kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
example_hydra.cpp
Go to the documentation of this file.
1
#include "
kokkos-execution/graph.hpp
"
2
3
#include "
kokkos-utils/tests/scoped/ExecutionSpace.hpp
"
4
19
20
namespace
Examples::Graph
{
21
22
template
<
typename
ViewType,
char
Value, std::
size_t
Index>
23
struct
Write
{
24
ViewType
data
;
25
26
KOKKOS_FUNCTION
void
operator()
() const noexcept {
27
data
(Index) = Value;
28
}
29
};
30
31
template
<Kokkos::ExecutionSpace Exec>
32
struct
Hydra
:
public
Kokkos::utils::tests::scoped::ExecutionSpace
<Exec> {
33
public
:
34
using
base_t
=
Kokkos::utils::tests::scoped::ExecutionSpace<Exec>
;
35
37
static
constexpr
std::string_view
pattern
=
"SORRY HERACLES"
;
38
40
using
view_t
= Kokkos::View<
char
[
pattern
.size() + 1], Exec>;
41
42
public
:
43
Hydra
()
44
:
base_t
()
45
,
data
(
Kokkos
::view_alloc(this->
exec
,
"data"
)) {
46
}
47
48
void
check
()
const
{
49
const
auto
mirror = Kokkos::create_mirror_view_and_copy(
data
);
50
const
std::string_view got{mirror.data(),
pattern
.size()};
51
52
std::printf(
// NOLINT(modernize-use-std-print)
53
"%s\n"
,
54
std::format(
55
"The Lernaean hydra has {} heads. They all spoke at once, inside the graph, and said: '{}'."
,
56
pattern
.size(),
57
got)
58
.c_str());
59
60
if
(got !=
pattern
)
61
throw
std::runtime_error(
62
std::format(
63
"Heracles got to a head: got '{}', expected '{}'. Fetch Iolaus and a torch."
, got,
pattern
));
64
65
std::printf(
// NOLINT(modernize-use-std-print)
66
"Every head survived the labours. Want a bigger monster? Add characters to 'pattern'.\n"
);
67
}
68
69
void
run
()
const
{
70
const
Kokkos::Execution::GraphContext<Exec>
gctx{this->
exec
};
71
72
auto
sndr = [&]<std::size_t... Is>(std::index_sequence<Is...>) {
73
return
stdexec::when_all(
74
(stdexec::schedule(gctx.
get_scheduler
())
75
| stdexec::then(
Write
<
view_t
,
pattern
.at(Is), Is>{.data = data}))...);
76
}(std::make_index_sequence<
pattern
.size()>{});
77
79
this->
exec
.fence();
80
81
stdexec::sync_wait(std::move(sndr));
82
83
check
();
84
}
85
86
protected
:
87
view_t
data
;
88
};
89
90
}
// namespace Examples::Graph
91
92
int
main
(
int
argc,
char
* argv[]) {
93
const
Kokkos::ScopeGuard guard{argc, argv};
94
{
95
Examples::Graph::Hydra<EXAMPLE_EXECUTION_SPACE>
{}.
run
();
96
}
97
return
EXIT_SUCCESS;
98
}
ExecutionSpace.hpp
graph.hpp
main
int main(int argc, char **argv)
Examples::Graph
Definition
example_hydra.cpp:20
Kokkos
Examples::Graph::Hydra
Definition
example_hydra.cpp:32
Examples::Graph::Hydra::Hydra
Hydra()
Definition
example_hydra.cpp:43
Examples::Graph::Hydra::check
void check() const
Definition
example_hydra.cpp:48
Examples::Graph::Hydra::view_t
Kokkos::View< char[pattern.size()+1], Exec > view_t
One extra slot, zero-initialized, so the result is always null-terminated.
Definition
example_hydra.cpp:40
Examples::Graph::Hydra::pattern
static constexpr std::string_view pattern
One branch (head) per character. To grow another head, extend the string.
Definition
example_hydra.cpp:37
Examples::Graph::Hydra::run
void run() const
Definition
example_hydra.cpp:69
Examples::Graph::Hydra::base_t
Kokkos::utils::tests::scoped::ExecutionSpace< Exec > base_t
Definition
example_hydra.cpp:34
Examples::Graph::Hydra::data
view_t data
Definition
example_hydra.cpp:87
Examples::Graph::Write
Definition
example_hydra.cpp:23
Examples::Graph::Write::operator()
void operator()() const noexcept
Definition
example_hydra.cpp:26
Examples::Graph::Write::data
ViewType data
Definition
example_hydra.cpp:24
Kokkos::Execution::GraphContext
Execution context using Kokkos::Experimental::Graph under the hood.
Definition
graph.hpp:123
Kokkos::Execution::GraphContext::get_scheduler
auto get_scheduler() const noexcept -> GraphImpl::Scheduler< execution_space >
Definition
graph.hpp:134
Kokkos::utils::tests::scoped::ExecutionSpace
Kokkos::utils::tests::scoped::ExecutionSpace< Exec >::exec
Exec exec
examples
graph
example_hydra.cpp
Generated on
for kokkos-execution by
1.18.0