NextLA.jl

NextLA.jl is a hardware-agnostic, datatype-flexible dense linear algebra library written in pure Julia. It reimplements LAPACK/BLAS-style routines on top of KernelAbstractions.jl, so one code path runs on CPUs and on NVIDIA, AMD, Intel and Apple GPUs, for Float64, Float32, Float16, BFloat16 and complex element types, and adds mixed-precision recursive factorizations on top.

Instead of writing one implementation per data type and per device, as Fortran and C libraries do, NextLA relies on Julia's multiple dispatch, type inference and LLVM-based compilation to generate specialized code for each combination.

Features

  • Unified API. Implements LAPACK/BLAS subroutines in Julia, avoiding type- and hardware-specific implementations. Supports Float64, Float32, Float16, Float8 (in mixed precision), complex numbers and other numerical types.
  • Multi-architecture support. Efficiently runs on CPUs and GPUs, leveraging Julia's LLVM-based compilation: the same call runs on a Matrix, CuArray, ROCArray, oneArray or MtlArray.
  • High performance. Benchmarks show that Julia-based implementations achieve performance on par with or exceeding LAPACK/CUSOLVER. See Benchmarks.
  • Mixed precision. Recursive factorizations on matrices that store each block in its own precision, from Float64 down to Float8_E5M2. See Mixed precision.
  • Future-proof and composable. Designed for extensibility, allowing new data types and hardware architectures to be integrated with minimal modifications.

Hierarchical Recursive Precision for Accelerating Symmetric Linear Solves on MXUs, poster

Why Julia for dense linear algebra?

Traditionally, linear algebra libraries have been optimized for Fortran and C, requiring separate implementations for different hardware and data types. NextLA.jl leverages Julia's multiple dispatch, type inference, and metaprogramming capabilities to dynamically generate optimized machine code, making it a future-proof alternative.

Installation

NextLA is registered in the Julia General registry and is tested on Julia 1.10, the latest release and nightly.

using Pkg
Pkg.add("NextLA")   # latest release

# development version
Pkg.add(url = "https://github.com/NextLinearAlgebra/NextLA.jl")

For GPU support, also add the backend package you want (CUDA, AMDGPU, oneAPI or Metal).

Quick start

On the CPU

using NextLA          # for potrf_recursive!, trsm!
using LinearAlgebra   # for I

n = 2048
A = rand(n, n)
S = A * A' + n * I                     # symmetric positive definite
B = rand(n, 256)

F = copy(S)
potrf_recursive!(F)                    # Cholesky: S = L * L', L stored in F

X = copy(B)
trsm!('L', 'L', 'N', 'N', 1.0, F, X)   # solve L * Y = B
trsm!('L', 'L', 'T', 'N', 1.0, F, X)   # solve L' * X = Y

S * X ≈ B

# output

true

On a GPU

# For AMD GPUs, load AMDGPU and use ROCArray instead.
using NextLA          # for potrf_recursive!, trsm!
using CUDA            # for CUDA.rand
using LinearAlgebra   # for I

A = CUDA.rand(Float32, 4096, 4096)     # on the GPU
S = A * A' + 4096f0 * I
B = CUDA.rand(Float32, 4096, 256)

F = copy(S)
potrf_recursive!(F)                    # same call as on the CPU

X = copy(B)
trsm!('L', 'L', 'N', 'N', 1f0, F, X)   # solve L Y = B
trsm!('L', 'L', 'T', 'N', 1f0, F, X)   # solve Lᵀ X = Y
S * X ≈ B                              # output: true

Mixed precision

using NextLA                  # for potrf_recursive!
using NextLA.MixedPrecision   # for the mixed-precision matrices
using LinearAlgebra           # for I, norm

A = rand(2048, 2048)
S = A * A' + 2048I

# off-diagonal block stored in Float32, diagonal blocks in Float64
M = SymmMixedPrec(S, 'L'; precisions = DataType[Float32, Float64])
potrf_recursive!(M)                    # Cholesky on the mixed-precision matrix

L = reconstruct_matrix(TriMixedPrec(M))   # the factor as a dense matrix
norm(L * L' - S) / norm(S) < 1e-6

# output

true

Where to go next

Continue with Getting started for examples, read the Manual to learn how backends and mixed precision work, or look up a routine's arguments and examples in the API reference.

Getting help

Questions, bug reports and feature requests go to the GitHub issues.

Citing

If you use NextLA.jl in your research, please cite the papers listed in CITATION.md. GitHub's "Cite this repository" button uses CITATION.cff.

Contributing

Pull requests are welcome. CONTRIBUTING.md describes the repository layout and the modules, and test/README.md explains how to run all or some of the tests, on the CPU or a GPU.

Contributors

License

NextLA.jl is released under the MIT License (copyright 2024 Rabab Alomairy).