Skip to content
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
1 change: 1 addition & 0 deletions bmf/hmp/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions bmf/hmp/include/hmp/core/half.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ struct alignas(2) Half {

}; // Half

template<typename T>
typename std::enable_if<std::is_base_of<Half, T>::value, float>::type format_as(T t) {
return float(t);
}

// CUDA intrinsics

#if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 350)) || \
Expand Down
3 changes: 2 additions & 1 deletion bmf/hmp/include/hmp/core/tensor_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#pragma once

#include <vector>
#include <fmt/ranges.h>
#include <hmp/core/ref_ptr.h>
#include <hmp/core/buffer.h>
#include <hmp/core/scalar.h>
Expand Down Expand Up @@ -198,7 +199,7 @@ template <> struct fmt::formatter<hmp::SizeArray> {
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, ", "));
}
};
32 changes: 26 additions & 6 deletions bmf/hmp/include/hmp/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
#pragma once

#include <type_traits>

// FIXME: do not include this file in header files

#include <fmt/format.h>
Expand All @@ -28,15 +30,33 @@ template <typename T> struct hasStringfy {
static constexpr bool value = !std::is_same<ret_type, void>::value;
};

template <> struct hasStringfy<void> {
using ret_type = void;
static constexpr bool value = false;
};

} // namespace hmp

namespace fmt {

#if FMT_VERSION < 110000
template <typename T>
using buffered_context = buffer_context<T>;
#endif

template <typename T, typename Char>
struct fmt::formatter<T, Char, fmt::enable_if_t<hmp::hasStringfy<T>::value>> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) {
return ctx.begin();
struct formatter<T, Char, enable_if_t<hmp::hasStringfy<T>::value>> : formatter<basic_string_view<Char>> {
auto format(const T &c, buffered_context<Char> &ctx) const {
return formatter<basic_string_view<Char>>::format(hmp::stringfy(c), ctx);
}
};

auto format(const T &c, fmt::format_context &ctx) {
return fmt::format_to(ctx.out(), "{}", hmp::stringfy(c));
template <typename T>
struct formatter<T, std::enable_if_t<std::is_enum_v<T> && !hmp::hasStringfy<T>::value, char>> :
formatter<int> {
auto format(const T& a, format_context& ctx) const {
return formatter<int>::format((int)a, ctx);
}
};
};

} // namespace fmt
1 change: 1 addition & 0 deletions bmf/hmp/src/core/allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include <hmp/format.h>
#include <hmp/core/logging.h>
#include <hmp/core/allocator.h>
#include <hmp/core/scalar_type.h>
Expand Down
3 changes: 2 additions & 1 deletion bmf/hmp/src/core/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#include <string_view>
#include <mutex>
#include <fmt/format.h>
#include <hmp/core/logging.h>
#include <hmp/core/device.h>
#include <hmp/core/logging.h>
#include <hmp/format.h>

namespace hmp {

Expand Down
1 change: 1 addition & 0 deletions bmf/hmp/src/core/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <mutex>
#include <hmp/format.h>
#include <hmp/core/stream.h>

namespace hmp {
Expand Down
1 change: 1 addition & 0 deletions bmf/hmp/src/cuda/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include <mutex>
#include <hmp/format.h>
#include <hmp/cuda/macros.h>
#include <hmp/cuda/device.h>
#include <hmp/core/device.h>
Expand Down
Loading