MLIR-AIE 1.4.6.dev
AIEBufferAllocation.h
Go to the documentation of this file.
1//===- AIEBufferAllocation.h ------------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2026 Advanced Micro Devices, Inc.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7
8#ifndef AIE_DIALECT_AIE_TRANSFORMS_AIEBUFFERALLOCATION_H
9#define AIE_DIALECT_AIE_TRANSFORMS_AIEBUFFERALLOCATION_H
10
13
14#include "llvm/ADT/ArrayRef.h"
15#include "llvm/ADT/DenseMap.h"
16#include "llvm/ADT/IntEqClasses.h"
17#include "llvm/ADT/MapVector.h"
18#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/SmallVector.h"
20#include "llvm/Support/MathExtras.h"
21
22#include <optional>
23#include <string>
24#include <utility>
25
26namespace xilinx::AIE {
27
28/// A memtile is reached by DMA rather than by core vector load and store, so
29/// its bus width also covers the vector-alignment requirement.
36 AIETileType tileType) {
37 if (tileType == AIETileType::MemTile) {
38 return {targetModel.getMemTileSize(),
39 targetModel.getMemTileLoadStoreBusWidth(),
40 targetModel.getMemTileLoadStoreBusWidth()};
41 }
42 return {targetModel.getLocalMemorySize(),
45}
46
47/// Return the alignment (in bits) a buffer of `sizeBytes` must satisfy.
48///
49/// Bus width alone is insufficient: from AIE2P on, a full-width vector access
50/// needs 512-bit alignment while the bus is 256 bits wide. An externally
51/// compiled kernel may perform such an access, so a buffer large enough to hold
52/// a full-width vector gets the stricter alignment. A smaller buffer keeps the
53/// bus width and costs no padding.
54inline uint32_t requiredBufferAlignBits(uint32_t busAlignBits,
55 uint32_t maxVecAlignBits,
56 int64_t sizeBytes) {
57 if (maxVecAlignBits <= busAlignBits)
58 return busAlignBits;
59 return sizeBytes * 8 >= static_cast<int64_t>(maxVecAlignBits)
60 ? maxVecAlignBits
61 : busAlignBits;
62}
63
65 int64_t size;
66 int64_t alignment;
67 std::optional<int64_t> address;
68};
69
70/// Buffers are laid out, and given a tile, largest buffer first: by the address
71/// layout below, the objectFIFO allocator, and the SA placer's estimate of it.
72/// Equal sizes keep their order.
73template <typename Range, typename BytesFn>
74void sortLargestBufferFirst(Range &&buffers, BytesFn bytes) {
75 llvm::stable_sort(buffers, [&](const auto &a, const auto &b) {
76 return bytes(a) > bytes(b);
77 });
78}
79
80/// The basic address allocator and resource planner share this layout: retain
81/// address pins, then place unpinned buffers largest-first, aligning each start
82/// and skipping occupied ranges. Return the high-water mark, without padding
83/// after the final buffer. Entries retain their input order.
84inline int64_t
85assignSequentialBufferAddresses(llvm::MutableArrayRef<BufferAllocation> buffers,
86 int64_t start = 0) {
87 llvm::SmallVector<std::pair<int64_t, int64_t>> pinned;
88 llvm::SmallVector<BufferAllocation *> pending;
89 int64_t highWater = start;
90 for (auto &buffer : buffers) {
91 if (buffer.address) {
92 pinned.emplace_back(*buffer.address, buffer.size);
93 highWater = std::max(highWater, *buffer.address + buffer.size);
94 } else {
95 pending.push_back(&buffer);
96 }
97 }
98 llvm::stable_sort(pinned, [](auto a, auto b) { return a.first < b.first; });
99 sortLargestBufferFirst(pending, [](auto *buffer) { return buffer->size; });
100 auto *current = pinned.begin();
101 int64_t address = start;
102 for (auto *buffer : pending) {
103 address = llvm::alignTo(address, buffer->alignment);
104 while (current != pinned.end() && address + buffer->size > current->first) {
105 address =
106 llvm::alignTo(current->first + current->second, buffer->alignment);
107 ++current;
108 }
109 buffer->address = address;
110 address += buffer->size;
111 }
112 return std::max(highWater, address);
113}
114
115/// A mem tile pool as aie-objectfifo-allocate packs it: `count` buffers of
116/// `bytes` homed on `home`, and the DMA ends it has there in its busier
117/// direction.
118struct SpillPool {
119 SpillPool(int64_t bytes, int64_t count, unsigned home, int demand)
121 int64_t bytes;
122 int64_t count;
123 unsigned home;
125};
126
127/// aie-objectfifo-allocate's demand-first packing order of `pools`, given in
128/// its size-first order, as indices into them: each home's pools by demand,
129/// then buffer size, merged by buffer size, then demand, then home in order of
130/// first appearance, so that small pools are not put first over large buffers
131/// on unrelated tiles.
132inline llvm::SmallVector<unsigned>
133demandFirstOrder(llvm::ArrayRef<SpillPool> pools) {
134 llvm::SmallVector<unsigned> homes;
135 llvm::SmallVector<llvm::SmallVector<unsigned>> perHome;
136 for (auto [index, pool] : llvm::enumerate(pools)) {
137 auto *at = llvm::find(homes, pool.home);
138 if (at == homes.end()) {
139 homes.push_back(pool.home);
140 perHome.emplace_back();
141 at = std::prev(homes.end());
142 }
143 perHome[at - homes.begin()].push_back(index);
144 }
145 for (auto &list : perHome)
146 llvm::stable_sort(list, [&](unsigned a, unsigned b) {
147 if (pools[a].demand != pools[b].demand)
148 return pools[a].demand > pools[b].demand;
149 return pools[a].bytes > pools[b].bytes;
150 });
151 llvm::SmallVector<unsigned> order;
152 llvm::SmallVector<size_t> next(perHome.size(), 0);
153 for (size_t slot = 0; slot < pools.size(); ++slot) {
154 std::optional<size_t> best;
155 for (size_t home = 0; home < perHome.size(); ++home) {
156 if (next[home] >= perHome[home].size())
157 continue;
158 const SpillPool &pool = pools[perHome[home][next[home]]];
159 const SpillPool *top =
160 best ? &pools[perHome[*best][next[*best]]] : nullptr;
161 if (!top || pool.bytes > top->bytes ||
162 (pool.bytes == top->bytes && pool.demand > top->demand))
163 best = home;
164 }
165 order.push_back(perHome[*best][next[*best]++]);
166 }
167 return order;
168}
169
170/// The tiles a mem tile buffer homed at `home` may spill to: those in its row
171/// home shares memory with, in column order.
172inline llvm::SmallVector<TileID, 2>
174 llvm::SmallVector<TileID, 2> neighbours;
175 for (int col = 0; col < target.columns(); ++col) {
176 if (col == home.col)
177 continue;
178 TileID neighbour{col, home.row};
179 if (!target.isValidTile(neighbour))
180 continue;
181 auto shared = target.getSharedMemory(home, neighbour);
184 neighbours.push_back(neighbour);
185 }
186 return neighbours;
187}
188
189/// For each of `homes`, the index of its component: homes whose buffers may
190/// spill to a tile in common, directly or through other homes, share one.
191/// What one component's buffers do never touches another's tiles.
192inline llvm::SmallVector<unsigned> memTileSpillComponents(
193 llvm::ArrayRef<TileID> homes,
194 llvm::function_ref<llvm::SmallVector<TileID, 2>(TileID)> neighboursOf) {
195 llvm::DenseMap<TileID, unsigned> index;
196 llvm::IntEqClasses eq;
197 auto indexOf = [&](TileID tile) {
198 auto [it, fresh] = index.try_emplace(tile, index.size());
199 if (fresh)
200 eq.grow(index.size());
201 return it->second;
202 };
203 for (TileID home : homes) {
204 unsigned at = indexOf(home);
205 for (TileID neighbour : neighboursOf(home))
206 eq.join(indexOf(neighbour), at);
207 }
208 eq.compress();
209 llvm::SmallVector<unsigned> component;
210 for (TileID home : homes)
211 component.push_back(eq[indexOf(home)]);
212 return component;
213}
214inline llvm::SmallVector<unsigned>
216 llvm::ArrayRef<TileID> homes) {
218 homes, [&](TileID home) { return memTileSpillNeighbours(target, home); });
219}
220
221/// The mem tiles a mem tile pool's buffers go to: aie-objectfifo-allocate
222/// places them by this search, and the SA placer runs it on each placement it
223/// weighs. A tile's use is its layout by assignSequentialBufferAddresses. Each
224/// buffer in turn goes home when it fits there, else to a neighbour home shares
225/// memory with, least used first; when one fits nowhere, earlier choices are
226/// revisited, latest first, until kRetries alternatives have been tried.
228public:
229 struct Tile {
230 Tile(int64_t capacity, llvm::SmallVector<BufferAllocation> fixed)
231 : capacity(capacity), fixed(std::move(fixed)) {}
232 int64_t capacity;
233 llvm::SmallVector<BufferAllocation> fixed;
234 };
235 /// A buffer of `bytes` homed on `home`, which it may take unless `atHome`
236 /// is false, and the `neighbours` it may spill to, in the order tried when
237 /// they are equally used.
238 struct Buffer {
239 Buffer(int64_t bytes, unsigned home, bool atHome,
240 llvm::SmallVector<unsigned, 2> neighbours)
242 neighbours(std::move(neighbours)) {}
243 int64_t bytes;
244 unsigned home;
245 bool atHome;
246 llvm::SmallVector<unsigned, 2> neighbours;
247 };
248
249 MemTileSpillSearch(llvm::SmallVector<Tile> tiles, int64_t alignment)
250 : tiles(std::move(tiles)), planned(this->tiles.size()),
251 alignment(alignment) {
252 weighed.assign(this->tiles.size(), false);
253 plannedBytes.assign(this->tiles.size(), 0);
254 misaligned.assign(this->tiles.size(), 0);
255 for (const Tile &tile : this->tiles) {
256 bool packed = llvm::all_of(tile.fixed, [&](const BufferAllocation &b) {
257 return !b.address && b.size % alignment == 0;
258 });
259 int64_t bytes = 0;
260 for (const BufferAllocation &buffer : tile.fixed)
261 bytes += buffer.size;
262 fixedBytes.push_back(packed ? std::optional<int64_t>(bytes)
263 : std::nullopt);
264 }
265 }
266
267 /// The bytes `tile` spans with what it holds and `count` more of `bytes`.
268 int64_t used(unsigned tile, int64_t bytes = 0, int count = 0) const {
269 // Unpinned buffers whose sizes all keep the alignment leave no gaps, so
270 // the layout spans their sum.
271 if (fixedBytes[tile] && !misaligned[tile] && bytes % alignment == 0)
272 return *fixedBytes[tile] + plannedBytes[tile] + count * bytes;
273 llvm::SmallVector<BufferAllocation> layout;
274 for (int64_t size : planned[tile])
275 layout.push_back({size, alignment, std::nullopt});
276 for (int i = 0; i < count; ++i)
277 layout.push_back({bytes, alignment, std::nullopt});
278 llvm::append_range(layout, tiles[tile].fixed);
279 return assignSequentialBufferAddresses(layout);
280 }
281 bool fits(unsigned tile, int64_t bytes, int count = 1) const {
282 return used(tile, bytes, count) <= tiles[tile].capacity;
283 }
284 void reserve(unsigned tile, int64_t bytes, int count = 1) {
285 for (int i = 0; i < count; ++i)
286 add(tile, bytes);
287 }
288
289 /// Alternatives the search tries before it gives up.
290 static constexpr int kRetries = 256;
291
292 /// Places `buffers` in order on top of what the tiles hold. On success each
293 /// buffer's tile is in `chosen`; otherwise `failed` is the buffer that fit
294 /// nowhere with the most buffers left after it, and `unplacedBytes` the
295 /// bytes of it and those.
296 /// Buffers whose tiles reach no tile in common place independently, so
297 /// each such component is searched on its own, with its own kRetries.
298 bool place(llvm::ArrayRef<Buffer> buffers) {
299 llvm::IntEqClasses eq(tiles.size());
300 for (const Buffer &buffer : buffers)
301 for (unsigned neighbour : buffer.neighbours)
302 eq.join(neighbour, buffer.home);
303 eq.compress();
304 llvm::MapVector<unsigned, llvm::SmallVector<unsigned>> components;
305 for (auto [index, buffer] : llvm::enumerate(buffers))
306 components[eq[buffer.home]].push_back(index);
307
308 llvm::SmallVector<unsigned> placedOn(buffers.size(), 0);
309 size_t firstFailed = buffers.size();
310 int64_t unplaced = 0;
311 for (auto &[_, members] : components) {
312 llvm::SmallVector<Buffer> component;
313 for (unsigned index : members)
314 component.push_back(buffers[index]);
315 chosen.clear();
316 failed = component.size();
317 unplacedBytes = 0;
318 int retries = kRetries;
319 if (placeFrom(component, 0, retries)) {
320 for (auto [index, tile] : llvm::zip_equal(members, chosen))
321 placedOn[index] = tile;
322 continue;
323 }
324 // Its buffers stay off the tiles for the components after it.
325 while (!chosen.empty())
326 removeLast(chosen.pop_back_val());
327 firstFailed = std::min<size_t>(
328 firstFailed, members[std::min<size_t>(failed, members.size() - 1)]);
329 unplaced += unplacedBytes;
330 }
331 chosen = std::move(placedOn);
332 failed = firstFailed;
333 unplacedBytes = unplaced;
334 return firstFailed == buffers.size();
335 }
336 llvm::SmallVector<unsigned> chosen;
337 size_t failed = 0;
338 int64_t unplacedBytes = 0;
339 /// Homes a spill from was weighed: aie-objectfifo-allocate gives their
340 /// neighbours tile ops, as later passes may use them.
341 llvm::SmallVector<bool> weighed;
342
343private:
344 llvm::SmallVector<unsigned> spillTargets(const Buffer &buffer) {
345 weighed[buffer.home] = true;
346 llvm::SmallVector<unsigned, 2> neighbours(buffer.neighbours);
347 // A stable sort allocates a buffer even for the usual two neighbours.
348 if (neighbours.size() == 2) {
349 if (used(neighbours[1]) < used(neighbours[0]))
350 std::swap(neighbours[0], neighbours[1]);
351 } else {
352 llvm::stable_sort(neighbours, [&](unsigned a, unsigned b) {
353 return used(a) < used(b);
354 });
355 }
356 llvm::SmallVector<unsigned> fitting;
357 for (unsigned neighbour : neighbours)
358 if (fits(neighbour, buffer.bytes))
359 fitting.push_back(neighbour);
360 return fitting;
361 }
362
363 bool placeFrom(llvm::ArrayRef<Buffer> buffers, size_t index, int &retries) {
364 if (index == buffers.size())
365 return true;
366 const Buffer &buffer = buffers[index];
367 bool fitsHome = buffer.atHome && fits(buffer.home, buffer.bytes);
368 llvm::SmallVector<unsigned> candidates;
369 if (fitsHome)
370 candidates.push_back(buffer.home);
371 else
372 candidates = spillTargets(buffer);
373 if (candidates.empty() && index < failed) {
374 failed = index;
375 unplacedBytes = 0;
376 for (const Buffer &left : buffers.drop_front(index))
377 unplacedBytes += left.bytes;
378 }
379 auto tryTile = [&](unsigned tile) {
380 add(tile, buffer.bytes);
381 chosen.push_back(tile);
382 if (placeFrom(buffers, index + 1, retries))
383 return true;
384 removeLast(tile);
385 chosen.pop_back();
386 return false;
387 };
388 for (auto [i, tile] : llvm::enumerate(candidates)) {
389 if (i > 0 && retries-- <= 0)
390 return false;
391 if (tryTile(tile))
392 return true;
393 }
394 if (!fitsHome)
395 return false;
396 for (unsigned tile : spillTargets(buffer)) {
397 if (retries-- <= 0)
398 return false;
399 if (tryTile(tile))
400 return true;
401 }
402 return false;
403 }
404
405 void add(unsigned tile, int64_t bytes) {
406 planned[tile].push_back(bytes);
407 plannedBytes[tile] += bytes;
408 misaligned[tile] += bytes % alignment != 0;
409 }
410 void removeLast(unsigned tile) {
411 int64_t bytes = planned[tile].pop_back_val();
412 plannedBytes[tile] -= bytes;
413 misaligned[tile] -= bytes % alignment != 0;
414 }
415
416 llvm::SmallVector<Tile> tiles;
417 llvm::SmallVector<llvm::SmallVector<int64_t>> planned;
418 int64_t alignment;
419 /// What the fixed buffers span when unpinned and aligned in size, and the
420 /// planned buffers' bytes and how many of them are not.
421 llvm::SmallVector<std::optional<int64_t>> fixedBytes;
422 llvm::SmallVector<int64_t> plannedBytes;
423 llvm::SmallVector<int> misaligned;
424};
425
426/// The alignment assign-buffer-addresses places `buffer` at, in bytes: the
427/// vector rule when `aligned`, and the measured section alignment either way.
428inline int64_t bufferAlignBytes(BufferOp buffer, uint32_t tileAlignBitWidth,
429 uint32_t maxVecAlignBits) {
430 int64_t sectionAlign = buffer.getSectionAlignment();
431 if (!buffer.getAligned())
432 return sectionAlign;
433 return std::max<int64_t>(requiredBufferAlignBits(tileAlignBitWidth,
434 maxVecAlignBits,
435 buffer.getAllocationSize()) /
436 8,
437 sectionAlign);
438}
439
440/// One buffer of a tile, as assign-buffer-addresses lays it out.
442 int64_t size = 0;
443 /// bufferAlignBytes.
444 int64_t alignBytes = 1;
445 /// The measured section alignment a pinned address must meet.
446 int64_t sectionAlignBytes = 1;
447 /// Whether a pinned address must meet the bus width.
448 bool aligned = true;
449 std::optional<int64_t> address;
450 std::optional<int32_t> memBank;
451 /// The banks the buffer's memory space allows, when it names some.
452 llvm::SmallVector<int, 2> spaceBanks;
453 /// Whether the buffer has an initial value, which keeps it off
454 /// TileLayoutProblem::initGuardBytes.
455 bool initialized = false;
456};
457
458/// A tile's data memory and what it must hold.
460 int numBanks = 1;
461 uint32_t tileAlignBitWidth = 0;
462 uint32_t maxVecAlignBits = 0;
463 int64_t maxDataMemorySize = 0;
464 /// Whether the tile runs a core, whose sections need a contiguous region.
465 bool hasCore = false;
466 /// The core's stack; empty without one.
468 /// For a stack pinned to a bank but not an address: the bank, and the
469 /// alignment of the address chosen in it.
470 std::optional<int> stackBank;
471 int64_t stackAlignBytes = 1;
472 /// Bytes at the start of the tile an initialized buffer must not cover.
473 int64_t initGuardBytes = 0;
474 /// In the order the device holds them.
475 llvm::SmallVector<TileLayoutBuffer> buffers;
476 /// Placements each search may try before it gives up.
477 int64_t budget = 0;
478};
479
480/// What the searches cost, for --mlir-pass-statistics.
482 int64_t backtracks = 0; // placements undone because a later buffer had none
483 int64_t tilesSearched = 0; // tiles needing more than the ranked first try
484 int64_t budgetExhausted = 0;
485 int64_t tilesCompacted = 0; // placed only by the exhaustive search
486};
487
488/// assign-buffer-addresses' layout of one tile, or why there is none.
490 enum class Status {
492 /// The bank-pinned stack has no room; `message` says why.
494 /// Buffer `failed` has a pin or bank request the tile cannot honour;
495 /// `message` says why.
497 /// Buffer `failed` fits nowhere once the others are placed.
499 };
501 size_t failed = 0;
502 std::string message;
503 /// Whether the search ran out of budget with arrangements untried.
504 bool exhausted = false;
505 /// Address and bank of each buffer placed: every buffer when Placed, and
506 /// the pinned ones plus the deepest attempt's on NoRoom.
507 llvm::SmallVector<std::optional<std::pair<int64_t, int>>> at;
508 /// The address chosen for a bank-pinned stack.
509 std::optional<int64_t> stackStart;
510 /// The buffers with an address or bank pin, in the order they were placed,
511 /// and the others in the order the search placed them.
512 llvm::SmallVector<size_t> preAllocated, allocated;
513 /// The banks buffer `failed` must lie in, and on NoRoom with one bank,
514 /// the bytes free there.
515 llvm::SmallVector<int, 2> failedBanks;
516 int64_t freeInFailedBank = 0;
517 /// Bytes of the buffers left without an address on NoRoom.
518 int64_t unplacedBytes = 0;
519};
520
521/// Lays out `problem` as assign-buffer-addresses does, without touching IR.
523
524/// assign-buffer-addresses' placement-budget unless set.
525constexpr int64_t kDefaultPlacementBudget = 100000;
526
527/// What assign-buffer-addresses lays `buffer` out as, on a tile with
528/// `limits`.
529TileLayoutBuffer tileLayoutBuffer(BufferOp buffer,
530 const TileMemoryLimits &limits);
531
532/// What assign-buffer-addresses lays out the buffer it makes for `held` as,
533/// on a core tile with `limits`.
535 const TileMemoryLimits &limits);
536
537} // namespace xilinx::AIE
538
539#endif // AIE_DIALECT_AIE_TRANSFORMS_AIEBUFFERALLOCATION_H
virtual uint32_t getLocalMemorySize() const =0
Return the size (in bytes) of the local data memory of a core.
virtual uint32_t getComputeTileLoadStoreBusWidth() const =0
Return the data bus width (in bits) for load/store operations of a compute core.
virtual bool isValidTile(TileID src) const
Return true if the given tile ID is valid.
virtual uint32_t getComputeTileMaxVectorAlignBits() const
Return the alignment (in bits) required by the widest vector load/store a compute core can issue.
virtual int columns() const =0
Return the number of columns in the device.
virtual uint32_t getMemTileLoadStoreBusWidth() const
Return the data bus width (in bits) for load/store operations of a memory tile.
@ Second
Only the second tile's module.
SharedMemory getSharedMemory(TileID a, TileID b) const
Return the memory module a and b can both reach, if any.
virtual uint32_t getMemTileSize() const =0
Return the size (in bytes) of a MemTile.
void reserve(unsigned tile, int64_t bytes, int count=1)
bool place(llvm::ArrayRef< Buffer > buffers)
Places buffers in order on top of what the tiles hold.
llvm::SmallVector< bool > weighed
Homes a spill from was weighed: aie-objectfifo-allocate gives their neighbours tile ops,...
static constexpr int kRetries
Alternatives the search tries before it gives up.
MemTileSpillSearch(llvm::SmallVector< Tile > tiles, int64_t alignment)
bool fits(unsigned tile, int64_t bytes, int count=1) const
llvm::SmallVector< unsigned > chosen
int64_t used(unsigned tile, int64_t bytes=0, int count=0) const
The bytes tile spans with what it holds and count more of bytes.
void sortLargestBufferFirst(Range &&buffers, BytesFn bytes)
Buffers are laid out, and given a tile, largest buffer first: by the address layout below,...
TileLayout layoutTile(const TileLayoutProblem &problem, TileLayoutStats &stats)
Lays out problem as assign-buffer-addresses does, without touching IR.
TileLayoutBuffer tileLayoutBuffer(BufferOp buffer, const TileMemoryLimits &limits)
What assign-buffer-addresses lays buffer out as, on a tile with limits.
llvm::SmallVector< unsigned > demandFirstOrder(llvm::ArrayRef< SpillPool > pools)
aie-objectfifo-allocate's demand-first packing order of pools, given in its size-first order,...
llvm::SmallVector< TileID, 2 > memTileSpillNeighbours(const AIETargetModel &target, TileID home)
The tiles a mem tile buffer homed at home may spill to: those in its row home shares memory with,...
struct TileID { friend std::ostream &operator<<(std::ostream &os, const TileID &s) { os<< "TileID("<< s.col<< ", "<< s.row<< ")"; return os; } friend std::string to_string(const TileID &s) { std::ostringstream ss; ss<< s; return ss.str(); } friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const TileID &s) { os<< to_string(s); return os; } inline bool operator<(const TileID &rhs) const { return std::tie(col, row)< std::tie(rhs.col, rhs.row); } bool operator==(const TileID &rhs) const { return std::tie(col, row)==std::tie(rhs.col, rhs.row); } bool operator!=(const TileID &rhs) const { return !(*this==rhs);} int col, row;} TileID
constexpr int64_t kDefaultPlacementBudget
assign-buffer-addresses' placement-budget unless set.
uint32_t requiredBufferAlignBits(uint32_t busAlignBits, uint32_t maxVecAlignBits, int64_t sizeBytes)
Return the alignment (in bits) a buffer of sizeBytes must satisfy.
int64_t assignSequentialBufferAddresses(llvm::MutableArrayRef< BufferAllocation > buffers, int64_t start=0)
The basic address allocator and resource planner share this layout: retain address pins,...
int64_t bufferAlignBytes(BufferOp buffer, uint32_t tileAlignBitWidth, uint32_t maxVecAlignBits)
The alignment assign-buffer-addresses places buffer at, in bytes: the vector rule when aligned,...
TileMemoryLimits tileMemoryLimits(const AIETargetModel &targetModel, AIETileType tileType)
llvm::SmallVector< unsigned > memTileSpillComponents(llvm::ArrayRef< TileID > homes, llvm::function_ref< llvm::SmallVector< TileID, 2 >(TileID)> neighboursOf)
For each of homes, the index of its component: homes whose buffers may spill to a tile in common,...
std::optional< int64_t > address
A buffer of bytes homed on home, which it may take unless atHome is false, and the neighbours it may ...
llvm::SmallVector< unsigned, 2 > neighbours
Buffer(int64_t bytes, unsigned home, bool atHome, llvm::SmallVector< unsigned, 2 > neighbours)
llvm::SmallVector< BufferAllocation > fixed
Tile(int64_t capacity, llvm::SmallVector< BufferAllocation > fixed)
A mem tile pool as aie-objectfifo-allocate packs it: count buffers of bytes homed on home,...
SpillPool(int64_t bytes, int64_t count, unsigned home, int demand)
One buffer of a tile, as assign-buffer-addresses lays it out.
std::optional< int64_t > address
int64_t alignBytes
bufferAlignBytes.
llvm::SmallVector< int, 2 > spaceBanks
The banks the buffer's memory space allows, when it names some.
int64_t sectionAlignBytes
The measured section alignment a pinned address must meet.
std::optional< int32_t > memBank
bool initialized
Whether the buffer has an initial value, which keeps it off TileLayoutProblem::initGuardBytes.
bool aligned
Whether a pinned address must meet the bus width.
A tile's data memory and what it must hold.
llvm::SmallVector< TileLayoutBuffer > buffers
In the order the device holds them.
bool hasCore
Whether the tile runs a core, whose sections need a contiguous region.
MemoryRun stackRun
The core's stack; empty without one.
std::optional< int > stackBank
For a stack pinned to a bank but not an address: the bank, and the alignment of the address chosen in...
int64_t budget
Placements each search may try before it gives up.
int64_t initGuardBytes
Bytes at the start of the tile an initialized buffer must not cover.
What the searches cost, for –mlir-pass-statistics.
assign-buffer-addresses' layout of one tile, or why there is none.
llvm::SmallVector< std::optional< std::pair< int64_t, int > > > at
Address and bank of each buffer placed: every buffer when Placed, and the pinned ones plus the deepes...
@ StackNoRoom
The bank-pinned stack has no room; message says why.
@ NoRoom
Buffer failed fits nowhere once the others are placed.
@ BadPin
Buffer failed has a pin or bank request the tile cannot honour; message says why.
llvm::SmallVector< int, 2 > failedBanks
The banks buffer failed must lie in, and on NoRoom with one bank, the bytes free there.
llvm::SmallVector< size_t > preAllocated
The buffers with an address or bank pin, in the order they were placed, and the others in the order t...
bool exhausted
Whether the search ran out of budget with arrangements untried.
int64_t unplacedBytes
Bytes of the buffers left without an address on NoRoom.
std::optional< int64_t > stackStart
The address chosen for a bank-pinned stack.
llvm::SmallVector< size_t > allocated
A memtile is reached by DMA rather than by core vector load and store, so its bus width also covers t...