Skip to content

Commit 77026bc

Browse files
committed
use stdexec::v2::continue_on() in nvexec maxwell example
1 parent e5b233e commit 77026bc

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

examples/nvexec/maxwell/snr.cuh

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,9 @@ namespace nvexec::STDEXEC_STREAM_DETAIL_NS { //
134134
}
135135
};
136136

137-
template <class PredecessorSenderId, class ClosureId, class ReceiverId>
137+
template <class PredecessorSenderId, class Closure, class ReceiverId>
138138
struct operation_state_t : operation_state_base_t<ReceiverId> {
139139
using PredSender = stdexec::__t<PredecessorSenderId>;
140-
using Closure = stdexec::__t<ClosureId>;
141140
using Receiver = stdexec::__t<ReceiverId>;
142141
using Scheduler =
143142
stdexec::tag_invoke_result_t<stdexec::get_scheduler_t, stdexec::env_of_t<Receiver>>;
@@ -193,6 +192,8 @@ namespace repeat_n_detail {
193192
OpT& op_state_;
194193

195194
public:
195+
using __t = receiver_t;
196+
using __id = receiver_t;
196197
using is_receiver = void;
197198

198199
template <stdexec::__one_of<ex::set_error_t, ex::set_stopped_t> _Tag, class... _Args>
@@ -222,10 +223,9 @@ namespace repeat_n_detail {
222223
}
223224
};
224225

225-
template <class SenderId, class ClosureId, class ReceiverId>
226+
template <class SenderId, class Closure, class ReceiverId>
226227
struct operation_state_t {
227228
using Sender = stdexec::__t<SenderId>;
228-
using Closure = stdexec::__t<ClosureId>;
229229
using Receiver = stdexec::__t<ReceiverId>;
230230

231231
using inner_op_state_t = stdexec::connect_result_t<Sender, receiver_t<operation_state_t>>;
@@ -246,13 +246,12 @@ namespace repeat_n_detail {
246246
, n_(n) {
247247
}
248248
};
249-
}
250249

251-
struct repeat_n_t {
252-
template <class SenderId, class ClosureId>
250+
template <class SenderId, class Closure>
253251
struct repeat_n_sender_t {
252+
using __t = repeat_n_sender_t;
253+
using __id = repeat_n_sender_t;
254254
using Sender = stdexec::__t<SenderId>;
255-
using Closure = stdexec::__t<ClosureId>;
256255
using is_sender = void;
257256

258257
using completion_signatures = //
@@ -275,8 +274,8 @@ struct repeat_n_t {
275274
requires(stdexec::sender_to<Sender, Receiver>)
276275
&& (!nvexec::STDEXEC_STREAM_DETAIL_NS::receiver_with_stream_env<Receiver>)
277276
friend auto tag_invoke(stdexec::connect_t, Self&& self, Receiver r)
278-
-> repeat_n_detail::operation_state_t<SenderId, ClosureId, stdexec::__id<Receiver>> {
279-
return repeat_n_detail::operation_state_t<SenderId, ClosureId, stdexec::__id<Receiver>>(
277+
-> repeat_n_detail::operation_state_t<SenderId, Closure, stdexec::__id<Receiver>> {
278+
return repeat_n_detail::operation_state_t<SenderId, Closure, stdexec::__id<Receiver>>(
280279
(Sender&&) self.sender_, self.closure_, (Receiver&&) r, self.n_);
281280
}
282281

@@ -285,17 +284,17 @@ struct repeat_n_t {
285284
&& (nvexec::STDEXEC_STREAM_DETAIL_NS::receiver_with_stream_env<Receiver>)
286285
friend auto tag_invoke(stdexec::connect_t, Self&& self, Receiver r)
287286
-> nvexec::STDEXEC_STREAM_DETAIL_NS::repeat_n::
288-
operation_state_t<SenderId, ClosureId, stdexec::__id<Receiver>> {
287+
operation_state_t<SenderId, Closure, stdexec::__id<Receiver>> {
289288
return nvexec::STDEXEC_STREAM_DETAIL_NS::repeat_n::
290-
operation_state_t<SenderId, ClosureId, stdexec::__id<Receiver>>(
289+
operation_state_t<SenderId, Closure, stdexec::__id<Receiver>>(
291290
(Sender&&) self.sender_, self.closure_, (Receiver&&) r, self.n_);
292291
}
293292
#else
294293
template <stdexec::__decays_to<repeat_n_sender_t> Self, stdexec::receiver Receiver>
295294
requires stdexec::sender_to<Sender, Receiver>
296295
friend auto tag_invoke(stdexec::connect_t, Self&& self, Receiver r)
297-
-> repeat_n_detail::operation_state_t<SenderId, ClosureId, stdexec::__id<Receiver>> {
298-
return repeat_n_detail::operation_state_t<SenderId, ClosureId, stdexec::__id<Receiver>>(
296+
-> repeat_n_detail::operation_state_t<SenderId, Closure, stdexec::__id<Receiver>> {
297+
return repeat_n_detail::operation_state_t<SenderId, Closure, stdexec::__id<Receiver>>(
299298
(Sender&&) self.sender_, self.closure_, (Receiver&&) r, self.n_);
300299
}
301300
#endif
@@ -306,11 +305,13 @@ struct repeat_n_t {
306305
return stdexec::get_env(s.sender_);
307306
}
308307
};
308+
}
309309

310+
struct repeat_n_t {
310311
template <stdexec::sender Sender, stdexec::__sender_adaptor_closure Closure>
311312
auto operator()(Sender&& __sndr, std::size_t n, Closure closure) const noexcept
312-
-> repeat_n_sender_t<stdexec::__x<Sender>, stdexec::__x<Closure>> {
313-
return repeat_n_sender_t<stdexec::__x<Sender>, stdexec::__x<Closure>>{
313+
-> repeat_n_detail::repeat_n_sender_t<stdexec::__id<Sender>, Closure> {
314+
return repeat_n_detail::repeat_n_sender_t<stdexec::__id<Sender>, Closure>{
314315
std::forward<Sender>(__sndr), closure, n};
315316
}
316317

@@ -329,7 +330,8 @@ inline constexpr repeat_n_t repeat_n{};
329330

330331
template <class SchedulerT>
331332
[[nodiscard]] bool is_gpu_scheduler(SchedulerT&& scheduler) {
332-
auto snd = ex::just() | exec::on(scheduler, ex::then([] { return nvexec::is_on_gpu(); }));
333+
auto snd = ex::just()
334+
| stdexec::v2::continue_on(scheduler, ex::then([] { return nvexec::is_on_gpu(); }));
333335
auto [on_gpu] = stdexec::sync_wait(std::move(snd)).value();
334336
return on_gpu;
335337
}
@@ -342,7 +344,7 @@ auto maxwell_eqs_snr(
342344
fields_accessor accessor,
343345
stdexec::scheduler auto&& computer) {
344346
return ex::just()
345-
| exec::on(
347+
| stdexec::v2::continue_on(
346348
computer,
347349
repeat_n(
348350
n_iterations,
@@ -361,7 +363,9 @@ void run_snr(
361363
time_storage_t time{is_gpu_scheduler(computer)};
362364
fields_accessor accessor = grid.accessor();
363365

364-
auto init = ex::just() | exec::on(computer, ex::bulk(grid.cells, grid_initializer(dt, accessor)));
366+
auto init =
367+
ex::just()
368+
| stdexec::v2::continue_on(computer, ex::bulk(grid.cells, grid_initializer(dt, accessor)));
365369
stdexec::sync_wait(init);
366370

367371
auto snd = maxwell_eqs_snr(dt, time.get(), write_vtk, n_iterations, accessor, computer);

include/nvexec/stream/transfer.cuh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,10 @@ namespace nvexec::STDEXEC_STREAM_DETAIL_NS {
160160
};
161161
};
162162
}
163+
164+
namespace stdexec::__detail {
165+
template <class SenderId>
166+
inline constexpr __mconst<
167+
nvexec::STDEXEC_STREAM_DETAIL_NS::transfer_sender_t<__name_of<__t<SenderId>>>>
168+
__name_of_v<nvexec::STDEXEC_STREAM_DETAIL_NS::transfer_sender_t<SenderId>>{};
169+
}

0 commit comments

Comments
 (0)