Skip to content

Fix isblasmatrix for GPU StridedViews - #96

Merged
kshyatt merged 7 commits into
mainfrom
ksh/gpu_ibm
Nov 2, 2026
Merged

kshyatt merged 7 commits into
mainfrom
ksh/gpu_ibm

Conversation

@kshyatt

@kshyatt kshyatt commented Oct 29, 2026

Copy link
Copy Markdown
Member

I think our original approach here was wrong, because we can use the BLAS methods as long as the view that's passed is densely packed. So right now we aren't using BLAS where we could (a dense patch of a higher dimensional tensor, for example) and we are trying to use it in dangerous places. Hopefully this fixes both.

@kshyatt
kshyatt requested a review from lkdvos October 29, 2026 13:26

@lkdvos lkdvos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch!

Comment thread ext/StridedGPUArraysExt.jl Resolved
@kshyatt

kshyatt commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

I got a little carried away here. I think we can get rid of the vendor specific extensions and just use LinearAlgebra.mul! which should dispatch to the vendor BLAS if it's available or fall back to GPUArrays' implementation if not.

@Jutho

Jutho commented Oct 29, 2026

Copy link
Copy Markdown
Member

Why is this packed columns (essentially: contiguous data) necessary. I thought gemm supports this via the "leading dimension" argument?

@kshyatt

kshyatt commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

The vendor gemms only support matrices whose first dimension (so rows for operation == N, cols for operation == T or C) has stride 1, right? It's the second dimension that can have lda > m.

@lkdvos

lkdvos commented Oct 30, 2026

Copy link
Copy Markdown
Member

It's the second dimension that can have lda > m

But doesn't that mean precisely that stride(A, 2) != size(A, 1) is allowed?

@kshyatt

kshyatt commented Oct 30, 2026 •

Copy link
Copy Markdown
Member Author

But doesn't that mean precisely that stride(A, 2) != size(A, 1) is allowed?

Only if stride(A, 2) / size(A, 1) is an integer, right? I'll add that as a looser check, good catch.

In fact this turned out not to be right, the issue is also that my _densematrix was discarding the stride, I think we can widen this a little bit to support both dense patches as well as things with stride(A, 2) > size(A, 1)

Comment thread ext/StridedGPUArraysExt.jl Resolved
Comment thread ext/StridedGPUArraysExt.jl Resolved
Comment thread ext/StridedGPUArraysExt.jl Resolved
lkdvos
lkdvos previously approved these changes Oct 30, 2026
Comment thread src/linalg.jl Resolved
Comment thread ext/StridedGPUArraysExt.jl Outdated
Comment on lines 164 to 179
function _densematrix(A::GPUStridedView{T, 2}) where {T}
A2, CA = Strided.getblasmatrix(A)
m, n = size(A2)
lda = max(stride(A2, 2), m, 1)
M = view(GPUArrays.derive(T, parent(A2), (lda, n), A2.offset), 1:m, 1:n)
return CA == 'N' ? M : CA == 'T' ? transpose(M) : adjoint(M)
end

function Strided.blas_mul!(
C::GPUStridedView{T, 2}, A::GPUStridedView{T, 2}, B::GPUStridedView{T, 2},
α::Number, β::Number
) where {T <: LinearAlgebra.BlasFloat}
isempty(C) && return C
LinearAlgebra.mul!(_densematrix(C), _densematrix(A), _densematrix(B), convert(T, α), convert(T, β))
return C
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this still need updating to be similar to cuBLAS?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This one is only reached by Metal (or JLArrays) right now I believe? I'm a bit unclear what this comment is asking, sorry!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, what I meant is that the code looks somewhat different here in comparison to the cuBLAS extension, with different auxiliary function names as well, do we want to uniformize this or is it on purpose?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Let me see if I can't get everyone to share these...

Comment thread ext/StridedcuBLASExt.jl Resolved
@lkdvos
lkdvos dismissed their stale review October 30, 2026 19:23

accidentally did this

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ext/StridedAMDGPUExt.jl 100.00% <100.00%> (+75.00%) ⬆️
ext/StridedGPUArraysExt.jl 94.18% <100.00%> (+1.78%) ⬆️
ext/StridedcuBLASExt.jl 100.00% <100.00%> (+100.00%) ⬆️
src/linalg.jl 97.08% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread ext/StridedcuBLASExt.jl Resolved
Co-authored-by: Lukas Devos <ldevos98@gmail.com>
@kshyatt
kshyatt merged commit 5f4d292 into main Nov 2, 2026
15 of 19 checks passed
@kshyatt
kshyatt deleted the ksh/gpu_ibm branch November 2, 2026 18:59
@lkdvos lkdvos mentioned this pull request Nov 3, 2026
lkdvos referenced this pull request Nov 3, 2026
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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