-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathupon_error.cpp
83 lines (65 loc) · 2.39 KB
/
upon_error.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <catch2/catch.hpp>
#include <stdexec/execution.hpp>
#include "nvexec/stream_context.cuh"
#include "common.cuh"
#include "test_common/type_helpers.hpp"
namespace ex = stdexec;
using nvexec::is_on_gpu;
namespace {
TEST_CASE("nvexec upon_error returns a sender", "[cuda][stream][adaptors][upon_error]") {
nvexec::stream_context stream_ctx{};
auto snd = ex::just_error(42) | ex::continues_on(stream_ctx.get_scheduler())
| ex::upon_error([](int) { });
STATIC_REQUIRE(ex::sender<decltype(snd)>);
(void) snd;
}
TEST_CASE("nvexec upon_error executes on GPU", "[cuda][stream][adaptors][upon_error]") {
nvexec::stream_context stream_ctx{};
flags_storage_t flags_storage{};
auto flags = flags_storage.get();
auto snd = ex::just_error(42) | ex::continues_on(stream_ctx.get_scheduler())
| ex::upon_error([=](int err) {
if (is_on_gpu() && err == 42) {
flags.set();
}
});
stdexec::sync_wait(std::move(snd));
REQUIRE(flags_storage.all_set_once());
}
TEST_CASE(
"upon_error can preceed a sender without values",
"[cuda][stream][adaptors][upon_error]") {
nvexec::stream_context stream_ctx{};
flags_storage_t<2> flags_storage{};
auto flags = flags_storage.get();
auto snd = ex::just_error(42) | ex::continues_on(stream_ctx.get_scheduler())
| ex::upon_error([=](int err) {
if (is_on_gpu() && err == 42) {
flags.set(0);
}
})
| a_sender([=]() noexcept {
if (is_on_gpu()) {
flags.set(1);
}
});
stdexec::sync_wait(std::move(snd));
REQUIRE(flags_storage.all_set_once());
}
TEST_CASE(
"upon_error can succeed a sender without values",
"[cuda][stream][adaptors][upon_error]") {
nvexec::stream_context stream_ctx{};
flags_storage_t flags_storage{};
auto flags = flags_storage.get();
auto snd = ex::just_error(42) | ex::continues_on(stream_ctx.get_scheduler())
| a_sender([=]() noexcept {}) //
| ex::upon_error([=](int err) noexcept {
if (is_on_gpu() && err == 42) {
flags.set();
}
});
stdexec::sync_wait(std::move(snd));
REQUIRE(flags_storage.all_set_once());
}
} // namespace