Project
Loading...
Searching...
No Matches
TimeFrameGPU.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.
12
13#ifndef TRACKINGITSGPU_INCLUDE_TIMEFRAMEGPU_H
14#define TRACKINGITSGPU_INCLUDE_TIMEFRAMEGPU_H
15
20
21#include <gsl/gsl>
22
23namespace o2::its::gpu
24{
25
26class Stream;
27
29{
30 void* allocate(size_t size) override;
31};
32
33template <int nLayers = 7>
34class TimeFrameGPU : public TimeFrame<nLayers>
35{
36 public:
39
41 void registerHostMemory(const int);
42 void unregisterHostMemory(const int);
43 void initialise(const int, const TrackingParameters&, const int, IndexTableUtils* utils = nullptr, const TimeFrameGPUParameters* pars = nullptr);
44 void initDevice(IndexTableUtils*, const TrackingParameters& trkParam, const TimeFrameGPUParameters&, const int, const int);
46 void loadIndexTableUtils(const int);
49 void loadClustersDevice(const int);
50 void loadClustersIndexTables(const int iteration);
51 void createUsedClustersDevice(const int);
54 void loadMultiplicityCutMask(const int);
55 void loadVertices(const int);
56
58 void createTrackletsLUTDevice(const int);
68 void createCellsBuffers(const int);
72 void createNeighboursDevice(const unsigned int layer, const unsigned int nNeighbours);
73 void createNeighboursDevice(const unsigned int layer, std::vector<std::pair<int, int>>& neighbours);
74 void createNeighboursLUTDevice(const int, const unsigned int);
78 void downloadCellsNeighboursDevice(std::vector<bounded_vector<std::pair<int, int>>>&, const int);
83 template <Task task>
84 Stream& getStream(const size_t stream)
85 {
86 return *mGpuStreams[stream];
87 }
88 void wipe(const int);
89
91 int getNClustersInRofSpan(const int, const int, const int) const;
92 IndexTableUtils* getDeviceIndexTableUtils() { return mIndexTableUtilsDevice; }
93 int* getDeviceROFramesClusters(const int layer) { return mROFramesClustersDevice[layer]; }
94 auto& getTrackITSExt() { return mTrackITSExt; }
95 Vertex* getDeviceVertices() { return mPrimaryVerticesDevice; }
96 int* getDeviceROFramesPV() { return mROFramesPVDevice; }
97 unsigned char* getDeviceUsedClusters(const int);
99
100 // Hybrid
101 Road<nLayers - 2>* getDeviceRoads() { return mRoadsDevice; }
102 TrackITSExt* getDeviceTrackITSExt() { return mTrackITSExtDevice; }
103 int* getDeviceNeighboursLUT(const int layer) { return mNeighboursLUTDevice[layer]; }
104 gsl::span<int*> getDeviceNeighboursLUTs() { return mNeighboursLUTDevice; }
105 gpuPair<int, int>* getDeviceNeighbourPairs(const int layer) { return mNeighbourPairsDevice[layer]; }
106 std::array<int*, nLayers - 2>& getDeviceNeighboursAll() { return mNeighboursDevice; }
107 int* getDeviceNeighbours(const int layer) { return mNeighboursDevice[layer]; }
108 int** getDeviceNeighboursArray() { return mNeighboursDeviceArray; }
110 const TrackingFrameInfo** getDeviceArrayTrackingFrameInfo() const { return mTrackingFrameInfoDeviceArray; }
111 const Cluster** getDeviceArrayClusters() const { return mClustersDeviceArray; }
112 const Cluster** getDeviceArrayUnsortedClusters() const { return mUnsortedClustersDeviceArray; }
113 const int** getDeviceArrayClustersIndexTables() const { return mClustersIndexTablesDeviceArray; }
114 std::vector<unsigned int> getClusterSizes();
115 const unsigned char** getDeviceArrayUsedClusters() const { return mUsedClustersDeviceArray; }
116 const int** getDeviceROframeClusters() const { return mROFrameClustersDeviceArray; }
117 Tracklet** getDeviceArrayTracklets() { return mTrackletsDeviceArray; }
118 int** getDeviceArrayTrackletsLUT() const { return mTrackletsLUTDeviceArray; }
119 int** getDeviceArrayCellsLUT() const { return mCellsLUTDeviceArray; }
120 int** getDeviceArrayNeighboursCellLUT() const { return mNeighboursCellLUTDeviceArray; }
121 CellSeed** getDeviceArrayCells() const { return mCellsDeviceArray; }
122 CellSeed* getDeviceTrackSeeds() { return mTrackSeedsDevice; }
123 o2::track::TrackParCovF** getDeviceArrayTrackSeeds() { return mCellSeedsDeviceArray; }
124 float** getDeviceArrayTrackSeedsChi2() { return mCellSeedsChi2DeviceArray; }
125 int* getDeviceNeighboursIndexTables(const int layer) { return mNeighboursIndexTablesDevice[layer]; }
126 uint8_t* getDeviceMultCutMask() { return mMultMaskDevice; }
127
129
130 // Host-specific getters
131 gsl::span<int, nLayers - 1> getNTracklets() { return mNTracklets; }
132 gsl::span<int, nLayers - 2> getNCells() { return mNCells; }
133 auto& getArrayNCells() { return mNCells; }
134 gsl::span<int, nLayers - 3> getNNeighbours() { return mNNeighbours; }
135 auto& getArrayNNeighbours() { return mNNeighbours; }
136
137 // Host-available device getters
138 gsl::span<int*> getDeviceTrackletsLUTs() { return mTrackletsLUTDevice; }
139 gsl::span<int*> getDeviceCellLUTs() { return mCellsLUTDevice; }
140 gsl::span<Tracklet*> getDeviceTracklet() { return mTrackletsDevice; }
141 gsl::span<CellSeed*> getDeviceCells() { return mCellsDevice; }
142
143 // Overridden getters
144 int getNumberOfTracklets() const final;
145 int getNumberOfCells() const final;
146 int getNumberOfNeighbours() const final;
147
148 private:
149 void allocMemAsync(void**, size_t, Stream*, bool); // Abstract owned and unowned memory allocations
150 bool mHostRegistered = false;
151 TimeFrameGPUParameters mGpuParams;
152
153 // Host-available device buffer sizes
154 std::array<int, nLayers - 1> mNTracklets;
155 std::array<int, nLayers - 2> mNCells;
156 std::array<int, nLayers - 3> mNNeighbours;
157
158 // Device pointers
159 IndexTableUtils* mIndexTableUtilsDevice;
160
161 // Hybrid pref
162 uint8_t* mMultMaskDevice;
163 Vertex* mPrimaryVerticesDevice;
164 int* mROFramesPVDevice;
165 std::array<Cluster*, nLayers> mClustersDevice;
166 std::array<Cluster*, nLayers> mUnsortedClustersDevice;
167 std::array<int*, nLayers> mClustersIndexTablesDevice;
168 std::array<unsigned char*, nLayers> mUsedClustersDevice;
169 std::array<int*, nLayers> mROFramesClustersDevice;
170 const Cluster** mClustersDeviceArray;
171 const Cluster** mUnsortedClustersDeviceArray;
172 const int** mClustersIndexTablesDeviceArray;
173 const unsigned char** mUsedClustersDeviceArray;
174 const int** mROFrameClustersDeviceArray;
175 std::array<Tracklet*, nLayers - 1> mTrackletsDevice;
176 Tracklet** mTrackletsDeviceArray;
177 std::array<int*, nLayers - 1> mTrackletsLUTDevice;
178 std::array<int*, nLayers - 2> mCellsLUTDevice;
179 std::array<int*, nLayers - 3> mNeighboursLUTDevice;
180
181 int** mCellsLUTDeviceArray;
182 int** mNeighboursCellDeviceArray;
183 int** mNeighboursCellLUTDeviceArray;
184 int** mTrackletsLUTDeviceArray;
185 std::array<CellSeed*, nLayers - 2> mCellsDevice;
186 std::array<int*, nLayers - 2> mNeighboursIndexTablesDevice;
187 CellSeed* mTrackSeedsDevice;
188 CellSeed** mCellsDeviceArray;
189 std::array<o2::track::TrackParCovF*, nLayers - 2> mCellSeedsDevice;
190 o2::track::TrackParCovF** mCellSeedsDeviceArray;
191 std::array<float*, nLayers - 2> mCellSeedsChi2Device;
192 float** mCellSeedsChi2DeviceArray;
193
194 Road<nLayers - 2>* mRoadsDevice;
195 TrackITSExt* mTrackITSExtDevice;
196 std::array<gpuPair<int, int>*, nLayers - 2> mNeighbourPairsDevice;
197 std::array<int*, nLayers - 2> mNeighboursDevice;
198 int** mNeighboursDeviceArray;
199 std::array<TrackingFrameInfo*, nLayers> mTrackingFrameInfoDevice;
200 const TrackingFrameInfo** mTrackingFrameInfoDeviceArray;
201
202 // State
203 std::vector<Stream*> mGpuStreams;
204 size_t mAvailMemGB;
205 bool mFirstInit = true;
206
207 // Temporary buffer for storing output tracks from GPU tracking
208 bounded_vector<TrackITSExt> mTrackITSExt;
209};
210
211template <int nLayers>
212inline int TimeFrameGPU<nLayers>::getNClustersInRofSpan(const int rofIdstart, const int rofSpanSize, const int layerId) const
213{
214 return static_cast<int>(this->mROFramesClusters[layerId][(rofIdstart + rofSpanSize) < this->mROFramesClusters.size() ? rofIdstart + rofSpanSize : this->mROFramesClusters.size() - 1] - this->mROFramesClusters[layerId][rofIdstart]);
215}
216
217template <int nLayers>
218inline std::vector<unsigned int> TimeFrameGPU<nLayers>::getClusterSizes()
219{
220 std::vector<unsigned int> sizes(this->mUnsortedClusters.size());
221 std::transform(this->mUnsortedClusters.begin(), this->mUnsortedClusters.end(), sizes.begin(),
222 [](const auto& v) { return static_cast<unsigned int>(v.size()); });
223 return sizes;
224}
225
226template <int nLayers>
228{
229 return std::accumulate(mNTracklets.begin(), mNTracklets.end(), 0);
230}
231
232template <int nLayers>
234{
235 return std::accumulate(mNCells.begin(), mNCells.end(), 0);
236}
237
238template <int nLayers>
240{
241 return std::accumulate(mNNeighbours.begin(), mNNeighbours.end(), 0);
242}
243
244} // namespace o2::its::gpu
245
246#endif
const TrackingFrameInfo ** getDeviceArrayTrackingFrameInfo() const
gsl::span< int * > getDeviceCellLUTs()
void createNeighboursDevice(const unsigned int layer, const unsigned int nNeighbours)
void loadROframeClustersDevice(const int)
IndexTableUtils * getDeviceIndexTableUtils()
const unsigned char ** getDeviceArrayUsedClusters() const
const int ** getDeviceArrayClustersIndexTables() const
void initDevice(IndexTableUtils *, const TrackingParameters &trkParam, const TimeFrameGPUParameters &, const int, const int)
void initialise(const int, const TrackingParameters &, const int, IndexTableUtils *utils=nullptr, const TimeFrameGPUParameters *pars=nullptr)
const Cluster ** getDeviceArrayUnsortedClusters() const
void loadTrackingFrameInfoDevice(const int)
int * getDeviceNeighbours(const int layer)
int * getDeviceNeighboursIndexTables(const int layer)
void loadIndexTableUtils(const int)
float ** getDeviceArrayTrackSeedsChi2()
void createNeighboursLUTDevice(const int, const unsigned int)
Tracklet ** getDeviceArrayTracklets()
TrackingFrameInfo * getDeviceTrackingFrameInfo(const int)
void createTrackletsLUTDevice(const int)
int getNClustersInRofSpan(const int, const int, const int) const
interface
gsl::span< int, nLayers - 2 > getNCells()
void setDevicePropagator(const o2::base::PropagatorImpl< float > *) override
std::array< int *, nLayers - 2 > & getDeviceNeighboursAll()
gsl::span< Tracklet * > getDeviceTracklet()
CellSeed ** getDeviceArrayCells() const
void createTrackITSExtDevice(bounded_vector< CellSeed > &)
void downloadNeighboursLUTDevice(bounded_vector< int > &, const int)
void createNeighboursDevice(const unsigned int layer, std::vector< std::pair< int, int > > &neighbours)
void loadVertices(const int)
int * getDeviceNeighboursLUT(const int layer)
Road< nLayers - 2 > * getDeviceRoads()
void registerHostMemory(const int)
Most relevant operations.
void loadClustersIndexTables(const int iteration)
o2::track::TrackParCovF ** getDeviceArrayTrackSeeds()
int getNumberOfCells() const final
gsl::span< int * > getDeviceNeighboursLUTs()
std::vector< unsigned int > getClusterSizes()
const o2::base::Propagator * getChainPropagator()
int ** getDeviceArrayNeighboursCellLUT() const
void createUsedClustersDevice(const int)
const int ** getDeviceROframeClusters() const
gsl::span< CellSeed * > getDeviceCells()
int ** getDeviceArrayTrackletsLUT() const
void loadTrackSeedsDevice(bounded_vector< CellSeed > &)
int getNumberOfTracklets() const final
gsl::span< int * > getDeviceTrackletsLUTs()
void downloadCellsNeighboursDevice(std::vector< bounded_vector< std::pair< int, int > > > &, const int)
void createCellsBuffers(const int)
unsigned char * getDeviceUsedClusters(const int)
gpuPair< int, int > * getDeviceNeighbourPairs(const int layer)
void loadClustersDevice(const int)
Stream & getStream(const size_t stream)
TrackITSExt * getDeviceTrackITSExt()
void loadMultiplicityCutMask(const int)
int ** getDeviceArrayCellsLUT() const
void loadUnsortedClustersDevice(const int)
gsl::span< int, nLayers - 3 > getNNeighbours()
int * getDeviceROFramesClusters(const int layer)
const Cluster ** getDeviceArrayClusters() const
void unregisterHostMemory(const int)
int getNumberOfNeighbours() const final
void downloadTrackITSExtDevice(bounded_vector< CellSeed > &)
gsl::span< int, nLayers - 1 > getNTracklets()
GLsizeiptr size
Definition glcorearb.h:659
const GLdouble * v
Definition glcorearb.h:832
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition glcorearb.h:2595
GLenum array
Definition glcorearb.h:4274
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLuint GLuint stream
Definition glcorearb.h:1806
std::pmr::vector< T > bounded_vector
TrackParametrizationWithError< float > TrackParCovF
Definition Track.h:31
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
Common utility functions.
std::array< bounded_vector< int >, nLayers > mROFramesClusters
Definition TimeFrame.h:280
std::array< bounded_vector< Cluster >, nLayers > mUnsortedClusters
Definition TimeFrame.h:299