Skip to content

Commit 1cf022b

Browse files
authored
Merge pull request #144 from grnydawn/ykim/omega/logging
fixed a bug in logging for Kokkos data types
2 parents b5e42b0 + 31e5036 commit 1cf022b

File tree

2 files changed

+79
-24
lines changed

2 files changed

+79
-24
lines changed

components/omega/src/infra/LogFormatters.h

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,48 @@
1313
#include <spdlog/spdlog.h>
1414

1515
#ifdef OMEGA_DEBUG
16-
#define GENERATE_FORMATTER(D, T) \
16+
#define GENERATE_FORMATTER(ARR, DIM, TYPE) \
1717
template <> \
18-
struct fmt::formatter<OMEGA::Array##D##T> : fmt::formatter<std::string> { \
19-
auto format(OMEGA::Array##D##T my, \
18+
struct fmt::formatter<OMEGA::ARR##DIM##TYPE> \
19+
: fmt::formatter<std::string> { \
20+
auto format(OMEGA::ARR##DIM##TYPE my, \
2021
format_context &ctx) -> decltype(ctx.out()) { \
2122
return fmt::format_to(ctx.out(), "{}({}D:{})", my.label(), my.rank(), \
2223
my.size()); \
2324
} \
2425
};
2526
#else
26-
#define GENERATE_FORMATTER(D, T) \
27-
template <> \
28-
struct fmt::formatter<OMEGA::Array##D##T> : fmt::formatter<std::string> { \
29-
auto format(OMEGA::Array##D##T my, \
30-
format_context &ctx) -> decltype(ctx.out()) { \
31-
return fmt::format_to(ctx.out(), "{}", my.label()); \
32-
} \
27+
#define GENERATE_FORMATTER(ARR, DIM, TYPE) \
28+
template <> \
29+
struct fmt::formatter<OMEGA::ARR##DIM##TYPE> \
30+
: fmt::formatter<std::string> { \
31+
auto format(OMEGA::ARR##DIM##TYPE my, \
32+
format_context &ctx) -> decltype(ctx.out()) { \
33+
return fmt::format_to(ctx.out(), "{}", my.label()); \
34+
} \
3335
};
3436
#endif
3537

36-
#define GENERATE_FORMATTER_DIM(D) \
37-
GENERATE_FORMATTER(D, I4) \
38-
GENERATE_FORMATTER(D, I8) \
39-
GENERATE_FORMATTER(D, R4) \
40-
GENERATE_FORMATTER(D, R8)
38+
#define GENERATE_FORMATTER_DIM(ARR, DIM) \
39+
GENERATE_FORMATTER(ARR, DIM, I4) \
40+
GENERATE_FORMATTER(ARR, DIM, I8) \
41+
GENERATE_FORMATTER(ARR, DIM, R4) \
42+
GENERATE_FORMATTER(ARR, DIM, R8)
4143

42-
GENERATE_FORMATTER_DIM(1D)
43-
GENERATE_FORMATTER_DIM(2D)
44-
GENERATE_FORMATTER_DIM(3D)
45-
GENERATE_FORMATTER_DIM(4D)
46-
GENERATE_FORMATTER_DIM(5D)
44+
#define GENERATE_FORMATTER_ARR(ARR) \
45+
GENERATE_FORMATTER_DIM(ARR, 1D) \
46+
GENERATE_FORMATTER_DIM(ARR, 2D) \
47+
GENERATE_FORMATTER_DIM(ARR, 3D) \
48+
GENERATE_FORMATTER_DIM(ARR, 4D) \
49+
GENERATE_FORMATTER_DIM(ARR, 5D)
4750

51+
GENERATE_FORMATTER_ARR(HostArray)
52+
53+
#ifdef OMEGA_TARGET_DEVICE
54+
GENERATE_FORMATTER_ARR(Array)
55+
#endif
56+
57+
#undef GENERATE_FORMATTER_ARR
4858
#undef GENERATE_FORMATTER_DIM
4959
#undef GENERATE_FORMATTER
5060

components/omega/test/infra/LoggingTest.cpp

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ int testKokkosDataTypes(bool LogEnabled) {
141141

142142
Kokkos::initialize();
143143
{
144-
HostArray1DReal test1d("test1d", d1);
145-
HostArray2DReal test2d("test2d", d1, d2);
144+
Array1DReal test1d("test1dD", d1);
145+
Array2DReal test2d("test2dD", d1, d2);
146146

147147
TestRun = true;
148148

@@ -164,7 +164,7 @@ int testKokkosDataTypes(bool LogEnabled) {
164164

165165
// check if HostArray1DReal is detected
166166
if (LogEnabled && TestRun)
167-
RetVal += outputTestResult("Kokkos data type 1", "test1d", Contains);
167+
RetVal += outputTestResult("Kokkos data type 1", "test1dD", Contains);
168168

169169
TestRun = true;
170170

@@ -186,7 +186,52 @@ int testKokkosDataTypes(bool LogEnabled) {
186186

187187
// check if HostArray2DReal is detected
188188
if (LogEnabled && TestRun)
189-
RetVal += outputTestResult("Kokkos data type 2", "test2d", Contains);
189+
RetVal += outputTestResult("Kokkos data type 2", "test2dD", Contains);
190+
191+
HostArray1DReal test1dH("test1dH", d1);
192+
HostArray2DReal test2dH("test2dH", d1, d2);
193+
194+
if (OMEGA_LOG_LEVEL == 0) {
195+
LOG_INFO("1d var {}", test1dH);
196+
} else if (OMEGA_LOG_LEVEL == 1) {
197+
LOG_DEBUG("1d var {}", test1dH);
198+
} else if (OMEGA_LOG_LEVEL == 2) {
199+
LOG_INFO("1d var {}", test1dH);
200+
} else if (OMEGA_LOG_LEVEL == 3) {
201+
LOG_WARN("1d var {}", test1dH);
202+
} else if (OMEGA_LOG_LEVEL == 4) {
203+
LOG_ERROR("1d var {}", test1dH);
204+
} else if (OMEGA_LOG_LEVEL == 5) {
205+
LOG_CRITICAL("1d var {}", test1dH);
206+
} else {
207+
TestRun = false; // off
208+
}
209+
210+
// check if HostArray1DReal is detected
211+
if (LogEnabled && TestRun)
212+
RetVal += outputTestResult("Kokkos data type 1", "test1dH", Contains);
213+
214+
TestRun = true;
215+
216+
if (OMEGA_LOG_LEVEL == 0) {
217+
LOG_INFO("2d var {}", test2dH);
218+
} else if (OMEGA_LOG_LEVEL == 1) {
219+
LOG_DEBUG("2d var {}", test2dH);
220+
} else if (OMEGA_LOG_LEVEL == 2) {
221+
LOG_INFO("2d var {}", test2dH);
222+
} else if (OMEGA_LOG_LEVEL == 3) {
223+
LOG_WARN("2d var {}", test2dH);
224+
} else if (OMEGA_LOG_LEVEL == 4) {
225+
LOG_ERROR("2d var {}", test2dH);
226+
} else if (OMEGA_LOG_LEVEL == 5) {
227+
LOG_CRITICAL("2d var {}", test2dH);
228+
} else {
229+
TestRun = false; // off
230+
}
231+
232+
// check if HostArray2DReal is detected
233+
if (LogEnabled && TestRun)
234+
RetVal += outputTestResult("Kokkos data type 2", "test2dH", Contains);
190235
}
191236
Kokkos::finalize();
192237

0 commit comments

Comments
 (0)