Merged
fix(build_ci): auto-derive job_num from CPU count and cgroup memory #5721
陈晨Add on Aug 27
fix(build_ci): auto-derive job_num from CPU count and cgroup memory #5721
Merged
Merged fromchen_chenn/pyptofix_build_ci_job_numintocann/pyptomaster
Pull Request has been successfully merged by CANN-robot.
(Thank you for 陈晨's contribution.)atomgit-bot
Aug 27 Comments:
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 v2memory.max/ v1memory.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)。


Incorrect?
atomgit-bot
Aug 27 Comments:
Aug 27 Comments:
Aug 27 Added label: cann-cla/yes
CANN-robot
Aug 27 Comments:
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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


98 messages are collapsed here。 See more
杨旭
Aug 28 Comments:
Aug 28 Comments:
/lgtm


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