mxnet
op_attr_types.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
24 #ifndef NNVM_OP_ATTR_TYPES_H_
25 #define NNVM_OP_ATTR_TYPES_H_
26 
27 #include <vector>
28 #include <string>
29 #include <utility>
30 #include <functional>
31 #include <unordered_map>
32 #include "base.h"
33 #include "node.h"
34 #include "tuple.h"
35 #include "layout.h"
36 
37 namespace nnvm {
38 
39 // These types are optional attributes in each operator.
40 // Each attribute can be required by some passes.
41 
51 using FListInputNames = std::function<std::vector<std::string> (const NodeAttrs& attrs)>;
52 
63 using FNumVisibleOutputs = std::function<uint32_t (const NodeAttrs& attrs)>;
64 
74 using FListOutputNames = std::function<std::vector<std::string> (const NodeAttrs& attrs)>;
75 
84 using FMutateInputs = std::function<std::vector<uint32_t> (const NodeAttrs& attrs)>;
85 
91 template<typename AttrType>
92 using FInferNodeEntryAttr = std::function<bool (const NodeAttrs& attrs,
93  std::vector<AttrType> *in_attrs,
94  std::vector<AttrType> *out_attrs)>;
95 
103 using FGetAttrDict = std::function<
104  std::unordered_map<std::string, std::string>
105  (const NodeAttrs& attrs)>;
106 
118 
127 
136 using TIsBackward = bool;
137 
147 using TIsGhost = bool;
148 
158 using FInplaceOption = std::function<
159  std::vector<std::pair<int, int> > (const NodeAttrs& attrs)>;
160 
171 using FInplaceIdentity = std::function<std::vector<bool> (const NodeAttrs& attrs)>;
172 
182 using FIgnoreInputs = std::function<
183  std::vector<uint32_t> (const NodeAttrs& attrs)>;
184 
194 using FGradient = std::function<std::vector<NodeEntry>(
195  const ObjectPtr& nodeptr,
196  const std::vector<NodeEntry>& out_grads)>;
197 
205 using FSetInputVarAttrOnCompose = std::function<void(
206  const NodeAttrs& attrs,
207  ObjectPtr var,
208  const int index)>;
209 
229 using FCorrectLayout = std::function<bool(
230  const NodeAttrs& attrs,
231  std::vector<Layout> *ilayouts,
232  const std::vector<Layout> *last_ilayouts,
233  std::vector<Layout> *olayouts)>;
234 
245 using FInputGraph = std::function<std::vector<uint32_t>(const NodeAttrs& attrs)>;
246 
247 } // namespace nnvm
248 
249 #endif // NNVM_OP_ATTR_TYPES_H_
std::function< std::unordered_map< std::string, std::string >(const NodeAttrs &attrs)> FGetAttrDict
Get attribute dictionary from node.
Definition: op_attr_types.h:105
Definition: base.h:35
std::function< std::vector< NodeEntry >(const ObjectPtr &nodeptr, const std::vector< NodeEntry > &out_grads)> FGradient
Get the gradient node of the op node This function generates the backward graph of the node...
Definition: op_attr_types.h:196
std::function< std::vector< std::string >(const NodeAttrs &attrs)> FListInputNames
Return list of input arguments names of each operator.
Definition: op_attr_types.h:51
std::function< std::vector< std::pair< int, int > >(const NodeAttrs &attrs)> FInplaceOption
Get possible inplace options. This function enables optimization to reuse memory of inputs in output...
Definition: op_attr_types.h:159
The attributes of the current operation node. Usually are additional parameters like axis...
Definition: node.h:119
bool TIsGhost
Whether this op is a ghost node. If TIsGhost is true:
Definition: op_attr_types.h:147
FInferNodeEntryAttr< TShape > FInferShape
Shape inference function. Update the shapes given the input shape information. TShape.ndim() == 0 means the shape is still unknown.
Definition: op_attr_types.h:117
Graph node data structure.
std::function< std::vector< uint32_t >(const NodeAttrs &attrs)> FMutateInputs
Check whether operator will mutate k-th input.
Definition: op_attr_types.h:84
std::function< std::vector< std::string >(const NodeAttrs &attrs)> FListOutputNames
Return list of output arguments names of each operator.
Definition: op_attr_types.h:74
Data structure Tuple and TShape to store dynamic sized shapes.
std::function< std::vector< bool >(const NodeAttrs &attrs)> FInplaceIdentity
Get if the inplace option is an identity This function enables inplace optimization even when input r...
Definition: op_attr_types.h:171
std::function< std::vector< uint32_t >(const NodeAttrs &attrs)> FIgnoreInputs
Get list of inputs in the op whose content are actually not used by the operator These are dummy inpu...
Definition: op_attr_types.h:183
std::function< bool(const NodeAttrs &attrs, std::vector< AttrType > *in_attrs, std::vector< AttrType > *out_attrs)> FInferNodeEntryAttr
Inference function of certain type.
Definition: op_attr_types.h:94
FInferNodeEntryAttr< int > FInferType
Type inference function. Update the type given the known type information.
Definition: op_attr_types.h:126
std::function< std::vector< uint32_t >(const NodeAttrs &attrs)> FInputGraph
Get a list of inputs that represent graphs instead of data. Normally, input symbols are considered as...
Definition: op_attr_types.h:245
std::function< uint32_t(const NodeAttrs &attrs)> FNumVisibleOutputs
Return number of visible outputs by the user.
Definition: op_attr_types.h:63
std::function< bool(const NodeAttrs &attrs, std::vector< Layout > *ilayouts, const std::vector< Layout > *last_ilayouts, std::vector< Layout > *olayouts)> FCorrectLayout
Infer & correct function of node layout. See Layout for layout convention.
Definition: op_attr_types.h:233
bool TIsBackward
Whether this op is an explicit backward operator, If TIsBackward is true:
Definition: op_attr_types.h:136
Layout expression. The layout is composed of upper cases, lower cases and numbers, where upper case indicates a (super-)dimension and the corresponding lower case with factor size indicates the split (sub-)dimension. For example, NCHW16c can describe a 5-D tensor of [batch_size, channel, height, width, channel_block]. Here sub-dimension channel_block=16 is the split of super-dimension C (channel).
std::function< void(const NodeAttrs &attrs, ObjectPtr var, const int index)> FSetInputVarAttrOnCompose
Set the attributes of input variable. Usually used for setting initialization or weight decay...
Definition: op_attr_types.h:208
std::shared_ptr< Node > ObjectPtr
we always used ObjectPtr for a reference pointer to the node, so this alias can be changed in case...
Definition: node.h:48
Configuration of nnvm as well as basic data structure.