Skip to content

[AIEPathfinder] Fix packet_dest-before-packet_source ordering crash (#2583)#2919

Merged
hunhoffe merged 10 commits intomainfrom
fix/issue-2583-packet-flow-ordering
Mar 4, 2026
Merged

[AIEPathfinder] Fix packet_dest-before-packet_source ordering crash (#2583)#2919
hunhoffe merged 10 commits intomainfrom
fix/issue-2583-packet-flow-ordering

Conversation

@hunhoffe
Copy link
Collaborator

@hunhoffe hunhoffe commented Mar 3, 2026

[AIEPathfinder] Fix packet_dest-before-packet_source ordering crash (#2583)

AIEPathfinderPass assumed aie.packet_source always precedes aie.packet_dest in aie.packet_flow regions. MLIR provides no such guarantee, leaving srcCoords/srcPort uninitialized when the order is reversed and crashing via Assertion 'i < sb.srcPorts.size()' failed in
Pathfinder::findPaths.

Fix the assumption in both AIEPathFinder.cpp and AIECreatePathFindFlows.cpp by splitting the single-pass if/else if loop into two passes: pass 1 extracts the source unconditionally, pass 2 processes each destination with the already-known source.

Also closes a verifier gap: PacketFlowOp::verify() previously only checked that contained ops were of legal types, but did not enforce that exactly one aie.packet_source and at least one aie.packet_dest were present. Zero-source flows would hit UB in both passes;
multiple-source flows would silently use the last one. The verifier now rejects both cases with a diagnostic. A null-check after pass 1 in each transform serves as a defensive backstop.

Tests added:

  • packet_flow_dest_before_source.mlir — functional regression for dest-before-source ordering (single dest, multiple dests, keep_pkt_header)
  • badpacket_flow_source_count.mlir — verifier error cases for zero sources, multiple sources, and zero dests

hunhoffe and others added 5 commits March 3, 2026 15:16
)

Split the single if/else-if loop in runOnPacketFlow (AIECreatePathFindFlows.cpp
and AIEPathFinder.cpp) into two passes: pass 1 collects the packet_source, pass
2 processes each packet_dest. This removes the implicit assumption that
packet_source precedes packet_dest in the block, which MLIR does not guarantee.

Tighten PacketFlowOp::verify() to enforce exactly one packet_source and at
least one packet_dest, closing the verifier gap that previously allowed
zero-source and multi-source flows through. Add a null-check after pass 1 in
both transform passes as a defensive backstop against any future verifier bypass.

Adds two lit regression tests:
- packet_flow_dest_before_source.mlir: verifies correct output for
  dest-before-source ordering (single dest, multiple dests, keep_pkt_header).
- badpacket_flow_source_count.mlir: verifies verifier errors for zero-source,
  multiple-source, and zero-dest packet flows.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a crash in AIEPathfinderPass (issue #2583) where aie.packet_source appearing after aie.packet_dest inside an aie.packet_flow region caused uninitialized srcCoords/srcPort to be used, producing an assertion failure in Pathfinder::findPaths.

Changes:

  • Two-pass refactor in AIEPathFinder.cpp and AIECreatePathFindFlows.cpp: pass 1 scans the region to extract the source (order-independent); pass 2 processes destinations using the already-known source, with a null-check backstop between passes.
  • Enhanced PacketFlowOp::verify() in AIEDialect.cpp to enforce exactly one aie.packet_source and at least one aie.packet_dest in each packet flow region.
  • Two new regression test files covering the dest-before-source ordering fix and the verifier's rejection of zero/multiple sources and zero dests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/Dialect/AIE/Transforms/AIEPathFinder.cpp Two-pass loop fix to extract source before processing destinations
lib/Dialect/AIE/Transforms/AIECreatePathFindFlows.cpp Same two-pass loop fix in the packet-flow transform pass
lib/Dialect/AIE/IR/AIEDialect.cpp New verifier checks: exactly one packet_source, at least one packet_dest
test/create-packet-flows/packet_flow_dest_before_source.mlir Regression test for dest-before-source ordering
test/create-packet-flows/badpacket_flow_source_count.mlir Verifier error tests for zero/multiple sources and zero dests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Coverage Report

Created: 2026-03-04 18:16

Click here for information about interpreting this report.

FilenameFunction CoverageLine CoverageRegion CoverageBranch Coverage
IR/AIEDialect.cpp 93.08% 86.97% 88.14% 80.06%
Transforms/AIECreatePathFindFlows.cpp 100.00% 91.60% 86.68% 76.34%
Transforms/AIEPathFinder.cpp 87.50% 94.15% 89.22% 83.33%
Totals 93.25% 89.30% 87.96% 79.70%
Generated by llvm-cov -- llvm version 18.1.3

hunhoffe and others added 3 commits March 4, 2026 09:40
Remove the extra `for (Operation &Op : b.getOperations())` line that was
accidentally duplicated when writing the two-pass packet_source/dest fix,
causing -Werror=unused-variable and cascading parse failures across all CI.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Update from '2024 Xilinx Inc.' to '2026 Advanced Micro Devices, Inc.'

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@hunhoffe hunhoffe marked this pull request as ready for review March 4, 2026 18:02
@hunhoffe hunhoffe added this pull request to the merge queue Mar 4, 2026
Merged via the queue into main with commit 1517f98 Mar 4, 2026
63 of 64 checks passed
@hunhoffe hunhoffe deleted the fix/issue-2583-packet-flow-ordering branch March 4, 2026 22:36
hunhoffe added a commit that referenced this pull request Mar 12, 2026
PacketFlowOp::verify() was rejecting flows with more than one
aie.packet_source, breaking valid fan-in topologies that predate the
verifier check added in PR #2919. Relax the check from `numSources != 1`
to `numSources < 1` so zero-source flows are still rejected while
multi-source flows are accepted.

The pathfinder (AIEPathFinder.cpp / AIECreatePathFindFlows.cpp) had a
related "last source wins" bug: Pass 1 overwrote the single srcCoords/
srcPort accumulator on each PacketSourceOp, silently dropping all but the
last source before calling addFlow(). This is left for a follow-up fix;
the per-source loop change belongs in a separate commit.

Tests added / updated:
- badpacket_flow_source_count.mlir: remove multi-source rejection case
  (no longer an error), update error message for zero-source case
- multi_source_packet_flow.mlir: positive verifier regression test
- multi_source_pathfinder.mlir: pathfinder-level regression test
  (currently failing — documents the remaining bug)
- npu-xrt/multi_source_packet_flow/: end-to-end hardware test

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
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.

3 participants