-
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
[PHI]Unify Fluid and PHI kernel #49328
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
paddle/phi/core/kernel_factory.h
Outdated
@@ -241,10 +241,13 @@ class Kernel { | |||
|
|||
bool IsValid() const { return fn_ != nullptr; } | |||
|
|||
bool IsFuncKernel() const { return is_func_kernel_; } |
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.
个人理解,函数名改成 IsStructKernel
比较好?
IsFuncKernel
和 StructPhiKernel
是取反的概念,IsFuncKernel
的命名凭空多了一层理解成本
Maybe changing the name to IsStructKernel
would be better?
IsFuncKernel
and StructPhiKernel
are opposite concepts, the name IsFuncKernel
makes the understanding cost higher.
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.
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.
或许可以两个接口都加上?两种判断都更容易理解?IsFuncKernel 和 IsStructKernel
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.
讨论后决定使用枚举值来判断
FUNCTION_KERNEL_INSTANTIATION, \ | ||
ARG_PARSE_FUNCTOR, \ | ||
PHI_KERNEL, \ | ||
PHI_VARIADIC_KERNEL, \ |
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's the meaning of these four macros? Is it possible to simplify the registration process?
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.
好的,这里我会追加一下注释,不过简化方式目前我并没有想到更合适的方法,宏展开不太好处理,如果你有比较好的想法可以提一下
paddle/fluid/framework/op_registry.h
Outdated
@@ -486,3 +487,36 @@ struct OpKernelRegistrarFunctorEx<PlaceType, | |||
|
|||
} // namespace framework | |||
} // namespace paddle | |||
|
|||
namespace phi { |
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.
namespace还是在framework里吧,这个和目录是有关的,这里定位给fluid专用,咱们也不需要都搞到phi里
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.
好的,我改一下
paddle/phi/core/kernel_factory.h
Outdated
@@ -241,10 +241,13 @@ class Kernel { | |||
|
|||
bool IsValid() const { return fn_ != nullptr; } | |||
|
|||
bool IsFuncKernel() const { return is_func_kernel_; } |
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.
或许可以两个接口都加上?两种判断都更容易理解?IsFuncKernel 和 IsStructKernel
paddle/phi/core/kernel_registry.h
Outdated
@@ -32,7 +32,7 @@ | |||
namespace phi { | |||
|
|||
#define BACKEND(arg__) phi::Backend::arg__ | |||
#define DATALAYOUT(arg__) phi::DataLayout::arg__ | |||
#define _DATALAYOUT(arg__) phi::DataLayout::arg__ |
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.
由于这个头文件在op_registry.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.
这种情况是不改op_registry.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.
我和其他团队下去再沟通一下吧,这个涉及到其他团队宏定义的命名,咱们不改他们就要改,需要看一下对他们的影响范围
paddle/phi/core/kernel_registry.h
Outdated
meta_kernel_fn, \ | ||
kernel_instantiation, \ | ||
arg_parse_functor, \ | ||
to_kernel, \ |
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.
这里的名称可以再用得更“自解释”一些吗?这里是向下传递一个用于展开kernel的宏,比如是否可以叫“kernel_unfold_macro”, "variadic_kernel_unfold_marco"
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.
好的
paddle/phi/core/kernel_registry.h
Outdated
context, \ | ||
layout, \ | ||
meta_kernel_fn, \ | ||
kernel_instantiation, \ |
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.
以及这个,kernel_instantiate_macro
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.
好的,谢谢
paddle/phi/core/kernel_factory.cc
Outdated
return std::all_of(kernel_iter->second.begin(), | ||
kernel_iter->second.end(), | ||
[](phi::KernelKeyMap::const_reference kernel_pair) { | ||
return kernel_pair.second.GetKernelRegisteredType() == | ||
KernelRegisteredType::STRUCTURE; | ||
}); |
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.
同一个Kernel的map里会同时有STRUCTURE
和FUNCTION
两种类型的Kernel吗?
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.
一般不会,这里我再改一下吧,在注册端拦截一下Kernel的类型,防止出现多种类型的注册
paddle/phi/core/kernel_registry.h
Outdated
if (variadic_kernel_fn == nullptr) { | ||
kernel_registered_type = KernelRegisteredType::STRUCTURE; | ||
} |
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.
看上去kernel_registered_type
的类型可以由variadic_kernel_fn
来决定,这个逻辑是不可以直接放在构造函数里?这样开发者看着也比较直观,也避免了kernel_registered_type
作为参数传进去构造
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.
好的,我修改一下
paddle/phi/core/kernel_registry.h
Outdated
@@ -32,7 +32,7 @@ | |||
namespace phi { | |||
|
|||
#define BACKEND(arg__) phi::Backend::arg__ | |||
#define DATALAYOUT(arg__) phi::DataLayout::arg__ | |||
#define _DATALAYOUT(arg__) phi::DataLayout::arg__ |
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.
这种情况是不改op_registry.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.
LGTM
PR types
Others
PR changes
Others
Describe
完善机制,使得Fluid的结构体Kernel可以注册到PHI中,并且修改rank_loss_op验证功能