[WIP] Fix insert-sync control-flow: avoid deadlocks and #128 crash#132
Merged
zhangstevenunity merged 4 commits intoFeb 27, 2026
Conversation
adc055b to
54ac891
Compare
54ac891 to
c998729
Compare
Contributor
Author
|
Manual remote NPU validation (Ascend910, CANN 8.5.0, DEVICE_ID=2, PTO_ISA_COMMIT=082b94a3): movfp OK, tmatmulk OK, tmatmulk_autosync OK, add_double_dynamic OK. |
added 4 commits
February 27, 2026 16:33
Port loop/branch sync analysis to AscendNPU-IR style to guarantee begin<end for event-id allocation. Add a reproducer sample and fix outdated Python sample op names so runop.sh all passes.
12d0bfc to
42ee599
Compare
Contributor
Contributor
|
OK I see #149 now |
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.
Fixes #128
Problem
ptoas --enable-insert-synccould crash inSyncEventIdAllocationwith:Root cause (#128)
The sync insertion phase could build an invalid
syncOperations_[syncIndex]group wheresyncPair[0]is not a SET op (e.g. it becomes apipe_barrier). Then event-id allocation treats that op assetFlag, computes a non-forward lifetime interval (begin >= end), and aborts.This was triggered by double-buffer + dynamic-shape IR with control flow, where the old
BlockSyncAnalysisbranch-merge logic injected “phantom” SETs and could reuse asyncIndexbelonging to a barrier-only group.Fix (#128, AscendNPU-IR style)
Make the analysis/insertion phase maintain the allocator invariant (
begin < end) instead of adding allocator-side fallbacks:SyncRecordList(per multi-buffer slot) with{ alreadySync: bool[], syncFinder: map }.InsertBackForSyncso lifetime intervals remain forward.assert(begin < end)inSyncEventIdAllocation(with a debug print when violated).Additional fix: avoid auto-sync deadlock for
tmatmulk(#112 regression)During remote NPU validation, the auto-sync variant (manual sync removed) could hang because we hoisted
WAIT_EVENTout ofif/elseregions but did not sink the matchedSET_EVENTout of the regions. This leaves conditionalset_flagstatements inside branches while correspondingwait_flagare unconditional; sincewait_flagconsumes the flag on Ascend, later iterations can wait on an event-id that is never re-set on that path.Fix: restore AscendNPU-IR behavior in
MoveSyncStateto sinkSET_EVENTout ofif/elsewhen the matchedWAIT_EVENTis outside the branch region. This materializes a safe “merge” signal atIF_END, and prevents deadlock/hangs fortmatmulk_autosync.Additional fix:
movfpNPU validation (TMOV_FP tile layout)Remote NPU validation was failing for
movfpwith a pto-isastatic_assert(and could manifest asaicore exception) because the generated C++ emitted the wrong tile layouts forTMOV_FP.Root cause:
PTOToEmitC's lowering forpto.pointer_casttreatedTileBufConfigAttr's enum attrs (BLayoutAttr/SLayoutAttr/PadValueAttr) as rawIntegerAttr, so it always defaulted toBLayout::RowMajor+SLayout::NoneBoxeven when the MLIR!pto.tile_buftype requestedBLayout::ColMajor+SLayout::RowMajor.Fix: decode those enum attrs properly and emit the requested layout/fractal/pad into the generated
Tile<...>template parameters.Tests
test/samples/InsertSync/add_double_dynamic.py.test/samples/runop.shfortmatmulk_autosyncto catch known deadlock signatures.PYTHONPATH=<mlir_core>:<PTOAS/build/python> PTOAS_BIN=... bash test/samples/runop.sh alltmatmulk,tmatmulk_autosync,add_double_dynamic,movfpMisc
pto.tgatherb,pto.mgather,pto.tmins,pto.txor/txors) sorunop.sh allstays green.