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"
30 mlir::DenseMap<std::pair<int, int>, mlir::Value> tilesByCoordinate;
31 mlir::Value getTileKey(mlir::Value tile);
34 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, mlir::Operation *>
38 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, mlir::Operation *>
42 mlir::DenseSet<std::tuple<mlir::Value, DMAChannelDir, int>> sharedChannels;
43 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, mlir::Operation *>
48 mlir::Operation *owner;
51 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, StreamClaim>
59 mlir::Operation *
owner)
69 llvm::SmallVector<ChannelClaim> claims;
70 void claim(mlir::Value tile, DMAChannelDir dir,
int channel,
71 mlir::Operation *owner);
83 bool requiresAdjacentTileAccessChannels);
90 bool requiresAdjacentTileAccessChannels,
91 mlir::Operation *owner =
nullptr);
95 bool isChannelFree(TileLike tile, DMAChannelDir dir,
int channel);
102 mlir::Operation *owner =
nullptr,
103 bool shareable =
false);
114 std::optional<int>
pinned)
129 int col,
int row,
int numChannels);
136 static std::optional<llvm::SmallVector<int>>
138 llvm::ArrayRef<BDPlanEnd> ends,
139 llvm::function_ref<
bool(DMAChannelDir,
int)> free,
140 llvm::function_ref<int64_t(
int)> spent);
142 static std::optional<llvm::SmallVector<int>>
144 llvm::ArrayRef<BDPlanEnd> ends,
145 llvm::function_ref<
bool(DMAChannelDir,
int)> free,
146 llvm::function_ref<int64_t(
int)> spent);
159 llvm::SmallVector<llvm::SmallVector<unsigned>>
sets;
170 static std::optional<unsigned>
172 llvm::ArrayRef<unsigned> poolOf,
173 llvm::ArrayRef<BDWalkPool> pools, llvm::ArrayRef<bool> whole);
185 llvm::ArrayRef<BDPlanEnd> ends,
186 llvm::ArrayRef<unsigned> poolOf,
187 llvm::ArrayRef<BDWalkPool> pools,
188 llvm::function_ref<
bool(DMAChannelDir,
int)> free,
189 llvm::function_ref<int64_t(
int)> spent,
190 unsigned maxSets = std::numeric_limits<unsigned>::max());
196 llvm::SmallVector<unsigned>
sets;
206 llvm::function_ref<
bool(llvm::ArrayRef<unsigned>)> places,
211 static llvm::SmallVector<mlir::Block *>
chainOf(DMAStartOp start);
212 static int64_t
countBDs(DMAStartOp start);
225 llvm::DenseMap<int, int64_t>
227 llvm::ArrayRef<mlir::Operation *> tiles = {})
const;
229 llvm::SmallVector<std::pair<int, int>>
positions()
const;
234 std::optional<int> channel;
236 llvm::MapVector<mlir::Operation *, llvm::DenseMap<int, int64_t>> fixed;
237 llvm::MapVector<mlir::Operation *, llvm::DenseMap<int32_t, Pin>> pinned;
243 mlir::Operation *user,
244 bool packet =
false);
llvm::DenseMap< int, int64_t > at(const AIETargetModel &target, int col, int row, llvm::ArrayRef< mlir::Operation * > tiles={}) const
By channel, the ids held at (col, row) by tiles and by every tile with those coordinates.
llvm::SmallVector< std::pair< int, int > > positions() const
Coordinates of the placed tiles that hold BD ids.
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,...
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 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(int)> spent)
A channel of the tile at (col, row) for each of ends: its pinned one, else one free leaves that no ot...
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 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(int)> spent)
The same, given the tile's bdGroups.
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(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.
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.
struct DMAChannel { DMAChannelDir direction; int channel; bool operator==(const DMAChannel &rhs) const { return std::tie(direction, channel)==std::tie(rhs.direction, rhs.channel); } } DMAChannel
Channels among 0..numChannels-1 at (col, row), grouped by whichever BD ids any two in a group share,...
llvm::SmallVector< int > channels
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