已合并
Lerp示例改用C++ RAII资源管理,与IsFinite/IsInf示例风格对齐 #4700
sunday创建于 26 天前
Lerp示例改用C++ RAII资源管理,与IsFinite/IsInf示例风格对齐 #4700
已合并
sunday创建于 26 天前
sunday成员
26 天前

描述

math/lerp/examples 下的 aclnn 示例由手动资源管理改为 C++ RAII 管理,与同仓 math/is_finitemath/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

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 sunday 的贡献)
Ssunday成员
26 天前 创建了 pull request,commit c8067411
atomgit-bot
atomgit-bot
26 天前 评论:

变更摘要

本 PR 对 math/lerp/examples/test_aclnn_lerp.cpp 示例进行资源管理方式改造,将原先手动调用 aclDestroyTensoraclrtFreeaclrtDestroyStreamaclrtResetDeviceaclFinalize 的清理流程,改为基于 C++ RAII(std::unique_ptrstd::shared_ptr)自动释放,从而与 math/is_finitemath/is_inf 示例风格保持一致。改动主要集中在资源类型定义、初始化与张量创建接口签名调整,以及删除函数末尾的手动清理代码。

主要改动

  • 引入 RAII 资源类型别名:新增 StreamPtrDeviceMemPtrTensorPtr 三个基于 std::unique_ptr 的类型别名,分别以 aclrtDestroyStreamaclrtFreeaclDestroyTensor 作为删除器,并新增 <memory><type_traits> 头文件。
  • 调整 Init 函数接口与实现Init 改为接收 StreamPtr&bool& initializedbool& deviceSet 引用,内部先用裸指针创建 aclrtStream 再通过 stream.reset(rawStream) 交给智能指针管理,同时记录初始化和设备设置状态。
  • 调整 CreateAclTensor 接口与实现:函数由接收裸指针改为接收 DeviceMemPtr&TensorPtr&,内部先申请裸指针再 reset 到智能指针,并新增 aclCreateTensor 返回空指针的错误检查。
  • 使用 aclGuard 自动执行设备反初始化:在 main 中新增 std::shared_ptr<void> aclGuard,通过 lambda 在作用域结束时按状态调用 aclrtResetDeviceaclFinalize
  • 删除手动资源清理并改用 .get() 传递裸指针:移除函数末尾的 aclDestroyTensoraclrtFreeaclrtDestroyStream 等手动释放逻辑,workspaceAddr 改为 DeviceMemPtr,并在 aclnnLerpGetWorkspaceSizeaclnnLerpaclrtSynchronizeStreamaclrtMemcpy 等调用处改用 .get()
likedislike
不准确?
atomgit-bot
atomgit-bot
26 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
26 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
26 天前 评论:

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 /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成员
26 天前 评论:

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
26 天前 将FelixTang7,yue-ma,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,zhanw_coding设为评审人
CANN-robotCANN-robot成员
26 天前 将FelixTang7,yue-ma,wangrui_,rxtfeng,loov1,zhangzijie,zl_hw,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,zhanw_coding设为审查人
sunday成员
25 天前 评论:

compile

likedislike
Ssunday成员
25 天前 update merge request[project id: 7649531, iid: 4700, commit_id: 8d0b423d8a443f4144fd19e26334439bb7906fcc] virtual merging success
CANN-robotCANN-robot成员
25 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
25 天前 评论:

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

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

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

likedislike
CANN-robotCANN-robot成员
25 天前 添加了label:api-check-pass
此处折叠了8条事件消息 查看更多
Ssunday成员
21 天前 修改了pull request 的描述
RuiWang_成员
21 天前 评论:

/lgtm
/approve

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

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
21 天前 添加了label:lgtm
CANN-robotCANN-robot成员
21 天前 删除了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
21 天前 评论:

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.

likedislike
sunday成员
21 天前 评论:

compile

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

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

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

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

likedislike
CANN-robotCANN-robot成员
21 天前 添加了label:api-check-pass
CANN-robotCANN-robot成员
21 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
21 天前 添加了label:ci-pipeline-passed
CANN-robotCANN-robot成员
21 天前 关闭了关联的issue
CANN-robotCANN-robot成员
21 天前 合入了pull request