已合并
perf: softmax_grad算子FMA指令融合优化 #7040
zhuzixian-lr创建于 7月4日
perf: softmax_grad算子FMA指令融合优化 #7040
已合并
Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhuzixian-lr 的贡献)7月4日 创建了 pull request,commit 00aebbcb
7月4日 添加了label:cann-cla/yes
CANN-robot
7月4日 评论:
7月4日 评论:
CANN-robot
7月4日 评论:
7月4日 评论:
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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| ** | ✅ 唐玮玮, gcw_kUomxQ2l (2/2) | ✅ gcw_kUomxQ2l (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


atomgit-bot
7月4日 评论:
7月4日 评论:
变更摘要
此 PR 对 softmax_grad 算子的 Ascend 向量核函数进行了 FMA(融合乘加)指令优化。将原来的 Mul + Sub 双指令模式替换为 Neg + MulAddDst,利用单条 FMA 指令完成"取反乘加"操作,减少指令发射数量,提升计算效率。由于 MulAddDst 指令将结果写入累加寄存器,相关 store/cast 操作的目标寄存器也相应调整为 x1Reg。改动涉及 arch35 架构下的 5 个核函数文件。
主要改动
- FMA 指令融合:在
softmax_grad_ar_full_load.h、softmax_grad_ar_recompute.h、softmax_grad_ar_small_r.h、softmax_grad_ara_full_load.h、softmax_grad_ara_recompute.h五个文件中,将Mul(reg0, reg0, reg2, mask)+Sub(reg1, reg1, reg0, mask)替换为Neg(reg0, reg0, mask)+MulAddDst(reg1, reg0, reg2, mask),用一条 FMA 指令替代原来的乘法与减法两条指令。 - 结果寄存器调整:由于
MulAddDst的语义是将结果累积到reg1,在softmax_grad_ar_small_r.h、softmax_grad_ara_full_load.h、softmax_grad_ara_recompute.h中,后续将结果写回内存(DataCopy/Cast)的源寄存器统一从x0Reg改为x1Reg,确保写入正确的计算结果。 - 统一覆盖各变体核函数:本次优化覆盖了
SoftmaxGradAR(NormComputeSmallR和NormComputePost)、SoftmaxGradArRecompute(CalcOutVF)及对应 ARA 变体中的同类计算路径,保证所有softmax_grad计算路径均受益于 FMA 融合优化。


7月4日 修改了pull request 的描述
zhuzixian-lr
7月4日 评论:
7月4日 评论:
compile


Zzhuzixian-lr
7月4日 update merge request[project id: 7665709, iid: 7040, commit_id: 706532e25aabbdae1da60d8d45fdd3b68215adb4] virtual merging success
7月4日 update merge request[project id: 7665709, iid: 7040, commit_id: 706532e25aabbdae1da60d8d45fdd3b68215adb4] virtual merging success
7月4日 添加了label:ci-pipeline-running
CANN-robot
7月4日 评论:
7月4日 评论:
流水线任务触发成功
任务链接 [a6f533dd555c4df79376568d3b202bb4][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer-chs-nn | ✅ SUCCESS | >>>>> | |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |
[2026-07-04 17:25:37] CI执行结束


CANN-robot
7月4日 评论:
7月4日 评论:
流水线任务触发成功
任务链接 [c08e7b1069d44dccbc1dee45bb26bcd9][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_style | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ⚠️ WARNING | >>>>> | >>>>> |
| SCA | ✅ SUCCESS | >>>>> |
[2026-07-04 17:21:09] CI执行结束


atomgit-bot
7月4日 评论:
7月4日 评论:
7月4日 删除了label:ci-pipeline-running
7月4日 添加了label:ci-pipeline-passed
liulun0308
7月4日 评论:
7月4日 评论:
/approve


7月4日 添加了label:approved
tangweiwei2
7月6日 评论:
7月6日 评论:
/approve
/lgtm


7月6日 添加了label:lgtm
7月6日 合入了pull request
描述
对 softmax_grad 算子的 arch35 实现进行 FMA 指令融合优化,主要改动:
Mul + Sub指令序列替换为Neg + MulAddDst融合指令模式reg1 = x0 * x1; reg0 = x0 * sum; reg1 = reg1 - reg0(Mul + Mul + Sub)reg1 = x0 * x1; Neg(reg0, x0); MulAddDst(reg1, reg0, sum)(Mul + Neg + MulAddDst)reg1/x1Reg,同步更新后续 Store/Cast/DataCopy 操作的源寄存器引用涉及文件:
softmax_grad_ar_full_load.h:AR full load 路径,包含 pMask 和 pFull 两种 mask 场景的 FMA 替换softmax_grad_ar_recompute.h:AR recompute 路径的 FMA 替换和输出寄存器修正softmax_grad_ar_small_r.h:Small R 路径的 FMA 替换,含 fp16/bf16 Cast 输出修正softmax_grad_ara_full_load.h:ARA full load 路径的 FMA 替换,含 fp16/bf16 Cast 输出修正softmax_grad_ara_recompute.h:ARA recompute 路径的 FMA 替换,含 fp16/bf16 Cast 输出修正关联的Issue
测试
通过 ST 测试验证精度和性能
文档更新
无文档更新
类型标签