Skip to content

Commit

Permalink
[XCLBinGen] Fix chess core elf generation (#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtuyls authored Aug 30, 2024
1 parent e16dd26 commit cc68d51
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 36 deletions.
12 changes: 12 additions & 0 deletions build_tools/ci/run_matmul_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,18 @@ if [ -d "$VITIS" ]; then
--num_repeat_runs "10" \
--use_ukernel "1"

run_matmul_test \
--name_prefix "chess_i32_matmul_multi_core" \
--lower_to_aie_pipeline "objectFifo" \
--tile_pipeline "pack-peel" \
--lhs_rhs_type "i32" \
--acc_type "i32" \
--m "32" \
--n "32" \
--k "32" \
--use_chess "1" \
--num_repeat_runs "10"

fi

echo "\n\n"
Expand Down
72 changes: 36 additions & 36 deletions compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/XCLBinGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,45 +603,46 @@ static LogicalResult generateCoreElfFiles(
chessArgs.emplace_back("-o");
chessArgs.emplace_back(elfFile.string());
std::vector<std::string> env = makeChessEnv(*vitisDir, npuVersion);
return runTool(xChessCCExe, chessArgs, verbose, env);
}
if (failed(runTool(xChessCCExe, chessArgs, verbose, env))) {
return deviceOp.emitOpError() << "failed to generate elf for core: ("
<< col << ", " << row << ")";
}
} else {
Path ldscriptPath = tempDir / (elfFileName + ".ld");
{
auto ldscriptOutput =
openOutputFile(ldscriptPath.string(), &errorMessage);
if (!ldscriptOutput) {
llvm::errs() << "Failed to open ldscript file because: "
<< errorMessage;
return failure();
}
if (failed(mlir::iree_compiler::AMDAIE::AIETranslateToLdScript(
deviceOp, ldscriptOutput->os(), col, row))) {
return failure();
}
ldscriptOutput->keep();
}

Path ldscriptPath = tempDir / (elfFileName + ".ld");
{
auto ldscriptOutput =
openOutputFile(ldscriptPath.string(), &errorMessage);
if (!ldscriptOutput) {
llvm::errs() << "Failed to open ldscript file because: "
<< errorMessage;
return failure();
std::string targetLower = StringRef(targetArch).lower();
std::vector<std::string> flags;
flags.emplace_back(objFile);
if (ukernel && (ukernel == "mm" || ukernel == "all")) {
flags.emplace_back(mmObjectFilePath->string());
}
if (failed(mlir::iree_compiler::AMDAIE::AIETranslateToLdScript(
deviceOp, ldscriptOutput->os(), col, row))) {
llvm::errs() << "failed to generate ld script for core (" << col << ","
<< row << ")\n";
flags.emplace_back("--target=" + targetLower + "-none-unknown-elf");
flags.emplace_back("-Wl,--gc-sections");
flags.emplace_back("-Wl,--orphan-handling=error");
flags.emplace_back("-Wl,-T," + ldscriptPath.string());
flags.emplace_back("-o");
flags.emplace_back(elfFile.string());
if (verbose) flags.emplace_back("-v");
// we run clang (ie cc) so that libc, libm, crt0/1 paths are injected
// automatically into the ld.lld invocation
if (failed(
runTool((peanoDir / "bin" / "clang").string(), flags, verbose))) {
return failure();
}
ldscriptOutput->keep();
}

std::string targetLower = StringRef(targetArch).lower();
std::vector<std::string> flags;
flags.emplace_back(objFile);
if (ukernel && (ukernel == "mm" || ukernel == "all")) {
flags.emplace_back(mmObjectFilePath->string());
}
flags.emplace_back("--target=" + targetLower + "-none-unknown-elf");
flags.emplace_back("-Wl,--gc-sections");
flags.emplace_back("-Wl,--orphan-handling=error");
flags.emplace_back("-Wl,-T," + ldscriptPath.string());
flags.emplace_back("-o");
flags.emplace_back(elfFile.string());
if (verbose) flags.emplace_back("-v");
// we run clang (ie cc) so that libc, libm, crt0/1 paths are injected
// automatically into the ld.lld invocation
if (failed(
runTool((peanoDir / "bin" / "clang").string(), flags, verbose))) {
return failure();
}
}
return success();
Expand Down Expand Up @@ -1149,7 +1150,6 @@ LogicalResult aie2xclbin(
const std::string &xclBinInstanceName, const std::string &amdAIEInstallDir,
const std::optional<std::string> &InputXCLBin,
const std::optional<std::string> &ukernel) {

FailureOr<ArrayRef<uint32_t>> maybeNpuInstructions =
getNpuInstructions(deviceOp);
if (failed(maybeNpuInstructions)) {
Expand Down

0 comments on commit cc68d51

Please sign in to comment.