Closed
修复 PyACL get_aipp_data_size 返回值截断 #1203
KaranocaVeAdd on  Oct 21Closed at  24 days ago
KaranocaVe
KaranocaVe
Oct 21 Create

修复 PyACL get_aipp_data_size 返回值截断

aclmdlGetAippDataSize 通过 size_t * 返回所需内存大小。PyACL 包装器 WrapAclMdlGetAippDataSize 使用 Py_BuildValue("Ii", memSize, ret) 将该值返回给 Python;在 64 位 CPython 中,I 按 unsigned int 读取,0x100000060 会变成 0x60。请求大小超过 4 GiB 时,调用方因此会拿到错误的缓冲区长度。
将格式串改为 "ki",使 memSize 在 CANN 的 64 位 Linux 平台上按与 size_t 同宽的 unsigned long 返回,错误码仍按 int 返回。

验证

  • CPython C API 探针确认:64 位 CPython 下,"Ii" 将 0x100000060 返回为 0x60,"ki" 保留完整值。
  • 变更检查通过:补丁仅将尺寸格式符改为 "ki",错误码格式 i 保持。
  • 真实 ACL Runtime API 和 NPU 行为未验证。

关联 PR: https://gitcode.com/cann/runtime/merge_requests/5753

likedislike
KaranocaVeKaranocaVe
Oct 21 Associated pull request
KaranocaVeKaranocaVe
Oct 21 Modify description of issue
KaranocaVeKaranocaVe
Oct 21 Change title to "修复 PyACL get_aipp_data_size 返回值截断", originally titled "PyACL `get_aipp_data_size` 返回值宽度截断".
KaranocaVeKaranocaVe
Oct 21 Modify description of issue
ykl999
ykl999Collaborators
Oct 22 Comments:

你好,PyACL get_aipp_data_size 的相关问题已收到,我们将会尽快check截断问题,检查pr

likedislike
ykl999ykl999Collaborators
Oct 22 Assign ykl999 as responsible person
wuqifan
wuqifan
Oct 22 Comments:

感谢反馈!根据提供的核实情况:acl.mdl.get_aipp_data_size 把 aclmdlGetAippDataSize 写回的内存大小用 "I" 打包返回,64 位 CPython 下该格式项按 unsigned int 读取,超过 4 GiB 的值会丢掉高位,调用方据此申请的缓冲区长度会偏小。该数值应按与 size_t 等宽的整数类型返回,错误码仍按 int 返回。我们正在复现该问题,修复会在通过测试后合入。

likedislike
wuqifan
wuqifan
26 days ago Comments:

感谢反馈,已确认该问题。aclmdlGetAippDataSize 的大小输出为 size_t,而当前 Python 包装使用 Py_BuildValue("Ii", ...);在 64 位 Linux 环境下,返回大小超过 32 位范围时会丢失高位,且错误码可能仍为 0。
关联修复为 MR !5753,将该返回值的格式改为 k。使用 CANN 9.3.0 ,对 MR 父提交和当前 head 分别构建 pyACL 并验证:batch_size=44739242 时,C 接口返回 4294967296 字节,修复前 Python 返回 0,MR 版本返回 4294967296;普通输入 batch_size=1 在两版中均返回 160 字节。我们会尽快推进合入,对pyacl建议补充 4 GiB 边界和普通输入的自动回归测试。本次验证覆盖了接口返回值转换,感谢贡献!

likedislike
wuqifanwuqifan
26 days ago Associated pull request
ykl999
ykl999Collaborators
24 days ago Comments:

pr已合入,issue关闭处理

likedislike
ykl999ykl999Collaborators
24 days ago changed custom state from 进行中 to 已解决
ykl999ykl999Collaborators
24 days ago Close issue
CANN-robotCANN-robotCollaborators
24 days ago Added label: resolved