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