HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
onnxruntime::concurrency::ThreadPool Class Reference

#include <threadpool.h>

Classes

class  ParallelSection
 
struct  WorkInfo
 

Public Types

using NAME_CHAR_TYPE = char
 

Public Member Functions

 ThreadPool (Env *env, const ThreadOptions &thread_options, const NAME_CHAR_TYPE *name, int degree_of_parallelism, bool low_latency_hint, bool force_hybrid=false)
 
 ~ThreadPool ()
 
void EnableSpinning ()
 
void DisableSpinning ()
 
 ORT_DISALLOW_COPY_AND_ASSIGNMENT (ThreadPool)
 

Static Public Member Functions

static void Schedule (ThreadPool *tp, std::function< void()> fn)
 
static void TryParallelFor (ThreadPool *tp, std::ptrdiff_t total, double cost_per_unit, const std::function< void(std::ptrdiff_t first, std::ptrdiff_t last)> &fn)
 
static void TryParallelFor (ThreadPool *tp, std::ptrdiff_t total, const TensorOpCost &cost_per_unit, const std::function< void(std::ptrdiff_t first, std::ptrdiff_t last)> &fn)
 
static void TrySimpleParallelFor (ThreadPool *tp, std::ptrdiff_t total, const std::function< void(std::ptrdiff_t)> &fn)
 
template<typename F >
static void TryBatchParallelFor (ThreadPool *tp, std::ptrdiff_t total, F &&fn, std::ptrdiff_t num_batches)
 
static constexpr WorkInfo PartitionWork (std::ptrdiff_t batch_idx, std::ptrdiff_t num_batches, std::ptrdiff_t total_work)
 
static bool ShouldParallelize (const ThreadPool *tp)
 
static int DegreeOfParallelism (const ThreadPool *tp)
 
static void StartProfiling (concurrency::ThreadPool *tp)
 
static std::string StopProfiling (concurrency::ThreadPool *tp)
 

Friends

class LoopCounter
 

Detailed Description

Definition at line 140 of file threadpool.h.

Member Typedef Documentation

Definition at line 145 of file threadpool.h.

Constructor & Destructor Documentation

onnxruntime::concurrency::ThreadPool::ThreadPool ( Env *  env,
const ThreadOptions &  thread_options,
const NAME_CHAR_TYPE name,
int  degree_of_parallelism,
bool  low_latency_hint,
bool  force_hybrid = false 
)
onnxruntime::concurrency::ThreadPool::~ThreadPool ( )

Member Function Documentation

static int onnxruntime::concurrency::ThreadPool::DegreeOfParallelism ( const ThreadPool tp)
static
void onnxruntime::concurrency::ThreadPool::DisableSpinning ( )
void onnxruntime::concurrency::ThreadPool::EnableSpinning ( )
onnxruntime::concurrency::ThreadPool::ORT_DISALLOW_COPY_AND_ASSIGNMENT ( ThreadPool  )
static constexpr WorkInfo onnxruntime::concurrency::ThreadPool::PartitionWork ( std::ptrdiff_t  batch_idx,
std::ptrdiff_t  num_batches,
std::ptrdiff_t  total_work 
)
inlinestatic

Calculate the start and end offsets for a batch.

Remarks
Based on MlasPartitionWork

Definition at line 327 of file threadpool.h.

static void onnxruntime::concurrency::ThreadPool::Schedule ( ThreadPool tp,
std::function< void()>  fn 
)
inlinestatic

Definition at line 229 of file threadpool.h.

static bool onnxruntime::concurrency::ThreadPool::ShouldParallelize ( const ThreadPool tp)
static
static void onnxruntime::concurrency::ThreadPool::StartProfiling ( concurrency::ThreadPool tp)
static
static std::string onnxruntime::concurrency::ThreadPool::StopProfiling ( concurrency::ThreadPool tp)
static
template<typename F >
static void onnxruntime::concurrency::ThreadPool::TryBatchParallelFor ( ThreadPool tp,
std::ptrdiff_t  total,
F &&  fn,
std::ptrdiff_t  num_batches 
)
inlinestatic

Tries to call the given function in parallel, with calls split into (num_batches) batches.

Parameters
num_batchesIf it is zero, it will be replaced to the value of DegreeOfParallelism().
fnA std::function or STL style functor with signature of "void f(std::ptrdiff_t);" Pitfall: Caller should cap num_batches to a reasonable value based on the cost of fn and the value of total. For example, if fn is as simple as: int sum=0; fn = [&](int i){sum +=i;} and total is 100, then num_batches should be just 1.

```

Definition at line 284 of file threadpool.h.

static void onnxruntime::concurrency::ThreadPool::TryParallelFor ( ThreadPool tp,
std::ptrdiff_t  total,
double  cost_per_unit,
const std::function< void(std::ptrdiff_t first, std::ptrdiff_t last)> &  fn 
)
inlinestatic

Definition at line 250 of file threadpool.h.

static void onnxruntime::concurrency::ThreadPool::TryParallelFor ( ThreadPool tp,
std::ptrdiff_t  total,
const TensorOpCost cost_per_unit,
const std::function< void(std::ptrdiff_t first, std::ptrdiff_t last)> &  fn 
)
static
static void onnxruntime::concurrency::ThreadPool::TrySimpleParallelFor ( ThreadPool tp,
std::ptrdiff_t  total,
const std::function< void(std::ptrdiff_t)> &  fn 
)
inlinestatic

Definition at line 261 of file threadpool.h.

Friends And Related Function Documentation

friend class LoopCounter
friend

Definition at line 371 of file threadpool.h.


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