Skip to content

Solve PyTorch Ops compilation error in Windows #7140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 59 additions & 46 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# FIXME:
# - MSVC 17 and CUDA 12.4+ error while building CreateCUDAHashBackend.cu
# - PyTorch Ops in debug mode - DLL initialization error while loading open3d_torch_ops.dll

name: Windows
permissions: {}

Expand All @@ -21,17 +25,17 @@ 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
NPROC: 6
DEVELOPER_BUILD: ${{ github.event.inputs.developer_build || 'ON' }}

jobs:
windows:
permissions:
contents: write # upload
runs-on: windows-2019
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
Expand All @@ -46,16 +50,12 @@ jobs:
- BUILD_CUDA_MODULE: ON
env:
BUILD_WEBRTC: ${{ ( matrix.BUILD_SHARED_LIBS == 'OFF' && matrix.STATIC_RUNTIME == 'ON' ) && 'ON' || 'OFF' }}
BUILD_PYTORCH_OPS: ${{ ( matrix.BUILD_CUDA_MODULE == 'ON' || matrix.CONFIG == 'Debug' ) && 'OFF' || 'ON' }}

steps:
- name: Disk space used
run: Get-PSDrive

- name: Setup Windows SDK
uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
with:
sdk-version: 19041


- name: Install CUDA
if: ${{ matrix.BUILD_CUDA_MODULE == 'ON' }}
run: |
Expand All @@ -73,7 +73,7 @@ jobs:
# Installer arguments
$CUDA_INSTALL_ARGS = "-s"
# Required packages
$CUDA_PACKAGES = "nvcc", "visual_studio_integration", "cublas", "cublas_dev", "cudart", "cusolver", "cusolver_dev", "npp", "npp_dev", "thrust"
$CUDA_PACKAGES = "nvcc", "visual_studio_integration", "cublas", "cublas_dev", "cudart", "cusolver", "cusolver_dev", "cusparse", "cusparse_dev", "npp", "npp_dev", "nvtx", "thrust"
$CUDA_PACKAGES.ForEach({ $CUDA_INSTALL_ARGS += " $($_)_$($CUDA_VER)" })
# Download and install CUDA
echo "Downloading CUDA installer from $CUDA_URL"
Expand All @@ -85,9 +85,9 @@ jobs:
}
# Add CUDA environment variables.
$CUDA_PATH = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v$CUDA_VER"
echo "CUDA_PATH=$CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "CUDA_PATH_V$CUDA_VER_ID=$CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "$CUDA_PATH\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "CUDA_PATH=$CUDA_PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "CUDA_PATH_V$CUDA_VER_ID=$CUDA_PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "$CUDA_PATH\bin" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf8 -Append

- name: Checkout source code
uses: actions/checkout@v4
Expand All @@ -96,29 +96,44 @@ 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 }}' -eq 'ON' ) {
# python -m pip install -r open3d_ml/requirements-torch-cuda.txt
python -m pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124
} 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
run: |
$ErrorActionPreference = 'Stop'
New-Item -Path ${{ env.BUILD_DIR }} -ItemType Directory
cd ${{ env.BUILD_DIR }}
if (${env:DEVELOPER_BUILD} -ne "OFF") {
${env:DEVELOPER_BUILD}="ON"
New-Item -Path '${{ env.BUILD_DIR }}' -ItemType Directory
cd '${{ env.BUILD_DIR }}'
if ($Env:DEVELOPER_BUILD -ne "OFF") {
$Env:DEVELOPER_BUILD = "ON"
}
cmake --version
cmake -G "Visual Studio 16 2019" -A x64 `
-DDEVELOPER_BUILD="${env:DEVELOPER_BUILD}" `
-DCMAKE_SYSTEM_VERSION="10.0.19041.0" `
cmake -G "Visual Studio 17 2022" -A x64 `
-DDEVELOPER_BUILD=$Env:DEVELOPER_BUILD `
-DBUILD_EXAMPLES=OFF `
-DCMAKE_INSTALL_PREFIX="C:\Program Files\Open3D" `
-DBUILD_SHARED_LIBS=${{ matrix.BUILD_SHARED_LIBS }} `
-DSTATIC_WINDOWS_RUNTIME=${{ matrix.STATIC_RUNTIME }} `
-DBUILD_COMMON_ISPC_ISAS=ON `
-DBUILD_LIBREALSENSE=ON `
-DBUILD_LIBREALSENSE=OFF `
-DBUILD_WEBRTC=${{ env.BUILD_WEBRTC }} `
-DBUILD_UNIT_TESTS=ON `
-DBUILD_CUDA_MODULE=${{ matrix.BUILD_CUDA_MODULE }} `
-DBUILD_PYTORCH_OPS=${{ env.BUILD_PYTORCH_OPS }} `
${{ env.SRC_DIR }}

- name: Build
Expand All @@ -143,7 +158,7 @@ jobs:
}
$DEVEL_PKG_NAME=(Get-ChildItem package/open3d-devel-*.zip).Name
echo "DEVEL_PKG_NAME=$DEVEL_PKG_NAME" | Out-File -FilePath `
$env:GITHUB_ENV -Encoding utf8 -Append
$Env:GITHUB_ENV -Encoding utf8 -Append

- name: Upload Package
if: ${{ matrix.BUILD_SHARED_LIBS == 'ON' && matrix.BUILD_CUDA_MODULE == 'OFF' }}
Expand Down Expand Up @@ -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 }} `
..
Expand All @@ -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: |
Expand All @@ -233,7 +248,7 @@ jobs:
name: Build wheel
permissions:
contents: write # upload
runs-on: windows-2019
runs-on: windows-2022
strategy:
fail-fast: false
# https://github.community/t/how-to-conditionally-include-exclude-items-in-matrix-eg-based-on-branch/16853/6
Expand All @@ -254,12 +269,13 @@ jobs:
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Setup Windows SDK
uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
- name: Checkout Open3D-ML
uses: actions/checkout@v4
with:
sdk-version: 19041

repository: isl-org/Open3D-ML
path: open3d_ml

- name: Set up Python
uses: actions/setup-python@v5
with:
Expand All @@ -269,47 +285,44 @@ jobs:
working-directory: ${{ env.SRC_DIR }}
run: |
$ErrorActionPreference = 'Stop'
python -m pip install -U pip==${{ env.PIP_VER }}
# maturin>1.7.8 breaks dependency y-py (Python 3.12) and pywinpty (Python 3.8) wheel building
# https://github.com/MichaIng/DietPi/issues/7329#issuecomment-2565130837
python -m pip install maturin==1.7.8
python -m pip install -r python/requirements.txt
python -m pip install -U -c python/requirements_build.txt wheel setuptools
python -m pip install -r python/requirements_jupyter_build.txt
python -m pip install -r open3d_ml/requirements-torch.txt


- name: Config
run: |
$ErrorActionPreference = 'Stop'
New-Item -Path ${{ env.BUILD_DIR }} -ItemType Directory
cd ${{ env.BUILD_DIR }}
if (${env:DEVELOPER_BUILD} -ne "OFF") {
${env:DEVELOPER_BUILD}="ON"
if ($Env:DEVELOPER_BUILD -ne "OFF") {
$Env:DEVELOPER_BUILD = "ON"
}
cmake -G "Visual Studio 16 2019" -A x64 `
cmake -G "Visual Studio 17 2022" -A x64 `
-DCMAKE_INSTALL_PREFIX="C:\Program Files\Open3D" `
-DDEVELOPER_BUILD="${env:DEVELOPER_BUILD}" `
-DCMAKE_SYSTEM_VERSION="10.0.19041.0" `
-DDEVELOPER_BUILD="$Env:DEVELOPER_BUILD" `
-DBUILD_SHARED_LIBS=OFF `
-DSTATIC_WINDOWS_RUNTIME=ON `
-DBUILD_COMMON_ISPC_ISAS=ON `
-DBUILD_AZURE_KINECT=ON `
-DBUILD_LIBREALSENSE=ON `
-DBUILD_LIBREALSENSE=OFF `
-DBUILD_WEBRTC=ON `
-DBUILD_JUPYTER_EXTENSION=ON `
-DBUILD_PYTORCH_OPS=ON `
${{ env.SRC_DIR }}

- name: Install Open3D python build requirements
working-directory: ${{ env.SOURCE_DIR }}
run: |
$ErrorActionPreference = 'Stop'
python -m pip install -U pip==${{ env.PIP_VER }}
python -m pip install -U -c python/requirements_build.txt wheel setuptools

- name: Build Python package
working-directory: ${{ env.BUILD_DIR }}
run: |
$ErrorActionPreference = 'Stop'
cmake --build . --parallel ${{ env.NPROC }} --config Release --target pip-package
$PIP_PKG_NAME=(Get-ChildItem lib/python_package/pip_package/open3d*.whl).Name
echo "PIP_PKG_NAME=$PIP_PKG_NAME" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "PIP_PKG_NAME=$PIP_PKG_NAME" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append

- name: Upload wheel
uses: actions/upload-artifact@v4
Expand All @@ -330,7 +343,7 @@ jobs:
name: Test wheel
permissions:
contents: read
runs-on: windows-2019
runs-on: windows-2022
needs: [build-wheel]
strategy:
fail-fast: false
Expand Down Expand Up @@ -391,5 +404,5 @@ jobs:
echo "Running Open3D python tests..."
echo "Add --randomly-seed=SEED to the test command to reproduce test order."
echo "Testing ML and ML Ops disabled"
python -m pytest python/test/ --ignore python/test/ml_ops/
python -m pytest python/test/
deactivate
8 changes: 6 additions & 2 deletions 3rdparty/cmake/FindPytorch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ if(NOT Pytorch_FOUND)
# remove flags that nvcc does not understand
get_target_property( iface_compile_options torch INTERFACE_COMPILE_OPTIONS )
set_target_properties( torch PROPERTIES INTERFACE_COMPILE_OPTIONS "" )
set_target_properties( torch_cuda PROPERTIES INTERFACE_COMPILE_OPTIONS "" )
set_target_properties( torch_cpu PROPERTIES INTERFACE_COMPILE_OPTIONS "" )
if (TARGET torch_cuda)
set_target_properties( torch_cuda PROPERTIES INTERFACE_COMPILE_OPTIONS "" )
endif()
if (TARGET torch_cpu)
set_target_properties( torch_cpu PROPERTIES INTERFACE_COMPILE_OPTIONS "" )
endif()
endif()

# If MKL is installed in the system level (e.g. for oneAPI Toolkit),
Expand Down
4 changes: 1 addition & 3 deletions 3rdparty/find_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ if(USE_SYSTEM_ASSIMP)
open3d_find_package_3rdparty_library(3rdparty_assimp
PACKAGE assimp
TARGETS assimp::assimp
DEPENDS ext_zlib
)
if(NOT 3rdparty_assimp_FOUND)
set(USE_SYSTEM_ASSIMP OFF)
Expand Down Expand Up @@ -956,7 +955,6 @@ if(NOT USE_SYSTEM_PNG)
LIBRARIES ${LIBPNG_LIBRARIES}
DEPENDS ext_libpng
)
add_dependencies(ext_libpng ext_zlib)
target_link_libraries(3rdparty_png INTERFACE Open3D::3rdparty_zlib)
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM Open3D::3rdparty_png)
else()
Expand Down Expand Up @@ -1759,7 +1757,7 @@ if(BUILD_CUDA_MODULE)
# ship the CUDA toolkit with the wheel (e.g. PyTorch can make use of the
# cudatoolkit conda package), or have a mechanism to locate the CUDA
# toolkit from the system.
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM CUDA::cusolver CUDA::cublas)
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM CUDA::cudart CUDA::cusolver CUDA::cublas)
else()
# CMake docs : https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html
# cusolver 11.0: https://docs.nvidia.com/cuda/archive/11.0/cusolver/index.html#static-link-lapack
Expand Down
18 changes: 5 additions & 13 deletions 3rdparty/fmt/fmt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@ include(ExternalProject)

set(FMT_LIB_NAME fmt)

if (MSVC AND BUILD_CUDA_MODULE)
if (MSVC_VERSION GREATER_EQUAL 1930) # v143
set(FMT_VER "10.1.1")
set(FMT_SHA256
"78b8c0a72b1c35e4443a7e308df52498252d1cefc2b08c9a97bc9ee6cfe61f8b")
else()
set(FMT_VER "6.0.0")
set(FMT_SHA256
"f1907a58d5e86e6c382e51441d92ad9e23aea63827ba47fd647eacc0d3a16c78")
endif()
else()
if (WIN32 AND BUILD_CUDA_MODULE)
set(FMT_VER "10.1.1")
set(FMT_SHA256 "78b8c0a72b1c35e4443a7e308df52498252d1cefc2b08c9a97bc9ee6cfe61f8b")
else ()
set(FMT_VER "10.2.1")
set(FMT_SHA256
"1250e4cc58bf06ee631567523f48848dc4596133e163f02615c97f78bab6c811")
set(FMT_SHA256 "1250e4cc58bf06ee631567523f48848dc4596133e163f02615c97f78bab6c811")
endif()

ExternalProject_Add(
Expand Down
3 changes: 2 additions & 1 deletion 3rdparty/libpng/libpng.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ ExternalProject_Add(
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DPNG_SHARED=OFF
-DPNG_EXECUTABLES=OFF
-DPNG_TOOLS=OFF
-DPNG_TESTS=OFF
-DZLIB_ROOT=${CMAKE_BINARY_DIR}/zlib
-DPNG_ARM_NEON=off # Must be lower case.
${ExternalProject_CMAKE_ARGS_hidden}
DEPENDS ext_zlib
BUILD_BYPRODUCTS
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${LIBPNG_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${LIBPNG_LIB_NAME}d${CMAKE_STATIC_LIBRARY_SUFFIX}
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,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.")
Expand Down Expand Up @@ -479,6 +480,9 @@ endif()

# OS specific settings
if(WIN32)
# Set oldest supported Windows version to Windows 10 (10.0, 0x0A00)
# https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170
add_compile_definitions(WINVER=0x0A00 _WIN32_WINNT=0x0A00)
# Windows defaults to hidden symbol visibility, override that
# TODO: It would be better to explicitly export symbols.
# Then, we could use -fvisibility=hidden for Linux as well
Expand Down
1 change: 0 additions & 1 deletion cmake/Open3DSetGlobalProperties.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ function(open3d_set_global_properties target)
endif()
if(WIN32)
target_compile_definitions(${target} PRIVATE
WINDOWS
_CRT_SECURE_NO_DEPRECATE
_CRT_NONSTDC_NO_DEPRECATE
_SCL_SECURE_NO_WARNINGS
Expand Down
1 change: 1 addition & 0 deletions cmake/Open3DShowAndAbortOnWarning.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function(open3d_show_and_abort_on_warning target)
/wd4267 # conversion from size_t to smaller type (FixedRadiusSearchCUDA, tests)
/wd4305 # conversion to smaller type in initialization or constructor argument (examples, tests)
/wd4819 # suppress vs2019+ compiler build error C2220 (Windows)
/wd4996 # torch_ops with CUDA. Deprecated type will be removed in future versions
)
set(DISABLE_GNU_CLANG_INTEL_WARNINGS
-Wno-unused-parameter # (many places in Open3D code)
Expand Down
6 changes: 1 addition & 5 deletions cpp/open3d/ml/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
#include <cuda.h>
#include <cuda_runtime.h>

// TODO: Disable fmt() macro defined in fmt<7.0.0.
// TODO: Remove this line once Open3D upgrades its fmt dependency.
#define FMT_STRING_ALIAS 0

#include "open3d/core/CUDAUtils.h"
#include "open3d/utility/Logging.h"

Expand Down Expand Up @@ -49,7 +45,7 @@ inline void __OPEN3D_ML_CUDA_DRIVER_CHECK(CUresult err,
}
}

inline cudaStream_t GetDefaultStream() { (cudaStream_t)0; }
inline cudaStream_t GetDefaultStream() { return (cudaStream_t)0; }

inline int GetDevice(cudaStream_t stream) {
if (stream == GetDefaultStream()) {
Expand Down
Loading
Loading