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.
Float64, Float32, Float16, Float8 (in mixed precision), complex numbers and other numerical types.Matrix, CuArray, ROCArray, oneArray or MtlArray.Float64 down to Float8_E5M2. See Mixed precision.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.
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).
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
# 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
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
See the documentation for the full guide and API reference.
The documentation is built with Documenter.jl. To build it locally:
julia --project=docs -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd()))'
julia --project=docs -e 'using Pkg; Pkg.instantiate()'
julia --project=docs docs/make.jl
Then open docs/build/index.html.
julia --project -e 'using Pkg; Pkg.test()'
This runs every test on the CPU. How to test on a GPU, run only some tests, and the other options: test/README.md.
Questions, bug reports and feature requests go to the GitHub issues.
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.
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.
NextLA.jl is released under the MIT License (copyright 2024 Rabab Alomairy).