Merged
add tensor api examples #6163
li-yuanjie-daAdd on Sep 17
add tensor api examples #6163
Merged
li-yuanjie-daAdd on Sep 17
li-yuanjie-da
li-yuanjie-daCollaborators
Sep 17

描述

新增tensor api样例

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for li-yuanjie-da's contribution.)
li-yuanjie-dali-yuanjie-daCollaborators
Sep 17 Created pull request, commit 36c1e5fa
atomgit-bot
atomgit-bot
Sep 17 Comments:

变更摘要

本 PR 为 SIMD C++ 示例集新增 Tensor API 的使用样例,目录位于 examples/01_simd_cpp_api/07_tensor_api/matmul_split_k/。样例以 Split-K 方式实现 half 输入的矩阵乘:将 K 维切分为 SPLIT_K 份,由多个 Cube 核各自计算一个 K 切片并通过原子累加写入同一输出矩阵。配套提供了数据读写工具、输入/金标准数据生成脚本以及结果校验脚本,形成从造数、执行到验证的完整示例闭环。

主要改动

  • 新增 Split-K 矩阵乘 Kernel: matmul_split_k.asc 中定义 matmul_split_k_kernel,通过 block_idx 确定 K 切片偏移,使用 make_tensor、make_frame_layout、slice 构建 GM/L1/L0 各级张量视图。
  • 引入 Tensor API 的拷贝与矩阵乘接口: 样例使用 make_copy 搭配 copy_gm_to_l1、copy_l1_to_l0a、copy_l1_to_l0b、copy_l0c_to_gm 完成数据搬运,并用 make_mmad 与 mmad_params 完成 L0 上的矩阵乘计算。
  • 新增原子累加输出流程: 通过 asc_set_atomic_add_float() 与 asc_disable_dma_atomic() 实现多核向同一 gmC 的累加写入,主机侧在启动前用 aclrtMemset 将输出清零。
  • 新增数据读写工具: data_utils.h 提供 ReadFile/WriteFile,对输入文件的存在性、是否为普通文件及大小进行校验,并在失败时输出错误信息。
  • 新增造数与校验脚本: scripts/gen_data.py 以固定随机种子生成输入与 golden.bin,scripts/verify_result.py 按相对/绝对容差比较输出与金标准并报告最大绝对误差或首个不匹配位置。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 17 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 17 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 17 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 ✅ 诸葛洵, hyolee (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

li-yuanjie-da, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
206 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 24 Added label: ci-pipeline-passed
hyolee
hyoleeCollaborators
Sep 24 Comments:

/lgtm

likedislike
zhugexun_sjtu
zhugexun_sjtuCollaborators
Sep 24 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 24 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Sep 24 Merged pull request