Skip to content

Commit fe93e12

Browse files
committed
[XCLBinGen] Fix chess core elf generation
1 parent e16dd26 commit fe93e12

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/XCLBinGen.cpp

+36-36
Original file line numberDiff line numberDiff line change
@@ -603,45 +603,46 @@ static LogicalResult generateCoreElfFiles(
603603
chessArgs.emplace_back("-o");
604604
chessArgs.emplace_back(elfFile.string());
605605
std::vector<std::string> env = makeChessEnv(*vitisDir, npuVersion);
606-
return runTool(xChessCCExe, chessArgs, verbose, env);
607-
}
606+
if (failed(runTool(xChessCCExe, chessArgs, verbose, env))) {
607+
return deviceOp.emitOpError() << "failed to generate elf for core: ("
608+
<< col << ", " << row << ")";
609+
}
610+
} else {
611+
Path ldscriptPath = tempDir / (elfFileName + ".ld");
612+
{
613+
auto ldscriptOutput =
614+
openOutputFile(ldscriptPath.string(), &errorMessage);
615+
if (!ldscriptOutput) {
616+
llvm::errs() << "Failed to open ldscript file because: "
617+
<< errorMessage;
618+
return failure();
619+
}
620+
if (failed(mlir::iree_compiler::AMDAIE::AIETranslateToLdScript(
621+
deviceOp, ldscriptOutput->os(), col, row))) {
622+
return failure();
623+
}
624+
ldscriptOutput->keep();
625+
}
608626

609-
Path ldscriptPath = tempDir / (elfFileName + ".ld");
610-
{
611-
auto ldscriptOutput =
612-
openOutputFile(ldscriptPath.string(), &errorMessage);
613-
if (!ldscriptOutput) {
614-
llvm::errs() << "Failed to open ldscript file because: "
615-
<< errorMessage;
616-
return failure();
627+
std::string targetLower = StringRef(targetArch).lower();
628+
std::vector<std::string> flags;
629+
flags.emplace_back(objFile);
630+
if (ukernel && (ukernel == "mm" || ukernel == "all")) {
631+
flags.emplace_back(mmObjectFilePath->string());
617632
}
618-
if (failed(mlir::iree_compiler::AMDAIE::AIETranslateToLdScript(
619-
deviceOp, ldscriptOutput->os(), col, row))) {
620-
llvm::errs() << "failed to generate ld script for core (" << col << ","
621-
<< row << ")\n";
633+
flags.emplace_back("--target=" + targetLower + "-none-unknown-elf");
634+
flags.emplace_back("-Wl,--gc-sections");
635+
flags.emplace_back("-Wl,--orphan-handling=error");
636+
flags.emplace_back("-Wl,-T," + ldscriptPath.string());
637+
flags.emplace_back("-o");
638+
flags.emplace_back(elfFile.string());
639+
if (verbose) flags.emplace_back("-v");
640+
// we run clang (ie cc) so that libc, libm, crt0/1 paths are injected
641+
// automatically into the ld.lld invocation
642+
if (failed(
643+
runTool((peanoDir / "bin" / "clang").string(), flags, verbose))) {
622644
return failure();
623645
}
624-
ldscriptOutput->keep();
625-
}
626-
627-
std::string targetLower = StringRef(targetArch).lower();
628-
std::vector<std::string> flags;
629-
flags.emplace_back(objFile);
630-
if (ukernel && (ukernel == "mm" || ukernel == "all")) {
631-
flags.emplace_back(mmObjectFilePath->string());
632-
}
633-
flags.emplace_back("--target=" + targetLower + "-none-unknown-elf");
634-
flags.emplace_back("-Wl,--gc-sections");
635-
flags.emplace_back("-Wl,--orphan-handling=error");
636-
flags.emplace_back("-Wl,-T," + ldscriptPath.string());
637-
flags.emplace_back("-o");
638-
flags.emplace_back(elfFile.string());
639-
if (verbose) flags.emplace_back("-v");
640-
// we run clang (ie cc) so that libc, libm, crt0/1 paths are injected
641-
// automatically into the ld.lld invocation
642-
if (failed(
643-
runTool((peanoDir / "bin" / "clang").string(), flags, verbose))) {
644-
return failure();
645646
}
646647
}
647648
return success();
@@ -1149,7 +1150,6 @@ LogicalResult aie2xclbin(
11491150
const std::string &xclBinInstanceName, const std::string &amdAIEInstallDir,
11501151
const std::optional<std::string> &InputXCLBin,
11511152
const std::optional<std::string> &ukernel) {
1152-
11531153
FailureOr<ArrayRef<uint32_t>> maybeNpuInstructions =
11541154
getNpuInstructions(deviceOp);
11551155
if (failed(maybeNpuInstructions)) {

0 commit comments

Comments
 (0)