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
16#include <gsl/gsl>
17#include <bitset>
18
23
24namespace o2::its::gpu
25{
26
27template <int nLayers = 7>
28class TimeFrameGPU final : public TimeFrame<nLayers>
29{
30 using typename TimeFrame<nLayers>::CellSeedN;
32
33 public:
34 TimeFrameGPU() = default;
35 ~TimeFrameGPU() = default;
36
38 void registerHostMemory(const int);
39 void unregisterHostMemory(const int);
40 void initialise(const int, const TrackingParameters&, const int, IndexTableUtilsN* utils = nullptr, const TimeFrameGPUParameters* pars = nullptr);
41 void initDevice(IndexTableUtilsN*, const TrackingParameters& trkParam, const TimeFrameGPUParameters&, const int, const int);
43 void loadIndexTableUtils(const int);
44 void loadTrackingFrameInfoDevice(const int, const int);
46 void loadUnsortedClustersDevice(const int, const int);
47 void createUnsortedClustersDeviceArray(const int, const int = nLayers);
48 void loadClustersDevice(const int, const int);
49 void createClustersDeviceArray(const int, const int = nLayers);
50 void loadClustersIndexTables(const int, const int);
52 void createUsedClustersDevice(const int, const int);
53 void createUsedClustersDeviceArray(const int, const int = nLayers);
55 void loadROFrameClustersDevice(const int, const int);
57 void loadMultiplicityCutMask(const int);
58 void loadVertices(const int);
59
61 void createTrackletsLUTDevice(const int, const int);
71 void createTrackletsBuffers(const int);
73 void createCellsBuffers(const int);
74 void createCellsBuffersArray(const int);
76 void createCellsLUTDevice(const int);
79 void createNeighboursDevice(const unsigned int layer);
80 void createNeighboursLUTDevice(const int, const unsigned int);
83 void downloadCellsNeighboursDevice(std::vector<bounded_vector<std::pair<int, int>>>&, const int);
87
89 void createVtxTrackletsLUTDevice(const int32_t);
90 void createVtxTrackletsBuffers(const int32_t);
91 void createVtxLinesLUTDevice(const int32_t);
92 void createVtxLinesBuffer(const int32_t);
93
95 auto& getStream(const size_t stream) { return mGpuStreams[stream]; }
96 auto& getStreams() { return mGpuStreams; }
97 void syncStream(const size_t stream);
98 void syncStreams(const bool = true);
99 void waitEvent(const int, const int);
100 void recordEvent(const int);
101 void recordEvents(const int = 0, const int = nLayers);
102
104 virtual void wipe() final;
105
107 virtual bool isGPU() const noexcept final { return true; }
108 virtual const char* getName() const noexcept { return "GPU"; }
109 int getNClustersInRofSpan(const int, const int, const int) const;
110 IndexTableUtilsN* getDeviceIndexTableUtils() { return mIndexTableUtilsDevice; }
111 int* getDeviceROFramesClusters(const int layer) { return mROFramesClustersDevice[layer]; }
112 auto& getTrackITSExt() { return mTrackITSExt; }
113 Vertex* getDeviceVertices() { return mPrimaryVerticesDevice; }
114 int* getDeviceROFramesPV() { return mROFramesPVDevice; }
115 unsigned char* getDeviceUsedClusters(const int);
117
118 // Hybrid
119 Road<nLayers - 2>* getDeviceRoads() { return mRoadsDevice; }
120 TrackITSExt* getDeviceTrackITSExt() { return mTrackITSExtDevice; }
121 int* getDeviceNeighboursLUT(const int layer) { return mNeighboursLUTDevice[layer]; }
122 gsl::span<int*> getDeviceNeighboursLUTs() { return mNeighboursLUTDevice; }
123 gpuPair<int, int>* getDeviceNeighbourPairs(const int layer) { return mNeighbourPairsDevice[layer]; }
124 std::array<int*, nLayers - 2>& getDeviceNeighboursAll() { return mNeighboursDevice; }
125 int* getDeviceNeighbours(const int layer) { return mNeighboursDevice[layer]; }
126 int** getDeviceNeighboursArray() { return mNeighboursDevice.data(); }
128 const TrackingFrameInfo** getDeviceArrayTrackingFrameInfo() const { return mTrackingFrameInfoDeviceArray; }
129 const Cluster** getDeviceArrayClusters() const { return mClustersDeviceArray; }
130 const Cluster** getDeviceArrayUnsortedClusters() const { return mUnsortedClustersDeviceArray; }
131 const int** getDeviceArrayClustersIndexTables() const { return mClustersIndexTablesDeviceArray; }
132 std::vector<unsigned int> getClusterSizes();
133 uint8_t** getDeviceArrayUsedClusters() const { return mUsedClustersDeviceArray; }
134 const int** getDeviceROFrameClusters() const { return mROFramesClustersDeviceArray; }
135 Tracklet** getDeviceArrayTracklets() { return mTrackletsDeviceArray; }
136 int** getDeviceArrayTrackletsLUT() const { return mTrackletsLUTDeviceArray; }
137 int** getDeviceArrayCellsLUT() const { return mCellsLUTDeviceArray; }
138 int** getDeviceArrayNeighboursCellLUT() const { return mNeighboursCellLUTDeviceArray; }
139 CellSeedN** getDeviceArrayCells() { return mCellsDeviceArray; }
140 CellSeedN* getDeviceTrackSeeds() { return mTrackSeedsDevice; }
141 o2::track::TrackParCovF** getDeviceArrayTrackSeeds() { return mCellSeedsDeviceArray; }
142 float** getDeviceArrayTrackSeedsChi2() { return mCellSeedsChi2DeviceArray; }
143 int* getDeviceNeighboursIndexTables(const int layer) { return mNeighboursIndexTablesDevice[layer]; }
144 uint8_t* getDeviceMultCutMask() { return mMultMaskDevice; }
145
146 // Vertexer
147 auto& getDeviceNTrackletsPerROF() const noexcept { return mNTrackletsPerROFDevice; }
148 auto& getDeviceNTrackletsPerCluster() const noexcept { return mNTrackletsPerClusterDevice; }
149 auto& getDeviceNTrackletsPerClusterSum() const noexcept { return mNTrackletsPerClusterSumDevice; }
150 int32_t** getDeviceArrayNTrackletsPerROF() const noexcept { return mNTrackletsPerROFDeviceArray; }
151 int32_t** getDeviceArrayNTrackletsPerCluster() const noexcept { return mNTrackletsPerClusterDeviceArray; }
152 int32_t** getDeviceArrayNTrackletsPerClusterSum() const noexcept { return mNTrackletsPerClusterSumDeviceArray; }
153 uint8_t* getDeviceUsedTracklets() const noexcept { return mUsedTrackletsDevice; }
154 int32_t* getDeviceNLinesPerCluster() const noexcept { return mNLinesPerClusterDevice; }
155 int32_t* getDeviceNLinesPerClusterSum() const noexcept { return mNLinesPerClusterSumDevice; }
156 Line* getDeviceLines() const noexcept { return mLinesDevice; }
157 gsl::span<int*> getDeviceTrackletsPerROFs() { return mNTrackletsPerROFDevice; }
158
160
161 // Host-specific getters
162 gsl::span<int, nLayers - 1> getNTracklets() { return mNTracklets; }
163 gsl::span<int, nLayers - 2> getNCells() { return mNCells; }
164 auto& getArrayNCells() { return mNCells; }
165 gsl::span<int, nLayers - 3> getNNeighbours() { return mNNeighbours; }
166 auto& getArrayNNeighbours() { return mNNeighbours; }
167
168 // Host-available device getters
169 gsl::span<int*> getDeviceTrackletsLUTs() { return mTrackletsLUTDevice; }
170 gsl::span<int*> getDeviceCellLUTs() { return mCellsLUTDevice; }
171 gsl::span<Tracklet*> getDeviceTracklets() { return mTrackletsDevice; }
172 gsl::span<CellSeedN*> getDeviceCells() { return mCellsDevice; }
173
174 // Overridden getters
175 int getNumberOfTracklets() const final;
176 int getNumberOfCells() const final;
177 int getNumberOfNeighbours() const final;
178
179 private:
180 void allocMemAsync(void**, size_t, Stream&, bool); // Abstract owned and unowned memory allocations on specific stream
181 void allocMem(void**, size_t, bool); // Abstract owned and unowned memory allocations on default stream
182 TimeFrameGPUParameters mGpuParams;
183
184 // Host-available device buffer sizes
185 std::array<int, nLayers - 1> mNTracklets;
186 std::array<int, nLayers - 2> mNCells;
187 std::array<int, nLayers - 3> mNNeighbours;
188
189 // Device pointers
190 IndexTableUtilsN* mIndexTableUtilsDevice;
191
192 // Hybrid pref
193 uint8_t* mMultMaskDevice;
194 Vertex* mPrimaryVerticesDevice;
195 int* mROFramesPVDevice;
196 std::array<Cluster*, nLayers> mClustersDevice;
197 std::array<Cluster*, nLayers> mUnsortedClustersDevice;
198 std::array<int*, nLayers> mClustersIndexTablesDevice;
199 std::array<unsigned char*, nLayers> mUsedClustersDevice;
200 std::array<int*, nLayers> mROFramesClustersDevice;
201 const Cluster** mClustersDeviceArray;
202 const Cluster** mUnsortedClustersDeviceArray;
203 const int** mClustersIndexTablesDeviceArray;
204 uint8_t** mUsedClustersDeviceArray;
205 const int** mROFramesClustersDeviceArray;
206 std::array<Tracklet*, nLayers - 1> mTrackletsDevice;
207 std::array<int*, nLayers - 1> mTrackletsLUTDevice;
208 std::array<int*, nLayers - 2> mCellsLUTDevice;
209 std::array<int*, nLayers - 3> mNeighboursLUTDevice;
210
211 Tracklet** mTrackletsDeviceArray{nullptr};
212 int** mCellsLUTDeviceArray{nullptr};
213 int** mNeighboursCellDeviceArray{nullptr};
214 int** mNeighboursCellLUTDeviceArray{nullptr};
215 int** mTrackletsLUTDeviceArray{nullptr};
216 std::array<CellSeedN*, nLayers - 2> mCellsDevice;
217 CellSeedN** mCellsDeviceArray;
218 std::array<int*, nLayers - 3> mNeighboursIndexTablesDevice;
219 CellSeedN* mTrackSeedsDevice{nullptr};
220 std::array<o2::track::TrackParCovF*, nLayers - 2> mCellSeedsDevice;
221 o2::track::TrackParCovF** mCellSeedsDeviceArray;
222 std::array<float*, nLayers - 2> mCellSeedsChi2Device;
223 float** mCellSeedsChi2DeviceArray;
224
225 Road<nLayers - 2>* mRoadsDevice;
226 TrackITSExt* mTrackITSExtDevice;
227 std::array<gpuPair<int, int>*, nLayers - 2> mNeighbourPairsDevice;
228 std::array<int*, nLayers - 2> mNeighboursDevice;
229 std::array<TrackingFrameInfo*, nLayers> mTrackingFrameInfoDevice;
230 const TrackingFrameInfo** mTrackingFrameInfoDeviceArray;
231
233 std::array<int32_t*, 2> mNTrackletsPerROFDevice;
234 std::array<int32_t*, 2> mNTrackletsPerClusterDevice;
235 std::array<int32_t*, 2> mNTrackletsPerClusterSumDevice;
236 uint8_t* mUsedTrackletsDevice;
237 int32_t* mNLinesPerClusterDevice;
238 int32_t* mNLinesPerClusterSumDevice;
239 int32_t** mNTrackletsPerROFDeviceArray;
240 int32_t** mNTrackletsPerClusterDeviceArray;
241 int32_t** mNTrackletsPerClusterSumDeviceArray;
242 Line* mLinesDevice;
243
244 // State
245 Streams mGpuStreams;
246 std::bitset<nLayers + 1> mPinnedUnsortedClusters{0};
247 std::bitset<nLayers + 1> mPinnedClusters{0};
248 std::bitset<nLayers + 1> mPinnedClustersIndexTables{0};
249 std::bitset<nLayers + 1> mPinnedUsedClusters{0};
250 std::bitset<nLayers + 1> mPinnedROFramesClusters{0};
251 std::bitset<nLayers + 1> mPinnedTrackingFrameInfo{0};
252
253 // Temporary buffer for storing output tracks from GPU tracking
254 bounded_vector<TrackITSExt> mTrackITSExt;
255};
256
257template <int nLayers>
258inline int TimeFrameGPU<nLayers>::getNClustersInRofSpan(const int rofIdstart, const int rofSpanSize, const int layerId) const
259{
260 return static_cast<int>(this->mROFramesClusters[layerId][(rofIdstart + rofSpanSize) < this->mROFramesClusters.size() ? rofIdstart + rofSpanSize : this->mROFramesClusters.size() - 1] - this->mROFramesClusters[layerId][rofIdstart]);
261}
262
263template <int nLayers>
264inline std::vector<unsigned int> TimeFrameGPU<nLayers>::getClusterSizes()
265{
266 std::vector<unsigned int> sizes(this->mUnsortedClusters.size());
267 std::transform(this->mUnsortedClusters.begin(), this->mUnsortedClusters.end(), sizes.begin(),
268 [](const auto& v) { return static_cast<unsigned int>(v.size()); });
269 return sizes;
270}
271
272template <int nLayers>
274{
275 return std::accumulate(mNTracklets.begin(), mNTracklets.end(), 0);
276}
277
278template <int nLayers>
280{
281 return std::accumulate(mNCells.begin(), mNCells.end(), 0);
282}
283
284template <int nLayers>
286{
287 return std::accumulate(mNNeighbours.begin(), mNNeighbours.end(), 0);
288}
289
290} // namespace o2::its::gpu
291
292#endif
const TrackingFrameInfo ** getDeviceArrayTrackingFrameInfo() const
gsl::span< int * > getDeviceCellLUTs()
uint8_t * getDeviceUsedTracklets() const noexcept
void initialise(const int, const TrackingParameters &, const int, IndexTableUtilsN *utils=nullptr, const TimeFrameGPUParameters *pars=nullptr)
gsl::span< CellSeedN * > getDeviceCells()
void createCellsBuffersArray(const int)
void loadTrackSeedsDevice(bounded_vector< CellSeedN > &)
const int ** getDeviceArrayClustersIndexTables() const
auto & getDeviceNTrackletsPerROF() const noexcept
auto & getDeviceNTrackletsPerClusterSum() const noexcept
virtual const char * getName() const noexcept
auto & getDeviceNTrackletsPerCluster() const noexcept
const Cluster ** getDeviceArrayUnsortedClusters() const
virtual bool isGPU() const noexcept final
interface
int * getDeviceNeighbours(const int layer)
int * getDeviceNeighboursIndexTables(const int layer)
void loadIndexTableUtils(const int)
virtual void wipe() final
cleanup
const int ** getDeviceROFrameClusters() const
float ** getDeviceArrayTrackSeedsChi2()
void createNeighboursLUTDevice(const int, const unsigned int)
Tracklet ** getDeviceArrayTracklets()
TrackingFrameInfo * getDeviceTrackingFrameInfo(const int)
int32_t ** getDeviceArrayNTrackletsPerCluster() const noexcept
void createClustersIndexTablesArray(const int)
void createTrackletsBuffersArray(const int)
int getNClustersInRofSpan(const int, const int, const int) const
gsl::span< int, nLayers - 2 > getNCells()
void loadTrackingFrameInfoDevice(const int, const int)
void syncStreams(const bool=true)
int32_t ** getDeviceArrayNTrackletsPerROF() const noexcept
std::array< int *, nLayers - 2 > & getDeviceNeighboursAll()
void createVtxLinesBuffer(const int32_t)
void createUnsortedClustersDeviceArray(const int, const int=nLayers)
void downloadNeighboursLUTDevice(bounded_vector< int > &, const int)
void loadVertices(const int)
void createCellsLUTDevice(const int)
int * getDeviceNeighboursLUT(const int layer)
void waitEvent(const int, const int)
Road< nLayers - 2 > * getDeviceRoads()
void createVtxTrackletsBuffers(const int32_t)
void createClustersDeviceArray(const int, const int=nLayers)
void createTrackITSExtDevice(bounded_vector< CellSeedN > &)
void loadClustersDevice(const int, const int)
void initDevice(IndexTableUtilsN *, const TrackingParameters &trkParam, const TimeFrameGPUParameters &, const int, const int)
void registerHostMemory(const int)
Most relevant operations.
o2::track::TrackParCovF ** getDeviceArrayTrackSeeds()
int getNumberOfCells() const final
void loadClustersIndexTables(const int, const int)
gsl::span< int * > getDeviceNeighboursLUTs()
std::vector< unsigned int > getClusterSizes()
const o2::base::Propagator * getChainPropagator()
void syncStream(const size_t stream)
void createVtxTrackletsLUTDevice(const int32_t)
Vertexer.
void createUsedClustersDeviceArray(const int, const int=nLayers)
int ** getDeviceArrayNeighboursCellLUT() const
CellSeedN ** getDeviceArrayCells()
int32_t * getDeviceNLinesPerClusterSum() const noexcept
void createVtxLinesLUTDevice(const int32_t)
void recordEvents(const int=0, const int=nLayers)
int ** getDeviceArrayTrackletsLUT() const
void setDevicePropagator(const o2::base::PropagatorImpl< float > *p) final
int getNumberOfTracklets() const final
gsl::span< int * > getDeviceTrackletsLUTs()
void downloadCellsNeighboursDevice(std::vector< bounded_vector< std::pair< int, int > > > &, const int)
void recordEvent(const int)
void createCellsBuffers(const int)
void createTrackingFrameInfoDeviceArray(const int)
unsigned char * getDeviceUsedClusters(const int)
gpuPair< int, int > * getDeviceNeighbourPairs(const int layer)
void createTrackletsLUTDevice(const int, const int)
void createTrackletsBuffers(const int)
void downloadTrackITSExtDevice(bounded_vector< CellSeedN > &)
gsl::span< Tracklet * > getDeviceTracklets()
TrackITSExt * getDeviceTrackITSExt()
void loadMultiplicityCutMask(const int)
int32_t ** getDeviceArrayNTrackletsPerClusterSum() const noexcept
void loadUnsortedClustersDevice(const int, const int)
auto & getStream(const size_t stream)
synchronization
int ** getDeviceArrayCellsLUT() const
IndexTableUtilsN * getDeviceIndexTableUtils()
int32_t * getDeviceNLinesPerCluster() const noexcept
void createNeighboursDevice(const unsigned int layer)
gsl::span< int, nLayers - 3 > getNNeighbours()
int * getDeviceROFramesClusters(const int layer)
const Cluster ** getDeviceArrayClusters() const
void createTrackletsLUTDeviceArray(const int)
CellSeedN * getDeviceTrackSeeds()
uint8_t ** getDeviceArrayUsedClusters() const
void unregisterHostMemory(const int)
Line * getDeviceLines() const noexcept
gsl::span< int * > getDeviceTrackletsPerROFs()
int getNumberOfNeighbours() const final
void createUsedClustersDevice(const int, const int)
void createNeighboursIndexTablesDevice(const int)
gsl::span< int, nLayers - 1 > getNTracklets()
void createROFrameClustersDeviceArray(const int)
void createCellsLUTDeviceArray(const int)
void loadROFrameClustersDevice(const int, const int)
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
uint8_t itsSharedClusterMap uint8_t
std::pair< T1, T2 > gpuPair
Definition Utils.h:54
std::pmr::vector< T > bounded_vector
TrackParametrizationWithError< float > TrackParCovF
Definition Track.h:31
constexpr int nLayers
Definition Specs.h:45
Defining DataPointCompositeObject explicitly as copiable.
Common utility functions.
const o2::base::PropagatorImpl< float > * mPropagatorDevice
Definition TimeFrame.h:306
CellSeed< nLayers > CellSeedN
Definition TimeFrame.h:69
IndexTableUtils< nLayers > IndexTableUtilsN
Definition TimeFrame.h:68