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-0.1.5.tar.gz (59.2 MB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.10 Windows x86-64

cholespy-0.1.5-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-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (986.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

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

Uploaded CPython 3.10 macOS 10.14+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

cholespy-0.1.5-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-0.1.5-cp39-cp39-macosx_11_0_arm64.whl (986.8 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

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

Uploaded CPython 3.9 macOS 10.14+ x86-64

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

Uploaded CPython 3.8 Windows x86-64

cholespy-0.1.5-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-0.1.5-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-0.1.5.tar.gz.

File metadata

  • Download URL: cholespy-0.1.5.tar.gz
  • Upload date:
  • Size: 59.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for cholespy-0.1.5.tar.gz
Algorithm Hash digest
SHA256 d819f88c1c17daaab602a52b80783e622d38b6d482dbf4126c85dfcd49be7d7c
MD5 1bfb7686e8bd00918fcd676ef62af36a
BLAKE2b-256 6776b4608ae41100c8368b2bf40b0d65ed85a9a6664c9fdcc2ab6fffbe1e5530

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cholespy-0.1.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 63a88750ab7710730867c548359803e7a7f15444d1f3c37e608fcfe5fe7f50d0
MD5 a78908fdeecb6efcff7769ffa61868b2
BLAKE2b-256 4393017a766ffc9e928e473ada5ba7a233ac04825b2bcf028b3f53d88b455b56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cholespy-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 00e5348c68ae937bdb403aa41d6755baa6b7a6050c82b6b0f31872a894156662
MD5 dfbd6a57dc5faaf3731a757aca175634
BLAKE2b-256 c2360ee6306fee7682a67df6b51f3a5ef880f8834cec1ad8ae957a03c707e45b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cholespy-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 76ce432f438d8ef58a1debebe300429bbefc1215abee5f0bac6e46e167b7b15c
MD5 0155b7817fae80ad22d3f72bf19d4b86
BLAKE2b-256 0fe2e065f7b5ed1ac672dbf4f5dfde8bc5757c849a093d1b7b887e39ac5da439

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cholespy-0.1.5-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 bd1154105affd62016850a72d50156b12494201cd460f02f402b5d985d7073c3
MD5 bdd545837ad08ca935165adaacb0d73e
BLAKE2b-256 84e5c73f3244bcc9600eecad4a4dbe209cc20070eb5875958256993c1e8ada69

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cholespy-0.1.5-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.1 CPython/3.9.13

File hashes

Hashes for cholespy-0.1.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 6e1730acc62c7c9c7ef2c14e30dbfefacd79187fb890c022bb9d39af0b4c650b
MD5 169861fcf7381aa870525fd24f2921ad
BLAKE2b-256 2452e36e8cde47e30322fd33aeee7011a8b1456c6145a1c94cc30d2c402bd0f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cholespy-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 baccf57cb37fda62e4de158d6ca49c449f8f5a0653a72d3a167b8a6583a97bcd
MD5 733cf5a733b7e495bc0c3127b243d39f
BLAKE2b-256 73ea1a75f650c27f23f8e341bc44eca20ee53d9f6157f4600a19232f27ab152f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cholespy-0.1.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d9ad73d728201bd72c167eaeb67fb8d1920de2bcffb81e733a490849236faa10
MD5 d4059bef05df2d1e6180c0b11b0eb7a4
BLAKE2b-256 d9524db8c2b66c91acbdeb351bcf939c45a1855ee034c8e8bdfbfc01cb8a99c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cholespy-0.1.5-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 5a204dae49bd44fc7d35e25dc8f4d26f240a1806165b387bea693d0b00151c5e
MD5 8501e8ce74572f25c890ae6500161ec2
BLAKE2b-256 efed24755eaa971cc3b702132b92a3830f7cde0b0d989c3330bc4598486eb727

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cholespy-0.1.5-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.1 CPython/3.9.13

File hashes

Hashes for cholespy-0.1.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 668347cd60f833e3c62603ed0c66d288826f0f5ceb91dc2c2b04411fbb28390a
MD5 04562393b78960d5015f1982162c32f5
BLAKE2b-256 5eac0ca9b88f0da8709a50b624587d2c2658ec5c5502330c948f80f9ee65f6ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cholespy-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8612d685552192e9dc3118eddb3f4f3997bf55fb8fbc5d4036b3750af61e5a09
MD5 6763f389d9e9044fc9dad5f9ff059cb8
BLAKE2b-256 1f1c5e1236ca2a747f0edb10b5dabf2a655a14e4d7253b3352df2dca4f247d66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cholespy-0.1.5-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ee8365c3c10cc408e8f0962fbdd2598a50d64670d32a008526adef05bff210bf
MD5 f44ca7d27c8955286b0b404dda0fab65
BLAKE2b-256 2ee37a8a29fed4160ae701a72677a5ea707e6f59a68462cd93b8f75f0fd0479f

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