-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build light weight PyRuntime without llvm or onnx-mlir #3044
Changes from 10 commits
4ab6256
49034b5
45b1d9d
0ee214f
beff2e3
28584dd
a92ccc2
2037d8d
8ecd7ff
79ab54f
0bd61d2
0694678
0d049a5
8c8a17f
8ff28b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ option(ONNX_MLIR_ENABLE_STABLEHLO "Enable StableHLO support." ON) | |
option(ONNX_MLIR_ENABLE_WERROR "Enable warnings as errors." OFF) | ||
option(ONNX_MLIR_SUPPRESS_THIRD_PARTY_WARNINGS "Suppress warning in third_party code." ON) | ||
option(ONNX_MLIR_ENABLE_JAVA "Set to ON for building the Java runtime, tools, and tests" ON) | ||
option(ONNX_MLIR_ENABLE_PYRUNTIME_LIT "Set to ON for building Python driver of running the compiled model without llvm-project." OFF) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
|
@@ -73,8 +74,10 @@ set(ONNX_MLIR_INCLUDE_PATH ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}) | |
set(ONNX_MLIR_VENDOR ${PACKAGE_VENDOR} CACHE STRING | ||
"Vendor-specific text for showing with version information.") | ||
|
||
include(CTest) | ||
include(ExternalProject) | ||
if(NOT ONNX_MLIR_ENABLE_PYRUNTIME_LIT) | ||
include(CTest) | ||
include(ExternalProject) | ||
endif() | ||
include(MLIR.cmake) | ||
|
||
# MLIR.cmake calls find_package(MLIR) which sets LLVM_MINIMUM_PYTHON_VERSION | ||
|
@@ -159,23 +162,29 @@ endif() | |
set(CMAKE_MESSAGE_LOG_LEVEL NOTICE) | ||
|
||
# Add third party subdirectories and define options appropriate to run their cmakes. | ||
set(pybind11_FIND_QUIETLY ON) | ||
add_subdirectory(third_party/onnx) | ||
add_subdirectory(third_party/pybind11) | ||
add_subdirectory(third_party/rapidcheck) | ||
if (ONNX_MLIR_ENABLE_PYRUNTIME_LIT) | ||
add_subdirectory(third_party/onnx) | ||
add_subdirectory(third_party/pybind11) | ||
else() | ||
set(pybind11_FIND_QUIETLY ON) | ||
add_subdirectory(third_party/onnx) | ||
add_subdirectory(third_party/pybind11) | ||
|
||
if (ONNX_MLIR_ENABLE_STABLEHLO) | ||
add_subdirectory(third_party/stablehlo EXCLUDE_FROM_ALL) | ||
endif() | ||
add_subdirectory(third_party/rapidcheck) | ||
|
||
if (NOT TARGET benchmark) | ||
set(BENCHMARK_USE_BUNDLED_GTEST OFF) | ||
set(BENCHMARK_ENABLE_GTEST_TESTS OFF) | ||
set(BENCHMARK_ENABLE_TESTING OFF) | ||
set(BENCHMARK_ENABLE_WERROR OFF) | ||
# Since LLVM requires C++11 (or higher) it is safe to assume that std::regex is available. | ||
set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE) | ||
add_subdirectory(third_party/benchmark) | ||
if (ONNX_MLIR_ENABLE_STABLEHLO) | ||
add_subdirectory(third_party/stablehlo EXCLUDE_FROM_ALL) | ||
endif() | ||
|
||
if (NOT TARGET benchmark) | ||
set(BENCHMARK_USE_BUNDLED_GTEST OFF) | ||
set(BENCHMARK_ENABLE_GTEST_TESTS OFF) | ||
set(BENCHMARK_ENABLE_TESTING OFF) | ||
set(BENCHMARK_ENABLE_WERROR OFF) | ||
# Since LLVM requires C++11 (or higher) it is safe to assume that std::regex is available. | ||
set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE) | ||
add_subdirectory(third_party/benchmark) | ||
endif() | ||
endif() | ||
|
||
# All libraries and executables coming from llvm or ONNX-MLIR have had their | ||
|
@@ -207,8 +216,12 @@ if (ONNX_MLIR_ENABLE_STABLEHLO) | |
add_compile_definitions(ONNX_MLIR_ENABLE_STABLEHLO) | ||
endif() | ||
|
||
add_subdirectory(utils) | ||
add_subdirectory(include) | ||
add_subdirectory(src) | ||
add_subdirectory(docs) | ||
add_subdirectory(test) | ||
if (ONNX_MLIR_ENABLE_PYRUNTIME_LIT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this (and above): there are some dir that added on both path. Is it that the order of them is important? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only the |
||
add_subdirectory(src) | ||
else() | ||
add_subdirectory(utils) | ||
add_subdirectory(include) | ||
add_subdirectory(src) | ||
add_subdirectory(docs) | ||
add_subdirectory(test) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Must unset LLVM_DIR in cache. Otherwise, when MLIR_DIR changes LLVM_DIR | ||
# won't change accordingly. | ||
unset(LLVM_DIR CACHE) | ||
if (NOT DEFINED MLIR_DIR) | ||
message(FATAL_ERROR "MLIR_DIR is not configured but it is required. " | ||
"Set the cmake option MLIR_DIR, e.g.,\n" | ||
" cmake -DMLIR_DIR=/path/to/llvm-project/build/lib/cmake/mlir ..\n" | ||
) | ||
endif() | ||
if (ONNX_MLIR_ENABLE_PYRUNTIME_LIT) | ||
function(llvm_update_compile_flags name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a one liner comment on why this function is defined here. |
||
endfunction() | ||
else() | ||
# Must unset LLVM_DIR in cache. Otherwise, when MLIR_DIR changes LLVM_DIR | ||
# won't change accordingly. | ||
unset(LLVM_DIR CACHE) | ||
if (NOT DEFINED MLIR_DIR) | ||
message(FATAL_ERROR "MLIR_DIR is not configured but it is required. " | ||
"Set the cmake option MLIR_DIR, e.g.,\n" | ||
" cmake -DMLIR_DIR=/path/to/llvm-project/build/lib/cmake/mlir ..\n" | ||
) | ||
endif() | ||
|
||
find_package(MLIR REQUIRED CONFIG) | ||
find_package(MLIR REQUIRED CONFIG) | ||
|
||
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") | ||
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") | ||
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") | ||
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") | ||
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") | ||
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") | ||
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") | ||
|
||
include(TableGen) | ||
include(AddLLVM) | ||
include(AddMLIR) | ||
include(TableGen) | ||
include(AddLLVM) | ||
include(AddMLIR) | ||
|
||
include(HandleLLVMOptions) | ||
include(HandleLLVMOptions) | ||
|
||
include_directories(${LLVM_INCLUDE_DIRS}) | ||
include_directories(${MLIR_INCLUDE_DIRS}) | ||
include_directories(${LLVM_INCLUDE_DIRS}) | ||
include_directories(${MLIR_INCLUDE_DIRS}) | ||
|
||
add_definitions(${LLVM_DEFINITIONS}) | ||
add_definitions(${LLVM_DEFINITIONS}) | ||
endif() | ||
|
||
set(BUILD_SHARED_LIBS ${LLVM_ENABLE_SHARED_LIBS} CACHE BOOL "" FORCE) | ||
message(STATUS "BUILD_SHARED_LIBS : " ${BUILD_SHARED_LIBS}) | ||
|
@@ -158,7 +163,9 @@ function(add_onnx_mlir_library name) | |
) | ||
|
||
if (NOT ARG_EXCLUDE_FROM_OM_LIBS) | ||
set_property(GLOBAL APPEND PROPERTY ONNX_MLIR_LIBS ${name}) | ||
if (NOT ONNX_MLIR_ENABLE_PYRUNTIME_LIT) | ||
set_property(GLOBAL APPEND PROPERTY ONNX_MLIR_LIBS ${name}) | ||
endif() | ||
endif() | ||
|
||
add_library(${name} ${ARG_UNPARSED_ARGUMENTS}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# How to build and use PyRuntime lit | ||
|
||
## Purpsoe | ||
|
||
PyRuntime lit is a different way to build the original PyRuntime (src/Runtime/python). | ||
All necessary dependence, such as llvm_project and onnx-mlir compiler is removed. The purpose is to easily build the python driver for the model execution on | ||
different systems. Currently, only the OMTenserUtils (src/Runtime), Python driver (src/Runtime/python), third_party/onnx and third_party/pybind11 are built. | ||
|
||
The build of PyRuntime lit is controlled by a CMake option: ONNX_MLIR_ENABLE_PYRUNTIME_LIT. Without this option to cmake, the whole system remains the same. | ||
|
||
## Functionalities | ||
1. Build the python driver without llvm_project and onnx-mlir compiler built. | ||
2. The python driver can be used with utils/RunONNXModel.py, or onnxmlir python package. | ||
3. With PyRuntime lit, the compiler has not been built locally and docker image of onnx-mlir has to be usd to compile the model. The onnxmlir package contains | ||
the python code to use python docker package to perform the compilation. Alternatively, the old script, onnx-mlir/docker/onnx-mlir.py, can do the fulfill the same task with subprocess and docker CLI. | ||
|
||
## How to use | ||
You can find the script for build and run at "onnx-mlir/utils/build-pyruntime-lit.sh. | ||
``` | ||
#!/bin/bash | ||
|
||
# Assume you are in an empty directory for build in cloned onnx-mlir. | ||
# Usually it is "your_path/onnx-mlir/build" | ||
# then you can run this script as "../util/build-pyruntime-lit.sh" | ||
|
||
cmake .. -DONNX_MLIR_ENABLE_PYRUNTIME_LIT=ON | ||
make | ||
make OMCreatePyRuntimePackage | ||
|
||
# Install the package | ||
pip3 install -e src/Runtime/python/onnxmlir | ||
# -e is necessary for current package. Need to add resource description | ||
# to install the pre-compiled binary | ||
|
||
# Run test case | ||
cd src/Runtime/python/onnxmlir/tests | ||
python3 test_1.py | ||
# Current limitation on where the model is | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the name should be explained: if off, then no pyruntime is build? Or its build anyway, but when on, then it's only the pyruntime? Or when off, pyruntime is build one way, but when off, its build another way?
Maybe the name could be a bit more explicit, depending on what the answer is from the question above.
minor question:
_LIT
is it for "_LIGHT"?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this option is off, the pyruntime is built with onnx-mlir and llvm-project, as it was previously.
When this option is on, only the pyruntime is built without llvm-project.
Yes, LIT for LIGHT.