Skip to content
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

Fix broken GPU dispatching #1802

Merged
merged 2 commits into from
Jun 12, 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
4 changes: 4 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ steps:
key: unit_data_fill
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/DataLayouts/unit_fill.jl"

- label: "Unit: data_ndims"
key: unit_data_ndims
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/DataLayouts/unit_ndims.jl"

- label: "Unit: data1d"
key: unit_data1d
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/DataLayouts/data1d.jl"
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ ClimaCore.jl Release Notes
main
-------

v0.14.9
-------

- ![][badge-🐛bugfix] GPU dispatching with `copyto!` and `fill!` have been fixed PR [#1802](https://github.com/CliMA/ClimaCore.jl/pull/1802).

v0.14.8
-------

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimaCore"
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
authors = ["CliMA Contributors <[email protected]>"]
version = "0.14.8"
version = "0.14.9"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 1 addition & 1 deletion ext/ClimaCoreCUDAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ClimaCore.RecursiveApply:
⊠, ⊞, ⊟, radd, rmul, rsub, rdiv, rmap, rzero, rmin, rmax

const CuArrayBackedTypes =
Union{CUDA.CuArray, SubArray{<:Any, <:Any, CUDA.CuArray}}
Union{CUDA.CuArray, SubArray{<:Any, <:Any, <:CUDA.CuArray}}

include(joinpath("cuda", "cuda_utils.jl"))
include(joinpath("cuda", "data_layouts.jl"))
Expand Down
3 changes: 3 additions & 0 deletions src/DataLayouts/DataLayouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,9 @@ struct IF{S, Ni, A} <: DataSlab1D{S, Ni}
array::A
end

rebuild(data::IF{S, Nij}, array::A) where {S, Nij, A <: AbstractArray} =
IF{S, Nij, A}(array)

parent_array_type(::Type{IF{S, Ni, A}}) where {S, Ni, A} = A

function IF{S, Ni}(array::AbstractArray{T, 2}) where {S, Ni, T}
Expand Down
83 changes: 63 additions & 20 deletions test/DataLayouts/unit_fill.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ using ClimaCore.DataLayouts
import ClimaComms
ClimaComms.@import_required_backends

function test_fill!(data, vals::Tuple{<:Any, <:Any})
fill!(data, vals)
@test all(parent(data.:1) .== vals[1])
@test all(parent(data.:2) .== vals[2])
end
function test_fill!(data, val::Real)
fill!(data, val)
@test all(parent(data) .== val)
end

@testset "fill! with Nf = 1" begin
device = ClimaComms.device()
device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...))
Expand All @@ -18,17 +28,17 @@ ClimaComms.@import_required_backends
Nh = 5
Nk = 6
#! format: off
data = DataF{S}(device_zeros(FT,Nf)); fill!(data, 3); @test all(parent(data) .== 3)
data = IJFH{S, Nij}(device_zeros(FT,Nij,Nij,Nf,Nh)); fill!(data, 3); @test all(parent(data) .== 3)
data = IFH{S, Nij}(device_zeros(FT,Nij,Nf,Nh)); fill!(data, 3); @test all(parent(data) .== 3)
data = IJF{S, Nij}(device_zeros(FT,Nij,Nij,Nf)); fill!(data, 3); @test all(parent(data) .== 3)
data = IF{S, Nij}(device_zeros(FT,Nij,Nf)); fill!(data, 3); @test all(parent(data) .== 3)
data = VF{S, Nv}(device_zeros(FT,Nv,Nf)); fill!(data, 3); @test all(parent(data) .== 3)
data = VIJFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nij,Nf,Nh)); fill!(data, 3); @test all(parent(data) .== 3)
data = VIFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nf,Nh)); fill!(data, 3); @test all(parent(data) .== 3)
data = DataF{S}(device_zeros(FT,Nf)); test_fill!(data, 3)
data = IJFH{S, Nij}(device_zeros(FT,Nij,Nij,Nf,Nh)); test_fill!(data, 3)
data = IFH{S, Nij}(device_zeros(FT,Nij,Nf,Nh)); test_fill!(data, 3)
data = IJF{S, Nij}(device_zeros(FT,Nij,Nij,Nf)); test_fill!(data, 3)
data = IF{S, Nij}(device_zeros(FT,Nij,Nf)); test_fill!(data, 3)
data = VF{S, Nv}(device_zeros(FT,Nv,Nf)); test_fill!(data, 3)
data = VIJFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nij,Nf,Nh)); test_fill!(data, 3)
data = VIFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nf,Nh)); test_fill!(data, 3)
#! format: on
# data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); fill!(data, (2,3)); @test all(parent(data) .== 3) # TODO: test
# data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); fill!(data, (2,3)); @test all(parent(data) .== 3) # TODO: test
# data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_fill!(data, 3) # TODO: test
# data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_fill!(data, 3) # TODO: test
end

@testset "fill! with Nf > 1" begin
Expand All @@ -42,16 +52,49 @@ end
Nh = 5
Nk = 6
#! format: off
data = DataF{S}(device_zeros(FT,Nf)); fill!(data, (2,3)); @test all(parent(data.:1) .== 2); @test all(parent(data.:2) .== 3)
data = IJFH{S, Nij}(device_zeros(FT,Nij,Nij,Nf,Nh)); fill!(data, (2,3)); @test all(parent(data.:1) .== 2); @test all(parent(data.:2) .== 3)
data = IFH{S, Nij}(device_zeros(FT,Nij,Nf,Nh)); fill!(data, (2,3)); @test all(parent(data.:1) .== 2); @test all(parent(data.:2) .== 3)
data = IJF{S, Nij}(device_zeros(FT,Nij,Nij,Nf)); fill!(data, (2,3)); @test all(parent(data.:1) .== 2); @test all(parent(data.:2) .== 3)
data = IF{S, Nij}(device_zeros(FT,Nij,Nf)); fill!(data, (2,3)); @test all(parent(data.:1) .== 2); @test all(parent(data.:2) .== 3)
data = VF{S, Nv}(device_zeros(FT,Nv,Nf)); fill!(data, (2,3)); @test all(parent(data.:1) .== 2); @test all(parent(data.:2) .== 3)
data = VIJFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nij,Nf,Nh)); fill!(data, (2,3)); @test all(parent(data.:1) .== 2); @test all(parent(data.:2) .== 3)
data = VIFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nf,Nh)); fill!(data, (2,3)); @test all(parent(data.:1) .== 2); @test all(parent(data.:2) .== 3)
data = DataF{S}(device_zeros(FT,Nf)); test_fill!(data, (2,3))
data = IJFH{S, Nij}(device_zeros(FT,Nij,Nij,Nf,Nh)); test_fill!(data, (2,3))
data = IFH{S, Nij}(device_zeros(FT,Nij,Nf,Nh)); test_fill!(data, (2,3))
data = IJF{S, Nij}(device_zeros(FT,Nij,Nij,Nf)); test_fill!(data, (2,3))
data = IF{S, Nij}(device_zeros(FT,Nij,Nf)); test_fill!(data, (2,3))
data = VF{S, Nv}(device_zeros(FT,Nv,Nf)); test_fill!(data, (2,3))
data = VIJFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nij,Nf,Nh)); test_fill!(data, (2,3))
data = VIFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nf,Nh)); test_fill!(data, (2,3))
#! format: on
# TODO: test this
# data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_fill!(data, (2,3)) # TODO: test
# data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_fill!(data, (2,3)) # TODO: test
end

@testset "fill! views with Nf > 1" begin
device = ClimaComms.device()
device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...))
data_view(data) = DataLayouts.rebuild(
data,
SubArray(
parent(data),
ntuple(i -> Base.OneTo(size(parent(data), i)), ndims(data)),
),
)
FT = Float64
S = Tuple{FT, FT}
Nf = 2
Nv = 4
Nij = 3
Nh = 5
Nk = 6
# Rather than using level/slab/column, let's just make views/SubArrays
# directly so that we can easily test all cases:
#! format: off
data = IJFH{S, Nij}(device_zeros(FT,Nij,Nij,Nf,Nh)); test_fill!(data_view(data), (2,3))
data = IFH{S, Nij}(device_zeros(FT,Nij,Nf,Nh)); test_fill!(data_view(data), (2,3))
data = IJF{S, Nij}(device_zeros(FT,Nij,Nij,Nf)); test_fill!(data_view(data), (2,3))
data = IF{S, Nij}(device_zeros(FT,Nij,Nf)); test_fill!(data_view(data), (2,3))
data = VF{S, Nv}(device_zeros(FT,Nv,Nf)); test_fill!(data_view(data), (2,3))
data = VIJFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nij,Nf,Nh)); test_fill!(data_view(data), (2,3))
data = VIFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nf,Nh)); test_fill!(data_view(data), (2,3))
#! format: on
# TODO: test this
# data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); fill!(data, (2,3)); @test all(parent(data) .== (2,3)) # TODO: test
# data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); fill!(data, (2,3)); @test all(parent(data) .== (2,3)) # TODO: test
# data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_fill!(data, (2,3)) # TODO: test
# data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_fill!(data, (2,3)) # TODO: test
end
2 changes: 1 addition & 1 deletion test/DataLayouts/unit_ndims.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#=
julia --project
using Revise; include(joinpath("test", "DataLayouts", "ndims.jl"))
using Revise; include(joinpath("test", "DataLayouts", "unit_ndims.jl"))
=#
using Test
using ClimaCore.DataLayouts
Expand Down
Loading