Skip to content

Commit e90b535

Browse files
committed
GPU: Send compressed-cluster output in preallocated flat char array
1 parent e40fb9b commit e90b535

12 files changed

Lines changed: 73 additions & 19 deletions

File tree

DataFormats/Detectors/TPC/include/DataFormatsTPC/CompressedClusters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct CompressedClusters : public CompressedClustersCounters, public Compressed
8484
struct CompressedClustersROOT : public CompressedClusters {
8585
CompressedClustersROOT() CON_DEFAULT;
8686
CompressedClustersROOT(const CompressedClustersFlat& v) : CompressedClusters(v) {}
87+
CompressedClustersROOT(const CompressedClusters& v) : CompressedClusters(v) {}
8788
// flatbuffer used for streaming
8889
int flatdataSize = 0;
8990
char* flatdata = nullptr; //[flatdataSize]

Detectors/TPC/reconstruction/include/TPCReconstruction/GPUCATracking.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace gpu
2424
{
2525
struct GPUO2InterfaceConfiguration;
2626
struct GPUO2InterfaceIOPtrs;
27+
struct GPUInterfaceOutputs;
2728
class GPUTPCO2Interface;
2829
} // namespace gpu
2930
} // namespace o2
@@ -55,7 +56,7 @@ class GPUCATracking
5556
void deinitialize();
5657

5758
//Input: cluster structure, possibly including MC labels, pointers to std::vectors for tracks and track MC labels. outputTracksMCTruth may be nullptr to indicate missing cluster MC labels. Otherwise, cluster MC labels are assumed to be present.
58-
int runTracking(o2::gpu::GPUO2InterfaceIOPtrs* data);
59+
int runTracking(o2::gpu::GPUO2InterfaceIOPtrs* data, o2::gpu::GPUInterfaceOutputs* outputs = nullptr);
5960

6061
float getPseudoVDrift(); //Return artificial VDrift used to convert time to Z
6162
int getNTracksASide() { return mNTracksASide; }

Detectors/TPC/reconstruction/src/GPUCATracking.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void GPUCATracking::deinitialize()
5959
mTrackingCAO2Interface.reset();
6060
}
6161

62-
int GPUCATracking::runTracking(GPUO2InterfaceIOPtrs* data)
62+
int GPUCATracking::runTracking(GPUO2InterfaceIOPtrs* data, GPUInterfaceOutputs* outputs)
6363
{
6464
if ((int)(data->tpcZS != nullptr) + (int)(data->o2Digits != nullptr) + (int)(data->clusters != nullptr) != 1) {
6565
return 0;
@@ -118,7 +118,7 @@ int GPUCATracking::runTracking(GPUO2InterfaceIOPtrs* data)
118118
ptrs.clustersNative = clusters;
119119
ptrs.tpcPackedDigits = nullptr;
120120
}
121-
int retVal = mTrackingCAO2Interface->RunTracking(&ptrs);
121+
int retVal = mTrackingCAO2Interface->RunTracking(&ptrs, outputs);
122122
if (data->o2Digits || data->tpcZS) {
123123
clusters = ptrs.clustersNative;
124124
}

Detectors/TPC/workflow/src/CATrackerSpec.cxx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ DataProcessorSpec getCATrackerSpec(ca::Config const& specconfig, std::vector<int
230230
config.configReconstruction.tpcSigBitsWidth = 3; // Number of significant bits in TPC cluster width
231231

232232
config.configInterface.dumpEvents = dump;
233+
config.configInterface.outputToPreallocatedBuffers = true;
233234

234235
// Configure the "GPU workflow" i.e. which steps we run on the GPU (or CPU) with this instance of GPUCATracking
235236
config.configWorkflow.steps.set(GPUDataTypes::RecoStep::TPCConversion,
@@ -538,7 +539,12 @@ DataProcessorSpec getCATrackerSpec(ca::Config const& specconfig, std::vector<int
538539
ClusterNativeHelper::Reader::fillIndex(clusterIndex, clusterBuffer, clustersMCBuffer, inputs, mcInputs, [&validInputs](auto& index) { return validInputs.test(index); });
539540
ptrs.clusters = &clusterIndex;
540541
}
541-
int retVal = tracker->runTracking(&ptrs);
542+
GPUInterfaceOutputs outputRegions;
543+
auto bufferCompressedClusters = pc.outputs().make<std::vector<GPUO2InterfaceConfiguration::bufferType>>(Output{gDataOriginTPC, "COMPCLUSTERS", 0});
544+
bufferCompressedClusters.resize(2048ul * 1024 * 1024 / sizeof(GPUO2InterfaceConfiguration::bufferType)); // TODO: Just allocated some large buffer for now, should estimate this correctly
545+
outputRegions.compressedClusters.ptr = bufferCompressedClusters.data();
546+
outputRegions.compressedClusters.size = bufferCompressedClusters.size() * sizeof(GPUO2InterfaceConfiguration::bufferType);
547+
int retVal = tracker->runTracking(&ptrs, &outputRegions);
542548
if (retVal != 0) {
543549
throw std::runtime_error("tracker returned error code " + std::to_string(retVal));
544550
}
@@ -562,8 +568,7 @@ DataProcessorSpec getCATrackerSpec(ca::Config const& specconfig, std::vector<int
562568
//mDecoder.decompress(clustersCompressed, clustersNativeDecoded, clusterBuffer, param); // Run decompressor
563569
if (pc.outputs().isAllowed({gDataOriginTPC, "COMPCLUSTERS", 0})) {
564570
if (ptrs.compressedClusters != nullptr) {
565-
o2::tpc::CompressedClustersROOT compressedClusters = *ptrs.compressedClusters;
566-
pc.outputs().snapshot(Output{gDataOriginTPC, "COMPCLUSTERS", 0}, ROOTSerialized<o2::tpc::CompressedClustersROOT const>(compressedClusters));
571+
bufferCompressedClusters.resize(outputRegions.compressedClusters.size);
567572
} else {
568573
LOG(ERROR) << "unable to get compressed cluster info from track";
569574
}

Detectors/TPC/workflow/src/EntropyEncoderSpec.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ DataProcessorSpec getEntropyEncoderSpec()
5252
auto processAttributes = std::make_shared<ProcessAttributes>();
5353

5454
auto processingFct = [processAttributes](ProcessingContext& pc) {
55-
auto clusters = pc.inputs().get<CompressedClustersROOT*>("input");
56-
if (clusters == nullptr) {
55+
auto tmp = pc.inputs().get<CompressedClustersFlat*>("input");
56+
if (tmp == nullptr) {
5757
LOG(ERROR) << "invalid input";
5858
return;
5959
}
60+
CompressedClusters clusters(*tmp);
6061

61-
auto encodedClusters = o2::tpc::TPCEntropyEncoder::encode(*clusters);
62+
auto encodedClusters = o2::tpc::TPCEntropyEncoder::encode(clusters);
6263

6364
const char* outFileName = "tpc-encoded-clusters.root";
6465

GPU/GPUTracking/Base/GPUOutputControl.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
#define GPUOUTPUTCONTROL_H
1616

1717
#include "GPUCommonDef.h"
18-
#ifndef GPUCA_GPUCODE
18+
#ifndef GPUCA_GPUCODE_DEVICE
1919
#include <cstddef>
20+
#include <new>
2021
#endif
2122

2223
namespace GPUCA_NAMESPACE
@@ -28,6 +29,13 @@ struct GPUOutputControl {
2829
UseExternalBuffer = 1 };
2930
#ifndef GPUCA_GPUCODE_DEVICE
3031
GPUOutputControl() = default;
32+
void set(void* ptr, size_t size)
33+
{
34+
new (this) GPUOutputControl;
35+
OutputType = GPUOutputControl::UseExternalBuffer;
36+
OutputBase = OutputPtr = (char*)ptr;
37+
OutputMaxSize = size;
38+
}
3139
#endif
3240

3341
void* OutputBase = nullptr; // Base ptr to memory pool, occupied size is OutputPtr - OutputBase

GPU/GPUTracking/Base/GPUReconstruction.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,7 @@ void GPUReconstruction::SetSettings(const GPUSettingsEvent* settings, const GPUS
651651
void GPUReconstruction::SetOutputControl(void* ptr, size_t size)
652652
{
653653
GPUOutputControl outputControl;
654-
outputControl.OutputType = GPUOutputControl::UseExternalBuffer;
655-
outputControl.OutputBase = outputControl.OutputPtr = (char*)ptr;
656-
outputControl.OutputMaxSize = size;
654+
outputControl.set(ptr, size);
657655
SetOutputControl(outputControl);
658656
}
659657

GPU/GPUTracking/Global/GPUChainTracking.cxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ int GPUChainTracking::Init()
283283
mEventDisplay.reset(new GPUDisplay(GetDeviceProcessingSettings().eventDisplay, this, mQA.get()));
284284
}
285285

286+
if (mOutputCompressedClusters == nullptr) {
287+
mOutputCompressedClusters = &mRec->OutputControl();
288+
}
289+
286290
if (mRec->IsGPU()) {
287291
if (processors()->calibObjects.fastTransform) {
288292
memcpy((void*)mFlatObjectsShadow.mCalibObjects.fastTransform, (const void*)processors()->calibObjects.fastTransform, sizeof(*processors()->calibObjects.fastTransform));
@@ -1697,7 +1701,7 @@ int GPUChainTracking::RunTPCCompression()
16971701
O->nAttachedClustersReduced = O->nAttachedClusters - O->nTracks;
16981702
O->nSliceRows = NSLICES * GPUCA_ROW_COUNT;
16991703
O->nComppressionModes = param().rec.tpcCompressionModes;
1700-
size_t outputSize = AllocateRegisteredMemory(Compressor.mMemoryResOutputHost, &mRec->OutputControl());
1704+
size_t outputSize = AllocateRegisteredMemory(Compressor.mMemoryResOutputHost, mOutputCompressedClusters);
17011705
Compressor.mOutputFlat->set(outputSize, *Compressor.mOutput);
17021706
const o2::tpc::CompressedClustersPtrs* P = nullptr;
17031707
if (DeviceProcessingSettings().tpcCompressionGatherMode == 2) {

GPU/GPUTracking/Global/GPUChainTracking.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class GPUChainTracking : public GPUChain, GPUReconstructionHelpers::helperDelega
152152
void SetMatLUT(const o2::base::MatLayerCylSet* lut) { processors()->calibObjects.matLUT = lut; }
153153
void SetTRDGeometry(const o2::trd::TRDGeometryFlat* geo) { processors()->calibObjects.trdGeometry = geo; }
154154
void LoadClusterErrors();
155+
void SetOutputControlCompressedClusters(GPUOutputControl* v) { mOutputCompressedClusters = v; }
155156

156157
const void* mConfigDisplay = nullptr; // Abstract pointer to Standalone Display Configuration Structure
157158
const void* mConfigQA = nullptr; // Abstract pointer to Standalone QA Configuration Structure
@@ -217,6 +218,8 @@ class GPUChainTracking : public GPUChain, GPUReconstructionHelpers::helperDelega
217218
std::unique_ptr<void*[]> mTPCZSPtrs; // Array with pointers to TPC ZS pages
218219
std::unique_ptr<GPUTrackingInOutZS> mTPCZS; // TPC ZS Data Structure
219220

221+
GPUOutputControl* mOutputCompressedClusters = nullptr;
222+
220223
// Upper bounds for memory allocation
221224
unsigned int mMaxTPCHits = 0;
222225
unsigned int mMaxTRDTracklets = 0;

GPU/GPUTracking/Interface/GPUO2Interface.cxx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "GPUReconstruction.h"
1616
#include "GPUChainTracking.h"
1717
#include "GPUMemorySizeScalers.h"
18+
#include "GPUOutputControl.h"
1819
#include "GPUO2InterfaceConfiguration.h"
1920
#include "GPUParam.inc"
2021
#include <iostream>
@@ -37,7 +38,6 @@ int GPUTPCO2Interface::Initialize(const GPUO2InterfaceConfiguration& config)
3738
return (1);
3839
}
3940
mConfig.reset(new GPUO2InterfaceConfiguration(config));
40-
mDumpEvents = mConfig->configInterface.dumpEvents;
4141
mContinuous = mConfig->configEvent.continuousMaxTimeBin != 0;
4242
mRec.reset(GPUReconstruction::CreateInstance(mConfig->configProcessing));
4343
if (mRec == nullptr) {
@@ -55,6 +55,11 @@ int GPUTPCO2Interface::Initialize(const GPUO2InterfaceConfiguration& config)
5555
mChain->SetdEdxSplines(mConfig->configCalib.dEdxSplines);
5656
mChain->SetMatLUT(mConfig->configCalib.matLUT);
5757
mChain->SetTRDGeometry(mConfig->configCalib.trdGeometry);
58+
if (mConfig->configInterface.outputToPreallocatedBuffers) {
59+
mOutputCompressedClusters.reset(new GPUOutputControl);
60+
mChain->SetOutputControlCompressedClusters(mOutputCompressedClusters.get());
61+
}
62+
5863
if (mRec->Init()) {
5964
return (1);
6065
}
@@ -74,13 +79,13 @@ void GPUTPCO2Interface::Deinitialize()
7479
mInitialized = false;
7580
}
7681

77-
int GPUTPCO2Interface::RunTracking(GPUTrackingInOutPointers* data)
82+
int GPUTPCO2Interface::RunTracking(GPUTrackingInOutPointers* data, GPUInterfaceOutputs* outputs)
7883
{
7984
if (!mInitialized) {
8085
return (1);
8186
}
8287
static int nEvent = 0;
83-
if (mDumpEvents) {
88+
if (mConfig->configInterface.dumpEvents) {
8489
mChain->ClearIOPointers();
8590
mChain->mIOPtrs.clustersNative = data->clustersNative;
8691
mChain->mIOPtrs.tpcPackedDigits = data->tpcPackedDigits;
@@ -95,6 +100,9 @@ int GPUTPCO2Interface::RunTracking(GPUTrackingInOutPointers* data)
95100
}
96101

97102
mChain->mIOPtrs = *data;
103+
if (mConfig->configInterface.outputToPreallocatedBuffers) {
104+
mOutputCompressedClusters->set(outputs->compressedClusters.ptr, outputs->compressedClusters.size);
105+
}
98106
int retVal = mRec->RunChains();
99107
if (retVal == 2) {
100108
retVal = 0; // 2 signals end of event display, ignore
@@ -103,6 +111,9 @@ int GPUTPCO2Interface::RunTracking(GPUTrackingInOutPointers* data)
103111
mRec->ClearAllocatedMemory();
104112
return retVal;
105113
}
114+
if (mConfig->configInterface.outputToPreallocatedBuffers) {
115+
outputs->compressedClusters.size = mOutputCompressedClusters->EndOfSpace ? 0 : mChain->mIOPtrs.tpcCompressedClusters->totalDataSize;
116+
}
106117
*data = mChain->mIOPtrs;
107118

108119
const o2::tpc::ClusterNativeAccess* ext = mChain->GetClusterNativeAccess();

0 commit comments

Comments
 (0)