From 17383768dff6df052754771eabbcc8264fa43605 Mon Sep 17 00:00:00 2001 From: Kevin O'Brien Date: Wed, 23 Sep 2020 18:58:27 -0400 Subject: [PATCH] Initial Location info support (#302) * NFC: Attribute cleanup (remove references of attributes) (#286) * Define krnl.permute op. * Support krnl.permute operation. * Properly remove loop references. * Re-push, Github was down. * Need to debug interpretOp error. * Fix lowering bug by erasing ops after full krnl IR interpretation is done, and clean up & comment code. * Introduce permute, unroll operations. * More debug. * Remove std::set. * krnl.terminate fails to be converted. * Pass all tests, need to add legal ops as well as part of the conversion target. * Change test format to new permute spec. * Bug fix for nested iterate op lowering. * Simplify error reporting. * Fix compilation error. * Increase comments coverage. * Remove unnecessary imports. * Re-trigger Jenkins * Add permute/unroll tests. * Retrigger Jenkins * remove & (ref) for Attributes Co-authored-by: Tian Jin Signed-off-by: Kevin O'Brien * Syntax highlighting for mlir code in README (#276) * Syntax highlighting for mlir code in README * Restart Jenkins Co-authored-by: Gheorghe-Teodor Bercea Co-authored-by: Alexandre Eichenberger Co-authored-by: Tian Jin Signed-off-by: Kevin O'Brien * use print not dump Signed-off-by: Kevin O'Brien * add semicolon Signed-off-by: Kevin O'Brien * syntax Signed-off-by: Kevin O'Brien * add code to preserve locations Signed-off-by: Kevin O'Brien * format Signed-off-by: Kevin O'Brien * Emit the dynamic memory pool (#290) * Reorganize main function. * Follow review comments. * Emit constants are globals in Krnl and LLVM dialects. * Add support for bundling dynamic memory pools. * Add dynamic bundling. * Clean-up code. * Clean-up file. * Add test for bundling dynamic memory pool. * Fixes. Simplify data structure. Add mixed test. * Remove unused import. Signed-off-by: Kevin O'Brien * Fix wrong type for llvm::loadop (#293) Signed-off-by: Kevin O'Brien * Update llvm commit ID to 1d01fc1 (#292) * Fix for LLVM revision D85495 * Fix for LLVM revision DD86121 * Fix for LLVM revision D85622 (f9dc2b7) TODO: Change preloadDialectsInContext to false Memo for previous fixes: D86121 (250f43d), D85495 (575b22b) * clang-format * Update llvm commit ID of README and clone-mlir.sh * Updated llvm commit ID of README.md * Fix for passing backend tests * Removed the commented code * Empty commit for triggering rebuild * Test multi-stage travis build * Specify stage order. * Empty commit for triggering rebuild * Update prereq.s390x.Dockerfile Make it possible to execute s390x prereq docker multiple times. * Build prereq for each arch * Fix multi-arch prereq build. * timeout at 40m * Update .travis.yml * add ppc64le prereq builder * Run ppc docker prereq build multiple times * Do not test branch update unless it's mater. * Fix dockerfile. * Fix typo in travis.yml. * Fix ppc64 docker file * Update .travis.yml * turn off metacopy on ppc64le * Update .travis.yml * Turn off metacopy. * Turn off metacopy inside Dockerfile in ppc64. * No sudo in Docker. * Remove metacopy config from Dockerfile. * Change base image to be bionic. * Using newer linux distro for ppc64. * Turn off metacopy in before_install. * Fix sudo permission issue. * Run docker info. * Allow amd64 docker file to be built multiple times * Support building amd64 prereq. * Fix amd64 docker file typo. * fix ppc64le dockerfile typo. * timeout from 40m -> 30m * 40m->30m * 40m->30m * fix bug preventing incremental build. * fix bug preventing incremental build. * Bump CircleCI cache version. * Push to production prereq container repository and condition prereq docker rebuild on commit message. * Rebuild prereq docker. * Move default script to top-level. * Python not properly installed. * amd64 -> x86 * Rebuild prereq docker. * Rebuild prereq docker. * Rebuild prereq docker. * Restart all CI. * Disallow cache on Jenkins docker build. * Restart zJenkins. * Restart zJenkins. Co-authored-by: Haruki Imai Co-authored-by: Alexandre Eichenberger Signed-off-by: Kevin O'Brien * Using onnx-mlir through incremental stages (#257) * Add lowering of Vector dialect for lower-all-llvm pass * Fix generating CallOp instructions when return type is void * Fix lowering of memref * Reformat using clang-format * Record more context. * Reflow comments. Co-authored-by: Tian Jin Signed-off-by: Kevin O'Brien * Dropout elimination & Conv Bugfix (#297) * Dropout elimination. * Test VGG19. * Add shufflenet. * Fix grouped convolution bug. * Fix lit test failure. Signed-off-by: Kevin O'Brien * Rewrite shape and size OP (#285) * add shape inference * Revert "add shape inference" This reverts commit f9d42f39e68e14b5648abccfc8617fff00244d16. * add rewrite rules * test cases * format * add constraint * response to review * response to review Signed-off-by: Kevin O'Brien * initial code for handling custom ops (#288) * initial code for handling custom ops * format Signed-off-by: Kevin O'Brien * ShapeInference for SizeOp (#299) * add shape inference * Revert "add shape inference" This reverts commit f9d42f39e68e14b5648abccfc8617fff00244d16. * shape inference * test case * format Signed-off-by: Kevin O'Brien * Gather ONNX to Kernel Lowering (#294) * Define krnl.permute op. * Support krnl.permute operation. * Properly remove loop references. * Re-push, Github was down. * Need to debug interpretOp error. * Fix lowering bug by erasing ops after full krnl IR interpretation is done, and clean up & comment code. * Introduce permute, unroll operations. * More debug. * Remove std::set. * krnl.terminate fails to be converted. * Pass all tests, need to add legal ops as well as part of the conversion target. * Change test format to new permute spec. * Bug fix for nested iterate op lowering. * Simplify error reporting. * Fix compilation error. * Increase comments coverage. * Remove unnecessary imports. * Re-trigger Jenkins * Add permute/unroll tests. * Retrigger Jenkins * initial implementation of gather * added tests * format * remove affine load for second load, as it uses an indirection * changes suggested by reviewers * remove backend tests until I can verify them locally Co-authored-by: Tian Jin Signed-off-by: Kevin O'Brien * add lit test Signed-off-by: Kevin O'Brien * fix option spelling Signed-off-by: Kevin O'Brien * braces in wrong place Signed-off-by: Kevin O'Brien * add lit test Signed-off-by: Kevin O'Brien * remove duplicate code from lit test Signed-off-by: Kevin O'Brien * Simplify lit test Signed-off-by: Kevin O'Brien * remove attributes from lit test Signed-off-by: Kevin O'Brien * add onnx-mlir-opt to tool names Signed-off-by: Kevin O'Brien * add printIR to second RUN Signed-off-by: Kevin O'Brien * redo adding printIR Signed-off-by: Kevin O'Brien * fix bug Signed-off-by: Kevin O'Brien * format Signed-off-by: Kevin O'Brien * fix typo in test Signed-off-by: Kevin O'Brien Co-authored-by: Alexandre Eichenberger Co-authored-by: Tian Jin Co-authored-by: Tung D. Le Co-authored-by: Gheorghe-Teodor Bercea Co-authored-by: Haruki Imai Co-authored-by: Kevin Wu <6334443+kwu91@users.noreply.github.com> Co-authored-by: chentong319 --- .travis.yml | 2 +- src/MainUtils.cpp | 24 ++++++++++++++++++++++-- src/main.cpp | 3 +-- test/mlir/lit.cfg.py | 2 +- test/mlir/onnx/onnx_location.mlir | 11 +++++++++++ test/mlir/onnx/onnx_lowering.mlir | 1 - 6 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 test/mlir/onnx/onnx_location.mlir diff --git a/.travis.yml b/.travis.yml index 1f11046..830e494 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ script: - docker exec build compile-onnx-mlir.sh - docker exec build test-onnx-mlir.sh - docker commit build onnxmlirczar/onnx-mlir-build:$CPU_ARCH - + jobs: fast_finish: true allow_failures: diff --git a/src/MainUtils.cpp b/src/MainUtils.cpp index 35e22ac..f5350f1 100644 --- a/src/MainUtils.cpp +++ b/src/MainUtils.cpp @@ -446,27 +446,47 @@ void processInputFile(string inputFilename, EmissionTargetType emissionTarget, } } +// This definition is here rather than in main.cpp because otherwise it's not +// found probably should be pulled out to a more common location +// TODO: Find a respectable home for the wain +llvm::cl::OptionCategory OnnxMlirOptions( + "ONNX MLIR Options", "These are frontend options."); +// the option is used in this file, so defined here +llvm::cl::opt preserveLocations("preserveLocations", + llvm::cl::desc("emit location data:"), llvm::cl::init(false), + llvm::cl::cat(OnnxMlirOptions)); + +llvm::cl::opt printIR("printIR", + llvm::cl::desc("print the IR to stdout:"), llvm::cl::init(false), + llvm::cl::cat(OnnxMlirOptions)); + void outputCode( mlir::OwningModuleRef &module, string filename, string extension) { // Start a separate process to redirect the model output. I/O redirection // changes will not be visible to the parent process. string tempFilename = filename + extension; + mlir::OpPrintingFlags flags; + if (preserveLocations) + flags.enableDebugInfo(); + #ifdef _WIN32 // copy original stderr file number int stderrOrigin = _dup(_fileno(stderr)); freopen(tempFilename.c_str(), "w", stderr); - module->dump(); + module->print(llvm::errs(), flags); fflush(stderr); // set modified stderr as original stderr _dup2(stderrOrigin, _fileno(stderr)); #else if (fork() == 0) { freopen(tempFilename.c_str(), "w", stderr); - module->dump(); + module->print(llvm::errs(), flags); fclose(stderr); exit(0); } #endif + if (printIR) + module->print(llvm::outs(), flags); } void emitOutputFiles(string outputBaseName, EmissionTargetType emissionTarget, diff --git a/src/main.cpp b/src/main.cpp index d273af1..29989e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,14 +10,13 @@ using namespace std; using namespace onnx_mlir; +extern llvm::cl::OptionCategory OnnxMlirOptions; int main(int argc, char *argv[]) { setExecPath(argv[0], (void *)main); mlir::MLIRContext context; registerDialects(context); - llvm::cl::OptionCategory OnnxMlirOptions( - "ONNX MLIR Options", "These are frontend options."); llvm::cl::opt inputFilename(llvm::cl::Positional, llvm::cl::desc(""), llvm::cl::init("-"), llvm::cl::cat(OnnxMlirOptions)); diff --git a/test/mlir/lit.cfg.py b/test/mlir/lit.cfg.py index 7dc6819..a963de5 100644 --- a/test/mlir/lit.cfg.py +++ b/test/mlir/lit.cfg.py @@ -31,7 +31,7 @@ tool_dirs = [ config.onnx_mlir_tools_dir, config.mlir_tools_dir, config.llvm_tools_dir ] tool_names = [ - 'onnx-mlir-opt', 'mlir-opt', 'mlir-translate', "binary-decoder" + 'onnx-mlir', 'onnx-mlir-opt', 'mlir-opt', 'mlir-translate', "binary-decoder" ] tools = [ToolSubst(s, unresolved='ignore') for s in tool_names] llvm_config.add_tool_substitutions(tools, tool_dirs) \ No newline at end of file diff --git a/test/mlir/onnx/onnx_location.mlir b/test/mlir/onnx/onnx_location.mlir new file mode 100644 index 0000000..be64793 --- /dev/null +++ b/test/mlir/onnx/onnx_location.mlir @@ -0,0 +1,11 @@ + +// RUN: onnx-mlir --EmitMLIR --preserveLocations --printIR %s | FileCheck %s --checkPrefixes=PRESENT; rm %p/*.onnx.mlir ; rm %p/*.tmp +// RUN: onnx-mlir --EmitMLIR --printIR %s | FileCheck %s --checkPrefixes=ABSENT; rm %p/*.onnx.mlir ; rm %p/*.tmp + + func @main_graph(%arg0: tensor<1x16xf32>, %arg1: tensor<1x16xf32>) -> tensor<1x16xf32> { + %0 = "onnx.Add"(%arg0, %arg1) : (tensor<1x16xf32>, tensor<1x16xf32>) -> tensor<1x16xf32> loc("/build/workspace/addop.onnx":1:0) + return %0 : tensor<1x16xf32> + } + +// PRESENT: loc("{{(/[[:alnum:]]+)+}}.onnx":1:0) +// ABSENT-NOT: loc("{{(/[[:alnum:]]+)+}}.onnx":1:0) diff --git a/test/mlir/onnx/onnx_lowering.mlir b/test/mlir/onnx/onnx_lowering.mlir index 4318d1f..14d84ce 100644 --- a/test/mlir/onnx/onnx_lowering.mlir +++ b/test/mlir/onnx/onnx_lowering.mlir @@ -2285,4 +2285,3 @@ func @test_constant_of_shape_static_dims() -> tensor<*xf32> { // CHECK: } // CHECK: return [[RES]] : memref<3x4x5xf32> } -