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) {
64 startCDOFileStream(outputPath.str().c_str());
72 endCurrentCDOFileStream();
76static LogicalResult generateCDOBinariesSeparately(
AIERTControl &ctl,
77 const StringRef workDirPath,
81 auto ps = std::filesystem::path::preferred_separator;
83 LLVM_DEBUG(llvm::dbgs() <<
"Generating aie_cdo_elfs.bin");
84 if (failed(generateCDOBinary(
85 (llvm::Twine(workDirPath) + std::string(1, ps) +
"aie_cdo_elfs.bin")
87 [&ctl, &targetOp, &workDirPath, &aieSim] {
88 return ctl.
addAieElfs(targetOp, workDirPath, aieSim);
92 LLVM_DEBUG(llvm::dbgs() <<
"Generating aie_cdo_init.bin");
93 if (failed(generateCDOBinary(
94 (llvm::Twine(workDirPath) + std::string(1, ps) +
"aie_cdo_init.bin")
99 LLVM_DEBUG(llvm::dbgs() <<
"Generating aie_cdo_enable.bin");
101 failed(generateCDOBinary(
102 (llvm::Twine(workDirPath) + std::string(1, ps) +
"aie_cdo_enable.bin")
110static LogicalResult generateCDOUnified(
AIERTControl &ctl,
111 const StringRef workDirPath,
112 DeviceOp &targetOp,
bool aieSim,
114 auto ps = std::filesystem::path::preferred_separator;
116 return generateCDOBinary(
117 (llvm::Twine(workDirPath) + std::string(1, ps) +
"aie_cdo.bin").str(),
118 [&ctl, &targetOp, &workDirPath, &aieSim, &enableCores] {
119 if (!targetOp.getOps<CoreOp>().empty() &&
120 failed(ctl.
addAieElfs(targetOp, workDirPath, aieSim)))
124 if (enableCores && !targetOp.getOps<CoreOp>().empty() &&
132translateToCDODirect(ModuleOp m, llvm::StringRef workDirPath,
133 byte_ordering endianness,
bool emitUnified,
bool cdoDebug,
134 bool aieSim,
bool xaieDebug,
bool enableCores) {
136 auto devOps = m.getOps<DeviceOp>();
137 assert(llvm::range_size(devOps) == 1 &&
138 "only exactly 1 device op supported.");
139 DeviceOp targetOp = *devOps.begin();
146 "Only NPU currently supported");
151 initializeCDOGenerator(endianness, cdoDebug);
153 auto result = [&]() {
155 return generateCDOUnified(ctl, workDirPath, targetOp, aieSim,
158 return generateCDOBinariesSeparately(ctl, workDirPath, targetOp, aieSim,
165 ModuleOp m, llvm::StringRef workDirPath,
bool bigEndian,
bool emitUnified,
166 bool cdoDebug,
bool aieSim,
bool xaieDebug,
bool enableCores) {
167 byte_ordering endianness =
168 bigEndian ? byte_ordering::Big_Endian : byte_ordering::Little_Endian;
169 return translateToCDODirect(m, workDirPath, endianness, emitUnified, cdoDebug,
170 aieSim, xaieDebug, enableCores);
bool hasProperty(ModelProperty Prop) const
Include the generated interface declarations.
mlir::LogicalResult AIETranslateToCDODirect(mlir::ModuleOp m, llvm::StringRef workDirPath, bool bigEndian=false, bool emitUnified=false, bool cdoDebug=false, bool aieSim=false, bool xaieDebug=false, bool enableCores=true)
mlir::LogicalResult addAieElfs(DeviceOp &targetOp, const mlir::StringRef workDirPath, bool aieSim)
mlir::LogicalResult setIOBackend(bool aieSim, bool xaieDebug)
mlir::LogicalResult addCoreEnable(DeviceOp &targetOp)
mlir::LogicalResult addInitConfig(DeviceOp &targetOp)