Backends and GPUs
NextLA writes its kernels once with KernelAbstractions.jl and picks the backend from the array it is given (KernelAbstractions.get_backend(A)). Vendor-specific code lives in package extensions under ext/, which Julia loads automatically when the matching GPU package is loaded:
| Extension | Loaded by | Vendor libraries used |
|---|---|---|
NextLACUDAExt | using CUDA | cuBLAS, cuSOLVER |
NextLAAMDGPUExt | using AMDGPU | rocBLAS, rocSOLVER |
NextLAoneAPIExt | using oneAPI | oneMKL |
NextLAMetalExt | using Metal | Metal Performance Shaders |
Without any GPU package, every routine except cholesky_blocked! and tile_lu_factor! runs on the CPU, calling LinearAlgebra.BLAS/LAPACK where they cover the element type and portable Julia kernels otherwise.
Usage
using NextLA, CUDA # or AMDGPU, oneAPI, Metal
using LinearAlgebra
A = rand(Float32, 100, 100)
S = CuArray(A * A' + 100I) # move the matrix to the GPU once
potrf_recursive!(S) # runs on the GPUThe call is the same as on the CPU. Keep all operands on the same device: NextLA does not move data between host and device for you.
What runs where
The table lists the main entry points. "Portable" means the generic KernelAbstractions or recursive Julia implementation; "vendor" means the call is forwarded to the vendor library for the supported element types (other types fall back to the portable path where one exists).
| Routine | CPU | CUDA | AMDGPU | oneAPI | Metal |
|---|---|---|---|---|---|
gemm!, recgemm! | BLAS | vendor (Float32), mul! otherwise | mul! | mul! | mul! |
gemmEx! (mixed types) | portable | vendor | vendor | — | — |
gemm_batched! | loop | vendor | vendor | vendor (no pointer form) | vendor (3-D only) |
trsm!, unified_rectrxm! | portable | vendor + portable | vendor + portable | portable | portable |
trsm_batched! | loop | vendor | vendor | vendor | — |
syrk! | BLAS | vendor | vendor | vendor | MPS GEMM |
recsyrk!, SYRK_KERNEL! | portable | portable | portable | portable | portable |
potrf! | LAPACK | vendor | vendor | — | — |
potrf_batched! | loop | vendor | vendor | vendor | — |
potrf_recursive! | recursive | recursive | recursive | needs potrf! | needs potrf! |
lu_recursive! (leaf) | lu!(NoPivot()) | cuSOLVER getrf | rocSOLVER getrf_npvt | — | — |
cholesky_blocked! | — | portable | portable | portable | portable |
syrk_batched! | loop | loop | vendor | vendor (strided), loop (pointer) | via gemm_batched! (3-D only) |
lu_base! | portable | portable | portable | portable | portable |
tile_lu_factor! | — | portable | portable | portable | portable |
QR tile kernels (geqrt!, tsqrt!, ttqrt!, unmqr!, tsmqr!, ttmqr!, …) | portable | portable; larfb! (so unmqr!) vendor for Float32, ComplexF32 | portable | portable | portable |
Notes:
gemmEx!with differing storage and compute types is a CUDA and AMDGPU feature; the CPU accepts any combination and accumulates incompute_type. oneAPI and Metal throw.trsm!reaches cuBLAS/rocBLAStrsm!forFloat32,Float64,ComplexF32andComplexF64dense matrices;Float16, views on AMDGPU and the other backends take the recursion; on CUDA, views go to cuBLAS too (a view whose rows are not consecutive is copied first). When the recursion runs on CUDA (Float16, and the leaves of the mixed-precision solve), its leaf solves and multiplies are cuBLAStrsm!/trmm!and its updates are cuBLAS GEMMs;Float16is worked inFloat32copies, as cuBLAS has noFloat16TRSM.gemm!on CUDA sendsFloat32matrices, views and transposes to cuBLAS, andFloat16too, throughgemmEx!withFloat32sums. Other types callmul!, which for a view of a device array can reach a generic GPU kernel, except when the output shares a device buffer with an input without overlapping it (a one-column block of a recursion, which newer Julia versions'mul!refuses): that case goes to cuBLAS too.larfb!, and sounmqr!, applies the block reflector with cuBLAS GEMM/TRMM on CUDA forFloat32andComplexF32(side = 'L');Float64keeps the portable code, which is faster there.potrf!has no generic device fallback, so on oneAPI and Metal, where NextLA has no wrapper for it, it throws instead of silently copying to the host.potrf_recursive!calls it at its leaves, so it needspotrf!too. Metal also throws forpotrf_batched!andtrsm_batched!.gemm_batched!takes a 3-D array on every GPU backend. Metal does not take a vector of matrices, and neither Metal nor oneAPI takes the pointer form; both throwArgumentError. Metal'ssyrk_batched!goes throughgemm_batched!, so it also needs a 3-D array.Float16has no vendor SYRK, so recursive Cholesky in half precision usesrecsyrk!.cholesky_blocked!is GPU-only: on the CPU it throws and points topotrf!.tile_lu_factor!refuses the CPU because its kernels give wrong results there.- cuBLAS has no batched SYRK, so
syrk_batched!loops single calls on CUDA. Metal has no SYRK at all: its single-matrixsyrk!is a full GEMM (MPSmatmul!), so it also overwrites the other triangle. - The AMDGPU fast path of
unified_rectrxm!compiles and is selected forROCMatrixarguments, but has not been run on AMD hardware. - The QR tile kernels are not exported, except
parfb!andpemv!(call the others asNextLA.geqrt!and so on). Their CUDA runs pass the test suite on Julia 1.10.
Element types
| Type | Notes |
|---|---|
Float64, Float32 | Supported by every routine below. |
ComplexF64, ComplexF32 | Supported by every routine below; cholesky_lower! gives wrong results, and potrf_recursive! is correct only when the matrix fits in one leaf (n ≤ block_size). |
Float16 | Portable kernels. recgemm!, recsyrk! and the triangular solve and multiply accumulate in Float32; gemm! accumulates Float16 in Float32 on the CPU and CUDA (strided matrices); on AMDGPU, Metal and oneAPI it calls mul!, which may accumulate in Float16. gemmEx! with only Float16 operands accumulates in Float16 unless it is given compute_type = Float32. Not in syrk!, the CPU batched routines or getrf2!. |
BFloat16 | From BFloat16s.jl. As Float16, and no Cholesky (potrf!, potrf_recursive!). |
Float8_E5M2 | Storage type for mixed-precision off-diagonal blocks. |
Measured on the CPU: each routine runs on 32×32 inputs and its result is compared with a Float64/ComplexF64 reference. ✓ correct result, ✗ wrong result, — no method for that type, GPU only / refused throws by design. On GPUs the vendor libraries decide which types the vendor paths take; other types use the portable code.
| Routine | Float64 | Float32 | Float16 | BFloat16 | ComplexF64 | ComplexF32 |
|---|---|---|---|---|---|---|
gemm! | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gemmEx! | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
recgemm! | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gemm_batched! | ✓ | ✓ | refused | refused | ✓ | ✓ |
trsm! | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
trmm! | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
unified_rectrxm! (solve) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
unified_rectrxm! (multiply) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
trsm_batched! | ✓ | ✓ | — | — | ✓ | ✓ |
syrk! | ✓ | ✓ | — | — | ✓ | ✓ |
recsyrk! | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
SYRK_KERNEL! | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
syrk_batched! | ✓ | ✓ | — | — | ✓ | ✓ |
potrf! | ✓ | ✓ | ✓ | — | ✓ | ✓ |
potrf_recursive! | ✓ | ✓ | ✓ | — | ✓ | ✓ |
cholesky_blocked! | GPU only | GPU only | GPU only | GPU only | GPU only | GPU only |
cholesky_lower! | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ |
potrf_batched! | ✓ | ✓ | — | — | ✓ | ✓ |
getrf2! (pivoted LU) | ✓ | ✓ | — | — | ✓ | ✓ |
lu_recursive! (no pivoting) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
lu_recursive_nopiv! | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
lu_base! (pivoted, n ≤ 32) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
geqrt! + unmqr! (QR of a tile) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
tsqrt! + tsmqr! (triangle on square) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
ttqrt! + ttmqr! (triangle on triangle) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
geru! | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gerc! | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
axpy! | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
lartg (Givens) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
GEMM compute modes
For reduced-precision inputs, gemmEx! and its batched variants take a compute_type that sets the accumulation precision. default_compute_type picks one from the storage types of A, B and C, and GEMM_COMPUTE_TYPES documents the supported behaviour per backend. The precision-policy entry points such as precision_gemm_batched! take a compute mode instead, where TF32 requests TensorFloat-32 computation for Float32 operands.
Some vendor GEMMs need aligned leading dimensions; is_gemm_aligned, gemm_alignment_quantum and aligned_leading_dimension help allocate arrays that qualify.