@@ -1840,9 +1840,35 @@ void initializeContextFromHandle(Context& ctx, void* platform, void* _context, v
1840
1840
1841
1841
struct Queue ::Impl
1842
1842
{
1843
- Impl ( const Context& c, const Device& d )
1843
+ inline void __init ( )
1844
1844
{
1845
1845
refcount = 1 ;
1846
+ handle = 0 ;
1847
+ isProfilingQueue_ = false ;
1848
+ }
1849
+
1850
+ Impl (cl_command_queue q)
1851
+ {
1852
+ __init ();
1853
+ handle = q;
1854
+
1855
+ cl_command_queue_properties props = 0 ;
1856
+ cl_int result = clGetCommandQueueInfo (handle, CL_QUEUE_PROPERTIES, sizeof (cl_command_queue_properties), &props, NULL );
1857
+ CV_Assert (result && " clGetCommandQueueInfo(CL_QUEUE_PROPERTIES)" );
1858
+ isProfilingQueue_ = !!(props & CL_QUEUE_PROFILING_ENABLE);
1859
+ }
1860
+
1861
+ Impl (cl_command_queue q, bool isProfilingQueue)
1862
+ {
1863
+ __init ();
1864
+ handle = q;
1865
+ isProfilingQueue_ = isProfilingQueue;
1866
+ }
1867
+
1868
+ Impl (const Context& c, const Device& d, bool withProfiling = false )
1869
+ {
1870
+ __init ();
1871
+
1846
1872
const Context* pc = &c;
1847
1873
cl_context ch = (cl_context)pc->ptr ();
1848
1874
if ( !ch )
@@ -1854,8 +1880,10 @@ struct Queue::Impl
1854
1880
if ( !dh )
1855
1881
dh = (cl_device_id)pc->device (0 ).ptr ();
1856
1882
cl_int retval = 0 ;
1857
- handle = clCreateCommandQueue (ch, dh, 0 , &retval);
1883
+ cl_command_queue_properties props = withProfiling ? CL_QUEUE_PROFILING_ENABLE : 0 ;
1884
+ handle = clCreateCommandQueue (ch, dh, props, &retval);
1858
1885
CV_OclDbgAssert (retval == CL_SUCCESS);
1886
+ isProfilingQueue_ = withProfiling;
1859
1887
}
1860
1888
1861
1889
~Impl ()
@@ -1873,9 +1901,37 @@ struct Queue::Impl
1873
1901
}
1874
1902
}
1875
1903
1904
+ const cv::ocl::Queue& getProfilingQueue (const cv::ocl::Queue& self)
1905
+ {
1906
+ if (isProfilingQueue_)
1907
+ return self;
1908
+
1909
+ if (profiling_queue_.ptr ())
1910
+ return profiling_queue_;
1911
+
1912
+ cl_context ctx = 0 ;
1913
+ CV_Assert (CL_SUCCESS == clGetCommandQueueInfo (handle, CL_QUEUE_CONTEXT, sizeof (cl_context), &ctx, NULL ));
1914
+
1915
+ cl_device_id device = 0 ;
1916
+ CV_Assert (CL_SUCCESS == clGetCommandQueueInfo (handle, CL_QUEUE_DEVICE, sizeof (cl_device_id), &device, NULL ));
1917
+
1918
+ cl_int result = CL_SUCCESS;
1919
+ cl_command_queue_properties props = CL_QUEUE_PROFILING_ENABLE;
1920
+ cl_command_queue q = clCreateCommandQueue (ctx, device, props, &result);
1921
+ CV_Assert (result == CL_SUCCESS && " clCreateCommandQueue(with CL_QUEUE_PROFILING_ENABLE)" );
1922
+
1923
+ Queue queue;
1924
+ queue.p = new Impl (q, true );
1925
+ profiling_queue_ = queue;
1926
+
1927
+ return profiling_queue_;
1928
+ }
1929
+
1876
1930
IMPLEMENT_REFCOUNTABLE ();
1877
1931
1878
1932
cl_command_queue handle;
1933
+ bool isProfilingQueue_;
1934
+ cv::ocl::Queue profiling_queue_;
1879
1935
};
1880
1936
1881
1937
Queue::Queue ()
@@ -1929,6 +1985,12 @@ void Queue::finish()
1929
1985
}
1930
1986
}
1931
1987
1988
+ const Queue& Queue::getProfilingQueue () const
1989
+ {
1990
+ CV_Assert (p);
1991
+ return p->getProfilingQueue (*this );
1992
+ }
1993
+
1932
1994
void * Queue::ptr () const
1933
1995
{
1934
1996
return p ? p->handle : 0 ;
0 commit comments