Merged
增加对opType是否越界的校验 #803
ren-botaoAdd on Aug 31
增加对opType是否越界的校验 #803
Merged
ren-botaoAdd on Aug 31
ren-botao
ren-botaoCollaborators
Aug 31

描述

本 PR 主要聚焦于对 opType(算子类型 ID)是否越界或未注册的校验增强。

关联的Issue

#347 (https://gitcode.com/cann/opbase/issues/347)

测试

增加了相关ut用例,冒烟验证

文档更新

不涉及

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for ren-botao's contribution.)
ren-botaoren-botaoCollaborators
Aug 31 Created pull request, commit 24dcedca
atomgit-bot
atomgit-bot
Aug 31 Comments:

变更摘要

本 PR 主要聚焦于对 opType(算子类型 ID)是否越界或未注册的校验增强。改动将上限常量 MAX_OP_TYPE_COUNT(值为 1024)统一定义到 kernel_utils.h,并在算子注册、AclOpKernelInit、InitOpFunctions、MemSet 与 NonFiniteCheck 等关键路径上补充了 opType == 0(未注册)或越界的检查,同时将原 kernel_mgr.cpp 中的 OP_LOGD 日志提升为 OP_LOGW 告警级别。

主要改动

  • 统一定义上限常量:在 src/nnopbase/common/inc/kernel_utils.h 新增 MAX_OP_TYPE_COUNT = 1024,并从 op_ctx_def.h 中移除重复定义,避免同一常量多处声明。
  • 强化 AclOpKernelInit 校验:在 kernel_mgr.cpp 中将校验条件由 opType >= MAX_OP_TYPE_COUNT 扩展为 opType >= MAX_OP_TYPE_COUNT || opType == 0,对未注册(id 为 0)的算子类型也予以拦截,并将日志级别从 OP_LOGD 提升为 OP_LOGW。
  • InitOpFunctions 增加越界检查:在 op_run_context.cpp 的 InitOpFunctions 入口新增 CHECK_COND(opType < MAX_OP_TYPE_COUNT, ...),越界时返回 ACLNN_ERR_INNER。
  • MemSet 与 NonFiniteCheck 增加未注册检查:分别在 op_run_context.h 与 non_finite_check_op.h 中通过 OP_CHECK(opType != 0, ...) / OP_CHECK(opid != 0, ...) 校验算子已注册,未注册时分别返回 nullptr 与 ACLNN_ERR_INNER。
  • 注册端与查询端越界防护:在 op_def.cpp 的 OpTypeDict::Add 中新增注册数量达到 MAX_OP_TYPE_COUNT 上限时拒绝注册并返回 ACLNN_ERR_INNER 的检查;同时在 GetOpConfigJsonFileName 中增加 opType 超出 opConfigJsonPath_ 容量时返回空容器的越界保护。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Aug 31 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 31 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 31 Comments:

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.
You can self-configure the PR merge rules for this repository. For more details, please refer to 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/opbase ✅ 宋恺, pengjiahao96 (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

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

likedislike
CANN-robotCANN-robotCollaborators
Aug 31 Set pengjiahao96,zhou-qilong,wangrui_,rxtfeng,loov1,jia0liang,zl_hw,songkai111,pingchuantang,llimwang,gubaocheng as approver
19 event messages are collapsed here。 See more
ren-botaoren-botaoCollaborators
Sep 1 Modify description of pull request
ren-botao
ren-botaoCollaborators
Sep 1 Comments:

compile

likedislike
ren-botaoren-botaoCollaborators
Sep 1 Pre merge succeeded (commit_id: f58eed0ec7a68d2347c0485a0900dc8ab70fff90)
CANN-robot
CANN-robotCollaborators
Sep 1 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 1 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 1 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 1 Added label: ci-pipeline-passed
pengjiahao96
pengjiahao96Collaborators
Sep 2 Comments:

/lgtm

likedislike
songkai111
songkai111Collaborators
Sep 2 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 2 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Sep 2 Closed associated issue
CANN-robotCANN-robotCollaborators
Sep 2 Merged pull request