Skip to content

Commit 6a80834

Browse files
committed
Merge pull request opencv#9803 from wzw-intel:ocl_timer
2 parents 5933294 + dbe9ee0 commit 6a80834

File tree

3 files changed

+13
-183
lines changed

3 files changed

+13
-183
lines changed

modules/core/src/ocl.cpp

Lines changed: 13 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -5239,78 +5239,31 @@ struct Timer::Impl
52395239

52405240
Impl(const Queue& q)
52415241
: queue(q)
5242-
, initted_(false)
5243-
, running_(false)
5244-
, has_run_at_least_once_(false)
52455242
{
5246-
init();
52475243
}
52485244

5249-
~Impl()
5250-
{
5251-
clWaitForEvents(1, &start_gpu_cl_);
5252-
clWaitForEvents(1, &stop_gpu_cl_);
5253-
clReleaseEvent(start_gpu_cl_);
5254-
clReleaseEvent(stop_gpu_cl_);
5255-
}
5245+
~Impl(){}
52565246

52575247
void start()
52585248
{
52595249
#ifdef HAVE_OPENCL
5260-
if (!running())
5261-
{
5262-
clWaitForEvents(1, &start_gpu_cl_);
5263-
clReleaseEvent(start_gpu_cl_);
5264-
ocl::Kernel kernel("null_kernel_float", ocl::core::benchmark_oclsrc);
5265-
float arg = 0;
5266-
clSetKernelArg((cl_kernel)kernel.ptr(), 0, sizeof(arg), &arg);
5267-
clEnqueueTask((cl_command_queue)queue.ptr(), (cl_kernel)kernel.ptr(), 0,
5268-
NULL, &start_gpu_cl_);
5269-
clFinish((cl_command_queue)queue.ptr());
5270-
running_ = true;
5271-
has_run_at_least_once_ = true;
5272-
}
5250+
clFinish((cl_command_queue)queue.ptr());
5251+
timer.start();
52735252
#endif
52745253
}
52755254

52765255
void stop()
52775256
{
52785257
#ifdef HAVE_OPENCL
5279-
if (running())
5280-
{
5281-
clWaitForEvents(1, &stop_gpu_cl_);
5282-
clReleaseEvent(stop_gpu_cl_);
5283-
ocl::Kernel kernel("null_kernel_float", ocl::core::benchmark_oclsrc);
5284-
float arg = 0;
5285-
clSetKernelArg((cl_kernel)kernel.ptr(), 0, sizeof(arg), &arg);
5286-
clEnqueueTask((cl_command_queue)queue.ptr(), (cl_kernel)kernel.ptr(), 0,
5287-
NULL, &stop_gpu_cl_);
5288-
clFinish((cl_command_queue)queue.ptr());
5289-
running_ = false;
5290-
}
5258+
clFinish((cl_command_queue)queue.ptr());
5259+
timer.stop();
52915260
#endif
52925261
}
52935262

52945263
float microSeconds()
52955264
{
52965265
#ifdef HAVE_OPENCL
5297-
if (!has_run_at_least_once())
5298-
{
5299-
return 0;
5300-
}
5301-
if (running())
5302-
{
5303-
stop();
5304-
}
5305-
cl_ulong startTime, stopTime;
5306-
clWaitForEvents(1, &stop_gpu_cl_);
5307-
clGetEventProfilingInfo(start_gpu_cl_, CL_PROFILING_COMMAND_END,
5308-
sizeof startTime, &startTime, NULL);
5309-
clGetEventProfilingInfo(stop_gpu_cl_, CL_PROFILING_COMMAND_START,
5310-
sizeof stopTime, &stopTime, NULL);
5311-
double us = static_cast<double>(stopTime - startTime) / 1000.0;
5312-
elapsed_microseconds_ = static_cast<float>(us);
5313-
return elapsed_microseconds_;
5266+
return (float)timer.getTimeMicro();
53145267
#else
53155268
return 0;
53165269
#endif
@@ -5319,54 +5272,21 @@ struct Timer::Impl
53195272
float milliSeconds()
53205273
{
53215274
#ifdef HAVE_OPENCL
5322-
if (!has_run_at_least_once())
5323-
{
5324-
return 0;
5325-
}
5326-
if (running())
5327-
{
5328-
stop();
5329-
}
5330-
cl_ulong startTime = 0, stopTime = 0;
5331-
clGetEventProfilingInfo(start_gpu_cl_, CL_PROFILING_COMMAND_END,
5332-
sizeof startTime, &startTime, NULL);
5333-
clGetEventProfilingInfo(stop_gpu_cl_, CL_PROFILING_COMMAND_START,
5334-
sizeof stopTime, &stopTime, NULL);
5335-
double ms = static_cast<double>(stopTime - startTime) / 1000000.0;
5336-
elapsed_milliseconds_ = static_cast<float>(ms);
5337-
return elapsed_milliseconds_;
5275+
return (float)timer.getTimeMilli();
53385276
#else
53395277
return 0;
53405278
#endif
53415279
}
53425280

53435281
float seconds()
53445282
{
5345-
return milliSeconds() / 1000.f;
5346-
}
5347-
5348-
void init()
5349-
{
5350-
CV_Assert(queue.getImpl() && queue.getImpl()->isProfilingQueue_);
5351-
if (!initted())
5352-
{
5353-
start_gpu_cl_ = 0;
5354-
stop_gpu_cl_ = 0;
5355-
initted_ = true;
5356-
}
5283+
#ifdef HAVE_OPENCL
5284+
return (float)timer.getTimeSec();
5285+
#else
5286+
return 0;
5287+
#endif
53575288
}
5358-
5359-
inline bool initted() { return initted_; }
5360-
inline bool running() { return running_; }
5361-
inline bool has_run_at_least_once() { return has_run_at_least_once_; }
5362-
5363-
bool initted_;
5364-
bool running_;
5365-
bool has_run_at_least_once_;
5366-
float elapsed_milliseconds_;
5367-
float elapsed_microseconds_;
5368-
cl_event start_gpu_cl_;
5369-
cl_event stop_gpu_cl_;
5289+
TickMeter timer;
53705290
};
53715291

53725292
Timer::Timer(const Queue& q)

modules/core/src/opencl/benchmark.cl

Lines changed: 0 additions & 45 deletions
This file was deleted.

modules/dnn/src/opencl/benchmark.cl

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)