Project
Loading...
Searching...
No Matches
GPULogging.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 GPULOGGING_H
16#define GPULOGGING_H
17
18#include "GPUCommonDef.h"
19// clang-format off
20#if defined(GPUCA_GPUCODE_DEVICE) && !defined(GPUCA_GPU_DEBUG_PRINT)
21 // Compile-time disable for performance-reasons
22 #define GPUInfo(...)
23 #define GPUImportant(...)
24 #define GPUWarning(...)
25 #define GPUAlarm(...)
26 #define GPUError(...)
27 #define GPUCritical(...)
28 #define GPUFatal(...)
29#elif defined(GPUCA_STANDALONE) && !defined(GPUCA_GPUCODE_DEVICE) && !defined(GPUCA_NO_FMT)
30 #include <cstdio>
31 #pragma GCC diagnostic push
32 #if defined(__FAST_MATH__) && defined(__clang__)
33 #pragma GCC diagnostic ignored "-Wnan-infinity-disabled"
34 #endif
35 #include <fmt/printf.h>
36 #pragma GCC diagnostic pop
37 #define GPUInfo(string, ...) \
38 { \
39 fmt::printf(string "\n", ##__VA_ARGS__); \
40 }
41 #define GPUImportant(...) GPUInfo(__VA_ARGS__)
42 #define GPUWarning(string, ...) \
43 { \
44 fmt::fprintf(stderr, string "\n", ##__VA_ARGS__); \
45 }
46 #define GPUError(...) GPUWarning(__VA_ARGS__)
47 #define GPUCritical(...) GPUWarning(__VA_ARGS__)
48 #define GPUAlarm(...) GPUWarning(__VA_ARGS__)
49 #define GPUFatal(string, ...) \
50 { \
51 fmt::fprintf(stderr, string "\n", ##__VA_ARGS__); \
52 throw std::exception(); \
53 }
54#elif defined(GPUCA_STANDALONE) || defined(GPUCA_GPUCODE_DEVICE)
55 // For standalone / CUDA / HIP, we just use printf, which should be available
56 #include <cstdio>
57 #define GPUInfo(string, ...) \
58 { \
59 printf(string "\n", ##__VA_ARGS__); \
60 }
61 #define GPUImportant(...) GPUInfo(__VA_ARGS__)
62 #ifdef GPUCA_GPUCODE_DEVICE
63 #define GPUWarning(...) GPUInfo(__VA_ARGS__)
64 #define GPUAlarm(...) GPUInfo(__VA_ARGS__)
65 #define GPUError(...) GPUInfo(__VA_ARGS__)
66 #define GPUFatal(...) GPUInfo(__VA_ARGS__)
67 #else
68 #define GPUWarning(string, ...) \
69 { \
70 fprintf(stderr, string "\n", ##__VA_ARGS__); \
71 }
72 #define GPUAlarm(...) GPUWarning(__VA_ARGS__)
73 #define GPUError(...) GPUWarning(__VA_ARGS__)
74 #define GPUCritical(...) GPUWarning(__VA_ARGS__)
75 #define GPUFatal(string, ...) \
76 { \
77 fprintf(stderr, string "\n", ##__VA_ARGS__); \
78 exit(1); \
79 }
80 #endif
81#elif defined(GPUCA_O2_LIB) || defined(GPUCA_O2_INTERFACE)
82 // Forward to O2 LOGF logginf for O2
83 #include "GPUCommonLogger.h"
84 #define GPUInfo(...) LOGF(info, __VA_ARGS__)
85 #define GPUImportant(...) LOGF(info, __VA_ARGS__)
86 #define GPUWarning(...) LOGF(warning, __VA_ARGS__)
87 #define GPUAlarm(...) LOGF(alarm, __VA_ARGS__)
88 #define GPUError(...) LOGF(error, __VA_ARGS__)
89 #define GPUCritical(...) LOGF(critical, __VA_ARGS__)
90 #define GPUFatal(...) LOGF(fatal, __VA_ARGS__)
91#endif
92
93// clang-format on
94
95#endif // GPULOGGING_H