1#include "gmock/gmock.h"
3#include "Kokkos_Core.hpp"
33using namespace Kokkos::utils::callbacks;
48 static_assert(std::same_as<
50 Kokkos::Impl::type_list<BeginParallelForEvent, EndParallelForEvent>
53 static_assert(Listener<parallel_for_timer_t>);
64 ASSERT_FALSE(par_for_timer.
closed());
75 .name =
"my-name", .dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id = 1
78 ASSERT_FALSE(par_for_timer.
closed());
90 .name =
"my-name", .dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id = 1
95 ASSERT_TRUE(par_for_timer.
closed());
97 par_for_timer.
reset();
99 ASSERT_FALSE(par_for_timer.
closed());
102 .name =
"my-name", .dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id = 2
105 ASSERT_FALSE(par_for_timer.
closed());
114 const auto other_exec = Kokkos::Experimental::partition_space(
execution_space{}, 1)[0];
115 const auto other_exec_dev_id = Kokkos::Tools::Experimental::device_id(other_exec);
116 const auto exec_dev_id = Kokkos::Tools::Experimental::device_id( exec);
120 .name =
"my-name", .dev_id = other_exec_dev_id, .event_id = 1
122 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 <<
'.';
128 const auto par_for_timer_matching = std::make_shared<parallel_for_timer_t>(
129 std::regex(
"computation - level 0 - pfor"), exec
131 const auto par_for_timer_no_match = std::make_shared<parallel_for_timer_t>(
132 std::regex(
"this-should-not-match"), exec
142 EXPECT_FALSE(par_for_timer_no_match->connected() || par_for_timer_no_match->closed())
143 <<
"The listener should not be connected or closed because the events did not match.";
158 const auto par_for_timer = std::make_shared<parallel_for_with_launch_timer_t>(
159 "computation - level 0 - pfor", exec
164 timer_external.
start();
168 timer_external.
stop();
170 ASSERT_GT(par_for_timer->timer.duration(), unit_t{0.});
171 ASSERT_GT(par_for_timer->timer.launch(), unit_t{0.});
172 ASSERT_LE(par_for_timer->timer.launch(), timer_external.
duration());
185 static_assert(std::same_as<
187 Kokkos::Impl::type_list<PushRegionEvent, PopRegionEvent>
190 static_assert(Listener<region_timer_t>);
206 const auto par_for_timer = std::make_shared<parallel_for_timer_t>(
207 std::regex(
"computation - level 0 - pfor"), exec
210 const auto region_timer = std::make_shared<region_timer_t>(
211 std::regex(
"computation - level 0")
220 ASSERT_LT(par_for_timer->timer.duration(), region_timer->timer.duration());
234 static_assert(std::constructible_from<
235 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
Kokkos::Impl::filter_type_list_t< impl::IsListenerFor< Callable >::template type, EventTypeList > 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