已合并
新增 Challenge09:CATLASS DSL MatmulAddRelu 算子练习题 #4197
新增 Challenge09:CATLASS DSL MatmulAddRelu 算子练习题 #4197
已合并
悠悠的云朵创建于 29 天前
悠悠的云朵
29 天前

当前PR是否有AI参与:

[x] 否

[ ] 是
__1. AI Agent 平台:
__2. AI 模型:
__3. Prompt上下文 :

PR功能描述 / 为什么需要这个合入**:

新增固定 256×256×256 的 MatmulAddRelu 题目,提供包含五处待补全代码的核函数模板、验证脚本,以及环境准备和提交说明。保留 PR_code/ 目录供学员提交答案。

该PR关联的issue

(格式为fixes #<issue号>, 或者resolves #<issue号>): fixes #

希望检视人员了解:

改动类型 / Change Type

测试信息 / Testing

检查清单 / Checklist

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 悠悠的云朵 的贡献)
悠悠的云朵悠悠的云朵
29 天前 创建了 pull request,commit 711953f6
atomgit-bot
atomgit-bot
29 天前 评论:

变更摘要

本 PR 新增 Challenge09-MatmulAddRelu 练习题,面向 CATLASS DSL,提供固定 256×256×256 的融合算子 MatmulAddRelu(即 A @ B + X 后取 ReLU)的核函数模板与验证脚本。模板 matmul_add_relu.py 给出了基于 tla 的 Cube/Vector 双流水骨架、多级存储分配与同步 flag 链路,并在关键位置留出五处 TODO 供学员补全;test_matmul_add_relu.py 提供在 Ascend 设备上编译执行并做容差校验的测试入口。按 PR 描述,还保留了 PR_code/ 目录供提交答案并附带环境准备与提交说明。

主要改动

  • 核函数模板与固定尺寸常量: 新增 matmul_add_relu_kernel,定义 M = N = K = 256、L0_K = 64、AIV_M、X_CHUNK_M、SIMD_LANES 等常量,约定该题固定为 256 规模的矩阵乘加 ReLU 融合。
  • 多级存储分配与 flag 同步链路: 通过 tla.allocate 分配 L1、L0A、L0B、L0C 及 UB(ub_acc_ptr、ub_x_ptr),并用 tla.flag / tla.cross_flag(如 l1_ready、l0_ready、mmad_done、fix_done、x_ready、y_ready 等)组织 MTE1/MTE2/MTE3、Cube、Vector 之间的异步读写顺序。
  • 五处待补全 TODO: 模板在 GM→L1 搬运、L1→L0 搬运、tla.mmad 矩阵乘累加(含 init_c 分片累加)、L0C→UB 搬运(CopyL0C2DstParams 的 l0c2ub_mode = SPLIT_M)以及 Vector 的 tla.add + tla.max 加 ReLU 处各留一个 TODO 供学员实现。
  • 验证脚本: 新增 test_matmul_add_relu.py,提供 --device 参数校验,使用 torch / torch_npu 构造随机输入与参考结果,经 from_dlpack 包装后调用 tla.compile(--npu-arch 3510)编译并执行,最后按容差比较并输出 PASS/FAIL。
likedislike
不准确?
CANN-robot
CANN-robot成员
29 天前 评论:

Hi @weixin_42818618, 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
29 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
29 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
29 天前 评论:

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
repo-cann/cann-outreach ✅ shaoyf, 傅涛 (2/2) ✅ shaoyf, 傅涛 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
悠悠的云朵悠悠的云朵
29 天前 预合并成功(commit_id: 31ad7e3186463739a3696ee987083e0bea17bc01)
悠悠的云朵悠悠的云朵
29 天前 推送  1 个提交:4e1ed100-补充文档
悠悠的云朵悠悠的云朵
29 天前 预合并成功(commit_id: c1ca1764f26ae1d8ab76e2e6104b2e5245e8611e)
CANN-robotCANN-robot成员
29 天前 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
29 天前 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
29 天前 添加了label:cann-cla/yes
shaoyf成员25 天前进行代码检视2
2026/CANN-Code-Detective/Challenge09-MatmulAddRelu/README.md
已过期
@@ -0,0 +46,10 @@
46+## 环境准备
47+ 
48+| 类别 | 需要的组件 |
49+| :--- | :--- |
50+| 硬件与系统 | Ascend 950 系列 NPU、配套驱动和固件,以及 CANN 支持的 Linux(`x86_64` 或 `aarch64`) |
51+| CANN | CANN 9.1.0 或更高版本 |
52+| Python | Python 3.10~3.13、`pip` |
53+| CATLASS Python 包 | `ascend-catlass-dsl==2.1.0`;其依赖的 `numpy>=1.24,<3` 会由 `pip` 自动安装 |
54+| 验证 Python 包 | `torch`、`torch-npu`(导入名为 `torch_npu`)和 `PyYAML`(导入名为 `yaml`);前两者须相互匹配并与 CANN 版本匹配 |
55+ 
56+[PyPI 已发布 CATLASS DSL v2.1.0 wheel](https://pypi.org/project/ascend-catlass-dsl/2.1.0/)。以下以 CANN 9.1.0 为例,安装配套的 PyTorch 2.9.0 和 `torch-npu 2.9.0.post6`;其他 CANN 版本请按[昇腾 PyTorch 版本配套表](https://gitcode.com/Ascend/pytorch/blob/master/docs/zh/release_notes.md)调整。先加载 CANN 环境;如果 CANN 不在示例路径,请改成实际的 `set_env.sh` 路径:
shaoyf25 天前评论:

此条代码评论区间+46至+69

硬件设备考虑加上一个在线环境的使用牵引,比如加入如下描述:

开发者可以申请使用公共在线环境进行开发,包括:

HiDevLab:云环境容器方式使用,有 950/A2 算力,当前使用资源需要申请,申请时需说明使用背景,申请通过后可获得 100 小时资源。
地址:HiDevLab
使用指导:HiDevLab

likedislike
System
系统消息系统
24 天前 评论:

changed this line on 1ba82439 view diff detail

悠悠的云朵悠悠的云朵
24 天前 预合并成功(commit_id: 7e3106d51acff712031ffdea50f7967212d5b83d)
此处折叠了18条事件消息 查看更多
CANN-robotCANN-robot成员
24 天前 添加了label:cann-cla/yes
shaoyf成员
24 天前 评论:

/approve
/lgtm

likedislike
fulltower成员
24 天前 评论:

/approve
/lgtm

likedislike
fulltower成员
24 天前 评论:

/check-pr

likedislike
CANN-robotCANN-robot成员
24 天前 添加了label:lgtmapproved
CANN-robot
CANN-robot成员
24 天前 评论:

The following labels are not ready.

lgtm: Please wait for committers to review the code.

approved: Please wait for committers to review the code.

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

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
Ffulltower成员
24 天前 解决了最后一个问题
fulltower成员
24 天前 评论:

/check-pr

likedislike
CANN-robotCANN-robot成员
24 天前 合入了pull request