我是opencv和opencl的新手。 在opencl中,它们为opencl实用程序函数调用提供了一个包装器。 我不需要做太多。 ocl :: Context :: getContext()将获取上下文,我可以将它传递给所有opencl相关的执行。我这里不需要命令。但我想知道使用opencl的性能分析事件的内核性能。为此,我需要创建一个自定义命令队列。如何使用与执行内核相同的上下文创建命令队列。请使用opencv的函数ocl :: Context :: getContext()创建此上下文。
我不想从头开始创建命令队列(通过逐个获取平台ID,设备ID,上下文)。这意味着要改变很多地方。我想重用opencv的上下文并重用它来创建具有事件功能的命令队列。
答案 0 :(得分:1)
由于OpenCV代码缺少底层OpenCL选项的功能接口,因此处于棘手的状态:
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 }
我认为您应该通过以下方式释放并重新创建内部队列:
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
或者自己动手做(创建所有设备并手动使用) 但要小心!这是不安全的! (并且未经测试)。但是,DOC说这些类具有公共属性,可以从外部编写。