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] Migrate elementwise add, sub and mul kernels #47657

Closed

Conversation

piotrekobi
Copy link
Contributor

@piotrekobi piotrekobi commented Nov 3, 2022

PR types

Others

PR changes

Others

Describe

Migrates the following oneDNN operator fluid kernels to PHI:

  • elementwise_add
  • elementwise_sub
  • elementwise_mul

@paddle-bot
Copy link

paddle-bot bot commented Nov 3, 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.

@paddle-bot paddle-bot bot added contributor External developers status: proposed labels Nov 3, 2022
@piotrekobi
Copy link
Contributor Author

@chenwhql I have a few issues with migrating the elementwise kernels:

  1. I'm getting errors related to .cc tests at the end of compilation even though I added PD_DECLARE_KERNEL(...) changes to them
  2. The Out tensor is required in some grad kernels. It was previously acquired by auto* out = ctx.Input<phi::DenseTensor>("Out"). I tried auto* out = dev_ctx.GetDnnInput("Out") but it doesn't work.
  3. When I try to register the divide_grad kernel I'm getting compilation errors, starting with:
In file included from /home/ppaturej/Paddle/paddle/phi/core/custom_kernel.h:18,
                 from /home/ppaturej/Paddle/paddle/phi/core/kernel_registry.h:24,
                 from /home/ppaturej/Paddle/paddle/phi/kernels/onednn/elementwise_grad_kernel.cc:21:
/home/ppaturej/Paddle/paddle/phi/core/kernel_registry.h:457:55: error: decltype cannot resolve address of overloaded function
   template decltype(meta_kernel_fn<cpp_dtype, context>) \

Could you please help me solve these problems?

@yaomichael
Copy link

@YuanRisheng can you help @piotrekobi out?

@YuanRisheng
Copy link
Contributor

@chenwhql I have a few issues with migrating the elementwise kernels:

  1. I'm getting errors related to .cc tests at the end of compilation even though I added PD_DECLARE_KERNEL(...) changes to them
  2. The Out tensor is required in some grad kernels. It was previously acquired by auto* out = ctx.Input<phi::DenseTensor>("Out"). I tried auto* out = dev_ctx.GetDnnInput("Out") but it doesn't work.
  3. When I try to register the divide_grad kernel I'm getting compilation errors, starting with:
In file included from /home/ppaturej/Paddle/paddle/phi/core/custom_kernel.h:18,
                 from /home/ppaturej/Paddle/paddle/phi/core/kernel_registry.h:24,
                 from /home/ppaturej/Paddle/paddle/phi/kernels/onednn/elementwise_grad_kernel.cc:21:
/home/ppaturej/Paddle/paddle/phi/core/kernel_registry.h:457:55: error: decltype cannot resolve address of overloaded function
   template decltype(meta_kernel_fn<cpp_dtype, context>) \

Could you please help me solve these problems?

For the first point, please provide more detailed error information.

For the second point, the only kernel that uses Out tensor is DivideGradKernel and you need separate divide_grad logic from EltwiseMKLDNNGradKernel for it. Please see the function declaration of DivideGradKernel in "elementwise_divide_grad_kernel.h". It has provided Out tensor.

For the third point, It is because the kernel you defined is not equal with the function declaration of DivideGradKernel in "elementwise_divide_grad_kernel.h".
Good luck. @piotrekobi

@piotrekobi
Copy link
Contributor Author

@YuanRisheng Thanks a lot for your help with the elementwise_div_grad registration! The issues were simple to fix.

I'm still getting compilation errors related to .cc tests after adding PD_DECLARE_KERNEL(...) to them.
Here's the error message:

[ 89%] Linking CXX executable tests/test_mkldnn_caching
/usr/bin/ld: CMakeFiles/test_mkldnn_caching.dir/fluid/operators/mkldnn/test_mkldnn_caching.cc.o: in function `__static_initialization_and_destruction_0(int, int) [clone .constprop.994]':
test_mkldnn_caching.cc:(.text.startup+0x83d): undefined reference to `TouchKernelSymbolFor_elementwise_add_OneDNN_ONEDNN()'
/usr/bin/ld: test_mkldnn_caching.cc:(.text.startup+0x847): undefined reference to `TouchKernelSymbolFor_elementwise_mul_OneDNN_ONEDNN()'
collect2: error: ld returned 1 exit status
make[2]: *** [paddle/CMakeFiles/test_mkldnn_caching.dir/build.make:92: paddle/tests/test_mkldnn_caching] Error 1
make[1]: *** [CMakeFiles/Makefile2:7073: paddle/CMakeFiles/test_mkldnn_caching.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

@YuanRisheng
Copy link
Contributor

YuanRisheng commented Nov 10, 2022

@YuanRisheng Thanks a lot for your help with the elementwise_div_grad registration! The issues were simple to fix.

I'm still getting compilation errors related to .cc tests after adding PD_DECLARE_KERNEL(...) to them. Here's the error message:

[ 89%] Linking CXX executable tests/test_mkldnn_caching
/usr/bin/ld: CMakeFiles/test_mkldnn_caching.dir/fluid/operators/mkldnn/test_mkldnn_caching.cc.o: in function `__static_initialization_and_destruction_0(int, int) [clone .constprop.994]':
test_mkldnn_caching.cc:(.text.startup+0x83d): undefined reference to `TouchKernelSymbolFor_elementwise_add_OneDNN_ONEDNN()'
/usr/bin/ld: test_mkldnn_caching.cc:(.text.startup+0x847): undefined reference to `TouchKernelSymbolFor_elementwise_mul_OneDNN_ONEDNN()'
collect2: error: ld returned 1 exit status
make[2]: *** [paddle/CMakeFiles/test_mkldnn_caching.dir/build.make:92: paddle/tests/test_mkldnn_caching] Error 1
make[1]: *** [CMakeFiles/Makefile2:7073: paddle/CMakeFiles/test_mkldnn_caching.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

@piotrekobi Well, I get it. For elementwise_add, the kernel name registered in PHI is add_raw or add. So, you can modify it like this : PD_DECLARE_KERNEL(add_raw, OneDNN, ONEDNN); .The same reason is for elementwise_mul

@piotrekobi
Copy link
Contributor Author

@YuanRisheng Thanks! Everything seems to be working now.

@piotrekobi piotrekobi marked this pull request as ready for review November 10, 2022 10:42
@piotrekobi piotrekobi changed the title [PHI] Migrate elementwise+grad kernels [PHI] Migrate elementwise add, sub and mul kernels Nov 23, 2022
@Silv3S
Copy link
Member

Silv3S commented Dec 6, 2022

Done in #48625, #48611

@paddle-bot
Copy link

paddle-bot bot commented Dec 6, 2022

很抱歉,经过我们的反复讨论,你的PR暂未达到合入标准,请阅读飞桨原生算子开发规范,你可以重新提交新的PR,我们先将此PR关闭,感谢你的贡献。
Sorry to inform you that through our discussion, your PR fails to meet the merging standard (Reference: Paddle Custom Operator Design Doc). You can also submit an new one. Thank you.

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

Successfully merging this pull request may close these issues.

6 participants