Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement make_integer_sequence in terms of intrinsics whenever possible #2384

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions libcudacxx/include/cuda/std/__utility/integer_sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,26 @@ template <class _IdxType, _IdxType... _Values>
struct __integer_sequence
{
template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType>
using __convert = _ToIndexSeq<_ToIndexType, _Values...>;
using __convert _LIBCUDACXX_NODEBUG_TYPE = _ToIndexSeq<_ToIndexType, _Values...>;

template <size_t _Sp>
using __to_tuple_indices = __tuple_indices<(_Values + _Sp)...>;
using __to_tuple_indices _LIBCUDACXX_NODEBUG_TYPE = __tuple_indices<(_Values + _Sp)...>;
};

#ifndef _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
#if defined(_LIBCUDACXX_HAS_MAKE_INTEGER_SEQ)

template <size_t _Ep, size_t _Sp>
using __make_indices_imp _LIBCUDACXX_NODEBUG_TYPE =
typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template __to_tuple_indices<_Sp>;

#elif defined(_LIBCUDACXX_HAS_INTEGER_PACK) // ^^^ _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ ^^^
// vvv _LIBCUDACXX_HAS_INTEGER_PACK vvv
Comment on lines +48 to +49
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conventionally, we do not add those to elif branches, because it is clear what is coming next.

It is a bit inconsistent insofar we do not know what was before and I am open to suggestion whether we want to completely skip it or add a // ^^^ What is above ^^^ comment


template <size_t _Ep, size_t _Sp>
using __make_indices_imp _LIBCUDACXX_NODEBUG_TYPE =
typename __integer_sequence<size_t, __integer_pack(_Ep - _Sp)...>::template __to_tuple_indices<_Sp>;

#else // ^^^ _LIBCUDACXX_HAS_INTEGER_PACK ^^^ / vvv !_LIBCUDACXX_HAS_INTEGER_PACK vvv

namespace __detail
{
Expand All @@ -65,6 +78,7 @@ struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...>

template <size_t _Np>
struct __parity;

template <size_t _Np>
struct __make : __parity<_Np % 8>::template __pmake<_Np>
{};
Expand Down Expand Up @@ -170,15 +184,9 @@ struct __parity<7>

} // namespace __detail

#endif // !_LIBCUDACXX_HAS_MAKE_INTEGER_SEQ

#ifdef _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
template <size_t _Ep, size_t _Sp>
using __make_indices_imp =
typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template __to_tuple_indices<_Sp>;
#else
template <size_t _Ep, size_t _Sp>
using __make_indices_imp = typename __detail::__make<_Ep - _Sp>::type::template __to_tuple_indices<_Sp>;
using __make_indices_imp _LIBCUDACXX_NODEBUG_TYPE =
typename __detail::__make<_Ep - _Sp>::type::template __to_tuple_indices<_Sp>;

#endif

Expand All @@ -201,7 +209,13 @@ using index_sequence = integer_sequence<size_t, _Ip...>;
template <class _Tp, _Tp _Ep>
using __make_integer_sequence _LIBCUDACXX_NODEBUG_TYPE = __make_integer_seq<integer_sequence, _Tp, _Ep>;

#else // _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
#elif defined(_LIBCUDACXX_HAS_INTEGER_PACK) // ^^^ _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ ^^^
// vvv _LIBCUDACXX_HAS_INTEGER_PACK vvv

template <class _Tp, _Tp _Ep>
using __make_integer_sequence _LIBCUDACXX_NODEBUG_TYPE = integer_sequence<_Tp, __integer_pack(_Ep)...>;

#else // ^^^ _LIBCUDACXX_HAS_INTEGER_PACK ^^^ / vvv !_LIBCUDACXX_HAS_INTEGER_PACK vvv

template <typename _Tp, _Tp _Np>
using __make_integer_sequence_unchecked _LIBCUDACXX_NODEBUG_TYPE =
Expand Down
13 changes: 11 additions & 2 deletions libcudacxx/include/cuda/std/detail/libcxx/include/__config
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,17 @@ typedef unsigned int char32_t;
# define _LIBCUDACXX_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
# endif

# if __check_builtin(make_integer_seq) && !defined(_LIBCUDACXX_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
# define _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
# if !defined(_LIBCUDACXX_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
# if __check_builtin(make_integer_seq)
# define _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
# elif defined(_CCCL_COMPILER_MSVC)
# if _CCCL_MSVC_VERSION_FULL >= 190023918
# define _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
# endif
# endif
# if __check_builtin(integer_pack)
# define _LIBCUDACXX_HAS_INTEGER_PACK
# endif
# endif

# ifdef _LIBCUDACXX_DEBUG
Expand Down
Loading