From ef8df4bf539d9383b56ae415c0605a01c6ac0437 Mon Sep 17 00:00:00 2001 From: "Murillo Rojas, Luis" Date: Fri, 17 Jan 2025 15:17:06 -0600 Subject: [PATCH 1/5] Solve PyTorch Ops compilation error in Windows --- cpp/open3d/ml/impl/continuous_conv/ContinuousConv.h | 6 ++++-- .../ml/impl/continuous_conv/ContinuousConvBackpropFilter.h | 6 ++++-- .../ml/impl/continuous_conv/ContinuousConvTranspose.h | 6 ++++-- .../continuous_conv/ContinuousConvTransposeBackpropFilter.h | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cpp/open3d/ml/impl/continuous_conv/ContinuousConv.h b/cpp/open3d/ml/impl/continuous_conv/ContinuousConv.h index 570cdd84730..a0f66ad9bea 100644 --- a/cpp/open3d/ml/impl/continuous_conv/ContinuousConv.h +++ b/cpp/open3d/ml/impl/continuous_conv/ContinuousConv.h @@ -59,6 +59,9 @@ void _CConvComputeFeaturesCPU(TOut* out_features, memset(out_features, 0, sizeof(TOut) * num_out * out_channels); + typedef Eigen::Array Matrix; + typedef Eigen::Array Matrix3C; + tbb::parallel_for( tbb::blocked_range(0, num_out, 32), [&](const tbb::blocked_range& r) { @@ -72,13 +75,12 @@ void _CConvComputeFeaturesCPU(TOut* out_features, in_channels * spatial_filter_size, range_length); B.setZero(); - typedef Eigen::Array Matrix; Matrix infeat(VECSIZE, in_channels); Eigen::Array offsets_(offsets[0], offsets[1], offsets[2]); - Eigen::Array inv_extents; + Matrix3C inv_extents; if (INDIVIDUAL_EXTENT == false) { if (ISOTROPIC_EXTENT) { inv_extents = 1 / extents[0]; diff --git a/cpp/open3d/ml/impl/continuous_conv/ContinuousConvBackpropFilter.h b/cpp/open3d/ml/impl/continuous_conv/ContinuousConvBackpropFilter.h index b75089cd889..42e427424a0 100644 --- a/cpp/open3d/ml/impl/continuous_conv/ContinuousConvBackpropFilter.h +++ b/cpp/open3d/ml/impl/continuous_conv/ContinuousConvBackpropFilter.h @@ -63,6 +63,9 @@ void _CConvBackropFilterCPU(TOut* filter_backprop, memset(filter_backprop, 0, sizeof(TOut) * total_filter_size); std::mutex filter_backprop_mutex; + typedef Eigen::Array Matrix; + typedef Eigen::Array Matrix3C; + tbb::parallel_for( tbb::blocked_range(0, num_out, 32), [&](const tbb::blocked_range& r) { @@ -74,13 +77,12 @@ void _CConvBackropFilterCPU(TOut* filter_backprop, Eigen::Matrix C( out_channels, range_length); - typedef Eigen::Array Matrix; Matrix infeat(VECSIZE, in_channels); Eigen::Array offsets_(offsets[0], offsets[1], offsets[2]); - Eigen::Array inv_extents; + Matrix3C inv_extents; if (INDIVIDUAL_EXTENT == false) { if (ISOTROPIC_EXTENT) { inv_extents = 1 / extents[0]; diff --git a/cpp/open3d/ml/impl/continuous_conv/ContinuousConvTranspose.h b/cpp/open3d/ml/impl/continuous_conv/ContinuousConvTranspose.h index 1a19cdc4034..2e997a747a5 100644 --- a/cpp/open3d/ml/impl/continuous_conv/ContinuousConvTranspose.h +++ b/cpp/open3d/ml/impl/continuous_conv/ContinuousConvTranspose.h @@ -61,6 +61,9 @@ void _CConvTransposeComputeFeaturesCPU( memset(out_features, 0, sizeof(TOut) * num_out * out_channels); + typedef Eigen::Array Matrix; + typedef Eigen::Array Matrix3C; + tbb::parallel_for( tbb::blocked_range(0, num_out, 32), [&](const tbb::blocked_range& r) { @@ -70,13 +73,12 @@ void _CConvTransposeComputeFeaturesCPU( in_channels * spatial_filter_size, range_length); B.setZero(); - typedef Eigen::Array Matrix; Matrix infeat(VECSIZE, in_channels); Eigen::Array offsets_(offsets[0], offsets[1], offsets[2]); - Eigen::Array inv_extents; + Matrix3C inv_extents; if (INDIVIDUAL_EXTENT == false) { if (ISOTROPIC_EXTENT) { inv_extents = 1 / extents[0]; diff --git a/cpp/open3d/ml/impl/continuous_conv/ContinuousConvTransposeBackpropFilter.h b/cpp/open3d/ml/impl/continuous_conv/ContinuousConvTransposeBackpropFilter.h index 296850f24a2..b1cb93c0949 100644 --- a/cpp/open3d/ml/impl/continuous_conv/ContinuousConvTransposeBackpropFilter.h +++ b/cpp/open3d/ml/impl/continuous_conv/ContinuousConvTransposeBackpropFilter.h @@ -64,6 +64,9 @@ void _CConvTransposeBackpropFilterCPU(TOut* filter_backprop, sizeof(TOut) * spatial_filter_size * in_channels * out_channels); std::mutex filter_backprop_mutex; + typedef Eigen::Array Matrix; + typedef Eigen::Array Matrix3C; + tbb::parallel_for( tbb::blocked_range(0, num_out, 32), [&](const tbb::blocked_range& r) { @@ -75,13 +78,12 @@ void _CConvTransposeBackpropFilterCPU(TOut* filter_backprop, Eigen::Matrix C( out_channels, range_length); - typedef Eigen::Array Matrix; Matrix infeat(VECSIZE, in_channels); Eigen::Array offsets_(offsets[0], offsets[1], offsets[2]); - Eigen::Array inv_extents; + Matrix3C inv_extents; if (INDIVIDUAL_EXTENT == false) { if (ISOTROPIC_EXTENT) { inv_extents = 1 / extents[0]; From 57ff4a24ef7cc8c48e51c31383b8b700c26319a8 Mon Sep 17 00:00:00 2001 From: "Murillo Rojas, Luis" Date: Fri, 31 Jan 2025 16:12:16 -0600 Subject: [PATCH 2/5] Fix the python package generation with pytorch ops --- cpp/open3d/ml/pytorch/CMakeLists.txt | 3 ++- cpp/pybind/CMakeLists.txt | 3 ++- cpp/pybind/generate_torch_ops_wrapper.py | 10 ++++++++++ python/open3d/ml/tf/__init__.py | 2 +- python/open3d/ml/torch/__init__.py | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cpp/open3d/ml/pytorch/CMakeLists.txt b/cpp/open3d/ml/pytorch/CMakeLists.txt index 76e40b82791..8969e7d57bd 100644 --- a/cpp/open3d/ml/pytorch/CMakeLists.txt +++ b/cpp/open3d/ml/pytorch/CMakeLists.txt @@ -123,7 +123,8 @@ set(TORCH_OPS_ARCH_DIR "${TORCH_OPS_DIR}/$,cuda,cpu>") set_target_properties(open3d_torch_ops PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TORCH_OPS_ARCH_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${TORCH_OPS_ARCH_DIR}") + ARCHIVE_OUTPUT_DIRECTORY "${TORCH_OPS_ARCH_DIR}" + RUNTIME_OUTPUT_DIRECTORY "${TORCH_OPS_ARCH_DIR}") # Do not add "lib" prefix set_target_properties(open3d_torch_ops PROPERTIES PREFIX "") diff --git a/cpp/pybind/CMakeLists.txt b/cpp/pybind/CMakeLists.txt index 6efae9a17fd..faa5a11bfbf 100644 --- a/cpp/pybind/CMakeLists.txt +++ b/cpp/pybind/CMakeLists.txt @@ -169,8 +169,9 @@ endif() # add additional optional compiled modules if (BUILD_PYTORCH_OPS) list( APPEND COMPILED_MODULE_PATH_LIST $ ) + set(DEPENDENCIES_DIR "$") 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 $ --tensorflow_ops_dir "${CMAKE_CURRENT_SOURCE_DIR}/../open3d/ml/tensorflow" + 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 $ --tensorflow_ops_dir "${CMAKE_CURRENT_SOURCE_DIR}/../open3d/ml/tensorflow" --dependencies_dir "${DEPENDENCIES_DIR}" DEPENDS open3d_torch_ops WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Generating python ops.py and return_types.py" ) diff --git a/cpp/pybind/generate_torch_ops_wrapper.py b/cpp/pybind/generate_torch_ops_wrapper.py index bda52b8fc83..fa3e948af73 100644 --- a/cpp/pybind/generate_torch_ops_wrapper.py +++ b/cpp/pybind/generate_torch_ops_wrapper.py @@ -130,12 +130,22 @@ def main(): type=str, required=True, help="This is cpp/open3d/ml/tensorflow") + parser.add_argument("--dependencies_dir", + type=str, + required=True, + help="PyTorch dependencies directory") args = parser.parse_args() print(args) + if sys.platform == "win32": + open3d_deps = os.add_dll_directory(args.dependencies_dir) + torch.ops.load_library(args.lib) + if sys.platform == "win32": + open3d_deps.close() + generated_function_strs = '' generated_namedtuple_strs = '' for schema in torch._C._jit_get_all_schemas(): diff --git a/python/open3d/ml/tf/__init__.py b/python/open3d/ml/tf/__init__.py index 86ce9dd38fa..f5069efa30f 100644 --- a/python/open3d/ml/tf/__init__.py +++ b/python/open3d/ml/tf/__init__.py @@ -11,7 +11,7 @@ from open3d import _build_config if not _build_config["Tensorflow_VERSION"]: - raise Exception('Open3D was not built with TensorFlow support!') + raise ImportError('Open3D was not built with TensorFlow support!') _o3d_tf_version = _build_config["Tensorflow_VERSION"].split('.') if _tf_version.split('.')[:2] != _o3d_tf_version[:2]: diff --git a/python/open3d/ml/torch/__init__.py b/python/open3d/ml/torch/__init__.py index 09a48b131aa..161420fbcb5 100644 --- a/python/open3d/ml/torch/__init__.py +++ b/python/open3d/ml/torch/__init__.py @@ -12,7 +12,7 @@ from open3d import _build_config if not _build_config["Pytorch_VERSION"]: - raise Exception('Open3D was not built with PyTorch support!') + raise ImportError('Open3D was not built with PyTorch support!') _o3d_torch_version = _verp(_build_config["Pytorch_VERSION"]) # Check match with PyTorch version, any patch level is OK if _verp(_torch.__version__).release[:2] != _o3d_torch_version.release[:2]: From 59d77b8cf4dff12640d44b6aa28622b197ac7490 Mon Sep 17 00:00:00 2001 From: "Murillo Rojas, Luis" Date: Wed, 12 Feb 2025 14:17:39 -0600 Subject: [PATCH 3/5] Enable pytorch in Windows CI --- .github/workflows/windows.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 04a408802d0..5d37c71b448 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -25,7 +25,7 @@ env: STOOLS_VER: "67.3.2" JEDI_VER: "0.17.2" # https://github.com/ipython/ipython/issues/12740 IDNA_VER: "2.8" # https://github.com/psf/requests/issues/5710 - CUDA_VERSION: "12.1.0" + CUDA_VERSION: "12.4.0" SRC_DIR: "D:\\a\\open3d\\open3d" BUILD_DIR: "C:\\Open3D\\build" NPROC: 2 @@ -35,7 +35,7 @@ jobs: windows: permissions: contents: write # upload - runs-on: windows-2019 + runs-on: windows-2022 strategy: fail-fast: false matrix: @@ -111,7 +111,7 @@ jobs: ${env:DEVELOPER_BUILD}="ON" } cmake --version - cmake -G "Visual Studio 16 2019" -A x64 ` + cmake -G "Visual Studio 17 2022" -A x64 ` -DDEVELOPER_BUILD="${env:DEVELOPER_BUILD}" ` -DCMAKE_SYSTEM_VERSION="10.0.19041.0" ` -DBUILD_EXAMPLES=OFF ` @@ -274,6 +274,16 @@ jobs: $ErrorActionPreference = 'Stop' python -m pip install -r python/requirements.txt python -m pip install -r python/requirements_jupyter_build.txt + + - name: Checkout Open3D-ML + uses: actions/checkout@v4 + with: + repository: isl-org/Open3D-ML + path: open3d_ml + + - name: Install PyTorch requirements + run: | + python -m pip install -r open3d_ml/requirements-torch.txt - name: Config run: | @@ -294,6 +304,7 @@ jobs: -DBUILD_LIBREALSENSE=ON ` -DBUILD_WEBRTC=ON ` -DBUILD_JUPYTER_EXTENSION=ON ` + -DBUILD_PYTORCH_OPS=ON ` ${{ env.SRC_DIR }} - name: Build Python package From 15fe3d086e01cd3b9aa7357c8e226ca5acf95dda Mon Sep 17 00:00:00 2001 From: "Murillo Rojas, Luis" Date: Fri, 14 Feb 2025 14:07:22 -0600 Subject: [PATCH 4/5] CI fixes --- .github/workflows/windows.yml | 30 +++++++++++++++++------------- CMakeLists.txt | 1 + 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index f817df85477..af9320495f9 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -96,6 +96,20 @@ jobs: uses: actions/setup-python@v5 with: python-version: 3.8 + + - name: Checkout Open3D-ML + uses: actions/checkout@v4 + with: + repository: isl-org/Open3D-ML + path: open3d_ml + + - name: Install PyTorch requirements + run: | + if (${{ matrix.BUILD_CUDA_MODULE == 'ON' }}) { + python -m pip install -r open3d_ml/requirements-torch-cuda.txt + } else { + python -m pip install -r open3d_ml/requirements-torch.txt + } - name: Config # Move build directory to C: https://github.com/actions/virtual-environments/issues/1341 @@ -119,6 +133,7 @@ jobs: -DBUILD_WEBRTC=${{ env.BUILD_WEBRTC }} ` -DBUILD_UNIT_TESTS=ON ` -DBUILD_CUDA_MODULE=${{ matrix.BUILD_CUDA_MODULE }} ` + -DBUILD_PYTORCH_OPS=ON ` ${{ env.SRC_DIR }} - name: Build @@ -202,7 +217,7 @@ jobs: $ErrorActionPreference = 'Stop' mkdir build cd build - cmake -G "Visual Studio 16 2019" -A x64 ` + cmake -G "Visual Studio 17 2022" -A x64 ` -DCMAKE_INSTALL_PREFIX="C:\Program Files\Open3D" ` -DSTATIC_WINDOWS_RUNTIME=${{ matrix.STATIC_RUNTIME }} ` .. @@ -214,7 +229,7 @@ jobs: run: | $ErrorActionPreference = 'Stop' python -m pip install -U pip==${{ env.PIP_VER }} - python -m pip install -U -c python/requirements_build.txt wheel setuptools + python -m pip install -U -r python/requirements_build.txt - name: Install Python package working-directory: ${{ env.BUILD_DIR }} run: | @@ -274,16 +289,6 @@ jobs: python -m pip install maturin==1.7.8 python -m pip install -r python/requirements.txt python -m pip install -r python/requirements_jupyter_build.txt - - - name: Checkout Open3D-ML - uses: actions/checkout@v4 - with: - repository: isl-org/Open3D-ML - path: open3d_ml - - - name: Install PyTorch requirements - run: | - python -m pip install -r open3d_ml/requirements-torch.txt - name: Config run: | @@ -304,7 +309,6 @@ jobs: -DBUILD_LIBREALSENSE=ON ` -DBUILD_WEBRTC=ON ` -DBUILD_JUPYTER_EXTENSION=ON ` - -DBUILD_PYTORCH_OPS=ON ` ${{ env.SRC_DIR }} - name: Install Open3D python build requirements diff --git a/CMakeLists.txt b/CMakeLists.txt index 354125dc01d..d8d69969794 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -395,6 +395,7 @@ if(BUILD_CUDA_MODULE) # https://forums.developer.nvidia.com/t/problems-with-latest-vs2022-update/294150/12 if (MSVC AND MSVC_VERSION VERSION_LESS_EQUAL "1949") # Set this before any CUDA checks + add_compile_definitions(_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH) set(CMAKE_CUDA_FLAGS "--allow-unsupported-compiler" CACHE STRING "Additional flags for nvcc" FORCE) message(WARNING "Using --allow-unsupported-compiler flag for nvcc with MSVC 2022. " "Set $Env:NVCC_PREPEND_FLAGS='--allow-unsupported-compiler' if nvcc still fails.") From c2e48a5ac8d54480867768c32aa8dd49af49cfee Mon Sep 17 00:00:00 2001 From: "Murillo Rojas, Luis" Date: Mon, 24 Feb 2025 10:38:10 -0600 Subject: [PATCH 5/5] Upgrade CUDA version in Windows CI --- .github/workflows/windows.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index af9320495f9..10129662fb9 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -21,7 +21,7 @@ concurrency: env: PIP_VER: "24.3.1" - CUDA_VERSION: "12.1.0" + CUDA_VERSION: "12.4.0" SRC_DIR: "D:\\a\\open3d\\open3d" BUILD_DIR: "C:\\Open3D\\build" NPROC: 2 @@ -106,7 +106,8 @@ jobs: - name: Install PyTorch requirements run: | if (${{ matrix.BUILD_CUDA_MODULE == 'ON' }}) { - python -m pip install -r open3d_ml/requirements-torch-cuda.txt + python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124 + python -m pip install tensorboard } else { python -m pip install -r open3d_ml/requirements-torch.txt }