-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NDTensors] Remove and test for scalar indexing on GPU (#1245)
- Loading branch information
Showing
23 changed files
with
296 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Same definition as `MtlArray`. | ||
function Base.copy(src::Exposed{<:CuArray,<:Base.ReshapedArray}) | ||
return reshape(copy(parent(src)), size(unexpose(src))) | ||
end | ||
|
||
function Base.copy( | ||
src::Exposed{ | ||
<:CuArray,<:SubArray{<:Any,<:Any,<:Base.ReshapedArray{<:Any,<:Any,<:Adjoint}} | ||
}, | ||
) | ||
return copy(@view copy(expose(parent(src)))[parentindices(unexpose(src))...]) | ||
end | ||
|
||
# Catches a bug in `copyto!` in CUDA backend. | ||
function Base.copyto!(dest::Exposed{<:CuArray}, src::Exposed{<:CuArray,<:SubArray}) | ||
copyto!(dest, expose(copy(src))) | ||
return unexpose(dest) | ||
end | ||
|
||
# Catches a bug in `copyto!` in CUDA backend. | ||
function Base.copyto!( | ||
dest::Exposed{<:CuArray}, src::Exposed{<:CuArray,<:Base.ReshapedArray} | ||
) | ||
copyto!(dest, expose(parent(src))) | ||
return unexpose(dest) | ||
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
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,43 @@ | ||
# This was calling generic matrix multiplication. | ||
# TODO: Raise an issue with `CUDA.jl`. | ||
function LinearAlgebra.mul!( | ||
CM::Exposed{<:CuArray,<:LinearAlgebra.Transpose}, | ||
AM::Exposed{<:CuArray}, | ||
BM::Exposed{<:CuArray}, | ||
α, | ||
β, | ||
) | ||
mul!(transpose(CM), transpose(BM), transpose(AM), α, β) | ||
return unexpose(CM) | ||
end | ||
|
||
# This was calling generic matrix multiplication. | ||
# TODO: Raise an issue with `CUDA.jl`. | ||
function LinearAlgebra.mul!( | ||
CM::Exposed{<:CuArray,<:LinearAlgebra.Adjoint}, | ||
AM::Exposed{<:CuArray}, | ||
BM::Exposed{<:CuArray}, | ||
α, | ||
β, | ||
) | ||
mul!(CM', BM', AM', α, β) | ||
return unexpose(CM) | ||
end | ||
|
||
## Fix issue in CUDA.jl where it cannot distinguish Transpose{Reshape{Adjoint{CuArray}}} | ||
## as a CuArray and calls generic matmul | ||
function LinearAlgebra.mul!( | ||
CM::Exposed{<:CuArray}, | ||
AM::Exposed{<:CuArray}, | ||
BM::Exposed{ | ||
<:CuArray, | ||
<:LinearAlgebra.Transpose{ | ||
<:Any,<:Base.ReshapedArray{<:Any,<:Any,<:LinearAlgebra.Adjoint} | ||
}, | ||
}, | ||
α, | ||
β, | ||
) | ||
mul!(CM, AM, expose(transpose(copy(expose(parent(BM))))), α, β) | ||
return unexpose(CM) | ||
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,7 @@ | ||
function Base.permutedims!( | ||
Edest::Exposed{<:CuArray,<:Base.ReshapedArray}, Esrc::Exposed{<:CuArray}, perm | ||
) | ||
Aperm = permutedims(Esrc, perm) | ||
copyto!(expose(parent(Edest)), expose(Aperm)) | ||
return unexpose(Edest) | ||
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import Base: | ||
adjoint, | ||
permutedims, | ||
permutedims!, | ||
copy, | ||
|
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
Oops, something went wrong.