Question

I am new to opencv and opencl. In opencl they give a wrappers for opencl utility function calling. I do not need to do much. ocl::Context::getContext() will get me the context and I can pass it to all opencl related execution. I do not need command quee here. But I want to know the performance of the kernels using opencl's profiling events. For that I need to create a custom command queue. How can I create a command queue with the same context that I used for executing kernel. Please I created this context using opencv's function ocl::Context::getContext().

I do not want to create command queue from scratch (by getting platform id, device id, context one by one). That would mean to change a lot of places. I want to reuse opencv's context and reuse it to create command queue with event capability.

Was it helpful?

Solution

You are in a tricky situation since the OpenCV code has missing functionality interface to the underlying OpenCL options:

  804 void CommandQueue::create(ContextImpl* context)
  805 {
  806     release();
  807     cl_int status = 0;
  808     // TODO add CL_QUEUE_PROFILING_ENABLE
  809     cl_command_queue clCmdQueue = clCreateCommandQueue(context->clContext, context->clDeviceID, 0, &status);
  810     openCLVerifyCall(status);
  811     context_ = context;
  812     clQueue_ = clCmdQueue;
  813 }

I think you should either release and re-create the internal queue, by:

 cl_command_queue Queue = clCreateCommandQueue(ocl::Context::getOpenCLContextPtr(), ocl::Context::getOpenCLDeviceIDPtr(), CL_QUEUE_PROFILING_ENABLE); //Create a new queue with same parameters
 ocl::CommandQueue::Release(); //To release the old queue
 ocl::CommandQueue::clQueue_ = Queue ; //To overwrite it internally with the new one

Or do it everything yourself (creating all the devices and using them manually) But beware! This is unsafe! (And untested). However, the DOC says that those classes have public attributes and they can be written from the outside.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top