Merged
fix(index): validate empty self and handle empty indices #12074
fix(index): validate empty self and handle empty indices #12074
Merged
fazhenyao123Add on 27 days ago
fazhenyao123
fazhenyao123Collaborators
27 days ago

描述

修复 aclnnIndex 的两类空输入问题:self 为空且 out 非空时成功返回但不写输出,以及 indices 全为空占位时访问空 allDefinedIndices 导致越界。

  • self 为空且 out 非空时返回 ACLNN_ERR_PARAM_INVALID。
  • indices 中无 tensor 或所有 tensor 均为空时,要求 out 与 self 的 shape 一致,并通过 Contiguous + ViewCopy 将 self 复制到 out;在索引检查和形状推导前返回,避免访问空索引集合。
  • 形状合法的空输出仍成功返回,workspaceSize 为 0。
  • 补充单个/多个空索引、标量、非连续输入输出和输出形状不匹配的第一段接口回归用例,并保留 self/out 同为空的用例。
  • 同步接口文档的错误码表与约束说明。

关联的Issue

https://gitcode.com/cann/ops-nn/issues/6304

测试

  • clang-format 18.1.8 --style=file --dry-run --Werror:通过(两个变更 C++ 文件)。
  • git diff --check:通过。
  • 本次推送远端 Git Hooks Checking:通过。
  • 未执行编译和 UT:本机缺少 CMake/CANN 编译工具链。新增 UT 检查第一段接口返回结果,不代表已完成设备输出精度验证;历史 CI 通过结果不作为本次提交的测试结果。
  • 目标分支:master;基线 commit:2e44a4a70b418a6cc1d088e12f3608e4c27f0bf9。

文档更新

已更新 index/index/docs/aclnnIndex.md。

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for fazhenyao123's contribution.)
fazhenyao123fazhenyao123Collaborators
27 days ago Created pull request, commit c56bc7ac
fazhenyao123fazhenyao123Collaborators
27 days ago Associated issue: [Bug-Report|缺陷反馈]: aclnnIndex 空 self × 非空 out 时早退不填输出,返回成功但输出为未初始化内存
atomgit-bot
atomgit-bot
27 days ago Comments:

变更摘要

本次变更修复了 aclnnIndex 在 self 为空、out 非空时直接返回成功却不写输出的问题。核心改动是在 CheckParams 中新增非法组合校验,拒绝该组合并返回 ACLNN_ERR_PARAM_INVALID;同时将 aclnnIndexGetWorkspaceSize 的空张量早退条件由 self 或 out 任一为空收窄为仅 out 为空,并配套更新了单元测试与接口文档的错误码说明。

主要改动

  • 参数检查拒绝非法组合: 在 CheckParams 中新增判断,当 self->IsEmpty() 且 !out->IsEmpty() 时记录错误日志并返回 ACLNN_ERR_PARAM_INVALID。
  • 收窄空张量早退条件: 将 aclnnIndexGetWorkspaceSize 中的早退判断从 self->IsEmpty() || out->IsEmpty() 改为仅 out->IsEmpty(),此路径仍设置 *workspaceSize = 0 并直接返回 ACLNN_SUCCESS。
  • 更新回归用例期望: 将 l2_test_self_empty_fp32 的期望结果由 ACLNN_SUCCESS 改为 ACLNN_ERR_PARAM_INVALID,以反映 self 为空的非法组合被拒绝。
  • 新增空张量用例: 新增 l2_test_self_and_out_empty_fp32,验证 self 与 out 同时为空时返回 ACLNN_SUCCESS 且 workspaceSize 为 0。
  • 更新接口文档: 同步更新 index/index/docs/aclnnIndex.md 中的错误码说明(该文件未嵌入补丁,仅据 PR 描述归纳)。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
atomgit-bot
atomgit-bot
27 days ago Comments:

代码审查

✅ 未发现问题


🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
27 days ago Added label: cann-cla/yes
44 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
23 days ago Added label: approved
CANN-robot
CANN-robotCollaborators
23 days ago Comments:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
fazhenyao123fazhenyao123Collaborators
23 days ago Resolved final issue
CANN-robotCANN-robotCollaborators
23 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
23 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike