Skip to content

Commit 59d2a56

Browse files
committed
GPU SA MultiThreading: Run async receiveThread only once DPL invoked run() the first time to make sure everything is initialized
1 parent cc1a009 commit 59d2a56

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

GPU/Workflow/src/GPUWorkflowInternal.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ struct GPURecoWorkflowSpec_PipelineInternals {
6363
fair::mq::Device* fmqDevice = nullptr;
6464

6565
fair::mq::State fmqState = fair::mq::State::Undefined;
66-
bool endOfStreamReceived = false;
67-
std::mutex fmqStateMutex;
68-
std::condition_variable fmqStateCheckNotify;
66+
volatile bool endOfStreamReceived = false;
67+
volatile bool runStarted = false;
68+
volatile bool shouldTerminate = false;
69+
std::mutex stateMutex;
70+
std::condition_variable stateNotify;
6971

7072
std::thread receiveThread;
71-
std::mutex threadMutex;
72-
volatile bool shouldTerminate = false;
7373

7474
struct pipelineWorkerStruct {
7575
std::thread thread;

GPU/Workflow/src/GPUWorkflowPipeline.cxx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ void GPURecoWorkflowSpec::finalizeInputPipelinedJob(GPUTrackingInOutPointers* pt
156156

157157
int GPURecoWorkflowSpec::handlePipeline(ProcessingContext& pc, GPUTrackingInOutPointers& ptrs, GPURecoWorkflowSpec_TPCZSBuffers& tpcZSmeta, o2::gpu::GPUTrackingInOutZS& tpcZS, std::unique_ptr<GPURecoWorkflow_QueueObject>& context)
158158
{
159+
mPipeline->runStarted = true;
160+
mPipeline->stateNotify.notify_all();
161+
159162
auto* device = pc.services().get<RawDeviceService>().device();
160163
const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
161164
if (mSpecConfig.enableDoublePipeline == 1) {
@@ -239,11 +242,8 @@ int GPURecoWorkflowSpec::handlePipeline(ProcessingContext& pc, GPUTrackingInOutP
239242
void GPURecoWorkflowSpec::handlePipelineEndOfStream(EndOfStreamContext& ec)
240243
{
241244
if (mSpecConfig.enableDoublePipeline == 1) {
242-
{
243-
std::lock_guard lk(mPipeline->fmqStateMutex);
244-
mPipeline->endOfStreamReceived = true;
245-
}
246-
mPipeline->fmqStateCheckNotify.notify_all();
245+
mPipeline->endOfStreamReceived = true;
246+
mPipeline->stateNotify.notify_all();
247247
}
248248
if (mSpecConfig.enableDoublePipeline == 2) {
249249
auto* device = ec.services().get<RawDeviceService>().device();
@@ -260,7 +260,7 @@ void GPURecoWorkflowSpec::handlePipelineEndOfStream(EndOfStreamContext& ec)
260260
void GPURecoWorkflowSpec::receiveFMQStateCallback(fair::mq::State newState)
261261
{
262262
{
263-
std::lock_guard lk(mPipeline->fmqStateMutex);
263+
std::lock_guard lk(mPipeline->stateMutex);
264264
if (mPipeline->fmqState != fair::mq::State::Running && newState == fair::mq::State::Running) {
265265
mPipeline->endOfStreamReceived = false;
266266
}
@@ -269,7 +269,7 @@ void GPURecoWorkflowSpec::receiveFMQStateCallback(fair::mq::State newState)
269269
mPipeline->fmqDevice->UnsubscribeFromStateChange(GPURecoWorkflowSpec_FMQCallbackKey);
270270
}
271271
}
272-
mPipeline->fmqStateCheckNotify.notify_all();
272+
mPipeline->stateNotify.notify_all();
273273
}
274274

275275
void GPURecoWorkflowSpec::RunReceiveThread()
@@ -282,8 +282,8 @@ void GPURecoWorkflowSpec::RunReceiveThread()
282282
LOG(debug) << "Waiting for out of band message";
283283
do {
284284
{
285-
std::unique_lock lk(mPipeline->fmqStateMutex);
286-
mPipeline->fmqStateCheckNotify.wait(lk, [this]() { return (mPipeline->fmqState == fair::mq::State::Running && !mPipeline->endOfStreamReceived) || mPipeline->shouldTerminate; }); // Do not check mPipeline->fmqDevice->NewStatePending() since we wait for EndOfStream!
285+
std::unique_lock lk(mPipeline->stateMutex);
286+
mPipeline->stateNotify.wait(lk, [this]() { return (mPipeline->runStarted && mPipeline->fmqState == fair::mq::State::Running && !mPipeline->endOfStreamReceived) || mPipeline->shouldTerminate; }); // Do not check mPipeline->fmqDevice->NewStatePending() since we wait for EndOfStream!
287287
}
288288
if (mPipeline->shouldTerminate) {
289289
break;
@@ -309,8 +309,10 @@ void GPURecoWorkflowSpec::RunReceiveThread()
309309
}
310310
if (m->flagEndOfStream) {
311311
LOG(info) << "Received end-of-stream from out-of-band channel";
312+
std::lock_guard lk(mPipeline->stateMutex);
312313
mPipeline->endOfStreamReceived = true;
313314
mPipeline->mNTFReceived = 0;
315+
mPipeline->runStarted = false;
314316
continue;
315317
}
316318

@@ -379,7 +381,7 @@ void GPURecoWorkflowSpec::ExitPipeline()
379381
if (mSpecConfig.enableDoublePipeline == 1 && mPipeline->fmqDevice) {
380382
mPipeline->fmqDevice = nullptr;
381383
mPipeline->shouldTerminate = true;
382-
mPipeline->fmqStateCheckNotify.notify_all();
384+
mPipeline->stateNotify.notify_all();
383385
for (unsigned int i = 0; i < mPipeline->workers.size(); i++) {
384386
mPipeline->workers[i].inputQueueNotify.notify_one();
385387
}

0 commit comments

Comments
 (0)