From cf7776a83e22a48ea8207f2d5c50d47afe231101 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Wed, 9 Oct 2024 16:23:33 -0400 Subject: [PATCH] Add DataLayouts convenience constructors --- src/DataLayouts/DataLayouts.jl | 133 ++++++++++++++++++++++++- test/DataLayouts/benchmark_copyto.jl | 25 +++-- test/DataLayouts/benchmark_fill.jl | 43 ++++---- test/DataLayouts/cuda.jl | 23 ++--- test/DataLayouts/data0d.jl | 74 +++++++------- test/DataLayouts/data1d.jl | 34 +++---- test/DataLayouts/data1dx.jl | 24 ++--- test/DataLayouts/data2d.jl | 41 ++++---- test/DataLayouts/data2dx.jl | 24 ++--- test/DataLayouts/opt_similar.jl | 25 +++-- test/DataLayouts/opt_universal_size.jl | 25 +++-- test/DataLayouts/unit_copyto.jl | 73 +++++++------- test/DataLayouts/unit_data2array.jl | 23 ++--- test/DataLayouts/unit_fill.jl | 96 +++++++++--------- test/DataLayouts/unit_mapreduce.jl | 75 +++++++------- test/DataLayouts/unit_ndims.jl | 28 +++--- 16 files changed, 427 insertions(+), 339 deletions(-) diff --git a/src/DataLayouts/DataLayouts.jl b/src/DataLayouts/DataLayouts.jl index bc698fe235..50f4297144 100644 --- a/src/DataLayouts/DataLayouts.jl +++ b/src/DataLayouts/DataLayouts.jl @@ -302,12 +302,20 @@ function replace_basetype(data::AbstractData{S}, ::Type{T}) where {S, T} ) end +maybe_populate!(array, ::typeof(similar)) = nothing +maybe_populate!(array, ::typeof(ones)) = fill!(array, 1) +maybe_populate!(array, ::typeof(zeros)) = fill!(array, 0) +function maybe_populate!(array, ::typeof(rand)) + parent(array) .= typeof(array)(rand(eltype(array), size(array))) +end + # ================== # Data3D DataLayout # ================== """ IJKFVH{S, Nij, Nk}(array::AbstractArray{T, 6}) <: Data3D{S, Nij, Nk} + IJKFVH{S}(ArrayType[, ones | zeros | rand]; Nij, Nk, Nv) A 3D DataLayout. TODO: Add more docs """ @@ -327,6 +335,20 @@ function IJKFVH{S, Nij, Nk, Nv}( IJKFVH{S, Nij, Nk, Nv, typeof(array)}(array) end +function IJKFVH{S}( + ::Type{ArrayType}, + fun = similar; + Nv::Integer, + Nij::Integer, + Nk::Integer, + Nh::Integer, +) where {S, ArrayType} + Nf = typesize(eltype(ArrayType), S) + array = similar(ArrayType, Nij, Nij, Nk, Nf, Nv, Nh) + maybe_populate!(array, fun) + IJKFVH{S, Nij, Nk, Nv}(array) +end + @inline universal_size(data::IJKFVH{S, Nij, Nk, Nv}) where {S, Nij, Nk, Nv} = (Nij, Nij, Nk, Nv, get_Nh_dynamic(data)) @@ -337,6 +359,7 @@ end """ IJFH{S, Nij, A} <: Data2D{S, Nij} IJFH{S,Nij}(ArrayType, nelements) + IJFH{S}(ArrayType[, ones | zeros | rand]; Nij, Nh) Backing `DataLayout` for 2D spectral element slabs. @@ -360,6 +383,18 @@ function IJFH{S, Nij}(array::AbstractArray{T, 4}) where {S, Nij, T} IJFH{S, Nij, typeof(array)}(array) end +function IJFH{S}( + ::Type{ArrayType}, + fun = similar; + Nij::Integer, + Nh::Integer, +) where {S, ArrayType} + Nf = typesize(eltype(ArrayType), S) + array = similar(ArrayType, Nij, Nij, Nf, Nh) + maybe_populate!(array, fun) + IJFH{S, Nij}(array) +end + @inline universal_size(data::IJFH{S, Nij}) where {S, Nij} = (Nij, Nij, 1, 1, get_Nh_dynamic(data)) @@ -408,6 +443,7 @@ Base.length(data::Data1D) = get_Nh_dynamic(data) """ IFH{S,Ni,Nh,A} <: Data1D{S, Ni} IFH{S,Ni,Nh}(ArrayType) + IFH{S}(ArrayType[, ones | zeros | rand]; Ni, Nh) Backing `DataLayout` for 1D spectral element slabs. @@ -431,6 +467,18 @@ function IFH{S, Ni}(array::AbstractArray{T, 3}) where {S, Ni, T} IFH{S, Ni, typeof(array)}(array) end +function IFH{S}( + ::Type{ArrayType}, + fun = similar; + Ni::Integer, + Nh::Integer, +) where {S, ArrayType} + Nf = typesize(eltype(ArrayType), S) + array = similar(ArrayType, Ni, Nf, Nh) + maybe_populate!(array, fun) + IFH{S, Ni}(array) +end + function IFH{S, Ni}(::Type{ArrayType}, Nh::Integer) where {S, Ni, ArrayType} T = eltype(ArrayType) IFH{S, Ni}(ArrayType(undef, Ni, typesize(T, S), Nh)) @@ -465,6 +513,7 @@ Base.length(data::Data0D) = 1 """ DataF{S, A} <: Data0D{S} + DataF{S}(ArrayType[, ones | zeros | rand]) Backing `DataLayout` for 0D point data. """ @@ -478,9 +527,11 @@ function DataF{S}(array::AbstractVector{T}) where {S, T} DataF{S, typeof(array)}(array) end -function DataF{S}(::Type{ArrayType}) where {S, ArrayType} - T = eltype(ArrayType) - DataF{S}(ArrayType(undef, typesize(T, S))) +function DataF{S}(::Type{ArrayType}, fun = similar;) where {S, ArrayType} + Nf = typesize(eltype(ArrayType), S) + array = similar(ArrayType, Nf) + maybe_populate!(array, fun) + DataF{S}(array) end function DataF(x::T) where {T} @@ -544,6 +595,7 @@ end """ IJF{S, Nij, A} <: DataSlab2D{S, Nij} + IJF{S}(ArrayType[, ones | zeros | rand]; Nij) Backing `DataLayout` for 2D spectral element slab data. @@ -563,6 +615,17 @@ function IJF{S, Nij}(array::AbstractArray{T, 3}) where {S, Nij, T} IJF{S, Nij, typeof(array)}(array) end +function IJF{S}( + ::Type{ArrayType}, + fun = similar; + Nij::Integer, +) where {S, ArrayType} + Nf = typesize(eltype(ArrayType), S) + array = similar(ArrayType, Nij, Nij, Nf) + maybe_populate!(array, fun) + IJF{S, Nij}(array) +end + function IJF{S, Nij}(::Type{MArray}, ::Type{T}) where {S, Nij, T} Nf = typesize(T, S) array = MArray{Tuple{Nij, Nij, Nf}, T, 3, Nij * Nij * Nf}(undef) @@ -598,6 +661,7 @@ end """ IF{S, Ni, A} <: DataSlab1D{S, Ni} + IF{S}(ArrayType[, ones | zeros | rand]; Ni) Backing `DataLayout` for 1D spectral element slab data. @@ -615,6 +679,18 @@ function IF{S, Ni}(array::AbstractArray{T, 2}) where {S, Ni, T} @assert size(array, 2) == typesize(T, S) IF{S, Ni, typeof(array)}(array) end + +function IF{S}( + ::Type{ArrayType}, + fun = similar; + Ni::Integer, +) where {S, ArrayType} + Nf = typesize(eltype(ArrayType), S) + array = similar(ArrayType, Ni, Nf) + maybe_populate!(array, fun) + IF{S, Ni}(array) +end + function IF{S, Ni}(::Type{MArray}, ::Type{T}) where {S, Ni, T} Nf = typesize(T, S) array = MArray{Tuple{Ni, Nf}, T, 2, Ni * Nf}(undef) @@ -639,6 +715,7 @@ Base.length(data::DataColumn) = get_Nv(data) """ VF{S, A} <: DataColumn{S, Nv} + VF{S}(ArrayType[, ones | zeros | rand]; Nv) Backing `DataLayout` for 1D FV column data. @@ -657,6 +734,17 @@ function VF{S, Nv}(array::AbstractArray{T, 2}) where {S, Nv, T} VF{S, Nv, typeof(array)}(array) end +function VF{S}( + ::Type{ArrayType}, + fun = similar; + Nv::Integer, +) where {S, ArrayType} + Nf = typesize(eltype(ArrayType), S) + array = similar(ArrayType, Nv, Nf) + maybe_populate!(array, fun) + VF{S, Nv}(array) +end + function VF{S, Nv}(array::AbstractVector{T}) where {S, Nv, T} check_basetype(T, S) @assert typesize(T, S) == 1 @@ -697,6 +785,7 @@ end """ VIJFH{S, Nij, A} <: Data2DX{S, Nij} + VIJFH{S}(ArrayType[, ones | zeros | rand]; Nv, Nij, Nh) Backing `DataLayout` for 2D spectral element slab + extruded 1D FV column data. @@ -715,6 +804,19 @@ function VIJFH{S, Nv, Nij}(array::AbstractArray{T, 5}) where {S, Nv, Nij, T} VIJFH{S, Nv, Nij, typeof(array)}(array) end +function VIJFH{S}( + ::Type{ArrayType}, + fun = similar; + Nv::Integer, + Nij::Integer, + Nh::Integer, +) where {S, ArrayType} + Nf = typesize(eltype(ArrayType), S) + array = similar(ArrayType, Nv, Nij, Nij, Nf, Nh) + maybe_populate!(array, fun) + VIJFH{S, Nv, Nij, typeof(array)}(array) +end + nlevels(::VIJFH{S, Nv}) where {S, Nv} = Nv @inline universal_size(data::VIJFH{<:Any, Nv, Nij}) where {Nv, Nij} = @@ -778,6 +880,7 @@ end """ VIFH{S, Nv, Ni, A} <: Data1DX{S, Nv, Ni} + VIFH{S}(ArrayType[, ones | zeros | rand]; Nv, Ni, Nh) Backing `DataLayout` for 1D spectral element slab + extruded 1D FV column data. @@ -796,6 +899,19 @@ function VIFH{S, Nv, Ni}(array::AbstractArray{T, 4}) where {S, Nv, Ni, T} VIFH{S, Nv, Ni, typeof(array)}(array) end +function VIFH{S}( + ::Type{ArrayType}, + fun = similar; + Nv::Integer, + Ni::Integer, + Nh::Integer, +) where {S, ArrayType} + Nf = typesize(eltype(ArrayType), S) + array = similar(ArrayType, Nv, Ni, Nf, Nh) + maybe_populate!(array, fun) + VIFH{S, Nv, Ni, typeof(array)}(array) +end + nlevels(::VIFH{S, Nv}) where {S, Nv} = Nv @inline universal_size(data::VIFH{<:Any, Nv, Ni}) where {Nv, Ni} = @@ -844,6 +960,7 @@ end """ IH1JH2{S, Nij}(data::AbstractMatrix{S}) + IH1JH2{S}(ArrayType[, ones | zeros | rand]; Nij) Stores a 2D field in a matrix using a column-major format. The primary use is for interpolation to a regular grid for ex. plotting / field output. @@ -858,6 +975,16 @@ function IH1JH2{S, Nij}(array::AbstractMatrix{S}) where {S, Nij} IH1JH2{S, Nij, typeof(array)}(array) end +function IH1JH2{S}( + ::Type{ArrayType}, + fun = similar; + Nij::Integer, +) where {S, ArrayType} + array = similar(ArrayType, 2 * Nij, 3 * Nij) + maybe_populate!(array, fun) + IH1JH2{S, Nij}(array) +end + @inline universal_size(data::IH1JH2{S, Nij}) where {S, Nij} = (Nij, Nij, 1, 1, div(array_length(data), Nij * Nij)) diff --git a/test/DataLayouts/benchmark_copyto.jl b/test/DataLayouts/benchmark_copyto.jl index 737d1bf523..f825ac5b39 100644 --- a/test/DataLayouts/benchmark_copyto.jl +++ b/test/DataLayouts/benchmark_copyto.jl @@ -40,38 +40,37 @@ end @testset "copyto! with Nf = 1" begin device = ClimaComms.device() - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) FT = Float64 S = FT - Nf = 1 Nv = 63 - Nij = 4 + Ni = Nij = 4 Nh = 30 * 30 * 6 Nk = 6 bm = Benchmark(; float_type = FT, device_name) - data = DataF{S}(device_zeros(FT, Nf)) + data = DataF{S}(ArrayType{FT}) benchmarkcopyto!(bm, device, data, 3) @test all(parent(data) .== 3) - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}; Nij, Nh) benchmarkcopyto!(bm, device, data, 3) @test all(parent(data) .== 3) - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) + data = IFH{S}(ArrayType{FT}; Nij, Nh) benchmarkcopyto!(bm, device, data, 3) @test all(parent(data) .== 3) # The parent array of IJF and IF datalayouts are MArrays, and can therefore not bm, be passed into CUDA kernels on the RHS. - # data = IJF{S, Nij}(device_zeros(FT,Nij,Nij,Nf)); benchmarkcopyto!(bm, device, data, 3); @test all(parent(data) .== 3) - # data = IF{S, Nij}(device_zeros(FT,Nij,Nf)); benchmarkcopyto!(bm, device, data, 3); @test all(parent(data) .== 3) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + # data = IJF{S}(ArrayType{FT}; Nij); benchmarkcopyto!(bm, device, data, 3); @test all(parent(data) .== 3) + # data = IF{S}(ArrayType{FT}; Nij); benchmarkcopyto!(bm, device, data, 3); @test all(parent(data) .== 3) + data = VF{S}(ArrayType{FT}; Nv) benchmarkcopyto!(bm, device, data, 3) @test all(parent(data) .== 3) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}; Nv, Nij, Nh) benchmarkcopyto!(bm, device, data, 3) @test all(parent(data) .== 3) - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) + data = VIFH{S}(ArrayType{FT}; Nv, Nij, Nh) benchmarkcopyto!(bm, device, data, 3) @test all(parent(data) .== 3) - # data = IJKFVH{S}(device_zeros(FT,Nij,Nij,Nk,Nf,Nh)); benchmarkcopyto!(bm, device, data, 3); @test all(parent(data) .== 3) # TODO: test - # data = IH1JH2{S}(device_zeros(FT,Nij,Nij,Nk,Nf,Nh)); benchmarkcopyto!(bm, device, data, 3); @test all(parent(data) .== 3) # TODO: test + # data = IJKFVH{S}(ArrayType{FT}; Nij,Nk,Nh); benchmarkcopyto!(bm, device, data, 3); @test all(parent(data) .== 3) # TODO: test + # data = IH1JH2{S}(ArrayType{FT}; Nij,Nk,Nh); benchmarkcopyto!(bm, device, data, 3); @test all(parent(data) .== 3) # TODO: test tabulate_benchmark(bm) end diff --git a/test/DataLayouts/benchmark_fill.jl b/test/DataLayouts/benchmark_fill.jl index e067d414c7..0ec876eb93 100644 --- a/test/DataLayouts/benchmark_fill.jl +++ b/test/DataLayouts/benchmark_fill.jl @@ -18,7 +18,7 @@ end include(joinpath(pkgdir(ClimaCore), "benchmarks/scripts/benchmark_utils.jl")) -function benchmarkfill!(bm, device, data, val, name) +function benchmarkfill!(bm, device, data, val) caller = string(nameof(typeof(data))) @info "Benchmarking $caller..." trial = @benchmark ClimaComms.@cuda_sync $device fill!($data, $val) @@ -37,41 +37,40 @@ end @testset "fill! with Nf = 1" begin device = ClimaComms.device() - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) FT = Float64 S = FT - Nf = 1 Nv = 63 - Nij = 4 + Ni = Nij = 4 Nh = 30 * 30 * 6 Nk = 6 bm = Benchmark(; float_type = FT, device_name) - data = DataF{S}(device_zeros(FT, Nf)) - benchmarkfill!(bm, device, data, 3, "DataF") + data = DataF{S}(ArrayType{FT}, zeros) + benchmarkfill!(bm, device, data, 3) @test all(parent(data) .== 3) - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) - benchmarkfill!(bm, device, data, 3, "IJFH") + data = IJFH{S}(ArrayType{FT}, zeros; Nij, Nh) + benchmarkfill!(bm, device, data, 3) @test all(parent(data) .== 3) - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) - benchmarkfill!(bm, device, data, 3, "IFH") + data = IFH{S}(ArrayType{FT}, zeros; Ni, Nh) + benchmarkfill!(bm, device, data, 3) @test all(parent(data) .== 3) - data = IJF{S, Nij}(device_zeros(FT, Nij, Nij, Nf)) - benchmarkfill!(bm, device, data, 3, "IJF") + data = IJF{S}(ArrayType{FT}, zeros; Nij) + benchmarkfill!(bm, device, data, 3) @test all(parent(data) .== 3) - data = IF{S, Nij}(device_zeros(FT, Nij, Nf)) - benchmarkfill!(bm, device, data, 3, "IF") + data = IF{S}(ArrayType{FT}, zeros; Ni) + benchmarkfill!(bm, device, data, 3) @test all(parent(data) .== 3) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) - benchmarkfill!(bm, device, data, 3, "VF") + data = VF{S}(ArrayType{FT}, zeros; Nv) + benchmarkfill!(bm, device, data, 3) @test all(parent(data) .== 3) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) - benchmarkfill!(bm, device, data, 3, "VIJFH") + data = VIJFH{S}(ArrayType{FT}, zeros; Nv, Nij, Nh) + benchmarkfill!(bm, device, data, 3) @test all(parent(data) .== 3) - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) - benchmarkfill!(bm, device, data, 3, "VIFH") + data = VIFH{S}(ArrayType{FT}, zeros; Nv, Ni, Nh) + benchmarkfill!(bm, device, data, 3) @test all(parent(data) .== 3) - # data = IJKFVH{S}(device_zeros(FT,Nij,Nij,Nk,Nf,Nh)); benchmarkfill!(bm, device, data, 3); @test all(parent(data) .== 3) # TODO: test - # data = IH1JH2{S}(device_zeros(FT,Nij,Nij,Nk,Nf,Nh)); benchmarkfill!(bm, device, data, 3); @test all(parent(data) .== 3) # TODO: test + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}, zeros; Nij,Nk,Nv,Nh); benchmarkfill!(bm, device, data, 3); @test all(parent(data) .== 3) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}, zeros; Nij); benchmarkfill!(bm, device, data, 3); @test all(parent(data) .== 3) # TODO: test tabulate_benchmark(bm) end diff --git a/test/DataLayouts/cuda.jl b/test/DataLayouts/cuda.jl index d684b82988..f3c30f7cfe 100644 --- a/test/DataLayouts/cuda.jl +++ b/test/DataLayouts/cuda.jl @@ -32,8 +32,8 @@ end device = ClimaComms.device() ArrayType = ClimaComms.array_type(device) Nh = 10 - src = IJFH{S, 4}(ArrayType(rand(4, 4, 3, Nh))) - dst = IJFH{S, 4}(ArrayType(zeros(4, 4, 3, Nh))) + src = IJFH{S}(ArrayType{Float64}, rand; Nij = 4, Nh) + dst = IJFH{S}(ArrayType{Float64}, zeros; Nij = 4, Nh) test_copy!(dst, src) @@ -46,11 +46,9 @@ end S2 = Float64 Nh = 2 device = ClimaComms.device() - ArrayType = ClimaComms.array_type(device) - data_arr1 = ArrayType(ones(FT, 2, 2, 3, Nh)) - data_arr2 = ArrayType(ones(FT, 2, 2, 1, Nh)) - data1 = IJFH{S1, 2}(data_arr1) - data2 = IJFH{S2, 2}(data_arr2) + ArrayType = ClimaComms.array_type(device){FT} + data1 = IJFH{S1}(ArrayType, ones; Nij = 2, Nh) + data2 = IJFH{S2}(ArrayType, ones; Nij = 2, Nh) f1(a1, a2) = a1.a.re * a2 + a1.b res = f1.(data1, data2) @@ -58,10 +56,8 @@ end @test Array(parent(res)) == FT[2 for i in 1:2, j in 1:2, f in 1:1, h in 1:2] Nv = 33 - data_arr1 = ArrayType(ones(FT, Nv, 4, 4, 3, 2)) - data_arr2 = ArrayType(ones(FT, Nv, 4, 4, 1, 2)) - data1 = VIJFH{S1, Nv, 4}(data_arr1) - data2 = VIJFH{S2, Nv, 4}(data_arr2) + data1 = VIJFH{S1}(ArrayType{FT}, ones; Nv, Nij = 4, Nh = 2) + data2 = VIJFH{S2}(ArrayType{FT}, ones; Nv, Nij = 4, Nh = 2) f2(a1, a2) = a1.a.re * a2 + a1.b res = f2.(data1, data2) @@ -77,14 +73,13 @@ end Nh = 3 device = ClimaComms.device() ArrayType = ClimaComms.array_type(device) - array = similar(ArrayType{FT}, 2, 2, 2, Nh) - data = IJFH{S, 2}(array) + data = IJFH{S}(ArrayType{FT}; Nij = 2, Nh) data .= Complex(1.0, 2.0) @test Array(parent(data)) == FT[f == 1 ? 1 : 2 for i in 1:2, j in 1:2, f in 1:2, h in 1:3] Nv = 33 - data = VIJFH{S, Nv, 4}(ArrayType{FT}(undef, Nv, 4, 4, 2, Nh)) + data = VIJFH{S}(ArrayType{FT}; Nv, Nij = 4, Nh) data .= Complex(1.0, 2.0) @test Array(parent(data)) == FT[ f == 1 ? 1 : 2 for v in 1:Nv, i in 1:4, j in 1:4, f in 1:2, h in 1:3 diff --git a/test/DataLayouts/data0d.jl b/test/DataLayouts/data0d.jl index 6e71ef7331..3b09eee70d 100644 --- a/test/DataLayouts/data0d.jl +++ b/test/DataLayouts/data0d.jl @@ -5,18 +5,21 @@ using Revise; include(joinpath("test", "DataLayouts", "data0d.jl")) using Test using JET +using ClimaComms using ClimaCore.DataLayouts using StaticArrays using ClimaCore.DataLayouts: get_struct, set_struct! TestFloatTypes = (Float32, Float64) +device = ClimaComms.device() +ArrayType = ClimaComms.array_type(device) @testset "DataF" begin for FT in TestFloatTypes S = Tuple{Complex{FT}, FT} - array = rand(FT, 3) - data = DataF{S}(array) + data = DataF{S}(ArrayType{FT}, rand) + array = parent(data) @test getfield(data, :array) == array # test tuple assignment @@ -42,8 +45,7 @@ end @testset "DataF boundscheck" begin S = Tuple{Complex{Float64}, Float64} - array = zeros(Float64, 3) - data = DataF{S}(array) + data = DataF{S}(ArrayType{Float64}, zeros) @test data[][2] == zero(Float64) @test_throws MethodError data[1] end @@ -53,8 +55,7 @@ end SA = (a = 1.0, b = 2.0) SB = (c = 1.0, d = 2.0) - array = zeros(Float64, 2) - data = DataF{typeof(SA)}(array) + data = DataF{typeof(SA)}(ArrayType{Float64}, zeros) ret = begin data[] = SA @@ -66,9 +67,8 @@ end @testset "DataF broadcasting between 0D data objects and scalars" begin for FT in TestFloatTypes - data1 = ones(FT, 2) S = Complex{FT} - data1 = DataF{S}(data1) + data1 = DataF{S}(ArrayType{FT}, ones) res = data1 .+ 1 @test res isa DataF @test parent(res) == FT[2.0, 1.0] @@ -91,12 +91,10 @@ end @testset "DataF broadcasting between 0D data objects" begin for FT in TestFloatTypes - data1 = ones(FT, 2) - data2 = ones(FT, 1) S1 = Complex{FT} S2 = FT - data1 = DataF{S1}(data1) - data2 = DataF{S2}(data2) + data1 = DataF{S1}(ArrayType{FT}, ones) + data2 = DataF{S2}(ArrayType{FT}, ones) res = data1 .+ data2 @test res isa DataF{S1} @test parent(res) == FT[2.0, 1.0] @@ -108,8 +106,8 @@ end FT = Float64 S = Complex{FT} Nv = 3 - data_f = DataF{S}(ones(FT, 2)) - data_vf = VF{S, Nv}(ones(FT, Nv, 2)) + data_f = DataF{S}(ArrayType{FT}, ones) + data_vf = VF{S}(ArrayType{FT}, ones; Nv) data_vf2 = data_f .+ data_vf @test data_vf2 isa VF{S, Nv} @test size(data_vf2) == (1, 1, 1, 3, 1) @@ -118,8 +116,8 @@ end @testset "broadcasting DataF + IF data object => IF" begin FT = Float64 S = Complex{FT} - data_f = DataF{S}(ones(FT, 2)) - data_if = IF{S, 2}(ones(FT, 2, 2)) + data_f = DataF{S}(ArrayType{FT}, ones) + data_if = IF{S}(ArrayType{FT}, ones; Ni = 2) data_if2 = data_f .+ data_if @test data_if2 isa IF{S} @test size(data_if2) == (2, 1, 1, 1, 1) @@ -129,8 +127,8 @@ end FT = Float64 S = Complex{FT} Nh = 3 - data_f = DataF{S}(ones(FT, 2)) - data_ifh = IFH{S, 2}(ones(FT, 2, 2, Nh)) + data_f = DataF{S}(ArrayType{FT}, ones) + data_ifh = IFH{S}(ArrayType{FT}, ones; Ni = 2, Nh) data_ifh2 = data_f .+ data_ifh @test data_ifh2 isa IFH{S} @test size(data_ifh2) == (2, 1, 1, 1, 3) @@ -139,8 +137,8 @@ end @testset "broadcasting DataF + IJF data object => IJF" begin FT = Float64 S = Complex{FT} - data_f = DataF{S}(ones(FT, 2)) - data_ijf = IJF{S, 2}(ones(FT, 2, 2, 2)) + data_f = DataF{S}(ArrayType{FT}, ones) + data_ijf = IJF{S}(ArrayType{FT}, ones; Nij = 2) data_ijf2 = data_f .+ data_ijf @test data_ijf2 isa IJF{S} @test size(data_ijf2) == (2, 2, 1, 1, 1) @@ -150,8 +148,8 @@ end FT = Float64 S = Complex{FT} Nh = 3 - data_f = DataF{S}(ones(FT, 2)) - data_ijfh = IJFH{S, 2}(ones(2, 2, 2, Nh)) + data_f = DataF{S}(ArrayType{FT}, ones) + data_ijfh = IJFH{S}(ArrayType{FT}, ones; Nij = 2, Nh) data_ijfh2 = data_f .+ data_ijfh @test data_ijfh2 isa IJFH{S} @test size(data_ijfh2) == (2, 2, 1, 1, Nh) @@ -161,9 +159,9 @@ end FT = Float64 S = Complex{FT} Nh = 10 - data_f = DataF{S}(ones(FT, 2)) + data_f = DataF{S}(ArrayType{FT}, ones) Nv = 10 - data_vifh = VIFH{S, Nv, 4}(ones(FT, Nv, 4, 2, Nh)) + data_vifh = VIFH{S}(ArrayType{FT}, ones; Nv, Ni = 4, Nh) data_vifh2 = data_f .+ data_vifh @test data_vifh2 isa VIFH{S, Nv} @test size(data_vifh2) == (4, 1, 1, Nv, Nh) @@ -174,8 +172,8 @@ end S = Complex{FT} Nv = 2 Nh = 2 - data_f = DataF{S}(ones(FT, 2)) - data_vijfh = VIJFH{S, Nv, 2}(ones(FT, Nv, 2, 2, 2, Nh)) + data_f = DataF{S}(ArrayType{FT}, ones) + data_vijfh = VIJFH{S}(ArrayType{FT}, ones; Nv, Nij = 2, Nh) data_vijfh2 = data_f .+ data_vijfh @test data_vijfh2 isa VIJFH{S, Nv} @test size(data_vijfh2) == (2, 2, 1, Nv, Nh) @@ -184,8 +182,9 @@ end @testset "column IF => DataF" begin FT = Float64 S = Complex{FT} - array = FT[1 2; 3 4] - data_if = IF{S, 2}(array) + data_if = IF{S}(ArrayType{FT}; Ni = 2) + array = parent(data_if) + array .= FT[1 2; 3 4] if_column = column(data_if, 2) @test if_column isa DataF @test if_column[] == 3.0 + 4.0im @@ -196,9 +195,9 @@ end FT = Float64 S = Complex{FT} Nh = 3 - array = ones(FT, 2, 2, Nh) + data_ifh = IFH{S}(ArrayType{FT}; Ni = 2, Nh) + array = parent(data_ifh) array[1, :, 1] .= FT[3, 4] - data_ifh = IFH{S, 2}(array) ifh_column = column(data_ifh, 1, 1) @test ifh_column isa DataF @test ifh_column[] == 3.0 + 4.0im @@ -209,9 +208,9 @@ end @testset "column IJF => DataF" begin FT = Float64 S = Complex{FT} - array = ones(FT, 2, 2, 2) + data_ijf = IJF{S}(ArrayType{FT}; Nij = 2) + array = parent(data_ijf) array[1, 1, :] .= FT[3, 4] - data_ijf = IJF{S, 2}(array) ijf_column = column(data_ijf, 1, 1) @test ijf_column isa DataF @test ijf_column[] == 3.0 + 4.0im @@ -223,9 +222,9 @@ end FT = Float64 S = Complex{FT} Nh = 3 - array = ones(2, 2, 2, 3) + data_ijfh = IJFH{S}(ArrayType{FT}; Nij = 2, Nh) + array = parent(data_ijfh) array[1, 1, :, 2] .= FT[3, 4] - data_ijfh = IJFH{S, 2}(array) ijfh_column = column(data_ijfh, 1, 1, 2) @test ijfh_column isa DataF @test ijfh_column[] == 3.0 + 4.0im @@ -237,9 +236,10 @@ end @testset "level VF => DataF" begin FT = Float64 S = Complex{FT} - array = FT[1 2; 3 4; 5 6] - Nv = size(array, 1) - data_vf = VF{S, Nv}(array) + Nv = 3 + data_vf = VF{S}(ArrayType{FT}; Nv) + array = parent(data_vf) + array .= FT[1 2; 3 4; 5 6] vf_level = level(data_vf, 2) @test vf_level isa DataF @test vf_level[] == 3.0 + 4.0im diff --git a/test/DataLayouts/data1d.jl b/test/DataLayouts/data1d.jl index b425bb2965..844e5828d9 100644 --- a/test/DataLayouts/data1d.jl +++ b/test/DataLayouts/data1d.jl @@ -5,19 +5,21 @@ using Revise; include(joinpath("test", "DataLayouts", "data1d.jl")) using Test using JET +using ClimaComms using ClimaCore.DataLayouts using StaticArrays using ClimaCore.DataLayouts: get_struct, set_struct!, vindex TestFloatTypes = (Float32, Float64) +device = ClimaComms.device() +ArrayType = ClimaComms.array_type(device) @testset "VF" begin for FT in TestFloatTypes S = Tuple{Complex{FT}, FT} Nv = 4 - array = rand(FT, Nv, 3) - - data = VF{S, Nv}(array) + data = VF{S}(ArrayType{FT}, rand; Nv) + array = parent(data) @test getfield(data.:1, :array) == @view(array[:, 1:2]) # test tuple assignment @@ -35,8 +37,7 @@ TestFloatTypes = (Float32, Float64) end FT = Float64 Nv = 4 - array = rand(FT, Nv, 1) - data = VF{FT, Nv}(array) + data = VF{FT}(ArrayType{FT}, rand; Nv) @test DataLayouts.data2array(data) == reshape(parent(data), DataLayouts.nlevels(data), :) @test DataLayouts.array2data(DataLayouts.data2array(data), data) == data @@ -45,8 +46,7 @@ end @testset "VF boundscheck" begin S = Tuple{Complex{Float64}, Float64} Nv = 4 - array = zeros(Float64, Nv, 3) - data = VF{S, Nv}(array) + data = VF{S}(ArrayType{FT}, rand; Nv) @test data[vindex(1)][2] == zero(Float64) @test_throws BoundsError data[vindex(-1)] @test_throws BoundsError data[vindex(5)] @@ -59,8 +59,7 @@ end SA = (a = 1.0, b = 2.0) SB = (c = 1.0, d = 2.0) - array = zeros(Float64, Nv, 2) - data = VF{typeof(SA), Nv}(array) + data = VF{typeof(SA)}(ArrayType{Float64}, zeros; Nv) ret = begin data[vindex(1)] = SA @@ -73,9 +72,8 @@ end @testset "VF broadcasting between 1D data objects and scalars" begin for FT in TestFloatTypes Nv = 2 - data1 = ones(FT, Nv, 2) S = Complex{FT} - data1 = VF{S, Nv}(data1) + data1 = VF{S}(ArrayType{FT}, ones; Nv) res = data1 .+ 1 @test res isa VF @test parent(res) == FT[2.0 1.0; 2.0 1.0] @@ -89,7 +87,7 @@ end for FT in TestFloatTypes Nv = 3 S = Complex{FT} - data = VF{S, Nv}(Array{FT}, Nv) + data = VF{S}(ArrayType{FT}; Nv) data .= Complex{FT}(1.0, 2.0) @test parent(data) == FT[1.0 2.0; 1.0 2.0; 1.0 2.0] data .= 1 @@ -100,12 +98,10 @@ end @testset "VF broadcasting between 1D data objects" begin for FT in TestFloatTypes Nv = 2 - data1 = ones(FT, Nv, 2) - data2 = ones(FT, Nv, 1) S1 = Complex{FT} S2 = FT - data1 = VF{S1, Nv}(data1) - data2 = VF{S2, Nv}(data2) + data1 = VF{S1}(ArrayType{FT}, ones; Nv) + data2 = VF{S2}(ArrayType{FT}, ones; Nv) res = data1 .+ data2 @test res isa VF{S1} @test parent(res) == FT[2.0 1.0; 2.0 1.0] @@ -119,12 +115,10 @@ end for FT in TestFloatTypes Nv = 2 S1 = NamedTuple{(:a, :b), Tuple{Complex{FT}, FT}} - data1 = ones(FT, Nv, 3) S2 = NamedTuple{(:c,), Tuple{FT}} - data2 = ones(FT, Nv, 1) - dl1 = VF{S1, Nv}(data1) - dl2 = VF{S2, Nv}(data2) + dl1 = VF{S1}(ArrayType{FT}, ones; Nv) + dl2 = VF{S2}(ArrayType{FT}, ones; Nv) f(a1, a2) = a1.a.re * a2.c + a1.b diff --git a/test/DataLayouts/data1dx.jl b/test/DataLayouts/data1dx.jl index 8322ca03aa..d493fbd687 100644 --- a/test/DataLayouts/data1dx.jl +++ b/test/DataLayouts/data1dx.jl @@ -3,9 +3,12 @@ julia --project=test using Revise; include(joinpath("test", "DataLayouts", "data1dx.jl")) =# using Test +using ClimaComms using ClimaCore.DataLayouts import ClimaCore.DataLayouts: VIFH, slab, column, VF, IFH, vindex, slab_index +device = ClimaComms.device() +ArrayType = ClimaComms.array_type(device) @testset "VIFH" begin TestFloatTypes = (Float32, Float64) for FT in TestFloatTypes @@ -16,9 +19,9 @@ import ClimaCore.DataLayouts: VIFH, slab, column, VF, IFH, vindex, slab_index # construct a data object with 10 cells in vertical and # 10 elements in horizontal with 4 nodal points per element in horizontal - array = rand(FT, Nv, Ni, 3, Nh) - data = VIFH{S, Nv, Ni}(array) + data = VIFH{S}(ArrayType{FT}, rand; Nv, Ni, Nh) + array = parent(data) sum(x -> x[2], data) @test getfield(data.:1, :array) == @view(array[:, :, 1:2, :]) @@ -50,8 +53,7 @@ end Nh = 2 # number of elements S = Tuple{Complex{Float64}, Float64} - array = zeros(Float64, Nv, Ni, 3, Nh) - data = VIFH{S, Nv, Ni}(array) + data = VIFH{S}(ArrayType{Float64}, zeros; Nv, Ni, Nh) @test_throws BoundsError slab(data, -1, -1) @test_throws BoundsError slab(data, 1, 3) @@ -76,8 +78,7 @@ end SA = (a = 1.0, b = 2.0) SB = (c = 1.0, d = 2.0) - array = zeros(Float64, Nv, Ni, 2, Nh) - data = VIFH{typeof(SA), Nv, Ni}(array) + data = VIFH{typeof(SA)}(ArrayType{Float64}, zeros; Nv, Ni, Nh) cdata = column(data, 1, 1) cdata[slab_index(1)] = SA @@ -93,9 +94,8 @@ end FT = Float64 Nv = 2 Nh = 2 - data1 = ones(FT, Nv, 2, 2, 2) S = Complex{Float64} - data1 = VIFH{S, Nv, 2}(data1) + data1 = VIFH{S}(ArrayType{FT}, ones; Nv, Ni = 2, Nh = 2) res = data1 .+ 1 @test res isa VIFH{S, Nv} @test parent(res) == @@ -109,8 +109,8 @@ end S = Complex{FT} Nv = 3 Nh = 2 - data_vf = VF{S, Nv}(ones(FT, Nv, 2)) - data_ifh = IFH{FT, 2}(ones(FT, 2, 1, 2)) + data_vf = VF{S}(ArrayType{FT}, ones; Nv) + data_ifh = IFH{FT}(ArrayType{FT}, ones; Ni = 2, Nh = 2) data_vifh = data_vf .+ data_ifh @test data_vifh isa VIFH{S, Nv} @test size(data_vifh) == (2, 1, 1, 3, 2) @@ -125,9 +125,7 @@ end end @testset "fill" begin - - Nh = 3 - data = IFH{Float64, 3}(ones(3, 1, Nh)) + data = IFH{Float64}(ArrayType{Float64}, ones; Ni = 3, Nh = 3) data .= 2.0 @test all(==(2.0), parent(data)) end diff --git a/test/DataLayouts/data2d.jl b/test/DataLayouts/data2d.jl index 8d1fd03894..d88de4b267 100644 --- a/test/DataLayouts/data2d.jl +++ b/test/DataLayouts/data2d.jl @@ -3,10 +3,13 @@ julia --project=test using Revise; include(joinpath("test", "DataLayouts", "data2d.jl")) =# using Test +using ClimaComms using ClimaCore.DataLayouts using StaticArrays using ClimaCore.DataLayouts: check_basetype, get_struct, set_struct!, slab_index +device = ClimaComms.device() +ArrayType = ClimaComms.array_type(device) @testset "check_basetype" begin @test_throws Exception check_basetype(Real, Float64) @test_throws Exception check_basetype(Float64, Real) @@ -44,9 +47,10 @@ end @testset "IJFH" begin Nij = 2 # number of nodal points Nh = 2 # number of elements - S = Tuple{Complex{Float64}, Float64} - array = rand(Nij, Nij, 3, Nh) - data = IJFH{S, 2}(array) + FT = Float64 + S = Tuple{Complex{FT}, FT} + data = IJFH{S}(ArrayType{FT}, rand; Nij, Nh) + array = parent(data) @test getfield(data.:1, :array) == @view(array[:, :, 1:2, :]) data_slab = slab(data, 1) @test data_slab[slab_index(2, 1)] == @@ -70,8 +74,7 @@ end Nij = 1 # number of nodal points Nh = 2 # number of elements S = Tuple{Complex{Float64}, Float64} - array = zeros(Float64, Nij, Nij, 3, Nh) - data = IJFH{S, Nij}(array) + data = IJFH{S}(ArrayType{Float64}, zeros; Nij, Nh) @test_throws BoundsError slab(data, -1) @test_throws BoundsError slab(data, 3) @@ -94,8 +97,7 @@ end SA = (a = 1.0, b = 2.0) SB = (c = 1.0, d = 2.0) - array = zeros(Float64, Nij, Nij, 2, Nh) - data = IJFH{typeof(SA), Nij}(array) + data = IJFH{typeof(SA)}(ArrayType{Float64}, zeros; Nij, Nh) data_slab = slab(data, 1) ret = begin data_slab[slab_index(1, 1)] = SA @@ -110,11 +112,8 @@ end Nh = 2 # number of elements S1 = Float64 S2 = Float32 - array1 = ones(S1, Nij, Nij, 1, Nh) - data1 = IJFH{S1, Nij}(array1) - - array2 = ones(S2, Nij, Nij, 1, Nh) - data2 = IJFH{S2, Nij}(array2) + data1 = IJFH{S1}(ArrayType{S1}, ones; Nij, Nh) + data2 = IJFH{S2}(ArrayType{S2}, ones; Nij, Nh) for h in 1:Nh slab1 = slab(data1, h) @@ -129,9 +128,8 @@ end @testset "broadcasting between data object + scalars" begin FT = Float64 Nh = 2 - data1 = ones(FT, 2, 2, 2, Nh) S = Complex{Float64} - data1 = IJFH{S, 2}(data1) + data1 = IJFH{S}(ArrayType{FT}, ones; Nij = 2, Nh) res = data1 .+ 1 @test res isa IJFH{S} @test parent(res) == @@ -145,8 +143,7 @@ end FT = Float64 S = Complex{FT} Nh = 3 - array = similar(Array{FT}, 2, 2, 2, Nh) - data = IJFH{S, 2}(array) + data = IJFH{S}(ArrayType{FT}; Nij = 2, Nh) data .= Complex(1.0, 2.0) @test parent(data) == FT[f == 1 ? 1 : 2 for i in 1:2, j in 1:2, f in 1:2, h in 1:3] @@ -160,12 +157,10 @@ end @testset "broadcasting between data objects" begin FT = Float64 Nh = 2 - data1 = ones(FT, 2, 2, 2, Nh) - data2 = ones(FT, 2, 2, 1, Nh) S1 = Complex{Float64} S2 = Float64 - data1 = IJFH{S1, 2}(data1) - data2 = IJFH{S2, 2}(data2) + data1 = IJFH{S1}(ArrayType{FT}, ones; Nij = 2, Nh) + data2 = IJFH{S2}(ArrayType{FT}, ones; Nij = 2, Nh) res = data1 .+ data2 @test res isa IJFH{S1} @test parent(res) == @@ -179,11 +174,9 @@ end FT = Float64 S1 = NamedTuple{(:a, :b), Tuple{Complex{Float64}, Float64}} Nh = 2 - data1 = ones(FT, 2, 2, 3, Nh) S2 = Float64 - data2 = ones(FT, 2, 2, 1, Nh) - data1 = IJFH{S1, 2}(data1) - data2 = IJFH{S2, 2}(data2) + data1 = IJFH{S1}(ArrayType{FT}, ones; Nij = 2, Nh) + data2 = IJFH{S2}(ArrayType{FT}, ones; Nij = 2, Nh) f(a1, a2) = a1.a.re * a2 + a1.b res = f.(data1, data2) diff --git a/test/DataLayouts/data2dx.jl b/test/DataLayouts/data2dx.jl index 62b45ff53a..1b2621b4dd 100644 --- a/test/DataLayouts/data2dx.jl +++ b/test/DataLayouts/data2dx.jl @@ -3,9 +3,12 @@ julia --project=test using Revise; include(joinpath("test", "DataLayouts", "data2dx.jl")) =# using Test +using ClimaComms using ClimaCore.DataLayouts import ClimaCore.DataLayouts: VF, IJFH, VIJFH, slab, column, slab_index, vindex +device = ClimaComms.device() +ArrayType = ClimaComms.array_type(device) @testset "VIJFH" begin Nv = 10 # number of vertical levels Nij = 4 # Nij × Nij nodal points per element @@ -17,9 +20,8 @@ import ClimaCore.DataLayouts: VF, IJFH, VIJFH, slab, column, slab_index, vindex # construct a data object with 10 cells in vertical and # 10 elements in horizontal with 4 × 4 nodal points per element in horizontal - array = rand(FT, Nv, Nij, Nij, 3, Nh) - - data = VIJFH{S, Nv, Nij}(array) + data = VIJFH{S}(ArrayType{FT}, rand; Nv, Nij, Nh) + array = parent(data) @test getfield(data.:1, :array) == @view(array[:, :, :, 1:2, :]) @test getfield(data.:2, :array) == @view(array[:, :, :, 3:3, :]) @@ -51,8 +53,7 @@ end Nh = 2 # number of elements S = Tuple{Complex{Float64}, Float64} - array = zeros(Float64, Nv, Nij, Nij, 3, Nh) - data = VIJFH{S, Nv, Nij}(array) + data = VIJFH{S}(ArrayType{Float64}, zeros; Nv, Nij, Nh) @test_throws BoundsError slab(data, -1, 1) @test_throws BoundsError slab(data, 1, -1) @@ -76,8 +77,7 @@ end SA = (a = 1.0, b = 2.0) SB = (c = 1.0, d = 2.0) - array = zeros(Float64, Nv, Nij, Nij, 2, Nh) - data = VIJFH{typeof(SA), Nv, Nij}(array) + data = VIJFH{typeof(SA)}(ArrayType{Float64}, zeros; Nv, Nij, Nh) cdata = column(data, 1, 2, 1) cdata[vindex(1)] = SA @@ -91,11 +91,11 @@ end @testset "broadcasting between VIJFH data object + scalars" begin FT = Float64 - array = ones(FT, 2, 2, 2, 2, 2) + S = Complex{Float64} + data1 = VIJFH{S}(ArrayType{FT}, ones; Nv = 2, Nij = 2, Nh = 2) + array = parent(data1) Nv = size(array, 1) Nh = size(array, 5) - S = Complex{Float64} - data1 = VIJFH{S, Nv, 2}(array) res = data1 .+ 1 @test res isa VIJFH{S, Nv} @test parent(res) == FT[ @@ -111,8 +111,8 @@ end S = Complex{FT} Nv = 3 Nh = 2 - data_vf = VF{S, Nv}(ones(FT, Nv, 2)) - data_ijfh = IJFH{FT, 2}(ones(FT, 2, 2, 1, Nh)) + data_vf = VF{S}(ArrayType{FT}, ones; Nv) + data_ijfh = IJFH{FT}(ArrayType{FT}, ones; Nij = 2, Nh) data_vijfh = data_vf .+ data_ijfh @test data_vijfh isa VIJFH{S, Nv} @test size(data_vijfh) == (2, 2, 1, 3, 2) diff --git a/test/DataLayouts/opt_similar.jl b/test/DataLayouts/opt_similar.jl index a14cffb084..2ff0b053a3 100644 --- a/test/DataLayouts/opt_similar.jl +++ b/test/DataLayouts/opt_similar.jl @@ -28,30 +28,29 @@ end @testset "similar" begin device = ClimaComms.device() - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) FT = Float64 S = FT - Nf = 1 Nv = 4 - Nij = 3 + Ni = Nij = 3 Nh = 5 Nk = 6 - data = DataF{S}(device_zeros(FT, Nf)) + data = DataF{S}(ArrayType{FT}, zeros) test_similar!(data) - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}, zeros; Nij, Nh) test_similar!(data) - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) + data = IFH{S}(ArrayType{FT}, zeros; Ni, Nh) test_similar!(data) - data = IJF{S, Nij}(device_zeros(FT, Nij, Nij, Nf)) + data = IJF{S}(ArrayType{FT}, zeros; Nij) test_similar!(data) - data = IF{S, Nij}(device_zeros(FT, Nij, Nf)) + data = IF{S}(ArrayType{FT}, zeros; Ni) test_similar!(data) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + data = VF{S}(ArrayType{FT}, zeros; Nv) test_similar!(data) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}, zeros; Nv, Nij, Nh) test_similar!(data) - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) + data = VIFH{S}(ArrayType{FT}, zeros; Nv, Ni, Nh) test_similar!(data) - # data = DataLayouts.IJKFVH{S, Nij, Nk, Nv}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_similar!(data) # TODO: test - # data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_similar!(data) # TODO: test + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}, zeros; Nij,Nk,Nv,Nh); test_similar!(data) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}, zeros; Nij); test_similar!(data) # TODO: test end diff --git a/test/DataLayouts/opt_universal_size.jl b/test/DataLayouts/opt_universal_size.jl index ef53322c9b..27a5e69b0b 100644 --- a/test/DataLayouts/opt_universal_size.jl +++ b/test/DataLayouts/opt_universal_size.jl @@ -50,30 +50,29 @@ end @testset "UniversalSize" begin device = ClimaComms.device() - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) FT = Float64 S = FT - Nf = 1 Nv = 4 - Nij = 3 + Ni = Nij = 3 Nh = 5 Nk = 6 - data = DataF{S}(device_zeros(FT, Nf)) + data = DataF{S}(ArrayType{FT}, zeros) test_universal_size(data) - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}, zeros; Nij, Nh) test_universal_size(data) - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) + data = IFH{S}(ArrayType{FT}, zeros; Ni, Nh) test_universal_size(data) - data = IJF{S, Nij}(device_zeros(FT, Nij, Nij, Nf)) + data = IJF{S}(ArrayType{FT}, zeros; Nij) test_universal_size(data) - data = IF{S, Nij}(device_zeros(FT, Nij, Nf)) + data = IF{S}(ArrayType{FT}, zeros; Ni) test_universal_size(data) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + data = VF{S}(ArrayType{FT}, zeros; Nv) test_universal_size(data) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}, zeros; Nv, Nij, Nh) test_universal_size(data) - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) + data = VIFH{S}(ArrayType{FT}, zeros; Nv, Ni, Nh) test_universal_size(data) - # data = DataLayouts.IJKFVH{S, Nij, Nk, Nv}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_universal_size(data) # TODO: test - # data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_universal_size(data) # TODO: test + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}, zeros; Nij,Nk,Nv,Nh); test_universal_size(data) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}, zeros; Nij); test_universal_size(data) # TODO: test end diff --git a/test/DataLayouts/unit_copyto.jl b/test/DataLayouts/unit_copyto.jl index 1dfe3ecee9..6bf260bb08 100644 --- a/test/DataLayouts/unit_copyto.jl +++ b/test/DataLayouts/unit_copyto.jl @@ -43,68 +43,66 @@ end @testset "copyto! with Nf = 1" begin device = ClimaComms.device() - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) FT = Float64 S = FT - Nf = 1 Nv = 4 - Nij = 3 + Ni = Nij = 3 Nh = 5 Nk = 6 - data = DataF{S}(device_zeros(FT, Nf)) + data = DataF{S}(ArrayType{FT}, zeros) test_copyto_float!(data) - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}, zeros; Nij, Nh) test_copyto_float!(data) - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) + data = IFH{S}(ArrayType{FT}, zeros; Ni, Nh) test_copyto_float!(data) - data = IJF{S, Nij}(device_zeros(FT, Nij, Nij, Nf)) + data = IJF{S}(ArrayType{FT}, zeros; Nij) test_copyto_float!(data) - data = IF{S, Nij}(device_zeros(FT, Nij, Nf)) + data = IF{S}(ArrayType{FT}, zeros; Ni) test_copyto_float!(data) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + data = VF{S}(ArrayType{FT}, zeros; Nv) test_copyto_float!(data) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}, zeros; Nv, Nij, Nh) test_copyto_float!(data) - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) + data = VIFH{S}(ArrayType{FT}, zeros; Nv, Ni, Nh) test_copyto_float!(data) - # data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_copyto_float!(data) # TODO: test - # data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_copyto_float!(data) # TODO: test + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}, zeros; Nij,Nk,Nv,Nh); test_copyto_float!(data) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}, zeros; Nij); test_copyto_float!(data) # TODO: test end @testset "copyto! with Nf > 1" begin device = ClimaComms.device() - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) FT = Float64 S = Tuple{FT, FT} - Nf = 2 Nv = 4 - Nij = 3 + Ni = Nij = 3 Nh = 5 Nk = 6 - data = DataF{S}(device_zeros(FT, Nf)) + data = DataF{S}(ArrayType{FT}, zeros) test_copyto!(data) - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}, zeros; Nij, Nh) test_copyto!(data) - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) + data = IFH{S}(ArrayType{FT}, zeros; Ni, Nh) test_copyto!(data) - data = IJF{S, Nij}(device_zeros(FT, Nij, Nij, Nf)) + data = IJF{S}(ArrayType{FT}, zeros; Nij) test_copyto!(data) - data = IF{S, Nij}(device_zeros(FT, Nij, Nf)) + data = IF{S}(ArrayType{FT}, zeros; Ni) test_copyto!(data) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + data = VF{S}(ArrayType{FT}, zeros; Nv) test_copyto!(data) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}, zeros; Nv, Nij, Nh) test_copyto!(data) - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) + data = VIFH{S}(ArrayType{FT}, zeros; Nv, Ni, Nh) test_copyto!(data) # TODO: test this - # data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_copyto!(data) # TODO: test - # data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_copyto!(data) # TODO: test + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}, zeros; Nij,Nk,Nv,Nh); test_copyto!(data) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}, zeros; Nij); test_copyto!(data) # TODO: test end @testset "copyto! views with Nf > 1" begin device = ClimaComms.device() - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) data_view(data) = DataLayouts.rebuild( data, SubArray( @@ -117,28 +115,27 @@ end ) FT = Float64 S = Tuple{FT, FT} - Nf = 2 Nv = 4 - Nij = 3 + Ni = 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: - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}, zeros; Nij, Nh) test_copyto!(data_view(data)) - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) + data = IFH{S}(ArrayType{FT}, zeros; Ni, Nh) test_copyto!(data_view(data)) - data = IJF{S, Nij}(device_zeros(FT, Nij, Nij, Nf)) + data = IJF{S}(ArrayType{FT}, zeros; Nij) test_copyto!(data_view(data)) - data = IF{S, Nij}(device_zeros(FT, Nij, Nf)) + data = IF{S}(ArrayType{FT}, zeros; Ni) test_copyto!(data_view(data)) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + data = VF{S}(ArrayType{FT}, zeros; Nv) test_copyto!(data_view(data)) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}, zeros; Nv, Nij, Nh) test_copyto!(data_view(data)) - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) + data = VIFH{S}(ArrayType{FT}, zeros; Nv, Ni, Nh) test_copyto!(data_view(data)) # TODO: test this - # data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_copyto!(data) # TODO: test - # data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_copyto!(data) # TODO: test + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}, zeros; Nij,Nk,Nv,Nh); test_copyto!(data) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}, zeros; Nij); test_copyto!(data) # TODO: test end diff --git a/test/DataLayouts/unit_data2array.jl b/test/DataLayouts/unit_data2array.jl index b404f10c05..8ce5084064 100644 --- a/test/DataLayouts/unit_data2array.jl +++ b/test/DataLayouts/unit_data2array.jl @@ -4,6 +4,7 @@ using Revise; include(joinpath("test", "DataLayouts", "unit_data2array.jl")) =# using Test using ClimaCore.DataLayouts +using ClimaComms function is_data2array2data_identity(data) all( @@ -15,36 +16,32 @@ end @testset "data2array & array2data" begin FT = Float64 Nv = 10 # number of vertical levels - Nij = 4 # number of nodal points + Ni = Nij = 4 # number of nodal points Nh = 10 # number of elements + device = ClimaComms.device() + ArrayType = ClimaComms.array_type(device) - array = rand(FT, 2, 1) - data = IF{FT, 2}(array) + data = IF{FT}(ArrayType{FT}, rand; Ni) @test DataLayouts.data2array(data) == reshape(parent(data), :) @test is_data2array2data_identity(data) - array = rand(FT, 2, 1, Nh) - data = IFH{FT, 2}(array) + data = IFH{FT}(ArrayType{FT}, rand; Ni, Nh) @test DataLayouts.data2array(data) == reshape(parent(data), :) @test is_data2array2data_identity(data) - array = rand(FT, 2, 2, 1) - data = IJF{FT, 2}(array) + data = IJF{FT}(ArrayType{FT}, rand; Nij) @test DataLayouts.data2array(data) == reshape(parent(data), :) @test is_data2array2data_identity(data) - array = rand(FT, Nij, Nij, 1, Nh) - data = IJFH{FT, Nij}(array) + data = IJFH{FT}(ArrayType{FT}, rand; Nij, Nh) @test DataLayouts.data2array(data) == reshape(parent(data), :) @test is_data2array2data_identity(data) - array = rand(FT, Nv, Nij, 1, Nh) - data = VIFH{FT, Nv, Nij}(array) + data = VIFH{FT}(ArrayType{FT}, rand; Nv, Ni, Nh) @test DataLayouts.data2array(data) == reshape(parent(data), Nv, :) @test is_data2array2data_identity(data) - array = rand(FT, Nv, Nij, Nij, 1, Nh) - data = VIJFH{FT, Nv, Nij}(array) + data = VIJFH{FT}(ArrayType{FT}, rand; Nv, Nij, Nh) @test DataLayouts.data2array(data) == reshape(parent(data), Nv, :) @test is_data2array2data_identity(data) end diff --git a/test/DataLayouts/unit_fill.jl b/test/DataLayouts/unit_fill.jl index 4c00d342a2..eb45880aa3 100644 --- a/test/DataLayouts/unit_fill.jl +++ b/test/DataLayouts/unit_fill.jl @@ -19,72 +19,70 @@ end @testset "fill! with Nf = 1" begin device = ClimaComms.device() - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) FT = Float64 S = FT - Nf = 1 Nv = 4 - Nij = 3 + Ni = Nij = 3 Nh = 5 Nk = 6 - data = DataF{S}(device_zeros(FT, Nf)) + data = DataF{S}(ArrayType{FT}, zeros) test_fill!(data, 3) - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}, zeros; Nij, Nh) test_fill!(data, 3) - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) + data = IFH{S}(ArrayType{FT}, zeros; Ni, Nh) test_fill!(data, 3) - data = IJF{S, Nij}(device_zeros(FT, Nij, Nij, Nf)) + data = IJF{S}(ArrayType{FT}, zeros; Nij) test_fill!(data, 3) - data = IF{S, Nij}(device_zeros(FT, Nij, Nf)) + data = IF{S}(ArrayType{FT}, zeros; Ni) test_fill!(data, 3) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + data = VF{S}(ArrayType{FT}, zeros; Nv) test_fill!(data, 3) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}, zeros; Nv, Nij, Nh) test_fill!(data, 3) - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) + data = VIFH{S}(ArrayType{FT}, zeros; Nv, Ni, Nh) test_fill!(data, 3) - # 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 + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}, zeros; Nij,Nk,Nv,Nh); test_fill!(data, 3) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}, zeros; Nij); test_fill!(data, 3) # TODO: test end @testset "fill! with Nf > 1" begin device = ClimaComms.device() - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) FT = Float64 S = Tuple{FT, FT} - Nf = 2 Nv = 4 - Nij = 3 + Ni = Nij = 3 Nh = 5 Nk = 6 - data = DataF{S}(device_zeros(FT, Nf)) + data = DataF{S}(ArrayType{FT}, zeros) test_fill!(data, (2, 3)) - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}, zeros; Nij, Nh) test_fill!(data, (2, 3)) - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) + data = IFH{S}(ArrayType{FT}, zeros; Ni, Nh) test_fill!(data, (2, 3)) - data = IJF{S, Nij}(device_zeros(FT, Nij, Nij, Nf)) + data = IJF{S}(ArrayType{FT}, zeros; Nij) test_fill!(data, (2, 3)) - data = IF{S, Nij}(device_zeros(FT, Nij, Nf)) + data = IF{S}(ArrayType{FT}, zeros; Ni) test_fill!(data, (2, 3)) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + data = VF{S}(ArrayType{FT}, zeros; Nv) test_fill!(data, (2, 3)) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}, zeros; Nv, Nij, Nh) test_fill!(data, (2, 3)) - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) + data = VIFH{S}(ArrayType{FT}, zeros; Nv, Ni, Nh) test_fill!(data, (2, 3)) # 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 + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}, zeros; Nij,Nk,Nv,Nh); test_fill!(data, (2,3)) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}, zeros; 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...)) + ArrayType = ClimaComms.array_type(device) data_view(data) = DataLayouts.rebuild( data, SubArray( @@ -97,37 +95,36 @@ end ) FT = Float64 S = Tuple{FT, FT} - Nf = 2 Nv = 4 - Nij = 3 + Ni = 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: - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}, zeros; Nij, Nh) test_fill!(data_view(data), (2, 3)) - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) + data = IFH{S}(ArrayType{FT}, zeros; Ni, Nh) test_fill!(data_view(data), (2, 3)) - data = IJF{S, Nij}(device_zeros(FT, Nij, Nij, Nf)) + data = IJF{S}(ArrayType{FT}, zeros; Nij) test_fill!(data_view(data), (2, 3)) - data = IF{S, Nij}(device_zeros(FT, Nij, Nf)) + data = IF{S}(ArrayType{FT}, zeros; Ni) test_fill!(data_view(data), (2, 3)) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + data = VF{S}(ArrayType{FT}, zeros; Nv) test_fill!(data_view(data), (2, 3)) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}, zeros; Nv, Nij, Nh) test_fill!(data_view(data), (2, 3)) - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) + data = VIFH{S}(ArrayType{FT}, zeros; Nv, Ni, Nh) test_fill!(data_view(data), (2, 3)) # 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 + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}, zeros; Nij,Nk,Nv,Nh); test_fill!(data, (2,3)) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}, zeros; Nij); test_fill!(data, (2,3)) # TODO: test end @testset "Reshaped Arrays" begin device = ClimaComms.device() - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) function reshaped_array(data2) # `reshape` does not always return a `ReshapedArray`, which # we need to specialize on to correctly dispatch when its @@ -160,26 +157,25 @@ end end FT = Float64 S = Tuple{FT, FT} # need at least 2 components to make a SubArray - Nf = 2 Nv = 4 - Nij = 3 + Ni = Nij = 3 Nh = 5 Nk = 6 # directly so that we can easily test all cases: - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}, zeros; Nij, Nh) test_fill!(reshaped_array(data), 2) - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) + data = IFH{S}(ArrayType{FT}, zeros; Ni, Nh) test_fill!(reshaped_array(data), 2) - # data = IJF{S, Nij}(device_zeros(FT,Nij,Nij,Nf)); test_fill!(reshaped_array(data), 2) - # data = IF{S, Nij}(device_zeros(FT,Nij,Nf)); test_fill!(reshaped_array(data), 2) - # data = VF{S, Nv}(device_zeros(FT,Nv,Nf)); test_fill!(reshaped_array(data), 2) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + # data = IJF{S}(ArrayType{FT}; Nij); test_fill!(reshaped_array(data), 2) + # data = IF{S}(ArrayType{FT}; Ni); test_fill!(reshaped_array(data), 2) + # data = VF{S}(ArrayType{FT}; Nv); test_fill!(reshaped_array(data), 2) + data = VIJFH{S}(ArrayType{FT}, zeros; Nv, Nij, Nh) test_fill!(reshaped_array(data), 2) - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) + data = VIFH{S}(ArrayType{FT}, zeros; Nv, Ni, Nh) test_fill!(reshaped_array(data), 2) # TODO: test this - # data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_fill!(reshaped_array(data), 2) # TODO: test - # data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_fill!(reshaped_array(data), 2) # TODO: test + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}, zeros; Nij,Nk,Nv,Nh); test_fill!(reshaped_array(data), 2) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}, zeros; Nij); test_fill!(reshaped_array(data), 2) # TODO: test end diff --git a/test/DataLayouts/unit_mapreduce.jl b/test/DataLayouts/unit_mapreduce.jl index 9ebe0c7fdd..0941e83700 100644 --- a/test/DataLayouts/unit_mapreduce.jl +++ b/test/DataLayouts/unit_mapreduce.jl @@ -66,58 +66,56 @@ function test_mapreduce_2!(context, data) end @testset "mapreduce with Nf = 1" begin - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) FT = Float64 S = FT - Nf = 1 Nv = 4 - Nij = 3 + Ni = Nij = 3 Nh = 5 Nk = 6 - data = DataF{S}(device_zeros(FT, Nf)) + data = DataF{S}(ArrayType{FT}) test_mapreduce_1!(context, data) - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}; Nij, Nh) test_mapreduce_1!(context, data) - # data = IFH{S, Nij}(device_zeros(FT,Nij,Nf,Nh)); test_mapreduce_1!(context, data) - # data = IJF{S, Nij}(device_zeros(FT,Nij,Nij,Nf)); test_mapreduce_1!(context, data) - # data = IF{S, Nij}(device_zeros(FT,Nij,Nf)); test_mapreduce_1!(context, data) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + # data = IFH{S}(ArrayType{FT}; Ni,Nh); test_mapreduce_1!(context, data) + # data = IJF{S}(ArrayType{FT}; Nij); test_mapreduce_1!(context, data) + # data = IF{S}(ArrayType{FT}; Ni); test_mapreduce_1!(context, data) + data = VF{S}(ArrayType{FT}; Nv) test_mapreduce_1!(context, data) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}; Nv, Nij, Nh) test_mapreduce_1!(context, data) - # data = VIFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nf,Nh)); test_mapreduce_1!(context, data) - # data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_mapreduce_1!(context, data) # TODO: test - # data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_mapreduce_1!(context, data) # TODO: test + # data = VIFH{S}(ArrayType{FT}; Nv,Nij,Nh); test_mapreduce_1!(context, data) + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}; Nij,Nk,Nv,Nh); test_mapreduce_1!(context, data) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}; Nij); test_mapreduce_1!(context, data) # TODO: test end @testset "mapreduce with Nf > 1" begin - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) FT = Float64 S = Tuple{FT, FT} - Nf = 2 Nv = 4 - Nij = 3 + Ni = Nij = 3 Nh = 5 Nk = 6 - data = DataF{S}(device_zeros(FT, Nf)) + data = DataF{S}(ArrayType{FT}) test_mapreduce_2!(context, data) - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}; Nij, Nh) test_mapreduce_2!(context, data) - # data = IFH{S, Nij}(device_zeros(FT,Nij,Nf,Nh)); test_mapreduce_2!(context, data) - # data = IJF{S, Nij}(device_zeros(FT,Nij,Nij,Nf)); test_mapreduce_2!(context, data) - # data = IF{S, Nij}(device_zeros(FT,Nij,Nf)); test_mapreduce_2!(context, data) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + # data = IFH{S}(ArrayType{FT}; Ni,Nh); test_mapreduce_2!(context, data) + # data = IJF{S}(ArrayType{FT}; Nij); test_mapreduce_2!(context, data) + # data = IF{S}(ArrayType{FT}; Ni); test_mapreduce_2!(context, data) + data = VF{S}(ArrayType{FT}; Nv) test_mapreduce_2!(context, data) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}; Nv, Nij, Nh) test_mapreduce_2!(context, data) - # data = VIFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nf,Nh)); test_mapreduce_2!(context, data) + # data = VIFH{S}(ArrayType{FT}; Nv,Nij,Nh); test_mapreduce_2!(context, data) # TODO: test this - # data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_mapreduce_2!(context, data) # TODO: test - # data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_mapreduce_2!(context, data) # TODO: test + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}; Nij,Nk,Nv,Nh); test_mapreduce_2!(context, data) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}; Nij); test_mapreduce_2!(context, data) # TODO: test end @testset "mapreduce views with Nf > 1" begin - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) data_view(data) = DataLayouts.rebuild( data, SubArray( @@ -130,26 +128,25 @@ end ) FT = Float64 S = Tuple{FT, FT} - Nf = 2 Nv = 4 - Nij = 3 + Ni = 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: - data = DataF{S}(device_zeros(FT, Nf)) + data = DataF{S}(ArrayType{FT}) test_mapreduce_2!(context, data_view(data)) - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}; Nij, Nh) test_mapreduce_2!(context, data_view(data)) - # data = IFH{S, Nij}(device_zeros(FT,Nij,Nf,Nh)); test_mapreduce_2!(context, data_view(data)) - # data = IJF{S, Nij}(device_zeros(FT,Nij,Nij,Nf)); test_mapreduce_2!(context, data_view(data)) - # data = IF{S, Nij}(device_zeros(FT,Nij,Nf)); test_mapreduce_2!(context, data_view(data)) - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + # data = IFH{S}(ArrayType{FT}; Ni,Nh); test_mapreduce_2!(context, data_view(data)) + # data = IJF{S}(ArrayType{FT}; Nij); test_mapreduce_2!(context, data_view(data)) + # data = IF{S}(ArrayType{FT}; Ni); test_mapreduce_2!(context, data_view(data)) + data = VF{S}(ArrayType{FT}; Nv) test_mapreduce_2!(context, data_view(data)) - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}; Nv, Nij, Nh) test_mapreduce_2!(context, data_view(data)) - # data = VIFH{S, Nv, Nij}(device_zeros(FT,Nv,Nij,Nf,Nh)); test_mapreduce_2!(context, data_view(data)) + # data = VIFH{S}(ArrayType{FT}; Nv,Nij,Nh); test_mapreduce_2!(context, data_view(data)) # TODO: test this - # data = DataLayouts.IJKFVH{S, Nij, Nk}(device_zeros(FT,Nij,Nij,Nk,Nf,Nv,Nh)); test_mapreduce_2!(context, data_view(data)) # TODO: test - # data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT,2*Nij,3*Nij)); test_mapreduce_2!(context, data_view(data)) # TODO: test + # data = DataLayouts.IJKFVH{S}(ArrayType{FT}; Nij,Nk,Nv,Nh); test_mapreduce_2!(context, data_view(data)) # TODO: test + # data = DataLayouts.IH1JH2{S}(ArrayType{FT}; Nij); test_mapreduce_2!(context, data_view(data)) # TODO: test end diff --git a/test/DataLayouts/unit_ndims.jl b/test/DataLayouts/unit_ndims.jl index 0b68f05945..50114d514d 100644 --- a/test/DataLayouts/unit_ndims.jl +++ b/test/DataLayouts/unit_ndims.jl @@ -9,44 +9,42 @@ ClimaComms.@import_required_backends @testset "Base.ndims" begin device = ClimaComms.device() - device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) + ArrayType = ClimaComms.array_type(device) FT = Float64 S = FT - Nf = 1 Nv = 4 - Nij = 3 + Ni = Nij = 3 Nh = 5 Nk = 6 - data = DataF{S}(device_zeros(FT, Nf)) + + data = DataF{S}(ArrayType{FT}, zeros) @test ndims(data) == 1 @test ndims(typeof(data)) == 1 - data = IF{S, Nij}(device_zeros(FT, Nij, Nf)) + data = IF{S}(ArrayType{FT}, zeros; Ni) @test ndims(data) == 2 @test ndims(typeof(data)) == 2 - data = VF{S, Nv}(device_zeros(FT, Nv, Nf)) + data = VF{S}(ArrayType{FT}, zeros; Nv) @test ndims(data) == 2 @test ndims(typeof(data)) == 2 - data = IFH{S, Nij}(device_zeros(FT, Nij, Nf, Nh)) + data = IFH{S}(ArrayType{FT}, zeros; Ni, Nh) @test ndims(data) == 3 @test ndims(typeof(data)) == 3 - data = IJF{S, Nij}(device_zeros(FT, Nij, Nij, Nf)) + data = IJF{S}(ArrayType{FT}, zeros; Nij) @test ndims(data) == 3 @test ndims(typeof(data)) == 3 - data = IJFH{S, Nij}(device_zeros(FT, Nij, Nij, Nf, Nh)) + data = IJFH{S}(ArrayType{FT}, zeros; Nij, Nh) @test ndims(data) == 4 @test ndims(typeof(data)) == 4 - data = VIFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nf, Nh)) + data = VIFH{S}(ArrayType{FT}, zeros; Nv, Ni, Nh) @test ndims(data) == 4 @test ndims(typeof(data)) == 4 - data = VIJFH{S, Nv, Nij}(device_zeros(FT, Nv, Nij, Nij, Nf, Nh)) + data = VIJFH{S}(ArrayType{FT}, zeros; Nv, Nij, Nh) @test ndims(data) == 5 @test ndims(typeof(data)) == 5 - data = DataLayouts.IJKFVH{S, Nij, Nk, Nv}( - device_zeros(FT, Nij, Nij, Nk, Nf, Nv, Nh), - ) + data = DataLayouts.IJKFVH{S}(ArrayType{FT}, zeros; Nij, Nk, Nv, Nh) @test ndims(data) == 6 @test ndims(typeof(data)) == 6 - data = DataLayouts.IH1JH2{S, Nij}(device_zeros(FT, 2 * Nij, 3 * Nij)) + data = DataLayouts.IH1JH2{S}(ArrayType{FT}, zeros; Nij) @test ndims(data) == 2 @test ndims(typeof(data)) == 2 end