已合并
fix foreach_addcmul_scalar int32 经 float24 往返丢失低位 #8650
east_yang创建于 12 天前
fix foreach_addcmul_scalar int32 经 float24 往返丢失低位 #8650
已合并
Pull Request已成功合入, 合并人@CANN-robot
(感谢 east_yang 的贡献)atomgit-bot
12 天前 评论:
12 天前 评论:
变更摘要
该 PR 主要修复 foreach_addcmul_scalar 系列算子中 int32 标量经 float 往返导致的大整数低位丢失问题(例如 16777217 被转为 16777216)。核心思路是引入基于模板类型的标量存储萃取 ScalarStorageType 与 ScalarT<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_t和int特化为int32_t存储,其他类型默认使用float。 - 调整通用四元隐式输出模板的标量传递链路:将
OneScalarQuaternaryImplictOutputOp函数指针、InnerComputer::Compute及成员scalarVal的参数类型由float改为ScalarT<T>,并将标量读取改为ScalarT<T>(inScalarGM.GetValue(0))。 - 修复
foreach_addcmul_scalar的 int 适配函数:AddcMulScalarAdapterForInt的scalarValue由const float改为const int32_t,Muls调用移除(int32_t)强转。 - 修复
foreach_addcmul_scalar_list的 int 适配函数:同样将AddcMulScalarListAdapterForInt的scalarValue改为const int32_t并移除Muls中的强转。 - 调整
valueScalar(const int& bVal)的存储方式:在foreach_one_scalar_list_quaternary_implict_output.h中改为按static_cast<int32_t>(bVal)保存到ScalarT<T>,不再转成float。


atomgit-bot
12 天前 评论:
12 天前 评论:
代码审查
审查结论
已逐一审查全部 5 个改动文件:
- activation/selu_grad/examples/test_aclnn_selu_grad.cpp — 仅缩进/括号风格重排与文件末尾补换行,无逻辑改动。无问题。
- foreach/foreach_addcmul_scalar/op_kernel/foreach_addcmul_scalar.cpp —
AddcMulScalarAdapterForInt标量参数由float改为int32_t,Muls直接使用int32_t,修复方向正确;仅存在上述缺测试问题。 - foreach/foreach_addcmul_scalar_list/op_kernel/foreach_addcmul_scalar_list.cpp — 同上的
AddcMulScalarListAdapterForInt改动,与头文件函数指针类型一致。无独立问题(受头文件编译错误影响)。 - foreach/foreach_utils/op_kernel/foreach_one_scalar_list_quaternary_implict_output.h —
scalarValue改为ScalarT<T>、valueScalar(const int&)改为按int32_t存储,逻辑正确。无独立问题。 - foreach/foreach_utils/op_kernel/foreach_one_scalar_quaternary_implict_output.h — 新增
ScalarStorageType/ScalarT萃取及签名改造,存在 P0 编译错误(int32_t与int重复全特化)。
发现数量:P0 × 1,P3 × 1。
总体风险判断:修复思路正确(int32 标量全程按 int32_t 传递,避免 float 往返丢精度,且各调用方适配器签名均已同步),但头文件中的重复模板全特化会直接导致所有包含该头文件的内核编译失败,属于阻断性问题,必须先修复后才能合并。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 0 |
⛔ 需要修改


此处折叠了65条消息 查看更多
liujie12345678
11 天前 评论:
11 天前 评论:
/lgtm
/approve


11 天前 添加了label:lgtm
11 天前 关闭了关联的issue
11 天前 合入了pull request
CANN-robot
11 天前 评论:
11 天前 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
foreach_addcmul_scalar 对 int32 路径经 float 往返导致大于 2^24 的整数低位丢失(16777217→16777216),需要进行修复
关联的Issue
https://gitcode.com/cann/ops-nn/issues/4519
测试
文档更新
类型标签
AI/Agent生成声明