kokkos-execution 0.0.1
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_IMPL_HPX_EVENT_HPP
2#define KOKKOS_EXECUTION_IMPL_HPX_EVENT_HPP
3
4#include "Kokkos_Macros.hpp"
5#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
6import kokkos.core;
7# include "Kokkos_Assert.hpp"
8#else
9# include "Kokkos_Core.hpp"
10#endif
11
17
18#if !defined(KOKKOS_ENABLE_IMPL_HPX_ASYNC_DISPATCH)
19# error "This is not supported."
20#endif
21
23
24template <>
25struct HasNonBlockingDispatch<Kokkos::Experimental::HPX> : std::true_type { };
26
38template <>
39struct Event<Kokkos::Experimental::HPX> {
40 using sndr_t = hpx::execution::experimental::unique_any_sender<>;
41
42 mutable std::optional<sndr_t> m_sender;
43 uint64_t m_event_id = invalid_event_id;
44
45 Event() = default;
46 Event(const Event&) = delete;
47 Event& operator=(const Event&) = delete;
48 Event(Event&&) noexcept = delete;
49 Event& operator=(Event&&) noexcept = delete;
50 ~Event() = default;
51
53 void record(const Kokkos::Experimental::HPX& exec) {
54 KOKKOS_EXPECTS(!m_sender.has_value());
55
56 auto& instance_data = exec.impl_get_instance_data();
57
58 const std::scoped_lock<hpx::spinlock> lock(instance_data.m_sender_mutex);
59
60 m_sender = std::move(instance_data.m_sender);
61
62 instance_data.m_sender = sndr_t(hpx::execution::experimental::just());
63 }
64
77 void wait() const {
78 if (m_sender.has_value()) {
79 hpx::this_thread::experimental::sync_wait(std::move(*m_sender));
80 m_sender = std::nullopt;
81 }
82 }
83};
84
85template <Kokkos::ExecutionSpace... Exec>
86requires(std::same_as<Exec, Kokkos::Experimental::HPX> && ...)
87void impl_wait(const Event<Kokkos::Experimental::HPX>& event, const Event<Exec>&... events) {
88 KOKKOS_EXPECTS(event.m_sender.has_value() && (events.m_sender.has_value() && ...));
89
90 hpx::this_thread::experimental::sync_wait(
91 hpx::execution::experimental::when_all(std::move(*event.m_sender), std::move(*events.m_sender)...));
92
94 event.m_sender = std::nullopt;
95 ((events.m_sender = std::nullopt), ...);
96}
97
98template <Kokkos::ExecutionSpace... ExecFrom>
99requires(std::same_as<ExecFrom, Kokkos::Experimental::HPX> && ...)
100void impl_wait(const Kokkos::Experimental::HPX& exec, const Event<ExecFrom>&... events) {
101 KOKKOS_EXPECTS((events.m_sender.has_value() && ...));
102
103 auto& instance_data = exec.impl_get_instance_data();
104
105 const std::scoped_lock<hpx::spinlock> lock(instance_data.m_sender_mutex);
106
107 auto& sndr = instance_data.m_sender;
108 sndr = hpx::execution::experimental::when_all(std::move(sndr), std::move(*events.m_sender)...);
109
111 ((events.m_sender = std::nullopt), ...);
112}
113
114} // namespace Kokkos::Execution::Impl
115
116#endif // KOKKOS_EXECUTION_IMPL_HPX_EVENT_HPP
Constrain an EventType type to be a valid event type for Exec execution space type.
Definition event.hpp:31
void impl_wait(const Kokkos::Cuda &exec, const Event< ExecFrom > &... events)
Definition event.hpp:60
hpx::execution::experimental::unique_any_sender<> sndr_t
Definition event.hpp:40
void record(const Kokkos::Experimental::HPX &exec)
Steal the head of the underlying sender, and store it in m_sender.
Definition event.hpp:53
An event that can be recorded on an execution space instance.
Definition event.hpp:115
Determine if the Kokkos backend has non-blocking dispatch.
Definition event.hpp:50