Skip to content

Commit 62ca43a

Browse files
[SYCL] Fix unsafe command usage (#5789)
Command may be destroyed by cleanup process in another thread Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent 62651dd commit 62ca43a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

sycl/source/detail/scheduler/scheduler.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,18 @@ void Scheduler::removeMemoryObject(detail::SYCLMemObjI *MemObj) {
291291

292292
EventImplPtr Scheduler::addHostAccessor(Requirement *Req) {
293293
std::vector<Command *> AuxiliaryCmds;
294-
Command *NewCmd = nullptr;
294+
EventImplPtr NewCmdEvent = nullptr;
295295

296296
{
297297
WriteLockT Lock(MGraphLock, std::defer_lock);
298298
acquireWriteLock(Lock);
299299

300-
NewCmd = MGraphBuilder.addHostAccessor(Req, AuxiliaryCmds);
300+
Command *NewCmd = MGraphBuilder.addHostAccessor(Req, AuxiliaryCmds);
301+
if (!NewCmd)
302+
return nullptr;
303+
NewCmdEvent = NewCmd->getEvent();
301304
}
302305

303-
if (!NewCmd)
304-
return nullptr;
305-
306306
std::vector<Command *> ToCleanUp;
307307
{
308308
ReadLockT ReadLock(MGraphLock);
@@ -315,14 +315,15 @@ EventImplPtr Scheduler::addHostAccessor(Requirement *Req) {
315315
throw runtime_error("Enqueue process failed.", PI_INVALID_OPERATION);
316316
}
317317

318-
Enqueued = GraphProcessor::enqueueCommand(NewCmd, Res, ToCleanUp);
319-
if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult)
320-
throw runtime_error("Enqueue process failed.", PI_INVALID_OPERATION);
318+
if (Command *NewCmd = static_cast<Command *>(NewCmdEvent->getCommand())) {
319+
Enqueued = GraphProcessor::enqueueCommand(NewCmd, Res, ToCleanUp);
320+
if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult)
321+
throw runtime_error("Enqueue process failed.", PI_INVALID_OPERATION);
322+
}
321323
}
322324

323-
EventImplPtr NewEvent = NewCmd->getEvent();
324325
cleanupCommands(ToCleanUp);
325-
return NewEvent;
326+
return NewCmdEvent;
326327
}
327328

328329
void Scheduler::releaseHostAccessor(Requirement *Req) {

0 commit comments

Comments
 (0)