18#include "mlir/Dialect/Arith/IR/Arith.h"
19#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
20#include "mlir/Dialect/Func/IR/FuncOps.h"
21#include "mlir/Dialect/MemRef/IR/MemRef.h"
22#include "mlir/IR/SymbolTable.h"
23#include "mlir/Interfaces/DataLayoutInterfaces.h"
24#include "mlir/Interfaces/SideEffectInterfaces.h"
26#include "mlir/Tools/mlir-translate/MlirTranslateMain.h"
27#include "llvm/ADT/DenseMap.h"
29#include "mlir/Dialect/Utils/StaticValueUtils.h"
30#include "llvm/ADT/ArrayRef.h"
31#include "llvm/ADT/TypeSwitch.h"
32#include "llvm/Support/Format.h"
33#include "llvm/Support/FormatVariadic.h"
34#include "llvm/Support/JSON.h"
35#include "llvm/Support/raw_ostream.h"
52llvm::MutableArrayRef<uint32_t>
53reserveAndGetTail(std::vector<uint32_t> &instructions, uint64_t tailSize) {
54 auto oldSize = instructions.size();
55 auto newSize = oldSize + tailSize;
56 instructions.resize(newSize, 0);
57 return llvm::MutableArrayRef<uint32_t>(instructions.data() + oldSize,
64LogicalResult appendSync(std::vector<uint32_t> &instructions, NpuSyncOp op) {
67 std::optional<uint32_t> direction =
69 std::optional<uint32_t> channel =
71 std::optional<uint32_t> columnNum =
74 if (!column || !row || !direction || !channel || !columnNum || !rowNum)
75 return op.emitOpError(
"Cannot translate sync with non-constant operands to "
76 "a static TXN binary");
78 *channel, *columnNum, *rowNum);
82LogicalResult appendWrite32(std::vector<uint32_t> &instructions,
85 return op.emitOpError(
"Cannot translate symbolic address");
86 std::optional<uint32_t> address = op.getAbsoluteAddress();
88 if (!address || !value)
89 return op.emitOpError(
90 "Cannot translate write32 with non-constant address or value "
91 "to a static TXN binary");
96LogicalResult appendMaskWrite32(std::vector<uint32_t> &instructions,
97 NpuMaskWrite32Op op) {
99 return op.emitOpError(
"Cannot translate symbolic address");
100 std::optional<uint32_t> address = op.getAbsoluteAddress();
103 if (!address || !value || !mask)
104 return op.emitOpError(
"Cannot translate maskwrite32 with non-constant "
105 "address, value, or mask to a static TXN binary");
110LogicalResult appendMaskPoll(std::vector<uint32_t> &instructions,
113 return op.emitOpError(
"Cannot translate symbolic address");
114 std::optional<uint32_t> address = op.getAbsoluteAddress();
117 if (!address || !value || !mask)
118 return op.emitOpError(
"Cannot translate maskpoll with non-constant "
119 "address, value, or mask to a static TXN binary");
124void appendLoadPdi(std::vector<uint32_t> &instructions, NpuLoadPdiOp op) {
129LogicalResult appendAddressPatch(std::vector<uint32_t> &instructions,
130 NpuAddressPatchOp op,
bool foldDDRAddrOffset) {
132 return op.emitOpError(
"Cannot translate address_patch with a runtime "
133 "register address (addr_val) to a static TXN binary; "
134 "the runtime-bd_id pool path targets the C++ TXN "
136 std::optional<uint64_t> argPlus =
139 return op.emitOpError(
"Cannot translate address_patch with non-constant "
140 "arg_plus to a static TXN binary");
141 std::optional<uint32_t> argIdx = op.getArgIdx();
143 return op.emitOpError(
"address_patch still names its host buffer by SSA "
144 "value; run -aie-resolve-address-patch-buffers");
146 *argPlus, foldDDRAddrOffset);
161static DenseIntElementsAttr cachedBlockWriteData(
162 NpuBlockWriteOp op, mlir::SymbolTable &symTab,
163 llvm::DenseMap<mlir::StringAttr, DenseIntElementsAttr> &cache) {
164 auto getGlobal = op.getData().getDefiningOp<mlir::memref::GetGlobalOp>();
166 return op.getDataWords();
168 mlir::StringAttr key = getGlobal.getNameAttr().getRootReference();
169 auto it = cache.find(key);
170 if (it != cache.end())
175 mlir::DataLayout dataLayout = mlir::DataLayout::closest(op);
176 if (dataLayout.getTypeSizeInBits(
177 mlir::cast<mlir::MemRefType>(op.getData().getType())
178 .getElementType()) != 32)
179 return op.getDataWords();
180 DenseIntElementsAttr data;
182 dyn_cast_if_present<mlir::memref::GlobalOp>(symTab.lookup(key)))
183 if (
auto initVal = global.getInitialValue())
184 data = dyn_cast<DenseIntElementsAttr>(*initVal);
186 data = op.getDataWords();
191LogicalResult appendBlockWrite(
192 std::vector<uint32_t> &instructions, NpuBlockWriteOp op,
193 std::optional<uint32_t> address, mlir::SymbolTable &symTab,
194 llvm::DenseMap<mlir::StringAttr, DenseIntElementsAttr> &dataCache) {
196 return op.emitOpError(
197 "Cannot translate blockwrite with unresolved address to a static TXN "
199 DenseIntElementsAttr data = cachedBlockWriteData(op, symTab, dataCache);
203 std::vector<uint32_t> payload;
204 payload.reserve(data.size());
205 if (
auto words = data.tryGetValues<uint32_t>(); succeeded(words))
207 payload.assign(words->begin(), words->end());
210 payload.push_back(d.getZExtValue());
214 auto col = op.getColumn();
215 auto row = op.getRow();
216 uint32_t colVal = 0, rowVal = 0;
222 payload.size(), colVal, rowVal);
226void appendPreempt(std::vector<uint32_t> &instructions, NpuPreemptOp op) {
230void appendCreateScratchpad(std::vector<uint32_t> &instructions,
231 NpuCreateScratchpadOp op) {
238 auto words = reserveAndGetTail(instructions, 4);
241 words[0] |= (
static_cast<uint32_t
>(op.getUsageType()) << 8);
242 words[1] = op.getSize();
250LogicalResult appendUpdateRegFromScratchpad(std::vector<uint32_t> &instructions,
251 NpuUpdateFromScratchpadOp op,
253 std::optional<uint32_t> address = op.getAbsoluteAddress(&names);
255 return op.emitOpError(
"Cannot translate update_from_scratchpad with "
256 "unresolved address to a static TXN binary");
264 auto words = reserveAndGetTail(instructions, 3);
267 words[0] |= (
static_cast<uint32_t
>(op.getStateTableIdx()) << 8);
268 words[0] |= (
static_cast<uint32_t
>(op.getFunc()) << 16);
269 words[1] = op.getFuncArg();
282 static std::unique_ptr<xilinx::AIE::RegisterDatabase> db =
286 static std::unique_ptr<xilinx::AIE::RegisterDatabase> db =
296static llvm::StringRef
297lookupRegisterByAddress(uint64_t address,
const AIETargetModel &tm,
299 std::string &outModule) {
303 if (address > UINT32_MAX)
311 StringRef moduleName;
315 moduleName =
"memory_tile";
324 outModule =
"memory";
330 outModule = moduleName.str();
336static void pushLocEntry(std::vector<TxnLocEntry> *locmap,
337 uint32_t byteOffsetBefore, uint32_t byteOffsetAfter,
338 StringRef opcodeName, StringRef sourceOpName,
339 std::optional<uint64_t> address, mlir::Operation *op,
345 e.
byteSize = byteOffsetAfter - byteOffsetBefore;
349 e.
loc = op->getLoc();
351 if (
auto regName = lookupRegisterByAddress(*address, tm, getRegDB(tm),
357 locmap->push_back(std::move(e));
362 TxnEncoder(DeviceOp device, std::vector<uint32_t> &instructions,
363 std::vector<TxnLocEntry> *locmap,
bool foldDDRAddrOffset,
364 NpuConfigCache &configs)
366 symTab(device.getOperation()), names(device.getOperation()),
367 configs(configs), instructions(instructions), locmap(locmap),
368 foldDDRAddrOffset(foldDDRAddrOffset) {}
370 void encode(Operation &o);
371 LogicalResult encodeConfig(DeviceOp configured,
bool teardown,
372 NpuConfigCache::Config &config);
373 void appendConfig(Operation *op, FlatSymbolRefAttr deviceRef,
bool teardown);
376 const AIETargetModel &tm;
380 mlir::SymbolTable symTab;
382 llvm::DenseMap<mlir::StringAttr, DenseIntElementsAttr> blockWriteDataCache;
383 NpuConfigCache &configs;
384 std::vector<uint32_t> &instructions;
385 std::vector<TxnLocEntry> *locmap;
386 bool foldDDRAddrOffset;
392 LogicalResult result = success();
398LogicalResult TxnEncoder::encodeConfig(DeviceOp configured,
bool teardown,
400 MLIRContext *ctx = device.getContext();
401 ctx->getOrLoadDialect<arith::ArithDialect>();
402 ctx->getOrLoadDialect<memref::MemRefDialect>();
403 OpBuilder builder(ctx);
404 OwningOpRef<ModuleOp> scratch = ModuleOp::create(device.getLoc());
405 builder.setInsertionPointToStart(scratch->getBody());
407 DeviceOp::create(builder, device.getLoc(), configured.getDevice(),
408 configured.getSymName(),
nullptr);
409 holder.getRegion().emplaceBlock();
410 DeviceOp::ensureTerminator(holder.getBodyRegion(), builder, device.getLoc());
411 builder.setInsertionPointToStart(holder.getBody());
412 auto seq = RuntimeSequenceOp::create(
413 builder, device.getLoc(), builder.getStringAttr(
"configure"), BoolAttr{},
414 TraceBufferAttr{}, ArrayAttr{}, ArrayAttr{});
415 Block *body =
new Block;
416 seq.getBody().push_back(body);
417 builder.setInsertionPointToStart(body);
418 BlockwriteData payloads(holder, teardown ?
"teardown_" :
"loadpdi_");
425 TxnEncoder encoder(holder, config.
words, &config.
locmap, foldDDRAddrOffset,
427 for (Operation &op : *body)
429 config.
count = encoder.count;
430 return encoder.result;
433void TxnEncoder::appendConfig(Operation *op, FlatSymbolRefAttr deviceRef,
435 auto configured = dyn_cast_or_null<DeviceOp>(
436 SymbolTable::lookupSymbolIn(device->getParentOp(), deviceRef));
437 const NpuConfigCache::Config *config =
440 [&](NpuConfigCache::Config &c) {
441 return encodeConfig(configured, teardown, c);
445 op->emitOpError(teardown ?
"cannot generate the teardown of "
446 :
"cannot generate the configuration of ")
451 uint32_t base =
static_cast<uint32_t
>(instructions.size() *
sizeof(uint32_t));
452 llvm::append_range(instructions, config->
words);
453 count += config->
count;
455 for (TxnLocEntry entry : config->
locmap) {
457 locmap->push_back(std::move(entry));
461void TxnEncoder::encode(Operation &o) {
462 auto byteOffset = [&]() -> uint32_t {
463 return static_cast<uint32_t
>(instructions.size() *
sizeof(uint32_t));
465 llvm::TypeSwitch<Operation *>(&o)
466 .Case<cf::AssertOp>([&](
auto op) {
471 auto c = getConstantIntValue(op.getArg());
473 op.emitOpError(
"is violated at compile time: ") << op.getMsg();
476 op.emitOpError(
"runtime check cannot be encoded in a static TXN "
477 "binary; use the C++ builder (--aie-npu-to-cpp) "
478 "or specialize the value: ")
483 .Case<NpuSyncOp>([&](
auto op) {
485 uint32_t before = byteOffset();
486 if (failed(appendSync(instructions, op)))
488 pushLocEntry(locmap, before, byteOffset(),
"TCT",
489 op->getName().getStringRef(), std::nullopt, op, tm);
491 .Case<NpuWrite32Op>([&](
auto op) {
493 uint32_t before = byteOffset();
494 uint64_t addr = op.getAbsoluteAddress().value_or(0);
495 if (failed(appendWrite32(instructions, op)))
497 pushLocEntry(locmap, before, byteOffset(),
"WRITE32",
498 op->getName().getStringRef(), addr, op, tm);
500 .Case<NpuBlockWriteOp>([&](
auto op) {
502 uint32_t before = byteOffset();
503 std::optional<uint32_t> addr = op.getAbsoluteAddress(&names);
504 if (failed(appendBlockWrite(instructions, op, addr, symTab,
505 blockWriteDataCache)))
507 pushLocEntry(locmap, before, byteOffset(),
"BLOCKWRITE",
508 op->getName().getStringRef(), addr.value_or(0), op, tm);
510 .Case<NpuBlockWriteValuesOp>([&](
auto op) {
513 op.emitOpError(
"cannot translate a runtime-valued blockwrite "
514 "payload to a static TXN binary; this op is "
515 "supported only by the C++ TXN target "
516 "(--aie-npu-to-cpp)");
519 .Case<NpuMaskWrite32Op>([&](
auto op) {
521 uint32_t before = byteOffset();
522 uint64_t addr = op.getAbsoluteAddress().value_or(0);
523 if (failed(appendMaskWrite32(instructions, op)))
525 pushLocEntry(locmap, before, byteOffset(),
"MASKWRITE",
526 op->getName().getStringRef(), addr, op, tm);
528 .Case<NpuMaskPollOp>([&](
auto op) {
530 uint32_t before = byteOffset();
531 uint64_t addr = op.getAbsoluteAddress().value_or(0);
532 if (failed(appendMaskPoll(instructions, op)))
534 pushLocEntry(locmap, before, byteOffset(),
"MASKPOLL",
535 op->getName().getStringRef(), addr, op, tm);
537 .Case<NpuLoadPdiOp>([&](
auto op) {
539 uint32_t before = byteOffset();
540 appendLoadPdi(instructions, op);
541 pushLocEntry(locmap, before, byteOffset(),
"LOAD_PDI",
542 op->getName().getStringRef(), std::nullopt, op, tm);
544 .Case<NpuAddressPatchOp>([&](
auto op) {
546 uint32_t before = byteOffset();
547 if (failed(appendAddressPatch(instructions, op, foldDDRAddrOffset)))
549 pushLocEntry(locmap, before, byteOffset(),
"ADDRESS_PATCH",
550 op->getName().getStringRef(), op.getAddr(), op, tm);
552 .Case<NpuPreemptOp>([&](
auto op) {
554 uint32_t before = byteOffset();
555 appendPreempt(instructions, op);
556 pushLocEntry(locmap, before, byteOffset(),
"PREEMPT",
557 op->getName().getStringRef(), std::nullopt, op, tm);
559 .Case<NpuCreateScratchpadOp>([&](
auto op) {
561 uint32_t before = byteOffset();
562 appendCreateScratchpad(instructions, op);
563 pushLocEntry(locmap, before, byteOffset(),
"CREATE_SCRATCHPAD",
564 op->getName().getStringRef(), std::nullopt, op, tm);
566 .Case<NpuUpdateFromScratchpadOp>([&](
auto op) {
568 uint32_t before = byteOffset();
569 if (failed(appendUpdateRegFromScratchpad(instructions, op, names)))
571 pushLocEntry(locmap, before, byteOffset(),
"UPDATE_FROM_SCRATCHPAD",
572 op->getName().getStringRef(), std::nullopt, op, tm);
574 .Case<NpuWriteConfigOp>([&](
auto op) {
575 appendConfig(op, op.getDeviceRefAttr(),
false);
577 .Case<NpuWriteTeardownOp>([&](
auto op) {
578 appendConfig(op, op.getDeviceRefAttr(),
true);
580 .Default([&](Operation *op) {
584 if (isMemoryEffectFree(op) || op->hasTrait<OpTrait::IsTerminator>() ||
585 isa<NpuControlPacketOp, SetDeviceOp>(op))
587 op->emitOpError(
"has no static TXN encoding");
595 Operation *device,
bool teardown,
596 llvm::function_ref<LogicalResult(
Config &)> encode) {
597 std::lock_guard<std::mutex> lock(mutex);
598 auto [it, inserted] = configs[teardown].try_emplace(device);
600 auto config = std::make_unique<Config>();
601 if (succeeded(encode(*config)))
602 it->second = std::move(config);
604 return it->second.get();
608 mlir::ModuleOp moduleOp, std::vector<uint32_t> &instructions,
609 StringRef deviceName, StringRef sequenceName,
610 std::vector<TxnLocEntry> *locmap,
bool foldDDRAddrOffset,
614 DeviceOp::getForSymbolInModuleOrError(moduleOp, deviceName);
628 AIE::RuntimeSequenceOp seq =
629 AIE::RuntimeSequenceOp::getForSymbolInDeviceOrError(deviceOp,
635 SmallVector<AIEX::ConfigStep> steps;
636 for (Block &block : seq.getBody())
637 for (Operation &o : block) {
638 if (
auto loadPdiOp = dyn_cast<NpuLoadPdiOp>(o)) {
639 FlatSymbolRefAttr ref = loadPdiOp.getDeviceRefAttr();
641 {&o, loadPdiOp,
false,
642 ref ? moduleOp.lookupSymbol<AIE::DeviceOp>(ref) : nullptr});
643 }
else if (
auto writeConfigOp = dyn_cast<NpuWriteConfigOp>(o)) {
644 steps.push_back({&o,
nullptr,
false,
645 moduleOp.lookupSymbol<AIE::DeviceOp>(
646 writeConfigOp.getDeviceRefAttr())});
652 NpuConfigCache ownConfigs;
653 TxnEncoder encoder(deviceOp, instructions, locmap, foldDDRAddrOffset,
654 configs ? *configs : ownConfigs);
655 for (Block &block : seq.getBody())
656 for (Operation &o : block)
658 if (failed(encoder.result))
667 ModuleOp module, std::vector<uint32_t> &instructions, StringRef deviceName,
668 StringRef sequenceName, std::vector<TxnLocEntry> *locmap) {
670 AIE::DeviceOp::getForSymbolInModuleOrError(module, deviceName);
674 AIE::RuntimeSequenceOp seq =
675 AIE::RuntimeSequenceOp::getForSymbolInDeviceOrError(deviceOp,
681 const AIETargetModel &tm = deviceOp.getTargetModel();
682 llvm::DenseMap<TileID, AIE::PacketInfoAttr> controllerIds =
684 SmallVector<AIEX::ControlPacketMulticast> multicasts;
685 for (Operation &operation : seq.getBody().getOps()) {
686 if (
auto context = dyn_cast<AIEX::SetDeviceOp>(operation)) {
687 std::optional<SmallVector<AIEX::ControlPacketMulticast>> groups =
691 multicasts = std::move(*groups);
692 }
else if (isa<AIEX::NpuLoadPdiOp>(operation)) {
695 auto packetOp = dyn_cast<AIEX::NpuControlPacketOp>(operation);
701 if (failed(packetOp.verify()))
705 static_cast<uint32_t
>(instructions.size() *
sizeof(uint32_t));
708 auto data = packetOp.getData();
717 auto words = reserveAndGetTail(instructions, 2 + size);
719 std::optional<uint32_t> length = packetOp.getLength();
723 auto parity = [](uint32_t n) {
736 if (size > AIEX::NpuControlPacketOp::getMaxDataWords())
737 return packetOp.emitOpError()
738 <<
"payload is " << size
739 <<
" words; a control packet carries at most "
740 << AIEX::NpuControlPacketOp::getMaxDataWords()
741 <<
" on the wire. Run --aie-legalize-control-packet before "
746 if (std::optional<uint32_t>
id = packetOp.getMulticastId()) {
747 if (*
id >= multicasts.size())
748 return packetOp.emitOpError(
"multicast_id ")
749 << *
id <<
" has no declaration in the active overlay";
750 hdr = multicasts[*id].packetId;
752 TileID tile = packetOp.getTileFromAddr();
753 AIE::PacketInfoAttr info = controllerIds.lookup(tile);
755 return packetOp.emitOpError(
"targets tile (")
756 << tile.col <<
", " << tile.row
757 <<
"), which has no controller_id to route it by";
758 hdr = (info.getPktType() & 0x7) << 12 | (info.assignedId() & 0xff);
760 words[0] = hdr | (0x1 & parity(hdr)) << 31;
762 uint32_t addr = packetOp.getAddress() & 0xFFFFF;
763 uint32_t beats = size - 1;
764 uint32_t opc = packetOp.getOpcode();
765 uint32_t
id = packetOp.getStreamId();
766 hdr =
id << 24 | opc << 22 | beats << 20 | addr;
767 words[1] = hdr | (0x1 & parity(hdr)) << 31;
770 if (data && (opc == 0x0 || opc == 0x2)) {
771 for (
unsigned i = 0; i < size; i++)
772 words[i + 2] = (*data)[i];
776 static_cast<uint32_t
>(instructions.size() *
sizeof(uint32_t));
777 pushLocEntry(locmap, before, after,
"CONTROL_PACKET",
778 packetOp->getName().getStringRef(), packetOp.getAddress(),
787static llvm::json::Value locToJSON(mlir::Location loc) {
788 using namespace llvm;
789 if (
auto f = dyn_cast<mlir::FileLineColLoc>(loc))
790 return json::Value(json::Object{
792 {
"file", f.getFilename().str()},
793 {
"line",
static_cast<int64_t
>(f.getLine())},
794 {
"col",
static_cast<int64_t
>(f.getColumn())},
796 if (
auto n = dyn_cast<mlir::NameLoc>(loc)) {
797 json::Object o{{
"kind",
"name"}, {
"name", n.getName().str()}};
798 o[
"child"] = locToJSON(n.getChildLoc());
799 return json::Value(std::move(o));
801 if (
auto fused = dyn_cast<mlir::FusedLoc>(loc)) {
802 json::Array children;
803 for (mlir::Location c : fused.getLocations())
804 children.push_back(locToJSON(c));
806 json::Object{{
"kind",
"fused"}, {
"children", std::move(children)}});
808 if (
auto cs = dyn_cast<mlir::CallSiteLoc>(loc))
809 return json::Value(json::Object{
810 {
"kind",
"callsite"},
811 {
"callee", locToJSON(cs.getCallee())},
812 {
"caller", locToJSON(cs.getCaller())},
814 if (isa<mlir::OpaqueLoc>(loc))
815 return json::Value(json::Object{{
"kind",
"opaque"}});
816 return json::Value(json::Object{{
"kind",
"unknown"}});
820 llvm::StringRef deviceName,
821 llvm::StringRef binaryName,
822 const std::vector<TxnLocEntry> &locmap) {
823 llvm::json::Object root;
825 root[
"device"] = deviceName.str();
826 root[
"binary"] = binaryName.str();
828 llvm::json::Array opsArr;
829 for (
const auto &e : locmap) {
830 llvm::json::Object o;
831 o[
"byte_offset"] =
static_cast<int64_t
>(e.
byteOffset);
832 o[
"byte_size"] =
static_cast<int64_t
>(e.
byteSize);
836 o[
"address"] = llvm::formatv(
"{0:X}", *e.
address).str();
842 o[
"loc"] = locToJSON(*e.
loc);
843 opsArr.push_back(std::move(o));
845 root[
"operations"] = std::move(opsArr);
847 output << llvm::formatv(
"{0:2}\n", llvm::json::Value(std::move(root)));
virtual uint32_t getTileAddress(int col, int row) const
Return the base address of the tile's window.
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.
uint32_t getColumnFromAddress(uint32_t address) const
virtual uint32_t getRowFromAddress(uint32_t address) const
Inverse of getTileAddress() for any address in the tile's window.
bool isShimPLTile(int col, int row) const
Return true if the given tile is a ShimPL tile.
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 int columns() const =0
Return the number of columns in the device.
virtual uint32_t getNumMemTileRows() const =0
const Config * getOrEncode(mlir::Operation *device, bool teardown, llvm::function_ref< mlir::LogicalResult(Config &)> encode)
Register and event database for a specific architecture.
static std::unique_ptr< RegisterDatabase > loadAIE2()
Load database for AIE2 architecture.
static std::unique_ptr< RegisterDatabase > loadAIE4()
Load database for AIE4 architecture.
const RegisterInfo * lookupRegisterByOffset(uint32_t offset, llvm::StringRef module) const
Lookup register by tile-relative offset and module name.
void txn_append_maskpoll32(std::vector< uint32_t > &txn, uint32_t addr, uint32_t val, uint32_t mask)
void txn_append_loadpdi(std::vector< uint32_t > &txn, uint32_t id, uint32_t size, uint64_t addr)
void txn_append_write32(std::vector< uint32_t > &txn, uint32_t addr, uint32_t val)
void txn_init(std::vector< uint32_t > &txn)
void txn_append_sync(std::vector< uint32_t > &txn, uint32_t col, uint32_t row, uint32_t dir, uint32_t chan, uint32_t ncol, uint32_t nrow)
void txn_append_preempt(std::vector< uint32_t > &txn, uint32_t level)
void txn_append_arg_patch(std::vector< uint32_t > &txn, uint32_t addr, int32_t arg_idx, uint64_t arg_plus, bool fold_ddr_addr_offset)
TxnDeviceInfo txn_device_info(uint8_t dev_gen, uint8_t num_rows, uint8_t num_cols, uint8_t num_memtile_rows)
@ TXN_OPC_CREATE_SCRATCHPAD
void txn_append_maskwrite32(std::vector< uint32_t > &txn, uint32_t addr, uint32_t val, uint32_t mask)
void txn_append_blockwrite(std::vector< uint32_t > &txn, uint32_t addr, const uint32_t *data, size_t count, uint32_t col=0, uint32_t row=0)
void txn_prepend_header(std::vector< uint32_t > &txn, uint32_t op_count, TxnDeviceInfo info={})
mlir::FailureOr< llvm::SmallVector< ControlPacketMulticast > > controlPacketMulticasts(mlir::ModuleOp module, mlir::FlatSymbolRefAttr reference)
llvm::DenseMap< AIE::TileID, AIE::PacketInfoAttr > controllerIdsOf(AIE::DeviceOp device)
LogicalResult checkResidentsSurvive(AIE::RuntimeSequenceOp seq, ArrayRef< ConfigStep > steps)
std::optional< uint64_t > getConstantInt64Operand(mlir::Value v)
std::optional< uint32_t > getConstantIntOperand(mlir::Value v)
void emitNpuLocmapJSON(llvm::raw_ostream &output, llvm::StringRef deviceName, llvm::StringRef binaryName, const std::vector< TxnLocEntry > &locmap)
uint8_t txnDeviceGen(const AIETargetModel &tm)
Device generation ID written into the TXN header (aie_runtime::TxnDeviceInfo::devGen).
mlir::LogicalResult AIETranslateControlPacketsToUI32Vec(mlir::ModuleOp, std::vector< uint32_t > &, llvm::StringRef deviceName="", llvm::StringRef sequenceName="", std::vector< TxnLocEntry > *locmap=nullptr)
mlir::LogicalResult AIETranslateNpuToBinary(mlir::ModuleOp, std::vector< uint32_t > &, llvm::StringRef deviceName="", llvm::StringRef sequenceName="", std::vector< TxnLocEntry > *locmap=nullptr, bool foldDDRAddrOffset=true, NpuConfigCache *configs=nullptr)
mlir::LogicalResult generateAndInsertConfigOps(mlir::OpBuilder &builder, xilinx::AIE::DeviceOp device, xilinx::AIEX::BlockwriteData &blockwriteData, llvm::StringRef clElfDir="", AIEToConfigurationOutputType outputType=AIEToConfigurationOutputType::Transaction, bool skipCtrlPktOverlay=false)
struct TileID { friend std::ostream &operator<<(std::ostream &os, const TileID &s) { os<< "TileID("<< s.col<< ", "<< s.row<< ")"; return os; } friend std::string to_string(const TileID &s) { std::ostringstream ss; ss<< s; return ss.str(); } friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const TileID &s) { os<< to_string(s); return os; } inline bool operator<(const TileID &rhs) const { return std::tie(col, row)< std::tie(rhs.col, rhs.row); } bool operator==(const TileID &rhs) const { return std::tie(col, row)==std::tie(rhs.col, rhs.row); } bool operator!=(const TileID &rhs) const { return !(*this==rhs);} int col, row;} TileID
const AIETargetModel & getTargetModel(mlir::Operation *op)
mlir::LogicalResult generateAndInsertTeardownOps(mlir::OpBuilder &builder, xilinx::AIE::DeviceOp device, xilinx::AIEX::BlockwriteData &blockwriteData, AIEToConfigurationOutputType outputType=AIEToConfigurationOutputType::Transaction, bool skipCtrlPktOverlay=false)
std::vector< uint32_t > words
std::vector< TxnLocEntry > locmap
std::optional< uint64_t > address
std::string registerModule
std::optional< mlir::Location > loc