From 21c6d6b44cd3818afea0560636203fcf074269ba Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Tue, 28 Nov 2023 11:50:48 +0100 Subject: [PATCH] #2216: Provide custom fmt::formatters for various vt types --- src/vt/handler/handler.cc | 2 +- src/vt/rdma/rdma_common.h | 16 +++++ src/vt/termination/interval/interval.h | 23 +++++++ src/vt/topos/index/dense/dense_array.h | 10 +++ .../collection/balance/greedylb/greedylb.h | 14 +++++ .../collection/balance/temperedlb/criterion.h | 15 +++++ .../balance/temperedlb/tempered_enums.h | 62 +++++++++++++++++++ tests/unit/lb/test_lbargs_enum_conv.nompi.cc | 14 +++++ 8 files changed, 155 insertions(+), 1 deletion(-) diff --git a/src/vt/handler/handler.cc b/src/vt/handler/handler.cc index 807e8b4ebf..d026ee74fd 100644 --- a/src/vt/handler/handler.cc +++ b/src/vt/handler/handler.cc @@ -70,7 +70,7 @@ namespace vt { verbose, handler, "HandlerManager::makeHandler: is_functor={}, is_auto={}, registry_type={}, " "id={:x}, control={:x}, han={:x}, is_trace={}\n", - is_functor, is_auto, registry_type, id, control, new_han, is_trace + is_functor, is_auto, static_cast(registry_type), id, control, new_han, is_trace ); return new_han; diff --git a/src/vt/rdma/rdma_common.h b/src/vt/rdma/rdma_common.h index 9e049c075c..5c7a596bb8 100644 --- a/src/vt/rdma/rdma_common.h +++ b/src/vt/rdma/rdma_common.h @@ -75,6 +75,7 @@ enum Type { Uninitialized = 3 }; + static constexpr BitCountType const rdma_type_num_bits = 4; static constexpr BitCountType const rdma_sized_num_bits = 1; static constexpr BitCountType const rdma_collective_num_bits = 1; @@ -116,6 +117,21 @@ static constexpr ByteType rdma_default_byte_size = sizeof(char); }} //end namespace vt::rdma +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(vt::rdma::Type t, FormatContext& ctx) { + std::string_view name = "Unknown"; + switch (t) { + case vt::rdma::Type::Get: name = "Get"; break; + case vt::rdma::Type::Put: name = "Put"; break; + case vt::rdma::Type::GetOrPut: name = "GetOrPut"; break; + case vt::rdma::Type::Uninitialized: name = "Uninitialized"; break; + } + return formatter::format(name, ctx); + } +}; + #define PRINT_CHANNEL_TYPE(rdma_op_type) ( \ rdma_op_type == vt::rdma::Type::Get ? "rdma::Get" : ( \ rdma_op_type == vt::rdma::Type::Put ? "rdma::Put" : ( \ diff --git a/src/vt/termination/interval/interval.h b/src/vt/termination/interval/interval.h index 59c4ecd724..94ce573e57 100644 --- a/src/vt/termination/interval/interval.h +++ b/src/vt/termination/interval/interval.h @@ -230,4 +230,27 @@ using Interval = term::interval::Interval; } /* end namespace vt */ +#include +#include + +namespace vt { namespace term { namespace interval { + +template +struct Interval; + +}}} + +template +struct fmt::formatter> : fmt::formatter { + template + auto format(const vt::term::interval::Interval& interval, FormatContext& ctx) { + return format_to( + ctx.out(), + "Interval[{}, {}]", + interval.lower(), + interval.upper() + ); + } +}; + #endif /*INCLUDED_VT_TERMINATION_INTERVAL_INTERVAL_H*/ diff --git a/src/vt/topos/index/dense/dense_array.h b/src/vt/topos/index/dense/dense_array.h index a40a05d215..296b4dc789 100644 --- a/src/vt/topos/index/dense/dense_array.h +++ b/src/vt/topos/index/dense/dense_array.h @@ -157,6 +157,16 @@ static_assert( }} // end namespace vt::index + +template +struct fmt::formatter> : fmt::formatter { + template + auto format(const vt::index::DenseIndexArray& idx, FormatContext& ctx) { + return formatter::format(idx.toString(), ctx); + } +}; + + #include "vt/topos/index/dense/dense_array.impl.h" #endif /*INCLUDED_VT_TOPOS_INDEX_DENSE_DENSE_ARRAY_H*/ diff --git a/src/vt/vrt/collection/balance/greedylb/greedylb.h b/src/vt/vrt/collection/balance/greedylb/greedylb.h index d544826aad..21ac388e28 100644 --- a/src/vt/vrt/collection/balance/greedylb/greedylb.h +++ b/src/vt/vrt/collection/balance/greedylb/greedylb.h @@ -126,4 +126,18 @@ struct GreedyLB : LoadSamplerBaseLB { }}}} /* end namespace vt::vrt::collection::lb */ +template <> +struct fmt::formatter : formatter { + template + auto format(vt::vrt::collection::lb::DataDistStrategy c, FormatContext& ctx) { + std::string_view name = "Unknown"; + switch (c) { + case vt::vrt::collection::lb::DataDistStrategy::scatter: name = "scatter"; break; + case vt::vrt::collection::lb::DataDistStrategy::bcast: name = "bcast"; break; + case vt::vrt::collection::lb::DataDistStrategy::pt2pt: name = "pt2pt"; break; + } + return formatter::format(name, ctx); + } +}; + #endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H*/ diff --git a/src/vt/vrt/collection/balance/temperedlb/criterion.h b/src/vt/vrt/collection/balance/temperedlb/criterion.h index 70cb736fe8..e0864f51df 100644 --- a/src/vt/vrt/collection/balance/temperedlb/criterion.h +++ b/src/vt/vrt/collection/balance/temperedlb/criterion.h @@ -53,6 +53,8 @@ enum struct CriterionEnum : uint8_t { ModifiedGrapevine = 1 }; + + struct GrapevineCriterion { bool operator()(LoadType, LoadType under, LoadType obj, LoadType avg) const { return not (under + obj > avg); @@ -91,4 +93,17 @@ struct Criterion { }}}} /* end namespace vt::vrt::collection::lb */ +template <> +struct fmt::formatter : formatter { + template + auto format(vt::vrt::collection::lb::CriterionEnum c, FormatContext& ctx) { + std::string_view name = "Unknown"; + switch (c) { + case vt::vrt::collection::lb::CriterionEnum::Grapevine: name = "Grapevine"; break; + case vt::vrt::collection::lb::CriterionEnum::ModifiedGrapevine: name = "ModifiedGrapevine"; break; + } + return formatter::format(name, ctx); + } +}; + #endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDLB_CRITERION_H*/ diff --git a/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h b/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h index b56414a333..80ace17274 100644 --- a/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h +++ b/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h @@ -167,4 +167,66 @@ enum struct KnowledgeEnum : uint8_t { }}}} /* end namespace vt::vrt::collection::lb */ +// Specialize fmt::formatter for ObjectOrderEnum +template <> +struct fmt::formatter : formatter { + template + auto format(vt::vrt::collection::lb::ObjectOrderEnum c, FormatContext& ctx) { + std::string_view name = "Unknown"; + switch (c) { + case vt::vrt::collection::lb::ObjectOrderEnum::Arbitrary: name = "Arbitrary"; break; + case vt::vrt::collection::lb::ObjectOrderEnum::ElmID: name = "ElmID"; break; + case vt::vrt::collection::lb::ObjectOrderEnum::FewestMigrations: name = "FewestMigrations"; break; + case vt::vrt::collection::lb::ObjectOrderEnum::SmallObjects: name = "SmallObjects"; break; + case vt::vrt::collection::lb::ObjectOrderEnum::LargestObjects: name = "LargestObjects"; break; + } + return formatter::format(name, ctx); + } +}; + +// Specialize fmt::formatter for CMFTypeEnum +template <> +struct fmt::formatter : formatter { + template + auto format(vt::vrt::collection::lb::CMFTypeEnum c, FormatContext& ctx) { + std::string_view name = "Unknown"; + switch (c) { + case vt::vrt::collection::lb::CMFTypeEnum::Original: name = "Original"; break; + case vt::vrt::collection::lb::CMFTypeEnum::NormByMax: name = "NormByMax"; break; + case vt::vrt::collection::lb::CMFTypeEnum::NormBySelf: name = "NormBySelf"; break; + case vt::vrt::collection::lb::CMFTypeEnum::NormByMaxExcludeIneligible: name = "NormByMaxExcludeIneligible"; break; + } + return formatter::format(name, ctx); + } +}; + +// Specialize fmt::formatter for KnowledgeEnum +template <> +struct fmt::formatter : formatter { + template + auto format(vt::vrt::collection::lb::KnowledgeEnum c, FormatContext& ctx) { + std::string_view name = "Unknown"; + switch (c) { + case vt::vrt::collection::lb::KnowledgeEnum::UserDefined: name = "UserDefined"; break; + case vt::vrt::collection::lb::KnowledgeEnum::Complete: name = "Complete"; break; + case vt::vrt::collection::lb::KnowledgeEnum::Log: name = "Log"; break; + } + return formatter::format(name, ctx); + } +}; + +// Specialize fmt::formatter for KnowledgeEnum +template <> +struct fmt::formatter : formatter { + template + auto format(vt::vrt::collection::lb::InformTypeEnum c, FormatContext& ctx) { + std::string_view name = "Unknown"; + switch (c) { + case vt::vrt::collection::lb::InformTypeEnum::SyncInform: name = "SyncInform"; break; + case vt::vrt::collection::lb::InformTypeEnum::AsyncInform: name = "AsyncInform"; break; + } + return formatter::format(name, ctx); + } +}; + #endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDLB_TEMPERED_ENUMS_H*/ diff --git a/tests/unit/lb/test_lbargs_enum_conv.nompi.cc b/tests/unit/lb/test_lbargs_enum_conv.nompi.cc index a523b0a4bd..f8a9e1ed07 100644 --- a/tests/unit/lb/test_lbargs_enum_conv.nompi.cc +++ b/tests/unit/lb/test_lbargs_enum_conv.nompi.cc @@ -147,3 +147,17 @@ TEST_F(TestLBArgsEnumConverter, test_enum_converter_config) { } }}} // end namespace vt::tests::unit + +template <> +struct fmt::formatter : formatter { + template + auto format(vt::tests::unit::DummyEnum c, FormatContext& ctx) { + std::string_view name = "Unknown"; + switch (c) { + case vt::tests::unit::DummyEnum::One: name = "One"; break; + case vt::tests::unit::DummyEnum::Two: name = "Two"; break; + case vt::tests::unit::DummyEnum::Three: name = "Three"; break; + } + return formatter::format(name, ctx); + } +};