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
18
24
25#include <gsl/gsl>
26
27namespace o2
28{
29namespace its
30{
31namespace gpu
32{
33
35{
36 void* allocate(size_t size) override;
37};
38
39template <int nLayers = 7>
40class TimeFrameGPU : public TimeFrame
41{
42 friend class GpuTimeFrameChunk<nLayers>;
43
44 public:
47
49 void registerHostMemory(const int);
50 void unregisterHostMemory(const int);
51 void initialise(const int, const TrackingParameters&, const int, IndexTableUtils* utils = nullptr, const TimeFrameGPUParameters* pars = nullptr);
52 void initDevice(IndexTableUtils*, const TrackingParameters& trkParam, const TimeFrameGPUParameters&, const int, const int);
54 void loadIndexTableUtils(const int);
57 void loadClustersDevice(const int);
58 void loadClustersIndexTables(const int iteration);
59 void createUsedClustersDevice(const int);
62 void loadMultiplicityCutMask(const int);
63 void loadVertices(const int);
64
66 void createTrackletsLUTDevice(const int);
74 void loadTrackSeedsDevice(std::vector<CellSeed>&);
76 void createCellsBuffers(const int);
80 void createNeighboursDevice(const unsigned int layer, const unsigned int nNeighbours);
81 void createNeighboursDevice(const unsigned int layer, std::vector<std::pair<int, int>>& neighbours);
82 void createNeighboursLUTDevice(const int, const unsigned int);
84 void createTrackITSExtDevice(std::vector<CellSeed>&);
85 void downloadTrackITSExtDevice(std::vector<CellSeed>&);
86 void downloadCellsNeighboursDevice(std::vector<std::vector<std::pair<int, int>>>&, const int);
87 void downloadNeighboursLUTDevice(std::vector<int>&, const int);
91 void initDeviceChunks(const int, const int);
92 template <Task task>
93 size_t loadChunkData(const size_t, const size_t, const size_t);
94 size_t getNChunks() const { return mMemChunks.size(); }
95 GpuTimeFrameChunk<nLayers>& getChunk(const int chunk) { return mMemChunks[chunk]; }
96 Stream& getStream(const size_t stream) { return mGpuStreams[stream]; }
97 void wipe(const int);
98
100 int getNClustersInRofSpan(const int, const int, const int) const;
101 IndexTableUtils* getDeviceIndexTableUtils() { return mIndexTableUtilsDevice; }
102 int* getDeviceROFramesClusters(const int layer) { return mROFramesClustersDevice[layer]; }
103 std::vector<std::vector<Vertex>>& getVerticesInChunks() { return mVerticesInChunks; }
104 std::vector<std::vector<int>>& getNVerticesInChunks() { return mNVerticesInChunks; }
105 std::vector<o2::its::TrackITSExt>& getTrackITSExt() { return mTrackITSExt; }
106 std::vector<std::vector<o2::MCCompLabel>>& getLabelsInChunks() { return mLabelsInChunks; }
107 int getNAllocatedROFs() const { return mNrof; } // Allocated means maximum nROF for each chunk while populated is the number of loaded ones.
109 Vertex* getDeviceVertices() { return mPrimaryVerticesDevice; }
110 int* getDeviceROFramesPV() { return mROFramesPVDevice; }
111 unsigned char* getDeviceUsedClusters(const int);
113
114 // Hybrid
115 Road<nLayers - 2>* getDeviceRoads() { return mRoadsDevice; }
116 TrackITSExt* getDeviceTrackITSExt() { return mTrackITSExtDevice; }
117 int* getDeviceNeighboursLUT(const int layer) { return mNeighboursLUTDevice[layer]; }
118 gsl::span<int*> getDeviceNeighboursLUTs() { return mNeighboursLUTDevice; }
119 gpuPair<int, int>* getDeviceNeighbourPairs(const int layer) { return mNeighbourPairsDevice[layer]; }
120 std::array<int*, nLayers - 2>& getDeviceNeighboursAll() { return mNeighboursDevice; }
121 int* getDeviceNeighbours(const int layer) { return mNeighboursDevice[layer]; }
122 int** getDeviceNeighboursArray() { return mNeighboursDeviceArray; }
123 TrackingFrameInfo* getDeviceTrackingFrameInfo(const int);
124 const TrackingFrameInfo** getDeviceArrayTrackingFrameInfo() const { return mTrackingFrameInfoDeviceArray; }
125 const Cluster** getDeviceArrayClusters() const { return mClustersDeviceArray; }
126 const Cluster** getDeviceArrayUnsortedClusters() const { return mUnsortedClustersDeviceArray; }
127 const int** getDeviceArrayClustersIndexTables() const { return mClustersIndexTablesDeviceArray; }
128 std::vector<unsigned int> getClusterSizes();
129 const unsigned char** getDeviceArrayUsedClusters() const { return mUsedClustersDeviceArray; }
130 const int** getDeviceROframeClusters() const { return mROFrameClustersDeviceArray; }
131 Tracklet** getDeviceArrayTracklets() { return mTrackletsDeviceArray; }
132 int** getDeviceArrayTrackletsLUT() const { return mTrackletsLUTDeviceArray; }
133 int** getDeviceArrayCellsLUT() const { return mCellsLUTDeviceArray; }
134 int** getDeviceArrayNeighboursCellLUT() const { return mNeighboursCellLUTDeviceArray; }
135 CellSeed** getDeviceArrayCells() const { return mCellsDeviceArray; }
136 CellSeed* getDeviceTrackSeeds() { return mTrackSeedsDevice; }
137 o2::track::TrackParCovF** getDeviceArrayTrackSeeds() { return mCellSeedsDeviceArray; }
138 float** getDeviceArrayTrackSeedsChi2() { return mCellSeedsChi2DeviceArray; }
139 int* getDeviceNeighboursIndexTables(const int layer) { return mNeighboursIndexTablesDevice[layer]; }
140 uint8_t* getDeviceMultCutMask() { return mMultMaskDevice; }
141
143
144 // Host-specific getters
145 gsl::span<int, nLayers - 1> getNTracklets() { return mNTracklets; }
146 gsl::span<int, nLayers - 2> getNCells() { return mNCells; }
147 std::array<int, nLayers - 2>& getArrayNCells() { return mNCells; }
148
149 // Host-available device getters
150 gsl::span<int*> getDeviceTrackletsLUTs() { return mTrackletsLUTDevice; }
151 gsl::span<int*> getDeviceCellLUTs() { return mCellsLUTDevice; }
152 gsl::span<Tracklet*> getDeviceTracklet() { return mTrackletsDevice; }
153 gsl::span<CellSeed*> getDeviceCells() { return mCellsDevice; }
154
155 // Overridden getters
156 int getNumberOfCells() const;
157
158 private:
159 void allocMemAsync(void**, size_t, Stream*, bool); // Abstract owned and unowned memory allocations
160 bool mHostRegistered = false;
161 std::vector<GpuTimeFrameChunk<nLayers>> mMemChunks;
162 TimeFrameGPUParameters mGpuParams;
163 StaticTrackingParameters<nLayers> mStaticTrackingParams;
164
165 // Host-available device buffer sizes
166 std::array<int, nLayers - 1> mNTracklets;
167 std::array<int, nLayers - 2> mNCells;
168
169 // Device pointers
170 StaticTrackingParameters<nLayers>* mTrackingParamsDevice;
171 IndexTableUtils* mIndexTableUtilsDevice;
172
173 // Hybrid pref
174 uint8_t* mMultMaskDevice;
175 Vertex* mPrimaryVerticesDevice;
176 int* mROFramesPVDevice;
177 std::array<Cluster*, nLayers> mClustersDevice;
178 std::array<Cluster*, nLayers> mUnsortedClustersDevice;
179 std::array<int*, nLayers> mClustersIndexTablesDevice;
180 std::array<unsigned char*, nLayers> mUsedClustersDevice;
181 std::array<int*, nLayers> mROFramesClustersDevice;
182 const Cluster** mClustersDeviceArray;
183 const Cluster** mUnsortedClustersDeviceArray;
184 const int** mClustersIndexTablesDeviceArray;
185 const unsigned char** mUsedClustersDeviceArray;
186 const int** mROFrameClustersDeviceArray;
187 std::array<Tracklet*, nLayers - 1> mTrackletsDevice;
188 Tracklet** mTrackletsDeviceArray;
189 std::array<int*, nLayers - 1> mTrackletsLUTDevice;
190 std::array<int*, nLayers - 2> mCellsLUTDevice;
191 std::array<int*, nLayers - 3> mNeighboursLUTDevice;
192
193 int** mCellsLUTDeviceArray;
194 int** mNeighboursCellDeviceArray;
195 int** mNeighboursCellLUTDeviceArray;
196 int** mTrackletsLUTDeviceArray;
197 std::array<CellSeed*, nLayers - 2> mCellsDevice;
198 std::array<int*, nLayers - 2> mNeighboursIndexTablesDevice;
199 CellSeed* mTrackSeedsDevice;
200 CellSeed** mCellsDeviceArray;
201 std::array<o2::track::TrackParCovF*, nLayers - 2> mCellSeedsDevice;
202 o2::track::TrackParCovF** mCellSeedsDeviceArray;
203 std::array<float*, nLayers - 2> mCellSeedsChi2Device;
204 float** mCellSeedsChi2DeviceArray;
205
206 Road<nLayers - 2>* mRoadsDevice;
207 TrackITSExt* mTrackITSExtDevice;
208 std::array<gpuPair<int, int>*, nLayers - 2> mNeighbourPairsDevice;
209 std::array<int*, nLayers - 2> mNeighboursDevice;
210 int** mNeighboursDeviceArray;
211 std::array<TrackingFrameInfo*, nLayers> mTrackingFrameInfoDevice;
212 const TrackingFrameInfo** mTrackingFrameInfoDeviceArray;
213
214 // State
215 std::vector<Stream> mGpuStreams;
216 size_t mAvailMemGB;
217 bool mFirstInit = true;
218
219 // Output
220 std::vector<std::vector<Vertex>> mVerticesInChunks;
221 std::vector<std::vector<int>> mNVerticesInChunks;
222 std::vector<std::vector<o2::MCCompLabel>> mLabelsInChunks;
223
224 // Temporary buffer for storing output tracks from GPU tracking
225 std::vector<TrackITSExt> mTrackITSExt;
226};
227
228template <int nLayers>
229template <Task task>
230size_t TimeFrameGPU<nLayers>::loadChunkData(const size_t chunk, const size_t offset, const size_t maxRofs) // offset: readout frame to start from, maxRofs: to manage boundaries
231{
232 size_t nRof{0};
233
234 mMemChunks[chunk].reset(task, mGpuStreams[chunk]); // Reset chunks memory
235 if constexpr ((bool)task) {
236 nRof = mMemChunks[chunk].loadDataOnDevice(offset, maxRofs, 3, mGpuStreams[chunk]);
237 } else {
238 nRof = mMemChunks[chunk].loadDataOnDevice(offset, maxRofs, nLayers, mGpuStreams[chunk]);
239 }
240 LOGP(debug, "In chunk {}: loaded {} readout frames starting from {}", chunk, nRof, offset);
241 return nRof;
242}
243
244template <int nLayers>
245inline int TimeFrameGPU<nLayers>::getNClustersInRofSpan(const int rofIdstart, const int rofSpanSize, const int layerId) const
246{
247 return static_cast<int>(mROFramesClusters[layerId][(rofIdstart + rofSpanSize) < mROFramesClusters.size() ? rofIdstart + rofSpanSize : mROFramesClusters.size() - 1] - mROFramesClusters[layerId][rofIdstart]);
248}
249
250template <int nLayers>
251inline std::vector<unsigned int> TimeFrameGPU<nLayers>::getClusterSizes()
252{
253 std::vector<unsigned int> sizes(mUnsortedClusters.size());
254 std::transform(mUnsortedClusters.begin(), mUnsortedClusters.end(), sizes.begin(),
255 [](const auto& v) { return static_cast<unsigned int>(v.size()); });
256 return sizes;
257}
258
259template <int nLayers>
261{
262 return std::accumulate(mNCells.begin(), mNCells.end(), 0);
263}
264
265} // namespace gpu
266} // namespace its
267} // namespace o2
268#endif
GPU-compliant version of ClusterLines, for the moment separated, might create a common traits for Clu...
std::ostringstream debug
const TrackingFrameInfo ** getDeviceArrayTrackingFrameInfo() const
gsl::span< int * > getDeviceCellLUTs()
void createNeighboursDevice(const unsigned int layer, const unsigned int nNeighbours)
void loadROframeClustersDevice(const int)
Stream & getStream(const size_t stream)
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
GpuTimeFrameChunk< nLayers > & getChunk(const int chunk)
void loadTrackingFrameInfoDevice(const int)
int * getDeviceNeighbours(const int layer)
int * getDeviceNeighboursIndexTables(const int layer)
void downloadNeighboursLUTDevice(std::vector< int > &, const int)
void loadIndexTableUtils(const int)
float ** getDeviceArrayTrackSeedsChi2()
void createNeighboursLUTDevice(const int, const unsigned int)
Tracklet ** getDeviceArrayTracklets()
TrackingFrameInfo * getDeviceTrackingFrameInfo(const int)
std::vector< std::vector< Vertex > > & getVerticesInChunks()
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
void createTrackITSExtDevice(std::vector< CellSeed > &)
std::array< int *, nLayers - 2 > & getDeviceNeighboursAll()
gsl::span< Tracklet * > getDeviceTracklet()
CellSeed ** getDeviceArrayCells() const
void initDeviceChunks(const 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)
std::vector< o2::its::TrackITSExt > & getTrackITSExt()
Road< nLayers - 2 > * getDeviceRoads()
void registerHostMemory(const int)
Most relevant operations.
void loadClustersIndexTables(const int iteration)
std::vector< std::vector< int > > & getNVerticesInChunks()
o2::track::TrackParCovF ** getDeviceArrayTrackSeeds()
void downloadTrackITSExtDevice(std::vector< CellSeed > &)
gsl::span< int * > getDeviceNeighboursLUTs()
std::vector< unsigned int > getClusterSizes()
StaticTrackingParameters< nLayers > * getDeviceTrackingParameters()
const o2::base::Propagator * getChainPropagator()
int ** getDeviceArrayNeighboursCellLUT() const
void createUsedClustersDevice(const int)
const int ** getDeviceROframeClusters() const
gsl::span< CellSeed * > getDeviceCells()
int ** getDeviceArrayTrackletsLUT() const
size_t loadChunkData(const size_t, const size_t, const size_t)
gsl::span< int * > getDeviceTrackletsLUTs()
void createCellsBuffers(const int)
unsigned char * getDeviceUsedClusters(const int)
gpuPair< int, int > * getDeviceNeighbourPairs(const int layer)
std::array< int, nLayers - 2 > & getArrayNCells()
void loadClustersDevice(const int)
TrackITSExt * getDeviceTrackITSExt()
void loadMultiplicityCutMask(const int)
int ** getDeviceArrayCellsLUT() const
void loadUnsortedClustersDevice(const int)
void loadTrackSeedsDevice(std::vector< CellSeed > &)
int * getDeviceROFramesClusters(const int layer)
const Cluster ** getDeviceArrayClusters() const
std::vector< std::vector< o2::MCCompLabel > > & getLabelsInChunks()
void downloadCellsNeighboursDevice(std::vector< std::vector< std::pair< int, int > > > &, const int)
void unregisterHostMemory(const int)
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
GLintptr offset
Definition glcorearb.h:660
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLuint GLuint stream
Definition glcorearb.h:1806
TrackParametrizationWithError< float > TrackParCovF
Definition Track.h:31
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Common utility functions.