Pull Request已成功合入, 合并人@CANN-robot
(感谢 Tian_1122 的贡献)变更摘要
本 PR 修复 foreach_add_list(AddListV2)在 int16/int8/uint8 数据类型下的整数溢出语义,将其从原先经 AddListFloatAdapter 的浮点中间态计算改为二进制补码回绕(wrap-around)语义,以对齐 PyTorch CPU/GPU 行为。核心改动是新增内核模板类 ForeachAddListWrap<T>(位于新增文件 foreach_add_list_wrap.h),并在 foreach_add_list.cpp 中将 TILING_KEY_IS(5)、(7)、(8) 三个分支的算子从 ForeachOneScalarTernary 切换为 ForeachAddListWrap。
主要改动
- 新增
ForeachAddListWrap<T>内核类:在foreach_add_list_wrap.h中新增按数据块处理的 int16/int8/uint8 加法内核,包含Init/Process/CopyIn/Compute/CopyOut流水线,双缓冲队列及余量(remainder)数据处理逻辑。 - int16 路径直接计算:
T=int16_t时在 int16 域内直接执行Muls(inLocal2, inLocal2, alphaVal, dataCount)与Add,利用硬件二进制补码回绕语义,无需中间转换。 - int8/uint8 提升计算后掩码回绕:
T=int8_t/uint8_t时先经half提升为 int16 精确计算a + alpha * b,再回绕到低 8 位:uint8_t通过& 0x00FF保留低 8 位,int8_t通过(v & 0x7F) - (v & 0x80)映射到 [-128, 127]。 - 算子入口替换:
foreach_add_list.cpp中TILING_KEY_IS(5)/(7)/(8)分支由ForeachOneScalarTernary<int16_t, float, AddListFloatAdapter<float>>、ForeachOneScalarTernary<int8_t, half, ...>、ForeachOneScalarTernary<uint8_t, half, ...>分别替换为ForeachAddListWrap<int16_t>、ForeachAddListWrap<int8_t>、ForeachAddListWrap<uint8_t>,并新增对foreach_add_list_wrap.h头文件的引用。


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 |
|---|---|---|
| foreach | ✅ 查建青, 唐玮玮, 任如海 (3/2) | ✅ 查建青 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
Tian_1122, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/approve


/approve


描述
本 PR 修复 foreach_add_list(AddListV2)在 int16/int8/uint8 数据类型下的整数溢出语义,将其从原先经 AddListFloatAdapter 的浮点中间态计算改为二进制补码回绕(wrap-around)语义,以对齐 PyTorch CPU/GPU 行为。核心改动是新增内核模板类 ForeachAddListWrap(位于新增文件 foreach_add_list_wrap.h),并在 foreach_add_list.cpp 中将 TILING_KEY_IS(5)、(7)、(8) 三个分支的算子从 ForeachOneScalarTernary 切换为 ForeachAddListWrap。
主要改动
关联的Issue
#5169
测试
文档更新
类型标签
AI/Agent生成声明