Skip to content

[Operator Mechanism]Add 64-bit strided BatchGEMM dispatch - #79697

Open
feixi139 wants to merge 2 commits into
PaddlePaddle:developfrom
feixi139:fix_batchgemm_int64t
Open

[Operator Mechanism]Add 64-bit strided BatchGEMM dispatch#79697
feixi139 wants to merge 2 commits into
PaddlePaddle:developfrom
feixi139:fix_batchgemm_int64t

Conversation

@feixi139

@feixi139 feixi139 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

当前 MatMulBatchedGEMM 的部分接口及实现仍会将 M/N/K/batchCount 收窄为 32 位整数,导致大于 INT_MAX 的维度无法使用 CUDA 12.3 提供的 64 位 cuBLAS 接口,部分路径还可能基于已截断的维度计算 leading dimension。

本 PR 主要包含以下改动:

  • MatMul 和 pointer-array BatchedGEMM 的维度参数调整为 int64_t,保证 MatMul 广播及 BLAS 调用链能够完整传递 64 位维度。
  • 为 CUDA BatchedGEMM、StridedBatchedGEMM 和 TRSM 补充 _64 动态加载符号及调用封装。当相关维度超过 INT_MAX 时,在 Linux CUDA 12.3 及以上环境分发到对应的 64 位 cuBLAS API;其他情况继续使用原有 32 位接口。
  • 在不支持 64 位 BLAS API 的 CPU/HIP 路径增加显式范围检查,避免静默整数截断;同时在分配 MatMul 输出内存前校验 pointer-array batch size。
  • 修复 CUDA/HIP 开启 FLAGS_gemm_use_half_precision_compute_type 时 FP16 alpha/beta 的类型不匹配问题,避免 BLAS 按 FP16 读取 float 标量而产生错误结果。
  • 将 FP16 accumulation 限制在 compute capability 7.0 及以上,并修正 FP16 64 位分发中的错误模板特化。
  • 移除因 ldc 不满足 cuBLAS 要求而无法覆盖目标 shape 的 N == 1 BatchedGEMM 快速路径,以及重复、不可达的维度检查。
  • 新增 C++ 单元测试,覆盖 MatMul/BatchedGEMMint64_t 接口以及 CPU 对不支持维度的异常处理。

是否引起精度变化

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paddle-Bot Review Board (review完成)

序号 位置 优先级 规则来源 状态
1 LIBXSMM 维度参数 P1 仓库规则:算子整数宽度与构建兼容性
Powered by Nyanpasu with gpt-5.6-sol 默认推理级别, please check the suggestions carefully.

template <typename T>
void Blas<CPUContext>::MatMul(
const int M, const int N, const int K, const T *A, const T *B, T *C) const {
int64_t M, int64_t N, int64_t K, const T *A, const T *B, T *C) const {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 PADDLE_WITH_LIBXSMM 构建会因维度指针类型不匹配而失败。这里将 M/N/K 改成 int64_t,但下方 CBlas<T>::SMM_GEMM 仍把 &N/&M/&K 传给 LIBXSMM 的 libxsmm_[sd]gemm;Paddle 固定版本的 LIBXSMM LP64 头文件声明这些参数为 const int*,因此启用 WITH_LIBXSMM=ON 时编译器会拒绝 int64_t*(最小原型复现同样报错)。请先用 detail::to_blas_int 转成独立的 int 局部变量,并保留范围检查,再传入 SMM。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在当前提交中将 M/N/K 通过 detail::to_blas_int 转为独立的 libxsmm_blasint 局部变量,并保留范围检查;LIBXSMM 路径的指针类型问题已修复。

@feixi139
feixi139 force-pushed the fix_batchgemm_int64t branch from a1808b5 to 8ed924a Compare August 29, 2026 15:44
@risemeup1111

risemeup1111 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Failed CI看板

流水线名称 问题标签 修复建议 日志片段
Check approval 检查器发现 2 个 approved errors 【无法判断】根据完整检查器输出定位 2 个错误的规则、文件和行号,修复新增 BLAS 代码违规或补充有效审批后重跑 报错代码
Slice / Slice test 性能基准回归 【与当前改动无关】先单独重跑该性能任务;若持续复现,再定位 Setitem/Slice 路径并校准基线 报错代码
日志分析报告

失败的测试 case:

1. Check approval
   步骤:检查 PR 变更。
   关键错误:There are 2 approved errors.
   进程:exit code 6。
   快照未提供两个错误的具体规则、文件或行号。

2. Slice / Slice test
   Case:Setitem - forward - Combined - Slice/Int/List (variant) - float16 - paddle
   性能变化:-0.10062443559662002,约下降 10.06%。
   关键错误:slice测试失败;run.py 抛出 Exception("slice测试失败"),进程 exit code 1。

根本原因分析:

  1. Check approval 的直接失败原因是检查器统计到 2 个 approved errors,而不是编译、单元测试或 CUDA 运行时错误。日志片段展示了新增 BLAS 代码上下文,包括 static_cast<int>to_blas_int,但没有给出具体违规位置,因此无法确认是否由本 PR 的某两处改动直接触发。当前应标记为【无法判断】。

  2. Slice / Slice test 是性能阈值失败。依赖安装成功,随后基准脚本明确报告一个 float16 Setitem/Slice case 下降约 10.06%,并主动抛出异常。PR diff 主要修改 cuBLAS、rocBLAS、CPU BLAS、MatMul 和 BatchedGEMM,没有修改 Slice 或 Setitem 实现,也没有快照证据证明该 case 调用了新增 64-bit BLAS 路径,因此与当前改动无直接关联,应标记为【与当前改动无关】。

  3. 两个 job 属于独立失败链路:一个是审批检查门禁,另一个是性能基准门禁。快照没有显示 CI 基础设施异常、依赖安装失败或 CUDA 错误。

修复建议:

  1. 【无法判断】Check approval:查看该 job 完整检查器输出,确认 2 个错误对应的规则和代码位置;若命中本 PR 新增 BLAS 改动则逐项修复,若属于可接受例外则按仓库流程重新审批,然后重跑该 job。
  2. 【与当前改动无关】Slice / Slice test:先重跑 Slice / Slice test 排除单次性能抖动;若仍稳定下降,再比较基线、多次测量和测试环境,定位 Setitem/Slice 性能变化,不应仅依据该结果修改 BLAS 代码。

Powered by Nyanpasu with gpt-5.6-luna 默认推理级别, please check the suggestions carefully.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@4306edd). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #79697   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         1           
  Lines              ?         8           
  Branches           ?         0           
===========================================
  Hits               ?         8           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants