Pull Request已成功合入, 合并人@CANN-robot
(感谢 dx 的贡献)变更摘要
此 PR 为 Catlass 框架新增了 TRMM(三角矩阵乘法)算子,实现 C = alpha * op(T) * B(左侧)或 C = alpha * A * op(T)(右侧)的计算,其中 T 为三角矩阵。核心包括一个双核(AIC/AIV)算子模板 TrmmTla、多套针对不同问题规模的 Tile/Swizzle 调度策略、JIT 编译支持、Torch 集成接口及完整的测试与示例程序。
主要改动
- 新增
TrmmTla核心算子模板:在include/catlass/gemm/kernel/trmm_tla.hpp中定义Catlass::Gemm::Kernel::TrmmTla类,实现 AIC 核上的 MMAD 分块计算与 AIV 核上的 alpha 缩放后处理,通过side/uplo/trans参数动态裁剪每个 tile 的有效 K 范围以跳过三角矩阵的零元区域。 - 新增按问题规模选择 Tile 变体的调度逻辑:在示例
trmm_tla.cpp和 JIT 调度层trmm_tla.cpp中实现SelectTileVariant函数,根据 side/uplo/trans 及 M/N 大小在 8 种TileVariant(含 default、small_right、small_left、K128、swizzle31 等)间选择不同的 L1/L0 tile shape 和GemmIdentityBlockSwizzle配置。 - 新增 JIT 编译支持:
tests/optest/kernels/74_trmm_tla/trmm_tla_impl.cpp通过宏CATLASS_JIT_TRMM_TILE_VARIANT与CATLASS_JIT_BLOCK_SCHEDULER在编译时确定 tile 形状和 block scheduler,配合tests/optest/kernels/74_trmm_tla/trmm_tla.cpp中的TrmmTLA函数完成 JIT kernel 的分发与启动。 - 新增 Torch 集成接口与 Python API:
tests/optest/torch_catlass/ops/trmm_tla.py提供trmm_tla()Python 函数;tests/optest/src/include/template/trmm_tla.h中的TrmmTlaLike模板完成张量校验、布局推导与算子调用;tests/optest/src/catlass_torch.cpp完成 Torch 函数注册。 - 新增示例程序与测试:
examples/74_trmm_tla/trmm_tla.cpp提供完整独立示例,支持 warmup/repeat 性能计时、采样验证与全量多线程 CPU golden 校验;tests/optest/tests/test_74_trmm_tla.py提供参数化 pytest 用例覆盖 left/right、lower/upper、transpose 及 alpha 组合。


代码审查
审查总结
审查了全部 15 个变更文件:
| 文件 | 审查结果 |
|---|---|
examples/74_trmm_tla/CMakeLists.txt |
无问题 |
examples/74_trmm_tla/README.md |
无问题 |
examples/74_trmm_tla/trmm_tla.cpp |
P0×1, P2×1, P3×3 |
examples/CMakeLists.txt |
无问题 |
include/catlass/gemm/kernel/trmm_tla.hpp |
无问题 |
tests/optest/include/catlass_kernel_jit.h |
无问题 |
tests/optest/kernels/74_trmm_tla/CMakeLists.txt |
无问题 |
tests/optest/kernels/74_trmm_tla/trmm_tla.cpp |
无问题 |
tests/optest/kernels/74_trmm_tla/trmm_tla_impl.cpp |
无问题 |
tests/optest/kernels/CMakeLists.txt |
无问题 |
tests/optest/src/catlass_torch.cpp |
无问题 |
tests/optest/src/include/template/trmm_tla.h |
无问题 |
tests/optest/tests/test_74_trmm_tla.py |
无问题 |
tests/optest/torch_catlass/ops/__init__.py |
无问题 |
tests/optest/torch_catlass/ops/trmm_tla.py |
无问题 |
按优先级汇总:
- P0: 1 个 —
TrmmTlaOptions类型未定义,示例将编译失败 - P1: 0 个
- P2: 1 个 —
CanImplement返回值被忽略,无效参数可能静默通过 - P3: 3 个 — 不可达死代码、误导性输出消息、
strtoul未检查errno
整体风险评估: 本 PR 的核心 kernel 实现 (include/catlass/gemm/kernel/trmm_tla.hpp)、JIT 编译路径、Python 绑定和测试代码均经过仔细审查,未发现正确性或安全性问题。但示例程序存在一个 P0 编译阻断问题(TrmmTlaOptions 未定义),必须在合入前修复。Kernel 侧的 Ascend C 并发同步(SetFlag/WaitFlag 配对、跨核 CrossCoreFlag 协议)、三角区域裁剪逻辑和整数溢出检查均通过审查,未发现缺陷。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 2 |
| 🟡 建议 | 1 |
⛔ 需要修改


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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/catlass | ✅ sunhao_hw, yuantao_ (2/2) | ✅ sunhao_hw (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
weixin_63557130, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


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.


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


Something went wrong during merge: git update-ref: exit status 128, stderr: "fatal: commit: cannot lock ref 'refs/heads/master': is at 688f0bfd66e71de570dda3ef3d1b5eab30aa8b9e but expected c6b0248b379a1fcfab355f854a860cca625cc413\n"
If you want to solve this problem, you can click here to do it in the FAQs.


描述
新增 examples/74_trmm 样例,支持 TRMM 参数解析、NPU 执行和 CPU golden 精度校验。
新增 TRMM kernel 封装,支持基于 CATLASS GEMM/TLA 组件完成三角矩阵乘计算。
新增 torch_catlass.trmm Python API 和 optest 用例。
支持 float32 输入输出。
支持 side = 0 / 1,覆盖 left-side 和 right-side TRMM。
支持 uplo = 0 / 1,覆盖下三角和上三角。
支持 trans = 0 / 1,覆盖不转置和转置。
支持 alpha 输出缩放。
关联的Issue
https://gitcode.com/cann/catlass/issues/331
原因
测试
optest 精度用例 test_74_trmm.py 通过,覆盖 16 个 TRMM 参数组合。
examples/74_trmm 指定 shape 自测通过,36/36 cases passed。
文档更新
类型标签