Commit e4a15ba
Fix GPU InvalidIR: compute _col_major_offset via unrolled_reduce [perf]
The real cause of the persisting Integrals/matrix GPU InvalidIRError
(ijl_get_nth_field_checked in single_column_reduce!/bycolumn_kernel! and
eager_copyto_stencil_kernel!) was F1's `_col_major_offset` helper, written as a
tuple TAIL-RECURSION. It constant-folds on CPU, but under the deep inlining of a
stencil / column-reduce kernel, device inference exhausts its recursion/const-prop
budget, widens the peeled tuple argument to an abstract `Tuple`, and lowers
`idx[1]` to a runtime bounds-checked `getfield` (ijl_get_nth_field_checked) that
cannot compile on device. (The earlier type-level flat_mode change was not the
culprit; it is kept as harmless hardening.)
Replace the recursion with `unrolled_reduce` (UnrolledUtilities, already a
DataLayouts dependency), keeping all unrolling isolated to that package rather
than an ad-hoc @generated: it emits a non-self-recursive unrolled body that folds
regardless of the surrounding inference budget. Carries (offset, stride) in a
left fold over the (size, coord) pairs.
Verified locally (device-free GPUCompiler IR check, manual CompilerJob on the
real device kernel types — not the Adapt path): bycolumn_kernel! (extruded +
column) and eager_copyto_stencil_kernel! now compile clean; DataLayouts
unit_loops / unit_struct / unit_fill_and_copyto pass; CPU getindex/setindex
values unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 68ae496 commit e4a15ba
1 file changed
Lines changed: 17 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
150 | 162 | | |
151 | 163 | | |
152 | 164 | | |
| |||
0 commit comments