Skip to content

【Hackathon 10th Spring No.52】[WIP][Build] Enable C++20 toolchain baseline - part 4#79260

Open
gouzil wants to merge 7 commits into
PaddlePaddle:developfrom
gouzil:codex/toolchain-cxx20-baseline
Open

【Hackathon 10th Spring No.52】[WIP][Build] Enable C++20 toolchain baseline - part 4#79260
gouzil wants to merge 7 commits into
PaddlePaddle:developfrom
gouzil:codex/toolchain-cxx20-baseline

Conversation

@gouzil

@gouzil gouzil commented Jun 5, 2026

Copy link
Copy Markdown
Member

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 标志。

主要改动

  • 将主 C++、CUDA、CINN 标准入口切到 C++20,并启用 required 约束。
  • 更新工具链 gate,目前要求 GCC >= 11、Clang >= 14、AppleClang >= 14。
  • 更新 Linux CI/Docker baseline:
    • CPU 镜像切到 GCC 13。
    • Coverage 镜像切到 CUDA 12.0 + Ubuntu 22.04 + GCC 12。
    • Build/CE framework 镜像切到 CUDA 12.3 + cuDNN 9 + TensorRT 8 + GCC 12.2。
    • Distribute 镜像路径与 GCC 12.2 名称保持一致。
  • 将 Windows 默认构建工具链从 VS2017 回退路径更新到 VS2019。
  • 增加 patches/threadpool/ThreadPool.h.patch,修复第三方 threadpool 在 C++20 下使用 std::result_of 的问题。
  • 修复本机 C++20 baseline build 暴露的最小源码 hard error,包括:
    • std::result_of -> std::invoke_result_t
    • shared_ptr::unique() -> use_count() == 1
    • std::memory_order_relaxed 写法
    • C++20 下模板重载约束歧义
    • std::accumulate lambda 引用绑定问题:
      • C++20 标准对 std::accumulate 的效果描述为 acc = std::move(acc) + *iacc = 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,所以计算语义不变。
      • 标准依据:C++ working draft [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。
      • 辅助参考:cppreference std::accumulate 对 C++20 std::move(acc) 行为的说明:https://en.cppreference.com/w/cpp/algorithm/accumulate。

未覆盖范围 / 后续工作

  • Linux CPU 和 Linux CUDA baseline 的 configure/min build 仍需在 CI 或 Linux CUDA 容器中验证。
  • Windows configure/build 仍需通过 Windows runner 验证。
  • HIP、XPU、IPU、NPU、DCU、JIT/custom-op/device SDK 的 C++ 标准收敛留给后续变更处理。
  • CUDA 11.x、gcc8.2、部分外部 SDK 路径作为 legacy/exception 保留,不纳入本 PR 的 C++20 baseline。

相关链接

是否引起精度变化

Copilot AI review requested due to automatic review settings June 5, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_of removal) 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_ofinvoke_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) {
Comment thread ci/windows/config_env.bat
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%
PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

@paddle-bot paddle-bot Bot added the contributor External developers label Jun 5, 2026
@PaddlePaddle-bot

PaddlePaddle-bot commented Jun 6, 2026

Copy link
Copy Markdown

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-06-12 23:03:11 UTC+08:00

CI报告基于以下代码生成(30分钟更新一次):
PR commit: 0922b42 | Merge base: 7ef7b9c (branch: develop)


1 Required任务 : 20/40 通过

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
72(0) 72 44 12 0 0 16
任务 错误类型 置信度 日志
Linux-NPU / Test PR问题:外部设备标准未同步 Job
Coverage build 环境问题:Paddle.tar.gz 下载失败 Job
Windows-GPU / Build and test PR问题:Windows C++20 编译错误 Job
Check approval 需要 Approval Job
Windows-Inference / Build and test 未知:分析省略/待后续深挖 Job
Windows-OPENBLAS / Build and test 未知:分析省略/待后续深挖 Job
Coverage build 未知:分析省略/待后续深挖 Job
Distribute-stable-build / Build 未知:分析省略/待后续深挖 Job
Linux-DCU / Build 未知:分析省略/待后续深挖 Job
Linux-XPU / Build 未知:分析省略/待后续深挖 Job
Linux-build / Build 未知:分析省略/待后续深挖 Job
PR-CI-Inference / Build 未知:分析省略/待后续深挖 Job

2 失败详情

🔴 Linux-NPU / Test — PR问题(置信度: 高)

分析器: ci_analyze_paddle
失败用例: NPU custom device 编译

用例 错误摘要
paddle/backends/npu/kernels/clip_kernel.cc 包含 paddle/common/ddim.h 后无法解析 std::invoke_result_t

关键日志:

/usr/local/lib/python3.10/dist-packages/paddle/include/paddle/common/ddim.h:107:8: error: 'invoke_result_t' in namespace 'std' does not name a template type
std::invoke_result_t<Visitor, Dim<0>&> apply_visitor(Visitor&& visitor) {
Make Error Found !!!
Process completed with exit code 7.
  • 根因摘要: NPU 外部设备编译标准未同步
    PR 将 paddle/common/ddim.hstd::result_of 替换为 std::invoke_result_t,但 NPU custom device 编译路径仍使用不支持该别名的旧 C++ 标准或未同步 C++20 baseline。该路径属于 PR 描述中尚未覆盖的外部设备路径,但当前 required CI 已因此阻塞。

修复建议:

  1. 同步 NPU custom device 的编译标准到 C++17/C++20,或在公开安装头文件中保留兼容旧标准的写法,确保外部设备编译参数与新 header 要求一致。

关联变更: paddle/common/ddim.hcmake/flags.cmake

🔴 Coverage build — 环境问题(置信度: 高)

分析器: ci_analyze_paddle
失败用例: 下载构建产物

用例 错误摘要
Download paddle.tar.gz and update test branch wget 下载 BOS 上的 Paddle.tar.gz 退出码 4

关键日志:

wget -q --tries=5 --no-proxy https://paddle-github-action.bj.bcebos.com/PR/h-ci/79260/0922b42ba056211d93b7ad67ce43e35fb85fc12c/Paddle.tar.gz
Downloading Paddle.tar.gz
Process completed with exit code 4.
  • 根因摘要: 构建产物下载网络失败
    该 job 在下载 Paddle.tar.gz 阶段失败,Build 步骤未执行;wget 退出码 4 表示网络失败,日志中没有进入 PR 代码编译或覆盖率检查。

修复建议:

  1. 环境问题,请 rerun。

关联变更: 未关联 PR 源码变更

🔴 Windows-GPU / Build and test — PR问题(置信度: 高)

分析器: ci_analyze_paddle
失败用例: Windows VS2019/C++latest 编译

用例 错误摘要
dynamic_loader.cc, dynamic_shape_infermeta.cc 新 Windows 工具链下出现 const 字符串转换和 operator== 重载歧义

关键日志:

cl.exe ... -std:c++latest ... dynamic_loader.cc
..\paddle\phi\backends\dynload\dynamic_loader.cc(172): error C2440: cannot convert from 'const char [14]' to 'char *const '
..\paddle\fluid\inference\tensorrt\pir\dynamic_shape_infermeta.cc(194): error C2666: '==': 2 overloads have similar conversions
ninja: build stopped: subcommand failed.
  • 根因摘要: Windows C++20 baseline 暴露源码硬错误
    PR 将 Windows 默认工具链切到 VS2019 并将标准推进到 C++20/C++latest,当前 Windows 构建中已有源码不满足更严格的字符串常量 const 规则,并在 PIR/TensorRT 动态 shape 逻辑中触发 nullptr 与 Attribute 相关比较的重载歧义。

修复建议:

  1. 修复 paddle/phi/backends/dynload/dynamic_loader.cc 中对应数组/变量的 const 类型,例如改为 const char *const
  2. 修复 paddle/fluid/inference/tensorrt/pir/dynamic_shape_infermeta.cc 中与 nullptr 比较的 Attribute 判断,改用显式有效性判断或拆分类型,避免 C++20/MSVC 下的重载歧义。

关联变更: ci/windows/config_env.batci/windows/build.batcmake/flags.cmake

🔴 Check approval — 需要 Approval(置信度: 高)

该 Job 需要人工 Approval,完成审批后 CI 才会继续执行。

🔴 其余 8 个失败任务 — 未知(置信度: 低)

受本轮时间与默认深度分析数量限制,以下任务未继续下载单 job 深度日志,标记为分析省略/待后续深挖:

  • Windows-Inference / Build and test
  • Windows-OPENBLAS / Build and test
  • Coverage build(Coverage workflow)
  • Distribute-stable-build / Build
  • Linux-DCU / Build
  • Linux-XPU / Build
  • Linux-build / Build
  • PR-CI-Inference / Build

PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 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.ymltools/dockerfile/ci_dockerfile.sh 或 Dockerfile 变更,描述与代码不一致。

历史 Findings 修复情况

Finding 问题 状态
F1 PATCH_COMMAND 使用 && shell 语法存在可移植性隐患 ⚠️ 仍存在
F2 VS2019 generator 缺少 64 位架构指定 ⚠️ 仍存在
F3 零上下文 patch(--unidiff-zero)的脆弱性 ⚠️ 仍存在
F4 type_util.ccstd::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 保持一致。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants