kokkos-utils
0.0.5
Toggle main menu visibility
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
5
#include "
kokkos-utils/callbacks/EnqueuedEventTimer.hpp
"
6
#include "
kokkos-utils/callbacks/EnqueuedEventWithLaunchTimer.hpp
"
7
#include "
kokkos-utils/timer/Duration.hpp
"
8
9
#include "tests/IgnoreWarnings.hpp"
10
20
21
using
execution_space
= Kokkos::DefaultExecutionSpace;
22
23
namespace
Kokkos::utils::tests::callbacks
24
{
25
26
using namespace
Kokkos::utils::callbacks;
27
28
template
<
typename
TimerType>
29
struct
TimerTest
:
public
::testing::Test
30
{
31
public
:
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
38
protected
:
39
execution_space
exec
{};
40
uint32_t
dev_id
= 0;
41
TimerType
timer
{};
42
};
43
44
struct
EnqueuedEventTimerTest
:
public
TimerTest
<EnqueuedEventTimer<execution_space>> {};
45
47
TEST_F
(
EnqueuedEventTimerTest
, duration)
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
59
struct
EnqueuedEventWithLaunchTimerTest
:
public
TimerTest
<EnqueuedEventWithLaunchTimer<execution_space>> {};
60
62
TEST_F
(
EnqueuedEventWithLaunchTimerTest
, duration)
63
{
64
using
unit_t =
Kokkos::utils::timer::microseconds
;
65
66
constexpr
unit_t sleep_for_h{5.};
67
68
Kokkos::utils::timer::Timer<void>
timer_outer_h {};
69
Kokkos::utils::timer::Timer<execution_space>
timer_inner_d {};
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
102
using
TimerTypes
= ::testing::Types<
103
EnqueuedEventTimer<execution_space>
,
104
EnqueuedEventWithLaunchTimer<execution_space>
105
>;
106
107
TYPED_TEST_SUITE
(
TimerTest
,
TimerTypes
);
108
114
TYPED_TEST
(
TimerTest
, start_aborts_for_wrongly_enqueued_event)
115
{
116
PRAGMA_DIAGNOSTIC_PUSH
117
PRAGMA_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."
);
122
PRAGMA_DIAGNOSTIC_POP
123
}
124
125
}
// namespace Kokkos::utils::tests::callbacks
Duration.hpp
EnqueuedEventTimer.hpp
EnqueuedEventWithLaunchTimer.hpp
Kokkos::utils::timer::Timer
Measure elapsed time between events.
Definition
Timer.hpp:18
Kokkos::utils::timer::Timer::stop
void stop()
Stop the timer.
Definition
Timer.hpp:55
Kokkos::utils::timer::Timer::start
void start()
Start the timer.
Definition
Timer.hpp:38
Kokkos::utils::tests::callbacks
Definition
Helpers.hpp:7
Kokkos::utils::tests::callbacks::TEST_F
TEST_F(EnqueuedEventTimerTest, duration)
Definition
test_EnqueuedEventTimer.cpp:47
Kokkos::utils::tests::callbacks::TYPED_TEST
TYPED_TEST(TimerTest, start_aborts_for_wrongly_enqueued_event)
Definition
test_EnqueuedEventTimer.cpp:114
Kokkos::utils::tests::callbacks::TimerTypes
::testing::Types< EnqueuedEventTimer< execution_space >, EnqueuedEventWithLaunchTimer< execution_space > > TimerTypes
Definition
test_EnqueuedEventTimer.cpp:102
Kokkos::utils::tests::callbacks::TYPED_TEST_SUITE
TYPED_TEST_SUITE(TimerTest, TimerTypes)
Kokkos::utils::tests::timer
Definition
test_Event.cpp:23
Kokkos::utils::timer::microseconds
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
Kokkos::utils::callbacks::BeginParallelForEvent
Definition
Events.hpp:37
Kokkos::utils::callbacks::EndParallelForEvent
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
Definition
Events.hpp:47
Kokkos::utils::callbacks::EnqueuedEventTimer
Timer for events that are enqueued on exec.
Definition
EnqueuedEventTimer.hpp:14
Kokkos::utils::callbacks::EnqueuedEventWithLaunchTimer
Timer for events that are enqueued on exec. This timer also measures the launch time.
Definition
EnqueuedEventWithLaunchTimer.hpp:14
Kokkos::utils::tests::callbacks::EnqueuedEventTimerTest
Definition
test_EnqueuedEventTimer.cpp:44
Kokkos::utils::tests::callbacks::EnqueuedEventWithLaunchTimerTest
Definition
test_EnqueuedEventTimer.cpp:59
Kokkos::utils::tests::callbacks::TimerTest
Definition
test_EnqueuedEventTimer.cpp:30
Kokkos::utils::tests::callbacks::TimerTest::SetUp
void SetUp() override
Definition
test_EnqueuedEventTimer.cpp:32
Kokkos::utils::tests::callbacks::TimerTest::dev_id
uint32_t dev_id
Definition
test_EnqueuedEventTimer.cpp:40
Kokkos::utils::tests::callbacks::TimerTest::timer
TimerType timer
Definition
test_EnqueuedEventTimer.cpp:41
Kokkos::utils::tests::callbacks::TimerTest::exec
execution_space exec
Definition
test_EnqueuedEventTimer.cpp:39
execution_space
Kokkos::DefaultExecutionSpace execution_space
Definition
test_InsertOp.cpp:8
tests
callbacks
test_EnqueuedEventTimer.cpp
Generated on
for kokkos-utils by
1.18.0