mxnet
|
OperatorProperty is a object that stores all information about Operator. It also contains method to generate context(device) specific operators. More...
#include <operator.h>
Public Member Functions | |
virtual | ~OperatorProperty () |
virtual destructor More... | |
virtual void | Init (const std::vector< std::pair< std::string, std::string > > &kwargs)=0 |
Initialize the Operator by setting the parameters This function need to be called before all other functions. More... | |
virtual std::map< std::string, std::string > | GetParams () const =0 |
Get a map representation of internal parameters. This can be used by Init to recover the state of OperatorProperty. More... | |
virtual std::vector< std::string > | ListArguments () const |
Get input arguments of the Operator. More... | |
virtual std::vector< std::string > | ListOutputs () const |
Get name of output values of Operator. More... | |
virtual std::vector< std::string > | ListAuxiliaryStates () const |
Get name of auxiliary states of Operator. More... | |
virtual int | NumOutputs () const |
virtual int | NumVisibleOutputs () const |
get number of visible return values during Symbol creation. If NumVisibleOutputs() = k, and NumOutputs() = n. The first k returns will be presented in the resulting symbol. More... | |
virtual bool | InferShape (mxnet::ShapeVector *in_shape, mxnet::ShapeVector *out_shape, mxnet::ShapeVector *aux_shape) const =0 |
infer the shapes of outputs and unknown input arguments More... | |
virtual bool | InferType (std::vector< int > *in_type, std::vector< int > *out_type, std::vector< int > *aux_type) const |
infer the data types of outputs and unknown input arguments More... | |
virtual OperatorProperty * | Copy () const =0 |
Copy this OperatorProperty. More... | |
virtual Operator * | CreateOperator (Context ctx) const =0 |
Create a Operator on specific context. More... | |
virtual Operator * | CreateOperatorEx (Context ctx, mxnet::ShapeVector *in_shape, std::vector< int > *in_type) const |
Create a Operator on specific context and input shape/type. More... | |
virtual std::string | TypeString () const =0 |
return the type string of the Operator subclasses override this function. More... | |
virtual std::vector< ResourceRequest > | ForwardResource (const mxnet::ShapeVector &in_shape) const |
Declare additional resource required in forward pass. These additional resources will be presented in OpContext.requested in the same order of the returned Resource. More... | |
virtual std::vector< ResourceRequest > | BackwardResource (const mxnet::ShapeVector &in_shape) const |
Declare additional resource required in backward pass. These additional resources will be presented in OpContext.requested in the same order of the returned Resource. More... | |
virtual std::vector< int > | DeclareBackwardDependency (const std::vector< int > &out_grad, const std::vector< int > &in_data, const std::vector< int > &out_data) const |
Declare the input requirement of Backward pass. More... | |
virtual std::vector< std::pair< int, void * > > | ForwardInplaceOption (const std::vector< int > &in_data, const std::vector< void * > &out_data) const |
Get possible forward inplace options. This function enables optimization to reuse memory of inputs in output. Only override when necessary, by default in-place is disabled. More... | |
virtual std::vector< std::pair< int, void * > > | BackwardInplaceOption (const std::vector< int > &out_grad, const std::vector< int > &in_data, const std::vector< int > &out_data, const std::vector< void * > &in_grad) const |
Get possible backward inplace options. This function enables optimization to reuse memory of inputs in output. Only override when necessary, by default in-place is disabled. More... | |
template<typename T > | |
std::vector< T > | BackwardInputs (const std::vector< T > &out_grad, const std::vector< T > &in_data, const std::vector< T > &out_data) const |
Get Backward Input Dependency for generic types of data. Normally T can be pointer of Symbol::DataEntry, or NDArray. This function will select the result list of T according to DeclareBackwardDependency. More... | |
virtual ExecType | exec_type () const |
Static Public Member Functions | |
static OperatorProperty * | Create (const char *type_name) |
create OperatorProperty More... | |
OperatorProperty is a object that stores all information about Operator. It also contains method to generate context(device) specific operators.
It also contains various functions that can be optimally overriden to provide optimization chance for computation engine.
|
inlinevirtual |
virtual destructor
|
inlinevirtual |
Get possible backward inplace options. This function enables optimization to reuse memory of inputs in output. Only override when necessary, by default in-place is disabled.
The reason for void* type in the in_grad is to distinguish the order of mappings between the two, compiler will report error when in_data and out_data's order in the pair get reversed.
in_data | The input data in forward pass. |
out_data | The output data in forward pass. |
in_grad | Gradient of inputs in backward pass. |
out_grad | Gradient of outputs in backward pass. |
|
inline |
Get Backward Input Dependency for generic types of data. Normally T can be pointer of Symbol::DataEntry, or NDArray. This function will select the result list of T according to DeclareBackwardDependency.
in_data | the input data in forward pass. |
out_data | the output data in forward pass. |
out_grad | gradient of outputs in backward pass. |
T | the generic type parameter. |
|
inlinevirtual |
Declare additional resource required in backward pass. These additional resources will be presented in OpContext.requested in the same order of the returned Resource.
in_shape | The input shape to the operator, corresponds to shapes of in_data. |
|
pure virtual |
Copy this OperatorProperty.
|
static |
create OperatorProperty
type_name | the type string of the OperatorProperty |
Create a Operator on specific context.
|
inlinevirtual |
Create a Operator on specific context and input shape/type.
ctx | context of this operator |
in_shape | shape of the input ndarrays |
in_type | dtype of the input ndarrays |
|
inlinevirtual |
Declare the input requirement of Backward pass.
Only the returned list of variables will be used in Backward. This function is used for memory optimization. It is advised to override and only return what is actually needed. If this function is not overriden, all the variables will be valid in Backward.
out_grad | gradient of outputs in backward pass. |
in_data | the input data in forward pass. |
out_data | the output data in forward pass. |
|
inlinevirtual |
|
inlinevirtual |
Get possible forward inplace options. This function enables optimization to reuse memory of inputs in output. Only override when necessary, by default in-place is disabled.
The reason for void* type in the out_data is to distinguish the order of mappings between the two, compiler will report error when in_data and out_data's order in the pair get reversed.
in_data | The input data in forward pass. |
out_data | The output data in forward pass. |
|
inlinevirtual |
Declare additional resource required in forward pass. These additional resources will be presented in OpContext.requested in the same order of the returned Resource.
in_shape | The input shape to the operator, corresponds to shapes of in_data. |
|
pure virtual |
Get a map representation of internal parameters. This can be used by Init to recover the state of OperatorProperty.
|
pure virtual |
infer the shapes of outputs and unknown input arguments
in_shape | the shape of input arguments of the operator this should be of same length as the vector returned by DescribeArgs in_shape allows unknown elements, which are checked by shape.ndim() == 0. For unknown shapes, InferShape will try to fill in the correct Shape in in_shape For known shapes, InferShape will check shape consistency |
common practice: set the shape of data input, and usually weight's shape can be inferred
out_shape | the shape of outputs of the operator InferShape will modify the vector to fill output mxnet::TShape |
aux_shape | the shape of auxiliary states of the operator InferShape will modify the vector to fill output mxnet::TShape |
dmlc::Error | if the known arg_shapes are inconsistent. |
|
inlinevirtual |
infer the data types of outputs and unknown input arguments
in_type | the type of input arguments of the operator this should be of same length as the vector returned by DescribeArgs in_type allows unknown elements, which are checked by type.ndim() == 0. For unknown types, Infertype will try to fill in the correct type in in_type For known types, Infertype will check type consistency |
common practice: set the type of data input, and usually weight's type can be inferred
out_type | the type of outputs of the operator Infertype will modify the vector to fill output Ttype |
aux_type | the type of auxiliary states of the operator Infertype will modify the vector to fill output Ttype |
dmlc::Error | if the known arg_types are inconsistent. |
|
pure virtual |
Initialize the Operator by setting the parameters This function need to be called before all other functions.
kwargs | the keyword arguments parameters |
|
inlinevirtual |
Get input arguments of the Operator.
|
inlinevirtual |
Get name of auxiliary states of Operator.
|
inlinevirtual |
Get name of output values of Operator.
|
inlinevirtual |
|
inlinevirtual |
get number of visible return values during Symbol creation. If NumVisibleOutputs() = k, and NumOutputs() = n. The first k returns will be presented in the resulting symbol.
The rest of the returns can be used for auxiliary states for Backward. For example, Dropout will return [data, mask], with NumVisibleOutputs() == 1. So when user call sym = Dropout(input), only data is presented in sym. But all the returns will be presented in out_data parameter of Backward if requested.
|
pure virtual |
return the type string of the Operator subclasses override this function.