115 static llvm::cl::opt<int> tileCol(
116 "tilecol", llvm::cl::desc(
"column coordinate of core to translate"),
118 static llvm::cl::opt<int> tileRow(
119 "tilerow", llvm::cl::desc(
"row coordinate of core to translate"),
122#ifdef AIE_ENABLE_AIRBIN
123 static llvm::cl::opt<std::string> outputFilename(
124 "airbin-output-filepath",
125 llvm::cl::desc(
"Output airbin file path (including filename)"),
126 llvm::cl::value_desc(
"airbin-output-filepath"),
127 llvm::cl::init(
"airbin.elf"));
129 static llvm::cl::opt<std::string> coreFilesDir(
130 "airbin-aux-core-dir-path",
131 llvm::cl::desc(
"Auxiliary core elf files dir path"),
132 llvm::cl::value_desc(
"airbin-aux-core-dir-path"), llvm::cl::init(
"."));
135 static llvm::cl::opt<std::string> workDirPath(
136 "work-dir-path", llvm::cl::Optional,
137 llvm::cl::desc(
"Absolute path to working directory"));
139 static llvm::cl::opt<bool> bigEndian(
"big-endian", llvm::cl::init(
false),
140 llvm::cl::desc(
"Endianness"));
142 static llvm::cl::opt<bool> cdoUnified(
143 "cdo-unified", llvm::cl::init(
false),
144 llvm::cl::desc(
"Emit unified CDO bin (or separate bins)"));
145 static llvm::cl::opt<bool> cdoDebug(
"cdo-debug", llvm::cl::init(
false),
146 llvm::cl::desc(
"Emit cdo debug info"));
147 static llvm::cl::opt<bool> cdoAieSim(
148 "cdo-aiesim", llvm::cl::init(
false),
149 llvm::cl::desc(
"AIESIM target cdo generation"));
150 static llvm::cl::opt<bool> cdoXaieDebug(
151 "cdo-xaie-debug", llvm::cl::init(
false),
152 llvm::cl::desc(
"Emit libxaie debug info"));
153 static llvm::cl::opt<size_t> cdoEnableCores(
154 "cdo-enable-cores", llvm::cl::init(
true),
155 llvm::cl::desc(
"Enable cores in CDO"));
157 static llvm::cl::opt<bool> outputBinary(
158 "aie-output-binary", llvm::cl::init(
true),
160 "Select binary (true) or text (false) output for supported "
161 "translations. e.g. aie-npu-to-binary, aie-ctrlpkt-to-bin"));
163 static llvm::cl::opt<std::string> sequenceName(
164 "aie-sequence-name", llvm::cl::init(
""),
166 "Specify the name of the aiex.runtime_sequence to translate"));
168 TranslateFromMLIRRegistration registrationMMap(
169 "aie-generate-mmap",
"Generate AIE memory map",
170 [](ModuleOp module, raw_ostream &output) {
171 DenseMap<TileID, Operation *> tiles;
172 DenseMap<Operation *, SmallVector<BufferOp, 4>> buffers;
174 if (module.getOps<DeviceOp>().empty()) {
175 module.emitOpError(
"expected AIE.device operation at toplevel");
177 DeviceOp targetOp = *(module.getOps<DeviceOp>().begin());
179 collectTiles(targetOp, tiles);
181 using tileType = std::pair<TileID, Operation *>;
183 bool operator()(
const tileType &lhs,
const tileType &rhs)
const {
184 return lhs.first < rhs.first;
187 std::set<tileType, tileCmp> sortedTiles;
188 for (
auto tile : tiles)
189 sortedTiles.insert(tileType{tile.first, tile.second});
191 collectBuffers(targetOp, buffers);
193 for (
auto tile : sortedTiles) {
194 Operation *srcTileOp = tile.second;
195 TileID srcCoord = cast<TileOp>(srcTileOp).getTileID();
196 int srcCol = srcCoord.col;
197 int srcRow = srcCoord.row;
199 output <<
"// Tile(" << srcCol <<
", " << srcRow <<
")\n";
200 output <<
"// Memory map: name base_address num_bytes\n";
202 auto doBuffer = [&](std::optional<TileID> tile,
int offset) {
203 if (tiles.count(*tile))
204 for (
auto buf : buffers[tiles[*tile]])
210 if (
auto tile = targetModel.getMemSouth(srcCoord))
211 doBuffer(tile, targetModel.getMemSouthBaseAddress());
212 if (
auto tile = targetModel.getMemWest(srcCoord))
213 doBuffer(tile, targetModel.getMemWestBaseAddress());
214 if (
auto tile = targetModel.getMemNorth(srcCoord))
215 doBuffer(tile, targetModel.getMemNorthBaseAddress());
216 if (
auto tile = targetModel.getMemEast(srcCoord))
217 doBuffer(tile, targetModel.getMemEastBaseAddress());
223 TranslateFromMLIRRegistration registrationShimDMAToJSON(
224 "aie-generate-json",
"Transform AIE shim DMA allocation info into JSON",
225 [](ModuleOp module, raw_ostream &output) {
226 for (
auto d : module.getOps<DeviceOp>()) {
227 llvm::json::Object moduleJSON;
228 for (
auto shimDMAMeta : d.getOps<ShimDMAAllocationOp>()) {
229 llvm::json::Object shimJSON;
230 auto channelDir = shimDMAMeta.getChannelDirAttr();
231 shimJSON[
"channelDir"] =
attrToJSON(channelDir);
232 auto channelIndex = shimDMAMeta.getChannelIndexAttr();
233 shimJSON[
"channelIndex"] =
attrToJSON(channelIndex);
234 auto col = shimDMAMeta.getColAttr();
236 moduleJSON[shimDMAMeta.getSymName()] =
237 llvm::json::Value(std::move(shimJSON));
239 llvm::json::Value topv(std::move(moduleJSON));
241 llvm::raw_string_ostream ss(ret);
242 ss << llvm::formatv(
"{0:2}", topv) <<
"\n";
249 TranslateFromMLIRRegistration registrationLDScript(
250 "aie-generate-ldscript",
"Generate AIE loader script",
251 [](ModuleOp module, raw_ostream &output) {
256 TranslateFromMLIRRegistration registrationBCF(
257 "aie-generate-bcf",
"Generate AIE bcf",
258 [](ModuleOp module, raw_ostream &output) {
263 TranslateFromMLIRRegistration registrationTargetArch(
264 "aie-generate-target-arch",
"Get the target architecture",
267 TranslateFromMLIRRegistration registrationCoreList(
268 "aie-generate-corelist",
"Generate python list of cores",
269 [](ModuleOp module, raw_ostream &output) {
270 if (module.getOps<DeviceOp>().empty()) {
271 module.emitOpError(
"expected AIE.device operation at toplevel");
273 DeviceOp targetOp = *(module.getOps<DeviceOp>().begin());
276 for (
auto tileOp : targetOp.getOps<TileOp>()) {
277 int col = tileOp.colIndex();
278 int row = tileOp.rowIndex();
279 if (
auto coreOp = tileOp.getCoreOp()) {
280 std::string elfFile =
"None";
281 if (
auto fileAttr = coreOp.getElfFile())
282 elfFile =
"\"" + fileAttr.value().str() +
"\"";
283 output <<
'(' <<
col <<
',' <<
row <<
',' << elfFile <<
"),";
291 TranslateFromMLIRRegistration registrationXADF(
292 "adf-generate-cpp-graph",
"Translate ADFDialect to C++ graph",
294 registry.insert<xilinx::ADF::ADFDialect>();
295 registerDialects(registry);
297#ifdef AIE_ENABLE_AIRBIN
298 TranslateFromMLIRRegistration registrationAirbin(
299 "aie-generate-airbin",
"Generate configuration binary blob",
300 [](ModuleOp module, raw_ostream &) {
305 TranslateFromMLIRRegistration registrationXAIE(
306 "aie-generate-xaie",
"Generate libxaie configuration",
307 [](ModuleOp module, raw_ostream &output) {
311 TranslateFromMLIRRegistration registrationHSA(
312 "aie-generate-hsa",
"Generate hsa data movement configuration",
313 [](ModuleOp module, raw_ostream &output) {
317 TranslateFromMLIRRegistration registrationXJSON(
318 "aie-flows-to-json",
"Translate AIE flows to JSON",
AIEFlowsToJSON,
320 TranslateFromMLIRRegistration registrationXPE(
321 "aie-mlir-to-xpe",
"Translate AIE design to XPE file for simulation",
323 TranslateFromMLIRRegistration registrationSCSimConfig(
324 "aie-mlir-to-scsim-config",
325 "Translate AIE design to SCSimConfig file for simulation",
327 TranslateFromMLIRRegistration registrationShimSolution(
328 "aie-mlir-to-shim-solution",
329 "Translate AIE design to ShimSolution file for simulation",
331 TranslateFromMLIRRegistration registrationCDODirect(
332 "aie-generate-cdo",
"Generate libxaie for CDO directly",
333 [](ModuleOp module, raw_ostream &) {
334 SmallString<128> workDirPath_;
335 if (workDirPath.getNumOccurrences() == 0) {
336 if (llvm::sys::fs::current_path(workDirPath_))
337 llvm::report_fatal_error(
338 "couldn't get cwd to use as work-dir-path");
340 workDirPath_ = workDirPath.getValue();
341 LLVM_DEBUG(llvm::dbgs() <<
"work-dir-path: " << workDirPath_ <<
"\n");
343 cdoUnified, cdoDebug, cdoAieSim,
344 cdoXaieDebug, cdoEnableCores);
347 TranslateFromMLIRRegistration registrationNPU(
348 "aie-npu-to-binary",
"Translate npu instructions to binary",
349 [](ModuleOp module, raw_ostream &output) {
350 std::vector<uint32_t> instructions;
355 output.write(
reinterpret_cast<const char *
>(instructions.data()),
356 instructions.size() *
sizeof(uint32_t));
358 for (
auto w : instructions)
359 output <<
llvm::format(
"%08X\n", w);
364 TranslateFromMLIRRegistration registrationCtrlPkt(
365 "aie-ctrlpkt-to-bin",
"Translate aiex.control_packet ops to binary",
366 [](ModuleOp module, raw_ostream &output) {
367 std::vector<uint32_t> instructions;
373 output.write(
reinterpret_cast<const char *
>(instructions.data()),
374 instructions.size() *
sizeof(uint32_t));
376 for (
auto w : instructions)
377 output <<
llvm::format(
"%08X\n", w);