Skip to content

[SYCL] Fix unqiue_ptr out-of-memory checks in scheduler #4592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions sycl/source/detail/scheduler/graph_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ Scheduler::GraphBuilder::addCopyBack(Requirement *Req,
AllocaCommandBase *SrcAllocaCmd =
findAllocaForReq(Record, Req, Record->MCurContext);

std::unique_ptr<MemCpyCommandHost> MemCpyCmdUniquePtr(new MemCpyCommandHost(
auto MemCpyCmdUniquePtr = std::make_unique<MemCpyCommandHost>(
*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);
Expand Down Expand Up @@ -886,8 +886,7 @@ Scheduler::GraphBuilder::addCG(std::unique_ptr<detail::CG> CommandGroup,
const std::vector<detail::EventImplPtr> &Events = CommandGroup->MEvents;
const CG::CGTYPE CGType = CommandGroup->getType();

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

Expand Down Expand Up @@ -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<detail::HostTask> HT(new detail::HostTask);
std::unique_ptr<detail::CG> ConnectCG(new detail::CGHostTask(
std::move(HT), /* Queue = */ {}, /* Context = */ {}, /* Args = */ {},
Expand All @@ -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<Command *>(DepEvent->getCommand()))
DepCmd->addUser(ConnectCmd);
Expand Down