-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use UniversalSize struct in more kernels
- Loading branch information
1 parent
4736aea
commit 82151d9
Showing
7 changed files
with
128 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#= | ||
julia --project | ||
using Revise; include(joinpath("test", "DataLayouts", "opt_universal_size.jl")) | ||
=# | ||
using Test | ||
using ClimaCore.DataLayouts | ||
using ClimaCore: DataLayouts, Geometry | ||
import ClimaComms | ||
using StaticArrays: SMatrix | ||
ClimaComms.@import_required_backends | ||
using JET | ||
using InteractiveUtils: @code_typed | ||
|
||
function test_universal_size(data) | ||
us = DataLayouts.UniversalSize(data) | ||
# Make sure results is statically returned / constant propagated | ||
ct = @code_typed DataLayouts.get_N(us) | ||
@test ct.first.code[1] isa Core.ReturnNode | ||
@test ct.first.code[end].val == DataLayouts.get_N(us) | ||
|
||
ct = @code_typed DataLayouts.get_Nv(us) | ||
@test ct.first.code[1] isa Core.ReturnNode | ||
@test ct.first.code[end].val == DataLayouts.get_Nv(us) | ||
|
||
ct = @code_typed DataLayouts.get_Nij(us) | ||
@test ct.first.code[1] isa Core.ReturnNode | ||
@test ct.first.code[end].val == DataLayouts.get_Nij(us) | ||
|
||
ct = @code_typed DataLayouts.get_Nh(us) | ||
@test ct.first.code[1] isa Core.ReturnNode | ||
@test ct.first.code[end].val == DataLayouts.get_Nh(us) | ||
|
||
ct = @code_typed size(data) | ||
@test ct.first.code[1] isa Core.ReturnNode | ||
@test ct.first.code[end].val == size(data) | ||
|
||
ct = @code_typed DataLayouts.get_N(data) | ||
@test ct.first.code[1] isa Core.ReturnNode | ||
@test ct.first.code[end].val == DataLayouts.get_N(data) | ||
|
||
# Demo of failed constant prop: | ||
ct = @code_typed prod(size(data)) | ||
@test ct.first.code[1] isa Expr # first element is not a return node, but an expression | ||
end | ||
|
||
@testset "UniversalSize" begin | ||
device = ClimaComms.device() | ||
device_zeros(args...) = ClimaComms.array_type(device)(zeros(args...)) | ||
FT = Float64 | ||
S = FT | ||
Nf = 1 | ||
Nv = 4 | ||
Nij = 3 | ||
Nh = 5 | ||
Nk = 6 | ||
#! format: off | ||
data = DataF{S}(device_zeros(FT,Nf)); test_universal_size(data) | ||
data = IJFH{S, Nij, Nh}(device_zeros(FT,Nij,Nij,Nf,Nh)); test_universal_size(data) | ||
data = IFH{S, Nij, Nh}(device_zeros(FT,Nij,Nf,Nh)); test_universal_size(data) | ||
data = IJF{S, Nij}(device_zeros(FT,Nij,Nij,Nf)); test_universal_size(data) | ||
data = IF{S, Nij}(device_zeros(FT,Nij,Nf)); test_universal_size(data) | ||
data = VF{S, Nv}(device_zeros(FT,Nv,Nf)); test_universal_size(data) | ||
data = VIJFH{S,Nv,Nij,Nh}(device_zeros(FT,Nv,Nij,Nij,Nf,Nh));test_universal_size(data) | ||
data = VIFH{S, Nv, Nij, Nh}(device_zeros(FT,Nv,Nij,Nf,Nh)); test_universal_size(data) | ||
#! format: on | ||
# data = DataLayouts.IJKFVH{S, Nij, Nk, Nv, Nh}(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 | ||
end |