已合并
解决foreach_exp/foreach_expm1/foreach_round_off_number/foreach_sub_list算子已知问题 #10178
surezz创建于 18 天前
解决foreach_exp/foreach_expm1/foreach_round_off_number/foreach_sub_list算子已知问题 #10178
已合并
surezz创建于 18 天前
surezz
surezz成员
18 天前

描述

解决foreach_exp/foreach_expm1/foreach_round_off_number/foreach_sub_list算子已知问题,核心改动是为这些算子补齐整型数据类型支持(int16/int8/uint8,其中 foreach_round_off_number 为 int16)

关联的Issue

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

测试

david冒烟、二级冒烟、新增四个算子(int16/int8/uint8)用例共100条,加上原用例200条,无功能回退,精度通过

文档更新

类型标签

AI/Agent生成声明

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 surezz 的贡献)
surezzsurezz成员
18 天前 创建了 pull request,commit f9c20128
atomgit-bot
atomgit-bot
18 天前 评论:

变更摘要

该 PR 主要解决 foreach_exp、foreach_expm1、foreach_round_off_number、foreach_sub_list 四个算子(arch35/ascend950 平台)的已知问题,核心是为这些算子新增整型数据类型(DT_INT16、DT_INT8、DT_UINT8)支持:扩展 tiling key 枚举与宏定义、在 binary 配置 JSON 中补充对应算子二进制配置、更新算子 dtype 列表,并在 SIMT kernel 侧为整型结果增加"四舍五入到最近偶数 + 饱和截断"的浮点转整型逻辑;其中 foreach_sub_list 还重构了 Process 模板以区分数据类型与 alpha 标量类型,并新增输入兼容性校验及对应单测。

主要改动

  • 整型数据类型支持扩展:在 foreach_exp、foreach_expm1、foreach_sub_list 的 tiling 函数与 kernel 分派逻辑中新增 DT_INT16/DT_INT8/DT_UINT8 分支,同步扩展 foreach_*_tiling_key.h 中的调度模式宏与枚举,并在各自的 ascend950 binary JSON 配置中新增整型输入/输出的算子二进制条目(foreach_round_off_number 仅新增 DT_INT16)。
  • 算子 dtype 列表更新:在 foreach_exp_def.cpp、foreach_expm1_def.cpp、foreach_round_off_number_def.cpp、foreach_sub_list_def.cpp 中将整型数据类型加入 tensor_dtype_list_950,使这些算子支持整型 dtype 的注册与编译;foreach_round_off_number 同时在其 proto(foreach_round_off_number_proto.h)的 x/y 的 TensorType 中增加 DT_INT16。
  • 整型 SIMT 转换逻辑:foreach_exp 的 CastFromFloat 与 foreach_expm1 新增的 SaturatingCastFromFloat 实现统一的浮点转整型处理:先 rintf 四舍五入到最近偶数,NaN 归零,并对 int8_t/uint8_t/int16_t 分别做上下界饱和截断,保证整型结果与 arch22 CAST_RINT 语义一致。
  • foreach_sub_list 模板与校验重构:kernel 的 Process 由单模板参数改为 Process<T, AlphaT> 双参数,整型输入时 alpha 使用 int32_t、bf16 输入时使用 float;tiling 侧新增 GetExpectedAlphaDtype 与 CheckInputCompatibility,校验 x1/x2 张量数量、dtype 与存储形状一致,以及 alpha 的 dtype(整型输入须为 int32)和单元素形状。
  • 新增单测用例:test_foreach_sub_list_tiling.cpp 增加 ExpectTilingResult 辅助函数及用例,覆盖 INT16/INT8/UINT8 的 tiling key 生成,并验证 x1/x2 dtype 不匹配及非法 alpha dtype 时返回 GRAPH_FAILED。
likedislike
不准确?
atomgit-bot
atomgit-bot
18 天前 评论:

代码审查

审查结论

发现汇总(共 3 项)

  • P1 × 2
    1. foreach_round_off_number 内核缺少 TILING_KEY_INT16 分派分支(foreach_round_off_number.cpp:28-44):tiling/proto/def/json 已全面放开 int16,但内核 if constexpr 链在 schMode==3 时全部分支为假,内核空转、y 从不写入,int16 输入得到未初始化输出(静默错误结果)。
    2. foreach_sub_list 的 AlphaT 模板参数是死参数(foreach_sub_list_simt.h:69-80):VF 内核 OpForeachSubListSimt<T> 仍按 T 读取 alpha。INT16/INT8/UINT8 路径把 int32 alpha 按 int16/int8/uint8 读取、BF16 路径把强制 float32 的 alpha 按 bf16 读取(小端取到的是尾数低位),新整数路径计算结果错误。
  • P2 × 1
    3. foreach_round_off_number_binary.json:128 新增 int16 条目的 bin_filename 用 ForeachRoundOffNumber_Int16 手工命名,与同文件其余条目及同 PR 其他三个 binary.json 的哈希命名不一致,可能导致运行时内核二进制查找失败(置信度较低,需与构建流程确认)。

总体风险判断

本 PR 为 4 个 foreach 算子新增整型 dtype 支持(ascend950),tiling key 枚举均为追加、host 侧 dtype→key 映射与 def/json 配置整体自洽;但两个算子的内核侧实现与 host 侧契约脱节:round_off_number 的内核分派遗漏、sub_list 的 alpha 类型未生效,均会直接导致新支持路径输出错误,且新增单测只覆盖 host tiling 逻辑、无法捕获这两处内核缺陷。建议合入前修复上述两处 P1 问题并补充内核级数值测试。

逐文件复核清单

  • foreach/foreach_exp/op_host/arch35/foreach_exp_tiling.cpp —— no issues(dtype→key 映射与枚举一致)
  • foreach/foreach_exp/op_host/config/ascend950/foreach_exp_binary.json —— no issues(与 def/kernel 一致,哈希命名)
  • foreach/foreach_exp/op_host/foreach_exp_def.cpp —— no issues(ascend950 dtype 列表扩展自洽)
  • foreach/foreach_exp/op_kernel/arch35/foreach_exp.cpp —— no issues(6 个 key 全部分派)
  • foreach/foreach_exp/op_kernel/arch35/foreach_exp_simt.h —— no issues(饱和舍入转换边界值已核查:NaN/±inf/半程偶数舍入均正确)
  • foreach/foreach_exp/op_kernel/arch35/foreach_exp_tiling_key.h —— no issues(追加式新增,未改历史顺序)
  • foreach/foreach_expm1/op_host/arch35/foreach_expm1_tiling_arch35.cpp —— no issues
  • foreach/foreach_expm1/op_host/config/ascend950/foreach_expm1_binary.json —— no issues
  • foreach/foreach_expm1/op_host/foreach_expm1_def.cpp —— no issues
  • foreach/foreach_expm1/op_kernel/arch35/foreach_expm1.cpp —— no issues(6 个 key 全部分派)
  • foreach/foreach_expm1/op_kernel/arch35/foreach_expm1_simt.h —— no issues(SaturatingCastFromFloat 与 exp 路径一致)
  • foreach/foreach_expm1/op_kernel/arch35/foreach_expm1_tiling_key.h —— no issues
  • foreach/foreach_round_off_number/op_graph/foreach_round_off_number_proto.h —— no issues(int16 加入 TensorType)
  • foreach/foreach_round_off_number/op_host/arch35/foreach_round_off_number_tiling.cpp —— no issues(INT16→key 3 映射正确)
  • foreach/foreach_round_off_number/op_host/config/ascend950/foreach_round_off_number_binary.json —— 问题(P2,bin_filename 命名)
  • foreach/foreach_round_off_number/op_host/foreach_round_off_number_def.cpp —— no issues
  • foreach/foreach_round_off_number/op_kernel/arch35/foreach_round_off_number.cpp —— 问题(P1,INT16 分派缺失)
  • foreach/foreach_round_off_number/op_kernel/arch35/foreach_round_off_number_tiling_key.h —— no issues
  • foreach/foreach_sub_list/op_host/arch35/foreach_sub_list_tiling_arch35.cpp —— no issues(CheckInputCompatibility/GetExpectedAlphaDtype 与 def、json、单测一致;alpha 契约收紧属有意变更且有单测)
  • foreach/foreach_sub_list/op_host/config/ascend950/foreach_sub_list_binary.json —— no issues(alpha int32/float32 与 tiling 规则一致)
  • foreach/foreach_sub_list/op_host/foreach_sub_list_def.cpp —— no issues
  • foreach/foreach_sub_list/op_kernel/arch35/foreach_sub_list.cpp —— 分派与 simt.h 的问题同根因(见 P1 第 2 项,锚定在 simt.h)
  • foreach/foreach_sub_list/op_kernel/arch35/foreach_sub_list_simt.h —— 问题(P1,AlphaT 未生效)
  • foreach/foreach_sub_list/op_kernel/arch35/foreach_sub_list_tiling_key.h —— no issues
  • foreach/foreach_sub_list/tests/ut/op_host/arch35/test_foreach_sub_list_tiling.cpp —— no issues(host tiling 单测有效,但无法覆盖上述内核缺陷,已并入对应 finding 的建议)
类型 数量
🔴 阻塞 2
🟡 建议 0

⛔ 需要修改

likedislike
不准确?
CANN-robotCANN-robot成员
18 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
18 天前 评论:

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
*/*/README.md ✅ 陈娇, 陈展熹 (2/2) ✅ 陈娇 (1/1)
*/*/op_host/*_def.cpp ✅ 王永光, 陈展熹 (2/2) ✅ 王永光 (1/1)
foreach ✅ 上官秦南, 陈展熹 (2/2) ✅ 上官秦南 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

surezz, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
此处折叠了136条消息 查看更多
CANN-robotCANN-robot成员
13 天前 添加了label:approved
陈展熹成员
13 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
13 天前 添加了label:lgtm
CANN-robotCANN-robot成员
13 天前 合入了pull request
CANN-robot
CANN-robot成员
13 天前 评论:

Pull Request 已合并或已关闭。

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

likedislike