From e7f4a432775eb215c9da7ade1ee2710f67641068 Mon Sep 17 00:00:00 2001 From: Anthony Barbier Date: Fri, 9 Nov 2018 10:58:40 +0000 Subject: COMPMID-1777: Output 'now' measurements in OpenCLTimer at the beginning of the test. This is needed in order to calculate the offset between OpenCL timestamps and Wall Clock timestamps as they're using different clocks Change-Id: I874b2a475bf98fd664a1e3e15045c80f0181af47 --- tests/framework/instruments/OpenCLTimer.cpp | 27 +++++++++++++++++++++++++++ tests/framework/instruments/OpenCLTimer.h | 1 + 2 files changed, 28 insertions(+) diff --git a/tests/framework/instruments/OpenCLTimer.cpp b/tests/framework/instruments/OpenCLTimer.cpp index b23b8a8878..c443aade56 100644 --- a/tests/framework/instruments/OpenCLTimer.cpp +++ b/tests/framework/instruments/OpenCLTimer.cpp @@ -202,6 +202,33 @@ Instrument::MeasurementsMap OpenCLClock::measurements() const return measurements; } +template +Instrument::MeasurementsMap OpenCLClock::test_measurements() const +{ + MeasurementsMap measurements; + + if(output_timestamps) + { + // The OpenCL clock and the wall clock are not in sync, so we use + // this trick to calculate the offset between the two clocks: + ::cl::Event event; + cl_ulong now_gpu; + + // Enqueue retrieve current CPU clock and enqueue a dummy marker + std::chrono::high_resolution_clock::time_point now_cpu = std::chrono::high_resolution_clock::now(); + CLScheduler::get().queue().enqueueMarker(&event); + + CLScheduler::get().queue().finish(); + //Access the time at which the marker was enqueued: + event.getProfilingInfo(CL_PROFILING_COMMAND_QUEUED, &now_gpu); + + measurements.emplace("Now Wall clock", Measurement(now_cpu.time_since_epoch().count() / 1000, "us")); + measurements.emplace("Now OpenCL", Measurement(now_gpu / static_cast(_scale_factor), _unit)); + } + + return measurements; +} + template class OpenCLClock; template class OpenCLClock; } // namespace framework diff --git a/tests/framework/instruments/OpenCLTimer.h b/tests/framework/instruments/OpenCLTimer.h index 8722e6b348..b094ef44cb 100644 --- a/tests/framework/instruments/OpenCLTimer.h +++ b/tests/framework/instruments/OpenCLTimer.h @@ -56,6 +56,7 @@ public: void stop() override; void test_stop() override; MeasurementsMap measurements() const override; + MeasurementsMap test_measurements() const override; private: #ifdef ARM_COMPUTE_CL -- cgit v1.2.1