kokkos-utils 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
5
7
19
20using execution_space = Kokkos::DefaultExecutionSpace;
21
23{
24
25using namespace Kokkos::utils::callbacks;
26
28TEST(EventTest, BeginEvent)
29{
30 static_assert(BeginEvent<BeginParallelForEvent>);
31 static_assert(BeginEvent<BeginParallelReduceEvent>);
32 static_assert(BeginEvent<BeginParallelScanEvent>);
33 static_assert(BeginEvent<BeginFenceEvent>);
34
35 static_assert( ! BeginEvent<EndParallelForEvent>);
36
37 static_assert( ! BeginEvent<PushRegionEvent>);
38}
39
41TEST(EventTest, EndEvent)
42{
43 static_assert(EndEvent<EndParallelForEvent>);
44 static_assert(EndEvent<EndParallelReduceEvent>);
45 static_assert(EndEvent<EndParallelScanEvent>);
46 static_assert(EndEvent<EndFenceEvent>);
47
48 static_assert( ! EndEvent<BeginParallelForEvent>);
49
50 static_assert( ! EndEvent<PopRegionEvent>);
51
52 static_assert( ! EndEvent<StopProfileSectionEvent>);
53}
54
56TEST(EventTest, DataEvent)
57{
58 static_assert(DataEvent<AllocateDataEvent>);
59 static_assert(DataEvent<DeallocateDataEvent>);
60
61 static_assert( ! DataEvent<PopRegionEvent>);
62}
63
68TEST(EventTest, ProfileSectionManipulationEvent)
69{
70 static_assert( ! ProfileSectionManipulationEvent<EndParallelForEvent>);
71
72 static_assert(ProfileSectionManipulationEvent<StartProfileSectionEvent>);
73 static_assert(ProfileSectionManipulationEvent<StopProfileSectionEvent>);
74 static_assert(ProfileSectionManipulationEvent<DestroyProfileSectionEvent>);
75
76 static_assert( ! ProfileSectionManipulationEvent<PushRegionEvent>);
77 static_assert( ! ProfileSectionManipulationEvent<PopRegionEvent>);
78}
79
84TEST(EventTest, NamedEvent)
85{
86 static_assert(NamedEvent<BeginParallelForEvent>);
87 static_assert(NamedEvent<BeginParallelReduceEvent>);
88 static_assert(NamedEvent<BeginParallelScanEvent>);
89 static_assert(NamedEvent<BeginFenceEvent>);
90 static_assert(NamedEvent<CreateProfileSectionEvent>);
91 static_assert(NamedEvent<PushRegionEvent>);
92 static_assert(NamedEvent<ProfileEvent>);
93
94 static_assert( ! NamedEvent<PopRegionEvent>);
95}
96
99{
100#define CHECK_GET_NAME(__type__) \
101 static_assert(get_name<__type__>() == #__type__);
102
107}
108
109template <Event>
111
112template <BeginEvent EventType>
113struct EventTest<EventType> : public ::testing::Test
114{
115 EventType event {.name = "my begin event", .dev_id = 1, .event_id = 2};
116 std::string expt_descr = "{name = \"my begin event\", dev_id = 1, event_id = 2}";
117};
118
119template <EndEvent EventType>
120struct EventTest<EventType> : public ::testing::Test
121{
122 EventType event {.event_id = 1};
123 std::string expt_descr {"{event_id = 1}"};
124};
125
126template <DataEvent EventType>
127struct EventTest<EventType> : public ::testing::Test
128{
129 EventType event {.alloc = {.kpsh = Kokkos::Profiling::make_space_handle("Host"), .name = "my data event", .ptr = reinterpret_cast<void*>(0x7ffdbc161a70), .size = 2}};
130 std::string expt_descr {"{name = \"my data event\", space = \"Host\", ptr = 0x7ffdbc161a70, size = 2}"};
131};
132
133template <>
134struct EventTest<BeginDeepCopyEvent> : public ::testing::Test
135{
137 .dst = {.kpsh = Kokkos::Profiling::make_space_handle("Cuda"), .name = "my destination", .ptr = reinterpret_cast<void*>(0x7ffdbc161a80), .size = 2},
138 .src = {.kpsh = Kokkos::Profiling::make_space_handle("Host"), .name = "my source", .ptr = reinterpret_cast<void*>(0x7ffdbc161a70), .size = 2}
139 };
140 std::string expt_descr {"{src = \"my source\" (Host, 0x7ffdbc161a70) -> dst = \"my destination\" (Cuda, 0x7ffdbc161a80) of size 2}"};
141};
142
143template <>
144struct EventTest<EndDeepCopyEvent> : public ::testing::Test
145{
147 std::string expt_descr {"{}"};
148};
149
150template <>
151struct EventTest<CreateProfileSectionEvent> : public ::testing::Test
152{
153 CreateProfileSectionEvent event {.name = "my profile section", .section_id = 1};
154 std::string expt_descr {"{name = \"my profile section\", section_id = 1}"};
155};
156
157template <ProfileSectionManipulationEvent EventType>
158struct EventTest<EventType> : public ::testing::Test
159{
160 EventType event {.section_id = 1};
161 std::string expt_descr {"{section_id = 1}"};
162};
163
164template <>
165struct EventTest<PushRegionEvent> : public ::testing::Test
166{
167 PushRegionEvent event {.name = "my push region event"};
168 std::string expt_descr {"{name = \"my push region event\"}"};
169};
170
171template <>
172struct EventTest<PopRegionEvent> : public ::testing::Test
173{
175 std::string expt_descr {"{}"};
176};
177
178template <>
179struct EventTest<ProfileEvent> : public ::testing::Test
180{
181 ProfileEvent event {.name = "my profile event"};
182 std::string expt_descr {"{name = \"my profile event\"}"};
183};
184
186
189{
190 static_assert(Event<TypeParam>);
191}
192
195{
196 static_assert(std::is_aggregate_v<TypeParam>);
197 static_assert(std::is_default_constructible_v<TypeParam>);
198 static_assert(std::movable<TypeParam>);
199}
200
203{
204 ASSERT_THAT([&event = this->event]{ std::stringstream oss; oss << event; return oss.str(); }(), ::testing::StrEq(std::string(get_name<TypeParam>()) + ": " + this->expt_descr));
205}
206
211TYPED_TEST(EventTest, get_and_set_callback_from_and_in_eventset)
212{
214 using callback_fptr_t = decltype(get_callback_from_eventset<TypeParam>(std::declval<Kokkos::Tools::Experimental::EventSet>()));
215
217 const auto context_callbacks = Kokkos::Tools::Experimental::get_callbacks();
218
220 const auto context_callback = get_callback_from_eventset<TypeParam>(context_callbacks);
221 static_assert(std::same_as<std::remove_const_t<decltype(context_callback)>, callback_fptr_t>);
222
226 const auto callback_to_register = [] <typename... Args>(Args...) -> void {};
227 static_assert(std::convertible_to<decltype(callback_to_register), callback_fptr_t>);
228
230 get_callback_setter<TypeParam>()(callback_to_register);
231
233 ASSERT_EQ(get_callback_from_eventset<TypeParam>(Kokkos::Tools::Experimental::get_callbacks()), callback_to_register);
234
236 get_callback_setter<TypeParam>()(context_callback);
237}
238
239} // namespace Kokkos::utils::tests::callbacks
constexpr auto get_name()
Definition Events.hpp:226
auto get_callback_from_eventset(const Kokkos::Tools::Experimental::EventSet &event_set)
auto get_callback_setter()
Get the setter function of a Kokkos profiling callback corresponding to EventType.
typename impl::EventTestTypes< Kokkos::utils::callbacks::EventTypeList >::type EventTestTypes
Useful type for defining a typed test suite over all types in Kokkos::utils::callbacks::EventTypeList...
Definition Helpers.hpp:21
TYPED_TEST_SUITE(EventTest, EventTestTypes)
TEST(EventTest, BeginEvent)
Begin-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::begin_deep_copy.
Definition Events.hpp:102
Begin-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_red...
Definition Events.hpp:39
Begin-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_scan.
Definition Events.hpp:53
Create-profile-section event associated with Kokkos::Tools::Experimental::EventSet::create_profile_se...
Definition Events.hpp:112
Destroy-profile-section event associated with Kokkos::Tools::Experimental::EventSet::destroy_profile_...
Definition Events.hpp:131
End-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::end_deep_copy.
Definition Events.hpp:108
Pop-region event associated with Kokkos::Tools::Experimental::EventSet::pop_region.
Definition Events.hpp:142
Profile event associated with Kokkos::Tools::Experimental::EventSet::profile_event.
Definition Events.hpp:146
Push-region event associated with Kokkos::Tools::Experimental::EventSet::push_region.
Definition Events.hpp:137
#define CHECK_GET_NAME(__type__)
Kokkos::DefaultExecutionSpace execution_space