Merged
fix(heaviside): 补全tiling入参/dtype校验与溢出防护,整改静态检查问题 #13876
tan_xinAdd on 14 days ago
fix(heaviside): 补全tiling入参/dtype校验与溢出防护,整改静态检查问题 #13876
Merged
tan_xinAdd on 14 days ago
tan_xin
tan_xinCollaborators
14 days ago

描述

本条PR针对 heaviside 算子静态检查发现的问题进行修复,分为功能加固与规范整改两类:

  1. 功能加固(op_host)

    • heaviside_tiling.cpp:
      • CeilA2B 改为 (a-1)/b + 1 形式,避免 a 接近 INT64_MAX 时 (a+b-1) 有符号溢出;a<=0 时直接返回 0。
      • 新增 inputDesc / valuesDesc 空校验,并校验 values 与 input dtype 一致,不一致时报错返回 GRAPH_FAILED。
      • 新增 input/values shape、PlatformInfo、workspace、RawTilingData 空指针校验。
      • 对 GetShapeSize 返回的 INT64_MIN 无效哨兵值做溢出防护。
      • 新增 coreNum 为 0 的校验。
    • heaviside_infershape.cpp:InferDataType 增加 values dtype 读取与校验(input/values dtype 非 UNDEFINED 且必须一致),否则返回 GRAPH_FAILED。
  2. 文档与接口注释(op_api / docs / README)

    • op_api/aclnn_heaviside.h:out 参数由 @param [in] 修正为 @param [out];修正 GetWorkspaceSize 接口名笔误(ForeachAbs→Heaviside)。
    • docs/aclnnHeaviside_en.md:错误码表表头 Error Code→Return Code;新增"input 与 values dtype 不一致"错误行(rowspan 3→4)。
    • README_en.md:公式条件分支文案由中文"如果"改为英文"if"。
  3. 示例资源释放

    • examples/test_aclnn_heaviside.cpp:各失败分支补充 aclDestroyTensor / aclrtFree / aclrtResetDevice / aclFinalize,修复异常路径资源泄漏。
  4. 静态检查规范整改

    • CMakeLists、config binary json、proto/tiling/kernel 头文件、UT 源码等补充文件末尾换行、去除行尾空格。
    • tests/ut/op_kernel/heaviside_tiling_def.h:elementNum 类型 int32_t→int64_t,与 tiling 结构对齐。
    • gen_data.py / compare_data.py:移除未使用 import(re/math/torch),代码风格修正。

关联的Issue

测试

  • 现有 UT 全量回归:op_host infershape/tiling、op_kernel、op_api、ST(含更新后的 atk 用例与 tiling_def 类型对齐)。

文档更新

  • activation/heaviside/docs/aclnnHeaviside_en.md:错误码表头与 dtype 一致性错误行。
  • activation/heaviside/README_en.md:公式文案英文化。
  • activation/heaviside/op_api/aclnn_heaviside.h:参数方向与接口名注释修正。

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for tan_xin's contribution.)
tan_xintan_xinCollaborators
14 days ago Created pull request, commit 09295fa2
atomgit-bot
atomgit-bot
14 days ago Comments:

变更摘要

本 PR 针对 heaviside 算子的静态检查问题做修复,主要集中在 op_host 的 tiling 与 infershape 逻辑健壮性、op_api 接口注释与样例程序的资源释放、以及 UT 数据生成/比对脚本的规范化。核心是补齐空指针、dtype 一致性与数值溢出等边界校验,并让示例与测试代码在失败路径上正确释放 device、stream 与 tensor 资源。

主要改动

  • heaviside_tiling.cpp 增加上下文与数值边界校验:RunBigKernelTiling 对 GetInputDesc、GetInputShape、GetPlatformInfo、GetWorkspaceSizes、GetRawTilingData 的返回值增加空指针检查,并校验 values 与 input 的 dtype 一致、GetCoreNumAiv 非 0、GetShapeSize 未返回溢出哨兵值,失败时返回 ge::GRAPH_FAILED。
  • CeilA2B 改为防溢出实现:CeilA2B 先处理 b == 0 与非正 a 的边界,再使用 (a - 1) / b + 1 计算向上取整,避免 a + b - 1 在 a 接近 INT64_MAX 时溢出。
  • InferDataType4Heaviside 新增数据类型一致性校验:同时读取 input 与 values 的 dtype,当任一为 ge::DT_UNDEFINED 或两者不相等时,通过 OP_CHECK_IF 报错并返回 ge::GRAPH_FAILED,之后才设置输出数据类型。
  • aclnn_heaviside.h 接口文档修正:out 参数标注由 @param [in] 改为 @param [out],并将 workspaceSize 说明中的接口名从 aclnnForeachAbsGetWorkspaceSize 更正为 aclnnHeavisideGetWorkspaceSize。
  • 样例与 UT 的资源释放及类型对齐:test_aclnn_heaviside.cpp 在 aclrtSetDevice、aclrtCreateStream、aclrtMemcpy、CreateAclTensor 失败路径补充 aclFinalize、aclrtResetDevice、aclrtFree、aclDestroyTensor 等清理;UT 结构体 HeavisideTilingData 的 elementNum 由 int32_t 改为 int64_t,与 tiling 数据字段对齐。
  • 测试脚本与文件格式规范化:compare_data.py 使用 ~diff_res 替代与 True 比较、移除未使用导入与未使用返回值;gen_data.py 清理多余导入;多个 .json、.h、.cpp 文件补齐行尾换行。

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

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

代码审查

✅ 未发现问题


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

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
14 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
14 days ago 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
*/*/docs/acl*.md ✅ 陈娇, 王星, 上官秦南 (3/2) ✅ 陈娇 (1/1)
*/*/op_api/*.h ✅ 汤磊, 王星, 上官秦南 (3/2) ✅ 汤磊 (1/1)
*/*/op_graph/*_proto.h ✅ 汤磊, 王星, 上官秦南 (3/2) ✅ 汤磊 (1/1)
activation ✅ 王星, 上官秦南 (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

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

likedislike
CANN-robotCANN-robotCollaborators
14 days ago Set zengjuan,u010470851,chaotang233,kevin_huang1234,crystalhu,yangyang016,fanqirui,gitee-duhuiping,wangrui_,renruhai,su-yueming,zhajianqing123,tang-lei01,yourealize,chenqi317,wang-xing001,liubo75,tangweiwei2,gitcode-chenjiao,chenxingyu18,liujie12345678,east_yang,pingchuantang,Chen_HaoWen,qianzehong,wangyongguang,fengying555682,caiwenwen,yanglu-1 as approver
CANN-robotCANN-robotCollaborators
14 days ago Set u010470851,kevin_huang1234,gitee-duhuiping,wangrui_,renruhai,su-yueming,zhajianqing123,tang-lei01,yourealize,wang-xing001,gitcode-chenjiao,chenxingyu18,liujie12345678,east_yang,pingchuantang,Chen_HaoWen,qianzehong,wangyongguang,fengying555682,caiwenwen,yanglu-1 as approver
tan_xintan_xinCollaborators
14 days ago Pre merge succeeded (commit_id: aabf2838d8a7cc597bfac04f7532786a5fbdfbc5)
tan_xintan_xinCollaborators
14 days ago Force-pushed 1 commits:1e13b921-heaviside
tan_xintan_xinCollaborators
14 days ago Pre merge succeeded (commit_id: cf0e24cbb832dd3499b9fd2ed595b7c217c9bb9b)
tan_xin
tan_xinCollaborators
14 days ago Comments:

compile

likedislike
tan_xintan_xinCollaborators
14 days ago Pre merge succeeded (commit_id: 9184c305adaaa4f5ac6f3de80fe3e19fdb41399c)
CANN-robotCANN-robotCollaborators
14 days ago Removed label: cann-cla/yes
CANN-robotCANN-robotCollaborators
14 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
14 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
14 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
14 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
14 days ago Added label: ci-pipeline-passed
yuning_chen
yuning_chenCollaborators
14 days ago Comments:
chenqi317
chenqi317Collaborators
14 days ago Comments:

pr描述为空,没有说明pr背景和价值

likedislike
chenqi317
chenqi317Collaborators
14 days ago Comments:

请补充关联issue 说明合入背景

likedislike
tan_xintan_xinCollaborators
12 days ago Change title to "fix(heaviside): 补全tiling入参/dtype校验与溢出防护,整改静态检查问题", originally titled "fix(heaviside): 静态检查问题修复".
tan_xintan_xinCollaborators
12 days ago Modify description of pull request
tang-lei01
tang-lei01Collaborators
12 days ago Comments:

/approve

likedislike
wang-xing001
wang-xing001Collaborators
12 days ago Comments:

/lgtm
/approve

likedislike
sgqt12
sgqt12Collaborators
12 days ago Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
12 days ago Added label: lgtm
chenjiao
chenjiaoCollaborators
12 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
12 days ago Added label: approved
CANN-robotCANN-robotCollaborators
12 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
12 days ago Merged pull request