Skip to content

Commit

Permalink
Fixup pathfinder pktflow sorting by sorting on src coords and port on…
Browse files Browse the repository at this point in the history
…ly (#1777)

Co-authored-by: Jeff Fifield <jeff.fifield@amd.com>
  • Loading branch information
erwei-xilinx and fifield authored Sep 18, 2024
1 parent e90b275 commit 5821674
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 56 deletions.
3 changes: 3 additions & 0 deletions include/aie/Dialect/AIE/Transforms/AIEPathFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ class DynamicTileAnalysis {
ShimMuxOp getShimMux(mlir::OpBuilder &builder, int col);
};

// Get enum int value from WireBundle.
int getWireBundleAsInt(WireBundle bundle);

} // namespace xilinx::AIE

namespace llvm {
Expand Down
57 changes: 15 additions & 42 deletions lib/Dialect/AIE/Transforms/AIECreatePathFindFlows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,50 +445,23 @@ void AIEPathfinderPass::runOnPacketFlow(DeviceOp device, OpBuilder &builder) {
return -1;
};

// To get determinsitic behaviour; allocate amsels for control packet flows
// before others
auto getWireBundleAsInt = [](WireBundle bundle) {
switch (bundle) {
case WireBundle::Core:
return 0;
case WireBundle::DMA:
return 1;
case WireBundle::FIFO:
return 2;
case WireBundle::South:
return 3;
case WireBundle::West:
return 4;
case WireBundle::North:
return 5;
case WireBundle::East:
return 6;
case WireBundle::PLIO:
return 7;
case WireBundle::NOC:
return 8;
case WireBundle::Trace:
return 9;
case WireBundle::Ctrl:
return 10;
// Sorting the packet flows in order to get determinsitic amsel allocation;
// allocate amsels for control packet flows before others to ensure
// consistency in control packet flow overlay.
auto getUniqueIdPerFlowPerSB = [](int flowID, WireBundle srcBundle,
SmallVector<PhysPort, 4> dests) {
int totalNumOfWireBundles = AIE::getMaxEnumValForWireBundle();
int currMultiplier = totalNumOfWireBundles;
int uniqueId = flowID;
uniqueId += currMultiplier + getWireBundleAsInt(srcBundle);
currMultiplier += totalNumOfWireBundles;
for (auto dst : dests) {
uniqueId += currMultiplier;
uniqueId += getWireBundleAsInt(dst.second.bundle);
currMultiplier += totalNumOfWireBundles;
}
return -1;
return uniqueId;
};
auto getUniqueIdPerFlowPerSB =
[getWireBundleAsInt](int flowID, WireBundle srcBundle,
SmallVector<PhysPort, 4> dests) {
int totalNumOfWireBundles = AIE::getMaxEnumValForWireBundle();
int currMultiplier = totalNumOfWireBundles;
int uniqueId = flowID;
uniqueId += currMultiplier + getWireBundleAsInt(srcBundle);
currMultiplier += totalNumOfWireBundles;
for (auto dst : dests) {
uniqueId += currMultiplier;
uniqueId += getWireBundleAsInt(dst.second.bundle);
currMultiplier += totalNumOfWireBundles;
}
return uniqueId;
};
auto getSortedPacketFlows =
[&](DenseMap<std::pair<PhysPort, int>, SmallVector<PhysPort, 4>> pktFlows,
DenseMap<std::pair<PhysPort, int>, SmallVector<PhysPort, 4>>
Expand Down
26 changes: 12 additions & 14 deletions lib/Dialect/AIE/Transforms/AIEPathFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,22 +357,15 @@ void Pathfinder::sortFlows(const int maxCol, const int maxRow) {
[maxCol, maxRow](const auto &lhs, const auto &rhs) {
int lhsUniqueID = lhs.src.coords.col;
lhsUniqueID += lhs.src.coords.row * maxCol;
int currMultiplier = maxCol * maxRow;
for (auto dest : lhs.dsts) {
lhsUniqueID += currMultiplier;
lhsUniqueID += dest.coords.col;
lhsUniqueID += dest.coords.row * maxCol;
currMultiplier += maxCol * maxRow;
}
lhsUniqueID += maxRow * maxCol;
lhsUniqueID += getWireBundleAsInt(lhs.src.port.bundle);
lhsUniqueID += AIE::getMaxEnumValForWireBundle();
lhsUniqueID += lhs.src.port.channel;
int rhsUniqueID = rhs.src.coords.col;
rhsUniqueID += rhs.src.coords.row * maxCol;
currMultiplier = maxCol * maxRow;
for (auto dest : rhs.dsts) {
rhsUniqueID += currMultiplier;
rhsUniqueID += dest.coords.col;
rhsUniqueID += dest.coords.row * maxCol;
currMultiplier += maxCol * maxRow;
}
rhsUniqueID += maxRow * maxCol;
rhsUniqueID += getWireBundleAsInt(rhs.src.port.bundle);
rhsUniqueID += rhs.src.port.channel;
return lhsUniqueID < rhsUniqueID;
});
flows = priorityFlows;
Expand Down Expand Up @@ -693,3 +686,8 @@ Pathfinder::findPaths(const int maxIterations) {
LLVM_DEBUG(llvm::dbgs() << "\t---End Pathfinder::findPaths---\n");
return routingSolution;
}

// Get enum int value from WireBundle.
int AIE::getWireBundleAsInt(WireBundle bundle) {
return static_cast<typename std::underlying_type<WireBundle>::type>(bundle);
}

0 comments on commit 5821674

Please sign in to comment.