Repository navigation
Conversation
Two changes to reserving space in a device-initiated SDMA queue. Cached read index: every reservation read the queue's HW read pointer, an uncached round trip of ~1.8 us, to check that the ring has room. Like rocm-xio's SdmaQueueHandle::CanWriteUpto, keep the last observed read index and read the HW pointer only when the cached value says the ring is full. The HW read index only grows, so a stale value (or one written by another workgroup) is a lower bound and never reports space that does not exist. The cache lives in a new last column of the copy-engine context tensor (sdma_utils.queue_ctx_size(), queue_ctx(), cached_read_index_slot()); it starts at 0. Reservation drops from ~2.3 to ~0.85 us. Straddle the ring end: when a command did not fit before the end of the ring, acquire_fadd padded the rest of the ring with NOPs, submitted the padding and reserved again. The copy engine fetches the ring modulo its size (the amdgpu driver never pads at the wrap either), so instead every packet writer now wraps each dword and a command may cross the end. acquire_fadd and acquire return just the start index and no longer need the queue, write, doorbell and committed pointers. Tests: fake-queue tests for commands that straddle the end (atomic, 2-D put) and for the cached read index (refreshed only when the ring looks full); a hardware test that wraps a device queue three times with 28-byte copies, which cannot all land on the ring boundary, and checks every copy. Co-Authored-By: Claude <[email protected]>
dsidler
requested review from
BKP,
artulab,
drprajap,
efric,
mawad-amd,
neoblizz and
nirvedhmeshram
as code owners
November 25, 2026 18:00
This branch has not been deployed
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.
Stacked on #659 (base
dev/dasidler/sdma-packet-vector-store). Review only the top commit.Summary
Two changes to reserving space in a device-initiated SDMA queue (
iris/device/sdma_utils.py).Cached HW read index. Every reservation read the queue's hardware read pointer, an uncached round trip of ~1.8 µs, to check that the ring has room. Like rocm-xio's
SdmaQueueHandle::CanWriteUpto,can_write_up_tonow keeps the last observed read index and reads the hardware pointer only when the cached value says the ring is full. The hardware read index only grows. A stale cached value, or one written by another workgroup, is therefore a lower bound and never reports space that does not exist.The cache lives in a new last column of the copy-engine context tensor and starts at 0. The row layout now has one source of truth:
queue_ctx_size(): used byIristo allocate the tensorqueue_ctx(copy_engine_ctx, to_rank): device-side row lookupcached_read_index_slot(row): pointer to the cached indexAll row arithmetic in
iris/mem/triton/ops.pyandcopy_lineargoes through these.Commands straddle the ring end. When a command did not fit before the end of the ring,
acquire_faddpadded the rest of the ring with NOPs, submitted the padding, and reserved again. The copy engine fetches the ring modulo its size; the amdgpu kernel driver never pads at the wrap either. So every packet writer now wraps each dword (_ring_dword), and a command may cross the end of the ring. As a result:acquire_fadd/acquirereturn just the start index.place_nop_packet(..., offset)/+ offsetbookkeeping.place_nop_packetstays available and also wraps per dword.The modulo indexing keeps one store instruction per packet (checked in the AMDGCN).
Measured on MI300X (8 GPUs, timestamped copy of the submit path):
Tests
test_sdma_packets.py, fake queue:test_command_straddles_ring_end: an atomic (8 dwords) and a 2-D put (20 dwords) placed 1, 2 or 7 dwords before the ring end are split across end and start with the exact dwords, no NOP, and all pointers advanced by exactly the command.test_reservation_refreshes_cached_read_index: the cache is refreshed only when the ring looks full.test_copy_engine_ops.py::test_copy_engine_ring_wrap, hardware: 8 workgroups wrap a device queue three times with 28-byte linear copies. 8 MiB mod 28 ≠ 0, so at most one of the three wraps can land on a command boundary. Every copied element is checked.mainin this environment:test_sdma_packets.py25,test_copy_engine_ops.py25,test_copy_engine_tile_ops.py13,test_all_gather_sdma.py26,test_message_passing.py36,test_matmul_reduce_scatter.py21,test_optional_sdma.py4 passedtest_all_gather_sdma.py25 passed / 1 skipped,test_matmul_reduce_scatter.py21 passedmainhere:test_plan.pygluon (2) andtest_device_placement.py::test_ranks_placed_off_rank_mod_gpus(8).🤖 Generated with Claude Code