Collapse same-flow circuit S2MM memcpys onto one memtile DMA channel - #1756
Merged
erwei-xilinx merged 3 commits intoJul 29, 2026
Merged
Conversation
MemTileDMAAllocator::simpleDmaChannelAlloc collapses same-logical-flow S2MM ops (same channel declaration + constant bundle indices) onto one physical channel only for packet flows. For circuit flows, distinct ops of one flow round-robin onto separate physical channels, wasting the memtile's limited DMA channels -- a memtile that also carries a wide broadcast can then run out of S2MM channels even though the ops share a single logical flow. Extend the same-flow S2MM collapse to circuit flows: reuse an existing physical channel when the op matches an existing alloc's logical flow (and neither is a dedicated channel). Distinct sources keep distinct channels since matching bundle indices are required. getRepeatCounts / BD generation already emit the collapsed ops as sequential BD tasks on the shared channel. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Extends MemTile DMA channel allocation so circuit (non-packet) S2MM memcpys that belong to the same logical flow (same air.channel declaration and same constant bundle indices) reuse a single physical S2MM DMA channel, reducing memtile DMA channel pressure in multi-round/refill scenarios.
Changes:
- Add a circuit-flow S2MM reuse path in
MemTileDMAAllocator::simpleDmaChannelAllocmirroring the existing packet-flow S2MM “same logical flow” collapse rule. - Preserve the existing “never collapse dedicated DMA channels” behavior by checking both the incoming memcpy and any existing memcpys already assigned to the channel.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Now that the same-logical-flow S2MM collapse serves both packet and circuit flows, the "Packet" naming is misleading. Rename to reflect that the predicate tests a logical-flow endpoint (same channel decl + same constant bundle indices), independent of flow type: isSamePacketFlowEndpoint -> isSameLogicalFlowEndpoint foundSamePacketFlowInTile -> foundSameLogicalFlowInTile Pure rename; no behavioral change. Addresses PR review feedback. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Addressed in the follow-up commit: renamed |
The prior commit added a parallel circuit-flow S2MM collapse block that
duplicated the packet block's dedicated-channel scan and collapse/return tail.
Since both directions of S2MM now use the identical same-logical-flow rule,
fold the packet and circuit branches into one:
- MM2S: collapse promiscuously onto a packet-flow channel (unchanged).
- S2MM: collapse when foundSameLogicalFlowInTile, for BOTH packet and
circuit flows.
Behavior is preserved (same-logical-flow implies same channel decl, so a
packet op can only match a packet alloc), while the memtile allocator drops
~26 lines.
Extract the repeated "does this allocation host a dedicated channel" scan --
which appeared three times -- into allocation_info_t::containsDedicatedChannel(),
reused by the unified memtile block and the shim packet-reuse walk.
Add the circuit-flow lit tests that mirror the existing packet pair:
memtile_circuit_same_flow_collapse.mlir (same flow -> one S2MM channel) and
memtile_circuit_two_sources_one_dst.mlir (distinct sources -> distinct
channels, guarding against over-collapse).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
MemTileDMAAllocator::simpleDmaChannelAlloc(AIRToAIESchedulingUtils.cpp) collapses same-logical-flow S2MM memcpy ops (sameair.channeldeclaration + same constant bundle indices) onto one physical DMA channel — but originally only for packet flows. For circuit flows, distinct ops of a single logical flow were round-robined onto separate physical channels.This wastes the memtile's limited DMA channels: when several ops belong to one flow (e.g. an L2 buffer re-filled at one endpoint across loop iterations / rounds), each lands on its own S2MM channel. A memtile that also carries a wide broadcast can then exhaust its S2MM channels even though those ops share a single flow.
What this does
Extends the same-flow S2MM collapse to circuit flows. Since both directions of S2MM now use the identical same-logical-flow rule, the packet and circuit paths are folded into one branch:
foundSameLogicalFlowInTile), for both packet and circuit flows. Distinct sources keep distinct channels since matching bundle indices are required.This is behavior-preserving for packet flows: same-logical-flow implies same channel declaration, so a packet op can only ever match a packet allocation. The unification makes the memtile allocator smaller rather than larger.
The repeated "does this allocation host a dedicated channel" scan (previously written out three times) is extracted into
allocation_info_t::containsDedicatedChannel(), reused by the unified memtile block and the shim packet-reuse walk.getRepeatCounts/ BD generation already emit the collapsed ops as sequential BD tasks on the shared channel, so no downstream change is needed.Tradeoff
Collapsing same-flow S2MM trades channel count for serialization: same-logical-flow ops writing disjoint buffer regions that could previously overlap on two channels now share one channel as sequential BDs. This is the right call for the motivating case (the design does not fit otherwise) and mirrors the existing packet-flow behavior, but is applied unconditionally.
Tests
New circuit-flow lit tests mirroring the existing packet pair:
memtile_circuit_same_flow_collapse.mlir— same flow → one S2MM channel (two BDs).memtile_circuit_two_sources_one_dst.mlir— distinct sources → distinct channels (guards against over-collapse).ninja check-air-mlir— full Conversion + Transform suites pass (0 failures)Verified on a multi-round temporal flash-attention deployment where the K/V-broadcast memtile previously overflowed its S2MM channels; with this change it fits and routes.