Skip to content

Commit

Permalink
Merge pull request #1802 from CliMA/ck/fix_gpu_dispatching
Browse files Browse the repository at this point in the history
Fix broken GPU dispatching
  • Loading branch information
charleskawczynski authored Jun 12, 2024
2 parents fbd017b + be98273 commit d67c873
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 23 deletions.
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

2 comments on commit d67c873

@charleskawczynski
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/108829

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.9 -m "<description of version>" d67c873f907c0d17e68a6e9750d377712709125f
git push origin v0.14.9

Please sign in to comment.