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
18
27
29
31enum class Kind : std::uint8_t {
34};
35
36template <Kind kind, stdexec::__is_instance_of<Scheduler> Schd, stdexec::receiver Rcvr>
38 using receiver_concept = stdexec::receiver_tag;
39
40 std::string name;
41 Schd schd;
42 Rcvr rcvr;
43
44 template <typename Tag, typename... Args>
45 void complete(Tag tag, Args&&... args) && noexcept {
46 schd.state->exec.fence(
47 std::format(
48 "{}: {}",
50 kind == Kind::PUSH ? "push" : "pop"));
51
52 if constexpr (kind == Kind::PUSH) {
53 Kokkos::Profiling::pushRegion(name);
54 } else {
55 Kokkos::Profiling::popRegion();
56 }
57
58 std::invoke(tag, std::move(rcvr), std::forward<Args>(args)...);
59 }
60
61 void set_value() && noexcept {
62 std::move(*this).complete(stdexec::set_value);
63 }
64
65 template <typename Error>
66 void set_error(Error&& err) && noexcept {
67 std::move(*this).complete(stdexec::set_error, std::forward<Error>(err));
68 }
69
71};
72
73template <Kind kind, stdexec::sender Sndr>
75 using sender_concept = stdexec::sender_tag;
76
78
79 template <typename Rcvr>
81
82 template <typename Rcvr>
84
85 template <stdexec::__decays_to<RegionSender> Self, stdexec::receiver Rcvr>
86 [[nodiscard]]
87 constexpr STDEXEC_EXPLICIT_THIS_BEGIN(
88 auto connect)(this Self&& self, Rcvr rcvr) // NOLINT(cppcoreguidelines-missing-std-forward)
89 noexcept(
90 std::is_nothrow_constructible_v<
94 Rcvr&&
95 >
96 && stdexec::__nothrow_connectable<KOKKOS_EXECUTION_IMPL_MEMBER_CVREF_T(Self, sndr), rcvr_t<Rcvr>&&>)
97 -> stdexec::connect_result_t<KOKKOS_EXECUTION_IMPL_MEMBER_CVREF_T(Self, sndr), rcvr_t<Rcvr>&&> {
98 auto schd = stdexec::get_completion_scheduler<stdexec::set_value_t>(
99 stdexec::get_env(self.sndr), stdexec::get_env(rcvr));
100
101 return stdexec::connect(
104 .name = KOKKOS_EXECUTION_IMPL_FORWARD_THIS(Self, self).name,
105 .schd = std::move(schd),
106 .rcvr = std::move(rcvr)});
107 }
108 STDEXEC_EXPLICIT_THIS_END(connect)
109
110 std::string name{};
111 Sndr sndr;
112
114};
115
116struct Push {
117 template <stdexec::sender Sndr, typename T>
118 auto operator()(Sndr&& sndr, T&& name) const noexcept -> RegionSender<Kind::PUSH, Sndr> {
119 return {.name = std::forward<T>(name), .sndr = std::forward<Sndr>(sndr)};
120 }
121
122 template <typename T>
123 auto operator()(T&& name) const noexcept {
124 return stdexec::__closure{*this, std::forward<T>(name)};
125 }
126};
127
128struct Pop {
129 template <stdexec::sender Sndr>
130 auto operator()(Sndr&& sndr) const noexcept -> RegionSender<Kind::POP, Sndr> {
131 return {.sndr = std::forward<Sndr>(sndr)};
132 }
133
134 auto operator()() const noexcept {
135 return stdexec::__closure{*this};
136 }
137};
138
141 template <stdexec::sender Sndr, typename T, stdexec::__sender_adaptor_closure Closure>
142 auto operator()(Sndr&& sndr, T&& name, Closure&& closure) const noexcept {
143 return std::forward<Sndr>(sndr) | Push{}(std::forward<T>(name)) | std::forward<Closure>(closure) | Pop{}();
144 }
145
146 template <typename T, stdexec::__sender_adaptor_closure Closure>
147 auto operator()(T&& name, Closure&& closure) const noexcept {
148 return stdexec::__closure{*this, std::forward<T>(name), std::forward<Closure>(closure)};
149 }
150};
151
152} // namespace Kokkos::Execution::ExecutionSpaceImpl
153
159
160#endif // KOKKOS_EXECUTION_EXECUTION_SPACE_SCOPED_REGION_HPP
#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
#define KOKKOS_EXECUTION_IMPL_FORWARDING_ATTRIBUTES_GET_ENV(_type_, _obj_)
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 auto display_string_of() noexcept -> std::string_view
Definition type_info.hpp:20
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
constexpr auto connect(this Self &&self, Rcvr rcvr) noexcept(std::is_nothrow_constructible_v< rcvr_t< Rcvr >, decltype((std::declval< Self >().name)), schd_t< Rcvr > &&, Rcvr && > &&stdexec::__nothrow_connectable< decltype((std::declval< Self >().sndr)), rcvr_t< Rcvr > && >) -> stdexec::connect_result_t< decltype((std::declval< Self >().sndr)), rcvr_t< Rcvr > && >
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_).