已合并
fix: softmax_grad_ext fusion pass 代码审查修复(memcpy_s 安全函数)、quant_update_scatter 原型重构、leaky_relu mask 调整、tiling 告警消除及 classify_rule 测试分类调整 #9190
fix: softmax_grad_ext fusion pass 代码审查修复(memcpy_s 安全函数)、quant_update_scatter 原型重构、leaky_relu mask 调整、tiling 告警消除及 classify_rule 测试分类调整 #9190
已合并
yuanbin_22创建于 10 天前
yuanbin_22成员
10 天前

描述

本 PR 涵盖 softmax_grad_ext fusion pass 代码审查问题修复、quant_update_scatter 算子原型重构、leaky_relu arch35 内核 mask 计算调整、tiling prepare 函数未使用参数告警消除、以及 classify_rule.yaml 测试分类规则调整。共涉及 6 个文件(+150 -94 行)。

涉及文件

文件 变更类型 +行 -行
activation/softmax_grad_ext/op_graph/fusion_pass/softmax_grad_ext_fusion_pass.cpp 代码修复 +49 -28
classify_rule.yaml 配置调整 +45 -88
index/quant_update_scatter/op_host/quant_update_scatter_def.cpp 重构 +46 -63
quant/dynamic_block_quant/op_host/dynamic_block_quant_tiling.cpp 告警修复 +4 -1
quant/dynamic_mx_quant/op_host/arch35/dynamic_mx_quant_tiling_arch35.cpp 告警修复 +4 -1
activation/leaky_relu/op_kernel/arch35/leaky_relu_dag.h 内核调整 +2 -3

变更内容

1. softmax_grad_ext fusion pass 代码审查修复

  • 严格别名违规修复GetAxisFromReduceSumreinterpret_cast 直接解引用改为 memcpy_s(安全函数)拷贝到本地变量,并使用 OP_LOGE_IF 检查 memcpy_s 返回值是否为 EOK
  • 新增 #include "securec.h":引入 memcpy_s/EOK 定义
  • 格式符修复axis_valueint64_t)的格式符从 %ld 改为 %lld
  • 返回值校验AddEdgeAndUpdatePeerDesc 调用使用 ES_ASSERT_GRAPH_SUCCESS 宏包装
  • 魔法数字消除:新增 9 个命名常量替换硬编码值(kUnknownShapeDimkReduceLastAxiskAxesShapeDimkPatternV2VariantCountkBinaryInputX1IdxkBinaryInputX2IdxkReduceSumInputXIdxkNodeOutputIdxkTargetSocVersion
  • 日志增强:平台不支持日志中的 Ascend950 改为引用 kTargetSocVersion 常量

2. quant_update_scatter 算子原型重构

QuantUpdateScatter 类中各输入/输出的内联 DataType/Format/UnknownShapeFormat 向量提取为文件级 static const 命名向量(varDataTypeindicesDataTypeupdatesDataTypequantScalesDataTypequantZeroPointsDataTypeinputAndOutputFormat),消除重复代码,提升可维护性。

3. leaky_relu arch35 内核 mask 计算调整

  • 移除局部 constexpr uint64_t VECTOR_REG_WIDTH = 256UL(使用全局定义)
  • Reg::UpdateMask 从循环外移入循环内,确保每次迭代 mask 与实际剩余元素匹配,避免最后一次循环处理越界

4. tiling prepare 函数未使用参数告警消除

dynamic_block_quantdynamic_mx_quantTilingPrepare 函数中 context 参数未使用,添加 [[maybe_unused]] 属性消除编译告警,并格式化函数体。

5. classify_rule.yaml 测试分类调整

将以下算子的测试代码从 activation-c@ops-nn(已发布分类)移至 VC1@ops-nn(未发布分类),并取消原 VC1 中的注释标记:

  • eluelu_grad_v2fast_gelufast_gelu_grad
  • ge_glu_grad_v2ge_glu_v2gelugelu_gradgelu_grad_v2gelu_quantgelu_v2
  • hardtanh_gradleaky_reluleaky_relu_gradp_relurelurelu_grad
  • sigmoidsigmoid_gradsilu_gradswi_glu_gradswishswish_grad
  • ascend_quant

关联的Issue

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

测试

  • softmax_grad_ext fusion pass 功能验证通过
  • quant_update_scatter 算子原型注册行为不受影响
  • leaky_relu FP16/BF16/FP32 各 dtype 功能验证通过
  • tiling 函数编译无新增告警
  • classify_rule 分类调整后 CI 流水线通过(ci-pipeline-passed)

文档更新

不涉及

类型标签

AI/Agent生成声明

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

变更摘要

本 PR 针对 activation/softmax_grad_ext/op_graph/fusion_pass/softmax_grad_ext_fusion_pass.cpp 中的 SoftmaxGradExt 融合算子图构建逻辑进行修复与加固(PR 标题提及的"补充文件末尾换行符"对应其余文件的改动)。核心内容包括:用 memcpy 替代 reinterpret_cast 安全读取 ReduceSum 的 axes 数据,修正日志格式符以匹配 int64_t 类型,为建图阶段 es::AddEdgeAndUpdatePeerDesc 调用补充 ES_ASSERT_GRAPH_SUCCESS 返回值检查,并将魔法数字 3UL 抽取为具名常量 kMinSubgraphInputCount 用于子图输入数量校验。

主要改动

  • 安全读取 axes 数据: 在 GetAxisFromReduceSum 中,将原先通过 reinterpret_cast 解引用读取 DT_INT64/DT_INT32 数据的方式改为先经 memcpy 拷贝到局部变量再赋值给 axis_value,规避潜在的对齐/严格别名问题。
  • 修正日志格式符: 将 ReduceSum axis 的日志格式从 %ld 调整为 %lld,与 int64_t 类型的 axis_value 保持一致。
  • 建图调用增加返回值检查: 在 BuildBinaryNodeBuildPatternReduceSum 中,用 ES_ASSERT_GRAPH_SUCCESS 包装 es::AddEdgeAndUpdatePeerDesc 调用,对建边失败进行显式断言处理。
  • 抽取输入数量常量: 新增常量 kMinSubgraphInputCount = 3UL,替换 SoftmaxGradExtReplacementCommon 中校验子图输入数量的魔法数字 3UL,使校验逻辑更清晰可维护。
likedislike
atomgit-bot
atomgit-bot
10 天前 评论:

代码审查

✅ 未发现问题

likedislike
CANN-robotCANN-robot成员
10 天前 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
10 天前 添加了label:cann-cla/yes
此处折叠了115条消息 查看更多
范其瑞
范其瑞成员
4 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
4 天前 添加了label:lgtm
tang-lei01成员
4 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
4 天前 添加了label:approved
CANN-robotCANN-robot成员
4 天前 合入了pull request