Pull Request has been successfully merged by CANN-robot.
(Thank you for lihuaichao's contribution.)变更摘要
本 PR 修正了 3510/9201 架构 C API 中 GM↔UB 搬运接口参数位宽不足的问题,并补齐 3510 架构对 fp8_e8m0_t 搬运类型的支持。核心是:在 asc_copy_gm2ub、asc_copy_ub2gm 中,burst_count、burst_len 从 uint16_t 扩宽为 uint32_t,GM 侧 stride 从 uint16_t 扩宽为 uint64_t,UB 侧 stride 从 uint16_t 扩宽为 uint32_t,以免超过 65535 的合法参数在接口入口被截断;同时为 3510 的 asc_copy_gm2ub_align、asc_copy_ub2gm_align 增加 fp8_e8m0_t 的完整参数与简化重载,并同步公共头文件声明。
主要改动
- 搬运接口参数位宽扩宽(3510/9201):
impl/c_api/reg_base_impl/npu_arch_3510/vector_datamove_intf_impl.h与npu_arch_9201下的asc_copy_gm2ub、asc_copy_ub2gm签名改为uint32_t burst_count、uint32_t burst_len、uint64_tGM stride、uint32_tUB stride,使大尺寸参数不再被窄类型截断。 - 补齐 3510 的
fp8_e8m0_t对齐搬运重载: 在 3510 实现中新增asc_copy_gm2ub_align的fp8_e8m0_t完整参数版本(含 padding、常量填充、L2 cache mode、stride)及按size调用的简化版本,内部转调copy_gm_to_ubuf_align_v2。 - 补齐 3510 的
fp8_e8m0_t反向搬运重载: 新增asc_copy_ub2gm_align的fp8_e8m0_t完整参数版本及size简化版本,内部转调copy_ubuf_to_gm_align_v2,与 GM→UB 方向保持对称。 - 公共声明按架构收敛:
include/c_api/vector_datamove/vector_datamove.h中将窄参数的六参数asc_copy_gm2ub/asc_copy_ub2gm声明收进__NPU_ARCH__ == 2201条件编译块,仅宽度参数版本与size版本保持通用可见,并同步为宽参数签名及新增的fp8_e8m0_t声明,避免宽窄声明在非 2201 架构下并存。


代码审查
审查结论
发现清单(按严重度)
| 级别 | 位置 | 问题 |
|---|---|---|
| P1 (0.75) | include/c_api/vector_datamove/vector_datamove.h:198-203 |
2201 架构下 6 参数 asc_copy_gm2ub/asc_copy_ub2gm 同时存在 uint16_t×4(第 80-85 行按 2201 门控保留)与 uint32_t/uint32_t/uint64_t/uint32_t 两套不同签名声明;memory_base_impl(2201 唯一实现)只有窄版本。字面量调用 asc_copy_gm2ub(dst, src, 1, 512, 0, 0) 对两个候选均为 integral conversion,重载决议歧义 → 2201 存量代码编译失败;若传 uint32_t 实参则胜出的宽重载在 2201 无定义 → 链接期 undefined reference。 |
| P3 (0.50) | include/c_api/vector_datamove/vector_datamove.h:259-264 |
新增 fp8_e8m0_t 的 align 声明未在 npu_arch_9201 实现(该段其余所有类型 3510/9201 均有实现),而 9201 在 convert/permute 中已支持 e8m0,用户调用会得到“能编译、不能链接”的隐晦错误,而非清晰的“不支持”诊断。 |
逐文件复核
impl/c_api/reg_base_impl/npu_arch_3510/vector_datamove_intf_impl.h:no issues。burst_count/burst_len/dst_stride扩为uint32_t、GM 侧src_stride扩为uint64_t后,函数体向copy_gm_to_ubuf_align_v2/copy_ubuf_to_gm_align_v2的实参顺序与该文件既有*_align模板完全一致(GM 侧 stride 为 64 位、UB 侧为 32 位,无错位);新增的fp8_e8m0_t两个gm2ub_align(257-272)与两个ub2gm_align(466-480)逐个参数照搬fp8_e5m2_t/fp8_e4m3fn_t既有实现,无重复定义、无越界/未初始化问题,且fp8_e8m0_t在本文件早已使用(第 536 行),类型可用。impl/c_api/reg_base_impl/npu_arch_9201/vector_datamove_intf_impl.h:no issues(仅签名扩宽,两处转发实参位置与该文件既有 8/13 参数*_align实现逐位对应,dst_stride/src_stride未互换)。其“缺 e8m0 实现”的缺口已在公共头文件的 P3 条目中按跨文件不一致上报。include/c_api/vector_datamove/vector_datamove.h:2 个问题(上表)。
总体风险判断
3510/9201 两个 impl 的位宽与类型补齐本身是干净、模式一致的;主要风险集中在公共头文件的兼容性:#if __NPU_ARCH__ == 2201 门控与无条件宽参数声明叠加,使 2201 侧出现不可分辨的重载集合,属于公开接口的源码级破坏性变更,建议合并前必须有 2201 字面量调用的编译验证;另需确认 9201 是否应支持 e8m0 的 GM↔UB 搬运。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 0 |
⛔ 需要修改


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 |
|---|---|---|
| docs | ✅ munanhw, wuyang_hw, Lycheeeee (3/2) | ✅ munanhw (1/1) |
| impl/c_api | ✅ Lycheeeee, wuyang_hw (2/2) | ✅ Lycheeeee (1/1) |
| include/c_api | ✅ wuzhaolin, wuyang_hw, Lycheeeee (3/2) | ✅ wuzhaolin (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
lihuaichao, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


🟠 High Priority
变更点:include/c_api/vector_datamove/vector_datamove.h 第 198-203 行把 6 参数 asc_copy_gm2ub / asc_copy_ub2gm 扩宽为 uint32_t/uint32_t/uint64_t/uint32_t,同时第 80-85 行只为 __NPU_ARCH__ == 2201 保留了 uint16_t ×4 的窄参数声明(该窄声明在改动前与第 197 行那段是同名同型的重复声明,改动后变成两个不同签名的重载)。
影响:impl/c_api/memory_base_impl/vector_datamove_intf_impl.h(2201 的唯一实现,约 101-111 行)只定义了窄参数版本,没有定义宽参数版本。因此 2201 编译单元最终看到两套可见的 6 参数重载:f(uint16_t,uint16_t,uint16_t,uint16_t) 与 f(uint32_t,uint32_t,uint64_t,uint32_t)。
失效方式:
- 现有 2201 用户代码几乎都写成字面量形式
asc_copy_gm2ub(dst, src, 1, 512, 0, 0)。4 个实参均为int,对两个候选都需要 integral conversion(同级 rank,互不优于对方),重载决议无最强者 → clang/gcc 直接报 “call to 'asc_copy_gm2ub' is ambiguous”,2201 侧存量代码编译失败(asc_copy_ub2gm同理)。PR 描述里已把这一点当作“兼容性取舍”,但对公开头文件而言这是源码级破坏性变更,不是可接受的内部取舍。 - 若调用方传入
uint32_t(如asc_copy_gm2ub(dst, src, 1, len /*uint32_t*/, 0, 0)),第 2 参精确匹配使宽重载胜出,而 2201 没有该重载的定义 → 编译/链接期出现 “used but never defined / undefined reference”,比改动前的隐式窄化(能编译通过)是新的硬失败。
建议:让 2201 只能看到一套 6 参数声明:要么把第 198-203 行的宽参数声明用 #if !defined(__NPU_ARCH__) || (__NPU_ARCH__ != 2201) 门控起来,要么在 memory_base_impl 中补上宽参数实现并去掉 2201 的窄声明(需确认 2201 硬件是否支持 >16bit 的 burst/stride)。同时补充一个 2201 字面量调用的编译验证。


/lgtm


/approve


/lgtm
/approve


/approve


/approve


The following users do not have permission to comment /lgtm or /approve on any module in this PR:
/approve: wuyang_hw


描述
修正 3510/9201 架构 C API 的 GM↔UB 搬运参数位宽,并补齐 3510 的 FP8 搬运类型支持。
asc_copy_gm2ub、asc_copy_ub2gm的burst_count、burst_len和 UB stride 从uint16_t扩宽为uint32_t,GM stride 扩宽为uint64_t,避免超过 65535 的合法参数在接口入口被截断。asc_copy_gm2ub_align、asc_copy_ub2gm_align补充fp8_e8m0_t类型的完整参数及简化重载。宽参数接口声明保持 host 侧可见。为此保留的兼容性取舍是:2201 下同时存在窄、宽参数声明,六参数接口使用整数字面量时可能产生重载歧义;2201 调用需使用匹配原接口的
uint16_t参数。关联的Issue
无。
测试
文档更新
更新 3510 的
asc_copy_gm2ub、asc_copy_ub2gm参数类型及取值范围,并在asc_copy_gm2ub_align、asc_copy_ub2gm_align支持类型中增加fp8_e8m0_t。类型标签