Skip to main content

Linear Algebra with CUDA

Project description

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.1.tar.gz (42.0 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.1-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: linac-1.0.1.tar.gz
  • Upload date:
  • Size: 42.0 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.1.tar.gz
Algorithm Hash digest
SHA256 3679915b4432ebf8dee270e638610f730914069d14d17830b79bddc231d08c3f
MD5 a72c48aed988eca20e0dd64928497aa7
BLAKE2b-256 5f6186d2a986634891b19cbf9d5e5dabebe2cbabbb18f40743ef5626efb94e3a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linac-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e1c275b8d6d215f678c3ea04ff25b1ab7ac9f5791060bfb42f940a6c7a2eec27
MD5 b383097fb21ea189c3ae058f3c48bdd6
BLAKE2b-256 b28f7525225be66600b3b59504437aa678d83ab1ab5785b2011c6c2115508648

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