From aae71242a1db8940148d9e79b662ef191146bd0a Mon Sep 17 00:00:00 2001 From: Armstrong Date: Tue, 11 Mar 2025 19:34:03 +0800 Subject: [PATCH 1/3] add fmt v10 and v11 support 1. make custom formatter const 2. make default enum formatter for non-stringfy type 3. fmt::join is moved to 4. some source files are not properly include the enum formatter --- bmf/hmp/include/hmp/core/half.h | 5 ++++ bmf/hmp/include/hmp/core/tensor_info.h | 3 ++- bmf/hmp/include/hmp/format.h | 32 +++++++++++++++++++++----- bmf/hmp/src/core/allocator.cpp | 1 + bmf/hmp/src/core/device.cpp | 3 ++- bmf/hmp/src/core/stream.cpp | 1 + 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/bmf/hmp/include/hmp/core/half.h b/bmf/hmp/include/hmp/core/half.h index 95a5fb0d..b16c9eef 100644 --- a/bmf/hmp/include/hmp/core/half.h +++ b/bmf/hmp/include/hmp/core/half.h @@ -72,6 +72,11 @@ struct alignas(2) Half { }; // Half +template +typename std::enable_if::value, float>::type format_as(T t) { + return float(t); +} + // CUDA intrinsics #if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 350)) || \ diff --git a/bmf/hmp/include/hmp/core/tensor_info.h b/bmf/hmp/include/hmp/core/tensor_info.h index 938fd66d..815b33a5 100644 --- a/bmf/hmp/include/hmp/core/tensor_info.h +++ b/bmf/hmp/include/hmp/core/tensor_info.h @@ -16,6 +16,7 @@ #pragma once #include +#include #include #include #include @@ -198,7 +199,7 @@ template <> struct fmt::formatter { return ctx.begin(); } - auto format(hmp::SizeArray c, fmt::format_context &ctx) { + auto format(hmp::SizeArray c, fmt::format_context &ctx) const { return fmt::format_to(ctx.out(), "({})", fmt::join(c, ", ")); } }; diff --git a/bmf/hmp/include/hmp/format.h b/bmf/hmp/include/hmp/format.h index 3fbd59af..157cea64 100644 --- a/bmf/hmp/include/hmp/format.h +++ b/bmf/hmp/include/hmp/format.h @@ -15,6 +15,8 @@ */ #pragma once +#include + // FIXME: do not include this file in header files #include @@ -28,15 +30,33 @@ template struct hasStringfy { static constexpr bool value = !std::is_same::value; }; +template <> struct hasStringfy { + using ret_type = void; + static constexpr bool value = false; +}; + } // namespace hmp +namespace fmt { + +#if FMT_VERSION < 110000 +template +using buffered_context = buffer_context; +#endif + template -struct fmt::formatter::value>> { - template constexpr auto parse(ParseContext &ctx) { - return ctx.begin(); +struct formatter::value>> : formatter> { + auto format(const T &c, buffered_context &ctx) const { + return formatter>::format(hmp::stringfy(c), ctx); } +}; - auto format(const T &c, fmt::format_context &ctx) { - return fmt::format_to(ctx.out(), "{}", hmp::stringfy(c)); +template +struct formatter && !hmp::hasStringfy::value, char>> : + formatter { + auto format(const T& a, format_context& ctx) const { + return formatter::format((int)a, ctx); } -}; \ No newline at end of file +}; + +} // namespace fmt \ No newline at end of file diff --git a/bmf/hmp/src/core/allocator.cpp b/bmf/hmp/src/core/allocator.cpp index 1f0db795..11f82651 100644 --- a/bmf/hmp/src/core/allocator.cpp +++ b/bmf/hmp/src/core/allocator.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include diff --git a/bmf/hmp/src/core/device.cpp b/bmf/hmp/src/core/device.cpp index 3eab3c45..d6571539 100644 --- a/bmf/hmp/src/core/device.cpp +++ b/bmf/hmp/src/core/device.cpp @@ -17,8 +17,9 @@ #include #include #include -#include #include +#include +#include namespace hmp { diff --git a/bmf/hmp/src/core/stream.cpp b/bmf/hmp/src/core/stream.cpp index cd74fed5..8e1d86a0 100644 --- a/bmf/hmp/src/core/stream.cpp +++ b/bmf/hmp/src/core/stream.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ #include +#include #include namespace hmp { From 2e8bb75b17d12d885aad32b054fde56462185ad6 Mon Sep 17 00:00:00 2001 From: ArmstrongCN Date: Fri, 11 Apr 2025 09:43:55 +0800 Subject: [PATCH 2/3] fix cudaError_enum fmt --- bmf/hmp/src/cuda/device.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bmf/hmp/src/cuda/device.cpp b/bmf/hmp/src/cuda/device.cpp index 3296b95f..d5f3c1c7 100644 --- a/bmf/hmp/src/cuda/device.cpp +++ b/bmf/hmp/src/cuda/device.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include #include From 469e428e81dff1f9afb17bb1825ce236f319772a Mon Sep 17 00:00:00 2001 From: ArmstrongCN Date: Sat, 19 Apr 2025 11:06:32 +0800 Subject: [PATCH 3/3] ignore the fmt bundled with spdlog --- bmf/hmp/cmake/dependencies.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/bmf/hmp/cmake/dependencies.cmake b/bmf/hmp/cmake/dependencies.cmake index eda97385..202faa6f 100644 --- a/bmf/hmp/cmake/dependencies.cmake +++ b/bmf/hmp/cmake/dependencies.cmake @@ -81,6 +81,7 @@ endif() #### spdlog if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Android|iOS" AND NOT EMSCRIPTEN) if (HMP_LOCAL_DEPENDENCIES) + set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "SPDLOG_FMT_EXTERNAL" FORCE) FetchContent_Declare( spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git