Skip to content

Commit

Permalink
Output better error messages for file opening errors instead of fatal…
Browse files Browse the repository at this point in the history
… errors by assertion. (llvm#968)

* Conversion support (llvm#956)

* initial

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* works, bool is great, but unsigned create issues

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* added support to remove the UnrealizedConversionCastOp while lowering to llvm

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* last version to support some shaped type in conversion, reduce after to Integer or Float

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* converted to cast scalar only

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* added lit tests

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* initial

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* works, bool is great, but unsigned create issues

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* added support to remove the UnrealizedConversionCastOp while lowering to llvm

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* last version to support some shaped type in conversion, reduce after to Integer or Float

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* converted to cast scalar only

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* added lit tests

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* implemented cast with index, before replacing usage

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* cleanup and use of createMath constant/constantIndex/cast/castIndex

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* make sure that only explicitly unsigned are treated as unsigned; signless and indices are treated as signed

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Add the onnx-mlir logo to the onnxai webpage (llvm#959)

* Add the onnx-mlir logo to the onnxai webpage

Signed-off-by: Tung D. Le <tung@jp.ibm.com>

* Remove a dump()

Signed-off-by: Tung D. Le <tung@jp.ibm.com>

* Missing git-add the .png file

Signed-off-by: Tung D. Le <tung@jp.ibm.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Several small improvements including adding onnx-mlir-doc to ALL target and building onnx from the submodule (llvm#957)

1. Add onnx-mlir-doc to the ALL target. This way it will be run with the default target
2. On Windows instead of installing onnx from pip, build it from source to match other CIs
3. Remove unnecessary include in Compiler

Signed-off-by: Stella Stamenova <stilis@microsoft.com>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* fix the mistake of shape in doc-example (llvm#964)

Signed-off-by: david.cheng <david.cheng@enflame-tech.com>

Co-authored-by: david.cheng <david.cheng@enflame-tech.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* install dll to bin (llvm#963)

Signed-off-by: Michael Holman <michhol@microsoft.com>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Output better error messages for file opening errors.

Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Fix clang-format errors

Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Fix build errors.

Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Fix a build error

Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Onehot update (llvm#967)

* initial commit

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* one hot upgraded, more dyn cases

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* cleanup

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* cleanup

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* initial commit

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* one hot upgraded, more dyn cases

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* cleanup

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* cleanup

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* We currently run a few test sets, e.g., check-onnx-backend, (llvm#958)

check-onnx-backend-dynamic, etc., in serial. While we do
parallelize within each test set, we don't get much benefit
from it. Because within each test set, most of the time was
spent on one or two long running tests. While waiting for
these long running tests, we could have started the other
test sets.

This patch parallelizes across tests sets by starting them
all at once so the long running tests from different test
sets can run in parallel.

CompilerLib tests are disabled because a bug has been uncovered
that it was actually still using onnx-mlir instead of CompilerLibTest
to compile the models. Fix the bug to use CompilerLibTest and
it fails to compile the models.

Use CTEST_PARALLEL_LEVEL for numerical tests to be compatible
with Windows CI

Signed-off-by: Gong Su <gong_su@hotmail.com>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Use ninja as a build system (llvm#946)

Signed-off-by: mshr-h <mhg00g13@gmail.com>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Added documentation on using DEBUG according to LLVM (llvm#970)

* added documentation on using DEBUG according to LLVM

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* removed errand printf for debugging

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* CategoryMapper: shape inference support. (llvm#971)

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Updating docs to move into the right place (llvm#972)

* Updating docs to move into the right place

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* add link

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* add links

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* add links

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* respond to comments on MLIR.cmake

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Fix EnableMemoryPool to account for 'memref.cast' operation. (llvm#966)

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>
Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Fix typo.

Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Revert "Fix typo."

This reverts commit f2934faee463557ebc2adb6aca5b9521f5064f12.

Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

* Fix typo

Signed-off-by: Yasushi Negishi <negishi@jp.ibm.com>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Co-authored-by: Tung D. Le <tung@jp.ibm.com>
Co-authored-by: Stella Stamenova <stilis@microsoft.com>
Co-authored-by: DavidChan <chengwei0519@163.com>
Co-authored-by: david.cheng <david.cheng@enflame-tech.com>
Co-authored-by: Michael Holman <michhol@microsoft.com>
Co-authored-by: gongsu832 <gong_su@hotmail.com>
Co-authored-by: Masahiro Hiramori <mhg00g13@gmail.com>
Co-authored-by: Ettore Tiotto <etiotto@ca.ibm.com>
  • Loading branch information
10 people committed Nov 4, 2021
1 parent f79edff commit 7f7edf7
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/OnnxMlirCompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace onnx_mlir {
*/
ONNX_MLIR_EXPORT int omCompileFromFile(const char *inputFilename,
const char *outputBaseName, EmissionTargetType emissionTarget,
const char *mcpu, const char *mtriple);
const char *mcpu, const char *mtriple, const char **errorMessage);

/*!
* Compile an onnx model from an ONNX protobuf array
Expand Down
7 changes: 5 additions & 2 deletions src/Builder/FrontendDialectTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,12 +1394,15 @@ void ImportFrontendModelArray(const void *onnxBuffer, int size,
}

void ImportFrontendModelFile(std::string model_fname, MLIRContext &context,
OwningModuleRef &module, ImportOptions options) {
OwningModuleRef &module, std::string *errorMessage, ImportOptions options) {
onnx::ModelProto model;
std::fstream input(model_fname, std::ios::in | std::ios::binary);

auto parse_success = model.ParseFromIstream(&input);
assert(parse_success && "Onnx Model Parsing Failed.");
if (!parse_success) {
*errorMessage = "Onnx Model Parsing Failed on " + model_fname;
return;
}
ImportFrontendModelInternal(model, context, module, options);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Builder/FrontendDialectTransformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void ImportFrontendModelArray(const void *onnxBuffer, int bufferSize,
*/
void ImportFrontendModelFile(std::string model_fname,
mlir::MLIRContext &context, mlir::OwningModuleRef &module,
ImportOptions options = ImportOptions());
std::string *errorMessage, ImportOptions options = ImportOptions());

/*!
* Import an ONNX model proto into the ONNX Dialect.
Expand Down
12 changes: 8 additions & 4 deletions src/Compiler/CompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,21 +542,25 @@ void addKrnlToLLVMPasses(mlir::OpPassManager &pm) {
}

void processInputFile(string inputFilename, mlir::MLIRContext &context,
mlir::OwningModuleRef &module) {
mlir::OwningModuleRef &module, std::string *errorMessage) {
// Decide if the input file is an ONNX model or a model specified
// in MLIR. The extension of the file is the decider.
string extension = inputFilename.substr(inputFilename.find_last_of(".") + 1);
bool inputIsONNX = (extension == "onnx");
bool inputIsMLIR = (extension == "mlir");
assert(inputIsONNX != inputIsMLIR &&
"Either ONNX model or MLIR file needs to be provided.");
if (inputIsONNX == inputIsMLIR) {
*errorMessage = "Invaid input file '" + inputFilename +
"': Either ONNX model or MLIR file needs to be provided.";
return;
}

if (inputIsONNX) {
ImportOptions options;
options.useOnnxModelTypes = useOnnxModelTypes;
options.invokeOnnxVersionConverter = invokeOnnxVersionConverter;
options.shapeInformation = shapeInformation;
ImportFrontendModelFile(inputFilename, context, module, options);
ImportFrontendModelFile(
inputFilename, context, module, errorMessage, options);
} else {
LoadMLIR(inputFilename, context, module);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/CompilerUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void addKrnlToAffinePasses(mlir::PassManager &pm);
void addKrnlToLLVMPasses(mlir::OpPassManager &pm);

void processInputFile(std::string inputFilename, mlir::MLIRContext &context,
mlir::OwningModuleRef &module);
mlir::OwningModuleRef &module, std::string *errorMessage);

void processInputArray(const void *onnxBuffer, int bufferSize,
mlir::MLIRContext &context, mlir::OwningModuleRef &module);
Expand Down
9 changes: 7 additions & 2 deletions src/Compiler/OnnxMlirCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ extern "C" {
namespace onnx_mlir {
ONNX_MLIR_EXPORT int omCompileFromFile(const char *inputFilename,
const char *outputBaseName, EmissionTargetType emissionTarget,
const char *mcpu, const char *mtriple) {
const char *mcpu, const char *mtriple, const char **errorMessage) {
mlir::OwningModuleRef module;
mlir::MLIRContext context;

setCompileContext(context, mcpu, mtriple);
processInputFile(std::string(inputFilename), context, module);
std::string error_message;
processInputFile(std::string(inputFilename), context, module, &error_message);
if (errorMessage != NULL) {
*errorMessage = error_message.c_str();
return 1;
}
return compileModule(module, context, outputBaseName, emissionTarget);
}

Expand Down
7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ int main(int argc, char *argv[]) {
argc, argv, "ONNX MLIR modular optimizer driver\n");

mlir::OwningModuleRef module;
processInputFile(inputFilename, context, module);
std::string errorMessage;
processInputFile(inputFilename, context, module, &errorMessage);
if (!errorMessage.empty()) {
printf("%s\n", errorMessage.c_str());
return 1;
}

// Input file base name, replace path if required.
// outputBaseName must specify a file, so ignore invalid values
Expand Down
7 changes: 6 additions & 1 deletion test/compilerlib/CompilerLibTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ int main(int argc, char *argv[]) {
}
int retVal = 0;
if (compileFromFile) {
const char *errorMessage = NULL;
retVal = omCompileFromFile(testFileName.c_str(), outputBaseName.c_str(),
onnx_mlir::EmitLib, mcpu.empty() ? nullptr : mcpu.c_str(),
mtriple.empty() ? nullptr : mtriple.c_str());
mtriple.empty() ? nullptr : mtriple.c_str(), &errorMessage);
if (errorMessage != NULL) {
std::cerr << errorMessage;
retVal = 0xf;
}
} else {
std::ifstream inFile(
testFileName, std::ios_base::in | std::ios_base::binary);
Expand Down

0 comments on commit 7f7edf7

Please sign in to comment.