Skip to content

Commit 70b0142

Browse files
committed
GPU: Add workaround if fmt not available to GPUCommonLogger
1 parent c72dece commit 70b0142

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

GPU/Common/GPUCommonLogger.h

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,79 @@
1616
#define GPUCOMMONFAIRLOGGER_H
1717

1818
#include "GPUCommonDef.h"
19+
#ifndef GPUCA_GPUCODE_DEVICE
20+
#include <cstdio>
21+
#endif
1922

20-
#if defined(GPUCA_GPUCODE_DEVICE)
21-
namespace o2::gpu::detail
23+
namespace o2::gpu::internal
2224
{
25+
#if defined(GPUCA_GPUCODE_DEVICE)
2326
struct DummyLogger {
2427
template <typename... Args>
2528
GPUd() DummyLogger& operator<<(Args... args)
2629
{
2730
return *this;
2831
}
2932
};
30-
} // namespace o2::gpu::detail
33+
#else
34+
template <typename... Args>
35+
void LOGP_internal(const char* str, Args... args)
36+
{
37+
printf("%s\n", str);
38+
}
3139
#endif
40+
} // namespace o2::gpu::internal
3241

33-
#if defined(__OPENCL__) || (defined(GPUCA_GPUCODE_DEVICE) && !defined(GPUCA_GPU_DEBUG_PRINT))
34-
#define LOG(...) o2::gpu::detail::DummyLogger()
42+
#ifdef GPUCA_GPUCODE_DEVICE
43+
// ---------- begin GPUCA_GPUCODE_DEVICE ----------
44+
45+
#if defined(__OPENCL__) || !defined(GPUCA_GPU_DEBUG_PRINT)
46+
#define LOG(...) o2::gpu::internal::DummyLogger()
3547
#define LOGF(...)
3648
#define LOGP(...)
3749

38-
#elif defined(GPUCA_GPUCODE_DEVICE)
39-
#define LOG(...) o2::gpu::detail::DummyLogger()
50+
#else
51+
#define LOG(...) o2::gpu::internal::DummyLogger()
4052
// #define LOG(...) static_assert(false, "LOG(...) << ... unsupported in GPU code");
4153
#define LOGF(type, string, ...) \
4254
{ \
4355
printf(string "\n", ##__VA_ARGS__); \
4456
}
4557
#define LOGP(...)
4658
// #define LOGP(...) static_assert(false, "LOGP(...) unsupported in GPU code");
59+
#endif
4760

61+
// ---------- end GPUCA_GPUCODE_DEVICE ----------
4862
#elif defined(GPUCA_STANDALONE) || defined(GPUCA_GPUCODE_COMPILEKERNELS) || defined(GPUCA_COMPILEKERNELS)
63+
// ---------- begin GPUCA_STANDALONE / COMPILEKERNELS ----------
64+
4965
#include <iostream>
5066
#include <cstdio>
5167
#define LOG(type) std::cout
52-
#define LOGF(type, string, ...) \
53-
{ \
54-
printf(string "\n", ##__VA_ARGS__); \
55-
}
56-
#define LOGP(type, string, ...) \
57-
{ \
58-
printf("%s\n", string); \
59-
}
68+
#define LOGF(type, string, ...) printf(string "\n", ##__VA_ARGS__);
69+
#if !defined(GPUCA_NO_FMT) && !defined(GPUCA_GPUCODE)
70+
#define LOGP(type, string, ...) fmt::print(string, ##__VA_ARGS__)
71+
#else
72+
#define LOGP(type, string, ...) o2::gpu::internal::LOGP_internal(string, ##__VA_ARGS__)
73+
#endif
74+
#if defined(GPUCA_STANDALONE) && !defined(GPUCA_GPUCODE)
75+
#if !defined(GPUCA_NO_FMT)
76+
#include <fmt/format.h>
77+
#else
78+
namespace fmt
79+
{
80+
template <typename... Args>
81+
static const char* format(Args... args)
82+
{
83+
return "";
84+
}
85+
} // namespace fmt
86+
#endif
87+
#endif
6088

89+
// ---------- end GPUCA_STANDALONE / COMPILEKERNELS ----------
6190
#else
6291
#include <Framework/Logger.h>
63-
6492
#endif
6593

6694
#endif

0 commit comments

Comments
 (0)