MLIR-AIE
AIEPlacer.h
Go to the documentation of this file.
1//===- AIEPlacer.h ----------------------------------------------*- C++ -*-===//
2//
3// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7// (c) Copyright 2026 Advanced Micro Devices, Inc.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef AIE_PLACER_H
12#define AIE_PLACER_H
13
16
17namespace xilinx::AIE {
18
19/// Placement algorithm type for pass option
21
22// maps logical tile operations to physical coordinates
23using PlacementResult = llvm::DenseMap<mlir::Operation *, TileID>;
24
25// Track available tiles and resource usage
27 std::vector<TileID> compTiles;
28 std::vector<TileID> nonCompTiles; // Memory and shim tiles
29
30 llvm::DenseMap<TileID, int> inputChannelsUsed;
31 llvm::DenseMap<TileID, int> outputChannelsUsed;
32
33 void removeTile(TileID tile, AIETileType type);
34};
35
36// Abstract placer interface
37class Placer {
38public:
39 Placer() = default;
40 virtual ~Placer() = default;
41
42 virtual void initialize(const AIETargetModel &targetModel) = 0;
43
44 virtual mlir::LogicalResult place(DeviceOp device) = 0;
45
46 virtual llvm::StringRef getName() const = 0;
47
48 std::optional<TileID> getPlacement(mlir::Operation *logicalTile) const {
49 auto it = result.find(logicalTile);
50 if (it != result.end())
51 return it->second;
52 return std::nullopt;
53 }
54
55protected:
57};
58
59// Sequential placement algorithm
60//
61// Places logical tiles to physical tiles using a simple strategy:
62// - Compute tiles: Sequential column-major placement (fill column before next)
63// - Memory/shim tiles: DMA Channel capacity placement near common column
64//
65// Core-to-core connections are NOT validated because SequentialPlacer
66// doesn't account for shared memory optimization.
67//
68// Shim/Mem tiles with identical placement constraints and sufficient
69// DMA capacity are merged to the same physical tile.
70class SequentialPlacer : public Placer {
71public:
72 SequentialPlacer(std::optional<int> coresPerCol = std::nullopt)
73 : coresPerCol(coresPerCol) {}
74
75 void initialize(const AIETargetModel &targetModel) override;
76
77 mlir::LogicalResult place(DeviceOp device) override;
78
79 llvm::StringRef getName() const override { return "sequential_placer"; }
80
81private:
82 std::optional<int> coresPerCol;
83 int deviceCoresPerCol = 0; // Actual cores per column in device
84 TileAvailability availability;
85 const AIETargetModel *targetModel = nullptr;
86
87 void limitCoresPerColumn(int maxCoresPerCol, int numColumns);
88
89 void buildObjectFifoGroups(
90 llvm::SmallVector<ObjectFifoCreateOp> &objectFifos,
91 llvm::SmallVector<ObjectFifoLinkOp> &objectFifoLinks,
92 llvm::DenseMap<int, llvm::SmallVector<ObjectFifoCreateOp>> &groupToFifos,
93 llvm::DenseMap<int, llvm::SmallVector<LogicalTileOp>>
94 &groupToLogicalTiles);
95
96 std::optional<TileID> findTileWithCapacity(int targetCol,
97 std::vector<TileID> &tiles,
98 int requiredInputChannels,
99 int requiredOutputChannels,
100 AIETileType requestedType);
101
102 void updateChannelUsage(TileID tile, bool isOutput, int numChannels);
103
104 bool hasAvailableChannels(TileID tile, int inputChannels, int outputChannels);
105
106 mlir::LogicalResult validateAndUpdateChannelUsage(
107 LogicalTileOp logicalTile, TileID tile,
108 const llvm::DenseMap<mlir::Operation *, std::pair<int, int>>
109 &channelRequirements,
110 bool isConstrained);
111
112 llvm::DenseMap<mlir::Operation *, std::pair<int, int>>
113 buildChannelRequirements(
114 llvm::SmallVector<ObjectFifoCreateOp> &objectFifos,
115 llvm::SmallVector<ObjectFifoLinkOp> &objectFifoLinks);
116};
117
118} // namespace xilinx::AIE
119
120#endif // AIE_PLACER_H
virtual mlir::LogicalResult place(DeviceOp device)=0
virtual ~Placer()=default
virtual llvm::StringRef getName() const =0
PlacementResult result
Definition AIEPlacer.h:56
std::optional< TileID > getPlacement(mlir::Operation *logicalTile) const
Definition AIEPlacer.h:48
virtual void initialize(const AIETargetModel &targetModel)=0
llvm::StringRef getName() const override
Definition AIEPlacer.h:79
void initialize(const AIETargetModel &targetModel) override
Definition AIEPlacer.cpp:22
SequentialPlacer(std::optional< int > coresPerCol=std::nullopt)
Definition AIEPlacer.h:72
mlir::LogicalResult place(DeviceOp device) override
Include the generated interface declarations.
TileID { friend std::ostream &operator<<(std::ostream &os, const TileID &s) { os<< "TileID("<< s.col<< ", "<< s.row<< ")" TileID
llvm::DenseMap< mlir::Operation *, TileID > PlacementResult
Definition AIEPlacer.h:23
PlacerType
Placement algorithm type for pass option.
Definition AIEPlacer.h:20
std::vector< TileID > compTiles
Definition AIEPlacer.h:27
llvm::DenseMap< TileID, int > outputChannelsUsed
Definition AIEPlacer.h:31
void removeTile(TileID tile, AIETileType type)
std::vector< TileID > nonCompTiles
Definition AIEPlacer.h:28
llvm::DenseMap< TileID, int > inputChannelsUsed
Definition AIEPlacer.h:30