Merged
fix(build_ci): auto-derive job_num from CPU count and cgroup memory #5721
fix(build_ci): auto-derive job_num from CPU count and cgroup memory #5721
Merged
陈晨Add on Aug 27
陈晨
陈晨Collaborators
Aug 27

修复

  1. build_ci默认并发度过高导致高核低内存环境编译OOM
  2. [文档] 编译(pip install .)未说明内存/并行度要求,默认并行在 32Gi 内存仍 OOM(exit 137)
likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 陈晨's contribution.)
陈晨陈晨Collaborators
Aug 27 Created pull request, commit 955fd9c4
atomgit-bot
atomgit-bot
Aug 27 Comments:

变更摘要

本 PR 修复 build_ci 默认构建并发度过高、导致高核低内存环境下编译 OOM(exit 137)的问题。核心是新增公共模块 python/pypto/_job_num.py,提供 get_job_num() 按 CPU 核数与可用内存(含 cgroup 上限)自动推导构建并行度,并将 setup.py、build_ci.py 中原有的仅基于 CPU 核数计算逻辑统一委托到该公共函数;同时补充 PYPTO_BUILD_JOB_NUM 环境变量覆盖机制、更新 -j/--job_num 参数说明,并新增对应单元测试覆盖问题场景。

主要改动

  • 新增公共模块 python/pypto/_job_num.py: get_job_num() 按优先级返回并行度——CLI -j > 环境变量 PYPTO_BUILD_JOB_NUM > 内存感知默认值(取 min(基于CPU, 基于内存, 128),默认按每编译单元约 2 GiB 估算,即 DEFAULT_MEM_PER_JOB_BYTES),Ninja 生成器返回 None 交由 Ninja 自行决定;可用内存优先读取 cgroup v2 memory.max / v1 memory.limit_in_bytes,其次读取 /proc/meminfo。
  • build_ci.py 与 setup.py 委托公共逻辑: BuildParam._get_job_num 与 CMakeBuild._get_job_num 均改为调用 get_job_num();setup.py 移除本地 math/multiprocessing 计算并按路径加载公共模块(同 _which_cmake.py 方式),build_ci.py 在 setup 导入失败时回退到旧的仅按 CPU 核数计算逻辑,并更新 -j/--job_num 帮助文本说明内存感知默认值与 PYPTO_BUILD_JOB_NUM 覆盖行为。
  • 测试框架透传构建并行度: test_case_args_parser.py 新增 -j/--job_num 参数(默认 None 表示使用 build_ci.py 默认),test_case_launcher.py 的 compile_if_need() 在 job_num > 0 时将 -j {job_num} 追加到 build_ci.py 命令。
  • 新增单元测试 python/tests/ut/test_job_num.py: 覆盖 CLI > 环境变量 > 内存感知默认值的优先级链、cgroup v2/v1 读取与无限制哨兵值、无内存信息时回退 CPU 计算、非法环境变量值静默忽略,以及两个 issue 场景(128 核/32 GiB → 16、8 GiB → 4)。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Aug 27 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 27 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 27 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
build_ci.py ✅ 尹杰, DCGDDD (2/2) ✅ 尹杰 (1/1)
cmake ✅ 尹杰, DCGDDD (2/2) ✅ 尹杰 (1/1)
docs ✅ 尹杰, DCGDDD (2/2) ✅ 尹杰 (1/1)
repo-cann/pypto ✅ 尹杰, DCGDDD (2/2) ✅ 尹杰 (1/1)
setup.py ✅ 尹杰, DCGDDD (2/2) ✅ 尹杰 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

chen_chenn, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
98 messages are collapsed here。 See more
杨旭
杨旭Collaborators
Aug 28 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Aug 28 Added label: lgtm
CANN-robotCANN-robotCollaborators
Aug 28 Merged pull request
chengding888chengding888Collaborators
Aug 29 Deleted associated issue: [Bug-Report|缺陷反馈]: build_ci默认并发度过高导致高核低内存环境编译OOM
chengding888chengding888Collaborators
Aug 29 Associated issue: [Roadmap|里程碑]: [文档] 编译(pip install .)未说明内存/并行度要求,默认并行在 32Gi 内存仍 OOM(exit 137)