kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_events.cpp
Go to the documentation of this file.
1#include "gmock/gmock.h"
2#include "gtest/gtest.h"
3
6
8
11
22
23#if !defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
24# error "This is not supported."
25#endif
26
27namespace Tests::GraphImpl {
28
29using namespace Kokkos::utils::callbacks;
30
44
46consteval bool test_noexcept() {
47 static_assert(
48 noexcept(Kokkos::Execution::GraphImpl::get_graph_impl_ptr(std::declval<const EventsTest::graph_t::root_t&>())));
49 static_assert(
50 noexcept(Kokkos::Execution::GraphImpl::get_node_ptr(std::declval<const EventsTest::graph_t::root_t&>())));
51
52 static_assert(
53 !noexcept(Kokkos::Execution::GraphImpl::graph_create_event(std::declval<const EventsTest::graph_t&>())));
54 static_assert(
55 !noexcept(Kokkos::Execution::GraphImpl::create_graph(std::declval<const EventsTest::device_handle_t&>())));
56
58 std::declval<std::string>(),
59 std::declval<const EventsTest::graph_t::root_t&>(),
60 std::declval<const EventsTest::graph_t::root_t&>())));
61
62 static_assert(
63 !noexcept(Kokkos::Execution::GraphImpl::graph_instantiate_event(std::declval<const EventsTest::graph_t&>())));
64
66 std::declval<const EventsTest::graph_t&>(), std::declval<const TEST_EXECUTION_SPACE&>())));
67
68 static_assert(!noexcept(Kokkos::Execution::GraphImpl::submit_graph(
69 std::declval<const EventsTest::graph_t&>(), std::declval<const TEST_EXECUTION_SPACE&>())));
70
71 return true;
72}
73
74static_assert(test_noexcept());
75
77TEST_F(EventsTest, create_instantiate_and_submit) {
78 const auto recorded_events = recorder_listener_t::record([this]() {
80
81 graph.instantiate();
83
85 });
86 ASSERT_THAT(
87 recorded_events.at(0),
88 AGraphCreateEvent(
89 testing::Field(&Kokkos::Execution::GraphImpl::GraphCreateEvent::root_node, testing::NotNull())));
90
91 ASSERT_THAT(
92 recorded_events,
93 testing::ElementsAre(
95 MATCHER_FOR_GRAPH_INSTANTIATE(recorded_events.at(0)),
96 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0))));
97}
98
100TEST_F(EventsTest, create_and_add_nodes) {
101 const auto recorded_events = recorder_listener_t::record([this]() {
102 const graph_t graph{device_handle};
104
105 const auto root = graph.root_node();
106
107 const auto node_A = root.then(Kokkos::Experimental::node_props(device_handle), KOKKOS_LAMBDA(){});
109
110 const auto node_B = node_A.then(Kokkos::Experimental::node_props(device_handle), KOKKOS_LAMBDA(){});
111 Kokkos::Execution::GraphImpl::graph_add_node_event("my label", node_A, node_B);
112 });
113 ASSERT_THAT(
114 recorded_events,
115 testing::ElementsAre(
118 recorded_events.at(0),
120 MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0)),
121 "my label"),
123 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(1)), "my label")));
124}
125
127TEST(GraphCreateEvent, streaming_operator) {
129 .graph = reinterpret_cast<void*>(0x7f3a2b4c8000),
130 .root_node = reinterpret_cast<void*>(0x7f6d9e1a5000),
131 .dev_id = 8,
132 .event_id = 666};
133
134 std::ostringstream oss;
135 oss << event;
136
137 ASSERT_EQ(
138 oss.str(),
139 "GraphCreateEvent: {graph = 0x7f3a2b4c8000, root_node = 0x7f6d9e1a5000, dev_id = 8, event_id = 666}");
140}
141
143TEST(GraphAddAggregateNodeEvent, streaming_operator) {
145 .graph = reinterpret_cast<void*>(0x7f3a2b4c8000),
146 .predecessors = {reinterpret_cast<void*>(0x7f6d9e1a5000), reinterpret_cast<void*>(0x7f6d9e1a5500)},
147 .node = reinterpret_cast<void*>(0x7f7d9e1a5000)
148 };
149
150 std::ostringstream oss;
151 oss << event;
152
153 ASSERT_EQ(
154 oss.str(),
155 "GraphAddAggregateNodeEvent: {graph = 0x7f3a2b4c8000, predecessors = [0x7f6d9e1a5000, 0x7f6d9e1a5500], node = "
156 "0x7f7d9e1a5000}");
157}
158
159} // namespace Tests::GraphImpl
RecorderListener< GraphEventDiscardMatcher< TEST_EXECUTION_SPACE >, BeginFenceEvent, Kokkos::Execution::GraphImpl::GraphAddNodeEvent, Kokkos::Execution::GraphImpl::GraphCreateEvent, Kokkos::Execution::GraphImpl::GraphInstantiateEvent, Kokkos::Execution::GraphImpl::GraphSubmitEvent > recorder_listener_t
void graph_add_node_event(Label &&label, const Predecessor &predecessor, const NodeType &node)
Record an event for a node added after predecessor.
Definition events.hpp:151
void graph_create_event(const Kokkos::Experimental::Graph< Exec > &graph)
Record a GraphCreateEvent event.
Definition events.hpp:129
auto * get_node_ptr(const NodeType &node) noexcept
Retrieve the raw node pointer.
Definition events.hpp:123
auto create_graph(const Kokkos::Impl::DeviceHandle< Exec > &device_handle, Args &&... args)
Create a graph and record the associated event with graph_create_event.
Definition events.hpp:143
void graph_instantiate_event(const Kokkos::Experimental::Graph< Exec > &graph)
Record a GraphInstantiateEvent event.
Definition events.hpp:178
void graph_submit_event(const Kokkos::Experimental::Graph< Exec > &graph, const Exec &exec)
Record a GraphSubmitEvent event.
Definition events.hpp:186
auto * get_graph_impl_ptr(const NodeType &node) noexcept
Retrieve the raw graph pointer from a node.
Definition events.hpp:117
void submit_graph(const Kokkos::Experimental::Graph< Exec > &graph, const Exec &exec)
Submit a graph and record the associated event with graph_submit_event.
Definition events.hpp:196
consteval bool test_noexcept()
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph aggregate node is added.
Definition events.hpp:68
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph node is added.
Definition events.hpp:49
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
Definition events.hpp:28
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is instantiated.
Definition events.hpp:85
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is submitted.
Definition events.hpp:98
Similar to EventDiscardMatcher, for graph-related events.
Definition events.hpp:83
#define MATCHER_FOR_GRAPH_CREATE(_device_handle_)
Definition events.hpp:17
#define MATCHER_FOR_GRAPH_ADDNODE(_graph_create_event_variant_, _device_handle_, _predecessor_,...)
Definition events.hpp:24
#define MATCHER_FOR_GRAPH_SUBMIT(_exec_, _graph_create_event_variant_)
Definition events.hpp:71
#define MATCHER_FOR_GRAPH_ROOT_NODE_OF(_graph_create_event_)
Definition events.hpp:51
#define MATCHER_FOR_GRAPH_INSTANTIATE(_graph_create_event_variant_)
Definition events.hpp:63
#define MATCHER_FOR_GRAPH_NODE_OF(_graph_add_node_event_)
Definition events.hpp:55