kokkos-execution 0.0.1
Loading...
Searching...
No Matches
callback_matchers.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_TESTS_UTILS_CALLBACK_MATCHERS_HPP
2#define KOKKOS_EXECUTION_TESTS_UTILS_CALLBACK_MATCHERS_HPP
3
4#include <string>
5#include <string_view>
6
7#include "Kokkos_Macros.hpp"
8#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
9import kokkos.core;
10#else
11# include "Kokkos_Core.hpp"
12#endif
13
15
17
25
26// NOLINTBEGIN(cppcoreguidelines-macro-usage)
27#define MATCHER_FOR_NAME(_type_, _name_) \
28 ::testing::Field(&Kokkos::utils::callbacks::_type_##Event::name, ::testing::StrEq(_name_))
29
30#define MATCHER_FOR_DEV_ID(_type_, _exec_) \
31 ::testing::Field( \
32 &Kokkos::utils::callbacks::_type_##Event::dev_id, \
33 ::testing::Eq(Kokkos::Tools::Experimental::device_id(_exec_)))
34
35#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_) \
36 ABeginFenceEvent(MATCHER_FOR_NAME(BeginFence, _label_), MATCHER_FOR_DEV_ID(BeginFence, _exec_))
37#define MATCHER_FOR_BEGIN_PFOR(_exec_, _label_) \
38 ABeginParallelForEvent(MATCHER_FOR_NAME(BeginParallelFor, _label_), MATCHER_FOR_DEV_ID(BeginParallelFor, _exec_))
39#define MATCHER_FOR_BEGIN_PRED(_exec_, _label_) \
40 ABeginParallelReduceEvent( \
41 MATCHER_FOR_NAME(BeginParallelReduce, _label_), MATCHER_FOR_DEV_ID(BeginParallelReduce, _exec_))
42#define MATCHER_FOR_BEGIN_SINGLE(_exec_, _label_) \
43 ABeginSingleEvent(MATCHER_FOR_NAME(BeginSingle, _label_), MATCHER_FOR_DEV_ID(BeginSingle, _exec_))
44#define MATCHER_FOR_PUSH_REGION(_label_) APushRegionEventWithName(::testing::StrEq(_label_))
45#define MATCHER_FOR_POP_REGION() APopRegionEvent()
46
47#define MATCHER_FOR_BEGIN_DEEP_COPY(_dst_, _src_) \
48 ABeginDeepCopyEvent( \
49 Kokkos::utils::callbacks::PartialMatcher<Kokkos::utils::callbacks::BeginDeepCopyEvent>{}( \
50 Kokkos::utils::callbacks::BeginDeepCopyEvent{ \
51 .dst = KOKKOS_IMPL_STRIP_PARENS(_dst_), .src = KOKKOS_IMPL_STRIP_PARENS(_src_)}))
52
53// NOLINTEND(cppcoreguidelines-macro-usage)
54
56template <Kokkos::ExecutionSpace Exec>
57constexpr std::string dispatch_label(const Exec&, const std::string_view label) {
58 constexpr std::string_view prefix{Kokkos::Execution::Impl::display_string_of<Exec>()};
59
60 std::string result;
61 result.reserve(prefix.size() + 2 + label.size());
62 result.append(prefix).append(": ").append(label);
63 return result;
64}
65
66#if defined(KOKKOS_EXECUTION_IMPL_EVENT_HPP)
69#endif
70
71// NOLINTBEGIN(cppcoreguidelines-macro-usage)
72#define MATCHER_FOR_RECORD_EVENT(_exec_) \
73 ARecordEvent( \
74 ::testing::Field( \
75 &Kokkos::Execution::Impl::RecordEvent::dev_id, \
76 ::testing::Eq(Kokkos::Tools::Experimental::device_id(_exec_))))
77
78#define MATCHER_FOR_WAIT_EVENT(_record_event_variant_) \
79 AWaitEvent( \
80 ::testing::Field( \
81 &Kokkos::Execution::Impl::WaitEvent::event_id, \
82 ::testing::Eq(std::get<Kokkos::Execution::Impl::RecordEvent>(_record_event_variant_).event_id)), \
83 ::testing::Field( \
84 &Kokkos::Execution::Impl::WaitEvent::dev_id, ::testing::Eq(Kokkos::Execution::Impl::invalid_dev_id)))
85
86#define MATCHER_FOR_WAIT_EXEC_EVENT(_exec_, _record_event_variant_) \
87 AWaitEvent( \
88 ::testing::Field( \
89 &Kokkos::Execution::Impl::WaitEvent::event_id, \
90 ::testing::Eq(std::get<Kokkos::Execution::Impl::RecordEvent>(_record_event_variant_).event_id)), \
91 ::testing::Field( \
92 &Kokkos::Execution::Impl::WaitEvent::dev_id, \
93 ::testing::Eq(Kokkos::Tools::Experimental::device_id(_exec_))))
94
95// NOLINTEND(cppcoreguidelines-macro-usage)
96
98template <Kokkos::ExecutionSpace Exec>
100#if defined(KOKKOS_ENABLE_SYCL)
103 requires std::same_as<Exec, Kokkos::SYCL>
104 {
105 return event.name.find("Kokkos::SYCLInternal::USMObject") == std::string::npos;
106 }
107
110 requires std::same_as<Exec, Kokkos::SYCL>
111 {
112 return event.alloc.name.find("Kokkos::SYCL::USMObject") == std::string::npos;
113 }
114#endif
115#if defined(KOKKOS_ENABLE_THREADS)
118 return event.name.find("Kokkos::ThreadsInternal::fence: Unnamed Instance Fence") == std::string::npos;
119 }
120#endif
121
122#if defined(KOKKOS_ENABLE_HPX)
130 static constexpr bool hpx_on_destruction(const Kokkos::utils::callbacks::BeginFenceEvent& event) noexcept {
131 return event.name != "Kokkos::Experimental::HPX: fence on destruction";
132 }
133
134 bool operator()(const Kokkos::utils::callbacks::BeginFenceEvent& event) const noexcept
135 requires std::same_as<Exec, Kokkos::Experimental::HPX>
136 {
137 return hpx_on_destruction(event);
138 }
139#endif
140
141 template <Kokkos::utils::callbacks::Event EventType>
142 constexpr bool operator()(const EventType&) const {
143 return true;
144 }
145};
146
147#endif // KOKKOS_EXECUTION_TESTS_UTILS_CALLBACK_MATCHERS_HPP
constexpr std::string dispatch_label(const Exec &, const std::string_view label)
Get the dispatch label from Exec and label.
#define DEFINE_EVENT_MATCHER_IN(__namespace__, __eventtype__)
constexpr auto display_string_of() noexcept -> std::string_view
Definition type_info.hpp:20
Matcher to filter out events that are just noise for tests.
constexpr bool operator()(const EventType &) const