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