@@ -60,6 +60,7 @@ if(TORCH_MLIR_ENABLE_TOSA)
list(APPEND TORCH_MLIR_TABLEGEN_FLAGS "-DTORCH_MLIR_ENABLE_TOSA")
endif()
+option(TORCH_MLIR_BUILD_EMBEDDED "Build torch mlir as part of another project" OFF)
option(TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF)
# PyTorch native extension gate. If OFF, then no features which depend on
@@ -134,7 +135,7 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR TORCH_MLIR_OUT_OF_TREE_
set(TORCH-MLIR_BUILT_STANDALONE ON)
set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
-else()
+elseif(NOT TORCH_MLIR_BUILD_EMBEDDED)
message(STATUS "Torch-MLIR in-tree build.")
# In-tree build with LLVM_EXTERNAL_PROJECTS=torch-mlir
@@ -145,6 +146,8 @@ else()
set(MLIR_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/../mlir/include)
set(MLIR_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/tools/mlir/include)
set(MLIR_INCLUDE_DIRS "${MLIR_INCLUDE_DIR};${MLIR_GENERATED_INCLUDE_DIR}")
+else()
+ message(STATUS "Torch-MLIR embedded build.")
endif()
set(TORCH_MLIR_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
@@ -48,6 +48,7 @@ declare_mlir_python_sources(TorchMLIRPythonSources.PublicAPI
extras/fx_decomp_util.py
)
+if(NOT TORCH_MLIR_BUILD_EMBEDDED)
declare_mlir_python_sources(TorchMLIRPythonSources.Tools
ROOT_DIR "${TORCH_MLIR_PYTHON_ROOT_DIR}"
ADD_TO_PARENT TorchMLIRPythonSources
@@ -62,6 +63,7 @@ declare_mlir_python_sources(TorchMLIRSiteInitialize
SOURCES
_mlir_libs/_site_initialize_0.py
)
+endif()
################################################################################
# Extensions
@@ -96,8 +98,10 @@ set(_source_components
MLIRPythonExtension.RegisterEverything
TorchMLIRPythonSources
TorchMLIRPythonExtensions
- TorchMLIRSiteInitialize
)
+if(NOT TORCH_MLIR_BUILD_EMBEDDED)
+ list(APPEND _source_components TorchMLIRSiteInitialize)
+endif()
if(TORCH_MLIR_ENABLE_STABLEHLO)
list(APPEND _source_components StablehloPythonExtensions)