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>
28class TimeFrameGPU final : public TimeFrame<NLayers>
29{
34 using typename TimeFrame<NLayers>::TrackSeedN;
35
36 public:
37 TimeFrameGPU() = default;
38 ~TimeFrameGPU() final = default;
39
41 void pushMemoryStack(const int);
42 void popMemoryStack(const int);
43 void registerHostMemory(const int);
44 void unregisterHostMemory(const int);
45 void initialise(const int, const TrackingParameters&, const int);
46 void loadIndexTableUtils(const int);
47 void loadTrackingFrameInfoDevice(const int, const int);
49 void loadUnsortedClustersDevice(const int, const int);
50 void createUnsortedClustersDeviceArray(const int, const int = NLayers);
51 void loadClustersDevice(const int, const int);
52 void createClustersDeviceArray(const int, const int = NLayers);
53 void loadClustersIndexTables(const int, const int);
55 void createUsedClustersDevice(const int, const int);
56 void createUsedClustersDeviceArray(const int, const int = NLayers);
58 void loadROFrameClustersDevice(const int, const int);
60 void loadROFCutMask(const int);
61 void loadVertices(const int);
62 void loadROFOverlapTable(const int);
63 void loadROFVertexLookupTable(const int);
65
67 void createTrackletsLUTDevice(const int, const int);
76 void createTrackletsBuffers(const int);
78 void createCellsBuffers(const int);
79 void createCellsBuffersArray(const int);
81 void createCellsLUTDevice(const int);
84 void createNeighboursDevice(const unsigned int layer);
85 void createNeighboursLUTDevice(const int, const unsigned int);
86 void createTrackITSExtDevice(const size_t);
88 void downloadCellsNeighboursDevice(std::vector<bounded_vector<std::pair<int, int>>>&, const int);
92
94 auto& getStream(const size_t stream) { return mGpuStreams[stream]; }
95 auto& getStreams() { return mGpuStreams; }
96 void syncStream(const size_t stream);
97 void syncStreams(const bool = true);
98 void waitEvent(const int, const int);
99 void recordEvent(const int);
100 void recordEvents(const int = 0, const int = NLayers);
101
103 virtual void wipe() final;
104
106 virtual bool isGPU() const noexcept final { return true; }
107 virtual const char* getName() const noexcept { return "GPU"; }
108 IndexTableUtilsN* getDeviceIndexTableUtils() { return mIndexTableUtilsDevice; }
109 const auto getDeviceROFOverlapTableView() { return mDeviceROFOverlapTableView; }
110 const auto getDeviceROFVertexLookupTableView() { return mDeviceROFVertexLookupTableView; }
111 const auto getDeviceROFMaskTableView() { return mDeviceROFMaskTableView; }
112 int* getDeviceROFramesClusters(const int layer) { return mROFramesClustersDevice[layer]; }
113 auto& getTrackITSExt() { return mTrackITSExt; }
114 Vertex* getDeviceVertices() { return mPrimaryVerticesDevice; }
115 int* getDeviceROFramesPV() { return mROFramesPVDevice; }
116 unsigned char* getDeviceUsedClusters(const int);
118
119 // Hybrid
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 CellSeed** getDeviceArrayCells() { return mCellsDeviceArray; }
140 TrackSeedN* getDeviceTrackSeeds() { return mTrackSeedsDevice; }
141 int* getDeviceTrackSeedsLUT() { return mTrackSeedsLUTDevice; }
142 auto getNTrackSeeds() const { return mNTracks; }
143 o2::track::TrackParCovF** getDeviceArrayTrackSeeds() { return mCellSeedsDeviceArray; }
144 float** getDeviceArrayTrackSeedsChi2() { return mCellSeedsChi2DeviceArray; }
145 int* getDeviceNeighboursIndexTables(const int layer) { return mNeighboursIndexTablesDevice[layer]; }
146
148
149 // Host-specific getters
150 gsl::span<int, NLayers - 1> getNTracklets() { return mNTracklets; }
151 gsl::span<int, NLayers - 2> getNCells() { return mNCells; }
152 auto& getArrayNCells() { return mNCells; }
153 gsl::span<int, NLayers - 3> getNNeighbours() { return mNNeighbours; }
154 auto& getArrayNNeighbours() { return mNNeighbours; }
155
156 // Host-available device getters
157 gsl::span<int*> getDeviceTrackletsLUTs() { return mTrackletsLUTDevice; }
158 gsl::span<int*> getDeviceCellLUTs() { return mCellsLUTDevice; }
159 gsl::span<Tracklet*> getDeviceTracklets() { return mTrackletsDevice; }
160 gsl::span<CellSeed*> getDeviceCells() { return mCellsDevice; }
161
162 // Overridden getters
163 size_t getNumberOfTracklets() const final;
164 size_t getNumberOfCells() const final;
165 size_t getNumberOfNeighbours() const final;
166
167 private:
168 void allocMemAsync(void**, size_t, Stream&, bool, int32_t = o2::gpu::GPUMemoryResource::MEMORY_GPU); // Abstract owned and unowned memory allocations on specific stream
169 void allocMem(void**, size_t, bool, int32_t = o2::gpu::GPUMemoryResource::MEMORY_GPU); // Abstract owned and unowned memory allocations on default stream
170
171 // Host-available device buffer sizes
172 std::array<int, NLayers - 1> mNTracklets;
173 std::array<int, NLayers - 2> mNCells;
174 std::array<int, NLayers - 3> mNNeighbours;
175
176 // Device pointers
177 IndexTableUtilsN* mIndexTableUtilsDevice;
178 // device navigation views
179 ROFOverlapTableN::View mDeviceROFOverlapTableView;
180 ROFVertexLookupTableN::View mDeviceROFVertexLookupTableView;
181 ROFMaskTableN::View mDeviceROFMaskTableView;
182
183 // Hybrid pref
184 Vertex* mPrimaryVerticesDevice;
185 int* mROFramesPVDevice;
186 std::array<Cluster*, NLayers> mClustersDevice;
187 std::array<Cluster*, NLayers> mUnsortedClustersDevice;
188 std::array<int*, NLayers> mClustersIndexTablesDevice;
189 std::array<unsigned char*, NLayers> mUsedClustersDevice;
190 std::array<int*, NLayers> mROFramesClustersDevice;
191 const Cluster** mClustersDeviceArray;
192 const Cluster** mUnsortedClustersDeviceArray;
193 const int** mClustersIndexTablesDeviceArray;
194 uint8_t** mUsedClustersDeviceArray;
195 const int** mROFramesClustersDeviceArray;
196 std::array<Tracklet*, NLayers - 1> mTrackletsDevice;
197 std::array<int*, NLayers - 1> mTrackletsLUTDevice;
198 std::array<int*, NLayers - 2> mCellsLUTDevice;
199 std::array<int*, NLayers - 3> mNeighboursLUTDevice;
200
201 Tracklet** mTrackletsDeviceArray{nullptr};
202 int** mCellsLUTDeviceArray{nullptr};
203 int** mNeighboursCellDeviceArray{nullptr};
204 int** mNeighboursCellLUTDeviceArray{nullptr};
205 int** mTrackletsLUTDeviceArray{nullptr};
206 std::array<CellSeed*, NLayers - 2> mCellsDevice;
207 CellSeed** mCellsDeviceArray;
208 std::array<int*, NLayers - 3> mNeighboursIndexTablesDevice;
209 TrackSeedN* mTrackSeedsDevice{nullptr};
210 int* mTrackSeedsLUTDevice{nullptr};
211 unsigned int mNTracks{0};
212 std::array<o2::track::TrackParCovF*, NLayers - 2> mCellSeedsDevice;
213 o2::track::TrackParCovF** mCellSeedsDeviceArray;
214 std::array<float*, NLayers - 2> mCellSeedsChi2Device;
215 float** mCellSeedsChi2DeviceArray;
216
217 TrackITSExt* mTrackITSExtDevice;
218 std::array<gpuPair<int, int>*, NLayers - 2> mNeighbourPairsDevice;
219 std::array<int*, NLayers - 2> mNeighboursDevice;
220 std::array<TrackingFrameInfo*, NLayers> mTrackingFrameInfoDevice;
221 const TrackingFrameInfo** mTrackingFrameInfoDeviceArray;
222
223 // State
224 Streams mGpuStreams;
225 std::bitset<NLayers + 1> mPinnedUnsortedClusters{0};
226 std::bitset<NLayers + 1> mPinnedClusters{0};
227 std::bitset<NLayers + 1> mPinnedClustersIndexTables{0};
228 std::bitset<NLayers + 1> mPinnedUsedClusters{0};
229 std::bitset<NLayers + 1> mPinnedROFramesClusters{0};
230 std::bitset<NLayers + 1> mPinnedTrackingFrameInfo{0};
231
232 // Temporary buffer for storing output tracks from GPU tracking
233 bounded_vector<TrackITSExt> mTrackITSExt;
234};
235
236template <int NLayers>
237inline std::vector<unsigned int> TimeFrameGPU<NLayers>::getClusterSizes()
238{
239 std::vector<unsigned int> sizes(this->mUnsortedClusters.size());
240 std::transform(this->mUnsortedClusters.begin(), this->mUnsortedClusters.end(), sizes.begin(),
241 [](const auto& v) { return static_cast<unsigned int>(v.size()); });
242 return sizes;
243}
244
245template <int NLayers>
247{
248 return std::accumulate(mNTracklets.begin(), mNTracklets.end(), 0);
249}
250
251template <int NLayers>
253{
254 return std::accumulate(mNCells.begin(), mNCells.end(), 0);
255}
256
257template <int NLayers>
259{
260 return std::accumulate(mNNeighbours.begin(), mNNeighbours.end(), 0);
261}
262
263} // namespace o2::its::gpu
264
265#endif
CellSeed: connections of three clusters.
Definition Cell.h:68
gsl::span< Tracklet * > getDeviceTracklets()
size_t getNumberOfTracklets() const final
o2::track::TrackParCovF ** getDeviceArrayTrackSeeds()
virtual bool isGPU() const noexcept final
interface
std::array< int *, NLayers - 2 > & getDeviceNeighboursAll()
int * getDeviceROFramesClusters(const int layer)
void createNeighboursIndexTablesDevice(const int)
void createUsedClustersDevice(const int, const int)
void createUnsortedClustersDeviceArray(const int, const int=NLayers)
~TimeFrameGPU() final=default
void loadROFrameClustersDevice(const int, const int)
void pushMemoryStack(const int)
Most relevant operations.
int * getDeviceNeighbours(const int layer)
void downloadNeighboursLUTDevice(bounded_vector< int > &, const int)
const auto getDeviceROFOverlapTableView()
void loadROFVertexLookupTable(const int)
TrackITSExt * getDeviceTrackITSExt()
TrackSeedN * getDeviceTrackSeeds()
gsl::span< int, NLayers - 2 > getNCells()
void loadROFOverlapTable(const int)
void unregisterHostMemory(const int)
const auto getDeviceROFMaskTableView()
unsigned char * getDeviceUsedClusters(const int)
float ** getDeviceArrayTrackSeedsChi2()
virtual void wipe() final
cleanup
void loadClustersIndexTables(const int, const int)
size_t getNumberOfNeighbours() const final
uint8_t ** getDeviceArrayUsedClusters() const
const int ** getDeviceArrayClustersIndexTables() const
void createTrackletsLUTDeviceArray(const int)
void registerHostMemory(const int)
void recordEvent(const int)
int ** getDeviceArrayCellsLUT() const
CellSeed ** getDeviceArrayCells()
gsl::span< CellSeed * > getDeviceCells()
void waitEvent(const int, const int)
gsl::span< int * > getDeviceTrackletsLUTs()
void popMemoryStack(const int)
void createClustersIndexTablesArray(const int)
gpuPair< int, int > * getDeviceNeighbourPairs(const int layer)
void syncStreams(const bool=true)
void createTrackletsBuffers(const int)
int * getDeviceNeighboursLUT(const int layer)
void loadUnsortedClustersDevice(const int, const int)
const int ** getDeviceROFrameClusters() const
void loadTrackingFrameInfoDevice(const int, const int)
void createNeighboursDevice(const unsigned int layer)
void initialise(const int, const TrackingParameters &, const int)
int * getDeviceNeighboursIndexTables(const int layer)
const auto getDeviceROFVertexLookupTableView()
Tracklet ** getDeviceArrayTracklets()
size_t getNumberOfCells() const final
auto & getStream(const size_t stream)
synchronization
void createTrackingFrameInfoDeviceArray(const int)
void downloadCellsNeighboursDevice(std::vector< bounded_vector< std::pair< int, int > > > &, const int)
void createCellsLUTDeviceArray(const int)
gsl::span< int, NLayers - 3 > getNNeighbours()
void loadROFCutMask(const int)
void createCellsLUTDevice(const int)
void syncStream(const size_t stream)
void loadClustersDevice(const int, const int)
const Cluster ** getDeviceArrayUnsortedClusters() const
gsl::span< int * > getDeviceNeighboursLUTs()
virtual const char * getName() const noexcept
void createCellsBuffersArray(const int)
void loadVertices(const int)
void setDevicePropagator(const o2::base::PropagatorImpl< float > *p) final
int ** getDeviceArrayTrackletsLUT() const
int ** getDeviceArrayNeighboursCellLUT() const
const o2::base::Propagator * getChainPropagator()
const Cluster ** getDeviceArrayClusters() const
void recordEvents(const int=0, const int=NLayers)
void createUsedClustersDeviceArray(const int, const int=NLayers)
const TrackingFrameInfo ** getDeviceArrayTrackingFrameInfo() const
IndexTableUtilsN * getDeviceIndexTableUtils()
void createNeighboursLUTDevice(const int, const unsigned int)
void loadIndexTableUtils(const int)
void createTrackletsBuffersArray(const int)
gsl::span< int * > getDeviceCellLUTs()
void createClustersDeviceArray(const int, const int=NLayers)
void createTrackletsLUTDevice(const int, const int)
TrackingFrameInfo * getDeviceTrackingFrameInfo(const int)
void createCellsBuffers(const int)
void createROFrameClustersDeviceArray(const int)
void createTrackITSExtDevice(const size_t)
std::vector< unsigned int > getClusterSizes()
gsl::span< int, NLayers - 1 > getNTracklets()
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:58
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 ...
ROFVertexLookupTable< NLayers > ROFVertexLookupTableN
Definition TimeFrame.h:69
TrackSeed< NLayers > TrackSeedN
Definition TimeFrame.h:71
void updateROFVertexLookupTable()
Definition TimeFrame.h:152
IndexTableUtils< NLayers > IndexTableUtilsN
Definition TimeFrame.h:67
const o2::base::PropagatorImpl< float > * mPropagatorDevice
Definition TimeFrame.h:280
ROFOverlapTable< NLayers > ROFOverlapTableN
Definition TimeFrame.h:68
ROFMaskTable< NLayers > ROFMaskTableN
Definition TimeFrame.h:70