{"id":15144639,"url":"https://github.com/iith-compilers/ml-compiler-bridge","last_synced_at":"2025-07-13T05:41:22.510Z","repository":{"id":217719332,"uuid":"735809301","full_name":"IITH-Compilers/ML-Compiler-Bridge","owner":"IITH-Compilers","description":"Library to interface Compilers and ML models for ML-Enabled Compiler Optimizations","archived":false,"fork":false,"pushed_at":"2024-05-14T11:46:36.000Z","size":11122,"stargazers_count":17,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-29T22:09:36.178Z","etag":null,"topics":["compiler","llvm","machinelearning","mlir","optimization","pluto"],"latest_commit_sha":null,"homepage":"https://iith-compilers.github.io/ML-Compiler-Bridge/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IITH-Compilers.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":"2023-12-26T06:22:34.000Z","updated_at":"2024-10-24T08:54:01.000Z","dependencies_parsed_at":"2024-02-21T03:29:47.420Z","dependency_job_id":"230b70f3-ddda-4da3-bf67-87213ac2005c","html_url":"https://github.com/IITH-Compilers/ML-Compiler-Bridge","commit_stats":{"total_commits":243,"total_committers":11,"mean_commits":22.09090909090909,"dds":0.7283950617283951,"last_synced_commit":"53bf989f6e34125a2be6dd6b832cb852fb6922ce"},"previous_names":["iith-compilers/mlcompilerbridge","iith-compilers/ml-compiler-bridge"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IITH-Compilers%2FML-Compiler-Bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IITH-Compilers%2FML-Compiler-Bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IITH-Compilers%2FML-Compiler-Bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IITH-Compilers%2FML-Compiler-Bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IITH-Compilers","download_url":"https://codeload.github.com/IITH-Compilers/ML-Compiler-Bridge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237890775,"owners_count":19382562,"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":["compiler","llvm","machinelearning","mlir","optimization","pluto"],"created_at":"2024-09-26T11:00:20.659Z","updated_at":"2025-02-09T00:33:55.330Z","avatar_url":"https://github.com/IITH-Compilers.png","language":"C++","readme":"# ML-Compiler-Bridge\n\n`ML-Compiler-Bridge` is a compiler agnostic library to aid in ML-Enabled Compiler Optimizations. ML-Compiler-Bridge supports both training and inference scenarios. Library exposes Python and C/C++ APIs to interface\nwith the Python-based ML models and a C/C++ compiler. This design allows ML model development within a traditional Python framework while making end-to-end integration with an optimizing compiler possible and efficient.\n\nThis repo contains the source code and relevant information described in our paper, [\"The Next 700 ML-Enabled Compiler Optimizations\"](https://doi.org/10.1145/3640537.3641580) ([arxiv](https://arxiv.org/abs/2311.10800)).\nPlease see [here](https://iith-compilers.github.io/ML-Compiler-Bridge/) for documentation and other details.\n\n\u003e The Next 700 ML-Enabled Compiler Optimizations, S. VenkataKeerthy, Siddharth Jain, Umesh Kalvakuntla, Pranav Sai Gorantla, Rajiv Shailesh Chitale, Eugene Brevdo, Albert Cohen, Mircea Trofin and Ramakrishna Upadrasta. CC 2024.\n\n[![Build and Tests](https://github.com/IITH-Compilers/MLCompilerBridge/actions/workflows/build.yml/badge.svg)](https://github.com/IITH-Compilers/MLCompilerBridge/actions/workflows/build.yml)\n[![Doxygen Action](https://github.com/IITH-Compilers/MLCompilerBridge/actions/workflows/main.yml/badge.svg)](https://github.com/IITH-Compilers/MLCompilerBridge/actions/workflows/main.yml)\n[![pre-commit checks](https://github.com/IITH-Compilers/MLCompilerBridge/actions/workflows/formatting.yml/badge.svg)](https://github.com/IITH-Compilers/MLCompilerBridge/actions/workflows/formatting.yml)\n[![Upload to Pypi](https://github.com/IITH-Compilers/MLCompilerBridge/actions/workflows/upload_pypi.yml/badge.svg)](https://github.com/IITH-Compilers/MLCompilerBridge/actions/workflows/upload_pypi.yml)\n\n\n![Image](https://github.com/IITH-Compilers/ML-Compiler-Bridge/raw/main/images/component-ml-compiler-bridge.png)\n\n## Features\n* **Unified Framework:** Comes with a suite of two inter-process and two in-process model runners and three serialization-deserialization mechanisms to support interleaved and non-interleaved communication between models and compiler.\n* **Multi-language Support:** Exposes C++ and C APIs to interface model runners and serializers with the compilers and Python APIs to interface inter-process model runners with ML models.\n* **Compiler and ML-Framework Independence:** Provides compiler and ML-Framework independent APIs, and supports easier integration with compilers like LLVM, MLIR, and Pluto and ML Frameworks like TensorFlow, PyTorch, JAX, etc.\n* **Deeper Integration:** Enables deeper integration of ML models within the compiler in a framework-independent manner to support easier inference in case of ML driven compiler optimizations.\n\n## Requirements\n* cmake (\u003e= 3.10)\n* GNU Make (4.2.1)\n* LLVM (10.X) - [src](https://github.com/llvm/llvm-project/tree/release/10.x), [release](https://releases.llvm.org/download.html#10.0.1)\n* Python (3.10), C++17\n* gRPC v1.58 and protobuf v23.4 - for gRPC Model Runner\n    * Building GRPC from Source: Please follow [`Build GRPC with cmake`](https://grpc.io/docs/languages/cpp/quickstart/) v1.58 (protobuf v23.4) to build GRPC from source.\n    * In the above tutorial setting `DCMAKE_INSTALL_PREFIX` may not be necessary and the default install prefix can be used.\n    * The following dependencies will be required for Python: `pip install grpcio-tools`.\n* [ONNXRuntime](https://github.com/microsoft/onnxruntime/releases) v1.13.1\n* TensorFlow - for TF Model Runner (AOT flow)\n    * Tested with TensorFlow 2.13.0\n* Other python requirements are available in [mlbridge.yml](./mlbridge.yml)\n    * Conda/Anaconda based virtual environment is assumed\n\n(Experiments are done on an Ubuntu 20.04 machine)\n\n## Setup\n`ML-Compiler-Bridge` can be built as a stand-alone library to generate `.a` files that can in turn be linked with any compiler.\n1. `mkdir build \u0026\u0026 cd build`\n2. `cmake [-DCMAKE_BUILD_TYPE=Release|Debug] [-DCMAKE_INSTALL_PREFIX=\u003cInstall_path\u003e] [-DMLBRIDGE_ENABLE_TEST=ON|OFF] -DONNXRUNTIME_ROOTDIR=\u003cPath to ONNX install dir\u003e -DPROTOS_DIRECTORY=\u003cPath to protobuf files\u003e -DTENSORFLOW_AOT_PATH=\u003cPath to TensorFlow pip install dir\u003e ../`\n3. `make -j [\u0026\u0026 make install]`\n4. `pip install compilerinterface`\n\nThis process would generate `libMLCompilerBridge.a` and `libMLCompilerBridgeC.a` libraries under `build/lib` directory, required headers under `build/include` directory. `libMLCompilerBridgeC.a` exposes C APIs for using with C-based compilers like Pluto, where as `libMLCompilerBridge.a` exposes C++ APIs that can be used with any compiler written in C++.\n\nPython end points are available under [`CompilerInterface`](./CompilerInterface/). They can be downloaded as a [`package`](https://pypi.org/project/compilerinterface/) from pypi.\n\nTo ensure the correctness, run `make verify-all`. This would need enabling tests in cmake (`-DMLBRIDGE_ENABLE_TEST=ON`) and `PROTOS_DIRECTORY` should point to `test/protos`.\n\n### Using ML-Compiler-Bridge with LLVM and MLIR\n\n`ML-Compiler-Bridge` can be integrated and built along with the LLVM project. This can be done by adding this repository as a new project and setting `LLVM_MLBRIDGE` option to `ON`.\n\nYou can check the [CMakeLists.txt](https://github.com/IITH-Compilers/ml-llvm-project/blob/mlbridge-lib/llvm/CMakeLists.txt) of the [`ml-llvm-project`](https://github.com/IITH-Compilers/ml-llvm-project/tree/mlbridge-lib) repository which demonstrates such an integration.\n\nThe passes that need to make use of this library can then just link with `LLVMMLBridge`.\n\nExample `CMakeLists.txt` of an LLVM pass that would use the library is shown below.\n\n```CMakeLists.txt\nadd_llvm_component_library(LLVMMLPass\npass.cpp\nml.cpp\n\nADDITIONAL_HEADER_DIRS\n  ${CMAKE_CURRENT_SOURCE_DIR}/includes\n\nDEPENDS\n  LLVMMLBridge\n  intrinsics_gen\n)\ntarget_link_libraries(LLVMMLPass PRIVATE LLVMMLBridge)\n\n```\nTo use TensorFlow AOT Model Runner, you need to make use of `tf_find_and_compile` method exposed in [`cmake/modules/TensorFlowCompile.cmake`](cmake/modules/TensorFlowCompile.cmake) in the CMakeLists.txt of your pass with appropriate arguments. An example of integrating TF AOT Model with inlining pass is shown [here](https://github.com/IITH-Compilers/ml-llvm-project/blob/tfmodel/llvm/lib/Analysis/CMakeLists.txt).\n\n## Artifacts\nLibraries are autogenerated for every relevant check-in with GitHub actions. Such generated artifacts are tagged along with the successful runs of [`Publish`]() action.\n\n## Citation\n```\n@inproceedings{venkatakeerthy-2024-MLCompilerBridge,\nauthor = {VenkataKeerthy, S. and Jain, Siddharth and Kalvakuntla, Umesh and Gorantla, Pranav Sai and Chitale, Rajiv Shailesh and Brevdo, Eugene and Cohen, Albert and Trofin, Mircea and Upadrasta, Ramakrishna},\ntitle = {The Next 700 ML-Enabled Compiler Optimizations},\nyear = {2024},\nisbn = {9798400705076},\npublisher = {Association for Computing Machinery},\naddress = {New York, NY, USA},\nurl = {https://doi.org/10.1145/3640537.3641580},\ndoi = {10.1145/3640537.3641580},\nbooktitle = {Proceedings of the 33rd ACM SIGPLAN International Conference on Compiler Construction},\npages = {238–249},\nnumpages = {12},\nkeywords = {Machine Learning for Compiler Optimizations, ONNX, Pipes, TensorFlow AOT, gRPC},\nlocation = {\u003cconf-loc\u003e, \u003ccity\u003eEdinburgh\u003c/city\u003e, \u003ccountry\u003eUnited Kingdom\u003c/country\u003e, \u003c/conf-loc\u003e},\nseries = {CC 2024}\n}\n```\n\n## Contributions\nPlease feel free to raise issues to file a bug, pose a question, or initiate any related discussions. Pull requests are welcome :)\n\n## License\nML-Compiler-Bridge is released under Apache 2.0 license with LLVM Exceptions. See LICENSE file for more details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiith-compilers%2Fml-compiler-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiith-compilers%2Fml-compiler-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiith-compilers%2Fml-compiler-bridge/lists"}