Skip to content

Commit b20fad1

Browse files
dennisYatuninclaude
andcommitted
Revert flat_mode to value-level; 68ae496 was a no-op [perf]
Commit 68ae496 made `flat_mode` type-level on the theory that the value-level form could fail to constant-fold under GPU const-prop and emit a checked getfield -> InvalidIR. That was the wrong culprit: the real GPU-InvalidIR was `_col_major_offset`'s tuple tail-recursion, fixed in e4a15ba via unrolled_reduce. With _col_major_offset fixed, the type-level form makes no difference across any metric, so restore the simpler value-level `flat_mode` (identical to F1's original bd53967 form). Verified locally (device-free GPUCompiler CompilerJob + CPU code_typed/code_llvm, reverted vs HEAD, plus a 3-lens adversarial re-check): - GPU: bycolumn_kernel! (extruded + column) and eager_copyto_stencil_kernel! (matrix TridiagonalMatrixRow) all compile clean -- same verdicts as type-level. - CPU: getindex/setindex! codegen byte-identical across the layout matrix (0 div/rem, 0 alloc, flat_mode fully folded, no surviving dynamic dispatch); flat_mode(data) === flat_mode(typeof(data)) for every layout. - DataLayouts unit_struct / unit_loops / unit_fill_and_copyto: byte-identical Test Summary lines, 0 Fail/Error. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e4a15ba commit b20fad1

1 file changed

Lines changed: 12 additions & 21 deletions

File tree

src/DataLayouts/indexing.jl

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,19 @@ is_trivial_point(data, index) = isone(length(data)) && index == CartesianIndex()
9898
# Base reindex / `div` / `rem` is instantiated.
9999
# Val(0) everything else (dynamic `Nh`, or a true box `VIJFH` field view with
100100
# `Nh > 1`): the unchanged Cartesian path, which stays correct.
101-
# Decided entirely from the layout TYPE, mirroring `Base.IndexStyle(::Type{D})`,
102-
# so the decision is a compile-time constant on every backend (the value-domain
103-
# form let `f_dim(data)` reach a runtime tuple slice that failed to fold under
104-
# GPU inference, turning `_getidx_flat(flat_mode(data), ...)` into a dynamic
105-
# dispatch that compiled the `Val(2)` root path for unsupported types and emitted
106-
# a checked `getfield`). `F` is threaded as a `Val` type parameter so
107-
# `inferred_size(D)[F:end]` is a literal slice.
108-
@inline flat_mode(data::DataLayout) = flat_mode(typeof(data))
109-
@inline function flat_mode(::Type{D}) where {D <: DataLayout}
110-
has_inferred_size(D) || return Val(0)
111-
IndexStyle(D) isa IndexLinear && return Val(1)
112-
return _flat_mode_cartesian(D, Val(f_dim(D)))
101+
@inline function flat_mode(data::DataLayout)
102+
has_inferred_size(data) || return Val(0)
103+
IndexStyle(data) isa IndexLinear && return Val(1)
104+
F = f_dim(data)
105+
F isa Integer || return Val(0)
106+
# The root path omits every logical coordinate at or beyond the F axis, so it
107+
# is only correct when those extents are all 1 (the column case). Unlike the
108+
# layout IndexStyle, a `ncomponents <= 1` escape is NOT valid here: a scalar
109+
# field view of a box (Nh > 1) still needs its h-term, which we drop.
110+
all_ones(inferred_size(data)[F:end]...) &&
111+
reducible_property_view(parent_type(data), Val(F)) && return Val(2)
112+
return Val(0)
113113
end
114-
# The root path omits every logical coordinate at or beyond the F axis, so it is
115-
# only correct when those extents are all 1 (the column case). Unlike the layout
116-
# IndexStyle, a `ncomponents <= 1` escape is NOT valid here: a scalar field view
117-
# of a box (Nh > 1) still needs its h-term, which we drop.
118-
@inline _flat_mode_cartesian(::Type{D}, ::Val{nothing}) where {D} = Val(0)
119-
@inline _flat_mode_cartesian(::Type{D}, ::Val{F}) where {D, F} =
120-
F isa Integer &&
121-
all_ones(inferred_size(D)[F:end]...) &&
122-
reducible_property_view(parent_type(D), Val(F)) ? Val(2) : Val(0)
123114

124115
# A property-view SubArray (as built by struct_field_view) of an IndexLinear
125116
# array, whose indices are full `Slice`s except for a `UnitRange` at position F.

0 commit comments

Comments
 (0)