Project
Loading...
Searching...
No Matches
TPCClusterDecompressor.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
16#include "GPUO2DataTypes.h"
17#include "GPUParam.h"
19#include "GPULogging.h"
20#include <algorithm>
21#include <cstring>
22#include <atomic>
23#include "TPCClusterDecompressionCore.inc"
24
25#include <oneapi/tbb.h>
26
27using namespace o2::gpu;
28using namespace o2::tpc;
29
30int32_t TPCClusterDecompressor::decompress(const CompressedClustersFlat* clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, std::function<o2::tpc::ClusterNative*(size_t)> allocator, const GPUParam& param, bool deterministicRec)
31{
33 const CompressedClusters* p;
34 if (clustersCompressed->ptrForward) {
35 p = clustersCompressed->ptrForward;
36 } else {
37 c = *clustersCompressed;
38 p = &c;
39 }
40 return decompress(p, clustersNative, allocator, param, deterministicRec);
41}
42
43int32_t TPCClusterDecompressor::decompress(const CompressedClusters* clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, std::function<o2::tpc::ClusterNative*(size_t)> allocator, const GPUParam& param, bool deterministicRec)
44{
45 if (clustersCompressed->nTracks && clustersCompressed->solenoidBz != -1e6f && clustersCompressed->solenoidBz != param.bzkG) {
46 throw std::runtime_error("Configured solenoid Bz does not match value used for track model encoding");
47 }
48 if (clustersCompressed->nTracks && clustersCompressed->maxTimeBin != -1e6 && clustersCompressed->maxTimeBin != param.continuousMaxTimeBin) {
49 throw std::runtime_error("Configured max time bin does not match value used for track model encoding");
50 }
51 std::vector<ClusterNative> clusters[NSECTORS][GPUCA_ROW_COUNT];
52 std::atomic_flag locks[NSECTORS][GPUCA_ROW_COUNT];
53 for (uint32_t i = 0; i < NSECTORS * GPUCA_ROW_COUNT; i++) {
54 (&locks[0][0])[i].clear();
55 }
56 const uint32_t maxTime = param.continuousMaxTimeBin > 0 ? ((param.continuousMaxTimeBin + 1) * ClusterNative::scaleTimePacked - 1) : TPC_MAX_TIME_BIN_TRIGGERED;
57 tbb::parallel_for(tbb::blocked_range<uint32_t>(0, clustersCompressed->nTracks), [&](const tbb::blocked_range<uint32_t>& range) {
58 uint32_t offset = 0, lasti = 0;
59 for (uint32_t i = range.begin(); i < range.end(); i++) {
60 if (i < lasti) {
61 offset = lasti = 0; // dynamic scheduling order, need to reinitialize offset
62 }
63 while (lasti < i) {
64 offset += clustersCompressed->nTrackClusters[lasti++];
65 }
66 lasti++;
67 TPCClusterDecompressionCore::decompressTrack(*clustersCompressed, param, maxTime, i, offset, clusters, locks);
68 }
69 });
70 size_t nTotalClusters = clustersCompressed->nAttachedClusters + clustersCompressed->nUnattachedClusters;
71 ClusterNative* clusterBuffer = allocator(nTotalClusters);
72 uint32_t offsets[NSECTORS][GPUCA_ROW_COUNT];
73 uint32_t offset = 0;
74 uint32_t decodedAttachedClusters = 0;
75 for (uint32_t i = 0; i < NSECTORS; i++) {
76 for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) {
77 clustersNative.nClusters[i][j] = clusters[i][j].size() + ((i * GPUCA_ROW_COUNT + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUCA_ROW_COUNT + j]);
78 offsets[i][j] = offset;
79 offset += (i * GPUCA_ROW_COUNT + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUCA_ROW_COUNT + j];
80 decodedAttachedClusters += clusters[i][j].size();
81 }
82 }
83 if (decodedAttachedClusters != clustersCompressed->nAttachedClusters) {
84 GPUWarning("%u / %u clusters failed track model decoding (%f %%)", clustersCompressed->nAttachedClusters - decodedAttachedClusters, clustersCompressed->nAttachedClusters, 100.f * (float)(clustersCompressed->nAttachedClusters - decodedAttachedClusters) / (float)clustersCompressed->nAttachedClusters);
85 }
86 clustersNative.clustersLinear = clusterBuffer;
87 clustersNative.setOffsetPtrs();
88 tbb::parallel_for<uint32_t>(0, NSECTORS, [&](auto i) {
89 for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) {
90 ClusterNative* buffer = &clusterBuffer[clustersNative.clusterOffset[i][j]];
91 if (clusters[i][j].size()) {
92 memcpy((void*)buffer, (const void*)clusters[i][j].data(), clusters[i][j].size() * sizeof(clusterBuffer[0]));
93 }
94 ClusterNative* clout = buffer + clusters[i][j].size();
95 uint32_t end = offsets[i][j] + ((i * GPUCA_ROW_COUNT + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUCA_ROW_COUNT + j]);
96 TPCClusterDecompressionCore::decompressHits(*clustersCompressed, offsets[i][j], end, clout);
97 if (param.rec.tpc.clustersShiftTimebins != 0.f) {
98 for (uint32_t k = 0; k < clustersNative.nClusters[i][j]; k++) {
99 auto& cl = buffer[k];
100 float t = cl.getTime() + param.rec.tpc.clustersShiftTimebins;
101 if (t < 0) {
102 t = 0;
103 }
104 if (param.continuousMaxTimeBin > 0 && t > param.continuousMaxTimeBin) {
105 t = param.continuousMaxTimeBin;
106 }
107 cl.setTime(t);
108 }
109 }
110 if (deterministicRec) {
111 std::sort(buffer, buffer + clustersNative.nClusters[i][j]);
112 }
113 } // clang-format off
114 }, tbb::simple_partitioner()); // clang-format on
115 return 0;
116}
int32_t i
#define TPC_MAX_TIME_BIN_TRIGGERED
#define GPUCA_ROW_COUNT
uint32_t j
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
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)
GLuint buffer
Definition glcorearb.h:655
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLsizei const GLuint const GLintptr * offsets
Definition glcorearb.h:2595
GLuint GLuint end
Definition glcorearb.h:469
GLenum GLint * range
Definition glcorearb.h:1899
GLboolean * data
Definition glcorearb.h:298
GLintptr offset
Definition glcorearb.h:660
GLenum GLfloat param
Definition glcorearb.h:271
Global TPC definitions and constants.
Definition SimTraits.h:167
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int clusterOffset[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
const ClusterNative * clustersLinear
static constexpr int scaleTimePacked
const CompressedClusters * ptrForward
std::vector< Cluster > clusters
vec clear()