Skip to content

[SYCL] Fast launch of kernels that have no dependencies #4188

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
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions sycl/source/detail/scheduler/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ class ExecCGCommand : public Command {
std::unique_ptr<detail::CG> MCommandGroup;

friend class Command;
friend class Scheduler;
};

class UpdateHostRequirementCommand : public Command {
Expand Down
53 changes: 53 additions & 0 deletions sycl/source/detail/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,59 @@ EventImplPtr Scheduler::addCG(std::unique_ptr<detail::CG> CommandGroup,
initStream(Stream, Queue);
}
}

if (CommandGroup->MRequirements.size() + CommandGroup->MEvents.size() ==
0) {
ExecCGCommand *NewCmd(
new ExecCGCommand(std::move(CommandGroup), std::move(Queue)));
if (!NewCmd)
throw runtime_error("Out of host memory", PI_OUT_OF_HOST_MEMORY);
NewEvent = NewCmd->getEvent();

auto CleanUp = [&]() {
NewEvent->setCommand(nullptr);
delete NewCmd;
};

if (MGraphBuilder
.MPrintOptionsArray[GraphBuilder::PrintOptions::BeforeAddCG])
MGraphBuilder.printGraphAsDot("before_addCG");
if (MGraphBuilder
.MPrintOptionsArray[GraphBuilder::PrintOptions::AfterAddCG])
MGraphBuilder.printGraphAsDot("after_addCG");

try {
#ifdef XPTI_ENABLE_INSTRUMENTATION
NewCmd->emitInstrumentation(xpti::trace_task_begin, nullptr);
#endif

cl_int Res = NewCmd->enqueueImp();

// Emit this correlation signal before the task end
NewCmd->emitEnqueuedEventSignal(NewEvent->getHandleRef());
#ifdef XPTI_ENABLE_INSTRUMENTATION
NewCmd->emitInstrumentation(xpti::trace_task_end, nullptr);
#endif

if (CL_SUCCESS != Res)
throw runtime_error("Enqueue process failed.", PI_INVALID_OPERATION);
else if (NewEvent->is_host() || NewEvent->getHandleRef() == nullptr)
NewEvent->setComplete();
} catch (...) {
// enqueueImp() func and if statement above may throw an exception,
// so destroy required resources to avoid memory leak
CleanUp();
std::rethrow_exception(std::current_exception());
}

CleanUp();

for (auto StreamImplPtr : Streams) {
StreamImplPtr->flush();
}

return NewEvent;
}
}

{
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/scheduler/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ class Scheduler {
const ContextImplPtr &Context);

friend class Command;
friend class Scheduler;

private:
friend class ::MockScheduler;
Expand Down