已开启
feat(examples): 新增 AIN + Blaze AllGatherMatmul 流水示例 #226
feat(examples): 新增 AIN + Blaze AllGatherMatmul 流水示例 #226
已开启
izanaami创建于 12 天前
izanaami
izanaami成员
12 天前

新增 AIN + Blaze AllGatherMatmul 示例:在一个 MIX AIC:AIV=1:1 kernel 内由 AIV 使用 AIN Get 拉取远端 M 分块,AIC 使用 Blaze BlockMmad 计算,实现本地 matmul 与首轮通信、远端 matmul 与后续通信重叠。输出按源 rank 排列,支持 FP16/BF16、ND、M 尾块和改变输入后复用资源。

示例位于 examples/aicore/ain/02_all_gather_matmul,包含外部 ops-tensor/Tensor API 固定版本构建说明、数值校验、AIN 串行和 HCCL cascade 对照、独立通信/计算模式、cycle 诊断和设备回归脚本。接收区使用完整 rank-major GM,ready/free 使用固定双槽通知,所有核均参与消费和归还。

同时修复公共 TCP 控制通道的启动偏斜:消息头和载荷分开发送时,Nagle 与延迟 ACK 导致 barrier 退出偏斜约 41 ms;设置 TCP_NODELAY 后独立 probe 降至 11~47 µs。性能输出增加 Host event 提交偏斜 P95,避免将该偏斜误判为通信开销。

验证:

  • macOS 便携 Host CTest 通过;Linux x86_64 ASC/dav-3510 构建通过。
  • A5_4p 的 0~3 卡互联组上 11/11 回归通过,覆盖 FP16/BF16、尾块、18 轮分块、单核多 peer、延迟 rank、独立通信/计算和 HCCL cascade。
  • 四卡 M=1024、K=4096、N=1024、tileM=256,预热 10 次、测量 100 次。按每轮最大 rank event 耗时统计:
dtype AIN serial median AIN fused median 耗时降低
FP16 408.699 µs 257.151 µs 37.081%
BF16 409.139 µs 257.781 µs 36.994%

独立 cycle 采样确认通信/计算阶段区间重叠,诊断样本未混入性能统计。包目录名为 cann-9.3.0,但 runtime/asc-devkit/hccl/hcomm 安装清单实际标为 9.2.0、20260923_000324205;完整环境、复现命令和验证边界见 VALIDATION.md。

本示例尚未与传统 MC2 融合算子直接对比,也未进行 Get/Put A/B 或 8/16 rank 验证;上述性能结论仅适用于已测 shape。Blaze 外部头文件保留一条 cce_global attribute ignored 编译警告。

likedislike
合并受阻
izanaamiizanaami成员
12 天前 创建了 pull request,commit a9ba1ec5
atomgit-bot
atomgit-bot
12 天前 评论:

变更摘要

本 PR 在 examples/aicore/ain/02_all_gather_matmul 新增 AIN + Blaze AllGatherMatmul 流水示例,在 MIX AIC:AIV=1:1 的 kernel 内由 AIV 通过 AIN Get 拉取远端 M 分块、AIC 使用 Blaze BlockMmad 计算,实现本地 matmul 与首轮通信、远端 matmul 与后续通信的重叠。示例输出按源 rank 排列,支持 FP16/BF16、ND、M 尾块以及改变输入后复用资源,并附带数值校验、AIN 串行与 HCCL cascade 对照、独立通信/计算模式、cycle 诊断与设备回归脚本。同时修复公共 TCP 控制通道的启动偏斜问题。

主要改动

  • 新增融合 kernel 与通信/计算流水: kernel.h 中新增 FusedKernel、GatherKernel、MatmulKernel 与 Gather/Matmul 模板,通过 CrossCoreSetFlag/CrossCoreWaitFlag 的 READY_BASE、FREE_BASE、AIV_BARRIER 固定双槽通知协调 AIV 拉取与 AIC 计算的重叠。
  • 新增分块与参数校验逻辑: tiling.h 定义 Tiling 结构、MakeTiling 与 CheckedProduct,约束 N/K 为 16 的倍数、2<=ranks<=64、MAX_GET_BYTES(256 MiB)Get 上限及 tile-m 对齐规则,所有设备侧偏移使用 uint64_t。
  • 新增主机侧流程与命令行选项: main.asc 提供 Resources 资源管理、RunRank 多模式(fused/serial/hccl/comm/matmul)执行与 PERF 输出;options.h 定义 Options 与 ParseOptions,新增 --mode、--dtype、--tile-m、--cores、--delay-rank/--delay-ms 等配置项。
  • 新增数值参考与测试: reference.h 提供 InputValue/Encode/Decode/Golden 的 FP16/BF16 参考实现;tests/host_tests.cpp 覆盖分块、参数校验与参考一致性;tests/run_device_tests.py 组织多组设备回归用例并保留命令与日志。
  • 修复 TCP 控制通道启动偏斜: examples/aicore/utils/rank_sync.h 在套接字选项中新增 IPPROTO_TCP/TCP_NODELAY,避免 Nagle 与延迟 ACK 导致 barrier 退出偏斜,并在性能输出中新增 Host event 提交偏斜 P95。
likedislike
不准确?
atomgit-bot
atomgit-bot
12 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
12 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
12 天前 评论:

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robot成员
12 天前 评论:

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

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
examples ❌ (0/2)(You can also ask: kong0808, chenma, hyolee, 闫庆尚, 石楠翔) ❌ (0/1)(You can also ask: 闫庆尚, qin437231, chenma, bluesky901, 石楠翔)

💡 Tip:

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

CLA Signature Pass

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

likedislike
izanaamiizanaami成员
9 天前 预合并成功(commit_id: 1d8e0aace70883f03aed142fbf4d9873a727dd98)
izanaamiizanaami成员
9 天前 推送  1 个提交:00f41af2-docs(examples): explain AIN AllGatherMatmul pipeline in Chinese
izanaamiizanaami成员
9 天前 预合并成功(commit_id: 130aae4c267b1799186f526ca5126442becec312)
CANN-robotCANN-robot成员
9 天前 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
9 天前 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
9 天前 添加了label:cann-cla/yes