kokkos-utils
0.0.7
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_Macros.hpp"
4
#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
5
import
kokkos.core;
6
#else
7
#include "Kokkos_Core.hpp"
8
#endif
9
10
#include "
kokkos-utils/callbacks/EnqueuedEventTimer.hpp
"
11
#include "
kokkos-utils/callbacks/EnqueuedEventWithLaunchTimer.hpp
"
12
#include "
kokkos-utils/timer/Duration.hpp
"
13
14
#include "tests/IgnoreWarnings.hpp"
15
25
26
using
execution_space
= Kokkos::DefaultExecutionSpace;
27
28
namespace
Kokkos::utils::tests::callbacks
29
{
30
31
using namespace
Kokkos::utils::callbacks;
32
33
template
<
typename
TimerType>
34
struct
TimerTest
:
public
::testing::Test
35
{
36
public
:
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
43
protected
:
44
execution_space
exec
{};
45
uint32_t
dev_id
= 0;
46
TimerType
timer
{};
47
};
48
49
struct
EnqueuedEventTimerTest
:
public
TimerTest
<EnqueuedEventTimer<execution_space>> {};
50
52
TEST_F
(
EnqueuedEventTimerTest
, duration)
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
64
struct
EnqueuedEventWithLaunchTimerTest
:
public
TimerTest
<EnqueuedEventWithLaunchTimer<execution_space>> {};
65
67
TEST_F
(
EnqueuedEventWithLaunchTimerTest
, duration)
68
{
69
using
unit_t =
Kokkos::utils::timer::microseconds
;
70
71
constexpr
unit_t sleep_for_h{5.};
72
73
Kokkos::utils::timer::Timer<void>
timer_outer_h {};
74
Kokkos::utils::timer::Timer<execution_space>
timer_inner_d {};
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
107
using
TimerTypes
= ::testing::Types<
108
EnqueuedEventTimer<execution_space>
,
109
EnqueuedEventWithLaunchTimer<execution_space>
110
>;
111
112
TYPED_TEST_SUITE
(
TimerTest
,
TimerTypes
);
113
119
TYPED_TEST
(
TimerTest
, start_aborts_for_wrongly_enqueued_event)
120
{
121
PRAGMA_DIAGNOSTIC_PUSH
122
PRAGMA_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."
);
127
PRAGMA_DIAGNOSTIC_POP
128
}
129
130
}
// 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:52
Kokkos::utils::tests::callbacks::TYPED_TEST
TYPED_TEST(TimerTest, start_aborts_for_wrongly_enqueued_event)
Definition
test_EnqueuedEventTimer.cpp:119
Kokkos::utils::tests::callbacks::TimerTypes
::testing::Types< EnqueuedEventTimer< execution_space >, EnqueuedEventWithLaunchTimer< execution_space > > TimerTypes
Definition
test_EnqueuedEventTimer.cpp:107
Kokkos::utils::tests::callbacks::TYPED_TEST_SUITE
TYPED_TEST_SUITE(TimerTest, TimerTypes)
Kokkos::utils::tests::timer
Definition
test_Event.cpp:28
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:45
Kokkos::utils::callbacks::EndParallelForEvent
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
Definition
Events.hpp:55
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:49
Kokkos::utils::tests::callbacks::EnqueuedEventWithLaunchTimerTest
Definition
test_EnqueuedEventTimer.cpp:64
Kokkos::utils::tests::callbacks::TimerTest
Definition
test_EnqueuedEventTimer.cpp:35
Kokkos::utils::tests::callbacks::TimerTest::SetUp
void SetUp() override
Definition
test_EnqueuedEventTimer.cpp:37
Kokkos::utils::tests::callbacks::TimerTest::dev_id
uint32_t dev_id
Definition
test_EnqueuedEventTimer.cpp:45
Kokkos::utils::tests::callbacks::TimerTest::timer
TimerType timer
Definition
test_EnqueuedEventTimer.cpp:46
Kokkos::utils::tests::callbacks::TimerTest::exec
execution_space exec
Definition
test_EnqueuedEventTimer.cpp:44
execution_space
Kokkos::DefaultExecutionSpace execution_space
Definition
test_InsertOp.cpp:13
tests
callbacks
test_EnqueuedEventTimer.cpp
Generated on
for kokkos-utils by
1.18.0