Skip to content
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

Merged
merged 15 commits into from
May 14, 2018

Conversation

Superjomn
Copy link
Contributor

@Superjomn Superjomn commented May 9, 2018

fixes: #10602

@Superjomn Superjomn changed the title feature/inference framework feature/analysis node representation May 9, 2018
@Superjomn Superjomn requested review from luotao1 and Xreki May 9, 2018 09:56
@Superjomn Superjomn self-assigned this May 12, 2018
@Superjomn Superjomn added the 预测 原名Inference,包含Capi预测问题等 label May 12, 2018
@Superjomn Superjomn added this to To do in Inference on Engine via automation May 12, 2018
@Superjomn Superjomn added this to the infernce-enable-engine 0.1 milestone May 12, 2018
@Superjomn Superjomn moved this from To do to In progress in Inference on Engine May 12, 2018
@Superjomn Superjomn removed this from In progress in Inference on Engine May 12, 2018
template <typename T>
class OrderedRegistry {
public:
T *Register(const std::string &name, T *x) {
Copy link
Contributor

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.

Copy link
Contributor Author

@Superjomn Superjomn May 13, 2018

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.

Copy link
Contributor

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);
Copy link
Contributor

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"),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

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")});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is "style" "filled"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This DOT's syntax.

Copy link
Contributor

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]);
Copy link
Contributor

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) {
Copy link
Contributor

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"),
Copy link
Contributor

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")});
Copy link
Contributor

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() {
Copy link
Contributor

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()

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Superjomn Superjomn merged commit de81ccb into PaddlePaddle:develop May 14, 2018
@Superjomn Superjomn deleted the feature/inference-framework branch May 14, 2018 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
预测 原名Inference,包含Capi预测问题等
Projects
None yet
Development

Successfully merging this pull request may close these issues.

analysis/node
3 participants