Compute Library
 22.08
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 its 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 35 of file IScheduler.cpp.

References arm_compute::cpuinfo::num_threads_hint().

36 {
37  // Work out the best possible number of execution threads
38  _num_threads_hint = cpuinfo::num_threads_hint();
39 }
uint32_t num_threads_hint()
Some systems have both big and small cores, this fuction computes the minimum number of cores that ar...
Definition: CpuInfo.cpp:391

◆ ~IScheduler()

virtual ~IScheduler ( )
virtualdefault

Destructor.

Member Function Documentation

◆ cpu_info()

◆ num_threads()

virtual unsigned int num_threads ( ) const
pure virtual

◆ num_threads_hint()

◆ 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 172 of file IScheduler.cpp.

References ARM_COMPUTE_LOG_INFO_MSG_CORE, ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE, ARM_COMPUTE_UNUSED, IScheduler::cpu_info(), Window::DimW, Window::DimX, Window::DimY, ICPPKernel::get_mws(), Window::num_iterations(), and tf_frozen_model_extractor::t.

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

◆ schedule()

◆ schedule_op()

◆ 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 46 of file IScheduler.cpp.

References ARM_COMPUTE_ERROR, and ARM_COMPUTE_UNUSED.

47 {
49  ARM_COMPUTE_ERROR("Feature for affinity setting is not implemented");
50 }
#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
virtual unsigned int num_threads() const =0
Returns the number of threads that the SingleThreadScheduler has in its 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: