32 #include <unordered_map> 54 node(
std::move(node)),
60 node(
std::move(node)),
94 return std::hash<Node*>()(e.
node.get()) ^
95 (std::hash<size_t>()(e.
index) << 1 >> 1) ^
96 (std::hash<size_t>()(e.
version) << 1);
106 return (a.
node.get() == b.
node.get()) &&
113 template<
typename ValueType>
114 using NodeEntryMap = std::unordered_map<NodeEntry, ValueType, NodeEntryHash, NodeEntryEqual>;
125 const Op *op{
nullptr};
129 std::unordered_map<std::string, std::string>
dict;
159 Node(
const Op* op,
const std::string& name) {
161 this->attrs.
name = name;
177 inline const Op* op()
const;
183 inline bool is_variable()
const;
185 inline uint32_t num_outputs()
const;
187 inline uint32_t num_inputs()
const;
192 template<
class ...Args>
194 return std::make_shared<Node>(std::forward<Args>(args)...);
208 std::string node_name,
209 std::vector<NodeEntry> inputs,
210 std::unordered_map<std::string, std::string> attrs =
211 std::unordered_map<std::string, std::string>()) {
214 p->attrs.name = std::move(node_name);
215 p->attrs.dict = attrs;
216 if (p->attrs.op->attr_parser) {
217 p->attrs.op->attr_parser(&(p->attrs));
219 p->inputs = std::move(inputs);
225 return this->attrs.op;
229 return this->op() ==
nullptr;
233 if (is_variable())
return 1;
234 if (this->op()->get_num_outputs ==
nullptr) {
235 return this->op()->num_outputs;
237 return this->op()->get_num_outputs(this->attrs);
242 if (is_variable())
return 1;
243 if (this->op()->get_num_inputs ==
nullptr) {
244 return this->op()->num_inputs;
246 return this->op()->get_num_inputs(this->attrs);
252 #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:85
size_t operator()(const NodeEntry &a, const NodeEntry &b) const
Definition: node.h:105
Node(const Op *op, const std::string &name)
Definition: node.h:159
bool is_variable() const
return whether node is placeholder variable. This is equivalent to op == nullptr
Definition: node.h:228
The attributes of the current operation node. Usually are additional parameters like axis...
Definition: node.h:120
size_t operator()(const NodeEntry &e) const
Definition: node.h:93
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:104
NodeEntry(NodePtr node, uint32_t index, uint32_t version)
Definition: node.h:53
Definition: optional.h:241
std::shared_ptr< Node > NodePtr
we always used NodePtr for a reference pointer to the node, so this alias can be changed in case...
Definition: node.h:49
std::vector< NodeEntry > inputs
inputs to this node
Definition: node.h:166
NodeAttrs attrs
The attributes in the node.
Definition: node.h:164
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:150
NodePtr node
the source node of this data
Definition: node.h:76
NodeEntry(NodePtr node)
Definition: node.h:59
Node represents an operation in a computation graph.
Definition: node.h:156
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:135
#define NNVM_DLL
NNVM_DLL prefix for windows.
Definition: c_api.h:38
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:92
std::string name
name of the node
Definition: node.h:127
std::string name
name of the operator
Definition: op.h:107
uint32_t num_inputs() const
Definition: node.h:241
std::vector< NodePtr > control_deps
Optional control flow dependencies Gives operation must be performed before this operation.
Definition: node.h:171
uint32_t num_outputs() const
Definition: node.h:232
an entry that represents output data from a node
Definition: node.h:52
std::unordered_map< NodeEntry, ValueType, NodeEntryHash, NodeEntryEqual > NodeEntryMap
Definition: node.h:114
NodeEntry()
Definition: node.h:69
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:206
std::unordered_map< std::string, std::string > dict
The dictionary representation of attributes.
Definition: node.h:129
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.
uint32_t index
index of output from the source.
Definition: node.h:78
C API of NNVM symbolic construction and pass. Enables construction and transformation of Graph in any...
static NodePtr Create(Args &&...args)
create a new empty shared_ptr of Node.
Definition: node.h:193
any info
additional fields for this node
Definition: node.h:173
Configuration of nnvm as well as basic data structure.
Operator structure.
Definition: op.h:104
const Op * op() const
Definition: node.h:224