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