Compute Library
 19.08
Scheduler Class Reference

Configurable scheduler which supports multiple multithreading APIs and choosing between different schedulers at runtime. More...

#include <Scheduler.h>

Public Types

enum  Type { ST, CPP, OMP, CUSTOM }
 Scheduler type. More...
 

Static Public Member Functions

static void set (std::shared_ptr< IScheduler > scheduler)
 Sets the user defined scheduler and makes it the active scheduler. More...
 
static ISchedulerget ()
 Access the scheduler singleton. More...
 
static void set (Type t)
 Set the active scheduler. More...
 
static Type get_type ()
 Returns the type of the active scheduler. More...
 
static bool is_available (Type t)
 Returns true if the given scheduler type is supported. More...
 

Detailed Description

Configurable scheduler which supports multiple multithreading APIs and choosing between different schedulers at runtime.

Definition at line 33 of file Scheduler.h.

Member Enumeration Documentation

◆ Type

enum Type
strong

Scheduler type.

Enumerator
ST 

Single thread.

CPP 

C++11 threads.

OMP 

OpenMP.

CUSTOM 

Provided by the user.

Definition at line 37 of file Scheduler.h.

38  {
39  ST,
40  CPP,
41  OMP,
42  CUSTOM
43  };

Member Function Documentation

◆ get()

IScheduler & get ( )
static

Access the scheduler singleton.

Returns
A reference to the scheduler object.

Definition at line 96 of file Scheduler.cpp.

97 {
98  switch(_scheduler_type)
99  {
100  case Type::ST:
101  {
103  }
104  case Type::CPP:
105  {
106 #if ARM_COMPUTE_CPP_SCHEDULER
107  return CPPScheduler::get();
108 #else /* ARM_COMPUTE_CPP_SCHEDULER */
109  ARM_COMPUTE_ERROR("Recompile with cppthreads=1 to use C++11 scheduler.");
110 #endif /* ARM_COMPUTE_CPP_SCHEDULER */
111  break;
112  }
113  case Type::OMP:
114  {
115 #if ARM_COMPUTE_OPENMP_SCHEDULER
116  return OMPScheduler::get();
117 #else /* ARM_COMPUTE_OPENMP_SCHEDULER */
118  ARM_COMPUTE_ERROR("Recompile with openmp=1 to use openmp scheduler.");
119 #endif /* ARM_COMPUTE_OPENMP_SCHEDULER */
120  break;
121  }
122  case Type::CUSTOM:
123  {
124  if(_custom_scheduler == nullptr)
125  {
126  ARM_COMPUTE_ERROR("No custom scheduler has been setup. Call set(std::shared_ptr<IScheduler> &scheduler) before Scheduler::get()");
127  }
128  else
129  {
130  return *_custom_scheduler;
131  }
132  break;
133  }
134  default:
135  {
136  ARM_COMPUTE_ERROR("Invalid Scheduler type");
137  break;
138  }
139  }
141 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
static CPPScheduler & get()
Access the scheduler singleton.
static SingleThreadScheduler & get()
Access the scheduler singleton.
static OMPScheduler & get()
Access the scheduler singleton.

References ARM_COMPUTE_ERROR, Scheduler::CPP, Scheduler::CUSTOM, OMPScheduler::get(), SingleThreadScheduler::get(), CPPScheduler::get(), Scheduler::OMP, and Scheduler::ST.

Referenced by NEHistogram::configure(), NEDepthwiseConvolutionAssemblyDispatch::configure(), NEWinogradConvolutionLayer::configure(), NEGEMMInterleavedWrapper::configure(), main(), NEWinogradConvolutionLayer::prepare(), NELocallyConnectedLayer::prepare(), NEGEMM::prepare(), NEGEMMLowpMatrixMultiplyCore::prepare(), NEDeconvolutionLayer::prepare(), NEGEMMInterleavedWrapper::prepare(), NEDepthwiseConvolutionLayer::prepare(), INESimpleFunctionNoBorder::run(), ICPPSimpleFunction::run(), INESimpleFunction::run(), NESimpleAssemblyFunction::run(), NEHistogram::run(), NEFillBorder::run(), NEMeanStdDev::run(), NEGEMMLowpAssemblyMatrixMultiplyCore::run(), NEConvertFullyConnectedWeights::run(), NEHOGDescriptor::run(), NEDerivative::run(), NEEqualizeHistogram::run(), NEROIPoolingLayer::run(), NEMinMaxLocation::run(), NEHOGGradient::run(), NERange::run(), NEGaussian5x5::run(), NEUpsampleLayer::run(), NESobel7x7::run(), NESobel5x5::run(), NEArgMinMaxLayer::run(), NEReductionOperation::run(), NEPoolingLayer::run(), NEFastCorners::run(), NEFFT1D::run(), NEL2NormalizeLayer::run(), NEStackLayer::run(), NESpaceToDepthLayer::run(), NEConvolutionLayerReshapeWeights::run(), NEIm2Col::run(), NENormalizationLayer::run(), NEPadLayer::run(), NEScale::run(), NEWinogradConvolutionLayer::run(), NERNNLayer::run(), NEConcatenateLayer::run(), NECannyEdge::run(), NEBatchNormalizationLayer::run(), NEOpticalFlow::run(), CLHarrisCorners::run(), NEHarrisCorners::run(), NESoftmaxLayer::run(), NEConvolutionSquare< matrix_size >::run(), NEHOGMultiDetection::run(), CLHOGMultiDetection::run(), NEGaussianPyramidHalf::run(), NELocallyConnectedLayer::run(), NECropResize::run(), NEGEMM::run(), NEFuseBatchNormalization::run(), NEDirectConvolutionLayer::run(), NESpaceToBatchLayer::run(), NEGEMMLowpMatrixMultiplyCore::run(), NEDepthwiseConvolutionAssemblyDispatch::run(), NEGEMMInterleavedWrapper::run(), NEFullyConnectedLayer::run(), NELSTMLayer::run(), NEGEMMConvolutionLayer::run(), NEDepthwiseConvolutionLayer::run(), NEDeviceBackend::setup_backend_context(), and SchedulerClock< output_timestamps >::test_start().

◆ get_type()

Scheduler::Type get_type ( )
static

Returns the type of the active scheduler.

Returns
The current scheduler's type.

Definition at line 91 of file Scheduler.cpp.

92 {
93  return _scheduler_type;
94 }

Referenced by SchedulerClock< output_timestamps >::test_start().

◆ is_available()

bool is_available ( Type  t)
static

Returns true if the given scheduler type is supported.

False otherwise.

Parameters
[in]tthe type of the scheduler to check.
Returns
true if the given scheduler type is supported. False otherwise.

Definition at line 55 of file Scheduler.cpp.

56 {
57  switch(t)
58  {
59  case Type::ST:
60  {
61  return true;
62  }
63  case Type::CPP:
64  {
65 #if ARM_COMPUTE_CPP_SCHEDULER
66  return true;
67 #else /* ARM_COMPUTE_CPP_SCHEDULER */
68  return false;
69 #endif /* ARM_COMPUTE_CPP_SCHEDULER */
70  }
71  case Type::OMP:
72  {
73 #if ARM_COMPUTE_OPENMP_SCHEDULER
74  return true;
75 #else /* ARM_COMPUTE_OPENMP_SCHEDULER */
76  return false;
77 #endif /* ARM_COMPUTE_OPENMP_SCHEDULER */
78  }
79  case Type::CUSTOM:
80  {
81  return _custom_scheduler != nullptr;
82  }
83  default:
84  {
85  ARM_COMPUTE_ERROR("Invalid Scheduler type");
86  return false;
87  }
88  }
89 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261

References ARM_COMPUTE_ERROR, Scheduler::CPP, Scheduler::CUSTOM, Scheduler::OMP, and Scheduler::ST.

Referenced by Scheduler::set().

◆ set() [1/2]

void set ( std::shared_ptr< IScheduler scheduler)
static

Sets the user defined scheduler and makes it the active scheduler.

Parameters
[in]schedulerA shared pointer to a custom scheduler implemented by the user.

Definition at line 145 of file Scheduler.cpp.

146 {
147  _custom_scheduler = std::move(scheduler);
148  set(Type::CUSTOM);
149 }
static void set(std::shared_ptr< IScheduler > scheduler)
Sets the user defined scheduler and makes it the active scheduler.
Definition: Scheduler.cpp:145

References Scheduler::CUSTOM.

Referenced by SchedulerClock< output_timestamps >::test_start(), and SchedulerClock< output_timestamps >::test_stop().

◆ set() [2/2]

void set ( Type  t)
static

Set the active scheduler.

Only one scheduler can be enabled at any time.

Parameters
[in]tthe type of the scheduler to be enabled.

Definition at line 49 of file Scheduler.cpp.

50 {
52  _scheduler_type = t;
53 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
static bool is_available(Type t)
Returns true if the given scheduler type is supported.
Definition: Scheduler.cpp:55

References ARM_COMPUTE_ERROR_ON, and Scheduler::is_available().


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