32 int tileCol,
int tileRow,
33 llvm::StringRef deviceName) {
34 DenseMap<TileID, Operation *> tiles;
35 DenseMap<Operation *, SmallVector<BufferOp, 4>> buffers;
37 DeviceOp targetOp = AIE::DeviceOp::getForSymbolInModule(module, deviceName);
39 module.emitOpError("expected aie.device operation at toplevel");
55 for (
auto tile : targetOp.getOps<TileOp>())
56 if (tile.colIndex() == tileCol && tile.rowIndex() == tileRow) {
58 TileID srcCoord = {tile.colIndex(), tile.rowIndex()};
61 output <<
"_entry_point _main_init\n";
62 output <<
"_symbol " << corefunc <<
" _after _main_init\n";
63 output <<
"_symbol _main_init 0\n";
64 int dataMemoryStart = targetModel.getMemSouthBaseAddress();
65 output <<
"_reserved DMb 0x00000 " << utohexstr(dataMemoryStart)
66 <<
" // Don't put data in code memory\n";
69 if (
auto core = tile.getCoreOp()) {
70 if (core.getStackBank() && !core.getStackAddress())
71 return core.emitOpError(
72 "stack_bank has no assigned stack_address; run "
73 "--aie-assign-buffer-addresses with bank-aware allocation");
74 stackRun = core.getStackRun();
76 output <<
"_stack DM_stack "
77 << utohexstr(targetModel.getMemInternalBaseAddress(srcCoord) +
79 <<
" " << utohexstr(stackRun.
size) <<
" // stack for core\n";
81 auto doBuffer = [&](std::optional<TileID> tile,
int offset,
82 const std::string &dir) {
84 output <<
"// " + dir +
86 " -------------------------------------------------\n";
87 uint32_t localMemSize = targetModel.getLocalMemorySize();
89 output <<
"_reserved DMb " << utohexstr(offset) <<
" "
90 << utohexstr(localMemSize) <<
" "
91 <<
" // Don't allocate variables in " << dir
95 if (tiles.count(*tile)) {
96 for (
auto buf : buffers[tiles[*tile]]) {
97 if (buf.getCoreData())
99 std::string bufName(buf.name().getValue());
101 int numBytes = buf.getAllocationSize();
106 output <<
"_symbol " << bufName <<
" "
107 << utohexstr(offset + bufferBaseAddr) <<
" " << numBytes
109 output <<
"_extern " << bufName <<
"\n";
110 output <<
"_reserved DMb " << utohexstr(offset + bufferBaseAddr)
111 <<
" " << numBytes <<
'\n';
116 uint32_t localMemSize = targetModel.getLocalMemorySize();
117 output <<
"_reserved DMb " << utohexstr(offset) <<
" "
118 << utohexstr(localMemSize) <<
" "
119 <<
" // No tile with memory exists to the " << dir <<
".\n";
123 output <<
"\n// mapping neighbors tile memory\n";
124 doBuffer(targetModel.getMemSouth(srcCoord),
125 targetModel.getMemSouthBaseAddress(), std::string(
"south"));
126 doBuffer(targetModel.getMemWest(srcCoord),
127 targetModel.getMemWestBaseAddress(), std::string(
"west"));
128 doBuffer(targetModel.getMemNorth(srcCoord),
129 targetModel.getMemNorthBaseAddress(), std::string(
"north"));
130 doBuffer(targetModel.getMemEast(srcCoord),
131 targetModel.getMemEastBaseAddress(), std::string(
"east"));
132 output <<
"// end mapping neighbors tile memory\n\n";
134 int addressSpaceSize = targetModel.getCoreDataAddressSpaceSize();
135 int dataMemoryEnd = targetModel.getMemEastBaseAddress() +
136 targetModel.getLocalMemorySize();
137 output <<
"_reserved DMb " << utohexstr(dataMemoryEnd) <<
" "
138 << utohexstr(addressSpaceSize - dataMemoryEnd)
139 <<
" // And everything else the core can't see\n";
141 if (
auto coreOp = tile.getCoreOp()) {
143 if (
auto filesAttr = coreOp.getLinkFiles()) {
145 for (
auto f : filesAttr->getAsRange<mlir::StringAttr>())
146 output <<
"_include _file " << f.getValue() <<
"\n";
147 }
else if (
auto linkWith = coreOp.getLinkWith()) {
151 output <<
"_include _file " << linkWith->str() <<
"\n";
154 output <<
"_resolve _main core_" << tile.getCol() <<
"_" << tile.getRow()
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