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 2 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
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 @@ -169,8 +169,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