Skip to content

[StableHLO] Support StableHLO programs with dynamic dimensions, empty tensors, and general indexing operations. - #25236

Draft
jschuhmacher wants to merge 70 commits into
mainfrom
users/jschuhmacher/stablehlo_stage01_dynamic_shapes
Draft

jschuhmacher wants to merge 70 commits into
mainfrom
users/jschuhmacher/stablehlo_stage01_dynamic_shapes

Conversation

@jschuhmacher

@jschuhmacher jschuhmacher commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Lower StableHLO programs whose dimensions are only known at run time, including
empty tensors and general gather/scatter.

The input is trusted. Facts available from dynamic shapes, shape assertions and
the surrounding IR become util.assume.int facts or, where provable, static
shapes. Shape assertions are not checked at run time; invalid inputs are outside
the supported contract, and no runtime checks, assertions or status results are
emitted for them. Constant invalid inputs are diagnosed at compile time.

StableHLO input conversion

  • Dynamic reshape, broadcast, concatenation, slicing and update slicing use
    symbolic size proofs (a constant times a product of symbols with powers, plus
    an offset) to emit expand_shape/collapse_shape, including reshapes that
    collapse some dimensions and expand others.
  • Padding without interior padding lowers to a slice of the kept window plus
    tensor.pad; padding with interior padding computes its full-range phase on
    the host, so device code needs only index arithmetic.
  • Convolution supports runtime padding, dilation, feature and batch groups and
    crops.
  • Gather, dynamic slice and scatter clamp start indices exactly for any index
    width of at least 32 bits, including unsigned and narrow index types.
  • Reduction, window reduction and scan handle type promotion and empty extents.
  • Custom calls: shape assertions become facts; their private helper functions
    are inlined first.

Supporting compiler changes

  • LinalgExt: general scatter (verification, tiling, scalar lowering) and sort
    with dynamic shapes.
  • Codegen (Common, SPIR-V, VM, VMVX, Metal): narrow integer and f16/bf16
    emulation on targets without native support, signed-zero preservation, and
    binding offsets kept through flattened memref subspans.
  • Flow: dynamic dimensions captured through scf.if.
  • Stream: transient allocations bounded by proven sizes; resource usage tracked
    through optimization barriers.
  • DispatchCreation and GlobalOptimization: unit-extent folding keeps strided
    extents; zero-trip reductions fold to their initial value.
  • LLVMGPU: undistributable scans and scatters use a single-thread configuration.

Assisted-by: Codex
Assisted-by: Claude Code

@jschuhmacher
jschuhmacher force-pushed the users/jschuhmacher/stablehlo_stage01_dynamic_shapes branch from 9bded43 to 734fbff Compare November 10, 2026 12:21
@jschuhmacher jschuhmacher changed the title [StableHLO] Preserve dynamic shape and indexing semantics through execution [StableHLO] Support StableHLO programs with dynamic dimensions, empty tensors, and general indexing operations. Nov 10, 2026
Base automatically changed from users/jschuhmacher/stablehlo_target_registry to main November 10, 2026 14:31
@jschuhmacher
jschuhmacher force-pushed the users/jschuhmacher/stablehlo_stage01_dynamic_shapes branch 2 times, most recently from 4566f15 to 2c4bc0d Compare November 16, 2026 14:38
@jschuhmacher

Copy link
Copy Markdown
Contributor Author

Needs #25285

@jschuhmacher

Copy link
Copy Markdown
Contributor Author

Needs: #25291

@jschuhmacher

Copy link
Copy Markdown
Contributor Author

Needs #25329

@jschuhmacher

Copy link
Copy Markdown
Contributor Author

Needs #25330

jschuhmacher added a commit that referenced this pull request Nov 25, 2026
…vers (#25329)

Programs with dynamic shapes can produce tensors with a zero-sized
dimension at
runtime. The compiler cannot fold these away, because the extent is only
known
at execution time, so the HAL drivers receive empty buffers, empty
binding
ranges and partially empty workgroup grids. Several drivers rejected
these or
stalled on them. This change makes them work in the HAL core, CUDA, HIP,
AMDGPU and Vulkan.

## Changes

- **Empty buffer views on devices that stage uploads.** Generating an
empty
buffer view failed on devices whose memory cannot be mapped, because the
host staging step required a non-zero allocation. The generator callback
is
now also invoked for empty views, as it already was on devices with
mappable
  memory.
- **Dispatches with a partially empty workgroup grid.** A grid with any
zero
dimension (for example 4x0x1) launches no workgroups, but only a fully
zero
grid was treated as a no-op. Grids like that reached device launch APIs
that
reject them. The HAL command buffer and the AMDGPU host queue now skip
them.
- **Empty queue allocations on HIP and CUDA.** A 0-byte `queue_alloca`
asked the pool for 0 bytes and got a null pointer back, so the buffer
never
looked ready. Its first use waited forever and stalled the queue. These
  allocations are now backed by a small allocation while keeping a byte
  length of 0.
- **Empty binding ranges on Vulkan.** Vulkan descriptors cannot have a
zero
range, and a buffer-device-address (BDA) binding table entry needs a
valid
address. Each device now owns a small empty-binding buffer that is bound
in
place of an empty range, in both the descriptor and the BDA dispatch
paths.
  Shaders never read from it, because the binding has no elements.

These failures came up in the StableHLO dynamic-shape work (#25236),
which
depends on this change.

Assisted-by: Claude Code
@jschuhmacher
jschuhmacher force-pushed the users/jschuhmacher/stablehlo_stage01_dynamic_shapes branch from 675092d to 74d9d51 Compare November 27, 2026 16:01
…cution

Keep runtime extents, shape constraints, general scatter semantics, and observable dispatch failures across lowering and execution.

Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
…sions

Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Assisted-by: Codex

Signed-off-by: Jelle Schuhmacher <[email protected]>
Assisted-by: Codex

Signed-off-by: Jelle Schuhmacher <[email protected]>
The clone-cost lookup captured a structured binding in a lambda, which C++17
does not allow. Clang accepts it only as an extension, so builds that treat
warnings as errors rejected the StableHLO plugin.

Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
The upstream StableHLO convolution verifier reads constant padding as signed
and asserts on the negative bound an unsigned value with its high bit set
produces, so assertion-enabled builds could not parse these tests. The
normalisation of such constants stays covered without parse-time
verification; end-to-end coverage keeps the runtime unsigned padding case.

Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
MSVC cannot choose between the const and non-const SPIRV-Cross constant
lookups from inside the lambda, which broke the Windows build.

Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
These tests now run correctly on Vulkan devices without native 16-bit float
support, so listing them as expected failures fails the suite.

Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
The CMake build does not provide split-file to lit tests, so these tests
failed wherever no system copy happened to be installed. Each case that a
second pipeline checks now lives in its own test file.

Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Wide shape-computation constants and the signed minimum must yield a valid
divisor instead of aborting or overflowing.

Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
The byte offset of an interface binding is optional; a binding without one
starts at the beginning of its buffer.

Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Dynamic-shape support does not depend on normalising deprecated operations,
so keep that compatibility work out of this change for separate review.

Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Codex
Padding amounts given as index elements were not accepted as signed
values, and a padding edge of INT64_MIN wrapped to a negative crop once
negated. Both produced wrong pad results for trusted inputs that the
StableHLO specification allows.

Assisted-by: Claude Code
The static extreme-padding pad case overflowed inside StableHLO's own shape
inference before reaching IREE, so it tested upstream behaviour rather than
IREE's lowering, which the dynamic and unit tests already cover. The ONNX
uint8 division test now compiles on Vulkan RDNA3 at O0 and is no longer an
expected failure.

Signed-off-by: Jelle Schuhmacher <[email protected]>

Assisted-by: Claude Code
@jschuhmacher
jschuhmacher force-pushed the users/jschuhmacher/stablehlo_stage01_dynamic_shapes branch from 74d9d51 to 47d0ee3 Compare December 2, 2026 14:01

This branch has not been deployed

No deployments
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