已合并
Xlog1py示例改用C++ RAII资源管理,与IsFinite/IsInf示例风格对齐 #4850
Xlog1py示例改用C++ RAII资源管理,与IsFinite/IsInf示例风格对齐 #4850
已合并
chendunyang创建于 10 天前
chendunyang
chendunyang成员
10 天前

描述

math/xlog1py/examples 下的 aclnn 示例由手动资源管理改为 C++ RAII 管理,与同仓 math/is_finitemath/is_inf 示例风格保持一致。

测试

未在 Ascend 环境实际编译运行;改动结构与已合并的 is_inf(PR #4531)一致。

文档更新

无。

类型标签

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

变更摘要

本 PR 将 math/xlog1py/examples 下的 aclnn 示例(test_aclnn_xlog1py.cpp)从手动资源管理改造为 C++ RAII 管理,与同仓 math/is_finitemath/is_inf 示例风格对齐:引入基于 std::unique_ptr 的智能指针统一管理 ACL stream、设备内存和 aclTensor 的生命周期,并在 main 中通过 lambda 守卫统一回收设备与 ACL 全局资源,同时删除了各函数中分散的显式释放代码。

主要改动

  • 新增 RAII 类型别名:定义 StreamPtrDeviceMemPtrTensorPtr(均为 std::unique_ptr,分别绑定 aclrtDestroyStreamaclrtFreeaclDestroyTensor 作为删除器),并包含 <memory><type_traits> 头文件。
  • 改造 Init 接口:签名由 int Init(int32_t deviceId, aclrtStream* stream) 改为接收 StreamPtr&bool& initializedbool& deviceSet,在 aclInitaclrtSetDevice 成功后记录状态标志,并将创建的 stream 交由 StreamPtr 持有。
  • 改造 CreateAclTensorRunXlog1py:张量与设备内存改为通过 DeviceMemPtr&TensorPtr& 管理,新增对 aclCreateTensor 返回空指针的 CHECK_RET 校验;RunXlog1py 内调用改为 .get() 传参(workspace 同样用 DeviceMemPtr 管理),并删除函数末尾的手动 aclDestroyTensor/aclrtFree 清理段。
  • 重构 main 资源回收:使用 std::shared_ptr<void> 守卫(aclGuard)在退出时按 deviceSet/initialized 状态调用 aclrtResetDeviceaclFinalize,同时移除结尾手动的 aclrtDestroyStream/aclrtResetDevice/aclFinalize 调用。
  • 代码风格统一:按 is_finite/is_inf 示例风格调整 for 循环、条件语句的换行与大括号格式(纯排版调整,不影响行为)。
likedislike
atomgit-bot
atomgit-bot
10 天前 评论:

代码审查

✅ 未发现问题

likedislike
CANN-robotCANN-robot成员
10 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
10 天前 评论:

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
repo-cann/ops-math 周奇龙, andong_hw (2/2) 周奇龙 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies 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. 👍

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

compile

likedislike
chendunyangchendunyang成员
10 天前 update merge request[project id: 7649531, iid: 4850, commit_id: 0acb65c816e7c761fd6e343ec706e36f70422a69] virtual merging success
CANN-robotCANN-robot成员
10 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
10 天前 评论:

流水线任务触发成功
任务链接 [0fe636ec6cb3443e91f8373b83adda8d][流水线指导]

任务名称状态日志下载链接
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 >>>>>
likedislike
CANN-robot
CANN-robot成员
10 天前 评论:

流水线任务触发成功
任务链接 [b7402af7f2bb48678e2f738b6650d1b3][流水线指导]

任务名称状态日志下载链接
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:33:13]    CI执行结束

likedislike
CANN-robotCANN-robot成员
10 天前 添加了label:api-check-pass
CANN-robotCANN-robot成员
10 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
10 天前 添加了label:ci-pipeline-failed
chendunyang
chendunyang成员
10 天前 评论:

compile#UT_Test_experimental

likedislike
chendunyangchendunyang成员
10 天前 update merge request[project id: 7649531, iid: 4850, commit_id: d06c37935c258c96004c46d91065feb51a345b2c] virtual merging success
CANN-robotCANN-robot成员
10 天前 删除了label:ci-pipeline-failedapi-check-pass
CANN-robotCANN-robot成员
10 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
10 天前 评论:

流水线任务触发成功
任务链接 [6cc903ec20554eb9b9054aab0ffd8451][流水线指导]

任务名称状态日志下载链接
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 11:54:14]    CI执行结束

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

流水线任务触发成功
任务链接 [c26bedb2f1e04968a1f47917993ff8ec][流水线指导]

任务名称状态日志下载链接
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 11:49:19]    CI执行结束

likedislike
CANN-robotCANN-robot成员
10 天前 添加了label:api-check-pass
CANN-robotCANN-robot成员
10 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
10 天前 添加了label:ci-pipeline-passed
sunday成员
9 天前 评论:

/lgtm
/approve

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

/lgtm

likedislike
CANN-robotCANN-robot成员
9 天前 添加了label:lgtm
CANN-robotCANN-robot成员
9 天前 合入了pull request