Go to file
Gheorghe-Teodor Bercea 8a992b619f
Create some helper functions to emit constant op for a specific type (#7)
* emitConstantOp with a given type

* Helper functions to create infinity constants

* Use new constant helper functions for MaxPoolSingleOut

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-03-05 14:21:00 -05:00
.buildbot Exit Bash Script on Error (#381) 2019-12-21 00:50:30 -05:00
.circleci Use the exact commit id specified in clang-ykt/llvm-project. 2020-03-03 00:18:59 +08:00
doc Add a pass to decompose ONNX operations (#9) 2020-03-04 10:53:59 -05:00
src Create some helper functions to emit constant op for a specific type (#7) 2020-03-05 14:21:00 -05:00
test Lower MaxPoolSingleOutOp to Krnl dialect (#1) 2020-03-04 14:27:21 -05:00
third_party Transition to ONNX-1.6.0. (#95) 2020-02-25 13:04:15 +08:00
utils Use the exact commit id specified in clang-ykt/llvm-project. 2020-03-03 00:18:59 +08:00
.clang-format Introduce helper class to generate KRNL code and apply it to Convolution (#93) 2020-02-24 17:20:15 -05:00
.gitignore Update gitignore file to ignore Filesystem artifacts and python related temporary files. (#103) 2020-02-25 11:18:37 -05:00
.gitmodules Chentong319 attribute with variant (#25) 2020-01-21 19:36:21 -07:00
CMakeLists.txt Chentong319 attribute with variant (#25) 2020-01-21 19:36:21 -07:00
LICENSE Initial commit 2019-12-18 10:18:14 -05:00
MLIR.cmake Fix building ONNF with latest LLVM/MLIR (#89) 2020-02-19 18:15:02 -05:00
README.md Use the exact commit id specified in clang-ykt/llvm-project. 2020-03-03 00:18:59 +08:00
SharingWork.md Added lowering of SignOp (#21) 2020-02-04 22:27:17 +08:00

README.md

ONNF

Open Neural Network Frontend : an ONNX frontend for MLIR.

CircleCI

Prerequisites

gcc >= 6.4
libprotoc >= 3.11.0
cmake >= 3.15.4

Installation

Firstly, install MLIR (as a part of LLVM-Project):

git clone https://github.com/llvm/llvm-project.git
# Check out a specific branch that is known to work with ONNF.
cd llvm-project && git checkout 076475713c236081a3247a53e9dbab9043c3eac2 && cd ..
mkdir llvm-project/build
cd llvm-project/build
cmake -G Ninja ../llvm \
   -DLLVM_ENABLE_PROJECTS=mlir \
   -DLLVM_BUILD_EXAMPLES=ON \
   -DLLVM_TARGETS_TO_BUILD="host" \
   -DCMAKE_BUILD_TYPE=Release \
   -DLLVM_ENABLE_ASSERTIONS=ON \
   -DLLVM_ENABLE_RTTI=ON

cmake --build . --target -- ${MAKEFLAGS}
cmake --build . --target check-mlir

Two environment variables need to be set:

  • LLVM_PROJ_SRC should point to the llvm-project src directory (e.g., llvm-project/).
  • LLVM_PROJ_BUILD should point to the llvm-project build directory (e.g., llvm-project/build).

To build ONNF, use the following command:

git clone --recursive git@github.com:clang-ykt/ONNF.git

# Export environment variables pointing to LLVM-Projects.
export LLVM_PROJ_SRC=$(pwd)/llvm-project/
export LLVM_PROJ_BUILD=$(pwd)/llvm-project/build

mkdir ONNF/build && cd ONNF/build
cmake ..
cmake --build . --target onnf

# Run FileCheck tests:
export LIT_OPTS=-v
cmake --build . --target check-mlir-lit

After the above commands succeed, an onnf executable should appear in the bin directory.

Using ONNF

The usage of onnf is as such:

OVERVIEW: ONNF MLIR modular optimizer driver

USAGE: onnf [options] <input file>

OPTIONS:

Generic Options:

  --help        - Display available options (--help-hidden for more)
  --help-list   - Display list of available options (--help-list-hidden for more)
  --version     - Display the version of this program

ONNF Options:
These are frontend options.

  Choose target to emit:
      --EmitONNXIR - Ingest ONNX and emit corresponding ONNX dialect.
      --EmitMLIR   - Lower model to MLIR built-in transformation dialect.
      --EmitLLVMIR - Lower model to LLVM IR (LLVM dialect).
      --EmitLLVMBC - Lower model to LLVM IR and emit (to file) LLVM bitcode for model.

Example

For example, to lower an ONNX model (e.g., add.onnx) to ONNX dialect, use the following command:

./onnf --EmitONNXIR add.onnx

The output should look like:

module {
  func @main_graph(%arg0: tensor<10x10x10xf32>, %arg1: tensor<10x10x10xf32>) -> tensor<10x10x10xf32> {
    %0 = "onnx.Add"(%arg0, %arg1) : (tensor<10x10x10xf32>, tensor<10x10x10xf32>) -> tensor<10x10x10xf32>
    return %0 : tensor<10x10x10xf32>
  }
}

Troubleshooting

If the latest LLVM project fails to work due to the latest changes to the MLIR subproject please consider using a slightly older version of LLVM. One such version, which we use, can be found here.