Skip to content

Commit 6730e74

Browse files
committed
GPU: Switch integer types to <cstdint> types
1 parent 63b9c7c commit 6730e74

File tree

419 files changed

+9278
-9266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

419 files changed

+9278
-9266
lines changed

DataFormats/Detectors/TRD/include/DataFormatsTRD/RecoInputContainer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ inline void RecoInputContainer::fillGPUIOPtr(o2::gpu::GPUTrackingInOutPointers*
8888
ptrs->nTRDTriggerRecords = mNTriggerRecords;
8989
ptrs->trdTriggerTimes = &(trdTriggerTimes[0]);
9090
ptrs->trdTrackletIdxFirst = &(trdTriggerIndices[0]);
91-
ptrs->trdTrigRecMask = reinterpret_cast<const char*>(mTrigRecMask.data());
91+
ptrs->trdTrigRecMask = reinterpret_cast<const uint8_t*>(mTrigRecMask.data());
9292
ptrs->nTRDTracklets = mNTracklets;
9393
ptrs->trdTracklets = reinterpret_cast<const o2::gpu::GPUTRDTrackletWord*>(mTracklets.data());
9494
ptrs->trdSpacePoints = reinterpret_cast<const o2::gpu::GPUTRDSpacePoint*>(mSpacePoints.data());

Detectors/TPC/workflow/src/ZSSpec.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ DataProcessorSpec getZSEncoderSpec(std::vector<int> const& tpcSectors, bool outR
6666
using DigitArray = std::array<gsl::span<const o2::tpc::Digit>, NSectors>;
6767

6868
struct ProcessAttributes {
69-
std::unique_ptr<unsigned long long int[]> zsoutput;
69+
std::unique_ptr<unsigned long[]> zsoutput;
7070
std::unique_ptr<IonTailCorrection> itcorr;
7171
std::vector<unsigned int> sizes;
7272
std::vector<int> tpcSectors;
@@ -216,7 +216,7 @@ DataProcessorSpec getZStoDigitsSpec(std::vector<int> const& tpcSectors)
216216

217217
struct ProcessAttributes {
218218
std::array<std::vector<Digit>, NSectors> outDigits;
219-
std::unique_ptr<unsigned long long int[]> zsinput;
219+
std::unique_ptr<unsigned long[]> zsinput;
220220
std::vector<unsigned int> sizes;
221221
std::unique_ptr<o2::tpc::ZeroSuppress> decoder;
222222
std::vector<int> tpcSectors;

GPU/Common/GPUCommonAlgorithm.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l, Cmp cmp) noexcept
157157
if (f == l) {
158158
return;
159159
}
160-
using IndexType = unsigned short;
160+
using IndexType = uint16_t;
161161

162162
struct pair {
163163
IndexType first;
@@ -166,7 +166,7 @@ GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l, Cmp cmp) noexcept
166166

167167
struct Stack {
168168
pair data[11];
169-
unsigned char n{0};
169+
uint8_t n{0};
170170

171171
GPUd() void emplace(IndexType x, IndexType y)
172172
{
@@ -295,12 +295,12 @@ GPUdi() void GPUCommonAlgorithm::sortInBlock(T* begin, T* end, const S& comp)
295295
#ifndef GPUCA_GPUCODE
296296
GPUCommonAlgorithm::sort(begin, end, comp);
297297
#else
298-
int n = end - begin;
299-
for (int i = 0; i < n; i++) {
300-
for (int tIdx = get_local_id(0); tIdx < n; tIdx += get_local_size(0)) {
301-
int offset = i % 2;
302-
int curPos = 2 * tIdx + offset;
303-
int nextPos = curPos + 1;
298+
int32_t n = end - begin;
299+
for (int32_t i = 0; i < n; i++) {
300+
for (int32_t tIdx = get_local_id(0); tIdx < n; tIdx += get_local_size(0)) {
301+
int32_t offset = i % 2;
302+
int32_t curPos = 2 * tIdx + offset;
303+
int32_t nextPos = curPos + 1;
304304

305305
if (nextPos < n) {
306306
if (!comp(begin[curPos], begin[nextPos])) {
@@ -363,9 +363,9 @@ GPUdi() T work_group_scan_inclusive_add_FUNC(T v, S& smem)
363363

364364
#define work_group_broadcast(v, i) work_group_broadcast_FUNC(v, i, smem)
365365
template <class T, class S>
366-
GPUdi() T work_group_broadcast_FUNC(T v, int i, S& smem)
366+
GPUdi() T work_group_broadcast_FUNC(T v, int32_t i, S& smem)
367367
{
368-
if ((int)threadIdx.x == i) {
368+
if ((int32_t)threadIdx.x == i) {
369369
smem.tmpBroadcast = v;
370370
}
371371
__syncthreads();
@@ -394,7 +394,7 @@ GPUdi() T warp_scan_inclusive_add_FUNC(T v, S& smem)
394394

395395
#define warp_broadcast(v, i) warp_broadcast_FUNC(v, i)
396396
template <class T>
397-
GPUdi() T warp_broadcast_FUNC(T v, int i)
397+
GPUdi() T warp_broadcast_FUNC(T v, int32_t i)
398398
{
399399
#ifdef __CUDACC__
400400
return __shfl_sync(0xFFFFFFFF, v, i);
@@ -419,7 +419,7 @@ GPUdi() T work_group_reduce_add(T v)
419419
}
420420

421421
template <class T>
422-
GPUdi() T work_group_broadcast(T v, int i)
422+
GPUdi() T work_group_broadcast(T v, int32_t i)
423423
{
424424
return v;
425425
}
@@ -431,7 +431,7 @@ GPUdi() T warp_scan_inclusive_add(T v)
431431
}
432432

433433
template <class T>
434-
GPUdi() T warp_broadcast(T v, int i)
434+
GPUdi() T warp_broadcast(T v, int32_t i)
435435
{
436436
return v;
437437
}

GPU/Common/GPUCommonDefAPI.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#error Please include GPUCommonDef.h!
2121
#endif
2222

23+
#ifndef GPUCA_GPUCODE_DEVICE
24+
#include <cstdint>
25+
#endif
26+
2327
//Define macros for GPU keywords. i-version defines inline functions.
2428
//All host-functions in GPU code are automatically inlined, to avoid duplicate symbols.
2529
//For non-inline host only functions, use no keyword at all!
@@ -54,21 +58,21 @@
5458
#define GPUconstantref() // reference / ptr to constant memory
5559
#define GPUconstexprref() // reference / ptr to variable declared as GPUconstexpr()
5660

57-
#ifndef __VECTOR_TYPES_H__ // ROOT will pull in these CUDA definitions if built against CUDA, so we have to add an ugly protection here
61+
#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
5862
struct float4 { float x, y, z, w; };
5963
struct float3 { float x, y, z; };
6064
struct float2 { float x; float y; };
61-
struct uchar2 { unsigned char x, y; };
62-
struct short2 { short x, y; };
63-
struct ushort2 { unsigned short x, y; };
64-
struct int2 { int x, y; };
65-
struct int3 { int x, y, z; };
66-
struct int4 { int x, y, z, w; };
67-
struct uint1 { unsigned int x; };
68-
struct uint2 { unsigned int x, y; };
69-
struct uint3 { unsigned int x, y, z; };
70-
struct uint4 { unsigned int x, y, z, w; };
71-
struct dim3 { unsigned int x, y, z; };
65+
struct uchar2 { uint8_t x, y; };
66+
struct short2 { int16_t x, y; };
67+
struct ushort2 { uint16_t x, y; };
68+
struct int2 { int32_t x, y; };
69+
struct int3 { int32_t x, y, z; };
70+
struct int4 { int32_t x, y, z, w; };
71+
struct uint1 { uint32_t x; };
72+
struct uint2 { uint32_t x, y; };
73+
struct uint3 { uint32_t x, y, z; };
74+
struct uint4 { uint32_t x, y, z, w; };
75+
struct dim3 { uint32_t x, y, z; };
7276
#endif
7377
#elif defined(__OPENCL__) // Defines for OpenCL
7478
#define GPUd()
@@ -95,15 +99,15 @@
9599
#define GPUbarrier() work_group_barrier(mem_fence::global | mem_fence::local);
96100
#define GPUbarrierWarp()
97101
#define GPUAtomic(type) atomic<type>
98-
static_assert(sizeof(atomic<unsigned int>) == sizeof(unsigned int), "Invalid size of atomic type");
102+
static_assert(sizeof(atomic<uint32_t>) == sizeof(uint32_t), "Invalid size of atomic type");
99103
#else
100104
#define GPUbarrier() barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE)
101105
#define GPUbarrierWarp()
102106
#if defined(__OPENCLCPP__) && defined(GPUCA_OPENCL_CPP_CLANG_C11_ATOMICS)
103107
namespace GPUCA_NAMESPACE { namespace gpu {
104108
template <class T> struct oclAtomic;
105-
template <> struct oclAtomic<unsigned int> {typedef atomic_uint t;};
106-
static_assert(sizeof(oclAtomic<unsigned int>::t) == sizeof(unsigned int), "Invalid size of atomic type");
109+
template <> struct oclAtomic<uint32_t> {typedef atomic_uint t;};
110+
static_assert(sizeof(oclAtomic<uint32_t>::t) == sizeof(uint32_t), "Invalid size of atomic type");
107111
}}
108112
#define GPUAtomic(type) GPUCA_NAMESPACE::gpu::oclAtomic<type>::t
109113
#else

GPU/Common/GPUCommonMath.h

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include <atomic>
2828
#endif
2929

30+
#if !defined(GPUCA_GPUCODE_COMPILEKERNELS) && (!defined(GPUCA_GPUCODE_DEVICE) || defined(__CUDACC__) || defined(__HIPCC__))
31+
#include <cstdint>
32+
#endif
33+
3034
#if !defined(__OPENCL__) || defined(__OPENCLCPP__)
3135
namespace GPUCA_NAMESPACE
3236
{
@@ -75,13 +79,13 @@ class GPUCommonMath
7579
GPUd() static CONSTEXPR float Pi() { return 3.1415927f; }
7680
GPUd() static float Round(float x);
7781
GPUd() static float Floor(float x);
78-
GPUd() static unsigned int Float2UIntReint(const float& x);
79-
GPUd() static unsigned int Float2UIntRn(float x);
80-
GPUd() static int Float2IntRn(float x);
82+
GPUd() static uint32_t Float2UIntReint(const float& x);
83+
GPUd() static uint32_t Float2UIntRn(float x);
84+
GPUd() static int32_t Float2IntRn(float x);
8185
GPUd() static float Modf(float x, float y);
8286
GPUd() static bool Finite(float x);
83-
GPUd() static unsigned int Clz(unsigned int val);
84-
GPUd() static unsigned int Popcount(unsigned int val);
87+
GPUd() static uint32_t Clz(uint32_t val);
88+
GPUd() static uint32_t Popcount(uint32_t val);
8589

8690
GPUhdni() static float Hypot(float x, float y);
8791
GPUhdni() static float Hypot(float x, float y, float z);
@@ -137,10 +141,10 @@ class GPUCommonMath
137141
{
138142
GPUCommonMath::AtomicMinInternal(addr, val);
139143
}
140-
GPUd() static int Mul24(int a, int b);
144+
GPUd() static int32_t Mul24(int32_t a, int32_t b);
141145
GPUd() static float FMulRZ(float a, float b);
142146

143-
template <int I, class T>
147+
template <int32_t I, class T>
144148
GPUd() CONSTEXPR static T nextMultipleOf(T val);
145149

146150
#ifdef GPUCA_NOCOMPAT
@@ -163,11 +167,11 @@ class GPUCommonMath
163167

164168
private:
165169
template <class S, class T>
166-
GPUd() static unsigned int AtomicExchInternal(S* addr, T val);
170+
GPUd() static uint32_t AtomicExchInternal(S* addr, T val);
167171
template <class S, class T>
168172
GPUd() static bool AtomicCASInternal(S* addr, T cmp, T val);
169173
template <class S, class T>
170-
GPUd() static unsigned int AtomicAddInternal(S* addr, T val);
174+
GPUd() static uint32_t AtomicAddInternal(S* addr, T val);
171175
template <class S, class T>
172176
GPUd() static void AtomicMaxInternal(S* addr, T val);
173177
template <class S, class T>
@@ -185,7 +189,7 @@ typedef GPUCommonMath CAMath;
185189
#define CHOICE(c1, c2, c3) (c1) // Select first option for Host
186190
#endif // clang-format on
187191

188-
template <int I, class T>
192+
template <int32_t I, class T>
189193
GPUdi() CONSTEXPR T GPUCommonMath::nextMultipleOf(T val)
190194
{
191195
if CONSTEXPR (I & (I - 1)) {
@@ -212,23 +216,23 @@ GPUdi() float2 GPUCommonMath::MakeFloat2(float x, float y)
212216

213217
GPUdi() float GPUCommonMath::Modf(float x, float y) { return CHOICE(fmodf(x, y), fmodf(x, y), fmod(x, y)); }
214218

215-
GPUdi() unsigned int GPUCommonMath::Float2UIntReint(const float& x)
219+
GPUdi() uint32_t GPUCommonMath::Float2UIntReint(const float& x)
216220
{
217221
#if defined(GPUCA_GPUCODE_DEVICE) && (defined(__CUDACC__) || defined(__HIPCC__))
218222
return __float_as_uint(x);
219223
#elif defined(GPUCA_GPUCODE_DEVICE) && (defined(__OPENCL__) || defined(__OPENCLCPP__))
220224
return as_uint(x);
221225
#else
222-
return reinterpret_cast<const unsigned int&>(x);
226+
return reinterpret_cast<const uint32_t&>(x);
223227
#endif
224228
}
225229

226-
GPUdi() unsigned int GPUCommonMath::Float2UIntRn(float x) { return (unsigned int)(int)(x + 0.5f); }
230+
GPUdi() uint32_t GPUCommonMath::Float2UIntRn(float x) { return (uint32_t)(int32_t)(x + 0.5f); }
227231
GPUdi() float GPUCommonMath::Floor(float x) { return CHOICE(floorf(x), floorf(x), floor(x)); }
228232

229233
#ifdef GPUCA_NO_FAST_MATH
230234
GPUdi() float GPUCommonMath::Round(float x) { return CHOICE(roundf(x), roundf(x), round(x)); }
231-
GPUdi() int GPUCommonMath::Float2IntRn(float x) { return (int)Round(x); }
235+
GPUdi() int32_t GPUCommonMath::Float2IntRn(float x) { return (int32_t)Round(x); }
232236
GPUdi() bool GPUCommonMath::Finite(float x) { return CHOICE(std::isfinite(x), isfinite(x), true); }
233237
GPUhdi() float GPUCommonMath::Sqrt(float x) { return CHOICE(sqrtf(x), (float)sqrt((double)x), sqrt(x)); }
234238
GPUdi() float GPUCommonMath::ATan(float x) { return CHOICE((float)atan((double)x), (float)atan((double)x), atan(x)); }
@@ -243,7 +247,7 @@ GPUdi() float GPUCommonMath::Log(float x) { return CHOICE((float)log((double)x),
243247
GPUdi() float GPUCommonMath::Exp(float x) { return CHOICE((float)exp((double)x), (float)exp((double)x), exp(x)); }
244248
#else
245249
GPUdi() float GPUCommonMath::Round(float x) { return CHOICE(roundf(x), rintf(x), rint(x)); }
246-
GPUdi() int GPUCommonMath::Float2IntRn(float x) { return CHOICE((int)Round(x), __float2int_rn(x), (int)Round(x)); }
250+
GPUdi() int32_t GPUCommonMath::Float2IntRn(float x) { return CHOICE((int32_t)Round(x), __float2int_rn(x), (int32_t)Round(x)); }
247251
GPUdi() bool GPUCommonMath::Finite(float x) { return CHOICE(std::isfinite(x), true, true); }
248252
GPUhdi() float GPUCommonMath::Sqrt(float x) { return CHOICE(sqrtf(x), sqrtf(x), sqrt(x)); }
249253
GPUdi() float GPUCommonMath::ATan(float x) { return CHOICE(atanf(x), atanf(x), atan(x)); }
@@ -283,12 +287,12 @@ GPUhdi() void GPUCommonMath::SinCosd(double x, double& s, double& c)
283287
#endif
284288
}
285289

286-
GPUdi() unsigned int GPUCommonMath::Clz(unsigned int x)
290+
GPUdi() uint32_t GPUCommonMath::Clz(uint32_t x)
287291
{
288292
#if (defined(__GNUC__) || defined(__clang__) || defined(__CUDACC__) || defined(__HIPCC__)) && (!defined(__OPENCL__) || defined(__OPENCLCPP__))
289293
return x == 0 ? 32 : CHOICE(__builtin_clz(x), __clz(x), __builtin_clz(x)); // use builtin if available
290294
#else
291-
for (int i = 31; i >= 0; i--) {
295+
for (int32_t i = 31; i >= 0; i--) {
292296
if (x & (1u << i)) {
293297
return (31 - i);
294298
}
@@ -297,7 +301,7 @@ GPUdi() unsigned int GPUCommonMath::Clz(unsigned int x)
297301
#endif
298302
}
299303

300-
GPUdi() unsigned int GPUCommonMath::Popcount(unsigned int x)
304+
GPUdi() uint32_t GPUCommonMath::Popcount(uint32_t x)
301305
{
302306
#if (defined(__GNUC__) || defined(__clang__) || defined(__CUDACC__) || defined(__HIPCC__)) && (!defined(__OPENCL__) /*|| defined(__OPENCLCPP__)*/) // TODO: remove OPENCLCPP workaround when reported SPIR-V bug is fixed
303307
// use builtin if available
@@ -404,7 +408,7 @@ GPUdi() float GPUCommonMath::InvSqrt(float _x)
404408
#else
405409
union {
406410
float f;
407-
int i;
411+
int32_t i;
408412
} x = {_x};
409413
const float xhalf = 0.5f * x.f;
410414
x.i = 0x5f3759df - (x.i >> 1);
@@ -428,7 +432,7 @@ GPUhdi() double GPUCommonMath::Abs<double>(double x)
428432
#endif
429433

430434
template <>
431-
GPUhdi() int GPUCommonMath::Abs<int>(int x)
435+
GPUhdi() int32_t GPUCommonMath::Abs<int32_t>(int32_t x)
432436
{
433437
return CHOICE(abs(x), abs(x), abs(x));
434438
}
@@ -448,7 +452,7 @@ GPUhdi() float GPUCommonMath::Copysign(float x, float y)
448452
}
449453

450454
template <class S, class T>
451-
GPUdi() unsigned int GPUCommonMath::AtomicExchInternal(S* addr, T val)
455+
GPUdi() uint32_t GPUCommonMath::AtomicExchInternal(S* addr, T val)
452456
{
453457
#if defined(GPUCA_GPUCODE) && defined(__OPENCLCPP__) && (!defined(__clang__) || defined(GPUCA_OPENCL_CPP_CLANG_C11_ATOMICS))
454458
return ::atomic_exchange(addr, val);
@@ -457,7 +461,7 @@ GPUdi() unsigned int GPUCommonMath::AtomicExchInternal(S* addr, T val)
457461
#elif defined(GPUCA_GPUCODE) && (defined(__CUDACC__) || defined(__HIPCC__))
458462
return ::atomicExch(addr, val);
459463
#elif defined(WITH_OPENMP)
460-
unsigned int old;
464+
uint32_t old;
461465
__atomic_exchange(addr, &val, &old, __ATOMIC_SEQ_CST);
462466
return old;
463467
#else
@@ -482,7 +486,7 @@ GPUdi() bool GPUCommonMath::AtomicCASInternal(S* addr, T cmp, T val)
482486
}
483487

484488
template <class S, class T>
485-
GPUdi() unsigned int GPUCommonMath::AtomicAddInternal(S* addr, T val)
489+
GPUdi() uint32_t GPUCommonMath::AtomicAddInternal(S* addr, T val)
486490
{
487491
#if defined(GPUCA_GPUCODE) && defined(__OPENCLCPP__) && (!defined(__clang__) || defined(GPUCA_OPENCL_CPP_CLANG_C11_ATOMICS))
488492
return ::atomic_fetch_add(addr, val);
@@ -538,9 +542,9 @@ GPUdii() void GPUCommonMath::AtomicMaxInternal(GPUglobalref() GPUgeneric() GPUAt
538542
val = 0.f;
539543
}
540544
if (val >= 0) {
541-
AtomicMaxInternal((GPUAtomic(int)*)addr, __float_as_int(val));
545+
AtomicMaxInternal((GPUAtomic(int32_t)*)addr, __float_as_int(val));
542546
} else {
543-
AtomicMinInternal((GPUAtomic(unsigned int)*)addr, __float_as_uint(val));
547+
AtomicMinInternal((GPUAtomic(uint32_t)*)addr, __float_as_uint(val));
544548
}
545549
}
546550
template <>
@@ -550,9 +554,9 @@ GPUdii() void GPUCommonMath::AtomicMinInternal(GPUglobalref() GPUgeneric() GPUAt
550554
val = 0.f;
551555
}
552556
if (val >= 0) {
553-
AtomicMinInternal((GPUAtomic(int)*)addr, __float_as_int(val));
557+
AtomicMinInternal((GPUAtomic(int32_t)*)addr, __float_as_int(val));
554558
} else {
555-
AtomicMaxInternal((GPUAtomic(unsigned int)*)addr, __float_as_uint(val));
559+
AtomicMaxInternal((GPUAtomic(uint32_t)*)addr, __float_as_uint(val));
556560
}
557561
}
558562
#endif

GPU/Common/GPUCommonRtypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#define ClassImp(name)
2727
#define templateClassImp(name)
2828
#ifndef GPUCA_GPUCODE_DEVICE
29-
// typedef unsigned long long ULong64_t;
30-
// typedef unsigned int UInt_t;
29+
// typedef uint64_t ULong64_t;
30+
// typedef uint32_t UInt_t;
3131
#include <iostream>
3232
#endif
3333
#endif

GPU/Common/GPUCommonTransform3D.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Transform3D
2727
Transform3D() = default;
2828
Transform3D(float* v)
2929
{
30-
for (int i = 0; i < 12; i++) {
30+
for (int32_t i = 0; i < 12; i++) {
3131
m[i] = v[i];
3232
}
3333
}

0 commit comments

Comments
 (0)