Skip to content

[WIP] InsertSync: fix multi-buffer sync event selection#176

Closed
TaoTao-real wants to merge 2 commits intozhangstevenunity:mainfrom
TaoTao-real:codex/pypto-multibuf-dyn-event
Closed

[WIP] InsertSync: fix multi-buffer sync event selection#176
TaoTao-real wants to merge 2 commits intozhangstevenunity:mainfrom
TaoTao-real:codex/pypto-multibuf-dyn-event

Conversation

@TaoTao-real
Copy link
Contributor

This fixes a correctness gap in --enable-insert-sync for multi-buffer (ping-pong) synchronization on loop back-edges.

What was wrong

For some loop-carried UB reuse patterns, InsertSync allocates two event ids (e.g. EVENT_ID0/1) and even builds an SSA selector (based on iv % 2).

However, codegen still emitted pto.set_flag/pto.wait_flag with a fixed EVENT_ID0, effectively dropping the selector. This defeats the intended ping-pong behavior and can produce incorrect synchronization.

What this PR does

  • Add pto.set_flag_dyn / pto.wait_flag_dyn ops that take the event id as an SSA value.
  • In InsertSync codegen, use the dyn ops when sync->eventIds.size() > 1 so the per-iteration selected event id is actually consumed.
  • Lower the dyn ops to EmitC set_flag/wait_flag calls with the event id operand properly placed in the argument list.

Tests

  • bash test/samples/runop.sh all
  • Added a minimal python sample test/samples/InjectSync/test_inject_sync_multibuf_loop.py.
  • Added runop guards to ensure generated C++ uses a dynamic event id for PIPE_MTE3 -> PIPE_MTE2 multi-buffer sync.

Multi-buffer (ping-pong) sync currently computes a per-iteration event id selector but still emits set_flag/wait_flag with a fixed EVENT_ID0. This breaks the intended back-edge synchronization for loop-carried UB reuse.

Add pto.set_flag_dyn/pto.wait_flag_dyn to carry a dynamic event id SSA value, use them in SyncCodegen for multi-buffer sync, and lower them to emitc call_opaque with the operand in the argument list.

Tests: extend sample runner guards and add a minimal python InjectSync sample to ensure generated C++ uses a dynamic event id for PIPE_MTE3->PIPE_MTE2.
@TaoTao-real TaoTao-real changed the title InsertSync: fix multi-buffer sync event selection [WIP] InsertSync: fix multi-buffer sync event selection Mar 3, 2026
@TaoTao-real
Copy link
Contributor Author

Closing this PR in favor of #196, which carries the current multibuffer ping/pong implementation and tests.\n\nSuperseded by: #196

@TaoTao-real TaoTao-real closed this Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant