Skip to content

Commit f37b22d

Browse files
[SYCL] Fix unqiue_ptr out-of-memory checks in scheduler (#4592)
Select places in the scheduler incorrectly assumes a unique pointer to be null when explicit allocations passed as parameter fails due to the host being out of memory. These changes correct these through the use of std::make_unique. Additionally, Scheduler::GraphBuilder::connectDepEvent assumed the same for a raw pointer, whilst not checking the creation of its constituent unique pointers. Allocation here is now governed by a catch of `std::bad_alloc`. Signed-off-by: Steffen Larsen <steffen.larsen@intel.com>
1 parent 95104c0 commit f37b22d

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

sycl/source/detail/scheduler/graph_builder.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ Scheduler::GraphBuilder::addCopyBack(Requirement *Req,
453453
AllocaCommandBase *SrcAllocaCmd =
454454
findAllocaForReq(Record, Req, Record->MCurContext);
455455

456-
std::unique_ptr<MemCpyCommandHost> MemCpyCmdUniquePtr(new MemCpyCommandHost(
456+
auto MemCpyCmdUniquePtr = std::make_unique<MemCpyCommandHost>(
457457
*SrcAllocaCmd->getRequirement(), SrcAllocaCmd, *Req, &Req->MData,
458-
SrcAllocaCmd->getQueue(), std::move(HostQueue)));
458+
SrcAllocaCmd->getQueue(), std::move(HostQueue));
459459

460460
if (!MemCpyCmdUniquePtr)
461461
throw runtime_error("Out of host memory", PI_OUT_OF_HOST_MEMORY);
@@ -886,8 +886,7 @@ Scheduler::GraphBuilder::addCG(std::unique_ptr<detail::CG> CommandGroup,
886886
const std::vector<detail::EventImplPtr> &Events = CommandGroup->MEvents;
887887
const CG::CGTYPE CGType = CommandGroup->getType();
888888

889-
std::unique_ptr<ExecCGCommand> NewCmd(
890-
new ExecCGCommand(std::move(CommandGroup), Queue));
889+
auto NewCmd = std::make_unique<ExecCGCommand>(std::move(CommandGroup), Queue);
891890
if (!NewCmd)
892891
throw runtime_error("Out of host memory", PI_OUT_OF_HOST_MEMORY);
893892

@@ -1183,7 +1182,7 @@ Command *Scheduler::GraphBuilder::connectDepEvent(Command *const Cmd,
11831182
// construct Host Task type command manually and make it depend on DepEvent
11841183
ExecCGCommand *ConnectCmd = nullptr;
11851184

1186-
{
1185+
try {
11871186
std::unique_ptr<detail::HostTask> HT(new detail::HostTask);
11881187
std::unique_ptr<detail::CG> ConnectCG(new detail::CGHostTask(
11891188
std::move(HT), /* Queue = */ {}, /* Context = */ {}, /* Args = */ {},
@@ -1193,10 +1192,9 @@ Command *Scheduler::GraphBuilder::connectDepEvent(Command *const Cmd,
11931192
/* Payload */ {}));
11941193
ConnectCmd = new ExecCGCommand(
11951194
std::move(ConnectCG), Scheduler::getInstance().getDefaultHostQueue());
1196-
}
1197-
1198-
if (!ConnectCmd)
1195+
} catch (const std::bad_alloc &) {
11991196
throw runtime_error("Out of host memory", PI_OUT_OF_HOST_MEMORY);
1197+
}
12001198

12011199
if (Command *DepCmd = reinterpret_cast<Command *>(DepEvent->getCommand()))
12021200
DepCmd->addUser(ConnectCmd);

0 commit comments

Comments
 (0)