Skip to main content

kernelax: fused, vectorized and multithreaded C and CUDA kernels from JAX

kernelax.jit is a drop-in replacement for jax.jit for JAX code that does many small operations per sample: a material law at every integration point, a Newton solve per particle, a 3 x 3 eigenproblem per cell. It compiles such code into fused kernels, C with SIMD and OpenMP on the CPU and CUDA on NVIDIA GPUs.

When it helps

XLA fuses elementwise operations, but it splits a program at reductions, contractions, gathers and scatters, loops and library calls. Every intermediate value that crosses such a boundary is written to memory as an array over the whole batch and read back, and a while loop under jax.vmap runs every step over the whole batch until its slowest sample has converged. When a program consists of many small operations per sample, this memory traffic, not the arithmetic, dominates the run time, and jax.jit often reaches only a few percent of what the hardware can do. kernelax keeps the intermediate values of a sample in registers and runs loops per sample. Typical cases:

  • material laws and their derivatives (jax.grad, jax.jacfwd) at every integration point,
  • local Newton solves, while loops and ODE time steps per sample,
  • small linear algebra per sample (solves, inverses, eigenvalues of matrices up to about 8 x 8),
  • element routines of a finite element assembly, with their gathers and scatter-adds,
  • rollouts of simulators and reinforcement learning environments, one per sample (gymnax, pgx, jumanji, Brax), and simulations per parameter set (Jaxley, diffrax, dynamiqs).

Example

import jax, jax.numpy as jnp
import kernelax

jax.config.update("jax_enable_x64", True)


def psi(F):  # strain energy of a Neo-Hooke material at one point (shear modulus 1, Lame constant 10)
    J = jnp.linalg.det(F)
    return 0.5 * (jnp.sum(F * F) - 3) - jnp.log(J) + 5.0 * jnp.log(J) ** 2


stress = jax.vmap(jax.jacrev(psi))  # first Piola-Kirchhoff stress P = dpsi/dF at every point

F = jnp.eye(3) + 0.1 * jax.random.normal(jax.random.key(0), (1_000_000, 3, 3))  # a million points
P_xla = jax.jit(stress)(F)
P = kernelax.jit(stress)(F)  # the first call compiles the kernel (seconds; later processes load it from disk)

A call takes 3.9 ms with kernelax.jit and 420 ms with jax.jit on 8 cores of an AMD EPYC 9474F, and 0.27 ms against 4.1 ms on an NVIDIA L40S.

With common libraries

In these examples the only change is kernelax.jit in place of jax.jit. Seconds on 8 cores of an AMD EPYC 9474F, each run in a fresh process; the first call includes tracing and compilation, for kernelax.jit the build of its kernels (empty cache).

Example First call, jax.jit kernelax.jit Later calls, jax.jit kernelax.jit
diffrax: stiff kinetics (Kvaerno5) for 16 384 sets of rate constants 14.3 3.9 14.5 0.12 (120×)
optimistix: BFGS for 2 million parameter sets 6.6 2.8 6.2 0.059 (105×)
e3nn: equivariant messages on 4 million edges (float32) 1.3 2.8 1.6 0.10 (15×)
Jaxley: the branched neuron of Jaxley's tutorial on jit and vmap for 4096 pairs of conductances 3.1 4.9 2.3 0.088 (27×)

Installation

pip install kernelax

Requirements: Linux on x86-64 with AVX2 or AVX-512, Python >= 3.12, JAX 0.12 (>= 0.12.1), gcc and g++ >= 12 with OpenMP, glibc >= 2.35. GPU kernels also need an NVIDIA GPU, JAX with CUDA (jax[cuda12] or jax[cuda13]) and the CUDA toolkit's nvcc.

Further API

kernelax.kernel compiles a function of one sample explicitly: under jax.vmap it runs as one kernel over the batch, and its derivatives run as kernels too. With psi and F from the example above:

stress = kernelax.kernel(jax.grad(psi))  # the stress at one point, as a kernel
P = jax.vmap(stress)(F)  # one kernel call over all points
A = jax.vmap(jax.jacfwd(stress))(F)  # its derivative, the tangent dP/dF, is a kernel too

kernelax.export writes a function of one sample as a C library with Fortran and Java interfaces, e.g. a material law with its tangent for a finite element code:

import numpy as np

kernelax.export(lambda F: (jax.grad(psi)(F), jax.hessian(psi)(F)), (np.eye(3),), name="neo_hooke", out_dir="neo_hooke")
# then make -C neo_hooke: libneo_hooke.so with neo_hooke_batch(nt, n, F, P, A) for n points on nt threads and
# neo_hooke_point(F, P, A) for one point

The reference covers the options, report(), environment variables, numerics (results are close to, but not bitwise equal to, XLA's) and limits.

AI usage

Parts of the code, tests and documentation were developed with AI assistance.

Citation

If you use kernelax in your work, please cite it as given in CITATION.cff:

@software{kernelax,
  author  = {Bode, Tobias},
  title   = {kernelax: fused, vectorized and multithreaded C and CUDA kernels from JAX},
  year    = {2026},
  version = {0.1.0},
  url     = {https://github.com/BodeTobias/kernelax},
}

License

MIT, see LICENSE.

Metadata

Release files for kernelax 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kernelax 0.1.0
File Size Uploaded Provenance Actions
kernelax-0.1.0.tar.gz 377.9 kB With provenance Details for kernelax-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kernelax 0.1.0
File Interpreter ABI Platform Actions
kernelax-0.1.0-py3-none-any.whl Python 3 none any Details for kernelax-0.1.0-py3-none-any.whl

Total release size: 627.1 kB

Release files / kernelax-0.1.0.tar.gz

Download URL kernelax-0.1.0.tar.gz
Size 377.9 kB
Tags Source
SHA-256 checksum
How to use checksums
efd704a048d9460f53ad45da3b8b5d7629499a8568b0a08a2a7a62d6f5b6a6f9
BLAKE2b-256 checksum
How to use checksums
ed9da3994ef6b4093da02396fb3dbf54dc099a29e271b25f0f85cf0b0f8e762a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / kernelax-0.1.0-py3-none-any.whl

Download URL kernelax-0.1.0-py3-none-any.whl
Size 249.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3e471fd0870bc84d3033b73093077903df72dc970aaab9a43f58e13ca15aafb
BLAKE2b-256 checksum
How to use checksums
0be1848f147f7c5e2a7075da2d923069b2d54bc712e753d1f039d96e28ab1767
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for kernelax 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kernelax-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page