Project
Loading...
Searching...
No Matches
VertexerTraitsGPU.cxx
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.
11//
13
14#include <iostream>
15#include <sstream>
16#include <fstream>
17#include <array>
18#include <cassert>
19#include <thread>
20
21#ifdef VTX_DEBUG
22#include "TTree.h"
23#include "TFile.h"
24#endif
25
28
29namespace o2::its
30{
35
36void VertexerTraitsGPU::initialise(const TrackingParameters& trackingParams, const int iteration)
37{
38 mTimeFrameGPU->initialise(0, trackingParams, 3, &mIndexTableUtils, &mTfGPUParams);
39}
40
41void VertexerTraitsGPU::updateVertexingParameters(const std::vector<VertexingParameters>& vrtPar, const TimeFrameGPUParameters& tfPar)
42{
43 mVrtParams = vrtPar;
44 mTfGPUParams = tfPar;
46 for (auto& par : mVrtParams) {
47 par.phiSpan = static_cast<int>(std::ceil(mIndexTableUtils.getNphiBins() * par.phiCut / constants::math::TwoPi));
48 par.zSpan = static_cast<int>(std::ceil(par.zCut * mIndexTableUtils.getInverseZCoordinate(0)));
49 }
50}
51
52void VertexerTraitsGPU::computeTracklets(const int iteration)
53{
54 if (!mTimeFrameGPU->getClusters().size()) {
55 return;
56 }
57 std::vector<std::thread> threads(mTimeFrameGPU->getNChunks());
58 for (int chunkId{0}; chunkId < mTimeFrameGPU->getNChunks(); ++chunkId) {
59 // int rofPerChunk{mTimeFrameGPU->mNrof / (int)mTimeFrameGPU->getNChunks()};
60 // mTimeFrameGPU->getVerticesInChunks()[chunkId].clear();
61 // mTimeFrameGPU->getNVerticesInChunks()[chunkId].clear();
62 // mTimeFrameGPU->getLabelsInChunks()[chunkId].clear();
63 // auto doVertexReconstruction = [&, chunkId, rofPerChunk]() -> void {
64 // auto offset = chunkId * rofPerChunk;
65 // auto maxROF = offset + rofPerChunk;
66 // while (offset < maxROF) {
67 // auto rofs = mTimeFrameGPU->loadChunkData<gpu::Task::Vertexer>(chunkId, offset, maxROF);
68 // RANGE("chunk_gpu_vertexing", 1);
69 // // gpu::GpuTimer timer{offset, mTimeFrameGPU->getStream(chunkId).get()};
70 // // timer.Start("vtTrackletFinder");
71 // gpu::trackleterKernelMultipleRof<TrackletMode::Layer0Layer1><<<rofs, 1024, 0, mTimeFrameGPU->getStream(chunkId).get()>>>(
72 // mTimeFrameGPU->getChunk(chunkId).getDeviceClusters(0), // const Cluster* clustersNextLayer, // 0 2
73 // mTimeFrameGPU->getChunk(chunkId).getDeviceClusters(1), // const Cluster* clustersCurrentLayer, // 1 1
74 // mTimeFrameGPU->getDeviceROframesClusters(0), // const int* sizeNextLClusters,
75 // mTimeFrameGPU->getDeviceROframesClusters(1), // const int* sizeCurrentLClusters,
76 // mTimeFrameGPU->getChunk(chunkId).getDeviceIndexTables(0), // const int* nextIndexTables,
77 // mTimeFrameGPU->getChunk(chunkId).getDeviceTracklets(0), // Tracklet* Tracklets,
78 // mTimeFrameGPU->getChunk(chunkId).getDeviceNTrackletCluster(0), // int* foundTracklets,
79 // mTimeFrameGPU->getDeviceIndexTableUtils(), // const IndexTableUtils* utils,
80 // offset, // const unsigned int startRofId,
81 // rofs, // const unsigned int rofSize,
82 // mVrtParams.phiCut, // const float phiCut,
83 // mVrtParams.maxTrackletsPerCluster); // const size_t maxTrackletsPerCluster = 1e2
84
85 // gpu::trackleterKernelMultipleRof<TrackletMode::Layer1Layer2><<<rofs, 1024, 0, mTimeFrameGPU->getStream(chunkId).get()>>>(
86 // mTimeFrameGPU->getChunk(chunkId).getDeviceClusters(2), // const Cluster* clustersNextLayer, // 0 2
87 // mTimeFrameGPU->getChunk(chunkId).getDeviceClusters(1), // const Cluster* clustersCurrentLayer, // 1 1
88 // mTimeFrameGPU->getDeviceROframesClusters(2), // const int* sizeNextLClusters,
89 // mTimeFrameGPU->getDeviceROframesClusters(1), // const int* sizeCurrentLClusters,
90 // mTimeFrameGPU->getChunk(chunkId).getDeviceIndexTables(2), // const int* nextIndexTables,
91 // mTimeFrameGPU->getChunk(chunkId).getDeviceTracklets(1), // Tracklet* Tracklets,
92 // mTimeFrameGPU->getChunk(chunkId).getDeviceNTrackletCluster(1), // int* foundTracklets,
93 // mTimeFrameGPU->getDeviceIndexTableUtils(), // const IndexTableUtils* utils,
94 // offset, // const unsigned int startRofId,
95 // rofs, // const unsigned int rofSize,
96 // mVrtParams.phiCut, // const float phiCut,
97 // mVrtParams.maxTrackletsPerCluster); // const size_t maxTrackletsPerCluster = 1e2
98
99 // gpu::trackletSelectionKernelMultipleRof<true><<<rofs, 1024, 0, mTimeFrameGPU->getStream(chunkId).get()>>>(
100 // mTimeFrameGPU->getChunk(chunkId).getDeviceClusters(0), // const Cluster* clusters0, // Clusters on layer 0
101 // mTimeFrameGPU->getChunk(chunkId).getDeviceClusters(1), // const Cluster* clusters1, // Clusters on layer 1
102 // mTimeFrameGPU->getDeviceROframesClusters(0), // const int* sizeClustersL0, // Number of clusters on layer 0 per ROF
103 // mTimeFrameGPU->getDeviceROframesClusters(1), // const int* sizeClustersL1, // Number of clusters on layer 1 per ROF
104 // mTimeFrameGPU->getChunk(chunkId).getDeviceTracklets(0), // Tracklet* tracklets01, // Tracklets on layer 0-1
105 // mTimeFrameGPU->getChunk(chunkId).getDeviceTracklets(1), // Tracklet* tracklets12, // Tracklets on layer 1-2
106 // mTimeFrameGPU->getChunk(chunkId).getDeviceNTrackletCluster(0), // const int* nFoundTracklets01, // Number of tracklets found on layers 0-1
107 // mTimeFrameGPU->getChunk(chunkId).getDeviceNTrackletCluster(1), // const int* nFoundTracklet12, // Number of tracklets found on layers 1-2
108 // mTimeFrameGPU->getChunk(chunkId).getDeviceUsedTracklets(), // unsigned char* usedTracklets, // Used tracklets
109 // mTimeFrameGPU->getChunk(chunkId).getDeviceLines(), // Line* lines, // Lines
110 // mTimeFrameGPU->getChunk(chunkId).getDeviceNFoundLines(), // int* nFoundLines, // Number of found lines
111 // mTimeFrameGPU->getChunk(chunkId).getDeviceNExclusiveFoundLines(), // int* nExclusiveFoundLines, // Number of found lines exclusive scan
112 // offset, // const unsigned int startRofId, // Starting ROF ID
113 // rofs, // const unsigned int rofSize, // Number of ROFs to consider
114 // mVrtParams.maxTrackletsPerCluster, // const int maxTrackletsPerCluster = 1e2, // Maximum number of tracklets per cluster
115 // mVrtParams.tanLambdaCut, // const float tanLambdaCut = 0.025f, // Cut on tan lambda
116 // mVrtParams.phiCut); // const float phiCut = 0.002f) // Cut on phi
117
118 // discardResult(cub::DeviceScan::ExclusiveSum(mTimeFrameGPU->getChunk(chunkId).getDeviceCUBTmpBuffer(),
119 // mTimeFrameGPU->getChunk(chunkId).getTimeFrameGPUParameters()->tmpCUBBufferSize,
120 // mTimeFrameGPU->getChunk(chunkId).getDeviceNFoundLines(),
121 // mTimeFrameGPU->getChunk(chunkId).getDeviceNExclusiveFoundLines(),
122 // mTimeFrameGPU->getTotalClustersPerROFrange(offset, rofs, 1),
123 // mTimeFrameGPU->getStream(chunkId).get()));
124
125 // // Reset used tracklets
126 // checkGPUError(cudaMemsetAsync(mTimeFrameGPU->getChunk(chunkId).getDeviceUsedTracklets(),
127 // false,
128 // sizeof(unsigned char) * mVrtParams.maxTrackletsPerCluster * mTimeFrameGPU->getTotalClustersPerROFrange(offset, rofs, 1),
129 // mTimeFrameGPU->getStream(chunkId).get()),
130 // __FILE__, __LINE__);
131
132 // gpu::trackletSelectionKernelMultipleRof<false><<<rofs, 1024, 0, mTimeFrameGPU->getStream(chunkId).get()>>>(
133 // mTimeFrameGPU->getChunk(chunkId).getDeviceClusters(0), // const Cluster* clusters0, // Clusters on layer 0
134 // mTimeFrameGPU->getChunk(chunkId).getDeviceClusters(1), // const Cluster* clusters1, // Clusters on layer 1
135 // mTimeFrameGPU->getDeviceROframesClusters(0), // const int* sizeClustersL0, // Number of clusters on layer 0 per ROF
136 // mTimeFrameGPU->getDeviceROframesClusters(1), // const int* sizeClustersL1, // Number of clusters on layer 1 per ROF
137 // mTimeFrameGPU->getChunk(chunkId).getDeviceTracklets(0), // Tracklet* tracklets01, // Tracklets on layer 0-1
138 // mTimeFrameGPU->getChunk(chunkId).getDeviceTracklets(1), // Tracklet* tracklets12, // Tracklets on layer 1-2
139 // mTimeFrameGPU->getChunk(chunkId).getDeviceNTrackletCluster(0), // const int* nFoundTracklets01, // Number of tracklets found on layers 0-1
140 // mTimeFrameGPU->getChunk(chunkId).getDeviceNTrackletCluster(1), // const int* nFoundTracklet12, // Number of tracklets found on layers 1-2
141 // mTimeFrameGPU->getChunk(chunkId).getDeviceUsedTracklets(), // unsigned char* usedTracklets, // Used tracklets
142 // mTimeFrameGPU->getChunk(chunkId).getDeviceLines(), // Line* lines, // Lines
143 // mTimeFrameGPU->getChunk(chunkId).getDeviceNFoundLines(), // int* nFoundLines, // Number of found lines
144 // mTimeFrameGPU->getChunk(chunkId).getDeviceNExclusiveFoundLines(), // int* nExclusiveFoundLines, // Number of found lines exclusive scan
145 // offset, // const unsigned int startRofId, // Starting ROF ID
146 // rofs, // const unsigned int rofSize, // Number of ROFs to consider
147 // mVrtParams.maxTrackletsPerCluster, // const int maxTrackletsPerCluster = 1e2, // Maximum number of tracklets per cluster
148 // mVrtParams.tanLambdaCut, // const float tanLambdaCut = 0.025f, // Cut on tan lambda
149 // mVrtParams.phiCut); // const float phiCut = 0.002f) // Cut on phi
150
151 // int nClusters = mTimeFrameGPU->getTotalClustersPerROFrange(offset, rofs, 1);
152 // int lastFoundLines;
153 // std::vector<int> exclusiveFoundLinesHost(nClusters + 1);
154
155 // // Obtain whole exclusive sum including nCluster+1 element (nCluster+1)th element is the total number of found lines.
156 // checkGPUError(cudaMemcpyAsync(exclusiveFoundLinesHost.data(), mTimeFrameGPU->getChunk(chunkId).getDeviceNExclusiveFoundLines(), (nClusters) * sizeof(int), cudaMemcpyDeviceToHost, mTimeFrameGPU->getStream(chunkId).get()));
157 // checkGPUError(cudaMemcpyAsync(&lastFoundLines, mTimeFrameGPU->getChunk(chunkId).getDeviceNFoundLines() + nClusters - 1, sizeof(int), cudaMemcpyDeviceToHost, mTimeFrameGPU->getStream(chunkId).get()));
158 // exclusiveFoundLinesHost[nClusters] = exclusiveFoundLinesHost[nClusters - 1] + lastFoundLines;
159
160 // std::vector<Line> lines(exclusiveFoundLinesHost[nClusters]);
161
162 // checkGPUError(cudaMemcpyAsync(lines.data(), mTimeFrameGPU->getChunk(chunkId).getDeviceLines(), sizeof(Line) * lines.size(), cudaMemcpyDeviceToHost, mTimeFrameGPU->getStream(chunkId).get()));
163 // checkGPUError(cudaStreamSynchronize(mTimeFrameGPU->getStream(chunkId).get()));
164
165 // // Compute vertices
166 // std::vector<ClusterLines> clusterLines;
167 // std::vector<bool> usedLines;
168 // for (int rofId{0}; rofId < rofs; ++rofId) {
169 // auto rof = offset + rofId;
170 // auto clustersL1offsetRof = mTimeFrameGPU->getROframeClusters(1)[rof] - mTimeFrameGPU->getROframeClusters(1)[offset]; // starting cluster offset for this ROF
171 // auto nClustersL1Rof = mTimeFrameGPU->getROframeClusters(1)[rof + 1] - mTimeFrameGPU->getROframeClusters(1)[rof]; // number of clusters for this ROF
172 // auto linesOffsetRof = exclusiveFoundLinesHost[clustersL1offsetRof]; // starting line offset for this ROF
173 // auto nLinesRof = exclusiveFoundLinesHost[clustersL1offsetRof + nClustersL1Rof] - linesOffsetRof;
174 // gsl::span<const o2::its::Line> linesInRof(lines.data() + linesOffsetRof, static_cast<gsl::span<o2::its::Line>::size_type>(nLinesRof));
175
176 // usedLines.resize(linesInRof.size(), false);
177 // usedLines.assign(linesInRof.size(), false);
178 // clusterLines.clear();
179 // clusterLines.reserve(nClustersL1Rof);
180 // computeVerticesInRof(rof,
181 // linesInRof,
182 // usedLines,
183 // clusterLines,
184 // mTimeFrameGPU->getBeamXY(),
185 // mTimeFrameGPU->getVerticesInChunks()[chunkId],
186 // mTimeFrameGPU->getNVerticesInChunks()[chunkId],
187 // mTimeFrameGPU,
188 // mTimeFrameGPU->hasMCinformation() ? &mTimeFrameGPU->getLabelsInChunks()[chunkId] : nullptr);
189 // }
190 // offset += rofs;
191 // }
192 // };
193 // // Do work
194 // threads[chunkId] = std::thread(doVertexReconstruction);
195 // }
196 // for (auto& thread : threads) {
197 // thread.join();
198 // }
199 // for (int chunkId{0}; chunkId < mTimeFrameGPU->getNChunks(); ++chunkId) {
200 // int start{0};
201 // for (int rofId{0}; rofId < mTimeFrameGPU->getNVerticesInChunks()[chunkId].size(); ++rofId) {
202 // gsl::span<const Vertex> rofVerts{mTimeFrameGPU->getVerticesInChunks()[chunkId].data() + start, static_cast<gsl::span<Vertex>::size_type>(mTimeFrameGPU->getNVerticesInChunks()[chunkId][rofId])};
203 // mTimeFrameGPU->addPrimaryVertices(rofVerts);
204 // if (mTimeFrameGPU->hasMCinformation()) {
205 // mTimeFrameGPU->getVerticesLabels().emplace_back();
206 // // TODO: add MC labels
207 // }
208 // start += mTimeFrameGPU->getNVerticesInChunks()[chunkId][rofId];
209 // }
210 // }
211 // mTimeFrameGPU->wipe(3);
212 }
213}
214
216{
217}
218
219void VertexerTraitsGPU::computeVertices(const int iteration)
220{
221}
222
226
231} // namespace o2::its
void setTrackingParameters(const T &params)
float getInverseZCoordinate(const int layerIndex) const
std::vector< std::vector< Cluster > > & getClusters()
Definition TimeFrame.h:638
void computeTrackletMatching(const int iteration=0) override
TimeFrameGPUParameters mTfGPUParams
void initialise(const TrackingParameters &, const int iteration=0) override
gpu::TimeFrameGPU< 7 > * mTimeFrameGPU
void computeTracklets(const int iteration=0) override
void updateVertexingParameters(const std::vector< VertexingParameters > &, const TimeFrameGPUParameters &) override
void computeVertices(const int iteration=0) override
void setIsGPU(const unsigned char isgpu)
std::vector< VertexingParameters > mVrtParams
IndexTableUtils mIndexTableUtils
void initialise(const int, const TrackingParameters &, const int, IndexTableUtils *utils=nullptr, const TimeFrameGPUParameters *pars=nullptr)
constexpr float TwoPi
Definition Constants.h:44
VertexerTraits * createVertexerTraitsGPU()