121 static llvm::cl::opt<int> tileCol(
122 "tilecol", llvm::cl::desc(
"column coordinate of core to translate"),
124 static llvm::cl::opt<int> tileRow(
125 "tilerow", llvm::cl::desc(
"row coordinate of core to translate"),
128#ifdef AIE_ENABLE_AIRBIN
129 static llvm::cl::opt<std::string> outputFilename(
130 "airbin-output-filepath",
131 llvm::cl::desc(
"Output airbin file path (including filename)"),
132 llvm::cl::value_desc(
"airbin-output-filepath"),
133 llvm::cl::init(
"airbin.elf"));
135 static llvm::cl::opt<std::string> coreFilesDir(
136 "airbin-aux-core-dir-path",
137 llvm::cl::desc(
"Auxiliary core elf files dir path"),
138 llvm::cl::value_desc(
"airbin-aux-core-dir-path"), llvm::cl::init(
"."));
141 static llvm::cl::opt<std::string> workDirPath(
142 "work-dir-path", llvm::cl::Optional,
143 llvm::cl::desc(
"Absolute path to working directory"));
145 static llvm::cl::opt<bool> bigEndian(
"big-endian", llvm::cl::init(
false),
146 llvm::cl::desc(
"Endianness"));
148 static llvm::cl::opt<bool> cdoUnified(
149 "cdo-unified", llvm::cl::init(
false),
150 llvm::cl::desc(
"Emit unified CDO bin (or separate bins)"));
151 static llvm::cl::opt<bool> cdoDebug(
"cdo-debug", llvm::cl::init(
false),
152 llvm::cl::desc(
"Emit cdo debug info"));
153 static llvm::cl::opt<bool> cdoAieSim(
154 "cdo-aiesim", llvm::cl::init(
false),
155 llvm::cl::desc(
"AIESIM target cdo generation"));
156 static llvm::cl::opt<bool> cdoXaieDebug(
157 "cdo-xaie-debug", llvm::cl::init(
false),
158 llvm::cl::desc(
"Emit libxaie debug info"));
159 static llvm::cl::opt<size_t> cdoEnableCores(
160 "cdo-enable-cores", llvm::cl::init(
true),
161 llvm::cl::desc(
"Enable cores in CDO"));
163 static llvm::cl::opt<bool> outputBinary(
164 "aie-output-binary", llvm::cl::init(
true),
166 "Select binary (true) or text (false) output for supported "
167 "translations. e.g. aie-npu-to-binary, aie-ctrlpkt-to-bin"));
169 static llvm::cl::opt<std::string> sequenceName(
170 "aie-sequence-name", llvm::cl::init(
""),
172 "Specify the name of the aiex.runtime_sequence to translate"));
174 TranslateFromMLIRRegistration registrationMMap(
175 "aie-generate-mmap",
"Generate AIE memory map",
176 [](ModuleOp module, raw_ostream &output) {
177 DenseMap<TileID, Operation *> tiles;
178 DenseMap<Operation *, SmallVector<BufferOp, 4>> buffers;
180 if (module.getOps<DeviceOp>().empty()) {
181 module.emitOpError(
"expected AIE.device operation at toplevel");
183 DeviceOp targetOp = *(module.getOps<DeviceOp>().begin());
185 collectTiles(targetOp, tiles);
187 using tileType = std::pair<TileID, Operation *>;
189 bool operator()(
const tileType &lhs,
const tileType &rhs)
const {
190 return lhs.first < rhs.first;
193 std::set<tileType, tileCmp> sortedTiles;
194 for (
auto tile : tiles)
195 sortedTiles.insert(tileType{tile.first, tile.second});
197 collectBuffers(targetOp, buffers);
199 for (
auto tile : sortedTiles) {
200 Operation *srcTileOp = tile.second;
201 TileID srcCoord = cast<TileOp>(srcTileOp).getTileID();
202 int srcCol = srcCoord.col;
203 int srcRow = srcCoord.row;
205 output <<
"// Tile(" << srcCol <<
", " << srcRow <<
")\n";
206 output <<
"// Memory map: name base_address num_bytes\n";
208 auto doBuffer = [&](std::optional<TileID> tile,
int offset) {
209 if (tiles.count(*tile))
210 for (
auto buf : buffers[tiles[*tile]])
216 if (
auto tile = targetModel.getMemSouth(srcCoord))
217 doBuffer(tile, targetModel.getMemSouthBaseAddress());
218 if (
auto tile = targetModel.getMemWest(srcCoord))
219 doBuffer(tile, targetModel.getMemWestBaseAddress());
220 if (
auto tile = targetModel.getMemNorth(srcCoord))
221 doBuffer(tile, targetModel.getMemNorthBaseAddress());
222 if (
auto tile = targetModel.getMemEast(srcCoord))
223 doBuffer(tile, targetModel.getMemEastBaseAddress());
229 TranslateFromMLIRRegistration registrationShimDMAToJSON(
230 "aie-generate-json",
"Transform AIE shim DMA allocation info into JSON",
231 [](ModuleOp module, raw_ostream &output) {
232 for (
auto d : module.getOps<DeviceOp>()) {
233 llvm::json::Object moduleJSON;
234 for (
auto shimDMAMeta : d.getOps<ShimDMAAllocationOp>()) {
235 llvm::json::Object shimJSON;
236 auto channelDir = shimDMAMeta.getChannelDirAttr();
237 shimJSON[
"channelDir"] =
attrToJSON(channelDir);
238 auto channelIndex = shimDMAMeta.getChannelIndexAttr();
239 shimJSON[
"channelIndex"] =
attrToJSON(channelIndex);
240 auto col = shimDMAMeta.getColAttr();
242 moduleJSON[shimDMAMeta.getSymName()] =
243 llvm::json::Value(std::move(shimJSON));
245 llvm::json::Value topv(std::move(moduleJSON));
247 llvm::raw_string_ostream ss(ret);
248 ss << llvm::formatv(
"{0:2}", topv) <<
"\n";
255 TranslateFromMLIRRegistration registrationLDScript(
256 "aie-generate-ldscript",
"Generate AIE loader script",
257 [](ModuleOp module, raw_ostream &output) {
262 TranslateFromMLIRRegistration registrationBCF(
263 "aie-generate-bcf",
"Generate AIE bcf",
264 [](ModuleOp module, raw_ostream &output) {
269 TranslateFromMLIRRegistration registrationTargetArch(
270 "aie-generate-target-arch",
"Get the target architecture",
273 TranslateFromMLIRRegistration registrationCoreList(
274 "aie-generate-corelist",
"Generate python list of cores",
275 [](ModuleOp module, raw_ostream &output) {
276 if (module.getOps<DeviceOp>().empty()) {
277 module.emitOpError(
"expected AIE.device operation at toplevel");
279 DeviceOp targetOp = *(module.getOps<DeviceOp>().begin());
282 for (
auto tileOp : targetOp.getOps<TileOp>()) {
283 int col = tileOp.colIndex();
284 int row = tileOp.rowIndex();
285 if (
auto coreOp = tileOp.getCoreOp()) {
286 std::string elfFile =
"None";
287 if (
auto fileAttr = coreOp.getElfFile())
288 elfFile =
"\"" + fileAttr.value().str() +
"\"";
289 output <<
'(' <<
col <<
',' <<
row <<
',' << elfFile <<
"),";
297 TranslateFromMLIRRegistration registrationXADF(
298 "adf-generate-cpp-graph",
"Translate ADFDialect to C++ graph",
300 registry.insert<xilinx::ADF::ADFDialect>();
301 registerDialects(registry);
303#ifdef AIE_ENABLE_AIRBIN
304 TranslateFromMLIRRegistration registrationAirbin(
305 "aie-generate-airbin",
"Generate configuration binary blob",
306 [](ModuleOp module, raw_ostream &) {
311 TranslateFromMLIRRegistration registrationXAIE(
312 "aie-generate-xaie",
"Generate libxaie configuration",
313 [](ModuleOp module, raw_ostream &output) {
317 TranslateFromMLIRRegistration registrationHSA(
318 "aie-generate-hsa",
"Generate hsa data movement configuration",
319 [](ModuleOp module, raw_ostream &output) {
323 TranslateFromMLIRRegistration registrationXJSON(
324 "aie-flows-to-json",
"Translate AIE flows to JSON",
AIEFlowsToJSON,
326 TranslateFromMLIRRegistration registrationXPE(
327 "aie-mlir-to-xpe",
"Translate AIE design to XPE file for simulation",
329 TranslateFromMLIRRegistration registrationSCSimConfig(
330 "aie-mlir-to-scsim-config",
331 "Translate AIE design to SCSimConfig file for simulation",
333 TranslateFromMLIRRegistration registrationShimSolution(
334 "aie-mlir-to-shim-solution",
335 "Translate AIE design to ShimSolution file for simulation",
337 TranslateFromMLIRRegistration registrationCDODirect(
338 "aie-generate-cdo",
"Generate libxaie for CDO directly",
339 [](ModuleOp module, raw_ostream &) {
340 SmallString<128> workDirPath_;
341 if (workDirPath.getNumOccurrences() == 0) {
342 if (llvm::sys::fs::current_path(workDirPath_))
343 llvm::report_fatal_error(
344 "couldn't get cwd to use as work-dir-path");
346 workDirPath_ = workDirPath.getValue();
347 LLVM_DEBUG(llvm::dbgs() <<
"work-dir-path: " << workDirPath_ <<
"\n");
349 cdoUnified, cdoDebug, cdoAieSim,
350 cdoXaieDebug, cdoEnableCores);
353 TranslateFromMLIRRegistration registrationNPU(
354 "aie-npu-to-binary",
"Translate npu instructions to binary",
355 [](ModuleOp module, raw_ostream &output) {
356 std::vector<uint32_t> instructions;
361 output.write(
reinterpret_cast<const char *
>(instructions.data()),
362 instructions.size() *
sizeof(uint32_t));
364 for (
auto w : instructions)
365 output <<
llvm::format(
"%08X\n", w);
370 TranslateFromMLIRRegistration registrationCtrlPkt(
371 "aie-ctrlpkt-to-bin",
"Translate aiex.control_packet ops to binary",
372 [](ModuleOp module, raw_ostream &output) {
373 std::vector<uint32_t> instructions;
379 output.write(
reinterpret_cast<const char *
>(instructions.data()),
380 instructions.size() *
sizeof(uint32_t));
382 for (
auto w : instructions)
383 output <<
llvm::format(
"%08X\n", w);