Pull Request has been successfully merged by ascend-robot.
(Thank you for wangjian161's contribution.)变更摘要
此 PR 新增了 npu_affinity NPU 亲和调度策略,面向 A5 场景:将 ACL 等关键线程按 cluster 隔离绑定到 NPU 亲和的 NUMA 上,同时将 NPU 进程及其他线程范围绑定到同 NUMA 的剩余 cluster。核心实现为新增的 HbsNpuAffinity 调度器类,通过 npu-smi info -t topo 和 /sys/devices/system/node/ 获取 NPU→NUMA 亲和拓扑,支持 npu_process_out_cluster 布局模式及 cluster 分配降级(亲和 NUMA 无可用 cluster 时回退到同 socket 兄弟 NUMA)。同时扩展了配置、API、调度器工厂和工具函数以支持该策略。
主要改动
- 新增
HbsNpuAffinity调度器:在hbs_npu_affinity.py中实现完整的 NPU 亲和调度逻辑,包括 NPU 拓扑初始化、亲和组约束校验、背景任务 cluster 预留(每 socket 取非 NPU 亲和 NUMA 的 20% cluster)、以及按npu_process_out_cluster布局为高优先级线程分配独占 cluster、为进程/线程分配共享 cluster(含降级策略)。 - 配置与 API 扩展:
AffinityConfig新增layout字段和set_isolate_strategy方法;api.py的set_isolate_strategy接口新增layout参数,支持npu_affinity隔离策略和npu_process_out_cluster布局策略的传递。 - 调度器工厂新增 NPU 亲和决策:
scheduler_factory.py新增decide_on_npu_affinity函数,仅在 A5 设备上返回HBS_NPU_AFFINITY调度器;decide_scheduler中 NPU 亲和策略优先级高于cluster/numa/auto。 - 新增
get_npu_topo_numa_affinity工具函数:在utils.py中通过get_npu_topo_cpu_affinity获取 NPU 亲和 CPU 列表,再结合/sys/devices/system/node/*/cpulist建立 NPU→NUMA 映射,要求每个 NPU 恰好亲和到一个 NUMA。 - 新增单元测试:
test_hbs_npu_affinity.py覆盖配置行为、调度器决策、cluster 降级分配、以及_assign_clusters_cpus_to_tasks和_assign_clusters_for_task_group在降级场景下 task/group 的 NUMA 元数据正确性。


代码审查
我的审查完成。以下是各文件的审查结论汇总:
审查结果汇总
| 优先级 | 数量 |
|---|---|
| P2 | 1 |
| P3 | 2 |
各文件审查结论:
affinity-sched/affinity_sched/api.py— P3:layout默认值使用硬编码字符串,与config.py常量存在分歧风险affinity-sched/affinity_sched/config.py— 无问题affinity-sched/affinity_sched/strategy/__init__.py— 无问题(仅新增 import 和__all__条目)affinity-sched/affinity_sched/strategy/hbs_npu_affinity.py— P3:_get_numa_of_cluster返回 -1 可静默传播到 numa 数组affinity-sched/affinity_sched/strategy/scheduler_factory.py— 无问题affinity-sched/affinity_sched/utils.py— P2:单个 NUMA 节点 cpulist 读取异常被静默吞掉affinity-sched/tests/test_hbs_npu_affinity.py— 无问题
整体风险判断:低。 核心调度逻辑正确,降级策略、NUMA 元数据一致性、约束校验等关键路径均经过仔细测试覆盖。发现的问题均为防御性编程缺口(静默吞异常、哨兵值传播)和可维护性细节(硬编码字符串),不影响正常功能流程。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/msboost | ✅ baij77, xnm-s83u (2/2) | ✅ baij77 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
wangjian161, thanks for your pull request. All authors of the commits have signed the CLA. 👍


The MR can not be merged, because of CodeReview discussion not resolved
If you want to solve this problem, you can click here to do it in the FAQs.


Something went wrong during merge: Only fast-forward merge is allowed for your project. Please update your source branch
If you want to solve this problem, you can click here to do it in the FAQs.


Summary
对于A5场景,每个npu存在对应numa亲和的概念,npu访问亲和numa性能最高,因此需要将与npu绑定的进程调度到npu请和的numa上
Related issue: https://gitcode.com/Ascend/msboost/issues/5
changes
新增npu-affinity隔离策略,将acl等关键线程绑定到npu亲和的numa 。同时支持npu_process_out_cluster 进程/线程布局模式
"npu_process_out_cluster":acl等关键线程按cluster隔离绑定在npu亲核的numa上,npu进程范围绑定在npu亲核的numa中的其它cluster上
Test
Log