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
27{
28 void* allocate(size_t size) override;
29};
30
31template <int nLayers = 7>
32class TimeFrameGPU : public TimeFrame<nLayers>
33{
34 public:
37
39 void registerHostMemory(const int);
40 void unregisterHostMemory(const int);
41 void initialise(const int, const TrackingParameters&, const int, IndexTableUtils* utils = nullptr, const TimeFrameGPUParameters* pars = nullptr);
42 void initDevice(IndexTableUtils*, const TrackingParameters& trkParam, const TimeFrameGPUParameters&, const int, const int);
44 void loadIndexTableUtils(const int);
47 void loadClustersDevice(const int);
48 void loadClustersIndexTables(const int iteration);
49 void createUsedClustersDevice(const int);
52 void loadMultiplicityCutMask(const int);
53 void loadVertices(const int);
54
56 void createTrackletsLUTDevice(const int);
66 void createCellsBuffers(const int);
70 void createNeighboursDevice(const unsigned int layer, const unsigned int nNeighbours);
71 void createNeighboursDevice(const unsigned int layer, std::vector<std::pair<int, int>>& neighbours);
72 void createNeighboursLUTDevice(const int, const unsigned int);
76 void downloadCellsNeighboursDevice(std::vector<bounded_vector<std::pair<int, int>>>&, const int);
81 template <Task task>
82 auto& getStream(const size_t stream)
83 {
84 return mGpuStreams[stream];
85 }
86 auto& getStreams() { return mGpuStreams; }
87 void wipe(const int);
88
90 int getNClustersInRofSpan(const int, const int, const int) const;
91 IndexTableUtils* getDeviceIndexTableUtils() { return mIndexTableUtilsDevice; }
92 int* getDeviceROFramesClusters(const int layer) { return mROFramesClustersDevice[layer]; }
93 auto& getTrackITSExt() { return mTrackITSExt; }
94 Vertex* getDeviceVertices() { return mPrimaryVerticesDevice; }
95 int* getDeviceROFramesPV() { return mROFramesPVDevice; }
96 unsigned char* getDeviceUsedClusters(const int);
98
99 // Hybrid
100 Road<nLayers - 2>* getDeviceRoads() { return mRoadsDevice; }
101 TrackITSExt* getDeviceTrackITSExt() { return mTrackITSExtDevice; }
102 int* getDeviceNeighboursLUT(const int layer) { return mNeighboursLUTDevice[layer]; }
103 gsl::span<int*> getDeviceNeighboursLUTs() { return mNeighboursLUTDevice; }
104 gpuPair<int, int>* getDeviceNeighbourPairs(const int layer) { return mNeighbourPairsDevice[layer]; }
105 std::array<int*, nLayers - 2>& getDeviceNeighboursAll() { return mNeighboursDevice; }
106 int* getDeviceNeighbours(const int layer) { return mNeighboursDevice[layer]; }
107 int** getDeviceNeighboursArray() { return mNeighboursDeviceArray; }
109 const TrackingFrameInfo** getDeviceArrayTrackingFrameInfo() const { return mTrackingFrameInfoDeviceArray; }
110 const Cluster** getDeviceArrayClusters() const { return mClustersDeviceArray; }
111 const Cluster** getDeviceArrayUnsortedClusters() const { return mUnsortedClustersDeviceArray; }
112 const int** getDeviceArrayClustersIndexTables() const { return mClustersIndexTablesDeviceArray; }
113 std::vector<unsigned int> getClusterSizes();
114 const unsigned char** getDeviceArrayUsedClusters() const { return mUsedClustersDeviceArray; }
115 const int** getDeviceROframeClusters() const { return mROFrameClustersDeviceArray; }
116 Tracklet** getDeviceArrayTracklets() { return mTrackletsDeviceArray; }
117 int** getDeviceArrayTrackletsLUT() const { return mTrackletsLUTDeviceArray; }
118 int** getDeviceArrayCellsLUT() const { return mCellsLUTDeviceArray; }
119 int** getDeviceArrayNeighboursCellLUT() const { return mNeighboursCellLUTDeviceArray; }
120 CellSeed** getDeviceArrayCells() const { return mCellsDeviceArray; }
121 CellSeed* getDeviceTrackSeeds() { return mTrackSeedsDevice; }
122 o2::track::TrackParCovF** getDeviceArrayTrackSeeds() { return mCellSeedsDeviceArray; }
123 float** getDeviceArrayTrackSeedsChi2() { return mCellSeedsChi2DeviceArray; }
124 int* getDeviceNeighboursIndexTables(const int layer) { return mNeighboursIndexTablesDevice[layer]; }
125 uint8_t* getDeviceMultCutMask() { return mMultMaskDevice; }
126
128
129 // Host-specific getters
130 gsl::span<int, nLayers - 1> getNTracklets() { return mNTracklets; }
131 gsl::span<int, nLayers - 2> getNCells() { return mNCells; }
132 auto& getArrayNCells() { return mNCells; }
133 gsl::span<int, nLayers - 3> getNNeighbours() { return mNNeighbours; }
134 auto& getArrayNNeighbours() { return mNNeighbours; }
135
136 // Host-available device getters
137 gsl::span<int*> getDeviceTrackletsLUTs() { return mTrackletsLUTDevice; }
138 gsl::span<int*> getDeviceCellLUTs() { return mCellsLUTDevice; }
139 gsl::span<Tracklet*> getDeviceTracklet() { return mTrackletsDevice; }
140 gsl::span<CellSeed*> getDeviceCells() { return mCellsDevice; }
141
142 // Overridden getters
143 int getNumberOfTracklets() const final;
144 int getNumberOfCells() const final;
145 int getNumberOfNeighbours() const final;
146
147 private:
148 void allocMemAsync(void**, size_t, Stream&, bool); // Abstract owned and unowned memory allocations
149 bool mHostRegistered = false;
150 TimeFrameGPUParameters mGpuParams;
151
152 // Host-available device buffer sizes
153 std::array<int, nLayers - 1> mNTracklets;
154 std::array<int, nLayers - 2> mNCells;
155 std::array<int, nLayers - 3> mNNeighbours;
156
157 // Device pointers
158 IndexTableUtils* mIndexTableUtilsDevice;
159
160 // Hybrid pref
161 uint8_t* mMultMaskDevice;
162 Vertex* mPrimaryVerticesDevice;
163 int* mROFramesPVDevice;
164 std::array<Cluster*, nLayers> mClustersDevice;
165 std::array<Cluster*, nLayers> mUnsortedClustersDevice;
166 std::array<int*, nLayers> mClustersIndexTablesDevice;
167 std::array<unsigned char*, nLayers> mUsedClustersDevice;
168 std::array<int*, nLayers> mROFramesClustersDevice;
169 const Cluster** mClustersDeviceArray;
170 const Cluster** mUnsortedClustersDeviceArray;
171 const int** mClustersIndexTablesDeviceArray;
172 const unsigned char** mUsedClustersDeviceArray;
173 const int** mROFrameClustersDeviceArray;
174 std::array<Tracklet*, nLayers - 1> mTrackletsDevice;
175 Tracklet** mTrackletsDeviceArray;
176 std::array<int*, nLayers - 1> mTrackletsLUTDevice;
177 std::array<int*, nLayers - 2> mCellsLUTDevice;
178 std::array<int*, nLayers - 3> mNeighboursLUTDevice;
179
180 int** mCellsLUTDeviceArray;
181 int** mNeighboursCellDeviceArray;
182 int** mNeighboursCellLUTDeviceArray;
183 int** mTrackletsLUTDeviceArray;
184 std::array<CellSeed*, nLayers - 2> mCellsDevice;
185 std::array<int*, nLayers - 2> mNeighboursIndexTablesDevice;
186 CellSeed* mTrackSeedsDevice;
187 CellSeed** mCellsDeviceArray;
188 std::array<o2::track::TrackParCovF*, nLayers - 2> mCellSeedsDevice;
189 o2::track::TrackParCovF** mCellSeedsDeviceArray;
190 std::array<float*, nLayers - 2> mCellSeedsChi2Device;
191 float** mCellSeedsChi2DeviceArray;
192
193 Road<nLayers - 2>* mRoadsDevice;
194 TrackITSExt* mTrackITSExtDevice;
195 std::array<gpuPair<int, int>*, nLayers - 2> mNeighbourPairsDevice;
196 std::array<int*, nLayers - 2> mNeighboursDevice;
197 int** mNeighboursDeviceArray;
198 std::array<TrackingFrameInfo*, nLayers> mTrackingFrameInfoDevice;
199 const TrackingFrameInfo** mTrackingFrameInfoDeviceArray;
200
201 // State
202 Streams mGpuStreams;
203 size_t mAvailMemGB;
204 bool mFirstInit = true;
205
206 // Temporary buffer for storing output tracks from GPU tracking
207 bounded_vector<TrackITSExt> mTrackITSExt;
208};
209
210template <int nLayers>
211inline int TimeFrameGPU<nLayers>::getNClustersInRofSpan(const int rofIdstart, const int rofSpanSize, const int layerId) const
212{
213 return static_cast<int>(this->mROFramesClusters[layerId][(rofIdstart + rofSpanSize) < this->mROFramesClusters.size() ? rofIdstart + rofSpanSize : this->mROFramesClusters.size() - 1] - this->mROFramesClusters[layerId][rofIdstart]);
214}
215
216template <int nLayers>
217inline std::vector<unsigned int> TimeFrameGPU<nLayers>::getClusterSizes()
218{
219 std::vector<unsigned int> sizes(this->mUnsortedClusters.size());
220 std::transform(this->mUnsortedClusters.begin(), this->mUnsortedClusters.end(), sizes.begin(),
221 [](const auto& v) { return static_cast<unsigned int>(v.size()); });
222 return sizes;
223}
224
225template <int nLayers>
227{
228 return std::accumulate(mNTracklets.begin(), mNTracklets.end(), 0);
229}
230
231template <int nLayers>
233{
234 return std::accumulate(mNCells.begin(), mNCells.end(), 0);
235}
236
237template <int nLayers>
239{
240 return std::accumulate(mNNeighbours.begin(), mNNeighbours.end(), 0);
241}
242
243} // namespace o2::its::gpu
244
245#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()
auto & getStream(const size_t stream)
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)
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:283
std::array< bounded_vector< Cluster >, nLayers > mUnsortedClusters
Definition TimeFrame.h:302