Skip to content

Commit ac33bab

Browse files
Integrate LLVM at bb1f220d534b0f6d80bea36662f5188ff11c2e54
Update externals/llvm-project. Torch-MLIR's Python extension is updated to use MLIR's nanobind adaptors (PybindAdaptors.h was removed upstream).
1 parent f53b5be commit ac33bab

6 files changed

Lines changed: 37 additions & 29 deletions

File tree

externals/llvm-project

Submodule llvm-project updated 6889 files

lib/Dialect/Torch/IR/TorchOps.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,12 +2475,15 @@ void AtenUnflattenIntOp::getCanonicalizationPatterns(
24752475
"sizes must come from list construct");
24762476
if (sizeValues.size() != 2)
24772477
return failure();
2478-
int64_t dim0, dim1;
2478+
int64_t dim0 = Torch::kUnknownSize;
2479+
int64_t dim1 = Torch::kUnknownSize;
24792480
bool dim0Constant = matchPattern(sizeValues[0], m_TorchConstantInt(&dim0));
24802481
bool dim1Constant = matchPattern(sizeValues[1], m_TorchConstantInt(&dim1));
24812482
if (!dim0Constant && !dim1Constant)
24822483
return failure();
2483-
if (dim0 != 1 && dim1 != 1)
2484+
bool dim0IsOne = dim0Constant && dim0 == 1;
2485+
bool dim1IsOne = dim1Constant && dim1 == 1;
2486+
if (!dim0IsOne && !dim1IsOne)
24842487
return failure();
24852488
Value unflattenDim = op.getDim();
24862489
int64_t dimAsInt;
@@ -2491,7 +2494,7 @@ void AtenUnflattenIntOp::getCanonicalizationPatterns(
24912494
// the runtime asserts below are introduced to catch malformed unflatten ops
24922495
// possibly generated from onnx IR.
24932496
Value unsqueeze;
2494-
if (dim0 == 1) {
2497+
if (dim0IsOne) {
24952498
// unsqueeze at dim
24962499
FailureOr<Value> maybeUnsqueeze =
24972500
Torch::unsqueezeTensor(rewriter, op, self, unflattenDim);
@@ -2512,7 +2515,7 @@ void AtenUnflattenIntOp::getCanonicalizationPatterns(
25122515
rewriter, op.getLoc(), isMOneOrSameSize,
25132516
rewriter.getStringAttr("unflatten sizes must be compatible"));
25142517
}
2515-
if (dim1 == 1) {
2518+
if (dim1IsOne) {
25162519
// unsqueeze at dim + 1
25172520
Value dimPlusOne;
25182521
if (!dimWasConstant) {

projects/pt1/python/torch_mlir/csrc/jit_ir_importer/CMakeLists.txt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Separate Pybind MODULE due to issues with a SHARED library.
22
# https://github.com/llvm/torch-mlir/issues/1154
3-
add_library(TorchMLIRJITIRImporterPybind MODULE
3+
Python3_add_library(TorchMLIRJITIRImporterPybind MODULE WITH_SOABI
44
class_annotator_pybind.cpp
55
get_registered_ops.cpp
66
import_options_pybind.cpp
@@ -11,26 +11,23 @@ add_dependencies(TorchMLIRJITIRImporterPybind
1111
TorchMLIRJITIRImporter
1212
)
1313
target_link_libraries(TorchMLIRJITIRImporterPybind
14-
${TORCH_LIBRARIES}
15-
torch_python
16-
TorchMLIRJITIRImporter
14+
PRIVATE
15+
${TORCH_LIBRARIES}
16+
torch_python
17+
TorchMLIRJITIRImporter
1718
)
1819

19-
# On static Python builds, there may not be Python libraries to link against
20-
# (they will late bind at runtime from the executable). We have to condition
21-
# this because in that case it is set to NOTFOUND and CMake will consider
22-
# this an error.
23-
if(Python3_LIBRARIES)
24-
target_link_libraries(TorchMLIRJITIRImporterPybind
25-
${Python3_LIBRARIES}
26-
)
20+
# Prefer the imported target when available (handles static Python correctly).
21+
if(TARGET Python3::Module)
22+
target_link_libraries(TorchMLIRJITIRImporterPybind PRIVATE Python3::Module)
23+
elseif(Python3_LIBRARIES)
24+
# On some setups the imported target is unavailable; fall back to raw libs.
25+
target_link_libraries(TorchMLIRJITIRImporterPybind PRIVATE ${Python3_LIBRARIES})
2726
endif()
2827

2928
set_target_properties(TorchMLIRJITIRImporterPybind PROPERTIES
3029
LIBRARY_OUTPUT_DIRECTORY "${TORCH_MLIR_PYTHON_PACKAGES_DIR}/torch_mlir/torch_mlir/_mlir_libs"
3130
OUTPUT_NAME _jit_ir_importer
32-
PREFIX "${PYTHON_MODULE_PREFIX}"
33-
SUFFIX "${PYTHON_MODULE_EXTENSION}"
3431
CXX_VISIBILITY_PRESET "hidden"
3532
COMPILE_FLAGS "${TORCH_CXXFLAGS}"
3633
)

projects/pt1/python/torch_mlir/csrc/reference_lazy_backend/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,24 @@ if(TORCH_MLIR_ENABLE_LTC)
2020
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
2121
add_link_options(-Wl,-rpath,$ORIGIN/lib)
2222

23-
add_library(reference_lazy_backend MODULE
23+
Python3_add_library(reference_lazy_backend MODULE WITH_SOABI
2424
backend_impl.cpp
2525
reference_lazy_backend_pybind.cpp
2626
)
2727
add_dependencies(reference_lazy_backend
2828
torch_mlir_ltc_backend
2929
)
3030
target_link_libraries(reference_lazy_backend
31-
${TORCH_LIBRARIES}
32-
torch_python
33-
torch_mlir_ltc_backend
31+
PRIVATE
32+
${TORCH_LIBRARIES}
33+
torch_python
34+
torch_mlir_ltc_backend
3435
)
3536

3637
message(STATUS "TORCH_CXXFLAGS=${TORCH_CXXFLAGS} -Wno-pedantic")
3738
set_target_properties(reference_lazy_backend PROPERTIES
3839
LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
3940
OUTPUT_NAME ${OUTPUT_NAME}
40-
PREFIX "${PYTHON_MODULE_PREFIX}"
41-
SUFFIX "${PYTHON_MODULE_EXTENSION}"
4241
CXX_VISIBILITY_PRESET "hidden"
4342
COMPILE_FLAGS "${TORCH_CXXFLAGS} -Wno-pedantic"
4443
)

python/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,10 @@ add_mlir_python_modules(TorchMLIRPythonModules
126126
)
127127

128128
add_dependencies(TorchMLIRPythonModules torch-mlir-opt)
129+
130+
# Some optional PyTorch-extension backed modules are built outside of the
131+
# AddMLIRPython `declare_mlir_python_extension()` flow, but are still expected to
132+
# be present in the python package when enabled.
133+
if(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER)
134+
add_dependencies(TorchMLIRPythonModules TorchMLIRJITIRImporterPybind)
135+
endif()

python/TorchMLIRModule.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
#include "mlir/Bindings/Python/PybindAdaptors.h"
10+
#include <cstdint>
11+
12+
#include "mlir/Bindings/Python/NanobindAdaptors.h"
1113
#include "torch-mlir-c/Dialects.h"
1214
#include "torch-mlir-c/Registration.h"
1315

14-
namespace py = pybind11;
16+
namespace nb = nanobind;
1517

16-
PYBIND11_MODULE(_torchMlir, m) {
18+
NB_MODULE(_torchMlir, m) {
1719
torchMlirRegisterAllPasses();
1820

1921
m.doc() = "torch-mlir main python extension";
@@ -27,7 +29,7 @@ PYBIND11_MODULE(_torchMlir, m) {
2729
mlirDialectHandleLoadDialect(handle, context);
2830
}
2931
},
30-
py::arg("context"), py::arg("load") = true);
32+
nb::arg("context"), nb::arg("load") = true);
3133

3234
m.def("get_int64_max", []() { return INT64_MAX; });
3335

0 commit comments

Comments
 (0)