Refactor: unify two-phase dispatch and fix sync_start spin loop#553
Merged
poursoul merged 1 commit intohw-native-sys:mainfrom Apr 15, 2026
Merged
Refactor: unify two-phase dispatch and fix sync_start spin loop#553poursoul merged 1 commit intohw-native-sys:mainfrom
poursoul merged 1 commit intohw-native-sys:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the AICPU executor to implement a two-phase dispatch mechanism (IDLE and PENDING) for AIC, AIV, and MIX resource shapes. The changes introduce a unified dispatch_shape function and update the CoreTracker to manage bit offsets for both phases, which also addresses a bug where AIC core states could incorrectly interfere with AIV idle dispatch. Feedback was provided regarding an inaccuracy in the code comments describing the bit representation for AIV idle dispatch, noting that it incorrectly claims a per-core bit representation when it is actually per-cluster for the idle phase.
Replace the separate idle-dispatch and AIC-only pending-dispatch loops with a single dispatch_shape() that iterates IDLE then PENDING phases for every resource shape (AIC, AIV, MIX). Key changes: - Add CoreTracker::DispatchPhase enum and get_dispatchable_cores() as a unified query for both phases - Rename get_idle_cluster_offset_states -> get_idle_core_offset_states; skip AIC-centric pending_occupied filter for AIV/MIX (fixes a latent bug where running+pending AIC blocked AIV idle dispatch) - Consolidate get_pending_only_cluster_offset_states into get_pending_core_offset_states, extending pending dispatch to AIV and MIX shapes - MIX pending dispatch: require at least one running core per cluster but allow idle cores to participate; dispatch_mix_block_to_cluster resolves per-core to_pending (idle cores use to_pending=false to trigger change_core_state, running cores use to_pending=true) - Rename dispatch_block_to_cluster -> dispatch_block with a to_pending parameter; AIV pending dispatch passes resolved core bit offset - Fix infinite spin when all tasks in a pending-phase batch are sync_start (requeued without dispatching); dispatch_shape now breaks when dispatched_any is false
poursoul
approved these changes
Apr 15, 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
dispatch_shape()helper, replacing two separate hand-unrolled loops inresolve_and_dispatch_pto2get_idle_cluster_offset_statesincorrectly applied AICpending_occupiedfilter to AIV idle dispatch, causing spurious idle-slot blockssync_startspin loop: tasks that cannot be dispatched in pending phase are now requeued immediately instead of spinningKey Changes
get_idle_cluster_offset_states→get_idle_core_offset_states: AIC-only filter forpending_occupied; AIV/MIX no longer filtered (invariant guarantees idle cores always havepending_occupied=0)get_pending_only_cluster_offset_states→get_pending_core_offset_states: extended to support AIV (per-core) and MIX (all 3 cores per cluster must be running+free)DispatchPhaseenum andget_dispatchable_cores(shape, phase)unified querydispatch_shape(): encapsulates all per-shape dispatch logic for one phase, including sync_start gating, drain-mode entry, multi-block do-while, and lazy refreshdispatch_block_to_clusterrenameddispatch_blockwith explicitto_pendingflag; MIXdispatch_mix_block_to_clusternow forwards the flag to all three subtask slotsresolve_and_dispatch_pto2main loop collapses to two nested loops:for phase in {IDLE, PENDING}: for shape in dispatch_order: dispatch_shape(...)Testing
./ci.sh -p a2a3sim)🤖 Generated with Claude Code