Linear Algebra with CUDA

Linac is a Python library for GPU-accelerated linear algebra using CUDA. Its main functionality is dense Gaussian elimination to row-reduced echelon form, with support for real and complex floating-point arithmetic, finite fields, and leading-digit p-adic workflows.

The package was developed for applications to finite-field reconstruction of scattering amplitude in quantum field theory, but the core routines are general-purpose tools for dense linear algebra over the supported arithmetic domains.

Main features

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]"

The available extras are

cuda, dev, full (= cuda + dev)

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

Quick start

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

1import numpy
2from linac import cuda_row_reduce
3
4p = 2**31 - 1
5
6A = numpy.random.randint(0, p, size=(2000, 2000), dtype="uint32")
7rref = cuda_row_reduce(A, field_characteristic=p)

Setting field_characteristic=0 selects floating-point arithmetic.

1import numpy
2from linac import cuda_row_reduce
3
4A = numpy.random.rand(2000, 2000)
5rref = cuda_row_reduce(A, field_characteristic=0)

For CPU row reduction, use linac.row_reduce().

1from linac import row_reduce
2
3rref, variable_order = row_reduce(A, prime=p)

Constructing linear systems

Linac also provides utilities for constructing dense matrices from polynomial ansätze. These are useful when fitting unknown coefficients from numerical evaluations.

1from linac import load_matrices
2
3matrices = load_matrices(prefactors, ansatze, points, use_cuda=True)

For lower-level GPU matrix construction, see linac.cuda_load_matrix().

Documentation contents

Indices and tables