Compute Library
 21.02
IScheduler Class Referenceabstract

Scheduler interface to run kernels. More...

#include <IScheduler.h>

Data Structures

class  Hints
 Scheduler hints. More...
 

Public Types

enum  StrategyHint { STATIC, DYNAMIC }
 Strategies available to split a workload. More...
 
using BindFunc = std::function< int(int, int)>
 Function to be used and map a given thread id to a logical core id. More...
 
using Workload = std::function< void(const ThreadInfo &)>
 Signature for the workloads to execute. More...
 

Public Member Functions

 IScheduler ()
 Default constructor. More...
 
virtual ~IScheduler ()=default
 Destructor. More...
 
virtual void set_num_threads (unsigned int num_threads)=0
 Sets the number of threads the scheduler will use to run the kernels. More...
 
virtual void set_num_threads_with_affinity (unsigned int num_threads, BindFunc func)
 Sets the number of threads the scheduler will use to run the kernels but also using a binding function to pin the threads to given logical cores. More...
 
virtual unsigned int num_threads () const =0
 Returns the number of threads that the SingleThreadScheduler has in his pool. More...
 
virtual void schedule (ICPPKernel *kernel, const Hints &hints)=0
 Runs the kernel in the same thread as the caller synchronously. More...
 
virtual void schedule_op (ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors)=0
 Runs the kernel in the same thread as the caller synchronously. More...
 
virtual void run_tagged_workloads (std::vector< Workload > &workloads, const char *tag)
 Execute all the passed workloads. More...
 
CPUInfocpu_info ()
 Get CPU info. More...
 
unsigned int num_threads_hint () const
 Get a hint for the best possible number of execution threads. More...
 

Static Public Attributes

static constexpr unsigned int split_dimensions_all = std::numeric_limits<unsigned>::max()
 When arm_compute::ISchedular::Hints::_split_dimension is initialized with this value then the schedular is free to break down the problem space over as many dimensions as it wishes. More...
 

Detailed Description

Scheduler interface to run kernels.

Definition at line 41 of file IScheduler.h.

Member Typedef Documentation

◆ BindFunc

using BindFunc = std::function<int(int, int)>

Function to be used and map a given thread id to a logical core id.

Mapping function expects the thread index and total number of cores as input, and returns the logical core index to bind against

Definition at line 56 of file IScheduler.h.

◆ Workload

using Workload = std::function<void(const ThreadInfo &)>

Signature for the workloads to execute.

Definition at line 135 of file IScheduler.h.

Member Enumeration Documentation

◆ StrategyHint

enum StrategyHint
strong

Strategies available to split a workload.

Enumerator
STATIC 

Split the workload evenly among the threads.

DYNAMIC 

Split the workload dynamically using a bucket system.

Definition at line 45 of file IScheduler.h.

46  {
47  STATIC, /**< Split the workload evenly among the threads */
48  DYNAMIC, /**< Split the workload dynamically using a bucket system */
49  };

Constructor & Destructor Documentation

◆ IScheduler()

Default constructor.

Definition at line 34 of file IScheduler.cpp.

References arm_compute::utils::cpu::get_cpu_configuration(), and arm_compute::utils::cpu::get_threads_hint().

35  : _cpu_info()
36 {
38  // Work out the best possible number of execution threads
39  _num_threads_hint = utils::cpu::get_threads_hint();
40 }
void get_cpu_configuration(CPUInfo &cpuinfo)
This function will try to detect the CPU configuration on the system and will fill the cpuinfo object...
Definition: CPUUtils.cpp:359
unsigned int get_threads_hint()
Some systems have both big and small cores, this fuction computes the minimum number of cores that ar...
Definition: CPUUtils.cpp:414

◆ ~IScheduler()

virtual ~IScheduler ( )
virtualdefault

Destructor.

Member Function Documentation

◆ cpu_info()

CPUInfo & cpu_info ( )

Get CPU info.

Returns
CPU info.

Definition at line 42 of file IScheduler.cpp.

Referenced by CpuPoolingAssemblyDispatch::configure(), NEConvolutionLayer::get_convolution_method(), and main().

43 {
44  return _cpu_info;
45 }

◆ num_threads()

virtual unsigned int num_threads ( ) const
pure virtual

Returns the number of threads that the SingleThreadScheduler has in his pool.

Returns
Number of threads available in SingleThreadScheduler.

Implemented in CPPScheduler, OMPScheduler, and SingleThreadScheduler.

Referenced by CpuPoolingAssemblyDispatch::configure(), NEHistogram::configure(), NEWinogradConvolutionLayer::configure(), and IScheduler::num_threads_hint().

◆ num_threads_hint()

unsigned int num_threads_hint ( ) const

◆ run_tagged_workloads()

void run_tagged_workloads ( std::vector< Workload > &  workloads,
const char *  tag 
)
virtual

Execute all the passed workloads.

Note
there is no guarantee regarding the order in which the workloads will be executed or whether or not they will be executed in parallel.
Parameters
[in]workloadsArray of workloads to run
[in]tagString that can be used by profiling tools to identify the workloads run by the scheduler (Can be null).

Definition at line 170 of file IScheduler.cpp.

References ARM_COMPUTE_UNUSED.

171 {
172  ARM_COMPUTE_UNUSED(tag);
173  run_workloads(workloads);
174 }
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

◆ schedule()

virtual void schedule ( ICPPKernel kernel,
const Hints hints 
)
pure virtual

Runs the kernel in the same thread as the caller synchronously.

Parameters
[in]kernelKernel to execute.
[in]hintsHints for the scheduler.

Implemented in OMPScheduler, CPPScheduler, and SingleThreadScheduler.

Referenced by NEWinogradConvolutionLayer::prepare(), NEGEMM::prepare(), NEGEMMLowpMatrixMultiplyCore::prepare(), NEQLSTMLayer::prepare(), ICPPSimpleFunction::run(), INESimpleFunction::run(), NEFillBorder::run(), NEMeanStdDev::run(), NEHistogram::run(), NEConvertFullyConnectedWeights::run(), NEDerivative::run(), NEROIPoolingLayer::run(), NEEqualizeHistogram::run(), NESpaceToDepthLayer::run(), NEHOGDescriptor::run(), NEGaussian5x5::run(), NERange::run(), NEHOGGradient::run(), NEMinMaxLocation::run(), NESobel5x5::run(), NESobel7x7::run(), NEL2NormalizeLayer::run(), NEMaxUnpoolingLayer::run(), NEReductionOperation::run(), NEStackLayer::run(), NEFastCorners::run(), NEFFT1D::run(), NENormalizationLayer::run(), NEInstanceNormalizationLayer::run(), NEWinogradConvolutionLayer::run(), CPPBoxWithNonMaximaSuppressionLimit::run(), NECannyEdge::run(), NEConvolutionLayerReshapeWeights::run(), NEOpticalFlow::run(), NEPadLayer::run(), NECropResize::run(), NEFuseBatchNormalization::run(), NEBatchNormalizationLayer::run(), NEHOGMultiDetection::run(), NEHarrisCorners::run(), NESpaceToBatchLayer::run(), NEGEMM::run(), NEDirectConvolutionLayer::run(), CLHarrisCorners::run(), NEGaussianPyramidHalf::run(), NEGenerateProposalsLayer::run(), NEGEMMLowpMatrixMultiplyCore::run(), CLHOGMultiDetection::run(), NEConvolutionSquare< matrix_size >::run(), NEQLSTMLayer::run(), NEGEMMConvolutionLayer::run(), and arm_compute::utils::schedule_kernel_on_ctx().

◆ schedule_op()

virtual void schedule_op ( ICPPKernel kernel,
const Hints hints,
const Window window,
ITensorPack tensors 
)
pure virtual

Runs the kernel in the same thread as the caller synchronously.

Parameters
[in]kernelKernel to execute.
[in]hintsHints for the scheduler.
[in]windowWindow to use for kernel execution.
[in]tensorsVector containing the tensors to operate on.

Implemented in OMPScheduler, SingleThreadScheduler, and CPPScheduler.

Referenced by INEOperator::run(), NELogicalAnd::run(), CpuConcatenate::run(), CpuPoolingAssemblyDispatch::run(), CpuSoftmaxGeneric< IS_LOG >::run(), CpuPooling::run(), NELogicalOr::run(), and NELogicalNot::run().

◆ set_num_threads()

virtual void set_num_threads ( unsigned int  num_threads)
pure virtual

Sets the number of threads the scheduler will use to run the kernels.

Parameters
[in]num_threadsIf set to 0, then one thread per CPU core available on the system will be used, otherwise the number of threads specified.

Implemented in CPPScheduler, OMPScheduler, and SingleThreadScheduler.

Referenced by main(), and NEDeviceBackend::setup_backend_context().

◆ set_num_threads_with_affinity()

void set_num_threads_with_affinity ( unsigned int  num_threads,
BindFunc  func 
)
virtual

Sets the number of threads the scheduler will use to run the kernels but also using a binding function to pin the threads to given logical cores.

Parameters
[in]num_threadsIf set to 0, then one thread per CPU core available on the system will be used, otherwise the number of threads specified.
[in]funcBinding function to use.

Reimplemented in CPPScheduler.

Definition at line 47 of file IScheduler.cpp.

References ARM_COMPUTE_ERROR, and ARM_COMPUTE_UNUSED.

48 {
50  ARM_COMPUTE_ERROR("Feature for affinity setting is not implemented");
51 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
FloorUKernelPtr func
virtual unsigned int num_threads() const =0
Returns the number of threads that the SingleThreadScheduler has in his pool.

Field Documentation

◆ split_dimensions_all

constexpr unsigned int split_dimensions_all = std::numeric_limits<unsigned>::max()
static

When arm_compute::ISchedular::Hints::_split_dimension is initialized with this value then the schedular is free to break down the problem space over as many dimensions as it wishes.

Definition at line 62 of file IScheduler.h.

Referenced by IScheduler::num_threads_hint(), and SingleThreadScheduler::schedule().


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