Skip to content

Commit

Permalink
Making APEX actually picking up the annotated function name
Browse files Browse the repository at this point in the history
- added support in for_each, for_loop, and transform
  • Loading branch information
hkaiser committed Apr 7, 2017
1 parent d0c4b66 commit 7966811
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 5 deletions.
72 changes: 70 additions & 2 deletions hpx/parallel/algorithms/for_each.hpp
Expand Up @@ -26,6 +26,19 @@
#include <hpx/parallel/util/foreach_partitioner.hpp>
#include <hpx/parallel/util/loop.hpp>
#include <hpx/parallel/util/projection_identity.hpp>
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
#include <hpx/traits/get_function_address.hpp>
#include <hpx/traits/get_function_annotation.hpp>
#endif
#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_APEX)
#include <hpx/runtime/get_thread_name.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 <algorithm>
#include <cstddef>
Expand Down Expand Up @@ -86,6 +99,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 +137,22 @@ 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_});
#if HPX_HAVE_ITTNOTIFY != 0
util::itt::string_handle const& sh =
hpx::traits::get_function_annotation_itt<fun_type>::call(f_);
util::itt::task task(hpx::get_thread_itt_domain(), sh);
#elif defined(HPX_HAVE_APEX)
char const* name =
hpx::traits::get_function_annotation<fun_type>::call(f_);
if (name != nullptr)
{
util::apex_wrapper apex_profiler(name,
reinterpret_cast<std::uint64_t>(this));
execute(part_begin, part_size);
}
else
#endif
execute(part_begin, part_size);
}
};

Expand Down Expand Up @@ -463,4 +498,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
71 changes: 70 additions & 1 deletion hpx/parallel/algorithms/for_loop.hpp
Expand Up @@ -27,6 +27,19 @@
#include <hpx/parallel/util/detail/algorithm_result.hpp>
#include <hpx/parallel/util/loop.hpp>
#include <hpx/parallel/util/partitioner.hpp>
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
#include <hpx/traits/get_function_address.hpp>
#include <hpx/traits/get_function_annotation.hpp>
#endif
#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_APEX)
#include <hpx/runtime/get_thread_name.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 <algorithm>
#include <cstddef>
Expand Down Expand Up @@ -110,7 +123,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 +146,29 @@ 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)
{
#if HPX_HAVE_ITTNOTIFY != 0
util::itt::string_handle const& sh =
hpx::traits::get_function_annotation_itt<fun_type>::call(f_);
util::itt::task task(hpx::get_thread_itt_domain(), sh);
#elif defined(HPX_HAVE_APEX)
char const* name =
hpx::traits::get_function_annotation<fun_type>::call(f_);
if (name != nullptr)
{
util::apex_wrapper apex_profiler(name,
reinterpret_cast<std::uint64_t>(this));
execute(part_begin, part_steps, part_index)
}
else
#endif
execute(part_begin, part_steps, part_index);
}
};

///////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1099,5 +1135,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

80 changes: 78 additions & 2 deletions hpx/parallel/algorithms/transform.hpp
Expand Up @@ -27,6 +27,19 @@
#include <hpx/parallel/util/transform_loop.hpp>
#include <hpx/parallel/util/projection_identity.hpp>
#include <hpx/parallel/util/zip_iterator.hpp>
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
#include <hpx/traits/get_function_address.hpp>
#include <hpx/traits/get_function_annotation.hpp>
#endif
#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_APEX)
#include <hpx/runtime/get_thread_name.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 <algorithm>
#include <cstddef>
Expand Down Expand Up @@ -103,15 +116,45 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
1, typename Iter::iterator_tuple_type
>::type
>
operator()(Iter part_begin, std::size_t part_size,
std::size_t /*part_index*/)
execute(Iter part_begin, std::size_t part_size)
{
auto iters = part_begin.get_iterator_tuple();
return util::transform_loop_n<execution_policy_type>(
hpx::util::get<0>(iters), part_size,
hpx::util::get<1>(iters),
transform_projected<F, Proj>{f_, proj_});
}

template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE
std::pair<
typename hpx::util::tuple_element<
0, typename Iter::iterator_tuple_type
>::type,
typename hpx::util::tuple_element<
1, typename Iter::iterator_tuple_type
>::type
>
operator()(Iter part_begin, std::size_t part_size,
std::size_t /*part_index*/)
{
#if HPX_HAVE_ITTNOTIFY != 0
util::itt::string_handle const& sh =
hpx::traits::get_function_annotation_itt<fun_type>::call(f_);
util::itt::task task(hpx::get_thread_itt_domain(), sh);
#elif defined(HPX_HAVE_APEX)
char const* name =
hpx::traits::get_function_annotation<fun_type>::call(f_);
if (name != nullptr)
{
util::apex_wrapper apex_profiler(name,
reinterpret_cast<std::uint64_t>(this));
execute(part_begin, part_size);
}
else
#endif
execute(part_begin, part_size);
}
};

template <typename IterPair>
Expand Down Expand Up @@ -788,4 +831,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::transform_iteration<ExPolicy, F, Proj> >
{
static std::size_t call(
parallel::v1::detail::transform_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::transform_iteration<ExPolicy, F, Proj> >
{
static char const* call(
parallel::v1::detail::transform_iteration<ExPolicy, F, Proj> const& f)
HPX_NOEXCEPT
{
return get_function_annotation<
typename hpx::util::decay<F>::type
>::call(f.f_);
}
};
}}
#endif

#endif
1 change: 1 addition & 0 deletions tests/regressions/parallel/CMakeLists.txt
Expand Up @@ -4,6 +4,7 @@
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

set(tests
for_each_annotated_function
for_loop_2281
minimal_findend
scan_different_inits
Expand Down
49 changes: 49 additions & 0 deletions tests/regressions/parallel/for_each_annotated_function.cpp
@@ -0,0 +1,49 @@
// Copyright (c) 2017 Hartmut Kaiser
//
// 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)

#include <hpx/hpx_init.hpp>
#include <hpx/hpx.hpp>
#include <hpx/include/parallel_for_each.hpp>
#include <hpx/util/lightweight_test.hpp>

#include <algorithm>
#include <numeric>
#include <string>
#include <vector>

///////////////////////////////////////////////////////////////////////////////
int hpx_main()
{
std::vector<int> c(10007);
std::iota(boost::begin(c), boost::end(c), std::rand());

hpx::parallel::for_each(
hpx::parallel::execution::par, c.begin(), c.end(),
hpx::util::annotated_function(
[](int i) -> void
{
hpx::util::thread_description desc(
hpx::threads::get_thread_description(hpx::threads::get_self_id())
);
HPX_TEST(std::string(desc.get_description()) == "annotated_function");
},
"annotated_function"
)
);

return hpx::finalize();
}

int main(int argc, char* argv[])
{
std::vector<std::string> const cfg = {
"hpx.os_threads=4"
};

HPX_TEST_EQ_MSG(hpx::init(argc, argv, cfg), 0,
"HPX main exited with non-zero status");

return hpx::util::report_errors();
}

0 comments on commit 7966811

Please sign in to comment.