Merged
feat(apace): AllGather MX QuantMatmul Hcomm通算融合模板 #10588
feat(apace): AllGather MX QuantMatmul Hcomm通算融合模板 #10588
Merged
wangfuhaoAdd on Aug 25
wangfuhao
wangfuhaoCollaborators
Aug 25

描述

新增了 AllGather MX QuantMatmul 的 Hcomm通算融合模板:
新增 all_gather_mx_matmul_hcomm_impl.h(AIC 核内 HCCL AllGather 通信 + 复用 FragmentTensor QBMM kernel 的 CommPolicy 注入式实现,含 bias 可选输入接线与纯尾块 tileCnt=0 跳过守卫)与自有的 all_gather_mx_matmul_tiling_data.h(URMA/Hcomm 两路共用 tiling 结构),将原 urma_tiling_data.h 重命名合并、urma_impl.h 同步适配 11 行;
qbmm_mx_kernel.h 引入 CommPolicy 模板参数、恢复 bias 并同步 master 的 DIMS_NUM clean-code 改造,另将 all_gather_matmul_v3 两个文件的 tiling data include 路径更新为新文件名(urma ST main.cpp 同步);该提交不含 TransB(非转置 B)支持,全部代码位于 namespace Apace

关联的Issue

https://gitcode.com/cann/ops-transformer/issues/5259

测试

文档更新

类型标签

PR #10588 快速检视报告

项目 内容
PR https://gitcode.com/cann/ops-transformer/pull/10588
标题 feat(apace): AllGather MX QuantMatmul Hcomm/CCU 通算融合模板
对应 commit 4e761ac2(已与本地 ops-transformer 仓 commit 逐字节比对,10 文件 +408/-93,index hash 全匹配)
检视日期 2026-09-12
检视方式 ascendc-code-review / quick-review 工作流(假设检验法)+ MC2-17/MC2-18 条例 + 官方 AllGather 文档动态验证(CANN 9.0.0-beta1)
侧别 Kernel + Tiling(MC2/apace hcomm 模板)

总体结论

对现有功能(URMA 路径 / all_gather_matmul_v3)无影响,属增量变更。

SUSPICIOUS(2 项)

[SUSPICIOUS-1] CommPolicy 模板参数无默认值 — 头文件级接口破坏性变更 置信度:MED

问题描述:AllGatherQbmmMxKernel 新增第 4 模板参 CommPolicy 且无默认值(all_gather_qbmm_mx_kernel.h:50 template <typename AType, typename BType, typename CType, typename CommPolicy>)。commit 树内验证:仅 2 处实例化,均已同步更新传参(urma_impl.h:56 传 UrmaCommWaitPolicy、hcomm_impl.h:93 传 HcommCommWaitPolicy<ServerType>),仓内编译安全。但作为公共 kernel 头文件,仓外任何按旧 3 参签名直接实例化该头的代码将编译失败。

证据:规范违反 +40%(无默认值属硬破坏)+ PR 归属 +20% + 上下文防御缺失 +30%(无默认值兜底)= 90%,但考虑 apace 模板头文件当前无仓外消费者证据,降级 MED 人工确认。

建议:确认该头是否对外发布;若仅仓内使用可接受,否则补默认策略或走 deprecated 过渡。

[SUSPICIOUS-2] hcommAllGatherMatmulTilingData.gatherLen 无 host 填充方 置信度:MED

问题描述:kernel 侧依赖 tilingData_->gatherLen(all_gather_mx_matmul_tiling_data.h:57)判断 gather_out 可用性(hcomm_impl.h:199 if (tilingData_->gatherLen == 0 && gatherOut != 0)),但该结构体在本 commit 无任何 host 侧赋值路径(git grep 确认 host tiling 仅填充 URMA 结构体)。当前未接线故无风险,但后续接线时若遗漏 gatherLen 初始化,将依赖未初始化内存做出错误的 buffer 选择。另:tileCnt_==0 && tailCnt_==0 退化场景下 scale handle 已提交(repeat=1)但从不 Wait 即 Finalize(host 正常不应产生该切分,仅记录)。

建议:接线时确保 host 侧初始化 gatherLen(语义对齐 mc2_tiling_struct.h 既有 gatherLen 约定),并在 tiling 生成处约束 commTurn ≥ 1。


PASS(7 项)

条例/检查点 结论
[MC2-17] AllGather API 用法动态验证 PASS。官方文档确认签名 AllGather<commit>(send, recv, sendCount, dataType, strideCount, repeat);commit=true 自动 Commit + 逐轮 Wait 消费,与官方多轮切分示例逐字一致;strideCount/repeat 寻址数学与 FragmentTensor 窗口布局一致(rank 块偏移 i*strideCount,第 t 轮推进 sendCount),Wait 次数与 repeat 配对正确(scale×1 / head×tileCnt / tail×tailCnt)
[MC2-18] HCCL 生命周期配对 PASS(屏障缺失另计 FAIL)。InitV2 → SetCcTilingV2 → AllGather<true> → Wait → Finalize 配对完整;Prepare 类调用 3 次 ≤ 63 上限
[MC2-18] HcclDataType 匹配 PASS。FP8E8M0(scale)与 UINT8(fp4x2 打包)均为仓内已验证用法(allto_all_mx_quant_matmul_arch35.h:59、hccl_a2av_op.h:186);FP8/UINT8 均为 1 字节,count/stride 字节语义自洽
URMA 行为等价 PASS。UrmaCommWaitPolicy::WaitTile 逐字还原原 CrossCoreWaitFlag<0x2, PIPE_MTE2>(idx) 调用序列(含 tileIdx=0 前置等待),既有 URMA 路径时序不变
Tiling 头文件合并 PASS。commit 树内 git grep 确认被删头文件 0 残留引用,4 个消费方全部同步更新;AllGatherMxMatmulUrmaTilingData 字段与对齐(alignas(8)/pack(8))逐字节一致,无 tiling 二进制兼容问题
FP4 dataBytesPerMRow_ 修复 PASS(仅新路径)。fp4x2_e2m1_t 1 字节 2 元素,原 k*sizeof(AType)=K 确为 2× 错位;修复 IsMxFp4 ? k/2 : k*sizeof(AType) 方向正确,与 kForComm_(CeilDiv(K,2))及 URMA 契约一致;FP8 行为不变(k*1==k)
注释类改动 PASS。allto_all_matmul_tiling_key.h 与 all_to_all_mx_quant_matmul_hcomm_impl.h 仅注释修改,无代码语义变化

LOW 备注项(3 项)

  1. commit message 与实际 diff 不符:message 第 6 条(mc2_quant_batch_matmul.h 加 #undef)与第 8 条(CrossCore 模式0 屏障)均不在本 commit diff 及 commit 树内。
  2. 无关文件顺手改动:allto_all_matmul_tiling_key.h 与本特性无关,建议拆分提交。
  3. 新增路径无 ST 覆盖:ST 目录仅有 urma 路径(main.cpp 仅改 include),hcomm 路径无任何测试接线与用例。

汇总

快速检视 — PR #10588 (commit 4e761ac2) | 侧别: Kernel+Tiling(MC2/apace) | 7 PASS / 0 FAIL / 2 SUSPICIOUS / 3 LOW
  • 现有功能影响:无(URMA 路径行为与数据结构保持不变,变更全部通过交叉验证)
likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for wangfuhao's contribution.)
wangfuhaowangfuhaoCollaborators
Aug 25 Created pull request, commit 7e582e92
atomgit-bot
atomgit-bot
Aug 25 Comments:

变更摘要

本 PR 为 apace 的 AllGather + MX QuantMatmul 融合算子新增 Hcomm/CCU「通算融合」模板。核心做法是将通信等待逻辑抽象为 CommPolicy 模板参数注入 AllGatherQbmmMxKernel,并新增基于 hccl_.Wait(handle) 的 HcommCommWaitPolicy(AIC 核内 HCCL AllGather)与基于 CrossCoreWaitFlag 的 UdmaCommWaitPolicy(UDMA/AIV 版本),同时新增 Hcomm 路径专用的 hcommAllGatherMatmulTilingData 结构和 AllGatherMxQuantMatmulHcommImpl 实现模板,计算逻辑复用 AllGatherQbmmMxKernel 保持不变。

主要改动

  • 新增 Hcomm 融合实现模板 all_gather_mx_matmul_hcomm_impl.h: 实现 AllGatherMxQuantMatmulHcommImpl,AIC 核内通过 hccl_.InitV2()/SetCcTilingV2() 批量下发 AllGather<true>(scale、dataHead、dataTail 三段),由 HcommCommWaitPolicy::WaitTile() 按 tile 依次调用 hccl_.Wait(handle),并在 FP4 场景用 CeilDiv(K,2) 计算通信用 K 元素数(kForComm_)。
  • all_gather_qbmm_mx_kernel.h 增加 CommPolicy 模板参数: 将原硬编码的 CrossCoreWaitFlag<0x2, PIPE_MTE2> 等待逻辑替换为 commPolicy_.WaitTile(...) 调用,新增 commPolicy_ 成员与 GetCommPolicy() 接口,命名空间由 Apace 改为 AllGatherQuantMatmulImpl,使同一计算内核可适配 UDMA 与 Hcomm 两种通信路径。
  • all_gather_mx_matmul_udma_impl.h 适配统一策略接口: 新增 UdmaCommWaitPolicy(封装 CrossCoreWaitFlag<0x2, PIPE_MTE2>),UDMA 版本改为实例化 AllGatherQbmmMxKernel<AType, BType, CType, UdmaCommWaitPolicy>,并将头文件引用更新为新的 all_gather_mx_matmul_tiling_data.h。
  • 新增 hcommAllGatherMatmulTilingData 结构: 由 all_gather_mx_matmul_udma_tiling_data.h 重命名为 all_gather_mx_matmul_tiling_data.h,新增 apace 自有的 hcommAllGatherMatmulTilingData(含 mc2InitTiling、mc2CcTiling、commTile、mmTile、gatherLen,其中 gatherLen==0 时通信写入 gatherOut 否则用 workspace),并增加 __CCE_AICORE__ 条件包含保护及 kernel_tiling/kernel_tiling.h 头文件。
  • mc2_quant_batch_matmul.h 宏定义清理: 在重新定义 LOCAL_TEMPLATE_CLASS_PARAMS/LOCAL_TEMPLATE_FUNC_PARAMS 之前增加 #undef 保护,避免重复定义。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 25 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 25 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
mc2 ✅ libohao6, chenjunjian11 (2/2) ✅ libohao6 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Aug 25 Set captainmiaow,monologue815,jiang-lirui,Allan_Yu,wang-minbo,tgwsakiko_,liudan12,chenjunjian11,yangzeheng,liuboxi,luobaiqing,libohao6,mabing1118,macech as approver
165 messages are collapsed here。 See more
chenjianjun11
chenjianjun11Collaborators
Sep 12 Comments:

/lgtm

likedislike
Beau Howard
Beau HowardCollaborators
Sep 12 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 12 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Sep 12 Closed associated issue
CANN-robotCANN-robotCollaborators
Sep 12 Merged pull request