Compute Library
 21.05
MaliCounter Class Reference

Instrument implementation for mali hw counters. More...

#include <MaliCounter.h>

Collaboration diagram for MaliCounter:
[legend]

Public Member Functions

 MaliCounter (ScaleFactor scale_factor)
 Default constructor. More...
 
 MaliCounter (const MaliCounter &)=delete
 Prevent instances of this class from being copy constructed. More...
 
MaliCounteroperator= (const MaliCounter &)=delete
 Prevent instances of this class from being copied. More...
 
 ~MaliCounter ()
 Default destructor. More...
 
std::string id () const override
 Identifier for the instrument. More...
 
void start () override
 Start measuring. More...
 
void stop () override
 Stop measuring. More...
 
MeasurementsMap measurements () const override
 Return the latest measurements. More...
 
- Public Member Functions inherited from Instrument
 Instrument ()=default
 Default constructor. More...
 
 Instrument (const Instrument &)=default
 Allow instances of this class to be copy constructed. More...
 
 Instrument (Instrument &&)=default
 Allow instances of this class to be move constructed. More...
 
Instrumentoperator= (const Instrument &)=default
 Allow instances of this class to be copied. More...
 
Instrumentoperator= (Instrument &&)=default
 Allow instances of this class to be moved. More...
 
virtual ~Instrument ()=default
 Default destructor. More...
 
virtual void test_start ()
 Start of the test. More...
 
virtual void test_stop ()
 End of the test. More...
 
virtual MeasurementsMap test_measurements () const
 Return the latest test measurements. More...
 

Additional Inherited Members

- Public Types inherited from Instrument
using MeasurementsMap = std::map< std::string, Measurement >
 Map of measurements. More...
 
- Static Public Member Functions inherited from Instrument
template<typename T , ScaleFactor scale>
static std::unique_ptr< Instrumentmake_instrument ()
 Helper function to create an instrument of the given type. More...
 

Detailed Description

Instrument implementation for mali hw counters.

Definition at line 41 of file MaliCounter.h.

Constructor & Destructor Documentation

◆ MaliCounter() [1/2]

MaliCounter ( ScaleFactor  scale_factor)

Default constructor.

Parameters
[in]scale_factorMeasurement scale factor;

Definition at line 110 of file MaliCounter.cpp.

111 {
112  _counters =
113  {
114  { "GPU_ACTIVE", Measurement(0, "cycles") },
115  };
116 
117  _core_counters =
118  {
119  { "ARITH_WORDS", { "Arithmetic pipe", std::map<int, uint64_t>(), "instructions" } },
120  { "LS_ISSUE", { "LS pipe", std::map<int, uint64_t>(), "instructions" } },
121  { "TEX_ISSUE", { "Texture pipe", std::map<int, uint64_t>(), "instructions" } },
122  { "COMPUTE_ACTIVE", { "Compute core", std::map<int, uint64_t>(), "cycles" } },
123  { "FRAG_ACTIVE", { "Fragment core", std::map<int, uint64_t>(), "cycles" } },
124  };
125 
126  switch(scale_factor)
127  {
128  case ScaleFactor::NONE:
129  _scale_factor = 1;
130  _unit = "";
131  break;
133  _scale_factor = 1000;
134  _unit = "K ";
135  break;
137  _scale_factor = 1000000;
138  _unit = "M ";
139  break;
140  default:
141  ARM_COMPUTE_ERROR("Invalid scale");
142  }
143 
144  init();
145 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352

References ARM_COMPUTE_ERROR, arm_compute::test::framework::NONE, arm_compute::test::framework::SCALE_1K, and arm_compute::test::framework::SCALE_1M.

◆ MaliCounter() [2/2]

MaliCounter ( const MaliCounter )
delete

Prevent instances of this class from being copy constructed.

◆ ~MaliCounter()

Default destructor.

Definition at line 147 of file MaliCounter.cpp.

148 {
149  term();
150 }

Member Function Documentation

◆ id()

std::string id ( ) const
overridevirtual

Identifier for the instrument.

Implements Instrument.

Definition at line 418 of file MaliCounter.cpp.

419 {
420  return "Mali Counter";
421 }

◆ measurements()

Instrument::MeasurementsMap measurements ( ) const
overridevirtual

Return the latest measurements.

Returns
the latest measurements.

Reimplemented from Instrument.

Definition at line 423 of file MaliCounter.cpp.

424 {
425  Measurement counters((_counters.at("GPU_ACTIVE").value() / _scale_factor).v.floating_point, _unit + _counters.at("GPU_ACTIVE").unit()); //NOLINT
426 
428  {
429  { "Timespan", Measurement(_stop_time - _start_time, "ns") },
430  { "GPU active", counters },
431  };
432 
433  for(const auto &counter : _core_counters)
434  {
435  for(const auto &core : counter.second.values)
436  {
437  measurements.emplace(counter.second.name + " #" + support::cpp11::to_string(core.first), Measurement(core.second / _scale_factor, _unit + counter.second.unit));
438  }
439  }
440 
441  return measurements;
442 }
std::string to_string(T &&value)
Convert integer and float values to string.
MeasurementsMap measurements() const override
Return the latest measurements.
std::map< std::string, Measurement > MeasurementsMap
Map of measurements.
Definition: Instrument.h:109

References arm_compute::support::cpp11::to_string().

◆ operator=()

MaliCounter& operator= ( const MaliCounter )
delete

Prevent instances of this class from being copied.

◆ start()

void start ( )
overridevirtual

Start measuring.

Called just before the run of the test starts

Reimplemented from Instrument.

Definition at line 382 of file MaliCounter.cpp.

383 {
384  sample_counters();
385  wait_next_event();
386  _start_time = _timestamp;
387 }

◆ stop()

void stop ( )
overridevirtual

Stop measuring.

Called just after the run of the test ends

Reimplemented from Instrument.

Definition at line 389 of file MaliCounter.cpp.

390 {
391  sample_counters();
392  wait_next_event();
393 
394  const uint32_t *counter = get_counters(mali_userspace::MALI_NAME_BLOCK_JM);
395  _counters.at("GPU_ACTIVE") = Measurement(counter[find_counter_index_by_name(mali_userspace::MALI_NAME_BLOCK_JM, "GPU_ACTIVE")], _counters.at("GPU_ACTIVE").unit());
396 
397  const int arith_index = find_counter_index_by_name(mali_userspace::MALI_NAME_BLOCK_SHADER, "ARITH_WORDS");
398  const int ls_index = find_counter_index_by_name(mali_userspace::MALI_NAME_BLOCK_SHADER, "LS_ISSUE");
399  const int tex_index = find_counter_index_by_name(mali_userspace::MALI_NAME_BLOCK_SHADER, "TEX_ISSUE");
400  const int compute_index = find_counter_index_by_name(mali_userspace::MALI_NAME_BLOCK_SHADER, "COMPUTE_ACTIVE");
401  const int frag_index = find_counter_index_by_name(mali_userspace::MALI_NAME_BLOCK_SHADER, "FRAG_ACTIVE");
402 
403  // Shader core counters can be averaged if desired, but here we don't.
404  for(uint32_t core = 0; core < _num_cores; ++core)
405  {
406  const uint32_t *sc_counter = get_counters(mali_userspace::MALI_NAME_BLOCK_SHADER, core);
407 
408  _core_counters.at("ARITH_WORDS").values[core] = sc_counter[arith_index];
409  _core_counters.at("LS_ISSUE").values[core] = sc_counter[ls_index];
410  _core_counters.at("TEX_ISSUE").values[core] = sc_counter[tex_index];
411  _core_counters.at("COMPUTE_ACTIVE").values[core] = sc_counter[compute_index];
412  _core_counters.at("FRAG_ACTIVE").values[core] = sc_counter[frag_index];
413  }
414 
415  _stop_time = _timestamp;
416 }

The documentation for this class was generated from the following files: