From 2dae2f134cf5f1af3578e90c90a115477dd9443e Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 21 Apr 2025 04:27:03 -0400 Subject: [PATCH 1/6] Recurse adapt Needs a test case to really know if this is right. Thinking of GPUArrays, you can't have a GPUArray of GPUArrays so it should be an Array of GPUArrays --- src/vector_of_array.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 408d5bf5..eb6e095e 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -143,7 +143,7 @@ end Base.convert(::Type{AbstractArray}, VA::AbstractVectorOfArray) = stack(VA.u) function Adapt.adapt_structure(to, VA::AbstractVectorOfArray) - Adapt.adapt(to, Array(VA)) + Adapt.adapt.(to, VA.u) end function VectorOfArray(vec::AbstractVector{T}, ::NTuple{N}) where {T, N} From b34fd8ff3756a0235e34022c3444036e7b5c369a Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 21 Apr 2025 22:33:36 -0400 Subject: [PATCH 2/6] Update vector_of_array.jl --- src/vector_of_array.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index eb6e095e..3fa52087 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -143,7 +143,11 @@ end Base.convert(::Type{AbstractArray}, VA::AbstractVectorOfArray) = stack(VA.u) function Adapt.adapt_structure(to, VA::AbstractVectorOfArray) - Adapt.adapt.(to, VA.u) + VectorOfArray(Adapt.adapt.(to, VA.u)) +end + +function Adapt.adapt_structure(to, VA::AbstractDiffEqArray) + DiffEqArray(Adapt.adapt.(to, VA.u), Adapt.adapt(to, VA.t)) end function VectorOfArray(vec::AbstractVector{T}, ::NTuple{N}) where {T, N} From e812893306e63e8aa7965f9f01cea1b657efeac1 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 21 Apr 2025 22:37:35 -0400 Subject: [PATCH 3/6] Update gpu.jl --- test/gpu.jl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/gpu.jl b/test/gpu.jl index 2ed5211c..88097a98 100644 --- a/test/gpu.jl +++ b/test/gpu.jl @@ -1,4 +1,15 @@ -using RecursiveArrayTools, CuArrays +using RecursiveArrayTools, Adapt, CuArrays, Test a = ArrayPartition(([1.0f0] |> cu, [2.0f0] |> cu, [3.0f0] |> cu)) b = ArrayPartition(([0.0f0] |> cu, [0.0f0] |> cu, [0.0f0] |> cu)) @. a + b + +a = VectorOfArray([ones(2) for i in 1:3]) +_a = Adapt.adapt(CuArray,a) +@test _a isa VectorOfArray +@test _a.u isa Vector{<:CuArray} + +b = DiffEqArray([ones(2) for i in 1:3],ones(2)) +_b = Adapt.adapt(CuArray,b) +@test _b isa DiffEqArray +@test _b.u isa Vector{<:CuArray} +@test _b.t isa CuArray From 2419648cf928003d682822f2fd265c6baf98f85d Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 21 Apr 2025 23:33:43 -0400 Subject: [PATCH 4/6] Update vectorofarray_gpu.jl --- test/gpu/vectorofarray_gpu.jl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/gpu/vectorofarray_gpu.jl b/test/gpu/vectorofarray_gpu.jl index c97beca2..7422a6c1 100644 --- a/test/gpu/vectorofarray_gpu.jl +++ b/test/gpu/vectorofarray_gpu.jl @@ -1,4 +1,4 @@ -using RecursiveArrayTools, CUDA, Test, Zygote +using RecursiveArrayTools, CUDA, Test, Zygote, Adapt CUDA.allowscalar(false) # Test indexing with colon @@ -37,3 +37,14 @@ va_cu = convert(AbstractArray, va) @test va_cu isa CuArray @test size(va_cu) == size(x) + +a = VectorOfArray([ones(2) for i in 1:3]) +_a = Adapt.adapt(CuArray,a) +@test _a isa VectorOfArray +@test _a.u isa Vector{<:CuArray} + +b = DiffEqArray([ones(2) for i in 1:3],ones(2)) +_b = Adapt.adapt(CuArray,b) +@test _b isa DiffEqArray +@test _b.u isa Vector{<:CuArray} +@test _b.t isa CuArray From 72fbbf499d1a8508b91b9813dbae316ee4db82e5 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 21 Apr 2025 23:34:03 -0400 Subject: [PATCH 5/6] Update arraypartition_gpu.jl --- test/gpu/arraypartition_gpu.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/gpu/arraypartition_gpu.jl b/test/gpu/arraypartition_gpu.jl index 80f9a8d6..08fdb69a 100644 --- a/test/gpu/arraypartition_gpu.jl +++ b/test/gpu/arraypartition_gpu.jl @@ -17,3 +17,7 @@ RecursiveArrayTools.recursivefill!(pA, true) # Test that regular filling is done using GPU kernels and not scalar indexing fill!(pA, false) @test all(pA .== false) + +a = ArrayPartition(([1.0f0] |> cu, [2.0f0] |> cu, [3.0f0] |> cu)) +b = ArrayPartition(([0.0f0] |> cu, [0.0f0] |> cu, [0.0f0] |> cu)) +@. a + b From 63be2a17f8c325cecd801785a34cc860615e1e21 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 21 Apr 2025 23:34:11 -0400 Subject: [PATCH 6/6] Delete test/gpu.jl --- test/gpu.jl | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 test/gpu.jl diff --git a/test/gpu.jl b/test/gpu.jl deleted file mode 100644 index 88097a98..00000000 --- a/test/gpu.jl +++ /dev/null @@ -1,15 +0,0 @@ -using RecursiveArrayTools, Adapt, CuArrays, Test -a = ArrayPartition(([1.0f0] |> cu, [2.0f0] |> cu, [3.0f0] |> cu)) -b = ArrayPartition(([0.0f0] |> cu, [0.0f0] |> cu, [0.0f0] |> cu)) -@. a + b - -a = VectorOfArray([ones(2) for i in 1:3]) -_a = Adapt.adapt(CuArray,a) -@test _a isa VectorOfArray -@test _a.u isa Vector{<:CuArray} - -b = DiffEqArray([ones(2) for i in 1:3],ones(2)) -_b = Adapt.adapt(CuArray,b) -@test _b isa DiffEqArray -@test _b.u isa Vector{<:CuArray} -@test _b.t isa CuArray