Pull Request已成功合入, 合并人@CANN-robot
(感谢 omarzohir 的贡献)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 |
|---|---|---|
| docs | ✅ shengxinchen, csjlchen (2/2) | ✅ shengxinchen (1/1) |
| repo-cann/pto-isa | ✅ csjlchen, ChanKaLok (2/2) | ✅ ChanKaLok (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
omarzohir, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/compile


变更摘要
此 PR 为 A5 NPU 指令集新增了 TMOV 的 DN→ZZ 数据搬运支持,用于 MX 格式量化管线中处理轴-0 分组(DN)的 E8M0 指数张量到立方 ZZ scale fractal 的转换。核心思路是通过新的模板参数 grp_axis 区分 DN 与 ND 两种分组模式,并实现高效的向量交织(vintlv)搬运路径,避免昂贵的索引 gather 操作。
主要改动
- 新增
grp_axis模板化的TMOV公共入口: 在pto_instr.hpp中新增带int grp_axis非类型模板参数的三参TMOV(dst, src, tmp)重载,grp_axis=0时路由到 DN→ZZ,grp_axis=1(默认)保留原有 ND→ZZ 行为。 - 新增 DN→ZZ 底层实现: 在
TMov.hpp中新增CommonCheckZZ编译期校验、GenerateB8IndicesDN2ZZToUB向量交织搬运函数、以及TMovDnTo2Zz模板函数。DN→ZZ 使用两条 16 字节加载配合vintlv交织指令,每条 ZZ box 仅需一次 32 字节存储,效率高于 ND→ZZ 的步进式 gather。 - 修改
TMOV_IMPL调度逻辑:TMov.hpp中的三参TMOV_IMPL新增grp_axis模板参数,根据其值分发到TMovDnTo2Zz(grp_axis=0)或TMovNdTo2Zz(grp_axis=1)。 - 更新测试管线以覆盖 DN→ZZ: 在
tquant_dn_kernel.cpp中扩充 DN 向量管线,增加E8ZzTile、E8StoreTile等 ZZ 相关 tile 类型与 UB 布局,并调用TMOV<0>(e8ZzTile, e8DnTile, tmpTile)。 - 更新测试框架与 Golden 数据生成:
main.cpp增加对e8_zz输出的设备内存分配、回读与 golden 比对;gen_data.py新增dn2zz_e8m0函数计算 DN→ZZ 的参考输出,并集成到quant_bf16_to_mxfp8_dn与各 golden 生成流程中。


流水线任务触发成功
任务链接 [0b0ef6f41b1b4f05b4177b0432dfa798][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ❌ FAILED | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| Check_Pr | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| pto-isa_check | ❌ FAILED | ||
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| cocheck_codestyle | ✅ SUCCESS | ||
| precommit | ⚠️ WARNING | >>>>> | >>>>> |




代码审查
审查总结
我对所有 7 个变更文件逐一进行了详细审查:
| 文件 | 状态 |
|---|---|
docs/isa/TQUANT_DN.md |
无问题 — 纯文档,无不安全命令或配置。 |
include/pto/common/pto_instr.hpp |
无问题 — 新增的 grp_axis 模板重载与 TMOV_IMPL 调度逻辑一致。 |
include/pto/npu/a5/TMov.hpp |
发现 2 个 P3 问题:static_assert 消息误导 + 注释与代码不一致(PAT_ALL vs PAT_VL16)。DN→ZZ 核心逻辑正确。 |
tests/npu/a5/src/st/CMakeLists.txt |
无问题 — 移除的 --cce-pto-enable 标志在 comm/st/CMakeLists.txt 中已有设置,且测试通过。 |
tests/npu/a5/src/st/testcase/tquant_dn/gen_data.py |
无问题 — ND→NZ、DN→ZZ 的 golden 数据生成逻辑正确,MXFP4 golden 写入签名更新一致。 |
tests/npu/a5/src/st/testcase/tquant_dn/main.cpp |
发现 2 个 P3 问题:bf16 和 fp32 测试函数中各有一对死代码 constexpr 变量。资源分配/释放全部正确配对。 |
tests/npu/a5/src/st/testcase/tquant_dn/tquant_dn_kernel.cpp |
无问题 — 内核逻辑正确,MXFP4 路径消除 CompactFp4PackedRows 改用 TMOV 的简化合理。模板实例化宏重命名一致。 |
发现统计:P0 0 个,P1 0 个,P2 0 个,P3 4 个。
整体风险判断:低风险。所有核心的 DN→ZZ 变换逻辑(数学公式、UB 实现、golden 验证、管道调度)均正确且自洽。发现的 4 个问题均为 P3 清理性/可读性问题(误导的错误消息文本、注释与代码不一致、死代码),不影响功能正确性。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


🟡 Medium Priority
pack_e8_dn 返回 hat_m * padded_cols 元素的数组(包含尾部填充列),但 dn2zz_e8m0(e8_dn, hat_m, n) 按 (hat_m, n) reshape。当 n % 32 != 0 时 padded_cols > n,hat_m * padded_cols ≠ hat_m * n,reshape 会抛出 ValueError。旧代码 e8m0_dn[: hat_m * n].copy() 是安全的。当前所有测试用例的 n 均为 32 的倍数,因此未被触发,但对于非对齐输入会静默崩溃。
建议:在 dn2zz_e8m0 中,应先按 n 截取有效数据再进行 reshape:e8m0_dn = e8m0_dn[:hat_m * n],或者将 padded_cols 传入并在 reshape 中使用 padded_cols 然后切掉尾部填充列。最安全的方式是在函数开头加入 e8m0_dn = e8m0_dn[:hat_m * n].copy() 确保数组大小与 (hat_m, n) 匹配。


/compile


流水线任务触发成功
任务链接 [601aa6189af14cbb97bd9ff8ba62ffb5][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ❌ FAILED | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| Check_Pr | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| pto-isa_check | ✅ SUCCESS | ||
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| cocheck_codestyle | ✅ SUCCESS | ||
| precommit | ⚠️ WARNING | >>>>> | >>>>> |




/compile


流水线任务触发成功
任务链接 [6a3d9aaa82b74417baa0ad00fb3872af][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| Check_Pr | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| pto-isa_check | ✅ SUCCESS | ||
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| cocheck_codestyle | ✅ SUCCESS | ||
| precommit | ⚠️ WARNING | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5 | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | |
| UT_Test | ✅ SUCCESS |
[2026-06-26 19:09:35] CI执行结束




/lgtm


/approve


描述
Adding support for TMOV DN to ZZ
关联的Issue
https://gitcode.com/cann/pto-isa/issues/443
测试
Passes ST testcases
文档更新
类型标签