@@ -5239,78 +5239,31 @@ struct Timer::Impl
5239
5239
5240
5240
Impl (const Queue& q)
5241
5241
: queue(q)
5242
- , initted_(false )
5243
- , running_(false )
5244
- , has_run_at_least_once_(false )
5245
5242
{
5246
- init ();
5247
5243
}
5248
5244
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 (){}
5256
5246
5257
5247
void start ()
5258
5248
{
5259
5249
#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 ();
5273
5252
#endif
5274
5253
}
5275
5254
5276
5255
void stop ()
5277
5256
{
5278
5257
#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 ();
5291
5260
#endif
5292
5261
}
5293
5262
5294
5263
float microSeconds ()
5295
5264
{
5296
5265
#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 ();
5314
5267
#else
5315
5268
return 0 ;
5316
5269
#endif
@@ -5319,54 +5272,21 @@ struct Timer::Impl
5319
5272
float milliSeconds ()
5320
5273
{
5321
5274
#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 ();
5338
5276
#else
5339
5277
return 0 ;
5340
5278
#endif
5341
5279
}
5342
5280
5343
5281
float seconds ()
5344
5282
{
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
5357
5288
}
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;
5370
5290
};
5371
5291
5372
5292
Timer::Timer (const Queue& q)
0 commit comments