31 #include <unordered_map> 53 node(
std::move(node)),
59 node(
std::move(node)),
93 return std::hash<Node*>()(e.
node.get()) ^
94 (std::hash<size_t>()(e.
index) << 1 >> 1) ^
95 (std::hash<size_t>()(e.
version) << 1);
105 return (a.
node.get() == b.
node.get()) &&
112 template<
typename ValueType>
113 using NodeEntryMap = std::unordered_map<NodeEntry, ValueType, NodeEntryHash, NodeEntryEqual>;
124 const Op *op{
nullptr};
128 std::unordered_map<std::string, std::string>
dict;
158 Node(
const Op* op,
const std::string& name) {
160 this->attrs.
name = name;
176 inline const Op* op()
const;
182 inline bool is_variable()
const;
184 inline uint32_t num_outputs()
const;
186 inline uint32_t num_inputs()
const;
191 template<
class ...Args>
193 return std::make_shared<Node>(std::forward<Args>(args)...);
207 std::string node_name,
208 std::vector<NodeEntry> inputs,
209 std::unordered_map<std::string, std::string> attrs =
210 std::unordered_map<std::string, std::string>()) {
213 p->attrs.name = std::move(node_name);
214 p->attrs.dict = attrs;
215 if (p->attrs.op->attr_parser) {
216 p->attrs.op->attr_parser(&(p->attrs));
218 p->inputs = std::move(inputs);
224 return this->attrs.op;
228 return this->op() ==
nullptr;
232 if (is_variable())
return 1;
233 if (this->op()->get_num_outputs ==
nullptr) {
234 return this->op()->num_outputs;
236 return this->op()->get_num_outputs(this->attrs);
241 if (is_variable())
return 1;
242 if (this->op()->get_num_inputs ==
nullptr) {
243 return this->op()->num_inputs;
245 return this->op()->get_num_inputs(this->attrs);
251 #endif // NNVM_NODE_H_ uint32_t version
version of input Variable. This field can only be nonzero when this->node is a Variable node...
Definition: node.h:84
size_t operator()(const NodeEntry &a, const NodeEntry &b) const
Definition: node.h:104
Node(const Op *op, const std::string &name)
Definition: node.h:158
bool is_variable() const
return whether node is placeholder variable. This is equivalent to op == nullptr
Definition: node.h:227
The attributes of the current operation node. Usually are additional parameters like axis...
Definition: node.h:119
size_t operator()(const NodeEntry &e) const
Definition: node.h:92
This lets you use a NodeEntry as a key in a unordered_map of the form unordered_map<NodeEntry, ValueType, NodeEntryHash, NodeEntryEqual>
Definition: node.h:103
Definition: optional.h:241
ObjectPtr node
the source node of this data
Definition: node.h:75
std::vector< NodeEntry > inputs
inputs to this node
Definition: node.h:165
std::vector< ObjectPtr > control_deps
Optional control flow dependencies Gives operation must be performed before this operation.
Definition: node.h:170
NodeAttrs attrs
The attributes in the node.
Definition: node.h:163
std::vector< std::shared_ptr< Symbol > > subgraphs
Some operators take graphs as input. These operators include control flow operators and high-order fu...
Definition: node.h:149
Node represents an operation in a computation graph.
Definition: node.h:155
any parsed
A parsed version of attributes, This is generated if OpProperty.attr_parser is registered. The object can be used to quickly access attributes.
Definition: node.h:134
#define NNVM_DLL
NNVM_DLL prefix for windows.
Definition: c_api.h:37
This lets you use a NodeEntry as a key in a unordered_map of the form unordered_map<NodeEntry, ValueType, NodeEntryHash, NodeEntryEqual>
Definition: node.h:91
NodeEntry(ObjectPtr node)
Definition: node.h:58
std::string name
name of the node
Definition: node.h:126
std::string name
name of the operator
Definition: op.h:106
uint32_t num_inputs() const
Definition: node.h:240
uint32_t num_outputs() const
Definition: node.h:231
an entry that represents output data from a node
Definition: node.h:51
std::unordered_map< NodeEntry, ValueType, NodeEntryHash, NodeEntryEqual > NodeEntryMap
Definition: node.h:113
static ObjectPtr Create(Args &&...args)
create a new empty shared_ptr of Node.
Definition: node.h:192
NodeEntry()
Definition: node.h:68
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.
Definition: node.h:205
std::unordered_map< std::string, std::string > dict
The dictionary representation of attributes.
Definition: node.h:128
Operator information structor.
static const Op * Get(const std::string &op_name)
Get an Op for a given operator name. Will raise an error if the op has not been registered.
NodeEntry(ObjectPtr node, uint32_t index, uint32_t version)
Definition: node.h:52
uint32_t index
index of output from the source.
Definition: node.h:77
C API of NNVM symbolic construction and pass. Enables construction and transformation of Graph in any...
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
any info
additional fields for this node
Definition: node.h:172
Configuration of nnvm as well as basic data structure.
Operator structure.
Definition: op.h:103
const Op * op() const
Definition: node.h:223