Skip to content

Commit

Permalink
[Test] Improve error message when no peano path (#1080)
Browse files Browse the repository at this point in the history
The test added in 7fe1354 fails (cryptically) when `PEANO_INSTALL_DIR`
is not set (constructing std::string from nullptr). This PR improves the
diagnostics.

I guess we don't want peano to be in the minimal set of requirements to
run tests, so we should refactor this test to only run if
PEANO_INSTALL_DIR is present (or factorize aie2xlcbin somehow).
  • Loading branch information
newling authored Feb 5, 2025
1 parent 4c43795 commit ed9e895
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1117,12 +1117,14 @@ LogicalResult generateUnifiedObject(
mlir::iree_compiler::AMDAIE::detail::makePeanoOptArgs(
LLVMIRFile, OptLLVMIRFile, additionalPeanoOptFlags);
if (failed(peanoArgs)) {
llvm::errs() << "Failed to make peano opt args";
llvm::errs() << "Failed to make peano opt args\n";
return failure();
}

if (failed(runTool(peanoOptBin.string(), peanoArgs.value(), verbose))) {
llvm::errs() << "Failed to optimize ll with peano";
llvm::errs() << "Failed to optimize ll with peano\n";
llvm::errs() << "Using peano at provided path: '" << peanoDir.string()
<< "'\n";
return failure();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <iostream>
#include <string>

#include "aie/AIEDialect.h"
Expand Down Expand Up @@ -48,9 +47,9 @@ int main(int argc, char **argv) {
llvm::SmallString<128> workDir(argv[2]);
llvm::SmallString<128> artifactPath(workDir);
llvm::sys::path::append(artifactPath, "artifact.pdi");
if (auto ecode = llvm::sys::fs::create_directories(workDir)) {
std::cerr << "Error: failed to create working directory: "
<< ecode.message() << "\n";
if (std::error_code ecode = llvm::sys::fs::create_directories(workDir)) {
llvm::errs() << "Error: failed to create working directory: "
<< ecode.message() << "\n";
return 1;
}

Expand All @@ -69,7 +68,7 @@ int main(int argc, char **argv) {
SmallVector<xilinx::AIE::DeviceOp> deviceOps(
moduleOp.getOps<xilinx::AIE::DeviceOp>());
if (deviceOps.size() != 1) {
std::cerr << "Error: Expected exactly one xilinx.aie.device op\n";
llvm::errs() << "Error: Expected exactly one xilinx.aie.device op\n";
return 1;
}
xilinx::AIE::DeviceOp deviceOp = deviceOps[0];
Expand All @@ -79,7 +78,7 @@ int main(int argc, char **argv) {
std::optional<std::string> npuVersion = deviceModel.getNPUVersionString();
std::optional<std::string> targetArch = deviceModel.getTargetArchString();
if (!npuVersion.has_value() || !targetArch.has_value()) {
std::cerr << "Error: unhandled NPU partitioning.\n";
llvm::errs() << "Error: unhandled NPU partitioning.\n";
return 1;
}

Expand All @@ -90,6 +89,15 @@ int main(int argc, char **argv) {
llvm::setCurrentDebugType("iree-amdaie-ert");
#endif

const char *peanoDir = std::getenv("PEANO_INSTALL_DIR");
if (!peanoDir) {
llvm::errs()
<< "Error: PEANO_INSTALL_DIR environment variable not set. A path to "
"an llvm-aie directory is needed to run aie2xclbin.";
return 1;
}
std::string peanoDirStr = peanoDir;

// Use `aie2xclbin` to generate the elf files.
if (failed(aie2xclbin(
/*ctx=*/&context,
Expand All @@ -107,7 +115,7 @@ int main(int argc, char **argv) {
/*vitisDir=*/std::nullopt,
/*targetArch=*/targetArch.value(),
/*npuVersion=*/npuVersion.value(),
/*peanoDir=*/std::getenv("PEANO_INSTALL_DIR"),
/*peanoDir=*/peanoDirStr,
/*deviceHal=*/AMDAIEOptions::DeviceHAL::XRT_LITE,
/*xclBinKernelID=*/"",
/*xclBinKernelName=*/"",
Expand All @@ -116,7 +124,8 @@ int main(int argc, char **argv) {
/*InputXCLBin=*/std::nullopt,
/*ukernel=*/std::nullopt,
/*additionalPeanoOptFlags=*/""))) {
std::cerr << "Error: failed to generate xclbin\n";
llvm::errs() << "Error: failed to generate xclbin\n";
return 1;
}
return 0;
}

0 comments on commit ed9e895

Please sign in to comment.