Pull Request已成功合入, 合并人@CANN-robot
(感谢 sunday 的贡献)变更摘要
本 PR 将 math/is_close/examples/test_aclnn_isclose.cpp 中的 ACLNN 示例从手动资源管理改造为 C++ RAII 风格,与同仓 math/is_finite、math/is_inf 示例保持一致。核心是引入基于 std::unique_ptr 的自定义删除器类型(StreamPtr、DeviceMemPtr、TensorPtr),并通过 std::shared_ptr 清理守卫统一管理设备初始化/复位与 aclFinalize,移除原先在 main 结尾处的显式 aclDestroyTensor、aclrtFree、aclrtDestroyStream、aclrtResetDevice 和 aclFinalize 调用。
主要改动
- 引入 RAII 智能指针类型: 新增
StreamPtr、DeviceMemPtr、TensorPtr三个类型别名,分别以aclrtDestroyStream、aclrtFree、aclDestroyTensor作为自定义删除器,并在文件中补充<memory>与<type_traits>头文件。 - 调整
Init函数接口:Init改为接收StreamPtr&引用,并新增initialized、deviceSet两个状态标志,内部通过aclrtCreateStream创建裸指针后调用stream.reset(rawStream)交由 RAII 管理。 - 调整
CreateAclTensor函数接口: 函数参数由裸指针输出参数改为DeviceMemPtr&和TensorPtr&引用,先申请裸指针资源再reset()托管,并为aclCreateTensor增加空指针CHECK_RET校验。 - 增加设备生命周期清理守卫: 在
main中使用std::shared_ptr<void>类型的aclGuard,通过捕获deviceSet与initialized标志,在作用域结束时自动执行aclrtResetDevice与aclFinalize。 - 调用点统一改用
.get()并删除手动释放:aclnnIsCloseGetWorkspaceSize、aclnnIsClose、aclrtSynchronizeStream、aclrtMemcpy等接口调用均改为传入智能指针的.get(),同时移除原先main末尾第 6、7 步的全部手动资源释放代码。


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/is_close | ✅ zhangzijie, 王瑞 (2/2) | ✅ zhangzijie, 王瑞 (2/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. 👍


流水线任务触发成功
任务链接 [f3355288ff1b4d7bb042e0d1248a66fe][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| 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:05:43] CI执行结束


流水线任务触发成功
任务链接 [f67ceefb252c4c5fa8fc35829934d01f][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| 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 19:54:00] CI执行结束


/lgtm
/approve


描述
将
math/is_close/examples下的 aclnn 示例由手动资源管理改为 C++ RAII 管理,与同仓math/is_finite、math/is_inf示例风格保持一致。测试
bash build.sh --run_example is_close eager --soc=ascend950:编译通过,在 Ascend950PR 上运行成功,输出符合预期(isclose 比较掩码 1,1,1,1,0,1,1,1 正确),示例正常退出。文档更新
无。
类型标签