void WebCLUserEvent::setStatus(cl_int executionStatus, ExceptionState& es) { ASSERT(isUserEvent()); if (isReleased()) { es.throwWebCLException(WebCLException::INVALID_EVENT, WebCLException::invalidEventMessage); return; } if (!(executionStatus < 0 || executionStatus == CL_COMPLETE)) { es.throwWebCLException(WebCLException::INVALID_VALUE, WebCLException::invalidValueMessage); return; } if (m_eventStatusSituation == StatusSet) { es.throwWebCLException(WebCLException::INVALID_OPERATION, WebCLException::invalidOperationMessage); return; } m_eventStatusSituation = StatusSet; m_executionStatus = executionStatus; cl_int err = clSetUserEventStatus(m_clEvent, executionStatus); if (err != CL_SUCCESS) WebCLException::throwException(err, es); }
ScriptValue WebCLEvent::getInfo(ScriptState* scriptState, unsigned paramName, ExceptionState& es) { v8::Handle<v8::Object> creationContext = scriptState->context()->Global(); v8::Isolate* isolate = scriptState->isolate(); if (isReleased()) { es.throwWebCLException(WebCLException::INVALID_EVENT, WebCLException::invalidEventMessage); return ScriptValue(scriptState, v8::Null(isolate)); } cl_int err = CL_SUCCESS; cl_int intUnits = 0; cl_command_type commandType = 0; switch(paramName) { case CL_EVENT_COMMAND_EXECUTION_STATUS: err = clGetEventInfo(m_clEvent, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(cl_int), &intUnits, nullptr); if (err == CL_SUCCESS) return ScriptValue(scriptState, v8::Integer::New(isolate, static_cast<int>(intUnits))); break; case CL_EVENT_COMMAND_TYPE: err = clGetEventInfo(m_clEvent, CL_EVENT_COMMAND_TYPE, sizeof(cl_command_type), &commandType, nullptr); if (err == CL_SUCCESS) return ScriptValue(scriptState, v8::Integer::NewFromUnsigned(isolate, static_cast<unsigned>(commandType))); break; case CL_EVENT_CONTEXT: ASSERT(!isUserEvent()); return ScriptValue(scriptState, toV8(context(), creationContext, isolate)); case CL_EVENT_COMMAND_QUEUE: ASSERT(m_commandQueue); ASSERT(!isUserEvent()); return ScriptValue(scriptState, toV8(m_commandQueue, creationContext, isolate)); default: es.throwWebCLException(WebCLException::INVALID_VALUE, WebCLException::invalidValueMessage); return ScriptValue(scriptState, v8::Null(isolate)); } WebCLException::throwException(err, es); return ScriptValue(scriptState, v8::Null(isolate)); }
ScriptValue WebCLEvent::getProfilingInfo(ScriptState* scriptState, unsigned paramName, ExceptionState& es) { v8::Isolate* isolate = scriptState->isolate(); if (isReleased()) { es.throwWebCLException(WebCLException::InvalidEvent, WebCLException::invalidEventMessage); return ScriptValue(scriptState, v8::Null(isolate)); } int status = getStatus(); unsigned properties = m_commandQueue ? m_commandQueue->getProperties() : 0; if (isUserEvent() || status != CL_COMPLETE || !(properties & CL_QUEUE_PROFILING_ENABLE)) { es.throwWebCLException(WebCLException::ProfilingInfoNotAvailable, WebCLException::profilingInfoNotAvailableMessage); return ScriptValue(scriptState, v8::Null(isolate)); } cl_int err = CL_SUCCESS; cl_ulong ulongUnits = 0; switch (paramName) { case CL_PROFILING_COMMAND_QUEUED: err = clGetEventProfilingInfo(m_clEvent, CL_PROFILING_COMMAND_QUEUED, sizeof(cl_ulong), &ulongUnits, nullptr); if (err == CL_SUCCESS) return ScriptValue(scriptState, v8::Number::New(isolate, static_cast<double>(ulongUnits))); break; case CL_PROFILING_COMMAND_SUBMIT: err = clGetEventProfilingInfo(m_clEvent, CL_PROFILING_COMMAND_SUBMIT, sizeof(cl_ulong), &ulongUnits, nullptr); if (err == CL_SUCCESS) return ScriptValue(scriptState, v8::Number::New(isolate, static_cast<double>(ulongUnits))); break; case CL_PROFILING_COMMAND_START: err = clGetEventProfilingInfo(m_clEvent, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &ulongUnits, nullptr); if (err == CL_SUCCESS) return ScriptValue(scriptState, v8::Number::New(isolate, static_cast<double>(ulongUnits))); break; case CL_PROFILING_COMMAND_END: err = clGetEventProfilingInfo(m_clEvent, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &ulongUnits, nullptr); if (err == CL_SUCCESS) return ScriptValue(scriptState, v8::Number::New(isolate, static_cast<double>(ulongUnits))); break; default: es.throwWebCLException(WebCLException::InvalidValue, WebCLException::invalidValueMessage); return ScriptValue(scriptState, v8::Null(isolate)); } WebCLException::throwException(err, es); return ScriptValue(scriptState, v8::Null(isolate)); }
unsigned WebCLEvent::getProfilingInfo(int paramName, ExceptionState& es) { if (isReleased()) { es.throwWebCLException(WebCLException::INVALID_EVENT, WebCLException::invalidEventMessage); return 0; } int status = getStatus(); unsigned properties = m_commandQueue ? m_commandQueue->getProperties() : 0; if (isUserEvent() || status != CL_COMPLETE || !(properties & CL_QUEUE_PROFILING_ENABLE)) { es.throwWebCLException(WebCLException::PROFILING_INFO_NOT_AVAILABLE, WebCLException::profilingInfoNotAvailableMessage); return 0; } cl_int err = CL_SUCCESS; cl_ulong ulongUnits = 0; switch(paramName) { case CL_PROFILING_COMMAND_QUEUED: err = clGetEventProfilingInfo(m_clEvent, CL_PROFILING_COMMAND_QUEUED, sizeof(cl_ulong), &ulongUnits, nullptr); if (err == CL_SUCCESS) return static_cast<unsigned long long>(ulongUnits); break; case CL_PROFILING_COMMAND_SUBMIT: err = clGetEventProfilingInfo(m_clEvent, CL_PROFILING_COMMAND_SUBMIT, sizeof(cl_ulong), &ulongUnits, nullptr); if (err == CL_SUCCESS) return static_cast<unsigned long long>(ulongUnits); break; case CL_PROFILING_COMMAND_START: err = clGetEventProfilingInfo(m_clEvent, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &ulongUnits, nullptr); if (err == CL_SUCCESS) return static_cast<unsigned long long>(ulongUnits); break; case CL_PROFILING_COMMAND_END: err = clGetEventProfilingInfo(m_clEvent, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &ulongUnits, nullptr); if (err == CL_SUCCESS) return static_cast<unsigned long long>(ulongUnits); break; default: es.throwWebCLException(WebCLException::INVALID_VALUE, WebCLException::invalidValueMessage); return 0; } WebCLException::throwException(err, es); return 0; }