forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGPUCommonHelpers.h
More file actions
62 lines (55 loc) · 2.77 KB
/
GPUCommonHelpers.h
File metadata and controls
62 lines (55 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file GPUCommonHelpers.h
/// \author David Rohr
// GPUChkErr and GPUChkErrI will both check x for an error, using the loaded backend of GPUReconstruction (requiring GPUReconstruction.h to be included by the user).
// In case of an error, it will print out the corresponding CUDA / HIP / OpenCL error code
// GPUChkErr will download GPUReconstruction error values from GPU, print them, and terminate the application with an exception if an error occured.
// GPUChkErrI will return 0 or 1, depending on whether an error has occurred.
// These Macros must be called ona GPUReconstruction instance.
// The GPUChkErrS and GPUChkErrSI are similar but static, without required GPUReconstruction instance.
// Examples:
// if (mRec->GPUChkErrI(cudaMalloc(...))) { exit(1); }
// gpuRecObj.GPUChkErr(cudaMalloc(...));
// if (GPUChkErrSI(cudaMalloc(..))) { exit(1); }
#ifndef GPUCOMMONHELPERS_H
#define GPUCOMMONHELPERS_H
// Please #include "GPUReconstruction.h" in your code, if you use these 2!
#define GPUChkErr(x) GPUChkErrA(x, __FILE__, __LINE__, true)
#define GPUChkErrI(x) GPUChkErrA(x, __FILE__, __LINE__, false)
#define GPUChkErrS(x) o2::gpu::internal::GPUReconstructionChkErr(x, __FILE__, __LINE__, true)
#define GPUChkErrSI(x) o2::gpu::internal::GPUReconstructionChkErr(x, __FILE__, __LINE__, false)
#include "GPUCommonDef.h"
#include <cstdint>
namespace o2::gpu::internal
{
#define GPUCOMMON_INTERNAL_CAT_A(a, b, c) a##b##c
#define GPUCOMMON_INTERNAL_CAT(...) GPUCOMMON_INTERNAL_CAT_A(__VA_ARGS__)
extern int32_t GPUCOMMON_INTERNAL_CAT(GPUReconstruction, GPUCA_GPUTYPE, ChkErr)(const int64_t error, const char* file, int32_t line);
inline int32_t GPUReconstructionCPUChkErr(const int64_t error, const char* file, int32_t line)
{
if (error) {
GPUError("GPUCommon Error Code %d (%s:%d)", error, file, line);
}
return error != 0;
}
static inline int32_t GPUReconstructionChkErr(const int64_t error, const char* file, int32_t line, bool failOnError)
{
int32_t retVal = error && GPUCOMMON_INTERNAL_CAT(GPUReconstruction, GPUCA_GPUTYPE, ChkErr)(error, file, line);
if (retVal && failOnError) {
throw std::runtime_error("GPU API Call Failure");
}
return error;
}
#undef GPUCOMMON_INTERNAL_CAT_A
#undef GPUCOMMON_INTERNAL_CAT
} // namespace o2::gpu::internal
#endif