已合并
fix: 修复opgen生成的算子工程无法编译通过的问题 #2431
songkai111创建于 4月24日
fix: 修复opgen生成的算子工程无法编译通过的问题 #2431
已合并
songkai111创建于 4月24日
songkai111成员
4月24日

描述

修复 opgen 工具生成的算子工程在编译时出现的多处问题,确保生成的模板代码可以正常编译通过。

改动原因:

  • CMakeLists.txt 中硬编码过滤 `add_example` 导致其他算子的 examples 目录无法正确包含
  • 生成的算子工程目录缺少 CMake 构建链路(父目录 CMakeLists.txt 中没有 `add_subdirectory`)
  • 模板代码中存在编译错误:未定义的 `IDX_0` 宏、未使用参数警告、kernel 函数签名与 Init 调用参数不匹配

改动方法:

  1. CMakeLists.txt:将硬编码的 `add_example` 过滤逻辑改为动态检查 `examples/{op_name}/CMakeLists.txt` 文件是否存在,从而正确判断是否需要包含 examples 子目录
  2. opgen_standalone.py:新增 `_update_cmake_chain()` 方法,在生成算子工程后自动向上遍历父目录,在各级 CMakeLists.txt 中追加 `add_subdirectory`,确保构建系统能找到新建的工程目录
  3. add_example_infershape.cpp:将 `IDX_0` 替换为字面量 `0`,消除未定义宏导致的编译错误
  4. add_example_tiling.cpp:为未使用的 `context` 参数添加 `[[maybe_unused]]` 属性并直接返回 `GRAPH_SUCCESS`,消除未使用参数警告
  5. add_example.cpp / add_example.h:修正 kernel 函数和 `Init` 方法的参数签名,移除多余的 `z`(输出)参数;补全 `Init` 的参数声明和实现;将 `Process` 中的循环次数改为变量 `loopExample`

关联的Issue

测试

使用 opgen 工具生成算子工程后,验证生成的代码可以正常编译通过。

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 songkai111 的贡献)
Ssongkai111成员
4月24日 创建了 pull request,commit e1aab9ab
CANN-robot
CANN-robot成员
4月24日 评论:

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
repo-cann/ops-math 张磊, 王林木 (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

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

likedislike
CANN-robotCANN-robot成员
4月24日 将zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,llimwang,gubaocheng设为评审人
CANN-robotCANN-robot成员
4月24日 添加了label:cann-cla/yes
CANN-robotCANN-robot成员
4月24日 将zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,llimwang,gubaocheng设为审查人
songkai111成员
4月24日 评论:

compile

likedislike
CANN-robotCANN-robot成员
4月24日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
4月24日 评论:

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

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>>
harmony-infer ✅ SUCCESS
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
UT_Test_experimental ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
ATK_Test_A2 ✅ SUCCESS

[2026-04-24 16:19:11]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
4月24日 评论:

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

任务名称状态日志下载链接
codecheck ❌ FAILED >>>>>
SCA ✅ SUCCESS >>>>>
anti_virus ✅ SUCCESS >>>>>
Check_Pr ✅ SUCCESS >>>>>
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
cocheck_codestyle ✅ SUCCESS
likedislike
CANN-robotCANN-robot成员
4月24日 添加了label:api-check-pass
CANN-robotCANN-robot成员
4月24日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
4月24日 添加了label:ci-pipeline-failed
songkai111成员
4月25日 评论:

compile

likedislike
CANN-robotCANN-robot成员
4月25日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
4月25日 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
4月25日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
4月25日 添加了label:ci-pipeline-failed
songkai111成员
4月25日 评论:

compile

likedislike
CANN-robotCANN-robot成员
4月25日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
4月25日 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
4月25日 删除了label:api-check-pass
CANN-robot
CANN-robot成员
4月25日 评论:

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

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>>
harmony-infer ✅ SUCCESS
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
UT_Test_experimental ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
ATK_Test_A2 ✅ SUCCESS

[2026-04-25 10:26:39]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
4月25日 评论:

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

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
anti_virus ✅ SUCCESS >>>>>
Check_Pr ✅ SUCCESS >>>>>
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
cocheck_codestyle ✅ SUCCESS

[2026-04-25 10:16:36]    CI执行结束

likedislike
CANN-robotCANN-robot成员
4月25日 添加了label:api-check-pass
CANN-robotCANN-robot成员
4月25日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
4月25日 添加了label:ci-pipeline-passed
Ssongkai111成员
4月25日 修改标题为 “fix: 修复opgen生成的算子工程无法编译通过的问题”,原标题为“修复genop无法编译通过的问题”
Ssongkai111成员
4月25日 修改了pull request 的描述
Ssongkai111成员
4月25日 修改了pull request 的描述
zl_hw成员
4月25日 评论:

/lgtm

likedislike
llimwang成员
4月25日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
4月25日 添加了label:lgtmapproved
CANN-robot
CANN-robot成员
4月25日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: 王林木.
Reviewers who wrote a comment of /lgtm are: 王林木, 张磊.

likedislike
CANN-robotCANN-robot成员
4月25日 关闭了关联的issue
CANN-robotCANN-robot成员
4月25日 合入了pull request