合并受阻
变更摘要
本 PR 在 PR_code/xhf_A2_1/ 目录下新增了 Challenge 09 的 MatmulAddRelu 融合算子实现与自验证脚本。matmul_add_relu.py 基于 catlass.tla 描述固定 256×256×256 的 Matmul、Add、ReLU 数据流,通过多级缓冲、mutex 同步与 Cube/Vector 双流水实现多核切分与计算;test_matmul_add_relu.py 构造随机输入,调用 tla.compile 并执行核函数,与 PyTorch 参考结果对比完成验证。
主要改动
- 融合算子骨架与常量定义: 新增
matmul_add_relu_kernel,固定M=N=K=256,定义L0_K=64、AIV_M=M//2、X_CHUNK_M=64、SIMD_LANES=64,并通过tla.allocate在l1、l0a、l0b、l0c、ub上分配 A/B/累加/输入缓冲。 - Cube 端多级搬运与矩阵乘累加: 在
tla.cube()中完成 GM→L1 的tla.copy、按k_tile的 L1→L0 搬运,并用tla.mmad(l0_c, l0_a, l0_b, init_c=(k_tile == 0))将 FP16 乘积累加到 L0C 的 FP32 结果,mutex_l1/mutex_l0/mutex_l0c管理各 Pipe 访问顺序。 - L0C→UB 拆分与跨核同步: 使用带
tla.params.CopyL0C2DstParams(l0c2ub_mode=SPLIT_M)的tla.copy将完整累加结果分片到两个 AIV 的 UB,并通过tla.cross_core_set_flag/tla.cross_core_wait_flag(fix_done)实现 Cube 到 Vector 的跨核通知。 - Vector 端 Add + ReLU 计算与写回: 在
tla.vector()中按aiv_id和chunk切分数据,使用tla.vec.func(mode="simd")对每行按SIMD_LANES切向量,执行tla.max(tla.add(acc_reg.load(), x_reg.load()), 0.0)原位写回,再由tla.copy输出到gm_y。 - 新增自验证测试脚本:
test_matmul_add_relu.py支持--device参数并延迟导入catlass.tla、torch、torch_npu,构造 A/B/X 输入与torch.relu(a @ b + x)参考值,经tla.compile(..., options="--npu-arch 3510")编译后执行,按容差校验并打印 PASS/FAIL。
说明:我按要求对代码进行了只读分析,并尝试运行 ast-grep、grep、read_file 等工具辅助理解,但所有调用均因当前环境限制未能实际返回结果;以上总结完全基于 PR 标题、描述、改动文件列表及内嵌补丁内容,未对文件做额外探查。


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


AI Declaration Check Failed
@xhf_A2_1, AI declaration is not compliant. AI tool: OpenAI Codex
Please check:
- The AI tool and model declared in the PR description must be real.
- Commit messages must include the AI model, and it must be consistent with the PR description. ⚠️


当前PR是否有AI参与:
__1. AI Agent 平台: OpenAI Codex
__2. AI 模型: GPT-5
__3. Prompt上下文: 协助分析 Challenge 09 任务、补全 TODO、准备验证脚本,并在本人 HiDevLab Ascend 950 环境执行实机验证。
PR功能描述 / 为什么需要这个合入
完成 Challenge 09 MatmulAddRelu 融合算子:
关联活动 Issue
https://gitcode.com/cann/cann-learning-hub/issues/777
希望检视人员了解
已在本人 HiDevLab Ascend950PR_9579 真机环境验证通过。
改动类型 / Change Type
测试信息 / Testing
环境:CANN 9.1.0,CATLASS 2.1.0
芯片:Ascend950PR_9579
torch:2.9.0+cpu
torch_npu:2.9.0.post6
命令:python PR_code/xhf_A2_1/test_matmul_add_relu.py --device 0
结果:PASS: M=N=K=256, blocks=1
退出状态:0
检查清单 / Checklist