Skip to content

Commit

Permalink
Merge pull request #2018 from CliMA/ck/julia1p11
Browse files Browse the repository at this point in the history
Fix Julia 1.11
  • Loading branch information
charleskawczynski authored Oct 1, 2024
2 parents c6bfad8 + 84c5eb7 commit e632054
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/DataLayouts/DataLayouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,40 @@ end
)
end

### --------------- Support for multi-dimensional indexing
# TODO: can we remove this? It's not needed for Julia 1.10,
# but seems needed in Julia 1.11.
@inline Base.getindex(
data::Union{IJF, IJFH, IFH, VIJFH, VIFH, VF, IF},
I::Vararg{Int, N},
) where {N} = Base.getindex(data, to_universal_index(data, I))

@inline Base.setindex!(
data::Union{IJF, IJFH, IFH, VIJFH, VIFH, VF, IF},
val,
I::Vararg{Int, N},
) where {N} = Base.setindex!(data, val, to_universal_index(data, I))

@inline to_universal_index(data::AbstractData, I::Tuple) =
CartesianIndex(_to_universal_index(data, I))

# Certain datalayouts support special indexing.
# Like VF datalayouts with `getindex(::VF, v::Integer)`
#! format: off
@inline _to_universal_index(::VF, I::NTuple{1, T}) where {T} = (T(1), T(1), T(1), I[1], T(1))
@inline _to_universal_index(::IF, I::NTuple{1, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{2, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{3, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{4, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{5, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{2, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{3, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{4, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{5, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::AbstractData, I::NTuple{5}) = I
#! format: on
### ---------------

"""
data2array(::AbstractData)
Expand Down
4 changes: 2 additions & 2 deletions test/Spaces/ddss1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ init_state_vector(local_geometry, p) = Geometry.Covariant12Vector(1.0, -1.0)
#! format: on

p = @allocated Spaces.weighted_dss!(y0, dss_buffer)
@test p 39448 # cuda allocation
@test p 266744 # cuda allocation
@test p == 0 broken = device isa ClimaComms.CUDADevice
end

Expand All @@ -134,6 +134,6 @@ end
@test parent(yx) parent(y0)

p = @allocated Spaces.weighted_dss!(y0, dss_buffer)
@test p 39448 # cuda allocation
@test p 266744 # cuda allocation
@test p == 0 broken = device isa ClimaComms.CUDADevice
end

0 comments on commit e632054

Please sign in to comment.