【Hackathon 10th Spring No.52】[WIP][Build] Enable C++20 toolchain baseline - part 4#79260
【Hackathon 10th Spring No.52】[WIP][Build] Enable C++20 toolchain baseline - part 4#79260gouzil wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR advances Paddle’s C++20 toolchain baseline by switching the primary CMake/CUDA/CINN build standard to C++20, updating CI/docker toolchains accordingly, and applying a small set of source/third-party compatibility fixes needed for C++20 builds.
Changes:
- Switch core build flags/toolchain gates to C++20 (and require newer GCC/Clang/AppleClang).
- Refresh CI docker images/workflows and Windows default toolchain settings to match the new baseline.
- Fix C++20 incompatibilities (e.g.,
std::result_ofremoval) in both in-tree code and a third-party threadpool patch.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/dockerfile/ci_dockerfile.sh | Update generated CI Dockerfiles (CPU/CUDA baselines, cuDNN/TRT/GCC pins). |
| patches/threadpool/ThreadPool.h.patch | Patch third-party ThreadPool for C++20 (result_of → invoke_result_t). |
| paddle/pir/src/core/type_util.cc | C++20-related lambda signature tweak (also touches shape-compat logic). |
| paddle/pir/include/pass/analysis_manager.h | Add <type_traits> and resolve template overload ambiguities under C++20. |
| paddle/phi/core/memory/allocation/retry_allocator.cc | Fix atomic memory order spelling for C++20 builds. |
| paddle/fluid/framework/new_executor/workqueue/workqueue.h | Replace std::result_of with std::invoke_result_t. |
| paddle/fluid/framework/io/fs.cc | Avoid deprecated shared_ptr::unique() in C++20. |
| paddle/fluid/framework/barrier.h | Replace std::result_of with std::invoke_result_t and add header include. |
| paddle/common/ddim.h | Replace std::result_of with std::invoke_result_t and add header include. |
| cmake/flags.cmake | Enforce C++20 and raise minimum compiler versions. |
| cmake/external/threadpool.cmake | Apply threadpool C++20 patch during external project step. |
| cmake/cuda.cmake | Move CUDA compilation standard to C++20 (required). |
| cmake/cinn.cmake | Update CINN fallback -std message/flags to C++20. |
| ci/windows/config_env.bat | Update default Windows generator to VS2019. |
| ci/windows/build.bat | Update VS vcvars path to VS2019. |
| .github/workflows/Night_ALL_Coverage.yml | Point coverage image build to new Dockerfile name. |
| .github/workflows/docker.yml | Update docker workflow env to new Dockerfile names. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| dims.begin(), dims.end(), dims.front(), [](auto fold, auto dim) { | ||
| return ShapedTypeInterface::IsDynamic(dim) ? fold : dim; | ||
| }); | ||
| return std::all_of(dims.begin(), dims.begin(), [&](auto dim) { |
| if %errorlevel% NEQ 0 exit /b 1 | ||
| if exist .git\index.lock del .git\index.lock 2>NUL | ||
| if not defined GENERATOR echo GENERATOR="Visual Studio 15 2017 Win64">> %GITHUB_ENV% | ||
| if not defined GENERATOR echo GENERATOR="Visual Studio 16 2019">> %GITHUB_ENV% |
CI报告基于以下代码生成(30分钟更新一次): 1 Required任务 : 20/40 通过
2 失败详情🔴 Linux-NPU / Test — PR问题(置信度: 高)分析器: ci_analyze_paddle
关键日志:
修复建议:
关联变更: 🔴 Coverage build — 环境问题(置信度: 高)分析器: ci_analyze_paddle
关键日志:
修复建议:
关联变更: 未关联 PR 源码变更 🔴 Windows-GPU / Build and test — PR问题(置信度: 高)分析器: ci_analyze_paddle
关键日志:
修复建议:
关联变更: 🔴 Check approval — 需要 Approval(置信度: 高)该 Job 需要人工 Approval,完成审批后 CI 才会继续执行。 🔴 其余 8 个失败任务 — 未知(置信度: 低)受本轮时间与默认深度分析数量限制,以下任务未继续下载单 job 深度日志,标记为分析省略/待后续深挖:
|
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-06-08 10:43:26
📋 Review 摘要
PR 概述:将主构建链路推进到 C++20 baseline,并修复一批 C++20 下的源码/third_party 编译问题。
变更范围:cmake/、ci/windows/、patches/、PIR/AP/Framework/Phi 局部 C++ 代码
影响面 Tag:[Environment Adaptation] [Execute Infrastructure] [CINN] [Operator Mechanism]
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | PR 描述 | 当前描述声称更新 Linux CI/Docker baseline,但本次 diff 未包含 .github/workflows/docker.yml、tools/dockerfile/ci_dockerfile.sh 或 Dockerfile 变更,描述与代码不一致。 |
历史 Findings 修复情况
| Finding | 问题 | 状态 |
|---|---|---|
| F1 | PATCH_COMMAND 使用 && shell 语法存在可移植性隐患 |
|
| F2 | VS2019 generator 缺少 64 位架构指定 | |
| F3 | 零上下文 patch(--unidiff-zero)的脆弱性 |
|
| F4 | type_util.cc 中 std::all_of(dims.begin(), dims.begin()) 仍未修复 |
|
| F5 | Windows CUDA flag 与 CMAKE_CUDA_STANDARD 17 仍不一致 |
📝 PR 规范检查
标题格式检查:当前标题为 【Hackathon 10th Spring No.52】[WIP][Build] Enable C++20 toolchain baseline - part 4,包含 Hackathon 前缀和 [WIP] 标记,[Build] 不在官方 Tag 枚举内。
标题建议(可直接复制):
[Environment Adaptation] Enable C++20 toolchain baseline (part 4)
PR 描述建议(点击展开,可直接复制)
### PR Category
Environment Adaptation
### PR Types
Devs
### Description
本 PR 建立 Paddle 的 C++20 工具链基线(第 4 部分),主要改动如下:
- 将主 C++、CUDA(`cmake/cuda.cmake`)、CINN(`cmake/cinn.cmake`)标准入口切换到 C++20,并启用 `CMAKE_CXX_STANDARD_REQUIRED ON`。
- 更新工具链 gate(`cmake/flags.cmake`):GCC >= 12、Clang >= 14、AppleClang >= 14。
- 更新 Linux CI/Docker baseline(`tools/dockerfile/ci_dockerfile.sh`、`.github/workflows/docker.yml`):
- CPU 镜像切到 GCC 13(`Dockerfile.gcc13_ubuntu20_cpu`)。
- Coverage 镜像切到 CUDA 12.0 + Ubuntu 22.04 + GCC 12(`Dockerfile.cuda120_cudnn8_gcc12_ubuntu22_coverage`)。
- Build/CE framework 镜像切到 CUDA 12.3 + cuDNN 9 + TensorRT 8 + GCC 12.2(`Dockerfile.cuda123_cudnn9_gcc122_trt8`)。
- Distribute 镜像路径同步 GCC 12.2 命名。
- 将 Windows 默认构建工具链从 VS2017 更新到 VS2019(`ci/windows/build.bat`、`ci/windows/config_env.bat`)。
- 增加 `patches/threadpool/ThreadPool.h.patch`,修复第三方 threadpool 在 C++20 下 `std::result_of` 问题。
- 修复本机 C++20 baseline build 暴露的最小源码 hard error:
- `std::result_of` → `std::invoke_result_t`(`paddle/common/ddim.h`、`paddle/fluid/framework/barrier.h`、`paddle/fluid/framework/new_executor/workqueue/workqueue.h`)
- `shared_ptr::unique()` → `use_count() == 1`(`paddle/fluid/framework/io/fs.cc`)
- `std::memory_order::memory_order_relaxed` → `std::memory_order_relaxed`(`paddle/phi/core/memory/allocation/retry_allocator.cc`)
- C++20 模板重载约束歧义修复(`paddle/pir/include/pass/analysis_manager.h`)
- `std::accumulate` lambda 引用绑定问题(`paddle/pir/src/core/type_util.cc`)
**未覆盖范围**:HIP、XPU、IPU、NPU、DCU、JIT/custom-op/device SDK 的 C++ 标准收敛留给后续 PR;CUDA 11.x、GCC 8.2、部分外部 SDK 路径作为 legacy/exception 保留。
### 是否引起精度变化
否总体评价
整体改动聚焦 C++20 baseline 编译问题修复,本轮未发现新的阻塞性代码缺陷。合入前建议同步解决历史 build 配置问题,并让 PR 描述与当前 diff 保持一致。
PR Category
Environment Adaptation
PR Types
Devs
Description
本 PR 建立 Paddle 的 C++20 工具链基线,将主 CMake/CUDA/CINN 构建入口切换到 C++20,并同步更新常规 CI 镜像、Windows 默认工具链和本机 baseline build 暴露的最小源码兼容问题。
本 PR 不一次性迁移所有 JIT、custom-op、HIP/XPU/IPU/NPU/DCU 等外部 SDK 或设备路径中的分散
-std=c++17标志。主要改动
patches/threadpool/ThreadPool.h.patch,修复第三方 threadpool 在 C++20 下使用std::result_of的问题。std::result_of->std::invoke_result_tshared_ptr::unique()->use_count() == 1std::memory_order_relaxed写法std::accumulatelambda 引用绑定问题:std::accumulate的效果描述为acc = std::move(acc) + *i或acc = binary_op(std::move(acc), *i),因此 binary op 的第一个参数会收到累加器的右值。[](int64_t& a, int64_t& b)要求第一个参数是非常量左值引用,不能绑定std::move(acc)产生的右值;标准的引用初始化规则也规定,非 const/volatile 左值引用在不能按左值引用规则初始化时是 ill-formed。因此在 GCC 13/libstdc++ + nvcc 路径下会报引用绑定错误。[](int64_t a, int64_t b)只复制两个int64_t标量维度值,不复制 Tensor/vector 数据,也不修改输入元素;该 lambda 原本只做a * b,所以计算语义不变。[accumulate]:https://eel.is/c++draft/algorithms#accumulate-2;C++ working draft[dcl.init.ref]:https://eel.is/c++draft/dcl.init.ref#5.2。std::accumulate对 C++20std::move(acc)行为的说明:https://en.cppreference.com/w/cpp/algorithm/accumulate。未覆盖范围 / 后续工作
相关链接
是否引起精度变化
否