[fix][ttl] ttl-insert-cb-sync: Allow tensor SSA uses past the next-acquire boundary (#536)#554
Merged
Merged
Conversation
… acquires + N matching releases into the canonical tt-metal cumulative-wait shape (`cb_wait_front(N*k)` + per-block `tensor.extract_slice` views + `cb_pop_front(N*k)`). `addSliceOffset` already folds the slice offsets into the per-tile `src_idx` / `dst_idx`, so no lowering changes. Symmetric on the producer side. Fixes #556.
extend correctness argument and idempotency notes in DFBManagement.md; add adversarial pytests (matmul-style two-DFB interleave, t1-fanout, interposed third acquire) and matching lit coverage; rename CB->DFB in new content.
ttl-auto-sync pipeline; update C++, Python, and me2e callers to use it. Remove helper used just once.
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.
Problem:
ttl-insert-cb-syncinsertscb_pop/cb_pushafter the last use of each acquired slot, but only searched up to the next same-class acquire on the same DFB. Tensor SSA uses can legitimately appear after a later acquire (a tile fromcb_wait t1may be consumed aftercb_wait t2). Those uses were missed, the pop was inserted right after the acquire, and the read pointer advanced before the data was read. The case_a / case_b reproducers from the issue 536 follow-up comment miscompiled silently.Independently, deferred-consume patterns (
t1 = cb.wait(); t2 = cb.wait(); use(t1); use(t2)) lowered to N independentcb_wait_front(k)/cb_pop_front(k)calls. Because metal's wait/pop primitives are non-cumulative, the first pop advances the front before the producer has pushed enough tiles to satisfy the next read.Fixes (~530 LOC):
findLastOwnedUse: direct CB uses keep the boundary, tensor SSA uses ignore it. ExtendfindOwnedReleases' upper bound to the last owned use.ttl-coalesce-dfb-acquiresrewrites a maximal run of same-DFB acquires + their matched releases into the canonical tt-metal cumulative-wait shape (cb_wait_front(N*k)+ per-blocktensor.extract_sliceviews +cb_pop_front(N*k)).addSliceOffsetalready folds the slice offsets into the per-tilesrc_idx/dst_idx, so no lowering changes. Same template handles producer-sidecb_reserve/cb_push. The detection rule is locally-checkable: an op between members terminates the group iff it touches our DFB or consumes a group member's result, or carries a region (the conservative envelope of "could trigger a release on the DFB"). This means matmul-style patterns where acquires on two DFBs are interleaved (a1, b1, a2, b2) coalesce per-DFB independently, since an acquire on a different DFB is benign. Seedocs/development/DFBManagement.mdfor the full correctness argument. Fixes [ttl] Coalesce consecutive cb_wait acquires into multi-tile cb_wait_front(N) with per-acquire src_idx #556.Tests:
Future work:
ttl.copyoperands. Would collapsefindLastOwnedUseto a single SSA walk and lift the DM-thread xfails. Requires (mechanical) updates to a large number of lit tests.Fixes #536 follow-up. Fixes #556.