Skip to content

Commit

Permalink
Assert atmos to not have UnionAll types
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Dec 15, 2023
1 parent 06a3da7 commit a716d02
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ClimaAtmos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include(joinpath("parameters", "Parameters.jl"))
import .Parameters as CAP

include(joinpath("utils", "abbreviations.jl"))
include(joinpath("utils", "gpu_compat.jl"))
include(joinpath("utils", "common_spaces.jl"))
include(joinpath("solver", "types.jl"))
include(joinpath("solver", "cli_options.jl"))
Expand Down
1 change: 1 addition & 0 deletions src/solver/type_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function get_atmos(config::AtmosConfig, params)
surface_model = get_surface_model(parsed_args),
numerics = get_numerics(parsed_args),
)
@assert !@has_DataType_or_UnionAll(atmos)

@info "AtmosModel: \n$(summary(atmos))"
return atmos
Expand Down
29 changes: 29 additions & 0 deletions src/utils/gpu_compat.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
has_DataType_or_UnionAll(::Any)
Returns a Bool (and prints warnings if) the given
data structure has an instance of `DataType` or
`UnionAll` type, both of which are not `isbits`
and therefore cannot be broadcasted through a
gpu kernel.
"""
function has_DataType_or_UnionAll(obj, name, pc = ())
for pn in propertynames(obj)
prop = getproperty(obj, pn)
pc_full = (pc..., ".", pn)
pc_string = name * string(join(pc_full))
if prop isa DataType
@warn "$pc_string::$(typeof(prop)) is a DataType"
return true
elseif prop isa UnionAll
@warn "$pc_string::$(typeof(prop)) is a UnionAll"
return true
else
has_DataType_or_UnionAll(prop, name, pc_full)
end
end
return false
end
macro has_DataType_or_UnionAll(obj)
return :(has_DataType_or_UnionAll($(esc(obj)), $(string(obj))))
end

0 comments on commit a716d02

Please sign in to comment.