Skip to main content

Linear Algebra with CUDA

Project description

linac_logo_v1

Linac: Linear algebra with CUDA

CI Lint CI Test Coverage Docs PyPI PyPI Downloads Binder DOI Python

Linac implements GPU-accelerated linear algebra using CUDA, with support for real and complex floating-point arithmetic, finite fields, and leading-digit p-adic numbers. Its main functionality is dense Gaussian elimination to reduced row-echelon form. Applications include functional reconstruction of analytic scattering amplitudes.

Installation

The latest stable release is available from PyPI:

pip install linac

To enable GPU acceleration, install the CUDA extra:

pip install "linac[cuda]"

For development, clone the repository and install it in editable mode:

git clone https://github.com/GDeLaurentis/linac.git
pip install -e "linac[full]"

Available extras are:

cuda, dev, full(=cuda+dev)

Requirements

The core package depends on:

numpy, pycoretools, pyadic, syngular

Optional dependencies include:

pycuda   # CUDA/GPU support

with the cuda extra, and

mpmath, galois, diskcache, pytest, pytest-cov, flake8

with the dev extra.

GPU acceleration requires a working CUDA development environment, including nvcc, compatible NVIDIA drivers, and access to a CUDA-enabled GPU.

You can check your CUDA setup with:

nvcc --version
nvidia-smi

Quick Start

The main entry point is cuda_row_reduce, which computes a row-reduced echelon form on the GPU.

import numpy
from linac import cuda_row_reduce

p = 2**31 - 1

A = numpy.random.randint(0, p, size=(2000, 2000), dtype="uint32")
rref = cuda_row_reduce(A, field_characteristic=p)

Setting field_characteristic=0 selects floating-point arithmetic:

A = numpy.random.rand(2000, 2000)
rref = cuda_row_reduce(A, field_characteristic=0)

For CPU row reduction, use:

from linac import row_reduce

rref, variable_order = row_reduce(A, prime=p)

Linac also provides utilities for constructing dense linear systems from polynomial ansätze:

from linac import load_matrices

matrices = load_matrices(prefactors, ansatze, points, use_cuda=True)

Testing

Run the test suite with:

pytest -rs --verbose --cov=linac --cov-report=html

Timings

The following timings are for dense Gaussian elimination to reduced row-echelon form over the finite field with p=(2**31 - 1). Times are shown in seconds as mean ± standard deviation.

Matrix size A100 80GB RTX 4070 Laptop 8GB
1,000 0.52 ± 0.01 0.28 ± 0.02
2,000 0.56 ± 0.01 0.34 ± 0.01
5,000 1.02 ± 0.01 3.31 ± 0.01
10,000 3.60 ± 0.01 25.97 ± 0.66
15,000 10.23 ± 0.02 98.21 ± 0.85
20,000 23.40 ± 0.03 241.29 ± 3.00
100,000 2824.64

The 100k run used approximately 37.67 GiB of memory on an 80 GiB A100.

For full benchmark details and comparison with CPU implementations, see the accompanying paper and documentation.

Size Limit

For 32-bit entries, the approximate upper bound for a dense square matrix is

N_max ~ sqrt(VRAM [bytes] / 4)
Available VRAM Approx. square matrix size
4 GB 31,622
8 GB 44,721
11 GB 52,440
12 GB 54,772
16 GB 63,245
24 GB 77,459
40 GB 100,000
80 GB 141,421

The practical limit is usually close to this estimate, up to padding and (small) memory-management overheads.

Documentation

Documentation is available at:

https://gdelaurentis.github.io/linac/

Citation

If you use Linac in academic work, please cite the accompanying paper and the Zenodo archive:

@software{linac,
  author = {De Laurentis, Giuseppe and Franklin, Jack},
  title = {Linac: linear algebra with CUDA over finite fields},
  year = {2026},
  doi = {10.5281/zenodo.xxxxxxxx},
}

Project details


Download files

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

Source Distribution

linac-1.0.0.tar.gz (41.9 kB view details)

Uploaded Source

Built Distribution

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

linac-1.0.0-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

Details for the file linac-1.0.0.tar.gz.

File metadata

  • Download URL: linac-1.0.0.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.3

File hashes

Hashes for linac-1.0.0.tar.gz
Algorithm Hash digest
SHA256 212e770ec50b9e4a4ef5aded37f40e89136c45aebd4fa77480d85accc7ffa01c
MD5 304310b465d19744843d6a32be981470
BLAKE2b-256 6ffa733056c0ba3f4d111739da91c8112f292143529c5e48f4f324d9e54ce9cc

See more details on using hashes here.

File details

Details for the file linac-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: linac-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.3

File hashes

Hashes for linac-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2703a0d20b2acdce14b785bbf9bffaa27bda54c5fe81c47501e861bdc531b4fb
MD5 d0980892d1ef8733c39469060e730dc0
BLAKE2b-256 fd6de19034d55df242770fcb3c46e92427ea2ffbf6b1f8cd8b0e2a6df1fe2fb1

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