MLIR-AIE 1.4.6.dev
AIEExpandLoadPdi.cpp
Go to the documentation of this file.
1//===- AIEExpandLoadPdi.cpp -------------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2025 Advanced Micro Devices, Inc.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7//
8// This pass expands `npu.load_pdi` operations that reference a device. There
9// are two output modes, controlled by the `ctrl-pkt` option:
10//
11// 1. Default (ctrl-pkt=false): replaces each `load_pdi @device` with
12// a. an empty device PDI load (`load_pdi @empty_N`), which causes the
13// firmware to reset the device, and
14// b. an `aiex.npu.write_config @device`, whose register writes the NPU
15// translation emits (or, with inline-config, those writes as ops).
16// c. with teardown, an `aiex.npu.write_teardown @device` where it ends.
17// 2. With ctrl-pkt=true: replaces each `load_pdi @device` with
18// a. a `load_pdi @ctrl_pkt_overlay`, which configures the NPU to stream
19// further configuration as control packets, and
20// b. a sequence of `aiex.npu.control_packet` ops carrying the device's
21// configuration.
22//
23//===----------------------------------------------------------------------===//
24
30
31#include "mlir/Dialect/Arith/IR/Arith.h"
32#include "mlir/Dialect/MemRef/IR/MemRef.h"
33#include "mlir/Pass/Pass.h"
34
35#include "llvm/ADT/DenseMap.h"
36#include "llvm/ADT/MapVector.h"
37#include "llvm/ADT/StringRef.h"
38#include "llvm/Support/FormatVariadic.h"
39#include "llvm/Support/raw_ostream.h"
40
41#include <array>
42#include <map>
43#include <set>
44
45namespace xilinx::AIEX {
46#define GEN_PASS_DEF_AIEEXPANDLOADPDI
47#include "aie/Dialect/AIEX/Transforms/AIEXPasses.h.inc"
48} // namespace xilinx::AIEX
49
50#define DEBUG_TYPE "aie-expand-load-pdi"
51
52using namespace mlir;
53using namespace xilinx;
54using namespace xilinx::AIEX;
55using namespace xilinx::AIE;
56
57namespace {
58
59static AIE::DeviceOp controlOverlayOf(AIE::DeviceOp device) {
60 auto ref = device.getOverlayAttr();
61 return ref ? device->getParentOfType<ModuleOp>().lookupSymbol<AIE::DeviceOp>(
62 ref)
63 : AIE::DeviceOp{};
64}
65
66using OverlayCopies = llvm::DenseMap<AIE::DeviceOp, AIE::DeviceOp>;
67
68// Firmware caches the last PDI address, so consecutive resets alternate copies.
69static AIE::DeviceOp overlayPreload(AIE::DeviceOp overlay, unsigned parity,
70 OverlayCopies &copies) {
71 if (!parity)
72 return overlay;
73 auto [it, inserted] = copies.try_emplace(overlay);
74 if (!inserted)
75 return it->second;
76 auto copy = cast<AIE::DeviceOp>(overlay->clone());
77 copy.setSymName((overlay.getSymName() + "_copy").str());
78 SymbolTable(overlay->getParentOfType<ModuleOp>()).insert(copy);
79 return it->second = copy;
80}
81
82// A control-packet reload reaches a tile only if `overlay` routes control
83// packets to its TileControl port. `packets` are the reload's.
84static LogicalResult
85verifyOverlayReachesTiles(NpuLoadPdiOp loadPdiOp, AIE::DeviceOp overlay,
86 iterator_range<Block::iterator> packets) {
87 std::set<AIE::TileID> reached;
88 overlay.walk([&](AIE::SwitchboxOp sb) {
89 for (Operation &op : sb.getConnections().front()) {
90 std::optional<AIE::Port> dest;
91 if (auto master = dyn_cast<AIE::MasterSetOp>(op))
92 dest = master.destPort();
93 else if (auto connect = dyn_cast<AIE::ConnectOp>(op))
94 dest = connect.destPort();
95 if (dest == AIE::Port{AIE::WireBundle::TileControl, 0})
96 reached.insert({sb.colIndex(), sb.rowIndex()});
97 }
98 });
99 for (Operation &op : packets) {
100 auto packet = dyn_cast<NpuControlPacketOp>(op);
101 if (!packet)
102 continue;
103 AIE::TileID tile{static_cast<int>(packet.getColumnFromAddr()),
104 static_cast<int>(packet.getRowFromAddr())};
105 if (reached.count(tile))
106 continue;
107 return loadPdiOp.emitError()
108 << "a control-packet reload configures tile (" << tile.col << ", "
109 << tile.row << "), but @" << overlay.getSymName()
110 << " routes no control packets to it";
111 }
112 return success();
113}
114
115// The empty device whose PDI load makes the firmware reset the array. `parity`
116// alternates so that two consecutive loads never name the same PDI (see
117// transformLoadPdi).
118static AIE::DeviceOp getOrCreateEmptyDevice(ModuleOp moduleOp,
119 AIE::AIEDevice deviceType,
120 unsigned parity, Location loc) {
121 std::string emptyName = "empty_" + std::to_string(parity);
122 if (auto existing = moduleOp.lookupSymbol<AIE::DeviceOp>(emptyName)) {
123 // Shared reset PDIs retain every load and trailing sequence's provenance.
124 loc = FusedLoc::get(moduleOp.getContext(), {existing.getLoc(), loc});
125 existing->setLoc(loc);
126 existing.getRegion().front().getTerminator()->setLoc(loc);
127 return existing;
128 }
129
130 OpBuilder builder(moduleOp.getContext());
131 builder.setInsertionPointToStart(moduleOp.getBody());
132 auto emptyDevice = AIE::DeviceOp::create(
133 builder, loc, deviceType, builder.getStringAttr(emptyName), nullptr);
134 emptyDevice.getRegion().emplaceBlock();
135 builder.setInsertionPointToEnd(&emptyDevice.getRegion().front());
136 AIE::EndOp::create(builder, loc);
137 return emptyDevice;
138}
139
140// A control-packet reload: the load_pdi it replaces, the device it streams,
141// and the overlay load ahead of it.
142struct CtrlPktReload {
143 NpuLoadPdiOp load;
144 AIE::DeviceOp device;
145 NpuLoadPdiOp preload;
146 AIE::DeviceOp overlay;
147};
148
149// Set `builder` at the next load_pdi, or at the block's end if there is none.
150static void setInsertionPointToSegmentEnd(OpBuilder &builder,
151 NpuLoadPdiOp loadPdiOp) {
152 Operation *op = loadPdiOp->getNextNode();
153 while (op && !isa<NpuLoadPdiOp>(op) && !op->hasTrait<OpTrait::IsTerminator>())
154 op = op->getNextNode();
155 if (op)
156 builder.setInsertionPoint(op);
157 else
158 builder.setInsertionPointToEnd(loadPdiOp->getBlock());
159}
160
161// Helper to transform a single load_pdi operation. Without `keepPreload` the
162// reset or overlay load is left out. With `teardown` the configuration's
163// teardown goes where it ends. A control packet configuration under teardown
164// goes in here, its writes from `configData` and its teardown's from
165// `teardownData`, in program order, since masked writes fold onto the control
166// packets before them. Without teardown, control packets go in once every
167// load_pdi is known (`ctrlPktReloads`), so a sequence's loads share them.
168static LogicalResult transformLoadPdi(
169 NpuLoadPdiOp loadPdiOp, ModuleOp moduleOp, unsigned index,
170 AIEX::ExpandMode defaultMode, bool keepPreload, bool teardown,
171 AIEX::BlockwriteData *configData, AIEX::BlockwriteData *teardownData,
172 SmallVectorImpl<CtrlPktReload> &ctrlPktReloads, OverlayCopies &copies) {
173 OpBuilder builder(loadPdiOp);
174
175 // Only process load_pdi ops that reference a device
176 auto deviceRefAttr = loadPdiOp.getDeviceRefAttr();
177 if (!deviceRefAttr) {
178 return success();
179 }
180
181 // Per-op annotation takes precedence; fall back to pass default
182 AIEX::ExpandMode mode = loadPdiOp.getExpandMode().value_or(defaultMode);
183 if (mode == AIEX::ExpandMode::none)
184 return success();
185 bool ctrlPkt = (mode == AIEX::ExpandMode::ctrlpkt);
186
187 auto referencedDevice = moduleOp.lookupSymbol<AIE::DeviceOp>(deviceRefAttr);
188 if (!referencedDevice) {
189 loadPdiOp.emitError("Referenced symbol '")
190 << deviceRefAttr.getValue() << "' is not a device";
191 return failure();
192 }
193
194 AIE::DeviceOp overlay;
195 if (ctrlPkt) {
196 overlay = controlOverlayOf(referencedDevice);
197 if (!overlay)
198 return referencedDevice.emitOpError(
199 "requires an overlay symbol reference for control-packet "
200 "configuration");
201 }
202
203 // Consecutive preloads alternate between two PDIs with the same contents,
204 // since the firmware skips a load of the PDI it loaded last.
205 if (keepPreload) {
206 FlatSymbolRefAttr preloadRef;
207 if (ctrlPkt) {
208 preloadRef = FlatSymbolRefAttr::get(
209 overlayPreload(overlay, index % 2, copies).getSymNameAttr());
210 } else {
211 AIE::DeviceOp emptyDevice =
212 getOrCreateEmptyDevice(moduleOp, referencedDevice.getDevice(),
213 index % 2, loadPdiOp.getLoc());
214 preloadRef = FlatSymbolRefAttr::get(emptyDevice.getSymNameAttr());
215 }
216 auto expandNone =
217 AIEX::ExpandModeAttr::get(builder.getContext(), AIEX::ExpandMode::none);
218 if (ctrlPkt)
219 NpuLoadPdiOp::create(builder, loadPdiOp.getLoc(), preloadRef,
220 /*id=*/nullptr, /*size=*/nullptr,
221 /*address=*/nullptr, expandNone);
222 else
223 NpuLoadPdiOp::create(builder, loadPdiOp.getLoc(), preloadRef,
224 loadPdiOp.getIdAttr(), loadPdiOp.getSizeAttr(),
225 loadPdiOp.getAddressAttr(), expandNone);
226 }
227 Operation *beforeConfig = loadPdiOp->getPrevNode();
228
229 if (!ctrlPkt) {
230 NpuWriteConfigOp::create(builder, loadPdiOp.getLoc(), deviceRefAttr);
231 if (teardown) {
232 setInsertionPointToSegmentEnd(builder, loadPdiOp);
233 NpuWriteTeardownOp::create(builder, loadPdiOp.getLoc(), deviceRefAttr);
234 }
235 loadPdiOp.erase();
236 return success();
237 }
238 if (!teardown) {
239 ctrlPktReloads.push_back({loadPdiOp, referencedDevice,
240 cast<NpuLoadPdiOp>(beforeConfig), overlay});
241 return success();
242 }
243
246 builder, referencedDevice, *configData, /*clElfDir=*/"", outputType,
247 /*skipCtrlPktOverlay=*/true))) {
248 loadPdiOp.emitError("Failed to generate configuration operations");
249 return failure();
250 }
251 if (failed(verifyOverlayReachesTiles(
252 loadPdiOp, overlay,
253 {beforeConfig ? std::next(beforeConfig->getIterator())
254 : loadPdiOp->getBlock()->begin(),
255 loadPdiOp->getIterator()})))
256 return failure();
257
258 // Erase the load_pdi before inserting the teardown, so the teardown's masked
259 // writes fold onto the configuration's writes instead of stopping at it.
260 Location loc = loadPdiOp.getLoc();
261 setInsertionPointToSegmentEnd(builder, loadPdiOp);
262 loadPdiOp.erase();
264 builder, referencedDevice, *teardownData, outputType,
265 /*skipCtrlPktOverlay=*/true))) {
266 emitError(loc, "Failed to generate teardown operations");
267 return failure();
268 }
269 return success();
270}
271
272// The checks that need no expansion, so the pass fails before it changes the
273// IR.
274static LogicalResult
275verifyExpansion(ModuleOp module, ArrayRef<NpuLoadPdiOp> loadPdiOps,
276 function_ref<AIEX::ExpandMode(NpuLoadPdiOp)> expandMode,
277 ArrayRef<bool> keepPreloads, bool teardown, bool initEntry) {
278 if (initEntry && !teardown)
279 return module.emitError(
280 "aie-expand-load-pdi: init-entry requires teardown");
281 if (initEntry)
282 for (auto device : module.getOps<AIE::DeviceOp>())
283 if (Operation *existing = device.lookupSymbol(initEntrySequenceName))
284 return existing->emitOpError()
285 << "is named '" << initEntrySequenceName
286 << "', which aie-expand-load-pdi reserves under init-entry";
287 // A load left alone is a PDI load; an expanded one resets only through the
288 // preload it gets.
289 llvm::MapVector<AIE::RuntimeSequenceOp, SmallVector<AIEX::ConfigStep>> steps;
290 for (auto [load, keepPreload] : llvm::zip_equal(loadPdiOps, keepPreloads)) {
291 NpuLoadPdiOp loadPdiOp = load;
292 if (auto seq = loadPdiOp->getParentOfType<AIE::RuntimeSequenceOp>()) {
293 FlatSymbolRefAttr ref = loadPdiOp.getDeviceRefAttr();
294 bool expanded = expandMode(loadPdiOp) != AIEX::ExpandMode::none;
295 steps[seq].push_back(
296 {loadPdiOp, expanded ? NpuLoadPdiOp() : loadPdiOp,
297 expanded && keepPreload,
298 ref ? module.lookupSymbol<AIE::DeviceOp>(ref) : nullptr});
299 }
300 }
301 for (auto &[seq, seqSteps] : steps)
302 if (failed(AIEX::checkResidentsSurvive(seq, seqSteps)))
303 return failure();
304 if (!teardown)
305 return success();
306 for (NpuLoadPdiOp loadPdiOp : loadPdiOps) {
307 if (expandMode(loadPdiOp) == AIEX::ExpandMode::none)
308 continue;
309 // write_teardown's verifier checks this too, but inline-config leaves no
310 // write_teardown to verify.
311 auto dev = module.lookupSymbol<AIE::DeviceOp>(loadPdiOp.getDeviceRefAttr());
312 if (Operation *start = dev ? AIEX::findShimDmaStart(dev) : nullptr)
313 return start->emitOpError(
314 "starts a shim DMA channel, which teardown cannot stop");
315 }
316 return success();
317}
318
319struct AIEExpandLoadPdiPass
320 : public xilinx::AIEX::impl::AIEExpandLoadPdiBase<AIEExpandLoadPdiPass> {
321 using AIEExpandLoadPdiBase::AIEExpandLoadPdiBase;
322
323 void getDependentDialects(DialectRegistry &registry) const override {
324 registry.insert<arith::ArithDialect, memref::MemRefDialect, AIE::AIEDialect,
325 AIEX::AIEXDialect>();
326 }
327
328 void runOnOperation() override {
329 auto module = getOperation();
330
331 // Collect all load_pdi operations in program order;
332 // need to collect once, then transform all collected ops;
333 // since the transform inserts a new preload load_pdi, we can't transform
334 // as we walk or it'd infinitely recurse.
335 SmallVector<NpuLoadPdiOp> loadPdiOps;
336
337 module.walk(
338 [&](NpuLoadPdiOp loadPdiOp) { loadPdiOps.push_back(loadPdiOp); });
339
340 // Map the legacy bool option to the new ExpandMode enum.
341 AIEX::ExpandMode defaultMode =
342 clCtrlPkt ? AIEX::ExpandMode::ctrlpkt : AIEX::ExpandMode::write32;
343
344 auto expandMode = [&](NpuLoadPdiOp loadPdiOp) {
345 return loadPdiOp.getDeviceRefAttr()
346 ? loadPdiOp.getExpandMode().value_or(defaultMode)
347 : AIEX::ExpandMode::none;
348 };
349 // Per enclosing runtime sequence, the parity of the FIRST and LAST of its
350 // empty-device resets and of its overlay loads, plus the device type, and
351 // the kind of its last load, which leaves the array as the next dispatch
352 // finds it. `transformLoadPdi` picks the preload as `index % 2` over the
353 // module-wide op order, and that order includes ops this pass skips, so a
354 // sequence's first preload is not necessarily the even one and its parity
355 // cannot be recovered from a count. Captured BEFORE transforming, which
356 // erases the ops.
357 using ArrayState = std::pair<AIEX::ExpandMode, FlatSymbolRefAttr>;
358 struct PreloadParity {
359 unsigned firstParity = 0;
360 unsigned lastParity = 0;
361 bool seen = false;
362 AIE::AIEDevice device = {};
363 AIE::DeviceOp firstOverlay, lastOverlay;
364 };
365 struct SequenceLoads {
366 std::array<PreloadParity, 2> preloads;
367 ArrayState last = {AIEX::ExpandMode::none, {}};
368 };
369 llvm::MapVector<AIE::RuntimeSequenceOp, SequenceLoads> sequences;
370 for (auto [index, loadPdiOp] : llvm::enumerate(loadPdiOps)) {
371 auto seq = loadPdiOp->getParentOfType<AIE::RuntimeSequenceOp>();
372 if (!seq)
373 continue;
374 SequenceLoads &loads = sequences[seq];
375 AIEX::ExpandMode mode = expandMode(loadPdiOp);
376 loads.last = {mode, {}};
377 if (mode == AIEX::ExpandMode::none)
378 continue;
379 auto dev =
380 module.lookupSymbol<AIE::DeviceOp>(loadPdiOp.getDeviceRefAttr());
381 if (!dev)
382 continue;
383 auto overlay = mode == AIEX::ExpandMode::ctrlpkt ? controlOverlayOf(dev)
384 : AIE::DeviceOp{};
385 if (mode == AIEX::ExpandMode::ctrlpkt && !overlay) {
386 dev.emitOpError("requires an overlay symbol reference for "
387 "control-packet configuration");
388 return signalPassFailure();
389 }
390 loads.last.second = overlay ? dev.getOverlayAttr() : FlatSymbolRefAttr{};
391 auto &entry = loads.preloads[mode == AIEX::ExpandMode::ctrlpkt];
392 if (!entry.seen) {
393 entry.firstParity = index % 2;
394 entry.seen = true;
395 entry.firstOverlay = overlay;
396 }
397 entry.lastParity = index % 2;
398 entry.lastOverlay = overlay;
399 entry.device = dev.getDevice();
400 }
401
402 // Teardown leaves the array ready for the next configuration of the same
403 // kind, so only a sequence's first load, or one after a load of another
404 // kind, needs its preload. A load this pass leaves alone sets up a
405 // configuration no teardown undoes, so the load after it keeps its preload.
406 // The host may dispatch a device's sequences in any order, so with an init
407 // entry they start without a preload only if each ends torn down by the
408 // same kind, and `reconfig_init` holds that kind's preload.
409 llvm::MapVector<AIE::DeviceOp, ArrayState> initEntries;
410 if (clInitEntry) {
411 for (auto &[seq, loads] : sequences)
412 initEntries.try_emplace(seq->getParentOfType<AIE::DeviceOp>(),
413 loads.last);
414 for (auto &[seq, loads] : sequences) {
415 auto device = seq->getParentOfType<AIE::DeviceOp>();
416 auto *it = initEntries.find(device);
417 if (it != initEntries.end() &&
418 (loads.last.first == AIEX::ExpandMode::none ||
419 loads.last != it->second))
420 initEntries.erase(it);
421 }
422 }
423
424 // A load gets a reset or overlay preload unless a teardown of the same kind
425 // left the array ready for it.
426 SmallVector<bool> keepPreloads;
427 llvm::DenseMap<Operation *, std::optional<ArrayState>> arrayState;
428 for (NpuLoadPdiOp loadPdiOp : loadPdiOps) {
429 auto seq = loadPdiOp->getParentOfType<AIE::RuntimeSequenceOp>();
430 std::optional<ArrayState> start;
431 if (seq)
432 if (auto *it = initEntries.find(seq->getParentOfType<AIE::DeviceOp>());
433 it != initEntries.end())
434 start = it->second;
435 std::optional<ArrayState> &state =
436 arrayState.try_emplace(seq, start).first->second;
437 auto dev =
438 module.lookupSymbol<AIE::DeviceOp>(loadPdiOp.getDeviceRefAttr());
439 auto mode = expandMode(loadPdiOp);
440 ArrayState next = {mode, dev && mode == AIEX::ExpandMode::ctrlpkt
441 ? dev.getOverlayAttr()
442 : FlatSymbolRefAttr{}};
443 keepPreloads.push_back(!clTeardown || state != next);
444 state = next;
445 }
446
447 if (failed(verifyExpansion(module, loadPdiOps, expandMode, keepPreloads,
448 clTeardown, clInitEntry)))
449 return signalPassFailure();
450
451 OverlayCopies copies;
452 SmallVector<CtrlPktReload> ctrlPktReloads;
453 llvm::DenseMap<AIE::DeviceOp, AIEX::BlockwriteData> configData,
454 teardownData;
455 for (auto [idx, loadPdiOp] : llvm::enumerate(loadPdiOps)) {
456 bool keepPreload = keepPreloads[idx];
457 AIEX::BlockwriteData *config = nullptr, *teardown = nullptr;
458 if (clTeardown && expandMode(loadPdiOp) == AIEX::ExpandMode::ctrlpkt) {
459 auto device = loadPdiOp->getParentOfType<AIE::DeviceOp>();
460 config =
461 &configData.try_emplace(device, device, "loadpdi_").first->second;
462 teardown = &teardownData.try_emplace(device, device, "teardown_")
463 .first->second;
464 }
465 if (failed(transformLoadPdi(loadPdiOp, module, idx, defaultMode,
466 keepPreload, clTeardown, config, teardown,
467 ctrlPktReloads, copies))) {
468 signalPassFailure();
469 return;
470 }
471 }
472
473 SmallVector<std::pair<Operation *, AIE::DeviceOp>> ctrlPktSites;
474 for (CtrlPktReload &reload : ctrlPktReloads)
475 ctrlPktSites.emplace_back(reload.load, reload.device);
476 if (failed(AIE::insertConfigOps(
478 signalPassFailure();
479 return;
480 }
481 for (CtrlPktReload &reload : ctrlPktReloads) {
482 if (failed(verifyOverlayReachesTiles(
483 reload.load, reload.overlay,
484 {std::next(reload.preload->getIterator()),
485 reload.load->getIterator()}))) {
486 signalPassFailure();
487 return;
488 }
489 reload.load.erase();
490 }
491
492 for (auto [device, kind] : initEntries) {
493 FlatSymbolRefAttr preloadRef =
494 kind.first == AIEX::ExpandMode::ctrlpkt
495 ? kind.second
496 : FlatSymbolRefAttr::get(
497 getOrCreateEmptyDevice(module, device.getDevice(), 0,
498 device.getLoc())
499 .getSymNameAttr());
500 OpBuilder builder(device.getContext());
501 builder.setInsertionPoint(
502 *device.getOps<AIE::RuntimeSequenceOp>().begin());
503 auto init = AIE::RuntimeSequenceOp::create(
504 builder, device.getLoc(),
505 builder.getStringAttr(initEntrySequenceName), BoolAttr{},
506 AIE::TraceBufferAttr{}, ArrayAttr{}, ArrayAttr{});
507 builder.setInsertionPointToStart(&init.getBody().emplaceBlock());
508 NpuLoadPdiOp::create(builder, device.getLoc(), preloadRef,
509 /*id=*/nullptr, /*size=*/nullptr,
510 /*address=*/nullptr,
511 /*expand_mode=*/
512 AIEX::ExpandModeAttr::get(builder.getContext(),
513 AIEX::ExpandMode::none));
514 }
515
516 if (clInlineConfig && failed(AIE::inlineWriteConfigs(module)))
517 return signalPassFailure();
518
519 // Under teardown a skipped preload follows only torn-down configurations
520 // (write_config's verifier checks this for resets), so nothing needs the
521 // append.
522 if (clTeardown)
523 return;
524
525 // The `index % 2` alternation above keeps two consecutive preloads on
526 // different PDIs WITHIN a sequence. But the host re-runs the whole sequence
527 // on every dispatch, so the alternation has to hold across that boundary
528 // too. When a sequence's last preload lands on the same PDI as its first,
529 // the firmware caches the address and no-ops the next dispatch's first
530 // load, and the configuration that follows lands on a device that was never
531 // reset. That is silent -- the first dispatch is correct and later ones
532 // return non-deterministic garbage.
533 //
534 // Append one more preload, of the parity opposite the last one, so the
535 // sequence ends somewhere its own start will not repeat. The empty PDI is a
536 // few hundred bytes, so the cost is negligible next to the configuration it
537 // guards.
538 for (auto &[seq, loads] : sequences) {
539 for (auto [ctrlPkt, info] : llvm::enumerate(loads.preloads)) {
540 if (!info.seen || info.firstParity != info.lastParity ||
541 info.firstOverlay != info.lastOverlay)
542 continue;
543 unsigned parity = 1 - info.lastParity;
544 FlatSymbolRefAttr preloadRef;
545 if (ctrlPkt) {
546 preloadRef = FlatSymbolRefAttr::get(
547 overlayPreload(info.lastOverlay, parity, copies)
548 .getSymNameAttr());
549 } else {
550 AIE::DeviceOp emptyDevice =
551 getOrCreateEmptyDevice(module, info.device, parity, seq.getLoc());
552 preloadRef = FlatSymbolRefAttr::get(emptyDevice.getSymNameAttr());
553 }
554 OpBuilder builder(seq.getContext());
555 Block &body = seq.getBody().front();
556 if (!body.empty() && body.back().hasTrait<OpTrait::IsTerminator>())
557 builder.setInsertionPoint(&body.back());
558 else
559 builder.setInsertionPointToEnd(&body);
560 NpuLoadPdiOp::create(builder, seq.getLoc(), preloadRef,
561 /*id=*/nullptr, /*size=*/nullptr,
562 /*address=*/nullptr,
563 /*expand_mode=*/
564 AIEX::ExpandModeAttr::get(seq.getContext(),
565 AIEX::ExpandMode::none));
566 }
567 }
568 }
569};
570
571} // namespace
572
573std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
575 return std::make_unique<AIEExpandLoadPdiPass>();
576}
constexpr llvm::StringLiteral initEntrySequenceName
Name of the runtime sequence aie-expand-load-pdi{init-entry} adds.
Definition AIEXPasses.h:100
mlir::Operation * findShimDmaStart(AIE::DeviceOp device)
LogicalResult checkResidentsSurvive(AIE::RuntimeSequenceOp seq, ArrayRef< ConfigStep > steps)
Definition AIEUtils.cpp:396
std::unique_ptr< mlir::OperationPass< mlir::ModuleOp > > createAIEExpandLoadPdiPass()
mlir::LogicalResult insertConfigOps(llvm::ArrayRef< std::pair< mlir::Operation *, xilinx::AIE::DeviceOp > > sites, AIEToConfigurationOutputType outputType)
mlir::LogicalResult inlineWriteConfigs(mlir::ModuleOp module)
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
mlir::LogicalResult generateAndInsertTeardownOps(mlir::OpBuilder &builder, xilinx::AIE::DeviceOp device, xilinx::AIEX::BlockwriteData &blockwriteData, AIEToConfigurationOutputType outputType=AIEToConfigurationOutputType::Transaction, bool skipCtrlPktOverlay=false)
struct Port { WireBundle bundle; int channel; bool operator==(const Port &rhs) const { return std::tie(bundle, channel)==std::tie(rhs.bundle, rhs.channel); } bool operator!=(const Port &rhs) const { return !(*this==rhs);} bool operator<(const Port &rhs) const { return std::tie(bundle, channel)< std::tie(rhs.bundle, rhs.channel); } friend std::ostream &operator<<(std::ostream &os, const Port &port) { os<< "("; os<< stringifyWireBundle(port.bundle).str(); os<< ": "<< std::to_string(port.channel)<< ")"; return os; } friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Port &port) { os<< to_string(port); return os; } } Port
Definition AIEDialect.h:265