Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialised algorithms, move using std::memcpy #6271

Merged
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
81dff9b
move as buffers when data type is trivially copyable
Jun 3, 2023
8bd9740
copy as buffers for triviably copyable types
Jun 4, 2023
7806973
added cancellation token
Jun 4, 2023
73befc3
added unseq support
Jun 4, 2023
20d9a17
fixed unused error
Jun 4, 2023
79cbd6b
unedd parameter
Jun 4, 2023
48552c2
enable if else error to be fixed
Jun 5, 2023
cc8120f
cf
Jun 5, 2023
a90301f
unused param
Jun 5, 2023
4008ad9
customisation point for loop_with_cleanup
Jun 7, 2023
bfb5962
fixed ambiguos funtion error
Jun 7, 2023
85159db
fixed template and typename mismatch
Jun 7, 2023
9dc7a5f
template arguments were not provided in certain cases
Jun 7, 2023
f108785
added concept to resolve ambiguity
Jun 7, 2023
e76f7ef
fixed ambiguity using concepts
Jun 7, 2023
502adfa
fixed inspect and include errors
Jun 7, 2023
f265e7f
used hpx::parallel::util::transfer for uninit_copy
Jun 9, 2023
ad499de
try in constexpr function fixed
Jun 9, 2023
7030661
fixed missing includes
Jun 9, 2023
5a4facf
variable name
Jun 9, 2023
17a6a40
changed concept
Jun 9, 2023
463e1f2
fixed concept ambiguity
Jun 9, 2023
4a0f920
fixes extra free which happens during tests
Jun 10, 2023
45ce76b
fixed bug
Jun 10, 2023
eedc239
manual unrolling causing errors
Jun 10, 2023
5fe20d0
uninit default construct
Jun 11, 2023
8bf4da7
added another call overload to loop_with_cleanup_n
Jun 11, 2023
e246fe2
clang-format
Jun 11, 2023
c04c157
fixed concept
Jun 11, 2023
8d01524
fixed error from test which hass seninal not convertible to iterable …
Jun 13, 2023
16d5f14
unused variable fixed
Jun 13, 2023
d9772c6
uninit move
Jun 14, 2023
a2c9ce1
uninit value construct
Jun 15, 2023
4765db9
uninit fill
Jun 15, 2023
29e90fa
removed commented out code
Jun 15, 2023
e87991e
reeplaced try catch loops with loop_with_cleanup
Jul 16, 2023
c1dc43f
changed variable name
Jul 16, 2023
aed9825
namespace errors
Jul 16, 2023
bfc74d0
fixed template errors
Jul 17, 2023
ef0476d
cf
Johan511 Jul 17, 2023
cdb1265
Merge branch 'STEllAR-GROUP:master' into uninitialised-algorithms-par…
Johan511 Jul 17, 2023
7202338
removed unused vars
Johan511 Jul 17, 2023
15e8964
requested changes
Johan511 Jul 24, 2023
bb560af
unseq dispatch psuhed to tag_invoke stage
Johan511 Jul 28, 2023
f573137
loop with cleanup moved to tag fallback invoke
Johan511 Aug 2, 2023
e2277ce
removed tokens
Johan511 Aug 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,21 @@ namespace hpx {
#include <hpx/iterator_support/traits/is_iterator.hpp>
#include <hpx/parallel/algorithms/detail/dispatch.hpp>
#include <hpx/parallel/algorithms/detail/distance.hpp>
#include <hpx/parallel/unseq/loop.hpp>
#include <hpx/parallel/util/cancellation_token.hpp>
#include <hpx/parallel/util/detail/algorithm_result.hpp>
#include <hpx/parallel/util/detail/clear_container.hpp>
#include <hpx/parallel/util/detail/sender_util.hpp>
#include <hpx/parallel/util/loop.hpp>
#include <hpx/parallel/util/partitioner_with_cleanup.hpp>
#include <hpx/parallel/util/result_types.hpp>
#include <hpx/parallel/util/transfer.hpp>
#include <hpx/parallel/util/zip_iterator.hpp>
#include <hpx/type_support/construct_at.hpp>

#include <algorithm>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <memory>
#include <type_traits>
Expand All @@ -223,51 +226,11 @@ namespace hpx::parallel {
/// \cond NOINTERNAL

///////////////////////////////////////////////////////////////////////
template <typename InIter1, typename FwdIter2, typename Cond>
util::in_out_result<InIter1, FwdIter2> sequential_uninitialized_copy(
InIter1 first, FwdIter2 dest, Cond cond)
{
FwdIter2 current = dest;
try
{
for (/* */; cond(first, current); (void) ++first, ++current)
{
hpx::construct_at(std::addressof(*current), *first);
}
return util::in_out_result<InIter1, FwdIter2>{first, current};
}
catch (...)
{
for (/* */; dest != current; ++dest)
{
std::destroy_at(std::addressof(*dest));
}
throw;
}
}

///////////////////////////////////////////////////////////////////////
template <typename InIter1, typename InIter2>
util::in_out_result<InIter1, InIter2> sequential_uninitialized_copy_n(
InIter1 first, std::size_t count, InIter2 dest,
util::cancellation_token<util::detail::no_data>& tok)
{
return {std::next(first, count),
util::loop_with_cleanup_n_with_token(
first, count, dest, tok,
[](InIter1 it, InIter2 dest) -> void {
hpx::construct_at(std::addressof(*dest), *it);
},
[](InIter2 dest) -> void {
std::destroy_at(std::addressof(*dest));
})};
}

///////////////////////////////////////////////////////////////////////
template <typename ExPolicy, typename Iter, typename FwdIter2>
typename util::detail::algorithm_result<ExPolicy,
util::in_out_result<Iter, FwdIter2>>::type
parallel_sequential_uninitialized_copy_n(
parallel_uninitialized_copy_n(
ExPolicy&& policy, Iter first, std::size_t count, FwdIter2 dest)
{
if (count == 0)
Expand All @@ -280,22 +243,21 @@ namespace hpx::parallel {
using zip_iterator = hpx::util::zip_iterator<Iter, FwdIter2>;
using partition_result_type = std::pair<FwdIter2, FwdIter2>;

util::cancellation_token<util::detail::no_data> tok;

return util::partitioner_with_cleanup<ExPolicy,
util::in_out_result<Iter, FwdIter2>, partition_result_type>::
call(
HPX_FORWARD(ExPolicy, policy), zip_iterator(first, dest),
count,
[tok](zip_iterator t, std::size_t part_size) mutable
[policy](zip_iterator t, std::size_t part_size) mutable
-> partition_result_type {
using hpx::get;
auto iters = t.get_iterator_tuple();
FwdIter2 dest = get<1>(iters);
return std::make_pair(dest,
util::get_second_element(
sequential_uninitialized_copy_n(
get<0>(iters), part_size, dest, tok)));
hpx::parallel::util::uninit_copy_n(
HPX_FORWARD(ExPolicy, policy),
get<0>(iters), part_size, dest)));
},
// finalize, called once if no error occurred
[dest, first, count](auto&& data) mutable
Expand Down Expand Up @@ -332,12 +294,11 @@ namespace hpx::parallel {
template <typename ExPolicy, typename InIter1, typename Sent,
typename FwdIter2>
static util::in_out_result<InIter1, FwdIter2> sequential(
ExPolicy, InIter1 first, Sent last, FwdIter2 dest)
ExPolicy&& policy, InIter1 first, Sent last, FwdIter2 dest)
{
return sequential_uninitialized_copy(
first, dest, [last](InIter1 first, FwdIter2) -> bool {
return first != last;
});
std::size_t n = std::distance(first, last);
return hpx::parallel::util::uninit_copy_n(
HPX_FORWARD(ExPolicy, policy), first, n, dest);
}

template <typename ExPolicy, typename Iter, typename Sent,
Expand All @@ -346,7 +307,7 @@ namespace hpx::parallel {
util::in_out_result<Iter, FwdIter2>>::type
parallel(ExPolicy&& policy, Iter first, Sent last, FwdIter2 dest)
{
return parallel_sequential_uninitialized_copy_n(
return parallel_uninitialized_copy_n(
HPX_FORWARD(ExPolicy, policy), first,
detail::distance(first, last), dest);
}
Expand All @@ -371,13 +332,16 @@ namespace hpx::parallel {

template <typename ExPolicy, typename InIter1, typename Sent1,
typename FwdIter2, typename Sent2>
static util::in_out_result<InIter1, FwdIter2> sequential(ExPolicy,
InIter1 first, Sent1 last, FwdIter2 dest, Sent2 last_d)
static util::in_out_result<InIter1, FwdIter2> sequential(
ExPolicy&& policy, InIter1 first, Sent1 last, FwdIter2 dest,
Sent2 last_d)
{
return sequential_uninitialized_copy(first, dest,
[last, last_d](InIter1 first, FwdIter2 current) -> bool {
return !(first == last || current == last_d);
});
std::size_t const dist1 = detail::distance(first, last);
std::size_t const dist2 = detail::distance(dest, last_d);
std::size_t dist = dist1 <= dist2 ? dist1 : dist2;

return hpx::parallel::util::uninit_copy_n(
HPX_FORWARD(ExPolicy, policy), first, dist, dest);
}

template <typename ExPolicy, typename Iter, typename Sent1,
Expand All @@ -391,7 +355,7 @@ namespace hpx::parallel {
std::size_t const dist2 = detail::distance(dest, last_d);
std::size_t dist = dist1 <= dist2 ? dist1 : dist2;

return parallel_sequential_uninitialized_copy_n(
return parallel_uninitialized_copy_n(
HPX_FORWARD(ExPolicy, policy), first, dist, dest);
}
};
Expand All @@ -413,28 +377,16 @@ namespace hpx::parallel {
{
}

template <typename ExPolicy, typename InIter, typename FwdIter2>
// non vectorized overload
template <typename ExPolicy, typename InIter, typename FwdIter2,
HPX_CONCEPT_REQUIRES_(
hpx::is_sequenced_execution_policy_v<ExPolicy>)>
static util::in_out_result<InIter, FwdIter2> sequential(
ExPolicy, InIter first, std::size_t count, FwdIter2 dest)
ExPolicy&& policy, InIter first, std::size_t count,
FwdIter2 dest)
{
FwdIter2 current = dest;
try
{
for (/* */; count > 0; ++first, (void) ++current, --count)
{
hpx::construct_at(std::addressof(*current), *first);
}
return util::in_out_result<InIter, FwdIter2>{
first, current};
}
catch (...)
{
for (/* */; dest != current; ++dest)
{
std::destroy_at(std::addressof(*dest));
}
throw;
}
return hpx::parallel::util::uninit_copy_n(
HPX_FORWARD(ExPolicy, policy), first, count, dest);
}

template <typename ExPolicy, typename Iter, typename FwdIter2>
Expand All @@ -443,7 +395,7 @@ namespace hpx::parallel {
parallel(
ExPolicy&& policy, Iter first, std::size_t count, FwdIter2 dest)
{
return parallel_sequential_uninitialized_copy_n(
return parallel_uninitialized_copy_n(
HPX_FORWARD(ExPolicy, policy), first, count, dest);
}
};
Expand Down
Loading
Loading