Skip to content
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

Solve PyTorch Ops compilation error in Windows #7140

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 21 additions & 5 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +31,7 @@ jobs:
windows:
permissions:
contents: write # upload
runs-on: windows-2019
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -96,6 +96,21 @@ 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 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
}

- name: Config
# Move build directory to C: https://github.com/actions/virtual-environments/issues/1341
Expand All @@ -107,7 +122,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 `
Expand All @@ -119,6 +134,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
Expand Down Expand Up @@ -202,7 +218,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 +230,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 Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
6 changes: 4 additions & 2 deletions cpp/open3d/ml/impl/continuous_conv/ContinuousConv.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ void _CConvComputeFeaturesCPU(TOut* out_features,

memset(out_features, 0, sizeof(TOut) * num_out * out_channels);

typedef Eigen::Array<TFeat, VECSIZE, Eigen::Dynamic> Matrix;
typedef Eigen::Array<TReal, VECSIZE, 3> Matrix3C;

tbb::parallel_for(
tbb::blocked_range<size_t>(0, num_out, 32),
[&](const tbb::blocked_range<size_t>& r) {
Expand All @@ -72,13 +75,12 @@ void _CConvComputeFeaturesCPU(TOut* out_features,
in_channels * spatial_filter_size, range_length);
B.setZero();

typedef Eigen::Array<TFeat, VECSIZE, Eigen::Dynamic> Matrix;
Matrix infeat(VECSIZE, in_channels);

Eigen::Array<TReal, 3, 1> offsets_(offsets[0], offsets[1],
offsets[2]);

Eigen::Array<TReal, VECSIZE, 3> inv_extents;
Matrix3C inv_extents;
if (INDIVIDUAL_EXTENT == false) {
if (ISOTROPIC_EXTENT) {
inv_extents = 1 / extents[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TFeat, VECSIZE, Eigen::Dynamic> Matrix;
typedef Eigen::Array<TReal, VECSIZE, 3> Matrix3C;

tbb::parallel_for(
tbb::blocked_range<size_t>(0, num_out, 32),
[&](const tbb::blocked_range<size_t>& r) {
Expand All @@ -74,13 +77,12 @@ void _CConvBackropFilterCPU(TOut* filter_backprop,
Eigen::Matrix<TFeat, Eigen::Dynamic, Eigen::Dynamic> C(
out_channels, range_length);

typedef Eigen::Array<TFeat, VECSIZE, Eigen::Dynamic> Matrix;
Matrix infeat(VECSIZE, in_channels);

Eigen::Array<TReal, 3, 1> offsets_(offsets[0], offsets[1],
offsets[2]);

Eigen::Array<TReal, VECSIZE, 3> inv_extents;
Matrix3C inv_extents;
if (INDIVIDUAL_EXTENT == false) {
if (ISOTROPIC_EXTENT) {
inv_extents = 1 / extents[0];
Expand Down
6 changes: 4 additions & 2 deletions cpp/open3d/ml/impl/continuous_conv/ContinuousConvTranspose.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ void _CConvTransposeComputeFeaturesCPU(

memset(out_features, 0, sizeof(TOut) * num_out * out_channels);

typedef Eigen::Array<TFeat, VECSIZE, Eigen::Dynamic> Matrix;
typedef Eigen::Array<TReal, VECSIZE, 3> Matrix3C;

tbb::parallel_for(
tbb::blocked_range<size_t>(0, num_out, 32),
[&](const tbb::blocked_range<size_t>& r) {
Expand All @@ -70,13 +73,12 @@ void _CConvTransposeComputeFeaturesCPU(
in_channels * spatial_filter_size, range_length);
B.setZero();

typedef Eigen::Array<TFeat, VECSIZE, Eigen::Dynamic> Matrix;
Matrix infeat(VECSIZE, in_channels);

Eigen::Array<TReal, 3, 1> offsets_(offsets[0], offsets[1],
offsets[2]);

Eigen::Array<TReal, VECSIZE, 3> inv_extents;
Matrix3C inv_extents;
if (INDIVIDUAL_EXTENT == false) {
if (ISOTROPIC_EXTENT) {
inv_extents = 1 / extents[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TFeat, VECSIZE, Eigen::Dynamic> Matrix;
typedef Eigen::Array<TReal, VECSIZE, 3> Matrix3C;

tbb::parallel_for(
tbb::blocked_range<size_t>(0, num_out, 32),
[&](const tbb::blocked_range<size_t>& r) {
Expand All @@ -75,13 +78,12 @@ void _CConvTransposeBackpropFilterCPU(TOut* filter_backprop,
Eigen::Matrix<TFeat, Eigen::Dynamic, Eigen::Dynamic> C(
out_channels, range_length);

typedef Eigen::Array<TFeat, VECSIZE, Eigen::Dynamic> Matrix;
Matrix infeat(VECSIZE, in_channels);

Eigen::Array<TReal, 3, 1> offsets_(offsets[0], offsets[1],
offsets[2]);

Eigen::Array<TReal, VECSIZE, 3> inv_extents;
Matrix3C inv_extents;
if (INDIVIDUAL_EXTENT == false) {
if (ISOTROPIC_EXTENT) {
inv_extents = 1 / extents[0];
Expand Down
3 changes: 2 additions & 1 deletion cpp/open3d/ml/pytorch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ set(TORCH_OPS_ARCH_DIR
"${TORCH_OPS_DIR}/$<IF:$<BOOL:${BUILD_CUDA_MODULE}>,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 "")
Expand Down
3 changes: 2 additions & 1 deletion cpp/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ endif()
# add additional optional compiled modules
if (BUILD_PYTORCH_OPS)
list( APPEND COMPILED_MODULE_PATH_LIST $<TARGET_FILE:open3d_torch_ops> )
set(DEPENDENCIES_DIR "$<TARGET_FILE_DIR:tbb>")
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"
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" --dependencies_dir "${DEPENDENCIES_DIR}"
DEPENDS open3d_torch_ops
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating python ops.py and return_types.py" )
Expand Down
10 changes: 10 additions & 0 deletions cpp/pybind/generate_torch_ops_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion python/open3d/ml/tf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion python/open3d/ml/torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
Loading