Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Sarkars/builder #176

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open

Sarkars/builder #176

wants to merge 38 commits into from

Conversation

sayantan-nervana
Copy link
Contributor

Please take a look at the builder refactoring change.

  1. Switching from old to new builder.
    The killswitch is a primeval C style macro in encapsulate_op.cc. Maybe there is a better/preferable method. But I used it instead of if(flag) because, when we enable the newbuilder at a later stage, we can just delete the stuff in the #if-#else en masse and not have to modify any more code.
    Currently, the old builder is in use, so nothing should fall apart.

#define BUILDER1 // (un)comment this line to (de)activate old builder

#ifdef BUILDER1
newbuilder
#else
oldbuilder
#endif

  1. I will continue adding more TranslateOps functions in the meanwhile

  2. Since its a big change, I am sure there are style issues, questionable design/syntax choices, outright unoptimised chunks and sneaky leaks. Your feedback is very important and appreciated.

Copy link
Contributor

@aprocter aprocter left a comment

Choose a reason for hiding this comment

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

Good stuff! Just some suggestions.

src/ngraph_builder1.h Outdated Show resolved Hide resolved
src/ngraph_builder1.cc Show resolved Hide resolved
// Given the input shapes and a list of TF _Arg nodes, create corresponding
// nGraph parameters. Also populate the ng_op_map
Status GetInputParams(const std::vector<TensorShape>&, vector<const Node*>,
vector<shared_ptr<ng::op::Parameter>>&);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think TF style favors pointers over non-const references (not 100% sure though)

// Given a TF node, return its corresponding TranslateOp function and required
// input indexes. A wrapper for TRANSLATE_OP_MAP and INPUT_INDEX_MAP
Status GetOpTranslationRequirements(const Node*, Builder1::TranslatorFn&,
vector<int>&);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think TF style favors pointers over non-const references (not 100% sure though)

Copy link
Contributor Author

@sayantan-nervana sayantan-nervana Aug 31, 2018

Choose a reason for hiding this comment

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

https://google.github.io/styleguide/cppguide.html#Reference_Arguments

It seems to prefer a const T&, and never a raw T&. It prefers T* over T& for 'return' values.

But, our code makes a lot of use of T& for returning. For example TranslateGraph itself uses std::shared_ptrngraph::Function& to return the created ng_function.

The 'cons' of not using T& as stated in the style guide is:
References can be confusing, as they have value syntax but pointer semantics.

I am not sure if addressing that con is worth the effort of overhauling all places where we have already used T& for returning values

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right---we didn't really fully absorb that this was a Google style preference until we had written a fair chunk of the bridge code already, so a lot of our code is using return-via-reference. I guess it's a question of whether we need to conform to Google style here. I'll leave that question up to @avijit-nervana .

src/ngraph_builder1.cc Outdated Show resolved Hide resolved
src/ngraph_translateops.h Show resolved Hide resolved
src/ngraph_builder1.cc Show resolved Hide resolved
src/ngraph_translateops.h Outdated Show resolved Hide resolved
src/ngraph_builder1.h Outdated Show resolved Hide resolved
src/ngraph_builder1.h Outdated Show resolved Hide resolved
@sayantan-nervana
Copy link
Contributor Author

I think most of Adam's review comments are addressed or incorporated. The two things remaining are:

  1. T& vs T* for return. TF style prefers T* for return/changeable variables. references are preferred with consts. But in out code, we use TranslateGraph that uses non-const T&.
  2. Adding MakeNGraphNode as suggested by Adam in Slack. Should we do this in a new PR?

Any other thing that I missed in the above summary?

@avijit-nervana
Copy link
Contributor

avijit-nervana commented Sep 3, 2018 via email

@sayantan-nervana
Copy link
Contributor Author

Ok, will make the T& -> T* changes. Also tagged you in slack

int32 max_arg_index = -1;
std::vector<const Node*> arg_nodes;

for (auto node : m_tf_graph.nodes()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can loop over m_tf_params as we have already classified the nodes into params, retvals and ops. Might not need the arg_nodes vector, can use m_tf_params

Copy link
Contributor

Choose a reason for hiding this comment

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

Going by the GetInputParams() function, max_arg_index = m_tf_params.size()-1 .. In that case we dont need this loop. And, If the _Arg indexes are not predictable, i.e. in sequence (0 to n-1) then GetInputParams() would need changes, ng_parameter_list[index] = ng_param; index might be greater than size.

// vector of generated nGraph nodes. Since we process nodes in toposort
// order, it is guaranteed when processing a TF node, its parents
// will already have been processed and safely stowed in ng_op_map
std::unordered_map<std::string, vector<shared_ptr<ng::Node>>> m_ng_op_map;
Copy link
Contributor

Choose a reason for hiding this comment

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

Google Style Guide suggests adding trailing _ to all private data members of a class. nGraph core follows the style adopted here.
https://google.github.io/styleguide/cppguide.html#Variable_Names
@avijit-nervana which one is recommended? Actually we can do both, by adding _ to all the variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The m_ means data member, and s_ means static members. According to Adam, ngraph follows m_ and s_, so I have that format. Not sure if we stick to (m_, s_) or trailing _

Copy link
Contributor

Choose a reason for hiding this comment

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

@sayantan-nervana When you get a chance - please resolve the conflict.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants