MLIR-AIE 1.4.6.dev
AIERT.cpp
Go to the documentation of this file.
1//===- AIERT.cpp ------------------------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2024 Advanced Micro Devices, Inc.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7
8#include "aie/Targets/AIERT.h"
10
11#include "mlir/Dialect/Utils/StaticValueUtils.h"
12#include "mlir/Support/LogicalResult.h"
13#include "llvm/ADT/SmallPtrSet.h"
14#include "llvm/ADT/SmallSet.h"
15
16extern "C" {
17#include "aie_codegen.h"
18}
19
20#include <algorithm>
21#include <filesystem>
22
23#define AIERC_STR(x) x, #x
24static const std::map<AieRC, std::string> AIERCTOSTR = {
25 {AIERC_STR(XAIE_OK)},
26 {AIERC_STR(XAIE_ERR)},
27 {AIERC_STR(XAIE_INVALID_DEVICE)},
28 {AIERC_STR(XAIE_INVALID_RANGE)},
29 {AIERC_STR(XAIE_INVALID_ARGS)},
30 {AIERC_STR(XAIE_INVALID_TILE)},
31 {AIERC_STR(XAIE_ERR_STREAM_PORT)},
32 {AIERC_STR(XAIE_INVALID_DMA_TILE)},
33 {AIERC_STR(XAIE_INVALID_BD_NUM)},
34 {AIERC_STR(XAIE_ERR_OUTOFBOUND)},
35 {AIERC_STR(XAIE_INVALID_DATA_MEM_ADDR)},
36 {AIERC_STR(XAIE_INVALID_ELF)},
37 {AIERC_STR(XAIE_CORE_STATUS_TIMEOUT)},
38 {AIERC_STR(XAIE_INVALID_CHANNEL_NUM)},
39 {AIERC_STR(XAIE_INVALID_LOCK)},
40 {AIERC_STR(XAIE_INVALID_DMA_DIRECTION)},
41 {AIERC_STR(XAIE_INVALID_PLIF_WIDTH)},
42 {AIERC_STR(XAIE_INVALID_LOCK_ID)},
43 {AIERC_STR(XAIE_INVALID_LOCK_VALUE)},
44 {AIERC_STR(XAIE_LOCK_RESULT_FAILED)},
45 {AIERC_STR(XAIE_INVALID_DMA_DESC)},
46 {AIERC_STR(XAIE_INVALID_ADDRESS)},
47 {AIERC_STR(XAIE_FEATURE_NOT_SUPPORTED)},
48 {AIERC_STR(XAIE_INVALID_BURST_LENGTH)},
49 {AIERC_STR(XAIE_INVALID_BACKEND)},
50 {AIERC_STR(XAIE_INSUFFICIENT_BUFFER_SIZE)},
51 {AIERC_STR(XAIE_ERR_MAX)}};
52#undef AIERC_STR
53
54static const std::map<xilinx::AIE::WireBundle, StrmSwPortType>
55 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE = {
56 {xilinx::AIE::WireBundle::Core, StrmSwPortType::CORE},
57 {xilinx::AIE::WireBundle::DMA, StrmSwPortType::DMA},
58 {xilinx::AIE::WireBundle::TileControl, StrmSwPortType::CTRL},
59 {xilinx::AIE::WireBundle::FIFO, StrmSwPortType::FIFO},
60 {xilinx::AIE::WireBundle::South, StrmSwPortType::SOUTH},
61 {xilinx::AIE::WireBundle::West, StrmSwPortType::WEST},
62 {xilinx::AIE::WireBundle::North, StrmSwPortType::NORTH},
63 {xilinx::AIE::WireBundle::East, StrmSwPortType::EAST},
64 // missing PLIO from WireBundle
65 // missing NOC from WireBundle
66 {xilinx::AIE::WireBundle::Trace, StrmSwPortType::TRACE},
67 // AIE4 ports of the 512-bit switch.
68 {xilinx::AIE::WireBundle::DMATrace, StrmSwPortType::DMA_Trace},
69 {xilinx::AIE::WireBundle::DMAControl, StrmSwPortType::DMA_CTRL},
70 {xilinx::AIE::WireBundle::NorthControl, StrmSwPortType::NORTH_CTRL},
71 {xilinx::AIE::WireBundle::SouthControl, StrmSwPortType::SOUTH_CTRL},
72 {xilinx::AIE::WireBundle::Switch32, StrmSwPortType::SWITCH_32b},
73 // AIE4 ports of the 32-bit switch.
74 {xilinx::AIE::WireBundle::Control32, StrmSwPortType::_32B_CTRL},
75 {xilinx::AIE::WireBundle::Trace32, StrmSwPortType::_32B_TRACE},
76 {xilinx::AIE::WireBundle::South32, StrmSwPortType::_32B_SOUTH},
77 {xilinx::AIE::WireBundle::West32, StrmSwPortType::_32B_WEST},
78 {xilinx::AIE::WireBundle::North32, StrmSwPortType::_32B_NORTH},
79 {xilinx::AIE::WireBundle::East32, StrmSwPortType::_32B_EAST},
80 {xilinx::AIE::WireBundle::Switch512, StrmSwPortType::_32B_SWITCH_512b},
81 {xilinx::AIE::WireBundle::Controller32, StrmSwPortType::_32B_UCTRLR},
82 {xilinx::AIE::WireBundle::PLIO32, StrmSwPortType::_32B_PL},
83};
84
85static XAie_DmaDirection toXAieDmaDirection(xilinx::AIE::DMAChannelDir dir) {
86 switch (dir) {
87 case xilinx::AIE::DMAChannelDir::S2MM:
88 return DMA_S2MM;
89 case xilinx::AIE::DMAChannelDir::MM2S:
90 return DMA_MM2S;
91 case xilinx::AIE::DMAChannelDir::ControlMM2S:
92 return DMA_MM2S_CTRL;
93 case xilinx::AIE::DMAChannelDir::TraceS2MM:
94 return DMA_S2MM_TRACE;
95 }
96 llvm_unreachable("unknown DMAChannelDir");
97}
98
99#ifndef NDEBUG
100
101// https://stackoverflow.com/a/32230306
102template <typename H1>
103static llvm::raw_ostream &showAIEXRTArgs(llvm::raw_ostream &out,
104 const char *label, H1 &&value) {
105 return out << label << "=" << std::forward<H1>(value);
106}
107
108template <typename H1, typename... T>
109static llvm::raw_ostream &showAIEXRTArgs(llvm::raw_ostream &out,
110 const char *label, H1 &&value,
111 T &&...rest) {
112 const char *pcomma = strchr(label, ',');
113 return showAIEXRTArgs(out.write(label, pcomma - label)
114 << "=" << std::forward<H1>(value) << ',',
115 pcomma + 1, std::forward<T>(rest)...);
116}
117
118static llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
119 const XAie_LocType &loc);
120
121static llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
122 const XAie_Lock &lock);
123
124static llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
125 const XAie_Packet &packet);
126
127#define SHOW_AIERT_ARGS(os, ...) showAIEXRTArgs(os, #__VA_ARGS__, __VA_ARGS__)
128
129// So that we can use the pattern if(auto r = TRY_XAIE_API...) { // r is nonzero
130// }
131static_assert(XAIE_OK == 0);
132
133#define TRY_XAIE_API_FATAL_ERROR(API, ...) \
134 do { \
135 LLVM_DEBUG(llvm::dbgs() << "trying XAIE API: " << #API << " with args: "); \
136 LLVM_DEBUG(SHOW_AIERT_ARGS(llvm::dbgs(), __VA_ARGS__)); \
137 LLVM_DEBUG(llvm::dbgs() << "\n"); \
138 if (auto r = API(__VA_ARGS__)) \
139 llvm::report_fatal_error(llvm::Twine(#API " failed with ") + \
140 AIERCTOSTR.at(r)); \
141 } while (0)
142
143#define TRY_XAIE_API_EMIT_ERROR(OP, API, ...) \
144 do { \
145 LLVM_DEBUG(llvm::dbgs() << "trying XAIE API: " << #API << " with args: "); \
146 LLVM_DEBUG(SHOW_AIERT_ARGS(llvm::dbgs(), __VA_ARGS__)); \
147 LLVM_DEBUG(llvm::dbgs() << "\n"); \
148 if (auto r = API(__VA_ARGS__)) \
149 return OP.emitOpError() << #API " failed with " << AIERCTOSTR.at(r); \
150 } while (0)
151
152#define TRY_XAIE_API_LOGICAL_RESULT(API, ...) \
153 do { \
154 LLVM_DEBUG(llvm::dbgs() << "trying XAIE API: " << #API << " with args: "); \
155 LLVM_DEBUG(SHOW_AIERT_ARGS(llvm::dbgs(), __VA_ARGS__)); \
156 LLVM_DEBUG(llvm::dbgs() << "\n"); \
157 if (auto r = API(__VA_ARGS__)) { \
158 llvm::errs() << #API " failed with " << AIERCTOSTR.at(r); \
159 return failure(); \
160 } \
161 } while (0)
162
163#else
164
165#define TRY_XAIE_API_FATAL_ERROR(API, ...) \
166 do { \
167 if (auto r = API(__VA_ARGS__)) \
168 llvm::report_fatal_error(llvm::Twine(#API " failed with ") + \
169 AIERCTOSTR.at(r)); \
170 } while (0)
171
172#define TRY_XAIE_API_EMIT_ERROR(OP, API, ...) \
173 do { \
174 if (auto r = API(__VA_ARGS__)) \
175 return OP.emitOpError() << #API " failed with " << AIERCTOSTR.at(r); \
176 } while (0)
177
178#define TRY_XAIE_API_LOGICAL_RESULT(API, ...) \
179 do { \
180 if (auto r = API(__VA_ARGS__)) { \
181 llvm::errs() << #API " failed with " << AIERCTOSTR.at(r); \
182 return failure(); \
183 } \
184 } while (0)
185
186#endif
187
188using namespace mlir;
189using namespace xilinx;
190
191#define DEBUG_TYPE "aie-aiert"
192
193llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const XAie_LocType &loc) {
194 os << "XAie_LocType(col: " << std::to_string(loc.Col)
195 << ", row: " << std::to_string(loc.Row) << ")";
196 return os;
197}
198
199llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const XAie_Lock &lock) {
200 os << "XAie_Lock(id: " << std::to_string(lock.LockId)
201 << ", val: " << std::to_string(lock.LockVal) << ")";
202 return os;
203}
204
205llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
206 const XAie_Packet &packet) {
207 os << "XAie_Packet(id: " << std::to_string(packet.PktId)
208 << ", type: " << std::to_string(packet.PktType) << ")";
209 return os;
210}
211
212#define XAIE_BASE_ADDR 0x40000000
213#define XAIE_SHIM_ROW 0
214#define XAIE_MEM_TILE_ROW_START 1
215#define XAIE_PARTITION_BASE_ADDR 0x0
216
217#define NPI_ADDR 0x0
218#define NUM_LOCKS 16
219#define EVEN_BD_NUM_START 0
220#define ODD_BD_NUM_START 24
221
223 XAie_Config configPtr;
224 XAie_DevInst devInst;
225
226 // One Location per recorded XAie_TxnCmd, indexed by position in
227 // XAie_TxnInst::CmdBuf. Populated by TxnLocBracket scopes.
228 std::vector<mlir::Location> txnCmdLocs;
229
230 // One Location per operation in the exported transaction binary. Derived
231 // from txnCmdLocs by exportSerializedTransaction().
232 std::vector<mlir::Location> txnOpLocs;
233};
234
235// Walk DevInst->TxnList to find the active XAie_TxnInst (single-threaded
236// compilation: at most one). Returns null if no transaction is being
237// recorded. The XAie_TxnInst struct and TxnList layout are part of
238// aie-codegen's public xaiegbl.h, so this only depends on the public header.
239static XAie_TxnInst *getActiveTxnInst(XAie_DevInst &devInst) {
240 XAie_List *node = devInst.TxnList.Next;
241 if (!node)
242 return nullptr;
243 return reinterpret_cast<XAie_TxnInst *>(reinterpret_cast<char *>(node) -
244 offsetof(XAie_TxnInst, Node));
245}
246
247static uint32_t getActiveTxnNumCmds(XAie_DevInst &devInst) {
248 XAie_TxnInst *inst = getActiveTxnInst(devInst);
249 return inst ? inst->NumCmds : 0;
250}
251
253 : ctl(c), loc(l), startCmds(c.getCurrentTxnNumCmds()) {}
254
256 uint32_t endCmds = ctl.getCurrentTxnNumCmds();
257 if (endCmds <= startCmds)
258 return;
259 // Only record meaningful locations. Falling through (no entry) lets the
260 // downstream emitter use its fallback (device.getLoc()), which preserves
261 // the pre-existing behavior for source ops that don't carry a real loc.
262 if (mlir::isa<mlir::UnknownLoc>(loc))
263 return;
264 ctl.recordTxnLocRange(startCmds, endCmds, loc);
265}
266
267xilinx::AIE::AIERTControl::~AIERTControl() { XAie_Finish(&aiert->devInst); }
268
269LogicalResult xilinx::AIE::AIERTControl::isSupported(Operation *op,
270 const AIETargetModel &tm) {
271 if (isa<AIE4TargetModel>(tm))
272 return op->emitOpError("aie-codegen configuration is not yet supported "
273 "for the AIE4 architecture");
274 return success();
275}
276
278 : targetModel(tm), aiert(std::make_unique<AIERtImpl>()) {
279 // The first column in the NPU lacks a shim tile. AIE-RT exposes some of
280 // the internals about how this is modeled in a somewhat awkward way.
281 size_t partitionStartCol =
283 size_t partitionNumCols = tm.columns();
284 size_t deviceRows = tm.rows();
285 size_t deviceCols = tm.columns() + partitionStartCol;
286
287 // Don't put this in the target model, because it's XAIE specific.
288 unsigned char devGen = XAIE_DEV_GEN_AIE;
289 switch (tm.getTargetArch()) {
290 case AIEArch::AIE1: // probably unreachable.
291 devGen = XAIE_DEV_GEN_AIE;
292 break;
293 case AIEArch::AIE2:
294 // FIXME: What if we don't have an IPU? aie-codegen
295 // models non-IPU devices differently.
296 devGen = XAIE_DEV_GEN_AIE2IPU;
297 break;
298 case AIEArch::AIE2p:
299 devGen = XAIE_DEV_GEN_AIE2P_STRIX_B0;
300 break;
301 case AIEArch::AIE2ps:
302 // AIE2PS configures the array through a CERT ELF instead of CDO or an
303 // xclbin (see AIE2PSTargetModel), so it has no aie-codegen device
304 // generation. Listed here so that a new AIEArch still raises -Wswitch.
305 llvm::report_fatal_error(
306 "aie-codegen configuration is not supported for the "
307 "AIE2PS architecture");
308 case AIEArch::AIE4:
309 // Callers diagnose AIE4 first (see AIERTControl::isSupported).
310 llvm::report_fatal_error(
311 "aie-codegen configuration is not yet supported for the AIE4 "
312 "architecture");
313 }
314 aiert->configPtr = XAie_Config{
315 /*AieGen*/ devGen,
316 /*BaseAddr*/ XAIE_BASE_ADDR,
317 /*ColShift*/ static_cast<uint8_t>(tm.getColumnShift()),
318 /*RowShift*/ static_cast<uint8_t>(tm.getRowShift()),
319 /*NumRows*/ static_cast<uint8_t>(deviceRows),
320 /*NumCols*/ static_cast<uint8_t>(deviceCols),
321 /*ShimRowNum*/ XAIE_SHIM_ROW,
322 /*MemTileRowStart*/ XAIE_MEM_TILE_ROW_START,
323 /*MemTileNumRows*/ static_cast<uint8_t>(tm.getNumMemTileRows()),
324 /*AieTileRowStart*/
325 static_cast<uint8_t>(XAIE_MEM_TILE_ROW_START + tm.getNumMemTileRows()),
326 /*AieTileNumRows*/
327 static_cast<uint8_t>(tm.rows() - tm.getNumMemTileRows() - 1),
328 /*PartProp*/ {},
329 /*ShimTileNumRowsNorth*/ 0,
330 /*ShimTileNumRowsSouth*/ 0};
331 XAie_InstDeclare(_devInst, &aiert->configPtr);
332 aiert->devInst = _devInst;
333 TRY_XAIE_API_FATAL_ERROR(XAie_SetupPartitionConfig, &aiert->devInst,
334 XAIE_PARTITION_BASE_ADDR, partitionStartCol,
335 partitionNumCols);
336 TRY_XAIE_API_FATAL_ERROR(XAie_CfgInitialize, &aiert->devInst,
337 &aiert->configPtr);
338 TRY_XAIE_API_FATAL_ERROR(XAie_UpdateNpiAddr, &aiert->devInst, NPI_ADDR);
339}
340
342 bool xaieDebug) {
343 // Quoting: The instance of a device must be always declared using this
344 // macro. In the future, the same macro will be expanded to
345 // allocate more memory from the user application for resource
346 // management.
347 if (aieSim) {
348 TRY_XAIE_API_FATAL_ERROR(XAie_SetIOBackend, &aiert->devInst,
349 XAIE_IO_BACKEND_SIM);
350 } else if (xaieDebug)
351 TRY_XAIE_API_FATAL_ERROR(XAie_SetIOBackend, &aiert->devInst,
352 XAIE_IO_BACKEND_DEBUG);
353 else
354 TRY_XAIE_API_FATAL_ERROR(XAie_SetIOBackend, &aiert->devInst,
355 XAIE_IO_BACKEND_CDO);
356 return success();
357}
358
359static LogicalResult
360configureLocksInBdBlock(const AIE::AIETargetModel &targetModel,
361 XAie_DmaDesc &dmaTileBd, Block &block, int col, int row,
362 bool outOfOrder) {
363 LLVM_DEBUG(llvm::dbgs() << "\nstart configuring bds\n");
364 AIE::UseLockOp acquire, release;
365 if (failed(AIE::verifyBdLockPair(block, outOfOrder, acquire, release)))
366 return failure();
367 std::optional<int> acqValue, relValue, acqLockId, relLockId;
368 bool acqEn = false;
369
370 // A memtile BD may use locks of its neighbours, so each lock ID is offset
371 // by the base index of the tile that owns that lock.
372 auto lockIdFor = [&](AIE::LockOp lock) {
373 int id = lock.getLockIDValue();
374 if (targetModel.isMemTile(col, row))
375 if (auto offset = targetModel.getLockLocalBaseIndex(
376 col, row, lock.colIndex(), lock.rowIndex()))
377 id += *offset;
378 return id;
379 };
380 for (auto op : block.getOps<AIE::UseLockOp>()) {
381 auto lock = cast<AIE::LockOp>(op.getLock().getDefiningOp());
382 switch (op.getAction()) {
383 case AIE::LockAction::Acquire:
384 case AIE::LockAction::AcquireGreaterEqual: {
385 acqEn = op.getAcqEn();
386 acqLockId = lockIdFor(lock);
387 auto value = op.getConstantValue();
388 if (failed(value))
389 return failure();
390 int32_t v = *value; // NOLINT(bugprone-unchecked-optional-access)
391 if (op.acquireGE())
392 v = -v;
393 acqValue = v;
394 break;
395 }
396 case AIE::LockAction::Release: {
397 relLockId = lockIdFor(lock);
398 auto value = op.getConstantValue();
399 if (failed(value))
400 return failure();
401 relValue = value;
402 break;
403 }
404 }
405 }
406
407 // no RelEn in the arch spec even though the API requires you to set it?
408 bool relEn = false;
409 if (outOfOrder && !acqLockId) {
410 // Release-only out-of-order BD: point the disabled acquire lock at the
411 // release lock so XAie_LockInit gets a valid id.
412 acqLockId = relLockId;
413 acqValue = 0;
414 }
415 assert(acqLockId && acqValue && relLockId && relValue &&
416 "lock values must be resolved before init");
417 XAie_Lock acqLock = XAie_LockInit(acqLockId.value(), acqValue.value());
418 XAie_Lock relLock = XAie_LockInit(relLockId.value(), relValue.value());
419 TRY_XAIE_API_EMIT_ERROR((*block.getOps<AIE::UseLockOp>().begin()),
420 dmaTileBd.DmaMod->SetLock, &dmaTileBd, acqLock,
421 relLock, acqEn, relEn);
422 return success();
423}
424
425static LogicalResult configureBdInBlock(const AIE::AIETargetModel &targetModel,
426 XAie_DevInst *devInst,
427 XAie_DmaDesc &dmaTileBd, Block &block,
428 int col, int row, int bdId,
429 std::optional<int> nextBdId) {
430 std::optional<int> packetType;
431 std::optional<int> packetID;
432
433 // Below should go
434 auto maybePacketOps = block.getOps<AIE::DMABDPACKETOp>();
435 if (!maybePacketOps.empty()) {
436 assert(llvm::range_size(maybePacketOps) == 1 &&
437 "expected only one dma_bd_packet");
438 auto packetOp = *maybePacketOps.begin();
439 packetType = packetOp.getPacketType();
440 packetID = packetOp.getPacketID();
441 }
442
443 auto bdOp = *block.getOps<AIE::DMABDOp>().begin();
444
445 if (targetModel.isShimNOCTile(col, row)) {
446 // write them out like this so they show up with names in debug prints
447 uint8_t smid = 0;
448 uint32_t burstLen =
449 getShimBurstLengthBytes(targetModel, bdOp.getBurstLength());
450 uint8_t qOs = 0;
451 uint8_t cache = static_cast<uint8_t>(bdOp.getAxcacheOrDefault());
452 uint8_t secure = 0;
453 TRY_XAIE_API_EMIT_ERROR(bdOp, XAie_DmaSetAxi, &dmaTileBd, smid,
454 burstLen / 16, qOs, cache, secure);
455 }
456
457 // get address from BufferOp (core,mem) or ExternalBufferOp (shim)
458 uint64_t baseAddr = 0;
459 if (targetModel.isShimNOCTile(col, row)) {
460 auto bufferOp =
461 cast<AIE::ExternalBufferOp>(bdOp.getBuffer().getDefiningOp());
462 // external buffers aren't required to have an address here because the
463 // address might get patched later or the default of zero might be a valid
464 // address.
465 if (auto addr = bufferOp.getAddress())
466 baseAddr = *addr; // NOLINT(bugprone-unchecked-optional-access)
467 } else {
468 auto bufferOp = cast<AIE::BufferOp>(bdOp.getBuffer().getDefiningOp());
469 auto addr = bufferOp.getAddress();
470 if (!addr)
471 return bufferOp.emitError("buffer must have address assigned");
472 baseAddr = *addr; // NOLINT(bugprone-unchecked-optional-access)
473 }
474
475 if (targetModel.isMemTile(col, row)) {
476 // check if buffer is allocated on the same memtile, the west, or the east
477 // one
478 auto bufferOp = cast<AIE::BufferOp>(bdOp.getBuffer().getDefiningOp());
479 auto bufferRow = bufferOp.getTileOp().getRow();
480 auto bufferCol = bufferOp.getTileOp().getCol();
481 auto addrOffset =
482 targetModel.getMemLocalBaseAddress(col, row, bufferCol, bufferRow);
483 if (addrOffset)
484 baseAddr += addrOffset.value();
485 }
486
487 // Runtime-valued sizes/strides are not supported on this static lowering
488 // path.
489 for (mlir::OpFoldResult s : bdOp.getMixedSizes())
490 if (!mlir::getConstantIntValue(s))
491 return bdOp->emitOpError(
492 "runtime-valued BD size/stride is not supported on the static XAIE "
493 "lowering path; use compile-time constant sizes");
494 for (mlir::OpFoldResult s : bdOp.getMixedStrides())
495 if (!mlir::getConstantIntValue(s))
496 return bdOp->emitOpError(
497 "runtime-valued BD size/stride is not supported on the static XAIE "
498 "lowering path; use compile-time constant sizes");
499 // The owning storage must outlive the ArrayRef used below.
500 std::optional<llvm::SmallVector<AIE::BDDimLayoutAttr>> dimsStorage =
501 bdOp.getConstantDimensions();
502 if (!dimsStorage)
503 return bdOp->emitOpError("internal error folding BD dimensions");
504 std::optional<llvm::ArrayRef<AIE::BDDimLayoutAttr>> dims;
505 if (!dimsStorage->empty())
506 dims = llvm::ArrayRef<AIE::BDDimLayoutAttr>(*dimsStorage);
507 uint64_t lenInBytes = bdOp.getLenInBytes();
508 uint64_t basePlusOffsetInBytes = baseAddr + bdOp.getOffsetInBytes();
509 if (!dims) {
510 TRY_XAIE_API_EMIT_ERROR(bdOp, XAie_DmaSetAddrLen, &dmaTileBd,
511 basePlusOffsetInBytes, lenInBytes);
512 } else {
513 llvm::SmallVector<XAie_DmaDimDesc, 4> dimDescs(dims->size());
514 XAie_DmaTensor dmaTileBdTensor = {};
515 dmaTileBdTensor.NumDim = dimDescs.size();
516 dmaTileBdTensor.Dim = dimDescs.data();
517 // libxaie requires stride in multiples of 32b
518 double elementWidthIn32bWords =
519 static_cast<double>(bdOp.getBufferElementTypeWidthInBytes()) / 4.0;
520 for (size_t i = 0; i < dims->size(); i++) {
521 // Pass down dimensions in reverse order; in the MLIR, this allows
522 // us to specify step sizes/wraps in the same order as we would
523 // access a multi-dim C array, with the highest dimension first.
524 int j = dims->size() - i - 1;
525 uint16_t size;
526 uint32_t stride;
527 if (j > 0) {
528 stride = static_cast<uint32_t>(dims.value()[i].getStride() *
529 elementWidthIn32bWords);
530 size = dims.value()[i].getSize();
531 } else {
532 stride = dims.value()[i].getStride();
533 size = static_cast<uint16_t>(dims.value()[i].getSize() *
534 elementWidthIn32bWords);
535 }
536 stride = stride > 0 ? stride : 1;
537 // Assume AIE-ML architecture (ie use AieMlDimDesc instead of AieDimDesc);
538 // asserted in AIETranslateToCDODirect).
539 dmaTileBdTensor.Dim[j].AieMlDimDesc = {stride, size};
540 }
541 TRY_XAIE_API_EMIT_ERROR(bdOp, XAie_DmaSetMultiDimAddr, &dmaTileBd,
542 &dmaTileBdTensor, basePlusOffsetInBytes,
543 lenInBytes);
544 }
545
546 // BD iteration.
547 if (auto iter = bdOp.getIteration(); iter && iter->getSize() > 1) {
548 if (iter->getStride() > 0) {
549 double elementWidthIn32bWords =
550 static_cast<double>(bdOp.getBufferElementTypeWidthInBytes()) / 4.0;
551 uint32_t stepInWords =
552 static_cast<uint32_t>(iter->getStride() * elementWidthIn32bWords);
553 uint8_t wrap = static_cast<uint8_t>(iter->getSize());
554 uint8_t iterCurr = static_cast<uint8_t>(iter->getCurrent());
555 TRY_XAIE_API_EMIT_ERROR(bdOp, XAie_DmaSetBdIteration, &dmaTileBd,
556 stepInWords, wrap, iterCurr);
557 }
558 }
559
560 // ND zero padding.
561 std::optional<llvm::ArrayRef<AIE::BDPadLayoutAttr>> padDims =
562 bdOp.getPadDimensions();
563
564 if (padDims) {
565 // The verifier leaves the dims past the tile's pad fields unpadded.
566 llvm::SmallVector<XAie_PadDesc, 3> padDescs(
567 std::min(padDims->size(),
568 targetModel.getDmaBdLayout(col, row)->padFields().size()));
569 XAie_DmaPadTensor dmaPadTensor = {};
570 dmaPadTensor.NumDim = padDescs.size();
571 dmaPadTensor.PadDesc = padDescs.data();
572 // libxaie requires stride in multiples of 32b
573 double elementWidthIn32bWords =
574 static_cast<double>(bdOp.getBufferElementTypeWidthInBytes()) / 4.0;
575 for (size_t i = 0; i < padDims->size(); i++) {
576 // Pass down dimensions in reverse order.
577 int j = padDims->size() - i - 1;
578 if (j >= static_cast<int>(padDescs.size()))
579 continue;
580 uint8_t before;
581 uint8_t after;
582 if (j > 0) {
583 before = static_cast<uint8_t>(padDims.value()[i].getConstPadBefore());
584 after = static_cast<uint8_t>(padDims.value()[i].getConstPadAfter());
585 } else {
586 before = static_cast<uint8_t>(padDims.value()[i].getConstPadBefore() *
587 elementWidthIn32bWords);
588 after = static_cast<uint8_t>(padDims.value()[i].getConstPadAfter() *
589 elementWidthIn32bWords);
590 }
591 dmaPadTensor.PadDesc[j] = {before, after};
592 }
593 TRY_XAIE_API_EMIT_ERROR(bdOp, XAie_DmaSetPadding, &dmaTileBd,
594 &dmaPadTensor);
595 }
596 if (nextBdId) {
597 auto enableNextBd = 1;
598 TRY_XAIE_API_EMIT_ERROR(bdOp, XAie_DmaSetNextBd, &dmaTileBd,
599 nextBdId.value(), enableNextBd);
600 }
601
602 if (auto packetInfo = bdOp.getPacket()) {
603 packetType = packetInfo->getPktType();
604 packetID = packetInfo->assignedId();
605 }
606
607 if (packetID) {
608 if (!packetType)
609 return bdOp.emitError("must have packetType with packetID");
610 // getConstantLen() is nullopt for a runtime len operand, so this guard only
611 // catches a compile-time-zero length. A runtime len that happens to be 0 is
612 // not diagnosed here (runtime len is not yet reachable on this static
613 // path).
614 if (bdOp.getConstantLen() == 0)
615 return bdOp.emitOpError(
616 "For MM2S channels, if Buffer_Length=0 then Enable_Packet must be "
617 "set to 0, otherwise behavior is undefined (3.7.8 arch spec)");
618 TRY_XAIE_API_EMIT_ERROR(bdOp, XAie_DmaSetPkt, &dmaTileBd,
619 XAie_PacketInit(*packetID, *packetType));
620 }
621 if (std::optional<int32_t> oooId = bdOp.getOutOfOrderId())
622 TRY_XAIE_API_EMIT_ERROR(bdOp, XAie_DmaSetOutofOrderBdId, &dmaTileBd,
623 static_cast<uint8_t>(*oooId));
624 TRY_XAIE_API_EMIT_ERROR(bdOp, XAie_DmaEnableBd, &dmaTileBd);
625 auto tileLoc = XAie_TileLoc(col, row);
626 TRY_XAIE_API_EMIT_ERROR(bdOp, XAie_DmaWriteBd, devInst, &dmaTileBd, tileLoc,
627 bdId);
628 LLVM_DEBUG(llvm::dbgs() << "\nend configuring bds\n");
629 return success();
630};
631
633 Operation &op, int col, int row, int chNum, const DMAChannelDir &channelDir,
634 int bdId, int repeatCount, uint32_t padValue, bool outOfOrder,
635 bool configureChannel, bool pushTask) {
636 TxnLocBracket bracket(*this, op.getLoc());
637 XAie_DmaDirection direction = toXAieDmaDirection(channelDir);
638 auto tileLoc = XAie_TileLoc(col, row);
639 if (configureChannel && padValue != 0 && direction == DMA_MM2S &&
640 targetModel.isMemTile(col, row)) {
641 TRY_XAIE_API_EMIT_ERROR(op, XAie_DmaSetPadValue, &aiert->devInst, tileLoc,
642 static_cast<uint8_t>(chNum), padValue);
643 }
644 // in english repeat_count==0 means "do it once" and don't repeat but
645 // libxaie treats repeat_count=1 as do it once.
646 repeatCount += 1;
647 if (outOfOrder) {
648 if (configureChannel) {
649 XAie_DmaChannelDesc dmaChannelDesc;
650 TRY_XAIE_API_EMIT_ERROR(op, XAie_DmaChannelDescInit, &aiert->devInst,
651 &dmaChannelDesc, tileLoc);
652 TRY_XAIE_API_EMIT_ERROR(op, XAie_DmaChannelEnOutofOrder, &dmaChannelDesc,
653 static_cast<uint8_t>(XAIE_ENABLE));
654 TRY_XAIE_API_EMIT_ERROR(op, XAie_DmaWriteChannel, &aiert->devInst,
655 &dmaChannelDesc, tileLoc,
656 static_cast<uint8_t>(chNum), direction);
657 }
658 // StartBd=0 (ignored) and skip the BD/channel validity check.
659 // Disable TCT because the bd lookup id aliases the token bits.
660 XAie_DmaDeclareQueueConfig(startQueueCfg, /*StartBd=*/0, repeatCount,
661 /*EnToken=*/static_cast<uint8_t>(XAIE_DISABLE),
662 static_cast<uint8_t>(XAIE_ENABLE));
663 if (pushTask)
664 TRY_XAIE_API_EMIT_ERROR(op, XAie_DmaChannelSetStartQueueGeneric,
665 &aiert->devInst, tileLoc, chNum, direction,
666 &startQueueCfg);
667 } else if (pushTask) {
668 bool enTokenIssue = tileLoc.Row == 0 && direction == DMA_S2MM;
669 TRY_XAIE_API_EMIT_ERROR(op, XAie_DmaChannelSetStartQueue, &aiert->devInst,
670 tileLoc, chNum, direction, bdId, repeatCount,
671 enTokenIssue);
672 }
673 if (configureChannel)
674 TRY_XAIE_API_EMIT_ERROR(op, XAie_DmaChannelEnable, &aiert->devInst, tileLoc,
675 chNum, direction);
676 return success();
677};
678
680 int col, int row,
681 bool outOfOrder) {
682 DMABDOp bd = *block.getOps<DMABDOp>().begin();
683 auto bdId = bd.getBdId();
684 assert(bdId.has_value() &&
685 "DMABDOp must have assigned bd_id; did you forget to run "
686 "aie-assign-bd-ids?");
687 TxnLocBracket bracket(*this, bd.getLoc());
688 XAie_DmaDesc dmaTileBd;
689 auto tileLoc = XAie_TileLoc(col, row);
690 TRY_XAIE_API_EMIT_ERROR(bd, XAie_DmaDescInit, &aiert->devInst, &dmaTileBd,
691 tileLoc);
692 if (!block.getOps<UseLockOp>().empty() &&
693 failed(configureLocksInBdBlock(targetModel, dmaTileBd, block, col, row,
694 outOfOrder)))
695 return failure();
696 // Out-of-order ignores Use_Next_BD; the IR chain exists only so every
697 // receive BD gets configured.
698 std::optional<int> nextBdId =
699 outOfOrder ? std::optional<int>() : bd.getNextBdId();
700 if (!block.getOps<DMABDOp>().empty() &&
701 failed(configureBdInBlock(
702 targetModel, &aiert->devInst, dmaTileBd, block, col, row,
703 *bdId, // NOLINT(bugprone-unchecked-optional-access)
704 nextBdId)))
705 return failure();
706 return success();
707}
708
709LogicalResult xilinx::AIE::AIERTControl::initLocks(DeviceOp &targetOp) {
710 for (auto tileOp : targetOp.getOps<TileOp>()) {
711 auto tileLoc = XAie_TileLoc(tileOp.colIndex(), tileOp.rowIndex());
712 if (!tileOp.isShimTile() && tileOp.getCoreOp()) {
713 TxnLocBracket bracket(*this, tileOp.getLoc());
714 TRY_XAIE_API_EMIT_ERROR(tileOp, XAie_CoreReset, &aiert->devInst, tileLoc);
715 TRY_XAIE_API_EMIT_ERROR(tileOp, XAie_CoreUnreset, &aiert->devInst,
716 tileLoc);
717 // Set locks to zero
718 for (uint8_t l = 0; l < NUM_LOCKS; l++) {
719 auto locInit = XAie_LockInit(l, 0);
720 TRY_XAIE_API_EMIT_ERROR(tileOp, XAie_LockSetValue, &aiert->devInst,
721 tileLoc, locInit);
722 }
723 }
724 }
725
726 // Set locks with explicit initializers
727 targetOp.walkOutsideRuntimeSequences<LockOp>([&](LockOp lockOp) {
728 if (lockOp.getLockID() && lockOp.getInit()) {
729 TxnLocBracket bracket(*this, lockOp.getLoc());
730 auto tileLoc = XAie_TileLoc(lockOp.getTileOp().colIndex(),
731 lockOp.getTileOp().rowIndex());
732 auto locInit = XAie_LockInit(*lockOp.getLockID(), *lockOp.getInit());
733 TRY_XAIE_API_FATAL_ERROR(XAie_LockSetValue, &aiert->devInst, tileLoc,
734 locInit);
735 } else
736 LLVM_DEBUG(llvm::dbgs()
737 << "lock op missing either id or init" << lockOp << "\n");
738 });
739 return success();
740}
741
742LogicalResult xilinx::AIE::AIERTControl::initBuffers(DeviceOp &targetOp) {
743 // Set buffers with explicit initializers
744 targetOp.walkOutsideRuntimeSequences<BufferOp>([&](BufferOp bufferOp) {
745 auto initialValue = bufferOp.getInitialValue();
746 if (!initialValue)
747 return;
748 TxnLocBracket bracket(*this, bufferOp.getLoc());
749 mlir::DenseElementsAttr denseInit =
750 dyn_cast<mlir::DenseElementsAttr>(initialValue.value());
751 if (!denseInit)
752 return;
753 auto tileLoc = XAie_TileLoc(bufferOp.getTileOp().colIndex(),
754 bufferOp.getTileOp().rowIndex());
755 std::optional<std::vector<char>> byteVec = denseAttrToBytes(denseInit);
756 if (!byteVec) {
757 llvm::outs() << "buffer op type not supported for initialization "
758 << bufferOp << "\n";
759 return;
760 }
761 TRY_XAIE_API_FATAL_ERROR(XAie_DataMemBlockWrite, &aiert->devInst, tileLoc,
762 bufferOp.getAddress().value(), byteVec->data(),
763 byteVec->size());
764 });
765 return success();
766}
767
768LogicalResult
770 bool skipCtrlPktOverlay) {
771 AIEDialect::IsCtrlPktOverlayAttrHelper overlay(targetOp.getContext());
772
773 // StreamSwitch (switchbox) configuration
774 for (auto switchboxOp : targetOp.getOps<SwitchboxOp>()) {
775 int32_t col = switchboxOp.colIndex();
776 int32_t row = switchboxOp.rowIndex();
777 XAie_LocType tileLoc = XAie_TileLoc(col, row);
778 assert(targetModel.hasProperty(AIETargetModel::IsNPU) &&
779 "Only NPU currently supported");
780
781 Block &b = switchboxOp.getConnections().front();
782 for (auto connectOp : b.getOps<ConnectOp>()) {
783 if (skipCtrlPktOverlay && overlay.isAttrPresent(connectOp))
784 continue;
785 TxnLocBracket bracket(*this, connectOp.getLoc());
787 switchboxOp, XAie_StrmConnCctEnable, &aiert->devInst, tileLoc,
788 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(connectOp.getSourceBundle()),
789 connectOp.sourceIndex(),
790 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(connectOp.getDestBundle()),
791 connectOp.destIndex());
792 }
793
794 for (auto masterSetOp : b.getOps<MasterSetOp>()) {
795 if (skipCtrlPktOverlay && overlay.isAttrPresent(masterSetOp))
796 continue;
797 TxnLocBracket bracket(*this, masterSetOp.getLoc());
798 int mask = 0;
799 int arbiter = -1;
800
801 // MasterSetOp::verify guarantees every amsel names the same arbiter, so
802 // folding them into one arbiter plus msel mask is safe here.
803 for (auto val : masterSetOp.getAmsels()) {
804 AMSelOp amsel = cast<AMSelOp>(val.getDefiningOp());
805 arbiter = amsel.arbiterIndex();
806 int msel = amsel.getMselValue();
807 mask |= (1 << msel);
808 }
809
810 auto dropHeader = masterSetOp.keepsPktHeader()
811 ? XAIE_SS_PKT_DONOT_DROP_HEADER
812 : XAIE_SS_PKT_DROP_HEADER;
814 masterSetOp, XAie_StrmPktSwMstrPortEnable, &aiert->devInst, tileLoc,
815 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(masterSetOp.getDestBundle()),
816 masterSetOp.destIndex(), dropHeader, arbiter, mask);
817 }
818
819 for (auto packetRulesOp : b.getOps<PacketRulesOp>()) {
820 if (skipCtrlPktOverlay && overlay.isAttrPresent(packetRulesOp))
821 continue;
822 TxnLocBracket bracket(*this, packetRulesOp.getLoc());
823 int slot = 0;
824 Block &block = packetRulesOp.getRules().front();
825 // The overlay's rules take the first slots of a port they share with the
826 // design's rules, and the overlay already enabled the port.
827 bool overlayPort =
828 skipCtrlPktOverlay &&
829 llvm::any_of(block.getOps<PacketRuleOp>(), [&](PacketRuleOp rule) {
830 return overlay.isAttrPresent(rule);
831 });
832 for (auto slotOp : block.getOps<PacketRuleOp>()) {
833 if (skipCtrlPktOverlay && overlay.isAttrPresent(slotOp)) {
834 slot++;
835 continue;
836 }
837 AMSelOp amselOp = cast<AMSelOp>(slotOp.getAmsel().getDefiningOp());
838 int arbiter = amselOp.arbiterIndex();
839 int msel = amselOp.getMselValue();
840 if (!overlayPort)
841 TRY_XAIE_API_EMIT_ERROR(packetRulesOp, XAie_StrmPktSwSlavePortEnable,
842 &aiert->devInst, tileLoc,
843 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(
844 packetRulesOp.getSourceBundle()),
845 packetRulesOp.sourceIndex());
846 auto packetInit = XAie_PacketInit(slotOp.valueInt(), /*PktType*/ 0);
847 // TODO Need to better define packet id,type used here
848 TRY_XAIE_API_EMIT_ERROR(packetRulesOp, XAie_StrmPktSwSlaveSlotEnable,
849 &aiert->devInst, tileLoc,
850 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(
851 packetRulesOp.getSourceBundle()),
852 packetRulesOp.sourceIndex(), slot, packetInit,
853 slotOp.maskInt(), msel, arbiter);
854 slot++;
855 }
856 }
857 }
858
859 for (auto muxOp : targetOp.getOps<ShimMuxOp>()) {
860 // NOTE ShimMux always connects from the south as directions are
861 // defined relative to the tile stream switch.
862 auto tileLoc =
863 XAie_TileLoc(muxOp.getTileOp().getCol(), muxOp.getTileOp().getRow());
864 Block &b = muxOp.getConnections().front();
865 for (auto connectOp : b.getOps<ConnectOp>()) {
866 if (skipCtrlPktOverlay && overlay.isAttrPresent(connectOp))
867 continue;
868 TxnLocBracket bracket(*this, connectOp.getLoc());
869 // demux!
870 if (connectOp.getSourceBundle() == WireBundle::North)
871 TRY_XAIE_API_EMIT_ERROR(muxOp, XAie_EnableAieToShimDmaStrmPort,
872 &aiert->devInst, tileLoc,
873 connectOp.sourceIndex());
874 // mux
875 if (connectOp.getDestBundle() == WireBundle::North)
876 TRY_XAIE_API_EMIT_ERROR(muxOp, XAie_EnableShimDmaToAieStrmPort,
877 &aiert->devInst, tileLoc,
878 connectOp.destIndex());
879 }
880 }
881
882 // Cascade configuration
883 if (isa<AIE2TargetModel>(targetModel)) {
884 for (auto configOp : targetOp.getOps<ConfigureCascadeOp>()) {
885 TxnLocBracket bracket(*this, configOp.getLoc());
886 TileOp tile = cast<TileOp>(configOp.getTile().getDefiningOp());
887 auto tileLoc = XAie_TileLoc(tile.getCol(), tile.getRow());
889 targetOp, XAie_CoreConfigAccumulatorControl, &aiert->devInst, tileLoc,
890 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(
891 static_cast<WireBundle>(configOp.getInputDir())),
892 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(
893 static_cast<WireBundle>(configOp.getOutputDir())));
894 }
895 }
896
897 return success();
898}
899
900LogicalResult
902 bool skipCtrlPktOverlay) {
903 AIEDialect::IsCtrlPktOverlayAttrHelper overlay(targetOp.getContext());
904 auto skip = [&](Operation *op) {
905 return skipCtrlPktOverlay && overlay.isAttrPresent(op);
906 };
907 for (auto switchboxOp : targetOp.getOps<SwitchboxOp>()) {
908 XAie_LocType tileLoc =
909 XAie_TileLoc(switchboxOp.colIndex(), switchboxOp.rowIndex());
910 Block &b = switchboxOp.getConnections().front();
911 for (auto connectOp : b.getOps<ConnectOp>()) {
912 if (skip(connectOp))
913 continue;
914 TxnLocBracket bracket(*this, connectOp.getLoc());
916 switchboxOp, XAie_StrmConnCctDisable, &aiert->devInst, tileLoc,
917 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(connectOp.getSourceBundle()),
918 connectOp.sourceIndex(),
919 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(connectOp.getDestBundle()),
920 connectOp.destIndex());
921 }
922 for (auto masterSetOp : b.getOps<MasterSetOp>()) {
923 if (skip(masterSetOp))
924 continue;
925 TxnLocBracket bracket(*this, masterSetOp.getLoc());
927 masterSetOp, XAie_StrmPktSwMstrPortDisable, &aiert->devInst, tileLoc,
928 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(masterSetOp.getDestBundle()),
929 masterSetOp.destIndex());
930 }
931 for (auto packetRulesOp : b.getOps<PacketRulesOp>()) {
932 auto rules = packetRulesOp.getRules().front().getOps<PacketRuleOp>();
933 if (rules.empty() || skip(packetRulesOp))
934 continue;
935 TxnLocBracket bracket(*this, packetRulesOp.getLoc());
936 StrmSwPortType port =
937 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE.at(packetRulesOp.getSourceBundle());
938 if (llvm::none_of(rules, skip))
939 TRY_XAIE_API_EMIT_ERROR(packetRulesOp, XAie_StrmPktSwSlavePortDisable,
940 &aiert->devInst, tileLoc, port,
941 packetRulesOp.sourceIndex());
942 // A slot stays enabled when its port is disabled.
943 for (auto [slot, rule] : llvm::enumerate(rules))
944 if (!skip(rule))
945 TRY_XAIE_API_EMIT_ERROR(packetRulesOp, XAie_StrmPktSwSlaveSlotDisable,
946 &aiert->devInst, tileLoc, port,
947 packetRulesOp.sourceIndex(), slot);
948 }
949 }
950 return success();
951}
952
953LogicalResult xilinx::AIE::AIERTControl::disableCores(DeviceOp &targetOp) {
954 for (auto coreOp : targetOp.getOps<CoreOp>()) {
955 TileID tile = coreOp.getTileID();
956 TxnLocBracket bracket(*this, coreOp.getLoc());
957 TRY_XAIE_API_EMIT_ERROR(coreOp, XAie_CoreDisable, &aiert->devInst,
958 XAie_TileLoc(tile.col, tile.row));
959 }
960 return success();
961}
962
963LogicalResult xilinx::AIE::AIERTControl::resetDmaChannels(DeviceOp &targetOp) {
964 auto memOps = llvm::to_vector_of<TileElement>(targetOp.getOps<MemOp>());
965 llvm::append_range(memOps, targetOp.getOps<MemTileDMAOp>());
966 for (TileElement memOp : memOps) {
967 TileID tile = memOp.getTileID();
968 XAie_LocType tileLoc = XAie_TileLoc(tile.col, tile.row);
969 llvm::SmallSet<std::pair<DMAChannelDir, int>, 4> reset;
970 auto resetChannel = [&](Operation *op, DMAChannelDir dir,
971 int channel) -> LogicalResult {
972 if (!reset.insert({dir, channel}).second)
973 return success();
974 TxnLocBracket bracket(*this, op->getLoc());
975 XAie_DmaDirection direction = toXAieDmaDirection(dir);
976 TRY_XAIE_API_EMIT_ERROR((*op), XAie_DmaChannelReset, &aiert->devInst,
977 tileLoc, channel, direction,
978 XAie_DmaChReset::DMA_CHANNEL_RESET);
979 // Writing a fresh descriptor ends the reset and returns every field of
980 // the control register, such as out-of-order mode, to its reset value.
981 XAie_DmaChannelDesc defaults;
982 TRY_XAIE_API_EMIT_ERROR((*op), XAie_DmaChannelDescInit, &aiert->devInst,
983 &defaults, tileLoc);
984 TRY_XAIE_API_EMIT_ERROR((*op), XAie_DmaWriteChannel, &aiert->devInst,
985 &defaults, tileLoc, channel, direction);
986 return success();
987 };
988 Region &region = memOp.getOperation()->getRegion(0);
989 for (auto dmaOp : region.getOps<DMAOp>())
990 if (failed(resetChannel(dmaOp, dmaOp.getChannelDir(),
991 dmaOp.getChannelIndex())))
992 return failure();
993 for (Block *block : getOrderedChainOfBlocks(&region))
994 for (auto startOp : block->getOps<DMAStartOp>())
995 if (failed(resetChannel(startOp, startOp.getChannelDir(),
996 startOp.getChannelIndex())))
997 return failure();
998 }
999 return success();
1000}
1001
1002LogicalResult
1004 bool skipCtrlPktOverlay) {
1005
1006 if (failed(verifyDMAChannelsResolved(targetOp)))
1007 return failure();
1008
1009 if (failed(initLocks(targetOp))) {
1010 return failure();
1011 }
1012
1013 if (failed(initBuffers(targetOp))) {
1014 return failure();
1015 }
1016
1017 // A DMA whose lock is already satisfied streams as soon as it is enabled, so
1018 // its route must exist first.
1019 if (failed(configureSwitches(targetOp, skipCtrlPktOverlay))) {
1020 return failure();
1021 }
1022
1023 auto memOps = llvm::to_vector_of<TileElement>(targetOp.getOps<MemOp>());
1024 llvm::append_range(memOps, targetOp.getOps<MemTileDMAOp>());
1025 llvm::append_range(memOps, targetOp.getOps<ShimDMAOp>());
1026 for (TileElement memOp : memOps) {
1027 int col = memOp.getTileID().col;
1028 int row = memOp.getTileID().row;
1029
1030 // Get the region's entry block, then start traversing through the chain of
1031 // blocks.
1032 llvm::SetVector<Block *> blockVector =
1033 getOrderedChainOfBlocks(&memOp.getOperation()->getRegion(0));
1034
1035 llvm::SmallPtrSet<Block *, 8> unchainedBlocks =
1036 collectUnchainedBlocks(blockVector);
1037
1038 // handle DMA ops separately
1039 auto dmaOps = llvm::to_vector_of<DMAOp>(
1040 memOp.getOperation()->getRegion(0).getOps<DMAOp>());
1041 if (!dmaOps.empty()) {
1042 for (auto dmaOp : dmaOps)
1043 for (auto &bdRegion : dmaOp.getBds()) {
1044 Block &block = bdRegion.getBlocks().front();
1045 if (failed(
1046 configureLocksAndBd(block, col, row, dmaOp.getOutOfOrder())))
1047 return failure();
1048 }
1049 } else {
1050 for (Block *block : blockVector) {
1051 if (block->getOps<DMABDOp>().empty())
1052 continue;
1053 if (failed(configureLocksAndBd(*block, col, row,
1054 unchainedBlocks.contains(block))))
1055 return failure();
1056 }
1057 }
1058 }
1059 return success();
1060}
1061
1062LogicalResult xilinx::AIE::AIERTControl::addDmaActivation(DeviceOp &targetOp) {
1063 auto memOps = llvm::to_vector_of<TileElement>(targetOp.getOps<MemOp>());
1064 llvm::append_range(memOps, targetOp.getOps<MemTileDMAOp>());
1065 llvm::append_range(memOps, targetOp.getOps<ShimDMAOp>());
1066 for (TileElement memOp : memOps) {
1067 int col = memOp.getTileID().col;
1068 int row = memOp.getTileID().row;
1069 auto dmaOps = memOp.getOperation()->getRegion(0).getOps<DMAOp>();
1070 if (!dmaOps.empty()) {
1071 for (auto dmaOp : dmaOps) {
1072 DMABDOp bd = *dmaOp.getBds().front().front().getOps<DMABDOp>().begin();
1073 auto bdId = bd.getBdId();
1074 if (!bdId)
1075 return bd.emitOpError("requires a BD ID before DMA activation");
1076 if (failed(pushToBdQueueAndEnable(
1077 *dmaOp.getOperation(), col, row, dmaOp.getChannelIndex(),
1078 dmaOp.getChannelDir(), *bdId, dmaOp.getRepeatCount(),
1079 dmaOp.getPadValue(), dmaOp.getOutOfOrder())))
1080 return failure();
1081 }
1082 } else {
1083 for (Block *block :
1084 getOrderedChainOfBlocks(&memOp.getOperation()->getRegion(0))) {
1085 for (auto op : block->getOps<DMAStartOp>()) {
1086 DMABDOp bd = *op.getDest()->getOps<DMABDOp>().begin();
1087 auto bdId = bd.getBdId();
1088 if (!bdId)
1089 return bd.emitOpError("requires a BD ID before DMA activation");
1090 if (failed(pushToBdQueueAndEnable(
1091 *bd.getOperation(), col, row, op.getChannelIndex(),
1092 op.getChannelDir(), *bdId, op.getRepeatCount(),
1093 op.getPadValue(), op.getOutOfOrder(),
1094 /*configureChannel=*/true, /*pushTask=*/!op.getCorePushes())))
1095 return failure();
1096 }
1097 }
1098 }
1099 }
1100 return success();
1101}
1102
1103LogicalResult xilinx::AIE::AIERTControl::addCoreEnable(DeviceOp &targetOp) {
1104 // Start execution of all the cores.
1105 for (auto tileOp : targetOp.getOps<TileOp>()) {
1106 auto tileLoc = XAie_TileLoc(tileOp.colIndex(), tileOp.rowIndex());
1107 if (!tileOp.isShimTile() && tileOp.getCoreOp()) {
1108 CoreOp coreOp = tileOp.getCoreOp();
1109 TxnLocBracket bracket(*this, coreOp.getLoc());
1110 // A core reaching its own tile's registers goes through the processor
1111 // bus, which starts disabled: an access made before this stalls the
1112 // core. Only the cores that ask for it pay for it.
1113 if (coreOp.getProcessorBus())
1114 TRY_XAIE_API_EMIT_ERROR(targetOp, XAie_CoreProcessorBusEnable,
1115 &aiert->devInst, tileLoc);
1116 TRY_XAIE_API_EMIT_ERROR(targetOp, XAie_CoreEnable, &aiert->devInst,
1117 tileLoc);
1118 }
1119 }
1120 return success();
1121}
1122
1123LogicalResult xilinx::AIE::AIERTControl::addAieElf(uint8_t col, uint8_t row,
1124 const StringRef elfPath,
1125 bool aieSim) {
1126 // loadSym: Load symbols from .map file. This argument is not used when
1127 // __AIESIM__ is not defined.
1128 TRY_XAIE_API_LOGICAL_RESULT(XAie_LoadElf, &aiert->devInst,
1129 XAie_TileLoc(col, row), elfPath.str().c_str(),
1130 /*loadSym*/ aieSim);
1131
1132 return success();
1133}
1134
1136 TRY_XAIE_API_LOGICAL_RESULT(XAie_ResetPartition, &aiert->devInst);
1137 return success();
1138}
1139
1140LogicalResult xilinx::AIE::AIERTControl::resetDMA(int col, int row, bool on) {
1141 auto tileLoc = XAie_TileLoc(col, row);
1142 XAie_DmaDesc dmaTileBd;
1143 TRY_XAIE_API_LOGICAL_RESULT(XAie_DmaDescInit, &aiert->devInst, &dmaTileBd,
1144 tileLoc);
1145 TRY_XAIE_API_LOGICAL_RESULT(XAie_DmaDisableBd, &dmaTileBd);
1146 TRY_XAIE_API_LOGICAL_RESULT(XAie_DmaChannelResetAll, &aiert->devInst, tileLoc,
1147 on ? XAie_DmaChReset::DMA_CHANNEL_UNRESET
1148 : XAie_DmaChReset::DMA_CHANNEL_RESET);
1149 return success();
1150}
1151
1152LogicalResult xilinx::AIE::AIERTControl::resetCore(int col, int row) {
1153 auto tileLoc = XAie_TileLoc(col, row);
1154 TRY_XAIE_API_LOGICAL_RESULT(XAie_CoreReset, &aiert->devInst, tileLoc);
1155 return success();
1156}
1157
1158LogicalResult xilinx::AIE::AIERTControl::resetSwitch(int col, int row) {
1159 XAie_LocType tileLoc = XAie_TileLoc(col, row);
1160
1161 // Reset all combinations of input/output routing in the switchbox
1162 for (auto endpoint_a : WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE) {
1163 for (auto endpoint_b : WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE) {
1164 unsigned n_a_connections = targetModel.getNumSourceSwitchboxConnections(
1165 col, row, endpoint_a.first);
1166 unsigned n_b_connections = targetModel.getNumDestSwitchboxConnections(
1167 col, row, endpoint_b.first);
1168 for (unsigned a_index = 0; a_index < n_a_connections; a_index++) {
1169 for (unsigned b_index = 0; b_index < n_b_connections; b_index++) {
1170 if (!targetModel.isLegalTileConnection(col, row, endpoint_a.first,
1171 a_index, endpoint_b.first,
1172 b_index)) {
1173 continue;
1174 }
1175 TRY_XAIE_API_FATAL_ERROR(XAie_StrmConnCctDisable, &aiert->devInst,
1176 tileLoc, endpoint_a.second, a_index,
1177 endpoint_b.second, b_index);
1178 }
1179 }
1180 }
1181 }
1182
1183 return success();
1184}
1185
1186LogicalResult xilinx::AIE::AIERTControl::resetCoreUnreset(int col, int row) {
1187 auto tileLoc = XAie_TileLoc(col, row);
1188 TRY_XAIE_API_LOGICAL_RESULT(XAie_CoreUnreset, &aiert->devInst, tileLoc);
1189 return success();
1190}
1191
1192LogicalResult xilinx::AIE::AIERTControl::resetLock(int col, int row,
1193 int lockId) {
1194 auto tileLoc = XAie_TileLoc(col, row);
1195 // Reset a single lock to value 0
1196 XAie_Lock lock;
1197 lock.LockId = lockId;
1198 lock.LockVal = 0;
1199 TRY_XAIE_API_LOGICAL_RESULT(XAie_LockSetValue, &aiert->devInst, tileLoc,
1200 lock);
1201 return success();
1202}
1203
1205 int col, int row, WireBundle sourceBundle, int sourceChannel,
1206 WireBundle destBundle, int destChannel) {
1207 auto tileLoc = XAie_TileLoc(col, row);
1208
1209 // Helper lambda to map WireBundle to StrmSwPortType
1210 auto mapBundle = [](WireBundle bundle) -> StrmSwPortType {
1211 switch (bundle) {
1212 case WireBundle::Core:
1213 return CORE;
1214 case WireBundle::DMA:
1215 return DMA;
1216 case WireBundle::FIFO:
1217 return FIFO;
1218 case WireBundle::South:
1219 return SOUTH;
1220 case WireBundle::West:
1221 return WEST;
1222 case WireBundle::North:
1223 return NORTH;
1224 case WireBundle::East:
1225 return EAST;
1226 case WireBundle::Trace:
1227 return TRACE;
1228 default:
1229 return SOUTH;
1230 }
1231 };
1232
1233 StrmSwPortType sourcePortType = mapBundle(sourceBundle);
1234 StrmSwPortType destPortType = mapBundle(destBundle);
1235
1236 // Disconnect the specific connection from source to destination
1237 TRY_XAIE_API_LOGICAL_RESULT(XAie_StrmConnCctDisable, &aiert->devInst, tileLoc,
1238 sourcePortType, sourceChannel, destPortType,
1239 destChannel);
1240
1241 return success();
1242}
1243
1244LogicalResult xilinx::AIE::AIERTControl::resetPerfCounters(int col, int row) {
1245 auto tileLoc = XAie_TileLoc(col, row);
1246 // Reset performance counters in all modules
1247 // Try core module counters (if applicable)
1248 for (int counterId = 0; counterId < 4; counterId++) {
1249 // Ignore errors as not all tiles have all counter types
1250 (void)XAie_PerfCounterReset(&aiert->devInst, tileLoc, XAIE_CORE_MOD,
1251 counterId);
1252 }
1253 // Try mem module counters
1254 for (int counterId = 0; counterId < 4; counterId++) {
1255 (void)XAie_PerfCounterReset(&aiert->devInst, tileLoc, XAIE_MEM_MOD,
1256 counterId);
1257 }
1258 // Try PL module counters (for shim tiles)
1259 for (int counterId = 0; counterId < 4; counterId++) {
1260 (void)XAie_PerfCounterReset(&aiert->devInst, tileLoc, XAIE_PL_MOD,
1261 counterId);
1262 }
1263 return success();
1264}
1265
1266LogicalResult xilinx::AIE::AIERTControl::addAieElfs(DeviceOp &targetOp,
1267 const StringRef elfPath,
1268 bool aieSim) {
1269 auto reset = [&](bool asserted) -> LogicalResult {
1270 for (auto core : targetOp.getOps<CoreOp>()) {
1271 if (!core.getElfFile())
1272 continue;
1273 auto tile = core.getTileOp();
1274 auto tileLoc = XAie_TileLoc(tile.colIndex(), tile.rowIndex());
1275 TxnLocBracket bracket(*this, core.getLoc());
1276 if (asserted)
1277 TRY_XAIE_API_EMIT_ERROR(core, XAie_CoreDisable, &aiert->devInst,
1278 tileLoc);
1279 TRY_XAIE_API_EMIT_ERROR(core, XAie_DmaChannelResetAll, &aiert->devInst,
1280 tileLoc,
1281 asserted ? XAie_DmaChReset::DMA_CHANNEL_RESET
1282 : XAie_DmaChReset::DMA_CHANNEL_UNRESET);
1283 }
1284 return success();
1285 };
1286 if (failed(reset(true)))
1287 return failure();
1288 for (auto tileOp : targetOp.getOps<TileOp>())
1289 if (tileOp.isShimNOCorPLTile()) {
1290 // Resets no needed with V2 kernel driver
1291 } else {
1292 int col = tileOp.colIndex();
1293 int row = tileOp.rowIndex();
1294 if (auto coreOp = tileOp.getCoreOp()) {
1295 std::string fileName;
1296 if (auto fileAttr = coreOp.getElfFile()) {
1297 fileName = fileAttr->str();
1298 } else {
1299 // Skip cores without elf_file (e.g., lightweight reset
1300 // devices that only need DMA/lock reconfiguration).
1301 continue;
1302 }
1303 // Check if fileName is already an absolute path.
1304 // If so, use it directly. Otherwise, concatenate with elfPath.
1305 std::string fullPath;
1306 if (std::filesystem::path(fileName).is_absolute()) {
1307 fullPath = fileName;
1308 } else {
1309 auto ps = std::filesystem::path::preferred_separator;
1310 fullPath =
1311 (llvm::Twine(elfPath) + std::string(1, ps) + fileName).str();
1312 }
1313 if (failed(addAieElf(col, row, fullPath, aieSim)))
1314 return failure();
1315 }
1316 }
1317 return reset(false);
1318}
1319
1320void xilinx::AIE::AIERTControl::dmaUpdateBdAddr(int col, int row, size_t addr,
1321 size_t bdId) {
1322 auto tileLoc = XAie_TileLoc(col, row);
1323 TRY_XAIE_API_FATAL_ERROR(XAie_DmaUpdateBdAddr, &aiert->devInst, tileLoc, addr,
1324 bdId);
1325}
1326
1328 aiert->txnCmdLocs.clear();
1329 aiert->txnOpLocs.clear();
1330 TRY_XAIE_API_FATAL_ERROR(XAie_StartTransaction, &aiert->devInst,
1331 XAIE_TRANSACTION_DISABLE_AUTO_FLUSH);
1332}
1333
1335 TRY_XAIE_API_FATAL_ERROR(XAie_ClearTransaction, &aiert->devInst);
1336}
1337
1338// Project the per-XAie_TxnCmd locations in `cmdLocs` onto the operations
1339// aie-codegen's serializer actually emits, mirroring
1340// _XAie_TxnExportSerialized's command-to-operation mapping. That mapping is not
1341// 1:1: the serializer buffers block writes and collapses a run of
1342// address-contiguous XAIE_IO_BLOCKWRITE commands into a single block-write
1343// operation, holds that pending run across intervening DDR-patch commands (so a
1344// patch is emitted *before* the block write it follows in CmdBuf), and drops
1345// XAIE_IO_LOAD_PM_END_INTERNAL entirely. Everything else emits one operation
1346// in command order.
1347static std::vector<mlir::Location>
1348projectCmdLocsOntoSerializedOps(const XAie_TxnInst &inst,
1349 const std::vector<mlir::Location> &cmdLocs) {
1350 std::vector<mlir::Location> opLocs;
1351 opLocs.reserve(inst.NumCmds);
1352
1353 mlir::Location unknown = mlir::UnknownLoc::get(cmdLocs.front().getContext());
1354 bool pendingBlockWrite = false;
1355 mlir::Location pendingBlockWriteLoc = unknown;
1356 uint64_t blockWriteEndOff = 0;
1357
1358 for (uint32_t i = 0; i < inst.NumCmds; ++i) {
1359 const XAie_TxnCmd &cmd = inst.CmdBuf[i];
1360 mlir::Location loc = i < cmdLocs.size() ? cmdLocs[i] : unknown;
1361
1362 if (cmd.Opcode == XAIE_IO_BLOCKWRITE) {
1363 // A command that extends the run in flight emits nothing of its own;
1364 // the run keeps the location of the command that started it.
1365 if (!pendingBlockWrite || cmd.RegOff != blockWriteEndOff) {
1366 if (pendingBlockWrite)
1367 opLocs.push_back(pendingBlockWriteLoc);
1368 pendingBlockWrite = true;
1369 pendingBlockWriteLoc = loc;
1370 }
1371 blockWriteEndOff = cmd.RegOff + cmd.Size * sizeof(uint32_t);
1372 continue;
1373 }
1374
1375 if (cmd.Opcode == XAIE_IO_LOAD_PM_END_INTERNAL)
1376 continue;
1377
1378 if (pendingBlockWrite && cmd.Opcode != XAIE_IO_CUSTOM_OP_DDR_PATCH) {
1379 opLocs.push_back(pendingBlockWriteLoc);
1380 pendingBlockWrite = false;
1381 }
1382 opLocs.push_back(loc);
1383 }
1384 if (pendingBlockWrite)
1385 opLocs.push_back(pendingBlockWriteLoc);
1386
1387 return opLocs;
1388}
1389
1391 // Export the transactions to a binary buffer
1392 uint8_t *txn_ptr = XAie_ExportSerializedTransaction(&aiert->devInst, 0, 0);
1393 XAie_TxnHeader *hdr = (XAie_TxnHeader *)txn_ptr;
1394 std::vector<uint8_t> txn_data(txn_ptr, txn_ptr + hdr->TxnSize);
1395 free(txn_ptr);
1396
1397 // Exporting leaves the recorded commands intact, so the loc projection can
1398 // still walk CmdBuf here. With nothing bracketed there is no location to
1399 // project and every emitted op falls back to the device location.
1400 XAie_TxnInst *inst = getActiveTxnInst(aiert->devInst);
1401 if (inst && !aiert->txnCmdLocs.empty())
1402 aiert->txnOpLocs =
1403 projectCmdLocsOntoSerializedOps(*inst, aiert->txnCmdLocs);
1404
1405 return txn_data;
1406}
1407
1408const std::vector<mlir::Location> &
1410 return aiert->txnOpLocs;
1411}
1412
1414 return getActiveTxnNumCmds(aiert->devInst);
1415}
1416
1418 uint32_t endCmds,
1419 mlir::Location loc) {
1420 if (endCmds <= startCmds)
1421 return;
1422 if (aiert->txnCmdLocs.size() < endCmds)
1423 aiert->txnCmdLocs.resize(endCmds, mlir::UnknownLoc::get(loc.getContext()));
1424 for (uint32_t i = startCmds; i < endCmds; ++i)
1425 aiert->txnCmdLocs[i] = loc;
1426}
#define XAIE_PARTITION_BASE_ADDR
Definition AIERT.cpp:215
#define TRY_XAIE_API_LOGICAL_RESULT(API,...)
Definition AIERT.cpp:152
#define NPI_ADDR
Definition AIERT.cpp:217
#define NUM_LOCKS
Definition AIERT.cpp:218
#define TRY_XAIE_API_FATAL_ERROR(API,...)
Definition AIERT.cpp:133
#define TRY_XAIE_API_EMIT_ERROR(OP, API,...)
Definition AIERT.cpp:143
#define AIERC_STR(x)
Definition AIERT.cpp:23
virtual 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 const DmaBdLayout * getDmaBdLayout(AIETileType tileType) const
Return the register layout of a buffer descriptor on the given tile type, or null if the target has n...
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.
virtual 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.
bool hasProperty(ModelProperty Prop) const
virtual int columns() const =0
Return the number of columns in the device.
TxnLocBracket(AIERTControl &ctl, mlir::Location loc)
Definition AIERT.cpp:252
uint32_t getShimBurstLengthBytes(const AIE::AIETargetModel &tm, uint32_t burstLength)
mlir::LogicalResult verifyBdLockPair(mlir::Block &block, bool outOfOrder, UseLockOp &acquire, UseLockOp &release)
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
mlir::LogicalResult verifyDMAChannelsResolved(DeviceOp device)
std::optional< std::vector< char > > denseAttrToBytes(mlir::DenseElementsAttr denseInit)
A buffer's initial_value as the bytes to write to its tile memory, in element order.
llvm::SmallPtrSet< mlir::Block *, 8 > collectUnchainedBlocks(const llvm::SetVector< mlir::Block * > &blockVector)
Collect BD blocks that require use_next_bd=0 during configuration.
llvm::SetVector< mlir::Block * > getOrderedChainOfBlocks(mlir::Region *region)
std::vector< mlir::Location > txnCmdLocs
Definition AIERT.cpp:228
std::vector< mlir::Location > txnOpLocs
Definition AIERT.cpp:232
mlir::LogicalResult configureSwitches(DeviceOp &targetOp, bool skipCtrlPktOverlay=false)
Definition AIERT.cpp:769
mlir::LogicalResult resetPerfCounters(int col, int row)
Definition AIERT.cpp:1244
mlir::LogicalResult configureLocksAndBd(mlir::Block &block, int col, int row, bool outOfOrder=false)
Definition AIERT.cpp:679
mlir::LogicalResult resetCore(int col, int row)
Definition AIERT.cpp:1152
mlir::LogicalResult addDmaActivation(DeviceOp &targetOp)
Definition AIERT.cpp:1062
void dmaUpdateBdAddr(int col, int row, size_t addr, size_t bdId)
Definition AIERT.cpp:1320
mlir::LogicalResult resetPartition()
Definition AIERT.cpp:1135
mlir::LogicalResult resetCoreUnreset(int col, int row)
Definition AIERT.cpp:1186
mlir::LogicalResult setIOBackend(bool aieSim, bool xaieDebug)
Definition AIERT.cpp:341
uint32_t getCurrentTxnNumCmds() const
Definition AIERT.cpp:1413
std::vector< uint8_t > exportSerializedTransaction()
Definition AIERT.cpp:1390
AIERTControl(const xilinx::AIE::AIETargetModel &tm)
Definition AIERT.cpp:277
mlir::LogicalResult initLocks(DeviceOp &targetOp)
Definition AIERT.cpp:709
mlir::LogicalResult resetDMA(int col, int row, bool on)
Definition AIERT.cpp:1140
static mlir::LogicalResult isSupported(mlir::Operation *op, const AIETargetModel &tm)
Diagnose, on op, a target this aie-rt lowering cannot configure.
Definition AIERT.cpp:269
mlir::LogicalResult disableCores(DeviceOp &targetOp)
Definition AIERT.cpp:953
mlir::LogicalResult initBuffers(DeviceOp &targetOp)
Definition AIERT.cpp:742
mlir::LogicalResult resetSwitch(int col, int row)
Definition AIERT.cpp:1158
mlir::LogicalResult addCoreEnable(DeviceOp &targetOp)
Definition AIERT.cpp:1103
mlir::LogicalResult resetSwitchConnection(int col, int row, WireBundle sourceBundle, int sourceChannel, WireBundle destBundle, int destChannel)
Definition AIERT.cpp:1204
const std::vector< mlir::Location > & getTxnOpLocs() const
Definition AIERT.cpp:1409
mlir::LogicalResult addInitConfig(DeviceOp &targetOp, bool skipCtrlPktOverlay=false)
Definition AIERT.cpp:1003
mlir::LogicalResult addAieElf(uint8_t col, uint8_t row, const mlir::StringRef elfPath, bool aieSim)
Definition AIERT.cpp:1123
void recordTxnLocRange(uint32_t startCmds, uint32_t endCmds, mlir::Location loc)
Definition AIERT.cpp:1417
mlir::LogicalResult resetDmaChannels(DeviceOp &targetOp)
Definition AIERT.cpp:963
mlir::LogicalResult pushToBdQueueAndEnable(mlir::Operation &op, int col, int row, int chNum, const DMAChannelDir &channelDir, int bdId, int repeatCount, uint32_t padValue=0, bool outOfOrder=false, bool configureChannel=true, bool pushTask=true)
Definition AIERT.cpp:632
mlir::LogicalResult addAieElfs(DeviceOp &targetOp, const mlir::StringRef elfPath, bool aieSim)
Definition AIERT.cpp:1266
mlir::LogicalResult resetLock(int col, int row, int lockId)
Definition AIERT.cpp:1192
mlir::LogicalResult teardownSwitches(DeviceOp &targetOp, bool skipCtrlPktOverlay=false)
Definition AIERT.cpp:901
llvm::SmallVector< std::pair< DmaBdField, DmaBdField >, 3 > padFields() const
The (before, after) zero-padding fields, innermost dimension first.