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:

ExtensionLoaded byVendor libraries used
NextLACUDAExtusing CUDAcuBLAS, cuSOLVER
NextLAAMDGPUExtusing AMDGPUrocBLAS, rocSOLVER
NextLAoneAPIExtusing oneAPIoneMKL
NextLAMetalExtusing MetalMetal 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 GPU

The 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).

RoutineCPUCUDAAMDGPUoneAPIMetal
gemm!, recgemm!BLASvendor (Float32), mul! otherwisemul!mul!mul!
gemmEx! (mixed types)portablevendorvendor——
gemm_batched!loopvendorvendorvendor (no pointer form)vendor (3-D only)
trsm!, unified_rectrxm!portablevendor + portablevendor + portableportableportable
trsm_batched!loopvendorvendorvendor—
syrk!BLASvendorvendorvendorMPS GEMM
recsyrk!, SYRK_KERNEL!portableportableportableportableportable
potrf!LAPACKvendorvendor——
potrf_batched!loopvendorvendorvendor—
potrf_recursive!recursiverecursiverecursiveneeds potrf!needs potrf!
lu_recursive! (leaf)lu!(NoPivot())cuSOLVER getrfrocSOLVER getrf_npvt——
cholesky_blocked!—portableportableportableportable
syrk_batched!looploopvendorvendor (strided), loop (pointer)via gemm_batched! (3-D only)
lu_base!portableportableportableportableportable
tile_lu_factor!—portableportableportableportable
QR tile kernels (geqrt!, tsqrt!, ttqrt!, unmqr!, tsmqr!, ttmqr!, …)portableportable; larfb! (so unmqr!) vendor for Float32, ComplexF32portableportableportable

Notes:

  • gemmEx! with differing storage and compute types is a CUDA and AMDGPU feature; the CPU accepts any combination and accumulates in compute_type. oneAPI and Metal throw.
  • trsm! reaches cuBLAS/rocBLAS trsm! for Float32, Float64, ComplexF32 and ComplexF64 dense 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 cuBLAS trsm!/trmm! and its updates are cuBLAS GEMMs; Float16 is worked in Float32 copies, as cuBLAS has no Float16 TRSM.
  • gemm! on CUDA sends Float32 matrices, views and transposes to cuBLAS, and Float16 too, through gemmEx! with Float32 sums. Other types call mul!, 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 so unmqr!, applies the block reflector with cuBLAS GEMM/TRMM on CUDA for Float32 and ComplexF32 (side = 'L'); Float64 keeps 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 needs potrf! too. Metal also throws for potrf_batched! and trsm_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 throw ArgumentError. Metal's syrk_batched! goes through gemm_batched!, so it also needs a 3-D array.
  • Float16 has no vendor SYRK, so recursive Cholesky in half precision uses recsyrk!.
  • cholesky_blocked! is GPU-only: on the CPU it throws and points to potrf!. 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-matrix syrk! is a full GEMM (MPS matmul!), so it also overwrites the other triangle.
  • The AMDGPU fast path of unified_rectrxm! compiles and is selected for ROCMatrix arguments, but has not been run on AMD hardware.
  • The QR tile kernels are not exported, except parfb! and pemv! (call the others as NextLA.geqrt! and so on). Their CUDA runs pass the test suite on Julia 1.10.

Element types

TypeNotes
Float64, Float32Supported by every routine below.
ComplexF64, ComplexF32Supported 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).
Float16Portable 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!.
BFloat16From BFloat16s.jl. As Float16, and no Cholesky (potrf!, potrf_recursive!).
Float8_E5M2Storage 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.

RoutineFloat64Float32Float16BFloat16ComplexF64ComplexF32
gemm!✓✓✓✓✓✓
gemmEx!✓✓✓✓✓✓
recgemm!✓✓✓✓✓✓
gemm_batched!✓✓refusedrefused✓✓
trsm!✓✓✓✓✓✓
trmm!✓✓✓✓✓✓
unified_rectrxm! (solve)✓✓✓✓✓✓
unified_rectrxm! (multiply)✓✓✓✓✓✓
trsm_batched!✓✓——✓✓
syrk!✓✓——✓✓
recsyrk!✓✓✓✓✓✓
SYRK_KERNEL!✓✓✓✓✓✓
syrk_batched!✓✓——✓✓
potrf!✓✓✓—✓✓
potrf_recursive!✓✓✓—✓✓
cholesky_blocked!GPU onlyGPU onlyGPU onlyGPU onlyGPU onlyGPU 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.