-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.h
57 lines (41 loc) · 1.34 KB
/
node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef _NODE_H_
#define _NODE_H_
#include <string>
#include <vector>
#include "context.h"
namespace graph_executor {
class Graph;
// `Node` class itself doesn't handle any concurrency issues as it is stateless.
// The user of `Node` class should handle it.
// Virtual base class of execution nodes.
class Node {
public:
explicit Node(const std::string &name = "") : name_(name){};
virtual ~Node() = default;
// Not copyable. Movable.
Node(const Node &other) = delete;
Node(Node &&other) = default;
const std::string &Name() const { return name_; }
const std::vector<Context *> &Inputs() const { return inputs_; }
const std::vector<Context *> &Outputs() const { return outputs_; }
// Binds the node to input and output contexts.
void Bind(const std::vector<Context *> &inputs,
const std::vector<Context *> &outputs);
// Whether the node can get inputs and put outputs.
bool IsReady() const;
// Executes the node.
virtual void Execute() const = 0;
protected:
std::string name_;
std::vector<Context *> inputs_;
std::vector<Context *> outputs_;
};
// A special execution node that does nothing. It can be used as inputs/outputs
// nodes to concatenate contexts and create dependency.
class NoOpNode : public Node {
public:
using Node::Node;
virtual void Execute() const {}
};
} // namespace graph_executor
#endif