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

【PFCC算子性能优化】 SeluKernel Optimization #44490

Merged
merged 5 commits into from
Aug 2, 2022

Conversation

carryyu
Copy link
Contributor

@carryyu carryyu commented Jul 20, 2022

PR types

Performance optimization

PR changes

OPs

Describe

[PFCC算子性能优化] Selu Kernel性能优化,抛弃原有Eigen写法,放入activation_kernel文件中。
优化文档PR链接:PaddlePaddle/community#169

当前性能如下表:

Case No. device input_shape input_type Paddle Perf(ms)
1 Tesla T4 [8, 1024, 3072] float32 0.9122
2 Tesla T4 [8, 1024, 3072] float64 5.2592

PyTorch性能如下:

Case No. device input_shape input_type Pytorch Perf(ms)
1 Tesla T4 [8, 1024, 3072] float32 0.8349
2 Tesla T4 [8, 1024, 3072] float64 5.4939

通过使用飞桨内部的Elementwise Kernel来进行计算。通过向量化读取、向量化写入以及gpu_launch_config.h中的线程配置方法对算子进行优化。

完成优化后,Paddle与优化前的Paddle的性能对比效果如下,达到了预期性能提升效果(提升>=5%):

Case No. device input_shape input_type Paddle Perf(ms) Old-Paddle Perf(ms) diff
1 Tesla T4 [8, 1024, 3072] float32 0.8277 0.9122 faster than 9.26%
2 Tesla T4 [8, 1024, 3072] float64 4.5655 5.2592 faster than 13.19%

完成优化后,Paddle与Pytorch的性能对比效果如下,在fp32情况下基本与Pytorch持平,在fp64情况下提升较大 :

Case No. device input_shape input_type Paddle Perf(ms) Pytorch Perf(ms) diff
1 Tesla T4 [8, 1024, 3072] float32 0.8277 0.8349 faster than 0.86%
2 Tesla T4 [8, 1024, 3072] float64 4.5655 5.4939 faster than 16.89%

@paddle-bot
Copy link

paddle-bot bot commented Jul 20, 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.

@carryyu carryyu requested a review from JamesLim-sy August 1, 2022 05:57
float scale;
float alpha;
double zero = static_cast<double>(0.0f);

Copy link
Contributor

Choose a reason for hiding this comment

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

对于以下内置变量可以用private关键字标注下:

 private :
    float scale;
    float alpha;
    double zero = static_cast<double>(0.0f);

float scale;
float alpha;
T zero = static_cast<T>(0.0f);

Copy link
Contributor

Choose a reason for hiding this comment

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

同下

@JamesLim-sy
Copy link
Contributor

代码上没啥问题了,按照这个链接中的表述,简单在PR Comment里面补充描述下吧:
https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/op_optimization/op_optimization_accpetance_criteria_cn.html#pr

@carryyu
Copy link
Contributor Author

carryyu commented Aug 2, 2022

代码上没啥问题了,按照这个链接中的表述,简单在PR Comment里面补充描述下吧: https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/op_optimization/op_optimization_accpetance_criteria_cn.html#pr

已修改

Copy link
Contributor

@JamesLim-sy JamesLim-sy left a comment

Choose a reason for hiding this comment

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

LGTM

@JamesLim-sy JamesLim-sy merged commit 859c407 into PaddlePaddle:develop Aug 2, 2022
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.

2 participants