Skip to content

Commit

Permalink
Adapting transform and transform_binary to support datapar
Browse files Browse the repository at this point in the history
- more work on for_each
- factoring out low-level customization points
  • Loading branch information
hkaiser committed Sep 11, 2016
1 parent e8896f6 commit 9d7b05b
Show file tree
Hide file tree
Showing 27 changed files with 2,581 additions and 1,112 deletions.
2 changes: 2 additions & 0 deletions docs/manual/build_system/cmake_variables.qbk
Expand Up @@ -57,6 +57,7 @@ The options are split into these categories:
* [link build_system.cmake_variables.HPX_WITH_SECURITY HPX_WITH_SECURITY]
* [link build_system.cmake_variables.HPX_WITH_STATIC_LINKING HPX_WITH_STATIC_LINKING]
* [link build_system.cmake_variables.HPX_WITH_SYCL HPX_WITH_SYCL]
* [link build_system.cmake_variables.HPX_WITH_VC_DATAPAR HPX_WITH_VC_DATAPAR]

[variablelist
[[[#build_system.cmake_variables.HPX_WITH_ASYNC_FUNCTION_COMPATIBILITY] `HPX_WITH_ASYNC_FUNCTION_COMPATIBILITY:BOOL`][Enable old style ..._sync/..._async functions in API (default: OFF)]]
Expand Down Expand Up @@ -89,6 +90,7 @@ The options are split into these categories:
[[[#build_system.cmake_variables.HPX_WITH_SECURITY] `HPX_WITH_SECURITY:BOOL`][Enable security support via libsodium.]]
[[[#build_system.cmake_variables.HPX_WITH_STATIC_LINKING] `HPX_WITH_STATIC_LINKING:BOOL`][Compile HPX statically linked libraries (Default: OFF)]]
[[[#build_system.cmake_variables.HPX_WITH_SYCL] `HPX_WITH_SYCL:BOOL`][Enable sycl support (default: OFF)]]
[[[#build_system.cmake_variables.HPX_WITH_VC_DATAPAR] `HPX_WITH_VC_DATAPAR:BOOL`][Enable data parallel algorithm support (default: OFF)]]
] [/ Generic Options]

[#build_system.cmake_variables.Build_Targets][h3 Build Targets Options]
Expand Down
Expand Up @@ -42,7 +42,7 @@ namespace hpx { namespace server
/// \brief This is the basic wrapper class for stl vector.
///
/// This contain the implementation of the partitioned_vector_partition's
/// fcomponent unctionality.
/// component functionality.
template <typename T, typename Data>
class partitioned_vector
: public components::locking_hook<
Expand Down
32 changes: 27 additions & 5 deletions hpx/parallel/algorithms/count.hpp
Expand Up @@ -90,7 +90,7 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
void operator()(Iter curr,
typename std::iterator_traits<Iter>::difference_type& ret)
{
ret += util::detail::count_bits(op_(*curr)); //util::detail::count_bits(hpx::util::invoke(op_, *curr));
ret += util::detail::count_bits(hpx::util::invoke(op_, *curr));
}
};

Expand All @@ -107,9 +107,21 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)

template <typename ExPolicy, typename Iter, typename T>
static difference_type
sequential(ExPolicy, Iter first, Iter last, T const& value)
sequential(ExPolicy && policy, Iter first, Iter last, T const& value)
{
return std::count(first, last, value);
auto f1 =
count_iteration<ExPolicy, detail::compare_to<T> >(
std::forward<ExPolicy>(policy),
detail::compare_to<T>(value));

using hpx::util::placeholders::_1;
typename std::iterator_traits<Iter>::difference_type ret = 0;

util::loop(
policy, first, last,
hpx::util::bind(std::move(f1), _1, std::ref(ret)));

return ret;
}

template <typename ExPolicy, typename Iter, typename T>
Expand Down Expand Up @@ -254,9 +266,19 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)

template <typename ExPolicy, typename Iter, typename Pred>
static difference_type
sequential(ExPolicy, Iter first, Iter last, Pred && op)
sequential(ExPolicy && policy, Iter first, Iter last, Pred && op)
{
return std::count_if(first, last, std::forward<Pred>(op));
auto f1 = count_iteration<ExPolicy, Pred>(
std::forward<ExPolicy>(policy), op);

using hpx::util::placeholders::_1;
typename std::iterator_traits<Iter>::difference_type ret = 0;

util::loop(
policy, first, last,
hpx::util::bind(std::move(f1), _1, std::ref(ret)));

return ret;
}

template <typename ExPolicy, typename Iter, typename Pred>
Expand Down
12 changes: 11 additions & 1 deletion hpx/parallel/algorithms/detail/predicates.hpp
Expand Up @@ -9,6 +9,7 @@
#include <hpx/config.hpp>
#include <hpx/traits/is_iterator.hpp>
#include <hpx/util/assert.hpp>
#include <hpx/util/invoke.hpp>

#include <hpx/parallel/algorithms/detail/is_negative.hpp>
#include <hpx/parallel/config/inline_namespace.hpp>
Expand All @@ -17,6 +18,7 @@
#include <cstddef>
#include <cstdlib>
#include <type_traits>
#include <utility>

namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1) { namespace detail
{
Expand Down Expand Up @@ -222,6 +224,7 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1) { namespace detail
struct equal_to
{
template <typename T1, typename T2>
HPX_HOST_DEVICE HPX_FORCEINLINE
auto operator()(T1 const& t1, T2 const& t2) const
-> decltype(t1 == t2)
{
Expand All @@ -232,12 +235,19 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1) { namespace detail
template <typename Value>
struct compare_to
{
HPX_HOST_DEVICE HPX_FORCEINLINE
compare_to(Value && val)
: value_(std::move(val))
{}
HPX_HOST_DEVICE HPX_FORCEINLINE
compare_to(Value const& val)
: value_(val)
{}

template <typename T>
auto operator()(T const& t) const -> decltype(value_ == t)
HPX_HOST_DEVICE HPX_FORCEINLINE
auto operator()(T const& t) const
-> decltype(std::declval<Value>() == t)
{
return value_ == t;
}
Expand Down
62 changes: 26 additions & 36 deletions hpx/parallel/algorithms/for_each.hpp
Expand Up @@ -13,6 +13,7 @@
#include <hpx/traits/is_callable.hpp>
#include <hpx/traits/is_iterator.hpp>
#include <hpx/traits/segmented_iterator_traits.hpp>
#include <hpx/util/identity.hpp>
#include <hpx/util/invoke.hpp>

#include <hpx/parallel/algorithms/detail/dispatch.hpp>
Expand All @@ -38,6 +39,20 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
namespace detail
{
/// \cond NOINTERNAL
template <typename F, typename Proj>
struct invoke_projected
{
typename hpx::util::decay<F>::type& f_;
typename hpx::util::decay<Proj>::type& proj_;

template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE
void operator()(Iter curr)
{
hpx::util::invoke(f_, hpx::util::invoke(proj_, *curr));
}
};

template <typename ExPolicy, typename F, typename Proj>
struct for_each_iteration
{
Expand Down Expand Up @@ -82,14 +97,8 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
void operator()(Iter part_begin, std::size_t part_size,
std::size_t /*part_index*/)
{
util::loop_n(policy_, part_begin, part_size, *this);
}

template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE
void operator()(Iter curr)
{
hpx::util::invoke(f_, hpx::util::invoke(proj_, *curr));
util::loop_n(policy_, part_begin, part_size,
invoke_projected<fun_type, proj_type>{f_, proj_});
}
};

Expand All @@ -107,14 +116,8 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
sequential(ExPolicy && policy, InIter first, std::size_t count,
F && f, Proj && proj/* = Proj()*/)
{
typedef typename util::detail::loop_n<InIter>::type it_type;

return util::loop_n(
policy, first, count,
[&f, &proj](it_type curr)
{
hpx::util::invoke(f, hpx::util::invoke(proj, *curr));
});
return util::loop_n(std::forward<ExPolicy>(policy),
first, count, invoke_projected<F, Proj>{f, proj});
}

template <typename ExPolicy, typename InIter, typename F,
Expand All @@ -132,11 +135,7 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)

return util::foreach_partitioner<ExPolicy>::call(
std::forward<ExPolicy>(policy), first, count,
std::move(f1),
[](InIter && last) -> InIter
{
return std::move(last);
});
std::move(f1), util::projection_identity());
}

return util::detail::algorithm_result<ExPolicy, InIter>::get(
Expand Down Expand Up @@ -272,16 +271,11 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
template <typename ExPolicy, typename InIter, typename F,
typename Proj>
static InIter
sequential(ExPolicy, InIter first, InIter last, F && f,
sequential(ExPolicy && policy, InIter first, InIter last, F && f,
Proj && proj)
{
typedef typename util::detail::loop<InIter>::type it_type;

return util::loop(first, last,
[&f, &proj](it_type curr)
{
hpx::util::invoke(f, hpx::util::invoke(proj, *curr));
});
return util::loop(std::forward<ExPolicy>(policy), first, last,
invoke_projected<F, Proj>{f, proj});
}

template <typename ExPolicy, typename InIter, typename F,
Expand All @@ -298,13 +292,9 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
std::forward<F>(f), std::forward<Proj>(proj));

return util::foreach_partitioner<ExPolicy>::call(
std::forward<ExPolicy>(policy), first,
std::distance(first, last),
std::move(f1),
[](InIter && last) -> InIter
{
return std::move(last);
});
std::forward<ExPolicy>(policy),
first, std::distance(first, last),
std::move(f1), util::projection_identity());
}

return util::detail::algorithm_result<ExPolicy, InIter>::get(
Expand Down

0 comments on commit 9d7b05b

Please sign in to comment.