Pull Request已成功合入, 合并人@CANN-robot
(感谢 sunday 的贡献)变更摘要
本 PR 将 math/log/examples 下的三个 aclnn 示例(test_aclnn_log.cpp、test_aclnn_log10.cpp、test_aclnn_log2.cpp)由手动资源管理改造为 C++ RAII 资源管理,与同仓 math/is_finite、math/is_inf 示例风格对齐。核心变化是通过 std::unique_ptr 与自定义删除器自动管理 stream、device 内存、tensor 等 ACL 资源,并通过 std::shared_ptr<void> 守卫统一执行 aclrtResetDevice 与 aclFinalize,同时移除显式的资源释放代码。
主要改动
- 引入 RAII 类型别名:新增
StreamPtr、DeviceMemPtr、TensorPtr,分别以std::unique_ptr配合aclrtDestroyStream、aclrtFree、aclDestroyTensor作为删除器,替代裸指针的声明方式。 - 改造
Init初始化接口:Init的 stream 参数由aclrtStream*改为StreamPtr&,并新增bool& initialized、bool& deviceSet引用参数以跟踪aclInit和aclrtSetDevice的执行状态。 - 新增 ACL 生命周期守卫:在
main中使用std::shared_ptr<void> aclGuard与 lambda 删除器,在作用域结束时按状态自动调用aclrtResetDevice和aclFinalize,替代原先手动的尾部清理。 - 改造
CreateAclTensor与算子调用:CreateAclTensor改用DeviceMemPtr&、TensorPtr&管理地址与 tensor,并对aclCreateTensor返回值补充空指针检查;调用aclnnLog/aclnnLog10/aclnnLog2及其 workspace 申请时改用智能指针并通过.get()传入裸指针。 - 移除手动释放逻辑:删除原示例中
aclDestroyTensor、aclrtFree、aclrtDestroyStream、aclrtResetDevice、aclFinalize的显式释放代码,资源清理交由 RAII 自动完成。


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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执行结束


描述
将
math/log/examples下的 aclnn 示例由手动资源管理改为 C++ RAII 管理,与同仓math/is_finite、math/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、… 正确),示例正常退出。文档更新
无。
类型标签