{"id":13811686,"url":"https://github.com/iml130/mlir-emitc","last_synced_at":"2025-05-14T19:34:00.042Z","repository":{"id":36954065,"uuid":"267591415","full_name":"iml130/mlir-emitc","owner":"iml130","description":"Conversions to MLIR EmitC","archived":false,"fork":false,"pushed_at":"2024-08-22T07:05:59.000Z","size":1575,"stargazers_count":118,"open_issues_count":2,"forks_count":24,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-08-22T08:25:48.594Z","etag":null,"topics":["code-generation","mlir"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iml130.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-28T13:02:23.000Z","updated_at":"2024-08-22T07:06:03.000Z","dependencies_parsed_at":"2023-02-17T17:31:23.883Z","dependency_job_id":"dd90466c-296e-4d01-9a5e-95cc75c9d1b2","html_url":"https://github.com/iml130/mlir-emitc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iml130%2Fmlir-emitc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iml130%2Fmlir-emitc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iml130%2Fmlir-emitc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iml130%2Fmlir-emitc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iml130","download_url":"https://codeload.github.com/iml130/mlir-emitc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225307823,"owners_count":17453882,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generation","mlir"],"created_at":"2024-08-04T04:00:28.673Z","updated_at":"2025-05-14T19:34:00.033Z","avatar_url":"https://github.com/iml130.png","language":"C++","readme":"\u003c!--\nSPDX-FileCopyrightText: Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.\nSPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n--\u003e\n# MLIR-EmitC\n\n![Build and test](https://github.com/iml130/mlir-emitc/workflows/Build%20and%20test/badge.svg)\n\n\u003e [!WARNING]\n\u003e The code provided in this repository is no longer maintained and superseded by code available in upstream MLIR. \n\n\u003e [!NOTE]  \n\u003e We encourage to use upstream MLIR lowering passes instead of the TOSA and StableHLO to EmitC conversions provided here.\n\u003e Lowering via multiple dialects and hence using different abstraction levels, allows to reuse different optimization passes.\n\u003e Furthermore, the generated C and C++ code depends on the standard libraries without requiring additional header files, whereas code generated with the the conversions in this repositories requires a header-only reference implementation.\n\u003e For missing features, we highly encourage to consider extending the upstream dialect and conversions.\n\nMLIR-EmitC provides a way to translate ML models into C++ code. The repository\ncontains scripts and tools to translate Keras and TensorFlow models into the\n[TOSA](https://mlir.llvm.org/docs/Dialects/TOSA/) and\n[StableHLO](https://github.com/openxla/stablehlo/) dialect and to convert those to\n[EmitC](https://mlir.llvm.org/docs/Dialects/EmitC/).\nThe latter is used to generate calls to a reference implementation.\n\n**The [EmitC](https://mlir.llvm.org/docs/Dialects/EmitC/) dialect itself, as well as the C++ emitter, are part of MLIR core and are no longer provided via this repository.**\n\nThe initial EmitC dialect and C++ emitter checked into this repository were forked from https://reviews.llvm.org/D76571.\n\n**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.\n\n\n## Getting Started\n### Clone\n\n```shell\ngit clone https://github.com/iml130/mlir-emitc.git\ncd mlir-emitc\ngit submodule update --init\n```\n\n### Build and Run\n\nThere 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.\n\n#### Building with pre-built LLVM/MLIR\n\nThe 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`](https://github.com/iml130/mlir-emitc/blob/main/build_tools/build_mlir.sh) shell script to configure, build and install LLVM and MLIR.\n\n**Note**: The hash of the latest tested LLVM version is given in [`build_tools/llvm_version.txt`](https://github.com/iml130/mlir-emitc/blob/main/build_tools/llvm_version.txt). Since MLIR evolves fast, it is possible that EmitC fails to build with a newer LLVM.\n\nTo build and launch the tests, run\n```shell\nmkdir build \u0026\u0026 cd build\ncmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .. -DMLIR_DIR=$PREFIX/lib/cmake/mlir -DLLVM_EXTERNAL_LIT=$BUILD_DIR/bin/llvm-lit\ncmake --build . --target check-emitc\n```\n\n**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.\n\nTo additionally build and execute the unittests, run\n```shell\ncmake --build . --target MLIREmitCTests\n./reference-implementation/unittests/MLIREmitCTests\n```\n\n#### Bulding as part of an LLVM/MLIR build\n\nMLIR-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).\n\nTo build and launch the tests, run\n```shell\nmkdir build \u0026\u0026 cd build\ncmake -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\ncmake --build . --target check-emitc\n```\n\n## Supported Conversions and Translations\n\nConversions are supported for [StableHLO](https://github.com/openxla/stablehlo/) ops and some ops of the arith and Tensor dialect.\nIn addition, support for converting Tensor Operator Set Architecture [(TOSA)](https://mlir.llvm.org/docs/Dialects/TOSA/) dialect to EmitC is emerging.\nThe `emitc-opt` tool supports the following options:\n\n| option                                     |                                                                          |\n| :----------------------------------------- |:------------------------------------------------------------------------ |\n| `--convert-func-to-emitc`                  | Convert Func dialect to EmitC dialect                                    |\n| `--convert-scf-to-emitc`                   | Convert SCF dialect to EmitC dialect, maintaining structured control flow|\n| `--convert-stablehlo-region-ops-to-emitc ` | Convert StableHLO operations containing regions to EmitC dialect.        |\n| `--convert-stablehlo-to-emitc `            | Convert from StableHLO dialect to EmitC dialect.                         |\n| `--convert-arith-to-emitc-ext `            | Convert arith dialect to EmitC dialect (extended).                       |\n| `--convert-tensor-to-emitc `               | Convert tensor dialect to EmitC dialect.                                 |\n| `--convert-tosa-to-emitc `                 | Convert TOSA dialect to EmitC dialect.                                   |\n| `--insert-emitc-stablehlo-include`         | Insert an EmitC include for the StableHLO dialect.                       |\n| `--insert-emitc-arith-include`             | Insert an EmitC include for the arith dialect.                           |\n| `--insert-emitc-tensor-include`            | Insert an EmitC include for the tensor dialect.                          |\n| `--insert-emitc-tosa-include`              | Insert an EmitC include for the TOSA dialect.                            |\n| `--stablehlo-to-emitc-pipeline`            | Run the StableHLO to EmitC pipeline.                                     |\n| `--arith-to-emitc-pipeline`                | Run the Arithmetic to EmitC pipeline.                                    |\n| `--tensor-to-emitc-pipeline`               | Run the Tensor to EmitC pipeline.                                        |\n| `--tosa-to-emitc-pipeline`                 | Run the TOSA to EmitC pipeline.                                          |\n\nThe currently supported StableHLO ops are listed in the [docs/stablehlo-op-coverage.md](docs/stablehlo-op-coverage.md) document.\nSupported TOSA ops are listed in the [docs/tosa-op-coverage.md](docs/tosa-op-coverage.md) document.\n\nAfter converting to EmitC dialect, C++ code can be emitted using `emitc-translate --mlir-to-cpp`.\nFurthermore, `emitc-translate` has specific support to emit code with variables declared at top using `--mlir-to-cpp --declare-variables-at-top`.\n","funding_links":[],"categories":["Implements based on the underlying LLVM/MLIR compiler technology","Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiml130%2Fmlir-emitc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiml130%2Fmlir-emitc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiml130%2Fmlir-emitc/lists"}