Skip to content

Commit 9b1b281

Browse files
committed
Merge pull request opencv#9881 from alalek:ocl_timer_simplify
2 parents c63b443 + 185faf9 commit 9b1b281

File tree

3 files changed

+24
-52
lines changed

3 files changed

+24
-52
lines changed

modules/core/include/opencv2/core/ocl.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,13 +742,16 @@ class CV_EXPORTS Timer
742742
~Timer();
743743
void start();
744744
void stop();
745-
float milliSeconds();
746-
float microSeconds();
747-
float seconds();
745+
746+
uint64 durationNS() const; //< duration in nanoseconds
748747

749748
protected:
750749
struct Impl;
751-
Impl* p;
750+
Impl* const p;
751+
752+
private:
753+
Timer(const Timer&); // disabled
754+
Timer& operator=(const Timer&); // disabled
752755
};
753756

754757
CV_EXPORTS MatAllocator* getOpenCLAllocator();

modules/core/src/ocl.cpp

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5288,68 +5288,37 @@ struct Timer::Impl
52885288
#endif
52895289
}
52905290

5291-
float microSeconds()
5291+
uint64 durationNS() const
52925292
{
52935293
#ifdef HAVE_OPENCL
5294-
return (float)timer.getTimeMicro();
5294+
return (uint64)(timer.getTimeSec() * 1e9);
52955295
#else
52965296
return 0;
52975297
#endif
52985298
}
52995299

5300-
float milliSeconds()
5301-
{
5302-
#ifdef HAVE_OPENCL
5303-
return (float)timer.getTimeMilli();
5304-
#else
5305-
return 0;
5306-
#endif
5307-
}
5308-
5309-
float seconds()
5310-
{
5311-
#ifdef HAVE_OPENCL
5312-
return (float)timer.getTimeSec();
5313-
#else
5314-
return 0;
5315-
#endif
5316-
}
53175300
TickMeter timer;
53185301
};
53195302

5320-
Timer::Timer(const Queue& q)
5321-
{
5322-
p = new Impl(q);
5323-
}
5324-
5325-
Timer::~Timer()
5326-
{
5327-
if(p)
5328-
{
5329-
delete p;
5330-
p = 0;
5331-
}
5332-
}
5303+
Timer::Timer(const Queue& q) : p(new Impl(q)) { }
5304+
Timer::~Timer() { delete p; }
53335305

53345306
void Timer::start()
53355307
{
5336-
if(p)
5337-
p->start();
5308+
CV_Assert(p);
5309+
p->start();
53385310
}
53395311

53405312
void Timer::stop()
53415313
{
5342-
if(p)
5343-
p->stop();
5314+
CV_Assert(p);
5315+
p->stop();
53445316
}
53455317

5346-
float Timer::microSeconds()
5347-
{ return p ? p->microSeconds() : 0; }
5348-
5349-
float Timer::milliSeconds()
5350-
{ return p ? p->milliSeconds() : 0; }
5351-
5352-
float Timer::seconds()
5353-
{ return p ? p->seconds() : 0; }
5318+
uint64 Timer::durationNS() const
5319+
{
5320+
CV_Assert(p);
5321+
return p->durationNS();
5322+
}
53545323

5355-
}}
5324+
}} // namespace

modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ float OCL4DNNConvSpatial<float>::timedConvolve(const UMat &bottom, UMat &top,
890890
return 1e5;
891891
}
892892

893-
float elapsedTime = timer.milliSeconds() / loop_cnt;
893+
float elapsedTime = timer.durationNS() * 1e-6 / loop_cnt;
894894
#ifdef dbg
895895
double out_w = output_w_;
896896
double out_h = output_h_;
@@ -899,9 +899,9 @@ float OCL4DNNConvSpatial<float>::timedConvolve(const UMat &bottom, UMat &top,
899899
double k_h = kernel_h_;
900900
double k_z = channels_;
901901
double totalFlops = ((k_w*k_h*k_z -1)*2)*(out_w*out_h*out_z)*num_;
902-
std::cout << "\tEstimated Gflops:" << ((totalFlops/1000)/1000)/1000
902+
std::cout << "\tEstimated Gflops:" << (totalFlops * 1e-9)
903903
<< std::endl;
904-
std::cout << "\tEstimated GFLOPS/S: " << (((totalFlops/1000)/1000)/1000)*(1000.0/elapsedTime)
904+
std::cout << "\tEstimated GFLOPS/S: " << ((totalFlops * 1e-9)*(1000.0/elapsedTime))
905905
<< std::endl;
906906
#if 0
907907
std::cout << "Estimated utilization: " <<

0 commit comments

Comments
 (0)