mxnet
Public Types | Public Member Functions | Static Public Member Functions | List of all members
mxnet::Engine Class Referenceabstract

Dependency engine that schedules operations. More...

#include <engine.h>

Collaboration diagram for mxnet::Engine:
Collaboration graph

Public Types

typedef engine::CallbackOnComplete CallbackOnComplete
 callback on complete More...
 
typedef std::function< void(RunContext)> SyncFn
 Synchronous operation to pass to engine. More...
 
typedef std::function< void(RunContext, CallbackOnComplete)> AsyncFn
 Asynchronous operation to pass to engine. More...
 
typedef engine::VarHandle VarHandle
 Variable pointer. More...
 
typedef engine::OprHandle OprHandle
 Operator pointer. More...
 

Public Member Functions

virtual void NotifyShutdown ()=0
 Notify the engine about a shutdown, This can help engine to print less messages into display. More...
 
virtual VarHandle NewVariable ()=0
 Allocate a new variable, the variable can then be used to schedule the operation concurrently via dependency patterns. More...
 
virtual OprHandle NewOperator (AsyncFn fn, std::vector< VarHandle > const &const_vars, std::vector< VarHandle > const &mutable_vars, FnProperty prop=FnProperty::kNormal, const char *opr_name=nullptr)=0
 Create a new operator. The returned operator could be saved externally so that it could be resued for scheduling. More...
 
virtual void DeleteOperator (OprHandle op)=0
 Delete the given operator. More...
 
virtual void Push (OprHandle op, Context exec_ctx, int priority=0, bool profiling=false)=0
 Push an operator to the engine. More...
 
virtual void PushAsync (AsyncFn exec_fun, Context exec_ctx, std::vector< VarHandle > const &const_vars, std::vector< VarHandle > const &mutable_vars, FnProperty prop=FnProperty::kNormal, int priority=0, const char *opr_name=nullptr)=0
 Push an asynchronous operation to the engine. More...
 
virtual void DeleteVariable (SyncFn delete_fn, Context exec_ctx, VarHandle var)=0
 Schedule the deletion of a variable. More...
 
virtual void WaitForVar (VarHandle var)=0
 Wait for a variable. More...
 
virtual void WaitForAll ()=0
 Wait until all the activity of engine finishes. More...
 
virtual ~Engine () noexcept(false)
 virtual destructor More...
 
void PushSync (SyncFn exec_fn, Context exec_ctx, std::vector< VarHandle > const &const_vars, std::vector< VarHandle > const &mutable_vars, FnProperty prop=FnProperty::kNormal, int priority=0, const char *opr_name=nullptr)
 Push an synchronous operation to the engine. More...
 
CallbackOnComplete CreateCallback (void(*callback)(Engine *, void *), void *param)
 factory function to create OnComplete callback. More...
 
void DeduplicateVarHandle (std::vector< engine::VarHandle > *read_vars, std::vector< engine::VarHandle > *write_vars)
 
virtual int num_omp_threads_per_worker () const =0
 Return the number of OMP threads that should be used per worker. More...
 
virtual void set_num_omp_threads_per_worker (int num_omp_threads_per_worker)=0
 Set the number of OMP threads that should be used per worker. More...
 

Static Public Member Functions

static EngineGet ()
 
static std::shared_ptr< Engine_GetSharedRef ()
 Get shared pointer reference to engine singleton. Most user should not call this function. This function is called by another singleton X who requires engine to be destructed after X. More...
 

Detailed Description

Dependency engine that schedules operations.

Member Typedef Documentation

typedef std::function<void(RunContext, CallbackOnComplete)> mxnet::Engine::AsyncFn

Asynchronous operation to pass to engine.

callback on complete

Operator pointer.

typedef std::function<void(RunContext)> mxnet::Engine::SyncFn

Synchronous operation to pass to engine.

Variable pointer.

Constructor & Destructor Documentation

virtual mxnet::Engine::~Engine ( )
inlinevirtualnoexcept

virtual destructor

Member Function Documentation

static std::shared_ptr<Engine> mxnet::Engine::_GetSharedRef ( )
static

Get shared pointer reference to engine singleton. Most user should not call this function. This function is called by another singleton X who requires engine to be destructed after X.

Returns
A shared pointer to Engine singleton.
CallbackOnComplete mxnet::Engine::CreateCallback ( void(*)(Engine *, void *)  callback,
void *  param 
)
inline

factory function to create OnComplete callback.

Parameters
callbackth static callback function.
paramthe paramter passed to callback.
void mxnet::Engine::DeduplicateVarHandle ( std::vector< engine::VarHandle > *  read_vars,
std::vector< engine::VarHandle > *  write_vars 
)
inline
virtual void mxnet::Engine::DeleteOperator ( OprHandle  op)
pure virtual

Delete the given operator.

Parameters
opThe operator to delete.

The delete will not happen immediately, but will wait until all the operations using this operator are completed.

virtual void mxnet::Engine::DeleteVariable ( SyncFn  delete_fn,
Context  exec_ctx,
VarHandle  var 
)
pure virtual

Schedule the deletion of a variable.

The delete will not happen immediately, but will wait until all the operations depending on var are completed.

Parameters
delete_fnA function that will be called after the variable is deleted.
exec_ctxExecution context.
varThe variable to be deleted.
static Engine* mxnet::Engine::Get ( )
static
Returns
Engine singleton.
virtual OprHandle mxnet::Engine::NewOperator ( AsyncFn  fn,
std::vector< VarHandle > const &  const_vars,
std::vector< VarHandle > const &  mutable_vars,
FnProperty  prop = FnProperty::kNormal,
const char *  opr_name = nullptr 
)
pure virtual

Create a new operator. The returned operator could be saved externally so that it could be resued for scheduling.

Parameters
fnThe execution function.
const_varsThe variables that current operation will use but not mutate.
mutable_varsThe variables that current operation will mutate.
propProperty of the function.
opr_nameThe operator name.
Returns
The new operator allocated.
virtual VarHandle mxnet::Engine::NewVariable ( )
pure virtual

Allocate a new variable, the variable can then be used to schedule the operation concurrently via dependency patterns.

Returns
The new variable allocated.
virtual void mxnet::Engine::NotifyShutdown ( )
pure virtual

Notify the engine about a shutdown, This can help engine to print less messages into display.

User do not have to call this function.

Returns
0 when success, -1 when failure happens.
virtual int mxnet::Engine::num_omp_threads_per_worker ( ) const
pure virtual

Return the number of OMP threads that should be used per worker.

Returns
Number of OMP threads that should be used per worker
virtual void mxnet::Engine::Push ( OprHandle  op,
Context  exec_ctx,
int  priority = 0,
bool  profiling = false 
)
pure virtual

Push an operator to the engine.

Parameters
opThe operator to push.
exec_ctxExecution context.
priorityPriority of the action, as hint to the engine.
profilingThe variable indicate whether to profile this operator.
virtual void mxnet::Engine::PushAsync ( AsyncFn  exec_fun,
Context  exec_ctx,
std::vector< VarHandle > const &  const_vars,
std::vector< VarHandle > const &  mutable_vars,
FnProperty  prop = FnProperty::kNormal,
int  priority = 0,
const char *  opr_name = nullptr 
)
pure virtual

Push an asynchronous operation to the engine.

Parameters
exec_funExecution function, this function takes a parameter on_complete that must be called when the execution completes.
exec_ctxExecution context.
const_varsThe variables that current operation will use but not mutate.
mutable_varsThe variables that current operation will mutate.
propProperty of the function.
priorityPriority of the action, as hint to the engine.
opr_nameThe operator name.
void mxnet::Engine::PushSync ( SyncFn  exec_fn,
Context  exec_ctx,
std::vector< VarHandle > const &  const_vars,
std::vector< VarHandle > const &  mutable_vars,
FnProperty  prop = FnProperty::kNormal,
int  priority = 0,
const char *  opr_name = nullptr 
)
inline

Push an synchronous operation to the engine.

Parameters
exec_fnExecution function that executes the operation.
exec_ctxExecution context.
const_varsThe variables that current operation will use but not mutate.
mutable_varsThe variables that current operation will mutate.
propProperty of the function.
priorityPriority of the action, as hint to the engine.
opr_nameThe operator name.
Template Parameters
SyncFnthe synchronous function to be pushed.
virtual void mxnet::Engine::set_num_omp_threads_per_worker ( int  num_omp_threads_per_worker)
pure virtual

Set the number of OMP threads that should be used per worker.

Parameters
num_threads_per_workerNumber of OMP threads to be used per worker
virtual void mxnet::Engine::WaitForAll ( )
pure virtual

Wait until all the activity of engine finishes.

virtual void mxnet::Engine::WaitForVar ( VarHandle  var)
pure virtual

Wait for a variable.

Parameters
varThe variable we should wait for. This function returns when the variable is ready.

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