Commit d9ab3149 authored by Alexander Alekhin's avatar Alexander Alekhin

ocl: profiling queue

parent 6a5298a5
...@@ -333,8 +333,12 @@ public: ...@@ -333,8 +333,12 @@ public:
void* ptr() const; void* ptr() const;
static Queue& getDefault(); static Queue& getDefault();
/// @brief Returns OpenCL command queue with enable profiling mode support
const Queue& getProfilingQueue() const;
struct Impl; friend struct Impl;
inline Impl* getImpl() const { return p; }
protected: protected:
struct Impl;
Impl* p; Impl* p;
}; };
......
...@@ -1840,9 +1840,35 @@ void initializeContextFromHandle(Context& ctx, void* platform, void* _context, v ...@@ -1840,9 +1840,35 @@ void initializeContextFromHandle(Context& ctx, void* platform, void* _context, v
struct Queue::Impl struct Queue::Impl
{ {
Impl(const Context& c, const Device& d) inline void __init()
{ {
refcount = 1; refcount = 1;
handle = 0;
isProfilingQueue_ = false;
}
Impl(cl_command_queue q)
{
__init();
handle = q;
cl_command_queue_properties props = 0;
cl_int result = clGetCommandQueueInfo(handle, CL_QUEUE_PROPERTIES, sizeof(cl_command_queue_properties), &props, NULL);
CV_Assert(result && "clGetCommandQueueInfo(CL_QUEUE_PROPERTIES)");
isProfilingQueue_ = !!(props & CL_QUEUE_PROFILING_ENABLE);
}
Impl(cl_command_queue q, bool isProfilingQueue)
{
__init();
handle = q;
isProfilingQueue_ = isProfilingQueue;
}
Impl(const Context& c, const Device& d, bool withProfiling = false)
{
__init();
const Context* pc = &c; const Context* pc = &c;
cl_context ch = (cl_context)pc->ptr(); cl_context ch = (cl_context)pc->ptr();
if( !ch ) if( !ch )
...@@ -1854,8 +1880,10 @@ struct Queue::Impl ...@@ -1854,8 +1880,10 @@ struct Queue::Impl
if( !dh ) if( !dh )
dh = (cl_device_id)pc->device(0).ptr(); dh = (cl_device_id)pc->device(0).ptr();
cl_int retval = 0; cl_int retval = 0;
handle = clCreateCommandQueue(ch, dh, 0, &retval); cl_command_queue_properties props = withProfiling ? CL_QUEUE_PROFILING_ENABLE : 0;
handle = clCreateCommandQueue(ch, dh, props, &retval);
CV_OclDbgAssert(retval == CL_SUCCESS); CV_OclDbgAssert(retval == CL_SUCCESS);
isProfilingQueue_ = withProfiling;
} }
~Impl() ~Impl()
...@@ -1873,9 +1901,37 @@ struct Queue::Impl ...@@ -1873,9 +1901,37 @@ struct Queue::Impl
} }
} }
const cv::ocl::Queue& getProfilingQueue(const cv::ocl::Queue& self)
{
if (isProfilingQueue_)
return self;
if (profiling_queue_.ptr())
return profiling_queue_;
cl_context ctx = 0;
CV_Assert(CL_SUCCESS == clGetCommandQueueInfo(handle, CL_QUEUE_CONTEXT, sizeof(cl_context), &ctx, NULL));
cl_device_id device = 0;
CV_Assert(CL_SUCCESS == clGetCommandQueueInfo(handle, CL_QUEUE_DEVICE, sizeof(cl_device_id), &device, NULL));
cl_int result = CL_SUCCESS;
cl_command_queue_properties props = CL_QUEUE_PROFILING_ENABLE;
cl_command_queue q = clCreateCommandQueue(ctx, device, props, &result);
CV_Assert(result == CL_SUCCESS && "clCreateCommandQueue(with CL_QUEUE_PROFILING_ENABLE)");
Queue queue;
queue.p = new Impl(q, true);
profiling_queue_ = queue;
return profiling_queue_;
}
IMPLEMENT_REFCOUNTABLE(); IMPLEMENT_REFCOUNTABLE();
cl_command_queue handle; cl_command_queue handle;
bool isProfilingQueue_;
cv::ocl::Queue profiling_queue_;
}; };
Queue::Queue() Queue::Queue()
...@@ -1929,6 +1985,12 @@ void Queue::finish() ...@@ -1929,6 +1985,12 @@ void Queue::finish()
} }
} }
const Queue& Queue::getProfilingQueue() const
{
CV_Assert(p);
return p->getProfilingQueue(*this);
}
void* Queue::ptr() const void* Queue::ptr() const
{ {
return p ? p->handle : 0; return p ? p->handle : 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment