From: =?utf-8?q?Timo_R=C3=B6hling?= <roehling@debian.org>
Date: Sat, 8 Jul 2023 01:24:09 +0200
Subject: Hardcode path to open3d_torch_ops

---
 cpp/pybind/CMakeLists.txt          |  2 +-
 cpp/pybind/_build_config.py.in     |  1 +
 python/open3d/ml/torch/__init__.py | 45 +++-----------------------------------
 3 files changed, 5 insertions(+), 43 deletions(-)

diff --git a/cpp/pybind/CMakeLists.txt b/cpp/pybind/CMakeLists.txt
index 0260a43..c5adc92 100644
--- a/cpp/pybind/CMakeLists.txt
+++ b/cpp/pybind/CMakeLists.txt
@@ -165,7 +165,7 @@ endif()
 
 # add additional optional compiled modules
 if (BUILD_PYTORCH_OPS)
-    list( APPEND COMPILED_MODULE_PATH_LIST $<TARGET_FILE:open3d_torch_ops> )
+    #list( APPEND COMPILED_MODULE_PATH_LIST $<TARGET_FILE:open3d_torch_ops> )
     add_custom_command( OUTPUT "${CMAKE_BINARY_DIR}/lib/ml/torch/python/ops.py" "${CMAKE_BINARY_DIR}/lib/ml/torch/python/return_types.py"
             COMMAND ${Python3_EXECUTABLE} generate_torch_ops_wrapper.py --input_ops_py_in "${PYTHON_PACKAGE_SRC_DIR}/open3d/ml/torch/python/ops.py.in" --input_return_types_py_in "${PYTHON_PACKAGE_SRC_DIR}/open3d/ml/torch/python/return_types.py.in" --output_dir "${CMAKE_BINARY_DIR}/lib/ml/torch/python/" --lib $<TARGET_FILE:open3d_torch_ops> --tensorflow_ops_dir "${CMAKE_CURRENT_SOURCE_DIR}/../open3d/ml/tensorflow"
                         DEPENDS open3d_torch_ops
diff --git a/cpp/pybind/_build_config.py.in b/cpp/pybind/_build_config.py.in
index 6c32224..1770384 100644
--- a/cpp/pybind/_build_config.py.in
+++ b/cpp/pybind/_build_config.py.in
@@ -16,5 +16,6 @@ _build_config = {
     "CUDA_GENCODES" : "@CUDA_GENCODES@",
     "Tensorflow_VERSION" : "@Tensorflow_VERSION@",
     "Pytorch_VERSION" : "@Pytorch_VERSION@",
+    "PLUGIN_LIBDIR" : "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/libopen3d@OPEN3D_SOVERSION@",
     "WITH_OPENMP" : $<IF:$<BOOL:@WITH_OPENMP@>,True,False>
 }
diff --git a/python/open3d/ml/torch/__init__.py b/python/open3d/ml/torch/__init__.py
index 09a48b1..e3b214a 100644
--- a/python/open3d/ml/torch/__init__.py
+++ b/python/open3d/ml/torch/__init__.py
@@ -52,48 +52,9 @@ if (_build_config["BUILD_CUDA_MODULE"] and
 --------------------------------------------------------------------------------
 """)
 
-_lib_path = []
-# allow overriding the path to the op library with an env var.
-if 'OPEN3D_TORCH_OP_LIB' in _os.environ:
-    _lib_path.append(_os.environ['OPEN3D_TORCH_OP_LIB'])
-
-_this_dir = _os.path.dirname(__file__)
-_package_root = _os.path.join(_this_dir, '..', '..')
-_lib_ext = {'linux': '.so', 'darwin': '.dylib', 'win32': '.dll'}[_sys.platform]
-_lib_suffix = '_debug' if _build_config['CMAKE_BUILD_TYPE'] == 'Debug' else ''
-_lib_arch = ('cpu',)
-if _build_config["BUILD_CUDA_MODULE"] and _torch.cuda.is_available():
-    if _torch.version.cuda == _build_config["CUDA_VERSION"]:
-        _lib_arch = ('cuda', 'cpu')
-    else:
-        print("Warning: Open3D was built with CUDA {} but"
-              "PyTorch was built with CUDA {}. Falling back to CPU for now."
-              "Otherwise, install PyTorch with CUDA {}.".format(
-                  _build_config["CUDA_VERSION"], _torch.version.cuda,
-                  _build_config["CUDA_VERSION"]))
-_lib_path.extend([
-    _os.path.join(_package_root, la,
-                  'open3d_torch_ops' + _lib_suffix + _lib_ext)
-    for la in _lib_arch
-])
-
-_load_except = None
-_loaded = False
-for _lp in _lib_path:
-    try:
-        _torch.ops.load_library(_lp)
-        _torch.classes.load_library(_lp)
-        _loaded = True
-        break
-    except Exception as ex:
-        _load_except = ex
-        if not _os.path.isfile(_lp):
-            print('The op library at "{}" was not found. Make sure that '
-                  'BUILD_PYTORCH_OPS was enabled.'.format(
-                      _os.path.realpath(_lp)))
-
-if not _loaded:
-    raise _load_except
+_lp = _os.environ.get("OPEN3D_TORCH_OP_LIB", _os.path.join(_build_config["PLUGIN_LIBDIR"], "open3d_torch_ops.so"))
+_torch.ops.load_library(_lp)
+_torch.classes.load_library(_lp)
 
 from . import layers
 from . import ops
