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
110TEST(EventTest, paired_event)
111{
112 static_assert(std::same_as<paired_event_t<BeginParallelForEvent> , EndParallelForEvent>);
113 static_assert(std::same_as<paired_event_t<BeginParallelReduceEvent>, EndParallelReduceEvent>);
114 static_assert(std::same_as<paired_event_t<BeginParallelScanEvent>, EndParallelScanEvent>);
115 static_assert(std::same_as<paired_event_t<BeginFenceEvent>, EndFenceEvent>);
116 static_assert(std::same_as<paired_event_t<AllocateDataEvent>, DeallocateDataEvent>);
117 static_assert(std::same_as<paired_event_t<BeginDeepCopyEvent>, EndDeepCopyEvent>);
118 static_assert(std::same_as<paired_event_t<CreateProfileSectionEvent>, DestroyProfileSectionEvent>);
119 static_assert(std::same_as<paired_event_t<StartProfileSectionEvent>, StopProfileSectionEvent>);
120 static_assert(std::same_as<paired_event_t<PushRegionEvent>, PopRegionEvent>);
121}
122
123template <Event>
125
126template <BeginEvent EventType>
127struct EventTest<EventType> : public ::testing::Test
128{
129 EventType event {.name = "my begin event", .dev_id = 1, .event_id = 2};
130 std::string expt_descr = "{name = \"my begin event\", dev_id = 1, event_id = 2}";
131};
132
133template <EndEvent EventType>
134struct EventTest<EventType> : public ::testing::Test
135{
136 EventType event {.event_id = 1};
137 std::string expt_descr {"{event_id = 1}"};
138};
139
140template <DataEvent EventType>
141struct EventTest<EventType> : public ::testing::Test
142{
143 EventType event {.alloc = {.kpsh = Kokkos::Profiling::make_space_handle("Host"), .name = "my data event", .ptr = reinterpret_cast<void*>(0x7ffdbc161a70), .size = 2}};
144 std::string expt_descr {"{name = \"my data event\", space = \"Host\", ptr = 0x7ffdbc161a70, size = 2}"};
145};
146
147template <>
148struct EventTest<BeginDeepCopyEvent> : public ::testing::Test
149{
151 .dst = {.kpsh = Kokkos::Profiling::make_space_handle("Cuda"), .name = "my destination", .ptr = reinterpret_cast<void*>(0x7ffdbc161a80), .size = 2},
152 .src = {.kpsh = Kokkos::Profiling::make_space_handle("Host"), .name = "my source", .ptr = reinterpret_cast<void*>(0x7ffdbc161a70), .size = 2}
153 };
154 std::string expt_descr {"{src = \"my source\" (Host, 0x7ffdbc161a70) -> dst = \"my destination\" (Cuda, 0x7ffdbc161a80) of size 2}"};
155};
156
157template <>
158struct EventTest<EndDeepCopyEvent> : public ::testing::Test
159{
161 std::string expt_descr {"{}"};
162};
163
164template <>
165struct EventTest<CreateProfileSectionEvent> : public ::testing::Test
166{
167 CreateProfileSectionEvent event {.name = "my profile section", .section_id = 1};
168 std::string expt_descr {"{name = \"my profile section\", section_id = 1}"};
169};
170
171template <ProfileSectionManipulationEvent EventType>
172struct EventTest<EventType> : public ::testing::Test
173{
174 EventType event {.section_id = 1};
175 std::string expt_descr {"{section_id = 1}"};
176};
177
178template <>
179struct EventTest<PushRegionEvent> : public ::testing::Test
180{
181 PushRegionEvent event {.name = "my push region event"};
182 std::string expt_descr {"{name = \"my push region event\"}"};
183};
184
185template <>
186struct EventTest<PopRegionEvent> : public ::testing::Test
187{
189 std::string expt_descr {"{}"};
190};
191
192template <>
193struct EventTest<ProfileEvent> : public ::testing::Test
194{
195 ProfileEvent event {.name = "my profile event"};
196 std::string expt_descr {"{name = \"my profile event\"}"};
197};
198
200
203{
204 static_assert(Event<TypeParam>);
205}
206
209{
210 ASSERT_EQ(this->event, this->event);
211}
212
215{
216 static_assert(std::is_aggregate_v<TypeParam>);
217 static_assert(std::is_default_constructible_v<TypeParam>);
218 static_assert(std::movable<TypeParam>);
219}
220
223{
224 ASSERT_THAT([&event = this->event]{ std::stringstream oss; oss << event; return oss.str(); }(), ::testing::StrEq(std::string(get_name<TypeParam>()) + ": " + this->expt_descr));
225}
226
231TYPED_TEST(EventTest, get_and_set_callback_from_and_in_eventset)
232{
234 using callback_fptr_t = decltype(get_callback_from_eventset<TypeParam>(std::declval<Kokkos::Tools::Experimental::EventSet>()));
235
237 const auto context_callbacks = Kokkos::Tools::Experimental::get_callbacks();
238
240 const auto context_callback = get_callback_from_eventset<TypeParam>(context_callbacks);
241 static_assert(std::same_as<std::remove_const_t<decltype(context_callback)>, callback_fptr_t>);
242
246 const auto callback_to_register = [] <typename... Args>(Args...) -> void {};
247 static_assert(std::convertible_to<decltype(callback_to_register), callback_fptr_t>);
248
250 get_callback_setter<TypeParam>()(callback_to_register);
251
253 ASSERT_EQ(get_callback_from_eventset<TypeParam>(Kokkos::Tools::Experimental::get_callbacks()), callback_to_register);
254
256 get_callback_setter<TypeParam>()(context_callback);
257}
258
259} // namespace Kokkos::utils::tests::callbacks
constexpr auto get_name()
Definition Events.hpp:308
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(TimerTest, start_aborts_for_wrongly_enqueued_event)
TYPED_TEST_SUITE(TimerTest, TimerTypes)
TEST(EventTest, BeginEvent)
Begin-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::begin_deep_copy.
Definition Events.hpp:129
Begin-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_red...
Definition Events.hpp:48
Begin-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_scan.
Definition Events.hpp:66
Create-profile-section event associated with Kokkos::Tools::Experimental::EventSet::create_profile_se...
Definition Events.hpp:144
Deallocate-data event associated with Kokkos::Tools::Experimental::EventSet::deallocate_data.
Definition Events.hpp:121
Destroy-profile-section event associated with Kokkos::Tools::Experimental::EventSet::destroy_profile_...
Definition Events.hpp:169
End-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::end_deep_copy.
Definition Events.hpp:138
End-fence event associated with Kokkos::Tools::Experimental::EventSet::end_fence.
Definition Events.hpp:94
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
Definition Events.hpp:40
End-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_reduce.
Definition Events.hpp:58
End-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_scan.
Definition Events.hpp:76
Pop-region event associated with Kokkos::Tools::Experimental::EventSet::pop_region.
Definition Events.hpp:185
Profile event associated with Kokkos::Tools::Experimental::EventSet::profile_event.
Definition Events.hpp:191
Push-region event associated with Kokkos::Tools::Experimental::EventSet::push_region.
Definition Events.hpp:177
Stop-profile-section event associated with Kokkos::Tools::Experimental::EventSet::stop_profile_sectio...
Definition Events.hpp:161
#define CHECK_GET_NAME(__type__)
Kokkos::DefaultExecutionSpace execution_space