已开启
【代码侦探Challenge 04】完成 DivCustomTemplate 工程化算子实现 #2156
【代码侦探Challenge 04】完成 DivCustomTemplate 工程化算子实现 #2156
已开启
iss_liqinghua创建于 2 天前
2 天前

当前 PR 是否有 AI 参与

  1. AI Agent 平台:OpenAI Codex
  2. AI 模型:GPT-5
  3. Prompt 上下文:协助完成代码实现、静态检查与验证流程。

变更描述 / Description

完成 DivCustomTemplate 工程化算子实现:

  • 支持 FP16、FP32 数据类型及 ACLNN 调用验证。
  • 根据输入规模动态生成 Tiling 参数,并按 32B 对齐处理数据。
  • 完善运行资源申请、释放及异常路径清理。
  • 支持 ascend310p 与 ascend910b 编译目标。

测试信息 / Testing

验证结果:

  • Ascend 310P3 + CANN 9.0.0:编译、安装及硬件执行验证通过,FP16/FP32 结果均为 0.5,测试通过。
  • ascend910b:目标编译及算子包生成通过,未进行对应硬件执行。

下图为验证环境实际终端截图,显示 CANN 9.0.0、Ascend 310P3 以及 FP16/FP32 执行通过。

验证环境实际终端截图

查看原始终端日志 verification.log

提交说明

GitCode API v5 仅提供单文件创建或更新接口,因此本分支形成多个 commit;这些提交均属于同一功能变更,PR 已启用合入时自动 squash。

检查清单 / Checklist

likedislike
合并受阻
Iiss_liqinghua
2 天前 创建了 pull request,commit f08d0301
Iiss_liqinghua
2 天前 关联了issue:🔍 代码侦探(第四期)|补全工程化算子代码有奖,周周赢取定制礼品!
atomgit-bot
atomgit-bot
2 天前 评论:

变更摘要

本 PR 完成 DivCustomTemplate 自定义算子的工程化实现:在 host 侧实现 Tiling 参数计算与 Shape/DataType 推导,在 kernel 侧基于 AscendC 完成除法计算,并配套算子定义、TF 插件注册、CMake 构建脚本、一键构建/安装/运行脚本以及基于 ACLNN 接口的测试用例。算子支持 FP16/FP32 两种数据类型,按输入规模动态生成 Tiling 参数并遵循 32B 对齐,同时支持 ascend310pascend910b 两种编译目标。

主要改动

  • 算子定义与注册: 新增 div_custom_template.json 定义算子输入 x/y 与输出 z(ND 格式,float16/float),并在 tensorflow_div_custom_template_plugin.cc 中通过 REGISTER_CUSTOM_OP("DivCustomTemplate") 完成 TF 框架插件注册。

  • Host 侧 Tiling 与推导逻辑: op_host/div_custom_template.cpp 实现 TilingFunc(校验输入 shape/数据类型一致性,按 32B 对齐计算 blockDim/blockLength/tileLength 并写入 DivCustomTemplateTilingData)、InferShape/InferDataType,并通过 AICore().AddConfig 注册 ascend910bascend310p 配置。

  • Kernel 侧算子实现: op_kernel/div_custom_template.cpp 使用 TPipe/TQue 双缓冲流水,经 DataCopy 搬入、Div 计算、DataCopy 搬出完成逐 tile 处理,并根据 tilingData.dataTypefloathalf 之间分发。

  • Tiling 数据结构: op_kernel/div_custom_template_tiling.h 通过 BEGIN_TILING_DATA_DEF 定义 totalLength/blockLength/tileLength/dataType 四个字段并注册 DivCustomTemplateTilingData

  • 构建、运行与验证流程: 新增 CMakePresets.json/build.sh 构建配置与脚本、run.sh 一键加载 CANN 环境并完成编译、安装、环境 source 与测试执行,test/main.cpp 通过 aclnnDivCustomTemplateGetWorkspaceSize/aclnnDivCustomTemplate 验证 FP16/FP32 除法结果,并实现资源申请与异常路径的释放清理。

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

Hi @iss_liqinghua, welcome to submitting your first PR to cann-outreach!

PR Merge Steps

1. CLA Signing

If the current PR label includes cann-cla/yes, it means you have signed the CLA and can proceed to the next step. If the label includes cann-cla/no, please sign the CLA first. If you have any questions, please refer to the FAQ.

2. CI Check

Please comment /compile to trigger the CI pipeline check. If the CI run is successful, the PR will be tagged with ci-pipeline-passed and you can proceed to the next step. If the CI run fails, the PR will be tagged with ci-pipeline-failed, please check the CI logs to fix the issues in the PR. If you have any questions, please refer to the FAQ.

3. Code Review

After CI passes, please refer to the PR Approval Progress and proactively @ the committers in the table to review the code. After approval, committers will comment /lgtm and /approve. Once the lgtm and approved labels are successfully added, the PR will be merged automatically.

likedislike
atomgit-bot
atomgit-bot
2 天前 评论:

代码审查

✅ 未发现问题

likedislike
CANN-robotCANN-robot成员
2 天前 添加了label:cann-cla/no
CANN-robotCANN-robot成员
2 天前 添加了label:stat/needs-squash
CANN-robot
CANN-robot成员
2 天前 评论:

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.
For more, you also can visit HICANN.


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
repo-cann/cann-outreach ❌ (0/2)(You can also ask: Carolina_yuan, jxlang, 傅涛, shaoyf, 田晓亮) ❌ (0/1)(You can also ask: jxlang, gcw_tgPdOLZT, shaoyf, 田晓亮, luzx66)

💡 Tip:

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

CLA Signature Pass

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

likedislike
iss_liqinghua
2 天前 评论:

/compile

likedislike
Iiss_liqinghua
2 天前 update merge request[project id: 9865789, iid: 2156, commit_id: 8997f88779ae8225eb19648094e018bb884718cf] virtual merging success
此处折叠了5条事件消息 查看更多
Iiss_liqinghua
2 天前 修改了pull request 的描述
iss_liqinghua
2 天前 评论:

/compile

likedislike
Iiss_liqinghua
2 天前 修改了pull request 的描述
iss_liqinghua
2 天前 评论:

/compile

likedislike
Iiss_liqinghua
2 天前 update merge request[project id: 9865789, iid: 2156, commit_id: e2fb13508414f5cf0ab9fa6a93a7df6b22bb669a] virtual merging success
Iiss_liqinghua
2 天前 推送  1 个提交:04d3934b-【代码侦探Challenge 04】替换为环境实际终端截图
Iiss_liqinghua
2 天前 update merge request[project id: 9865789, iid: 2156, commit_id: 7973463ee1fec69666ede5d2d5451464740bfd93] virtual merging success
CANN-robotCANN-robot成员
2 天前 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
2 天前 添加了label:cann-cla/yes
Iiss_liqinghua
2 天前 修改了pull request 的描述