1#include "gmock/gmock.h"
3#include "Kokkos_Macros.hpp"
4#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
7#include "Kokkos_Core.hpp"
38using namespace Kokkos::utils::callbacks;
53 static_assert(std::same_as<
55 Kokkos::Impl::type_list<BeginParallelForEvent, EndParallelForEvent>
58 static_assert(Listener<parallel_for_timer_t>);
69 ASSERT_FALSE(par_for_timer.
closed());
80 .name =
"my-name", .dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id = 1
83 ASSERT_FALSE(par_for_timer.
closed());
95 .name =
"my-name", .dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id = 1
100 ASSERT_TRUE(par_for_timer.
closed());
102 par_for_timer.
reset();
104 ASSERT_FALSE(par_for_timer.
closed());
107 .name =
"my-name", .dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id = 2
110 ASSERT_FALSE(par_for_timer.
closed());
119 const auto other_exec = Kokkos::Experimental::partition_space(
execution_space{}, 1)[0];
120 const auto other_exec_dev_id = Kokkos::Tools::Experimental::device_id(other_exec);
121 const auto exec_dev_id = Kokkos::Tools::Experimental::device_id( exec);
125 .name =
"my-name", .dev_id = other_exec_dev_id, .event_id = 1
127 ASSERT_EQ(par_for_timer.
connected(), other_exec_dev_id == exec_dev_id) <<
"The event was enqueued on " << other_exec_dev_id <<
" and the timer should look at events on " << exec_dev_id <<
'.';
133 const auto par_for_timer_matching = std::make_shared<parallel_for_timer_t>(
134 std::regex(
"computation - level 0 - pfor"), exec
136 const auto par_for_timer_no_match = std::make_shared<parallel_for_timer_t>(
137 std::regex(
"this-should-not-match"), exec
147 EXPECT_FALSE(par_for_timer_no_match->connected() || par_for_timer_no_match->closed())
148 <<
"The listener should not be connected or closed because the events did not match.";
163 const auto par_for_timer = std::make_shared<parallel_for_with_launch_timer_t>(
164 "computation - level 0 - pfor", exec
169 timer_external.
start();
173 timer_external.
stop();
175 ASSERT_GT(par_for_timer->timer.duration(), unit_t{0.});
176 ASSERT_GT(par_for_timer->timer.launch(), unit_t{0.});
177 ASSERT_LE(par_for_timer->timer.launch(), timer_external.
duration());
190 static_assert(std::same_as<
192 Kokkos::Impl::type_list<PushRegionEvent, PopRegionEvent>
195 static_assert(Listener<region_timer_t>);
211 const auto par_for_timer = std::make_shared<parallel_for_timer_t>(
212 std::regex(
"computation - level 0 - pfor"), exec
215 const auto region_timer = std::make_shared<region_timer_t>(
216 std::regex(
"computation - level 0")
225 ASSERT_LT(par_for_timer->timer.duration(), region_timer->timer.duration());
239 static_assert(std::constructible_from<
240 region_timer_with_enqueued_event_timer_t,
static void unregister_listener(const Callable *const callable)
Unregister a callable object as a listener.
static listener_list_const_iter_t register_listener(std::shared_ptr< Callable > callable)
Register a callable object, passed as a shared pointer, as a listener.
Measure elapsed time between events.
void stop()
Stop the timer.
void start()
Start the timer.
BeginEndTimerListener< MatcherType, BeginParallelForEvent, Exec, EnqueuedEventWithLaunchTimer< Exec > > ParallelForWithLaunchTimerListener
typename impl::ListenerEventTypeList< Callable >::type listener_event_type_list_t
Type list holding the event types that Callable can be a listener for.
BeginEndTimerListener< MatcherType, BeginParallelForEvent, Exec > ParallelForTimerListener
RegionTimerListener< EventRegexMatcher > region_timer_t
Listener to time regions whose name matches a regex.
TEST_F(EnqueuedEventTimerTest, duration)
ParallelForTimerListener< EventRegexMatcher, execution_space > parallel_for_timer_t
Listener to time parallel for regions whose name matches a regex.
TEST(EventTest, BeginEvent)
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
Similar to std::chrono::microseconds, but using double instead of an integer type to represent the ti...
std::chrono::duration< double, std::milli > milliseconds
Similar to std::chrono::milliseconds, but using double instead of an integer type to represent the ti...
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
Timer for events that are enqueued on exec.
Matcher to select events whose name matches a regular expression.
Timer listener for a profiling region that matches MatcherType.
void reset()
Reset the listener so that it can be reused to match a begin event again.
bool closed() const
When the listener has matched both the begin and end events, it is said to be "closed".
bool connected() const
When the listener has matched the begin, but not yet the end event, it is said to be "connected".
void execute(const Exec &exec) const
Create a new execution space instance with RAII semantics.
Initializing and finalizing Kokkos::utils::callbacks::Manager in a RAII manner.
Kokkos::DefaultExecutionSpace execution_space