Skip to content

Commit

Permalink
Fix OOT LTC CI build failure
Browse files Browse the repository at this point in the history
  • Loading branch information
henrytwo committed Aug 19, 2022
1 parent 57681f7 commit 3a8e72a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ jobs:
-DLLVM_EXTERNAL_TORCH_MLIR_DIALECTS_SOURCE_DIR="${GITHUB_WORKSPACE}/externals/llvm-external-projects/torch-mlir-dialects" \
-DLLVM_TARGETS_TO_BUILD=host \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DTORCH_MLIR_ENABLE_LTC=ON \
-DTORCH_MLIR_USE_INSTALLED_PYTORCH="${{ matrix.torch-binary }}" \
-DPython3_EXECUTABLE="$(which python)" \
$GITHUB_WORKSPACE/externals/llvm-project/llvm
Expand Down Expand Up @@ -134,6 +133,7 @@ jobs:
-DLLVM_ENABLE_ZSTD=OFF \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DTORCH_MLIR_ENABLE_MHLO=OFF \
-DTORCH_MLIR_ENABLE_LTC=OFF \
-DTORCH_MLIR_USE_INSTALLED_PYTORCH="${{ matrix.torch-binary }}" \
-DMACOSX_DEPLOYMENT_TARGET=12.0 \
-DPython3_EXECUTABLE="$(which python)" \
Expand Down
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ if(TORCH_MLIR_ENABLE_MHLO)
endif()
endif()

# TODO: Reenable LTC once OOT build is successful (https://github.com/llvm/torch-mlir/issues/1154)
option(TORCH_MLIR_ENABLE_LTC "Enables LTC backend" OFF)
option(TORCH_MLIR_ENABLE_LTC "Enables LTC backend" ON)

if(TORCH_MLIR_ENABLE_LTC)
set(ENV{TORCH_MLIR_ENABLE_LTC} 1)
Expand Down
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ add_mlir_python_modules(TorchMLIRPythonModules
# Then it would "just work".
if(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER)
add_dependencies(TorchMLIRPythonModules TorchMLIRJITIRImporter)
add_dependencies(TorchMLIRPythonModules TorchMLIRJITIRImporterPybind)
# Build the E2E Tests (which depend on the JIT IR importer now).
add_dependencies(TorchMLIRPythonModules TorchMLIRE2ETestPythonModules)
endif()
Expand Down
3 changes: 2 additions & 1 deletion python/torch_mlir/csrc/reference_lazy_backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if(TORCH_MLIR_ENABLE_LTC)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
add_link_options(-Wl,-rpath,$ORIGIN/lib)

add_library(reference_lazy_backend SHARED
add_library(reference_lazy_backend MODULE
backend_impl.cpp
reference_lazy_backend_pybind.cpp
)
Expand All @@ -51,6 +51,7 @@ if(TORCH_MLIR_ENABLE_LTC)
)
target_link_libraries(reference_lazy_backend
${TORCH_LIBRARIES}
torch_python
torch_mlir_ltc_backend
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,66 @@ include_directories(BEFORE
)
link_directories("${TORCH_INSTALL_PREFIX}/lib")

# TODO: Currently, out-of-tree build fails when LIBRARY_TYPE is set to SHARED, so we have this toggle.
# See https://github.com/llvm/torch-mlir/issues/1154 for more details.
if(TORCH_MLIR_ENABLE_LTC)
set(LIBRARY_TYPE "SHARED")
else()
set(LIBRARY_TYPE "MODULE")
endif()

add_library(TorchMLIRJITIRImporter ${LIBRARY_TYPE}
# Static library with core functionality.
add_library(TorchMLIRJITIRImporter STATIC
class_annotator.cpp
class_annotator_pybind.cpp
get_registered_ops.cpp
function_importer.cpp
module_builder.cpp
node_importer.cpp
import_options_pybind.cpp
ivalue_importer.cpp
init_python_bindings.cpp
torch_to_mlir_utils.cpp
)

target_link_libraries(TorchMLIRJITIRImporter
TorchMLIRAggregateCAPI
${TORCH_LIBRARIES}
)
message(STATUS "TORCH_CXXFLAGS=${TORCH_CXXFLAGS}")
set_target_properties(TorchMLIRJITIRImporter PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${TORCH_MLIR_PYTHON_PACKAGES_DIR}/torch_mlir/torch_mlir/_mlir_libs"
OUTPUT_NAME lib_jit_ir_importer
PREFIX ""
SUFFIX ".a"
CXX_VISIBILITY_PRESET "default"
COMPILE_FLAGS "${TORCH_CXXFLAGS}"
)

# Separate Pybind MODULE due to issues with a SHARED library.
# https://github.com/llvm/torch-mlir/issues/1154
add_library(TorchMLIRJITIRImporterPybind MODULE
class_annotator_pybind.cpp
get_registered_ops.cpp
import_options_pybind.cpp
init_python_bindings.cpp
module_builder.cpp
)
add_dependencies(TorchMLIRJITIRImporterPybind
TorchMLIRJITIRImporter
)
target_link_libraries(TorchMLIRJITIRImporterPybind
${TORCH_LIBRARIES}
torch_python
)
TorchMLIRJITIRImporter
)

# On static Python builds, there may not be Python libraries to link against
# (they will late bind at runtime from the executable). We have to condition
# this because in that case it is set to NOTFOUND and CMake will consider
# this an error.
if(Python3_LIBRARIES)
target_link_libraries(TorchMLIRJITIRImporter
target_link_libraries(TorchMLIRJITIRImporterPybind
${Python3_LIBRARIES}
)
endif()

message(STATUS "TORCH_CXXFLAGS=${TORCH_CXXFLAGS}")
set_target_properties(TorchMLIRJITIRImporter PROPERTIES
set_target_properties(TorchMLIRJITIRImporterPybind PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${TORCH_MLIR_PYTHON_PACKAGES_DIR}/torch_mlir/torch_mlir/_mlir_libs"
OUTPUT_NAME _jit_ir_importer
PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}"
CXX_VISIBILITY_PRESET "hidden"
COMPILE_FLAGS "${TORCH_CXXFLAGS}"
)
mlir_python_setup_extension_rpath(TorchMLIRJITIRImporter)
mlir_python_setup_extension_rpath(TorchMLIRJITIRImporterPybind)

torch_mlir_python_target_compile_options(TorchMLIRJITIRImporter)
mlir_check_all_link_libraries(TorchMLIRJITIRImporter)
torch_mlir_python_target_compile_options(TorchMLIRJITIRImporterPybind)
mlir_check_all_link_libraries(TorchMLIRJITIRImporterPybind)
8 changes: 0 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
# prevent this script from attempting to build the directory, and will simply
# use the (presumed already built) directory as-is.
#
# By default the lazy tensor backend is disabled and not built to avoid conflicts
# with the out-of-tree build. To enable it, set the TORCH_MLIR_ENABLE_LTC
# environment variable to 1.
#
# The package version can be set with the TORCH_MLIR_PYTHON_PACKAGE_VERSION
# environment variable. For example, this can be "20220330.357" for a snapshot
# release on 2022-03-30 with build number 357.
Expand Down Expand Up @@ -86,10 +82,6 @@ def run(self):
f"-DCMAKE_C_VISIBILITY_PRESET=hidden",
f"-DCMAKE_CXX_VISIBILITY_PRESET=hidden",
]
# TODO: Enable LTC by default once JIT importer linkage issue is fixed (https://github.com/llvm/torch-mlir/issues/1154)
enable_ltc = bool(int(os.environ.get("TORCH_MLIR_ENABLE_LTC", 0)))
if not enable_ltc:
cmake_args.append("-DTORCH_MLIR_ENABLE_LTC=OFF")

os.makedirs(cmake_build_dir, exist_ok=True)
cmake_cache_file = os.path.join(cmake_build_dir, "CMakeCache.txt")
Expand Down

0 comments on commit 3a8e72a

Please sign in to comment.