-
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/extract op info into op info.cc #3587
Feature/extract op info into op info.cc #3587
Conversation
Fix cycle dependencies, Fix PaddlePaddle#3583.
* Add Get/Has methods to OpInfoMap * Add PADDLE_ENFORCE for OpInfo to get field.
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.
我没看明白为什么需要 OpInfo 和 OpInfoMap 。它们和 OpRegistry 是什么关系?尤其是OpReistry里有不少singleton了,为什么还要再加一个OpInfoMap::Instance?
return proto_ != nullptr && checker_ != nullptr; | ||
} | ||
|
||
const OpProto& Proto() const { |
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 am not sure if these PADDLE_ENFORCE are necessary. But if they are, please make OpInfo a class instead of a struct due to https://google.github.io/styleguide/cppguide.html#Structs_vs._Classes. Especially, if we need OpInfo a class, we should declare creator_ and other data members private
.
bool HasGradientOp() const { return !grad_op_type_.empty(); } | ||
}; | ||
|
||
class OpInfoMap { |
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 class seems unnecessary and should be removed, as its methods basically duplicate unordered_map's interface.
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 are lot duplicated code before.
See code here. To use unordered_map
directly could be nosing to check Is that key in the map? If not, enforce an error
again and again.
|
||
static OpInfoMap* g_op_info_map = nullptr; | ||
|
||
OpInfoMap& OpInfoMap::Instance() { |
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.
The right way to implement a singleton in C++ doesn't need global pointer variables:
OpInfoMap& OpInfoMap::Singleton() {
static OpInfoMap _;
return _;
}
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.
https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables
In Google C++ style, Only POD type can be a global variable. OpInfoMap
is a class, it should not 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.
确实。不过看上去也不需要一个global variable,可以是这样?
OpInfoMap& OpInfoMap::Singleton() {
static OpInfoMap* p = new OpInfoMap;
return *p;
}
@wangkuiyi OpInfo和OpInfoMap并不是新增的概念。他们原来在OpRegistry中。OpRegistry里面的singleton都统一到这个 这么做的原因如#3583所示,主要是:
|
paddle/framework/operator.h
Outdated
#define DEFINE_OP_CONSTRUCTOR(CLS, PARENT_CLS) \ | ||
CLS(const std::string& type, const VarNameMap& inputs, \ | ||
const VarNameMap& outputs, const paddle::framework::AttributeMap& attrs) \ | ||
#define DEFINE_OP_CONSTRUCTOR(CLS, PARENT_CLS) \ |
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 think CLS
and PARENT_CLS
should be lowercase.
See this example from Google c++ code style: https://google.github.io/styleguide/cppguide.html#Macro_Names
#define ROUND(x) ...
x
is lowercase.
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.
Fix cycle dependencies, Fix #3583.