MLIR-AIE 1.4.6.dev
AIEAssignBufferDescriptorIDs.cpp
Go to the documentation of this file.
1//===- AIEAssignBufferDescriptorIDs.cpp -------------------------*- C++ -*-===//
2//
3// Copyright (C) 2024 Advanced Micro Devices, Inc.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7
13
14#include "mlir/IR/Block.h"
15#include "mlir/IR/Builders.h"
16#include "mlir/IR/Region.h"
17#include "mlir/IR/ValueRange.h"
18#include "mlir/IR/Visitors.h"
19#include "mlir/Pass/Pass.h"
20#include "mlir/Support/LLVM.h"
21
22#include "llvm/ADT/STLExtras.h"
23#include "llvm/ADT/SmallVector.h"
24#include "llvm/Support/MathExtras.h"
25
26#include <algorithm>
27#include <cassert>
28#include <cstdint>
29#include <map>
30#include <memory>
31#include <optional>
32#include <set>
33#include <string>
34#include <utility>
35
36namespace xilinx::AIE {
37#define GEN_PASS_DEF_AIEASSIGNBUFFERDESCRIPTORIDS
38#include "aie/Dialect/AIE/Transforms/AIEPasses.h.inc"
39} // namespace xilinx::AIE
40
41#define DEBUG_TYPE "aie-assign-bd-ids"
42
43using namespace mlir;
44using namespace xilinx;
45using namespace xilinx::AIE;
46
50
51// The pool key of a BD id that no pool of the tile holds.
52static constexpr uint32_t noPool = ~0u;
53
54SmallVector<uint32_t, 2> BdIdGenerator::poolsHolding(uint32_t bdId) const {
55 SmallVector<uint32_t, 2> pools;
56 for (DMAChannelDir dir :
57 {DMAChannelDir::MM2S, DMAChannelDir::S2MM, DMAChannelDir::ControlMM2S,
58 DMAChannelDir::TraceS2MM}) {
59 int numChannels =
60 static_cast<int>(targetModel.getNumDMAChannels(col, row, dir));
61 // A tile without a data DMA still answers for channel 0.
62 if (getDMAChannelBundle(dir) == WireBundle::DMA)
63 numChannels = std::max(1, numChannels);
64 for (int channel = 0; channel < numChannels; ++channel) {
65 uint32_t pool = targetModel.getBdPoolId(col, row, channel, dir);
66 if (targetModel.isBdInChannelPool(col, row, bdId, channel, dir) &&
67 !llvm::is_contained(pools, pool))
68 pools.push_back(pool);
69 }
70 }
71 if (pools.empty())
72 pools.push_back(noPool);
73 return pools;
74}
75
76std::optional<uint32_t> BdIdGenerator::poolOf(int channelIndex,
77 DMAChannelDir dir,
78 uint32_t bdId) const {
79 if (!targetModel.isBdChannelAccessible(col, row, bdId, channelIndex, dir))
80 return std::nullopt;
81 return targetModel.getBdPoolId(col, row, channelIndex, dir);
82}
83
84std::optional<uint32_t> BdIdGenerator::nextBdId(int channelIndex,
85 DMAChannelDir dir,
86 uint32_t alignment) {
87 uint32_t pool = targetModel.getBdPoolId(col, row, channelIndex, dir);
88 auto [first, last] =
89 targetModel.getBdIdRangeForChannel(col, row, channelIndex, dir);
90 // Find the next free BD ID. This is not an efficient algorithm, but doesn't
91 // need to be.
92 for (uint32_t bdId = llvm::alignTo(first, alignment); bdId < last;
93 bdId += alignment) {
94 if (alreadyAssigned.count({pool, bdId}) || reserved.count({pool, bdId}))
95 continue;
96 alreadyAssigned.insert({pool, bdId});
97 return bdId;
98 }
99 return std::nullopt;
100}
101
102void BdIdGenerator::assignBdId(int channelIndex, DMAChannelDir dir,
103 uint32_t bdId) {
104 std::optional<uint32_t> pool = poolOf(channelIndex, dir, bdId);
105 if (!pool)
106 return assignBdId(bdId);
107 assert(!alreadyAssigned.count({*pool, bdId}) &&
108 "bdId has already been assigned");
109 alreadyAssigned.insert({*pool, bdId});
110}
111
112bool BdIdGenerator::bdIdAlreadyAssigned(int channelIndex, DMAChannelDir dir,
113 uint32_t bdId) {
114 std::optional<uint32_t> pool = poolOf(channelIndex, dir, bdId);
115 if (!pool)
116 return bdIdAlreadyAssigned(bdId);
117 return alreadyAssigned.count({*pool, bdId});
118}
119
120void BdIdGenerator::freeBdId(int channelIndex, DMAChannelDir dir,
121 uint32_t bdId) {
122 // Ids outside this channel's pool belong to another channel.
123 if (std::optional<uint32_t> pool = poolOf(channelIndex, dir, bdId))
124 alreadyAssigned.erase({*pool, bdId});
125}
126
127void BdIdGenerator::reserveBdId(int channelIndex, DMAChannelDir dir,
128 uint32_t bdId) {
129 if (std::optional<uint32_t> pool = poolOf(channelIndex, dir, bdId))
130 reserved.insert({*pool, bdId});
131 else
132 reserveBdId(bdId);
133}
134
135void BdIdGenerator::reserveBdId(uint32_t bdId) {
136 for (uint32_t pool : poolsHolding(bdId))
137 reserved.insert({pool, bdId});
138}
139
140bool BdIdGenerator::isReserved(int channelIndex, DMAChannelDir dir,
141 uint32_t bdId) const {
142 if (std::optional<uint32_t> pool = poolOf(channelIndex, dir, bdId))
143 return reserved.count({*pool, bdId});
144 return isReserved(bdId);
145}
146
147bool BdIdGenerator::isReserved(uint32_t bdId) const {
148 return llvm::any_of(poolsHolding(bdId), [&](uint32_t pool) {
149 return reserved.count({pool, bdId});
150 });
151}
152
153void BdIdGenerator::assignBdId(uint32_t bdId) {
154 for (uint32_t pool : poolsHolding(bdId))
155 alreadyAssigned.insert({pool, bdId});
156}
157
158void BdIdGenerator::freeBdId(uint32_t bdId) {
159 for (uint32_t pool : poolsHolding(bdId))
160 alreadyAssigned.erase({pool, bdId});
161}
162
164 return llvm::any_of(poolsHolding(bdId), [&](uint32_t pool) {
165 return alreadyAssigned.count({pool, bdId});
166 });
167}
168
169bool BdIdGenerator::holdsTileWide(int channelIndex, DMAChannelDir dir,
170 uint32_t bdId) const {
171 if (channelIndex < 0 ||
172 channelIndex >=
173 static_cast<int>(targetModel.getNumDMAChannels(col, row, dir)))
174 return true;
175 std::optional<uint32_t> pool = poolOf(channelIndex, dir, bdId);
176 if (!pool)
177 return true;
178 return poolsHolding(bdId) == SmallVector<uint32_t, 2>{*pool};
179}
180
181static constexpr StringLiteral reservedBdIdsAttr = "aiex.reserved_bd_ids";
182static constexpr StringLiteral reservedChannelBdIdsAttr =
183 "aiex.reserved_channel_bd_ids";
184
185bool xilinx::AIE::isReservedBdIdsAttr(StringRef name) {
186 return name == reservedBdIdsAttr || name == reservedChannelBdIdsAttr;
187}
188
189SmallVector<ReservedBdId> xilinx::AIE::getReservedBdIds(TileOp tile) {
190 SmallVector<ReservedBdId> ids;
191 if (auto flat = tile->getAttrOfType<DenseI32ArrayAttr>(reservedBdIdsAttr))
192 for (int32_t id : flat.asArrayRef())
193 ids.push_back({std::nullopt, id});
194 if (auto perChannel =
195 tile->getAttrOfType<DictionaryAttr>(reservedChannelBdIdsAttr))
196 for (NamedAttribute entry : perChannel) {
197 auto [dirName, channelName] = entry.getName().getValue().rsplit('_');
198 std::optional<DMAChannelDir> dir = symbolizeDMAChannelDir(dirName);
199 int channel;
200 auto list = dyn_cast<DenseI32ArrayAttr>(entry.getValue());
201 if (!dir || channelName.getAsInteger(10, channel) || !list)
202 continue;
203 for (int32_t id : list.asArrayRef())
204 ids.push_back({std::make_pair(channel, *dir), id});
205 }
206 return ids;
207}
208
209void xilinx::AIE::setReservedBdIds(TileOp tile, ArrayRef<ReservedBdId> ids) {
210 MLIRContext *ctx = tile->getContext();
211 std::set<int32_t> flat;
212 std::map<std::string, std::set<int32_t>> perChannel;
213 for (const ReservedBdId &r : ids) {
214 if (!r.channel) {
215 flat.insert(r.id);
216 continue;
217 }
218 auto [channel, dir] = *r.channel;
219 perChannel[(stringifyDMAChannelDir(dir) + "_" + Twine(channel)).str()]
220 .insert(r.id);
221 }
222 tile->removeAttr(reservedBdIdsAttr);
223 tile->removeAttr(reservedChannelBdIdsAttr);
224 if (!flat.empty())
225 tile->setAttr(reservedBdIdsAttr,
226 DenseI32ArrayAttr::get(
227 ctx, SmallVector<int32_t>(flat.begin(), flat.end())));
228 if (!perChannel.empty()) {
229 SmallVector<NamedAttribute> entries;
230 for (auto &[key, channelIds] : perChannel)
231 entries.emplace_back(
232 StringAttr::get(ctx, key),
233 DenseI32ArrayAttr::get(
234 ctx, SmallVector<int32_t>(channelIds.begin(), channelIds.end())));
235 tile->setAttr(reservedChannelBdIdsAttr, DictionaryAttr::get(ctx, entries));
236 }
237}
238
239// Read the head buffer-descriptor id and (biased) START_QUEUE repeat count of
240// the resident DMA channel (dir, channel) on `tile`, off the placed
241// aie.mem / aie.memtile_dma chain, exactly as the load-time start-queue push
242// does. Returns false if there is no such resident channel or its head BD id is
243// not yet assigned. Only the block form (aie.dma_start) is scanned; the
244// objectFIFO transform always emits that form.
245static bool resolveResidentChannel(DeviceOp device, TileOp tile,
246 DMAChannelDir dir, int channel,
247 uint32_t &headBdId, int32_t &repeatCount) {
248 auto scanRegion = [&](Region &region) -> bool {
249 for (Block &block : region)
250 for (DMAStartOp startOp : block.getOps<DMAStartOp>()) {
251 if (startOp.getChannelDir() != dir ||
252 startOp.getChannelIndex() != channel)
253 continue;
254 Block *dest = startOp.getDest();
255 if (!dest)
256 return false;
257 auto bds = dest->getOps<DMABDOp>();
258 if (bds.empty())
259 return false;
260 DMABDOp head = *bds.begin();
261 if (!head.getBdId().has_value())
262 return false;
263 headBdId = head.getBdId().value();
264 repeatCount = startOp.getRepeatCount();
265 return true;
266 }
267 return false;
268 };
269 for (MemOp mem : device.getOps<MemOp>())
270 if (mem.getTile() == tile.getResult())
271 return scanRegion(mem->getRegion(0));
272 for (MemTileDMAOp mem : device.getOps<MemTileDMAOp>())
273 if (mem.getTile() == tile.getResult())
274 return scanRegion(mem->getRegion(0));
275 return false;
276}
277
278// Populate each objectFIFO re-arm binding's head_bd_ids / repeat_counts now
279// that BD ids are assigned, so the later aiex.dma_channel_reset_for lowering
280// reads them straight off the binding instead of re-scanning the emitted chain.
281// A binding that already carries them (hand-authored) is left untouched; one
282// whose endpoints cannot all be resolved is left unpopulated for the lowering
283// to diagnose.
284static void populateRearmBindings(DeviceOp device) {
285 for (auto binding : device.getOps<ObjectFifoRearmBindingOp>()) {
286 if (binding.getHeadBdIds().has_value() ||
287 binding.getRepeatCounts().has_value())
288 continue;
289 ValueRange tiles = binding.getChannelTiles();
290 ArrayRef<int32_t> dirs = binding.getChannelDirs();
291 ArrayRef<int32_t> chans = binding.getChannelIndices();
292 SmallVector<int32_t> headBdIds, repeatCounts;
293 bool resolvedAll = true;
294 for (unsigned i = 0; i < tiles.size(); ++i) {
295 auto tileOp = tiles[i].getDefiningOp<TileOp>();
296 DMAChannelDir dir =
297 dirs[i] == 0 ? DMAChannelDir::S2MM : DMAChannelDir::MM2S;
298 uint32_t headBdId = 0;
299 int32_t repeatCount = 0;
300 if (!tileOp || !resolveResidentChannel(device, tileOp, dir, chans[i],
301 headBdId, repeatCount)) {
302 resolvedAll = false;
303 break;
304 }
305 headBdIds.push_back(static_cast<int32_t>(headBdId));
306 repeatCounts.push_back(repeatCount);
307 }
308 if (!resolvedAll)
309 continue;
310 OpBuilder b(binding);
311 binding.setHeadBdIdsAttr(b.getDenseI32ArrayAttr(headBdIds));
312 binding.setRepeatCountsAttr(b.getDenseI32ArrayAttr(repeatCounts));
313 }
314}
315
318 AIEAssignBufferDescriptorIDsPass> {
319 void runOnOperation() override {
320 DeviceOp targetOp = getOperation();
321 if (failed(verifyDMAChannelsResolved(targetOp)))
322 return signalPassFailure();
323 const AIETargetModel &targetModel = targetOp.getTargetModel();
324
325 auto memOps = llvm::to_vector_of<TileElement>(targetOp.getOps<MemOp>());
326 llvm::append_range(memOps, targetOp.getOps<MemTileDMAOp>());
327 llvm::append_range(memOps, targetOp.getOps<ShimDMAOp>());
328
329 // BD IDs are per-tile, but a tile can be described by more than one op
330 // here -- key the generator by tile, not by op, or two ops on the same
331 // tile hand out the same ids and silently collide.
332 std::map<std::pair<int, int>, BdIdGenerator> gens;
333 for (TileElement memOp : memOps) {
334 int col = memOp.getTileID().col;
335 int row = memOp.getTileID().row;
336
337 auto emplaced =
338 gens.try_emplace(std::make_pair(col, row), col, row, targetModel);
339 BdIdGenerator &gen = emplaced.first->second;
340 if (emplaced.second) {
341 for (TileOp tile : targetOp.getOps<TileOp>()) {
342 if (tile.getCol() != col || tile.getRow() != row)
343 continue;
344 for (const ReservedBdId &reserved : getReservedBdIds(tile)) {
345 auto id = static_cast<uint32_t>(reserved.id);
346 if (reserved.channel) {
347 auto [channel, dir] = *reserved.channel;
348 if (!gen.holdsTileWide(channel, dir, id)) {
349 if (!gen.bdIdAlreadyAssigned(channel, dir, id))
350 gen.assignBdId(channel, dir, id);
351 continue;
352 }
353 }
354 if (!gen.bdIdAlreadyAssigned(id))
355 gen.assignBdId(id);
356 }
357 }
358 }
359 }
360
361 struct Assignment {
362 DMABDOp bd;
363 int col, row, channel;
364 DMAChannelDir dir;
365 };
366 SmallVector<Assignment> assignments;
367 std::map<int32_t, SmallVector<size_t>> receiversOfTag;
368 for (TileElement memOp : memOps) {
369 DenseMap<Block *, std::pair<int, DMAChannelDir>> channels;
370 Region &region = memOp->getRegion(0);
371 for (Block &block : region)
372 for (auto start : block.getOps<DMAStartOp>()) {
373 Block *dest = start.getDest();
374 while (dest && !channels.contains(dest)) {
375 channels[dest] = {start.getChannelIndex(), start.getChannelDir()};
376 dest = dest->hasNoSuccessors() ? nullptr : dest->getSuccessor(0);
377 }
378 }
379 memOp->walk([&](DMABDOp bd) {
380 std::pair<int, DMAChannelDir> channel = {0, DMAChannelDir::MM2S};
381 if (auto dma = bd->getParentOfType<DMAOp>())
382 channel = {dma.getChannelIndex(), dma.getChannelDir()};
383 else if (auto it = channels.find(bd->getBlock()); it != channels.end())
384 channel = it->second;
385 if (auto tag = bd.getBdTag())
386 receiversOfTag[*tag].push_back(assignments.size());
387 assignments.push_back({bd, memOp.getTileID().col, memOp.getTileID().row,
388 channel.first, channel.second});
389 });
390 }
391
392 for (auto &a : assignments) {
393 std::optional<int32_t> id = a.bd.getBdId();
394 if (!id)
395 continue;
396 auto &gen = gens.at({a.col, a.row});
397 if (gen.bdIdAlreadyAssigned(a.channel, a.dir, *id)) {
398 a.bd.emitOpError() << "assigned bd_id " << *id
399 << " is already used by another BD on this tile";
400 return signalPassFailure();
401 }
402 gen.assignBdId(a.channel, a.dir, *id);
403 }
404
405 // Broadcast destinations must agree on a hardware ID. Reserve their
406 // common IDs before ordinary allocation can consume them on one tile.
407 for (auto &[tag, indices] : receiversOfTag) {
408 if (indices.size() < 2)
409 continue;
410 std::optional<uint32_t> fixed;
411 for (size_t i : indices) {
412 if (auto id = assignments[i].bd.getBdId()) {
413 if (fixed && *fixed != static_cast<uint32_t>(*id)) {
414 assignments[i].bd.emitOpError(
415 "broadcast receiving buffers must have matching bd_id values "
416 "for bd_tag ")
417 << tag;
418 return signalPassFailure();
419 }
420 fixed = id;
421 }
422 }
423 auto available = [&, &indices = indices](uint32_t id) {
424 std::set<std::pair<int, int>> tiles;
425 for (size_t i : indices) {
426 auto &a = assignments[i];
427 auto tile = std::make_pair(a.col, a.row);
428 if (!tiles.insert(tile).second ||
429 id >= targetModel.getNumBDs(a.col, a.row) ||
430 !targetModel.isBdChannelAccessible(a.col, a.row, id, a.channel,
431 a.dir) ||
432 (!a.bd.getBdId() &&
433 gens.at(tile).bdIdAlreadyAssigned(a.channel, a.dir, id)))
434 return false;
435 }
436 return true;
437 };
438 uint32_t id = fixed.value_or(0);
439 auto &first = assignments[indices.front()];
440 uint32_t limit = targetModel.getNumBDs(first.col, first.row);
441 if (!fixed)
442 while (id < limit && !available(id))
443 ++id;
444 if (id >= limit || !available(id)) {
445 first.bd.emitOpError("cannot allocate a common bd_id for broadcast "
446 "receiving buffers with bd_tag ")
447 << tag;
448 return signalPassFailure();
449 }
450 for (size_t i : indices) {
451 auto &a = assignments[i];
452 if (!a.bd.getBdId()) {
453 gens.at({a.col, a.row}).assignBdId(a.channel, a.dir, id);
454 a.bd.setBdId(id);
455 }
456 }
457 }
458 for (auto &a : assignments) {
459 auto &gen = gens.at({a.col, a.row});
460 if (auto id = a.bd.getBdId()) {
461 if (!targetModel.isBdChannelAccessible(a.col, a.row, *id, a.channel,
462 a.dir)) {
463 a.bd.emitOpError()
464 << "assigned bd_id " << *id << " is not accessible from channel "
465 << a.channel << " on this tile";
466 return signalPassFailure();
467 }
468 } else {
469 auto nextId = gen.nextBdId(a.channel, a.dir);
470 if (!nextId) {
471 a.bd.emitOpError()
472 << "Allocator exhausted available BD IDs (maximum "
473 << targetModel.getNumBDsForChannel(a.col, a.row, a.channel, a.dir)
474 << " available for channel " << a.channel << ").";
475 return signalPassFailure();
476 }
477 a.bd.setBdId(*nextId);
478 }
479 }
480 for (TileElement memOp : memOps) {
481 auto dmaOps = memOp.getOperation()->getRegion(0).getOps<DMAOp>();
482 if (!dmaOps.empty()) {
483 for (auto dmaOp : dmaOps) {
484 auto bdRegions = dmaOp.getBds();
485 for (auto *bdRegionIt = bdRegions.begin();
486 bdRegionIt != bdRegions.end();) {
487 auto &block = bdRegionIt->getBlocks().front();
488 DMABDOp bd = *block.getOps<DMABDOp>().begin();
489 std::optional<int> nextBdId;
490 if (++bdRegionIt != bdRegions.end())
491 nextBdId =
492 (*bdRegionIt->getBlocks().front().getOps<DMABDOp>().begin())
493 .getBdId();
494 else if (dmaOp.getLoop())
495 nextBdId = (*bdRegions.front()
496 .getBlocks()
497 .front()
498 .getOps<DMABDOp>()
499 .begin())
500 .getBdId();
501 bd.setNextBdId(nextBdId);
502 }
503 }
504 } else {
505 DenseMap<Block *, int> blockBdIdMap;
506 for (Block &block : memOp.getOperation()->getRegion(0)) {
507 if (block.getOps<DMABDOp>().empty())
508 continue;
509 DMABDOp bd = *block.getOps<DMABDOp>().begin();
510 auto bdId = bd.getBdId();
511 assert(bdId.has_value() &&
512 "DMABDOp should have bd_id assigned by now");
513 blockBdIdMap[&block] = *bdId;
514 }
515
516 for (Block &block : memOp.getOperation()->getRegion(0)) {
517 if (block.getOps<DMABDOp>().empty())
518 continue;
519 DMABDOp bd = *block.getOps<DMABDOp>().begin();
520 std::optional<int> nextBdId;
521 if (block.getNumSuccessors()) {
522 assert(llvm::range_size(block.getSuccessors()) == 1 &&
523 "should have only one successor block");
524 Block *nextBlock = block.getSuccessor(0);
525 if (blockBdIdMap.contains(nextBlock)) {
526 nextBdId = blockBdIdMap[nextBlock];
527 } else if (nextBlock->getOperations().size() != 1 ||
528 !isa<EndOp>(nextBlock->getOperations().front())) {
529 bd.emitOpError("must be followed by a block with a dma_bd or "
530 "by a block with only aie.end");
531 return signalPassFailure();
532 }
533 bd.setNextBdId(nextBdId);
534 }
535 }
536 }
537 }
538
539 if (failed(resolveOutOfOrderTags(targetOp)))
540 return signalPassFailure();
541 populateRearmBindings(targetOp);
542 }
543
544 /// Resolve BD tags after hardware ID assignment.
545 LogicalResult resolveOutOfOrderTags(DeviceOp device) {
546 DenseMap<int32_t, int> idOfTag;
547 DenseMap<std::pair<Value, int32_t>, int> localIdOfTag;
548 WalkResult receivers = device.walk([&](DMABDOp bd) {
549 std::optional<uint32_t> id = bd.getBdId();
550 if (std::optional<int32_t> tag = bd.getBdTag(); tag && id) {
551 auto tile = bd->getParentOfType<TileElement>();
552 if (tile)
553 localIdOfTag[{tile.getTile(), *tag}] = *id;
554 auto [it, inserted] = idOfTag.try_emplace(*tag, *id);
555 if (!inserted && it->second != static_cast<int>(*id)) {
556 bd.emitOpError("broadcast receiving buffers must have matching bd_id "
557 "values for bd_tag ")
558 << *tag;
559 return WalkResult::interrupt();
560 }
561 }
562 bd.removeBdTagAttr();
563 return WalkResult::advance();
564 });
565 if (receivers.wasInterrupted())
566 return failure();
567 WalkResult walked = device.walk([&](DMABDOp bd) {
568 std::optional<int32_t> tag = bd.getOutOfOrderTag();
569 if (!tag)
570 return WalkResult::advance();
571 auto it = idOfTag.find(*tag);
572 if (it == idOfTag.end()) {
573 bd.emitOpError("sends out of order into a descriptor that no "
574 "receiving tile holds");
575 return WalkResult::interrupt();
576 }
577 bd.setOutOfOrderId(it->second);
578 bd.removeOutOfOrderTagAttr();
579 return WalkResult::advance();
580 });
581 if (walked.wasInterrupted())
582 return failure();
583 walked = device.walk([&](DmaPushQueueOp push) {
584 std::optional<int32_t> tag = push.getBdTag();
585 if (!tag)
586 return WalkResult::advance();
587 Value tile = push->getParentOfType<CoreOp>().getTile();
588 auto it = localIdOfTag.find({tile, *tag});
589 if (it == localIdOfTag.end()) {
590 push.emitOpError("pushes a descriptor that this tile does not hold");
591 return WalkResult::interrupt();
592 }
593 push.setBdId(it->second);
594 push.removeBdTagAttr();
595 return WalkResult::advance();
596 });
597 return failure(walked.wasInterrupted());
598 }
599};
600
601std::unique_ptr<OperationPass<DeviceOp>>
603 return std::make_unique<AIEAssignBufferDescriptorIDsPass>();
604}
uint32_t getNumBDsForChannel(int col, int row, int channel, DMAChannelDir dir) const
bool isBdChannelAccessible(int col, int row, uint32_t bd_id, int channel, DMAChannelDir dir) const
virtual uint32_t getNumBDs(AIETileType tileType) const =0
Return the size of the BD id space of a tile type (see getTotalNumBDs()).
void setReservedBdIds(TileOp tile, llvm::ArrayRef< ReservedBdId > ids)
bool isReservedBdIdsAttr(llvm::StringRef name)
mlir::LogicalResult verifyDMAChannelsResolved(DeviceOp device)
std::unique_ptr< mlir::OperationPass< DeviceOp > > createAIEAssignBufferDescriptorIDsPass()
llvm::SmallVector< ReservedBdId > getReservedBdIds(TileOp tile)
WireBundle getDMAChannelBundle(DMAChannelDir dir)
The stream-switch bundle the channels of dir use.
Definition AIEEnums.h:29
LogicalResult resolveOutOfOrderTags(DeviceOp device)
Resolve BD tags after hardware ID assignment.
bool isReserved(int channelIndex, DMAChannelDir dir, uint32_t bdId) const
bool holdsTileWide(int channelIndex, DMAChannelDir dir, uint32_t bdId) const
const AIETargetModel & targetModel
std::set< std::pair< uint32_t, uint32_t > > alreadyAssigned
std::set< std::pair< uint32_t, uint32_t > > reserved
void reserveBdId(int channelIndex, DMAChannelDir dir, uint32_t bdId)
std::optional< uint32_t > nextBdId(int channelIndex, DMAChannelDir dir, uint32_t alignment=1)
void freeBdId(int channelIndex, DMAChannelDir dir, uint32_t bdId)
BdIdGenerator(int col, int row, const AIETargetModel &targetModel)
void assignBdId(int channelIndex, DMAChannelDir dir, uint32_t bdId)
bool bdIdAlreadyAssigned(int channelIndex, DMAChannelDir dir, uint32_t bdId)