kokkos-utils 0.0.1
 
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
18
19using execution_space = Kokkos::DefaultExecutionSpace;
20
22{
23
24using namespace Kokkos::utils::callbacks;
25
26template <typename TimerType>
27struct TimerTest : public ::testing::Test
28{
29public:
30 void SetUp() override {
31 this->exec = Kokkos::Experimental::partition_space(execution_space{}, 1)[0];
32 this->dev_id = Kokkos::Tools::Experimental::device_id(this->exec);
33 this->timer = TimerType{this->exec};
34 }
35
36protected:
38 uint32_t dev_id = 0;
39 TimerType timer {};
40};
41
42struct EnqueuedEventTimerTest : public TimerTest<EnqueuedEventTimer<execution_space>> {};
43
46{
47 this->timer.start(BeginParallelForEvent{.name = "my-name", .dev_id = this->dev_id, .event_id = 1});
48
49 this->timer.stop(EndParallelForEvent{.event_id = 1});
50
51 const auto duration = this->timer.template duration<Kokkos::utils::timer::milliseconds>();
52
54 ASSERT_GE(duration.count(), 0.);
55}
56
57struct EnqueuedEventWithLaunchTimerTest : public TimerTest<EnqueuedEventWithLaunchTimer<execution_space>> {};
58
61{
63
64 constexpr unit_t sleep_for_h{5.};
65
66 Kokkos::utils::timer::Timer<void> timer_outer_h {};
68
69 timer_outer_h.start();
70
71 this->timer.start(BeginParallelForEvent{.name = "my-name", .dev_id = this->dev_id, .event_id = 1});
72
73 std::this_thread::sleep_for(sleep_for_h);
74
75 timer_inner_d.start(this->exec);
76
77 timer_inner_d.stop(this->exec);
78
79 this->timer.stop(EndParallelForEvent{.event_id = 1});
80
81 const auto duration = this->timer.template duration<unit_t>();
82
83 timer_outer_h.stop();
84
85 const auto launch_duration = this->timer.template launch<unit_t>();
86
87 const auto outer_duration = timer_outer_h.template duration<unit_t>();
88 const auto inner_duration = timer_inner_d.template duration<unit_t>();
89
91 ASSERT_GE(duration, unit_t{0.});
92 ASSERT_GE(duration, inner_duration);
93 ASSERT_LE(duration, outer_duration);
94
96 ASSERT_GE(launch_duration, sleep_for_h);
97 ASSERT_LE(launch_duration, outer_duration);
98}
99
100using TimerTypes = ::testing::Types<
103>;
104
106
112TYPED_TEST(TimerTest, start_aborts_for_wrongly_enqueued_event)
113{
114 ASSERT_DEATH({
115 this->timer.start(BeginParallelForEvent{.name = "my-name", .dev_id =
116 this->dev_id + 1, .event_id = 1});
117 }, "EnqueuedEventTimer cannot be started for a wrongly enqueued event.");
118}
119
120} // 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