已合并
修改foreach算子示例代码使用aclrtMemcpy没有返回值校验不规范问题 #7797
tramp-ll创建于 19 天前
修改foreach算子示例代码使用aclrtMemcpy没有返回值校验不规范问题 #7797
已合并
tramp-ll创建于 19 天前
tramp-ll
19 天前

描述

foreach 示例代码增加aclrtMemcpy返回值校验

关联的Issue

Issue: https://gitcode.com/cann/ops-nn/issues/4219

测试

编译通过

文档更新

更新foreach系列算子md资料

类型标签

  • Bug修复
  • 新特性
  • 性能优化
  • 文档更新
  • 其他,请描述:

AI/Agent生成声明

  • AI辅助编写
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 tramp-ll 的贡献)
Ttramp-ll
19 天前 创建了 pull request,commit 4015af47
atomgit-bot
atomgit-bot
19 天前 评论:

变更摘要

此 PR 主要修复了 foreach 系列算子示例代码中调用 aclrtMemcpy 后未检查返回值的规范性问题。在所有受影响的示例文件中,对每次 aclrtMemcpy 调用后增加了 CHECK_RET 宏判断,确保设备到主机的内存拷贝失败时能够及时打印错误信息并返回错误码。此外,还清理了一处未使用的变量。

主要改动

  • 统一增加 aclrtMemcpy 返回值检查: 在 137 个 foreach 算子示例文件(涵盖 foreach_absforeach_acosforeach_add_listforeach_add_scalarforeach_mul_listforeach_sin 等全部算子变体)中,每个 aclrtMemcpy 调用后均新增了 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); 检查逻辑,确保 Device-to-Host 拷贝失败时能正确报错并终止程序。
  • 清理未使用变量: 在 foreach/foreach_maximum_scalar/examples/test_aclnn_foreach_maximum_scalar.cpp 中,移除了声明但未使用的局部变量 float alphaValue = 5.2f; 及其后续多余空行。
likedislike
atomgit-bot
atomgit-bot
19 天前 评论:

代码审查

✅ 未发现问题

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

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


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
*/*/docs/acl*.md 周文芳, 韩小龙, 杜慧萍, 陈娇 (4/2) 杜慧萍, 陈娇 (2/1)
** 陈娇, 韩小龙 (2/2) 陈娇, 韩小龙 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
19 天前 将zengjuan,crystalhu,yangyang016,fanqirui,gitee-duhuiping,chenqi317,jiangtao_rts,liubo75,tangweiwei2,gitcode-chenjiao,hanxiaolong,zhouwenfang,wuyao51511,gcw_kUomxQ2l,Andy-lb,caiwenwen设为评审人
CANN-robotCANN-robot成员
19 天前 将gitee-duhuiping,jiangtao_rts,gitcode-chenjiao,hanxiaolong,zhouwenfang,wuyao51511,gcw_kUomxQ2l,Andy-lb,caiwenwen设为审查人
Ttramp-ll
19 天前 update merge request[project id: 7665709, iid: 7797, commit_id: 27a6157773d4fdaf6330668d802b7075f3c95502] virtual merging success
Ttramp-ll
19 天前 推送  1 个提交:7fec06ec-修改foreach算子示例代码不规范问题
Ttramp-ll
19 天前 update merge request[project id: 7665709, iid: 7797, commit_id: 0ab75ee7b39624a389860aada6433c9d28a4b89f] virtual merging success
CANN-robotCANN-robot成员
19 天前 添加了label:stat/needs-squash
tramp-ll
19 天前 评论:

compile

likedislike
Ttramp-ll
19 天前 update merge request[project id: 7665709, iid: 7797, commit_id: e667878406e02bbb9f3541e7803d429dae5529e2] virtual merging success
CANN-robotCANN-robot成员
19 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
19 天前 评论:

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

任务名称状态日志下载链接
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950 ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
UT_Test_ophost ✅ SUCCESS
UT_Test_opapi ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
UT_Test_opgraph ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-07-22 10:36:29]    CI执行结束

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

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

任务名称状态日志下载链接
antipoison ✅ SUCCESS >>>>>
codecheck_checkpr ✅ SUCCESS
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_style ✅ SUCCESS >>>>>
codecheck_precommit ⚠️ WARNING >>>>> >>>>>
SCA ✅ SUCCESS >>>>>

[2026-07-22 10:27:21]    CI执行结束

likedislike
Ttramp-ll
19 天前 修改标题为 “修改foreach算子示例代码使用aclrtMemcpy没有返回值校验不规范问题”,原标题为“修改foreach算子示例代码使用aclrtMemcpy没有返回值不规范问题”
CANN-robotCANN-robot成员
19 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
19 天前 添加了label:ci-pipeline-passed
zhajianqing123成员
18 天前 评论:

/lgtm
/approve

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

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
查建青

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

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
查建青

likedislike
Ttramp-ll
18 天前 修改了pull request 的描述
gitee-duhuiping成员
18 天前 评论:

/lgtm
/approve

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

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
查建青

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

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
查建青

likedislike
zhouwenfang
zhouwenfang成员
18 天前 评论:

/lgtm

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

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
查建青

likedislike
chenjiao成员
18 天前 评论:

/approve

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

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
查建青

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

/lgtm
/approve

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

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
查建青

likedislike
CANN-robotCANN-robot成员
18 天前 添加了label:lgtm
CANN-robotCANN-robot成员
18 天前 关闭了关联的issue
CANN-robotCANN-robot成员
18 天前 合入了pull request