Merged
TensorAPI添加自定义Op样例 #6174
TensorAPI添加自定义Op样例 #6174
Merged
ca1kwAdd on Sep 18
ca1kw
ca1kwCollaborators
Sep 18

描述

概述

这是一个基于 Tensor API 的固定 Shape QKV 投影样例(dav-3510,CANN >= 9.2.0),核心目的是演示如何自定义 Copy Operation 并接入 Tensor API 的 Atom 调用流程。

功能

output = reshape(input, [B * S, H]) * weight[H, 3H] + bias[3H]
  • 输入:fp16 三维 ND 张量 [16, 64, 256](Batch, Sequence, Hidden)
  • 输出:[1024, 768],Q/K/V 三个投影结果在最后一维连续排列(只做投影计算,不拆分 Q/K/V)
  • weight[H, 3H] 与 bias[3H] 在所有 Batch 之间共享

核心亮点:自定义拷贝算子 copy_slice_gm_to_l1

  • 通过特化 copy_traits 接入 Tensor API,可像内置 copy 一样用 make_copy / copy(atom, dst, src) 调用
  • 在 GM 到 L1 的搬运过程中一步完成 Batch/Sequence 维展平 + ND 到 NZ 的格式转换(标准 copy 需要两步)
  • 底层调用 3510 C API:asc_set_gm2l1_nz_para(NZ 目的布局参数打包)+ asc_copy_gm2l1_nd2nz

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for ca1kw's contribution.)
ca1kwca1kwCollaborators
Sep 18 Created pull request, commit a646558a
CANN-robotCANN-robotCollaborators
Sep 18 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 18 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
examples ✅ changxianyu, 苏建加 (2/2) ✅ changxianyu (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robotCollaborators
Sep 18 Comments:

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Sep 18 Set zengjuan,zhanghao_0689,suqwe,wulinyu,kong0808,dengjing_aoe,YeZZzzz1,bluesky901,yangbinhua,zhudi22,chenyiyuan,xun_zhuge,XuebinYang,sjtulxh,bianque,houyuyang,Lycheeeee,YANXI_ZHAO,chentianyu19,shi_nanxiang,wuyang_hw,jiangxinyu3,munanhw,ai_xin,ascendhjh,hujiawen_kaven,wangxiaozhi,DragonBornHD84,louyuxuan,changxianyu,hyolee,yukangchen as approver
99 messages are collapsed here。 See more
changxianyu
changxianyuCollaborators
Sep 22 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 22 Added label: approved
suqwe
suqweCollaborators
Sep 22 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 22 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 22 Merged pull request