已合并
新增trmm #845
新增trmm #845
已合并
dx创建于 7月10日
dx
dx成员
7月10日

描述

新增 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。

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 dx 的贡献)
atomgit-bot
atomgit-bot
7月10日 评论:

变更摘要

此 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 组合。
likedislike
不准确?
atomgit-bot
atomgit-bot
7月10日 评论:

代码审查


审查总结

审查了全部 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

⛔ 需要修改

likedislike
不准确?
CANN-robotCANN-robot成员
7月10日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7月10日 评论:

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 /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
dx
dx成员
7月10日 评论:

compile

likedislike
此处折叠了162条消息 查看更多
CANN-robot
CANN-robot成员
7月25日 评论:

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
Ssunhao_hw成员
7月26日 解决了最后一个问题
CANN-robotCANN-robot成员
7月26日 合入了pull request
CANN-robot
CANN-robot成员
7月26日 评论:

Pull Request 已合并或已关闭。

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

likedislike
CANN-robot
CANN-robot成员
7月26日 评论:

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.

likedislike