1#include "gtest/gtest.h"
3#include "Kokkos_Core.hpp"
23using namespace Kokkos::utils::timer;
45 ASSERT_FALSE(
timer.is_valid());
55 timer.reset(this->exec);
56 ASSERT_FALSE(
timer.is_valid());
66 timer.stop(this->exec);
67 ASSERT_FALSE(
timer.is_valid());
77 timer.reset(this->exec);
78 timer.stop (this->exec);
79 ASSERT_TRUE(
timer.is_valid());
88 using view_t = Kokkos::View<double*, execution_space>;
90 Kokkos::Timer timer_external;
93 timer_external.reset();
94 timer.reset(this->exec);
96 const view_t my_view(Kokkos::view_alloc(Kokkos::WithoutInitializing, this->exec,
"my view"), 10);
97 Kokkos::deep_copy(exec, my_view, 1.0);
99 timer.stop(this->exec);
108 const auto elapsed_external = timer_external.seconds();
110 ASSERT_LE(elapsed, elapsed_external);
111 ASSERT_GE(elapsed, 0.);
112 ASSERT_GE(elapsed_external, 0.);
120 timer.reset(this->exec);
122 std::this_thread::sleep_for(std::chrono::milliseconds(100));
124 timer.stop(this->exec);
129 ASSERT_GE(elapsed, 100.);
133 ASSERT_NEAR(duration_ms.count(), elapsed, 1e-3);
137 ASSERT_NEAR(duration_us.count(), elapsed * 1e3, 1.);
141 ASSERT_NEAR(duration_se.count(), elapsed / 1e3, 1e-6);
144 ASSERT_LE(abs(duration_ms - duration_us), std::chrono::microseconds(1));
145 ASSERT_LE(abs(duration_ms - duration_se), std::chrono::microseconds(1));
171 constexpr size_t nreps = 10;
173 constexpr std::chrono::milliseconds wait(14);
177 for(
size_t irep = 0; irep < nreps; ++irep)
179 const Kokkos::Timer timer_external;
181 timer.reset(this->exec);
183 this->exec.fence(
"ensure that the event 'started'");
185 std::this_thread::sleep_for(wait);
187 timer.stop(this->exec);
191 const seconds elapsed_external(timer_external.seconds());
196 ASSERT_GE(elapsed, wait);
197 ASSERT_LE(elapsed, elapsed_external);
Measure elapsed time between events.
Timer< execution_space > timer_t
TEST_F(TimerTest, invalid_if_not_reset_and_not_stopped)
std::chrono::duration< double, std::ratio< 1, 1 > > seconds
Similar to std::chrono::seconds, but using double instead of an integer type to represent the tick co...
std::chrono::duration< double, std::micro > microseconds
std::chrono::duration< double, std::milli > milliseconds
Similar to std::chrono::milliseconds, but using double instead of an integer type to represent the ti...
Kokkos::DefaultExecutionSpace execution_space