提交 7231ef6b 编写于 作者: X Xin Pan

tmp

上级 68aa5004
...@@ -58,9 +58,9 @@ class Graph { ...@@ -58,9 +58,9 @@ class Graph {
return attr; return attr;
} }
std::vector<Node*> inputs; std::vector<ir::Node*> inputs;
std::vector<Node*> outputs; std::vector<ir::Node*> outputs;
std::vector<std::unique_ptr<Node>> nodes; std::vector<std::unique_ptr<ir::Node>> nodes;
private: private:
std::map<std::string, boost::any> attrs_; std::map<std::string, boost::any> attrs_;
......
...@@ -15,6 +15,7 @@ limitations under the License. */ ...@@ -15,6 +15,7 @@ limitations under the License. */
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <functional>
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -23,13 +24,23 @@ limitations under the License. */ ...@@ -23,13 +24,23 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace framework { namespace framework {
namespace ir {
class Node { class Node {
public: public:
enum class Type { kNone = -1, kOperation, kVariable }; enum class Type { kNone = -1, kOperation, kVariable };
Node() {} Node(const std::string& name, Type type) : name_(name), type_(type) {}
virtual ~Node() {}
virtual ~Node() {
for (auto& attr : attrs_) {
if (attr_dels_.find(attr.first) != attr_dels_.end()) {
attr_dels_[attr.first]();
}
}
attr_dels_.clear();
attrs_.clear();
}
int64_t ID() const { return id_; } int64_t ID() const { return id_; }
...@@ -43,17 +54,42 @@ class Node { ...@@ -43,17 +54,42 @@ class Node {
Type NodeType() const { return type_; } Type NodeType() const { return type_; }
std::vector<Node *> inputs; template <typename AttrType>
std::vector<Node *> outputs; void Set(const std::string& name, AttrType attr) {
attrs_[name] = attr;
}
template <typename AttrType>
void Set(const std::string& name, AttrType* attr,
std::function<void(void)> attr_del) {
attrs_[name] = attr;
attr_dels_[name] = attr_del;
}
std::vector<Node*> inputs;
std::vector<Node*> outputs;
protected: protected:
std::map<std::string, std::vector<boost::any>> attrs_; std::map<std::string, boost::any> attrs_;
std::map<std::string, std::function<void(void)>> attr_dels_;
int64_t id_ = 0; int64_t id_ = 0;
std::string name_; std::string name_;
Type type_; Type type_;
private:
DISABLE_COPY_AND_ASSIGN(Node); DISABLE_COPY_AND_ASSIGN(Node);
}; };
class Variable : public Node {
public:
explicit Variable(const std::string& name) : Node(name, Type::kVariable) {}
};
class Operation : public Node {
public:
explicit Operation(const std::string& name) : Node(name, Type::kOperation) {}
};
} // namespace ir
} // namespace framework } // namespace framework
} // namespace paddle } // namespace paddle
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册