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