13#include "llvm/ADT/BitVector.h"
14#include "llvm/ADT/DenseSet.h"
26Value DMAChannelAnalysis::getTileKey(Value tile) {
27 auto tileOp = cast<TileLike>(tile.getDefiningOp());
28 auto col = tileOp.tryGetCol();
29 auto row = tileOp.tryGetRow();
32 return tilesByCoordinate.try_emplace({*col, *row}, tile).first->second;
35void DMAChannelAnalysis::claim(Value tile, DMAChannelDir dir,
int channel,
37 if (usedChannels.try_emplace({getTileKey(tile), dir, channel}, owner).second)
38 claims.emplace_back(tile, dir, channel, owner);
42 for (
auto program : device.getOps<DmaBody>()) {
43 for (Block &block : program.getDmaBody()) {
44 for (
auto start : block.getOps<DMAStartOp>()) {
46 if (start.getEndpoint())
48 claim(program.getTile(), start.getChannelDir(), start.getChannelIndex(),
59 auto streamDMA = [&](Value tile, DMAChannelDir dir,
int channel,
61 streamedChannels.try_emplace(
62 std::make_tuple(getTileKey(tile), dir, channel), owner);
64 for (
auto flowOp : device.getOps<FlowOp>()) {
65 if (flowOp.getSourceBundle() == WireBundle::Core) {
66 usedStreams.try_emplace({getTileKey(flowOp.getSource()),
67 DMAChannelDir::MM2S, flowOp.getSourceChannel()},
68 StreamClaim{flowOp,
false});
70 if (flowOp.getDestBundle() == WireBundle::Core) {
71 usedStreams.try_emplace({getTileKey(flowOp.getDest()),
72 DMAChannelDir::S2MM, flowOp.getDestChannel()},
73 StreamClaim{flowOp,
false});
75 if (flowOp.getSourceBundle() == WireBundle::DMA)
76 streamDMA(flowOp.getSource(), DMAChannelDir::MM2S,
77 flowOp.getSourceChannel(), flowOp);
78 if (flowOp.getDestBundle() == WireBundle::DMA)
79 streamDMA(flowOp.getDest(), DMAChannelDir::S2MM, flowOp.getDestChannel(),
82 for (
auto packetFlow : device.getOps<PacketFlowOp>()) {
83 for (
auto source : packetFlow.getOps<PacketSourceOp>())
84 if (source.getBundle() == WireBundle::DMA)
85 streamDMA(source.getTile(), DMAChannelDir::MM2S, source.getChannel(),
87 for (
auto dest : packetFlow.getOps<PacketDestOp>())
88 if (dest.getBundle() == WireBundle::DMA)
89 streamDMA(dest.getTile(), DMAChannelDir::S2MM, dest.getChannel(),
95 device.walk([&](AIEX::DMAConfigureTaskOp task) {
96 claim(task.getTile(), task.getDirection(), (
int)task.getChannel(), task);
99 for (
auto flow : device.getOps<PacketFlowOp>()) {
100 Block &ports = flow.getPorts().front();
101 for (
auto source : ports.getOps<PacketSourceOp>())
102 if (source.getBundle() == WireBundle::Core)
103 usedStreams.try_emplace({getTileKey(source.getTile()),
104 DMAChannelDir::MM2S, source.channelIndex()},
105 StreamClaim{source,
true});
106 for (
auto dest : ports.getOps<PacketDestOp>())
107 if (dest.getBundle() == WireBundle::Core)
108 usedStreams.try_emplace({getTileKey(dest.getTile()),
109 DMAChannelDir::S2MM, dest.channelIndex()},
110 StreamClaim{dest,
true});
117 for (
auto allocOp : device.getOps<ShimDMAAllocationOp>()) {
118 MLIRContext *context = allocOp->getContext();
119 if (!AIEDialect::ShareableWithAttrHelper(context).isAttrPresent(allocOp)) {
120 claim(allocOp.getTile(), allocOp.getChannelDir(),
121 (
int)allocOp.getChannelIndex(), allocOp);
124 shareableChannels.try_emplace(
125 std::make_tuple(getTileKey(allocOp.getTile()), allocOp.getChannelDir(),
126 (
int)allocOp.getChannelIndex()),
127 allocOp.getOperation());
128 if (!AIEDialect::IsCtrlPktOverlayAttrHelper(context).isAttrPresent(allocOp))
129 claims.emplace_back(allocOp.getTile(), allocOp.getChannelDir(),
130 (
int)allocOp.getChannelIndex(), allocOp);
135 TileLike tile, DMAChannelDir dir,
bool requiresAdjacentTileAccessChannels) {
136 std::optional<int> col = tile.tryGetCol();
137 std::optional<int> row = tile.tryGetRow();
143 : cast<LogicalTileOp>(tile.getOperation()).getCanonicalTileID();
144 int maxChannelNum = targetModel.getNumDMAChannels(
id.col,
id.row, dir);
146 if (!requiresAdjacentTileAccessChannels)
147 return maxChannelNum;
150 return std::min<int>(
152 targetModel.getMaxChannelNumForAdjacentMemTile(*col, *row));
156 bool foundPosition =
false;
157 for (
int c = 0; c < targetModel.columns(); ++c) {
158 if (col && c != *col)
160 for (
int r = 0; r < targetModel.rows(); ++r) {
161 if ((row && r != *row) ||
162 targetModel.getTileType(c, r) != tile.getTileType())
164 foundPosition =
true;
165 maxChannelNum = std::min<int>(
166 maxChannelNum, targetModel.getMaxChannelNumForAdjacentMemTile(c, r));
170 return foundPosition ? maxChannelNum : 0;
174 TileLike tile, DMAChannelDir dir,
bool requiresAdjacentTileAccessChannels,
177 for (
int i = 0; i < limit; i++) {
188 auto key = std::make_tuple(getTileKey(tile->getResult(0)), dir, channel);
189 return !usedChannels.contains(key) && !streamedChannels.contains(key) &&
190 !shareableChannels.contains(key);
194 int channel, Operation *owner,
197 if (channel < 0 || channel >= maxChannelNum) {
200 auto key = std::make_tuple(getTileKey(tile->getResult(0)), dir, channel);
201 if (
auto *reservation = shareableChannels.lookup(key)) {
205 AIEDialect::ShareableWithAttrHelper(reservation->getContext())
206 .getAttr(reservation);
208 owner ? owner->getAttrOfType<StringAttr>(
"sym_name") : StringAttr();
209 if (!allowed || !name || llvm::none_of(allowed, [&](Attribute attr) {
210 auto symbol = dyn_cast<FlatSymbolRefAttr>(attr);
211 return symbol && symbol.getAttr() == name;
215 if (usedChannels.try_emplace(key, owner).second) {
217 sharedChannels.insert(key);
222 if (shareable && sharedChannels.contains(key))
230 auto key = std::make_tuple(getTileKey(tile->getResult(0)), dir, channel);
231 if (Operation *owner = usedChannels.lookup(key))
233 if (Operation *owner = streamedChannels.lookup(key))
235 return shareableChannels.lookup(key);
242 auto [it, inserted] = usedStreams.try_emplace(
243 {getTileKey(tile->getResult(0)), chan.direction, chan.channel},
244 StreamClaim{user, packet});
245 if (inserted || (packet && it->second.packet)) {
248 auto diag = user->emitOpError(
"Core ")
249 << (chan.direction == DMAChannelDir::MM2S ?
"output " :
"input ")
251 <<
" is already in use on this tile; a core stream port carries "
252 "one circuit or only packet flows";
253 diag.attachNote(it->second.owner->getLoc()) <<
"the other stream is here";
258 SmallVector<Block *> chain;
259 SmallPtrSet<Block *, 8> seen;
260 SmallVector<Block *> work{start.getDest()};
261 while (!work.empty()) {
262 Block *block = work.pop_back_val();
263 if (!seen.insert(block).second || block->getOps<DMABDOp>().empty())
265 chain.push_back(block);
266 if (
auto next = dyn_cast<NextBDOp>(block->getTerminator()))
267 work.push_back(next.getDest());
274 for (Block *block :
chainOf(start))
275 bds += llvm::range_size(block->getOps<DMABDOp>());
280 for (
auto program : device.getOps<DmaBody>())
281 for (Block &block : program.getDmaBody())
282 for (
auto start : block.getOps<DMAStartOp>())
283 if (!start.getEndpointOp())
284 if (Operation *tile = program.getTile().getDefiningOp())
285 fixed[tile][{start.getChannelDir(), start.getChannelIndex()}] +=
289 device, [&](Operation *, Operation *tile, std::optional<int> channel,
290 std::optional<DMAChannelDir> dir, int32_t
id) {
291 pinned[tile].push_back(Pin{order++, id, channel, dir});
295std::map<DMAChannelAnalysis::BDUser, int64_t>
297 ArrayRef<Operation *> tiles)
const {
298 auto here = [&](Operation *tile) {
299 auto like = dyn_cast<TileLike>(tile);
300 return llvm::is_contained(tiles, tile) ||
301 (like && like.tryGetCol() == col && like.tryGetRow() == row);
303 std::map<BDUser, int64_t> taken;
304 for (
auto &[tile, users] : fixed)
306 for (
auto [user, bds] : users)
308 int numChannels = std::max(
313 std::map<std::pair<uint32_t, int32_t>, std::pair<unsigned, BDUser>> charged;
314 for (
auto &[tile, pins] : pinned) {
317 for (
const Pin &pin : pins) {
318 SmallVector<DMAChannelDir, 2> dirs;
320 dirs.push_back(*pin.dir);
322 dirs.append({DMAChannelDir::S2MM, DMAChannelDir::MM2S});
323 std::optional<uint32_t> own;
324 if (pin.channel && pin.dir &&
327 own = target.
getBdPoolId(col, row, *pin.channel, *pin.dir);
328 std::optional<BDUser> user;
329 for (
int channel = 0, last = pin.channel.value_or(numChannels - 1);
330 channel <= last && !user; ++channel)
331 for (DMAChannelDir dir : dirs)
333 (!own || target.
getBdPoolId(col, row, channel, dir) == *own)) {
334 user =
BDUser{dir, channel};
339 uint32_t pool = target.
getBdPoolId(col, row, user->second, user->first);
340 if (
auto [it, added] =
341 charged.try_emplace({pool, pin.id}, pin.order, *user);
342 !added && pin.order < it->second.first)
343 it->second = {pin.order, *user};
346 for (
auto &[key, entry] : charged)
347 ++taken[entry.second];
351SmallVector<std::pair<int, int>>
353 std::set<std::pair<int, int>>
at;
354 auto add = [&](Operation *tile) {
355 auto like = dyn_cast<TileLike>(tile);
358 if (
auto col = like.tryGetCol(), row = like.tryGetRow(); col && row)
359 at.insert({*col, *row});
361 for (
auto &entry : fixed)
363 for (
auto &entry : pinned)
365 return {
at.begin(),
at.end()};
368llvm::SmallVector<DMAChannelAnalysis::BDGroup>
376 SmallVector<Pool> pools;
377 for (
int channel = 0; channel < numChannels; ++channel)
378 for (DMAChannelDir dir : {DMAChannelDir::S2MM, DMAChannelDir::MM2S}) {
381 uint32_t poolId = target.
getBdPoolId(col, row, channel, dir);
386 auto *it = llvm::find_if(
387 pools, [&](
const Pool &pool) {
return pool.id == poolId; });
388 if (it != pools.end()) {
389 llvm::append_range(merged.group.users, it->group.users);
392 pools.push_back(std::move(merged));
394 SmallVector<BDGroup> groups;
395 for (Pool &pool : pools) {
396 llvm::sort(pool.group.users, [](
const BDUser &a,
const BDUser &b) {
397 return std::make_pair(a.second, a.first) <
398 std::make_pair(b.second, b.first);
400 groups.push_back(std::move(pool.group));
405static SmallVector<DMAChannelAnalysis::BDGroup>
407 int numChannels = std::max(
414 const AIETargetModel &target,
int col,
int row, ArrayRef<BDPlanEnd> allEnds,
415 function_ref<
bool(DMAChannelDir,
int)> free,
416 function_ref<int64_t(DMAChannelDir,
int)> spent) {
417 return planBDChannels(tileBDGroups(target, col, row), allEnds, free, spent);
421 ArrayRef<BDGroup> tileGroups, ArrayRef<BDPlanEnd> allEnds,
422 function_ref<
bool(DMAChannelDir,
int)> free,
423 function_ref<int64_t(DMAChannelDir,
int)> spent) {
427 SmallVector<BDUser> users;
430 SmallVector<Group> groups;
431 for (
const BDGroup &group : tileGroups) {
432 Group &added = groups.emplace_back(Group{group.users, group.size});
433 for (
auto [dir, channel] : group.users)
434 added.room -= spent(dir, channel);
439 SmallVector<BDPlanEnd> ends;
440 SmallVector<unsigned> looseOf;
441 llvm::DenseSet<std::pair<int, int>> pinned;
442 for (
auto [index, end] : llvm::enumerate(allEnds)) {
445 looseOf.push_back(index);
448 BDUser user{end.dir, *end.pinned};
449 auto *group = llvm::find_if(groups, [&](
const Group &group) {
450 return llvm::is_contained(group.users, user);
452 if (group == groups.end())
454 group->room -= end.bds;
455 pinned.insert({
static_cast<int>(end.dir), *end.pinned});
457 if (llvm::any_of(groups, [](
const Group &group) {
return group.room < 0; }))
459 auto open = [&](DMAChannelDir dir,
int channel) {
460 return free(dir, channel) &&
461 !pinned.contains({
static_cast<int>(dir), channel});
469 SmallVector<unsigned> order(ends.size());
470 std::iota(order.begin(), order.end(), 0);
471 auto shape = [&](
unsigned end) {
472 return std::make_tuple(-ends[end].bds,
static_cast<int>(ends[end].dir),
476 order, [&](
unsigned a,
unsigned b) {
return shape(a) < shape(b); });
477 SmallVector<unsigned> groupOf(ends.size());
478 SmallVector<int> channelOf(ends.size(), -1);
480 SmallVector<unsigned> byBound(ends.size());
481 std::iota(byBound.begin(), byBound.end(), 0);
482 llvm::stable_sort(byBound, [&](
unsigned a,
unsigned b) {
483 return ends[a].limit < ends[b].limit;
485 llvm::DenseSet<std::pair<int, int>> taken;
486 for (
unsigned end : byBound) {
488 for (
auto [userDir, channel] : groups[groupOf[end]].users) {
489 int dir =
static_cast<int>(ends[end].dir);
490 if (userDir == ends[end].dir && channel < ends[end].limit &&
491 open(ends[end].dir, channel) &&
492 taken.insert({dir, channel}).second) {
493 channelOf[end] = channel;
497 if (channelOf[end] < 0)
507 SmallVector<int> bounds;
509 bounds.push_back(end.limit);
511 bounds.erase(llvm::unique(bounds), bounds.end());
512 size_t slots = 2 * bounds.size();
513 SmallVector<int64_t> below(groups.size() * slots, 0);
514 for (
auto [g, group] : llvm::enumerate(groups))
515 for (DMAChannelDir dir : {DMAChannelDir::S2MM, DMAChannelDir::MM2S})
516 for (
auto [i, bound] : llvm::enumerate(bounds))
517 for (
auto [userDir, channel] : group.users)
518 below[g * slots +
static_cast<int>(dir) * bounds.size() + i] +=
519 userDir == dir && channel < bound && open(dir, channel);
520 SmallVector<int64_t> held(groups.size() * slots, 0);
521 auto fits = [&](
unsigned g, DMAChannelDir dir) {
522 size_t base = g * slots +
static_cast<int>(dir) * bounds.size();
524 for (
size_t i = 0; i < bounds.size(); ++i) {
525 tighter += held[base + i];
526 if (tighter > below[base + i])
533 for (DMAChannelDir dir : {DMAChannelDir::S2MM, DMAChannelDir::MM2S}) {
535 for (
size_t i = 0; i < bounds.size(); ++i) {
537 for (
size_t g = 0; g < groups.size(); ++g)
538 room += below[g * slots +
static_cast<int>(dir) * bounds.size() + i];
539 tighter += llvm::count_if(ends, [&](
const BDPlanEnd &end) {
540 return end.dir == dir && end.limit == bounds[i];
548 std::function<bool(
size_t)> place = [&](
size_t next) {
549 if (next == order.size())
551 unsigned end = order[next];
552 size_t slot =
static_cast<int>(ends[end].dir) * bounds.size() +
553 (llvm::lower_bound(bounds, ends[end].limit) - bounds.begin());
554 unsigned first = next > 0 && shape(order[next - 1]) == shape(end)
555 ? groupOf[order[next - 1]]
557 for (
unsigned g = first; g < groups.size(); ++g) {
558 if (groups[g].room < ends[end].bds)
560 ++held[g * slots + slot];
561 if (fits(g, ends[end].dir)) {
563 groups[g].room -= ends[end].bds;
564 bool placed = place(next + 1);
565 groups[g].room += ends[end].bds;
567 --held[g * slots + slot];
571 --held[g * slots + slot];
577 SmallVector<int> result;
579 result.push_back(end.pinned ? *end.pinned : -1);
580 for (
auto [loose, index] : llvm::enumerate(looseOf))
581 result[index] = channelOf[loose];
586 ArrayRef<BDPlanEnd> ends, ArrayRef<unsigned> poolOf,
587 ArrayRef<BDWalkPool> pools, ArrayRef<bool> whole) {
588 SmallVector<int64_t> bds(pools.size(), 0);
589 for (
auto [end, pool] : llvm::zip_equal(ends, poolOf))
590 bds[pool] += end.bds;
591 auto key = [&](
unsigned pool) {
592 return std::make_tuple(pools[pool].depth, -pools[pool].objectBytes,
595 std::optional<unsigned> next;
596 for (
unsigned pool = 0, e = pools.size(); pool < e; ++pool)
597 if (pools[pool].walkable && !whole[pool] &&
598 (!next || key(pool) > key(*next)))
604 const AIETargetModel &target,
int col,
int row, ArrayRef<BDPlanEnd> ends,
605 ArrayRef<unsigned> poolOf, ArrayRef<BDWalkPool> pools,
606 function_ref<
bool(DMAChannelDir,
int)> free,
607 function_ref<int64_t(DMAChannelDir,
int)> spent,
unsigned maxSets) {
609 SmallVector<BDGroup> tileGroups = tileBDGroups(target, col, row);
610 auto none = [](DMAChannelDir, int) -> int64_t {
return 0; };
611 auto fitsWalking = [&](ArrayRef<bool> whole,
bool weighted) {
612 SmallVector<BDPlanEnd> planned;
613 for (
auto [end, pool] : llvm::zip_equal(ends, poolOf))
614 planned.push_back({end.dir,
618 end.limit, end.pinned});
622 : function_ref<int64_t(DMAChannelDir,
int)>(none))
625 SmallVector<bool> whole(pools.size(),
false);
626 if (!fitsWalking(whole,
false)) {
630 if (fitsWalking(whole,
true))
633 SmallVector<unsigned> ranked;
634 while (std::optional<unsigned> next =
636 ranked.push_back(*next);
639 if (!fitsWalking(whole,
true)) {
645 unsigned n = ranked.size();
646 assert(n < 32 &&
"each walkable pool draws a channel the plan above fit");
647 SmallVector<int64_t> maskBytes(uint32_t(1) << n, 0);
648 for (uint32_t mask = 1; mask < (uint32_t(1) << n); ++mask) {
649 const BDWalkPool &pool = pools[ranked[llvm::countr_zero(mask)]];
653 auto bytes = [&](uint32_t mask) {
return maskBytes[mask]; };
659 SmallVector<uint32_t> order;
660 for (uint32_t mask = 1; mask < (uint32_t(1) << n); ++mask)
661 order.push_back(mask);
662 llvm::stable_sort(order, [&](uint32_t a, uint32_t b) {
663 int64_t aBytes = bytes(a), bBytes = bytes(b);
664 if (aBytes != bBytes)
665 return aBytes < bBytes;
666 if (llvm::popcount(a) != llvm::popcount(b))
667 return llvm::popcount(a) < llvm::popcount(b);
670 uint32_t differ = a ^ b;
671 return differ && (a & differ & -differ);
673 llvm::BitVector fitsMask(uint32_t(1) << n);
674 for (uint32_t mask : order) {
675 if (result.
sets.size() >= maxSets)
677 bool fits = llvm::any_of(llvm::seq<unsigned>(0, n), [&](
unsigned bit) {
678 return (mask >> bit & 1) && fitsMask.test(mask & ~(uint32_t(1) << bit));
681 llvm::fill(whole,
false);
682 for (
unsigned bit = 0; bit < n; ++bit)
684 whole[ranked[bit]] =
true;
685 fits = fitsWalking(whole,
true);
689 SmallVector<unsigned> set;
690 for (
unsigned bit = 0; bit < n; ++bit)
692 set.push_back(ranked[bit]);
693 result.
sets.push_back(std::move(set));
694 result.
bytes.push_back(bytes(mask));
701 ArrayRef<SmallVector<int64_t>> bytes,
702 function_ref<
bool(ArrayRef<unsigned>)> places,
unsigned maxTries) {
703 using Choice = std::vector<unsigned>;
704 auto total = [&](
const Choice &choice) {
706 for (
auto [tile, set] : llvm::enumerate(choice))
707 sum += bytes[tile][set];
713 std::set<std::pair<int64_t, Choice>> frontier;
714 std::set<Choice> seen;
715 Choice first(bytes.size(), 0);
716 frontier.insert({total(first), first});
719 result.
sets.assign(first.begin(), first.end());
720 for (
unsigned tries = 0; !frontier.empty(); ++tries) {
721 if (tries == maxTries) {
725 Choice choice = frontier.begin()->second;
726 frontier.erase(frontier.begin());
727 if (places(choice)) {
728 result.
sets.assign(choice.begin(), choice.end());
732 for (
unsigned tile = 0; tile < choice.size(); ++tile) {
733 if (choice[tile] + 1 >= bytes[tile].size())
735 Choice next = choice;
737 if (seen.insert(next).second)
738 frontier.insert({total(next), next});
virtual uint32_t getBdPoolId(int col, int row, int channel, DMAChannelDir dir) const
Return the pool channel in direction dir draws its BDs from.
bool isBdChannelAccessible(int col, int row, uint32_t bd_id, int channel, DMAChannelDir dir) const
uint32_t getNumDMAChannels(int col, int row, AIE::DMAChannelDir dir) const
Return the number of DMA channels a tile has in one direction.
virtual uint32_t getNumBDsInPool(int col, int row, uint32_t poolId) const
virtual uint32_t getNumDestSwitchboxConnections(int col, int row, WireBundle bundle) const =0
Return the number of destinations of connections inside a switchbox.
virtual uint32_t getNumSourceSwitchboxConnections(int col, int row, WireBundle bundle) const =0
Return the number of sources of connections inside a switchbox.
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 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.
void forEachRuntimePinnedBdId(AIE::DeviceOp device, llvm::function_ref< void(Operation *op, Operation *tile, std::optional< int > channel, std::optional< AIE::DMAChannelDir > dir, int32_t id)> pinned)
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
const AIETargetModel & getTargetModel(mlir::Operation *op)
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...
A DMA end of one tile: its direction, the BD ids it takes, the exclusive upper bound on the channels ...
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
One walkSetsThatFit set per mem tile of a spill component (memTileSpillComponents),...
llvm::SmallVector< unsigned > sets