已合并
feat: add SoftMax AscIR operator for V2 (A5/v35) #1222
feat: add SoftMax AscIR operator for V2 (A5/v35) #1222
已合并
WangYanMale创建于 7月7日
WangYanMale成员
7月7日

Pull Request

描述

add SoftMax AscIR operator for V2 (A5/v35)

变更类型

请选择本次引入的变更类型:

关联的Issue

如何测试

前端调用softmax算子,观测性能结果数据,与单算子做比对

核对清单

其他信息

在此添加任何其他关于本次 PR 的说明。

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 WangYanMale 的贡献)
WWangYanMale成员
7月7日 添加了label:enhancement
WWangYanMale成员
7月7日 创建了 pull request,commit 5114695b
atomgit-bot
atomgit-bot
7月7日 评论:

变更摘要

此 PR 为 V2(A5/v35)架构新增了 SoftMax AscIR 算子支持,涵盖算子注册、代码生成、调度优化及 Python 前端接口等多个层面。SoftMax 被归类为 Reduce 类型算子,但其调度行为与通用 Reduce 算子有所区别:在分片(tiling)策略上强制全量加载(AllLoad),且轴分组逻辑采用简化处理(仅取最后一个轴)。

主要改动

  • 算子注册与类型声明:在 att_const_values.h 中新增 kSoftMaxkReduceSoftMax 常量,在 ascir_builtin_ops_v2.cpp 中通过 REG_ASC_IR(SoftMax) 将 SoftMax 注册为 kComputeReduce 类型算子,支持 INT8/UINT8/INT16/INT32/BF16/FLOAT16/FLOAT/FLOAT64 等多种数据类型,并在 v2_ascir_att_impl.hv2_ascir_codegen_impl.h 中分别添加了对应的 Att 实现与 Codegen 实现类声明。

  • 代码生成实现:新增 softmax_api_call.hsoftmax_api_call.cpp,实现 SoftMaxApiCall 类,核心 Generate 方法通过模板化调用 SoftMaxExtend API 生成算子代码,并利用临时缓冲区(tmp_buf)管理中间内存;同时通过静态注册机制 ApiCallRegister<SoftMaxApiCall> 将 "SoftMaxApiCall" 注册到工厂中。

  • 调度策略适配:在 tiling_group.cppGenReduceTilingGroupFullLoad 中,对 SoftMax 做特殊分支处理——直接取 axes.back() 作为分组轴,而非调用通用的 CalcReduceAxes 计算;在 schedule_utils.cppIsReduceArFullLoad 中,SoftMax 节点直接返回 true 强制全量加载。

  • 分片生成器扩展:在 reduce_schedule_case_generator.hReduceType variant 中新增 af::ascir_op::SoftMax 类型;在 reduce_schedule_case_generator.cpp 的 reduce 类型映射表及 ShouldForceAllLoad 方法中添加 SoftMax 支持,当图中存在 SoftMax 节点时强制启用 AllLoad 分片策略。

  • Python 前端接口与参数构建:在 ascir_api.py 中新增 SoftMax() 函数,复用 _common_in_1_out_1_normal_op 创建单输入单输出的 SoftMax 算子节点;在 ascir_param_builder.cppIsReduceParamSupported 中将 "SoftMax" 加入支持的 Reduce 类型集合。

likedislike
不准确?
atomgit-bot
atomgit-bot
7月7日 评论:

代码审查

审查总结

本次审查覆盖了全部 12 个变更文件,逐文件审查结果如下:

文件 审查结论
autofuse/att/base/att_const_values.h 发现 1 个 P3 问题(死代码常量)
autofuse/common/ascir_node_param/ascir_param_builder.cpp 无问题
autofuse/compiler/python/ascir_api.py 无问题
autofuse/optimize/autoschedule/tiling_group.cpp 发现 1 个 P2 问题(空轴边界)
autofuse/optimize/schedule_utils.cpp 无问题
autofuse/optimize/task_generator/reduce_schedule_case_generator.cpp 无问题
autofuse/optimize/task_generator/reduce_schedule_case_generator.h 无问题
autofuse/v35/ascir/generator/ascir_builtin_ops_v2.cpp 无问题
autofuse/v35/ascir/generator/v2_ascir_att_impl.h 无问题
autofuse/v35/ascir/generator/v2_ascir_codegen_impl.h 无问题
autofuse/v35/codegen/reg_api_call/softmax_api_call.cpp 发现 1 个 P3 问题(dump 参数顺序/缺失)
autofuse/v35/codegen/reg_api_call/softmax_api_call.h 无问题

按优先级统计: P0: 0, P1: 0, P2: 1, P3: 2

整体风险评估:本次变更新增 SoftMax AscIR 算子支持,代码结构完整、注册链路清晰。发现的 3 个问题均为次要问题:

  1. P2tiling_group.cpp 中 SoftMax 空轴边界情况静默返回成功(confidence 0.60,因为空轴场景概率较低);
  2. P3softmax_api_call.cpp 中 dump 参数注册顺序错误且缺少临时缓冲区名称;
  3. P3att_const_values.h 中两个常量定义为死代码。

无编译阻断、运行时崩溃、安全漏洞或数据一致性风险。建议在合入前修复 P3 项,对 P2 项添加防御性错误处理。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
不准确?
CANN-robotCANN-robot成员
7月7日 添加了label:cann-cla/yes
此处折叠了181条消息 查看更多
wangxiaotian995成员
7月16日 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
7月16日 添加了label:lgtm
zhanj
zhanj成员
7月16日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
7月16日 添加了label:approved
CANN-robotCANN-robot成员
7月16日 合入了pull request