Project
Loading...
Searching...
No Matches
GPUReconstructionOCLKernels.cxx
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
16#include "GPUReconstructionKernelIncludes.h"
17
18#include "GPUReconstructionOCLKernelsSpecialize.inc"
19#include "GPUReconstructionProcessingKernels.inc"
21
22template <class T, int32_t I, typename... Args>
23inline void GPUReconstructionOCL::runKernelBackend(const krnlSetupTime& _xyz, const Args&... args)
24{
25 cl_kernel k = getKernelObject<cl_kernel, T, I>();
26 auto& x = _xyz.x;
27 auto& y = _xyz.y;
28 auto& z = _xyz.z;
29 GPUChkErr(OCLsetKernelParameters(k, mInternals->mem_gpu, mInternals->mem_constant, y.index, args...));
30
31 cl_event ev;
32 cl_event* evr;
33 bool tmpEvent = false;
34 if (z.ev == nullptr && GetProcessingSettings().deviceTimers && GetProcessingSettings().debugLevel > 0) {
35 evr = &ev;
36 tmpEvent = true;
37 } else {
38 evr = (cl_event*)z.ev;
39 }
40 GPUChkErr(clExecuteKernelA(mInternals->command_queue[x.stream], k, x.nThreads, x.nThreads * x.nBlocks, evr, (cl_event*)z.evList, z.nEvents));
41 if (GetProcessingSettings().deviceTimers && GetProcessingSettings().debugLevel > 0) {
42 cl_ulong time_start, time_end;
43 GPUChkErr(clWaitForEvents(1, evr));
44 GPUChkErr(clGetEventProfilingInfo(*evr, CL_PROFILING_COMMAND_START, sizeof(time_start), &time_start, nullptr));
45 GPUChkErr(clGetEventProfilingInfo(*evr, CL_PROFILING_COMMAND_END, sizeof(time_end), &time_end, nullptr));
46 _xyz.t = (time_end - time_start) * 1.e-9f;
47 if (tmpEvent) {
48 GPUChkErr(clReleaseEvent(ev));
49 }
50 }
51}
52
53template <class T, int32_t I>
55{
56 std::string name(GetKernelName<T, I>());
57 std::string kname("krnl_" + name);
58
59 cl_int ocl_error;
60 cl_kernel krnl = clCreateKernel(mInternals->program, kname.c_str(), &ocl_error);
61 if (GPUChkErrI(ocl_error)) {
62 GPUError("Error creating OPENCL Kernel: %s", name.c_str());
63 return 1;
64 }
65 mInternals->kernels.emplace_back(krnl);
66 return 0;
67}
68
69template <class S, class T, int32_t I>
71{
72 return mInternals->kernels[GetKernelNum<T, I>()];
73}
74
75int32_t GPUReconstructionOCL::AddKernels()
76{
77#define GPUCA_KRNL(x_class, ...) \
78 if (AddKernel<GPUCA_M_KRNL_TEMPLATE(x_class)>()) { \
79 return 1; \
80 }
81#include "GPUReconstructionKernelList.h"
82#undef GPUCA_KRNL
83 return 0;
84}
#define GPUChkErrI(x)
#define GPUChkErr(x)
double num
void runKernelBackend(const krnlSetupTime &_xyz, const Args &... args)
GPUReconstructionOCLInternals * mInternals
virtual void runKernelVirtual(const int num, const void *args)
const GPUSettingsProcessing & GetProcessingSettings() const
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
cl_command_queue command_queue[GPUCA_MAX_STREAMS]