Skip to main content

JAXMg provides a C++ interface between JAX and cuSolverMg, NVIDIA's multi-GPU linear solver.

Project description

Jaxmg

JAXMg: A distributed linear solver in JAX with cuSolverMg

Docs Releases Build Status

JAXMg

JAXMg provides a C++ interface between JAX and cuSolverMg, NVIDIA’s multi-GPU linear solver. We provide a jittable API for the following routines.

  • cusolverMgPotrs: Solves the system of linear equations: $Ax=b$ where $A$ is an $N\times N$ symmetric (Hermitian) positive-definite matrix via a Cholesky decomposition
  • cusolverMgPotrs: Computes the inverse of an $N\times N$ symmetric (Hermitian) positive-definite matrix via a Cholesky decomposition.
  • cusolverMgPotrs: Computes eigenvalues and eigenvectors of an $N\times N$ symmetric (Hermitian) matrix.

For more details, see the API.

Installation

The package is available on PyPi and can be installed with

pip install jaxmg[cuda12]

This will install a GPU compatible version of JAX.

  1. pip install "jaxmg[cuda12]": Use CUDA 12 (only works for jax>=0.6.2).

  2. pip install "jaxmg[cuda12-local]": Use locally available CUDA 12 installation.

  3. pip install "jaxmg[cuda13]": Use CUDA 13 (only works for jax>=0.7.2).

  4. pip install "jaxmg[cuda13-local]": Use locally available CUDA 13 installation.

The provided binaries are compiled with

JAXMg CUDA cuDNN
cuda12,cuda12-local 12.8.0 9.17.1.4
cuda13,cuda13-local 13.0.0 9.17.1.4

Note: pip install jaxmg will install a CPU-only version of JAX. Since jaxmg is a GPU-only package you will receive a warning to install a GPU-compatible version of jax.

Example

A minimal example that runs the code is:

import jax
jax.config.update("jax_enable_x64", True)
import jax.numpy as jnp
from jax.sharding import PartitionSpec as P, NamedSharding
from jaxmg import potrs
print(f"Devices: {jax.devices()}")
# Assumes we have at least one GPU available
devices = jax.devices("gpu")
N = 12
T_A = 3
dtype = jnp.float64
# Create diagonal matrix and `b` all equal to one
A = jnp.diag(jnp.arange(N, dtype=dtype) + 1)
b = jnp.ones((N, 1), dtype=dtype)
ndev = len(devices)
# Make mesh and place data (rows sharded)
mesh = jax.make_mesh((ndev,), ("x",))
A = jax.device_put(A, NamedSharding(mesh, P("x", None)))
b = jax.device_put(b, NamedSharding(mesh, P(None, None)))
# Call potrs
out = potrs(A, b, T_A=T_A, mesh=mesh, in_specs=(P("x", None), P(None, None)))
print(out)
expected_out = 1.0 / (jnp.arange(N, dtype=dtype) + 1)
print(jnp.allclose(out.flatten(), expected_out))

which gives

[[1.        ]
 [0.5       ]
 [0.33333333]
 [0.25      ]
 [0.2       ]
 [0.16666667]
 [0.14285714]
 [0.125     ]
 [0.11111111]
 [0.1       ]
 [0.09090909]
 [0.08333333]]
True

as expected.

Projects that use JAXMg

  • JAXMg Benchmarks: Benchmarks for various Multi-GPUs setups.
  • JAXMg + Netket: Implementation of the MinSR Netket driver that uses JAXMg for inverting the SR-matrix. Tested on Multi-node settings.

cuSolverMp

As of CUDA 13, there is a new distributed linear algebra library called cuSolverMp with similar capabilities as cuSolverMg, that does support multi-node computations as well as >16 devices. Given the similarities in syntax, it should be straightforward to eventually switch to this API. This will require sharding data into a cyclic 2D form and handling the solver orchestration with MPI.

Citations

@software{Wiersema_JAXMg_distributed_linear_2025,
author = {Wiersema, Roeland},
month = dec,
title = {{JAXMg: distributed linear solvers in JAX}},
url = {https://github.com/flatironinstitute/jaxmg},
version = {0.0.4},
year = {2025}
}

Acknowledgements

I acknowledge support from the Flatiron Institute. The Flatiron Institute is a division of the Simons Foundation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

jaxmg-0.0.4-cp314-cp314-manylinux_2_26_x86_64.whl (24.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.26+ x86-64

jaxmg-0.0.4-cp313-cp313-manylinux_2_26_x86_64.whl (24.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.26+ x86-64

jaxmg-0.0.4-cp312-cp312-manylinux_2_26_x86_64.whl (24.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.26+ x86-64

jaxmg-0.0.4-cp311-cp311-manylinux_2_26_x86_64.whl (24.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.26+ x86-64

File details

Details for the file jaxmg-0.0.4-cp314-cp314-manylinux_2_26_x86_64.whl.

File metadata

File hashes

Hashes for jaxmg-0.0.4-cp314-cp314-manylinux_2_26_x86_64.whl
Algorithm Hash digest
SHA256 a6c63ca71d1e73a1d09c278f874215d4660ab2ef56bc6095fe3e63b8dabbdc7a
MD5 1afe62a874fb7ae51ab1f0e9c602d1fa
BLAKE2b-256 f77d3a1f3820a97c0c76e23c550dd3c9b965ef0e38a5f0e30b0b830554c40af2

See more details on using hashes here.

File details

Details for the file jaxmg-0.0.4-cp313-cp313-manylinux_2_26_x86_64.whl.

File metadata

File hashes

Hashes for jaxmg-0.0.4-cp313-cp313-manylinux_2_26_x86_64.whl
Algorithm Hash digest
SHA256 c3710049319426fe00cf87a95c46a1f1f230ff3c4f852f83c2124e576897c338
MD5 ad1169a6e9a4f850e68c28efb2a488eb
BLAKE2b-256 3312c3a0933cdb43f76715cfb01bfde90f3cd257dad17bdc10f9a8461d1087a9

See more details on using hashes here.

File details

Details for the file jaxmg-0.0.4-cp312-cp312-manylinux_2_26_x86_64.whl.

File metadata

File hashes

Hashes for jaxmg-0.0.4-cp312-cp312-manylinux_2_26_x86_64.whl
Algorithm Hash digest
SHA256 07063093a89c2e2cb6415517ab2a35901d83a1c18c76970af22eb8e19a8b3e89
MD5 ea8fa40230b71b6462cb34908f0a8fe0
BLAKE2b-256 f76037a2072981a583a69aa00607d4d4bc2d690e411664ba40339acb85b1107c

See more details on using hashes here.

File details

Details for the file jaxmg-0.0.4-cp311-cp311-manylinux_2_26_x86_64.whl.

File metadata

File hashes

Hashes for jaxmg-0.0.4-cp311-cp311-manylinux_2_26_x86_64.whl
Algorithm Hash digest
SHA256 cea261d4151f933a6a02fbf35cef53db6a334f38b8f509f754fddd0500e65741
MD5 a8fdd170390d564936aa88c2eb9110ce
BLAKE2b-256 864ad165fb66ba8db098956e40bbb800a2bb4df7085b9e3ee4b684f04e10c98d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page