exact-linalg

exact-linalg computes the exact determinant, the exact rank, and an exact integer nullspace basis of an integer matrix on the GPU, loadable through kernels. Results are exact integers, not floating-point approximations, and no tolerance parameter exists anywhere. The reference baselines are FLINT fmpz_mat_det, fmpz_mat_rank, fmpz_mat_nullspace and a fraction-free Bareiss elimination compared digit for digit.

Floating-point linear algebra cannot answer these questions reliably: a determinant overflows or rounds to noise, and rank depends on a tolerance the caller has to guess. This kernel answers them exactly. A 1,728-digit determinant of a 256 x 256 integer matrix returns in 33 ms as a Python integer, rank is a theorem rather than a threshold, and every nullspace vector can be certified by multiplying it back in integer arithmetic.

A prime dial fills while a 77-digit determinant churns and snaps exact the moment the CRT range covers the Hadamard bound

The determinant of a random 24 x 24 integer matrix assembling from residues modulo 31-bit primes: the candidate churns until the prime product clears twice the Hadamard bound, then locks to the exact 77-digit value, verified digit for digit against Bareiss elimination. Below, an exact rank with no tolerance parameter, and a nullspace vector certified S @ v == 0 in integer arithmetic.

Usage

import torch
from kernels import get_kernel

el = get_kernel("phanerozoic/exact-linalg", version=1, trust_remote_code=True)

A = torch.randint(-10**6, 10**6, (256, 256), dtype=torch.int64, device="cuda")

el.det(A)         # exact determinant, a Python int
el.rank(A)        # rank over the rationals
el.nullspace(A)   # list of primitive integer vectors spanning {x : A x = 0}

version selects the release branch; trust_remote_code is required by kernels for publishers without the trusted-publisher mark. Entries must fit in int64. gmpy2 accelerates the reconstruction and is recommended.

API

Symbol Purpose
det(A) exact determinant of a square integer matrix, as a Python int
rank(A) exact rank over the rationals, as a Python int
nullspace(A) list of n-entry primitive integer vectors spanning the nullspace; empty when A is nonsingular

A may be a torch integer tensor, a nested list, or a numpy array.

Method

One pass produces all three results. The matrix is reduced to reduced row echelon form modulo a set of 31-bit primes, one CUDA grid slice per prime, with per-prime pivot bookkeeping so a prime that loses rank proceeds independently. Primes stay below 2^31 so a product of residues fits in 62 bits and Barrett reduction needs one 64-bit high-multiply.

The determinant modulo each prime is the signed product of that prime's pivots, and a prime that loses rank has determinant zero, which is itself correct, so every prime contributes to the lift. The Hadamard bound prod_i ||row_i||_2 bounds the determinant; once the prime product exceeds twice the bound, CRT recovers the signed integer exactly.

Rank modulo a prime never exceeds rank over the rationals, and some r x r minor is nonzero and bounded by the same Hadamard bound, so it survives at least one prime in a set whose product exceeds the bound. The maximum of the per-prime ranks is therefore the exact rank.

For the nullspace, the reduced echelon form is rational, but scaling by the pivot-submatrix determinant d clears the denominators: the free columns of d * RREF are r x r minors of the input, again under the Hadamard bound. CRT lifts those and the gcd is divided out, giving a primitive integer basis. Only primes agreeing on both rank and pivot column set join the lift; the prime set grows and the reduction repeats if too few agree.

Measured

Random matrices, entries to 10^6:

n det digits rank
64 25 ms 412 3 ms
128 9 ms 845 6 ms
256 33 ms 1,728 27 ms

Verification

Every result is checkable without trusting this kernel. A @ v == 0 certifies each nullspace vector in exact integer arithmetic, and the test suite compares determinants digit for digit against a fraction-free Bareiss elimination computed independently in Python, across sizes 1 to 32, entries to 10^12, singular and rank-deficient matrices of constructed rank, and the zero matrix.

Requirements and limits

  • NVIDIA GPU with compute capability 8.0+.
  • Entries must fit in int64.
  • Rank-deficient inputs cost additional reduction rounds when primes disagree on the pivot set; the prime set grows until enough agree.

References

Hart et al., FLINT (Fast Library for Number Theory); fraction-free Bareiss elimination; Chinese Remainder Theorem lifting over word-size primes.

License

Apache-2.0.

Downloads last month
-
apache-2.0
Supported hardwares new
CUDA
8.08.68.99.010.012.0
GPU
B300
288GB
NVIDIA SXM
B200
192GB
NVIDIA SXM
H200
141GB
NVIDIA SXM
H100
80GB
GPU
H800
80GB
GPU
H20
96GB
GPU
L40s
48GB
GPU
L40
48GB
GPU
L20
48GB
GPU
L4
24GB
DGX Spark
GB10
128GB
GPU
RTX PRO 6000 WS
96GB
GPU
RTX PRO 6000 Max-Q
96GB
GPU
RTX PRO 5000
48GB
GPU
RTX PRO 4500 WS
32GB
GPU
RTX PRO 4000
24GB
GPU
RTX PRO 4000 SFF
24GB
GPU
RTX PRO 2000
16GB
GPU
RTX 6000 Ada
48GB
GPU
RTX 5880 Ada
48GB
RTX
RTX 5000 Ada
32GB
GPU
RTX 4500 Ada
24GB
RTX
RTX 4000 Ada
20GB
RTX
RTX 4000 SFF Ada
20GB
GPU
RTX 3500 Ada Mobile
12GB
GPU
RTX 2000 Ada
16GB
GPU
RTX A6000
48GB
GPU
RTX A5000
8GB
GPU
RTX A5000 Max-Q
16GB
GPU
RTX A5000 Mobile
16GB
GPU
RTX A4000
16GB
GPU
RTX A4000 Max-Q
8GB
GPU
RTX A4000 Mobile
8GB
GPU
RTX A3000 Mobile
6GB
GPU
RTX A2000
6GB
GPU
RTX A2000 Embedded
4GB
GPU
RTX A2000 Max-Q
4GB
GPU
RTX A2000 Mobile
4GB
GPU
A800
40GB
GPU
A100
80GB
GPU
A40
48GB
GPU
A30
24GB
GPU
A10
24GB
GPU
A2
16GB
RTX
RTX 5090
32GB
RTX
RTX 5090 D
32GB
RTX
RTX 5090 Mobile
24GB
RTX
RTX 5080
16GB
RTX
RTX 5080 Mobile
16GB
RTX
RTX 5070
12GB
RTX
RTX 5070 Mobile
8GB
RTX
RTX 5070 Ti
16GB
RTX
RTX 5070 Ti Mobile
12GB
RTX
RTX 5060 Ti
16GB
RTX
RTX 5060
8GB
RTX
RTX 5060 Mobile
8GB
RTX
RTX 5050
8GB
RTX
RTX 5050 Mobile
8GB
RTX
RTX 4090
24GB
RTX
RTX 4090D
24GB
RTX
RTX 4090 Mobile
16GB
RTX
RTX 4080 SUPER
16GB
RTX
RTX 4080
16GB
RTX
RTX 4080 Mobile
12GB
RTX
RTX 4070
12GB
RTX
RTX 4070 Mobile
8GB
RTX
RTX 4070 Ti
12GB
RTX
RTX 4070 Super
12GB
RTX
RTX 4070 Ti Super
16GB
RTX
RTX 4060
8GB
RTX
RTX 4060 Ti
8GB
RTX
RTX 4090 Laptop
16GB
RTX
RTX 4080 Laptop
12GB
RTX
RTX 4070 Laptop
8GB
RTX
RTX 4060 Laptop
8GB
RTX
RTX 4050 Laptop
6GB
RTX
RTX 3090
24GB
RTX
RTX 3090 Ti
24GB
RTX
RTX 3080
12GB
RTX
RTX 3080 Ti
12GB
RTX
RTX 3080 Mobile
16GB
RTX
RTX 3070
8GB
RTX
RTX 3070 Ti
8GB
RTX
RTX 3070 Ti Mobile
8GB
RTX
RTX 3060 Ti
8GB
RTX
RTX 3060
12GB
RTX
RTX 3060 Mobile
6GB
RTX
RTX 3050 Mobile
4GB
GPU
RTX 2050 Mobile
4GB
Jetson
Jetson AGX Orin 64GB
64GB
Jetson
Jetson AGX Orin 32GB
32GB
Jetson
Jetson Orin NX 16GB
16GB
Jetson
Jetson Orin NX 8GB
8GB
Jetson
Jetson Orin Nano 8GB
8GB
Jetson
Jetson Orin Nano 4GB
4GB
OS
linux
Arch
x86_64aarch64
Kernel Builder
19aaa64