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] Add phi device context pool #40635

Merged
merged 7 commits into from
Mar 21, 2022

Conversation

chenwhql
Copy link
Contributor

@chenwhql chenwhql commented Mar 16, 2022

PR types

Performance optimization

PR changes

APIs

Describe

[Phi] Add phi device context pool

基于以下两个需求,在phi/api中添加DeviceContextPool:

  1. 部分高阶用户需要在自定义算子中获取内部DeviceContext,使用内部Context的一些handle,确保自定义算子显存管理与框架一致,避免自定义算子内频繁发生内存申请释放操作从而影响性能
  2. 新动态图对phi C++ API有较高的性能要求,而原先的DeviceContextPool访问效率较低
  • 新增DeviceContextPool,同时优化了Place的Hash访问实现

性能变化:

  • 基于对新动态图_C_ops.final_state_diagonal的百万次循环测试采样数据进行分析
    • 缩减50%耗时:0.15s(2.44%) - > 0.08s(1.22%)

    • 本PR前:

      • image
    • 本PR后:(耗时较少,主图上不再显示GetDeviceContextByBackend,以下为搜索找到的局部显示)

      • image

TODO:下一个PR再将DeviceContextPool关联到的自定义算子中

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

paddle/phi/common/place.h Outdated Show resolved Hide resolved
jiweibo
jiweibo previously approved these changes Mar 18, 2022
Copy link
Contributor

@jiweibo jiweibo left a comment

Choose a reason for hiding this comment

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

LGTM👍🏻

* in program running, so DeviceContextPool here can always access the correct
* DeviceContext pointer.
*
* In order not to depend on the fluid's DeviceContextPool,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

中间实现有所调整,这里注释也需要调整下,下个pr完善下

@chenwhql chenwhql requested a review from jiweibo March 21, 2022 02:30
Copy link
Contributor

@jiweibo jiweibo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

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

LGTM for const_cast

@chenwhql chenwhql merged commit 0e1191f into PaddlePaddle:develop Mar 21, 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.

4 participants