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 : public TimeFrame<NLayers>
29{
35 using typename TimeFrame<NLayers>::TrackSeedN;
36 static constexpr int MaxTransitions = TrackingTopologyN::MaxTransitions;
37 static constexpr int MaxCells = TrackingTopologyN::MaxCells;
38 static constexpr int MaxStreams = MaxCells > NLayers ? MaxCells : NLayers;
39
40 public:
41 TimeFrameGPU() = default;
42 ~TimeFrameGPU() override = default;
43
45 void pushMemoryStack(const int);
46 void popMemoryStack(const int);
47 void registerHostMemory(const int);
48 void unregisterHostMemory(const int);
49 void initialise(const TrackingParameters&, int maxLayers);
50 void initialise(const TrackingParameters&, int maxLayers, int iteration);
56 void createUnsortedClustersDeviceArray(const int = NLayers);
57 void loadClustersDevice(const int);
58 void createClustersDeviceArray(const int = NLayers);
59 void loadClustersIndexTables(const int);
61 void createUsedClustersDevice(const int);
62 void createUsedClustersDeviceArray(const int = NLayers);
66 void loadROFCutMask(const int);
71
73 void createTrackletsLUTDevice(bool, const int);
82 void createTrackletsBuffers(const int);
84 void createCellsBuffers(const int);
87 void createCellsLUTDevice(const int);
90 void createNeighboursDevice(const unsigned int layer);
91 void createNeighboursLUTDevice(const int, const unsigned int);
92 void createTrackITSExtDevice(const size_t);
98
100 auto& getStream(const size_t stream) { return mGpuStreams[stream]; }
101 auto& getStreams() { return mGpuStreams; }
102 void syncStream(const size_t stream);
103 void syncStreams(const bool = true);
104 void waitEvent(const int, const int);
105 void recordEvent(const int);
106 void recordEvents(const int = 0, const int = NLayers);
107
109 virtual void wipe() final;
110
112 virtual bool isGPU() const noexcept final { return true; }
113 virtual const char* getName() const noexcept override final { return "GPU"; }
114 IndexTableUtilsN* getDeviceIndexTableUtils() { return mIndexTableUtilsDevice; }
115 const auto getDeviceROFOverlapTableView() { return mDeviceROFOverlapTableView; }
116 const auto getDeviceROFVertexLookupTableView() { return mDeviceROFVertexLookupTableView; }
117 const auto getDeviceROFMaskTableView() { return mDeviceROFMaskTableView; }
118 const auto getDeviceTrackingTopologyView() const { return mDeviceTrackingTopologyView; }
119 int* getDeviceROFramesClusters(const int layer) { return mROFramesClustersDevice[layer]; }
120 auto& getTrackITSExt() { return mTrackITSExt; }
121 Vertex* getDeviceVertices() { return mPrimaryVerticesDevice; }
122 int* getDeviceROFramesPV() { return mROFramesPVDevice; }
123 unsigned char* getDeviceUsedClusters(const int);
125
126 // Hybrid
127 TrackITSExt* getDeviceTrackITSExt() { return mTrackITSExtDevice; }
128 int* getDeviceNeighboursLUT(const int layer) { return mNeighboursLUTDevice[layer]; }
129 gsl::span<int*> getDeviceNeighboursLUTs() { return mNeighboursLUTDevice; }
130 CellNeighbour** getDeviceArrayNeighbours() { return mNeighboursDeviceArray; }
131 std::array<CellNeighbour*, MaxCells>& getDeviceNeighboursAll() { return mNeighboursDevice; }
132 CellNeighbour* getDeviceNeighbours(const int layer) { return mNeighboursDevice[layer]; }
134 const TrackingFrameInfo** getDeviceArrayTrackingFrameInfo() const { return mTrackingFrameInfoDeviceArray; }
135 const Cluster** getDeviceArrayClusters() const { return mClustersDeviceArray; }
136 const Cluster** getDeviceArrayUnsortedClusters() const { return mUnsortedClustersDeviceArray; }
137 const int** getDeviceArrayClustersIndexTables() const { return mClustersIndexTablesDeviceArray; }
138 std::vector<unsigned int> getClusterSizes();
139 uint8_t** getDeviceArrayUsedClusters() const { return mUsedClustersDeviceArray; }
140 const int** getDeviceROFrameClusters() const { return mROFramesClustersDeviceArray; }
141 Tracklet** getDeviceArrayTracklets() { return mTrackletsDeviceArray; }
142 int** getDeviceArrayTrackletsLUT() const { return mTrackletsLUTDeviceArray; }
143 int** getDeviceArrayCellsLUT() const { return mCellsLUTDeviceArray; }
144 int** getDeviceArrayNeighboursCellLUT() const { return mNeighboursCellLUTDeviceArray; }
145 CellSeed** getDeviceArrayCells() { return mCellsDeviceArray; }
146 TrackSeedN* getDeviceTrackSeeds() { return mTrackSeedsDevice; }
147 int* getDeviceTrackSeedsLUT() { return mTrackSeedsLUTDevice; }
148 auto getNTrackSeeds() const { return mNTracks; }
149 o2::track::TrackParCovF** getDeviceArrayTrackSeeds() { return mCellSeedsDeviceArray; }
150 float** getDeviceArrayTrackSeedsChi2() { return mCellSeedsChi2DeviceArray; }
151 int* getDeviceNeighboursIndexTables(const int layer) { return mNeighboursIndexTablesDevice[layer]; }
152
154
155 // Host-specific getters
156 gsl::span<int> getNTracklets() { return {mNTracklets.data(), static_cast<gsl::span<int>::size_type>(this->mTrackingTopologyView.nTransitions)}; }
157 gsl::span<int> getNCells() { return {mNCells.data(), static_cast<gsl::span<int>::size_type>(this->mTrackingTopologyView.nCells)}; }
158 auto& getArrayNCells() { return mNCells; }
159 gsl::span<int> getNNeighbours() { return {mNNeighbours.data(), static_cast<gsl::span<int>::size_type>(this->mTrackingTopologyView.nCells)}; }
160 auto& getArrayNNeighbours() { return mNNeighbours; }
161
162 // Host-available device getters
163 gsl::span<int*> getDeviceTrackletsLUTs() { return mTrackletsLUTDevice; }
164 gsl::span<int*> getDeviceCellLUTs() { return mCellsLUTDevice; }
165 gsl::span<Tracklet*> getDeviceTracklets() { return mTrackletsDevice; }
166 gsl::span<CellSeed*> getDeviceCells() { return mCellsDevice; }
167
168 // Overridden getters
169 size_t getNumberOfTracklets() const final;
170 size_t getNumberOfCells() const final;
171 size_t getNumberOfNeighbours() const final;
172
173 private:
174 void allocMemAsync(void**, size_t, Stream&, bool, int32_t = o2::gpu::GPUMemoryResource::MEMORY_GPU); // Abstract owned and unowned memory allocations on specific stream
175 void allocMem(void**, size_t, bool, int32_t = o2::gpu::GPUMemoryResource::MEMORY_GPU); // Abstract owned and unowned memory allocations on default stream
176
177 // Host-available device buffer sizes
178 std::array<int, MaxTransitions> mNTracklets{};
179 std::array<int, MaxCells> mNCells{};
180 std::array<int, MaxCells> mNNeighbours{};
181
182 // Device pointers
183 IndexTableUtilsN* mIndexTableUtilsDevice;
184 // device navigation views
185 ROFOverlapTableN::View mDeviceROFOverlapTableView;
186 ROFVertexLookupTableN::View mDeviceROFVertexLookupTableView;
187 ROFMaskTableN::View mDeviceROFMaskTableView;
188 std::vector<typename TrackingTopologyN::View> mDeviceTrackerTopologyViews;
189 typename TrackingTopologyN::View mDeviceTrackingTopologyView;
190
191 // Hybrid pref
192 Vertex* mPrimaryVerticesDevice;
193 int* mROFramesPVDevice;
194 std::array<Cluster*, NLayers> mClustersDevice;
195 std::array<Cluster*, NLayers> mUnsortedClustersDevice;
196 std::array<int*, NLayers> mClustersIndexTablesDevice;
197 std::array<unsigned char*, NLayers> mUsedClustersDevice;
198 std::array<int*, NLayers> mROFramesClustersDevice;
199 const Cluster** mClustersDeviceArray;
200 const Cluster** mUnsortedClustersDeviceArray;
201 const int** mClustersIndexTablesDeviceArray;
202 uint8_t** mUsedClustersDeviceArray;
203 const int** mROFramesClustersDeviceArray;
204 std::array<Tracklet*, MaxTransitions> mTrackletsDevice{};
205 std::array<int*, MaxTransitions> mTrackletsLUTDevice{};
206 std::array<int*, MaxCells> mCellsLUTDevice{};
207 std::array<int*, MaxCells> mNeighboursLUTDevice{};
208
209 Tracklet** mTrackletsDeviceArray{nullptr};
210 int** mCellsLUTDeviceArray{nullptr};
211 int** mNeighboursCellLUTDeviceArray{nullptr};
212 int** mTrackletsLUTDeviceArray{nullptr};
213 std::array<CellSeed*, MaxCells> mCellsDevice{};
214 CellSeed** mCellsDeviceArray;
215 std::array<int*, MaxCells> mNeighboursIndexTablesDevice{};
216 TrackSeedN* mTrackSeedsDevice{nullptr};
217 int* mTrackSeedsLUTDevice{nullptr};
218 unsigned int mNTracks{0};
219 std::array<o2::track::TrackParCovF*, MaxCells> mCellSeedsDevice{};
220 o2::track::TrackParCovF** mCellSeedsDeviceArray;
221 std::array<float*, MaxCells> mCellSeedsChi2Device{};
222 float** mCellSeedsChi2DeviceArray;
223
224 TrackITSExt* mTrackITSExtDevice;
225 std::array<CellNeighbour*, MaxCells> mNeighboursDevice{};
226 CellNeighbour** mNeighboursDeviceArray{nullptr};
227 std::array<TrackingFrameInfo*, NLayers> mTrackingFrameInfoDevice;
228 const TrackingFrameInfo** mTrackingFrameInfoDeviceArray;
229
230 // State
231 Streams mGpuStreams;
232 std::bitset<NLayers + 1> mPinnedUnsortedClusters{0};
233 std::bitset<NLayers + 1> mPinnedClusters{0};
234 std::bitset<NLayers + 1> mPinnedClustersIndexTables{0};
235 std::bitset<NLayers + 1> mPinnedUsedClusters{0};
236 std::bitset<NLayers + 1> mPinnedROFramesClusters{0};
237 std::bitset<NLayers + 1> mPinnedTrackingFrameInfo{0};
238
239 // Temporary buffer for storing output tracks from GPU tracking
240 bounded_vector<TrackITSExt> mTrackITSExt;
241};
242
243template <int NLayers>
244inline std::vector<unsigned int> TimeFrameGPU<NLayers>::getClusterSizes()
245{
246 std::vector<unsigned int> sizes(this->mUnsortedClusters.size());
247 std::transform(this->mUnsortedClusters.begin(), this->mUnsortedClusters.end(), sizes.begin(),
248 [](const auto& v) { return static_cast<unsigned int>(v.size()); });
249 return sizes;
250}
251
252template <int NLayers>
254{
255 return std::accumulate(mNTracklets.begin(), mNTracklets.begin() + this->mTrackingTopologyView.nTransitions, 0);
256}
257
258template <int NLayers>
260{
261 return std::accumulate(mNCells.begin(), mNCells.begin() + this->mTrackingTopologyView.nCells, 0);
262}
263
264template <int NLayers>
266{
267 return std::accumulate(mNNeighbours.begin(), mNNeighbours.begin() + this->mTrackingTopologyView.nCells, 0);
268}
269
270} // namespace o2::its::gpu
271
272#endif
HMPID cluster implementation.
Definition Cluster.h:27
CellSeed: connections of three clusters.
Definition Cell.h:81
gsl::span< Tracklet * > getDeviceTracklets()
size_t getNumberOfTracklets() const final
o2::track::TrackParCovF ** getDeviceArrayTrackSeeds()
virtual const char * getName() const noexcept override final
virtual bool isGPU() const noexcept final
interface
void createUsedClustersDevice(const int)
int * getDeviceROFramesClusters(const int layer)
void createNeighboursIndexTablesDevice(const int)
void pushMemoryStack(const int)
Most relevant operations.
void downloadNeighboursLUTDevice(bounded_vector< int > &, const int)
const auto getDeviceROFOverlapTableView()
void loadClustersIndexTables(const int)
TrackITSExt * getDeviceTrackITSExt()
TrackSeedN * getDeviceTrackSeeds()
void initialise(const TrackingParameters &, int maxLayers, int iteration)
void unregisterHostMemory(const int)
const auto getDeviceROFMaskTableView()
unsigned char * getDeviceUsedClusters(const int)
float ** getDeviceArrayTrackSeedsChi2()
virtual void wipe() final
cleanup
size_t getNumberOfNeighbours() const final
void createTrackletsLUTDevice(bool, const int)
uint8_t ** getDeviceArrayUsedClusters() const
const int ** getDeviceArrayClustersIndexTables() const
void registerHostMemory(const int)
void recordEvent(const int)
int ** getDeviceArrayCellsLUT() const
CellSeed ** getDeviceArrayCells()
gsl::span< CellSeed * > getDeviceCells()
void downloadCellsNeighboursDevice(std::vector< bounded_vector< CellNeighbour > > &, const int)
const auto getDeviceTrackingTopologyView() const
void waitEvent(const int, const int)
gsl::span< int * > getDeviceTrackletsLUTs()
void popMemoryStack(const int)
void loadTrackSeedsDevice(bounded_vector< TrackSeedN > &)
void syncStreams(const bool=true)
void createTrackletsBuffers(const int)
~TimeFrameGPU() override=default
int * getDeviceNeighboursLUT(const int layer)
const int ** getDeviceROFrameClusters() const
void createNeighboursDevice(const unsigned int layer)
void loadTrackingFrameInfoDevice(const int)
void loadClustersDevice(const int)
int * getDeviceNeighboursIndexTables(const int layer)
void createUnsortedClustersDeviceArray(const int=NLayers)
const auto getDeviceROFVertexLookupTableView()
Tracklet ** getDeviceArrayTracklets()
size_t getNumberOfCells() const final
auto & getStream(const size_t stream)
synchronization
void loadUnsortedClustersDevice(const int)
void loadROFCutMask(const int)
void createClustersDeviceArray(const int=NLayers)
void createCellsLUTDevice(const int)
void syncStream(const size_t stream)
const Cluster ** getDeviceArrayUnsortedClusters() const
gsl::span< int * > getDeviceNeighboursLUTs()
CellNeighbour ** getDeviceArrayNeighbours()
CellNeighbour * getDeviceNeighbours(const int layer)
void setDevicePropagator(const o2::base::PropagatorImpl< float > *p) final
int ** getDeviceArrayTrackletsLUT() const
gsl::span< int > getNCells()
int ** getDeviceArrayNeighboursCellLUT() const
const o2::base::Propagator * getChainPropagator()
const Cluster ** getDeviceArrayClusters() const
void recordEvents(const int=0, const int=NLayers)
gsl::span< int > getNNeighbours()
const TrackingFrameInfo ** getDeviceArrayTrackingFrameInfo() const
IndexTableUtilsN * getDeviceIndexTableUtils()
void createNeighboursLUTDevice(const int, const unsigned int)
void loadROFrameClustersDevice(const int)
std::array< CellNeighbour *, MaxCells > & getDeviceNeighboursAll()
void createUsedClustersDeviceArray(const int=NLayers)
gsl::span< int * > getDeviceCellLUTs()
void initialise(const TrackingParameters &, int maxLayers)
TrackingFrameInfo * getDeviceTrackingFrameInfo(const int)
void createCellsBuffers(const int)
gsl::span< int > getNTracklets()
void createTrackITSExtDevice(const size_t)
std::vector< unsigned int > getClusterSizes()
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
o2::dataformats::Vertex< o2::its::TimeEstBC > Vertex
Definition Vertex.h:26
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:68
TrackSeed< NLayers > TrackSeedN
Definition TimeFrame.h:71
IndexTableUtils< NLayers > IndexTableUtilsN
Definition TimeFrame.h:66
const o2::base::PropagatorImpl< float > * mPropagatorDevice
Definition TimeFrame.h:287
TrackingTopologyN::View mTrackingTopologyView
Definition TimeFrame.h:334
TrackingTopology< NLayers > TrackingTopologyN
Definition TimeFrame.h:70
ROFOverlapTable< NLayers > ROFOverlapTableN
Definition TimeFrame.h:67
ROFMaskTable< NLayers > ROFMaskTableN
Definition TimeFrame.h:69