Skip to content

Commit 6d7ad68

Browse files
authored
Assume the presence of c++20 ranges (#2076)
* remove support for building without c++20 ranges * use range algorithms where appropriate
1 parent da7640a commit 6d7ad68

14 files changed

Lines changed: 66 additions & 208 deletions

examples/benchmark/static_thread_pool_bulk_enqueue.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,42 @@
1717
#include "./common.hpp"
1818
#include <exec/static_thread_pool.hpp>
1919

20-
#if !STDEXEC_NO_STDCPP_RANGES()
21-
# include <exec/sequence/ignore_all_values.hpp>
22-
# include <ranges>
20+
#include <exec/sequence/ignore_all_values.hpp>
21+
#include <ranges>
2322

2423
struct RunThread
2524
{
2625
void operator()(exec::static_thread_pool& pool,
2726
std::size_t total_scheds,
2827
std::size_t tid,
2928
std::barrier<>& barrier,
30-
# ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
29+
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
3130
std::span<char> buffer,
32-
# endif
31+
#endif
3332
std::atomic<bool>& stop,
3433
exec::numa_policy numa)
3534
{
3635
int numa_node = numa.thread_index_to_node(tid);
37-
numa.bind_to_node(numa_node);
36+
void(numa.bind_to_node(numa_node));
3837
while (true)
3938
{
4039
barrier.arrive_and_wait();
4140
if (stop.load())
4241
{
4342
break;
4443
}
45-
# ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
44+
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
4645
pmr::monotonic_buffer_resource rsrc{buffer.data(), buffer.size()};
4746
pmr::polymorphic_allocator<char> alloc{&rsrc};
4847
auto env = stdexec::prop{stdexec::get_allocator, alloc};
4948
auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism());
5049
auto iterate = exec::schedule_all(pool, std::views::iota(start, end))
5150
| exec::ignore_all_values() | stdexec::write_env(env);
52-
# else
51+
#else
5352
auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism());
5453
auto iterate = exec::schedule_all(pool, std::views::iota(start, end))
5554
| exec::ignore_all_values();
56-
# endif
55+
#endif
5756
stdexec::sync_wait(iterate);
5857
barrier.arrive_and_wait();
5958
}
@@ -74,6 +73,3 @@ auto main(int argc, char** argv) -> int
7473
exec::numa_policy numa{my_numa_distribution{}};
7574
my_main<exec::static_thread_pool, RunThread>(argc, argv, std::move(numa));
7675
}
77-
#else
78-
int main() {}
79-
#endif

examples/benchmark/static_thread_pool_bulk_enqueue_nested.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,23 @@
1717
#include "./common.hpp"
1818
#include <exec/static_thread_pool.hpp>
1919

20-
#if !STDEXEC_NO_STDCPP_RANGES()
21-
# include <exec/sequence/ignore_all_values.hpp>
22-
# include <ranges>
20+
#include <exec/sequence/ignore_all_values.hpp>
21+
#include <ranges>
2322

2423
struct RunThread
2524
{
2625
void operator()(exec::static_thread_pool& pool,
2726
std::size_t total_scheds,
2827
std::size_t tid,
2928
std::barrier<>& barrier,
30-
# ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
29+
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
3130
std::span<char> buffer,
32-
# endif
31+
#endif
3332
std::atomic<bool>& stop,
3433
exec::numa_policy numa)
3534
{
3635
int numa_node = numa.thread_index_to_node(tid);
37-
numa.bind_to_node(numa_node);
36+
void(numa.bind_to_node(numa_node));
3837
auto scheduler = pool.get_scheduler_on_thread(tid);
3938
while (true)
4039
{
@@ -43,17 +42,17 @@ struct RunThread
4342
{
4443
break;
4544
}
46-
# ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
45+
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
4746
pmr::monotonic_buffer_resource rsrc{buffer.data(), buffer.size()};
4847
pmr::polymorphic_allocator<char> alloc{&rsrc};
4948
auto env = stdexec::prop{stdexec::get_allocator, alloc};
5049
auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism());
5150
auto iterate = exec::iterate(std::views::iota(start, end)) | exec::ignore_all_values()
5251
| stdexec::write_env(env);
53-
# else
52+
#else
5453
auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism());
5554
auto iterate = exec::iterate(std::views::iota(start, end)) | exec::ignore_all_values();
56-
# endif
55+
#endif
5756
stdexec::sync_wait(stdexec::starts_on(scheduler, iterate));
5857
barrier.arrive_and_wait();
5958
}
@@ -64,6 +63,3 @@ auto main(int argc, char** argv) -> int
6463
{
6564
my_main<exec::static_thread_pool, RunThread>(argc, argv);
6665
}
67-
#else
68-
int main() {}
69-
#endif

examples/sudoku.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ void partial_solve(stdexec::parallel_scheduler sch,
336336
{
337337
if (1 << (potential - 1) & board.get()[first_potential_set].potential_set)
338338
{
339+
// NOLINTNEXTLINE(bugprone-unhandled-exception-at-new)
339340
std::unique_ptr<board_element[]> new_board(new board_element[BOARD_SIZE]);
340341
copy_board(board.get(), new_board.get());
341342
new_board.get()[first_potential_set].solved_element = potential;

include/exec/sequence/iterate.hpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,24 @@
1818

1919
#include "../../stdexec/__detail/__config.hpp"
2020

21-
#if !STDEXEC_NO_STDCPP_RANGES()
22-
23-
# include "../../stdexec/__detail/__concepts.hpp"
24-
# include "../../stdexec/__detail/__connect.hpp"
25-
# include "../../stdexec/__detail/__env.hpp"
26-
# include "../../stdexec/__detail/__execution_fwd.hpp"
27-
# include "../../stdexec/__detail/__operation_states.hpp"
28-
# include "../../stdexec/__detail/__optional.hpp"
29-
# include "../../stdexec/__detail/__receivers.hpp"
30-
# include "../../stdexec/__detail/__schedulers.hpp"
31-
# include "../../stdexec/__detail/__sender_concepts.hpp"
32-
33-
# include "../detail/basic_sequence.hpp"
34-
# include "../sender_for.hpp"
35-
# include "../sequence.hpp"
36-
# include "../sequence_senders.hpp"
37-
# include "../trampoline_scheduler.hpp"
38-
39-
# include <exception>
40-
# include <ranges>
21+
#include "../../stdexec/__detail/__concepts.hpp"
22+
#include "../../stdexec/__detail/__connect.hpp"
23+
#include "../../stdexec/__detail/__env.hpp"
24+
#include "../../stdexec/__detail/__execution_fwd.hpp"
25+
#include "../../stdexec/__detail/__operation_states.hpp"
26+
#include "../../stdexec/__detail/__optional.hpp"
27+
#include "../../stdexec/__detail/__receivers.hpp"
28+
#include "../../stdexec/__detail/__schedulers.hpp"
29+
#include "../../stdexec/__detail/__sender_concepts.hpp"
30+
31+
#include "../detail/basic_sequence.hpp"
32+
#include "../sender_for.hpp"
33+
#include "../sequence.hpp"
34+
#include "../sequence_senders.hpp"
35+
#include "../trampoline_scheduler.hpp"
36+
37+
#include <exception>
38+
#include <ranges>
4139

4240
namespace experimental::execution
4341
{
@@ -250,5 +248,3 @@ namespace experimental::execution
250248
} // namespace experimental::execution
251249

252250
namespace exec = experimental::execution;
253-
254-
#endif // !STDEXEC_NO_STDCPP_RANGES()

include/exec/static_thread_pool.hpp

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,11 @@ namespace experimental::execution
104104
return std::make_pair(static_cast<Shape>(begin), static_cast<Shape>(end));
105105
}
106106

107-
#if !STDEXEC_NO_STDCPP_RANGES()
108107
namespace schedule_all_
109108
{
110109
template <class Range>
111110
class sequence;
112111
} // namespace schedule_all_
113-
#endif
114112

115113
struct task_base
116114
{
@@ -267,7 +265,6 @@ namespace experimental::execution
267265
_static_thread_pool& pool_;
268266
};
269267

270-
#if !STDEXEC_NO_STDCPP_RANGES()
271268
struct _transform_iterate
272269
{
273270
template <class Range>
@@ -278,7 +275,6 @@ namespace experimental::execution
278275

279276
_static_thread_pool& pool_;
280277
};
281-
#endif
282278

283279
static auto _hardware_concurrency() noexcept -> unsigned int
284280
{
@@ -316,7 +312,6 @@ namespace experimental::execution
316312
}
317313
}
318314

319-
#if !STDEXEC_NO_STDCPP_RANGES()
320315
template <sender_for<exec::iterate_t> Sender, class Env>
321316
constexpr auto
322317
transform_sender(STDEXEC::set_value_t, Sender&& sndr, Env const & env) const noexcept
@@ -340,7 +335,6 @@ namespace experimental::execution
340335
STDEXEC::_WITH_ENVIRONMENT_(Env)>();
341336
}
342337
}
343-
#endif
344338
};
345339

346340
public:
@@ -765,8 +759,7 @@ namespace experimental::execution
765759
.thread_index = index});
766760
}
767761

768-
// NOLINTNEXTLINE(modernize-use-ranges) we still support platforms without the std::ranges algorithms
769-
std::sort(thread_index_by_numa_node_.begin(), thread_index_by_numa_node_.end());
762+
std::ranges::sort(thread_index_by_numa_node_);
770763
std::vector<workstealing_victim> victims{};
771764
for (auto& state: thread_states_)
772765
{
@@ -842,15 +835,12 @@ namespace experimental::execution
842835
inline auto _static_thread_pool::num_threads(int numa) const noexcept -> std::size_t
843836
{
844837
thread_index_by_numa_node key{.numa_node = numa, .thread_index = 0};
845-
// NOLINTNEXTLINE(modernize-use-ranges) we still support platforms without the std::ranges algorithms
846-
auto it = std::lower_bound(thread_index_by_numa_node_.begin(),
847-
thread_index_by_numa_node_.end(),
848-
key);
838+
auto it = std::ranges::lower_bound(thread_index_by_numa_node_, key);
849839
if (it == thread_index_by_numa_node_.end())
850840
{
851841
return 0;
852842
}
853-
auto it_end = std::upper_bound(it, thread_index_by_numa_node_.end(), key);
843+
auto it_end = std::ranges::upper_bound(it, thread_index_by_numa_node_.end(), key);
854844
return static_cast<std::size_t>(std::distance(it, it_end));
855845
}
856846

@@ -876,10 +866,7 @@ namespace experimental::execution
876866
-> std::size_t
877867
{
878868
thread_index_by_numa_node key{.numa_node = node_index, .thread_index = 0};
879-
// NOLINTNEXTLINE(modernize-use-ranges) we still support platforms without the std::ranges algorithms
880-
auto it = std::lower_bound(thread_index_by_numa_node_.begin(),
881-
thread_index_by_numa_node_.end(),
882-
key);
869+
auto it = std::ranges::lower_bound(thread_index_by_numa_node_, key);
883870
STDEXEC_ASSERT(it != thread_index_by_numa_node_.end());
884871
std::advance(it, thread_index);
885872
return it->thread_index;
@@ -1578,7 +1565,6 @@ namespace experimental::execution
15781565
{}
15791566
};
15801567

1581-
#if !STDEXEC_NO_STDCPP_RANGES()
15821568
namespace schedule_all_
15831569
{
15841570
template <class Rcvr>
@@ -1832,14 +1818,11 @@ namespace experimental::execution
18321818
} // namespace schedule_all_
18331819

18341820
struct schedule_all_t;
1835-
#endif
18361821
} // namespace _pool_
18371822

18381823
struct static_thread_pool : private _pool_::_static_thread_pool
18391824
{
1840-
#if !STDEXEC_NO_STDCPP_RANGES()
18411825
friend struct _pool_::schedule_all_t;
1842-
#endif
18431826
using task_base = _pool_::task_base;
18441827

18451828
static_thread_pool() = default;
@@ -1872,7 +1855,6 @@ namespace experimental::execution
18721855
using _pool_::_static_thread_pool::params;
18731856
};
18741857

1875-
#if !STDEXEC_NO_STDCPP_RANGES()
18761858
namespace _pool_
18771859
{
18781860
struct schedule_all_t
@@ -1887,7 +1869,6 @@ namespace experimental::execution
18871869
} // namespace _pool_
18881870

18891871
inline constexpr _pool_::schedule_all_t schedule_all{};
1890-
#endif
18911872

18921873
} // namespace experimental::execution
18931874

include/nvexec/stream/algorithm_base.cuh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
#pragma once
2020

21-
#include "../../stdexec/__detail/__ranges.hpp"
2221
#include "../../stdexec/execution.hpp"
22+
2323
#include <cstddef>
24+
#include <ranges>
2425

2526
#include <cuda/std/type_traits>
2627

@@ -32,7 +33,7 @@ namespace nv::execution::_strm::__algo_range_init_fun
3233
{
3334
template <class Range, class InitT, class Fun>
3435
using binary_invoke_result_t = ::cuda::std::decay_t<
35-
::cuda::std::invoke_result_t<Fun, STDEXEC::ranges::range_reference_t<Range>, InitT>>;
36+
::cuda::std::invoke_result_t<Fun, std::ranges::range_reference_t<Range>, InitT>>;
3637

3738
template <class Sender, class Receiver, class InitT, class Fun, class DerivedReceiver>
3839
struct receiver : public stream_receiver_base

include/stdexec/__detail/__config.hpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,6 @@ namespace STDEXEC
592592
# define STDEXEC_TSAN() 0
593593
#endif
594594

595-
// Before clang-16, clang did not like libstdc++'s ranges implementation
596-
#if __has_include(<ranges>) && \
597-
(defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L) && \
598-
(!STDEXEC_CLANG() || STDEXEC_CLANG_VERSION >= 1600 || defined(_LIBCPP_VERSION))
599-
# define STDEXEC_NO_STDCPP_RANGES() 0
600-
#else
601-
# define STDEXEC_NO_STDCPP_RANGES() 1
602-
#endif
603-
604595
#if __has_include(<memory_resource>) && \
605596
(defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L)
606597
# define STDEXEC_NO_STDCPP_MEMORY_RESOURCE() 0

include/stdexec/__detail/__deprecations.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#pragma once
1717

1818
#include "__execution_fwd.hpp"
19+
#include "__ranges.hpp" // IWYU pragma: keep
1920

2021
#include "__prologue.hpp"
2122

@@ -27,8 +28,8 @@ namespace STDEXEC
2728
inline constexpr __execute_may_block_caller_t const & execute_may_block_caller =
2829
__execute_may_block_caller;
2930

30-
using empty_env [[deprecated(
31-
"STDEXEC::empty_env is now spelled " STDEXEC_PP_STRINGIZE(STDEXEC) "::env<>")]] = env<>;
31+
using empty_env
32+
[[deprecated("empty_env is now spelled " STDEXEC_PP_STRINGIZE(STDEXEC) "::env<>")]] = env<>;
3233

3334
using dependent_completions [[deprecated("use dependent_sender_error instead of "
3435
"dependent_completions")]] = dependent_sender_error;
@@ -86,6 +87,9 @@ namespace STDEXEC
8687

8788
[[deprecated]]
8889
inline constexpr exec::__execute_t const & execute = exec::__execute;
90+
91+
namespace [[deprecated("Use std::ranges directly")]] ranges
92+
{}
8993
} // namespace STDEXEC
9094

9195
#include "__epilogue.hpp"

0 commit comments

Comments
 (0)