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 : public TimeFrame<nLayers>
29{
30 using typename TimeFrame<nLayers>::CellSeedN;
32
33 public:
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);
48 void loadClustersDevice(const int, const int);
50 void loadClustersIndexTables(const int, const int);
51 void createClustersIndexTablesArray(const int iteration);
52 void createUsedClustersDevice(const int, const int);
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 auto& getStream(const size_t stream) { return mGpuStreams[stream]; }
90 auto& getStreams() { return mGpuStreams; }
91 void syncStream(const size_t stream);
92 void syncStreams(const bool = true);
93 void waitEvent(const int, const int);
94 void recordEvent(const int);
95 void recordEvents(const int = 0, const int = nLayers);
96
98 virtual void wipe() final;
99
101 int getNClustersInRofSpan(const int, const int, const int) const;
102 IndexTableUtilsN* getDeviceIndexTableUtils() { return mIndexTableUtilsDevice; }
103 int* getDeviceROFramesClusters(const int layer) { return mROFramesClustersDevice[layer]; }
104 auto& getTrackITSExt() { return mTrackITSExt; }
105 Vertex* getDeviceVertices() { return mPrimaryVerticesDevice; }
106 int* getDeviceROFramesPV() { return mROFramesPVDevice; }
107 unsigned char* getDeviceUsedClusters(const int);
109
110 // Hybrid
111 Road<nLayers - 2>* getDeviceRoads() { return mRoadsDevice; }
112 TrackITSExt* getDeviceTrackITSExt() { return mTrackITSExtDevice; }
113 int* getDeviceNeighboursLUT(const int layer) { return mNeighboursLUTDevice[layer]; }
114 gsl::span<int*> getDeviceNeighboursLUTs() { return mNeighboursLUTDevice; }
115 gpuPair<int, int>* getDeviceNeighbourPairs(const int layer) { return mNeighbourPairsDevice[layer]; }
116 std::array<int*, nLayers - 2>& getDeviceNeighboursAll() { return mNeighboursDevice; }
117 int* getDeviceNeighbours(const int layer) { return mNeighboursDevice[layer]; }
118 int** getDeviceNeighboursArray() { return mNeighboursDevice.data(); }
120 const TrackingFrameInfo** getDeviceArrayTrackingFrameInfo() const { return mTrackingFrameInfoDeviceArray; }
121 const Cluster** getDeviceArrayClusters() const { return mClustersDeviceArray; }
122 const Cluster** getDeviceArrayUnsortedClusters() const { return mUnsortedClustersDeviceArray; }
123 const int** getDeviceArrayClustersIndexTables() const { return mClustersIndexTablesDeviceArray; }
124 std::vector<unsigned int> getClusterSizes();
125 const unsigned char** getDeviceArrayUsedClusters() const { return mUsedClustersDeviceArray; }
126 const int** getDeviceROFrameClusters() const { return mROFramesClustersDeviceArray; }
127 Tracklet** getDeviceArrayTracklets() { return mTrackletsDeviceArray; }
128 int** getDeviceArrayTrackletsLUT() const { return mTrackletsLUTDeviceArray; }
129 int** getDeviceArrayCellsLUT() const { return mCellsLUTDeviceArray; }
130 int** getDeviceArrayNeighboursCellLUT() const { return mNeighboursCellLUTDeviceArray; }
131 CellSeedN** getDeviceArrayCells() { return mCellsDeviceArray; }
132 CellSeedN* getDeviceTrackSeeds() { return mTrackSeedsDevice; }
133 o2::track::TrackParCovF** getDeviceArrayTrackSeeds() { return mCellSeedsDeviceArray; }
134 float** getDeviceArrayTrackSeedsChi2() { return mCellSeedsChi2DeviceArray; }
135 int* getDeviceNeighboursIndexTables(const int layer) { return mNeighboursIndexTablesDevice[layer]; }
136 uint8_t* getDeviceMultCutMask() { return mMultMaskDevice; }
137
139
140 // Host-specific getters
141 gsl::span<int, nLayers - 1> getNTracklets() { return mNTracklets; }
142 gsl::span<int, nLayers - 2> getNCells() { return mNCells; }
143 auto& getArrayNCells() { return mNCells; }
144 gsl::span<int, nLayers - 3> getNNeighbours() { return mNNeighbours; }
145 auto& getArrayNNeighbours() { return mNNeighbours; }
146
147 // Host-available device getters
148 gsl::span<int*> getDeviceTrackletsLUTs() { return mTrackletsLUTDevice; }
149 gsl::span<int*> getDeviceCellLUTs() { return mCellsLUTDevice; }
150 gsl::span<Tracklet*> getDeviceTracklets() { return mTrackletsDevice; }
151 gsl::span<CellSeedN*> getDeviceCells() { return mCellsDevice; }
152
153 // Overridden getters
154 int getNumberOfTracklets() const final;
155 int getNumberOfCells() const final;
156 int getNumberOfNeighbours() const final;
157
158 private:
159 void allocMemAsync(void**, size_t, Stream&, bool); // Abstract owned and unowned memory allocations on specific stream
160 void allocMem(void**, size_t, bool); // Abstract owned and unowned memory allocations on default stream
161 TimeFrameGPUParameters mGpuParams;
162
163 // Host-available device buffer sizes
164 std::array<int, nLayers - 1> mNTracklets;
165 std::array<int, nLayers - 2> mNCells;
166 std::array<int, nLayers - 3> mNNeighbours;
167
168 // Device pointers
169 IndexTableUtilsN* mIndexTableUtilsDevice;
170
171 // Hybrid pref
172 uint8_t* mMultMaskDevice;
173 Vertex* mPrimaryVerticesDevice;
174 int* mROFramesPVDevice;
175 std::array<Cluster*, nLayers> mClustersDevice;
176 std::array<Cluster*, nLayers> mUnsortedClustersDevice;
177 std::array<int*, nLayers> mClustersIndexTablesDevice;
178 std::array<unsigned char*, nLayers> mUsedClustersDevice;
179 std::array<int*, nLayers> mROFramesClustersDevice;
180 const Cluster** mClustersDeviceArray;
181 const Cluster** mUnsortedClustersDeviceArray;
182 const int** mClustersIndexTablesDeviceArray;
183 const unsigned char** mUsedClustersDeviceArray;
184 const int** mROFramesClustersDeviceArray;
185 std::array<Tracklet*, nLayers - 1> mTrackletsDevice;
186 std::array<int*, nLayers - 1> mTrackletsLUTDevice;
187 std::array<int*, nLayers - 2> mCellsLUTDevice;
188 std::array<int*, nLayers - 3> mNeighboursLUTDevice;
189
190 Tracklet** mTrackletsDeviceArray{nullptr};
191 int** mCellsLUTDeviceArray{nullptr};
192 int** mNeighboursCellDeviceArray{nullptr};
193 int** mNeighboursCellLUTDeviceArray{nullptr};
194 int** mTrackletsLUTDeviceArray{nullptr};
195 std::array<CellSeedN*, nLayers - 2> mCellsDevice;
196 CellSeedN** mCellsDeviceArray;
197 std::array<int*, nLayers - 3> mNeighboursIndexTablesDevice;
198 CellSeedN* mTrackSeedsDevice{nullptr};
199 std::array<o2::track::TrackParCovF*, nLayers - 2> mCellSeedsDevice;
200 o2::track::TrackParCovF** mCellSeedsDeviceArray;
201 std::array<float*, nLayers - 2> mCellSeedsChi2Device;
202 float** mCellSeedsChi2DeviceArray;
203
204 Road<nLayers - 2>* mRoadsDevice;
205 TrackITSExt* mTrackITSExtDevice;
206 std::array<gpuPair<int, int>*, nLayers - 2> mNeighbourPairsDevice;
207 std::array<int*, nLayers - 2> mNeighboursDevice;
208 std::array<TrackingFrameInfo*, nLayers> mTrackingFrameInfoDevice;
209 const TrackingFrameInfo** mTrackingFrameInfoDeviceArray;
210
211 // State
212 Streams mGpuStreams;
213 std::bitset<nLayers + 1> mPinnedUnsortedClusters{0};
214 std::bitset<nLayers + 1> mPinnedClusters{0};
215 std::bitset<nLayers + 1> mPinnedClustersIndexTables{0};
216 std::bitset<nLayers + 1> mPinnedUsedClusters{0};
217 std::bitset<nLayers + 1> mPinnedROFramesClusters{0};
218 std::bitset<nLayers + 1> mPinnedTrackingFrameInfo{0};
219
220 // Temporary buffer for storing output tracks from GPU tracking
221 bounded_vector<TrackITSExt> mTrackITSExt;
222};
223
224template <int nLayers>
225inline int TimeFrameGPU<nLayers>::getNClustersInRofSpan(const int rofIdstart, const int rofSpanSize, const int layerId) const
226{
227 return static_cast<int>(this->mROFramesClusters[layerId][(rofIdstart + rofSpanSize) < this->mROFramesClusters.size() ? rofIdstart + rofSpanSize : this->mROFramesClusters.size() - 1] - this->mROFramesClusters[layerId][rofIdstart]);
228}
229
230template <int nLayers>
231inline std::vector<unsigned int> TimeFrameGPU<nLayers>::getClusterSizes()
232{
233 std::vector<unsigned int> sizes(this->mUnsortedClusters.size());
234 std::transform(this->mUnsortedClusters.begin(), this->mUnsortedClusters.end(), sizes.begin(),
235 [](const auto& v) { return static_cast<unsigned int>(v.size()); });
236 return sizes;
237}
238
239template <int nLayers>
241{
242 return std::accumulate(mNTracklets.begin(), mNTracklets.end(), 0);
243}
244
245template <int nLayers>
247{
248 return std::accumulate(mNCells.begin(), mNCells.end(), 0);
249}
250
251template <int nLayers>
253{
254 return std::accumulate(mNNeighbours.begin(), mNNeighbours.end(), 0);
255}
256
257} // namespace o2::its::gpu
258
259#endif
const TrackingFrameInfo ** getDeviceArrayTrackingFrameInfo() const
gsl::span< int * > getDeviceCellLUTs()
void initialise(const int, const TrackingParameters &, const int, IndexTableUtilsN *utils=nullptr, const TimeFrameGPUParameters *pars=nullptr)
gsl::span< CellSeedN * > getDeviceCells()
void createCellsBuffersArray(const int)
const unsigned char ** getDeviceArrayUsedClusters() const
void loadTrackSeedsDevice(bounded_vector< CellSeedN > &)
const int ** getDeviceArrayClustersIndexTables() const
const Cluster ** getDeviceArrayUnsortedClusters() const
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()
void createClustersIndexTablesArray(const int iteration)
TrackingFrameInfo * getDeviceTrackingFrameInfo(const int)
void createTrackletsBuffersArray(const int)
int getNClustersInRofSpan(const int, const int, const int) const
interface
gsl::span< int, nLayers - 2 > getNCells()
void loadTrackingFrameInfoDevice(const int, const int)
void syncStreams(const bool=true)
std::array< int *, nLayers - 2 > & getDeviceNeighboursAll()
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 createTrackITSExtDevice(bounded_vector< CellSeedN > &)
void loadClustersDevice(const int, const int)
void initDevice(IndexTableUtilsN *, const TrackingParameters &trkParam, const TimeFrameGPUParameters &, const int, const int)
void createUsedClustersDeviceArray(const int)
void registerHostMemory(const int)
Most relevant operations.
o2::track::TrackParCovF ** getDeviceArrayTrackSeeds()
int getNumberOfCells() const final
void createUnsortedClustersDeviceArray(const int)
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 createClustersDeviceArray(const int)
int ** getDeviceArrayNeighboursCellLUT() const
CellSeedN ** getDeviceArrayCells()
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)
void loadUnsortedClustersDevice(const int, const int)
auto & getStream(const size_t stream)
synchronization
int ** getDeviceArrayCellsLUT() const
IndexTableUtilsN * getDeviceIndexTableUtils()
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()
void unregisterHostMemory(const int)
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
std::pair< T1, T2 > gpuPair
Definition Utils.h:43
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:312
CellSeed< nLayers > CellSeedN
Definition TimeFrame.h:69
IndexTableUtils< nLayers > IndexTableUtilsN
Definition TimeFrame.h:68