kokkos-execution 0.0.1
Loading...
Searching...
No Matches
scoped_region.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_EXECUTION_SPACE_SCOPED_REGION_HPP
2#define KOKKOS_EXECUTION_EXECUTION_SPACE_SCOPED_REGION_HPP
3
4#include <format>
5
7
8#include "impl/Kokkos_Profiling.hpp"
9
11
17
26
28
30enum class Kind : std::uint8_t {
33};
34
35template <Kind kind, stdexec::__is_instance_of<Scheduler> Schd, stdexec::receiver Rcvr>
37 using receiver_concept = stdexec::receiver_tag;
38
39 std::string name;
40 Schd schd;
41 Rcvr rcvr;
42
43 template <typename Tag, typename... Args>
44 void complete(Tag tag, Args&&... args) && noexcept {
45 schd.state->exec.fence(
46 std::format(
47 "{}: {}",
48 Kokkos::Impl::TypeInfo<typename Schd::execution_space>::name(),
49 kind == Kind::PUSH ? "push" : "pop"));
50
51 if constexpr (kind == Kind::PUSH) {
52 Kokkos::Profiling::pushRegion(name);
53 } else {
54 Kokkos::Profiling::popRegion();
55 }
56
57 std::invoke(tag, std::move(rcvr), std::forward<Args>(args)...);
58 }
59
60 void set_value() && noexcept {
61 std::move(*this).complete(stdexec::set_value);
62 }
63
64 template <typename Error>
65 void set_error(Error&& err) && noexcept {
66 std::move(*this).complete(stdexec::set_error, std::forward<Error>(err));
67 }
68
70};
71
72template <Kind kind, stdexec::sender Sndr>
74 using sender_concept = stdexec::sender_tag;
75
77
78 template <typename Rcvr>
80
81 template <typename Rcvr>
83
84 template <stdexec::__decays_to<RegionSender> Self, stdexec::receiver Rcvr>
85 [[nodiscard]]
86 constexpr STDEXEC_EXPLICIT_THIS_BEGIN(
87 auto connect)(this Self&& self, Rcvr rcvr) // NOLINT(cppcoreguidelines-missing-std-forward)
88 noexcept(
89 std::is_nothrow_constructible_v<
93 Rcvr&&
94 >
95 && stdexec::__nothrow_connectable<KOKKOS_EXECUTION_IMPL_MEMBER_CVREF_T(Self, sndr), rcvr_t<Rcvr>&&>)
96 -> stdexec::connect_result_t<KOKKOS_EXECUTION_IMPL_MEMBER_CVREF_T(Self, sndr), rcvr_t<Rcvr>&&> {
97 auto schd = stdexec::get_completion_scheduler<stdexec::set_value_t>(
98 stdexec::get_env(self.sndr), stdexec::get_env(rcvr));
99
100 return stdexec::connect(
103 .name = KOKKOS_EXECUTION_IMPL_FORWARD_THIS(Self, self).name,
104 .schd = std::move(schd),
105 .rcvr = std::move(rcvr)});
106 }
107 STDEXEC_EXPLICIT_THIS_END(connect)
108
109 std::string name{};
110 Sndr sndr;
111
113};
114
115struct Push {
116 template <stdexec::sender Sndr, typename T>
117 auto operator()(Sndr&& sndr, T&& name) const noexcept -> RegionSender<Kind::PUSH, Sndr> {
118 return {.name = std::forward<T>(name), .sndr = std::forward<Sndr>(sndr)};
119 }
120
121 template <typename T>
122 auto operator()(T&& name) const noexcept {
123 return stdexec::__closure{*this, std::forward<T>(name)};
124 }
125};
126
127struct Pop {
128 template <stdexec::sender Sndr>
129 auto operator()(Sndr&& sndr) const noexcept -> RegionSender<Kind::POP, Sndr> {
130 return {.sndr = std::forward<Sndr>(sndr)};
131 }
132
133 auto operator()() const noexcept {
134 return stdexec::__closure{*this};
135 }
136};
137
140 template <stdexec::sender Sndr, typename T, stdexec::__sender_adaptor_closure Closure>
141 auto operator()(Sndr&& sndr, T&& name, Closure&& closure) const noexcept {
142 return std::forward<Sndr>(sndr) | Push{}(std::forward<T>(name)) | std::forward<Closure>(closure) | Pop{}();
143 }
144
145 template <typename T, stdexec::__sender_adaptor_closure Closure>
146 auto operator()(T&& name, Closure&& closure) const noexcept {
147 return stdexec::__closure{*this, std::forward<T>(name), std::forward<Closure>(closure)};
148 }
149};
150
151} // namespace Kokkos::Execution::ExecutionSpaceImpl
152
158
159#endif // KOKKOS_EXECUTION_EXECUTION_SPACE_SCOPED_REGION_HPP
#define KOKKOS_EXECUTION_IMPL_FORWARDING_ATTRIBUTES_GET_ENV(_type_, _obj_)
#define KOKKOS_EXECUTION_COMPL_SIGS_KEEP(_decayed_self_type_, _sndr_type_)
#define KOKKOS_EXECUTION_FORWARDING_GET_ENV(_type_, _obj_)
Retrieve the environment of _obj_ (with forwarding). // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)...
Definition env.hpp:7
std::invoke_result_t< stdexec::get_completion_scheduler_t< Tag >, stdexec::env_of_t< Sndr >, Env... > completion_scheduler_of_t
Retrieve the completion scheduler for a given completion tag.
constexpr Kokkos::Execution::ExecutionSpaceImpl::Push push
constexpr Kokkos::Execution::ExecutionSpaceImpl::ScopedRegion scoped_region
constexpr Kokkos::Execution::ExecutionSpaceImpl::Pop pop
auto operator()(Sndr &&sndr) const noexcept -> RegionSender< Kind::POP, Sndr >
auto operator()(T &&name) const noexcept
auto operator()(Sndr &&sndr, T &&name) const noexcept -> RegionSender< Kind::PUSH, Sndr >
void complete(Tag tag, Args &&... args) &&noexcept
RegionReceiver< kind, schd_t< Rcvr >, Rcvr > rcvr_t
Impl::completion_scheduler_of_t< stdexec::set_value_t, Sndr, stdexec::env_of_t< Rcvr > > schd_t
Helper for Kokkos::Profiling::scoped_region.
auto operator()(Sndr &&sndr, T &&name, Closure &&closure) const noexcept
auto operator()(T &&name, Closure &&closure) const noexcept
#define KOKKOS_EXECUTION_IMPL_MEMBER_CVREF_T(_Self_, _member_)
Yields the type of member _member_ as accessed from expression _Self_, preserving the cv and ref qual...
#define KOKKOS_EXECUTION_IMPL_FORWARD_THIS(_Self_, _self_)
Equivalent to std::forward<_Self_>(_self_).