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_Macros.hpp"
9#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
10import kokkos.core;
11#else
12# include "Kokkos_Core.hpp"
13#endif
14
15#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
16# include "plog/Formatters/TxtFormatter.h"
17# include "plog/Initializers/ConsoleInitializer.h"
18# include "plog/Log.h"
19#endif
20
22
25
26namespace Tests::Utils {
27
28template <template <typename> typename ContextType, Kokkos::ExecutionSpace Exec>
30 : public virtual testing::Test
32 public:
33 using context_t = ContextType<Exec>;
34 using scheduler_t = decltype(std::declval<const context_t>().get_scheduler());
35 using schedule_sender_t = decltype(stdexec::schedule(std::declval<scheduler_t>()));
36
37 using value_t = int;
38 using view_s_t = Kokkos::View<value_t, Kokkos::SharedSpace>;
39 using view_um_s_t = Kokkos::View<value_t, Kokkos::SharedSpace, Kokkos::MemoryUnmanaged>;
40
41 static constexpr bool on_device = Tests::Utils::on_device<Exec>();
42
43 public:
44#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
45 static void SetUpTestSuite() {
46 plog::init<plog::TxtFormatter>(plog::debug, plog::streamStdOut);
47 }
48#endif
49};
50
51#if defined(KOKKOS_ENABLE_THREADS)
64# define KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT(_sndr_) \
65 ASSERT_THAT( \
66 Tests::Utils::Functors::MutableMoveToSyncWait{.sndr = std::move(_sndr_)}, \
67 ::testing::ThrowsMessage<std::runtime_error>( \
68 ::testing::HasSubstr("Called by a worker thread, can only be called by the master process.")));
69# define KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT_AND_SKIP(_sndr_) \
70 if constexpr (std::same_as<TEST_EXECUTION_SPACE, Kokkos::Threads>) { \
71 KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT(_sndr_) \
72 GTEST_SKIP() \
73 << "Kokkos::Threads parallel regions must be launched from the thread that initialized " "Kokkos."; \
74 }
75#else
76# define KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT_AND_SKIP(_sndr_)
77#endif
78
79} // namespace Tests::Utils
80
81#endif // KOKKOS_EXECUTION_TESTS_UTILS_CONTEXT_HPP
constexpr bool on_device()
Definition kokkos.hpp:27
decltype(std::declval< const context_t >().get_scheduler()) scheduler_t
Definition context.hpp:34
decltype(stdexec::schedule(std::declval< scheduler_t >())) schedule_sender_t
Definition context.hpp:35
Kokkos::View< value_t, Kokkos::SharedSpace, Kokkos::MemoryUnmanaged > view_um_s_t
Definition context.hpp:39
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Definition context.hpp:38
ContextType< Exec > context_t
Definition context.hpp:33
static constexpr bool on_device
Definition context.hpp:41