Project
Loading...
Searching...
No Matches
GPUReconstructionCUDAInternals.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// All CUDA-header related stuff goes here, so we can run CING over GPUReconstructionCUDA
16
17#ifndef GPURECONSTRUCTIONCUDAINTERNALS_H
18#define GPURECONSTRUCTIONCUDAINTERNALS_H
19
20#include <cuda.h>
21#include "GPULogging.h"
22#include <vector>
23#include <memory>
24#include <string>
25
26namespace o2::gpu
27{
28
29#define GPUFailedMsg(x) GPUFailedMsgA(x, __FILE__, __LINE__)
30#define GPUFailedMsgI(x) GPUFailedMsgAI(x, __FILE__, __LINE__)
31
33 std::vector<std::unique_ptr<CUmodule>> kernelModules; // module for RTC compilation
34 std::vector<std::unique_ptr<CUfunction>> kernelFunctions; // vector of ptrs to RTC kernels
35 std::vector<std::string> kernelNames; // names of kernels
36 cudaStream_t Streams[GPUCA_MAX_STREAMS]; // Pointer to array of CUDA Streams
37
38 static void getArgPtrs(const void** pArgs) {}
39 template <typename T, typename... Args>
40 static void getArgPtrs(const void** pArgs, const T& arg, const Args&... args)
41 {
42 *pArgs = &arg;
43 getArgPtrs(pArgs + 1, args...);
44 }
45};
46
48{
49 public:
50 GPUDebugTiming(bool d, gpu_reconstruction_kernels::deviceEvent* t, cudaStream_t* s, const gpu_reconstruction_kernels::krnlSetupTime& x, GPUReconstructionCUDABackend* r) : mDeviceTimers(t), mStreams(s), mXYZ(x), mRec(r), mDo(d)
51 {
52 if (mDo) {
53 if (mDeviceTimers) {
54 mRec->GPUFailedMsg(cudaEventRecord(mDeviceTimers[0].get<cudaEvent_t>(), mStreams[mXYZ.x.stream]));
55 } else {
56 mTimer.ResetStart();
57 }
58 }
59 }
61 {
62 if (mDo && mXYZ.t == 0.) {
63 if (mDeviceTimers) {
64 mRec->GPUFailedMsg(cudaEventRecord(mDeviceTimers[1].get<cudaEvent_t>(), mStreams[mXYZ.x.stream]));
65 mRec->GPUFailedMsg(cudaEventSynchronize(mDeviceTimers[1].get<cudaEvent_t>()));
66 float v;
67 mRec->GPUFailedMsg(cudaEventElapsedTime(&v, mDeviceTimers[0].get<cudaEvent_t>(), mDeviceTimers[1].get<cudaEvent_t>()));
68 mXYZ.t = v * 1.e-3f;
69 } else {
70 mRec->GPUFailedMsg(cudaStreamSynchronize(mStreams[mXYZ.x.stream]));
71 mXYZ.t = mTimer.GetCurrentElapsedTime();
72 }
73 }
74 }
75
76 private:
78 cudaStream_t* mStreams;
81 HighResTimer mTimer;
82 bool mDo;
83};
84
85static_assert(std::is_convertible<cudaEvent_t, void*>::value, "CUDA event type incompatible to deviceEvent");
86
87} // namespace o2::gpu
88
89#endif
#define GPUCA_MAX_STREAMS
double GetCurrentElapsedTime(bool reset=false)
Definition timer.cxx:110
void ResetStart()
Definition timer.cxx:63
GPUDebugTiming(bool d, gpu_reconstruction_kernels::deviceEvent *t, cudaStream_t *s, const gpu_reconstruction_kernels::krnlSetupTime &x, GPUReconstructionCUDABackend *r)
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLboolean r
Definition glcorearb.h:1233
static void getArgPtrs(const void **pArgs, const T &arg, const Args &... args)
std::vector< std::unique_ptr< CUmodule > > kernelModules
std::vector< std::unique_ptr< CUfunction > > kernelFunctions