26 #ifndef MXNET_OP_ATTR_TYPES_H_ 27 #define MXNET_OP_ATTR_TYPES_H_ 29 #include <mshadow/tensor.h> 30 #include <nnvm/op_attr_types.h> 42 using nnvm::NodeAttrs;
82 template<
typename xpu>
143 template<
typename T,
typename... Args>
146 auto state =
new T(std::forward<Args>(args)...);
149 new OpState(var, state),
152 delete reinterpret_cast<T*
>(p->state);
165 return *
reinterpret_cast<T*
>(ptr_->state);
174 return ptr_.unique();
177 explicit operator bool()
const {
178 return ptr_ ?
true :
false;
188 OpState(
const OpState& other) =
delete;
189 OpState& operator=(
const OpState& other) =
delete;
192 std::shared_ptr<OpState> ptr_;
210 const std::vector<int>& in_type)>;
214 using FExecType = std::function<ExecType (const NodeAttrs& attrs)>;
224 const std::vector<TBlob>& inputs,
225 const std::vector<OpReqType>& req,
226 const std::vector<TBlob>& outputs)>;
236 const std::vector<NDArray>& inputs,
237 const std::vector<OpReqType>& req,
238 const std::vector<NDArray>& outputs)>;
246 std::vector<ResourceRequest> (
const NodeAttrs& n)>;
256 std::vector<ResourceRequest> (
const NodeAttrs& n,
265 const std::vector<NDArray>& inputs,
266 std::vector<NDArray>* outputs)>;
272 using FCompute = std::function<void (
const nnvm::NodeAttrs& attrs,
274 const std::vector<TBlob>& inputs,
275 const std::vector<OpReqType>& req,
276 const std::vector<TBlob>& outputs)>;
282 using FComputeEx = std::function<void (
const nnvm::NodeAttrs& attrs,
284 const std::vector<NDArray>& inputs,
285 const std::vector<OpReqType>& req,
286 const std::vector<NDArray>& outputs)>;
297 std::vector<int>* in_attrs,
298 std::vector<int>* out_attrs)>;
304 using FQuantizedOp = std::function<nnvm::NodePtr (const NodeAttrs& attrs)>;
324 #endif // MXNET_OP_ATTR_TYPES_H_ std::function< void(const OpStatePtr &state, const OpContext &ctx, const std::vector< TBlob > &inputs, const std::vector< OpReqType > &req, const std::vector< TBlob > &outputs)> FStatefulCompute
Resiger a compute function for stateful operator. OpStatePtr is a pointer type, it's content is mutab...
Definition: op_attr_types.h:226
void reset()
Definition: op_attr_types.h:168
Forward/Backward are synchronous calls.
Engine that schedules all the operations according to dependency.
no operation, do not write anything
Definition: op_attr_types.h:47
write gradient to provided space
Definition: op_attr_types.h:49
namespace of mxnet
Definition: base.h:89
std::function< std::vector< ResourceRequest >(const NodeAttrs &n)> FResourceRequest
The resource request from the operator. An operator could register ResourceRequestEx, or ResourceRequest, or neither.
Definition: op_attr_types.h:246
std::function< void(const OpStatePtr &state, const OpContext &ctx, const std::vector< NDArray > &inputs, const std::vector< OpReqType > &req, const std::vector< NDArray > &outputs)> FStatefulComputeEx
Resiger a compute function for stateful operator using NDArray interface. OpStatePtr is a pointer typ...
Definition: op_attr_types.h:238
mshadow::Stream< xpu > * get_stream() const
get mshadow stream from Context
Definition: base.h:358
std::function< bool(const NodeAttrs &attrs)> FNeedRequantize
Register a function to determine if the output of a quantized operator needs to be requantized...
Definition: op_attr_types.h:312
Asynchronous function call.
bool is_train
whether it is training phase
Definition: op_attr_types.h:70
engine::VarHandle get_var() const
Definition: op_attr_types.h:159
Cross device copy operation, this is a special operator that indicates it will copy across devices...
execution time context. The information needed in runtime for actual execution.
Definition: base.h:337
DispatchMode
the dispatch mode of the operator
Definition: op_attr_types.h:122
base class of engine variables.
Definition: engine.h:44
Provides automatic coordination of an auxilary stream with a primary one. This object, upon construction, prepares an aux stream for use by syncing it with enqueued primary-stream work. Object destruction will sync again so future primary-stream work will wait on enqueued aux-stream work. If MXNET_GPU_WORKER_NSTREAMS == 1, then this defaults simply: the primary stream will equal the aux stream and the syncs will be executed as nops. See ./src/operator/cudnn/cudnn_convolution-inl.h for a usage example.
Definition: base.h:302
T & get_state() const
Definition: op_attr_types.h:164
engine::CallbackOnComplete async_on_complete
the callback when operation completes, used by asynchronize ops
Definition: op_attr_types.h:74
All the possible information needed by Operator.Forward and Backward This is the superset of RunConte...
Definition: op_attr_types.h:66
std::vector< mxnet::TShape > ShapeVector
The result holder of shape of each NodeEntry in the graph.
Definition: tuple.h:768
std::function< ExecType(const NodeAttrs &attrs)> FExecType
Execution mode of this operator.
Definition: op_attr_types.h:214
virtual VarHandle NewVariable()=0
Allocate a new variable, the variable can then be used to schedule the operation concurrently via dep...
static OpStatePtr Create(Args &&...args)
Definition: op_attr_types.h:144
std::function< nnvm::NodePtr(const NodeAttrs &attrs)> FQuantizedOp
Register a quantized node creation function based on the attrs of the node.
Definition: op_attr_types.h:304
bool need_grad
whether there is a backward phase to compute gradients.
Definition: op_attr_types.h:68
SyncedGPUAuxStream get_gpu_aux_stream() const
get auxilary gpu stream auto-syncing object from Context
Definition: op_attr_types.h:91
std::function< void(const nnvm::NodeAttrs &attrs, const std::vector< NDArray > &inputs, std::vector< NDArray > *outputs)> FNDArrayFunction
Register an operator called as a NDArray function.
Definition: op_attr_types.h:266
Global resource allocation handling.
virtual void DeleteVariable(SyncFn delete_fn, Context exec_ctx, VarHandle var)=0
Schedule the deletion of a variable.
std::function< OpStatePtr(const NodeAttrs &attrs, Context ctx, const mxnet::ShapeVector &in_shape, const std::vector< int > &in_type)> FCreateOpState
Create a Layer style, forward/backward operator. This is easy to write code that contains state...
Definition: op_attr_types.h:210
perform an inplace write, This option only happen when Target shares memory with one of input argumen...
Definition: op_attr_types.h:55
A subgraph execution should happen in the main thread, instead of in the execution engine...
bool unique() const
Definition: op_attr_types.h:173
OpReqType
operation request type to Forward and Backward
Definition: op_attr_types.h:45
std::function< void(const nnvm::NodeAttrs &attrs, const OpContext &ctx, const std::vector< NDArray > &inputs, const std::vector< OpReqType > &req, const std::vector< NDArray > &outputs)> FComputeEx
Register an NDArray compute function for simple stateless forward only operator.
Definition: op_attr_types.h:286
std::vector< Resource > requested
Resources requested by the operator.
Definition: op_attr_types.h:76
RunContext run_ctx
RunContext related resources.
Definition: op_attr_types.h:72
static Context CPU(int32_t dev_id=0)
std::function< void(const nnvm::NodeAttrs &attrs, const OpContext &ctx, const std::vector< TBlob > &inputs, const std::vector< OpReqType > &req, const std::vector< TBlob > &outputs)> FCompute
Register a compute function for simple stateless forward only operator.
Definition: op_attr_types.h:276
OnComplete Callback to the engine, called by AsyncFn when action completes.
Definition: engine.h:73
SyncedGPUAuxStream get_gpu_aux_stream() const
get an RAII object that transparently handles the syncing of the auxiliary stream.
Definition: base.h:366
std::function< bool(const NodeAttrs &attrs, const int dev_mask, DispatchMode *dispatch_mode, std::vector< int > *in_attrs, std::vector< int > *out_attrs)> FInferStorageType
Register a storage and dispatch mode inference function based on storage types of the inputs and outp...
Definition: op_attr_types.h:298
std::function< std::vector< ResourceRequest >(const NodeAttrs &n, const int dev_mask, const DispatchMode dispatch_mode)> FResourceRequestEx
The resource request from the operator. An operator could register ResourceRequestEx, or ResourceRequest, or neither. If an operator registers both ResourceRequestEx and ResourceRequest, ResourceRequest is ignored.
Definition: op_attr_types.h:258
add to the provided space
Definition: op_attr_types.h:57
std::function< bool(const NodeAttrs &attrs, size_t index)> FAvoidQuantizeInput
Register a function to determine if the input of a quantized operator needs to be quantized...
Definition: op_attr_types.h:320
ExecType
the execution type of the operator
Definition: op_attr_types.h:98
Context information about the execution environment.
Definition: base.h:102
mshadow::Stream< xpu > * get_stream() const
get mshadow stream from Context
Definition: op_attr_types.h:83
Operator state. This is a pointer type, its content is mutable even if OpStatePtr is const...
Definition: op_attr_types.h:138