Skip to content

fix: hotfix for breaking changes in GPUArrays #282

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 1 commit into from
Nov 17, 2024
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
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
Expand All @@ -27,6 +28,7 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
ComponentArraysAdaptExt = "Adapt"
ComponentArraysConstructionBaseExt = "ConstructionBase"
ComponentArraysGPUArraysExt = "GPUArrays"
ComponentArraysKernelAbstractionsExt = "KernelAbstractions"
ComponentArraysOptimisersExt = "Optimisers"
ComponentArraysRecursiveArrayToolsExt = "RecursiveArrayTools"
ComponentArraysReverseDiffExt = "ReverseDiff"
Expand All @@ -42,6 +44,7 @@ ConstructionBase = "1"
ForwardDiff = "0.10.36"
Functors = "0.4.12, 0.5"
GPUArrays = "10, 11"
KernelAbstractions = "0.9.29"
LinearAlgebra = "1.10"
Optimisers = "0.3, 0.4"
RecursiveArrayTools = "3.8"
Expand Down
24 changes: 16 additions & 8 deletions ext/ComponentArraysGPUArraysExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ const GPUComponentVector{T,Ax} = ComponentArray{T,1,<:GPUArrays.AbstractGPUVecto
const GPUComponentMatrix{T,Ax} = ComponentArray{T,2,<:GPUArrays.AbstractGPUMatrix,Ax}
const GPUComponentVecorMat{T,Ax} = Union{GPUComponentVector{T,Ax},GPUComponentMatrix{T,Ax}}

GPUArrays.backend(x::ComponentArray) = GPUArrays.backend(getdata(x))
@static if pkgversion(GPUArrays) < v"11"
GPUArrays.backend(x::ComponentArray) = GPUArrays.backend(getdata(x))

function Base.fill!(A::GPUComponentArray{T}, x) where {T}
length(A) == 0 && return A
GPUArrays.gpu_call(A, convert(T, x)) do ctx, a, val
idx = GPUArrays.@linearidx(a)
@inbounds a[idx] = val
return
function Base.fill!(A::GPUComponentArray{T}, x) where {T}
length(A) == 0 && return A
GPUArrays.gpu_call(A, convert(T, x)) do ctx, a, val
idx = GPUArrays.@linearidx(a)
@inbounds a[idx] = val
return
end
return A
end
else
function Base.fill!(A::GPUComponentArray{T}, x) where {T}
length(A) == 0 && return A
ComponentArrays.fill_componentarray_ka!(A, x)
return A
end
A
end

LinearAlgebra.dot(x::GPUComponentArray, y::GPUComponentArray) = dot(getdata(x), getdata(y))
Expand Down
19 changes: 19 additions & 0 deletions ext/ComponentArraysKernelAbstractionsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module ComponentArraysKernelAbstractionsExt

using ComponentArrays: ComponentArrays, ComponentArray
using KernelAbstractions: KernelAbstractions, @kernel, @index

KernelAbstractions.backend(x::ComponentArray) = KernelAbstractions.backend(getdata(x))

@kernel function ca_fill_kernel!(A, @Const(x))
idx = @index(Global, Linear)
@inbounds A[idx] = x
end

function ComponentArrays.fill_componentarray_ka!(A::ComponentArray{T}, x) where {T}
kernel! = ca_fill_kernel!(KernelAbstractions.get_backend(A))
kernel!(A, x; ndrange=length(A))
return A
end

end
1 change: 1 addition & 0 deletions src/componentarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ ComponentArray(x::ComponentArray) = x
ComponentArray{T}(x::ComponentArray) where {T} = T.(x)
(CA::Type{<:ComponentArray{T,N,A,Ax}})(x::ComponentArray) where {T,N,A,Ax} = ComponentArray(T.(getdata(x)), getaxes(x))

function fill_componentarray_ka! end # defined in extensions

## Some aliases
"""
Expand Down
Loading