SciML / LinearSolve.jl

LinearSolve.jl: High-Performance Unified Interface for Linear Solvers in Julia. Easily switch between factorization and Krylov methods, add preconditioners, and all in one interface.
https://docs.sciml.ai/LinearSolve/stable/
Other
235 stars 51 forks source link

Symbolic Factorization Reuse in the standard LUFactorization #493

Closed ChrisRackauckas closed 2 months ago

ChrisRackauckas commented 3 months ago

This should be sufficient for CUDSS.jl to be optimally used as well

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 51.85185% with 39 lines in your changes are missing coverage. Please review.

Project coverage is 62.61%. Comparing base (d050e01) to head (084d0d6).

Files Patch % Lines
ext/LinearSolveCUDAExt.jl 0.00% 27 Missing :warning:
src/LinearSolve.jl 78.43% 11 Missing :warning:
ext/LinearSolveCUDSSExt.jl 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #493 +/- ## =========================================== + Coverage 25.10% 62.61% +37.50% =========================================== Files 28 29 +1 Lines 2167 2212 +45 =========================================== + Hits 544 1385 +841 + Misses 1623 827 -796 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

ChrisRackauckas commented 3 months ago

This is hard to test, but it is now working with CUDSS and I can check the symbolic factorizations are reused! MWE:

using CUDA, CUDA.CUSPARSE
using CUDSS
using SparseArrays, LinearAlgebra
using LinearSolve

T = Float64
n = 100
A_cpu = sprand(T, n, n, 0.05) + I
x_cpu = zeros(T, n)
b_cpu = rand(T, n)

A_gpu = CuSparseMatrixCSR(A_cpu)
x_gpu = CuVector(x_cpu)
b_gpu = CuVector(b_cpu)
prob = LinearProblem(A_gpu, b_gpu)
sol = solve(prob, LUFactorization())

cache = init(prob, LUFactorization())
solve!(cache)
cache.b = CuVector(rand(T, n))
solve!(cache)
cache.A = CuSparseMatrixCSR(A_cpu + 3I)
solve!(cache)
cache.b = CuVector(rand(T, n))
solve!(cache)

This is with https://github.com/JuliaArrays/ArrayInterface.jl/pull/433 and https://github.com/exanauts/CUDSS.jl/pull/33