Fix ring buffer indexing in AIE AQL queue SubmitPackets#3619
Open
aamarnat wants to merge 1 commit intoROCm:developfrom
Open
Fix ring buffer indexing in AIE AQL queue SubmitPackets#3619aamarnat wants to merge 1 commit intoROCm:developfrom
aamarnat wants to merge 1 commit intoROCm:developfrom
Conversation
atgutier
approved these changes
Feb 27, 2026
cfreeamd
approved these changes
Feb 28, 2026
4cd0de5 to
2313d04
Compare
dayatsin-amd
approved these changes
Mar 3, 2026
ypapadop-amd
approved these changes
Mar 6, 2026
a2d497f to
17d1074
Compare
Use modulo to properly index into the ring buffer when accessing packets in SubmitPackets. The queue indices (cur_id and peak_pkt_id) can grow unbounded and exceed the queue size, so modulo is required to wrap around correctly. Without this fix, accessing packets beyond the ring buffer size causes out-of-bounds memory access and undefined behavior after the queue wraps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
17d1074 to
e49a874
Compare
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.
Motivation
Fix a ring buffer overflow bug in the AIE AQL queue that causes out-of-bounds memory access when queue indices wrap around. The SubmitPackets function was using absolute packet indices (cur_id and peak_pkt_id) directly to access the ring buffer, without applying modulo. This caused crashes after the queue size (64 packets) was exceeded.
Technical Details
In AieAqlQueue::SubmitPackets():
The producer side (eg. code in GGML https://github.com/ypapadop-amd/ggml/blob/68e0094019edabe519d9f50240d4aa5378bd01b3/src/ggml-hsa/aie-kernel.cpp#L29-L31) already correctly uses modulo when writing packets, but the consumer side (in ROCr-runtime: here and here) was not using modulo when reading packets, causing the mismatch.
Test Plan
Test Result
Test passes with 100+ dispatches completing successfully. Queue IDs increment past the original crash point (64) and continue to work correctly with proper ring buffer wrap-around.
Submission Checklist