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