24 #ifndef MXNET_ENGINE_H_ 25 #define MXNET_ENGINE_H_ 27 #include <dmlc/base.h> 60 (*callback_)(engine_, param_);
65 friend class ::mxnet::Engine;
67 void (*callback_)(
Engine *,
void *);
98 typedef std::function<void(RunContext)>
SyncFn;
100 typedef std::function<void(RunContext, CallbackOnComplete)>
AsyncFn;
112 virtual void NotifyShutdown() = 0;
119 virtual VarHandle NewVariable() = 0;
131 virtual OprHandle NewOperator(AsyncFn fn,
132 std::vector<VarHandle>
const& const_vars,
133 std::vector<VarHandle>
const& mutable_vars,
135 const char* opr_name =
nullptr) = 0;
143 virtual void DeleteOperator(OprHandle op) = 0;
151 virtual void Push(OprHandle op,
Context exec_ctx,
int priority = 0,
bool profiling =
false) = 0;
165 virtual void PushAsync(AsyncFn exec_fun,
Context exec_ctx,
166 std::vector<VarHandle>
const& const_vars,
167 std::vector<VarHandle>
const& mutable_vars,
170 const char* opr_name =
nullptr) = 0;
182 virtual void DeleteVariable(SyncFn delete_fn,
190 virtual void WaitForVar(VarHandle var) = 0;
194 virtual void WaitForAll() = 0;
209 static std::shared_ptr<Engine> _GetSharedRef();
223 std::vector<VarHandle>
const& const_vars,
224 std::vector<VarHandle>
const& mutable_vars,
227 const char* opr_name =
nullptr) {
228 this->PushAsync([exec_fn](
RunContext ctx, CallbackOnComplete on_complete) {
231 }, exec_ctx, const_vars, mutable_vars, prop, priority, opr_name);
240 void (*callback)(
Engine *,
void *),
void *param) {
241 CallbackOnComplete ret;
242 ret.callback_ = callback;
250 std::vector<engine::VarHandle> *write_vars) {
251 std::sort(write_vars->begin(), write_vars->end());
252 write_vars->resize(std::unique(write_vars->begin(), write_vars->end()) -
253 write_vars->begin());
254 std::sort(read_vars->begin(), read_vars->end());
255 read_vars->resize(std::unique(read_vars->begin(), read_vars->end()) -
257 auto wit = write_vars->begin();
258 auto rtop = read_vars->begin();
259 for (
auto rit = read_vars->begin(); rit != read_vars->end(); ++rit) {
260 while (wit != write_vars->end() && *wit < *rit) ++wit;
261 if (wit == write_vars->end() || *wit != *rit) {
266 read_vars->resize(rtop - read_vars->begin());
269 #endif // DMLC_USE_CXX11 271 #endif // MXNET_ENGINE_H_ void DeduplicateVarHandle(std::vector< engine::VarHandle > *read_vars, std::vector< engine::VarHandle > *write_vars)
Definition: engine.h:249
FnProperty
Function property, used to hint what action is pushed to engine.
Definition: engine.h:77
std::function< void(RunContext)> SyncFn
Synchronous operation to pass to engine.
Definition: engine.h:98
std::function< void(RunContext, CallbackOnComplete)> AsyncFn
Asynchronous operation to pass to engine.
Definition: engine.h:100
namespace of mxnet
Definition: base.h:126
Asynchronous function call.
CallbackOnComplete CreateCallback(void(*callback)(Engine *, void *), void *param)
factory function to create OnComplete callback.
Definition: engine.h:239
void operator()() const
involve the callback
Definition: engine.h:59
execution time context. The information needed in runtime for actual execution.
Definition: base.h:238
virtual ~Engine() noexcept(false)
virtual destructor
Definition: engine.h:196
Copy operation from GPU to other devices.
engine::OprHandle OprHandle
Operator pointer.
Definition: engine.h:104
engine::VarHandle VarHandle
Variable pointer.
Definition: engine.h:102
Var * VarHandle
Variable pointer type, usually hold by user used to specify dependencies.
Definition: engine.h:46
Prioritized sync operation on CPU.
engine::CallbackOnComplete CallbackOnComplete
callback on complete
Definition: engine.h:96
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.
Definition: engine.h:222
Dependency engine that schedules operations.
Definition: engine.h:93
Symbol sort(const std::string &symbol_name, Symbol data, dmlc::optional< int > axis=dmlc::optional< int >(-1), bool is_ascend=true)
Definition: op.h:2539
OnComplete Callback to the engine, called by AsyncFn when action completes.
Definition: engine.h:55
Context information about the execution environment.
Definition: base.h:141
#define MXNET_API
define compatible keywords in g++ Used to support g++-4.6 and g++4.7
Definition: base.h:91
Copy operation from CPU to other devices.
Opr * OprHandle
Operator pointer type, usually hold by user.
Definition: engine.h:50