Merged
fix: 补齐3510 C API搬运类型并修正burst参数位宽 #7189
fix: 补齐3510 C API搬运类型并修正burst参数位宽 #7189
Merged
lihuaichaoAdd on 23 days ago
lihuaichao
lihuaichaoCollaborators
23 days ago

描述

修正 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 的合法参数在接口入口被截断。
  • 为 3510 的 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。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for lihuaichao's contribution.)
lihuaichaolihuaichaoCollaborators
23 days ago Created pull request, commit 003e37d7
atomgit-bot
atomgit-bot
23 days ago Comments:

变更摘要

本 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_t GM stride、uint32_t UB 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 架构下并存。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
23 days ago Comments:

代码审查

审查结论

发现清单(按严重度)

级别 位置 问题
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

⛔ 需要修改

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
23 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
23 days ago 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
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 /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
CANN-robotCANN-robotCollaborators
23 days ago updated PR
CANN-robotCANN-robotCollaborators
23 days ago Set bianque,pangfd,Lycheeeee,munanhw,ai_xin,ascendhjh,wuzhaolin as approver
lihuaichao
lihuaichaoCollaborators
23 days ago Comments:

compile

likedislike
lihuaichaolihuaichaoCollaborators
23 days ago Pre merge succeeded (commit_id: 0c28d40d7c25eb7f3dd870438dbc7d5c20f1109d)
CANN-robot
CANN-robotCollaborators
23 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
23 days ago Added label: ci-pipeline-running
lihuaichaolihuaichaoCollaborators
23 days ago Modify description of pull request
atomgit-bot
atomgit-bot23 days agoStart code review1
include/c_api/vector_datamove/vector_datamove.h
@@ -200,2 +202,2 @@
200- __gm__ void* dst, __ubuf__ void* src, uint16_t burst_count, uint16_t burst_len, uint16_t dst_stride,
201- uint16_t src_stride);
202+ __gm__ void* dst, __ubuf__ void* src, uint32_t burst_count, uint32_t burst_len, uint64_t dst_stride,
203+ uint32_t src_stride);
atomgit-bot
atomgit-bot23 days agoComments:

🟠 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)。

失效方式:

  1. 现有 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 描述里已把这一点当作“兼容性取舍”,但对公开头文件而言这是源码级破坏性变更,不是可接受的内部取舍。
  2. 若调用方传入 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 字面量调用的编译验证。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
23 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
23 days ago Added label: ci-pipeline-passed
lihuaichaolihuaichaoCollaborators
23 days ago Resolved final issue
Lycheeeee
LycheeeeeCollaborators
22 days ago Comments:

/lgtm

likedislike
munanhw
munanhwCollaborators
22 days ago Comments:

/approve

likedislike
吴洋
吴洋Collaborators
21 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
21 days ago Added label: lgtm
Lycheeeee
LycheeeeeCollaborators
21 days ago Comments:

/approve

likedislike
wuzhaolin
wuzhaolinCollaborators
21 days ago Comments:

/approve

likedislike
CANN-robot
CANN-robotCollaborators
21 days ago Comments:

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

likedislike
CANN-robotCANN-robotCollaborators
21 days ago Added label: approved
CANN-robotCANN-robotCollaborators
21 days ago Merged pull request