Skip to content

Commit ba17a4d

Browse files
authored
Reenable LTC in out-of-tree build (for real this time) (#1205)
* Fix OOT LTC CI build failure * Disable LTC during macOS package gen * Add more details about static TorchMLIRJITIRImporter library
1 parent 65d811e commit ba17a4d

File tree

7 files changed

+47
-33
lines changed

7 files changed

+47
-33
lines changed

.github/workflows/buildAndTest.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ jobs:
7575
-DLLVM_EXTERNAL_TORCH_MLIR_DIALECTS_SOURCE_DIR="${GITHUB_WORKSPACE}/externals/llvm-external-projects/torch-mlir-dialects" \
7676
-DLLVM_TARGETS_TO_BUILD=host \
7777
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
78-
-DTORCH_MLIR_ENABLE_LTC=ON \
7978
-DTORCH_MLIR_USE_INSTALLED_PYTORCH="${{ matrix.torch-binary }}" \
8079
-DPython3_EXECUTABLE="$(which python)" \
8180
$GITHUB_WORKSPACE/externals/llvm-project/llvm
@@ -116,6 +115,7 @@ jobs:
116115
# cross compile, can't test arm64
117116
if: ${{ matrix.os-arch == 'macos-arm64' && matrix.llvm-build == 'in-tree' }}
118117
run: |
118+
# TODO: Reenable LTC after build on macOS-arm64 is fixed (https://github.com/llvm/torch-mlir/issues/1253)
119119
cmake -GNinja -Bbuild_arm64 \
120120
-DCMAKE_BUILD_TYPE=Release \
121121
-DCMAKE_C_COMPILER=clang \
@@ -134,6 +134,7 @@ jobs:
134134
-DLLVM_ENABLE_ZSTD=OFF \
135135
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
136136
-DTORCH_MLIR_ENABLE_MHLO=OFF \
137+
-DTORCH_MLIR_ENABLE_LTC=OFF \
137138
-DTORCH_MLIR_USE_INSTALLED_PYTORCH="${{ matrix.torch-binary }}" \
138139
-DMACOSX_DEPLOYMENT_TARGET=12.0 \
139140
-DPython3_EXECUTABLE="$(which python)" \

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ if(TORCH_MLIR_ENABLE_MHLO)
4949
endif()
5050
endif()
5151

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

5554
if(TORCH_MLIR_ENABLE_LTC)
5655
set(ENV{TORCH_MLIR_ENABLE_LTC} 1)

build_tools/python_deploy/build_macos_packages.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export CMAKE_OSX_ARCHITECTURES="${TORCH_MLIR_OSX_ARCH:-arm64;x86_64}"
3535
echo "CMAKE_OSX_ARCHITECTURES: $CMAKE_OSX_ARCHITECTURES"
3636
echo "MACOSX_DEPLOYMENT_TARGET $MACOSX_DEPLOYMENT_TARGET"
3737

38+
# Disable LTC build on MacOS to avoid linkage issues
39+
# https://github.com/llvm/torch-mlir/issues/1253
40+
export TORCH_MLIR_ENABLE_LTC=0
41+
3842
function run() {
3943
echo "Using python versions: ${python_versions}"
4044

python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ add_mlir_python_modules(TorchMLIRPythonModules
154154
# Then it would "just work".
155155
if(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER)
156156
add_dependencies(TorchMLIRPythonModules TorchMLIRJITIRImporter)
157+
add_dependencies(TorchMLIRPythonModules TorchMLIRJITIRImporterPybind)
157158
# Build the E2E Tests (which depend on the JIT IR importer now).
158159
add_dependencies(TorchMLIRPythonModules TorchMLIRE2ETestPythonModules)
159160
endif()

python/torch_mlir/csrc/reference_lazy_backend/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if(TORCH_MLIR_ENABLE_LTC)
4242
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
4343
add_link_options(-Wl,-rpath,$ORIGIN/lib)
4444

45-
add_library(reference_lazy_backend SHARED
45+
add_library(reference_lazy_backend MODULE
4646
backend_impl.cpp
4747
reference_lazy_backend_pybind.cpp
4848
)
@@ -51,6 +51,7 @@ if(TORCH_MLIR_ENABLE_LTC)
5151
)
5252
target_link_libraries(reference_lazy_backend
5353
${TORCH_LIBRARIES}
54+
torch_python
5455
torch_mlir_ltc_backend
5556
)
5657

python/torch_mlir/dialects/torch/importer/jit_ir/csrc/CMakeLists.txt

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,68 @@ include_directories(BEFORE
1010
)
1111
link_directories("${TORCH_INSTALL_PREFIX}/lib")
1212

13-
# TODO: Currently, out-of-tree build fails when LIBRARY_TYPE is set to SHARED, so we have this toggle.
14-
# See https://github.com/llvm/torch-mlir/issues/1154 for more details.
15-
if(TORCH_MLIR_ENABLE_LTC)
16-
set(LIBRARY_TYPE "SHARED")
17-
else()
18-
set(LIBRARY_TYPE "MODULE")
19-
endif()
20-
21-
add_library(TorchMLIRJITIRImporter ${LIBRARY_TYPE}
13+
# Static library with core functionality.
14+
# We can't use a shared library here, due to issues with linking on macOS-arm64 (the library itself won't build)
15+
# For details, see: https://github.com/llvm/torch-mlir/runs/7919012376
16+
add_library(TorchMLIRJITIRImporter STATIC
2217
class_annotator.cpp
23-
class_annotator_pybind.cpp
24-
get_registered_ops.cpp
2518
function_importer.cpp
26-
module_builder.cpp
2719
node_importer.cpp
28-
import_options_pybind.cpp
2920
ivalue_importer.cpp
30-
init_python_bindings.cpp
3121
torch_to_mlir_utils.cpp
3222
)
33-
3423
target_link_libraries(TorchMLIRJITIRImporter
3524
TorchMLIRAggregateCAPI
25+
${TORCH_LIBRARIES}
26+
)
27+
message(STATUS "TORCH_CXXFLAGS=${TORCH_CXXFLAGS}")
28+
set_target_properties(TorchMLIRJITIRImporter PROPERTIES
29+
LIBRARY_OUTPUT_DIRECTORY "${TORCH_MLIR_PYTHON_PACKAGES_DIR}/torch_mlir/torch_mlir/_mlir_libs"
30+
OUTPUT_NAME lib_jit_ir_importer
31+
PREFIX ""
32+
SUFFIX ".a"
33+
CXX_VISIBILITY_PRESET "default"
34+
COMPILE_FLAGS "${TORCH_CXXFLAGS}"
35+
)
36+
37+
# Separate Pybind MODULE due to issues with a SHARED library.
38+
# https://github.com/llvm/torch-mlir/issues/1154
39+
add_library(TorchMLIRJITIRImporterPybind MODULE
40+
class_annotator_pybind.cpp
41+
get_registered_ops.cpp
42+
import_options_pybind.cpp
43+
init_python_bindings.cpp
44+
module_builder.cpp
45+
)
46+
add_dependencies(TorchMLIRJITIRImporterPybind
47+
TorchMLIRJITIRImporter
48+
)
49+
target_link_libraries(TorchMLIRJITIRImporterPybind
3650
${TORCH_LIBRARIES}
3751
torch_python
38-
)
52+
TorchMLIRJITIRImporter
53+
)
3954

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

5065
message(STATUS "TORCH_CXXFLAGS=${TORCH_CXXFLAGS}")
51-
set_target_properties(TorchMLIRJITIRImporter PROPERTIES
66+
set_target_properties(TorchMLIRJITIRImporterPybind PROPERTIES
5267
LIBRARY_OUTPUT_DIRECTORY "${TORCH_MLIR_PYTHON_PACKAGES_DIR}/torch_mlir/torch_mlir/_mlir_libs"
5368
OUTPUT_NAME _jit_ir_importer
5469
PREFIX "${PYTHON_MODULE_PREFIX}"
5570
SUFFIX "${PYTHON_MODULE_EXTENSION}"
5671
CXX_VISIBILITY_PRESET "hidden"
5772
COMPILE_FLAGS "${TORCH_CXXFLAGS}"
5873
)
59-
mlir_python_setup_extension_rpath(TorchMLIRJITIRImporter)
74+
mlir_python_setup_extension_rpath(TorchMLIRJITIRImporterPybind)
6075

61-
torch_mlir_python_target_compile_options(TorchMLIRJITIRImporter)
62-
mlir_check_all_link_libraries(TorchMLIRJITIRImporter)
76+
torch_mlir_python_target_compile_options(TorchMLIRJITIRImporterPybind)
77+
mlir_check_all_link_libraries(TorchMLIRJITIRImporterPybind)

setup.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
# prevent this script from attempting to build the directory, and will simply
2121
# use the (presumed already built) directory as-is.
2222
#
23-
# By default the lazy tensor backend is disabled and not built to avoid conflicts
24-
# with the out-of-tree build. To enable it, set the TORCH_MLIR_ENABLE_LTC
25-
# environment variable to 1.
26-
#
2723
# The package version can be set with the TORCH_MLIR_PYTHON_PACKAGE_VERSION
2824
# environment variable. For example, this can be "20220330.357" for a snapshot
2925
# release on 2022-03-30 with build number 357.
@@ -85,11 +81,8 @@ def run(self):
8581
f"-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON",
8682
f"-DCMAKE_C_VISIBILITY_PRESET=hidden",
8783
f"-DCMAKE_CXX_VISIBILITY_PRESET=hidden",
84+
f"-DTORCH_MLIR_ENABLE_LTC={'ON' if int(os.environ.get('TORCH_MLIR_ENABLE_LTC', 1)) else 'OFF'}",
8885
]
89-
# TODO: Enable LTC by default once JIT importer linkage issue is fixed (https://github.com/llvm/torch-mlir/issues/1154)
90-
enable_ltc = bool(int(os.environ.get("TORCH_MLIR_ENABLE_LTC", 0)))
91-
if not enable_ltc:
92-
cmake_args.append("-DTORCH_MLIR_ENABLE_LTC=OFF")
9386

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

0 commit comments

Comments
 (0)