Project
Loading...
Searching...
No Matches
GPUTPCTracker.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 "GPUTPCTracker.h"
16#include "GPUTPCRow.h"
17#include "GPUTPCTrack.h"
18#include "GPUCommonMath.h"
19
20#include "GPUO2DataTypes.h"
21#include "GPUTPCTrackParam.h"
22#include "GPUParam.inc"
23#include "GPUTPCConvertImpl.h"
24#include "GPUDefParametersRuntime.h"
25
26#if !defined(GPUCA_GPUCODE)
27#include <cstring>
28#include <cmath>
29#include <algorithm>
30#include <stdexcept>
31
32#include "GPUReconstruction.h"
34#endif
35
36using namespace o2::gpu;
37using namespace o2::tpc;
38
39#if !defined(GPUCA_GPUCODE)
40
42
43// ----------------------------------------------------------------------------------
44void GPUTPCTracker::SetSector(int32_t iSector) { mISector = iSector; }
50
51void* GPUTPCTracker::SetPointersDataLinks(void* mem) { return mData.SetPointersLinks(mem); }
52void* GPUTPCTracker::SetPointersDataWeights(void* mem) { return mData.SetPointersWeights(mem); }
54void* GPUTPCTracker::SetPointersDataRows(void* mem) { return mData.SetPointersRows(mem); }
55
57{
58 computePointerWithAlignment(mem, mTrackletStartHits, mNMaxStartHits);
59 if (mRec->GetProcessingSettings().memoryAllocationStrategy != GPUMemoryResource::ALLOCATION_INDIVIDUAL) {
60 mem = SetPointersTracklets(mem);
61 }
63 computePointerWithAlignment(mem, mTrackletTmpStartHits, GPUTPCGeometry::NROWS * mNMaxRowStartHits);
64 computePointerWithAlignment(mem, mRowStartHitCountOffset, GPUTPCGeometry::NROWS);
65 }
66 return mem;
67}
68
70{
71 if (mRec->GetProcessingSettings().keepDisplayMemory) {
72 computePointerWithAlignment(mem, mLinkTmpMemory, mRec->Res(mMemoryResLinks).Size());
73 }
75 return mem;
76}
77
79{
80 computePointerWithAlignment(mem, mCommonMem, 1);
81 return mem;
82}
83
85{
86 return !mRec->GetProcessingSettings().keepDisplayMemory && ((mRec->GetRecoStepsGPU() & gpudatatypes::RecoStep::TPCSectorTracking) || mRec->GetProcessingSettings().inKernelParallel == 1 || mRec->GetProcessingSettings().nHostThreads == 1);
87}
88
90{
92 bool reuseCondition = MemoryReuseAllowed();
93 GPUMemoryReuse reLinks{reuseCondition, GPUMemoryReuse::REUSE_1TO1, GPUMemoryReuse::TrackerDataLinks, (uint16_t)(mISector % mRec->GetProcessingSettings().nStreams)};
96 GPUMemoryReuse reWeights{reuseCondition, GPUMemoryReuse::REUSE_1TO1, GPUMemoryReuse::TrackerDataWeights, (uint16_t)(mISector % mRec->GetProcessingSettings().nStreams)};
98 GPUMemoryReuse reScratch{reuseCondition, GPUMemoryReuse::REUSE_1TO1, GPUMemoryReuse::TrackerScratch, (uint16_t)(mISector % mRec->GetProcessingSettings().nStreams)};
103
105 if (mRec->GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL) { // For individual scheme, we allocate tracklets separately, and change the type for the following allocations to custom
107 mMemoryResTracklets = mRec->RegisterMemoryAllocation(this, &GPUTPCTracker::SetPointersTracklets, type | GPUMemoryResource::MEMORY_STACK, "TPCTrackerTracklets");
108 }
109 mMemoryResOutput = mRec->RegisterMemoryAllocation(this, &GPUTPCTracker::SetPointersOutput, type, "TPCTrackerTracks"); // TODO: Ideally this should eventually go on the stack, so that we can free it after the first phase of track merging
110}
111
112GPUhd() void* GPUTPCTracker::SetPointersTracklets(void* mem)
113{
114 computePointerWithAlignment(mem, mTracklets, mNMaxTracklets);
115 computePointerWithAlignment(mem, mTrackletRowHits, mNMaxRowHits);
116 return mem;
117}
118
119GPUhd() void* GPUTPCTracker::SetPointersOutput(void* mem)
120{
121 computePointerWithAlignment(mem, mTracks, mNMaxTracks);
122 computePointerWithAlignment(mem, mTrackHits, mNMaxTrackHits);
123 return mem;
124}
125
127{
128 if (mRec->GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL) {
129 mNMaxStartHits = mData.NumberOfHits();
130 } else {
131 mNMaxStartHits = mRec->MemoryScalers()->NTPCStartHits(mData.NumberOfHits());
132 }
133 if (io.clustersNative) {
134 uint32_t maxRowHits = 0;
135 for (uint32_t i = 0; i < GPUTPCGeometry::NROWS; i++) {
136 if (io.clustersNative->nClusters[mISector][i] > maxRowHits) {
137 maxRowHits = io.clustersNative->nClusters[mISector][i];
138 }
139 }
140 mNMaxRowStartHits = mRec->MemoryScalers()->NTPCRowStartHits(maxRowHits * GPUTPCGeometry::NROWS);
141 } else {
142 mNMaxRowStartHits = mRec->MemoryScalers()->NTPCRowStartHits(mData.NumberOfHits());
143 }
144 bool lowField = CAMath::Abs(Param().bzkG) < 4;
145 mNMaxTracklets = mRec->MemoryScalers()->NTPCTracklets(mData.NumberOfHits(), lowField);
146 mNMaxRowHits = mRec->MemoryScalers()->NTPCTrackletHits(mData.NumberOfHits(), lowField);
147 mNMaxTracks = mRec->MemoryScalers()->NTPCSectorTracks(mData.NumberOfHits());
148 if (io.clustersNative) {
149 uint32_t sectorOffset = mISector >= GPUTPCGeometry::NSECTORS / 2 ? GPUTPCGeometry::NSECTORS / 2 : 0;
150 uint32_t nextSector = (mISector + 1) % (GPUTPCGeometry::NSECTORS / 2) + sectorOffset;
151 uint32_t prevSector = (mISector + GPUTPCGeometry::NSECTORS - 1) % (GPUTPCGeometry::NSECTORS / 2) + sectorOffset;
152 uint32_t nExtrapolationTracks = mRec->MemoryScalers()->NTPCSectorTracks((io.clustersNative->nClustersSector[nextSector] + io.clustersNative->nClustersSector[prevSector]) / 2) / 2;
153 if (nExtrapolationTracks > mNMaxTracks) {
154 mNMaxTracks = nExtrapolationTracks;
155 }
156 }
157 mNMaxTrackHits = mRec->MemoryScalers()->NTPCSectorTrackHits(mData.NumberOfHits(), mRec->GetProcessingSettings().tpcInputWithClusterRejection);
158
160 if (mNMaxStartHits > mNMaxRowStartHits * GPUTPCGeometry::NROWS) {
161 mNMaxStartHits = mNMaxRowStartHits * GPUTPCGeometry::NROWS;
162 }
163 }
164 mData.SetMaxData();
165}
166
168{
169 mNMaxTracklets = mCommonMem->nStartHits;
170 mNMaxTracks = mNMaxTracklets * 2 + 50;
171 mNMaxRowHits = mNMaxTracklets * GPUTPCGeometry::NROWS;
172}
173
175
176GPUh() int32_t GPUTPCTracker::CheckEmptySector()
177{
178 // Check if the Sector is empty, if so set the output apropriate and tell the reconstuct procesdure to terminate
179 if (NHitsTotal() < 1) {
180 mCommonMem->nTracks = mCommonMem->nTrackHits = 0;
181 return 1;
182 }
183 return 0;
184}
185
186#endif
int32_t i
#define GPUhd()
#define GPUh()
uint32_t iSector
GPUReconstruction * mRec
static void computePointerWithAlignment(T *&basePtr, S *&objPtr, size_t nEntries=1)
RecoStepField GetRecoStepsGPU() const
int16_t RegisterMemoryAllocation(T *proc, void *(T::*setPtr)(void *), int32_t type, const char *name="", const GPUMemoryReuse &re=GPUMemoryReuse())
GPUMemoryResource & Res(int16_t num)
GPUMemorySizeScalers * MemoryScalers()
const GPUSettingsProcessing & GetProcessingSettings() const
virtual const GPUDefParameters & getGPUParameters(bool doGPU) const =0
static constexpr uint32_t NROWS
static constexpr uint32_t NSECTORS
void * SetPointersScratchHost(void *mem)
void * SetPointersDataWeights(void *mem)
void * SetPointersDataRows(void *mem)
void * SetPointersOutput(void *mem)
void SetMaxData(const GPUTrackingInOutPointers &io)
void * SetPointersDataLinks(void *mem)
void * SetPointersDataScratch(void *mem)
void InitializeRows(const GPUParam *param)
void * SetPointersCommon(void *mem)
void * SetPointersTracklets(void *mem)
void * SetPointersScratch(void *mem)
void SetSector(int32_t iSector)
void * SetPointersScratch(void *mem, bool idsOnGPU)
void * SetPointersClusterIds(void *mem, bool idsOnGPU)
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
Global TPC definitions and constants.
Definition SimTraits.h:168
size_t NTPCTracklets(size_t tpcHits, bool lowField)
size_t NTPCRowStartHits(size_t tpcHits)
size_t NTPCSectorTracks(size_t tpcHits)
size_t NTPCTrackletHits(size_t tpcHits, bool lowField)
size_t NTPCSectorTrackHits(size_t tpcHits, uint8_t withRejection=0)
const o2::tpc::ClusterNativeAccess * clustersNative
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int nClustersSector[constants::MAXSECTOR]