合并受阻
变更摘要
本 PR 基于 msopgen 生成的算子工程,完成 DivCustomTemplate(z = x / y)工程化自定义算子开发,并通过 ACLNN 接口完成端到端验证(CANN 9.0.0 / Ascend910B4,bash run.sh 输出 test pass)。整套工程包含算子原型定义(div_custom_template.json)、host 侧算子注册与 Tiling 计算、kernel 侧 Ascend C 核函数实现(CopyIn -> Compute -> CopyOut 三段流水 + Double Buffer)、TensorFlow 框架适配插件,以及构建脚本与 ACLNN 测试用例。
主要改动
- 算子原型与 host 侧实现:
op_host/div_custom_template.cpp中注册DivCustomTemplate算子(输入x、y,输出z,支持 float16/float、ND 格式),实现InferShape(输出形状复制输入)、InferDataType(输出数据类型跟随输入)以及TilingFunc(计算总元素数写入size,设tileNum = 8并SetBlockDim(8)按 8 核均分)。 - Tiling 数据结构:
op_kernel/div_custom_template_tiling.h定义 host 与 kernel 共享的DivCustomTemplateTilingData结构体(size、tileNum两个字段),作为 host 侧 Tiling 与核函数间的数据传递载体。 - kernel 核函数实现:
op_kernel/div_custom_template.cpp中实现模板类KernelOp<T>,按tileNum × BUFFER_NUM = 16分片(每片 128 元素),通过inX/inY/outZ队列完成 CopyIn -> Compute -> CopyOut 三段流水,Compute 阶段用Div(z, x, y, tileLength)指令执行逐元素除法,入口函数为div_custom_template。 - 框架适配与原型定义:
framework/tf_plugin/tensorflow_div_custom_template_plugin.cc通过REGISTER_CUSTOM_OP("DivCustomTemplate")将算子注册到 GE(TensorFlow 框架);div_custom_template.json描述算子输入/输出原型(x、y、z,float16/float)。 - 构建与测试验证:
CMakePresets.json与build.sh配置编译目标(ascend910b、Release、打包安装);run.sh串联环境加载、算子工程生成、构建安装及测试编译执行;test/main.cpp通过aclnnDivCustomTemplateGetWorkspaceSize/aclnnDivCustomTemplate接口对{8, 2048}的 float16 张量(x=1.0, y=2.0)执行除法并校验输出为 0.5。


代码审查
关闭总结
各文件审查结果
| 文件 | 审查结论 |
|---|---|
custom_op/CMakeLists.txt |
no issues(标准 msopgen 顶层构建脚本,set(package_name ${vendor_name}) 依赖 preset 的 cache 变量,build.sh 固定走 preset,无实际缺陷) |
custom_op/CMakePresets.json |
no issues(标准配置;ASCEND_CANN_PACKAGE_PATH 为作者本机路径,属环境配置而非代码缺陷) |
custom_op/build.sh |
no issues([ "$cmake_version" \< "3.19.0" ] 为 bash test 内合法转义比较;opts 未加引号是刻意做词拆分) |
custom_op/framework/CMakeLists.txt |
no issues |
custom_op/framework/tf_plugin/CMakeLists.txt |
no issues |
custom_op/framework/tf_plugin/tensorflow_div_custom_template_plugin.cc |
no issues(标准 REGISTER_CUSTOM_OP 注册) |
custom_op/op_host/CMakeLists.txt |
no issues(file(GLOB ...) 用于生成文件是 msopgen 标准模式) |
custom_op/op_host/div_custom_template.cpp |
发现 2 个问题(int32 溢出;缺少可整除性校验) |
custom_op/op_kernel/CMakeLists.txt |
no issues |
custom_op/op_kernel/div_custom_template.cpp |
发现 1 个问题(整数除法截断静默丢尾块) |
custom_op/op_kernel/div_custom_template_tiling.h |
no issues(结构体字段与 host/kernel 读写一致,uint32_t 收窄风险已在 host 侧溢出问题中覆盖) |
div_custom_template.json |
no issues(key 拼写与 msopgen 规范一致) |
run.sh |
发现 1 个问题(ASCEND_TOOLKIT_HOME 可能未设置导致编译失败) |
test/CMakeLists.txt |
no issues |
test/main.cpp |
发现 1 个问题(tensors/deviceAddrs 保存 nullptr 副本导致资源清理空转) |
汇总
- P0: 0 个
- P1: 0 个
- P2: 2 个(kernel 静默丢尾块、host tiling 32 位溢出)
- P3: 2 个(测试资源泄漏、run.sh 环境变量脆弱性)
总体风险判断
该算子在 PR 自验证的精确测试形状(16384={8,2048},恰好被 8×2×8=128 整除)下可以正确运行,且 host/kernel 的 tiling 数据契约、双缓冲流水、ACLNN 接口调用链均一致。但作为对外暴露的通用逐元素除法算子,其 tiling 缺少可整除性校验与大尺寸溢出防护:任意非 128 整数倍的输入会静默丢失尾块(输出保持未初始化数据)、超大输入会因 int32_t 溢出导致设备端越界——这两项是 P2 级正确性/可靠性缺陷,建议在 TilingFunc 中补校验后合入。测试与脚本问题均为 P3 级,不影响当前用例通过,但会掩盖回归并降低可移植性。整体风险中等,合入前建议至少修复 P2 两项。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


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
⚠️ 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: luzx66, shaoyf, jxlang, li-shengxian3, gcw_tgPdOLZT) | ❌ (0/1)(You can also ask: li-shengxian3, luzx66, 王艳秋, 傅涛, jxlang) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
ftrghujhgf, thanks for your pull request. All authors of the commits have signed the CLA. 👍


🟡 Medium Priority


实现说明
基于 msopgen 生成的算子工程完成 DivCustomTemplate(z = x / y)工程化算子开发,通过 ACLNN 接口验证。
算子工程目录结构
custom_op/
实现思路
自验证
环境:CANN 9.0.0 / Ascend910B4,bash run.sh 输出 test pass
