kokkos-execution 0.0.1
Loading...
Searching...
No Matches
context.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_TESTS_UTILS_CONTEXT_HPP
2#define KOKKOS_EXECUTION_TESTS_UTILS_CONTEXT_HPP
3
4#include "gtest/gtest.h"
5
7
8#include "Kokkos_Core.hpp"
9
10#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
11# include "plog/Formatters/TxtFormatter.h"
12# include "plog/Initializers/ConsoleInitializer.h"
13# include "plog/Log.h"
14#endif
15
17
19
20namespace Tests::Utils {
21
22template <template <typename> typename ContextType, Kokkos::ExecutionSpace Exec>
24 : public virtual testing::Test
26 public:
27 using context_t = ContextType<Exec>;
28 using scheduler_t = decltype(std::declval<const context_t>().get_scheduler());
29 using schedule_sender_t = decltype(stdexec::schedule(std::declval<scheduler_t>()));
30
31 using value_t = int;
32 using view_s_t = Kokkos::View<value_t, Kokkos::SharedSpace>;
33
35
36 public:
37#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
38 static void SetUpTestSuite() {
39 plog::init<plog::TxtFormatter>(plog::debug, plog::streamStdOut);
40 }
41#endif
42};
43
44#if defined(KOKKOS_ENABLE_THREADS)
57# define KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT(_sndr_) \
58 ASSERT_THAT( \
59 Tests::Utils::Functors::MutableMoveToSyncWait{.sndr = std::move(_sndr_)}, \
60 ::testing::ThrowsMessage<std::runtime_error>( \
61 ::testing::HasSubstr("Called by a worker thread, can only be called by the master process.")));
62# define KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT_AND_SKIP(_sndr_) \
63 if constexpr (std::same_as<TEST_EXECUTION_SPACE, Kokkos::Threads>) { \
64 KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT(_sndr_) \
65 GTEST_SKIP() \
66 << "Kokkos::Threads parallel regions must be launched from the thread that initialized " "Kokkos."; \
67 }
68#else
69# define KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT_AND_SKIP(_sndr_)
70#endif
71
72} // namespace Tests::Utils
73
74#endif // KOKKOS_EXECUTION_TESTS_UTILS_CONTEXT_HPP
constexpr bool on_device()
Definition kokkos.hpp:22
decltype(std::declval< const context_t >().get_scheduler()) scheduler_t
Definition context.hpp:28
decltype(stdexec::schedule(std::declval< scheduler_t >())) schedule_sender_t
Definition context.hpp:29
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Definition context.hpp:32
ContextType< Exec > context_t
Definition context.hpp:27
static constexpr bool on_device
Definition context.hpp:34