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

Incremental compilation optimization of phi #59811

Merged
merged 13 commits into from
Dec 11, 2023

Conversation

risemeup1
Copy link
Contributor

@risemeup1 risemeup1 commented Dec 7, 2023

PR types

others

PR changes

others

Description

  1. 背景:

    • Paddle现在面临增量编译耗时非常长,改一些不相关的cmake代码或者简单的代码,甚至在cmake加一行空格,phi目录下的所有文件都会重新编译,约30min(不同机器可能有差异),主要原因是cmake代码不规范,此PR用来优化phi在增量编译中存在的问题。
  2. phi增量编译存在的问题:

    • phi作为独立编译模块,理论上phi目录下的所有符号都应该编译到libphi.so中,但是phi/kernels/ops/compat/*.cc文件并没有编译在phi中,而是在paddle/fluid/operators/generator/中编译,故将这些文件放在这fluid目录下更加合理,也是导致phi重新编译的原因之一

    • phi/kernels/fusion/下面有多个通过一些.py文件生成大量.cu文件的操作(约150个),cmake写法都是通过execute_process生成,每次cmake构建阶段都会重新生成,时间戳发生变化,导致phi下这些kernel文件都会重新编译(约20min),也是增量编译耗时过长的原因,应设置tmp文件配合copy_if_different或者用add_custom_command,add_custom_target命令封装在make阶段编译进行优化。

    • 不仅仅是phi/kernels目录,往往改了很简单的文件,phi基本上都会从0开始编译,主要原因是phi/CMakeLists.txt/下调用了phi.cmake中的generate_unify_header函数,此函数中使用了一些string(replace xxx)操作导致cmake阶段检测到phi下边的文件几乎都有变化,故需要使用更加规范的cmake代码进行重构

    • 还有一些其它地方也是类似于生成代码的逻辑都会在增量编译存在这个问题,需要添加合适的跳过机制

  3. 收益:

    • 本地测试(a100机器,cpu核心数159),增量编译可以受益约15min,p40收益约30min,不同机器可能有差异

    • CI上也普遍存在这个问题,优化后CI配合ccache也有较大收益

    • 优化之后,只有改phi或者common(phi依赖基础组件common)中的文件,phi才会重新编译(且只编译phi目录下改动的某个.cc文件),若改了phi依赖的库文件,只会重新Linking CXX shared library libphi.so,不会重新编译phi,符合预期

  4. To do

    • fluid等其它目录也存在这样的问题,此PR之后优化fluid目录

    • 添加cmake代码相关监控

Pcard-67010

Copy link

paddle-bot bot commented Dec 7, 2023

你的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.

@risemeup1 risemeup1 changed the title [cmake治理]mv phi/ops/.cc file to fluid [cmake治理]mv phi/ops/_compat/*.cc files to fluid Dec 7, 2023
@risemeup1 risemeup1 changed the title [cmake治理]mv phi/ops/_compat/*.cc files to fluid [cmake治理]mv phi/kernels/ops/_compat/*.cc files to fluid Dec 7, 2023
@risemeup1 risemeup1 changed the title [cmake治理]mv phi/kernels/ops/_compat/*.cc files to fluid [cmake治理]mv phi/kernels/ops/compat/*.cc files to fluid Dec 7, 2023
@risemeup1 risemeup1 changed the title [cmake治理]mv phi/kernels/ops/compat/*.cc files to fluid [Incremental compilation optimization]mv phi/kernels/ops/compat/*.cc files to fluid Dec 7, 2023
@risemeup1 risemeup1 changed the title [Incremental compilation optimization]mv phi/kernels/ops/compat/*.cc files to fluid [compilation optimization]mv phi/kernels/ops/compat/*.cc files to fluid Dec 7, 2023
@risemeup1 risemeup1 changed the title [compilation optimization]mv phi/kernels/ops/compat/*.cc files to fluid [cmake治理] Incremental compilation optimization of phi Dec 8, 2023
zhangbo9674
zhangbo9674 previously approved these changes Dec 8, 2023
Copy link
Contributor

@zhangbo9674 zhangbo9674 left a comment

Choose a reason for hiding this comment

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

LGTM

@risemeup1 risemeup1 changed the title [cmake治理] Incremental compilation optimization of phi Incremental compilation optimization of phi Dec 8, 2023
Copy link
Contributor

@Galaxy1458 Galaxy1458 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -15,8 +15,8 @@ limitations under the License. */
#include <iostream>

#include "gtest/gtest.h"
#include "paddle/fluid/operators/ops_signature/signatures.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

这两个单测要不要也移到fluid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这两个单测要不要也移到fluid

收到

Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

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

Great work! LGTM

Copy link
Contributor

@From00 From00 left a comment

Choose a reason for hiding this comment

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

Great job!

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@risemeup1 risemeup1 merged commit b3d4ce3 into PaddlePaddle:develop Dec 11, 2023
29 checks passed
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.

10 participants