Skip to content

Commit

Permalink
Merge pull request #2581 from STEllAR-GROUP/annotate_parallel_algorithms
Browse files Browse the repository at this point in the history
Enable annotated function for parallel algorithms
  • Loading branch information
hkaiser committed Apr 16, 2017
2 parents 5da331d + 6c9af5e commit a238b89
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 134 deletions.
25 changes: 2 additions & 23 deletions hpx/lcos/dataflow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,14 @@
#include <hpx/traits/is_future_range.hpp>
#include <hpx/traits/is_launch_policy.hpp>
#include <hpx/traits/promise_local_result.hpp>
#include <hpx/util/annotated_function.hpp>
#include <hpx/util/deferred_call.hpp>
#include <hpx/util/detail/pack.hpp>
#include <hpx/util/invoke_fused.hpp>
#include <hpx/util/thread_description.hpp>
#include <hpx/util/tuple.hpp>
#include <hpx/util/unwrap_ref.hpp>

#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_APEX)
#include <hpx/runtime/get_thread_name.hpp>
#include <hpx/traits/get_function_annotation.hpp>
#if defined(HPX_HAVE_APEX)
#include <hpx/util/apex.hpp>
#else
#include <hpx/util/itt_notify.hpp>
#endif
#endif

#include <hpx/parallel/executors/executor_traits.hpp>

#include <boost/atomic.hpp>
Expand Down Expand Up @@ -237,19 +228,7 @@ namespace hpx { namespace lcos { namespace detail

HPX_FORCEINLINE void done()
{
#if HPX_HAVE_ITTNOTIFY != 0
util::itt::string_handle const& sh =
traits::get_function_annotation_itt<Func>::call(func_);
util::itt::task task(hpx::get_thread_itt_domain(), sh);
#elif defined(HPX_HAVE_APEX)
char const* name = traits::get_function_annotation<Func>::call(func_);
if (name != nullptr)
{
util::apex_wrapper apex_profiler(name, (uint64_t)this);
execute(indices_type(), is_void());
}
else
#endif
hpx::util::annotate_function annotate(func_);
execute(indices_type(), is_void());
}

Expand Down
30 changes: 2 additions & 28 deletions hpx/lcos/detail/future_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <hpx/throw_exception.hpp>
#include <hpx/traits/future_access.hpp>
#include <hpx/traits/get_remote_result.hpp>
#include <hpx/util/annotated_function.hpp>
#include <hpx/util/assert_owns_lock.hpp>
#include <hpx/util/atomic_count.hpp>
#include <hpx/util/bind.hpp>
Expand All @@ -27,17 +28,6 @@
#include <hpx/util/unique_function.hpp>
#include <hpx/util/unused.hpp>

#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_APEX)
#include <hpx/runtime/get_thread_name.hpp>
#include <hpx/traits/get_function_annotation.hpp>
#include <hpx/util/thread_description.hpp>
#if defined(HPX_HAVE_APEX)
#include <hpx/util/apex.hpp>
#else
#include <hpx/util/itt_notify.hpp>
#endif
#endif

#include <boost/exception_ptr.hpp>
#include <boost/intrusive_ptr.hpp>

Expand Down Expand Up @@ -513,23 +503,7 @@ namespace detail
boost::exception_ptr& ptr)
{
try {
#if HPX_HAVE_ITTNOTIFY != 0
util::itt::string_handle const& sh =
traits::get_function_annotation_itt<
completed_callback_type
>::call(on_completed);
util::itt::task task(hpx::get_thread_itt_domain(), sh);
#elif defined(HPX_HAVE_APEX)
char const* name = traits::get_function_annotation<
completed_callback_type
>::call(on_completed);
if (name != nullptr)
{
util::apex_wrapper apex_profiler(name, (uint64_t)this);
on_completed();
}
else
#endif
hpx::util::annotate_function annotate(on_completed);
on_completed();
}
catch (...) {
Expand Down
25 changes: 2 additions & 23 deletions hpx/lcos/local/packaged_continuation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,12 @@
#include <hpx/traits/future_access.hpp>
#include <hpx/traits/future_traits.hpp>
#include <hpx/traits/is_executor.hpp>
#include <hpx/util/annotated_function.hpp>
#include <hpx/util/bind.hpp>
#include <hpx/util/decay.hpp>
#include <hpx/util/deferred_call.hpp>
#include <hpx/util/thread_description.hpp>

#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_APEX)
#include <hpx/runtime/get_thread_name.hpp>
#include <hpx/traits/get_function_annotation.hpp>
#if defined(HPX_HAVE_APEX)
#include <hpx/util/apex.hpp>
#else
#include <hpx/util/itt_notify.hpp>
#endif
#endif

#include <boost/intrusive_ptr.hpp>

#include <functional>
Expand Down Expand Up @@ -115,19 +106,7 @@ namespace hpx { namespace lcos { namespace detail
typename util::result_of<Func(Future)>::type
> is_void;

#if HPX_HAVE_ITTNOTIFY != 0
util::itt::string_handle const& sh =
traits::get_function_annotation_itt<Func>::call(func);
util::itt::task task(hpx::get_thread_itt_domain(), sh);
#elif defined(HPX_HAVE_APEX)
char const* name = traits::get_function_annotation<Func>::call(func);
if (name != nullptr)
{
util::apex_wrapper apex_profiler(name, (uint64_t)&future);
invoke_continuation(func, future, cont, is_void());
}
else
#endif
hpx::util::annotate_function annotate(func);
invoke_continuation(func, future, cont, is_void());
}

Expand Down
29 changes: 2 additions & 27 deletions hpx/lcos/local/packaged_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@
#include <hpx/lcos/local/promise.hpp>
#include <hpx/throw_exception.hpp>
#include <hpx/traits/is_callable.hpp>
#include <hpx/util/annotated_function.hpp>
#include <hpx/util/thread_description.hpp>
#include <hpx/util/unique_function.hpp>

#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_APEX)
#include <hpx/runtime/get_thread_name.hpp>
#include <hpx/traits/get_function_annotation.hpp>
#if defined(HPX_HAVE_APEX)
#include <hpx/util/apex.hpp>
#else
#include <hpx/util/itt_notify.hpp>
#endif
#endif

#include <boost/exception_ptr.hpp>

#include <type_traits>
Expand Down Expand Up @@ -92,23 +83,7 @@ namespace hpx { namespace lcos { namespace local
return;
}

#if HPX_HAVE_ITTNOTIFY != 0
util::itt::string_handle const& sh =
traits::get_function_annotation_itt<
function_type
>::call(function_);
util::itt::task task(hpx::get_thread_itt_domain(), sh);
#elif defined(HPX_HAVE_APEX)
char const* name = traits::get_function_annotation<
function_type
>::call(function_);
if (name != nullptr)
{
util::apex_wrapper apex_profiler(name, (uint64_t)this);
invoke_impl(std::is_void<R>(), std::forward<Ts>(vs)...);
}
else
#endif
hpx::util::annotate_function annotate(function_);
invoke_impl(std::is_void<R>(), std::forward<Ts>(vs)...);
}

Expand Down
51 changes: 49 additions & 2 deletions hpx/parallel/algorithms/for_each.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@

#include <hpx/config.hpp>
#include <hpx/traits/concepts.hpp>
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
#include <hpx/traits/get_function_address.hpp>
#include <hpx/traits/get_function_annotation.hpp>
#endif
#include <hpx/traits/is_callable.hpp>
#include <hpx/traits/is_iterator.hpp>
#include <hpx/traits/is_value_proxy.hpp>
#include <hpx/traits/segmented_iterator_traits.hpp>
#include <hpx/util/annotated_function.hpp>
#include <hpx/util/identity.hpp>
#include <hpx/util/invoke.hpp>

Expand All @@ -29,6 +34,7 @@

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -86,6 +92,14 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
fun_type f_;
proj_type proj_;

template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE
void execute(Iter part_begin, std::size_t part_size)
{
util::loop_n<execution_policy_type>(part_begin, part_size,
invoke_projected<fun_type, proj_type>{f_, proj_});
}

template <typename F_, typename Proj_>
HPX_HOST_DEVICE for_each_iteration(F_ && f, Proj_ && proj)
: f_(std::forward<F_>(f))
Expand Down Expand Up @@ -116,8 +130,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<execution_policy_type>(part_begin, part_size,
invoke_projected<fun_type, proj_type>{f_, proj_});
hpx::util::annotate_function annotate(f_);
execute(part_begin, part_size);
}
};

Expand Down Expand Up @@ -463,4 +477,37 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
}
}}}

#if defined(HPX_HAVE_THREAD_DESCRIPTION)
namespace hpx { namespace traits
{
template <typename ExPolicy, typename F, typename Proj>
struct get_function_address<
parallel::v1::detail::for_each_iteration<ExPolicy, F, Proj> >
{
static std::size_t call(
parallel::v1::detail::for_each_iteration<ExPolicy, F, Proj> const& f)
HPX_NOEXCEPT
{
return get_function_address<
typename hpx::util::decay<F>::type
>::call(f.f_);
}
};

template <typename ExPolicy, typename F, typename Proj>
struct get_function_annotation<
parallel::v1::detail::for_each_iteration<ExPolicy, F, Proj> >
{
static char const* call(
parallel::v1::detail::for_each_iteration<ExPolicy, F, Proj> const& f)
HPX_NOEXCEPT
{
return get_function_annotation<
typename hpx::util::decay<F>::type
>::call(f.f_);
}
};
}}
#endif

#endif
54 changes: 52 additions & 2 deletions hpx/parallel/algorithms/for_loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

#include <hpx/config.hpp>
#include <hpx/traits/concepts.hpp>
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
#include <hpx/traits/get_function_address.hpp>
#include <hpx/traits/get_function_annotation.hpp>
#endif
#include <hpx/traits/is_iterator.hpp>
#include <hpx/util/annotated_function.hpp>
#include <hpx/util/assert.hpp>
#include <hpx/util/decay.hpp>
#include <hpx/util/detail/pack.hpp>
Expand All @@ -30,6 +35,7 @@

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -97,7 +103,9 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v2)
template <typename F, typename S, typename ...Ts>
struct part_iterations<F, S, hpx::util::tuple<Ts...> >
{
typename hpx::util::decay<F>::type f_;
typedef typename hpx::util::decay<F>::type fun_type;

fun_type f_;
S stride_;
hpx::util::tuple<Ts...> args_;

Expand All @@ -110,7 +118,7 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v2)

template <typename B>
HPX_HOST_DEVICE
void operator()(B part_begin, std::size_t part_steps,
void execute(B part_begin, std::size_t part_steps,
std::size_t part_index)
{
auto pack = typename hpx::util::detail::make_index_pack<
Expand All @@ -133,6 +141,15 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v2)
part_steps -= chunk;
}
}

template <typename B>
HPX_HOST_DEVICE
void operator()(B part_begin, std::size_t part_steps,
std::size_t part_index)
{
hpx::util::annotate_function annotate(f_);
execute(part_begin, part_steps, part_index);
}
};

///////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1099,5 +1116,38 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v2)
}
}}}

#if defined(HPX_HAVE_THREAD_DESCRIPTION)
namespace hpx { namespace traits
{
template <typename F, typename S, typename Tuple>
struct get_function_address<
parallel::v2::detail::part_iterations<F, S, Tuple> >
{
static std::size_t call(
parallel::v2::detail::part_iterations<F, S, Tuple> const& f)
HPX_NOEXCEPT
{
return get_function_address<
typename hpx::util::decay<F>::type
>::call(f.f_);
}
};

template <typename F, typename S, typename Tuple>
struct get_function_annotation<
parallel::v2::detail::part_iterations<F, S, Tuple> >
{
static char const* call(
parallel::v2::detail::part_iterations<F, S, Tuple> const& f)
HPX_NOEXCEPT
{
return get_function_annotation<
typename hpx::util::decay<F>::type
>::call(f.f_);
}
};
}}
#endif

#endif

Loading

0 comments on commit a238b89

Please sign in to comment.