Project
Loading...
Searching...
No Matches
Utils.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.
15
16#ifndef ITSTRACKINGGPU_UTILS_H_
17#define ITSTRACKINGGPU_UTILS_H_
18
19#include "GPUCommonDef.h"
20#include "Stream.h"
21
22namespace o2
23{
24namespace its
25{
26template <typename T1, typename T2>
27struct gpuPair {
30};
31
32namespace gpu
33{
34// Poor man implementation of a span-like struct. It is very limited.
35template <typename T>
36struct gpuSpan {
37 using value_type = T;
38 using ptr = T*;
39 using ref = T&;
40
41 GPUd() gpuSpan() : _data(nullptr), _size(0) {}
42 GPUd() gpuSpan(ptr data, unsigned int dim) : _data(data), _size(dim) {}
43 GPUd() ref operator[](unsigned int idx) const { return _data[idx]; }
44 GPUd() unsigned int size() const { return _size; }
45 GPUd() bool empty() const { return _size == 0; }
46 GPUd() ref front() const { return _data[0]; }
47 GPUd() ref back() const { return _data[_size - 1]; }
48 GPUd() ptr begin() const { return _data; }
49 GPUd() ptr end() const { return _data + _size; }
50
51 protected:
53 unsigned int _size;
54};
55
56template <typename T>
57struct gpuSpan<const T> {
58 using value_type = T;
59 using ptr = const T*;
60 using ref = const T&;
61
62 GPUd() gpuSpan() : _data(nullptr), _size(0) {}
63 GPUd() gpuSpan(ptr data, unsigned int dim) : _data(data), _size(dim) {}
65 GPUd() ref operator[](unsigned int idx) const { return _data[idx]; }
66 GPUd() unsigned int size() const { return _size; }
67 GPUd() bool empty() const { return _size == 0; }
68 GPUd() ref front() const { return _data[0]; }
69 GPUd() ref back() const { return _data[_size - 1]; }
70 GPUd() ptr begin() const { return _data; }
71 GPUd() ptr end() const { return _data + _size; }
72
73 protected:
75 unsigned int _size;
76};
77
78enum class Task {
79 Tracker = 0,
80 Vertexer = 1
81};
82
83template <class T>
84GPUhd() T* getPtrFromRuler(int index, T* src, const int* ruler, const int stride = 1)
85{
86 return src + ruler[index] * stride;
87}
88
89template <class T>
90GPUhd() const T* getPtrFromRuler(int index, const T* src, const int* ruler, const int stride = 1)
91{
92 return src + ruler[index] * stride;
93}
94
95GPUh() void gpuThrowOnError();
96
97namespace utils
98{
99#ifdef __CUDACC__
100void checkGPUError(const cudaError_t error, const char* file = __FILE__, const int line = __LINE__);
101#endif
102#ifdef __HIPCC__
103void checkGPUError(const hipError_t error, const char* file = __FILE__, const int line = __LINE__);
104#endif
105
106// Dump device properties
107void getDeviceProp(int, bool verbose = true);
108
110dim3 getBlockSize(const int, const int);
111dim3 getBlockSize(const int, const int, const int);
112dim3 getBlocksGrid(const dim3&, const int);
113dim3 getBlocksGrid(const dim3&, const int, const int);
114
115void gpuMalloc(void**, const int);
116void gpuFree(void*);
117void gpuMemset(void*, int, int);
118void gpuMemcpyHostToDevice(void*, const void*, int);
119void gpuMemcpyDeviceToHost(void*, const void*, int);
120void gpuMemcpyToSymbol(const void* symbol, const void* src, int size);
121void gpuMemcpyFromSymbol(void* dst, const void* symbol, int size);
122
123GPUd() int getLaneIndex();
124GPUd() int shareToWarp(const int, const int);
125} // namespace utils
126} // namespace gpu
127} // namespace its
128} // namespace o2
129
130#endif
#define GPUh()
#define GPUd()
GLenum src
Definition glcorearb.h:1767
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
GLuint index
Definition glcorearb.h:781
GLenum GLenum dst
Definition glcorearb.h:1767
GLboolean * data
Definition glcorearb.h:298
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLint GLenum GLboolean GLsizei stride
Definition glcorearb.h:867
void gpuMemcpyHostToDevice(void *, const void *, int)
void gpuMemcpyFromSymbol(void *dst, const void *symbol, int size)
dim3 getBlockSize(const int)
void getDeviceProp(int, bool verbose=true)
void gpuMemset(void *, int, int)
void gpuFree(void *)
void gpuMemcpyToSymbol(const void *symbol, const void *src, int size)
dim3 getBlocksGrid(const dim3 &, const int)
void gpuMalloc(void **, const int)
void gpuMemcpyDeviceToHost(void *, const void *, int)
T const int * ruler
Definition Utils.h:84
T const int const int stride
Definition Utils.h:84
GPUhd() T *getPtrFromRuler(int index
Definition Vector.h:126
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Common utility functions.
void empty(int)
GPUd() gpuSpan(const gpuSpan< T > &other)
Definition Utils.h:64
GPUd() ref front() const
Definition Utils.h:68
GPUd() bool empty() const
Definition Utils.h:67
GPUd() ref operator[](unsigned int idx) const
Definition Utils.h:65
GPUd() ptr end() const
Definition Utils.h:71
GPUd() unsigned int size() const
Definition Utils.h:66
GPUd() ptr begin() const
Definition Utils.h:70
GPUd() ref back() const
Definition Utils.h:69
GPUd() bool empty() const
Definition Utils.h:45
unsigned int dim
Definition Utils.h:42
GPUd() ptr begin() const
Definition Utils.h:48
GPUd() ref operator[](unsigned int idx) const
Definition Utils.h:43
GPUd() gpuSpan()
Definition Utils.h:41
GPUd() ptr end() const
Definition Utils.h:49
GPUd() unsigned int size() const
Definition Utils.h:44
unsigned int _size
Definition Utils.h:53
GPUd() ref back() const
Definition Utils.h:47
GPUd() ref front() const
Definition Utils.h:46
VectorOfTObjectPtrs other