-
Notifications
You must be signed in to change notification settings - Fork 739
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
mmoadeli
wants to merge
5
commits into
intel:sycl
Choose a base branch
from
mmoadeli:dependent-async-handler
base: sycl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[SYCL] wait_and_throw
invokes asynchronous handlers linked to the events that the event depends on.
#12202
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bf9a906
Invoke asynchronous handlers linked to the events; the occurrence of …
mmoadeli 89a25c0
Improve test to cover cases where the dependence comes from accessor …
mmoadeli fbeb80c
Use `sycl::read_write_host_task` for accessor creation.
mmoadeli b73e44b
Merge branch 'sycl' into dependent-async-handler
mmoadeli 81789cb
Add a test case for the situation where there is no dependency chain …
mmoadeli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
sycl/test-e2e/Basic/dependent_event_async_exception.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// 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")); | ||
} | ||
{ | ||
int data = 0; | ||
{ | ||
sycl::buffer<int, 1> Buf(&data, sycl::range<1>(1)); | ||
test_exception_handler teh1; | ||
test_exception_handler teh2; | ||
|
||
auto e1 = teh1.get_queue().submit([&](sycl::handler &cgh) { | ||
auto B = sycl::accessor(Buf, cgh, sycl::read_write_host_task); | ||
cgh.host_task([=]() { | ||
B[0] = 10; | ||
throw test_exception{"some-error"}; | ||
}); | ||
}); | ||
|
||
auto e2 = teh2.get_queue().submit([&](sycl::handler &cgh) { | ||
auto B = sycl::accessor(Buf, cgh, sycl::read_write_host_task); | ||
cgh.host_task([=]() { | ||
B[0] *= 10; | ||
throw test_exception{"another-error"}; | ||
}); | ||
}); | ||
|
||
e2.wait_and_throw(); | ||
|
||
assert(data == 100); | ||
assert(teh2.count() == 1); | ||
assert(teh2.has("another-error")); | ||
|
||
assert(teh1.count() == 1); | ||
assert(teh1.has("some-error")); | ||
} | ||
} | ||
{ | ||
int data1 = 0, data2 = 0; | ||
{ | ||
sycl::buffer<int, 1> Buf1(&data1, sycl::range<1>(1)); | ||
sycl::buffer<int, 1> Buf2(&data2, sycl::range<1>(1)); | ||
test_exception_handler teh; | ||
|
||
auto e1 = teh.get_queue().submit([&](sycl::handler &cgh) { | ||
auto B = sycl::accessor(Buf1, cgh, sycl::read_write_host_task); | ||
cgh.host_task([=]() { | ||
B[0] = 10; | ||
throw test_exception{"some-error"}; | ||
}); | ||
}); | ||
|
||
auto e2 = teh.get_queue().submit([&](sycl::handler &cgh) { | ||
auto B = sycl::accessor(Buf2, cgh, sycl::read_write_host_task); | ||
cgh.host_task([=]() { | ||
B[0] = 20; | ||
throw test_exception{"another-error"}; | ||
}); | ||
}); | ||
|
||
e2.wait_and_throw(); | ||
|
||
assert(data1 == 10); | ||
assert(data2 == 20); | ||
assert(teh.count() == 2); | ||
assert(teh.has("another-error")); | ||
assert(teh.has("some-error")); | ||
} | ||
} | ||
} | ||
steffenlarsen marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could be worth also having a test for the case that @gmlueck highlighted in the spec PR where there is no dependency chain between the two kernels but they are enqueued to the same queue.
It was decided that in this case we should all errors caught by the
queue
, so if there is a call towait
on thequeue
then both exceptions should be thrown.