Compute Library
 21.02
SingleThreadScheduler Class Referencefinal

Pool of threads to automatically split a kernel's execution among several threads. More...

#include <SingleThreadScheduler.h>

Collaboration diagram for SingleThreadScheduler:
[legend]

Public Member Functions

 SingleThreadScheduler ()=default
 Constructor. More...
 
void set_num_threads (unsigned int num_threads) override
 Sets the number of threads the scheduler will use to run the kernels. More...
 
unsigned int num_threads () const override
 Returns the number of threads that the SingleThreadScheduler has, which is always 1. 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 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 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...
 

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

Pool of threads to automatically split a kernel's execution among several threads.

Definition at line 32 of file SingleThreadScheduler.h.

Constructor & Destructor Documentation

◆ SingleThreadScheduler()

SingleThreadScheduler ( )
default

Constructor.

Member Function Documentation

◆ num_threads()

unsigned int num_threads ( ) const
overridevirtual

Returns the number of threads that the SingleThreadScheduler has, which is always 1.

Returns
Number of threads available in SingleThreadScheduler.

Implements IScheduler.

Definition at line 73 of file SingleThreadScheduler.cpp.

74 {
75  return 1;
76 }

◆ 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 38 of file SingleThreadScheduler.cpp.

References ThreadInfo::cpu_info, arm_compute::test::validation::info, Window::num_iterations(), ICPPKernel::run(), IScheduler::Hints::split_dimension(), IScheduler::split_dimensions_all, and IKernel::window().

39 {
40  const Window &max_window = kernel->window();
41 
42  if(hints.split_dimension() != IScheduler::split_dimensions_all)
43  {
44  const unsigned int num_iterations = max_window.num_iterations(hints.split_dimension());
45  if(num_iterations < 1)
46  {
47  return;
48  }
49  }
50 
51  ThreadInfo info;
52  info.cpu_info = &_cpu_info;
53  kernel->run(kernel->window(), info);
54 }
static constexpr unsigned int split_dimensions_all
When arm_compute::ISchedular::Hints::_split_dimension is initialized with this value then the schedul...
Definition: IScheduler.h:62
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ 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 56 of file SingleThreadScheduler.cpp.

References ARM_COMPUTE_UNUSED, ThreadInfo::cpu_info, arm_compute::test::validation::info, and ICPPKernel::run_op().

57 {
58  ARM_COMPUTE_UNUSED(hints);
59  ThreadInfo info;
60  info.cpu_info = &_cpu_info;
61  kernel->run_op(tensors, window, info);
62 }
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ 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_threadsThis is ignored for this scheduler as the number of threads is always one.

Implements IScheduler.

Definition at line 32 of file SingleThreadScheduler.cpp.

References ARM_COMPUTE_ERROR_ON, and ARM_COMPUTE_UNUSED.

33 {
36 }
unsigned int num_threads() const override
Returns the number of threads that the SingleThreadScheduler has, which is always 1...
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

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