Compute Library
 21.02
CPPScheduler Class Referencefinal

C++11 implementation of a pool of threads to automatically split a kernel's execution among several threads. More...

#include <CPPScheduler.h>

Collaboration diagram for CPPScheduler:
[legend]

Public Member Functions

 CPPScheduler ()
 Constructor: create a pool of threads. More...
 
 ~CPPScheduler ()
 Default destructor. More...
 
void set_num_threads (unsigned int num_threads) override
 Sets the number of threads the scheduler will use to run the kernels. More...
 
void set_num_threads_with_affinity (unsigned int num_threads, BindFunc func) override
 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...
 
unsigned int num_threads () const override
 Returns the number of threads that the SingleThreadScheduler has in his pool. More...
 
void schedule (ICPPKernel *kernel, const Hints &hints) override
 Runs the kernel in the same thread as the caller synchronously. More...
 
void schedule_op (ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors) override
 Runs the kernel in the same thread as the caller synchronously. More...
 
- Public Member Functions inherited from IScheduler
 IScheduler ()
 Default constructor. More...
 
virtual ~IScheduler ()=default
 Destructor. 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 Member Functions

static CPPSchedulerget ()
 Access the scheduler singleton. More...
 

Additional Inherited Members

- Public Types inherited from IScheduler
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...
 
- Static Public Attributes inherited from IScheduler
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

C++11 implementation of a pool of threads to automatically split a kernel's execution among several threads.

Definition at line 35 of file CPPScheduler.h.

Constructor & Destructor Documentation

◆ CPPScheduler()

Constructor: create a pool of threads.

Definition at line 284 of file CPPScheduler.cpp.

References CPPScheduler::~CPPScheduler().

285  : _impl(std::make_unique<Impl>(num_threads_hint()))
286 {
287 }
unsigned int num_threads_hint() const
Get a hint for the best possible number of execution threads.
Definition: IScheduler.cpp:53

◆ ~CPPScheduler()

~CPPScheduler ( )
default

Default destructor.

Referenced by CPPScheduler::CPPScheduler().

Member Function Documentation

◆ get()

CPPScheduler & get ( )
static

Access the scheduler singleton.

Note
this method has been deprecated and will be remover in future releases
Returns
The scheduler

Definition at line 278 of file CPPScheduler.cpp.

279 {
280  static CPPScheduler scheduler;
281  return scheduler;
282 }
CPPScheduler()
Constructor: create a pool of threads.

◆ num_threads()

unsigned int num_threads ( ) const
overridevirtual

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

Returns
Number of threads available in SingleThreadScheduler.

Implements IScheduler.

Definition at line 305 of file CPPScheduler.cpp.

References arm_compute::test::validation::info, and tf_frozen_model_extractor::t.

306 {
307  return _impl->num_threads();
308 }

◆ schedule()

void schedule ( ICPPKernel kernel,
const Hints hints 
)
overridevirtual

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

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

Implements IScheduler.

Definition at line 360 of file CPPScheduler.cpp.

References IKernel::window().

361 {
362  ITensorPack tensors;
363  schedule_common(kernel, hints, kernel->window(), tensors);
364 }

◆ schedule_op()

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

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.

Implements IScheduler.

Definition at line 355 of file CPPScheduler.cpp.

356 {
357  schedule_common(kernel, hints, window, tensors);
358 }

◆ set_num_threads()

void set_num_threads ( unsigned int  num_threads)
overridevirtual

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.

Implements IScheduler.

Definition at line 291 of file CPPScheduler.cpp.

References IScheduler::num_threads_hint().

292 {
293  // No changes in the number of threads while current workloads are running
294  arm_compute::lock_guard<std::mutex> lock(_impl->_run_workloads_mutex);
295  _impl->set_num_threads(num_threads, num_threads_hint());
296 }
unsigned int num_threads() const override
Returns the number of threads that the SingleThreadScheduler has in his pool.
unsigned int num_threads_hint() const
Get a hint for the best possible number of execution threads.
Definition: IScheduler.cpp:53
std::lock_guard< Mutex > lock_guard
Wrapper of lock_guard data-object.
Definition: Mutex.h:37

◆ set_num_threads_with_affinity()

void set_num_threads_with_affinity ( unsigned int  num_threads,
BindFunc  func 
)
overridevirtual

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 from IScheduler.

Definition at line 298 of file CPPScheduler.cpp.

References IScheduler::num_threads_hint().

299 {
300  // No changes in the number of threads while current workloads are running
301  arm_compute::lock_guard<std::mutex> lock(_impl->_run_workloads_mutex);
302  _impl->set_num_threads_with_affinity(num_threads, num_threads_hint(), func);
303 }
unsigned int num_threads() const override
Returns the number of threads that the SingleThreadScheduler has in his pool.
FloorUKernelPtr func
unsigned int num_threads_hint() const
Get a hint for the best possible number of execution threads.
Definition: IScheduler.cpp:53
std::lock_guard< Mutex > lock_guard
Wrapper of lock_guard data-object.
Definition: Mutex.h:37

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