14#include "mlir/Support/LogicalResult.h"
17#include "xaiengine/xaie_core.h"
18#include "xaiengine/xaie_dma.h"
19#include "xaiengine/xaie_elfloader.h"
20#include "xaiengine/xaie_interrupt.h"
21#include "xaiengine/xaie_locks.h"
22#include "xaiengine/xaie_mem.h"
23#include "xaiengine/xaie_perfcnt.h"
24#include "xaiengine/xaie_plif.h"
25#include "xaiengine/xaie_reset.h"
26#include "xaiengine/xaie_ss.h"
27#include "xaiengine/xaie_txn.h"
28#include "xaiengine/xaiegbl.h"
29#include "xaiengine/xaiegbl_defs.h"
34#define AIERC_STR(x) x, #x
35static const std::map<AieRC, std::string> AIERCTOSTR = {
61 {
AIERC_STR(XAIE_INSUFFICIENT_BUFFER_SIZE)},
65static const std::map<xilinx::AIE::WireBundle, StrmSwPortType>
66 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE = {
67 {xilinx::AIE::WireBundle::Core, StrmSwPortType::CORE},
68 {xilinx::AIE::WireBundle::DMA, StrmSwPortType::DMA},
69 {xilinx::AIE::WireBundle::TileControl, StrmSwPortType::CTRL},
70 {xilinx::AIE::WireBundle::FIFO, StrmSwPortType::FIFO},
71 {xilinx::AIE::WireBundle::South, StrmSwPortType::SOUTH},
72 {xilinx::AIE::WireBundle::West, StrmSwPortType::WEST},
73 {xilinx::AIE::WireBundle::North, StrmSwPortType::NORTH},
74 {xilinx::AIE::WireBundle::East, StrmSwPortType::EAST},
77 {xilinx::AIE::WireBundle::Trace, StrmSwPortType::TRACE},
86 return out << label <<
"=" << std::forward<H1>(value);
89template <
typename H1,
typename... T>
91 H1 &&value, T &&...rest) {
92 const char *pcomma = strchr(label,
',');
94 <<
"=" << std::forward<H1>(value) <<
',',
95 pcomma + 1, std::forward<T>(rest)...);
98llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const XAie_LocType &loc);
100llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const XAie_Lock &lock);
102llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const XAie_Packet &packet);
104#define SHOW_AIERT_ARGS(os, ...) showAIEXRTArgs(os, #__VA_ARGS__, __VA_ARGS__)
108static_assert(XAIE_OK == 0);
110#define TRY_XAIE_API_FATAL_ERROR(API, ...) \
112 LLVM_DEBUG(llvm::dbgs() << "trying XAIE API: " << #API << " with args: "); \
113 LLVM_DEBUG(SHOW_AIERT_ARGS(llvm::dbgs(), __VA_ARGS__)); \
114 LLVM_DEBUG(llvm::dbgs() << "\n"); \
115 if (auto r = API(__VA_ARGS__)) \
116 llvm::report_fatal_error(llvm::Twine(#API " failed with ") + \
120#define TRY_XAIE_API_EMIT_ERROR(OP, API, ...) \
122 LLVM_DEBUG(llvm::dbgs() << "trying XAIE API: " << #API << " with args: "); \
123 LLVM_DEBUG(SHOW_AIERT_ARGS(llvm::dbgs(), __VA_ARGS__)); \
124 LLVM_DEBUG(llvm::dbgs() << "\n"); \
125 if (auto r = API(__VA_ARGS__)) \
126 return OP.emitOpError() << #API " failed with " << AIERCTOSTR.at(r); \
129#define TRY_XAIE_API_LOGICAL_RESULT(API, ...) \
131 LLVM_DEBUG(llvm::dbgs() << "trying XAIE API: " << #API << " with args: "); \
132 LLVM_DEBUG(SHOW_AIERT_ARGS(llvm::dbgs(), __VA_ARGS__)); \
133 LLVM_DEBUG(llvm::dbgs() << "\n"); \
134 if (auto r = API(__VA_ARGS__)) { \
135 llvm::errs() << #API " failed with " << AIERCTOSTR.at(r); \
142#define TRY_XAIE_API_FATAL_ERROR(API, ...) \
144 if (auto r = API(__VA_ARGS__)) \
145 llvm::report_fatal_error(llvm::Twine(#API " failed with ") + \
149#define TRY_XAIE_API_EMIT_ERROR(OP, API, ...) \
151 if (auto r = API(__VA_ARGS__)) \
152 return OP.emitOpError() << #API " failed with " << AIERCTOSTR.at(r); \
155#define TRY_XAIE_API_LOGICAL_RESULT(API, ...) \
157 if (auto r = API(__VA_ARGS__)) { \
158 llvm::errs() << #API " failed with " << AIERCTOSTR.at(r); \
168#define DEBUG_TYPE "aie-aiert"
170llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const XAie_LocType &loc) {
171 os <<
"XAie_LocType(col: " << std::to_string(loc.Col)
172 <<
", row: " << std::to_string(loc.Row) <<
")";
176llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const XAie_Lock &lock) {
177 os <<
"XAie_Lock(id: " << std::to_string(lock.LockId)
178 <<
", val: " << std::to_string(lock.LockVal) <<
")";
183 const XAie_Packet &packet) {
184 os <<
"XAie_Packet(id: " << std::to_string(packet.PktId)
185 <<
", type: " << std::to_string(packet.PktType) <<
")";
189#define XAIE_BASE_ADDR 0x40000000
190#define XAIE_SHIM_ROW 0
191#define XAIE_MEM_TILE_ROW_START 1
192#define XAIE_PARTITION_BASE_ADDR 0x0
196#define EVEN_BD_NUM_START 0
197#define ODD_BD_NUM_START 24
207 : targetModel(tm), aiert(std::make_unique<
AIERtImpl>()) {
210 size_t partitionStartCol =
212 size_t partitionNumCols = tm.
columns();
213 size_t deviceRows = tm.
rows();
214 size_t deviceCols = tm.
columns() + partitionStartCol;
217 unsigned char devGen;
220 devGen = XAIE_DEV_GEN_AIE;
225 devGen = XAIE_DEV_GEN_AIE2IPU;
228 devGen = XAIE_DEV_GEN_AIE2P_STRIX_B0;
231 aiert->configPtr = XAie_Config{
236 static_cast<uint8_t
>(deviceRows),
237 static_cast<uint8_t
>(deviceCols),
246 XAIE_IO_BACKEND_CDO};
247 XAie_InstDeclare(_devInst, &aiert->configPtr);
248 aiert->devInst = _devInst;
265 XAIE_IO_BACKEND_SIM);
266 }
else if (xaieDebug)
268 XAIE_IO_BACKEND_DEBUG);
271 XAIE_IO_BACKEND_CDO);
276 XAie_DmaDesc &dmaTileBd, Block &block,
278 LLVM_DEBUG(llvm::dbgs() <<
"\nstart configuring bds\n");
279 std::optional<int> acqValue, relValue, acqLockId, relLockId;
284 for (
auto op : block.getOps<AIE::UseLockOp>()) {
289 lock = cast<AIE::LockOp>(op.getLock().getDefiningOp());
290 switch (op.getAction()) {
291 case AIE::LockAction::Acquire:
292 case AIE::LockAction::AcquireGreaterEqual:
293 acqEn = op.getAcqEn();
294 acqLockId = lock.getLockIDValue();
295 acqValue = op.getLockValue();
297 acqValue.value() = -acqValue.value();
299 case AIE::LockAction::Release:
300 relLockId = lock.getLockIDValue();
301 relValue = op.getLockValue();
306 assert(acqValue && relValue && acqLockId && relLockId &&
307 "expected both use_lock(acquire) and use_lock(release) with bd");
311 col,
row, lock.colIndex(), lock.rowIndex());
312 if (lockOffset && acqLockId)
313 acqLockId.value() += lockOffset.value();
314 if (lockOffset && relLockId)
315 relLockId.value() += lockOffset.value();
320 XAie_Lock acqLock = XAie_LockInit(acqLockId.value(), acqValue.value());
321 XAie_Lock relLock = XAie_LockInit(relLockId.value(), relValue.value());
323 dmaTileBd.DmaMod->SetLock, &dmaTileBd, acqLock,
324 relLock, acqEn, relEn);
329 XAie_DevInst *devInst, XAie_DmaDesc &dmaTileBd,
330 Block &block,
int col,
int row,
int bdId,
331 std::optional<int> nextBdId) {
332 std::optional<int> packetType;
333 std::optional<int> packetID;
336 auto maybePacketOps = block.getOps<AIE::DMABDPACKETOp>();
337 if (!maybePacketOps.empty()) {
338 assert(llvm::range_size(maybePacketOps) == 1 &&
339 "expected only one dma_bd_packet");
340 auto packetOp = *maybePacketOps.begin();
341 packetType = packetOp.getPacketType();
342 packetID = packetOp.getPacketID();
345 auto bdOp = *block.getOps<AIE::DMABDOp>().begin();
356 burstLen / 16, qOs, cache, secure);
360 uint64_t baseAddr = 0;
363 cast<AIE::ExternalBufferOp>(bdOp.getBuffer().getDefiningOp());
367 if (bufferOp.getAddress())
368 baseAddr = bufferOp.getAddress().value();
370 auto bufferOp = cast<AIE::BufferOp>(bdOp.getBuffer().getDefiningOp());
371 if (!bufferOp.getAddress())
372 return bufferOp.emitError(
"buffer must have address assigned");
373 baseAddr = bufferOp.getAddress().value();
379 auto bufferOp = cast<AIE::BufferOp>(bdOp.getBuffer().getDefiningOp());
380 auto bufferRow = bufferOp.getTileOp().getRow();
381 auto bufferCol = bufferOp.getTileOp().getCol();
385 baseAddr += addrOffset.value();
388 std::optional<llvm::ArrayRef<AIE::BDDimLayoutAttr>> dims =
389 bdOp.getDimensions();
390 uint64_t lenInBytes = bdOp.getLenInBytes();
391 uint64_t basePlusOffsetInBytes = baseAddr + bdOp.getOffsetInBytes();
394 basePlusOffsetInBytes, lenInBytes);
396 XAie_DmaTensor dmaTileBdTensor = {};
397 dmaTileBdTensor.NumDim = dims->size();
398 dmaTileBdTensor.Dim =
static_cast<XAie_DmaDimDesc *
>(
399 calloc(dmaTileBdTensor.NumDim,
sizeof(XAie_DmaDimDesc)));
400 if (!dmaTileBdTensor.Dim)
401 return bdOp.emitError(
"couldn't allocate array of XAie_DmaDimDesc");
403 double elementWidthIn32bWords =
404 static_cast<double>(bdOp.getBufferElementTypeWidthInBytes()) / 4.0;
405 for (
size_t i = 0; i < dims->size(); i++) {
409 int j = dims->size() - i - 1;
413 stride =
static_cast<uint32_t
>(dims.value()[i].getStride() *
414 elementWidthIn32bWords);
415 size = dims.value()[i].getSize();
417 stride = dims.value()[i].getStride();
418 size =
static_cast<uint16_t
>(dims.value()[i].getSize() *
419 elementWidthIn32bWords);
421 stride = stride > 0 ? stride : 1;
424 dmaTileBdTensor.Dim[j].AieMlDimDesc = {stride, size};
427 &dmaTileBdTensor, basePlusOffsetInBytes,
432 std::optional<llvm::ArrayRef<AIE::BDPadLayoutAttr>> padDims =
433 bdOp.getPadDimensions();
436 XAie_DmaPadTensor dmaPadTensor = {};
437 dmaPadTensor.NumDim = padDims->size();
438 dmaPadTensor.PadDesc =
static_cast<XAie_PadDesc *
>(
439 calloc(dmaPadTensor.NumDim,
sizeof(XAie_PadDesc)));
440 if (!dmaPadTensor.PadDesc)
441 return bdOp.emitError(
"couldn't allocate array of XAie_PadDesc");
443 double elementWidthIn32bWords =
444 static_cast<double>(bdOp.getBufferElementTypeWidthInBytes()) / 4.0;
445 for (
size_t i = 0; i < padDims->size(); i++) {
447 int j = padDims->size() - i - 1;
451 before =
static_cast<uint8_t
>(padDims.value()[i].getConstPadBefore());
452 after =
static_cast<uint8_t
>(padDims.value()[i].getConstPadAfter());
454 before =
static_cast<uint8_t
>(padDims.value()[i].getConstPadBefore() *
455 elementWidthIn32bWords);
456 after =
static_cast<uint8_t
>(padDims.value()[i].getConstPadAfter() *
457 elementWidthIn32bWords);
459 dmaPadTensor.PadDesc[j] = {before, after};
465 auto enableNextBd = 1;
467 nextBdId.value(), enableNextBd);
470 if (
auto packetInfo = bdOp.getPacket()) {
471 packetType = packetInfo->getPktType();
472 packetID = packetInfo->getPktId();
477 bdOp.emitError(
"must have packetType with packetID");
478 if (bdOp.getLen() == 0)
479 return bdOp.emitOpError(
480 "For MM2S channels, if Buffer_Length=0 then Enable_Packet must be "
481 "set to 0, otherwise behavior is undefined (3.7.8 arch spec)");
483 bdOp, XAie_DmaSetPkt, &dmaTileBd,
484 XAie_PacketInit(packetID.value(), packetType.value()));
487 auto tileLoc = XAie_TileLoc(
col,
row);
490 LLVM_DEBUG(llvm::dbgs() <<
"\nend configuring bds\n");
495 Operation &op,
int col,
int row,
int chNum,
const DMAChannelDir &channelDir,
496 int bdId,
int repeatCount) {
497 XAie_DmaDirection direction =
498 channelDir == DMAChannelDir::S2MM ? DMA_S2MM : DMA_MM2S;
499 auto tileLoc = XAie_TileLoc(
col,
row);
500 auto enTokenIssue = tileLoc.Row == 0 && direction == DMA_S2MM;
505 tileLoc, chNum, direction, bdId, repeatCount,
514 DMABDOp bd = *block.getOps<DMABDOp>().begin();
515 assert(bd.getBdId().has_value() &&
516 "DMABDOp must have assigned bd_id; did you forget to run "
517 "aie-assign-bd-ids?");
518 XAie_DmaDesc dmaTileBd;
519 auto tileLoc = XAie_TileLoc(
col,
row);
522 if (!block.getOps<UseLockOp>().empty() &&
525 if (!block.getOps<DMABDOp>().empty() &&
527 col,
row, bd.getBdId().value(),
534 for (
auto tileOp : targetOp.getOps<TileOp>()) {
535 auto tileLoc = XAie_TileLoc(tileOp.colIndex(), tileOp.rowIndex());
536 if (!tileOp.isShimTile() && tileOp.getCoreOp()) {
541 for (uint8_t l = 0; l <
NUM_LOCKS; l++) {
542 auto locInit = XAie_LockInit(l, 0);
550 targetOp.walk<WalkOrder::PreOrder>([&](LockOp lockOp) {
551 if (lockOp.getLockID() && lockOp.getInit()) {
552 auto tileLoc = XAie_TileLoc(lockOp.getTileOp().colIndex(),
553 lockOp.getTileOp().rowIndex());
554 auto locInit = XAie_LockInit(*lockOp.getLockID(), *lockOp.getInit());
558 LLVM_DEBUG(llvm::dbgs()
559 <<
"lock op missing either id or init" << lockOp <<
"\n");
566 targetOp.walk<WalkOrder::PreOrder>([&](BufferOp bufferOp) {
567 auto initialValue = bufferOp.getInitialValue();
570 mlir::DenseElementsAttr denseInit =
571 dyn_cast<mlir::DenseElementsAttr>(initialValue.value());
574 auto tileLoc = XAie_TileLoc(bufferOp.getTileOp().colIndex(),
575 bufferOp.getTileOp().rowIndex());
576 std::vector<char> byteVec;
577 if (denseInit.getElementType().isIntOrIndex()) {
578 for (
auto intVal : denseInit.getValues<APInt>()) {
580 size_t byteSize = (intVal.getBitWidth() + 7) / 8;
582 std::vector<char> bytes(byteSize);
584 static_cast<const char *
>(
static_cast<const void *
>(&intVal)),
585 static_cast<const char *
>(
static_cast<const void *
>(&intVal)) +
588 byteVec.insert(byteVec.end(), bytes.begin(), bytes.end());
590 }
else if (isa<FloatType>(denseInit.getElementType())) {
591 for (
auto floatVal : denseInit.getValues<APFloat>()) {
592 APInt floatInt = floatVal.bitcastToAPInt();
594 size_t byteSize = (floatInt.getBitWidth() + 7) / 8;
596 std::vector<char> bytes(byteSize);
598 static_cast<const char *
>(
static_cast<const void *
>(&floatInt)),
599 static_cast<const char *
>(
static_cast<const void *
>(&floatInt)) +
602 byteVec.insert(byteVec.end(), bytes.begin(), bytes.end());
605 llvm::outs() <<
"buffer op type not supported for initialization "
610 bufferOp.getAddress().value(), byteVec.data(),
619 for (
auto switchboxOp : targetOp.getOps<SwitchboxOp>()) {
620 int32_t
col = switchboxOp.colIndex();
621 int32_t
row = switchboxOp.rowIndex();
622 XAie_LocType tileLoc = XAie_TileLoc(
col,
row);
624 "Only NPU currently supported");
626 Block &b = switchboxOp.getConnections().front();
627 for (
auto connectOp : b.getOps<ConnectOp>())
629 switchboxOp, XAie_StrmConnCctEnable, &aiert->devInst, tileLoc,
630 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(connectOp.getSourceBundle()),
631 connectOp.sourceIndex(),
632 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(connectOp.getDestBundle()),
633 connectOp.destIndex());
635 for (
auto masterSetOp : b.getOps<MasterSetOp>()) {
639 for (
auto val : masterSetOp.getAmsels()) {
640 AMSelOp amsel = cast<AMSelOp>(val.getDefiningOp());
641 arbiter = amsel.arbiterIndex();
642 int msel = amsel.getMselValue();
647 bool keepHeader =
true;
649 if (masterSetOp.getDestBundle() == WireBundle::DMA)
653 if (switchboxOp.rowIndex() == 0 &&
654 masterSetOp.getDestBundle() == WireBundle::South)
658 if (
auto keep = masterSetOp.getKeepPktHeader())
662 keepHeader ? XAIE_SS_PKT_DONOT_DROP_HEADER : XAIE_SS_PKT_DROP_HEADER;
664 masterSetOp, XAie_StrmPktSwMstrPortEnable, &aiert->devInst, tileLoc,
665 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(masterSetOp.getDestBundle()),
666 masterSetOp.destIndex(), dropHeader, arbiter, mask);
669 for (
auto packetRulesOp : b.getOps<PacketRulesOp>()) {
671 Block &block = packetRulesOp.getRules().front();
672 for (
auto slotOp : block.getOps<PacketRuleOp>()) {
673 AMSelOp amselOp = cast<AMSelOp>(slotOp.getAmsel().getDefiningOp());
674 int arbiter = amselOp.arbiterIndex();
675 int msel = amselOp.getMselValue();
677 &aiert->devInst, tileLoc,
678 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(
679 packetRulesOp.getSourceBundle()),
680 packetRulesOp.sourceIndex());
681 auto packetInit = XAie_PacketInit(slotOp.valueInt(), 0);
684 &aiert->devInst, tileLoc,
685 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(
686 packetRulesOp.getSourceBundle()),
687 packetRulesOp.sourceIndex(), slot, packetInit,
688 slotOp.maskInt(), msel, arbiter);
694 for (
auto muxOp : targetOp.getOps<ShimMuxOp>()) {
698 XAie_TileLoc(muxOp.getTileOp().getCol(), muxOp.getTileOp().getRow());
699 Block &b = muxOp.getConnections().front();
700 for (
auto connectOp : b.getOps<ConnectOp>()) {
702 if (connectOp.getSourceBundle() == WireBundle::North)
704 &aiert->devInst, tileLoc,
705 connectOp.sourceIndex());
707 if (connectOp.getDestBundle() == WireBundle::North)
709 &aiert->devInst, tileLoc,
710 connectOp.destIndex());
714 for (
auto switchboxOp : targetOp.getOps<ShimSwitchboxOp>()) {
715 Block &b = switchboxOp.getConnections().front();
716 auto tileLoc = XAie_TileLoc(switchboxOp.getCol(), 0);
717 for (
auto connectOp : b.getOps<ConnectOp>())
719 switchboxOp, XAie_StrmConnCctEnable, &aiert->devInst, tileLoc,
720 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(connectOp.getSourceBundle()),
721 connectOp.sourceIndex(),
722 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(connectOp.getDestBundle()),
723 connectOp.destIndex());
727 if (isa<AIE2TargetModel>(targetModel)) {
728 for (
auto configOp : targetOp.getOps<ConfigureCascadeOp>()) {
729 TileOp tile = cast<TileOp>(configOp.getTile().getDefiningOp());
730 auto tileLoc = XAie_TileLoc(tile.getCol(), tile.getRow());
732 targetOp, XAie_CoreConfigAccumulatorControl, &aiert->devInst, tileLoc,
733 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(
734 static_cast<WireBundle
>(configOp.getInputDir())),
735 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(
736 static_cast<WireBundle
>(configOp.getOutputDir())));
745 if (failed(initLocks(targetOp))) {
749 if (failed(initBuffers(targetOp))) {
753 auto memOps = llvm::to_vector_of<TileElement>(targetOp.getOps<MemOp>());
754 llvm::append_range(memOps, targetOp.getOps<MemTileDMAOp>());
755 llvm::append_range(memOps, targetOp.getOps<ShimDMAOp>());
756 for (TileElement memOp : memOps) {
757 int col = memOp.getTileID().col;
758 int row = memOp.getTileID().row;
762 llvm::SetVector<Block *> blockVector =
766 auto dmaOps = llvm::to_vector_of<DMAOp>(
767 memOp.getOperation()->getRegion(0).getOps<DMAOp>());
768 if (!dmaOps.empty()) {
769 for (
auto dmaOp : dmaOps)
770 for (
auto &bdRegion : dmaOp.getBds()) {
771 Block &block = bdRegion.getBlocks().front();
772 if (failed(configureLocksAndBd(block,
col,
row)))
776 for (Block *block : blockVector) {
777 if (block->getOps<DMABDOp>().empty())
779 if (failed(configureLocksAndBd(*block,
col,
row)))
785 for (
auto dmaOp : dmaOps) {
786 auto &block = dmaOp.getBds().front().getBlocks().front();
787 DMABDOp bd = *block.getOps<DMABDOp>().begin();
788 if (failed(pushToBdQueueAndEnable(
789 *dmaOp.getOperation(),
col,
row, dmaOp.getChannelIndex(),
790 dmaOp.getChannelDir(), bd.getBdId().value(),
791 dmaOp.getRepeatCount())))
795 for (Block *block : blockVector) {
796 for (
auto op : block->getOps<DMAStartOp>()) {
797 DMABDOp bd = *op.getDest()->getOps<DMABDOp>().begin();
798 int chNum = op.getChannelIndex();
799 auto channelDir = op.getChannelDir();
800 if (failed(pushToBdQueueAndEnable(*bd.getOperation(),
col,
row, chNum,
801 channelDir, bd.getBdId().value(),
802 op.getRepeatCount())))
808 if (failed(configureSwitches(targetOp))) {
817 for (
auto tileOp : targetOp.getOps<TileOp>()) {
818 auto tileLoc = XAie_TileLoc(tileOp.colIndex(), tileOp.rowIndex());
819 if (!tileOp.isShimTile() && tileOp.getCoreOp())
827 const StringRef elfPath,
833 XAie_DmaChReset::DMA_CHANNEL_RESET);
838 XAie_TileLoc(
col,
row), elfPath.str().c_str(),
843 XAie_DmaChReset::DMA_CHANNEL_UNRESET);
854 auto tileLoc = XAie_TileLoc(
col,
row);
855 XAie_DmaDesc dmaTileBd;
860 on ? XAie_DmaChReset::DMA_CHANNEL_UNRESET
861 : XAie_DmaChReset::DMA_CHANNEL_RESET);
866 auto tileLoc = XAie_TileLoc(
col,
row);
872 XAie_LocType tileLoc = XAie_TileLoc(
col,
row);
875 for (
auto endpoint_a : WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE) {
876 for (
auto endpoint_b : WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE) {
877 unsigned n_a_connections = targetModel.getNumSourceSwitchboxConnections(
878 col,
row, endpoint_a.first);
879 unsigned n_b_connections = targetModel.getNumDestSwitchboxConnections(
880 col,
row, endpoint_b.first);
881 for (
unsigned a_index = 0; a_index < n_a_connections; a_index++) {
882 for (
unsigned b_index = 0; b_index < n_b_connections; b_index++) {
883 if (!targetModel.isLegalTileConnection(
col,
row, endpoint_a.first,
884 a_index, endpoint_b.first,
889 tileLoc, endpoint_a.second, a_index,
890 endpoint_b.second, b_index);
900 auto tileLoc = XAie_TileLoc(
col,
row);
907 auto tileLoc = XAie_TileLoc(
col,
row);
910 lock.LockId = lockId;
918 int col,
int row, WireBundle sourceBundle,
int sourceChannel,
919 WireBundle destBundle,
int destChannel) {
920 auto tileLoc = XAie_TileLoc(
col,
row);
923 auto mapBundle = [](WireBundle bundle) -> StrmSwPortType {
925 case WireBundle::Core:
927 case WireBundle::DMA:
929 case WireBundle::FIFO:
931 case WireBundle::South:
933 case WireBundle::West:
935 case WireBundle::North:
937 case WireBundle::East:
939 case WireBundle::Trace:
946 StrmSwPortType sourcePortType = mapBundle(sourceBundle);
947 StrmSwPortType destPortType = mapBundle(destBundle);
951 sourcePortType, sourceChannel, destPortType,
958 auto tileLoc = XAie_TileLoc(
col,
row);
961 for (
int counterId = 0; counterId < 4; counterId++) {
963 (void)XAie_PerfCounterReset(&aiert->devInst, tileLoc, XAIE_CORE_MOD,
967 for (
int counterId = 0; counterId < 4; counterId++) {
968 (void)XAie_PerfCounterReset(&aiert->devInst, tileLoc, XAIE_MEM_MOD,
972 for (
int counterId = 0; counterId < 4; counterId++) {
973 (void)XAie_PerfCounterReset(&aiert->devInst, tileLoc, XAIE_PL_MOD,
980 const StringRef elfPath,
982 for (
auto tileOp : targetOp.getOps<TileOp>())
983 if (tileOp.isShimNOCorPLTile()) {
986 int col = tileOp.colIndex();
987 int row = tileOp.rowIndex();
988 if (
auto coreOp = tileOp.getCoreOp()) {
989 std::string fileName;
990 if (
auto fileAttr = coreOp.getElfFile()) {
991 fileName = fileAttr->str();
999 std::string fullPath;
1000 if (std::filesystem::path(fileName).is_absolute()) {
1001 fullPath = fileName;
1003 auto ps = std::filesystem::path::preferred_separator;
1005 (llvm::Twine(elfPath) + std::string(1, ps) + fileName).str();
1007 if (failed(addAieElf(
col,
row, fullPath, aieSim)))
1016 auto tileLoc = XAie_TileLoc(
col,
row);
1023 XAIE_TRANSACTION_DISABLE_AUTO_FLUSH);
1028 uint8_t *txn_ptr = XAie_ExportSerializedTransaction(&aiert->devInst, 0, 0);
1029 XAie_TxnHeader *hdr = (XAie_TxnHeader *)txn_ptr;
1030 std::vector<uint8_t> txn_data(txn_ptr, txn_ptr + hdr->TxnSize);
llvm::raw_ostream & showAIEXRTArgs(llvm::raw_ostream &out, const char *label, H1 &&value)
LogicalResult configureLocksInBdBlock(const AIE::AIETargetModel &targetModel, XAie_DmaDesc &dmaTileBd, Block &block, int col, int row)
#define XAIE_PARTITION_BASE_ADDR
#define TRY_XAIE_API_LOGICAL_RESULT(API,...)
#define TRY_XAIE_API_FATAL_ERROR(API,...)
llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const XAie_LocType &loc)
#define TRY_XAIE_API_EMIT_ERROR(OP, API,...)
#define XAIE_MEM_TILE_ROW_START
LogicalResult configureBdInBlock(const AIE::AIETargetModel &targetModel, XAie_DevInst *devInst, XAie_DmaDesc &dmaTileBd, Block &block, int col, int row, int bdId, std::optional< int > nextBdId)
std::optional< uint32_t > getMemLocalBaseAddress(int localCol, int localRow, int memCol, int memRow) const
Return the memory base address (or offset) in the local tile when accessing a neighbor's memory or an...
virtual AIEArch getTargetArch() const =0
Return the target architecture.
bool isMemTile(int col, int row) const
Return true if the given tile is a Mem tile.
std::optional< uint32_t > getLockLocalBaseIndex(int localCol, int localRow, int lockCol, int lockRow) const
Return the lock base index (or offset) in the local tile when accessing a neighbor's lock or an empty...
virtual int rows() const =0
Return the number of rows in the device.
bool isShimNOCTile(int col, int row) const
Return true if the given tile is a ShimNOC tile.
virtual uint32_t getColumnShift() const =0
bool hasProperty(ModelProperty Prop) const
virtual int columns() const =0
Return the number of columns in the device.
virtual uint32_t getNumMemTileRows() const =0
virtual uint32_t getRowShift() const =0
uint32_t getShimBurstLengthBytes(const AIE::AIETargetModel &tm, uint32_t burstLength)
llvm::SetVector< mlir::Block * > getOrderedChainOfBlocks(mlir::Region *region)
mlir::LogicalResult resetPerfCounters(int col, int row)
mlir::LogicalResult resetCore(int col, int row)
mlir::LogicalResult pushToBdQueueAndEnable(mlir::Operation &op, int col, int row, int chNum, const DMAChannelDir &channelDir, int bdId, int repeatCount)
void dmaUpdateBdAddr(int col, int row, size_t addr, size_t bdId)
mlir::LogicalResult resetPartition()
mlir::LogicalResult addAieElfs(DeviceOp &targetOp, const mlir::StringRef workDirPath, bool aieSim)
mlir::LogicalResult resetCoreUnreset(int col, int row)
mlir::LogicalResult setIOBackend(bool aieSim, bool xaieDebug)
std::vector< uint8_t > exportSerializedTransaction()
AIERTControl(const xilinx::AIE::AIETargetModel &tm)
mlir::LogicalResult initLocks(DeviceOp &targetOp)
mlir::LogicalResult resetDMA(int col, int row, bool on)
mlir::LogicalResult configureSwitches(DeviceOp &targetOp)
mlir::LogicalResult initBuffers(DeviceOp &targetOp)
mlir::LogicalResult resetSwitch(int col, int row)
mlir::LogicalResult addCoreEnable(DeviceOp &targetOp)
mlir::LogicalResult resetSwitchConnection(int col, int row, WireBundle sourceBundle, int sourceChannel, WireBundle destBundle, int destChannel)
mlir::LogicalResult addAieElf(uint8_t col, uint8_t row, const mlir::StringRef elfPath, bool aieSim)
mlir::LogicalResult configureLocksAndBd(mlir::Block &block, int col, int row)
mlir::LogicalResult addInitConfig(DeviceOp &targetOp)
mlir::LogicalResult resetLock(int col, int row, int lockId)