Pull Request已成功合入, 合并人@CANN-robot
(感谢 sunday 的贡献)变更摘要
本 PR 对 math/lerp/examples/test_aclnn_lerp.cpp 示例进行资源管理方式改造,将原先手动调用 aclDestroyTensor、aclrtFree、aclrtDestroyStream、aclrtResetDevice、aclFinalize 的清理流程,改为基于 C++ RAII(std::unique_ptr、std::shared_ptr)自动释放,从而与 math/is_finite、math/is_inf 示例风格保持一致。改动主要集中在资源类型定义、初始化与张量创建接口签名调整,以及删除函数末尾的手动清理代码。
主要改动
- 引入 RAII 资源类型别名:新增
StreamPtr、DeviceMemPtr、TensorPtr三个基于std::unique_ptr的类型别名,分别以aclrtDestroyStream、aclrtFree、aclDestroyTensor作为删除器,并新增<memory>、<type_traits>头文件。 - 调整
Init函数接口与实现:Init改为接收StreamPtr&及bool& initialized、bool& deviceSet引用,内部先用裸指针创建aclrtStream再通过stream.reset(rawStream)交给智能指针管理,同时记录初始化和设备设置状态。 - 调整
CreateAclTensor接口与实现:函数由接收裸指针改为接收DeviceMemPtr&与TensorPtr&,内部先申请裸指针再reset到智能指针,并新增aclCreateTensor返回空指针的错误检查。 - 使用
aclGuard自动执行设备反初始化:在main中新增std::shared_ptr<void> aclGuard,通过 lambda 在作用域结束时按状态调用aclrtResetDevice和aclFinalize。 - 删除手动资源清理并改用
.get()传递裸指针:移除函数末尾的aclDestroyTensor、aclrtFree、aclrtDestroyStream等手动释放逻辑,workspaceAddr改为DeviceMemPtr,并在aclnnLerpGetWorkspaceSize、aclnnLerp、aclrtSynchronizeStream、aclrtMemcpy等调用处改用.get()。


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


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


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


The following label is not ready.
ci-pipeline-passed: The ci-pipeline-passed label is expired as added over 72 hours. Please use /compile to recompile.


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


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


描述
将
math/lerp/examples下的 aclnn 示例由手动资源管理改为 C++ RAII 管理,与同仓math/is_finite、math/is_inf示例风格保持一致。测试
Start to run examples, name:lerp mode:eager
Start compile and run examples file: ../math/lerp/examples/test_aclnn_inplace_lerp.cpp
pkg_mode:cust vendor_name:lerp
result[0] is: 7.000000
result[1] is: 8.000000
result[2] is: 9.000000
result[3] is: 10.000000
result[4] is: 11.000000
result[5] is: 12.000000
result[6] is: 13.000000
result[7] is: 14.000000
文档更新
无。
类型标签
关联 Issue
https://gitcode.com/cann/ops-math/issues/2733