Project
Loading...
Searching...
No Matches
GPUCommonDefAPI.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 GPUCOMMONDEFAPI_H
16#define GPUCOMMONDEFAPI_H
17// clang-format off
18
19#ifndef GPUCOMMONDEF_H
20 #error Please include GPUCommonDef.h!
21#endif
22
23#ifndef GPUCA_GPUCODE_DEVICE
24#include <cstdint>
25#endif
26
27//Define macros for GPU keywords. i-version defines inline functions.
28//All host-functions in GPU code are automatically inlined, to avoid duplicate symbols.
29//For non-inline host only functions, use no keyword at all!
30#if !defined(GPUCA_GPUCODE) || defined(__OPENCL_HOST__) || defined(__METAL_HOST__) || defined(__CPUDEVICE__) // For host / ROOT dictionary, and for the CPUDevice backend whose device code runs on the host
31 #define GPUd() // device function
32 #define GPUdDefault() // default (constructor / operator) device function
33 #define GPUhdDefault() // default (constructor / operator) host device function
34 #define GPUdi() inline // to-be-inlined device function
35 #define GPUdii() // Only on GPU to-be-inlined (forced) device function
36 #define GPUdni() // Device function, not-to-be-inlined
37 #define GPUdnii() inline // Device function, not-to-be-inlined on device, inlined on host
38 #define GPUh() // Host-only function
39 // NOTE: All GPUd*() functions are also compiled on the host during host compilation.
40 // The GPUh*() macros are for the rare cases of functions that you want to compile for the host during GPU compilation.
41 // Usually, you do not need the GPUh*() versions. If in doubt, use GPUd*()!
42 #define GPUhi() inline // to-be-inlined host-only function
43 #define GPUhd() // Host and device function, inlined during GPU compilation to avoid symbol clashes in host code
44 #define GPUhdi() inline // Host and device function, to-be-inlined on host and device
45 #define GPUhdni() // Host and device function, not to-be-inlined automatically
46 #define GPUg() INVALID_TRIGGER_ERROR_NO_GPU_CODE // GPU kernel
47 #define GPUshared() // shared memory variable declaration
48 #define GPUglobal() // global memory variable declaration (only used for kernel input pointers)
49 #define GPUconstant() // constant memory variable declaraion
50 #define GPUconstexpr() static constexpr // constexpr on GPU that needs to be instantiated for dynamic access (e.g. arrays), becomes __constant on GPU
51 #define GPUglobalconstexpr() constexpr // constexpr variable at program scope, needs the constant address space in MSL
52 #define GPUnoexcept() noexcept // noexcept where the backend supports it
53 #define GPUprivate() // private memory variable declaration
54 #define GPUgeneric() // reference / ptr to generic address space
55 #define GPUbarrier() // synchronize all GPU threads in block
56 #define GPUbarrierWarp() // synchronize threads inside warp
57 #define GPUAtomic(type) type // atomic variable type
58 #define GPUsharedref() // reference / ptr to shared memory
59 #define GPUglobalref() // reference / ptr to global memory
60 #define GPUconstantref() // reference / ptr to constant memory
61 #define GPUconstexprref() // reference / ptr to variable declared as GPUconstexpr()
62
63 #ifndef __VECTOR_TYPES_H__ // FIXME: ROOT will pull in these CUDA definitions if built against CUDA, so we have to add an ugly protection here
64 struct float4 { float x, y, z, w; };
65 struct float3 { float x, y, z; };
66 struct float2 { float x; float y; };
67 struct uchar2 { uint8_t x, y; };
68 struct short2 { int16_t x, y; };
69 struct ushort2 { uint16_t x, y; };
70 struct int2 { int32_t x, y; };
71 struct int3 { int32_t x, y, z; };
72 struct int4 { int32_t x, y, z, w; };
73 struct uint1 { uint32_t x; };
74 struct uint2 { uint32_t x, y; };
75 struct uint3 { uint32_t x, y, z; };
76 struct uint4 { uint32_t x, y, z, w; };
77 struct dim3 { uint32_t x, y, z; };
78 #endif
79#elif defined(__OPENCL__) // Defines for OpenCL
80 #define GPUd()
81 #define GPUdDefault()
82 #define GPUhdDefault()
83 #define GPUdi() inline
84 #define GPUdii() GPUdi() GPUAlwaysInline()
85 #define GPUdni()
86 #define GPUdnii()
87 #define GPUh() INVALID_TRIGGER_ERROR_NO_HOST_CODE
88 #define GPUhi() INVALID_TRIGGER_ERROR_NO_HOST_CODE
89 #define GPUhd() inline
90 #define GPUhdi() inline
91 #define GPUhdni()
92 #define GPUg() __kernel
93 #define GPUshared() __local
94 #define GPUglobal() __global
95 #define GPUconstant() __constant // TODO: possibly add const __restrict where possible later!
96 #define GPUconstexpr() __constant
97 #define GPUprivate() __private
98 #define GPUgeneric() __generic
99 #define GPUconstexprref() GPUconstexpr()
100 #if defined(__OPENCL__) && !defined(__clang__)
101 #define GPUbarrier() work_group_barrier(mem_fence::global | mem_fence::local)
102 #define GPUbarrierWarp() sub_group_barrier(mem_fence::global | mem_fence::local)
103 #define GPUAtomic(type) atomic<type>
104 static_assert(sizeof(atomic<uint32_t>) == sizeof(uint32_t), "Invalid size of atomic type");
105 #else
106 #define GPUbarrier() barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE)
107 #define GPUbarrierWarp() sub_group_barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE)
108 #if defined(__OPENCL__) && defined(GPUCA_OPENCL_CLANG_C11_ATOMICS)
109 namespace o2 { namespace gpu {
110 template <class T> struct oclAtomic;
111 template <> struct oclAtomic<uint32_t> {typedef atomic_uint t;};
112 static_assert(sizeof(oclAtomic<uint32_t>::t) == sizeof(uint32_t), "Invalid size of atomic type");
113 }}
114 #define GPUAtomic(type) o2::gpu::oclAtomic<type>::t
115 #else
116 #define GPUAtomic(type) volatile type
117 #endif
118 #endif
119 #if !defined(__OPENCL__) // Other special defines for OpenCL 1
120 #define GPUCA_USE_TEMPLATE_ADDRESS_SPACES // TODO: check if we can make this (partially, where it is already implemented) compatible with OpenCL CPP
121 #define GPUsharedref() GPUshared()
122 #define GPUglobalref() GPUglobal()
123 #undef GPUgeneric
124 #define GPUgeneric()
125 #endif
126 #if (!defined(__OPENCL__) || !defined(GPUCA_NO_CONSTANT_MEMORY))
127 #define GPUconstantref() GPUconstant()
128 #endif
129#elif defined(__METAL__) //Defines for Metal Shading Language
130 // ADDRESS SPACES. This backend targets MSL 4.1 (macOS 27) and later only --
131 // see -std=metal4.1 in the CMakeLists, which fails the build on anything
132 // older rather than miscompiling quietly.
133 //
134 // That version is what makes the port tractable: up to MSL 4.0 a member
135 // function's implicit `this` is `thread`, which is wrong for us, since most
136 // objects the kernels touch live in `device` memory. Pinning defaulted
137 // constructors and operators to `device` was the 4.0 workaround, and it made
138 // the same type unusable in `thread` or `threadgroup`. In 4.1 an unannotated
139 // `this` is GENERIC and resolves to whichever address space the object is in
140 // -- the C++ semantics this codebase already assumes -- so GPUdDefault()
141 // needs nothing at all. The compiler resolves it statically in almost every
142 // case; it only falls back to a runtime branch where it cannot see through,
143 // such as argument buffers or dynamic libraries.
144 //
145 // The *ref() macros below stay explicit even so. They are already correct
146 // from the OpenCL port, an explicit annotation is never slower than a generic
147 // one, and `constant` is not covered by generic pointers at all.
148 #define GPUdDefault() // generic `this` (MSL 4.1+)
149 #define GPUd()
150 #define GPUhdDefault()
151 #define GPUdi() inline
152 #define GPUdii() GPUdi() GPUAlwaysInline()
153 #define GPUdni()
154 #define GPUdnii()
155 #define GPUh() inline
156 #define GPUhi() inline
157 #define GPUhd() inline
158 #define GPUhdi() inline
159 #define GPUhdni()
160 #define GPUg() kernel
161 #define GPUshared() threadgroup
162 #define GPUglobal() device
163 #define GPUconstant() constant // TODO: possibly add const __restrict where possible later!
164 #define GPUconstexpr() constant
165 #define GPUglobalconstexpr() constant constexpr
166 #define GPUnoexcept()
167 #define GPUprivate() thread
168 #define GPUgeneric()
169 #define GPUglobalref()
170 #define GPUsharedref() threadgroup
171 #define GPUprivateref() thread
172 #define GPUconstexprref() GPUconstexpr()
173 #define GPUdouble() float
174 #define GPUbarrier() threadgroup_barrier(mem_flags::mem_device | mem_flags::mem_threadgroup)
175 #define GPUbarrierWarp() simdgroup_barrier(mem_flags::mem_device | mem_flags::mem_threadgroup)
176 #define GPUAtomic(type) type // atomic variable type
177#elif defined(__HIPCC__) //Defines for HIP
178 #define GPUd() __device__
179 #define GPUdDefault() __device__
180 #define GPUhdDefault() __host__ __device__
181 #define GPUdi() __device__ inline
182 #define GPUdii() GPUdi() GPUAlwaysInline()
183 #define GPUdni() __device__ __attribute__((noinline))
184 #define GPUdnii() __device__ __attribute__((noinline))
185 #define GPUh() __host__ inline
186 #define GPUhi() __host__ inline
187 #define GPUhd() __host__ __device__ inline
188 #define GPUhdi() __host__ __device__ inline
189 #define GPUhdni() __host__ __device__
190 #define GPUg() __global__
191 #define GPUshared() __shared__
192 #if defined(GPUCA_GPUCODE_DEVICE) && 0 // TODO: Fix for HIP
193 #define GPUCA_USE_TEMPLATE_ADDRESS_SPACES
194 #define GPUglobal() __attribute__((address_space(1)))
195 #define GPUglobalref() GPUglobal()
196 #define GPUconstantref() __attribute__((address_space(4)))
197 #define GPUsharedref() __attribute__((address_space(3)))
198 #else
199 #define GPUglobal()
200 #endif
201 #define GPUconstant() __constant__
202 #define GPUconstexpr() constexpr __constant__
203 #define GPUprivate()
204 #define GPUgeneric()
205 #define GPUbarrier() __syncthreads()
206 #define GPUbarrierWarp()
207 #define GPUAtomic(type) type
208#elif defined(__CUDACC__) //Defines for CUDA
209 #ifndef GPUCA_GPUCODE_DEVICE
210 #define GPUd() __device__ inline // FIXME: DR: Workaround: mark device function as inline such that nvcc does not create bogus host symbols
211 #else
212 #define GPUd() __device__
213 #endif
214 #define GPUdDefault()
215 #define GPUhdDefault()
216 #define GPUdi() __device__ inline
217 #define GPUdii() GPUdi() GPUAlwaysInline()
218 #define GPUdni() __device__ __attribute__((noinline))
219 #define GPUdnii() __device__ __attribute__((noinline))
220 #define GPUh() __host__ inline
221 #define GPUhi() __host__ inline
222 #define GPUhd() __host__ __device__ inline
223 #define GPUhdi() __host__ __device__ inline
224 #define GPUhdni() __host__ __device__
225 #define GPUg() __global__
226 #define GPUshared() __shared__
227 #define GPUglobal()
228 #define GPUconstant() __constant__
229 #define GPUconstexpr() constexpr __constant__
230 #define GPUprivate()
231 #define GPUgeneric()
232 #define GPUbarrier() __syncthreads()
233 #define GPUbarrierWarp() __syncwarp()
234 #define GPUAtomic(type) type
235#endif
236
237#define GPUAlwaysInline() __attribute__((always_inline)) // Forced inlining on host and device
238
239#ifndef GPUdic // Takes different parameter for inlining: 0 = never, 1 = always, 2 = compiler-decision
240#define GPUdic(...) GPUd()
241#endif
242#define GPUCA_GPUdic_select_0() GPUdni()
243#define GPUCA_GPUdic_select_1() GPUdii()
244#define GPUCA_GPUdic_select_2() GPUd()
245
246#if defined(GPUCA_NO_CONSTANT_MEMORY)
247 #undef GPUconstant
248 #define GPUconstant() GPUglobal()
249#endif
250
251#ifndef GPUsharedref
252#define GPUsharedref()
253#endif
254#ifndef GPUglobalref
255#define GPUglobalref()
256#endif
257#ifndef GPUconstantref
258#define GPUconstantref()
259#endif
260#ifndef GPUconstexprref
261#define GPUconstexprref()
262#endif
263#ifndef GPUglobalconstexpr
264#define GPUglobalconstexpr() constexpr
265#endif
266#ifndef GPUnoexcept
267#define GPUnoexcept() noexcept
268#endif
269
270#define GPUrestrict() __restrict__
271
272// Macros for GRID dimension
273#if defined(__CUDACC__) || defined(__HIPCC__)
274 #define get_global_id(dim) (blockIdx.x * blockDim.x + threadIdx.x)
275 #define get_global_size(dim) (blockDim.x * gridDim.x)
276 #define get_num_groups(dim) (gridDim.x)
277 #define get_local_id(dim) (threadIdx.x)
278 #define get_local_size(dim) (blockDim.x)
279 #define get_group_id(dim) (blockIdx.x)
280#elif defined(__OPENCL__)
281 // Using OpenCL defaults
282#elif defined(__METAL__)
283 // MSL has no work-item builtins. They arrive as attributes on the entry point,
284 // named there after the nBlocks / nThreads / iBlock / iThread that Thread()
285 // already takes, so these resolve both there and in every function below it.
286 #define get_global_id(dim) (iBlock * nThreads + iThread)
287 #define get_global_size(dim) (nBlocks * nThreads)
288 #define get_num_groups(dim) (nBlocks)
289 #define get_local_id(dim) (iThread)
290 #define get_local_size(dim) (nThreads)
291 #define get_group_id(dim) (iBlock)
292#else
293 #define get_global_id(dim) iBlock
294 #define get_global_size(dim) nBlocks
295 #define get_num_groups(dim) nBlocks
296 #define get_local_id(dim) 0
297 #define get_local_size(dim) 1
298 #define get_group_id(dim) iBlock
299#endif
300
301// A device function that uses the helpers above but has none of the indices in
302// scope needs them passed in on Metal, where they are ordinary parameters.
303// Both expand to nothing everywhere else, and go last in the parameter list.
304#ifdef __METAL__
305 #define GPUCA_THREAD_INFO_DECL , int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread
306 #define GPUCA_THREAD_INFO_PROVIDE , nBlocks, nThreads, iBlock, iThread
307#else
308 #define GPUCA_THREAD_INFO_DECL
309 #define GPUCA_THREAD_INFO_PROVIDE
310#endif
311
312// clang-format on
313#endif
unsigned short int uint16_t
unsigned int uint32_t
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
uint32_t y
uint32_t z
uint32_t x
int32_t x
int32_t y
int32_t z
int32_t y
int32_t x
int32_t y
int32_t z
int32_t x
int32_t w
int16_t y
int16_t x
uint8_t x
uint8_t y
uint32_t x
uint32_t x
uint32_t y
uint32_t y
uint32_t x
uint32_t z
uint32_t z
uint32_t w
uint32_t x
uint32_t y
uint16_t x
uint16_t y