31 int tileCol,
int tileRow,
32 llvm::StringRef deviceName) {
33 DenseMap<TileID, Operation *> tiles;
34 DenseMap<Operation *, SmallVector<BufferOp, 4>> buffers;
36 DeviceOp targetOp = AIE::DeviceOp::getForSymbolInModule(module, deviceName);
38 module.emitOpError("expected aie.device operation at toplevel");
54 for (
auto tile : targetOp.getOps<TileOp>())
55 if (tile.colIndex() == tileCol && tile.rowIndex() == tileRow) {
57 TileID srcCoord = {tile.colIndex(), tile.rowIndex()};
59 std::string corefunc = std::string(
"core_") +
60 std::to_string(tile.getCol()) +
"_" +
61 std::to_string(tile.getRow());
62 output <<
"_entry_point _main_init\n";
63 output <<
"_symbol " << corefunc <<
" _after _main_init\n";
64 output <<
"_symbol _main_init 0\n";
65 int dataMemoryStart = targetModel.getMemSouthBaseAddress();
66 output <<
"_reserved DMb 0x00000 " <<
utohexstr(dataMemoryStart)
67 <<
" // Don't put data in code memory\n";
70 if (
auto core = tile.getCoreOp())
71 stacksize = core.getStackSize();
72 output <<
"_stack DM_stack "
73 <<
utohexstr(targetModel.getMemInternalBaseAddress(srcCoord))
74 <<
" " <<
utohexstr(stacksize) <<
" // stack for core\n";
76 auto doBuffer = [&](std::optional<TileID> tile,
int offset,
77 const std::string &dir) {
79 output <<
"// " + dir +
81 " -------------------------------------------------\n";
82 uint32_t localMemSize = targetModel.getLocalMemorySize();
84 output <<
"_reserved DMb " <<
utohexstr(offset) <<
" "
86 <<
" // Don't allocate variables in " << dir
90 if (tiles.count(*tile)) {
91 for (
auto buf : buffers[tiles[*tile]]) {
92 std::string bufName(buf.name().getValue());
94 int numBytes = buf.getAllocationSize();
95 if (buf.getInitialValue() && tile != srcCoord) {
96 output <<
"// skip initialization of " << buf.name()
97 <<
" which is initialized "
98 "in the neighboring tile\n";
101 }
else if (buf.getInitialValue() && tile == srcCoord) {
102 output <<
"_overlay " << bufName <<
" "
103 <<
utohexstr(offset + bufferBaseAddr) <<
" // "
104 << numBytes <<
" bytes\n";
106 output <<
"_symbol " << bufName <<
" "
107 <<
utohexstr(offset + bufferBaseAddr) <<
" " << numBytes
109 output <<
"_extern " << bufName <<
"\n";
110 output <<
"_reserved DMb " <<
utohexstr(offset + bufferBaseAddr)
111 <<
" " << numBytes <<
'\n';
117 uint32_t localMemSize = targetModel.getLocalMemorySize();
118 output <<
"_reserved DMb " <<
utohexstr(offset) <<
" "
120 <<
" // No tile with memory exists to the " << dir <<
".\n";
124 output <<
"\n// mapping neighbors tile memory\n";
125 doBuffer(targetModel.getMemSouth(srcCoord),
126 targetModel.getMemSouthBaseAddress(), std::string(
"south"));
127 doBuffer(targetModel.getMemWest(srcCoord),
128 targetModel.getMemWestBaseAddress(), std::string(
"west"));
129 doBuffer(targetModel.getMemNorth(srcCoord),
130 targetModel.getMemNorthBaseAddress(), std::string(
"north"));
131 doBuffer(targetModel.getMemEast(srcCoord),
132 targetModel.getMemEastBaseAddress(), std::string(
"east"));
133 output <<
"// end mapping neighbors tile memory\n\n";
135 int addressSpaceSize = 0x100000;
136 int dataMemoryEnd = targetModel.getMemEastBaseAddress() +
137 targetModel.getLocalMemorySize();
138 output <<
"_reserved DMb " <<
utohexstr(dataMemoryEnd) <<
" "
139 <<
utohexstr(addressSpaceSize - dataMemoryEnd)
140 <<
" // And everything else the core can't see\n";
142 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 (coreOp.getLinkWith()) {
150 output <<
"_include _file " << coreOp.getLinkWith().value().str()
154 output <<
"_resolve _main core_" << tile.getCol() <<
"_" << tile.getRow()