Pull Request已成功合入, 合并人@CANN-robot
(感谢 chendunyang 的贡献)变更摘要
该 PR 将 math/square/examples/arch35/test_aclnn_square.cpp 示例从手动资源管理改造为 C++ RAII 资源管理,与同仓 math/is_finite、math/is_inf 示例风格对齐。改动引入基于 std::unique_ptr 的自定义删除器类型(StreamPtr、DeviceMemPtr、TensorPtr)分别托管 stream、device 内存和 aclTensor,并将 Init、CreateAclTensor 等接口改为以智能指针引用传递资源,同时用带自定义删除器的 std::shared_ptr 守卫统一在退出时执行 aclrtResetDevice/aclFinalize,从而删除原先手工释放资源的收尾代码。
主要改动
- 新增 RAII 智能指针类型: 在
test_aclnn_square.cpp中引入StreamPtr(aclrtDestroyStream)、DeviceMemPtr(aclrtFree)、TensorPtr(aclDestroyTensor)三个std::unique_ptr类型别名,并新增<memory>、<type_traits>头文件引用,以 RAII 方式托管 ACL 资源。 - 改造
Init接口:Init函数签名由Init(int32_t deviceId, aclrtStream* stream)改为Init(int32_t deviceId, StreamPtr& stream, bool& initialized, bool& deviceSet),通过initialized、deviceSet布尔标记记录aclInit/aclrtSetDevice的完成状态,并将新建 stream 通过stream.reset(rawStream)交由智能指针持有。 - 改造
CreateAclTensor接口: 入参由void** deviceAddr、aclTensor** tensor改为DeviceMemPtr& deviceAddr、TensorPtr& tensor,内部以deviceAddr.get()传递设备地址,并新增对aclCreateTensor返回空指针的失败校验后调用tensor.reset(rawTensor)。 main中改用智能指针并删除手工释放代码: 输入输出 tensor、device 内存与 workspace 均改为智能指针,API 调用(aclnnSquareGetWorkspaceSize、aclnnSquare、aclrtSynchronizeStream、aclrtMemcpy)改用.get()传入原始指针;新增std::shared_ptr守卫在作用域结束时按状态执行aclrtResetDevice与aclFinalize,删除了原有的aclDestroyTensor、aclrtFree、aclrtDestroyStream等手动清理步骤。


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/square | ✅ 周奇龙, 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
qq_37913898, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


流水线任务触发成功
任务链接 [6777467f498b418abac0230448edbd31][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| 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 | ❌ FAILED | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |


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


compile#UT_Test_experimental


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


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


描述
将
math/square/examples下的 aclnn 示例由手动资源管理改为 C++ RAII 管理,与同仓math/is_finite、math/is_inf示例风格保持一致。测试
未在 Ascend 环境实际编译运行;改动结构与已合并的
is_inf(PR #4531)一致。文档更新
无。
类型标签