Project
Loading...
Searching...
No Matches
GPUChainTrackingCompression.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
14
15#include "GPUChainTracking.h"
16#include "GPULogging.h"
17#include "GPUO2DataTypes.h"
21#include "utils/strtag.h"
22
23#include <numeric>
24
25using namespace o2::gpu;
26using namespace o2::tpc;
27
29{
31 RecoStep myStep = RecoStep::TPCCompression;
32 bool doGPU = GetRecoStepsGPU() & RecoStep::TPCCompression;
34 GPUTPCCompression& CompressorShadow = doGPU ? processorsShadow()->tpcCompressor : Compressor;
35 const auto& threadContext = GetThreadContext();
36 if (mPipelineFinalizationCtx && GetProcessingSettings().doublePipelineClusterizer) {
38 }
39
40 if (GetProcessingSettings().tpcCompressionGatherMode == 3) {
41 mRec->AllocateVolatileDeviceMemory(0); // make future device memory allocation volatile
42 }
43 SetupGPUProcessor(&Compressor, true);
44 new (Compressor.mMemory) GPUTPCCompression::memory;
45 WriteToConstantMemory(myStep, (char*)&processors()->tpcCompressor - (char*)processors(), &CompressorShadow, sizeof(CompressorShadow), 0);
46 TransferMemoryResourcesToGPU(myStep, &Compressor, 0);
47 runKernel<GPUMemClean16>(GetGridAutoStep(0, RecoStep::TPCCompression), CompressorShadow.mClusterStatus, Compressor.mMaxClusters * sizeof(CompressorShadow.mClusterStatus[0]));
48 runKernel<GPUTPCCompressionKernels, GPUTPCCompressionKernels::step0attached>(GetGridAuto(0));
49 runKernel<GPUTPCCompressionKernels, GPUTPCCompressionKernels::step1unattached>(GetGridAuto(0));
50 TransferMemoryResourcesToHost(myStep, &Compressor, 0);
51#ifdef GPUCA_TPC_GEOMETRY_O2
52 if (mPipelineFinalizationCtx && GetProcessingSettings().doublePipelineClusterizer) {
54 ((GPUChainTracking*)GetNextChainInQueue())->RunTPCClusterizer_prepare(false);
56 }
57#endif
60 memset((void*)O, 0, sizeof(*O));
61 O->nTracks = Compressor.mMemory->nStoredTracks;
66 O->nComppressionModes = param().rec.tpc.compressionTypeMask;
67 O->solenoidBz = param().bzkG;
70 Compressor.mOutputFlat->set(outputSize, *Compressor.mOutput);
71 char* hostFlatPtr = (char*)Compressor.mOutput->qTotU; // First array as allocated in GPUTPCCompression::SetPointersCompressedClusters
72 size_t copySize = 0;
73 if (GetProcessingSettings().tpcCompressionGatherMode == 3) {
74 CompressorShadow.mOutputA = Compressor.mOutput;
75 copySize = AllocateRegisteredMemory(Compressor.mMemoryResOutputGPU); // We overwrite Compressor.mOutput with the allocated output pointers on the GPU
76 }
77 const o2::tpc::CompressedClustersPtrs* P = nullptr;
78 HighResTimer* gatherTimer = nullptr;
79 int32_t outputStream = 0;
80 if (GetProcessingSettings().doublePipeline) {
81 SynchronizeStream(OutputStream()); // Synchronize output copies running in parallel from memory that might be released, only the following async copy from stacked memory is safe after the chain finishes.
82 outputStream = OutputStream();
83 }
84 if (GetProcessingSettings().tpcCompressionGatherMode >= 2) {
85 if (GetProcessingSettings().tpcCompressionGatherMode == 2) {
86 void* devicePtr = mRec->getGPUPointer(Compressor.mOutputFlat);
87 if (devicePtr != Compressor.mOutputFlat) {
88 CompressedClustersPtrs& ptrs = *Compressor.mOutput; // We need to update the ptrs with the gpu-mapped version of the host address space
89 for (uint32_t i = 0; i < sizeof(ptrs) / sizeof(void*); i++) {
90 reinterpret_cast<char**>(&ptrs)[i] = reinterpret_cast<char**>(&ptrs)[i] + (reinterpret_cast<char*>(devicePtr) - reinterpret_cast<char*>(Compressor.mOutputFlat));
91 }
92 }
93 }
94 TransferMemoryResourcesToGPU(myStep, &Compressor, outputStream);
95 constexpr uint32_t nBlocksDefault = 2;
96 constexpr uint32_t nBlocksMulti = 1 + 2 * 200;
97 switch (GetProcessingSettings().tpcCompressionGatherModeKernel) {
98 case 0:
99 runKernel<GPUTPCCompressionGatherKernels, GPUTPCCompressionGatherKernels::unbuffered>(GetGridBlkStep(nBlocksDefault, outputStream, RecoStep::TPCCompression));
100 getKernelTimer<GPUTPCCompressionGatherKernels, GPUTPCCompressionGatherKernels::unbuffered>(RecoStep::TPCCompression, 0, outputSize, false);
101 break;
102 case 1:
103 runKernel<GPUTPCCompressionGatherKernels, GPUTPCCompressionGatherKernels::buffered32>(GetGridBlkStep(nBlocksDefault, outputStream, RecoStep::TPCCompression));
104 getKernelTimer<GPUTPCCompressionGatherKernels, GPUTPCCompressionGatherKernels::buffered32>(RecoStep::TPCCompression, 0, outputSize, false);
105 break;
106 case 2:
107 runKernel<GPUTPCCompressionGatherKernels, GPUTPCCompressionGatherKernels::buffered64>(GetGridBlkStep(nBlocksDefault, outputStream, RecoStep::TPCCompression));
108 getKernelTimer<GPUTPCCompressionGatherKernels, GPUTPCCompressionGatherKernels::buffered64>(RecoStep::TPCCompression, 0, outputSize, false);
109 break;
110 case 3:
111 runKernel<GPUTPCCompressionGatherKernels, GPUTPCCompressionGatherKernels::buffered128>(GetGridBlkStep(nBlocksDefault, outputStream, RecoStep::TPCCompression));
112 getKernelTimer<GPUTPCCompressionGatherKernels, GPUTPCCompressionGatherKernels::buffered128>(RecoStep::TPCCompression, 0, outputSize, false);
113 break;
114 case 4:
115 static_assert((nBlocksMulti & 1) && nBlocksMulti >= 3);
116 runKernel<GPUTPCCompressionGatherKernels, GPUTPCCompressionGatherKernels::multiBlock>(GetGridBlkStep(nBlocksMulti, outputStream, RecoStep::TPCCompression));
117 getKernelTimer<GPUTPCCompressionGatherKernels, GPUTPCCompressionGatherKernels::multiBlock>(RecoStep::TPCCompression, 0, outputSize, false);
118 break;
119 default:
120 GPUError("Invalid compression kernel %d selected.", (int32_t)GetProcessingSettings().tpcCompressionGatherModeKernel);
121 return 1;
122 }
123 if (GetProcessingSettings().tpcCompressionGatherMode == 3) {
124 RecordMarker(&mEvents->stream[outputStream], outputStream);
125 char* deviceFlatPts = (char*)Compressor.mOutput->qTotU;
126 if (GetProcessingSettings().doublePipeline) {
127 const size_t blockSize = CAMath::nextMultipleOf<1024>(copySize / 30);
128 const uint32_t n = (copySize + blockSize - 1) / blockSize;
129 for (uint32_t i = 0; i < n; i++) {
130 GPUMemCpy(myStep, hostFlatPtr + i * blockSize, deviceFlatPts + i * blockSize, CAMath::Min(blockSize, copySize - i * blockSize), outputStream, false);
131 }
132 } else {
133 GPUMemCpy(myStep, hostFlatPtr, deviceFlatPts, copySize, outputStream, false);
134 }
135 }
136 } else {
137 int8_t direction = 0;
138 if (GetProcessingSettings().tpcCompressionGatherMode == 0) {
139 P = &CompressorShadow.mPtrs;
140 } else if (GetProcessingSettings().tpcCompressionGatherMode == 1) {
141 P = &Compressor.mPtrs;
142 direction = -1;
143 gatherTimer = &getTimer<GPUTPCCompressionKernels>("GPUTPCCompression_GatherOnCPU", 0);
144 gatherTimer->Start();
145 }
146 GPUMemCpyAlways(myStep, O->nSliceRowClusters, P->nSliceRowClusters, NSECTORS * GPUCA_ROW_COUNT * sizeof(O->nSliceRowClusters[0]), outputStream, direction);
147 GPUMemCpyAlways(myStep, O->nTrackClusters, P->nTrackClusters, O->nTracks * sizeof(O->nTrackClusters[0]), outputStream, direction);
148 SynchronizeStream(outputStream);
149 uint32_t offset = 0;
150 for (uint32_t i = 0; i < NSECTORS; i++) {
151 for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) {
152 uint32_t srcOffset = mIOPtrs.clustersNative->clusterOffset[i][j] * Compressor.mMaxClusterFactorBase1024 / 1024;
153 GPUMemCpyAlways(myStep, O->qTotU + offset, P->qTotU + srcOffset, O->nSliceRowClusters[i * GPUCA_ROW_COUNT + j] * sizeof(O->qTotU[0]), outputStream, direction);
154 GPUMemCpyAlways(myStep, O->qMaxU + offset, P->qMaxU + srcOffset, O->nSliceRowClusters[i * GPUCA_ROW_COUNT + j] * sizeof(O->qMaxU[0]), outputStream, direction);
155 GPUMemCpyAlways(myStep, O->flagsU + offset, P->flagsU + srcOffset, O->nSliceRowClusters[i * GPUCA_ROW_COUNT + j] * sizeof(O->flagsU[0]), outputStream, direction);
156 GPUMemCpyAlways(myStep, O->padDiffU + offset, P->padDiffU + srcOffset, O->nSliceRowClusters[i * GPUCA_ROW_COUNT + j] * sizeof(O->padDiffU[0]), outputStream, direction);
157 GPUMemCpyAlways(myStep, O->timeDiffU + offset, P->timeDiffU + srcOffset, O->nSliceRowClusters[i * GPUCA_ROW_COUNT + j] * sizeof(O->timeDiffU[0]), outputStream, direction);
158 GPUMemCpyAlways(myStep, O->sigmaPadU + offset, P->sigmaPadU + srcOffset, O->nSliceRowClusters[i * GPUCA_ROW_COUNT + j] * sizeof(O->sigmaPadU[0]), outputStream, direction);
159 GPUMemCpyAlways(myStep, O->sigmaTimeU + offset, P->sigmaTimeU + srcOffset, O->nSliceRowClusters[i * GPUCA_ROW_COUNT + j] * sizeof(O->sigmaTimeU[0]), outputStream, direction);
161 }
162 }
163 offset = 0;
164 for (uint32_t i = 0; i < O->nTracks; i++) {
165 GPUMemCpyAlways(myStep, O->qTotA + offset, P->qTotA + Compressor.mAttachedClusterFirstIndex[i], O->nTrackClusters[i] * sizeof(O->qTotA[0]), outputStream, direction);
166 GPUMemCpyAlways(myStep, O->qMaxA + offset, P->qMaxA + Compressor.mAttachedClusterFirstIndex[i], O->nTrackClusters[i] * sizeof(O->qMaxA[0]), outputStream, direction);
167 GPUMemCpyAlways(myStep, O->flagsA + offset, P->flagsA + Compressor.mAttachedClusterFirstIndex[i], O->nTrackClusters[i] * sizeof(O->flagsA[0]), outputStream, direction);
168 GPUMemCpyAlways(myStep, O->sigmaPadA + offset, P->sigmaPadA + Compressor.mAttachedClusterFirstIndex[i], O->nTrackClusters[i] * sizeof(O->sigmaPadA[0]), outputStream, direction);
169 GPUMemCpyAlways(myStep, O->sigmaTimeA + offset, P->sigmaTimeA + Compressor.mAttachedClusterFirstIndex[i], O->nTrackClusters[i] * sizeof(O->sigmaTimeA[0]), outputStream, direction);
170
171 // First index stored with track
172 GPUMemCpyAlways(myStep, O->rowDiffA + offset - i, P->rowDiffA + Compressor.mAttachedClusterFirstIndex[i] + 1, (O->nTrackClusters[i] - 1) * sizeof(O->rowDiffA[0]), outputStream, direction);
173 GPUMemCpyAlways(myStep, O->sliceLegDiffA + offset - i, P->sliceLegDiffA + Compressor.mAttachedClusterFirstIndex[i] + 1, (O->nTrackClusters[i] - 1) * sizeof(O->sliceLegDiffA[0]), outputStream, direction);
174 GPUMemCpyAlways(myStep, O->padResA + offset - i, P->padResA + Compressor.mAttachedClusterFirstIndex[i] + 1, (O->nTrackClusters[i] - 1) * sizeof(O->padResA[0]), outputStream, direction);
175 GPUMemCpyAlways(myStep, O->timeResA + offset - i, P->timeResA + Compressor.mAttachedClusterFirstIndex[i] + 1, (O->nTrackClusters[i] - 1) * sizeof(O->timeResA[0]), outputStream, direction);
176 offset += O->nTrackClusters[i];
177 }
178 GPUMemCpyAlways(myStep, O->qPtA, P->qPtA, O->nTracks * sizeof(O->qPtA[0]), outputStream, direction);
179 GPUMemCpyAlways(myStep, O->rowA, P->rowA, O->nTracks * sizeof(O->rowA[0]), outputStream, direction);
180 GPUMemCpyAlways(myStep, O->sliceA, P->sliceA, O->nTracks * sizeof(O->sliceA[0]), outputStream, direction);
181 GPUMemCpyAlways(myStep, O->timeA, P->timeA, O->nTracks * sizeof(O->timeA[0]), outputStream, direction);
182 GPUMemCpyAlways(myStep, O->padA, P->padA, O->nTracks * sizeof(O->padA[0]), outputStream, direction);
183 }
184 if (GetProcessingSettings().tpcCompressionGatherMode == 1) {
185 gatherTimer->Stop();
186 }
188 if (GetProcessingSettings().tpcCompressionGatherMode == 3) {
191 }
192
193 if (mPipelineFinalizationCtx == nullptr) {
194 SynchronizeStream(outputStream);
195 } else {
197 }
198 mRec->PopNonPersistentMemory(RecoStep::TPCCompression, qStr2Tag("TPCCOMPR"));
199 return 0;
200}
201
203{
204 if (GetProcessingSettings().tpcUseOldCPUDecoding) {
205 const auto& threadContext = GetThreadContext();
207 auto allocatorFinal = [this](size_t size) {
208 this->mInputsHost->mNClusterNative = this->mInputsShadow->mNClusterNative = size;
209 this->AllocateRegisteredMemory(this->mInputsHost->mResourceClusterNativeOutput, this->mSubOutputControls[GPUTrackingOutputs::getIndex(&GPUTrackingOutputs::clustersNative)]);
210 return this->mInputsHost->mPclusterNativeOutput;
211 };
212 std::unique_ptr<ClusterNative[]> tmpBuffer;
213 auto allocatorTmp = [&tmpBuffer](size_t size) {
214 return ((tmpBuffer = std::make_unique<ClusterNative[]>(size))).get();
215 };
216 auto& decompressTimer = getTimer<TPCClusterDecompressor>("TPCDecompression", 0);
217 bool runFiltering = GetProcessingSettings().tpcApplyCFCutsAtDecoding;
218 auto allocatorUse = runFiltering ? std::function<ClusterNative*(size_t)>{allocatorTmp} : std::function<ClusterNative*(size_t)>{allocatorFinal};
219 decompressTimer.Start();
220 if (decomp.decompress(mIOPtrs.tpcCompressedClusters, *mClusterNativeAccess, allocatorUse, param(), GetProcessingSettings().deterministicGPUReconstruction)) {
221 GPUError("Error decompressing clusters");
222 return 1;
223 }
224 if (runFiltering) {
225 RunTPCClusterFilter(mClusterNativeAccess.get(), allocatorFinal, GetProcessingSettings().tpcApplyCFCutsAtDecoding);
226 }
227 decompressTimer.Stop();
229 if (mRec->IsGPU()) {
230 AllocateRegisteredMemory(mInputsHost->mResourceClusterNativeBuffer);
231 processorsShadow()->ioPtrs.clustersNative = mInputsShadow->mPclusterNativeAccess;
232 WriteToConstantMemory(RecoStep::TPCDecompression, (char*)&processors()->ioPtrs - (char*)processors(), &processorsShadow()->ioPtrs, sizeof(processorsShadow()->ioPtrs), 0);
233 *mInputsHost->mPclusterNativeAccess = *mIOPtrs.clustersNative;
234 mInputsHost->mPclusterNativeAccess->clustersLinear = mInputsShadow->mPclusterNativeBuffer;
235 mInputsHost->mPclusterNativeAccess->setOffsetPtrs();
236 GPUMemCpy(RecoStep::TPCDecompression, mInputsShadow->mPclusterNativeBuffer, mIOPtrs.clustersNative->clustersLinear, sizeof(mIOPtrs.clustersNative->clustersLinear[0]) * mIOPtrs.clustersNative->nClustersTotal, 0, true);
237 TransferMemoryResourceLinkToGPU(RecoStep::TPCDecompression, mInputsHost->mResourceClusterNativeAccess, 0);
239 }
240 } else {
242 RecoStep myStep = RecoStep::TPCDecompression;
243 bool doGPU = GetRecoStepsGPU() & RecoStep::TPCDecompression;
244 bool runFiltering = param().tpcCutTimeBin > 0;
246 GPUTPCDecompression& DecompressorShadow = doGPU ? processorsShadow()->tpcDecompressor : Decompressor;
247 const auto& threadContext = GetThreadContext();
249 CompressedClusters& inputGPU = Decompressor.mInputGPU;
250 CompressedClusters& inputGPUShadow = DecompressorShadow.mInputGPU;
251
252 if (cmprClsHost.nTracks && cmprClsHost.solenoidBz != -1e6f && cmprClsHost.solenoidBz != param().bzkG) {
253 throw std::runtime_error("Configured solenoid Bz does not match value used for track model encoding");
254 }
255 if (cmprClsHost.nTracks && cmprClsHost.maxTimeBin != -1e6 && cmprClsHost.maxTimeBin != param().continuousMaxTimeBin) {
256 throw std::runtime_error("Configured max time bin does not match value used for track model encoding");
257 }
258
259 int32_t inputStream = 0;
260 int32_t unattachedStream = mRec->NStreams() - 1;
261 inputGPU = cmprClsHost;
262 SetupGPUProcessor(&Decompressor, true);
263 WriteToConstantMemory(myStep, (char*)&processors()->tpcDecompressor - (char*)processors(), &DecompressorShadow, sizeof(DecompressorShadow), inputStream);
264 inputGPU = cmprClsHost;
265
266 bool toGPU = true;
267 runKernel<GPUMemClean16>({GetGridAutoStep(inputStream, RecoStep::TPCDecompression), krnlRunRangeNone, &mEvents->init}, DecompressorShadow.mNativeClustersIndex, NSECTORS * GPUCA_ROW_COUNT * sizeof(DecompressorShadow.mNativeClustersIndex[0]));
268 int32_t nStreams = doGPU ? mRec->NStreams() - 1 : 1;
269 if (cmprClsHost.nAttachedClusters != 0) {
270 std::exclusive_scan(cmprClsHost.nTrackClusters, cmprClsHost.nTrackClusters + cmprClsHost.nTracks, Decompressor.mAttachedClustersOffsets, 0u); // computing clusters offsets for first kernel
271 for (int32_t iStream = 0; iStream < nStreams; iStream++) {
272 uint32_t startTrack = cmprClsHost.nTracks / nStreams * iStream;
273 uint32_t endTrack = cmprClsHost.nTracks / nStreams * (iStream + 1) + (iStream < nStreams - 1 ? 0 : cmprClsHost.nTracks % nStreams); // index of last track (excluded from computation)
274 uint32_t numTracks = endTrack - startTrack;
275 uint32_t* offsets = Decompressor.mAttachedClustersOffsets;
276 uint32_t numClusters = (endTrack == cmprClsHost.nTracks ? offsets[endTrack - 1] + cmprClsHost.nTrackClusters[endTrack - 1] : offsets[endTrack]) - offsets[startTrack];
277 uint32_t numClustersRed = numClusters - numTracks;
278 GPUMemCpy(myStep, DecompressorShadow.mAttachedClustersOffsets + startTrack, Decompressor.mAttachedClustersOffsets + startTrack, numTracks * sizeof(Decompressor.mAttachedClustersOffsets[0]), iStream, toGPU);
279 GPUMemCpy(myStep, inputGPUShadow.nTrackClusters + startTrack, cmprClsHost.nTrackClusters + startTrack, numTracks * sizeof(cmprClsHost.nTrackClusters[0]), iStream, toGPU);
280 GPUMemCpy(myStep, inputGPUShadow.qTotA + offsets[startTrack], cmprClsHost.qTotA + offsets[startTrack], numClusters * sizeof(cmprClsHost.qTotA[0]), iStream, toGPU);
281 GPUMemCpy(myStep, inputGPUShadow.qMaxA + offsets[startTrack], cmprClsHost.qMaxA + offsets[startTrack], numClusters * sizeof(cmprClsHost.qMaxA[0]), iStream, toGPU);
282 GPUMemCpy(myStep, inputGPUShadow.flagsA + offsets[startTrack], cmprClsHost.flagsA + offsets[startTrack], numClusters * sizeof(cmprClsHost.flagsA[0]), iStream, toGPU);
283 GPUMemCpy(myStep, inputGPUShadow.rowDiffA + offsets[startTrack] - startTrack, cmprClsHost.rowDiffA + offsets[startTrack] - startTrack, numClustersRed * sizeof(cmprClsHost.rowDiffA[0]), iStream, toGPU);
284 GPUMemCpy(myStep, inputGPUShadow.sliceLegDiffA + offsets[startTrack] - startTrack, cmprClsHost.sliceLegDiffA + offsets[startTrack] - startTrack, numClustersRed * sizeof(cmprClsHost.sliceLegDiffA[0]), iStream, toGPU);
285 GPUMemCpy(myStep, inputGPUShadow.padResA + offsets[startTrack] - startTrack, cmprClsHost.padResA + offsets[startTrack] - startTrack, numClustersRed * sizeof(cmprClsHost.padResA[0]), iStream, toGPU);
286 GPUMemCpy(myStep, inputGPUShadow.timeResA + offsets[startTrack] - startTrack, cmprClsHost.timeResA + offsets[startTrack] - startTrack, numClustersRed * sizeof(cmprClsHost.timeResA[0]), iStream, toGPU);
287 GPUMemCpy(myStep, inputGPUShadow.sigmaPadA + offsets[startTrack], cmprClsHost.sigmaPadA + offsets[startTrack], numClusters * sizeof(cmprClsHost.sigmaPadA[0]), iStream, toGPU);
288 GPUMemCpy(myStep, inputGPUShadow.sigmaTimeA + offsets[startTrack], cmprClsHost.sigmaTimeA + offsets[startTrack], numClusters * sizeof(cmprClsHost.sigmaTimeA[0]), iStream, toGPU);
289 GPUMemCpy(myStep, inputGPUShadow.qPtA + startTrack, cmprClsHost.qPtA + startTrack, numTracks * sizeof(cmprClsHost.qPtA[0]), iStream, toGPU);
290 GPUMemCpy(myStep, inputGPUShadow.rowA + startTrack, cmprClsHost.rowA + startTrack, numTracks * sizeof(cmprClsHost.rowA[0]), iStream, toGPU);
291 GPUMemCpy(myStep, inputGPUShadow.sliceA + startTrack, cmprClsHost.sliceA + startTrack, numTracks * sizeof(cmprClsHost.sliceA[0]), iStream, toGPU);
292 GPUMemCpy(myStep, inputGPUShadow.timeA + startTrack, cmprClsHost.timeA + startTrack, numTracks * sizeof(cmprClsHost.timeA[0]), iStream, toGPU);
293 GPUMemCpy(myStep, inputGPUShadow.padA + startTrack, cmprClsHost.padA + startTrack, numTracks * sizeof(cmprClsHost.padA[0]), iStream, toGPU);
294 runKernel<GPUTPCDecompressionKernels, GPUTPCDecompressionKernels::step0attached>({GetGridAuto(iStream), krnlRunRangeNone, {&mEvents->stream[iStream], &mEvents->init}}, startTrack, endTrack);
295 }
296 }
297 GPUMemCpy(myStep, inputGPUShadow.nSliceRowClusters, cmprClsHost.nSliceRowClusters, NSECTORS * GPUCA_ROW_COUNT * sizeof(cmprClsHost.nSliceRowClusters[0]), unattachedStream, toGPU);
298 GPUMemCpy(myStep, inputGPUShadow.qTotU, cmprClsHost.qTotU, cmprClsHost.nUnattachedClusters * sizeof(cmprClsHost.qTotU[0]), unattachedStream, toGPU);
299 GPUMemCpy(myStep, inputGPUShadow.qMaxU, cmprClsHost.qMaxU, cmprClsHost.nUnattachedClusters * sizeof(cmprClsHost.qMaxU[0]), unattachedStream, toGPU);
300 GPUMemCpy(myStep, inputGPUShadow.flagsU, cmprClsHost.flagsU, cmprClsHost.nUnattachedClusters * sizeof(cmprClsHost.flagsU[0]), unattachedStream, toGPU);
301 GPUMemCpy(myStep, inputGPUShadow.padDiffU, cmprClsHost.padDiffU, cmprClsHost.nUnattachedClusters * sizeof(cmprClsHost.padDiffU[0]), unattachedStream, toGPU);
302 GPUMemCpy(myStep, inputGPUShadow.timeDiffU, cmprClsHost.timeDiffU, cmprClsHost.nUnattachedClusters * sizeof(cmprClsHost.timeDiffU[0]), unattachedStream, toGPU);
303 GPUMemCpy(myStep, inputGPUShadow.sigmaPadU, cmprClsHost.sigmaPadU, cmprClsHost.nUnattachedClusters * sizeof(cmprClsHost.sigmaPadU[0]), unattachedStream, toGPU);
304 GPUMemCpy(myStep, inputGPUShadow.sigmaTimeU, cmprClsHost.sigmaTimeU, cmprClsHost.nUnattachedClusters * sizeof(cmprClsHost.sigmaTimeU[0]), unattachedStream, toGPU);
305
306 TransferMemoryResourceLinkToHost(RecoStep::TPCDecompression, Decompressor.mResourceTmpIndexes, inputStream, nullptr, mEvents->stream, nStreams);
307 SynchronizeStream(inputStream);
308 uint32_t offset = 0;
309 uint32_t decodedAttachedClusters = 0;
310 for (uint32_t i = 0; i < NSECTORS; i++) {
311 for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) {
312 uint32_t linearIndex = i * GPUCA_ROW_COUNT + j;
313 uint32_t unattachedOffset = (linearIndex >= cmprClsHost.nSliceRows) ? 0 : cmprClsHost.nSliceRowClusters[linearIndex];
314 (mClusterNativeAccess->nClusters)[i][j] = Decompressor.mNativeClustersIndex[linearIndex] + unattachedOffset;
315 Decompressor.mUnattachedClustersOffsets[linearIndex] = offset;
316 offset += unattachedOffset;
317 decodedAttachedClusters += Decompressor.mNativeClustersIndex[linearIndex];
318 }
319 }
320 TransferMemoryResourceLinkToGPU(RecoStep::TPCDecompression, Decompressor.mResourceTmpClustersOffsets, inputStream);
321 if (decodedAttachedClusters != cmprClsHost.nAttachedClusters) {
322 GPUWarning("%u / %u clusters failed track model decoding (%f %%)", cmprClsHost.nAttachedClusters - decodedAttachedClusters, cmprClsHost.nAttachedClusters, 100.f * (float)(cmprClsHost.nAttachedClusters - decodedAttachedClusters) / (float)cmprClsHost.nAttachedClusters);
323 }
324 if (runFiltering) { // If filtering, allocate a temporary buffer and cluster native access in decompressor context
325 Decompressor.mNClusterNativeBeforeFiltering = DecompressorShadow.mNClusterNativeBeforeFiltering = decodedAttachedClusters + cmprClsHost.nUnattachedClusters;
328 mClusterNativeAccess->clustersLinear = DecompressorShadow.mNativeClustersBuffer;
329 mClusterNativeAccess->setOffsetPtrs();
331 WriteToConstantMemory(myStep, (char*)&processors()->tpcDecompressor - (char*)processors(), &DecompressorShadow, sizeof(DecompressorShadow), inputStream);
332 TransferMemoryResourceLinkToGPU(RecoStep::TPCDecompression, Decompressor.mResourceClusterNativeAccess, inputStream, &mEvents->single);
333 } else { // If not filtering, directly allocate the final buffers
334 mInputsHost->mNClusterNative = mInputsShadow->mNClusterNative = cmprClsHost.nAttachedClusters + cmprClsHost.nUnattachedClusters;
336 AllocateRegisteredMemory(mInputsHost->mResourceClusterNativeBuffer);
337 DecompressorShadow.mNativeClustersBuffer = mInputsShadow->mPclusterNativeBuffer;
338 Decompressor.mNativeClustersBuffer = mInputsHost->mPclusterNativeOutput;
339 DecompressorShadow.mClusterNativeAccess = mInputsShadow->mPclusterNativeAccess;
340 Decompressor.mClusterNativeAccess = mInputsHost->mPclusterNativeAccess;
341 WriteToConstantMemory(myStep, (char*)&processors()->tpcDecompressor - (char*)processors(), &DecompressorShadow, sizeof(DecompressorShadow), inputStream);
342 if (doGPU) {
343 mClusterNativeAccess->clustersLinear = mInputsShadow->mPclusterNativeBuffer;
344 mClusterNativeAccess->setOffsetPtrs();
345 *mInputsHost->mPclusterNativeAccess = *mClusterNativeAccess;
346 processorsShadow()->ioPtrs.clustersNative = mInputsShadow->mPclusterNativeAccess;
347 WriteToConstantMemory(RecoStep::TPCDecompression, (char*)&processors()->ioPtrs - (char*)processors(), &processorsShadow()->ioPtrs, sizeof(processorsShadow()->ioPtrs), inputStream);
348 TransferMemoryResourceLinkToGPU(RecoStep::TPCDecompression, mInputsHost->mResourceClusterNativeAccess, inputStream, &mEvents->single);
349 }
351 mClusterNativeAccess->clustersLinear = mInputsHost->mPclusterNativeOutput;
352 mClusterNativeAccess->setOffsetPtrs();
353 *mInputsHost->mPclusterNativeAccess = *mClusterNativeAccess;
354 }
355
356 uint32_t batchSize = doGPU ? 6 : NSECTORS;
357 for (uint32_t iSector = 0; iSector < NSECTORS; iSector = iSector + batchSize) {
358 int32_t iStream = (iSector / batchSize) % mRec->NStreams();
359 runKernel<GPUTPCDecompressionKernels, GPUTPCDecompressionKernels::step1unattached>({GetGridAuto(iStream), krnlRunRangeNone, {nullptr, &mEvents->single}}, iSector, batchSize);
360 uint32_t copySize = std::accumulate(mClusterNativeAccess->nClustersSector + iSector, mClusterNativeAccess->nClustersSector + iSector + batchSize, 0u);
361 if (!runFiltering) {
362 GPUMemCpy(RecoStep::TPCDecompression, mInputsHost->mPclusterNativeOutput + mClusterNativeAccess->clusterOffset[iSector][0], DecompressorShadow.mNativeClustersBuffer + mClusterNativeAccess->clusterOffset[iSector][0], sizeof(Decompressor.mNativeClustersBuffer[0]) * copySize, iStream, false);
363 }
364 }
366
367 if (runFiltering) { // If filtering is applied, count how many clusters will remain after filtering and allocate final buffers accordingly
369 WriteToConstantMemory(myStep, (char*)&processors()->tpcDecompressor - (char*)processors(), &DecompressorShadow, sizeof(DecompressorShadow), unattachedStream);
370 runKernel<GPUMemClean16>({GetGridAutoStep(unattachedStream, RecoStep::TPCDecompression), krnlRunRangeNone}, DecompressorShadow.mNClusterPerSectorRow, NSECTORS * GPUCA_ROW_COUNT * sizeof(DecompressorShadow.mNClusterPerSectorRow[0]));
371 runKernel<GPUTPCDecompressionUtilKernels, GPUTPCDecompressionUtilKernels::countFilteredClusters>(GetGridAutoStep(unattachedStream, RecoStep::TPCDecompression));
372 TransferMemoryResourceLinkToHost(RecoStep::TPCDecompression, Decompressor.mResourceNClusterPerSectorRow, unattachedStream);
373 SynchronizeStream(unattachedStream);
374 uint32_t nClustersFinal = std::accumulate(Decompressor.mNClusterPerSectorRow, Decompressor.mNClusterPerSectorRow + inputGPU.nSliceRows, 0u);
375 mInputsHost->mNClusterNative = mInputsShadow->mNClusterNative = nClustersFinal;
377 AllocateRegisteredMemory(mInputsHost->mResourceClusterNativeBuffer);
378 DecompressorShadow.mNativeClustersBuffer = mInputsShadow->mPclusterNativeBuffer;
379 Decompressor.mNativeClustersBuffer = mInputsHost->mPclusterNativeOutput;
380 WriteToConstantMemory(myStep, (char*)&processors()->tpcDecompressor - (char*)processors(), &DecompressorShadow, sizeof(DecompressorShadow), unattachedStream);
381 for (uint32_t i = 0; i < NSECTORS; i++) {
382 for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) {
383 mClusterNativeAccess->nClusters[i][j] = Decompressor.mNClusterPerSectorRow[i * GPUCA_ROW_COUNT + j];
384 }
385 }
386 if (doGPU) {
387 mClusterNativeAccess->clustersLinear = mInputsShadow->mPclusterNativeBuffer;
388 mClusterNativeAccess->setOffsetPtrs();
389 *mInputsHost->mPclusterNativeAccess = *mClusterNativeAccess;
390 processorsShadow()->ioPtrs.clustersNative = mInputsShadow->mPclusterNativeAccess;
391 WriteToConstantMemory(RecoStep::TPCDecompression, (char*)&processors()->ioPtrs - (char*)processors(), &processorsShadow()->ioPtrs, sizeof(processorsShadow()->ioPtrs), unattachedStream);
392 TransferMemoryResourceLinkToGPU(RecoStep::TPCDecompression, mInputsHost->mResourceClusterNativeAccess, unattachedStream);
393 }
395 mClusterNativeAccess->clustersLinear = mInputsHost->mPclusterNativeOutput;
396 mClusterNativeAccess->setOffsetPtrs();
397 runKernel<GPUTPCDecompressionUtilKernels, GPUTPCDecompressionUtilKernels::storeFilteredClusters>(GetGridAutoStep(unattachedStream, RecoStep::TPCDecompression));
398 GPUMemCpy(RecoStep::TPCDecompression, mInputsHost->mPclusterNativeOutput, DecompressorShadow.mNativeClustersBuffer, sizeof(Decompressor.mNativeClustersBuffer[0]) * nClustersFinal, unattachedStream, false);
399 SynchronizeStream(unattachedStream);
400 }
401 if (GetProcessingSettings().deterministicGPUReconstruction || GetProcessingSettings().debugLevel >= 4) {
402 runKernel<GPUTPCDecompressionUtilKernels, GPUTPCDecompressionUtilKernels::sortPerSectorRow>(GetGridAutoStep(unattachedStream, RecoStep::TPCDecompression));
404 if (doGPU) {
405 for (uint32_t i = 0; i < NSECTORS; i++) {
406 for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) {
407 ClusterNative* begin = mInputsHost->mPclusterNativeOutput + decoded->clusterOffset[i][j];
408 ClusterNative* end = begin + decoded->nClusters[i][j];
409 std::sort(begin, end);
410 }
411 }
412 }
413 SynchronizeStream(unattachedStream);
414 }
415 mRec->PopNonPersistentMemory(RecoStep::TPCDecompression, qStr2Tag("TPCDCMPR"));
416 }
417 return 0;
418}
int32_t i
#define GPUCA_ROW_COUNT
uint32_t j
Definition RawData.h:0
void Start()
Definition timer.cxx:57
void Stop()
Definition timer.cxx:69
std::unique_ptr< o2::tpc::ClusterNativeAccess > mClusterNativeAccess
std::unique_ptr< GPUTrackingInputProvider > mInputsHost
std::array< GPUOutputControl *, GPUTrackingOutputs::count()> mSubOutputControls
std::unique_ptr< GPUTPCCFChainContext > mCFContext
GPUTrackingInOutPointers & mIOPtrs
std::unique_ptr< GPUTrackingInputProvider > mInputsShadow
void RecordMarker(deviceEvent *ev, int32_t stream)
Definition GPUChain.h:103
void TransferMemoryResourceLinkToGPU(RecoStep step, int16_t res, int32_t stream=-1, deviceEvent *ev=nullptr, deviceEvent *evList=nullptr, int32_t nEvents=1)
Definition GPUChain.h:119
void GPUMemCpyAlways(RecoStep step, void *dst, const void *src, size_t size, int32_t stream, int32_t toGPU, deviceEvent *ev=nullptr, deviceEvent *evList=nullptr, int32_t nEvents=1)
Definition GPUChain.h:124
void GPUMemCpy(RecoStep step, void *dst, const void *src, size_t size, int32_t stream, int32_t toGPU, deviceEvent *ev=nullptr, deviceEvent *evList=nullptr, int32_t nEvents=1)
Definition GPUChain.h:123
GPUReconstruction::RecoStep RecoStep
Definition GPUChain.h:29
void SynchronizeGPU()
Definition GPUChain.h:105
krnlExec GetGridAuto(int32_t stream, GPUReconstruction::krnlDeviceType d=GPUReconstruction::krnlDeviceType::Auto, GPUCA_RECO_STEP st=GPUCA_RECO_STEP::NoRecoStep)
Definition GPUChain.cxx:42
GPUReconstruction::RecoStepField GetRecoStepsGPU() const
Definition GPUChain.h:68
virtual std::unique_ptr< gpu_reconstruction_kernels::threadContext > GetThreadContext()
Definition GPUChain.h:104
void WriteToConstantMemory(RecoStep step, size_t offset, const void *src, size_t size, int32_t stream=-1, deviceEvent *ev=nullptr)
Definition GPUChain.h:122
GPUChain * GetNextChainInQueue()
Definition GPUChain.h:217
size_t AllocateRegisteredMemory(GPUProcessor *proc)
Definition GPUChain.h:209
GPUConstantMem * processors()
Definition GPUChain.h:80
static constexpr krnlRunRange krnlRunRangeNone
Definition GPUChain.h:37
krnlExec GetGridAutoStep(int32_t stream, GPUCA_RECO_STEP st=GPUCA_RECO_STEP::NoRecoStep)
Definition GPUChain.cxx:47
GPUParam & param()
Definition GPUChain.h:83
void SetupGPUProcessor(T *proc, bool allocate)
Definition GPUChain.h:212
const GPUSettingsProcessing & GetProcessingSettings() const
Definition GPUChain.h:72
void SynchronizeStream(int32_t stream)
Definition GPUChain.h:85
GPUReconstructionCPU * mRec
Definition GPUChain.h:75
GPUConstantMem * processorsShadow()
Definition GPUChain.h:81
static constexpr int32_t NSECTORS
Definition GPUChain.h:54
void TransferMemoryResourceLinkToHost(RecoStep step, int16_t res, int32_t stream=-1, deviceEvent *ev=nullptr, deviceEvent *evList=nullptr, int32_t nEvents=1)
Definition GPUChain.h:120
void TransferMemoryResourcesToHost(RecoStep step, GPUProcessor *proc, int32_t stream=-1, bool all=false)
Definition GPUChain.h:118
krnlExec GetGridBlkStep(uint32_t nBlocks, int32_t stream, GPUCA_RECO_STEP st=GPUCA_RECO_STEP::NoRecoStep)
Definition GPUChain.cxx:37
void SynchronizeEventAndRelease(deviceEvent &ev, bool doGPU=true)
Definition GPUChain.h:87
void TransferMemoryResourcesToGPU(RecoStep step, GPUProcessor *proc, int32_t stream=-1, bool all=false)
Definition GPUChain.h:117
virtual void * getGPUPointer(void *ptr)
void PopNonPersistentMemory(RecoStep step, uint64_t tag)
void * AllocateVolatileDeviceMemory(size_t size)
void PushNonPersistentMemory(uint64_t tag)
void BlockStackedMemory(GPUReconstruction *rec)
o2::tpc::CompressedClusters * mOutput
o2::tpc::CompressedClusters * mOutputA
o2::tpc::CompressedClustersPtrs mPtrs
o2::tpc::CompressedClustersFlat * mOutputFlat
o2::tpc::CompressedClusters mInputGPU
o2::tpc::ClusterNative * mNativeClustersBuffer
o2::tpc::ClusterNativeAccess * mClusterNativeAccess
static int32_t decompress(const o2::tpc::CompressedClustersFlat *clustersCompressed, o2::tpc::ClusterNativeAccess &clustersNative, std::function< o2::tpc::ClusterNative *(size_t)> allocator, const GPUParam &param, bool deterministicRec)
GLdouble n
Definition glcorearb.h:1982
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLsizei const GLuint const GLintptr * offsets
Definition glcorearb.h:2595
GLuint GLuint end
Definition glcorearb.h:469
GLintptr offset
Definition glcorearb.h:660
GLenum GLfloat param
Definition glcorearb.h:271
Global TPC definitions and constants.
Definition SimTraits.h:167
Enum< T >::Iterator begin(Enum< T >)
Definition Defs.h:173
constexpr T qStr2Tag(const char *str)
Definition strtag.h:22
deviceEvent stream[GPUCA_MAX_STREAMS]
GPUTPCDecompression tpcDecompressor
GPUTrackingInOutPointers ioPtrs
GPUTPCCompression tpcCompressor
const o2::tpc::ClusterNativeAccess * clustersNative
const o2::tpc::CompressedClustersFlat * tpcCompressedClusters
size_t getIndex(const GPUOutputControl &v)
GPUOutputControl compressedClusters
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int clusterOffset[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
const ClusterNative * clustersLinear
void set(size_t bufferSize, const CompressedClusters &v)