Skip to content

Commit

Permalink
add support to fmt-v10 (#6783)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
daizhirui committed Jun 14, 2024
1 parent 525c4e6 commit 0bdedd3
Show file tree
Hide file tree
Showing 16 changed files with 321 additions and 15 deletions.
4 changes: 3 additions & 1 deletion 3rdparty/find_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions 3rdparty/fmt/fmt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 52 additions & 0 deletions cpp/open3d/core/DLPack.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,56 @@ typedef struct DLManagedTensor {
#ifdef __cplusplus
} // DLPACK_EXTERN_C
#endif

#include <fmt/core.h>
#include <fmt/format.h>

namespace fmt {

template <>
struct formatter<DLDeviceType> {
template <typename FormatContext>
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 <typename ParseContext>
constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
return ctx.begin();
}
};

} // namespace fmt

#endif // DLPACK_DLPACK_H_
103 changes: 103 additions & 0 deletions cpp/open3d/core/linalg/LinalgHeadersCUDA.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,107 @@
#include <cublas_v2.h>
#include <cusolverDn.h>
#include <cusolver_common.h>
#include <fmt/core.h>
#include <fmt/format.h>

namespace fmt {

template <>
struct formatter<cusolverStatus_t> {
template <typename FormatContext>
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 <typename ParseContext>
constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
return ctx.begin();
}
};

} // namespace fmt

#endif
2 changes: 1 addition & 1 deletion cpp/open3d/io/IJsonConvertibleIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool WriteIJsonConvertibleToJSONString(std::string &json_string,
[&str](const std::pair<ENUM_TYPE, std::string> &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
Expand Down
35 changes: 35 additions & 0 deletions cpp/open3d/io/sensor/azure_kinect/K4aPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,38 @@ k4a_result_t k4a_transformation_depth_image_to_point_cloud(
} // namespace k4a_plugin
} // namespace io
} // namespace open3d

#include <fmt/format.h>

namespace fmt {

template <>
struct formatter<k4a_wait_result_t> {
template <typename FormatContext>
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 <typename ParseContext>
constexpr auto parse(ParseContext &ctx) -> decltype(ctx.begin()) {
return ctx.begin();
}
};

} // namespace fmt
11 changes: 10 additions & 1 deletion cpp/open3d/ml/pytorch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 41 additions & 1 deletion cpp/open3d/t/geometry/RaycastingScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,4 +1173,44 @@ uint32_t RaycastingScene::INVALID_ID() { return RTC_INVALID_GEOMETRY_ID; }

} // namespace geometry
} // namespace t
} // namespace open3d
} // namespace open3d

namespace fmt {
template <>
struct formatter<RTCError> {
template <typename FormatContext>
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<string_view>::format(name, ctx);
return format_to(ctx.out(), name);
}

template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
return ctx.begin();
}
};
} // namespace fmt
3 changes: 3 additions & 0 deletions cpp/open3d/t/io/sensor/realsense/RSBagReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#include "open3d/t/io/sensor/realsense/RSBagReader.h"

#if FMT_VERSION >= 100000
#include <fmt/std.h>
#endif
#include <json/json.h>

#include <chrono>
Expand Down
3 changes: 3 additions & 0 deletions cpp/open3d/utility/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <fmt/core.h>
#include <fmt/printf.h>
#include <fmt/ranges.h>
#if FMT_VERSION >= 100000
#include <fmt/std.h>
#endif

#define DEFAULT_IO_BUFFER_SIZE 1024

Expand Down
8 changes: 8 additions & 0 deletions cpp/open3d/utility/ParallelScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <oneapi/dpl/execution>
#include <oneapi/dpl/numeric>
#else
Expand Down
2 changes: 1 addition & 1 deletion cpp/open3d/visualization/rendering/RendererHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ using ResourcesContainer =
template <class ResourceType>
std::shared_ptr<ResourceType> MakeShared(ResourceType* pointer,
filament::Engine& engine) {
return std::move(std::shared_ptr<ResourceType>(
pointer, [&engine](ResourceType* p) { engine.destroy(p); }));
return std::shared_ptr<ResourceType>(
pointer, [&engine](ResourceType* p) { engine.destroy(p); });
}

template <class ResourceType>
Expand Down
Loading

0 comments on commit 0bdedd3

Please sign in to comment.