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);
49 void initialise(const TrackingParameters&, int maxLayers);
50 void initialise(const TrackingParameters&, int maxLayers, int iteration);
54 void createTrackingFrameInfoDeviceArray(const int = NLayers);
56 void createUnsortedClustersDeviceArray(const int = NLayers);
57 void loadClustersDevice(const int);
58 void createClustersDeviceArray(const int = NLayers);
59 void loadClustersIndexTables(const int);
60 void createClustersIndexTablesArray(const int = NLayers);
61 void createUsedClustersDevice(const int);
62 void createUsedClustersDeviceArray(const int = NLayers);
65 void createROFrameClustersDeviceArray(const int = NLayers);
66 void loadROFCutMask(const int);
72
74 void createTrackletsLUTDevice(bool, const int);
76 void createTrackSeedsDevice(const size_t capacity);
77 void createTrackletsBuffers(const int, size_t capacity);
79 void createCellsBuffers(const int, size_t capacity);
81 void createCellsLUTDevice(const int);
83 void createNeighboursDevice(const unsigned int layer, size_t capacity);
84 void createNeighboursLUTDevice(const int, const unsigned int);
85 void createTrackITSExtDevice(const size_t capacity);
86 void createTrackITSExtHost(const size_t nTracks);
87 void createTrackExtensionScratchDevice(const int nThreads, const int maxHypotheses);
89
91 auto& getStream(const size_t stream) { return mGpuStreams[stream]; }
92 auto& getStreams() { return mGpuStreams; }
93 void syncStreams(const bool = true);
94 void waitEvent(const int, const int);
95 void recordEvent(const int);
96
98 virtual void wipe() final;
99
101 virtual bool isGPU() const noexcept final { return true; }
102 virtual const char* getName() const noexcept override final { return "GPU"; }
103 IndexTableUtilsN* getDeviceIndexTableUtils() { return mIndexTableUtilsDevice; }
104 const float* getDeviceLayerRadii() const { return mLayerRadiiDevice; }
105 const float* getDeviceMinPts() const { return mMinPtsDevice; }
106 const float* getDeviceLayerxX0() const { return mLayerxX0Device; }
107 const auto getDeviceROFOverlapTableView() { return mDeviceROFOverlapTableView; }
108 const auto getDeviceROFVertexLookupTableView() { return mDeviceROFVertexLookupTableView; }
109 const auto getDeviceROFMaskTableView() { return mDeviceROFMaskTableView; }
110 const auto getDeviceTrackingTopologyView() const { return mDeviceTrackingTopologyView; }
111 auto& getTrackITSExt() { return mTrackITSExt; }
112 auto& getTrackIndices() { return mTrackIndices; }
113 Vertex* getDeviceVertices() { return mPrimaryVerticesDevice; }
114
115 // Hybrid
116 TrackITSExt* getDeviceTrackITSExt() { return mTrackITSExtDevice; }
117 int* getDeviceTrackIndices() { return mTrackIndicesDevice; }
118 TrackExtensionHypothesis<NLayers>* getDeviceActiveTrackExtensionHypotheses() { return mActiveTrackExtensionHypothesesDevice; }
119 TrackExtensionHypothesis<NLayers>* getDeviceNextTrackExtensionHypotheses() { return mNextTrackExtensionHypothesesDevice; }
120 int* getDeviceNeighboursLUT(const int layer) { return mNeighboursLUTDevice[layer]; }
121 CellNeighbour** getDeviceArrayNeighbours() { return mNeighboursDeviceArray; }
122 CellNeighbour* getDeviceNeighbours(const int layer) { return mNeighboursDevice[layer]; }
123 const TrackingFrameInfo** getDeviceArrayTrackingFrameInfo() const { return mTrackingFrameInfoDeviceArray; }
124 const Cluster** getDeviceArrayClusters() const { return mClustersDeviceArray; }
125 const Cluster** getDeviceArrayUnsortedClusters() const { return mUnsortedClustersDeviceArray; }
126 const int** getDeviceArrayClustersIndexTables() const { return mClustersIndexTablesDeviceArray; }
127 std::vector<unsigned int> getClusterSizes();
128 uint8_t** getDeviceArrayUsedClusters() const { return mUsedClustersDeviceArray; }
129 const int** getDeviceROFrameClusters() const { return mROFramesClustersDeviceArray; }
130 Tracklet** getDeviceArrayTracklets() { return mTrackletsDeviceArray; }
131 int** getDeviceArrayTrackletsLUT() const { return mTrackletsLUTDeviceArray; }
132 int** getDeviceArrayCellsLUT() const { return mCellsLUTDeviceArray; }
133 int** getDeviceArrayNeighboursCellLUT() const { return mNeighboursCellLUTDeviceArray; }
134 CellSeed** getDeviceArrayCells() { return mCellsDeviceArray; }
135 TrackSeedN* getDeviceTrackSeeds() { return mTrackSeedsDevice; }
136 int* getDeviceTrackSeedIndices() { return mTrackSeedIndicesDevice; }
137 int* getDeviceTrackCounter() { return mTrackCounterDevice; }
138 auto getNTrackSeeds() const { return mNTracks; }
139
141
142 // Host-specific getters
143 gsl::span<int> getNTracklets() { return {mNTracklets.data(), static_cast<gsl::span<int>::size_type>(this->mTrackingTopologyView.nLinks)}; }
144 gsl::span<int> getNCells() { return {mNCells.data(), static_cast<gsl::span<int>::size_type>(this->mTrackingTopologyView.nCells)}; }
145 auto& getArrayNCells() { return mNCells; }
146 gsl::span<int> getNNeighbours() { return {mNNeighbours.data(), static_cast<gsl::span<int>::size_type>(this->mTrackingTopologyView.nCells)}; }
147
148 // Host-available device getters
149 gsl::span<int*> getDeviceTrackletsLUTs() { return mTrackletsLUTDevice; }
150 gsl::span<int*> getDeviceCellLUTs() { return mCellsLUTDevice; }
151 gsl::span<Tracklet*> getDeviceTracklets() { return mTrackletsDevice; }
152 gsl::span<CellSeed*> getDeviceCells() { return mCellsDevice; }
153
154 // Overridden getters
155 size_t getNumberOfTracklets() const final;
156 size_t getNumberOfCells() const final;
157 size_t getNumberOfNeighbours() const final;
158
159 private:
160 enum class SlotInit {
161 Raw,
162 Zero
163 };
164
165 template <typename T>
166 T* allocDevice(size_t n, int32_t type = o2::gpu::GPUMemoryResource::MEMORY_GPU);
167 template <typename T>
168 T* allocDeviceAsync(size_t n, Stream&, int32_t type = o2::gpu::GPUMemoryResource::MEMORY_GPU);
169 template <typename SlotPtr>
170 SlotPtr* allocSlotArray(size_t n);
171 template <typename T>
172 void copyToDevice(T* dst, const T* src, size_t n);
173 template <typename T>
174 void copyFromDevice(T* dst, const T* src, size_t n);
175 template <typename T, typename ArrayT>
176 void publishSlot(ArrayT deviceArray, int slot, T* const& devicePtr, Stream&);
177 template <typename T, size_t N, typename ArrayT>
178 T* createSlot(std::array<T*, N>& slots, ArrayT deviceArray, int slot, size_t n, const char* what, SlotInit init = SlotInit::Raw, int32_t type = o2::gpu::GPUMemoryResource::MEMORY_GPU);
179 template <typename T, size_t N, typename ArrayT, typename Container>
180 void uploadSlot(std::array<T*, N>& slots, ArrayT deviceArray, int slot, const Container& host, const char* what);
181 template <typename ArrayT, typename T, size_t N>
182 void createPinnedSlotArray(ArrayT& deviceArray, std::array<T*, N>& slots, std::bitset<NLayers + 1>& pinned);
183 template <typename Layers>
184 void pinHostLayers(Layers& layers, std::bitset<NLayers + 1>& pinned, int maxLayers);
185 template <typename Table>
186 typename Table::View uploadNavigationTable(const Table& table, const typename Table::View& hostView);
187
188 // Host-available device buffer sizes
189 std::array<int, MaxLinks> mNTracklets{};
190 std::array<int, MaxCells> mNCells{};
191 std::array<int, MaxCells> mNNeighbours{};
192
193 // Device pointers
194 IndexTableUtilsN* mIndexTableUtilsDevice{nullptr};
195 float* mIterationParametersDevice{nullptr};
196 const float* mLayerRadiiDevice{nullptr};
197 const float* mMinPtsDevice{nullptr};
198 const float* mLayerxX0Device{nullptr};
199 // device navigation views
200 ROFOverlapTableN::View mDeviceROFOverlapTableView;
201 ROFVertexLookupTableN::View mDeviceROFVertexLookupTableView;
202 ROFMaskTableN::View mDeviceROFMaskTableView;
203 std::vector<typename TrackingTopologyN::View> mDeviceTrackerTopologyViews;
204 typename TrackingTopologyN::View mDeviceTrackingTopologyView;
205
206 // Hybrid pref
207 Vertex* mPrimaryVerticesDevice{nullptr};
208 std::array<Cluster*, NLayers> mClustersDevice{};
209 std::array<Cluster*, NLayers> mUnsortedClustersDevice{};
210 std::array<int*, NLayers> mClustersIndexTablesDevice{};
211 std::array<unsigned char*, NLayers> mUsedClustersDevice{};
212 std::array<int*, NLayers> mROFramesClustersDevice{};
213 const Cluster** mClustersDeviceArray{nullptr};
214 const Cluster** mUnsortedClustersDeviceArray{nullptr};
215 const int** mClustersIndexTablesDeviceArray{nullptr};
216 uint8_t** mUsedClustersDeviceArray{nullptr};
217 const int** mROFramesClustersDeviceArray{nullptr};
218 std::array<Tracklet*, MaxLinks> mTrackletsDevice{};
219 std::array<int*, MaxLinks> mTrackletsLUTDevice{};
220 std::array<int*, MaxCells> mCellsLUTDevice{};
221 std::array<int*, MaxCells> mNeighboursLUTDevice{};
222
223 Tracklet** mTrackletsDeviceArray{nullptr};
224 int** mCellsLUTDeviceArray{nullptr};
225 int** mNeighboursCellLUTDeviceArray{nullptr};
226 int** mTrackletsLUTDeviceArray{nullptr};
227 std::array<CellSeed*, MaxCells> mCellsDevice{};
228 CellSeed** mCellsDeviceArray{nullptr};
229 TrackSeedN* mTrackSeedsDevice{nullptr};
230 int* mTrackSeedIndicesDevice{nullptr};
231 int* mTrackCounterDevice{nullptr};
232 unsigned int mNTracks{0};
233
234 TrackITSExt* mTrackITSExtDevice{nullptr};
235 int* mTrackIndicesDevice{nullptr};
236 TrackExtensionHypothesis<NLayers>* mActiveTrackExtensionHypothesesDevice{nullptr};
237 TrackExtensionHypothesis<NLayers>* mNextTrackExtensionHypothesesDevice{nullptr};
238 std::array<CellNeighbour*, MaxCells> mNeighboursDevice{};
239 CellNeighbour** mNeighboursDeviceArray{nullptr};
240 std::array<TrackingFrameInfo*, NLayers> mTrackingFrameInfoDevice{};
241 const TrackingFrameInfo** mTrackingFrameInfoDeviceArray{nullptr};
242
243 // State
244 Streams mGpuStreams;
245 std::bitset<NLayers + 1> mPinnedUnsortedClusters{0};
246 std::bitset<NLayers + 1> mPinnedClusters{0};
247 std::bitset<NLayers + 1> mPinnedClustersIndexTables{0};
248 std::bitset<NLayers + 1> mPinnedUsedClusters{0};
249 std::bitset<NLayers + 1> mPinnedROFramesClusters{0};
250 std::bitset<NLayers + 1> mPinnedTrackingFrameInfo{0};
251
252 // Temporary buffer for storing output tracks from GPU tracking
253 bounded_vector<TrackITSExt> mTrackITSExt;
254 bounded_vector<int> mTrackIndices;
255};
256
257template <int NLayers>
258inline std::vector<unsigned int> TimeFrameGPU<NLayers>::getClusterSizes()
259{
260 std::vector<unsigned int> sizes(this->mUnsortedClusters.size());
261 std::transform(this->mUnsortedClusters.begin(), this->mUnsortedClusters.end(), sizes.begin(),
262 [](const auto& v) { return static_cast<unsigned int>(v.size()); });
263 return sizes;
264}
265
266template <int NLayers>
268{
269 return std::accumulate(mNTracklets.begin(), mNTracklets.begin() + this->mTrackingTopologyView.nLinks, 0);
270}
271
272template <int NLayers>
274{
275 return std::accumulate(mNCells.begin(), mNCells.begin() + this->mTrackingTopologyView.nCells, 0);
276}
277
278template <int NLayers>
280{
281 return std::accumulate(mNNeighbours.begin(), mNNeighbours.begin() + this->mTrackingTopologyView.nCells, 0);
282}
283
284} // namespace o2::its::gpu
285
286#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
virtual const char * getName() const noexcept override final
virtual bool isGPU() const noexcept final
interface
void createUsedClustersDevice(const int)
TrackExtensionHypothesis< NLayers > * getDeviceActiveTrackExtensionHypotheses()
void pushMemoryStack(const int)
Most relevant operations.
void createROFrameClustersDeviceArray(const int=NLayers)
const auto getDeviceROFOverlapTableView()
void loadClustersIndexTables(const int)
TrackITSExt * getDeviceTrackITSExt()
TrackSeedN * getDeviceTrackSeeds()
void createTrackletsBuffers(const int, size_t capacity)
void initialise(const TrackingParameters &, int maxLayers, int iteration)
const auto getDeviceROFMaskTableView()
virtual void wipe() final
cleanup
void createTrackITSExtHost(const size_t nTracks)
size_t getNumberOfNeighbours() const final
void createTrackletsLUTDevice(bool, const int)
uint8_t ** getDeviceArrayUsedClusters() const
const int ** getDeviceArrayClustersIndexTables() const
const float * getDeviceMinPts() const
void createTrackExtensionScratchDevice(const int nThreads, const int maxHypotheses)
void recordEvent(const int)
int ** getDeviceArrayCellsLUT() const
CellSeed ** getDeviceArrayCells()
gsl::span< CellSeed * > getDeviceCells()
const auto getDeviceTrackingTopologyView() const
void waitEvent(const int, const int)
gsl::span< int * > getDeviceTrackletsLUTs()
void popMemoryStack(const int)
void createCellsBuffers(const int, size_t capacity)
void syncStreams(const bool=true)
~TimeFrameGPU() override=default
int * getDeviceNeighboursLUT(const int layer)
const int ** getDeviceROFrameClusters() const
void loadTrackingFrameInfoDevice(const int)
void loadClustersDevice(const int)
void createUnsortedClustersDeviceArray(const int=NLayers)
const auto getDeviceROFVertexLookupTableView()
Tracklet ** getDeviceArrayTracklets()
size_t getNumberOfCells() const final
auto & getStream(const size_t stream)
synchronization
void createTrackingFrameInfoDeviceArray(const int=NLayers)
void loadUnsortedClustersDevice(const int)
const float * getDeviceLayerxX0() const
void loadROFCutMask(const int)
void createClustersDeviceArray(const int=NLayers)
void createCellsLUTDevice(const int)
const Cluster ** getDeviceArrayUnsortedClusters() const
void loadIterationParameters(const TrackingParameters &)
CellNeighbour ** getDeviceArrayNeighbours()
CellNeighbour * getDeviceNeighbours(const int layer)
void setDevicePropagator(const o2::base::PropagatorImpl< float > *p) final
void createTrackITSExtDevice(const size_t capacity)
int ** getDeviceArrayTrackletsLUT() const
gsl::span< int > getNCells()
void createClustersIndexTablesArray(const int=NLayers)
int ** getDeviceArrayNeighboursCellLUT() const
const Cluster ** getDeviceArrayClusters() const
TrackExtensionHypothesis< NLayers > * getDeviceNextTrackExtensionHypotheses()
gsl::span< int > getNNeighbours()
const TrackingFrameInfo ** getDeviceArrayTrackingFrameInfo() const
IndexTableUtilsN * getDeviceIndexTableUtils()
void createNeighboursLUTDevice(const int, const unsigned int)
void loadROFrameClustersDevice(const int)
void createUsedClustersDeviceArray(const int=NLayers)
gsl::span< int * > getDeviceCellLUTs()
void initialise(const TrackingParameters &, int maxLayers)
void createNeighboursDevice(const unsigned int layer, size_t capacity)
const float * getDeviceLayerRadii() const
void createTrackSeedsDevice(const size_t capacity)
gsl::span< int > getNTracklets()
std::vector< unsigned int > getClusterSizes()
GLdouble n
Definition glcorearb.h:1982
GLenum src
Definition glcorearb.h:1767
const GLdouble * v
Definition glcorearb.h:832
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition glcorearb.h:2595
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLenum GLenum dst
Definition glcorearb.h:1767
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLuint GLuint stream
Definition glcorearb.h:1806
uint8_t itsSharedClusterMap uint8_t
TrackExtensionHypothesis< NLayers > int const int maxHypotheses
o2::dataformats::Vertex< o2::its::TimeEstBC > Vertex
Definition Vertex.h:26
ROFVertexLookupTable< NLayers > ROFVertexLookupTableN
Definition TimeFrame.h:70
TrackSeed< NLayers > TrackSeedN
Definition TimeFrame.h:73
IndexTableUtils< NLayers > IndexTableUtilsN
Definition TimeFrame.h:68
const o2::base::PropagatorImpl< float > * mPropagatorDevice
Definition TimeFrame.h:300
TrackingTopologyN::View mTrackingTopologyView
Definition TimeFrame.h:349
TrackingTopology< NLayers > TrackingTopologyN
Definition TimeFrame.h:72
ROFOverlapTable< NLayers > ROFOverlapTableN
Definition TimeFrame.h:69
ROFMaskTable< NLayers > ROFMaskTableN
Definition TimeFrame.h:71