@@ -91,7 +91,7 @@ void GPURecoWorkflowSpec::RunWorkerThread(int id)
9191 context = workerContext.inputQueue .front ();
9292 workerContext.inputQueue .pop ();
9393 }
94- context->jobReturnValue = runMain (nullptr , context->jobPtrs , context->jobOutputRegions , id);
94+ context->jobReturnValue = runMain (nullptr , context->jobPtrs , context->jobOutputRegions , id, context-> jobInputUpdateCallback . get () );
9595 {
9696 std::lock_guard lk (context->jobFinishedMutex );
9797 context->jobFinished = true ;
@@ -100,11 +100,37 @@ void GPURecoWorkflowSpec::RunWorkerThread(int id)
100100 }
101101}
102102
103- void GPURecoWorkflowSpec::enqueuePipelinedJob (GPUTrackingInOutPointers* ptrs, GPUInterfaceOutputs* outputRegions, GPURecoWorkflow_QueueObject* context)
103+ void GPURecoWorkflowSpec::enqueuePipelinedJob (GPUTrackingInOutPointers* ptrs, GPUInterfaceOutputs* outputRegions, GPURecoWorkflow_QueueObject* context, bool inputFinal )
104104{
105+ {
106+ std::unique_lock lk (mPipeline ->mayInjectMutex );
107+ mPipeline ->mayInjectCondition .wait (lk, [this , context]() { return mPipeline ->mayInject && mPipeline ->mayInjectTFId == context->mTFId ; });
108+ mPipeline ->mayInjectTFId ++;
109+ mPipeline ->mayInject = false ;
110+ }
105111 context->jobSubmitted = true ;
112+ context->jobInputFinal = inputFinal;
106113 context->jobPtrs = ptrs;
107114 context->jobOutputRegions = outputRegions;
115+
116+ context->jobInputUpdateCallback = std::make_unique<GPUInterfaceInputUpdate>();
117+
118+ if (!inputFinal) {
119+ context->jobInputUpdateCallback ->callback = [context](GPUTrackingInOutPointers*& data, GPUInterfaceOutputs*& outputs) {
120+ std::unique_lock lk (context->jobInputFinalMutex );
121+ context->jobInputFinalNotify .wait (lk, [context]() { return context->jobInputFinal ; });
122+ data = context->jobPtrs ;
123+ outputs = context->jobOutputRegions ;
124+ };
125+ }
126+ context->jobInputUpdateCallback ->notifyCallback = [this ]() {
127+ {
128+ std::lock_guard lk (mPipeline ->mayInjectMutex );
129+ mPipeline ->mayInject = true ;
130+ }
131+ mPipeline ->mayInjectCondition .notify_one ();
132+ };
133+
108134 mNextThreadIndex = (mNextThreadIndex + 1 ) % 2 ;
109135
110136 {
@@ -114,6 +140,17 @@ void GPURecoWorkflowSpec::enqueuePipelinedJob(GPUTrackingInOutPointers* ptrs, GP
114140 mPipeline ->workers [mNextThreadIndex ].inputQueueNotify .notify_one ();
115141}
116142
143+ void GPURecoWorkflowSpec::finalizeInputPipelinedJob (GPUTrackingInOutPointers* ptrs, GPUInterfaceOutputs* outputRegions, GPURecoWorkflow_QueueObject* context)
144+ {
145+ {
146+ std::lock_guard lk (context->jobInputFinalMutex );
147+ context->jobPtrs = ptrs;
148+ context->jobOutputRegions = outputRegions;
149+ context->jobInputFinal = true ;
150+ }
151+ context->jobInputFinalNotify .notify_one ();
152+ }
153+
117154int GPURecoWorkflowSpec::handlePipeline (ProcessingContext& pc, GPUTrackingInOutPointers& ptrs, GPURecoWorkflowSpec_TPCZSBuffers& tpcZSmeta, o2::gpu::GPUTrackingInOutZS& tpcZS, std::unique_ptr<GPURecoWorkflow_QueueObject>& context)
118155{
119156 auto * device = pc.services ().get <RawDeviceService>().device ();
@@ -246,9 +283,9 @@ void GPURecoWorkflowSpec::RunReceiveThread()
246283 break ;
247284 }
248285
249- auto o = std::make_unique<GPURecoWorkflow_QueueObject>();
250- o ->timeSliceId = m->timeSliceId ;
251- o ->tfSettings = m->tfSettings ;
286+ auto context = std::make_unique<GPURecoWorkflow_QueueObject>();
287+ context ->timeSliceId = m->timeSliceId ;
288+ context ->tfSettings = m->tfSettings ;
252289
253290 size_t regionOffset = 0 ;
254291 if (m->pointersTotal ) {
@@ -263,29 +300,34 @@ void GPURecoWorkflowSpec::RunReceiveThread()
263300 }
264301 size_t ptrsCopied = 0 ;
265302 size_t * ptrBuffer = (size_t *)msg->GetData () + sizeof (pipelinePrepareMessage) / sizeof (size_t );
266- o ->tpcZSmeta .Pointers [0 ][0 ].resize (m->pointersTotal );
267- o ->tpcZSmeta .Sizes [0 ][0 ].resize (m->pointersTotal );
303+ context ->tpcZSmeta .Pointers [0 ][0 ].resize (m->pointersTotal );
304+ context ->tpcZSmeta .Sizes [0 ][0 ].resize (m->pointersTotal );
268305 for (unsigned int i = 0 ; i < GPUTrackingInOutZS::NSLICES ; i++) {
269306 for (unsigned int j = 0 ; j < GPUTrackingInOutZS::NENDPOINTS ; j++) {
270- o ->tpcZS .slice [i].count [j] = m->pointerCounts [i][j];
271- for (unsigned int k = 0 ; k < o ->tpcZS .slice [i].count [j]; k++) {
272- o ->tpcZSmeta .Pointers [0 ][0 ][ptrsCopied + k] = (void *)(ptrBuffer[ptrsCopied + k] + regionOffset);
273- o ->tpcZSmeta .Sizes [0 ][0 ][ptrsCopied + k] = ptrBuffer[m->pointersTotal + ptrsCopied + k];
307+ context ->tpcZS .slice [i].count [j] = m->pointerCounts [i][j];
308+ for (unsigned int k = 0 ; k < context ->tpcZS .slice [i].count [j]; k++) {
309+ context ->tpcZSmeta .Pointers [0 ][0 ][ptrsCopied + k] = (void *)(ptrBuffer[ptrsCopied + k] + regionOffset);
310+ context ->tpcZSmeta .Sizes [0 ][0 ][ptrsCopied + k] = ptrBuffer[m->pointersTotal + ptrsCopied + k];
274311 }
275- o ->tpcZS .slice [i].zsPtr [j] = o ->tpcZSmeta .Pointers [0 ][0 ].data () + ptrsCopied;
276- o ->tpcZS .slice [i].nZSPtr [j] = o ->tpcZSmeta .Sizes [0 ][0 ].data () + ptrsCopied;
277- ptrsCopied += o ->tpcZS .slice [i].count [j];
312+ context ->tpcZS .slice [i].zsPtr [j] = context ->tpcZSmeta .Pointers [0 ][0 ].data () + ptrsCopied;
313+ context ->tpcZS .slice [i].nZSPtr [j] = context ->tpcZSmeta .Sizes [0 ][0 ].data () + ptrsCopied;
314+ ptrsCopied += context ->tpcZS .slice [i].count [j];
278315 }
279316 }
280- o->ptrs .tpcZS = &o->tpcZS ;
317+ context->ptrs .tpcZS = &context->tpcZS ;
318+ context->ptrs .settingsTF = &context->tfSettings ;
319+ context->mTFId = mPipeline ->mNTFReceived ;
320+ if (mPipeline ->mNTFReceived ++ >= mPipeline ->workers .size ()) { // Do not inject the first 2 TF, since we need a first round of calib updates from DPL before starting
321+ enqueuePipelinedJob (&context->ptrs , nullptr , context.get (), false );
322+ }
281323 {
282324 std::lock_guard lk (mPipeline ->completionPolicyMutex );
283325 mPipeline ->completionPolicyQueue .emplace (m->timeSliceId );
284326 }
285327 mPipeline ->completionPolicyNotify .notify_one ();
286328 {
287329 std::lock_guard lk (mPipeline ->queueMutex );
288- mPipeline ->pipelineQueue .emplace (std::move (o ));
330+ mPipeline ->pipelineQueue .emplace (std::move (context ));
289331 }
290332 mPipeline ->queueNotify .notify_one ();
291333 }
0 commit comments