kokkos-utils 0.0.7
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
5import kokkos.core;
6#else
7#include "Kokkos_Core.hpp"
8#endif
9
13
24
25using execution_space = Kokkos::DefaultExecutionSpace;
26
28{
29
30using namespace Kokkos::utils::timer;
31
32template <typename T>
33struct EventTest : public ::testing::Test,
34 public scoped::ExecutionSpace<execution_space>
35{};
36
37using EventTypes = ::testing::Types<
40>;
41
43
45TYPED_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
63TEST(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
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
98TYPED_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
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
TYPED_TEST_SUITE(EventTest, EventTypes)
TEST(Event, duration_instances)
TYPED_TEST(EventTest, impl_event_type)
::testing::Types< Event< void >, Event< execution_space > > EventTypes
Create a new execution space instance with RAII semantics.
Kokkos::DefaultExecutionSpace execution_space