Skip to content

Commit

Permalink
par unseq implemented
Browse files Browse the repository at this point in the history
Signed-off-by: Hari Hara Naveen S <harihara.sn@gmail.com>
  • Loading branch information
Johan511 committed Aug 11, 2023
1 parent bfb7da1 commit be275f0
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions libs/core/algorithms/include/hpx/parallel/util/loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,32 @@ namespace hpx::parallel::util {

return call(it, num, HPX_FORWARD(F, f), tag);
}

template <typename Iter, typename F>
HPX_HOST_DEVICE HPX_FORCEINLINE static constexpr Iter unseq_call(
Iter it, std::size_t num, F&& f)
{
// clang-format off
HPX_VECTORIZE
for (std::size_t i = 0; i < num; i++) // -V112
{
HPX_INVOKE(f, it++);
}
// clang-format on
return it;
}

template <typename Iter, typename CancelToken, typename F,
typename Tag>
HPX_HOST_DEVICE HPX_FORCEINLINE static Iter unseq_call(
Iter it, std::size_t num, CancelToken& tok, F&& f)
{
// check at the start of a partition only
if (tok.was_cancelled())
return it;

return unseq_call(it, num, HPX_FORWARD(F, f));
}
};
} // namespace detail

Expand Down Expand Up @@ -426,6 +452,25 @@ namespace hpx::parallel::util {
}
};

template <typename Iter, typename F,
HPX_CONCEPT_REQUIRES_(hpx::traits::is_random_access_iterator_v<Iter>)>
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Iter tag_invoke(
hpx::parallel::util::loop_n_t<hpx::execution::unsequenced_policy>,
Iter it, std::size_t count, F&& f)
{
return detail::loop_n_helper::unseq_call(it, count, HPX_FORWARD(F, f));
}

template <typename Iter, typename CancelToken, typename F,
HPX_CONCEPT_REQUIRES_(hpx::traits::is_random_access_iterator_v<Iter>)>
HPX_HOST_DEVICE HPX_FORCEINLINE Iter tag_invoke(
hpx::parallel::util::loop_n_t<hpx::execution::unsequenced_policy>,
Iter it, std::size_t count, CancelToken& tok, F&& f)
{
return detail::loop_n_helper::unseq_call(
it, count, tok, HPX_FORWARD(F, f));
}

#if !defined(HPX_COMPUTE_DEVICE_CODE)
template <typename ExPolicy>
inline constexpr loop_n_t<ExPolicy> loop_n = loop_n_t<ExPolicy>{};
Expand Down Expand Up @@ -963,16 +1008,17 @@ namespace hpx::parallel::util {
template <typename Iter, typename CancelToken, typename F,
HPX_CONCEPT_REQUIRES_(hpx::traits::is_random_access_iterator_v<Iter>)>
HPX_HOST_DEVICE HPX_FORCEINLINE static constexpr Iter tag_invoke(
hpx::parallel::util::loop_idx_n_t<hpx::execution::unsequenced_task_policy>,
hpx::parallel::util::loop_idx_n_t<
hpx::execution::unsequenced_task_policy>,
std::size_t base_idx, Iter it, std::size_t count, CancelToken& tok,
F&& f)
{
if (tok.was_cancelled(base_idx))
return it;

return detail::loop_idx_n<std::random_access_iterator_tag,
hpx::execution::unsequenced_task_policy>::unseq_call(base_idx, it, count,
HPX_FORWARD(F, f));
hpx::execution::unsequenced_task_policy>::unseq_call(base_idx, it,
count, HPX_FORWARD(F, f));
}

#if !defined(HPX_COMPUTE_DEVICE_CODE)
Expand Down

0 comments on commit be275f0

Please sign in to comment.