Pull Request已成功合入, 合并人@CANN-robot
(感谢 Davydov_Danil 的贡献)变更摘要
此 PR 将 RFC 0001 中已为 ReduceScatter 引入的 BIRS(批量不变性)算法扩展至 AllReduce,新增名为 AllReduceBIAR 的实验性算法实现。该算法在 A3(SIO + HCCS 混合拓扑)上针对 DEV_TYPE_910_93 设备,采用 ReduceScatter + AllGather 两阶段模式,通过 3 线程并行利用 SIO 和 HCCS 两类链路完成确定性的归约与广播。整体变更通过 ENABLE_EXPERIMENTAL 编译选项控制,新增了完整的 executor 基础框架、BIAR 模板实现、算法选择逻辑及仿真测试用例。
主要改动
-
新增
AllReduceBIARExecutor与AllReduceExecutorBase框架: 在experimental/ops/all_reduce/biar/下新增 executor 基类和 BIAR 专用子类,AllReduceExecutorBase::Orchestrate负责参数还原与多线程编排,AllReduceBIARExecutor::CalcResRequest为单/多服务器 A3 拓扑分别计算资源(level0 NP_MESH + 3 线程),并通过REGISTER_EXEC注册为"AllReduceBIARExecutor"。 -
新增
AllReduceBIAR模板实现: 在experimental/ops/all_reduce/biar/template/all_reduce_biar.cc中实现两阶段通信模板——RunReduceScatter(HCCS 写入 + SIO 带 reduce 写入 + 本地 Tree Reduce)和RunAllGather(HCCS 写入 + SIO 读取 + 本地拷贝),以TEMPLATE_ALL_REDUCE_BIAR(类型值 1005)注册到模板工厂。 -
算法选择与调度入口:
op_common_experimental.cc新增SelectAlgAllReduce函数,对DEV_TYPE_910_93且 rank 数为偶数时选中AllReduceBIARExecutor;all_reduce_op_experimental.cc新增AllReduceExperimental入口,先通过MatchBIRS()判断,命中 BIAR 路径时调用ProcessA3执行。 -
编译控制与集成:
build.sh新增ENABLE_EXPERIMENTAL选项传导至 CMake;src/ops/all_reduce/all_reduce_op.cc在ENABLE_EXPERIMENTAL宏下将HcclAllReduce重定向至AllReduceExperimental;all_reduce_op.h条件包含实验性头文件。 -
仿真测试用例: 添加
test/st/algorithm/testcase/all_reduce_testcase_a3.cc,覆盖 4/6/8/10/12/14/16 卡及 1 超节点×4 服务器×16 卡等多 rank 规模,验证 V-style 分片(含余数)下的归约正确性。


代码审查
审查完成 — 逐文件总结
| # | 文件 | 审查结论 |
|---|---|---|
| 1 | CMakeLists.txt |
无新增问题 |
| 2 | build.sh |
无新增问题 |
| 3 | cmake/device/CMakeLists.txt |
无新增问题 |
| 4 | experimental/ops/CMakeLists.txt |
无新增问题 |
| 5 | experimental/ops/all_reduce/CMakeLists.txt |
无新增问题(新文件,缺文件尾换行) |
| 6 | experimental/ops/all_reduce/all_reduce_op_experimental.cc |
P1: beginTime 未初始化; P3: userRankSize 未使用、重复校验 |
| 7 | experimental/ops/all_reduce/all_reduce_op_experimental.h |
无新增问题(新文件,缺文件尾换行) |
| 8 | experimental/ops/all_reduce/biar/CMakeLists.txt |
无新增问题(新文件) |
| 9 | experimental/ops/all_reduce/biar/all_reduce_biar_executor.cc |
P2: %u/%zu 格式不匹配、dynamic_cast 无 else; P3: 未使用变量、冗余 make_unique |
| 10 | experimental/ops/all_reduce/biar/all_reduce_biar_executor.h |
无新增问题(新文件) |
| 11 | experimental/ops/all_reduce/biar/all_reduce_executor_base.cc |
无新增问题(新文件) |
| 12 | experimental/ops/all_reduce/biar/all_reduce_executor_base.h |
无新增问题(新文件) |
| 13 | experimental/ops/all_reduce/biar/template/CMakeLists.txt |
无新增问题(新文件) |
| 14 | experimental/ops/all_reduce/biar/template/all_reduce_biar.cc |
P2: std::vector<u32> 截断 u64 偏移量; P3: 未使用变量 |
| 15 | experimental/ops/all_reduce/biar/template/all_reduce_biar.h |
P3: #endif 注释粘贴错误、未使用成员 vec |
| 16 | experimental/ops/op_common/op_common_experimental.cc |
无新增问题 |
| 17 | experimental/ops/op_common/template/alg_template_base_experimental.h |
无新增问题 |
| 18 | src/ops/all_reduce/all_reduce_op.cc |
无新增问题 |
| 19 | src/ops/all_reduce/all_reduce_op.h |
无新增问题 |
| 20 | test/st/algorithm/testcase/all_reduce_testcase_a3.cc |
无新增问题(新文件) |
总结
- P1: 1 个 —
AllReduceOutPlaceCustom中beginTime未初始化即按值传递,触发未定义行为。 - P2: 3 个 —
TreeReduceRs中用u32容器存储u64字节偏移导致大消息数据损坏;日志格式%u/%zu不匹配;dynamic_cast失败时静默跳过操作。 - P3: 7 个 — 未使用变量、复制粘贴残留注释、冗余校验/分配等代码清理项。
整体风险评估:中等。P1 的未初始化变量在实际未启用 profiling 时有 UB 风险但概率较低;P2 的 u32 截断问题在大消息(单 slice 超过 ~4 GiB)时会静默数据损坏,是最值得关注的逻辑缺陷。建议在合入前至少修复 P1 和 P2 级别问题。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 4 |
⛔ 需要修改


/ai review force


🤖 AI 代码检视正在进行中,请稍候…


Description
RFC 0001 已为 HcclReduceScatter 引入 BIRS(Batchsize Invariant ReduceScatter)算法:在 A3(SIO + HCCS 混合拓扑)上对大消息相比 RHD 提升带宽利用,并保证确定性规约顺序(bit-identical)。但 RFC 0001 仅覆盖 ReduceScatter,其 Open Question #1 明确声明批次不变 AllReduce 将以独立 PR 提交。
当前 AllReduce 在 A3 仍走 level0 NP_MESH/NHR/NB/Ring 路径,无法同时打满 SIO 与 HCCS 两类链路,且在大消息批量不变场景下缺少对应算法——这与 RFC 0001 §Background 列举的 RLHF/PPO、vLLM 批量不变性、CI 复现等需求存在缺口。
Related Issue
https://gitcode.com/cann/hccl/issues/533
Testing
test/ut/all_reduce_biar/,随bash build.sh --experimental -u运行):biar_selector_test.cc(10 用例):覆盖选路判定——serverNum==0、单机双卡、每 server 3 rank、rankSize==1 等拒绝场景;每 server ≥4 rank 的 910_93 偶数 rank 选中;非 A3 / 奇数 rankSize 不选中。biar_core_test.cc(30 用例):覆盖 PrepareDataSlice 均匀/余数/边界切片、TreeReduceRs 拓扑与规约顺序、HCCS/SIO/LocalCopy 的 RS/AG 环路、Preprocess 校验、RunAsync 端到端序列与失败传播。test/st/algorithm/testcase/all_reduce_testcase_a3.cc,ST 目标all_reduce_a3,随bash build.sh --experimental -s运行):15 个用例在 DEV_TYPE_910_93(A3,SIO+HCCS 混合拓扑)仿真环境验证 AllReduceBIAR:*_rem余数用例;18_min、116_rem_max、1416_max);st_all_reduce_1416_test(1 SuperPod × 4 Server × 16 卡,共 64 rank)。注:上述 UT/ST 均仅在
--experimental(ENABLE_EXPERIMENTAL=ON)构建时编译运行,不影响默认 CI 构建与测试。Documentation Update
Type Label