forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
/
GPUO2Interface.cxx
200 lines (183 loc) · 7.41 KB
/
GPUO2Interface.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file GPUO2Interface.cxx
/// \author David Rohr
#include "GPUO2Interface.h"
#include "GPUReconstruction.h"
#include "GPUChainTracking.h"
#include "GPUMemorySizeScalers.h"
#include "GPUOutputControl.h"
#include "GPUO2InterfaceConfiguration.h"
#include "GPUParam.inc"
#include "GPUQA.h"
#include <iostream>
#include <fstream>
#ifdef WITH_OPENMP
#include <omp.h>
#endif
using namespace o2::gpu;
#include "DataFormatsTPC/ClusterNative.h"
GPUTPCO2Interface::GPUTPCO2Interface() = default;
GPUTPCO2Interface::~GPUTPCO2Interface() { Deinitialize(); }
int GPUTPCO2Interface::Initialize(const GPUO2InterfaceConfiguration& config)
{
if (mInitialized) {
return (1);
}
mConfig.reset(new GPUO2InterfaceConfiguration(config));
mContinuous = mConfig->configEvent.continuousMaxTimeBin != 0;
mRec.reset(GPUReconstruction::CreateInstance(mConfig->configDeviceBackend));
if (mRec == nullptr) {
GPUError("Error obtaining instance of GPUReconstruction");
return 1;
}
mChain = mRec->AddChain<GPUChainTracking>(mConfig->configInterface.maxTPCHits, mConfig->configInterface.maxTRDTracklets);
mChain->mConfigDisplay = &mConfig->configDisplay;
mChain->mConfigQA = &mConfig->configQA;
if (mConfig->configWorkflow.inputs.isSet(GPUDataTypes::InOutType::TPCRaw)) {
mConfig->configEvent.needsClusterer = 1;
}
mRec->SetSettings(&mConfig->configEvent, &mConfig->configReconstruction, &mConfig->configProcessing, &mConfig->configWorkflow);
mChain->SetTPCFastTransform(mConfig->configCalib.fastTransform);
mChain->SetTPCPadGainCalib(mConfig->configCalib.tpcPadGain);
mChain->SetdEdxSplines(mConfig->configCalib.dEdxSplines);
mChain->SetMatLUT(mConfig->configCalib.matLUT);
mChain->SetTRDGeometry(mConfig->configCalib.trdGeometry);
mChain->SetO2Propagator(mConfig->configCalib.o2Propagator);
if (mConfig->configInterface.outputToExternalBuffers) {
mOutputCompressedClusters.reset(new GPUOutputControl);
mChain->SetOutputControlCompressedClusters(mOutputCompressedClusters.get());
mOutputClustersNative.reset(new GPUOutputControl);
mChain->SetOutputControlClustersNative(mOutputClustersNative.get());
mOutputTPCTracks.reset(new GPUOutputControl);
mChain->SetOutputControlTPCTracks(mOutputTPCTracks.get());
mOutputSharedClusterMap.reset(new GPUOutputControl);
mChain->SetOutputControlSharedClusterMap(mOutputSharedClusterMap.get());
GPUOutputControl dummy;
dummy.set([](size_t size) -> void* {throw std::runtime_error("invalid output memory request, no common output buffer set"); return nullptr; });
mRec->SetOutputControl(dummy);
}
if (mConfig->configProcessing.runMC) {
mOutputTPCClusterLabels.reset(new GPUOutputControl);
mChain->SetOutputControlClusterLabels(mOutputTPCClusterLabels.get());
}
if (mRec->Init()) {
return (1);
}
if (!mRec->IsGPU() && mRec->GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL) {
mRec->MemoryScalers()->factor *= 2;
}
mRec->MemoryScalers()->factor *= mConfig->configInterface.memoryBufferScaleFactor;
mInitialized = true;
return (0);
}
void GPUTPCO2Interface::Deinitialize()
{
if (mInitialized) {
mRec->Finalize();
mRec.reset();
}
mInitialized = false;
}
int GPUTPCO2Interface::RunTracking(GPUTrackingInOutPointers* data, GPUInterfaceOutputs* outputs)
{
if (!mInitialized) {
return (1);
}
if (mConfig->configInterface.dumpEvents) {
static int nEvent = 0;
mChain->ClearIOPointers();
mChain->mIOPtrs.clustersNative = data->clustersNative;
mChain->mIOPtrs.tpcPackedDigits = data->tpcPackedDigits;
mChain->mIOPtrs.tpcZS = data->tpcZS;
char fname[1024];
sprintf(fname, "event.%d.dump", nEvent);
mChain->DumpData(fname);
if (nEvent == 0) {
mRec->DumpSettings();
}
nEvent++;
if (mConfig->configInterface.dumpEvents >= 2) {
return 0;
}
}
mChain->mIOPtrs = *data;
if (mConfig->configInterface.outputToExternalBuffers) {
if (outputs->compressedClusters.allocator) {
mOutputCompressedClusters->set(outputs->compressedClusters.allocator);
} else if (outputs->compressedClusters.ptr) {
mOutputCompressedClusters->set(outputs->compressedClusters.ptr, outputs->compressedClusters.size);
} else {
mOutputCompressedClusters->reset();
}
if (outputs->clustersNative.allocator) {
mOutputClustersNative->set(outputs->clustersNative.allocator);
} else if (outputs->clustersNative.ptr) {
mOutputClustersNative->set(outputs->clustersNative.ptr, outputs->clustersNative.size);
} else {
mOutputClustersNative->reset();
}
if (outputs->tpcTracks.allocator) {
mOutputTPCTracks->set(outputs->tpcTracks.allocator);
} else if (outputs->tpcTracks.ptr) {
mOutputTPCTracks->set(outputs->tpcTracks.ptr, outputs->tpcTracks.size);
} else {
mOutputTPCTracks->reset();
}
if (outputs->sharedClusterMap.allocator) {
mOutputSharedClusterMap->set(outputs->sharedClusterMap.allocator);
} else if (outputs->sharedClusterMap.ptr) {
mOutputSharedClusterMap->set(outputs->sharedClusterMap.ptr, outputs->sharedClusterMap.size);
} else {
mOutputSharedClusterMap->reset();
}
}
if (mConfig->configProcessing.runMC) {
if (outputs->clusterLabels.allocator) {
mOutputTPCClusterLabels->set(outputs->clusterLabels.allocator);
} else {
mOutputTPCClusterLabels->reset();
}
}
int retVal = mRec->RunChains();
if (retVal == 2) {
retVal = 0; // 2 signals end of event display, ignore
}
if (retVal) {
mRec->ClearAllocatedMemory();
return retVal;
}
if (mConfig->configInterface.outputToExternalBuffers) {
outputs->compressedClusters.size = mOutputCompressedClusters->EndOfSpace ? 0 : mChain->mIOPtrs.tpcCompressedClusters->totalDataSize;
outputs->clustersNative.size = mOutputClustersNative->EndOfSpace ? 0 : (mChain->mIOPtrs.clustersNative->nClustersTotal * sizeof(*mChain->mIOPtrs.clustersNative->clustersLinear));
outputs->tpcTracks.size = mOutputCompressedClusters->EndOfSpace ? 0 : (size_t)((char*)mOutputCompressedClusters->OutputPtr - (char*)mOutputCompressedClusters->OutputBase);
}
if (mConfig->configQA.shipToQC) {
outputs->qa.hist1 = &mChain->GetQA()->getHistograms1D();
outputs->qa.hist2 = &mChain->GetQA()->getHistograms2D();
outputs->qa.hist3 = &mChain->GetQA()->getHistograms1Dd();
}
*data = mChain->mIOPtrs;
return 0;
}
void GPUTPCO2Interface::Clear(bool clearOutputs) { mRec->ClearAllocatedMemory(clearOutputs); }
void GPUTPCO2Interface::GetClusterErrors2(int row, float z, float sinPhi, float DzDs, short clusterState, float& ErrY2, float& ErrZ2) const
{
mRec->GetParam().GetClusterErrors2(row, z, sinPhi, DzDs, ErrY2, ErrZ2);
mRec->GetParam().UpdateClusterError2ByState(clusterState, ErrY2, ErrZ2);
}
int GPUTPCO2Interface::registerMemoryForGPU(const void* ptr, size_t size)
{
return mRec->registerMemoryForGPU(ptr, size);
}
int GPUTPCO2Interface::unregisterMemoryForGPU(const void* ptr)
{
return mRec->unregisterMemoryForGPU(ptr);
}