Refactor PIM/Common (splitting in files, adding helpers, adding brief
Validate Operations / validate-operations (push) Failing after 18m36s
Validate Operations / validate-operations (push) Failing after 18m36s
docs)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#include "llvm/Support/raw_os_ostream.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "src/Accelerators/PIM/Common/Support/DebugDump.hpp"
|
||||
#include "src/Accelerators/PIM/Common/Support/FileSystemUtils.hpp"
|
||||
|
||||
namespace onnx_mlir {
|
||||
|
||||
void dumpModule(mlir::ModuleOp moduleOp, const std::string& name) {
|
||||
std::string outputDir = getOutputDir();
|
||||
if (outputDir.empty())
|
||||
return;
|
||||
|
||||
std::string dialectsDir = outputDir + "/dialects";
|
||||
createDirectory(dialectsDir);
|
||||
|
||||
std::fstream file(dialectsDir + "/" + name + ".mlir", std::ios::out);
|
||||
llvm::raw_os_ostream os(file);
|
||||
mlir::OpPrintingFlags flags;
|
||||
flags.elideLargeElementsAttrs();
|
||||
moduleOp.print(os, flags);
|
||||
os.flush();
|
||||
file.close();
|
||||
}
|
||||
|
||||
} // namespace onnx_mlir
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "mlir/IR/BuiltinOps.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace onnx_mlir {
|
||||
|
||||
/// Emits a MLIR snapshot under the current compiler output
|
||||
/// directory for pass-level debugging.
|
||||
void dumpModule(mlir::ModuleOp moduleOp, const std::string& name);
|
||||
|
||||
} // namespace onnx_mlir
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
|
||||
#include "src/Accelerators/PIM/Common/Support/Diagnostics.hpp"
|
||||
|
||||
namespace onnx_mlir::pim {
|
||||
|
||||
mlir::InFlightDiagnostic emitUnsupportedStaticShapeDiagnostic(mlir::Operation* op, llvm::StringRef valueDescription) {
|
||||
return op->emitOpError() << "requires statically shaped " << valueDescription;
|
||||
}
|
||||
|
||||
mlir::InFlightDiagnostic emitUnsupportedRankDiagnostic(mlir::Operation* op,
|
||||
llvm::StringRef valueDescription,
|
||||
int64_t actualRank,
|
||||
llvm::ArrayRef<int64_t> supportedRanks) {
|
||||
auto diag = op->emitOpError() << "has unsupported rank " << actualRank << " for " << valueDescription;
|
||||
if (supportedRanks.empty())
|
||||
return diag;
|
||||
|
||||
diag << "; supported rank";
|
||||
if (supportedRanks.size() != 1)
|
||||
diag << 's';
|
||||
diag << ' ';
|
||||
|
||||
llvm::interleaveComma(supportedRanks, diag, [&](int64_t rank) { diag << rank; });
|
||||
return diag;
|
||||
}
|
||||
|
||||
mlir::InFlightDiagnostic
|
||||
emitMissingSymbolDiagnostic(mlir::Operation* op, llvm::StringRef symbolKind, llvm::StringRef symbolName) {
|
||||
return op->emitOpError() << "references missing " << symbolKind << " `" << symbolName << "`";
|
||||
}
|
||||
|
||||
mlir::LogicalResult emitFileSystemError(mlir::Location loc,
|
||||
llvm::StringRef action,
|
||||
llvm::StringRef path,
|
||||
const std::error_code& errorCode) {
|
||||
mlir::emitError(loc) << "failed to " << action << " `" << path << "`: " << errorCode.message();
|
||||
return mlir::failure();
|
||||
}
|
||||
|
||||
} // namespace onnx_mlir::pim
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "mlir/IR/Diagnostics.h"
|
||||
#include "mlir/IR/Operation.h"
|
||||
#include "mlir/Support/LogicalResult.h"
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
#include <system_error>
|
||||
|
||||
namespace onnx_mlir::pim {
|
||||
|
||||
/// Emits a consistent diagnostic for target paths that require static shapes.
|
||||
mlir::InFlightDiagnostic emitUnsupportedStaticShapeDiagnostic(mlir::Operation* op, llvm::StringRef valueDescription);
|
||||
|
||||
/// Emits a consistent diagnostic for unsupported ranks while listing the ranks
|
||||
/// accepted by the current lowering/codegen path.
|
||||
mlir::InFlightDiagnostic emitUnsupportedRankDiagnostic(mlir::Operation* op,
|
||||
llvm::StringRef valueDescription,
|
||||
int64_t actualRank,
|
||||
llvm::ArrayRef<int64_t> supportedRanks);
|
||||
|
||||
/// Emits a consistent diagnostic for missing symbol/global references.
|
||||
mlir::InFlightDiagnostic
|
||||
emitMissingSymbolDiagnostic(mlir::Operation* op, llvm::StringRef symbolKind, llvm::StringRef symbolName);
|
||||
|
||||
/// Converts a filesystem error into an MLIR failure diagnostic anchored at
|
||||
/// the relevant IR location.
|
||||
mlir::LogicalResult
|
||||
emitFileSystemError(mlir::Location loc, llvm::StringRef action, llvm::StringRef path, const std::error_code& errorCode);
|
||||
|
||||
template <typename T>
|
||||
mlir::LogicalResult failureOrToLogicalResult(const llvm::FailureOr<T>& value) {
|
||||
return mlir::success(succeeded(value));
|
||||
}
|
||||
|
||||
} // namespace onnx_mlir::pim
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <filesystem>
|
||||
|
||||
#include "src/Accelerators/PIM/Common/Support/FileSystemUtils.hpp"
|
||||
#include "src/Compiler/CompilerOptions.hpp"
|
||||
|
||||
namespace onnx_mlir {
|
||||
|
||||
std::string getOutputDir() {
|
||||
if (outputBaseName.empty() || outputBaseName == "-")
|
||||
return {};
|
||||
|
||||
size_t lastSlash = outputBaseName.find_last_of('/');
|
||||
if (lastSlash == std::string::npos)
|
||||
return ".";
|
||||
return outputBaseName.substr(0, lastSlash);
|
||||
}
|
||||
|
||||
void createDirectory(const std::string& directory) {
|
||||
std::error_code errorCode;
|
||||
std::filesystem::create_directories(directory, errorCode);
|
||||
assert(!errorCode && ("Failed to create directory: " + errorCode.message()).data());
|
||||
}
|
||||
|
||||
} // namespace onnx_mlir
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace onnx_mlir {
|
||||
|
||||
/// Returns the directory that should hold PIM artifacts/debug dumps for the
|
||||
/// current compiler invocation.
|
||||
std::string getOutputDir();
|
||||
|
||||
void createDirectory(const std::string& directory);
|
||||
|
||||
} // namespace onnx_mlir
|
||||
Reference in New Issue
Block a user