Fix: re-guard dispatch_shape() do-while against empty core mask#569
Merged
poursoul merged 1 commit intohw-native-sys:mainfrom Apr 16, 2026
Merged
Fix: re-guard dispatch_shape() do-while against empty core mask#569poursoul merged 1 commit intohw-native-sys:mainfrom
poursoul merged 1 commit intohw-native-sys:mainfrom
Conversation
Commit 9951499 refactored the two-phase dispatch helper but dropped the guard that PR hw-native-sys#566 (af3b1db) had introduced. When a multi-block task drains all available cores mid-batch, the next task in the batch entered the do-while unconditionally, calling cores.pop_first() on an empty bitmask (returns -1) and passing -1 as core_offset to dispatch_block(), causing OOB access. Re-add the guard before dispatched_any = true in both a2a3 and a5: when cores are exhausted, push_batch() re-enqueues the current and remaining batch tasks atomically and breaks out of the for-loop. The existing regression test (spmd_batch_dispatch_oob) covers this.
There was a problem hiding this comment.
Code Review
This pull request introduces guards in the AICPU executor for both a2a3 and a5 runtimes to handle scenarios where a task batch exhausts available cores. When no cores are available, the remaining tasks in the batch are re-enqueued to the scheduler's ready queue. I have no feedback to provide.
poursoul
approved these changes
Apr 16, 2026
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.
Summary
cores.has_value()guard before thedo-whileblock dispatch loop indispatch_shape()for both a2a3 and a5do-whileunconditionally, callingcores.pop_first()on an empty bitmask (returns -1) and passing -1 ascore_offsettodispatch_block(), causing OOB accessRoot Cause
pop_ready_tasks_batch()pops up towant = cores.count()tasks, but a single multi-block task can consume all those cores in its inner dispatch loop. Subsequent tasks in the same batch then see an empty mask. The fix: if!cores.has_value()before entering dispatch, callpush_batch()to re-enqueue the current and remaining batch tasks atomically, thenbreak.Testing
tests/st/a2a3/tensormap_and_ringbuffer/spmd_batch_dispatch_oob/covers this exact scenario (two back-to-back MIX tasks withblock_num=48on 24 clusters)Related Issues
Regression introduced by #9951499; original fix was #566 (#565)