From ce58a9f8f8504c165ca4527bfd991a4029437cba Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Tue, 31 Oct 2017 17:59:17 +0000 Subject: COMPMID-622 Let the user choose the units for the instruments Change-Id: Ic6ac4cd6df6970593a5e2e6310b6d61951c88898 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/93887 Tested-by: Kaizen Reviewed-by: Anthony Barbier --- tests/framework/instruments/Instrument.h | 21 ++++++-- tests/framework/instruments/Instruments.cpp | 30 +++++++---- tests/framework/instruments/Instruments.h | 73 +++++++++++++++++++++++--- tests/framework/instruments/MaliCounter.cpp | 26 +++++++-- tests/framework/instruments/MaliCounter.h | 3 +- tests/framework/instruments/Measurement.h | 2 +- tests/framework/instruments/OpenCLTimer.cpp | 26 ++++++++- tests/framework/instruments/OpenCLTimer.h | 5 +- tests/framework/instruments/PMUCounter.cpp | 4 +- tests/framework/instruments/PMUCounter.h | 22 ++++++++ tests/framework/instruments/WallClockTimer.cpp | 2 +- tests/framework/instruments/WallClockTimer.h | 22 ++++++++ 12 files changed, 203 insertions(+), 33 deletions(-) (limited to 'tests/framework/instruments') diff --git a/tests/framework/instruments/Instrument.h b/tests/framework/instruments/Instrument.h index 560bdf6a35..9156d70010 100644 --- a/tests/framework/instruments/Instrument.h +++ b/tests/framework/instruments/Instrument.h @@ -37,6 +37,15 @@ namespace test { namespace framework { +enum class ScaleFactor : unsigned int +{ + NONE, /* Default scale */ + SCALE_1K, /* 1000 */ + SCALE_1M, /* 1 000 000 */ + TIME_US, /* Microseconds */ + TIME_MS, /* Milliseconds */ + TIME_S, /* Seconds */ +}; /** Interface for classes that can be used to measure performance. */ class Instrument { @@ -45,10 +54,11 @@ public: * * @return Instance of an instrument of the given type. */ - template + template static std::unique_ptr make_instrument(); - Instrument() = default; + Instrument() = default; + Instrument(const Instrument &) = default; Instrument(Instrument &&) = default; Instrument &operator=(const Instrument &) = default; @@ -68,12 +78,15 @@ public: /** Return the latest measurement. */ virtual MeasurementsMap measurements() const = 0; + +protected: + std::string _unit{}; }; -template +template inline std::unique_ptr Instrument::make_instrument() { - return support::cpp14::make_unique(); + return support::cpp14::make_unique(scale); } } // namespace framework } // namespace test diff --git a/tests/framework/instruments/Instruments.cpp b/tests/framework/instruments/Instruments.cpp index eca6d6f437..641e6305cd 100644 --- a/tests/framework/instruments/Instruments.cpp +++ b/tests/framework/instruments/Instruments.cpp @@ -34,18 +34,28 @@ namespace test { namespace framework { -InstrumentType instrument_type_from_name(const std::string &name) +InstrumentsDescription instrument_type_from_name(const std::string &name) { - static const std::map types = + static const std::map types = { - { "all", InstrumentType::ALL }, - { "none", InstrumentType::NONE }, - { "wall_clock", InstrumentType::WALL_CLOCK_TIMER }, - { "pmu", InstrumentType::PMU }, - { "pmu_cycles", InstrumentType::PMU_CYCLE_COUNTER }, - { "pmu_instructions", InstrumentType::PMU_INSTRUCTION_COUNTER }, - { "mali", InstrumentType::MALI }, - { "opencl_timer", InstrumentType::OPENCL_TIMER }, + { "all", std::pair(InstrumentType::ALL, ScaleFactor::NONE) }, + { "none", std::pair(InstrumentType::NONE, ScaleFactor::NONE) }, + { "wall_clock", std::pair(InstrumentType::WALL_CLOCK_TIMER, ScaleFactor::NONE) }, + { "wall_clock_timer", std::pair(InstrumentType::WALL_CLOCK_TIMER, ScaleFactor::NONE) }, + { "wall_clock_timer_ms", std::pair(InstrumentType::WALL_CLOCK_TIMER, ScaleFactor::TIME_MS) }, + { "wall_clock_timer_s", std::pair(InstrumentType::WALL_CLOCK_TIMER, ScaleFactor::TIME_S) }, + { "pmu", std::pair(InstrumentType::PMU, ScaleFactor::NONE) }, + { "pmu_k", std::pair(InstrumentType::PMU, ScaleFactor::SCALE_1K) }, + { "pmu_m", std::pair(InstrumentType::PMU, ScaleFactor::SCALE_1M) }, + { "pmu_cycles", std::pair(InstrumentType::PMU_CYCLE_COUNTER, ScaleFactor::NONE) }, + { "pmu_instructions", std::pair(InstrumentType::PMU_INSTRUCTION_COUNTER, ScaleFactor::NONE) }, + { "mali", std::pair(InstrumentType::MALI, ScaleFactor::NONE) }, + { "mali_k", std::pair(InstrumentType::MALI, ScaleFactor::SCALE_1K) }, + { "mali_m", std::pair(InstrumentType::MALI, ScaleFactor::SCALE_1M) }, + { "opencl_timer", std::pair(InstrumentType::OPENCL_TIMER, ScaleFactor::NONE) }, + { "opencl_timer_us", std::pair(InstrumentType::OPENCL_TIMER, ScaleFactor::TIME_US) }, + { "opencl_timer_ms", std::pair(InstrumentType::OPENCL_TIMER, ScaleFactor::TIME_MS) }, + { "opencl_timer_s", std::pair(InstrumentType::OPENCL_TIMER, ScaleFactor::TIME_S) }, }; try diff --git a/tests/framework/instruments/Instruments.h b/tests/framework/instruments/Instruments.h index ffe7cb681d..651f0f567e 100644 --- a/tests/framework/instruments/Instruments.h +++ b/tests/framework/instruments/Instruments.h @@ -50,9 +50,11 @@ enum class InstrumentType : unsigned int OPENCL_TIMER = 0x0400, }; -InstrumentType instrument_type_from_name(const std::string &name); +using InstrumentsDescription = std::pair; -inline ::std::stringstream &operator>>(::std::stringstream &stream, InstrumentType &instrument) +InstrumentsDescription instrument_type_from_name(const std::string &name); + +inline ::std::stringstream &operator>>(::std::stringstream &stream, InstrumentsDescription &instrument) { std::string value; stream >> value; @@ -60,15 +62,41 @@ inline ::std::stringstream &operator>>(::std::stringstream &stream, InstrumentTy return stream; } -inline ::std::stringstream &operator<<(::std::stringstream &stream, InstrumentType instrument) +inline ::std::stringstream &operator<<(::std::stringstream &stream, InstrumentsDescription instrument) { - switch(instrument) + switch(instrument.first) { case InstrumentType::WALL_CLOCK_TIMER: - stream << "WALL_CLOCK_TIMER"; + switch(instrument.second) + { + case ScaleFactor::NONE: + stream << "WALL_CLOCK_TIMER"; + break; + case ScaleFactor::TIME_MS: + stream << "WALL_CLOCK_TIMER_MS"; + break; + case ScaleFactor::TIME_S: + stream << "WALL_CLOCK_TIMER_S"; + break; + default: + throw std::invalid_argument("Unsupported instrument scale"); + } break; case InstrumentType::PMU: - stream << "PMU"; + switch(instrument.second) + { + case ScaleFactor::NONE: + stream << "PMU"; + break; + case ScaleFactor::SCALE_1K: + stream << "PMU_K"; + break; + case ScaleFactor::SCALE_1M: + stream << "PMU_M"; + break; + default: + throw std::invalid_argument("Unsupported instrument scale"); + } break; case InstrumentType::PMU_CYCLE_COUNTER: stream << "PMU_CYCLE_COUNTER"; @@ -77,10 +105,39 @@ inline ::std::stringstream &operator<<(::std::stringstream &stream, InstrumentTy stream << "PMU_INSTRUCTION_COUNTER"; break; case InstrumentType::MALI: - stream << "MALI"; + switch(instrument.second) + { + case ScaleFactor::NONE: + stream << "MALI"; + break; + case ScaleFactor::SCALE_1K: + stream << "MALI_K"; + break; + case ScaleFactor::SCALE_1M: + stream << "MALI_M"; + break; + default: + throw std::invalid_argument("Unsupported instrument scale"); + } break; case InstrumentType::OPENCL_TIMER: - stream << "OPENCL_TIMER"; + switch(instrument.second) + { + case ScaleFactor::NONE: + stream << "OPENCL_TIMER"; + break; + case ScaleFactor::TIME_US: + stream << "OPENCL_TIMER_US"; + break; + case ScaleFactor::TIME_MS: + stream << "OPENCL_TIMER_MS"; + break; + case ScaleFactor::TIME_S: + stream << "OPENCL_TIMER_S"; + break; + default: + throw std::invalid_argument("Unsupported instrument scale"); + } break; case InstrumentType::ALL: stream << "ALL"; diff --git a/tests/framework/instruments/MaliCounter.cpp b/tests/framework/instruments/MaliCounter.cpp index f36d1801a3..f3ec45d485 100644 --- a/tests/framework/instruments/MaliCounter.cpp +++ b/tests/framework/instruments/MaliCounter.cpp @@ -107,7 +107,7 @@ MaliHWInfo get_mali_hw_info(const char *path) } } // namespace -MaliCounter::MaliCounter() +MaliCounter::MaliCounter(ScaleFactor scale_factor) { _counters = { @@ -123,6 +123,24 @@ MaliCounter::MaliCounter() { "FRAG_ACTIVE", { "Fragment core", std::map(), "cycles" } }, }; + switch(scale_factor) + { + case ScaleFactor::NONE: + _scale_factor = 1; + _unit = ""; + break; + case ScaleFactor::SCALE_1K: + _scale_factor = 1000; + _unit = "K "; + break; + case ScaleFactor::SCALE_1M: + _scale_factor = 1000000; + _unit = "M "; + break; + default: + ARM_COMPUTE_ERROR("Invalid scale"); + } + init(); } @@ -404,17 +422,19 @@ std::string MaliCounter::id() const Instrument::MeasurementsMap MaliCounter::measurements() const { + Measurement counters((_counters.at("GPU_ACTIVE").value() / _scale_factor).v.floating_point, _unit + _counters.at("GPU_ACTIVE").unit()); //NOLINT + MeasurementsMap measurements { { "Timespan", Measurement(_stop_time - _start_time, "ns") }, - { "GPU active", _counters.at("GPU_ACTIVE") }, + { "GPU active", counters }, }; for(const auto &counter : _core_counters) { for(const auto &core : counter.second.values) { - measurements.emplace(counter.second.name + " #" + support::cpp11::to_string(core.first), Measurement(core.second, counter.second.unit)); + measurements.emplace(counter.second.name + " #" + support::cpp11::to_string(core.first), Measurement(core.second / _scale_factor, _unit + counter.second.unit)); } } diff --git a/tests/framework/instruments/MaliCounter.h b/tests/framework/instruments/MaliCounter.h index 64b5b93015..b7c3483817 100644 --- a/tests/framework/instruments/MaliCounter.h +++ b/tests/framework/instruments/MaliCounter.h @@ -42,7 +42,7 @@ class MaliCounter : public Instrument { public: /** Default constructor. */ - MaliCounter(); + MaliCounter(ScaleFactor scale_factor); MaliCounter(const MaliCounter &) = delete; MaliCounter &operator=(const MaliCounter &) = delete; @@ -95,6 +95,7 @@ private: std::vector _core_index_remap{}; int _fd{ -1 }; int _hwc_fd{ -1 }; + int _scale_factor{}; }; } // namespace framework } // namespace test diff --git a/tests/framework/instruments/Measurement.h b/tests/framework/instruments/Measurement.h index 08624f3345..8a1ec9cb14 100644 --- a/tests/framework/instruments/Measurement.h +++ b/tests/framework/instruments/Measurement.h @@ -57,7 +57,7 @@ struct Measurement { if(value.is_floating_point) { - os << arithmetic_to_string(value.v.floating_point); + os << arithmetic_to_string(value.v.floating_point, 4); } else { diff --git a/tests/framework/instruments/OpenCLTimer.cpp b/tests/framework/instruments/OpenCLTimer.cpp index 819ecdb743..3de953fbe7 100644 --- a/tests/framework/instruments/OpenCLTimer.cpp +++ b/tests/framework/instruments/OpenCLTimer.cpp @@ -90,7 +90,7 @@ private: OpenCLTimer &_timer; }; -OpenCLTimer::OpenCLTimer() +OpenCLTimer::OpenCLTimer(ScaleFactor scale_factor) : real_function(CLSymbols::get().clEnqueueNDRangeKernel_ptr) { auto q = CLScheduler::get().queue(); @@ -99,6 +99,28 @@ OpenCLTimer::OpenCLTimer() { CLScheduler::get().set_queue(cl::CommandQueue(CLScheduler::get().context(), props | CL_QUEUE_PROFILING_ENABLE)); } + + switch(scale_factor) + { + case ScaleFactor::NONE: + _scale_factor = 1.f; + _unit = "ns"; + break; + case ScaleFactor::TIME_US: + _scale_factor = 1000.f; + _unit = "us"; + break; + case ScaleFactor::TIME_MS: + _scale_factor = 1000000.f; + _unit = "ms"; + break; + case ScaleFactor::TIME_S: + _scale_factor = 1000000000.f; + _unit = "s"; + break; + default: + ARM_COMPUTE_ERROR("Invalid scale"); + } } void OpenCLTimer::start() @@ -133,7 +155,7 @@ Instrument::MeasurementsMap OpenCLTimer::measurements() const "start", support::cpp11::to_string(start), "end", support::cpp11::to_string(end), }; - measurements.emplace(kernel.name + " #" + support::cpp11::to_string(kernel_number++), Measurement(end - start, "ns", raw_data)); + measurements.emplace(kernel.name + " #" + support::cpp11::to_string(kernel_number++), Measurement((end - start) / _scale_factor, _unit, raw_data)); } return measurements; diff --git a/tests/framework/instruments/OpenCLTimer.h b/tests/framework/instruments/OpenCLTimer.h index d00a2e8bf2..a3dc107bf8 100644 --- a/tests/framework/instruments/OpenCLTimer.h +++ b/tests/framework/instruments/OpenCLTimer.h @@ -42,7 +42,7 @@ namespace framework class OpenCLTimer : public Instrument { public: - OpenCLTimer(); + OpenCLTimer(ScaleFactor scale_factor); std::string id() const override; void start() override; void stop() override; @@ -56,6 +56,9 @@ public: std::list kernels{}; std::function real_function; #endif /* ARM_COMPUTE_CL */ + +private: + float _scale_factor{}; }; } // namespace framework } // namespace test diff --git a/tests/framework/instruments/PMUCounter.cpp b/tests/framework/instruments/PMUCounter.cpp index b962bd9b2b..df059fbc4e 100644 --- a/tests/framework/instruments/PMUCounter.cpp +++ b/tests/framework/instruments/PMUCounter.cpp @@ -65,8 +65,8 @@ Instrument::MeasurementsMap PMUCounter::measurements() const { return MeasurementsMap { - { "CPU cycles", Measurement(_cycles, "cycles") }, - { "CPU instructions", Measurement(_instructions, "instructions") }, + { "CPU cycles", Measurement(_cycles / _scale_factor, _unit + "cycles") }, + { "CPU instructions", Measurement(_instructions / _scale_factor, _unit + "instructions") }, }; } } // namespace framework diff --git a/tests/framework/instruments/PMUCounter.h b/tests/framework/instruments/PMUCounter.h index 7beb6d931d..e1b9433eda 100644 --- a/tests/framework/instruments/PMUCounter.h +++ b/tests/framework/instruments/PMUCounter.h @@ -37,6 +37,27 @@ namespace framework class PMUCounter : public Instrument { public: + PMUCounter(ScaleFactor scale_factor) + { + switch(scale_factor) + { + case ScaleFactor::NONE: + _scale_factor = 1; + _unit = ""; + break; + case ScaleFactor::SCALE_1K: + _scale_factor = 1000; + _unit = "K "; + break; + case ScaleFactor::SCALE_1M: + _scale_factor = 1000000; + _unit = "M "; + break; + default: + ARM_COMPUTE_ERROR("Invalid scale"); + } + }; + std::string id() const override; void start() override; void stop() override; @@ -47,6 +68,7 @@ private: PMU _pmu_instructions{ PERF_COUNT_HW_INSTRUCTIONS }; long long _cycles{ 0 }; long long _instructions{ 0 }; + int _scale_factor{}; }; } // namespace framework } // namespace test diff --git a/tests/framework/instruments/WallClockTimer.cpp b/tests/framework/instruments/WallClockTimer.cpp index c6384a3ab5..6c69360236 100644 --- a/tests/framework/instruments/WallClockTimer.cpp +++ b/tests/framework/instruments/WallClockTimer.cpp @@ -50,7 +50,7 @@ void WallClockTimer::stop() Instrument::MeasurementsMap WallClockTimer::measurements() const { const auto delta = std::chrono::duration_cast(_stop - _start); - return MeasurementsMap{ { "Wall clock time", Measurement(delta.count(), "us") } }; + return MeasurementsMap{ { "Wall clock time", Measurement(delta.count() / _scale_factor, _unit) } }; } } // namespace framework } // namespace test diff --git a/tests/framework/instruments/WallClockTimer.h b/tests/framework/instruments/WallClockTimer.h index fd2b18c3fb..468f4d3a8f 100644 --- a/tests/framework/instruments/WallClockTimer.h +++ b/tests/framework/instruments/WallClockTimer.h @@ -38,6 +38,27 @@ namespace framework class WallClockTimer : public Instrument { public: + WallClockTimer(ScaleFactor scale_factor) + { + switch(scale_factor) + { + case ScaleFactor::NONE: + _scale_factor = 1.f; + _unit = "us"; + break; + case ScaleFactor::TIME_MS: + _scale_factor = 1000.f; + _unit = "ms"; + break; + case ScaleFactor::TIME_S: + _scale_factor = 1000000.f; + _unit = "s"; + break; + default: + ARM_COMPUTE_ERROR("Invalid scale"); + } + }; + std::string id() const override; void start() override; void stop() override; @@ -46,6 +67,7 @@ public: private: std::chrono::high_resolution_clock::time_point _start{}; std::chrono::high_resolution_clock::time_point _stop{}; + float _scale_factor{}; }; } // namespace framework } // namespace test -- cgit v1.2.1