9#ifndef AIE_DIALECT_AIE_TRANSFORMS_AIEDMACHANNELANALYSIS_H
10#define AIE_DIALECT_AIE_TRANSFORMS_AIEDMACHANNELANALYSIS_H
14#include "llvm/ADT/BitVector.h"
15#include "llvm/ADT/DenseMap.h"
16#include "llvm/ADT/MapVector.h"
17#include "llvm/ADT/STLFunctionalExtras.h"
18#include "llvm/ADT/SmallVector.h"
32 mlir::DenseMap<std::pair<int, int>, mlir::Value> tilesByCoordinate;
33 mlir::Value getTileKey(mlir::Value tile);
36 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, mlir::Operation *>
40 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, mlir::Operation *>
44 mlir::DenseSet<std::tuple<mlir::Value, DMAChannelDir, int>> sharedChannels;
45 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, mlir::Operation *>
50 mlir::Operation *owner;
53 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, StreamClaim>
61 mlir::Operation *
owner)
71 llvm::SmallVector<ChannelClaim> claims;
72 void claim(mlir::Value tile, DMAChannelDir dir,
int channel,
73 mlir::Operation *owner);
85 bool requiresAdjacentTileAccessChannels);
92 bool requiresAdjacentTileAccessChannels,
93 mlir::Operation *owner =
nullptr);
97 bool isChannelFree(TileLike tile, DMAChannelDir dir,
int channel);
104 mlir::Operation *owner =
nullptr,
105 bool shareable =
false);
116 std::optional<int>
pinned)
124 using BDUser = std::pair<DMAChannelDir, int>;
132 int col,
int row,
int numChannels);
138 static std::optional<llvm::SmallVector<int>>
140 llvm::ArrayRef<BDPlanEnd> ends,
141 llvm::function_ref<
bool(DMAChannelDir,
int)> free,
142 llvm::function_ref<int64_t(DMAChannelDir,
int)> spent);
144 static std::optional<llvm::SmallVector<int>>
146 llvm::ArrayRef<BDPlanEnd> ends,
147 llvm::function_ref<
bool(DMAChannelDir,
int)> free,
148 llvm::function_ref<int64_t(DMAChannelDir,
int)> spent);
161 llvm::SmallVector<llvm::SmallVector<unsigned>>
sets;
172 static std::optional<unsigned>
174 llvm::ArrayRef<unsigned> poolOf,
175 llvm::ArrayRef<BDWalkPool> pools, llvm::ArrayRef<bool> whole);
187 llvm::ArrayRef<BDPlanEnd> ends,
188 llvm::ArrayRef<unsigned> poolOf,
189 llvm::ArrayRef<BDWalkPool> pools,
190 llvm::function_ref<
bool(DMAChannelDir,
int)> free,
191 llvm::function_ref<int64_t(DMAChannelDir,
int)> spent,
192 unsigned maxSets = std::numeric_limits<unsigned>::max());
198 llvm::SmallVector<unsigned>
sets;
208 llvm::function_ref<
bool(llvm::ArrayRef<unsigned>)> places,
213 static llvm::SmallVector<mlir::Block *>
chainOf(DMAStartOp start);
214 static int64_t
countBDs(DMAStartOp start);
227 std::map<BDUser, int64_t>
229 llvm::ArrayRef<mlir::Operation *> tiles = {})
const;
231 llvm::SmallVector<std::pair<int, int>>
positions()
const;
237 std::optional<int> channel;
238 std::optional<DMAChannelDir> dir;
240 llvm::MapVector<mlir::Operation *, std::map<BDUser, int64_t>> fixed;
241 llvm::MapVector<mlir::Operation *, llvm::SmallVector<Pin>> pinned;
247 mlir::Operation *user,
248 bool packet =
false);
llvm::SmallVector< std::pair< int, int > > positions() const
Coordinates of the placed tiles that hold BD ids.
std::map< BDUser, int64_t > at(const AIETargetModel &target, int col, int row, llvm::ArrayRef< mlir::Operation * > tiles={}) const
By channel and direction, the ids held at (col, row) by tiles and by every tile with those coordinate...
DMAChannelAnalysis(DeviceOp &device)
int getDMAChannelIndex(TileLike tile, DMAChannelDir dir, bool requiresAdjacentTileAccessChannels, mlir::Operation *owner=nullptr)
Next free channel of tile in dir, or -1 when the tile has none left.
static std::optional< unsigned > nextPoolToWalk(llvm::ArrayRef< BDPlanEnd > ends, llvm::ArrayRef< unsigned > poolOf, llvm::ArrayRef< BDWalkPool > pools, llvm::ArrayRef< bool > whole)
The walkable pool not yet whole to walk next: the deepest, then the one with the smallest objects,...
static std::optional< llvm::SmallVector< int > > planBDChannels(const AIETargetModel &target, int col, int row, llvm::ArrayRef< BDPlanEnd > ends, llvm::function_ref< bool(DMAChannelDir, int)> free, llvm::function_ref< int64_t(DMAChannelDir, int)> spent)
A channel of the tile at (col, row) for each of ends: its pinned one, else one free leaves that no ot...
mlir::Operation * getDMAChannelOwner(TileLike tile, DMAChannelDir dir, int channel)
Operation reserving or routing this channel; null if none.
bool isChannelFree(TileLike tile, DMAChannelDir dir, int channel)
Whether first-free assignment could hand out channel: nothing reserves it and no explicit flow routes...
static constexpr unsigned kMaxWalkPlacements
static int64_t countBDs(DMAStartOp start)
static llvm::SmallVector< BDGroup > bdGroups(const AIETargetModel &target, int col, int row, int numChannels)
static WalkChoice searchWalkProduct(llvm::ArrayRef< llvm::SmallVector< int64_t > > bytes, llvm::function_ref< bool(llvm::ArrayRef< unsigned >)> places, unsigned maxTries)
Tries the choices of one set per tile, bytes[tile] giving each of its sets' bytes walked whole,...
static llvm::SmallVector< mlir::Block * > chainOf(DMAStartOp start)
Blocks of the BD chain start begins, following next_bd.
static BDWalkSets walkSetsThatFit(const AIETargetModel &target, int col, int row, llvm::ArrayRef< BDPlanEnd > ends, llvm::ArrayRef< unsigned > poolOf, llvm::ArrayRef< BDWalkPool > pools, llvm::function_ref< bool(DMAChannelDir, int)> free, llvm::function_ref< int64_t(DMAChannelDir, int)> spent, unsigned maxSets=std::numeric_limits< unsigned >::max())
Every set of walkable pools whose walk lets planBDChannels fit ends (poolOf gives each end's pool),...
static int getDMAChannelLimit(TileLike tile, DMAChannelDir dir, bool requiresAdjacentTileAccessChannels)
Exclusive upper bound on channel indices eligible for this transfer.
std::pair< DMAChannelDir, int > BDUser
mlir::LogicalResult checkAIEStreamIndex(TileLike tile, DMAChannel chan, mlir::Operation *user, bool packet=false)
Claim a raw stream port for user, reporting on it when the port is taken; packet users may share it w...
int reservePinnedChannel(TileLike tile, DMAChannelDir dir, int channel, mlir::Operation *owner=nullptr, bool shareable=false)
Claim channel for (tile, dir) so first-free assignment cannot take it.
llvm::ArrayRef< ChannelClaim > getChannelClaims() const
The channels taken by index rather than through a route endpoint, in the order the claims were made.
static std::optional< llvm::SmallVector< int > > planBDChannels(llvm::ArrayRef< BDGroup > tileGroups, llvm::ArrayRef< BDPlanEnd > ends, llvm::function_ref< bool(DMAChannelDir, int)> free, llvm::function_ref< int64_t(DMAChannelDir, int)> spent)
The same, given the tile's bdGroups.
struct DMAChannel { DMAChannelDir direction; int channel; bool operator==(const DMAChannel &rhs) const { return std::tie(direction, channel)==std::tie(rhs.direction, rhs.channel); } } DMAChannel
The channels among 0..numChannels-1 at (col, row), per direction, grouped by BD pool; size is the poo...
llvm::SmallVector< BDUser > users
std::optional< int > pinned
BDPlanEnd(DMAChannelDir dir, int64_t bds, int limit, std::optional< int > pinned)
A pool whose ends a BD plan weighs: how many objects it holds, the bytes of one, and whether it can b...
walkSetsThatFit's result; channelShort when the ends do not fit the tile's channels even taking no BD...
llvm::SmallVector< int64_t > bytes
The bytes each set walks whole.
llvm::SmallVector< llvm::SmallVector< unsigned > > sets
ChannelClaim(mlir::Value tile, DMAChannelDir dir, int channel, mlir::Operation *owner)
One walkSetsThatFit set per mem tile of a spill component (memTileSpillComponents),...
llvm::SmallVector< unsigned > sets