kokkos-utils 0.0.2
 
Loading...
Searching...
No Matches
test_EnqueuedEventTimer.cpp
Go to the documentation of this file.
1#include "gtest/gtest.h"
2
3#include "Kokkos_Core.hpp"
4
8
9#include "tests/IgnoreWarnings.hpp"
10
20
21using execution_space = Kokkos::DefaultExecutionSpace;
22
24{
25
26using namespace Kokkos::utils::callbacks;
27
28template <typename TimerType>
29struct TimerTest : public ::testing::Test
30{
31public:
32 void SetUp() override {
33 this->exec = Kokkos::Experimental::partition_space(execution_space{}, 1)[0];
34 this->dev_id = Kokkos::Tools::Experimental::device_id(this->exec);
35 this->timer = TimerType{this->exec};
36 }
37
38protected:
40 uint32_t dev_id = 0;
41 TimerType timer {};
42};
43
44struct EnqueuedEventTimerTest : public TimerTest<EnqueuedEventTimer<execution_space>> {};
45
48{
49 this->timer.start(BeginParallelForEvent{.name = "my-name", .dev_id = this->dev_id, .event_id = 1});
50
51 this->timer.stop(EndParallelForEvent{.event_id = 1});
52
53 const auto duration = this->timer.template duration<Kokkos::utils::timer::milliseconds>();
54
56 ASSERT_GE(duration.count(), 0.);
57}
58
59struct EnqueuedEventWithLaunchTimerTest : public TimerTest<EnqueuedEventWithLaunchTimer<execution_space>> {};
60
63{
65
66 constexpr unit_t sleep_for_h{5.};
67
68 Kokkos::utils::timer::Timer<void> timer_outer_h {};
70
71 timer_outer_h.start();
72
73 this->timer.start(BeginParallelForEvent{.name = "my-name", .dev_id = this->dev_id, .event_id = 1});
74
75 std::this_thread::sleep_for(sleep_for_h);
76
77 timer_inner_d.start(this->exec);
78
79 timer_inner_d.stop(this->exec);
80
81 this->timer.stop(EndParallelForEvent{.event_id = 1});
82
83 const auto duration = this->timer.template duration<unit_t>();
84
85 timer_outer_h.stop();
86
87 const auto launch_duration = this->timer.template launch<unit_t>();
88
89 const auto outer_duration = timer_outer_h.template duration<unit_t>();
90 const auto inner_duration = timer_inner_d.template duration<unit_t>();
91
93 ASSERT_GE(duration, unit_t{0.});
94 ASSERT_GE(duration, inner_duration);
95 ASSERT_LE(duration, outer_duration);
96
98 ASSERT_GE(launch_duration, sleep_for_h);
99 ASSERT_LE(launch_duration, outer_duration);
100}
101
102using TimerTypes = ::testing::Types<
105>;
106
108
114TYPED_TEST(TimerTest, start_aborts_for_wrongly_enqueued_event)
115{
116PRAGMA_DIAGNOSTIC_PUSH
117PRAGMA_DIAGNOSTIC_IGNORED("-Wswitch-default")
118 ASSERT_DEATH({
119 this->timer.start(BeginParallelForEvent{.name = "my-name", .dev_id =
120 this->dev_id + 1, .event_id = 1});
121 }, "EnqueuedEventTimer cannot be started for a wrongly enqueued event.");
122PRAGMA_DIAGNOSTIC_POP
123}
124
125} // namespace Kokkos::utils::tests::callbacks
Measure elapsed time between events.
Definition Timer.hpp:18
void start()
Start the timer.
Definition Timer.hpp:38
TEST_F(EnqueuedEventTimerTest, duration)
::testing::Types< EnqueuedEventTimer< execution_space >, EnqueuedEventWithLaunchTimer< execution_space > > TimerTypes
TYPED_TEST(TimerTest, start_aborts_for_wrongly_enqueued_event)
TYPED_TEST_SUITE(TimerTest, TimerTypes)
std::chrono::duration< double, std::micro > microseconds
Similar to std::chrono::microseconds, but using double instead of an integer type to represent the ti...
Definition Duration.hpp:15
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
Definition Events.hpp:40
Timer for events that are enqueued on exec.
Timer for events that are enqueued on exec. This timer also measures the launch time.
Kokkos::DefaultExecutionSpace execution_space