kokkos-utils 0.0.7
Loading...
Searching...
No Matches
test_EnqueuedEventTimer.cpp
Go to the documentation of this file.
1#include "gtest/gtest.h"
2
3#include "Kokkos_Macros.hpp"
4#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
5import kokkos.core;
6#else
7#include "Kokkos_Core.hpp"
8#endif
9
13
14#include "tests/IgnoreWarnings.hpp"
15
25
26using execution_space = Kokkos::DefaultExecutionSpace;
27
29{
30
31using namespace Kokkos::utils::callbacks;
32
33template <typename TimerType>
34struct TimerTest : public ::testing::Test
35{
36public:
37 void SetUp() override {
38 this->exec = Kokkos::Experimental::partition_space(execution_space{}, 1)[0];
39 this->dev_id = Kokkos::Tools::Experimental::device_id(this->exec);
40 this->timer = TimerType{this->exec};
41 }
42
43protected:
45 uint32_t dev_id = 0;
46 TimerType timer {};
47};
48
49struct EnqueuedEventTimerTest : public TimerTest<EnqueuedEventTimer<execution_space>> {};
50
53{
54 this->timer.start(BeginParallelForEvent{.name = "my-name", .dev_id = this->dev_id, .event_id = 1});
55
56 this->timer.stop(EndParallelForEvent{.event_id = 1});
57
58 const auto duration = this->timer.template duration<Kokkos::utils::timer::milliseconds>();
59
61 ASSERT_GE(duration.count(), 0.);
62}
63
64struct EnqueuedEventWithLaunchTimerTest : public TimerTest<EnqueuedEventWithLaunchTimer<execution_space>> {};
65
68{
70
71 constexpr unit_t sleep_for_h{5.};
72
73 Kokkos::utils::timer::Timer<void> timer_outer_h {};
75
76 timer_outer_h.start();
77
78 this->timer.start(BeginParallelForEvent{.name = "my-name", .dev_id = this->dev_id, .event_id = 1});
79
80 std::this_thread::sleep_for(sleep_for_h);
81
82 timer_inner_d.start(this->exec);
83
84 timer_inner_d.stop(this->exec);
85
86 this->timer.stop(EndParallelForEvent{.event_id = 1});
87
88 const auto duration = this->timer.template duration<unit_t>();
89
90 timer_outer_h.stop();
91
92 const auto launch_duration = this->timer.template launch<unit_t>();
93
94 const auto outer_duration = timer_outer_h.template duration<unit_t>();
95 const auto inner_duration = timer_inner_d.template duration<unit_t>();
96
98 ASSERT_GE(duration, unit_t{0.});
99 ASSERT_GE(duration, inner_duration);
100 ASSERT_LE(duration, outer_duration);
101
103 ASSERT_GE(launch_duration, sleep_for_h);
104 ASSERT_LE(launch_duration, outer_duration);
105}
106
107using TimerTypes = ::testing::Types<
110>;
111
113
119TYPED_TEST(TimerTest, start_aborts_for_wrongly_enqueued_event)
120{
121PRAGMA_DIAGNOSTIC_PUSH
122PRAGMA_DIAGNOSTIC_IGNORED("-Wswitch-default")
123 ASSERT_DEATH({
124 this->timer.start(BeginParallelForEvent{.name = "my-name", .dev_id =
125 this->dev_id + 1, .event_id = 1});
126 }, "EnqueuedEventTimer cannot be started for a wrongly enqueued event.");
127PRAGMA_DIAGNOSTIC_POP
128}
129
130} // namespace Kokkos::utils::tests::callbacks
Measure elapsed time between events.
Definition Timer.hpp:18
void stop()
Stop the timer.
Definition Timer.hpp:55
void start()
Start the timer.
Definition Timer.hpp:38
TEST_F(EnqueuedEventTimerTest, duration)
TYPED_TEST(TimerTest, start_aborts_for_wrongly_enqueued_event)
::testing::Types< EnqueuedEventTimer< execution_space >, EnqueuedEventWithLaunchTimer< execution_space > > TimerTypes
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:55
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