Skip to content

Commit

Permalink
#2216: Provide custom fmt::formatters for various vt types
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Dec 7, 2023
1 parent 46fdf96 commit a72520e
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/vt/handler/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>(registry_type), id, control, new_han, is_trace
);

return new_han;
Expand Down
16 changes: 16 additions & 0 deletions src/vt/rdma/rdma_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,6 +117,21 @@ static constexpr ByteType rdma_default_byte_size = sizeof(char);

}} //end namespace vt::rdma

template<>
struct fmt::formatter<vt::rdma::Type> : fmt::formatter<std::string_view> {
template <typename FormatContext>
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<std::string_view>::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" : ( \
Expand Down
23 changes: 23 additions & 0 deletions src/vt/termination/interval/interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,27 @@ using Interval = term::interval::Interval<DomainT>;

} /* end namespace vt */

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

namespace vt { namespace term { namespace interval {

template <typename DomainT, DomainT sentinel>
struct Interval;

}}}

template <typename DomainT, DomainT sentinel>
struct fmt::formatter<vt::term::interval::Interval<DomainT, sentinel>> : fmt::formatter<std::string> {
template <typename FormatContext>
auto format(const vt::term::interval::Interval<DomainT, sentinel>& interval, FormatContext& ctx) {
return format_to(
ctx.out(),
"Interval[{}, {}]",
interval.lower(),
interval.upper()
);
}
};

#endif /*INCLUDED_VT_TERMINATION_INTERVAL_INTERVAL_H*/
10 changes: 10 additions & 0 deletions src/vt/topos/index/dense/dense_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ static_assert(

}} // end namespace vt::index


template <typename IndexType, vt::index::NumDimensionsType ndim>
struct fmt::formatter<vt::index::DenseIndexArray<IndexType, ndim>> : fmt::formatter<std::string> {
template <typename FormatContext>
auto format(const vt::index::DenseIndexArray<IndexType, ndim>& idx, FormatContext& ctx) {
return formatter<std::string>::format(idx.toString(), ctx);
}
};


#include "vt/topos/index/dense/dense_array.impl.h"

#endif /*INCLUDED_VT_TOPOS_INDEX_DENSE_DENSE_ARRAY_H*/
14 changes: 14 additions & 0 deletions src/vt/vrt/collection/balance/greedylb/greedylb.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,18 @@ struct GreedyLB : LoadSamplerBaseLB {

}}}} /* end namespace vt::vrt::collection::lb */

template <>
struct fmt::formatter<vt::vrt::collection::lb::DataDistStrategy> : formatter<std::string_view> {
template <typename FormatContext>
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<string_view>::format(name, ctx);
}
};

#endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H*/
15 changes: 15 additions & 0 deletions src/vt/vrt/collection/balance/temperedlb/criterion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -91,4 +93,17 @@ struct Criterion {

}}}} /* end namespace vt::vrt::collection::lb */

template <>
struct fmt::formatter<vt::vrt::collection::lb::CriterionEnum> : formatter<std::string_view> {
template <typename FormatContext>
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<string_view>::format(name, ctx);
}
};

#endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDLB_CRITERION_H*/
62 changes: 62 additions & 0 deletions src/vt/vrt/collection/balance/temperedlb/tempered_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,66 @@ enum struct KnowledgeEnum : uint8_t {

}}}} /* end namespace vt::vrt::collection::lb */

// Specialize fmt::formatter for ObjectOrderEnum
template <>
struct fmt::formatter<vt::vrt::collection::lb::ObjectOrderEnum> : formatter<std::string_view> {
template <typename FormatContext>
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<string_view>::format(name, ctx);
}
};

// Specialize fmt::formatter for CMFTypeEnum
template <>
struct fmt::formatter<vt::vrt::collection::lb::CMFTypeEnum> : formatter<std::string_view> {
template <typename FormatContext>
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<string_view>::format(name, ctx);
}
};

// Specialize fmt::formatter for KnowledgeEnum
template <>
struct fmt::formatter<vt::vrt::collection::lb::KnowledgeEnum> : formatter<std::string_view> {
template <typename FormatContext>
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<string_view>::format(name, ctx);
}
};

// Specialize fmt::formatter for KnowledgeEnum
template <>
struct fmt::formatter<vt::vrt::collection::lb::InformTypeEnum> : formatter<std::string_view> {
template <typename FormatContext>
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<string_view>::format(name, ctx);
}
};

#endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDLB_TEMPERED_ENUMS_H*/
14 changes: 14 additions & 0 deletions tests/unit/lb/test_lbargs_enum_conv.nompi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,17 @@ TEST_F(TestLBArgsEnumConverter, test_enum_converter_config) {
}

}}} // end namespace vt::tests::unit

template <>
struct fmt::formatter<vt::tests::unit::DummyEnum> : formatter<std::string_view> {
template <typename FormatContext>
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<string_view>::format(name, ctx);
}
};

0 comments on commit a72520e

Please sign in to comment.