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
19
20#include <gsl/gsl>
21
22namespace o2::its::gpu
23{
24
25class Stream;
26
28{
29 void* allocate(size_t size) override;
30};
31
32template <int nLayers = 7>
33class TimeFrameGPU : public TimeFrame
34{
35 public:
38
40 void registerHostMemory(const int);
41 void unregisterHostMemory(const int);
42 void initialise(const int, const TrackingParameters&, const int, IndexTableUtils* utils = nullptr, const TimeFrameGPUParameters* pars = nullptr);
43 void initDevice(IndexTableUtils*, const TrackingParameters& trkParam, const TimeFrameGPUParameters&, const int, const int);
45 void loadIndexTableUtils(const int);
48 void loadClustersDevice(const int);
49 void loadClustersIndexTables(const int iteration);
50 void createUsedClustersDevice(const int);
53 void loadMultiplicityCutMask(const int);
54 void loadVertices(const int);
55
57 void createTrackletsLUTDevice(const int);
65 void loadTrackSeedsDevice(std::vector<CellSeed>&);
67 void createCellsBuffers(const int);
71 void createNeighboursDevice(const unsigned int layer, const unsigned int nNeighbours);
72 void createNeighboursDevice(const unsigned int layer, std::vector<std::pair<int, int>>& neighbours);
73 void createNeighboursLUTDevice(const int, const unsigned int);
75 void createTrackITSExtDevice(std::vector<CellSeed>&);
76 void downloadTrackITSExtDevice(std::vector<CellSeed>&);
77 void downloadCellsNeighboursDevice(std::vector<std::vector<std::pair<int, int>>>&, const int);
78 void downloadNeighboursLUTDevice(std::vector<int>&, const int);
82 template <Task task>
83 Stream& getStream(const size_t stream)
84 {
85 return *mGpuStreams[stream];
86 }
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 std::vector<o2::its::TrackITSExt>& 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; }
108 TrackingFrameInfo* getDeviceTrackingFrameInfo(const int);
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 std::array<int, nLayers - 2>& getArrayNCells() { return mNCells; }
133
134 // Host-available device getters
135 gsl::span<int*> getDeviceTrackletsLUTs() { return mTrackletsLUTDevice; }
136 gsl::span<int*> getDeviceCellLUTs() { return mCellsLUTDevice; }
137 gsl::span<Tracklet*> getDeviceTracklet() { return mTrackletsDevice; }
138 gsl::span<CellSeed*> getDeviceCells() { return mCellsDevice; }
139
140 // Overridden getters
141 int getNumberOfCells() const;
142
143 private:
144 void allocMemAsync(void**, size_t, Stream*, bool); // Abstract owned and unowned memory allocations
145 bool mHostRegistered = false;
146 TimeFrameGPUParameters mGpuParams;
147
148 // Host-available device buffer sizes
149 std::array<int, nLayers - 1> mNTracklets;
150 std::array<int, nLayers - 2> mNCells;
151
152 // Device pointers
153 IndexTableUtils* mIndexTableUtilsDevice;
154
155 // Hybrid pref
156 uint8_t* mMultMaskDevice;
157 Vertex* mPrimaryVerticesDevice;
158 int* mROFramesPVDevice;
159 std::array<Cluster*, nLayers> mClustersDevice;
160 std::array<Cluster*, nLayers> mUnsortedClustersDevice;
161 std::array<int*, nLayers> mClustersIndexTablesDevice;
162 std::array<unsigned char*, nLayers> mUsedClustersDevice;
163 std::array<int*, nLayers> mROFramesClustersDevice;
164 const Cluster** mClustersDeviceArray;
165 const Cluster** mUnsortedClustersDeviceArray;
166 const int** mClustersIndexTablesDeviceArray;
167 const unsigned char** mUsedClustersDeviceArray;
168 const int** mROFrameClustersDeviceArray;
169 std::array<Tracklet*, nLayers - 1> mTrackletsDevice;
170 Tracklet** mTrackletsDeviceArray;
171 std::array<int*, nLayers - 1> mTrackletsLUTDevice;
172 std::array<int*, nLayers - 2> mCellsLUTDevice;
173 std::array<int*, nLayers - 3> mNeighboursLUTDevice;
174
175 int** mCellsLUTDeviceArray;
176 int** mNeighboursCellDeviceArray;
177 int** mNeighboursCellLUTDeviceArray;
178 int** mTrackletsLUTDeviceArray;
179 std::array<CellSeed*, nLayers - 2> mCellsDevice;
180 std::array<int*, nLayers - 2> mNeighboursIndexTablesDevice;
181 CellSeed* mTrackSeedsDevice;
182 CellSeed** mCellsDeviceArray;
183 std::array<o2::track::TrackParCovF*, nLayers - 2> mCellSeedsDevice;
184 o2::track::TrackParCovF** mCellSeedsDeviceArray;
185 std::array<float*, nLayers - 2> mCellSeedsChi2Device;
186 float** mCellSeedsChi2DeviceArray;
187
188 Road<nLayers - 2>* mRoadsDevice;
189 TrackITSExt* mTrackITSExtDevice;
190 std::array<gpuPair<int, int>*, nLayers - 2> mNeighbourPairsDevice;
191 std::array<int*, nLayers - 2> mNeighboursDevice;
192 int** mNeighboursDeviceArray;
193 std::array<TrackingFrameInfo*, nLayers> mTrackingFrameInfoDevice;
194 const TrackingFrameInfo** mTrackingFrameInfoDeviceArray;
195
196 // State
197 std::vector<Stream*> mGpuStreams;
198 size_t mAvailMemGB;
199 bool mFirstInit = true;
200
201 // Temporary buffer for storing output tracks from GPU tracking
202 std::vector<TrackITSExt> mTrackITSExt;
203};
204
205template <int nLayers>
206inline int TimeFrameGPU<nLayers>::getNClustersInRofSpan(const int rofIdstart, const int rofSpanSize, const int layerId) const
207{
208 return static_cast<int>(mROFramesClusters[layerId][(rofIdstart + rofSpanSize) < mROFramesClusters.size() ? rofIdstart + rofSpanSize : mROFramesClusters.size() - 1] - mROFramesClusters[layerId][rofIdstart]);
209}
210
211template <int nLayers>
212inline std::vector<unsigned int> TimeFrameGPU<nLayers>::getClusterSizes()
213{
214 std::vector<unsigned int> sizes(mUnsortedClusters.size());
215 std::transform(mUnsortedClusters.begin(), mUnsortedClusters.end(), sizes.begin(),
216 [](const auto& v) { return static_cast<unsigned int>(v.size()); });
217 return sizes;
218}
219
220template <int nLayers>
222{
223 return std::accumulate(mNCells.begin(), mNCells.end(), 0);
224}
225
226} // namespace o2::its::gpu
227
228#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 downloadNeighboursLUTDevice(std::vector< int > &, const int)
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
void createTrackITSExtDevice(std::vector< CellSeed > &)
std::array< int *, nLayers - 2 > & getDeviceNeighboursAll()
gsl::span< Tracklet * > getDeviceTracklet()
CellSeed ** getDeviceArrayCells() const
void createNeighboursDevice(const unsigned int layer, std::vector< std::pair< int, int > > &neighbours)
void loadVertices(const int)
int * getDeviceNeighboursLUT(const int layer)
std::vector< o2::its::TrackITSExt > & getTrackITSExt()
Road< nLayers - 2 > * getDeviceRoads()
void registerHostMemory(const int)
Most relevant operations.
void loadClustersIndexTables(const int iteration)
o2::track::TrackParCovF ** getDeviceArrayTrackSeeds()
void downloadTrackITSExtDevice(std::vector< CellSeed > &)
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
gsl::span< int * > getDeviceTrackletsLUTs()
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)
void loadTrackSeedsDevice(std::vector< CellSeed > &)
int * getDeviceROFramesClusters(const int layer)
const Cluster ** getDeviceArrayClusters() const
void downloadCellsNeighboursDevice(std::vector< std::vector< std::pair< int, int > > > &, const int)
void unregisterHostMemory(const int)
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
TrackParametrizationWithError< float > TrackParCovF
Definition Track.h:31
Common utility functions.