summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSameer Sheorey <41028320+ssheorey@users.noreply.github.com>2023-02-14 09:10:27 -0800
committerGitHub <noreply@github.com>2023-02-14 09:10:27 -0800
commitab6bf430c36387a46bc7521103699a58389723ea (patch)
tree9873366b70f235374046a908357260e5d9f0e33a
parent1bfedb6c25212b795363382430b85be7172dca3b (diff)
downloadOpen3D-ab6bf430c36387a46bc7521103699a58389723ea.tar.gz
Open3D-ab6bf430c36387a46bc7521103699a58389723ea.tar.bz2
Open3D-ab6bf430c36387a46bc7521103699a58389723ea.zip
Fix build compatibility with fmtlib 8 [Author: @roehling] (#5892)
* Fix build compatibility with fmtlib >= 8 --------- Co-authored-by: Timo Röhling <timo.roehling@fkie.fraunhofer.de> Co-authored-by: Yixing Lao <yixing.lao@gmail.com>
-rw-r--r--3rdparty/find_dependencies.cmake4
-rw-r--r--3rdparty/fmt/fmt.cmake17
-rw-r--r--cpp/benchmarks/core/BinaryEW.cpp26
-rw-r--r--cpp/benchmarks/core/UnaryEW.cpp38
-rw-r--r--cpp/open3d/core/SizeVector.cpp4
-rw-r--r--cpp/open3d/io/IJsonConvertibleIO.h7
-rw-r--r--cpp/open3d/t/geometry/Image.h2
-rw-r--r--cpp/open3d/t/geometry/VtkUtils.cpp2
-rw-r--r--cpp/open3d/t/geometry/kernel/IPPImage.cpp3
-rw-r--r--cpp/open3d/t/geometry/kernel/NPPImage.cpp3
-rw-r--r--cpp/open3d/utility/IJsonConvertible.cpp2
-rw-r--r--cpp/open3d/utility/IJsonConvertible.h21
-rw-r--r--cpp/open3d/visualization/rendering/RendererHandle.h15
-rw-r--r--cpp/tests/core/CUDAUtils.cpp17
-rw-r--r--cpp/tests/core/Tensor.cpp10
-rw-r--r--cpp/tools/GLInfo.cpp3
16 files changed, 120 insertions, 54 deletions
diff --git a/3rdparty/find_dependencies.cmake b/3rdparty/find_dependencies.cmake
index c2614e47..58b450d6 100644
--- a/3rdparty/find_dependencies.cmake
+++ b/3rdparty/find_dependencies.cmake
@@ -1049,6 +1049,8 @@ endif()
# fmt
if(USE_SYSTEM_FMT)
+ # MSVC >= 17.x required for building fmt 8+
+ # SYCL / DPC++ needs fmt ver <8 or >= 9.2: https://github.com/fmtlib/fmt/issues/3005
open3d_find_package_3rdparty_library(3rdparty_fmt
PUBLIC
PACKAGE fmt
@@ -1073,7 +1075,7 @@ if(NOT USE_SYSTEM_FMT)
target_compile_definitions(3rdparty_fmt INTERFACE FMT_STRING_ALIAS=1)
list(APPEND Open3D_3RDPARTY_HEADER_TARGETS_FROM_CUSTOM Open3D::3rdparty_fmt)
else()
- list(APPEND Open3D_3RDPARTY_HEADER_TARGETS_FROM_SYSTEM Open3D::3rdparty_fmt)
+ list(APPEND Open3D_3RDPARTY_PUBLIC_TARGETS_FROM_SYSTEM Open3D::3rdparty_fmt)
endif()
# Pybind11
diff --git a/3rdparty/fmt/fmt.cmake b/3rdparty/fmt/fmt.cmake
index 4e576c86..f53e2f49 100644
--- a/3rdparty/fmt/fmt.cmake
+++ b/3rdparty/fmt/fmt.cmake
@@ -2,11 +2,24 @@ include(ExternalProject)
set(FMT_LIB_NAME fmt)
+if (MSVC AND MSVC_VERSION VERSION_LESS 1930 OR
+ CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
+ # MSVC 17.x required for building fmt >6
+ # 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")
+else()
+ set(FMT_VER "9.0.0")
+ set(FMT_SHA256
+ "9a1e0e9e843a356d65c7604e2c8bf9402b50fe294c355de0095ebd42fb9bd2c5")
+endif()
+
ExternalProject_Add(
ext_fmt
PREFIX fmt
- URL https://github.com/fmtlib/fmt/archive/refs/tags/6.0.0.tar.gz
- URL_HASH SHA256=f1907a58d5e86e6c382e51441d92ad9e23aea63827ba47fd647eacc0d3a16c78
+ URL https://github.com/fmtlib/fmt/archive/refs/tags/${FMT_VER}.tar.gz
+ URL_HASH SHA256=${FMT_SHA256}
DOWNLOAD_DIR "${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}/fmt"
UPDATE_COMMAND ""
CMAKE_ARGS
diff --git a/cpp/benchmarks/core/BinaryEW.cpp b/cpp/benchmarks/core/BinaryEW.cpp
index e077ec87..7174d4a9 100644
--- a/cpp/benchmarks/core/BinaryEW.cpp
+++ b/cpp/benchmarks/core/BinaryEW.cpp
@@ -115,7 +115,7 @@ static std::function<Tensor(const Tensor&, const Tensor&)> MakeOperation(
};
default:
- utility::LogError("Unknown operation {}", op);
+ utility::LogError("Unknown operation {}", static_cast<int>(op));
}
}
@@ -175,22 +175,22 @@ void BinaryEW(benchmark::State& state,
ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float32) \
ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float64)
-//#ifdef BUILD_CUDA_MODULE
-//#define ENUM_BM_TENSOR(FN, OP)
-// ENUM_BM_DTYPE(FN, OP, Device("CPU:0"), CPU)
-// ENUM_BM_DTYPE(FN, OP, Device("CUDA:0"), CUDA)
-//#else
+// #ifdef BUILD_CUDA_MODULE
+// #define ENUM_BM_TENSOR(FN, OP)
+// ENUM_BM_DTYPE(FN, OP, Device("CPU:0"), CPU)
+// ENUM_BM_DTYPE(FN, OP, Device("CUDA:0"), CUDA)
+// #else
#define ENUM_BM_TENSOR(FN, OP) ENUM_BM_DTYPE(FN, OP, Device("CPU:0"), CPU)
-//#endif
+// #endif
-//#ifdef BUILD_CUDA_MODULE
-//#define ENUM_BM_TENSOR_WTIH_BOOL(FN, OP)
-// ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CPU:0"), CPU)
-// ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CUDA:0"), CUDA)
-//#else
+// #ifdef BUILD_CUDA_MODULE
+// #define ENUM_BM_TENSOR_WTIH_BOOL(FN, OP)
+// ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CPU:0"), CPU)
+// ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CUDA:0"), CUDA)
+// #else
#define ENUM_BM_TENSOR_WTIH_BOOL(FN, OP) \
ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CPU:0"), CPU)
-//#endif
+// #endif
ENUM_BM_TENSOR(BinaryEW, Add)
ENUM_BM_TENSOR(BinaryEW, Sub)
diff --git a/cpp/benchmarks/core/UnaryEW.cpp b/cpp/benchmarks/core/UnaryEW.cpp
index 4cbde153..933ff027 100644
--- a/cpp/benchmarks/core/UnaryEW.cpp
+++ b/cpp/benchmarks/core/UnaryEW.cpp
@@ -101,7 +101,7 @@ std::function<Tensor(const Tensor&)> MakeOperation(UnaryOpCode op) {
return [](const Tensor& arg) -> Tensor { return arg.LogicalNot(); };
default:
- utility::LogError("Unknown operation {}", op);
+ utility::LogError("Unknown operation {}", static_cast<int>(op));
}
}
@@ -164,31 +164,31 @@ void UnaryEW(benchmark::State& state,
ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float32) \
ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float64)
-//#ifdef BUILD_CUDA_MODULE
-//#define ENUM_BM_TENSOR(FN, OP)
-// ENUM_BM_DTYPE(FN, OP, Device("CPU:0"), CPU)
-// ENUM_BM_DTYPE(FN, OP, Device("CUDA:0"), CUDA)
-//#else
+// #ifdef BUILD_CUDA_MODULE
+// #define ENUM_BM_TENSOR(FN, OP)
+// ENUM_BM_DTYPE(FN, OP, Device("CPU:0"), CPU)
+// ENUM_BM_DTYPE(FN, OP, Device("CUDA:0"), CUDA)
+// #else
#define ENUM_BM_TENSOR(FN, OP) ENUM_BM_DTYPE(FN, OP, Device("CPU:0"), CPU)
-//#endif
+// #endif
-//#ifdef BUILD_CUDA_MODULE
-//#define ENUM_BM_TENSOR_FLOAT(FN, OP)
-// ENUM_BM_DTYPE_FLOAT(FN, OP, Device("CPU:0"), CPU)
-// ENUM_BM_DTYPE_FLOAT(FN, OP, Device("CUDA:0"), CUDA)
-//#else
+// #ifdef BUILD_CUDA_MODULE
+// #define ENUM_BM_TENSOR_FLOAT(FN, OP)
+// ENUM_BM_DTYPE_FLOAT(FN, OP, Device("CPU:0"), CPU)
+// ENUM_BM_DTYPE_FLOAT(FN, OP, Device("CUDA:0"), CUDA)
+// #else
#define ENUM_BM_TENSOR_FLOAT(FN, OP) \
ENUM_BM_DTYPE_FLOAT(FN, OP, Device("CPU:0"), CPU)
-//#endif
+// #endif
-//#ifdef BUILD_CUDA_MODULE
-//#define ENUM_BM_TENSOR_WTIH_BOOL(FN, OP)
-// ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CPU:0"), CPU)
-// ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CUDA:0"), CUDA)
-//#else
+// #ifdef BUILD_CUDA_MODULE
+// #define ENUM_BM_TENSOR_WTIH_BOOL(FN, OP)
+// ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CPU:0"), CPU)
+// ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CUDA:0"), CUDA)
+// #else
#define ENUM_BM_TENSOR_WTIH_BOOL(FN, OP) \
ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CPU:0"), CPU)
-//#endif
+// #endif
ENUM_BM_TENSOR_FLOAT(UnaryEW, Sqrt)
ENUM_BM_TENSOR_FLOAT(UnaryEW, Sin)
diff --git a/cpp/open3d/core/SizeVector.cpp b/cpp/open3d/core/SizeVector.cpp
index 4a0f4283..2ea1bb17 100644
--- a/cpp/open3d/core/SizeVector.cpp
+++ b/cpp/open3d/core/SizeVector.cpp
@@ -148,7 +148,9 @@ int64_t SizeVector::GetLength() const {
}
}
-std::string SizeVector::ToString() const { return fmt::format("{}", *this); }
+std::string SizeVector::ToString() const {
+ return fmt::format("{{{}}}", fmt::join(*this, ", "));
+}
void SizeVector::AssertCompatible(const DynamicSizeVector& dsv,
const std::string msg) const {
diff --git a/cpp/open3d/io/IJsonConvertibleIO.h b/cpp/open3d/io/IJsonConvertibleIO.h
index 3b2ce618..bb6af998 100644
--- a/cpp/open3d/io/IJsonConvertibleIO.h
+++ b/cpp/open3d/io/IJsonConvertibleIO.h
@@ -76,9 +76,10 @@ bool WriteIJsonConvertibleToJSONString(std::string &json_string,
/// - enum_from_string(const std::string &str, ENUM_TYPE &e) -> void
/// for conversion between the enum and string. Invalid string values are mapped
/// to the first specified option in the macro.
-#define DECLARE_STRINGIFY_ENUM(ENUM_TYPE) \
- std::string enum_to_string(ENUM_TYPE e); \
- void enum_from_string(const std::string &str, ENUM_TYPE &e);
+#define DECLARE_STRINGIFY_ENUM(ENUM_TYPE) \
+ std::string enum_to_string(ENUM_TYPE e); \
+ void enum_from_string(const std::string &str, ENUM_TYPE &e); \
+ inline auto format_as(ENUM_TYPE e) { return enum_to_string(e); }
#define STRINGIFY_ENUM(ENUM_TYPE, ...) \
std::string enum_to_string(ENUM_TYPE e) { \
diff --git a/cpp/open3d/t/geometry/Image.h b/cpp/open3d/t/geometry/Image.h
index ec5f4e77..fafa786b 100644
--- a/cpp/open3d/t/geometry/Image.h
+++ b/cpp/open3d/t/geometry/Image.h
@@ -195,12 +195,14 @@ public:
Lanczos = 3, ///< Lanczos filter interpolation.
Super = 4 ///< Super sampling interpolation (only downsample).
};
+
/// \brief Return a new image after resizing with specified interpolation
/// type.
///
/// Downsample if sampling rate is < 1. Upsample if sampling rate > 1.
/// Aspect ratio is always preserved.
Image Resize(float sampling_rate = 0.5f,
+
InterpType interp_type = InterpType::Nearest) const;
/// \brief Return a new image after performing morphological dilation.
diff --git a/cpp/open3d/t/geometry/VtkUtils.cpp b/cpp/open3d/t/geometry/VtkUtils.cpp
index 3dfd584e..f709308e 100644
--- a/cpp/open3d/t/geometry/VtkUtils.cpp
+++ b/cpp/open3d/t/geometry/VtkUtils.cpp
@@ -405,7 +405,7 @@ vtkSmartPointer<vtkPolyData> CreateVtkPolyDataFromGeometry(
face_attr_include, face_attr_exclude);
} else {
utility::LogError("Unsupported geometry type {}",
- geometry.GetGeometryType());
+ static_cast<int>(geometry.GetGeometryType()));
}
return polydata;
diff --git a/cpp/open3d/t/geometry/kernel/IPPImage.cpp b/cpp/open3d/t/geometry/kernel/IPPImage.cpp
index 4c763f3e..e586a1b8 100644
--- a/cpp/open3d/t/geometry/kernel/IPPImage.cpp
+++ b/cpp/open3d/t/geometry/kernel/IPPImage.cpp
@@ -123,7 +123,8 @@ void Resize(const open3d::core::Tensor &src_im,
auto it = type_dict.find(interp_type);
if (it == type_dict.end()) {
- utility::LogError("Unsupported interp type {}", interp_type);
+ utility::LogError("Unsupported interp type {}",
+ static_cast<int>(interp_type));
}
try {
diff --git a/cpp/open3d/t/geometry/kernel/NPPImage.cpp b/cpp/open3d/t/geometry/kernel/NPPImage.cpp
index b2f7dce0..d5aa9d42 100644
--- a/cpp/open3d/t/geometry/kernel/NPPImage.cpp
+++ b/cpp/open3d/t/geometry/kernel/NPPImage.cpp
@@ -147,7 +147,8 @@ void Resize(const open3d::core::Tensor &src_im,
};
auto it = type_dict.find(interp_type);
if (it == type_dict.end()) {
- utility::LogError("Invalid interpolation type {}.", interp_type);
+ utility::LogError("Invalid interpolation type {}.",
+ static_cast<int>(interp_type));
}
auto dtype = src_im.GetDtype();
diff --git a/cpp/open3d/utility/IJsonConvertible.cpp b/cpp/open3d/utility/IJsonConvertible.cpp
index 2d4f98f9..4c154a5d 100644
--- a/cpp/open3d/utility/IJsonConvertible.cpp
+++ b/cpp/open3d/utility/IJsonConvertible.cpp
@@ -47,7 +47,7 @@ Json::Value StringToJson(const std::string &json_str) {
return json;
}
-std::string JsonToString(const Json::Value json) {
+std::string JsonToString(const Json::Value &json) {
return Json::writeString(Json::StreamWriterBuilder(), json);
}
diff --git a/cpp/open3d/utility/IJsonConvertible.h b/cpp/open3d/utility/IJsonConvertible.h
index f20eb603..8b3d8942 100644
--- a/cpp/open3d/utility/IJsonConvertible.h
+++ b/cpp/open3d/utility/IJsonConvertible.h
@@ -26,6 +26,8 @@
#pragma once
+#include <fmt/format.h>
+
#include <Eigen/Core>
#include "open3d/utility/Eigen.h"
@@ -50,7 +52,7 @@ Json::Value StringToJson(const std::string &json_str);
///
/// \param json The Json::Value object to be converted.
/// \return A string containing the json value.
-std::string JsonToString(const Json::Value json);
+std::string JsonToString(const Json::Value &json);
/// Class IJsonConvertible defines the behavior of a class that can convert
/// itself to/from a json::Value.
@@ -98,3 +100,20 @@ public:
} // namespace utility
} // namespace open3d
+
+namespace fmt {
+template <>
+struct formatter<Json::Value> {
+ template <typename FormatContext>
+ auto format(const Json::Value &value, FormatContext &ctx)
+ -> decltype(ctx.out()) {
+ return format_to(ctx.out(), "{}", open3d::utility::JsonToString(value));
+ }
+
+ template <typename ParseContext>
+ constexpr auto parse(ParseContext &ctx) -> decltype(ctx.begin()) {
+ return ctx.begin();
+ }
+};
+
+} // namespace fmt
diff --git a/cpp/open3d/visualization/rendering/RendererHandle.h b/cpp/open3d/visualization/rendering/RendererHandle.h
index dbf9d765..2c47cadd 100644
--- a/cpp/open3d/visualization/rendering/RendererHandle.h
+++ b/cpp/open3d/visualization/rendering/RendererHandle.h
@@ -31,6 +31,7 @@
#include <array>
#include <cstdint>
#include <functional>
+#include <type_traits>
namespace open3d {
@@ -173,12 +174,16 @@ public:
} // namespace std
namespace fmt {
-using namespace open3d::visualization;
-template <>
-struct formatter<open3d::visualization::rendering::REHandle_abstract> {
+template <typename T>
+struct formatter<
+ T,
+ std::enable_if_t<std::is_base_of<open3d::visualization::rendering::
+ REHandle_abstract,
+ T>::value,
+ char>> {
template <typename FormatContext>
auto format(const open3d::visualization::rendering::REHandle_abstract& uid,
- FormatContext& ctx) {
+ FormatContext& ctx) -> decltype(ctx.out()) {
return format_to(ctx.out(), "[{}, {}, hash: {}]",
open3d::visualization::rendering::REHandle_abstract::
TypeToString(uid.type),
@@ -186,7 +191,7 @@ struct formatter<open3d::visualization::rendering::REHandle_abstract> {
}
template <typename ParseContext>
- constexpr auto parse(ParseContext& ctx) {
+ constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
return ctx.begin();
}
};
diff --git a/cpp/tests/core/CUDAUtils.cpp b/cpp/tests/core/CUDAUtils.cpp
index f0e1a76b..443fab83 100644
--- a/cpp/tests/core/CUDAUtils.cpp
+++ b/cpp/tests/core/CUDAUtils.cpp
@@ -28,11 +28,23 @@
#include "open3d/core/CUDAUtils.h"
+#include <sstream>
#include <thread>
#include <vector>
#include "tests/Tests.h"
+// #include <fmt/std.h> // fmt version >=9, else:
+namespace {
+// Use std::ostringstream to get string representation.
+template <typename T>
+std::string to_str(T var) {
+ std::ostringstream ss;
+ ss << var;
+ return ss.str();
+}
+} // namespace
+
namespace open3d {
namespace tests {
@@ -98,7 +110,7 @@ void CheckScopedStreamMultiThreaded(const std::function<void()>& func) {
for (int i = 0; i < kThreads; ++i) {
threads.emplace_back([&kIterations, &func]() {
utility::LogDebug("Starting thread with ID {}",
- std::this_thread::get_id());
+ to_str(std::this_thread::get_id()));
for (int i = 0; i < kIterations; ++i) {
func();
}
@@ -107,7 +119,8 @@ void CheckScopedStreamMultiThreaded(const std::function<void()>& func) {
for (auto& thread : threads) {
if (thread.joinable()) {
- utility::LogDebug("Joining thread with ID {}", thread.get_id());
+ utility::LogDebug("Joining thread with ID {}",
+ to_str(thread.get_id()));
thread.join();
}
}
diff --git a/cpp/tests/core/Tensor.cpp b/cpp/tests/core/Tensor.cpp
index f2ebe471..57fc9c5a 100644
--- a/cpp/tests/core/Tensor.cpp
+++ b/cpp/tests/core/Tensor.cpp
@@ -26,6 +26,8 @@
#include "open3d/core/Tensor.h"
+#include <gmock/gmock.h>
+
#include <cmath>
#include <limits>
@@ -681,12 +683,14 @@ TEST_P(TensorPermuteDevices, ItemAssign) {
}
TEST_P(TensorPermuteDevices, ToString) {
+ using ::testing::AnyOf;
core::Device device = GetParam();
core::Tensor t;
// 0D
t = core::Tensor::Ones({}, core::Float32, device);
- EXPECT_EQ(t.ToString(/*with_suffix=*/false), R"(1.0)");
+ // IntelLLVM / fmt 6 adds 1 decimal place
+ EXPECT_THAT(t.ToString(/*with_suffix=*/false), AnyOf(R"(1)", R"(1.0)"));
t = core::Tensor::Full({}, std::numeric_limits<float>::quiet_NaN(),
core::Float32, device);
EXPECT_EQ(t.ToString(/*with_suffix=*/false), R"(nan)");
@@ -697,7 +701,9 @@ TEST_P(TensorPermuteDevices, ToString) {
// 1D float
t = core::Tensor(std::vector<float>{0, 1, 2, 3, 4}, {5}, core::Float32,
device);
- EXPECT_EQ(t.ToString(/*with_suffix=*/false), R"([0.0 1.0 2.0 3.0 4.0])");
+ // IntelLLVM / fmt 6 adds 1 decimal place
+ EXPECT_THAT(t.ToString(/*with_suffix=*/false),
+ AnyOf(R"([0 1 2 3 4])", R"([0.0 1.0 2.0 3.0 4.0])"));
// 1D int
std::vector<int32_t> vals{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
diff --git a/cpp/tools/GLInfo.cpp b/cpp/tools/GLInfo.cpp
index ccf2036e..2efe1e7b 100644
--- a/cpp/tools/GLInfo.cpp
+++ b/cpp/tools/GLInfo.cpp
@@ -85,7 +85,8 @@ void TryGLVersion(int major,
if (!r) {
utility::LogWarning("Unable to get info on {} id {:d}", name, id);
} else {
- utility::LogDebug("{}:\t{}", name, r);
+ utility::LogDebug("{}:\t{}", name,
+ reinterpret_cast<const char *>(r));
}
};
#define OPEN3D_REPORT_GL_STRING(n) reportGlStringFunc(n, #n)