Skip to content

Commit

Permalink
use integer_pack, make_integer_seq and type_pack_e
Browse files Browse the repository at this point in the history
We were already using __make_integer_seq, incorporate the __integer_pack
code from the concepts refactor branch and add cases for intel, nvcc and
pgi to be able to use one or more of these intrinsics as well.  It turns
out EDG supports __make_integer_seq and __integer_pack, but only when configured some
certain way.  NVCC supports both, with the clang builtin supported only
when clang is selected as a host compiler and __integer_pack supported
only in version 10+ and only with a g++ >= 8 selected as host compiler.
Both of PGI and Intel seem to do something similar, supporting only
__integer_pack, and only when their targeted compiler and libstdc++ is
8+.  I have yet to try XL, but that's next.
  • Loading branch information
trws committed Jul 15, 2020
1 parent 092e1f8 commit b3be1a2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
33 changes: 31 additions & 2 deletions include/camp/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,39 @@ namespace camp
#define CAMP_HAVE_OMP_OFFLOAD 1
#endif

#if defined(__has_builtin)
#if __has_builtin(__make_integer_seq)
// This works for clang, nvcc 10 and higher using clang as a host compiler
#define CAMP_USE_MAKE_INTEGER_SEQ 0
#define CAMP_USE_TYPE_PACK_ELEMENT 0
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 191125507
// __has_builtin exists but does not always expose this
#undef CAMP_USE_MAKE_INTEGER_SEQ
#define CAMP_USE_MAKE_INTEGER_SEQ 1
#undef CAMP_USE_TYPE_PACK_ELEMENT
#define CAMP_USE_TYPE_PACK_ELEMENT 1
#elif defined(__has_builtin)
#if __has_builtin(__make_integer_seq) && ((!defined(__NVCC__) || __CUDACC_VER_MAJOR >= 10))
#undef CAMP_USE_MAKE_INTEGER_SEQ
#define CAMP_USE_MAKE_INTEGER_SEQ 1
#undef CAMP_USE_TYPE_PACK_ELEMENT
#define CAMP_USE_TYPE_PACK_ELEMENT 1
#endif
#endif

// This works for:
// GCC >= 8
// intel 19+ in GCC 8 or higher mode
// nvcc 10+ in GCC 8 or higher mode
// PGI 19+ in GCC 8 or higher mode
#if __GNUC__ >= 8 && (\
/* intel compiler in gcc 8+ mode */ \
((!defined(__INTEL_COMPILER)) || __INTEL_COMPILER >= 1900) \
/* nvcc in gcc 8+ mode */ \
||((!defined(__NVCC__)) || __CUDACC_VER_MAJOR >= 10) \
||((!defined(__PGIC__)) || __PGIC__ >= 19) \
)
#define CAMP_USE_INTEGER_PACK 1
#else
#define CAMP_USE_INTEGER_PACK 0
#endif

// libstdc++ from GCC below version 5 lacks the type trait
Expand Down
12 changes: 10 additions & 2 deletions include/camp/list/at.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ namespace camp

namespace detail
{
template <typename T, idx_t Idx>
struct _at;

#if CAMP_USE_TYPE_PACK_ELEMENT
template <idx_t Idx, template <class...> class T, typename... Pack>
struct _at<T<Pack...>, Idx> {
using type = __type_pack_element<Idx, Pack...>;
};
#else
// Lookup from metal::at machinery
template <idx_t, typename>
struct entry {
Expand All @@ -45,8 +54,6 @@ namespace detail
: decltype(_lookup_impl<Idx>(declptr<entries<indices, vals>>())) {
};

template <typename T, idx_t Idx>
struct _at;
template <template <class...> class T, typename X, typename... Rest>
struct _at<T<X, Rest...>, 0> {
using type = X;
Expand All @@ -65,6 +72,7 @@ namespace detail
make_idx_seq_t<sizeof...(Rest)>,
Idx>::type;
};
#endif
} // namespace detail

// TODO: document
Expand Down
7 changes: 6 additions & 1 deletion include/camp/number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ namespace detail
{
template <typename T, typename N>
struct gen_seq;
#if defined(CAMP_USE_MAKE_INTEGER_SEQ) && !__NVCC__
#if CAMP_USE_MAKE_INTEGER_SEQ
template <typename T, T N>
struct gen_seq<T, integral_constant<T, N>> {
using type = __make_integer_seq<int_seq, T, N>;
};
#elif CAMP_USE_INTEGER_PACK
template <typename T, T N>
struct gen_seq<T, integral_constant<T, N>> {
using type = int_seq<T, __integer_pack(N)...>;
};
#else
template <typename T, typename S1, typename S2>
struct concat;
Expand Down

0 comments on commit b3be1a2

Please sign in to comment.