127 static llvm::cl::opt<int> tileCol(
128 "tilecol", llvm::cl::desc(
"column coordinate of core to translate"),
130 static llvm::cl::opt<int> tileRow(
131 "tilerow", llvm::cl::desc(
"row coordinate of core to translate"),
134 static llvm::cl::opt<std::string> workDirPath(
135 "work-dir-path", llvm::cl::Optional,
136 llvm::cl::desc(
"Absolute path to working directory"));
138 static llvm::cl::opt<bool> bigEndian(
"big-endian", llvm::cl::init(
false),
139 llvm::cl::desc(
"Endianness"));
141 static llvm::cl::opt<bool> cdoUnified(
142 "cdo-unified", llvm::cl::init(
false),
143 llvm::cl::desc(
"Emit unified CDO bin (or separate bins)"));
144 static llvm::cl::opt<bool> cdoDebug(
"cdo-debug", llvm::cl::init(
false),
145 llvm::cl::desc(
"Emit cdo debug info"));
146 static llvm::cl::opt<bool> cdoAieSim(
147 "cdo-aiesim", llvm::cl::init(
false),
148 llvm::cl::desc(
"AIESIM target cdo generation"));
149 static llvm::cl::opt<bool> cdoXaieDebug(
150 "cdo-xaie-debug", llvm::cl::init(
false),
151 llvm::cl::desc(
"Emit libxaie debug info"));
152 static llvm::cl::opt<size_t> cdoEnableCores(
153 "cdo-enable-cores", llvm::cl::init(
true),
154 llvm::cl::desc(
"Enable cores in CDO"));
156 static llvm::cl::opt<bool> outputBinary(
157 "aie-output-binary", llvm::cl::init(
true),
159 "Select binary (true) or text (false) output for supported "
160 "translations. e.g. aie-npu-to-binary, aie-ctrlpkt-to-bin"));
161 static llvm::cl::opt<std::string> deviceName(
162 "aie-device-name", llvm::cl::init(
""),
163 llvm::cl::desc(
"Specify which device to translate"));
164 static llvm::cl::opt<std::string> sequenceName(
165 "aie-sequence-name", llvm::cl::init(
""),
167 "Specify the name of the aiex.runtime_sequence to translate"));
169 TranslateFromMLIRRegistration registrationMMap(
170 "aie-generate-mmap",
"Generate AIE memory map",
171 [](ModuleOp module, raw_ostream &output) {
172 DenseMap<TileID, Operation *> tiles;
173 DenseMap<Operation *, SmallVector<BufferOp, 4>> buffers;
176 AIE::DeviceOp::getForSymbolInModule(module, deviceName);
178 module.emitOpError("expected AIE.device operation at toplevel");
183 using tileType = std::pair<TileID, Operation *>;
185 bool operator()(
const tileType &lhs,
const tileType &rhs)
const {
186 return lhs.first < rhs.first;
189 std::set<tileType, tileCmp> sortedTiles;
190 for (
auto tile : tiles)
191 sortedTiles.insert(tileType{tile.first, tile.second});
195 for (
auto tile : sortedTiles) {
196 Operation *srcTileOp = tile.second;
197 TileID srcCoord = cast<TileOp>(srcTileOp).getTileID();
198 int srcCol = srcCoord.col;
199 int srcRow = srcCoord.row;
201 output <<
"// Tile(" << srcCol <<
", " << srcRow <<
")\n";
202 output <<
"// Memory map: name base_address num_bytes\n";
204 auto doBuffer = [&](std::optional<TileID> tile,
int offset) {
205 if (tiles.count(*tile))
206 for (
auto buf : buffers[tiles[*tile]])
212 if (
auto tile = targetModel.getMemSouth(srcCoord))
213 doBuffer(tile, targetModel.getMemSouthBaseAddress());
214 if (
auto tile = targetModel.getMemWest(srcCoord))
215 doBuffer(tile, targetModel.getMemWestBaseAddress());
216 if (
auto tile = targetModel.getMemNorth(srcCoord))
217 doBuffer(tile, targetModel.getMemNorthBaseAddress());
218 if (
auto tile = targetModel.getMemEast(srcCoord))
219 doBuffer(tile, targetModel.getMemEastBaseAddress());
225 TranslateFromMLIRRegistration registrationShimDMAToJSON(
226 "aie-generate-json",
"Transform AIE shim DMA allocation info into JSON",
227 [](ModuleOp module, raw_ostream &output) {
229 AIE::DeviceOp::getForSymbolInModuleOrError(module, deviceName);
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 AIE::TileOp tile = shimDMAMeta.getTileOp();
242 shimDMAMeta.emitError(
243 "shim DMA allocation must reference a valid TileOp");
246 auto col = tile.getColAttr();
248 moduleJSON[shimDMAMeta.getSymName()] =
249 llvm::json::Value(std::move(shimJSON));
251 llvm::json::Value topv(std::move(moduleJSON));
253 llvm::raw_string_ostream ss(ret);
254 ss << llvm::formatv(
"{0:2}", topv) <<
"\n";
260 TranslateFromMLIRRegistration registrationLDScript(
261 "aie-generate-ldscript",
"Generate AIE loader script",
262 [](ModuleOp module, raw_ostream &output) {
268 TranslateFromMLIRRegistration registrationBCF(
269 "aie-generate-bcf",
"Generate AIE bcf",
270 [](ModuleOp module, raw_ostream &output) {
275 TranslateFromMLIRRegistration registrationTargetArch(
276 "aie-generate-target-arch",
"Get the target architecture",
277 [](ModuleOp module, raw_ostream &output) {
282 TranslateFromMLIRRegistration registrationCoreList(
283 "aie-generate-corelist",
"Generate python list of cores",
284 [](ModuleOp module, raw_ostream &output) {
286 AIE::DeviceOp::getForSymbolInModule(module, deviceName);
288 module.emitOpError("expected AIE.device operation at toplevel");
293 for (
auto tileOp : targetOp.getOps<TileOp>()) {
294 int col = tileOp.colIndex();
295 int row = tileOp.rowIndex();
296 if (
auto coreOp = tileOp.getCoreOp()) {
297 std::string elfFile =
"None";
298 if (
auto fileAttr = coreOp.getElfFile())
299 elfFile =
"\"" + fileAttr.value().str() +
"\"";
300 output <<
'(' <<
col <<
',' <<
row <<
',' << elfFile <<
"),";
308 TranslateFromMLIRRegistration registrationXADF(
309 "adf-generate-cpp-graph",
"Translate ADFDialect to C++ graph",
311 registry.insert<xilinx::ADF::ADFDialect>();
312 registerDialects(registry);
314 TranslateFromMLIRRegistration registrationXAIE(
315 "aie-generate-xaie",
"Generate libxaie configuration",
316 [](ModuleOp module, raw_ostream &output) {
320 TranslateFromMLIRRegistration registrationHSA(
321 "aie-generate-hsa",
"Generate hsa data movement configuration",
322 [](ModuleOp module, raw_ostream &output) {
326 TranslateFromMLIRRegistration registrationXJSON(
327 "aie-flows-to-json",
"Translate AIE flows to JSON",
328 [](ModuleOp module, raw_ostream &output) {
332 TranslateFromMLIRRegistration registrationXPE(
333 "aie-mlir-to-xpe",
"Translate AIE design to XPE file for simulation",
334 [](ModuleOp module, raw_ostream &output) {
338 TranslateFromMLIRRegistration registrationSCSimConfig(
339 "aie-mlir-to-scsim-config",
340 "Translate AIE design to SCSimConfig file for simulation",
341 [](ModuleOp module, raw_ostream &output) {
345 TranslateFromMLIRRegistration registrationShimSolution(
346 "aie-mlir-to-shim-solution",
347 "Translate AIE design to ShimSolution file for simulation",
348 [](ModuleOp module, raw_ostream &output) {
352 TranslateFromMLIRRegistration registrationCDODirect(
353 "aie-generate-cdo",
"Generate libxaie for CDO directly",
354 [](ModuleOp module, raw_ostream &) {
355 SmallString<128> workDirPath_;
356 if (workDirPath.getNumOccurrences() == 0) {
357 if (llvm::sys::fs::current_path(workDirPath_))
358 llvm::report_fatal_error(
359 "couldn't get cwd to use as work-dir-path");
361 workDirPath_ = workDirPath.getValue();
362 LLVM_DEBUG(llvm::dbgs() <<
"work-dir-path: " << workDirPath_ <<
"\n");
364 bigEndian, cdoUnified, cdoDebug,
365 cdoAieSim, cdoXaieDebug, cdoEnableCores);
368 TranslateFromMLIRRegistration registrationNPU(
369 "aie-npu-to-binary",
"Translate npu instructions to binary",
370 [](ModuleOp module, raw_ostream &output) {
371 std::vector<uint32_t> instructions;
377 output.write(
reinterpret_cast<const char *
>(instructions.data()),
378 instructions.size() *
sizeof(uint32_t));
380 for (
auto w : instructions)
381 output <<
llvm::format(
"%08X\n", w);
386 TranslateFromMLIRRegistration registrationCtrlPkt(
387 "aie-ctrlpkt-to-bin",
"Translate aiex.control_packet ops to binary",
388 [](ModuleOp module, raw_ostream &output) {
389 std::vector<uint32_t> instructions;
391 deviceName, sequenceName);
395 output.write(
reinterpret_cast<const char *
>(instructions.data()),
396 instructions.size() *
sizeof(uint32_t));
398 for (
auto w : instructions)
399 output <<
llvm::format(
"%08X\n", w);
406 TranslateFromMLIRRegistration registrationCertToAsm(
407 "aie-cert-to-asm",
"Translate cert operations to assembly",
408 [](ModuleOp module, raw_ostream &output) {