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_Core.hpp"
8
10
18
19// NOLINTBEGIN(cppcoreguidelines-macro-usage)
20#define MATCHER_FOR_NAME(_type_, _name_) \
21 ::testing::Field(&Kokkos::utils::callbacks::_type_##Event::name, ::testing::StrEq(_name_))
22
23#define MATCHER_FOR_DEV_ID(_type_, _exec_) \
24 ::testing::Field( \
25 &Kokkos::utils::callbacks::_type_##Event::dev_id, \
26 ::testing::Eq(Kokkos::Tools::Experimental::device_id(_exec_)))
27
28#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_) \
29 ABeginFenceEvent(MATCHER_FOR_NAME(BeginFence, _label_), MATCHER_FOR_DEV_ID(BeginFence, _exec_))
30#define MATCHER_FOR_BEGIN_PFOR(_exec_, _label_) \
31 ABeginParallelForEvent(MATCHER_FOR_NAME(BeginParallelFor, _label_), MATCHER_FOR_DEV_ID(BeginParallelFor, _exec_))
32#define MATCHER_FOR_BEGIN_PRED(_exec_, _label_) \
33 ABeginParallelReduceEvent( \
34 MATCHER_FOR_NAME(BeginParallelReduce, _label_), MATCHER_FOR_DEV_ID(BeginParallelReduce, _exec_))
35#define MATCHER_FOR_PUSH_REGION(_label_) APushRegionEventWithName(::testing::StrEq(_label_))
36#define MATCHER_FOR_POP_REGION() APopRegionEvent()
37
38#define MATCHER_FOR_BEGIN_DEEP_COPY(_dst_, _src_) \
39 ABeginDeepCopyEvent( \
40 Kokkos::utils::callbacks::PartialMatcher<Kokkos::utils::callbacks::BeginDeepCopyEvent>{}( \
41 Kokkos::utils::callbacks::BeginDeepCopyEvent{ \
42 .dst = KOKKOS_IMPL_STRIP_PARENS(_dst_), .src = KOKKOS_IMPL_STRIP_PARENS(_src_)}))
43// NOLINTEND(cppcoreguidelines-macro-usage)
44
46template <Kokkos::ExecutionSpace Exec, std::convertible_to<std::string_view> Label>
47constexpr std::string dispatch_label(const Exec&, Label&& label) {
48 return std::string(Kokkos::Impl::TypeInfo<Exec>::name()).append(": ").append(std::forward<Label>(label));
49}
50
51#if defined(KOKKOS_EXECUTION_IMPL_EVENT_HPP)
54#endif
55
56// NOLINTBEGIN(cppcoreguidelines-macro-usage)
57#define MATCHER_FOR_RECORD_EVENT(_exec_) \
58 ARecordEvent( \
59 ::testing::Field( \
60 &Kokkos::Execution::Impl::RecordEvent::dev_id, \
61 ::testing::Eq(Kokkos::Tools::Experimental::device_id(_exec_))))
62
63#define MATCHER_FOR_WAIT_EVENT(_record_event_variant_) \
64 AWaitEvent( \
65 ::testing::Field( \
66 &Kokkos::Execution::Impl::WaitEvent::event_id, \
67 ::testing::Eq(std::get<Kokkos::Execution::Impl::RecordEvent>(_record_event_variant_).event_id)), \
68 ::testing::Field( \
69 &Kokkos::Execution::Impl::WaitEvent::dev_id, ::testing::Eq(Kokkos::Execution::Impl::invalid_dev_id)))
70
71#define MATCHER_FOR_WAIT_EXEC_EVENT(_exec_, _record_event_variant_) \
72 AWaitEvent( \
73 ::testing::Field( \
74 &Kokkos::Execution::Impl::WaitEvent::event_id, \
75 ::testing::Eq(std::get<Kokkos::Execution::Impl::RecordEvent>(_record_event_variant_).event_id)), \
76 ::testing::Field( \
77 &Kokkos::Execution::Impl::WaitEvent::dev_id, \
78 ::testing::Eq(Kokkos::Tools::Experimental::device_id(_exec_))))
79// NOLINTEND(cppcoreguidelines-macro-usage)
80
82template <Kokkos::ExecutionSpace Exec>
84#if defined(KOKKOS_ENABLE_SYCL)
87 requires std::same_as<Exec, Kokkos::SYCL>
88 {
89 return event.name.find("Kokkos::SYCLInternal::USMObject") == std::string::npos;
90 }
91
94 requires std::same_as<Exec, Kokkos::SYCL>
95 {
96 return event.alloc.name.find("Kokkos::SYCL::USMObject") == std::string::npos;
97 }
98#endif
99#if defined(KOKKOS_ENABLE_THREADS)
102 return event.name.find("Kokkos::ThreadsInternal::fence: Unnamed Instance Fence") == std::string::npos;
103 }
104#endif
105
106#if defined(KOKKOS_ENABLE_HPX)
115 requires std::same_as<Exec, Kokkos::Experimental::HPX>
116 {
117 return event.name != "Kokkos::Experimental::HPX: fence on destruction";
118 }
119#endif
120
121 template <Kokkos::utils::callbacks::Event EventType>
122 constexpr bool operator()(const EventType&) const {
123 return true;
124 }
125};
126
127#endif // KOKKOS_EXECUTION_TESTS_UTILS_CALLBACK_MATCHERS_HPP
constexpr std::string dispatch_label(const Exec &, Label &&label)
Get the dispatch label from Exec and label.
#define DEFINE_EVENT_MATCHER_IN(__namespace__, __eventtype__)
Matcher to filter out events that are just noise for tests.
constexpr bool operator()(const EventType &) const