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 GPUFatal(...)
28#elif defined(GPUCA_STANDALONE) && !defined(GPUCA_GPUCODE_DEVICE) && !defined(GPUCA_NO_FMT)
29 #include <cstdio>
30 #include <fmt/printf.h>
31 #define GPUInfo(string, ...) \
32 { \
33 fmt::printf(string "\n", ##__VA_ARGS__); \
34 }
35 #define GPUImportant(...) GPUInfo(__VA_ARGS__)
36 #define GPUWarning(string, ...) \
37 { \
38 fmt::fprintf(stderr, string "\n", ##__VA_ARGS__); \
39 }
40 #define GPUError(...) GPUWarning(__VA_ARGS__)
41 #define GPUAlarm(...) GPUWarning(__VA_ARGS__)
42 #define GPUFatal(string, ...) \
43 { \
44 fmt::fprintf(stderr, string "\n", ##__VA_ARGS__); \
45 throw std::exception(); \
46 }
47#elif defined(GPUCA_STANDALONE) || defined(GPUCA_GPUCODE_DEVICE)
48 // For standalone / CUDA / HIP, we just use printf, which should be available
49 #include <cstdio>
50 #define GPUInfo(string, ...) \
51 { \
52 printf(string "\n", ##__VA_ARGS__); \
53 }
54 #define GPUImportant(...) GPUInfo(__VA_ARGS__)
55 #ifdef GPUCA_GPUCODE_DEVICE
56 #define GPUWarning(...) GPUInfo(__VA_ARGS__)
57 #define GPUAlarm(...) GPUInfo(__VA_ARGS__)
58 #define GPUError(...) GPUInfo(__VA_ARGS__)
59 #define GPUFatal(...) GPUInfo(__VA_ARGS__)
60 #else
61 #define GPUWarning(string, ...) \
62 { \
63 fprintf(stderr, string "\n", ##__VA_ARGS__); \
64 }
65 #define GPUAlarm(...) GPUWarning(__VA_ARGS__)
66 #define GPUError(...) GPUWarning(__VA_ARGS__)
67 #define GPUFatal(string, ...) \
68 { \
69 fprintf(stderr, string "\n", __VA_ARGS__); \
70 exit(1); \
71 }
72 #endif
73#elif defined(GPUCA_O2_LIB) || defined(GPUCA_O2_INTERFACE)
74 // Forward to O2 LOGF logginf for O2
75 #include "GPUCommonLogger.h"
76 #define GPUInfo(...) LOGF(info, __VA_ARGS__)
77 #define GPUImportant(...) LOGF(info, __VA_ARGS__)
78 #define GPUWarning(...) LOGF(warning, __VA_ARGS__)
79 #define GPUAlarm(...) LOGF(alarm, __VA_ARGS__)
80 #define GPUError(...) LOGF(error, __VA_ARGS__)
81 #define GPUFatal(...) LOGF(fatal, __VA_ARGS__)
82#endif
83
84// clang-format on
85
86#endif // GPULOGGING_H