Skip to content

[cublas] Implement dgmm_batch backend - #756

Open
zjin-lcf wants to merge 3 commits into
uxlfoundation:developfrom
zjin-lcf:feature/cublas-dgmm-batch
Open

[cublas] Implement dgmm_batch backend#756
zjin-lcf wants to merge 3 commits into
uxlfoundation:developfrom
zjin-lcf:feature/cublas-dgmm-batch

Conversation

@zjin-lcf

Copy link
Copy Markdown
Contributor

Summary

dgmm_batch was unimplemented (threw unimplemented) in the cuBLAS backend. As noted in #562, cuBLAS provides only the non-batched cublas<t>dgmm — there is no strided/batched dgmm in any CUDA library (verified across cuBLAS, cuBLASLt, cuBLASXt, cuSPARSE headers; only cublasSdgmm/Ddgmm/Cdgmm/Zdgmm and their _64 twins exist). This PR implements dgmm_batch for the cuBLAS backend by looping over cublas<t>dgmm.

  • Implements column-major buffer strided, USM strided, and USM group dgmm_batch
  • Types: float, double, complex<float>, complex<double>
  • Row-major maps to column-major by flipping side and swapping m/n (same approach as the rocBLAS backend)
  • Handles negative incx via the standard BLAS start-at-end convention

Tests

Extends the shared dgmm_batch tests for stronger coverage:

  • strided (buffer + USM): adds incx = 3 and incx = -1 cases
  • group (USM): adds group_count = 1 and group_count = 10 cases

Test plan

Verified on an NVIDIA RTX PRO 6000 Blackwell (sm_120), CUDA 13.3 / cuBLAS 13.6, DPC++:

  • test_main_blas_ct --gtest_filter=*Dgmm* → all pass (col/row major, all 4 types)
  • test_main_blas_rt --gtest_filter=*Dgmm* → all pass
  • Covers DgmmBatchStride, DgmmBatchStrideUsm, DgmmBatchUsm (group API)

Closes #562.

cuBLAS exposes only the non-batched cublas<t>dgmm (no strided/batched
variant exists in any CUDA library), so the cuBLAS backend previously
threw unimplemented for all dgmm_batch entry points (issue uxlfoundation#599 -> uxlfoundation#562).

Implement dgmm_batch for the cuBLAS backend by looping over cublas<t>dgmm:
- Buffer strided, USM strided, and USM group APIs
- float, double, complex<float>, complex<double>
- Row-major handled by flipping the side and swapping m/n, then delegating
  to the column-major implementation (matches the rocBLAS backend)

Also extend the shared dgmm_batch tests with additional incx values
(3 and -1) and group_count values (1 and 10) for more rigorous coverage.

Verified on an NVIDIA RTX PRO 6000 Blackwell (sm_120), CUDA 13.3 /
cuBLAS 13.6: all DgmmBatch{,Stride}{,Usm} tests pass (col/row major,
all four types, run-time and compile-time dispatch).

Co-authored-by: Cursor <cursoragent@cursor.com>
@zjin-lcf
zjin-lcf requested a review from a team as a code owner August 11, 2026 14:41
zjin-lcf and others added 2 commits August 11, 2026 14:53
Switch dgmm_batch to the cublas<t>dgmm_64 entry points and pass
int64_t m/n/lda/incx/ldc directly (no int casts), and drop the 32-bit
overflow_check so dimensions beyond 2^31 are supported.

Co-authored-by: Cursor <cursoragent@cursor.com>
Switch dgmm_batch (strided buffer, strided USM, and grouped USM) to the
ILP64 (_64) rocBLAS entry points and drop the overflow_check calls that
capped dimensions below 2^31. Dimensions are now passed straight through
as int64_t, matching the cuBLAS backend change.

Verified on AMD Instinct MI300A (gfx942): all 24 dgmm_batch CT and RT
tests pass.

Co-authored-by: Cursor <cursoragent@cursor.com>

@sknepper sknepper 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.

Thanks for the cublas implementation, as well as a nice fix for rocBLAS! One concern I had about writing over an input parameter. Please also check the clang-format check results and adjust the formatting as needed.

int64_t* ldc, int64_t group_count, int64_t* groupsize, \
const std::vector<sycl::event>& dependencies) { \
for (int64_t i = 0; i < group_count; i++) \
left_right[i] = dgmm_flip_side(left_right[i]); \

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.

I'm not sure if this is allowed by the spec. Per https://github.com/uxlfoundation/oneMath/blob/develop/docs/spec/domains/blas/dgmm_batch.rst , left_right is an input parameter, and so shouldn't be modified.

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.

oneMKL only has dgmm_batch variant: doesn't map to cublas

2 participants