MLIR-AIE 1.4.6.dev
AIETargetModel.cpp
Go to the documentation of this file.
1//===- AIETargetModel.cpp ---------------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2019-2022 Xilinx, Inc.
4// Copyright (C) 2023 Advanced Micro Devices, Inc.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "llvm/ADT/STLExtras.h"
12#include "llvm/Support/ErrorHandling.h"
13#include <cstdint>
14#include <utility>
15
16using namespace llvm;
17
18namespace xilinx {
19namespace AIE {
20
21namespace {
22
23std::string getModuleForTile(const AIETargetModel &model, TileID tile,
24 bool isMem) {
25 if (model.isShimNOCorPLTile(tile.col, tile.row))
26 return "shim";
27 if (model.isMemTile(tile.col, tile.row))
28 return "memory_tile";
29 return isMem ? std::string("memory") : std::string("core");
30}
31
32// Get module name for event lookups (events database uses different names)
33std::string getModuleForTileEvents(const AIETargetModel &model, TileID tile,
34 bool isMem) {
35 if (model.isShimNOCorPLTile(tile.col, tile.row))
36 return "pl"; // Events database uses "pl" for shim tiles
37 if (model.isMemTile(tile.col, tile.row))
38 return "mem_tile"; // Events database uses "mem_tile" instead of
39 // "memory_tile"
40 // AIE4 compute tiles number memory and DMA events in the core module.
41 if (isMem && model.getTargetArch() == AIEArch::AIE4)
42 return "core";
43 return isMem ? std::string("memory") : std::string("core");
44}
45
46} // namespace
47
49
50// Base class implementations for register database
51
52std::unique_ptr<RegisterDatabase> AIETargetModel::loadRegisterDatabase() const {
53 // Default: no register database available
54 return nullptr;
55}
56
58 std::call_once(regDBInitFlag, [this]() { regDB = loadRegisterDatabase(); });
59 return regDB.get();
60}
61
62const RegisterInfo *AIETargetModel::lookupRegister(llvm::StringRef name,
63 TileID tile,
64 bool isMem) const {
65 const auto *db = getRegisterDatabase();
66 if (!db)
67 return nullptr;
68 return db->lookupRegister(name, getModuleForTile(*this, tile, isMem));
69}
70
72 uint32_t offset) const {
73 if ((offset & 3) || !isValidTile(tile) ||
74 (getTargetArch() != AIEArch::AIE2 && getTargetArch() != AIEArch::AIE2p))
75 return false;
76 auto inRange = [offset](uint32_t base, uint32_t bytes) {
77 return offset >= base && offset - base < bytes;
78 };
79 if (isCoreTile(tile.col, tile.row) &&
80 inRange(0x20000, getProgramMemorySize()))
81 return true;
82 if ((isCoreTile(tile.col, tile.row) && inRange(0, getLocalMemorySize())) ||
83 (isMemTile(tile.col, tile.row) && inRange(0, getMemTileSize())))
84 return true;
85 if (isCoreTile(tile.col, tile.row) || isMemTile(tile.col, tile.row) ||
86 isShimNOCTile(tile.col, tile.row))
87 if (const DmaBdLayout *layout = getDmaBdLayout(tile.col, tile.row))
88 for (uint32_t descriptor = 0; descriptor < getNumBDs(tile.col, tile.row);
89 ++descriptor)
90 if (inRange(getDmaBdAddress(tile.col, tile.row, descriptor) &
91 ((1u << getRowShift()) - 1),
92 4 * layout->numWords))
93 return true;
94 const RegisterDatabase *database = getRegisterDatabase();
95 const RegisterInfo *reg =
96 database ? database->lookupRegisterByOffset(
97 offset, getModuleForTile(*this, tile, false))
98 : nullptr;
99 if (!reg && database)
100 reg = database->lookupRegisterByOffset(offset,
101 getModuleForTile(*this, tile, true));
102 if (!reg)
103 return false;
104 llvm::StringRef name = reg->name;
105 return name.starts_with("Stream_Switch_Master_Config_") ||
106 name.starts_with("Stream_Switch_Slave_Config_") ||
107 (name.starts_with("Stream_Switch_Slave_") && name.contains("_Slot")) ||
108 (isShimNOCorPLTile(tile.col, tile.row) &&
109 (name == "Mux_Config" || name == "Demux_Config"));
110}
111
112std::optional<uint32_t> AIETargetModel::lookupEvent(llvm::StringRef name,
113 TileID tile,
114 bool isMem) const {
115 const auto *db = getRegisterDatabase();
116 if (!db)
117 return std::nullopt;
118 return db->lookupEvent(name, getModuleForTileEvents(*this, tile, isMem));
119}
120
121std::optional<uint32_t>
123 uint32_t value) const {
124 const auto *db = getRegisterDatabase();
125 if (!db)
126 return std::nullopt;
127 return db->encodeFieldValue(field, value);
128}
129
130std::optional<uint32_t>
132 uint32_t width = field.getWidth();
133 if (width == 0 || width > 32 || field.bit_end >= 32)
134 return std::nullopt;
135
136 uint64_t mask = (width == 32) ? 0xFFFFFFFFULL : ((1ULL << width) - 1ULL);
137 mask <<= field.bit_start;
138 if (mask > UINT32_MAX)
139 return std::nullopt;
140
141 return static_cast<uint32_t>(mask);
142}
143
144DenseMap<TileID, int>
145AIETargetModel::getTileToControllerIdMap(bool columnWiseUniqueIDs) const {
146 if (rows() <= 6) {
147 // Controller id combinations chosen to avoid packet flow deadlock due to
148 // single-level LUT bit-masking on packet header. Shim tile ids are < 16
149 // because the TCT actor id field is only 4 bits.
150 SmallVector<SmallVector<int>> validTileIds = {{15, 26, 27, 29, 30, 31},
151 {14, 21, 22, 23, 24, 25},
152 {13, 11, 17, 18, 19, 20},
153 {12, 28, 7, 8, 9, 10}};
154 if (!columnWiseUniqueIDs && columns() > (int)validTileIds.size())
155 llvm::report_fatal_error(
156 "Device has " + llvm::Twine(columns()) + " columns but only " +
157 llvm::Twine(validTileIds.size()) +
158 " globally-unique controller ID sets are defined; "
159 "use column-wise unique IDs mode.");
160 DenseMap<TileID, int> tileIDMap;
161 for (int col = 0; col < columns(); col++) {
162 for (int row = 0; row < rows(); row++) {
163 if (columnWiseUniqueIDs)
164 tileIDMap[{col, row}] = validTileIds[0][row];
165 else
166 tileIDMap[{col, row}] = validTileIds[col][row];
167 }
168 }
169 return tileIDMap;
170 }
171
172 // Devices with more than 6 rows use sequential assignment.
173 assert(columnWiseUniqueIDs &&
174 "Device has more tiles than candidate packet ids; "
175 "use column-wise unique IDs mode.");
176 DenseMap<TileID, int> tileIDMap;
177 int unusedPacketIdFrom = 0;
178 for (int col = 0; col < columns(); col++) {
179 if (columnWiseUniqueIDs)
180 unusedPacketIdFrom = 0;
181 for (int row = 0; row < rows(); row++)
182 tileIDMap[{col, row}] = unusedPacketIdFrom++;
183 }
184 return tileIDMap;
185}
186
187std::optional<uint32_t> AIETargetModel::resolvePortValue(llvm::StringRef value,
188 TileID tile,
189 bool master) const {
190 auto colonPos = value.find(':');
191 if (colonPos == StringRef::npos)
192 return std::nullopt;
193
194 StringRef portName = value.substr(0, colonPos);
195 StringRef channelStr = value.substr(colonPos + 1);
196
197 int channel;
198 if (channelStr.getAsInteger(10, channel) || channel < 0)
199 return std::nullopt;
200
201 WireBundle bundle;
202 if (portName.equals_insensitive("north")) {
203 bundle = WireBundle::North;
204 } else if (portName.equals_insensitive("south")) {
205 bundle = WireBundle::South;
206 } else if (portName.equals_insensitive("east")) {
207 bundle = WireBundle::East;
208 } else if (portName.equals_insensitive("west")) {
209 bundle = WireBundle::West;
210 } else if (portName.equals_insensitive("dma")) {
211 bundle = WireBundle::DMA;
212 } else if (portName.equals_insensitive("fifo")) {
213 bundle = WireBundle::FIFO;
214 } else if (portName.equals_insensitive("core")) {
215 bundle = WireBundle::Core;
216 } else if (portName.equals_insensitive("ctrl")) {
217 bundle = WireBundle::TileControl;
218 } else {
219 return std::nullopt;
220 }
221
222 return getStreamSwitchPortIndex(tile.col, tile.row, bundle,
223 static_cast<uint32_t>(channel), master);
224}
225
226///
227/// AIE1 TargetModel
228///
229
230AIEArch AIE1TargetModel::getTargetArch() const { return AIEArch::AIE1; }
231
232// Return the tile ID of the memory to the west of the given tile, if it exists.
233std::optional<TileID> AIE1TargetModel::getMemWest(TileID src) const {
234 bool isEvenRow = ((src.row % 2) == 0);
235 std::optional<TileID> ret;
236 if (isEvenRow)
237 ret = src;
238 else
239 ret = {src.col - 1, src.row};
240 if (!isValidTile(*ret))
241 ret.reset();
242 return ret;
243}
244
245// Return the tile ID of the memory to the west of the given tile, if it exists.
246std::optional<TileID> AIE1TargetModel::getMemEast(TileID src) const {
247 bool isEvenRow = (src.row % 2) == 0;
248 std::optional<TileID> ret;
249 if (isEvenRow)
250 ret = {src.col + 1, src.row};
251 else
252 ret = src;
253 if (!isValidTile(*ret))
254 ret.reset();
255 return ret;
256}
257
258// Return the tile ID of the memory to the west of the given tile, if it exists.
259std::optional<TileID> AIE1TargetModel::getMemNorth(TileID src) const {
260 std::optional<TileID> ret({src.col, src.row + 1});
261 if (!isValidTile(*ret))
262 ret.reset();
263 return ret;
264}
265
266std::optional<TileID> AIE1TargetModel::getMemSouth(TileID src) const {
267 std::optional<TileID> ret({src.col, src.row - 1});
268 // The first row doesn't have a tile memory south
269 if (!isValidTile(*ret) || ret->row == 0)
270 ret.reset();
271 return ret;
272}
273
274bool AIE1TargetModel::isMemWest(int srcCol, int srcRow, int dstCol,
275 int dstRow) const {
276 bool IsEvenRow = (srcRow % 2) == 0;
277 return (IsEvenRow && isInternal(srcCol, srcRow, dstCol, dstRow)) ||
278 (!IsEvenRow && isWest(srcCol, srcRow, dstCol, dstRow));
279}
280
281bool AIE1TargetModel::isMemEast(int srcCol, int srcRow, int dstCol,
282 int dstRow) const {
283 bool IsEvenRow = (srcRow % 2) == 0;
284 return (!IsEvenRow && isInternal(srcCol, srcRow, dstCol, dstRow)) ||
285 (IsEvenRow && isEast(srcCol, srcRow, dstCol, dstRow));
286}
287
288bool AIE1TargetModel::isMemNorth(int srcCol, int srcRow, int dstCol,
289 int dstRow) const {
290 return isNorth(srcCol, srcRow, dstCol, dstRow);
291}
292
293bool AIE1TargetModel::isMemSouth(int srcCol, int srcRow, int dstCol,
294 int dstRow) const {
295 return isSouth(srcCol, srcRow, dstCol, dstRow);
296}
297
298bool AIE1TargetModel::isLegalMemAffinity(int coreCol, int coreRow, int memCol,
299 int memRow) const {
300 bool IsEvenRow = ((coreRow % 2) == 0);
301
302 bool IsMemWest = (isWest(coreCol, coreRow, memCol, memRow) && !IsEvenRow) ||
303 (isInternal(coreCol, coreRow, memCol, memRow) && IsEvenRow);
304
305 bool IsMemEast = (isEast(coreCol, coreRow, memCol, memRow) && IsEvenRow) ||
306 (isInternal(coreCol, coreRow, memCol, memRow) && !IsEvenRow);
307
308 bool IsMemNorth = isNorth(coreCol, coreRow, memCol, memRow);
309 bool IsMemSouth = isSouth(coreCol, coreRow, memCol, memRow);
310
311 return IsMemSouth || IsMemNorth || IsMemWest || IsMemEast;
312}
313
314uint64_t AIE1TargetModel::getDmaBdAddress(int col, int row, uint32_t bd_id,
315 int channel,
316 AIE::DMAChannelDir direction) const {
317 uint32_t offset = 0;
318 if (isShimNOCTile(col, row)) {
319 offset = 0x0001D000 + (bd_id * 0x14);
320 } else if (isCoreTile(col, row)) {
321 offset = 0x0001D000 + (bd_id * 0x20);
322 } else {
323 llvm_unreachable(
324 "AIE1TargetModel::getDmaBdAddress called for non-DMA tile");
325 }
326 return getTileAddress(col, row) | offset;
327}
328
329uint32_t AIE1TargetModel::getDmaBdAddressOffset(int col, int row) const {
330 if (isShimNOCTile(col, row) || isCoreTile(col, row)) {
331 return 0;
332 }
333 llvm_unreachable(
334 "AIE1TargetModel::getDmaBdAddressOffset called for non-DMA tile");
335}
336
337uint32_t
338AIE1TargetModel::getDmaControlAddress(int col, int row, int channel,
339 AIE::DMAChannelDir direction) const {
340 uint32_t offset = 0;
341 if (isShimNOCTile(col, row))
342 offset = 0x0001D140 + (channel * 0x8);
343 else if (isCoreTile(col, row))
344 offset = 0x0001DE00 + (channel * 0x8);
345 else
346 llvm_unreachable(
347 "AIE1TargetModel::getDmaControlAddress called for non-DMA tile");
348
349 if (direction == AIE::DMAChannelDir::MM2S)
350 offset += 010;
351
352 return getTileAddress(col, row) | offset;
353}
354
355uint32_t
357 WireBundle bundle) const {
358 if (isShimNOCTile(col, row) || isShimPLTile(col, row))
359 switch (bundle) {
360 case WireBundle::FIFO:
361 return 2;
362 case WireBundle::North:
363 return 6;
364 case WireBundle::West: {
365 if (col == 0)
366 return 0;
367 return 4;
368 }
369 case WireBundle::South:
370 return 6;
371 case WireBundle::East: {
372 if (col == columns() - 1)
373 return 0;
374 return 4;
375 }
376 case WireBundle::TileControl:
377 return isShimNOCTile(col, row) ? 1 : 0;
378 default:
379 return 0;
380 }
381
382 switch (bundle) {
383 case WireBundle::Core:
384 case WireBundle::DMA:
385 case WireBundle::FIFO:
386 return 2;
387 case WireBundle::North: {
388 if (row == rows() - 1)
389 return 0;
390 return 6;
391 }
392 case WireBundle::West: {
393 if (col == 0)
394 return 0;
395 return 4;
396 }
397 case WireBundle::South:
398 return 4;
399 case WireBundle::East: {
400 if (col == columns() - 1)
401 return 0;
402 return 4;
403 }
404 case WireBundle::TileControl:
405 return 1;
406 default:
407 return 0;
408 }
409}
410
411uint32_t
413 WireBundle bundle) const {
414 if (isShimNOCTile(col, row) || isShimPLTile(col, row))
415 switch (bundle) {
416 case WireBundle::FIFO:
417 return 2;
418 case WireBundle::North:
419 return 4;
420 case WireBundle::West: {
421 if (col == 0)
422 return 0;
423 return 4;
424 }
425 case WireBundle::South:
426 return 8;
427 case WireBundle::East: {
428 if (col == columns() - 1)
429 return 0;
430 return 4;
431 }
432 case WireBundle::Trace:
433 return 1;
434 case WireBundle::TileControl:
435 return isShimNOCTile(col, row) ? 1 : 0;
436 default:
437 return 0;
438 }
439
440 switch (bundle) {
441 case WireBundle::Core:
442 case WireBundle::DMA:
443 case WireBundle::FIFO:
444 return 2;
445 case WireBundle::North: {
446 if (row == rows() - 1)
447 return 0;
448 return 4;
449 }
450 case WireBundle::West: {
451 if (col == 0)
452 return 0;
453 return 4;
454 }
455 case WireBundle::South:
456 return 6;
457 case WireBundle::East: {
458 if (col == columns() - 1)
459 return 0;
460 return 4;
461 }
462 case WireBundle::Trace:
463 return 2;
464 case WireBundle::TileControl:
465 return 1;
466 default:
467 return 0;
468 }
469}
470uint32_t
472 WireBundle bundle) const {
473 if (isShimNOCorPLTile(col, row))
474 switch (bundle) {
475 case WireBundle::DMA:
476 return 2;
477 case WireBundle::NOC:
478 return 4;
479 case WireBundle::PLIO:
480 return 6;
481 case WireBundle::South:
482 return 8; // Connection to the south port of the stream switch
483 default:
484 return 0;
485 }
486 return 0;
487}
488uint32_t
490 WireBundle bundle) const {
491 if (isShimNOCorPLTile(col, row))
492 switch (bundle) {
493 case WireBundle::DMA:
494 return 2;
495 case WireBundle::NOC:
496 return 4;
497 case WireBundle::PLIO:
498 return 8;
499 case WireBundle::South:
500 return 6; // Connection to the south port of the stream switch
501 default:
502 return 0;
503 }
504 return 0;
505}
506
508 WireBundle srcBundle, int srcChan,
509 WireBundle dstBundle,
510 int dstChan) const {
511 // Check Channel Id within the range
512 if (srcChan >= int(getNumSourceSwitchboxConnections(col, row, srcBundle)))
513 return false;
514 if (dstChan >= int(getNumDestSwitchboxConnections(col, row, dstBundle)))
515 return false;
516
517 // Memtile
518 if (isMemTile(col, row)) {
519 return false;
520 }
521 // Shimtile and Coretile currently share this trace-routing constraint;
522 // flagged by bugprone-branch-clone -- unconfirmed whether that's
523 // deliberate or a copy-paste that should differ per tile kind, needs
524 // hardware-team confirmation before changing.
525 // NOLINTBEGIN(bugprone-branch-clone)
526 if (isShimNOCorPLTile(col, row)) {
527 if (srcBundle == WireBundle::Trace)
528 return dstBundle == WireBundle::South;
529 return true;
530 }
531 // Coretile
532 if (isCoreTile(col, row)) {
533 if (srcBundle == WireBundle::Trace)
534 return dstBundle == WireBundle::South;
535 return true;
536 }
537 // NOLINTEND(bugprone-branch-clone)
538 return false;
539}
540
541std::vector<std::pair<uint32_t, uint32_t>>
543 return {std::pair(0, 64), std::pair(1, 128), std::pair(2, 256)};
544}
545
546std::optional<uint32_t>
547AIE1TargetModel::getLocalLockAddress(uint32_t lockId, TileID tile) const {
548 // This function is currently not supported for AIE1.
549 // In order to be implemented for this target model, the interface
550 // would need to change given the different way locks are written to in AIE1.
551 return std::nullopt;
552}
553
554namespace {
555namespace aie1_port_id {
556namespace core {
557
558// Slave port offset/size constants
559static constexpr uint32_t S_CORE_OFFSET = 0;
560static constexpr uint32_t S_CORE_SIZE = 2;
561static constexpr uint32_t S_CTRL_OFFSET = 4;
562static constexpr uint32_t S_CTRL_SIZE = 1;
563static constexpr uint32_t S_DMA_OFFSET = 2;
564static constexpr uint32_t S_DMA_SIZE = 2;
565static constexpr uint32_t S_EAST_OFFSET = 21;
566static constexpr uint32_t S_EAST_SIZE = 4;
567static constexpr uint32_t S_FIFO_OFFSET = 5;
568static constexpr uint32_t S_FIFO_SIZE = 2;
569static constexpr uint32_t S_NORTH_OFFSET = 17;
570static constexpr uint32_t S_NORTH_SIZE = 4;
571static constexpr uint32_t S_SOUTH_OFFSET = 7;
572static constexpr uint32_t S_SOUTH_SIZE = 6;
573static constexpr uint32_t S_TRACE_OFFSET = 25;
574static constexpr uint32_t S_TRACE_SIZE = 2;
575static constexpr uint32_t S_WEST_OFFSET = 13;
576static constexpr uint32_t S_WEST_SIZE = 4;
577
578// Master port offset/size constants
579static constexpr uint32_t M_CORE_OFFSET = 0;
580static constexpr uint32_t M_CORE_SIZE = 2;
581static constexpr uint32_t M_CTRL_OFFSET = 4;
582static constexpr uint32_t M_CTRL_SIZE = 1;
583static constexpr uint32_t M_DMA_OFFSET = 2;
584static constexpr uint32_t M_DMA_SIZE = 2;
585static constexpr uint32_t M_EAST_OFFSET = 21;
586static constexpr uint32_t M_EAST_SIZE = 4;
587static constexpr uint32_t M_FIFO_OFFSET = 5;
588static constexpr uint32_t M_FIFO_SIZE = 2;
589static constexpr uint32_t M_NORTH_OFFSET = 15;
590static constexpr uint32_t M_NORTH_SIZE = 6;
591static constexpr uint32_t M_SOUTH_OFFSET = 7;
592static constexpr uint32_t M_SOUTH_SIZE = 4;
593static constexpr uint32_t M_WEST_OFFSET = 11;
594static constexpr uint32_t M_WEST_SIZE = 4;
595
596} // namespace core
597
598namespace shim {
599
600// Slave port offset/size constants
601static constexpr uint32_t S_CTRL_OFFSET = 0;
602static constexpr uint32_t S_CTRL_SIZE = 1;
603static constexpr uint32_t S_EAST_OFFSET = 19;
604static constexpr uint32_t S_EAST_SIZE = 4;
605static constexpr uint32_t S_FIFO_OFFSET = 1;
606static constexpr uint32_t S_FIFO_SIZE = 2;
607static constexpr uint32_t S_NORTH_OFFSET = 15;
608static constexpr uint32_t S_NORTH_SIZE = 4;
609static constexpr uint32_t S_SOUTH_OFFSET = 3;
610static constexpr uint32_t S_SOUTH_SIZE = 8;
611static constexpr uint32_t S_TRACE_OFFSET = 23;
612static constexpr uint32_t S_TRACE_SIZE = 1;
613static constexpr uint32_t S_WEST_OFFSET = 11;
614static constexpr uint32_t S_WEST_SIZE = 4;
615
616// Master port offset/size constants
617static constexpr uint32_t M_CTRL_OFFSET = 0;
618static constexpr uint32_t M_CTRL_SIZE = 1;
619static constexpr uint32_t M_EAST_OFFSET = 19;
620static constexpr uint32_t M_EAST_SIZE = 4;
621static constexpr uint32_t M_FIFO_OFFSET = 1;
622static constexpr uint32_t M_FIFO_SIZE = 2;
623static constexpr uint32_t M_NORTH_OFFSET = 13;
624static constexpr uint32_t M_NORTH_SIZE = 6;
625static constexpr uint32_t M_SOUTH_OFFSET = 3;
626static constexpr uint32_t M_SOUTH_SIZE = 6;
627static constexpr uint32_t M_WEST_OFFSET = 9;
628static constexpr uint32_t M_WEST_SIZE = 4;
629
630} // namespace shim
631} // namespace aie1_port_id
632} // anonymous namespace
633
635 int col, int row, WireBundle bundle, uint32_t port_num, bool master) const {
636 if (master) {
637 if (isCoreTile(col, row)) {
638 switch (bundle) {
639 case WireBundle::Core:
640 if (port_num >= aie1_port_id::core::M_CORE_SIZE)
641 return std::nullopt;
642 return aie1_port_id::core::M_CORE_OFFSET + port_num;
643 case WireBundle::TileControl:
644 if (port_num >= aie1_port_id::core::M_CTRL_SIZE)
645 return std::nullopt;
646 return aie1_port_id::core::M_CTRL_OFFSET + port_num;
647 case WireBundle::DMA:
648 if (port_num >= aie1_port_id::core::M_DMA_SIZE)
649 return std::nullopt;
650 return aie1_port_id::core::M_DMA_OFFSET + port_num;
651 case WireBundle::East:
652 if (port_num >= aie1_port_id::core::M_EAST_SIZE)
653 return std::nullopt;
654 return aie1_port_id::core::M_EAST_OFFSET + port_num;
655 case WireBundle::FIFO:
656 if (port_num >= aie1_port_id::core::M_FIFO_SIZE)
657 return std::nullopt;
658 return aie1_port_id::core::M_FIFO_OFFSET + port_num;
659 case WireBundle::North:
660 if (port_num >= aie1_port_id::core::M_NORTH_SIZE)
661 return std::nullopt;
662 return aie1_port_id::core::M_NORTH_OFFSET + port_num;
663 case WireBundle::South:
664 if (port_num >= aie1_port_id::core::M_SOUTH_SIZE)
665 return std::nullopt;
666 return aie1_port_id::core::M_SOUTH_OFFSET + port_num;
667 case WireBundle::West:
668 if (port_num >= aie1_port_id::core::M_WEST_SIZE)
669 return std::nullopt;
670 return aie1_port_id::core::M_WEST_OFFSET + port_num;
671 default:
672 return std::nullopt;
673 }
674 } else if (isShimNOCorPLTile(col, row)) {
675 switch (bundle) {
676 case WireBundle::TileControl:
677 if (port_num >= aie1_port_id::shim::M_CTRL_SIZE)
678 return std::nullopt;
679 return aie1_port_id::shim::M_CTRL_OFFSET + port_num;
680 case WireBundle::East:
681 if (port_num >= aie1_port_id::shim::M_EAST_SIZE)
682 return std::nullopt;
683 return aie1_port_id::shim::M_EAST_OFFSET + port_num;
684 case WireBundle::FIFO:
685 if (port_num >= aie1_port_id::shim::M_FIFO_SIZE)
686 return std::nullopt;
687 return aie1_port_id::shim::M_FIFO_OFFSET + port_num;
688 case WireBundle::North:
689 if (port_num >= aie1_port_id::shim::M_NORTH_SIZE)
690 return std::nullopt;
691 return aie1_port_id::shim::M_NORTH_OFFSET + port_num;
692 case WireBundle::South:
693 if (port_num >= aie1_port_id::shim::M_SOUTH_SIZE)
694 return std::nullopt;
695 return aie1_port_id::shim::M_SOUTH_OFFSET + port_num;
696 case WireBundle::West:
697 if (port_num >= aie1_port_id::shim::M_WEST_SIZE)
698 return std::nullopt;
699 return aie1_port_id::shim::M_WEST_OFFSET + port_num;
700 default:
701 return std::nullopt;
702 }
703 } else {
704 return std::nullopt;
705 }
706 } else {
707 if (isCoreTile(col, row)) {
708 switch (bundle) {
709 case WireBundle::Core:
710 if (port_num >= aie1_port_id::core::S_CORE_SIZE)
711 return std::nullopt;
712 return aie1_port_id::core::S_CORE_OFFSET + port_num;
713 case WireBundle::TileControl:
714 if (port_num >= aie1_port_id::core::S_CTRL_SIZE)
715 return std::nullopt;
716 return aie1_port_id::core::S_CTRL_OFFSET + port_num;
717 case WireBundle::DMA:
718 if (port_num >= aie1_port_id::core::S_DMA_SIZE)
719 return std::nullopt;
720 return aie1_port_id::core::S_DMA_OFFSET + port_num;
721 case WireBundle::East:
722 if (port_num >= aie1_port_id::core::S_EAST_SIZE)
723 return std::nullopt;
724 return aie1_port_id::core::S_EAST_OFFSET + port_num;
725 case WireBundle::FIFO:
726 if (port_num >= aie1_port_id::core::S_FIFO_SIZE)
727 return std::nullopt;
728 return aie1_port_id::core::S_FIFO_OFFSET + port_num;
729 case WireBundle::North:
730 if (port_num >= aie1_port_id::core::S_NORTH_SIZE)
731 return std::nullopt;
732 return aie1_port_id::core::S_NORTH_OFFSET + port_num;
733 case WireBundle::South:
734 if (port_num >= aie1_port_id::core::S_SOUTH_SIZE)
735 return std::nullopt;
736 return aie1_port_id::core::S_SOUTH_OFFSET + port_num;
737 case WireBundle::Trace:
738 if (port_num >= aie1_port_id::core::S_TRACE_SIZE)
739 return std::nullopt;
740 return aie1_port_id::core::S_TRACE_OFFSET + port_num;
741 case WireBundle::West:
742 if (port_num >= aie1_port_id::core::S_WEST_SIZE)
743 return std::nullopt;
744 return aie1_port_id::core::S_WEST_OFFSET + port_num;
745 default:
746 return std::nullopt;
747 }
748 } else if (isShimNOCorPLTile(col, row)) {
749 switch (bundle) {
750 case WireBundle::TileControl:
751 if (port_num >= aie1_port_id::shim::S_CTRL_SIZE)
752 return std::nullopt;
753 return aie1_port_id::shim::S_CTRL_OFFSET + port_num;
754 case WireBundle::East:
755 if (port_num >= aie1_port_id::shim::S_EAST_SIZE)
756 return std::nullopt;
757 return aie1_port_id::shim::S_EAST_OFFSET + port_num;
758 case WireBundle::FIFO:
759 if (port_num >= aie1_port_id::shim::S_FIFO_SIZE)
760 return std::nullopt;
761 return aie1_port_id::shim::S_FIFO_OFFSET + port_num;
762 case WireBundle::North:
763 if (port_num >= aie1_port_id::shim::S_NORTH_SIZE)
764 return std::nullopt;
765 return aie1_port_id::shim::S_NORTH_OFFSET + port_num;
766 case WireBundle::South:
767 if (port_num >= aie1_port_id::shim::S_SOUTH_SIZE)
768 return std::nullopt;
769 return aie1_port_id::shim::S_SOUTH_OFFSET + port_num;
770 case WireBundle::Trace:
771 if (port_num >= aie1_port_id::shim::S_TRACE_SIZE)
772 return std::nullopt;
773 return aie1_port_id::shim::S_TRACE_OFFSET + port_num;
774 case WireBundle::West:
775 if (port_num >= aie1_port_id::shim::S_WEST_SIZE)
776 return std::nullopt;
777 return aie1_port_id::shim::S_WEST_OFFSET + port_num;
778 default:
779 return std::nullopt;
780 }
781 } else {
782 return std::nullopt;
783 }
784 }
785}
786
787///
788/// AIE2 TargetModel
789///
790
791std::unique_ptr<RegisterDatabase>
795
796AIEArch AIE2TargetModel::getTargetArch() const { return AIEArch::AIE2; }
797
798// Return the tile ID of the memory to the west of the given tile, if it exists.
799std::optional<TileID> AIE2TargetModel::getMemWest(TileID src) const {
800 std::optional<TileID> ret({src.col - 1, src.row});
801 if (!isValidTile(*ret))
802 ret.reset();
803 return ret;
804}
805
806// Return the tile ID of the memory to the east of the given tile (ie self), if
807// it exists.
808std::optional<TileID> AIE2TargetModel::getMemEast(TileID src) const {
809 std::optional ret = src;
810 if (!isValidTile(*ret))
811 ret.reset();
812 return ret;
813}
814
815// Return the tile ID of the memory to the north of the given tile, if it
816// exists.
817std::optional<TileID> AIE2TargetModel::getMemNorth(TileID src) const {
818 std::optional<TileID> ret({src.col, src.row + 1});
819 if (!isValidTile(*ret))
820 ret.reset();
821 return ret;
822}
823
824std::optional<TileID> AIE2TargetModel::getMemSouth(TileID src) const {
825 std::optional<TileID> ret({src.col, src.row - 1});
826 // The first row doesn't have a tile memory south
827 // Memtiles don't have memory adjacency to neighboring core tiles.
828 if (!isValidTile(*ret) || ret->row == 0 || isMemTile(ret->col, ret->row))
829 ret.reset();
830 return ret;
831}
832
833bool AIE2TargetModel::isMemWest(int srcCol, int srcRow, int dstCol,
834 int dstRow) const {
835 return isWest(srcCol, srcRow, dstCol, dstRow);
836}
837
838bool AIE2TargetModel::isMemEast(int srcCol, int srcRow, int dstCol,
839 int dstRow) const {
840 return isInternal(srcCol, srcRow, dstCol, dstRow);
841}
842
843bool AIE2TargetModel::isMemNorth(int srcCol, int srcRow, int dstCol,
844 int dstRow) const {
845 return isNorth(srcCol, srcRow, dstCol, dstRow);
846}
847
848bool AIE2TargetModel::isMemSouth(int srcCol, int srcRow, int dstCol,
849 int dstRow) const {
850 return isSouth(srcCol, srcRow, dstCol, dstRow);
851}
852
853bool AIE2TargetModel::isLegalMemAffinity(int coreCol, int coreRow, int memCol,
854 int memRow) const {
855
856 bool IsMemWest = isMemWest(coreCol, coreRow, memCol, memRow);
857 bool IsMemEast = isMemEast(coreCol, coreRow, memCol, memRow);
858 bool IsMemNorth = isMemNorth(coreCol, coreRow, memCol, memRow);
859 bool IsMemSouth = isMemSouth(coreCol, coreRow, memCol, memRow);
860
861 if (isMemTile(coreCol, coreRow))
862 return isEast(coreCol, coreRow, memCol, memRow) ||
863 isInternal(coreCol, coreRow, memCol, memRow) ||
864 isWest(coreCol, coreRow, memCol, memRow);
865 return (IsMemSouth && !isMemTile(memCol, memRow)) || IsMemNorth ||
866 IsMemWest || IsMemEast;
867}
868
869uint64_t AIE2TargetModel::getDmaBdAddress(int col, int row, uint32_t bd_id,
870 int channel,
871 AIE::DMAChannelDir direction) const {
872 uint64_t offset = 0;
873 // Shimtile and Coretile currently compute the same offset; flagged by
874 // bugprone-branch-clone -- unconfirmed whether the DMA BD register bank
875 // genuinely shares this base across both tile kinds, needs hardware-team
876 // confirmation before changing.
877 // NOLINTBEGIN(bugprone-branch-clone)
878 if (isShimNOCTile(col, row)) {
879 offset = 0x0001D000 + bd_id * 0x20;
880 } else if (isMemTile(col, row)) {
881 offset = 0x000A0000 + bd_id * 0x20;
882 } else if (isCoreTile(col, row)) {
883 offset = 0x0001D000 + bd_id * 0x20;
884 } else {
885 llvm_unreachable(
886 "AIE2TargetModel::getDmaBdAddress called for non-DMA tile");
887 }
888 // NOLINTEND(bugprone-branch-clone)
889 return getTileAddress(col, row) | offset;
890}
891
892static DmaBdLayout makeAIE2ShimBdLayout() {
893 DmaBdLayout l;
894 l.numWords = 8;
895 l.bufferLength = {0, 0, 32};
896 l.bufferOffset = {1, 0, 32};
897 l.enablePacket = {2, 30, 1};
898 l.outOfOrderId = {2, 24, 6};
899 l.packetId = {2, 19, 5};
900 l.packetType = {2, 16, 3};
901 l.d0Size = {3, 20, 10};
902 l.d0Stride = {3, 0, 20};
903 l.burstLength = {4, 30, 2};
904 l.d1Size = {4, 20, 10};
905 l.d1Stride = {4, 0, 20};
906 l.axcache = {5, 24, 4};
907 l.d2Stride = {5, 0, 20};
908 l.iterationCurrent = {6, 26, 6};
909 l.iterationSize = {6, 20, 6};
910 l.iterationStride = {6, 0, 20};
911 l.nextBd = {7, 27, 4};
912 l.useNextBd = {7, 26, 1};
913 l.validBd = {7, 25, 1};
914 l.lockRelValue = {7, 18, 7};
915 l.lockRelId = {7, 13, 4};
916 l.lockAcqEnable = {7, 12, 1};
917 l.lockAcqValue = {7, 5, 7};
918 l.lockAcqId = {7, 0, 4};
919 return l;
920}
921
922// D2_Wrap and D3_Stepsize are left out: the lowering never programs them, and
923// the d2 extent is carried by buffer_length as on the other tiles.
924static DmaBdLayout makeAIE2MemTileBdLayout() {
925 DmaBdLayout l;
926 l.numWords = 8;
927 l.enablePacket = {0, 31, 1};
928 l.packetType = {0, 28, 3};
929 l.packetId = {0, 23, 5};
930 l.outOfOrderId = {0, 17, 6};
931 l.bufferLength = {0, 0, 17};
932 l.d0ZeroBefore = {1, 26, 6};
933 l.nextBd = {1, 20, 6};
934 l.useNextBd = {1, 19, 1};
935 l.bufferOffset = {1, 0, 19};
936 l.d0Size = {2, 17, 10};
937 l.d0Stride = {2, 0, 17};
938 l.d1ZeroBefore = {3, 27, 5};
939 l.d1Size = {3, 17, 10};
940 l.d1Stride = {3, 0, 17};
941 l.d2ZeroBefore = {4, 27, 4};
942 l.d2Stride = {4, 0, 17};
943 l.d2ZeroAfter = {5, 28, 4};
944 l.d1ZeroAfter = {5, 23, 5};
945 l.d0ZeroAfter = {5, 17, 6};
946 l.iterationCurrent = {6, 23, 6};
947 l.iterationSize = {6, 17, 6};
948 l.iterationStride = {6, 0, 17};
949 l.validBd = {7, 31, 1};
950 l.lockRelValue = {7, 24, 7};
951 l.lockRelId = {7, 16, 8};
952 l.lockAcqEnable = {7, 15, 1};
953 l.lockAcqValue = {7, 8, 7};
954 l.lockAcqId = {7, 0, 8};
955 return l;
956}
957
958// The core tile's buffer offset is its Base_Address field, in 32-bit words.
959static DmaBdLayout makeAIE2CoreTileBdLayout() {
960 DmaBdLayout l;
961 l.numWords = 6;
962 l.bufferOffset = {0, 14, 14};
963 l.bufferLength = {0, 0, 14};
964 l.enablePacket = {1, 30, 1};
965 l.outOfOrderId = {1, 24, 6};
966 l.packetId = {1, 19, 5};
967 l.packetType = {1, 16, 3};
968 l.d1Stride = {2, 13, 13};
969 l.d0Stride = {2, 0, 13};
970 l.d1Size = {3, 21, 8};
971 l.d0Size = {3, 13, 8};
972 l.d2Stride = {3, 0, 13};
973 l.iterationCurrent = {4, 19, 6};
974 l.iterationSize = {4, 13, 6};
975 l.iterationStride = {4, 0, 13};
976 l.nextBd = {5, 27, 4};
977 l.useNextBd = {5, 26, 1};
978 l.validBd = {5, 25, 1};
979 l.lockRelValue = {5, 18, 7};
980 l.lockRelId = {5, 13, 4};
981 l.lockAcqEnable = {5, 12, 1};
982 l.lockAcqValue = {5, 5, 7};
983 l.lockAcqId = {5, 0, 4};
984 return l;
985}
986
987const DmaBdLayout *AIE2TargetModel::getDmaBdLayout(AIETileType tileType) const {
988 static const DmaBdLayout shim = makeAIE2ShimBdLayout();
989 static const DmaBdLayout mem = makeAIE2MemTileBdLayout();
990 static const DmaBdLayout core = makeAIE2CoreTileBdLayout();
991 switch (tileType) {
992 case AIETileType::ShimNOCTile:
993 return &shim;
994 case AIETileType::MemTile:
995 return &mem;
996 case AIETileType::CoreTile:
997 return &core;
998 default:
999 return nullptr;
1000 }
1001}
1002
1003uint32_t AIE2TargetModel::getDmaBdAddressOffset(int col, int row) const {
1004 if (isCoreTile(col, row))
1005 return 0x0;
1006 return 0x4;
1007}
1008
1009uint32_t
1010AIE2TargetModel::getDmaControlAddress(int col, int row, int channel,
1011 AIE::DMAChannelDir direction) const {
1012 uint32_t offset = 0;
1013 if (isShimNOCTile(col, row)) {
1014 offset = 0x0001D200 + (channel * 0x8);
1015 if (direction == AIE::DMAChannelDir::MM2S)
1016 offset += 0x10;
1017 } else if (isMemTile(col, row)) {
1018 offset = 0x000A0600 + (channel * 0x8);
1019 if (direction == AIE::DMAChannelDir::MM2S)
1020 offset += 0x30;
1021 } else if (isCoreTile(col, row)) {
1022 offset = 0x0001DE00 + (channel * 0x8);
1023 if (direction == AIE::DMAChannelDir::MM2S)
1024 offset += 0x10;
1025 } else {
1026 llvm_unreachable(
1027 "AIE2TargetModel::getDmaControlAddress called for non-DMA tile");
1028 }
1029
1030 return getTileAddress(col, row) | offset;
1031}
1032
1033std::optional<uint32_t>
1034AIE2TargetModel::getDmaStatusAddress(int col, int row, int channel,
1035 AIE::DMAChannelDir direction) const {
1036 // Status registers sit one word apart per channel, unlike the task-queue
1037 // control registers above, which are two words apart.
1038 uint32_t offset = 0;
1039 if (isShimNOCTile(col, row)) {
1040 offset = 0x0001D220 + (channel * 0x4);
1041 if (direction == AIE::DMAChannelDir::MM2S)
1042 offset += 0x8;
1043 } else if (isMemTile(col, row)) {
1044 offset = 0x000A0660 + (channel * 0x4);
1045 if (direction == AIE::DMAChannelDir::MM2S)
1046 offset += 0x20;
1047 } else if (isCoreTile(col, row)) {
1048 offset = 0x0001DF00 + (channel * 0x4);
1049 if (direction == AIE::DMAChannelDir::MM2S)
1050 offset += 0x10;
1051 } else {
1052 return std::nullopt;
1053 }
1054
1055 return getTileAddress(col, row) | offset;
1056}
1057
1058uint32_t
1060 WireBundle bundle) const {
1061 if (isMemTile(col, row))
1062 switch (bundle) {
1063 case WireBundle::DMA:
1064 case WireBundle::North:
1065 return 6;
1066 case WireBundle::South:
1067 return 4;
1068 case WireBundle::TileControl:
1069 return 1;
1070 default:
1071 return 0;
1072 }
1073
1074 if (isShimNOCTile(col, row) || isShimPLTile(col, row))
1075 switch (bundle) {
1076 case WireBundle::FIFO:
1077 return 1;
1078 case WireBundle::North:
1079 return 6;
1080 case WireBundle::West: {
1081 if (col == 0)
1082 return 0;
1083 return 4;
1084 }
1085 case WireBundle::South:
1086 return 6;
1087 case WireBundle::East: {
1088 if (col == columns() - 1)
1089 return 0;
1090 return 4;
1091 }
1092 case WireBundle::TileControl:
1093 return isShimNOCTile(col, row) ? 1 : 0;
1094 default:
1095 return 0;
1096 }
1097
1098 switch (bundle) {
1099 case WireBundle::Core:
1100 return 1;
1101 case WireBundle::DMA:
1102 return 2;
1103 case WireBundle::FIFO:
1104 return 1;
1105 case WireBundle::North: {
1106 if (row == rows() - 1)
1107 return 0;
1108 return 6;
1109 }
1110 case WireBundle::West: {
1111 if (col == 0)
1112 return 0;
1113 return 4;
1114 }
1115 case WireBundle::South:
1116 return 4;
1117 case WireBundle::East: {
1118 if (col == columns() - 1)
1119 return 0;
1120 return 4;
1121 }
1122 case WireBundle::TileControl:
1123 return 1;
1124 default:
1125 return 0;
1126 }
1127}
1128
1129uint32_t
1131 WireBundle bundle) const {
1132 if (isMemTile(col, row))
1133 switch (bundle) {
1134 case WireBundle::DMA:
1135 return 6;
1136 case WireBundle::North:
1137 return 4;
1138 case WireBundle::South:
1139 return 6;
1140 case WireBundle::Trace:
1141 case WireBundle::TileControl:
1142 return 1;
1143 default:
1144 return 0;
1145 }
1146
1147 if (isShimNOCTile(col, row) || isShimPLTile(col, row))
1148 switch (bundle) {
1149 case WireBundle::FIFO:
1150 return 1;
1151 case WireBundle::North:
1152 return 4;
1153 case WireBundle::West: {
1154 if (col == 0)
1155 return 0;
1156 return 4;
1157 }
1158 case WireBundle::South:
1159 return 8;
1160 case WireBundle::East: {
1161 if (col == columns() - 1)
1162 return 0;
1163 return 4;
1164 }
1165 case WireBundle::Trace:
1166 return 1;
1167 case WireBundle::TileControl:
1168 return isShimNOCTile(col, row) ? 1 : 0;
1169 default:
1170 return 0;
1171 }
1172
1173 // compute/core tile
1174 switch (bundle) {
1175 case WireBundle::Core:
1176 return 1;
1177 case WireBundle::DMA:
1178 return 2;
1179 case WireBundle::FIFO:
1180 return 1;
1181 case WireBundle::North: {
1182 if (row == rows() - 1)
1183 return 0;
1184 return 4;
1185 }
1186 case WireBundle::West: {
1187 if (col == 0)
1188 return 0;
1189 return 4;
1190 }
1191 case WireBundle::South:
1192 return 6;
1193 case WireBundle::East: {
1194 if (col == columns() - 1)
1195 return 0;
1196 return 4;
1197 }
1198 case WireBundle::Trace:
1199 // Port 0: core trace. Port 1: memory trace.
1200 return 2;
1201 case WireBundle::TileControl:
1202 return 1;
1203 default:
1204 return 0;
1205 }
1206}
1207
1208uint32_t
1210 WireBundle bundle) const {
1211 if (isShimNOCorPLTile(col, row))
1212 switch (bundle) {
1213 case WireBundle::DMA:
1214 return 2;
1215 case WireBundle::NOC:
1216 return 4;
1217 case WireBundle::PLIO:
1218 return 6;
1219 case WireBundle::South:
1220 return 8; // Connection to the south port of the stream switch
1221 default:
1222 return 0;
1223 }
1224
1225 return 0;
1226}
1227
1228uint32_t
1230 WireBundle bundle) const {
1231 if (isShimNOCorPLTile(col, row))
1232 switch (bundle) {
1233 case WireBundle::DMA:
1234 return 2;
1235 case WireBundle::NOC:
1236 return 4;
1237 case WireBundle::PLIO:
1238 return 8;
1239 case WireBundle::South:
1240 return 6; // Connection to the south port of the stream switch
1241 default:
1242 return 0;
1243 }
1244
1245 return 0;
1246}
1247
1249 WireBundle srcBundle, int srcChan,
1250 WireBundle dstBundle,
1251 int dstChan) const {
1252 // Check Channel Id within the range
1253 if (srcChan >= int(getNumSourceSwitchboxConnections(col, row, srcBundle)))
1254 return false;
1255 if (dstChan >= int(getNumDestSwitchboxConnections(col, row, dstBundle)))
1256 return false;
1257
1258 // Lambda function to check if a bundle is in a list
1259 auto isBundleInList = [](WireBundle bundle,
1260 std::initializer_list<WireBundle> bundles) {
1261 return llvm::find(bundles, bundle) != bundles.end();
1262 };
1263
1264 // Memtile
1265 if (isMemTile(col, row)) {
1266 if (srcBundle == WireBundle::DMA) {
1267 if (dstBundle == WireBundle::DMA)
1268 return srcChan == dstChan;
1269 if (isBundleInList(dstBundle, {WireBundle::TileControl, WireBundle::South,
1270 WireBundle::North}))
1271 return true;
1272 }
1273 if (srcBundle == WireBundle::TileControl) {
1274 if (dstBundle == WireBundle::DMA)
1275 return dstChan == 5;
1276 if (isBundleInList(dstBundle, {WireBundle::South, WireBundle::North}))
1277 return true;
1278 }
1279 if (isBundleInList(srcBundle, {WireBundle::South, WireBundle::North})) {
1280 if (isBundleInList(dstBundle, {WireBundle::DMA, WireBundle::TileControl}))
1281 return true;
1282 if (isBundleInList(dstBundle, {WireBundle::South, WireBundle::North}))
1283 return srcChan == dstChan;
1284 }
1285 if (srcBundle == WireBundle::Trace) {
1286 if (dstBundle == WireBundle::DMA)
1287 return dstChan == 5;
1288 if (dstBundle == WireBundle::South)
1289 return true;
1290 }
1291 }
1292 // Shimtile
1293 else if (isShimNOCorPLTile(col, row)) {
1294 if (srcBundle == WireBundle::TileControl)
1295 return dstBundle != WireBundle::TileControl;
1296 if (isBundleInList(srcBundle, {WireBundle::FIFO, WireBundle::South}))
1297 return isBundleInList(dstBundle,
1298 {WireBundle::TileControl, WireBundle::FIFO,
1299 WireBundle::South, WireBundle::West,
1300 WireBundle::North, WireBundle::East});
1301 if (isBundleInList(srcBundle,
1302 {WireBundle::West, WireBundle::North, WireBundle::East}))
1303 return (srcBundle == dstBundle)
1304 ? (srcChan == dstChan)
1305 : isBundleInList(dstBundle,
1306 {WireBundle::TileControl, WireBundle::FIFO,
1307 WireBundle::South, WireBundle::West,
1308 WireBundle::North, WireBundle::East});
1309 if (srcBundle == WireBundle::Trace) {
1310 if (isBundleInList(dstBundle, {WireBundle::FIFO, WireBundle::South}))
1311 return true;
1312 if (isBundleInList(dstBundle, {WireBundle::West, WireBundle::East}))
1313 return dstChan == 0;
1314 }
1315 }
1316 // Coretile
1317 if (isCoreTile(col, row)) {
1318 if (isBundleInList(srcBundle,
1319 {WireBundle::DMA, WireBundle::FIFO, WireBundle::South,
1320 WireBundle::West, WireBundle::North, WireBundle::East}))
1321 if (isBundleInList(dstBundle, {WireBundle::Core, WireBundle::DMA,
1322 WireBundle::TileControl, WireBundle::FIFO,
1323 WireBundle::South, WireBundle::West,
1324 WireBundle::North, WireBundle::East}))
1325 return (srcBundle == dstBundle) ? (srcChan == dstChan) : true;
1326 if (srcBundle == WireBundle::Core)
1327 return dstBundle != WireBundle::Core;
1328 if (srcBundle == WireBundle::TileControl)
1329 return dstBundle != WireBundle::TileControl &&
1330 dstBundle != WireBundle::DMA;
1331 if (srcBundle == WireBundle::Trace) {
1332 if (dstBundle == WireBundle::DMA)
1333 return dstChan == 0;
1334 if (isBundleInList(dstBundle, {WireBundle::FIFO, WireBundle::South}))
1335 return true;
1336 }
1337 }
1338 return false;
1339}
1340
1341std::vector<std::pair<uint32_t, uint32_t>>
1343 return {std::pair(0, 64), std::pair(1, 128), std::pair(2, 256)};
1344}
1345
1346std::optional<uint32_t>
1347AIE2TargetModel::getLocalLockAddress(uint32_t lockId, TileID tile) const {
1348 auto computeTileBaseAddress = 0x0001F000;
1349 auto memTileBaseAddress = 0x000C0000;
1350 auto shimTileBaseAddress = 0x00014000;
1351 auto lockAddrOffset = 0x10;
1352
1353 if (isCoreTile(tile.col, tile.row) &&
1354 lockId < getNumLocks(tile.col, tile.row))
1355 return computeTileBaseAddress + lockAddrOffset * lockId;
1356
1357 if (isMemTile(tile.col, tile.row) && lockId < getNumLocks(tile.col, tile.row))
1358 return memTileBaseAddress + lockAddrOffset * lockId;
1359
1360 if (isShimNOCorPLTile(tile.col, tile.row) &&
1361 lockId < getNumLocks(tile.col, tile.row))
1362 return shimTileBaseAddress + lockAddrOffset * lockId;
1363
1364 return std::nullopt;
1365}
1366
1367namespace {
1368namespace aie2_port_id {
1369namespace core {
1370
1371// Slave port offset/size constants
1372static constexpr uint32_t S_CORE_OFFSET = 0;
1373static constexpr uint32_t S_CORE_SIZE = 1;
1374static constexpr uint32_t S_CTRL_OFFSET = 3;
1375static constexpr uint32_t S_CTRL_SIZE = 1;
1376static constexpr uint32_t S_DMA_OFFSET = 1;
1377static constexpr uint32_t S_DMA_SIZE = 2;
1378static constexpr uint32_t S_EAST_OFFSET = 19;
1379static constexpr uint32_t S_EAST_SIZE = 4;
1380static constexpr uint32_t S_FIFO_OFFSET = 4;
1381static constexpr uint32_t S_FIFO_SIZE = 1;
1382static constexpr uint32_t S_NORTH_OFFSET = 15;
1383static constexpr uint32_t S_NORTH_SIZE = 4;
1384static constexpr uint32_t S_SOUTH_OFFSET = 5;
1385static constexpr uint32_t S_SOUTH_SIZE = 6;
1386static constexpr uint32_t S_TRACE_OFFSET = 23;
1387static constexpr uint32_t S_TRACE_SIZE = 2;
1388static constexpr uint32_t S_WEST_OFFSET = 11;
1389static constexpr uint32_t S_WEST_SIZE = 4;
1390
1391// Master port offset/size constants
1392static constexpr uint32_t M_CORE_OFFSET = 0;
1393static constexpr uint32_t M_CORE_SIZE = 1;
1394static constexpr uint32_t M_CTRL_OFFSET = 3;
1395static constexpr uint32_t M_CTRL_SIZE = 1;
1396static constexpr uint32_t M_DMA_OFFSET = 1;
1397static constexpr uint32_t M_DMA_SIZE = 2;
1398static constexpr uint32_t M_EAST_OFFSET = 19;
1399static constexpr uint32_t M_EAST_SIZE = 4;
1400static constexpr uint32_t M_FIFO_OFFSET = 4;
1401static constexpr uint32_t M_FIFO_SIZE = 1;
1402static constexpr uint32_t M_NORTH_OFFSET = 13;
1403static constexpr uint32_t M_NORTH_SIZE = 6;
1404static constexpr uint32_t M_SOUTH_OFFSET = 5;
1405static constexpr uint32_t M_SOUTH_SIZE = 4;
1406static constexpr uint32_t M_WEST_OFFSET = 9;
1407static constexpr uint32_t M_WEST_SIZE = 4;
1408
1409} // namespace core
1410
1411namespace mem {
1412
1413// Slave port offset/size constants
1414static constexpr uint32_t S_CTRL_OFFSET = 6;
1415static constexpr uint32_t S_CTRL_SIZE = 1;
1416static constexpr uint32_t S_DMA_OFFSET = 0;
1417static constexpr uint32_t S_DMA_SIZE = 6;
1418static constexpr uint32_t S_NORTH_OFFSET = 13;
1419static constexpr uint32_t S_NORTH_SIZE = 4;
1420static constexpr uint32_t S_SOUTH_OFFSET = 7;
1421static constexpr uint32_t S_SOUTH_SIZE = 6;
1422static constexpr uint32_t S_TRACE_OFFSET = 17;
1423static constexpr uint32_t S_TRACE_SIZE = 1;
1424
1425// Master port offset/size constants
1426static constexpr uint32_t M_CTRL_OFFSET = 6;
1427static constexpr uint32_t M_CTRL_SIZE = 1;
1428static constexpr uint32_t M_DMA_OFFSET = 0;
1429static constexpr uint32_t M_DMA_SIZE = 6;
1430static constexpr uint32_t M_NORTH_OFFSET = 11;
1431static constexpr uint32_t M_NORTH_SIZE = 6;
1432static constexpr uint32_t M_SOUTH_OFFSET = 7;
1433static constexpr uint32_t M_SOUTH_SIZE = 4;
1434
1435} // namespace mem
1436
1437namespace shim {
1438
1439// Slave port offset/size constants
1440static constexpr uint32_t S_CTRL_OFFSET = 0;
1441static constexpr uint32_t S_CTRL_SIZE = 1;
1442static constexpr uint32_t S_EAST_OFFSET = 18;
1443static constexpr uint32_t S_EAST_SIZE = 4;
1444static constexpr uint32_t S_FIFO_OFFSET = 1;
1445static constexpr uint32_t S_FIFO_SIZE = 1;
1446static constexpr uint32_t S_NORTH_OFFSET = 14;
1447static constexpr uint32_t S_NORTH_SIZE = 4;
1448static constexpr uint32_t S_SOUTH_OFFSET = 2;
1449static constexpr uint32_t S_SOUTH_SIZE = 8;
1450static constexpr uint32_t S_TRACE_OFFSET = 22;
1451static constexpr uint32_t S_TRACE_SIZE = 2;
1452static constexpr uint32_t S_WEST_OFFSET = 10;
1453static constexpr uint32_t S_WEST_SIZE = 4;
1454
1455// Master port offset/size constants
1456static constexpr uint32_t M_CTRL_OFFSET = 0;
1457static constexpr uint32_t M_CTRL_SIZE = 1;
1458static constexpr uint32_t M_EAST_OFFSET = 18;
1459static constexpr uint32_t M_EAST_SIZE = 4;
1460static constexpr uint32_t M_FIFO_OFFSET = 1;
1461static constexpr uint32_t M_FIFO_SIZE = 1;
1462static constexpr uint32_t M_NORTH_OFFSET = 12;
1463static constexpr uint32_t M_NORTH_SIZE = 6;
1464static constexpr uint32_t M_SOUTH_OFFSET = 2;
1465static constexpr uint32_t M_SOUTH_SIZE = 6;
1466static constexpr uint32_t M_WEST_OFFSET = 8;
1467static constexpr uint32_t M_WEST_SIZE = 4;
1468
1469} // namespace shim
1470} // namespace aie2_port_id
1471} // namespace
1472
1474 int col, int row, WireBundle bundle, uint32_t port_num, bool master) const {
1475
1476 if (master) {
1477 if (isCoreTile(col, row)) {
1478 switch (bundle) {
1479 case WireBundle::Core:
1480 if (port_num >= aie2_port_id::core::M_CORE_SIZE)
1481 return std::nullopt;
1482 return aie2_port_id::core::M_CORE_OFFSET + port_num;
1483 case WireBundle::TileControl:
1484 if (port_num >= aie2_port_id::core::M_CTRL_SIZE)
1485 return std::nullopt;
1486 return aie2_port_id::core::M_CTRL_OFFSET + port_num;
1487 case WireBundle::DMA:
1488 if (port_num >= aie2_port_id::core::M_DMA_SIZE)
1489 return std::nullopt;
1490 return aie2_port_id::core::M_DMA_OFFSET + port_num;
1491 case WireBundle::East:
1492 if (port_num >= aie2_port_id::core::M_EAST_SIZE)
1493 return std::nullopt;
1494 return aie2_port_id::core::M_EAST_OFFSET + port_num;
1495 case WireBundle::FIFO:
1496 if (port_num >= aie2_port_id::core::M_FIFO_SIZE)
1497 return std::nullopt;
1498 return aie2_port_id::core::M_FIFO_OFFSET + port_num;
1499 case WireBundle::North:
1500 if (port_num >= aie2_port_id::core::M_NORTH_SIZE)
1501 return std::nullopt;
1502 return aie2_port_id::core::M_NORTH_OFFSET + port_num;
1503 case WireBundle::South:
1504 if (port_num >= aie2_port_id::core::M_SOUTH_SIZE)
1505 return std::nullopt;
1506 return aie2_port_id::core::M_SOUTH_OFFSET + port_num;
1507 case WireBundle::West:
1508 if (port_num >= aie2_port_id::core::M_WEST_SIZE)
1509 return std::nullopt;
1510 return aie2_port_id::core::M_WEST_OFFSET + port_num;
1511 default:
1512 return std::nullopt;
1513 }
1514 } else if (isMemTile(col, row)) {
1515 switch (bundle) {
1516 case WireBundle::TileControl:
1517 if (port_num >= aie2_port_id::mem::M_CTRL_SIZE)
1518 return std::nullopt;
1519 return aie2_port_id::mem::M_CTRL_OFFSET + port_num;
1520 case WireBundle::DMA:
1521 if (port_num >= aie2_port_id::mem::M_DMA_SIZE)
1522 return std::nullopt;
1523 return aie2_port_id::mem::M_DMA_OFFSET + port_num;
1524 case WireBundle::North:
1525 if (port_num >= aie2_port_id::mem::M_NORTH_SIZE)
1526 return std::nullopt;
1527 return aie2_port_id::mem::M_NORTH_OFFSET + port_num;
1528 case WireBundle::South:
1529 if (port_num >= aie2_port_id::mem::M_SOUTH_SIZE)
1530 return std::nullopt;
1531 return aie2_port_id::mem::M_SOUTH_OFFSET + port_num;
1532 default:
1533 return std::nullopt;
1534 }
1535 } else if (isShimNOCTile(col, row)) {
1536 switch (bundle) {
1537 case WireBundle::TileControl:
1538 if (port_num >= aie2_port_id::shim::M_CTRL_SIZE)
1539 return std::nullopt;
1540 return aie2_port_id::shim::M_CTRL_OFFSET + port_num;
1541 case WireBundle::East:
1542 if (port_num >= aie2_port_id::shim::M_EAST_SIZE)
1543 return std::nullopt;
1544 return aie2_port_id::shim::M_EAST_OFFSET + port_num;
1545 case WireBundle::FIFO:
1546 if (port_num >= aie2_port_id::shim::M_FIFO_SIZE)
1547 return std::nullopt;
1548 return aie2_port_id::shim::M_FIFO_OFFSET + port_num;
1549 case WireBundle::North:
1550 if (port_num >= aie2_port_id::shim::M_NORTH_SIZE)
1551 return std::nullopt;
1552 return aie2_port_id::shim::M_NORTH_OFFSET + port_num;
1553 case WireBundle::South:
1554 if (port_num >= aie2_port_id::shim::M_SOUTH_SIZE)
1555 return std::nullopt;
1556 return aie2_port_id::shim::M_SOUTH_OFFSET + port_num;
1557 case WireBundle::West:
1558 if (port_num >= aie2_port_id::shim::M_WEST_SIZE)
1559 return std::nullopt;
1560 return aie2_port_id::shim::M_WEST_OFFSET + port_num;
1561 default:
1562 return std::nullopt;
1563 }
1564 }
1565 // Slave ports
1566 } else {
1567
1568 if (isCoreTile(col, row)) {
1569 switch (bundle) {
1570 case WireBundle::Core:
1571 if (port_num >= aie2_port_id::core::S_CORE_SIZE)
1572 return std::nullopt;
1573 return aie2_port_id::core::S_CORE_OFFSET + port_num;
1574 case WireBundle::TileControl:
1575 if (port_num >= aie2_port_id::core::S_CTRL_SIZE)
1576 return std::nullopt;
1577 return aie2_port_id::core::S_CTRL_OFFSET + port_num;
1578 case WireBundle::DMA:
1579 if (port_num >= aie2_port_id::core::S_DMA_SIZE)
1580 return std::nullopt;
1581 return aie2_port_id::core::S_DMA_OFFSET + port_num;
1582 case WireBundle::East:
1583 if (port_num >= aie2_port_id::core::S_EAST_SIZE)
1584 return std::nullopt;
1585 return aie2_port_id::core::S_EAST_OFFSET + port_num;
1586 case WireBundle::FIFO:
1587 if (port_num >= aie2_port_id::core::S_FIFO_SIZE)
1588 return std::nullopt;
1589 return aie2_port_id::core::S_FIFO_OFFSET + port_num;
1590 case WireBundle::North:
1591 if (port_num >= aie2_port_id::core::S_NORTH_SIZE)
1592 return std::nullopt;
1593 return aie2_port_id::core::S_NORTH_OFFSET + port_num;
1594 case WireBundle::South:
1595 if (port_num >= aie2_port_id::core::S_SOUTH_SIZE)
1596 return std::nullopt;
1597 return aie2_port_id::core::S_SOUTH_OFFSET + port_num;
1598 case WireBundle::Trace:
1599 if (port_num >= aie2_port_id::core::S_TRACE_SIZE)
1600 return std::nullopt;
1601 return aie2_port_id::core::S_TRACE_OFFSET + port_num;
1602 case WireBundle::West:
1603 if (port_num >= aie2_port_id::core::S_WEST_SIZE)
1604 return std::nullopt;
1605 return aie2_port_id::core::S_WEST_OFFSET + port_num;
1606 default:
1607 return std::nullopt;
1608 }
1609 } else if (isMemTile(col, row)) {
1610 switch (bundle) {
1611 case WireBundle::TileControl:
1612 if (port_num >= aie2_port_id::mem::S_CTRL_SIZE)
1613 return std::nullopt;
1614 return aie2_port_id::mem::S_CTRL_OFFSET + port_num;
1615 case WireBundle::DMA:
1616 if (port_num >= aie2_port_id::mem::S_DMA_SIZE)
1617 return std::nullopt;
1618 return aie2_port_id::mem::S_DMA_OFFSET + port_num;
1619 case WireBundle::North:
1620 if (port_num >= aie2_port_id::mem::S_NORTH_SIZE)
1621 return std::nullopt;
1622 return aie2_port_id::mem::S_NORTH_OFFSET + port_num;
1623 case WireBundle::South:
1624 if (port_num >= aie2_port_id::mem::S_SOUTH_SIZE)
1625 return std::nullopt;
1626 return aie2_port_id::mem::S_SOUTH_OFFSET + port_num;
1627 case WireBundle::Trace:
1628 if (port_num >= aie2_port_id::mem::S_TRACE_SIZE)
1629 return std::nullopt;
1630 return aie2_port_id::mem::S_TRACE_OFFSET + port_num;
1631 default:
1632 return std::nullopt;
1633 }
1634 } else if (isShimNOCTile(col, row)) {
1635 switch (bundle) {
1636 case WireBundle::TileControl:
1637 if (port_num >= aie2_port_id::shim::S_CTRL_SIZE)
1638 return std::nullopt;
1639 return aie2_port_id::shim::S_CTRL_OFFSET + port_num;
1640 case WireBundle::East:
1641 if (port_num >= aie2_port_id::shim::S_EAST_SIZE)
1642 return std::nullopt;
1643 return aie2_port_id::shim::S_EAST_OFFSET + port_num;
1644 case WireBundle::FIFO:
1645 if (port_num >= aie2_port_id::shim::S_FIFO_SIZE)
1646 return std::nullopt;
1647 return aie2_port_id::shim::S_FIFO_OFFSET + port_num;
1648 case WireBundle::North:
1649 if (port_num >= aie2_port_id::shim::S_NORTH_SIZE)
1650 return std::nullopt;
1651 return aie2_port_id::shim::S_NORTH_OFFSET + port_num;
1652 case WireBundle::South:
1653 if (port_num >= aie2_port_id::shim::S_SOUTH_SIZE)
1654 return std::nullopt;
1655 return aie2_port_id::shim::S_SOUTH_OFFSET + port_num;
1656 case WireBundle::Trace:
1657 if (port_num >= aie2_port_id::shim::S_TRACE_SIZE)
1658 return std::nullopt;
1659 return aie2_port_id::shim::S_TRACE_OFFSET + port_num;
1660 case WireBundle::West:
1661 if (port_num >= aie2_port_id::shim::S_WEST_SIZE)
1662 return std::nullopt;
1663 return aie2_port_id::shim::S_WEST_OFFSET + port_num;
1664 default:
1665 return std::nullopt;
1666 }
1667 }
1668 }
1669 return std::nullopt;
1670}
1671
1673 // Every tile in a shimtile row must be a shimtile, and can only be one type
1674 // of shim tile.
1675 for (int j = 0; j < columns(); j++) {
1676 assert(!isMemTile(j, 0) && (isShimPLTile(j, 0) || isShimNOCTile(j, 0)) &&
1677 !isCoreTile(j, 0));
1678 assert(isShimPLTile(j, 0) ^ isShimNOCTile(j, 0));
1679 }
1680
1681 // Every tile in a memtile row must be a memtile.
1682 for (int i = 1; i < 1 + static_cast<int>(getNumMemTileRows()); i++)
1683 for (int j = 0; j < columns(); j++)
1684 assert(isMemTile(j, i) && !isShimPLTile(j, i) && !isShimNOCTile(j, i) &&
1685 !isCoreTile(j, i));
1686
1687 // Every other tile is a coretile.
1688 for (int i = 1 + getNumMemTileRows(); i < rows(); i++)
1689 for (int j = 0; j < columns(); j++)
1690 assert(!isMemTile(j, i) && !isShimPLTile(j, i) && !isShimNOCTile(j, i) &&
1691 isCoreTile(j, i));
1692
1693 // Looking North, buses must match
1694 for (int i = 0; i < rows() - 1; i++)
1695 for (int j = 0; j < columns(); j++)
1696 assert(getNumSourceSwitchboxConnections(j, i, WireBundle::North) ==
1697 getNumDestSwitchboxConnections(j, i + 1, WireBundle::South));
1698 // Looking South, buses must match
1699 for (int i = 1; i < rows(); i++)
1700 for (int j = 0; j < columns(); j++)
1701 assert(getNumSourceSwitchboxConnections(j, i, WireBundle::South) ==
1702 getNumDestSwitchboxConnections(j, i - 1, WireBundle::North));
1703 // Looking East, buses must match
1704 for (int i = 0; i < rows(); i++)
1705 for (int j = 0; j < columns() - 1; j++)
1706 assert(getNumSourceSwitchboxConnections(j, i, WireBundle::East) ==
1707 getNumDestSwitchboxConnections(j + 1, i, WireBundle::West));
1708 // Looking West, buses must match
1709 for (int i = 0; i < rows(); i++)
1710 for (int j = 1; j < columns(); j++)
1711 assert(getNumSourceSwitchboxConnections(j, i, WireBundle::West) ==
1712 getNumDestSwitchboxConnections(j - 1, i, WireBundle::East));
1713 // Edges have no connections
1714 for (int j = 0; j < columns(); j++)
1715 assert(getNumSourceSwitchboxConnections(j, rows() - 1, WireBundle::North) ==
1716 0);
1717 for (int i = 0; i < rows(); i++)
1719 WireBundle::East) == 0);
1720 for (int i = 0; i < rows(); i++)
1721 assert(getNumSourceSwitchboxConnections(0, i, WireBundle::West) == 0);
1722
1723 // FIFOS are consistent
1724 for (int i = 0; i < rows(); i++)
1725 for (int j = 0; j < columns(); j++)
1726 assert(getNumSourceSwitchboxConnections(j, i, WireBundle::FIFO) ==
1727 getNumDestSwitchboxConnections(j, i, WireBundle::FIFO));
1728}
1729
1730std::optional<uint32_t>
1731AIETargetModel::getLockLocalBaseIndex(int localCol, int localRow, int lockCol,
1732 int lockRow) const {
1733 if (isCoreTile(localCol, localRow)) {
1734 if (isMemSouth(localCol, localRow, lockCol, lockRow))
1735 return 0;
1736 if (isMemWest(localCol, localRow, lockCol, lockRow))
1737 return getNumLocks(localCol, localRow);
1738 if (isMemNorth(localCol, localRow, lockCol, lockRow))
1739 return getNumLocks(localCol, localRow) * 2;
1740 if (isMemEast(localCol, localRow, lockCol, lockRow))
1741 return getNumLocks(localCol, localRow) * 3;
1742 }
1743
1744 if (isMemTile(localCol, localRow)) {
1745 if (isWest(localCol, localRow, lockCol, lockRow))
1746 return 0;
1747 if (isInternal(localCol, localRow, lockCol, lockRow))
1748 return getNumLocks(localCol, localRow);
1749 if (isEast(localCol, localRow, lockCol, lockRow))
1750 return getNumLocks(localCol, localRow) * 2;
1751 }
1752
1753 return std::nullopt;
1754}
1755
1756std::optional<uint32_t>
1757AIETargetModel::getMemLocalBaseAddress(int localCol, int localRow, int memCol,
1758 int memRow) const {
1759 if (isCoreTile(localCol, localRow)) {
1760 if (isMemSouth(localCol, localRow, memCol, memRow))
1761 return getMemSouthBaseAddress();
1762 if (isMemWest(localCol, localRow, memCol, memRow))
1763 return getMemWestBaseAddress();
1764 if (isMemNorth(localCol, localRow, memCol, memRow))
1765 return getMemNorthBaseAddress();
1766 if (isMemEast(localCol, localRow, memCol, memRow))
1767 return getMemEastBaseAddress();
1768 }
1769
1770 if (isMemTile(localCol, localRow)) {
1771 if (isWest(localCol, localRow, memCol, memRow))
1772 return 0;
1773 if (isInternal(localCol, localRow, memCol, memRow))
1774 return getMemTileSize();
1775 if (isEast(localCol, localRow, memCol, memRow))
1776 return getMemTileSize() * 2;
1777 }
1778
1779 return std::nullopt;
1780}
1781
1782uint32_t AIETargetModel::getNumDMAChannels(int col, int row,
1783 AIE::DMAChannelDir dir) const {
1784 // The C API may pass an invalid tile or direction.
1785 if (!isValidTile({col, row}) ||
1786 !symbolizeDMAChannelDir(static_cast<uint32_t>(dir)))
1787 return 0;
1788 bool mm2s = isMM2S(dir);
1789 WireBundle bundle = getDMAChannelBundle(dir);
1790 if (hasShimMux(col, row))
1791 return mm2s ? getNumSourceShimMuxConnections(col, row, bundle)
1792 : getNumDestShimMuxConnections(col, row, bundle);
1793 return mm2s ? getNumSourceSwitchboxConnections(col, row, bundle)
1794 : getNumDestSwitchboxConnections(col, row, bundle);
1795}
1796
1797bool AIETargetModel::isSupportedBlockFormat(std::string const &format) const {
1798 return false;
1799}
1800
1801AIEArch BaseNPU2TargetModel::getTargetArch() const { return AIEArch::AIE2p; }
1802
1803std::vector<std::pair<uint32_t, uint32_t>>
1805 return {std::pair(0, 64), std::pair(1, 128), std::pair(2, 256),
1806 std::pair(3, 512)};
1807}
1808
1810 std::string const &format) const {
1811 std::set<std::string> supportedTypes = {"v8bfp16ebs8", "v16bfp16ebs16"};
1812 return static_cast<bool>(supportedTypes.find(format) != supportedTypes.end());
1813}
1814
1815// AIE2PS overrides: shim DMA registers are at different offsets than AIE2.
1816// Memtile and core tile DMA addresses are identical to AIE2.
1817uint64_t
1818AIE2PSTargetModel::getDmaBdAddress(int col, int row, uint32_t bd_id,
1819 int channel,
1820 AIE::DMAChannelDir direction) const {
1821 if (isShimNOCTile(col, row)) {
1822 uint64_t offset = 0x00009000 + bd_id * 0x30;
1823 return getTileAddress(col, row) | offset;
1824 }
1825 // Memtile and core tile use same addresses as AIE2.
1826 return AIE2TargetModel::getDmaBdAddress(col, row, bd_id, channel, direction);
1827}
1828
1829uint32_t
1830AIE2PSTargetModel::getDmaControlAddress(int col, int row, int channel,
1831 AIE::DMAChannelDir direction) const {
1832 if (isShimNOCTile(col, row)) {
1833 uint32_t offset = 0x00009300 + (channel * 0x8);
1834 if (direction == AIE::DMAChannelDir::MM2S)
1835 offset += 0x10;
1836 return getTileAddress(col, row) | offset;
1837 }
1838 // Memtile and core tile use same addresses as AIE2.
1839 return AIE2TargetModel::getDmaControlAddress(col, row, channel, direction);
1840}
1841
1842std::optional<uint32_t>
1843AIE2PSTargetModel::getDmaStatusAddress(int col, int row, int channel,
1844 AIE::DMAChannelDir direction) const {
1845 // The AIE2PS shim relocates its DMA registers (control is at 0x9300, not
1846 // 0x1D200), and the status block has not been confirmed against a register
1847 // spec. Report "unknown" rather than guess an address a maskpoll would then
1848 // read garbage from; memtile and core tiles match AIE2.
1849 if (isShimNOCTile(col, row))
1850 return std::nullopt;
1851 return AIE2TargetModel::getDmaStatusAddress(col, row, channel, direction);
1852}
1853
1854// AIE2PS shim tiles have uC stream switch port for routing TCT to CERT uC.
1855uint32_t
1857 WireBundle bundle) const {
1858 if (isShimNOCTile(col, row) && bundle == WireBundle::Controller32)
1859 return 1;
1860 return AIE2TargetModel::getNumDestSwitchboxConnections(col, row, bundle);
1861}
1862
1863uint32_t
1865 WireBundle bundle) const {
1866 if (isShimNOCTile(col, row) && bundle == WireBundle::Controller32)
1867 return 1;
1869}
1870
1872 int col, int row, WireBundle bundle, uint32_t channel, bool master) const {
1873 // AIE2PS shim: Controller32 maps to hw master port 22 / slave port 23.
1874 if (isShimNOCTile(col, row) && bundle == WireBundle::Controller32) {
1875 if (channel > 0)
1876 return std::nullopt;
1877 return master ? 22 : 23;
1878 }
1879 return AIE2TargetModel::getStreamSwitchPortIndex(col, row, bundle, channel,
1880 master);
1881}
1882
1883///
1884/// AIE4 TargetModel
1885///
1886
1887std::unique_ptr<RegisterDatabase>
1891
1892AIEArch AIE4TargetModel::getTargetArch() const { return AIEArch::AIE4; }
1893
1894uint32_t AIE4TargetModel::getTileAddress(int col, int row) const {
1895 uint32_t addressRow = static_cast<uint32_t>(row);
1896 if (isCoreTile(col, row))
1897 addressRow += 4 * getNumMemTileRows();
1898 else if (isMemTile(col, row))
1899 addressRow = 5 * addressRow - 4; // memtile row m: address rows 5m-4 .. 5m
1900 return (static_cast<uint32_t>(col & 0xff) << getColumnShift()) |
1901 ((addressRow & 0xff) << getRowShift());
1902}
1903
1904uint32_t AIE4TargetModel::getRowFromAddress(uint32_t address) const {
1905 uint32_t addressRow = (address >> getRowShift()) & getRowFieldMask();
1906 uint32_t memTileRows = getNumMemTileRows();
1907 if (addressRow == 0)
1908 return 0;
1909 if (addressRow <= 5 * memTileRows)
1910 return 1 + (addressRow - 1) / 5;
1911 return addressRow - 4 * memTileRows;
1912}
1913
1914uint32_t AIE4TargetModel::getDataMemoryOffset(int col, int row) const {
1915 return isMemTile(col, row) ? 0x00100000 : 0;
1916}
1917
1918std::optional<TileID> AIE4TargetModel::getMemEast(TileID src) const {
1919 std::optional ret = src;
1920 if (!isValidTile(*ret))
1921 ret.reset();
1922 return ret;
1923}
1924
1925bool AIE4TargetModel::isMemWest(int srcCol, int srcRow, int dstCol,
1926 int dstRow) const {
1927 return isWest(srcCol, srcRow, dstCol, dstRow);
1928}
1929
1930bool AIE4TargetModel::isMemEast(int srcCol, int srcRow, int dstCol,
1931 int dstRow) const {
1932 return isInternal(srcCol, srcRow, dstCol, dstRow);
1933}
1934
1935bool AIE4TargetModel::isMemNorth(int srcCol, int srcRow, int dstCol,
1936 int dstRow) const {
1937 return isNorth(srcCol, srcRow, dstCol, dstRow);
1938}
1939
1940bool AIE4TargetModel::isMemSouth(int srcCol, int srcRow, int dstCol,
1941 int dstRow) const {
1942 return isSouth(srcCol, srcRow, dstCol, dstRow);
1943}
1944
1945bool AIE4TargetModel::isLegalMemAffinity(int coreCol, int coreRow, int memCol,
1946 int memRow) const {
1947 if (isMemTile(coreCol, coreRow))
1948 return isEast(coreCol, coreRow, memCol, memRow) ||
1949 isInternal(coreCol, coreRow, memCol, memRow) ||
1950 isWest(coreCol, coreRow, memCol, memRow);
1951 return isMemEast(coreCol, coreRow, memCol, memRow);
1952}
1953
1954// Shim pools: 0 and 1 are the data BD banks, then one private pool per
1955// ControlMM2S channel and one for the TraceS2MM channel.
1956static constexpr uint32_t aie4ShimControlPool = 2;
1957static constexpr uint32_t aie4ShimNumControlChannels = 2;
1958static constexpr uint32_t aie4ShimTracePool =
1959 aie4ShimControlPool + aie4ShimNumControlChannels;
1960
1961uint32_t AIE4TargetModel::getBdPoolId(int col, int row, int channel,
1962 DMAChannelDir dir) const {
1963 bool mm2s = isMM2S(dir);
1964 if (isMemTile(col, row))
1965 return 2 * channel + (mm2s ? 0 : 1);
1966 if (isShimNOCTile(col, row)) {
1967 if (dir == DMAChannelDir::ControlMM2S)
1968 return aie4ShimControlPool + channel;
1969 if (dir == DMAChannelDir::TraceS2MM)
1970 return aie4ShimTracePool + channel;
1971 return channel >= (mm2s ? 2 : 1) ? 1 : 0;
1972 }
1973 return 0;
1974}
1975
1976uint32_t AIE4TargetModel::getBdPoolStartId(int col, int row,
1977 uint32_t poolId) const {
1978 return isShimNOCTile(col, row) && poolId == 1 ? 16 : 0;
1979}
1980
1981uint32_t AIE4TargetModel::getNumBDsInPool(int col, int row,
1982 uint32_t poolId) const {
1983 if (isShimNOCTile(col, row) && poolId >= aie4ShimTracePool)
1984 return 4;
1985 if (isShimNOCTile(col, row) && poolId >= aie4ShimControlPool)
1986 return 8;
1987 return 16;
1988}
1989
1990static void aie4ChannelOutOfRange(StringRef what, int col, int row,
1991 int channel) {
1992 report_fatal_error(Twine("AIE4TargetModel::") + what + ": DMA channel " +
1993 Twine(channel) + " is not available on tile (" +
1994 Twine(col) + ", " + Twine(row) + ")");
1995}
1996
1997// AIE4 BD layouts, from aie-codegen's xaie4gbl_params.h. Fields no lowering
1998// programs (TLAST suppression; on the shim high address bits, AXI
1999// user/key/QoS, compression, data reuse, IO coherence) are left out.
2000static DmaBdLayout makeAIE4CoreTileBdLayout() {
2001 DmaBdLayout l;
2002 l.numWords = 6;
2003 l.stepBias = 0;
2004 l.bufferOffset = {0, 16, 15};
2005 l.bufferLength = {0, 0, 15};
2006 l.enablePacket = {1, 30, 1};
2007 l.outOfOrderId = {1, 24, 4};
2008 l.packetId = {1, 19, 5};
2009 l.packetType = {1, 16, 3};
2010 l.d1Stride = {2, 16, 15};
2011 l.iterationCurrent = {3, 26, 6};
2012 l.d0Size = {3, 17, 9};
2013 l.d2Stride = {3, 0, 15};
2014 l.d1Size = {4, 23, 9};
2015 l.iterationSize = {4, 17, 6};
2016 l.iterationStride = {4, 0, 15};
2017 l.nextBd = {5, 27, 4};
2018 l.useNextBd = {5, 26, 1};
2019 l.lockRelValue = {5, 18, 7};
2020 l.lockRelId = {5, 13, 4};
2021 l.lockAcqEnable = {5, 12, 1};
2022 l.lockAcqValue = {5, 5, 7};
2023 l.lockAcqId = {5, 0, 4};
2024 return l;
2025}
2026
2027// The packet type is a channel setting on a memtile. The pads are MM2S-only.
2028static DmaBdLayout makeAIE4MemTileBdLayout() {
2029 DmaBdLayout l;
2030 l.numWords = 11;
2031 l.stepBias = 0;
2032 l.bufferOffset = {0, 0, 24};
2033 l.lockAcqValue = {1, 25, 7};
2034 l.bufferLength = {1, 0, 23};
2035 l.lockAcqId = {2, 20, 10};
2036 l.lockRelValue = {2, 11, 7};
2037 l.lockRelId = {2, 1, 10};
2038 l.lockAcqEnable = {2, 0, 1};
2039 l.d1Stride = {3, 0, 23};
2040 l.d2Stride = {4, 0, 23};
2041 l.d3Stride = {5, 0, 23};
2042 l.iterationStride = {6, 0, 23};
2043 l.iterationCurrent = {7, 22, 8};
2044 l.enablePacket = {7, 21, 1};
2045 l.packetId = {7, 16, 5};
2046 l.d0ZeroAfter = {7, 8, 8};
2047 l.d0ZeroBefore = {7, 0, 8};
2048 l.d2ZeroAfter = {8, 24, 8};
2049 l.d2ZeroBefore = {8, 16, 8};
2050 l.d1ZeroAfter = {8, 8, 8};
2051 l.d1ZeroBefore = {8, 0, 8};
2052 l.d1Size = {9, 19, 12};
2053 l.d0Size = {9, 5, 12};
2054 l.outOfOrderId = {9, 0, 4};
2055 l.nextBd = {10, 27, 4};
2056 l.useNextBd = {10, 26, 1};
2057 l.d2Size = {10, 14, 12};
2058 l.iterationSize = {10, 0, 8};
2059 return l;
2060}
2061
2062// Word 1 holds address bits [31:2] in place, so the byte offset goes there
2063// as on AIE2. The packet type is a channel setting on a shim.
2064static DmaBdLayout makeAIE4ShimBdLayout() {
2065 DmaBdLayout l;
2066 l.numWords = 9;
2067 l.stepBias = 0;
2068 l.bufferOffset = {1, 0, 32};
2069 l.bufferLength = {2, 0, 32};
2070 l.lockAcqId = {3, 27, 5};
2071 l.lockAcqEnable = {3, 26, 1};
2072 l.burstLength = {3, 24, 2};
2073 l.d1Size = {3, 12, 12};
2074 l.d2Size = {3, 0, 12};
2075 l.d0Size = {4, 19, 12};
2076 l.lockRelValue = {4, 12, 7};
2077 l.lockRelId = {4, 7, 5};
2078 l.lockAcqValue = {4, 0, 7};
2079 l.enablePacket = {5, 31, 1};
2080 l.nextBd = {5, 27, 4};
2081 l.useNextBd = {5, 26, 1};
2082 l.d1Stride = {5, 0, 22};
2083 l.iterationCurrent = {6, 24, 6};
2084 l.d2Stride = {6, 0, 22};
2085 l.axcache = {7, 28, 4};
2086 l.iterationSize = {7, 22, 6};
2087 l.iterationStride = {7, 0, 22};
2088 l.d3Stride = {8, 10, 22};
2089 l.outOfOrderId = {8, 5, 4};
2090 l.packetId = {8, 0, 5};
2091 return l;
2092}
2093
2094// Control/trace BDs: data BD word positions, no dimensions or locks; control
2095// length is 24 bits, trace has no packet fields.
2096static DmaBdLayout makeAIE4ShimLinearBdLayout(bool control) {
2097 DmaBdLayout l;
2098 l.numWords = 9;
2099 l.stepBias = 0;
2100 l.bufferOffset = {1, 0, 32};
2101 l.bufferLength = {2, 0, uint8_t(control ? 24 : 32)};
2102 l.burstLength = {3, 24, 2};
2103 l.nextBd = {5, 27, 4};
2104 l.useNextBd = {5, 26, 1};
2105 l.iterationCurrent = {6, 24, 6};
2106 l.axcache = {7, 28, 4};
2107 l.iterationSize = {7, 22, 6};
2108 l.iterationStride = {7, 0, 22};
2109 if (control) {
2110 l.enablePacket = {5, 31, 1};
2111 l.outOfOrderId = {8, 5, 4};
2112 l.packetId = {8, 0, 5};
2113 }
2114 return l;
2115}
2116
2117const DmaBdLayout *AIE4TargetModel::getDmaBdLayout(AIETileType tileType) const {
2118 static const DmaBdLayout shim = makeAIE4ShimBdLayout();
2119 static const DmaBdLayout mem = makeAIE4MemTileBdLayout();
2120 static const DmaBdLayout core = makeAIE4CoreTileBdLayout();
2121 switch (tileType) {
2122 case AIETileType::ShimNOCTile:
2123 return &shim;
2124 case AIETileType::MemTile:
2125 return &mem;
2126 case AIETileType::CoreTile:
2127 return &core;
2128 default:
2129 return nullptr;
2130 }
2131}
2132
2133const DmaBdLayout *
2135 DMAChannelDir direction) const {
2136 static const DmaBdLayout control = makeAIE4ShimLinearBdLayout(true);
2137 static const DmaBdLayout trace = makeAIE4ShimLinearBdLayout(false);
2138 if (direction == DMAChannelDir::ControlMM2S)
2139 return tileType == AIETileType::ShimNOCTile ? &control : nullptr;
2140 if (direction == DMAChannelDir::TraceS2MM)
2141 return tileType == AIETileType::ShimNOCTile ? &trace : nullptr;
2142 return getDmaBdLayout(tileType);
2143}
2144
2145uint64_t AIE4TargetModel::getDmaBdAddress(int col, int row, uint32_t bd_id,
2146 int channel,
2147 AIE::DMAChannelDir direction) const {
2148 bool mm2s = isMM2S(direction);
2149 uint64_t offset = 0;
2150 if (isShimNOCTile(col, row) && channel < 0) {
2151 // A data BD id is global across the two 16-BD banks.
2152 if (getDMAChannelBundle(direction) != WireBundle::DMA)
2153 report_fatal_error("AIE4TargetModel::getDmaBdAddress: a shim control "
2154 "or trace BD's address depends on its channel");
2155 if (bd_id >= getNumBDs(AIETileType::ShimNOCTile))
2156 report_fatal_error("AIE4TargetModel::getDmaBdAddress: shim BD " +
2157 Twine(bd_id) + " does not exist");
2158 offset = (bd_id < 16 ? 0x00018000 : 0x00058000) + (bd_id % 16) * 0x30;
2159 } else if (isShimNOCTile(col, row)) {
2160 if (channel >= static_cast<int>(getNumDMAChannels(col, row, direction)))
2161 aie4ChannelOutOfRange("getDmaBdAddress", col, row, channel);
2162 if (!isBdChannelAccessible(col, row, bd_id, channel, direction))
2163 report_fatal_error("AIE4TargetModel::getDmaBdAddress: shim BD " +
2164 Twine(bd_id) + " is not in the pool of channel " +
2165 Twine(channel));
2166 if (direction == AIE::DMAChannelDir::ControlMM2S) {
2167 // ControlMM2S channel 1 is in the upper application bank.
2168 offset = (channel == 0 ? 0x00018300 : 0x00058300) + bd_id * 0x30;
2169 } else if (direction == AIE::DMAChannelDir::TraceS2MM) {
2170 offset = 0x00018480 + bd_id * 0x30;
2171 } else {
2172 // bd_id is global across the two 16-BD banks; the register is indexed
2173 // bank-locally.
2174 bool upper = getBdPoolId(col, row, channel, direction) == 1;
2175 offset = (upper ? 0x00058000 : 0x00018000) + (bd_id % 16) * 0x30;
2176 }
2177 } else if (isMemTile(col, row)) {
2178 if (channel < 0)
2179 report_fatal_error("AIE4TargetModel::getDmaBdAddress: a memtile BD's "
2180 "pool depends on its channel and direction");
2181 if (channel >= static_cast<int>(getNumDMAChannels(col, row, direction)))
2182 aie4ChannelOutOfRange("getDmaBdAddress", col, row, channel);
2183 // Each of the two application banks has five MM2S and four S2MM channels;
2184 // every channel owns 16 BDs at a 0x30-byte stride.
2185 int channelsPerBank = mm2s ? 5 : 4;
2186 offset = mm2s ? 0x00008C00 : 0x00008000;
2187 offset += (channel % channelsPerBank) * 16 * 0x30 + bd_id * 0x30;
2188 if (channel >= channelsPerBank)
2189 offset += 0x40000;
2190 } else if (isCoreTile(col, row)) {
2191 offset = 0x000AC000 + bd_id * 0x20;
2192 } else {
2193 llvm_unreachable("AIE4TargetModel::getDmaBdAddress called for non-DMA "
2194 "tile");
2195 }
2196 return getTileAddress(col, row) | offset;
2197}
2198
2199uint32_t AIE4TargetModel::getDmaBdAddressOffset(int col, int row) const {
2200 if (isShimNOCTile(col, row))
2201 return 0x4;
2202 return 0x0;
2203}
2204
2205uint32_t
2206AIE4TargetModel::getDmaControlAddress(int col, int row, int channel,
2207 AIE::DMAChannelDir direction) const {
2208 bool mm2s = isMM2S(direction);
2209 if (channel < 0 ||
2210 channel >= static_cast<int>(getNumDMAChannels(col, row, direction)))
2211 aie4ChannelOutOfRange("getDmaControlAddress", col, row, channel);
2212 uint32_t offset = 0;
2213 if (isShimNOCTile(col, row)) {
2214 static constexpr uint32_t s2mm[] = {0x00018540, 0x00058540};
2215 static constexpr uint32_t mm2s4[] = {0x00018550, 0x00018558, 0x00058550,
2216 0x00058558};
2217 static constexpr uint32_t control[] = {0x00018560, 0x00058560};
2218 if (direction == AIE::DMAChannelDir::ControlMM2S)
2219 offset = control[channel];
2220 else if (direction == AIE::DMAChannelDir::TraceS2MM)
2221 offset = 0x00018548;
2222 else
2223 offset = mm2s ? mm2s4[channel] : s2mm[channel];
2224 } else if (isMemTile(col, row)) {
2225 int channelsPerBank = mm2s ? 5 : 4;
2226 offset = mm2s ? 0x00009E60 : 0x00009E00;
2227 offset += (channel % channelsPerBank) * 0x8;
2228 if (channel >= channelsPerBank)
2229 offset += 0x40000;
2230 } else if (isCoreTile(col, row)) {
2231 offset = (mm2s ? 0x000ACE10 : 0x000ACE00) + channel * 0x8;
2232 } else {
2233 llvm_unreachable("AIE4TargetModel::getDmaControlAddress called for "
2234 "non-DMA tile");
2235 }
2236 return getTileAddress(col, row) | offset;
2237}
2238
2239std::optional<uint32_t>
2240AIE4TargetModel::getLocalLockAddress(uint32_t lockId, TileID tile) const {
2241 constexpr uint32_t lockAddrOffset = 0x10;
2242 if (lockId >= getNumLocks(tile.col, tile.row))
2243 return std::nullopt;
2244 // Compute-tile locks live in the memory module.
2245 if (isCoreTile(tile.col, tile.row))
2246 return 0x000AE000 + lockAddrOffset * lockId;
2247 // Memtile (2 x 32) and shim (2 x 16) locks are split over two banks; the
2248 // offsets restart in the upper bank.
2249 uint32_t bankSize = getNumLocks(tile.col, tile.row) / 2;
2250 if (isMemTile(tile.col, tile.row) || isShimNOCTile(tile.col, tile.row)) {
2251 if (lockId < bankSize)
2252 return 0x00010000 + lockAddrOffset * lockId;
2253 return 0x00050000 + lockAddrOffset * (lockId - bankSize);
2254 }
2255 return std::nullopt;
2256}
2257
2258// Window index of memtile (memCol, memRow) seen from (localCol, localRow):
2259// 0 = seven columns west, 7 = local, 14 = seven columns east.
2260static std::optional<uint32_t> aie4MemTileWindow(const AIETargetModel &tm,
2261 int localCol, int localRow,
2262 int memCol, int memRow) {
2263 constexpr int reach = 7;
2264 if (!tm.isValidTile({memCol, memRow}) || !tm.isMemTile(memCol, memRow) ||
2265 localRow != memRow)
2266 return std::nullopt;
2267 int delta = memCol - localCol;
2268 if (delta < -reach || delta > reach)
2269 return std::nullopt;
2270 return delta + reach;
2271}
2272
2273std::optional<uint32_t>
2274AIE4TargetModel::getLockLocalBaseIndex(int localCol, int localRow, int lockCol,
2275 int lockRow) const {
2276 if (!isMemTile(localCol, localRow))
2277 return AIETargetModel::getLockLocalBaseIndex(localCol, localRow, lockCol,
2278 lockRow);
2279 if (auto window =
2280 aie4MemTileWindow(*this, localCol, localRow, lockCol, lockRow))
2281 return *window * getNumLocks(lockCol, lockRow);
2282 return std::nullopt;
2283}
2284
2285std::optional<uint32_t>
2286AIE4TargetModel::getMemLocalBaseAddress(int localCol, int localRow, int memCol,
2287 int memRow) const {
2288 if (!isMemTile(localCol, localRow))
2289 return AIETargetModel::getMemLocalBaseAddress(localCol, localRow, memCol,
2290 memRow);
2291 constexpr uint32_t memTileWindowBase = 0x00B00000;
2292 if (auto window =
2293 aie4MemTileWindow(*this, localCol, localRow, memCol, memRow))
2294 return memTileWindowBase + *window * getMemTileSize();
2295 return std::nullopt;
2296}
2297
2298std::vector<std::pair<uint32_t, uint32_t>>
2300 return {std::pair(0, 64), std::pair(1, 128), std::pair(2, 256),
2301 std::pair(3, 512)};
2302}
2303
2304// Manager ports
2305uint32_t
2307 WireBundle bundle) const {
2308 if (isMemTile(col, row))
2309 switch (bundle) {
2310 case WireBundle::DMA:
2311 case WireBundle::North:
2312 return 8;
2313 case WireBundle::South:
2314 return 4;
2315 case WireBundle::TileControl:
2316 return 1;
2317 case WireBundle::NorthControl:
2318 case WireBundle::Switch32:
2319 // 32 bit ports
2320 case WireBundle::South32:
2321 case WireBundle::North32:
2322 case WireBundle::Switch512:
2323 return 2;
2324 case WireBundle::West32:
2325 case WireBundle::East32:
2326 default:
2327 return 0;
2328 }
2329
2330 if (isShimNOCTile(col, row))
2331 switch (bundle) {
2332 case WireBundle::DMATrace:
2333 return 1;
2334 case WireBundle::DMA:
2335 return 2;
2336 case WireBundle::North:
2337 return 4;
2338 case WireBundle::West: {
2339 if (col == 0)
2340 return 0;
2341 return 2;
2342 }
2343 case WireBundle::East: {
2344 if (col == columns() - 1)
2345 return 0;
2346 return 2;
2347 }
2348 case WireBundle::TileControl:
2349 return 1;
2350 case WireBundle::NorthControl:
2351 case WireBundle::Switch32:
2352 // 32 bit ports
2353 case WireBundle::North32:
2354 case WireBundle::Switch512:
2355 case WireBundle::Controller32:
2356 return 2;
2357 case WireBundle::West32:
2358 if (col == 0)
2359 return 0;
2360 return 1;
2361 case WireBundle::East32:
2362 if (col == columns() - 1)
2363 return 0;
2364 return 1;
2365 case WireBundle::PLIO32:
2366 default:
2367 return 0;
2368 }
2369
2370 switch (bundle) {
2371 case WireBundle::Core:
2372 case WireBundle::DMA:
2373 case WireBundle::NorthControl:
2374 return 2;
2375 case WireBundle::North: {
2376 if (row == rows() - 1)
2377 return 0;
2378 return 8;
2379 }
2380 case WireBundle::West: {
2381 if (col == 0)
2382 return 0;
2383 return 2;
2384 }
2385 case WireBundle::South:
2386 return 4;
2387 case WireBundle::East: {
2388 if (col == columns() - 1)
2389 return 0;
2390 return 2;
2391 }
2392 case WireBundle::TileControl:
2393 case WireBundle::Switch32:
2394 return 1;
2395 // 32 bit ports
2396 case WireBundle::South32:
2397 case WireBundle::North32:
2398 return 2;
2399 case WireBundle::West32:
2400 case WireBundle::East32:
2401 case WireBundle::Switch512:
2402 return 1;
2403 default:
2404 return 0;
2405 }
2406}
2407
2408// Subordinate ports
2409uint32_t
2411 WireBundle bundle) const {
2412
2413 if (isMemTile(col, row))
2414 switch (bundle) {
2415 case WireBundle::DMA:
2416 return 10;
2417 case WireBundle::North:
2418 case WireBundle::South:
2419 return 4;
2420 case WireBundle::SouthControl:
2421 case WireBundle::Switch32:
2422 return 2;
2423 // 32-bit ports
2424 case WireBundle::Trace32:
2425 return 1;
2426 case WireBundle::Control32:
2427 case WireBundle::South32:
2428 case WireBundle::North32:
2429 case WireBundle::Switch512:
2430 return 2;
2431 case WireBundle::West32:
2432 case WireBundle::East32:
2433 default:
2434 return 0;
2435 }
2436
2437 if (isShimNOCTile(col, row))
2438 switch (bundle) {
2439 case WireBundle::DMA:
2440 case WireBundle::North:
2441 return 4;
2442 case WireBundle::West: {
2443 if (col == 0)
2444 return 0;
2445 return 2;
2446 }
2447 case WireBundle::East: {
2448 if (col == columns() - 1)
2449 return 0;
2450 return 2;
2451 }
2452 case WireBundle::DMAControl:
2453 case WireBundle::Switch32:
2454 return 2;
2455 // 32-bit ports
2456 case WireBundle::Trace32:
2457 return 1;
2458 case WireBundle::Control32:
2459 case WireBundle::North32:
2460 case WireBundle::Switch512:
2461 case WireBundle::Controller32:
2462 return 2;
2463 case WireBundle::West32:
2464 if (col == 0)
2465 return 0;
2466 return 1;
2467 case WireBundle::East32:
2468 if (col == columns() - 1)
2469 return 0;
2470 return 1;
2471 default:
2472 return 0;
2473 }
2474
2475 // compute/core tile
2476 switch (bundle) {
2477 case WireBundle::Core:
2478 case WireBundle::DMA:
2479 return 1;
2480 case WireBundle::North: {
2481 if (row == rows() - 1)
2482 return 0;
2483 return 4;
2484 }
2485 case WireBundle::West: {
2486 if (col == 0)
2487 return 0;
2488 return 2;
2489 }
2490 case WireBundle::South:
2491 return 8;
2492 case WireBundle::East: {
2493 if (col == columns() - 1)
2494 return 0;
2495 return 2;
2496 }
2497 case WireBundle::SouthControl:
2498 return 2;
2499 case WireBundle::Switch32:
2500 return 1;
2501 // 32-bit ports
2502 case WireBundle::Trace32:
2503 case WireBundle::South32:
2504 case WireBundle::North32:
2505 return 2;
2506 case WireBundle::Control32:
2507 case WireBundle::West32:
2508 case WireBundle::East32:
2509 case WireBundle::Switch512:
2510 return 1;
2511 default:
2512 return 0;
2513 }
2514}
2515
2517 WireBundle) const {
2518 return 0;
2519}
2520
2522 WireBundle) const {
2523 return 0;
2524}
2525
2526// src == subordinate
2527// dst == manager
2529 WireBundle srcBundle, int srcChan,
2530 WireBundle dstBundle,
2531 int dstChan) const {
2532 if (srcChan >= int(getNumSourceSwitchboxConnections(col, row, srcBundle)))
2533 return false;
2534 if (dstChan >= int(getNumDestSwitchboxConnections(col, row, dstBundle)))
2535 return false;
2536
2537 auto isBundleInList = [](WireBundle bundle,
2538 std::initializer_list<WireBundle> bundles) -> bool {
2539 return llvm::is_contained(bundles, bundle);
2540 };
2541
2542 auto isBundle32 = [&](WireBundle bundle) -> bool {
2543 return isBundleInList(
2544 bundle,
2545 {WireBundle::Control32, WireBundle::Controller32, WireBundle::Trace32,
2546 WireBundle::South32, WireBundle::West32, WireBundle::North32,
2547 WireBundle::East32, WireBundle::Switch512, WireBundle::PLIO32});
2548 };
2549
2550 // 32-bit switch is fully connected
2551 if (isBundle32(srcBundle) && isBundle32(dstBundle))
2552 return true;
2553
2554 // Crossing between the 32-bit and 512-bit switches is a bridge wire.
2555 if (isBundle32(srcBundle) != isBundle32(dstBundle))
2556 return false;
2557
2558 // Memtile
2559 if (isMemTile(col, row)) {
2560
2561 // DMA Subordinate
2562 if (srcBundle == WireBundle::DMA) {
2563 // DMA -> DMA
2564 if ((dstBundle == WireBundle::DMA) &&
2565 ((srcChan <= 3) || (srcChan >= 6 && srcChan <= 9)))
2566 return srcChan == dstChan;
2567 // DMA -> South
2568 if (dstBundle == WireBundle::South) {
2569 switch (srcChan) {
2570 case 0:
2571 case 2:
2572 return dstChan == 0;
2573 case 1:
2574 case 3:
2575 return dstChan == 1;
2576 case 5:
2577 case 7:
2578 return dstChan == 2;
2579 case 6:
2580 case 8:
2581 return dstChan == 3;
2582 case 4:
2583 case 9:
2584 return true;
2585 default:
2586 return false;
2587 }
2588 }
2589 // DMA -> North
2590 if (dstBundle == WireBundle::North) {
2591 if (srcChan == 4)
2592 return dstChan == 0;
2593 if (srcChan == 9)
2594 return dstChan == 4;
2595 return true;
2596 }
2597 // DMA -> Switch32
2598 if (dstBundle == WireBundle::Switch32)
2599 return true;
2600 // DMA -> NorthControl, Control
2601 if (isBundleInList(dstBundle,
2602 {WireBundle::NorthControl, WireBundle::TileControl})) {
2603 if (srcChan == 3 || srcChan == 4)
2604 return dstChan == 0;
2605 if (srcChan == 9 || srcChan == 10)
2606 return dstChan == 1;
2607 }
2608 return false;
2609 }
2610
2611 // South Subordinate
2612 if (srcBundle == WireBundle::South) {
2613 // South -> DMA
2614 if (dstBundle == WireBundle::DMA) {
2615 if (srcChan == 0)
2616 return dstChan == 0 || dstChan == 2 || dstChan == 3;
2617 if (srcChan == 1)
2618 return dstChan == 1 || dstChan == 2 || dstChan == 3;
2619 if (srcChan == 2)
2620 return dstChan == 4 || dstChan == 6 || dstChan == 7;
2621 if (srcChan == 3)
2622 return dstChan == 5 || dstChan == 6 || dstChan == 7;
2623 }
2624 // South -> South
2625 if (dstBundle == WireBundle::South)
2626 return srcChan == dstChan;
2627 // South -> North, Switch32
2628 return isBundleInList(dstBundle,
2629 {WireBundle::North, WireBundle::Switch32});
2630 }
2631
2632 // North Subordinate
2633 if (srcBundle == WireBundle::North) {
2634 // North -> DMA
2635 if (dstBundle == WireBundle::DMA) {
2636 if (dstChan <= 1)
2637 return true;
2638 if (srcChan == 0)
2639 return dstChan == 2;
2640 if (srcChan == 1)
2641 return dstChan == 3;
2642 if (srcChan == 2)
2643 return dstChan == 4 || dstChan == 5 || dstChan == 6;
2644 if (srcChan == 3)
2645 return dstChan == 4 || dstChan == 5 || dstChan == 7;
2646 }
2647 // North -> North
2648 if (dstBundle == WireBundle::North) {
2649 if (srcChan == 0 && dstChan == 0)
2650 return true;
2651 if (srcChan == 1 && dstChan == 1)
2652 return true;
2653 if (srcChan == 2 && dstChan == 4)
2654 return true;
2655 if (srcChan == 3 && dstChan == 5)
2656 return true;
2657 }
2658 // North -> Control
2659 if (dstBundle == WireBundle::TileControl) {
2660 if (srcChan == 1 && dstChan == 0)
2661 return true;
2662 if (srcChan == 3)
2663 return true;
2664 }
2665 // North -> South, Switch32
2666 return isBundleInList(dstBundle,
2667 {WireBundle::South, WireBundle::Switch32});
2668 }
2669
2670 // SouthControl Subordinate
2671 if (srcBundle == WireBundle::SouthControl) {
2672 // SouthControl -> DMA
2673 if (dstBundle == WireBundle::DMA) {
2674 if (srcChan == 0 && dstChan == 3)
2675 return true;
2676 if (srcChan == 1 && dstChan == 7)
2677 return true;
2678 }
2679 // SouthControl -> NorthControl
2680 if (dstBundle == WireBundle::NorthControl)
2681 return srcChan == dstChan;
2682 // SouthControl -> Control
2683 if (dstBundle == WireBundle::TileControl)
2684 return srcChan == 1 || dstChan == 0;
2685 // SouthControl -> Switch32
2686 if (dstBundle == WireBundle::Switch32)
2687 return true;
2688 return false;
2689 }
2690
2691 // Switch32 Subordinate
2692 if (srcBundle == WireBundle::Switch32) {
2693 // Switch32 and Switch512 are joined by the bridge, not a crossbar hop.
2694 if (isBundleInList(dstBundle,
2695 {WireBundle::Switch32, WireBundle::Switch512}))
2696 return false;
2697 if (isBundleInList(dstBundle,
2698 {WireBundle::TileControl, WireBundle::NorthControl}))
2699 return srcChan == dstChan;
2700 return true;
2701 }
2702
2703 return false;
2704 }
2705
2706 // Shimtile
2707 if (isShimNOCorPLTile(col, row)) {
2708 // The trace DMA accepts cardinal inputs and the 32b bridge only.
2709 if (dstBundle == WireBundle::DMATrace)
2710 return isBundleInList(srcBundle,
2711 {WireBundle::North, WireBundle::East,
2712 WireBundle::West, WireBundle::Switch32});
2713
2714 // DMA subordinate
2715 if (srcBundle == WireBundle::DMA) {
2716 if (dstBundle == WireBundle::DMA) {
2717 if (srcChan == 0 || srcChan == 2)
2718 return srcChan == dstChan;
2719 return false;
2720 }
2721 if (isBundleInList(dstBundle,
2722 {WireBundle::NorthControl, WireBundle::TileControl})) {
2723 if (srcChan <= 1 && dstChan == 0)
2724 return true;
2725 if (srcChan >= 2 && dstChan == 1)
2726 return true;
2727 return false;
2728 }
2729 return isBundleInList(dstBundle,
2730 {WireBundle::West, WireBundle::North,
2731 WireBundle::East, WireBundle::Switch32});
2732 }
2733 // North, East, West subordinate
2734 if (isBundleInList(srcBundle, {WireBundle::West, WireBundle::North,
2735 WireBundle::East})) {
2736 if (srcBundle == dstBundle)
2737 return srcChan == dstChan;
2738 if (isBundleInList(dstBundle,
2739 {WireBundle::DMA, WireBundle::West, WireBundle::North,
2740 WireBundle::East, WireBundle::Switch32}))
2741 return true;
2742 if (dstBundle == WireBundle::TileControl) {
2743 if (dstChan == 1)
2744 return (srcBundle == WireBundle::North) && (srcChan == 3);
2745 if (srcBundle == WireBundle::North)
2746 return (srcChan == 1) || (srcChan == 3);
2747 return true;
2748 }
2749 if (dstBundle == WireBundle::NorthControl) {
2750 if (srcBundle != WireBundle::North)
2751 return true;
2752 if (srcChan == 3)
2753 return true;
2754 if (srcChan == 1 && dstChan == 0)
2755 return true;
2756 return false;
2757 }
2758 return false;
2759 }
2760 // Control mm2s subordinate
2761 if (srcBundle == WireBundle::DMAControl) {
2762 if (isBundleInList(dstBundle, {WireBundle::West, WireBundle::East}))
2763 return (srcChan == 0) || (dstChan == 1);
2764 if (dstBundle == WireBundle::North) {
2765 if (dstChan <= 1)
2766 return srcChan == 0;
2767 if (dstChan >= 2)
2768 return srcChan == 1;
2769 }
2770 if (isBundleInList(dstBundle,
2771 {WireBundle::NorthControl, WireBundle::TileControl,
2772 WireBundle::Switch32})) {
2773 if (srcChan == dstChan)
2774 return true;
2775 if (dstBundle == WireBundle::TileControl)
2776 return dstChan == 0;
2777 return false;
2778 }
2779 }
2780 // Switch32 subordinate
2781 if (srcBundle == WireBundle::Switch32) {
2782 if (isBundleInList(dstBundle,
2783 {WireBundle::DMA, WireBundle::West, WireBundle::North,
2784 WireBundle::East, WireBundle::NorthControl}))
2785 return true;
2786 if (dstBundle == WireBundle::TileControl)
2787 return srcChan == dstChan;
2788 }
2789 // Switch512 is a 32-bit switch port; handled by the rule above.
2790 return false;
2791 }
2792
2793 // Coretile
2794 if (isCoreTile(col, row)) {
2795 // Core subordinate
2796 switch (srcBundle) {
2797 default:
2798 return false;
2799 case WireBundle::Core:
2800 if (dstBundle == WireBundle::DMA)
2801 return dstChan == 1;
2802 if (dstBundle == WireBundle::NorthControl)
2803 return dstChan == 0;
2804 return isBundleInList(dstBundle,
2805 {WireBundle::South, WireBundle::East,
2806 WireBundle::West, WireBundle::North,
2807 WireBundle::TileControl, WireBundle::Switch32});
2808 // DMA subordinate
2809 case WireBundle::DMA:
2810 if (dstBundle == WireBundle::DMA)
2811 return dstChan == 0;
2812 return isBundleInList(dstBundle,
2813 {WireBundle::Core, WireBundle::South,
2814 WireBundle::East, WireBundle::West,
2815 WireBundle::North, WireBundle::NorthControl,
2816 WireBundle::TileControl, WireBundle::Switch32});
2817 // North, South subordinate
2818 case WireBundle::North:
2819 case WireBundle::South:
2820 if (srcBundle == dstBundle) {
2821 if (srcChan == 0 || srcChan == 1)
2822 return srcChan == dstChan;
2823 if (srcChan == 4 || srcChan == 5)
2824 return (srcChan - 2) == dstChan;
2825 return false;
2826 }
2827 return isBundleInList(dstBundle, {WireBundle::Core, WireBundle::DMA,
2828 WireBundle::West, WireBundle::North,
2829 WireBundle::South, WireBundle::East,
2830 WireBundle::Switch32});
2831 // East, West subordinate
2832 case WireBundle::East:
2833 case WireBundle::West:
2834 if (dstBundle == srcBundle)
2835 return srcChan == dstChan;
2836 return isBundleInList(
2837 dstBundle, {WireBundle::Core, WireBundle::DMA, WireBundle::South,
2838 WireBundle::East, WireBundle::West, WireBundle::North,
2839 WireBundle::NorthControl, WireBundle::TileControl,
2840 WireBundle::Switch32});
2841 // SouthControl subordinate
2842 case WireBundle::SouthControl:
2843 if (isBundleInList(dstBundle, {WireBundle::Core, WireBundle::DMA}))
2844 return srcChan == dstChan;
2845 if (isBundleInList(dstBundle, {WireBundle::East, WireBundle::West}))
2846 return dstChan == 1 || srcChan == 0;
2847 if (dstBundle == WireBundle::NorthControl)
2848 return srcChan == 1 || dstChan == 0;
2849 return isBundleInList(dstBundle,
2850 {WireBundle::TileControl, WireBundle::Switch32});
2851 // Switch512 is a 32-bit switch port; handled by the rule above.
2852 case (WireBundle::Switch512):
2853 return false;
2854 // Switch32 subordinate (port on the 512-bit switch fed by the bridge)
2855 case (WireBundle::Switch32):
2856 return (isBundleInList(
2857 dstBundle, {WireBundle::Core, WireBundle::DMA, WireBundle::South,
2858 WireBundle::East, WireBundle::West, WireBundle::North,
2859 WireBundle::NorthControl, WireBundle::TileControl,
2860 WireBundle::Switch512}));
2861 }
2862 }
2863 return false;
2864}
2865
2866} // namespace AIE
2867} // namespace xilinx
bool isMemNorth(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is North of dst.
uint32_t getDmaControlAddress(int col, int row, int channel, AIE::DMAChannelDir direction) const override
Return the array address of the dma task queue register for the given col, row, channel and direction...
std::optional< TileID > getMemSouth(TileID src) const override
Return the tile ID of the memory to the south of the given tile, if it exists.
std::optional< uint32_t > getLocalLockAddress(uint32_t lockId, TileID tile) const override
std::optional< TileID > getMemNorth(TileID src) const override
Return the tile ID of the memory to the north of the given tile, if it exists.
std::optional< uint32_t > getStreamSwitchPortIndex(int col, int row, WireBundle bundle, uint32_t port_num, bool master) const override
Get stream switch port index for a given port specification Return port index for Stream_Switch_Event...
bool isMemSouth(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is South of dst.
std::optional< TileID > getMemWest(TileID src) const override
Return the tile ID of the memory to the west of the given tile, if it exists.
bool isLegalMemAffinity(int coreCol, int coreRow, int memCol, int memRow) const override
Return true if core can access the memory in mem.
uint64_t getDmaBdAddress(int col, int row, uint32_t bd_id, int channel, AIE::DMAChannelDir direction) const override
Return the array address of the dma buffer descriptor for the given col, row, buffer descriptor id,...
uint32_t getNumSourceShimMuxConnections(int col, int row, WireBundle bundle) const override
Return the number of sources of connections inside a shimmux.
uint32_t getNumDestSwitchboxConnections(int col, int row, WireBundle bundle) const override
Return the number of destinations of connections inside a switchbox.
bool isMemEast(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is East of dst.
bool isMemWest(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is West of dst.
uint32_t getDmaBdAddressOffset(int col, int row) const override
Return the offset of the base address field within the shim dma buffer descriptor.
std::vector< std::pair< uint32_t, uint32_t > > getShimBurstEncodingsAndLengths() const override
AIEArch getTargetArch() const override
AIE1 TargetModel.
uint32_t getNumDestShimMuxConnections(int col, int row, WireBundle bundle) const override
Return the number of destinations of connections inside a shimmux.
std::optional< TileID > getMemEast(TileID src) const override
Return the tile ID of the memory to the east of the given tile, if it exists.
bool isLegalTileConnection(int col, int row, WireBundle srcBundle, int srcChan, WireBundle dstBundle, int dstChan) const override
uint32_t getNumSourceSwitchboxConnections(int col, int row, WireBundle bundle) const override
Return the number of sources of connections inside a switchbox.
uint32_t getNumSourceSwitchboxConnections(int col, int row, WireBundle bundle) const override
Return the number of sources of connections inside a switchbox.
uint32_t getDmaControlAddress(int col, int row, int channel, AIE::DMAChannelDir direction) const override
Return the array address of the dma task queue register for the given col, row, channel and direction...
uint32_t getNumDestSwitchboxConnections(int col, int row, WireBundle bundle) const override
Return the number of destinations of connections inside a switchbox.
std::optional< uint32_t > getDmaStatusAddress(int col, int row, int channel, AIE::DMAChannelDir direction) const override
Return the address of the DMA status register for a channel, or nullopt when this target's layout has...
uint64_t getDmaBdAddress(int col, int row, uint32_t bd_id, int channel, AIE::DMAChannelDir direction) const override
Return the array address of the dma buffer descriptor for the given col, row, buffer descriptor id,...
std::optional< uint32_t > getStreamSwitchPortIndex(int col, int row, WireBundle bundle, uint32_t channel, bool master) const override
Get stream switch port index for a given port specification Return port index for Stream_Switch_Event...
bool isLegalTileConnection(int col, int row, WireBundle srcBundle, int srcChan, WireBundle dstBundle, int dstChan) const override
uint32_t getNumSourceSwitchboxConnections(int col, int row, WireBundle bundle) const override
Return the number of sources of connections inside a switchbox.
std::vector< std::pair< uint32_t, uint32_t > > getShimBurstEncodingsAndLengths() const override
uint32_t getNumLocks(AIETileType tileType) const override
Return the number of lock objects for a given tile type.
std::optional< uint32_t > getDmaStatusAddress(int col, int row, int channel, AIE::DMAChannelDir direction) const override
Return the address of the DMA status register for a channel, or nullopt when this target's layout has...
std::optional< TileID > getMemWest(TileID src) const override
Return the tile ID of the memory to the west of the given tile, if it exists.
std::optional< uint32_t > getStreamSwitchPortIndex(int col, int row, WireBundle bundle, uint32_t port_num, bool master) const override
Get stream switch port index for a given port specification Return port index for Stream_Switch_Event...
std::unique_ptr< RegisterDatabase > loadRegisterDatabase() const override
AIE2 TargetModel.
AIEArch getTargetArch() const override
Return the target architecture.
bool isLegalMemAffinity(int coreCol, int coreRow, int memCol, int memRow) const override
Return true if core can access the memory in mem.
std::optional< TileID > getMemEast(TileID src) const override
Return the tile ID of the memory to the east of the given tile, if it exists.
bool isMemNorth(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is North of dst.
uint32_t getNumDestShimMuxConnections(int col, int row, WireBundle bundle) const override
Return the number of destinations of connections inside a shimmux.
uint64_t getDmaBdAddress(int col, int row, uint32_t bd_id, int channel, AIE::DMAChannelDir direction) const override
Return the array address of the dma buffer descriptor for the given col, row, buffer descriptor id,...
uint32_t getDmaControlAddress(int col, int row, int channel, AIE::DMAChannelDir direction) const override
Return the array address of the dma task queue register for the given col, row, channel and direction...
std::optional< uint32_t > getLocalLockAddress(uint32_t lockId, TileID tile) const override
std::optional< TileID > getMemSouth(TileID src) const override
Return the tile ID of the memory to the south of the given tile, if it exists.
const DmaBdLayout * getDmaBdLayout(AIETileType tileType) const override
Return the register layout of a buffer descriptor on the given tile type, or null if the target has n...
uint32_t getNumDestSwitchboxConnections(int col, int row, WireBundle bundle) const override
Return the number of destinations of connections inside a switchbox.
bool isMemWest(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is West of dst.
bool isMemSouth(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is South of dst.
std::optional< TileID > getMemNorth(TileID src) const override
Return the tile ID of the memory to the north of the given tile, if it exists.
bool isMemEast(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is East of dst.
uint32_t getNumSourceShimMuxConnections(int col, int row, WireBundle bundle) const override
Return the number of sources of connections inside a shimmux.
uint32_t getDmaBdAddressOffset(int col, int row) const override
Return the offset of the base address field within the shim dma buffer descriptor.
uint32_t getNumLocks(AIETileType tileType) const override
Return the number of lock objects for a given tile type.
uint32_t getRowShift() const override
std::optional< TileID > getMemEast(TileID src) const override
Return the tile ID of the memory to the east of the given tile, if it exists.
const DmaBdLayout * getDmaBdLayout(AIETileType tileType) const override
Return the register layout of a buffer descriptor on the given tile type, or null if the target has n...
uint64_t getDmaBdAddress(int col, int row, uint32_t bd_id, int channel, AIE::DMAChannelDir direction) const override
Shim data BDs need no channel; control, trace and memtile BDs do (fatal error without one).
uint32_t getDmaControlAddress(int col, int row, int channel, AIE::DMAChannelDir direction) const override
Return the array address of the dma task queue register for the given col, row, channel and direction...
uint32_t getBdPoolStartId(int col, int row, uint32_t poolId) const override
bool isMemWest(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is West of dst.
uint32_t getTileAddress(int col, int row) const override
A memtile spans five address rows (registers, then 4 MiB of data), so memtile row m starts at address...
bool isLegalMemAffinity(int coreCol, int coreRow, int memCol, int memRow) const override
Return true if core can access the memory in mem.
std::unique_ptr< RegisterDatabase > loadRegisterDatabase() const override
AIE4 TargetModel.
bool isMemSouth(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is South of dst.
uint32_t getNumBDsInPool(int col, int row, uint32_t poolId) const override
uint32_t getNumDestSwitchboxConnections(int col, int row, WireBundle bundle) const override
Return the number of destinations of connections inside a switchbox.
uint32_t getDataMemoryOffset(int col, int row) const override
A memtile's data memory starts 1 MiB into its window.
bool isMemNorth(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is North of dst.
AIEArch getTargetArch() const override
Return the target architecture.
uint32_t getMemTileSize() const override
Return the size (in bytes) of a MemTile.
uint32_t getBdPoolId(int col, int row, int channel, DMAChannelDir dir) const override
Shim: MM2S 0-1 and S2MM 0 use BDs 0-15, MM2S 2-3 and S2MM 1 BDs 16-31; ControlMM2S (8) and TraceS2MM ...
uint32_t getNumSourceSwitchboxConnections(int col, int row, WireBundle bundle) const override
Return the number of sources of connections inside a switchbox.
std::optional< uint32_t > getLocalLockAddress(uint32_t lockId, TileID tile) const override
std::optional< uint32_t > getLockLocalBaseIndex(int localCol, int localRow, int lockCol, int lockRow) const override
A memtile DMA reaches the locks and memory of the 15 memtiles within seven columns,...
bool isMemEast(int srcCol, int srcRow, int dstCol, int dstRow) const override
Return true if src has a memory tile which is East of dst.
uint32_t getNumDestShimMuxConnections(int col, int row, WireBundle bundle) const override
Return the number of destinations of connections inside a shimmux.
bool isLegalTileConnection(int col, int row, WireBundle srcBundle, int srcChan, WireBundle dstBundle, int dstChan) const override
std::optional< uint32_t > getMemLocalBaseAddress(int localCol, int localRow, int memCol, int memRow) const override
Return the memory base address (or offset) in the local tile when accessing a neighbor's memory or an...
uint32_t getNumSourceShimMuxConnections(int col, int row, WireBundle bundle) const override
Return the number of sources of connections inside a shimmux.
uint32_t getNumBDs(AIETileType tileType) const override
16 ids per core tile or memtile channel pool; 32 across two shim banks.
std::vector< std::pair< uint32_t, uint32_t > > getShimBurstEncodingsAndLengths() const override
uint32_t getColumnShift() const override
uint32_t getRowFromAddress(uint32_t address) const override
Inverse of getTileAddress() for any address in the tile's window.
uint32_t getDmaBdAddressOffset(int col, int row) const override
Return the offset of the base address field within the shim dma buffer descriptor.
std::optional< uint32_t > encodeFieldValue(const BitFieldInfo &field, uint32_t value) const
Encode a field value with proper bit shifting.
std::optional< uint32_t > resolvePortValue(llvm::StringRef value, TileID tile, bool master) const
Resolve stream switch port specification to port index.
llvm::DenseMap< TileID, int > getTileToControllerIdMap(bool columnWiseUniqueIDs=true) const
Return a mapping from tile coordinates to controller IDs.
virtual uint32_t getTileAddress(int col, int row) const
Return the base address of the tile's window.
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...
bool isNorth(int srcCol, int srcRow, int dstCol, int dstRow) const
Return true if src is North of dst.
bool isSouth(int srcCol, int srcRow, int dstCol, int dstRow) const
Return true if src is South of dst.
bool isWest(int srcCol, int srcRow, int dstCol, int dstRow) const
Return true if src is West of dst.
virtual bool isSupportedBlockFormat(std::string const &format) const
bool isCoreTile(int col, int row) const
Return true if the given tile is a Core tile.
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.
virtual bool isMemNorth(int srcCol, int srcRow, int dstCol, int dstRow) const =0
Return true if src has a memory tile which is North of dst.
virtual uint32_t getNumSourceShimMuxConnections(int col, int row, WireBundle bundle) const =0
Return the number of sources of connections inside a shimmux.
bool isMemTile(int col, int row) const
Return true if the given tile is a Mem tile.
virtual uint32_t getMemSouthBaseAddress() const =0
Return the base address in the local address map for a core.
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 uint32_t getLocalMemorySize() const =0
Return the size (in bytes) of the local data memory of a core.
std::optional< uint32_t > getFieldMask(const BitFieldInfo &field) const
Compute a 32-bit mask for a register field.
virtual uint32_t getNumLocks(AIETileType tileType) const =0
Return the number of lock objects for a given tile type.
bool isOrdinaryWriteAddress(TileID tile, uint32_t offset) const
std::optional< uint32_t > lookupEvent(llvm::StringRef name, TileID tile, bool isMem=false) const
Lookup event number by name and tile.
const RegisterInfo * lookupRegister(llvm::StringRef name, TileID tile, bool isMem=false) const
Register Database API - provides access to register and event information for trace configuration and...
const RegisterDatabase * getRegisterDatabase() const
Get the register database, loading it lazily on first access.
virtual bool isMemEast(int srcCol, int srcRow, int dstCol, int dstRow) const =0
Return true if src has a memory tile which is East of dst.
bool isShimPLTile(int col, int row) const
Return true if the given tile is a ShimPL tile.
virtual uint64_t getDmaBdAddress(int col, int row, uint32_t bd_id, int channel=-1, AIE::DMAChannelDir direction=AIE::DMAChannelDir::MM2S) const =0
Return the array address of the dma buffer descriptor for the given col, row, buffer descriptor id,...
bool isBdChannelAccessible(int col, int row, uint32_t bd_id, int channel, DMAChannelDir dir) const
virtual bool isValidTile(TileID src) const
Return true if the given tile ID is valid.
bool isEast(int srcCol, int srcRow, int dstCol, int dstRow) const
Return true if src is East of dst.
virtual bool isMemSouth(int srcCol, int srcRow, int dstCol, int dstRow) const =0
Return true if src has a memory tile which is South of dst.
bool isShimNOCorPLTile(int col, int row) const
Return true if the given tile is either a ShimNOC or ShimPL tile.
virtual uint32_t getMemWestBaseAddress() const =0
Return the base address in the local address map for a core.
virtual int rows() const =0
Return the number of rows in the device.
bool isShimNOCTile(int col, int row) const
Return true if the given tile is a ShimNOC tile.
virtual uint32_t getNumBDs(AIETileType tileType) const =0
Return the size of the BD id space of a tile type (see getTotalNumBDs()).
virtual std::unique_ptr< RegisterDatabase > loadRegisterDatabase() const
Subclasses override to provide architecture-specific database loading.
virtual uint32_t getProgramMemorySize() const =0
Return the size (in bytes) of a core's program memory.
virtual uint32_t getMemNorthBaseAddress() const =0
Return the base address in the local address map for a core.
uint32_t getNumDMAChannels(int col, int row, AIE::DMAChannelDir dir) const
Return the number of DMA channels a tile has in one direction.
virtual int columns() const =0
Return the number of columns in the device.
virtual uint32_t getMemEastBaseAddress() const =0
Return the base address in the local address map for a core.
virtual uint32_t getNumMemTileRows() const =0
virtual uint32_t getNumDestShimMuxConnections(int col, int row, WireBundle bundle) const =0
Return the number of destinations of connections inside a shimmux.
virtual bool isMemWest(int srcCol, int srcRow, int dstCol, int dstRow) const =0
Return true if src has a memory tile which is West of dst.
virtual uint32_t getNumDestSwitchboxConnections(int col, int row, WireBundle bundle) const =0
Return the number of destinations of connections inside a switchbox.
bool isInternal(int srcCol, int srcRow, int dstCol, int dstRow) const
Return true if src is the internal memory of dst.
virtual uint32_t getRowShift() const =0
uint32_t getRowFieldMask() const
virtual bool hasShimMux(int col, int row) const
True if the tile's DMA/NOC/PLIO ports sit behind an aie.shim_mux; otherwise its DMA is routed in the ...
virtual uint32_t getMemTileSize() const =0
Return the size (in bytes) of a MemTile.
virtual std::optional< uint32_t > getStreamSwitchPortIndex(int col, int row, WireBundle bundle, uint32_t channel, bool master) const =0
Get stream switch port index for a given port specification Return port index for Stream_Switch_Event...
virtual uint32_t getNumSourceSwitchboxConnections(int col, int row, WireBundle bundle) const =0
Return the number of sources of connections inside a switchbox.
std::vector< std::pair< uint32_t, uint32_t > > getShimBurstEncodingsAndLengths() const override
AIEArch getTargetArch() const override
Return the target architecture.
bool isSupportedBlockFormat(std::string const &format) const override
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.
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
bool isMM2S(DMAChannelDir dir)
True if dir moves data out of memory onto a stream (MM2S, ControlMM2S).
Definition AIEEnums.h:19
WireBundle getDMAChannelBundle(DMAChannelDir dir)
The stream-switch bundle the channels of dir use.
Definition AIEEnums.h:29
Bit field information for a register.
The register layout of one tile type's DMA buffer descriptor.
DmaBdField d0Size
Without a d0Stride field the innermost dimension is contiguous.