Project
Loading...
Searching...
No Matches
GPUCommonLogger.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef GPUCOMMONFAIRLOGGER_H
16#define GPUCOMMONFAIRLOGGER_H
17
18#include "GPUCommonDef.h"
19#ifndef GPUCA_GPUCODE_DEVICE
20#include <cstdio>
21#endif
22
23namespace o2::gpu::internal
24{
25#if defined(GPUCA_GPUCODE_DEVICE)
26struct DummyLogger {
27 template <typename... Args>
28 GPUd() DummyLogger& operator<<(Args... args)
29 {
30 return *this;
31 }
32};
33#else
34template <typename... Args>
35void LOGP_internal(const char* str, Args... args)
36{
37 printf("%s\n", str);
38}
39#endif
40enum class loglevel : int32_t {
41 debug = 0,
42 info = 1,
43 warning = 2,
44 important = 3,
45 alarm = 4,
46 error = 5,
47 fatal = 6
48};
49} // namespace o2::gpu::internal
50
51#ifdef GPUCA_GPUCODE_DEVICE // clang-format off
52// ---------- begin GPUCA_GPUCODE_DEVICE ----------
53
54#if defined(__OPENCL__) || !defined(GPUCA_GPU_DEBUG_PRINT)
55#define LOG(...) o2::gpu::internal::DummyLogger()
56#define LOGF(...)
57#define LOGP(...)
58
59#else
60#define LOG(...) o2::gpu::internal::DummyLogger()
61// #define LOG(...) static_assert(false, "LOG(...) << ... unsupported in GPU code");
62#define LOGF(type, string, ...) do { if (o2::gpu::internal::loglevel::type >= o2::gpu::internal::loglevel::info) { printf(string "\n", ##__VA_ARGS__); }} while (false);
63#define LOGP(...)
64// #define LOGP(...) static_assert(false, "LOGP(...) unsupported in GPU code");
65#endif
66
67// ---------- end GPUCA_GPUCODE_DEVICE ----------
68#elif defined(GPUCA_STANDALONE) || defined(GPUCA_GPUCODE_COMPILEKERNELS) || defined(GPUCA_COMPILEKERNELS)
69// ---------- begin GPUCA_STANDALONE / COMPILEKERNELS ----------
70
71#include <iostream>
72#include <cstdio>
73#define LOG(type) std::cout
74#define LOGF(type, string, ...) do { if (o2::gpu::internal::loglevel::type >= o2::gpu::internal::loglevel::info) { printf(string "\n", ##__VA_ARGS__); }} while (false);
75#if !defined(GPUCA_NO_FMT) && !defined(GPUCA_GPUCODE)
76#define LOGP(type, string, ...) do { if (o2::gpu::internal::loglevel::type >= o2::gpu::internal::loglevel::info) { fmt::print(string, ##__VA_ARGS__); printf("\n"); }} while (false);
77#else
78#define LOGP(type, string, ...) do { if (o2::gpu::internal::loglevel::type >= o2::gpu::internal::loglevel::info) { o2::gpu::internal::LOGP_internal(string, ##__VA_ARGS__); }} while (false);
79#endif
80#if defined(GPUCA_STANDALONE) && !defined(GPUCA_GPUCODE)
81#if !defined(GPUCA_NO_FMT)
82#include <fmt/format.h>
83#else
84namespace fmt
85{
86template <typename... Args>
87static const char* format(Args... args)
88{
89 return "";
90}
91} // namespace fmt
92#endif
93#endif
94
95// ---------- end GPUCA_STANDALONE / COMPILEKERNELS ----------
96#else
97#include <Framework/Logger.h>
98#endif // clang-format on
99
100#endif
#define GPUd()
GLint GLint GLsizei GLint GLenum format
Definition glcorearb.h:275
void LOGP_internal(const char *str, Args... args)
const std::string str