已合并
Log示例改用C++ RAII资源管理,与IsFinite/IsInf示例风格对齐 #4704
sunday创建于 8月14日
Log示例改用C++ RAII资源管理,与IsFinite/IsInf示例风格对齐 #4704
已合并
sunday创建于 8月14日
sunday成员
8月14日

描述

math/log/examples 下的 aclnn 示例由手动资源管理改为 C++ RAII 管理,与同仓 math/is_finitemath/is_inf 示例风格保持一致。

测试

  • bash build.sh --run_example log eager --soc=ascend950:编译通过,在 Ascend950PR 上 test_aclnn_log、test_aclnn_log10、test_aclnn_log2 及对应 inplace 示例均运行成功,输出符合预期(输入 [0,1,…,7] 的 log 结果 -inf、0.000000、0.693147、1.098612、… 正确),示例正常退出。

文档更新

无。

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 sunday 的贡献)
Ssunday成员
8月14日 创建了 pull request,commit 3a5588c2
atomgit-bot
atomgit-bot
8月14日 评论:

变更摘要

本 PR 将 math/log/examples 下的三个 aclnn 示例(test_aclnn_log.cpptest_aclnn_log10.cpptest_aclnn_log2.cpp)由手动资源管理改造为 C++ RAII 资源管理,与同仓 math/is_finitemath/is_inf 示例风格对齐。核心变化是通过 std::unique_ptr 与自定义删除器自动管理 stream、device 内存、tensor 等 ACL 资源,并通过 std::shared_ptr<void> 守卫统一执行 aclrtResetDeviceaclFinalize,同时移除显式的资源释放代码。

主要改动

  • 引入 RAII 类型别名:新增 StreamPtrDeviceMemPtrTensorPtr,分别以 std::unique_ptr 配合 aclrtDestroyStreamaclrtFreeaclDestroyTensor 作为删除器,替代裸指针的声明方式。
  • 改造 Init 初始化接口Init 的 stream 参数由 aclrtStream* 改为 StreamPtr&,并新增 bool& initializedbool& deviceSet 引用参数以跟踪 aclInitaclrtSetDevice 的执行状态。
  • 新增 ACL 生命周期守卫:在 main 中使用 std::shared_ptr<void> aclGuard 与 lambda 删除器,在作用域结束时按状态自动调用 aclrtResetDeviceaclFinalize,替代原先手动的尾部清理。
  • 改造 CreateAclTensor 与算子调用CreateAclTensor 改用 DeviceMemPtr&TensorPtr& 管理地址与 tensor,并对 aclCreateTensor 返回值补充空指针检查;调用 aclnnLog/aclnnLog10/aclnnLog2 及其 workspace 申请时改用智能指针并通过 .get() 传入裸指针。
  • 移除手动释放逻辑:删除原示例中 aclDestroyTensoraclrtFreeaclrtDestroyStreamaclrtResetDeviceaclFinalize 的显式释放代码,资源清理交由 RAII 自动完成。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月14日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
8月14日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
8月14日 评论:

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
math/log 王瑞, andong_hw (2/2) 王瑞 (1/1)

💡 Tip:

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

CLA Signature Pass

zhou-qilong, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robot
CANN-robot成员
8月14日 评论:

CLA Signature Pass

zhou-qilong, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robot成员
8月14日 将FelixTang7,yue-ma,wangrui_,su-yueming,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,zhanw_coding设为评审人
CANN-robotCANN-robot成员
8月14日 将FelixTang7,yue-ma,wangrui_,su-yueming,rxtfeng,loov1,zhangzijie,zl_hw,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,zhanw_coding设为审查人
sunday成员
8月15日 评论:

compile

likedislike
Ssunday成员
8月15日 update merge request[project id: 7649531, iid: 4704, commit_id: 40e915533dee90c051df94b9be262d10a78fb248] virtual merging success
CANN-robotCANN-robot成员
8月15日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
8月15日 评论:

流水线任务触发成功
任务链接 [65d01edd4aa24be6be22f52fbedc4971][流水线指导]

任务名称状态日志下载链接
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_harmony-infer ✅ SUCCESS >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_9030_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
UT_Test_experimental ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-08-15 20:59:24]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
8月15日 评论:

流水线任务触发成功
任务链接 [634d18bf1674454db3e6d0315d65e885][流水线指导]

任务名称状态日志下载链接
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
StaticCheck_codespell ✅ SUCCESS
StaticCheck_link_validity ✅ SUCCESS
StaticCheck_resource_existence ✅ SUCCESS
StaticCheck_tag_closed ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_precommit ✅ SUCCESS >>>>>

[2026-08-15 20:53:56]    CI执行结束

likedislike
CANN-robotCANN-robot成员
8月15日 添加了label:api-check-pass
此处折叠了8条事件消息 查看更多
CANN-robotCANN-robot成员
26 天前 添加了label:cann-cla/yes
sunday成员
26 天前 评论:

compile

likedislike
Ssunday成员
26 天前 update merge request[project id: 7649531, iid: 4704, commit_id: e72506a10cf132c6cc99c453b5579630d86536c0] virtual merging success
CANN-robotCANN-robot成员
26 天前 删除了label:ci-pipeline-passedapi-check-pass
CANN-robotCANN-robot成员
26 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
26 天前 评论:

流水线任务触发成功
任务链接 [2f6c7b881ac64746bf1a1f6b86fc5fbb][流水线指导]

任务名称状态日志下载链接
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_harmony-infer ✅ SUCCESS >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_9030_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
UT_Test_experimental ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-08-19 16:01:13]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
26 天前 评论:

流水线任务触发成功
任务链接 [852a6c26fde943aab0a34af5a5a4ad2e][流水线指导]

任务名称状态日志下载链接
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
StaticCheck_codespell ✅ SUCCESS
StaticCheck_link_validity ✅ SUCCESS
StaticCheck_resource_existence ✅ SUCCESS
StaticCheck_tag_closed ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_precommit ✅ SUCCESS >>>>>

[2026-08-19 15:54:38]    CI执行结束

likedislike
CANN-robotCANN-robot成员
26 天前 添加了label:api-check-pass
CANN-robotCANN-robot成员
26 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
26 天前 添加了label:ci-pipeline-passed
RuiWang_成员
26 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
26 天前 添加了label:approved
andong_hw成员
26 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
26 天前 添加了label:lgtm
CANN-robotCANN-robot成员
26 天前 关闭了关联的issue
CANN-robotCANN-robot成员
26 天前 合入了pull request