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
16
25
27
29enum class Kind : std::uint8_t {
32};
33
34template <Kind kind, stdexec::__is_instance_of<Scheduler> Schd, stdexec::receiver Rcvr>
36 using receiver_concept = stdexec::receiver_tag;
37
38 std::string name;
39 Schd schd;
40 Rcvr rcvr;
41
42 template <typename Tag, typename... Args>
43 void complete(Tag tag, Args&&... args) && noexcept {
44 schd.state->exec.fence(
45 std::format(
46 "{}: {}",
47 Kokkos::Impl::TypeInfo<typename Schd::execution_space>::name(),
48 kind == Kind::PUSH ? "push" : "pop"));
49
50 if constexpr (kind == Kind::PUSH) {
51 Kokkos::Profiling::pushRegion(name);
52 } else {
53 Kokkos::Profiling::popRegion();
54 }
55
56 std::invoke(tag, std::move(rcvr), std::forward<Args>(args)...);
57 }
58
59 void set_value() && noexcept {
60 std::move(*this).complete(stdexec::set_value);
61 }
62
63 template <typename Error>
64 void set_error(Error&& err) && noexcept {
65 std::move(*this).complete(stdexec::set_error, std::forward<Error>(err));
66 }
67
69};
70
71template <Kind kind, stdexec::sender Sndr>
73 using sender_concept = stdexec::sender_tag;
74
76
77 template <typename Rcvr>
79
80 template <typename Rcvr>
82
83 template <stdexec::receiver Rcvr>
84 stdexec::operation_state auto connect(Rcvr rcvr) && noexcept(
85 std::is_nothrow_constructible_v<rcvr_t<Rcvr>, std::string&&, schd_t<Rcvr>&&, Rcvr&&>
86 && stdexec::__nothrow_connectable<Sndr&&, rcvr_t<Rcvr>>) {
87 auto schd =
88 stdexec::get_completion_scheduler<stdexec::set_value_t>(stdexec::get_env(sndr), stdexec::get_env(rcvr));
89
90 return stdexec::connect(
91 std::forward<Sndr>(sndr),
92 rcvr_t<Rcvr>{.name = std::move(name), .schd = std::move(schd), .rcvr = std::move(rcvr)});
93 }
94
95 std::string name{};
96 Sndr sndr;
97
99};
100
101struct Push {
102 template <stdexec::sender Sndr, typename T>
103 auto operator()(Sndr&& sndr, T&& name) const noexcept -> RegionSender<Kind::PUSH, Sndr> {
104 return {.name = std::forward<T>(name), .sndr = std::forward<Sndr>(sndr)};
105 }
106
107 template <typename T>
108 auto operator()(T&& name) const noexcept {
109 return stdexec::__closure{*this, std::forward<T>(name)};
110 }
111};
112
113struct Pop {
114 template <stdexec::sender Sndr>
115 auto operator()(Sndr&& sndr) const noexcept -> RegionSender<Kind::POP, Sndr> {
116 return {.sndr = std::forward<Sndr>(sndr)};
117 }
118
119 auto operator()() const noexcept {
120 return stdexec::__closure{*this};
121 }
122};
123
126 template <stdexec::sender Sndr, typename T, stdexec::__sender_adaptor_closure Closure>
127 auto operator()(Sndr&& sndr, T&& name, Closure&& closure) const noexcept {
128 return std::forward<Sndr>(sndr) | Push{}(std::forward<T>(name)) | std::forward<Closure>(closure) | Pop{}();
129 }
130
131 template <typename T, stdexec::__sender_adaptor_closure Closure>
132 auto operator()(T&& name, Closure&& closure) const noexcept {
133 return stdexec::__closure{*this, std::forward<T>(name), std::forward<Closure>(closure)};
134 }
135};
136
137} // namespace Kokkos::Execution::ExecutionSpaceImpl
138
144
145#endif // KOKKOS_EXECUTION_EXECUTION_SPACE_SCOPED_REGION_HPP
#define KOKKOS_EXECUTION_IMPL_FORWARDING_ATTRIBUTES_GET_ENV(_type_, _obj_)
#define KOKKOS_EXECUTION_COMPL_SIGS_KEEP(_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
stdexec::operation_state auto connect(Rcvr rcvr) &&noexcept(std::is_nothrow_constructible_v< rcvr_t< Rcvr >, std::string &&, schd_t< Rcvr > &&, Rcvr && > &&stdexec::__nothrow_connectable< Sndr &&, rcvr_t< Rcvr > >)
Helper for Kokkos::Profiling::scoped_region.
auto operator()(Sndr &&sndr, T &&name, Closure &&closure) const noexcept
auto operator()(T &&name, Closure &&closure) const noexcept