From 0bdedd347a223b5434b3788aef2e79ea604dbbdf Mon Sep 17 00:00:00 2001 From: daizhirui Date: Fri, 14 Jun 2024 11:26:02 -0700 Subject: [PATCH] add support to fmt-v10 (#6783) * fix build of examples OnlineSLAMRGBD with fmt 10.2.0 * fix build with Intel-LLVM toolchains * change dependencies of fmt from 9.0.0 to 10.2.0 except Windows * change fmt from 6.0.0 to 10.2.0 for windows * fix build on Windows with CUDA enabled * fix build when BUILD_AZURE_KINECT is ON * fix build on Windows with MSVC v142 and CUDA enabled --- 3rdparty/find_dependencies.cmake | 4 +- 3rdparty/fmt/fmt.cmake | 20 ++-- CHANGELOG.md | 1 + cpp/open3d/core/DLPack.h | 52 +++++++++ cpp/open3d/core/linalg/LinalgHeadersCUDA.h | 103 ++++++++++++++++++ cpp/open3d/io/IJsonConvertibleIO.h | 2 +- cpp/open3d/io/sensor/azure_kinect/K4aPlugin.h | 35 ++++++ cpp/open3d/ml/pytorch/CMakeLists.txt | 11 +- cpp/open3d/t/geometry/RaycastingScene.cpp | 42 ++++++- .../t/io/sensor/realsense/RSBagReader.cpp | 3 + cpp/open3d/utility/Logging.h | 3 + cpp/open3d/utility/ParallelScan.h | 8 ++ .../visualization/rendering/RendererHandle.h | 2 +- .../filament/FilamentResourceManager.cpp | 4 +- .../webrtc_server/PeerConnectionManager.h | 42 +++++++ examples/cpp/OnlineSLAMUtil.h | 4 + 16 files changed, 321 insertions(+), 15 deletions(-) diff --git a/3rdparty/find_dependencies.cmake b/3rdparty/find_dependencies.cmake index d929b27728a..45555b83a84 100644 --- a/3rdparty/find_dependencies.cmake +++ b/3rdparty/find_dependencies.cmake @@ -1554,7 +1554,9 @@ if(OPEN3D_USE_ONEAPI_PACKAGES) TARGETS TBB::tbb ) list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_tbb) - + target_compile_definitions(3rdparty_tbb INTERFACE OPEN3D_USE_ONEAPI_PACKAGES=1) + target_compile_definitions(3rdparty_tbb INTERFACE _PSTL_UDR_PRESENT=0) + target_compile_definitions(3rdparty_tbb INTERFACE _PSTL_UDS_PRESENT=0) # 2. oneDPL # /opt/intel/oneapi/dpl/latest/lib/cmake/oneDPL open3d_find_package_3rdparty_library(3rdparty_onedpl diff --git a/3rdparty/fmt/fmt.cmake b/3rdparty/fmt/fmt.cmake index 88cd8e2fcef..d7698e1a645 100644 --- a/3rdparty/fmt/fmt.cmake +++ b/3rdparty/fmt/fmt.cmake @@ -2,16 +2,20 @@ include(ExternalProject) set(FMT_LIB_NAME fmt) -if (MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") - # MSVC has errors when building fmt >6, up till 9.1 - # SYCL / DPC++ needs fmt ver <=6 or >= 9.2: https://github.com/fmtlib/fmt/issues/3005 - set(FMT_VER "6.0.0") - set(FMT_SHA256 - "f1907a58d5e86e6c382e51441d92ad9e23aea63827ba47fd647eacc0d3a16c78") +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() - set(FMT_VER "9.0.0") + set(FMT_VER "10.2.1") set(FMT_SHA256 - "9a1e0e9e843a356d65c7604e2c8bf9402b50fe294c355de0095ebd42fb9bd2c5") + "1250e4cc58bf06ee631567523f48848dc4596133e163f02615c97f78bab6c811") endif() ExternalProject_Add( diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d9d4bbb575..743afd15834 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ - Fix KDTreeFlann possibly using a dangling pointer instead of internal storage and simplified its members (PR #6734) - Fix RANSAC early stop if no inliers in a specific iteration (PR #6789) - Fix segmentation fault (infinite recursion) of DetectPlanarPatches if multiple points have same coordinates (PR #6794) +- Fix build with fmt v10.2.0 (#6783) ## 0.13 diff --git a/cpp/open3d/core/DLPack.h b/cpp/open3d/core/DLPack.h index 9a0c3e57aff..1cec10a712f 100644 --- a/cpp/open3d/core/DLPack.h +++ b/cpp/open3d/core/DLPack.h @@ -188,4 +188,56 @@ typedef struct DLManagedTensor { #ifdef __cplusplus } // DLPACK_EXTERN_C #endif + +#include +#include + +namespace fmt { + +template <> +struct formatter { + template + auto format(const DLDeviceType& c, FormatContext& ctx) const + -> decltype(ctx.out()) { + const char* text = nullptr; + switch (c) { + case kDLCPU: + text = "kDLCPU"; + break; + case kDLGPU: + text = "kDLGPU"; + break; + case kDLCPUPinned: + text = "kDLCPUPinned"; + break; + case kDLOpenCL: + text = "kDLOpenCL"; + break; + case kDLVulkan: + text = "kDLVulkan"; + break; + case kDLMetal: + text = "kDLMetal"; + break; + case kDLVPI: + text = "kDLVPI"; + break; + case kDLROCM: + text = "kDLROCM"; + break; + case kDLExtDev: + text = "kDLExtDev"; + break; + } + return format_to(ctx.out(), text); + } + + template + constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } +}; + +} // namespace fmt + #endif // DLPACK_DLPACK_H_ diff --git a/cpp/open3d/core/linalg/LinalgHeadersCUDA.h b/cpp/open3d/core/linalg/LinalgHeadersCUDA.h index d34394dc813..cf1b8d635ba 100644 --- a/cpp/open3d/core/linalg/LinalgHeadersCUDA.h +++ b/cpp/open3d/core/linalg/LinalgHeadersCUDA.h @@ -16,4 +16,107 @@ #include #include #include +#include +#include + +namespace fmt { + +template <> +struct formatter { + template + auto format(const cusolverStatus_t& c, FormatContext& ctx) const + -> decltype(ctx.out()) { + const char* text = nullptr; + switch (c) { + case CUSOLVER_STATUS_SUCCESS: + text = "CUSOLVER_STATUS_SUCCESS"; + break; + case CUSOLVER_STATUS_NOT_INITIALIZED: + text = "CUSOLVER_STATUS_NOT_INITIALIZED"; + break; + case CUSOLVER_STATUS_ALLOC_FAILED: + text = "CUSOLVER_STATUS_ALLOC_FAILED"; + break; + case CUSOLVER_STATUS_INVALID_VALUE: + text = "CUSOLVER_STATUS_INVALID_VALUE"; + break; + case CUSOLVER_STATUS_ARCH_MISMATCH: + text = "CUSOLVER_STATUS_ARCH_MISMATCH"; + break; + case CUSOLVER_STATUS_MAPPING_ERROR: + text = "CUSOLVER_STATUS_MAPPING_ERROR"; + break; + case CUSOLVER_STATUS_EXECUTION_FAILED: + text = "CUSOLVER_STATUS_EXECUTION_FAILED"; + break; + case CUSOLVER_STATUS_INTERNAL_ERROR: + text = "CUSOLVER_STATUS_INTERNAL_ERROR"; + break; + case CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED: + text = "CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED"; + break; + case CUSOLVER_STATUS_NOT_SUPPORTED: + text = "CUSOLVER_STATUS_NOT_SUPPORTED"; + break; + case CUSOLVER_STATUS_ZERO_PIVOT: + text = "CUSOLVER_STATUS_ZERO_PIVOT"; + break; + case CUSOLVER_STATUS_INVALID_LICENSE: + text = "CUSOLVER_STATUS_INVALID_LICENSE"; + break; + case CUSOLVER_STATUS_IRS_PARAMS_NOT_INITIALIZED: + text = "CUSOLVER_STATUS_IRS_PARAMS_NOT_INITIALIZED"; + break; + case CUSOLVER_STATUS_IRS_PARAMS_INVALID: + text = "CUSOLVER_STATUS_IRS_PARAMS_INVALID"; + break; + case CUSOLVER_STATUS_IRS_PARAMS_INVALID_PREC: + text = "CUSOLVER_STATUS_IRS_PARAMS_INVALID_PREC"; + break; + case CUSOLVER_STATUS_IRS_PARAMS_INVALID_REFINE: + text = "CUSOLVER_STATUS_IRS_PARAMS_INVALID_REFINE"; + break; + case CUSOLVER_STATUS_IRS_PARAMS_INVALID_MAXITER: + text = "CUSOLVER_STATUS_IRS_PARAMS_INVALID_MAXITER"; + break; + case CUSOLVER_STATUS_IRS_INTERNAL_ERROR: + text = "CUSOLVER_STATUS_IRS_INTERNAL_ERROR"; + break; + case CUSOLVER_STATUS_IRS_NOT_SUPPORTED: + text = "CUSOLVER_STATUS_IRS_NOT_SUPPORTED"; + break; + case CUSOLVER_STATUS_IRS_OUT_OF_RANGE: + text = "CUSOLVER_STATUS_IRS_OUT_OF_RANGE"; + break; + case CUSOLVER_STATUS_IRS_NRHS_NOT_SUPPORTED_FOR_REFINE_GMRES: + text = "CUSOLVER_STATUS_IRS_NRHS_NOT_SUPPORTED_FOR_REFINE_" + "GMRES"; + break; + case CUSOLVER_STATUS_IRS_INFOS_NOT_INITIALIZED: + text = "CUSOLVER_STATUS_IRS_INFOS_NOT_INITIALIZED"; + break; + case CUSOLVER_STATUS_IRS_INFOS_NOT_DESTROYED: + text = "CUSOLVER_STATUS_IRS_INFOS_NOT_DESTROYED"; + break; + case CUSOLVER_STATUS_IRS_MATRIX_SINGULAR: + text = "CUSOLVER_STATUS_IRS_MATRIX_SINGULAR"; + break; + case CUSOLVER_STATUS_INVALID_WORKSPACE: + text = "CUSOLVER_STATUS_INVALID_WORKSPACE"; + break; + default: + text = "CUSOLVER_STATUS_UNKNOWN"; + break; + } + return format_to(ctx.out(), text); + } + + template + constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } +}; + +} // namespace fmt + #endif diff --git a/cpp/open3d/io/IJsonConvertibleIO.h b/cpp/open3d/io/IJsonConvertibleIO.h index 8bc9f03b13b..a366b4f5ef8 100644 --- a/cpp/open3d/io/IJsonConvertibleIO.h +++ b/cpp/open3d/io/IJsonConvertibleIO.h @@ -82,7 +82,7 @@ bool WriteIJsonConvertibleToJSONString(std::string &json_string, [&str](const std::pair &es_pair) \ -> bool { return es_pair.second == str; }); \ e = ((it != std::end(m)) ? it : std::begin(m))->first; \ - utility::LogDebug("{} -> {}", str, e); \ + utility::LogDebug("{} -> {}", str, enum_to_string(e)); \ } } // namespace io diff --git a/cpp/open3d/io/sensor/azure_kinect/K4aPlugin.h b/cpp/open3d/io/sensor/azure_kinect/K4aPlugin.h index cd9a6eb1db1..15e461d4285 100644 --- a/cpp/open3d/io/sensor/azure_kinect/K4aPlugin.h +++ b/cpp/open3d/io/sensor/azure_kinect/K4aPlugin.h @@ -295,3 +295,38 @@ k4a_result_t k4a_transformation_depth_image_to_point_cloud( } // namespace k4a_plugin } // namespace io } // namespace open3d + +#include + +namespace fmt { + +template <> +struct formatter { + template + auto format(const k4a_wait_result_t &c, FormatContext &ctx) const + -> decltype(ctx.out()) { + const char *text = nullptr; + switch (c) { + case K4A_WAIT_RESULT_SUCCEEDED: + text = "K4A_WAIT_RESULT_SUCCEEDED"; + break; + case K4A_WAIT_RESULT_FAILED: + text = "K4A_WAIT_RESULT_FAILED"; + break; + case K4A_WAIT_RESULT_TIMEOUT: + text = "K4A_WAIT_RESULT_TIMEOUT"; + break; + default: + text = "Unknown k4a_wait_result_t"; + break; + } + return format_to(ctx.out(), text); + } + + template + constexpr auto parse(ParseContext &ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } +}; + +} // namespace fmt diff --git a/cpp/open3d/ml/pytorch/CMakeLists.txt b/cpp/open3d/ml/pytorch/CMakeLists.txt index adc9ac48e3d..3cb75e531de 100644 --- a/cpp/open3d/ml/pytorch/CMakeLists.txt +++ b/cpp/open3d/ml/pytorch/CMakeLists.txt @@ -140,9 +140,18 @@ target_link_libraries(open3d_torch_ops PRIVATE Open3D::3rdparty_eigen3 Open3D::3rdparty_fmt Open3D::3rdparty_nanoflann - Open3D::3rdparty_parallelstl Open3D::3rdparty_tbb ) +if (TARGET Open3D::3rdparty_parallelstl) + target_link_libraries(open3d_torch_ops PRIVATE + Open3D::3rdparty_parallelstl + ) +endif() +if (TARGET Open3D::3rdparty_onedpl) + target_link_libraries(open3d_torch_ops PRIVATE + Open3D::3rdparty_onedpl + ) +endif() if (BUILD_CUDA_MODULE) target_link_libraries(open3d_torch_ops PRIVATE diff --git a/cpp/open3d/t/geometry/RaycastingScene.cpp b/cpp/open3d/t/geometry/RaycastingScene.cpp index 14f9962c26c..8906f6373e5 100644 --- a/cpp/open3d/t/geometry/RaycastingScene.cpp +++ b/cpp/open3d/t/geometry/RaycastingScene.cpp @@ -1173,4 +1173,44 @@ uint32_t RaycastingScene::INVALID_ID() { return RTC_INVALID_GEOMETRY_ID; } } // namespace geometry } // namespace t -} // namespace open3d \ No newline at end of file +} // namespace open3d + +namespace fmt { +template <> +struct formatter { + template + auto format(const RTCError& c, FormatContext& ctx) { + const char* name = nullptr; + switch (c) { + case RTC_ERROR_NONE: + name = "RTC_ERROR_NONE"; + break; + case RTC_ERROR_UNKNOWN: + name = "RTC_ERROR_UNKNOWN"; + break; + case RTC_ERROR_INVALID_ARGUMENT: + name = "RTC_ERROR_INVALID_ARGUMENT"; + break; + case RTC_ERROR_INVALID_OPERATION: + name = "RTC_ERROR_INVALID_OPERATION"; + break; + case RTC_ERROR_OUT_OF_MEMORY: + name = "RTC_ERROR_OUT_OF_MEMORY"; + break; + case RTC_ERROR_UNSUPPORTED_CPU: + name = "RTC_ERROR_UNSUPPORTED_CPU"; + break; + case RTC_ERROR_CANCELLED: + name = "RTC_ERROR_CANCELLED"; + break; + } + // return formatter::format(name, ctx); + return format_to(ctx.out(), name); + } + + template + constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } +}; +} // namespace fmt diff --git a/cpp/open3d/t/io/sensor/realsense/RSBagReader.cpp b/cpp/open3d/t/io/sensor/realsense/RSBagReader.cpp index 356fdbed6bc..1bb6dd76081 100644 --- a/cpp/open3d/t/io/sensor/realsense/RSBagReader.cpp +++ b/cpp/open3d/t/io/sensor/realsense/RSBagReader.cpp @@ -7,6 +7,9 @@ #include "open3d/t/io/sensor/realsense/RSBagReader.h" +#if FMT_VERSION >= 100000 +#include +#endif #include #include diff --git a/cpp/open3d/utility/Logging.h b/cpp/open3d/utility/Logging.h index 15fe28fa539..fdb132f9b06 100644 --- a/cpp/open3d/utility/Logging.h +++ b/cpp/open3d/utility/Logging.h @@ -21,6 +21,9 @@ #include #include #include +#if FMT_VERSION >= 100000 +#include +#endif #define DEFAULT_IO_BUFFER_SIZE 1024 diff --git a/cpp/open3d/utility/ParallelScan.h b/cpp/open3d/utility/ParallelScan.h index a98015053f8..0479d611eb5 100644 --- a/cpp/open3d/utility/ParallelScan.h +++ b/cpp/open3d/utility/ParallelScan.h @@ -13,6 +13,14 @@ // clang-format off #if TBB_INTERFACE_VERSION >= 10000 #ifdef OPEN3D_USE_ONEAPI_PACKAGES + #ifdef _PSTL_UDR_PRESENT + #undef _PSTL_UDR_PRESENT + #endif + #define _PSTL_UDR_PRESENT 0 + #ifdef _PSTL_UDS_PRESENT + #undef _PSTL_UDS_PRESENT + #endif + #define _PSTL_UDS_PRESENT 0 #include #include #else diff --git a/cpp/open3d/visualization/rendering/RendererHandle.h b/cpp/open3d/visualization/rendering/RendererHandle.h index 45b59a70c60..dc8b06382e7 100644 --- a/cpp/open3d/visualization/rendering/RendererHandle.h +++ b/cpp/open3d/visualization/rendering/RendererHandle.h @@ -98,7 +98,7 @@ struct REHandle : public REHandle_abstract { id = REHandle_abstract::kBadId + 1; } - return std::move(REHandle(id)); + return REHandle(id); } static REHandle Concretize(const REHandle_abstract& abstract) { diff --git a/cpp/open3d/visualization/rendering/filament/FilamentResourceManager.cpp b/cpp/open3d/visualization/rendering/filament/FilamentResourceManager.cpp index 0c831e9d2d0..1dcf1715368 100644 --- a/cpp/open3d/visualization/rendering/filament/FilamentResourceManager.cpp +++ b/cpp/open3d/visualization/rendering/filament/FilamentResourceManager.cpp @@ -77,8 +77,8 @@ using ResourcesContainer = template std::shared_ptr MakeShared(ResourceType* pointer, filament::Engine& engine) { - return std::move(std::shared_ptr( - pointer, [&engine](ResourceType* p) { engine.destroy(p); })); + return std::shared_ptr( + pointer, [&engine](ResourceType* p) { engine.destroy(p); }); } template diff --git a/cpp/open3d/visualization/webrtc_server/PeerConnectionManager.h b/cpp/open3d/visualization/webrtc_server/PeerConnectionManager.h index ceb0fc9df74..8ef27e79a54 100644 --- a/cpp/open3d/visualization/webrtc_server/PeerConnectionManager.h +++ b/cpp/open3d/visualization/webrtc_server/PeerConnectionManager.h @@ -456,3 +456,45 @@ class PeerConnectionManager { } // namespace webrtc_server } // namespace visualization } // namespace open3d + +namespace fmt { + +template <> +struct formatter { + template + auto format(const webrtc::PeerConnectionInterface::SignalingState& state, + FormatContext& ctx) const -> decltype(ctx.out()) { + using namespace webrtc; + const char* text = nullptr; + switch (state) { + case PeerConnectionInterface::SignalingState::kStable: + text = "kStable"; + break; + case PeerConnectionInterface::SignalingState::kHaveLocalOffer: + text = "kHaveLocalOffer"; + break; + case PeerConnectionInterface::SignalingState::kHaveLocalPrAnswer: + text = "kHaveLocalPrAnswer"; + break; + case PeerConnectionInterface::SignalingState::kHaveRemoteOffer: + text = "kHaveRemoteOffer"; + break; + case PeerConnectionInterface::SignalingState::kHaveRemotePrAnswer: + text = "kHaveRemotePrAnswer"; + break; + case PeerConnectionInterface::SignalingState::kClosed: + text = "kClosed"; + break; + default: + text = "unknown"; + } + return format_to(ctx.out(), "{}", text); + } + + template + constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } +}; + +} // namespace fmt diff --git a/examples/cpp/OnlineSLAMUtil.h b/examples/cpp/OnlineSLAMUtil.h index 585f18a8fbe..358256de3df 100644 --- a/examples/cpp/OnlineSLAMUtil.h +++ b/examples/cpp/OnlineSLAMUtil.h @@ -5,6 +5,10 @@ // SPDX-License-Identifier: MIT // ---------------------------------------------------------------------------- +#if FMT_VERSION >= 100000 +#include +#endif + #include #include #include