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 SupportEvents<Kokkos::Experimental::HPX> : std::true_type { };
20
21template <>
22struct Event<Kokkos::Experimental::HPX> {
23 mutable std::optional<Kokkos::Experimental::HPX> m_exec = std::nullopt;
25
26 Event() = default;
27
28 explicit Event(const Kokkos::Experimental::HPX& exec) {
29 record(exec);
30 }
31
32 Event(const Event&) = delete;
33 Event& operator=(const Event&) = delete;
34 Event(Event&& other) noexcept
35 : m_exec(std::move(other.m_exec))
36 , m_event_id(std::exchange(other.m_event_id, invalid_event_id)) {
37 }
38 Event& operator=(Event&& other) noexcept {
39 if (this != &other) {
40 m_exec = std::move(other.m_exec);
41 m_event_id = std::exchange(other.m_event_id, invalid_event_id);
42 }
43 return *this;
44 }
45 ~Event() = default;
46
47 void record(const Kokkos::Experimental::HPX& exec) {
48 m_exec = exec;
50 }
51
67 void wait() const {
69 if (m_exec.has_value()) {
70 auto& instance_data = m_exec->impl_get_instance_data();
71
72 {
73 const std::lock_guard<hpx::spinlock> lock(instance_data.m_sender_mutex);
74
75 auto& sndr = instance_data.m_sender;
76 hpx::this_thread::experimental::sync_wait(std::move(sndr));
77 sndr = hpx::execution::experimental::unique_any_sender<>(hpx::execution::experimental::just());
78 }
79
80 m_exec = std::nullopt;
81 }
82 }
83};
84
85Event(const Kokkos::Experimental::HPX&) -> Event<Kokkos::Experimental::HPX>;
86
87} // namespace Kokkos::Execution::Impl
88
89#endif // KOKKOS_EXECUTION_IMPL_HPX_EVENT_HPP
static constexpr auto invalid_event_id
Definition event.hpp:43
void record_event(const Exec &exec, uint64_t &event_id)
Definition event.hpp:54
Event(const Kokkos::Cuda &) -> Event< Kokkos::Cuda >
void wait_event(const uint64_t event_id)
Definition event.hpp:69
Event(const Kokkos::Experimental::HPX &exec)
Definition event.hpp:28
std::optional< Kokkos::Experimental::HPX > m_exec
Definition event.hpp:23
void record(const Kokkos::Experimental::HPX &exec)
Definition event.hpp:47
An event that can be recorded on an execution space instance.
Definition event.hpp:34
Determine if events are supported.
Definition event.hpp:38