11module LinearSolveCUDAExt
22
3- using CUDA
3+ using cuSOLVER
4+ CUDACore = cuSOLVER. CUDACore
5+ cuSPARSE = cuSOLVER. cuSPARSE
6+
47using LinearSolve: LinearSolve, is_cusparse, defaultalg, cudss_loaded, DefaultLinearSolver,
58 DefaultAlgorithmChoice, ALREADY_WARNED_CUDSS, LinearCache,
69 needs_concrete_A,
@@ -11,20 +14,20 @@ using LinearSolve: LinearSolve, is_cusparse, defaultalg, cudss_loaded, DefaultLi
1114using LinearSolve. LinearAlgebra, LinearSolve. SciMLBase, LinearSolve. ArrayInterface
1215using SciMLBase: AbstractSciMLOperator
1316
14- LinearSolve. usecuda (x:: Nothing ) = CUDA . functional ()
17+ LinearSolve. usecuda (x:: Nothing ) = CUDACore . functional ()
1518
1619function LinearSolve. is_cusparse (
1720 A:: Union {
18- CUDA . CUSPARSE . CuSparseMatrixCSR, CUDA . CUSPARSE . CuSparseMatrixCSC,
21+ cuSPARSE . CuSparseMatrixCSR, cuSPARSE . CuSparseMatrixCSC,
1922 }
2023 )
2124 return true
2225end
23- LinearSolve. is_cusparse_csr (:: CUDA.CUSPARSE .CuSparseMatrixCSR ) = true
24- LinearSolve. is_cusparse_csc (:: CUDA.CUSPARSE .CuSparseMatrixCSC ) = true
26+ LinearSolve. is_cusparse_csr (:: cuSPARSE .CuSparseMatrixCSR ) = true
27+ LinearSolve. is_cusparse_csc (:: cuSPARSE .CuSparseMatrixCSC ) = true
2528
2629function LinearSolve. defaultalg (
27- A:: CUDA.CUSPARSE .CuSparseMatrixCSR{Tv, Ti} , b,
30+ A:: cuSPARSE .CuSparseMatrixCSR{Tv, Ti} , b,
2831 assump:: OperatorAssumptions{Bool}
2932 ) where {Tv, Ti}
3033 return if LinearSolve. cudss_loaded (A)
@@ -39,7 +42,7 @@ function LinearSolve.defaultalg(
3942end
4043
4144function LinearSolve. defaultalg (
42- A:: CUDA.CUSPARSE .CuSparseMatrixCSC , b,
45+ A:: cuSPARSE .CuSparseMatrixCSC , b,
4346 assump:: OperatorAssumptions{Bool}
4447 )
4548 if LinearSolve. cudss_loaded (A)
@@ -50,7 +53,7 @@ function LinearSolve.defaultalg(
5053 return LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. KrylovJL_GMRES)
5154end
5255
53- function LinearSolve. error_no_cudss_lu (A:: CUDA.CUSPARSE .CuSparseMatrixCSR )
56+ function LinearSolve. error_no_cudss_lu (A:: cuSPARSE .CuSparseMatrixCSR )
5457 if ! LinearSolve. cudss_loaded (A)
5558 error (" CUDSS.jl is required for LU Factorizations on CuSparseMatrixCSR. Please load this library." )
5659 end
@@ -63,12 +66,12 @@ function SciMLBase.solve!(
6366 )
6467 if cache. isfresh
6568 cacheval = LinearSolve. @get_cacheval (cache, :CudaOffloadLUFactorization )
66- fact = lu (CUDA . CuArray (cache. A))
69+ fact = lu (CUDACore . CuArray (cache. A))
6770 cache. cacheval = fact
6871 cache. isfresh = false
6972 end
7073 fact = LinearSolve. @get_cacheval (cache, :CudaOffloadLUFactorization )
71- y = Array (ldiv! (CUDA . CuArray (cache. u), fact, CUDA . CuArray (cache. b)))
74+ y = Array (ldiv! (CUDACore . CuArray (cache. u), fact, CUDACore . CuArray (cache. b)))
7275 cache. u .= y
7376 return SciMLBase. build_linear_solution (alg, y, nothing , cache)
7477end
@@ -79,28 +82,28 @@ function LinearSolve.init_cacheval(
7982 assumptions:: OperatorAssumptions
8083 )
8184 # Check if CUDA is functional before creating CUDA arrays
82- if ! CUDA . functional ()
85+ if ! CUDACore . functional ()
8386 return nothing
8487 end
8588
8689 T = eltype (A)
8790 noUnitT = typeof (zero (T))
8891 luT = LinearAlgebra. lutype (noUnitT)
89- ipiv = CuVector {Int32} (undef, 0 )
92+ ipiv = CUDACore . CuVector {Int32} (undef, 0 )
9093 info = zero (LinearAlgebra. BlasInt)
91- return LU {luT} (CuMatrix {Float64} (undef, 0 , 0 ), ipiv, info)
94+ return LU {luT} (CUDACore . CuMatrix {Float64} (undef, 0 , 0 ), ipiv, info)
9295end
9396
9497function SciMLBase. solve! (
9598 cache:: LinearSolve.LinearCache , alg:: CudaOffloadQRFactorization ;
9699 kwargs...
97100 )
98101 if cache. isfresh
99- fact = qr (CUDA . CuArray (cache. A))
102+ fact = qr (CUDACore . CuArray (cache. A))
100103 cache. cacheval = fact
101104 cache. isfresh = false
102105 end
103- y = Array (ldiv! (CUDA . CuArray (cache. u), cache. cacheval, CUDA . CuArray (cache. b)))
106+ y = Array (ldiv! (CUDACore . CuArray (cache. u), cache. cacheval, CUDACore . CuArray (cache. b)))
104107 cache. u .= y
105108 return SciMLBase. build_linear_solution (alg, y, nothing , cache)
106109end
@@ -111,11 +114,11 @@ function LinearSolve.init_cacheval(
111114 assumptions:: OperatorAssumptions
112115 )
113116 # Check if CUDA is functional before creating CUDA arrays
114- if ! CUDA . functional ()
117+ if ! CUDACore . functional ()
115118 return nothing
116119 end
117120
118- return qr (CUDA . CuArray (A))
121+ return qr (CUDACore . CuArray (A))
119122end
120123
121124# Keep the deprecated CudaOffloadFactorization working by forwarding to QR
@@ -124,11 +127,11 @@ function SciMLBase.solve!(
124127 kwargs...
125128 )
126129 if cache. isfresh
127- fact = qr (CUDA . CuArray (cache. A))
130+ fact = qr (CUDACore . CuArray (cache. A))
128131 cache. cacheval = fact
129132 cache. isfresh = false
130133 end
131- y = Array (ldiv! (CUDA . CuArray (cache. u), cache. cacheval, CUDA . CuArray (cache. b)))
134+ y = Array (ldiv! (CUDACore . CuArray (cache. u), cache. cacheval, CUDACore . CuArray (cache. b)))
132135 cache. u .= y
133136 return SciMLBase. build_linear_solution (alg, y, nothing , cache)
134137end
@@ -138,19 +141,19 @@ function LinearSolve.init_cacheval(
138141 maxiters:: Int , abstol, reltol, verbose:: Union{LinearVerbosity, Bool} ,
139142 assumptions:: OperatorAssumptions
140143 )
141- return qr (CUDA . CuArray (A))
144+ return qr (CUDACore . CuArray (A))
142145end
143146
144147for AlgType in (SparspakFactorization, LinearSolve. QRFactorization)
145148 @eval function LinearSolve. init_cacheval (
146- :: $AlgType , A:: CUDA.CUSPARSE .CuSparseMatrixCSR , b, u,
149+ :: $AlgType , A:: cuSPARSE .CuSparseMatrixCSR , b, u,
147150 Pl, Pr, maxiters:: Int , abstol, reltol,
148151 verbose:: Union{LinearVerbosity, Bool} , assumptions:: OperatorAssumptions
149152 )
150153 return nothing
151154 end
152155 @eval function LinearSolve. init_cacheval (
153- :: $AlgType , A:: CUDA.CUSPARSE .CuSparseMatrixCSC , b, u,
156+ :: $AlgType , A:: cuSPARSE .CuSparseMatrixCSC , b, u,
154157 Pl, Pr, maxiters:: Int , abstol, reltol,
155158 verbose:: Union{LinearVerbosity, Bool} , assumptions:: OperatorAssumptions
156159 )
@@ -159,14 +162,14 @@ for AlgType in (SparspakFactorization, LinearSolve.QRFactorization)
159162end
160163
161164function LinearSolve. init_cacheval (
162- :: KLUFactorization , A:: CUDA.CUSPARSE .CuSparseMatrixCSR , b, u,
165+ :: KLUFactorization , A:: cuSPARSE .CuSparseMatrixCSR , b, u,
163166 Pl, Pr, maxiters:: Int , abstol, reltol, verbose:: Union{LinearVerbosity, Bool} , assumptions:: OperatorAssumptions
164167 )
165168 return nothing
166169end
167170
168171function LinearSolve. init_cacheval (
169- :: UMFPACKFactorization , A:: CUDA.CUSPARSE .CuSparseMatrixCSR , b, u,
172+ :: UMFPACKFactorization , A:: cuSPARSE .CuSparseMatrixCSR , b, u,
170173 Pl, Pr, maxiters:: Int , abstol, reltol, verbose:: Union{LinearVerbosity, Bool} , assumptions:: OperatorAssumptions
171174 )
172175 return nothing
0 commit comments