kokkos-utils
0.0.5
Toggle main menu visibility
Loading...
Searching...
No Matches
test_Event.cpp
Go to the documentation of this file.
1
#include "gtest/gtest.h"
2
3
#include "Kokkos_Core.hpp"
4
5
#include "
kokkos-utils/tests/scoped/ExecutionSpace.hpp
"
6
#include "
kokkos-utils/timer/Duration.hpp
"
7
#include "
kokkos-utils/timer/Event.hpp
"
8
19
20
using
execution_space
= Kokkos::DefaultExecutionSpace;
21
22
namespace
Kokkos::utils::tests::timer
23
{
24
25
using namespace
Kokkos::utils::timer
;
26
27
template
<
typename
T>
28
struct
EventTest
:
public
::testing::Test,
29
public
scoped::ExecutionSpace
<execution_space>
30
{};
31
32
using
EventTypes
= ::testing::Types<
33
Event<void>
,
34
Event<execution_space>
35
>;
36
37
TYPED_TEST_SUITE
(
EventTest
,
EventTypes
);
38
40
TYPED_TEST
(
EventTest
, impl_event_type)
41
{
42
using
expt_impl_event_t = std::conditional_t<
43
std::same_as<TypeParam, Event<void>>,
44
std::chrono::steady_clock::time_point,
45
#if defined(KOKKOS_ENABLE_CUDA)
46
cudaEvent_t
47
#elif defined(KOKKOS_ENABLE_HIP)
48
hipEvent_t
49
#else
50
std::chrono::steady_clock::time_point
51
#endif
52
>;
53
54
static_assert
(std::same_as<typename TypeParam::impl_event_t, expt_impl_event_t>);
55
}
56
58
TEST
(
Event
, duration_instances)
59
{
60
static_assert
(std::same_as<typename std::chrono::microseconds::period, std::ratio<1, 1000000>>);
61
static_assert
(std::same_as<typename microseconds::period, std::ratio<1, 1000000>>);
62
static_assert
(std::same_as<typename microseconds::rep, double>);
63
64
static_assert
(std::same_as<typename std::chrono::milliseconds::period, std::ratio<1, 1000>>);
65
static_assert
(std::same_as<typename milliseconds::period, std::ratio<1, 1000>>);
66
static_assert
(std::same_as<typename milliseconds::rep, double>);
67
68
static_assert
(std::same_as<typename std::chrono::seconds::period, std::ratio<1, 1>>);
69
static_assert
(std::same_as<typename seconds::period, std::ratio<1, 1>>);
70
static_assert
(std::same_as<typename seconds::rep, double>);
71
}
72
74
TYPED_TEST
(
EventTest
, duration)
75
{
76
TypeParam begin, end;
77
78
if
constexpr
(std::same_as<TypeParam, void>)
79
{
80
begin.record();
81
end.record();
82
}
83
else
84
{
85
begin.record(this->exec);
86
end.record(this->exec);
87
}
88
89
ASSERT_GE(begin.template duration<milliseconds>(end).count(), 0.);
90
}
91
93
TYPED_TEST
(
EventTest
, destroyed_while_recording)
94
{
95
std::optional<TypeParam> event(std::in_place);
96
97
if
constexpr
(std::same_as<TypeParam, void>) {
98
event
->record();
99
}
else
{
100
event
->record(this->exec);
101
}
102
103
event
.reset();
104
}
105
112
TYPED_TEST
(
EventTest
, movable)
113
{
114
static_assert
(std::movable<TypeParam>);
115
116
TypeParam begin, end;
117
118
if
constexpr
(std::same_as<TypeParam, void>)
119
{
120
begin.record();
121
end.record();
122
}
123
else
124
{
125
begin.record(this->exec);
126
end.record(this->exec);
127
}
128
129
TypeParam moved(std::move(end));
// NOLINT(misc-const-correctness,performance-move-const-arg)
130
131
ASSERT_GE(begin.template duration<milliseconds>(moved).count(), 0.);
132
}
133
134
}
// namespace Kokkos::utils::tests::timer
Duration.hpp
Event.hpp
ExecutionSpace.hpp
Kokkos::utils::tests::timer
Definition
test_Event.cpp:23
Kokkos::utils::tests::timer::TYPED_TEST_SUITE
TYPED_TEST_SUITE(EventTest, EventTypes)
Kokkos::utils::tests::timer::TEST
TEST(Event, duration_instances)
Definition
test_Event.cpp:58
Kokkos::utils::tests::timer::TYPED_TEST
TYPED_TEST(EventTest, impl_event_type)
Definition
test_Event.cpp:40
Kokkos::utils::tests::timer::EventTypes
::testing::Types< Event< void >, Event< execution_space > > EventTypes
Definition
test_Event.cpp:32
Kokkos::utils::timer
Definition
Duration.hpp:7
Kokkos::utils::tests::scoped::ExecutionSpace
Create a new execution space instance with RAII semantics.
Definition
ExecutionSpace.hpp:12
Kokkos::utils::tests::timer::EventTest
Definition
test_Event.cpp:30
Kokkos::utils::timer::Event
Event.
Definition
Event.hpp:31
execution_space
Kokkos::DefaultExecutionSpace execution_space
Definition
test_InsertOp.cpp:8
tests
timer
test_Event.cpp
Generated on
for kokkos-utils by
1.18.0