已关闭
[Bug-Report|缺陷反馈]: build_ci默认并发度过高导致高核低内存环境编译OOM #3042
陈展熹创建于  8月19日关闭于  26 天前
陈展熹
8月19日 创建

Describe the current behavior / 问题描述 (Mandatory / 必填)

build_ci.py 的 BuildParam._get_job_num() 仅根据 multiprocessing.cpu_count() 计算默认编译并发度:

def_job_num = min(int(math.ceil(float(multiprocessing.cpu_count()) * 0.9)), 128)

当前容器可见128个逻辑CPU,因此默认得到 Job Num 116,并生成 cmake --build ... -j 116。该计算未考虑容器cgroup内存上限;当前环境内存上限为32 GiB,大量cc1plus进程并行启动后触发OOM,导致构建失败。

此外,tools/scripts/run_operation_test_with_config.py 通过 TestCaseLauncher.compile_if_need() 调用build_ci.py时未提供并发参数,也未向测试入口暴露job_num,使用该测试入口时会直接采用过高的默认并发度。

Environment / 环境信息 (Mandatory / 必填)

  • 服务器/NPU 型号: Unknown(该问题发生在Host编译阶段)
  • CPU: 128个逻辑CPU
  • cgroup内存上限: 34359738368 bytes(32 GiB)
  • cgroup OOM统计: oom_kill 863,memory.failcnt 250663107
  • PyPTO版本/Commit: 2ba08562c(基于upstream/master 8236a3556)
  • CANN版本: 9.1.0
  • Python版本: Python 3.12.9
  • 操作系统: Ubuntu 24.04.3 LTS

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

  1. 在可见128个逻辑CPU、cgroup内存限制32 GiB的容器中检出PyPTO代码。

  2. 不指定-j参数,通过operation回归入口触发构建:

    python3 tools/scripts/run_operation_test_with_config.py Sign -s 0 -e 0
    
  3. 构建日志显示默认并发度为116:

    Job Num : 116
    cmake --build /workspace/pypto/build -j 116
    
  4. 多个互不相关的C++翻译单元同时被系统终止,构建失败。

Describe the expected behavior / 预期结果 (Mandatory / 必填)

默认并发度应避免只依据CPU数量决定,建议至少满足以下一种方式:

  1. 默认并发上限采用更保守的值,或结合主机/cgroup可用内存估算;
  2. tools/scripts/run_operation_test_with_config.py 支持透传job_num,使用户可通过测试入口指定较小并发度;
  3. 支持明确的环境变量覆盖默认并发度,并在帮助信息中说明。

在上述32 GiB环境中使用-j8或-j16时,应能够避免因并发过高触发OOM。

c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
gmake[2]: *** [framework/src/operator/CMakeFiles/tile_fwk_operator.dir/build.make:160: framework/src/operator/CMakeFiles/tile_fwk_operator.dir/quantize/quant.cpp.o] Error 1
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
gmake[2]: *** [framework/src/codegen/CMakeFiles/tile_fwk_codegen.dir/build.make:188: framework/src/codegen/CMakeFiles/tile_fwk_codegen.dir/npu/codegen_mte_conv.cpp.o] Error 1
gmake: *** [Makefile:136: all] Error 2

同一轮构建中多个无关目标同时出现Killed signal;cgroup记录oom_kill 863,符合并发编译触发内存上限的现象。

Special notes for this issue/备注 (Optional / 选填)

去重检索未发现cann/pypto中已有默认job_num过高或高核低内存环境编译OOM的同类Issue。现有Issue #128是CANN 8.5 include路径缺失导致的编译失败,与本问题不同。

likedislike
袁野袁野成员
8月19日 issue类型由 任务 改变为 缺陷
袁野袁野成员
8月19日 将 chengding888 设为负责人
袁野袁野成员
8月19日 添加了label:bug-report
袁野
袁野成员
8月19日 评论:

感谢反馈
@chengding888 请处理下,谢谢

likedislike
chengding888
chengding888成员
8月19日 评论:

好的

likedislike
陈晨陈晨成员
28 天前 关联了pull request:fix(build_ci): auto-derive job_num from CPU count and cgroup memory
chengding888
chengding888成员
26 天前 评论:

已修复,参考关联PR

likedislike
chengding888chengding888成员
26 天前 issue状态由 待办的 改变为 已完成
chengding888chengding888成员
26 天前 关闭了 issue
chengding888chengding888成员
26 天前 删除了关联的pull request:fix(build_ci): auto-derive job_num from CPU count and cgroup memory