Skip to content

Commit 8c46474

Browse files
authored
Implement P3481 (#251)
* Implement P3481 - std::execution::bulk() issues * Add execution policy support to bulk algorithms * Try fix MSVC CI error * Try fix MSVC CI error again
1 parent 34c5b62 commit 8c46474

8 files changed

Lines changed: 597 additions & 124 deletions

File tree

include/beman/execution/detail/bulk.hpp

Lines changed: 190 additions & 79 deletions
Large diffs are not rendered by default.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// include/beman/execution/detail/execution_policy.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_EXECUTION_POLICY
5+
#define INCLUDED_BEMAN_EXECUTION_DETAIL_EXECUTION_POLICY
6+
#include <version>
7+
#include <beman/execution/detail/common.hpp>
8+
#ifdef BEMAN_HAS_IMPORT_STD
9+
import std;
10+
#else
11+
#ifdef __cpp_lib_execution
12+
#include <execution>
13+
#else
14+
#include <type_traits>
15+
#endif
16+
#endif
17+
18+
// ----------------------------------------------------------------------------
19+
20+
namespace beman::execution {
21+
#ifdef __cpp_lib_execution
22+
23+
using ::std::execution::par;
24+
using ::std::execution::parallel_policy;
25+
26+
using ::std::execution::par_unseq;
27+
using ::std::execution::parallel_unsequenced_policy;
28+
29+
using ::std::execution::seq;
30+
using ::std::execution::sequenced_policy;
31+
32+
#if __cpp_lib_execution >= 201902L
33+
using ::std::execution::unseq;
34+
using ::std::execution::unsequenced_policy;
35+
#endif
36+
37+
template <typename T>
38+
struct is_execution_policy : ::std::is_execution_policy<T> {};
39+
40+
template <typename T>
41+
inline constexpr bool is_execution_policy_v = ::beman::execution::is_execution_policy<T>::value;
42+
43+
#else
44+
45+
struct sequenced_policy {};
46+
inline constexpr sequenced_policy seq{};
47+
48+
struct parallel_policy {};
49+
inline constexpr parallel_policy par{};
50+
51+
struct parallel_unsequenced_policy {};
52+
inline constexpr parallel_unsequenced_policy par_unseq{};
53+
54+
struct unsequenced_policy {};
55+
inline constexpr unsequenced_policy unseq{};
56+
57+
template <typename>
58+
struct is_execution_policy : ::std::false_type {};
59+
60+
template <>
61+
struct is_execution_policy< ::beman::execution::sequenced_policy> : ::std::true_type {};
62+
63+
template <>
64+
struct is_execution_policy< ::beman::execution::parallel_policy> : ::std::true_type {};
65+
66+
template <>
67+
struct is_execution_policy< ::beman::execution::parallel_unsequenced_policy> : ::std::true_type {};
68+
69+
template <>
70+
struct is_execution_policy< ::beman::execution::unsequenced_policy> : ::std::true_type {};
71+
72+
template <typename T>
73+
inline constexpr bool is_execution_policy_v = ::beman::execution::is_execution_policy<T>::value;
74+
75+
#endif
76+
} // namespace beman::execution
77+
78+
// ----------------------------------------------------------------------------
79+
80+
#endif // INCLUDED_BEMAN_EXECUTION_DETAIL_EXECUTION_POLICY

include/beman/execution/execution.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import beman.execution.detail.affine_on;
1212
import beman.execution.detail.as_except_ptr;
1313
import beman.execution.detail.associate;
1414
import beman.execution.detail.bulk;
15+
import beman.execution.detail.execution_policy;
1516
import beman.execution.detail.completion_signature;
1617
import beman.execution.detail.completion_signatures;
1718
import beman.execution.detail.connect;
1819
import beman.execution.detail.continues_on;
1920
import beman.execution.detail.counting_scope;
2021
import beman.execution.detail.env;
22+
import beman.execution.detail.execution_policy;
2123
import beman.execution.detail.forwarding_query;
2224
import beman.execution.detail.get_allocator;
2325
import beman.execution.detail.get_await_completion_adaptor;
@@ -29,6 +31,7 @@ import beman.execution.detail.get_forward_progress_guarantee;
2931
import beman.execution.detail.get_env;
3032
import beman.execution.detail.get_scheduler;
3133
import beman.execution.detail.get_stop_token;
34+
import beman.execution.detail.inline_scheduler;
3235
import beman.execution.detail.into_variant;
3336
import beman.execution.detail.just;
3437
import beman.execution.detail.let;
@@ -44,6 +47,7 @@ import beman.execution.detail.scheduler;
4447
import beman.execution.detail.scope_token;
4548
import beman.execution.detail.sender_adaptor_closure;
4649
import beman.execution.detail.sender_in;
50+
import beman.execution.detail.sender_to;
4751
import beman.execution.detail.sender;
4852
import beman.execution.detail.set_error;
4953
import beman.execution.detail.set_stopped;
@@ -76,6 +80,7 @@ import beman.execution.detail.write_env;
7680
#include <beman/execution/detail/continues_on.hpp>
7781
#include <beman/execution/detail/counting_scope.hpp>
7882
#include <beman/execution/detail/env.hpp>
83+
#include <beman/execution/detail/execution_policy.hpp>
7984
#include <beman/execution/detail/forwarding_query.hpp>
8085
#include <beman/execution/detail/get_allocator.hpp>
8186
#include <beman/execution/detail/get_await_completion_adaptor.hpp>

src/beman/execution/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ target_sources(
6969
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/default_domain.hpp
7070
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/default_impls.hpp
7171
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/dependent_sender_error.hpp
72+
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/execution_policy.hpp
7273
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/emplace_from.hpp
7374
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/env.hpp
7475
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/env_of_t.hpp
@@ -259,6 +260,7 @@ if(BEMAN_USE_MODULES)
259260
default_domain.cppm
260261
default_impls.cppm
261262
dependent_sender_error.cppm
263+
execution_policy.cppm
262264
emplace_from.cppm
263265
enable_sender.cppm
264266
env_of_t.cppm

src/beman/execution/bulk.cppm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ export module beman.execution.detail.bulk;
99
namespace beman::execution {
1010
export using beman::execution::bulk_t;
1111
export using beman::execution::bulk;
12+
export using beman::execution::bulk_chunked_t;
13+
export using beman::execution::bulk_chunked;
14+
export using beman::execution::bulk_unchunked_t;
15+
export using beman::execution::bulk_unchunked;
1216
} // namespace beman::execution

src/beman/execution/execution.cppm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import beman.execution.detail.default_domain;
2323
export import beman.execution.detail.env;
2424
export import beman.execution.detail.env_of_t;
2525
export import beman.execution.detail.error_types_of_t; // [exec.getcomplsigs], completion signatures
26+
export import beman.execution.detail.execution_policy;
2627
import beman.execution.detail.forwarding_query;
2728
import beman.execution.detail.get_allocator;
2829
import beman.execution.detail.get_await_completion_adaptor;
@@ -201,6 +202,8 @@ export using ::beman::execution::let_value_t;
201202
export using ::beman::execution::let_error_t;
202203
export using ::beman::execution::let_stopped_t;
203204
export using ::beman::execution::bulk_t;
205+
export using ::beman::execution::bulk_chunked_t;
206+
export using ::beman::execution::bulk_unchunked_t;
204207
//-dk:TODO export using ::beman::execution::split_t;
205208
export using ::beman::execution::when_all_t;
206209
export using ::beman::execution::when_all_with_variant_t;
@@ -219,6 +222,8 @@ export using ::beman::execution::let_value;
219222
export using ::beman::execution::let_error;
220223
export using ::beman::execution::let_stopped;
221224
export using ::beman::execution::bulk;
225+
export using ::beman::execution::bulk_chunked;
226+
export using ::beman::execution::bulk_unchunked;
222227
//-dk:TODO export using ::beman::execution::split;
223228
export using ::beman::execution::when_all;
224229
export using ::beman::execution::when_all_with_variant;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module;
2+
// src/beman/execution/execution_policy.cppm -*-C++-*-
3+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
#include <beman/execution/detail/execution_policy.hpp>
6+
7+
export module beman.execution.detail.execution_policy;
8+
9+
namespace beman::execution {
10+
export using beman::execution::parallel_policy;
11+
export using beman::execution::par;
12+
13+
export using beman::execution::parallel_unsequenced_policy;
14+
export using beman::execution::par_unseq;
15+
16+
export using beman::execution::sequenced_policy;
17+
export using beman::execution::seq;
18+
19+
#if !defined(__cpp_lib_execution) || (__cpp_lib_execution >= 201902L)
20+
export using beman::execution::unsequenced_policy;
21+
export using beman::execution::unseq;
22+
#endif
23+
24+
export using beman::execution::is_execution_policy;
25+
export using beman::execution::is_execution_policy_v;
26+
} // namespace beman::execution

0 commit comments

Comments
 (0)