已合并
fix foreach_addcmul_scalar int32 经 float24 往返丢失低位 #8650
east_yang创建于 12 天前
fix foreach_addcmul_scalar int32 经 float24 往返丢失低位 #8650
已合并
east_yang创建于 12 天前
east_yang成员
12 天前

描述

foreach_addcmul_scalar 对 int32 路径经 float 往返导致大于 2^24 的整数低位丢失(16777217→16777216),需要进行修复

关联的Issue

https://gitcode.com/cann/ops-nn/issues/4519

测试

文档更新

类型标签

AI/Agent生成声明

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 east_yang 的贡献)
Eeast_yang成员
12 天前 创建了 pull request,commit be5afd98
Eeast_yang成员
12 天前 关联了issue:[Bug] foreach_addcmul_scalar int32 经 float24 往返丢失低位(16777217→16777216)
atomgit-bot
atomgit-bot
12 天前 评论:

变更摘要

该 PR 主要修复 foreach_addcmul_scalar 系列算子中 int32 标量经 float 往返导致的大整数低位丢失问题(例如 16777217 被转为 16777216)。核心思路是引入基于模板类型的标量存储萃取 ScalarStorageTypeScalarT<T>,使 int32_t/int 标量按原始 int32_t 保存,而 half/bfloat16_t/float 仍以 float 保存,从而避免 int32 路径经 float() 强转造成精度损失,并相应调整相关 kernel 函数的参数类型。

主要改动

  • 新增标量类型萃取 ScalarStorageType 与别名 ScalarT<T>:在 foreach_one_scalar_quaternary_implict_output.h 中对 int32_tint 特化为 int32_t 存储,其他类型默认使用 float
  • 调整通用四元隐式输出模板的标量传递链路:将 OneScalarQuaternaryImplictOutputOp 函数指针、InnerComputer::Compute 及成员 scalarVal 的参数类型由 float 改为 ScalarT<T>,并将标量读取改为 ScalarT<T>(inScalarGM.GetValue(0))
  • 修复 foreach_addcmul_scalar 的 int 适配函数AddcMulScalarAdapterForIntscalarValueconst float 改为 const int32_tMuls 调用移除 (int32_t) 强转。
  • 修复 foreach_addcmul_scalar_list 的 int 适配函数:同样将 AddcMulScalarListAdapterForIntscalarValue 改为 const int32_t 并移除 Muls 中的强转。
  • 调整 valueScalar(const int& bVal) 的存储方式:在 foreach_one_scalar_list_quaternary_implict_output.h 中改为按 static_cast<int32_t>(bVal) 保存到 ScalarT<T>,不再转成 float
likedislike
atomgit-bot
atomgit-bot
12 天前 评论:

代码审查

审查结论

已逐一审查全部 5 个改动文件:

  1. activation/selu_grad/examples/test_aclnn_selu_grad.cpp — 仅缩进/括号风格重排与文件末尾补换行,无逻辑改动。无问题
  2. foreach/foreach_addcmul_scalar/op_kernel/foreach_addcmul_scalar.cppAddcMulScalarAdapterForInt 标量参数由 float 改为 int32_tMuls 直接使用 int32_t,修复方向正确;仅存在上述缺测试问题。
  3. foreach/foreach_addcmul_scalar_list/op_kernel/foreach_addcmul_scalar_list.cpp — 同上的 AddcMulScalarListAdapterForInt 改动,与头文件函数指针类型一致。无独立问题(受头文件编译错误影响)。
  4. foreach/foreach_utils/op_kernel/foreach_one_scalar_list_quaternary_implict_output.hscalarValue 改为 ScalarT<T>valueScalar(const int&) 改为按 int32_t 存储,逻辑正确。无独立问题
  5. foreach/foreach_utils/op_kernel/foreach_one_scalar_quaternary_implict_output.h — 新增 ScalarStorageType/ScalarT 萃取及签名改造,存在 P0 编译错误int32_tint 重复全特化)。

发现数量:P0 × 1,P3 × 1。

总体风险判断:修复思路正确(int32 标量全程按 int32_t 传递,避免 float 往返丢精度,且各调用方适配器签名均已同步),但头文件中的重复模板全特化会直接导致所有包含该头文件的内核编译失败,属于阻断性问题,必须先修复后才能合并。

类型 数量
🔴 阻塞 1
🟡 建议 0

⛔ 需要修改

likedislike
Eeast_yang成员
12 天前 修改了pull request 的描述
此处折叠了65条消息 查看更多
liujie12345678成员
11 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
11 天前 添加了label:lgtm
CANN-robotCANN-robot成员
11 天前 关闭了关联的issue
CANN-robotCANN-robot成员
11 天前 合入了pull request
CANN-robot
CANN-robot成员
11 天前 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike