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_Core.hpp"
5
11
12#if !defined(KOKKOS_ENABLE_IMPL_HPX_ASYNC_DISPATCH)
13# error "This is not supported."
14#endif
15
17
18template <>
19struct HasNonBlockingDispatch<Kokkos::Experimental::HPX> : std::true_type { };
20
32template <>
33struct Event<Kokkos::Experimental::HPX> {
34 using sndr_t = hpx::execution::experimental::unique_any_sender<>;
35
36 mutable std::optional<sndr_t> m_sender;
38
39 Event() = default;
40 Event(const Event&) = delete;
41 Event& operator=(const Event&) = delete;
42 Event(Event&&) noexcept = delete;
43 Event& operator=(Event&&) noexcept = delete;
44 ~Event() = default;
45
47 void record(const Kokkos::Experimental::HPX& exec) {
48 KOKKOS_EXPECTS(!m_sender.has_value());
49
50 auto& instance_data = exec.impl_get_instance_data();
51
52 const std::scoped_lock<hpx::spinlock> lock(instance_data.m_sender_mutex);
53
54 m_sender = std::move(instance_data.m_sender);
55
56 instance_data.m_sender = sndr_t(hpx::execution::experimental::just());
57 }
58
71 void wait() const {
72 if (m_sender.has_value()) {
73 hpx::this_thread::experimental::sync_wait(std::move(*m_sender));
74 m_sender = std::nullopt;
75 }
76 }
77};
78
79template <Kokkos::ExecutionSpace... Exec>
80requires(std::same_as<Exec, Kokkos::Experimental::HPX> && ...)
81void impl_wait(const Event<Kokkos::Experimental::HPX>& event, const Event<Exec>&... events) {
82 KOKKOS_EXPECTS(event.m_sender.has_value() && (events.m_sender.has_value() && ...));
83
84 hpx::this_thread::experimental::sync_wait(
85 hpx::execution::experimental::when_all(std::move(*event.m_sender), std::move(*events.m_sender)...));
86
88 event.m_sender = std::nullopt;
89 ((events.m_sender = std::nullopt), ...);
90}
91
92template <Kokkos::ExecutionSpace... ExecFrom>
93requires(std::same_as<ExecFrom, Kokkos::Experimental::HPX> && ...)
94void impl_wait(const Kokkos::Experimental::HPX& exec, const Event<ExecFrom>&... events) {
95 KOKKOS_EXPECTS((events.m_sender.has_value() && ...));
96
97 auto& instance_data = exec.impl_get_instance_data();
98
99 const std::scoped_lock<hpx::spinlock> lock(instance_data.m_sender_mutex);
100
101 auto& sndr = instance_data.m_sender;
102 sndr = hpx::execution::experimental::when_all(std::move(sndr), std::move(*events.m_sender)...);
103
105 ((events.m_sender = std::nullopt), ...);
106}
107
108} // namespace Kokkos::Execution::Impl
109
110#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:26
static constexpr auto invalid_event_id
Definition event.hpp:51
void impl_wait(const Kokkos::Cuda &exec, const Event< ExecFrom > &... events)
Definition event.hpp:54
hpx::execution::experimental::unique_any_sender<> sndr_t
Definition event.hpp:34
void record(const Kokkos::Experimental::HPX &exec)
Steal the head of the underlying sender, and store it in m_sender.
Definition event.hpp:47
An event that can be recorded on an execution space instance.
Definition event.hpp:110
Determine if the Kokkos backend has non-blocking dispatch.
Definition event.hpp:45