Skip to content
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

[SYCL] wait_and_throw invokes asynchronous handlers linked to the events that the event depends on. #12202

Open
wants to merge 5 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ void event_impl::wait_and_throw(
std::shared_ptr<sycl::detail::event_impl> Self) {
wait(Self);

auto WaitList = getWaitList();
for (const auto &Event : WaitList) {
Event->getSubmittedQueue()->throw_asynchronous();
}

if (QueueImplPtr SubmittedQueue = MSubmittedQueue.lock())
SubmittedQueue->throw_asynchronous();
}
Expand Down
74 changes: 74 additions & 0 deletions sycl/test-e2e/Basic/dependent_event_async_exception.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// RUN: %{build} -o %t.out
// RUN: %{run} %t.out

//==----- dependent_event_async_exception.cpp - Test for event async exceptions
//-----==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <sycl/sycl.hpp>
#include <unordered_set>

struct test_exception {
std::string name;
};

class test_exception_handler {
public:
test_exception_handler()
: queue{[this](sycl::exception_list el) { capture(std::move(el)); }} {}
sycl::queue &get_queue() { return queue; }

bool has(const std::string &name) const {
return captured_exceptions.count(name) != 0;
}

size_t count() const { return captured_exceptions.size(); }

void clear() { captured_exceptions.clear(); }

private:
std::unordered_set<std::string> captured_exceptions;
sycl::queue queue;

void capture(sycl::exception_list el) {
for (auto &e : el) {
try {
std::rethrow_exception(e);
} catch (test_exception &te) {
captured_exceptions.insert(te.name);
}
}
}
};

static sycl::event
make_throwing_host_event(sycl::queue &queue, std::string name,
const std::vector<sycl::event> &dependencies = {}) {
return queue.submit([name, &dependencies](sycl::handler &cgh) {
for (auto &dep : dependencies) {
cgh.depends_on(dep);
}
cgh.host_task([name](auto) { throw test_exception{name}; });
});
}

int main() {
test_exception_handler teh1;
test_exception_handler teh2;

auto e1 = make_throwing_host_event(teh1.get_queue(), "some-error");
auto e2 = make_throwing_host_event(teh2.get_queue(), "another-error", {e1});

e2.wait_and_throw();

assert(teh2.count() == 1);
assert(teh2.has("another-error"));

assert(teh1.count() == 1);
assert(teh1.has("some-error"));
}
steffenlarsen marked this conversation as resolved.
Show resolved Hide resolved