Giter Site home page Giter Site logo

mlir-emitc's Introduction

MLIR-EmitC

Build and test

MLIR-EmitC provides a way to translate ML models into C++ code. The repository contains scripts and tools to translate Keras and TensorFlow models into the TOSA and StableHLO dialect and to convert those to EmitC. The latter is used to generate calls to a reference implementation.

The EmitC dialect itself, as well as the C++ emitter, are part of MLIR core and are no longer provided via this repository.

The initial EmitC dialect and C++ emitter checked into this repository were forked from https://reviews.llvm.org/D76571.

DISCLAIMER: This is a research project and not intended for everyday use. The code is made available without any support. However, we welcome any kind of feedback via the issue tracker.

Getting Started

Clone

git clone https://github.com/iml130/mlir-emitc.git
cd mlir-emitc
git submodule update --init

Build and Run

There are two variants to build EmitC: As part of an LLVM/MLIR build (via the LLVM external projects mechanism) and against a pre-built LLVM/MLIR.

Building with pre-built LLVM/MLIR

The setup assumes that you have built LLVM and MLIR in $BUILD_DIR and installed them to $PREFIX. You can use the build_tools/build_mlir.sh shell script to configure, build and install LLVM and MLIR.

Note: The hash of the latest tested LLVM version is given in build_tools/llvm_version.txt. Since MLIR evolves fast, it is possible that EmitC fails to build with a newer LLVM.

To build and launch the tests, run

mkdir build && cd build
cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .. -DMLIR_DIR=$PREFIX/lib/cmake/mlir -DLLVM_EXTERNAL_LIT=$BUILD_DIR/bin/llvm-lit
cmake --build . --target check-emitc

Note: If you don't use build_tools/build_mlir.sh, make sure to pass -DLLVM_INSTALL_UTILS=ON when building LLVM with CMake in order to install FileCheck to the chosen installation prefix.

To additionally build and execute the unittests, run

cmake --build . --target MLIREmitCTests
./reference-implementation/unittests/MLIREmitCTests

Bulding as part of an LLVM/MLIR build

MLIR-EmitC can also be built as part of an LLVM/MLIR build, using the LLVM_EXTERNAL_PROJECTS mechanism (see https://llvm.org/docs/CMake.html).

To build and launch the tests, run

mkdir build && cd build
cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DEMITC_ENABLE_HLO=OFF -DLLVM_ENABLE_PROJECTS=mlir -DLLVM_EXTERNAL_PROJECTS="mlir-emitc" -DLLVM_EXTERNAL_MLIR_EMITC_SOURCE_DIR=`realpath ../` -DLLVM_TARGETS_TO_BUILD=host ${ROOT_PATH_TO_llvm-project}/llvm
cmake --build . --target check-emitc

Supported Conversions and Translations

Conversions are supported for StableHLO ops and some ops of the arith and Tensor dialect. In addition, support for converting Tensor Operator Set Architecture (TOSA) dialect to EmitC is emerging. The emitc-opt tool supports the following options:

option
--convert-func-to-emitc Convert Func dialect to EmitC dialect
--convert-scf-to-emitc Convert SCF dialect to EmitC dialect, maintaining structured control flow
--convert-stablehlo-region-ops-to-emitc Convert StableHLO operations containing regions to EmitC dialect.
--convert-stablehlo-to-emitc Convert from StableHLO dialect to EmitC dialect.
--convert-arith-to-emitc-ext Convert arith dialect to EmitC dialect (extended).
--convert-tensor-to-emitc Convert tensor dialect to EmitC dialect.
--convert-tosa-to-emitc Convert TOSA dialect to EmitC dialect.
--insert-emitc-stablehlo-include Insert an EmitC include for the StableHLO dialect.
--insert-emitc-arith-include Insert an EmitC include for the arith dialect.
--insert-emitc-tensor-include Insert an EmitC include for the tensor dialect.
--insert-emitc-tosa-include Insert an EmitC include for the TOSA dialect.
--stablehlo-to-emitc-pipeline Run the StableHLO to EmitC pipeline.
--arith-to-emitc-pipeline Run the Arithmetic to EmitC pipeline.
--tensor-to-emitc-pipeline Run the Tensor to EmitC pipeline.
--tosa-to-emitc-pipeline Run the TOSA to EmitC pipeline.

The currently supported StableHLO ops are listed in the docs/stablehlo-op-coverage.md document. Supported TOSA ops are listed in the docs/tosa-op-coverage.md document.

After converting to EmitC dialect, C++ code can be emitted using emitc-translate --mlir-to-cpp. Furthermore, emitc-translate has specific support to emit code with variables declared at top using --mlir-to-cpp --declare-variables-at-top.

mlir-emitc's People

Contributors

marbre avatar simon-camp avatar oliverscherf avatar henri-gruender avatar jpienaar avatar natashaknk avatar heidebro avatar lucas-camp avatar dajuro avatar jacob-hegna avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.