已开启
【代码侦探Challenge04-DivCustomTemplate】新增DivCustomTemplate工程化算子开发实现 #2154
【代码侦探Challenge04-DivCustomTemplate】新增DivCustomTemplate工程化算子开发实现 #2154
已开启
luoxiaoyan2024创建于 5 天前
5 天前

变更描述 / Description

本PR实现Challenge04-DivCustomTemplate工程化算子开发任务,完成矢量除法算子 z = x / y 的工程化开发。

实现内容

  1. msopgen生成算子工程msopgen gen -c ai_core-ascend910a(SoC型号Ascend910PremiumA)

  2. op_kernel核函数 (op_kernel/div_custom_template.cpp):

    • GlobalTensor/LocalTensor/TQue管理数据,双缓冲(BUFFER_NUM=2)
    • DataCopy搬运,Div计算 z = x / y
    • CopyIn→Compute→CopyOut编程范式
    • 支持任意shape:tile循环 + 尾块处理,最后一个block处理余数
  3. op_host tiling逻辑

    • 使用int64_t计算元素总数,避免溢出
    • SetBlockDim(8),InferShape/InferDataType与输入一致
    • dtype声明与kernel实例化保持一致(仅float16)
  4. ACLNN验证aclnnDivCustomTemplate,x=1.0, y=2.0, z=0.5,test pass

改动类型 / Change Type

  • References #549

测试信息 / Testing

result is:
0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
test pass

检查清单 / Checklist

likedislike
合并受阻
Lluoxiaoyan2024
5 天前 创建了 pull request,commit 5acfb8c2
atomgit-bot
atomgit-bot
5 天前 评论:

变更摘要

本 PR 实现 Challenge04-DivCustomTemplate 工程化算子开发任务,新增矢量除法算子 DivCustomTemplate(计算 z = x / y,仅支持 float16),通过 msopgen 生成算子工程,完整覆盖 op_host tiling、op_kernel 核函数与 ACLNN 单测验证流程。

主要改动

  • 核函数实现:新增 op_kernel/div_custom_template.cpp,定义 KernelDiv 模板类,采用 GlobalTensor/LocalTensor/TQue 与双缓冲(BUFFER_NUM=2)管理数据,按 CopyIn→Compute→CopyOut 范式用 DataCopy 搬运、Div 指令计算;通过 tile 循环(TILE_LENGTH=2048)加尾块处理支持任意 shape,最后一个 block 负责处理余数
  • Host tiling 逻辑:新增 op_host/div_custom_template.cppTilingFuncint64_t 计算元素总数避免溢出并写入 tiling 数据,SetBlockDim(8) 设置 8 个核;InferShape/InferDataType 使输出 shape 与数据类型与输入一致
  • Tiling 数据结构:新增 op_host/div_custom_template_tiling.h,通过 BEGIN_TILING_DATA_DEF 定义 DivCustomTemplateTilingData,包含 size(uint32_t)字段并注册 tiling 数据类
  • 算子定义文件:新增 div_custom_template.json,声明 xy 两个 required 输入与 z 输出,均为 float16ND 格式
  • 工程化构建与验证:新增 run.sh 自动化脚本(加载 CANN 环境、msopgen gen 生成工程、编译安装算子、编译并运行测试)与 test/main.cpp ACLNN 测试用例,通过 aclnnDivCustomTemplate 验证 1.0 / 2.0 = 0.5 并输出 test pass
likedislike
atomgit-bot
atomgit-bot
5 天前 评论:

代码审查

✅ 未发现问题

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

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, 田晓亮, luzx66, shaoyf, 王艳秋) ❌ (0/1)(You can also ask: luzx66, 傅涛, jxlang, gcw_tgPdOLZT, 田晓亮)

💡 Tip:

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

CLA Signature Pass

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

likedislike
Lluoxiaoyan2024
5 天前 update merge request[project id: 9865789, iid: 2154, commit_id: b6013e71e17ee5220b6f4b8f2beedeb101676d09] virtual merging success
Lluoxiaoyan2024
5 天前 强制推送  1 个提交:ba437de0-[Challenge04-DivCustomTemplate] 新增DivCustomTemplate工程化算子开发实现\n\n- 使用msopgen生成算子工程(ai_core-ascend910a,适配Ascend910硬件)\n- 实现op_kernel核函数:使用GlobalTensor/LocalTensor/TQue管理数据,DataCopy搬运,Div计算z=x/y,tile循环+尾块处理支持任意shape\n- 实现op_host tiling逻辑:int64_t计算元素总数避免溢出,SetBlockDim(8),dtype声明与kernel一致(仅float16)\n- 通过ACLNN接口验证test pass(x=1.0, y=2.0, z=0.5)\n\nCo-authored-by: luoxiaoyan2024
Lluoxiaoyan2024
5 天前 update merge request[project id: 9865789, iid: 2154, commit_id: 544ae0a8369cb8b180779487ca2d69f219edf233] virtual merging success
CANN-robotCANN-robot成员
5 天前 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
5 天前 删除了label:stat/needs-squash
CANN-robot
CANN-robot成员
5 天前 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): stat/needs-squash.

likedislike
CANN-robotCANN-robot成员
5 天前 添加了label:cann-cla/yes