| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
|
|
|
|
| #ifndef _CG_INFO_H_
|
| #define _CG_INFO_H_
|
| |
| |
|
|
| #define _CG_VERSION 1000
|
|
|
| |
| |
|
|
| #ifndef _CG_ABI_VERSION
|
| # define _CG_ABI_VERSION 1
|
| #endif
|
|
|
| |
| |
| |
|
|
| #if defined(_CG_ABI_EXPERIMENTAL)
|
| #endif
|
|
|
| #define _CG_CONCAT_INNER(x, y) x ## y
|
| #define _CG_CONCAT_OUTER(x, y) _CG_CONCAT_INNER(x, y)
|
| #define _CG_NAMESPACE _CG_CONCAT_OUTER(__v, _CG_ABI_VERSION)
|
|
|
| #define _CG_BEGIN_NAMESPACE \
|
| namespace cooperative_groups { namespace _CG_NAMESPACE {
|
| #define _CG_END_NAMESPACE \
|
| }; using namespace _CG_NAMESPACE; };
|
|
|
| #if (defined(__cplusplus) && (__cplusplus >= 201103L)) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
|
| # define _CG_CPP11_FEATURES
|
| #endif
|
|
|
| #if !defined(_CG_QUALIFIER)
|
| # define _CG_QUALIFIER __forceinline__ __device__
|
| #endif
|
| #if !defined(_CG_STATIC_QUALIFIER)
|
| # define _CG_STATIC_QUALIFIER static __forceinline__ __device__
|
| #endif
|
| #if !defined(_CG_CONSTEXPR_QUALIFIER)
|
| # if defined(_CG_CPP11_FEATURES)
|
| # define _CG_CONSTEXPR_QUALIFIER constexpr __forceinline__ __device__
|
| # else
|
| # define _CG_CONSTEXPR_QUALIFIER _CG_QUALIFIER
|
| # endif
|
| #endif
|
| #if !defined(_CG_STATIC_CONSTEXPR_QUALIFIER)
|
| # if defined(_CG_CPP11_FEATURES)
|
| # define _CG_STATIC_CONSTEXPR_QUALIFIER static constexpr __forceinline__ __device__
|
| # else
|
| # define _CG_STATIC_CONSTEXPR_QUALIFIER _CG_STATIC_QUALIFIER
|
| # endif
|
| #endif
|
|
|
| #if defined(_MSC_VER)
|
| # define _CG_DEPRECATED __declspec(deprecated)
|
| #else
|
| # define _CG_DEPRECATED __attribute__((deprecated))
|
| #endif
|
|
|
| #if (__CUDA_ARCH__ >= 600) || !defined(__CUDA_ARCH__)
|
| # define _CG_HAS_GRID_GROUP
|
| #endif
|
| #if (__CUDA_ARCH__ >= 600) || !defined(__CUDA_ARCH__)
|
| # define _CG_HAS_MULTI_GRID_GROUP
|
| #endif
|
| #if (__CUDA_ARCH__ >= 700) || !defined(__CUDA_ARCH__)
|
| # define _CG_HAS_MATCH_COLLECTIVE
|
| #endif
|
|
|
| #if (__CUDA_ARCH__ >= 800) || !defined(__CUDA_ARCH__) && (defined(__NVCC__) || defined(__CUDACC_RTC__))
|
| # define _CG_HAS_OP_REDUX
|
| #endif
|
|
|
| #if ((__CUDA_ARCH__ >= 800) || !defined(__CUDA_ARCH__)) && !defined(_CG_USER_PROVIDED_SHARED_MEMORY)
|
| # define _CG_HAS_RESERVED_SHARED
|
| #endif
|
|
|
| #if ((__CUDA_ARCH__ >= 900) || !defined(__CUDA_ARCH__)) && \
|
| (defined(__NVCC__) || defined(__CUDACC_RTC__) || defined(_CG_CLUSTER_INTRINSICS_AVAILABLE)) && \
|
| defined(_CG_CPP11_FEATURES)
|
| # define _CG_HAS_CLUSTER_GROUP
|
| #endif
|
|
|
| #if (__CUDA_ARCH__ >= 900) || !defined(__CUDA_ARCH__)
|
| # define _CG_HAS_INSTR_ELECT
|
| #endif
|
|
|
|
|
|
|
|
|
| #ifdef __CUDA_FP16_TYPES_EXIST__
|
| # define _CG_HAS_FP16_COLLECTIVE
|
| #endif
|
|
|
|
|
| #if defined(_CG_CPP11_FEATURES) && !defined(__QNX__) && !defined(__ibmxl__) && \
|
| (defined(__NVCC__) || defined(__CUDACC_RTC__)) && \
|
| (defined(__x86_64__) || defined(__aarch64__) || defined(__ppc64__)|| defined(_M_X64) || defined(_M_ARM64)) && \
|
| (defined(_MSC_VER) || defined(__GNUC__) || defined(__clang__))
|
| # define _CG_USE_CUDA_STL
|
| #else
|
| # define _CG_USE_OWN_TRAITS
|
| #endif
|
|
|
| #if defined(_CG_USE_CUDA_STL) && (!defined(__CUDA_ARCH__) || \
|
| ((!defined(_MSC_VER) && __CUDA_ARCH__ >= 600) || (defined(_MSC_VER) && __CUDA_ARCH__ >= 700)))
|
| # define _CG_HAS_STL_ATOMICS
|
| #endif
|
|
|
| #ifdef _CG_CPP11_FEATURES
|
|
|
| # if defined(_CG_USE_CUDA_STL)
|
| # define _CG_STL_NAMESPACE cuda::std
|
| # include <cuda/std/type_traits>
|
|
|
| # else
|
| # define _CG_STL_NAMESPACE cooperative_groups::details::templates
|
| # endif
|
| #endif
|
|
|
| #ifdef _CG_CPP11_FEATURES
|
| # define _CG_STATIC_CONST_DECL static constexpr
|
| # define _CG_CONST_DECL constexpr
|
| #else
|
| # define _CG_STATIC_CONST_DECL static const
|
| # define _CG_CONST_DECL const
|
| #endif
|
|
|
| #if (defined(_MSC_VER) && !defined(_WIN64)) || defined(__arm__)
|
| # define _CG_ASM_PTR_CONSTRAINT "r"
|
| #else
|
| # define _CG_ASM_PTR_CONSTRAINT "l"
|
| #endif
|
|
|
| |
| |
| |
|
|
| #if defined(__CUDACC_DEBUG__) && defined(CG_DEBUG) && !defined(NDEBUG)
|
| # define _CG_DEBUG
|
| #endif
|
|
|
| #if defined(_CG_DEBUG)
|
| # include <assert.h>
|
| # define _CG_ASSERT(x) assert((x));
|
| # define _CG_ABORT() assert(0);
|
| #else
|
| # define _CG_ASSERT(x)
|
| # define _CG_ABORT() __trap();
|
| #endif
|
|
|
| _CG_BEGIN_NAMESPACE
|
|
|
| namespace details {
|
| _CG_STATIC_CONST_DECL unsigned int default_max_block_size = 1024;
|
|
|
| #if defined(_CG_CPP11_FEATURES) && !defined(_CG_USE_CUDA_STL)
|
| namespace templates {
|
|
|
| |
| |
|
|
| template <typename Ty, Ty Val>
|
| struct integral_constant {
|
| static constexpr Ty value = Val;
|
| typedef Ty type;
|
|
|
| _CG_QUALIFIER constexpr operator type() const noexcept { return value; }
|
| _CG_QUALIFIER constexpr type operator()() const noexcept { return value; }
|
| };
|
|
|
| typedef integral_constant<bool, true> true_type;
|
| typedef integral_constant<bool, false> false_type;
|
|
|
| |
| |
|
|
| template <class Ty> struct is_lvalue_reference : public details::templates::false_type {};
|
| template <class Ty> struct is_lvalue_reference<Ty&> : public details::templates::true_type {};
|
|
|
| template <class Ty> struct remove_reference {typedef Ty type;};
|
| template <class Ty> struct remove_reference<Ty&> {typedef Ty type;};
|
| template <class Ty> struct remove_reference<Ty&&> {typedef Ty type;};
|
|
|
| template <class Ty>
|
| using remove_reference_t = typename details::templates::remove_reference<Ty>::type;
|
|
|
| template <class Ty> struct remove_const {typedef Ty type;};
|
| template <class Ty> struct remove_const<const Ty> {typedef Ty type;};
|
|
|
| template <class Ty> struct remove_volatile {typedef Ty type;};
|
| template <class Ty> struct remove_volatile<volatile Ty> {typedef Ty type;};
|
|
|
| template <class Ty> struct remove_cv {typedef typename details::templates::remove_volatile<typename details::templates::remove_const<Ty>::type>::type type;};
|
|
|
| template <class Ty>
|
| using remove_cv_t = typename details::templates::remove_cv<Ty>::type;
|
|
|
| template <class Ty>
|
| _CG_QUALIFIER Ty&& forward(remove_reference_t<Ty> &t) noexcept {
|
| return static_cast<Ty&&>(t);
|
| }
|
|
|
| template <class Ty>
|
| _CG_QUALIFIER Ty&& forward(remove_reference_t<Ty> &&t) noexcept {
|
| static_assert(!details::templates::is_lvalue_reference<Ty>::value, "Forwarding an rvalue as an lvalue is not allowed.");
|
| return static_cast<Ty&&>(t);
|
| }
|
|
|
| |
| |
|
|
| template <class Ty> struct _is_integral : public details::templates::false_type {};
|
| template <> struct _is_integral<bool> : public details::templates::true_type {};
|
| template <> struct _is_integral<char> : public details::templates::true_type {};
|
| template <> struct _is_integral<unsigned char> : public details::templates::true_type {};
|
| template <> struct _is_integral<short> : public details::templates::true_type {};
|
| template <> struct _is_integral<unsigned short> : public details::templates::true_type {};
|
| template <> struct _is_integral<int> : public details::templates::true_type {};
|
| template <> struct _is_integral<unsigned int> : public details::templates::true_type {};
|
| template <> struct _is_integral<long> : public details::templates::true_type {};
|
| template <> struct _is_integral<long long> : public details::templates::true_type {};
|
| template <> struct _is_integral<unsigned long> : public details::templates::true_type {};
|
| template <> struct _is_integral<unsigned long long> : public details::templates::true_type {};
|
|
|
|
|
| template <typename Ty>
|
| struct is_integral : public details::templates::_is_integral<typename details::templates::remove_cv<Ty>::type> {};
|
|
|
| |
| |
|
|
| template <class Ty> struct _is_floating_point : public details::templates::false_type {};
|
| template <> struct _is_floating_point<float> : public details::templates::true_type {};
|
| template <> struct _is_floating_point<double> : public details::templates::true_type {};
|
| template <> struct _is_floating_point<long double> : public details::templates::true_type {};
|
| # ifdef __CUDA_FP16_TYPES_EXIST__
|
| template <> struct _is_floating_point<__half> : public details::templates::true_type {};
|
| template <> struct _is_floating_point<__half2> : public details::templates::true_type {};
|
| # endif
|
|
|
|
|
| template <typename Ty>
|
| struct is_floating_point : public details::templates::_is_floating_point<typename details::templates::remove_cv<Ty>::type> {};
|
|
|
| template <class T>
|
| struct is_arithmetic : details::templates::integral_constant<
|
| bool,
|
| details::templates::is_integral<T>::value ||
|
| details::templates::is_floating_point<T>::value> {};
|
|
|
| template <typename Ty, bool = details::templates::is_arithmetic<Ty>::value>
|
| struct _is_unsigned : details::templates::integral_constant<bool, Ty(0) < Ty(-1)> {};
|
|
|
| template <typename Ty>
|
| struct _is_unsigned<Ty,false> : details::templates::false_type {};
|
|
|
| template <typename Ty>
|
| struct is_unsigned : _is_unsigned<typename details::templates::remove_cv<Ty>::type> {};
|
|
|
| template <typename Ty> struct _is_pointer : public details::templates::false_type {};
|
| template <typename Ty> struct _is_pointer<Ty*> : public details::templates::true_type {};
|
|
|
| template <typename Ty>
|
| struct is_pointer : _is_pointer<typename details::templates::remove_cv<Ty>::type> {};
|
|
|
| |
| |
|
|
| template<bool B, class Ty = void>
|
| struct enable_if {};
|
|
|
| template<class Ty>
|
| struct enable_if<true, Ty> { typedef Ty type; };
|
|
|
| template<bool Cond, typename Ty = void>
|
| using enable_if_t = typename details::templates::enable_if<Cond, Ty>::type;
|
|
|
| template<class Ty1, class Ty2>
|
| struct is_same : details::templates::false_type {};
|
|
|
| template<class Ty>
|
| struct is_same<Ty, Ty> : details::templates::true_type {};
|
|
|
| }
|
| #endif
|
|
|
| }
|
| _CG_END_NAMESPACE
|
|
|
|
|
| #endif
|
|
|