This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from LuxDL/ap/operator
Migrate to an operator based implementation
- Loading branch information
Showing
18 changed files
with
863 additions
and
550 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
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,31 @@ | ||
# Low Level Wrappers | ||
for (fname, elty) in ((:cublasDgetrsBatched, :Float64), (:cublasSgetrsBatched, :Float32), | ||
(:cublasZgetrsBatched, :ComplexF64), (:cublasCgetrsBatched, :ComplexF32)) | ||
@eval begin | ||
function getrs_batched!(trans::Char, n, nrhs, Aptrs::CuVector{CuPtr{$elty}}, | ||
lda, p, Bptrs::CuVector{CuPtr{$elty}}, ldb) | ||
batchSize = length(Aptrs) | ||
info = Array{Cint}(undef, batchSize) | ||
CUBLAS.$fname( | ||
CUBLAS.handle(), trans, n, nrhs, Aptrs, lda, p, Bptrs, ldb, info, batchSize) | ||
CUDA.unsafe_free!(Aptrs) | ||
CUDA.unsafe_free!(Bptrs) | ||
return info | ||
end | ||
end | ||
end | ||
|
||
function getrs_strided_batched!(trans::Char, F::DenseCuArray{<:Any, 3}, p::DenseCuMatrix, | ||
B::Union{DenseCuArray{<:Any, 3}, DenseCuMatrix}) | ||
m, n = size(F, 1), size(F, 2) | ||
m != n && throw(DimensionMismatch("All matrices must be square!")) | ||
lda = max(1, stride(F, 2)) | ||
ldb = max(1, stride(B, 2)) | ||
nrhs = ifelse(ndims(B) == 2, 1, size(B, 2)) | ||
|
||
Fptrs = CUBLAS.unsafe_strided_batch(F) | ||
Bptrs = CUBLAS.unsafe_strided_batch(B) | ||
info = getrs_batched!(trans, n, nrhs, Fptrs, lda, p, Bptrs, ldb) | ||
|
||
return B, info | ||
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module BatchedRoutinesCUDALinearSolveExt | ||
|
||
using BatchedRoutines: UniformBlockDiagonalOperator, getdata | ||
using CUDA: CUDA | ||
using LinearAlgebra: LinearAlgebra | ||
using LinearSolve: LinearSolve | ||
|
||
const CuUniformBlockDiagonalOperator{T} = UniformBlockDiagonalOperator{ | ||
T, <:CUDA.AnyCuArray{T, 3}} | ||
|
||
function LinearSolve.init_cacheval( | ||
alg::LinearSolve.SVDFactorization, A::CuUniformBlockDiagonalOperator, b, u, Pl, Pr, | ||
maxiters::Int, abstol, reltol, verbose::Bool, ::LinearSolve.OperatorAssumptions) | ||
return nothing | ||
end | ||
|
||
function LinearSolve.init_cacheval( | ||
alg::LinearSolve.QRFactorization, A::CuUniformBlockDiagonalOperator, b, u, Pl, Pr, | ||
maxiters::Int, abstol, reltol, verbose::Bool, ::LinearSolve.OperatorAssumptions) | ||
A_ = UniformBlockDiagonalOperator(similar(getdata(A), 0, 0, 1)) | ||
return LinearAlgebra.qr!(A_) # ignore the pivot since CUDA doesn't support it | ||
end | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module BatchedRoutinesComponentArraysForwardDiffExt | ||
|
||
using BatchedRoutines: BatchedRoutines | ||
using ComponentArrays: ComponentArrays, ComponentArray | ||
using ForwardDiff: ForwardDiff | ||
|
||
@inline function BatchedRoutines._restructure(y, x::ComponentArray) | ||
x_data = ComponentArrays.getdata(x) | ||
return ComponentArray(reshape(y, size(x_data)), ComponentArrays.getaxes(x)) | ||
end | ||
|
||
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
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.