Skip to content

[HAL] Handle empty tensors and empty buffer ranges in the runtime drivers - #25329

Merged
jschuhmacher merged 5 commits into
mainfrom
users/jschuhmacher/hal_empty_extents
Nov 25, 2026
Merged

jschuhmacher merged 5 commits into
mainfrom
users/jschuhmacher/hal_empty_extents

Conversation

@jschuhmacher

Copy link
Copy Markdown
Contributor

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

Generating an empty buffer view on a device whose memory cannot be mapped
failed instead of producing an empty view, because the host staging step
required a non-zero allocation. Empty inputs now reach the generator and
produce an empty buffer view, as they already do on devices with mappable
memory.

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

Assisted-by: Codex
A grid with any zero dimension launches no workgroups, but only a fully
zero grid was treated as a no-op. Grids such as 4x0x1 reached device
launch APIs that reject them.

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

Assisted-by: Claude Code
A zero-byte queue allocation received no device storage on HIP, so every
later use of the buffer waited forever and the queue stopped making
progress. CUDA memory pools cannot serve a zero-byte request either.
Empty queue allocations now behave like empty synchronous allocations.

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

Assisted-by: Claude Code
Dispatches over empty tensors bind zero-length buffer ranges, which
Vulkan descriptors and BDA binding tables could not represent, so those
dispatches failed. Empty bindings now refer to a device-owned placeholder
that the dispatch never accesses.

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

Assisted-by: Claude Code

@schuermans-roofline schuermans-roofline left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general. I annotated a nit suggestion and two questions about potential additions.

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

Assisted-by: Claude Code

@schuermans-roofline schuermans-roofline left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jschuhmacher
jschuhmacher merged commit 99962e6 into main Nov 25, 2026
60 checks passed
@jschuhmacher
jschuhmacher deleted the users/jschuhmacher/hal_empty_extents branch November 25, 2026 10:57
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.

2 participants