kokkos-utils 0.0.1
 
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
8
19
20using execution_space = Kokkos::DefaultExecutionSpace;
21
23{
24
25using namespace Kokkos::utils::timer;
26
27template <typename T>
28struct EventTest : public ::testing::Test,
29 public scoped::ExecutionSpace<execution_space>
30{};
31
32using EventTypes = ::testing::Types<
35>;
36
38
40TYPED_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
58TEST(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
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
93TYPED_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
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
TYPED_TEST_SUITE(EventTest, EventTypes)
::testing::Types< Event< void >, Event< execution_space > > EventTypes
TEST(Event, duration_instances)
TYPED_TEST(EventTest, impl_event_type)
Create a new execution space instance with RAII semantics.
Kokkos::DefaultExecutionSpace execution_space