From 9fc6a6b1a393d7eb02964a3d8a0bb928676fca28 Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Wed, 10 Nov 2021 11:39:23 +0530 Subject: [PATCH 01/12] Convert loop_idx_n to CPO --- .../hpx/parallel/algorithms/adjacent_find.hpp | 3 +- .../hpx/parallel/algorithms/detail/search.hpp | 4 +- .../hpx/parallel/algorithms/is_heap.hpp | 6 ++- .../hpx/parallel/algorithms/is_sorted.hpp | 3 +- .../algorithms/lexicographical_compare.hpp | 3 +- .../hpx/parallel/algorithms/mismatch.hpp | 19 ++++--- .../hpx/parallel/algorithms/remove.hpp | 4 +- .../include/hpx/parallel/util/loop.hpp | 53 +++++++++++++++---- 8 files changed, 68 insertions(+), 27 deletions(-) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/adjacent_find.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/adjacent_find.hpp index 169ae6f9b5af..c17644f64371 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/adjacent_find.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/adjacent_find.hpp @@ -193,7 +193,8 @@ namespace hpx { namespace parallel { inline namespace v1 { auto f1 = [pred_projected = std::move(pred_projected), tok]( zip_iterator it, std::size_t part_size, std::size_t base_idx) mutable { - util::loop_idx_n(base_idx, it, part_size, tok, + util::loop_idx_n>(base_idx, it, + part_size, tok, [&pred_projected, &tok](reference t, std::size_t i) { using hpx::get; if (pred_projected(get<0>(t), get<1>(t))) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/search.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/search.hpp index 01c4c4a11310..3e716522f24d 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/search.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/search.hpp @@ -108,7 +108,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { std::size_t base_idx) mutable -> void { FwdIter curr = it; - hpx::parallel::util::loop_idx_n(base_idx, it, part_size, tok, + hpx::parallel::util::loop_idx_n>(base_idx, it, part_size, tok, [diff, count, s_first, &tok, &curr, op = std::forward(op), proj1 = std::forward(proj1), @@ -208,7 +208,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { std::size_t base_idx) mutable -> void { FwdIter curr = it; - util::loop_idx_n(base_idx, it, part_size, tok, + util::loop_idx_n>(base_idx, it, part_size, tok, [count, diff, s_first, &tok, &curr, op = std::forward(op), proj1 = std::forward(proj1), diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/is_heap.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/is_heap.hpp index 6f104dede71f..c177d7435a4e 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/is_heap.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/is_heap.hpp @@ -212,7 +212,8 @@ namespace hpx { namespace parallel { inline namespace v1 { proj = std::forward(proj)](Iter it, std::size_t part_size, std::size_t base_idx) mutable -> void { - util::loop_idx_n(base_idx, it, part_size, tok, + util::loop_idx_n>(base_idx, it, + part_size, tok, [&tok, first, &comp, &proj]( type const& v, std::size_t i) -> void { if (hpx::util::invoke(comp, @@ -356,7 +357,8 @@ namespace hpx { namespace parallel { inline namespace v1 { proj = std::forward(proj)](Iter it, std::size_t part_size, std::size_t base_idx) mutable { - util::loop_idx_n(base_idx, it, part_size, tok, + util::loop_idx_n>(base_idx, it, + part_size, tok, [&tok, first, &comp, &proj]( type const& v, std::size_t i) -> void { if (hpx::util::invoke(comp, diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/is_sorted.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/is_sorted.hpp index 4568ce13a881..16c9d6c95c68 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/is_sorted.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/is_sorted.hpp @@ -391,7 +391,8 @@ namespace hpx { namespace parallel { inline namespace v1 { FwdIter part_begin, std::size_t part_size, std::size_t base_idx) mutable -> void { FwdIter trail = part_begin++; - util::loop_idx_n(++base_idx, part_begin, part_size - 1, tok, + util::loop_idx_n>(++base_idx, + part_begin, part_size - 1, tok, [&trail, &tok, &pred_projected]( reference& v, std::size_t ind) -> void { if (hpx::util::invoke(pred_projected, v, *trail++)) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/lexicographical_compare.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/lexicographical_compare.hpp index cb4fdd5c69e3..a9bef75ac4ab 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/lexicographical_compare.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/lexicographical_compare.hpp @@ -249,7 +249,8 @@ namespace hpx { namespace parallel { inline namespace v1 { auto f1 = [tok, pred, proj1, proj2](zip_iterator it, std::size_t part_count, std::size_t base_idx) mutable -> void { - util::loop_idx_n(base_idx, it, part_count, tok, + util::loop_idx_n>(base_idx, it, + part_count, tok, [&pred, &tok, &proj1, &proj2]( reference t, std::size_t i) -> void { using hpx::get; diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/mismatch.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/mismatch.hpp index af76a33e48ee..2d0ea461c6db 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/mismatch.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/mismatch.hpp @@ -282,11 +282,12 @@ namespace hpx { namespace parallel { inline namespace v1 { proj2 = std::forward(proj2)]( zip_iterator it, std::size_t part_count, std::size_t base_idx) mutable -> void { - util::loop_idx_n(base_idx, it, part_count, tok, - [&](reference t, std::size_t i) { - if (!HPX_INVOKE(f, - HPX_INVOKE(proj1, hpx::get<0>(t)), - HPX_INVOKE(proj2, hpx::get<1>(t)))) + util::loop_idx_n>(base_idx, it, + part_count, tok, + [&f, &proj1, &proj2, &tok](reference t, std::size_t i) { + if (!hpx::util::invoke(f, + hpx::util::invoke(proj1, hpx::get<0>(t)), + hpx::util::invoke(proj2, hpx::get<1>(t)))) { tok.cancel(i); } @@ -426,9 +427,11 @@ namespace hpx { namespace parallel { inline namespace v1 { auto f1 = [tok, f = std::forward(f)](zip_iterator it, std::size_t part_count, std::size_t base_idx) mutable -> void { - util::loop_idx_n(base_idx, it, part_count, tok, - [&](reference t, std::size_t i) { - if (!HPX_INVOKE(f, hpx::get<0>(t), hpx::get<1>(t))) + util::loop_idx_n>(base_idx, it, + part_count, tok, + [&f, &tok](reference t, std::size_t i) { + if (!hpx::util::invoke( + f, hpx::get<0>(t), hpx::get<1>(t))) { tok.cancel(i); } diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/remove.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/remove.hpp index 366610c05953..2d3d413bfb3d 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/remove.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/remove.hpp @@ -255,8 +255,8 @@ namespace hpx { namespace parallel { inline namespace v1 { template Iter sequential_remove_if(Iter first, Sent last, Pred pred, Proj proj) { - first = hpx::parallel::v1::detail::sequential_find_if( - first, last, pred, proj); + first = hpx::parallel::v1::detail::sequential_find_if< + hpx::execution::sequenced_policy>(first, last, pred, proj); if (first != last) for (Iter i = first; ++i != last;) diff --git a/libs/core/algorithms/include/hpx/parallel/util/loop.hpp b/libs/core/algorithms/include/hpx/parallel/util/loop.hpp index 8db87b73a7f8..9a2c22ddb814 100644 --- a/libs/core/algorithms/include/hpx/parallel/util/loop.hpp +++ b/libs/core/algorithms/include/hpx/parallel/util/loop.hpp @@ -1166,24 +1166,57 @@ namespace hpx { namespace parallel { namespace util { }; } // namespace detail - /////////////////////////////////////////////////////////////////////////// - template - HPX_FORCEINLINE constexpr Iter loop_idx_n( + /////////////////////////////////////////////////////////////////////// + template + struct loop_idx_n_t final + : hpx::functional::detail::tag_fallback> + { + private: + template + friend HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Iter + tag_fallback_invoke(hpx::parallel::util::loop_idx_n_t, + std::size_t base_idx, Iter it, std::size_t count, F&& f) + { + using cat = typename std::iterator_traits::iterator_category; + return detail::loop_idx_n::call( + base_idx, it, count, std::forward(f)); + } + + template + friend HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Iter + tag_fallback_invoke(hpx::parallel::util::loop_idx_n_t, + std::size_t base_idx, Iter it, std::size_t count, CancelToken& tok, + F&& f) + { + using cat = typename std::iterator_traits::iterator_category; + return detail::loop_idx_n::call( + base_idx, it, count, tok, std::forward(f)); + } + }; + +#if !defined(HPX_COMPUTE_DEVICE_CODE) + template + HPX_INLINE_CONSTEXPR_VARIABLE loop_idx_n_t loop_idx_n = + loop_idx_n_t{}; +#else + template + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Iter loop_idx_n( std::size_t base_idx, Iter it, std::size_t count, F&& f) { - using cat = typename std::iterator_traits::iterator_category; - return detail::loop_idx_n::call( + return hpx::parallel::util::loop_idx_n_t{}( base_idx, it, count, std::forward(f)); } - template - HPX_FORCEINLINE constexpr Iter loop_idx_n(std::size_t base_idx, Iter it, - std::size_t count, CancelToken& tok, F&& f) + template + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Iter loop_idx_n( + std::size_t base_idx, Iter it, std::size_t count, CancelToken& tok, + F&& f) { - using cat = typename std::iterator_traits::iterator_category; - return detail::loop_idx_n::call( + return hpx::parallel::util::loop_idx_n_t{}( base_idx, it, count, tok, std::forward(f)); } +#endif /////////////////////////////////////////////////////////////////////////// namespace detail { From c15e8523fd5edace650002e6d3fa4744bb7ab363 Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Wed, 10 Nov 2021 11:41:12 +0530 Subject: [PATCH 02/12] Adapt new vector_pack traits Adapt all_of, any_of, none_of and find_first vector_pack traits --- libs/core/execution/CMakeLists.txt | 6 +++ .../detail/simd/vector_pack_all_any_none.hpp | 42 +++++++++++++++++++ .../traits/detail/simd/vector_pack_find.hpp | 30 +++++++++++++ .../traits/vector_pack_all_any_none.hpp | 17 ++++++++ .../hpx/execution/traits/vector_pack_find.hpp | 17 ++++++++ 5 files changed, 112 insertions(+) create mode 100644 libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_all_any_none.hpp create mode 100644 libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_find.hpp create mode 100644 libs/core/execution/include/hpx/execution/traits/vector_pack_all_any_none.hpp create mode 100644 libs/core/execution/include/hpx/execution/traits/vector_pack_find.hpp diff --git a/libs/core/execution/CMakeLists.txt b/libs/core/execution/CMakeLists.txt index 44b55715034d..08f8d9ba8007 100644 --- a/libs/core/execution/CMakeLists.txt +++ b/libs/core/execution/CMakeLists.txt @@ -46,7 +46,9 @@ set(execution_headers hpx/execution/executors/rebind_executor.hpp hpx/execution/executors/static_chunk_size.hpp hpx/execution/traits/detail/simd/vector_pack_alignment_size.hpp + hpx/execution/traits/detail/simd/vector_pack_all_any_none.hpp hpx/execution/traits/detail/simd/vector_pack_count_bits.hpp + hpx/execution/traits/detail/simd/vector_pack_find.hpp hpx/execution/traits/detail/simd/vector_pack_load_store.hpp hpx/execution/traits/detail/simd/vector_pack_type.hpp hpx/execution/traits/detail/vc/vector_pack_alignment_size.hpp @@ -57,7 +59,9 @@ set(execution_headers hpx/execution/traits/future_then_result_exec.hpp hpx/execution/traits/is_execution_policy.hpp hpx/execution/traits/vector_pack_alignment_size.hpp + hpx/execution/traits/vector_pack_all_any_none.hpp hpx/execution/traits/vector_pack_count_bits.hpp + hpx/execution/traits/vector_pack_find.hpp hpx/execution/traits/vector_pack_load_store.hpp hpx/execution/traits/vector_pack_type.hpp ) @@ -85,6 +89,8 @@ set(execution_compat_headers hpx/parallel/executors/rebind_executor.hpp => hpx/execution.hpp hpx/parallel/executors/static_chunk_size.hpp => hpx/execution.hpp hpx/parallel/traits/vector_pack_alignment_size.hpp => hpx/execution.hpp + hpx/parallel/traits/vector_pack_all_any_none.hpp => hpx/execution.hpp + hpx/parallel/traits/vector_pack_find.hpp => hpx/execution.hpp hpx/parallel/traits/vector_pack_count_bits.hpp => hpx/execution.hpp hpx/parallel/traits/vector_pack_load_store.hpp => hpx/execution.hpp hpx/parallel/traits/vector_pack_type.hpp => hpx/execution.hpp diff --git a/libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_all_any_none.hpp b/libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_all_any_none.hpp new file mode 100644 index 000000000000..dcc15ecce62b --- /dev/null +++ b/libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_all_any_none.hpp @@ -0,0 +1,42 @@ +// Copyright (c) 2021 Srinivas Yadav +// +// 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 + +#if defined(HPX_HAVE_CXX20_EXPERIMENTAL_SIMD) +#include + +#include + +namespace hpx { namespace parallel { namespace traits { + /////////////////////////////////////////////////////////////////////// + template + HPX_HOST_DEVICE HPX_FORCEINLINE std::size_t all_of( + std::experimental::simd_mask const& msk) + { + return std::experimental::all_of(msk); + } + + /////////////////////////////////////////////////////////////////////// + template + HPX_HOST_DEVICE HPX_FORCEINLINE std::size_t any_of( + std::experimental::simd_mask const& msk) + { + return std::experimental::any_of(msk); + } + + /////////////////////////////////////////////////////////////////////// + template + HPX_HOST_DEVICE HPX_FORCEINLINE std::size_t none_of( + std::experimental::simd_mask const& msk) + { + return std::experimental::none_of(msk); + } +}}} // namespace hpx::parallel::traits + +#endif diff --git a/libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_find.hpp b/libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_find.hpp new file mode 100644 index 000000000000..f70da27920fc --- /dev/null +++ b/libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_find.hpp @@ -0,0 +1,30 @@ +// Copyright (c) 2021 Srinivas Yadav +// +// 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 + +#if defined(HPX_HAVE_CXX20_EXPERIMENTAL_SIMD) +#include + +#include + +namespace hpx { namespace parallel { namespace traits { + /////////////////////////////////////////////////////////////////////// + template + HPX_HOST_DEVICE HPX_FORCEINLINE int find_first_of( + std::experimental::simd_mask const& msk) + { + if (std::experimental::any_of(msk)) + { + return std::experimental::find_first_set(msk); + } + return -1; + } +}}} // namespace hpx::parallel::traits + +#endif diff --git a/libs/core/execution/include/hpx/execution/traits/vector_pack_all_any_none.hpp b/libs/core/execution/include/hpx/execution/traits/vector_pack_all_any_none.hpp new file mode 100644 index 000000000000..21a264167c3a --- /dev/null +++ b/libs/core/execution/include/hpx/execution/traits/vector_pack_all_any_none.hpp @@ -0,0 +1,17 @@ +// Copyright (c) 2021 Srinivas Yadav +// +// 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 + +#if defined(HPX_HAVE_DATAPAR) + +#if !defined(__CUDACC__) +#include +#endif + +#endif diff --git a/libs/core/execution/include/hpx/execution/traits/vector_pack_find.hpp b/libs/core/execution/include/hpx/execution/traits/vector_pack_find.hpp new file mode 100644 index 000000000000..00f5fe9c071a --- /dev/null +++ b/libs/core/execution/include/hpx/execution/traits/vector_pack_find.hpp @@ -0,0 +1,17 @@ +// Copyright (c) 2021 Srinivas Yadav +// +// 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 + +#if defined(HPX_HAVE_DATAPAR) + +#if !defined(__CUDACC__) +#include +#endif + +#endif From 84babab6bcdcc4cc8931b2be76f237fffa17fd3d Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Wed, 10 Nov 2021 11:44:15 +0530 Subject: [PATCH 03/12] Adapt tokenized loops and loop_idx_n for datapar Adapts cancelation token overload for datpar_loop and datapar_loop_ind. Adapts loop_idx_n for datapar. --- .../include/hpx/parallel/datapar/loop.hpp | 246 ++++++++++++++++++ 1 file changed, 246 insertions(+) diff --git a/libs/core/algorithms/include/hpx/parallel/datapar/loop.hpp b/libs/core/algorithms/include/hpx/parallel/datapar/loop.hpp index 584728d50bf6..573960122ea8 100644 --- a/libs/core/algorithms/include/hpx/parallel/datapar/loop.hpp +++ b/libs/core/algorithms/include/hpx/parallel/datapar/loop.hpp @@ -161,6 +161,60 @@ namespace hpx { namespace parallel { namespace util { } return it; } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static typename std::enable_if< + iterator_datapar_compatible::value, Begin>::type + call(Begin first, End last, CancelToken& tok, F&& f) + { + while (!is_data_aligned(first) && first != last) + { + datapar_loop_step_tok::call1(f, first); + if (tok.was_cancelled()) + return first; + ++first; + } + + static std::size_t constexpr size = + traits::vector_pack_size::value; + + End const lastV = last - (size + 1); + while (first < lastV) + { + std::size_t incr = + datapar_loop_step_tok::callv(f, first); + if (tok.was_cancelled()) + return first; + std::advance(first, incr); + } + + while (first != last) + { + datapar_loop_step_tok::call1(f, first); + if (tok.was_cancelled()) + return first; + ++first; + } + + return first; + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static typename std::enable_if< + !iterator_datapar_compatible::value, Begin>::type + call(Begin it, End end, CancelToken& tok, F&& f) + { + while (it != end) + { + datapar_loop_step_tok::call1(f, it); + if (tok.was_cancelled()) + return it; + ++it; + } + return it; + } }; /////////////////////////////////////////////////////////////////////// @@ -331,6 +385,60 @@ namespace hpx { namespace parallel { namespace util { } return first; } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static typename std::enable_if< + iterator_datapar_compatible::value, InIter>::type + call(InIter first, std::size_t count, CancelToken& tok, F&& f) + { + std::size_t len = count; + + for (/* */; !detail::is_data_aligned(first) && len != 0; --len) + { + datapar_loop_step_tok::call1(f, first); + if (tok.was_cancelled()) + return first; + ++first; + } + + static std::size_t constexpr size = + traits::vector_pack_size::value; + + for (std::int64_t len_v = std::int64_t(len - (size + 1)); + len_v > 0; len_v -= size, len -= size) + { + std::size_t incr = + datapar_loop_step_tok::callv(f, first); + if (tok.was_cancelled()) + return first; + std::advance(first, incr); + } + + for (/* */; len != 0; --len) + { + datapar_loop_step_tok::call1(f, first); + if (tok.was_cancelled()) + return first; + ++first; + } + + return first; + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static typename std::enable_if< + !iterator_datapar_compatible::value, InIter>::type + call(InIter first, std::size_t count, CancelToken& tok, F&& f) + { + for (/* */; count != 0; --count) + { + datapar_loop_step_tok::call1(f, first); + if (tok.was_cancelled()) + return first; + ++first; + } + return first; + } }; /////////////////////////////////////////////////////////////////////// @@ -384,6 +492,91 @@ namespace hpx { namespace parallel { namespace util { return first; } }; + + /////////////////////////////////////////////////////////////////////// + template + struct datapar_loop_idx_n + { + typedef typename std::decay::type iterator_type; + typedef typename std::iterator_traits::value_type + value_type; + + typedef typename traits::vector_pack_type::type V; + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static Iter call( + std::size_t base_idx, Iter it, std::size_t count, F&& f) + { + std::size_t len = count; + + for (/* */; !detail::is_data_aligned(it) && len != 0; --len) + { + datapar_loop_idx_step::call1(f, it, base_idx); + ++it; + ++base_idx; + } + + static std::size_t constexpr size = + traits::vector_pack_size::value; + + for (std::int64_t len_v = std::int64_t(len - (size + 1)); + len_v > 0; len_v -= size, len -= size) + { + std::size_t incr = + datapar_loop_idx_step::callv(f, it, base_idx); + std::advance(it, incr); + base_idx += incr; + } + + for (/* */; len != 0; --len) + { + datapar_loop_idx_step::call1(f, it, base_idx); + ++it; + ++base_idx; + } + return it; + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static Iter call( + std::size_t base_idx, Iter it, std::size_t count, + CancelToken& tok, F&& f) + { + std::size_t len = count; + + for (/* */; !detail::is_data_aligned(it) && len != 0; --len) + { + datapar_loop_idx_step::call1(f, it, base_idx); + if (tok.was_cancelled(base_idx)) + return it; + ++it; + ++base_idx; + } + + static std::size_t constexpr size = + traits::vector_pack_size::value; + + for (std::int64_t len_v = std::int64_t(len - (size + 1)); + len_v > 0; len_v -= size, len -= size) + { + datapar_loop_idx_step::callv(f, it, base_idx); + if (tok.was_cancelled(base_idx)) + return it; + std::advance(it, size); + base_idx += size; + } + + for (/* */; len != 0; --len) + { + datapar_loop_idx_step::call1(f, it, base_idx); + if (tok.was_cancelled(base_idx)) + return it; + ++it; + ++base_idx; + } + return it; + } + }; } // namespace detail /////////////////////////////////////////////////////////////////////////// @@ -442,6 +635,24 @@ namespace hpx { namespace parallel { namespace util { begin, end, std::forward(f)); } + template + HPX_HOST_DEVICE HPX_FORCEINLINE Begin tag_invoke( + hpx::parallel::util::loop_t, hpx::execution::simd_policy, Begin begin, + End end, CancelToken& tok, F&& f) + { + return detail::datapar_loop::call( + begin, end, tok, std::forward(f)); + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE Begin tag_invoke( + hpx::parallel::util::loop_t, hpx::execution::simd_task_policy, + Begin begin, End end, CancelToken& tok, F&& f) + { + return detail::datapar_loop::call( + begin, end, tok, std::forward(f)); + } + /////////////////////////////////////////////////////////////////////////// template HPX_HOST_DEVICE HPX_FORCEINLINE Begin tag_invoke( @@ -485,6 +696,18 @@ namespace hpx { namespace parallel { namespace util { it, count, std::forward(f)); } + template + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr typename std::enable_if< + hpx::is_vectorpack_execution_policy::value, Iter>::type + tag_invoke(hpx::parallel::util::loop_n_t, Iter it, + std::size_t count, CancelToken& tok, F&& f) + { + return hpx::parallel::util::detail::datapar_loop_n::call( + it, count, tok, std::forward(f)); + } + + /////////////////////////////////////////////////////////////////////////// template HPX_HOST_DEVICE HPX_FORCEINLINE constexpr typename std::enable_if< hpx::is_vectorpack_execution_policy::value, Iter>::type @@ -494,6 +717,29 @@ namespace hpx { namespace parallel { namespace util { return hpx::parallel::util::detail::datapar_loop_n_ind::call( it, count, std::forward(f)); } + + /////////////////////////////////////////////////////////////////////////// + template + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr typename std::enable_if< + hpx::is_vectorpack_execution_policy::value, Iter>::type + tag_invoke(hpx::parallel::util::loop_idx_n_t, + std::size_t base_idx, Iter it, std::size_t count, F&& f) + { + return hpx::parallel::util::detail::datapar_loop_idx_n::call( + base_idx, it, count, std::forward(f)); + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr typename std::enable_if< + hpx::is_vectorpack_execution_policy::value, Iter>::type + tag_invoke(hpx::parallel::util::loop_idx_n_t, + std::size_t base_idx, Iter it, std::size_t count, CancelToken& tok, + F&& f) + { + return hpx::parallel::util::detail::datapar_loop_idx_n::call( + base_idx, it, count, tok, std::forward(f)); + } }}} // namespace hpx::parallel::util #endif From 8901eb94d68f64bceaf5c1d67451d9e4d0c6b01f Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Wed, 10 Nov 2021 11:45:34 +0530 Subject: [PATCH 04/12] Convert existing find helper functions to CPOs --- .../hpx/parallel/algorithms/detail/find.hpp | 243 ++++++++++++++++-- .../include/hpx/parallel/algorithms/find.hpp | 21 +- 2 files changed, 231 insertions(+), 33 deletions(-) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp index be05a72b41ff..a9bc972e1a87 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp @@ -1,5 +1,6 @@ // Copyright (c) 2020 Hartmut Kaiser // Copyright (c) 2021 Giannis Gonidelis +// Copyright (c) 2021 Srinivas Yadav // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -8,56 +9,248 @@ #pragma once #include +#include #include +#include +#include +#include +#include #include +#include +#include + namespace hpx { namespace parallel { inline namespace v1 { namespace detail { // provide implementation of std::find supporting iterators/sentinels - template - inline constexpr Iterator sequential_find( - Iterator first, Sentinel last, T const& value, Proj proj = Proj()) + template + struct sequential_find_t + : hpx::functional::detail::tag_fallback> { - for (; first != last; ++first) + private: + template + friend inline constexpr Iterator tag_fallback_invoke( + sequential_find_t, Iterator first, Sentinel last, + T const& value, Proj proj = Proj()) { - if (hpx::util::invoke(proj, *first) == value) + for (; first != last; ++first) { - return first; + if (hpx::util::invoke(proj, *first) == value) + { + return first; + } } + return first; + } + + template + friend inline constexpr void tag_fallback_invoke( + sequential_find_t, std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, + T const& val, Proj&& proj) + { + util::loop_idx_n(base_idx, part_begin, part_count, tok, + [&val, &proj, &tok](auto& v, std::size_t i) -> void { + if (hpx::util::invoke(proj, v) == val) + { + tok.cancel(i); + } + }); } - return first; + }; + +#if !defined(HPX_COMPUTE_DEVICE_CODE) + template + HPX_INLINE_CONSTEXPR_VARIABLE sequential_find_t sequential_find = + sequential_find_t{}; +#else + template + inline constexpr Iterator sequential_find( + Iterator first, Sentinel last, T const& val, Proj proj = Proj()) + { + return sequential_find_t{}(first, last, val, proj); + } + + template + inline constexpr void sequential_find(std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, T const& val, + Proj&& proj) + { + return sequential_find_t{}(base_idx, part_begin, part_count, + tok, val, std::forward(proj)); } +#endif // provide implementation of std::find_if supporting iterators/sentinels - template - inline constexpr Iterator sequential_find_if( - Iterator first, Sentinel last, Pred pred, Proj proj = Proj()) + template + struct sequential_find_if_t + : hpx::functional::detail::tag_fallback> { - for (; first != last; ++first) + private: + template + friend inline constexpr Iterator tag_fallback_invoke( + sequential_find_if_t, Iterator first, Sentinel last, + Pred pred, Proj proj = Proj()) { - if (hpx::util::invoke(pred, hpx::util::invoke(proj, *first))) + for (; first != last; ++first) { - return first; + if (hpx::util::invoke(pred, hpx::util::invoke(proj, *first))) + { + return first; + } } + return first; } - return first; - } - // provide implementation of std::find_if supporting iterators/sentinels - template - inline constexpr Iterator sequential_find_if_not( + template + friend inline constexpr void tag_fallback_invoke( + sequential_find_if_t, FwdIter part_begin, + std::size_t part_count, Token& tok, F&& op, Proj&& proj) + { + util::loop_n>(part_begin, part_count, tok, + [&op, &tok, &proj](auto const& curr) { + if (hpx::util::invoke(op, hpx::util::invoke(proj, *curr))) + { + tok.cancel(); + } + }); + } + + template + friend inline constexpr void tag_fallback_invoke( + sequential_find_if_t, std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, F&& f, + Proj&& proj) + { + util::loop_idx_n(base_idx, part_begin, part_count, tok, + [&f, &proj, &tok](auto& v, std::size_t i) -> void { + if (hpx::util::invoke(f, hpx::util::invoke(proj, v))) + { + tok.cancel(i); + } + }); + } + }; + +#if !defined(HPX_COMPUTE_DEVICE_CODE) + template + HPX_INLINE_CONSTEXPR_VARIABLE sequential_find_if_t + sequential_find_if = sequential_find_if_t{}; +#else + template + inline constexpr Iterator sequential_find_if( Iterator first, Sentinel last, Pred pred, Proj proj = Proj()) { - for (; first != last; ++first) + return sequential_find_if_t{}(first, last, pred, proj); + } + + template + inline constexpr void sequential_find_if(FwdIter part_begin, + std::size_t part_count, Token& tok, F&& op, Proj&& proj) + { + return sequential_find_if_t{}(part_begin, part_count, tok, + std::forward(op), std::forward(proj)); + } + + template + inline constexpr void sequential_find_if(std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, F&& f, + Proj&& proj) + { + return sequential_find_if_t{}(base_idx, part_begin, + part_count, tok, std::forward(f), std::forward(proj)); + } +#endif + + // provide implementation of std::find_if_not supporting iterators/sentinels + template + struct sequential_find_if_not_t + : hpx::functional::detail::tag_fallback> + { + private: + template + friend inline constexpr Iterator tag_fallback_invoke( + sequential_find_if_not_t, Iterator first, Sentinel last, + Pred pred, Proj proj = Proj()) { - if (!hpx::util::invoke(pred, hpx::util::invoke(proj, *first))) + for (; first != last; ++first) { - return first; + if (!hpx::util::invoke(pred, hpx::util::invoke(proj, *first))) + { + return first; + } } + return first; + } + + template + friend inline constexpr void tag_fallback_invoke( + sequential_find_if_not_t, FwdIter part_begin, + std::size_t part_count, Token& tok, F&& op, Proj&& proj) + { + util::loop_n>(part_begin, part_count, tok, + [&op, &tok, &proj](auto const& curr) { + if (!hpx::util::invoke(op, hpx::util::invoke(proj, *curr))) + { + tok.cancel(); + } + }); + } + + template + friend inline constexpr void tag_fallback_invoke( + sequential_find_if_not_t, std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, F&& f, + Proj&& proj) + { + util::loop_idx_n(base_idx, part_begin, part_count, tok, + [&f, &proj, &tok](auto& v, std::size_t i) -> void { + if (!hpx::util::invoke(f, hpx::util::invoke(proj, v))) + { + tok.cancel(i); + } + }); } - return first; + }; + +#if !defined(HPX_COMPUTE_DEVICE_CODE) + template + HPX_INLINE_CONSTEXPR_VARIABLE sequential_find_if_not_t + sequential_find_if_not = sequential_find_if_not_t{}; +#else + template + inline constexpr Iterator sequential_find_if_not( + Iterator first, Sentinel last, Pred pred, Proj proj = Proj()) + { + return sequential_find_if_not_t{}(first, last, pred, proj); + } + + template + inline constexpr void sequential_find_if_not(FwdIter part_begin, + std::size_t part_count, Token& tok, F&& op, Proj&& proj) + { + return sequential_find_if_not_t{}(part_begin, part_count, tok, + std::forward(op), std::forward(proj)); + } + + template + inline constexpr void sequential_find_if_not(std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, F&& f, + Proj&& proj) + { + return sequential_find_if_not_t{}(base_idx, part_begin, + part_count, tok, std::forward(f), std::forward(proj)); } +#endif }}}} // namespace hpx::parallel::v1::detail diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/find.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/find.hpp index 783548b90c89..897911b5f983 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/find.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/find.hpp @@ -419,7 +419,7 @@ namespace hpx { namespace parallel { inline namespace v1 { static constexpr Iter sequential(ExPolicy, Iter first, Sent last, T const& val, Proj&& proj = Proj()) { - return sequential_find( + return sequential_find( first, last, val, std::forward(proj)); } @@ -443,7 +443,8 @@ namespace hpx { namespace parallel { inline namespace v1 { auto f1 = [val, proj = std::forward(proj), tok](Iter it, std::size_t part_size, std::size_t base_idx) mutable -> void { - util::loop_idx_n(base_idx, it, part_size, tok, + util::loop_idx_n>(base_idx, it, + part_size, tok, [&val, &proj, &tok](type& v, std::size_t i) -> void { if (hpx::util::invoke(proj, v) == val) { @@ -520,7 +521,7 @@ namespace hpx { namespace parallel { inline namespace v1 { static constexpr Iter sequential( ExPolicy, Iter first, Sent last, F&& f, Proj&& proj = Proj()) { - return sequential_find_if( + return sequential_find_if( first, last, std::forward(f), std::forward(proj)); } @@ -545,7 +546,8 @@ namespace hpx { namespace parallel { inline namespace v1 { proj = std::forward(proj), tok](Iter it, std::size_t part_size, std::size_t base_idx) mutable -> void { - util::loop_idx_n(base_idx, it, part_size, tok, + util::loop_idx_n>(base_idx, it, + part_size, tok, [&f, &proj, &tok](type& v, std::size_t i) -> void { if (hpx::util::invoke( f, hpx::util::invoke(proj, v))) @@ -629,7 +631,7 @@ namespace hpx { namespace parallel { inline namespace v1 { static constexpr Iter sequential( ExPolicy, Iter first, Sent last, F&& f, Proj&& proj = Proj()) { - return sequential_find_if_not( + return sequential_find_if_not( first, last, std::forward(f), std::forward(proj)); } @@ -654,7 +656,8 @@ namespace hpx { namespace parallel { inline namespace v1 { proj = std::forward(proj), tok](Iter it, std::size_t part_size, std::size_t base_idx) mutable -> void { - util::loop_idx_n(base_idx, it, part_size, tok, + util::loop_idx_n>(base_idx, it, + part_size, tok, [&f, &proj, &tok](type& v, std::size_t i) -> void { if (!hpx::util::invoke( f, hpx::util::invoke(proj, v))) @@ -839,7 +842,8 @@ namespace hpx { namespace parallel { inline namespace v1 { proj2 = std::forward(proj2)](Iter1 it, std::size_t part_size, std::size_t base_idx) mutable -> void { - util::loop_idx_n(base_idx, it, part_size, tok, + util::loop_idx_n>(base_idx, it, + part_size, tok, [=, &tok, &op, &proj1, &proj2]( auto t, std::size_t i) -> void { if (hpx::util::invoke(op, @@ -1003,7 +1007,8 @@ namespace hpx { namespace parallel { inline namespace v1 { proj2 = std::forward(proj2)](FwdIter it, std::size_t part_size, std::size_t base_idx) mutable -> void { - util::loop_idx_n(base_idx, it, part_size, tok, + util::loop_idx_n>(base_idx, it, + part_size, tok, [&tok, &s_first, &s_last, &op, &proj1, &proj2]( reference v, std::size_t i) -> void { for (FwdIter2 iter = s_first; iter != s_last; From fa192b5045d892724584801058b053bb7b19b8ee Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Wed, 10 Nov 2021 11:47:37 +0530 Subject: [PATCH 05/12] Simplify datapar iterator helpers and added new facilites Simplify datapar iterator helpers. Adds datapar_loop_step_tok for tokenized loops for datapar. Adds transform binary loop for datapar. --- .../hpx/parallel/datapar/iterator_helpers.hpp | 168 +++++++++++++- .../hpx/parallel/datapar/transform_loop.hpp | 211 ++++++++++++++++++ 2 files changed, 368 insertions(+), 11 deletions(-) diff --git a/libs/core/algorithms/include/hpx/parallel/datapar/iterator_helpers.hpp b/libs/core/algorithms/include/hpx/parallel/datapar/iterator_helpers.hpp index 785b6b9cc6b8..df21af6f4ef6 100644 --- a/libs/core/algorithms/include/hpx/parallel/datapar/iterator_helpers.hpp +++ b/libs/core/algorithms/include/hpx/parallel/datapar/iterator_helpers.hpp @@ -210,23 +210,21 @@ namespace hpx { namespace parallel { namespace util { namespace detail { typedef typename traits::vector_pack_type::type V; template - HPX_HOST_DEVICE HPX_FORCEINLINE static - typename hpx::util::invoke_result::type - call1(F&& f, Iter& it) + HPX_HOST_DEVICE HPX_FORCEINLINE static void call1(F&& f, Iter& it) { - store_on_exit_unaligned tmp(it); + V1 tmp(traits::vector_pack_load::aligned(it)); + HPX_INVOKE(f, &tmp); + traits::vector_pack_store::aligned(tmp, it); ++it; - return HPX_INVOKE(f, &tmp); } template - HPX_HOST_DEVICE HPX_FORCEINLINE static - typename hpx::util::invoke_result::type - callv(F&& f, Iter& it) + HPX_HOST_DEVICE HPX_FORCEINLINE static void callv(F&& f, Iter& it) { - store_on_exit tmp(it); + V tmp(traits::vector_pack_load::aligned(it)); + HPX_INVOKE(f, &tmp); + traits::vector_pack_store::aligned(tmp, it); std::advance(it, traits::vector_pack_size::value); - return HPX_INVOKE(f, &tmp); } }; @@ -258,6 +256,62 @@ namespace hpx { namespace parallel { namespace util { namespace detail { } }; + /////////////////////////////////////////////////////////////////////////// + template + struct datapar_loop_idx_step + { + typedef typename std::iterator_traits::value_type value_type; + + typedef typename traits::vector_pack_type::type V1; + typedef typename traits::vector_pack_type::type V; + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static void call1( + F&& f, Iter& it, std::size_t base_idx) + { + V1 tmp(traits::vector_pack_load::aligned(it)); + HPX_INVOKE(f, tmp, base_idx); + traits::vector_pack_store::aligned(tmp, it); + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static void callv( + F&& f, Iter& it, std::size_t base_idx) + { + V tmp(traits::vector_pack_load::aligned(it)); + HPX_INVOKE(f, tmp, base_idx); + traits::vector_pack_store::aligned(tmp, it); + } + }; + + /////////////////////////////////////////////////////////////////////////// + template + struct datapar_loop_step_tok + { + typedef typename std::iterator_traits::value_type value_type; + + typedef typename traits::vector_pack_type::type V1; + typedef typename traits::vector_pack_type::type V; + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static void call1(F&& f, Iter& it) + { + V1 tmp(traits::vector_pack_load::aligned(it)); + HPX_INVOKE(f, &tmp); + traits::vector_pack_store::aligned(tmp, it); + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static std::size_t callv( + F&& f, Iter& it) + { + V tmp(traits::vector_pack_load::aligned(it)); + HPX_INVOKE(f, &tmp); + traits::vector_pack_store::aligned(tmp, it); + return traits::vector_pack_size::value; + } + }; + /////////////////////////////////////////////////////////////////////////// template struct invoke_vectorized_in2 @@ -477,6 +531,62 @@ namespace hpx { namespace parallel { namespace util { namespace detail { } }; + template + struct invoke_vectorized_inout2_ind + { + template + HPX_HOST_DEVICE HPX_FORCEINLINE static void call_aligned( + F&& f, InIter1& it1, InIter2& it2, OutIter& dest) + { + static_assert(traits::vector_pack_size::value == + traits::vector_pack_size::value, + "the sizes of the vector-packs should be equal"); + + typedef + typename std::iterator_traits::value_type value_type1; + typedef + typename std::iterator_traits::value_type value_type2; + + V1 tmp1(traits::vector_pack_load::aligned(it1)); + V2 tmp2(traits::vector_pack_load::aligned(it2)); + + auto ret = HPX_INVOKE(f, tmp1, tmp2); + traits::vector_pack_store::aligned( + ret, dest); + + std::advance(it1, traits::vector_pack_size::value); + std::advance(it2, traits::vector_pack_size::value); + std::advance(dest, ret.size()); + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static void call_unaligned( + F&& f, InIter1& it1, InIter2& it2, OutIter& dest) + { + static_assert(traits::vector_pack_size::value == + traits::vector_pack_size::value, + "the sizes of the vector-packs should be equal"); + + typedef + typename std::iterator_traits::value_type value_type1; + typedef + typename std::iterator_traits::value_type value_type2; + + V1 tmp1(traits::vector_pack_load::unaligned(it1)); + V2 tmp2(traits::vector_pack_load::unaligned(it2)); + + auto ret = HPX_INVOKE(f, tmp1, tmp2); + traits::vector_pack_store::unaligned( + ret, dest); + + std::advance(it1, traits::vector_pack_size::value); + std::advance(it2, traits::vector_pack_size::value); + std::advance(dest, ret.size()); + } + }; + struct datapar_transform_loop_step { template @@ -520,7 +630,7 @@ namespace hpx { namespace parallel { namespace util { namespace detail { typedef typename traits::vector_pack_type::type V; HPX_ASSERT(is_data_aligned(it) && is_data_aligned(dest)); - invoke_vectorized_inout1_ind::call_aligned( + invoke_vectorized_inout1::call_aligned( std::forward(f), it, dest); } @@ -559,6 +669,23 @@ namespace hpx { namespace parallel { namespace util { namespace detail { std::forward(f), it, dest); } + template + HPX_HOST_DEVICE HPX_FORCEINLINE static void call1( + F&& f, InIter1& it1, InIter2& it2, OutIter& dest) + { + typedef + typename std::iterator_traits::value_type value_type1; + typedef + typename std::iterator_traits::value_type value_type2; + + typedef typename traits::vector_pack_type::type V1; + typedef typename traits::vector_pack_type::type V2; + + invoke_vectorized_inout2_ind::call_unaligned( + std::forward(f), it1, it2, dest); + } + /////////////////////////////////////////////////////////////////// template HPX_HOST_DEVICE HPX_FORCEINLINE static void callv( @@ -573,6 +700,25 @@ namespace hpx { namespace parallel { namespace util { namespace detail { invoke_vectorized_inout1_ind::call_aligned( std::forward(f), it, dest); } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static void callv( + F&& f, InIter1& it1, InIter2& it2, OutIter& dest) + { + typedef + typename std::iterator_traits::value_type value1_type; + typedef + typename std::iterator_traits::value_type value2_type; + + typedef typename traits::vector_pack_type::type V1; + typedef typename traits::vector_pack_type::type V2; + + HPX_ASSERT(is_data_aligned(it1) && is_data_aligned(it2) && + is_data_aligned(dest)); + invoke_vectorized_inout2_ind::call_aligned( + std::forward(f), it1, it2, dest); + } }; }}}} // namespace hpx::parallel::util::detail diff --git a/libs/core/algorithms/include/hpx/parallel/datapar/transform_loop.hpp b/libs/core/algorithms/include/hpx/parallel/datapar/transform_loop.hpp index 2ce296068896..fcf1c187b597 100644 --- a/libs/core/algorithms/include/hpx/parallel/datapar/transform_loop.hpp +++ b/libs/core/algorithms/include/hpx/parallel/datapar/transform_loop.hpp @@ -515,5 +515,216 @@ namespace hpx { namespace parallel { namespace util { return detail::datapar_transform_binary_loop::call( first1, last1, first2, last2, dest, std::forward(f)); } + + namespace detail { + /////////////////////////////////////////////////////////////////////// + template + struct datapar_transform_binary_loop_ind_n + { + typedef typename std::decay::type iterator1_type; + typedef typename std::iterator_traits::value_type + value_type; + + typedef typename traits::vector_pack_type::type V; + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static typename std::enable_if< + iterators_datapar_compatible::value && + iterators_datapar_compatible::value && + iterator_datapar_compatible::value && + iterator_datapar_compatible::value && + iterator_datapar_compatible::value, + hpx::tuple>::type + call(InIter1 first1, std::size_t count, InIter2 first2, + OutIter dest, F&& f) + { + std::size_t len = count; + + for (/* */; + !(is_data_aligned(first1) && is_data_aligned(first2) && + is_data_aligned(dest)) && + len != 0; + --len) + { + datapar_transform_loop_step_ind::call1( + f, first1, first2, dest); + } + + static constexpr std::size_t size = + traits::vector_pack_size::value; + + for (std::int64_t len_v = std::int64_t(len - (size + 1)); + len_v > 0; len_v -= size, len -= size) + { + datapar_transform_loop_step_ind::callv( + f, first1, first2, dest); + } + + for (/* */; len != 0; --len) + { + datapar_transform_loop_step_ind::call1( + f, first1, first2, dest); + } + + return hpx::make_tuple( + std::move(first1), std::move(first2), std::move(dest)); + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static typename std::enable_if< + !iterators_datapar_compatible::value || + !iterators_datapar_compatible::value || + !iterator_datapar_compatible::value || + !iterator_datapar_compatible::value || + !iterator_datapar_compatible::value, + hpx::tuple>::type + call(InIter1 first1, std::size_t count, InIter2 first2, + OutIter dest, F&& f) + { + return util::transform_binary_loop_ind_n< + hpx::execution::sequenced_policy>( + first1, count, first2, dest, std::forward(f)); + } + }; + } // namespace detail + + template + HPX_HOST_DEVICE HPX_FORCEINLINE typename std::enable_if< + hpx::is_vectorpack_execution_policy::value, + hpx::tuple>::type + tag_invoke(hpx::parallel::util::transform_binary_loop_ind_n_t, + InIter1 first1, std::size_t count, InIter2 first2, OutIter dest, F&& f) + { + return detail::datapar_transform_binary_loop_ind_n::call(first1, count, first2, dest, std::forward(f)); + } + + namespace detail { + /////////////////////////////////////////////////////////////////////// + template + struct datapar_transform_binary_loop_ind + { + typedef typename std::decay::type iterator1_type; + typedef typename std::decay::type iterator2_type; + + typedef typename std::iterator_traits::value_type + value1_type; + typedef typename std::iterator_traits::value_type + value2_type; + + typedef typename traits::vector_pack_type::type V11; + typedef typename traits::vector_pack_type::type V12; + + typedef typename traits::vector_pack_type::type V1; + typedef typename traits::vector_pack_type::type V2; + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static typename std::enable_if< + iterators_datapar_compatible::value && + iterators_datapar_compatible::value && + iterator_datapar_compatible::value && + iterator_datapar_compatible::value && + iterator_datapar_compatible::value, + util::in_in_out_result>::type + call(InIter1 first1, InIter1 last1, InIter2 first2, OutIter dest, + F&& f) + { + auto ret = util::transform_binary_loop_ind_n< + hpx::execution::par_simd_policy>(first1, + std::distance(first1, last1), first2, dest, + std::forward(f)); + + return util::in_in_out_result{ + hpx::get<0>(ret), hpx::get<1>(ret), hpx::get<2>(ret)}; + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static typename std::enable_if< + !iterators_datapar_compatible::value || + !iterators_datapar_compatible::value || + !iterator_datapar_compatible::value || + !iterator_datapar_compatible::value || + !iterator_datapar_compatible::value, + util::in_in_out_result>::type + call(InIter1 first1, InIter1 last1, InIter2 first2, OutIter dest, + F&& f) + { + return util::transform_binary_loop_ind< + hpx::execution::sequenced_policy>( + first1, last1, first2, dest, std::forward(f)); + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static typename std::enable_if< + iterators_datapar_compatible::value && + iterators_datapar_compatible::value && + iterator_datapar_compatible::value && + iterator_datapar_compatible::value && + iterator_datapar_compatible::value, + util::in_in_out_result>::type + call(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, + OutIter dest, F&& f) + { + std::size_t count = (std::min)( + std::distance(first1, last1), std::distance(first2, last2)); + + auto ret = util::transform_binary_loop_ind_n< + hpx::execution::par_simd_policy>( + first1, count, first2, dest, std::forward(f)); + + return util::in_in_out_result{ + hpx::get<0>(ret), hpx::get<1>(ret), hpx::get<2>(ret)}; + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE static typename std::enable_if< + !iterators_datapar_compatible::value || + !iterators_datapar_compatible::value || + !iterator_datapar_compatible::value || + !iterator_datapar_compatible::value || + !iterator_datapar_compatible::value, + util::in_in_out_result>::type + call(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, + OutIter dest, F&& f) + { + return util::transform_binary_loop_ind< + hpx::execution::sequenced_policy>( + first1, last1, first2, last2, dest, std::forward(f)); + } + }; + } // namespace detail + + template + HPX_HOST_DEVICE HPX_FORCEINLINE typename std::enable_if< + hpx::is_vectorpack_execution_policy::value, + util::in_in_out_result>::type + tag_invoke(hpx::parallel::util::transform_binary_loop_ind_t, + InIter1 first1, InIter1 last1, InIter2 first2, OutIter dest, F&& f) + { + return detail::datapar_transform_binary_loop_ind::call(first1, last1, first2, dest, std::forward(f)); + } + + template + HPX_HOST_DEVICE HPX_FORCEINLINE typename std::enable_if< + hpx::is_vectorpack_execution_policy::value, + util::in_in_out_result>::type + tag_invoke(hpx::parallel::util::transform_binary_loop_ind_t, + InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, + OutIter dest, F&& f) + { + return detail::datapar_transform_binary_loop_ind::call(first1, last1, first2, last2, dest, + std::forward(f)); + } }}} // namespace hpx::parallel::util #endif From 7e6a56d57a925c714108dfb779d9095acec9eb5a Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Wed, 10 Nov 2021 11:49:09 +0530 Subject: [PATCH 06/12] Adapt datapar all any non --- libs/core/algorithms/CMakeLists.txt | 1 + .../hpx/parallel/algorithms/all_any_none.hpp | 48 ++- .../include/hpx/parallel/datapar.hpp | 1 + .../include/hpx/parallel/datapar/find.hpp | 274 ++++++++++++++++++ .../hpx/parallel/util/invoke_projected.hpp | 2 +- .../algorithms/detail/predicates.hpp | 12 +- 6 files changed, 301 insertions(+), 37 deletions(-) create mode 100644 libs/core/algorithms/include/hpx/parallel/datapar/find.hpp diff --git a/libs/core/algorithms/CMakeLists.txt b/libs/core/algorithms/CMakeLists.txt index a2d034d54b52..53f318237c1e 100644 --- a/libs/core/algorithms/CMakeLists.txt +++ b/libs/core/algorithms/CMakeLists.txt @@ -154,6 +154,7 @@ set(algorithms_headers hpx/parallel/container_numeric.hpp hpx/parallel/datapar.hpp hpx/parallel/datapar/fill.hpp + hpx/parallel/datapar/find.hpp hpx/parallel/datapar/generate.hpp hpx/parallel/datapar/adjacent_difference.hpp hpx/parallel/datapar/iterator_helpers.hpp diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/all_any_none.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/all_any_none.hpp index 4a4cb0781ef2..8f065f8158e1 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/all_any_none.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/all_any_none.hpp @@ -270,7 +270,7 @@ namespace hpx { namespace parallel { inline namespace v1 { static bool sequential( ExPolicy, Iter first, Sent last, F&& f, Proj&& proj) { - return detail::sequential_find_if(first, last, + return detail::sequential_find_if(first, last, util::invoke_projected(std::forward(f), std::forward(proj))) == last; } @@ -292,14 +292,9 @@ namespace hpx { namespace parallel { inline namespace v1 { proj = std::forward(proj)]( FwdIter part_begin, std::size_t part_count) mutable -> bool { - util::loop_n>(part_begin, part_count, - tok, [&op, &tok, &proj](FwdIter const& curr) { - if (hpx::util::invoke( - op, hpx::util::invoke(proj, *curr))) - { - tok.cancel(); - } - }); + detail::sequential_find_if>( + part_begin, part_count, tok, std::forward(op), + std::forward(proj)); return !tok.was_cancelled(); }; @@ -308,7 +303,8 @@ namespace hpx { namespace parallel { inline namespace v1 { std::forward(policy), first, detail::distance(first, last), std::move(f1), [](std::vector>&& results) { - return detail::sequential_find_if_not( + return detail::sequential_find_if_not< + hpx::execution::sequenced_policy>( hpx::util::begin(results), hpx::util::end(results), [](hpx::future& val) { @@ -369,7 +365,7 @@ namespace hpx { namespace parallel { inline namespace v1 { static bool sequential( ExPolicy, Iter first, Sent last, F&& f, Proj&& proj) { - return detail::sequential_find_if(first, last, + return detail::sequential_find_if(first, last, util::invoke_projected(std::forward(f), std::forward(proj))) != last; } @@ -391,14 +387,9 @@ namespace hpx { namespace parallel { inline namespace v1 { proj = std::forward(proj)]( FwdIter part_begin, std::size_t part_count) mutable -> bool { - util::loop_n>(part_begin, part_count, - tok, [&op, &tok, &proj](FwdIter const& curr) { - if (hpx::util::invoke( - op, hpx::util::invoke(proj, *curr))) - { - tok.cancel(); - } - }); + detail::sequential_find_if>( + part_begin, part_count, tok, std::forward(op), + std::forward(proj)); return tok.was_cancelled(); }; @@ -407,7 +398,8 @@ namespace hpx { namespace parallel { inline namespace v1 { std::forward(policy), first, detail::distance(first, last), std::move(f1), [](std::vector>&& results) { - return detail::sequential_find_if( + return detail::sequential_find_if< + hpx::execution::sequenced_policy>( hpx::util::begin(results), hpx::util::end(results), [](hpx::future& val) { @@ -468,7 +460,7 @@ namespace hpx { namespace parallel { inline namespace v1 { static bool sequential( ExPolicy, Iter first, Sent last, F&& f, Proj&& proj) { - return detail::sequential_find_if_not(first, last, + return detail::sequential_find_if_not(first, last, std::forward(f), std::forward(proj)) == last; } @@ -490,14 +482,9 @@ namespace hpx { namespace parallel { inline namespace v1 { proj = std::forward(proj)]( FwdIter part_begin, std::size_t part_count) mutable -> bool { - util::loop_n>(part_begin, part_count, - tok, [&op, &tok, &proj](FwdIter const& curr) { - if (!hpx::util::invoke( - op, hpx::util::invoke(proj, *curr))) - { - tok.cancel(); - } - }); + detail::sequential_find_if_not>( + part_begin, part_count, tok, std::forward(op), + std::forward(proj)); return !tok.was_cancelled(); }; @@ -506,7 +493,8 @@ namespace hpx { namespace parallel { inline namespace v1 { std::forward(policy), first, detail::distance(first, last), std::move(f1), [](std::vector>&& results) { - return detail::sequential_find_if_not( + return detail::sequential_find_if_not< + hpx::execution::sequenced_policy>( hpx::util::begin(results), hpx::util::end(results), [](hpx::future& val) { diff --git a/libs/core/algorithms/include/hpx/parallel/datapar.hpp b/libs/core/algorithms/include/hpx/parallel/datapar.hpp index 7632149de61d..f0f7f27521d2 100644 --- a/libs/core/algorithms/include/hpx/parallel/datapar.hpp +++ b/libs/core/algorithms/include/hpx/parallel/datapar.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/libs/core/algorithms/include/hpx/parallel/datapar/find.hpp b/libs/core/algorithms/include/hpx/parallel/datapar/find.hpp new file mode 100644 index 000000000000..310493bcdb0f --- /dev/null +++ b/libs/core/algorithms/include/hpx/parallel/datapar/find.hpp @@ -0,0 +1,274 @@ +// Copyright (c) 2021 Srinivas Yadav +// +// 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 + +#if defined(HPX_HAVE_DATAPAR) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace hpx { namespace parallel { inline namespace v1 { namespace detail { + /////////////////////////////////////////////////////////////////////////// + template + struct datapar_find + { + template + static inline constexpr Iterator call( + Iterator first, Sentinel last, T const& val, Proj proj) + { + int offset = 0; + util::cancellation_token<> tok; + + auto ret = util::loop_n(first, std::distance(first, last), + tok, [&offset, &val, &tok, &proj](auto const& curr) { + auto msk = hpx::util::invoke(proj, *curr) == val; + offset = hpx::parallel::traits::find_first_of(msk); + if (offset != -1) + { + tok.cancel(); + } + }); + + if (tok.was_cancelled()) + std::advance(ret, offset); + return ret; + } + + template + static inline constexpr void call(std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, + T const& val, Proj&& proj) + { + util::loop_idx_n(base_idx, part_begin, part_count, tok, + [&val, &proj, &tok](auto& v, std::size_t i) -> void { + auto msk = hpx::util::invoke(proj, v) == val; + int offset = hpx::parallel::traits::find_first_of(msk); + if (offset != -1) + tok.cancel(i + offset); + }); + } + }; + + template + inline constexpr std::enable_if_t< + hpx::is_vectorpack_execution_policy::value, Iterator> + tag_invoke(sequential_find_t, Iterator first, Sentinel last, + T const& val, Proj proj = Proj()) + { + return datapar_find::call(first, last, val, proj); + } + + template + inline constexpr std::enable_if_t< + hpx::is_vectorpack_execution_policy::value, void> + tag_invoke(sequential_find_t, std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, T const& val, + Proj&& proj) + { + return datapar_find::call(base_idx, part_begin, part_count, + tok, val, std::forward(proj)); + } + + /////////////////////////////////////////////////////////////////////////// + template + struct datapar_find_if + { + template + static inline constexpr Iterator call( + Iterator first, Sentinel last, Pred pred, Proj proj) + { + int offset = 0; + util::cancellation_token<> tok; + + auto ret = util::loop_n(first, std::distance(first, last), + tok, [&offset, &pred, &tok, &proj](auto const& curr) { + auto msk = + hpx::util::invoke(pred, hpx::util::invoke(proj, *curr)); + offset = hpx::parallel::traits::find_first_of(msk); + if (offset != -1) + { + tok.cancel(); + } + }); + + if (tok.was_cancelled()) + std::advance(ret, offset); + return ret; + } + + template + static inline constexpr void call(FwdIter part_begin, + std::size_t part_count, Token& tok, F&& op, Proj&& proj) + { + util::loop_n>(part_begin, part_count, tok, + [&op, &tok, &proj](auto const& curr) { + auto msk = + hpx::util::invoke(op, hpx::util::invoke(proj, *curr)); + if (hpx::parallel::traits::any_of(msk)) + { + tok.cancel(); + } + }); + } + + template + static inline constexpr void call(std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, F&& f, + Proj&& proj) + { + util::loop_idx_n(base_idx, part_begin, part_count, tok, + [&f, &proj, &tok](auto& v, std::size_t i) -> void { + auto msk = hpx::util::invoke(f, hpx::util::invoke(proj, v)); + int offset = hpx::parallel::traits::find_first_of(msk); + if (offset != -1) + tok.cancel(i + offset); + }); + } + }; + + template + inline constexpr std::enable_if_t< + hpx::is_vectorpack_execution_policy::value, Iterator> + tag_invoke(sequential_find_if_t, Iterator first, Sentinel last, + Pred pred, Proj proj = Proj()) + { + return datapar_find_if::call(first, last, pred, proj); + } + + template + inline constexpr std::enable_if_t< + hpx::is_vectorpack_execution_policy::value, void> + tag_invoke(sequential_find_if_t, FwdIter part_begin, + std::size_t part_count, Token& tok, F&& op, Proj&& proj) + { + return datapar_find_if::call(part_begin, part_count, tok, + std::forward(op), std::forward(proj)); + } + + template + inline constexpr std::enable_if_t< + hpx::is_vectorpack_execution_policy::value, void> + tag_invoke(sequential_find_if_t, std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, F&& op, + Proj&& proj) + { + return datapar_find_if::call(base_idx, part_begin, part_count, + tok, std::forward(op), std::forward(proj)); + } + /////////////////////////////////////////////////////////////////////////// + template + struct datapar_find_if_not + { + template + static inline constexpr Iterator call( + Iterator first, Sentinel last, Pred pred, Proj proj) + { + int offset = 0; + util::cancellation_token<> tok; + + auto ret = util::loop_n(first, std::distance(first, last), + tok, [&offset, &pred, &tok, &proj](auto const& curr) { + auto msk = !hpx::util::invoke( + pred, hpx::util::invoke(proj, *curr)); + offset = hpx::parallel::traits::find_first_of(msk); + if (offset != -1) + { + tok.cancel(); + } + }); + + if (tok.was_cancelled()) + std::advance(ret, offset); + return ret; + } + + template + static inline constexpr void call(FwdIter part_begin, + std::size_t part_count, Token& tok, F&& op, Proj&& proj) + { + util::loop_n>(part_begin, part_count, tok, + [&op, &tok, &proj](auto const& curr) { + auto msk = + !hpx::util::invoke(op, hpx::util::invoke(proj, *curr)); + if (hpx::parallel::traits::any_of(msk)) + { + tok.cancel(); + } + }); + } + + template + static inline constexpr void call(std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, F&& f, + Proj&& proj) + { + util::loop_idx_n(base_idx, part_begin, part_count, tok, + [&f, &proj, &tok](auto& v, std::size_t i) -> void { + auto msk = + !hpx::util::invoke(f, hpx::util::invoke(proj, v)); + int offset = hpx::parallel::traits::find_first_of(msk); + if (offset != -1) + tok.cancel(i + offset); + }); + } + }; + + template + inline constexpr std::enable_if_t< + hpx::is_vectorpack_execution_policy::value, Iterator> + tag_invoke(sequential_find_if_not_t, Iterator first, + Sentinel last, Pred pred, Proj proj = Proj()) + { + return datapar_find_if_not::call(first, last, pred, proj); + } + + template + inline constexpr std::enable_if_t< + hpx::is_vectorpack_execution_policy::value, void> + tag_invoke(sequential_find_if_not_t, FwdIter part_begin, + std::size_t part_count, Token& tok, F&& op, Proj&& proj) + { + return datapar_find_if_not::call(part_begin, part_count, tok, + std::forward(op), std::forward(proj)); + } + + template + inline constexpr std::enable_if_t< + hpx::is_vectorpack_execution_policy::value, void> + tag_invoke(sequential_find_if_not_t, std::size_t base_idx, + FwdIter part_begin, std::size_t part_count, Token& tok, F&& op, + Proj&& proj) + { + return datapar_find_if_not::call(base_idx, part_begin, + part_count, tok, std::forward(op), std::forward(proj)); + } +}}}} // namespace hpx::parallel::v1::detail +#endif diff --git a/libs/core/algorithms/include/hpx/parallel/util/invoke_projected.hpp b/libs/core/algorithms/include/hpx/parallel/util/invoke_projected.hpp index fd2cbe250009..8e1e0f1b0bda 100644 --- a/libs/core/algorithms/include/hpx/parallel/util/invoke_projected.hpp +++ b/libs/core/algorithms/include/hpx/parallel/util/invoke_projected.hpp @@ -65,7 +65,7 @@ namespace hpx { namespace parallel { namespace util { } template - bool operator()(T&& t, T&& u) + auto operator()(T&& t, T&& u) { return HPX_INVOKE(pred_, std::forward(t), std::forward(u)); } diff --git a/libs/core/execution/include/hpx/execution/algorithms/detail/predicates.hpp b/libs/core/execution/include/hpx/execution/algorithms/detail/predicates.hpp index 87f50e9192c9..98302fc606e2 100644 --- a/libs/core/execution/include/hpx/execution/algorithms/detail/predicates.hpp +++ b/libs/core/execution/include/hpx/execution/algorithms/detail/predicates.hpp @@ -278,7 +278,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { template ::value>::type> - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr bool operator()( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( T1&& t1, T2&& t2) const { return t1 == t2; @@ -290,7 +290,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { template ::value>::type> - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr bool operator()( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( T1&& t1, T2&& t2) const { return t1 != t2; @@ -323,7 +323,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { struct less { template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr bool operator()( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( T1&& t1, T2&& t2) const { return std::forward(t1) < std::forward(t2); @@ -333,7 +333,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { struct greater { template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr bool operator()( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( T1&& t1, T2&& t2) const { return std::forward(t1) > std::forward(t2); @@ -343,7 +343,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { struct greater_equal { template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr bool operator()( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( T1&& t1, T2&& t2) const { return std::forward(t1) >= std::forward(t2); @@ -353,7 +353,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { struct less_equal { template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr bool operator()( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( T1&& t1, T2&& t2) const { return std::forward(t1) <= std::forward(t2); From a28599fd466c3c65d3650d96e98ae8e8028d5075 Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Wed, 10 Nov 2021 11:49:41 +0530 Subject: [PATCH 07/12] Split all any none tests into header and source. --- .../tests/unit/algorithms/all_of.cpp | 356 +---------------- .../tests/unit/algorithms/all_of_tests.hpp | 365 +++++++++++++++++ .../tests/unit/algorithms/any_of.cpp | 356 +---------------- .../tests/unit/algorithms/any_of_tests.hpp | 366 ++++++++++++++++++ .../tests/unit/algorithms/none_of.cpp | 352 +---------------- .../tests/unit/algorithms/none_of_tests.hpp | 360 +++++++++++++++++ 6 files changed, 1103 insertions(+), 1052 deletions(-) create mode 100644 libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp create mode 100644 libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp create mode 100644 libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp diff --git a/libs/core/algorithms/tests/unit/algorithms/all_of.cpp b/libs/core/algorithms/tests/unit/algorithms/all_of.cpp index 315a322af4c6..b8fa987d511c 100644 --- a/libs/core/algorithms/tests/unit/algorithms/all_of.cpp +++ b/libs/core/algorithms/tests/unit/algorithms/all_of.cpp @@ -5,172 +5,14 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#include -#include -#include -#include -#include #include -#include #include #include -#include "test_utils.hpp" - -/////////////////////////////////////////////////////////////////////////////// -template -void test_all_of(IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool result = hpx::all_of(iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { return v != 0; }); - - // verify values - bool expected = std::all_of( - std::begin(c), std::end(c), [](std::size_t v) { return v != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_all_of(ExPolicy&& policy, IteratorTag) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool result = hpx::all_of(policy, iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { return v != 0; }); - - // verify values - bool expected = std::all_of( - std::begin(c), std::end(c), [](std::size_t v) { return v != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_all_of_ranges_seq(IteratorTag, Proj proj = Proj()) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool result = hpx::ranges::all_of( - iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return v != 0; }, proj); - - // verify values - bool expected = std::all_of(std::begin(c), std::end(c), - [proj](std::size_t v) { return proj(v) != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_all_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool result = hpx::ranges::all_of( - policy, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return v != 0; }, proj); - - // verify values - bool expected = std::all_of(std::begin(c), std::end(c), - [proj](std::size_t v) { return proj(v) != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_all_of_async(ExPolicy&& p, IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - hpx::future f = hpx::all_of(p, iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { return v != 0; }); - f.wait(); - - // verify values - bool expected = std::all_of( - std::begin(c), std::end(c), [](std::size_t v) { return v != 0; }); - - HPX_TEST_EQ(expected, f.get()); - } -} - -template -void test_all_of_ranges_async(ExPolicy&& p, IteratorTag, Proj proj = Proj()) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - hpx::future f = hpx::ranges::all_of( - p, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return v != 0; }, proj); - f.wait(); - - // verify values - bool expected = std::all_of(std::begin(c), std::end(c), - [proj](std::size_t v) { return proj(v) != 0; }); - - HPX_TEST_EQ(expected, f.get()); - } -} +#include "all_of_tests.hpp" +//////////////////////////////////////////////////////////////////////////// template void test_all_of() { @@ -233,123 +75,7 @@ void all_of_test() test_all_of(); } -/////////////////////////////////////////////////////////////////////////////// -template -void test_all_of_exception(ExPolicy&& policy, IteratorTag) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - try - { - hpx::all_of(policy, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { - return throw std::runtime_error("test"), v != 0; - }); - - HPX_TEST(false); - } - catch (hpx::exception_list const& e) - { - caught_exception = true; - test::test_num_exceptions::call(policy, e); - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - } -} - -template -void test_all_of_exception(IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - try - { - hpx::all_of(iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { - return throw std::runtime_error("test"), v != 0; - }); - - HPX_TEST(false); - } - catch (hpx::exception_list const& e) - { - caught_exception = true; - test::test_num_exceptions::call(hpx::execution::seq, e); - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - } -} - -template -void test_all_of_exception_async(ExPolicy&& p, IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - bool returned_from_algorithm = false; - try - { - hpx::future f = hpx::all_of(p, iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { - return throw std::runtime_error("test"), v != 0; - }); - returned_from_algorithm = true; - f.get(); - - HPX_TEST(false); - } - catch (hpx::exception_list const& e) - { - caught_exception = true; - test::test_num_exceptions::call(p, e); - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - HPX_TEST(returned_from_algorithm); - } -} - +//////////////////////////////////////////////////////////////////////////// template void test_all_of_exception() { @@ -373,81 +99,7 @@ void all_of_exception_test() test_all_of_exception(); } -/////////////////////////////////////////////////////////////////////////////// -template -void test_all_of_bad_alloc(ExPolicy&& policy, IteratorTag) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - try - { - hpx::all_of(policy, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return throw std::bad_alloc(), v != 0; }); - - HPX_TEST(false); - } - catch (std::bad_alloc const&) - { - caught_exception = true; - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - } -} - -template -void test_all_of_bad_alloc_async(ExPolicy&& p, IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - bool returned_from_algorithm = false; - try - { - hpx::future f = hpx::all_of(p, iterator(std::begin(c)), - iterator(std::end(c)), - [](std::size_t v) { return throw std::bad_alloc(), v != 0; }); - returned_from_algorithm = true; - f.get(); - - HPX_TEST(false); - } - catch (std::bad_alloc const&) - { - caught_exception = true; - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - HPX_TEST(returned_from_algorithm); - } -} - +//////////////////////////////////////////////////////////////////////////// template void test_all_of_bad_alloc() { diff --git a/libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp b/libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp new file mode 100644 index 000000000000..6de7f8fa919b --- /dev/null +++ b/libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp @@ -0,0 +1,365 @@ +// Copyright (c) 2014-2020 Hartmut Kaiser +// +// 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 +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "test_utils.hpp" + +/////////////////////////////////////////////////////////////////////////////// +template +void test_all_of(IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool result = hpx::all_of(iterator(std::begin(c)), + iterator(std::end(c)), [](auto v) { return v != 0; }); + + // verify values + bool expected = std::all_of( + std::begin(c), std::end(c), [](auto v) { return v != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_all_of(ExPolicy&& policy, IteratorTag) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool result = hpx::all_of(policy, iterator(std::begin(c)), + iterator(std::end(c)), [](auto v) { return v != 0; }); + + // verify values + bool expected = std::all_of( + std::begin(c), std::end(c), [](auto v) { return v != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_all_of_ranges_seq(IteratorTag, Proj proj = Proj()) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool result = hpx::ranges::all_of( + iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return v != 0; }, proj); + + // verify values + bool expected = std::all_of(std::begin(c), std::end(c), + [proj](auto v) { return proj(v) != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_all_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool result = hpx::ranges::all_of( + policy, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return v != 0; }, proj); + + // verify values + bool expected = std::all_of(std::begin(c), std::end(c), + [proj](auto v) { return proj(v) != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_all_of_async(ExPolicy&& p, IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + hpx::future f = hpx::all_of(p, iterator(std::begin(c)), + iterator(std::end(c)), [](auto v) { return v != 0; }); + f.wait(); + + // verify values + bool expected = std::all_of( + std::begin(c), std::end(c), [](auto v) { return v != 0; }); + + HPX_TEST_EQ(expected, f.get()); + } +} + +template +void test_all_of_ranges_async(ExPolicy&& p, IteratorTag, Proj proj = Proj()) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + hpx::future f = hpx::ranges::all_of( + p, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return v != 0; }, proj); + f.wait(); + + // verify values + bool expected = std::all_of(std::begin(c), std::end(c), + [proj](auto v) { return proj(v) != 0; }); + + HPX_TEST_EQ(expected, f.get()); + } +} + +/////////////////////////////////////////////////////////////////////////////// +template +void test_all_of_exception(ExPolicy&& policy, IteratorTag) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + try + { + hpx::all_of(policy, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { + return throw std::runtime_error("test"), v != 0; + }); + + HPX_TEST(false); + } + catch (hpx::exception_list const& e) + { + caught_exception = true; + test::test_num_exceptions::call(policy, e); + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + } +} + +template +void test_all_of_exception(IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + try + { + hpx::all_of( + iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { + return throw std::runtime_error("test"), v != 0; + }); + + HPX_TEST(false); + } + catch (hpx::exception_list const& e) + { + caught_exception = true; + test::test_num_exceptions::call(hpx::execution::seq, e); + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + } +} + +template +void test_all_of_exception_async(ExPolicy&& p, IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + bool returned_from_algorithm = false; + try + { + hpx::future f = hpx::all_of( + p, iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { + return throw std::runtime_error("test"), v != 0; + }); + returned_from_algorithm = true; + f.get(); + + HPX_TEST(false); + } + catch (hpx::exception_list const& e) + { + caught_exception = true; + test::test_num_exceptions::call(p, e); + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + HPX_TEST(returned_from_algorithm); + } +} + +/////////////////////////////////////////////////////////////////////////////// +template +void test_all_of_bad_alloc(ExPolicy&& policy, IteratorTag) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + try + { + hpx::all_of(policy, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return throw std::bad_alloc(), v != 0; }); + + HPX_TEST(false); + } + catch (std::bad_alloc const&) + { + caught_exception = true; + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + } +} + +template +void test_all_of_bad_alloc_async(ExPolicy&& p, IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + bool returned_from_algorithm = false; + try + { + hpx::future f = + hpx::all_of(p, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return throw std::bad_alloc(), v != 0; }); + returned_from_algorithm = true; + f.get(); + + HPX_TEST(false); + } + catch (std::bad_alloc const&) + { + caught_exception = true; + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + HPX_TEST(returned_from_algorithm); + } +} diff --git a/libs/core/algorithms/tests/unit/algorithms/any_of.cpp b/libs/core/algorithms/tests/unit/algorithms/any_of.cpp index e1999c72c7bc..e8e1f0305387 100644 --- a/libs/core/algorithms/tests/unit/algorithms/any_of.cpp +++ b/libs/core/algorithms/tests/unit/algorithms/any_of.cpp @@ -5,172 +5,14 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#include -#include -#include -#include -#include #include -#include #include #include -#include "test_utils.hpp" - -/////////////////////////////////////////////////////////////////////////////// -template -void test_any_of(IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool result = hpx::any_of(iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { return v != 0; }); - - // verify values - bool expected = std::any_of( - std::begin(c), std::end(c), [](std::size_t v) { return v != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_any_of(ExPolicy&& policy, IteratorTag) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool result = hpx::any_of(policy, iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { return v != 0; }); - - // verify values - bool expected = std::any_of( - std::begin(c), std::end(c), [](std::size_t v) { return v != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_any_of_ranges_seq(IteratorTag, Proj proj = Proj()) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool result = hpx::ranges::any_of( - iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return v != 0; }, proj); - - // verify values - bool expected = std::any_of(std::begin(c), std::end(c), - [proj](std::size_t v) { return proj(v) != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_any_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool result = hpx::ranges::any_of( - policy, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return v != 0; }, proj); - - // verify values - bool expected = std::any_of(std::begin(c), std::end(c), - [proj](std::size_t v) { return proj(v) != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_any_of_async(ExPolicy&& p, IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - hpx::future f = hpx::any_of(p, iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { return v != 0; }); - f.wait(); - - // verify values - bool expected = std::any_of( - std::begin(c), std::end(c), [](std::size_t v) { return v != 0; }); - - HPX_TEST_EQ(expected, f.get()); - } -} - -template -void test_any_of_ranges_async(ExPolicy&& p, IteratorTag, Proj proj = Proj()) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - hpx::future f = hpx::ranges::any_of( - p, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return v != 0; }, proj); - f.wait(); - - // verify values - bool expected = std::any_of(std::begin(c), std::end(c), - [proj](std::size_t v) { return proj(v) != 0; }); - - HPX_TEST_EQ(expected, f.get()); - } -} +#include "any_of_tests.hpp" +//////////////////////////////////////////////////////////////////////////// template void test_any_of() { @@ -227,129 +69,13 @@ void test_any_of() // } // } +//////////////////////////////////////////////////////////////////////////// void any_of_test() { test_any_of(); test_any_of(); } -/////////////////////////////////////////////////////////////////////////////// -template -void test_any_of_exception(IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - try - { - hpx::any_of(iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { - return throw std::runtime_error("test"), v != 0; - }); - - HPX_TEST(false); - } - catch (hpx::exception_list const& e) - { - caught_exception = true; - test::test_num_exceptions::call(hpx::execution::seq, e); - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - } -} - -template -void test_any_of_exception(ExPolicy&& policy, IteratorTag) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - try - { - hpx::any_of(policy, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { - return throw std::runtime_error("test"), v != 0; - }); - - HPX_TEST(false); - } - catch (hpx::exception_list const& e) - { - caught_exception = true; - test::test_num_exceptions::call(policy, e); - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - } -} - -template -void test_any_of_exception_async(ExPolicy&& p, IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - bool returned_from_algorithm = false; - try - { - hpx::future f = hpx::any_of(p, iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { - return throw std::runtime_error("test"), v != 0; - }); - returned_from_algorithm = true; - f.get(); - - HPX_TEST(false); - } - catch (hpx::exception_list const& e) - { - caught_exception = true; - test::test_num_exceptions::call(p, e); - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - HPX_TEST(returned_from_algorithm); - } -} - template void test_any_of_exception() { @@ -367,87 +93,13 @@ void test_any_of_exception() test_any_of_exception_async(par(task), IteratorTag()); } +//////////////////////////////////////////////////////////////////////////// void any_of_exception_test() { test_any_of_exception(); test_any_of_exception(); } -/////////////////////////////////////////////////////////////////////////////// -template -void test_any_of_bad_alloc(ExPolicy&& policy, IteratorTag) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - try - { - hpx::any_of(policy, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return throw std::bad_alloc(), v != 0; }); - - HPX_TEST(false); - } - catch (std::bad_alloc const&) - { - caught_exception = true; - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - } -} - -template -void test_any_of_bad_alloc_async(ExPolicy&& p, IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - bool returned_from_algorithm = false; - try - { - hpx::future f = hpx::any_of(p, iterator(std::begin(c)), - iterator(std::end(c)), - [](std::size_t v) { return throw std::bad_alloc(), v != 0; }); - returned_from_algorithm = true; - f.get(); - - HPX_TEST(false); - } - catch (std::bad_alloc const&) - { - caught_exception = true; - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - HPX_TEST(returned_from_algorithm); - } -} - template void test_any_of_bad_alloc() { diff --git a/libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp b/libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp new file mode 100644 index 000000000000..72a023125220 --- /dev/null +++ b/libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp @@ -0,0 +1,366 @@ +// Copyright (c) 2014-2020 Hartmut Kaiser +// +// 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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "test_utils.hpp" + +/////////////////////////////////////////////////////////////////////////////// +template +void test_any_of(IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool result = hpx::any_of(iterator(std::begin(c)), + iterator(std::end(c)), [](auto v) { return v != 0; }); + + // verify values + bool expected = std::any_of( + std::begin(c), std::end(c), [](auto v) { return v != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_any_of(ExPolicy&& policy, IteratorTag) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool result = hpx::any_of(policy, iterator(std::begin(c)), + iterator(std::end(c)), [](auto v) { return v != 0; }); + + // verify values + bool expected = std::any_of( + std::begin(c), std::end(c), [](auto v) { return v != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_any_of_ranges_seq(IteratorTag, Proj proj = Proj()) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool result = hpx::ranges::any_of( + iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return v != 0; }, proj); + + // verify values + bool expected = std::any_of(std::begin(c), std::end(c), + [proj](auto v) { return proj(v) != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_any_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool result = hpx::ranges::any_of( + policy, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return v != 0; }, proj); + + // verify values + bool expected = std::any_of(std::begin(c), std::end(c), + [proj](auto v) { return proj(v) != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_any_of_async(ExPolicy&& p, IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + hpx::future f = hpx::any_of(p, iterator(std::begin(c)), + iterator(std::end(c)), [](auto v) { return v != 0; }); + f.wait(); + + // verify values + bool expected = std::any_of( + std::begin(c), std::end(c), [](auto v) { return v != 0; }); + + HPX_TEST_EQ(expected, f.get()); + } +} + +template +void test_any_of_ranges_async(ExPolicy&& p, IteratorTag, Proj proj = Proj()) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + hpx::future f = hpx::ranges::any_of( + p, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return v != 0; }, proj); + f.wait(); + + // verify values + bool expected = std::any_of(std::begin(c), std::end(c), + [proj](auto v) { return proj(v) != 0; }); + + HPX_TEST_EQ(expected, f.get()); + } +} + +/////////////////////////////////////////////////////////////////////////////// +template +void test_any_of_exception(IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + try + { + hpx::any_of( + iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { + return throw std::runtime_error("test"), v != 0; + }); + + HPX_TEST(false); + } + catch (hpx::exception_list const& e) + { + caught_exception = true; + test::test_num_exceptions::call(hpx::execution::seq, e); + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + } +} + +template +void test_any_of_exception(ExPolicy&& policy, IteratorTag) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + try + { + hpx::any_of(policy, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { + return throw std::runtime_error("test"), v != 0; + }); + + HPX_TEST(false); + } + catch (hpx::exception_list const& e) + { + caught_exception = true; + test::test_num_exceptions::call(policy, e); + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + } +} + +template +void test_any_of_exception_async(ExPolicy&& p, IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + bool returned_from_algorithm = false; + try + { + hpx::future f = hpx::any_of( + p, iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { + return throw std::runtime_error("test"), v != 0; + }); + returned_from_algorithm = true; + f.get(); + + HPX_TEST(false); + } + catch (hpx::exception_list const& e) + { + caught_exception = true; + test::test_num_exceptions::call(p, e); + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + HPX_TEST(returned_from_algorithm); + } +} + +/////////////////////////////////////////////////////////////////////////////// +template +void test_any_of_bad_alloc(ExPolicy&& policy, IteratorTag) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + try + { + hpx::any_of(policy, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return throw std::bad_alloc(), v != 0; }); + + HPX_TEST(false); + } + catch (std::bad_alloc const&) + { + caught_exception = true; + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + } +} + +template +void test_any_of_bad_alloc_async(ExPolicy&& p, IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + bool returned_from_algorithm = false; + try + { + hpx::future f = + hpx::any_of(p, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return throw std::bad_alloc(), v != 0; }); + returned_from_algorithm = true; + f.get(); + + HPX_TEST(false); + } + catch (std::bad_alloc const&) + { + caught_exception = true; + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + HPX_TEST(returned_from_algorithm); + } +} diff --git a/libs/core/algorithms/tests/unit/algorithms/none_of.cpp b/libs/core/algorithms/tests/unit/algorithms/none_of.cpp index 8206a0fc81b4..bedc747f6a92 100644 --- a/libs/core/algorithms/tests/unit/algorithms/none_of.cpp +++ b/libs/core/algorithms/tests/unit/algorithms/none_of.cpp @@ -5,168 +5,14 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#include -#include -#include -#include -#include #include -#include #include #include -#include "test_utils.hpp" - -/////////////////////////////////////////////////////////////////////////////// -template -void test_none_of(IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 1, 3}; - for (std::size_t i : iseq) - { - std::vector c = test::fill_all_any_none(3, i); //-V106 - - bool result = hpx::none_of(iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { return v != 0; }); - - // verify values - bool expected = std::none_of( - std::begin(c), std::end(c), [](std::size_t v) { return v != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_none_of(ExPolicy&& policy, IteratorTag) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 1, 3}; - for (std::size_t i : iseq) - { - std::vector c = test::fill_all_any_none(3, i); //-V106 - - bool result = hpx::none_of(policy, iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { return v != 0; }); - - // verify values - bool expected = std::none_of( - std::begin(c), std::end(c), [](std::size_t v) { return v != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_none_of_ranges_seq(IteratorTag, Proj proj = Proj()) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 1, 3}; - for (std::size_t i : iseq) - { - std::vector c = test::fill_all_any_none(3, i); //-V106 - - bool result = hpx::ranges::none_of( - iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return v != 0; }, proj); - - // verify values - bool expected = std::none_of(std::begin(c), std::end(c), - [proj](std::size_t v) { return proj(v) != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_none_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 1, 3}; - for (std::size_t i : iseq) - { - std::vector c = test::fill_all_any_none(3, i); //-V106 - - bool result = hpx::ranges::none_of( - policy, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return v != 0; }, proj); - - // verify values - bool expected = std::none_of(std::begin(c), std::end(c), - [proj](std::size_t v) { return proj(v) != 0; }); - - HPX_TEST_EQ(result, expected); - } -} - -template -void test_none_of_async(ExPolicy&& p, IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - hpx::future f = hpx::none_of(p, iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { return v != 0; }); - f.wait(); - - // verify values - bool expected = std::none_of( - std::begin(c), std::end(c), [](std::size_t v) { return v != 0; }); - - HPX_TEST_EQ(expected, f.get()); - } -} - -template -void test_none_of_ranges_async(ExPolicy&& p, IteratorTag, Proj proj = Proj()) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - hpx::future f = hpx::ranges::none_of( - p, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return v != 0; }, proj); - f.wait(); - - // verify values - bool expected = std::none_of(std::begin(c), std::end(c), - [proj](std::size_t v) { return proj(v) != 0; }); - - HPX_TEST_EQ(expected, f.get()); - } -} +#include "none_of_tests.hpp" +//////////////////////////////////////////////////////////////////////////// template void test_none_of() { @@ -229,123 +75,7 @@ void none_of_test() test_none_of(); } -/////////////////////////////////////////////////////////////////////////////// -template -void test_none_of_exception(IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - try - { - hpx::none_of(iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { - return throw std::runtime_error("test"), v != 0; - }); - - HPX_TEST(false); - } - catch (hpx::exception_list const& e) - { - caught_exception = true; - test::test_num_exceptions::call(hpx::execution::seq, e); - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - } -} - -template -void test_none_of_exception(ExPolicy&& policy, IteratorTag) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - try - { - hpx::none_of(policy, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { - return throw std::runtime_error("test"), v != 0; - }); - - HPX_TEST(false); - } - catch (hpx::exception_list const& e) - { - caught_exception = true; - test::test_num_exceptions::call(policy, e); - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - } -} - -template -void test_none_of_exception_async(ExPolicy&& p, IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - bool returned_from_algorithm = false; - try - { - hpx::future f = hpx::none_of(p, iterator(std::begin(c)), - iterator(std::end(c)), [](std::size_t v) { - return throw std::runtime_error("test"), v != 0; - }); - returned_from_algorithm = true; - f.get(); - - HPX_TEST(false); - } - catch (hpx::exception_list const& e) - { - caught_exception = true; - test::test_num_exceptions::call(p, e); - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - HPX_TEST(returned_from_algorithm); - } -} - +//////////////////////////////////////////////////////////////////////////// template void test_none_of_exception() { @@ -369,81 +99,7 @@ void none_of_exception_test() test_none_of_exception(); } -/////////////////////////////////////////////////////////////////////////////// -template -void test_none_of_bad_alloc(ExPolicy&& policy, IteratorTag) -{ - static_assert(hpx::is_execution_policy::value, - "hpx::is_execution_policy::value"); - - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - try - { - hpx::none_of(policy, iterator(std::begin(c)), iterator(std::end(c)), - [](std::size_t v) { return throw std::bad_alloc(), v != 0; }); - - HPX_TEST(false); - } - catch (std::bad_alloc const&) - { - caught_exception = true; - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - } -} - -template -void test_none_of_bad_alloc_async(ExPolicy&& p, IteratorTag) -{ - typedef std::vector::iterator base_iterator; - typedef test::test_iterator iterator; - - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) - { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 - - bool caught_exception = false; - bool returned_from_algorithm = false; - try - { - hpx::future f = hpx::none_of(p, iterator(std::begin(c)), - iterator(std::end(c)), - [](std::size_t v) { return throw std::bad_alloc(), v != 0; }); - returned_from_algorithm = true; - f.get(); - - HPX_TEST(false); - } - catch (std::bad_alloc const&) - { - caught_exception = true; - } - catch (...) - { - HPX_TEST(false); - } - - HPX_TEST(caught_exception); - HPX_TEST(returned_from_algorithm); - } -} - +//////////////////////////////////////////////////////////////////////////// template void test_none_of_bad_alloc() { diff --git a/libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp b/libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp new file mode 100644 index 000000000000..07b45e809385 --- /dev/null +++ b/libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp @@ -0,0 +1,360 @@ +// Copyright (c) 2014-2020 Hartmut Kaiser +// +// 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) + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "test_utils.hpp" + +/////////////////////////////////////////////////////////////////////////////// +template +void test_none_of(IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 1, 3}; + for (std::size_t i : iseq) + { + std::vector c = test::fill_all_any_none(3, i); //-V106 + + bool result = hpx::none_of(iterator(std::begin(c)), + iterator(std::end(c)), [](auto v) { return v != 0; }); + + // verify values + bool expected = std::none_of( + std::begin(c), std::end(c), [](auto v) { return v != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_none_of(ExPolicy&& policy, IteratorTag) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 1, 3}; + for (std::size_t i : iseq) + { + std::vector c = test::fill_all_any_none(3, i); //-V106 + + bool result = hpx::none_of(policy, iterator(std::begin(c)), + iterator(std::end(c)), [](auto v) { return v != 0; }); + + // verify values + bool expected = std::none_of( + std::begin(c), std::end(c), [](auto v) { return v != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_none_of_ranges_seq(IteratorTag, Proj proj = Proj()) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 1, 3}; + for (std::size_t i : iseq) + { + std::vector c = test::fill_all_any_none(3, i); //-V106 + + bool result = hpx::ranges::none_of( + iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return v != 0; }, proj); + + // verify values + bool expected = std::none_of(std::begin(c), std::end(c), + [proj](auto v) { return proj(v) != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_none_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 1, 3}; + for (std::size_t i : iseq) + { + std::vector c = test::fill_all_any_none(3, i); //-V106 + + bool result = hpx::ranges::none_of( + policy, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return v != 0; }, proj); + + // verify values + bool expected = std::none_of(std::begin(c), std::end(c), + [proj](auto v) { return proj(v) != 0; }); + + HPX_TEST_EQ(result, expected); + } +} + +template +void test_none_of_async(ExPolicy&& p, IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + hpx::future f = hpx::none_of(p, iterator(std::begin(c)), + iterator(std::end(c)), [](auto v) { return v != 0; }); + f.wait(); + + // verify values + bool expected = std::none_of( + std::begin(c), std::end(c), [](auto v) { return v != 0; }); + + HPX_TEST_EQ(expected, f.get()); + } +} + +template +void test_none_of_ranges_async(ExPolicy&& p, IteratorTag, Proj proj = Proj()) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + hpx::future f = hpx::ranges::none_of( + p, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return v != 0; }, proj); + f.wait(); + + // verify values + bool expected = std::none_of(std::begin(c), std::end(c), + [proj](auto v) { return proj(v) != 0; }); + + HPX_TEST_EQ(expected, f.get()); + } +} + +/////////////////////////////////////////////////////////////////////////////// +template +void test_none_of_exception(IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + try + { + hpx::none_of( + iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { + return throw std::runtime_error("test"), v != 0; + }); + + HPX_TEST(false); + } + catch (hpx::exception_list const& e) + { + caught_exception = true; + test::test_num_exceptions::call(hpx::execution::seq, e); + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + } +} + +template +void test_none_of_exception(ExPolicy&& policy, IteratorTag) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + try + { + hpx::none_of(policy, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { + return throw std::runtime_error("test"), v != 0; + }); + + HPX_TEST(false); + } + catch (hpx::exception_list const& e) + { + caught_exception = true; + test::test_num_exceptions::call(policy, e); + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + } +} + +template +void test_none_of_exception_async(ExPolicy&& p, IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + bool returned_from_algorithm = false; + try + { + hpx::future f = hpx::none_of( + p, iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { + return throw std::runtime_error("test"), v != 0; + }); + returned_from_algorithm = true; + f.get(); + + HPX_TEST(false); + } + catch (hpx::exception_list const& e) + { + caught_exception = true; + test::test_num_exceptions::call(p, e); + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + HPX_TEST(returned_from_algorithm); + } +} + +/////////////////////////////////////////////////////////////////////////////// +template +void test_none_of_bad_alloc(ExPolicy&& policy, IteratorTag) +{ + static_assert(hpx::is_execution_policy::value, + "hpx::is_execution_policy::value"); + + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + try + { + hpx::none_of(policy, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return throw std::bad_alloc(), v != 0; }); + + HPX_TEST(false); + } + catch (std::bad_alloc const&) + { + caught_exception = true; + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + } +} + +template +void test_none_of_bad_alloc_async(ExPolicy&& p, IteratorTag) +{ + typedef std::vector::iterator base_iterator; + typedef test::test_iterator iterator; + + std::size_t iseq[] = {0, 23, 10007}; + for (std::size_t i : iseq) + { + std::vector c = + test::fill_all_any_none(10007, i); //-V106 + + bool caught_exception = false; + bool returned_from_algorithm = false; + try + { + hpx::future f = + hpx::none_of(p, iterator(std::begin(c)), iterator(std::end(c)), + [](auto v) { return throw std::bad_alloc(), v != 0; }); + returned_from_algorithm = true; + f.get(); + + HPX_TEST(false); + } + catch (std::bad_alloc const&) + { + caught_exception = true; + } + catch (...) + { + HPX_TEST(false); + } + + HPX_TEST(caught_exception); + HPX_TEST(returned_from_algorithm); + } +} From 8cf9c6ad4b8bda7e3c63d963ebf34a23bbe8b4d6 Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Wed, 10 Nov 2021 11:50:04 +0530 Subject: [PATCH 08/12] Adapt datapar all any none unit tests --- .../unit/datapar_algorithms/CMakeLists.txt | 5 +- .../datapar_algorithms/all_of_datapar.cpp | 121 +++++++++++++++++ .../datapar_algorithms/any_of_datapar.cpp | 119 ++++++++++++++++ .../datapar_algorithms/none_of_datapar.cpp | 128 ++++++++++++++++++ 4 files changed, 372 insertions(+), 1 deletion(-) create mode 100644 libs/core/algorithms/tests/unit/datapar_algorithms/all_of_datapar.cpp create mode 100644 libs/core/algorithms/tests/unit/datapar_algorithms/any_of_datapar.cpp create mode 100644 libs/core/algorithms/tests/unit/datapar_algorithms/none_of_datapar.cpp diff --git a/libs/core/algorithms/tests/unit/datapar_algorithms/CMakeLists.txt b/libs/core/algorithms/tests/unit/datapar_algorithms/CMakeLists.txt index 9e5f606ca94c..c3a4217fc459 100644 --- a/libs/core/algorithms/tests/unit/datapar_algorithms/CMakeLists.txt +++ b/libs/core/algorithms/tests/unit/datapar_algorithms/CMakeLists.txt @@ -9,9 +9,11 @@ set(tests) if(HPX_WITH_DATAPAR_VC OR HPX_WITH_CXX20_EXPERIMENTAL_SIMD) set(tests ${tests} + adjacentdifference_datapar + all_of_datapar + any_of_datapar copy_datapar copyn_datapar - adjacentdifference_datapar count_datapar countif_datapar fill_datapar @@ -21,6 +23,7 @@ if(HPX_WITH_DATAPAR_VC OR HPX_WITH_CXX20_EXPERIMENTAL_SIMD) foreachn_datapar generate_datapar generaten_datapar + none_of_datapar transform_binary_datapar transform_binary2_datapar transform_reduce_binary_datapar diff --git a/libs/core/algorithms/tests/unit/datapar_algorithms/all_of_datapar.cpp b/libs/core/algorithms/tests/unit/datapar_algorithms/all_of_datapar.cpp new file mode 100644 index 000000000000..f66f44fcdb95 --- /dev/null +++ b/libs/core/algorithms/tests/unit/datapar_algorithms/all_of_datapar.cpp @@ -0,0 +1,121 @@ +// Copyright (c) 2021 Srinivas Yadav +// Copyright (c) 2014-2020 Hartmut Kaiser +// +// 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) + +#include +#include + +#include +#include +#include + +#include "../algorithms/all_of_tests.hpp" + +//////////////////////////////////////////////////////////////////////////// +template +void test_all_of() +{ + struct proj + { + //This projection should cause tests to fail if it is not applied + //because it causes predicate to evaluate the opposite + constexpr std::size_t operator()(std::size_t x) const + { + return !static_cast(x); + } + }; + using namespace hpx::execution; + + test_all_of(simd, IteratorTag()); + test_all_of(par_simd, IteratorTag()); + + test_all_of_async(simd(task), IteratorTag()); + test_all_of_async(par_simd(task), IteratorTag()); +} + +void all_of_test() +{ + test_all_of(); + test_all_of(); +} + +//////////////////////////////////////////////////////////////////////////// +template +void test_all_of_exception() +{ + using namespace hpx::execution; + + test_all_of_exception(simd, IteratorTag()); + test_all_of_exception(par_simd, IteratorTag()); + + test_all_of_exception_async(simd(task), IteratorTag()); + test_all_of_exception_async(par_simd(task), IteratorTag()); +} + +void all_of_exception_test() +{ + test_all_of_exception(); + test_all_of_exception(); +} + +//////////////////////////////////////////////////////////////////////////// +template +void test_all_of_bad_alloc() +{ + using namespace hpx::execution; + + test_all_of_bad_alloc(simd, IteratorTag()); + test_all_of_bad_alloc(par_simd, IteratorTag()); + + test_all_of_bad_alloc_async(simd(task), IteratorTag()); + test_all_of_bad_alloc_async(par_simd(task), IteratorTag()); +} + +void all_of_bad_alloc_test() +{ + test_all_of_bad_alloc(); + test_all_of_bad_alloc(); +} + +/////////////////////////////////////////////////////////////////////////////// +int hpx_main(hpx::program_options::variables_map& vm) +{ + unsigned int seed = (unsigned int) std::time(nullptr); + if (vm.count("seed")) + seed = vm["seed"].as(); + + std::cout << "using seed: " << seed << std::endl; + std::srand(seed); + + all_of_test(); + all_of_exception_test(); + all_of_bad_alloc_test(); + return hpx::local::finalize(); +} + +int main(int argc, char* argv[]) +{ + // add command line option which controls the random number generator seed + using namespace hpx::program_options; + options_description desc_commandline( + "Usage: " HPX_APPLICATION_STRING " [options]"); + + desc_commandline.add_options()("seed,s", value(), + "the random number generator seed to use for this run"); + + // By default this test should run on all available cores + std::vector const cfg = {"hpx.os_threads=all"}; + + // Initialize and run HPX + hpx::local::init_params init_args; + init_args.desc_cmdline = desc_commandline; + init_args.cfg = cfg; + + HPX_TEST_EQ_MSG(hpx::local::init(hpx_main, argc, argv, init_args), 0, + "HPX main exited with non-zero status"); + + return hpx::util::report_errors(); +} diff --git a/libs/core/algorithms/tests/unit/datapar_algorithms/any_of_datapar.cpp b/libs/core/algorithms/tests/unit/datapar_algorithms/any_of_datapar.cpp new file mode 100644 index 000000000000..aec7ac75b507 --- /dev/null +++ b/libs/core/algorithms/tests/unit/datapar_algorithms/any_of_datapar.cpp @@ -0,0 +1,119 @@ +// Copyright (c) 2021 Srinivas Yadav +// Copyright (c) 2014-2020 Hartmut Kaiser +// +// 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) + +#include +#include + +#include +#include +#include + +#include "../algorithms/any_of_tests.hpp" + +//////////////////////////////////////////////////////////////////////////// +template +void test_any_of() +{ + struct proj + { + //This projection should cause tests to fail if it is not applied + //because it causes predicate to evaluate the opposite + constexpr std::size_t operator()(std::size_t x) const + { + return !static_cast(x); + } + }; + using namespace hpx::execution; + + test_any_of(simd, IteratorTag()); + test_any_of(par_simd, IteratorTag()); + + test_any_of_async(simd(task), IteratorTag()); + test_any_of_async(par_simd(task), IteratorTag()); +} + +//////////////////////////////////////////////////////////////////////////// +void any_of_test() +{ + test_any_of(); + test_any_of(); +} + +template +void test_any_of_exception() +{ + using namespace hpx::execution; + + test_any_of_exception(IteratorTag()); + + // If the execution policy object is of type vector_execution_policy, + // std::terminate shall be called. therefore we do not test exceptions + // with a vector execution policy + test_any_of_exception(simd, IteratorTag()); + test_any_of_exception(par_simd, IteratorTag()); + + test_any_of_exception_async(simd(task), IteratorTag()); + test_any_of_exception_async(par_simd(task), IteratorTag()); +} + +//////////////////////////////////////////////////////////////////////////// +void any_of_exception_test() +{ + test_any_of_exception(); + test_any_of_exception(); +} + +template +void test_any_of_bad_alloc() +{ + using namespace hpx::execution; + + // If the execution policy object is of type vector_execution_policy, + // std::terminate shall be called. therefore we do not test exceptions + // with a vector execution policy + test_any_of_bad_alloc(simd, IteratorTag()); + test_any_of_bad_alloc(par_simd, IteratorTag()); + + test_any_of_bad_alloc_async(simd(task), IteratorTag()); + test_any_of_bad_alloc_async(par_simd(task), IteratorTag()); +} + +void any_of_bad_alloc_test() +{ + test_any_of_bad_alloc(); + test_any_of_bad_alloc(); +} + +/////////////////////////////////////////////////////////////////////////////// +int hpx_main() +{ + any_of_test(); + any_of_exception_test(); + any_of_bad_alloc_test(); + return hpx::local::finalize(); +} + +int main(int argc, char* argv[]) +{ + // add command line option which controls the random number generator seed + using namespace hpx::program_options; + options_description desc_commandline( + "Usage: " HPX_APPLICATION_STRING " [options]"); + + // By default this test should run on all available cores + std::vector const cfg = {"hpx.os_threads=all"}; + + // Initialize and run HPX + hpx::local::init_params init_args; + init_args.desc_cmdline = desc_commandline; + init_args.cfg = cfg; + + HPX_TEST_EQ_MSG(hpx::local::init(hpx_main, argc, argv, init_args), 0, + "HPX main exited with non-zero status"); + + return hpx::util::report_errors(); +} diff --git a/libs/core/algorithms/tests/unit/datapar_algorithms/none_of_datapar.cpp b/libs/core/algorithms/tests/unit/datapar_algorithms/none_of_datapar.cpp new file mode 100644 index 000000000000..b647752e7040 --- /dev/null +++ b/libs/core/algorithms/tests/unit/datapar_algorithms/none_of_datapar.cpp @@ -0,0 +1,128 @@ +// Copyright (c) 2021 Srinivas Yadav +// Copyright (c) 2014-2020 Hartmut Kaiser +// +// 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) + +#include +#include + +#include +#include +#include + +#include "../algorithms/none_of_tests.hpp" + +//////////////////////////////////////////////////////////////////////////// +template +void test_none_of() +{ + struct proj + { + //This projection should cause tests to fail if it is not applied + //because it causes predicate to evaluate the opposite + constexpr std::size_t operator()(std::size_t x) const + { + return !static_cast(x); + } + }; + using namespace hpx::execution; + + test_none_of(simd, IteratorTag()); + test_none_of(par_simd, IteratorTag()); + + test_none_of_async(simd(task), IteratorTag()); + test_none_of_async(par_simd(task), IteratorTag()); +} + +void none_of_test() +{ + test_none_of(); + test_none_of(); +} + +//////////////////////////////////////////////////////////////////////////// +template +void test_none_of_exception() +{ + using namespace hpx::execution; + + test_none_of_exception(IteratorTag()); + + // If the execution policy object is of type vector_execution_policy, + // std::terminate shall be called. therefore we do not test exceptions + // with a vector execution policy + test_none_of_exception(simd, IteratorTag()); + test_none_of_exception(par_simd, IteratorTag()); + + test_none_of_exception_async(simd(task), IteratorTag()); + test_none_of_exception_async(par_simd(task), IteratorTag()); +} + +void none_of_exception_test() +{ + test_none_of_exception(); + test_none_of_exception(); +} + +//////////////////////////////////////////////////////////////////////////// +template +void test_none_of_bad_alloc() +{ + using namespace hpx::execution; + + // If the execution policy object is of type vector_execution_policy, + // std::terminate shall be called. therefore we do not test exceptions + // with a vector execution policy + test_none_of_bad_alloc(simd, IteratorTag()); + test_none_of_bad_alloc(par_simd, IteratorTag()); + + test_none_of_bad_alloc_async(simd(task), IteratorTag()); + test_none_of_bad_alloc_async(par_simd(task), IteratorTag()); +} + +void none_of_bad_alloc_test() +{ + test_none_of_bad_alloc(); + test_none_of_bad_alloc(); +} + +/////////////////////////////////////////////////////////////////////////////// +int hpx_main(hpx::program_options::variables_map& vm) +{ + unsigned int seed = (unsigned int) std::time(nullptr); + if (vm.count("seed")) + seed = vm["seed"].as(); + + std::cout << "using seed: " << seed << std::endl; + std::srand(seed); + + none_of_test(); + none_of_exception_test(); + none_of_bad_alloc_test(); + return hpx::local::finalize(); +} + +int main(int argc, char* argv[]) +{ + // add command line option which controls the random number generator seed + using namespace hpx::program_options; + options_description desc_commandline( + "Usage: " HPX_APPLICATION_STRING " [options]"); + + desc_commandline.add_options()("seed,s", value(), + "the random number generator seed to use for this run"); + // By default this test should run on all available cores + std::vector const cfg = {"hpx.os_threads=all"}; + + // Initialize and run HPX + hpx::local::init_params init_args; + init_args.desc_cmdline = desc_commandline; + init_args.cfg = cfg; + + HPX_TEST_EQ_MSG(hpx::local::init(hpx_main, argc, argv, init_args), 0, + "HPX main exited with non-zero status"); + + return hpx::util::report_errors(); +} From 4c7b98bb77f14628e24ed297093cf1890a41923f Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Wed, 10 Nov 2021 18:27:05 +0530 Subject: [PATCH 09/12] Replace std::size_t with int for Vc datapar tests --- .../hpx/parallel/algorithms/detail/find.hpp | 5 +- .../hpx/parallel/algorithms/detail/search.hpp | 6 +- .../tests/unit/algorithms/all_of_tests.hpp | 99 +++++++++---------- .../tests/unit/algorithms/any_of_tests.hpp | 99 +++++++++---------- .../tests/unit/algorithms/none_of_tests.hpp | 95 +++++++++--------- .../tests/unit/algorithms/test_utils.hpp | 23 +++++ 6 files changed, 162 insertions(+), 165 deletions(-) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp index a9bc972e1a87..386e37d76d74 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp @@ -10,8 +10,8 @@ #include #include -#include #include +#include #include #include #include @@ -172,7 +172,8 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { // provide implementation of std::find_if_not supporting iterators/sentinels template struct sequential_find_if_not_t - : hpx::functional::detail::tag_fallback> + : hpx::functional::detail::tag_fallback< + sequential_find_if_not_t> { private: template void { FwdIter curr = it; - hpx::parallel::util::loop_idx_n>(base_idx, it, part_size, tok, + hpx::parallel::util::loop_idx_n>( + base_idx, it, part_size, tok, [diff, count, s_first, &tok, &curr, op = std::forward(op), proj1 = std::forward(proj1), @@ -208,7 +209,8 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { std::size_t base_idx) mutable -> void { FwdIter curr = it; - util::loop_idx_n>(base_idx, it, part_size, tok, + util::loop_idx_n>(base_idx, it, + part_size, tok, [count, diff, s_first, &tok, &curr, op = std::forward(op), proj1 = std::forward(proj1), diff --git a/libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp b/libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp index 6de7f8fa919b..fcae9b31ae70 100644 --- a/libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp +++ b/libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp @@ -23,14 +23,13 @@ template void test_all_of(IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool result = hpx::all_of(iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { return v != 0; }); @@ -49,14 +48,13 @@ void test_all_of(ExPolicy&& policy, IteratorTag) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool result = hpx::all_of(policy, iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { return v != 0; }); @@ -73,14 +71,13 @@ template void test_all_of_ranges_seq(IteratorTag, Proj proj = Proj()) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool result = hpx::ranges::all_of( iterator(std::begin(c)), iterator(std::end(c)), @@ -101,14 +98,13 @@ void test_all_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool result = hpx::ranges::all_of( policy, iterator(std::begin(c)), iterator(std::end(c)), @@ -125,14 +121,13 @@ void test_all_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) template void test_all_of_async(ExPolicy&& p, IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 hpx::future f = hpx::all_of(p, iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { return v != 0; }); @@ -150,14 +145,13 @@ template void test_all_of_ranges_async(ExPolicy&& p, IteratorTag, Proj proj = Proj()) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 hpx::future f = hpx::ranges::all_of( p, iterator(std::begin(c)), iterator(std::end(c)), @@ -179,14 +173,13 @@ void test_all_of_exception(ExPolicy&& policy, IteratorTag) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; try @@ -215,14 +208,13 @@ void test_all_of_exception(ExPolicy&& policy, IteratorTag) template void test_all_of_exception(IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; try @@ -252,14 +244,13 @@ void test_all_of_exception(IteratorTag) template void test_all_of_exception_async(ExPolicy&& p, IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; bool returned_from_algorithm = false; @@ -296,14 +287,13 @@ void test_all_of_bad_alloc(ExPolicy&& policy, IteratorTag) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; try @@ -329,14 +319,13 @@ void test_all_of_bad_alloc(ExPolicy&& policy, IteratorTag) template void test_all_of_bad_alloc_async(ExPolicy&& p, IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; bool returned_from_algorithm = false; diff --git a/libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp b/libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp index 72a023125220..24fcab6925f3 100644 --- a/libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp +++ b/libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp @@ -24,14 +24,13 @@ template void test_any_of(IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool result = hpx::any_of(iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { return v != 0; }); @@ -50,14 +49,13 @@ void test_any_of(ExPolicy&& policy, IteratorTag) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool result = hpx::any_of(policy, iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { return v != 0; }); @@ -74,14 +72,13 @@ template void test_any_of_ranges_seq(IteratorTag, Proj proj = Proj()) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool result = hpx::ranges::any_of( iterator(std::begin(c)), iterator(std::end(c)), @@ -102,14 +99,13 @@ void test_any_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool result = hpx::ranges::any_of( policy, iterator(std::begin(c)), iterator(std::end(c)), @@ -126,14 +122,13 @@ void test_any_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) template void test_any_of_async(ExPolicy&& p, IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 hpx::future f = hpx::any_of(p, iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { return v != 0; }); @@ -151,14 +146,13 @@ template void test_any_of_ranges_async(ExPolicy&& p, IteratorTag, Proj proj = Proj()) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 hpx::future f = hpx::ranges::any_of( p, iterator(std::begin(c)), iterator(std::end(c)), @@ -177,14 +171,13 @@ void test_any_of_ranges_async(ExPolicy&& p, IteratorTag, Proj proj = Proj()) template void test_any_of_exception(IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; try @@ -217,14 +210,13 @@ void test_any_of_exception(ExPolicy&& policy, IteratorTag) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; try @@ -253,14 +245,13 @@ void test_any_of_exception(ExPolicy&& policy, IteratorTag) template void test_any_of_exception_async(ExPolicy&& p, IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; bool returned_from_algorithm = false; @@ -297,14 +288,13 @@ void test_any_of_bad_alloc(ExPolicy&& policy, IteratorTag) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; try @@ -330,14 +320,13 @@ void test_any_of_bad_alloc(ExPolicy&& policy, IteratorTag) template void test_any_of_bad_alloc_async(ExPolicy&& p, IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; bool returned_from_algorithm = false; diff --git a/libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp b/libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp index 07b45e809385..dd88ea3dcf1f 100644 --- a/libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp +++ b/libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp @@ -22,13 +22,13 @@ template void test_none_of(IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 1, 3}; - for (std::size_t i : iseq) + int iseq[] = {0, 1, 3}; + for (int i : iseq) { - std::vector c = test::fill_all_any_none(3, i); //-V106 + std::vector c = test::fill_all_any_none(3, i); //-V106 bool result = hpx::none_of(iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { return v != 0; }); @@ -47,13 +47,13 @@ void test_none_of(ExPolicy&& policy, IteratorTag) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 1, 3}; - for (std::size_t i : iseq) + int iseq[] = {0, 1, 3}; + for (int i : iseq) { - std::vector c = test::fill_all_any_none(3, i); //-V106 + std::vector c = test::fill_all_any_none(3, i); //-V106 bool result = hpx::none_of(policy, iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { return v != 0; }); @@ -70,13 +70,13 @@ template void test_none_of_ranges_seq(IteratorTag, Proj proj = Proj()) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 1, 3}; - for (std::size_t i : iseq) + int iseq[] = {0, 1, 3}; + for (int i : iseq) { - std::vector c = test::fill_all_any_none(3, i); //-V106 + std::vector c = test::fill_all_any_none(3, i); //-V106 bool result = hpx::ranges::none_of( iterator(std::begin(c)), iterator(std::end(c)), @@ -97,13 +97,13 @@ void test_none_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 1, 3}; - for (std::size_t i : iseq) + int iseq[] = {0, 1, 3}; + for (int i : iseq) { - std::vector c = test::fill_all_any_none(3, i); //-V106 + std::vector c = test::fill_all_any_none(3, i); //-V106 bool result = hpx::ranges::none_of( policy, iterator(std::begin(c)), iterator(std::end(c)), @@ -120,14 +120,13 @@ void test_none_of_ranges(ExPolicy&& policy, IteratorTag, Proj proj = Proj()) template void test_none_of_async(ExPolicy&& p, IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 hpx::future f = hpx::none_of(p, iterator(std::begin(c)), iterator(std::end(c)), [](auto v) { return v != 0; }); @@ -145,14 +144,13 @@ template void test_none_of_ranges_async(ExPolicy&& p, IteratorTag, Proj proj = Proj()) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 hpx::future f = hpx::ranges::none_of( p, iterator(std::begin(c)), iterator(std::end(c)), @@ -171,14 +169,13 @@ void test_none_of_ranges_async(ExPolicy&& p, IteratorTag, Proj proj = Proj()) template void test_none_of_exception(IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; try @@ -211,14 +208,13 @@ void test_none_of_exception(ExPolicy&& policy, IteratorTag) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; try @@ -247,14 +243,13 @@ void test_none_of_exception(ExPolicy&& policy, IteratorTag) template void test_none_of_exception_async(ExPolicy&& p, IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; bool returned_from_algorithm = false; @@ -291,14 +286,13 @@ void test_none_of_bad_alloc(ExPolicy&& policy, IteratorTag) static_assert(hpx::is_execution_policy::value, "hpx::is_execution_policy::value"); - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; try @@ -324,14 +318,13 @@ void test_none_of_bad_alloc(ExPolicy&& policy, IteratorTag) template void test_none_of_bad_alloc_async(ExPolicy&& p, IteratorTag) { - typedef std::vector::iterator base_iterator; + typedef std::vector::iterator base_iterator; typedef test::test_iterator iterator; - std::size_t iseq[] = {0, 23, 10007}; - for (std::size_t i : iseq) + int iseq[] = {0, 23, 10007}; + for (int i : iseq) { - std::vector c = - test::fill_all_any_none(10007, i); //-V106 + std::vector c = test::fill_all_any_none(10007, i); //-V106 bool caught_exception = false; bool returned_from_algorithm = false; diff --git a/libs/core/algorithms/tests/unit/algorithms/test_utils.hpp b/libs/core/algorithms/tests/unit/algorithms/test_utils.hpp index 27b760a2b026..7a83c4d5c072 100644 --- a/libs/core/algorithms/tests/unit/algorithms/test_utils.hpp +++ b/libs/core/algorithms/tests/unit/algorithms/test_utils.hpp @@ -259,6 +259,29 @@ namespace test { return c; } + /////////////////////////////////////////////////////////////////////////// + template + inline std::vector fill_all_any_none(T size, T num_filled) + { + if (num_filled == 0) + return std::vector(size, 0); + + if (num_filled == size) + return std::vector(size, 1); + + std::vector c(size, 0); + for (T i = 0; i < num_filled; /**/) + { + T pos = std::rand() % c.size(); //-V104 + if (c[pos]) + continue; + + c[pos] = 1; + ++i; + } + return c; + } + /////////////////////////////////////////////////////////////////////////// template bool equal(InputIter1 first1, InputIter1 last1, InputIter2 first2, From 4c49fff679b0cab2289a04ebad41bb131b3952b7 Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Wed, 10 Nov 2021 20:38:02 +0530 Subject: [PATCH 10/12] Fixes from CIRCLE CI Inspect --- .../algorithms/include/hpx/parallel/algorithms/detail/find.hpp | 2 ++ libs/core/algorithms/include/hpx/parallel/datapar/find.hpp | 1 - libs/core/algorithms/tests/unit/algorithms/all_of.cpp | 1 + libs/core/algorithms/tests/unit/algorithms/any_of.cpp | 1 + libs/core/algorithms/tests/unit/algorithms/none_of.cpp | 1 + libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp | 2 ++ .../algorithms/tests/unit/datapar_algorithms/all_of_datapar.cpp | 1 + .../algorithms/tests/unit/datapar_algorithms/any_of_datapar.cpp | 1 + .../tests/unit/datapar_algorithms/none_of_datapar.cpp | 1 + 9 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp index 386e37d76d74..c3b98aa4ab17 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/find.hpp @@ -17,8 +17,10 @@ #include #include +#include #include #include +#include namespace hpx { namespace parallel { inline namespace v1 { namespace detail { diff --git a/libs/core/algorithms/include/hpx/parallel/datapar/find.hpp b/libs/core/algorithms/include/hpx/parallel/datapar/find.hpp index 310493bcdb0f..f01441f886c0 100644 --- a/libs/core/algorithms/include/hpx/parallel/datapar/find.hpp +++ b/libs/core/algorithms/include/hpx/parallel/datapar/find.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include diff --git a/libs/core/algorithms/tests/unit/algorithms/all_of.cpp b/libs/core/algorithms/tests/unit/algorithms/all_of.cpp index b8fa987d511c..20e5ae39f2c5 100644 --- a/libs/core/algorithms/tests/unit/algorithms/all_of.cpp +++ b/libs/core/algorithms/tests/unit/algorithms/all_of.cpp @@ -6,6 +6,7 @@ #include +#include #include #include #include diff --git a/libs/core/algorithms/tests/unit/algorithms/any_of.cpp b/libs/core/algorithms/tests/unit/algorithms/any_of.cpp index e8e1f0305387..d07006a48f0b 100644 --- a/libs/core/algorithms/tests/unit/algorithms/any_of.cpp +++ b/libs/core/algorithms/tests/unit/algorithms/any_of.cpp @@ -6,6 +6,7 @@ #include +#include #include #include #include diff --git a/libs/core/algorithms/tests/unit/algorithms/none_of.cpp b/libs/core/algorithms/tests/unit/algorithms/none_of.cpp index bedc747f6a92..813ebfa0580d 100644 --- a/libs/core/algorithms/tests/unit/algorithms/none_of.cpp +++ b/libs/core/algorithms/tests/unit/algorithms/none_of.cpp @@ -6,6 +6,7 @@ #include +#include #include #include #include diff --git a/libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp b/libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp index dd88ea3dcf1f..70cdd69ed314 100644 --- a/libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp +++ b/libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp @@ -4,6 +4,8 @@ // 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 #include #include diff --git a/libs/core/algorithms/tests/unit/datapar_algorithms/all_of_datapar.cpp b/libs/core/algorithms/tests/unit/datapar_algorithms/all_of_datapar.cpp index f66f44fcdb95..273946694e87 100644 --- a/libs/core/algorithms/tests/unit/datapar_algorithms/all_of_datapar.cpp +++ b/libs/core/algorithms/tests/unit/datapar_algorithms/all_of_datapar.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/libs/core/algorithms/tests/unit/datapar_algorithms/any_of_datapar.cpp b/libs/core/algorithms/tests/unit/datapar_algorithms/any_of_datapar.cpp index aec7ac75b507..7b61f2a6b3d2 100644 --- a/libs/core/algorithms/tests/unit/datapar_algorithms/any_of_datapar.cpp +++ b/libs/core/algorithms/tests/unit/datapar_algorithms/any_of_datapar.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/libs/core/algorithms/tests/unit/datapar_algorithms/none_of_datapar.cpp b/libs/core/algorithms/tests/unit/datapar_algorithms/none_of_datapar.cpp index b647752e7040..12f2d157190b 100644 --- a/libs/core/algorithms/tests/unit/datapar_algorithms/none_of_datapar.cpp +++ b/libs/core/algorithms/tests/unit/datapar_algorithms/none_of_datapar.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include From 0a33a9f84e012f8def9d07cfa73124d397d35138 Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Thu, 11 Nov 2021 13:44:27 +0530 Subject: [PATCH 11/12] Remove constexpr for datapar CPOs Fixes CIRCLE CI constexpr error --- libs/core/algorithms/include/hpx/parallel/datapar/find.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/core/algorithms/include/hpx/parallel/datapar/find.hpp b/libs/core/algorithms/include/hpx/parallel/datapar/find.hpp index f01441f886c0..4357a4c8711a 100644 --- a/libs/core/algorithms/include/hpx/parallel/datapar/find.hpp +++ b/libs/core/algorithms/include/hpx/parallel/datapar/find.hpp @@ -30,7 +30,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { { template - static inline constexpr Iterator call( + static inline Iterator call( Iterator first, Sentinel last, T const& val, Proj proj) { int offset = 0; @@ -94,7 +94,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { { template - static inline constexpr Iterator call( + static inline Iterator call( Iterator first, Sentinel last, Pred pred, Proj proj) { int offset = 0; @@ -184,7 +184,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail { { template - static inline constexpr Iterator call( + static inline Iterator call( Iterator first, Sentinel last, Pred pred, Proj proj) { int offset = 0; From 90195f60d2ae6aa3b5a9e3d2b0d9eb8b4f8f2663 Mon Sep 17 00:00:00 2001 From: srinivasyadav18 Date: Thu, 11 Nov 2021 13:44:46 +0530 Subject: [PATCH 12/12] Adapt new vector_pack traits for datapar Vc --- libs/core/execution/CMakeLists.txt | 2 + .../detail/vc/vector_pack_all_any_none.hpp | 43 +++++++++++++++++++ .../traits/detail/vc/vector_pack_find.hpp | 31 +++++++++++++ .../traits/vector_pack_all_any_none.hpp | 1 + .../hpx/execution/traits/vector_pack_find.hpp | 1 + 5 files changed, 78 insertions(+) create mode 100644 libs/core/execution/include/hpx/execution/traits/detail/vc/vector_pack_all_any_none.hpp create mode 100644 libs/core/execution/include/hpx/execution/traits/detail/vc/vector_pack_find.hpp diff --git a/libs/core/execution/CMakeLists.txt b/libs/core/execution/CMakeLists.txt index 08f8d9ba8007..6ad89e25bf7f 100644 --- a/libs/core/execution/CMakeLists.txt +++ b/libs/core/execution/CMakeLists.txt @@ -52,7 +52,9 @@ set(execution_headers hpx/execution/traits/detail/simd/vector_pack_load_store.hpp hpx/execution/traits/detail/simd/vector_pack_type.hpp hpx/execution/traits/detail/vc/vector_pack_alignment_size.hpp + hpx/execution/traits/detail/vc/vector_pack_all_any_none.hpp hpx/execution/traits/detail/vc/vector_pack_count_bits.hpp + hpx/execution/traits/detail/vc/vector_pack_find.hpp hpx/execution/traits/detail/vc/vector_pack_load_store.hpp hpx/execution/traits/detail/vc/vector_pack_type.hpp hpx/execution/traits/executor_traits.hpp diff --git a/libs/core/execution/include/hpx/execution/traits/detail/vc/vector_pack_all_any_none.hpp b/libs/core/execution/include/hpx/execution/traits/detail/vc/vector_pack_all_any_none.hpp new file mode 100644 index 000000000000..dba178e89663 --- /dev/null +++ b/libs/core/execution/include/hpx/execution/traits/detail/vc/vector_pack_all_any_none.hpp @@ -0,0 +1,43 @@ +// Copyright (c) 2021 Srinivas Yadav +// +// 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 + +#if defined(HPX_HAVE_DATAPAR_VC) +#include + +#include +#include + +namespace hpx { namespace parallel { namespace traits { + /////////////////////////////////////////////////////////////////////// + template + HPX_HOST_DEVICE HPX_FORCEINLINE std::size_t all_of( + Vc::Mask const& msk) + { + return Vc::all_of(msk); + } + + /////////////////////////////////////////////////////////////////////// + template + HPX_HOST_DEVICE HPX_FORCEINLINE std::size_t any_of( + Vc::Mask const& msk) + { + return Vc::any_of(msk); + } + + /////////////////////////////////////////////////////////////////////// + template + HPX_HOST_DEVICE HPX_FORCEINLINE std::size_t none_of( + Vc::Mask const& msk) + { + return Vc::none_of(msk); + } +}}} // namespace hpx::parallel::traits + +#endif diff --git a/libs/core/execution/include/hpx/execution/traits/detail/vc/vector_pack_find.hpp b/libs/core/execution/include/hpx/execution/traits/detail/vc/vector_pack_find.hpp new file mode 100644 index 000000000000..892dcd652424 --- /dev/null +++ b/libs/core/execution/include/hpx/execution/traits/detail/vc/vector_pack_find.hpp @@ -0,0 +1,31 @@ +// Copyright (c) 2021 Srinivas Yadav +// +// 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 + +#if defined(HPX_HAVE_DATAPAR_VC) +#include + +#include +#include + +namespace hpx { namespace parallel { namespace traits { + /////////////////////////////////////////////////////////////////////// + template + HPX_HOST_DEVICE HPX_FORCEINLINE int find_first_of( + Vc::Mask const& msk) + { + if (Vc::any_of(msk)) + { + return msk.firstOne(); + } + return -1; + } +}}} // namespace hpx::parallel::traits + +#endif diff --git a/libs/core/execution/include/hpx/execution/traits/vector_pack_all_any_none.hpp b/libs/core/execution/include/hpx/execution/traits/vector_pack_all_any_none.hpp index 21a264167c3a..d31e7ab6cc89 100644 --- a/libs/core/execution/include/hpx/execution/traits/vector_pack_all_any_none.hpp +++ b/libs/core/execution/include/hpx/execution/traits/vector_pack_all_any_none.hpp @@ -12,6 +12,7 @@ #if !defined(__CUDACC__) #include +#include #endif #endif diff --git a/libs/core/execution/include/hpx/execution/traits/vector_pack_find.hpp b/libs/core/execution/include/hpx/execution/traits/vector_pack_find.hpp index 00f5fe9c071a..26ac5504e067 100644 --- a/libs/core/execution/include/hpx/execution/traits/vector_pack_find.hpp +++ b/libs/core/execution/include/hpx/execution/traits/vector_pack_find.hpp @@ -12,6 +12,7 @@ #if !defined(__CUDACC__) #include +#include #endif #endif