Skip to content

Commit

Permalink
Merge pull request #2382 from gentryx/datapar_zip_iterator
Browse files Browse the repository at this point in the history
add LibFlatArray-based backend for datapar
  • Loading branch information
hkaiser committed Nov 4, 2016
2 parents 0321463 + bfad6f5 commit bdf4455
Show file tree
Hide file tree
Showing 11 changed files with 334 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Expand Up @@ -4,7 +4,7 @@
# Copyright (c) 2011 Bryce Lelbach
# Copyright (c) 2011 Vinay C Amatya
# Copyright (c) 2013 Jeroen Habraken
# Copyright (c) 2014 Andreas Schaefer
# Copyright (c) 2014-2016 Andreas Schaefer
#
# 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)
Expand Down Expand Up @@ -243,6 +243,8 @@ hpx_option(HPX_WITH_SYCL BOOL
################################################################################
# HPX datapar configuration
################################################################################
hpx_option(HPX_WITH_DATAPAR_LIBFLATARRAY BOOL
"Enable data parallel algorithm support using the external LibFlatArray (default: OFF)" OFF ADVANCED)
hpx_option(HPX_WITH_DATAPAR_VC BOOL
"Enable data parallel algorithm support using the external Vc library (default: OFF)" OFF ADVANCED)
hpx_option(HPX_WITH_DATAPAR_BOOST_SIMD BOOL
Expand All @@ -251,6 +253,9 @@ if(HPX_WITH_DATAPAR_VC AND HPX_WITH_DATAPAR_BOOST_SIMD)
hpx_error("Please select only one of the supported external vectorization libraries (HPX_WITH_DATAPAR_VC or HPX_WITH_DATAPAR_BOOST_SIMD)")
endif()

if(HPX_WITH_DATAPAR_LIBFLATARRAY)
include(HPX_SetupLibFlatArray)
endif()
if(HPX_WITH_DATAPAR_VC)
include(HPX_SetupVc)
endif()
Expand Down
20 changes: 20 additions & 0 deletions cmake/HPX_SetupLibFlatArray.cmake
@@ -0,0 +1,20 @@
# Copyright (c) 2016 Hartmut Kaiser
# Copyright (c) 2016 Andreas Schaefer
#
# 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)

# Locate LibFlatArray ( http://libgeodecomp.org/libflatarray.html )
#
find_package(libflatarray NO_MODULE)
if(NOT libflatarray_FOUND)
hpx_error("LibFlatArray was not found while datapar support was requested. Set LIBFLATARRAY_ROOT to the installation path of LibFlatArray")
endif()

if(libflatarray_FOUND)
include_directories(SYSTEM ${libflatarray_INCLUDE_DIRS})

hpx_add_config_define(HPX_HAVE_DATAPAR)
hpx_add_config_define(HPX_HAVE_DATAPAR_LIBFLATARRAY)
endif()

27 changes: 27 additions & 0 deletions hpx/parallel/traits/detail/libflatarray/fake_accessor.hpp
@@ -0,0 +1,27 @@
// Copyright (c) 2016 Andreas Schaefer
//
// 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(HPX_PARALLEL_TRAITS_LIBFLATARRAY_FAKE_ACCESSOR)
#define HPX_PARALLEL_TRAITS_LIBFLATARRAY_FAKE_ACCESSOR

#include <hpx/config.hpp>

#if defined(HPX_HAVE_DATAPAR_LIBFLATARRAY)

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace parallel { namespace traits
{
///////////////////////////////////////////////////////////////////////////
struct fake_accessor
{
public:
static const int DIM_PROD = 1;
typedef char element_type;
};
}}}

#endif
#endif

116 changes: 116 additions & 0 deletions hpx/parallel/traits/detail/libflatarray/vector_pack_alignment_size.hpp
@@ -0,0 +1,116 @@
// Copyright (c) 2016 Hartmut Kaiser
// Copyright (c) 2016 Andreas Schaefer
////
// 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(HPX_PARALLEL_TRAITS_VECTOR_PACK_ALIGNMENT_SIZE_LIBFLATARRAY_SEP_29_2016_0905PM)
#define HPX_PARALLEL_TRAITS_VECTOR_PACK_ALIGNMENT_SIZE_LIBFLATARRAY_SEP_29_2016_0905PM

#include <hpx/config.hpp>

#if defined(HPX_HAVE_DATAPAR_LIBFLATARRAY)
#include <hpx/parallel/traits/detail/libflatarray/fake_accessor.hpp>
#include <hpx/util/detail/pack.hpp>
#include <hpx/util/tuple.hpp>

#include <cstddef>
#include <type_traits>

#include <libflatarray/flat_array.hpp>

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace parallel { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename T, std::size_t N>
struct is_vector_pack<LibFlatArray::short_vec<T, N> >
: std::true_type
{};

///////////////////////////////////////////////////////////////////////////
template <typename T, std::size_t N>
struct is_scalar_vector_pack<LibFlatArray::short_vec<T, N> >
: std::false_type
{};

template <typename T>
struct is_scalar_vector_pack<LibFlatArray::short_vec<T, 1> >
: std::true_type
{};

///////////////////////////////////////////////////////////////////////////
template <typename T, std::size_t N>
struct is_non_scalar_vector_pack<LibFlatArray::short_vec<T, N> >
: std::true_type
{};

template <typename T>
struct is_non_scalar_vector_pack<LibFlatArray::short_vec<T, 1> >
: std::false_type
{};

///////////////////////////////////////////////////////////////////////////
template <typename T, typename Enable>
struct vector_pack_alignment
{
typedef typename LibFlatArray::estimate_optimum_short_vec_type<T, fake_accessor>::VALUE shortvec;
typedef typename shortvec::strategy strategy;
typedef typename strategy::alignment foo;

static std::size_t const value = foo::ALIGNMENT;
};

template <typename T, std::size_t N>
struct vector_pack_alignment<LibFlatArray::short_vec<T, N> >
{
typedef typename LibFlatArray::short_vec<T, N> shortvec;

static std::size_t const value = shortvec::strategy::alignment::ALIGNMENT;
};

template <typename ... Vector>
struct vector_pack_alignment<hpx::util::tuple<Vector...>,
typename std::enable_if<
hpx::util::detail::all_of<is_vector_pack<Vector>...>::value
>::type>
{
typedef typename hpx::util::tuple_element<
0, hpx::util::tuple<Vector...>
>::type pack_type;

static std::size_t const value = pack_type::alignment;
};

///////////////////////////////////////////////////////////////////////////
template <typename T, typename Enable>
struct vector_pack_size
{
typedef typename LibFlatArray::estimate_optimum_short_vec_type<T, fake_accessor>::VALUE shortvec;

static std::size_t const value = shortvec::ARITY;
};

template <typename T, std::size_t N>
struct vector_pack_size<LibFlatArray::short_vec<T, N> >
{
static std::size_t const value = LibFlatArray::short_vec<T, N>::ARITY;
};

template <typename ... Vector>
struct vector_pack_size<hpx::util::tuple<Vector...>,
typename std::enable_if<
hpx::util::detail::all_of<is_vector_pack<Vector>...>::value
>::type>
{
typedef typename hpx::util::tuple_element<
0, hpx::util::tuple<Vector...>
>::type pack_type;

static std::size_t const value = pack_type::alignment;
};
}}}

#endif
#endif

30 changes: 30 additions & 0 deletions hpx/parallel/traits/detail/libflatarray/vector_pack_count_bits.hpp
@@ -0,0 +1,30 @@
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2016 Andreas Schaefer
//
// 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(HPX_PARALLEL_DATAPAR_LIBFLATARRAY_COUNT_BITS_SEP_22_2016_0220PM)
#define HPX_PARALLEL_DATAPAR_LIBFLATARRAY_COUNT_BITS_SEP_22_2016_0220PM

#include <hpx/config.hpp>

#if defined(HPX_HAVE_DATAPAR_LIBFLATARRAY)
#include <cstddef>

#include <libflatarray/flat_array.hpp>

namespace hpx { namespace parallel { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename T, std::size_t N>
HPX_HOST_DEVICE HPX_FORCEINLINE std::size_t
count_bits(LibFlatArray::short_vec<T, N>::mask_type const& mask)
{
return LibFlatArray::count_mask<T, N>(mask);
}
}}}

#endif
#endif

91 changes: 91 additions & 0 deletions hpx/parallel/traits/detail/libflatarray/vector_pack_load_store.hpp
@@ -0,0 +1,91 @@
// Copyright (c) 2016 Hartmut Kaiser
// Copyright (c) 2016 Andreas Schaefer
//
// 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(HPX_PARALLEL_TRAITS_VECTOR_PACK_LOAD_STORE_LIBFLATARRAY)
#define HPX_PARALLEL_TRAITS_VECTOR_PACK_LOAD_STORE_LIBFLATARRAY

#include <hpx/parallel/traits/detail/libflatarray/fake_accessor.hpp>

#if defined(HPX_HAVE_DATAPAR_LIBFLATARRAY)
#include <hpx/util/tuple.hpp>
#include <hpx/util/tuple.hpp>

#include <cstddef>
#include <iterator>
#include <memory>

#include <libflatarray/flat_array.hpp>

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace parallel { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename T, typename NewT>
struct rebind_pack
{
typedef typename LibFlatArray::estimate_optimum_short_vec_type<T, fake_accessor>::VALUE type;
};

template <typename T, std::size_t N, typename NewT>
struct rebind_pack<LibFlatArray::short_vec<T, N>, NewT>
{
typedef typename LibFlatArray::estimate_optimum_short_vec_type<NewT, fake_accessor>::VALUE type;
};

///////////////////////////////////////////////////////////////////////////
template <typename V, typename Enable>
struct vector_pack_load
{
template <typename Iter>
static typename rebind_pack<
V, typename std::iterator_traits<Iter>::value_type
>::type
aligned(Iter const& iter)
{
typedef typename rebind_pack<
V, typename std::iterator_traits<Iter>::value_type
>::type vector_pack_type;

return vector_pack_type(
std::addressof(*iter));
}

template <typename Iter>
static typename rebind_pack<
V, typename std::iterator_traits<Iter>::value_type
>::type
unaligned(Iter const& iter)
{
typedef typename rebind_pack<
V, typename std::iterator_traits<Iter>::value_type
>::type vector_pack_type;

vector_pack_type v;
v.load_aligned(std::addressof(*iter));
return v;
}
};

///////////////////////////////////////////////////////////////////////////
template <typename V, typename Enable>
struct vector_pack_store
{
template <typename Iter_>
static void aligned(V const& value, Iter_ const& iter)
{
value.store(std::addressof(*iter));
}

template <typename Iter_>
static void unaligned(V const& value, Iter_ const& iter)
{
value.store_aligned(std::addressof(*iter));
}
};
}}}

#endif
#endif
40 changes: 40 additions & 0 deletions hpx/parallel/traits/detail/libflatarray/vector_pack_type.hpp
@@ -0,0 +1,40 @@
// Copyright (c) 2016 Hartmut Kaiser
// Copyright (c) 2016 Andreas Schaefer
//
// 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(HPX_PARALLEL_TRAITS_VECTOR_PACK_TYPE_LIBFLATARRAY)
#define HPX_PARALLEL_TRAITS_VECTOR_PACK_TYPE_LIBFLATARRAY

#include <hpx/config.hpp>

#if defined(HPX_HAVE_DATAPAR_LIBFLATARRAY)
#include <hpx/util/tuple.hpp>
#include <hpx/parallel/traits/detail/libflatarray/fake_accessor.hpp>

#include <cstddef>

#include <libflatarray/flat_array.hpp>

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace parallel { namespace traits
{
template <typename T,
std::size_t N = LibFlatArray::estimate_optimum_short_vec_type<T, fake_accessor>::VALUE::ARITY,
typename Abi = void>
struct vector_pack_type
{
typedef LibFlatArray::short_vec<T, N> type;
};

template <typename ... T, std::size_t N>
struct vector_pack_type<hpx::util::tuple<T...>, N, void>
{
typedef hpx::util::tuple<LibFlatArray::short_vec<T, N>...> type;
};
}}}

#endif
#endif

1 change: 1 addition & 0 deletions hpx/parallel/traits/vector_pack_alignment_size.hpp
Expand Up @@ -33,6 +33,7 @@ namespace hpx { namespace parallel { namespace traits

#include <hpx/parallel/traits/detail/vc/vector_pack_alignment_size.hpp>
#include <hpx/parallel/traits/detail/boost_simd/vector_pack_alignment_size.hpp>
#include <hpx/parallel/traits/detail/libflatarray/vector_pack_alignment_size.hpp>

#endif
#endif
Expand Down
1 change: 1 addition & 0 deletions hpx/parallel/traits/vector_pack_count_bits.hpp
Expand Up @@ -24,6 +24,7 @@ namespace hpx { namespace parallel { namespace traits

#include <hpx/parallel/traits/detail/vc/vector_pack_count_bits.hpp>
#include <hpx/parallel/traits/detail/boost_simd/vector_pack_count_bits.hpp>
#include <hpx/parallel/traits/detail/libflatarray/vector_pack_count_bits.hpp>

#endif
#endif
Expand Down
1 change: 1 addition & 0 deletions hpx/parallel/traits/vector_pack_load_store.hpp
Expand Up @@ -27,6 +27,7 @@ namespace hpx { namespace parallel { namespace traits

#include <hpx/parallel/traits/detail/vc/vector_pack_load_store.hpp>
#include <hpx/parallel/traits/detail/boost_simd/vector_pack_load_store.hpp>
#include <hpx/parallel/traits/detail/libflatarray/vector_pack_load_store.hpp>

#endif
#endif
Expand Down
1 change: 1 addition & 0 deletions hpx/parallel/traits/vector_pack_type.hpp
Expand Up @@ -22,6 +22,7 @@ namespace hpx { namespace parallel { namespace traits

#include <hpx/parallel/traits/detail/vc/vector_pack_type.hpp>
#include <hpx/parallel/traits/detail/boost_simd/vector_pack_type.hpp>
#include <hpx/parallel/traits/detail/libflatarray/vector_pack_type.hpp>

#endif
#endif
Expand Down

0 comments on commit bdf4455

Please sign in to comment.