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

[PHI]Unify Fluid and PHI kernel #49328

Merged
merged 16 commits into from
Feb 8, 2023

Conversation

YuanRisheng
Copy link
Contributor

@YuanRisheng YuanRisheng commented Dec 26, 2022

PR types

Others

PR changes

Others

Describe

完善机制,使得Fluid的结构体Kernel可以注册到PHI中,并且修改rank_loss_op验证功能

@paddle-bot
Copy link

paddle-bot bot commented Dec 26, 2022

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@@ -241,10 +241,13 @@ class Kernel {

bool IsValid() const { return fn_ != nullptr; }

bool IsFuncKernel() const { return is_func_kernel_; }
Copy link
Contributor

Choose a reason for hiding this comment

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

个人理解,函数名改成 IsStructKernel 比较好?
IsFuncKernelStructPhiKernel 是取反的概念,IsFuncKernel 的命名凭空多了一层理解成本

Maybe changing the name to IsStructKernel would be better?
IsFuncKernel and StructPhiKernel are opposite concepts, the name IsFuncKernel makes the understanding cost higher.

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.

个人感觉StructuredKernel从理解上会比较容易些,torch中也有类似的命名方式,具体可以再讨论下
image

Copy link
Contributor

Choose a reason for hiding this comment

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

或许可以两个接口都加上?两种判断都更容易理解?IsFuncKernel 和 IsStructKernel

Copy link
Contributor Author

@YuanRisheng YuanRisheng Jan 18, 2023

Choose a reason for hiding this comment

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

讨论后决定使用枚举值来判断

Comment on lines +407 to +410
FUNCTION_KERNEL_INSTANTIATION, \
ARG_PARSE_FUNCTOR, \
PHI_KERNEL, \
PHI_VARIADIC_KERNEL, \
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,这里我会追加一下注释,不过简化方式目前我并没有想到更合适的方法,宏展开不太好处理,如果你有比较好的想法可以提一下

@@ -486,3 +487,36 @@ struct OpKernelRegistrarFunctorEx<PlaceType,

} // namespace framework
} // namespace paddle

namespace phi {
Copy link
Contributor

Choose a reason for hiding this comment

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

namespace还是在framework里吧,这个和目录是有关的,这里定位给fluid专用,咱们也不需要都搞到phi里

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,我改一下

@@ -241,10 +241,13 @@ class Kernel {

bool IsValid() const { return fn_ != nullptr; }

bool IsFuncKernel() const { return is_func_kernel_; }
Copy link
Contributor

Choose a reason for hiding this comment

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

或许可以两个接口都加上?两种判断都更容易理解?IsFuncKernel 和 IsStructKernel

@@ -32,7 +32,7 @@
namespace phi {

#define BACKEND(arg__) phi::Backend::arg__
#define DATALAYOUT(arg__) phi::DataLayout::arg__
#define _DATALAYOUT(arg__) phi::DataLayout::arg__
Copy link
Contributor

Choose a reason for hiding this comment

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

这个地方加下滑线的考虑是?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

由于这个头文件在op_registry.h里进行了引用,造成了和其他模块宏定义冲突的问题,这里加下划线去除冲突,表示内部使用

Copy link
Contributor

Choose a reason for hiding this comment

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

这种情况是不改op_registry.h里的宏定义名会更合适?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我和其他团队下去再沟通一下吧,这个涉及到其他团队宏定义的命名,咱们不改他们就要改,需要看一下对他们的影响范围

meta_kernel_fn, \
kernel_instantiation, \
arg_parse_functor, \
to_kernel, \
Copy link
Contributor

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

context, \
layout, \
meta_kernel_fn, \
kernel_instantiation, \
Copy link
Contributor

Choose a reason for hiding this comment

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

以及这个,kernel_instantiate_macro

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,谢谢

Comment on lines 70 to 75
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;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

同一个Kernel的map里会同时有STRUCTUREFUNCTION两种类型的Kernel吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

一般不会,这里我再改一下吧,在注册端拦截一下Kernel的类型,防止出现多种类型的注册

Comment on lines 352 to 354
if (variadic_kernel_fn == nullptr) {
kernel_registered_type = KernelRegisteredType::STRUCTURE;
}
Copy link
Contributor

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作为参数传进去构造

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,我修改一下

@@ -32,7 +32,7 @@
namespace phi {

#define BACKEND(arg__) phi::Backend::arg__
#define DATALAYOUT(arg__) phi::DataLayout::arg__
#define _DATALAYOUT(arg__) phi::DataLayout::arg__
Copy link
Contributor

Choose a reason for hiding this comment

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

这种情况是不改op_registry.h里的宏定义名会更合适?

Copy link
Contributor

@jiahy0825 jiahy0825 left a comment

Choose a reason for hiding this comment

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

LGTM

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

Successfully merging this pull request may close these issues.

4 participants