Skip to content

Offload duplicated BLAS logic to GPUArrays - #1229

Open
kshyatt wants to merge 13 commits into
JuliaGPU:mainfrom
kshyatt:ksh/blas-hooks
Open

kshyatt wants to merge 13 commits into
JuliaGPU:mainfrom
kshyatt:ksh/blas-hooks

Conversation

@kshyatt

@kshyatt kshyatt commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Implements GPUArrays' BLAS hooks (JuliaGPU/GPUArrays.jl#852) with rocBLAS, and removes the LinearAlgebra methods that duplicated GPUArrays' dispatch: matrix and matrix-vector products, triangular multiplication and division, syrk/herk, geam, dgmm, and the BLAS 1 functions. GPUArrays now decides which calls reach rocBLAS, with generic kernels for the rest, as with CUDA.jl (JuliaGPU/CUDA.jl#3626) and oneAPI.jl (JuliaGPU/oneAPI.jl#779).

Requires GPUArrays 12.4, which implements dot for every wrapped GPU array, so the dot methods for Symmetric and Hermitian matrices are gone too. test/hip_rocarray/blas_edge_cases.jl tests the cases the old methods handled: triangular operations on strided views, false as a strong zero, Diagonal norms, and dot of wrapped arrays and strided views.

@luraess

luraess commented Nov 20, 2026

Copy link
Copy Markdown
Member

Do we need the additional BLAS stuff here JuliaGPU/GPUArrays.jl#852 (comment) ?

Katharine Hyatt and others added 5 commits November 25, 2026 09:38
… operations

GPUArrays 12.3 implements the dispatch from LinearAlgebra's storage-level
`mul!` and triangular methods to BLAS routines, and calls hooks that
back-ends implement with their library. Replace our copy of that dispatch
with methods for those hooks. Float16 and BFloat16 products still use
gemm_ex!.

The triangular-triangular product now zeroes a triangle on a copy of its
operand, instead of on the caller's matrix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013b7DCbTAjtfi3JqXU4xZmW
GPUArrays now implements the BLAS 1 operations, the Diagonal and
triangular-triangular products, and matrix addition with a transposed
operand, calling hooks for the BLAS routines. Implement those with rocBLAS,
and drop our copies of the rest. rocBLAS' nrm2 doesn't rescale, so norm
keeps using GPUArrays' implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013b7DCbTAjtfi3JqXU4xZmW
…l edge cases

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013b7DCbTAjtfi3JqXU4xZmW
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013b7DCbTAjtfi3JqXU4xZmW
@kshyatt
kshyatt marked this pull request as ready for review December 2, 2026 09:21
@kshyatt

kshyatt commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

@luraess with the latest GPUArrays release I think this is ready for review

@luraess luraess changed the title [WIP] Offload duplicated BLAS logic to GPUArrays Offload duplicated BLAS logic to GPUArrays Dec 2, 2026
@luraess

luraess commented Dec 2, 2026

Copy link
Copy Markdown
Member

Thanks, this is a nice!

A few things we may want to tweak (upon suggestions from the robot):

  1. blas_nrm2 isn't implemented, so norm(x) moves from rocBLAS nrm2 to GPUArrays' generic norm. Is that on purpose? GPUArrays' norm tests include floatmax/2, floatmin*2 and subnormal inputs at p = 2, and I don't know whether rocBLAS' nrm2 rescales for those. If it's deliberate, a one-line comment next to the other BLAS 1 hooks would stop someone from adding it back later. It also makes norm(x) and norm(x, 2) take the same path, which they didn't on main.
  2. test/runtests.jl only skips hip_rocarray/blas when rocBLAS isn't functional. The new hip_rocarray/blas_edge_cases should be skipped too, e.g. with startswith(name, "hip_rocarray/blas").
  3. Optional: blas_geam! takes β::Union{Bool,T}, but gpu_geam passes β = -one(real(T)) for -, so for complex eltypes A - B' falls back to broadcasting instead of rocBLAS. β::Union{Bool,T,real(T)} with T(β) would cover it.
  4. Optional, for later: the dot(::Symmetric, ::Symmetric) and dot(::Hermitian, ::Hermitian) methods fill a gap that GPUArrays 12.3 has on every back-end (JLArrays hits scalar indexing there), so they could move to GPUArrays.
  5. rocblas_size at the top of highlevel.jl was already unused before this PR and could go.

Before merging I'll run CSCS CI on it briefly as well

@kshyatt

kshyatt commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

I don't know whether rocBLAS' nrm2 rescales for those

It doesn't, I've actually opened an issue with AMD about this ROCm/rocm-libraries#16703

Katharine Hyatt and others added 3 commits December 2, 2026 13:36
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013b7DCbTAjtfi3JqXU4xZmW
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013b7DCbTAjtfi3JqXU4xZmW
@kshyatt

kshyatt commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

OK, 1, 2, 3, and 5 are fixed

@luraess

luraess commented Dec 2, 2026

Copy link
Copy Markdown
Member

Thanks! 2, 3 and 5 look good. For 1, could you add a one-line comment next to the BLAS 1 hooks so nobody adds the hook back, e.g. # no blas_nrm2: rocBLAS' nrm2 doesn't rescale (ROCm/rocm-libraries#16703), so norm uses GPUArrays' generic kernel?

Optional on 3: Union{Bool,T,real(T)} would be tighter than Union{Real,T}, which for a real T accepts any Real and rounds it in T(α). It's fine with the scalars GPUArrays passes today (true, false, -1).

@kshyatt

kshyatt commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Done for both :)

@luraess

luraess commented Dec 2, 2026

Copy link
Copy Markdown
Member

Seems I can't run CSCS pipelines as PR is from a fork - sorry for the noise

@kshyatt

kshyatt commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Oh is this due to the changes Tim made? I wonder if there's a way to reroute the branch if I push it here?

@luraess

luraess commented Dec 2, 2026

Copy link
Copy Markdown
Member

Unrelated. CSCS ci can not run from forks and I missed that here.

Comment thread src/blas/highlevel.jl Resolved
@luraess

luraess commented Dec 2, 2026

Copy link
Copy Markdown
Member

CSCS CI doesn't run on fork PRs, so I ran its jobs locally at 403735b, with GPUArrays 12.3.0. All 8 pass: the four jobs of ci/cscs-common.yml on both MI300A and MI250X.

Julia 1.12, system ROCm 7.2 Julia 1.13, system ROCm 7.2 Julia 1.13, ROCm artifacts 10.2 Julia 1.14.0-beta1, ROCm artifacts 10.2
MI300A ✅ ✅ ✅ ✅
MI250X ✅ ✅ ✅ ✅

This includes hip_rocarray/blas, hip_rocarray/blas_edge_cases and all of gpuarrays/linalg/*. The only broken tests are the existing ones in device/wavefront, hip_dnn/conv and kernelabstractions_tests.

GPUArrays 12.4 implements dot for all wrapped GPU arrays, and returns a
real number for Hermitian matrices, as LinearAlgebra does.
@maleadt

maleadt commented Dec 2, 2026

Copy link
Copy Markdown
Member

With GPUArrays 12.4 (JuliaGPU/GPUArrays.jl#888), the dot methods for Symmetric and Hermitian matrices can go: GPUArrays implements dot for every wrapped GPU array, including mixed pairs such as dot(Symmetric(A), B) and triangular matrices, and gives Hermitian matrices a real result as LinearAlgebra does on Julia 1.11 and later. I pushed that as a separate commit (it needs 12.4 to be registered before CI can resolve it). With it, the BLAS tests and GPUArrays' linalg test suite pass on a gfx1036 iGPU.

@maleadt

maleadt commented Dec 3, 2026

Copy link
Copy Markdown
Member

I merged main into this branch: the Buildkite relay refused it because its workflow files were behind main. The earlier failures were GPUArrays 12.4 not being registered yet; CI is now running against 12.4.

@luraess

luraess commented Dec 3, 2026

Copy link
Copy Markdown
Member

Thanks @maleadt - let's wait GPU BK passes and then we could merge and release.

This branch has not been deployed

No deployments
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