Compute Library
 21.05
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.

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:405
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:491

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

◆ ~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.

43 {
44  return _cpu_info;
45 }

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

◆ num_threads()

virtual unsigned int num_threads ( ) const
pure virtual

◆ num_threads_hint()

unsigned int num_threads_hint ( ) const

Get a hint for the best possible number of execution threads.

Warning
In case we can't work out the best number of threads, std::thread::hardware_concurrency() is returned else 1 in case of bare metal builds
Returns
Best possible number of execution threads to use

Definition at line 53 of file IScheduler.cpp.

54 {
55  return _num_threads_hint;
56 }

Referenced by CPPScheduler::set_num_threads(), and CPPScheduler::set_num_threads_with_affinity().

◆ 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.

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

References ARM_COMPUTE_UNUSED.

◆ schedule()

◆ schedule_op()

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

◆ 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.

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.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_UNUSED, func, and IScheduler::num_threads().

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 SingleThreadScheduler::schedule().


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