Skip to content

Commit

Permalink
Merge pull request #2228 from STEllAR-GROUP/prefetching_test
Browse files Browse the repository at this point in the history
On prefetching_test branch : adding prefetching_iterator and related tests used for prefetching containers within lambda functions
  • Loading branch information
hkaiser committed Jun 26, 2016
2 parents ce26b07 + 34c7dc4 commit eab1171
Show file tree
Hide file tree
Showing 11 changed files with 953 additions and 33 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Expand Up @@ -1025,6 +1025,13 @@ if(HPX_WITH_CUDA AND HPX_WITH_CUDA_CLANG)
link_directories(${CUDA_TOOLKIT_ROOT_DIR}/lib64)
endif()

################################################################################
# check for miscellaneous things
################################################################################

hpx_check_for_mm_prefetch(
DEFINITIONS HPX_HAVE_MM_PREFETCH)

################################################################################
# Check for misc system headers
################################################################################
Expand Down
9 changes: 8 additions & 1 deletion cmake/HPX_AddConfigTest.cmake
Expand Up @@ -83,7 +83,7 @@ macro(add_hpx_config_test variable)
OUTPUT_VARIABLE ${variable}_OUTPUT
COPY_FILE ${test_binary})
hpx_debug("Compile test: ${variable}")
hpx_debug("Compilation output: \n\n${${variable}_OUTPUT}")
hpx_debug("Compilation output: ${${variable}_OUTPUT}")
endif()

set(_run_msg "Success")
Expand Down Expand Up @@ -450,3 +450,10 @@ macro(hpx_check_for_cxx_experimental_std_optional)
SOURCE cmake/tests/cxx1y_experimental_std_optional.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_mm_prefetch)
add_hpx_config_test(HPX_WITH_MM_PREFECTH
SOURCE cmake/tests/mm_prefetch.cpp
FILE ${ARGN})
endmacro()
17 changes: 17 additions & 0 deletions cmake/tests/mm_prefetch.cpp
@@ -0,0 +1,17 @@
// Copyright (c) 2016 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)

#if defined(_MSC_VER)
#include <intrin.h>
#endif
#if defined(__GNUC__)
#include <emmintrin.h>
#endif

int main()
{
char* p = 0;
_mm_prefetch(p, _MM_HINT_T0);
}
2 changes: 0 additions & 2 deletions docs/manual/build_system/cmake_variables.qbk
Expand Up @@ -39,7 +39,6 @@ The options are split into these categories:
* [link build_system.cmake_variables.HPX_WITH_CUDA HPX_WITH_CUDA]
* [link build_system.cmake_variables.HPX_WITH_CUDA_CLANG HPX_WITH_CUDA_CLANG]
* [link build_system.cmake_variables.HPX_WITH_FORTRAN HPX_WITH_FORTRAN]
* [link build_system.cmake_variables.HPX_WITH_FPGA_QUEUES HPX_WITH_FPGA_QUEUES]
* [link build_system.cmake_variables.HPX_WITH_FULL_RPATH HPX_WITH_FULL_RPATH]
* [link build_system.cmake_variables.HPX_WITH_GCC_VERSION_CHECK HPX_WITH_GCC_VERSION_CHECK]
* [link build_system.cmake_variables.HPX_WITH_GENERIC_CONTEXT_COROUTINES HPX_WITH_GENERIC_CONTEXT_COROUTINES]
Expand Down Expand Up @@ -70,7 +69,6 @@ The options are split into these categories:
[[[#build_system.cmake_variables.HPX_WITH_CUDA] `HPX_WITH_CUDA:BOOL`][Enable CUDA support (default: OFF)]]
[[[#build_system.cmake_variables.HPX_WITH_CUDA_CLANG] `HPX_WITH_CUDA_CLANG:BOOL`][Use clang to compile CUDA code (default: OFF)]]
[[[#build_system.cmake_variables.HPX_WITH_FORTRAN] `HPX_WITH_FORTRAN:BOOL`][Enable or disable the compilation of Fortran examples using HPX]]
[[[#build_system.cmake_variables.HPX_WITH_FPGA_QUEUES] `HPX_WITH_FPGA_QUEUES:BOOL`][Enable special FPGA based queues and schedulers (default: OFF)]]
[[[#build_system.cmake_variables.HPX_WITH_FULL_RPATH] `HPX_WITH_FULL_RPATH:BOOL`][Build and link HPX libraries and executables with full RPATHs (default: ON)]]
[[[#build_system.cmake_variables.HPX_WITH_GCC_VERSION_CHECK] `HPX_WITH_GCC_VERSION_CHECK:BOOL`][Don't ignore version reported by gcc (default: ON)]]
[[[#build_system.cmake_variables.HPX_WITH_GENERIC_CONTEXT_COROUTINES] `HPX_WITH_GENERIC_CONTEXT_COROUTINES:BOOL`][Use Boost.Context as the underlying coroutines context switch implementation.]]
Expand Down
35 changes: 18 additions & 17 deletions hpx/parallel/algorithms/for_each.hpp
Expand Up @@ -46,9 +46,11 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
void operator()(std::size_t /*part_index*/,
Iter part_begin, std::size_t part_size)
{
typedef typename util::detail::loop_n<Iter>::type it_type;

util::loop_n(
part_begin, part_size,
[this](Iter curr) mutable
[this](it_type curr) mutable
{
hpx::util::invoke(
f_, hpx::util::invoke(proj_, *curr));
Expand All @@ -71,16 +73,19 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
sequential(ExPolicy, 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(first, count,
[&f, &proj](InIter curr)
[&f, &proj](it_type curr)
{
hpx::util::invoke(f, hpx::util::invoke(proj, *curr));
});
}

template <typename ExPolicy, typename InIter, typename F,
typename Proj = util::projection_identity>
static typename util::detail::algorithm_result<ExPolicy, InIter>::type
static typename util::detail::algorithm_result<ExPolicy,
InIter>::type
parallel(ExPolicy && policy, InIter first, std::size_t count,
F && f, Proj && proj/* = Proj()*/)
{
Expand Down Expand Up @@ -245,29 +250,23 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)

template <typename ExPolicy, typename InIter, typename F,
typename Proj>
static Iter
static InIter
sequential(ExPolicy, InIter first, InIter last, F && f,
Proj && proj)
{
typedef typename util::detail::loop<InIter>::type it_type;

return util::loop(first, last,
[&f, &proj](Iter curr)
[&f, &proj](it_type curr)
{
f(hpx::util::invoke(proj, *curr));
});
}

template <typename ExPolicy, typename InIter, typename F>
static InIter
sequential(ExPolicy, InIter first, InIter last, F && f,
util::projection_identity)
{
std::for_each(first, last, std::forward<F>(f));
return last;
}

template <typename ExPolicy, typename InIter, typename F,
typename Proj>
static typename util::detail::algorithm_result<ExPolicy, InIter>::type
static typename util::detail::algorithm_result<ExPolicy,
InIter>::type
parallel(ExPolicy && policy, InIter first, InIter last, F && f,
Proj && proj)
{
Expand All @@ -280,7 +279,8 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)

///////////////////////////////////////////////////////////////////////
// non-segmented implementation
template <typename ExPolicy, typename InIter, typename F, typename Proj>
template <typename ExPolicy, typename InIter, typename F,
typename Proj>
inline typename util::detail::algorithm_result<ExPolicy, InIter>::type
for_each_(ExPolicy && policy, InIter first, InIter last, F && f,
Proj && proj, std::false_type)
Expand All @@ -302,7 +302,8 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
}

// forward declare the segmented version of this algorithm
template <typename ExPolicy, typename SegIter, typename F, typename Proj>
template <typename ExPolicy, typename SegIter, typename F,
typename Proj>
inline typename util::detail::algorithm_result<ExPolicy, SegIter>::type
for_each_(ExPolicy && policy, SegIter first, SegIter last, F && f,
Proj && proj, std::true_type);
Expand Down
28 changes: 15 additions & 13 deletions hpx/parallel/util/loop.hpp
Expand Up @@ -8,9 +8,11 @@

#include <hpx/config.hpp>
#include <hpx/parallel/util/cancellation_token.hpp>
#include <hpx/util/tuple.hpp>

#include <algorithm>
#include <iterator>
#include <vector>

namespace hpx { namespace parallel { namespace util
{
Expand All @@ -20,9 +22,11 @@ namespace hpx { namespace parallel { namespace util
///////////////////////////////////////////////////////////////////////
// Helper class to repeatedly call a function starting from a given
// iterator position.
template <typename IterCat>
template <typename Iterator>
struct loop
{
typedef Iterator type;

///////////////////////////////////////////////////////////////////
template <typename Begin, typename End, typename F>
HPX_HOST_DEVICE
Expand Down Expand Up @@ -55,26 +59,26 @@ namespace hpx { namespace parallel { namespace util
HPX_HOST_DEVICE HPX_FORCEINLINE Begin
loop(Begin begin, End end, F && f)
{
typedef typename std::iterator_traits<Begin>::iterator_category cat;
return detail::loop<cat>::call(begin, end, std::forward<F>(f));
return detail::loop<Begin>::call(begin, end, std::forward<F>(f));
}

template <typename Begin, typename End, typename CancelToken, typename F>
HPX_HOST_DEVICE HPX_FORCEINLINE Begin
loop(Begin begin, End end, CancelToken& tok, F && f)
{
typedef typename std::iterator_traits<Begin>::iterator_category cat;
return detail::loop<cat>::call(begin, end, tok, std::forward<F>(f));
};
return detail::loop<Begin>::call(begin, end, tok, std::forward<F>(f));
}

///////////////////////////////////////////////////////////////////////////
namespace detail
{
// Helper class to repeatedly call a function a given number of times
// starting from a given iterator position.
template <typename IterCat>

template <typename Iterator>
struct loop_n
{
typedef Iterator type;

///////////////////////////////////////////////////////////////////
// handle sequences of non-futures
template <typename Iter, typename F>
Expand Down Expand Up @@ -107,17 +111,15 @@ namespace hpx { namespace parallel { namespace util
HPX_HOST_DEVICE HPX_FORCEINLINE Iter
loop_n(Iter it, std::size_t count, F && f)
{
typedef typename std::iterator_traits<Iter>::iterator_category cat;
return detail::loop_n<cat>::call(it, count, std::forward<F>(f));
return detail::loop_n<Iter>::call(it, count, std::forward<F>(f));
}

template <typename Iter, typename CancelToken, typename F>
HPX_HOST_DEVICE HPX_FORCEINLINE Iter
loop_n(Iter it, std::size_t count, CancelToken& tok, F && f)
{
typedef typename std::iterator_traits<Iter>::iterator_category cat;
return detail::loop_n<cat>::call(it, count, tok, std::forward<F>(f));
};
return detail::loop_n<Iter>::call(it, count, tok, std::forward<F>(f));
}

///////////////////////////////////////////////////////////////////////////
namespace detail
Expand Down

0 comments on commit eab1171

Please sign in to comment.