-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Add BlockDesc
and ProgramDesc
to framework.proto
#4276
Conversation
paddle/framework/attribute.h
Outdated
@@ -29,11 +29,13 @@ namespace framework { | |||
|
|||
typedef boost::variant<boost::blank, int, float, std::string, std::vector<int>, | |||
std::vector<float>, std::vector<std::string>, | |||
std::vector<std::pair<int, int>>> | |||
std::vector<std::pair<int, int>>, BlockDesc> |
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.
Actually, this variant is BlockDesc*
to avoid memcpy.
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.
done
paddle/framework/attribute.h
Outdated
Attribute; | ||
|
||
typedef std::unordered_map<std::string, Attribute> AttributeMap; | ||
|
||
static ProgramDesc g_program_desc; |
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.
In Google C++ style, a class instance cannot be a global variable.
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.
It cannot be written in .h
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.
Variable definition usually should not be written in a header file, because it will define all variables in .cc which includes this header. Here should be a declaration.
-
To define an int value, we use
int a;
. To declare an int value, we useextern int a;
.extern
means somewhere is define that int value, but every.cc
which includes this header can use that int value. -
static
means not to generate symbol name in.S
or.o
file. So this will actually create manyProgramDesc
, each.cc
has a newg_program_desc
.
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.
Got it
paddle/framework/attribute.cc
Outdated
std::vector<std::pair<int, int>> val(attr_desc.int_pairs_size()); | ||
for (int i = 0; i < attr_desc.int_pairs_size(); ++i) { | ||
val[i].first = attr_desc.int_pairs(i).first(); | ||
val[i].second = attr_desc.int_pairs(i).second(); | ||
} | ||
return val; | ||
} | ||
case framework::AttrType::BLOCK: { | ||
return g_program_desc.blocks(attr_desc.block_idx()); |
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.
Just return a pointer, to avoid memcpy.
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.
done
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.
Excellent Job!
No description provided.