Skip to content

Derive parallel-axis bounds interprocedurally and from dominating guards - #2991

Open
wsmoses wants to merge 1 commit into
mainfrom
pb/extent-bound-derivation
Open

Derive parallel-axis bounds interprocedurally and from dominating guards#2991
wsmoses wants to merge 1 commit into
mainfrom
pb/extent-bound-derivation

Conversation

@wsmoses

@wsmoses wsmoses commented Aug 27, 2026

Copy link
Copy Markdown
Member

Follow-up to #2981. The bounded-axis batching only helped kernels whose clamp is in the same function as the launch. MFEM's runtime-dispatch fallback families (quadinterpolator, lininteg, restriction) break that assumption three ways: the ceiling lives in a dispatcher MFEM_VERIFY rather than a min; the extent crosses the noinline device-stub boundary as a plain argument; and LLVM deletes source-level clamps it can prove redundant from those very verifies (adding min(q1d, MAX_Q1D) at the launch literally compiles away).

derivedExtentBound therefore learns to:

  • walk call sites: a stub argument's bound is the max over what direct callers pass (kernel-registration addressof uses are skipped), and the recursion anchors at the call site so caller-side guards apply to the launch inside;
  • read dominating guards: a cmp+noreturn verify arm, or the surviving branch of an enclosing scf.if, pins the complementary relation (if (d < 25) bounds the axis at 24);
  • see through the plumbing: staged scalars (the gpu.alloc+memcpy hoisting), dim3 packing (x * 0x100000001 replication, disjoint-or with a constant, trunc/shrui halves), llvm.intr.smin/smax, extension, bounded sums/products (dof counts like 2*(D1D-1)*D1D), and selects;
  • fall back to scratch shapes: static buffers an axis unconditionally indexes bound it on pain of out-of-bounds.

boundParallelFors applies the same batching to a parallel-marked affine.for that never became an affine.parallel (identified by its iv appearing as a barrier operand), and the #2980 check now accepts a barrier whose iv belongs to a constant-trip affine.for — lockstep raising gives it the same whole-tensor ordering as a batched parallel axis. Dim-expr upper-bound maps are accepted alongside symbols.

On the MFEM sweep this class went from 23 dynamic-barrier TU failures to zero: quadinterpolator.cpp and the lininteg family fully raise, and the QuadratureInterpolator-adjacent runtime battery stays exact.

🤖 Generated with Claude Code

https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD

MFEM's runtime-dispatch fallback kernels carry no min-clamp of their
own: the ceiling lives in a dispatcher MFEM_VERIFY, the extent crosses
the noinline launch-stub boundary as a plain argument, and LLVM deletes
any source-level clamp it can prove redundant from those very guards.
derivedExtentBound therefore learns to
- walk call sites: a stub argument's bound is the max over what direct
  callers pass (registration addressofs are skipped), with the call
  site as the anchor so caller-side guards apply to the launch inside
- read dominating guards: a noreturn verify arm or the enclosing
  surviving scf.if branch pins the complementary relation
- see through staged scalars (the gpu.alloc + memcpy hoisting), dim3
  packing (the 0x100000001 replication, or-with-constant, trunc/shrui
  halves), llvm.intr.smin/smax forms, extension, bounded sums and
  products, and selects
- fall back to the shapes of static scratch an axis unconditionally
  indexes, which bound the axis on pain of out-of-bounds

boundParallelFors applies the same batching to a parallel-marked
affine.for that never became an affine.parallel (identified by its iv
appearing as a barrier operand), and a barrier whose iv belongs to a
constant-trip affine.for is a no-op exactly like a batched parallel
axis. Upper-bound maps using a dim expr instead of a symbol are
accepted.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant