Skip to content

Commit 4456424

Browse files
committed
GPU Interface: Support a callback for providing final set of inputs and output buffer late, to be propagated to GPUReconstruciton only after running TPC Clusterization
1 parent 8c6f3ae commit 4456424

3 files changed

Lines changed: 43 additions & 10 deletions

File tree

GPU/GPUTracking/Interface/GPUO2Interface.cxx

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,50 @@ void GPUO2Interface::DumpSettings()
163163
mCtx[0].mRec->DumpSettings();
164164
}
165165

166-
int GPUO2Interface::RunTracking(GPUTrackingInOutPointers* data, GPUInterfaceOutputs* outputs, unsigned int iThread)
166+
int GPUO2Interface::RunTracking(GPUTrackingInOutPointers* data, GPUInterfaceOutputs* outputs, unsigned int iThread, GPUInterfaceInputUpdate* inputUpdateCallback)
167167
{
168168
if (mNContexts <= iThread) {
169169
return (1);
170170
}
171171

172172
mCtx[iThread].mChain->mIOPtrs = *data;
173-
if (mConfig->configInterface.outputToExternalBuffers) {
174-
for (unsigned int i = 0; i < mCtx[iThread].mOutputRegions->count(); i++) {
175-
if (outputs->asArray()[i].allocator) {
176-
mCtx[iThread].mOutputRegions->asArray()[i].set(outputs->asArray()[i].allocator);
177-
} else if (outputs->asArray()[i].ptrBase) {
178-
mCtx[iThread].mOutputRegions->asArray()[i].set(outputs->asArray()[i].ptrBase, outputs->asArray()[i].size);
179-
} else {
180-
mCtx[iThread].mOutputRegions->asArray()[i].reset();
173+
174+
auto setOutputs = [this, iThread](GPUInterfaceOutputs* outputs) {
175+
if (mConfig->configInterface.outputToExternalBuffers) {
176+
for (unsigned int i = 0; i < mCtx[iThread].mOutputRegions->count(); i++) {
177+
if (outputs->asArray()[i].allocator) {
178+
mCtx[iThread].mOutputRegions->asArray()[i].set(outputs->asArray()[i].allocator);
179+
} else if (outputs->asArray()[i].ptrBase) {
180+
mCtx[iThread].mOutputRegions->asArray()[i].set(outputs->asArray()[i].ptrBase, outputs->asArray()[i].size);
181+
} else {
182+
mCtx[iThread].mOutputRegions->asArray()[i].reset();
183+
}
181184
}
182185
}
186+
};
187+
188+
auto inputWaitCallback = [this, iThread, inputUpdateCallback, &data, &outputs, &setOutputs]() {
189+
GPUTrackingInOutPointers* updatedData;
190+
GPUInterfaceOutputs* updatedOutputs;
191+
if (inputUpdateCallback->callback) {
192+
inputUpdateCallback->callback(updatedData, updatedOutputs);
193+
mCtx[iThread].mChain->mIOPtrs = *updatedData;
194+
outputs = updatedOutputs;
195+
data = updatedData;
196+
setOutputs(outputs);
197+
}
198+
if (inputUpdateCallback->notifyCallback) {
199+
inputUpdateCallback->notifyCallback();
200+
}
201+
};
202+
203+
if (inputUpdateCallback) {
204+
mCtx[iThread].mChain->SetFinalInputCallback(inputWaitCallback);
205+
} else {
206+
mCtx[iThread].mChain->SetFinalInputCallback(nullptr);
207+
}
208+
if (!inputUpdateCallback || !inputUpdateCallback->callback) {
209+
setOutputs(outputs);
183210
}
184211

185212
int retVal = mCtx[iThread].mRec->RunChains();

GPU/GPUTracking/Interface/GPUO2Interface.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class GPUChainTracking;
5454
class GPUChainITS;
5555
struct GPUO2InterfaceConfiguration;
5656
struct GPUInterfaceOutputs;
57+
struct GPUInterfaceInputUpdate;
5758
struct GPUTrackingOutputs;
5859
struct GPUConstantMem;
5960
struct GPUNewCalibValues;
@@ -70,7 +71,7 @@ class GPUO2Interface
7071
int Initialize(const GPUO2InterfaceConfiguration& config);
7172
void Deinitialize();
7273

73-
int RunTracking(GPUTrackingInOutPointers* data, GPUInterfaceOutputs* outputs = nullptr, unsigned int iThread = 0);
74+
int RunTracking(GPUTrackingInOutPointers* data, GPUInterfaceOutputs* outputs = nullptr, unsigned int iThread = 0, GPUInterfaceInputUpdate* inputUpdateCallback = nullptr);
7475
void Clear(bool clearOutputs, unsigned int iThread = 0);
7576
void DumpEvent(int nEvent, GPUTrackingInOutPointers* data);
7677
void DumpSettings();

GPU/GPUTracking/Interface/GPUO2InterfaceConfiguration.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ struct GPUInterfaceOutputs : public GPUTrackingOutputs {
6666
GPUInterfaceQAOutputs qa;
6767
};
6868

69+
struct GPUInterfaceInputUpdate {
70+
std::function<void(GPUTrackingInOutPointers*& data, GPUInterfaceOutputs*& outputs)> callback; // Callback which provides final data ptrs / outputRegions after Clusterization stage
71+
std::function<void()> notifyCallback; // Callback called to notify that Clusterization state has finished without update
72+
};
73+
6974
// Full configuration structure with all available settings of GPU...
7075
struct GPUO2InterfaceConfiguration {
7176
GPUO2InterfaceConfiguration() = default;

0 commit comments

Comments
 (0)