-
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 1 commit
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
Signed-off-by: Chen Tong <chentong@us.ibm.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ 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) | ||
#unset(ONNX_MLIR_ENABLE_PYRUNTIME_LIT CACHE) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
|
@@ -73,8 +75,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 +163,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 +217,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,39 @@ | ||
# 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() | ||
message(STATUS "ONNX_MLIR_ENABLE_PYRUNTIME_LIT: ${ONNX_MLIR_ENABLE_PYRUNTIE_LIT}") | ||
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}) | ||
|
@@ -55,6 +61,7 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND NOT LLVM_INSTALL_PREFIX) | |
endif() | ||
message(STATUS "CMAKE_INSTALL_PREFIX : " ${CMAKE_INSTALL_PREFIX}) | ||
|
||
if (ONNX_MLIR_ENABLE_PYRUNTIME_LIT) | ||
# The tablegen functions below are modeled based on the corresponding functions | ||
# in mlir: https://github.com/llvm/llvm-project/blob/main/mlir/cmake/modules/AddMLIR.cmake | ||
function(add_onnx_mlir_dialect_doc dialect dialect_tablegen_file) | ||
|
@@ -126,6 +133,7 @@ function(add_onnx_mlir_interface interface) | |
mlir_tablegen(${interface}.cpp.inc -gen-op-interface-defs) | ||
add_public_tablegen_target(OM${interface}IncGen) | ||
endfunction() | ||
endif() | ||
|
||
# add_onnx_mlir_library(name sources... | ||
# This function (generally) has the same semantic as add_library. In | ||
|
@@ -158,7 +166,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}) | ||
|
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.