11#include "cdo-driver/cdo_driver.h"
18#include "mlir/IR/Block.h"
19#include "mlir/IR/BuiltinOps.h"
20#include "mlir/IR/Operation.h"
21#include "mlir/Support/LLVM.h"
22#include "mlir/Support/LogicalResult.h"
24#include "llvm/ADT/STLExtras.h"
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/ADT/Twine.h"
27#include "llvm/Support/Debug.h"
41#include "xaiengine/xaie_elfloader.h"
42#include "xaiengine/xaie_interrupt.h"
43#include "xaiengine/xaiegbl.h"
46#define DEBUG_TYPE "aie-generate-cdo"
52static void initializeCDOGenerator(byte_ordering endianness,
bool cdoDebug) {
56 setEndianness(endianness);
60generateCDOBinary(
const StringRef outputPath,
61 const std::function<LogicalResult()> &cb) {
62 startCDOFileStream(outputPath.str().c_str());
70 endCurrentCDOFileStream();
74static LogicalResult generateCDOBinariesSeparately(
AIERTControl &ctl,
75 const StringRef workDirPath,
79 auto ps = std::filesystem::path::preferred_separator;
81 LLVM_DEBUG(llvm::dbgs() <<
"Generating aie_cdo_elfs.bin");
82 if (failed(generateCDOBinary((llvm::Twine(workDirPath) + std::string(1, ps) +
83 targetOp.getSymName() +
"_aie_cdo_elfs.bin")
85 [&ctl, &targetOp, &workDirPath, &aieSim] {
86 return ctl.addAieElfs(targetOp, workDirPath,
91 LLVM_DEBUG(llvm::dbgs() <<
"Generating aie_cdo_init.bin");
92 if (failed(generateCDOBinary(
93 (llvm::Twine(workDirPath) + std::string(1, ps) +
94 targetOp.getSymName() +
"_aie_cdo_init.bin")
96 [&ctl, &targetOp] { return ctl.addInitConfig(targetOp); })))
99 LLVM_DEBUG(llvm::dbgs() <<
"Generating aie_cdo_enable.bin");
101 failed(generateCDOBinary(
102 (llvm::Twine(workDirPath) + std::string(1, ps) +
103 targetOp.getSymName() +
"_aie_cdo_enable.bin")
105 [&ctl, &targetOp] { return ctl.addCoreEnable(targetOp); })))
111static LogicalResult generateCDOUnified(
AIERTControl &ctl,
112 const StringRef workDirPath,
113 DeviceOp &targetOp,
bool aieSim,
115 auto ps = std::filesystem::path::preferred_separator;
117 return generateCDOBinary(
118 (llvm::Twine(workDirPath) + std::string(1, ps) + targetOp.getSymName() +
121 [&ctl, &targetOp, &workDirPath, &aieSim, &enableCores] {
122 if (!targetOp.getOps<CoreOp>().empty() &&
123 failed(ctl.addAieElfs(targetOp, workDirPath, aieSim)))
125 if (failed(ctl.addInitConfig(targetOp)))
127 if (enableCores && !targetOp.getOps<CoreOp>().empty() &&
128 failed(ctl.addCoreEnable(targetOp)))
135translateToCDODirect(ModuleOp m, llvm::StringRef workDirPath,
136 llvm::StringRef deviceName, byte_ordering endianness,
137 bool emitUnified,
bool cdoDebug,
bool aieSim,
138 bool xaieDebug,
bool enableCores) {
140 DeviceOp targetOp = AIE::DeviceOp::getForSymbolInModuleOrError(m, deviceName);
150 "Only NPU currently supported");
155 initializeCDOGenerator(endianness, cdoDebug);
157 auto result = [&]() {
159 return generateCDOUnified(ctl, workDirPath, targetOp, aieSim,
162 return generateCDOBinariesSeparately(ctl, workDirPath, targetOp, aieSim,
169 ModuleOp m, llvm::StringRef workDirPath, llvm::StringRef deviceName,
170 bool bigEndian,
bool emitUnified,
bool cdoDebug,
bool aieSim,
171 bool xaieDebug,
bool enableCores) {
172 byte_ordering endianness =
173 bigEndian ? byte_ordering::Big_Endian : byte_ordering::Little_Endian;
174 return translateToCDODirect(m, workDirPath, deviceName, endianness,
175 emitUnified, cdoDebug, aieSim, xaieDebug,
bool hasProperty(ModelProperty Prop) const
Include the generated interface declarations.
mlir::LogicalResult AIETranslateToCDODirect(mlir::ModuleOp m, llvm::StringRef workDirPath, llvm::StringRef deviceName, bool bigEndian=false, bool emitUnified=false, bool cdoDebug=false, bool aieSim=false, bool xaieDebug=false, bool enableCores=true)
mlir::LogicalResult setIOBackend(bool aieSim, bool xaieDebug)