Skip to content

Commit fde390c

Browse files
nithinsubbiahvivekkhandelwal1
authored andcommitted
Re-enable custom op support
1 parent 0af5578 commit fde390c

File tree

10 files changed

+21
-51
lines changed

10 files changed

+21
-51
lines changed

build_tools/update_shape_lib.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@ build_dir="$(realpath "${TORCH_MLIR_BUILD_DIR:-$src_dir/build}")"
1616
torch_transforms_cpp_dir="${src_dir}/lib/Dialect/Torch/Transforms"
1717
python_packages_dir="${build_dir}/tools/torch-mlir/python_packages"
1818

19+
TORCH_MLIR_EXT_PYTHONPATH="${TORCH_MLIR_EXT_PYTHONPATH:-""}"
1920
pypath="${python_packages_dir}/torch_mlir"
20-
# TODO: Re-enable once custom op support is back.
21-
#if [ ! -z ${TORCH_MLIR_EXT_PYTHONPATH} ]; then
22-
# pypath="${pypath}:${TORCH_MLIR_EXT_PYTHONPATH}"
23-
#fi
24-
#ext_module="torch_mlir._torch_mlir_custom_op_example"
25-
#if [ ! -z ${TORCH_MLIR_EXT_MODULES} ]; then
26-
# ext_module="${ext_module},${TORCH_MLIR_EXT_MODULES} "
27-
#fi
21+
if [ ! -z ${TORCH_MLIR_EXT_PYTHONPATH} ]; then
22+
pypath="${pypath}:${TORCH_MLIR_EXT_PYTHONPATH}"
23+
fi
24+
TORCH_MLIR_EXT_MODULES="${TORCH_MLIR_EXT_MODULES:-""}"
25+
if [ ! -z ${TORCH_MLIR_EXT_MODULES} ]; then
26+
ext_module="${TORCH_MLIR_EXT_MODULES} "
27+
fi
2828

2929
PYTHONPATH="${pypath}" python \
3030
-m torch_mlir.dialects.torch.importer.jit_ir.build_tools.shape_lib_gen \
31+
--pytorch_op_extensions=${ext_module} \
3132
--torch_transforms_cpp_dir="${torch_transforms_cpp_dir}"
32-
33-
# TODO: Add back to shape_lib_gen invocation once custom op support is back.
34-
# --pytorch_op_extensions=${ext_module} \

build_tools/update_torch_ods.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@ build_dir="$(realpath "${TORCH_MLIR_BUILD_DIR:-$src_dir/build}")"
1616
torch_ir_include_dir="${src_dir}/include/torch-mlir/Dialect/Torch/IR"
1717
python_packages_dir="${build_dir}/tools/torch-mlir/python_packages"
1818

19+
TORCH_MLIR_EXT_PYTHONPATH="${TORCH_MLIR_EXT_PYTHONPATH:-""}"
1920
pypath="${python_packages_dir}/torch_mlir"
20-
# TODO: Re-enable once custom op support is back.
21-
#if [ ! -z ${TORCH_MLIR_EXT_PYTHONPATH} ]; then
22-
# pypath="${pypath}:${TORCH_MLIR_EXT_PYTHONPATH}"
23-
#fi
24-
#ext_module="torch_mlir._torch_mlir_custom_op_example"
25-
#if [ ! -z ${TORCH_MLIR_EXT_MODULES} ]; then
26-
# ext_module="${ext_module},${TORCH_MLIR_EXT_MODULES}"
27-
#fi
21+
if [ ! -z ${TORCH_MLIR_EXT_PYTHONPATH} ]; then
22+
pypath="${pypath}:${TORCH_MLIR_EXT_PYTHONPATH}"
23+
fi
24+
TORCH_MLIR_EXT_MODULES="${TORCH_MLIR_EXT_MODULES:-""}"
25+
ext_module="${ext_module:-""}"
26+
if [ ! -z ${TORCH_MLIR_EXT_MODULES} ]; then
27+
ext_module="${TORCH_MLIR_EXT_MODULES}"
28+
fi
2829

2930
PYTHONPATH="${pypath}" python \
3031
-m torch_mlir.dialects.torch.importer.jit_ir.build_tools.torch_ods_gen \
3132
--torch_ir_include_dir="${torch_ir_include_dir}" \
33+
--pytorch_op_extensions="${ext_module}" \
3234
--debug_registry_dump="${torch_ir_include_dir}/JITOperatorRegistryDump.txt"
33-
34-
# TODO: Add back to torch_ods_gen invocation once custom op support is back.
35-
# --pytorch_op_extensions="${ext_module}" \

lib/Conversion/TorchToLinalg/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
add_mlir_conversion_library(TorchMLIRTorchToLinalg
2-
# TODO: Re-enable after MacOS support is fixed for the custom op extension.
3-
# CustomOpExample.cpp
42
DataMovement.cpp
53
IndirectDataMovement.cpp
64
Linear.cpp

lib/Conversion/TorchToLinalg/PopulatePatterns.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ void populateIndirectDataMovementPatternsAndLegality(
6363
void populateTensorConstructorsPatternsAndLegality(TypeConverter &typeConverter,
6464
RewritePatternSet &patterns,
6565
ConversionTarget &target);
66-
//void populateCustomOpExamplePatternsAndLegality(TypeConverter &typeConverter,
67-
// RewritePatternSet &patterns,
68-
// ConversionTarget &target);
6966

7067
} // namespace torch_to_linalg
7168
} // namespace torch

lib/Conversion/TorchToLinalg/TorchToLinalg.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class ConvertTorchToLinalg
6262

6363
RewritePatternSet patterns(context);
6464

65-
//torch_to_linalg::populateCustomOpExamplePatternsAndLegality(
66-
// typeConverter, patterns, target);
6765
torch_to_linalg::populateTensorScalarInteropPatternsAndLegality(
6866
typeConverter, patterns, target);
6967
torch_to_linalg::populateLinearPatternsAndLegality(typeConverter, patterns,

python/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ add_subdirectory(torch_mlir/eager_mode)
111111
# Required for running the update_torch_ods.sh and update_shape_lib.sh scripts.
112112
################################################################################
113113

114-
# TODO: renable once it build on macOS Intel / M1
115-
#add_subdirectory(torch_mlir/_torch_mlir_custom_op_example)
114+
# add_subdirectory(torch_mlir/_torch_mlir_custom_op_example)
116115

117116
################################################################################
118117
# Generate packages and shared library
@@ -159,9 +158,6 @@ if(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER)
159158
add_dependencies(TorchMLIRPythonModules TorchMLIRE2ETestPythonModules)
160159
endif()
161160

162-
# TODO: Add after macOS builds are fixed
163-
#add_dependencies(TorchMLIRPythonModules torch_mlir_custom_op_example)
164-
165161
if(TORCH_MLIR_ENABLE_LTC)
166162
# Add Torch-MLIR LTC backend as dependency
167163
add_dependencies(TorchMLIRPythonModules torch_mlir_ltc_backend)

python/torch_mlir/_torch_mlir_custom_op_example/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Setup PyTorch
2-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../dialects/torch/importer/jit_ir/cmake/modules")
2+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules")
33
include(TorchMLIRPyTorch)
44
TorchMLIRProbeForPyTorchInstall()
55
find_package(Torch 1.8 REQUIRED)

python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/shape_lib_gen.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,10 +1173,6 @@ def aten〇linalg_vector_norm(self: List[int], ord: float = 2, dim: Optional[Lis
11731173
dim = list(range(len(self)))
11741174
return upstream_shape_functions.mean_dim(self, dim, keepdim, dtype)
11751175

1176-
# TODO: Re-enable after MacOS support is fixed for the extension.
1177-
#def _torch_mlir_custom_op_example〇identity(t: List[int]) -> List[int]:
1178-
# return upstream_shape_functions.unary(t)
1179-
11801176
# ==============================================================================
11811177
# Shape library generator main().
11821178
# ==============================================================================

python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/torch_ods_gen.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -633,16 +633,6 @@ def emit_with_mutating_variants(key, **kwargs):
633633
"quantized::linear : (Tensor, __torch__.torch.classes.quantized.LinearPackedParamsBase, float, int) -> (Tensor)",
634634
traits=["HasValueSemantics"])
635635

636-
# ==========================================================================
637-
# `_torch_mlir_custom_op_example::` namespace.
638-
#
639-
# This is a demonstration of supporting an operation defined in a PyTorch
640-
# extension.
641-
# ==========================================================================
642-
643-
# TODO: Re-enable after MacOS support is fixed for the extension.
644-
#emit("_torch_mlir_custom_op_example::identity : (Tensor) -> (Tensor)")
645-
646636

647637
def dump_registered_ops(outfile: TextIO, registry: Registry):
648638
for _, v in sorted(registry.by_unique_key.items()):

python/torch_mlir_e2e_test/test_suite/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,3 @@ def register_all_tests():
5151
from . import return_types
5252
from . import control_flow
5353
from . import stats
54-
# TODO: Re-enable after MacOS support is fixed for the extension.
55-
#from . import custom_op_example

0 commit comments

Comments
 (0)