A self-contained sparse Cholesky solver, compatible with CPU and GPU tensor frameworks.
Project description
What is this repo?
This is a minimalistic, self-contained sparse Cholesky solver, supporting solving both on the CPU and on the GPU, easily integrable in your tensor pipeline.
When we were working on our "Large Steps in Inverse Rendering of Geometry" paper
[1], we found it quite challenging to hook up an existing sparse
linear solver to our pipeline, and we managed to do so by adding dependencies on
large projects (i.e. cusparse
and scikit-sparse
), only to use a small part
of its functionality. Therefore, we decided to implement our own library, that
serves one purpose: efficiently solving sparse linear systems on the GPU or CPU,
using a Cholesky factorization.
Under the hood, it relies on CHOLMOD for sparse matrix factorization. For the solving phase, it uses CHOLMOD for the CPU version, and uses the result of an analysis step run once when building the solver for fast solving on the GPU [2].
It achieves comparable performance as other frameworks, with the dependencies nicely shipped along.
The Python bindings are generated with nanobind, which makes it easily interoperable with most tensor frameworks (Numpy, PyTorch, JAX...)
Installing
With PyPI (recommended)
pip install cholespy
From source
git clone --recursive https://github.com/rgl-epfl/cholespy
pip install ./cholespy
Documentation
There is only one class in the module, with two variants: CholeskySolverF, CholeskySolverD
. The only difference is that CholeskySolverF
solves the
system in single precision while CholeskySolverD
uses double precision. This
is mostly useful for solving on the GPU, as the CPU version relies on CHOLMOD,
which only supports double precision anyway.
The most common tensor frameworks (PyTorch, NumPy, TensorFlow...) are supported out of the box. You can pass them directly to the module without any need for manual conversion.
Since both variants have the same signature, we only detail CholeskySolverF
below:
cholespy.CholeskySolverF(n_rows, ii, jj, x, type)
Parameters:
n_rows
- The number of rows in the (sparse) matrix.ii
- The first array of indices in the sparse matrix representation. Iftype
isCOO
, then this is the array of row indices. If it isCSC
(resp.CSR
), then it is the array of column (resp. row) indices, such that row (resp. column) indices for column (resp. row)k
are stored injj[ii[k]:ii[k+1]]
and the corresponding entries are inx[ii[k]:ii[k+1]]
.jj
- The second array of indices in the sparse matrix representation. Iftype
isCOO
, then this is the array of column indices. If it isCSC
(resp.CSR
), then it is the array of row (resp. column) indices.x
- The array of nonzero entries.type
- The matrix representation type, of typeMatrixType
. Available types areMatrixType.COO
,MatrixType.CSC
andMatrixType.CSR
.
cholespy.CholeskySolverF.solve(b, x)
Parameters
b
- Right-hand side of the equation to solve. Can be a vector or a matrix. If it is a matrix, it must be of shape(n_rows, n_rhs)
. It must be on the same device as the tensors passed to the solver constructor. If using CUDA arrays, then the maximum supported value forn_rhs
is128
.x
- Placeholder for the solution. It must be on the same device and have the same shape asb
.
x
and b
must have the same dtype as the solver used, i.e. float32
for
CholeskySolverF
or float64
for CholeskySolver64
. Since x
is modified in
place, implicit type conversion is not supported.
Example usage
from cholespy import CholeskySolverF, MatrixType
import torch
# Identity matrix
n_rows = 20
rows = torch.arange(n_rows, device='cuda')
cols = torch.arange(n_rows, device='cuda')
data = torch.ones(n_rows, device='cuda')
solver = CholeskySolverF(n_rows, rows, cols, data, MatrixType.COO)
b = torch.ones(n_rows, device='cuda')
x = torch.zeros_like(b)
solver.solve(b, x)
# b = [1, ..., 1]
References
[1] Nicolet, B., Jacobson, A., & Jakob, W. (2021). Large steps in inverse rendering of geometry. ACM Transactions on Graphics (TOG), 40(6), 1-13.
[2] Naumov, M. (2011). Parallel solution of sparse triangular linear systems in the preconditioned iterative methods on the GPU. NVIDIA Corp., Westford, MA, USA, Tech. Rep. NVR-2011, 1.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file cholespy-0.1.1.tar.gz
.
File metadata
- Download URL: cholespy-0.1.1.tar.gz
- Upload date:
- Size: 59.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eae67210d8f44851e1a0dd13634c2e51eef0fd55e4ce29e97aaf9eb2db0fb865 |
|
MD5 | b081cbb0790b60b24759d05e5828afef |
|
BLAKE2b-256 | 5b47b44f21f1161b60f45edaa21da8d66f6af5b8d300f02dd027c4789c36af0a |
File details
Details for the file cholespy-0.1.1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: cholespy-0.1.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58a67cb943945f661e39288b43c8e2337567cbe35c7e9a2c9c14d93da7de75e6 |
|
MD5 | 279449aa065dd894cd80ed50a39ac1ac |
|
BLAKE2b-256 | 0cce54d5f4954d09ab2b156bf5c6f1aadaf3161bf6eeb08d501a2ec345804705 |
File details
Details for the file cholespy-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cholespy-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f55a3e3863e5be8d39a1d502220d82c46f6f1d3d79ca4e5814d15173da4f3c59 |
|
MD5 | 318b8f1211391595abdca05c82c076c7 |
|
BLAKE2b-256 | 882bddcd4f59b86c18a65284b952442b6e04814426a1604dd7101d866e54dfca |
File details
Details for the file cholespy-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: cholespy-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 183.7 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c440ad966dabae24afc00c645a3ad54b01560999f3acafd9d7c89a09e15d1c0 |
|
MD5 | aba52c270a0fffd2700efd39cbaba551 |
|
BLAKE2b-256 | 8117555aff5f31af7e6f85aca81e88db45d4b10ff9fd1463c09c6630ba8b5ffd |
File details
Details for the file cholespy-0.1.1-cp310-cp310-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: cholespy-0.1.1-cp310-cp310-macosx_10_14_x86_64.whl
- Upload date:
- Size: 220.5 kB
- Tags: CPython 3.10, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e57e19d91105c069f7a460d857262e330cd922cbc3d78ba7cc9751b99e3aaf3e |
|
MD5 | 356a70b0acb37795bd9248a15590bc2a |
|
BLAKE2b-256 | d0ca2db8df21cd8543c1c0a995a3b27c0f8831f079dfc8b2f68e0851ad022982 |
File details
Details for the file cholespy-0.1.1-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: cholespy-0.1.1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53bd6ff1ff1b742dadd39b5b57b1ff0d67eb1dfe9c4b71cf81fa1555cf5b4f42 |
|
MD5 | 224a33350e35486f6be5876d57d643a8 |
|
BLAKE2b-256 | 78fdf6e23168e183dc8693f3593f60394a3a0e79afa8862586d0b1d0cbcd0602 |
File details
Details for the file cholespy-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cholespy-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e5b6b2dcb18babc70adad708b845c6c985331a86b10efdbec1b3fb9a8bf1b7d |
|
MD5 | 9b0d5be0937ff8c8ea0fc478cbc5e3d7 |
|
BLAKE2b-256 | 07f4fc49b5b257c12cc13694261f51783c674785a9eba7c0bc6f9ff8f9c05e13 |
File details
Details for the file cholespy-0.1.1-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: cholespy-0.1.1-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 183.7 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f85bc7dd166dce3714b6341215c815744f38973854030b3716cbfdaa8162ced |
|
MD5 | 1a8cb240a4da20be3e9b4c2742c41f1d |
|
BLAKE2b-256 | 2571835d483075758db3c0a1edef88b6b84a7037641b879b2128e4ef9ce27450 |
File details
Details for the file cholespy-0.1.1-cp39-cp39-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: cholespy-0.1.1-cp39-cp39-macosx_10_14_x86_64.whl
- Upload date:
- Size: 220.5 kB
- Tags: CPython 3.9, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 161c313c6b8ddd4a56c793b3f7460ad4f7025b8ca8e18c34aff8c4b39cb5e529 |
|
MD5 | 54ee075ff3de30d80b66f110556755a8 |
|
BLAKE2b-256 | 79728e17ea2b31d2d7a137146e489e27cca1b62068dcb1fb01c94c70dede3c44 |
File details
Details for the file cholespy-0.1.1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: cholespy-0.1.1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc58cf459c8cf71d6a2f87baa608bd49e8c081037353f30499f545db23aed205 |
|
MD5 | 2e751e2fb633adb460354a9c03210566 |
|
BLAKE2b-256 | bb0a21e0530902b78f2a83809f9de25b5e137cc7ef557b6c9fc920f68599cdb8 |
File details
Details for the file cholespy-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cholespy-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80912be2207a78644a2dc4a77e96f372a2cd7816b538fa1264e4c545dab78442 |
|
MD5 | 7b0ef725a28a153e1de9f768c49f1937 |
|
BLAKE2b-256 | 79047c98c2aebcf39444a43abb0a9a631c6e94837f01efcb922200f171b05a20 |
File details
Details for the file cholespy-0.1.1-cp38-cp38-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: cholespy-0.1.1-cp38-cp38-macosx_10_14_x86_64.whl
- Upload date:
- Size: 220.4 kB
- Tags: CPython 3.8, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65fdcee4e98a752cf38827033580bd9124fb8282f09c3ba4e7818043ab423733 |
|
MD5 | cb0e089cb3964c5f7abbb0d2679a2c26 |
|
BLAKE2b-256 | 09e39dc28c9616f7d986ccbb95d61de6d2dca35bd98b7f2b8efc87427b74057e |