Project
Loading...
Searching...
No Matches
GPUProcessor.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 GPUPROCESSOR_H
16#define GPUPROCESSOR_H
17
18#include "GPUCommonDef.h"
19#include "GPUDef.h"
20
21#ifndef GPUCA_GPUCODE
22#include <cstddef>
23#include <algorithm>
24#endif
25
26namespace o2::gpu
27{
28struct GPUTrackingInOutPointers;
29class GPUReconstruction;
30struct GPUParam;
31struct GPUConstantMem;
32
34{
35 friend class GPUReconstruction;
37 friend class GPUMemoryResource;
38
39 public:
43
44#ifndef GPUCA_GPUCODE
47 GPUProcessor(const GPUProcessor&) = delete;
49#endif
50
51 GPUd() GPUconstantref() const GPUConstantMem* GetConstantMem() const; // Body in GPUConstantMem.h to avoid circular headers
52 GPUd() GPUconstantref() const GPUParam& Param() const; // ...
53 GPUd() void raiseError(uint32_t code, uint32_t param1 = 0, uint32_t param2 = 0, uint32_t param3 = 0) const;
54 const GPUReconstruction& GetRec() const { return *mRec; }
55
56#ifndef __OPENCL__
58 void Clear();
59 template <class T>
61 {
63 }
64
65 template <size_t alignment = GPUCA_BUFFER_ALIGNMENT>
66 static constexpr inline size_t getAlignmentMod(size_t addr)
67 {
68 static_assert((alignment & (alignment - 1)) == 0, "Invalid alignment, not power of 2");
69 if (alignment <= 1) {
70 return 0;
71 }
72 return addr & (alignment - 1);
73 }
74 template <size_t alignment = GPUCA_BUFFER_ALIGNMENT>
75 static constexpr inline size_t getAlignment(size_t addr)
76 {
77 size_t mod = getAlignmentMod<alignment>(addr);
78 if (mod == 0) {
79 return 0;
80 }
81 return (alignment - mod);
82 }
83 template <size_t alignment = GPUCA_BUFFER_ALIGNMENT>
84 static constexpr inline size_t nextMultipleOf(size_t size)
85 {
86 return size + getAlignment<alignment>(size);
87 }
88 static constexpr inline size_t nextMultipleOf(size_t size, size_t alignment)
89 {
90 if (alignment & (alignment - 1)) {
91 size_t tmp = size % alignment;
92 if (tmp) {
93 size += alignment - tmp;
94 }
95 return size;
96 } else {
97 return (size + alignment - 1) & ~(alignment - 1);
98 }
99 }
100 template <size_t alignment = GPUCA_BUFFER_ALIGNMENT>
101 static inline void* alignPointer(void* ptr)
102 {
103 return (reinterpret_cast<void*>(nextMultipleOf<alignment>(reinterpret_cast<size_t>(ptr))));
104 }
105 template <size_t alignment = GPUCA_BUFFER_ALIGNMENT>
106 static inline size_t getAlignmentMod(void* addr)
107 {
108 return (getAlignmentMod<alignment>(reinterpret_cast<size_t>(addr)));
109 }
110 template <size_t alignment = GPUCA_BUFFER_ALIGNMENT>
111 static inline size_t getAlignment(void* addr)
112 {
113 return (getAlignment<alignment>(reinterpret_cast<size_t>(addr)));
114 }
115 template <size_t alignment = GPUCA_BUFFER_ALIGNMENT, class S>
116 static inline S* getPointerWithAlignment(size_t& basePtr, size_t nEntries = 1)
117 {
118 if (basePtr == 0) {
119 basePtr = 1;
120 }
121 constexpr const size_t maxAlign = (alignof(S) > alignment) ? alignof(S) : alignment;
122 basePtr += getAlignment<maxAlign>(basePtr);
123 S* retVal = (S*)(basePtr);
124 basePtr += nEntries * sizeof(S);
125 return retVal;
126 }
127
128 template <size_t alignment = GPUCA_BUFFER_ALIGNMENT, class S>
129 static inline S* getPointerWithAlignment(void*& basePtr, size_t nEntries = 1)
130 {
131 size_t tmp = (size_t)basePtr;
132 auto retVal = getPointerWithAlignment<alignment, S>(tmp, nEntries);
133 basePtr = (void*)tmp;
134 return retVal;
135 }
136
137 template <size_t alignment = GPUCA_BUFFER_ALIGNMENT, class T, class S>
138 static inline void computePointerWithAlignment(T*& basePtr, S*& objPtr, size_t nEntries = 1)
139 {
140 size_t tmp = (size_t)basePtr;
141 objPtr = getPointerWithAlignment<alignment, S>(tmp, nEntries);
142 basePtr = (T*)tmp;
143 }
144
145 template <class T, class S>
146 static inline void computePointerWithoutAlignment(T*& basePtr, S*& objPtr, size_t nEntries = 1)
147 {
148 if ((size_t)basePtr < GPUCA_BUFFER_ALIGNMENT) {
149 basePtr = (T*)GPUCA_BUFFER_ALIGNMENT;
150 }
151 size_t tmp = (size_t)basePtr;
152 objPtr = reinterpret_cast<S*>(getPointerWithAlignment<1, char>(tmp, nEntries * sizeof(S)));
153 basePtr = (T*)tmp;
154 }
155#endif
156
157 protected:
158 void AllocateAndInitializeLate() { mAllocateAndInitializeLate = true; }
159
163 GPUconstantref() const GPUConstantMem* mConstantMem;
164
165 private:
166 bool mAllocateAndInitializeLate;
167
169};
170} // namespace o2::gpu
171
172#endif
#define GPUCA_BUFFER_ALIGNMENT
int32_t retVal
TBranch * ptr
static constexpr size_t nextMultipleOf(size_t size, size_t alignment)
GPUProcessor & operator=(const GPUProcessor &)=delete
uint32_t uint32_t uint32_t param3
GPUconstantref() const GPUConstantMem *mConstantMem
GPUd() GPUconstantref() const GPUConstantMem *GetConstantMem() const
static S * getPointerWithAlignment(size_t &basePtr, size_t nEntries=1)
static size_t getAlignmentMod(void *addr)
uint32_t uint32_t param2
GPUProcessor(const GPUProcessor &)=delete
GPUReconstruction * mRec
static constexpr size_t getAlignmentMod(size_t addr)
static void computePointerWithAlignment(T *&basePtr, S *&objPtr, size_t nEntries=1)
void InitGPUProcessor(GPUReconstruction *rec, ProcessorType type=PROCESSOR_TYPE_CPU, GPUProcessor *slaveProcessor=nullptr)
static constexpr size_t nextMultipleOf(size_t size)
static S * getPointerWithAlignment(void *&basePtr, size_t nEntries=1)
static void * alignPointer(void *ptr)
ProcessorType mGPUProcessorType
static size_t getAlignment(void *addr)
static constexpr size_t getAlignment(size_t addr)
GPUProcessor * mLinkedProcessor
const GPUReconstruction & GetRec() const
static void computePointerWithoutAlignment(T *&basePtr, S *&objPtr, size_t nEntries=1)
GLsizeiptr size
Definition glcorearb.h:659
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GPUReconstruction * rec