-
-
Notifications
You must be signed in to change notification settings - Fork 542
Implement P2300 bulk adapter for HPX executors #7240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shivansh023023
wants to merge
1
commit into
TheHPXProject:master
Choose a base branch
from
shivansh023023:feat/p2300-bulk-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
libs/core/executors/include/hpx/executors/executor_scheduler.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| // Copyright (c) 2026 The STE||AR-Group | ||
| // | ||
| // SPDX-License-Identifier: BSL-1.0 | ||
| // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
|
||
| /// \file parallel/executors/executor_scheduler.hpp | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <hpx/config.hpp> | ||
| #include <hpx/modules/errors.hpp> | ||
| #include <hpx/modules/execution.hpp> | ||
| #include <hpx/modules/execution_base.hpp> | ||
|
|
||
| #include <exception> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| namespace hpx::execution::experimental { | ||
|
|
||
| // Forward declarations | ||
| template <typename Executor> | ||
| struct executor_scheduler; | ||
|
|
||
| template <typename Executor> | ||
| struct executor_sender; | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////// | ||
| template <typename Executor, typename Receiver> | ||
| struct executor_operation_state | ||
| { | ||
| HPX_NO_UNIQUE_ADDRESS std::decay_t<Executor> exec_; | ||
| HPX_NO_UNIQUE_ADDRESS std::decay_t<Receiver> receiver_; | ||
|
|
||
| template <typename Exec, typename Recv> | ||
| executor_operation_state(Exec&& exec, Recv&& recv) | ||
| : exec_(HPX_FORWARD(Exec, exec)) | ||
| , receiver_(HPX_FORWARD(Recv, recv)) | ||
| { | ||
| } | ||
|
|
||
| executor_operation_state(executor_operation_state&&) = delete; | ||
| executor_operation_state(executor_operation_state const&) = delete; | ||
| executor_operation_state& operator=( | ||
| executor_operation_state&&) = delete; | ||
| executor_operation_state& operator=( | ||
| executor_operation_state const&) = delete; | ||
|
|
||
| ~executor_operation_state() = default; | ||
|
|
||
| friend void tag_invoke(start_t, executor_operation_state& os) noexcept | ||
| { | ||
| hpx::detail::try_catch_exception_ptr( | ||
| [&]() { | ||
| hpx::parallel::execution::post(os.exec_, | ||
| [receiver = HPX_MOVE(os.receiver_)]() mutable { | ||
| hpx::execution::experimental::set_value( | ||
| HPX_MOVE(receiver)); | ||
| }); | ||
| }, | ||
| [&](std::exception_ptr ep) { | ||
| hpx::execution::experimental::set_error( | ||
| HPX_MOVE(os.receiver_), HPX_MOVE(ep)); | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////// | ||
| template <typename Executor> | ||
| struct executor_sender | ||
| { | ||
| HPX_NO_UNIQUE_ADDRESS std::decay_t<Executor> exec_; | ||
|
|
||
| using completion_signatures = | ||
| hpx::execution::experimental::completion_signatures< | ||
| hpx::execution::experimental::set_value_t(), | ||
| hpx::execution::experimental::set_error_t(std::exception_ptr)>; | ||
|
|
||
| template <typename Env> | ||
| friend auto tag_invoke( | ||
| hpx::execution::experimental::get_completion_signatures_t, | ||
| executor_sender const&, Env) noexcept -> completion_signatures; | ||
|
|
||
| friend constexpr auto tag_invoke( | ||
| hpx::execution::experimental::get_completion_scheduler_t< | ||
| hpx::execution::experimental::set_value_t>, | ||
| executor_sender const& s) noexcept | ||
| { | ||
| return executor_scheduler<Executor>{s.exec_}; | ||
| } | ||
|
|
||
| template <typename Receiver> | ||
| friend executor_operation_state<Executor, Receiver> tag_invoke( | ||
| connect_t, executor_sender&& s, Receiver&& receiver) | ||
| { | ||
| return {HPX_MOVE(s.exec_), HPX_FORWARD(Receiver, receiver)}; | ||
| } | ||
|
|
||
| template <typename Receiver> | ||
| friend executor_operation_state<Executor, Receiver> tag_invoke( | ||
| connect_t, executor_sender const& s, Receiver&& receiver) | ||
| { | ||
| return {s.exec_, HPX_FORWARD(Receiver, receiver)}; | ||
| } | ||
| }; | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////// | ||
| template <typename Executor> | ||
| struct executor_scheduler | ||
| { | ||
| using executor_type = std::decay_t<Executor>; | ||
|
|
||
| HPX_NO_UNIQUE_ADDRESS executor_type exec_; | ||
|
|
||
| constexpr executor_scheduler() = default; | ||
|
|
||
| template <typename Exec, | ||
| typename = std::enable_if_t< | ||
| !std::is_same_v<std::decay_t<Exec>, executor_scheduler>>> | ||
| explicit executor_scheduler(Exec&& exec) | ||
| : exec_(HPX_FORWARD(Exec, exec)) | ||
| { | ||
| } | ||
|
|
||
| constexpr bool operator==(executor_scheduler const& rhs) const noexcept | ||
| { | ||
| return exec_ == rhs.exec_; | ||
| } | ||
|
|
||
| constexpr bool operator!=(executor_scheduler const& rhs) const noexcept | ||
| { | ||
| return !(*this == rhs); | ||
| } | ||
|
|
||
| friend executor_sender<Executor> tag_invoke( | ||
| schedule_t, executor_scheduler&& sched) | ||
| { | ||
| return {HPX_MOVE(sched.exec_)}; | ||
| } | ||
|
|
||
| friend executor_sender<Executor> tag_invoke( | ||
| schedule_t, executor_scheduler const& sched) | ||
| { | ||
| return {sched.exec_}; | ||
| } | ||
| }; | ||
| } // namespace hpx::execution::experimental |
222 changes: 222 additions & 0 deletions
222
libs/core/executors/include/hpx/executors/executor_scheduler_bulk.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| // Copyright (c) 2026 The STE||AR-Group | ||
| // | ||
| // SPDX-License-Identifier: BSL-1.0 | ||
| // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <hpx/config.hpp> | ||
|
|
||
| #if defined(HPX_HAVE_STDEXEC) | ||
| #include <hpx/execution_base/stdexec_forward.hpp> | ||
| #endif | ||
|
|
||
| #include <hpx/execution/algorithms/bulk.hpp> | ||
| #include <hpx/execution_base/completion_scheduler.hpp> | ||
| #include <hpx/execution_base/completion_signatures.hpp> | ||
| #include <hpx/execution_base/execution.hpp> | ||
| #include <hpx/execution_base/receiver.hpp> | ||
| #include <hpx/execution_base/sender.hpp> | ||
| #include <hpx/executors/executor_scheduler.hpp> | ||
| #include <hpx/modules/errors.hpp> | ||
|
|
||
| #include <exception> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| namespace hpx::execution::experimental { | ||
|
|
||
| namespace detail { | ||
| template <typename Executor, typename Receiver, typename Shape, | ||
| typename F> | ||
| struct executor_bulk_receiver | ||
| { | ||
| HPX_NO_UNIQUE_ADDRESS std::decay_t<Executor> exec_; | ||
| HPX_NO_UNIQUE_ADDRESS std::decay_t<Receiver> receiver_; | ||
| HPX_NO_UNIQUE_ADDRESS std::decay_t<Shape> shape_; | ||
| HPX_NO_UNIQUE_ADDRESS std::decay_t<F> f_; | ||
|
|
||
| template <typename Error> | ||
| friend void tag_invoke( | ||
| set_error_t, executor_bulk_receiver&& r, Error&& error) noexcept | ||
| { | ||
| hpx::execution::experimental::set_error( | ||
| HPX_MOVE(r.receiver_), HPX_FORWARD(Error, error)); | ||
| } | ||
|
|
||
| friend void tag_invoke( | ||
| set_stopped_t, executor_bulk_receiver&& r) noexcept | ||
| { | ||
| hpx::execution::experimental::set_stopped( | ||
| HPX_MOVE(r.receiver_)); | ||
| } | ||
|
|
||
| template <typename... Ts> | ||
| friend void tag_invoke( | ||
| set_value_t, executor_bulk_receiver&& r, Ts&&... ts) noexcept | ||
| { | ||
| hpx::detail::try_catch_exception_ptr( | ||
| [&]() { | ||
| hpx::parallel::execution::bulk_sync_execute( | ||
| r.exec_, r.f_, r.shape_, ts...); | ||
|
|
||
| hpx::execution::experimental::set_value( | ||
| HPX_MOVE(r.receiver_), HPX_FORWARD(Ts, ts)...); | ||
| }, | ||
| [&](std::exception_ptr ep) { | ||
| hpx::execution::experimental::set_error( | ||
| HPX_MOVE(r.receiver_), HPX_MOVE(ep)); | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| template <typename Executor, typename Sender, typename Shape, | ||
| typename F> | ||
| struct executor_bulk_sender | ||
| { | ||
| HPX_NO_UNIQUE_ADDRESS std::decay_t<Executor> exec_; | ||
| HPX_NO_UNIQUE_ADDRESS std::decay_t<Sender> sender_; | ||
| HPX_NO_UNIQUE_ADDRESS std::decay_t<Shape> shape_; | ||
| HPX_NO_UNIQUE_ADDRESS std::decay_t<F> f_; | ||
|
|
||
| #if defined(HPX_HAVE_STDEXEC) | ||
| using sender_concept = hpx::execution::experimental::sender_t; | ||
|
|
||
| template <typename Env> | ||
| friend auto tag_invoke( | ||
| hpx::execution::experimental::get_completion_signatures_t, | ||
| executor_bulk_sender const&, Env const&) -> hpx::execution:: | ||
| experimental::transform_completion_signatures_of<Sender, Env, | ||
| hpx::execution::experimental::completion_signatures< | ||
| hpx::execution::experimental::set_error_t( | ||
| std::exception_ptr)>>; | ||
|
|
||
| struct env | ||
| { | ||
| std::decay_t<Sender> const& pred_snd; | ||
| std::decay_t<Executor> const& exec; | ||
|
|
||
| template <typename CPO> | ||
| requires( | ||
| meta::value<meta::one_of<CPO, | ||
| hpx::execution::experimental::set_error_t, | ||
| hpx::execution::experimental::set_stopped_t>> && | ||
| hpx::execution::experimental::detail:: | ||
| has_completion_scheduler_v<CPO, | ||
| std::decay_t<Sender>>) | ||
| friend constexpr auto tag_invoke( | ||
| hpx::execution::experimental::get_completion_scheduler_t< | ||
| CPO> | ||
| tag, | ||
| env const& e) noexcept | ||
| { | ||
| return tag( | ||
| hpx::execution::experimental::get_env(e.pred_snd)); | ||
| } | ||
|
|
||
| friend constexpr auto tag_invoke( | ||
| hpx::execution::experimental::get_completion_scheduler_t< | ||
| hpx::execution::experimental::set_value_t>, | ||
| env const& e) noexcept | ||
| { | ||
| return hpx::execution::experimental::executor_scheduler< | ||
| Executor>{e.exec}; | ||
| } | ||
| }; | ||
|
|
||
| friend constexpr auto tag_invoke( | ||
| hpx::execution::experimental::get_env_t, | ||
| executor_bulk_sender const& s) noexcept | ||
| { | ||
| return env{s.sender_, s.exec_}; | ||
| } | ||
| #else | ||
| template <typename Env> | ||
| struct generate_completion_signatures | ||
| { | ||
| template <template <typename...> typename Tuple, | ||
| template <typename...> typename Variant> | ||
| using value_types = | ||
| value_types_of_t<Sender, Env, Tuple, Variant>; | ||
|
|
||
| template <template <typename...> typename Variant> | ||
| using error_types = hpx::util::detail::unique_concat_t< | ||
| error_types_of_t<Sender, Env, Variant>, | ||
| Variant<std::exception_ptr>>; | ||
|
|
||
| static constexpr bool sends_stopped = | ||
| sends_stopped_of_v<Sender, Env>; | ||
| }; | ||
|
|
||
| template <typename Env> | ||
| friend auto tag_invoke( | ||
| hpx::execution::experimental::get_completion_signatures_t, | ||
| executor_bulk_sender const&, Env) | ||
| -> generate_completion_signatures<Env>; | ||
|
|
||
| template <typename CPO> | ||
| friend constexpr auto tag_invoke( | ||
| hpx::execution::experimental::get_completion_scheduler_t<CPO> | ||
| tag, | ||
| executor_bulk_sender const& s) | ||
| { | ||
| return tag(s.sender_); | ||
| } | ||
|
|
||
| friend constexpr auto tag_invoke( | ||
| hpx::execution::experimental::get_completion_scheduler_t< | ||
| hpx::execution::experimental::set_value_t>, | ||
| executor_bulk_sender const& s) | ||
| { | ||
| return hpx::execution::experimental::executor_scheduler< | ||
| Executor>{s.exec_}; | ||
| } | ||
| #endif | ||
|
|
||
| template <typename Receiver> | ||
| friend auto tag_invoke(connect_t, | ||
| executor_bulk_sender<Executor, Sender, Shape, F>&& s, | ||
| Receiver&& receiver) | ||
| { | ||
| return hpx::execution::experimental::connect( | ||
| HPX_MOVE(s.sender_), | ||
| executor_bulk_receiver<Executor, std::decay_t<Receiver>, | ||
| Shape, F>{HPX_MOVE(s.exec_), | ||
| HPX_FORWARD(Receiver, receiver), HPX_MOVE(s.shape_), | ||
| HPX_MOVE(s.f_)}); | ||
| } | ||
|
|
||
| template <typename Receiver> | ||
| friend auto tag_invoke(connect_t, | ||
| executor_bulk_sender<Executor, Sender, Shape, F>& s, | ||
| Receiver&& receiver) | ||
| { | ||
| return hpx::execution::experimental::connect(s.sender_, | ||
| executor_bulk_receiver<Executor, std::decay_t<Receiver>, | ||
| Shape, F>{s.exec_, HPX_FORWARD(Receiver, receiver), | ||
| s.shape_, s.f_}); | ||
| } | ||
|
|
||
| template <typename Receiver> | ||
| friend auto tag_invoke(connect_t, | ||
| executor_bulk_sender<Executor, Sender, Shape, F> const& s, | ||
| Receiver&& receiver) | ||
| { | ||
| return hpx::execution::experimental::connect(s.sender_, | ||
| executor_bulk_receiver<Executor, std::decay_t<Receiver>, | ||
| Shape, F>{s.exec_, HPX_FORWARD(Receiver, receiver), | ||
| s.shape_, s.f_}); | ||
| } | ||
| }; | ||
| } // namespace detail | ||
|
|
||
| template <typename Executor, typename Sender, typename Shape, typename F> | ||
| auto tag_invoke(bulk_t, executor_scheduler<Executor> const& sched, | ||
| Sender&& sender, Shape const& shape, F&& f) | ||
| { | ||
| return detail::executor_bulk_sender<Executor, std::decay_t<Sender>, | ||
| Shape, std::decay_t<F>>{ | ||
| sched.exec_, HPX_FORWARD(Sender, sender), shape, HPX_FORWARD(F, f)}; | ||
| } | ||
| } // namespace hpx::execution::experimental | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the case
!defined(HPX_HAVE_STDEXEC)as we have dropped our own implementation of senders&receivers.