Skip to main content

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.


Benchmark

Benchmark run on a Linux Ryzen 3990X workstation with a TITAN RTX.


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. If type is COO, then this is the array of row indices. If it is CSC (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 in jj[ii[k]:ii[k+1]] and the corresponding entries are in x[ii[k]:ii[k+1]].
  • jj - The second array of indices in the sparse matrix representation. If type is COO, then this is the array of column indices. If it is CSC (resp. CSR), then it is the array of row (resp. column) indices.
  • x - The array of nonzero entries.
  • type - The matrix representation type, of type MatrixType. Available types are MatrixType.COO, MatrixType.CSC and MatrixType.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 for n_rhs is 128.
  • x - Placeholder for the solution. It must be on the same device and have the same shape as b.

x and b must have the same dtype as the solver used, i.e. float32 for CholeskySolverF or float64 for CholeskySolverD. 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


Download files

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

Source Distribution

cholespy-1.0.0.tar.gz (61.6 MB view details)

Uploaded Source

Built Distributions

cholespy-1.0.0-cp310-cp310-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.10 Windows x86-64

cholespy-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

cholespy-1.0.0-cp310-cp310-macosx_11_0_arm64.whl (993.5 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

cholespy-1.0.0-cp310-cp310-macosx_10_14_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10 macOS 10.14+ x86-64

cholespy-1.0.0-cp39-cp39-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.9 Windows x86-64

cholespy-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

cholespy-1.0.0-cp39-cp39-macosx_11_0_arm64.whl (993.6 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

cholespy-1.0.0-cp39-cp39-macosx_10_14_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

cholespy-1.0.0-cp38-cp38-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.8 Windows x86-64

cholespy-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

cholespy-1.0.0-cp38-cp38-macosx_10_14_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: cholespy-1.0.0.tar.gz
  • Upload date:
  • Size: 61.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for cholespy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ac2986ee1d3f0224fce8b1b53c7faf98b4c66474332ab72e2cddc7ad17168109
MD5 ae84728f7c5bfdf5f23a17d8918e082a
BLAKE2b-256 7c7b06e06191f6b2efbccf7bcd7a23d96d51cc715ad10efe0e4b4406fe93a172

See more details on using hashes here.

File details

Details for the file cholespy-1.0.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for cholespy-1.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 03f1e9b1e088f0617175f06d1f18eaff7a8b72de2f77f43423ecb906361ed73c
MD5 d9e17ee2e74d4673c7a69714d9313454
BLAKE2b-256 4a9f3b3f8501a373503c30a0eb8db1a3e2b90cba3e7d3fbdc4f3ca7763d4675e

See more details on using hashes here.

File details

Details for the file cholespy-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cholespy-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1818976af3eab590f4cd163dec9f89933fb49f732f528f849769d5bcdfcd6dd0
MD5 136fe7d84c12ea39812239d7c880086f
BLAKE2b-256 1fa6bb86b816eb2c2491f3d7bf4c95ed52fbea9bc3e4c16b5c89b3a5cb4876ec

See more details on using hashes here.

File details

Details for the file cholespy-1.0.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cholespy-1.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5286b52d4d1f59614b5c3548b4ef6c8ee7359040e6ae929603de9087ac4e8471
MD5 ceb9884b121ae12e9c4f063ec5ca77b4
BLAKE2b-256 392149c87aa778e2ae0b6dc9f44f2f37091b05e0e27c14a9df7a7023883cd41c

See more details on using hashes here.

File details

Details for the file cholespy-1.0.0-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for cholespy-1.0.0-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 08500bc0263ab455f42e96b8bcec0418a5e6de0bd29f88c3351261048030e12f
MD5 4c859d0f907abe1e007a2c1ba2189af7
BLAKE2b-256 8d26d8a5bc5ce779205151053d36006c2151d35f7e3cdf4122757823bd18346b

See more details on using hashes here.

File details

Details for the file cholespy-1.0.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: cholespy-1.0.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for cholespy-1.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 07ab1cb9a7d0cd4841195f6fb33361abb1550f0b3fa90fcc4e61f2fb1644f6c0
MD5 d80e6cf06b3233da8db121156c794e88
BLAKE2b-256 763923a22e31d1924e2bbee629e8aa4a57a140bf423136ba6a3f1bbea3a3fd5d

See more details on using hashes here.

File details

Details for the file cholespy-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cholespy-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c1569676cf77fd294a026a6125830641845baa60e80b4804e2f7bd8e8ba2a318
MD5 64961756e8065997f882e42d1d88f3b7
BLAKE2b-256 be5d1479ea0763655892f363096dccf7c54fb431b8215a1826adc3e122da8718

See more details on using hashes here.

File details

Details for the file cholespy-1.0.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cholespy-1.0.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c14304fc6a66247227423e689a4dd20498711ba22588a35a1f1edb5f133ef3d2
MD5 a6c64dcd2849304c2fca1cc96ef10853
BLAKE2b-256 641972b81fa834d9d73d9a20ae10c9875f1685bbe4e6808ef01b182786b9f6b9

See more details on using hashes here.

File details

Details for the file cholespy-1.0.0-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for cholespy-1.0.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 750573458495740927b326227a0b58f9ef7bc14ebfcf548ad0b8cfa90d992d46
MD5 89172b27521851bb321fe0be0ca2469e
BLAKE2b-256 a2bc0bdf4e3299102d00146226356b4e0a26ab3fc11ca6511fb1739aaa3bf738

See more details on using hashes here.

File details

Details for the file cholespy-1.0.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: cholespy-1.0.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for cholespy-1.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 39477dab9ebdc0fa5e9d8e39ac2096917d06ecbcdcd17e6612e72c68643f78fb
MD5 5e227745ef13dbd537b58bcc39474246
BLAKE2b-256 9f3950dd1dbd363c06a0cf076f3cb78d34d87dd457a71bd4d72a3bcae33d1e2b

See more details on using hashes here.

File details

Details for the file cholespy-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cholespy-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e5b2c1ba775637622d0c8562a227fb65aecb149768fbdaf7ab0773b5c03f8fa1
MD5 9ea03f69e87994b776bcb85ccb66c303
BLAKE2b-256 a1689be740ebdbce3186fe60ee664949db9ceac640eec4363f653227a25bac23

See more details on using hashes here.

File details

Details for the file cholespy-1.0.0-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for cholespy-1.0.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 82c525f5f163432642cbbce97cd8cd5240654684cf65241e565e0c9ed4bb52e0
MD5 a441394a6a45e4aa544095eff0201f00
BLAKE2b-256 35a64689f6487caa5065cd1657cba85eb4d4e82906e13985a9120358374921de

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page