Skip to content

Commit d537fd6

Browse files
committed
#2216: Provide custom fmt::formatters for various vt types
1 parent 0ed80e1 commit d537fd6

File tree

8 files changed

+155
-1
lines changed

8 files changed

+155
-1
lines changed

src/vt/handler/handler.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace vt {
7070
verbose, handler,
7171
"HandlerManager::makeHandler: is_functor={}, is_auto={}, registry_type={}, "
7272
"id={:x}, control={:x}, han={:x}, is_trace={}\n",
73-
is_functor, is_auto, registry_type, id, control, new_han, is_trace
73+
is_functor, is_auto, static_cast<int32_t>(registry_type), id, control, new_han, is_trace
7474
);
7575

7676
return new_han;

src/vt/rdma/rdma_common.h

+16
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ enum Type {
7575
Uninitialized = 3
7676
};
7777

78+
7879
static constexpr BitCountType const rdma_type_num_bits = 4;
7980
static constexpr BitCountType const rdma_sized_num_bits = 1;
8081
static constexpr BitCountType const rdma_collective_num_bits = 1;
@@ -116,6 +117,21 @@ static constexpr ByteType rdma_default_byte_size = sizeof(char);
116117

117118
}} //end namespace vt::rdma
118119

120+
template<>
121+
struct fmt::formatter<vt::rdma::Type> : fmt::formatter<std::string_view> {
122+
template <typename FormatContext>
123+
auto format(vt::rdma::Type t, FormatContext& ctx) {
124+
std::string_view name = "Unknown";
125+
switch (t) {
126+
case vt::rdma::Type::Get: name = "Get"; break;
127+
case vt::rdma::Type::Put: name = "Put"; break;
128+
case vt::rdma::Type::GetOrPut: name = "GetOrPut"; break;
129+
case vt::rdma::Type::Uninitialized: name = "Uninitialized"; break;
130+
}
131+
return formatter<std::string_view>::format(name, ctx);
132+
}
133+
};
134+
119135
#define PRINT_CHANNEL_TYPE(rdma_op_type) ( \
120136
rdma_op_type == vt::rdma::Type::Get ? "rdma::Get" : ( \
121137
rdma_op_type == vt::rdma::Type::Put ? "rdma::Put" : ( \

src/vt/termination/interval/interval.h

+23
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,27 @@ using Interval = term::interval::Interval<DomainT>;
230230

231231
} /* end namespace vt */
232232

233+
#include <fmt-vt/core.h>
234+
#include <fmt-vt/format.h>
235+
236+
namespace vt { namespace term { namespace interval {
237+
238+
template <typename DomainT, DomainT sentinel>
239+
struct Interval;
240+
241+
}}}
242+
243+
template <typename DomainT, DomainT sentinel>
244+
struct fmt::formatter<vt::term::interval::Interval<DomainT, sentinel>> : fmt::formatter<std::string> {
245+
template <typename FormatContext>
246+
auto format(const vt::term::interval::Interval<DomainT, sentinel>& interval, FormatContext& ctx) {
247+
return format_to(
248+
ctx.out(),
249+
"Interval[{}, {}]",
250+
interval.lower(),
251+
interval.upper()
252+
);
253+
}
254+
};
255+
233256
#endif /*INCLUDED_VT_TERMINATION_INTERVAL_INTERVAL_H*/

src/vt/topos/index/dense/dense_array.h

+10
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ static_assert(
157157

158158
}} // end namespace vt::index
159159

160+
161+
template <typename IndexType, vt::index::NumDimensionsType ndim>
162+
struct fmt::formatter<vt::index::DenseIndexArray<IndexType, ndim>> : fmt::formatter<std::string> {
163+
template <typename FormatContext>
164+
auto format(const vt::index::DenseIndexArray<IndexType, ndim>& idx, FormatContext& ctx) {
165+
return formatter<std::string>::format(idx.toString(), ctx);
166+
}
167+
};
168+
169+
160170
#include "vt/topos/index/dense/dense_array.impl.h"
161171

162172
#endif /*INCLUDED_VT_TOPOS_INDEX_DENSE_DENSE_ARRAY_H*/

src/vt/vrt/collection/balance/greedylb/greedylb.h

+14
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,18 @@ struct GreedyLB : LoadSamplerBaseLB {
126126

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

129+
template <>
130+
struct fmt::formatter<vt::vrt::collection::lb::DataDistStrategy> : formatter<std::string_view> {
131+
template <typename FormatContext>
132+
auto format(vt::vrt::collection::lb::DataDistStrategy c, FormatContext& ctx) {
133+
std::string_view name = "Unknown";
134+
switch (c) {
135+
case vt::vrt::collection::lb::DataDistStrategy::scatter: name = "scatter"; break;
136+
case vt::vrt::collection::lb::DataDistStrategy::bcast: name = "bcast"; break;
137+
case vt::vrt::collection::lb::DataDistStrategy::pt2pt: name = "pt2pt"; break;
138+
}
139+
return formatter<string_view>::format(name, ctx);
140+
}
141+
};
142+
129143
#endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H*/

src/vt/vrt/collection/balance/temperedlb/criterion.h

+15
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ enum struct CriterionEnum : uint8_t {
5353
ModifiedGrapevine = 1
5454
};
5555

56+
57+
5658
struct GrapevineCriterion {
5759
bool operator()(LoadType, LoadType under, LoadType obj, LoadType avg) const {
5860
return not (under + obj > avg);
@@ -91,4 +93,17 @@ struct Criterion {
9193

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

96+
template <>
97+
struct fmt::formatter<vt::vrt::collection::lb::CriterionEnum> : formatter<std::string_view> {
98+
template <typename FormatContext>
99+
auto format(vt::vrt::collection::lb::CriterionEnum c, FormatContext& ctx) {
100+
std::string_view name = "Unknown";
101+
switch (c) {
102+
case vt::vrt::collection::lb::CriterionEnum::Grapevine: name = "Grapevine"; break;
103+
case vt::vrt::collection::lb::CriterionEnum::ModifiedGrapevine: name = "ModifiedGrapevine"; break;
104+
}
105+
return formatter<string_view>::format(name, ctx);
106+
}
107+
};
108+
94109
#endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDLB_CRITERION_H*/

src/vt/vrt/collection/balance/temperedlb/tempered_enums.h

+62
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,66 @@ enum struct KnowledgeEnum : uint8_t {
167167

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

170+
// Specialize fmt::formatter for ObjectOrderEnum
171+
template <>
172+
struct fmt::formatter<vt::vrt::collection::lb::ObjectOrderEnum> : formatter<std::string_view> {
173+
template <typename FormatContext>
174+
auto format(vt::vrt::collection::lb::ObjectOrderEnum c, FormatContext& ctx) {
175+
std::string_view name = "Unknown";
176+
switch (c) {
177+
case vt::vrt::collection::lb::ObjectOrderEnum::Arbitrary: name = "Arbitrary"; break;
178+
case vt::vrt::collection::lb::ObjectOrderEnum::ElmID: name = "ElmID"; break;
179+
case vt::vrt::collection::lb::ObjectOrderEnum::FewestMigrations: name = "FewestMigrations"; break;
180+
case vt::vrt::collection::lb::ObjectOrderEnum::SmallObjects: name = "SmallObjects"; break;
181+
case vt::vrt::collection::lb::ObjectOrderEnum::LargestObjects: name = "LargestObjects"; break;
182+
}
183+
return formatter<string_view>::format(name, ctx);
184+
}
185+
};
186+
187+
// Specialize fmt::formatter for CMFTypeEnum
188+
template <>
189+
struct fmt::formatter<vt::vrt::collection::lb::CMFTypeEnum> : formatter<std::string_view> {
190+
template <typename FormatContext>
191+
auto format(vt::vrt::collection::lb::CMFTypeEnum c, FormatContext& ctx) {
192+
std::string_view name = "Unknown";
193+
switch (c) {
194+
case vt::vrt::collection::lb::CMFTypeEnum::Original: name = "Original"; break;
195+
case vt::vrt::collection::lb::CMFTypeEnum::NormByMax: name = "NormByMax"; break;
196+
case vt::vrt::collection::lb::CMFTypeEnum::NormBySelf: name = "NormBySelf"; break;
197+
case vt::vrt::collection::lb::CMFTypeEnum::NormByMaxExcludeIneligible: name = "NormByMaxExcludeIneligible"; break;
198+
}
199+
return formatter<string_view>::format(name, ctx);
200+
}
201+
};
202+
203+
// Specialize fmt::formatter for KnowledgeEnum
204+
template <>
205+
struct fmt::formatter<vt::vrt::collection::lb::KnowledgeEnum> : formatter<std::string_view> {
206+
template <typename FormatContext>
207+
auto format(vt::vrt::collection::lb::KnowledgeEnum c, FormatContext& ctx) {
208+
std::string_view name = "Unknown";
209+
switch (c) {
210+
case vt::vrt::collection::lb::KnowledgeEnum::UserDefined: name = "UserDefined"; break;
211+
case vt::vrt::collection::lb::KnowledgeEnum::Complete: name = "Complete"; break;
212+
case vt::vrt::collection::lb::KnowledgeEnum::Log: name = "Log"; break;
213+
}
214+
return formatter<string_view>::format(name, ctx);
215+
}
216+
};
217+
218+
// Specialize fmt::formatter for KnowledgeEnum
219+
template <>
220+
struct fmt::formatter<vt::vrt::collection::lb::InformTypeEnum> : formatter<std::string_view> {
221+
template <typename FormatContext>
222+
auto format(vt::vrt::collection::lb::InformTypeEnum c, FormatContext& ctx) {
223+
std::string_view name = "Unknown";
224+
switch (c) {
225+
case vt::vrt::collection::lb::InformTypeEnum::SyncInform: name = "SyncInform"; break;
226+
case vt::vrt::collection::lb::InformTypeEnum::AsyncInform: name = "AsyncInform"; break;
227+
}
228+
return formatter<string_view>::format(name, ctx);
229+
}
230+
};
231+
170232
#endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDLB_TEMPERED_ENUMS_H*/

tests/unit/lb/test_lbargs_enum_conv.nompi.cc

+14
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,17 @@ TEST_F(TestLBArgsEnumConverter, test_enum_converter_config) {
147147
}
148148

149149
}}} // end namespace vt::tests::unit
150+
151+
template <>
152+
struct fmt::formatter<vt::tests::unit::DummyEnum> : formatter<std::string_view> {
153+
template <typename FormatContext>
154+
auto format(vt::tests::unit::DummyEnum c, FormatContext& ctx) {
155+
std::string_view name = "Unknown";
156+
switch (c) {
157+
case vt::tests::unit::DummyEnum::One: name = "One"; break;
158+
case vt::tests::unit::DummyEnum::Two: name = "Two"; break;
159+
case vt::tests::unit::DummyEnum::Three: name = "Three"; break;
160+
}
161+
return formatter<string_view>::format(name, ctx);
162+
}
163+
};

0 commit comments

Comments
 (0)