Pull Request已成功合入, 合并人@CANN-robot
(感谢 luoyufan7 的贡献)变更摘要
该 PR 针对 aclnnLogitGrad 的 kernel 实现文件 loss/logit_grad/op_kernel/logit_grad.h,在 A5(__CCE_AICORE__ == 310)上引入基于 AscendC MicroAPI 的融合计算链:对 FP16 和 BF16 分别新增 ComputeFusedFp16、ComputeFusedBf16 路径,将原有的 ComputeStepOne + ComputeStepTwo 两步计算融合为一次向量计算链,减少 PipeBarrier 与中间数据搬运;FP32 仍保持原有计算路径不变。
主要改动
- 新增 FP16→FP32 的 CastTrait 常量: 在
__CCE_AICORE__ == 310条件下新增G5_FP16_TO_FP32_CAST_TRAIT,为 MicroAPI 的Cast指定寄存器布局、饱和模式、掩码合并模式与舍入模式。 Process()增加按类型分发的融合路径: 对half调用ComputeFusedFp16,对bfloat16_t调用ComputeFusedBf16,其他类型仍走ComputeStepOne+ComputeStepTwo。CopyInAndCast()对half提前返回: 在 310 上跳过原有的x1TensorFp32/x2TensorFp32显式Cast及对应的PipeBarrier<PIPE_V>,改由后续融合计算内完成搬入与类型转换。- 新增
ComputeFusedFp16(): 使用 MicroAPI 的DataCopy(DIST_UNPACK_B16)、Cast、Muls、Adds、Mul、Div、Compare、MaskAnd、Select构建融合链,完成dy / (x * (1 - x))及范围裁剪,并将结果写回x1TensorFp32。 - 新增
ComputeFusedBf16(): 基于已转换为 FP32 的x1TensorFp32/x2TensorFp32数据,使用与 FP16 相同的 MicroAPI 融合计算链,并将结果写回x1TensorFp32。


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
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 |
|---|---|---|
| loss | ✅ 汤平川, 钱泽洪 (2/2) | ✅ 汤平川 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


流水线任务触发成功
任务链接 [291c3dd0783e4bcf930357ca604307a1][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| 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_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
[2026-08-15 15:58:14] CI执行结束


流水线任务触发成功
任务链接 [6298aad84f9847df9c4be6d5e399f578][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_precommit | ❌ FAILED | >>>>> | >>>>> |
| SCA | ✅ SUCCESS | >>>>> |


流水线任务触发成功
任务链接 [f8e32470433c49ca99f1dc9a092db522][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| 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_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_report_lcov | ✅ SUCCESS | >>>>> |
[2026-08-15 16:14:29] CI执行结束


流水线任务触发成功
任务链接 [6c2fe91261c044e9bc478947aef8a5f1][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_precommit | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> |
[2026-08-15 16:00:32] CI执行结束


/lgtm
/approve


/lgtm


950判断用 NPU_ARCH == 3510


使用LoadAlign,DataCopy会逐渐日落


使用StoreAlign


同上


同上


优化内容
对 aclnnLogitGrad 的 kernel 实现(logit_grad.h)进行 A5 MicroAPI 融合优化:
性能数据
测量方法:batch100 event(torch.npu.Event),2100 条全量用例,5 轮 ABBA 交替配对
精度验证
与基线完全一致
改动范围
logit_grad.h
平台兼容性
通过条件编译 #if (CCE_AICORE == 310) 隔离 A5 优化路径,A2/A3 走原始高阶 API 路径,不受影响。