Compute Library
 21.05
SchedulerClock< output_timestamps > Class Template Reference

Instrument creating measurements based on the information returned by clGetEventProfilingInfo for each OpenCL kernel executed. More...

#include <SchedulerTimer.h>

Collaboration diagram for SchedulerClock< output_timestamps >:
[legend]

Data Structures

struct  kernel_info
 Kernel information. More...
 

Public Member Functions

 SchedulerClock (ScaleFactor scale_factor)
 Construct a Scheduler timer. More...
 
 SchedulerClock (const SchedulerClock &)=delete
 Prevent instances of this class from being copy constructed. More...
 
SchedulerClockoperator= (const SchedulerClock &)=delete
 Prevent instances of this class from being copied. More...
 
SchedulerClockoperator= (SchedulerClock &&)=default
 Use the default move assignment operator. More...
 
 SchedulerClock (SchedulerClock &&)=default
 Use the default move constructor. More...
 
 ~SchedulerClock ()=default
 Use the default destructor. More...
 
std::string id () const override
 Identifier for the instrument. More...
 
void test_start () override
 Start of the test. More...
 
void start () override
 Start measuring. More...
 
void test_stop () override
 End of the test. More...
 
Instrument::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 stop ()
 Stop measuring. 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

template<bool output_timestamps>
class arm_compute::test::framework::SchedulerClock< output_timestamps >

Instrument creating measurements based on the information returned by clGetEventProfilingInfo for each OpenCL kernel executed.

Definition at line 63 of file SchedulerTimer.h.

Constructor & Destructor Documentation

◆ SchedulerClock() [1/3]

SchedulerClock ( ScaleFactor  scale_factor)

Construct a Scheduler timer.

Parameters
[in]scale_factorMeasurement scale factor.

Definition at line 135 of file SchedulerTimer.cpp.

136  : _kernels(), _real_scheduler(nullptr), _real_scheduler_type(), _real_graph_function(nullptr), _scale_factor(scale_factor), _interceptor(nullptr), _scheduler_users()
137 {
138  if(instruments_info != nullptr)
139  {
140  _scheduler_users = instruments_info->_scheduler_users;
141  }
142 }
std::unique_ptr< InstrumentsInfo > instruments_info
Definition: Framework.cpp:50

References arm_compute::test::framework::instruments_info.

◆ SchedulerClock() [2/3]

SchedulerClock ( const SchedulerClock< output_timestamps > &  )
delete

Prevent instances of this class from being copy constructed.

◆ SchedulerClock() [3/3]

SchedulerClock ( SchedulerClock< output_timestamps > &&  )
default

Use the default move constructor.

◆ ~SchedulerClock()

~SchedulerClock ( )
default

Use the default destructor.

Member Function Documentation

◆ id()

std::string id ( ) const
overridevirtual

Identifier for the instrument.

Implements Instrument.

Definition at line 39 of file SchedulerTimer.cpp.

40 {
41  if(output_timestamps)
42  {
43  return "SchedulerTimestamps";
44  }
45  else
46  {
47  return "SchedulerTimer";
48  }
49 }

◆ measurements()

Instrument::MeasurementsMap measurements ( ) const
overridevirtual

Return the latest measurements.

Returns
the latest measurements.

Reimplemented from Instrument.

Definition at line 225 of file SchedulerTimer.cpp.

226 {
228  unsigned int kernel_number = 0;
229  for(auto kernel : _kernels)
230  {
231  std::string name = kernel.prefix + kernel.name + " #" + support::cpp11::to_string(kernel_number++);
232  if(output_timestamps)
233  {
234  ARM_COMPUTE_ERROR_ON(kernel.measurements.size() != 2);
235  for(auto const &m : kernel.measurements)
236  {
237  if(m.first.find("[start]") != std::string::npos)
238  {
239  measurements.emplace("[start]" + name, m.second);
240  }
241  else if(m.first.find("[end]") != std::string::npos)
242  {
243  measurements.emplace("[end]" + name, m.second);
244  }
245  else
246  {
247  ARM_COMPUTE_ERROR("Measurement not handled");
248  }
249  }
250  }
251  else
252  {
253  measurements.emplace(name, kernel.measurements.begin()->second);
254  }
255  }
256 
257  return measurements;
258 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
std::string to_string(T &&value)
Convert integer and float values to string.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Instrument::MeasurementsMap measurements() const override
Return the latest measurements.
const char * name
std::map< std::string, Measurement > MeasurementsMap
Map of measurements.
Definition: Instrument.h:109

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, name, and arm_compute::support::cpp11::to_string().

◆ operator=() [1/2]

SchedulerClock& operator= ( const SchedulerClock< output_timestamps > &  )
delete

Prevent instances of this class from being copied.

◆ operator=() [2/2]

SchedulerClock& operator= ( SchedulerClock< output_timestamps > &&  )
default

Use the default move assignment operator.

◆ start()

void start ( )
overridevirtual

Start measuring.

Called just before the run of the test starts

Reimplemented from Instrument.

Definition at line 198 of file SchedulerTimer.cpp.

199 {
200  _kernels.clear();
201 }

◆ test_start()

void test_start ( )
overridevirtual

Start of the test.

Called before the test set up starts

Reimplemented from Instrument.

Definition at line 145 of file SchedulerTimer.cpp.

146 {
147  // Start intercepting tasks:
148  ARM_COMPUTE_ERROR_ON(_real_graph_function != nullptr);
149  _real_graph_function = graph::TaskExecutor::get().execute_function;
150  auto task_interceptor = [this](graph::ExecutionTask & task)
151  {
152  Interceptor<output_timestamps> *scheduler = nullptr;
153  if(dynamic_cast<Interceptor<output_timestamps> *>(this->_interceptor.get()) != nullptr)
154  {
155  scheduler = arm_compute::utils::cast::polymorphic_downcast<Interceptor<output_timestamps> *>(_interceptor.get());
156  if(task.node != nullptr && !task.node->name().empty())
157  {
158  scheduler->set_prefix(task.node->name() + "/");
159  }
160  else
161  {
162  scheduler->set_prefix("");
163  }
164  }
165 
166  this->_real_graph_function(task);
167 
168  if(scheduler != nullptr)
169  {
170  scheduler->set_prefix("");
171  }
172  };
173 
174  ARM_COMPUTE_ERROR_ON(_real_scheduler != nullptr);
175  _real_scheduler_type = Scheduler::get_type();
176  //Note: We can't currently replace a custom scheduler
177  if(_real_scheduler_type != Scheduler::Type::CUSTOM)
178  {
179  _real_scheduler = &Scheduler::get();
180  _interceptor = std::make_shared<Interceptor<output_timestamps>>(_kernels, *_real_scheduler, _scale_factor);
181  Scheduler::set(std::static_pointer_cast<IScheduler>(_interceptor));
182  graph::TaskExecutor::get().execute_function = task_interceptor;
183 
184  // Create an interceptor for each scheduler
185  // TODO(COMPID-2638) : Allow multiple schedulers, now it assumes the same scheduler is used.
186  std::for_each(std::begin(_scheduler_users), std::end(_scheduler_users),
187  [&](ISchedulerUser * user)
188  {
189  if(user != nullptr && user->scheduler() != nullptr)
190  {
191  user->intercept_scheduler(std::make_unique<Interceptor<output_timestamps>>(_kernels, *user->scheduler(), _scale_factor));
192  }
193  });
194  }
195 }
static void set(std::shared_ptr< IScheduler > scheduler)
Sets the user defined scheduler and makes it the active scheduler.
Definition: Scheduler.cpp:126
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
static TaskExecutor & get()
Task executor accessor.
Definition: Workload.cpp:75
void for_each(F &&)
Base case of for_each.
Definition: Utility.h:110
static Type get_type()
Returns the type of the active scheduler.
Definition: Scheduler.cpp:89
std::function< decltype(execute_task)> execute_function
Function that is responsible for executing tasks.
Definition: Workload.h:63
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94

References ARM_COMPUTE_ERROR_ON, Scheduler::CUSTOM, arm_compute::mlgo::parser::end(), TaskExecutor::execute_function, arm_compute::utility::for_each(), Scheduler::get(), TaskExecutor::get(), Scheduler::get_type(), ISchedulerUser::intercept_scheduler(), ISchedulerUser::scheduler(), and Scheduler::set().

◆ test_stop()

void test_stop ( )
overridevirtual

End of the test.

Called after the test teardown ended

Reimplemented from Instrument.

Definition at line 204 of file SchedulerTimer.cpp.

205 {
206  // Restore real scheduler
207  Scheduler::set(_real_scheduler_type);
208  _real_scheduler = nullptr;
209  _interceptor = nullptr;
210  graph::TaskExecutor::get().execute_function = _real_graph_function;
211  _real_graph_function = nullptr;
212 
213  // Restore schedulers
214  std::for_each(std::begin(_scheduler_users), std::end(_scheduler_users),
215  [&](ISchedulerUser * user)
216  {
217  if(user != nullptr)
218  {
219  user->restore_scheduler();
220  }
221  });
222 }
static void set(std::shared_ptr< IScheduler > scheduler)
Sets the user defined scheduler and makes it the active scheduler.
Definition: Scheduler.cpp:126
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
static TaskExecutor & get()
Task executor accessor.
Definition: Workload.cpp:75
void for_each(F &&)
Base case of for_each.
Definition: Utility.h:110
std::function< decltype(execute_task)> execute_function
Function that is responsible for executing tasks.
Definition: Workload.h:63

References arm_compute::mlgo::parser::end(), TaskExecutor::execute_function, arm_compute::utility::for_each(), TaskExecutor::get(), ISchedulerUser::restore_scheduler(), and Scheduler::set().


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