-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/analysis node representation #10522
feature/analysis node representation #10522
Conversation
…/inference-framework
…/inference-framework
template <typename T> | ||
class OrderedRegistry { | ||
public: | ||
T *Register(const std::string &name, T *x) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be std::unique_ptr? if the ownership is transferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the pointer will be used by others and a shared_ptr
is a little heavy here, so the implementation of this function is
dic_[name] = data_.size();
data_.emplace_back(std::unique_ptr<T>(x));
return data_.back().get();
Here just a Register
and a Lookup
, without a Remove
API, so the owner can't be transferred to others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not suggesting a shared_ptr here.
Usually, unique_ptr in function def means the ownership of the pointer is tranferred to the function.
T *Register(const std::string &name, std::unique_ptr<T> x)
Register("foo", std::move(some_unique_ptr))
// Cast to a subclass type, Function for example. | ||
template <typename Subclass> | ||
Subclass &As() { | ||
return *reinterpret_cast<Subclass *>(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dynamic_cast is safer here?
namespace analysis { | ||
|
||
std::vector<Dot::Attr> Value::dot_attrs() const { | ||
return std::vector<Dot::Attr>({Dot::Attr("style", "filled,rounded"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are these "style" "shape" thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are DOT language's attributes, to control the visualization for graph debug.
Here, different Node
might have the different visual effect, for example, Operator
and Variable
looks different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
// DOT node representation. One Node type can customize its own node | ||
// representation. | ||
virtual std::vector<Dot::Attr> dot_attrs() const { | ||
return std::vector<Dot::Attr>({Dot::Attr("style", "filled")}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is "style" "filled"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This DOT's syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
data.resize(sizeof(T)); | ||
} | ||
PADDLE_ENFORCE_EQ(data.size(), sizeof(T), "Node attr type recast error"); | ||
return *reinterpret_cast<T *>(&data[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels crazy dangerous to me. You basically allow people to cast it to anything and then cause all kinds of memory issues?
template <typename T> | ||
class OrderedRegistry { | ||
public: | ||
T *Register(const std::string &name, T *x) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not suggesting a shared_ptr here.
Usually, unique_ptr in function def means the ownership of the pointer is tranferred to the function.
T *Register(const std::string &name, std::unique_ptr<T> x)
Register("foo", std::move(some_unique_ptr))
namespace analysis { | ||
|
||
std::vector<Dot::Attr> Value::dot_attrs() const { | ||
return std::vector<Dot::Attr>({Dot::Attr("style", "filled,rounded"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
// DOT node representation. One Node type can customize its own node | ||
// representation. | ||
virtual std::vector<Dot::Attr> dot_attrs() const { | ||
return std::vector<Dot::Attr>({Dot::Attr("style", "filled")}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
@@ -105,16 +105,19 @@ class Node { | |||
template <typename T> | |||
T &As() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to split this into a few different methods:
AsFoo()
AsBar()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
fixes: #10602