diff --git a/sycl/source/detail/scheduler/graph_builder.cpp b/sycl/source/detail/scheduler/graph_builder.cpp index c59aa11046e1a..116f3a3f98d14 100644 --- a/sycl/source/detail/scheduler/graph_builder.cpp +++ b/sycl/source/detail/scheduler/graph_builder.cpp @@ -453,9 +453,9 @@ Scheduler::GraphBuilder::addCopyBack(Requirement *Req, AllocaCommandBase *SrcAllocaCmd = findAllocaForReq(Record, Req, Record->MCurContext); - std::unique_ptr MemCpyCmdUniquePtr(new MemCpyCommandHost( + auto MemCpyCmdUniquePtr = std::make_unique( *SrcAllocaCmd->getRequirement(), SrcAllocaCmd, *Req, &Req->MData, - SrcAllocaCmd->getQueue(), std::move(HostQueue))); + SrcAllocaCmd->getQueue(), std::move(HostQueue)); if (!MemCpyCmdUniquePtr) throw runtime_error("Out of host memory", PI_OUT_OF_HOST_MEMORY); @@ -886,8 +886,7 @@ Scheduler::GraphBuilder::addCG(std::unique_ptr CommandGroup, const std::vector &Events = CommandGroup->MEvents; const CG::CGTYPE CGType = CommandGroup->getType(); - std::unique_ptr NewCmd( - new ExecCGCommand(std::move(CommandGroup), Queue)); + auto NewCmd = std::make_unique(std::move(CommandGroup), Queue); if (!NewCmd) throw runtime_error("Out of host memory", PI_OUT_OF_HOST_MEMORY); @@ -1183,7 +1182,7 @@ Command *Scheduler::GraphBuilder::connectDepEvent(Command *const Cmd, // construct Host Task type command manually and make it depend on DepEvent ExecCGCommand *ConnectCmd = nullptr; - { + try { std::unique_ptr HT(new detail::HostTask); std::unique_ptr ConnectCG(new detail::CGHostTask( std::move(HT), /* Queue = */ {}, /* Context = */ {}, /* Args = */ {}, @@ -1193,10 +1192,9 @@ Command *Scheduler::GraphBuilder::connectDepEvent(Command *const Cmd, /* Payload */ {})); ConnectCmd = new ExecCGCommand( std::move(ConnectCG), Scheduler::getInstance().getDefaultHostQueue()); - } - - if (!ConnectCmd) + } catch (const std::bad_alloc &) { throw runtime_error("Out of host memory", PI_OUT_OF_HOST_MEMORY); + } if (Command *DepCmd = reinterpret_cast(DepEvent->getCommand())) DepCmd->addUser(ConnectCmd);