Skip to content

[SYCL] Report exceptions during wait for dependencies of host-tasks #4087

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

Closed
wants to merge 2 commits into from
Closed
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
61 changes: 47 additions & 14 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class DispatchHostTask {
ExecCGCommand *MThisCmd;
std::vector<interop_handle::ReqToMem> MReqToMem;

void waitForEvents() const {
pi_result waitForEvents() const {
std::map<const detail::plugin *, std::vector<EventImplPtr>>
RequiredEventsPerPlugin;

Expand All @@ -185,26 +185,24 @@ class DispatchHostTask {
// other available job and resume once all required events are ready.
for (auto &PluginWithEvents : RequiredEventsPerPlugin) {
std::vector<RT::PiEvent> RawEvents = getPiEvents(PluginWithEvents.second);
PluginWithEvents.first->call<PiApiKind::piEventsWait>(RawEvents.size(),
RawEvents.data());
pi_result Error =
PluginWithEvents.first->call_nocheck<PiApiKind::piEventsWait>(
RawEvents.size(), RawEvents.data());

if (Error != PI_SUCCESS)
return Error;
}

// wait for dependency host events
// Wait for dependency host events.
// Host events can't throw exceptions so don't try to catch it.
for (const EventImplPtr &Event : MThisCmd->MPreparedHostDepsEvents) {
Event->waitInternal();
}
}

public:
DispatchHostTask(ExecCGCommand *ThisCmd,
std::vector<interop_handle::ReqToMem> ReqToMem)
: MThisCmd{ThisCmd}, MReqToMem(std::move(ReqToMem)) {}

void operator()() const {
waitForEvents();

assert(MThisCmd->getCG().getType() == CG::CGTYPE::CODEPLAY_HOST_TASK);
return PI_SUCCESS;
}

pi_result executeHostTask() const {
CGHostTask &HostTask = static_cast<CGHostTask &>(MThisCmd->getCG());

try {
Expand All @@ -219,10 +217,16 @@ class DispatchHostTask {
HostTask.MHostTask->call();
} catch (...) {
HostTask.MQueue->reportAsyncException(std::current_exception());

return PI_ERROR_UNKNOWN;
}

HostTask.MHostTask.reset();

return PI_SUCCESS;
}

void unblockGraph() const {
// unblock user empty command here
EmptyCommand *EmptyCmd = MThisCmd->MEmptyCmd;
assert(EmptyCmd && "No empty command found");
Expand All @@ -248,6 +252,35 @@ class DispatchHostTask {
Scheduler::enqueueLeavesOfReqUnlocked(Dep.MDepRequirement);
}
}

public:
DispatchHostTask(ExecCGCommand *ThisCmd,
std::vector<interop_handle::ReqToMem> ReqToMem)
: MThisCmd{ThisCmd}, MReqToMem(std::move(ReqToMem)) {}

void operator()() const {
assert(MThisCmd->getCG().getType() == CG::CGTYPE::CODEPLAY_HOST_TASK);

CGHostTask &HostTask = static_cast<CGHostTask &>(MThisCmd->getCG());

pi_result WaitResult = waitForEvents();
if (WaitResult != PI_SUCCESS) {
std::exception_ptr EPtr = std::make_exception_ptr(sycl::runtime_error(
std::string("Couldn't wait for host-task's dependencies"),
WaitResult));
HostTask.MQueue->reportAsyncException(EPtr);

// reset host-task's lambda and quit
HostTask.MHostTask.reset();
return;
}

if (executeHostTask() != PI_SUCCESS)
// The failure was reported already. No need to duplicate it here.
return;

unblockGraph();
}
};

void Command::waitForPreparedHostEvents() const {
Expand Down