Merge pull request #9881 from alalek:ocl_timer_simplify

This commit is contained in:
Maksim Shabunin 2017-10-18 14:49:21 +00:00
commit 9b1b281c7b
3 changed files with 24 additions and 52 deletions

View File

@ -742,13 +742,16 @@ public:
~Timer(); ~Timer();
void start(); void start();
void stop(); void stop();
float milliSeconds();
float microSeconds(); uint64 durationNS() const; //< duration in nanoseconds
float seconds();
protected: protected:
struct Impl; struct Impl;
Impl* p; Impl* const p;
private:
Timer(const Timer&); // disabled
Timer& operator=(const Timer&); // disabled
}; };
CV_EXPORTS MatAllocator* getOpenCLAllocator(); CV_EXPORTS MatAllocator* getOpenCLAllocator();

View File

@ -5288,68 +5288,37 @@ struct Timer::Impl
#endif #endif
} }
float microSeconds() uint64 durationNS() const
{ {
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
return (float)timer.getTimeMicro(); return (uint64)(timer.getTimeSec() * 1e9);
#else #else
return 0; return 0;
#endif #endif
} }
float milliSeconds()
{
#ifdef HAVE_OPENCL
return (float)timer.getTimeMilli();
#else
return 0;
#endif
}
float seconds()
{
#ifdef HAVE_OPENCL
return (float)timer.getTimeSec();
#else
return 0;
#endif
}
TickMeter timer; TickMeter timer;
}; };
Timer::Timer(const Queue& q) Timer::Timer(const Queue& q) : p(new Impl(q)) { }
{ Timer::~Timer() { delete p; }
p = new Impl(q);
}
Timer::~Timer()
{
if(p)
{
delete p;
p = 0;
}
}
void Timer::start() void Timer::start()
{ {
if(p) CV_Assert(p);
p->start(); p->start();
} }
void Timer::stop() void Timer::stop()
{ {
if(p) CV_Assert(p);
p->stop(); p->stop();
} }
float Timer::microSeconds() uint64 Timer::durationNS() const
{ return p ? p->microSeconds() : 0; } {
CV_Assert(p);
return p->durationNS();
}
float Timer::milliSeconds() }} // namespace
{ return p ? p->milliSeconds() : 0; }
float Timer::seconds()
{ return p ? p->seconds() : 0; }
}}

View File

@ -890,7 +890,7 @@ float OCL4DNNConvSpatial<float>::timedConvolve(const UMat &bottom, UMat &top,
return 1e5; return 1e5;
} }
float elapsedTime = timer.milliSeconds() / loop_cnt; float elapsedTime = timer.durationNS() * 1e-6 / loop_cnt;
#ifdef dbg #ifdef dbg
double out_w = output_w_; double out_w = output_w_;
double out_h = output_h_; double out_h = output_h_;
@ -899,9 +899,9 @@ float OCL4DNNConvSpatial<float>::timedConvolve(const UMat &bottom, UMat &top,
double k_h = kernel_h_; double k_h = kernel_h_;
double k_z = channels_; double k_z = channels_;
double totalFlops = ((k_w*k_h*k_z -1)*2)*(out_w*out_h*out_z)*num_; double totalFlops = ((k_w*k_h*k_z -1)*2)*(out_w*out_h*out_z)*num_;
std::cout << "\tEstimated Gflops:" << ((totalFlops/1000)/1000)/1000 std::cout << "\tEstimated Gflops:" << (totalFlops * 1e-9)
<< std::endl; << std::endl;
std::cout << "\tEstimated GFLOPS/S: " << (((totalFlops/1000)/1000)/1000)*(1000.0/elapsedTime) std::cout << "\tEstimated GFLOPS/S: " << ((totalFlops * 1e-9)*(1000.0/elapsedTime))
<< std::endl; << std::endl;
#if 0 #if 0
std::cout << "Estimated utilization: " << std::cout << "Estimated utilization: " <<