已合并
fix(softmax): release resources on init failure #8603
zhang-song-rui创建于 24 天前
fix(softmax): release resources on init failure #8603
已合并
zhang-song-rui创建于 24 天前
已删除 :master合入到cann/ops-nnmaster
zhang-song-rui
zhang-song-rui成员
24 天前

描述

修复 aclnnSoftmax 调用示例在初始化失败场景下资源释放不完整的问题。

  • aclrtSetDevice 失败时,在返回前调用 aclFinalize,释放已初始化的 ACL 资源。
  • aclrtCreateStream 失败时,在返回前依次调用 aclrtResetDeviceaclFinalize,释放已设置的 Device 及 ACL 资源。
  • 保留原有 CHECK_RET 写法和正常执行路径的资源释放顺序。
  • 同步修改文档示例和对应的可执行示例源码,保证两处代码一致。

本次修改参考仓库内同类算子的初始化失败回滚方式,仅补齐资源释放逻辑,不涉及算子 Tiling、Kernel 和计算功能变更。

关联的Issue

Issue #4745

测试

  • git diff --check:通过。
  • GitCode Git Hooks:通过。
  • PR 自动代码审查:未发现问题。
  • 本次仅修改调用示例的异常处理逻辑,未执行 NPU 运行测试。

文档更新

  • 更新 activation/softmax_v2/docs/aclnnSoftmax.md 中的调用示例。
  • 同步更新 activation/softmax_v2/examples/test_aclnn_softmax_v2.cpp

类型标签

AI/Agent生成声明

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhang-song-rui 的贡献)
zhang-song-ruizhang-song-rui成员
24 天前 创建了 pull request,commit 910411b0
atomgit-bot
atomgit-bot
24 天前 评论:

变更摘要

该 PR 修复了 test_aclnn_softmax_v2.cpp 示例中 Init 函数在初始化失败时资源未被正确释放的问题。当 aclrtSetDeviceaclrtCreateStream 调用失败时,原先直接 return 会导致前面步骤已获取的资源(如 ACL 初始化状态、设备上下文)泄漏。本次改动在失败路径上添加了对应的回滚清理操作,确保资源被逐级释放。

主要改动

  • aclrtSetDevice 失败时增加 aclFinalize 调用:在 Init 函数中,当 aclrtSetDevice 失败后,原先仅打印日志并返回错误码;现在改为在返回前调用 aclFinalize(),以释放 aclInit 已获取的资源。
  • aclrtCreateStream 失败时增加设备重置和 ACL 反初始化:当 aclrtCreateStream 失败后,原先仅打印日志并返回错误码;现在改为依次调用 aclrtResetDevice(deviceId)aclFinalize(),回滚之前成功设置的设备和 ACL 初始化状态。
  • 代码格式化调整CHECK_RET 宏调用改为多行格式以容纳新增的回滚逻辑,并在文件末尾补充了缺失的换行符。
likedislike
atomgit-bot
atomgit-bot
24 天前 评论:

代码审查

✅ 未发现问题

likedislike
CANN-robotCANN-robot成员
24 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
24 天前 评论:

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
*/*/docs/acl*.md 陈娇, 汤平川, 刘波 (3/2) 陈娇 (1/1)
activation 黄迪, 刘波, 任如海, 陈昊文, 汤平川, 苏跃明, 查建青 (7/2) 黄迪, 陈昊文, 汤平川, 苏跃明, 查建青 (5/1)

💡 Tip:

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

CLA Signature Pass

zhang-song-rui, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
此处折叠了47条消息 查看更多
CANN-robot
CANN-robot成员
22 天前 评论:

The MR can not be merged, because of CodeReview discussion not resolved

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

likedislike
zhang-song-ruizhang-song-rui成员
22 天前 解决了最后一个问题
zhang-song-ruizhang-song-rui成员
22 天前 解决了最后一个问题
CANN-robotCANN-robot成员
22 天前 合入了pull request
CANN-robot
CANN-robot成员
22 天前 评论:

Pull Request 已合并或已关闭。

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

likedislike