-
-
Notifications
You must be signed in to change notification settings - Fork 438
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
Relocation algorithms Clean #6314
Closed
isidorostsa
wants to merge
60
commits into
STEllAR-GROUP:master
from
isidorostsa:relocate_algorithms_clean
Closed
Changes from 29 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
2709dd9
relocate_at impl w/ tests
isidorostsa 3afc851
uninitialized_relocate w/ tests and comments fixed
isidorostsa 0b3a6e8
expected compile error tests
isidorostsa fe6e0fb
clang-format
isidorostsa 8ef523a
add explicit-noexcept where it is missing
isidorostsa 13a1279
enum instead of magic numbers
isidorostsa 2c9edb0
remove explicit from move constructors
isidorostsa 36b70cb
add explicit to relocate_at.cpp too
isidorostsa 148d729
fix Werror=class-memaccess, cast away const
isidorostsa cafae0c
clang-format
isidorostsa bf48827
too long line
isidorostsa 2706778
clang-format
isidorostsa 07bd94c
Arrays of TR types are TR
isidorostsa 6f22033
is_trivially_copyable -> is_trivially_relocatable correction
isidorostsa cb44e29
Add cvrefs and arrays to be "decayed"
isidorostsa 7fb8958
arrays of known size
isidorostsa 3f6059d
const volatile to avoid ambiguity
isidorostsa 4367007
cover rvalues too
isidorostsa 6dcb771
clang format
isidorostsa 6e532e1
testing and more specific ambiguity checks
isidorostsa 18705b9
clang-format
isidorostsa 22aeff9
clang-format
isidorostsa 944ccb9
detect trivially relocatable category
isidorostsa 7dbc69e
specific loop version needed for relocations
isidorostsa ba51777
uninitialized_relocate helpers
isidorostsa b41893f
deprecate type_support/uninitialized_relocate.hpp
isidorostsa 87f68e1
algorithms/uninitialized_relocate.hpp seq version
isidorostsa ab55350
algorithms/uninitialized_relocate.hpp par version
isidorostsa 324c3f1
various syntax fixes
isidorostsa 8d126a3
uninitialized_relocate_n test
isidorostsa b2f3946
include is_relocatable
isidorostsa 40269c0
missing includes and namespaces
isidorostsa 312cf1f
fix includes
isidorostsa b30eb55
fix typo + include
isidorostsa 8685988
endline
isidorostsa 2c1f407
remove circ dep
isidorostsa 9b27231
correctly resolve namespaces
isidorostsa db65f32
change uninitialzied_relocate_n test name
isidorostsa 8f0cc63
uninitialized_relocate iterators version
isidorostsa 6e1e85e
add noexcept relocation detector
isidorostsa db8ed7c
use HPX_CONCEPT_REQUIRES, detect noexcepts
isidorostsa a3d51bf
fix returned value of nothrow relocation
isidorostsa 00fb2e5
clang-format
isidorostsa 0d3d917
clang-format
isidorostsa 0d3a178
inspect
isidorostsa 0a60cf8
Merge branch 'relocate_algorithms_clean' of github.com:isidorostsa/hp…
isidorostsa 1a2e8a7
remove unneeded params + clang-format
isidorostsa 99c4dbb
using execution_policy instead of hpx/execution
isidorostsa 36080a3
include fixes
isidorostsa a9f9e9a
remove unused var
isidorostsa 32ed3c1
unwrap zip_iterator manually
isidorostsa c288589
clang-format
isidorostsa 95a70a0
gcc11 fix unpacking iterators
isidorostsa 4b98351
clang-format
isidorostsa 909998c
Add doxygen docs
isidorostsa 4bdc115
clang-format
isidorostsa 1e57fe5
docs typo
isidorostsa 426c52a
EOF endline
isidorostsa 8fd47df
public api gives better warnings
isidorostsa d26c2f6
atomics in test
isidorostsa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
275 changes: 275 additions & 0 deletions
275
libs/core/algorithms/include/hpx/parallel/algorithms/uninitialized_relocate.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,275 @@ | ||
// Copyright (c) 2014-2023 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) | ||
|
||
/// \file parallel/algorithms/uninitialized_relocate.hpp | ||
|
||
#pragma once | ||
|
||
#include <hpx/config.hpp> | ||
#include <hpx/concepts/concepts.hpp> | ||
#include <hpx/execution/algorithms/detail/is_negative.hpp> | ||
#include <hpx/executors/execution_policy.hpp> | ||
#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/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> | ||
#include <utility> | ||
|
||
namespace hpx::parallel { | ||
|
||
/////////////////////////////////////////////////////////////////////////// | ||
// uninitialized_relocate | ||
namespace detail { | ||
/// \cond NOINTERNAL | ||
|
||
/////////////////////////////////////////////////////////////////////// | ||
|
||
template <typename ExPolicy, typename Iter, typename FwdIter2> | ||
typename util::detail::algorithm_result<ExPolicy, | ||
util::in_out_result<Iter, FwdIter2>>::type | ||
parallel_uninitialized_relocate_n( | ||
ExPolicy&& policy, Iter first, std::size_t count, FwdIter2 dest) | ||
{ | ||
if (count == 0) | ||
{ | ||
return util::detail::algorithm_result<ExPolicy, | ||
util::in_out_result<Iter, FwdIter2>>:: | ||
get(util::in_out_result<Iter, FwdIter2>{first, dest}); | ||
} | ||
|
||
using zip_iterator = hpx::util::zip_iterator<Iter, FwdIter2>; | ||
using partition_result_type = std::pair<FwdIter2, FwdIter2>; | ||
|
||
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, | ||
[policy](zip_iterator t, std::size_t part_size) mutable | ||
-> partition_result_type { | ||
using hpx::get; | ||
|
||
auto iters = t.get_iterator_tuple(); | ||
|
||
Iter part_source = get<0>(iters); | ||
FwdIter2 part_dest = get<1>(iters); | ||
|
||
// returns (dest begin, dest end) | ||
return std::make_pair(part_dest, | ||
util::get_second_element( | ||
hpx::parallel::util::uninit_relocate_n( | ||
HPX_FORWARD(ExPolicy, policy), part_source, | ||
part_size, part_dest))); | ||
}, | ||
// finalize, called once if no error occurred | ||
[dest, first, count](auto&& data) mutable | ||
-> util::in_out_result<Iter, FwdIter2> { | ||
// make sure iterators embedded in function object that is | ||
// attached to futures are invalidated | ||
util::detail::clear_container(data); | ||
|
||
std::advance(first, count); | ||
std::advance(dest, count); | ||
return util::in_out_result<Iter, FwdIter2>{first, dest}; | ||
}, | ||
// cleanup function, called for each partition which | ||
// didn't fail, but only if at least one failed | ||
[](partition_result_type&& r) -> void { | ||
std::destroy(r.first, r.second); | ||
}); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// uninitialized_relocate_n | ||
|
||
/// \cond NOINTERNAL | ||
template <typename IterPair> | ||
struct uninitialized_relocate_n | ||
: public algorithm<uninitialized_relocate_n<IterPair>, IterPair> | ||
{ | ||
constexpr uninitialized_relocate_n() noexcept | ||
: algorithm<uninitialized_relocate_n, IterPair>( | ||
"uninitialized_relocate_n") | ||
{ | ||
} | ||
|
||
// 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&& policy, InIter first, std::size_t count, | ||
FwdIter2 dest) | ||
{ | ||
return hpx::parallel::util::uninit_relocate_n( | ||
HPX_FORWARD(ExPolicy, policy), first, count, dest); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sequential overload takes |
||
} | ||
|
||
template <typename ExPolicy, typename Iter, typename FwdIter2> | ||
static util::detail::algorithm_result_t<ExPolicy, | ||
util::in_out_result<Iter, FwdIter2>> | ||
parallel( | ||
ExPolicy&& policy, Iter first, std::size_t count, FwdIter2 dest) | ||
{ | ||
return parallel_uninitialized_relocate_n( | ||
HPX_FORWARD(ExPolicy, policy), first, count, dest); | ||
} | ||
}; | ||
/// \endcond | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// uninitialized_relocate | ||
/// \cond NOINTERNAL | ||
template <typename IterPair> | ||
struct uninitialized_relocate | ||
: public algorithm<uninitialized_relocate<IterPair>, IterPair> | ||
{ | ||
constexpr uninitialized_relocate() noexcept | ||
: algorithm<uninitialized_relocate, IterPair>( | ||
"uninitialized_relocate") | ||
{ | ||
} | ||
|
||
// 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&& policy, InIter first, InIter last, FwdIter2 dest) | ||
{ | ||
auto count = std::distance(first, last); | ||
|
||
return hpx::parallel::util::uninit_relocate_n( | ||
HPX_FORWARD(ExPolicy, policy), first, count, dest); | ||
} | ||
|
||
template <typename ExPolicy, typename InIter, typename FwdIter2> | ||
static util::detail::algorithm_result_t<ExPolicy, | ||
util::in_out_result<InIter, FwdIter2>> | ||
parallel( | ||
ExPolicy&& policy, InIter first, InIter last, FwdIter2 dest) | ||
{ | ||
auto count = std::distance(first, last); | ||
|
||
return parallel_uninitialized_relocate_n( | ||
HPX_FORWARD(ExPolicy, policy), first, count, dest); | ||
} | ||
}; | ||
/// \endcond | ||
|
||
} // namespace detail | ||
} // namespace hpx::parallel | ||
|
||
namespace hpx { | ||
|
||
/////////////////////////////////////////////////////////////////////////// | ||
// CPO for hpx::uninitialized_relocate_n | ||
inline constexpr struct uninitialized_relocate_n_t final | ||
: hpx::detail::tag_parallel_algorithm<uninitialized_relocate_n_t> | ||
{ | ||
// clang-format off | ||
template <typename InIter, typename Size, | ||
typename FwdIter, | ||
HPX_CONCEPT_REQUIRES_( | ||
hpx::traits::is_iterator_v<InIter> && | ||
hpx::traits::is_forward_iterator_v<FwdIter> && | ||
std::is_integral_v<Size> | ||
)> | ||
// clang-format on | ||
friend FwdIter tag_fallback_invoke(hpx::uninitialized_relocate_n_t, | ||
InIter first, Size count, | ||
hkaiser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FwdIter dest) noexcept(std::is_same_v<hpx::traits:: | ||
pointer_relocate_category< | ||
InIter, FwdIter>, | ||
hpx::traits:: | ||
nothrow_relocatable_pointer_tag> || | ||
std::is_same_v< | ||
hpx::traits::pointer_relocate_category<InIter, FwdIter>, | ||
hpx::traits::trivially_relocatable_pointer_tag>) | ||
{ | ||
static_assert(hpx::traits::is_input_iterator_v<InIter>, | ||
"Required at least input iterator."); | ||
static_assert(hpx::traits::is_forward_iterator_v<FwdIter>, | ||
"Requires at least forward iterator."); | ||
static_assert(hpx::traits::pointer_relocate_category<InIter, | ||
FwdIter>::valid_relocation, | ||
"Relocating from this source type to this destination type is " | ||
"ill-formed"); | ||
|
||
// if count is representing a negative value, we do nothing | ||
if (hpx::parallel::detail::is_negative(count)) | ||
{ | ||
return dest; | ||
} | ||
|
||
return parallel::util::get_second_element( | ||
hpx::parallel::detail::uninitialized_relocate_n< | ||
parallel::util::in_out_result<InIter, FwdIter>>() | ||
.call(hpx::execution::seq, first, | ||
static_cast<std::size_t>(count), dest)); | ||
} | ||
|
||
// clang-format off | ||
template <typename ExPolicy, typename FwdIter1, typename Size, | ||
typename FwdIter2, | ||
HPX_CONCEPT_REQUIRES_( | ||
hpx::is_execution_policy_v<ExPolicy> && | ||
hpx::traits::is_forward_iterator_v<FwdIter1> && | ||
hpx::traits::is_forward_iterator_v<FwdIter2> && | ||
std::is_integral_v<Size> | ||
)> | ||
friend typename parallel::util::detail::algorithm_result<ExPolicy, | ||
FwdIter2>::type | ||
tag_fallback_invoke(hpx::uninitialized_relocate_n_t, ExPolicy&& policy, | ||
FwdIter1 first, Size count, FwdIter2 dest) noexcept( | ||
std::is_same_v< | ||
hpx::traits::pointer_relocate_category<FwdIter1, FwdIter2>, | ||
hpx::traits::nothrow_relocatable_pointer_tag> || | ||
std::is_same_v< | ||
hpx::traits::pointer_relocate_category<FwdIter1, FwdIter2>, | ||
hpx::traits::trivially_relocatable_pointer_tag>) | ||
// clang-format on | ||
{ | ||
static_assert(hpx::traits::is_forward_iterator_v<FwdIter1>, | ||
"Requires at least forward iterator."); | ||
static_assert(hpx::traits::is_forward_iterator_v<FwdIter2>, | ||
"Requires at least forward iterator."); | ||
static_assert(hpx::traits::pointer_relocate_category<FwdIter1, | ||
FwdIter2>::valid_relocation, | ||
"Relocating from this source type to this destination type is " | ||
"ill-formed"); | ||
|
||
// if count is representing a negative value, we do nothing | ||
if (hpx::parallel::detail::is_negative(count)) | ||
{ | ||
return parallel::util::detail::algorithm_result<ExPolicy, | ||
FwdIter2>::get(HPX_MOVE(dest)); | ||
} | ||
|
||
return parallel::util::get_second_element( | ||
hpx::parallel::detail::uninitialized_relocate_n< | ||
parallel::util::in_out_result<FwdIter1, FwdIter2>>() | ||
.call(HPX_FORWARD(ExPolicy, policy), first, | ||
static_cast<std::size_t>(count), dest)); | ||
} | ||
} uninitialized_relocate_n{}; | ||
} // namespace hpx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need an empty line at the EOF. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding some docs as well? @dimitraka can help with the integration into the documentation build etc.