Pull Request已成功合入, 合并人@CANN-robot
(感谢 sunduiyang 的贡献)变更摘要
本PR将 QuantBatchMatmulV4 伪量化 MXA8W4 算子从 CMCT 框架迁移到 blaze 框架,移除了所有 CMCT 相关 kernel 代码,新增基于 SWAT(自适应分块)算法的 tiling 求解器和 blaze kernel 实现;同时重构了 tiling 基类 QuantBatchMatmulV4TilingBase,将数据校验逻辑上移至基类以复用代码,并将 QuantBatchMatmulV4RegBase 子类独立为单独文件。
主要改动
-
CMCT 代码移除与 blaze kernel 新增:删除了
cmct/目录下的block_mmad_mx_weight_from_ub.h、block_scheduler_swizzle_in_mn_core_nn.h、block_prologue_b_cast_scsc_nn.h及cmct_convertor.h共四个 CMCT 组件文件;新增quant_batch_matmul_v4_weight_quant_mx_blaze.h,基于Blaze::Gemm组件(BlockMmad、BlockSchedulerMatmulSwatWithTailSplit、GemmUniversal)实现 MX 伪量化 kernel。 -
SWAT Tiling 算法替代 Cost Model:新增
WeightQuantMxSwatTilingSolver(.h+.cpp,约 700 行)实现自适应分块求解器,从 L0/L1/UB 容量约束出发计算baseM/baseN/baseK、tileShapeKL1、尾块拆分等 tiling 参数;新增QuantBatchMatmulV4WeightQuantMxSwatTilingtiling 策略类,其DoOpTiling先后尝试 2-buffer 和 4-buffer 求解,失败时回退到保守策略。 -
Tiling 基类重构以复用数据校验:将
CheckA8W4Params、CustomCheck、CheckCoreNum、GetTilingKey从子类QuantBatchMatmulV4RegBase上移至基类QuantBatchMatmulV4TilingBase;基类新增CheckTilingDataCapacity、SerializeTilingData通用方法替代原先各自实现的PostTiling序列化逻辑;QuantBatchMatmulV4RegBase拆分到独立的.h/.cpp文件中。 -
新增 SWAT 专用 Tiling 数据结构:在
quant_batch_matmul_v4_tiling_data_apt.h中新增QuantBatchMatmulV4WeightQuantMxSwatTilingData结构体(含baseM/baseN/baseK、tileShapeKL1、mTailTile/nTailTile、mBaseTailSplitCnt/nBaseTailSplitCnt等字段),并在 tiling key 中将 MX 场景的模板参数结构体从QuantBatchMatmulV4TilingDataParams切换为该新结构体。 -
算子注册分发调整:在
quant_batch_matmul_v4_tiling_registry.cpp中新增QuantBatchMatmulV4WeightQuantMxSwatTiling(优先级 7)和QuantBatchMatmulV4RegBase(优先级 1)两个 tiling 策略注册项;kernel 入口quant_batch_matmul_v4.cpp中 MX 分支从调用QuantBatchMatmulV4::InvokeKernel改为调用QuantBatchMatmulV4::Arch35::InvokeWeightQuantMxBlazeSwat。


代码审查
Closing Summary
已逐文件审查完毕,以下是所有变更文件的审查结论:
| 文件 | 审查结果 |
|---|---|
quant_batch_matmul_v4_reg_base_tiling.cpp |
无问题 |
quant_batch_matmul_v4_reg_base_tiling.h |
无问题 |
quant_batch_matmul_v4_tiling.cpp |
无问题 |
quant_batch_matmul_v4_tiling.h |
无问题 |
quant_batch_matmul_v4_weight_quant_mx_swat_tiling.cpp |
P2 ×1, P3 ×1 |
quant_batch_matmul_v4_weight_quant_mx_swat_tiling.h |
无问题 |
quant_batch_matmul_v4_weight_quant_mx_swat_tiling_solver.cpp |
无问题 |
quant_batch_matmul_v4_weight_quant_mx_swat_tiling_solver.h |
无问题 |
quant_batch_matmul_v4_tiling_registry.cpp |
无问题 |
quant_batch_matmul_v4.cpp (kernel) |
无问题 |
quant_batch_matmul_v4_tiling_data_apt.h |
无问题 |
quant_batch_matmul_v4_tiling_key.h |
无问题 |
quant_batch_matmul_v4_weight_quant_mx_blaze.h |
无问题 |
test_quant_batch_matmul_v4_tiling.cpp |
无问题 |
test_quant_batch_matmul_v4_tiling.csv |
无问题 |
发现问题汇总:
- P2: 1 个(SWAT tiling workspace 乘法溢出风险)
- P3: 1 个(日志函数返回值冗余建议)
整体风险判断: 低。核心逻辑迁移(CMCT→blaze、cost model tiling→SWAT tiling)结构清晰,数据校验被合理上移到基类复用。唯一的 P2 问题在极端 shape 下才可能触发,修复简单。建议在合入前修复 workspace 溢出问题。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 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 |
|---|---|---|
| cmake | ✅ 刘波, 商晓波 (2/2) | ✅ 刘波, 商晓波 (2/1) |
| matmul | ✅ 徐炳麟, 刘波, 刘泱, 商晓波 (4/2) | ✅ 刘泱, 商晓波 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
sunduiyang, thanks for your pull request. All authors of the commits have signed the CLA. 👍


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


描述
本PR完成了QuantBatchMatmulV4伪量化MXA8W4算子从CMCT迁移到blaze框架的实现,并移除了cmct相关代码,同时对kernel性能进行了优化,主要改动如下:
关联的Issue
#4352
测试
本地tiling UT验证,白盒、泛化、二级冒烟验证通过。
文档更新
不涉及
类型标签
AI/Agent生成声明