diff --git a/lib/Targets/AIETargetCDODirect.cpp b/lib/Targets/AIETargetCDODirect.cpp index be189994e4..79eb4671d8 100644 --- a/lib/Targets/AIETargetCDODirect.cpp +++ b/lib/Targets/AIETargetCDODirect.cpp @@ -711,6 +711,8 @@ void initializeCDOGenerator(byte_ordering endianness, bool cdoDebug) { LogicalResult generateCDOBinary(const StringRef outputPath, const std::function &cb) { + + // TODO(newling): Get bootgen team to remove print statement in this function. startCDOFileStream(outputPath.str().c_str()); FileHeader(); // Never generate a completely empty CDO file. If the file only contains a @@ -775,6 +777,7 @@ LogicalResult AIETranslateToCDODirect(ModuleOp m, llvm::StringRef workDirPath, bool emitUnified, bool cdoDebug, bool aieSim, bool xaieDebug, bool enableCores) { + auto devOps = m.getOps(); assert(llvm::range_size(devOps) == 1 && "only exactly 1 device op supported."); @@ -788,10 +791,16 @@ LogicalResult AIETranslateToCDODirect(ModuleOp m, llvm::StringRef workDirPath, AIEControl ctl(aieSim, xaieDebug, targetModel); initializeCDOGenerator(endianness, cdoDebug); - if (emitUnified) - return generateCDOUnified(ctl, workDirPath, targetOp, aieSim, enableCores); - return generateCDOBinariesSeparately(ctl, workDirPath, targetOp, aieSim, - enableCores); + + auto result = [&]() { + if (emitUnified) { + return generateCDOUnified(ctl, workDirPath, targetOp, aieSim, + enableCores); + } + return generateCDOBinariesSeparately(ctl, workDirPath, targetOp, aieSim, + enableCores); + }(); + return result; } // Not sure why but defining this with xilinx::AIE will create a duplicate // symbol in libAIETargets.a that then doesn't actually match the header? diff --git a/tools/aie2xclbin/XCLBinGen.cpp b/tools/aie2xclbin/XCLBinGen.cpp index ebb0ba214c..9e640812c3 100644 --- a/tools/aie2xclbin/XCLBinGen.cpp +++ b/tools/aie2xclbin/XCLBinGen.cpp @@ -9,6 +9,7 @@ //===---------------------------------------------------------------------===// #include "XCLBinGen.h" +#include #include "aie/Conversion/AIEVecToLLVM/AIEVecToLLVM.h" #include "aie/Dialect/AIE/Transforms/AIEPasses.h" @@ -40,6 +41,7 @@ #include "llvm/Support/Program.h" #include "llvm/Support/ToolOutputFile.h" +#include #include #include #include @@ -212,14 +214,30 @@ int runTool(StringRef Program, ArrayRef Args, bool Verbose, std::optional opt_stats(stats); SmallVector PArgs = {Program}; PArgs.append(Args.begin(), Args.end()); - int result = sys::ExecuteAndWait(Program, PArgs, Env, {}, 0, 0, &err_msg, - nullptr, &opt_stats); - if (Verbose) + + SmallVector tmpPath; + auto ec = llvm::sys::fs::createTemporaryFile("run_tool", "", tmpPath); + if (ec) { + llvm::errs() << "Failed to create temporary file: " << ec.message() << "\n"; + return -1; + } + + // Convert tmpPath to a StringRef: + StringRef tp(tmpPath.begin(), tmpPath.size()); + + int result = sys::ExecuteAndWait(Program, PArgs, Env, {tp, tp, tp}, 0, 0, + &err_msg, nullptr, &opt_stats); + if (Verbose) { llvm::outs() << (result == 0 ? "Succeeded " : "Failed ") << "in " << std::chrono::duration_cast>( stats.TotalTime) .count() << " code: " << result << "\n"; + std::ifstream t(tp.str()); + std::stringstream buffer; + buffer << t.rdbuf(); + llvm::outs() << buffer.str(); + } return result; } @@ -369,13 +387,13 @@ static LogicalResult generateCDO(MLIRContext *context, ModuleOp moduleOp, // compilation in aiecc.py... not sure we need this. PassManager passManager(context, ModuleOp::getOperationName()); applyConfigToPassManager(TK, passManager); - passManager.addNestedPass(AIE::createAIEPathfinderPass()); passManager.addNestedPass( AIEX::createAIEBroadcastPacketPass()); passManager.addNestedPass( AIE::createAIERoutePacketFlowsPass()); passManager.addNestedPass(AIEX::createAIELowerMulticastPass()); + if (failed(passManager.run(copy))) return moduleOp.emitOpError( "failed to run passes to prepare of XCLBin generation"); diff --git a/tools/aie2xclbin/aie2xclbin.cpp b/tools/aie2xclbin/aie2xclbin.cpp index dbd7339aa4..dac737245f 100644 --- a/tools/aie2xclbin/aie2xclbin.cpp +++ b/tools/aie2xclbin/aie2xclbin.cpp @@ -142,6 +142,7 @@ int main(int argc, char *argv[]) { registerPassManagerCLOptions(); registerTranslationCLOptions(); cl::ParseCommandLineOptions(argc, argv); + XCLBinGenConfig TK; TK.Verbose = Verbose; TK.HostArch = HostArch;