mxnet
Namespaces | Classes | Typedefs | Enumerations | Functions
nnvm Namespace Reference

Namespaces

 pass
 

Classes

class  Graph
 Symbolic computation graph. This is the intermediate representation for optimization pass. More...
 
class  IndexedGraph
 Auxiliary data structure to index a graph. It maps Nodes in the graph to consecutive integers node_id. It also maps IndexedGraph::NodeEntry to consecutive integer entry_id. This allows storing properties of Node and NodeEntry into compact vector and quickly access them without resorting to hashmap. More...
 
class  Layout
 
class  Node
 Node represents an operation in a computation graph. More...
 
struct  NodeAttrs
 The attributes of the current operation node. Usually are additional parameters like axis,. More...
 
struct  NodeEntry
 an entry that represents output data from a node More...
 
struct  NodeEntryEqual
 This lets you use a NodeEntry as a key in a unordered_map of the form unordered_map<NodeEntry, ValueType, NodeEntryHash, NodeEntryEqual> More...
 
struct  NodeEntryHash
 This lets you use a NodeEntry as a key in a unordered_map of the form unordered_map<NodeEntry, ValueType, NodeEntryHash, NodeEntryEqual> More...
 
class  Op
 Operator structure. More...
 
class  OpGroup
 auxiliary data structure used to set attributes to a group of operators More...
 
class  OpMap
 A map data structure that takes Op* as key and returns ValueType. More...
 
struct  PassFunctionReg
 Registry entry for pass functions. More...
 
class  Symbol
 Symbol is help class used to represent the operator node in Graph. More...
 
class  TShape
 A Shape class that is used to represent shape of each tensor. More...
 
class  Tuple
 A dynamic sized array data structure that is optimized for storing small number of elements with same type. More...
 

Typedefs

using JSONString = std::string
 The result holder of JSON serializer. More...
 
using ShapeVector = std::vector< TShape >
 The result holder of shape of each NodeEntry in the graph. More...
 
using DTypeVector = std::vector< int >
 The result holder of type of each NodeEntry in the graph. More...
 
using LayoutVector = std::vector< Layout >
 The result holder of layout of each NodeEntry in the graph. More...
 
using DeviceVector = std::vector< int >
 The result holder of device of each operator in the graph. More...
 
using DeviceAssignMap = std::unordered_map< std::string, int >
 The result holder of device of each operator in the graph. More...
 
using StorageVector = std::vector< int >
 The result holder of storage id of each NodeEntry in the graph. More...
 
using ObjectPtr = std::shared_ptr< Node >
 we always used ObjectPtr for a reference pointer to the node, so this alias can be changed in case. More...
 
template<typename ValueType >
using NodeEntryMap = std::unordered_map< NodeEntry, ValueType, NodeEntryHash, NodeEntryEqual >
 
using FListInputNames = std::function< std::vector< std::string >(const NodeAttrs &attrs)>
 Return list of input arguments names of each operator. More...
 
using FNumVisibleOutputs = std::function< uint32_t(const NodeAttrs &attrs)>
 Return number of visible outputs by the user. More...
 
using FListOutputNames = std::function< std::vector< std::string >(const NodeAttrs &attrs)>
 Return list of output arguments names of each operator. More...
 
using FMutateInputs = std::function< std::vector< uint32_t >(const NodeAttrs &attrs)>
 Check whether operator will mutate k-th input. More...
 
template<typename AttrType >
using FInferNodeEntryAttr = std::function< bool(const NodeAttrs &attrs, std::vector< AttrType > *in_attrs, std::vector< AttrType > *out_attrs)>
 Inference function of certain type. More...
 
using FGetAttrDict = std::function< std::unordered_map< std::string, std::string >(const NodeAttrs &attrs)>
 Get attribute dictionary from node. More...
 
using FInferShape = FInferNodeEntryAttr< TShape >
 Shape inference function. Update the shapes given the input shape information. TShape.ndim() == 0 means the shape is still unknown. More...
 
using FInferType = FInferNodeEntryAttr< int >
 Type inference function. Update the type given the known type information. More...
 
using TIsBackward = bool
 Whether this op is an explicit backward operator, If TIsBackward is true: More...
 
using TIsGhost = bool
 Whether this op is a ghost node. If TIsGhost is true: More...
 
using FInplaceOption = std::function< std::vector< std::pair< int, int > >(const NodeAttrs &attrs)>
 Get possible inplace options. This function enables optimization to reuse memory of inputs in output. More...
 
using FInplaceIdentity = std::function< std::vector< bool >(const NodeAttrs &attrs)>
 Get if the inplace option is an identity This function enables inplace optimization even when input reference count is greater than one. More...
 
using FIgnoreInputs = std::function< std::vector< uint32_t >(const NodeAttrs &attrs)>
 Get list of inputs in the op whose content are actually not used by the operator These are dummy input that can be used for example in zeros_like, ones_like. More...
 
using FGradient = std::function< std::vector< NodeEntry >(const ObjectPtr &nodeptr, const std::vector< NodeEntry > &out_grads)>
 Get the gradient node of the op node This function generates the backward graph of the node. More...
 
using FSetInputVarAttrOnCompose = std::function< void(const NodeAttrs &attrs, ObjectPtr var, const int index)>
 Set the attributes of input variable. Usually used for setting initialization or weight decay. More...
 
using FCorrectLayout = std::function< bool(const NodeAttrs &attrs, std::vector< Layout > *ilayouts, const std::vector< Layout > *last_ilayouts, std::vector< Layout > *olayouts)>
 Infer & correct function of node layout. See Layout for layout convention. More...
 
using FInputGraph = std::function< std::vector< uint32_t >(const NodeAttrs &attrs)>
 Get a list of inputs that represent graphs instead of data. Normally, input symbols are considered as data to the operator. However, control flow operators and high-order functions need to interpret symbols as graphs. More...
 
typedef std::function< Graph(Graph src)> PassFunction
 A PassFunction is an "Operator on Graph". It takes a source graph and return a graph that may or may not be the same as the input one. More...
 
typedef int64_t dim_t
 data type to store dim size More...
 

Enumerations

enum  TypeFlag {
  kFloat32 = 0, kFloat64 = 1, kFloat16 = 2, kUint8 = 3,
  kInt32 = 4, kInt8 = 5, kInt64 = 6, kInt16 = 8,
  kUint16 = 9, kUint32 = 10, kUint64 = 11, kBfloat16 = 12
}
 

Functions

template<typename FVisit >
void DFSVisit (const std::vector< NodeEntry > &heads, FVisit fvisit)
 perform a Post Order DFS visit to each node in the graph. This order is deterministic and is also topoligical sorted. More...
 
template<typename GNode , typename HashType , typename FVisit , typename HashFunc , typename InDegree , typename GetInput >
void PostOrderDFSVisit (const std::vector< GNode > &heads, FVisit fvisit, HashFunc hash, InDegree indegree, GetInput getinput)
 
NodeEntry MakeNode (const char *op_name, std::string node_name, std::vector< NodeEntry > inputs, std::unordered_map< std::string, std::string > attrs=std::unordered_map< std::string, std::string >())
 Quick utilities make node. More...
 
Graph ApplyPasses (Graph src, const std::vector< std::string > &passes)
 Apply a series of pass transformations on the input graph. More...
 
Graph ApplyPass (Graph src, const std::string &pass)
 Apply one pass to the graph. More...
 
template<typename SrcIter , typename DstIter >
DstIter ShapeTypeCast (const SrcIter begin, const SrcIter end, DstIter dst_begin)
 helper function to cast type of container elements More...
 
template<typename SrcIter >
TShape ShapeTypeCast (const SrcIter begin, const SrcIter end)
 helper function to transform a container to TShape with type cast More...
 

Typedef Documentation

using nnvm::DeviceAssignMap = typedef std::unordered_map<std::string, int>

The result holder of device of each operator in the graph.

Note
Stored under graph.attrs["device_assign_map"], needed by Pass "PlaceDevice" -1 means unknown device
using nnvm::DeviceVector = typedef std::vector<int>

The result holder of device of each operator in the graph.

Note
Stored under graph.attrs["device"], provided by Pass "PlaceDevice"
Graph g = ApplyPass(src_graph, "PlaceDevice");
const &device = g.GetAttr<DeviceVector>("device");
// get device by node_id
int device_type = device[g.indexed_graph().node_id(my_node)];
typedef int64_t nnvm::dim_t

data type to store dim size

using nnvm::DTypeVector = typedef std::vector<int>

The result holder of type of each NodeEntry in the graph.

Note
Stored under graph.attrs["dtype"], provided by Pass "InferType"
Graph g = ApplyPass(src_graph, "InferType");
const DTypeVector& types = g.GetAttr<DTypeVector>("dtype");
// get type by entry id
int entry_type = dtypes[g.indexed_graph().entry_id(my_entry)];
See also
FInferType
using nnvm::FCorrectLayout = typedef std::function<bool( const NodeAttrs& attrs, std::vector<Layout> *ilayouts, const std::vector<Layout> *last_ilayouts, std::vector<Layout> *olayouts)>

Infer & correct function of node layout. See Layout for layout convention.

Parameters
attrsThe attribute of the node.
ilayoutsGiven the input layouts produced by ancestor nodes, it should be filled by layouts that the node requests. If the requested layout is different from what ancestor produces, a layout_transform operator will be inserted automatically.
last_ilayoutsThe input layouts requested by the node at the last infer pass (if any). This can be useful when an operator wants to keep the input layout the same as the original one. For example, after the pass of AlterOpLayout, transpose(input, axis=[1, 2, 3, 0]) may receive an input of NCHW16c layout, with which it cannot calculate with axis=[1, 2, 3, 0]. Last input layouts allow it to know what the layout it originally inferred, i.e., the layout in the imported model.
olayoutsInferred output layouts.
Returns
success flag.
using nnvm::FGetAttrDict = typedef std::function< std::unordered_map<std::string, std::string> (const NodeAttrs& attrs)>

Get attribute dictionary from node.

Parameters
attrsThe attributes of the node.
Returns
The attribute dict.
Note
Register under "FUpdateAttrDict"
using nnvm::FGradient = typedef std::function<std::vector<NodeEntry>( const ObjectPtr& nodeptr, const std::vector<NodeEntry>& out_grads)>

Get the gradient node of the op node This function generates the backward graph of the node.

Parameters
nodeptrThe node to take gradient
out_gradsGradient of current node's outputs
Returns
gradients of the inputs
Note
Register under "FGradient"
using nnvm::FIgnoreInputs = typedef std::function< std::vector<uint32_t> (const NodeAttrs& attrs)>

Get list of inputs in the op whose content are actually not used by the operator These are dummy input that can be used for example in zeros_like, ones_like.

Parameters
attrsThe attributes of the node
Returns
list input index that are not used by the operator.
Note
Register under "FIgnoreInputs".
template<typename AttrType >
using nnvm::FInferNodeEntryAttr = typedef std::function<bool (const NodeAttrs& attrs, std::vector<AttrType> *in_attrs, std::vector<AttrType> *out_attrs)>

Inference function of certain type.

Template Parameters
AttrTypeThe type of the attribute to be infered.
Returns
whether all attributes are inferred.

Shape inference function. Update the shapes given the input shape information. TShape.ndim() == 0 means the shape is still unknown.

Note
Register under "FInferShape", by default do not update any shapes.

FInferShape is needed by shape inference

using nnvm::FInferType = typedef FInferNodeEntryAttr<int>

Type inference function. Update the type given the known type information.

Note
Register under "FInferType", by default set all the output types to 0.
using nnvm::FInplaceIdentity = typedef std::function<std::vector<bool> (const NodeAttrs& attrs)>

Get if the inplace option is an identity This function enables inplace optimization even when input reference count is greater than one.

Parameters
attrsThe attributes of the node
Returns
list of bool indicating whether corresponding pair from FInplaceOption is an identity
Note
Register under "FInplaceIdentity", by default no identities.
using nnvm::FInplaceOption = typedef std::function< std::vector<std::pair<int, int> > (const NodeAttrs& attrs)>

Get possible inplace options. This function enables optimization to reuse memory of inputs in output.

Parameters
attrsThe attributes of the node
Returns
list of pair of that maps input->output, indicating possible in place operations.
Note
Register under "FInplaceOption", by default no inplace can happen.
using nnvm::FInputGraph = typedef std::function<std::vector<uint32_t>(const NodeAttrs& attrs)>

Get a list of inputs that represent graphs instead of data. Normally, input symbols are considered as data to the operator. However, control flow operators and high-order functions need to interpret symbols as graphs.

Parameters
attrsThe attributes of this node.
Returns
a list of input index that are interpreted as symbols by the operator.
Note
Register under "FInputGraph".
using nnvm::FListInputNames = typedef std::function<std::vector<std::string> (const NodeAttrs& attrs)>

Return list of input arguments names of each operator.

Parameters
attrsThe attributes of the node.
Returns
list of inputs
Note
Register under "FListInputNames", default return {"data"}.

FListInputNames enables automatic variable creation for missing arguments.

using nnvm::FListOutputNames = typedef std::function<std::vector<std::string> (const NodeAttrs& attrs)>

Return list of output arguments names of each operator.

Parameters
attrsThe attributes of the node.
Returns
list of inputs
Note
Register under "FListOutputNames", default return {"outputs"}.

FListOutputNames customized naming for operator outputs.

using nnvm::FMutateInputs = typedef std::function<std::vector<uint32_t> (const NodeAttrs& attrs)>

Check whether operator will mutate k-th input.

Parameters
attrsThe attributes of the node.
Returns
list of input indices it mutates.
Note
Register under "FMutateInputs", default return false FMutateInputs enables mutation order handling correctly.
using nnvm::FNumVisibleOutputs = typedef std::function<uint32_t (const NodeAttrs& attrs)>

Return number of visible outputs by the user.

Parameters
attrsThe attributes of the node.
Note
Register under "FNumVisibleOutputs", default not registered. This can be used to hide certain output from the user, but the additional outputs can be used to pass information from forward to gradient pass.
using nnvm::FSetInputVarAttrOnCompose = typedef std::function<void( const NodeAttrs& attrs, ObjectPtr var, const int index)>

Set the attributes of input variable. Usually used for setting initialization or weight decay.

Parameters
attrsThe attributes of this node.
varthe input variable
indexindex of var in all inputs
using nnvm::JSONString = typedef std::string

The result holder of JSON serializer.

Note
Stored under ret.attrs["json"], provided by Pass "SaveJSON"
Graph ret = ApplyPass(src_graph, "SaveJSON");
const JSONString& json = ret.GetAttr<JSONString>("shape");
using nnvm::LayoutVector = typedef std::vector<Layout>

The result holder of layout of each NodeEntry in the graph.

Note
Stored under graph.attrs["layout"], provided by Pass "InferType"
Graph g = ApplyPass(src_graph, "LayoutTransform");
const LayoutVector& layouts = g.GetAttr<LayoutVector>("layout");
// get layout by entry id
int entry_layout = layouts[g.indexed_graph().entry_id(my_entry)];
See also
FCorrectLayout
template<typename ValueType >
using nnvm::NodeEntryMap = typedef std::unordered_map<NodeEntry, ValueType, NodeEntryHash, NodeEntryEqual>

use NodeEntry as key in unordered_map

using nnvm::ObjectPtr = typedef std::shared_ptr<Node>

we always used ObjectPtr for a reference pointer to the node, so this alias can be changed in case.

By default, ObjectPtr is a std::shared_ptr of node

typedef std::function<Graph (Graph src)> nnvm::PassFunction

A PassFunction is an "Operator on Graph". It takes a source graph and return a graph that may or may not be the same as the input one.

A pass function can either change the graph structure (thus, generating a new Graph), or add new attributes to the graph.

Parameters
srcThe graph to be transformed.
Returns
The generated graph.
using nnvm::ShapeVector = typedef std::vector<TShape>

The result holder of shape of each NodeEntry in the graph.

Note
Stored under graph.attrs["shape"], provided by Pass "InferShape"
Graph g = ApplyPass(src_graph, "InferShape");
const ShapeVector& shapes = g.GetAttr<ShapeVector>("shape");
// get shape by entry id
TShape entry_shape = shapes[g.indexed_graph().entry_id(my_entry)];
See also
FInferShape
using nnvm::StorageVector = typedef std::vector<int>

The result holder of storage id of each NodeEntry in the graph.

Note
Stored under graph.attrs["storage"], provided by Pass "PlanMemory" Storage id is a continuous integer. If the storage id is -1 then the storage is not assigned.
Graph g = ApplyPass(src_graph, "PlanMemory");
const &storage = g.GetAttr<StorageVector>("storage");
// get storage id by entry
int storage_id = storage[g.indexed_graph().entry_id(my_entry)];
using nnvm::TIsBackward = typedef bool

Whether this op is an explicit backward operator, If TIsBackward is true:

  • The first control_deps of the node points to the corresponding forward operator.
Note
Register under "TIsBackward" This enables easier shape/type inference for backward operators.
using nnvm::TIsGhost = typedef bool

Whether this op is a ghost node. If TIsGhost is true:

  • The node with this op will not be visible in the indexed graph.
Note
Register under "TIsGhost" This enables shape/type inference for backward nodes when fusion is present.

Enumeration Type Documentation

Enumerator
kFloat32 
kFloat64 
kFloat16 
kUint8 
kInt32 
kInt8 
kInt64 
kInt16 
kUint16 
kUint32 
kUint64 
kBfloat16 

Function Documentation

Graph nnvm::ApplyPass ( Graph  src,
const std::string &  pass 
)
inline

Apply one pass to the graph.

Parameters
srcThe graph to be transformed.
passThe name of pass to be applied.
Returns
The transformed graph.
Graph nnvm::ApplyPasses ( Graph  src,
const std::vector< std::string > &  passes 
)

Apply a series of pass transformations on the input graph.

Parameters
srcThe graph to be transformed.
passesA list of pass names to be applied.
Returns
The transformed graph
template<typename FVisit >
void nnvm::DFSVisit ( const std::vector< NodeEntry > &  heads,
FVisit  fvisit 
)
inline

perform a Post Order DFS visit to each node in the graph. This order is deterministic and is also topoligical sorted.

Parameters
headsThe heads in the graph.
fvisita function of type std::function<void(const std::shared_ptr<Node>&)>
Template Parameters
FVisitThe function type to perform the visit.
NodeEntry nnvm::MakeNode ( const char *  op_name,
std::string  node_name,
std::vector< NodeEntry inputs,
std::unordered_map< std::string, std::string >  attrs = std::unordered_map<std::string, std::string>() 
)
inline

Quick utilities make node.

Parameters
op_nameThe name of operator
node_nameThe name of the node
inputsThe input entries
attrsThe attributes
Returns
The created node entry.
template<typename GNode , typename HashType , typename FVisit , typename HashFunc , typename InDegree , typename GetInput >
void nnvm::PostOrderDFSVisit ( const std::vector< GNode > &  heads,
FVisit  fvisit,
HashFunc  hash,
InDegree  indegree,
GetInput  getinput 
)
template<typename SrcIter , typename DstIter >
DstIter nnvm::ShapeTypeCast ( const SrcIter  begin,
const SrcIter  end,
DstIter  dst_begin 
)
inline

helper function to cast type of container elements

template<typename SrcIter >
TShape nnvm::ShapeTypeCast ( const SrcIter  begin,
const SrcIter  end 
)
inline

helper function to transform a container to TShape with type cast