kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
example_parallel_for.cpp
Go to the documentation of this file.
1
#include "
kokkos-execution/graph.hpp
"
2
3
#include "
kokkos-utils/tests/scoped/ExecutionSpace.hpp
"
4
16
17
namespace
Examples::Graph
{
18
19
template
<
char
Value,
typename
ViewType>
20
struct
Work
{
21
ViewType
data
;
22
23
template
<std::
int
egral IndexType>
24
KOKKOS_FUNCTION
void
operator()
(
const
IndexType index)
const
noexcept
{
25
data
(index) = Value;
26
}
27
};
28
29
template
<Kokkos::ExecutionSpace Exec>
30
struct
ParallelFor
:
public
Kokkos::utils::tests::scoped::ExecutionSpace
<Exec> {
31
public
:
32
using
base_t
=
Kokkos::utils::tests::scoped::ExecutionSpace<Exec>
;
33
using
policy_t
= Kokkos::RangePolicy<Exec>;
34
using
view_t
= Kokkos::View<char[6], Exec>;
35
36
public
:
37
ParallelFor
()
38
:
base_t
()
39
,
data
(
Kokkos
::view_alloc(
Kokkos
::WithoutInitializing, this->
exec
,
"data"
)) {
40
}
41
42
void
check
()
const
{
43
const
auto
mirror = Kokkos::create_mirror_view_and_copy(
data
);
44
if
(std::strcmp(mirror.data(),
"ABCBA"
) != 0) {
45
throw
std::runtime_error(std::format(
"'{}' is not equal to 'ABCBA'."
, mirror.data()));
46
}
47
}
48
49
void
reset
()
const
{
50
Kokkos::deep_copy(this->
exec
,
data
, 0);
51
}
52
54
void
with_kokkos_graph
()
const
{
55
reset
();
56
57
const
auto
graph = Kokkos::Experimental::create_graph(
58
Kokkos::Experimental::get_device_handle(this->
exec
), [&](
const
auto
& root) {
59
root.then_parallel_for(
policy_t
(0, 5),
Work
<
'A'
,
view_t
>{.data =
data
})
60
.then_parallel_for(
policy_t
(1, 4),
Work
<
'B'
,
view_t
>{.data =
data
})
61
.then_parallel_for(
policy_t
(2, 3),
Work
<
'C'
,
view_t
>{.data =
data
});
62
});
63
64
graph.submit(this->
exec
);
65
this->
exec
.fence();
66
67
check
();
68
}
69
71
void
with_graph_context
()
const
{
72
reset
();
73
74
const
Kokkos::Execution::GraphContext<Exec>
gctx{this->
exec
};
75
76
stdexec::sync_wait(
77
stdexec::schedule(gctx.
get_scheduler
())
78
|
Kokkos::Execution::parallel_for
(
policy_t
(0, 5),
Work
<
'A'
,
view_t
>{.data =
data
})
79
|
Kokkos::Execution::parallel_for
(
policy_t
(1, 4),
Work
<
'B'
,
view_t
>{.data =
data
})
80
|
Kokkos::Execution::parallel_for
(
policy_t
(2, 3),
Work
<
'C'
,
view_t
>{.data =
data
}));
81
82
check
();
83
}
84
85
protected
:
86
view_t
data
;
87
};
88
89
90
}
// namespace Examples::Graph
91
92
int
main
(
int
argc,
char
* argv[]) {
93
const
Kokkos::ScopeGuard guard{argc, argv};
94
{
95
const
Examples::Graph::ParallelFor<EXAMPLE_EXECUTION_SPACE>
pfor{};
96
97
pfor.
with_kokkos_graph
();
98
pfor.
with_graph_context
();
99
}
100
return
EXIT_SUCCESS;
101
}
ExecutionSpace.hpp
graph.hpp
main
int main(int argc, char **argv)
Examples::Graph
Definition
example_hydra.cpp:20
Kokkos::Execution::parallel_for
constexpr parallel_for_t parallel_for
Definition
parallel_for.hpp:170
Kokkos
Examples::Graph::ParallelFor
Definition
example_parallel_for.cpp:30
Examples::Graph::ParallelFor::policy_t
Kokkos::RangePolicy< Exec > policy_t
Definition
example_parallel_for.cpp:33
Examples::Graph::ParallelFor::view_t
Kokkos::View< char[6], Exec > view_t
Definition
example_parallel_for.cpp:34
Examples::Graph::ParallelFor::with_kokkos_graph
void with_kokkos_graph() const
Create the sequence with Kokkos::Graph.
Definition
example_parallel_for.cpp:54
Examples::Graph::ParallelFor::check
void check() const
Definition
example_parallel_for.cpp:42
Examples::Graph::ParallelFor::ParallelFor
ParallelFor()
Definition
example_parallel_for.cpp:37
Examples::Graph::ParallelFor::data
view_t data
Definition
example_parallel_for.cpp:86
Examples::Graph::ParallelFor::reset
void reset() const
Definition
example_parallel_for.cpp:49
Examples::Graph::ParallelFor::base_t
Kokkos::utils::tests::scoped::ExecutionSpace< Exec > base_t
Definition
example_parallel_for.cpp:32
Examples::Graph::ParallelFor::with_graph_context
void with_graph_context() const
Create the sequence with Kokkos::Execution::GraphContext.
Definition
example_parallel_for.cpp:71
Examples::Graph::Work
Definition
example_parallel_for.cpp:20
Examples::Graph::Work::operator()
void operator()(const IndexType index) const noexcept
Definition
example_parallel_for.cpp:24
Examples::Graph::Work::data
ViewType data
Definition
example_parallel_for.cpp:21
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_parallel_for.cpp
Generated on
for kokkos-execution by
1.18.0