Skip to content

Commit dd20050

Browse files
dennisYatuninclaude
andcommitted
Restore accidentally-dropped tests from the DataLayouts refactor
- benchmark_stencils.jl: restore the "sphere, VIJFH, Float64" set (main asserted both IJFH-F64 and IJHF-F64; the branch kept only the VIJHF-F64 analogue). - unit_struct.jl: restore the check_basetype testset (was in main's data2d.jl; check_basetype is still a live function in DataLayouts.jl). 17/17 pass. - benchmark_fill.jl (+ cpu/gpu_datalayouts_fill pipeline steps): restore the fill! perf benchmark, mirroring benchmark_copyto.jl's coverage (it was deleted while benchmark_copyto.jl was kept and broadened). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ebf5442 commit dd20050

4 files changed

Lines changed: 105 additions & 1 deletion

File tree

.buildkite/pipeline.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,22 @@ steps:
15781578
- group: "Perf: DataLayouts"
15791579
steps:
15801580

1581+
- label: "Perf: DataLayouts fill!"
1582+
key: "cpu_datalayouts_fill"
1583+
retry: *retry_policy
1584+
command: "julia --color=yes --project=.buildkite test/DataLayouts/benchmark_fill.jl"
1585+
1586+
- label: "Perf: DataLayouts fill"
1587+
key: "gpu_datalayouts_fill"
1588+
retry: *retry_policy
1589+
command:
1590+
- "julia --project=.buildkite -e 'using CUDA; CUDA.versioninfo()'"
1591+
- "julia --color=yes --project=.buildkite test/DataLayouts/benchmark_fill.jl"
1592+
env:
1593+
CLIMACOMMS_DEVICE: "CUDA"
1594+
agents:
1595+
slurm_gpus: 1
1596+
15811597
- label: "Perf: DataLayouts copyto!"
15821598
key: "cpu_datalayouts_copyto"
15831599
retry: *retry_policy

test/DataLayouts/benchmark_fill.jl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Test
2+
using BenchmarkTools
3+
import ClimaComms
4+
import ClimaCore: ClimaCore, DataLayouts
5+
@static pkgversion(ClimaComms) >= v"0.6" && ClimaComms.@import_required_backends
6+
if ClimaComms.device() isa ClimaComms.CUDADevice
7+
import CUDA
8+
device_name = CUDA.name(CUDA.device()) # Move to ClimaComms
9+
else
10+
device_name = "CPU"
11+
end
12+
13+
include(joinpath(pkgdir(ClimaCore), "benchmarks/scripts/benchmark_utils.jl"))
14+
15+
function benchmarkfill!(bm, device, data, val)
16+
caller = string(DataLayouts.layout_constructor(data))
17+
@info "Benchmarking $caller..."
18+
trial = @benchmark ClimaComms.@cuda_sync $device fill!($data, $val)
19+
kernel_time_s = minimum(trial.times) * 1e-9 # to seconds
20+
nreps = length(trial.times)
21+
problem_size = size(data)
22+
n_reads_writes = DataLayouts.ncomponents(data)
23+
push_info(bm; kernel_time_s, nreps, caller, problem_size, n_reads_writes)
24+
end
25+
26+
@testset "fill! with Nf = 1" begin
27+
device = ClimaComms.device()
28+
FT = Float64
29+
A = ClimaComms.array_type(device){FT}
30+
bm = Benchmark(; float_type = FT, device_name)
31+
32+
data = DataLayouts.DataF{FT}(A)
33+
benchmarkfill!(bm, device, data, 3)
34+
@test all(parent(data) .== 3)
35+
36+
(Nv, Nij, Nh) = (63, 4, 30 * 30 * 6)
37+
for Nv in (1, Nv), (Ni, Nj) in ((1, 1), (Nij, 1), (Nij, Nij)), Nh in (1, Nh)
38+
for D in (DataLayouts.VIJFH, DataLayouts.VIJHF)
39+
data = D{FT, Nv, Ni, Nj, Nh == 1 ? 1 : nothing}(A, Nh)
40+
benchmarkfill!(bm, device, data, 3)
41+
@test all(parent(data) .== 3)
42+
end
43+
end
44+
for Nv in (1, Nv), Ni in (1, Nij), Nh in (1, Nh)
45+
data = DataLayouts.VIH1{FT, Nv, Ni, Nh == 1 ? 1 : nothing}(A, Nh)
46+
benchmarkfill!(bm, device, data, 3)
47+
@test all(parent(data) .== 3)
48+
end
49+
for (Ni, Nj) in ((1, 1), (Nij, 1), (Nij, Nij)), Nh in (1, Nh)
50+
data = DataLayouts.IH1JH2{FT, Ni, Nj, Nh == 1 ? 1 : nothing}(A, Nh)
51+
benchmarkfill!(bm, device, data, 3)
52+
@test all(parent(data) .== 3)
53+
end
54+
55+
tabulate_benchmark(bm)
56+
end

test/DataLayouts/unit_struct.jl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Test
2-
using ClimaCore.DataLayouts: get_struct, set_struct!, struct_field_view
2+
using ClimaCore.DataLayouts: get_struct, set_struct!, struct_field_view, check_basetype
33

44
struct Foo{T}
55
x::T
@@ -70,3 +70,29 @@ end
7070
end
7171

7272
# TODO: add set_struct!
73+
74+
@testset "check_basetype" begin
75+
@test_throws Exception check_basetype(Real, Real)
76+
@test_throws Exception check_basetype(Real, Float64)
77+
@test_throws Exception check_basetype(Float64, Real)
78+
79+
@test isnothing(check_basetype(Float64, Float64))
80+
@test isnothing(check_basetype(Float32, Float64))
81+
@test_throws Exception check_basetype(Float64, Float32)
82+
83+
@test isnothing(check_basetype(Tuple{}, Tuple{}))
84+
@test isnothing(check_basetype(Float64, Tuple{}))
85+
@test_throws Exception check_basetype(Tuple{}, Float64)
86+
87+
S = typeof((a = ((1.0, 2.0f0), (3.0, 4.0f0)), b = (5.0, 6.0f0)))
88+
@test isnothing(check_basetype(Float32, S))
89+
@test isnothing(check_basetype(Float64, S))
90+
@test isnothing(check_basetype(Tuple{Float64, Float32}, S))
91+
@test_throws Exception check_basetype(NTuple{4, Float64}, S)
92+
93+
S = typeof(((), (1.0 + 2.0im, NamedTuple()), 3.0 + 4.0im, ()))
94+
@test isnothing(check_basetype(Float32, S))
95+
@test isnothing(check_basetype(Float64, S))
96+
@test isnothing(check_basetype(Complex{Float64}, S))
97+
@test_throws Exception check_basetype(NTuple{5, Float64}, S)
98+
end

test/Operators/finitedifference/benchmark_stencils.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ include("benchmark_stencils_utils.jl")
1515
(;t_min) = benchmark_operators_column(bm; z_elems = 63, helem = 30, Nq = 4)
1616
test_results_column(t_min)
1717

18+
@info "sphere, VIJFH, Float64"
19+
bm = Benchmark(;float_type = Float64, device_name)
20+
# benchmark_operators_sphere(bm; z_elems = 63, helem = 30, Nq = 4, compile = true)
21+
(;t_min) = benchmark_operators_sphere(bm; z_elems = 63, helem = 30, Nq = 4, VIJH = DataLayouts.VIJFH)
22+
test_results_sphere(t_min)
23+
1824
@info "sphere, VIJHF, Float64"
1925
bm = Benchmark(;float_type = Float64, device_name)
2026
(;t_min) = benchmark_operators_sphere(bm; z_elems = 63, helem = 30, Nq = 4, VIJH = DataLayouts.VIJHF)

0 commit comments

Comments
 (0)