Skip to content

Make the much lighter ArrayInterfaceGPUArrays #270

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

Merged
merged 2 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ArrayInterface"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "6.0.0"
version = "5.3.0"

[deps]
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"
Expand Down
4 changes: 3 additions & 1 deletion lib/ArrayInterfaceCUDA/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ version = "0.1.1"
[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
ArrayInterfaceGPUArrays = "6ba088a2-8465-4c0a-af30-387133b534db"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"

[compat]
Adapt = "3"
ArrayInterface = "5"
ArrayInterface = "5, 6"
ArrayInterfaceGPUArrays = "0.1"
CUDA = "3.9"
julia = "1.6"

20 changes: 3 additions & 17 deletions lib/ArrayInterfaceCUDA/src/ArrayInterfaceCUDA.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
module ArrayInterfaceCUDA

using Adapt
using ArrayInterface
using ArrayInterface, ArrayInterfaceGPUArrays
using CUDA

ArrayInterface.fast_scalar_indexing(::Type{<:CUDA.CuArray}) = false
@inline ArrayInterface.allowed_getindex(x::CUDA.CuArray, i...) = CUDA.@allowscalar(x[i...])
@inline ArrayInterface.allowed_setindex!(x::CUDA.CuArray, v, i...) = (CUDA.@allowscalar(x[i...] = v))

function Base.setindex(x::CUDA.CuArray, v, i::Int)
_x = copy(x)
ArrayInterface.allowed_setindex!(_x, v, i)
return _x
end

function ArrayInterface.restructure(x::CUDA.CuArray, y)
reshape(Adapt.adapt(ArrayInterface.parameterless_type(x), y), Base.size(x)...)
end

ArrayInterface.device(::Type{<:CUDA.CuArray}) = ArrayInterface.GPU()

function ArrayInterface.lu_instance(A::CuMatrix{T}) where {T}
CUDA.CUSOLVER.CuQR(similar(A, 0, 0), similar(A, 0))
end

ArrayInterface.device(::Type{<:CUDA.CuArray}) = ArrayInterface.GPU()

end # module
21 changes: 21 additions & 0 deletions lib/ArrayInterfaceGPUArrays/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 SciML

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions lib/ArrayInterfaceGPUArrays/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name = "ArrayInterfaceGPUArrays"
uuid = "6ba088a2-8465-4c0a-af30-387133b534db"
authors = ["Zachary P. Christensen <[email protected]>"]
version = "0.1.0"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"

[compat]
Adapt = "3"
ArrayInterfaceCore = "0.1.1"
GPUArrays = "8"
julia = "1.6"

28 changes: 28 additions & 0 deletions lib/ArrayInterfaceGPUArrays/src/ArrayInterfaceGPUArrays.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module ArrayInterfaceGPUArrays

using Adapt
using ArrayInterface
using GPUArrays

ArrayInterface.fast_scalar_indexing(::Type{<:GPUArrays.AbstractGPUArray}) = false
@inline ArrayInterface.allowed_getindex(x::GPUArrays.AbstractGPUArray, i...) = CUDA.@allowscalar(x[i...])
@inline ArrayInterface.allowed_setindex!(x::GPUArrays.AbstractGPUArray, v, i...) = (CUDA.@allowscalar(x[i...] = v))

function Base.setindex(x::GPUArrays.AbstractGPUArray, v, i::Int)
_x = copy(x)
ArrayInterface.allowed_setindex!(_x, v, i)
return _x
end

function ArrayInterface.restructure(x::GPUArrays.AbstractGPUArray, y)
reshape(Adapt.adapt(ArrayInterface.parameterless_type(x), y), Base.size(x)...)
end

function ArrayInterface.lu_instance(A::GPUArrays.AbstractGPUMatrix{T}) where {T}
qr(similar(A, 1, 1))
end

# Doesn't do much, but makes a gigantic change to the dependency chain.
# ArrayInterface.device(::Type{<:GPUArrays.AbstractGPUArray}) = ArrayInterface.GPU()

end
1 change: 1 addition & 0 deletions lib/ArrayInterfaceGPUArrays/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using ArrayInterfaceGPUArrays
2 changes: 1 addition & 1 deletion lib/ArrayInterfaceOffsetArrays/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"

[compat]
ArrayInterface = "5"
ArrayInterface = "5, 6"
OffsetArrays = "1.11"
Static = "0.6"
julia = "1.6"
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end

groups = if GROUP == "All"
["ArrayInterfaceCore", "ArrayInterface", "ArrayInterfaceBandedMatrices", "ArrayInterfaceBlockBandedMatrices",
"ArrayInterfaceCUDA", "ArrayInterfaceOffsetArrays", "ArrayInterfaceStaticArrays"]
"ArrayInterfaceOffsetArrays", "ArrayInterfaceStaticArrays",]
else
[GROUP]
end
Expand Down