Repository navigation
[HAL] Handle empty tensors and empty buffer ranges in the runtime drivers - #25329
Merged
Merged
Conversation
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
jschuhmacher
marked this pull request as ready for review
November 24, 2026 16:17
jschuhmacher
requested review from
AGindinson,
Manewing,
antiagainst,
benvanik,
devtbi,
krzysz00,
kuhar,
roberto-laudani,
schuermans-roofline and
ziereis
as code owners
November 24, 2026 16:17
schuermans-roofline
left a comment
Contributor
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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.
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.
queue_allocaasked 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.
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