kokkos-utils
0.0.7
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_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/tests/scoped/ExecutionSpace.hpp
"
11
#include "
kokkos-utils/timer/Duration.hpp
"
12
#include "
kokkos-utils/timer/Event.hpp
"
13
24
25
using
execution_space
= Kokkos::DefaultExecutionSpace;
26
27
namespace
Kokkos::utils::tests::timer
28
{
29
30
using namespace
Kokkos::utils::timer
;
31
32
template
<
typename
T>
33
struct
EventTest
:
public
::testing::Test,
34
public
scoped::ExecutionSpace
<execution_space>
35
{};
36
37
using
EventTypes
= ::testing::Types<
38
Event<void>
,
39
Event<execution_space>
40
>;
41
42
TYPED_TEST_SUITE
(
EventTest
,
EventTypes
);
43
45
TYPED_TEST
(
EventTest
, impl_event_type)
46
{
47
using
expt_impl_event_t = std::conditional_t<
48
std::same_as<TypeParam, Event<void>>,
49
std::chrono::steady_clock::time_point,
50
#if defined(KOKKOS_ENABLE_CUDA)
51
cudaEvent_t
52
#elif defined(KOKKOS_ENABLE_HIP)
53
hipEvent_t
54
#else
55
std::chrono::steady_clock::time_point
56
#endif
57
>;
58
59
static_assert
(std::same_as<typename TypeParam::impl_event_t, expt_impl_event_t>);
60
}
61
63
TEST
(
Event
, duration_instances)
64
{
65
static_assert
(std::same_as<typename std::chrono::microseconds::period, std::ratio<1, 1000000>>);
66
static_assert
(std::same_as<typename microseconds::period, std::ratio<1, 1000000>>);
67
static_assert
(std::same_as<typename microseconds::rep, double>);
68
69
static_assert
(std::same_as<typename std::chrono::milliseconds::period, std::ratio<1, 1000>>);
70
static_assert
(std::same_as<typename milliseconds::period, std::ratio<1, 1000>>);
71
static_assert
(std::same_as<typename milliseconds::rep, double>);
72
73
static_assert
(std::same_as<typename std::chrono::seconds::period, std::ratio<1, 1>>);
74
static_assert
(std::same_as<typename seconds::period, std::ratio<1, 1>>);
75
static_assert
(std::same_as<typename seconds::rep, double>);
76
}
77
79
TYPED_TEST
(
EventTest
, duration)
80
{
81
TypeParam begin, end;
82
83
if
constexpr
(std::same_as<TypeParam, void>)
84
{
85
begin.record();
86
end.record();
87
}
88
else
89
{
90
begin.record(this->exec);
91
end.record(this->exec);
92
}
93
94
ASSERT_GE(begin.template duration<milliseconds>(end).count(), 0.);
95
}
96
98
TYPED_TEST
(
EventTest
, destroyed_while_recording)
99
{
100
std::optional<TypeParam> event(std::in_place);
101
102
if
constexpr
(std::same_as<TypeParam, void>) {
103
event
->record();
104
}
else
{
105
event
->record(this->exec);
106
}
107
108
event
.reset();
109
}
110
117
TYPED_TEST
(
EventTest
, movable)
118
{
119
static_assert
(std::movable<TypeParam>);
120
121
TypeParam begin, end;
122
123
if
constexpr
(std::same_as<TypeParam, void>)
124
{
125
begin.record();
126
end.record();
127
}
128
else
129
{
130
begin.record(this->exec);
131
end.record(this->exec);
132
}
133
134
TypeParam moved(std::move(end));
// NOLINT(misc-const-correctness,performance-move-const-arg)
135
136
ASSERT_GE(begin.template duration<milliseconds>(moved).count(), 0.);
137
}
138
139
}
// namespace Kokkos::utils::tests::timer
Duration.hpp
Event.hpp
ExecutionSpace.hpp
Kokkos::utils::tests::timer
Definition
test_Event.cpp:28
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:63
Kokkos::utils::tests::timer::TYPED_TEST
TYPED_TEST(EventTest, impl_event_type)
Definition
test_Event.cpp:45
Kokkos::utils::tests::timer::EventTypes
::testing::Types< Event< void >, Event< execution_space > > EventTypes
Definition
test_Event.cpp:37
Kokkos::utils::timer
Definition
Duration.hpp:7
Kokkos::utils::tests::scoped::ExecutionSpace
Create a new execution space instance with RAII semantics.
Definition
ExecutionSpace.hpp:17
Kokkos::utils::tests::timer::EventTest
Definition
test_Event.cpp:35
Kokkos::utils::timer::Event
Event.
Definition
Event.hpp:31
execution_space
Kokkos::DefaultExecutionSpace execution_space
Definition
test_InsertOp.cpp:13
tests
timer
test_Event.cpp
Generated on
for kokkos-utils by
1.18.0