Skip to content

Collapse same-flow circuit S2MM memcpys onto one memtile DMA channel - #1756

Merged
erwei-xilinx merged 3 commits into
Xilinx:mainfrom
erwei-xilinx:memtile-collapse-circuit-s2mm-same-flow
Jul 29, 2026
Merged

Collapse same-flow circuit S2MM memcpys onto one memtile DMA channel#1756
erwei-xilinx merged 3 commits into
Xilinx:mainfrom
erwei-xilinx:memtile-collapse-circuit-s2mm-same-flow

Conversation

@erwei-xilinx

@erwei-xilinx erwei-xilinx commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

MemTileDMAAllocator::simpleDmaChannelAlloc (AIRToAIESchedulingUtils.cpp) collapses same-logical-flow S2MM memcpy ops (same air.channel declaration + 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:

  • MM2S (source) side collapses promiscuously onto a packet-flow channel (broadcast fan-out / pkt_id multiplexing rely on it).
  • S2MM (receiver) side collapses only flows proven identical (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.

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>
Copilot AI review requested due to automatic review settings July 29, 2026 03:54
@erwei-xilinx
erwei-xilinx requested a review from fifield as a code owner July 29, 2026 03:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::simpleDmaChannelAlloc mirroring 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.

Comment thread mlir/lib/Conversion/AIRToAIESchedulingUtils.cpp Outdated
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>
@erwei-xilinx

Copy link
Copy Markdown
Collaborator Author

Addressed in the follow-up commit: renamed isSamePacketFlowEndpointisSameLogicalFlowEndpoint and foundSamePacketFlowInTilefoundSameLogicalFlowInTile (and updated the header comment) to reflect that the predicate is flow-type-agnostic (same channel decl + same constant indices). Pure rename, no behavioral change.

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>
@erwei-xilinx
erwei-xilinx added this pull request to the merge queue Jul 29, 2026
Merged via the queue into Xilinx:main with commit 66e3ca7 Jul 29, 2026
27 checks passed
@erwei-xilinx
erwei-xilinx deleted the memtile-collapse-circuit-s2mm-same-flow branch July 29, 2026 23:00
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.

2 participants