Project
Loading...
Searching...
No Matches
GPUTPCGlobalDebugSortKernels.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 "GPUParam.h"
16#include "GPUProcessor.h"
17#include "GPUCommonMath.h"
18#include "GPUCommonAlgorithm.h"
20#ifndef GPUCA_GPUCODE_DEVICE
21#include <stdexcept>
22#endif
23
24using namespace o2::gpu;
25
26template <>
27GPUdii() void GPUTPCGlobalDebugSortKernels::Thread<GPUTPCGlobalDebugSortKernels::clearIds>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& GPUrestrict() merger, int8_t)
28{
29 for (int32_t i = iBlock * nThreads + iThread; i < GPUCA_NSECTORS * merger.NMaxSingleSectorTracks(); i++) {
30 merger.TrackIDs()[i] = -1;
31 }
32}
33
34template <>
35GPUdii() void GPUTPCGlobalDebugSortKernels::Thread<GPUTPCGlobalDebugSortKernels::sectorTracks>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& GPUrestrict() merger, int8_t parameter)
36{
37 if (iThread) {
38 return;
39 }
40 int32_t iStart = parameter ? GPUCA_NSECTORS : 0;
41 int32_t iEnd = iStart + GPUCA_NSECTORS;
42 for (int32_t i = iStart + iBlock; i < iEnd; i += nBlocks) {
43 const int32_t offset = merger.SectorTrackInfoFirst(i);
44 int32_t* GPUrestrict() tmp = merger.TmpSortMemory() + offset;
45 const int32_t n = merger.SectorTrackInfoLast(i) - merger.SectorTrackInfoFirst(i);
46 if (n < 2) {
47 continue;
48 }
49 for (int32_t j = 0; j < n; j++) {
50 tmp[j] = j;
51 }
52 GPUCommonAlgorithm::sort(tmp, tmp + n, [&merger, offset](const int32_t& aa, const int32_t& bb) {
53 const auto& a = merger.SectorTrackInfos()[offset + aa];
54 const auto& b = merger.SectorTrackInfos()[offset + bb];
55 return (a.X() != b.X()) ? (a.X() < b.X()) : (a.Y() != b.Y()) ? (a.Y() < b.Y())
56 : (a.Z() < b.Z());
57 });
58 for (int32_t j = 0; j < n; j++) {
59 if (tmp[j] >= 0 && tmp[j] != j) {
60 auto getTrackIDIndex = [&merger](const int32_t iSector, const int32_t iTrack) {
61 const int32_t kEnd = merger.NMaxSingleSectorTracks();
62 for (int32_t k = 0; k < kEnd; k++) {
63 if (merger.TrackIDs()[iSector * merger.NMaxSingleSectorTracks() + k] == iTrack) {
64 return k;
65 }
66 }
67#ifndef GPUCA_GPUCODE_DEVICE
68 throw std::runtime_error("Internal error, track id missing");
69#endif
70 return -1;
71 };
72 int32_t firstIdx = j;
73 auto firstItem = merger.SectorTrackInfos()[offset + firstIdx];
74 int32_t firstTrackIDIndex = parameter ? 0 : getTrackIDIndex(i, offset + firstIdx);
75 int32_t currIdx = firstIdx;
76 int32_t sourceIdx = tmp[currIdx];
77 do {
78 tmp[currIdx] = -1;
79 merger.SectorTrackInfos()[offset + currIdx] = merger.SectorTrackInfos()[offset + sourceIdx];
80 if (!parameter) {
81 merger.TrackIDs()[i * merger.NMaxSingleSectorTracks() + getTrackIDIndex(i, offset + sourceIdx)] = offset + currIdx;
82 }
83 currIdx = sourceIdx;
84 sourceIdx = tmp[currIdx];
85 } while (sourceIdx != firstIdx);
86 tmp[currIdx] = -1;
87 merger.SectorTrackInfos()[offset + currIdx] = firstItem;
88 if (!parameter) {
89 merger.TrackIDs()[i * merger.NMaxSingleSectorTracks() + firstTrackIDIndex] = offset + currIdx;
90 }
91 }
92 }
93 }
94}
95
96template <>
97GPUdii() void GPUTPCGlobalDebugSortKernels::Thread<GPUTPCGlobalDebugSortKernels::extrapolatedTracks1>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& GPUrestrict() merger, int8_t parameter)
98{
99 if (iThread || iBlock) {
100 return;
101 }
102 int32_t* GPUrestrict() tmp = merger.TmpSortMemory();
103 const int32_t n = merger.NOutputTracks();
104 for (int32_t j = 0; j < n; j++) {
105 tmp[j] = j;
106 }
107 GPUCommonAlgorithm::sortDeviceDynamic(tmp, tmp + n, [&merger](const int32_t& aa, const int32_t& bb) {
108 const GPUTPCGMMergedTrack& a = merger.OutputTracks()[aa];
109 const GPUTPCGMMergedTrack& b = merger.OutputTracks()[bb];
110 return (a.GetAlpha() != b.GetAlpha()) ? (a.GetAlpha() < b.GetAlpha()) : (a.GetParam().GetX() != b.GetParam().GetX()) ? (a.GetParam().GetX() < b.GetParam().GetX()) : (a.GetParam().GetY() != b.GetParam().GetY()) ? (a.GetParam().GetY() < b.GetParam().GetY()) : (a.GetParam().GetZ() < b.GetParam().GetZ());
111 });
112}
113
114template <>
115GPUdii() void GPUTPCGlobalDebugSortKernels::Thread<GPUTPCGlobalDebugSortKernels::extrapolatedTracks2>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& GPUrestrict() merger, int8_t parameter)
116{
117 if (iBlock) {
118 return;
119 }
120 const int32_t n = merger.NOutputTracks();
121 int32_t* GPUrestrict() tmp = merger.TmpSortMemory();
122 int32_t* GPUrestrict() tmp2 = tmp + n;
123 if (iThread == 0) {
124 for (int32_t j = 0; j < n; j++) {
125 if (tmp[j] == j) {
126 tmp2[j] = j;
127 } else if (tmp[j] >= 0) {
128 int32_t firstIdx = j;
129 auto firstItem = merger.OutputTracks()[firstIdx];
130 int32_t currIdx = firstIdx;
131 int32_t sourceIdx = tmp[currIdx];
132 tmp2[sourceIdx] = currIdx;
133 do {
134 tmp[currIdx] = -1;
135 merger.OutputTracks()[currIdx] = merger.OutputTracks()[sourceIdx];
136 currIdx = sourceIdx;
137 sourceIdx = tmp[currIdx];
138 tmp2[sourceIdx] = currIdx;
139 } while (sourceIdx != firstIdx);
140 tmp[currIdx] = -1;
141 merger.OutputTracks()[currIdx] = firstItem;
142 }
143 }
144 }
145 GPUbarrier();
146 for (int32_t i = 0; i < 2 * GPUCA_NSECTORS; i++) {
147 for (uint32_t k = iThread; k < merger.TmpCounter()[i]; k += nThreads) {
148 merger.BorderTracks(i)[k].SetTrackID(tmp2[merger.BorderTracks(i)[k].TrackID()]);
149 }
150 }
151}
152
153template <>
154GPUdii() void GPUTPCGlobalDebugSortKernels::Thread<GPUTPCGlobalDebugSortKernels::borderTracks>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& GPUrestrict() merger, int8_t parameter)
155{
156 if (iThread) {
157 return;
158 }
159 auto* borderTracks = merger.BorderTracks(iBlock);
160 const uint32_t n = merger.TmpCounter()[iBlock];
161 GPUCommonAlgorithm::sortDeviceDynamic(borderTracks, borderTracks + n, [](const GPUTPCGMBorderTrack& a, const GPUTPCGMBorderTrack& b) {
162 return (a.TrackID() < b.TrackID());
163 });
164}
int32_t i
#define GPUsharedref()
#define GPUbarrier()
#define GPUrestrict()
const int16_t bb
#define GPUCA_NSECTORS
GPUdii() void GPUTPCGlobalDebugSortKernels
uint32_t j
Definition RawData.h:0
GLdouble n
Definition glcorearb.h:1982
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLintptr offset
Definition glcorearb.h:660
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233