-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
245 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ jobs: | |
matrix: | ||
group: | ||
- All | ||
- LinearSolvePardiso | ||
version: | ||
- '1' | ||
- '1.6' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name = "LinearSolveCUDA" | ||
uuid = "0d26bed2-170e-468a-8415-1cfcbba6e180" | ||
authors = ["SciML"] | ||
version = "0.1" | ||
|
||
[deps] | ||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" | ||
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" | ||
|
||
[compat] | ||
CUDA = "3" | ||
SciMLBase = "1.25" | ||
LinearSolve = "1" | ||
julia = "1.6" | ||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module LinearSolveCUDA | ||
|
||
using CUDA, LinearAlgebra, LinearSolve, SciMLBase | ||
|
||
struct CudaOffloadFactorization <: LinearSolve.AbstractFactorization end | ||
|
||
function SciMLBase.solve(cache::LinearSolve.LinearCache, alg::CudaOffloadFactorization; kwargs...) | ||
if cache.isfresh | ||
fact = LinearSolve.do_factorization(alg, CUDA.CuArray(cache.A), cache.b, cache.u) | ||
cache = LinearSolve.set_cacheval(cache, fact) | ||
end | ||
|
||
copyto!(cache.u, cache.b) | ||
y = Array(ldiv!(cache.cacheval, CUDA.CuArray(cache.u))) | ||
SciMLBase.build_linear_solution(alg, y, nothing, cache) | ||
end | ||
|
||
function LinearSolve.do_factorization(alg::CudaOffloadFactorization, A, b, u) | ||
A isa Union{AbstractMatrix,AbstractDiffEqOperator} || | ||
error("LU is not defined for $(typeof(A))") | ||
|
||
if A isa AbstractDiffEqOperator | ||
A = A.A | ||
end | ||
fact = qr(CUDA.CuArray(A)) | ||
return fact | ||
end | ||
|
||
export CudaOffloadFactorization | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,41 @@ | ||
using LinearSolve, LinearAlgebra, SparseArrays | ||
using CUDA | ||
using Test | ||
|
||
n = 8 | ||
A = Matrix(I,n,n) | ||
b = ones(n) | ||
A1 = A/1; b1 = rand(n); x1 = zero(b) | ||
A2 = A/2; b2 = rand(n); x2 = zero(b) | ||
|
||
prob1 = LinearProblem(A1, b1; u0=x1) | ||
prob2 = LinearProblem(A2, b2; u0=x2) | ||
|
||
cache_kwargs = (;verbose=true, abstol=1e-8, reltol=1e-8, maxiter=30,) | ||
|
||
function test_interface(alg, prob1, prob2) | ||
A1 = prob1.A; b1 = prob1.b; x1 = prob1.u0 | ||
A2 = prob2.A; b2 = prob2.b; x2 = prob2.u0 | ||
|
||
y = solve(prob1, alg; cache_kwargs...) | ||
@test A1 * y ≈ b1 | ||
|
||
cache = SciMLBase.init(prob1,alg; cache_kwargs...) # initialize cache | ||
y = solve(cache) | ||
@test A1 * y ≈ b1 | ||
|
||
cache = LinearSolve.set_A(cache,copy(A2)) | ||
y = solve(cache) | ||
@test A2 * y ≈ b1 | ||
|
||
cache = LinearSolve.set_b(cache,b2) | ||
y = solve(cache) | ||
@test A2 * y ≈ b2 | ||
|
||
return | ||
end | ||
|
||
test_interface(GPUOffloadFactorization(), prob1, prob2) | ||
|
||
A1 = prob1.A; b1 = prob1.b; x1 = prob1.u0 | ||
y = solve(prob1) | ||
@test A1 * y ≈ b1 | ||
using LinearSolve, LinearSolveCUDA, LinearAlgebra, SparseArrays | ||
using Test | ||
|
||
n = 8 | ||
A = Matrix(I,n,n) | ||
b = ones(n) | ||
A1 = A/1; b1 = rand(n); x1 = zero(b) | ||
A2 = A/2; b2 = rand(n); x2 = zero(b) | ||
|
||
prob1 = LinearProblem(A1, b1; u0=x1) | ||
prob2 = LinearProblem(A2, b2; u0=x2) | ||
|
||
cache_kwargs = (;verbose=true, abstol=1e-8, reltol=1e-8, maxiter=30,) | ||
|
||
function test_interface(alg, prob1, prob2) | ||
A1 = prob1.A; b1 = prob1.b; x1 = prob1.u0 | ||
A2 = prob2.A; b2 = prob2.b; x2 = prob2.u0 | ||
|
||
y = solve(prob1, alg; cache_kwargs...) | ||
@test A1 * y ≈ b1 | ||
|
||
cache = SciMLBase.init(prob1,alg; cache_kwargs...) # initialize cache | ||
y = solve(cache) | ||
@test A1 * y ≈ b1 | ||
|
||
cache = LinearSolve.set_A(cache,copy(A2)) | ||
y = solve(cache) | ||
@test A2 * y ≈ b1 | ||
|
||
cache = LinearSolve.set_b(cache,b2) | ||
y = solve(cache) | ||
@test A2 * y ≈ b2 | ||
|
||
return | ||
end | ||
|
||
test_interface(CudaOffloadFactorization(), prob1, prob2) | ||
|
||
A1 = prob1.A; b1 = prob1.b; x1 = prob1.u0 | ||
y = solve(prob1) | ||
@test A1 * y ≈ b1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name = "LinearSolvePardiso" | ||
uuid = "a6722589-28b8-4472-944e-bde9ee6da670" | ||
authors = ["SciML"] | ||
version = "0.1" | ||
|
||
[deps] | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" | ||
Pardiso = "46dd5b70-b6fb-5a00-ae2d-e8fea33afaf2" | ||
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" | ||
|
||
[compat] | ||
SciMLBase = "1.25" | ||
LinearSolve = "1" | ||
Pardiso = "0.5" | ||
julia = "1.6" | ||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.