Add: require_sync_start for atomic SPMD block launch#448
Merged
ChaoWao merged 2 commits intohw-native-sys:mainfrom Apr 3, 2026
Merged
Add: require_sync_start for atomic SPMD block launch#448ChaoWao merged 2 commits intohw-native-sys:mainfrom
ChaoWao merged 2 commits intohw-native-sys:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements the sync_start mechanism for SPMD tasks, ensuring atomic launching of all blocks. It introduces a drain protocol in the AicpuExecutor to coordinate resource allocation across scheduler threads and prevent starvation. The submission logic was updated to handle the require_sync_start flag, and a suite of golden tests was added to verify the feature's correctness and robustness. Feedback identifies a potential undefined behavior in bitwise shifts for thread masks and suggests adjusting the deadlock check to allow tasks that require exactly the total available resources.
src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_orchestrator.cpp
Outdated
Show resolved
Hide resolved
a2a3a68 to
572bfd7
Compare
ChaoWao
previously approved these changes
Apr 3, 2026
Introduce a sync_start mechanism that forces all blocks of an SPMD task to be dispatched atomically before any can begin execution. Submission layer (pto_submit_types.h, pto_orchestrator.cpp/h): - Add LaunchSpec::require_sync_start and active_mask bit-3 flag - Add pto2_core_mask() / pto2_requires_sync_start() helpers - Validate block_num < total resources at submit time to prevent deadlock - Fix total_required_subtasks to use pto2_core_mask (strip flag bits) Scheduler drain protocol (aicpu_executor.cpp): - Three-phase drain: ack barrier → global resource check → exclusive dispatch - Elected thread verifies global idle resources before dispatching; if insufficient, all threads return to completion polling and retry - Non-elected threads spin-wait during dispatch, giving the elected thread exclusive CoreTracker access (no data race on core_states_) - Track active_sched_threads_ separately from thread_num_ so orchestrator threads that have not transitioned to scheduling do not block the ack barrier SPMD dispatch refactor: - Extract dispatch_block_to_cluster / dispatch_mix_block_to_cluster - AIV path uses count_idle_aiv_cores for accurate resource counting Test examples: spmd_sync_start, spmd_sync_start_aiv, spmd_sync_start_edge, spmd_sync_start_stress, spmd_starvation
Collaborator
Port the complete require_sync_start / drain mode implementation from a2a3 to a5 tensormap_and_ringbuffer runtime: - pto_submit_types.h: add PTO2_SUBTASK_FLAG_SYNC_START, pto2_core_mask, pto2_requires_sync_start; fix pto2_active_mask_to_shape to strip flag bits; extend PTO2LaunchSpec with require_sync_start - pto_orchestrator: add total_cluster_count/total_aiv_count for deadlock detection; encode sync_start flag in active_mask at submit time; fix total_required_subtasks popcount to use pto2_core_mask - aicpu_executor: add SyncStartDrainState, active_sched_threads, count_idle_aiv_cores, three-phase drain protocol (ack barrier, global resource check, exclusive dispatch); modify scheduler main loop with drain check and sync_start fast/slow path branching - Add 5 test examples: spmd_sync_start, spmd_sync_start_aiv, spmd_sync_start_edge, spmd_sync_start_stress, spmd_starvation
ChaoWao
approved these changes
Apr 3, 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.
Introduce a sync_start mechanism that forces all blocks of an SPMD task to be dispatched atomically before any can begin execution.
Submission layer (pto_submit_types.h, pto_orchestrator.cpp/h):
Scheduler drain protocol (aicpu_executor.cpp):
SPMD dispatch refactor:
Test examples: spmd_sync_start, spmd_sync_start_aiv, spmd_sync_start_edge, spmd_sync_start_stress, spmd_starvation