-
-
Notifications
You must be signed in to change notification settings - Fork 72
Fix CUDSS dispatches #626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CUDSS dispatches #626
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -3,7 +3,7 @@ module LinearSolveSparseArraysExt | |||||||
using LinearSolve, LinearAlgebra | ||||||||
using SparseArrays | ||||||||
using SparseArrays: AbstractSparseMatrixCSC, nonzeros, rowvals, getcolptr | ||||||||
using LinearSolve: BLASELTYPES, pattern_changed | ||||||||
using LinearSolve: BLASELTYPES, pattern_changed, ArrayInterface | ||||||||
|
||||||||
# Can't `using KLU` because cannot have a dependency in there without | ||||||||
# requiring the user does `using KLU` | ||||||||
|
@@ -100,15 +100,31 @@ function LinearSolve.init_cacheval( | |||||||
Pl, Pr, | ||||||||
maxiters::Int, abstol, reltol, | ||||||||
verbose::Bool, assumptions::OperatorAssumptions) where {T<:BLASELTYPES} | ||||||||
SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC{T, Int64}(zero(Int64), zero(Int64), [Int64(1)], Int64[], T[])) | ||||||||
if is_cusparse(A) | ||||||||
ArrayInterface.lu_instance(A) | ||||||||
else | ||||||||
SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC{T, Int64}(zero(Int64), zero(Int64), [Int64(1)], Int64[], T[])) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
end | ||||||||
end | ||||||||
|
||||||||
function LinearSolve.init_cacheval( | ||||||||
alg::LUFactorization, A::AbstractSparseArray{T, Int32}, b, u, | ||||||||
Pl, Pr, | ||||||||
maxiters::Int, abstol, reltol, | ||||||||
verbose::Bool, assumptions::OperatorAssumptions) where {T<:BLASELTYPES} | ||||||||
SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC{T, Int32}(zero(Int32), zero(Int32), [Int32(1)], Int32[], T[])) | ||||||||
if LinearSolve.is_cusparse(A) | ||||||||
ArrayInterface.lu_instance(A) | ||||||||
else | ||||||||
SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC{T, Int32}(zero(Int32), zero(Int32), [Int32(1)], Int32[], T[])) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
end | ||||||||
end | ||||||||
|
||||||||
function LinearSolve.init_cacheval( | ||||||||
alg::LUFactorization, A::LinearSolve.GPUArraysCore.AnyGPUArray, b, u, | ||||||||
Pl, Pr, | ||||||||
maxiters::Int, abstol, reltol, | ||||||||
verbose::Bool, assumptions::OperatorAssumptions) | ||||||||
ArrayInterface.lu_instance(A) | ||||||||
end | ||||||||
|
||||||||
function LinearSolve.init_cacheval( | ||||||||
|
@@ -120,6 +136,14 @@ function LinearSolve.init_cacheval( | |||||||
PREALLOCATED_UMFPACK | ||||||||
end | ||||||||
|
||||||||
function LinearSolve.init_cacheval( | ||||||||
alg::UMFPACKFactorization, A::LinearSolve.GPUArraysCore.AnyGPUArray, b, u, | ||||||||
Pl, Pr, | ||||||||
maxiters::Int, abstol, reltol, | ||||||||
verbose::Bool, assumptions::OperatorAssumptions) | ||||||||
nothing | ||||||||
end | ||||||||
|
||||||||
function LinearSolve.init_cacheval( | ||||||||
alg::UMFPACKFactorization, A::AbstractSparseArray{T, Int64}, b, u, | ||||||||
Pl, Pr, | ||||||||
|
@@ -191,6 +215,14 @@ function LinearSolve.init_cacheval( | |||||||
PREALLOCATED_KLU | ||||||||
end | ||||||||
|
||||||||
function LinearSolve.init_cacheval( | ||||||||
alg::KLUFactorization, A::LinearSolve.GPUArraysCore.AnyGPUArray, b, u, | ||||||||
Pl, Pr, | ||||||||
maxiters::Int, abstol, reltol, | ||||||||
verbose::Bool, assumptions::OperatorAssumptions) | ||||||||
nothing | ||||||||
end | ||||||||
|
||||||||
function LinearSolve.init_cacheval( | ||||||||
alg::KLUFactorization, A::AbstractSparseArray{Float64, Int32}, b, u, Pl, Pr, | ||||||||
maxiters::Int, abstol, | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||
using LinearSolve, CUDA, LinearAlgebra, SparseArrays, StableRNGs | ||||||
using CUDA.CUSPARSE, CUDSS | ||||||
using Test | ||||||
|
||||||
CUDA.allowscalar(false) | ||||||
|
@@ -91,3 +92,17 @@ prob2 = LinearProblem(transpose(A), b) | |||||
sol = solve(prob2, alg; alias = LinearAliasSpecifier(alias_A = false)) | ||||||
@test norm(transpose(A) * sol.u .- b) < 1e-5 | ||||||
end | ||||||
|
||||||
@testset "CUDSS" begin | ||||||
T = Float32 | ||||||
n = 100 | ||||||
A_cpu = sprand(T, n, n, 0.05) + I | ||||||
x_cpu = zeros(T, n) | ||||||
b_cpu = rand(T, n) | ||||||
|
||||||
A_gpu_csr = CuSparseMatrixCSR(A_cpu) | ||||||
b_gpu = CuVector(b_cpu) | ||||||
|
||||||
prob = LinearProblem(A_gpu_csr, b_gpu) | ||||||
sol = solve(prob) | ||||||
end | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶