Project
Loading...
Searching...
No Matches
GPUChainTrackingTransformation.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 "AliHLTTPCRawCluster.h"
22#include "GPUConstantMem.h"
23#include "GPUTPCClusterData.h"
24
28#include "utils/strtag.h"
29
30using namespace o2::gpu;
31using namespace o2::tpc;
32
33bool GPUChainTracking::NeedTPCClustersOnGPU()
34{
36}
37
39{
41 const auto& threadContext = GetThreadContext();
42
43 bool transferClusters = false;
44 if (mRec->IsGPU() && !(mRec->GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCClusterFinding) && NeedTPCClustersOnGPU()) {
45 mInputsHost->mNClusterNative = mInputsShadow->mNClusterNative = mIOPtrs.clustersNative->nClustersTotal;
46 AllocateRegisteredMemory(mInputsHost->mResourceClusterNativeBuffer);
47 processorsShadow()->ioPtrs.clustersNative = mInputsShadow->mPclusterNativeAccess;
48 WriteToConstantMemory(RecoStep::TPCConversion, (char*)&processors()->ioPtrs - (char*)processors(), &processorsShadow()->ioPtrs, sizeof(processorsShadow()->ioPtrs), 0);
49 *mInputsHost->mPclusterNativeAccess = *mIOPtrs.clustersNative;
50 mInputsHost->mPclusterNativeAccess->clustersLinear = mInputsShadow->mPclusterNativeBuffer;
51 mInputsHost->mPclusterNativeAccess->setOffsetPtrs();
52 GPUMemCpy(RecoStep::TPCConversion, mInputsShadow->mPclusterNativeBuffer, mIOPtrs.clustersNative->clustersLinear, sizeof(mIOPtrs.clustersNative->clustersLinear[0]) * mIOPtrs.clustersNative->nClustersTotal, 0, true);
53 TransferMemoryResourceLinkToGPU(RecoStep::TPCConversion, mInputsHost->mResourceClusterNativeAccess, 0);
54 transferClusters = true;
55 }
56 if (GetProcessingSettings().debugLevel >= 3) {
57 GPUInfo("Early transform inactive, skipping TPC Early transformation kernel, transformed on the fly during sector data creation / refit");
58 }
59 if (transferClusters) {
60 SynchronizeStream(0); // TODO: Synchronize implicitly with next step
61 }
62 return 0;
63}
64
66{
68 if (tmp != mIOPtrs.clustersNative) {
69 *tmp = *mIOPtrs.clustersNative;
70 }
72 for (uint32_t i = 0; i < NSECTORS; i++) {
74 if (GetProcessingSettings().registerStandaloneInputMemory) {
76 throw std::runtime_error("Error registering memory for GPU");
77 }
78 }
79 }
80 mIOPtrs.clustersNative = nullptr;
81 mIOMem.clustersNative.reset(nullptr);
82}
83
85{
87 for (uint32_t i = 0; i < NSECTORS; i++) {
88 mIOPtrs.rawClusters[i] = nullptr;
90 mIOMem.rawClusters[i].reset(nullptr);
91 mIOPtrs.clusterData[i] = nullptr;
93 mIOMem.clusterData[i].reset(nullptr);
94 }
96 if (GetProcessingSettings().registerStandaloneInputMemory) {
97 if (mRec->registerMemoryForGPU(mIOMem.clustersNative.get(), mIOMem.clusterNativeAccess->nClustersTotal * sizeof(*mIOMem.clusterNativeAccess->clustersLinear))) {
98 throw std::runtime_error("Error registering memory for GPU");
99 }
100 }
101}
102
104{
111 if (GetProcessingSettings().registerStandaloneInputMemory) {
112 for (uint32_t i = 0; i < NSECTORS; i++) {
113 for (uint32_t j = 0; j < GPUTrackingInOutZS::NENDPOINTS; j++) {
114 for (uint32_t k = 0; k < mIOPtrs.tpcZS->sector[i].count[j]; k++) {
116 throw std::runtime_error("Error registering memory for GPU");
117 }
118 }
119 }
120 }
121 }
122}
123
128
130{
131 if (GetRecoStepsGPU() & RecoStep::TPCClusterFinding) {
132 throw std::runtime_error("Cannot forward TPC digits with Clusterizer on GPU");
133 }
134 std::vector<ClusterNative> tmp[NSECTORS][GPUCA_ROW_COUNT];
135 uint32_t nTotal = 0;
136 const float zsThreshold = param().rec.tpc.zsThreshold;
137 for (int32_t i = 0; i < NSECTORS; i++) {
138 for (uint32_t j = 0; j < mIOPtrs.tpcPackedDigits->nTPCDigits[i]; j++) {
139 const auto& d = mIOPtrs.tpcPackedDigits->tpcDigits[i][j];
140 if (d.getChargeFloat() >= zsThreshold) {
142 c.setTimeFlags(d.getTimeStamp(), 0);
143 c.setPad(d.getPad());
144 c.setSigmaTime(1);
145 c.setSigmaPad(1);
146 c.qTot = c.qMax = d.getChargeFloat();
147 tmp[i][d.getRow()].emplace_back(c);
148 nTotal++;
149 }
150 }
151 }
152 mIOMem.clustersNative.reset(new ClusterNative[nTotal]);
153 nTotal = 0;
154 mClusterNativeAccess->clustersLinear = mIOMem.clustersNative.get();
155 for (int32_t i = 0; i < NSECTORS; i++) {
156 for (int32_t j = 0; j < GPUCA_ROW_COUNT; j++) {
157 mClusterNativeAccess->nClusters[i][j] = tmp[i][j].size();
158 memcpy(&mIOMem.clustersNative[nTotal], tmp[i][j].data(), tmp[i][j].size() * sizeof(*mClusterNativeAccess->clustersLinear));
159 nTotal += tmp[i][j].size();
160 }
161 }
162 mClusterNativeAccess->setOffsetPtrs();
163 mIOPtrs.tpcPackedDigits = nullptr;
165 GPUInfo("Forwarded %u TPC clusters", nTotal);
166 mRec->MemoryScalers()->nTPCHits = nTotal;
167 return 0;
168}
Class of a TPC cluster in TPC-native coordinates (row, time)
int32_t i
#define GPUCA_ROW_COUNT
uint32_t j
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
uint32_t version
Definition RawData.h:8
Definitions of TPC Zero Suppression Data Headers.
std::unique_ptr< o2::tpc::ClusterNativeAccess > mClusterNativeAccess
std::unique_ptr< GPUTrackingInputProvider > mInputsHost
GPUTrackingInOutPointers & mIOPtrs
struct o2::gpu::GPUChainTracking::InOutMemory mIOMem
std::unique_ptr< GPUTrackingInputProvider > mInputsShadow
void TransferMemoryResourceLinkToGPU(RecoStep step, int16_t res, int32_t stream=-1, 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:128
GPUReconstruction::RecoStepField GetRecoStepsGPU() const
Definition GPUChain.h:72
void WriteToConstantMemory(RecoStep step, size_t offset, const void *src, size_t size, int32_t stream=-1, deviceEvent *ev=nullptr)
Definition GPUChain.h:127
size_t AllocateRegisteredMemory(GPUProcessor *proc)
Definition GPUChain.h:217
virtual std::unique_ptr< GPUReconstructionProcessing::threadContext > GetThreadContext()
Definition GPUChain.h:109
GPUConstantMem * processors()
Definition GPUChain.h:84
GPUParam & param()
Definition GPUChain.h:87
const GPUSettingsProcessing & GetProcessingSettings() const
Definition GPUChain.h:76
void SynchronizeStream(int32_t stream)
Definition GPUChain.h:89
GPUReconstructionCPU * mRec
Definition GPUChain.h:79
GPUConstantMem * processorsShadow()
Definition GPUChain.h:85
static constexpr int32_t NSECTORS
Definition GPUChain.h:58
GPUReconstruction * rec()
Definition GPUChain.h:66
static void RunZSEncoder(const S &in, std::unique_ptr< uint64_t[]> *outBuffer, uint32_t *outSizes, o2::raw::RawFileWriter *raw, const o2::InteractionRecord *ir, const GPUParam &param, int32_t version, bool verify, float threshold=0.f, bool padding=false, std::function< void(std::vector< o2::tpc::Digit > &)> digitsFilter=nullptr)
static void ConvertNativeToClusterData(o2::tpc::ClusterNativeAccess *native, std::unique_ptr< GPUTPCClusterData[]> *clusters, uint32_t *nClusters, const TPCFastTransform *transform, int32_t continuousMaxTimeBin=0)
static void RunZSFilter(std::unique_ptr< o2::tpc::Digit[]> *buffers, const o2::tpc::Digit *const *ptrs, size_t *nsb, const size_t *ns, const GPUParam &param, bool zs12bit, float threshold)
static void RunZSEncoderCreateMeta(const uint64_t *buffer, const uint32_t *sizes, void **ptrs, GPUTrackingInOutZS *out)
static void ConvertRun2RawToNative(o2::tpc::ClusterNativeAccess &native, std::unique_ptr< o2::tpc::ClusterNative[]> &nativeBuffer, const AliHLTTPCRawCluster **rawClusters, uint32_t *nRawClusters)
RecoStepField GetRecoStepsGPU() const
void PushNonPersistentMemory(uint64_t tag)
GPUMemorySizeScalers * MemoryScalers()
int32_t registerMemoryForGPU(const void *ptr, size_t size)
GLenum GLfloat param
Definition glcorearb.h:271
Global TPC definitions and constants.
Definition SimTraits.h:167
constexpr T qStr2Tag(const char *str)
Definition strtag.h:22
std::unique_ptr< o2::tpc::Digit[]> tpcDigits[NSECTORS]
std::unique_ptr< GPUTrackingInOutDigits > digitMap
std::unique_ptr< GPUTPCClusterData[]> clusterData[NSECTORS]
std::unique_ptr< o2::tpc::ClusterNative[]> clustersNative
std::unique_ptr< uint64_t[]> tpcZSpages
std::unique_ptr< GPUTrackingInOutZS > tpcZSmeta
std::unique_ptr< o2::tpc::ClusterNativeAccess > clusterNativeAccess
std::unique_ptr< AliHLTTPCRawCluster[]> rawClusters[NSECTORS]
std::unique_ptr< GPUTrackingInOutZS::GPUTrackingInOutZSMeta > tpcZSmeta2
GPUTrackingInOutPointers ioPtrs
const o2::tpc::Digit * tpcDigits[NSECTORS]
const o2::tpc::ClusterNativeAccess * clustersNative
const GPUSettingsTF * settingsTF
const GPUTrackingInOutZS * tpcZS
const AliHLTTPCRawCluster * rawClusters[NSECTORS]
const GPUTPCClusterData * clusterData[NSECTORS]
const GPUTrackingInOutDigits * tpcPackedDigits
GPUTrackingInOutZSSector sector[NSECTORS]
static constexpr uint32_t NENDPOINTS
const ClusterNative * clustersLinear
static constexpr size_t TPC_ZS_PAGE_SIZE
o2::InteractionRecord ir(0, 0)