diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/common_functions.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/common_functions.h new file mode 100644 index 0000000000000000000000000000000000000000..b7e70950fb51d0d58f8dd99239e6b36ba89c4779 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/common_functions.h @@ -0,0 +1,310 @@ +/* + * Copyright 1993-2021 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/common_functions.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/common_functions.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_COMMON_FUNCTIONS_H__ +#endif + +#if !defined(__COMMON_FUNCTIONS_H__) +#define __COMMON_FUNCTIONS_H__ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__cplusplus) && defined(__CUDACC__) + +#include "builtin_types.h" +#include "host_defines.h" + +#define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported. Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead." + +#ifndef __CUDA_API_VER_MAJOR__ +#define __CUDA_API_VER_MAJOR__ __CUDACC_VER_MAJOR__ +#endif /* __CUDA_API_VER_MAJOR__ */ + +#ifndef __CUDA_API_VER_MINOR__ +#define __CUDA_API_VER_MINOR__ __CUDACC_VER_MINOR__ +#endif /* __CUDA_API_VER_MINOR__ */ + +#if !defined(__CUDACC_RTC__) +#include +#include + +extern "C" +{ +#endif /* !__CUDACC_RTC__ */ +extern _CRTIMP __host__ __device__ __device_builtin__ __cudart_builtin__ clock_t __cdecl clock(void) +#if defined(__QNX__) +asm("clock32") +#endif +__THROW; +extern __host__ __device__ __device_builtin__ __cudart_builtin__ void* __cdecl memset(void*, int, size_t) __THROW; +extern __host__ __device__ __device_builtin__ __cudart_builtin__ void* __cdecl memcpy(void*, const void*, size_t) __THROW; +#if !defined(__CUDACC_RTC__) +} +#endif /* !__CUDACC_RTC__ */ + +#if defined(__CUDA_ARCH__) + +#if defined(__CUDACC_RTC__) +inline __host__ __device__ void* operator new(size_t, void *p) { return p; } +inline __host__ __device__ void* operator new[](size_t, void *p) { return p; } +inline __host__ __device__ void operator delete(void*, void*) { } +inline __host__ __device__ void operator delete[](void*, void*) { } +#else /* !__CUDACC_RTC__ */ +#ifndef __CUDA_INTERNAL_SKIP_CPP_HEADERS__ +#include +#endif + +#if defined (__GNUC__) + +#define STD \ + std:: + +#else /* __GNUC__ */ + +#define STD + +#endif /* __GNUC__ */ + +extern __host__ __device__ __cudart_builtin__ void* __cdecl operator new(STD size_t, void*) throw(); +extern __host__ __device__ __cudart_builtin__ void* __cdecl operator new[](STD size_t, void*) throw(); +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete(void*, void*) throw(); +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete[](void*, void*) throw(); +# if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) || defined(__CUDA_XLC_CPP14__) || defined(__CUDA_ICC_CPP14__) +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete(void*, STD size_t) throw(); +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete[](void*, STD size_t) throw(); +#endif /* __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) || defined(__CUDA_XLC_CPP14__) || defined(__CUDA_ICC_CPP14__) */ +#endif /* __CUDACC_RTC__ */ + +#if !defined(__CUDACC_RTC__) +#include +#include +#endif /* !__CUDACC_RTC__ */ + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +extern "C" +{ +extern +#if !defined(_MSC_VER) || _MSC_VER < 1900 +_CRTIMP +#endif + +#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) && ( (__GLIBC__ < 2) || ( (__GLIBC__ == 2) && (__GLIBC_MINOR__ < 3) ) ) +__host__ __device__ __device_builtin__ __cudart_builtin__ int __cdecl printf(const char*, ...) __THROW; +#else /* newer glibc */ +__host__ __device__ __device_builtin__ __cudart_builtin__ int __cdecl printf(const char*, ...); +#endif /* defined(__GLIBC__) && defined(__GLIBC_MINOR__) && ( (__GLIBC__ < 2) || ( (__GLIBC__ == 2) && (__GLIBC_MINOR__ < 3) ) ) */ + + +extern _CRTIMP __host__ __device__ __cudart_builtin__ void* __cdecl malloc(size_t) __THROW; +extern _CRTIMP __host__ __device__ __cudart_builtin__ void __cdecl free(void*) __THROW; + +#if defined(_MSC_VER) +extern __host__ __device__ __cudart_builtin__ void* __cdecl _alloca(size_t); +#endif + +#if defined(__QNX__) +#undef alloca +#define alloca(__S) __builtin_alloca(__S) +#endif +} +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +#if !defined(__CUDACC_RTC__) +#include +#endif /* !__CUDACC_RTC__ */ + +extern "C" +{ +#if defined(__CUDACC_RTC__) +extern __host__ __device__ void __assertfail(const char * __assertion, + const char *__file, + unsigned int __line, + const char *__function, + size_t charsize); +#elif defined(__APPLE__) +#define __builtin_expect(exp,c) (exp) +extern __host__ __device__ __cudart_builtin__ void __assert_rtn( + const char *, const char *, int, const char *); +#elif defined(__ANDROID__) +extern __host__ __device__ __cudart_builtin__ void __assert2( + const char *, int, const char *, const char *); +#elif defined(__QNX__) +#if !defined(_LIBCPP_VERSION) +namespace std { +#endif +extern __host__ __device__ __cudart_builtin__ void __assert( + const char *, const char *, unsigned int, const char *); +#if !defined(_LIBCPP_VERSION) +} +#endif +#elif defined(__HORIZON__) +extern __host__ __device__ __cudart_builtin__ void __assert_fail( + const char *, const char *, int, const char *); +#elif defined(__GNUC__) +extern __host__ __device__ __cudart_builtin__ void __assert_fail( + const char *, const char *, unsigned int, const char *) + __THROW; +#elif defined(_WIN32) +extern __host__ __device__ __cudart_builtin__ _CRTIMP void __cdecl _wassert( + const wchar_t *, const wchar_t *, unsigned); +#endif +} + +#if defined(__CUDACC_RTC__) +#ifdef NDEBUG +#define assert(e) (static_cast(0)) +#else /* !NDEBUG */ +#define __ASSERT_STR_HELPER(x) #x +#define assert(e) ((e) ? static_cast(0)\ + : __assertfail(__ASSERT_STR_HELPER(e), __FILE__,\ + __LINE__, __PRETTY_FUNCTION__,\ + sizeof(char))) +#endif /* NDEBUG */ +__host__ __device__ void* operator new(size_t); +__host__ __device__ void* operator new[](size_t); +__host__ __device__ void operator delete(void*); +__host__ __device__ void operator delete[](void*); +# if __cplusplus >= 201402L +__host__ __device__ void operator delete(void*, size_t); +__host__ __device__ void operator delete[](void*, size_t); +#endif /* __cplusplus >= 201402L */ + +#if __cplusplus >= 201703L +namespace std { enum class align_val_t : size_t {}; } +__host__ __device__ void* __cdecl operator new(size_t sz, std::align_val_t) noexcept; +__host__ __device__ void* __cdecl operator new[](size_t sz, std::align_val_t) noexcept; +__host__ __device__ void __cdecl operator delete(void* ptr, std::align_val_t) noexcept; +__host__ __device__ void __cdecl operator delete[](void* ptr, std::align_val_t) noexcept; +__host__ __device__ void __cdecl operator delete(void* ptr, size_t, std::align_val_t) noexcept; +__host__ __device__ void __cdecl operator delete[](void* ptr, size_t, std::align_val_t) noexcept; +#endif /* __cplusplus >= 201703L */ + +#else /* !__CUDACC_RTC__ */ +#if defined (__GNUC__) + +#define __NV_GLIBCXX_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) + +#if (__cplusplus >= 201103L) && ((!(defined(__QNX__) && defined(_LIBCPP_VERSION))) || (defined(__QNX__) && __NV_GLIBCXX_VERSION >= 80300)) +#define THROWBADALLOC +#else +#if defined(__ANDROID__) && !defined(_LIBCPP_VERSION) && (defined(__BIONIC__) || __NV_GLIBCXX_VERSION < 40900) +#define THROWBADALLOC +#else +#define THROWBADALLOC throw(STD bad_alloc) +#endif +#endif +#define __DELETE_THROW throw() + +#undef __NV_GLIBCXX_VERSION + +#else /* __GNUC__ */ + +#define THROWBADALLOC throw(...) + +#endif /* __GNUC__ */ + +extern __host__ __device__ __cudart_builtin__ void* __cdecl operator new(STD size_t) THROWBADALLOC; +extern __host__ __device__ __cudart_builtin__ void* __cdecl operator new[](STD size_t) THROWBADALLOC; +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete(void*) throw(); +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete[](void*) throw(); +# if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) || defined(__CUDA_XLC_CPP14__) || defined(__CUDA_ICC_CPP14__) +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete(void*, STD size_t) throw(); +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete[](void*, STD size_t) throw(); +#endif /* __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) || defined(__CUDA_XLC_CPP14__) || defined(__CUDA_ICC_CPP14__) */ + +#if __cpp_aligned_new +extern __host__ __device__ __cudart_builtin__ void* __cdecl operator new(STD size_t, std::align_val_t); +extern __host__ __device__ __cudart_builtin__ void* __cdecl operator new[](STD size_t, std::align_val_t); +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete(void*, std::align_val_t) noexcept; +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete[](void*, std::align_val_t) noexcept; +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete(void*, STD size_t, std::align_val_t) noexcept; +extern __host__ __device__ __cudart_builtin__ void __cdecl operator delete[](void*, STD size_t, std::align_val_t) noexcept; +#endif /* __cpp_aligned_new */ + +#undef THROWBADALLOC +#undef STD +#endif /* __CUDACC_RTC__ */ + +#endif /* __CUDA_ARCH__ */ + +#endif /* __cplusplus && __CUDACC__ */ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__CUDACC_RTC__) && (__CUDA_ARCH__ >= 350) +#include "cuda_device_runtime_api.h" +#endif + +#include "math_functions.h" + +#endif /* !__COMMON_FUNCTIONS_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_COMMON_FUNCTIONS_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_COMMON_FUNCTIONS_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/cudacc_ext.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/cudacc_ext.h new file mode 100644 index 0000000000000000000000000000000000000000..8d244463e73f0f7569a4707002c8e059bca67c6d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/cudacc_ext.h @@ -0,0 +1,64 @@ +/* + * Copyright 2021-2021 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/cudacc_ext.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/cudacc_ext.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_CUDACC_EXT_H__ +#endif + + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_CUDACC_EXT_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_CUDACC_EXT_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_double_functions.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_double_functions.h new file mode 100644 index 0000000000000000000000000000000000000000..f03e54581b59e9232cb47ec2fe390d1ad47375ae --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_double_functions.h @@ -0,0 +1,1186 @@ +/* + * Copyright 1993-2021 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/device_double_functions.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/device_double_functions.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_DOUBLE_FUNCTIONS_H__ +#endif + +#if !defined(__DEVICE_DOUBLE_FUNCTIONS_H__) +#define __DEVICE_DOUBLE_FUNCTIONS_H__ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__cplusplus) && defined(__CUDACC__) + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__CUDACC_RTC__) +#define __DEVICE_DOUBLE_FUNCTIONS_DECL__ __device__ +#else +#define __DEVICE_DOUBLE_FUNCTIONS_DECL__ static __inline__ __device__ +#endif /* __CUDACC_RTC__ */ + +#include "builtin_types.h" +#include "device_types.h" +#include "host_defines.h" + +extern "C" +{ +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Reinterpret bits in a double as a 64-bit signed integer. + * + * Reinterpret the bits in the double-precision floating-point value \p x + * as a signed 64-bit integer. + * \return Returns reinterpreted value. + */ +extern __device__ __device_builtin__ long long int __double_as_longlong(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Reinterpret bits in a 64-bit signed integer as a double. + * + * Reinterpret the bits in the 64-bit signed integer value \p x as + * a double-precision floating-point value. + * \return Returns reinterpreted value. + */ +extern __device__ __device_builtin__ double __longlong_as_double(long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Compute + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation in round-to-nearest-even mode. + * + * Computes the value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single ternary operation, rounding the + * result once in round-to-nearest-even mode. + * + * \return Returns the rounded value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * - fmaf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf(\p x, \p y, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * . + * - fmaf(\p x, \p y, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * + * \endxmlonly + * . + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ double __fma_rn(double x, double y, double z); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Compute + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation in round-towards-zero mode. + * + * Computes the value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single ternary operation, rounding the + * result once in round-towards-zero mode. + * + * \return Returns the rounded value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * - fmaf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf(\p x, \p y, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * . + * - fmaf(\p x, \p y, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * + * \endxmlonly + * . + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ double __fma_rz(double x, double y, double z); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Compute + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation in round-up mode. + * + * Computes the value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single ternary operation, rounding the + * result once in round-up (to positive infinity) mode. + * + * \return Returns the rounded value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * - fmaf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf(\p x, \p y, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * . + * - fmaf(\p x, \p y, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * + * \endxmlonly + * . + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ double __fma_ru(double x, double y, double z); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Compute + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation in round-down mode. + * + * Computes the value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single ternary operation, rounding the + * result once in round-down (to negative infinity) mode. + * + * \return Returns the rounded value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * - fmaf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf(\p x, \p y, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * . + * - fmaf(\p x, \p y, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * + * \endxmlonly + * . + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ double __fma_rd(double x, double y, double z); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Add two floating-point values in round-to-nearest-even mode. + * + * Adds two floating-point values \p x and \p y in round-to-nearest-even mode. + * + * \return Returns \p x + \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dadd_rn(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Add two floating-point values in round-towards-zero mode. + * + * Adds two floating-point values \p x and \p y in round-towards-zero mode. + * + * \return Returns \p x + \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dadd_rz(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Add two floating-point values in round-up mode. + * + * Adds two floating-point values \p x and \p y in round-up (to positive infinity) mode. + * + * \return Returns \p x + \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dadd_ru(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Add two floating-point values in round-down mode. + * + * Adds two floating-point values \p x and \p y in round-down (to negative infinity) mode. + * + * \return Returns \p x + \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dadd_rd(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Subtract two floating-point values in round-to-nearest-even mode. + * + * Subtracts two floating-point values \p x and \p y in round-to-nearest-even mode. + * + * \return Returns \p x - \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dsub_rn(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Subtract two floating-point values in round-towards-zero mode. + * + * Subtracts two floating-point values \p x and \p y in round-towards-zero mode. + * + * \return Returns \p x - \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dsub_rz(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Subtract two floating-point values in round-up mode. + * + * Subtracts two floating-point values \p x and \p y in round-up (to positive infinity) mode. + * + * \return Returns \p x - \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dsub_ru(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Subtract two floating-point values in round-down mode. + * + * Subtracts two floating-point values \p x and \p y in round-down (to negative infinity) mode. + * + * \return Returns \p x - \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dsub_rd(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Multiply two floating-point values in round-to-nearest-even mode. + * + * Multiplies two floating-point values \p x and \p y in round-to-nearest-even mode. + * + * \return Returns \p x * \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dmul_rn(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Multiply two floating-point values in round-towards-zero mode. + * + * Multiplies two floating-point values \p x and \p y in round-towards-zero mode. + * + * \return Returns \p x * \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dmul_rz(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Multiply two floating-point values in round-up mode. + * + * Multiplies two floating-point values \p x and \p y in round-up (to positive infinity) mode. + * + * \return Returns \p x * \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dmul_ru(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_DOUBLE + * \brief Multiply two floating-point values in round-down mode. + * + * Multiplies two floating-point values \p x and \p y in round-down (to negative infinity) mode. + * + * \return Returns \p x * \p y. + * + * \note_accuracy_double + * \note_nofma + */ +extern __device__ __device_builtin__ double __dmul_rd(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a float in round-to-nearest-even mode. + * + * Convert the double-precision floating-point value \p x to a single-precision + * floating-point value in round-to-nearest-even mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ float __double2float_rn(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a float in round-towards-zero mode. + * + * Convert the double-precision floating-point value \p x to a single-precision + * floating-point value in round-towards-zero mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ float __double2float_rz(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a float in round-up mode. + * + * Convert the double-precision floating-point value \p x to a single-precision + * floating-point value in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ float __double2float_ru(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a float in round-down mode. + * + * Convert the double-precision floating-point value \p x to a single-precision + * floating-point value in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ float __double2float_rd(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a signed int in round-to-nearest-even mode. + * + * Convert the double-precision floating-point value \p x to a + * signed integer value in round-to-nearest-even mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ int __double2int_rn(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a signed int in round-up mode. + * + * Convert the double-precision floating-point value \p x to a + * signed integer value in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ int __double2int_ru(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a signed int in round-down mode. + * + * Convert the double-precision floating-point value \p x to a + * signed integer value in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ int __double2int_rd(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to an unsigned int in round-to-nearest-even mode. + * + * Convert the double-precision floating-point value \p x to an + * unsigned integer value in round-to-nearest-even mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ unsigned int __double2uint_rn(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to an unsigned int in round-up mode. + * + * Convert the double-precision floating-point value \p x to an + * unsigned integer value in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ unsigned int __double2uint_ru(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to an unsigned int in round-down mode. + * + * Convert the double-precision floating-point value \p x to an + * unsigned integer value in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ unsigned int __double2uint_rd(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a signed 64-bit int in round-to-nearest-even mode. + * + * Convert the double-precision floating-point value \p x to a + * signed 64-bit integer value in round-to-nearest-even mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ long long int __double2ll_rn(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a signed 64-bit int in round-up mode. + * + * Convert the double-precision floating-point value \p x to a + * signed 64-bit integer value in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ long long int __double2ll_ru(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a signed 64-bit int in round-down mode. + * + * Convert the double-precision floating-point value \p x to a + * signed 64-bit integer value in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ long long int __double2ll_rd(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to an unsigned 64-bit int in round-to-nearest-even mode. + * + * Convert the double-precision floating-point value \p x to an + * unsigned 64-bit integer value in round-to-nearest-even mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ unsigned long long int __double2ull_rn(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to an unsigned 64-bit int in round-up mode. + * + * Convert the double-precision floating-point value \p x to an + * unsigned 64-bit integer value in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ unsigned long long int __double2ull_ru(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to an unsigned 64-bit int in round-down mode. + * + * Convert the double-precision floating-point value \p x to an + * unsigned 64-bit integer value in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ unsigned long long int __double2ull_rd(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed int to a double. + * + * Convert the signed integer value \p x to a double-precision floating-point value. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ double __int2double_rn(int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned int to a double. + * + * Convert the unsigned integer value \p x to a double-precision floating-point value. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ double __uint2double_rn(unsigned int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed 64-bit int to a double in round-to-nearest-even mode. + * + * Convert the signed 64-bit integer value \p x to a double-precision floating-point + * value in round-to-nearest-even mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ double __ll2double_rn(long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed 64-bit int to a double in round-towards-zero mode. + * + * Convert the signed 64-bit integer value \p x to a double-precision floating-point + * value in round-towards-zero mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ double __ll2double_rz(long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed 64-bit int to a double in round-up mode. + * + * Convert the signed 64-bit integer value \p x to a double-precision floating-point + * value in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ double __ll2double_ru(long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed 64-bit int to a double in round-down mode. + * + * Convert the signed 64-bit integer value \p x to a double-precision floating-point + * value in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ double __ll2double_rd(long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned 64-bit int to a double in round-to-nearest-even mode. + * + * Convert the unsigned 64-bit integer value \p x to a double-precision floating-point + * value in round-to-nearest-even mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ double __ull2double_rn(unsigned long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned 64-bit int to a double in round-towards-zero mode. + * + * Convert the unsigned 64-bit integer value \p x to a double-precision floating-point + * value in round-towards-zero mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ double __ull2double_rz(unsigned long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned 64-bit int to a double in round-up mode. + * + * Convert the unsigned 64-bit integer value \p x to a double-precision floating-point + * value in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ double __ull2double_ru(unsigned long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned 64-bit int to a double in round-down mode. + * + * Convert the unsigned 64-bit integer value \p x to a double-precision floating-point + * value in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +extern __device__ __device_builtin__ double __ull2double_rd(unsigned long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Reinterpret high 32 bits in a double as a signed integer. + * + * Reinterpret the high 32 bits in the double-precision floating-point value \p x + * as a signed integer. + * \return Returns reinterpreted value. + */ +extern __device__ __device_builtin__ int __double2hiint(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Reinterpret low 32 bits in a double as a signed integer. + * + * Reinterpret the low 32 bits in the double-precision floating-point value \p x + * as a signed integer. + * \return Returns reinterpreted value. + */ +extern __device__ __device_builtin__ int __double2loint(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Reinterpret high and low 32-bit integer values as a double. + * + * Reinterpret the integer value of \p hi as the high 32 bits of a + * double-precision floating-point value and the integer value of \p lo + * as the low 32 bits of the same double-precision floating-point value. + * \return Returns reinterpreted value. + */ +extern __device__ __device_builtin__ double __hiloint2double(int hi, int lo); +} + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double fma(double a, double b, double c, enum cudaRoundMode mode); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double dmul(double a, double b, enum cudaRoundMode mode = cudaRoundNearest); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double dadd(double a, double b, enum cudaRoundMode mode = cudaRoundNearest); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double dsub(double a, double b, enum cudaRoundMode mode = cudaRoundNearest); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ int double2int(double a, enum cudaRoundMode mode = cudaRoundZero); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ unsigned int double2uint(double a, enum cudaRoundMode mode = cudaRoundZero); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ long long int double2ll(double a, enum cudaRoundMode mode = cudaRoundZero); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ unsigned long long int double2ull(double a, enum cudaRoundMode mode = cudaRoundZero); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double ll2double(long long int a, enum cudaRoundMode mode = cudaRoundNearest); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double ull2double(unsigned long long int a, enum cudaRoundMode mode = cudaRoundNearest); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double int2double(int a, enum cudaRoundMode mode = cudaRoundNearest); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double uint2double(unsigned int a, enum cudaRoundMode mode = cudaRoundNearest); + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double float2double(float a, enum cudaRoundMode mode = cudaRoundNearest); + +#undef __DEVICE_DOUBLE_FUNCTIONS_DECL__ + +#endif /* __cplusplus && __CUDACC__ */ + +#if !defined(__CUDACC_RTC__) +#include "device_double_functions.hpp" +#endif /* !__CUDACC_RTC__ */ + +#endif /* !__DEVICE_DOUBLE_FUNCTIONS_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_DOUBLE_FUNCTIONS_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_DOUBLE_FUNCTIONS_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_double_functions.hpp b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_double_functions.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f63063689d65c4a1dffb9a823ddaf6a5b353cba3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_double_functions.hpp @@ -0,0 +1,197 @@ +/* + * Copyright 1993-2017 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/device_double_functions.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/device_double_functions.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_DOUBLE_FUNCTIONS_HPP__ +#endif + +#if !defined(__DEVICE_DOUBLE_FUNCTIONS_HPP__) +#define __DEVICE_DOUBLE_FUNCTIONS_HPP__ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__cplusplus) && defined(__CUDACC__) + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__CUDACC_RTC__) +#define __DEVICE_DOUBLE_FUNCTIONS_DECL__ __device__ +#else +#define __DEVICE_DOUBLE_FUNCTIONS_DECL__ static __inline__ __device__ +#endif /* __CUDACC_RTC__ */ + +#include "builtin_types.h" +#include "device_types.h" +#include "host_defines.h" + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double fma(double a, double b, double c, enum cudaRoundMode mode) +{ + return mode == cudaRoundZero ? __fma_rz(a, b, c) : + mode == cudaRoundPosInf ? __fma_ru(a, b, c) : + mode == cudaRoundMinInf ? __fma_rd(a, b, c) : + __fma_rn(a, b, c); +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double dmul(double a, double b, enum cudaRoundMode mode) +{ + return mode == cudaRoundZero ? __dmul_rz(a, b) : + mode == cudaRoundPosInf ? __dmul_ru(a, b) : + mode == cudaRoundMinInf ? __dmul_rd(a, b) : + __dmul_rn(a, b); +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double dadd(double a, double b, enum cudaRoundMode mode) +{ + return mode == cudaRoundZero ? __dadd_rz(a, b) : + mode == cudaRoundPosInf ? __dadd_ru(a, b) : + mode == cudaRoundMinInf ? __dadd_rd(a, b) : + __dadd_rn(a, b); +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double dsub(double a, double b, enum cudaRoundMode mode) +{ + return mode == cudaRoundZero ? __dsub_rz(a, b) : + mode == cudaRoundPosInf ? __dsub_ru(a, b) : + mode == cudaRoundMinInf ? __dsub_rd(a, b) : + __dsub_rn(a, b); +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ int double2int(double a, enum cudaRoundMode mode) +{ + return mode == cudaRoundNearest ? __double2int_rn(a) : + mode == cudaRoundPosInf ? __double2int_ru(a) : + mode == cudaRoundMinInf ? __double2int_rd(a) : + __double2int_rz(a); +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ unsigned int double2uint(double a, enum cudaRoundMode mode) +{ + return mode == cudaRoundNearest ? __double2uint_rn(a) : + mode == cudaRoundPosInf ? __double2uint_ru(a) : + mode == cudaRoundMinInf ? __double2uint_rd(a) : + __double2uint_rz(a); +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ long long int double2ll(double a, enum cudaRoundMode mode) +{ + return mode == cudaRoundNearest ? __double2ll_rn(a) : + mode == cudaRoundPosInf ? __double2ll_ru(a) : + mode == cudaRoundMinInf ? __double2ll_rd(a) : + __double2ll_rz(a); +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ unsigned long long int double2ull(double a, enum cudaRoundMode mode) +{ + return mode == cudaRoundNearest ? __double2ull_rn(a) : + mode == cudaRoundPosInf ? __double2ull_ru(a) : + mode == cudaRoundMinInf ? __double2ull_rd(a) : + __double2ull_rz(a); +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double ll2double(long long int a, enum cudaRoundMode mode) +{ + return mode == cudaRoundZero ? __ll2double_rz(a) : + mode == cudaRoundPosInf ? __ll2double_ru(a) : + mode == cudaRoundMinInf ? __ll2double_rd(a) : + __ll2double_rn(a); +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double ull2double(unsigned long long int a, enum cudaRoundMode mode) +{ + return mode == cudaRoundZero ? __ull2double_rz(a) : + mode == cudaRoundPosInf ? __ull2double_ru(a) : + mode == cudaRoundMinInf ? __ull2double_rd(a) : + __ull2double_rn(a); +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double int2double(int a, enum cudaRoundMode mode) +{ + return (double)a; +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double uint2double(unsigned int a, enum cudaRoundMode mode) +{ + return (double)a; +} + +__DEVICE_DOUBLE_FUNCTIONS_DECL__ double float2double(float a, enum cudaRoundMode mode) +{ + return (double)a; +} + +#undef __DEVICE_DOUBLE_FUNCTIONS_DECL__ + +#endif /* __cplusplus && __CUDACC__ */ + +#endif /* !__DEVICE_DOUBLE_FUNCTIONS_HPP__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_DOUBLE_FUNCTIONS_HPP__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_DOUBLE_FUNCTIONS_HPP__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_functions.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_functions.h new file mode 100644 index 0000000000000000000000000000000000000000..420a94ebe6122511b26f1057eca94243fdc9fc1e --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_functions.h @@ -0,0 +1,3645 @@ +/* + * Copyright 1993-2022 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/device_functions.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/device_functions.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_FUNCTIONS_H__ +#endif + +#if !defined(__DEVICE_FUNCTIONS_H__) +#define __DEVICE_FUNCTIONS_H__ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__cplusplus) && defined(__CUDACC__) + +#if defined(__CUDACC_RTC__) +#define __DEVICE_FUNCTIONS_DECL__ __device__ __cudart_builtin__ +#define __DEVICE_FUNCTIONS_STATIC_DECL__ __device__ __cudart_builtin__ +#define __DEVICE_HOST_FUNCTIONS_STATIC_DECL__ __device__ __host__ __cudart_builtin__ +#else +#define __DEVICE_FUNCTIONS_DECL__ __device__ __cudart_builtin__ +#define __DEVICE_FUNCTIONS_STATIC_DECL__ static __inline__ __device__ __cudart_builtin__ +#define __DEVICE_HOST_FUNCTIONS_STATIC_DECL__ static __inline__ __device__ __host__ __cudart_builtin__ +#endif /* __CUDACC_RTC__ */ + +#include "builtin_types.h" +#include "device_types.h" +#include "host_defines.h" + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +extern "C" +{ +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Calculate the most significant 32 bits of the product of the two 32-bit integers. + * + * Calculate the most significant 32 bits of the 64-bit product \p x * \p y, where \p x and \p y + * are 32-bit integers. + * + * \return Returns the most significant 32 bits of the product \p x * \p y. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __mulhi(int x, int y); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Calculate the most significant 32 bits of the product of the two 32-bit unsigned integers. + * + * Calculate the most significant 32 bits of the 64-bit product \p x * \p y, where \p x and \p y + * are 32-bit unsigned integers. + * + * \return Returns the most significant 32 bits of the product \p x * \p y. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __umulhi(unsigned int x, unsigned int y); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Calculate the most significant 64 bits of the product of the two 64-bit integers. + * + * Calculate the most significant 64 bits of the 128-bit product \p x * \p y, where \p x and \p y + * are 64-bit integers. + * + * \return Returns the most significant 64 bits of the product \p x * \p y. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int __mul64hi(long long int x, long long int y); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Calculate the most significant 64 bits of the product of the two 64 unsigned bit integers. + * + * Calculate the most significant 64 bits of the 128-bit product \p x * \p y, where \p x and \p y + * are 64-bit unsigned integers. + * + * \return Returns the most significant 64 bits of the product \p x * \p y. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned long long int __umul64hi(unsigned long long int x, unsigned long long int y); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Reinterpret bits in an integer as a float. + * + * Reinterpret the bits in the signed integer value \p x as a single-precision + * floating-point value. + * \return Returns reinterpreted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __int_as_float(int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Reinterpret bits in a float as a signed integer. + * + * Reinterpret the bits in the single-precision floating-point value \p x + * as a signed integer. + * \return Returns reinterpreted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __float_as_int(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Reinterpret bits in an unsigned integer as a float. + * + * Reinterpret the bits in the unsigned integer value \p x as a single-precision + * floating-point value. + * \return Returns reinterpreted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __uint_as_float(unsigned int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Reinterpret bits in a float as a unsigned integer. + * + * Reinterpret the bits in the single-precision floating-point value \p x + * as a unsigned integer. + * \return Returns reinterpreted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __float_as_uint(float x); +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ void __syncthreads(void); +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ void __prof_trigger(int); +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ void __threadfence(void); +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ void __threadfence_block(void); +__DEVICE_FUNCTIONS_DECL__ +#if defined(__GNUC__) || defined(__CUDACC_RTC__) +__attribute__((__noreturn__)) +#elif defined(_MSC_VER) +__declspec(noreturn) +#endif /* defined(__GNUC__) || defined(__CUDACC_RTC__) */ +__device_builtin__ void __trap(void); +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ void __brkpt(); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Clamp the input argument to [+0.0, 1.0]. + * + * Clamp the input argument \p x to be within the interval [+0.0, 1.0]. + * \return + * - __saturatef(\p x) returns 0 if \p x < 0. + * - __saturatef(\p x) returns 1 if \p x > 1. + * - __saturatef(\p x) returns \p x if + * \latexonly $0 \le x \le 1$ \endlatexonly + * \xmlonly + * + * + * 0 + * ≤ + * x + * ≤ + * 1 + * + * \endxmlonly. + * - __saturatef(NaN) returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __saturatef(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Calculate + * \latexonly $|x - y| + z$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * − + * y + * + * | + * + * + + * z + * + * + * \endxmlonly + * , the sum of absolute difference. + * + * Calculate + * \latexonly $|x - y| + z$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * − + * y + * + * | + * + * + + * z + * + * + * \endxmlonly + * , the 32-bit sum of the third argument \p z plus and the absolute + * value of the difference between the first argument, \p x, and second + * argument, \p y. + * + * Inputs \p x and \p y are signed 32-bit integers, input \p z is + * a 32-bit unsigned integer. + * + * \return Returns + * \latexonly $|x - y| + z$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * − + * y + * + * | + * + * + + * z + * + * \endxmlonly. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __sad(int x, int y, unsigned int z); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Calculate + * \latexonly $|x - y| + z$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * − + * y + * + * | + * + * + + * z + * + * + * \endxmlonly + * , the sum of absolute difference. + * + * Calculate + * \latexonly $|x - y| + z$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * − + * y + * + * | + * + * + + * z + * + * + * \endxmlonly + * , the 32-bit sum of the third argument \p z plus and the absolute + * value of the difference between the first argument, \p x, and second + * argument, \p y. + * + * Inputs \p x, \p y, and \p z are unsigned 32-bit integers. + * + * \return Returns + * \latexonly $|x - y| + z$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * − + * y + * + * | + * + * + + * z + * + * \endxmlonly. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __usad(unsigned int x, unsigned int y, unsigned int z); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Calculate the least significant 32 bits of the product of the least significant 24 bits of two integers. + * + * Calculate the least significant 32 bits of the product of the least significant 24 bits of \p x and \p y. + * The high order 8 bits of \p x and \p y are ignored. + * + * \return Returns the least significant 32 bits of the product \p x * \p y. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __mul24(int x, int y); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Calculate the least significant 32 bits of the product of the least significant 24 bits of two unsigned integers. + * + * Calculate the least significant 32 bits of the product of the least significant 24 bits of \p x and \p y. + * The high order 8 bits of \p x and \p y are ignored. + * + * \return Returns the least significant 32 bits of the product \p x * \p y. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __umul24(unsigned int x, unsigned int y); +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Divide two floating-point values. + * + * Compute \p x divided by \p y. If --use_fast_math is specified, + * use ::__fdividef() for higher performance, otherwise use normal division. + * + * \return Returns \p x / \p y. + * + * \note_accuracy_single + * \note_fastmath + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float fdividef(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Calculate the fast approximate division of the input arguments. + * + * Calculate the fast approximate division of \p x by \p y. + * + * \return Returns \p x / \p y. + * - __fdividef( + * \latexonly $\infty$ \endlatexonly + * \xmlonly + * + * + * ∞ + * + * + * \endxmlonly + * , \p y) returns NaN for + * \latexonly $2^{126} < |y| < 2^{128}$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * + * 126 + * + * + * < + * |y| + * < + * + * 2 + * + * 128 + * + * + * + * \endxmlonly. + * - __fdividef(\p x, \p y) returns 0 for + * \latexonly $2^{126} < |y| < 2^{128}$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * + * 126 + * + * + * < + * |y| + * < + * + * 2 + * + * 128 + * + * + * + * + * \endxmlonly + * and finite + * \latexonly $x$ \endlatexonly + * \xmlonly + * + * + * x + * + * \endxmlonly. + * + * \note_accuracy_single_intrinsic + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fdividef(float x, float y); +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ double fdivide(double x, double y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Calculate the fast approximate sine of the input argument. + * + * Calculate the fast approximate sine of the input argument \p x, measured in radians. + * + * \return Returns the approximate sine of \p x. + * + * \note_accuracy_single_intrinsic + * \note Output in the denormal range is flushed to sign preserving 0.0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ float __sinf(float x) __THROW; +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Calculate the fast approximate cosine of the input argument. + * + * Calculate the fast approximate cosine of the input argument \p x, measured in radians. + * + * \return Returns the approximate cosine of \p x. + * + * \note_accuracy_single_intrinsic + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ float __cosf(float x) __THROW; +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Calculate the fast approximate tangent of the input argument. + * + * Calculate the fast approximate tangent of the input argument \p x, measured in radians. + * + * \return Returns the approximate tangent of \p x. + * + * \note_accuracy_single_intrinsic + * \note The result is computed as the fast divide of ::__sinf() + * by ::__cosf(). Denormal output is flushed to sign-preserving 0.0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ float __tanf(float x) __THROW; +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Calculate the fast approximate of sine and cosine of the first input argument. + * + * Calculate the fast approximate of sine and cosine of the first input argument \p x (measured + * in radians). The results for sine and cosine are written into the second + * argument, \p sptr, and, respectively, third argument, \p cptr. + * + * \return + * - none + * + * \note_accuracy_single_intrinsic + * \note Denorm input/output is flushed to sign preserving 0.0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ void __sincosf(float x, float *sptr, float *cptr) __THROW; +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Calculate the fast approximate base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * exponential of the input argument. + * + * Calculate the fast approximate base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * exponential of the input argument \p x, + * \latexonly $e^x$ \endlatexonly + * \xmlonly + * + * + * + * e + * x + * + * + * \endxmlonly. + * + * \return Returns an approximation to + * \latexonly $e^x$ \endlatexonly + * \xmlonly + * + * + * + * e + * x + * + * + * \endxmlonly. + * + * \note_accuracy_single_intrinsic + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ float __expf(float x) __THROW; +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Calculate the fast approximate base 10 exponential of the input argument. + * + * Calculate the fast approximate base 10 exponential of the input argument \p x, + * \latexonly $10^x$ \endlatexonly + * \xmlonly + * + * + * + * 10 + * x + * + * + * \endxmlonly. + * + * \return Returns an approximation to + * \latexonly $10^x$ \endlatexonly + * \xmlonly + * + * + * + * 10 + * x + * + * + * \endxmlonly. + * + * \note_accuracy_single_intrinsic + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ float __exp10f(float x) __THROW; +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Calculate the fast approximate base 2 logarithm of the input argument. + * + * Calculate the fast approximate base 2 logarithm of the input argument \p x. + * + * \return Returns an approximation to + * \latexonly $\log_2(x)$ \endlatexonly + * \xmlonly + * + * + * + * log + * 2 + * + * ⁡ + * ( + * x + * ) + * + * \endxmlonly. + * + * \note_accuracy_single_intrinsic + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ float __log2f(float x) __THROW; +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Calculate the fast approximate base 10 logarithm of the input argument. + * + * Calculate the fast approximate base 10 logarithm of the input argument \p x. + * + * \return Returns an approximation to + * \latexonly $\log_{10}(x)$ \endlatexonly + * \xmlonly + * + * + * + * log + * + * 10 + * + * + * ⁡ + * ( + * x + * ) + * + * \endxmlonly. + * + * \note_accuracy_single_intrinsic + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ float __log10f(float x) __THROW; +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Calculate the fast approximate base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * logarithm of the input argument. + * + * Calculate the fast approximate base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * logarithm of the input argument \p x. + * + * \return Returns an approximation to + * \latexonly $\log_e(x)$ \endlatexonly + * \xmlonly + * + * + * + * log + * e + * + * ⁡ + * ( + * x + * ) + * + * \endxmlonly. + * + * \note_accuracy_single_intrinsic + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ float __logf(float x) __THROW; +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Calculate the fast approximate of + * \latexonly $x^y$ \endlatexonly + * \xmlonly + * + * + * + * x + * y + * + * + * \endxmlonly. + * + * Calculate the fast approximate of \p x, the first input argument, + * raised to the power of \p y, the second input argument, + * \latexonly $x^y$ \endlatexonly + * \xmlonly + * + * + * + * x + * y + * + * + * \endxmlonly. + * + * \return Returns an approximation to + * \latexonly $x^y$ \endlatexonly + * \xmlonly + * + * + * + * x + * y + * + * + * \endxmlonly. + * + * \note_accuracy_single_intrinsic + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ float __powf(float x, float y) __THROW; +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to a signed integer in round-to-nearest-even mode. + * + * Convert the single-precision floating-point value \p x to a signed integer + * in round-to-nearest-even mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __float2int_rn(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to a signed integer in round-towards-zero mode. + * + * Convert the single-precision floating-point value \p x to a signed integer + * in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __float2int_rz(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to a signed integer in round-up mode. + * + * Convert the single-precision floating-point value \p x to a signed integer + * in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __float2int_ru(float); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to a signed integer in round-down mode. + * + * Convert the single-precision floating-point value \p x to a signed integer + * in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __float2int_rd(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to an unsigned integer in round-to-nearest-even mode. + * + * Convert the single-precision floating-point value \p x to an unsigned integer + * in round-to-nearest-even mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __float2uint_rn(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to an unsigned integer in round-towards-zero mode. + * + * Convert the single-precision floating-point value \p x to an unsigned integer + * in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __float2uint_rz(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to an unsigned integer in round-up mode. + * + * Convert the single-precision floating-point value \p x to an unsigned integer + * in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __float2uint_ru(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to an unsigned integer in round-down mode. + * + * Convert the single-precision floating-point value \p x to an unsigned integer + * in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __float2uint_rd(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed integer to a float in round-to-nearest-even mode. + * + * Convert the signed integer value \p x to a single-precision floating-point value + * in round-to-nearest-even mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __int2float_rn(int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed integer to a float in round-towards-zero mode. + * + * Convert the signed integer value \p x to a single-precision floating-point value + * in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __int2float_rz(int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed integer to a float in round-up mode. + * + * Convert the signed integer value \p x to a single-precision floating-point value + * in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __int2float_ru(int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed integer to a float in round-down mode. + * + * Convert the signed integer value \p x to a single-precision floating-point value + * in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __int2float_rd(int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned integer to a float in round-to-nearest-even mode. + * + * Convert the unsigned integer value \p x to a single-precision floating-point value + * in round-to-nearest-even mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __uint2float_rn(unsigned int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned integer to a float in round-towards-zero mode. + * + * Convert the unsigned integer value \p x to a single-precision floating-point value + * in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __uint2float_rz(unsigned int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned integer to a float in round-up mode. + * + * Convert the unsigned integer value \p x to a single-precision floating-point value + * in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __uint2float_ru(unsigned int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned integer to a float in round-down mode. + * + * Convert the unsigned integer value \p x to a single-precision floating-point value + * in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __uint2float_rd(unsigned int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to a signed 64-bit integer in round-to-nearest-even mode. + * + * Convert the single-precision floating-point value \p x to a signed 64-bit integer + * in round-to-nearest-even mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int __float2ll_rn(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to a signed 64-bit integer in round-towards-zero mode. + * + * Convert the single-precision floating-point value \p x to a signed 64-bit integer + * in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int __float2ll_rz(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to a signed 64-bit integer in round-up mode. + * + * Convert the single-precision floating-point value \p x to a signed 64-bit integer + * in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int __float2ll_ru(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to a signed 64-bit integer in round-down mode. + * + * Convert the single-precision floating-point value \p x to a signed 64-bit integer + * in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int __float2ll_rd(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to an unsigned 64-bit integer in round-to-nearest-even mode. + * + * Convert the single-precision floating-point value \p x to an unsigned 64-bit integer + * in round-to-nearest-even mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned long long int __float2ull_rn(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to an unsigned 64-bit integer in round-towards-zero mode. + * + * Convert the single-precision floating-point value \p x to an unsigned 64-bit integer + * in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned long long int __float2ull_rz(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to an unsigned 64-bit integer in round-up mode. + * + * Convert the single-precision floating-point value \p x to an unsigned 64-bit integer + * in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned long long int __float2ull_ru(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a float to an unsigned 64-bit integer in round-down mode. + * + * Convert the single-precision floating-point value \p x to an unsigned 64-bit integer + * in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned long long int __float2ull_rd(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed 64-bit integer to a float in round-to-nearest-even mode. + * + * Convert the signed 64-bit integer value \p x to a single-precision floating-point value + * in round-to-nearest-even mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __ll2float_rn(long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed integer to a float in round-towards-zero mode. + * + * Convert the signed integer value \p x to a single-precision floating-point value + * in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __ll2float_rz(long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed integer to a float in round-up mode. + * + * Convert the signed integer value \p x to a single-precision floating-point value + * in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __ll2float_ru(long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a signed integer to a float in round-down mode. + * + * Convert the signed integer value \p x to a single-precision floating-point value + * in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __ll2float_rd(long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned integer to a float in round-to-nearest-even mode. + * + * Convert the unsigned integer value \p x to a single-precision floating-point value + * in round-to-nearest-even mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __ull2float_rn(unsigned long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned integer to a float in round-towards-zero mode. + * + * Convert the unsigned integer value \p x to a single-precision floating-point value + * in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __ull2float_rz(unsigned long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned integer to a float in round-up mode. + * + * Convert the unsigned integer value \p x to a single-precision floating-point value + * in round-up (to positive infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __ull2float_ru(unsigned long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert an unsigned integer to a float in round-down mode. + * + * Convert the unsigned integer value \p x to a single-precision floating-point value + * in round-down (to negative infinity) mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __ull2float_rd(unsigned long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Add two floating-point values in round-to-nearest-even mode. + * + * Compute the sum of \p x and \p y in round-to-nearest-even rounding mode. + * + * \return Returns \p x + \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fadd_rn(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Add two floating-point values in round-towards-zero mode. + * + * Compute the sum of \p x and \p y in round-towards-zero mode. + * + * \return Returns \p x + \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fadd_rz(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Add two floating-point values in round-up mode. + * + * Compute the sum of \p x and \p y in round-up (to positive infinity) mode. + * + * \return Returns \p x + \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fadd_ru(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Add two floating-point values in round-down mode. + * + * Compute the sum of \p x and \p y in round-down (to negative infinity) mode. + * + * \return Returns \p x + \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fadd_rd(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Subtract two floating-point values in round-to-nearest-even mode. + * + * Compute the difference of \p x and \p y in round-to-nearest-even rounding mode. + * + * \return Returns \p x - \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fsub_rn(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Subtract two floating-point values in round-towards-zero mode. + * + * Compute the difference of \p x and \p y in round-towards-zero mode. + * + * \return Returns \p x - \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fsub_rz(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Subtract two floating-point values in round-up mode. + * + * Compute the difference of \p x and \p y in round-up (to positive infinity) mode. + * + * \return Returns \p x - \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fsub_ru(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Subtract two floating-point values in round-down mode. + * + * Compute the difference of \p x and \p y in round-down (to negative infinity) mode. + * + * \return Returns \p x - \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fsub_rd(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Multiply two floating-point values in round-to-nearest-even mode. + * + * Compute the product of \p x and \p y in round-to-nearest-even mode. + * + * \return Returns \p x * \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fmul_rn(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Multiply two floating-point values in round-towards-zero mode. + * + * Compute the product of \p x and \p y in round-towards-zero mode. + * + * \return Returns \p x * \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fmul_rz(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Multiply two floating-point values in round-up mode. + * + * Compute the product of \p x and \p y in round-up (to positive infinity) mode. + * + * \return Returns \p x * \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fmul_ru(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Multiply two floating-point values in round-down mode. + * + * Compute the product of \p x and \p y in round-down (to negative infinity) mode. + * + * \return Returns \p x * \p y. + * + * \note_accuracy_single + * \note_nofma + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fmul_rd(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation, in round-to-nearest-even mode. + * + * Computes the value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single ternary operation, rounding the + * result once in round-to-nearest-even mode. + * + * \return Returns the rounded value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * - fmaf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf(\p x, \p y, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - fmaf(\p x, \p y, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fmaf_rn(float x, float y, float z); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation, in round-towards-zero mode. + * + * Computes the value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single ternary operation, rounding the + * result once in round-towards-zero mode. + * + * \return Returns the rounded value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * - fmaf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf(\p x, \p y, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - fmaf(\p x, \p y, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fmaf_rz(float x, float y, float z); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation, in round-up mode. + * + * Computes the value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single ternary operation, rounding the + * result once in round-up (to positive infinity) mode. + * + * \return Returns the rounded value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * - fmaf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf(\p x, \p y, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - fmaf(\p x, \p y, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fmaf_ru(float x, float y, float z); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation, in round-down mode. + * + * Computes the value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single ternary operation, rounding the + * result once in round-down (to negative infinity) mode. + * + * \return Returns the rounded value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * - fmaf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf(\p x, \p y, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - fmaf(\p x, \p y, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fmaf_rd(float x, float y, float z); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $\frac{1}{x}$ \endlatexonly + * \xmlonly + * + * + * + * 1 + * x + * + * + * + * \endxmlonly + * in round-to-nearest-even mode. + * + * Compute the reciprocal of \p x in round-to-nearest-even mode. + * + * \return Returns + * \latexonly $\frac{1}{x}$ \endlatexonly + * \xmlonly + * + * + * + * 1 + * x + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __frcp_rn(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $\frac{1}{x}$ \endlatexonly + * \xmlonly + * + * + * + * 1 + * x + * + * + * + * \endxmlonly + * in round-towards-zero mode. + * + * Compute the reciprocal of \p x in round-towards-zero mode. + * + * \return Returns + * \latexonly $\frac{1}{x}$ \endlatexonly + * \xmlonly + * + * + * + * 1 + * x + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __frcp_rz(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $\frac{1}{x}$ \endlatexonly + * \xmlonly + * + * + * + * 1 + * x + * + * + * + * \endxmlonly + * in round-up mode. + * + * Compute the reciprocal of \p x in round-up (to positive infinity) mode. + * + * \return Returns + * \latexonly $\frac{1}{x}$ \endlatexonly + * \xmlonly + * + * + * + * 1 + * x + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __frcp_ru(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $\frac{1}{x}$ \endlatexonly + * \xmlonly + * + * + * + * 1 + * x + * + * + * + * \endxmlonly + * in round-down mode. + * + * Compute the reciprocal of \p x in round-down (to negative infinity) mode. + * + * \return Returns + * \latexonly $\frac{1}{x}$ \endlatexonly + * \xmlonly + * + * + * + * 1 + * x + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __frcp_rd(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * + * \endxmlonly + * in round-to-nearest-even mode. + * + * Compute the square root of \p x in round-to-nearest-even mode. + * + * \return Returns + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fsqrt_rn(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * + * \endxmlonly + * in round-towards-zero mode. + * + * Compute the square root of \p x in round-towards-zero mode. + * + * \return Returns + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fsqrt_rz(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * + * \endxmlonly + * in round-up mode. + * + * Compute the square root of \p x in round-up (to positive infinity) mode. + * + * \return Returns + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fsqrt_ru(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * + * \endxmlonly + * in round-down mode. + * + * Compute the square root of \p x in round-down (to negative infinity) mode. + * + * \return Returns + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fsqrt_rd(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Compute + * \latexonly $1/\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * 1 + * + * / + * + * + * x + * + * + * + * \endxmlonly + * in round-to-nearest-even mode. + * + * Compute the reciprocal square root of \p x in round-to-nearest-even mode. + * + * \return Returns + * \latexonly $1/\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * 1 + * + * / + * + * + * x + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __frsqrt_rn(float x); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Divide two floating-point values in round-to-nearest-even mode. + * + * Divide two floating-point values \p x by \p y in round-to-nearest-even mode. + * + * \return Returns \p x / \p y. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fdiv_rn(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Divide two floating-point values in round-towards-zero mode. + * + * Divide two floating-point values \p x by \p y in round-towards-zero mode. + * + * \return Returns \p x / \p y. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fdiv_rz(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Divide two floating-point values in round-up mode. + * + * Divide two floating-point values \p x by \p y in round-up (to positive infinity) mode. + * + * \return Returns \p x / \p y. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fdiv_ru(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_SINGLE + * \brief Divide two floating-point values in round-down mode. + * + * Divide two floating-point values \p x by \p y in round-down (to negative infinity) mode. + * + * \return Returns \p x / \p y. + * + * \note_accuracy_single + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __fdiv_rd(float x, float y); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Return the number of consecutive high-order zero bits in a 32-bit integer. + * + * Count the number of consecutive leading zero bits, starting at the most significant bit (bit 31) of \p x. + * + * \return Returns a value between 0 and 32 inclusive representing the number of zero bits. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __clz(int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Find the position of the least significant bit set to 1 in a 32-bit integer. + * + * Find the position of the first (least significant) bit set to 1 in \p x, where the least significant + * bit position is 1. + * + * \return Returns a value between 0 and 32 inclusive representing the position of the first bit set. + * - __ffs(0) returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __ffs(int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Count the number of bits that are set to 1 in a 32-bit integer. + * + * Count the number of bits that are set to 1 in \p x. + * + * \return Returns a value between 0 and 32 inclusive representing the number of set bits. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __popc(unsigned int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Reverse the bit order of a 32-bit unsigned integer. + * + * Reverses the bit order of the 32-bit unsigned integer \p x. + * + * \return Returns the bit-reversed value of \p x. i.e. bit N of the return value corresponds to bit 31-N of \p x. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __brev(unsigned int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Count the number of consecutive high-order zero bits in a 64-bit integer. + * + * Count the number of consecutive leading zero bits, starting at the most significant bit (bit 63) of \p x. + * + * \return Returns a value between 0 and 64 inclusive representing the number of zero bits. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __clzll(long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Find the position of the least significant bit set to 1 in a 64-bit integer. + * + * Find the position of the first (least significant) bit set to 1 in \p x, where the least significant + * bit position is 1. + * + * \return Returns a value between 0 and 64 inclusive representing the position of the first bit set. + * - __ffsll(0) returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __ffsll(long long int x); + + +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Count the number of bits that are set to 1 in a 64-bit integer. + * + * Count the number of bits that are set to 1 in \p x. + * + * \return Returns a value between 0 and 64 inclusive representing the number of set bits. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __popcll(unsigned long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Reverse the bit order of a 64-bit unsigned integer. + * + * Reverses the bit order of the 64-bit unsigned integer \p x. + * + * \return Returns the bit-reversed value of \p x. i.e. bit N of the return value corresponds to bit 63-N of \p x. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned long long int __brevll(unsigned long long int x); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Return selected bytes from two 32-bit unsigned integers. + * + * \return Returns a 32-bit integer consisting of four bytes from eight input bytes provided in the two + * input integers \p x and \p y, as specified by a selector, \p s. + * + * Create 8-byte source + * - uint64_t \p tmp64 = ((uint64_t)\p y << 32) | \p x; + * + * Extract selector bits + * - \p selector0 = (\p s >> 0) & 0x7; + * - \p selector1 = (\p s >> 4) & 0x7; + * - \p selector2 = (\p s >> 8) & 0x7; + * - \p selector3 = (\p s >> 12) & 0x7; + * + * Return 4 selected bytes from 8-byte source: + * - \p res[07:00] = \p tmp64[\p selector0]; + * - \p res[15:08] = \p tmp64[\p selector1]; + * - \p res[23:16] = \p tmp64[\p selector2]; + * - \p res[31:24] = \p tmp64[\p selector3]; + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __byte_perm(unsigned int x, unsigned int y, unsigned int s); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Compute average of signed input arguments, avoiding overflow + * in the intermediate sum. + * + * Compute average of signed input arguments \p x and \p y + * as ( \p x + \p y ) >> 1, avoiding overflow in the intermediate sum. + * + * \return Returns a signed integer value representing the signed + * average value of the two inputs. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __hadd(int x, int y); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Compute rounded average of signed input arguments, avoiding + * overflow in the intermediate sum. + * + * Compute average of signed input arguments \p x and \p y + * as ( \p x + \p y + 1 ) >> 1, avoiding overflow in the intermediate + * sum. + * + * \return Returns a signed integer value representing the signed + * rounded average value of the two inputs. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __rhadd(int x, int y); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Compute average of unsigned input arguments, avoiding overflow + * in the intermediate sum. + * + * Compute average of unsigned input arguments \p x and \p y + * as ( \p x + \p y ) >> 1, avoiding overflow in the intermediate sum. + * + * \return Returns an unsigned integer value representing the unsigned + * average value of the two inputs. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __uhadd(unsigned int x, unsigned int y); +/** + * \ingroup CUDA_MATH_INTRINSIC_INT + * \brief Compute rounded average of unsigned input arguments, avoiding + * overflow in the intermediate sum. + * + * Compute average of unsigned input arguments \p x and \p y + * as ( \p x + \p y + 1 ) >> 1, avoiding overflow in the intermediate + * sum. + * + * \return Returns an unsigned integer value representing the unsigned + * rounded average value of the two inputs. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __urhadd(unsigned int x, unsigned int y); + +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a signed int in round-towards-zero mode. + * + * Convert the double-precision floating-point value \p x to a + * signed integer value in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __double2int_rz(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to an unsigned int in round-towards-zero mode. + * + * Convert the double-precision floating-point value \p x to an + * unsigned integer value in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __double2uint_rz(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to a signed 64-bit int in round-towards-zero mode. + * + * Convert the double-precision floating-point value \p x to a + * signed 64-bit integer value in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int __double2ll_rz(double x); +/** + * \ingroup CUDA_MATH_INTRINSIC_CAST + * \brief Convert a double to an unsigned 64-bit int in round-towards-zero mode. + * + * Convert the double-precision floating-point value \p x to an + * unsigned 64-bit integer value in round-towards-zero mode. + * \return Returns converted value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned long long int __double2ull_rz(double x); +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __pm0(void); +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __pm1(void); +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __pm2(void); +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __pm3(void); + +/******************************************************************************* + * * + * FP16 SIMD functions * + * * + *******************************************************************************/ + + // #include "fp16.h" + + +/******************************************************************************* + * * + * SIMD functions * + * * + *******************************************************************************/ + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-halfword absolute value. + * + * Splits 4 bytes of argument into 2 parts, each consisting of 2 bytes, + * then computes absolute value for each of parts. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vabs2(unsigned int a); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-halfword absolute value with signed saturation. + * + * Splits 4 bytes of argument into 2 parts, each consisting of 2 bytes, + * then computes absolute value with signed saturation for each of parts. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vabsss2(unsigned int a); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword (un)signed addition, with wrap-around: a + b + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes, + * then performs unsigned addition on corresponding parts. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vadd2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword addition with signed saturation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes, + * then performs addition with signed saturation on corresponding parts. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vaddss2 (unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword addition with unsigned saturation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes, + * then performs addition with unsigned saturation on corresponding parts. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vaddus2 (unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword signed rounded average computation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes, + * then computes signed rounded average of corresponding parts. Partial results are + * recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vavgs2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned rounded average computation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes, + * then computes unsigned rounded average of corresponding parts. Partial results are + * recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vavgu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned average computation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes, + * then computes unsigned average of corresponding parts. Partial results are + * recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vhaddu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword (un)signed comparison. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts result is ffff if they are equal, and 0000 otherwise. + * For example __vcmpeq2(0x1234aba5, 0x1234aba6) returns 0xffff0000. + * \return Returns 0xffff computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpeq2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword signed comparison: a >= b ? 0xffff : 0. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts result is ffff if 'a' part >= 'b' part, and 0000 otherwise. + * For example __vcmpges2(0x1234aba5, 0x1234aba6) returns 0xffff0000. + * \return Returns 0xffff if a >= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpges2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned comparison: a >= b ? 0xffff : 0. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts result is ffff if 'a' part >= 'b' part, and 0000 otherwise. + * For example __vcmpgeu2(0x1234aba5, 0x1234aba6) returns 0xffff0000. + * \return Returns 0xffff if a >= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpgeu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword signed comparison: a > b ? 0xffff : 0. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts result is ffff if 'a' part > 'b' part, and 0000 otherwise. + * For example __vcmpgts2(0x1234aba5, 0x1234aba6) returns 0x00000000. + * \return Returns 0xffff if a > b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpgts2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned comparison: a > b ? 0xffff : 0. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts result is ffff if 'a' part > 'b' part, and 0000 otherwise. + * For example __vcmpgtu2(0x1234aba5, 0x1234aba6) returns 0x00000000. + * \return Returns 0xffff if a > b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpgtu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword signed comparison: a <= b ? 0xffff : 0. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts result is ffff if 'a' part <= 'b' part, and 0000 otherwise. + * For example __vcmples2(0x1234aba5, 0x1234aba6) returns 0xffffffff. + * \return Returns 0xffff if a <= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmples2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned comparison: a <= b ? 0xffff : 0. + * + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts result is ffff if 'a' part <= 'b' part, and 0000 otherwise. + * For example __vcmpleu2(0x1234aba5, 0x1234aba6) returns 0xffffffff. + * \return Returns 0xffff if a <= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpleu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword signed comparison: a < b ? 0xffff : 0. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts result is ffff if 'a' part < 'b' part, and 0000 otherwise. + * For example __vcmplts2(0x1234aba5, 0x1234aba6) returns 0x0000ffff. + * \return Returns 0xffff if a < b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmplts2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned comparison: a < b ? 0xffff : 0. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts result is ffff if 'a' part < 'b' part, and 0000 otherwise. + * For example __vcmpltu2(0x1234aba5, 0x1234aba6) returns 0x0000ffff. + * \return Returns 0xffff if a < b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpltu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword (un)signed comparison: a != b ? 0xffff : 0. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts result is ffff if 'a' part != 'b' part, and 0000 otherwise. + * For example __vcmplts2(0x1234aba5, 0x1234aba6) returns 0x0000ffff. + * \return Returns 0xffff if a != b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpne2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword absolute difference of unsigned integer computation: |a - b| + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function computes absolute difference. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vabsdiffu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword signed maximum computation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function computes signed maximum. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vmaxs2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned maximum computation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function computes unsigned maximum. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vmaxu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword signed minimum computation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function computes signed minimum. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vmins2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned minimum computation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function computes unsigned minimum. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vminu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword (un)signed comparison. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs comparison 'a' part == 'b' part. + * If both equalities are satisfied, function returns 1. + * \return Returns 1 if a = b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vseteq2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword signed comparison. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs comparison 'a' part >= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a >= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetges2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned minimum unsigned comparison. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs comparison 'a' part >= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a >= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetgeu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword signed comparison. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs comparison 'a' part > 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a > b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetgts2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned comparison. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs comparison 'a' part > 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a > b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetgtu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned minimum computation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs comparison 'a' part <= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a <= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetles2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword signed comparison. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs comparison 'a' part <= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a <= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetleu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword signed comparison. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs comparison 'a' part <= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a < b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetlts2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword unsigned comparison. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs comparison 'a' part <= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a < b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetltu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword (un)signed comparison. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs comparison 'a' part != 'b' part. + * If both conditions are satisfied, function returns 1. + * \return Returns 1 if a != b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetne2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-halfword sum of abs diff of unsigned. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function computes absolute differences and returns + * sum of those differences. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsadu2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword (un)signed subtraction, with wrap-around. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs subtraction. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsub2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword (un)signed subtraction, with signed saturation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs subtraction with signed saturation. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsubss2 (unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword subtraction with unsigned saturation. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function performs subtraction with unsigned saturation. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsubus2 (unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-halfword negation. + * + * Splits 4 bytes of argument into 2 parts, each consisting of 2 bytes. + * For each part function computes negation. Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vneg2(unsigned int a); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-halfword negation with signed saturation. + * + * Splits 4 bytes of argument into 2 parts, each consisting of 2 bytes. + * For each part function computes negation. Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vnegss2(unsigned int a); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-halfword sum of absolute difference of signed integer. + * + * Splits 4 bytes of each into 2 parts, each consisting of 2 bytes. + * For corresponding parts function computes absolute difference. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vabsdiffs2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword sum of absolute difference of signed. + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * For corresponding parts function computes absolute difference and sum it up. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsads2(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte absolute value. + * + * Splits argument by bytes. Computes absolute value of each byte. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vabs4(unsigned int a); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte absolute value with signed saturation. + * + * Splits 4 bytes of argument into 4 parts, each consisting of 1 byte, + * then computes absolute value with signed saturation for each of parts. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vabsss4(unsigned int a); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte (un)signed addition. + * + * Splits 'a' into 4 bytes, then performs unsigned addition on each of these + * bytes with the corresponding byte from 'b', ignoring overflow. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vadd4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte addition with signed saturation. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte, + * then performs addition with signed saturation on corresponding parts. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vaddss4 (unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte addition with unsigned saturation. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte, + * then performs addition with unsigned saturation on corresponding parts. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vaddus4 (unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte signed rounded average. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * then computes signed rounded average of corresponding parts. Partial results are + * recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vavgs4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte unsigned rounded average. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * then computes unsigned rounded average of corresponding parts. Partial results are + * recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vavgu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte unsigned average. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * then computes unsigned average of corresponding parts. Partial results are + * recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vhaddu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte (un)signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts result is ff if they are equal, and 00 otherwise. + * For example __vcmpeq4(0x1234aba5, 0x1234aba6) returns 0xffffff00. + * \return Returns 0xff if a = b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpeq4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts result is ff if 'a' part >= 'b' part, and 00 otherwise. + * For example __vcmpges4(0x1234aba5, 0x1234aba6) returns 0xffffff00. + * \return Returns 0xff if a >= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpges4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte unsigned comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts result is ff if 'a' part >= 'b' part, and 00 otherwise. + * For example __vcmpgeu4(0x1234aba5, 0x1234aba6) returns 0xffffff00. + * \return Returns 0xff if a = b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpgeu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts result is ff if 'a' part > 'b' part, and 00 otherwise. + * For example __vcmpgts4(0x1234aba5, 0x1234aba6) returns 0x00000000. + * \return Returns 0xff if a > b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpgts4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte unsigned comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts result is ff if 'a' part > 'b' part, and 00 otherwise. + * For example __vcmpgtu4(0x1234aba5, 0x1234aba6) returns 0x00000000. + * \return Returns 0xff if a > b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpgtu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts result is ff if 'a' part <= 'b' part, and 00 otherwise. + * For example __vcmples4(0x1234aba5, 0x1234aba6) returns 0xffffffff. + * \return Returns 0xff if a <= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmples4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte unsigned comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts result is ff if 'a' part <= 'b' part, and 00 otherwise. + * For example __vcmpleu4(0x1234aba5, 0x1234aba6) returns 0xffffffff. + * \return Returns 0xff if a <= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpleu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts result is ff if 'a' part < 'b' part, and 00 otherwise. + * For example __vcmplts4(0x1234aba5, 0x1234aba6) returns 0x000000ff. + * \return Returns 0xff if a < b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmplts4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte unsigned comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts result is ff if 'a' part < 'b' part, and 00 otherwise. + * For example __vcmpltu4(0x1234aba5, 0x1234aba6) returns 0x000000ff. + * \return Returns 0xff if a < b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpltu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte (un)signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts result is ff if 'a' part != 'b' part, and 00 otherwise. + * For example __vcmplts4(0x1234aba5, 0x1234aba6) returns 0x000000ff. + * \return Returns 0xff if a != b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vcmpne4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte absolute difference of unsigned integer. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function computes absolute difference. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vabsdiffu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte signed maximum. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function computes signed maximum. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vmaxs4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte unsigned maximum. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function computes unsigned maximum. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vmaxu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte signed minimum. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function computes signed minimum. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vmins4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte unsigned minimum. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function computes unsigned minimum. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vminu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte (un)signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs comparison 'a' part == 'b' part. + * If both equalities are satisfied, function returns 1. + * \return Returns 1 if a = b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vseteq4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs comparison 'a' part <= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a <= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetles4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte unsigned comparison. + * + * Splits 4 bytes of each argument into 4 part, each consisting of 1 byte. + * For corresponding parts function performs comparison 'a' part <= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a <= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetleu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs comparison 'a' part <= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a < b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetlts4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte unsigned comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs comparison 'a' part <= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a < b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetltu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs comparison 'a' part >= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a >= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetges4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte unsigned comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs comparison 'a' part >= 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a >= b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetgeu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs comparison 'a' part > 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a > b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetgts4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte unsigned comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs comparison 'a' part > 'b' part. + * If both inequalities are satisfied, function returns 1. + * \return Returns 1 if a > b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetgtu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte (un)signed comparison. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs comparison 'a' part != 'b' part. + * If both conditions are satisfied, function returns 1. + * \return Returns 1 if a != b, else returns 0. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsetne4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte sum of abs difference of unsigned. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function computes absolute differences and returns + * sum of those differences. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsadu4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte subtraction. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs subtraction. Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsub4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte subtraction with signed saturation. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs subtraction with signed saturation. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsubss4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte subtraction with unsigned saturation. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function performs subtraction with unsigned saturation. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsubus4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte negation. + * + * Splits 4 bytes of argument into 4 parts, each consisting of 1 byte. + * For each part function computes negation. Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vneg4(unsigned int a); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-byte negation with signed saturation. + * + * Splits 4 bytes of argument into 4 parts, each consisting of 1 byte. + * For each part function computes negation. Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vnegss4(unsigned int a); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte absolute difference of signed integer. + * + * Splits 4 bytes of each into 4 parts, each consisting of 1 byte. + * For corresponding parts function computes absolute difference. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vabsdiffs4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes per-byte sum of abs difference of signed. + * + * Splits 4 bytes of each argument into 4 parts, each consisting of 1 byte. + * For corresponding parts function computes absolute difference and sum it up. + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int __vsads4(unsigned int a, unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(max(a, b), 0) + * + * Calculates the maximum of \p a and \p b of two signed ints, if this is less than \p 0 then \p 0 is returned. + * \return Returns computed value. + */ + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimax_s32_relu(const int a, const int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(max(a, b), 0) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs a max with relu ( = max(a_part, b_part, 0) ). Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimax_s16x2_relu(const unsigned int a, const unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(min(a, b), 0) + * + * Calculates the minimum of \p a and \p b of two signed ints, if this is less than \p 0 then \p 0 is returned. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimin_s32_relu(const int a, const int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(min(a, b), 0) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs a min with relu ( = max(min(a_part, b_part), 0) ). Partial results + * are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimin_s16x2_relu(const unsigned int a, const unsigned int b); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(max(a, b), c) + * + * Calculates the 3-way max of signed integers \p a, \p b and \p c. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimax3_s32(const int a, const int b, const int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(max(a, b), c) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs a 3-way max ( = max(max(a_part, b_part), c_part) ). + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimax3_s16x2(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(max(a, b), c) + * + * Calculates the 3-way max of unsigned integers \p a, \p b and \p c. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimax3_u32(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(max(a, b), c) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as unsigned shorts. + * For corresponding parts function performs a 3-way max ( = max(max(a_part, b_part), c_part) ). + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimax3_u16x2(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes min(min(a, b), c) + * + * Calculates the 3-way min of signed integers \p a, \p b and \p c. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimin3_s32(const int a, const int b, const int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword min(min(a, b), c) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs a 3-way min ( = min(min(a_part, b_part), c_part) ). + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimin3_s16x2(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes min(min(a, b), c) + * + * Calculates the 3-way min of unsigned integers \p a, \p b and \p c. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimin3_u32(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword min(min(a, b), c) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as unsigned shorts. + * For corresponding parts function performs a 3-way min ( = min(min(a_part, b_part), c_part) ). + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimin3_u16x2(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(max(max(a, b), c), 0) + * + * Calculates the maximum of three signed ints, if this is less than \p 0 then \p 0 is returned. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimax3_s32_relu(const int a, const int b, const int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(max(max(a, b), c), 0) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs a three-way max with relu ( = max(a_part, b_part, c_part, 0) ). + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimax3_s16x2_relu(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(min(min(a, b), c), 0) + * + * Calculates the minimum of three signed ints, if this is less than \p 0 then \p 0 is returned. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimin3_s32_relu(const int a, const int b, const int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(min(min(a, b), c), 0) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs a three-way min with relu ( = max(min(a_part, b_part, c_part), 0) ). + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimin3_s16x2_relu(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(a + b, c) + * + * Calculates the sum of signed integers \p a and \p b and takes the max with \p c. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __viaddmax_s32(const int a, const int b, const int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(a + b, c) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs an add and compare: max(a_part + b_part), c_part) + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmax_s16x2(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(a + b, c) + * + * Calculates the sum of unsigned integers \p a and \p b and takes the max with \p c. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmax_u32(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(a + b, c) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as unsigned shorts. + * For corresponding parts function performs an add and compare: max(a_part + b_part), c_part) + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmax_u16x2(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes min(a + b, c) + * + * Calculates the sum of signed integers \p a and \p b and takes the min with \p c. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __viaddmin_s32(const int a, const int b, const int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword min(a + b, c) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs an add and compare: min(a_part + b_part), c_part) + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmin_s16x2(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes min(a + b, c) + * + * Calculates the sum of unsigned integers \p a and \p b and takes the min with \p c. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmin_u32(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword min(a + b, c) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as unsigned shorts. + * For corresponding parts function performs an add and compare: min(a_part + b_part), c_part) + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmin_u16x2(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(max(a + b, c), 0) + * + * Calculates the sum of signed integers \p a and \p b and takes the max with \p c. + * If the result is less than \p 0 then \0 is returned. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __viaddmax_s32_relu(const int a, const int b, const int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(max(a + b, c), 0) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs an add, followed by a max with relu: max(max(a_part + b_part), c_part), 0) + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmax_s16x2_relu(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(min(a + b, c), 0) + * + * Calculates the sum of signed integers \p a and \p b and takes the min with \p c. + * If the result is less than \p 0 then \0 is returned. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __viaddmin_s32_relu(const int a, const int b, const int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(min(a + b, c), 0) + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs an add, followed by a min with relu: max(min(a_part + b_part), c_part), 0) + * Partial results are recombined and returned as unsigned int. + * \return Returns computed value. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmin_s16x2_relu(const unsigned int a, const unsigned int b, const unsigned int c); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(a, b), also sets the value pointed to by pred to (a >= b). + * + * Calculates the maximum of \p a and \p b of two signed ints. Also sets the value pointed to by \p pred to the value (a >= b). + * \return Returns computed values. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vibmax_s32(const int a, const int b, bool* const pred); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes max(a, b), also sets the value pointed to by pred to (a >= b). + * + * Calculates the maximum of \p a and \p b of two unsigned ints. Also sets the value pointed to by \p pred to the value (a >= b). + * \return Returns computed values. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmax_u32(const unsigned int a, const unsigned int b, bool* const pred); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes min(a, b), also sets the value pointed to by pred to (a <= b). + * + * Calculates the minimum of \p a and \p b of two signed ints. Also sets the value pointed to by \p pred to the value (a <= b). + * \return Returns computed values. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vibmin_s32(const int a, const int b, bool* const pred); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Computes min(a, b), also sets the value pointed to by pred to (a <= b). + * + * Calculates the minimum of \p a and \p b of two unsigned ints. Also sets the value pointed to by \p pred to the value (a <= b). + * \return Returns computed values. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmin_u32(const unsigned int a, const unsigned int b, bool* const pred); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(a, b), also sets the value pointed to by pred_hi and pred_lo to the per-halfword result of (a >= b). + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs a maximum ( = max(a_part, b_part) ). + * Partial results are recombined and returned as unsigned int. + * Sets the value pointed to by \p pred_hi to the value (a_high_part >= b_high_part). + * Sets the value pointed to by \p pred_lo to the value (a_low_part >= b_low_part). + * \return Returns computed values. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmax_s16x2(const unsigned int a, const unsigned int b, bool* const pred_hi, bool* const pred_lo); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword max(a, b), also sets the value pointed to by pred_hi and pred_lo to the per-halfword result of (a >= b). + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as unsigned shorts. + * For corresponding parts function performs a maximum ( = max(a_part, b_part) ). + * Partial results are recombined and returned as unsigned int. + * Sets the value pointed to by \p pred_hi to the value (a_high_part >= b_high_part). + * Sets the value pointed to by \p pred_lo to the value (a_low_part >= b_low_part). + * \return Returns computed values. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmax_u16x2(const unsigned int a, const unsigned int b, bool* const pred_hi, bool* const pred_lo); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword min(a, b), also sets the value pointed to by pred_hi and pred_lo to the per-halfword result of (a <= b). + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as signed shorts. + * For corresponding parts function performs a maximum ( = max(a_part, b_part) ). + * Partial results are recombined and returned as unsigned int. + * Sets the value pointed to by \p pred_hi to the value (a_high_part <= b_high_part). + * Sets the value pointed to by \p pred_lo to the value (a_low_part <= b_low_part). + * \return Returns computed values. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmin_s16x2(const unsigned int a, const unsigned int b, bool* const pred_hi, bool* const pred_lo); + +/** + * \ingroup CUDA_MATH_INTRINSIC_SIMD + * \brief Performs per-halfword min(a, b), also sets the value pointed to by pred_hi and pred_lo to the per-halfword result of (a <= b). + * + * Splits 4 bytes of each argument into 2 parts, each consisting of 2 bytes. + * These 2 byte parts are interpreted as unsigned shorts. + * For corresponding parts function performs a maximum ( = max(a_part, b_part) ). + * Partial results are recombined and returned as unsigned int. + * Sets the value pointed to by \p pred_hi to the value (a_high_part <= b_high_part). + * Sets the value pointed to by \p pred_lo to the value (a_low_part <= b_low_part). + * \return Returns computed values. + */ +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmin_u16x2(const unsigned int a, const unsigned int b, bool* const pred_hi, bool* const pred_lo); + +/******************************************************************************* + * * + * END SIMD functions * + * * + *******************************************************************************/ +} //extern "c" + +#undef __DEVICE_FUNCTIONS_DECL__ +#undef __DEVICE_FUNCTIONS_STATIC_DECL__ +#undef __DEVICE_HOST_FUNCTIONS_STATIC_DECL__ + +#endif /* __cplusplus && __CUDACC__ */ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if !defined(__CUDACC_RTC__) +#include "device_functions.hpp" +#endif /* !defined(__CUDACC_RTC__) */ + +#include "device_atomic_functions.h" +#include "device_double_functions.h" +#include "sm_20_atomic_functions.h" +#include "sm_32_atomic_functions.h" +#include "sm_35_atomic_functions.h" +#include "sm_60_atomic_functions.h" +#include "sm_20_intrinsics.h" +#include "sm_30_intrinsics.h" +#include "sm_32_intrinsics.h" +#include "sm_35_intrinsics.h" +#include "sm_61_intrinsics.h" +#include "sm_70_rt.h" +#include "sm_80_rt.h" +#include "sm_90_rt.h" +#include "texture_indirect_functions.h" +#include "surface_indirect_functions.h" +#include "cudacc_ext.h" + +#ifdef __CUDACC__ +extern "C" __host__ __device__ unsigned CUDARTAPI __cudaPushCallConfiguration(dim3 gridDim, + dim3 blockDim, + size_t sharedMem = 0, + struct CUstream_st *stream = 0); +#endif /* __CUDACC__ */ + +#endif /* !__DEVICE_FUNCTIONS_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_FUNCTIONS_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_FUNCTIONS_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_functions.hpp b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_functions.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7f750bb057f34be45f67fd43dfed0611a54a3daa --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/device_functions.hpp @@ -0,0 +1,1178 @@ +/* + * Copyright 1993-2022 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/device_functions.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/device_functions.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_FUNCTIONS_HPP__ +#endif + +#if !defined(__DEVICE_FUNCTIONS_HPP__) +#define __DEVICE_FUNCTIONS_HPP__ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__cplusplus) && defined(__CUDACC__) + +#if defined(__CUDACC_RTC__) +#define __DEVICE_FUNCTIONS_DECL__ __device__ +#define __DEVICE_FUNCTIONS_STATIC_DECL__ __device__ +#define __DEVICE_HOST_FUNCTIONS_STATIC_DECL__ __device__ __host__ __cudart_builtin__ +#else +#define __DEVICE_FUNCTIONS_DECL__ __device__ +#define __DEVICE_FUNCTIONS_STATIC_DECL__ static __inline__ __device__ +#define __DEVICE_HOST_FUNCTIONS_STATIC_DECL__ static __inline__ __device__ __host__ __cudart_builtin__ +#endif /* __CUDACC_RTC__ */ + +#include "builtin_types.h" +#include "device_types.h" +#include "host_defines.h" + +#undef __DEVICE_FUNCTIONS_DECL__ +#undef __DEVICE_FUNCTIONS_STATIC_DECL__ + +#endif /* __cplusplus && __CUDACC__ */ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#ifdef __CUDACC__ +# if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 900) +#define __CUDA_AND_AT_LEAST_SM_90__ +#endif /* defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 900) */ +#endif /* __CUDACC__ */ + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimax_s32_relu(const int a, const int b){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm("{max.s32.relu %0, %1, %2;}" : "=r"(res) : "r"(a), "r"(b)); + return res; +#else + // Host and older architecture code + int ans = max(a, b); + + return (ans > 0) ? ans : 0; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimax_s16x2_relu(const unsigned int a, const unsigned int b){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int res; + asm("{max.s16x2.relu %0, %1, %2;}" : "=r"(res) : "r"(a), "r"(b)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + // Get answer + short ansS_lo = (short)max(aS_lo, bS_lo); + short ansS_hi = (short)max(aS_hi, bS_hi); + + // relu + if(ansS_lo < 0){ ansS_lo = 0; } + if(ansS_hi < 0){ ansS_hi = 0; } + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimin_s32_relu(const int a, const int b){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm("{min.s32.relu %0, %1, %2;}" : "=r"(res) : "r"(a), "r"(b)); + return res; +#else + // Host and older architecture code + int ans = min(a, b); + + return (ans > 0) ? ans : 0; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimin_s16x2_relu(const unsigned int a, const unsigned int b){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int res; + asm("{min.s16x2.relu %0, %1, %2;}" : "=r"(res) : "r"(a), "r"(b)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + // Get answer + short ansS_lo = (short)min(aS_lo, bS_lo); + short ansS_hi = (short)min(aS_hi, bS_hi); + + // relu + if(ansS_lo < 0){ ansS_lo = 0; } + if(ansS_hi < 0){ ansS_hi = 0; } + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimax3_s32(const int a, const int b, const int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .s32 t1; \n\t" + "max.s32 t1, %1, %2; \n\t" + "max.s32 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + return max(max(a, b), c); +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimax3_s16x2(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + // Future asm code (naming/syntax may change): + unsigned int res; + asm ("{.reg .b32 t1; \n\t" + "max.s16x2 t1, %1, %2; \n\t" + "max.s16x2 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + short cS_lo = *(short*)& cU_lo; + short cS_hi = *(short*)& cU_hi; + + // Get answer + short ansS_lo = (short)max(max(aS_lo, bS_lo), cS_lo); + short ansS_hi = (short)max(max(aS_hi, bS_hi), cS_hi); + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimax3_u32(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ +int res; + asm ("{.reg .u32 t1; \n\t" + "max.u32 t1, %1, %2; \n\t" + "max.u32 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + return max(max(a, b), c); +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimax3_u16x2(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .b32 t1; \n\t" + "max.u16x2 t1, %1, %2; \n\t" + "max.u16x2 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + // Get answer + unsigned short ansU_lo = (unsigned short)max(max(aU_lo, bU_lo), cU_lo); + unsigned short ansU_hi = (unsigned short)max(max(aU_hi, bU_hi), cU_hi); + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimin3_s32(const int a, const int b, const int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .s32 t1; \n\t" + "min.s32 t1, %1, %2; \n\t" + "min.s32 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + return min(min(a, b), c); +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimin3_s16x2(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .b32 t1; \n\t" + "min.s16x2 t1, %1, %2; \n\t" + "min.s16x2 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + short cS_lo = *(short*)& cU_lo; + short cS_hi = *(short*)& cU_hi; + + // Get answer + short ansS_lo = (short)min(min(aS_lo, bS_lo), cS_lo); + short ansS_hi = (short)min(min(aS_hi, bS_hi), cS_hi); + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimin3_u32(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .u32 t1; \n\t" + "min.u32 t1, %1, %2; \n\t" + "min.u32 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + return min(min(a, b), c); +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimin3_u16x2(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .b32 t1; \n\t" + "min.u16x2 t1, %1, %2; \n\t" + "min.u16x2 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + // Get answer + unsigned short ansU_lo = (unsigned short)min(min(aU_lo, bU_lo), cU_lo); + unsigned short ansU_hi = (unsigned short)min(min(aU_hi, bU_hi), cU_hi); + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimax3_s32_relu(const int a, const int b, const int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .s32 t1; \n\t" + "max.s32.relu t1, %1, %2; \n\t" + "max.s32.relu %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + int ans = max(max(a, b), c); + + return (ans > 0) ? ans : 0; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimax3_s16x2_relu(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .b32 t1; \n\t" + "max.s16x2.relu t1, %1, %2; \n\t" + "max.s16x2.relu %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + short cS_lo = *(short*)& cU_lo; + short cS_hi = *(short*)& cU_hi; + + // Get answer + short ansS_lo = (short)max(max(aS_lo, bS_lo), cS_lo); + short ansS_hi = (short)max(max(aS_hi, bS_hi), cS_hi); + + // relu + if(ansS_lo < 0){ansS_lo = 0;} + if(ansS_hi < 0){ansS_hi = 0;} + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vimin3_s32_relu(const int a, const int b, const int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .s32 t1; \n\t" + "min.s32.relu t1, %1, %2; \n\t" + "min.s32.relu %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + int ans = min(min(a, b), c); + + return (ans > 0) ? ans : 0; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vimin3_s16x2_relu(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .b32 t1; \n\t" + "min.s16x2.relu t1, %1, %2; \n\t" + "min.s16x2.relu %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + short cS_lo = *(short*)& cU_lo; + short cS_hi = *(short*)& cU_hi; + + // Get answer + short ansS_lo = (short)min(min(aS_lo, bS_lo), cS_lo); + short ansS_hi = (short)min(min(aS_hi, bS_hi), cS_hi); + + // relu + if(ansS_lo < 0){ansS_lo = 0;} + if(ansS_hi < 0){ansS_hi = 0;} + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __viaddmax_s32(const int a, const int b, const int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .s32 t1; \n\t" + "add.s32 t1, %1, %2; \n\t" + "max.s32 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + return max(a + b, c); +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmax_s16x2(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int res; + asm ("{.reg .b32 t1; \n\t" + "add.s16x2 t1, %1, %2; \n\t" + "max.s16x2 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + short cS_lo = *(short*)& cU_lo; + short cS_hi = *(short*)& cU_hi; + + // Get answer + short ansS_lo = (short)max((short)(aS_lo + bS_lo), cS_lo); + short ansS_hi = (short)max((short)(aS_hi + bS_hi), cS_hi); + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmax_u32(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int res; + asm ("{.reg .u32 t1; \n\t" + "add.u32 t1, %1, %2; \n\t" + "max.u32 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + return max(a + b, c); +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmax_u16x2(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int res; + asm ("{.reg .b32 t1; \n\t" + "add.u16x2 t1, %1, %2; \n\t" + "max.u16x2 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + // Get answer + unsigned short ansU_lo = (unsigned short)max((unsigned short)(aU_lo + bU_lo), cU_lo); + unsigned short ansU_hi = (unsigned short)max((unsigned short)(aU_hi + bU_hi), cU_hi); + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __viaddmin_s32(const int a, const int b, const int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .s32 t1; \n\t" + "add.s32 t1, %1, %2; \n\t" + "min.s32 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + return min(a + b, c); +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmin_s16x2(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int res; + asm ("{.reg .b32 t1; \n\t" + "add.s16x2 t1, %1, %2; \n\t" + "min.s16x2 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + short cS_lo = *(short*)& cU_lo; + short cS_hi = *(short*)& cU_hi; + + // Get answer + short ansS_lo = (short)min((short)(aS_lo + bS_lo), cS_lo); + short ansS_hi = (short)min((short)(aS_hi + bS_hi), cS_hi); + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmin_u32(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int res; + asm ("{.reg .u32 t1; \n\t" + "add.u32 t1, %1, %2; \n\t" + "min.u32 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + return min(a + b, c); +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmin_u16x2(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int res; + asm ("{.reg .b32 t1; \n\t" + "add.u16x2 t1, %1, %2; \n\t" + "min.u16x2 %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + // Get answer + unsigned short ansU_lo = (unsigned short)min((unsigned short)(aU_lo + bU_lo), cU_lo); + unsigned short ansU_hi = (unsigned short)min((unsigned short)(aU_hi + bU_hi), cU_hi); + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __viaddmax_s32_relu(const int a, const int b, const int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .s32 t1; \n\t" + "add.s32 t1, %1, %2; \n\t" + "max.s32.relu %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + int ans = max(a + b, c); + + return (ans > 0) ? ans : 0; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmax_s16x2_relu(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int res; + asm ("{.reg .b32 t1; \n\t" + "add.s16x2 t1, %1, %2; \n\t" + "max.s16x2.relu %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + short cS_lo = *(short*)& cU_lo; + short cS_hi = *(short*)& cU_hi; + + // Get answer + short ansS_lo = (short)max((short)(aS_lo + bS_lo), cS_lo); + short ansS_hi = (short)max((short)(aS_hi + bS_hi), cS_hi); + + if(ansS_lo < 0){ansS_lo = 0;} + if(ansS_hi < 0){ansS_hi = 0;} + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __viaddmin_s32_relu(const int a, const int b, const int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int res; + asm ("{.reg .s32 t1; \n\t" + "add.s32 t1, %1, %2; \n\t" + "min.s32.relu %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + int ans = min(a + b, c); + + return (ans > 0) ? ans : 0; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __viaddmin_s16x2_relu(const unsigned int a, const unsigned int b, const unsigned int c){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int res; + asm ("{.reg .b32 t1; \n\t" + "add.s16x2 t1, %1, %2; \n\t" + "min.s16x2.relu %0, t1, %3;}\n\t" + : "=r"(res) : "r"(a), "r"(b), "r"(c)); + return res; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + unsigned short cU_lo = (unsigned short)(c & 0xFFFFU); + unsigned short cU_hi = (unsigned short)(c >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + short cS_lo = *(short*)& cU_lo; + short cS_hi = *(short*)& cU_hi; + + // Get answer + short ansS_lo = (short)min((short)(aS_lo + bS_lo), cS_lo); + short ansS_hi = (short)min((short)(aS_hi + bS_hi), cS_hi); + + if(ansS_lo < 0){ansS_lo = 0;} + if(ansS_hi < 0){ansS_hi = 0;} + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +// vimax vimin with predicate +// *pred gets set to '(a >= b)' +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vibmax_s32(const int a, const int b, bool* const pred){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int val; + unsigned int predicate_local; + asm ("{ .reg .pred __$temp1;\n\t" + " setp.ge.s32 __$temp1, %2, %3;\n\t" + " selp.s32 %0, %2, %3, __$temp1;\n\t" + " selp.s32 %1, 1, 0, __$temp1;}\n\t" + : "=r"(val), "=r"(predicate_local) : "r"(a), "r"(b)); + + *pred = (bool)predicate_local; + return val; +#else + // Host and older architecture code + int ans = max(a, b); + + *pred = (a >= b); + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmax_u32(const unsigned int a, const unsigned int b, bool* const pred){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int val; + unsigned int predicate_local; + asm ("{ .reg .pred __$temp1;\n\t" + " setp.ge.u32 __$temp1, %2, %3;\n\t" + " selp.u32 %0, %2, %3, __$temp1;\n\t" + " selp.u32 %1, 1, 0, __$temp1;}\n\t" + : "=r"(val), "=r"(predicate_local) : "r"(a), "r"(b)); + + *pred = (bool)predicate_local; + return val; +#else + // Host and older architecture code + unsigned int ans = max(a, b); + + *pred = (a >= b); + return ans; +#endif +} + +// *pred gets set to '(a <= b)' +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ int __vibmin_s32(const int a, const int b, bool* const pred){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + int val; + unsigned int predicate_local; + asm ("{ .reg .pred __$temp1;\n\t" + " setp.le.s32 __$temp1, %2, %3;\n\t" + " selp.s32 %0, %2, %3, __$temp1;\n\t" + " selp.s32 %1, 1, 0, __$temp1;}\n\t" + : "=r"(val), "=r"(predicate_local) : "r"(a), "r"(b)); + + *pred = (bool)predicate_local; + return val; +#else + // Host and older architecture code + int ans = min(a, b); + + *pred = (a <= b); + return ans; +#endif +} + +// *pred gets set to '(a <= b)' +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmin_u32(const unsigned int a, const unsigned int b, bool* const pred){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int val; + unsigned int predicate_local; + asm ("{ .reg .pred __$temp1;\n\t" + " setp.le.u32 __$temp1, %2, %3;\n\t" + " selp.u32 %0, %2, %3, __$temp1;\n\t" + " selp.u32 %1, 1, 0, __$temp1;}\n\t" + : "=r"(val), "=r"(predicate_local) : "r"(a), "r"(b)); + + *pred = (bool)predicate_local; + return val; +#else + // Host and older architecture code + unsigned int ans = min(a, b); + + *pred = (a <= b); + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmax_s16x2(const unsigned int a, const unsigned int b, bool* const pred_hi, bool* const pred_lo){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int val; + unsigned int predicate_local_hi; + unsigned int predicate_local_lo; + asm ("{.reg .pred pu, pv; \n\t" + ".reg .s16 rs0, rs1, rs2, rs3; \n\t" + "max.s16x2 %0, %3, %4; \n\t" + "mov.b32 {rs0, rs1}, %0; \n\t" + "mov.b32 {rs2, rs3}, %3; \n\t" + "setp.eq.s16 pv, rs0, rs2; \n\t" + "setp.eq.s16 pu, rs1, rs3; \n\t" + "selp.b32 %1, 1, 0, pu; \n\t" + "selp.b32 %2, 1, 0, pv;} \n\t" + : "=r"(val), "=r"(predicate_local_hi),"=r"(predicate_local_lo) : "r"(a), "r"(b)); + + *pred_hi = (bool)predicate_local_hi; + *pred_lo = (bool)predicate_local_lo; + return val; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + // Get answer + short ansS_lo = (short)max(aS_lo, bS_lo); + short ansS_hi = (short)max(aS_hi, bS_hi); + + *pred_hi = (aS_hi >= bS_hi); + *pred_lo = (aS_lo >= bS_lo); + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmax_u16x2(const unsigned int a, const unsigned int b, bool* const pred_hi, bool* const pred_lo){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int val; + unsigned int predicate_local_hi; + unsigned int predicate_local_lo; + asm ("{.reg .pred pu, pv; \n\t" + ".reg .u16 rs0, rs1, rs2, rs3; \n\t" + "max.u16x2 %0, %3, %4; \n\t" + "mov.b32 {rs0, rs1}, %0; \n\t" + "mov.b32 {rs2, rs3}, %3; \n\t" + "setp.eq.u16 pv, rs0, rs2; \n\t" + "setp.eq.u16 pu, rs1, rs3; \n\t" + "selp.b32 %1, 1, 0, pu; \n\t" + "selp.b32 %2, 1, 0, pv;} \n\t" + : "=r"(val), "=r"(predicate_local_hi),"=r"(predicate_local_lo) : "r"(a), "r"(b)); + + *pred_hi = (bool)predicate_local_hi; + *pred_lo = (bool)predicate_local_lo; + return val; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + // Get answer + unsigned short ansU_lo = (unsigned short)max(aU_lo, bU_lo); + unsigned short ansU_hi = (unsigned short)max(aU_hi, bU_hi); + + *pred_hi = (aU_hi >= bU_hi); + *pred_lo = (aU_lo >= bU_lo); + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmin_s16x2(const unsigned int a, const unsigned int b, bool* const pred_hi, bool* const pred_lo){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int val; + unsigned int predicate_local_hi; + unsigned int predicate_local_lo; + asm ("{.reg .pred pu, pv; \n\t" + ".reg .u16 rs0, rs1, rs2, rs3; \n\t" + "min.s16x2 %0, %3, %4; \n\t" + "mov.b32 {rs0, rs1}, %0; \n\t" + "mov.b32 {rs2, rs3}, %3; \n\t" + "setp.eq.s16 pv, rs0, rs2; \n\t" + "setp.eq.s16 pu, rs1, rs3; \n\t" + "selp.b32 %1, 1, 0, pu; \n\t" + "selp.b32 %2, 1, 0, pv;} \n\t" + : "=r"(val), "=r"(predicate_local_hi),"=r"(predicate_local_lo) : "r"(a), "r"(b)); + + *pred_hi = (bool)predicate_local_hi; + *pred_lo = (bool)predicate_local_lo; + return val; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + //cast to signed: + short aS_lo = *(short*)& aU_lo; + short aS_hi = *(short*)& aU_hi; + + short bS_lo = *(short*)& bU_lo; + short bS_hi = *(short*)& bU_hi; + + // Get answer + short ansS_lo = (short)min(aS_lo, bS_lo); + short ansS_hi = (short)min(aS_hi, bS_hi); + + *pred_hi = (aS_hi <= bS_hi); + *pred_lo = (aS_lo <= bS_lo); + + // Cast back to unsigned: + unsigned short ansU_lo = *(unsigned short*)& ansS_lo; + unsigned short ansU_hi = *(unsigned short*)& ansS_hi; + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +__DEVICE_HOST_FUNCTIONS_STATIC_DECL__ unsigned int __vibmin_u16x2(const unsigned int a, const unsigned int b, bool* const pred_hi, bool* const pred_lo){ +#ifdef __CUDA_AND_AT_LEAST_SM_90__ + unsigned int val; + unsigned int predicate_local_hi; + unsigned int predicate_local_lo; + asm ("{.reg .pred pu, pv; \n\t" + ".reg .u16 rs0, rs1, rs2, rs3; \n\t" + "min.u16x2 %0, %3, %4; \n\t" + "mov.b32 {rs0, rs1}, %0; \n\t" + "mov.b32 {rs2, rs3}, %3; \n\t" + "setp.eq.u16 pv, rs0, rs2; \n\t" + "setp.eq.u16 pu, rs1, rs3; \n\t" + "selp.b32 %1, 1, 0, pu; \n\t" + "selp.b32 %2, 1, 0, pv;} \n\t" + : "=r"(val), "=r"(predicate_local_hi),"=r"(predicate_local_lo) : "r"(a), "r"(b)); + + *pred_hi = (bool)predicate_local_hi; + *pred_lo = (bool)predicate_local_lo; + return val; +#else + // Host and older architecture code + // Separate our high and low bit: + unsigned short aU_lo = (unsigned short)(a & 0xFFFFU); + unsigned short aU_hi = (unsigned short)(a >> 16); + + unsigned short bU_lo = (unsigned short)(b & 0xFFFFU); + unsigned short bU_hi = (unsigned short)(b >> 16); + + // Get answer + unsigned short ansU_lo = (unsigned short)min(aU_lo, bU_lo); + unsigned short ansU_hi = (unsigned short)min(aU_hi, bU_hi); + + *pred_hi = (aU_hi <= bU_hi); + *pred_lo = (aU_lo <= bU_lo); + + // Put answer back together: + unsigned int ans = ((unsigned int) ansU_lo) | (((unsigned int) ansU_hi) << 16); + + return ans; +#endif +} + +#ifdef __CUDA_AND_AT_LEAST_SM_90__ +#undef __CUDA_AND_AT_LEAST_SM_90__ +#endif + +#undef __DEVICE_HOST_FUNCTIONS_STATIC_DECL__ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#endif /* !__DEVICE_FUNCTIONS_HPP__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_FUNCTIONS_HPP__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_DEVICE_FUNCTIONS_HPP__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/func_macro.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/func_macro.h new file mode 100644 index 0000000000000000000000000000000000000000..633554a01aaabd1bca5ae278c276710f323d5d7b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/func_macro.h @@ -0,0 +1,57 @@ +/* + * NVIDIA_COPYRIGHT_BEGIN + * + * Copyright (c) 2008-2018, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + * + * NVIDIA_COPYRIGHT_END + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/func_macro.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/func_macro.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_FUNC_MACRO_H__ +#endif + +#if !defined(__FUNC_MACRO_H__) +#define __FUNC_MACRO_H__ + +#if !defined(__CUDA_INTERNAL_COMPILATION__) + +#error -- incorrect inclusion of a cudart header file + +#endif /* !__CUDA_INTERNAL_COMPILATION__ */ + +#if defined(__GNUC__) + +#define __func__(decl) \ + inline decl + +#define __device_func__(decl) \ + static __attribute__((__unused__)) decl + +#elif defined(_WIN32) + +#define __func__(decl) \ + static inline decl + +#define __device_func__(decl) \ + static decl + +#endif /* __GNUC__ */ + +#endif /* __FUNC_MACRO_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_FUNC_MACRO_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_FUNC_MACRO_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/host_config.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/host_config.h new file mode 100644 index 0000000000000000000000000000000000000000..1daf7f2d7d3a5d68fe3f021d0a4677e76b4286c4 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/host_config.h @@ -0,0 +1,304 @@ +/* + * Copyright 1993-2022 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/host_config.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/host_config.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_HOST_CONFIG_H__ +#endif + +#if !defined(__HOST_CONFIG_H__) +#define __HOST_CONFIG_H__ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__CUDACC__) + +#if defined(__CUDACC_RTC__) + +#define _CRTIMP +#define __THROW + +#else /* __CUDACC_RTC__ */ + +/* check for host compilers that are compatible with nvcc */ +#if !defined(__GNUC__) && !defined(_WIN32) + +#error --- !!! UNSUPPORTED COMPILER !!! --- + +#endif /* !__GNUC__ && !_WIN32 */ + +/* check invalid configurations */ +#if defined(__PGIC__) +#if !defined(__GNUC__) || !defined(__LP64__) || !defined(__linux__) +#error -- unsupported pgc++ configuration! pgc++ is supported only on Linux x86_64! +#endif /* !defined(__GNUC__) || !defined(__LP64__) || !defined(__linux__) */ +#endif /* defined(__PGIC__) */ + +#if defined(__powerpc__) +#if !defined(__powerpc64__) || !defined(__LITTLE_ENDIAN__) +#error -- unsupported PPC platform! Only 64-bit little endian PPC is supported! +#endif /* !__powerpc64__ || !__LITTLE_ENDIAN__ */ +#endif /* __powerpc__ */ + +#if defined(__APPLE__) && defined(__MACH__) && !defined(__clang__) +#error -- clang and clang++ are the only supported host compilers on Mac OS X! +#endif /* __APPLE__ && __MACH__ && !__clang__ */ + + +/* check host compiler version */ +#if !__NV_NO_HOST_COMPILER_CHECK + +#if defined(__ICC) + +#if (__ICC != 1500 && __ICC != 1600 && __ICC != 1700 && __ICC != 1800 && !(__ICC >= 1900 && __ICC <= 2021)) || !defined(__GNUC__) || !defined(__LP64__) + +#error -- unsupported ICC configuration! Only ICC 15.0, ICC 16.0, ICC 17.0, ICC 18.0, ICC 19.x and 20.x on Linux x86_64 are supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. + +#endif /* (__ICC != 1500 && __ICC != 1600 && __ICC != 1700 && __ICC != 1800 && __ICC != 1900) || !__GNUC__ || !__LP64__ */ + +#endif /* __ICC */ + +#if defined(__GRCO_CLANG_COMPILER__) +#if (__GRCO_CLANG_COMPILER__ == 1) && ((__clang_major__ < 16) || (__clang_major__ > 16)) +#error -- unsupported Grace clang version! The version must be 16.x . The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. +#endif /* (__GRCO_CLANG_COMPILER__ == 1) && ((__clang_major__ < 16) || (__clang_major__ > 16)) */ + +#endif /* __GRCO_CLANG_COMPILER__ */ + +#if defined(__INTEL_CLANG_COMPILER) +#error -- unsupported Intel ICX compiler! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. +#endif /* __INTEL_CLANG_COMPILER */ + +#if defined(__powerpc__) + +#if defined(__ibmxl_vrm__) && !(__ibmxl_vrm__ >= 0x0d010000 && __ibmxl_vrm__ < 0x0d020000) && \ + !(__ibmxl_vrm__ >= 0x10010000 && __ibmxl_vrm__ < 0x10020000) + +#error -- unsupported xlC version! only xlC 13.1 and 16.1 are supported. The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. + +#endif /* __ibmxl_vrm__ && !(__ibmxl_vrm__ >= 0x0d010000 && __ibmxl_vrm__ < 0x0d020000) && + !(__ibmxl_vrm__ >= 0x10010000 && __ibmxl_vrm__ < 0x10020000) */ + +#endif /* __powerpc__ */ + +#if defined(__GNUC__) + +#if __GNUC__ > 12 + +#error -- unsupported GNU version! gcc versions later than 12 are not supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. + +#endif /* __GNUC__ > 12 */ + + +#if defined(__clang__) && !defined(__ibmxl_vrm__) && !defined(__ICC) && !defined(__HORIZON__) && !defined(__APPLE__) + +#if (__clang_major__ >= 17) || (__clang_major__ < 3) || ((__clang_major__ == 3) && (__clang_minor__ < 3)) +#error -- unsupported clang version! clang version must be less than 16 and greater than 3.2 . The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. + +#endif /* (__clang_major__ >= 17) || (__clang_major__ < 3) || ((__clang_major__ == 3) && (__clang_minor__ < 3)) */ + +#endif /* defined(__clang__) && !defined(__ibmxl_vrm__) && !defined(__ICC) && !defined(__HORIZON__) && !defined(__APPLE__) */ + + +#endif /* __GNUC__ */ + +#if defined(_WIN32) + +#if _MSC_VER < 1910 || _MSC_VER >= 1940 + +#error -- unsupported Microsoft Visual Studio version! Only the versions between 2017 and 2022 (inclusive) are supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. + +#elif _MSC_VER >= 1910 && _MSC_VER < 1910 + +#pragma message("support for this version of Microsoft Visual Studio has been deprecated! Only the versions between 2017 and 2022 (inclusive) are supported!") + +#endif /* (_MSC_VER < 1910 || _MSC_VER >= 1940) || (_MSC_VER >= 1910 && _MSC_VER < 1910) */ + +#endif /* _WIN32 */ +#endif /* !__NV_NO_HOST_COMPILER_CHECK */ + + +/* configure host compiler */ +#if defined(__APPLE__) + +#define _CRTIMP +#define _ACRTIMP +#define __THROW + +#if defined(__BLOCKS__) /* nvcc does not support closures */ + +#undef __BLOCKS__ + +#endif /* __BLOCKS__ */ + +#elif defined(__ANDROID__) + +#define _CRTIMP +#define _ACRTIMP +#define __THROW + +#elif defined(__QNX__) + +#define _CRTIMP +#define _ACRTIMP +#define __THROW + +#elif defined(__HORIZON__) + +#define _CRTIMP +#define _ACRTIMP +#define __THROW + +#elif defined(__GNUC__) + +#define _CRTIMP +#define _ACRTIMP + +#include /* for __THROW */ + +#elif defined(_WIN32) + +#if _MSC_VER >= 1500 + +#undef _USE_DECLSPECS_FOR_SAL +#define _USE_DECLSPECS_FOR_SAL \ + 1 + +#endif /* _MSC_VER >= 1500 */ + +#if !defined(_CRT_NONSTDC_NO_WARNINGS) + +#define _CRT_NONSTDC_NO_WARNINGS /* to suppress warnings */ + +#endif /* !_CRT_NONSTDC_NO_WARNINGS */ + +#if !defined(_CRT_SECURE_NO_WARNINGS) + +#define _CRT_SECURE_NO_WARNINGS /* to suppress warnings */ + +#endif /* !_CRT_SECURE_NO_WARNINGS */ + +#if !defined(NOMINMAX) + +#define NOMINMAX /* min and max are part of cuda runtime */ + +#endif /* !NOMINMAX */ + +#include /* for _CRTIMP */ +#if _MSC_VER >= 1900 +#include /* for _ACRTIMP */ +#endif /* _MSC_VER >= 1900 */ + +#define __THROW + +#endif /* __APPLE__ */ + +#endif /* __CUDACC_RTC__ */ + + +#if defined(__cplusplus) && defined(__CUDA_ARCH__) && (defined(__PGIC__) || defined(__CUDACC_RTC__) || (defined(_WIN32) && defined(_MSC_VER))) + +#if __CUDACC_RTC__ +typedef char *va_list; +#else /* !__CUDACC_RTC__ */ +#include +#endif /* __CUDACC_RTC__ */ + + +#undef va_start +#undef va_end +#undef va_arg + +#ifdef __PGIC__ + +#undef __builtin_va_end + +#define va_start(v,l) __builtin_alt_va_start(v,l) +#define va_end(v) __builtin_va_end(v) +#define va_arg(v,l) __builtin_alt_va_arg(v,l) + +#if (__cplusplus >= 201103L) +#undef va_copy +#define va_copy(d,s) __builtin_va_copy(d,s) +#endif + +#else /* !__PGIC__ */ + + +#define va_start(ap, x) (__cu_va_start(&ap, x)) +#define va_end(ap) (__cu_va_end(&ap)) +#define va_arg(ap, t) (*((t *)__cu_va_arg(&ap, (t *)0))) + +#if (_MSC_VER >= 1800) || (defined(__CUDACC_RTC__) && (__cplusplus >= 201103L)) +#undef va_copy +#define va_copy(apd, aps) (__cu_va_copy(&(apd), &(aps))) +#endif /* (_MSC_VER >= 1800) || (defined(__CUDACC_RTC__) && (__cplusplus >= 201103L)) */ +#endif /* __PGIC__ */ + +#endif /* defined(__cplusplus) && (defined(__CUDACC_RTC__) || (defined(_WIN32) && defined(_MSC_VER))) */ + + + +#endif /* __CUDACC__ */ + +#endif /* !__HOST_CONFIG_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_HOST_CONFIG_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_HOST_CONFIG_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/host_defines.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/host_defines.h new file mode 100644 index 0000000000000000000000000000000000000000..56cc4d5770af9a2cd98984e818ebd15d14bada16 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/host_defines.h @@ -0,0 +1,264 @@ +/* + * Copyright 1993-2022 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/host_defines.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/host_defines.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_HOST_DEFINES_H__ +#endif + +#if !defined(__HOST_DEFINES_H__) +#define __HOST_DEFINES_H__ + +/* CUDA JIT mode (__CUDACC_RTC__) also uses GNU style attributes */ +#if defined(__GNUC__) || (defined(__PGIC__) && defined(__linux__)) || defined(__CUDA_LIBDEVICE__) || defined(__CUDACC_RTC__) + +#if defined(__CUDACC_RTC__) +#define __volatile__ volatile +#endif /* __CUDACC_RTC__ */ + +#define __no_return__ \ + __attribute__((noreturn)) + +#if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__) +/* gcc allows users to define attributes with underscores, + e.g., __attribute__((__noinline__)). + Consider a non-CUDA source file (e.g. .cpp) that has the + above attribute specification, and includes this header file. In that case, + defining __noinline__ as below would cause a gcc compilation error. + Hence, only define __noinline__ when the code is being processed + by a CUDA compiler component. +*/ +#define __noinline__ \ + __attribute__((noinline)) +#endif /* __CUDACC__ || __CUDA_ARCH__ || __CUDA_LIBDEVICE__ */ + +#undef __forceinline__ +#define __forceinline__ \ + __inline__ __attribute__((always_inline)) +#define __align__(n) \ + __attribute__((aligned(n))) +#define __thread__ \ + __thread +#define __import__ +#define __export__ +#define __cdecl +#define __annotate__(a) \ + __attribute__((a)) +#define __location__(a) \ + __annotate__(a) +#define CUDARTAPI +#define CUDARTAPI_CDECL + +#elif defined(_MSC_VER) + +#if _MSC_VER >= 1400 + +#define __restrict__ \ + __restrict + +#else /* _MSC_VER >= 1400 */ + +#define __restrict__ + +#endif /* _MSC_VER >= 1400 */ + +#define __inline__ \ + __inline +#define __no_return__ \ + __declspec(noreturn) +#define __noinline__ \ + __declspec(noinline) +#define __forceinline__ \ + __forceinline +#define __align__(n) \ + __declspec(align(n)) +#define __thread__ \ + __declspec(thread) +#define __import__ \ + __declspec(dllimport) +#define __export__ \ + __declspec(dllexport) +#define __annotate__(a) \ + __declspec(a) +#define __location__(a) \ + __annotate__(__##a##__) +#define CUDARTAPI \ + __stdcall +#define CUDARTAPI_CDECL \ + __cdecl + +#else /* __GNUC__ || __CUDA_LIBDEVICE__ || __CUDACC_RTC__ */ + +#define __inline__ + +#if !defined(__align__) + +#error --- !!! UNKNOWN COMPILER: please provide a CUDA compatible definition for '__align__' !!! --- + +#endif /* !__align__ */ + +#if !defined(CUDARTAPI) + +#error --- !!! UNKNOWN COMPILER: please provide a CUDA compatible definition for 'CUDARTAPI' !!! --- + +#endif /* !CUDARTAPI */ + +#endif /* __GNUC__ || __CUDA_LIBDEVICE__ || __CUDACC_RTC__ */ + +#if (defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3 && !defined(__clang__)))) || \ + (defined(_MSC_VER) && _MSC_VER < 1900) || \ + (!defined(__GNUC__) && !defined(_MSC_VER)) + +#define __specialization_static \ + static + +#else /* (__GNUC__ && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3 && !__clang__))) || + (_MSC_VER && _MSC_VER < 1900) || + (!__GNUC__ && !_MSC_VER) */ + +#define __specialization_static + +#endif /* (__GNUC__ && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3 && !__clang__))) || + (_MSC_VER && _MSC_VER < 1900) || + (!__GNUC__ && !_MSC_VER) */ + +#if !defined(__CUDACC__) && !defined(__CUDA_LIBDEVICE__) + +#undef __annotate__ +#define __annotate__(a) + +#else /* !__CUDACC__ && !__CUDA_LIBDEVICE__ */ + +#define __launch_bounds__(...) \ + __annotate__(launch_bounds(__VA_ARGS__)) + +#endif /* !__CUDACC__ && !__CUDA_LIBDEVICE__ */ + +#if defined(__CUDACC__) || defined(__CUDA_LIBDEVICE__) || \ + defined(__GNUC__) || defined(_WIN64) + +#define __builtin_align__(a) \ + __align__(a) + +#else /* __CUDACC__ || __CUDA_LIBDEVICE__ || __GNUC__ || _WIN64 */ + +#define __builtin_align__(a) + +#endif /* __CUDACC__ || __CUDA_LIBDEVICE__ || __GNUC__ || _WIN64 */ + +#if defined(__CUDACC__) || !defined(__grid_constant__) +#define __grid_constant__ \ + __location__(grid_constant) +#endif /* defined(__CUDACC__) || !defined(__grid_constant__) */ + +#if defined(__CUDACC__) || !defined(__host__) +#define __host__ \ + __location__(host) +#endif /* defined(__CUDACC__) || !defined(__host__) */ +#if defined(__CUDACC__) || !defined(__device__) +#define __device__ \ + __location__(device) +#endif /* defined(__CUDACC__) || !defined(__device__) */ +#if defined(__CUDACC__) || !defined(__global__) +#define __global__ \ + __location__(global) +#endif /* defined(__CUDACC__) || !defined(__global__) */ +#if defined(__CUDACC__) || !defined(__shared__) +#define __shared__ \ + __location__(shared) +#endif /* defined(__CUDACC__) || !defined(__shared__) */ +#if defined(__CUDACC__) || !defined(__constant__) +#define __constant__ \ + __location__(constant) +#endif /* defined(__CUDACC__) || !defined(__constant__) */ +#if defined(__CUDACC__) || !defined(__managed__) +#define __managed__ \ + __location__(managed) +#endif /* defined(__CUDACC__) || !defined(__managed__) */ + +#if !defined(__CUDACC__) +#define __device_builtin__ +#define __device_builtin_texture_type__ +#define __device_builtin_surface_type__ +#define __cudart_builtin__ +#else /* defined(__CUDACC__) */ +#define __device_builtin__ \ + __location__(device_builtin) +#define __device_builtin_texture_type__ \ + __location__(device_builtin_texture_type) +#define __device_builtin_surface_type__ \ + __location__(device_builtin_surface_type) +#define __cudart_builtin__ \ + __location__(cudart_builtin) +#endif /* !defined(__CUDACC__) */ + +#if defined(__CUDACC__) || !defined(__cluster_dims__) +#if defined(_MSC_VER) +#define __cluster_dims__(...) \ + __declspec(__cluster_dims__(__VA_ARGS__)) + +#else /* !defined(_MSC_VER) */ +#define __cluster_dims__(...) \ + __attribute__((cluster_dims(__VA_ARGS__))) +#endif /* defined(_MSC_VER) */ +#endif /* defined(__CUDACC__) || !defined(__cluster_dims__) */ + +#define __CUDA_ARCH_HAS_FEATURE__(_FEAT) __CUDA_ARCH_FEAT_##_FEAT + +#endif /* !__HOST_DEFINES_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_HOST_DEFINES_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_HOST_DEFINES_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/host_runtime.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/host_runtime.h new file mode 100644 index 0000000000000000000000000000000000000000..94d4f6b4bdac0cf39a8b3a47fea7df61b712fcf8 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/host_runtime.h @@ -0,0 +1,288 @@ +/* + * NVIDIA_COPYRIGHT_BEGIN + * + * Copyright (c) 2008-2018, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + * + * NVIDIA_COPYRIGHT_END + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/device_functions.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/device_functions.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_HOST_RUNTIME_H__ +#endif + +#if !defined(__CUDA_INTERNAL_COMPILATION__) + +#define __CUDA_INTERNAL_COMPILATION__ +#define __text__ +#define __surf__ +#define __name__shadow_var(c, cpp) \ + #c +#define __name__text_var(c, cpp) \ + #cpp +#define __host__shadow_var(c, cpp) \ + cpp +#define __text_var(c, cpp) \ + cpp +#define __device_fun(fun) \ + #fun +#define __device_var(var) \ + #var +#define __device__text_var(c, cpp) \ + #c +#define __device__shadow_var(c, cpp) \ + #c + +#if defined(_WIN32) && !defined(_WIN64) + +#define __pad__(f) \ + f + +#else /* _WIN32 && !_WIN64 */ + +#define __pad__(f) + +#endif /* _WIN32 && !_WIN64 */ + +#include "builtin_types.h" +#include "storage_class.h" + +#else /* !__CUDA_INTERNAL_COMPILATION__ */ + +template +static inline T *__cudaAddressOf(T &val) +{ + return (T *)((void *)(&(const_cast(reinterpret_cast(val))))); +} + +#define __cudaRegisterBinary(X) \ + __cudaFatCubinHandle = __cudaRegisterFatBinary((void*)&__fatDeviceText); \ + { void (*callback_fp)(void **) = (void (*)(void **))(X); (*callback_fp)(__cudaFatCubinHandle); __cudaRegisterFatBinaryEnd(__cudaFatCubinHandle); }\ + atexit(__cudaUnregisterBinaryUtil) + +#define __cudaRegisterVariable(handle, var, ext, size, constant, global) \ + __cudaRegisterVar(handle, (char*)&__host##var, (char*)__device##var, __name##var, ext, size, constant, global) +#define __cudaRegisterManagedVariable(handle, var, ext, size, constant, global) \ + __cudaRegisterManagedVar(handle, (void **)&__host##var, (char*)__device##var, __name##var, ext, size, constant, global) + +#define __cudaRegisterGlobalTexture(handle, tex, dim, norm, ext) \ + __cudaRegisterTexture(handle, (const struct textureReference*)&tex, (const void**)(void*)__device##tex, __name##tex, dim, norm, ext) +#define __cudaRegisterGlobalSurface(handle, surf, dim, ext) \ + __cudaRegisterSurface(handle, (const struct surfaceReference*)&surf, (const void**)(void*)__device##surf, __name##surf, dim, ext) +#define __cudaRegisterEntry(handle, funptr, fun, thread_limit) \ + __cudaRegisterFunction(handle, (const char*)funptr, (char*)__device_fun(fun), #fun, -1, (uint3*)0, (uint3*)0, (dim3*)0, (dim3*)0, (int*)0) + +extern "C" cudaError_t CUDARTAPI __cudaPopCallConfiguration( + dim3 *gridDim, + dim3 *blockDim, + size_t *sharedMem, + void *stream +); + +#define __cudaLaunchPrologue(size) \ + void * __args_arr[size]; \ + int __args_idx = 0 + +#define __cudaSetupArg(arg, offset) \ + __args_arr[__args_idx] = (void *)__cudaAddressOf(arg); ++__args_idx + +#define __cudaSetupArgSimple(arg, offset) \ + __args_arr[__args_idx] = (void *)(char *)&arg; ++__args_idx + +#if defined(__GNUC__) +#define __NV_ATTR_UNUSED_FOR_LAUNCH __attribute__((unused)) +#else /* !__GNUC__ */ +#define __NV_ATTR_UNUSED_FOR_LAUNCH +#endif /* __GNUC__ */ + +/* the use of __args_idx in the expression below avoids host compiler warning about it being an + unused variable when the launch has no arguments */ +#define __cudaLaunch(fun) \ + { volatile static char *__f __NV_ATTR_UNUSED_FOR_LAUNCH; __f = fun; \ + dim3 __gridDim, __blockDim;\ + size_t __sharedMem; \ + cudaStream_t __stream; \ + if (__cudaPopCallConfiguration(&__gridDim, &__blockDim, &__sharedMem, &__stream) != cudaSuccess) \ + return; \ + if (__args_idx == 0) {\ + (void)cudaLaunchKernel(fun, __gridDim, __blockDim, &__args_arr[__args_idx], __sharedMem, __stream);\ + } else { \ + (void)cudaLaunchKernel(fun, __gridDim, __blockDim, &__args_arr[0], __sharedMem, __stream);\ + }\ + } + +#if defined(__GNUC__) +#define __nv_dummy_param_ref(param) \ + { volatile static void **__ref __attribute__((unused)); __ref = (volatile void **)param; } +#else /* __GNUC__ */ +#define __nv_dummy_param_ref(param) \ + { volatile static void **__ref; __ref = (volatile void **)param; } +#endif /* __GNUC__ */ + +static void ____nv_dummy_param_ref(void *param) __nv_dummy_param_ref(param) + +#define __REGISTERFUNCNAME_CORE(X) __cudaRegisterLinkedBinary##X +#define __REGISTERFUNCNAME(X) __REGISTERFUNCNAME_CORE(X) + +extern "C" { +void __REGISTERFUNCNAME( __NV_MODULE_ID ) ( void (*)(void **), void *, void *, void (*)(void *)); +} + +#define __TO_STRING_CORE(X) #X +#define __TO_STRING(X) __TO_STRING_CORE(X) + +extern "C" { +#if defined(_WIN32) +#pragma data_seg("__nv_module_id") + static const __declspec(allocate("__nv_module_id")) unsigned char __module_id_str[] = __TO_STRING(__NV_MODULE_ID); +#pragma data_seg() +#elif defined(__APPLE__) + static const unsigned char __module_id_str[] __attribute__((section ("__NV_CUDA,__nv_module_id"))) = __TO_STRING(__NV_MODULE_ID); +#else + static const unsigned char __module_id_str[] __attribute__((section ("__nv_module_id"))) = __TO_STRING(__NV_MODULE_ID); +#endif + +#undef __FATIDNAME_CORE +#undef __FATIDNAME +#define __FATIDNAME_CORE(X) __fatbinwrap##X +#define __FATIDNAME(X) __FATIDNAME_CORE(X) + +#define ____cudaRegisterLinkedBinary(X) \ +{ __REGISTERFUNCNAME(__NV_MODULE_ID) (( void (*)(void **))(X), (void *)&__FATIDNAME(__NV_MODULE_ID), (void *)&__module_id_str, (void (*)(void *))&____nv_dummy_param_ref); } + +} + +extern "C" { +extern void** CUDARTAPI __cudaRegisterFatBinary( + void *fatCubin +); + +extern void CUDARTAPI __cudaRegisterFatBinaryEnd( + void **fatCubinHandle +); + +extern void CUDARTAPI __cudaUnregisterFatBinary( + void **fatCubinHandle +); + +extern void CUDARTAPI __cudaRegisterVar( + void **fatCubinHandle, + char *hostVar, + char *deviceAddress, + const char *deviceName, + int ext, + size_t size, + int constant, + int global +); + +extern void CUDARTAPI __cudaRegisterManagedVar( + void **fatCubinHandle, + void **hostVarPtrAddress, + char *deviceAddress, + const char *deviceName, + int ext, + size_t size, + int constant, + int global +); + +extern char CUDARTAPI __cudaInitModule( + void **fatCubinHandle +); + +extern void CUDARTAPI __cudaRegisterTexture( + void **fatCubinHandle, + const struct textureReference *hostVar, + const void **deviceAddress, + const char *deviceName, + int dim, + int norm, + int ext +); + +extern void CUDARTAPI __cudaRegisterSurface( + void **fatCubinHandle, + const struct surfaceReference *hostVar, + const void **deviceAddress, + const char *deviceName, + int dim, + int ext +); + +extern void CUDARTAPI __cudaRegisterFunction( + void **fatCubinHandle, + const char *hostFun, + char *deviceFun, + const char *deviceName, + int thread_limit, + uint3 *tid, + uint3 *bid, + dim3 *bDim, + dim3 *gDim, + int *wSize +); + +#if defined(__APPLE__) +extern "C" int atexit(void (*)(void)); + +#elif defined(__GNUC__) && !defined(__ANDROID__) && !defined(__HORIZON__) +extern int atexit(void(*)(void)) throw(); + +#elif defined(__HORIZON__) + +// __TEMP_WAR__ 200132570 HOS : Disable atexit call until it works +#define atexit(p) + +#else /* __GNUC__ && !__ANDROID__ */ +extern int __cdecl atexit(void(__cdecl *)(void)); +#endif + +} + +static void **__cudaFatCubinHandle; + +static void __cdecl __cudaUnregisterBinaryUtil(void) +{ + ____nv_dummy_param_ref((void *)&__cudaFatCubinHandle); + __cudaUnregisterFatBinary(__cudaFatCubinHandle); +} + +static char __nv_init_managed_rt_with_module(void **handle) +{ + return __cudaInitModule(handle); +} + +#include "common_functions.h" + +#pragma pack() + +#if defined(_WIN32) + +#pragma warning(disable: 4099) + +#if !defined(_WIN64) + +#pragma warning(disable: 4408) + +#endif /* !_WIN64 */ + +#endif /* _WIN32 */ + +#endif /* !__CUDA_INTERNAL_COMPILATION__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_HOST_RUNTIME_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_HOST_RUNTIME_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/math_functions.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/math_functions.h new file mode 100644 index 0000000000000000000000000000000000000000..f1c0d662fddbcdf021751f3855bcf520cd52299c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/math_functions.h @@ -0,0 +1,12196 @@ +/* + * Copyright 1993-2022 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/math_functions.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/math_functions.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_MATH_FUNCTIONS_H__ +#endif + +#if !defined(__MATH_FUNCTIONS_H__) +#define __MATH_FUNCTIONS_H__ + +#if defined(__QNX__) && (__GNUC__ >= 5) && defined(__CUDACC__) +#if __has_include(<__config>) +#include <__config> +#endif +#endif + +/** + * \defgroup CUDA_MATH Mathematical Functions + * + * CUDA mathematical functions are always available in device code. + * + * Host implementations of the common mathematical functions are mapped + * in a platform-specific way to standard math library functions, provided + * by the host compiler and respective host libm where available. + * Some functions, not available with the host compilers, are implemented + * in crt/math_functions.hpp header file. + * For example, see ::erfinv(). Other, less common functions, + * like ::rhypot(), ::cyl_bessel_i0() are only available in device code. + * + * Note that many floating-point and integer functions names are + * overloaded for different argument types. For example, the ::log() + * function has the following prototypes: + * \code + * double log(double x); + * float log(float x); + * float logf(float x); + * \endcode + * + * Note also that due to implementation constraints, certain math functions + * from std:: namespace may be callable in device code even via explicitly + * qualified std:: names. However, such use is discouraged, since this + * capability is unsupported, unverified, undocumented, not portable, and + * may change without notice. + */ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__cplusplus) && defined(__CUDACC__) + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#include "builtin_types.h" +#include "host_defines.h" + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +extern "C" +{ + +/* Define math function DOXYGEN toplevel groups, functions will + be added to these groups later. +*/ +/** + * \defgroup CUDA_MATH_SINGLE Single Precision Mathematical Functions + * This section describes single precision mathematical functions. + * To use these functions you do not need to include any additional + * header files in your program. + */ + +/** + * \defgroup CUDA_MATH_DOUBLE Double Precision Mathematical Functions + * This section describes double precision mathematical functions. + * To use these functions you do not need to include any additional + * header files in your program. + */ + +/** + * \defgroup CUDA_MATH_INT Integer Mathematical Functions + * This section describes integer mathematical functions. + * To use these functions you do not need to include any additional + * header files in your program. + */ + +/** + * \defgroup CUDA_MATH_INTRINSIC_SINGLE Single Precision Intrinsics + * This section describes single precision intrinsic functions that are + * only supported in device code. + * To use these functions you do not need to include any additional + * header files in your program. + */ + +/** + * \defgroup CUDA_MATH_INTRINSIC_DOUBLE Double Precision Intrinsics + * This section describes double precision intrinsic functions that are + * only supported in device code. + * To use these functions you do not need to include any additional + * header files in your program. + */ + +/** + * \defgroup CUDA_MATH_INTRINSIC_INT Integer Intrinsics + * This section describes integer intrinsic functions that are + * only supported in device code. + * To use these functions you do not need to include any additional + * header files in your program. + */ + +/** + * \defgroup CUDA_MATH_INTRINSIC_CAST Type Casting Intrinsics + * This section describes type casting intrinsic functions that are + * only supported in device code. + * To use these functions you do not need to include any additional + * header files in your program. + */ + +/** + * + * \defgroup CUDA_MATH_INTRINSIC_SIMD SIMD Intrinsics + * This section describes SIMD intrinsic functions that are + * only supported in device code. + * To use these functions you do not need to include any additional + * header files in your program. + */ + + +/** + * @} + */ +#define __DEVICE_FUNCTIONS_DECL__ __host__ __device__ +#if !defined(_MSC_VER) +#define __CUDA_MATH_CRTIMP +#else +#if _MSC_VER < 1900 +#define __CUDA_MATH_CRTIMP _CRTIMP +#else +#define __CUDA_MATH_CRTIMP _ACRTIMP +#endif +#endif + +#if defined(__ANDROID__) && (__ANDROID_API__ <= 20) && !defined(__aarch64__) +static __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ int abs(int); +static __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ long int labs(long int); +static __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ long long int llabs(long long int); +#else /* __ANDROID__ */ +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the absolute value of the input \p int argument. + * + * Calculate the absolute value of the input argument \p a. + * + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ int __cdecl abs(int a) __THROW; +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the absolute value of the input \p long \p int argument. + * + * Calculate the absolute value of the input argument \p a. + * + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ long int __cdecl labs(long int a) __THROW; +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the absolute value of the input \p long \p long \p int argument. + * + * Calculate the absolute value of the input argument \p a. + * + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __cudart_builtin__ long long int llabs(long long int a) __THROW; +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} +#endif +#endif /* __ANDROID__ */ + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +/* put all math functions in std */ +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the absolute value of the input argument. + * + * Calculate the absolute value of the input argument \p x. + * + * \return + * Returns the absolute value of the input argument. + * - fabs( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - fabs( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns +0. + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl fabs(double x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the absolute value of its argument + * + * Calculate the absolute value of the input argument \p x. + * + * \return + * Returns the absolute value of its argument. + * - fabsf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - fabsf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns +0. + * - fabsf(NaN) returns an unspecified NaN. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float fabsf(float x) __THROW; +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b. + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int min(const int a, const int b); +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p unsigned \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b. + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int umin(const unsigned int a, const unsigned int b); +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p long \p long \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b. + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int llmin(const long long int a, const long long int b); +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p unsigned \p long \p long \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b. + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned long long int ullmin(const unsigned long long int a, const unsigned long long int b); + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Determine the minimum numeric value of the arguments. + * + * Determines the minimum numeric value of the arguments \p x and \p y. Treats NaN + * arguments as missing data. If one argument is a NaN and the other is legitimate numeric + * value, the numeric value is chosen. + * + * \return + * Returns the minimum numeric value of the arguments \p x and \p y. + * - If both arguments are NaN, returns NaN. + * - If one argument is NaN, returns the numeric argument. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float fminf(float x, float y) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl fminf(float x, float y); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Determine the minimum numeric value of the arguments. + * + * Determines the minimum numeric value of the arguments \p x and \p y. Treats NaN + * arguments as missing data. If one argument is a NaN and the other is legitimate numeric + * value, the numeric value is chosen. + * + * \return + * Returns the minimum numeric value of the arguments \p x and \p y. + * - If both arguments are NaN, returns NaN. + * - If one argument is NaN, returns the numeric argument. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double fmin(double x, double y) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl fmin(double x, double y); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b. + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int max(const int a, const int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p unsigned \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b. + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned int umax(const unsigned int a, const unsigned int b); +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p long \p long \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b. + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int llmax(const long long int a, const long long int b); +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p unsigned \p long \p long \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b. + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ unsigned long long int ullmax(const unsigned long long int a, const unsigned long long int b); + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Determine the maximum numeric value of the arguments. + * + * Determines the maximum numeric value of the arguments \p x and \p y. Treats NaN + * arguments as missing data. If one argument is a NaN and the other is legitimate numeric + * value, the numeric value is chosen. + * + * \return + * Returns the maximum numeric values of the arguments \p x and \p y. + * - If both arguments are NaN, returns NaN. + * - If one argument is NaN, returns the numeric argument. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float fmaxf(float x, float y) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl fmaxf(float x, float y); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Determine the maximum numeric value of the arguments. + * + * Determines the maximum numeric value of the arguments \p x and \p y. Treats NaN + * arguments as missing data. If one argument is a NaN and the other is legitimate numeric + * value, the numeric value is chosen. + * + * \return + * Returns the maximum numeric values of the arguments \p x and \p y. + * - If both arguments are NaN, returns NaN. + * - If one argument is NaN, returns the numeric argument. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double fmax(double, double) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl fmax(double, double); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the sine of the input argument. + * + * Calculate the sine of the input argument \p x (measured in radians). + * + * \return + * - sin( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - sin( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl sin(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the cosine of the input argument. + * + * Calculate the cosine of the input argument \p x (measured in radians). + * + * \return + * - cos( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - cos( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl cos(double x) __THROW; +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the sine and cosine of the first input argument. + * + * Calculate the sine and cosine of the first input argument \p x (measured + * in radians). The results for sine and cosine are written into the + * second argument, \p sptr, and, respectively, third argument, \p cptr. + * + * \return + * - none + * + * \see ::sin() and ::cos(). + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ void sincos(double x, double *sptr, double *cptr) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the sine and cosine of the first input argument. + * + * Calculate the sine and cosine of the first input argument \p x (measured + * in radians). The results for sine and cosine are written into the second + * argument, \p sptr, and, respectively, third argument, \p cptr. + * + * \return + * - none + * + * \see ::sinf() and ::cosf(). + * \note_accuracy_single + * \note_fastmath + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ void sincosf(float x, float *sptr, float *cptr) __THROW; + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the tangent of the input argument. + * + * Calculate the tangent of the input argument \p x (measured in radians). + * + * \return + * - tan( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - tan( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl tan(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the square root of the input argument. + * + * Calculate the nonnegative square root of \p x, + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * \endxmlonly. + * + * \return + * Returns + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * \endxmlonly. + * - sqrt( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - sqrt( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - sqrt(\p x) returns NaN if \p x is less than 0. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl sqrt(double x) __THROW; +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the reciprocal of the square root of the input argument. + * + * Calculate the reciprocal of the nonnegative square root of \p x, + * \latexonly $1/\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * 1 + * + * / + * + * + * x + * + * + * \endxmlonly. + * + * \return + * Returns + * \latexonly $1/\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * 1 + * + * / + * + * + * x + * + * + * \endxmlonly. + * - rsqrt( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * - rsqrt( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * - rsqrt(\p x) returns NaN if \p x is less than 0. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double rsqrt(double x); + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the reciprocal of the square root of the input argument. + * + * Calculate the reciprocal of the nonnegative square root of \p x, + * \latexonly $1/\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * 1 + * + * / + * + * + * x + * + * + * \endxmlonly. + * + * \return + * Returns + * \latexonly $1/\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * 1 + * + * / + * + * + * x + * + * + * \endxmlonly. + * - rsqrtf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * - rsqrtf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * - rsqrtf(\p x) returns NaN if \p x is less than 0. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float rsqrtf(float x); + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the base 2 logarithm of the input argument. + * + * Calculate the base 2 logarithm of the input argument \p x. + * + * \return + * - log2( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - log2(1) returns +0. + * - log2(\p x) returns NaN for \p x < 0. + * - log2( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double log2(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl log2(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the base 2 exponential of the input argument. + * + * Calculate + * \latexonly $2^x$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * x + * + * + * \endxmlonly, + * the base 2 exponential of the input argument \p x. + * + * \return + * - exp2( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - exp2( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns +0. + * - exp2( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double exp2(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl exp2(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the base 2 exponential of the input argument. + * + * Calculate + * \latexonly $2^x$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * x + * + * + * \endxmlonly, + * the base 2 exponential of the input argument \p x. + * + * \return + * - exp2f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - exp2f( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns +0. + * - exp2f( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float exp2f(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl exp2f(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the base 10 exponential of the input argument. + * + * Calculate + * \latexonly $10^x$ \endlatexonly + * \xmlonly + * + * + * + * 10 + * x + * + * + * \endxmlonly, + * the base 10 exponential of the input argument \p x. + * + * \return + * - exp10( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - exp10( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns +0. + * - exp10( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double exp10(double x) __THROW; + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the base 10 exponential of the input argument. + * + * Calculate + * \latexonly $10^x$ \endlatexonly + * \xmlonly + * + * + * + * 10 + * x + * + * + * \endxmlonly, + * the base 10 exponential of the input argument \p x. + * + * \return + * - exp10f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - exp10f( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns +0. + * - exp10f( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + * \note_fastmath + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float exp10f(float x) __THROW; + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * exponential of the input argument, minus 1. + * + * Calculate + * \latexonly $e^x$ \endlatexonly + * \xmlonly + * + * + * + * e + * x + * + * + * \endxmlonly + * -1, the base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * exponential of the input argument \p x, minus 1. + * + * \return + * - expm1( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - expm1( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns -1. + * - expm1( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double expm1(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl expm1(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * exponential of the input argument, minus 1. + * + * Calculate + * \latexonly $e^x$ \endlatexonly + * \xmlonly + * + * + * + * e + * x + * + * + * \endxmlonly + * -1, the base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * exponential of the input argument \p x, minus 1. + * + * \return + * - expm1f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - expm1f( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns -1. + * - expm1f( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float expm1f(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl expm1f(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the base 2 logarithm of the input argument. + * + * Calculate the base 2 logarithm of the input argument \p x. + * + * \return + * - log2f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - log2f(1) returns +0. + * - log2f(\p x) returns NaN for \p x < 0. + * - log2f( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + * \note_fastmath + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float log2f(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl log2f(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the base 10 logarithm of the input argument. + * + * Calculate the base 10 logarithm of the input argument \p x. + * + * \return + * - log10( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - log10(1) returns +0. + * - log10(\p x) returns NaN for \p x < 0. + * - log10( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl log10(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * logarithm of the input argument. + * + * Calculate the base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * logarithm of the input argument \p x. + * + * \return + * - log( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - log(1) returns +0. + * - log(\p x) returns NaN for \p x < 0. + * - log( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl log(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the value of + * \latexonly $\log_{e}(1+x)$ \endlatexonly + * \xmlonly + * + * + * + * log + * + * e + * + * + * ( + * 1 + * + + * x + * ) + * + * \endxmlonly. + * + * Calculate the value of + * \latexonly $\log_{e}(1+x)$ \endlatexonly + * \xmlonly + * + * + * + * log + * + * e + * + * + * ( + * 1 + * + + * x + * ) + * + * \endxmlonly + * of the input argument \p x. + * + * \return + * - log1p( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - log1p(-1) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - log1p(\p x) returns NaN for \p x < -1. + * - log1p( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double log1p(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl log1p(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the value of + * \latexonly $\log_{e}(1+x)$ \endlatexonly + * \xmlonly + * + * + * + * log + * + * e + * + * + * ( + * 1 + * + + * x + * ) + * + * \endxmlonly. + * + * Calculate the value of + * \latexonly $\log_{e}(1+x)$ \endlatexonly + * \xmlonly + * + * + * + * log + * + * e + * + * + * ( + * 1 + * + + * x + * ) + * + * \endxmlonly + * of the input argument \p x. + * + * \return + * - log1pf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - log1pf(-1) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - log1pf(\p x) returns NaN for \p x < -1. + * - log1pf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float log1pf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl log1pf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the largest integer less than or equal to \p x. + * + * Calculates the largest integer value which is less than or equal to \p x. + * + * \return + * Returns + * \latexonly $\lfloor x \rfloor$ \endlatexonly + * \xmlonly + * + * + * ⌊ + * x + * ⌋ + * + * + * \endxmlonly + * expressed as a floating-point number. + * - floor( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * - floor( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl floor(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * exponential of the input argument. + * + * Calculate + * \latexonly $e^x$ \endlatexonly + * \xmlonly + * + * + * + * e + * x + * + * + * \endxmlonly, + * the base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * exponential of the input argument \p x. + * + * \return + * - exp( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - exp( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns +0. + * - exp( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl exp(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the hyperbolic cosine of the input argument. + * + * Calculate the hyperbolic cosine of the input argument \p x. + * + * \return + * - cosh( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - cosh( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl cosh(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the hyperbolic sine of the input argument. + * + * Calculate the hyperbolic sine of the input argument \p x. + * + * \return + * - sinh( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - sinh( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl sinh(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the hyperbolic tangent of the input argument. + * + * Calculate the hyperbolic tangent of the input argument \p x. + * + * \return + * - tanh( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - tanh( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 1$ \endlatexonly + * \xmlonly + * + * + * ± + * 1 + * + * + * \endxmlonly. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl tanh(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the nonnegative inverse hyperbolic cosine of the input argument. + * + * Calculate the nonnegative inverse hyperbolic cosine of the input argument \p x. + * + * \return + * Result will be in the interval [0, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ]. + * - acosh(1) returns 0. + * - acosh(\p x) returns NaN for \p x in the interval [ + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * , 1). + * - acosh( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double acosh(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl acosh(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the nonnegative inverse hyperbolic cosine of the input argument. + * + * Calculate the nonnegative inverse hyperbolic cosine of the input argument \p x. + * + * \return + * Result will be in the interval [0, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ]. + * - acoshf(1) returns 0. + * - acoshf(\p x) returns NaN for \p x in the interval [ + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * , 1). + * - acoshf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float acoshf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl acoshf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the inverse hyperbolic sine of the input argument. + * + * Calculate the inverse hyperbolic sine of the input argument \p x. + * + * \return + * - asinh( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - asinh( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double asinh(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl asinh(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the inverse hyperbolic sine of the input argument. + * + * Calculate the inverse hyperbolic sine of the input argument \p x. + * + * \return + * - asinhf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - asinhf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float asinhf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl asinhf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the inverse hyperbolic tangent of the input argument. + * + * Calculate the inverse hyperbolic tangent of the input argument \p x. + * + * \return + * - atanh( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - atanh( + * \latexonly $\pm 1$ \endlatexonly + * \xmlonly + * + * + * ± + * 1 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * - atanh(\p x) returns NaN for \p x outside interval [-1, 1]. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double atanh(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl atanh(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the inverse hyperbolic tangent of the input argument. + * + * Calculate the inverse hyperbolic tangent of the input argument \p x. + * + * \return + * - atanhf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - atanhf( + * \latexonly $\pm 1$ \endlatexonly + * \xmlonly + * + * + * ± + * 1 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * - atanhf(\p x) returns NaN for \p x outside interval [-1, 1]. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float atanhf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl atanhf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the value of + * \latexonly $x\cdot 2^{exp}$ \endlatexonly + * \xmlonly + * + * + * x + * ⋅ + * + * 2 + * + * e + * x + * p + * + * + * + * \endxmlonly. + * + * Calculate the value of + * \latexonly $x\cdot 2^{exp}$ \endlatexonly + * \xmlonly + * + * + * x + * ⋅ + * + * 2 + * + * e + * x + * p + * + * + * + * + * \endxmlonly + * of the input arguments \p x and \p exp. + * + * \return + * - ldexp(\p x, \p exp) is equivalent to scalbn(\p x, \p exp). + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl ldexp(double x, int exp) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the value of + * \latexonly $x\cdot 2^{exp}$ \endlatexonly + * \xmlonly + * + * + * x + * ⋅ + * + * 2 + * + * e + * x + * p + * + * + * + * \endxmlonly. + * + * Calculate the value of + * \latexonly $x\cdot 2^{exp}$ \endlatexonly + * \xmlonly + * + * + * x + * ⋅ + * + * 2 + * + * e + * x + * p + * + * + * + * + * \endxmlonly + * of the input arguments \p x and \p exp. + * + * \return + * - ldexpf(\p x, \p exp) is equivalent to scalbnf(\p x, \p exp). + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float ldexpf(float x, int exp) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the floating-point representation of the exponent of the input argument. + * + * Calculate the floating-point representation of the exponent of the input argument \p x. + * + * \return + * - logb( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly. + * - logb( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double logb(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl logb(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the floating-point representation of the exponent of the input argument. + * + * Calculate the floating-point representation of the exponent of the input argument \p x. + * + * \return + * - logbf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly. + * - logbf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float logbf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl logbf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Compute the unbiased integer exponent of the argument. + * + * Calculates the unbiased integer exponent of the input argument \p x. + * + * \return + * - If successful, returns the unbiased exponent of the argument. + * - ilogb( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns INT_MIN. + * - ilogb(NaN) returns INT_MIN. + * - ilogb( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns INT_MAX. + * - Note: above behavior does not take into account FP_ILOGB0 nor FP_ILOGBNAN. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int ilogb(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP int __cdecl ilogb(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Compute the unbiased integer exponent of the argument. + * + * Calculates the unbiased integer exponent of the input argument \p x. + * + * \return + * - If successful, returns the unbiased exponent of the argument. + * - ilogbf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns INT_MIN. + * - ilogbf(NaN) returns INT_MIN. + * - ilogbf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns INT_MAX. + * - Note: above behavior does not take into account FP_ILOGB0 nor FP_ILOGBNAN. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int ilogbf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP int __cdecl ilogbf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Scale floating-point input by integer power of two. + * + * Scale \p x by + * \latexonly $2^n$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * n + * + * + * + * \endxmlonly + * by efficient manipulation of the floating-point + * exponent. + * + * \return + * Returns \p x * + * \latexonly $2^n$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * n + * + * + * \endxmlonly. + * - scalbn( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p n) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - scalbn(\p x, 0) returns \p x. + * - scalbn( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p n) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double scalbn(double x, int n) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl scalbn(double x, int n); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Scale floating-point input by integer power of two. + * + * Scale \p x by + * \latexonly $2^n$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * n + * + * + * + * \endxmlonly + * by efficient manipulation of the floating-point + * exponent. + * + * \return + * Returns \p x * + * \latexonly $2^n$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * n + * + * + * \endxmlonly. + * - scalbnf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p n) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - scalbnf(\p x, 0) returns \p x. + * - scalbnf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p n) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float scalbnf(float x, int n) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl scalbnf(float x, int n); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Scale floating-point input by integer power of two. + * + * Scale \p x by + * \latexonly $2^n$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * n + * + * + * + * \endxmlonly + * by efficient manipulation of the floating-point + * exponent. + * + * \return + * Returns \p x * + * \latexonly $2^n$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * n + * + * + * \endxmlonly. + * - scalbln( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p n) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - scalbln(\p x, 0) returns \p x. + * - scalbln( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p n) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double scalbln(double x, long int n) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl scalbln(double x, long int n); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Scale floating-point input by integer power of two. + * + * Scale \p x by + * \latexonly $2^n$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * n + * + * + * + * \endxmlonly + * by efficient manipulation of the floating-point + * exponent. + * + * \return + * Returns \p x * + * \latexonly $2^n$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * n + * + * + * \endxmlonly. + * - scalblnf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p n) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - scalblnf(\p x, 0) returns \p x. + * - scalblnf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p n) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float scalblnf(float x, long int n) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl scalblnf(float x, long int n); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Extract mantissa and exponent of a floating-point value + * + * Decompose the floating-point value \p x into a component \p m for the + * normalized fraction element and another term \p n for the exponent. + * The absolute value of \p m will be greater than or equal to 0.5 and + * less than 1.0 or it will be equal to 0; + * \latexonly $x = m\cdot 2^n$ \endlatexonly + * \xmlonly + * + * + * x + * = + * m + * ⋅ + * + * 2 + * n + * + * + * \endxmlonly. + * The integer exponent \p n will be stored in the location to which \p nptr points. + * + * \return + * Returns the fractional component \p m. + * - frexp( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p nptr) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * and stores zero in the location pointed to by \p nptr. + * - frexp( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p nptr) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * and stores an unspecified value in the + * location to which \p nptr points. + * - frexp(NaN, \p y) returns a NaN and stores an unspecified value in the location to which \p nptr points. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl frexp(double x, int *nptr) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Extract mantissa and exponent of a floating-point value + * + * Decomposes the floating-point value \p x into a component \p m for the + * normalized fraction element and another term \p n for the exponent. + * The absolute value of \p m will be greater than or equal to 0.5 and + * less than 1.0 or it will be equal to 0; + * \latexonly $x = m\cdot 2^n$ \endlatexonly + * \xmlonly + * + * + * x + * = + * m + * ⋅ + * + * 2 + * n + * + * + * \endxmlonly. + * The integer exponent \p n will be stored in the location to which \p nptr points. + * + * \return + * Returns the fractional component \p m. + * - frexpf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p nptr) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * and stores zero in the location pointed to by \p nptr. + * - frexpf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p nptr) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * and stores an unspecified value in the + * location to which \p nptr points. + * - frexpf(NaN, \p y) returns a NaN and stores an unspecified value in the location to which \p nptr points. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float frexpf(float x, int *nptr) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Round to nearest integer value in floating-point. + * + * Round \p x to the nearest integer value in floating-point format, + * with halfway cases rounded away from zero. + * + * \return + * Returns rounded integer value. + * - round( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - round( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * + * \note_slow_round See ::rint(). + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double round(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl round(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Round to nearest integer value in floating-point. + * + * Round \p x to the nearest integer value in floating-point format, + * with halfway cases rounded away from zero. + * + * \return + * Returns rounded integer value. + * - roundf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - roundf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * + * \note_slow_round See ::rintf(). + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float roundf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl roundf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Round to nearest integer value. + * + * Round \p x to the nearest integer value, with halfway cases rounded + * away from zero. If the result is outside the range of the return type, + * the behavior is undefined. + * + * \return + * Returns rounded integer value. + * + * \note_slow_round See ::lrint(). + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ long int lround(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP long int __cdecl lround(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Round to nearest integer value. + * + * Round \p x to the nearest integer value, with halfway cases rounded + * away from zero. If the result is outside the range of the return type, + * the behavior is undefined. + * + * \return + * Returns rounded integer value. + * + * \note_slow_round See ::lrintf(). + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ long int lroundf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP long int __cdecl lroundf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Round to nearest integer value. + * + * Round \p x to the nearest integer value, with halfway cases rounded + * away from zero. If the result is outside the range of the return type, + * the behavior is undefined. + * + * \return + * Returns rounded integer value. + * + * \note_slow_round See ::llrint(). + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int llround(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP long long int __cdecl llround(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Round to nearest integer value. + * + * Round \p x to the nearest integer value, with halfway cases rounded + * away from zero. If the result is outside the range of the return type, + * the behavior is undefined. + * + * \return + * Returns rounded integer value. + * + * \note_slow_round See ::llrintf(). + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int llroundf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP long long int __cdecl llroundf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Round to nearest integer value in floating-point. + * + * Round \p x to the nearest integer value in floating-point format, + * with halfway cases rounded to the nearest even integer value. + * + * \return + * Returns rounded integer value. + * - rint( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - rint( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + */ +#if defined(__CUDA_ARCH__) || defined(__DOXYGEN_ONLY__) +/* + * We don't generate the declaration of rint for host compilation. + * This is acaully a workaround to compile the boost header file when + * Clang 3.8 is used as the host compiler. The boost header file has + * the following example code: + * namespace NS { extern "C" { double rint(double); } + * } + * + * After preprocessing, we get something like below: + * + * extern "C" { double rint(double x) throw(); } + * # 30 "/usr/include/math.h" 3 + * extern "C" { double rint(double x) throw(); } + * namespace NS { extern "C" { double rint(double); } } + * + * Although GCC accepts this output, Clang 3.8 doesn't. + * Furthermore, we cannot change the boost header file by adding "throw()" + * to rint's declaration there. So, as a workaround, we just don't generate + * our re-declaration for the host compilation. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double rint(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl rint(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#endif /* __CUDA_ARCH__ || __DOXYGEN_ONLY__ */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Round input to nearest integer value in floating-point. + * + * Round \p x to the nearest integer value in floating-point format, + * with halfway cases rounded to the nearest even integer value. + * + * \return + * Returns rounded integer value. + * - rintf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - rintf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float rintf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl rintf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Round input to nearest integer value. + * + * Round \p x to the nearest integer value, + * with halfway cases rounded to the nearest even integer value. + * If the result is outside the range of the return type, + * the behavior is undefined. + * + * \return + * Returns rounded integer value. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ long int lrint(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP long int __cdecl lrint(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Round input to nearest integer value. + * + * Round \p x to the nearest integer value, + * with halfway cases rounded to the nearest even integer value. + * If the result is outside the range of the return type, + * the behavior is undefined. + * + * \return + * Returns rounded integer value. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ long int lrintf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP long int __cdecl lrintf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Round input to nearest integer value. + * + * Round \p x to the nearest integer value, + * with halfway cases rounded to the nearest even integer value. + * If the result is outside the range of the return type, + * the behavior is undefined. + * + * \return + * Returns rounded integer value. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int llrint(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP long long int __cdecl llrint(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Round input to nearest integer value. + * + * Round \p x to the nearest integer value, + * with halfway cases rounded to the nearest even integer value. + * If the result is outside the range of the return type, + * the behavior is undefined. + * + * \return + * Returns rounded integer value. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ long long int llrintf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP long long int __cdecl llrintf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Round the input argument to the nearest integer. + * + * Round argument \p x to an integer value in double precision floating-point format. Uses round to nearest rounding, with ties rounding to even. + * + * \return + * - nearbyint( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - nearbyint( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double nearbyint(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl nearbyint(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Round the input argument to the nearest integer. + * + * Round argument \p x to an integer value in single precision floating-point format. Uses round to nearest rounding, with ties rounding to even. + * + * \return + * - nearbyintf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - nearbyintf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float nearbyintf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl nearbyintf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate ceiling of the input argument. + * + * Compute the smallest integer value not less than \p x. + * + * \return + * Returns + * \latexonly $\lceil x \rceil$ \endlatexonly + * \xmlonly + * + * + * ⌈ + * x + * ⌉ + * + * + * \endxmlonly + expressed as a floating-point number. + * - ceil( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - ceil( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl ceil(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Truncate input argument to the integral part. + * + * Round \p x to the nearest integer value that does not exceed \p x in + * magnitude. + * + * \return + * Returns truncated integer value. + * - trunc( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - trunc( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double trunc(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl trunc(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Truncate input argument to the integral part. + * + * Round \p x to the nearest integer value that does not exceed \p x in + * magnitude. + * + * \return + * Returns truncated integer value. + * - truncf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - truncf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float truncf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl truncf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Compute the positive difference between \p x and \p y. + * + * Compute the positive difference between \p x and \p y. The positive + * difference is \p x - \p y when \p x > \p y and +0 otherwise. + * + * \return + * Returns the positive difference between \p x and \p y. + * - fdim(\p x, \p y) returns \p x - \p y if \p x > \p y. + * - fdim(\p x, \p y) returns +0 if \p x + * \latexonly $\leq$ \endlatexonly + * \xmlonly + * + * + * ≤ + * + * + * \endxmlonly \p y. + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double fdim(double x, double y) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl fdim(double x, double y); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Compute the positive difference between \p x and \p y. + * + * Compute the positive difference between \p x and \p y. The positive + * difference is \p x - \p y when \p x > \p y and +0 otherwise. + * + * \return + * Returns the positive difference between \p x and \p y. + * - fdimf(\p x, \p y) returns \p x - \p y if \p x > \p y. + * - fdimf(\p x, \p y) returns +0 if \p x + * \latexonly $\leq$ \endlatexonly + * \xmlonly + * + * + * ≤ + * + * + * \endxmlonly \p y. + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float fdimf(float x, float y) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl fdimf(float x, float y); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the arc tangent of the ratio of first and second input arguments. + * + * Calculate the principal value of the arc tangent of the ratio of first + * and second input arguments \p y / \p x. The quadrant of the result is + * determined by the signs of inputs \p y and \p x. + * + * \return + * Result will be in radians, in the interval [- + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * , + + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * ]. + * - atan2( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , -0) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly. + * - atan2( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , +0) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - atan2( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p x) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly + * for \p x < 0. + * - atan2( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p x) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * for \p x > 0. + * - atan2(\p y, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\pi$ \endlatexonly + * \xmlonly + * + * + * - + * π + * + * + * \endxmlonly + * /2 for \p y < 0. + * - atan2(\p y, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * /2 for \p y > 0. + * - atan2( + * \latexonly $\pm y$ \endlatexonly + * \xmlonly + * + * + * ± + * y + * + * + * \endxmlonly + * , + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly + * for finite \p y > 0. + * - atan2( + * \latexonly $\pm y$ \endlatexonly + * \xmlonly + * + * + * ± + * y + * + * + * \endxmlonly + * , + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * for finite \p y > 0. + * - atan2( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p x) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly + * /2 for finite \p x. + * - atan2( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $\pm 3\pi$ \endlatexonly + * \xmlonly + * + * + * ± + * 3 + * π + * + * + * \endxmlonly + * /4. + * - atan2( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly + * /4. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl atan2(double y, double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the arc tangent of the input argument. + * + * Calculate the principal value of the arc tangent of the input argument \p x. + * + * \return + * Result will be in radians, in the interval [- + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * /2, + + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * /2]. + * - atan( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - atan( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly + * /2. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl atan(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the arc cosine of the input argument. + * + * Calculate the principal value of the arc cosine of the input argument \p x. + * + * \return + * Result will be in radians, in the interval [0, + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * ] for \p x inside [-1, +1]. + * - acos(1) returns +0. + * - acos(\p x) returns NaN for \p x outside [-1, +1]. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl acos(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the arc sine of the input argument. + * + * Calculate the principal value of the arc sine of the input argument \p x. + * + * \return + * Result will be in radians, in the interval [- + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * /2, + + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * /2] for \p x inside [-1, +1]. + * - asin( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - asin(\p x) returns NaN for \p x outside [-1, +1]. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl asin(double x) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the square root of the sum of squares of two arguments. + * + * Calculate the length of the hypotenuse of a right triangle whose two sides have lengths + * \p x and \p y without undue overflow or underflow. + * + * \return Returns the length of the hypotenuse + * \latexonly $\sqrt{x^2+y^2}$ \endlatexonly + * \xmlonly + * + * + * + * + * x + * 2 + * + * + + * + * y + * 2 + * + * + * + * \endxmlonly. + * - hypot(\p x,\p y), hypot(\p y,\p x), and hypot(\p x, \p -y) are equivalent. + * - hypot(\p x, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) is equivalent to fabs(\p x). + * - hypot( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ,\p y) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly, + * even if \p y is a NaN. + * + * \note_accuracy_double + */ +#if defined(_WIN32) +#if defined(_MSC_VER) && _MSC_VER < 1900 +static __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __CRTDECL hypot(double x, double y); +#else +extern _ACRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl hypot(double x, double y); +#endif +#else /* _WIN32 */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double hypot(double x, double y) __THROW; +#endif /* _WIN32 */ + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate one over the square root of the sum of squares of two arguments. + * + * Calculate one over the length of the hypotenuse of a right triangle whose two sides have + * lengths \p x and \p y without undue overflow or underflow. + * + * \return Returns one over the length of the hypotenuse + * \latexonly $\frac{1}{\sqrt{x^2+y^2}}$ \endlatexonly + * \xmlonly + * + * + * + * + * 1 + * + * + * + * + * x + * 2 + * + * + + * + * y + * 2 + * + * + * + * + * + * \endxmlonly. + * - rhypot(\p x,\p y), rhypot(\p y,\p x), and rhypot(\p x, \p -y) are equivalent. + * - rhypot( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ,\p y) returns +0, + * even if \p y is a NaN. + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ double rhypot(double x, double y) __THROW; + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the square root of the sum of squares of two arguments. + * + * Calculates the length of the hypotenuse of a right triangle whose two sides have lengths + * \p x and \p y without undue overflow or underflow. + * + * \return Returns the length of the hypotenuse + * \latexonly $\sqrt{x^2+y^2}$ \endlatexonly + * \xmlonly + * + * + * + * + * x + * 2 + * + * + + * + * y + * 2 + * + * + * + * \endxmlonly. + * - hypotf(\p x,\p y), hypotf(\p y,\p x), and hypotf(\p x, \p -y) are equivalent. + * - hypotf(\p x, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) is equivalent to fabsf(\p x). + * - hypotf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ,\p y) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly, + * even if \p y is a NaN. + * + * \note_accuracy_single + */ +#if defined(_WIN32) +static __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __CRTDECL hypotf(float x, float y); +#else /* _WIN32 */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float hypotf(float x, float y) __THROW; +#endif /* _WIN32 */ + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate one over the square root of the sum of squares of two arguments. + * + * Calculates one over the length of the hypotenuse of a right triangle whose two sides have + * lengths \p x and \p y without undue overflow or underflow. + * + * \return Returns one over the length of the hypotenuse + * \latexonly $\frac{1}{\sqrt{x^2+y^2}}$ \endlatexonly + * \xmlonly + * + * + * + * + * 1 + * + * + * + * + * x + * 2 + * + * + + * + * y + * 2 + * + * + * + * + * + * \endxmlonly. + * - rhypotf(\p x,\p y), rhypotf(\p y,\p x), and rhypotf(\p x, \p -y) are equivalent. + * - rhypotf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ,\p y) returns +0, + * even if \p y is a NaN. + * + * \note_accuracy_single + */ +extern __device__ __device_builtin__ float rhypotf(float x, float y) __THROW; + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the square root of the sum of squares of three coordinates of the argument. + * + * Calculate the length of three dimensional vector in Euclidean space without undue overflow or underflow. + * + * \return Returns the length of 3D vector + * \latexonly $\sqrt{a^2+b^2+c^2}$ \endlatexonly + * \xmlonly + * + * + * + * + * a + * 2 + * + * + + * + * b + * 2 + * + * + + * + * c + * 2 + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl norm3d(double a, double b, double c) __THROW; + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate one over the square root of the sum of squares of three coordinates. + * + * Calculate one over the length of three dimensional vector in Euclidean space without undue overflow or underflow. + * + * \return Returns one over the length of the 3D vector + * \latexonly $\frac{1}{\sqrt{a^2+b^2+c^2}}$ \endlatexonly + * \xmlonly + * + * + * + * + * 1 + * + * + * + * + * a + * 2 + * + * + + * + * b + * 2 + * + * + + * + * c + * 2 + * + * + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+0$ \endlatexonly + * \xmlonly + * + * + * + + * 0 + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ double rnorm3d(double a, double b, double c) __THROW; + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the square root of the sum of squares of four coordinates of the argument. + * + * Calculate the length of four dimensional vector in Euclidean space without undue overflow or underflow. + * + * \return Returns the length of 4D vector + * \latexonly $\sqrt{a^2+b^2+c^2+d^2}$ \endlatexonly + * \xmlonly + * + * + * + * + * a + * 2 + * + * + + * + * b + * 2 + * + * + + * + * c + * 2 + * + * + + * + * d + * 2 + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl norm4d(double a, double b, double c, double d) __THROW; + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate one over the square root of the sum of squares of four coordinates. + * + * Calculate one over the length of four dimensional vector in Euclidean space without undue overflow or underflow. + * + * \return Returns one over the length of the 3D vector + * \latexonly $\frac{1}{\sqrt{a^2+b^2+c^2+d^2}}$ \endlatexonly + * \xmlonly + * + * + * + * + * 1 + * + * + * + * + * + * 2 + * + * + + * + * b + * 2 + * + * + + * + * c + * 2 + * + * + + * + * d + * 2 + * + * + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+0$ \endlatexonly + * \xmlonly + * + * + * + + * 0 + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ double rnorm4d(double a, double b, double c, double d) __THROW; + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the square root of the sum of squares of any number of coordinates. + * + * Calculate the length of a vector p, dimension of which is passed as an argument \p without undue overflow or underflow. + * + * \return Returns the length of the dim-D vector + * \latexonly $\sqrt{\sum_{i=0}^{dim-1} p_i^2}$ \endlatexonly + * \xmlonly + * + * + * + * + * + * p + * 0 + * + * 2 + * + * + + * + * + * p + * 1 + * + * 2 + * + * + ... + + * + * + * p + * + * dim + * - + * 1 + * + * + * 2 + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_double + */ +extern "C++" __device__ __device_builtin__ double norm(int dim, double const * p) __THROW; + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the reciprocal of square root of the sum of squares of any number of coordinates. + * + * Calculates one over the length of vector \p p, dimension of which is passed as an argument, in Euclidean space without undue overflow or underflow. + * + * \return Returns one over the length of the vector + * \latexonly $\frac{1}{\sqrt{\sum_{i=0}^{dim-1} p_i^2}$ \endlatexonly + * \xmlonly + * + * + * + * + * 1 + * + * + * + * + * + * p + * 0 + * + * 2 + * + * + + * + * + * p + * 1 + * + * 2 + * + * + ... + + * + * + * p + * + * dim + * - + * 1 + * + * + * 2 + * + * + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+0$ \endlatexonly + * \xmlonly + * + * + * + + * 0 + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ double rnorm(int dim, double const * p) __THROW; + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the reciprocal of square root of the sum of squares of any number of coordinates. + * + * Calculates one over the length of vector \p p, dimension of which is passed as an argument, in Euclidean space without undue overflow or underflow. + * + * \return Returns one over the length of the vector + * \latexonly $\frac{1}{\sqrt{\sum_{i=0}^{dim-1} p_i^2}$ \endlatexonly + * \xmlonly + * + * + * + * + * 1 + * + * + * + * + * + * p + * 0 + * + * 2 + * + * + + * + * + * p + * 1 + * + * 2 + * + * + ... + + * + * + * p + * + * dim + * - + * 1 + * + * + * 2 + * + * + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+0$ \endlatexonly + * \xmlonly + * + * + * + + * 0 + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_single + */ + +extern __device__ __device_builtin__ float rnormf(int dim, float const * p) __THROW; + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the square root of the sum of squares of any number of coordinates. + * + * Calculates the length of a vector \p p, dimension of which is passed as an argument without undue overflow or underflow. + * + * \return Returns the length of the dim-D vector + * \latexonly $\sqrt{\sum_{i=0}^{dim-1} p_i^2}$ \endlatexonly + * \xmlonly + * + * + * + * + * + * p + * 0 + * + * 2 + * + * + + * + * + * p + * 1 + * + * 2 + * + * + ... + + * + * + * p + * + * dim + * - + * 1 + * + * + * 2 + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_single + */ +extern "C++" __device__ __device_builtin__ float normf(int dim, float const * p) __THROW; + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the square root of the sum of squares of three coordinates of the argument. + * + * Calculates the length of three dimensional vector in Euclidean space without undue overflow or underflow. + * + * \return Returns the length of the 3D vector + * \latexonly $\sqrt{a^2+b^2+c^2}$ \endlatexonly + * \xmlonly + * + * + * + * + * a + * 2 + * + * + + * + * b + * 2 + * + * + + * + * c + * 2 + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_single + */ + +extern __device__ __device_builtin__ float norm3df(float a, float b, float c) __THROW; + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate one over the square root of the sum of squares of three coordinates. + * + * Calculates one over the length of three dimension vector in Euclidean space without undue overflow or underflow. + * + * \return Returns one over the length of the 3D vector + * \latexonly $\frac{1}{\sqrt{a^2+b^2+c^2}}$ \endlatexonly + * \xmlonly + * + * + * + * + * 1 + * + * + * + * + * a + * 2 + * + * + + * + * b + * 2 + * + * + + * + * c + * 2 + * + * + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+0$ \endlatexonly + * \xmlonly + * + * + * + + * 0 + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_single + */ +extern __device__ __device_builtin__ float rnorm3df(float a, float b, float c) __THROW; + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the square root of the sum of squares of four coordinates of the argument. + * + * Calculates the length of four dimensional vector in Euclidean space without undue overflow or underflow. + * + * \return Returns the length of the 4D vector + * \latexonly $\sqrt{a^2+b^2+c^2+d^2}$ \endlatexonly + * \xmlonly + * + * + * + * + * a + * 2 + * + * + + * + * b + * 2 + * + * + + * + * c + * 2 + * + * + + * + * d + * 2 + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_single + */ +extern __device__ __device_builtin__ float norm4df(float a, float b, float c, float d) __THROW; + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate one over the square root of the sum of squares of four coordinates. + * + * Calculates one over the length of four dimension vector in Euclidean space without undue overflow or underflow. + * + * \return Returns one over the length of the 3D vector + * \latexonly $\frac{1}{\sqrt{a^2+b^2+c^2+d^2}}$ \endlatexonly + * \xmlonly + * + * + * + * + * 1 + * + * + * + * + * a + * 2 + * + * + + * + * b + * 2 + * + * + + * + * c + * 2 + * + * + + * + * d + * 2 + * + * + * + * + * + * \endxmlonly. + * - In the presence of an exactly infinite coordinate + * \latexonly $+0$ \endlatexonly + * \xmlonly + * + * + * + + * 0 + * + * \endxmlonly + * is returned, even if there are NaNs. + * + * \note_accuracy_single + */ +extern __device__ __device_builtin__ float rnorm4df(float a, float b, float c, float d) __THROW; + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the cube root of the input argument. + * + * Calculate the cube root of \p x, + * \latexonly $x^{1/3}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * 1 + * + * / + * + * 3 + * + * + * + * \endxmlonly. + * + * \return + * Returns + * \latexonly $x^{1/3}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * 1 + * + * / + * + * 3 + * + * + * + * \endxmlonly. + * - cbrt( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - cbrt( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double cbrt(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl cbrt(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the cube root of the input argument. + * + * Calculate the cube root of \p x, + * \latexonly $x^{1/3}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * 1 + * + * / + * + * 3 + * + * + * + * \endxmlonly. + * + * \return + * Returns + * \latexonly $x^{1/3}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * 1 + * + * / + * + * 3 + * + * + * + * \endxmlonly. + * - cbrtf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - cbrtf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float cbrtf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl cbrtf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate reciprocal cube root function. + * + * Calculate reciprocal cube root function of \p x. + * + * \return + * - rcbrt( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * - rcbrt( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double rcbrt(double x); + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate reciprocal cube root function. + * + * Calculate reciprocal cube root function of \p x. + * + * \return + * - rcbrt( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * - rcbrt( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float rcbrtf(float x); +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the sine of the input argument + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * \endxmlonly. + * + * Calculate the sine of \p x + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * + * \endxmlonly + * (measured in radians), + * where \p x is the input argument. + * + * \return + * - sinpi( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - sinpi( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double sinpi(double x); +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the sine of the input argument + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * \endxmlonly. + * + * Calculate the sine of \p x + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * + * \endxmlonly + * (measured in radians), + * where \p x is the input argument. + * + * \return + * - sinpif( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - sinpif( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float sinpif(float x); +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the cosine of the input argument + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * \endxmlonly. + * + * Calculate the cosine of \p x + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * + * \endxmlonly + * (measured in radians), + * where \p x is the input argument. + * + * \return + * - cospi( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - cospi( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double cospi(double x); +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the cosine of the input argument + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * \endxmlonly. + * + * Calculate the cosine of \p x + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * + * \endxmlonly + * (measured in radians), + * where \p x is the input argument. + * + * \return + * - cospif( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - cospif( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float cospif(float x); +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the sine and cosine of the first input argument + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * \endxmlonly. + * + * Calculate the sine and cosine of the first input argument, \p x (measured in radians), + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * \endxmlonly. The results for sine and cosine are written into the + * second argument, \p sptr, and, respectively, third argument, \p cptr. + * + * \return + * - none + * + * \see ::sinpi() and ::cospi(). + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ void sincospi(double x, double *sptr, double *cptr); +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the sine and cosine of the first input argument + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * \endxmlonly. + * + * Calculate the sine and cosine of the first input argument, \p x (measured in radians), + * \latexonly $\times \pi$ \endlatexonly + * \xmlonly + * + * + * × + * π + * + * \endxmlonly. The results for sine and cosine are written into the + * second argument, \p sptr, and, respectively, third argument, \p cptr. + * + * \return + * - none + * + * \see ::sinpif() and ::cospif(). + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ void sincospif(float x, float *sptr, float *cptr); + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the value of first argument to the power of second argument. + * + * Calculate the value of \p x to the power of \p y. + * + * \return + * - pow( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * for \p y an odd integer less than 0. + * - pow( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * +* + + * ∞ + * + * + * \endxmlonly + * for \p y less than 0 and not an odd integer. + * - pow( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * for \p y an odd integer greater than 0. + * - pow( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p y) returns +0 for \p y > 0 and not an odd integer. + * - pow(-1, + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns 1. + * - pow(+1, \p y) returns 1 for any \p y, even a NaN. + * - pow(\p x, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1 for any \p x, even a NaN. + * - pow(\p x, \p y) returns a NaN for finite \p x < 0 and finite non-integer \p y. + * - pow(\p x, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * for + * \latexonly $| x | < 1$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * + * | + * + * < + * 1 + * + * \endxmlonly. + * - pow(\p x, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns +0 for + * \latexonly $| x | > 1$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * + * | + * + * > + * 1 + * + * \endxmlonly. + * - pow(\p x, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0 for + * \latexonly $| x | < 1$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * + * | + * + * < + * 1 + * + * \endxmlonly. + * - pow(\p x, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * for + * \latexonly $| x | > 1$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * + * | + * + * > + * 1 + * + * \endxmlonly. + * - pow( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * , \p y) returns -0 for \p y an odd integer less than 0. + * - pow( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * , \p y) returns +0 for \p y < 0 and not an odd integer. + * - pow( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * for \p y an odd integer greater than 0. + * - pow( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * for \p y > 0 and not an odd integer. + * - pow( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * , \p y) returns +0 for \p y < 0. + * - pow( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * for \p y > 0. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl pow(double x, double y) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Break down the input argument into fractional and integral parts. + * + * Break down the argument \p x into fractional and integral parts. The + * integral part is stored in the argument \p iptr. + * Fractional and integral parts are given the same sign as the argument \p x. + * + * \return + * - modf( + * \latexonly $\pm x$ \endlatexonly + * \xmlonly + * + * + * ± + * x + * + * + * \endxmlonly + * , \p iptr) returns a result with the same sign as \p x. + * - modf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p iptr) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * and stores + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * in the object pointed to by \p iptr. + * - modf(NaN, \p iptr) stores a NaN in the object pointed to by \p iptr and returns a NaN. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl modf(double x, double *iptr) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the double-precision floating-point remainder of \p x / \p y. + * + * Calculate the double-precision floating-point remainder of \p x / \p y. + * The floating-point remainder of the division operation \p x / \p y calculated + * by this function is exactly the value x - n*y, where \p n is \p x / \p y with its fractional part truncated. + * The computed value will have the same sign as \p x, and its magnitude will be less than the magnitude of \p y. + * + * \return + * - Returns the floating-point remainder of \p x / \p y. + * - fmod( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * if \p y is not zero. + * - fmod(\p x, + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns \p x if \p x is finite. + * - fmod(\p x, \p y) returns NaN if \p x is + * \latexonly $\pm\infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * or \p y is zero. + * - If either argument is NaN, NaN is returned. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double __cdecl fmod(double x, double y) __THROW; +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Compute double-precision floating-point remainder. + * + * Compute double-precision floating-point remainder \p r of dividing + * \p x by \p y for nonzero \p y. Thus + * \latexonly $ r = x - n y$ \endlatexonly + * \xmlonly + * + * + * r + * = + * x + * − + * n + * y + * + * \endxmlonly. + * The value \p n is the integer value nearest + * \latexonly $ \frac{x}{y} $ \endlatexonly + * \xmlonly + * + * + * + * x + * y + * + * + * \endxmlonly. + * In the case when + * \latexonly $ | n -\frac{x}{y} | = \frac{1}{2} $ \endlatexonly + * \xmlonly + * + * + * + * | + * + * n + * − + * + * x + * y + * + * + * | + * + * = + * + * 1 + * 2 + * + * + * + * \endxmlonly + * , the + * even \p n value is chosen. + * + * \return + * - remainder(\p x, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns NaN. + * - remainder( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p y) returns NaN. + * - remainder(\p x, + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns \p x for finite \p x. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double remainder(double x, double y) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl remainder(double x, double y); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Compute single-precision floating-point remainder. + * + * Compute single-precision floating-point remainder \p r of dividing + * \p x by \p y for nonzero \p y. Thus + * \latexonly $ r = x - n y$ \endlatexonly + * \xmlonly + * + * + * r + * = + * x + * − + * n + * y + * + * \endxmlonly. + * The value \p n is the integer value nearest + * \latexonly $ \frac{x}{y} $ \endlatexonly + * \xmlonly + * + * + * + * x + * y + * + * + * \endxmlonly. + * In the case when + * \latexonly $ | n -\frac{x}{y} | = \frac{1}{2} $ \endlatexonly + * \xmlonly + * + * + * + * | + * + * n + * − + * + * x + * y + * + * + * | + * + * = + * + * 1 + * 2 + * + * + * + * \endxmlonly + * , the + * even \p n value is chosen. + * + * \return + * - remainderf(\p x, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns NaN. + * - remainderf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p y) returns NaN. + * - remainderf(\p x, + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns \p x for finite \p x. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float remainderf(float x, float y) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl remainderf(float x, float y); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Compute double-precision floating-point remainder and part of quotient. + * + * Compute a double-precision floating-point remainder in the same way as the + * ::remainder() function. Argument \p quo returns part of quotient upon + * division of \p x by \p y. Value \p quo has the same sign as + * \latexonly $ \frac{x}{y} $ \endlatexonly + * \xmlonly + * + * + * + * x + * y + * + * + * + * \endxmlonly + * and may not be the exact quotient but agrees with the exact quotient + * in the low order 3 bits. + * + * \return + * Returns the remainder. + * - remquo(\p x, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p quo) returns NaN + * and stores an unspecified value in the + * location to which \p quo points. + * - remquo( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p y, \p quo) returns NaN + * and stores an unspecified value in the + * location to which \p quo points. + * - remquo(\p x, \p y, \p quo) returns NaN + * and stores an unspecified value in the + * location to which \p quo points if either of \p x or \p y is NaN. + * - remquo(\p x, + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p quo) returns \p x and stores zero + * in the location to which \p quo points for finite \p x. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double remquo(double x, double y, int *quo) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl remquo(double x, double y, int *quo); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Compute single-precision floating-point remainder and part of quotient. + * + * Compute a single-precision floating-point remainder in the same way as the + * ::remainderf() function. Argument \p quo returns part of quotient upon + * division of \p x by \p y. Value \p quo has the same sign as + * \latexonly $ \frac{x}{y} $ \endlatexonly + * \xmlonly + * + * + * + * x + * y + * + * + * + * \endxmlonly + * and may not be the exact quotient but agrees with the exact quotient + * in the low order 3 bits. + * + * \return + * Returns the remainder. + * - remquof(\p x, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p quo) returns NaN + * and stores an unspecified value in the + * location to which \p quo points. + * - remquof( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p y, \p quo) returns NaN + * and stores an unspecified value in the + * location to which \p quo points. + * - remquof(\p x, \p y, \p quo) returns NaN + * and stores an unspecified value in the + * location to which \p quo points if either of \p x or \p y is NaN. + * - remquof(\p x, + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p quo) returns \p x and stores zero + * in the location to which \p quo points for finite \p x. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float remquof(float x, float y, int *quo) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl remquof(float x, float y, int *quo); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the value of the Bessel function of the first kind of order 0 for the input argument. + * + * Calculate the value of the Bessel function of the first kind of order 0 for + * the input argument \p x, + * \latexonly $J_0(x)$ \endlatexonly + * \xmlonly + * + * + * + * J + * 0 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the first kind of order 0. + * - j0( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * - j0(NaN) returns NaN. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl j0(double x) __THROW; +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the value of the Bessel function of the first kind of order 0 for the input argument. + * + * Calculate the value of the Bessel function of the first kind of order 0 for + * the input argument \p x, + * \latexonly $J_0(x)$ \endlatexonly + * \xmlonly + * + * + * + * J + * 0 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the first kind of order 0. + * - j0f( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * - j0f(NaN) returns NaN. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float j0f(float x) __THROW; + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the value of the Bessel function of the first kind of order 1 for the input argument. + * + * Calculate the value of the Bessel function of the first kind of order 1 for + * the input argument \p x, + * \latexonly $J_1(x)$ \endlatexonly + * \xmlonly + * + * + * + * J + * 1 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the first kind of order 1. + * - j1( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - j1( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - j1(NaN) returns NaN. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl j1(double x) __THROW; +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the value of the Bessel function of the first kind of order 1 for the input argument. + * + * Calculate the value of the Bessel function of the first kind of order 1 for + * the input argument \p x, + * \latexonly $J_1(x)$ \endlatexonly + * \xmlonly + * + * + * + * J + * 1 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the first kind of order 1. + * - j1f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - j1f( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - j1f(NaN) returns NaN. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float j1f(float x) __THROW; + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the value of the Bessel function of the first kind of order n for the input argument. + * + * Calculate the value of the Bessel function of the first kind of order \p n for + * the input argument \p x, + * \latexonly $J_n(x)$ \endlatexonly + * \xmlonly + * + * + * + * J + * n + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the first kind of order \p n. + * - jn(\p n, NaN) returns NaN. + * - jn(\p n, \p x) returns NaN for \p n < 0. + * - jn(\p n, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl jn(int n, double x) __THROW; +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the value of the Bessel function of the first kind of order n for the input argument. + * + * Calculate the value of the Bessel function of the first kind of order \p n for + * the input argument \p x, + * \latexonly $J_n(x)$ \endlatexonly + * \xmlonly + * + * + * + * J + * n + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the first kind of order \p n. + * - jnf(\p n, NaN) returns NaN. + * - jnf(\p n, \p x) returns NaN for \p n < 0. + * - jnf(\p n, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float jnf(int n, float x) __THROW; + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the value of the Bessel function of the second kind of order 0 for the input argument. + * + * Calculate the value of the Bessel function of the second kind of order 0 for + * the input argument \p x, + * \latexonly $Y_0(x)$ \endlatexonly + * \xmlonly + * + * + * + * Y + * 0 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the second kind of order 0. + * - y0( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - y0(\p x) returns NaN for \p x < 0. + * - y0( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * - y0(NaN) returns NaN. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl y0(double x) __THROW; +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the value of the Bessel function of the second kind of order 0 for the input argument. + * + * Calculate the value of the Bessel function of the second kind of order 0 for + * the input argument \p x, + * \latexonly $Y_0(x)$ \endlatexonly + * \xmlonly + * + * + * + * Y + * 0 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the second kind of order 0. + * - y0f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - y0f(\p x) returns NaN for \p x < 0. + * - y0f( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * - y0f(NaN) returns NaN. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float y0f(float x) __THROW; + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the value of the Bessel function of the second kind of order 1 for the input argument. + * + * Calculate the value of the Bessel function of the second kind of order 1 for + * the input argument \p x, + * \latexonly $Y_1(x)$ \endlatexonly + * \xmlonly + * + * + * + * Y + * 1 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the second kind of order 1. + * - y1( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - y1(\p x) returns NaN for \p x < 0. + * - y1( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * - y1(NaN) returns NaN. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl y1(double x) __THROW; +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the value of the Bessel function of the second kind of order 1 for the input argument. + * + * Calculate the value of the Bessel function of the second kind of order 1 for + * the input argument \p x, + * \latexonly $Y_1(x)$ \endlatexonly + * \xmlonly + * + * + * + * Y + * 1 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the second kind of order 1. + * - y1f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - y1f(\p x) returns NaN for \p x < 0. + * - y1f( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * - y1f(NaN) returns NaN. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float y1f(float x) __THROW; + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the value of the Bessel function of the second kind of order n for the input argument. + * + * Calculate the value of the Bessel function of the second kind of order \p n for + * the input argument \p x, + * \latexonly $Y_n(x)$ \endlatexonly + * \xmlonly + * + * + * + * Y + * n + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the second kind of order \p n. + * - yn(\p n, \p x) returns NaN for \p n < 0. + * - yn(\p n, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + *) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - yn(\p n, \p x) returns NaN for \p x < 0. + * - yn(\p n, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * - yn(\p n, NaN) returns NaN. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl yn(int n, double x) __THROW; +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the value of the Bessel function of the second kind of order n for the input argument. + * + * Calculate the value of the Bessel function of the second kind of order \p n for + * the input argument \p x, + * \latexonly $Y_n(x)$ \endlatexonly + * \xmlonly + * + * + * + * Y + * n + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the Bessel function of the second kind of order \p n. + * - ynf(\p n, \p x) returns NaN for \p n < 0. + * - ynf(\p n, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - ynf(\p n, \p x) returns NaN for \p x < 0. + * - ynf(\p n, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * - ynf(\p n, NaN) returns NaN. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float ynf(int n, float x) __THROW; + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the value of the regular modified cylindrical Bessel function of order 0 for the input argument. + * + * Calculate the value of the regular modified cylindrical Bessel function of order 0 for + * the input argument \p x, + * \latexonly $I_0(x)$ \endlatexonly + * \xmlonly + * + * + * + * I + * 0 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the regular modified cylindrical Bessel function of order 0. + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl cyl_bessel_i0(double x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the value of the regular modified cylindrical Bessel function of order 0 for the input argument. + * + * Calculate the value of the regular modified cylindrical Bessel function of order 0 for + * the input argument \p x, + * \latexonly $I_0(x)$ \endlatexonly + * \xmlonly + * + * + * + * I + * 0 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the regular modified cylindrical Bessel function of order 0. + * + * \note_accuracy_single + */ +extern __device__ __device_builtin__ float cyl_bessel_i0f(float x) __THROW; + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the value of the regular modified cylindrical Bessel function of order 1 for the input argument. + * + * Calculate the value of the regular modified cylindrical Bessel function of order 1 for + * the input argument \p x, + * \latexonly $I_1(x)$ \endlatexonly + * \xmlonly + * + * + * + * I + * 1 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the regular modified cylindrical Bessel function of order 1. + * + * \note_accuracy_double + */ +extern __device__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl cyl_bessel_i1(double x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the value of the regular modified cylindrical Bessel function of order 1 for the input argument. + * + * Calculate the value of the regular modified cylindrical Bessel function of order 1 for + * the input argument \p x, + * \latexonly $I_1(x)$ \endlatexonly + * \xmlonly + * + * + * + * I + * 1 + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * Returns the value of the regular modified cylindrical Bessel function of order 1. + * + * \note_accuracy_single + */ +extern __device__ __device_builtin__ float cyl_bessel_i1f(float x) __THROW; + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the error function of the input argument. + * + * Calculate the value of the error function for the input argument \p x, + * \latexonly $\frac{2}{\sqrt \pi} \int_0^x e^{-t^2} dt$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * + * π + * + * + * + * ∫ + * 0 + * x + * + * + * e + * + * − + * + * t + * 2 + * + * + * + * d + * t + * + * \endxmlonly. + * + * \return + * - erf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - erf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 1$ \endlatexonly + * \xmlonly + * + * + * ± + * 1 + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double erf(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl erf(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the error function of the input argument. + * + * Calculate the value of the error function for the input argument \p x, + * \latexonly $\frac{2}{\sqrt \pi} \int_0^x e^{-t^2} dt$ \endlatexonly + * \xmlonly + * + * + * + * 2 + * + * π + * + * + * + * ∫ + * 0 + * x + * + * + * e + * + * − + * + * t + * 2 + * + * + * + * d + * t + * + * \endxmlonly. + * + * \return + * - erff( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - erff( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 1$ \endlatexonly + * \xmlonly + * + * + * ± + * 1 + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float erff(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl erff(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the inverse error function of the input argument. + * + * Calculate the inverse error function + * \latexonly $\erf^{-1}$ \endlatexonly + * \xmlonly + * + * + * + * erf + * + * - + * 1 + * + * + * + * + * \endxmlonly + * (\p x), of the input argument \p x in the interval [-1, 1]. + * + * \return + * - erfinv( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - erfinv(1) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - erfinv(-1) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - erfinv(\p x) returns NaN for \p x outside [-1, +1]. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double erfinv(double x); +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the inverse error function of the input argument. + * + * Calculate the inverse error function + * \latexonly $\erf^{-1}$ \endlatexonly + * \xmlonly + * + * + * + * erf + * + * - + * 1 + * + * + * + * + * \endxmlonly + * (\p x), of the input argument \p x in the interval [-1, 1]. + * + * \return + * - erfinvf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - erfinvf(1) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - erfinvf(-1) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - erfinvf(\p x) returns NaN for \p x outside [-1, +1]. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float erfinvf(float x); + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the complementary error function of the input argument. + * + * Calculate the complementary error function of the input argument \p x, + * 1 - erf(\p x). + * + * \return + * - erfc( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns 2. + * - erfc( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double erfc(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl erfc(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the complementary error function of the input argument. + * + * Calculate the complementary error function of the input argument \p x, + * 1 - erf(\p x). + * + * \return + * - erfcf( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns 2. + * - erfcf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float erfcf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl erfcf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the natural logarithm of the absolute value of the gamma function of the input argument. + * + * Calculate the natural logarithm of the absolute value of the gamma function of the input argument \p x, namely the value of + * \latexonly $\log_{e}\left|\int_{0}^{\infty} e^{-t}t^{x-1}dt\right|$ \endlatexonly + * \xmlonly + * + * + * + * log + * + * e + * + * + * + * + * + * ∫ + * + * 0 + * + * + * ∞ + * + * + * + * e + * + * − + * t + * + * + * + * t + * + * x + * − + * 1 + * + * + * d + * t + * + * + * + * + * \endxmlonly + * + * \return + * - lgamma(1) returns +0. + * - lgamma(2) returns +0. + * - lgamma(\p x) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * if \p x + * \latexonly $\leq$ \endlatexonly + * \xmlonly + * + * + * ≤ + * + * + * \endxmlonly 0 and \p x is an integer. + * - lgamma( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - lgamma( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double lgamma(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl lgamma(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the inverse complementary error function of the input argument. + * + * Calculate the inverse complementary error function + * \latexonly $\erfc^{-1}$ \endlatexonly + * \xmlonly + * + * + * + * erfc + * + * - + * 1 + * + * + * + * + * \endxmlonly + * (\p x), of the input argument \p x in the interval [0, 2]. + * + * \return + * - erfcinv( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - erfcinv(2) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - erfcinv(\p x) returns NaN for \p x outside [0, 2]. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double erfcinv(double x); +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the inverse complementary error function of the input argument. + * + * Calculate the inverse complementary error function + * \latexonly $\erfc^{-1}$ \endlatexonly + * \xmlonly + * + * + * + * erfc + * + * - + * 1 + * + * + * + * + * \endxmlonly + * (\p x), of the input argument \p x in the interval [0, 2]. + * + * \return + * - erfcinvf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - erfcinvf(2) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - erfcinvf(\p x) returns NaN for \p x outside [0, 2]. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float erfcinvf(float x); +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the inverse of the standard normal cumulative distribution function. + * + * Calculate the inverse of the standard normal cumulative distribution function for input argument \p x, + * \latexonly $\Phi^{-1}(x)$ \endlatexonly + * \xmlonly + * + * + * + * Φ + * + * − + * 1 + * + * + * ( + * x + * ) + * + * \endxmlonly. The function is defined for input values in the interval + * \latexonly $(0, 1)$ \endlatexonly + * \xmlonly + * + * + * ( + * 0 + * , + * 1 + * ) + * + * \endxmlonly. + * + * \return + * - normcdfinv( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - normcdfinv(1) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - normcdfinv(\p x) returns NaN + * if \p x is not in the interval [0,1]. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double normcdfinv(double x); +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the inverse of the standard normal cumulative distribution function. + * + * Calculate the inverse of the standard normal cumulative distribution function for input argument \p x, + * \latexonly $\Phi^{-1}(x)$ \endlatexonly + * \xmlonly + * + * + * + * Φ + * + * − + * 1 + * + * + * ( + * x + * ) + * + * \endxmlonly. The function is defined for input values in the interval + * \latexonly $(0, 1)$ \endlatexonly + * \xmlonly + * + * + * ( + * 0 + * , + * 1 + * ) + * + * \endxmlonly. + * + * \return + * - normcdfinvf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - normcdfinvf(1) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - normcdfinvf(\p x) returns NaN + * if \p x is not in the interval [0,1]. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float normcdfinvf(float x); +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the standard normal cumulative distribution function. + * + * Calculate the cumulative distribution function of the standard normal distribution for input argument \p x, + * \latexonly $\Phi(x)$ \endlatexonly + * \xmlonly + * + * + * Φ + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * - normcdf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns 1. + * - normcdf( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double normcdf(double x); +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the standard normal cumulative distribution function. + * + * Calculate the cumulative distribution function of the standard normal distribution for input argument \p x, + * \latexonly $\Phi(x)$ \endlatexonly + * \xmlonly + * + * + * Φ + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * - normcdff( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns 1. + * - normcdff( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns +0 + + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float normcdff(float x); +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the scaled complementary error function of the input argument. + * + * Calculate the scaled complementary error function of the input argument \p x, + * \latexonly $e^{x^2}\cdot \textrm{erfc}(x)$ \endlatexonly + * \xmlonly + * + * + * + * e + * + * + * x + * 2 + * + * + * + * ⋅ + * + * erfc + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * - erfcx( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly. + * - erfcx( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * + * \note_accuracy_double + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double erfcx(double x); +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the scaled complementary error function of the input argument. + * + * Calculate the scaled complementary error function of the input argument \p x, + * \latexonly $e^{x^2}\cdot \textrm{erfc}(x)$ \endlatexonly + * \xmlonly + * + * + * + * e + * + * + * x + * 2 + * + * + * + * ⋅ + * + * erfc + * + * ( + * x + * ) + * + * \endxmlonly. + * + * \return + * - erfcxf( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly. + * - erfcxf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float erfcxf(float x); + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the natural logarithm of the absolute value of the gamma function of the input argument. + * + * Calculate the natural logarithm of the absolute value of the gamma function of the input argument \p x, namely the value of + * \latexonly $\log_{e}\left|\int_{0}^{\infty} e^{-t}t^{x-1}dt\right|$ \endlatexonly + * \xmlonly + * + * + * + * log + * + * e + * + * + * + * + * + * ∫ + * + * 0 + * + * + * ∞ + * + * + * + * e + * + * − + * t + * + * + * + * t + * + * x + * − + * 1 + * + * + * d + * t + * + * + * + * + * \endxmlonly + * + * \return + * - lgammaf(1) returns +0. + * - lgammaf(2) returns +0. + * - lgammaf(\p x) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * if \p x + * \latexonly $\leq$ \endlatexonly + * \xmlonly + * + * + * ≤ + * + * + * \endxmlonly + * 0 and \p x is an integer. + * - lgammaf( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - lgammaf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float lgammaf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl lgammaf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the gamma function of the input argument. + * + * Calculate the gamma function of the input argument \p x, namely the value of + * \latexonly $\int_{0}^{\infty} e^{-t}t^{x-1}dt$ \endlatexonly + * \xmlonly + * + * + * + * ∫ + * + * 0 + * + * + * ∞ + * + * + * + * e + * + * − + * t + * + * + * + * t + * + * x + * − + * 1 + * + * + * d + * t + * + * \endxmlonly. + * + * \return + * - tgamma( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * - tgamma(2) returns +1. + * - tgamma(\p x) returns NaN if \p x < 0 and \p x is an integer. + * - tgamma( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * - tgamma( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double tgamma(double x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl tgamma(double x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the gamma function of the input argument. + * + * Calculate the gamma function of the input argument \p x, namely the value of + * \latexonly $\int_{0}^{\infty} e^{-t}t^{x-1}dt$ \endlatexonly + * \xmlonly + * + * + * + * ∫ + * + * 0 + * + * + * ∞ + * + * + * + * e + * + * − + * t + * + * + * + * t + * + * x + * − + * 1 + * + * + * d + * t + * + * \endxmlonly. + * + * \return + * - tgammaf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * - tgammaf(2) returns +1. + * - tgammaf(\p x) returns NaN if \p x < 0 and \p x is an integer. + * - tgammaf( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * - tgammaf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float tgammaf(float x) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl tgammaf(float x); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** \ingroup CUDA_MATH_DOUBLE + * \brief Create value with given magnitude, copying sign of second value. + * + * Create a floating-point value with the magnitude \p x and the sign of \p y. + * + * \return + * Returns a value with the magnitude of \p x and the sign of \p y. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double copysign(double x, double y) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl copysign(double x, double y); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** \ingroup CUDA_MATH_SINGLE + * \brief Create value with given magnitude, copying sign of second value. + * + * Create a floating-point value with the magnitude \p x and the sign of \p y. + * + * \return + * Returns a value with the magnitude of \p x and the sign of \p y. + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float copysignf(float x, float y) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl copysignf(float x, float y); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Return next representable double-precision floating-point value after argument \p x in the direction of \p y. + * + * Calculate the next representable double-precision floating-point value + * following \p x in the direction of \p y. For example, if \p y is greater than \p x, ::nextafter() + * returns the smallest representable number greater than \p x + * + * \return + * - nextafter(\p x, \p y) = \p y if \p x equals \p y. + * - nextafter(\p x, \p y) = \p NaN if either \p x or \p y are \p NaN. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double nextafter(double x, double y) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl nextafter(double x, double y); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Return next representable single-precision floating-point value after argument \p x in the direction of \p y. + * + * Calculate the next representable single-precision floating-point value + * following \p x in the direction of \p y. For example, if \p y is greater than \p x, ::nextafterf() + * returns the smallest representable number greater than \p x + * + * \return + * - nextafterf(\p x, \p y) = \p y if \p x equals \p y. + * - nextafterf(\p x, \p y) = \p NaN if either \p x or \p y are \p NaN. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float nextafterf(float x, float y) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl nextafterf(float x, float y); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Returns "Not a Number" value. + * + * Return a representation of a quiet NaN. Argument \p tagp selects one of the possible representations. + * + * \return + * - nan(\p tagp) returns NaN. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double nan(const char *tagp) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl nan(const char *tagp); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Returns "Not a Number" value + * + * Return a representation of a quiet NaN. Argument \p tagp selects one of the possible representations. + * + * \return + * - nanf(\p tagp) returns NaN. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float nanf(const char *tagp) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl nanf(const char *tagp); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* namespace std */ +#endif +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isinff(float) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isnanf(float) __THROW; + + +#if defined(__APPLE__) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isfinited(double) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isfinitef(float) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __signbitd(double) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isnand(double) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isinfd(double) __THROW; +#else /* __APPLE__ */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __finite(double) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __finitef(float) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __signbit(double) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isnan(double) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isinf(double) __THROW; +#endif /* __APPLE__ */ + +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __signbitf(float) __THROW; + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Compute + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * + * Compute the value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single ternary operation. After computing the value + * to infinite precision, the value is rounded once. + * + * \return + * Returns the rounded value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * - fma( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fma( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fma(\p x, \p y, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - fma(\p x, \p y, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_double + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double fma(double x, double y, double z) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP double __cdecl fma(double x, double y, double z); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Compute + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * + * Compute the value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single ternary operation. After computing the value + * to infinite precision, the value is rounded once. + * + * \return + * Returns the rounded value of + * \latexonly $x \times y + z$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + + * z + * + * + * \endxmlonly + * as a single operation. + * - fmaf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p z) returns NaN. + * - fmaf(\p x, \p y, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - fmaf(\p x, \p y, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns NaN if + * \latexonly $x \times y$ \endlatexonly + * \xmlonly + * + * + * x + * × + * y + * + * + * \endxmlonly + * is an exact + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float fmaf(float x, float y, float z) __THROW; +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ __CUDA_MATH_CRTIMP float __cdecl fmaf(float x, float y, float z); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif + + +/* these are here to avoid warnings on the call graph. + long double is not supported on the device */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __signbitl(long double) __THROW; +#if defined(__APPLE__) +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isfinite(long double) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isinf(long double) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isnan(long double) __THROW; +#else /* __APPLE__ */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __finitel(long double) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isinfl(long double) __THROW; +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int __isnanl(long double) __THROW; +#endif /* __APPLE__ */ + +#if defined(_WIN32) && defined(_M_AMD64) +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl acosf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl asinf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl atanf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl atan2f(float, float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl cosf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl sinf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl tanf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl coshf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl sinhf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl tanhf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl expf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl logf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl log10f(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl modff(float, float*) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl powf(float, float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl sqrtf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl ceilf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl floorf(float) __THROW; +extern __CUDA_MATH_CRTIMP __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float __cdecl fmodf(float, float) __THROW; +#else /* _WIN32 && _M_AMD64 */ + +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +namespace std { +#endif +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the arc cosine of the input argument. + * + * Calculate the principal value of the arc cosine of the input argument \p x. + * + * \return + * Result will be in radians, in the interval [0, + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * ] for \p x inside [-1, +1]. + * - acosf(1) returns +0. + * - acosf(\p x) returns NaN for \p x outside [-1, +1]. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float acosf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the arc sine of the input argument. + * + * Calculate the principal value of the arc sine of the input argument \p x. + * + * \return + * Result will be in radians, in the interval [- + * \latexonly $\pi/2$ \endlatexonly + * \xmlonly + * + * + * π + * + * / + * + * 2 + * + * + * \endxmlonly + * , + + * \latexonly $\pi/2$ \endlatexonly + * \xmlonly + * + * + * π + * + * / + * + * 2 + * + * + * \endxmlonly + * ] for \p x inside [-1, +1]. + * - asinf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - asinf(\p x) returns NaN for \p x outside [-1, +1]. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float asinf(float x) __THROW; + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the arc tangent of the input argument. + * + * Calculate the principal value of the arc tangent of the input argument \p x. + * + * \return + * Result will be in radians, in the interval [- + * \latexonly $\pi/2$ \endlatexonly + * \xmlonly + * + * + * π + * + * / + * + * 2 + * + * + * \endxmlonly + * , + + * \latexonly $\pi/2$ \endlatexonly + * \xmlonly + * + * + * π + * + * / + * + * 2 + * + * + * \endxmlonly + * ]. + * - atanf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - atanf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly + * /2. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float atanf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the arc tangent of the ratio of first and second input arguments. + * + * Calculate the principal value of the arc tangent of the ratio of first + * and second input arguments \p y / \p x. The quadrant of the result is + * determined by the signs of inputs \p y and \p x. + * + * \return + * Result will be in radians, in the interval [- + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * , + + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * ]. + * - atan2f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , -0) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly. + * - atan2f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , +0) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly. + * - atan2f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p x) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly + * for \p x < 0. + * - atan2f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p x) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * for \p x > 0. + * - atan2f(\p y, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\pi$ \endlatexonly + * \xmlonly + * + * + * - + * π + * + * + * \endxmlonly + * /2 for \p y < 0. + * - atan2f(\p y, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pi$ \endlatexonly + * \xmlonly + * + * + * π + * + * + * \endxmlonly + * /2 for \p y > 0. + * - atan2f( + * \latexonly $\pm y$ \endlatexonly + * \xmlonly + * + * + * ± + * y + * + * + * \endxmlonly + * , + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly + * for finite \p y > 0. + * - atan2f( + * \latexonly $\pm y$ \endlatexonly + * \xmlonly + * + * + * ± + * y + * + * + * \endxmlonly + * , + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * for finite \p y > 0. + * - atan2f( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p x) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly + * /2 for finite \p x. + * - atan2f( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $\pm 3\pi$ \endlatexonly + * \xmlonly + * + * + * ± + * 3 + * π + * + * + * \endxmlonly + * /4. + * - atan2f( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $\pm \pi$ \endlatexonly + * \xmlonly + * + * + * ± + * π + * + * + * \endxmlonly + * /4. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float atan2f(float y, float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the cosine of the input argument. + * + * Calculate the cosine of the input argument \p x (measured in radians). + * + * \return + * - cosf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - cosf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * + * \note_accuracy_single + * \note_fastmath + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float cosf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the sine of the input argument. + * + * Calculate the sine of the input argument \p x (measured in radians). + * + * \return + * - sinf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - sinf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * + * \note_accuracy_single + * \note_fastmath + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float sinf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the tangent of the input argument. + * + * Calculate the tangent of the input argument \p x (measured in radians). + * + * \return + * - tanf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - tanf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns NaN. + * + * \note_accuracy_single + * \note_fastmath + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float tanf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the hyperbolic cosine of the input argument. + * + * Calculate the hyperbolic cosine of the input argument \p x. + * + * \return + * - coshf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - coshf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float coshf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the hyperbolic sine of the input argument. + * + * Calculate the hyperbolic sine of the input argument \p x. + * + * \return + * - sinhf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - sinhf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float sinhf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the hyperbolic tangent of the input argument. + * + * Calculate the hyperbolic tangent of the input argument \p x. + * + * \return + * - tanhf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - tanhf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 1$ \endlatexonly + * \xmlonly + * + * + * ± + * 1 + * + * + * \endxmlonly. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float tanhf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the natural logarithm of the input argument. + * + * Calculate the natural logarithm of the input argument \p x. + * + * \return + * - logf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - logf(1) returns +0. + * - logf(\p x) returns NaN for \p x < 0. + * - logf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + * \note_fastmath + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float logf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * exponential of the input argument. + * + * Calculate + * \latexonly $e^x$ \endlatexonly + * \xmlonly + * + * + * + * e + * x + * + * + * \endxmlonly, + * the base + * \latexonly $e$ \endlatexonly + * \xmlonly + * + * + * e + * + * + * \endxmlonly + * exponential of the input argument \p x. + * + * \return + * - expf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1. + * - expf( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * - + * ∞ + * + * \endxmlonly + * ) returns +0. + * - expf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + * \note_fastmath + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float expf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the base 10 logarithm of the input argument. + * + * Calculate the base 10 logarithm of the input argument \p x. + * + * \return + * - log10f( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * \endxmlonly. + * - log10f(1) returns +0. + * - log10f(\p x) returns NaN for \p x < 0. + * - log10f( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * + * \note_accuracy_single + * \note_fastmath + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float log10f(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Break down the input argument into fractional and integral parts. + * + * Break down the argument \p x into fractional and integral parts. The integral part is stored in the argument \p iptr. + * Fractional and integral parts are given the same sign as the argument \p x. + * + * \return + * - modff( + * \latexonly $\pm x$ \endlatexonly + * \xmlonly + * + * + * ± + * x + * + * + * \endxmlonly + * , \p iptr) returns a result with the same sign as \p x. + * - modff( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * , \p iptr) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * and stores + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * in the object pointed to by \p iptr. + * - modff(NaN, \p iptr) stores a NaN in the object pointed to by \p iptr and returns a NaN. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float modff(float x, float *iptr) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the value of first argument to the power of second argument. + * + * Calculate the value of \p x to the power of \p y. + * + * \return + * - powf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * for \p y an odd integer less than 0. + * - powf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * for \p y less than 0 and not an odd integer. + * - powf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * for \p y an odd integer greater than 0. + * - powf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p y) returns +0 for \p y > 0 and not an odd integer. + * - powf(-1, + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns 1. + * - powf(+1, \p y) returns 1 for any \p y, even a NaN. + * - powf(\p x, + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns 1 for any \p x, even a NaN. + * - powf(\p x, \p y) returns a NaN for finite \p x < 0 and finite non-integer \p y. + * - powf(\p x, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * for + * \latexonly $| x | < 1$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * + * | + * + * < + * 1 + * + * \endxmlonly. + * - powf(\p x, + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * ) returns +0 for + * \latexonly $| x | > 1$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * + * | + * + * > + * 1 + * + * \endxmlonly. + * - powf(\p x, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns +0 for + * \latexonly $| x | < 1$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * + * | + * + * < + * 1 + * + * \endxmlonly. + * - powf(\p x, + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * for + * \latexonly $| x | > 1$ \endlatexonly + * \xmlonly + * + * + * + * | + * + * x + * + * | + * + * > + * 1 + * + * \endxmlonly. + * - powf( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * , \p y) returns -0 for \p y an odd integer less than 0. + * - powf( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * , \p y) returns +0 for \p y < 0 and not an odd integer. + * - powf( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * for \p y an odd integer greater than 0. + * - powf( + * \latexonly $-\infty$ \endlatexonly + * \xmlonly + * + * + * − + * ∞ + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * for \p y > 0 and not an odd integer. + * - powf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * , \p y) returns +0 for \p y < 0. + * - powf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * for \p y > 0. + * + * \note_accuracy_single + * \note_fastmath + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float powf(float x, float y) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the square root of the input argument. + * + * Calculate the nonnegative square root of \p x, + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * \endxmlonly. + * + * \return + * Returns + * \latexonly $\sqrt{x}$ \endlatexonly + * \xmlonly + * + * + * + * x + * + * + * \endxmlonly. + * - sqrtf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - sqrtf( + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $+\infty$ \endlatexonly + * \xmlonly + * + * + * + + * ∞ + * + * \endxmlonly. + * - sqrtf(\p x) returns NaN if \p x is less than 0. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float sqrtf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate ceiling of the input argument. + * + * Compute the smallest integer value not less than \p x. + * + * \return + * Returns + * \latexonly $\lceil x \rceil$ \endlatexonly + * \xmlonly + * + * + * ⌈ + * x + * ⌉ + * + * + * \endxmlonly + * expressed as a floating-point number. + * - ceilf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * - ceilf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float ceilf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the largest integer less than or equal to \p x. + * + * Calculate the largest integer value which is less than or equal to \p x. + * + * \return + * Returns + * \latexonly $\lfloor x \rfloor$ \endlatexonly + * \xmlonly + * + * + * ⌊ + * x + * ⌋ + * + * + * \endxmlonly + * expressed as a floating-point number. + * - floorf( + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * \endxmlonly. + * - floorf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * ) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * \endxmlonly. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float floorf(float x) __THROW; +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the floating-point remainder of \p x / \p y. + * + * Calculate the floating-point remainder of \p x / \p y. + * The floating-point remainder of the division operation \p x / \p y calculated + * by this function is exactly the value x - n*y, where \p n is \p x / \p y with its fractional part truncated. + * The computed value will have the same sign as \p x, and its magnitude will be less than the magnitude of \p y. + * \return + * - Returns the floating-point remainder of \p x / \p y. + * - fmodf( + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * , \p y) returns + * \latexonly $\pm 0$ \endlatexonly + * \xmlonly + * + * + * ± + * 0 + * + * + * \endxmlonly + * if \p y is not zero. + * - fmodf(\p x, + * \latexonly $\pm \infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * ) returns \p x if \p x is finite. + * - fmodf(\p x, \p y) returns NaN if \p x is + * \latexonly $\pm\infty$ \endlatexonly + * \xmlonly + * + * + * ± + * ∞ + * + * + * \endxmlonly + * or \p y is zero. + * - If either argument is NaN, NaN is returned. + * + * \note_accuracy_single + */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float fmodf(float x, float y) __THROW; +#if defined(__QNX__) +/* redeclare some builtins that QNX uses */ +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float _FLog(float, int); +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float _FCosh(float, float); +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float _FSinh(float, float); +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float _FSinx(float, unsigned int, int); +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int _FDsign(float); +extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ int _Dsign(double); +#endif +#if defined(__QNX__) && !defined(_LIBCPP_VERSION) +} /* std */ +#endif +#endif /* _WIN32 && _M_AMD64 */ + +} + +#if !defined(__CUDACC_RTC__) +#include +#include + +#ifndef __CUDA_INTERNAL_SKIP_CPP_HEADERS__ +#include +#include +#endif /* __CUDA_INTERNAL_SKIP_CPP_HEADERS__ */ +#endif /* __CUDACC_RTC__ */ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__CUDACC_RTC__) + +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int signbit(float x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int signbit(double x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int signbit(long double x); + +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isfinite(float x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isfinite(double x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isfinite(long double x); + +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isnan(float x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isnan(double x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isnan(long double x); + +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isinf(float x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isinf(double x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isinf(long double x); + +#elif defined(__GNUC__) + +#undef signbit +#undef isfinite +#undef isnan +#undef isinf + +#if defined(__APPLE__) + +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int signbit(float x); +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int signbit(double x); +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int signbit(long double x); + +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isfinite(float x); +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isfinite(double x); +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isfinite(long double x); + +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isnan(double x) throw(); +#if !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 7000 +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isnan(float x); +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isnan(long double x); +#else /* !(!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 7000) */ +template +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool __libcpp_isnan(T) _NOEXCEPT; +inline _LIBCPP_INLINE_VISIBILITY __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool isnan(float x) _NOEXCEPT; +inline _LIBCPP_INLINE_VISIBILITY __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool isnan(long double x) _NOEXCEPT; +#endif /* !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 7000 */ + +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isinf(double x) throw(); +#if !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 7000 +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isinf(float x); +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isinf(long double x); +#else /* !(!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 7000) */ +template +__cudart_builtin__ __DEVICE_FUNCTIONS_DECL__ bool __libcpp_isinf(T) _NOEXCEPT; +inline _LIBCPP_INLINE_VISIBILITY __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool isinf(float x) _NOEXCEPT; +inline _LIBCPP_INLINE_VISIBILITY __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool isinf(long double x) _NOEXCEPT; +#endif /* !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 7000 */ + +#else /* __APPLE__ */ + +#if ((defined _GLIBCXX_MATH_H) && _GLIBCXX_MATH_H) && (__cplusplus >= 201103L) +#if !defined(_NVHPC_CUDA) +namespace std { +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool signbit(float x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool signbit(double x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool signbit(long double x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool isfinite(float x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool isfinite(double x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool isfinite(long double x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool isnan(float x); +/* GCC 6.1 uses ::isnan(double x) for isnan(double x) if the condition is true */ +#if _GLIBCXX_HAVE_OBSOLETE_ISNAN && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isnan(double x) throw(); +#else /* !(_GLIBCXX_HAVE_OBSOLETE_ISNAN && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC) */ +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool isnan(double x); +#endif /* _GLIBCXX_HAVE_OBSOLETE_ISNAN && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC */ +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool isnan(long double x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool isinf(float x); +/* GCC 6.1 uses ::isinf(double x) for isinf(double x) if the condition is true. */ +#if _GLIBCXX_HAVE_OBSOLETE_ISINF && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isinf(double x) throw(); +#else /* !(_GLIBCXX_HAVE_OBSOLETE_ISINF && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC) */ +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool isinf(double x); +#endif /* _GLIBCXX_HAVE_OBSOLETE_ISINF && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC */ +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ constexpr bool isinf(long double x); +} +#endif + +#else /* !(((defined _GLIBCXX_MATH_H) && _GLIBCXX_MATH_H) && (__cplusplus >= 201103L)) */ + +#if defined(__QNX__) +#if (__QNX__) && !defined(_LIBCPP_VERSION) +/* QNX defines functions in std, need to declare them here */ +namespace std { +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool signbit(float x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool signbit(double x); +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool signbit(long double x); +} +#else +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool signbit(const float x); +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool signbit(const double x); +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool signbit(const long double x); +#endif +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isfinite(const float a); +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isfinite(const double a); +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isfinite(const long double a); +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isnan(const float a); +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isnan(const double a); +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isnan(const long double a); +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isinf(const float a); +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isinf(const double a); +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isinf(const long double a); +#else /* ! __QNX__ */ +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int signbit(const float x); +#if defined(__ICC) +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int signbit(const double x) throw(); +#else /* !__ICC */ +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int signbit(const double x); +#endif /* __ICC */ +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int signbit(const long double x); + +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isfinite(const float x); +#if defined(__ICC) +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isfinite(const double x) throw(); +#else /* !__ICC */ +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isfinite(const double x); +#endif /* __ICC */ +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isfinite(const long double x); + +#if (defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000 +template +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool __libcpp_isnan(T) _NOEXCEPT; +inline _LIBCPP_INLINE_VISIBILITY __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool isnan(float x) _NOEXCEPT; +#else /* !((defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000) */ +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isnan(float x); +#endif /* (defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000 */ +#if defined(__ANDROID__) || defined(__HORIZON__) +#if !defined(_LIBCPP_VERSION) +__forceinline__ +#endif /* !defined(_LIBCPP_VERSION) */ +#if _LIBCPP_VERSION >= 7000 +#ifdef _LIBCPP_PREFERRED_OVERLOAD +_LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool isnan(double x) _NOEXCEPT; +#endif /* _LIBCPP_PREFERRED_OVERLOAD */ +#else /* _LIBCPP_VERSION < 7000 */ +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isnan(double x); +#endif /* _LIBCPP_VERSION >= 7000 */ +#else /* !(__ANDROID__ || __HORIZON__) */ +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isnan(double x) throw(); +#endif /* __ANDROID__ */ +#if (defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000 +inline _LIBCPP_INLINE_VISIBILITY __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool isnan(long double x) _NOEXCEPT; +#else /* !( (defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000) */ +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isnan(long double x); +#endif /* (defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000 */ + +#if (defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000 +static __inline__ __cudart_builtin__ __DEVICE_FUNCTIONS_DECL__ unsigned __FLOAT_BITS(float __f); +static __inline__ __cudart_builtin__ __DEVICE_FUNCTIONS_DECL__ unsigned long long __DOUBLE_BITS(double __f); +template +__cudart_builtin__ __DEVICE_FUNCTIONS_DECL__ bool __libcpp_isinf(T) _NOEXCEPT; +inline _LIBCPP_INLINE_VISIBILITY __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool isinf(float x) _NOEXCEPT; +#else /* !( (defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000) */ +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isinf(float x); +#endif /* (defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000 */ + +#if defined(__ANDROID__) || defined(__HORIZON__) +#if !defined(_LIBCPP_VERSION) +__forceinline__ +#endif /* !defined(_LIBCPP_VERSION) */ +#if _LIBCPP_VERSION >= 7000 +#ifdef _LIBCPP_PREFERRED_OVERLOAD +_LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool isinf(double x) _NOEXCEPT; +#endif /* _LIBCPP_PREFERRED_OVERLOAD */ +#else /* _LIBCPP_VERSION < 7000 */ +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isinf(double x); +#endif /* _LIBCPP_VERSION >= 7000 */ +#else /* ! (__ANDROID__ || __HORIZON__) */ +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isinf(double x) throw(); +#endif /* __ANDROID__ || __HORIZON__ */ +#if (defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000 +inline _LIBCPP_INLINE_VISIBILITY __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool isinf(long double x) _NOEXCEPT; +#else /* !( (defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000) */ +__forceinline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ int isinf(long double x); +#endif /* (defined(__ANDROID__) || defined(__HORIZON__)) && _LIBCPP_VERSION >= 8000 */ +#endif /* __QNX__ */ + +#endif /* ((defined _GLIBCXX_MATH_H) && _GLIBCXX_MATH_H) && (__cplusplus >= 201103L) */ +#endif /* __APPLE__ */ + +#if !defined(_LIBCPP_VERSION) +#if defined(__clang__) +#if __has_include() +#define __NV_GLIBCXX_VERSION 40800 +#endif /* __has_include() */ +#endif /* __clang__ */ + +#if !defined(__NV_GLIBCXX_VERSION) +#define __NV_GLIBCXX_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +#endif /* !__NV_GLIBCXX_VERSION */ +#endif /* !defined(_LIBCPP_VERSION) */ + +#if !defined(__HORIZON__) || !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 3800 +#if defined(__arm__) && !defined(_STLPORT_VERSION) && !_GLIBCXX_USE_C99 +#if !defined(__ANDROID__) || (defined(__NV_GLIBCXX_VERSION) && __NV_GLIBCXX_VERSION < 40800) + +#if defined(__QNX__) +/* QNX defines functions in std, need to declare them here */ +namespace std { +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ long long int abs (long long int a); +} +#elif defined(__HORIZON__) +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif +_LIBCPP_BEGIN_NAMESPACE_STD +__DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ long long int abs (long long int a) throw(); +_LIBCPP_END_NAMESPACE_STD +#else +static __inline__ __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ long long int abs(long long int a); +#endif /* __QNX__ || __HORIZON__*/ + +#endif /* !__ANDROID__ || (defined(__NV_GLIBCXX_VERSION) && __NV_GLIBCXX_VERSION < 40800) */ +#endif /* __arm__ && !_STLPORT_VERSION && !_GLIBCXX_USE_C99 */ +#endif /* !defined(__HORIZON__) || !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 3800 */ + +#if defined(__NV_GLIBCXX_VERSION) && __NV_GLIBCXX_VERSION < 40800 && !defined(__ibmxl__) + +#if !defined(_STLPORT_VERSION) +namespace __gnu_cxx +{ +#endif /* !_STLPORT_VERSION */ + +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ long long int abs(long long int a); + +#if !defined(_STLPORT_VERSION) +} +#endif /* !_STLPORT_VERSION */ + +#endif /* defined(__NV_GLIBCXX_VERSION) && __NV_GLIBCXX_VERSION < 40800 && !__ibmxl__ */ + +namespace std +{ + template extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ T __pow_helper(T, int); + template extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ T __cmath_power(T, unsigned int); +} + +using std::abs; +using std::fabs; +using std::ceil; +using std::floor; +using std::sqrt; +#if !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 3800 +using std::pow; +#endif /* !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 3800 */ +using std::log; +using std::log10; +using std::fmod; +using std::modf; +using std::exp; +using std::frexp; +using std::ldexp; +using std::asin; +using std::sin; +using std::sinh; +using std::acos; +using std::cos; +using std::cosh; +using std::atan; +using std::atan2; +using std::tan; +using std::tanh; + +#elif defined(_WIN32) + +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ __CUDA_MATH_CRTIMP double __cdecl _hypot(double x, double y); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ __CUDA_MATH_CRTIMP float __cdecl _hypotf(float x, float y); + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __DEVICE_FUNCTIONS_DECL__ int signbit(long double a); +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#if _MSC_VER >= 1900 +#define __SIGNBIT_THROW throw() +#else +#define __SIGNBIT_THROW +#endif +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ bool signbit(long double) __SIGNBIT_THROW; +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ __device_builtin__ __CUDA_MATH_CRTIMP int _ldsign(long double); +#undef __SIGNBIT_THROW +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +#define __RETURN_TYPE int +/** + * \ingroup CUDA_MATH_DOUBLE + * + * \brief Return the sign bit of the input. + * + * Determine whether the floating-point value \p a is negative. + * + * \return + * Reports the sign bit of all values including infinities, zeros, and NaNs. + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. Returns + * true if and only if \p a is negative. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns a + * nonzero value if and only if \p a is negative. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE signbit(double a); +#undef __RETURN_TYPE +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#define __RETURN_TYPE bool +#if _MSC_VER >= 1900 +#define __SIGNBIT_THROW throw() +#else +#define __SIGNBIT_THROW +#endif +/** + * \ingroup CUDA_MATH_DOUBLE + * + * \brief Return the sign bit of the input. + * + * Determine whether the floating-point value \p a is negative. + * + * \return + * Reports the sign bit of all values including infinities, zeros, and NaNs. + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. Returns + * true if and only if \p a is negative. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns a + * nonzero value if and only if \p a is negative. + */ +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ __RETURN_TYPE signbit(double) __SIGNBIT_THROW; +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ __device_builtin__ __CUDA_MATH_CRTIMP int _dsign(double); +#undef __RETURN_TYPE +#undef __SIGNBIT_THROW +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +#define __RETURN_TYPE int +/** + * \ingroup CUDA_MATH_SINGLE + * + * \brief Return the sign bit of the input. + * + * Determine whether the floating-point value \p a is negative. + * + * \return + * Reports the sign bit of all values including infinities, zeros, and NaNs. + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. Returns + * true if and only if \p a is negative. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns a nonzero value + * if and only if \p a is negative. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE signbit(float a); +#undef __RETURN_TYPE +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#define __RETURN_TYPE bool +#if _MSC_VER >= 1900 +#define __SIGNBIT_THROW throw() +#else +#define __SIGNBIT_THROW +#endif +/** + * \ingroup CUDA_MATH_SINGLE + * + * \brief Return the sign bit of the input. + * + * Determine whether the floating-point value \p a is negative. + * + * \return + * Reports the sign bit of all values including infinities, zeros, and NaNs. + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. Returns + * true if and only if \p a is negative. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns a nonzero value + * if and only if \p a is negative. + */ +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ __RETURN_TYPE signbit(float) __SIGNBIT_THROW; +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ __device_builtin__ __CUDA_MATH_CRTIMP int _fdsign(float); +#undef __RETURN_TYPE +#undef __SIGNBIT_THROW +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __DEVICE_FUNCTIONS_DECL__ int isinf(long double a); +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isinf(long double a); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +#define __RETURN_TYPE int +/** + * \ingroup CUDA_MATH_DOUBLE + * + * \brief Determine whether argument is infinite. + * + * Determine whether the floating-point value \p a is an infinite value + * (positive or negative). + * \return + * - With Visual Studio 2013 host compiler: Returns true if and only + * if \p a is an infinite value. + * - With other host compilers: Returns a nonzero value if and only + * if \p a is an infinite value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isinf(double a); +#undef __RETURN_TYPE +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#define __RETURN_TYPE bool +/** + * \ingroup CUDA_MATH_DOUBLE + * + * \brief Determine whether argument is infinite. + * + * Determine whether the floating-point value \p a is an infinite value + * (positive or negative). + * \return + * - With Visual Studio 2013 host compiler: Returns true if and only + * if \p a is an infinite value. + * - With other host compilers: Returns a nonzero value if and only + * if \p a is an infinite value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isinf(double a); +#undef __RETURN_TYPE +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +#define __RETURN_TYPE int +/** + * \ingroup CUDA_MATH_SINGLE + * + * \brief Determine whether argument is infinite. + * + * Determine whether the floating-point value \p a is an infinite value + * (positive or negative). + * + * \return + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. Returns + * true if and only if \p a is an infinite value. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns a nonzero + * value if and only if \p a is an infinite value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isinf(float a); +#undef __RETURN_TYPE +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#define __RETURN_TYPE bool +/** + * \ingroup CUDA_MATH_SINGLE + * + * \brief Determine whether argument is infinite. + * + * Determine whether the floating-point value \p a is an infinite value + * (positive or negative). + * + * \return + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. Returns + * true if and only if \p a is an infinite value. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns a nonzero + * value if and only if \p a is an infinite value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isinf(float a); +#undef __RETURN_TYPE +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __DEVICE_FUNCTIONS_DECL__ int isnan(long double a); +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isnan(long double a); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +#define __RETURN_TYPE int +/** + * \ingroup CUDA_MATH_DOUBLE + * + * \brief Determine whether argument is a NaN. + * + * Determine whether the floating-point value \p a is a NaN. + * \return + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. + * Returns true if and only if \p a is a NaN value. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns a + * nonzero value if and only if \p a is a NaN value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isnan(double a); +#undef __RETURN_TYPE +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#define __RETURN_TYPE bool +/** + * \ingroup CUDA_MATH_DOUBLE + * + * \brief Determine whether argument is a NaN. + * + * Determine whether the floating-point value \p a is a NaN. + * \return + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. + * Returns true if and only if \p a is a NaN value. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns a + * nonzero value if and only if \p a is a NaN value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isnan(double a); +#undef __RETURN_TYPE +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +#define __RETURN_TYPE int +/** + * \ingroup CUDA_MATH_SINGLE + * + * + * \brief Determine whether argument is a NaN. + * + * Determine whether the floating-point value \p a is a NaN. + * \return + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. + * Returns true if and only if \p a is a NaN value. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns a + * nonzero value if and only if \p a is a NaN value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isnan(float a); +#undef __RETURN_TYPE +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#define __RETURN_TYPE bool +/** + * \ingroup CUDA_MATH_SINGLE + * + * + * \brief Determine whether argument is a NaN. + * + * Determine whether the floating-point value \p a is a NaN. + * \return + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. + * Returns true if and only if \p a is a NaN value. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns a + * nonzero value if and only if \p a is a NaN value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isnan(float a); +#undef __RETURN_TYPE +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __DEVICE_FUNCTIONS_DECL__ int isfinite(long double a); +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ bool isfinite(long double a); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +#define __RETURN_TYPE int +/** + * \ingroup CUDA_MATH_DOUBLE + * + * \brief Determine whether argument is finite. + * + * Determine whether the floating-point value \p a is a finite value + * (zero, subnormal, or normal and not infinity or NaN). + * + * \return + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. Returns + * true if and only if \p a is a finite value. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns + * a nonzero value if and only if \p a is a finite value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isfinite(double a); +#undef __RETURN_TYPE +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#define __RETURN_TYPE bool +/** + * \ingroup CUDA_MATH_DOUBLE + * + * \brief Determine whether argument is finite. + * + * Determine whether the floating-point value \p a is a finite value + * (zero, subnormal, or normal and not infinity or NaN). + * + * \return + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. Returns + * true if and only if \p a is a finite value. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns + * a nonzero value if and only if \p a is a finite value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isfinite(double a); +#undef __RETURN_TYPE +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +#define __RETURN_TYPE int +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Determine whether argument is finite. + * + * Determine whether the floating-point value \p a is a finite value + * (zero, subnormal, or normal and not infinity or NaN). + * + * \return + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. Returns + * true if and only if \p a is a finite value. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns + * a nonzero value if and only if \p a is a finite value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isfinite(float a); +#undef __RETURN_TYPE +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +#define __RETURN_TYPE bool +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Determine whether argument is finite. + * + * Determine whether the floating-point value \p a is a finite value + * (zero, subnormal, or normal and not infinity or NaN). + * + * \return + * - With Visual Studio 2013 host compiler: __RETURN_TYPE is 'bool'. Returns + * true if and only if \p a is a finite value. + * - With other host compilers: __RETURN_TYPE is 'int'. Returns + * a nonzero value if and only if \p a is a finite value. + */ +static __inline__ __DEVICE_FUNCTIONS_DECL__ __RETURN_TYPE isfinite(float a); +#undef __RETURN_TYPE +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +template extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ T _Pow_int(T, int); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ long long int abs(long long int); +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +template extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ T _Pow_int(T, int) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ long long int abs(long long int) throw(); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#endif /* __CUDACC_RTC__ */ + +#if __cplusplus >= 201103L +#define __NV_NOEXCEPT noexcept +#else /* !__cplusplus >= 201103L */ +#define __NV_NOEXCEPT throw() +#endif /* __cplusplus >= 201103L */ + +#if defined(_LIBCPP_VERSION) && defined(_LIBCPP_BEGIN_NAMESPACE_STD) && !defined(_STLPORT_VERSION) +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wc++11-extensions" +#endif /* __clang__ */ +#if _LIBCPP_VERSION < 3800 +_LIBCPP_BEGIN_NAMESPACE_STD +#endif /* _LIBCPP_VERSION < 3800 */ +#elif defined(__GNUC__) && !defined(_STLPORT_VERSION) +namespace std { +#endif /* defined(_LIBCPP_VERSION) && defined(_LIBCPP_BEGIN_NAMESPACE_STD) && !defined(_STLPORT_VERSION) || + __GNUC__ && !_STLPORT_VERSION */ + +#if defined(__CUDACC_RTC__) || defined(__GNUC__) + +#if defined(__CUDACC_RTC__) || \ + (defined(__NV_GLIBCXX_VERSION) && __NV_GLIBCXX_VERSION >= 40800) || \ + defined(__ibmxl__) +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ long long int abs(long long int); +#endif /* __CUDACC__RTC__ || + (defined(__NV_GLIBCXX_VERSION) && __NV_GLIBCXX_VERSION >= 40800) || + __ibmxl__ */ + +#endif /* __CUDACC_RTC__ || __GNUC__ */ + +#if defined(__CUDACC_RTC__) || \ + (!defined(_MSC_VER) || _MSC_VER < 1800) && \ + (!defined(_LIBCPP_VERSION) || (_LIBCPP_VERSION < 1101)) +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ long int __cdecl abs(long int); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl abs(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ double __cdecl abs(double); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl fabs(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl ceil(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl floor(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl sqrt(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl pow(float, float); + +#if !defined(__QNX__) + +#if defined(__GNUC__) && __cplusplus >= 201103L && !defined(_LIBCPP_VERSION) +template +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ +typename __gnu_cxx::__promote_2<_Tp, _Up>::__type pow(_Tp, _Up); +#else /* !(defined(__GNUC__) && __cplusplus >= 201103L && !defined(_LIBCPP_VERSION)) */ +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl pow(float, int); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ double __cdecl pow(double, int); +#endif /* defined(__GNUC__) && __cplusplus >= 201103L && !defined(_LIBCPP_VERSION) */ + +#endif /* !defined(__QNX__) */ + +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl log(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl log10(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl fmod(float, float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl modf(float, float*); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl exp(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl frexp(float, int*); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl ldexp(float, int); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl asin(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl sin(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl sinh(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl acos(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl cos(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl cosh(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl atan(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl atan2(float, float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl tan(float); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl tanh(float); +#else /* __CUDACC_RTC__ || + (!defined(_MSC_VER) || _MSC_VER < 1800) && + (!defined(_LIBCPP_VERSION) || (_LIBCPP_VERSION < 1101)) */ +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ long int __cdecl abs(long int) throw(); +#if defined(_LIBCPP_VERSION) +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ long long int __cdecl abs(long long int) throw(); +#endif /* defined(_LIBCPP_VERSION) */ +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl abs(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ double __cdecl abs(double) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl fabs(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl ceil(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl floor(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl sqrt(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl pow(float, float) throw(); +#if defined(_LIBCPP_VERSION) +#if (defined (__ANDROID__) || defined(__HORIZON__)) && (_LIBCPP_VERSION >= 9000) +template +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ +#if _LIBCPP_VERSION >= 14000 +typename std::__enable_if_t +#else /* _LIBCPP_VERSION < 14000 */ +typename std::_EnableIf +#endif /* _LIBCPP_VERSION >= 14000 */ +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type pow(_A1 __lcpp_x, _A2 __lcpp_y) __NV_NOEXCEPT; +#elif (defined(__APPLE__) && __clang_major__ >= 7) || _LIBCPP_VERSION >= 3800 || defined(__QNX__) +template +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ +typename std::__lazy_enable_if < + std::is_arithmetic<_Tp>::value && std::is_arithmetic<_Up>::value, + std::__promote<_Tp, _Up> +>::type pow(_Tp __x, _Up __y) __NV_NOEXCEPT; +#else /* !((__APPLE__ && __clang_major__ >= 7) || _LIBCPP_VERSION >= 3800) */ +template +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ +typename enable_if < + std::is_arithmetic<_Tp>::value && std::is_arithmetic<_Up>::value, + typename std::__promote<_Tp, _Up>::type +>::type pow(_Tp __x, _Up __y) __NV_NOEXCEPT; +#endif /* (__APPLE__ && __clang_major__ >= 7) || _LIBCPP_VERSION >= 3800 */ +#else /* !defined(_LIBCPP_VERSION) */ +#if !(defined(__GNUC__) && __cplusplus >= 201103L) +#if (defined(_MSC_VER) && (_MSC_VER >= 1928)) && !(defined __CUDA_INTERNAL_SKIP_CPP_HEADERS__) +template && ::std:: is_arithmetic_v<_Ty2>, int> > [[nodiscard]] __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ ::std:: _Common_float_type_t<_Ty1, _Ty2> __cdecl pow(_Ty1 _Left, _Ty2 _Right) noexcept; +#else +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl pow(float, int) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ double __cdecl pow(double, int) throw(); +#endif /* (defined(_MSC_VER) && (_MSC_VER >= 1928)) && !(defined __CUDA_INTERNAL_SKIP_CPP_HEADERS__) */ +#endif /* !(defined(__GNUC__) && __cplusplus >= 201103L) */ +#endif /* defined(_LIBCPP_VERSION) */ +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl log(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl log10(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl fmod(float, float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl modf(float, float*) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl exp(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl frexp(float, int*) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl ldexp(float, int) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl asin(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl sin(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl sinh(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl acos(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl cos(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl cosh(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl atan(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl atan2(float, float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl tan(float) throw(); +extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float __cdecl tanh(float) throw(); +#endif /* __CUDACC_RTC__ || + (!defined(_MSC_VER) || _MSC_VER < 1800) && + (!defined(_LIBCPP_VERSION) || (_LIBCPP_VERSION < 1101)) */ + +#if defined(_LIBCPP_VERSION) && defined(_LIBCPP_END_NAMESPACE_STD) && !defined(_STLPORT_VERSION) +#if _LIBCPP_VERSION < 3800 +_LIBCPP_END_NAMESPACE_STD +#endif /* _LIBCPP_VERSION < 3800 */ +#if defined(__clang__) +#pragma clang diagnostic pop +#endif /* __clang__ */ +#elif defined(__GNUC__) && !defined(_STLPORT_VERSION) +} +#endif /* defined(_LIBCPP_VERSION) && defined(_LIBCPP_BEGIN_NAMESPACE_STD) && !defined(_STLPORT_VERSION) || + __GNUC__ && !_STLPORT_VERSION */ + +#undef __DEVICE_FUNCTIONS_DECL__ +#undef __NV_NOEXCEPT + +#if defined(__CUDACC_RTC__) +#define __MATH_FUNCTIONS_DECL__ __host__ __device__ +#define __MATH_FUNCTIONS_DEVICE_DECL__ __device__ +#else /* __CUDACC_RTC__ */ +#define __MATH_FUNCTIONS_DECL__ static inline __host__ __device__ __cudart_builtin__ +#define __MATH_FUNCTIONS_DEVICE_DECL__ static inline __device__ __cudart_builtin__ +#endif /* __CUDACC_RTC__ */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +#if defined(__QNX__) || (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 3800) +#if defined(__QNX__) && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 8000) +#if defined(_LIBCPP_VERSION) +#define __NV_NOEXCEPT _NOEXCEPT +_LIBCPP_BEGIN_NAMESPACE_STD +#else +#define __NV_NOEXCEPT +namespace std { +__host__ __device__ __cudart_builtin__ int ilogbf(float a); +#endif +#else /* !(defined(__QNX__) && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 8000)) */ +#define __NV_NOEXCEPT _NOEXCEPT +#endif /* defined(__QNX__) && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 8000) */ +__host__ __device__ __cudart_builtin__ float logb(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ int ilogb(float a) __NV_NOEXCEPT; + +__host__ __device__ __cudart_builtin__ float scalbn(float a, int b) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float scalbln(float a, long int b) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float exp2(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float expm1(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float log2(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float log1p(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float acosh(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float asinh(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float atanh(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float hypot(float a, float b) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float cbrt(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float erf(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float erfc(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float lgamma(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float tgamma(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float copysign(float a, float b) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float nextafter(float a, float b) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float remainder(float a, float b) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float remquo(float a, float b, int *quo) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float round(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ long int lround(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ long long int llround(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float trunc(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float rint(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ long int lrint(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ long long int llrint(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float nearbyint(float a) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float fdim(float a, float b) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float fma(float a, float b, float c) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float fmax(float a, float b) __NV_NOEXCEPT; +__host__ __device__ __cudart_builtin__ float fmin(float a, float b) __NV_NOEXCEPT; +#if defined(__QNX__) && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 8000) +#if defined(_LIBCPP_VERSION) +_LIBCPP_END_NAMESPACE_STD +using _VSTD::logb; +using _VSTD::ilogb; +using _VSTD::scalbn; +using _VSTD::scalbln; +using _VSTD::exp2; +using _VSTD::expm1; +using _VSTD::log2; +using _VSTD::log1p; +using _VSTD::acosh; +using _VSTD::asinh; +using _VSTD::atanh; +using _VSTD::hypot; +using _VSTD::cbrt; +using _VSTD::erf; +using _VSTD::erfc; +using _VSTD::lgamma; +using _VSTD::tgamma; +using _VSTD::copysign; +using _VSTD::nextafter; +using _VSTD::remainder; +using _VSTD::remquo; +using _VSTD::round; +using _VSTD::lround; +using _VSTD::llround; +using _VSTD::trunc; +using _VSTD::rint; +using _VSTD::lrint; +using _VSTD::llrint; +using _VSTD::nearbyint; +using _VSTD::fdim; +using _VSTD::fma; +using _VSTD::fmax; +using _VSTD::fmin; +#else +} +#endif +#endif /* defined(__QNX__) && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 8000) */ +#undef __NV_NOEXCEPT +#else /* !(defined(__QNX__ ) || (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 3800)) */ +#if ((defined _GLIBCXX_MATH_H) && _GLIBCXX_MATH_H) && (__cplusplus >= 201103L) +namespace std { +__host__ __device__ __cudart_builtin__ constexpr float logb(float a); +__host__ __device__ __cudart_builtin__ constexpr int ilogb(float a); +__host__ __device__ __cudart_builtin__ constexpr float scalbn(float a, int b); +__host__ __device__ __cudart_builtin__ constexpr float scalbln(float a, long int b); +__host__ __device__ __cudart_builtin__ constexpr float exp2(float a); +__host__ __device__ __cudart_builtin__ constexpr float expm1(float a); +__host__ __device__ __cudart_builtin__ constexpr float log2(float a); +__host__ __device__ __cudart_builtin__ constexpr float log1p(float a); +__host__ __device__ __cudart_builtin__ constexpr float acosh(float a); +__host__ __device__ __cudart_builtin__ constexpr float asinh(float a); +__host__ __device__ __cudart_builtin__ constexpr float atanh(float a); +__host__ __device__ __cudart_builtin__ constexpr float hypot(float a, float b); +__host__ __device__ __cudart_builtin__ constexpr float cbrt(float a); +__host__ __device__ __cudart_builtin__ constexpr float erf(float a); +__host__ __device__ __cudart_builtin__ constexpr float erfc(float a); +__host__ __device__ __cudart_builtin__ constexpr float lgamma(float a); +__host__ __device__ __cudart_builtin__ constexpr float tgamma(float a); +__host__ __device__ __cudart_builtin__ constexpr float copysign(float a, float b); +__host__ __device__ __cudart_builtin__ constexpr float nextafter(float a, float b); +__host__ __device__ __cudart_builtin__ constexpr float remainder(float a, float b); +__host__ __device__ __cudart_builtin__ float remquo(float a, float b, int *quo); +__host__ __device__ __cudart_builtin__ constexpr float round(float a); +__host__ __device__ __cudart_builtin__ constexpr long int lround(float a); +__host__ __device__ __cudart_builtin__ constexpr long long int llround(float a); +__host__ __device__ __cudart_builtin__ constexpr float trunc(float a); +__host__ __device__ __cudart_builtin__ constexpr float rint(float a); +__host__ __device__ __cudart_builtin__ constexpr long int lrint(float a); +__host__ __device__ __cudart_builtin__ constexpr long long int llrint(float a); +__host__ __device__ __cudart_builtin__ constexpr float nearbyint(float a); +__host__ __device__ __cudart_builtin__ constexpr float fdim(float a, float b); +__host__ __device__ __cudart_builtin__ constexpr float fma(float a, float b, float c); +__host__ __device__ __cudart_builtin__ constexpr float fmax(float a, float b); +__host__ __device__ __cudart_builtin__ constexpr float fmin(float a, float b); +} +#else /* !(((defined _GLIBCXX_MATH_H) && _GLIBCXX_MATH_H) && (__cplusplus >= 201103L)) */ +__MATH_FUNCTIONS_DECL__ float logb(float a); + +__MATH_FUNCTIONS_DECL__ int ilogb(float a); + +__MATH_FUNCTIONS_DECL__ float scalbn(float a, int b); + +__MATH_FUNCTIONS_DECL__ float scalbln(float a, long int b); + +__MATH_FUNCTIONS_DECL__ float exp2(float a); + +__MATH_FUNCTIONS_DECL__ float expm1(float a); + +__MATH_FUNCTIONS_DECL__ float log2(float a); + +__MATH_FUNCTIONS_DECL__ float log1p(float a); + +__MATH_FUNCTIONS_DECL__ float acosh(float a); + +__MATH_FUNCTIONS_DECL__ float asinh(float a); + +__MATH_FUNCTIONS_DECL__ float atanh(float a); + +__MATH_FUNCTIONS_DECL__ float hypot(float a, float b); + +__MATH_FUNCTIONS_DECL__ float cbrt(float a); + +__MATH_FUNCTIONS_DECL__ float erf(float a); + +__MATH_FUNCTIONS_DECL__ float erfc(float a); + +__MATH_FUNCTIONS_DECL__ float lgamma(float a); + +__MATH_FUNCTIONS_DECL__ float tgamma(float a); + +__MATH_FUNCTIONS_DECL__ float copysign(float a, float b); + +__MATH_FUNCTIONS_DECL__ float nextafter(float a, float b); + +__MATH_FUNCTIONS_DECL__ float remainder(float a, float b); + +__MATH_FUNCTIONS_DECL__ float remquo(float a, float b, int *quo); + +__MATH_FUNCTIONS_DECL__ float round(float a); + +__MATH_FUNCTIONS_DECL__ long int lround(float a); + +__MATH_FUNCTIONS_DECL__ long long int llround(float a); + +__MATH_FUNCTIONS_DECL__ float trunc(float a); + +__MATH_FUNCTIONS_DECL__ float rint(float a); + +__MATH_FUNCTIONS_DECL__ long int lrint(float a); + +__MATH_FUNCTIONS_DECL__ long long int llrint(float a); + +__MATH_FUNCTIONS_DECL__ float nearbyint(float a); + +__MATH_FUNCTIONS_DECL__ float fdim(float a, float b); + +__MATH_FUNCTIONS_DECL__ float fma(float a, float b, float c); + +__MATH_FUNCTIONS_DECL__ float fmax(float a, float b); + +__MATH_FUNCTIONS_DECL__ float fmin(float a, float b); +#endif /* ((defined _GLIBCXX_MATH_H) && _GLIBCXX_MATH_H) && (__cplusplus >= 201103L) */ +#endif /* defined(__QNX__) || (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 3800) */ +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +extern __host__ __device__ __cudart_builtin__ float __cdecl logb(float) throw(); +extern __host__ __device__ __cudart_builtin__ int __cdecl ilogb(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl scalbn(float, float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl scalbln(float, long int) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl exp2(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl expm1(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl log2(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl log1p(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl acosh(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl asinh(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl atanh(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl hypot(float, float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl cbrt(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl erf(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl erfc(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl lgamma(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl tgamma(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl copysign(float, float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl nextafter(float, float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl remainder(float, float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl remquo(float, float, int *) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl round(float) throw(); +extern __host__ __device__ __cudart_builtin__ long int __cdecl lround(float) throw(); +extern __host__ __device__ __cudart_builtin__ long long int __cdecl llround(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl trunc(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl rint(float) throw(); +extern __host__ __device__ __cudart_builtin__ long int __cdecl lrint(float) throw(); +extern __host__ __device__ __cudart_builtin__ long long int __cdecl llrint(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl nearbyint(float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl fdim(float, float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl fma(float, float, float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl fmax(float, float) throw(); +extern __host__ __device__ __cudart_builtin__ float __cdecl fmin(float, float) throw(); +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +__MATH_FUNCTIONS_DECL__ float exp10(const float a); + +__MATH_FUNCTIONS_DECL__ float rsqrt(const float a); + +__MATH_FUNCTIONS_DECL__ float rcbrt(const float a); + +__MATH_FUNCTIONS_DECL__ float sinpi(const float a); + +__MATH_FUNCTIONS_DECL__ float cospi(const float a); + +__MATH_FUNCTIONS_DECL__ void sincospi(const float a, float *const sptr, float *const cptr); + +__MATH_FUNCTIONS_DECL__ void sincos(const float a, float *const sptr, float *const cptr); + +__MATH_FUNCTIONS_DECL__ float j0(const float a); + +__MATH_FUNCTIONS_DECL__ float j1(const float a); + +__MATH_FUNCTIONS_DECL__ float jn(const int n, const float a); + +__MATH_FUNCTIONS_DECL__ float y0(const float a); + +__MATH_FUNCTIONS_DECL__ float y1(const float a); + +__MATH_FUNCTIONS_DECL__ float yn(const int n, const float a); + +__MATH_FUNCTIONS_DEVICE_DECL__ float cyl_bessel_i0(const float a); + +__MATH_FUNCTIONS_DEVICE_DECL__ float cyl_bessel_i1(const float a); + +__MATH_FUNCTIONS_DECL__ float erfinv(const float a); + +__MATH_FUNCTIONS_DECL__ float erfcinv(const float a); + +__MATH_FUNCTIONS_DECL__ float normcdfinv(const float a); + +__MATH_FUNCTIONS_DECL__ float normcdf(const float a); + +__MATH_FUNCTIONS_DECL__ float erfcx(const float a); + +__MATH_FUNCTIONS_DECL__ double copysign(const double a, const float b); + +__MATH_FUNCTIONS_DECL__ double copysign(const float a, const double b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p unsigned \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b. + */ +__MATH_FUNCTIONS_DECL__ unsigned int min(const unsigned int a, const unsigned int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p int and \p unsigned \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned int min(const int a, const unsigned int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p unsigned \p int and \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned int min(const unsigned int a, const int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p long \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b. + */ +__MATH_FUNCTIONS_DECL__ long int min(const long int a, const long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p unsigned \p long \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b. + */ +__MATH_FUNCTIONS_DECL__ unsigned long int min(const unsigned long int a, const unsigned long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p long \p int and \p unsigned \p long \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned long int min(const long int a, const unsigned long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p unsigned \p long \p int and \p long \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned long int min(const unsigned long int a, const long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p long \p long \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b. + */ +__MATH_FUNCTIONS_DECL__ long long int min(const long long int a, const long long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p unsigned \p long \p long \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b. + */ +__MATH_FUNCTIONS_DECL__ unsigned long long int min(const unsigned long long int a, const unsigned long long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p long \p long \p int and \p unsigned \p long \p long \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned long long int min(const long long int a, const unsigned long long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the minimum value of the input \p unsigned \p long \p long \p int and \p long \p long \p int arguments. + * + * Calculate the minimum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned long long int min(const unsigned long long int a, const long long int b); + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the minimum value of the input \p float arguments. + * + * Calculate the minimum value of the arguments \p a and \p b. + * Behavior is equivalent to ::fminf() function. + * + * Note, this is different from \p std:: specification + */ +__MATH_FUNCTIONS_DECL__ float min(const float a, const float b); + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the minimum value of the input \p float arguments. + * + * Calculate the minimum value of the arguments \p a and \p b. + * Behavior is equivalent to ::fmin() function. + * + * Note, this is different from \p std:: specification + */ +__MATH_FUNCTIONS_DECL__ double min(const double a, const double b); + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the minimum value of the input \p float and \p double arguments. + * + * Convert \p float argument \p a to \p double, followed by ::fmin(). + * + * Note, this is different from \p std:: specification + */ +__MATH_FUNCTIONS_DECL__ double min(const float a, const double b); + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the minimum value of the input \p double and \p float arguments. + * + * Convert \p float argument \p b to \p double, followed by ::fmin(). + * + * Note, this is different from \p std:: specification + */ +__MATH_FUNCTIONS_DECL__ double min(const double a, const float b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p unsigned \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b. + */ +__MATH_FUNCTIONS_DECL__ unsigned int max(const unsigned int a, const unsigned int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p int and \p unsigned \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned int max(const int a, const unsigned int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p unsigned \p int and \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned int max(const unsigned int a, const int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p long \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b. + */ +__MATH_FUNCTIONS_DECL__ long int max(const long int a, const long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p unsigned \p long \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b. + */ +__MATH_FUNCTIONS_DECL__ unsigned long int max(const unsigned long int a, const unsigned long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p long \p int and \p unsigned \p long \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned long int max(const long int a, const unsigned long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p unsigned \p long \p int and \p long \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned long int max(const unsigned long int a, const long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p long \p long \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b. + */ +__MATH_FUNCTIONS_DECL__ long long int max(const long long int a, const long long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p unsigned \p long \p long \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b. + */ +__MATH_FUNCTIONS_DECL__ unsigned long long int max(const unsigned long long int a, const unsigned long long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p long \p long \p int and \p unsigned \p long \p long \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned long long int max(const long long int a, const unsigned long long int b); + +/** + * \ingroup CUDA_MATH_INT + * \brief Calculate the maximum value of the input \p unsigned \p long \p long \p int and \p long \p long \p int arguments. + * + * Calculate the maximum value of the arguments \p a and \p b, perform integer promotion first. + */ +__MATH_FUNCTIONS_DECL__ unsigned long long int max(const unsigned long long int a, const long long int b); + +/** + * \ingroup CUDA_MATH_SINGLE + * \brief Calculate the maximum value of the input \p float arguments. + * + * Calculate the maximum value of the arguments \p a and \p b. + * Behavior is equivalent to ::fmaxf() function. + * + * Note, this is different from \p std:: specification + */ +__MATH_FUNCTIONS_DECL__ float max(const float a, const float b); + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the maximum value of the input \p float arguments. + * + * Calculate the maximum value of the arguments \p a and \p b. + * Behavior is equivalent to ::fmax() function. + * + * Note, this is different from \p std:: specification + */ +__MATH_FUNCTIONS_DECL__ double max(const double a, const double b); + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the maximum value of the input \p float and \p double arguments. + * + * Convert \p float argument \p a to \p double, followed by ::fmax(). + * + * Note, this is different from \p std:: specification + */ +__MATH_FUNCTIONS_DECL__ double max(const float a, const double b); + +/** + * \ingroup CUDA_MATH_DOUBLE + * \brief Calculate the maximum value of the input \p double and \p float arguments. + * + * Convert \p float argument \p b to \p double, followed by ::fmax(). + * + * Note, this is different from \p std:: specification + */ +__MATH_FUNCTIONS_DECL__ double max(const double a, const float b); + +#undef __MATH_FUNCTIONS_DECL__ +#undef __MATH_FUNCTIONS_DEVICE_DECL__ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +extern "C"{ +inline __device__ void *__nv_aligned_device_malloc(size_t size, size_t align) +{ + __device__ void *__nv_aligned_device_malloc_impl(size_t, size_t); + return __nv_aligned_device_malloc_impl(size, align); +} +} +#endif /* __cplusplus && __CUDACC__ */ +#if !defined(__CUDACC__) + +/******************************************************************************* +* * +* ONLY FOR HOST CODE! NOT FOR DEVICE EXECUTION * +* * +*******************************************************************************/ + +#include + +#if defined(_WIN32) + +#pragma warning(disable : 4211) + +#endif /* _WIN32 */ + +__func__(double rsqrt(double a)); + +__func__(double rcbrt(double a)); + +__func__(double sinpi(double a)); + +__func__(double cospi(double a)); + +__func__(void sincospi(double a, double *sptr, double *cptr)); + +__func__(double erfinv(double a)); + +__func__(double erfcinv(double a)); + +__func__(double normcdfinv(double a)); + +__func__(double normcdf(double a)); + +__func__(double erfcx(double a)); + +__func__(float rsqrtf(float a)); + +__func__(float rcbrtf(float a)); + +__func__(float sinpif(float a)); + +__func__(float cospif(float a)); + +__func__(void sincospif(float a, float *sptr, float *cptr)); + +__func__(float erfinvf(float a)); + +__func__(float erfcinvf(float a)); + +__func__(float normcdfinvf(float a)); + +__func__(float normcdff(float a)); + +__func__(float erfcxf(float a)); + +__func__(int min(int a, int b)); + +__func__(unsigned int umin(unsigned int a, unsigned int b)); + +__func__(long long int llmin(long long int a, long long int b)); + +__func__(unsigned long long int ullmin(unsigned long long int a, unsigned long long int b)); + +__func__(int max(int a, int b)); + +__func__(unsigned int umax(unsigned int a, unsigned int b)); + +__func__(long long int llmax(long long int a, long long int b)); + +__func__(unsigned long long int ullmax(unsigned long long int a, unsigned long long int b)); + +#if defined(_WIN32) || defined(__APPLE__) || defined (__ANDROID__) + +__func__(int __isnan(double a)); + +#endif /* _WIN32 || __APPLE__ || __ANDROID__ */ + +#if defined(_WIN32) || defined(__APPLE__) || defined (__QNX__) + +__func__(void sincos(double a, double *sptr, double *cptr)); + +#endif /* _WIN32 || __APPLE__ || __QNX__ */ + +#if defined(_WIN32) || defined(__APPLE__) + +__func__(double exp10(double a)); + +__func__(float exp10f(float a)); + +__func__(void sincosf(float a, float *sptr, float *cptr)); + +__func__(int __isinf(double a)); + +#endif /* _WIN32 || __APPLE__ */ + +#if (defined(_WIN32) && (!defined(_MSC_VER) || _MSC_VER < 1800)) || defined (__ANDROID__) + +__func__(double log2(double a)); + +#endif /* (_WIN32 && (!defined(_MSC_VER) || _MSC_VER < 1800)) || __ANDROID__ */ + +#if defined(_WIN32) + +__func__(int __signbit(double a)); + +__func__(int __finite(double a)); + +__func__(int __signbitl(long double a)); + +__func__(int __signbitf(float a)); + +__func__(int __finitel(long double a)); + +__func__(int __finitef(float a)); + +__func__(int __isinfl(long double a)); + +__func__(int __isinff(float a)); + +__func__(int __isnanl(long double a)); + +__func__(int __isnanf(float a)); + +#endif /* _WIN32 */ + +#if defined(_WIN32) && (!defined(_MSC_VER) || _MSC_VER < 1800) + +__func__(double copysign(double a, double b)); + +__func__(double fmax(double a, double b)); + +__func__(double fmin(double a, double b)); + +__func__(double trunc(double a)); + +__func__(double round(double a)); + +__func__(long int lround(double a)); + +__func__(long long int llround(double a)); + +__func__(double rint(double a)); + +__func__(double nearbyint(double a)); + +__func__(long int lrint(double a)); + +__func__(long long int llrint(double a)); + +__func__(double fdim(double a, double b)); + +__func__(double scalbn(double a, int b)); + +__func__(double scalbln(double a, long int b)); + +__func__(double exp2(double a)); + +__func__(double log1p(double a)); + +__func__(double expm1(double a)); + +__func__(double cbrt(double a)); + +__func__(double acosh(double a)); + +__func__(double asinh(double a)); + +__func__(double atanh(double a)); + +__func__(int ilogb(double a)); + +__func__(double logb(double a)); + +__func__(double remquo(double a, double b, int *quo)); + +__func__(double remainder(double a, double b)); + +__func__(double fma (double a, double b, double c)); + +__func__(double nextafter(double a, double b)); + +__func__(double erf(double a)); + +__func__(double erfc(double a)); + +__func__(double lgamma(double a)); + +__func__(unsigned long long int __internal_host_nan_kernel(const char *s)); + +__func__(double nan(const char *tagp)); + +__func__(double __host_tgamma_kernel(double a)); + +__func__(double __host_stirling_poly(double a)); + +__func__(double __host_tgamma_stirling(double a)); + +__func__(double tgamma(double a)); + +__func__(float fmaxf(float a, float b)); + +__func__(float fminf(float a, float b)); + +__func__(float roundf(float a)); + +__func__(long int lroundf(float a)); + +__func__(long long int llroundf(float a)); + +__func__(float truncf(float a)); + +__func__(float rintf(float a)); + +__func__(float nearbyintf(float a)); + +__func__(long int lrintf(float a)); + +__func__(long long int llrintf(float a)); + +__func__(float logbf(float a)); + +__func__(float scalblnf(float a, long int b)); + +__func__(float log2f(float a)); + +__func__(float exp2f(float a)); + +__func__(float acoshf(float a)); + +__func__(float asinhf(float a)); + +__func__(float atanhf(float a)); + +__func__(float cbrtf(float a)); + +__func__(float expm1f(float a)); + +__func__(float fdimf(float a, float b)); + +__func__(float log1pf(float a)); + +__func__(float scalbnf(float a, int b)); + +__func__(float fmaf(float a, float b, float c)); + +__func__(int ilogbf(float a)); + +__func__(float erff(float a)); + +__func__(float erfcf(float a)); + +__func__(float lgammaf(float a)); + +__func__(float tgammaf(float a)); + +__func__(float remquof(float a, float b, int *quo)); + +__func__(float remainderf(float a, float b)); + +__func__(float copysignf(float a, float b)); + +__func__(float nextafterf(float a, float b)); + +__func__(float nanf(const char *tagp)); + +#endif /* _WIN32 && (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if defined(_WIN32) + +#pragma warning(default: 4211) + +#endif /* _WIN32 */ + +#endif /* !__CUDACC__ */ + +#if !defined(__CUDACC_RTC__) + +#include "math_functions.hpp" + +#endif /* !__CUDACC_RTC__ */ + +#endif /* !__MATH_FUNCTIONS_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_MATH_FUNCTIONS_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_MATH_FUNCTIONS_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/math_functions.hpp b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/math_functions.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3e434aa0c38dd6e62efde83bc1ba3313a8d2bf07 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/math_functions.hpp @@ -0,0 +1,3391 @@ +/* + * Copyright 1993-2023 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/math_functions.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/math_functions.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_MATH_FUNCTIONS_HPP__ +#endif + +#if !defined(__MATH_FUNCTIONS_HPP__) +#define __MATH_FUNCTIONS_HPP__ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__cplusplus) && defined(__CUDACC__) + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#include "builtin_types.h" +#include "host_defines.h" + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#if defined(__CUDACC_RTC__) + +__host__ __device__ __cudart_builtin__ int signbit(const float x) { return __signbitf(x); } +__host__ __device__ __cudart_builtin__ int signbit(const double x) { return __signbit(x); } +__host__ __device__ __cudart_builtin__ int signbit(const long double x) { return __signbitl(static_cast(x));} + +__host__ __device__ __cudart_builtin__ int isfinite(const float x) { return __finitef(x); } +__host__ __device__ __cudart_builtin__ int isfinite(const double x) { return __finite(x); } +__host__ __device__ __cudart_builtin__ int isfinite(const long double x) { return __finitel(static_cast(x)); } + +__host__ __device__ __cudart_builtin__ int isnan(const float x) { return __isnanf(x); } +__host__ __device__ __cudart_builtin__ int isnan(const double x) { return __isnan(x); } +__host__ __device__ __cudart_builtin__ int isnan(const long double x) { return __isnanl(static_cast(x)); } + +__host__ __device__ __cudart_builtin__ int isinf(const float x) { return __isinff(x); } +__host__ __device__ __cudart_builtin__ int isinf(const double x) { return __isinf(x); } +__host__ __device__ __cudart_builtin__ int isinf(const long double x) { return __isinfl(static_cast(x)); } + +__host__ __device__ __cudart_builtin__ long long int abs(const long long int a) { return llabs(a); } + +__host__ __device__ __cudart_builtin__ long int abs(const long int in) { return llabs(in); } +__host__ __device__ __cudart_builtin__ float abs(const float in) { return fabsf(in); } +__host__ __device__ __cudart_builtin__ double abs(const double in) { return fabs(in); } +__host__ __device__ __cudart_builtin__ float fabs(const float in) { return fabsf(in); } +__host__ __device__ __cudart_builtin__ float ceil(const float in) { return ceilf(in); } +__host__ __device__ __cudart_builtin__ float floor(const float in) { return floorf(in); } +__host__ __device__ __cudart_builtin__ float sqrt(const float in) { return sqrtf(in); } +__host__ __device__ __cudart_builtin__ float pow(const float a, const float b) { return powf(a, b); } +extern "C" __device__ float powif(float, int); +__host__ __device__ __cudart_builtin__ float pow(const float a, const int b) { return powif(a, b); } +extern "C" __device__ double powi(double, int); +__host__ __device__ __cudart_builtin__ double pow(const double a, const int b) { return powi(a, b); } +__host__ __device__ __cudart_builtin__ float log(const float in) { return logf(in); } +__host__ __device__ __cudart_builtin__ float log10(const float in) { return log10f(in); } +__host__ __device__ __cudart_builtin__ float fmod(const float a, const float b) { return fmodf(a, b); } +__host__ __device__ __cudart_builtin__ float modf(const float a, float*b) { return modff(a, b); } +__host__ __device__ __cudart_builtin__ float exp(const float in) { return expf(in); } +__host__ __device__ __cudart_builtin__ float frexp(const float a, int*b) { return frexpf(a, b); } +__host__ __device__ __cudart_builtin__ float ldexp(const float a, int b) { return ldexpf(a, b); } +__host__ __device__ __cudart_builtin__ float asin(const float in) { return asinf(in); } +__host__ __device__ __cudart_builtin__ float sin(const float in) { return sinf(in); } +__host__ __device__ __cudart_builtin__ float sinh(const float in) { return sinhf(in); } +__host__ __device__ __cudart_builtin__ float acos(const float in) { return acosf(in); } +__host__ __device__ __cudart_builtin__ float cos(const float in) { return cosf(in); } +__host__ __device__ __cudart_builtin__ float cosh(const float in) { return coshf(in); } +__host__ __device__ __cudart_builtin__ float atan(const float in) { return atanf(in); } +__host__ __device__ __cudart_builtin__ float atan2(const float a, const float b) { return atan2f(a, b); } +__host__ __device__ __cudart_builtin__ float tan(const float in) { return tanf(in); } +__host__ __device__ __cudart_builtin__ float tanh(const float in) { return tanhf(in); } + +#elif defined(__GNUC__) + +#undef signbit +#undef isfinite +#undef isnan +#undef isinf + +#if defined(_LIBCPP_VERSION) +extern "C" __device__ float powif(float, int); +extern "C" __device__ double powi(double, int); +#endif /* _LIBCPP_VERSION */ + +#if defined(__APPLE__) +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const float x) { return __signbitf(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const double x) { return __signbitd(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const long double x) { return __signbitl(x);} + +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const float x) { return __isfinitef(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const double x) { return __isfinited(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const long double x) { return __isfinite(x); } + +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const double x) throw() { return __isnand(x); } +#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 7000 +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const float x) { return __isnanf(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const long double x) { return __isnan(x); } +#endif /* defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 7000 */ + +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const double x) throw() { return __isinfd(x); } +#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 7000 +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const float x) { return __isinff(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const long double x) { return __isinf(x); } +#endif /* defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 7000 */ +#else /* __APPLE__ */ + +#if ((defined _GLIBCXX_MATH_H) && _GLIBCXX_MATH_H) && (__cplusplus >= 201103L) +#if defined(__CUDA_ARCH__) +#define __NV_BUILTIN_FUNC_DECL__ __forceinline__ __host__ __device__ __cudart_builtin__ +#if _GLIBCXX_HAVE_OBSOLETE_ISNAN && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC +__NV_BUILTIN_FUNC_DECL__ int isnan(const double a) throw() { return __isnan(a); } +__NV_BUILTIN_FUNC_DECL__ int isinf(const double x) throw() { return __isinf(x); } +#endif /* _GLIBCXX_HAVE_OBSOLETE_ISNAN && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC */ +#undef __NV_BUILTIN_FUNC_DECL__ +#endif /* __CUDA_ARCH */ +#else /* !(((defined _GLIBCXX_MATH_H) && _GLIBCXX_MATH_H) && (__cplusplus >= 201103L)) */ + +#if defined(__QNX__) +#if defined(__QNX__) && defined(_LIBCPP_VERSION) +static __inline__ __host__ __device__ __cudart_builtin__ bool signbit(const float x) +{ +#if defined(__CUDA_ARCH__) + return (__signbitf(x) != 0); +#else /* !__CUDA_ARCH__ */ + return signbit(x); +#endif /* __CUDA_ARCH__ */ +} +static __inline__ __host__ __device__ __cudart_builtin__ bool signbit(const double x) +{ +#if defined(__CUDA_ARCH__) + return (__signbit(x) != 0); +#else /* !__CUDA_ARCH__ */ + return signbit(x); +#endif /* __CUDA_ARCH__ */ +} +static __inline__ __host__ __device__ __cudart_builtin__ bool signbit(const long double x) +{ +#if defined(__CUDA_ARCH__) + return (__signbitl(x) != 0); +#else /* !__CUDA_ARCH__ */ + return signbit(x); +#endif /* __CUDA_ARCH__ */ +} +#endif /* (__QNX__ && _LIBCPP_VERSION) */ + +static __inline__ __host__ __device__ __cudart_builtin__ bool isfinite(const long double a) +{ +#if defined(__CUDA_ARCH__) + return (__finitel(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isfinite(a); +#endif /* defined(__CUDA_ARCH__) */ +} +static __inline__ __host__ __device__ __cudart_builtin__ bool isfinite(const double a) +{ +#if defined(__CUDA_ARCH__) + return (__finite(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isfinite(a); +#endif /* defined(__CUDA_ARCH__) */ +} +static __inline__ __host__ __device__ __cudart_builtin__ bool isfinite(const float a) +{ +#if defined(__CUDA_ARCH__) + return (__finitef(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isfinite(a); +#endif /* defined(__CUDA_ARCH__) */ +} + +static __inline__ __host__ __device__ __cudart_builtin__ bool isnan(const long double a) +{ +#if defined(__CUDA_ARCH__) + return (__isnanl(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isnan(a); +#endif /* defined(__CUDA_ARCH__) */ +} +static __inline__ __host__ __device__ __cudart_builtin__ bool isnan(const double a) +{ +#if defined(__CUDA_ARCH__) + return (__isnan(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isnan(a); +#endif /* defined(__CUDA_ARCH__) */ +} +static __inline__ __host__ __device__ __cudart_builtin__ bool isnan(const float a) +{ +#if defined(__CUDA_ARCH__) + return (__isnanf(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isnan(a); +#endif /* defined(__CUDA_ARCH__) */ +} + +static __inline__ __host__ __device__ __cudart_builtin__ bool isinf(const long double a) +{ +#if defined(__CUDA_ARCH__) + return (__isinfl(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isinf(a); +#endif /* defined(__CUDA_ARCH__) */ +} +static __inline__ __host__ __device__ __cudart_builtin__ bool isinf(const double a) +{ +#if defined(__CUDA_ARCH__) + return (__isinf(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isinf(a); +#endif /* defined(__CUDA_ARCH__) */ +} +static __inline__ __host__ __device__ __cudart_builtin__ bool isinf(const float a) +{ +#if defined(__CUDA_ARCH__) + return (__isinff(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isinf(a); +#endif /* defined(__CUDA_ARCH__) */ +} + +#elif ( (defined(__ANDROID__) || defined(__HORIZON__)) && defined(_LIBCPP_VERSION)) +#if defined(__CUDA_ARCH__) +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const float x) { return __signbitf(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const double x) { return __signbit(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const long double x) { return __signbitl(x);} + +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const float x) { return __finitef(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const double x) { return __finite(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const long double x) { return __finitel(x); } + +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const double x) { return __isnan(x); } +#if _LIBCPP_VERSION < 8000 +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const float x) { return __isnanf(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const long double x) { return __isnanl(x); } +#endif /* _LIBCPP_VERSION < 8000 */ + +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const double x) { return __isinf(x); } +#if _LIBCPP_VERSION < 8000 +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const float x) { return __isinff(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const long double x) { return __isinfl(x); } +#endif /* _LIBCPP_VERSION < 8000 */ +#else /* !defined(__CUDA_ARCH__) */ +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const float x) { return signbit(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const double x) { return signbit(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const long double x) { return signbit(x);} + +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const float x) { return isfinite(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const double x) { return isfinite(x); } +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const long double x) { return isfinite(x); } + +#if _LIBCPP_VERSION < 8000 +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const float x) { return isnan(x); } +/* int isnan(double) provided by math.h */ +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const long double x) { return isnan(x); } + +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const float x) { return isinf(x); } +/* int isinf(double) provided by math.h */ +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const long double x) { return isinf(x); } +#endif /* _LIBCPP_VERSION < 8000 */ + +#endif /* defined(__CUDA_ARCH__) */ + +#else /* !__QNX__ */ +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const float x) { return __signbitf(x); } +#if defined(__ICC) +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const double x) throw() { return __signbit(x); } +#else /* !__ICC */ +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const double x) { return __signbit(x); } +#endif /* __ICC */ +__forceinline__ __host__ __device__ __cudart_builtin__ int signbit(const long double x) { return __signbitl(x);} + +#if defined(__ANDROID__) +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const float x) { +#if defined(__CUDA_ARCH__) + return __finitef(x); +#else /* !__CUDA_ARCH__ */ + return __isfinitef(x); +#endif /* __CUDA_ARCH__ */ +} +#else /* !__ANDROID__ */ +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const float x) { return __finitef(x); } +#endif /* __ANDROID__ */ + +#if defined(__ANDROID__) +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const double x) +{ +#ifdef __CUDA_ARCH__ + return __finite(x); +#else /* !__CUDA_ARCH__ */ + return __isfinite(x); +#endif /* __CUDA_ARCH__ */ +} +#elif defined(__ICC) +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const double x) throw() { return __finite(x); } +#else +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const double x) { return __finite(x); } +#endif /* __ANDROID__ */ + +#if defined(__ANDROID__) +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const long double x) +{ +#ifdef __CUDA_ARCH__ + return __finitel(x); +#else /* !__CUDA_ARCH__ */ + return __isfinitel(x); +#endif /* __CUDA_ARCH__ */ +} +#else /* !__ANDROID__ */ +__forceinline__ __host__ __device__ __cudart_builtin__ int isfinite(const long double x) { return __finitel(x); } +#endif /* __ANDROID__ */ + +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const float x) { return __isnanf(x); } +#if defined(__ANDROID__) +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const double x) { return __isnan(x); } +#else /* !__ANDROID__ */ +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const double x) throw() { return __isnan(x); } +#endif /* __ANDROID__ */ +__forceinline__ __host__ __device__ __cudart_builtin__ int isnan(const long double x) { return __isnanl(x); } + +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const float x) { return __isinff(x); } +#if defined(__ANDROID__) +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const double x) { return __isinf(x); } +#else /* !__ANDROID__ */ +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const double x) throw() { return __isinf(x); } +#endif /* __ANDROID__ */ +__forceinline__ __host__ __device__ __cudart_builtin__ int isinf(const long double x) { return __isinfl(x); } +#endif /* __QNX__ || __HORIZON__ */ + +#endif /* ((defined _GLIBCXX_MATH_H) && _GLIBCXX_MATH_H) && (__cplusplus >= 201103L) */ +#endif /* __APPLE__ */ + +#if defined(__arm__) && !defined(_STLPORT_VERSION) && !_GLIBCXX_USE_C99 +#if !defined(__ANDROID__) || (!defined(_LIBCPP_VERSION) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))) + +#if !defined(__QNX__) && !defined(__HORIZON__) +static __inline__ __host__ __device__ __cudart_builtin__ long long int abs(const long long int a) +{ + return llabs(a); +} +#endif /* !__QNX__ && !__HORIZON__*/ + +#endif /* !defined(__ANDROID__) || (!defined(_LIBCPP_VERSION) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))) */ +#endif /* __arm__ && !_STLPORT_VERSION && !_GLIBCXX_USE_C99 */ + +#elif defined(_WIN32) + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __host__ __device__ __cudart_builtin__ int signbit(const long double a) +{ + return __signbitl(a); +} + +static __inline__ __host__ __device__ __cudart_builtin__ int signbit(const double a) +{ + return __signbit(a); +} + +static __inline__ __host__ __device__ __cudart_builtin__ int signbit(const float a) +{ + return __signbitf(a); +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __host__ __device__ __cudart_builtin__ int isinf(const long double a) +{ + return __isinfl(a); +} +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __host__ __device__ __cudart_builtin__ bool isinf(const long double a) +{ +#if defined(__CUDA_ARCH__) + return (__isinfl(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isinf(a); +#endif /* defined(__CUDA_ARCH__) */ +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __host__ __device__ __cudart_builtin__ int isinf(const double a) +{ + return __isinf(a); +} +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __host__ __device__ __cudart_builtin__ bool isinf(const double a) +{ +#if defined(__CUDA_ARCH__) + return (__isinf(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isinf(a); +#endif /* defined(__CUDA_ARCH__) */ +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __host__ __device__ __cudart_builtin__ int isinf(const float a) +{ + return __isinff(a); +} +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __host__ __device__ bool isinf(const float a) +{ +#if defined(__CUDA_ARCH__) + return (__isinff(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isinf(a); +#endif /* defined(__CUDA_ARCH__) */ +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __host__ __device__ __cudart_builtin__ int isnan(const long double a) +{ + return __isnanl(a); +} +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __host__ __device__ __cudart_builtin__ bool isnan(const long double a) +{ +#if defined(__CUDA_ARCH__) + return (__isnanl(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isnan(a); +#endif /* defined(__CUDA_ARCH__) */ +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __host__ __device__ __cudart_builtin__ int isnan(const double a) +{ + return __isnan(a); +} +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __host__ __device__ __cudart_builtin__ bool isnan(const double a) +{ +#if defined(__CUDA_ARCH__) + return (__isnan(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isnan(a); +#endif /* defined(__CUDA_ARCH__) */ +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __host__ __device__ __cudart_builtin__ int isnan(const float a) +{ + return __isnanf(a); +} +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __host__ __device__ __cudart_builtin__ bool isnan(const float a) +{ +#if defined(__CUDA_ARCH__) + return (__isnanf(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isnan(a); +#endif /* defined(__CUDA_ARCH__) */ +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __host__ __device__ __cudart_builtin__ int isfinite(const long double a) +{ + return __finitel(a); +} +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __host__ __device__ __cudart_builtin__ bool isfinite(const long double a) +{ +#if defined(__CUDA_ARCH__) + return (__finitel(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isfinite(a); +#endif /* defined(__CUDA_ARCH__) */ +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __host__ __device__ __cudart_builtin__ int isfinite(const double a) +{ + return __finite(a); +} +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __host__ __device__ __cudart_builtin__ bool isfinite(const double a) +{ +#if defined(__CUDA_ARCH__) + return (__finite(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isfinite(a); +#endif /* defined(__CUDA_ARCH__) */ +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +static __inline__ __host__ __device__ __cudart_builtin__ int isfinite(const float a) +{ + return __finitef(a); +} +#else /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ +static __inline__ __host__ __device__ __cudart_builtin__ bool isfinite(const float a) +{ +#if defined(__CUDA_ARCH__) + return (__finitef(a) != 0); +#else /* defined(__CUDA_ARCH__) */ + return isfinite(a); +#endif /* defined(__CUDA_ARCH__) */ +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#endif /* __CUDACC_RTC__ */ + +#if defined(__CUDACC_RTC__) +#define __MATH_FUNCTIONS_DECL__ __host__ __device__ +#define __MATH_FUNCTIONS_DEVICE_DECL__ __device__ +#else /* __CUDACC_RTC__ */ +#define __MATH_FUNCTIONS_DECL__ static inline __host__ __device__ +#define __MATH_FUNCTIONS_DEVICE_DECL__ static inline __device__ +#endif /* __CUDACC_RTC__ */ + +#if defined(__CUDACC_RTC__) || (!defined(_MSC_VER) || _MSC_VER < 1800) +#if defined(__QNX__) && defined(_LIBCPP_VERSION) +_LIBCPP_BEGIN_NAMESPACE_STD +#endif /* __QNX__ && _LIBCPP_VERSION */ +#if !defined(__QNX__) && !(defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 3800) +#if !(((defined _GLIBCXX_MATH_H) && _GLIBCXX_MATH_H) && (__cplusplus >= 201103L)) +__MATH_FUNCTIONS_DECL__ float logb(const float a) +{ + return logbf(a); +} + +__MATH_FUNCTIONS_DECL__ int ilogb(const float a) +{ + return ilogbf(a); +} + +__MATH_FUNCTIONS_DECL__ float scalbn(const float a, const int b) +{ + return scalbnf(a, b); +} + +__MATH_FUNCTIONS_DECL__ float scalbln(const float a, const long int b) +{ + return scalblnf(a, b); +} + +__MATH_FUNCTIONS_DECL__ float exp2(const float a) +{ + return exp2f(a); +} + +__MATH_FUNCTIONS_DECL__ float expm1(const float a) +{ + return expm1f(a); +} + +__MATH_FUNCTIONS_DECL__ float log2(const float a) +{ + return log2f(a); +} + +__MATH_FUNCTIONS_DECL__ float log1p(const float a) +{ + return log1pf(a); +} + +__MATH_FUNCTIONS_DECL__ float acosh(const float a) +{ + return acoshf(a); +} + +__MATH_FUNCTIONS_DECL__ float asinh(const float a) +{ + return asinhf(a); +} + +__MATH_FUNCTIONS_DECL__ float atanh(const float a) +{ + return atanhf(a); +} + +__MATH_FUNCTIONS_DECL__ float hypot(const float a, const float b) +{ + return hypotf(a, b); +} + +__MATH_FUNCTIONS_DECL__ float cbrt(const float a) +{ + return cbrtf(a); +} + +__MATH_FUNCTIONS_DECL__ float erf(const float a) +{ + return erff(a); +} + +__MATH_FUNCTIONS_DECL__ float erfc(const float a) +{ + return erfcf(a); +} + +__MATH_FUNCTIONS_DECL__ float lgamma(const float a) +{ + return lgammaf(a); +} + +__MATH_FUNCTIONS_DECL__ float tgamma(const float a) +{ + return tgammaf(a); +} + +__MATH_FUNCTIONS_DECL__ float copysign(const float a, const float b) +{ + return copysignf(a, b); +} + +__MATH_FUNCTIONS_DECL__ float nextafter(const float a, const float b) +{ + return nextafterf(a, b); +} + +__MATH_FUNCTIONS_DECL__ float remainder(const float a, const float b) +{ + return remainderf(a, b); +} + +__MATH_FUNCTIONS_DECL__ float remquo(const float a, const float b, int *quo) +{ + return remquof(a, b, quo); +} + +__MATH_FUNCTIONS_DECL__ float round(const float a) +{ + return roundf(a); +} + +__MATH_FUNCTIONS_DECL__ long int lround(const float a) +{ + return lroundf(a); +} + +__MATH_FUNCTIONS_DECL__ long long int llround(const float a) +{ + return llroundf(a); +} + +__MATH_FUNCTIONS_DECL__ float trunc(const float a) +{ + return truncf(a); +} + +__MATH_FUNCTIONS_DECL__ float rint(const float a) +{ + return rintf(a); +} + +__MATH_FUNCTIONS_DECL__ long int lrint(const float a) +{ + return lrintf(a); +} + +__MATH_FUNCTIONS_DECL__ long long int llrint(const float a) +{ + return llrintf(a); +} + +__MATH_FUNCTIONS_DECL__ float nearbyint(const float a) +{ + return nearbyintf(a); +} + +__MATH_FUNCTIONS_DECL__ float fdim(const float a, const float b) +{ + return fdimf(a, b); +} + +__MATH_FUNCTIONS_DECL__ float fma(const float a, const float b, const float c) +{ + return fmaf(a, b, c); +} + +__MATH_FUNCTIONS_DECL__ float fmax(const float a, const float b) +{ + return fmaxf(a, b); +} + +__MATH_FUNCTIONS_DECL__ float fmin(const float a, const float b) +{ + return fminf(a, b); +} +#endif /* !(((defined _GLIBCXX_MATH_H) && _GLIBCXX_MATH_H) && (__cplusplus >= 201103L)) */ +#endif /* !(!defined(__QNX__) && !(defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 3800)) */ +#if defined(__QNX__) && defined(_LIBCPP_VERSION) +_LIBCPP_END_NAMESPACE_STD +#endif +#endif /* __CUDACC_RTC__ || (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +__MATH_FUNCTIONS_DECL__ float exp10(const float a) +{ + return exp10f(a); +} + +__MATH_FUNCTIONS_DECL__ float rsqrt(const float a) +{ + return rsqrtf(a); +} + +__MATH_FUNCTIONS_DECL__ float rcbrt(const float a) +{ + return rcbrtf(a); +} + +__MATH_FUNCTIONS_DECL__ float sinpi(const float a) +{ + return sinpif(a); +} + +__MATH_FUNCTIONS_DECL__ float cospi(const float a) +{ + return cospif(a); +} + +__MATH_FUNCTIONS_DECL__ void sincospi(const float a, float *const sptr, float *const cptr) +{ + sincospif(a, sptr, cptr); +} + +__MATH_FUNCTIONS_DECL__ void sincos(const float a, float *const sptr, float *const cptr) +{ + sincosf(a, sptr, cptr); +} + +__MATH_FUNCTIONS_DECL__ float j0(const float a) +{ + return j0f(a); +} + +__MATH_FUNCTIONS_DECL__ float j1(const float a) +{ + return j1f(a); +} + +__MATH_FUNCTIONS_DECL__ float jn(const int n, const float a) +{ + return jnf(n, a); +} + +__MATH_FUNCTIONS_DECL__ float y0(const float a) +{ + return y0f(a); +} + +__MATH_FUNCTIONS_DECL__ float y1(const float a) +{ + return y1f(a); +} + +__MATH_FUNCTIONS_DECL__ float yn(const int n, const float a) +{ + return ynf(n, a); +} + +__MATH_FUNCTIONS_DEVICE_DECL__ float cyl_bessel_i0(const float a) +{ + return cyl_bessel_i0f(a); +} + +__MATH_FUNCTIONS_DEVICE_DECL__ float cyl_bessel_i1(const float a) +{ + return cyl_bessel_i1f(a); +} + +__MATH_FUNCTIONS_DECL__ float erfinv(const float a) +{ + return erfinvf(a); +} + +__MATH_FUNCTIONS_DECL__ float erfcinv(const float a) +{ + return erfcinvf(a); +} + +__MATH_FUNCTIONS_DECL__ float normcdfinv(const float a) +{ + return normcdfinvf(a); +} + +__MATH_FUNCTIONS_DECL__ float normcdf(const float a) +{ + return normcdff(a); +} + +__MATH_FUNCTIONS_DECL__ float erfcx(const float a) +{ + return erfcxf(a); +} + +__MATH_FUNCTIONS_DECL__ double copysign(const double a, const float b) +{ + return copysign(a, static_cast(b)); +} + +__MATH_FUNCTIONS_DECL__ double copysign(const float a, const double b) +{ + return copysign(static_cast(a), b); +} + +__MATH_FUNCTIONS_DECL__ unsigned int min(const unsigned int a, const unsigned int b) +{ + return umin(a, b); +} + +__MATH_FUNCTIONS_DECL__ unsigned int min(const int a, const unsigned int b) +{ + return umin(static_cast(a), b); +} + +__MATH_FUNCTIONS_DECL__ unsigned int min(const unsigned int a, const int b) +{ + return umin(a, static_cast(b)); +} + +__MATH_FUNCTIONS_DECL__ long int min(const long int a, const long int b) +{ + long int retval; + /* Suppress VS warning: warning C4127: conditional expression is constant */ +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (disable: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + /* long can be of 32-bit type on some systems. */ + if (sizeof(long int) == sizeof(int)) { +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (default: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + retval = static_cast(min(static_cast(a), static_cast(b))); + } else { + retval = static_cast(llmin(static_cast(a), static_cast(b))); + } + return retval; +} + +__MATH_FUNCTIONS_DECL__ unsigned long int min(const unsigned long int a, const unsigned long int b) +{ + unsigned long int retval; +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (disable: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + if (sizeof(unsigned long int) == sizeof(unsigned int)) { +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (default: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + retval = static_cast(umin(static_cast(a), static_cast(b))); + } else { + retval = static_cast(ullmin(static_cast(a), static_cast(b))); + } + return retval; +} + +__MATH_FUNCTIONS_DECL__ unsigned long int min(const long int a, const unsigned long int b) +{ + unsigned long int retval; +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (disable: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + if (sizeof(unsigned long int) == sizeof(unsigned int)) { +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (default: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + retval = static_cast(umin(static_cast(a), static_cast(b))); + } else { + retval = static_cast(ullmin(static_cast(a), static_cast(b))); + } + return retval; +} + +__MATH_FUNCTIONS_DECL__ unsigned long int min(const unsigned long int a, const long int b) +{ + unsigned long int retval; +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (disable: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + if (sizeof(unsigned long int) == sizeof(unsigned int)) { +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (default: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + retval = static_cast(umin(static_cast(a), static_cast(b))); + } else { + retval = static_cast(ullmin(static_cast(a), static_cast(b))); + } + return retval; +} + +__MATH_FUNCTIONS_DECL__ long long int min(const long long int a, const long long int b) +{ + return llmin(a, b); +} + +__MATH_FUNCTIONS_DECL__ unsigned long long int min(const unsigned long long int a, const unsigned long long int b) +{ + return ullmin(a, b); +} + +__MATH_FUNCTIONS_DECL__ unsigned long long int min(const long long int a, const unsigned long long int b) +{ + return ullmin(static_cast(a), b); +} + +__MATH_FUNCTIONS_DECL__ unsigned long long int min(const unsigned long long int a, const long long int b) +{ + return ullmin(a, static_cast(b)); +} + +__MATH_FUNCTIONS_DECL__ float min(const float a, const float b) +{ + return fminf(a, b); +} + +__MATH_FUNCTIONS_DECL__ double min(const double a, const double b) +{ + return fmin(a, b); +} + +__MATH_FUNCTIONS_DECL__ double min(const float a, const double b) +{ + return fmin(static_cast(a), b); +} + +__MATH_FUNCTIONS_DECL__ double min(const double a, const float b) +{ + return fmin(a, static_cast(b)); +} + +__MATH_FUNCTIONS_DECL__ unsigned int max(const unsigned int a, const unsigned int b) +{ + return umax(a, b); +} + +__MATH_FUNCTIONS_DECL__ unsigned int max(const int a, const unsigned int b) +{ + return umax(static_cast(a), b); +} + +__MATH_FUNCTIONS_DECL__ unsigned int max(const unsigned int a, const int b) +{ + return umax(a, static_cast(b)); +} + +__MATH_FUNCTIONS_DECL__ long int max(const long int a, const long int b) +{ + long int retval; + /* long can be of 32-bit type on some systems. */ +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (disable: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + if (sizeof(long int) == sizeof(int)) { +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (default: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + retval = static_cast(max(static_cast(a), static_cast(b))); + } else { + retval = static_cast(llmax(static_cast(a), static_cast(b))); + } + return retval; +} + +__MATH_FUNCTIONS_DECL__ unsigned long int max(const unsigned long int a, const unsigned long int b) +{ + unsigned long int retval; +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (disable: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + if (sizeof(unsigned long int) == sizeof(unsigned int)) { +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (default: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + retval = static_cast(umax(static_cast(a), static_cast(b))); + } else { + retval = static_cast(ullmax(static_cast(a), static_cast(b))); + } + return retval; +} + +__MATH_FUNCTIONS_DECL__ unsigned long int max(const long int a, const unsigned long int b) +{ + unsigned long int retval; +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (disable: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + if (sizeof(unsigned long int) == sizeof(unsigned int)) { +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (default: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + retval = static_cast(umax(static_cast(a), static_cast(b))); + } else { + retval = static_cast(ullmax(static_cast(a), static_cast(b))); + } + return retval; +} + +__MATH_FUNCTIONS_DECL__ unsigned long int max(const unsigned long int a, const long int b) +{ + unsigned long int retval; +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (disable: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + if (sizeof(unsigned long int) == sizeof(unsigned int)) { +#if defined(_MSC_VER) && !defined(__CUDA_ARCH__) +#pragma warning (default: 4127) +#endif /* _MSC_VER && !defined(__CUDA_ARCH__) */ + retval = static_cast(umax(static_cast(a), static_cast(b))); + } else { + retval = static_cast(ullmax(static_cast(a), static_cast(b))); + } + return retval; +} + +__MATH_FUNCTIONS_DECL__ long long int max(const long long int a, const long long int b) +{ + return llmax(a, b); +} + +__MATH_FUNCTIONS_DECL__ unsigned long long int max(const unsigned long long int a, const unsigned long long int b) +{ + return ullmax(a, b); +} + +__MATH_FUNCTIONS_DECL__ unsigned long long int max(const long long int a, const unsigned long long int b) +{ + return ullmax(static_cast(a), b); +} + +__MATH_FUNCTIONS_DECL__ unsigned long long int max(const unsigned long long int a, const long long int b) +{ + return ullmax(a, static_cast(b)); +} + +__MATH_FUNCTIONS_DECL__ float max(const float a, const float b) +{ + return fmaxf(a, b); +} + +__MATH_FUNCTIONS_DECL__ double max(const double a, const double b) +{ + return fmax(a, b); +} + +__MATH_FUNCTIONS_DECL__ double max(const float a, const double b) +{ + return fmax(static_cast(a), b); +} + +__MATH_FUNCTIONS_DECL__ double max(const double a, const float b) +{ + return fmax(a, static_cast(b)); +} + + +#if !defined(__CUDA_ARCH__) +#if defined(_WIN32) +#define __HELPER_FUNC_LINKAGE static inline __host__ __device__ +#pragma warning(disable : 4211) +#else /* !defined(_WIN32) */ +#define __HELPER_FUNC_LINKAGE inline __host__ __device__ +#endif /* defined(_WIN32) */ + +__HELPER_FUNC_LINKAGE int min(const int a, const int b) +{ + return (a < b) ? a : b; +} + +__HELPER_FUNC_LINKAGE unsigned int umin(const unsigned int a, const unsigned int b) +{ + return (a < b) ? a : b; +} + +__HELPER_FUNC_LINKAGE long long int llmin(const long long int a, const long long int b) +{ + return (a < b) ? a : b; +} + +__HELPER_FUNC_LINKAGE unsigned long long int ullmin(const unsigned long long int a, + const unsigned long long int b) +{ + return (a < b) ? a : b; +} + +__HELPER_FUNC_LINKAGE int max(const int a, const int b) +{ + return (a > b) ? a : b; +} + +__HELPER_FUNC_LINKAGE unsigned int umax(const unsigned int a, const unsigned int b) +{ + return (a > b) ? a : b; +} + +__HELPER_FUNC_LINKAGE long long int llmax(const long long int a, const long long int b) +{ + return (a > b) ? a : b; +} + +__HELPER_FUNC_LINKAGE unsigned long long int ullmax(const unsigned long long int a, + const unsigned long long int b) +{ + return (a > b) ? a : b; +} + +#if defined(_WIN32) +#pragma warning(default: 4211) +#endif /* defined(_WIN32) */ + +#undef __HELPER_FUNC_LINKAGE + +#endif /* !defined(__CUDA_ARCH__) */ + +#undef __MATH_FUNCTIONS_DECL__ +#undef __MATH_FUNCTIONS_DEVICE_DECL__ + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#endif /* __cplusplus && __CUDACC__ */ +#if !defined(__CUDACC__) + +#include "host_defines.h" +#include "math_constants.h" + +#define __cuda_INT_MAX \ + ((int)((unsigned int)-1 >> 1)) + +/******************************************************************************* +* * +* ONLY FOR HOST CODE! NOT FOR DEVICE EXECUTION * +* * +*******************************************************************************/ + +#include + +#if defined(_WIN32) + +#pragma warning(disable : 4211) + +#endif /* _WIN32 */ + +#if defined(_WIN32) || defined(__APPLE__) || defined (__ANDROID__) || defined(__QNX__) + +__func__(int __isnan(const double a)) +{ + unsigned long long int l; + memcpy(&l, &a, sizeof(double)); + return (l << 1ULL) > 0xffe0000000000000ULL; +} + +#endif /* _WIN32 || __APPLE__ || __ANDROID__ || __QNX__ */ + +#if defined(_WIN32) || defined(__APPLE__) || defined(__QNX__) + +/******************************************************************************* +* * +* HOST IMPLEMENTATION FOR DOUBLE ROUTINES FOR WINDOWS & APPLE PLATFORMS * +* * +*******************************************************************************/ + +__func__(double exp10(const double a)) +{ + return pow(10.0, a); +} + +__func__(float exp10f(const float a)) +{ + return static_cast(exp10(static_cast(a))); +} + +__func__(void sincos(const double a, double *sptr, double *cptr)) +{ + *sptr = sin(a); + *cptr = cos(a); +} + +__func__(void sincosf(const float a, float *sptr, float *cptr)) +{ + double s, c; + + sincos(static_cast(a), &s, &c); + *sptr = static_cast(s); + *cptr = static_cast(c); +} + +__func__(int __isinf(const double a)) +{ + unsigned long long int l; + memcpy(&l, &a, sizeof(double)); + return (l << 1ULL) == 0xffe0000000000000ULL; +} + +#endif /* _WIN32 || __APPLE__ */ + +#if defined(_WIN32) || defined (__ANDROID__) + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +__func__(double log2(const double a)) +{ + return log(a) * 1.44269504088896340; +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#endif /* _WIN32 || __ANDROID__ */ + +#if defined(_WIN32) + +/******************************************************************************* +* * +* HOST IMPLEMENTATION FOR DOUBLE ROUTINES FOR WINDOWS PLATFORM * +* * +*******************************************************************************/ + +__func__(int __signbit(double a)) +{ + signed long long int l; + memcpy(&l, &a, sizeof(double)); + return l < 0LL; +} + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +__func__(double copysign(double a, double b)) +{ + unsigned long long int la, lb; + memcpy(&la, &a, sizeof(double)); + memcpy(&lb, &b, sizeof(double)); + la = (la & 0x7fffffffffffffffULL) | (lb & 0x8000000000000000ULL); + memcpy(&a, &la, sizeof(double)); + return a; +} +#endif /* MSC_VER < 1800 */ + +__func__(int __finite(double a)) +{ + unsigned long long int l; + memcpy(&l, &a, sizeof(double)); + return (l << 1ULL) < 0xffe0000000000000ULL; +} + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +__func__(double fmax(double a, double b)) +{ + if (__isnan(a) && __isnan(b)) return a + b; + if (__isnan(a)) return b; + if (__isnan(b)) return a; + if ((a == 0.0) && (b == 0.0) && __signbit(b)) return a; + return a > b ? a : b; +} + +__func__(double fmin(double a, double b)) +{ + if (__isnan(a) && __isnan(b)) return a + b; + if (__isnan(a)) return b; + if (__isnan(b)) return a; + if ((a == 0.0) && (b == 0.0) && __signbit(a)) return a; + return a < b ? a : b; +} + +__func__(double trunc(double a)) +{ + return a < 0.0 ? ceil(a) : floor(a); +} + +__func__(double round(double a)) +{ + double fa = fabs(a); + + if (fa > CUDART_TWO_TO_52) { + return a; + } else { + double u = floor(fa + 0.5); + if (fa < 0.5) u = 0; + u = copysign (u, a); + return u; + } +} + +__func__(long int lround(double a)) +{ + return static_cast(round(a)); +} + +__func__(long long int llround(double a)) +{ + return static_cast(round(a)); +} + +__func__(double rint(double a)) +{ + double fa = fabs(a); + double u = CUDART_TWO_TO_52 + fa; + if (fa >= CUDART_TWO_TO_52) { + u = a; + } else { + u = u - CUDART_TWO_TO_52; + u = copysign (u, a); + } + return u; +} + +__func__(double nearbyint(double a)) +{ + return rint(a); +} + +__func__(long int lrint(double a)) +{ + return static_cast(rint(a)); +} + +__func__(long long int llrint(double a)) +{ + return static_cast(rint(a)); +} + +__func__(double fdim(double a, double b)) +{ + if (a > b) { + return (a - b); + } else if (a <= b) { + return 0.0; + } else if (__isnan(a)) { + return a; + } else { + return b; + } +} + +__func__(double scalbn(double a, int b)) +{ + return ldexp(a, b); +} + +__func__(double scalbln(double a, long int b)) +{ + int t; + + if (b > 2147483647L) { + t = 2147483647; + } else if (b < (-2147483647 - 1)) { + t = (-2147483647 - 1); + } else { + t = static_cast(b); + } + return scalbn(a, t); +} + +__func__(double exp2(double a)) +{ + return pow(2.0, a); +} + +/* + * The following is based on: David Goldberg, "What every computer scientist + * should know about floating-point arithmetic", ACM Computing Surveys, Volume + * 23, Issue 1, March 1991. + */ +__func__(double log1p(double a)) +{ + volatile double u, m; + + u = 1.0 + a; + if (u == 1.0) { + /* a very close to zero */ + u = a; + } else { + m = u - 1.0; + u = log(u); + if (a < 1.0) { + /* a somewhat close to zero */ + u = a * u; + u = u / m; + } + } + return u; +} + +/* + * This code based on: http://www.cs.berkeley.edu/~wkahan/Math128/Sumnfp.pdf + */ +__func__(double expm1(double a)) +{ + volatile double u, m; + + u = exp(a); + m = u - 1.0; + if (m == 0.0) { + /* a very close zero */ + m = a; + } + else if (fabs(a) < 1.0) { + /* a somewhat close zero */ + u = log(u); + m = m * a; + m = m / u; + } + return m; +} + +__func__(double cbrt(double a)) +{ + double s, t; + + if (a == 0.0 || __isinf(a)) { + return a; + } + s = fabs(a); + t = exp2(CUDART_THIRD * log2(s)); /* initial approximation */ + t = t - (t - (s / (t * t))) * CUDART_THIRD; /* refine approximation */ + t = copysign(t, a); + return t; +} + +__func__(double acosh(double a)) +{ + double s, t; + + t = a - 1.0; + if (t == a) { + return log(2.0) + log(a); + } else { + s = a + 1.0; + t = t + sqrt(s * t); + return log1p(t); + } +} + +__func__(double asinh(double a)) +{ + double fa, oofa, t; + + fa = fabs(a); + if (fa > 1e18) { + t = log(2.0) + log(fa); + } else { + oofa = 1.0 / fa; + t = fa + fa / (oofa + sqrt(1.0 + oofa * oofa)); + t = log1p(t); + } + t = copysign(t, a); + return t; +} + +__func__(double atanh(double a)) +{ + double fa, t; + + if (__isnan(a)) { + return a + a; + } + fa = fabs(a); + t = (2.0 * fa) / (1.0 - fa); + t = 0.5 * log1p(t); + if (__isnan(t) || !__signbit(a)) { + return t; + } + return -t; +} + +__func__(int ilogb(double a)) +{ + unsigned long long int i; + int expo = -1022; + + if (__isnan(a)) return -__cuda_INT_MAX-1; + if (__isinf(a)) return __cuda_INT_MAX; + memcpy(&i, &a, sizeof(double)); + i = i & 0x7fffffffffffffffULL; + if (i == 0) return -__cuda_INT_MAX-1; + if (i >= 0x0010000000000000ULL) { + return (int)(((i >> 52ULL) & 0x7ffU) - 1023); + } + while (i < 0x0010000000000000ULL) { + expo--; + i <<= 1; + } + return expo; +} + +__func__(double logb(double a)) +{ + unsigned long long int i; + int expo = -1022; + + if (__isnan(a)) return a + a; + if (__isinf(a)) return fabs(a); + memcpy(&i, &a, sizeof(double)); + i = i & 0x7fffffffffffffffULL; + if (i == 0) return -1.0/fabs(a); + if (i >= 0x0010000000000000ULL) { + return (double)((int)((i >> 52ULL) & 0x7ffU) - 1023); + } + while (i < 0x0010000000000000ULL) { + expo--; + i <<= 1; + } + return static_cast(expo); +} + +__func__(double remquo(double a, double b, int *quo)) +{ + unsigned long long int aa, bb; + int rem1 = 1; /* do FPREM1, a.k.a IEEE remainder */ + int expo_a; + int expo_b; + unsigned long long mant_a; + unsigned long long mant_b; + unsigned long long mant_c; + unsigned long long temp; + int sign_a; + int sign_b; + int sign_c; + int expo_c; + int expodiff; + int quot = 0; /* initialize quotient */ + int l; + int iter; + + memcpy(&aa, &a, sizeof(double)); + mant_a = (aa << 11ULL) | 0x8000000000000000ULL; + expo_a = (int)((aa >> 52ULL) & 0x7ffU) - 1023; + sign_a = (int)(aa >> 63ULL); + + memcpy(&bb, &b, sizeof(double)); + mant_b = (bb << 11ULL) | 0x8000000000000000ULL; + expo_b = (int)((bb >> 52ULL) & 0x7ffU) - 1023; + sign_b = (int)(bb >> 63ULL); + + sign_c = sign_a; /* remainder has sign of dividend */ + expo_c = expo_a; /* default */ + + /* handled NaNs and infinities */ + if (__isnan(a) || __isnan(b)) { + *quo = quot; + return a + b; + } + if (__isinf(a) || (b == 0.0)) { + *quo = quot; + aa = 0xfff8000000000000ULL; + memcpy(&a, &aa, sizeof(double)); + return a; + } + if ((a == 0.0) || (__isinf(b))) { + *quo = quot; + return a; + } + /* normalize denormals */ + if (expo_a < -1022) { + mant_a = mant_a + mant_a; + while (mant_a < 0x8000000000000000ULL) { + mant_a = mant_a + mant_a; + expo_a--; + } + } + if (expo_b < -1022) { + mant_b = mant_b + mant_b; + while (mant_b < 0x8000000000000000ULL) { + mant_b = mant_b + mant_b; + expo_b--; + } + } + expodiff = expo_a - expo_b; + /* clamp iterations if exponent difference negative */ + if (expodiff < 0) { + iter = -1; + } else { + iter = expodiff; + } + /* Shift dividend and divisor right by one bit to prevent overflow + during the division algorithm. + */ + mant_a = mant_a >> 1ULL; + mant_b = mant_b >> 1ULL; + expo_c = expo_a - iter; /* default exponent of result */ + + /* Use binary longhand division (restoring) */ + for (l = 0; l < (iter + 1); l++) { + mant_a = mant_a - mant_b; + if (mant_a & 0x8000000000000000ULL) { + mant_a = mant_a + mant_b; + quot = quot + quot; + } else { + quot = quot + quot + 1; + } + mant_a = mant_a + mant_a; + } + + /* Save current remainder */ + mant_c = mant_a; + /* If remainder's mantissa is all zeroes, final result is zero. */ + if (mant_c == 0) { + quot = quot & 7; + *quo = (sign_a ^ sign_b) ? -quot : quot; + aa = static_cast(sign_c) << 63ULL; + memcpy(&a, &aa, sizeof(double)); + return a; + } + /* Normalize result */ + while (!(mant_c & 0x8000000000000000ULL)) { + mant_c = mant_c + mant_c; + expo_c--; + } + /* For IEEE remainder (quotient rounded to nearest-even we might need to + do a final subtraction of the divisor from the remainder. + */ + if (rem1 && ((expodiff+1) >= 0)) { + temp = mant_a - mant_b; + /* round quotient to nearest even */ + if (((temp != 0ULL) && (!(temp & 0x8000000000000000ULL))) || + ((temp == 0ULL) && (quot & 1))) { + mant_a = mant_a >> 1ULL; + quot++; + /* Since the divisor is greater than the remainder, the result will + have opposite sign of the dividend. To avoid a negative mantissa + when subtracting the divisor from remainder, reverse subtraction + */ + sign_c = 1 ^ sign_c; + expo_c = expo_a - iter + 1; + mant_c = mant_b - mant_a; + /* normalize result */ + while (!(mant_c & 0x8000000000000000ULL)) { + mant_c = mant_c + mant_c; + expo_c--; + } + } + } + /* package up result */ + if (expo_c >= -1022) { /* normal */ + mant_c = ((mant_c >> 11ULL) + + (((static_cast(sign_c)) << 63ULL) + + (((unsigned long long)(expo_c + 1022)) << 52ULL))); + } else { /* denormal */ + mant_c = (((static_cast(sign_c)) << 63ULL) + + (mant_c >> (unsigned long long)(11 - expo_c - 1022))); + } + quot = quot & 7; /* mask quotient down to least significant three bits */ + *quo = (sign_a ^ sign_b) ? -quot : quot; + memcpy(&a, &mant_c, sizeof(double)); + return a; +} + +__func__(double remainder(double a, double b)) +{ + int quo; + return remquo (a, b, &quo); +} + +__func__(double fma (double a, double b, double c)) +{ + struct { + unsigned int lo; + unsigned int hi; + } xx, yy, zz, ww; + double d; + unsigned int s, t, u, prod0, prod1, prod2, prod3, expo_x, expo_y, expo_z; + + memcpy(&xx, &a, sizeof(double)); + memcpy(&yy, &b, sizeof(double)); + memcpy(&zz, &c, sizeof(double)); + + expo_z = 0x7FFU; + t = xx.hi >> 20; + expo_x = expo_z & t; + expo_x = expo_x - 1; /* expo(x) - 1 */ + t = yy.hi >> 20; + expo_y = expo_z & t; + expo_y = expo_y - 1; /* expo(y) - 1 */ + t = zz.hi >> 20; + expo_z = expo_z & t; + expo_z = expo_z - 1; /* expo(z) - 1 */ + + if (!((expo_x <= 0x7FDU) && + (expo_y <= 0x7FDU) && + (expo_z <= 0x7FDU))) { + + /* fma (nan, y, z) --> nan + fma (x, nan, z) --> nan + fma (x, y, nan) --> nan + */ + if (((yy.hi << 1) | (yy.lo != 0)) > 0xffe00000U) { + yy.hi |= 0x00080000U; + memcpy(&d, &yy, sizeof(double)); + return d; + } + if (((zz.hi << 1) | (zz.lo != 0)) > 0xffe00000U) { + zz.hi |= 0x00080000U; + memcpy(&d, &zz, sizeof(double)); + return d; + } + if (((xx.hi << 1) | (xx.lo != 0)) > 0xffe00000U) { + xx.hi |= 0x00080000U; + memcpy(&d, &xx, sizeof(double)); + return d; + } + + /* fma (0, inf, z) --> INDEFINITE + fma (inf, 0, z) --> INDEFINITE + fma (-inf,+y,+inf) --> INDEFINITE + fma (+x,-inf,+inf) --> INDEFINITE + fma (+inf,-y,+inf) --> INDEFINITE + fma (-x,+inf,+inf) --> INDEFINITE + fma (-inf,-y,-inf) --> INDEFINITE + fma (-x,-inf,-inf) --> INDEFINITE + fma (+inf,+y,-inf) --> INDEFINITE + fma (+x,+inf,-inf) --> INDEFINITE + */ + if (((((xx.hi << 1) | xx.lo) == 0) && + (((yy.hi << 1) | (yy.lo != 0)) == 0xffe00000U)) || + ((((yy.hi << 1) | yy.lo) == 0) && + (((xx.hi << 1) | (xx.lo != 0)) == 0xffe00000U))) { + xx.hi = 0xfff80000U; + xx.lo = 0x00000000U; + memcpy(&d, &xx, sizeof(double)); + return d; + } + if (((zz.hi << 1) | (zz.lo != 0)) == 0xffe00000U) { + if ((((yy.hi << 1) | (yy.lo != 0)) == 0xffe00000U) || + (((xx.hi << 1) | (xx.lo != 0)) == 0xffe00000U)) { + if ((int)(xx.hi ^ yy.hi ^ zz.hi) < 0) { + xx.hi = 0xfff80000U; + xx.lo = 0x00000000U; + memcpy(&d, &xx, sizeof(double)); + return d; + } + } + } + /* fma (inf, y, z) --> inf + fma (x, inf, z) --> inf + fma (x, y, inf) --> inf + */ + if (((xx.hi << 1) | (xx.lo != 0)) == 0xffe00000U) { + xx.hi = xx.hi ^ (yy.hi & 0x80000000U); + memcpy(&d, &xx, sizeof(double)); + return d; + } + if (((yy.hi << 1) | (yy.lo != 0)) == 0xffe00000U) { + yy.hi = yy.hi ^ (xx.hi & 0x80000000U); + memcpy(&d, &yy, sizeof(double)); + return d; + } + if (((zz.hi << 1) | (zz.lo != 0)) == 0xffe00000U) { + memcpy(&d, &zz, sizeof(double)); + return d; + } + /* fma (+0, -y, -0) --> -0 + fma (-0, +y, -0) --> -0 + fma (+x, -0, -0) --> -0 + fma (-x, +0, -0) --> -0 + */ + if ((zz.hi == 0x80000000U) && (zz.lo == 0)) { + if ((((xx.hi << 1) | xx.lo) == 0) || + (((yy.hi << 1) | yy.lo) == 0)) { + if ((int)(xx.hi ^ yy.hi) < 0) { + memcpy(&d, &zz, sizeof(double)); + return d; + } + } + } + /* fma (0, y, 0) --> +0 (-0 if round down and signs of addend differ) + fma (x, 0, 0) --> +0 (-0 if round down and signs of addend differ) + */ + if ((((zz.hi << 1) | zz.lo) == 0) && + ((((xx.hi << 1) | xx.lo) == 0) || + (((yy.hi << 1) | yy.lo) == 0))) { + zz.hi &= 0x7fffffffU; + memcpy(&d, &zz, sizeof(double)); + return d; + } + + /* fma (0, y, z) --> z + fma (x, 0, z) --> z + */ + if ((((xx.hi << 1) | xx.lo) == 0) || + (((yy.hi << 1) | yy.lo) == 0)) { + memcpy(&d, &zz, sizeof(double)); + return d; + } + + if (expo_x == 0xffffffffU) { + expo_x++; + t = xx.hi & 0x80000000U; + s = xx.lo >> 21; + xx.lo = xx.lo << 11; + xx.hi = xx.hi << 11; + xx.hi = xx.hi | s; + if (!xx.hi) { + xx.hi = xx.lo; + xx.lo = 0; + expo_x -= 32; + } + while (static_cast(xx.hi) > 0) { + s = xx.lo >> 31; + xx.lo = xx.lo + xx.lo; + xx.hi = xx.hi + xx.hi; + xx.hi = xx.hi | s; + expo_x--; + } + xx.lo = (xx.lo >> 11); + xx.lo |= (xx.hi << 21); + xx.hi = (xx.hi >> 11) | t; + } + if (expo_y == 0xffffffffU) { + expo_y++; + t = yy.hi & 0x80000000U; + s = yy.lo >> 21; + yy.lo = yy.lo << 11; + yy.hi = yy.hi << 11; + yy.hi = yy.hi | s; + if (!yy.hi) { + yy.hi = yy.lo; + yy.lo = 0; + expo_y -= 32; + } + while (static_cast(yy.hi) > 0) { + s = yy.lo >> 31; + yy.lo = yy.lo + yy.lo; + yy.hi = yy.hi + yy.hi; + yy.hi = yy.hi | s; + expo_y--; + } + yy.lo = (yy.lo >> 11); + yy.lo |= (yy.hi << 21); + yy.hi = (yy.hi >> 11) | t; + } + if (expo_z == 0xffffffffU) { + expo_z++; + t = zz.hi & 0x80000000U; + s = zz.lo >> 21; + zz.lo = zz.lo << 11; + zz.hi = zz.hi << 11; + zz.hi = zz.hi | s; + if (!zz.hi) { + zz.hi = zz.lo; + zz.lo = 0; + expo_z -= 32; + } + while (static_cast(zz.hi) > 0) { + s = zz.lo >> 31; + zz.lo = zz.lo + zz.lo; + zz.hi = zz.hi + zz.hi; + zz.hi = zz.hi | s; + expo_z--; + } + zz.lo = (zz.lo >> 11); + zz.lo |= (zz.hi << 21); + zz.hi = (zz.hi >> 11) | t; + } + } + + expo_x = expo_x + expo_y; + expo_y = xx.hi ^ yy.hi; + t = xx.lo >> 21; + xx.lo = xx.lo << 11; + xx.hi = xx.hi << 11; + xx.hi = xx.hi | t; + yy.hi = yy.hi & 0x000fffffU; + xx.hi = xx.hi | 0x80000000U; /* set mantissa hidden bit */ + yy.hi = yy.hi | 0x00100000U; /* set mantissa hidden bit */ + + prod0 = xx.lo * yy.lo; + prod1 =(unsigned)((static_cast(xx.lo)*static_cast(yy.lo))>>32ULL); + prod2 = xx.hi * yy.lo; + prod3 = xx.lo * yy.hi; + prod1 += prod2; + t = (unsigned)(prod1 < prod2); + prod1 += prod3; + t += prod1 < prod3; + prod2 =(unsigned)((static_cast(xx.hi)*static_cast(yy.lo))>>32ULL); + prod3 =(unsigned)((static_cast(xx.lo)*static_cast(yy.hi))>>32ULL); + prod2 += prod3; + s = (unsigned)(prod2 < prod3); + prod3 = xx.hi * yy.hi; + prod2 += prod3; + s += prod2 < prod3; + prod2 += t; + s += prod2 < t; + prod3 =(unsigned)((static_cast(xx.hi)*static_cast(yy.hi))>>32ULL); + prod3 = prod3 + s; + + yy.lo = prod0; /* mantissa */ + yy.hi = prod1; /* mantissa */ + xx.lo = prod2; /* mantissa */ + xx.hi = prod3; /* mantissa */ + expo_x = expo_x - (1023 - 2); /* expo-1 */ + expo_y = expo_y & 0x80000000U; /* sign */ + + if (xx.hi < 0x00100000U) { + s = xx.lo >> 31; + s = (xx.hi << 1) + s; + xx.hi = s; + s = yy.hi >> 31; + s = (xx.lo << 1) + s; + xx.lo = s; + s = yy.lo >> 31; + s = (yy.hi << 1) + s; + yy.hi = s; + s = yy.lo << 1; + yy.lo = s; + expo_x--; + } + + t = 0; + if (((zz.hi << 1) | zz.lo) != 0) { /* z is not zero */ + + s = zz.hi & 0x80000000U; + + zz.hi &= 0x000fffffU; + zz.hi |= 0x00100000U; + ww.hi = 0; + ww.lo = 0; + + /* compare and swap. put augend into xx:yy */ + if (static_cast(expo_z) > static_cast(expo_x)) { + t = expo_z; + expo_z = expo_x; + expo_x = t; + t = zz.hi; + zz.hi = xx.hi; + xx.hi = t; + t = zz.lo; + zz.lo = xx.lo; + xx.lo = t; + t = ww.hi; + ww.hi = yy.hi; + yy.hi = t; + t = ww.lo; + ww.lo = yy.lo; + yy.lo = t; + t = expo_y; + expo_y = s; + s = t; + } + + /* augend_sign = expo_y, augend_mant = xx:yy, augend_expo = expo_x */ + /* addend_sign = s, addend_mant = zz:ww, addend_expo = expo_z */ + expo_z = expo_x - expo_z; + u = expo_y ^ s; + if (expo_z <= 107) { + /* denormalize addend */ + t = 0; + while (expo_z >= 32) { + t = ww.lo | (t != 0); + ww.lo = ww.hi; + ww.hi = zz.lo; + zz.lo = zz.hi; + zz.hi = 0; + expo_z -= 32; + } + if (expo_z) { + t = (t >> expo_z) | (ww.lo << (32 - expo_z)) | + ((t << (32 - expo_z)) != 0); + ww.lo = (ww.lo >> expo_z) | (ww.hi << (32 - expo_z)); + ww.hi = (ww.hi >> expo_z) | (zz.lo << (32 - expo_z)); + zz.lo = (zz.lo >> expo_z) | (zz.hi << (32 - expo_z)); + zz.hi = (zz.hi >> expo_z); + } + } else { + t = 1; + ww.lo = 0; + ww.hi = 0; + zz.lo = 0; + zz.hi = 0; + } + if (static_cast(u) < 0) { + /* signs differ, effective subtraction */ + t = (unsigned)(-static_cast(t)); + s = (unsigned)(t != 0); + u = yy.lo - s; + s = (unsigned)(u > yy.lo); + yy.lo = u - ww.lo; + s += yy.lo > u; + u = yy.hi - s; + s = (unsigned)(u > yy.hi); + yy.hi = u - ww.hi; + s += yy.hi > u; + u = xx.lo - s; + s = (unsigned)(u > xx.lo); + xx.lo = u - zz.lo; + s += xx.lo > u; + xx.hi = (xx.hi - zz.hi) - s; + if (!(xx.hi | xx.lo | yy.hi | yy.lo | t)) { + /* complete cancelation, return 0 */ + memcpy(&d, &xx, sizeof(double)); + return d; + } + if (static_cast(xx.hi) < 0) { + /* Oops, augend had smaller mantissa. Negate mantissa and flip + sign of result + */ + t = ~t; + yy.lo = ~yy.lo; + yy.hi = ~yy.hi; + xx.lo = ~xx.lo; + xx.hi = ~xx.hi; + if (++t == 0) { + if (++yy.lo == 0) { + if (++yy.hi == 0) { + if (++xx.lo == 0) { + ++xx.hi; + } + } + } + } + expo_y ^= 0x80000000U; + } + + /* normalize mantissa, if necessary */ + while (!(xx.hi & 0x00100000U)) { + xx.hi = (xx.hi << 1) | (xx.lo >> 31); + xx.lo = (xx.lo << 1) | (yy.hi >> 31); + yy.hi = (yy.hi << 1) | (yy.lo >> 31); + yy.lo = (yy.lo << 1); + expo_x--; + } + } else { + /* signs are the same, effective addition */ + yy.lo = yy.lo + ww.lo; + s = (unsigned)(yy.lo < ww.lo); + yy.hi = yy.hi + s; + u = (unsigned)(yy.hi < s); + yy.hi = yy.hi + ww.hi; + u += yy.hi < ww.hi; + xx.lo = xx.lo + u; + s = (unsigned)(xx.lo < u); + xx.lo = xx.lo + zz.lo; + s += xx.lo < zz.lo; + xx.hi = xx.hi + zz.hi + s; + if (xx.hi & 0x00200000U) { + t = t | (yy.lo << 31); + yy.lo = (yy.lo >> 1) | (yy.hi << 31); + yy.hi = (yy.hi >> 1) | (xx.lo << 31); + xx.lo = (xx.lo >> 1) | (xx.hi << 31); + xx.hi = ((xx.hi & 0x80000000U) | (xx.hi >> 1)) & ~0x40000000U; + expo_x++; + } + } + } + t = yy.lo | (t != 0); + t = yy.hi | (t != 0); + + xx.hi |= expo_y; /* or in sign bit */ + if (expo_x <= 0x7FDU) { + /* normal */ + xx.hi = xx.hi & ~0x00100000U; /* lop off integer bit */ + s = xx.lo & 1; /* mantissa lsb */ + u = xx.lo; + xx.lo += (t == 0x80000000U) ? s : (t >> 31); + xx.hi += (u > xx.lo); + xx.hi += ((expo_x + 1) << 20); + memcpy(&d, &xx, sizeof(double)); + return d; + } else if (static_cast(expo_x) >= 2046) { + /* overflow */ + xx.hi = (xx.hi & 0x80000000U) | 0x7ff00000U; + xx.lo = 0; + memcpy(&d, &xx, sizeof(double)); + return d; + } + /* subnormal */ + expo_x = (unsigned)(-static_cast(expo_x)); + if (expo_x > 54) { + xx.hi = xx.hi & 0x80000000U; + xx.lo = 0; + memcpy(&d, &xx, sizeof(double)); + return d; + } + yy.hi = xx.hi & 0x80000000U; /* save sign bit */ + xx.hi = xx.hi & ~0xffe00000U; + if (expo_x >= 32) { + t = xx.lo | (t != 0); + xx.lo = xx.hi; + xx.hi = 0; + expo_x -= 32; + } + if (expo_x) { + t = (t >> expo_x) | (xx.lo << (32 - expo_x)) | (t != 0); + xx.lo = (xx.lo >> expo_x) | (xx.hi << (32 - expo_x)); + xx.hi = (xx.hi >> expo_x); + } + expo_x = xx.lo & 1; + u = xx.lo; + xx.lo += (t == 0x80000000U) ? expo_x : (t >> 31); + xx.hi += (u > xx.lo); + xx.hi |= yy.hi; + memcpy(&d, &xx, sizeof(double)); + return d; +} + +__func__(double nextafter(double a, double b)) +{ + unsigned long long int ia; + unsigned long long int ib; + memcpy(&ia, &a, sizeof(double)); + memcpy(&ib, &b, sizeof(double)); + if (__isnan(a) || __isnan(b)) return a + b; /* NaN */ + if (((ia | ib) << 1ULL) == 0ULL) return b; + if (a == 0.0) { + return copysign (4.9406564584124654e-324, b); /* crossover */ + } + if ((a < b) && (a < 0.0)) ia--; + if ((a < b) && (a > 0.0)) ia++; + if ((a > b) && (a < 0.0)) ia++; + if ((a > b) && (a > 0.0)) ia--; + memcpy(&a, &ia, sizeof(double)); + return a; +} + +__func__(double erf(double a)) +{ + double t, r, q; + + t = fabs(a); + if (t >= 1.0) { + r = -1.28836351230756500E-019; + r = r * t + 1.30597472161093370E-017; + r = r * t - 6.33924401259620500E-016; + r = r * t + 1.96231865908940140E-014; + r = r * t - 4.35272243559990750E-013; + r = r * t + 7.37083927929352150E-012; + r = r * t - 9.91402142550461630E-011; + r = r * t + 1.08817017167760820E-009; + r = r * t - 9.93918713097634620E-009; + r = r * t + 7.66739923255145500E-008; + r = r * t - 5.05440278302806720E-007; + r = r * t + 2.87474157099000620E-006; + r = r * t - 1.42246725399722510E-005; + r = r * t + 6.16994555079419460E-005; + r = r * t - 2.36305221938908790E-004; + r = r * t + 8.05032844055371070E-004; + r = r * t - 2.45833366629108140E-003; + r = r * t + 6.78340988296706120E-003; + r = r * t - 1.70509103597554640E-002; + r = r * t + 3.93322852515666300E-002; + r = r * t - 8.37271292613764040E-002; + r = r * t + 1.64870423707623280E-001; + r = r * t - 2.99729521787681470E-001; + r = r * t + 4.99394435612628580E-001; + r = r * t - 7.52014596480123030E-001; + r = r * t + 9.99933138314926250E-001; + r = r * t - 1.12836725321102670E+000; + r = r * t + 9.99998988715182450E-001; + q = exp (-t * t); + r = 1.0 - r * q; + if (t >= 6.5) { + r = 1.0; + } + a = copysign (r, a); + } else { + q = a * a; + r = -7.77946848895991420E-010; + r = r * q + 1.37109803980285950E-008; + r = r * q - 1.62063137584932240E-007; + r = r * q + 1.64471315712790040E-006; + r = r * q - 1.49247123020098620E-005; + r = r * q + 1.20552935769006260E-004; + r = r * q - 8.54832592931448980E-004; + r = r * q + 5.22397760611847340E-003; + r = r * q - 2.68661706431114690E-002; + r = r * q + 1.12837916709441850E-001; + r = r * q - 3.76126389031835210E-001; + r = r * q + 1.12837916709551260E+000; + a = r * a; + } + return a; +} + +__func__(double erfc(double a)) +{ + double p, q, h, l; + + if (a < 0.75) { + return 1.0 - erf(a); + } + if (a > 27.3) { + return 0.0; + } + if (a < 5.0) { + double t; + t = 1.0 / a; + p = 1.9759923722227928E-008; + p = p * t - 1.0000002670474897E+000; + p = p * t - 7.4935303236347828E-001; + p = p * t - 1.5648136328071860E-001; + p = p * t + 1.2871196242447239E-001; + p = p * t + 1.1126459974811195E-001; + p = p * t + 4.0678642255914332E-002; + p = p * t + 7.9915414156678296E-003; + p = p * t + 7.1458332107840234E-004; + q = t + 2.7493547525030619E+000; + q = q * t + 3.3984254815725423E+000; + q = q * t + 2.4635304979947761E+000; + q = q * t + 1.1405284734691286E+000; + q = q * t + 3.4130157606195649E-001; + q = q * t + 6.2250967676044953E-002; + q = q * t + 5.5661370941268700E-003; + q = q * t + 1.0575248365468671E-009; + p = p / q; + p = p * t; + h = ((int)(a * 16.0)) * 0.0625; + l = (a - h) * (a + h); + q = exp(-h * h) * exp(-l); + q = q * 0.5; + p = p * q + q; + p = p * t; + } else { + double ooa, ooasq; + + ooa = 1.0 / a; + ooasq = ooa * ooa; + p = -4.0025406686930527E+005; + p = p * ooasq + 1.4420582543942123E+005; + p = p * ooasq - 2.7664185780951841E+004; + p = p * ooasq + 4.1144611644767283E+003; + p = p * ooasq - 5.8706000519209351E+002; + p = p * ooasq + 9.1490086446323375E+001; + p = p * ooasq - 1.6659491387740221E+001; + p = p * ooasq + 3.7024804085481784E+000; + p = p * ooasq - 1.0578553994424316E+000; + p = p * ooasq + 4.2314218745087778E-001; + p = p * ooasq - 2.8209479177354962E-001; + p = p * ooasq + 5.6418958354775606E-001; + h = a * a; + h = ((int)(a * 16.0)) * 0.0625; + l = (a - h) * (a + h); + q = exp(-h * h) * exp(-l); + p = p * ooa; + p = p * q; + } + return p; +} + +__func__(double lgamma(double a)) +{ + double s; + double t; + double i; + double fa; + double sum; + long long int quot; + if (__isnan(a) || __isinf(a)) { + return a * a; + } + fa = fabs(a); + if (fa >= 3.0) { + if (fa >= 8.0) { + /* Stirling approximation; coefficients from Hart et al, "Computer + * Approximations", Wiley 1968. Approximation 5404. + */ + s = 1.0 / fa; + t = s * s; + sum = -0.1633436431e-2; + sum = sum * t + 0.83645878922e-3; + sum = sum * t - 0.5951896861197e-3; + sum = sum * t + 0.793650576493454e-3; + sum = sum * t - 0.277777777735865004e-2; + sum = sum * t + 0.833333333333331018375e-1; + sum = sum * s + 0.918938533204672; + s = 0.5 * log (fa); + t = fa - 0.5; + s = s * t; + t = s - fa; + s = s + sum; + t = t + s; + } else { + i = fa - 3.0; + s = -4.02412642744125560E+003; + s = s * i - 2.97693796998962000E+005; + s = s * i - 6.38367087682528790E+006; + s = s * i - 5.57807214576539320E+007; + s = s * i - 2.24585140671479230E+008; + s = s * i - 4.70690608529125090E+008; + s = s * i - 7.62587065363263010E+008; + s = s * i - 9.71405112477113250E+008; + t = i - 1.02277248359873170E+003; + t = t * i - 1.34815350617954480E+005; + t = t * i - 4.64321188814343610E+006; + t = t * i - 6.48011106025542540E+007; + t = t * i - 4.19763847787431360E+008; + t = t * i - 1.25629926018000720E+009; + t = t * i - 1.40144133846491690E+009; + t = s / t; + t = t + i; + } + } else if (fa >= 1.5) { + i = fa - 2.0; + t = 9.84839283076310610E-009; + t = t * i - 6.69743850483466500E-008; + t = t * i + 2.16565148880011450E-007; + t = t * i - 4.86170275781575260E-007; + t = t * i + 9.77962097401114400E-007; + t = t * i - 2.03041287574791810E-006; + t = t * i + 4.36119725805364580E-006; + t = t * i - 9.43829310866446590E-006; + t = t * i + 2.05106878496644220E-005; + t = t * i - 4.49271383742108440E-005; + t = t * i + 9.94570466342226000E-005; + t = t * i - 2.23154589559238440E-004; + t = t * i + 5.09669559149637430E-004; + t = t * i - 1.19275392649162300E-003; + t = t * i + 2.89051032936815490E-003; + t = t * i - 7.38555102806811700E-003; + t = t * i + 2.05808084278121250E-002; + t = t * i - 6.73523010532073720E-002; + t = t * i + 3.22467033424113040E-001; + t = t * i + 4.22784335098467190E-001; + t = t * i; + } else if (fa >= 0.7) { + i = 1.0 - fa; + t = 1.17786911519331130E-002; + t = t * i + 3.89046747413522300E-002; + t = t * i + 5.90045711362049900E-002; + t = t * i + 6.02143305254344420E-002; + t = t * i + 5.61652708964839180E-002; + t = t * i + 5.75052755193461370E-002; + t = t * i + 6.21061973447320710E-002; + t = t * i + 6.67614724532521880E-002; + t = t * i + 7.14856037245421020E-002; + t = t * i + 7.69311251313347100E-002; + t = t * i + 8.33503129714946310E-002; + t = t * i + 9.09538288991182800E-002; + t = t * i + 1.00099591546322310E-001; + t = t * i + 1.11334278141734510E-001; + t = t * i + 1.25509666613462880E-001; + t = t * i + 1.44049896457704160E-001; + t = t * i + 1.69557177031481600E-001; + t = t * i + 2.07385551032182120E-001; + t = t * i + 2.70580808427600350E-001; + t = t * i + 4.00685634386517050E-001; + t = t * i + 8.22467033424113540E-001; + t = t * i + 5.77215664901532870E-001; + t = t * i; + } else { + t = -9.04051686831357990E-008; + t = t * fa + 7.06814224969349250E-007; + t = t * fa - 3.80702154637902830E-007; + t = t * fa - 2.12880892189316100E-005; + t = t * fa + 1.29108470307156190E-004; + t = t * fa - 2.15932815215386580E-004; + t = t * fa - 1.16484324388538480E-003; + t = t * fa + 7.21883433044470670E-003; + t = t * fa - 9.62194579514229560E-003; + t = t * fa - 4.21977386992884450E-002; + t = t * fa + 1.66538611813682460E-001; + t = t * fa - 4.20026350606819980E-002; + t = t * fa - 6.55878071519427450E-001; + t = t * fa + 5.77215664901523870E-001; + t = t * fa; + t = t * fa + fa; + t = -log (t); + } + if (a >= 0.0) return t; + if (fa < 1e-19) return -log(fa); + i = floor(fa); + if (fa == i) return 1.0 / (fa - i); /* a is an integer: return infinity */ + i = rint (2.0 * fa); + quot = static_cast(i); + i = fa - 0.5 * i; + i = i * CUDART_PI; + if (quot & 1) { + i = cos(i); + } else { + i = sin(i); + } + i = fabs(i); + t = log(CUDART_PI / (i * fa)) - t; + return t; +} + +__func__(unsigned long long int __internal_host_nan_kernel(const char *s)) +{ + unsigned long long i = 0; + int c; + int ovfl = 0; + int invld = 0; + if (s && (*s == '0')) { + s++; + if ((*s == 'x') || (*s == 'X')) { + s++; + while (*s == '0') s++; + while (*s) { + if (i > 0x0fffffffffffffffULL) { + ovfl = 1; + } + c = (((*s) >= 'A') && ((*s) <= 'F')) ? (*s + 'a' - 'A') : (*s); + if ((c >= 'a') && (c <= 'f')) { + c = c - 'a' + 10; + i = i * 16 + c; + } else if ((c >= '0') && (c <= '9')) { + c = c - '0'; + i = i * 16 + c; + } else { + invld = 1; + } + s++; + } + } else { + while (*s == '0') s++; + while (*s) { + if (i > 0x1fffffffffffffffULL) { + ovfl = 1; + } + c = *s; + if ((c >= '0') && (c <= '7')) { + c = c - '0'; + i = i * 8 + c; + } else { + invld = 1; + } + s++; + } + } + } else if (s) { + while (*s) { + c = *s; + if ((i > 1844674407370955161ULL) || + ((i == 1844674407370955161ULL) && (c > '5'))) { + ovfl = 1; + } + if ((c >= '0') && (c <= '9')) { + c = c - '0'; + i = i * 10 + c; + } else { + invld = 1; + } + s++; + } + } + if (ovfl) { + i = ~0ULL; + } + if (invld) { + i = 0ULL; + } + i = (i & 0x000fffffffffffffULL) | 0x7ff8000000000000ULL; + return i; +} + +__func__(double nan(const char *tagp)) +{ + unsigned long long l; + double d; + l = __internal_host_nan_kernel(tagp); + memcpy(&d, &l, sizeof(double)); + return d; +} + +__func__(double __host_tgamma_kernel(double a)) +{ + double t; + t = - 4.4268934071252475E-010; + t = t * a - 2.0266591846658954E-007; + t = t * a + 1.1381211721119527E-006; + t = t * a - 1.2507734816630748E-006; + t = t * a - 2.0136501740408771E-005; + t = t * a + 1.2805012607354486E-004; + t = t * a - 2.1524140811527418E-004; + t = t * a - 1.1651675459704604E-003; + t = t * a + 7.2189432248466381E-003; + t = t * a - 9.6219715326862632E-003; + t = t * a - 4.2197734554722394E-002; + t = t * a + 1.6653861138250356E-001; + t = t * a - 4.2002635034105444E-002; + t = t * a - 6.5587807152025712E-001; + t = t * a + 5.7721566490153287E-001; + t = t * a + 1.0000000000000000E+000; + return t; +} + +__func__(double __host_stirling_poly(double a)) +{ + double x = 1.0 / a; + double z = 0.0; + z = + 8.3949872067208726e-004; + z = z * x - 5.1717909082605919e-005; + z = z * x - 5.9216643735369393e-004; + z = z * x + 6.9728137583658571e-005; + z = z * x + 7.8403922172006662e-004; + z = z * x - 2.2947209362139917e-004; + z = z * x - 2.6813271604938273e-003; + z = z * x + 3.4722222222222220e-003; + z = z * x + 8.3333333333333329e-002; + z = z * x + 1.0000000000000000e+000; + return z; +} + +__func__(double __host_tgamma_stirling(double a)) +{ + double z; + double x; + z = __host_stirling_poly (a); + if (a < 142.0) { + x = pow (a, a - 0.5); + a = x * exp (-a); + a = a * CUDART_SQRT_2PI; + return a * z; + } else if (a < 172.0) { + x = pow (a, 0.5 * a - 0.25); + a = x * exp (-a); + a = a * CUDART_SQRT_2PI; + a = a * z; + return a * x; + } else { + return exp(1000.0); /* INF */ + } +} + +__func__(double tgamma(double a)) +{ + double s, xx, x = a; + if (__isnan(a)) { + return a + a; + } + if (fabs(x) < 20.0) { + if (x >= 0.0) { + s = 1.0; + xx = x; + while (xx > 1.5) { + xx = xx - 1.0; + s = s * xx; + } + if (x >= 0.5) { + xx = xx - 1.0; + } + xx = __host_tgamma_kernel (xx); + if (x < 0.5) { + xx = xx * x; + } + s = s / xx; + } else { + xx = x; + s = xx; + if (x == floor(x)) { + return 0.0 / (x - floor(x)); + } + while (xx < -0.5) { + xx = xx + 1.0; + s = s * xx; + } + xx = __host_tgamma_kernel (xx); + s = s * xx; + s = 1.0 / s; + } + return s; + } else { + if (x >= 0.0) { + return __host_tgamma_stirling (x); + } else { + double t; + int quot; + if (x == floor(x)) { + return 0.0 / (x - floor(x)); + } + if (x < -185.0) { + int negative; + x = floor(x); + negative = ((x - (2.0 * floor(0.5 * x))) == 1.0); + return negative ? (-1.0 / 1e308 / 1e308) : CUDART_ZERO; + } + /* compute sin(pi*x) accurately */ + xx = rint (2.0 * x); + quot = static_cast(xx); + xx = -0.5 * xx + x; + xx = xx * CUDART_PI; + if (quot & 1) { + xx = cos (xx); + } else { + xx = sin (xx); + } + if (quot & 2) { + xx = -xx; + } + x = fabs (x); + s = exp (-x); + t = x - 0.5; + if (x > 140.0) t = 0.5 * t; + t = pow (x, t); + if (x > 140.0) s = s * t; + s = s * __host_stirling_poly (x); + s = s * x; + s = s * xx; + s = 1.0 / s; + s = s * CUDART_SQRT_PIO2; + s = s / t; + return s; + } + } +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +/******************************************************************************* +* * +* HOST IMPLEMENTATION FOR FLOAT AND LONG DOUBLE ROUTINES FOR WINDOWS PLATFORM * +* MAP FLOAT AND LONG DOUBLE ROUTINES TO DOUBLE ROUTINES * +* * +*******************************************************************************/ + +__func__(int __signbitl(const long double a)) +{ + return __signbit(static_cast(a)); +} + +__func__(int __signbitf(const float a)) +{ + return __signbit(static_cast(a)); +} + +__func__(int __finitel(const long double a)) +{ + return __finite(static_cast(a)); +} + +__func__(int __finitef(const float a)) +{ + return __finite(static_cast(a)); +} + +__func__(int __isinfl(const long double a)) +{ + return __isinf(static_cast(a)); +} + +__func__(int __isinff(const float a)) +{ + return __isinf(static_cast(a)); +} + +__func__(int __isnanl(const long double a)) +{ + return __isnan(static_cast(a)); +} + +__func__(int __isnanf(const float a)) +{ + return __isnan(static_cast(a)); +} + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +__func__(float fmaxf(const float a, const float b)) +{ + return static_cast(fmax(static_cast(a), static_cast(b))); +} + +__func__(float fminf(const float a, const float b)) +{ + return static_cast(fmin(static_cast(a), static_cast(b))); +} + +__func__(float roundf(const float a)) +{ + return static_cast(round(static_cast(a))); +} + +__func__(long int lroundf(const float a)) +{ + return lround(static_cast(a)); +} + +__func__(long long int llroundf(const float a)) +{ + return llround(static_cast(a)); +} + +__func__(float truncf(const float a)) +{ + return static_cast(trunc(static_cast(a))); +} + +__func__(float rintf(const float a)) +{ + return static_cast(rint(static_cast(a))); +} + +__func__(float nearbyintf(const float a)) +{ + return static_cast(nearbyint(static_cast(a))); +} + +__func__(long int lrintf(const float a)) +{ + return lrint(static_cast(a)); +} + +__func__(long long int llrintf(const float a)) +{ + return llrint(static_cast(a)); +} + +__func__(float logbf(const float a)) +{ + return static_cast(logb(static_cast(a))); +} + +__func__(float scalblnf(const float a, const long int b)) +{ + return static_cast(scalbln(static_cast(a), b)); +} + +__func__(float log2f(const float a)) +{ + return static_cast(log2(static_cast(a))); +} + +__func__(float exp2f(const float a)) +{ + return static_cast(exp2(static_cast(a))); +} + +__func__(float acoshf(const float a)) +{ + return static_cast(acosh(static_cast(a))); +} + +__func__(float asinhf(const float a)) +{ + return static_cast(asinh(static_cast(a))); +} + +__func__(float atanhf(const float a)) +{ + return static_cast(atanh(static_cast(a))); +} + +__func__(float cbrtf(const float a)) +{ + return static_cast(cbrt(static_cast(a))); +} + +__func__(float expm1f(const float a)) +{ + return static_cast(expm1(static_cast(a))); +} + +__func__(float fdimf(const float a, const float b)) +{ + return static_cast(fdim(static_cast(a), static_cast(b))); +} + +__func__(float log1pf(const float a)) +{ + return static_cast(log1p(static_cast(a))); +} + +__func__(float scalbnf(const float a, const int b)) +{ + return static_cast(scalbn(static_cast(a), b)); +} + +__func__(float fmaf(const float a, const float b, const float c)) +{ + return static_cast(fma(static_cast(a), static_cast(b), static_cast(c))); +} + +__func__(int ilogbf(const float a)) +{ + return ilogb(static_cast(a)); +} + +__func__(float erff(const float a)) +{ + return static_cast(erf(static_cast(a))); +} + +__func__(float erfcf(const float a)) +{ + return static_cast(erfc(static_cast(a))); +} + +__func__(float lgammaf(const float a)) +{ + return static_cast(lgamma(static_cast(a))); +} + +__func__(float tgammaf(const float a)) +{ + return static_cast(tgamma(static_cast(a))); +} + +__func__(float remquof(const float a, const float b, int *quo)) +{ + return static_cast(remquo(static_cast(a), static_cast(b), quo)); +} + +__func__(float remainderf(const float a, const float b)) +{ + return static_cast(remainder(static_cast(a), static_cast(b))); +} +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#if (defined _MSC_VER) && (_MSC_VER >= 1700) +__func__(float j0f(const float a)) +{ + return static_cast(_j0(static_cast(a))); +} + +__func__(float j1f(const float a)) +{ + return static_cast(_j1(static_cast(a))); +} + +__func__(float jnf(const int n, const float a)) +{ + return static_cast(_jn(n, static_cast(a))); +} + +__func__(float y0f(const float a)) +{ + return static_cast(_y0(static_cast(a))); +} + +__func__(float y1f(const float a)) +{ + return static_cast(_y1(static_cast(a))); +} + +__func__(float ynf(const int n, const float a)) +{ + return static_cast(_yn(n, static_cast(a))); +} +#endif /* (defined _MSC_VER) && (_MSC_VER >= 1700) */ + + +/******************************************************************************* +* * +* HOST IMPLEMENTATION FOR FLOAT ROUTINES FOR WINDOWS PLATFORM * +* * +*******************************************************************************/ + +#if (!defined(_MSC_VER) || _MSC_VER < 1800) +__func__(float copysignf(float a, const float b)) +{ + unsigned int aa, bb; + memcpy(&aa, &a, sizeof(float)); + memcpy(&bb, &b, sizeof(float)); + aa = (aa & ~0x80000000U) | (bb & 0x80000000U); + memcpy(&a, &aa, sizeof(float)); + return a; +} + +__func__(float nextafterf(float a, const float b)) +{ + unsigned int ia; + unsigned int ib; + memcpy(&ia, &a, sizeof(float)); + memcpy(&ib, &b, sizeof(float)); + if (__isnanf(a) || __isnanf(b)) return a + b; /*NaN*/ + if (((ia | ib) << 1U) == 0U) return b; + if (a == 0.0F) { + return copysignf(1.401298464e-045F, b); /*crossover*/ + } + if ((a < b) && (a < 0.0F)) ia--; + if ((a < b) && (a > 0.0F)) ia++; + if ((a > b) && (a < 0.0F)) ia++; + if ((a > b) && (a > 0.0F)) ia--; + memcpy(&a, &ia, sizeof(float)); + return a; +} + +__func__(float nanf(const char *tagp)) +{ + float f; + unsigned int i; + i = static_cast(__internal_host_nan_kernel(tagp)); + i = (i & 0x007fffffU) | 0x7fc00000U; + memcpy(&f, &i, sizeof(float)); + return f; +} + +#endif /* (!defined(_MSC_VER) || _MSC_VER < 1800) */ + +#endif /* _WIN32 */ + +/******************************************************************************* +* * +* HOST IMPLEMENTATION FOR DOUBLE AND FLOAT ROUTINES. ALL PLATFORMS * +* * +*******************************************************************************/ + +__func__(double rsqrt(const double a)) +{ + return 1.0 / sqrt(a); +} + +__func__(double rcbrt(const double a)) +{ + double s, t; + + if (__isnan(a)) { + return a + a; + } + if (a == 0.0 || __isinf(a)) { + return 1.0 / a; + } + s = fabs(a); + t = exp2(-CUDART_THIRD * log2(s)); /* initial approximation */ + t = ((t*t) * (-s*t) + 1.0) * (CUDART_THIRD*t) + t;/* refine approximation */ +#if defined(__APPLE__) + if (__signbitd(a)) +#else /* __APPLE__ */ + if (__signbit(a)) +#endif /* __APPLE__ */ + { + t = -t; + } + return t; +} + +__func__(double sinpi(double a)) +{ + int n; + + if (__isnan(a)) { + return a + a; + } + if (a == 0.0 || __isinf(a)) { + return sin (a); + } + if (a == floor(a)) { + return ((a / 1.0e308) / 1.0e308) / 1.0e308; + } + double twoa = a + a; + double rtwoa = round(twoa); + long long int l = (long long int)rtwoa; + n = (int)l; + a -= rtwoa * 0.5; + a = a * CUDART_PI; + if (n & 1) { + a = cos (a); + } else { + a = sin (a); + } + if (n & 2) { + a = -a; + } + return a; +} + +__func__(double cospi(double a)) +{ + int n; + + if (__isnan(a)) { + return a + a; + } + if (__isinf(a)) { + return cos (a); + } + if (fabs(a) > 9.0071992547409920e+015) { + a = 0.0; + } + double twoa = a + a; + double rtwoa = round(twoa); + long long int l = (long long int)rtwoa; + n = (int)l; + a -= rtwoa * 0.5; + a = a * CUDART_PI; + n++; + if (n & 1) { + a = cos (a); + } else { + a = sin (a); + } + if (n & 2) { + a = -a; + } + if (a == 0.0) { + a = fabs(a); + } + return a; +} + +__func__(void sincospi(const double a, double *sptr, double *cptr)) +{ + *sptr = sinpi(a); + *cptr = cospi(a); +} + +__func__(double erfinv(const double a)) +{ + double p, q, t, fa; + unsigned long long int l; + + fa = fabs(a); + if (fa >= 1.0) { + l = 0xfff8000000000000ULL; + memcpy(&t, &l, sizeof(double)); /* INDEFINITE */ + if (fa == 1.0) { + t = a * exp(1000.0); /* Infinity */ + } + } else if (fa >= 0.9375) { + /* Based on: J.M. Blair, C.A. Edwards, J.H. Johnson: Rational Chebyshev + Approximations for the Inverse of the Error Function. Mathematics of + Computation, Vol. 30, No. 136 (Oct. 1976), pp. 827-830. Table 59 + */ + t = log1p(-fa); + t = 1.0 / sqrt(-t); + p = 2.7834010353747001060e-3; + p = p * t + 8.6030097526280260580e-1; + p = p * t + 2.1371214997265515515e+0; + p = p * t + 3.1598519601132090206e+0; + p = p * t + 3.5780402569085996758e+0; + p = p * t + 1.5335297523989890804e+0; + p = p * t + 3.4839207139657522572e-1; + p = p * t + 5.3644861147153648366e-2; + p = p * t + 4.3836709877126095665e-3; + p = p * t + 1.3858518113496718808e-4; + p = p * t + 1.1738352509991666680e-6; + q = t + 2.2859981272422905412e+0; + q = q * t + 4.3859045256449554654e+0; + q = q * t + 4.6632960348736635331e+0; + q = q * t + 3.9846608184671757296e+0; + q = q * t + 1.6068377709719017609e+0; + q = q * t + 3.5609087305900265560e-1; + q = q * t + 5.3963550303200816744e-2; + q = q * t + 4.3873424022706935023e-3; + q = q * t + 1.3858762165532246059e-4; + q = q * t + 1.1738313872397777529e-6; + t = p / (q * t); + if (a < 0.0) t = -t; + } else if (fa >= 0.75) { + /* Based on: J.M. Blair, C.A. Edwards, J.H. Johnson: Rational Chebyshev + Approximations for the Inverse of the Error Function. Mathematics of + Computation, Vol. 30, No. 136 (Oct. 1976), pp. 827-830. Table 39 + */ + t = a * a - .87890625; + p = .21489185007307062000e+0; + p = p * t - .64200071507209448655e+1; + p = p * t + .29631331505876308123e+2; + p = p * t - .47644367129787181803e+2; + p = p * t + .34810057749357500873e+2; + p = p * t - .12954198980646771502e+2; + p = p * t + .25349389220714893917e+1; + p = p * t - .24758242362823355486e+0; + p = p * t + .94897362808681080020e-2; + q = t - .12831383833953226499e+2; + q = q * t + .41409991778428888716e+2; + q = q * t - .53715373448862143349e+2; + q = q * t + .33880176779595142685e+2; + q = q * t - .11315360624238054876e+2; + q = q * t + .20369295047216351160e+1; + q = q * t - .18611650627372178511e+0; + q = q * t + .67544512778850945940e-2; + p = p / q; + t = a * p; + } else { + /* Based on: J.M. Blair, C.A. Edwards, J.H. Johnson: Rational Chebyshev + Approximations for the Inverse of the Error Function. Mathematics of + Computation, Vol. 30, No. 136 (Oct. 1976), pp. 827-830. Table 18 + */ + t = a * a - .5625; + p = - .23886240104308755900e+2; + p = p * t + .45560204272689128170e+3; + p = p * t - .22977467176607144887e+4; + p = p * t + .46631433533434331287e+4; + p = p * t - .43799652308386926161e+4; + p = p * t + .19007153590528134753e+4; + p = p * t - .30786872642313695280e+3; + q = t - .83288327901936570000e+2; + q = q * t + .92741319160935318800e+3; + q = q * t - .35088976383877264098e+4; + q = q * t + .59039348134843665626e+4; + q = q * t - .48481635430048872102e+4; + q = q * t + .18997769186453057810e+4; + q = q * t - .28386514725366621129e+3; + p = p / q; + t = a * p; + } + return t; +} + +__func__(double erfcinv(const double a)) +{ + double t; + unsigned long long int l; + + if (__isnan(a)) { + return a + a; + } + if (a <= 0.0) { + l = 0xfff8000000000000ULL; + memcpy(&t, &l, sizeof(double)); /* INDEFINITE */ + if (a == 0.0) { + t = (1.0 - a) * exp(1000.0); /* Infinity */ + } + } + else if (a >= 0.0625) { + t = erfinv (1.0 - a); + } + else if (a >= 1e-100) { + /* Based on: J.M. Blair, C.A. Edwards, J.H. Johnson: Rational Chebyshev + Approximations for the Inverse of the Error Function. Mathematics of + Computation, Vol. 30, No. 136 (Oct. 1976), pp. 827-830. Table 59 + */ + double p, q; + t = log(a); + t = 1.0 / sqrt(-t); + p = 2.7834010353747001060e-3; + p = p * t + 8.6030097526280260580e-1; + p = p * t + 2.1371214997265515515e+0; + p = p * t + 3.1598519601132090206e+0; + p = p * t + 3.5780402569085996758e+0; + p = p * t + 1.5335297523989890804e+0; + p = p * t + 3.4839207139657522572e-1; + p = p * t + 5.3644861147153648366e-2; + p = p * t + 4.3836709877126095665e-3; + p = p * t + 1.3858518113496718808e-4; + p = p * t + 1.1738352509991666680e-6; + q = t + 2.2859981272422905412e+0; + q = q * t + 4.3859045256449554654e+0; + q = q * t + 4.6632960348736635331e+0; + q = q * t + 3.9846608184671757296e+0; + q = q * t + 1.6068377709719017609e+0; + q = q * t + 3.5609087305900265560e-1; + q = q * t + 5.3963550303200816744e-2; + q = q * t + 4.3873424022706935023e-3; + q = q * t + 1.3858762165532246059e-4; + q = q * t + 1.1738313872397777529e-6; + t = p / (q * t); + } + else { + /* Based on: J.M. Blair, C.A. Edwards, J.H. Johnson: Rational Chebyshev + Approximations for the Inverse of the Error Function. Mathematics of + Computation, Vol. 30, No. 136 (Oct. 1976), pp. 827-830. Table 82 + */ + double p, q; + t = log(a); + t = 1.0 / sqrt(-t); + p = 6.9952990607058154858e-1; + p = p * t + 1.9507620287580568829e+0; + p = p * t + 8.2810030904462690216e-1; + p = p * t + 1.1279046353630280005e-1; + p = p * t + 6.0537914739162189689e-3; + p = p * t + 1.3714329569665128933e-4; + p = p * t + 1.2964481560643197452e-6; + p = p * t + 4.6156006321345332510e-9; + p = p * t + 4.5344689563209398450e-12; + q = t + 1.5771922386662040546e+0; + q = q * t + 2.1238242087454993542e+0; + q = q * t + 8.4001814918178042919e-1; + q = q * t + 1.1311889334355782065e-1; + q = q * t + 6.0574830550097140404e-3; + q = q * t + 1.3715891988350205065e-4; + q = q * t + 1.2964671850944981713e-6; + q = q * t + 4.6156017600933592558e-9; + q = q * t + 4.5344687377088206783e-12; + t = p / (q * t); + } + return t; +} + +__func__(double normcdfinv(const double a)) +{ + return -1.4142135623730951 * erfcinv(a + a); +} + +__func__(double normcdf(double a)) +{ + double ah, al, t1, t2, u1, u2, v1, v2, z; + if (fabs (a) > 38.5) a = copysign (38.5, a); + ah = a * 134217729.0; + u1 = (a - ah) + ah; + u2 = a - u1; + v1 = -7.0710678398609161e-01; + v2 = 2.7995440410322203e-09; + t1 = a * -CUDART_SQRT_HALF_HI; + t2 = (((u1 * v1 - t1) + u1 * v2) + u2 * v1) + u2 * v2; + t2 = (a * -CUDART_SQRT_HALF_LO) + t2; + ah = t1 + t2; + z = erfc (ah); + if (a < -1.0) { + al = (t1 - ah) + t2; + t1 = -2.0 * ah * z; + z = t1 * al + z; + } + return 0.5 * z; +} + +__func__(double erfcx(const double a)) +{ + double x, t1, t2, t3; + + if (__isnan(a)) { + return a + a; + } + x = fabs(a); + if (x < 32.0) { + /* + * This implementation of erfcx() is based on the algorithm in: M. M. + * Shepherd and J. G. Laframboise, "Chebyshev Approximation of (1 + 2x) + * exp(x^2)erfc x in 0 <= x < INF", Mathematics of Computation, Vol. + * 36, No. 153, January 1981, pp. 249-253. For the core approximation, + * the input domain [0,INF] is transformed via (x-k) / (x+k) where k is + * a precision-dependent constant. Here, we choose k = 4.0, so the input + * domain [0, 27.3] is transformed into the core approximation domain + * [-1, 0.744409]. + */ + /* + // Compute (1+2*x)*exp(x*x)*erfc(x) + */ + /* t2 = (x-4.0)/(x+4.0), transforming [0,INF] to [-1,+1] */ + t1 = x - 4.0; + t2 = x + 4.0; + t2 = t1 / t2; + /* approximate on [-1, 0.744409] */ + t1 = - 3.5602694826817400E-010; + t1 = t1 * t2 - 9.7239122591447274E-009; + t1 = t1 * t2 - 8.9350224851649119E-009; + t1 = t1 * t2 + 1.0404430921625484E-007; + t1 = t1 * t2 + 5.8806698585341259E-008; + t1 = t1 * t2 - 8.2147414929116908E-007; + t1 = t1 * t2 + 3.0956409853306241E-007; + t1 = t1 * t2 + 5.7087871844325649E-006; + t1 = t1 * t2 - 1.1231787437600085E-005; + t1 = t1 * t2 - 2.4399558857200190E-005; + t1 = t1 * t2 + 1.5062557169571788E-004; + t1 = t1 * t2 - 1.9925637684786154E-004; + t1 = t1 * t2 - 7.5777429182785833E-004; + t1 = t1 * t2 + 5.0319698792599572E-003; + t1 = t1 * t2 - 1.6197733895953217E-002; + t1 = t1 * t2 + 3.7167515553018733E-002; + t1 = t1 * t2 - 6.6330365827532434E-002; + t1 = t1 * t2 + 9.3732834997115544E-002; + t1 = t1 * t2 - 1.0103906603555676E-001; + t1 = t1 * t2 + 6.8097054254735140E-002; + t1 = t1 * t2 + 1.5379652102605428E-002; + t1 = t1 * t2 - 1.3962111684056291E-001; + t1 = t1 * t2 + 1.2329951186255526E+000; + /* + // Note: (1+2*x)*exp(x*x)*erfc(x) / (1+2*x) = exp(x*x)*erfc(x) + */ + t2 = 2.0 * x + 1.0; + t1 = t1 / t2; + } else { + /* asymptotic expansion for large aguments */ + t2 = 1.0 / x; + t3 = t2 * t2; + t1 = -29.53125; + t1 = t1 * t3 + 6.5625; + t1 = t1 * t3 - 1.875; + t1 = t1 * t3 + 0.75; + t1 = t1 * t3 - 0.5; + t1 = t1 * t3 + 1.0; + t2 = t2 * 5.6418958354775628e-001; + t1 = t1 * t2; + } + if (a < 0.0) { + /* + // Note: erfcx(x) = 2*exp(x^2) - erfcx(|x|) + */ + t2 = (static_cast(x * 16.0)) * 0.0625; + t3 = (x - t2) * (x + t2); + t3 = exp(t2 * t2) * exp(t3); + t3 = t3 + t3; + t1 = t3 - t1; + } + return t1; +} + +__func__(float rsqrtf(const float a)) +{ + return static_cast(rsqrt(static_cast(a))); +} + +__func__(float rcbrtf(const float a)) +{ + return static_cast(rcbrt(static_cast(a))); +} + +__func__(float sinpif(const float a)) +{ + return static_cast(sinpi(static_cast(a))); +} + +__func__(float cospif(const float a)) +{ + return static_cast(cospi(static_cast(a))); +} + +__func__(void sincospif(const float a, float *sptr, float *cptr)) +{ + double s, c; + + sincospi(static_cast(a), &s, &c); + *sptr = static_cast(s); + *cptr = static_cast(c); +} + +__func__(float erfinvf(const float a)) +{ + return static_cast(erfinv(static_cast(a))); +} + +__func__(float erfcinvf(const float a)) +{ + return static_cast(erfcinv(static_cast(a))); +} + +__func__(float normcdfinvf(const float a)) +{ + return static_cast(normcdfinv(static_cast(a))); +} + +__func__(float normcdff(const float a)) +{ + return static_cast(normcdf(static_cast(a))); +} + +__func__(float erfcxf(const float a)) +{ + return static_cast(erfcx(static_cast(a))); +} + +#if defined(_WIN32) + +#pragma warning(default: 4211) + +#endif /* _WIN32 */ + +#endif /* !__CUDACC__ */ + +#endif /* !__MATH_FUNCTIONS_HPP__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_MATH_FUNCTIONS_HPP__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_MATH_FUNCTIONS_HPP__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/mma.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/mma.h new file mode 100644 index 0000000000000000000000000000000000000000..3a85d6374eca408010f1221b698344b2cfb1ac2c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/mma.h @@ -0,0 +1,754 @@ +/* + * Copyright 2017-2020 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/mma.h is an internal header file and must not be used directly. Please use mma.h instead.") +#else +#warning "crt/mma.h is an internal header file and must not be used directly. Please use mma.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_CUDA_MMA_H__ +#endif + +#if !defined(__CUDA_MMA_H__) +#define __CUDA_MMA_H__ + +#include +#include + +#define __CUDA_MMA_DEVICE_DECL__ static __device__ __inline__ + +#if defined(__cplusplus) && defined(__CUDACC__) + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 700 + + +#ifndef __CUDA_ARCH__ +#define __DEF_IF_HOST { } +#else /* !__CUDA_ARCH__ */ +#define __DEF_IF_HOST ; +#endif /* __CUDA_ARCH__ */ + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 720 +#define __CUDA_IMMA__ 1 +#endif /* !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 720 */ + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 730 +#define __CUDA_SUBBYTE_IMMA__ 1 +#endif /* !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 730 */ + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 800 +#define __CUDA_AMPERE_MMA__ 1 +#endif /* !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 800 */ + +namespace nvcuda { +namespace wmma { + + // utility functions +#ifdef __CUDA_AMPERE_MMA__ + inline __device__ float __float_to_tf32(float in) + { + float ret; + asm("{\n .reg .b32 __$1;" + "\n cvt.rna.tf32.f32 __$1, %1;" + "\n mov.b32 %0, __$1;\n}\n" : "=f"(ret) : "f"(in) ); + return ret; + } +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // tags + // + struct row_major; + struct col_major; + struct matrix_a; + struct matrix_b; + struct accumulator; + +#ifdef __CUDA_AMPERE_MMA__ + namespace precision { + struct tf32; + } +#endif /* __CUDA_AMPERE_MMA__ */ +#ifdef __CUDA_SUBBYTE_IMMA__ + namespace experimental { + namespace precision { + struct u4; // 4-bit unsigned + struct s4; // 4-bit signed + struct b1; // 1-bit + } + enum bmmaBitOp { bmmaBitOpXOR = 1 +#ifdef __CUDA_AMPERE_MMA__ + , bmmaBitOpAND = 2 +#endif /* __CUDA_AMPERE_MMA__ */ + }; + enum bmmaAccumulateOp { bmmaAccumulateOpPOPC = 1 }; + } +#endif /* __CUDA_SUBBYTE_IMMA__ */ + + // + // layout + // + enum layout_t { + mem_row_major, mem_col_major + }; + + template + struct helper_traits { + typedef T element_type; + typedef T storage_element_type; + typedef T fill_argument_type; + }; + +#ifdef __CUDA_SUBBYTE_IMMA__ + template<> struct helper_traits { + typedef experimental::precision::u4 element_type; + typedef unsigned int storage_element_type; + typedef unsigned int fill_argument_type; + }; + + template<> struct helper_traits { + typedef experimental::precision::s4 element_type; + typedef int storage_element_type; + typedef int fill_argument_type; + }; + + template<> struct helper_traits { + typedef experimental::precision::b1 element_type; + typedef unsigned int storage_element_type; + typedef unsigned int fill_argument_type; + }; +#endif /* __CUDA_SUBBYTE_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + template<> struct helper_traits { + typedef precision::tf32 element_type; + typedef float storage_element_type; + typedef float fill_argument_type; + }; +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // The base fragment type + // + /* note: alignment required for compiler implementation */ + template + struct __align__(8) __frag_base { + + /* Number of elements in the fragment */ + enum {num_elements = size}; + + /* Number of storage elements in the fragment. + + The elements of the fragment are packed together when the + fragment element type is experimental::precision::u4, + experimental::precision::s4 or experimental::precision::b1. + When elements are packed, num_storage_elements + will be smaller than num_elements. + */ + enum {num_storage_elements = packed_size}; + + /* element type of the fragment */ + typedef T element_type; + + /* element type of the storage representation. + + The mapping from element_type to storage_element_type is as follows: + experimental::precision::u4 -> unsigned (8 elements in 1 storage element) + experimental::precision::s4 -> int (8 elements in 1 storage element) + experimental::precision::b1 -> unsigned (32 elements in 1 storage element) + precision::tf32 -> float (1 element in 1 storage element) + all other types T -> T + */ + typedef typename helper_traits::storage_element_type storage_element_type; + + /* Storage for the (possibly packed) fragment elements. */ + storage_element_type x[num_storage_elements]; + }; + + template + static inline __device__ StorageType __get_storage_value(ArgType in) { return in; } + +#ifdef __CUDA_SUBBYTE_IMMA__ + template<> + __device__ inline unsigned + __get_storage_value(unsigned in) + { + /* For experimental::precision::u4 fragment element type, pack 8 elements into a single + 32-bit unsigned int storage element */ + unsigned val = in & 0xf; + return (val | (val << 4) | (val << 8) | (val << 12) | (val << 16) | + (val << 20) | (val << 24) | (val << 28)); + }; + + template<> + __device__ inline int + __get_storage_value(int in) + { + /* For experimental::precision::s4 fragment element type, pack 8 elements into a single + 32-bit signed int storage element */ + int val = in & 0xf; + return (val | (val << 4) | (val << 8) | (val << 12) | (val << 16) | + (val << 20) | (val << 24) | (val << 28)); + }; + + template<> + __device__ inline unsigned + __get_storage_value(unsigned in) + { + /* For experimental::precision::b1 fragment element type, pack 32 elements into a + single 32-bit unsigned int storage element */ + return (in & 0x1) ? 0xFFFFFFFFU : 0; + } +#endif /* __CUDA_SUBBYTE_IMMA__ */ + + template + __CUDA_MMA_DEVICE_DECL__ void fill_fragment(__frag_base& f, + /* The mapping from fragment element type (FragEleType) to fill_argument_type is: + experimental::precision::u4 -> unsigned (only lower 4 bits taken) + experimental::precision::s4 -> int (only lower 4 bits taken) + experimental::precision::b1 -> unsigned (only lowest 1 bit taken) + precision::tf32 -> float + all other types T -> T + */ + const typename helper_traits::fill_argument_type & in) { + + /* get the (possibly packed) storage element value. See the specializations above for fragment + element types where the storage representation is packed */ + typedef typename helper_traits::storage_element_type storage_type; + storage_type v = __get_storage_value(in); +#pragma unroll + for (int i=0; i< f.num_storage_elements; i++) + f.x[i] = v; + } + + // + // Fragment template + // + template class fragment; + + // + // Fragments for 16x16x16 + // + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 8> {}; + template<> class fragment : public __frag_base {}; + +#ifdef __CUDA_IMMA__ + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + template<> class fragment : public __frag_base<__nv_bfloat16, 8> {}; + template<> class fragment : public __frag_base<__nv_bfloat16, 8> {}; + template<> class fragment : public __frag_base<__nv_bfloat16, 8> {}; + template<> class fragment : public __frag_base<__nv_bfloat16, 8> {}; +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // Fragments for 32x8x16 + // + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 8> {}; + template<> class fragment : public __frag_base {}; + +#ifdef __CUDA_IMMA__ + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + template<> class fragment : public __frag_base<__nv_bfloat16, 16> {}; + template<> class fragment : public __frag_base<__nv_bfloat16, 16> {}; + template<> class fragment : public __frag_base<__nv_bfloat16, 4> {}; + template<> class fragment : public __frag_base<__nv_bfloat16, 4> {}; +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // Fragments for 8x32x16 + // + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 16> {}; + template<> class fragment : public __frag_base<__half, 8> {}; + template<> class fragment : public __frag_base {}; + +#ifdef __CUDA_IMMA__ + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + template<> class fragment : public __frag_base<__nv_bfloat16, 4> {}; + template<> class fragment : public __frag_base<__nv_bfloat16, 4> {}; + template<> class fragment : public __frag_base<__nv_bfloat16, 16> {}; + template<> class fragment : public __frag_base<__nv_bfloat16, 16> {}; +#endif /* __CUDA_AMPERE_MMA__ */ + +#ifdef __CUDA_SUBBYTE_IMMA__ + // + // Fragments for 8x8x32 + // + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + + // + // Fragments for 8x8x128 + // + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; +#endif /* __CUDA_SUBBYTE_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + // + // Fragments for 16x16x8 + // + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + + // + // Fragments for 8x8x4 + // + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; + template<> class fragment : public __frag_base {}; +#endif /* __CUDA_AMPERE_MMA__ */ + + + // + // Load functions for frags of shape m16n16k16 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm, layout_t layout) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm, layout_t layout) __DEF_IF_HOST + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const int* p, unsigned ldm, layout_t layout) __DEF_IF_HOST +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // Load functions for frags of shape m32n8k16 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm, layout_t layout) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm, layout_t layout) __DEF_IF_HOST + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const int* p, unsigned ldm, layout_t layout) __DEF_IF_HOST +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // Load functions for frags of shape m8n32k16 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm, layout_t layout) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm, layout_t layout) __DEF_IF_HOST + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const int* p, unsigned ldm, layout_t layout) __DEF_IF_HOST +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) __DEF_IF_HOST +#endif /* __CUDA_AMPERE_MMA__ */ + +#ifdef __CUDA_SUBBYTE_IMMA__ + // + // Load functions for frags of shape m8n8k32 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) __DEF_IF_HOST + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const int* p, unsigned ldm, layout_t layout) __DEF_IF_HOST + + // + // Load functions for frags of shape m8n8k128 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const int* p, unsigned ldm, layout_t layout) __DEF_IF_HOST + +#endif /* __CUDA_SUBBYTE_IMMA__ */ + + +#ifdef __CUDA_AMPERE_MMA__ + // + // Load functions for frags of shape m16n16k8 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm, layout_t layout) __DEF_IF_HOST + + // + // Load functions for frags of shape m8n8k4 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const double* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const double* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const double* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const double* p, unsigned ldm) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const double* p, unsigned ldm, layout_t layout) __DEF_IF_HOST +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // Store functions for frags of shape m16n16k16 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(__half *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(float *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(int *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST +#endif /* __CUDA_IMMA__ */ + + // + // Store functions for frags of shape m32n8k16 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(__half *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(float *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(int *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST +#endif /* __CUDA_IMMA__ */ + + // + // Store functions for frags of shape m8n32k16 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(__half *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(float *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(int *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_SUBBYTE_IMMA__ + // + // Store functions for frags of shape m8n8k32 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(int *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST + + // + // Store functions for frags of shape m8n8k128 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(int *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST + +#endif /* __CUDA_SUBBYTE_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + // + // Store functions for frags of shape m16n16k8 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(float *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST + + // + // Store functions for frags of shape m8n8k4 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(double *p, const fragment& a, unsigned ldm, layout_t layout) __DEF_IF_HOST +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // MMA functions for shape m16n16k16 + // + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // MMA functions for shape m32n8k16 + // + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // MMA functions for shape m8n32k16 + // + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST +#endif /* __CUDA_AMPERE_MMA__ */ + +#ifdef __CUDA_SUBBYTE_IMMA__ + // + // MMA functions for shape m8n8k32 + // + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf=false) __DEF_IF_HOST + + + // + // MMA functions for shape m8n8k128 + // + __CUDA_MMA_DEVICE_DECL__ void bmma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, + experimental::bmmaBitOp = experimental::bmmaBitOpXOR, + experimental::bmmaAccumulateOp = experimental::bmmaAccumulateOpPOPC) __DEF_IF_HOST + +#endif /* __CUDA_SUBBYTE_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + // + // MMA functions for shape m16n16k8 + // + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + + // + // MMA functions for shape m8n8k4 + // + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) __DEF_IF_HOST +#endif /* __CUDA_AMPERE_MMA__ */ +}; +}; + +#undef __DEF_IF_HOST +#undef __CUDA_IMMA__ +#undef __CUDA_SUBBYTE_IMMA__ +#undef __CUDA_AMPERE_MMA__ +#endif /* !__CUDA_ARCH__ || __CUDA_ARCH__ >= 700 */ + +#endif /* __cplusplus && __CUDACC__ */ + +#undef __CUDA_MMA_DEVICE_DECL__ + +#if defined(__CUDA_ARCH__) +#include "mma.hpp" +#endif /* defined(__CUDA_ARCH__) */ + + +#endif /* !__CUDA_MMA_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_CUDA_MMA_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_CUDA_MMA_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/mma.hpp b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/mma.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3e10f2a982bd2dcf9814a2fc05a3f200d5a1cb07 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/mma.hpp @@ -0,0 +1,1128 @@ +/* + * Copyright 2017-2020 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/mma.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/mma.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_CUDA_MMA_HPP__ +#endif + +#if !defined(__CUDA_MMA_HPP__) +#define __CUDA_MMA_HPP__ + +#if defined(__cplusplus) && defined(__CUDACC__) + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 700 + +#include +#include + +#define __CUDA_MMA_DEVICE_DECL__ static __device__ __inline__ + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 720 +#define __CUDA_IMMA__ 1 +#endif /* !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 720 */ + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 730 +#define __CUDA_SUBBYTE_IMMA__ 1 +#endif /* !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 730 */ + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 800 +#define __CUDA_AMPERE_MMA__ 1 +#endif /* !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 800 */ + +namespace nvcuda { +namespace wmma { + + // + // Load functions for frags of shape m16n16k16 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m16n16k16_ld_a((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m16n16k16_ld_a((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m16n16k16_ld_b((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m16n16k16_ld_b((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m16n16k16_ld_c_f16((int*)&a, (const int*)p, ldm, 0); + else + __hmma_m16n16k16_ld_c_f16((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m16n16k16_ld_c_f32((float*)&a, (const float*)p, ldm, 0); + else + __hmma_m16n16k16_ld_c_f32((float*)&a, (const float*)p, ldm, 1); + } + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m16n16k16_ld_a_s8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m16n16k16_ld_a_s8((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m16n16k16_ld_a_u8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m16n16k16_ld_a_u8((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m16n16k16_ld_b_s8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m16n16k16_ld_b_s8((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m16n16k16_ld_b_u8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m16n16k16_ld_b_u8((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const int* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __imma_m16n16k16_ld_c((int *)&a, (const int*)p, ldm, 0); + else + __imma_m16n16k16_ld_c((int *)&a, (const int*)p, ldm, 1); + } +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m16n16k16_ld_a((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m16n16k16_ld_a((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m16n16k16_ld_b((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m16n16k16_ld_b((int*)&a, (const int*)p, ldm, 1); + } +#endif /* __CUDA_AMPERE_MMA__ */ + + + // + // Load functions for frags of shape m32n8k16 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m32n8k16_ld_a((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m32n8k16_ld_a((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m32n8k16_ld_b((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m32n8k16_ld_b((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m32n8k16_ld_c_f16((int*)&a, (const int*)p, ldm, 0); + else + __hmma_m32n8k16_ld_c_f16((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m32n8k16_ld_c_f32((float*)&a, (const float*)p, ldm, 0); + else + __hmma_m32n8k16_ld_c_f32((float*)&a, (const float*)p, ldm, 1); + } + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m32n8k16_ld_a_s8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m32n8k16_ld_a_s8((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m32n8k16_ld_a_u8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m32n8k16_ld_a_u8((int *)&a, (const int *)p, ldm, 1); + } + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m32n8k16_ld_b_s8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m32n8k16_ld_b_s8((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m32n8k16_ld_b_u8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m32n8k16_ld_b_u8((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const int* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __imma_m32n8k16_ld_c((int *)&a, (const int*)p, ldm, 0); + else + __imma_m32n8k16_ld_c((int *)&a, (const int*)p, ldm, 1); + } +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m32n8k16_ld_a((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m32n8k16_ld_a((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m32n8k16_ld_b((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m32n8k16_ld_b((int*)&a, (const int*)p, ldm, 1); + } +#endif /* __CUDA_AMPERE_MMA__ */ + + + // + // Load functions for frags of shape m8n32k16 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m8n32k16_ld_a((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m8n32k16_ld_a((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m8n32k16_ld_b((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm) { + __hmma_m8n32k16_ld_b((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __half* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m8n32k16_ld_c_f16((int*)&a, (const int*)p, ldm, 0); + else + __hmma_m8n32k16_ld_c_f16((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m8n32k16_ld_c_f32((float*)&a, (const float*)p, ldm, 0); + else + __hmma_m8n32k16_ld_c_f32((float*)&a, (const float*)p, ldm, 1); + } + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m8n32k16_ld_a_s8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m8n32k16_ld_a_s8((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m8n32k16_ld_a_u8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m8n32k16_ld_a_u8((int *)&a, (const int *)p, ldm, 1); + } + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m8n32k16_ld_b_s8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const signed char* p, unsigned ldm) { + __imma_m8n32k16_ld_b_s8((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m8n32k16_ld_b_u8((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const unsigned char* p, unsigned ldm) { + __imma_m8n32k16_ld_b_u8((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const int* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __imma_m8n32k16_ld_c((int *)&a, (const int*)p, ldm, 0); + else + __imma_m8n32k16_ld_c((int *)&a, (const int*)p, ldm, 1); + } +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m8n32k16_ld_a((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m8n32k16_ld_a((int*)&a, (const int*)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m8n32k16_ld_b((int*)&a, (const int*)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const __nv_bfloat16* p, unsigned ldm) { + __mma_bf16_m8n32k16_ld_b((int*)&a, (const int*)p, ldm, 1); + } +#endif /* __CUDA_AMPERE_MMA__ */ + + +#ifdef __CUDA_SUBBYTE_IMMA__ + // + // Load functions for frags of shape m8n8k32 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) { + __imma_m8n8k32_ld_a_s4((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) { + __imma_m8n8k32_ld_a_u4((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) { + __imma_m8n8k32_ld_b_s4((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) { + __imma_m8n8k32_ld_b_u4((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const int* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __imma_m8n8k32_ld_c((int *)&a, (const int*)p, ldm, 0); + else + __imma_m8n8k32_ld_c((int *)&a, (const int*)p, ldm, 1); + } + + // + // Load functions for frags of shape m8n8k128 + // + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) { + __bmma_m8n8k128_ld_a_b1((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const void* p, unsigned ldm) { + __bmma_m8n8k128_ld_b_b1((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const int* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __bmma_m8n8k128_ld_c((int *)&a, (const int*)p, ldm, 0); + else + __bmma_m8n8k128_ld_c((int *)&a, (const int*)p, ldm, 1); + } +#endif /* __CUDA_SUBBYTE_IMMA__ */ + + + +#ifdef __CUDA_AMPERE_MMA__ + // load functions for frags of shape m16n16k8 + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm) { + __mma_tf32_m16n16k8_ld_a((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm) { + __mma_tf32_m16n16k8_ld_a((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm) { + __mma_tf32_m16n16k8_ld_b((int *)&a, (const int *)p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm) { + __mma_tf32_m16n16k8_ld_b((int *)&a, (const int *)p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const float* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __mma_tf32_m16n16k8_ld_c((float *)&a, p, ldm, 0); + else + __mma_tf32_m16n16k8_ld_c((float *)&a, p, ldm, 1); + } + + // load functions for frags of shape m8n8k4 + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const double* p, unsigned ldm) { + __dmma_m8n8k4_ld_a((double *)&a, p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const double* p, unsigned ldm) { + __dmma_m8n8k4_ld_a((double *)&a, p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const double* p, unsigned ldm) { + __dmma_m8n8k4_ld_b((double *)&a, p, ldm, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const double* p, unsigned ldm) { + __dmma_m8n8k4_ld_b((double *)&a, p, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void load_matrix_sync(fragment& a, const double* p, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __dmma_m8n8k4_ld_c((double *)&a, p, ldm, 0); + else + __dmma_m8n8k4_ld_c((double *)&a, p, ldm, 1); + } +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // Store functions for frags of shape m16n16k16 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(__half *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m16n16k16_st_c_f16((int*)p, (int*)&a, ldm, 0); + else + __hmma_m16n16k16_st_c_f16((int*)p, (int*)&a, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(float *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m16n16k16_st_c_f32((float*)p, (float*)&a, ldm, 0); + else + __hmma_m16n16k16_st_c_f32((float*)p, (float*)&a, ldm, 1); + } + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(int *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __imma_m16n16k16_st_c_i32(p, (const int*)&a, ldm, 0); + else + __imma_m16n16k16_st_c_i32(p, (const int*)&a, ldm, 1); + } +#endif /* __CUDA_IMMA__ */ + + // + // Store functions for frags of shape m32n8k16 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(__half *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m32n8k16_st_c_f16((int*)p, (int*)&a, ldm, 0); + else + __hmma_m32n8k16_st_c_f16((int*)p, (int*)&a, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(float *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m32n8k16_st_c_f32((float*)p, (float*)&a, ldm, 0); + else + __hmma_m32n8k16_st_c_f32((float*)p, (float*)&a, ldm, 1); + } + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(int *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __imma_m32n8k16_st_c_i32(p, (const int*)&a, ldm, 0); + else + __imma_m32n8k16_st_c_i32(p, (const int*)&a, ldm, 1); + } +#endif /* __CUDA_IMMA__ */ + + // + // Store functions for frags of shape m8n32k16 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(__half *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m8n32k16_st_c_f16((int*)p, (int*)&a, ldm, 0); + else + __hmma_m8n32k16_st_c_f16((int*)p, (int*)&a, ldm, 1); + } + + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(float *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __hmma_m8n32k16_st_c_f32((float*)p, (float*)&a, ldm, 0); + else + __hmma_m8n32k16_st_c_f32((float*)p, (float*)&a, ldm, 1); + } + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(int *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __imma_m8n32k16_st_c_i32(p, (const int*)&a, ldm, 0); + else + __imma_m8n32k16_st_c_i32(p, (const int*)&a, ldm, 1); + } +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_SUBBYTE_IMMA__ + // + // Store functions for frags of shape m8n8k32 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(int *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __imma_m8n8k32_st_c_i32(p, (const int*)&a, ldm, 0); + else + __imma_m8n8k32_st_c_i32(p, (const int*)&a, ldm, 1); + } + + // + // Store functions for frags of shape m8n8k128 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(int *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __bmma_m8n8k128_st_c_i32(p, (const int*)&a, ldm, 0); + else + __bmma_m8n8k128_st_c_i32(p, (const int*)&a, ldm, 1); + } +#endif /* __CUDA_SUBBYTE_IMMA__ */ + + +#ifdef __CUDA_AMPERE_MMA__ + + // + // Store functions for frags of shape m16n16k8 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(float *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __mma_m16n16k8_st_c_f32(p, (const float*)&a, ldm, 0); + else + __mma_m16n16k8_st_c_f32(p, (const float*)&a, ldm, 1); + } + + + // + // Store functions for frags of shape m8n8k4 + // + __CUDA_MMA_DEVICE_DECL__ void store_matrix_sync(double *p, const fragment& a, unsigned ldm, layout_t layout) { + if (layout == mem_row_major) + __dmma_m8n8k4_st_c_f64(p, (const double*)&a, ldm, 0); + else + __dmma_m8n8k4_st_c_f64(p, (const double*)&a, ldm, 1); + } +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // MMA functions for shape m16n16k16 + // + // D fp16, C fp16 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 2, 0); + } + + // D fp32, C fp16 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 2, 0); + } + + // D fp32, C fp32 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 2, 0); + } + + // D fp16, C fp32 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m16n16k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 2, 0); + } + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m16n16k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 1, 1); + else + __imma_m16n16k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 1, 0); + } + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m16n16k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 3, 1); + else + __imma_m16n16k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m16n16k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 0, 1); + else + __imma_m16n16k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m16n16k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 2, 1); + else + __imma_m16n16k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 2, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m16n16k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 1, 1); + else + __imma_m16n16k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m16n16k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 3, 1); + else + __imma_m16n16k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m16n16k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 0, 1); + else + __imma_m16n16k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m16n16k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 2, 1); + else + __imma_m16n16k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int *)&c, 2, 0); + } +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m16n16k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m16n16k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m16n16k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m16n16k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 2, 0); + } +#endif /* __CUDA_AMPERE_MMA__ */ + + + // + // MMA functions for shape m32n8k16 + // + // D fp16, C fp16 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 2, 0); + } + + // D fp32, C fp16 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 2, 0); + } + + // D fp32, C fp32 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 2, 0); + } + + // D fp16, C fp32 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m32n8k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 2, 0); + } + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m32n8k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 1); + else + __imma_m32n8k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m32n8k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 3, 1); + else + __imma_m32n8k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m32n8k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 0, 1); + else + __imma_m32n8k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m32n8k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 2, 1); + else + __imma_m32n8k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 2, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m32n8k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 1); + else + __imma_m32n8k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m32n8k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 3, 1); + else + __imma_m32n8k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 3, 0); + + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m32n8k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 0, 1); + else + __imma_m32n8k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 0, 0); + + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m32n8k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 2, 1); + else + __imma_m32n8k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 2, 0); + + } +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m32n8k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m32n8k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m32n8k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m32n8k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 2, 0); + } +#endif /* __CUDA_AMPERE_MMA__ */ + + // + // MMA functions for shape m8n32k16 + // + // D fp16, C fp16 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f16f16((int*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 2, 0); + } + + // D fp32, C fp16 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f32f16((float*)&d, (const int*)&a, (const int*)&b, (const int*)&c, 2, 0); + } + + // D fp32, C fp32 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f32f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 2, 0); + } + + // D fp16, C fp32 + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __hmma_m8n32k16_mma_f16f32((int*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 2, 0); + } + +#ifdef __CUDA_IMMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m8n32k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 1); + else + __imma_m8n32k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m8n32k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 3, 1); + else + __imma_m8n32k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m8n32k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 0, 1); + else + __imma_m8n32k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m8n32k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 2, 1); + else + __imma_m8n32k16_mma_s8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 2, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m8n32k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 1); + else + __imma_m8n32k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m8n32k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 3, 1); + else + __imma_m8n32k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m8n32k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 0, 1); + else + __imma_m8n32k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m8n32k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 2, 1); + else + __imma_m8n32k16_mma_u8((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 2, 0); + } +#endif /* __CUDA_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m8n32k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m8n32k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m8n32k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_bf16_m8n32k16_mma_f32((float*)&d, (const int*)&a, (const int*)&b, (const float*)&c, 2, 0); + } +#endif /* __CUDA_AMPERE_MMA__ */ + + +#ifdef __CUDA_SUBBYTE_IMMA__ + // + // MMA functions for shape m8n8k32 + // + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m8n8k32_mma_s4((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 1); + else + __imma_m8n8k32_mma_s4((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, bool satf) { + if (satf) + __imma_m8n8k32_mma_u4((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 1); + else + __imma_m8n8k32_mma_u4((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1, 0); + } + + // + // MMA functions for shape m8n8k128 + // + __CUDA_MMA_DEVICE_DECL__ void bmma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c, + experimental::bmmaBitOp op, experimental::bmmaAccumulateOp) + { + +#ifdef __CUDA_AMPERE_MMA__ + if (op == experimental::bmmaBitOpAND) + __bmma_m8n8k128_mma_and_popc_b1((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1); + else +#endif /* __CUDA_AMPERE_MMA__ */ + __bmma_m8n8k128_mma_xor_popc_b1((int*)&d, (const int *)&a, (const int *)&b, (const int*)&c, 1); + } + + +#endif /* __CUDA_SUBBYTE_IMMA__ */ + +#ifdef __CUDA_AMPERE_MMA__ + // + // MMA functions for shape m16n16k8 + // + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_tf32_m16n16k8_mma_f32((float *)&d, (const int*)&a, (const int*)&b, (const float*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_tf32_m16n16k8_mma_f32((float *)&d, (const int*)&a, (const int*)&b, (const float*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_tf32_m16n16k8_mma_f32((float *)&d, (const int*)&a, (const int*)&b, (const float*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __mma_tf32_m16n16k8_mma_f32((float *)&d, (const int*)&a, (const int*)&b, (const float*)&c, 2, 0); + } + + + // + // MMA functions for shape m8n8k4 + // + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __dmma_m8n8k4_mma_f64((double *)&d, (const double*)&a, (const double*)&b, (const double*)&c, 1, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __dmma_m8n8k4_mma_f64((double *)&d, (const double*)&a, (const double*)&b, (const double*)&c, 3, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __dmma_m8n8k4_mma_f64((double *)&d, (const double*)&a, (const double*)&b, (const double*)&c, 0, 0); + } + + __CUDA_MMA_DEVICE_DECL__ void mma_sync(fragment& d, const fragment& a, const fragment& b, const fragment& c) { + __dmma_m8n8k4_mma_f64((double *)&d, (const double*)&a, (const double*)&b, (const double*)&c, 2, 0); + } + +#endif /* __CUDA_AMPERE_MMA__ */ + +}; +}; + +#undef __CUDA_IMMA__ +#undef __CUDA_SUBBYTE_IMMA__ +#undef __CUDA_MMA_DEVICE_DECL__ +#undef __CUDA_AMPERE_MMA__ + +#endif /* !__CUDA_ARCH__ || __CUDA_ARCH__ >= 700 */ + +#endif /* __cplusplus && __CUDACC__ */ + + +#endif /* __CUDA_MMA_HPP__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_CUDA_MMA_HPP__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_CUDA_MMA_HPP__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/nvfunctional b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/nvfunctional new file mode 100644 index 0000000000000000000000000000000000000000..5cb9ffeb9cb9f1d202cb1f5cb1d4d7e88a416475 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/nvfunctional @@ -0,0 +1,621 @@ +/* + * NVIDIA_COPYRIGHT_BEGIN + * + * Copyright (c) 2014-2018, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + * + * NVIDIA_COPYRIGHT_END + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/nvfunctional is an internal header file and must not be used directly. Please use nvfunctional instead.") +#else +#warning "crt/nvfunctional is an internal header file and must not be used directly. Please use nvfunctional instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_NV_LIBCXX_FUNCTIONAL_H__ +#endif + +#ifndef __NV_LIBCXX_FUNCTIONAL_H__ +#define __NV_LIBCXX_FUNCTIONAL_H__ + +#if __cplusplus < 201103L + #if defined(_MSC_VER) + #if _MSC_VER < 1800 + #error This library requires VS 2013 and above + #endif /* _MSC_VER < 1800 */ + #else /* !_MSC_VER */ + #error This library requires support for the ISO C++ 2011 standard + #endif /* _MSC_VER */ +#endif /* __cplusplus */ + +#if defined(_MSC_VER) + #define __NV_ALIGNOF __alignof + #define __NV_NOEXCEPT + #define __NV_CONSTEXPR +#else /* !_MSC_VER */ + #define __NV_ALIGNOF alignof + #define __NV_NOEXCEPT noexcept + #define __NV_CONSTEXPR constexpr +#endif /* _MSC_VER */ + +#include +#include +#include + +// n3290 20.8 +namespace nvstd +{ + +namespace internal { + +// D.8.1 base (deprecated) [depr.base] +template +struct unary_function +{ + typedef _Arg argument_type; + typedef _Result result_type; +}; + +template +struct binary_function +{ + typedef _Arg1 first_argument_type; + typedef _Arg2 second_argument_type; + typedef _Result result_type; +}; + +// move +template +inline __device__ __host__ +typename std::remove_reference<_T>::type&& move(_T&& __t) __NV_NOEXCEPT +{ + return static_cast::type&&>(__t); +} + +// 20.2.2 swap [utility.swap] +// swap +template::value && + std::is_move_assignable<_T>::value>::type> +inline __device__ __host__ +void swap(_T& __a, _T& __b) +#if !defined(_MSC_VER) +noexcept(std::is_nothrow_move_constructible<_T>::value && + std::is_nothrow_move_assignable<_T>::value) +#endif /* !defined(_MSC_VER) */ +{ + _T __t(internal::move(__a)); + __a = internal::move(__b); + __b = internal::move(__t); +} + +// 20.2.3 forward/move helpers [forward] +// forward +template +inline __device__ __host__ +_T&& forward(typename std::remove_reference<_T>::type& __t) __NV_NOEXCEPT +{ + return static_cast<_T&&>(__t); +} + +template +inline __device__ __host__ +_T&& forward(typename std::remove_reference<_T>::type&& __t) __NV_NOEXCEPT +{ + static_assert(!std::is_lvalue_reference<_T>::value, + "Error: __t is instantiated with an lvalue reference type"); + return static_cast<_T&&>(__t); +} + +} // namespace internal + +namespace __functional_helpers +{ + +struct __dummy_class; + +// Store small functors locally: +// a functor is legitimate to local storage if it is one of the following types: +// * member object pointer; +// * member function pointer; +// * closure type of size less than or equal to the largest size of +// the above types; +// * function pointer; +// * any callable class whose size is less than or equal to +// the largest one of the above types; +union _Small_functor_types +{ + void *__obj; + void (*__func_ptr)(); + void (__dummy_class::*mem_fn_ptr)(); +}; + +struct _Small_functor_data { + char __data[sizeof(_Small_functor_types)]; +}; + +template +struct __maybe_base_function +{ }; + +template +struct __maybe_base_function<_RetType(_T1)> + : public internal::unary_function<_T1, _RetType> +{ }; + +template +struct __maybe_base_function<_RetType(_T1, _T2)> + : public internal::binary_function<_T1, _T2, _RetType> +{ }; + +} // namespace __functional_helpers + +// 20.8.11 Polymorphic function wrappers [func.wrap] + +// 20.8.11.1 Class bad_function_call [func.wrap.badcall] +// unimplemented because of exception +// class bad_function_call : public std::exception + +// 20.8.11.2 Class template function [func.wrap.func] + +template class function; // undefined + +// Simplified version of template class function, which +// * does not support allocator_arg_t; +// * does not support target and target_type that rely on RTTI +// * does not throw bad_function_call exception on invoking a NULL target +template +class function<_RetType(_ArgTypes...)> + : public __functional_helpers::__maybe_base_function<_RetType(_ArgTypes...)> +{ + __functional_helpers::_Small_functor_data __small_functor_data; + void *__obj; + typedef _RetType(*__meta_fn_type)(void *, _ArgTypes...); + __meta_fn_type __meta_fn; + typedef void(*__cloner_type)(function &, const function &); + __cloner_type __cloner; + typedef void(*__destructor_type)(function *); + __destructor_type __destructor; + + #pragma nv_exec_check_disable + template + __device__ __host__ + __NV_CONSTEXPR bool __use_small_functor_data() const + { + return (sizeof(_F) <= sizeof(__small_functor_data) && + __NV_ALIGNOF(_F) <= __NV_ALIGNOF( + __functional_helpers::_Small_functor_types)); + } + + #pragma nv_exec_check_disable + __device__ __host__ + void* __get_small_functor_data() const + { + return (void*)(&__small_functor_data.__data[0]); + } + + #pragma nv_exec_check_disable + __device__ __host__ + bool __is_small_functor_data() const + { + return __obj == __get_small_functor_data(); + } + + #pragma nv_exec_check_disable + template + __device__ __host__ + static _F& __get_functor(void *__p) + { + return *((_F*)__p); + } + + #pragma nv_exec_check_disable + template + __device__ __host__ + static bool __is_empty_functor(const _F& /*__p*/) + { + return false; + } + + #pragma nv_exec_check_disable + template + __device__ __host__ + static bool __is_empty_functor(const _F* __p) + { + return !__p; + } + + #pragma nv_exec_check_disable + template + __device__ __host__ + static bool __is_empty_functor(const _Res _C::* __p) + { + return !__p; + } + + #pragma nv_exec_check_disable + template + __device__ __host__ + static bool __is_empty_functor(const function<_Res(_Args...)>& __p) + { + return !__p; + } + + template + struct __make_cloner + { + #pragma nv_exec_check_disable + __device__ __host__ + static void __clone_data(function &__dest, const function &__src) + { + if (__dest.__use_small_functor_data<_F>()) { + __dest.__obj = __dest.__get_small_functor_data(); + new (__dest.__obj) _F(__src.__get_functor<_F>(__src.__obj)); + } + else { + __dest.__obj = new _F(__src.__get_functor<_F>(__src.__obj)); + } + } + }; + + template + struct __make_destructor + { + #pragma nv_exec_check_disable + __device__ __host__ + static void __destruct(function *__fn) + { + if (__fn->__use_small_functor_data<_F>()) { + (__fn->__get_functor<_F>(__fn->__obj)).~_F(); + } + else { + delete (_F*)(__fn->__obj); + } + } + }; + + // We cannot simple define __make_functor in the following way: + // template + // __make_functor; + // template + // struct __make_functor<_RetType1(_ArgTypes1...), _F> + // + // because VS 2013 cannot unpack _RetType1(_ArgTypes1...) + template + struct __make_functor + { + typedef _RetType1 type; + + #pragma nv_exec_check_disable + __device__ __host__ + static _RetType1 __invoke(void *__d, _ArgTypes1... __args) + { + return __get_functor<_F>(__d)( + internal::forward<_ArgTypes1>(__args)...); + } + }; + + template + struct __make_functor<_RetType1, _M _C::*,_ArgTypes1...> + { + typedef _RetType1 type; + typedef _RetType1(*_Fn)(_ArgTypes1...); + + #pragma nv_exec_check_disable + __device__ __host__ + static _RetType1 __invoke(void *__d, _ArgTypes1... __args) + { + return __get_functor<_Fn>(__d)( + internal::forward<_ArgTypes1>(__args)...); + } + }; + +// workaround for GCC version below 4.8 +#if (__GNUC__ == 4) && (__GNUC_MINOR__ < 8) + template + struct __check_callability + : public std::integral_constant::value> + { }; +#elif defined(_MSC_VER) + // simulate VC 2013's behavior... + template + struct __check_callability1 + : public + std::integral_constant::value || + std::is_convertible< + _RetType, + typename std::result_of<_F(_ArgTypes...)>::type + >::value + > + { }; + + template + struct __check_callability + : public std::integral_constant< + bool, + !std::is_same<_F, function>::value && + __check_callability1::type>::value> + { }; +#else /* !((__GNUC__ == 4) && (__GNUC_MINOR__ < 8)) _MSC_VER */ + template ::type> + struct __check_callability + : public std::integral_constant< + bool, + !std::is_same<_F, function>::value && + std::is_convertible< _T, _RetType>::value> + { }; +#endif /* __GNUC__ == 4) && (__GNUC_MINOR__ < 8) */ + + #pragma nv_exec_check_disable + __device__ __host__ + void __destroy() + { + if (__obj) { + __destructor(this); + __obj = 0; + } + } + + #pragma nv_exec_check_disable + __device__ __host__ + void __clear() + { + __obj = 0; + __meta_fn = 0; + __cloner = 0; + __destructor = 0; + } + +public: + typedef _RetType result_type; + +/* + * These typedef(s) are derived from __maybe_base_function + * typedef T1 argument_type; // only if sizeof...(ArgTypes) == 1 and + * // the type in ArgTypes is T1 + * typedef T1 first_argument_type; // only if sizeof...(ArgTypes) == 2 and + * // ArgTypes contains T1 and T2 + * typedef T2 second_argument_type; // only if sizeof...(ArgTypes) == 2 and + * // ArgTypes contains T1 and T2 + */ + + // 20.8.11.2.1 construct/copy/destroy [func.wrap.con] + + #pragma nv_exec_check_disable + __device__ __host__ + function() __NV_NOEXCEPT + : __obj(0), __meta_fn(0), __cloner(0), __destructor(0) {} + + #pragma nv_exec_check_disable + __device__ __host__ + function(std::nullptr_t) __NV_NOEXCEPT + : __obj(0), __meta_fn(0), __cloner(0), __destructor(0) {} + + #pragma nv_exec_check_disable + __device__ __host__ + function(const function &__fn) + { + if (__fn.__obj == 0) { + __clear(); + } + else { + __meta_fn = __fn.__meta_fn; + __destructor = __fn.__destructor; + __fn.__cloner(*this, __fn); + __cloner = __fn.__cloner; + } + } + + #pragma nv_exec_check_disable + __device__ __host__ + function(function &&__fn) + { + __fn.swap(*this); + } + + // VS 2013 cannot process __check_callability type trait. + // So, we check callability using static_assert instead of + // using SFINAE such as + // template::value + // >::type> + + #pragma nv_exec_check_disable + template + __device__ __host__ + function(_F); + + // copy and swap + #pragma nv_exec_check_disable + __device__ __host__ + function& operator=(const function& __fn) + { + function(__fn).swap(*this); + return *this; + } + + #pragma nv_exec_check_disable + __device__ __host__ + function& operator=(function&& __fn) + { + function(internal::move(__fn)).swap(*this); + return *this; + } + + #pragma nv_exec_check_disable + __device__ __host__ + function& operator=(std::nullptr_t) + { + __destroy(); + return *this; + } + + #pragma nv_exec_check_disable + template + __device__ __host__ + function& + operator=(_F&& __fn) + { + static_assert(__check_callability<_F>::value, + "Unable to create functor object!"); + function(internal::forward<_F>(__fn)).swap(*this); + return *this; + } + + #pragma nv_exec_check_disable + __device__ __host__ + ~function() + { + __destroy(); + } + + // 20.8.11.2.2 function modifiers [func.wrap.func.mod] + #pragma nv_exec_check_disable + __device__ __host__ + void swap(function& __fn) __NV_NOEXCEPT + { + internal::swap(__meta_fn, __fn.__meta_fn); + internal::swap(__cloner, __fn.__cloner); + internal::swap(__destructor, __fn.__destructor); + + if (__is_small_functor_data() && __fn.__is_small_functor_data()) { + internal::swap(__small_functor_data, __fn.__small_functor_data); + } + else if (__is_small_functor_data()) { + internal::swap(__small_functor_data, __fn.__small_functor_data); + internal::swap(__obj, __fn.__obj); + __fn.__obj = __fn.__get_small_functor_data(); + } + else if (__fn.__is_small_functor_data()) { + internal::swap(__small_functor_data, __fn.__small_functor_data); + internal::swap(__obj, __fn.__obj); + __obj = __get_small_functor_data(); + } + else { + internal::swap(__obj, __fn.__obj); + } + } + + // 20.8.11.2.3 function capacity [func.wrap.func.cap] + #pragma nv_exec_check_disable + __device__ __host__ + explicit operator bool() const __NV_NOEXCEPT + { + return __obj; + } + + // 20.8.11.2.4 function invocation [func.wrap.func.inv] + // function::operator() can only be called in device code + // to avoid cross-execution space calls + #pragma nv_exec_check_disable + __device__ __host__ + _RetType operator()(_ArgTypes...) const; + +}; + +// Out-of-line definitions +#pragma nv_exec_check_disable +template +template +__device__ __host__ +function<_RetType(_ArgTypes...)>::function(_F __fn) + : __obj(0), __meta_fn(0), __cloner(0), __destructor(0) +{ + static_assert(__check_callability<_F>::value, + "Unable to construct functor object!"); + if (__is_empty_functor(__fn)) + return; + __meta_fn = &__make_functor<_RetType, _F, _ArgTypes...>::__invoke; + __cloner = &__make_cloner<_F>::__clone_data; + __destructor = &__make_destructor<_F>::__destruct; + + if (__use_small_functor_data<_F>()) { + __obj = __get_small_functor_data(); + new ((void*)__obj) _F(internal::move(__fn)); + } + else { + __obj = new _F(internal::move(__fn)); + } +} + +#pragma nv_exec_check_disable +template +__device__ __host__ +_RetType +function<_RetType(_ArgTypes...)>::operator()(_ArgTypes... __args) const +{ + return __meta_fn(__obj, internal::forward<_ArgTypes>(__args)...); +} + +// 20.8.11.2.6, Null pointer comparisons: + +#pragma nv_exec_check_disable +template +__device__ __host__ +bool operator==(const function<_R(_ArgTypes...)>& __fn, std::nullptr_t) +__NV_NOEXCEPT +{ + return !__fn; +} + +#pragma nv_exec_check_disable +template +__device__ __host__ +bool operator==(std::nullptr_t, const function<_R(_ArgTypes...)>& __fn) +__NV_NOEXCEPT +{ + return !__fn; +} + +#pragma nv_exec_check_disable +template +__device__ __host__ +bool operator!=(const function<_R(_ArgTypes...)>& __fn, std::nullptr_t) +__NV_NOEXCEPT +{ + return static_cast(__fn); +} + +#pragma nv_exec_check_disable +template +__device__ __host__ +bool operator!=(std::nullptr_t, const function<_R(_ArgTypes...)>& __fn) +__NV_NOEXCEPT +{ + return static_cast(__fn); +} + +// 20.8.11.2.7, specialized algorithms: +#pragma nv_exec_check_disable +template +__device__ __host__ +void swap(function<_R(_ArgTypes...)>& __fn1, function<_R(_ArgTypes...)>& __fn2) +{ + __fn1.swap(__fn2); +} + +} // namespace nvstd + +#undef __NV_NOEXCEPT +#undef __NV_CONSTEXPR +#undef __NV_ALIGNOF + +#endif // __NV_LIBCXX_FUNCTIONAL_H__ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_NV_LIBCXX_FUNCTIONAL_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_NV_LIBCXX_FUNCTIONAL_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_70_rt.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_70_rt.h new file mode 100644 index 0000000000000000000000000000000000000000..7a3eeb86dd29220de9861a05f8f920d82c86f23d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_70_rt.h @@ -0,0 +1,131 @@ +/* + * Copyright 2017-2018 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/sm_70_rt.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/sm_70_rt.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_70_RT_H__ +#endif + +#if !defined(__SM_70_RT_H__) +#define __SM_70_RT_H__ + +#if defined(__CUDACC_RTC__) +#define __SM_70_RT_DECL__ __host__ __device__ +#else /* !__CUDACC_RTC__ */ +#define __SM_70_RT_DECL__ static __device__ __inline__ +#endif /* __CUDACC_RTC__ */ + +#if defined(__cplusplus) && defined(__CUDACC__) + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 700 + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#include "builtin_types.h" +#include "device_types.h" +#include "host_defines.h" + +#ifndef __CUDA_ARCH__ +#define __DEF_IF_HOST { } +#else /* !__CUDA_ARCH__ */ +#define __DEF_IF_HOST ; +#endif /* __CUDA_ARCH__ */ + + +/****************************************************************************** + * match * + ******************************************************************************/ +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, unsigned value) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, int value) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, unsigned long value) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, long value) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, unsigned long long value) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, long long value) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, float value) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, double value) __DEF_IF_HOST + +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, unsigned value, int *pred) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, int value, int *pred) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, unsigned long value, int *pred) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, long value, int *pred) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, unsigned long long value, int *pred) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, long long value, int *pred) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, float value, int *pred) __DEF_IF_HOST +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, double value, int *pred) __DEF_IF_HOST + +__SM_70_RT_DECL__ void __nanosleep(unsigned int ns) __DEF_IF_HOST + +__SM_70_RT_DECL__ unsigned short int atomicCAS(unsigned short int *address, unsigned short int compare, unsigned short int val) __DEF_IF_HOST + +#endif /* !__CUDA_ARCH__ || __CUDA_ARCH__ >= 700 */ + +#endif /* __cplusplus && __CUDACC__ */ + +#undef __DEF_IF_HOST +#undef __SM_70_RT_DECL__ + +#if !defined(__CUDACC_RTC__) && defined(__CUDA_ARCH__) +#include "sm_70_rt.hpp" +#endif /* !__CUDACC_RTC__ && defined(__CUDA_ARCH__) */ + +#endif /* !__SM_70_RT_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_70_RT_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_70_RT_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_70_rt.hpp b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_70_rt.hpp new file mode 100644 index 0000000000000000000000000000000000000000..322496587325a1387e4280a509455e3ccc7caa1b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_70_rt.hpp @@ -0,0 +1,192 @@ +/* + * Copyright 2017-2021 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/sm_70_rt.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/sm_70_rt.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_70_RT_HPP__ +#endif + +#if !defined(__SM_70_RT_HPP__) +#define __SM_70_RT_HPP__ + +#if defined(__CUDACC_RTC__) +#define __SM_70_RT_DECL__ __host__ __device__ +#else /* !__CUDACC_RTC__ */ +#define __SM_70_RT_DECL__ static __device__ __inline__ +#endif /* __CUDACC_RTC__ */ + +#if defined(__cplusplus) && defined(__CUDACC__) + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 700 + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#include "builtin_types.h" +#include "device_types.h" +#include "host_defines.h" + +/******************************************************************************* +* * +* Below are implementations of SM-7.0 builtin functions which are included as * +* source (instead of being built in to the compiler) * +* * +*******************************************************************************/ + +// +// __match_any_sync +// +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, unsigned value) { + return __match32_any_sync(mask, value); +} + +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, int value) { + return __match32_any_sync(mask, value); +} + +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, unsigned long value) { + return (sizeof(long) == sizeof(long long)) ? + __match64_any_sync(mask, (unsigned long long)value): + __match32_any_sync(mask, (unsigned)value); +} + +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, long value) { + return (sizeof(long) == sizeof(long long)) ? + __match64_any_sync(mask, (unsigned long long)value): + __match32_any_sync(mask, (unsigned)value); +} + +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, unsigned long long value) { + return __match64_any_sync(mask, value); +} + +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, long long value) { + return __match64_any_sync(mask, value); +} + +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, float value) { + return __match32_any_sync(mask, __float_as_uint(value)); +} + +__SM_70_RT_DECL__ unsigned int __match_any_sync(unsigned mask, double value) { + return __match64_any_sync(mask, __double_as_longlong(value)); +} + +// +// __match_all_sync +// +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, unsigned value, int *pred) { + return __match32_all_sync(mask, value, pred); +} + +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, int value, int *pred) { + return __match32_all_sync(mask, value, pred); +} + +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, unsigned long value, int *pred) { + return (sizeof(long) == sizeof(long long)) ? + __match64_all_sync(mask, (unsigned long long)value, pred): + __match32_all_sync(mask, (unsigned)value, pred); +} + +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, long value, int *pred) { + return (sizeof(long) == sizeof(long long)) ? + __match64_all_sync(mask, (unsigned long long)value, pred): + __match32_all_sync(mask, (unsigned)value, pred); +} + +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, unsigned long long value, int *pred) { + return __match64_all_sync(mask, value, pred); +} + +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, long long value, int *pred) { + return __match64_all_sync(mask, value, pred); +} + +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, float value, int *pred) { + return __match32_all_sync(mask, __float_as_uint(value), pred); +} + +__SM_70_RT_DECL__ unsigned int __match_all_sync(unsigned mask, double value, int *pred) { + return __match64_all_sync(mask, __double_as_longlong(value), pred); +} + +__SM_70_RT_DECL__ void __nanosleep(unsigned int ns) { + asm volatile("nanosleep.u32 %0;" :: "r"(ns)); +} + + +extern "C" __device__ __device_builtin__ +unsigned short __usAtomicCAS(unsigned short *, unsigned short, unsigned short); + +__SM_70_RT_DECL__ unsigned short int atomicCAS(unsigned short int *address, unsigned short int compare, unsigned short int val) { + return __usAtomicCAS(address, compare, val); +} + + +#endif /* !__CUDA_ARCH__ || __CUDA_ARCH__ >= 700 */ + +#endif /* __cplusplus && __CUDACC__ */ + +#undef __SM_70_RT_DECL__ + +#endif /* !__SM_70_RT_HPP__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_70_RT_HPP__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_70_RT_HPP__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_80_rt.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_80_rt.h new file mode 100644 index 0000000000000000000000000000000000000000..13d1ba36c7842cb2592baf9410adde286d511aa9 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_80_rt.h @@ -0,0 +1,158 @@ +/* + * Copyright 2017-2021 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/sm_80_rt.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/sm_80_rt.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_80_RT_H__ +#endif + +#if !defined(__SM_80_RT_H__) +#define __SM_80_RT_H__ + +#if defined(__CUDACC_RTC__) +#define __SM_80_RT_DECL__ __host__ __device__ +#else /* !__CUDACC_RTC__ */ +#define __SM_80_RT_DECL__ static __device__ __inline__ +#endif /* __CUDACC_RTC__ */ + +#if defined(__cplusplus) && defined(__CUDACC__) + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 800 + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#include "builtin_types.h" +#include "device_types.h" +#include "host_defines.h" + +#ifndef __CUDA_ARCH__ +#define __DEF_IF_HOST { } +#else /* !__CUDA_ARCH__ */ +#define __DEF_IF_HOST ; +#endif /* __CUDA_ARCH__ */ + + +/****************************************************************************** + * reduce * + ******************************************************************************/ +__SM_80_RT_DECL__ unsigned __reduce_add_sync(unsigned mask, unsigned value) __DEF_IF_HOST +__SM_80_RT_DECL__ unsigned __reduce_min_sync(unsigned mask, unsigned value) __DEF_IF_HOST +__SM_80_RT_DECL__ unsigned __reduce_max_sync(unsigned mask, unsigned value) __DEF_IF_HOST + +__SM_80_RT_DECL__ int __reduce_add_sync(unsigned mask, int value) __DEF_IF_HOST +__SM_80_RT_DECL__ int __reduce_min_sync(unsigned mask, int value) __DEF_IF_HOST +__SM_80_RT_DECL__ int __reduce_max_sync(unsigned mask, int value) __DEF_IF_HOST + +__SM_80_RT_DECL__ unsigned __reduce_and_sync(unsigned mask, unsigned value) __DEF_IF_HOST +__SM_80_RT_DECL__ unsigned __reduce_or_sync(unsigned mask, unsigned value) __DEF_IF_HOST +__SM_80_RT_DECL__ unsigned __reduce_xor_sync(unsigned mask, unsigned value) __DEF_IF_HOST + + +extern "C" { +inline __device__ void *__nv_associate_access_property(const void *ptr, + unsigned long long property) { + extern __device__ void *__nv_associate_access_property_impl(const void *, + unsigned long long); + return __nv_associate_access_property_impl(ptr, property); +} + +inline __device__ void __nv_memcpy_async_shared_global_4(void *dst, + const void *src, + unsigned src_size) { + extern __device__ void __nv_memcpy_async_shared_global_4_impl(void *, + const void *, + unsigned); + __nv_memcpy_async_shared_global_4_impl(dst, src, src_size); +} + +inline __device__ void __nv_memcpy_async_shared_global_8(void *dst, + const void *src, + unsigned src_size) { + extern __device__ void __nv_memcpy_async_shared_global_8_impl(void *, + const void *, + unsigned); + __nv_memcpy_async_shared_global_8_impl(dst, src, src_size); +} + +inline __device__ void __nv_memcpy_async_shared_global_16(void *dst, + const void *src, + unsigned src_size) { + extern __device__ void __nv_memcpy_async_shared_global_16_impl(void *, + const void *, + unsigned); + __nv_memcpy_async_shared_global_16_impl(dst, src, src_size); +} + +} +#endif /* !__CUDA_ARCH__ || __CUDA_ARCH__ >= 800 */ + +#endif /* __cplusplus && __CUDACC__ */ + +#undef __DEF_IF_HOST +#undef __SM_80_RT_DECL__ + +#if !defined(__CUDACC_RTC__) && defined(__CUDA_ARCH__) +#include "sm_80_rt.hpp" +#endif /* !__CUDACC_RTC__ && defined(__CUDA_ARCH__) */ + +#endif /* !__SM_80_RT_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_80_RT_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_80_RT_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_80_rt.hpp b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_80_rt.hpp new file mode 100644 index 0000000000000000000000000000000000000000..857bd44a3bb0d8480560047a85f9059bc370b52f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_80_rt.hpp @@ -0,0 +1,148 @@ +/* + * Copyright 2017-2021 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/sm_80_rt.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/sm_80_rt.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_80_RT_HPP__ +#endif + +#if !defined(__SM_80_RT_HPP__) +#define __SM_80_RT_HPP__ + +#if defined(__CUDACC_RTC__) +#define __SM_80_RT_DECL__ __host__ __device__ +#else /* !__CUDACC_RTC__ */ +#define __SM_80_RT_DECL__ static __device__ __inline__ +#endif /* __CUDACC_RTC__ */ + +#if defined(__cplusplus) && defined(__CUDACC__) + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 800 + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#include "builtin_types.h" +#include "device_types.h" +#include "host_defines.h" + +/******************************************************************************* +* * +* Below are implementations of SM-8.0 builtin functions which are included as * +* source (instead of being built in to the compiler) * +* * +*******************************************************************************/ + +extern "C" { + __device_builtin__ __device__ unsigned __reduce_add_sync_unsigned_impl(unsigned, unsigned); + __device_builtin__ __device__ unsigned __reduce_min_sync_unsigned_impl(unsigned, unsigned); + __device_builtin__ __device__ unsigned __reduce_max_sync_unsigned_impl(unsigned, unsigned); + __device_builtin__ __device__ int __reduce_add_sync_signed_impl(unsigned, int); + __device_builtin__ __device__ int __reduce_min_sync_signed_impl(unsigned, int); + __device_builtin__ __device__ int __reduce_max_sync_signed_impl(unsigned, int); + __device_builtin__ __device__ unsigned __reduce_or_sync_unsigned_impl(unsigned, unsigned); + __device_builtin__ __device__ unsigned __reduce_and_sync_unsigned_impl(unsigned, unsigned); + __device_builtin__ __device__ unsigned __reduce_xor_sync_unsigned_impl(unsigned, unsigned); +} + +__SM_80_RT_DECL__ unsigned __reduce_add_sync(unsigned mask, unsigned value) { + return __reduce_add_sync_unsigned_impl(mask, value); +} + +__SM_80_RT_DECL__ unsigned __reduce_min_sync(unsigned mask, unsigned value) { + return __reduce_min_sync_unsigned_impl(mask, value); +} + +__SM_80_RT_DECL__ unsigned __reduce_max_sync(unsigned mask, unsigned value) { + return __reduce_max_sync_unsigned_impl(mask, value); +} + +__SM_80_RT_DECL__ int __reduce_add_sync(unsigned mask, int value) { + return __reduce_add_sync_signed_impl(mask, value); +} + +__SM_80_RT_DECL__ int __reduce_min_sync(unsigned mask, int value) { + return __reduce_min_sync_signed_impl(mask, value); +} + +__SM_80_RT_DECL__ int __reduce_max_sync(unsigned mask, int value) { + return __reduce_max_sync_signed_impl(mask, value); +} + +__SM_80_RT_DECL__ unsigned __reduce_and_sync(unsigned mask, unsigned value) { + return __reduce_and_sync_unsigned_impl(mask, value); +} + +__SM_80_RT_DECL__ unsigned __reduce_or_sync(unsigned mask, unsigned value) { + return __reduce_or_sync_unsigned_impl(mask, value); +} + +__SM_80_RT_DECL__ unsigned __reduce_xor_sync(unsigned mask, unsigned value) { + return __reduce_xor_sync_unsigned_impl(mask, value); +} +#endif /* !__CUDA_ARCH__ || __CUDA_ARCH__ >= 800 */ + +#endif /* __cplusplus && __CUDACC__ */ + +#undef __SM_80_RT_DECL__ + +#endif /* !__SM_80_RT_HPP__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_80_RT_HPP__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_80_RT_HPP__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_90_rt.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_90_rt.h new file mode 100644 index 0000000000000000000000000000000000000000..8228b5a82497d883f4ed34da0039225146f4486b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_90_rt.h @@ -0,0 +1,129 @@ +/* + * Copyright 2022 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/sm_90_rt.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/sm_90_rt.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_90_RT_H__ +#endif + +#if !defined(__SM_90_RT_H__) +#define __SM_90_RT_H__ + +#if defined(__CUDACC_RTC__) +#define __SM_90_RT_DECL__ __host__ __device__ +#else /* !__CUDACC_RTC__ */ +#define __SM_90_RT_DECL__ static __device__ __inline__ +#endif /* __CUDACC_RTC__ */ + +#if defined(__cplusplus) && defined(__CUDACC__) + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 900 + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#include "builtin_types.h" +#include "device_types.h" +#include "host_defines.h" + +#ifndef __CUDA_ARCH__ +#define __DEF_IF_HOST { } +#else /* !__CUDA_ARCH__ */ +#define __DEF_IF_HOST ; +#endif /* __CUDA_ARCH__ */ + +__SM_90_RT_DECL__ unsigned __isCtaShared(const void *ptr) __DEF_IF_HOST +__SM_90_RT_DECL__ unsigned __isClusterShared(const void *ptr) __DEF_IF_HOST +__SM_90_RT_DECL__ void *__cluster_map_shared_rank(const void *ptr, unsigned target_block_rank) __DEF_IF_HOST +__SM_90_RT_DECL__ unsigned __cluster_query_shared_rank(const void *ptr) __DEF_IF_HOST +__SM_90_RT_DECL__ uint2 __cluster_map_shared_multicast(const void *ptr, unsigned cluster_cta_mask) __DEF_IF_HOST +__SM_90_RT_DECL__ unsigned __clusterDimIsSpecified() __DEF_IF_HOST +__SM_90_RT_DECL__ dim3 __clusterDim() __DEF_IF_HOST +__SM_90_RT_DECL__ dim3 __clusterRelativeBlockIdx() __DEF_IF_HOST +__SM_90_RT_DECL__ dim3 __clusterGridDimInClusters() __DEF_IF_HOST +__SM_90_RT_DECL__ dim3 __clusterIdx() __DEF_IF_HOST +__SM_90_RT_DECL__ unsigned __clusterRelativeBlockRank() __DEF_IF_HOST +__SM_90_RT_DECL__ unsigned __clusterSizeInBlocks() __DEF_IF_HOST +__SM_90_RT_DECL__ void __cluster_barrier_arrive() __DEF_IF_HOST +__SM_90_RT_DECL__ void __cluster_barrier_arrive_relaxed() __DEF_IF_HOST +__SM_90_RT_DECL__ void __cluster_barrier_wait() __DEF_IF_HOST +__SM_90_RT_DECL__ void __threadfence_cluster() __DEF_IF_HOST + +__SM_90_RT_DECL__ float2 atomicAdd(float2 *address, float2 val) __DEF_IF_HOST +__SM_90_RT_DECL__ float2 atomicAdd_block(float2 *address, float2 val) __DEF_IF_HOST +__SM_90_RT_DECL__ float2 atomicAdd_system(float2 *address, float2 val) __DEF_IF_HOST +__SM_90_RT_DECL__ float4 atomicAdd(float4 *address, float4 val) __DEF_IF_HOST +__SM_90_RT_DECL__ float4 atomicAdd_block(float4 *address, float4 val) __DEF_IF_HOST +__SM_90_RT_DECL__ float4 atomicAdd_system(float4 *address, float4 val) __DEF_IF_HOST + +#endif /* !__CUDA_ARCH__ || __CUDA_ARCH__ >= 900 */ + +#endif /* __cplusplus && __CUDACC__ */ + +#undef __DEF_IF_HOST +#undef __SM_90_RT_DECL__ + +#if !defined(__CUDACC_RTC__) && defined(__CUDA_ARCH__) +#include "sm_90_rt.hpp" +#endif /* !__CUDACC_RTC__ && defined(__CUDA_ARCH__) */ + +#endif /* !__SM_90_RT_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_90_RT_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_90_RT_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_90_rt.hpp b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_90_rt.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4e61ac78b996fa03cadf60208bbd58f2e781f3ec --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/sm_90_rt.hpp @@ -0,0 +1,248 @@ +/* + * Copyright 2022 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO LICENSEE: + * + * This source code and/or documentation ("Licensed Deliverables") are + * subject to NVIDIA intellectual property rights under U.S. and + * international Copyright laws. + * + * These Licensed Deliverables contained herein is PROPRIETARY and + * CONFIDENTIAL to NVIDIA and is being provided under the terms and + * conditions of a form of NVIDIA software license agreement by and + * between NVIDIA and Licensee ("License Agreement") or electronically + * accepted by Licensee. Notwithstanding any terms or conditions to + * the contrary in the License Agreement, reproduction or disclosure + * of the Licensed Deliverables to any third party without the express + * written consent of NVIDIA is prohibited. + * + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE + * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS + * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. + * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED + * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, + * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE + * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY + * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THESE LICENSED DELIVERABLES. + * + * U.S. Government End Users. These Licensed Deliverables are a + * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT + * 1995), consisting of "commercial computer software" and "commercial + * computer software documentation" as such terms are used in 48 + * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government + * only as a commercial end item. Consistent with 48 C.F.R.12.212 and + * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all + * U.S. Government End Users acquire the Licensed Deliverables with + * only those rights set forth herein. + * + * Any use of the Licensed Deliverables in individual and commercial + * software must include, in the user documentation and internal + * comments to the code, the above Disclaimer and U.S. Government End + * Users Notice. + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/sm_90_rt.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/sm_90_rt.hpp is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_90_RT_HPP__ +#endif + +#if !defined(__SM_90_RT_HPP__) +#define __SM_90_RT_HPP__ + +#if defined(__CUDACC_RTC__) +#define __SM_90_RT_DECL__ __host__ __device__ +#else /* !__CUDACC_RTC__ */ +#define __SM_90_RT_DECL__ static __device__ __inline__ +#endif /* __CUDACC_RTC__ */ + +#if defined(__cplusplus) && defined(__CUDACC__) + +#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 900 + +/******************************************************************************* +* * +* * +* * +*******************************************************************************/ + +#include "builtin_types.h" +#include "device_types.h" +#include "host_defines.h" + +/******************************************************************************* +* * +* Below are implementations of SM-9.0 builtin functions which are included as * +* source (instead of being built in to the compiler) * +* * +*******************************************************************************/ +extern "C" { + __device__ unsigned __nv_isClusterShared_impl(const void *); + __device__ void * __nv_cluster_map_shared_rank_impl(const void *, unsigned); + __device__ unsigned __nv_cluster_query_shared_rank_impl(const void *); + __device__ unsigned __nv_clusterDimIsSpecifed_impl(); + __device__ void __nv_clusterDim_impl(unsigned *, unsigned *, unsigned *); + __device__ void __nv_clusterRelativeBlockIdx_impl(unsigned *, + unsigned *, unsigned *); + __device__ void __nv_clusterGridDimInClusters_impl(unsigned *, + unsigned *, unsigned *); + __device__ void __nv_clusterIdx_impl(unsigned *, unsigned *, unsigned *); + __device__ unsigned __nv_clusterRelativeBlockRank_impl(); + __device__ unsigned __nv_clusterSizeInBlocks_impl(); + __device__ void __nv_cluster_barrier_arrive_impl(); + __device__ void __nv_cluster_barrier_arrive_relaxed_impl(); + __device__ void __nv_cluster_barrier_wait_impl(); + __device__ void __nv_threadfence_cluster_impl(); + + __device__ __device_builtin__ float2 __f2AtomicAdd(float2 *, float2); + __device__ __device_builtin__ float2 __f2AtomicAdd_block(float2 *, float2); + __device__ __device_builtin__ float2 __f2AtomicAdd_system(float2 *, float2); + __device__ __device_builtin__ float4 __f4AtomicAdd(float4 *, float4); + __device__ __device_builtin__ float4 __f4AtomicAdd_block(float4 *, float4); + __device__ __device_builtin__ float4 __f4AtomicAdd_system(float4 *, float4); +} // extern "C" + +__SM_90_RT_DECL__ unsigned __isCtaShared(const void *ptr) +{ + return __isShared(ptr); +} + +__SM_90_RT_DECL__ unsigned __isClusterShared(const void *ptr) +{ + return __nv_isClusterShared_impl(ptr); +} + +__SM_90_RT_DECL__ void *__cluster_map_shared_rank(const void *ptr, + unsigned target_block_rank) +{ + return __nv_cluster_map_shared_rank_impl(ptr, target_block_rank); +} + +__SM_90_RT_DECL__ unsigned __cluster_query_shared_rank(const void *ptr) +{ + return __nv_cluster_query_shared_rank_impl(ptr); +} + +__SM_90_RT_DECL__ uint2 __cluster_map_shared_multicast(const void *ptr, + unsigned int cluster_cta_mask) +{ + return make_uint2((unsigned)__cvta_generic_to_shared(ptr), cluster_cta_mask); +} + +__SM_90_RT_DECL__ unsigned __clusterDimIsSpecified() +{ + return __nv_clusterDimIsSpecifed_impl(); +} + +__SM_90_RT_DECL__ dim3 __clusterDim() +{ + unsigned x, y, z; + __nv_clusterDim_impl(&x, &y, &z); + return dim3(x,y,z); +} + +__SM_90_RT_DECL__ dim3 __clusterRelativeBlockIdx() +{ + unsigned x, y, z; + __nv_clusterRelativeBlockIdx_impl(&x, &y, &z); + return dim3(x,y,z); +} + +__SM_90_RT_DECL__ dim3 __clusterGridDimInClusters() +{ + unsigned x, y, z; + __nv_clusterGridDimInClusters_impl(&x, &y, &z); + return dim3(x,y,z); +} + +__SM_90_RT_DECL__ dim3 __clusterIdx() +{ + unsigned x, y, z; + __nv_clusterIdx_impl(&x, &y, &z); + return dim3(x,y,z); +} + +__SM_90_RT_DECL__ unsigned __clusterRelativeBlockRank() +{ + return __nv_clusterRelativeBlockRank_impl(); +} + +__SM_90_RT_DECL__ unsigned __clusterSizeInBlocks() +{ + return __nv_clusterSizeInBlocks_impl(); +} + +__SM_90_RT_DECL__ void __cluster_barrier_arrive() +{ + __nv_cluster_barrier_arrive_impl(); +} + +__SM_90_RT_DECL__ void __cluster_barrier_arrive_relaxed() +{ + __nv_cluster_barrier_arrive_relaxed_impl(); +} + +__SM_90_RT_DECL__ void __cluster_barrier_wait() +{ + __nv_cluster_barrier_wait_impl(); +} + +__SM_90_RT_DECL__ void __threadfence_cluster() +{ + __nv_threadfence_cluster_impl(); +} + + +/* Define __PTR for atomicAdd prototypes below, undef after done */ +#if (defined(_MSC_VER) && defined(_WIN64)) || defined(__LP64__) || defined(__CUDACC_RTC__) +#define __PTR "l" +#else +#define __PTR "r" +#endif /*(defined(_MSC_VER) && defined(_WIN64)) || defined(__LP64__) || defined(__CUDACC_RTC__)*/ + +__SM_90_RT_DECL__ float2 atomicAdd(float2 *address, float2 val) { + return __f2AtomicAdd(address, val); +} + +__SM_90_RT_DECL__ float2 atomicAdd_block(float2 *address, float2 val) { + return __f2AtomicAdd_block(address, val); +} + +__SM_90_RT_DECL__ float2 atomicAdd_system(float2 *address, float2 val) { + return __f2AtomicAdd_system(address, val); +} + +__SM_90_RT_DECL__ float4 atomicAdd(float4 *address, float4 val) { + return __f4AtomicAdd(address, val); +} + +__SM_90_RT_DECL__ float4 atomicAdd_block(float4 *address, float4 val) { + return __f4AtomicAdd_block(address, val); +} + +__SM_90_RT_DECL__ float4 atomicAdd_system(float4 *address, float4 val) { + return __f4AtomicAdd_system(address, val); +} + +#endif /* !__CUDA_ARCH__ || __CUDA_ARCH__ >= 900 */ + +#endif /* __cplusplus && __CUDACC__ */ + +#undef __SM_90_RT_DECL__ + +#endif /* !__SM_90_RT_HPP__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_90_RT_HPP__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_SM_90_RT_HPP__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/storage_class.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/storage_class.h new file mode 100644 index 0000000000000000000000000000000000000000..1fb19bd46ebde4a53dfad866050fad9fb0cbd222 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/crt/storage_class.h @@ -0,0 +1,142 @@ +/* + * NVIDIA_COPYRIGHT_BEGIN + * + * Copyright (c) 2008-2018, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + * + * NVIDIA_COPYRIGHT_END + */ + +#if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__) +#if defined(_MSC_VER) +#pragma message("crt/storage_class.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead.") +#else +#warning "crt/storage_class.h is an internal header file and must not be used directly. Please use cuda_runtime_api.h or cuda_runtime.h instead." +#endif +#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#define __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_STORAGE_CLASS_H__ +#endif + +#if !defined(__STORAGE_CLASS_H__) +#define __STORAGE_CLASS_H__ + +#if !defined(__var_used__) + +#define __var_used__ + +#endif /* __var_used__ */ + +#if !defined(__loc_sc__) + +#define __loc_sc__(loc, size, sc) \ + __storage##_##sc##size##loc loc + +#endif /* !__loc_sc__ */ + +#if !defined(__storage___device__) +#define __storage___device__ static __var_used__ +#endif /* __storage___device__ */ + +#if !defined(__storage_extern__device__) +#define __storage_extern__device__ static __var_used__ +#endif /* __storage_extern__device__ */ + +#if !defined(__storage_auto__device__) +#define __storage_auto__device__ @@@ COMPILER @@@ ERROR @@@ +#endif /* __storage_auto__device__ */ + +#if !defined(__storage_static__device__) +#define __storage_static__device__ static __var_used__ +#endif /* __storage_static__device__ */ + +#if !defined(__storage___constant__) +#define __storage___constant__ static __var_used__ +#endif /* __storage___constant__ */ + +#if !defined(__storage_extern__constant__) +#define __storage_extern__constant__ static __var_used__ +#endif /* __storage_extern__constant__ */ + +#if !defined(__storage_auto__constant__) +#define __storage_auto__constant__ @@@ COMPILER @@@ ERROR @@@ +#endif /* __storage_auto__constant__ */ + +#if !defined(__storage_static__constant__) +#define __storage_static__constant__ static __var_used__ +#endif /* __storage_static__constant__ */ + +#if !defined(__storage___shared__) +#define __storage___shared__ static __var_used__ +#endif /* __storage___shared__ */ + +#if !defined(__storage_extern__shared__) +#define __storage_extern__shared__ static __var_used__ +#endif /* __storage_extern__shared__ */ + +#if !defined(__storage_auto__shared__) +#define __storage_auto__shared__ static +#endif /* __storage_auto__shared__ */ + +#if !defined(__storage_static__shared__) +#define __storage_static__shared__ static __var_used__ +#endif /* __storage_static__shared__ */ + +#if !defined(__storage__unsized__shared__) +#define __storage__unsized__shared__ @@@ COMPILER @@@ ERROR @@@ +#endif /* __storage__unsized__shared__ */ + +#if !defined(__storage_extern_unsized__shared__) +#define __storage_extern_unsized__shared__ static __var_used__ +#endif /* __storage_extern_unsized__shared__ */ + +#if !defined(__storage_auto_unsized__shared__) +#define __storage_auto_unsized__shared__ @@@ COMPILER @@@ ERROR @@@ +#endif /* __storage_auto_unsized__shared__ */ + +#if !defined(__storage_static_unsized__shared__) +#define __storage_static_unsized__shared__ @@@ COMPILER @@@ ERROR @@@ +#endif /* __storage_static_unsized__shared__ */ + +#if !defined(__storage___text__) +#define __storage___text__ static __var_used__ +#endif /* __storage___text__ */ + +#if !defined(__storage_extern__text__) +#define __storage_extern__text__ static __var_used__ +#endif /* __storage_extern__text__ */ + +#if !defined(__storage_auto__text__) +#define __storage_auto__text__ @@@ COMPILER @@@ ERROR @@@ +#endif /* __storage_auto__text__ */ + +#if !defined(__storage_static__text__) +#define __storage_static__text__ static __var_used__ +#endif /* __storage_static__text__ */ + +#if !defined(__storage___surf__) +#define __storage___surf__ static __var_used__ +#endif /* __storage___surf__ */ + +#if !defined(__storage_extern__surf__) +#define __storage_extern__surf__ static __var_used__ +#endif /* __storage_extern__surf__ */ + +#if !defined(__storage_auto__surf__) +#define __storage_auto__surf__ @@@ COMPILER @@@ ERROR @@@ +#endif /* __storage_auto__surf__ */ + +#if !defined(__storage_static__surf__) +#define __storage_static__surf__ static __var_used__ +#endif /* __storage_static__surf__ */ + +#endif /* !__STORAGE_CLASS_H__ */ + +#if defined(__UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_STORAGE_CLASS_H__) +#undef __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ +#undef __UNDEF_CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS_STORAGE_CLASS_H__ +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_adjacent_difference.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_adjacent_difference.cuh new file mode 100644 index 0000000000000000000000000000000000000000..b135fbbf53b727531059c08a44aa7644cab7816a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_adjacent_difference.cuh @@ -0,0 +1,279 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include "../config.cuh" +#include "../util_type.cuh" +#include "../util_namespace.cuh" +#include "../block/block_load.cuh" +#include "../block/block_store.cuh" +#include "../block/block_adjacent_difference.cuh" + +#include + + +CUB_NAMESPACE_BEGIN + + +template < + int _BLOCK_THREADS, + int _ITEMS_PER_THREAD = 1, + cub::BlockLoadAlgorithm _LOAD_ALGORITHM = cub::BLOCK_LOAD_DIRECT, + cub::CacheLoadModifier _LOAD_MODIFIER = cub::LOAD_LDG, + cub::BlockStoreAlgorithm _STORE_ALGORITHM = cub::BLOCK_STORE_DIRECT> +struct AgentAdjacentDifferencePolicy +{ + static constexpr int BLOCK_THREADS = _BLOCK_THREADS; + static constexpr int ITEMS_PER_THREAD = _ITEMS_PER_THREAD; + static constexpr int ITEMS_PER_TILE = BLOCK_THREADS * ITEMS_PER_THREAD; + + static constexpr cub::BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; + static constexpr cub::CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; + static constexpr cub::BlockStoreAlgorithm STORE_ALGORITHM = _STORE_ALGORITHM; +}; + +template +struct AgentDifference +{ + using LoadIt = typename THRUST_NS_QUALIFIER::cuda_cub::core::LoadIterator::type; + + using BlockLoad = typename cub::BlockLoadType::type; + using BlockStore = typename cub::BlockStoreType::type; + + using BlockAdjacentDifferenceT = + cub::BlockAdjacentDifference; + + union _TempStorage + { + typename BlockLoad::TempStorage load; + typename BlockStore::TempStorage store; + typename BlockAdjacentDifferenceT::TempStorage adjacent_difference; + }; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + static constexpr int BLOCK_THREADS = Policy::BLOCK_THREADS; + static constexpr int ITEMS_PER_THREAD = Policy::ITEMS_PER_THREAD; + static constexpr int ITEMS_PER_TILE = Policy::ITEMS_PER_TILE; + static constexpr int SHARED_MEMORY_SIZE = static_cast(sizeof(TempStorage)); + + _TempStorage &temp_storage; + InputIteratorT input_it; + LoadIt load_it; + InputT *first_tile_previous; + OutputIteratorT result; + DifferenceOpT difference_op; + OffsetT num_items; + + __device__ __forceinline__ AgentDifference(TempStorage &temp_storage, + InputIteratorT input_it, + InputT *first_tile_previous, + OutputIteratorT result, + DifferenceOpT difference_op, + OffsetT num_items) + : temp_storage(temp_storage.Alias()) + , input_it(input_it) + , load_it( + THRUST_NS_QUALIFIER::cuda_cub::core::make_load_iterator(Policy(), + input_it)) + , first_tile_previous(first_tile_previous) + , result(result) + , difference_op(difference_op) + , num_items(num_items) + {} + + template + __device__ __forceinline__ void consume_tile_impl(int num_remaining, + int tile_idx, + OffsetT tile_base) + { + InputT input[ITEMS_PER_THREAD]; + OutputT output[ITEMS_PER_THREAD]; + + if (IS_LAST_TILE) + { + // Fill last elements with the first element + // because collectives are not suffix guarded + BlockLoad(temp_storage.load) + .Load(load_it + tile_base, input, num_remaining, *(load_it + tile_base)); + } + else + { + BlockLoad(temp_storage.load).Load(load_it + tile_base, input); + } + + CTA_SYNC(); + + if (ReadLeft) + { + if (IS_FIRST_TILE) + { + if (IS_LAST_TILE) + { + BlockAdjacentDifferenceT(temp_storage.adjacent_difference) + .SubtractLeftPartialTile(input, + output, + difference_op, + num_remaining); + } + else + { + BlockAdjacentDifferenceT(temp_storage.adjacent_difference) + .SubtractLeft(input, output, difference_op); + } + } + else + { + InputT tile_prev_input = MayAlias + ? first_tile_previous[tile_idx] + : *(input_it + tile_base - 1); + + if (IS_LAST_TILE) + { + BlockAdjacentDifferenceT(temp_storage.adjacent_difference) + .SubtractLeftPartialTile(input, + output, + difference_op, + num_remaining, + tile_prev_input); + } + else + { + BlockAdjacentDifferenceT(temp_storage.adjacent_difference) + .SubtractLeft(input, output, difference_op, tile_prev_input); + } + } + } + else + { + if (IS_LAST_TILE) + { + BlockAdjacentDifferenceT(temp_storage.adjacent_difference) + .SubtractRightPartialTile(input, output, difference_op, num_remaining); + } + else + { + InputT tile_next_input = MayAlias + ? first_tile_previous[tile_idx] + : *(input_it + tile_base + ITEMS_PER_TILE); + + BlockAdjacentDifferenceT(temp_storage.adjacent_difference) + .SubtractRight(input, output, difference_op, tile_next_input); + } + } + + CTA_SYNC(); + + if (IS_LAST_TILE) + { + BlockStore(temp_storage.store) + .Store(result + tile_base, output, num_remaining); + } + else + { + BlockStore(temp_storage.store).Store(result + tile_base, output); + } + } + + template + __device__ __forceinline__ void consume_tile(int num_remaining, + int tile_idx, + OffsetT tile_base) + { + if (tile_idx == 0) + { + consume_tile_impl(num_remaining, + tile_idx, + tile_base); + } + else + { + consume_tile_impl(num_remaining, + tile_idx, + tile_base); + } + } + + __device__ __forceinline__ void Process(int tile_idx, + OffsetT tile_base) + { + OffsetT num_remaining = num_items - tile_base; + + if (num_remaining > ITEMS_PER_TILE) // not a last tile + { + consume_tile(num_remaining, tile_idx, tile_base); + } + else + { + consume_tile(num_remaining, tile_idx, tile_base); + } + } +}; + +template +struct AgentDifferenceInit +{ + static constexpr int BLOCK_THREADS = 128; + + static __device__ __forceinline__ void Process(int tile_idx, + InputIteratorT first, + InputT *result, + OffsetT num_tiles, + int items_per_tile) + { + OffsetT tile_base = static_cast(tile_idx) * items_per_tile; + + if (tile_base > 0 && tile_idx < num_tiles) + { + if (ReadLeft) + { + result[tile_idx] = first[tile_base - 1]; + } + else + { + result[tile_idx - 1] = first[tile_base]; + } + } + } +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_batch_memcpy.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_batch_memcpy.cuh new file mode 100644 index 0000000000000000000000000000000000000000..20db5bb6aecf06c83cd28242b0ab74a1e9c249d6 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_batch_memcpy.cuh @@ -0,0 +1,1206 @@ +/****************************************************************************** + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::AgentBatchMemcpy implements device-wide copying of a batch of device-accessible + * source-buffers to device-accessible destination-buffers. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ +template +__forceinline__ __device__ void LoadVectorAndFunnelShiftR(uint32_t const *aligned_ptr, + uint32_t bit_shift, + uint4 &data_out) +{ + data_out = {aligned_ptr[0], aligned_ptr[1], aligned_ptr[2], aligned_ptr[3]}; + + if (!PTR_IS_FOUR_BYTE_ALIGNED) + { + uint32_t tail = aligned_ptr[4]; + data_out.x = __funnelshift_r(data_out.x, data_out.y, bit_shift); + data_out.y = __funnelshift_r(data_out.y, data_out.z, bit_shift); + data_out.z = __funnelshift_r(data_out.z, data_out.w, bit_shift); + data_out.w = __funnelshift_r(data_out.w, tail, bit_shift); + } +} + +template +__forceinline__ __device__ void LoadVectorAndFunnelShiftR(uint32_t const *aligned_ptr, + uint32_t bit_shift, + uint2 &data_out) +{ + data_out = {aligned_ptr[0], aligned_ptr[1]}; + + if (!PTR_IS_FOUR_BYTE_ALIGNED) + { + uint32_t tail = aligned_ptr[2]; + data_out.x = __funnelshift_r(data_out.x, data_out.y, bit_shift); + data_out.y = __funnelshift_r(data_out.y, tail, bit_shift); + } +} + +template +__forceinline__ __device__ void LoadVectorAndFunnelShiftR(uint32_t const *aligned_ptr, + uint32_t bit_shift, + uint32_t &data_out) +{ + data_out = aligned_ptr[0]; + + if (!PTR_IS_FOUR_BYTE_ALIGNED) + { + uint32_t tail = aligned_ptr[1]; + data_out = __funnelshift_r(data_out, tail, bit_shift); + } +} + +/** + * @brief Loads data from \p ptr into \p data_out without requiring \p ptr to be aligned. + * @note If \p ptr isn't aligned to four bytes, the bytes from the last four-byte aligned address up + * to \p ptr are loaded too (but dropped) and, hence, need to be device-accessible. Similarly, if + * \p ptr isn't aligned to four bytes, the bytes from `(ptr + sizeof(VectorT))` up to the following + * four-byte aligned address are loaded too (but dropped), and, hence, need to be device-accessible. + * + * @tparam VectorT The vector type used for vectorized stores (i.e., one of uint4, uint2, uint32_t) + * @param ptr The pointer from which the data is supposed to be loaded + * @param data_out The vector type that stores the data loaded from \p ptr + */ +template +__forceinline__ __device__ void LoadVector(const char *ptr, VectorT &data_out) +{ + const uint32_t offset = reinterpret_cast(ptr) % 4U; + const uint32_t *aligned_ptr = reinterpret_cast(ptr - offset); + constexpr uint32_t bits_per_byte = 8U; + const uint32_t bit_shift = offset * bits_per_byte; + + // If `ptr` is aligned to four bytes, we can perform a simple uint32_t-aliased load + if (offset == 0) + { + LoadVectorAndFunnelShiftR(aligned_ptr, bit_shift, data_out); + } + // Otherwise, we need to load extra bytes and perform funnel-shifting + else + { + LoadVectorAndFunnelShiftR(aligned_ptr, bit_shift, data_out); + } +} + +/** + * @brief Helper data structure to hold information on the byte range for which we can safely + * perform vectorized copies. + * + * @tparam VectorT The vector type used for vectorized stores (i.e., one of uint4, uint2, uint32_t) + */ +template +struct PointerRange +{ + VectorT *out_begin; + VectorT *out_end; + const char *in_begin; + const char *in_end; +}; + +/** + * @brief Both `out_start_aligned` and `out_end_aligned` are indices into `out_ptr`. + * `out_start_aligned` is the first VectorT-aligned memory location after `out_ptr + 3`. + * `out_end_aligned` is the last VectorT-aligned memory location before `out_end - 4`, where out_end + * corresponds to one past the last byte to be copied. Bytes between `[out_start_aligned, + * out_end_aligned)` will be copied using VectorT. `out_ptr + 3` and `out_end - 4` are used instead + * of `out_ptr` and `out_end` to avoid `LoadVector` reading beyond data boundaries. + * + * @tparam VectorT The vector type used for vectorized stores (i.e., one of uint4, uint2, uint32_t) + * @tparam ByteOffsetT Type used to index the bytes within the buffers + * @param in_begin Pointer to the beginning of the byte range that shall be copied + * @param out_begin Pointer to the beginning of the byte range that shall be copied + * @param num_bytes Number of bytes that shall be copied + * @return The byte range that can safely be copied using vectorized stores of type VectorT + */ +template +__device__ __forceinline__ PointerRange GetAlignedPtrs(const void *in_begin, + void *out_begin, + ByteOffsetT num_bytes) +{ + // Data type size used for vectorized stores + constexpr size_t out_datatype_size = sizeof(VectorT); + // Data type size used for type-aliased loads + constexpr size_t in_datatype_size = sizeof(uint32_t); + + // char-aliased ptrs to simplify pointer arithmetic + char *out_ptr = reinterpret_cast(out_begin); + const char *in_ptr = reinterpret_cast(in_begin); + + // Number of bytes between the first VectorT-aligned address at or before out_begin and out_begin + const uint32_t alignment_offset = reinterpret_cast(out_ptr) % out_datatype_size; + + // The first VectorT-aligned address before (or at) out_begin + char *out_chars_aligned = reinterpret_cast(out_ptr - alignment_offset); + + // The number of extra bytes preceding `in_ptr` that are loaded but dropped + uint32_t in_extra_bytes = reinterpret_cast(in_ptr) % in_datatype_size; + + // The offset required by `LoadVector`: + // If the input pointer is not aligned, we load data from the last aligned address preceding the + // pointer. That is, loading up to (in_datatype_size-1) bytes before `in_ptr` + uint32_t in_offset_req = in_extra_bytes; + + // Bytes after `out_chars_aligned` to the first VectorT-aligned address at or after `out_begin` + uint32_t out_start_aligned = + CUB_QUOTIENT_CEILING(in_offset_req + alignment_offset, out_datatype_size) * out_datatype_size; + + // Compute the beginning of the aligned ranges (output and input pointers) + VectorT *out_aligned_begin = reinterpret_cast(out_chars_aligned + out_start_aligned); + const char *in_aligned_begin = in_ptr + (reinterpret_cast(out_aligned_begin) - out_ptr); + + // If the aligned range is not aligned for the input pointer, we load up to (in_datatype_size-1) + // bytes after the last byte that is copied. That is, we always load four bytes up to the next + // aligned input address at a time. E.g., if the last byte loaded is one byte past the last + // aligned address we'll also load the three bytes after that byte. + uint32_t in_extra_bytes_from_aligned = + (reinterpret_cast(in_aligned_begin) % in_datatype_size); + uint32_t in_end_padding_req = (in_datatype_size - in_extra_bytes_from_aligned) % in_datatype_size; + + // Bytes after `out_chars_aligned` to the last VectorT-aligned + // address at (or before) `out_begin` + `num_bytes` + uint32_t out_end_aligned{}; + if (in_end_padding_req + alignment_offset > num_bytes) + { + out_end_aligned = out_start_aligned; + } + else + { + out_end_aligned = (num_bytes - in_end_padding_req + alignment_offset) / out_datatype_size * + out_datatype_size; + } + + VectorT *out_aligned_end = reinterpret_cast(out_chars_aligned + out_end_aligned); + const char *in_aligned_end = in_ptr + (reinterpret_cast(out_aligned_end) - out_ptr); + + return {out_aligned_begin, out_aligned_end, in_aligned_begin, in_aligned_end}; +} + +/** + * @brief Cooperatively copies \p num_bytes from \p src to \p dest using vectorized stores of type + * \p VectorT for addresses within [dest, dest + num_bytes) that are aligned to \p VectorT. A + * byte-wise copy is used for byte-ranges that are not aligned to \p VectorT. + * + * @tparam LOGICAL_WARP_SIZE The number of threads cooperaing to copy the data; all threads within + * [0, `LOGICAL_WARP_SIZE`) must invoke this method with the same arguments + * @tparam VectorT The vector type used for vectorized stores (i.e., one of uint4, uint2, uint32_t) + * @tparam ByteOffsetT Type used to index the bytes within the buffers + * @param thread_rank The thread rank within the group that cooperates to copy the data must be + * within [0, `LOGICAL_WARP_SIZE`) + * @param dest Pointer to the memory location to copy to + * @param num_bytes Number of bytes to copy + * @param src Pointer to the memory location to copy from + */ +template +__device__ __forceinline__ void +VectorizedCopy(int32_t thread_rank, void *dest, ByteOffsetT num_bytes, const void *src) +{ + char *out_ptr = reinterpret_cast(dest); + const char *in_ptr = reinterpret_cast(src); + + // Gets the byte range that can safely be copied using vectorized stores of type VectorT + auto aligned_range = GetAlignedPtrs(src, dest, num_bytes); + + // If byte range for which we can use vectorized copies is empty -> use byte-wise copies + if (aligned_range.out_end <= aligned_range.out_begin) + { + for (ByteOffsetT ichar = thread_rank; ichar < num_bytes; ichar += LOGICAL_WARP_SIZE) + { + out_ptr[ichar] = in_ptr[ichar]; + } + } + else + { + // Copy bytes in range `[dest, aligned_range.out_begin)` + out_ptr += thread_rank; + in_ptr += thread_rank; + while (out_ptr < reinterpret_cast(aligned_range.out_begin)) + { + *out_ptr = *in_ptr; + out_ptr += LOGICAL_WARP_SIZE; + in_ptr += LOGICAL_WARP_SIZE; + } + + // Copy bytes in range `[aligned_range.out_begin, aligned_range.out_end)` + VectorT *aligned_range_begin = aligned_range.out_begin + thread_rank; + const char *in_aligned_begin = aligned_range.in_begin + thread_rank * sizeof(VectorT); + while (aligned_range_begin < aligned_range.out_end) + { + VectorT data_in; + LoadVector(in_aligned_begin, data_in); + *aligned_range_begin = data_in; + in_aligned_begin += sizeof(VectorT) * LOGICAL_WARP_SIZE; + aligned_range_begin += LOGICAL_WARP_SIZE; + } + + // Copy bytes in range `[aligned_range.out_end, dest + num_bytes)`. + out_ptr = reinterpret_cast(aligned_range.out_end) + thread_rank; + in_ptr = aligned_range.in_end + thread_rank; + while (out_ptr < reinterpret_cast(dest) + num_bytes) + { + *out_ptr = *in_ptr; + out_ptr += LOGICAL_WARP_SIZE; + in_ptr += LOGICAL_WARP_SIZE; + } + } +} + +template ::type = 0> +__device__ __forceinline__ void copy_items(InputBufferT input_buffer, + OutputBufferT output_buffer, + OffsetT num_bytes, + OffsetT offset = 0) +{ + VectorizedCopy(threadIdx.x % LOGICAL_WARP_SIZE, + &reinterpret_cast(output_buffer)[offset], + num_bytes, + &reinterpret_cast(input_buffer)[offset]); +} + +template ::type = 0> +__device__ __forceinline__ void copy_items(InputBufferT input_buffer, + OutputBufferT output_buffer, + OffsetT num_items, + OffsetT offset = 0) +{ + output_buffer += offset; + input_buffer += offset; + for (OffsetT i = threadIdx.x % LOGICAL_WARP_SIZE; i < num_items; i += LOGICAL_WARP_SIZE) + { + *(output_buffer + i) = *(input_buffer + i); + } +} + +template ::type = 0> +__device__ __forceinline__ AliasT read_item(InputIt buffer_src, OffsetT offset) +{ + return *(reinterpret_cast(buffer_src) + offset); +} + +template ::type = 0> +__device__ __forceinline__ AliasT read_item(InputIt buffer_src, OffsetT offset) +{ + return *(buffer_src + offset); +} + +template ::type = 0> +__device__ __forceinline__ void write_item(OutputIt buffer_dst, OffsetT offset, AliasT value) +{ + *(reinterpret_cast(buffer_dst) + offset) = value; +} + +template ::type = 0> +__device__ __forceinline__ void write_item(OutputIt buffer_dst, OffsetT offset, AliasT value) +{ + *(buffer_dst + offset) = value; +} + +/** + * @brief A helper class that allows threads to maintain multiple counters, where the counter that + * shall be incremented can be addressed dynamically without incurring register spillage. + * + * @tparam NUM_ITEMS The number of counters to allocate + * @tparam MAX_ITEM_VALUE The maximum count that must be supported. + * @tparam PREFER_POW2_BITS Whether the number of bits to dedicate to each counter should be a + * power-of-two. If enabled, this allows replacing integer multiplication with a bit-shift in + * exchange for higher register pressure. + * @tparam BackingUnitT The data type that is used to provide the bits of all the counters that + * shall be allocated. + */ +template +class BitPackedCounter +{ +private: + /// The minimum number of bits required to represent all values from [0, MAX_ITEM_VALUE] + static constexpr uint32_t MIN_BITS_PER_ITEM = + (MAX_ITEM_VALUE == 0U) ? 1U : cub::Log2(MAX_ITEM_VALUE + 1U)>::VALUE; + + /// The number of bits allocated for each item. For pre-Volta, we prefer a power-of-2 here to + /// have the compiler replace costly integer multiplication with bit-shifting. + static constexpr uint32_t BITS_PER_ITEM = + PREFER_POW2_BITS ? (0x01ULL << (cub::Log2(MIN_BITS_PER_ITEM)>::VALUE)) + : MIN_BITS_PER_ITEM; + + /// The number of bits that each backing data type can store + static constexpr uint32_t NUM_BITS_PER_UNIT = sizeof(BackingUnitT) * 8; + + /// The number of items that each backing data type can store + static constexpr uint32_t ITEMS_PER_UNIT = NUM_BITS_PER_UNIT / BITS_PER_ITEM; + + /// The number of bits the backing data type is actually making use of + static constexpr uint32_t USED_BITS_PER_UNIT = ITEMS_PER_UNIT * BITS_PER_ITEM; + + /// The number of backing data types required to store the given number of items + static constexpr uint32_t NUM_TOTAL_UNITS = CUB_QUOTIENT_CEILING(NUM_ITEMS, ITEMS_PER_UNIT); + + /// This is the net number of bit-storage provided by each unit (remainder bits are unused) + static constexpr uint32_t UNIT_MASK = (USED_BITS_PER_UNIT >= (8U * sizeof(uint32_t))) + ? 0xFFFFFFFF + : (0x01U << USED_BITS_PER_UNIT) - 1; + /// This is the bit-mask for each item + static constexpr uint32_t ITEM_MASK = (BITS_PER_ITEM >= (8U * sizeof(uint32_t))) + ? 0xFFFFFFFF + : (0x01U << BITS_PER_ITEM) - 1; + + //------------------------------------------------------------------------------ + // ACCESSORS + //------------------------------------------------------------------------------ +public: + __device__ __forceinline__ uint32_t Get(uint32_t index) const + { + const uint32_t target_offset = index * BITS_PER_ITEM; + uint32_t val = 0; + +#pragma unroll + for (uint32_t i = 0; i < NUM_TOTAL_UNITS; ++i) + { + // In case the bit-offset of the counter at is larger than the bit range of the + // current unit, the bit_shift amount will be larger than the bits provided by this unit. As + // C++'s bit-shift has undefined behaviour if the bits being shifted exceed the operand width, + // we use the PTX instruction `shr` to make sure behaviour is well-defined. + // Negative bit-shift amounts wrap around in unsigned integer math and are ultimately clamped. + const uint32_t bit_shift = target_offset - i * USED_BITS_PER_UNIT; + val |= detail::LogicShiftRight(data[i], bit_shift) & ITEM_MASK; + } + return val; + } + + __device__ __forceinline__ void Add(uint32_t index, uint32_t value) + { + const uint32_t target_offset = index * BITS_PER_ITEM; + +#pragma unroll + for (uint32_t i = 0; i < NUM_TOTAL_UNITS; ++i) + { + // In case the bit-offset of the counter at is larger than the bit range of the + // current unit, the bit_shift amount will be larger than the bits provided by this unit. As + // C++'s bit-shift has undefined behaviour if the bits being shifted exceed the operand width, + // we use the PTX instruction `shl` to make sure behaviour is well-defined. + // Negative bit-shift amounts wrap around in unsigned integer math and are ultimately clamped. + const uint32_t bit_shift = target_offset - i * USED_BITS_PER_UNIT; + data[i] += detail::LogicShiftLeft(value, bit_shift) & UNIT_MASK; + } + } + + __device__ BitPackedCounter operator+(const BitPackedCounter &rhs) const + { + BitPackedCounter result; +#pragma unroll + for (uint32_t i = 0; i < NUM_TOTAL_UNITS; ++i) + { + result.data[i] = data[i] + rhs.data[i]; + } + return result; + } + + //------------------------------------------------------------------------------ + // MEMBER VARIABLES + //------------------------------------------------------------------------------ +private: + BackingUnitT data[NUM_TOTAL_UNITS] = {}; +}; + +/** + * Parameterizable tuning policy type for AgentBatchMemcpy + */ +template +struct AgentBatchMemcpyPolicy +{ + /// Threads per thread block + static constexpr uint32_t BLOCK_THREADS = _BLOCK_THREADS; + /// Items per thread (per tile of input) + static constexpr uint32_t BUFFERS_PER_THREAD = _BUFFERS_PER_THREAD; + /// The number of bytes that each thread will work on with each iteration of reading in bytes + /// from one or more + // source-buffers and writing them out to the respective destination-buffers. + static constexpr uint32_t TLEV_BYTES_PER_THREAD = _TLEV_BYTES_PER_THREAD; + /// Whether the BitPackedCounter should prefer allocating a power-of-2 number of bits per + /// counter + static constexpr uint32_t PREFER_POW2_BITS = _PREFER_POW2_BITS; + /// BLEV tile size granularity + static constexpr uint32_t BLOCK_LEVEL_TILE_SIZE = _BLOCK_LEVEL_TILE_SIZE; + + static constexpr uint32_t WARP_LEVEL_THRESHOLD = _WARP_LEVEL_THRESHOLD; + static constexpr uint32_t BLOCK_LEVEL_THRESHOLD = _BLOCK_LEVEL_THRESHOLD; + + using buff_delay_constructor = BuffDelayConstructor; + using block_delay_constructor = BlockDelayConstructor; +}; + +template +class AgentBatchMemcpy +{ +private: + //--------------------------------------------------------------------- + // CONFIGS / CONSTANTS + //--------------------------------------------------------------------- + // Tuning policy-based configurations + static constexpr uint32_t BLOCK_THREADS = AgentMemcpySmallBuffersPolicyT::BLOCK_THREADS; + static constexpr uint32_t BUFFERS_PER_THREAD = AgentMemcpySmallBuffersPolicyT::BUFFERS_PER_THREAD; + static constexpr uint32_t TLEV_BYTES_PER_THREAD = + AgentMemcpySmallBuffersPolicyT::TLEV_BYTES_PER_THREAD; + static constexpr bool PREFER_POW2_BITS = AgentMemcpySmallBuffersPolicyT::PREFER_POW2_BITS; + static constexpr uint32_t BLOCK_LEVEL_TILE_SIZE = + AgentMemcpySmallBuffersPolicyT::BLOCK_LEVEL_TILE_SIZE; + + // Derived configs + static constexpr uint32_t BUFFERS_PER_BLOCK = BUFFERS_PER_THREAD * BLOCK_THREADS; + static constexpr uint32_t TLEV_BUFFERS_PER_THREAD = BUFFERS_PER_THREAD; + static constexpr uint32_t BLEV_BUFFERS_PER_THREAD = BUFFERS_PER_THREAD; + + static constexpr uint32_t WARP_LEVEL_THRESHOLD = + AgentMemcpySmallBuffersPolicyT::WARP_LEVEL_THRESHOLD; + + static constexpr uint32_t BLOCK_LEVEL_THRESHOLD = + AgentMemcpySmallBuffersPolicyT::BLOCK_LEVEL_THRESHOLD; + + static constexpr uint32_t BUFFER_STABLE_PARTITION = false; + + // Constants + enum : uint32_t + { + TLEV_SIZE_CLASS = 0, + WLEV_SIZE_CLASS, + BLEV_SIZE_CLASS, + NUM_SIZE_CLASSES, + }; + + //--------------------------------------------------------------------- + // TYPE DECLARATIONS + //--------------------------------------------------------------------- + /// Internal load/store type. For byte-wise memcpy, a single-byte type + using AliasT = typename ::cuda::std::conditional< + IsMemcpy, + std::iterator_traits, + std::iterator_traits>>::type::value_type; + + /// Types of the input and output buffers + using InputBufferT = cub::detail::value_t; + using OutputBufferT = cub::detail::value_t; + + /// Type that has to be sufficiently large to hold any of the buffers' sizes. + /// The BufferSizeIteratorT's value type must be convertible to this type. + using BufferSizeT = cub::detail::value_t; + + /// Type used to index into the tile of buffers that this thread block is assigned to. + using BlockBufferOffsetT = uint16_t; + + /// Internal type used to index into the bytes of and represent size of a TLEV buffer + using TLevBufferSizeT = uint16_t; + + /** + * @brief Helper struct to simplify BlockExchange within a single four-byte word + */ + struct ZippedTLevByteAssignment + { + // The buffer id within this tile + BlockBufferOffsetT tile_buffer_id; + + // Byte-offset within that buffer + TLevBufferSizeT buffer_byte_offset; + }; + + /** + * POD to keep track of pairs after having partitioned this tile's + * buffers by their size. + */ + struct BufferTuple + { + // Size is only valid (and relevant) for buffers that are use thread-level collaboration + TLevBufferSizeT size; + + // The buffer id relativ to this tile (i.e., the buffer id within this tile) + BlockBufferOffsetT buffer_id; + }; + + // Load buffers in a striped arrangement if we do not want to performa a stable partitioning into + // small, medium, and large buffers, otherwise load them in a blocked arrangement + using BufferLoadT = + BlockLoad(BLOCK_THREADS), + static_cast(BUFFERS_PER_THREAD), + BUFFER_STABLE_PARTITION ? BLOCK_LOAD_WARP_TRANSPOSE : BLOCK_LOAD_STRIPED>; + + // A vectorized counter that will count the number of buffers that fall into each of the + // size-classes. Where the size class representes the collaboration level that is required to + // process a buffer. The collaboration level being either: + //-> (1) TLEV (thread-level collaboration), requiring one or multiple threads but not a FULL warp + // to collaborate + //-> (2) WLEV (warp-level collaboration), requiring a full warp to collaborate on a buffer + //-> (3) BLEV (block-level collaboration), requiring one or multiple thread blocks to collaborate + // on a buffer */ + using VectorizedSizeClassCounterT = + BitPackedCounter; + + // Block-level scan used to compute the write offsets + using BlockSizeClassScanT = + cub::BlockScan(BLOCK_THREADS)>; + + // + using BlockBLevTileCountScanT = cub::BlockScan(BLOCK_THREADS)>; + + // Block-level run-length decode algorithm to evenly distribute work of all buffers requiring + // thread-level collaboration + using BlockRunLengthDecodeT = + cub::BlockRunLengthDecode(BLOCK_THREADS), + static_cast(TLEV_BUFFERS_PER_THREAD), + static_cast(TLEV_BYTES_PER_THREAD)>; + + using BlockExchangeTLevT = cub::BlockExchange(BLOCK_THREADS), + static_cast(TLEV_BYTES_PER_THREAD)>; + + using BLevBuffScanPrefixCallbackOpT = + TilePrefixCallbackOp; + + using BLevBlockScanPrefixCallbackOpT = + TilePrefixCallbackOp; + + //----------------------------------------------------------------------------- + // SHARED MEMORY DECLARATIONS + //----------------------------------------------------------------------------- + struct _TempStorage + { + union + { + typename BufferLoadT::TempStorage load_storage; + + // Stage 1: histogram over the size classes in preparation for partitioning buffers by size + typename BlockSizeClassScanT::TempStorage size_scan_storage; + + // Stage 2: Communicate the number ofer buffers requiring block-level collaboration + typename BLevBuffScanPrefixCallbackOpT::TempStorage buffer_scan_callback; + + // Stage 3; batch memcpy buffers that require only thread-level collaboration + struct + { + BufferTuple buffers_by_size_class[BUFFERS_PER_BLOCK]; + + // Stage 3.1: Write buffers requiring block-level collaboration to queue + union + { + struct + { + typename BLevBlockScanPrefixCallbackOpT::TempStorage block_scan_callback; + typename BlockBLevTileCountScanT::TempStorage block_scan_storage; + } blev; + + // Stage 3.3: run-length decode & block exchange for tlev + // rld_state needs to be persistent across loop iterations (RunLengthDecode calls) and, + // hence, cannot alias block_exchange_storage + struct + { + typename BlockRunLengthDecodeT::TempStorage rld_state; + typename BlockExchangeTLevT::TempStorage block_exchange_storage; + } tlev; + }; + } staged; + }; + BufferOffsetT blev_buffer_offset; + }; + + //----------------------------------------------------------------------------- + // PUBLIC TYPE MEMBERS + //----------------------------------------------------------------------------- +public: + struct TempStorage : Uninitialized<_TempStorage> + {}; + + //----------------------------------------------------------------------------- + // PRIVATE MEMBER FUNCTIONS + //----------------------------------------------------------------------------- +private: + /// Shared storage reference + _TempStorage &temp_storage; + + /** + * @brief Loads this tile's buffers' sizes, without any guards (i.e., out-of-bounds checks) + */ + __device__ __forceinline__ void + LoadBufferSizesFullTile(BufferSizeIteratorT tile_buffer_sizes_it, + BufferSizeT (&buffer_sizes)[BUFFERS_PER_THREAD]) + { + BufferLoadT(temp_storage.load_storage).Load(tile_buffer_sizes_it, buffer_sizes); + } + + /** + * @brief Loads this tile's buffers' sizes, making sure to read at most \p num_valid items. + */ + __device__ __forceinline__ void + LoadBufferSizesPartialTile(BufferSizeIteratorT tile_buffer_sizes_it, + BufferSizeT (&buffer_sizes)[BUFFERS_PER_THREAD], + BufferOffsetT num_valid) + { + // Out-of-bounds buffer items are initialized to '0', so those buffers will simply be ignored + // later on + constexpr BufferSizeT OOB_DEFAULT_BUFFER_SIZE = 0U; + + BufferLoadT(temp_storage.load_storage) + .Load(tile_buffer_sizes_it, buffer_sizes, num_valid, OOB_DEFAULT_BUFFER_SIZE); + } + + /** + * @brief Computes the histogram over the number of buffers belonging to each of the three + * size-classes (TLEV, WLEV, BLEV). + */ + __device__ __forceinline__ VectorizedSizeClassCounterT + GetBufferSizeClassHistogram(const BufferSizeT (&buffer_sizes)[BUFFERS_PER_THREAD]) + { + VectorizedSizeClassCounterT vectorized_counters{}; +#pragma unroll + for (uint32_t i = 0; i < BUFFERS_PER_THREAD; i++) + { + // Whether to increment ANY of the buffer size classes at all + const uint32_t increment = buffer_sizes[i] > 0 ? 1U : 0U; + // Identify the buffer's size class + uint32_t buffer_size_class = 0; + buffer_size_class += buffer_sizes[i] > WARP_LEVEL_THRESHOLD ? 1U : 0U; + buffer_size_class += buffer_sizes[i] > BLOCK_LEVEL_THRESHOLD ? 1U : 0U; + + // Increment the count of the respective size class + vectorized_counters.Add(buffer_size_class, increment); + } + return vectorized_counters; + } + + /** + * @brief Scatters the buffers into the respective buffer's size-class partition. + */ + __device__ __forceinline__ void + PartitionBuffersBySize(const BufferSizeT (&buffer_sizes)[BUFFERS_PER_THREAD], + VectorizedSizeClassCounterT &vectorized_offsets, + BufferTuple (&buffers_by_size_class)[BUFFERS_PER_BLOCK]) + { + // If we intend to perform a stable partitioning, the thread's buffer are in a blocked + // arrangement, otherwise they are in a striped arrangement + BlockBufferOffsetT buffer_id = BUFFER_STABLE_PARTITION ? (BUFFERS_PER_THREAD * threadIdx.x) + : (threadIdx.x); + constexpr BlockBufferOffsetT BUFFER_STRIDE = BUFFER_STABLE_PARTITION + ? static_cast(1) + : static_cast(BLOCK_THREADS); + +#pragma unroll + for (uint32_t i = 0; i < BUFFERS_PER_THREAD; i++) + { + if (buffer_sizes[i] > 0) + { + uint32_t buffer_size_class = 0; + buffer_size_class += buffer_sizes[i] > WARP_LEVEL_THRESHOLD ? 1U : 0U; + buffer_size_class += buffer_sizes[i] > BLOCK_LEVEL_THRESHOLD ? 1U : 0U; + const uint32_t write_offset = vectorized_offsets.Get(buffer_size_class); + buffers_by_size_class[write_offset] = {static_cast(buffer_sizes[i]), + buffer_id}; + vectorized_offsets.Add(buffer_size_class, 1U); + } + buffer_id += BUFFER_STRIDE; + } + } + + /** + * @brief Read in all the buffers that require block-level collaboration and put them to a queue + * that will get picked up in a separate, subsequent kernel. + */ + __device__ __forceinline__ void EnqueueBLEVBuffers(BufferTuple *buffers_by_size_class, + InputBufferIt tile_buffer_srcs, + OutputBufferIt tile_buffer_dsts, + BufferSizeIteratorT tile_buffer_sizes, + BlockBufferOffsetT num_blev_buffers, + BufferOffsetT tile_buffer_offset, + BufferOffsetT tile_id) + { + BlockOffsetT block_offset[BLEV_BUFFERS_PER_THREAD]; + // Read in the BLEV buffer partition (i.e., the buffers that require block-level collaboration) + uint32_t blev_buffer_offset = threadIdx.x * BLEV_BUFFERS_PER_THREAD; +#pragma unroll + for (uint32_t i = 0; i < BLEV_BUFFERS_PER_THREAD; i++) + { + if (blev_buffer_offset < num_blev_buffers) + { + BlockBufferOffsetT tile_buffer_id = buffers_by_size_class[blev_buffer_offset].buffer_id; + block_offset[i] = CUB_QUOTIENT_CEILING(tile_buffer_sizes[tile_buffer_id], + BLOCK_LEVEL_TILE_SIZE); + } + else + { + // Out-of-bounds buffers are assigned a tile count of '0' + block_offset[i] = 0U; + } + blev_buffer_offset++; + } + + if (tile_id == 0) + { + BlockOffsetT block_aggregate; + BlockBLevTileCountScanT(temp_storage.staged.blev.block_scan_storage) + .ExclusiveSum(block_offset, block_offset, block_aggregate); + if (threadIdx.x == 0) + { + blev_block_scan_state.SetInclusive(0, block_aggregate); + } + } + else + { + BLevBlockScanPrefixCallbackOpT blev_tile_prefix_op( + blev_block_scan_state, + temp_storage.staged.blev.block_scan_callback, + Sum(), + tile_id); + BlockBLevTileCountScanT(temp_storage.staged.blev.block_scan_storage) + .ExclusiveSum(block_offset, block_offset, blev_tile_prefix_op); + } + CTA_SYNC(); + + // Read in the BLEV buffer partition (i.e., the buffers that require block-level collaboration) + blev_buffer_offset = threadIdx.x * BLEV_BUFFERS_PER_THREAD; +#pragma unroll + for (uint32_t i = 0; i < BLEV_BUFFERS_PER_THREAD; i++) + { + if (blev_buffer_offset < num_blev_buffers) + { + BlockBufferOffsetT tile_buffer_id = buffers_by_size_class[blev_buffer_offset].buffer_id; + blev_buffer_srcs[tile_buffer_offset + blev_buffer_offset] = + tile_buffer_srcs[tile_buffer_id]; + blev_buffer_dsts[tile_buffer_offset + blev_buffer_offset] = + tile_buffer_dsts[tile_buffer_id]; + blev_buffer_sizes[tile_buffer_offset + blev_buffer_offset] = + tile_buffer_sizes[tile_buffer_id]; + blev_buffer_tile_offsets[tile_buffer_offset + blev_buffer_offset] = block_offset[i]; + blev_buffer_offset++; + } + } + } + + /** + * @brief Read in all the buffers of this tile that require warp-level collaboration and copy + * their bytes to the corresponding destination buffer + */ + __device__ __forceinline__ void BatchMemcpyWLEVBuffers(BufferTuple *buffers_by_size_class, + InputBufferIt tile_buffer_srcs, + OutputBufferIt tile_buffer_dsts, + BufferSizeIteratorT tile_buffer_sizes, + BlockBufferOffsetT num_wlev_buffers) + { + const int32_t warp_id = threadIdx.x / CUB_PTX_WARP_THREADS; + constexpr uint32_t WARPS_PER_BLOCK = BLOCK_THREADS / CUB_PTX_WARP_THREADS; + + for (BlockBufferOffsetT buffer_offset = warp_id; buffer_offset < num_wlev_buffers; + buffer_offset += WARPS_PER_BLOCK) + { + const auto buffer_id = buffers_by_size_class[buffer_offset].buffer_id; + copy_items( + tile_buffer_srcs[buffer_id], + tile_buffer_dsts[buffer_id], + tile_buffer_sizes[buffer_id]); + } + } + + /** + * @brief Read in all the buffers of this tile that require thread-level collaboration and copy + * their bytes to the corresponding destination buffer + */ + __device__ __forceinline__ void BatchMemcpyTLEVBuffers(BufferTuple *buffers_by_size_class, + InputBufferIt tile_buffer_srcs, + OutputBufferIt tile_buffer_dsts, + BlockBufferOffsetT num_tlev_buffers) + { + // Read in the buffers' ids that require thread-level collaboration (where buffer id is the + // buffer within this tile) + BlockBufferOffsetT tlev_buffer_ids[TLEV_BUFFERS_PER_THREAD]; + TLevBufferSizeT tlev_buffer_sizes[TLEV_BUFFERS_PER_THREAD]; + // Currently we do not go over the TLEV buffers in multiple iterations, so we need to make sure + // we are able to be covered for the case that all our buffers are TLEV buffers + static_assert(TLEV_BUFFERS_PER_THREAD >= BUFFERS_PER_THREAD, + "Unsupported confiugraiton: The number of 'thread-level buffers' must be at " + "least as large as the number of overall buffers being processed by each " + "thread."); + + // Read in the TLEV buffer partition (i.e., the buffers that require thread-level collaboration) + uint32_t tlev_buffer_offset = threadIdx.x * TLEV_BUFFERS_PER_THREAD; + + // Pre-populate the buffer sizes to 0 (i.e. zero-padding towards the end) to ensure + // out-of-bounds TLEV buffers will not be considered +#pragma unroll + for (uint32_t i = 0; i < TLEV_BUFFERS_PER_THREAD; i++) + { + tlev_buffer_sizes[i] = 0; + } + + // Assign TLEV buffers in a blocked arrangement (each thread is assigned consecutive TLEV + // buffers) +#pragma unroll + for (uint32_t i = 0; i < TLEV_BUFFERS_PER_THREAD; i++) + { + if (tlev_buffer_offset < num_tlev_buffers) + { + tlev_buffer_ids[i] = buffers_by_size_class[tlev_buffer_offset].buffer_id; + tlev_buffer_sizes[i] = buffers_by_size_class[tlev_buffer_offset].size; + } + tlev_buffer_offset++; + } + + // Evenly distribute all the bytes that have to be copied from all the buffers that require + // thread-level collaboration using BlockRunLengthDecode + uint32_t num_total_tlev_bytes = 0U; + BlockRunLengthDecodeT block_run_length_decode(temp_storage.staged.tlev.rld_state, + tlev_buffer_ids, + tlev_buffer_sizes, + num_total_tlev_bytes); + + // Run-length decode the buffers' sizes into a window buffer of limited size. This is repeated + // until we were able to cover all the bytes of TLEV buffers + uint32_t decoded_window_offset = 0U; + while (decoded_window_offset < num_total_tlev_bytes) + { + BlockBufferOffsetT buffer_id[TLEV_BYTES_PER_THREAD]; + TLevBufferSizeT buffer_byte_offset[TLEV_BYTES_PER_THREAD]; + + // Now we have a balanced assignment: buffer_id[i] will hold the tile's buffer id and + // buffer_byte_offset[i] that buffer's byte that this thread supposed to copy + block_run_length_decode.RunLengthDecode(buffer_id, buffer_byte_offset, decoded_window_offset); + + // Zip from SoA to AoS + ZippedTLevByteAssignment zipped_byte_assignment[TLEV_BYTES_PER_THREAD]; +#pragma unroll + for (int32_t i = 0; i < TLEV_BYTES_PER_THREAD; i++) + { + zipped_byte_assignment[i] = {buffer_id[i], buffer_byte_offset[i]}; + } + + // Exchange from blocked to striped arrangement for coalesced memory reads and writes + BlockExchangeTLevT(temp_storage.staged.tlev.block_exchange_storage) + .BlockedToStriped(zipped_byte_assignment, zipped_byte_assignment); + + // Read in the bytes that this thread is assigned to + constexpr uint32_t WINDOW_SIZE = (TLEV_BYTES_PER_THREAD * BLOCK_THREADS); + const bool is_full_window = decoded_window_offset + WINDOW_SIZE < num_total_tlev_bytes; + if (is_full_window) + { + uint32_t absolute_tlev_byte_offset = decoded_window_offset + threadIdx.x; + AliasT src_byte[TLEV_BYTES_PER_THREAD]; +#pragma unroll + for (int32_t i = 0; i < TLEV_BYTES_PER_THREAD; i++) + { + src_byte[i] = read_item( + tile_buffer_srcs[zipped_byte_assignment[i].tile_buffer_id], + zipped_byte_assignment[i].buffer_byte_offset); + absolute_tlev_byte_offset += BLOCK_THREADS; + } +#pragma unroll + for (int32_t i = 0; i < TLEV_BYTES_PER_THREAD; i++) + { + write_item( + tile_buffer_dsts[zipped_byte_assignment[i].tile_buffer_id], + zipped_byte_assignment[i].buffer_byte_offset, + src_byte[i]); + } + } + else + { + uint32_t absolute_tlev_byte_offset = decoded_window_offset + threadIdx.x; +#pragma unroll + for (int32_t i = 0; i < TLEV_BYTES_PER_THREAD; i++) + { + if (absolute_tlev_byte_offset < num_total_tlev_bytes) + { + const AliasT src_byte = read_item( + tile_buffer_srcs[zipped_byte_assignment[i].tile_buffer_id], + zipped_byte_assignment[i].buffer_byte_offset); + write_item( + tile_buffer_dsts[zipped_byte_assignment[i].tile_buffer_id], + zipped_byte_assignment[i].buffer_byte_offset, + src_byte); + } + absolute_tlev_byte_offset += BLOCK_THREADS; + } + } + + decoded_window_offset += WINDOW_SIZE; + + // Ensure all threads finished collaborative BlockExchange so temporary storage can be reused + // with next iteration + CTA_SYNC(); + } + } + + //----------------------------------------------------------------------------- + // PUBLIC MEMBER FUNCTIONS + //----------------------------------------------------------------------------- +public: + __device__ __forceinline__ void ConsumeTile(BufferOffsetT tile_id) + { + // Offset into this tile's buffers + BufferOffsetT buffer_offset = tile_id * BUFFERS_PER_BLOCK; + + // Indicates whether all of this tiles items are within bounds + bool is_full_tile = buffer_offset + BUFFERS_PER_BLOCK < num_buffers; + + // Load the buffer sizes of this tile's buffers + BufferSizeIteratorT tile_buffer_sizes_it = buffer_sizes_it + buffer_offset; + BufferSizeT buffer_sizes[BUFFERS_PER_THREAD]; + if (is_full_tile) + { + LoadBufferSizesFullTile(tile_buffer_sizes_it, buffer_sizes); + } + else + { + LoadBufferSizesPartialTile(tile_buffer_sizes_it, buffer_sizes, num_buffers - buffer_offset); + } + + // Ensure we can repurpose the BlockLoad's temporary storage + CTA_SYNC(); + + // Count how many buffers fall into each size-class + VectorizedSizeClassCounterT size_class_histogram = GetBufferSizeClassHistogram(buffer_sizes); + + // Compute the prefix sum over the histogram + VectorizedSizeClassCounterT size_class_agg = {}; + BlockSizeClassScanT(temp_storage.size_scan_storage) + .ExclusiveSum(size_class_histogram, size_class_histogram, size_class_agg); + + // Ensure we can repurpose the scan's temporary storage for scattering the buffer ids + CTA_SYNC(); + + // Factor in the per-size-class counts / offsets + // That is, WLEV buffer offset has to be offset by the TLEV buffer count and BLEV buffer offset + // has to be offset by the TLEV+WLEV buffer count + uint32_t buffer_count = 0U; + for (uint32_t i = 0; i < NUM_SIZE_CLASSES; i++) + { + size_class_histogram.Add(i, buffer_count); + buffer_count += size_class_agg.Get(i); + } + + // Signal the number of BLEV buffers we're planning to write out + BufferOffsetT buffer_exclusive_prefix = 0; + if (tile_id == 0) + { + if (threadIdx.x == 0) + { + blev_buffer_scan_state.SetInclusive(tile_id, size_class_agg.Get(BLEV_SIZE_CLASS)); + } + buffer_exclusive_prefix = 0; + } + else + { + BLevBuffScanPrefixCallbackOpT blev_buffer_prefix_op(blev_buffer_scan_state, + temp_storage.buffer_scan_callback, + Sum(), + tile_id); + + // Signal our partial prefix and wait for the inclusive prefix of previous tiles + if (threadIdx.x < CUB_PTX_WARP_THREADS) + { + buffer_exclusive_prefix = blev_buffer_prefix_op(size_class_agg.Get(BLEV_SIZE_CLASS)); + } + } + if (threadIdx.x == 0) + { + temp_storage.blev_buffer_offset = buffer_exclusive_prefix; + } + + // Ensure the prefix callback has finished using its temporary storage and that it can be reused + // in the next stage + CTA_SYNC(); + + // Scatter the buffers into one of the three partitions (TLEV, WLEV, BLEV) depending on their + // size + PartitionBuffersBySize(buffer_sizes, + size_class_histogram, + temp_storage.staged.buffers_by_size_class); + + // Ensure all buffers have been partitioned by their size class AND + // ensure that blev_buffer_offset has been written to shared memory + CTA_SYNC(); + + // TODO: think about prefetching tile_buffer_{srcs,dsts} into shmem + InputBufferIt tile_buffer_srcs = input_buffer_it + buffer_offset; + OutputBufferIt tile_buffer_dsts = output_buffer_it + buffer_offset; + BufferSizeIteratorT tile_buffer_sizes = buffer_sizes_it + buffer_offset; + + // Copy block-level buffers + EnqueueBLEVBuffers( + &temp_storage.staged.buffers_by_size_class[size_class_agg.Get(TLEV_SIZE_CLASS) + + size_class_agg.Get(WLEV_SIZE_CLASS)], + tile_buffer_srcs, + tile_buffer_dsts, + tile_buffer_sizes, + size_class_agg.Get(BLEV_SIZE_CLASS), + temp_storage.blev_buffer_offset, + tile_id); + + // Ensure we can repurpose the temporary storage required by EnqueueBLEVBuffers + CTA_SYNC(); + + // Copy warp-level buffers + BatchMemcpyWLEVBuffers( + &temp_storage.staged.buffers_by_size_class[size_class_agg.Get(TLEV_SIZE_CLASS)], + tile_buffer_srcs, + tile_buffer_dsts, + tile_buffer_sizes, + size_class_agg.Get(WLEV_SIZE_CLASS)); + + // Perform batch memcpy for all the buffers that require thread-level collaboration + uint32_t num_tlev_buffers = size_class_agg.Get(TLEV_SIZE_CLASS); + BatchMemcpyTLEVBuffers(temp_storage.staged.buffers_by_size_class, + tile_buffer_srcs, + tile_buffer_dsts, + num_tlev_buffers); + } + + //----------------------------------------------------------------------------- + // CONSTRUCTOR + //----------------------------------------------------------------------------- + __device__ __forceinline__ AgentBatchMemcpy(TempStorage &temp_storage, + InputBufferIt input_buffer_it, + OutputBufferIt output_buffer_it, + BufferSizeIteratorT buffer_sizes_it, + BufferOffsetT num_buffers, + BlevBufferSrcsOutItT blev_buffer_srcs, + BlevBufferDstsOutItT blev_buffer_dsts, + BlevBufferSizesOutItT blev_buffer_sizes, + BlevBufferTileOffsetsOutItT blev_buffer_tile_offsets, + BLevBufferOffsetTileState blev_buffer_scan_state, + BLevBlockOffsetTileState blev_block_scan_state) + : temp_storage(temp_storage.Alias()) + , input_buffer_it(input_buffer_it) + , output_buffer_it(output_buffer_it) + , buffer_sizes_it(buffer_sizes_it) + , num_buffers(num_buffers) + , blev_buffer_srcs(blev_buffer_srcs) + , blev_buffer_dsts(blev_buffer_dsts) + , blev_buffer_sizes(blev_buffer_sizes) + , blev_buffer_tile_offsets(blev_buffer_tile_offsets) + , blev_buffer_scan_state(blev_buffer_scan_state) + , blev_block_scan_state(blev_block_scan_state) + {} + +private: + // Iterator providing the pointers to the source memory buffers + InputBufferIt input_buffer_it; + // Iterator providing the pointers to the destination memory buffers + OutputBufferIt output_buffer_it; + // Iterator providing the number of bytes to be copied for each pair of buffers + BufferSizeIteratorT buffer_sizes_it; + // The total number of buffer pairs + BufferOffsetT num_buffers; + // Output iterator to which the source pointers of the BLEV buffers are written + BlevBufferSrcsOutItT blev_buffer_srcs; + // Output iterator to which the destination pointers of the BLEV buffers are written + BlevBufferDstsOutItT blev_buffer_dsts; + // Output iterator to which the number of bytes to be copied of the BLEV buffers are written + BlevBufferSizesOutItT blev_buffer_sizes; + // Output iterator to which the mapping of tiles to BLEV buffers is written + BlevBufferTileOffsetsOutItT blev_buffer_tile_offsets; + // The single-pass prefix scan's tile state used for tracking the prefix sum over the number of + // BLEV buffers + BLevBufferOffsetTileState blev_buffer_scan_state; + // The single-pass prefix scan's tile state used for tracking the prefix sum over tiles of BLEV + // buffers + BLevBlockOffsetTileState blev_block_scan_state; +}; + +} // namespace detail + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_histogram.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_histogram.cuh new file mode 100644 index 0000000000000000000000000000000000000000..f9770bd7158ff28ccff0ad8ac9176936a02086c6 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_histogram.cuh @@ -0,0 +1,809 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::AgentHistogram implements a stateful abstraction of CUDA thread blocks for participating in device-wide histogram . + */ + +#pragma once + +#include + +#include "../util_type.cuh" +#include "../block/block_load.cuh" +#include "../config.cuh" +#include "../grid/grid_queue.cuh" +#include "../iterator/cache_modified_input_iterator.cuh" + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Tuning policy + ******************************************************************************/ + +/** + * + */ +enum BlockHistogramMemoryPreference +{ + GMEM, + SMEM, + BLEND +}; + + +/** + * Parameterizable tuning policy type for AgentHistogram + */ +template < + int _BLOCK_THREADS, ///< Threads per thread block + int _PIXELS_PER_THREAD, ///< Pixels per thread (per tile of input) + BlockLoadAlgorithm _LOAD_ALGORITHM, ///< The BlockLoad algorithm to use + CacheLoadModifier _LOAD_MODIFIER, ///< Cache load modifier for reading input elements + bool _RLE_COMPRESS, ///< Whether to perform localized RLE to compress samples before histogramming + BlockHistogramMemoryPreference _MEM_PREFERENCE, ///< Whether to prefer privatized shared-memory bins (versus privatized global-memory bins) + bool _WORK_STEALING, ///< Whether to dequeue tiles from a global work queue + int _VEC_SIZE = 4> ///< Vector size for samples loading (1, 2, 4) +struct AgentHistogramPolicy +{ + enum + { + BLOCK_THREADS = _BLOCK_THREADS, ///< Threads per thread block + PIXELS_PER_THREAD = _PIXELS_PER_THREAD, ///< Pixels per thread (per tile of input) + IS_RLE_COMPRESS = _RLE_COMPRESS, ///< Whether to perform localized RLE to compress samples before histogramming + MEM_PREFERENCE = _MEM_PREFERENCE, ///< Whether to prefer privatized shared-memory bins (versus privatized global-memory bins) + IS_WORK_STEALING = _WORK_STEALING, ///< Whether to dequeue tiles from a global work queue + }; + + static constexpr int VEC_SIZE = _VEC_SIZE; ///< Vector size for samples loading (1, 2, 4) + + static const BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; ///< The BlockLoad algorithm to use + static const CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; ///< Cache load modifier for reading input elements +}; + + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + +/** + * \brief AgentHistogram implements a stateful abstraction of CUDA thread blocks for participating in device-wide histogram . + */ +template < + typename AgentHistogramPolicyT, ///< Parameterized AgentHistogramPolicy tuning policy type + int PRIVATIZED_SMEM_BINS, ///< Number of privatized shared-memory histogram bins of any channel. Zero indicates privatized counters to be maintained in device-accessible memory. + int NUM_CHANNELS, ///< Number of channels interleaved in the input data. Supports up to four channels. + int NUM_ACTIVE_CHANNELS, ///< Number of channels actively being histogrammed + typename SampleIteratorT, ///< Random-access input iterator type for reading samples + typename CounterT, ///< Integer type for counting sample occurrences per histogram bin + typename PrivatizedDecodeOpT, ///< The transform operator type for determining privatized counter indices from samples, one for each channel + typename OutputDecodeOpT, ///< The transform operator type for determining output bin-ids from privatized counter indices, one for each channel + typename OffsetT, ///< Signed integer type for global offsets + int LEGACY_PTX_ARCH = 0> ///< PTX compute capability (unused) +struct AgentHistogram +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + /// The sample type of the input iterator + using SampleT = cub::detail::value_t; + + /// The pixel type of SampleT + using PixelT = typename CubVector::Type; + + /// The vec type of SampleT + static constexpr int VecSize = AgentHistogramPolicyT::VEC_SIZE; + using VecT = typename CubVector::Type; + + /// Constants + enum + { + BLOCK_THREADS = AgentHistogramPolicyT::BLOCK_THREADS, + + PIXELS_PER_THREAD = AgentHistogramPolicyT::PIXELS_PER_THREAD, + SAMPLES_PER_THREAD = PIXELS_PER_THREAD * NUM_CHANNELS, + VECS_PER_THREAD = SAMPLES_PER_THREAD / VecSize, + + TILE_PIXELS = PIXELS_PER_THREAD * BLOCK_THREADS, + TILE_SAMPLES = SAMPLES_PER_THREAD * BLOCK_THREADS, + + IS_RLE_COMPRESS = AgentHistogramPolicyT::IS_RLE_COMPRESS, + + MEM_PREFERENCE = (PRIVATIZED_SMEM_BINS > 0) ? + AgentHistogramPolicyT::MEM_PREFERENCE : + GMEM, + + IS_WORK_STEALING = AgentHistogramPolicyT::IS_WORK_STEALING, + }; + + /// Cache load modifier for reading input elements + static const CacheLoadModifier LOAD_MODIFIER = AgentHistogramPolicyT::LOAD_MODIFIER; + + + /// Input iterator wrapper type (for applying cache modifier) + // Wrap the native input pointer with CacheModifiedInputIterator + // or directly use the supplied input iterator type + using WrappedSampleIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + SampleIteratorT>; + + /// Pixel input iterator type (for applying cache modifier) + typedef CacheModifiedInputIterator + WrappedPixelIteratorT; + + /// Qaud input iterator type (for applying cache modifier) + typedef CacheModifiedInputIterator + WrappedVecsIteratorT; + + /// Parameterized BlockLoad type for samples + typedef BlockLoad< + SampleT, + BLOCK_THREADS, + SAMPLES_PER_THREAD, + AgentHistogramPolicyT::LOAD_ALGORITHM> + BlockLoadSampleT; + + /// Parameterized BlockLoad type for pixels + typedef BlockLoad< + PixelT, + BLOCK_THREADS, + PIXELS_PER_THREAD, + AgentHistogramPolicyT::LOAD_ALGORITHM> + BlockLoadPixelT; + + /// Parameterized BlockLoad type for vecs + typedef BlockLoad< + VecT, + BLOCK_THREADS, + VECS_PER_THREAD, + AgentHistogramPolicyT::LOAD_ALGORITHM> + BlockLoadVecT; + + /// Shared memory type required by this thread block + struct _TempStorage + { + CounterT histograms[NUM_ACTIVE_CHANNELS][PRIVATIZED_SMEM_BINS + 1]; // Smem needed for block-privatized smem histogram (with 1 word of padding) + + int tile_idx; + + // Aliasable storage layout + union Aliasable + { + typename BlockLoadSampleT::TempStorage sample_load; // Smem needed for loading a tile of samples + typename BlockLoadPixelT::TempStorage pixel_load; // Smem needed for loading a tile of pixels + typename BlockLoadVecT::TempStorage vec_load; // Smem needed for loading a tile of vecs + + } aliasable; + }; + + + /// Temporary storage type (unionable) + struct TempStorage : Uninitialized<_TempStorage> {}; + + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + /// Reference to temp_storage + _TempStorage &temp_storage; + + /// Sample input iterator (with cache modifier applied, if possible) + WrappedSampleIteratorT d_wrapped_samples; + + /// Native pointer for input samples (possibly NULL if unavailable) + SampleT* d_native_samples; + + /// The number of output bins for each channel + int (&num_output_bins)[NUM_ACTIVE_CHANNELS]; + + /// The number of privatized bins for each channel + int (&num_privatized_bins)[NUM_ACTIVE_CHANNELS]; + + /// Reference to gmem privatized histograms for each channel + CounterT* d_privatized_histograms[NUM_ACTIVE_CHANNELS]; + + /// Reference to final output histograms (gmem) + CounterT* (&d_output_histograms)[NUM_ACTIVE_CHANNELS]; + + /// The transform operator for determining output bin-ids from privatized counter indices, one for each channel + OutputDecodeOpT (&output_decode_op)[NUM_ACTIVE_CHANNELS]; + + /// The transform operator for determining privatized counter indices from samples, one for each channel + PrivatizedDecodeOpT (&privatized_decode_op)[NUM_ACTIVE_CHANNELS]; + + /// Whether to prefer privatized smem counters vs privatized global counters + bool prefer_smem; + + + //--------------------------------------------------------------------- + // Initialize privatized bin counters + //--------------------------------------------------------------------- + + // Initialize privatized bin counters + __device__ __forceinline__ void InitBinCounters(CounterT* privatized_histograms[NUM_ACTIVE_CHANNELS]) + { + // Initialize histogram bin counts to zeros + #pragma unroll + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + for (int privatized_bin = threadIdx.x; privatized_bin < num_privatized_bins[CHANNEL]; privatized_bin += BLOCK_THREADS) + { + privatized_histograms[CHANNEL][privatized_bin] = 0; + } + } + + // Barrier to make sure all threads are done updating counters + CTA_SYNC(); + } + + + // Initialize privatized bin counters. Specialized for privatized shared-memory counters + __device__ __forceinline__ void InitSmemBinCounters() + { + CounterT* privatized_histograms[NUM_ACTIVE_CHANNELS]; + + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + privatized_histograms[CHANNEL] = temp_storage.histograms[CHANNEL]; + + InitBinCounters(privatized_histograms); + } + + + // Initialize privatized bin counters. Specialized for privatized global-memory counters + __device__ __forceinline__ void InitGmemBinCounters() + { + InitBinCounters(d_privatized_histograms); + } + + + //--------------------------------------------------------------------- + // Update final output histograms + //--------------------------------------------------------------------- + + // Update final output histograms from privatized histograms + __device__ __forceinline__ void StoreOutput(CounterT* privatized_histograms[NUM_ACTIVE_CHANNELS]) + { + // Barrier to make sure all threads are done updating counters + CTA_SYNC(); + + // Apply privatized bin counts to output bin counts + #pragma unroll + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + int channel_bins = num_privatized_bins[CHANNEL]; + for (int privatized_bin = threadIdx.x; + privatized_bin < channel_bins; + privatized_bin += BLOCK_THREADS) + { + int output_bin = -1; + CounterT count = privatized_histograms[CHANNEL][privatized_bin]; + bool is_valid = count > 0; + + output_decode_op[CHANNEL].template BinSelect((SampleT) privatized_bin, output_bin, is_valid); + + if (output_bin >= 0) + { + atomicAdd(&d_output_histograms[CHANNEL][output_bin], count); + } + + } + } + } + + + // Update final output histograms from privatized histograms. Specialized for privatized shared-memory counters + __device__ __forceinline__ void StoreSmemOutput() + { + CounterT* privatized_histograms[NUM_ACTIVE_CHANNELS]; + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + privatized_histograms[CHANNEL] = temp_storage.histograms[CHANNEL]; + + StoreOutput(privatized_histograms); + } + + + // Update final output histograms from privatized histograms. Specialized for privatized global-memory counters + __device__ __forceinline__ void StoreGmemOutput() + { + StoreOutput(d_privatized_histograms); + } + + + //--------------------------------------------------------------------- + // Tile accumulation + //--------------------------------------------------------------------- + + // Accumulate pixels. Specialized for RLE compression. + __device__ __forceinline__ void AccumulatePixels( + SampleT samples[PIXELS_PER_THREAD][NUM_CHANNELS], + bool is_valid[PIXELS_PER_THREAD], + CounterT* privatized_histograms[NUM_ACTIVE_CHANNELS], + Int2Type is_rle_compress) + { + #pragma unroll + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + // Bin pixels + int bins[PIXELS_PER_THREAD]; + + #pragma unroll + for (int PIXEL = 0; PIXEL < PIXELS_PER_THREAD; ++PIXEL) + { + bins[PIXEL] = -1; + privatized_decode_op[CHANNEL].template BinSelect(samples[PIXEL][CHANNEL], bins[PIXEL], is_valid[PIXEL]); + } + + CounterT accumulator = 1; + + #pragma unroll + for (int PIXEL = 0; PIXEL < PIXELS_PER_THREAD - 1; ++PIXEL) + { + if (bins[PIXEL] != bins[PIXEL + 1]) + { + if (bins[PIXEL] >= 0) + atomicAdd(privatized_histograms[CHANNEL] + bins[PIXEL], accumulator); + + accumulator = 0; + } + accumulator++; + } + + // Last pixel + if (bins[PIXELS_PER_THREAD - 1] >= 0) + atomicAdd(privatized_histograms[CHANNEL] + bins[PIXELS_PER_THREAD - 1], accumulator); + } + } + + + // Accumulate pixels. Specialized for individual accumulation of each pixel. + __device__ __forceinline__ void AccumulatePixels( + SampleT samples[PIXELS_PER_THREAD][NUM_CHANNELS], + bool is_valid[PIXELS_PER_THREAD], + CounterT* privatized_histograms[NUM_ACTIVE_CHANNELS], + Int2Type is_rle_compress) + { + #pragma unroll + for (int PIXEL = 0; PIXEL < PIXELS_PER_THREAD; ++PIXEL) + { + #pragma unroll + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + int bin = -1; + privatized_decode_op[CHANNEL].template BinSelect(samples[PIXEL][CHANNEL], bin, is_valid[PIXEL]); + if (bin >= 0) + atomicAdd(privatized_histograms[CHANNEL] + bin, 1); + } + } + } + + + /** + * Accumulate pixel, specialized for smem privatized histogram + */ + __device__ __forceinline__ void AccumulateSmemPixels( + SampleT samples[PIXELS_PER_THREAD][NUM_CHANNELS], + bool is_valid[PIXELS_PER_THREAD]) + { + CounterT* privatized_histograms[NUM_ACTIVE_CHANNELS]; + + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + privatized_histograms[CHANNEL] = temp_storage.histograms[CHANNEL]; + + AccumulatePixels(samples, is_valid, privatized_histograms, Int2Type()); + } + + + /** + * Accumulate pixel, specialized for gmem privatized histogram + */ + __device__ __forceinline__ void AccumulateGmemPixels( + SampleT samples[PIXELS_PER_THREAD][NUM_CHANNELS], + bool is_valid[PIXELS_PER_THREAD]) + { + AccumulatePixels(samples, is_valid, d_privatized_histograms, Int2Type()); + } + + + + //--------------------------------------------------------------------- + // Tile loading + //--------------------------------------------------------------------- + + // Load full, aligned tile using pixel iterator (multi-channel) + template + __device__ __forceinline__ void LoadFullAlignedTile( + OffsetT block_offset, + int valid_samples, + SampleT (&samples)[PIXELS_PER_THREAD][NUM_CHANNELS], + Int2Type<_NUM_ACTIVE_CHANNELS> num_active_channels) + { + typedef PixelT AliasedPixels[PIXELS_PER_THREAD]; + + WrappedPixelIteratorT d_wrapped_pixels((PixelT*) (d_native_samples + block_offset)); + + // Load using a wrapped pixel iterator + BlockLoadPixelT(temp_storage.aliasable.pixel_load).Load( + d_wrapped_pixels, + reinterpret_cast(samples)); + } + + // Load full, aligned tile using vec iterator (single-channel) + __device__ __forceinline__ void LoadFullAlignedTile( + OffsetT block_offset, + int valid_samples, + SampleT (&samples)[PIXELS_PER_THREAD][NUM_CHANNELS], + Int2Type<1> num_active_channels) + { + typedef VecT AliasedVecs[VECS_PER_THREAD]; + + WrappedVecsIteratorT d_wrapped_vecs((VecT*) (d_native_samples + block_offset)); + + // Load using a wrapped vec iterator + BlockLoadVecT(temp_storage.aliasable.vec_load).Load( + d_wrapped_vecs, + reinterpret_cast(samples)); + } + + // Load full, aligned tile + __device__ __forceinline__ void LoadTile( + OffsetT block_offset, + int valid_samples, + SampleT (&samples)[PIXELS_PER_THREAD][NUM_CHANNELS], + Int2Type is_full_tile, + Int2Type is_aligned) + { + LoadFullAlignedTile(block_offset, valid_samples, samples, Int2Type()); + } + + // Load full, mis-aligned tile using sample iterator + __device__ __forceinline__ void LoadTile( + OffsetT block_offset, + int valid_samples, + SampleT (&samples)[PIXELS_PER_THREAD][NUM_CHANNELS], + Int2Type is_full_tile, + Int2Type is_aligned) + { + typedef SampleT AliasedSamples[SAMPLES_PER_THREAD]; + + // Load using sample iterator + BlockLoadSampleT(temp_storage.aliasable.sample_load).Load( + d_wrapped_samples + block_offset, + reinterpret_cast(samples)); + } + + // Load partially-full, aligned tile using the pixel iterator + __device__ __forceinline__ void LoadTile( + OffsetT block_offset, + int valid_samples, + SampleT (&samples)[PIXELS_PER_THREAD][NUM_CHANNELS], + Int2Type is_full_tile, + Int2Type is_aligned) + { + typedef PixelT AliasedPixels[PIXELS_PER_THREAD]; + + WrappedPixelIteratorT d_wrapped_pixels((PixelT*) (d_native_samples + block_offset)); + + int valid_pixels = valid_samples / NUM_CHANNELS; + + // Load using a wrapped pixel iterator + BlockLoadPixelT(temp_storage.aliasable.pixel_load).Load( + d_wrapped_pixels, + reinterpret_cast(samples), + valid_pixels); + } + + // Load partially-full, mis-aligned tile using sample iterator + __device__ __forceinline__ void LoadTile( + OffsetT block_offset, + int valid_samples, + SampleT (&samples)[PIXELS_PER_THREAD][NUM_CHANNELS], + Int2Type is_full_tile, + Int2Type is_aligned) + { + typedef SampleT AliasedSamples[SAMPLES_PER_THREAD]; + + BlockLoadSampleT(temp_storage.aliasable.sample_load).Load( + d_wrapped_samples + block_offset, + reinterpret_cast(samples), + valid_samples); + } + + template + __device__ __forceinline__ void MarkValid(bool (&is_valid)[PIXELS_PER_THREAD], + int valid_samples, + Int2Type /* is_striped = false */) + { + #pragma unroll + for (int PIXEL = 0; PIXEL < PIXELS_PER_THREAD; ++PIXEL) + { + is_valid[PIXEL] = IS_FULL_TILE || (((threadIdx.x * PIXELS_PER_THREAD + PIXEL) * + NUM_CHANNELS) < valid_samples); + } + } + + template + __device__ __forceinline__ void MarkValid(bool (&is_valid)[PIXELS_PER_THREAD], + int valid_samples, + Int2Type /* is_striped = true */) + { + #pragma unroll + for (int PIXEL = 0; PIXEL < PIXELS_PER_THREAD; ++PIXEL) + { + is_valid[PIXEL] = IS_FULL_TILE || (((threadIdx.x + BLOCK_THREADS * PIXEL) * + NUM_CHANNELS) < valid_samples); + } + } + + //--------------------------------------------------------------------- + // Tile processing + //--------------------------------------------------------------------- + + // Consume a tile of data samples + template < + bool IS_ALIGNED, // Whether the tile offset is aligned (vec-aligned for single-channel, pixel-aligned for multi-channel) + bool IS_FULL_TILE> // Whether the tile is full + __device__ __forceinline__ void ConsumeTile(OffsetT block_offset, int valid_samples) + { + SampleT samples[PIXELS_PER_THREAD][NUM_CHANNELS]; + bool is_valid[PIXELS_PER_THREAD]; + + // Load tile + LoadTile( + block_offset, + valid_samples, + samples, + Int2Type(), + Int2Type()); + + // Set valid flags + MarkValid( + is_valid, + valid_samples, + Int2Type{}); + + // Accumulate samples + if (prefer_smem) + { + AccumulateSmemPixels(samples, is_valid); + } + else + { + AccumulateGmemPixels(samples, is_valid); + } + } + + + // Consume row tiles. Specialized for work-stealing from queue + template + __device__ __forceinline__ void ConsumeTiles( + OffsetT num_row_pixels, ///< The number of multi-channel pixels per row in the region of interest + OffsetT num_rows, ///< The number of rows in the region of interest + OffsetT row_stride_samples, ///< The number of samples between starts of consecutive rows in the region of interest + int tiles_per_row, ///< Number of image tiles per row + GridQueue tile_queue, + Int2Type is_work_stealing) + { + + int num_tiles = num_rows * tiles_per_row; + int tile_idx = (blockIdx.y * gridDim.x) + blockIdx.x; + OffsetT num_even_share_tiles = gridDim.x * gridDim.y; + + while (tile_idx < num_tiles) + { + int row = tile_idx / tiles_per_row; + int col = tile_idx - (row * tiles_per_row); + OffsetT row_offset = row * row_stride_samples; + OffsetT col_offset = (col * TILE_SAMPLES); + OffsetT tile_offset = row_offset + col_offset; + + if (col == tiles_per_row - 1) + { + // Consume a partially-full tile at the end of the row + OffsetT num_remaining = (num_row_pixels * NUM_CHANNELS) - col_offset; + ConsumeTile(tile_offset, num_remaining); + } + else + { + // Consume full tile + ConsumeTile(tile_offset, TILE_SAMPLES); + } + + CTA_SYNC(); + + // Get next tile + if (threadIdx.x == 0) + temp_storage.tile_idx = tile_queue.Drain(1) + num_even_share_tiles; + + CTA_SYNC(); + + tile_idx = temp_storage.tile_idx; + } + } + + + // Consume row tiles. Specialized for even-share (striped across thread blocks) + template + __device__ __forceinline__ void ConsumeTiles( + OffsetT num_row_pixels, ///< The number of multi-channel pixels per row in the region of interest + OffsetT num_rows, ///< The number of rows in the region of interest + OffsetT row_stride_samples, ///< The number of samples between starts of consecutive rows in the region of interest + int tiles_per_row, ///< Number of image tiles per row + GridQueue tile_queue, + Int2Type is_work_stealing) + { + for (int row = blockIdx.y; row < num_rows; row += gridDim.y) + { + OffsetT row_begin = row * row_stride_samples; + OffsetT row_end = row_begin + (num_row_pixels * NUM_CHANNELS); + OffsetT tile_offset = row_begin + (blockIdx.x * TILE_SAMPLES); + + while (tile_offset < row_end) + { + OffsetT num_remaining = row_end - tile_offset; + + if (num_remaining < TILE_SAMPLES) + { + // Consume partial tile + ConsumeTile(tile_offset, num_remaining); + break; + } + + // Consume full tile + ConsumeTile(tile_offset, TILE_SAMPLES); + tile_offset += gridDim.x * TILE_SAMPLES; + } + } + } + + + //--------------------------------------------------------------------- + // Parameter extraction + //--------------------------------------------------------------------- + + // Return a native pixel pointer (specialized for CacheModifiedInputIterator types) + template < + CacheLoadModifier _MODIFIER, + typename _ValueT, + typename _OffsetT> + __device__ __forceinline__ SampleT* NativePointer(CacheModifiedInputIterator<_MODIFIER, _ValueT, _OffsetT> itr) + { + return itr.ptr; + } + + // Return a native pixel pointer (specialized for other types) + template + __device__ __forceinline__ SampleT* NativePointer(IteratorT itr) + { + return NULL; + } + + + + //--------------------------------------------------------------------- + // Interface + //--------------------------------------------------------------------- + + + /** + * Constructor + */ + __device__ __forceinline__ AgentHistogram( + TempStorage &temp_storage, ///< Reference to temp_storage + SampleIteratorT d_samples, ///< Input data to reduce + int (&num_output_bins)[NUM_ACTIVE_CHANNELS], ///< The number bins per final output histogram + int (&num_privatized_bins)[NUM_ACTIVE_CHANNELS], ///< The number bins per privatized histogram + CounterT* (&d_output_histograms)[NUM_ACTIVE_CHANNELS], ///< Reference to final output histograms + CounterT* (&d_privatized_histograms)[NUM_ACTIVE_CHANNELS], ///< Reference to privatized histograms + OutputDecodeOpT (&output_decode_op)[NUM_ACTIVE_CHANNELS], ///< The transform operator for determining output bin-ids from privatized counter indices, one for each channel + PrivatizedDecodeOpT (&privatized_decode_op)[NUM_ACTIVE_CHANNELS]) ///< The transform operator for determining privatized counter indices from samples, one for each channel + : + temp_storage(temp_storage.Alias()), + d_wrapped_samples(d_samples), + d_native_samples(NativePointer(d_wrapped_samples)), + num_output_bins(num_output_bins), + num_privatized_bins(num_privatized_bins), + d_output_histograms(d_output_histograms), + output_decode_op(output_decode_op), + privatized_decode_op(privatized_decode_op), + prefer_smem((MEM_PREFERENCE == SMEM) ? + true : // prefer smem privatized histograms + (MEM_PREFERENCE == GMEM) ? + false : // prefer gmem privatized histograms + blockIdx.x & 1) // prefer blended privatized histograms + { + int blockId = (blockIdx.y * gridDim.x) + blockIdx.x; + + // Initialize the locations of this block's privatized histograms + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + this->d_privatized_histograms[CHANNEL] = d_privatized_histograms[CHANNEL] + (blockId * num_privatized_bins[CHANNEL]); + } + + + /** + * Consume image + */ + __device__ __forceinline__ void ConsumeTiles( + OffsetT num_row_pixels, ///< The number of multi-channel pixels per row in the region of interest + OffsetT num_rows, ///< The number of rows in the region of interest + OffsetT row_stride_samples, ///< The number of samples between starts of consecutive rows in the region of interest + int tiles_per_row, ///< Number of image tiles per row + GridQueue tile_queue) ///< Queue descriptor for assigning tiles of work to thread blocks + { + // Check whether all row starting offsets are vec-aligned (in single-channel) or pixel-aligned (in multi-channel) + int vec_mask = AlignBytes::ALIGN_BYTES - 1; + int pixel_mask = AlignBytes::ALIGN_BYTES - 1; + size_t row_bytes = sizeof(SampleT) * row_stride_samples; + + bool vec_aligned_rows = (NUM_CHANNELS == 1) && (SAMPLES_PER_THREAD % VecSize == 0) && // Single channel + ((size_t(d_native_samples) & vec_mask) == 0) && // ptr is quad-aligned + ((num_rows == 1) || ((row_bytes & vec_mask) == 0)); // number of row-samples is a multiple of the alignment of the quad + + bool pixel_aligned_rows = (NUM_CHANNELS > 1) && // Multi channel + ((size_t(d_native_samples) & pixel_mask) == 0) && // ptr is pixel-aligned + ((row_bytes & pixel_mask) == 0); // number of row-samples is a multiple of the alignment of the pixel + + // Whether rows are aligned and can be vectorized + if ((d_native_samples != NULL) && (vec_aligned_rows || pixel_aligned_rows)) + ConsumeTiles(num_row_pixels, num_rows, row_stride_samples, tiles_per_row, tile_queue, Int2Type()); + else + ConsumeTiles(num_row_pixels, num_rows, row_stride_samples, tiles_per_row, tile_queue, Int2Type()); + } + + + /** + * Initialize privatized bin counters. Specialized for privatized shared-memory counters + */ + __device__ __forceinline__ void InitBinCounters() + { + if (prefer_smem) + InitSmemBinCounters(); + else + InitGmemBinCounters(); + } + + + /** + * Store privatized histogram to device-accessible memory. Specialized for privatized shared-memory counters + */ + __device__ __forceinline__ void StoreOutput() + { + if (prefer_smem) + StoreSmemOutput(); + else + StoreGmemOutput(); + } + + +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_merge_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_merge_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..2e994dd97e125d1594751bdc51677da0c699001d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_merge_sort.cuh @@ -0,0 +1,750 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include "../config.cuh" +#include "../util_type.cuh" +#include "../util_namespace.cuh" +#include "../block/block_load.cuh" +#include "../block/block_store.cuh" +#include "../block/block_merge_sort.cuh" + +#include + +CUB_NAMESPACE_BEGIN + + +template < + int _BLOCK_THREADS, + int _ITEMS_PER_THREAD = 1, + cub::BlockLoadAlgorithm _LOAD_ALGORITHM = cub::BLOCK_LOAD_DIRECT, + cub::CacheLoadModifier _LOAD_MODIFIER = cub::LOAD_LDG, + cub::BlockStoreAlgorithm _STORE_ALGORITHM = cub::BLOCK_STORE_DIRECT> +struct AgentMergeSortPolicy +{ + static constexpr int BLOCK_THREADS = _BLOCK_THREADS; + static constexpr int ITEMS_PER_THREAD = _ITEMS_PER_THREAD; + static constexpr int ITEMS_PER_TILE = BLOCK_THREADS * ITEMS_PER_THREAD; + + static constexpr cub::BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; + static constexpr cub::CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; + static constexpr cub::BlockStoreAlgorithm STORE_ALGORITHM = _STORE_ALGORITHM; +}; + +/// \brief This agent is responsible for the initial in-tile sorting. +template +struct AgentBlockSort +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + static constexpr bool KEYS_ONLY = std::is_same::value; + + using BlockMergeSortT = + BlockMergeSort; + + using KeysLoadIt = typename THRUST_NS_QUALIFIER::cuda_cub::core::LoadIterator::type; + using ItemsLoadIt = typename THRUST_NS_QUALIFIER::cuda_cub::core::LoadIterator::type; + + using BlockLoadKeys = typename cub::BlockLoadType::type; + using BlockLoadItems = typename cub::BlockLoadType::type; + + using BlockStoreKeysIt = typename cub::BlockStoreType::type; + using BlockStoreItemsIt = typename cub::BlockStoreType::type; + using BlockStoreKeysRaw = typename cub::BlockStoreType::type; + using BlockStoreItemsRaw = typename cub::BlockStoreType::type; + + union _TempStorage + { + typename BlockLoadKeys::TempStorage load_keys; + typename BlockLoadItems::TempStorage load_items; + typename BlockStoreKeysIt::TempStorage store_keys_it; + typename BlockStoreItemsIt::TempStorage store_items_it; + typename BlockStoreKeysRaw::TempStorage store_keys_raw; + typename BlockStoreItemsRaw::TempStorage store_items_raw; + typename BlockMergeSortT::TempStorage block_merge; + }; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + static constexpr int BLOCK_THREADS = Policy::BLOCK_THREADS; + static constexpr int ITEMS_PER_THREAD = Policy::ITEMS_PER_THREAD; + static constexpr int ITEMS_PER_TILE = Policy::ITEMS_PER_TILE; + static constexpr int SHARED_MEMORY_SIZE = + static_cast(sizeof(TempStorage)); + + //--------------------------------------------------------------------- + // Per thread data + //--------------------------------------------------------------------- + + bool ping; + _TempStorage &storage; + KeysLoadIt keys_in; + ItemsLoadIt items_in; + OffsetT keys_count; + KeyIteratorT keys_out_it; + ValueIteratorT items_out_it; + KeyT *keys_out_raw; + ValueT *items_out_raw; + CompareOpT compare_op; + + __device__ __forceinline__ AgentBlockSort(bool ping_, + TempStorage &storage_, + KeysLoadIt keys_in_, + ItemsLoadIt items_in_, + OffsetT keys_count_, + KeyIteratorT keys_out_it_, + ValueIteratorT items_out_it_, + KeyT *keys_out_raw_, + ValueT *items_out_raw_, + CompareOpT compare_op_) + : ping(ping_) + , storage(storage_.Alias()) + , keys_in(keys_in_) + , items_in(items_in_) + , keys_count(keys_count_) + , keys_out_it(keys_out_it_) + , items_out_it(items_out_it_) + , keys_out_raw(keys_out_raw_) + , items_out_raw(items_out_raw_) + , compare_op(compare_op_) + { + } + + __device__ __forceinline__ void Process() + { + auto tile_idx = static_cast(blockIdx.x); + auto num_tiles = static_cast(gridDim.x); + auto tile_base = tile_idx * ITEMS_PER_TILE; + int items_in_tile = (cub::min)(keys_count - tile_base, int{ITEMS_PER_TILE}); + + if (tile_idx < num_tiles - 1) + { + consume_tile(tile_base, ITEMS_PER_TILE); + } + else + { + consume_tile(tile_base, items_in_tile); + } + } + + template + __device__ __forceinline__ void consume_tile(OffsetT tile_base, + int num_remaining) + { + ValueT items_local[ITEMS_PER_THREAD]; + if (!KEYS_ONLY) + { + if (IS_LAST_TILE) + { + BlockLoadItems(storage.load_items) + .Load(items_in + tile_base, + items_local, + num_remaining, + *(items_in + tile_base)); + } + else + { + BlockLoadItems(storage.load_items).Load(items_in + tile_base, items_local); + } + + CTA_SYNC(); + } + + KeyT keys_local[ITEMS_PER_THREAD]; + if (IS_LAST_TILE) + { + BlockLoadKeys(storage.load_keys) + .Load(keys_in + tile_base, + keys_local, + num_remaining, + *(keys_in + tile_base)); + } + else + { + BlockLoadKeys(storage.load_keys) + .Load(keys_in + tile_base, keys_local); + } + + CTA_SYNC(); + + if (IS_LAST_TILE) + { + BlockMergeSortT(storage.block_merge) + .Sort(keys_local, items_local, compare_op, num_remaining, keys_local[0]); + } + else + { + BlockMergeSortT(storage.block_merge).Sort(keys_local, items_local, compare_op); + } + + CTA_SYNC(); + + if (ping) + { + if (IS_LAST_TILE) + { + BlockStoreKeysIt(storage.store_keys_it) + .Store(keys_out_it + tile_base, keys_local, num_remaining); + } + else + { + BlockStoreKeysIt(storage.store_keys_it) + .Store(keys_out_it + tile_base, keys_local); + } + + if (!KEYS_ONLY) + { + CTA_SYNC(); + + if (IS_LAST_TILE) + { + BlockStoreItemsIt(storage.store_items_it) + .Store(items_out_it + tile_base, items_local, num_remaining); + } + else + { + BlockStoreItemsIt(storage.store_items_it) + .Store(items_out_it + tile_base, items_local); + } + } + } + else + { + if (IS_LAST_TILE) + { + BlockStoreKeysRaw(storage.store_keys_raw) + .Store(keys_out_raw + tile_base, keys_local, num_remaining); + } + else + { + BlockStoreKeysRaw(storage.store_keys_raw) + .Store(keys_out_raw + tile_base, keys_local); + } + + if (!KEYS_ONLY) + { + CTA_SYNC(); + + if (IS_LAST_TILE) + { + BlockStoreItemsRaw(storage.store_items_raw) + .Store(items_out_raw + tile_base, items_local, num_remaining); + } + else + { + BlockStoreItemsRaw(storage.store_items_raw) + .Store(items_out_raw + tile_base, items_local); + } + } + } + } +}; + +/** + * \brief This agent is responsible for partitioning a merge path into equal segments + * + * There are two sorted arrays to be merged into one array. If the first array + * is partitioned between parallel workers by slicing it into ranges of equal + * size, there could be a significant workload imbalance. The imbalance is + * caused by the fact that the distribution of elements from the second array + * is unknown beforehand. Instead, the MergePath is partitioned between workers. + * This approach guarantees an equal amount of work being assigned to each worker. + * + * This approach is outlined in the paper: + * Odeh et al, "Merge Path - Parallel Merging Made Simple" + * doi:10.1109/IPDPSW.2012.202 + */ +template < + typename KeyIteratorT, + typename OffsetT, + typename CompareOpT, + typename KeyT> +struct AgentPartition +{ + bool ping; + KeyIteratorT keys_ping; + KeyT *keys_pong; + OffsetT keys_count; + OffsetT partition_idx; + OffsetT *merge_partitions; + CompareOpT compare_op; + OffsetT target_merged_tiles_number; + int items_per_tile; + + __device__ __forceinline__ AgentPartition(bool ping, + KeyIteratorT keys_ping, + KeyT *keys_pong, + OffsetT keys_count, + OffsetT partition_idx, + OffsetT *merge_partitions, + CompareOpT compare_op, + OffsetT target_merged_tiles_number, + int items_per_tile) + : ping(ping) + , keys_ping(keys_ping) + , keys_pong(keys_pong) + , keys_count(keys_count) + , partition_idx(partition_idx) + , merge_partitions(merge_partitions) + , compare_op(compare_op) + , target_merged_tiles_number(target_merged_tiles_number) + , items_per_tile(items_per_tile) + {} + + __device__ __forceinline__ void Process() + { + OffsetT merged_tiles_number = target_merged_tiles_number / 2; + + // target_merged_tiles_number is a power of two. + OffsetT mask = target_merged_tiles_number - 1; + + // The first tile number in the tiles group being merged, equal to: + // target_merged_tiles_number * (partition_idx / target_merged_tiles_number) + OffsetT list = ~mask & partition_idx; + OffsetT start = items_per_tile * list; + OffsetT size = items_per_tile * merged_tiles_number; + + // Tile number within the tile group being merged, equal to: + // partition_idx / target_merged_tiles_number + OffsetT local_tile_idx = mask & partition_idx; + + OffsetT keys1_beg = (cub::min)(keys_count, start); + OffsetT keys1_end = (cub::min)(keys_count, start + size); + OffsetT keys2_beg = keys1_end; + OffsetT keys2_end = (cub::min)(keys_count, keys2_beg + size); + + OffsetT partition_at = (cub::min)(keys2_end - keys1_beg, + items_per_tile * local_tile_idx); + + OffsetT partition_diag = ping ? MergePath(keys_ping + keys1_beg, + keys_ping + keys2_beg, + keys1_end - keys1_beg, + keys2_end - keys2_beg, + partition_at, + compare_op) + : MergePath(keys_pong + keys1_beg, + keys_pong + keys2_beg, + keys1_end - keys1_beg, + keys2_end - keys2_beg, + partition_at, + compare_op); + + merge_partitions[partition_idx] = keys1_beg + partition_diag; + } +}; + +/// \brief The agent is responsible for merging N consecutive sorted arrays into N/2 sorted arrays. +template < + typename Policy, + typename KeyIteratorT, + typename ValueIteratorT, + typename OffsetT, + typename CompareOpT, + typename KeyT, + typename ValueT> +struct AgentMerge +{ + + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + using KeysLoadPingIt = typename THRUST_NS_QUALIFIER::cuda_cub::core::LoadIterator::type; + using ItemsLoadPingIt = typename THRUST_NS_QUALIFIER::cuda_cub::core::LoadIterator::type; + using KeysLoadPongIt = typename THRUST_NS_QUALIFIER::cuda_cub::core::LoadIterator::type; + using ItemsLoadPongIt = typename THRUST_NS_QUALIFIER::cuda_cub::core::LoadIterator::type; + + using KeysOutputPongIt = KeyIteratorT; + using ItemsOutputPongIt = ValueIteratorT; + using KeysOutputPingIt = KeyT*; + using ItemsOutputPingIt = ValueT*; + + using BlockStoreKeysPong = typename BlockStoreType::type; + using BlockStoreItemsPong = typename BlockStoreType::type; + using BlockStoreKeysPing = typename BlockStoreType::type; + using BlockStoreItemsPing = typename BlockStoreType::type; + + /// Parameterized BlockReduce primitive + + union _TempStorage + { + typename BlockStoreKeysPing::TempStorage store_keys_ping; + typename BlockStoreItemsPing::TempStorage store_items_ping; + typename BlockStoreKeysPong::TempStorage store_keys_pong; + typename BlockStoreItemsPong::TempStorage store_items_pong; + + KeyT keys_shared[Policy::ITEMS_PER_TILE + 1]; + ValueT items_shared[Policy::ITEMS_PER_TILE + 1]; + }; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + static constexpr bool KEYS_ONLY = std::is_same::value; + static constexpr int BLOCK_THREADS = Policy::BLOCK_THREADS; + static constexpr int ITEMS_PER_THREAD = Policy::ITEMS_PER_THREAD; + static constexpr int ITEMS_PER_TILE = Policy::ITEMS_PER_TILE; + static constexpr int SHARED_MEMORY_SIZE = + static_cast(sizeof(TempStorage)); + + //--------------------------------------------------------------------- + // Per thread data + //--------------------------------------------------------------------- + + bool ping; + _TempStorage& storage; + + KeysLoadPingIt keys_in_ping; + ItemsLoadPingIt items_in_ping; + KeysLoadPongIt keys_in_pong; + ItemsLoadPongIt items_in_pong; + + OffsetT keys_count; + + KeysOutputPongIt keys_out_pong; + ItemsOutputPongIt items_out_pong; + KeysOutputPingIt keys_out_ping; + ItemsOutputPingIt items_out_ping; + + CompareOpT compare_op; + OffsetT *merge_partitions; + OffsetT target_merged_tiles_number; + + //--------------------------------------------------------------------- + // Utility functions + //--------------------------------------------------------------------- + + /** + * \brief Concatenates up to ITEMS_PER_THREAD elements from input{1,2} into output array + * + * Reads data in a coalesced fashion [BLOCK_THREADS * item + tid] and + * stores the result in output[item]. + */ + template + __device__ __forceinline__ void + gmem_to_reg(T (&output)[ITEMS_PER_THREAD], + It1 input1, + It2 input2, + int count1, + int count2) + { + if (IS_FULL_TILE) + { +#pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD; ++item) + { + int idx = BLOCK_THREADS * item + threadIdx.x; + output[item] = (idx < count1) ? input1[idx] : input2[idx - count1]; + } + } + else + { +#pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD; ++item) + { + int idx = BLOCK_THREADS * item + threadIdx.x; + if (idx < count1 + count2) + { + output[item] = (idx < count1) ? input1[idx] : input2[idx - count1]; + } + } + } + } + + /// \brief Stores data in a coalesced fashion in[item] -> out[BLOCK_THREADS * item + tid] + template + __device__ __forceinline__ void + reg_to_shared(It output, + T (&input)[ITEMS_PER_THREAD]) + { +#pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD; ++item) + { + int idx = BLOCK_THREADS * item + threadIdx.x; + output[idx] = input[item]; + } + } + + template + __device__ __forceinline__ void + consume_tile(int tid, OffsetT tile_idx, OffsetT tile_base, int count) + { + OffsetT partition_beg = merge_partitions[tile_idx + 0]; + OffsetT partition_end = merge_partitions[tile_idx + 1]; + + // target_merged_tiles_number is a power of two. + OffsetT merged_tiles_number = target_merged_tiles_number / 2; + + OffsetT mask = target_merged_tiles_number - 1; + + // The first tile number in the tiles group being merged, equal to: + // target_merged_tiles_number * (tile_idx / target_merged_tiles_number) + OffsetT list = ~mask & tile_idx; + OffsetT start = ITEMS_PER_TILE * list; + OffsetT size = ITEMS_PER_TILE * merged_tiles_number; + + OffsetT diag = ITEMS_PER_TILE * tile_idx - start; + + OffsetT keys1_beg = partition_beg; + OffsetT keys1_end = partition_end; + OffsetT keys2_beg = (cub::min)(keys_count, 2 * start + size + diag - partition_beg); + OffsetT keys2_end = (cub::min)(keys_count, 2 * start + size + diag + ITEMS_PER_TILE - partition_end); + + // Check if it's the last tile in the tile group being merged + if (mask == (mask & tile_idx)) + { + keys1_end = (cub::min)(keys_count, start + size); + keys2_end = (cub::min)(keys_count, start + size * 2); + } + + // number of keys per tile + // + int num_keys1 = static_cast(keys1_end - keys1_beg); + int num_keys2 = static_cast(keys2_end - keys2_beg); + + // load keys1 & keys2 + KeyT keys_local[ITEMS_PER_THREAD]; + if (ping) + { + gmem_to_reg(keys_local, + keys_in_ping + keys1_beg, + keys_in_ping + keys2_beg, + num_keys1, + num_keys2); + } + else + { + gmem_to_reg(keys_local, + keys_in_pong + keys1_beg, + keys_in_pong + keys2_beg, + num_keys1, + num_keys2); + } + reg_to_shared(&storage.keys_shared[0], keys_local); + + // preload items into registers already + // + ValueT items_local[ITEMS_PER_THREAD]; + if (!KEYS_ONLY) + { + if (ping) + { + gmem_to_reg(items_local, + items_in_ping + keys1_beg, + items_in_ping + keys2_beg, + num_keys1, + num_keys2); + } + else + { + gmem_to_reg(items_local, + items_in_pong + keys1_beg, + items_in_pong + keys2_beg, + num_keys1, + num_keys2); + } + } + + CTA_SYNC(); + + // use binary search in shared memory + // to find merge path for each of thread + // we can use int type here, because the number of + // items in shared memory is limited + // + int diag0_local = (cub::min)(num_keys1 + num_keys2, ITEMS_PER_THREAD * tid); + + int keys1_beg_local = MergePath(&storage.keys_shared[0], + &storage.keys_shared[num_keys1], + num_keys1, + num_keys2, + diag0_local, + compare_op); + int keys1_end_local = num_keys1; + int keys2_beg_local = diag0_local - keys1_beg_local; + int keys2_end_local = num_keys2; + + int num_keys1_local = keys1_end_local - keys1_beg_local; + int num_keys2_local = keys2_end_local - keys2_beg_local; + + // perform serial merge + // + int indices[ITEMS_PER_THREAD]; + + SerialMerge(&storage.keys_shared[0], + keys1_beg_local, + keys2_beg_local + num_keys1, + num_keys1_local, + num_keys2_local, + keys_local, + indices, + compare_op); + + CTA_SYNC(); + + // write keys + // + if (ping) + { + if (IS_FULL_TILE) + { + BlockStoreKeysPing(storage.store_keys_ping) + .Store(keys_out_ping + tile_base, keys_local); + } + else + { + BlockStoreKeysPing(storage.store_keys_ping) + .Store(keys_out_ping + tile_base, keys_local, num_keys1 + num_keys2); + } + } + else + { + if (IS_FULL_TILE) + { + BlockStoreKeysPong(storage.store_keys_pong) + .Store(keys_out_pong + tile_base, keys_local); + } + else + { + BlockStoreKeysPong(storage.store_keys_pong) + .Store(keys_out_pong + tile_base, keys_local, num_keys1 + num_keys2); + } + } + + // if items are provided, merge them + if (!KEYS_ONLY) + { + CTA_SYNC(); + + reg_to_shared(&storage.items_shared[0], items_local); + + CTA_SYNC(); + + // gather items from shared mem + // +#pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD; ++item) + { + items_local[item] = storage.items_shared[indices[item]]; + } + + CTA_SYNC(); + + // write from reg to gmem + // + if (ping) + { + if (IS_FULL_TILE) + { + BlockStoreItemsPing(storage.store_items_ping) + .Store(items_out_ping + tile_base, items_local); + } + else + { + BlockStoreItemsPing(storage.store_items_ping) + .Store(items_out_ping + tile_base, items_local, count); + } + } + else + { + if (IS_FULL_TILE) + { + BlockStoreItemsPong(storage.store_items_pong) + .Store(items_out_pong + tile_base, items_local); + } + else + { + BlockStoreItemsPong(storage.store_items_pong) + .Store(items_out_pong + tile_base, items_local, count); + } + } + } + } + + __device__ __forceinline__ AgentMerge(bool ping_, + TempStorage &storage_, + KeysLoadPingIt keys_in_ping_, + ItemsLoadPingIt items_in_ping_, + KeysLoadPongIt keys_in_pong_, + ItemsLoadPongIt items_in_pong_, + OffsetT keys_count_, + KeysOutputPingIt keys_out_ping_, + ItemsOutputPingIt items_out_ping_, + KeysOutputPongIt keys_out_pong_, + ItemsOutputPongIt items_out_pong_, + CompareOpT compare_op_, + OffsetT *merge_partitions_, + OffsetT target_merged_tiles_number_) + : ping(ping_) + , storage(storage_.Alias()) + , keys_in_ping(keys_in_ping_) + , items_in_ping(items_in_ping_) + , keys_in_pong(keys_in_pong_) + , items_in_pong(items_in_pong_) + , keys_count(keys_count_) + , keys_out_pong(keys_out_pong_) + , items_out_pong(items_out_pong_) + , keys_out_ping(keys_out_ping_) + , items_out_ping(items_out_ping_) + , compare_op(compare_op_) + , merge_partitions(merge_partitions_) + , target_merged_tiles_number(target_merged_tiles_number_) + {} + + __device__ __forceinline__ void Process() + { + int tile_idx = static_cast(blockIdx.x); + int num_tiles = static_cast(gridDim.x); + OffsetT tile_base = OffsetT(tile_idx) * ITEMS_PER_TILE; + int tid = static_cast(threadIdx.x); + int items_in_tile = static_cast( + (cub::min)(static_cast(ITEMS_PER_TILE), keys_count - tile_base)); + + if (tile_idx < num_tiles - 1) + { + consume_tile(tid, tile_idx, tile_base, ITEMS_PER_TILE); + } + else + { + consume_tile(tid, tile_idx, tile_base, items_in_tile); + } + } +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_downsweep.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_downsweep.cuh new file mode 100644 index 0000000000000000000000000000000000000000..a6157a0974571d0f6ae8084209914122375e9c50 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_downsweep.cuh @@ -0,0 +1,775 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * AgentRadixSortDownsweep implements a stateful abstraction of CUDA thread + * blocks for participating in device-wide radix sort downsweep . + */ + + +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Tuning policy types + ******************************************************************************/ + +/** + * Parameterizable tuning policy type for AgentRadixSortDownsweep + */ +template < + int NOMINAL_BLOCK_THREADS_4B, ///< Threads per thread block + int NOMINAL_ITEMS_PER_THREAD_4B, ///< Items per thread (per tile of input) + typename ComputeT, ///< Dominant compute type + BlockLoadAlgorithm _LOAD_ALGORITHM, ///< The BlockLoad algorithm to use + CacheLoadModifier _LOAD_MODIFIER, ///< Cache load modifier for reading keys (and values) + RadixRankAlgorithm _RANK_ALGORITHM, ///< The radix ranking algorithm to use + BlockScanAlgorithm _SCAN_ALGORITHM, ///< The block scan algorithm to use + int _RADIX_BITS, ///< The number of radix bits, i.e., log2(bins) + typename ScalingType = RegBoundScaling > +struct AgentRadixSortDownsweepPolicy : + ScalingType +{ + enum + { + RADIX_BITS = _RADIX_BITS, ///< The number of radix bits, i.e., log2(bins) + }; + + static const BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; ///< The BlockLoad algorithm to use + static const CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; ///< Cache load modifier for reading keys (and values) + static const RadixRankAlgorithm RANK_ALGORITHM = _RANK_ALGORITHM; ///< The radix ranking algorithm to use + static const BlockScanAlgorithm SCAN_ALGORITHM = _SCAN_ALGORITHM; ///< The BlockScan algorithm to use +}; + + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + + + + + +/** + * \brief AgentRadixSortDownsweep implements a stateful abstraction of CUDA thread blocks for participating in device-wide radix sort downsweep . + */ +template < + typename AgentRadixSortDownsweepPolicy, ///< Parameterized AgentRadixSortDownsweepPolicy tuning policy type + bool IS_DESCENDING, ///< Whether or not the sorted-order is high-to-low + typename KeyT, ///< KeyT type + typename ValueT, ///< ValueT type + typename OffsetT, ///< Signed integer type for global offsets + typename DecomposerT = detail::identity_decomposer_t> +struct AgentRadixSortDownsweep +{ + //--------------------------------------------------------------------- + // Type definitions and constants + //--------------------------------------------------------------------- + + using traits = detail::radix::traits_t; + using bit_ordered_type = typename traits::bit_ordered_type; + using bit_ordered_conversion = typename traits::bit_ordered_conversion_policy; + + static const BlockLoadAlgorithm LOAD_ALGORITHM = AgentRadixSortDownsweepPolicy::LOAD_ALGORITHM; + static const CacheLoadModifier LOAD_MODIFIER = AgentRadixSortDownsweepPolicy::LOAD_MODIFIER; + static const RadixRankAlgorithm RANK_ALGORITHM = AgentRadixSortDownsweepPolicy::RANK_ALGORITHM; + static const BlockScanAlgorithm SCAN_ALGORITHM = AgentRadixSortDownsweepPolicy::SCAN_ALGORITHM; + + enum + { + BLOCK_THREADS = AgentRadixSortDownsweepPolicy::BLOCK_THREADS, + ITEMS_PER_THREAD = AgentRadixSortDownsweepPolicy::ITEMS_PER_THREAD, + RADIX_BITS = AgentRadixSortDownsweepPolicy::RADIX_BITS, + TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD, + + RADIX_DIGITS = 1 << RADIX_BITS, + KEYS_ONLY = std::is_same::value, + LOAD_WARP_STRIPED = RANK_ALGORITHM == RADIX_RANK_MATCH || + RANK_ALGORITHM == RADIX_RANK_MATCH_EARLY_COUNTS_ANY || + RANK_ALGORITHM == RADIX_RANK_MATCH_EARLY_COUNTS_ATOMIC_OR, + }; + + // Input iterator wrapper type (for applying cache modifier)s + using KeysItr = CacheModifiedInputIterator; + using ValuesItr = CacheModifiedInputIterator; + + // Radix ranking type to use + using BlockRadixRankT = + cub::detail::block_radix_rank_t< + RANK_ALGORITHM, BLOCK_THREADS, RADIX_BITS, IS_DESCENDING, SCAN_ALGORITHM>; + + // Digit extractor type + using fundamental_digit_extractor_t = BFEDigitExtractor; + using digit_extractor_t = + typename traits::template digit_extractor_t; + + enum + { + /// Number of bin-starting offsets tracked per thread + BINS_TRACKED_PER_THREAD = BlockRadixRankT::BINS_TRACKED_PER_THREAD + }; + + // BlockLoad type (keys) + using BlockLoadKeysT = + BlockLoad; + + // BlockLoad type (values) + using BlockLoadValuesT = + BlockLoad; + + // Value exchange array type + typedef ValueT ValueExchangeT[TILE_ITEMS]; + + /** + * Shared memory storage layout + */ + union __align__(16) _TempStorage + { + typename BlockLoadKeysT::TempStorage load_keys; + typename BlockLoadValuesT::TempStorage load_values; + typename BlockRadixRankT::TempStorage radix_rank; + + struct KeysAndOffsets + { + bit_ordered_type exchange_keys[TILE_ITEMS]; + OffsetT relative_bin_offsets[RADIX_DIGITS]; + } keys_and_offsets; + + Uninitialized exchange_values; + + OffsetT exclusive_digit_prefix[RADIX_DIGITS]; + }; + + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + //--------------------------------------------------------------------- + // Thread fields + //--------------------------------------------------------------------- + + // Shared storage for this CTA + _TempStorage &temp_storage; + + // Input and output device pointers + KeysItr d_keys_in; + ValuesItr d_values_in; + bit_ordered_type *d_keys_out; + ValueT *d_values_out; + + // The global scatter base offset for each digit (valid in the first RADIX_DIGITS threads) + OffsetT bin_offset[BINS_TRACKED_PER_THREAD]; + + std::uint32_t current_bit; + std::uint32_t num_bits; + + // Whether to short-cirucit + int short_circuit; + + DecomposerT decomposer; + + //--------------------------------------------------------------------- + // Utility methods + //--------------------------------------------------------------------- + + __device__ __forceinline__ digit_extractor_t digit_extractor() + { + return traits::template digit_extractor(current_bit, + num_bits, + decomposer); + } + + /** + * Scatter ranked keys through shared memory, then to device-accessible memory + */ + template + __device__ __forceinline__ void ScatterKeys( + bit_ordered_type (&twiddled_keys)[ITEMS_PER_THREAD], + OffsetT (&relative_bin_offsets)[ITEMS_PER_THREAD], + int (&ranks)[ITEMS_PER_THREAD], + OffsetT valid_items) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + temp_storage.keys_and_offsets.exchange_keys[ranks[ITEM]] = twiddled_keys[ITEM]; + } + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + bit_ordered_type key = temp_storage.keys_and_offsets.exchange_keys[threadIdx.x + (ITEM * BLOCK_THREADS)]; + std::uint32_t digit = digit_extractor().Digit(key); + relative_bin_offsets[ITEM] = temp_storage.keys_and_offsets.relative_bin_offsets[digit]; + + key = bit_ordered_conversion::from_bit_ordered(decomposer, key); + + if (FULL_TILE || + (static_cast(threadIdx.x + (ITEM * BLOCK_THREADS)) < valid_items)) + { + d_keys_out[relative_bin_offsets[ITEM] + threadIdx.x + (ITEM * BLOCK_THREADS)] = key; + } + } + } + + + /** + * Scatter ranked values through shared memory, then to device-accessible memory + */ + template + __device__ __forceinline__ void ScatterValues( + ValueT (&values)[ITEMS_PER_THREAD], + OffsetT (&relative_bin_offsets)[ITEMS_PER_THREAD], + int (&ranks)[ITEMS_PER_THREAD], + OffsetT valid_items) + { + CTA_SYNC(); + + ValueExchangeT &exchange_values = temp_storage.exchange_values.Alias(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + exchange_values[ranks[ITEM]] = values[ITEM]; + } + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + ValueT value = exchange_values[threadIdx.x + (ITEM * BLOCK_THREADS)]; + + if (FULL_TILE || + (static_cast(threadIdx.x + (ITEM * BLOCK_THREADS)) < valid_items)) + { + d_values_out[relative_bin_offsets[ITEM] + threadIdx.x + (ITEM * BLOCK_THREADS)] = value; + } + } + } + + /** + * Load a tile of keys (specialized for full tile, block load) + */ + __device__ __forceinline__ void LoadKeys( + bit_ordered_type (&keys)[ITEMS_PER_THREAD], + OffsetT block_offset, + OffsetT valid_items, + bit_ordered_type oob_item, + Int2Type is_full_tile, + Int2Type warp_striped) + { + BlockLoadKeysT(temp_storage.load_keys).Load( + d_keys_in + block_offset, keys); + + CTA_SYNC(); + } + + + /** + * Load a tile of keys (specialized for partial tile, block load) + */ + __device__ __forceinline__ void LoadKeys( + bit_ordered_type (&keys)[ITEMS_PER_THREAD], + OffsetT block_offset, + OffsetT valid_items, + bit_ordered_type oob_item, + Int2Type is_full_tile, + Int2Type warp_striped) + { + // Register pressure work-around: moving valid_items through shfl prevents compiler + // from reusing guards/addressing from prior guarded loads + valid_items = ShuffleIndex(valid_items, 0, 0xffffffff); + + BlockLoadKeysT(temp_storage.load_keys).Load( + d_keys_in + block_offset, keys, valid_items, oob_item); + + CTA_SYNC(); + } + + + /** + * Load a tile of keys (specialized for full tile, warp-striped load) + */ + __device__ __forceinline__ void LoadKeys( + bit_ordered_type (&keys)[ITEMS_PER_THREAD], + OffsetT block_offset, + OffsetT valid_items, + bit_ordered_type oob_item, + Int2Type is_full_tile, + Int2Type warp_striped) + { + LoadDirectWarpStriped(threadIdx.x, d_keys_in + block_offset, keys); + } + + /** + * Load a tile of keys (specialized for partial tile, warp-striped load) + */ + __device__ __forceinline__ void LoadKeys( + bit_ordered_type (&keys)[ITEMS_PER_THREAD], + OffsetT block_offset, + OffsetT valid_items, + bit_ordered_type oob_item, + Int2Type is_full_tile, + Int2Type warp_striped) + { + // Register pressure work-around: moving valid_items through shfl prevents compiler + // from reusing guards/addressing from prior guarded loads + valid_items = ShuffleIndex(valid_items, 0, 0xffffffff); + + LoadDirectWarpStriped(threadIdx.x, d_keys_in + block_offset, keys, valid_items, oob_item); + } + + /** + * Load a tile of values (specialized for full tile, block load) + */ + __device__ __forceinline__ void LoadValues( + ValueT (&values)[ITEMS_PER_THREAD], + OffsetT block_offset, + OffsetT valid_items, + Int2Type is_full_tile, + Int2Type warp_striped) + { + BlockLoadValuesT(temp_storage.load_values).Load( + d_values_in + block_offset, values); + + CTA_SYNC(); + } + + + /** + * Load a tile of values (specialized for partial tile, block load) + */ + __device__ __forceinline__ void LoadValues( + ValueT (&values)[ITEMS_PER_THREAD], + OffsetT block_offset, + OffsetT valid_items, + Int2Type is_full_tile, + Int2Type warp_striped) + { + // Register pressure work-around: moving valid_items through shfl prevents compiler + // from reusing guards/addressing from prior guarded loads + valid_items = ShuffleIndex(valid_items, 0, 0xffffffff); + + BlockLoadValuesT(temp_storage.load_values).Load( + d_values_in + block_offset, values, valid_items); + + CTA_SYNC(); + } + + + /** + * Load a tile of items (specialized for full tile, warp-striped load) + */ + __device__ __forceinline__ void LoadValues( + ValueT (&values)[ITEMS_PER_THREAD], + OffsetT block_offset, + OffsetT valid_items, + Int2Type is_full_tile, + Int2Type warp_striped) + { + LoadDirectWarpStriped(threadIdx.x, d_values_in + block_offset, values); + } + + /** + * Load a tile of items (specialized for partial tile, warp-striped load) + */ + __device__ __forceinline__ void LoadValues( + ValueT (&values)[ITEMS_PER_THREAD], + OffsetT block_offset, + OffsetT valid_items, + Int2Type is_full_tile, + Int2Type warp_striped) + { + // Register pressure work-around: moving valid_items through shfl prevents compiler + // from reusing guards/addressing from prior guarded loads + valid_items = ShuffleIndex(valid_items, 0, 0xffffffff); + + LoadDirectWarpStriped(threadIdx.x, d_values_in + block_offset, values, valid_items); + } + + /** + * Truck along associated values + */ + template + __device__ __forceinline__ void GatherScatterValues( + OffsetT (&relative_bin_offsets)[ITEMS_PER_THREAD], + int (&ranks)[ITEMS_PER_THREAD], + OffsetT block_offset, + OffsetT valid_items, + Int2Type /*is_keys_only*/) + { + ValueT values[ITEMS_PER_THREAD]; + + CTA_SYNC(); + + LoadValues( + values, + block_offset, + valid_items, + Int2Type(), + Int2Type()); + + ScatterValues( + values, + relative_bin_offsets, + ranks, + valid_items); + } + + + /** + * Truck along associated values (specialized for key-only sorting) + */ + template + __device__ __forceinline__ void GatherScatterValues( + OffsetT (&/*relative_bin_offsets*/)[ITEMS_PER_THREAD], + int (&/*ranks*/)[ITEMS_PER_THREAD], + OffsetT /*block_offset*/, + OffsetT /*valid_items*/, + Int2Type /*is_keys_only*/) + {} + + + /** + * Process tile + */ + template + __device__ __forceinline__ void ProcessTile( + OffsetT block_offset, + const OffsetT &valid_items = TILE_ITEMS) + { + bit_ordered_type keys[ITEMS_PER_THREAD]; + int ranks[ITEMS_PER_THREAD]; + OffsetT relative_bin_offsets[ITEMS_PER_THREAD]; + + // Assign default (min/max) value to all keys + bit_ordered_type default_key = IS_DESCENDING + ? traits::min_raw_binary_key(decomposer) + : traits::max_raw_binary_key(decomposer); + + // Load tile of keys + LoadKeys( + keys, + block_offset, + valid_items, + default_key, + Int2Type(), + Int2Type()); + + #pragma unroll + for (int KEY = 0; KEY < ITEMS_PER_THREAD; KEY++) + { + keys[KEY] = bit_ordered_conversion::to_bit_ordered(decomposer, keys[KEY]); + } + + // Rank the twiddled keys + int exclusive_digit_prefix[BINS_TRACKED_PER_THREAD]; + BlockRadixRankT(temp_storage.radix_rank).RankKeys( + keys, + ranks, + digit_extractor(), + exclusive_digit_prefix); + + CTA_SYNC(); + + // Share exclusive digit prefix + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + // Store exclusive prefix + temp_storage.exclusive_digit_prefix[bin_idx] = + exclusive_digit_prefix[track]; + } + } + + CTA_SYNC(); + + // Get inclusive digit prefix + int inclusive_digit_prefix[BINS_TRACKED_PER_THREAD]; + + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + if (IS_DESCENDING) + { + // Get inclusive digit prefix from exclusive prefix (higher bins come first) + inclusive_digit_prefix[track] = (bin_idx == 0) ? + (BLOCK_THREADS * ITEMS_PER_THREAD) : + temp_storage.exclusive_digit_prefix[bin_idx - 1]; + } + else + { + // Get inclusive digit prefix from exclusive prefix (lower bins come first) + inclusive_digit_prefix[track] = (bin_idx == RADIX_DIGITS - 1) ? + (BLOCK_THREADS * ITEMS_PER_THREAD) : + temp_storage.exclusive_digit_prefix[bin_idx + 1]; + } + } + } + + CTA_SYNC(); + + // Update global scatter base offsets for each digit + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + bin_offset[track] -= exclusive_digit_prefix[track]; + temp_storage.keys_and_offsets.relative_bin_offsets[bin_idx] = bin_offset[track]; + bin_offset[track] += inclusive_digit_prefix[track]; + } + } + + CTA_SYNC(); + + // Scatter keys + ScatterKeys(keys, relative_bin_offsets, ranks, valid_items); + + // Gather/scatter values + GatherScatterValues(relative_bin_offsets , ranks, block_offset, valid_items, Int2Type()); + } + + //--------------------------------------------------------------------- + // Copy shortcut + //--------------------------------------------------------------------- + + /** + * Copy tiles within the range of input + */ + template < + typename InputIteratorT, + typename T> + __device__ __forceinline__ void Copy( + InputIteratorT d_in, + T *d_out, + OffsetT block_offset, + OffsetT block_end) + { + // Simply copy the input + while (block_end - block_offset >= TILE_ITEMS) + { + T items[ITEMS_PER_THREAD]; + + LoadDirectStriped(threadIdx.x, d_in + block_offset, items); + CTA_SYNC(); + StoreDirectStriped(threadIdx.x, d_out + block_offset, items); + + block_offset += TILE_ITEMS; + } + + // Clean up last partial tile with guarded-I/O + if (block_offset < block_end) + { + OffsetT valid_items = block_end - block_offset; + + T items[ITEMS_PER_THREAD]; + + LoadDirectStriped(threadIdx.x, d_in + block_offset, items, valid_items); + CTA_SYNC(); + StoreDirectStriped(threadIdx.x, d_out + block_offset, items, valid_items); + } + } + + + /** + * Copy tiles within the range of input (specialized for NullType) + */ + template + __device__ __forceinline__ void Copy( + InputIteratorT /*d_in*/, + NullType * /*d_out*/, + OffsetT /*block_offset*/, + OffsetT /*block_end*/) + {} + + + //--------------------------------------------------------------------- + // Interface + //--------------------------------------------------------------------- + + /** + * Constructor + */ + __device__ __forceinline__ AgentRadixSortDownsweep( + TempStorage &temp_storage, + OffsetT (&bin_offset)[BINS_TRACKED_PER_THREAD], + OffsetT num_items, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int current_bit, + int num_bits, + DecomposerT decomposer = {}) + : + temp_storage(temp_storage.Alias()), + d_keys_in(reinterpret_cast(d_keys_in)), + d_values_in(d_values_in), + d_keys_out(reinterpret_cast(d_keys_out)), + d_values_out(d_values_out), + current_bit(current_bit), + num_bits(num_bits), + short_circuit(1), + decomposer(decomposer) + { + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + this->bin_offset[track] = bin_offset[track]; + + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + // Short circuit if the histogram has only bin counts of only zeros or problem-size + short_circuit = short_circuit && ((bin_offset[track] == 0) || (bin_offset[track] == num_items)); + } + } + + short_circuit = CTA_SYNC_AND(short_circuit); + } + + + /** + * Constructor + */ + __device__ __forceinline__ AgentRadixSortDownsweep( + TempStorage &temp_storage, + OffsetT num_items, + OffsetT *d_spine, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int current_bit, + int num_bits, + DecomposerT decomposer = {}) + : + temp_storage(temp_storage.Alias()), + d_keys_in(reinterpret_cast(d_keys_in)), + d_values_in(d_values_in), + d_keys_out(reinterpret_cast(d_keys_out)), + d_values_out(d_values_out), + current_bit(current_bit), + num_bits(num_bits), + short_circuit(1), + decomposer(decomposer) + { + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + + // Load digit bin offsets (each of the first RADIX_DIGITS threads will load an offset for that digit) + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + if (IS_DESCENDING) + bin_idx = RADIX_DIGITS - bin_idx - 1; + + // Short circuit if the first block's histogram has only bin counts of only zeros or problem-size + OffsetT first_block_bin_offset = d_spine[gridDim.x * bin_idx]; + short_circuit = short_circuit && ((first_block_bin_offset == 0) || (first_block_bin_offset == num_items)); + + // Load my block's bin offset for my bin + bin_offset[track] = d_spine[(gridDim.x * bin_idx) + blockIdx.x]; + } + } + + short_circuit = CTA_SYNC_AND(short_circuit); + } + + + /** + * Distribute keys from a segment of input tiles. + */ + __device__ __forceinline__ void ProcessRegion( + OffsetT block_offset, + OffsetT block_end) + { + if (short_circuit) + { + // Copy keys + Copy(d_keys_in, d_keys_out, block_offset, block_end); + + // Copy values + Copy(d_values_in, d_values_out, block_offset, block_end); + } + else + { + // Process full tiles of tile_items + #pragma unroll 1 + while (block_end - block_offset >= TILE_ITEMS) + { + ProcessTile(block_offset); + block_offset += TILE_ITEMS; + + CTA_SYNC(); + } + + // Clean up last partial tile with guarded-I/O + if (block_offset < block_end) + { + ProcessTile(block_offset, block_end - block_offset); + } + + } + } + +}; + + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_histogram.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_histogram.cuh new file mode 100644 index 0000000000000000000000000000000000000000..43649fc481b7a16a42388ac15488a49d823e5e03 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_histogram.cuh @@ -0,0 +1,282 @@ +/****************************************************************************** + * Copyright (c) 2011-2020, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * agent_radix_sort_histogram.cuh implements a stateful abstraction of CUDA + * thread blocks for participating in the device histogram kernel used for + * one-sweep radix sorting. + */ + +#pragma once + +#include "../block/block_load.cuh" +#include "../block/radix_rank_sort_operations.cuh" +#include "../config.cuh" +#include "../thread/thread_reduce.cuh" +#include "../util_math.cuh" +#include "../util_type.cuh" + + +CUB_NAMESPACE_BEGIN + +template < + int _BLOCK_THREADS, + int _ITEMS_PER_THREAD, + int NOMINAL_4B_NUM_PARTS, + typename ComputeT, + int _RADIX_BITS> +struct AgentRadixSortHistogramPolicy +{ + enum + { + BLOCK_THREADS = _BLOCK_THREADS, + ITEMS_PER_THREAD = _ITEMS_PER_THREAD, + /** NUM_PARTS is the number of private histograms (parts) each histogram is split + * into. Each warp lane is assigned to a specific part based on the lane + * ID. However, lanes with the same ID in different warp use the same private + * histogram. This arrangement helps reduce the degree of conflicts in atomic + * operations. */ + NUM_PARTS = CUB_MAX(1, NOMINAL_4B_NUM_PARTS * 4 / CUB_MAX(sizeof(ComputeT), 4)), + RADIX_BITS = _RADIX_BITS, + }; +}; + +template < + int _BLOCK_THREADS, + int _RADIX_BITS> +struct AgentRadixSortExclusiveSumPolicy +{ + enum + { + BLOCK_THREADS = _BLOCK_THREADS, + RADIX_BITS = _RADIX_BITS, + }; +}; + +template < + typename AgentRadixSortHistogramPolicy, + bool IS_DESCENDING, + typename KeyT, + typename OffsetT, + typename DecomposerT = detail::identity_decomposer_t> +struct AgentRadixSortHistogram +{ + // constants + enum + { + ITEMS_PER_THREAD = AgentRadixSortHistogramPolicy::ITEMS_PER_THREAD, + BLOCK_THREADS = AgentRadixSortHistogramPolicy::BLOCK_THREADS, + TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD, + RADIX_BITS = AgentRadixSortHistogramPolicy::RADIX_BITS, + RADIX_DIGITS = 1 << RADIX_BITS, + MAX_NUM_PASSES = (sizeof(KeyT) * 8 + RADIX_BITS - 1) / RADIX_BITS, + NUM_PARTS = AgentRadixSortHistogramPolicy::NUM_PARTS, + }; + + using traits = detail::radix::traits_t; + using bit_ordered_type = typename traits::bit_ordered_type; + using bit_ordered_conversion = typename traits::bit_ordered_conversion_policy; + + typedef RadixSortTwiddle Twiddle; + typedef std::uint32_t ShmemCounterT; + typedef ShmemCounterT ShmemAtomicCounterT; + + using fundamental_digit_extractor_t = ShiftDigitExtractor; + using digit_extractor_t = + typename traits::template digit_extractor_t; + + struct _TempStorage + { + ShmemAtomicCounterT bins[MAX_NUM_PASSES][RADIX_DIGITS][NUM_PARTS]; + }; + + struct TempStorage : Uninitialized<_TempStorage> {}; + + // thread fields + // shared memory storage + _TempStorage& s; + + // bins for the histogram + OffsetT* d_bins_out; + + // data to compute the histogram + const bit_ordered_type* d_keys_in; + + // number of data items + OffsetT num_items; + + // begin and end bits for sorting + int begin_bit, end_bit; + + // number of sorting passes + int num_passes; + + DecomposerT decomposer; + + __device__ __forceinline__ AgentRadixSortHistogram(TempStorage &temp_storage, + OffsetT *d_bins_out, + const KeyT *d_keys_in, + OffsetT num_items, + int begin_bit, + int end_bit, + DecomposerT decomposer = {}) + : s(temp_storage.Alias()) + , d_bins_out(d_bins_out) + , d_keys_in(reinterpret_cast(d_keys_in)) + , num_items(num_items) + , begin_bit(begin_bit) + , end_bit(end_bit) + , num_passes((end_bit - begin_bit + RADIX_BITS - 1) / RADIX_BITS) + , decomposer(decomposer) + {} + + __device__ __forceinline__ void Init() + { + // Initialize bins to 0. + #pragma unroll + for (int bin = threadIdx.x; bin < RADIX_DIGITS; bin += BLOCK_THREADS) + { + #pragma unroll + for (int pass = 0; pass < num_passes; ++pass) + { + #pragma unroll + for (int part = 0; part < NUM_PARTS; ++part) + { + s.bins[pass][bin][part] = 0; + } + } + } + CTA_SYNC(); + } + + __device__ __forceinline__ + void LoadTileKeys(OffsetT tile_offset, bit_ordered_type (&keys)[ITEMS_PER_THREAD]) + { + // tile_offset < num_items always, hence the line below works + bool full_tile = num_items - tile_offset >= TILE_ITEMS; + if (full_tile) + { + LoadDirectStriped( + threadIdx.x, d_keys_in + tile_offset, keys); + } + else + { + LoadDirectStriped( + threadIdx.x, d_keys_in + tile_offset, keys, + num_items - tile_offset, Twiddle::DefaultKey(decomposer)); + } + + #pragma unroll + for (int u = 0; u < ITEMS_PER_THREAD; ++u) + { + keys[u] = Twiddle::In(keys[u], decomposer); + } + } + + __device__ __forceinline__ + void AccumulateSharedHistograms(OffsetT tile_offset, bit_ordered_type (&keys)[ITEMS_PER_THREAD]) + { + int part = LaneId() % NUM_PARTS; + #pragma unroll + for (int current_bit = begin_bit, pass = 0; + current_bit < end_bit; current_bit += RADIX_BITS, ++pass) + { + int num_bits = CUB_MIN(RADIX_BITS, end_bit - current_bit); + #pragma unroll + for (int u = 0; u < ITEMS_PER_THREAD; ++u) + { + std::uint32_t bin = digit_extractor(current_bit, num_bits).Digit(keys[u]); + // Using cuda::atomic<> results in lower performance on GP100, + // so atomicAdd() is used instead. + atomicAdd(&s.bins[pass][bin][part], 1); + } + } + } + + __device__ __forceinline__ void AccumulateGlobalHistograms() + { + #pragma unroll + for (int bin = threadIdx.x; bin < RADIX_DIGITS; bin += BLOCK_THREADS) + { + #pragma unroll + for (int pass = 0; pass < num_passes; ++pass) + { + OffsetT count = internal::ThreadReduce(s.bins[pass][bin], Sum()); + if (count > 0) + { + // Using cuda::atomic<> here would also require using it in + // other kernels. However, other kernels of onesweep sorting + // (ExclusiveSum, Onesweep) don't need atomic + // access. Therefore, atomicAdd() is used, until + // cuda::atomic_ref<> becomes available. + atomicAdd(&d_bins_out[pass * RADIX_DIGITS + bin], count); + } + } + } + } + + __device__ __forceinline__ void Process() + { + // Within a portion, avoid overflowing (u)int32 counters. + // Between portions, accumulate results in global memory. + const OffsetT MAX_PORTION_SIZE = 1 << 30; + OffsetT num_portions = cub::DivideAndRoundUp(num_items, MAX_PORTION_SIZE); + for (OffsetT portion = 0; portion < num_portions; ++portion) + { + // Reset the counters. + Init(); + CTA_SYNC(); + + // Process the tiles. + OffsetT portion_offset = portion * MAX_PORTION_SIZE; + OffsetT portion_size = CUB_MIN(MAX_PORTION_SIZE, num_items - portion_offset); + for (OffsetT offset = blockIdx.x * TILE_ITEMS; offset < portion_size; + offset += TILE_ITEMS * gridDim.x) + { + OffsetT tile_offset = portion_offset + offset; + bit_ordered_type keys[ITEMS_PER_THREAD]; + LoadTileKeys(tile_offset, keys); + AccumulateSharedHistograms(tile_offset, keys); + } + CTA_SYNC(); + + // Accumulate the result in global memory. + AccumulateGlobalHistograms(); + CTA_SYNC(); + } + } + + __device__ __forceinline__ digit_extractor_t digit_extractor(int current_bit, int num_bits) + { + return traits::template digit_extractor(current_bit, + num_bits, + decomposer); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_onesweep.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_onesweep.cuh new file mode 100644 index 0000000000000000000000000000000000000000..1922936d66ee8237d5b2f33bd14ac1e4f62cf0fa --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_onesweep.cuh @@ -0,0 +1,690 @@ +/****************************************************************************** + * Copyright (c) 2011-2020, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * agent_radix_sort_onesweep.cuh implements a stateful abstraction of CUDA + * thread blocks for participating in the device one-sweep radix sort kernel. + */ + +#pragma once + +#include "../block/block_radix_rank.cuh" +#include "../block/radix_rank_sort_operations.cuh" +#include "../block/block_store.cuh" +#include "../config.cuh" +#include "../util_ptx.cuh" +#include "../util_type.cuh" + +CUB_NAMESPACE_BEGIN + +/** \brief cub::RadixSortStoreAlgorithm enumerates different algorithms to write + * partitioned elements (keys, values) stored in shared memory into global + * memory. Currently applies only to writing 4B keys in full tiles; in all other cases, + * RADIX_SORT_STORE_DIRECT is used. + */ +enum RadixSortStoreAlgorithm +{ + /** \brief Elements are statically distributed among block threads, which write them + * into the appropriate partition in global memory. This results in fewer instructions + * and more writes in flight at a given moment, but may generate more transactions. */ + RADIX_SORT_STORE_DIRECT, + /** \brief Elements are distributed among warps in a block distribution. Each warp + * goes through its elements and tries to write them while minimizing the number of + * memory transactions. This results in fewer memory transactions, but more + * instructions and less writes in flight at a given moment. */ + RADIX_SORT_STORE_ALIGNED +}; + +template < + int NOMINAL_BLOCK_THREADS_4B, + int NOMINAL_ITEMS_PER_THREAD_4B, + typename ComputeT, + /** \brief Number of private histograms to use in the ranker; + ignored if the ranking algorithm is not one of RADIX_RANK_MATCH_EARLY_COUNTS_* */ + int _RANK_NUM_PARTS, + /** \brief Ranking algorithm used in the onesweep kernel. Only algorithms that + support warp-strided key arrangement and count callbacks are supported. */ + RadixRankAlgorithm _RANK_ALGORITHM, + BlockScanAlgorithm _SCAN_ALGORITHM, + RadixSortStoreAlgorithm _STORE_ALGORITHM, + int _RADIX_BITS, + typename ScalingType = RegBoundScaling< + NOMINAL_BLOCK_THREADS_4B, NOMINAL_ITEMS_PER_THREAD_4B, ComputeT> > +struct AgentRadixSortOnesweepPolicy : ScalingType +{ + enum + { + RANK_NUM_PARTS = _RANK_NUM_PARTS, + RADIX_BITS = _RADIX_BITS, + }; + static const RadixRankAlgorithm RANK_ALGORITHM = _RANK_ALGORITHM; + static const BlockScanAlgorithm SCAN_ALGORITHM = _SCAN_ALGORITHM; + static const RadixSortStoreAlgorithm STORE_ALGORITHM = _STORE_ALGORITHM; +}; + +template < + typename AgentRadixSortOnesweepPolicy, + bool IS_DESCENDING, + typename KeyT, + typename ValueT, + typename OffsetT, + typename PortionOffsetT, + typename DecomposerT = detail::identity_decomposer_t> +struct AgentRadixSortOnesweep +{ + // constants + enum + { + ITEMS_PER_THREAD = AgentRadixSortOnesweepPolicy::ITEMS_PER_THREAD, + KEYS_ONLY = std::is_same::value, + BLOCK_THREADS = AgentRadixSortOnesweepPolicy::BLOCK_THREADS, + RANK_NUM_PARTS = AgentRadixSortOnesweepPolicy::RANK_NUM_PARTS, + TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD, + RADIX_BITS = AgentRadixSortOnesweepPolicy::RADIX_BITS, + RADIX_DIGITS = 1 << RADIX_BITS, + BINS_PER_THREAD = (RADIX_DIGITS + BLOCK_THREADS - 1) / BLOCK_THREADS, + FULL_BINS = BINS_PER_THREAD * BLOCK_THREADS == RADIX_DIGITS, + WARP_THREADS = CUB_PTX_WARP_THREADS, + BLOCK_WARPS = BLOCK_THREADS / WARP_THREADS, + WARP_MASK = ~0, + LOOKBACK_PARTIAL_MASK = 1 << (PortionOffsetT(sizeof(PortionOffsetT)) * 8 - 2), + LOOKBACK_GLOBAL_MASK = 1 << (PortionOffsetT(sizeof(PortionOffsetT)) * 8 - 1), + LOOKBACK_KIND_MASK = LOOKBACK_PARTIAL_MASK | LOOKBACK_GLOBAL_MASK, + LOOKBACK_VALUE_MASK = ~LOOKBACK_KIND_MASK, + }; + + using traits = detail::radix::traits_t; + using bit_ordered_type = typename traits::bit_ordered_type; + using bit_ordered_conversion = typename traits::bit_ordered_conversion_policy; + + using fundamental_digit_extractor_t = ShiftDigitExtractor; + using digit_extractor_t = + typename traits::template digit_extractor_t; + + typedef PortionOffsetT AtomicOffsetT; + + static const RadixRankAlgorithm RANK_ALGORITHM = + AgentRadixSortOnesweepPolicy::RANK_ALGORITHM; + static const BlockScanAlgorithm SCAN_ALGORITHM = + AgentRadixSortOnesweepPolicy::SCAN_ALGORITHM; + static const RadixSortStoreAlgorithm STORE_ALGORITHM = + sizeof(bit_ordered_type) == sizeof(uint32_t) ? + AgentRadixSortOnesweepPolicy::STORE_ALGORITHM : + RADIX_SORT_STORE_DIRECT; + + typedef RadixSortTwiddle Twiddle; + + static_assert(RANK_ALGORITHM == RADIX_RANK_MATCH + || RANK_ALGORITHM == RADIX_RANK_MATCH_EARLY_COUNTS_ANY + || RANK_ALGORITHM == RADIX_RANK_MATCH_EARLY_COUNTS_ATOMIC_OR, + "for onesweep agent, the ranking algorithm must warp-strided key arrangement"); + + using BlockRadixRankT = cub::detail::conditional_t< + RANK_ALGORITHM == RADIX_RANK_MATCH_EARLY_COUNTS_ATOMIC_OR, + BlockRadixRankMatchEarlyCounts, + cub::detail::conditional_t< + RANK_ALGORITHM == RADIX_RANK_MATCH, + BlockRadixRankMatch, + BlockRadixRankMatchEarlyCounts>>; + + // temporary storage + struct TempStorage_ + { + union + { + bit_ordered_type keys_out[TILE_ITEMS]; + ValueT values_out[TILE_ITEMS]; + typename BlockRadixRankT::TempStorage rank_temp_storage; + }; + union + { + OffsetT global_offsets[RADIX_DIGITS]; + PortionOffsetT block_idx; + }; + }; + + using TempStorage = Uninitialized; + + // thread variables + TempStorage_& s; + + // kernel parameters + AtomicOffsetT* d_lookback; + AtomicOffsetT* d_ctrs; + OffsetT* d_bins_out; + const OffsetT* d_bins_in; + bit_ordered_type* d_keys_out; + const bit_ordered_type* d_keys_in; + ValueT* d_values_out; + const ValueT* d_values_in; + PortionOffsetT num_items; + int current_bit; + int num_bits; + + // other thread variables + int warp; + int lane; + DecomposerT decomposer; + PortionOffsetT block_idx; + bool full_block; + + __device__ __forceinline__ digit_extractor_t digit_extractor() + { + return traits::template digit_extractor(current_bit, + num_bits, + decomposer); + } + + // helper methods + __device__ __forceinline__ std::uint32_t Digit(bit_ordered_type key) + { + return digit_extractor().Digit(key); + } + + __device__ __forceinline__ int ThreadBin(int u) + { + return threadIdx.x * BINS_PER_THREAD + u; + } + + __device__ __forceinline__ void LookbackPartial(int (&bins)[BINS_PER_THREAD]) + { + #pragma unroll + for (int u = 0; u < BINS_PER_THREAD; ++u) + { + int bin = ThreadBin(u); + if (FULL_BINS || bin < RADIX_DIGITS) + { + // write the local sum into the bin + AtomicOffsetT& loc = d_lookback[block_idx * RADIX_DIGITS + bin]; + PortionOffsetT value = bins[u] | LOOKBACK_PARTIAL_MASK; + ThreadStore(&loc, value); + } + } + } + + struct CountsCallback + { + typedef AgentRadixSortOnesweep AgentT; + AgentT& agent; + int (&bins)[BINS_PER_THREAD]; + bit_ordered_type (&keys)[ITEMS_PER_THREAD]; + static const bool EMPTY = false; + __device__ __forceinline__ CountsCallback( + AgentT& agent, int (&bins)[BINS_PER_THREAD], bit_ordered_type (&keys)[ITEMS_PER_THREAD]) + : agent(agent), bins(bins), keys(keys) {} + __device__ __forceinline__ void operator()(int (&other_bins)[BINS_PER_THREAD]) + { + #pragma unroll + for (int u = 0; u < BINS_PER_THREAD; ++u) + { + bins[u] = other_bins[u]; + } + agent.LookbackPartial(bins); + + agent.TryShortCircuit(keys, bins); + } + }; + + __device__ __forceinline__ void LookbackGlobal(int (&bins)[BINS_PER_THREAD]) + { + #pragma unroll + for (int u = 0; u < BINS_PER_THREAD; ++u) + { + int bin = ThreadBin(u); + if (FULL_BINS || bin < RADIX_DIGITS) + { + PortionOffsetT inc_sum = bins[u]; + int want_mask = ~0; + // backtrack as long as necessary + for (PortionOffsetT block_jdx = block_idx - 1; block_jdx >= 0; --block_jdx) + { + // wait for some value to appear + PortionOffsetT value_j = 0; + AtomicOffsetT& loc_j = d_lookback[block_jdx * RADIX_DIGITS + bin]; + do { + __threadfence_block(); // prevent hoisting loads from loop + value_j = ThreadLoad(&loc_j); + } while (value_j == 0); + + inc_sum += value_j & LOOKBACK_VALUE_MASK; + want_mask = WARP_BALLOT((value_j & LOOKBACK_GLOBAL_MASK) == 0, want_mask); + if (value_j & LOOKBACK_GLOBAL_MASK) break; + } + AtomicOffsetT& loc_i = d_lookback[block_idx * RADIX_DIGITS + bin]; + PortionOffsetT value_i = inc_sum | LOOKBACK_GLOBAL_MASK; + ThreadStore(&loc_i, value_i); + s.global_offsets[bin] += inc_sum - bins[u]; + } + } + } + + __device__ __forceinline__ + void LoadKeys(OffsetT tile_offset, bit_ordered_type (&keys)[ITEMS_PER_THREAD]) + { + if (full_block) + { + LoadDirectWarpStriped(threadIdx.x, d_keys_in + tile_offset, keys); + } + else + { + LoadDirectWarpStriped(threadIdx.x, d_keys_in + tile_offset, keys, + num_items - tile_offset, Twiddle::DefaultKey(decomposer)); + } + + #pragma unroll + for (int u = 0; u < ITEMS_PER_THREAD; ++u) + { + keys[u] = Twiddle::In(keys[u], decomposer); + } + } + + __device__ __forceinline__ + void LoadValues(OffsetT tile_offset, ValueT (&values)[ITEMS_PER_THREAD]) + { + if (full_block) + { + LoadDirectWarpStriped(threadIdx.x, d_values_in + tile_offset, values); + } + else + { + int tile_items = num_items - tile_offset; + LoadDirectWarpStriped(threadIdx.x, d_values_in + tile_offset, values, + tile_items); + } + } + + /** Checks whether "short-circuiting" is possible. Short-circuiting happens + * if all TILE_ITEMS keys fall into the same bin, i.e. have the same digit + * value (note that it only happens for full tiles). If short-circuiting is + * performed, the part of the ranking algorithm after the CountsCallback, as + * well as the rest of the sorting (e.g. scattering keys and values to + * shared and global memory) are skipped; updates related to decoupled + * look-back are still performed. Instead, the keys assigned to the current + * thread block are written cooperatively into a contiguous location in + * d_keys_out corresponding to their digit. The values (if also sorting + * values) assigned to the current thread block are similarly copied from + * d_values_in to d_values_out. */ + __device__ __forceinline__ + void TryShortCircuit(bit_ordered_type (&keys)[ITEMS_PER_THREAD], int (&bins)[BINS_PER_THREAD]) + { + // check if any bin can be short-circuited + bool short_circuit = false; + #pragma unroll + for (int u = 0; u < BINS_PER_THREAD; ++u) + { + if (FULL_BINS || ThreadBin(u) < RADIX_DIGITS) + { + short_circuit = short_circuit || bins[u] == TILE_ITEMS; + } + } + short_circuit = CTA_SYNC_OR(short_circuit); + if (!short_circuit) return; + + ShortCircuitCopy(keys, bins); + } + + __device__ __forceinline__ + void ShortCircuitCopy(bit_ordered_type (&keys)[ITEMS_PER_THREAD], int (&bins)[BINS_PER_THREAD]) + { + // short-circuit handling; note that global look-back is still required + + // compute offsets + std::uint32_t common_bin = Digit(keys[0]); + int offsets[BINS_PER_THREAD]; + #pragma unroll + for (int u = 0; u < BINS_PER_THREAD; ++u) + { + int bin = ThreadBin(u); + offsets[u] = bin > common_bin ? TILE_ITEMS : 0; + } + + // global lookback + LoadBinsToOffsetsGlobal(offsets); + LookbackGlobal(bins); + UpdateBinsGlobal(bins, offsets); + CTA_SYNC(); + + // scatter the keys + OffsetT global_offset = s.global_offsets[common_bin]; + #pragma unroll + for (int u = 0; u < ITEMS_PER_THREAD; ++u) + { + keys[u] = Twiddle::Out(keys[u], decomposer); + } + if (full_block) + { + StoreDirectWarpStriped(threadIdx.x, d_keys_out + global_offset, keys); + } + else + { + int tile_items = num_items - block_idx * TILE_ITEMS; + StoreDirectWarpStriped(threadIdx.x, d_keys_out + global_offset, keys, + tile_items); + } + + if (!KEYS_ONLY) + { + // gather and scatter the values + ValueT values[ITEMS_PER_THREAD]; + LoadValues(block_idx * TILE_ITEMS, values); + if (full_block) + { + StoreDirectWarpStriped(threadIdx.x, d_values_out + global_offset, values); + } + else + { + int tile_items = num_items - block_idx * TILE_ITEMS; + StoreDirectWarpStriped(threadIdx.x, d_values_out + global_offset, values, + tile_items); + } + } + + // exit early + ThreadExit(); + } + + __device__ __forceinline__ + void ScatterKeysShared(bit_ordered_type (&keys)[ITEMS_PER_THREAD], int (&ranks)[ITEMS_PER_THREAD]) + { + // write to shared memory + #pragma unroll + for (int u = 0; u < ITEMS_PER_THREAD; ++u) + { + s.keys_out[ranks[u]] = keys[u]; + } + } + + __device__ __forceinline__ + void ScatterValuesShared(ValueT (&values)[ITEMS_PER_THREAD], int (&ranks)[ITEMS_PER_THREAD]) + { + // write to shared memory + #pragma unroll + for (int u = 0; u < ITEMS_PER_THREAD; ++u) + { + s.values_out[ranks[u]] = values[u]; + } + } + + __device__ __forceinline__ void LoadBinsToOffsetsGlobal(int (&offsets)[BINS_PER_THREAD]) + { + // global offset - global part + #pragma unroll + for (int u = 0; u < BINS_PER_THREAD; ++u) + { + int bin = ThreadBin(u); + if (FULL_BINS || bin < RADIX_DIGITS) + { + s.global_offsets[bin] = d_bins_in[bin] - offsets[u]; + } + } + } + + __device__ __forceinline__ void UpdateBinsGlobal(int (&bins)[BINS_PER_THREAD], + int (&offsets)[BINS_PER_THREAD]) + { + bool last_block = (block_idx + 1) * TILE_ITEMS >= num_items; + if (d_bins_out != NULL && last_block) + { + #pragma unroll + for (int u = 0; u < BINS_PER_THREAD; ++u) + { + int bin = ThreadBin(u); + if (FULL_BINS || bin < RADIX_DIGITS) + { + d_bins_out[bin] = s.global_offsets[bin] + offsets[u] + bins[u]; + } + } + } + } + + template + __device__ __forceinline__ void ScatterKeysGlobalDirect() + { + int tile_items = FULL_TILE ? TILE_ITEMS : num_items - block_idx * TILE_ITEMS; + #pragma unroll + for (int u = 0; u < ITEMS_PER_THREAD; ++u) + { + int idx = threadIdx.x + u * BLOCK_THREADS; + bit_ordered_type key = s.keys_out[idx]; + OffsetT global_idx = idx + s.global_offsets[Digit(key)]; + if (FULL_TILE || idx < tile_items) + { + d_keys_out[global_idx] = Twiddle::Out(key, decomposer); + } + WARP_SYNC(WARP_MASK); + } + } + + template + __device__ __forceinline__ void ScatterValuesGlobalDirect(int (&digits)[ITEMS_PER_THREAD]) + { + int tile_items = FULL_TILE ? TILE_ITEMS : num_items - block_idx * TILE_ITEMS; + #pragma unroll + for (int u = 0; u < ITEMS_PER_THREAD; ++u) + { + int idx = threadIdx.x + u * BLOCK_THREADS; + ValueT value = s.values_out[idx]; + OffsetT global_idx = idx + s.global_offsets[digits[u]]; + if (FULL_TILE || idx < tile_items) d_values_out[global_idx] = value; + WARP_SYNC(WARP_MASK); + } + } + + __device__ __forceinline__ void ScatterKeysGlobalAligned() + { + // this only works with full tiles + const int ITEMS_PER_WARP = TILE_ITEMS / BLOCK_WARPS; + const int ALIGN = 8; + const auto CACHE_MODIFIER = STORE_CG; + + int warp_start = warp * ITEMS_PER_WARP; + int warp_end = (warp + 1) * ITEMS_PER_WARP; + int warp_offset = warp_start; + while (warp_offset < warp_end - WARP_THREADS) + { + int idx = warp_offset + lane; + bit_ordered_type key = s.keys_out[idx]; + bit_ordered_type key_out = Twiddle::Out(key, decomposer); + OffsetT global_idx = idx + s.global_offsets[Digit(key)]; + int last_lane = WARP_THREADS - 1; + int num_writes = WARP_THREADS; + if (lane == last_lane) + { + num_writes -= int(global_idx + 1) % ALIGN; + } + num_writes = SHFL_IDX_SYNC(num_writes, last_lane, WARP_MASK); + if (lane < num_writes) + { + ThreadStore(&d_keys_out[global_idx], key_out); + } + warp_offset += num_writes; + } + { + int num_writes = warp_end - warp_offset; + if (lane < num_writes) + { + int idx = warp_offset + lane; + bit_ordered_type key = s.keys_out[idx]; + OffsetT global_idx = idx + s.global_offsets[Digit(key)]; + ThreadStore(&d_keys_out[global_idx], Twiddle::Out(key, decomposer)); + } + } + } + + __device__ __forceinline__ void ScatterKeysGlobal() + { + // write block data to global memory + if (full_block) + { + if (STORE_ALGORITHM == RADIX_SORT_STORE_ALIGNED) + { + ScatterKeysGlobalAligned(); + } + else + { + ScatterKeysGlobalDirect(); + } + } + else + { + ScatterKeysGlobalDirect(); + } + } + + __device__ __forceinline__ void ScatterValuesGlobal(int (&digits)[ITEMS_PER_THREAD]) + { + // write block data to global memory + if (full_block) + { + ScatterValuesGlobalDirect(digits); + } + else + { + ScatterValuesGlobalDirect(digits); + } + } + + __device__ __forceinline__ void ComputeKeyDigits(int (&digits)[ITEMS_PER_THREAD]) + { + #pragma unroll + for (int u = 0; u < ITEMS_PER_THREAD; ++u) + { + int idx = threadIdx.x + u * BLOCK_THREADS; + digits[u] = Digit(s.keys_out[idx]); + } + } + + __device__ __forceinline__ void GatherScatterValues( + int (&ranks)[ITEMS_PER_THREAD], Int2Type keys_only) + { + // compute digits corresponding to the keys + int digits[ITEMS_PER_THREAD]; + ComputeKeyDigits(digits); + + // load values + ValueT values[ITEMS_PER_THREAD]; + LoadValues(block_idx * TILE_ITEMS, values); + + // scatter values + CTA_SYNC(); + ScatterValuesShared(values, ranks); + + CTA_SYNC(); + ScatterValuesGlobal(digits); + } + + + __device__ __forceinline__ void GatherScatterValues( + int (&ranks)[ITEMS_PER_THREAD], Int2Type keys_only) {} + + __device__ __forceinline__ void Process() + { + // load keys + // if warp1 < warp2, all elements of warp1 occur before those of warp2 + // in the source array + bit_ordered_type keys[ITEMS_PER_THREAD]; + LoadKeys(block_idx * TILE_ITEMS, keys); + + // rank keys + int ranks[ITEMS_PER_THREAD]; + int exclusive_digit_prefix[BINS_PER_THREAD]; + int bins[BINS_PER_THREAD]; + BlockRadixRankT(s.rank_temp_storage).RankKeys( + keys, ranks, digit_extractor(), exclusive_digit_prefix, + CountsCallback(*this, bins, keys)); + + // scatter keys in shared memory + CTA_SYNC(); + ScatterKeysShared(keys, ranks); + + // compute global offsets + LoadBinsToOffsetsGlobal(exclusive_digit_prefix); + LookbackGlobal(bins); + UpdateBinsGlobal(bins, exclusive_digit_prefix); + + // scatter keys in global memory + CTA_SYNC(); + ScatterKeysGlobal(); + + // scatter values if necessary + GatherScatterValues(ranks, Int2Type()); + } + + __device__ __forceinline__ // + AgentRadixSortOnesweep(TempStorage &temp_storage, + AtomicOffsetT *d_lookback, + AtomicOffsetT *d_ctrs, + OffsetT *d_bins_out, + const OffsetT *d_bins_in, + KeyT *d_keys_out, + const KeyT *d_keys_in, + ValueT *d_values_out, + const ValueT *d_values_in, + PortionOffsetT num_items, + int current_bit, + int num_bits, + DecomposerT decomposer = {}) + : s(temp_storage.Alias()) + , d_lookback(d_lookback) + , d_ctrs(d_ctrs) + , d_bins_out(d_bins_out) + , d_bins_in(d_bins_in) + , d_keys_out(reinterpret_cast(d_keys_out)) + , d_keys_in(reinterpret_cast(d_keys_in)) + , d_values_out(d_values_out) + , d_values_in(d_values_in) + , num_items(num_items) + , current_bit(current_bit) + , num_bits(num_bits) + , warp(threadIdx.x / WARP_THREADS) + , lane(LaneId()) + , decomposer(decomposer) + { + // initialization + if (threadIdx.x == 0) + { + s.block_idx = atomicAdd(d_ctrs, 1); + } + CTA_SYNC(); + block_idx = s.block_idx; + full_block = (block_idx + 1) * TILE_ITEMS <= num_items; + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_upsweep.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_upsweep.cuh new file mode 100644 index 0000000000000000000000000000000000000000..1918fb5f5ebc8e9d190052c58cbf838ad8e44af8 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_radix_sort_upsweep.cuh @@ -0,0 +1,531 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * AgentRadixSortUpsweep implements a stateful abstraction of CUDA thread blocks for participating in device-wide radix sort upsweep . + */ + +#pragma once + +#include "../thread/thread_reduce.cuh" +#include "../thread/thread_load.cuh" +#include "../warp/warp_reduce.cuh" +#include "../block/block_load.cuh" +#include "../block/radix_rank_sort_operations.cuh" +#include "../config.cuh" +#include "../util_type.cuh" +#include "../iterator/cache_modified_input_iterator.cuh" + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Tuning policy types + ******************************************************************************/ + +/** + * Parameterizable tuning policy type for AgentRadixSortUpsweep + */ +template < + int NOMINAL_BLOCK_THREADS_4B, ///< Threads per thread block + int NOMINAL_ITEMS_PER_THREAD_4B, ///< Items per thread (per tile of input) + typename ComputeT, ///< Dominant compute type + CacheLoadModifier _LOAD_MODIFIER, ///< Cache load modifier for reading keys + int _RADIX_BITS, ///< The number of radix bits, i.e., log2(bins) + typename ScalingType = RegBoundScaling > +struct AgentRadixSortUpsweepPolicy : + ScalingType +{ + enum + { + RADIX_BITS = _RADIX_BITS, ///< The number of radix bits, i.e., log2(bins) + }; + + static const CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; ///< Cache load modifier for reading keys +}; + + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + +/** + * \brief AgentRadixSortUpsweep implements a stateful abstraction of CUDA thread blocks for participating in device-wide radix sort upsweep . + */ +template < + typename AgentRadixSortUpsweepPolicy, ///< Parameterized AgentRadixSortUpsweepPolicy tuning policy type + typename KeyT, ///< KeyT type + typename OffsetT, + typename DecomposerT = detail::identity_decomposer_t> ///< Signed integer type for global offsets +struct AgentRadixSortUpsweep +{ + + //--------------------------------------------------------------------- + // Type definitions and constants + //--------------------------------------------------------------------- + using traits = detail::radix::traits_t; + using bit_ordered_type = typename traits::bit_ordered_type; + using bit_ordered_conversion = typename traits::bit_ordered_conversion_policy; + + // Integer type for digit counters (to be packed into words of PackedCounters) + typedef unsigned char DigitCounter; + + // Integer type for packing DigitCounters into columns of shared memory banks + typedef unsigned int PackedCounter; + + static const CacheLoadModifier LOAD_MODIFIER = AgentRadixSortUpsweepPolicy::LOAD_MODIFIER; + + enum + { + RADIX_BITS = AgentRadixSortUpsweepPolicy::RADIX_BITS, + BLOCK_THREADS = AgentRadixSortUpsweepPolicy::BLOCK_THREADS, + KEYS_PER_THREAD = AgentRadixSortUpsweepPolicy::ITEMS_PER_THREAD, + + RADIX_DIGITS = 1 << RADIX_BITS, + + LOG_WARP_THREADS = CUB_PTX_LOG_WARP_THREADS, + WARP_THREADS = 1 << LOG_WARP_THREADS, + WARPS = (BLOCK_THREADS + WARP_THREADS - 1) / WARP_THREADS, + + TILE_ITEMS = BLOCK_THREADS * KEYS_PER_THREAD, + + BYTES_PER_COUNTER = sizeof(DigitCounter), + LOG_BYTES_PER_COUNTER = Log2::VALUE, + + PACKING_RATIO = sizeof(PackedCounter) / sizeof(DigitCounter), + LOG_PACKING_RATIO = Log2::VALUE, + + LOG_COUNTER_LANES = CUB_MAX(0, int(RADIX_BITS) - int(LOG_PACKING_RATIO)), + COUNTER_LANES = 1 << LOG_COUNTER_LANES, + + // To prevent counter overflow, we must periodically unpack and aggregate the + // digit counters back into registers. Each counter lane is assigned to a + // warp for aggregation. + + LANES_PER_WARP = CUB_MAX(1, (COUNTER_LANES + WARPS - 1) / WARPS), + + // Unroll tiles in batches without risk of counter overflow + UNROLL_COUNT = CUB_MIN(64, 255 / KEYS_PER_THREAD), + UNROLLED_ELEMENTS = UNROLL_COUNT * TILE_ITEMS, + }; + + + // Input iterator wrapper type (for applying cache modifier)s + typedef CacheModifiedInputIterator KeysItr; + + // Digit extractor type + using fundamental_digit_extractor_t = BFEDigitExtractor; + using digit_extractor_t = + typename traits::template digit_extractor_t; + + /** + * Shared memory storage layout + */ + union __align__(16) _TempStorage + { + DigitCounter thread_counters[COUNTER_LANES][BLOCK_THREADS][PACKING_RATIO]; + PackedCounter packed_thread_counters[COUNTER_LANES][BLOCK_THREADS]; + OffsetT block_counters[WARP_THREADS][RADIX_DIGITS]; + }; + + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + //--------------------------------------------------------------------- + // Thread fields (aggregate state bundle) + //--------------------------------------------------------------------- + + // Shared storage for this CTA + _TempStorage &temp_storage; + + // Thread-local counters for periodically aggregating composite-counter lanes + OffsetT local_counts[LANES_PER_WARP][PACKING_RATIO]; + + // Input and output device pointers + KeysItr d_keys_in; + + // Target bits + int current_bit; + int num_bits; + DecomposerT decomposer; + + //--------------------------------------------------------------------- + // Helper structure for templated iteration + //--------------------------------------------------------------------- + + // Iterate + template + struct Iterate + { + // BucketKeys + static __device__ __forceinline__ void BucketKeys( + AgentRadixSortUpsweep &cta, + bit_ordered_type keys[KEYS_PER_THREAD]) + { + cta.Bucket(keys[COUNT]); + + // Next + Iterate::BucketKeys(cta, keys); + } + }; + + // Terminate + template + struct Iterate + { + // BucketKeys + static __device__ __forceinline__ void BucketKeys(AgentRadixSortUpsweep &/*cta*/, bit_ordered_type /*keys*/[KEYS_PER_THREAD]) {} + }; + + + //--------------------------------------------------------------------- + // Utility methods + //--------------------------------------------------------------------- + __device__ __forceinline__ digit_extractor_t digit_extractor() + { + return traits::template digit_extractor(current_bit, num_bits, decomposer); + } + + /** + * Decode a key and increment corresponding smem digit counter + */ + __device__ __forceinline__ void Bucket(bit_ordered_type key) + { + // Perform transform op + bit_ordered_type converted_key = bit_ordered_conversion::to_bit_ordered(decomposer, key); + + // Extract current digit bits + std::uint32_t digit = digit_extractor().Digit(converted_key); + + // Get sub-counter offset + std::uint32_t sub_counter = digit & (PACKING_RATIO - 1); + + // Get row offset + std::uint32_t row_offset = digit >> LOG_PACKING_RATIO; + + // Increment counter + temp_storage.thread_counters[row_offset][threadIdx.x][sub_counter]++; + } + + + /** + * Reset composite counters + */ + __device__ __forceinline__ void ResetDigitCounters() + { + #pragma unroll + for (int LANE = 0; LANE < COUNTER_LANES; LANE++) + { + temp_storage.packed_thread_counters[LANE][threadIdx.x] = 0; + } + } + + + /** + * Reset the unpacked counters in each thread + */ + __device__ __forceinline__ void ResetUnpackedCounters() + { + #pragma unroll + for (int LANE = 0; LANE < LANES_PER_WARP; LANE++) + { + #pragma unroll + for (int UNPACKED_COUNTER = 0; UNPACKED_COUNTER < PACKING_RATIO; UNPACKED_COUNTER++) + { + local_counts[LANE][UNPACKED_COUNTER] = 0; + } + } + } + + + /** + * Extracts and aggregates the digit counters for each counter lane + * owned by this warp + */ + __device__ __forceinline__ void UnpackDigitCounts() + { + unsigned int warp_id = threadIdx.x >> LOG_WARP_THREADS; + unsigned int warp_tid = LaneId(); + + #pragma unroll + for (int LANE = 0; LANE < LANES_PER_WARP; LANE++) + { + const int counter_lane = (LANE * WARPS) + warp_id; + if (counter_lane < COUNTER_LANES) + { + #pragma unroll + for (int PACKED_COUNTER = 0; PACKED_COUNTER < BLOCK_THREADS; PACKED_COUNTER += WARP_THREADS) + { + #pragma unroll + for (int UNPACKED_COUNTER = 0; UNPACKED_COUNTER < PACKING_RATIO; UNPACKED_COUNTER++) + { + OffsetT counter = temp_storage.thread_counters[counter_lane][warp_tid + PACKED_COUNTER][UNPACKED_COUNTER]; + local_counts[LANE][UNPACKED_COUNTER] += counter; + } + } + } + } + } + + + /** + * Processes a single, full tile + */ + __device__ __forceinline__ void ProcessFullTile(OffsetT block_offset) + { + // Tile of keys + bit_ordered_type keys[KEYS_PER_THREAD]; + + LoadDirectStriped(threadIdx.x, d_keys_in + block_offset, keys); + + // Prevent hoisting + CTA_SYNC(); + + // Bucket tile of keys + Iterate<0, KEYS_PER_THREAD>::BucketKeys(*this, keys); + } + + + /** + * Processes a single load (may have some threads masked off) + */ + __device__ __forceinline__ void ProcessPartialTile( + OffsetT block_offset, + const OffsetT &block_end) + { + // Process partial tile if necessary using single loads + for (OffsetT offset = threadIdx.x; offset < block_end - block_offset; offset += BLOCK_THREADS) + { + // Load and bucket key + bit_ordered_type key = d_keys_in[block_offset + offset]; + Bucket(key); + } + } + + + //--------------------------------------------------------------------- + // Interface + //--------------------------------------------------------------------- + + /** + * Constructor + */ + __device__ __forceinline__ AgentRadixSortUpsweep( + TempStorage &temp_storage, + const KeyT *d_keys_in, + int current_bit, + int num_bits, + DecomposerT decomposer = {}) + : + temp_storage(temp_storage.Alias()), + d_keys_in(reinterpret_cast(d_keys_in)), + current_bit(current_bit), + num_bits(num_bits), + decomposer(decomposer) + {} + + + /** + * Compute radix digit histograms from a segment of input tiles. + */ + __device__ __forceinline__ void ProcessRegion( + OffsetT block_offset, + const OffsetT &block_end) + { + // Reset digit counters in smem and unpacked counters in registers + ResetDigitCounters(); + ResetUnpackedCounters(); + + // Unroll batches of full tiles + while (block_end - block_offset >= UNROLLED_ELEMENTS) + { + for (int i = 0; i < UNROLL_COUNT; ++i) + { + ProcessFullTile(block_offset); + block_offset += TILE_ITEMS; + } + + CTA_SYNC(); + + // Aggregate back into local_count registers to prevent overflow + UnpackDigitCounts(); + + CTA_SYNC(); + + // Reset composite counters in lanes + ResetDigitCounters(); + } + + // Unroll single full tiles + while (block_end - block_offset >= TILE_ITEMS) + { + ProcessFullTile(block_offset); + block_offset += TILE_ITEMS; + } + + // Process partial tile if necessary + ProcessPartialTile( + block_offset, + block_end); + + CTA_SYNC(); + + // Aggregate back into local_count registers + UnpackDigitCounts(); + } + + + /** + * Extract counts (saving them to the external array) + */ + template + __device__ __forceinline__ void ExtractCounts( + OffsetT *counters, + int bin_stride = 1, + int bin_offset = 0) + { + unsigned int warp_id = threadIdx.x >> LOG_WARP_THREADS; + unsigned int warp_tid = LaneId(); + + // Place unpacked digit counters in shared memory + #pragma unroll + for (int LANE = 0; LANE < LANES_PER_WARP; LANE++) + { + int counter_lane = (LANE * WARPS) + warp_id; + if (counter_lane < COUNTER_LANES) + { + int digit_row = counter_lane << LOG_PACKING_RATIO; + + #pragma unroll + for (int UNPACKED_COUNTER = 0; UNPACKED_COUNTER < PACKING_RATIO; UNPACKED_COUNTER++) + { + int bin_idx = digit_row + UNPACKED_COUNTER; + + temp_storage.block_counters[warp_tid][bin_idx] = + local_counts[LANE][UNPACKED_COUNTER]; + } + } + } + + CTA_SYNC(); + + // Rake-reduce bin_count reductions + + // Whole blocks + #pragma unroll + for (int BIN_BASE = RADIX_DIGITS % BLOCK_THREADS; + (BIN_BASE + BLOCK_THREADS) <= RADIX_DIGITS; + BIN_BASE += BLOCK_THREADS) + { + int bin_idx = BIN_BASE + threadIdx.x; + + OffsetT bin_count = 0; + #pragma unroll + for (int i = 0; i < WARP_THREADS; ++i) + bin_count += temp_storage.block_counters[i][bin_idx]; + + if (IS_DESCENDING) + bin_idx = RADIX_DIGITS - bin_idx - 1; + + counters[(bin_stride * bin_idx) + bin_offset] = bin_count; + } + + // Remainder + if ((RADIX_DIGITS % BLOCK_THREADS != 0) && (threadIdx.x < RADIX_DIGITS)) + { + int bin_idx = threadIdx.x; + + OffsetT bin_count = 0; + #pragma unroll + for (int i = 0; i < WARP_THREADS; ++i) + bin_count += temp_storage.block_counters[i][bin_idx]; + + if (IS_DESCENDING) + bin_idx = RADIX_DIGITS - bin_idx - 1; + + counters[(bin_stride * bin_idx) + bin_offset] = bin_count; + } + } + + + /** + * Extract counts + */ + template + __device__ __forceinline__ void ExtractCounts( + OffsetT (&bin_count)[BINS_TRACKED_PER_THREAD]) ///< [out] The exclusive prefix sum for the digits [(threadIdx.x * BINS_TRACKED_PER_THREAD) ... (threadIdx.x * BINS_TRACKED_PER_THREAD) + BINS_TRACKED_PER_THREAD - 1] + { + unsigned int warp_id = threadIdx.x >> LOG_WARP_THREADS; + unsigned int warp_tid = LaneId(); + + // Place unpacked digit counters in shared memory + #pragma unroll + for (int LANE = 0; LANE < LANES_PER_WARP; LANE++) + { + int counter_lane = (LANE * WARPS) + warp_id; + if (counter_lane < COUNTER_LANES) + { + int digit_row = counter_lane << LOG_PACKING_RATIO; + + #pragma unroll + for (int UNPACKED_COUNTER = 0; UNPACKED_COUNTER < PACKING_RATIO; UNPACKED_COUNTER++) + { + int bin_idx = digit_row + UNPACKED_COUNTER; + + temp_storage.block_counters[warp_tid][bin_idx] = + local_counts[LANE][UNPACKED_COUNTER]; + } + } + } + + CTA_SYNC(); + + // Rake-reduce bin_count reductions + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + bin_count[track] = 0; + + #pragma unroll + for (int i = 0; i < WARP_THREADS; ++i) + bin_count[track] += temp_storage.block_counters[i][bin_idx]; + } + } + } + +}; + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_reduce.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_reduce.cuh new file mode 100644 index 0000000000000000000000000000000000000000..4a29d707b3034e2e84bd880e748473543cfe90ec --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_reduce.cuh @@ -0,0 +1,475 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::AgentReduce implements a stateful abstraction of CUDA thread + * blocks for participating in device-wide reduction. + */ + +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Tuning policy types + ******************************************************************************/ + +/** + * Parameterizable tuning policy type for AgentReduce + * @tparam NOMINAL_BLOCK_THREADS_4B Threads per thread block + * @tparam NOMINAL_ITEMS_PER_THREAD_4B Items per thread (per tile of input) + * @tparam ComputeT Dominant compute type + * @tparam _VECTOR_LOAD_LENGTH Number of items per vectorized load + * @tparam _BLOCK_ALGORITHM Cooperative block-wide reduction algorithm to use + * @tparam _LOAD_MODIFIER Cache load modifier for reading input elements + */ +template > +struct AgentReducePolicy : ScalingType +{ + /// Number of items per vectorized load + static constexpr int VECTOR_LOAD_LENGTH = _VECTOR_LOAD_LENGTH; + + /// Cooperative block-wide reduction algorithm to use + static constexpr BlockReduceAlgorithm BLOCK_ALGORITHM = _BLOCK_ALGORITHM; + + /// Cache load modifier for reading input elements + static constexpr CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; +}; + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + +/** + * @brief AgentReduce implements a stateful abstraction of CUDA thread blocks + * for participating in device-wide reduction . + * + * Each thread reduces only the values it loads. If `FIRST_TILE`, this partial + * reduction is stored into `thread_aggregate`. Otherwise it is accumulated + * into `thread_aggregate`. + * + * @tparam AgentReducePolicy + * Parameterized AgentReducePolicy tuning policy type + * + * @tparam InputIteratorT + * Random-access iterator type for input + * + * @tparam OutputIteratorT + * Random-access iterator type for output + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam ReductionOp + * Binary reduction operator type having member + * `auto operator()(T &&a, U &&b)` + * + * @tparam AccumT + * The type of intermediate accumulator (according to P2322R6) + */ +template +struct AgentReduce +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + /// The input value type + using InputT = cub::detail::value_t; + + /// Vector type of InputT for data movement + using VectorT = + typename CubVector::Type; + + /// Input iterator wrapper type (for applying cache modifier) + // Wrap the native input pointer with CacheModifiedInputIterator + // or directly use the supplied input iterator type + using WrappedInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + InputIteratorT>; + + /// Constants + static constexpr int BLOCK_THREADS = AgentReducePolicy::BLOCK_THREADS; + static constexpr int ITEMS_PER_THREAD = AgentReducePolicy::ITEMS_PER_THREAD; + static constexpr int TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD; + static constexpr int VECTOR_LOAD_LENGTH = + CUB_MIN(ITEMS_PER_THREAD, AgentReducePolicy::VECTOR_LOAD_LENGTH); + + // Can vectorize according to the policy if the input iterator is a native + // pointer to a primitive type + static constexpr bool ATTEMPT_VECTORIZATION = (VECTOR_LOAD_LENGTH > 1) && + (ITEMS_PER_THREAD % VECTOR_LOAD_LENGTH == 0) && + (std::is_pointer::value) && + Traits::PRIMITIVE; + + static constexpr CacheLoadModifier LOAD_MODIFIER = + AgentReducePolicy::LOAD_MODIFIER; + + static constexpr BlockReduceAlgorithm BLOCK_ALGORITHM = + AgentReducePolicy::BLOCK_ALGORITHM; + + /// Parameterized BlockReduce primitive + using BlockReduceT = + BlockReduce; + + /// Shared memory type required by this thread block + struct _TempStorage + { + typename BlockReduceT::TempStorage reduce; + }; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> + {}; + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + _TempStorage &temp_storage; ///< Reference to temp_storage + InputIteratorT d_in; ///< Input data to reduce + WrappedInputIteratorT d_wrapped_in; ///< Wrapped input data to reduce + ReductionOp reduction_op; ///< Binary reduction operator + + //--------------------------------------------------------------------- + // Utility + //--------------------------------------------------------------------- + + // Whether or not the input is aligned with the vector type (specialized for + // types we can vectorize) + template + static __device__ __forceinline__ bool + IsAligned(Iterator d_in, Int2Type /*can_vectorize*/) + { + return (size_t(d_in) & (sizeof(VectorT) - 1)) == 0; + } + + // Whether or not the input is aligned with the vector type (specialized for + // types we cannot vectorize) + template + static __device__ __forceinline__ bool + IsAligned(Iterator /*d_in*/, Int2Type /*can_vectorize*/) + { + return false; + } + + //--------------------------------------------------------------------- + // Constructor + //--------------------------------------------------------------------- + + /** + * @brief Constructor + * @param temp_storage Reference to temp_storage + * @param d_in Input data to reduce + * @param reduction_op Binary reduction operator + */ + __device__ __forceinline__ AgentReduce(TempStorage &temp_storage, + InputIteratorT d_in, + ReductionOp reduction_op) + : temp_storage(temp_storage.Alias()) + , d_in(d_in) + , d_wrapped_in(d_in) + , reduction_op(reduction_op) + {} + + //--------------------------------------------------------------------- + // Tile consumption + //--------------------------------------------------------------------- + + /** + * @brief Consume a full tile of input (non-vectorized) + * @param block_offset The offset the tile to consume + * @param valid_items The number of valid items in the tile + * @param is_full_tile Whether or not this is a full tile + * @param can_vectorize Whether or not we can vectorize loads + */ + template + __device__ __forceinline__ void ConsumeTile(AccumT &thread_aggregate, + OffsetT block_offset, + int /*valid_items*/, + Int2Type /*is_full_tile*/, + Int2Type /*can_vectorize*/) + { + AccumT items[ITEMS_PER_THREAD]; + + // Load items in striped fashion + LoadDirectStriped(threadIdx.x, + d_wrapped_in + block_offset, + items); + + // Reduce items within each thread stripe + thread_aggregate = + (IS_FIRST_TILE) + ? internal::ThreadReduce(items, reduction_op) + : internal::ThreadReduce(items, reduction_op, thread_aggregate); + } + + /** + * Consume a full tile of input (vectorized) + * @param block_offset The offset the tile to consume + * @param valid_items The number of valid items in the tile + * @param is_full_tile Whether or not this is a full tile + * @param can_vectorize Whether or not we can vectorize loads + */ + template + __device__ __forceinline__ void ConsumeTile(AccumT &thread_aggregate, + OffsetT block_offset, + int /*valid_items*/, + Int2Type /*is_full_tile*/, + Int2Type /*can_vectorize*/) + { + // Alias items as an array of VectorT and load it in striped fashion + enum + { + WORDS = ITEMS_PER_THREAD / VECTOR_LOAD_LENGTH + }; + + // Fabricate a vectorized input iterator + InputT *d_in_unqualified = const_cast(d_in) + block_offset + + (threadIdx.x * VECTOR_LOAD_LENGTH); + CacheModifiedInputIterator + d_vec_in(reinterpret_cast(d_in_unqualified)); + + // Load items as vector items + InputT input_items[ITEMS_PER_THREAD]; + VectorT *vec_items = reinterpret_cast(input_items); +#pragma unroll + for (int i = 0; i < WORDS; ++i) + { + vec_items[i] = d_vec_in[BLOCK_THREADS * i]; + } + + // Convert from input type to output type + AccumT items[ITEMS_PER_THREAD]; +#pragma unroll + for (int i = 0; i < ITEMS_PER_THREAD; ++i) + { + items[i] = input_items[i]; + } + + // Reduce items within each thread stripe + thread_aggregate = + (IS_FIRST_TILE) + ? internal::ThreadReduce(items, reduction_op) + : internal::ThreadReduce(items, reduction_op, thread_aggregate); + } + + /** + * Consume a partial tile of input + * @param block_offset The offset the tile to consume + * @param valid_items The number of valid items in the tile + * @param is_full_tile Whether or not this is a full tile + * @param can_vectorize Whether or not we can vectorize loads + */ + template + __device__ __forceinline__ void + ConsumeTile(AccumT &thread_aggregate, + OffsetT block_offset, + int valid_items, + Int2Type /*is_full_tile*/, + Int2Type /*can_vectorize*/) + { + // Partial tile + int thread_offset = threadIdx.x; + + // Read first item + if ((IS_FIRST_TILE) && (thread_offset < valid_items)) + { + thread_aggregate = d_wrapped_in[block_offset + thread_offset]; + thread_offset += BLOCK_THREADS; + } + + // Continue reading items (block-striped) + while (thread_offset < valid_items) + { + InputT item(d_wrapped_in[block_offset + thread_offset]); + + thread_aggregate = reduction_op(thread_aggregate, item); + thread_offset += BLOCK_THREADS; + } + } + + //--------------------------------------------------------------- + // Consume a contiguous segment of tiles + //--------------------------------------------------------------------- + + /** + * @brief Reduce a contiguous segment of input tiles + * @param even_share GridEvenShare descriptor + * @param can_vectorize Whether or not we can vectorize loads + */ + template + __device__ __forceinline__ AccumT + ConsumeRange(GridEvenShare &even_share, + Int2Type can_vectorize) + { + AccumT thread_aggregate{}; + + if (even_share.block_end - even_share.block_offset < TILE_ITEMS) + { + // First tile isn't full (not all threads have valid items) + int valid_items = even_share.block_end - even_share.block_offset; + ConsumeTile(thread_aggregate, + even_share.block_offset, + valid_items, + Int2Type(), + can_vectorize); + return BlockReduceT(temp_storage.reduce) + .Reduce(thread_aggregate, reduction_op, valid_items); + } + + // Extracting this into a function saves 8% of generated kernel size by allowing to reuse + // the block reduction below. This also workaround hang in nvcc. + ConsumeFullTileRange(thread_aggregate, even_share, can_vectorize); + + // Compute block-wide reduction (all threads have valid items) + return BlockReduceT(temp_storage.reduce) + .Reduce(thread_aggregate, reduction_op); + } + + /** + * @brief Reduce a contiguous segment of input tiles + * @param[in] block_offset Threadblock begin offset (inclusive) + * @param[in] block_end Threadblock end offset (exclusive) + */ + __device__ __forceinline__ AccumT ConsumeRange(OffsetT block_offset, + OffsetT block_end) + { + GridEvenShare even_share; + even_share.template BlockInit(block_offset, block_end); + + return (IsAligned(d_in + block_offset, Int2Type())) + ? ConsumeRange(even_share, + Int2Type < true && ATTEMPT_VECTORIZATION > ()) + : ConsumeRange(even_share, + Int2Type < false && ATTEMPT_VECTORIZATION > ()); + } + + /** + * Reduce a contiguous segment of input tiles + * @param[in] even_share GridEvenShare descriptor + */ + __device__ __forceinline__ AccumT + ConsumeTiles(GridEvenShare &even_share) + { + // Initialize GRID_MAPPING_STRIP_MINE even-share descriptor for this thread block + even_share.template BlockInit(); + + return (IsAligned(d_in, Int2Type())) + ? ConsumeRange(even_share, + Int2Type < true && ATTEMPT_VECTORIZATION > ()) + : ConsumeRange(even_share, + Int2Type < false && ATTEMPT_VECTORIZATION > ()); + } + +private: + /** + * @brief Reduce a contiguous segment of input tiles with more than `TILE_ITEMS` elements + * @param even_share GridEvenShare descriptor + * @param can_vectorize Whether or not we can vectorize loads + */ + template + __device__ __forceinline__ void + ConsumeFullTileRange(AccumT &thread_aggregate, + GridEvenShare &even_share, + Int2Type can_vectorize) + { + // At least one full block + ConsumeTile(thread_aggregate, + even_share.block_offset, + TILE_ITEMS, + Int2Type(), + can_vectorize); + + if (even_share.block_end - even_share.block_offset < even_share.block_stride) + { + // Exit early to handle offset overflow + return; + } + + even_share.block_offset += even_share.block_stride; + + // Consume subsequent full tiles of input, at least one full tile was processed, so + // `even_share.block_end >= TILE_ITEMS` + while (even_share.block_offset <= even_share.block_end - TILE_ITEMS) + { + ConsumeTile(thread_aggregate, + even_share.block_offset, + TILE_ITEMS, + Int2Type(), + can_vectorize); + + if (even_share.block_end - even_share.block_offset < even_share.block_stride) + { + // Exit early to handle offset overflow + return; + } + + even_share.block_offset += even_share.block_stride; + } + + // Consume a partially-full tile + if (even_share.block_offset < even_share.block_end) + { + int valid_items = even_share.block_end - even_share.block_offset; + ConsumeTile(thread_aggregate, + even_share.block_offset, + valid_items, + Int2Type(), + can_vectorize); + } + } +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_reduce_by_key.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_reduce_by_key.cuh new file mode 100644 index 0000000000000000000000000000000000000000..6eb001b26834f6e7f2f6c06db7a16207c332e901 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_reduce_by_key.cuh @@ -0,0 +1,694 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::AgentReduceByKey implements a stateful abstraction of CUDA thread + * blocks for participating in device-wide reduce-value-by-key. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Tuning policy types + ******************************************************************************/ + +/** + * @brief Parameterizable tuning policy type for AgentReduceByKey + * + * @tparam _BLOCK_THREADS + * Threads per thread block + * + * @tparam _ITEMS_PER_THREAD + * Items per thread (per tile of input) + * + * @tparam _LOAD_ALGORITHM + * The BlockLoad algorithm to use + * + * @tparam _LOAD_MODIFIER + * Cache load modifier for reading input elements + * + * @tparam _SCAN_ALGORITHM + * The BlockScan algorithm to use + * + * @tparam DelayConstructorT + * Implementation detail, do not specify directly, requirements on the + * content of this type are subject to breaking change. + */ +template > +struct AgentReduceByKeyPolicy +{ + ///< Threads per thread block + static constexpr int BLOCK_THREADS = _BLOCK_THREADS; + + ///< Items per thread (per tile of input) + static constexpr int ITEMS_PER_THREAD = _ITEMS_PER_THREAD; + + ///< The BlockLoad algorithm to use + static constexpr BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; + + ///< Cache load modifier for reading input elements + static constexpr CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; + + ///< The BlockScan algorithm to use + static constexpr const BlockScanAlgorithm SCAN_ALGORITHM = _SCAN_ALGORITHM; + + struct detail + { + using delay_constructor_t = DelayConstructorT; + }; +}; + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + +/** + * @brief AgentReduceByKey implements a stateful abstraction of CUDA thread + * blocks for participating in device-wide reduce-value-by-key + * + * @tparam AgentReduceByKeyPolicyT + * Parameterized AgentReduceByKeyPolicy tuning policy type + * + * @tparam KeysInputIteratorT + * Random-access input iterator type for keys + * + * @tparam UniqueOutputIteratorT + * Random-access output iterator type for keys + * + * @tparam ValuesInputIteratorT + * Random-access input iterator type for values + * + * @tparam AggregatesOutputIteratorT + * Random-access output iterator type for values + * + * @tparam NumRunsOutputIteratorT + * Output iterator type for recording number of items selected + * + * @tparam EqualityOpT + * KeyT equality operator type + * + * @tparam ReductionOpT + * ValueT reduction operator type + * + * @tparam OffsetT + * Signed integer type for global offsets + */ +template +struct AgentReduceByKey +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + // The input keys type + using KeyInputT = cub::detail::value_t; + + // The output keys type + using KeyOutputT = cub::detail::non_void_value_t; + + // The input values type + using ValueInputT = cub::detail::value_t; + + // Tuple type for scanning (pairs accumulated segment-value with + // segment-index) + using OffsetValuePairT = KeyValuePair; + + // Tuple type for pairing keys and values + using KeyValuePairT = KeyValuePair; + + // Tile status descriptor interface type + using ScanTileStateT = ReduceByKeyScanTileState; + + // Guarded inequality functor + template + struct GuardedInequalityWrapper + { + /// Wrapped equality operator + _EqualityOpT op; + + /// Items remaining + int num_remaining; + + /// Constructor + __host__ __device__ __forceinline__ GuardedInequalityWrapper(_EqualityOpT op, int num_remaining) + : op(op) + , num_remaining(num_remaining) + {} + + /// Boolean inequality operator, returns (a != b) + template + __host__ __device__ __forceinline__ bool operator()(const T &a, const T &b, int idx) const + { + if (idx < num_remaining) + { + return !op(a, b); // In bounds + } + + // Return true if first out-of-bounds item, false otherwise + return (idx == num_remaining); + } + }; + + // Constants + static constexpr int BLOCK_THREADS = AgentReduceByKeyPolicyT::BLOCK_THREADS; + static constexpr int ITEMS_PER_THREAD = AgentReduceByKeyPolicyT::ITEMS_PER_THREAD; + static constexpr int TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD; + static constexpr int TWO_PHASE_SCATTER = (ITEMS_PER_THREAD > 1); + + // Whether or not the scan operation has a zero-valued identity value (true + // if we're performing addition on a primitive type) + static constexpr int HAS_IDENTITY_ZERO = (std::is_same::value) && + (Traits::PRIMITIVE); + + // Cache-modified Input iterator wrapper type (for applying cache modifier) + // for keys Wrap the native input pointer with + // CacheModifiedValuesInputIterator or directly use the supplied input + // iterator type + using WrappedKeysInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + KeysInputIteratorT>; + + // Cache-modified Input iterator wrapper type (for applying cache modifier) + // for values Wrap the native input pointer with + // CacheModifiedValuesInputIterator or directly use the supplied input + // iterator type + using WrappedValuesInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + ValuesInputIteratorT>; + + // Cache-modified Input iterator wrapper type (for applying cache modifier) + // for fixup values Wrap the native input pointer with + // CacheModifiedValuesInputIterator or directly use the supplied input + // iterator type + using WrappedFixupInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + AggregatesOutputIteratorT>; + + // Reduce-value-by-segment scan operator + using ReduceBySegmentOpT = ReduceBySegmentOp; + + // Parameterized BlockLoad type for keys + using BlockLoadKeysT = + BlockLoad; + + // Parameterized BlockLoad type for values + using BlockLoadValuesT = + BlockLoad; + + // Parameterized BlockDiscontinuity type for keys + using BlockDiscontinuityKeys = BlockDiscontinuity; + + // Parameterized BlockScan type + using BlockScanT = + BlockScan; + + // Callback type for obtaining tile prefix during block scan + using DelayConstructorT = typename AgentReduceByKeyPolicyT::detail::delay_constructor_t; + using TilePrefixCallbackOpT = + TilePrefixCallbackOp; + + // Key and value exchange types + typedef KeyOutputT KeyExchangeT[TILE_ITEMS + 1]; + typedef AccumT ValueExchangeT[TILE_ITEMS + 1]; + + // Shared memory type for this thread block + union _TempStorage + { + struct ScanStorage + { + // Smem needed for tile scanning + typename BlockScanT::TempStorage scan; + + // Smem needed for cooperative prefix callback + typename TilePrefixCallbackOpT::TempStorage prefix; + + // Smem needed for discontinuity detection + typename BlockDiscontinuityKeys::TempStorage discontinuity; + } scan_storage; + + // Smem needed for loading keys + typename BlockLoadKeysT::TempStorage load_keys; + + // Smem needed for loading values + typename BlockLoadValuesT::TempStorage load_values; + + // Smem needed for compacting key value pairs(allows non POD items in this + // union) + Uninitialized raw_exchange; + }; + + // Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> + {}; + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + /// Reference to temp_storage + _TempStorage &temp_storage; + + /// Input keys + WrappedKeysInputIteratorT d_keys_in; + + /// Unique output keys + UniqueOutputIteratorT d_unique_out; + + /// Input values + WrappedValuesInputIteratorT d_values_in; + + /// Output value aggregates + AggregatesOutputIteratorT d_aggregates_out; + + /// Output pointer for total number of segments identified + NumRunsOutputIteratorT d_num_runs_out; + + /// KeyT equality operator + EqualityOpT equality_op; + + /// Reduction operator + ReductionOpT reduction_op; + + /// Reduce-by-segment scan operator + ReduceBySegmentOpT scan_op; + + //--------------------------------------------------------------------- + // Constructor + //--------------------------------------------------------------------- + + /** + * @param temp_storage + * Reference to temp_storage + * + * @param d_keys_in + * Input keys + * + * @param d_unique_out + * Unique output keys + * + * @param d_values_in + * Input values + * + * @param d_aggregates_out + * Output value aggregates + * + * @param d_num_runs_out + * Output pointer for total number of segments identified + * + * @param equality_op + * KeyT equality operator + * + * @param reduction_op + * ValueT reduction operator + */ + __device__ __forceinline__ AgentReduceByKey(TempStorage &temp_storage, + KeysInputIteratorT d_keys_in, + UniqueOutputIteratorT d_unique_out, + ValuesInputIteratorT d_values_in, + AggregatesOutputIteratorT d_aggregates_out, + NumRunsOutputIteratorT d_num_runs_out, + EqualityOpT equality_op, + ReductionOpT reduction_op) + : temp_storage(temp_storage.Alias()) + , d_keys_in(d_keys_in) + , d_unique_out(d_unique_out) + , d_values_in(d_values_in) + , d_aggregates_out(d_aggregates_out) + , d_num_runs_out(d_num_runs_out) + , equality_op(equality_op) + , reduction_op(reduction_op) + , scan_op(reduction_op) + {} + + //--------------------------------------------------------------------- + // Scatter utility methods + //--------------------------------------------------------------------- + + /** + * Directly scatter flagged items to output offsets + */ + __device__ __forceinline__ void ScatterDirect(KeyValuePairT (&scatter_items)[ITEMS_PER_THREAD], + OffsetT (&segment_flags)[ITEMS_PER_THREAD], + OffsetT (&segment_indices)[ITEMS_PER_THREAD]) + { +// Scatter flagged keys and values +#pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + if (segment_flags[ITEM]) + { + d_unique_out[segment_indices[ITEM]] = scatter_items[ITEM].key; + d_aggregates_out[segment_indices[ITEM]] = scatter_items[ITEM].value; + } + } + } + + /** + * 2-phase scatter flagged items to output offsets + * + * The exclusive scan causes each head flag to be paired with the previous + * value aggregate: the scatter offsets must be decremented for value + * aggregates + */ + __device__ __forceinline__ void ScatterTwoPhase(KeyValuePairT (&scatter_items)[ITEMS_PER_THREAD], + OffsetT (&segment_flags)[ITEMS_PER_THREAD], + OffsetT (&segment_indices)[ITEMS_PER_THREAD], + OffsetT num_tile_segments, + OffsetT num_tile_segments_prefix) + { + CTA_SYNC(); + +// Compact and scatter pairs +#pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + if (segment_flags[ITEM]) + { + temp_storage.raw_exchange.Alias()[segment_indices[ITEM] - num_tile_segments_prefix] = + scatter_items[ITEM]; + } + } + + CTA_SYNC(); + + for (int item = threadIdx.x; item < num_tile_segments; item += BLOCK_THREADS) + { + KeyValuePairT pair = temp_storage.raw_exchange.Alias()[item]; + d_unique_out[num_tile_segments_prefix + item] = pair.key; + d_aggregates_out[num_tile_segments_prefix + item] = pair.value; + } + } + + /** + * Scatter flagged items + */ + __device__ __forceinline__ void Scatter(KeyValuePairT (&scatter_items)[ITEMS_PER_THREAD], + OffsetT (&segment_flags)[ITEMS_PER_THREAD], + OffsetT (&segment_indices)[ITEMS_PER_THREAD], + OffsetT num_tile_segments, + OffsetT num_tile_segments_prefix) + { + // Do a one-phase scatter if (a) two-phase is disabled or (b) the average + // number of selected items per thread is less than one + if (TWO_PHASE_SCATTER && (num_tile_segments > BLOCK_THREADS)) + { + ScatterTwoPhase(scatter_items, + segment_flags, + segment_indices, + num_tile_segments, + num_tile_segments_prefix); + } + else + { + ScatterDirect(scatter_items, segment_flags, segment_indices); + } + } + + //--------------------------------------------------------------------- + // Cooperatively scan a device-wide sequence of tiles with other CTAs + //--------------------------------------------------------------------- + + /** + * @brief Process a tile of input (dynamic chained scan) + * + * @tparam IS_LAST_TILE + * Whether the current tile is the last tile + * + * @param num_remaining + * Number of global input items remaining (including this tile) + * + * @param tile_idx + * Tile index + * + * @param tile_offset + * Tile offset + * + * @param tile_state + * Global tile state descriptor + */ + template + __device__ __forceinline__ void + ConsumeTile(OffsetT num_remaining, int tile_idx, OffsetT tile_offset, ScanTileStateT &tile_state) + { + // Tile keys + KeyOutputT keys[ITEMS_PER_THREAD]; + + // Tile keys shuffled up + KeyOutputT prev_keys[ITEMS_PER_THREAD]; + + // Tile values + AccumT values[ITEMS_PER_THREAD]; + + // Segment head flags + OffsetT head_flags[ITEMS_PER_THREAD]; + + // Segment indices + OffsetT segment_indices[ITEMS_PER_THREAD]; + + // Zipped values and segment flags|indices + OffsetValuePairT scan_items[ITEMS_PER_THREAD]; + + // Zipped key value pairs for scattering + KeyValuePairT scatter_items[ITEMS_PER_THREAD]; + + // Load keys + if (IS_LAST_TILE) + { + BlockLoadKeysT(temp_storage.load_keys).Load(d_keys_in + tile_offset, keys, num_remaining); + } + else + { + BlockLoadKeysT(temp_storage.load_keys).Load(d_keys_in + tile_offset, keys); + } + + // Load tile predecessor key in first thread + KeyOutputT tile_predecessor; + if (threadIdx.x == 0) + { + // if (tile_idx == 0) + // first tile gets repeat of first item (thus first item will not + // be flagged as a head) + // else + // Subsequent tiles get last key from previous tile + tile_predecessor = (tile_idx == 0) ? keys[0] : d_keys_in[tile_offset - 1]; + } + + CTA_SYNC(); + + // Load values + if (IS_LAST_TILE) + { + BlockLoadValuesT(temp_storage.load_values) + .Load(d_values_in + tile_offset, values, num_remaining); + } + else + { + BlockLoadValuesT(temp_storage.load_values).Load(d_values_in + tile_offset, values); + } + + CTA_SYNC(); + + // Initialize head-flags and shuffle up the previous keys + if (IS_LAST_TILE) + { + // Use custom flag operator to additionally flag the first out-of-bounds + // item + GuardedInequalityWrapper flag_op(equality_op, num_remaining); + BlockDiscontinuityKeys(temp_storage.scan_storage.discontinuity) + .FlagHeads(head_flags, keys, prev_keys, flag_op, tile_predecessor); + } + else + { + InequalityWrapper flag_op(equality_op); + BlockDiscontinuityKeys(temp_storage.scan_storage.discontinuity) + .FlagHeads(head_flags, keys, prev_keys, flag_op, tile_predecessor); + } + + // Reset head-flag on the very first item to make sure we don't start a new run for data where + // (key[0] == key[0]) is false (e.g., when key[0] is NaN) + if (threadIdx.x == 0 && tile_idx == 0) + { + head_flags[0] = 0; + } + + // Zip values and head flags +#pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + scan_items[ITEM].value = values[ITEM]; + scan_items[ITEM].key = head_flags[ITEM]; + } + + // Perform exclusive tile scan + // Inclusive block-wide scan aggregate + OffsetValuePairT block_aggregate; + + // Number of segments prior to this tile + OffsetT num_segments_prefix; + + // The tile prefix folded with block_aggregate + OffsetValuePairT total_aggregate; + + if (tile_idx == 0) + { + // Scan first tile + BlockScanT(temp_storage.scan_storage.scan) + .ExclusiveScan(scan_items, scan_items, scan_op, block_aggregate); + num_segments_prefix = 0; + total_aggregate = block_aggregate; + + // Update tile status if there are successor tiles + if ((!IS_LAST_TILE) && (threadIdx.x == 0)) + { + tile_state.SetInclusive(0, block_aggregate); + } + } + else + { + // Scan non-first tile + TilePrefixCallbackOpT prefix_op(tile_state, + temp_storage.scan_storage.prefix, + scan_op, + tile_idx); + BlockScanT(temp_storage.scan_storage.scan) + .ExclusiveScan(scan_items, scan_items, scan_op, prefix_op); + + block_aggregate = prefix_op.GetBlockAggregate(); + num_segments_prefix = prefix_op.GetExclusivePrefix().key; + total_aggregate = prefix_op.GetInclusivePrefix(); + } + +// Rezip scatter items and segment indices +#pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + scatter_items[ITEM].key = prev_keys[ITEM]; + scatter_items[ITEM].value = scan_items[ITEM].value; + segment_indices[ITEM] = scan_items[ITEM].key; + } + + // At this point, each flagged segment head has: + // - The key for the previous segment + // - The reduced value from the previous segment + // - The segment index for the reduced value + + // Scatter flagged keys and values + OffsetT num_tile_segments = block_aggregate.key; + Scatter(scatter_items, head_flags, segment_indices, num_tile_segments, num_segments_prefix); + + // Last thread in last tile will output final count (and last pair, if + // necessary) + if ((IS_LAST_TILE) && (threadIdx.x == BLOCK_THREADS - 1)) + { + OffsetT num_segments = num_segments_prefix + num_tile_segments; + + // If the last tile is a whole tile, output the final_value + if (num_remaining == TILE_ITEMS) + { + d_unique_out[num_segments] = keys[ITEMS_PER_THREAD - 1]; + d_aggregates_out[num_segments] = total_aggregate.value; + num_segments++; + } + + // Output the total number of items selected + *d_num_runs_out = num_segments; + } + } + + /** + * @brief Scan tiles of items as part of a dynamic chained scan + * + * @param num_items + * Total number of input items + * + * @param tile_state + * Global tile state descriptor + * + * @param start_tile + * The starting tile for the current grid + */ + __device__ __forceinline__ void ConsumeRange(OffsetT num_items, + ScanTileStateT &tile_state, + int start_tile) + { + // Blocks are launched in increasing order, so just assign one tile per + // block + + // Current tile index + int tile_idx = start_tile + blockIdx.x; + + // Global offset for the current tile + OffsetT tile_offset = OffsetT(TILE_ITEMS) * tile_idx; + + // Remaining items (including this tile) + OffsetT num_remaining = num_items - tile_offset; + + if (num_remaining > TILE_ITEMS) + { + // Not last tile + ConsumeTile(num_remaining, tile_idx, tile_offset, tile_state); + } + else if (num_remaining > 0) + { + // Last tile + ConsumeTile(num_remaining, tile_idx, tile_offset, tile_state); + } + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_rle.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_rle.cuh new file mode 100644 index 0000000000000000000000000000000000000000..5b50c424b87728e053ca9851176dd73eafe1c7d7 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_rle.cuh @@ -0,0 +1,922 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::AgentRle implements a stateful abstraction of CUDA thread blocks for participating in device-wide run-length-encode. + */ + +#pragma once + +#include + +#include "single_pass_scan_operators.cuh" +#include "../block/block_load.cuh" +#include "../block/block_store.cuh" +#include "../block/block_scan.cuh" +#include "../block/block_exchange.cuh" +#include "../block/block_discontinuity.cuh" +#include "../config.cuh" +#include "../grid/grid_queue.cuh" +#include "../iterator/cache_modified_input_iterator.cuh" +#include "../iterator/constant_input_iterator.cuh" + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Tuning policy types + ******************************************************************************/ + +/** + * Parameterizable tuning policy type for AgentRle + * + * @tparam _BLOCK_THREADS + * Threads per thread block + * + * @tparam _ITEMS_PER_THREAD + * Items per thread (per tile of input) + * + * @tparam _LOAD_ALGORITHM + * The BlockLoad algorithm to use + * + * @tparam _LOAD_MODIFIER + * Cache load modifier for reading input elements + * + * @tparam _STORE_WARP_TIME_SLICING + * Whether or not only one warp's worth of shared memory should be allocated and time-sliced among + * block-warps during any store-related data transpositions + * (versus each warp having its own storage) + * + * @tparam _SCAN_ALGORITHM + * The BlockScan algorithm to use + * + * @tparam DelayConstructorT + * Implementation detail, do not specify directly, requirements on the + * content of this type are subject to breaking change. + */ +template > +struct AgentRlePolicy +{ + enum + { + BLOCK_THREADS = _BLOCK_THREADS, ///< Threads per thread block + ITEMS_PER_THREAD = _ITEMS_PER_THREAD, ///< Items per thread (per tile of input) + STORE_WARP_TIME_SLICING = _STORE_WARP_TIME_SLICING, ///< Whether or not only one warp's worth of shared memory should be allocated and time-sliced among block-warps during any store-related data transpositions (versus each warp having its own storage) + }; + + static const BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; ///< The BlockLoad algorithm to use + static const CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; ///< Cache load modifier for reading input elements + static const BlockScanAlgorithm SCAN_ALGORITHM = _SCAN_ALGORITHM; ///< The BlockScan algorithm to use + + struct detail + { + using delay_constructor_t = DelayConstructorT; + }; +}; + + + + + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + +/** + * \brief AgentRle implements a stateful abstraction of CUDA thread blocks for participating in device-wide run-length-encode + */ +template < + typename AgentRlePolicyT, ///< Parameterized AgentRlePolicyT tuning policy type + typename InputIteratorT, ///< Random-access input iterator type for data + typename OffsetsOutputIteratorT, ///< Random-access output iterator type for offset values + typename LengthsOutputIteratorT, ///< Random-access output iterator type for length values + typename EqualityOpT, ///< T equality operator type + typename OffsetT> ///< Signed integer type for global offsets +struct AgentRle +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + /// The input value type + using T = cub::detail::value_t; + + /// The lengths output value type + using LengthT = + cub::detail::non_void_value_t; + + /// Tuple type for scanning (pairs run-length and run-index) + using LengthOffsetPair = KeyValuePair; + + /// Tile status descriptor interface type + using ScanTileStateT = ReduceByKeyScanTileState; + + // Constants + enum + { + WARP_THREADS = CUB_WARP_THREADS(0), + BLOCK_THREADS = AgentRlePolicyT::BLOCK_THREADS, + ITEMS_PER_THREAD = AgentRlePolicyT::ITEMS_PER_THREAD, + WARP_ITEMS = WARP_THREADS * ITEMS_PER_THREAD, + TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD, + WARPS = (BLOCK_THREADS + WARP_THREADS - 1) / WARP_THREADS, + + /// Whether or not to sync after loading data + SYNC_AFTER_LOAD = (AgentRlePolicyT::LOAD_ALGORITHM != BLOCK_LOAD_DIRECT), + + /// Whether or not only one warp's worth of shared memory should be allocated and time-sliced among block-warps during any store-related data transpositions (versus each warp having its own storage) + STORE_WARP_TIME_SLICING = AgentRlePolicyT::STORE_WARP_TIME_SLICING, + ACTIVE_EXCHANGE_WARPS = (STORE_WARP_TIME_SLICING) ? 1 : WARPS, + }; + + + /** + * Special operator that signals all out-of-bounds items are not equal to everything else, + * forcing both (1) the last item to be tail-flagged and (2) all oob items to be marked + * trivial. + */ + template + struct OobInequalityOp + { + OffsetT num_remaining; + EqualityOpT equality_op; + + __device__ __forceinline__ OobInequalityOp( + OffsetT num_remaining, + EqualityOpT equality_op) + : + num_remaining(num_remaining), + equality_op(equality_op) + {} + + template + __host__ __device__ __forceinline__ bool operator()(T first, T second, Index idx) + { + if (!LAST_TILE || (idx < num_remaining)) + return !equality_op(first, second); + else + return true; + } + }; + + + // Cache-modified Input iterator wrapper type (for applying cache modifier) for data + // Wrap the native input pointer with CacheModifiedVLengthnputIterator + // Directly use the supplied input iterator type + using WrappedInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + InputIteratorT>; + + // Parameterized BlockLoad type for data + using BlockLoadT = BlockLoad; + + // Parameterized BlockDiscontinuity type for data + using BlockDiscontinuityT = BlockDiscontinuity ; + + // Parameterized WarpScan type + using WarpScanPairs = WarpScan; + + // Reduce-length-by-run scan operator + using ReduceBySegmentOpT = ReduceBySegmentOp; + + // Callback type for obtaining tile prefix during block scan + using DelayConstructorT = typename AgentRlePolicyT::detail::delay_constructor_t; + using TilePrefixCallbackOpT = + TilePrefixCallbackOp; + + // Warp exchange types + using WarpExchangePairs = WarpExchange; + + using WarpExchangePairsStorage = + cub::detail::conditional_t; + + using WarpExchangeOffsets = WarpExchange; + using WarpExchangeLengths = WarpExchange; + + typedef LengthOffsetPair WarpAggregates[WARPS]; + + // Shared memory type for this thread block + struct _TempStorage + { + // Aliasable storage layout + union Aliasable + { + struct ScanStorage + { + typename BlockDiscontinuityT::TempStorage discontinuity; // Smem needed for discontinuity detection + typename WarpScanPairs::TempStorage warp_scan[WARPS]; // Smem needed for warp-synchronous scans + Uninitialized warp_aggregates; // Smem needed for sharing warp-wide aggregates + typename TilePrefixCallbackOpT::TempStorage prefix; // Smem needed for cooperative prefix callback + } scan_storage; + + // Smem needed for input loading + typename BlockLoadT::TempStorage load; + + // Aliasable layout needed for two-phase scatter + union ScatterAliasable + { + unsigned long long align; + WarpExchangePairsStorage exchange_pairs[ACTIVE_EXCHANGE_WARPS]; + typename WarpExchangeOffsets::TempStorage exchange_offsets[ACTIVE_EXCHANGE_WARPS]; + typename WarpExchangeLengths::TempStorage exchange_lengths[ACTIVE_EXCHANGE_WARPS]; + } scatter_aliasable; + + } aliasable; + + OffsetT tile_idx; // Shared tile index + LengthOffsetPair tile_inclusive; // Inclusive tile prefix + LengthOffsetPair tile_exclusive; // Exclusive tile prefix + }; + + // Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + _TempStorage& temp_storage; ///< Reference to temp_storage + + WrappedInputIteratorT d_in; ///< Pointer to input sequence of data items + OffsetsOutputIteratorT d_offsets_out; ///< Input run offsets + LengthsOutputIteratorT d_lengths_out; ///< Output run lengths + + EqualityOpT equality_op; ///< T equality operator + ReduceBySegmentOpT scan_op; ///< Reduce-length-by-flag scan operator + OffsetT num_items; ///< Total number of input items + + + //--------------------------------------------------------------------- + // Constructor + //--------------------------------------------------------------------- + + // Constructor + __device__ __forceinline__ + AgentRle( + TempStorage &temp_storage, ///< [in] Reference to temp_storage + InputIteratorT d_in, ///< [in] Pointer to input sequence of data items + OffsetsOutputIteratorT d_offsets_out, ///< [out] Pointer to output sequence of run offsets + LengthsOutputIteratorT d_lengths_out, ///< [out] Pointer to output sequence of run lengths + EqualityOpT equality_op, ///< [in] T equality operator + OffsetT num_items) ///< [in] Total number of input items + : + temp_storage(temp_storage.Alias()), + d_in(d_in), + d_offsets_out(d_offsets_out), + d_lengths_out(d_lengths_out), + equality_op(equality_op), + scan_op(cub::Sum()), + num_items(num_items) + {} + + + //--------------------------------------------------------------------- + // Utility methods for initializing the selections + //--------------------------------------------------------------------- + + template + __device__ __forceinline__ void InitializeSelections( + OffsetT tile_offset, + OffsetT num_remaining, + T (&items)[ITEMS_PER_THREAD], + LengthOffsetPair (&lengths_and_num_runs)[ITEMS_PER_THREAD]) + { + bool head_flags[ITEMS_PER_THREAD]; + bool tail_flags[ITEMS_PER_THREAD]; + + OobInequalityOp inequality_op(num_remaining, equality_op); + + if (FIRST_TILE && LAST_TILE) + { + // First-and-last-tile always head-flags the first item and tail-flags the last item + + BlockDiscontinuityT(temp_storage.aliasable.scan_storage.discontinuity).FlagHeadsAndTails( + head_flags, tail_flags, items, inequality_op); + } + else if (FIRST_TILE) + { + // First-tile always head-flags the first item + + // Get the first item from the next tile + T tile_successor_item; + if (threadIdx.x == BLOCK_THREADS - 1) + tile_successor_item = d_in[tile_offset + TILE_ITEMS]; + + BlockDiscontinuityT(temp_storage.aliasable.scan_storage.discontinuity).FlagHeadsAndTails( + head_flags, tail_flags, tile_successor_item, items, inequality_op); + } + else if (LAST_TILE) + { + // Last-tile always flags the last item + + // Get the last item from the previous tile + T tile_predecessor_item; + if (threadIdx.x == 0) + tile_predecessor_item = d_in[tile_offset - 1]; + + BlockDiscontinuityT(temp_storage.aliasable.scan_storage.discontinuity).FlagHeadsAndTails( + head_flags, tile_predecessor_item, tail_flags, items, inequality_op); + } + else + { + // Get the first item from the next tile + T tile_successor_item; + if (threadIdx.x == BLOCK_THREADS - 1) + tile_successor_item = d_in[tile_offset + TILE_ITEMS]; + + // Get the last item from the previous tile + T tile_predecessor_item; + if (threadIdx.x == 0) + tile_predecessor_item = d_in[tile_offset - 1]; + + BlockDiscontinuityT(temp_storage.aliasable.scan_storage.discontinuity).FlagHeadsAndTails( + head_flags, tile_predecessor_item, tail_flags, tile_successor_item, items, inequality_op); + } + + // Zip counts and runs + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + // input output + // items [ 0 0 0 1 2 3 3 ] + // heads [ 1 0 0 1 1 1 0 ] + // tails [ 0 0 1 1 1 0 1 ] + // key [ 1 0 0 0 0 1 0 ] head && !tail - heads of non-trivial (length > 1) runs + // value [ 1 1 1 0 0 1 1 ] !head || !tail - elements of non-trivial runs + lengths_and_num_runs[ITEM].key = head_flags[ITEM] && (!tail_flags[ITEM]); + lengths_and_num_runs[ITEM].value = ((!head_flags[ITEM]) || (!tail_flags[ITEM])); + } + } + + //--------------------------------------------------------------------- + // Scan utility methods + //--------------------------------------------------------------------- + + /** + * Scan of allocations + */ + __device__ __forceinline__ void WarpScanAllocations( + LengthOffsetPair &tile_aggregate, + LengthOffsetPair &warp_aggregate, + LengthOffsetPair &warp_exclusive_in_tile, + LengthOffsetPair &thread_exclusive_in_warp, + LengthOffsetPair (&lengths_and_num_runs)[ITEMS_PER_THREAD]) + { + // Perform warpscans + unsigned int warp_id = ((WARPS == 1) ? 0 : threadIdx.x / WARP_THREADS); + int lane_id = LaneId(); + + LengthOffsetPair identity; + identity.key = 0; + identity.value = 0; + + LengthOffsetPair thread_inclusive; + + // `thread_exclusive_in_warp.key`: + // number of non-trivial runs starts in previous threads + // `thread_exclusive_in_warp.val`: + // number of items in the last non-trivial run in previous threads + + // `thread_aggregate.key`: + // number of non-trivial runs starts in this thread + // `thread_aggregate.val`: + // number of items in the last non-trivial run in this thread + LengthOffsetPair thread_aggregate = internal::ThreadReduce(lengths_and_num_runs, scan_op); + WarpScanPairs(temp_storage.aliasable.scan_storage.warp_scan[warp_id]).Scan( + thread_aggregate, + thread_inclusive, + thread_exclusive_in_warp, + identity, + scan_op); + + // `thread_inclusive.key`: + // number of non-trivial runs starts in this and previous warp threads + // `thread_inclusive.val`: + // number of items in the last non-trivial run in this or previous warp threads + + // Last lane in each warp shares its warp-aggregate + if (lane_id == WARP_THREADS - 1) + { + // `temp_storage.aliasable.scan_storage.warp_aggregates[warp_id].key`: + // number of non-trivial runs starts in this warp + // `temp_storage.aliasable.scan_storage.warp_aggregates[warp_id].val`: + // number of items in the last non-trivial run in this warp + temp_storage.aliasable.scan_storage.warp_aggregates.Alias()[warp_id] = thread_inclusive; + } + + CTA_SYNC(); + + // Accumulate total selected and the warp-wide prefix + + // `warp_exclusive_in_tile.key`: + // number of non-trivial runs starts in previous warps + // `warp_exclusive_in_tile.val`: + // number of items in the last non-trivial run in previous warps + warp_exclusive_in_tile = identity; + warp_aggregate = temp_storage.aliasable.scan_storage.warp_aggregates.Alias()[warp_id]; + + // `tile_aggregate.key`: + // number of non-trivial runs starts in this CTA + // `tile_aggregate.val`: + // number of items in the last non-trivial run in this CTA + tile_aggregate = temp_storage.aliasable.scan_storage.warp_aggregates.Alias()[0]; + +#pragma unroll + for (int WARP = 1; WARP < WARPS; ++WARP) + { + if (warp_id == WARP) + warp_exclusive_in_tile = tile_aggregate; + + tile_aggregate = scan_op(tile_aggregate, temp_storage.aliasable.scan_storage.warp_aggregates.Alias()[WARP]); + } + } + + + //--------------------------------------------------------------------- + // Utility methods for scattering selections + //--------------------------------------------------------------------- + + /** + * Two-phase scatter, specialized for warp time-slicing + */ + template + __device__ __forceinline__ void ScatterTwoPhase( + OffsetT tile_num_runs_exclusive_in_global, + OffsetT warp_num_runs_aggregate, + OffsetT warp_num_runs_exclusive_in_tile, + OffsetT (&thread_num_runs_exclusive_in_warp)[ITEMS_PER_THREAD], + LengthOffsetPair (&lengths_and_offsets)[ITEMS_PER_THREAD], + Int2Type is_warp_time_slice) + { + unsigned int warp_id = ((WARPS == 1) ? 0 : threadIdx.x / WARP_THREADS); + int lane_id = LaneId(); + + // Locally compact items within the warp (first warp) + if (warp_id == 0) + { + WarpExchangePairs(temp_storage.aliasable.scatter_aliasable.exchange_pairs[0]).ScatterToStriped( + lengths_and_offsets, thread_num_runs_exclusive_in_warp); + } + + // Locally compact items within the warp (remaining warps) + #pragma unroll + for (int SLICE = 1; SLICE < WARPS; ++SLICE) + { + CTA_SYNC(); + + if (warp_id == SLICE) + { + WarpExchangePairs(temp_storage.aliasable.scatter_aliasable.exchange_pairs[0]).ScatterToStriped( + lengths_and_offsets, thread_num_runs_exclusive_in_warp); + } + } + + // Global scatter + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + // warp_num_runs_aggregate - number of non-trivial runs starts in current warp + if ((ITEM * WARP_THREADS) < warp_num_runs_aggregate - lane_id) + { + OffsetT item_offset = + tile_num_runs_exclusive_in_global + + warp_num_runs_exclusive_in_tile + + (ITEM * WARP_THREADS) + lane_id; + + // Scatter offset + d_offsets_out[item_offset] = lengths_and_offsets[ITEM].key; + + // Scatter length if not the first (global) length + if ((ITEM != 0) || (item_offset > 0)) + { + d_lengths_out[item_offset - 1] = lengths_and_offsets[ITEM].value; + } + } + } + } + + + /** + * Two-phase scatter + */ + template + __device__ __forceinline__ void ScatterTwoPhase( + OffsetT tile_num_runs_exclusive_in_global, + OffsetT warp_num_runs_aggregate, + OffsetT warp_num_runs_exclusive_in_tile, + OffsetT (&thread_num_runs_exclusive_in_warp)[ITEMS_PER_THREAD], + LengthOffsetPair (&lengths_and_offsets)[ITEMS_PER_THREAD], + Int2Type is_warp_time_slice) + { + unsigned int warp_id = ((WARPS == 1) ? 0 : threadIdx.x / WARP_THREADS); + int lane_id = LaneId(); + + // Unzip + OffsetT run_offsets[ITEMS_PER_THREAD]; + LengthT run_lengths[ITEMS_PER_THREAD]; + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + run_offsets[ITEM] = lengths_and_offsets[ITEM].key; + run_lengths[ITEM] = lengths_and_offsets[ITEM].value; + } + + WarpExchangeOffsets(temp_storage.aliasable.scatter_aliasable.exchange_offsets[warp_id]).ScatterToStriped( + run_offsets, thread_num_runs_exclusive_in_warp); + + WARP_SYNC(0xffffffff); + + WarpExchangeLengths(temp_storage.aliasable.scatter_aliasable.exchange_lengths[warp_id]).ScatterToStriped( + run_lengths, thread_num_runs_exclusive_in_warp); + + // Global scatter + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + if ((ITEM * WARP_THREADS) + lane_id < warp_num_runs_aggregate) + { + OffsetT item_offset = + tile_num_runs_exclusive_in_global + + warp_num_runs_exclusive_in_tile + + (ITEM * WARP_THREADS) + lane_id; + + // Scatter offset + d_offsets_out[item_offset] = run_offsets[ITEM]; + + // Scatter length if not the first (global) length + if ((ITEM != 0) || (item_offset > 0)) + { + d_lengths_out[item_offset - 1] = run_lengths[ITEM]; + } + } + } + } + + + /** + * Direct scatter + */ + template + __device__ __forceinline__ void ScatterDirect( + OffsetT tile_num_runs_exclusive_in_global, + OffsetT warp_num_runs_aggregate, + OffsetT warp_num_runs_exclusive_in_tile, + OffsetT (&thread_num_runs_exclusive_in_warp)[ITEMS_PER_THREAD], + LengthOffsetPair (&lengths_and_offsets)[ITEMS_PER_THREAD]) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + if (thread_num_runs_exclusive_in_warp[ITEM] < warp_num_runs_aggregate) + { + OffsetT item_offset = + tile_num_runs_exclusive_in_global + + warp_num_runs_exclusive_in_tile + + thread_num_runs_exclusive_in_warp[ITEM]; + + // Scatter offset + d_offsets_out[item_offset] = lengths_and_offsets[ITEM].key; + + // Scatter length if not the first (global) length + if (item_offset > 0) + { + d_lengths_out[item_offset - 1] = lengths_and_offsets[ITEM].value; + } + } + } + } + + + /** + * Scatter + */ + template + __device__ __forceinline__ void Scatter( + OffsetT tile_num_runs_aggregate, + OffsetT tile_num_runs_exclusive_in_global, + OffsetT warp_num_runs_aggregate, + OffsetT warp_num_runs_exclusive_in_tile, + OffsetT (&thread_num_runs_exclusive_in_warp)[ITEMS_PER_THREAD], + LengthOffsetPair (&lengths_and_offsets)[ITEMS_PER_THREAD]) + { + if ((ITEMS_PER_THREAD == 1) || (tile_num_runs_aggregate < BLOCK_THREADS)) + { + // Direct scatter if the warp has any items + if (warp_num_runs_aggregate) + { + ScatterDirect( + tile_num_runs_exclusive_in_global, + warp_num_runs_aggregate, + warp_num_runs_exclusive_in_tile, + thread_num_runs_exclusive_in_warp, + lengths_and_offsets); + } + } + else + { + // Scatter two phase + ScatterTwoPhase( + tile_num_runs_exclusive_in_global, + warp_num_runs_aggregate, + warp_num_runs_exclusive_in_tile, + thread_num_runs_exclusive_in_warp, + lengths_and_offsets, + Int2Type()); + } + } + + + + //--------------------------------------------------------------------- + // Cooperatively scan a device-wide sequence of tiles with other CTAs + //--------------------------------------------------------------------- + + /** + * Process a tile of input (dynamic chained scan) + */ + template < + bool LAST_TILE> + __device__ __forceinline__ LengthOffsetPair ConsumeTile( + OffsetT num_items, ///< Total number of global input items + OffsetT num_remaining, ///< Number of global input items remaining (including this tile) + int tile_idx, ///< Tile index + OffsetT tile_offset, ///< Tile offset + ScanTileStateT &tile_status) ///< Global list of tile status + { + if (tile_idx == 0) + { + // First tile + + // Load items + T items[ITEMS_PER_THREAD]; + if (LAST_TILE) + BlockLoadT(temp_storage.aliasable.load).Load(d_in + tile_offset, items, num_remaining, T()); + else + BlockLoadT(temp_storage.aliasable.load).Load(d_in + tile_offset, items); + + if (SYNC_AFTER_LOAD) + CTA_SYNC(); + + // Set flags + LengthOffsetPair lengths_and_num_runs[ITEMS_PER_THREAD]; + + InitializeSelections( + tile_offset, + num_remaining, + items, + lengths_and_num_runs); + + // Exclusive scan of lengths and runs + LengthOffsetPair tile_aggregate; + LengthOffsetPair warp_aggregate; + LengthOffsetPair warp_exclusive_in_tile; + LengthOffsetPair thread_exclusive_in_warp; + + WarpScanAllocations( + tile_aggregate, + warp_aggregate, + warp_exclusive_in_tile, + thread_exclusive_in_warp, + lengths_and_num_runs); + + // Update tile status if this is not the last tile + if (!LAST_TILE && (threadIdx.x == 0)) + { + tile_status.SetInclusive(0, tile_aggregate); + } + + // Update thread_exclusive_in_warp to fold in warp run-length + if (thread_exclusive_in_warp.key == 0) + { + // If there are no non-trivial runs starts in the previous warp threads, then + // `thread_exclusive_in_warp.val` denotes the number of items in the last + // non-trivial run of the previous CTA threads, so the better name for it is + // `thread_exclusive_in_tile`. + thread_exclusive_in_warp.value += warp_exclusive_in_tile.value; + } + + LengthOffsetPair lengths_and_offsets[ITEMS_PER_THREAD]; + OffsetT thread_num_runs_exclusive_in_warp[ITEMS_PER_THREAD]; + LengthOffsetPair lengths_and_num_runs2[ITEMS_PER_THREAD]; + + // Downsweep scan through lengths_and_num_runs + internal::ThreadScanExclusive(lengths_and_num_runs, lengths_and_num_runs2, scan_op, thread_exclusive_in_warp); + + // Zip + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + lengths_and_offsets[ITEM].value = lengths_and_num_runs2[ITEM].value; + lengths_and_offsets[ITEM].key = tile_offset + (threadIdx.x * ITEMS_PER_THREAD) + ITEM; + thread_num_runs_exclusive_in_warp[ITEM] = (lengths_and_num_runs[ITEM].key) ? + lengths_and_num_runs2[ITEM].key : // keep + WARP_THREADS * ITEMS_PER_THREAD; // discard + } + + OffsetT tile_num_runs_aggregate = tile_aggregate.key; + OffsetT tile_num_runs_exclusive_in_global = 0; + OffsetT warp_num_runs_aggregate = warp_aggregate.key; + OffsetT warp_num_runs_exclusive_in_tile = warp_exclusive_in_tile.key; + + // Scatter + Scatter( + tile_num_runs_aggregate, + tile_num_runs_exclusive_in_global, + warp_num_runs_aggregate, + warp_num_runs_exclusive_in_tile, + thread_num_runs_exclusive_in_warp, + lengths_and_offsets); + + // Return running total (inclusive of this tile) + return tile_aggregate; + } + else + { + // Not first tile + + // Load items + T items[ITEMS_PER_THREAD]; + if (LAST_TILE) + BlockLoadT(temp_storage.aliasable.load).Load(d_in + tile_offset, items, num_remaining, T()); + else + BlockLoadT(temp_storage.aliasable.load).Load(d_in + tile_offset, items); + + if (SYNC_AFTER_LOAD) + CTA_SYNC(); + + // Set flags + LengthOffsetPair lengths_and_num_runs[ITEMS_PER_THREAD]; + + InitializeSelections( + tile_offset, + num_remaining, + items, + lengths_and_num_runs); + + // Exclusive scan of lengths and runs + LengthOffsetPair tile_aggregate; + LengthOffsetPair warp_aggregate; + LengthOffsetPair warp_exclusive_in_tile; + LengthOffsetPair thread_exclusive_in_warp; + + WarpScanAllocations( + tile_aggregate, + warp_aggregate, + warp_exclusive_in_tile, + thread_exclusive_in_warp, + lengths_and_num_runs); + + // First warp computes tile prefix in lane 0 + TilePrefixCallbackOpT prefix_op(tile_status, temp_storage.aliasable.scan_storage.prefix, Sum(), tile_idx); + unsigned int warp_id = ((WARPS == 1) ? 0 : threadIdx.x / WARP_THREADS); + if (warp_id == 0) + { + prefix_op(tile_aggregate); + if (threadIdx.x == 0) + temp_storage.tile_exclusive = prefix_op.exclusive_prefix; + } + + CTA_SYNC(); + + LengthOffsetPair tile_exclusive_in_global = temp_storage.tile_exclusive; + + // Update thread_exclusive_in_warp to fold in warp and tile run-lengths + LengthOffsetPair thread_exclusive = scan_op(tile_exclusive_in_global, warp_exclusive_in_tile); + if (thread_exclusive_in_warp.key == 0) + { + // If there are no non-trivial runs starts in the previous warp threads, then + // `thread_exclusive_in_warp.val` denotes the number of items in the last + // non-trivial run of the previous grid threads, so the better name for it is + // `thread_exclusive_in_grid`. + thread_exclusive_in_warp.value += thread_exclusive.value; + } + + // Downsweep scan through lengths_and_num_runs + + // `lengths_and_num_runs2.key`: + // number of non-trivial runs starts in previous grid threads + // `lengths_and_num_runs2.val`: + // number of items in the last non-trivial run in previous grid threads + LengthOffsetPair lengths_and_num_runs2[ITEMS_PER_THREAD]; + + // `lengths_and_offsets.key`: + // offset to the item in the input sequence + // `lengths_and_offsets.val`: + // number of items in the last non-trivial run in previous grid threads + LengthOffsetPair lengths_and_offsets[ITEMS_PER_THREAD]; + OffsetT thread_num_runs_exclusive_in_warp[ITEMS_PER_THREAD]; + + internal::ThreadScanExclusive(lengths_and_num_runs, lengths_and_num_runs2, scan_op, thread_exclusive_in_warp); + + // Zip + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + lengths_and_offsets[ITEM].value = lengths_and_num_runs2[ITEM].value; + lengths_and_offsets[ITEM].key = tile_offset + (threadIdx.x * ITEMS_PER_THREAD) + ITEM; + thread_num_runs_exclusive_in_warp[ITEM] = (lengths_and_num_runs[ITEM].key) ? + lengths_and_num_runs2[ITEM].key : // keep + WARP_THREADS * ITEMS_PER_THREAD; // discard + } + + OffsetT tile_num_runs_aggregate = tile_aggregate.key; + OffsetT tile_num_runs_exclusive_in_global = tile_exclusive_in_global.key; + OffsetT warp_num_runs_aggregate = warp_aggregate.key; + OffsetT warp_num_runs_exclusive_in_tile = warp_exclusive_in_tile.key; + + // Scatter + Scatter( + tile_num_runs_aggregate, + tile_num_runs_exclusive_in_global, + warp_num_runs_aggregate, + warp_num_runs_exclusive_in_tile, + thread_num_runs_exclusive_in_warp, + lengths_and_offsets); + + // Return running total (inclusive of this tile) + return prefix_op.inclusive_prefix; + } + } + + + /** + * Scan tiles of items as part of a dynamic chained scan + */ + template ///< Output iterator type for recording number of items selected + __device__ __forceinline__ void ConsumeRange( + int num_tiles, ///< Total number of input tiles + ScanTileStateT& tile_status, ///< Global list of tile status + NumRunsIteratorT d_num_runs_out) ///< Output pointer for total number of runs identified + { + // Blocks are launched in increasing order, so just assign one tile per block + int tile_idx = (blockIdx.x * gridDim.y) + blockIdx.y; // Current tile index + OffsetT tile_offset = tile_idx * TILE_ITEMS; // Global offset for the current tile + OffsetT num_remaining = num_items - tile_offset; // Remaining items (including this tile) + + if (tile_idx < num_tiles - 1) + { + // Not the last tile (full) + ConsumeTile(num_items, num_remaining, tile_idx, tile_offset, tile_status); + } + else if (num_remaining > 0) + { + // The last tile (possibly partially-full) + LengthOffsetPair running_total = ConsumeTile(num_items, num_remaining, tile_idx, tile_offset, tile_status); + + if (threadIdx.x == 0) + { + // Output the total number of items selected + *d_num_runs_out = running_total.key; + + // The inclusive prefix contains accumulated length reduction for the last run + if (running_total.key > 0) + d_lengths_out[running_total.key - 1] = running_total.value; + } + } + } +}; + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_scan.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_scan.cuh new file mode 100644 index 0000000000000000000000000000000000000000..7a5eef11ae3014c2323fa75b5087afb16485e4fd --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_scan.cuh @@ -0,0 +1,587 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::AgentScan implements a stateful abstraction of CUDA thread blocks + * for participating in device-wide prefix scan . + */ + +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Tuning policy types + ******************************************************************************/ + +/** + * @brief Parameterizable tuning policy type for AgentScan + * + * @tparam NOMINAL_BLOCK_THREADS_4B + * Threads per thread block + * + * @tparam NOMINAL_ITEMS_PER_THREAD_4B + * Items per thread (per tile of input) + * + * @tparam ComputeT + * Dominant compute type + * + * @tparam _LOAD_ALGORITHM + * The BlockLoad algorithm to use + * + * @tparam _LOAD_MODIFIER + * Cache load modifier for reading input elements + * + * @tparam _STORE_ALGORITHM + * The BlockStore algorithm to use + * + * @tparam _SCAN_ALGORITHM + * The BlockScan algorithm to use + * + * @tparam DelayConstructorT + * Implementation detail, do not specify directly, requirements on the + * content of this type are subject to breaking change. + */ +template , + typename DelayConstructorT = detail::default_delay_constructor_t> +struct AgentScanPolicy : ScalingType +{ + static const BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; + static const CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; + static const BlockStoreAlgorithm STORE_ALGORITHM = _STORE_ALGORITHM; + static const BlockScanAlgorithm SCAN_ALGORITHM = _SCAN_ALGORITHM; + + struct detail + { + using delay_constructor_t = DelayConstructorT; + }; +}; + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + +/** + * @brief AgentScan implements a stateful abstraction of CUDA thread blocks for + * participating in device-wide prefix scan. + * @tparam AgentScanPolicyT + * Parameterized AgentScanPolicyT tuning policy type + * + * @tparam InputIteratorT + * Random-access input iterator type + * + * @tparam OutputIteratorT + * Random-access output iterator type + * + * @tparam ScanOpT + * Scan functor type + * + * @tparam InitValueT + * The init_value element for ScanOpT type (cub::NullType for inclusive scan) + * + * @tparam OffsetT + * Signed integer type for global offsets + * + */ +template +struct AgentScan +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + // The input value type + using InputT = cub::detail::value_t; + + // Tile status descriptor interface type + using ScanTileStateT = ScanTileState; + + // Input iterator wrapper type (for applying cache modifier) + // Wrap the native input pointer with CacheModifiedInputIterator + // or directly use the supplied input iterator type + using WrappedInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + InputIteratorT>; + + // Constants + enum + { + // Inclusive scan if no init_value type is provided + IS_INCLUSIVE = std::is_same::value, + BLOCK_THREADS = AgentScanPolicyT::BLOCK_THREADS, + ITEMS_PER_THREAD = AgentScanPolicyT::ITEMS_PER_THREAD, + TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD, + }; + + // Parameterized BlockLoad type + typedef BlockLoad + BlockLoadT; + + // Parameterized BlockStore type + typedef BlockStore + BlockStoreT; + + // Parameterized BlockScan type + typedef BlockScan + BlockScanT; + + // Callback type for obtaining tile prefix during block scan + using DelayConstructorT = typename AgentScanPolicyT::detail::delay_constructor_t; + using TilePrefixCallbackOpT = + TilePrefixCallbackOp; + + // Stateful BlockScan prefix callback type for managing a running total while + // scanning consecutive tiles + typedef BlockScanRunningPrefixOp RunningPrefixCallbackOp; + + // Shared memory type for this thread block + union _TempStorage + { + // Smem needed for tile loading + typename BlockLoadT::TempStorage load; + + // Smem needed for tile storing + typename BlockStoreT::TempStorage store; + + struct ScanStorage + { + // Smem needed for cooperative prefix callback + typename TilePrefixCallbackOpT::TempStorage prefix; + + // Smem needed for tile scanning + typename BlockScanT::TempStorage scan; + } scan_storage; + }; + + // Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> + {}; + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + _TempStorage &temp_storage; ///< Reference to temp_storage + WrappedInputIteratorT d_in; ///< Input data + OutputIteratorT d_out; ///< Output data + ScanOpT scan_op; ///< Binary scan operator + InitValueT init_value; ///< The init_value element for ScanOpT + + //--------------------------------------------------------------------- + // Block scan utility methods + //--------------------------------------------------------------------- + + /** + * Exclusive scan specialization (first tile) + */ + __device__ __forceinline__ void ScanTile(AccumT (&items)[ITEMS_PER_THREAD], + AccumT init_value, + ScanOpT scan_op, + AccumT &block_aggregate, + Int2Type /*is_inclusive*/) + { + BlockScanT(temp_storage.scan_storage.scan) + .ExclusiveScan(items, items, init_value, scan_op, block_aggregate); + block_aggregate = scan_op(init_value, block_aggregate); + } + + /** + * Inclusive scan specialization (first tile) + */ + __device__ __forceinline__ void ScanTile(AccumT (&items)[ITEMS_PER_THREAD], + InitValueT /*init_value*/, + ScanOpT scan_op, + AccumT &block_aggregate, + Int2Type /*is_inclusive*/) + { + BlockScanT(temp_storage.scan_storage.scan) + .InclusiveScan(items, items, scan_op, block_aggregate); + } + + /** + * Exclusive scan specialization (subsequent tiles) + */ + template + __device__ __forceinline__ void ScanTile(AccumT (&items)[ITEMS_PER_THREAD], + ScanOpT scan_op, + PrefixCallback &prefix_op, + Int2Type /*is_inclusive*/) + { + BlockScanT(temp_storage.scan_storage.scan) + .ExclusiveScan(items, items, scan_op, prefix_op); + } + + /** + * Inclusive scan specialization (subsequent tiles) + */ + template + __device__ __forceinline__ void ScanTile(AccumT (&items)[ITEMS_PER_THREAD], + ScanOpT scan_op, + PrefixCallback &prefix_op, + Int2Type /*is_inclusive*/) + { + BlockScanT(temp_storage.scan_storage.scan) + .InclusiveScan(items, items, scan_op, prefix_op); + } + + //--------------------------------------------------------------------- + // Constructor + //--------------------------------------------------------------------- + + /** + * @param temp_storage + * Reference to temp_storage + * + * @param d_in + * Input data + * + * @param d_out + * Output data + * + * @param scan_op + * Binary scan operator + * + * @param init_value + * Initial value to seed the exclusive scan + */ + __device__ __forceinline__ AgentScan(TempStorage &temp_storage, + InputIteratorT d_in, + OutputIteratorT d_out, + ScanOpT scan_op, + InitValueT init_value) + : temp_storage(temp_storage.Alias()) + , d_in(d_in) + , d_out(d_out) + , scan_op(scan_op) + , init_value(init_value) + {} + + //--------------------------------------------------------------------- + // Cooperatively scan a device-wide sequence of tiles with other CTAs + //--------------------------------------------------------------------- + + /** + * Process a tile of input (dynamic chained scan) + * @tparam IS_LAST_TILE + * Whether the current tile is the last tile + * + * @param num_remaining + * Number of global input items remaining (including this tile) + * + * @param tile_idx + * Tile index + * + * @param tile_offset + * Tile offset + * + * @param tile_state + * Global tile state descriptor + */ + template + __device__ __forceinline__ void ConsumeTile(OffsetT num_remaining, + int tile_idx, + OffsetT tile_offset, + ScanTileStateT &tile_state) + { + // Load items + AccumT items[ITEMS_PER_THREAD]; + + if (IS_LAST_TILE) + { + // Fill last element with the first element because collectives are + // not suffix guarded. + BlockLoadT(temp_storage.load) + .Load(d_in + tile_offset, items, num_remaining, *(d_in + tile_offset)); + } + else + { + BlockLoadT(temp_storage.load).Load(d_in + tile_offset, items); + } + + CTA_SYNC(); + + // Perform tile scan + if (tile_idx == 0) + { + // Scan first tile + AccumT block_aggregate; + ScanTile(items, + init_value, + scan_op, + block_aggregate, + Int2Type()); + + if ((!IS_LAST_TILE) && (threadIdx.x == 0)) + { + tile_state.SetInclusive(0, block_aggregate); + } + } + else + { + // Scan non-first tile + TilePrefixCallbackOpT prefix_op(tile_state, + temp_storage.scan_storage.prefix, + scan_op, + tile_idx); + ScanTile(items, scan_op, prefix_op, Int2Type()); + } + + CTA_SYNC(); + + // Store items + if (IS_LAST_TILE) + { + BlockStoreT(temp_storage.store) + .Store(d_out + tile_offset, items, num_remaining); + } + else + { + BlockStoreT(temp_storage.store).Store(d_out + tile_offset, items); + } + } + + /** + * @brief Scan tiles of items as part of a dynamic chained scan + * + * @param num_items + * Total number of input items + * + * @param tile_state + * Global tile state descriptor + * + * @param start_tile + * The starting tile for the current grid + */ + __device__ __forceinline__ void ConsumeRange(OffsetT num_items, + ScanTileStateT &tile_state, + int start_tile) + { + // Blocks are launched in increasing order, so just assign one tile per + // block + + // Current tile index + int tile_idx = start_tile + blockIdx.x; + + // Global offset for the current tile + OffsetT tile_offset = OffsetT(TILE_ITEMS) * tile_idx; + + // Remaining items (including this tile) + OffsetT num_remaining = num_items - tile_offset; + + if (num_remaining > TILE_ITEMS) + { + // Not last tile + ConsumeTile(num_remaining, tile_idx, tile_offset, tile_state); + } + else if (num_remaining > 0) + { + // Last tile + ConsumeTile(num_remaining, tile_idx, tile_offset, tile_state); + } + } + + //--------------------------------------------------------------------------- + // Scan an sequence of consecutive tiles (independent of other thread blocks) + //--------------------------------------------------------------------------- + + /** + * @brief Process a tile of input + * + * @param tile_offset + * Tile offset + * + * @param prefix_op + * Running prefix operator + * + * @param valid_items + * Number of valid items in the tile + */ + template + __device__ __forceinline__ void ConsumeTile(OffsetT tile_offset, + RunningPrefixCallbackOp &prefix_op, + int valid_items = TILE_ITEMS) + { + // Load items + AccumT items[ITEMS_PER_THREAD]; + + if (IS_LAST_TILE) + { + // Fill last element with the first element because collectives are + // not suffix guarded. + BlockLoadT(temp_storage.load) + .Load(d_in + tile_offset, items, valid_items, *(d_in + tile_offset)); + } + else + { + BlockLoadT(temp_storage.load).Load(d_in + tile_offset, items); + } + + CTA_SYNC(); + + // Block scan + if (IS_FIRST_TILE) + { + AccumT block_aggregate; + ScanTile(items, + init_value, + scan_op, + block_aggregate, + Int2Type()); + prefix_op.running_total = block_aggregate; + } + else + { + ScanTile(items, scan_op, prefix_op, Int2Type()); + } + + CTA_SYNC(); + + // Store items + if (IS_LAST_TILE) + { + BlockStoreT(temp_storage.store) + .Store(d_out + tile_offset, items, valid_items); + } + else + { + BlockStoreT(temp_storage.store).Store(d_out + tile_offset, items); + } + } + + /** + * @brief Scan a consecutive share of input tiles + * + * @param[in] range_offset + * Threadblock begin offset (inclusive) + * + * @param[in] range_end + * Threadblock end offset (exclusive) + */ + __device__ __forceinline__ void ConsumeRange(OffsetT range_offset, + OffsetT range_end) + { + BlockScanRunningPrefixOp prefix_op(scan_op); + + if (range_offset + TILE_ITEMS <= range_end) + { + // Consume first tile of input (full) + ConsumeTile(range_offset, prefix_op); + range_offset += TILE_ITEMS; + + // Consume subsequent full tiles of input + while (range_offset + TILE_ITEMS <= range_end) + { + ConsumeTile(range_offset, prefix_op); + range_offset += TILE_ITEMS; + } + + // Consume a partially-full tile + if (range_offset < range_end) + { + int valid_items = range_end - range_offset; + ConsumeTile(range_offset, prefix_op, valid_items); + } + } + else + { + // Consume the first tile of input (partially-full) + int valid_items = range_end - range_offset; + ConsumeTile(range_offset, prefix_op, valid_items); + } + } + + /** + * @brief Scan a consecutive share of input tiles, seeded with the + * specified prefix value + * @param[in] range_offset + * Threadblock begin offset (inclusive) + * + * @param[in] range_end + * Threadblock end offset (exclusive) + * + * @param[in] prefix + * The prefix to apply to the scan segment + */ + __device__ __forceinline__ void ConsumeRange(OffsetT range_offset, + OffsetT range_end, + AccumT prefix) + { + BlockScanRunningPrefixOp prefix_op(prefix, scan_op); + + // Consume full tiles of input + while (range_offset + TILE_ITEMS <= range_end) + { + ConsumeTile(range_offset, prefix_op); + range_offset += TILE_ITEMS; + } + + // Consume a partially-full tile + if (range_offset < range_end) + { + int valid_items = range_end - range_offset; + ConsumeTile(range_offset, prefix_op, valid_items); + } + } +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_scan_by_key.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_scan_by_key.cuh new file mode 100644 index 0000000000000000000000000000000000000000..dffe38f86489e55eb5330fb0cfdb5e06aa1f44aa --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_scan_by_key.cuh @@ -0,0 +1,515 @@ +/****************************************************************************** + * Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file AgentScanByKey implements a stateful abstraction of CUDA thread blocks + * for participating in device-wide prefix scan by key. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Tuning policy types + ******************************************************************************/ + +/** + * Parameterizable tuning policy type for AgentScanByKey + * + * @tparam DelayConstructorT + * Implementation detail, do not specify directly, requirements on the + * content of this type are subject to breaking change. + */ +template > +struct AgentScanByKeyPolicy +{ + static constexpr int BLOCK_THREADS = _BLOCK_THREADS; + static constexpr int ITEMS_PER_THREAD = _ITEMS_PER_THREAD; + + static constexpr BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; + static constexpr CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; + static constexpr BlockScanAlgorithm SCAN_ALGORITHM = _SCAN_ALGORITHM; + static constexpr BlockStoreAlgorithm STORE_ALGORITHM = _STORE_ALGORITHM; + + struct detail + { + using delay_constructor_t = DelayConstructorT; + }; +}; + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + +/** + * @brief AgentScanByKey implements a stateful abstraction of CUDA thread + * blocks for participating in device-wide prefix scan by key. + * + * @tparam AgentScanByKeyPolicyT + * Parameterized AgentScanPolicyT tuning policy type + * + * @tparam KeysInputIteratorT + * Random-access input iterator type + * + * @tparam ValuesInputIteratorT + * Random-access input iterator type + * + * @tparam ValuesOutputIteratorT + * Random-access output iterator type + * + * @tparam EqualityOp + * Equality functor type + * + * @tparam ScanOpT + * Scan functor type + * + * @tparam InitValueT + * The init_value element for ScanOpT type (cub::NullType for inclusive scan) + * + * @tparam OffsetT + * Signed integer type for global offsets + * + */ +template +struct AgentScanByKey +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + using KeyT = cub::detail::value_t; + using InputT = cub::detail::value_t; + using SizeValuePairT = KeyValuePair; + using KeyValuePairT = KeyValuePair; + using ReduceBySegmentOpT = ReduceBySegmentOp; + + using ScanTileStateT = ReduceByKeyScanTileState; + + // Constants + // Inclusive scan if no init_value type is provided + static constexpr int IS_INCLUSIVE = std::is_same::value; + static constexpr int BLOCK_THREADS = AgentScanByKeyPolicyT::BLOCK_THREADS; + static constexpr int ITEMS_PER_THREAD = + AgentScanByKeyPolicyT::ITEMS_PER_THREAD; + static constexpr int ITEMS_PER_TILE = BLOCK_THREADS * ITEMS_PER_THREAD; + + using WrappedKeysInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + KeysInputIteratorT>; + + using WrappedValuesInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + ValuesInputIteratorT>; + + using BlockLoadKeysT = BlockLoad; + + using BlockLoadValuesT = BlockLoad; + + using BlockStoreValuesT = BlockStore; + + using BlockDiscontinuityKeysT = BlockDiscontinuity; + + using DelayConstructorT = typename AgentScanByKeyPolicyT::detail::delay_constructor_t; + using TilePrefixCallbackT = + TilePrefixCallbackOp; + + using BlockScanT = BlockScan; + + union TempStorage_ + { + struct ScanStorage + { + typename BlockScanT::TempStorage scan; + typename TilePrefixCallbackT::TempStorage prefix; + typename BlockDiscontinuityKeysT::TempStorage discontinuity; + } scan_storage; + + typename BlockLoadKeysT::TempStorage load_keys; + typename BlockLoadValuesT::TempStorage load_values; + typename BlockStoreValuesT::TempStorage store_values; + }; + + struct TempStorage : cub::Uninitialized + {}; + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + TempStorage_ &storage; + WrappedKeysInputIteratorT d_keys_in; + KeyT *d_keys_prev_in; + WrappedValuesInputIteratorT d_values_in; + ValuesOutputIteratorT d_values_out; + InequalityWrapper inequality_op; + ScanOpT scan_op; + ReduceBySegmentOpT pair_scan_op; + InitValueT init_value; + + //--------------------------------------------------------------------- + // Block scan utility methods (first tile) + //--------------------------------------------------------------------- + + // Exclusive scan specialization + __device__ __forceinline__ void + ScanTile(SizeValuePairT (&scan_items)[ITEMS_PER_THREAD], + SizeValuePairT &tile_aggregate, + Int2Type /* is_inclusive */) + { + BlockScanT(storage.scan_storage.scan) + .ExclusiveScan(scan_items, scan_items, pair_scan_op, tile_aggregate); + } + + // Inclusive scan specialization + __device__ __forceinline__ void + ScanTile(SizeValuePairT (&scan_items)[ITEMS_PER_THREAD], + SizeValuePairT &tile_aggregate, + Int2Type /* is_inclusive */) + { + BlockScanT(storage.scan_storage.scan) + .InclusiveScan(scan_items, scan_items, pair_scan_op, tile_aggregate); + } + + //--------------------------------------------------------------------- + // Block scan utility methods (subsequent tiles) + //--------------------------------------------------------------------- + + // Exclusive scan specialization (with prefix from predecessors) + __device__ __forceinline__ void + ScanTile(SizeValuePairT (&scan_items)[ITEMS_PER_THREAD], + SizeValuePairT &tile_aggregate, + TilePrefixCallbackT &prefix_op, + Int2Type /* is_incclusive */) + { + BlockScanT(storage.scan_storage.scan) + .ExclusiveScan(scan_items, scan_items, pair_scan_op, prefix_op); + tile_aggregate = prefix_op.GetBlockAggregate(); + } + + // Inclusive scan specialization (with prefix from predecessors) + __device__ __forceinline__ void + ScanTile(SizeValuePairT (&scan_items)[ITEMS_PER_THREAD], + SizeValuePairT &tile_aggregate, + TilePrefixCallbackT &prefix_op, + Int2Type /* is_inclusive */) + { + BlockScanT(storage.scan_storage.scan) + .InclusiveScan(scan_items, scan_items, pair_scan_op, prefix_op); + tile_aggregate = prefix_op.GetBlockAggregate(); + } + + //--------------------------------------------------------------------- + // Zip utility methods + //--------------------------------------------------------------------- + + template + __device__ __forceinline__ void + ZipValuesAndFlags(OffsetT num_remaining, + AccumT (&values)[ITEMS_PER_THREAD], + OffsetT (&segment_flags)[ITEMS_PER_THREAD], + SizeValuePairT (&scan_items)[ITEMS_PER_THREAD]) + { +// Zip values and segment_flags +#pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + // Set segment_flags for first out-of-bounds item, zero for others + if (IS_LAST_TILE && + OffsetT(threadIdx.x * ITEMS_PER_THREAD) + ITEM == num_remaining) + { + segment_flags[ITEM] = 1; + } + + scan_items[ITEM].value = values[ITEM]; + scan_items[ITEM].key = segment_flags[ITEM]; + } + } + + __device__ __forceinline__ void + UnzipValues(AccumT (&values)[ITEMS_PER_THREAD], + SizeValuePairT (&scan_items)[ITEMS_PER_THREAD]) + { +// Zip values and segment_flags +#pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + values[ITEM] = scan_items[ITEM].value; + } + } + + template ::value, + typename std::enable_if::type = 0> + __device__ __forceinline__ void + AddInitToScan(AccumT (&items)[ITEMS_PER_THREAD], + OffsetT (&flags)[ITEMS_PER_THREAD]) + { +#pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + items[ITEM] = flags[ITEM] ? init_value : scan_op(init_value, items[ITEM]); + } + } + + template ::value, + typename std::enable_if::type = 0> + __device__ __forceinline__ void + AddInitToScan(AccumT (&/*items*/)[ITEMS_PER_THREAD], + OffsetT (&/*flags*/)[ITEMS_PER_THREAD]) + {} + + //--------------------------------------------------------------------- + // Cooperatively scan a device-wide sequence of tiles with other CTAs + //--------------------------------------------------------------------- + + // Process a tile of input (dynamic chained scan) + // + template + __device__ __forceinline__ void ConsumeTile(OffsetT /*num_items*/, + OffsetT num_remaining, + int tile_idx, + OffsetT tile_base, + ScanTileStateT &tile_state) + { + // Load items + KeyT keys[ITEMS_PER_THREAD]; + AccumT values[ITEMS_PER_THREAD]; + OffsetT segment_flags[ITEMS_PER_THREAD]; + SizeValuePairT scan_items[ITEMS_PER_THREAD]; + + if (IS_LAST_TILE) + { + // Fill last element with the first element + // because collectives are not suffix guarded + BlockLoadKeysT(storage.load_keys) + .Load(d_keys_in + tile_base, + keys, + num_remaining, + *(d_keys_in + tile_base)); + } + else + { + BlockLoadKeysT(storage.load_keys).Load(d_keys_in + tile_base, keys); + } + + CTA_SYNC(); + + if (IS_LAST_TILE) + { + // Fill last element with the first element + // because collectives are not suffix guarded + BlockLoadValuesT(storage.load_values) + .Load(d_values_in + tile_base, + values, + num_remaining, + *(d_values_in + tile_base)); + } + else + { + BlockLoadValuesT(storage.load_values) + .Load(d_values_in + tile_base, values); + } + + CTA_SYNC(); + + // first tile + if (tile_idx == 0) + { + BlockDiscontinuityKeysT(storage.scan_storage.discontinuity) + .FlagHeads(segment_flags, keys, inequality_op); + + // Zip values and segment_flags + ZipValuesAndFlags(num_remaining, + values, + segment_flags, + scan_items); + + // Exclusive scan of values and segment_flags + SizeValuePairT tile_aggregate; + ScanTile(scan_items, tile_aggregate, Int2Type()); + + if (threadIdx.x == 0) + { + if (!IS_LAST_TILE) + { + tile_state.SetInclusive(0, tile_aggregate); + } + + scan_items[0].key = 0; + } + } + else + { + KeyT tile_pred_key = (threadIdx.x == 0) ? d_keys_prev_in[tile_idx] + : KeyT(); + + BlockDiscontinuityKeysT(storage.scan_storage.discontinuity) + .FlagHeads(segment_flags, keys, inequality_op, tile_pred_key); + + // Zip values and segment_flags + ZipValuesAndFlags(num_remaining, + values, + segment_flags, + scan_items); + + SizeValuePairT tile_aggregate; + TilePrefixCallbackT prefix_op(tile_state, + storage.scan_storage.prefix, + pair_scan_op, + tile_idx); + ScanTile(scan_items, tile_aggregate, prefix_op, Int2Type()); + } + + CTA_SYNC(); + + UnzipValues(values, scan_items); + + AddInitToScan(values, segment_flags); + + // Store items + if (IS_LAST_TILE) + { + BlockStoreValuesT(storage.store_values) + .Store(d_values_out + tile_base, values, num_remaining); + } + else + { + BlockStoreValuesT(storage.store_values) + .Store(d_values_out + tile_base, values); + } + } + + //--------------------------------------------------------------------- + // Constructor + //--------------------------------------------------------------------- + + // Dequeue and scan tiles of items as part of a dynamic chained scan + // with Init functor + __device__ __forceinline__ AgentScanByKey(TempStorage &storage, + KeysInputIteratorT d_keys_in, + KeyT *d_keys_prev_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + EqualityOp equality_op, + ScanOpT scan_op, + InitValueT init_value) + : storage(storage.Alias()) + , d_keys_in(d_keys_in) + , d_keys_prev_in(d_keys_prev_in) + , d_values_in(d_values_in) + , d_values_out(d_values_out) + , inequality_op(equality_op) + , scan_op(scan_op) + , pair_scan_op(scan_op) + , init_value(init_value) + {} + + /** + * Scan tiles of items as part of a dynamic chained scan + * + * @param num_items + * Total number of input items + * + * @param tile_state + * Global tile state descriptor + * + * start_tile + * The starting tile for the current grid + */ + __device__ __forceinline__ void ConsumeRange(OffsetT num_items, + ScanTileStateT &tile_state, + int start_tile) + { + int tile_idx = blockIdx.x; + OffsetT tile_base = OffsetT(ITEMS_PER_TILE) * tile_idx; + OffsetT num_remaining = num_items - tile_base; + + if (num_remaining > ITEMS_PER_TILE) + { + // Not the last tile (full) + ConsumeTile(num_items, + num_remaining, + tile_idx, + tile_base, + tile_state); + } + else if (num_remaining > 0) + { + // The last tile (possibly partially-full) + ConsumeTile(num_items, + num_remaining, + tile_idx, + tile_base, + tile_state); + } + } +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_segment_fixup.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_segment_fixup.cuh new file mode 100644 index 0000000000000000000000000000000000000000..bd2837ce06bb7aeef00e3ef8afd6ed36ce58a215 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_segment_fixup.cuh @@ -0,0 +1,372 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::AgentSegmentFixup implements a stateful abstraction of CUDA thread blocks for participating in device-wide reduce-value-by-key. + */ + +#pragma once + +#include + +#include "single_pass_scan_operators.cuh" +#include "../block/block_load.cuh" +#include "../block/block_store.cuh" +#include "../block/block_scan.cuh" +#include "../block/block_discontinuity.cuh" +#include "../config.cuh" +#include "../iterator/cache_modified_input_iterator.cuh" +#include "../iterator/constant_input_iterator.cuh" + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Tuning policy types + ******************************************************************************/ + +/** + * Parameterizable tuning policy type for AgentSegmentFixup + */ +template < + int _BLOCK_THREADS, ///< Threads per thread block + int _ITEMS_PER_THREAD, ///< Items per thread (per tile of input) + BlockLoadAlgorithm _LOAD_ALGORITHM, ///< The BlockLoad algorithm to use + CacheLoadModifier _LOAD_MODIFIER, ///< Cache load modifier for reading input elements + BlockScanAlgorithm _SCAN_ALGORITHM> ///< The BlockScan algorithm to use +struct AgentSegmentFixupPolicy +{ + enum + { + BLOCK_THREADS = _BLOCK_THREADS, ///< Threads per thread block + ITEMS_PER_THREAD = _ITEMS_PER_THREAD, ///< Items per thread (per tile of input) + }; + + static const BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; ///< The BlockLoad algorithm to use + static const CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; ///< Cache load modifier for reading input elements + static const BlockScanAlgorithm SCAN_ALGORITHM = _SCAN_ALGORITHM; ///< The BlockScan algorithm to use +}; + + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + +/** + * \brief AgentSegmentFixup implements a stateful abstraction of CUDA thread blocks for participating in device-wide reduce-value-by-key + */ +template < + typename AgentSegmentFixupPolicyT, ///< Parameterized AgentSegmentFixupPolicy tuning policy type + typename PairsInputIteratorT, ///< Random-access input iterator type for keys + typename AggregatesOutputIteratorT, ///< Random-access output iterator type for values + typename EqualityOpT, ///< KeyT equality operator type + typename ReductionOpT, ///< ValueT reduction operator type + typename OffsetT> ///< Signed integer type for global offsets +struct AgentSegmentFixup +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + // Data type of key-value input iterator + using KeyValuePairT = cub::detail::value_t; + + // Value type + using ValueT = typename KeyValuePairT::Value; + + // Tile status descriptor interface type + using ScanTileStateT = ReduceByKeyScanTileState; + + // Constants + enum + { + BLOCK_THREADS = AgentSegmentFixupPolicyT::BLOCK_THREADS, + ITEMS_PER_THREAD = AgentSegmentFixupPolicyT::ITEMS_PER_THREAD, + TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD, + + // Whether or not do fixup using RLE + global atomics + USE_ATOMIC_FIXUP = (std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value), + + // Whether or not the scan operation has a zero-valued identity value + // (true if we're performing addition on a primitive type) + HAS_IDENTITY_ZERO = (std::is_same::value) && + (Traits::PRIMITIVE), + }; + + // Cache-modified Input iterator wrapper type (for applying cache modifier) for keys + // Wrap the native input pointer with CacheModifiedValuesInputIterator + // or directly use the supplied input iterator type + using WrappedPairsInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + PairsInputIteratorT>; + + // Cache-modified Input iterator wrapper type (for applying cache modifier) for fixup values + // Wrap the native input pointer with CacheModifiedValuesInputIterator + // or directly use the supplied input iterator type + using WrappedFixupInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + AggregatesOutputIteratorT>; + + // Reduce-value-by-segment scan operator + using ReduceBySegmentOpT = ReduceByKeyOp; + + // Parameterized BlockLoad type for pairs + using BlockLoadPairs = BlockLoad; + + // Parameterized BlockScan type + using BlockScanT = BlockScan; + + // Callback type for obtaining tile prefix during block scan + using TilePrefixCallbackOpT = + TilePrefixCallbackOp; + + // Shared memory type for this thread block + union _TempStorage + { + struct ScanStorage + { + typename BlockScanT::TempStorage scan; // Smem needed for tile scanning + typename TilePrefixCallbackOpT::TempStorage prefix; // Smem needed for cooperative prefix callback + } scan_storage; + + // Smem needed for loading keys + typename BlockLoadPairs::TempStorage load_pairs; + }; + + // Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + _TempStorage& temp_storage; ///< Reference to temp_storage + WrappedPairsInputIteratorT d_pairs_in; ///< Input keys + AggregatesOutputIteratorT d_aggregates_out; ///< Output value aggregates + WrappedFixupInputIteratorT d_fixup_in; ///< Fixup input values + InequalityWrapper inequality_op; ///< KeyT inequality operator + ReductionOpT reduction_op; ///< Reduction operator + ReduceBySegmentOpT scan_op; ///< Reduce-by-segment scan operator + + + //--------------------------------------------------------------------- + // Constructor + //--------------------------------------------------------------------- + + // Constructor + __device__ __forceinline__ + AgentSegmentFixup( + TempStorage& temp_storage, ///< Reference to temp_storage + PairsInputIteratorT d_pairs_in, ///< Input keys + AggregatesOutputIteratorT d_aggregates_out, ///< Output value aggregates + EqualityOpT equality_op, ///< KeyT equality operator + ReductionOpT reduction_op) ///< ValueT reduction operator + : + temp_storage(temp_storage.Alias()), + d_pairs_in(d_pairs_in), + d_aggregates_out(d_aggregates_out), + d_fixup_in(d_aggregates_out), + inequality_op(equality_op), + reduction_op(reduction_op), + scan_op(reduction_op) + {} + + + //--------------------------------------------------------------------- + // Cooperatively scan a device-wide sequence of tiles with other CTAs + //--------------------------------------------------------------------- + + + /** + * Process input tile. Specialized for atomic-fixup + */ + template + __device__ __forceinline__ void ConsumeTile( + OffsetT num_remaining, ///< Number of global input items remaining (including this tile) + int tile_idx, ///< Tile index + OffsetT tile_offset, ///< Tile offset + ScanTileStateT& tile_state, ///< Global tile state descriptor + Int2Type use_atomic_fixup) ///< Marker whether to use atomicAdd (instead of reduce-by-key) + { + KeyValuePairT pairs[ITEMS_PER_THREAD]; + + // Load pairs + KeyValuePairT oob_pair; + oob_pair.key = -1; + + if (IS_LAST_TILE) + BlockLoadPairs(temp_storage.load_pairs).Load(d_pairs_in + tile_offset, pairs, num_remaining, oob_pair); + else + BlockLoadPairs(temp_storage.load_pairs).Load(d_pairs_in + tile_offset, pairs); + + // RLE + #pragma unroll + for (int ITEM = 1; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + ValueT* d_scatter = d_aggregates_out + pairs[ITEM - 1].key; + if (pairs[ITEM].key != pairs[ITEM - 1].key) + atomicAdd(d_scatter, pairs[ITEM - 1].value); + else + pairs[ITEM].value = reduction_op(pairs[ITEM - 1].value, pairs[ITEM].value); + } + + // Flush last item if valid + ValueT* d_scatter = d_aggregates_out + pairs[ITEMS_PER_THREAD - 1].key; + if ((!IS_LAST_TILE) || (pairs[ITEMS_PER_THREAD - 1].key >= 0)) + atomicAdd(d_scatter, pairs[ITEMS_PER_THREAD - 1].value); + } + + + /** + * Process input tile. Specialized for reduce-by-key fixup + */ + template + __device__ __forceinline__ void ConsumeTile( + OffsetT num_remaining, ///< Number of global input items remaining (including this tile) + int tile_idx, ///< Tile index + OffsetT tile_offset, ///< Tile offset + ScanTileStateT& tile_state, ///< Global tile state descriptor + Int2Type use_atomic_fixup) ///< Marker whether to use atomicAdd (instead of reduce-by-key) + { + KeyValuePairT pairs[ITEMS_PER_THREAD]; + KeyValuePairT scatter_pairs[ITEMS_PER_THREAD]; + + // Load pairs + KeyValuePairT oob_pair; + oob_pair.key = -1; + + if (IS_LAST_TILE) + BlockLoadPairs(temp_storage.load_pairs).Load(d_pairs_in + tile_offset, pairs, num_remaining, oob_pair); + else + BlockLoadPairs(temp_storage.load_pairs).Load(d_pairs_in + tile_offset, pairs); + + CTA_SYNC(); + + KeyValuePairT tile_aggregate; + if (tile_idx == 0) + { + // Exclusive scan of values and segment_flags + BlockScanT(temp_storage.scan_storage.scan).ExclusiveScan(pairs, scatter_pairs, scan_op, tile_aggregate); + + // Update tile status if this is not the last tile + if (threadIdx.x == 0) + { + // Set first segment id to not trigger a flush (invalid from exclusive scan) + scatter_pairs[0].key = pairs[0].key; + + if (!IS_LAST_TILE) + tile_state.SetInclusive(0, tile_aggregate); + + } + } + else + { + // Exclusive scan of values and segment_flags + TilePrefixCallbackOpT prefix_op(tile_state, temp_storage.scan_storage.prefix, scan_op, tile_idx); + BlockScanT(temp_storage.scan_storage.scan).ExclusiveScan(pairs, scatter_pairs, scan_op, prefix_op); + tile_aggregate = prefix_op.GetBlockAggregate(); + } + + // Scatter updated values + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + if (scatter_pairs[ITEM].key != pairs[ITEM].key) + { + // Update the value at the key location + ValueT value = d_fixup_in[scatter_pairs[ITEM].key]; + value = reduction_op(value, scatter_pairs[ITEM].value); + + d_aggregates_out[scatter_pairs[ITEM].key] = value; + } + } + + // Finalize the last item + if (IS_LAST_TILE) + { + // Last thread will output final count and last item, if necessary + if (threadIdx.x == BLOCK_THREADS - 1) + { + // If the last tile is a whole tile, the inclusive prefix contains accumulated value reduction for the last segment + if (num_remaining == TILE_ITEMS) + { + // Update the value at the key location + OffsetT last_key = pairs[ITEMS_PER_THREAD - 1].key; + d_aggregates_out[last_key] = reduction_op(tile_aggregate.value, d_fixup_in[last_key]); + } + } + } + } + + + /** + * Scan tiles of items as part of a dynamic chained scan + */ + __device__ __forceinline__ void ConsumeRange( + OffsetT num_items, ///< Total number of input items + int num_tiles, ///< Total number of input tiles + ScanTileStateT& tile_state) ///< Global tile state descriptor + { + // Blocks are launched in increasing order, so just assign one tile per block + int tile_idx = (blockIdx.x * gridDim.y) + blockIdx.y; // Current tile index + OffsetT tile_offset = tile_idx * TILE_ITEMS; // Global offset for the current tile + OffsetT num_remaining = num_items - tile_offset; // Remaining items (including this tile) + + if (num_remaining > TILE_ITEMS) + { + // Not the last tile (full) + ConsumeTile(num_remaining, tile_idx, tile_offset, tile_state, Int2Type()); + } + else if (num_remaining > 0) + { + // The last tile (possibly partially-full) + ConsumeTile(num_remaining, tile_idx, tile_offset, tile_state, Int2Type()); + } + } + +}; + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_segmented_radix_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_segmented_radix_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..a629771120e2f6b14d246efe82491761269acb97 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_segmented_radix_sort.cuh @@ -0,0 +1,297 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include + + +CUB_NAMESPACE_BEGIN + + +/** + * This agent will be implementing the `DeviceSegmentedRadixSort` when the + * https://github.com/NVIDIA/cub/issues/383 is addressed. + * + * @tparam IS_DESCENDING + * Whether or not the sorted-order is high-to-low + * + * @tparam SegmentedPolicyT + * Chained tuning policy + * + * @tparam KeyT + * Key type + * + * @tparam ValueT + * Value type + * + * @tparam OffsetT + * Signed integer type for global offsets + */ +template +struct AgentSegmentedRadixSort +{ + OffsetT num_items; + + static constexpr int ITEMS_PER_THREAD = SegmentedPolicyT::ITEMS_PER_THREAD; + static constexpr int BLOCK_THREADS = SegmentedPolicyT::BLOCK_THREADS; + static constexpr int RADIX_BITS = SegmentedPolicyT::RADIX_BITS; + static constexpr int RADIX_DIGITS = 1 << RADIX_BITS; + static constexpr int KEYS_ONLY = std::is_same::value; + + using traits = detail::radix::traits_t; + using bit_ordered_type = typename traits::bit_ordered_type; + + // Huge segment handlers + using BlockUpsweepT = AgentRadixSortUpsweep; + using DigitScanT = BlockScan; + using BlockDownsweepT = + AgentRadixSortDownsweep; + + /// Number of bin-starting offsets tracked per thread + static constexpr int BINS_TRACKED_PER_THREAD = BlockDownsweepT::BINS_TRACKED_PER_THREAD; + + // Small segment handlers + using BlockRadixSortT = + BlockRadixSort; + + using BlockKeyLoadT = BlockLoad; + + using BlockValueLoadT = BlockLoad; + + union _TempStorage + { + // Huge segment handlers + typename BlockUpsweepT::TempStorage upsweep; + typename BlockDownsweepT::TempStorage downsweep; + + struct UnboundBlockSort + { + OffsetT reverse_counts_in[RADIX_DIGITS]; + OffsetT reverse_counts_out[RADIX_DIGITS]; + typename DigitScanT::TempStorage scan; + } unbound_sort; + + // Small segment handlers + typename BlockKeyLoadT::TempStorage keys_load; + typename BlockValueLoadT::TempStorage values_load; + typename BlockRadixSortT::TempStorage sort; + }; + + using TempStorage = Uninitialized<_TempStorage>; + _TempStorage &temp_storage; + + DecomposerT decomposer; + + __device__ __forceinline__ + AgentSegmentedRadixSort(OffsetT num_items, + TempStorage &temp_storage, + DecomposerT decomposer = {}) + : num_items(num_items) + , temp_storage(temp_storage.Alias()) + , decomposer(decomposer) + {} + + __device__ __forceinline__ void ProcessSinglePass(int begin_bit, + int end_bit, + const KeyT *d_keys_in, + const ValueT *d_values_in, + KeyT *d_keys_out, + ValueT *d_values_out) + { + KeyT thread_keys[ITEMS_PER_THREAD]; + ValueT thread_values[ITEMS_PER_THREAD]; + + // For FP64 the difference is: + // Lowest() -> -1.79769e+308 = 00...00b -> TwiddleIn -> -0 = 10...00b + // LOWEST -> -nan = 11...11b -> TwiddleIn -> 0 = 00...00b + + bit_ordered_type default_key_bits = IS_DESCENDING + ? traits::min_raw_binary_key(decomposer) + : traits::max_raw_binary_key(decomposer); + KeyT oob_default = reinterpret_cast(default_key_bits); + + if (!KEYS_ONLY) + { + BlockValueLoadT(temp_storage.values_load) + .Load(d_values_in, thread_values, num_items); + + CTA_SYNC(); + } + + { + BlockKeyLoadT(temp_storage.keys_load) + .Load(d_keys_in, thread_keys, num_items, oob_default); + + CTA_SYNC(); + } + + BlockRadixSortT(temp_storage.sort).SortBlockedToStriped( + thread_keys, + thread_values, + begin_bit, + end_bit, + Int2Type(), + Int2Type(), + decomposer); + + cub::StoreDirectStriped( + threadIdx.x, d_keys_out, thread_keys, num_items); + + if (!KEYS_ONLY) + { + cub::StoreDirectStriped( + threadIdx.x, d_values_out, thread_values, num_items); + } + } + + __device__ __forceinline__ void ProcessIterative(int current_bit, + int pass_bits, + const KeyT *d_keys_in, + const ValueT *d_values_in, + KeyT *d_keys_out, + ValueT *d_values_out) + { + // Upsweep + BlockUpsweepT upsweep(temp_storage.upsweep, + d_keys_in, + current_bit, + pass_bits, + decomposer); + upsweep.ProcessRegion(OffsetT{}, num_items); + + CTA_SYNC(); + + // The count of each digit value in this pass (valid in the first RADIX_DIGITS threads) + OffsetT bin_count[BINS_TRACKED_PER_THREAD]; + upsweep.ExtractCounts(bin_count); + + CTA_SYNC(); + + if (IS_DESCENDING) + { + // Reverse bin counts + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + temp_storage.unbound_sort.reverse_counts_in[bin_idx] = bin_count[track]; + } + } + + CTA_SYNC(); + + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + bin_count[track] = temp_storage.unbound_sort.reverse_counts_in[RADIX_DIGITS - bin_idx - 1]; + } + } + } + + // Scan + // The global scatter base offset for each digit value in this pass + // (valid in the first RADIX_DIGITS threads) + OffsetT bin_offset[BINS_TRACKED_PER_THREAD]; + DigitScanT(temp_storage.unbound_sort.scan).ExclusiveSum(bin_count, bin_offset); + + if (IS_DESCENDING) + { + // Reverse bin offsets + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + temp_storage.unbound_sort.reverse_counts_out[threadIdx.x] = bin_offset[track]; + } + } + + CTA_SYNC(); + + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + bin_offset[track] = temp_storage.unbound_sort.reverse_counts_out[RADIX_DIGITS - bin_idx - 1]; + } + } + } + + CTA_SYNC(); + + // Downsweep + BlockDownsweepT downsweep(temp_storage.downsweep, + bin_offset, + num_items, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + current_bit, + pass_bits, + decomposer); + downsweep.ProcessRegion(OffsetT{}, num_items); + } +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_select_if.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_select_if.cuh new file mode 100644 index 0000000000000000000000000000000000000000..4347602c19b980dce9e516d06f692373c80dfe2c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_select_if.cuh @@ -0,0 +1,712 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::AgentSelectIf implements a stateful abstraction of CUDA thread blocks for participating in device-wide select. + */ + +#pragma once + +#include + +#include "single_pass_scan_operators.cuh" +#include "../block/block_load.cuh" +#include "../block/block_store.cuh" +#include "../block/block_scan.cuh" +#include "../block/block_exchange.cuh" +#include "../block/block_discontinuity.cuh" +#include "../config.cuh" +#include "../grid/grid_queue.cuh" +#include "../iterator/cache_modified_input_iterator.cuh" + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Tuning policy types + ******************************************************************************/ + +/** + * Parameterizable tuning policy type for AgentSelectIf + * + * @tparam _BLOCK_THREADS + * Threads per thread block + * + * @tparam _ITEMS_PER_THREAD + * Items per thread (per tile of input) + * + * @tparam _LOAD_ALGORITHM + * The BlockLoad algorithm to use + * + * @tparam _LOAD_MODIFIER + * Cache load modifier for reading input elements + * + * @tparam _SCAN_ALGORITHM + * The BlockScan algorithm to use + * + * @tparam DelayConstructorT + * Implementation detail, do not specify directly, requirements on the + * content of this type are subject to breaking change. + */ +template > +struct AgentSelectIfPolicy +{ + enum + { + BLOCK_THREADS = _BLOCK_THREADS, ///< Threads per thread block + ITEMS_PER_THREAD = _ITEMS_PER_THREAD, ///< Items per thread (per tile of input) + }; + + static const BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; ///< The BlockLoad algorithm to use + static const CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; ///< Cache load modifier for reading input elements + static const BlockScanAlgorithm SCAN_ALGORITHM = _SCAN_ALGORITHM; ///< The BlockScan algorithm to use + + struct detail + { + using delay_constructor_t = DelayConstructorT; + }; +}; + + + + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + + +/** + * \brief AgentSelectIf implements a stateful abstraction of CUDA thread blocks for participating in device-wide selection + * + * Performs functor-based selection if SelectOpT functor type != NullType + * Otherwise performs flag-based selection if FlagsInputIterator's value type != NullType + * Otherwise performs discontinuity selection (keep unique) + */ +template < + typename AgentSelectIfPolicyT, ///< Parameterized AgentSelectIfPolicy tuning policy type + typename InputIteratorT, ///< Random-access input iterator type for selection items + typename FlagsInputIteratorT, ///< Random-access input iterator type for selections (NullType* if a selection functor or discontinuity flagging is to be used for selection) + typename SelectedOutputIteratorT, ///< Random-access output iterator type for selection_flags items + typename SelectOpT, ///< Selection operator type (NullType if selections or discontinuity flagging is to be used for selection) + typename EqualityOpT, ///< Equality operator type (NullType if selection functor or selections is to be used for selection) + typename OffsetT, ///< Signed integer type for global offsets + bool KEEP_REJECTS> ///< Whether or not we push rejected items to the back of the output +struct AgentSelectIf +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + // The input value type + using InputT = cub::detail::value_t; + + // The flag value type + using FlagT = cub::detail::value_t; + + // Tile status descriptor interface type + using ScanTileStateT = ScanTileState; + + // Constants + enum + { + USE_SELECT_OP, + USE_SELECT_FLAGS, + USE_DISCONTINUITY, + + BLOCK_THREADS = AgentSelectIfPolicyT::BLOCK_THREADS, + ITEMS_PER_THREAD = AgentSelectIfPolicyT::ITEMS_PER_THREAD, + TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD, + TWO_PHASE_SCATTER = (ITEMS_PER_THREAD > 1), + + SELECT_METHOD = + (!std::is_same::value) ? USE_SELECT_OP + : (!std::is_same::value) ? USE_SELECT_FLAGS + : USE_DISCONTINUITY + }; + + // Cache-modified Input iterator wrapper type (for applying cache modifier) for items + // Wrap the native input pointer with CacheModifiedValuesInputIterator + // or directly use the supplied input iterator type + using WrappedInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + InputIteratorT>; + + // Cache-modified Input iterator wrapper type (for applying cache modifier) for values + // Wrap the native input pointer with CacheModifiedValuesInputIterator + // or directly use the supplied input iterator type + using WrappedFlagsInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + CacheModifiedInputIterator, + FlagsInputIteratorT>; + + // Parameterized BlockLoad type for input data + using BlockLoadT = BlockLoad; + + // Parameterized BlockLoad type for flags + using BlockLoadFlags = BlockLoad; + + // Parameterized BlockDiscontinuity type for items + using BlockDiscontinuityT = BlockDiscontinuity; + + // Parameterized BlockScan type + using BlockScanT = + BlockScan; + + + // Callback type for obtaining tile prefix during block scan + using DelayConstructorT = typename AgentSelectIfPolicyT::detail::delay_constructor_t; + using TilePrefixCallbackOpT = + TilePrefixCallbackOp; + + // Item exchange type + typedef InputT ItemExchangeT[TILE_ITEMS]; + + // Shared memory type for this thread block + union _TempStorage + { + struct ScanStorage + { + typename BlockScanT::TempStorage scan; // Smem needed for tile scanning + typename TilePrefixCallbackOpT::TempStorage prefix; // Smem needed for cooperative prefix callback + typename BlockDiscontinuityT::TempStorage discontinuity; // Smem needed for discontinuity detection + } scan_storage; + + // Smem needed for loading items + typename BlockLoadT::TempStorage load_items; + + // Smem needed for loading values + typename BlockLoadFlags::TempStorage load_flags; + + // Smem needed for compacting items (allows non POD items in this union) + Uninitialized raw_exchange; + }; + + // Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + _TempStorage& temp_storage; ///< Reference to temp_storage + WrappedInputIteratorT d_in; ///< Input items + SelectedOutputIteratorT d_selected_out; ///< Unique output items + WrappedFlagsInputIteratorT d_flags_in; ///< Input selection flags (if applicable) + InequalityWrapper inequality_op; ///< T inequality operator + SelectOpT select_op; ///< Selection operator + OffsetT num_items; ///< Total number of input items + + + //--------------------------------------------------------------------- + // Constructor + //--------------------------------------------------------------------- + + // Constructor + __device__ __forceinline__ + AgentSelectIf( + TempStorage &temp_storage, ///< Reference to temp_storage + InputIteratorT d_in, ///< Input data + FlagsInputIteratorT d_flags_in, ///< Input selection flags (if applicable) + SelectedOutputIteratorT d_selected_out, ///< Output data + SelectOpT select_op, ///< Selection operator + EqualityOpT equality_op, ///< Equality operator + OffsetT num_items) ///< Total number of input items + : + temp_storage(temp_storage.Alias()), + d_in(d_in), + d_selected_out(d_selected_out), + d_flags_in(d_flags_in), + inequality_op(equality_op), + select_op(select_op), + num_items(num_items) + {} + + + //--------------------------------------------------------------------- + // Utility methods for initializing the selections + //--------------------------------------------------------------------- + + /** + * Initialize selections (specialized for selection operator) + */ + template + __device__ __forceinline__ void InitializeSelections( + OffsetT /*tile_offset*/, + OffsetT num_tile_items, + InputT (&items)[ITEMS_PER_THREAD], + OffsetT (&selection_flags)[ITEMS_PER_THREAD], + Int2Type /*select_method*/) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + // Out-of-bounds items are selection_flags + selection_flags[ITEM] = 1; + + if (!IS_LAST_TILE || (OffsetT(threadIdx.x * ITEMS_PER_THREAD) + ITEM < num_tile_items)) + selection_flags[ITEM] = select_op(items[ITEM]); + } + } + + + /** + * Initialize selections (specialized for valid flags) + */ + template + __device__ __forceinline__ void InitializeSelections( + OffsetT tile_offset, + OffsetT num_tile_items, + InputT (&/*items*/)[ITEMS_PER_THREAD], + OffsetT (&selection_flags)[ITEMS_PER_THREAD], + Int2Type /*select_method*/) + { + CTA_SYNC(); + + FlagT flags[ITEMS_PER_THREAD]; + + if (IS_LAST_TILE) + { + // Out-of-bounds items are selection_flags + BlockLoadFlags(temp_storage.load_flags).Load(d_flags_in + tile_offset, flags, num_tile_items, 1); + } + else + { + BlockLoadFlags(temp_storage.load_flags).Load(d_flags_in + tile_offset, flags); + } + + // Convert flag type to selection_flags type + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + selection_flags[ITEM] = static_cast(flags[ITEM]); + } + } + + + /** + * Initialize selections (specialized for discontinuity detection) + */ + template + __device__ __forceinline__ void InitializeSelections( + OffsetT tile_offset, + OffsetT num_tile_items, + InputT (&items)[ITEMS_PER_THREAD], + OffsetT (&selection_flags)[ITEMS_PER_THREAD], + Int2Type /*select_method*/) + { + if (IS_FIRST_TILE) + { + CTA_SYNC(); + + // Set head selection_flags. First tile sets the first flag for the first item + BlockDiscontinuityT(temp_storage.scan_storage.discontinuity).FlagHeads(selection_flags, items, inequality_op); + } + else + { + InputT tile_predecessor; + if (threadIdx.x == 0) + tile_predecessor = d_in[tile_offset - 1]; + + CTA_SYNC(); + + BlockDiscontinuityT(temp_storage.scan_storage.discontinuity).FlagHeads(selection_flags, items, inequality_op, tile_predecessor); + } + + // Set selection flags for out-of-bounds items + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + // Set selection_flags for out-of-bounds items + if ((IS_LAST_TILE) && (OffsetT(threadIdx.x * ITEMS_PER_THREAD) + ITEM >= num_tile_items)) + selection_flags[ITEM] = 1; + } + } + + + //--------------------------------------------------------------------- + // Scatter utility methods + //--------------------------------------------------------------------- + + /** + * Scatter flagged items to output offsets (specialized for direct scattering) + */ + template + __device__ __forceinline__ void ScatterDirect( + InputT (&items)[ITEMS_PER_THREAD], + OffsetT (&selection_flags)[ITEMS_PER_THREAD], + OffsetT (&selection_indices)[ITEMS_PER_THREAD], + OffsetT num_selections) + { + // Scatter flagged items + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + if (selection_flags[ITEM]) + { + if ((!IS_LAST_TILE) || selection_indices[ITEM] < num_selections) + { + d_selected_out[selection_indices[ITEM]] = items[ITEM]; + } + } + } + } + + + /** + * Scatter flagged items to output offsets (specialized for two-phase scattering) + */ + template + __device__ __forceinline__ void ScatterTwoPhase( + InputT (&items)[ITEMS_PER_THREAD], + OffsetT (&selection_flags)[ITEMS_PER_THREAD], + OffsetT (&selection_indices)[ITEMS_PER_THREAD], + int /*num_tile_items*/, ///< Number of valid items in this tile + int num_tile_selections, ///< Number of selections in this tile + OffsetT num_selections_prefix, ///< Total number of selections prior to this tile + OffsetT /*num_rejected_prefix*/, ///< Total number of rejections prior to this tile + Int2Type /*is_keep_rejects*/) ///< Marker type indicating whether to keep rejected items in the second partition + { + CTA_SYNC(); + + // Compact and scatter items + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + int local_scatter_offset = selection_indices[ITEM] - num_selections_prefix; + if (selection_flags[ITEM]) + { + temp_storage.raw_exchange.Alias()[local_scatter_offset] = items[ITEM]; + } + } + + CTA_SYNC(); + + for (int item = threadIdx.x; item < num_tile_selections; item += BLOCK_THREADS) + { + d_selected_out[num_selections_prefix + item] = temp_storage.raw_exchange.Alias()[item]; + } + } + + + /** + * Scatter flagged items to output offsets (specialized for two-phase scattering) + */ + template + __device__ __forceinline__ void ScatterTwoPhase( + InputT (&items)[ITEMS_PER_THREAD], + OffsetT (&selection_flags)[ITEMS_PER_THREAD], + OffsetT (&selection_indices)[ITEMS_PER_THREAD], + int num_tile_items, ///< Number of valid items in this tile + int num_tile_selections, ///< Number of selections in this tile + OffsetT num_selections_prefix, ///< Total number of selections prior to this tile + OffsetT num_rejected_prefix, ///< Total number of rejections prior to this tile + Int2Type /*is_keep_rejects*/) ///< Marker type indicating whether to keep rejected items in the second partition + { + CTA_SYNC(); + + int tile_num_rejections = num_tile_items - num_tile_selections; + + // Scatter items to shared memory (rejections first) + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + int item_idx = (threadIdx.x * ITEMS_PER_THREAD) + ITEM; + int local_selection_idx = selection_indices[ITEM] - num_selections_prefix; + int local_rejection_idx = item_idx - local_selection_idx; + int local_scatter_offset = (selection_flags[ITEM]) ? + tile_num_rejections + local_selection_idx : + local_rejection_idx; + + temp_storage.raw_exchange.Alias()[local_scatter_offset] = items[ITEM]; + } + + CTA_SYNC(); + + // Gather items from shared memory and scatter to global + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + int item_idx = (ITEM * BLOCK_THREADS) + threadIdx.x; + int rejection_idx = item_idx; + int selection_idx = item_idx - tile_num_rejections; + OffsetT scatter_offset = (item_idx < tile_num_rejections) ? + num_items - num_rejected_prefix - rejection_idx - 1 : + num_selections_prefix + selection_idx; + + InputT item = temp_storage.raw_exchange.Alias()[item_idx]; + + if (!IS_LAST_TILE || (item_idx < num_tile_items)) + { + d_selected_out[scatter_offset] = item; + } + } + } + + + /** + * Scatter flagged items + */ + template + __device__ __forceinline__ void Scatter( + InputT (&items)[ITEMS_PER_THREAD], + OffsetT (&selection_flags)[ITEMS_PER_THREAD], + OffsetT (&selection_indices)[ITEMS_PER_THREAD], + int num_tile_items, ///< Number of valid items in this tile + int num_tile_selections, ///< Number of selections in this tile + OffsetT num_selections_prefix, ///< Total number of selections prior to this tile + OffsetT num_rejected_prefix, ///< Total number of rejections prior to this tile + OffsetT num_selections) ///< Total number of selections including this tile + { + // Do a two-phase scatter if (a) keeping both partitions or (b) two-phase is enabled and the average number of selection_flags items per thread is greater than one + if (KEEP_REJECTS || (TWO_PHASE_SCATTER && (num_tile_selections > BLOCK_THREADS))) + { + ScatterTwoPhase( + items, + selection_flags, + selection_indices, + num_tile_items, + num_tile_selections, + num_selections_prefix, + num_rejected_prefix, + Int2Type()); + } + else + { + ScatterDirect( + items, + selection_flags, + selection_indices, + num_selections); + } + } + + //--------------------------------------------------------------------- + // Cooperatively scan a device-wide sequence of tiles with other CTAs + //--------------------------------------------------------------------- + + + /** + * Process first tile of input (dynamic chained scan). Returns the running count of selections (including this tile) + */ + template + __device__ __forceinline__ OffsetT ConsumeFirstTile( + int num_tile_items, ///< Number of input items comprising this tile + OffsetT tile_offset, ///< Tile offset + ScanTileStateT& tile_state) ///< Global tile state descriptor + { + InputT items[ITEMS_PER_THREAD]; + OffsetT selection_flags[ITEMS_PER_THREAD]; + OffsetT selection_indices[ITEMS_PER_THREAD]; + + // Load items + if (IS_LAST_TILE) + BlockLoadT(temp_storage.load_items).Load(d_in + tile_offset, items, num_tile_items); + else + BlockLoadT(temp_storage.load_items).Load(d_in + tile_offset, items); + + // Initialize selection_flags + InitializeSelections( + tile_offset, + num_tile_items, + items, + selection_flags, + Int2Type()); + + CTA_SYNC(); + + // Exclusive scan of selection_flags + OffsetT num_tile_selections; + BlockScanT(temp_storage.scan_storage.scan).ExclusiveSum(selection_flags, selection_indices, num_tile_selections); + + if (threadIdx.x == 0) + { + // Update tile status if this is not the last tile + if (!IS_LAST_TILE) + tile_state.SetInclusive(0, num_tile_selections); + } + + // Discount any out-of-bounds selections + if (IS_LAST_TILE) + num_tile_selections -= (TILE_ITEMS - num_tile_items); + + // Scatter flagged items + Scatter( + items, + selection_flags, + selection_indices, + num_tile_items, + num_tile_selections, + 0, + 0, + num_tile_selections); + + return num_tile_selections; + } + + + /** + * Process subsequent tile of input (dynamic chained scan). Returns the running count of selections (including this tile) + */ + template + __device__ __forceinline__ OffsetT ConsumeSubsequentTile( + int num_tile_items, ///< Number of input items comprising this tile + int tile_idx, ///< Tile index + OffsetT tile_offset, ///< Tile offset + ScanTileStateT& tile_state) ///< Global tile state descriptor + { + InputT items[ITEMS_PER_THREAD]; + OffsetT selection_flags[ITEMS_PER_THREAD]; + OffsetT selection_indices[ITEMS_PER_THREAD]; + + // Load items + if (IS_LAST_TILE) + BlockLoadT(temp_storage.load_items).Load(d_in + tile_offset, items, num_tile_items); + else + BlockLoadT(temp_storage.load_items).Load(d_in + tile_offset, items); + + // Initialize selection_flags + InitializeSelections( + tile_offset, + num_tile_items, + items, + selection_flags, + Int2Type()); + + CTA_SYNC(); + + // Exclusive scan of values and selection_flags + TilePrefixCallbackOpT prefix_op(tile_state, temp_storage.scan_storage.prefix, cub::Sum(), tile_idx); + BlockScanT(temp_storage.scan_storage.scan).ExclusiveSum(selection_flags, selection_indices, prefix_op); + + OffsetT num_tile_selections = prefix_op.GetBlockAggregate(); + OffsetT num_selections = prefix_op.GetInclusivePrefix(); + OffsetT num_selections_prefix = prefix_op.GetExclusivePrefix(); + OffsetT num_rejected_prefix = (tile_idx * TILE_ITEMS) - num_selections_prefix; + + // Discount any out-of-bounds selections + if (IS_LAST_TILE) + { + int num_discount = TILE_ITEMS - num_tile_items; + num_selections -= num_discount; + num_tile_selections -= num_discount; + } + + // Scatter flagged items + Scatter( + items, + selection_flags, + selection_indices, + num_tile_items, + num_tile_selections, + num_selections_prefix, + num_rejected_prefix, + num_selections); + + return num_selections; + } + + + /** + * Process a tile of input + */ + template + __device__ __forceinline__ OffsetT ConsumeTile( + int num_tile_items, ///< Number of input items comprising this tile + int tile_idx, ///< Tile index + OffsetT tile_offset, ///< Tile offset + ScanTileStateT& tile_state) ///< Global tile state descriptor + { + OffsetT num_selections; + if (tile_idx == 0) + { + num_selections = ConsumeFirstTile(num_tile_items, tile_offset, tile_state); + } + else + { + num_selections = ConsumeSubsequentTile(num_tile_items, tile_idx, tile_offset, tile_state); + } + + return num_selections; + } + + + /** + * Scan tiles of items as part of a dynamic chained scan + */ + template ///< Output iterator type for recording number of items selection_flags + __device__ __forceinline__ void ConsumeRange( + int num_tiles, ///< Total number of input tiles + ScanTileStateT& tile_state, ///< Global tile state descriptor + NumSelectedIteratorT d_num_selected_out) ///< Output total number selection_flags + { + // Blocks are launched in increasing order, so just assign one tile per block + int tile_idx = (blockIdx.x * gridDim.y) + blockIdx.y; // Current tile index + OffsetT tile_offset = tile_idx * TILE_ITEMS; // Global offset for the current tile + + if (tile_idx < num_tiles - 1) + { + // Not the last tile (full) + ConsumeTile(TILE_ITEMS, tile_idx, tile_offset, tile_state); + } + else + { + // The last tile (possibly partially-full) + OffsetT num_remaining = num_items - tile_offset; + OffsetT num_selections = ConsumeTile(num_remaining, tile_idx, tile_offset, tile_state); + + if (threadIdx.x == 0) + { + // Output the total number of items selection_flags + *d_num_selected_out = num_selections; + } + } + } + +}; + + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_spmv_orig.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_spmv_orig.cuh new file mode 100644 index 0000000000000000000000000000000000000000..c89bc4a3cd1518e0f5bd0e54a899d847a3523149 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_spmv_orig.cuh @@ -0,0 +1,680 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::AgentSpmv implements a stateful abstraction of CUDA thread blocks for participating in device-wide SpMV. + */ + +#pragma once + +#include + +#include "../util_type.cuh" +#include "../block/block_reduce.cuh" +#include "../block/block_scan.cuh" +#include "../block/block_exchange.cuh" +#include "../config.cuh" +#include "../thread/thread_search.cuh" +#include "../thread/thread_operators.cuh" +#include "../iterator/cache_modified_input_iterator.cuh" +#include "../iterator/counting_input_iterator.cuh" + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Tuning policy + ******************************************************************************/ + +/** + * Parameterizable tuning policy type for AgentSpmv + */ +template < + int _BLOCK_THREADS, ///< Threads per thread block + int _ITEMS_PER_THREAD, ///< Items per thread (per tile of input) + CacheLoadModifier _ROW_OFFSETS_SEARCH_LOAD_MODIFIER, ///< Cache load modifier for reading CSR row-offsets during search + CacheLoadModifier _ROW_OFFSETS_LOAD_MODIFIER, ///< Cache load modifier for reading CSR row-offsets + CacheLoadModifier _COLUMN_INDICES_LOAD_MODIFIER, ///< Cache load modifier for reading CSR column-indices + CacheLoadModifier _VALUES_LOAD_MODIFIER, ///< Cache load modifier for reading CSR values + CacheLoadModifier _VECTOR_VALUES_LOAD_MODIFIER, ///< Cache load modifier for reading vector values + bool _DIRECT_LOAD_NONZEROS, ///< Whether to load nonzeros directly from global during sequential merging (vs. pre-staged through shared memory) + BlockScanAlgorithm _SCAN_ALGORITHM> ///< The BlockScan algorithm to use +struct AgentSpmvPolicy +{ + enum + { + BLOCK_THREADS = _BLOCK_THREADS, ///< Threads per thread block + ITEMS_PER_THREAD = _ITEMS_PER_THREAD, ///< Items per thread (per tile of input) + DIRECT_LOAD_NONZEROS = _DIRECT_LOAD_NONZEROS, ///< Whether to load nonzeros directly from global during sequential merging (pre-staged through shared memory) + }; + + static const CacheLoadModifier ROW_OFFSETS_SEARCH_LOAD_MODIFIER = _ROW_OFFSETS_SEARCH_LOAD_MODIFIER; ///< Cache load modifier for reading CSR row-offsets + static const CacheLoadModifier ROW_OFFSETS_LOAD_MODIFIER = _ROW_OFFSETS_LOAD_MODIFIER; ///< Cache load modifier for reading CSR row-offsets + static const CacheLoadModifier COLUMN_INDICES_LOAD_MODIFIER = _COLUMN_INDICES_LOAD_MODIFIER; ///< Cache load modifier for reading CSR column-indices + static const CacheLoadModifier VALUES_LOAD_MODIFIER = _VALUES_LOAD_MODIFIER; ///< Cache load modifier for reading CSR values + static const CacheLoadModifier VECTOR_VALUES_LOAD_MODIFIER = _VECTOR_VALUES_LOAD_MODIFIER; ///< Cache load modifier for reading vector values + static const BlockScanAlgorithm SCAN_ALGORITHM = _SCAN_ALGORITHM; ///< The BlockScan algorithm to use + +}; + + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + +template < + typename ValueT, ///< Matrix and vector value type + typename OffsetT> ///< Signed integer type for sequence offsets +struct SpmvParams +{ + const ValueT* d_values; ///< Pointer to the array of \p num_nonzeros values of the corresponding nonzero elements of matrix A. + const OffsetT* d_row_end_offsets; ///< Pointer to the array of \p m offsets demarcating the end of every row in \p d_column_indices and \p d_values + const OffsetT* d_column_indices; ///< Pointer to the array of \p num_nonzeros column-indices of the corresponding nonzero elements of matrix A. (Indices are zero-valued.) + const ValueT* d_vector_x; ///< Pointer to the array of \p num_cols values corresponding to the dense input vector x + ValueT* d_vector_y; ///< Pointer to the array of \p num_rows values corresponding to the dense output vector y + int num_rows; ///< Number of rows of matrix A. + int num_cols; ///< Number of columns of matrix A. + int num_nonzeros; ///< Number of nonzero elements of matrix A. + ValueT alpha; ///< Alpha multiplicand + ValueT beta; ///< Beta addend-multiplicand +}; + + +/** + * \brief AgentSpmv implements a stateful abstraction of CUDA thread blocks for participating in device-wide SpMV. + */ +template < + typename AgentSpmvPolicyT, ///< Parameterized AgentSpmvPolicy tuning policy type + typename ValueT, ///< Matrix and vector value type + typename OffsetT, ///< Signed integer type for sequence offsets + bool HAS_ALPHA, ///< Whether the input parameter \p alpha is 1 + bool HAS_BETA, ///< Whether the input parameter \p beta is 0 + int LEGACY_PTX_ARCH = 0> ///< PTX compute capability (unused) +struct AgentSpmv +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + /// Constants + enum + { + BLOCK_THREADS = AgentSpmvPolicyT::BLOCK_THREADS, + ITEMS_PER_THREAD = AgentSpmvPolicyT::ITEMS_PER_THREAD, + TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD, + }; + + /// 2D merge path coordinate type + typedef typename CubVector::Type CoordinateT; + + /// Input iterator wrapper types (for applying cache modifiers) + + typedef CacheModifiedInputIterator< + AgentSpmvPolicyT::ROW_OFFSETS_SEARCH_LOAD_MODIFIER, + OffsetT, + OffsetT> + RowOffsetsSearchIteratorT; + + typedef CacheModifiedInputIterator< + AgentSpmvPolicyT::ROW_OFFSETS_LOAD_MODIFIER, + OffsetT, + OffsetT> + RowOffsetsIteratorT; + + typedef CacheModifiedInputIterator< + AgentSpmvPolicyT::COLUMN_INDICES_LOAD_MODIFIER, + OffsetT, + OffsetT> + ColumnIndicesIteratorT; + + typedef CacheModifiedInputIterator< + AgentSpmvPolicyT::VALUES_LOAD_MODIFIER, + ValueT, + OffsetT> + ValueIteratorT; + + typedef CacheModifiedInputIterator< + AgentSpmvPolicyT::VECTOR_VALUES_LOAD_MODIFIER, + ValueT, + OffsetT> + VectorValueIteratorT; + + // Tuple type for scanning (pairs accumulated segment-value with segment-index) + typedef KeyValuePair KeyValuePairT; + + // Reduce-value-by-segment scan operator + typedef ReduceByKeyOp ReduceBySegmentOpT; + + // BlockReduce specialization + typedef BlockReduce< + ValueT, + BLOCK_THREADS, + BLOCK_REDUCE_WARP_REDUCTIONS> + BlockReduceT; + + // BlockScan specialization + typedef BlockScan< + KeyValuePairT, + BLOCK_THREADS, + AgentSpmvPolicyT::SCAN_ALGORITHM> + BlockScanT; + + // BlockScan specialization + typedef BlockScan< + ValueT, + BLOCK_THREADS, + AgentSpmvPolicyT::SCAN_ALGORITHM> + BlockPrefixSumT; + + // BlockExchange specialization + typedef BlockExchange< + ValueT, + BLOCK_THREADS, + ITEMS_PER_THREAD> + BlockExchangeT; + + /// Merge item type (either a non-zero value or a row-end offset) + union MergeItem + { + // Value type to pair with index type OffsetT + // (NullType if loading values directly during merge) + using MergeValueT = + cub::detail::conditional_t< + AgentSpmvPolicyT::DIRECT_LOAD_NONZEROS, NullType, ValueT>; + + OffsetT row_end_offset; + MergeValueT nonzero; + }; + + /// Shared memory type required by this thread block + struct _TempStorage + { + CoordinateT tile_coords[2]; + + union Aliasable + { + // Smem needed for tile of merge items + MergeItem merge_items[ITEMS_PER_THREAD + TILE_ITEMS + 1]; + + // Smem needed for block exchange + typename BlockExchangeT::TempStorage exchange; + + // Smem needed for block-wide reduction + typename BlockReduceT::TempStorage reduce; + + // Smem needed for tile scanning + typename BlockScanT::TempStorage scan; + + // Smem needed for tile prefix sum + typename BlockPrefixSumT::TempStorage prefix_sum; + + } aliasable; + }; + + /// Temporary storage type (unionable) + struct TempStorage : Uninitialized<_TempStorage> {}; + + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + + _TempStorage& temp_storage; /// Reference to temp_storage + + SpmvParams& spmv_params; + + ValueIteratorT wd_values; ///< Wrapped pointer to the array of \p num_nonzeros values of the corresponding nonzero elements of matrix A. + RowOffsetsIteratorT wd_row_end_offsets; ///< Wrapped Pointer to the array of \p m offsets demarcating the end of every row in \p d_column_indices and \p d_values + ColumnIndicesIteratorT wd_column_indices; ///< Wrapped Pointer to the array of \p num_nonzeros column-indices of the corresponding nonzero elements of matrix A. (Indices are zero-valued.) + VectorValueIteratorT wd_vector_x; ///< Wrapped Pointer to the array of \p num_cols values corresponding to the dense input vector x + VectorValueIteratorT wd_vector_y; ///< Wrapped Pointer to the array of \p num_cols values corresponding to the dense input vector x + + + //--------------------------------------------------------------------- + // Interface + //--------------------------------------------------------------------- + + /** + * Constructor + */ + __device__ __forceinline__ AgentSpmv( + TempStorage& temp_storage, ///< Reference to temp_storage + SpmvParams& spmv_params) ///< SpMV input parameter bundle + : + temp_storage(temp_storage.Alias()), + spmv_params(spmv_params), + wd_values(spmv_params.d_values), + wd_row_end_offsets(spmv_params.d_row_end_offsets), + wd_column_indices(spmv_params.d_column_indices), + wd_vector_x(spmv_params.d_vector_x), + wd_vector_y(spmv_params.d_vector_y) + {} + + + + + /** + * Consume a merge tile, specialized for direct-load of nonzeros + */ + __device__ __forceinline__ KeyValuePairT ConsumeTile( + int tile_idx, + CoordinateT tile_start_coord, + CoordinateT tile_end_coord, + Int2Type is_direct_load) ///< Marker type indicating whether to load nonzeros directly during path-discovery or beforehand in batch + { + int tile_num_rows = tile_end_coord.x - tile_start_coord.x; + int tile_num_nonzeros = tile_end_coord.y - tile_start_coord.y; + OffsetT* s_tile_row_end_offsets = &temp_storage.aliasable.merge_items[0].row_end_offset; + + // Gather the row end-offsets for the merge tile into shared memory + for (int item = threadIdx.x; item < tile_num_rows + ITEMS_PER_THREAD; item += BLOCK_THREADS) + { + const OffsetT offset = + (cub::min)(static_cast(tile_start_coord.x + item), + static_cast(spmv_params.num_rows - 1)); + s_tile_row_end_offsets[item] = wd_row_end_offsets[offset]; + } + + CTA_SYNC(); + + // Search for the thread's starting coordinate within the merge tile + CountingInputIterator tile_nonzero_indices(tile_start_coord.y); + CoordinateT thread_start_coord; + + MergePathSearch( + OffsetT(threadIdx.x * ITEMS_PER_THREAD), // Diagonal + s_tile_row_end_offsets, // List A + tile_nonzero_indices, // List B + tile_num_rows, + tile_num_nonzeros, + thread_start_coord); + + CTA_SYNC(); // Perf-sync + + // Compute the thread's merge path segment + CoordinateT thread_current_coord = thread_start_coord; + KeyValuePairT scan_segment[ITEMS_PER_THREAD]; + + ValueT running_total = 0.0; + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + OffsetT nonzero_idx = CUB_MIN(tile_nonzero_indices[thread_current_coord.y], spmv_params.num_nonzeros - 1); + OffsetT column_idx = wd_column_indices[nonzero_idx]; + ValueT value = wd_values[nonzero_idx]; + + ValueT vector_value = wd_vector_x[column_idx]; + + ValueT nonzero = value * vector_value; + + OffsetT row_end_offset = s_tile_row_end_offsets[thread_current_coord.x]; + + if (tile_nonzero_indices[thread_current_coord.y] < row_end_offset) + { + // Move down (accumulate) + running_total += nonzero; + scan_segment[ITEM].value = running_total; + scan_segment[ITEM].key = tile_num_rows; + ++thread_current_coord.y; + } + else + { + // Move right (reset) + scan_segment[ITEM].value = running_total; + scan_segment[ITEM].key = thread_current_coord.x; + running_total = 0.0; + ++thread_current_coord.x; + } + } + + CTA_SYNC(); + + // Block-wide reduce-value-by-segment + KeyValuePairT tile_carry; + ReduceBySegmentOpT scan_op; + KeyValuePairT scan_item; + + scan_item.value = running_total; + scan_item.key = thread_current_coord.x; + + BlockScanT(temp_storage.aliasable.scan).ExclusiveScan(scan_item, scan_item, scan_op, tile_carry); + + if (tile_num_rows > 0) + { + if (threadIdx.x == 0) + scan_item.key = -1; + + // Direct scatter + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + if (scan_segment[ITEM].key < tile_num_rows) + { + if (scan_item.key == scan_segment[ITEM].key) + scan_segment[ITEM].value = scan_item.value + scan_segment[ITEM].value; + + if (HAS_ALPHA) + { + scan_segment[ITEM].value *= spmv_params.alpha; + } + + if (HAS_BETA) + { + // Update the output vector element + ValueT addend = spmv_params.beta * wd_vector_y[tile_start_coord.x + scan_segment[ITEM].key]; + scan_segment[ITEM].value += addend; + } + + // Set the output vector element + spmv_params.d_vector_y[tile_start_coord.x + scan_segment[ITEM].key] = scan_segment[ITEM].value; + } + } + } + + // Return the tile's running carry-out + return tile_carry; + } + + + + /** + * Consume a merge tile, specialized for indirect load of nonzeros + */ + __device__ __forceinline__ KeyValuePairT ConsumeTile( + int tile_idx, + CoordinateT tile_start_coord, + CoordinateT tile_end_coord, + Int2Type is_direct_load) ///< Marker type indicating whether to load nonzeros directly during path-discovery or beforehand in batch + { + int tile_num_rows = tile_end_coord.x - tile_start_coord.x; + int tile_num_nonzeros = tile_end_coord.y - tile_start_coord.y; + +#if (CUB_PTX_ARCH >= 520) + + OffsetT* s_tile_row_end_offsets = &temp_storage.aliasable.merge_items[0].row_end_offset; + ValueT* s_tile_nonzeros = &temp_storage.aliasable.merge_items[tile_num_rows + ITEMS_PER_THREAD].nonzero; + + // Gather the nonzeros for the merge tile into shared memory + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + int nonzero_idx = threadIdx.x + (ITEM * BLOCK_THREADS); + + ValueIteratorT a = wd_values + tile_start_coord.y + nonzero_idx; + ColumnIndicesIteratorT ci = wd_column_indices + tile_start_coord.y + nonzero_idx; + ValueT* s = s_tile_nonzeros + nonzero_idx; + + if (nonzero_idx < tile_num_nonzeros) + { + + OffsetT column_idx = *ci; + ValueT value = *a; + + ValueT vector_value = wd_vector_x[column_idx]; + + ValueT nonzero = value * vector_value; + + *s = nonzero; + } + } + + +#else + + OffsetT* s_tile_row_end_offsets = &temp_storage.aliasable.merge_items[0].row_end_offset; + ValueT* s_tile_nonzeros = &temp_storage.aliasable.merge_items[tile_num_rows + ITEMS_PER_THREAD].nonzero; + + // Gather the nonzeros for the merge tile into shared memory + if (tile_num_nonzeros > 0) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + int nonzero_idx = threadIdx.x + (ITEM * BLOCK_THREADS); + nonzero_idx = CUB_MIN(nonzero_idx, tile_num_nonzeros - 1); + + OffsetT column_idx = wd_column_indices[tile_start_coord.y + nonzero_idx]; + ValueT value = wd_values[tile_start_coord.y + nonzero_idx]; + + ValueT vector_value = wd_vector_x[column_idx]; + + ValueT nonzero = value * vector_value; + + s_tile_nonzeros[nonzero_idx] = nonzero; + } + } + +#endif + + // Gather the row end-offsets for the merge tile into shared memory + #pragma unroll 1 + for (int item = threadIdx.x; item < tile_num_rows + ITEMS_PER_THREAD; item += BLOCK_THREADS) + { + const OffsetT offset = + (cub::min)(static_cast(tile_start_coord.x + item), + static_cast(spmv_params.num_rows - 1)); + s_tile_row_end_offsets[item] = wd_row_end_offsets[offset]; + } + + CTA_SYNC(); + + // Search for the thread's starting coordinate within the merge tile + CountingInputIterator tile_nonzero_indices(tile_start_coord.y); + CoordinateT thread_start_coord; + + MergePathSearch( + OffsetT(threadIdx.x * ITEMS_PER_THREAD), // Diagonal + s_tile_row_end_offsets, // List A + tile_nonzero_indices, // List B + tile_num_rows, + tile_num_nonzeros, + thread_start_coord); + + CTA_SYNC(); // Perf-sync + + // Compute the thread's merge path segment + CoordinateT thread_current_coord = thread_start_coord; + KeyValuePairT scan_segment[ITEMS_PER_THREAD]; + ValueT running_total = 0.0; + + OffsetT row_end_offset = s_tile_row_end_offsets[thread_current_coord.x]; + ValueT nonzero = s_tile_nonzeros[thread_current_coord.y]; + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + if (tile_nonzero_indices[thread_current_coord.y] < row_end_offset) + { + // Move down (accumulate) + scan_segment[ITEM].value = nonzero; + running_total += nonzero; + ++thread_current_coord.y; + nonzero = s_tile_nonzeros[thread_current_coord.y]; + } + else + { + // Move right (reset) + scan_segment[ITEM].value = 0.0; + running_total = 0.0; + ++thread_current_coord.x; + row_end_offset = s_tile_row_end_offsets[thread_current_coord.x]; + } + + scan_segment[ITEM].key = thread_current_coord.x; + } + + CTA_SYNC(); + + // Block-wide reduce-value-by-segment + KeyValuePairT tile_carry; + ReduceBySegmentOpT scan_op; + KeyValuePairT scan_item; + + scan_item.value = running_total; + scan_item.key = thread_current_coord.x; + + BlockScanT(temp_storage.aliasable.scan).ExclusiveScan(scan_item, scan_item, scan_op, tile_carry); + + if (threadIdx.x == 0) + { + scan_item.key = thread_start_coord.x; + scan_item.value = 0.0; + } + + if (tile_num_rows > 0) + { + + CTA_SYNC(); + + // Scan downsweep and scatter + ValueT* s_partials = &temp_storage.aliasable.merge_items[0].nonzero; + + if (scan_item.key != scan_segment[0].key) + { + s_partials[scan_item.key] = scan_item.value; + } + else + { + scan_segment[0].value += scan_item.value; + } + + #pragma unroll + for (int ITEM = 1; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + if (scan_segment[ITEM - 1].key != scan_segment[ITEM].key) + { + s_partials[scan_segment[ITEM - 1].key] = scan_segment[ITEM - 1].value; + } + else + { + scan_segment[ITEM].value += scan_segment[ITEM - 1].value; + } + } + + CTA_SYNC(); + + #pragma unroll 1 + for (int item = threadIdx.x; item < tile_num_rows; item += BLOCK_THREADS) + { + spmv_params.d_vector_y[tile_start_coord.x + item] = s_partials[item]; + } + } + + // Return the tile's running carry-out + return tile_carry; + } + + + /** + * Consume input tile + */ + __device__ __forceinline__ void ConsumeTile( + CoordinateT* d_tile_coordinates, ///< [in] Pointer to the temporary array of tile starting coordinates + KeyValuePairT* d_tile_carry_pairs, ///< [out] Pointer to the temporary array carry-out dot product row-ids, one per block + int num_merge_tiles) ///< [in] Number of merge tiles + { + int tile_idx = (blockIdx.x * gridDim.y) + blockIdx.y; // Current tile index + + if (tile_idx >= num_merge_tiles) + return; + + // Read our starting coordinates + if (threadIdx.x < 2) + { + if (d_tile_coordinates == NULL) + { + // Search our starting coordinates + OffsetT diagonal = (tile_idx + threadIdx.x) * TILE_ITEMS; + CoordinateT tile_coord; + CountingInputIterator nonzero_indices(0); + + // Search the merge path + MergePathSearch( + diagonal, + RowOffsetsSearchIteratorT(spmv_params.d_row_end_offsets), + nonzero_indices, + spmv_params.num_rows, + spmv_params.num_nonzeros, + tile_coord); + + temp_storage.tile_coords[threadIdx.x] = tile_coord; + } + else + { + temp_storage.tile_coords[threadIdx.x] = d_tile_coordinates[tile_idx + threadIdx.x]; + } + } + + CTA_SYNC(); + + CoordinateT tile_start_coord = temp_storage.tile_coords[0]; + CoordinateT tile_end_coord = temp_storage.tile_coords[1]; + + // Consume multi-segment tile + KeyValuePairT tile_carry = ConsumeTile( + tile_idx, + tile_start_coord, + tile_end_coord, + Int2Type()); + + // Output the tile's carry-out + if (threadIdx.x == 0) + { + if (HAS_ALPHA) + { + tile_carry.value *= spmv_params.alpha; + } + + tile_carry.key += tile_start_coord.x; + if (tile_carry.key >= spmv_params.num_rows) + { + // FIXME: This works around an invalid memory access in the + // fixup kernel. The underlying issue needs to be debugged and + // properly fixed, but this hack prevents writes to + // out-of-bounds addresses. It doesn't appear to have an effect + // on the validity of the results, since this only affects the + // carry-over from last tile in the input. + tile_carry.key = spmv_params.num_rows - 1; + tile_carry.value = ValueT{}; + }; + + d_tile_carry_pairs[tile_idx] = tile_carry; + } + } + + +}; + + + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_sub_warp_merge_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_sub_warp_merge_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..757d519ca5cc18755faecc14ea8123fec75ed29f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_sub_warp_merge_sort.cuh @@ -0,0 +1,360 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include + +#include + + +CUB_NAMESPACE_BEGIN + + +template < + int WARP_THREADS_ARG, + int ITEMS_PER_THREAD_ARG, + cub::WarpLoadAlgorithm LOAD_ALGORITHM_ARG = cub::WARP_LOAD_DIRECT, + cub::CacheLoadModifier LOAD_MODIFIER_ARG = cub::LOAD_LDG, + cub::WarpStoreAlgorithm STORE_ALGORITHM_ARG = cub::WARP_STORE_DIRECT> +struct AgentSubWarpMergeSortPolicy +{ + static constexpr int WARP_THREADS = WARP_THREADS_ARG; + static constexpr int ITEMS_PER_THREAD = ITEMS_PER_THREAD_ARG; + static constexpr int ITEMS_PER_TILE = WARP_THREADS * ITEMS_PER_THREAD; + + static constexpr cub::WarpLoadAlgorithm LOAD_ALGORITHM = LOAD_ALGORITHM_ARG; + static constexpr cub::CacheLoadModifier LOAD_MODIFIER = LOAD_MODIFIER_ARG; + static constexpr cub::WarpStoreAlgorithm STORE_ALGORITHM = STORE_ALGORITHM_ARG; +}; + +template +struct AgentSmallAndMediumSegmentedSortPolicy +{ + static constexpr int BLOCK_THREADS = BLOCK_THREADS_ARG; + using SmallPolicyT = SmallPolicy; + using MediumPolicyT = MediumPolicy; + + constexpr static int SEGMENTS_PER_MEDIUM_BLOCK = BLOCK_THREADS / + MediumPolicyT::WARP_THREADS; + + constexpr static int SEGMENTS_PER_SMALL_BLOCK = BLOCK_THREADS / + SmallPolicyT::WARP_THREADS; +}; + + +/** + * @brief AgentSubWarpSort implements a sub-warp merge sort. + * + * This agent can work with any power of two number of threads, not exceeding + * 32. The number of threads is defined in the `PolicyT::WARP_THREADS`. Virtual + * warp of `PolicyT::WARP_THREADS` will efficiently load data using + * `PolicyT::LOAD_ALGORITHM`, sort it using `WarpMergeSort`, and store it back + * using `PolicyT::STORE_ALGORITHM`. + * + * @tparam IS_DESCENDING + * Whether or not the sorted-order is high-to-low + * + * @tparam PolicyT + * Chained tuning policy + * + * @tparam KeyT + * Key type + * + * @tparam ValueT + * Value type + * + * @tparam OffsetT + * Signed integer type for global offsets + */ +template +class AgentSubWarpSort +{ + using traits = detail::radix::traits_t; + using bit_ordered_type = typename traits::bit_ordered_type; + + struct BinaryOpT + { + template + __device__ bool operator()(T lhs, T rhs) + { + return this->impl(lhs, rhs); + } + +#if defined(__CUDA_FP16_TYPES_EXIST__) + __device__ bool operator()(__half lhs, __half rhs) + { + // Need to explicitly cast to float for SM <= 52. + NV_IF_TARGET(NV_PROVIDES_SM_53, + (return this->impl(lhs, rhs);), + (return this->impl(__half2float(lhs), __half2float(rhs));)); + } +#endif + + private: + template + __device__ bool impl(T lhs, T rhs) + { + if (IS_DESCENDING) + { + return lhs > rhs; + } + else + { + return lhs < rhs; + } + } + }; + +#if defined(__CUDA_FP16_TYPES_EXIST__) + __device__ static bool equal(__half lhs, __half rhs) + { + // Need to explicitly cast to float for SM <= 52. + NV_IF_TARGET(NV_PROVIDES_SM_53, + (return lhs == rhs;), + (return __half2float(lhs) == __half2float(rhs);)); + } +#endif + + template + __device__ static bool equal(T lhs, T rhs) + { + return lhs == rhs; + } + + __device__ static bool get_oob_default(Int2Type /* is bool */) + { + // Traits::MAX_KEY for `bool` is 0xFF which is different from `true` and makes + // comparison with oob unreliable. + return !IS_DESCENDING; + } + + __device__ static KeyT get_oob_default(Int2Type /* is bool */) + { + // For FP64 the difference is: + // Lowest() -> -1.79769e+308 = 00...00b -> TwiddleIn -> -0 = 10...00b + // LOWEST -> -nan = 11...11b -> TwiddleIn -> 0 = 00...00b + + // Segmented sort doesn't support custom types at the moment. + bit_ordered_type default_key_bits = IS_DESCENDING + ? traits::min_raw_binary_key(detail::identity_decomposer_t{}) + : traits::max_raw_binary_key(detail::identity_decomposer_t{}); + return reinterpret_cast(default_key_bits); + } + +public: + static constexpr bool KEYS_ONLY = std::is_same::value; + + using WarpMergeSortT = + WarpMergeSort; + + using KeysLoadItT = typename THRUST_NS_QUALIFIER::cuda_cub::core:: + LoadIterator::type; + using ItemsLoadItT = typename THRUST_NS_QUALIFIER::cuda_cub::core:: + LoadIterator::type; + + using WarpLoadKeysT = cub::WarpLoad; + using WarpLoadItemsT = cub::WarpLoad; + + using WarpStoreKeysT = cub::WarpStore; + using WarpStoreItemsT = cub::WarpStore; + + union _TempStorage + { + typename WarpLoadKeysT::TempStorage load_keys; + typename WarpLoadItemsT::TempStorage load_items; + typename WarpMergeSortT::TempStorage sort; + typename WarpStoreKeysT::TempStorage store_keys; + typename WarpStoreItemsT::TempStorage store_items; + }; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + _TempStorage &storage; + + __device__ __forceinline__ + explicit AgentSubWarpSort(TempStorage &temp_storage) + : storage(temp_storage.Alias()) + { + } + + + __device__ __forceinline__ + void ProcessSegment(int segment_size, + KeysLoadItT keys_input, + KeyT *keys_output, + ItemsLoadItT values_input, + ValueT *values_output) + { + WarpMergeSortT warp_merge_sort(storage.sort); + + if (segment_size < 3) + { + ShortCircuit(warp_merge_sort.get_linear_tid(), + segment_size, + keys_input, + keys_output, + values_input, + values_output, + BinaryOpT{}); + } + else + { + KeyT keys[PolicyT::ITEMS_PER_THREAD]; + ValueT values[PolicyT::ITEMS_PER_THREAD]; + + KeyT oob_default = + AgentSubWarpSort::get_oob_default(Int2Type::value>{}); + + WarpLoadKeysT(storage.load_keys) + .Load(keys_input, keys, segment_size, oob_default); + WARP_SYNC(warp_merge_sort.get_member_mask()); + + if (!KEYS_ONLY) + { + WarpLoadItemsT(storage.load_items) + .Load(values_input, values, segment_size); + + WARP_SYNC(warp_merge_sort.get_member_mask()); + } + + warp_merge_sort.Sort(keys, values, BinaryOpT{}, segment_size, oob_default); + WARP_SYNC(warp_merge_sort.get_member_mask()); + + WarpStoreKeysT(storage.store_keys).Store(keys_output, keys, segment_size); + + if (!KEYS_ONLY) + { + WARP_SYNC(warp_merge_sort.get_member_mask()); + WarpStoreItemsT(storage.store_items) + .Store(values_output, values, segment_size); + } + } + } + +private: + /** + * This method implements a shortcut for sorting less than three items. + * Only the first thread of a virtual warp is used for soring. + */ + template + __device__ __forceinline__ void ShortCircuit(unsigned int linear_tid, + OffsetT segment_size, + KeysLoadItT keys_input, + KeyT *keys_output, + ItemsLoadItT values_input, + ValueT *values_output, + CompareOpT binary_op) + { + if (segment_size == 1) + { + if (linear_tid == 0) + { + if (keys_input.ptr != keys_output) + { + keys_output[0] = keys_input[0]; + } + + if (!KEYS_ONLY) + { + if (values_input.ptr != values_output) + { + values_output[0] = values_input[0]; + } + } + } + } + else if (segment_size == 2) + { + if (linear_tid == 0) + { + KeyT lhs = keys_input[0]; + KeyT rhs = keys_input[1]; + + if (equal(lhs, rhs) || binary_op(lhs, rhs)) + { + keys_output[0] = lhs; + keys_output[1] = rhs; + + if (!KEYS_ONLY) + { + if (values_output != values_input.ptr) + { + values_output[0] = values_input[0]; + values_output[1] = values_input[1]; + } + } + } + else + { + keys_output[0] = rhs; + keys_output[1] = lhs; + + if (!KEYS_ONLY) + { + // values_output might be an alias for values_input, so + // we have to use registers here + + const ValueT lhs_val = values_input[0]; + const ValueT rhs_val = values_input[1]; + + values_output[0] = rhs_val; + values_output[1] = lhs_val; + } + } + } + } + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_three_way_partition.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_three_way_partition.cuh new file mode 100644 index 0000000000000000000000000000000000000000..6d81fdb514a139231afc89d7fbde6c8dc379d427 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_three_way_partition.cuh @@ -0,0 +1,618 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Tuning policy types + ******************************************************************************/ + +namespace detail +{ + +namespace three_way_partition +{ + +template +struct pair_pack_t +{ + OffsetT x, y; + + __device__ pair_pack_t operator+(const pair_pack_t &other) const + { + return {x + other.x, y + other.y}; + } +}; + +template +struct accumulator_pack_base_t +{ + using pack_t = pair_pack_t; + + __device__ static pack_t pack(OffsetT f, OffsetT s) { return {f, s}; } + __device__ static OffsetT first(pack_t packed) { return packed.x; } + __device__ static OffsetT second(pack_t packed) { return packed.y; } +}; + +template +struct accumulator_pack_base_t::type> +{ + using pack_t = std::uint64_t; + + __device__ static pack_t pack(OffsetT f, OffsetT s) + { + return (static_cast(f) << 32) | static_cast(s); + } + + __device__ static OffsetT first(pack_t packed) { return static_cast(packed >> 32); } + + __device__ static OffsetT second(pack_t packed) + { + return static_cast(packed & 0xFFFFFFFF); + } +}; + +template +struct accumulator_pack_t : accumulator_pack_base_t +{ + using typename accumulator_pack_base_t::pack_t; + + __device__ static void subtract(pack_t &packed, OffsetT val) + { + packed = pack(first(packed) - val, second(packed) - val); + } + + __device__ static OffsetT sum(pack_t &packed) + { + return first(packed) + second(packed); + } + + __device__ static pack_t zero() + { + return {}; + } +}; + +} + +} + +template > +struct AgentThreeWayPartitionPolicy +{ + constexpr static int BLOCK_THREADS = _BLOCK_THREADS; + constexpr static int ITEMS_PER_THREAD = _ITEMS_PER_THREAD; + constexpr static BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; + constexpr static CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; + constexpr static BlockScanAlgorithm SCAN_ALGORITHM = _SCAN_ALGORITHM; + + struct detail + { + using delay_constructor_t = DelayConstructorT; + }; +}; + + +/** + * \brief Implements a device-wide three-way partitioning + * + * Splits input data into three parts based on the selection functors. If the + * first functor selects an item, the algorithm places it in the first part. + * Otherwise, if the second functor selects an item, the algorithm places it in + * the second part. If both functors don't select an item, the algorithm places + * it into the unselected part. + */ +template +struct AgentThreeWayPartition +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + // The input value type + using InputT = cub::detail::value_t; + + using AccumPackHelperT = detail::three_way_partition::accumulator_pack_t; + using AccumPackT = typename AccumPackHelperT::pack_t; + + // Tile status descriptor interface type + using ScanTileStateT = cub::ScanTileState; + + // Constants + constexpr static int BLOCK_THREADS = PolicyT::BLOCK_THREADS; + constexpr static int ITEMS_PER_THREAD = PolicyT::ITEMS_PER_THREAD; + constexpr static int TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD; + + using WrappedInputIteratorT = cub::detail::conditional_t< + std::is_pointer::value, + cub::CacheModifiedInputIterator, + InputIteratorT>; + + // Parameterized BlockLoad type for input data + using BlockLoadT = cub::BlockLoad; + + // Parameterized BlockScan type + using BlockScanT = + cub::BlockScan; + + // Callback type for obtaining tile prefix during block scan + using DelayConstructorT = typename PolicyT::detail::delay_constructor_t; + using TilePrefixCallbackOpT = + cub::TilePrefixCallbackOp; + + // Item exchange type + using ItemExchangeT = InputT[TILE_ITEMS]; + + // Shared memory type for this thread block + union _TempStorage + { + struct ScanStorage + { + // Smem needed for tile scanning + typename BlockScanT::TempStorage scan; + + // Smem needed for cooperative prefix callback + typename TilePrefixCallbackOpT::TempStorage prefix; + } scan_storage; + + // Smem needed for loading items + typename BlockLoadT::TempStorage load_items; + + // Smem needed for compacting items (allows non POD items in this union) + cub::Uninitialized raw_exchange; + }; + + // Alias wrapper allowing storage to be unioned + struct TempStorage : cub::Uninitialized<_TempStorage> {}; + + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + _TempStorage& temp_storage; ///< Reference to temp_storage + WrappedInputIteratorT d_in; ///< Input items + FirstOutputIteratorT d_first_part_out; + SecondOutputIteratorT d_second_part_out; + UnselectedOutputIteratorT d_unselected_out; + SelectFirstPartOp select_first_part_op; + SelectSecondPartOp select_second_part_op; + OffsetT num_items; ///< Total number of input items + + + //--------------------------------------------------------------------- + // Constructor + //--------------------------------------------------------------------- + + // Constructor + __device__ __forceinline__ + AgentThreeWayPartition(TempStorage &temp_storage, + InputIteratorT d_in, + FirstOutputIteratorT d_first_part_out, + SecondOutputIteratorT d_second_part_out, + UnselectedOutputIteratorT d_unselected_out, + SelectFirstPartOp select_first_part_op, + SelectSecondPartOp select_second_part_op, + OffsetT num_items) + : temp_storage(temp_storage.Alias()) + , d_in(d_in) + , d_first_part_out(d_first_part_out) + , d_second_part_out(d_second_part_out) + , d_unselected_out(d_unselected_out) + , select_first_part_op(select_first_part_op) + , select_second_part_op(select_second_part_op) + , num_items(num_items) + {} + + //--------------------------------------------------------------------- + // Utility methods for initializing the selections + //--------------------------------------------------------------------- + + template + __device__ __forceinline__ void + Initialize(OffsetT num_tile_items, + InputT (&items)[ITEMS_PER_THREAD], + AccumPackT (&items_selection_flags)[ITEMS_PER_THREAD]) + { + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + // Out-of-bounds items are selection_flags + items_selection_flags[ITEM] = AccumPackHelperT::pack(1, 1); + + if (!IS_LAST_TILE || (OffsetT(threadIdx.x * ITEMS_PER_THREAD) + ITEM < num_tile_items)) + { + OffsetT first_item_selected = select_first_part_op(items[ITEM]); + items_selection_flags[ITEM] = + AccumPackHelperT::pack(first_item_selected, + first_item_selected ? 0 : select_second_part_op(items[ITEM])); + } + } + } + + template + __device__ __forceinline__ void Scatter( + InputT (&items)[ITEMS_PER_THREAD], + AccumPackT (&items_selection_flags)[ITEMS_PER_THREAD], + AccumPackT (&items_selection_indices)[ITEMS_PER_THREAD], + int num_tile_items, + AccumPackT num_tile_selected, + AccumPackT num_tile_selected_prefix, + OffsetT num_rejected_prefix) + { + CTA_SYNC(); + + const OffsetT num_first_selections_prefix = AccumPackHelperT::first(num_tile_selected_prefix); + const OffsetT num_second_selections_prefix = AccumPackHelperT::second(num_tile_selected_prefix); + + const int first_item_end = AccumPackHelperT::first(num_tile_selected); + const int second_item_end = first_item_end + AccumPackHelperT::second(num_tile_selected); + + // Scatter items to shared memory (rejections first) + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + int item_idx = (threadIdx.x * ITEMS_PER_THREAD) + ITEM; + + const OffsetT first_items_selection_indices = AccumPackHelperT::first(items_selection_indices[ITEM]); + const OffsetT second_items_selection_indices = AccumPackHelperT::second(items_selection_indices[ITEM]); + + if (!IS_LAST_TILE || (item_idx < num_tile_items)) + { + int local_scatter_offset = 0; + + if (AccumPackHelperT::first(items_selection_flags[ITEM])) + { + local_scatter_offset = first_items_selection_indices + - num_first_selections_prefix; + } + else if (AccumPackHelperT::second(items_selection_flags[ITEM])) + { + local_scatter_offset = first_item_end + + second_items_selection_indices - + num_second_selections_prefix; + } + else + { + // Medium item + int local_selection_idx = + (first_items_selection_indices - num_first_selections_prefix) + + (second_items_selection_indices - num_second_selections_prefix); + local_scatter_offset = second_item_end + item_idx - local_selection_idx; + } + + temp_storage.raw_exchange.Alias()[local_scatter_offset] = items[ITEM]; + } + } + + CTA_SYNC(); + + // Gather items from shared memory and scatter to global + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + int item_idx = (ITEM * BLOCK_THREADS) + threadIdx.x; + + if (!IS_LAST_TILE || (item_idx < num_tile_items)) + { + InputT item = temp_storage.raw_exchange.Alias()[item_idx]; + + if (item_idx < first_item_end) + { + d_first_part_out[num_first_selections_prefix + item_idx] = item; + } + else if (item_idx < second_item_end) + { + d_second_part_out[num_second_selections_prefix + item_idx - first_item_end] = item; + } + else + { + int rejection_idx = item_idx - second_item_end; + d_unselected_out[num_rejected_prefix + rejection_idx] = item; + } + } + } + } + + + //--------------------------------------------------------------------- + // Cooperatively scan a device-wide sequence of tiles with other CTAs + //--------------------------------------------------------------------- + + + /** + * Process first tile of input (dynamic chained scan). + * Returns the running count of selections (including this tile) + * + * @param num_tile_items Number of input items comprising this tile + * @param tile_offset Tile offset + * @param first_tile_state Global tile state descriptor + * @param second_tile_state Global tile state descriptor + */ + template + __device__ __forceinline__ void + ConsumeFirstTile(int num_tile_items, + OffsetT tile_offset, + ScanTileStateT &tile_state, + AccumPackT &num_items_selected) + { + InputT items[ITEMS_PER_THREAD]; + + AccumPackT items_selection_flags[ITEMS_PER_THREAD]; + AccumPackT items_selection_indices[ITEMS_PER_THREAD]; + + // Load items + if (IS_LAST_TILE) + { + BlockLoadT(temp_storage.load_items) + .Load(d_in + tile_offset, items, num_tile_items); + } + else + { + BlockLoadT(temp_storage.load_items).Load(d_in + tile_offset, items); + } + + // Initialize selection_flags + Initialize(num_tile_items, items, items_selection_flags); + CTA_SYNC(); + + // Exclusive scan of selection_flags + BlockScanT(temp_storage.scan_storage.scan) + .ExclusiveSum(items_selection_flags, + items_selection_indices, + num_items_selected); + + if (threadIdx.x == 0) + { + // Update tile status if this is not the last tile + if (!IS_LAST_TILE) + { + tile_state.SetInclusive(0, num_items_selected); + } + } + + // Discount any out-of-bounds selections + if (IS_LAST_TILE) + { + AccumPackHelperT::subtract(num_items_selected, TILE_ITEMS - num_tile_items); + } + + // Scatter flagged items + Scatter( + items, + items_selection_flags, + items_selection_indices, + num_tile_items, + num_items_selected, + // all the prefixes equal to 0 because it's the first tile + AccumPackHelperT::zero(), + 0); + } + + + /** + * Process subsequent tile of input (dynamic chained scan). + * Returns the running count of selections (including this tile) + * + * @param num_tile_items Number of input items comprising this tile + * @param tile_idx Tile index + * @param tile_offset Tile offset + * @param first_tile_state Global tile state descriptor + * @param second_tile_state Global tile state descriptor + */ + template + __device__ __forceinline__ void + ConsumeSubsequentTile(int num_tile_items, + int tile_idx, + OffsetT tile_offset, + ScanTileStateT &tile_state, + AccumPackT &num_items_selected) + { + InputT items[ITEMS_PER_THREAD]; + + AccumPackT items_selected_flags[ITEMS_PER_THREAD]; + AccumPackT items_selected_indices[ITEMS_PER_THREAD]; + + // Load items + if (IS_LAST_TILE) + { + BlockLoadT(temp_storage.load_items).Load( + d_in + tile_offset, items, num_tile_items); + } + else + { + BlockLoadT(temp_storage.load_items).Load(d_in + tile_offset, items); + } + + // Initialize selection_flags + Initialize(num_tile_items, items, items_selected_flags); + CTA_SYNC(); + + // Exclusive scan of values and selection_flags + TilePrefixCallbackOpT prefix_op(tile_state, + temp_storage.scan_storage.prefix, + cub::Sum(), + tile_idx); + + BlockScanT(temp_storage.scan_storage.scan) + .ExclusiveSum(items_selected_flags, + items_selected_indices, + prefix_op); + + num_items_selected = prefix_op.GetInclusivePrefix(); + AccumPackT num_items_in_tile_selected = prefix_op.GetBlockAggregate(); + AccumPackT num_items_selected_prefix = prefix_op.GetExclusivePrefix(); + + CTA_SYNC(); + + OffsetT num_rejected_prefix = (tile_idx * TILE_ITEMS) - + AccumPackHelperT::sum(num_items_selected_prefix); + + // Discount any out-of-bounds selections. There are exactly + // TILE_ITEMS - num_tile_items elements like that because we + // marked them as selected in Initialize method. + if (IS_LAST_TILE) + { + const int num_discount = TILE_ITEMS - num_tile_items; + + AccumPackHelperT::subtract(num_items_selected, num_discount); + AccumPackHelperT::subtract(num_items_in_tile_selected, num_discount); + } + + // Scatter flagged items + Scatter( + items, + items_selected_flags, + items_selected_indices, + num_tile_items, + num_items_in_tile_selected, + num_items_selected_prefix, + num_rejected_prefix); + } + + + /** + * Process a tile of input + */ + template + __device__ __forceinline__ void ConsumeTile( + int num_tile_items, + int tile_idx, + OffsetT tile_offset, + ScanTileStateT& tile_state, + AccumPackT& accum) + { + if (tile_idx == 0) + { + ConsumeFirstTile(num_tile_items, + tile_offset, + tile_state, + accum); + } + else + { + ConsumeSubsequentTile(num_tile_items, + tile_idx, + tile_offset, + tile_state, + accum); + } + } + + + /** + * Scan tiles of items as part of a dynamic chained scan + * + * @tparam NumSelectedIteratorT + * Output iterator type for recording number of items selection_flags + * + * @param num_tiles + * Total number of input tiles + * + * @param first_tile_state + * Global tile state descriptor + * + * @param second_tile_state + * Global tile state descriptor + * + * @param d_num_selected_out + * Output total number selection_flags + */ + template + __device__ __forceinline__ void + ConsumeRange(int num_tiles, ScanTileStateT &tile_state, NumSelectedIteratorT d_num_selected_out) + { + // Blocks are launched in increasing order, so just assign one tile per block + // Current tile index + const int tile_idx = static_cast((blockIdx.x * gridDim.y) + blockIdx.y); + + // Global offset for the current tile + const OffsetT tile_offset = tile_idx * TILE_ITEMS; + + AccumPackT accum; + + if (tile_idx < num_tiles - 1) + { + // Not the last tile (full) + ConsumeTile(TILE_ITEMS, + tile_idx, + tile_offset, + tile_state, + accum); + } + else + { + // The last tile (possibly partially-full) + const OffsetT num_remaining = num_items - tile_offset; + + ConsumeTile(num_remaining, + tile_idx, + tile_offset, + tile_state, + accum); + + if (threadIdx.x == 0) + { + // Output the total number of items selection_flags + d_num_selected_out[0] = AccumPackHelperT::first(accum); + d_num_selected_out[1] = AccumPackHelperT::second(accum); + } + } + } + +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_unique_by_key.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_unique_by_key.cuh new file mode 100644 index 0000000000000000000000000000000000000000..54c87cd4125a4fe6bb2a6465ddac63637fe09e6f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/agent_unique_by_key.cuh @@ -0,0 +1,583 @@ +/****************************************************************************** + * Copyright (c) NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::AgentUniqueByKey implements a stateful abstraction of CUDA thread blocks for participating in device-wide unique-by-key. + */ + +#pragma once + +#include +#include + +#include "../thread/thread_operators.cuh" +#include "../block/block_load.cuh" +#include "../block/block_scan.cuh" +#include "../agent/single_pass_scan_operators.cuh" +#include "../block/block_discontinuity.cuh" + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Tuning policy types + ******************************************************************************/ + +/** + * Parameterizable tuning policy type for AgentUniqueByKey + * + * @tparam DelayConstructorT + * Implementation detail, do not specify directly, requirements on the + * content of this type are subject to breaking change. + */ +template > +struct AgentUniqueByKeyPolicy +{ + enum + { + BLOCK_THREADS = _BLOCK_THREADS, + ITEMS_PER_THREAD = _ITEMS_PER_THREAD, + }; + static const cub::BlockLoadAlgorithm LOAD_ALGORITHM = _LOAD_ALGORITHM; + static const cub::CacheLoadModifier LOAD_MODIFIER = _LOAD_MODIFIER; + static const cub::BlockScanAlgorithm SCAN_ALGORITHM = _SCAN_ALGORITHM; + + struct detail + { + using delay_constructor_t = DelayConstructorT; + }; +}; + + + + +/****************************************************************************** + * Thread block abstractions + ******************************************************************************/ + + +/** + * \brief AgentUniqueByKey implements a stateful abstraction of CUDA thread blocks for participating in device-wide unique-by-key + */ +template < + typename AgentUniqueByKeyPolicyT, ///< Parameterized AgentUniqueByKeyPolicy tuning policy type + typename KeyInputIteratorT, ///< Random-access input iterator type for keys + typename ValueInputIteratorT, ///< Random-access input iterator type for values + typename KeyOutputIteratorT, ///< Random-access output iterator type for keys + typename ValueOutputIteratorT, ///< Random-access output iterator type for values + typename EqualityOpT, ///< Equality operator type + typename OffsetT> ///< Signed integer type for global offsets +struct AgentUniqueByKey +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + // The input key and value type + using KeyT = typename std::iterator_traits::value_type; + using ValueT = typename std::iterator_traits::value_type; + + // Tile status descriptor interface type + using ScanTileStateT = ScanTileState; + + // Constants + enum + { + BLOCK_THREADS = AgentUniqueByKeyPolicyT::BLOCK_THREADS, + ITEMS_PER_THREAD = AgentUniqueByKeyPolicyT::ITEMS_PER_THREAD, + ITEMS_PER_TILE = BLOCK_THREADS * ITEMS_PER_THREAD, + }; + + // Cache-modified Input iterator wrapper type (for applying cache modifier) for keys + using WrappedKeyInputIteratorT = typename std::conditional::value, + CacheModifiedInputIterator, // Wrap the native input pointer with CacheModifiedValuesInputIterator + KeyInputIteratorT>::type; // Directly use the supplied input iterator type + + // Cache-modified Input iterator wrapper type (for applying cache modifier) for values + using WrappedValueInputIteratorT = typename std::conditional::value, + CacheModifiedInputIterator, // Wrap the native input pointer with CacheModifiedValuesInputIterator + ValueInputIteratorT>::type; // Directly use the supplied input iterator type + + // Parameterized BlockLoad type for input data + using BlockLoadKeys = BlockLoad< + KeyT, + BLOCK_THREADS, + ITEMS_PER_THREAD, + AgentUniqueByKeyPolicyT::LOAD_ALGORITHM>; + + // Parameterized BlockLoad type for flags + using BlockLoadValues = BlockLoad< + ValueT, + BLOCK_THREADS, + ITEMS_PER_THREAD, + AgentUniqueByKeyPolicyT::LOAD_ALGORITHM>; + + // Parameterized BlockDiscontinuity type for items + using BlockDiscontinuityKeys = cub::BlockDiscontinuity; + + // Parameterized BlockScan type + using BlockScanT = cub::BlockScan; + + // Parameterized BlockDiscontinuity type for items + using DelayConstructorT = typename AgentUniqueByKeyPolicyT::detail::delay_constructor_t; + using TilePrefixCallback = + cub::TilePrefixCallbackOp; + + // Key exchange type + using KeyExchangeT = KeyT[ITEMS_PER_TILE]; + + // Value exchange type + using ValueExchangeT = ValueT[ITEMS_PER_TILE]; + + // Shared memory type for this thread block + union _TempStorage + { + struct ScanStorage + { + typename BlockScanT::TempStorage scan; + typename TilePrefixCallback::TempStorage prefix; + typename BlockDiscontinuityKeys::TempStorage discontinuity; + } scan_storage; + + // Smem needed for loading keys + typename BlockLoadKeys::TempStorage load_keys; + + // Smem needed for loading values + typename BlockLoadValues::TempStorage load_values; + + // Smem needed for compacting items (allows non POD items in this union) + Uninitialized shared_keys; + Uninitialized shared_values; + }; + + // Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + _TempStorage& temp_storage; + WrappedKeyInputIteratorT d_keys_in; + WrappedValueInputIteratorT d_values_in; + KeyOutputIteratorT d_keys_out; + ValueOutputIteratorT d_values_out; + cub::InequalityWrapper inequality_op; + OffsetT num_items; + + + //--------------------------------------------------------------------- + // Constructor + //--------------------------------------------------------------------- + + // Constructor + __device__ __forceinline__ + AgentUniqueByKey( + TempStorage &temp_storage_, + WrappedKeyInputIteratorT d_keys_in_, + WrappedValueInputIteratorT d_values_in_, + KeyOutputIteratorT d_keys_out_, + ValueOutputIteratorT d_values_out_, + EqualityOpT equality_op_, + OffsetT num_items_) + : + temp_storage(temp_storage_.Alias()), + d_keys_in(d_keys_in_), + d_values_in(d_values_in_), + d_keys_out(d_keys_out_), + d_values_out(d_values_out_), + inequality_op(equality_op_), + num_items(num_items_) + {} + + + + //--------------------------------------------------------------------- + // Utility functions + //--------------------------------------------------------------------- + + struct KeyTagT {}; + struct ValueTagT {}; + + __device__ __forceinline__ + KeyExchangeT &GetShared(KeyTagT) + { + return temp_storage.shared_keys.Alias(); + } + __device__ __forceinline__ + ValueExchangeT &GetShared(ValueTagT) + { + return temp_storage.shared_values.Alias(); + } + + + //--------------------------------------------------------------------- + // Scatter utility methods + //--------------------------------------------------------------------- + template + __device__ __forceinline__ void Scatter( + Tag tag, + OutputIt items_out, + T (&items)[ITEMS_PER_THREAD], + OffsetT (&selection_flags)[ITEMS_PER_THREAD], + OffsetT (&selection_indices)[ITEMS_PER_THREAD], + int /*num_tile_items*/, + int num_tile_selections, + OffsetT num_selections_prefix, + OffsetT /*num_selections*/) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + int local_scatter_offset = selection_indices[ITEM] - + num_selections_prefix; + if (selection_flags[ITEM]) + { + GetShared(tag)[local_scatter_offset] = items[ITEM]; + } + } + + CTA_SYNC(); + + for (int item = threadIdx.x; + item < num_tile_selections; + item += BLOCK_THREADS) + { + items_out[num_selections_prefix + item] = GetShared(tag)[item]; + } + + CTA_SYNC(); + } + + + //--------------------------------------------------------------------- + // Cooperatively scan a device-wide sequence of tiles with other CTAs + //--------------------------------------------------------------------- + + + /** + * Process first tile of input (dynamic chained scan). Returns the running count of selections (including this tile) + */ + template + __device__ __forceinline__ OffsetT ConsumeFirstTile( + int num_tile_items, ///< Number of input items comprising this tile + OffsetT tile_offset, ///< Tile offset + ScanTileStateT& tile_state) ///< Global tile state descriptor + { + KeyT keys[ITEMS_PER_THREAD]; + OffsetT selection_flags[ITEMS_PER_THREAD]; + OffsetT selection_idx[ITEMS_PER_THREAD]; + + if (IS_LAST_TILE) + { + // Fill last elements with the first element + // because collectives are not suffix guarded + BlockLoadKeys(temp_storage.load_keys) + .Load(d_keys_in + tile_offset, + keys, + num_tile_items, + *(d_keys_in + tile_offset)); + } + else + { + BlockLoadKeys(temp_storage.load_keys).Load(d_keys_in + tile_offset, keys); + } + + + CTA_SYNC(); + + ValueT values[ITEMS_PER_THREAD]; + if (IS_LAST_TILE) + { + // Fill last elements with the first element + // because collectives are not suffix guarded + BlockLoadValues(temp_storage.load_values) + .Load(d_values_in + tile_offset, + values, + num_tile_items, + *(d_values_in + tile_offset)); + } + else + { + BlockLoadValues(temp_storage.load_values) + .Load(d_values_in + tile_offset, values); + } + + CTA_SYNC(); + + BlockDiscontinuityKeys(temp_storage.scan_storage.discontinuity) + .FlagHeads(selection_flags, keys, inequality_op); + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + // Set selection_flags for out-of-bounds items + if ((IS_LAST_TILE) && (OffsetT(threadIdx.x * ITEMS_PER_THREAD) + ITEM >= num_tile_items)) + selection_flags[ITEM] = 1; + } + + CTA_SYNC(); + + + OffsetT num_tile_selections = 0; + OffsetT num_selections = 0; + OffsetT num_selections_prefix = 0; + + BlockScanT(temp_storage.scan_storage.scan) + .ExclusiveSum(selection_flags, + selection_idx, + num_tile_selections); + + if (threadIdx.x == 0) + { + // Update tile status if this is not the last tile + if (!IS_LAST_TILE) + tile_state.SetInclusive(0, num_tile_selections); + } + + // Do not count any out-of-bounds selections + if (IS_LAST_TILE) + { + int num_discount = ITEMS_PER_TILE - num_tile_items; + num_tile_selections -= num_discount; + } + num_selections = num_tile_selections; + + CTA_SYNC(); + + Scatter(KeyTagT(), + d_keys_out, + keys, + selection_flags, + selection_idx, + num_tile_items, + num_tile_selections, + num_selections_prefix, + num_selections); + + CTA_SYNC(); + + Scatter(ValueTagT(), + d_values_out, + values, + selection_flags, + selection_idx, + num_tile_items, + num_tile_selections, + num_selections_prefix, + num_selections); + + return num_selections; + } + + /** + * Process subsequent tile of input (dynamic chained scan). Returns the running count of selections (including this tile) + */ + template + __device__ __forceinline__ OffsetT ConsumeSubsequentTile( + int num_tile_items, ///< Number of input items comprising this tile + int tile_idx, ///< Tile index + OffsetT tile_offset, ///< Tile offset + ScanTileStateT& tile_state) ///< Global tile state descriptor + { + KeyT keys[ITEMS_PER_THREAD]; + OffsetT selection_flags[ITEMS_PER_THREAD]; + OffsetT selection_idx[ITEMS_PER_THREAD]; + + if (IS_LAST_TILE) + { + // Fill last elements with the first element + // because collectives are not suffix guarded + BlockLoadKeys(temp_storage.load_keys) + .Load(d_keys_in + tile_offset, + keys, + num_tile_items, + *(d_keys_in + tile_offset)); + } + else + { + BlockLoadKeys(temp_storage.load_keys).Load(d_keys_in + tile_offset, keys); + } + + + CTA_SYNC(); + + ValueT values[ITEMS_PER_THREAD]; + if (IS_LAST_TILE) + { + // Fill last elements with the first element + // because collectives are not suffix guarded + BlockLoadValues(temp_storage.load_values) + .Load(d_values_in + tile_offset, + values, + num_tile_items, + *(d_values_in + tile_offset)); + } + else + { + BlockLoadValues(temp_storage.load_values) + .Load(d_values_in + tile_offset, values); + } + + CTA_SYNC(); + + KeyT tile_predecessor = d_keys_in[tile_offset - 1]; + BlockDiscontinuityKeys(temp_storage.scan_storage.discontinuity) + .FlagHeads(selection_flags, keys, inequality_op, tile_predecessor); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + // Set selection_flags for out-of-bounds items + if ((IS_LAST_TILE) && (OffsetT(threadIdx.x * ITEMS_PER_THREAD) + ITEM >= num_tile_items)) + selection_flags[ITEM] = 1; + } + + CTA_SYNC(); + + + OffsetT num_tile_selections = 0; + OffsetT num_selections = 0; + OffsetT num_selections_prefix = 0; + + TilePrefixCallback prefix_cb(tile_state, + temp_storage.scan_storage.prefix, + cub::Sum(), + tile_idx); + BlockScanT(temp_storage.scan_storage.scan) + .ExclusiveSum(selection_flags, + selection_idx, + prefix_cb); + + num_selections = prefix_cb.GetInclusivePrefix(); + num_tile_selections = prefix_cb.GetBlockAggregate(); + num_selections_prefix = prefix_cb.GetExclusivePrefix(); + + if (IS_LAST_TILE) + { + int num_discount = ITEMS_PER_TILE - num_tile_items; + num_tile_selections -= num_discount; + num_selections -= num_discount; + } + + CTA_SYNC(); + + Scatter(KeyTagT(), + d_keys_out, + keys, + selection_flags, + selection_idx, + num_tile_items, + num_tile_selections, + num_selections_prefix, + num_selections); + + CTA_SYNC(); + + Scatter(ValueTagT(), + d_values_out, + values, + selection_flags, + selection_idx, + num_tile_items, + num_tile_selections, + num_selections_prefix, + num_selections); + + return num_selections; + } + + + /** + * Process a tile of input + */ + template + __device__ __forceinline__ OffsetT ConsumeTile( + int num_tile_items, ///< Number of input items comprising this tile + int tile_idx, ///< Tile index + OffsetT tile_offset, ///< Tile offset + ScanTileStateT& tile_state) ///< Global tile state descriptor + { + OffsetT num_selections; + if (tile_idx == 0) + { + num_selections = ConsumeFirstTile(num_tile_items, tile_offset, tile_state); + } + else + { + num_selections = ConsumeSubsequentTile(num_tile_items, tile_idx, tile_offset, tile_state); + } + + return num_selections; + } + + /** + * Scan tiles of items as part of a dynamic chained scan + */ + template ///< Output iterator type for recording number of items selection_flags + __device__ __forceinline__ void ConsumeRange( + int num_tiles, ///< Total number of input tiles + ScanTileStateT& tile_state, ///< Global tile state descriptor + NumSelectedIteratorT d_num_selected_out) ///< Output total number selection_flags + { + // Blocks are launched in increasing order, so just assign one tile per block + int tile_idx = (blockIdx.x * gridDim.y) + blockIdx.y; // Current tile index + OffsetT tile_offset = tile_idx * ITEMS_PER_TILE; // Global offset for the current tile + + if (tile_idx < num_tiles - 1) + { + ConsumeTile(ITEMS_PER_TILE, + tile_idx, + tile_offset, + tile_state); + } + else + { + int num_remaining = static_cast(num_items - tile_offset); + OffsetT num_selections = ConsumeTile(num_remaining, + tile_idx, + tile_offset, + tile_state); + if (threadIdx.x == 0) + { + *d_num_selected_out = num_selections; + } + } + } +}; + + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/single_pass_scan_operators.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/single_pass_scan_operators.cuh new file mode 100644 index 0000000000000000000000000000000000000000..351cea2dd288f5255fcca3de069472b6be79abaa --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/agent/single_pass_scan_operators.cuh @@ -0,0 +1,1217 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Callback operator types for supplying BlockScan prefixes + */ + +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Prefix functor type for maintaining a running prefix while scanning a + * region independent of other thread blocks + ******************************************************************************/ + +/** + * Stateful callback operator type for supplying BlockScan prefixes. + * Maintains a running prefix that can be applied to consecutive + * BlockScan operations. + */ +template < + typename T, ///< BlockScan value type + typename ScanOpT> ///< Wrapped scan operator type +struct BlockScanRunningPrefixOp +{ + ScanOpT op; ///< Wrapped scan operator + T running_total; ///< Running block-wide prefix + + /// Constructor + __device__ __forceinline__ BlockScanRunningPrefixOp(ScanOpT op) + : + op(op) + {} + + /// Constructor + __device__ __forceinline__ BlockScanRunningPrefixOp( + T starting_prefix, + ScanOpT op) + : + op(op), + running_total(starting_prefix) + {} + + /** + * Prefix callback operator. Returns the block-wide running_total in thread-0. + */ + __device__ __forceinline__ T operator()( + const T &block_aggregate) ///< The aggregate sum of the BlockScan inputs + { + T retval = running_total; + running_total = op(running_total, block_aggregate); + return retval; + } +}; + + +/****************************************************************************** + * Generic tile status interface types for block-cooperative scans + ******************************************************************************/ + +/** + * Enumerations of tile status + */ +enum ScanTileStatus +{ + SCAN_TILE_OOB, // Out-of-bounds (e.g., padding) + SCAN_TILE_INVALID = 99, // Not yet processed + SCAN_TILE_PARTIAL, // Tile aggregate is available + SCAN_TILE_INCLUSIVE, // Inclusive tile prefix is available +}; + +namespace detail +{ + +template +__device__ __forceinline__ void delay() +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (if (Delay > 0) + { + if (gridDim.x < GridThreshold) + { + __threadfence_block(); + } + else + { + __nanosleep(Delay); + } + })); +} + +template +__device__ __forceinline__ void delay(int ns) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (if (ns > 0) + { + if (gridDim.x < GridThreshold) + { + __threadfence_block(); + } + else + { + __nanosleep(ns); + } + })); +} + +template +__device__ __forceinline__ void always_delay() +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, (__nanosleep(Delay);)); +} + +__device__ __forceinline__ void always_delay(int ns) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, (__nanosleep(ns);), ((void)ns;)); +} + +template +__device__ __forceinline__ void delay_or_prevent_hoisting() +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (delay();), + (__threadfence_block();)); +} + +template +__device__ __forceinline__ void delay_or_prevent_hoisting(int ns) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (delay(ns);), + ((void)ns; __threadfence_block();)); +} + +template +__device__ __forceinline__ void always_delay_or_prevent_hoisting() +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (always_delay(Delay);), + (__threadfence_block();)); +} + +__device__ __forceinline__ void always_delay_or_prevent_hoisting(int ns) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (always_delay(ns);), + ((void)ns; __threadfence_block();)); +} + +template +struct no_delay_constructor_t +{ + struct delay_t + { + __device__ __forceinline__ void operator()() + { + NV_IF_TARGET(NV_PROVIDES_SM_70, + (), + (__threadfence_block();)); + } + }; + + __device__ __forceinline__ no_delay_constructor_t(unsigned int /* seed */) + { + delay(); + } + + __device__ __forceinline__ delay_t operator()() { return {}; } +}; + +template +struct reduce_by_key_delay_constructor_t +{ + struct delay_t + { + __device__ __forceinline__ void operator()() + { + NV_DISPATCH_TARGET( + NV_IS_EXACTLY_SM_80, (delay();), + NV_PROVIDES_SM_70, (delay< 0, GridThreshold>();), + NV_IS_DEVICE, (__threadfence_block();)); + } + }; + + __device__ __forceinline__ reduce_by_key_delay_constructor_t(unsigned int /* seed */) + { + delay(); + } + + __device__ __forceinline__ delay_t operator()() { return {}; } +}; + +template +struct fixed_delay_constructor_t +{ + struct delay_t + { + __device__ __forceinline__ void operator()() { delay_or_prevent_hoisting(); } + }; + + __device__ __forceinline__ fixed_delay_constructor_t(unsigned int /* seed */) + { + delay(); + } + + __device__ __forceinline__ delay_t operator()() { return {}; } +}; + +template +struct exponential_backoff_constructor_t +{ + struct delay_t + { + int delay; + + __device__ __forceinline__ void operator()() + { + always_delay_or_prevent_hoisting(delay); + delay <<= 1; + } + }; + + __device__ __forceinline__ exponential_backoff_constructor_t(unsigned int /* seed */) + { + always_delay(); + } + + __device__ __forceinline__ delay_t operator()() { return {InitialDelay}; } +}; + +template +struct exponential_backoff_jitter_constructor_t +{ + struct delay_t + { + static constexpr unsigned int a = 16807; + static constexpr unsigned int c = 0; + static constexpr unsigned int m = 1u << 31; + + unsigned int max_delay; + unsigned int &seed; + + __device__ __forceinline__ unsigned int next(unsigned int min, unsigned int max) + { + return (seed = (a * seed + c) % m) % (max + 1 - min) + min; + } + + __device__ __forceinline__ void operator()() + { + always_delay_or_prevent_hoisting(next(0, max_delay)); + max_delay <<= 1; + } + }; + + unsigned int seed; + + __device__ __forceinline__ exponential_backoff_jitter_constructor_t(unsigned int seed) + : seed(seed) + { + always_delay(); + } + + __device__ __forceinline__ delay_t operator()() { return {InitialDelay, seed}; } +}; + +template +struct exponential_backoff_jitter_window_constructor_t +{ + struct delay_t + { + static constexpr unsigned int a = 16807; + static constexpr unsigned int c = 0; + static constexpr unsigned int m = 1u << 31; + + unsigned int max_delay; + unsigned int &seed; + + __device__ __forceinline__ unsigned int next(unsigned int min, unsigned int max) + { + return (seed = (a * seed + c) % m) % (max + 1 - min) + min; + } + + __device__ __forceinline__ void operator()() + { + unsigned int next_max_delay = max_delay << 1; + always_delay_or_prevent_hoisting(next(max_delay, next_max_delay)); + max_delay = next_max_delay; + } + }; + + unsigned int seed; + __device__ __forceinline__ exponential_backoff_jitter_window_constructor_t(unsigned int seed) + : seed(seed) + { + always_delay(); + } + + __device__ __forceinline__ delay_t operator()() { return {InitialDelay, seed}; } +}; + +template +struct exponential_backon_jitter_window_constructor_t +{ + struct delay_t + { + static constexpr unsigned int a = 16807; + static constexpr unsigned int c = 0; + static constexpr unsigned int m = 1u << 31; + + unsigned int max_delay; + unsigned int &seed; + + __device__ __forceinline__ unsigned int next(unsigned int min, unsigned int max) + { + return (seed = (a * seed + c) % m) % (max + 1 - min) + min; + } + + __device__ __forceinline__ void operator()() + { + int prev_delay = max_delay >> 1; + always_delay_or_prevent_hoisting(next(prev_delay, max_delay)); + max_delay = prev_delay; + } + }; + + unsigned int seed; + unsigned int max_delay = InitialDelay; + + __device__ __forceinline__ exponential_backon_jitter_window_constructor_t(unsigned int seed) + : seed(seed) + { + always_delay(); + } + + __device__ __forceinline__ delay_t operator()() + { + max_delay >>= 1; + return {max_delay, seed}; + } +}; + +template +struct exponential_backon_jitter_constructor_t +{ + struct delay_t + { + static constexpr unsigned int a = 16807; + static constexpr unsigned int c = 0; + static constexpr unsigned int m = 1u << 31; + + unsigned int max_delay; + unsigned int &seed; + + __device__ __forceinline__ unsigned int next(unsigned int min, unsigned int max) + { + return (seed = (a * seed + c) % m) % (max + 1 - min) + min; + } + + __device__ __forceinline__ void operator()() + { + always_delay_or_prevent_hoisting(next(0, max_delay)); + max_delay >>= 1; + } + }; + + unsigned int seed; + unsigned int max_delay = InitialDelay; + + __device__ __forceinline__ exponential_backon_jitter_constructor_t(unsigned int seed) + : seed(seed) + { + always_delay(); + } + + __device__ __forceinline__ delay_t operator()() + { + max_delay >>= 1; + return {max_delay, seed}; + } +}; + +template +struct exponential_backon_constructor_t +{ + struct delay_t + { + unsigned int delay; + + __device__ __forceinline__ void operator()() + { + always_delay_or_prevent_hoisting(delay); + delay >>= 1; + } + }; + + unsigned int max_delay = InitialDelay; + + __device__ __forceinline__ exponential_backon_constructor_t(unsigned int /* seed */) + { + always_delay(); + } + + __device__ __forceinline__ delay_t operator()() + { + max_delay >>= 1; + return {max_delay}; + } +}; + +using default_no_delay_constructor_t = no_delay_constructor_t<450>; +using default_no_delay_t = default_no_delay_constructor_t::delay_t; + +template +using default_delay_constructor_t = cub::detail::conditional_t::PRIMITIVE, + fixed_delay_constructor_t<350, 450>, + default_no_delay_constructor_t>; + +template +using default_delay_t = typename default_delay_constructor_t::delay_t; + +template +using default_reduce_by_key_delay_constructor_t = + detail::conditional_t<(Traits::PRIMITIVE) && (sizeof(ValueT) + sizeof(KeyT) < 16), + reduce_by_key_delay_constructor_t<350, 450>, + default_delay_constructor_t>>; +} + +/** + * Tile status interface. + */ +template < + typename T, + bool SINGLE_WORD = Traits::PRIMITIVE> +struct ScanTileState; + + +/** + * Tile status interface specialized for scan status and value types + * that can be combined into one machine word that can be + * read/written coherently in a single access. + */ +template +struct ScanTileState +{ + // Status word type + using StatusWord = cub::detail::conditional_t< + sizeof(T) == 8, + unsigned long long, + cub::detail::conditional_t< + sizeof(T) == 4, + unsigned int, + cub::detail::conditional_t>>; + + // Unit word type + using TxnWord = cub::detail::conditional_t< + sizeof(T) == 8, + ulonglong2, + cub::detail::conditional_t< + sizeof(T) == 4, + uint2, + unsigned int>>; + + // Device word type + struct TileDescriptor + { + StatusWord status; + T value; + }; + + + // Constants + enum + { + TILE_STATUS_PADDING = CUB_PTX_WARP_THREADS, + }; + + + // Device storage + TxnWord *d_tile_descriptors; + + /// Constructor + __host__ __device__ __forceinline__ + ScanTileState() + : + d_tile_descriptors(NULL) + {} + + + /// Initializer + __host__ __device__ __forceinline__ + cudaError_t Init( + int /*num_tiles*/, ///< [in] Number of tiles + void *d_temp_storage, ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t /*temp_storage_bytes*/) ///< [in] Size in bytes of \t d_temp_storage allocation + { + d_tile_descriptors = reinterpret_cast(d_temp_storage); + return cudaSuccess; + } + + + /** + * Compute device memory needed for tile status + */ + __host__ __device__ __forceinline__ + static cudaError_t AllocationSize( + int num_tiles, ///< [in] Number of tiles + size_t &temp_storage_bytes) ///< [out] Size in bytes of \t d_temp_storage allocation + { + temp_storage_bytes = (num_tiles + TILE_STATUS_PADDING) * sizeof(TxnWord); // bytes needed for tile status descriptors + return cudaSuccess; + } + + + /** + * Initialize (from device) + */ + __device__ __forceinline__ void InitializeStatus(int num_tiles) + { + int tile_idx = (blockIdx.x * blockDim.x) + threadIdx.x; + + TxnWord val = TxnWord(); + TileDescriptor *descriptor = reinterpret_cast(&val); + + if (tile_idx < num_tiles) + { + // Not-yet-set + descriptor->status = StatusWord(SCAN_TILE_INVALID); + d_tile_descriptors[TILE_STATUS_PADDING + tile_idx] = val; + } + + if ((blockIdx.x == 0) && (threadIdx.x < TILE_STATUS_PADDING)) + { + // Padding + descriptor->status = StatusWord(SCAN_TILE_OOB); + d_tile_descriptors[threadIdx.x] = val; + } + } + + + /** + * Update the specified tile's inclusive value and corresponding status + */ + __device__ __forceinline__ void SetInclusive(int tile_idx, T tile_inclusive) + { + TileDescriptor tile_descriptor; + tile_descriptor.status = SCAN_TILE_INCLUSIVE; + tile_descriptor.value = tile_inclusive; + + TxnWord alias; + *reinterpret_cast(&alias) = tile_descriptor; + + detail::store_relaxed(d_tile_descriptors + TILE_STATUS_PADDING + tile_idx, alias); + } + + + /** + * Update the specified tile's partial value and corresponding status + */ + __device__ __forceinline__ void SetPartial(int tile_idx, T tile_partial) + { + TileDescriptor tile_descriptor; + tile_descriptor.status = SCAN_TILE_PARTIAL; + tile_descriptor.value = tile_partial; + + TxnWord alias; + *reinterpret_cast(&alias) = tile_descriptor; + + detail::store_relaxed(d_tile_descriptors + TILE_STATUS_PADDING + tile_idx, alias); + } + + /** + * Wait for the corresponding tile to become non-invalid + */ + template > + __device__ __forceinline__ void WaitForValid( + int tile_idx, + StatusWord &status, + T &value, + DelayT delay_or_prevent_hoisting = {}) + { + TileDescriptor tile_descriptor; + + { + TxnWord alias = detail::load_relaxed(d_tile_descriptors + TILE_STATUS_PADDING + tile_idx); + tile_descriptor = reinterpret_cast(alias); + } + + while (WARP_ANY((tile_descriptor.status == SCAN_TILE_INVALID), 0xffffffff)) + { + delay_or_prevent_hoisting(); + TxnWord alias = detail::load_relaxed(d_tile_descriptors + TILE_STATUS_PADDING + tile_idx); + tile_descriptor = reinterpret_cast(alias); + } + + status = tile_descriptor.status; + value = tile_descriptor.value; + } + + /** + * Loads and returns the tile's value. The returned value is undefined if either (a) the tile's status is invalid or + * (b) there is no memory fence between reading a non-invalid status and the call to LoadValid. + */ + __device__ __forceinline__ T LoadValid(int tile_idx) + { + TxnWord alias = d_tile_descriptors[TILE_STATUS_PADDING + tile_idx]; + TileDescriptor tile_descriptor = reinterpret_cast(alias); + return tile_descriptor.value; + } +}; + + + +/** + * Tile status interface specialized for scan status and value types that + * cannot be combined into one machine word. + */ +template +struct ScanTileState +{ + // Status word type + using StatusWord = unsigned int; + + // Constants + enum + { + TILE_STATUS_PADDING = CUB_PTX_WARP_THREADS, + }; + + // Device storage + StatusWord *d_tile_status; + T *d_tile_partial; + T *d_tile_inclusive; + + /// Constructor + __host__ __device__ __forceinline__ + ScanTileState() + : + d_tile_status(NULL), + d_tile_partial(NULL), + d_tile_inclusive(NULL) + {} + + + /// Initializer + __host__ __device__ __forceinline__ + cudaError_t Init( + int num_tiles, ///< [in] Number of tiles + void *d_temp_storage, ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t temp_storage_bytes) ///< [in] Size in bytes of \t d_temp_storage allocation + { + cudaError_t error = cudaSuccess; + do + { + void* allocations[3] = {}; + size_t allocation_sizes[3]; + + allocation_sizes[0] = (num_tiles + TILE_STATUS_PADDING) * sizeof(StatusWord); // bytes needed for tile status descriptors + allocation_sizes[1] = (num_tiles + TILE_STATUS_PADDING) * sizeof(Uninitialized); // bytes needed for partials + allocation_sizes[2] = (num_tiles + TILE_STATUS_PADDING) * sizeof(Uninitialized); // bytes needed for inclusives + + // Compute allocation pointers into the single storage blob + if (CubDebug(error = AliasTemporaries(d_temp_storage, temp_storage_bytes, allocations, allocation_sizes))) break; + + // Alias the offsets + d_tile_status = reinterpret_cast(allocations[0]); + d_tile_partial = reinterpret_cast(allocations[1]); + d_tile_inclusive = reinterpret_cast(allocations[2]); + } + while (0); + + return error; + } + + + /** + * Compute device memory needed for tile status + */ + __host__ __device__ __forceinline__ + static cudaError_t AllocationSize( + int num_tiles, ///< [in] Number of tiles + size_t &temp_storage_bytes) ///< [out] Size in bytes of \t d_temp_storage allocation + { + // Specify storage allocation requirements + size_t allocation_sizes[3]; + allocation_sizes[0] = (num_tiles + TILE_STATUS_PADDING) * sizeof(StatusWord); // bytes needed for tile status descriptors + allocation_sizes[1] = (num_tiles + TILE_STATUS_PADDING) * sizeof(Uninitialized); // bytes needed for partials + allocation_sizes[2] = (num_tiles + TILE_STATUS_PADDING) * sizeof(Uninitialized); // bytes needed for inclusives + + // Set the necessary size of the blob + void* allocations[3] = {}; + return CubDebug(AliasTemporaries(NULL, temp_storage_bytes, allocations, allocation_sizes)); + } + + + /** + * Initialize (from device) + */ + __device__ __forceinline__ void InitializeStatus(int num_tiles) + { + int tile_idx = (blockIdx.x * blockDim.x) + threadIdx.x; + if (tile_idx < num_tiles) + { + // Not-yet-set + d_tile_status[TILE_STATUS_PADDING + tile_idx] = StatusWord(SCAN_TILE_INVALID); + } + + if ((blockIdx.x == 0) && (threadIdx.x < TILE_STATUS_PADDING)) + { + // Padding + d_tile_status[threadIdx.x] = StatusWord(SCAN_TILE_OOB); + } + } + + + /** + * Update the specified tile's inclusive value and corresponding status + */ + __device__ __forceinline__ void SetInclusive(int tile_idx, T tile_inclusive) + { + // Update tile inclusive value + ThreadStore(d_tile_inclusive + TILE_STATUS_PADDING + tile_idx, tile_inclusive); + detail::store_release(d_tile_status + TILE_STATUS_PADDING + tile_idx, StatusWord(SCAN_TILE_INCLUSIVE)); + } + + + /** + * Update the specified tile's partial value and corresponding status + */ + __device__ __forceinline__ void SetPartial(int tile_idx, T tile_partial) + { + // Update tile partial value + ThreadStore(d_tile_partial + TILE_STATUS_PADDING + tile_idx, tile_partial); + detail::store_release(d_tile_status + TILE_STATUS_PADDING + tile_idx, StatusWord(SCAN_TILE_PARTIAL)); + } + + /** + * Wait for the corresponding tile to become non-invalid + */ + template + __device__ __forceinline__ void WaitForValid( + int tile_idx, + StatusWord &status, + T &value, + DelayT delay = {}) + { + do + { + delay(); + status = detail::load_relaxed(d_tile_status + TILE_STATUS_PADDING + tile_idx); + __threadfence(); + } while (WARP_ANY((status == SCAN_TILE_INVALID), 0xffffffff)); + + if (status == StatusWord(SCAN_TILE_PARTIAL)) + { + value = ThreadLoad(d_tile_partial + TILE_STATUS_PADDING + tile_idx); + } + else + { + value = ThreadLoad(d_tile_inclusive + TILE_STATUS_PADDING + tile_idx); + } + } + + /** + * Loads and returns the tile's value. The returned value is undefined if either (a) the tile's status is invalid or + * (b) there is no memory fence between reading a non-invalid status and the call to LoadValid. + */ + __device__ __forceinline__ T LoadValid(int tile_idx) + { + return d_tile_inclusive[TILE_STATUS_PADDING + tile_idx]; + } +}; + + +/****************************************************************************** + * ReduceByKey tile status interface types for block-cooperative scans + ******************************************************************************/ + +/** + * Tile status interface for reduction by key. + * + */ +template < + typename ValueT, + typename KeyT, + bool SINGLE_WORD = (Traits::PRIMITIVE) && (sizeof(ValueT) + sizeof(KeyT) < 16)> +struct ReduceByKeyScanTileState; + + +/** + * Tile status interface for reduction by key, specialized for scan status and value types that + * cannot be combined into one machine word. + */ +template < + typename ValueT, + typename KeyT> +struct ReduceByKeyScanTileState : + ScanTileState > +{ + typedef ScanTileState > SuperClass; + + /// Constructor + __host__ __device__ __forceinline__ + ReduceByKeyScanTileState() : SuperClass() {} +}; + + +/** + * Tile status interface for reduction by key, specialized for scan status and value types that + * can be combined into one machine word that can be read/written coherently in a single access. + */ +template < + typename ValueT, + typename KeyT> +struct ReduceByKeyScanTileState +{ + using KeyValuePairT = KeyValuePair; + + // Constants + enum + { + PAIR_SIZE = static_cast(sizeof(ValueT) + sizeof(KeyT)), + TXN_WORD_SIZE = 1 << Log2::VALUE, + STATUS_WORD_SIZE = TXN_WORD_SIZE - PAIR_SIZE, + + TILE_STATUS_PADDING = CUB_PTX_WARP_THREADS, + }; + + // Status word type + using StatusWord = cub::detail::conditional_t< + STATUS_WORD_SIZE == 8, + unsigned long long, + cub::detail::conditional_t< + STATUS_WORD_SIZE == 4, + unsigned int, + cub::detail::conditional_t>>; + + // Status word type + using TxnWord = cub::detail::conditional_t< + TXN_WORD_SIZE == 16, + ulonglong2, + cub::detail::conditional_t>; + + // Device word type (for when sizeof(ValueT) == sizeof(KeyT)) + struct TileDescriptorBigStatus + { + KeyT key; + ValueT value; + StatusWord status; + }; + + // Device word type (for when sizeof(ValueT) != sizeof(KeyT)) + struct TileDescriptorLittleStatus + { + ValueT value; + StatusWord status; + KeyT key; + }; + + // Device word type + using TileDescriptor = + cub::detail::conditional_t; + + // Device storage + TxnWord *d_tile_descriptors; + + + /// Constructor + __host__ __device__ __forceinline__ + ReduceByKeyScanTileState() + : + d_tile_descriptors(NULL) + {} + + + /// Initializer + __host__ __device__ __forceinline__ + cudaError_t Init( + int /*num_tiles*/, ///< [in] Number of tiles + void *d_temp_storage, ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t /*temp_storage_bytes*/) ///< [in] Size in bytes of \t d_temp_storage allocation + { + d_tile_descriptors = reinterpret_cast(d_temp_storage); + return cudaSuccess; + } + + + /** + * Compute device memory needed for tile status + */ + __host__ __device__ __forceinline__ + static cudaError_t AllocationSize( + int num_tiles, ///< [in] Number of tiles + size_t &temp_storage_bytes) ///< [out] Size in bytes of \t d_temp_storage allocation + { + temp_storage_bytes = (num_tiles + TILE_STATUS_PADDING) * sizeof(TxnWord); // bytes needed for tile status descriptors + return cudaSuccess; + } + + + /** + * Initialize (from device) + */ + __device__ __forceinline__ void InitializeStatus(int num_tiles) + { + int tile_idx = (blockIdx.x * blockDim.x) + threadIdx.x; + TxnWord val = TxnWord(); + TileDescriptor *descriptor = reinterpret_cast(&val); + + if (tile_idx < num_tiles) + { + // Not-yet-set + descriptor->status = StatusWord(SCAN_TILE_INVALID); + d_tile_descriptors[TILE_STATUS_PADDING + tile_idx] = val; + } + + if ((blockIdx.x == 0) && (threadIdx.x < TILE_STATUS_PADDING)) + { + // Padding + descriptor->status = StatusWord(SCAN_TILE_OOB); + d_tile_descriptors[threadIdx.x] = val; + } + } + + + /** + * Update the specified tile's inclusive value and corresponding status + */ + __device__ __forceinline__ void SetInclusive(int tile_idx, KeyValuePairT tile_inclusive) + { + TileDescriptor tile_descriptor; + tile_descriptor.status = SCAN_TILE_INCLUSIVE; + tile_descriptor.value = tile_inclusive.value; + tile_descriptor.key = tile_inclusive.key; + + TxnWord alias; + *reinterpret_cast(&alias) = tile_descriptor; + + detail::store_relaxed(d_tile_descriptors + TILE_STATUS_PADDING + tile_idx, alias); + } + + + /** + * Update the specified tile's partial value and corresponding status + */ + __device__ __forceinline__ void SetPartial(int tile_idx, KeyValuePairT tile_partial) + { + TileDescriptor tile_descriptor; + tile_descriptor.status = SCAN_TILE_PARTIAL; + tile_descriptor.value = tile_partial.value; + tile_descriptor.key = tile_partial.key; + + TxnWord alias; + *reinterpret_cast(&alias) = tile_descriptor; + + detail::store_relaxed(d_tile_descriptors + TILE_STATUS_PADDING + tile_idx, alias); + } + + /** + * Wait for the corresponding tile to become non-invalid + */ + template ::delay_t> + __device__ __forceinline__ void WaitForValid( + int tile_idx, + StatusWord &status, + KeyValuePairT &value, + DelayT delay_or_prevent_hoisting = {}) + { +// TxnWord alias = ThreadLoad(d_tile_descriptors + TILE_STATUS_PADDING + tile_idx); +// TileDescriptor tile_descriptor = reinterpret_cast(alias); +// +// while (tile_descriptor.status == SCAN_TILE_INVALID) +// { +// __threadfence_block(); // prevent hoisting loads from loop +// +// alias = ThreadLoad(d_tile_descriptors + TILE_STATUS_PADDING + tile_idx); +// tile_descriptor = reinterpret_cast(alias); +// } +// +// status = tile_descriptor.status; +// value.value = tile_descriptor.value; +// value.key = tile_descriptor.key; + + TileDescriptor tile_descriptor; + + do + { + delay_or_prevent_hoisting(); + TxnWord alias = detail::load_relaxed(d_tile_descriptors + TILE_STATUS_PADDING + tile_idx); + tile_descriptor = reinterpret_cast(alias); + + } while (WARP_ANY((tile_descriptor.status == SCAN_TILE_INVALID), 0xffffffff)); + + status = tile_descriptor.status; + value.value = tile_descriptor.value; + value.key = tile_descriptor.key; + } + +}; + + +/****************************************************************************** + * Prefix call-back operator for coupling local block scan within a + * block-cooperative scan + ******************************************************************************/ + +/** + * Stateful block-scan prefix functor. Provides the the running prefix for + * the current tile by using the call-back warp to wait on on + * aggregates/prefixes from predecessor tiles to become available. + * + * @tparam DelayConstructorT + * Implementation detail, do not specify directly, requirements on the + * content of this type are subject to breaking change. + */ +template < + typename T, + typename ScanOpT, + typename ScanTileStateT, + int LEGACY_PTX_ARCH = 0, + typename DelayConstructorT = detail::default_delay_constructor_t> +struct TilePrefixCallbackOp +{ + // Parameterized warp reduce + typedef WarpReduce WarpReduceT; + + // Temporary storage type + struct _TempStorage + { + typename WarpReduceT::TempStorage warp_reduce; + T exclusive_prefix; + T inclusive_prefix; + T block_aggregate; + }; + + // Alias wrapper allowing temporary storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + // Type of status word + typedef typename ScanTileStateT::StatusWord StatusWord; + + // Fields + _TempStorage& temp_storage; ///< Reference to a warp-reduction instance + ScanTileStateT& tile_status; ///< Interface to tile status + ScanOpT scan_op; ///< Binary scan operator + int tile_idx; ///< The current tile index + T exclusive_prefix; ///< Exclusive prefix for the tile + T inclusive_prefix; ///< Inclusive prefix for the tile + + // Constructs prefix functor for a given tile index. + // Precondition: thread blocks processing all of the predecessor tiles were scheduled. + __device__ __forceinline__ TilePrefixCallbackOp(ScanTileStateT &tile_status, + TempStorage &temp_storage, + ScanOpT scan_op, + int tile_idx) + : temp_storage(temp_storage.Alias()) + , tile_status(tile_status) + , scan_op(scan_op) + , tile_idx(tile_idx) + {} + + // Computes the tile index and constructs prefix functor with it. + // Precondition: thread block per tile assignment. + __device__ __forceinline__ TilePrefixCallbackOp(ScanTileStateT &tile_status, + TempStorage &temp_storage, + ScanOpT scan_op) + : TilePrefixCallbackOp(tile_status, temp_storage, scan_op, blockIdx.x) + {} + + // Block until all predecessors within the warp-wide window have non-invalid status + template > + __device__ __forceinline__ + void ProcessWindow( + int predecessor_idx, ///< Preceding tile index to inspect + StatusWord &predecessor_status, ///< [out] Preceding tile status + T &window_aggregate, ///< [out] Relevant partial reduction from this window of preceding tiles + DelayT delay = {}) + { + T value; + tile_status.WaitForValid(predecessor_idx, predecessor_status, value, delay); + + // Perform a segmented reduction to get the prefix for the current window. + // Use the swizzled scan operator because we are now scanning *down* towards thread0. + + int tail_flag = (predecessor_status == StatusWord(SCAN_TILE_INCLUSIVE)); + window_aggregate = WarpReduceT(temp_storage.warp_reduce).TailSegmentedReduce( + value, + tail_flag, + SwizzleScanOp(scan_op)); + } + + + // BlockScan prefix callback functor (called by the first warp) + __device__ __forceinline__ + T operator()(T block_aggregate) + { + // Update our status with our tile-aggregate + if (threadIdx.x == 0) + { + detail::uninitialized_copy(&temp_storage.block_aggregate, + block_aggregate); + + tile_status.SetPartial(tile_idx, block_aggregate); + } + + int predecessor_idx = tile_idx - threadIdx.x - 1; + StatusWord predecessor_status; + T window_aggregate; + + // Wait for the warp-wide window of predecessor tiles to become valid + DelayConstructorT construct_delay(tile_idx); + ProcessWindow(predecessor_idx, predecessor_status, window_aggregate, construct_delay()); + + // The exclusive tile prefix starts out as the current window aggregate + exclusive_prefix = window_aggregate; + + // Keep sliding the window back until we come across a tile whose inclusive prefix is known + while (WARP_ALL((predecessor_status != StatusWord(SCAN_TILE_INCLUSIVE)), 0xffffffff)) + { + predecessor_idx -= CUB_PTX_WARP_THREADS; + + // Update exclusive tile prefix with the window prefix + ProcessWindow(predecessor_idx, predecessor_status, window_aggregate, construct_delay()); + exclusive_prefix = scan_op(window_aggregate, exclusive_prefix); + } + + // Compute the inclusive tile prefix and update the status for this tile + if (threadIdx.x == 0) + { + inclusive_prefix = scan_op(exclusive_prefix, block_aggregate); + tile_status.SetInclusive(tile_idx, inclusive_prefix); + + detail::uninitialized_copy(&temp_storage.exclusive_prefix, + exclusive_prefix); + + detail::uninitialized_copy(&temp_storage.inclusive_prefix, + inclusive_prefix); + } + + // Return exclusive_prefix + return exclusive_prefix; + } + + // Get the exclusive prefix stored in temporary storage + __device__ __forceinline__ + T GetExclusivePrefix() + { + return temp_storage.exclusive_prefix; + } + + // Get the inclusive prefix stored in temporary storage + __device__ __forceinline__ + T GetInclusivePrefix() + { + return temp_storage.inclusive_prefix; + } + + // Get the block aggregate stored in temporary storage + __device__ __forceinline__ + T GetBlockAggregate() + { + return temp_storage.block_aggregate; + } + + __device__ __forceinline__ + int GetTileIdx() const + { + return tile_idx; + } +}; + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_adjacent_difference.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_adjacent_difference.cuh new file mode 100644 index 0000000000000000000000000000000000000000..524ffbebfaab56cd7bb87a0abd7d667b9563ffa3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_adjacent_difference.cuh @@ -0,0 +1,1453 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file + * The cub::BlockAdjacentDifference class provides + * [collective](index.html#sec0) methods for computing the differences + * of adjacent elements partitioned across a CUDA thread block. + */ + +#pragma once + +#include "../config.cuh" +#include "../util_type.cuh" +#include "../util_ptx.cuh" + +CUB_NAMESPACE_BEGIN + +/** + * @brief BlockAdjacentDifference provides + * [collective](index.html#sec0) methods for computing the + * differences of adjacent elements partitioned across a CUDA thread + * block. + * + * @ingroup BlockModule + * + * @par Overview + * - BlockAdjacentDifference calculates the differences of adjacent elements in + * the elements partitioned across a CUDA thread block. Because the binary + * operation could be noncommutative, there are two sets of methods. + * Methods named SubtractLeft subtract left element `i - 1` of input sequence + * from current element `i`. Methods named SubtractRight subtract current + * element `i` from the right one `i + 1`: + * @par + * @code + * int values[4]; // [1, 2, 3, 4] + * //... + * int subtract_left_result[4]; <-- [ 1, 1, 1, 1 ] + * int subtract_right_result[4]; <-- [ -1, -1, -1, 4 ] + * @endcode + * - For SubtractLeft, if the left element is out of bounds, the + * output value is assigned to `input[0]` without modification. + * - For SubtractRight, if the right element is out of bounds, the output value + * is assigned to the current input value without modification. + * - The following example under the examples/block folder illustrates usage of + * dynamically shared memory with BlockReduce and how to re-purpose + * the same memory region: + * example_block_reduce_dyn_smem.cu + * This example can be easily adapted to the storage required by + * BlockAdjacentDifference. + * + * @par Snippet + * The code snippet below illustrates how to use @p BlockAdjacentDifference to + * compute the left difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * struct CustomDifference + * { + * template + * __device__ DataType operator()(DataType &lhs, DataType &rhs) + * { + * return lhs - rhs; + * } + * }; + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockAdjacentDifference for a 1D block of + * // 128 threads of type int + * using BlockAdjacentDifferenceT = + * cub::BlockAdjacentDifference; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockAdjacentDifferenceT::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute adjacent_difference + * int result[4]; + * + * BlockAdjacentDifferenceT(temp_storage).SubtractLeft( + * result, + * thread_data, + * CustomDifference()); + * + * @endcode + * @par + * Suppose the set of input `thread_data` across the block of threads is + * { [4,2,1,1], [1,1,1,1], [2,3,3,3], [3,4,1,4], ... }. + * The corresponding output `result` in those threads will be + * { [4,-2,-1,0], [0,0,0,0], [1,1,0,0], [0,1,-3,3], ... }. + * + */ +template +class BlockAdjacentDifference +{ +private: + + /*************************************************************************** + * Constants and type definitions + **************************************************************************/ + + /// Constants + + /// The thread block size in threads + static constexpr int BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z; + + /// Shared memory storage layout type (last element from each thread's input) + struct _TempStorage + { + T first_items[BLOCK_THREADS]; + T last_items[BLOCK_THREADS]; + }; + + + /*************************************************************************** + * Utility methods + **************************************************************************/ + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + + /// Specialization for when FlagOp has third index param + template ::HAS_PARAM> + struct ApplyOp + { + // Apply flag operator + static __device__ __forceinline__ T FlagT(FlagOp flag_op, + const T &a, + const T &b, + int idx) + { + return flag_op(b, a, idx); + } + }; + + /// Specialization for when FlagOp does not have a third index param + template + struct ApplyOp + { + // Apply flag operator + static __device__ __forceinline__ T FlagT(FlagOp flag_op, + const T &a, + const T &b, + int /*idx*/) + { + return flag_op(b, a); + } + }; + + /// Templated unrolling of item comparison (inductive case) + struct Iterate + { + /** + * Head flags + * + * @param[out] flags Calling thread's discontinuity head_flags + * @param[in] input Calling thread's input items + * @param[out] preds Calling thread's predecessor items + * @param[in] flag_op Binary boolean flag predicate + */ + template + static __device__ __forceinline__ void + FlagHeads(int linear_tid, + FlagT (&flags)[ITEMS_PER_THREAD], + T (&input)[ITEMS_PER_THREAD], + T (&preds)[ITEMS_PER_THREAD], + FlagOp flag_op) + { + #pragma unroll + for (int i = 1; i < ITEMS_PER_THREAD; ++i) { + preds[i] = input[i - 1]; + flags[i] = ApplyOp::FlagT( + flag_op, + preds[i], + input[i], + (linear_tid * ITEMS_PER_THREAD) + i); + } + } + + /** + * Tail flags + * + * @param[out] flags Calling thread's discontinuity head_flags + * @param[in] input Calling thread's input items + * @param[in] flag_op Binary boolean flag predicate + */ + template + static __device__ __forceinline__ void + FlagTails(int linear_tid, + FlagT (&flags)[ITEMS_PER_THREAD], + T (&input)[ITEMS_PER_THREAD], + FlagOp flag_op) + { + #pragma unroll + for (int i = 0; i < ITEMS_PER_THREAD - 1; ++i) { + flags[i] = ApplyOp::FlagT( + flag_op, + input[i], + input[i + 1], + (linear_tid * ITEMS_PER_THREAD) + i + 1); + } + } + }; + + /*************************************************************************** + * Thread fields + **************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Linear thread-id + unsigned int linear_tid; + + +public: + + /// \smemstorage{BlockDiscontinuity} + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /***********************************************************************//** + * @name Collective constructors + **************************************************************************/ + //@{ + + /** + * @brief Collective constructor using a private static allocation of shared + * memory as temporary storage. + */ + __device__ __forceinline__ BlockAdjacentDifference() + : temp_storage(PrivateStorage()) + , linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + /** + * @brief Collective constructor using the specified memory allocation as + * temporary storage. + * + * @param[in] temp_storage Reference to memory allocation having layout type TempStorage + */ + __device__ __forceinline__ BlockAdjacentDifference(TempStorage &temp_storage) + : temp_storage(temp_storage.Alias()) + , linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + //@} end member group + /***********************************************************************//** + * @name Read left operations + **************************************************************************/ + //@{ + + /** + * @brief Subtracts the left element of each adjacent pair of elements + * partitioned across a CUDA thread block. + * + * @par + * - \rowmajor + * - \smemreuse + * + * @par Snippet + * The code snippet below illustrates how to use @p BlockAdjacentDifference + * to compute the left difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * struct CustomDifference + * { + * template + * __device__ DataType operator()(DataType &lhs, DataType &rhs) + * { + * return lhs - rhs; + * } + * }; + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockAdjacentDifference for a 1D block + * // of 128 threads of type int + * using BlockAdjacentDifferenceT = + * cub::BlockAdjacentDifference; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockAdjacentDifferenceT::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute adjacent_difference + * BlockAdjacentDifferenceT(temp_storage).SubtractLeft( + * thread_data, + * thread_data, + * CustomDifference()); + * + * @endcode + * @par + * Suppose the set of input `thread_data` across the block of threads is + * `{ [4,2,1,1], [1,1,1,1], [2,3,3,3], [3,4,1,4], ... }`. + * The corresponding output `result` in those threads will be + * `{ [4,-2,-1,0], [0,0,0,0], [1,1,0,0], [0,1,-3,3], ... }`. + * + * @param[out] output + * Calling thread's adjacent difference result + * + * @param[in] input + * Calling thread's input items (may be aliased to @p output) + * + * @param[in] difference_op + * Binary difference operator + */ + template + __device__ __forceinline__ void + SubtractLeft(T (&input)[ITEMS_PER_THREAD], + OutputType (&output)[ITEMS_PER_THREAD], + DifferenceOpT difference_op) + { + // Share last item + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + #pragma unroll + for (int item = ITEMS_PER_THREAD - 1; item > 0; item--) + { + output[item] = difference_op(input[item], input[item - 1]); + } + + if (linear_tid == 0) + { + output[0] = input[0]; + } + else + { + output[0] = difference_op(input[0], + temp_storage.last_items[linear_tid - 1]); + } + } + + /** + * @brief Subtracts the left element of each adjacent pair of elements + * partitioned across a CUDA thread block. + * + * @par + * - \rowmajor + * - \smemreuse + * + * @par Snippet + * The code snippet below illustrates how to use @p BlockAdjacentDifference + * to compute the left difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * struct CustomDifference + * { + * template + * __device__ DataType operator()(DataType &lhs, DataType &rhs) + * { + * return lhs - rhs; + * } + * }; + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockAdjacentDifference for a 1D block of + * // 128 threads of type int + * using BlockAdjacentDifferenceT = + * cub::BlockAdjacentDifference; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockAdjacentDifferenceT::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // The last item in the previous tile: + * int tile_predecessor_item = ...; + * + * // Collectively compute adjacent_difference + * BlockAdjacentDifferenceT(temp_storage).SubtractLeft( + * thread_data, + * thread_data, + * CustomDifference(), + * tile_predecessor_item); + * + * @endcode + * @par + * Suppose the set of input `thread_data` across the block of threads is + * `{ [4,2,1,1], [1,1,1,1], [2,3,3,3], [3,4,1,4], ... }`. + * and that `tile_predecessor_item` is `3`. The corresponding output + * `result` in those threads will be + * `{ [1,-2,-1,0], [0,0,0,0], [1,1,0,0], [0,1,-3,3], ... }`. + * + * @param[out] output + * Calling thread's adjacent difference result + * + * @param[in] input + * Calling thread's input items (may be aliased to \p output) + * + * @param[in] difference_op + * Binary difference operator + * + * @param[in] tile_predecessor_item + * [thread0 only] item which is going to be + * subtracted from the first tile item (input0 from + * thread0). + */ + template + __device__ __forceinline__ void + SubtractLeft(T (&input)[ITEMS_PER_THREAD], + OutputT (&output)[ITEMS_PER_THREAD], + DifferenceOpT difference_op, + T tile_predecessor_item) + { + // Share last item + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + #pragma unroll + for (int item = ITEMS_PER_THREAD - 1; item > 0; item--) + { + output[item] = difference_op(input[item], input[item - 1]); + } + + // Set flag for first thread-item + if (linear_tid == 0) + { + output[0] = difference_op(input[0], tile_predecessor_item); + } + else + { + output[0] = difference_op(input[0], + temp_storage.last_items[linear_tid - 1]); + } + } + + /** + * @brief Subtracts the left element of each adjacent pair of elements + * partitioned across a CUDA thread block. + * + * @par + * - \rowmajor + * - \smemreuse + * + * @par Snippet + * The code snippet below illustrates how to use @p BlockAdjacentDifference + * to compute the left difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * struct CustomDifference + * { + * template + * __device__ DataType operator()(DataType &lhs, DataType &rhs) + * { + * return lhs - rhs; + * } + * }; + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockAdjacentDifference for a 1D block of + * // 128 threads of type int + * using BlockAdjacentDifferenceT = + * cub::BlockAdjacentDifference; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockAdjacentDifferenceT::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * int valid_items = 9; + * + * // Collectively compute adjacent_difference + * BlockAdjacentDifferenceT(temp_storage).SubtractLeftPartialTile( + * thread_data, + * thread_data, + * CustomDifference(), + * valid_items); + * + * @endcode + * @par + * Suppose the set of input `thread_data` across the block of threads is + * `{ [4,2,1,1], [1,1,1,1], [2,3,3,3], [3,4,1,4], ... }`. + * The corresponding output `result` in those threads will be + * `{ [4,-2,-1,0], [0,0,0,0], [1,3,3,3], [3,4,1,4], ... }`. + * + * @param[out] output + * Calling thread's adjacent difference result + * + * @param[in] input + * Calling thread's input items (may be aliased to \p output) + * + * @param[in] difference_op + * Binary difference operator + * + * @param[in] valid_items + * Number of valid items in thread block + */ + template + __device__ __forceinline__ void + SubtractLeftPartialTile(T (&input)[ITEMS_PER_THREAD], + OutputType (&output)[ITEMS_PER_THREAD], + DifferenceOpT difference_op, + int valid_items) + { + // Share last item + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + if ((linear_tid + 1) * ITEMS_PER_THREAD <= valid_items) + { + #pragma unroll + for (int item = ITEMS_PER_THREAD - 1; item > 0; item--) + { + output[item] = difference_op(input[item], input[item - 1]); + } + } + else + { + #pragma unroll + for (int item = ITEMS_PER_THREAD - 1; item > 0; item--) + { + const int idx = linear_tid * ITEMS_PER_THREAD + item; + + if (idx < valid_items) + { + output[item] = difference_op(input[item], input[item - 1]); + } + else + { + output[item] = input[item]; + } + } + } + + if (linear_tid == 0 || valid_items <= linear_tid * ITEMS_PER_THREAD) + { + output[0] = input[0]; + } + else + { + output[0] = difference_op(input[0], + temp_storage.last_items[linear_tid - 1]); + } + } + + /** + * @brief Subtracts the left element of each adjacent pair of elements + * partitioned across a CUDA thread block. + * + * @par + * - \rowmajor + * - \smemreuse + * + * @par Snippet + * The code snippet below illustrates how to use @p BlockAdjacentDifference + * to compute the left difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * struct CustomDifference + * { + * template + * __device__ DataType operator()(DataType &lhs, DataType &rhs) + * { + * return lhs - rhs; + * } + * }; + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockAdjacentDifference for a 1D block of + * // 128 threads of type int + * using BlockAdjacentDifferenceT = + * cub::BlockAdjacentDifference; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockAdjacentDifferenceT::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * int valid_items = 9; + * int tile_predecessor_item = 4; + * + * // Collectively compute adjacent_difference + * BlockAdjacentDifferenceT(temp_storage).SubtractLeftPartialTile( + * thread_data, + * thread_data, + * CustomDifference(), + * valid_items, + * tile_predecessor_item); + * + * @endcode + * @par + * Suppose the set of input `thread_data` across the block of threads is + * `{ [4,2,1,1], [1,1,1,1], [2,3,3,3], [3,4,1,4], ... }`. + * The corresponding output `result` in those threads will be + * `{ [0,-2,-1,0], [0,0,0,0], [1,3,3,3], [3,4,1,4], ... }`. + * + * @param[out] output + * Calling thread's adjacent difference result + * + * @param[in] input + * Calling thread's input items (may be aliased to \p output) + * + * @param[in] difference_op + * Binary difference operator + * + * @param[in] valid_items + * Number of valid items in thread block + * + * @param[in] tile_predecessor_item + * **[thread0 only]** item which is going to be + * subtracted from the first tile item (input0 from + * thread0). + */ + template + __device__ __forceinline__ void + SubtractLeftPartialTile(T (&input)[ITEMS_PER_THREAD], + OutputType (&output)[ITEMS_PER_THREAD], + DifferenceOpT difference_op, + int valid_items, + T tile_predecessor_item) + { + // Share last item + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + if ((linear_tid + 1) * ITEMS_PER_THREAD <= valid_items) + { + #pragma unroll + for (int item = ITEMS_PER_THREAD - 1; item > 0; item--) + { + output[item] = difference_op(input[item], input[item - 1]); + } + } + else + { + #pragma unroll + for (int item = ITEMS_PER_THREAD - 1; item > 0; item--) + { + const int idx = linear_tid * ITEMS_PER_THREAD + item; + + if (idx < valid_items) + { + output[item] = difference_op(input[item], input[item - 1]); + } + else + { + output[item] = input[item]; + } + } + } + + if (valid_items <= linear_tid * ITEMS_PER_THREAD) + { + output[0] = input[0]; + } + else if (linear_tid == 0) + { + output[0] = difference_op(input[0], + tile_predecessor_item); + } + else + { + output[0] = difference_op(input[0], + temp_storage.last_items[linear_tid - 1]); + } + } + + //@} end member group + /******************************************************************//** + * @name Read right operations + *********************************************************************/ + //@{ + + /** + * @brief Subtracts the right element of each adjacent pair of elements + * partitioned across a CUDA thread block. + * + * @par + * - \rowmajor + * - \smemreuse + * + * @par Snippet + * The code snippet below illustrates how to use @p BlockAdjacentDifference + * to compute the right difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * struct CustomDifference + * { + * template + * __device__ DataType operator()(DataType &lhs, DataType &rhs) + * { + * return lhs - rhs; + * } + * }; + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockAdjacentDifference for a 1D block of + * // 128 threads of type int + * using BlockAdjacentDifferenceT = + * cub::BlockAdjacentDifference; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockAdjacentDifferenceT::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute adjacent_difference + * BlockAdjacentDifferenceT(temp_storage).SubtractRight( + * thread_data, + * thread_data, + * CustomDifference()); + * + * @endcode + * @par + * Suppose the set of input `thread_data` across the block of threads is + * `{ ...3], [4,2,1,1], [1,1,1,1], [2,3,3,3], [3,4,1,4] }`. + * The corresponding output `result` in those threads will be + * `{ ..., [-1,2,1,0], [0,0,0,-1], [-1,0,0,0], [-1,3,-3,4] }`. + * + * @param[out] output + * Calling thread's adjacent difference result + * + * @param[in] input + * Calling thread's input items (may be aliased to \p output) + * + * @param[in] difference_op + * Binary difference operator + */ + template + __device__ __forceinline__ void + SubtractRight(T (&input)[ITEMS_PER_THREAD], + OutputT (&output)[ITEMS_PER_THREAD], + DifferenceOpT difference_op) + { + // Share first item + temp_storage.first_items[linear_tid] = input[0]; + + CTA_SYNC(); + + #pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD - 1; item++) + { + output[item] = difference_op(input[item], input[item + 1]); + } + + if (linear_tid == BLOCK_THREADS - 1) + { + output[ITEMS_PER_THREAD - 1] = input[ITEMS_PER_THREAD - 1]; + } + else + { + output[ITEMS_PER_THREAD - 1] = + difference_op(input[ITEMS_PER_THREAD - 1], + temp_storage.first_items[linear_tid + 1]); + } + } + + /** + * @brief Subtracts the right element of each adjacent pair of elements + * partitioned across a CUDA thread block. + * + * @par + * - \rowmajor + * - \smemreuse + * + * @par Snippet + * The code snippet below illustrates how to use @p BlockAdjacentDifference + * to compute the right difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * struct CustomDifference + * { + * template + * __device__ DataType operator()(DataType &lhs, DataType &rhs) + * { + * return lhs - rhs; + * } + * }; + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockAdjacentDifference for a 1D block of + * // 128 threads of type int + * using BlockAdjacentDifferenceT = + * cub::BlockAdjacentDifference; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockAdjacentDifferenceT::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // The first item in the nest tile: + * int tile_successor_item = ...; + * + * // Collectively compute adjacent_difference + * BlockAdjacentDifferenceT(temp_storage).SubtractRight( + * thread_data, + * thread_data, + * CustomDifference(), + * tile_successor_item); + * + * @endcode + * @par + * Suppose the set of input `thread_data` across the block of threads is + * `{ ...3], [4,2,1,1], [1,1,1,1], [2,3,3,3], [3,4,1,4] }`, + * and that `tile_successor_item` is `3`. The corresponding output `result` + * in those threads will be + * `{ ..., [-1,2,1,0], [0,0,0,-1], [-1,0,0,0], [-1,3,-3,1] }`. + * + * @param[out] output + * Calling thread's adjacent difference result + * + * @param[in] input + * Calling thread's input items (may be aliased to @p output) + * + * @param[in] difference_op + * Binary difference operator + * + * @param[in] tile_successor_item + * [threadBLOCK_THREADS-1 only] item + * which is going to be subtracted from the last tile item + * (inputITEMS_PER_THREAD-1 from + * threadBLOCK_THREADS-1). + */ + template + __device__ __forceinline__ void + SubtractRight(T (&input)[ITEMS_PER_THREAD], + OutputT (&output)[ITEMS_PER_THREAD], + DifferenceOpT difference_op, + T tile_successor_item) + { + // Share first item + temp_storage.first_items[linear_tid] = input[0]; + + CTA_SYNC(); + + // Set flag for last thread-item + T successor_item = (linear_tid == BLOCK_THREADS - 1) + ? tile_successor_item // Last thread + : temp_storage.first_items[linear_tid + 1]; + + #pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD - 1; item++) + { + output[item] = difference_op(input[item], input[item + 1]); + } + + output[ITEMS_PER_THREAD - 1] = + difference_op(input[ITEMS_PER_THREAD - 1], successor_item); + } + + /** + * @brief Subtracts the right element of each adjacent pair in range of + * elements partitioned across a CUDA thread block. + * + * @par + * - \rowmajor + * - \smemreuse + * + * @par Snippet + * The code snippet below illustrates how to use @p BlockAdjacentDifference to + * compute the right difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * struct CustomDifference + * { + * template + * __device__ DataType operator()(DataType &lhs, DataType &rhs) + * { + * return lhs - rhs; + * } + * }; + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockAdjacentDifference for a 1D block of + * // 128 threads of type int + * using BlockAdjacentDifferenceT = + * cub::BlockAdjacentDifference; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockAdjacentDifferenceT::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute adjacent_difference + * BlockAdjacentDifferenceT(temp_storage).SubtractRightPartialTile( + * thread_data, + * thread_data, + * CustomDifference(), + * valid_items); + * + * @endcode + * @par + * Suppose the set of input `thread_data` across the block of threads is + * `{ ...3], [4,2,1,1], [1,1,1,1], [2,3,3,3], [3,4,1,4] }`. + * and that `valid_items` is `507`. The corresponding output `result` in + * those threads will be + * `{ ..., [-1,2,1,0], [0,0,0,-1], [-1,0,3,3], [3,4,1,4] }`. + * + * @param[out] output + * Calling thread's adjacent difference result + * + * @param[in] input + * Calling thread's input items (may be aliased to @p output) + * + * @param[in] difference_op + * Binary difference operator + * + * @param[in] valid_items + * Number of valid items in thread block + */ + template + __device__ __forceinline__ void + SubtractRightPartialTile(T (&input)[ITEMS_PER_THREAD], + OutputT (&output)[ITEMS_PER_THREAD], + DifferenceOpT difference_op, + int valid_items) + { + // Share first item + temp_storage.first_items[linear_tid] = input[0]; + + CTA_SYNC(); + + if ((linear_tid + 1) * ITEMS_PER_THREAD < valid_items) + { + #pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD - 1; item++) + { + output[item] = difference_op(input[item], input[item + 1]); + } + + output[ITEMS_PER_THREAD - 1] = + difference_op(input[ITEMS_PER_THREAD - 1], + temp_storage.first_items[linear_tid + 1]); + } + else + { + #pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD; item++) + { + const int idx = linear_tid * ITEMS_PER_THREAD + item; + + // Right element of input[valid_items - 1] is out of bounds. + // According to the API it's copied into output array + // without modification. + if (idx < valid_items - 1) + { + output[item] = difference_op(input[item], input[item + 1]); + } + else + { + output[item] = input[item]; + } + } + } + } + + //@} end member group + /******************************************************************//** + * @name Head flag operations (deprecated) + *********************************************************************/ + //@{ + + #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + + /** + * \deprecated [Since 1.14.0] The cub::BlockAdjacentDifference::FlagHeads + * APIs are deprecated. Use cub::BlockAdjacentDifference::SubtractLeft instead. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + CUB_DEPRECATED __device__ __forceinline__ void FlagHeads( + FlagT (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&preds)[ITEMS_PER_THREAD], ///< [out] Calling thread's predecessor items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share last item + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + if (linear_tid == 0) + { + // Set flag for first thread-item (preds[0] is undefined) + output[0] = 1; + } + else + { + preds[0] = temp_storage.last_items[linear_tid - 1]; + output[0] = ApplyOp::FlagT(flag_op, preds[0], input[0], linear_tid * ITEMS_PER_THREAD); + } + + // Set output for remaining items + Iterate::FlagHeads(linear_tid, output, input, preds, flag_op); + } + + /** + * \deprecated [Since 1.14.0] The cub::BlockAdjacentDifference::FlagHeads + * APIs are deprecated. Use cub::BlockAdjacentDifference::SubtractLeft instead. + */ + template + CUB_DEPRECATED __device__ __forceinline__ void FlagHeads( + FlagT (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity result + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&preds)[ITEMS_PER_THREAD], ///< [out] Calling thread's predecessor items + FlagOp flag_op, ///< [in] Binary boolean flag predicate + T tile_predecessor_item) ///< [in] [thread0 only] Item with which to compare the first tile item (input0 from thread0). + { + // Share last item + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + // Set flag for first thread-item + preds[0] = (linear_tid == 0) ? + tile_predecessor_item : // First thread + temp_storage.last_items[linear_tid - 1]; + + output[0] = ApplyOp::FlagT(flag_op, preds[0], input[0], linear_tid * ITEMS_PER_THREAD); + + // Set output for remaining items + Iterate::FlagHeads(linear_tid, output, input, preds, flag_op); + } + +#endif // DOXYGEN_SHOULD_SKIP_THIS + + /** + * \deprecated [Since 1.14.0] The cub::BlockAdjacentDifference::FlagHeads + * APIs are deprecated. Use cub::BlockAdjacentDifference::SubtractLeft instead. + */ + template + CUB_DEPRECATED __device__ __forceinline__ void + FlagHeads(FlagT (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity result + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + T preds[ITEMS_PER_THREAD]; + FlagHeads(output, input, preds, flag_op); + } + + /** + * \deprecated [Since 1.14.0] The cub::BlockAdjacentDifference::FlagHeads + * APIs are deprecated. Use cub::BlockAdjacentDifference::SubtractLeft instead. + */ + template + CUB_DEPRECATED __device__ __forceinline__ void + FlagHeads(FlagT (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity result + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op, ///< [in] Binary boolean flag predicate + T tile_predecessor_item) ///< [in] [thread0 only] Item with which to compare the first tile item (input0 from thread0). + { + T preds[ITEMS_PER_THREAD]; + FlagHeads(output, input, preds, flag_op, tile_predecessor_item); + } + + + /** + * \deprecated [Since 1.14.0] The cub::BlockAdjacentDifference::FlagTails + * APIs are deprecated. Use cub::BlockAdjacentDifference::SubtractRight instead. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + CUB_DEPRECATED __device__ __forceinline__ void FlagTails( + FlagT (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity result + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share first item + temp_storage.first_items[linear_tid] = input[0]; + + CTA_SYNC(); + + // Set flag for last thread-item + output[ITEMS_PER_THREAD - 1] = (linear_tid == BLOCK_THREADS - 1) ? + 1 : // Last thread + ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + temp_storage.first_items[linear_tid + 1], + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set output for remaining items + Iterate::FlagTails(linear_tid, output, input, flag_op); + } + + + /** + * \deprecated [Since 1.14.0] The cub::BlockAdjacentDifference::FlagTails + * APIs are deprecated. Use cub::BlockAdjacentDifference::SubtractRight instead. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + CUB_DEPRECATED __device__ __forceinline__ void FlagTails( + FlagT (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity result + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op, ///< [in] Binary boolean flag predicate + T tile_successor_item) ///< [in] [threadBLOCK_THREADS-1 only] Item with which to compare the last tile item (inputITEMS_PER_THREAD-1 from threadBLOCK_THREADS-1). + { + // Share first item + temp_storage.first_items[linear_tid] = input[0]; + + CTA_SYNC(); + + // Set flag for last thread-item + T successor_item = (linear_tid == BLOCK_THREADS - 1) ? + tile_successor_item : // Last thread + temp_storage.first_items[linear_tid + 1]; + + output[ITEMS_PER_THREAD - 1] = ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + successor_item, + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set output for remaining items + Iterate::FlagTails(linear_tid, output, input, flag_op); + } + + + /** + * \deprecated [Since 1.14.0] The cub::BlockAdjacentDifference::FlagHeadsAndTails + * APIs are deprecated. Use cub::BlockAdjacentDifference::SubtractLeft or + * cub::BlockAdjacentDifference::SubtractRight instead. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + CUB_DEPRECATED __device__ __forceinline__ void FlagHeadsAndTails( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + FlagT (&tail_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity tail_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share first and last items + temp_storage.first_items[linear_tid] = input[0]; + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + T preds[ITEMS_PER_THREAD]; + + // Set flag for first thread-item + preds[0] = temp_storage.last_items[linear_tid - 1]; + if (linear_tid == 0) + { + head_flags[0] = 1; + } + else + { + head_flags[0] = ApplyOp::FlagT( + flag_op, + preds[0], + input[0], + linear_tid * ITEMS_PER_THREAD); + } + + + // Set flag for last thread-item + tail_flags[ITEMS_PER_THREAD - 1] = (linear_tid == BLOCK_THREADS - 1) ? + 1 : // Last thread + ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + temp_storage.first_items[linear_tid + 1], + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set head_flags for remaining items + Iterate::FlagHeads(linear_tid, head_flags, input, preds, flag_op); + + // Set tail_flags for remaining items + Iterate::FlagTails(linear_tid, tail_flags, input, flag_op); + } + + + /** + * \deprecated [Since 1.14.0] The cub::BlockAdjacentDifference::FlagHeadsAndTails + * APIs are deprecated. Use cub::BlockAdjacentDifference::SubtractLeft or + * cub::BlockAdjacentDifference::SubtractRight instead. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + CUB_DEPRECATED __device__ __forceinline__ void FlagHeadsAndTails( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + FlagT (&tail_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity tail_flags + T tile_successor_item, ///< [in] [threadBLOCK_THREADS-1 only] Item with which to compare the last tile item (inputITEMS_PER_THREAD-1 from threadBLOCK_THREADS-1). + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share first and last items + temp_storage.first_items[linear_tid] = input[0]; + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + T preds[ITEMS_PER_THREAD]; + + // Set flag for first thread-item + if (linear_tid == 0) + { + head_flags[0] = 1; + } + else + { + preds[0] = temp_storage.last_items[linear_tid - 1]; + head_flags[0] = ApplyOp::FlagT( + flag_op, + preds[0], + input[0], + linear_tid * ITEMS_PER_THREAD); + } + + // Set flag for last thread-item + T successor_item = (linear_tid == BLOCK_THREADS - 1) ? + tile_successor_item : // Last thread + temp_storage.first_items[linear_tid + 1]; + + tail_flags[ITEMS_PER_THREAD - 1] = ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + successor_item, + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set head_flags for remaining items + Iterate::FlagHeads(linear_tid, head_flags, input, preds, flag_op); + + // Set tail_flags for remaining items + Iterate::FlagTails(linear_tid, tail_flags, input, flag_op); + } + + /** + * \deprecated [Since 1.14.0] The cub::BlockAdjacentDifference::FlagHeadsAndTails + * APIs are deprecated. Use cub::BlockAdjacentDifference::SubtractLeft or + * cub::BlockAdjacentDifference::SubtractRight instead. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + CUB_DEPRECATED __device__ __forceinline__ void FlagHeadsAndTails( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + T tile_predecessor_item, ///< [in] [thread0 only] Item with which to compare the first tile item (input0 from thread0). + FlagT (&tail_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity tail_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share first and last items + temp_storage.first_items[linear_tid] = input[0]; + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + T preds[ITEMS_PER_THREAD]; + + // Set flag for first thread-item + preds[0] = (linear_tid == 0) ? + tile_predecessor_item : // First thread + temp_storage.last_items[linear_tid - 1]; + + head_flags[0] = ApplyOp::FlagT( + flag_op, + preds[0], + input[0], + linear_tid * ITEMS_PER_THREAD); + + // Set flag for last thread-item + tail_flags[ITEMS_PER_THREAD - 1] = (linear_tid == BLOCK_THREADS - 1) ? + 1 : // Last thread + ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + temp_storage.first_items[linear_tid + 1], + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set head_flags for remaining items + Iterate::FlagHeads(linear_tid, head_flags, input, preds, flag_op); + + // Set tail_flags for remaining items + Iterate::FlagTails(linear_tid, tail_flags, input, flag_op); + } + + + /** + * \deprecated [Since 1.14.0] The cub::BlockAdjacentDifference::FlagHeadsAndTails + * APIs are deprecated. Use cub::BlockAdjacentDifference::SubtractLeft or + * cub::BlockAdjacentDifference::SubtractRight instead. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + CUB_DEPRECATED __device__ __forceinline__ void FlagHeadsAndTails( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + T tile_predecessor_item, ///< [in] [thread0 only] Item with which to compare the first tile item (input0 from thread0). + FlagT (&tail_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity tail_flags + T tile_successor_item, ///< [in] [threadBLOCK_THREADS-1 only] Item with which to compare the last tile item (inputITEMS_PER_THREAD-1 from threadBLOCK_THREADS-1). + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share first and last items + temp_storage.first_items[linear_tid] = input[0]; + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + T preds[ITEMS_PER_THREAD]; + + // Set flag for first thread-item + preds[0] = (linear_tid == 0) ? + tile_predecessor_item : // First thread + temp_storage.last_items[linear_tid - 1]; + + head_flags[0] = ApplyOp::FlagT( + flag_op, + preds[0], + input[0], + linear_tid * ITEMS_PER_THREAD); + + // Set flag for last thread-item + T successor_item = (linear_tid == BLOCK_THREADS - 1) ? + tile_successor_item : // Last thread + temp_storage.first_items[linear_tid + 1]; + + tail_flags[ITEMS_PER_THREAD - 1] = ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + successor_item, + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set head_flags for remaining items + Iterate::FlagHeads(linear_tid, head_flags, input, preds, flag_op); + + // Set tail_flags for remaining items + Iterate::FlagTails(linear_tid, tail_flags, input, flag_op); + } + +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_discontinuity.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_discontinuity.cuh new file mode 100644 index 0000000000000000000000000000000000000000..a3bf17f319034c1b1754198cdb93856b8212d46d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_discontinuity.cuh @@ -0,0 +1,1119 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * The cub::BlockDiscontinuity class provides [collective](index.html#sec0) methods for flagging discontinuities within an ordered set of items partitioned across a CUDA thread block. + */ + +#pragma once + +#include "../config.cuh" +#include "../util_type.cuh" +#include "../util_ptx.cuh" + +CUB_NAMESPACE_BEGIN + +/** + * \brief The BlockDiscontinuity class provides [collective](index.html#sec0) methods for flagging discontinuities within an ordered set of items partitioned across a CUDA thread block. ![](discont_logo.png) + * \ingroup BlockModule + * + * \tparam T The data type to be flagged. + * \tparam BLOCK_DIM_X The thread block length in threads along the X dimension + * \tparam BLOCK_DIM_Y [optional] The thread block length in threads along the Y dimension (default: 1) + * \tparam BLOCK_DIM_Z [optional] The thread block length in threads along the Z dimension (default: 1) + * \tparam LEGACY_PTX_ARCH [optional] Unused. + * + * \par Overview + * - A set of "head flags" (or "tail flags") is often used to indicate corresponding items + * that differ from their predecessors (or successors). For example, head flags are convenient + * for demarcating disjoint data segments as part of a segmented scan or reduction. + * - \blocked + * + * \par Performance Considerations + * - \granularity + * + * \par A Simple Example + * \blockcollective{BlockDiscontinuity} + * \par + * The code snippet below illustrates the head flagging of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockDiscontinuity for a 1D block of 128 threads of type int + * typedef cub::BlockDiscontinuity BlockDiscontinuity; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockDiscontinuity::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute head flags for discontinuities in the segment + * int head_flags[4]; + * BlockDiscontinuity(temp_storage).FlagHeads(head_flags, thread_data, cub::Inequality()); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [0,0,1,1], [1,1,1,1], [2,3,3,3], [3,4,4,4], ... }. + * The corresponding output \p head_flags in those threads will be + * { [1,0,1,0], [0,0,0,0], [1,1,0,0], [0,1,0,0], ... }. + * + * \par Performance Considerations + * - Incurs zero bank conflicts for most types + * + * \par Re-using dynamically allocating shared memory + * The following example under the examples/block folder illustrates usage of + * dynamically shared memory with BlockReduce and how to re-purpose + * the same memory region: + * example_block_reduce_dyn_smem.cu + * + * This example can be easily adapted to the storage required by BlockDiscontinuity. + */ +template < + typename T, + int BLOCK_DIM_X, + int BLOCK_DIM_Y = 1, + int BLOCK_DIM_Z = 1, + int LEGACY_PTX_ARCH = 0> +class BlockDiscontinuity +{ +private: + + /****************************************************************************** + * Constants and type definitions + ******************************************************************************/ + + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + }; + + + /// Shared memory storage layout type (last element from each thread's input) + struct _TempStorage + { + T first_items[BLOCK_THREADS]; + T last_items[BLOCK_THREADS]; + }; + + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + + /// Specialization for when FlagOp has third index param + template ::HAS_PARAM> + struct ApplyOp + { + // Apply flag operator + static __device__ __forceinline__ bool FlagT(FlagOp flag_op, const T &a, const T &b, int idx) + { + return flag_op(a, b, idx); + } + }; + + /// Specialization for when FlagOp does not have a third index param + template + struct ApplyOp + { + // Apply flag operator + static __device__ __forceinline__ bool FlagT(FlagOp flag_op, const T &a, const T &b, int /*idx*/) + { + return flag_op(a, b); + } + }; + + /// Templated unrolling of item comparison (inductive case) + struct Iterate + { + // Head flags + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + static __device__ __forceinline__ void FlagHeads( + int linear_tid, + FlagT (&flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&preds)[ITEMS_PER_THREAD], ///< [out] Calling thread's predecessor items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + #pragma unroll + for (int i = 1; i < ITEMS_PER_THREAD; ++i) { + preds[i] = input[i - 1]; + flags[i] = ApplyOp::FlagT( + flag_op, + preds[i], + input[i], + (linear_tid * ITEMS_PER_THREAD) + i); + } + } + + // Tail flags + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + static __device__ __forceinline__ void FlagTails( + int linear_tid, + FlagT (&flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + #pragma unroll + for (int i = 0; i < ITEMS_PER_THREAD - 1; ++i) { + flags[i] = ApplyOp::FlagT( + flag_op, + input[i], + input[i + 1], + (linear_tid * ITEMS_PER_THREAD) + i + 1); + } + } + + }; + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Linear thread-id + unsigned int linear_tid; + + +public: + + /// \smemstorage{BlockDiscontinuity} + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /******************************************************************//** + * \name Collective constructors + *********************************************************************/ + //@{ + + /** + * \brief Collective constructor using a private static allocation of shared memory as temporary storage. + */ + __device__ __forceinline__ BlockDiscontinuity() + : + temp_storage(PrivateStorage()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + /** + * \brief Collective constructor using the specified memory allocation as temporary storage. + */ + __device__ __forceinline__ BlockDiscontinuity( + TempStorage &temp_storage) ///< [in] Reference to memory allocation having layout type TempStorage + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + //@} end member group + /******************************************************************//** + * \name Head flag operations + *********************************************************************/ + //@{ + + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + __device__ __forceinline__ void FlagHeads( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&preds)[ITEMS_PER_THREAD], ///< [out] Calling thread's predecessor items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share last item + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + if (linear_tid == 0) + { + // Set flag for first thread-item (preds[0] is undefined) + head_flags[0] = 1; + } + else + { + preds[0] = temp_storage.last_items[linear_tid - 1]; + head_flags[0] = ApplyOp::FlagT(flag_op, preds[0], input[0], linear_tid * ITEMS_PER_THREAD); + } + + // Set head_flags for remaining items + Iterate::FlagHeads(linear_tid, head_flags, input, preds, flag_op); + } + + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + __device__ __forceinline__ void FlagHeads( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&preds)[ITEMS_PER_THREAD], ///< [out] Calling thread's predecessor items + FlagOp flag_op, ///< [in] Binary boolean flag predicate + T tile_predecessor_item) ///< [in] [thread0 only] Item with which to compare the first tile item (input0 from thread0). + { + // Share last item + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + // Set flag for first thread-item + preds[0] = (linear_tid == 0) ? + tile_predecessor_item : // First thread + temp_storage.last_items[linear_tid - 1]; + + head_flags[0] = ApplyOp::FlagT(flag_op, preds[0], input[0], linear_tid * ITEMS_PER_THREAD); + + // Set head_flags for remaining items + Iterate::FlagHeads(linear_tid, head_flags, input, preds, flag_op); + } + +#endif // DOXYGEN_SHOULD_SKIP_THIS + + + /** + * \brief Sets head flags indicating discontinuities between items partitioned across the thread block, for which the first item has no reference and is always flagged. + * + * \par + * - The flag head_flagsi is set for item + * inputi when + * flag_op(previous-item, inputi) + * returns \p true (where previous-item is either the preceding item + * in the same thread or the last item in the previous thread). + * - For thread0, item input0 is always flagged. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the head-flagging of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockDiscontinuity for a 1D block of 128 threads of type int + * typedef cub::BlockDiscontinuity BlockDiscontinuity; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockDiscontinuity::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute head flags for discontinuities in the segment + * int head_flags[4]; + * BlockDiscontinuity(temp_storage).FlagHeads(head_flags, thread_data, cub::Inequality()); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [0,0,1,1], [1,1,1,1], [2,3,3,3], [3,4,4,4], ... }. + * The corresponding output \p head_flags in those threads will be + * { [1,0,1,0], [0,0,0,0], [1,1,0,0], [0,1,0,0], ... }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam FlagT [inferred] The flag type (must be an integer type) + * \tparam FlagOp [inferred] Binary predicate functor type having member T operator()(const T &a, const T &b) or member T operator()(const T &a, const T &b, unsigned int b_index), and returning \p true if a discontinuity exists between \p a and \p b, otherwise \p false. \p b_index is the rank of b in the aggregate tile of data. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + __device__ __forceinline__ void FlagHeads( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + T preds[ITEMS_PER_THREAD]; + FlagHeads(head_flags, input, preds, flag_op); + } + + + /** + * \brief Sets head flags indicating discontinuities between items partitioned across the thread block. + * + * \par + * - The flag head_flagsi is set for item + * inputi when + * flag_op(previous-item, inputi) + * returns \p true (where previous-item is either the preceding item + * in the same thread or the last item in the previous thread). + * - For thread0, item input0 is compared + * against \p tile_predecessor_item. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the head-flagging of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockDiscontinuity for a 1D block of 128 threads of type int + * typedef cub::BlockDiscontinuity BlockDiscontinuity; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockDiscontinuity::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Have thread0 obtain the predecessor item for the entire tile + * int tile_predecessor_item; + * if (threadIdx.x == 0) tile_predecessor_item == ... + * + * // Collectively compute head flags for discontinuities in the segment + * int head_flags[4]; + * BlockDiscontinuity(temp_storage).FlagHeads( + * head_flags, thread_data, cub::Inequality(), tile_predecessor_item); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [0,0,1,1], [1,1,1,1], [2,3,3,3], [3,4,4,4], ... }, + * and that \p tile_predecessor_item is \p 0. The corresponding output \p head_flags in those threads will be + * { [0,0,1,0], [0,0,0,0], [1,1,0,0], [0,1,0,0], ... }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam FlagT [inferred] The flag type (must be an integer type) + * \tparam FlagOp [inferred] Binary predicate functor type having member T operator()(const T &a, const T &b) or member T operator()(const T &a, const T &b, unsigned int b_index), and returning \p true if a discontinuity exists between \p a and \p b, otherwise \p false. \p b_index is the rank of b in the aggregate tile of data. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + __device__ __forceinline__ void FlagHeads( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op, ///< [in] Binary boolean flag predicate + T tile_predecessor_item) ///< [in] [thread0 only] Item with which to compare the first tile item (input0 from thread0). + { + T preds[ITEMS_PER_THREAD]; + FlagHeads(head_flags, input, preds, flag_op, tile_predecessor_item); + } + + + + //@} end member group + /******************************************************************//** + * \name Tail flag operations + *********************************************************************/ + //@{ + + + /** + * \brief Sets tail flags indicating discontinuities between items partitioned across the thread block, for which the last item has no reference and is always flagged. + * + * \par + * - The flag tail_flagsi is set for item + * inputi when + * flag_op(inputi, next-item) + * returns \p true (where next-item is either the next item + * in the same thread or the first item in the next thread). + * - For threadBLOCK_THREADS-1, item + * inputITEMS_PER_THREAD-1 is always flagged. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the tail-flagging of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockDiscontinuity for a 1D block of 128 threads of type int + * typedef cub::BlockDiscontinuity BlockDiscontinuity; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockDiscontinuity::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute tail flags for discontinuities in the segment + * int tail_flags[4]; + * BlockDiscontinuity(temp_storage).FlagTails(tail_flags, thread_data, cub::Inequality()); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [0,0,1,1], [1,1,1,1], [2,3,3,3], ..., [124,125,125,125] }. + * The corresponding output \p tail_flags in those threads will be + * { [0,1,0,0], [0,0,0,1], [1,0,0,...], ..., [1,0,0,1] }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam FlagT [inferred] The flag type (must be an integer type) + * \tparam FlagOp [inferred] Binary predicate functor type having member T operator()(const T &a, const T &b) or member T operator()(const T &a, const T &b, unsigned int b_index), and returning \p true if a discontinuity exists between \p a and \p b, otherwise \p false. \p b_index is the rank of b in the aggregate tile of data. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + __device__ __forceinline__ void FlagTails( + FlagT (&tail_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity tail_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share first item + temp_storage.first_items[linear_tid] = input[0]; + + CTA_SYNC(); + + // Set flag for last thread-item + tail_flags[ITEMS_PER_THREAD - 1] = (linear_tid == BLOCK_THREADS - 1) ? + 1 : // Last thread + ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + temp_storage.first_items[linear_tid + 1], + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set tail_flags for remaining items + Iterate::FlagTails(linear_tid, tail_flags, input, flag_op); + } + + + /** + * \brief Sets tail flags indicating discontinuities between items partitioned across the thread block. + * + * \par + * - The flag tail_flagsi is set for item + * inputi when + * flag_op(inputi, next-item) + * returns \p true (where next-item is either the next item + * in the same thread or the first item in the next thread). + * - For threadBLOCK_THREADS-1, item + * inputITEMS_PER_THREAD-1 is compared + * against \p tile_successor_item. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the tail-flagging of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockDiscontinuity for a 1D block of 128 threads of type int + * typedef cub::BlockDiscontinuity BlockDiscontinuity; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockDiscontinuity::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Have thread127 obtain the successor item for the entire tile + * int tile_successor_item; + * if (threadIdx.x == 127) tile_successor_item == ... + * + * // Collectively compute tail flags for discontinuities in the segment + * int tail_flags[4]; + * BlockDiscontinuity(temp_storage).FlagTails( + * tail_flags, thread_data, cub::Inequality(), tile_successor_item); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [0,0,1,1], [1,1,1,1], [2,3,3,3], ..., [124,125,125,125] } + * and that \p tile_successor_item is \p 125. The corresponding output \p tail_flags in those threads will be + * { [0,1,0,0], [0,0,0,1], [1,0,0,...], ..., [1,0,0,0] }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam FlagT [inferred] The flag type (must be an integer type) + * \tparam FlagOp [inferred] Binary predicate functor type having member T operator()(const T &a, const T &b) or member T operator()(const T &a, const T &b, unsigned int b_index), and returning \p true if a discontinuity exists between \p a and \p b, otherwise \p false. \p b_index is the rank of b in the aggregate tile of data. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + __device__ __forceinline__ void FlagTails( + FlagT (&tail_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity tail_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op, ///< [in] Binary boolean flag predicate + T tile_successor_item) ///< [in] [threadBLOCK_THREADS-1 only] Item with which to compare the last tile item (inputITEMS_PER_THREAD-1 from threadBLOCK_THREADS-1). + { + // Share first item + temp_storage.first_items[linear_tid] = input[0]; + + CTA_SYNC(); + + // Set flag for last thread-item + T successor_item = (linear_tid == BLOCK_THREADS - 1) ? + tile_successor_item : // Last thread + temp_storage.first_items[linear_tid + 1]; + + tail_flags[ITEMS_PER_THREAD - 1] = ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + successor_item, + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set tail_flags for remaining items + Iterate::FlagTails(linear_tid, tail_flags, input, flag_op); + } + + + //@} end member group + /******************************************************************//** + * \name Head & tail flag operations + *********************************************************************/ + //@{ + + + /** + * \brief Sets both head and tail flags indicating discontinuities between items partitioned across the thread block. + * + * \par + * - The flag head_flagsi is set for item + * inputi when + * flag_op(previous-item, inputi) + * returns \p true (where previous-item is either the preceding item + * in the same thread or the last item in the previous thread). + * - For thread0, item input0 is always flagged. + * - The flag tail_flagsi is set for item + * inputi when + * flag_op(inputi, next-item) + * returns \p true (where next-item is either the next item + * in the same thread or the first item in the next thread). + * - For threadBLOCK_THREADS-1, item + * inputITEMS_PER_THREAD-1 is always flagged. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the head- and tail-flagging of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockDiscontinuity for a 1D block of 128 threads of type int + * typedef cub::BlockDiscontinuity BlockDiscontinuity; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockDiscontinuity::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute head and flags for discontinuities in the segment + * int head_flags[4]; + * int tail_flags[4]; + * BlockDiscontinuity(temp_storage).FlagTails( + * head_flags, tail_flags, thread_data, cub::Inequality()); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [0,0,1,1], [1,1,1,1], [2,3,3,3], ..., [124,125,125,125] } + * and that the tile_successor_item is \p 125. The corresponding output \p head_flags + * in those threads will be { [1,0,1,0], [0,0,0,0], [1,1,0,0], [0,1,0,0], ... }. + * and the corresponding output \p tail_flags in those threads will be + * { [0,1,0,0], [0,0,0,1], [1,0,0,...], ..., [1,0,0,1] }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam FlagT [inferred] The flag type (must be an integer type) + * \tparam FlagOp [inferred] Binary predicate functor type having member T operator()(const T &a, const T &b) or member T operator()(const T &a, const T &b, unsigned int b_index), and returning \p true if a discontinuity exists between \p a and \p b, otherwise \p false. \p b_index is the rank of b in the aggregate tile of data. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + __device__ __forceinline__ void FlagHeadsAndTails( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + FlagT (&tail_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity tail_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share first and last items + temp_storage.first_items[linear_tid] = input[0]; + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + T preds[ITEMS_PER_THREAD]; + + // Set flag for first thread-item + if (linear_tid == 0) + { + head_flags[0] = 1; + } + else + { + preds[0] = temp_storage.last_items[linear_tid - 1]; + head_flags[0] = ApplyOp::FlagT( + flag_op, + preds[0], + input[0], + linear_tid * ITEMS_PER_THREAD); + } + + + // Set flag for last thread-item + tail_flags[ITEMS_PER_THREAD - 1] = (linear_tid == BLOCK_THREADS - 1) ? + 1 : // Last thread + ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + temp_storage.first_items[linear_tid + 1], + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set head_flags for remaining items + Iterate::FlagHeads(linear_tid, head_flags, input, preds, flag_op); + + // Set tail_flags for remaining items + Iterate::FlagTails(linear_tid, tail_flags, input, flag_op); + } + + + /** + * \brief Sets both head and tail flags indicating discontinuities between items partitioned across the thread block. + * + * \par + * - The flag head_flagsi is set for item + * inputi when + * flag_op(previous-item, inputi) + * returns \p true (where previous-item is either the preceding item + * in the same thread or the last item in the previous thread). + * - For thread0, item input0 is always flagged. + * - The flag tail_flagsi is set for item + * inputi when + * flag_op(inputi, next-item) + * returns \p true (where next-item is either the next item + * in the same thread or the first item in the next thread). + * - For threadBLOCK_THREADS-1, item + * inputITEMS_PER_THREAD-1 is compared + * against \p tile_predecessor_item. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the head- and tail-flagging of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockDiscontinuity for a 1D block of 128 threads of type int + * typedef cub::BlockDiscontinuity BlockDiscontinuity; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockDiscontinuity::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Have thread127 obtain the successor item for the entire tile + * int tile_successor_item; + * if (threadIdx.x == 127) tile_successor_item == ... + * + * // Collectively compute head and flags for discontinuities in the segment + * int head_flags[4]; + * int tail_flags[4]; + * BlockDiscontinuity(temp_storage).FlagTails( + * head_flags, tail_flags, tile_successor_item, thread_data, cub::Inequality()); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [0,0,1,1], [1,1,1,1], [2,3,3,3], ..., [124,125,125,125] } + * and that the tile_successor_item is \p 125. The corresponding output \p head_flags + * in those threads will be { [1,0,1,0], [0,0,0,0], [1,1,0,0], [0,1,0,0], ... }. + * and the corresponding output \p tail_flags in those threads will be + * { [0,1,0,0], [0,0,0,1], [1,0,0,...], ..., [1,0,0,0] }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam FlagT [inferred] The flag type (must be an integer type) + * \tparam FlagOp [inferred] Binary predicate functor type having member T operator()(const T &a, const T &b) or member T operator()(const T &a, const T &b, unsigned int b_index), and returning \p true if a discontinuity exists between \p a and \p b, otherwise \p false. \p b_index is the rank of b in the aggregate tile of data. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + __device__ __forceinline__ void FlagHeadsAndTails( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + FlagT (&tail_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity tail_flags + T tile_successor_item, ///< [in] [threadBLOCK_THREADS-1 only] Item with which to compare the last tile item (inputITEMS_PER_THREAD-1 from threadBLOCK_THREADS-1). + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share first and last items + temp_storage.first_items[linear_tid] = input[0]; + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + T preds[ITEMS_PER_THREAD]; + + // Set flag for first thread-item + if (linear_tid == 0) + { + head_flags[0] = 1; + } + else + { + preds[0] = temp_storage.last_items[linear_tid - 1]; + head_flags[0] = ApplyOp::FlagT( + flag_op, + preds[0], + input[0], + linear_tid * ITEMS_PER_THREAD); + } + + // Set flag for last thread-item + T successor_item = (linear_tid == BLOCK_THREADS - 1) ? + tile_successor_item : // Last thread + temp_storage.first_items[linear_tid + 1]; + + tail_flags[ITEMS_PER_THREAD - 1] = ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + successor_item, + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set head_flags for remaining items + Iterate::FlagHeads(linear_tid, head_flags, input, preds, flag_op); + + // Set tail_flags for remaining items + Iterate::FlagTails(linear_tid, tail_flags, input, flag_op); + } + + + /** + * \brief Sets both head and tail flags indicating discontinuities between items partitioned across the thread block. + * + * \par + * - The flag head_flagsi is set for item + * inputi when + * flag_op(previous-item, inputi) + * returns \p true (where previous-item is either the preceding item + * in the same thread or the last item in the previous thread). + * - For thread0, item input0 is compared + * against \p tile_predecessor_item. + * - The flag tail_flagsi is set for item + * inputi when + * flag_op(inputi, next-item) + * returns \p true (where next-item is either the next item + * in the same thread or the first item in the next thread). + * - For threadBLOCK_THREADS-1, item + * inputITEMS_PER_THREAD-1 is always flagged. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the head- and tail-flagging of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockDiscontinuity for a 1D block of 128 threads of type int + * typedef cub::BlockDiscontinuity BlockDiscontinuity; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockDiscontinuity::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Have thread0 obtain the predecessor item for the entire tile + * int tile_predecessor_item; + * if (threadIdx.x == 0) tile_predecessor_item == ... + * + * // Have thread127 obtain the successor item for the entire tile + * int tile_successor_item; + * if (threadIdx.x == 127) tile_successor_item == ... + * + * // Collectively compute head and flags for discontinuities in the segment + * int head_flags[4]; + * int tail_flags[4]; + * BlockDiscontinuity(temp_storage).FlagTails( + * head_flags, tile_predecessor_item, tail_flags, tile_successor_item, + * thread_data, cub::Inequality()); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [0,0,1,1], [1,1,1,1], [2,3,3,3], ..., [124,125,125,125] }, + * that the \p tile_predecessor_item is \p 0, and that the + * \p tile_successor_item is \p 125. The corresponding output \p head_flags + * in those threads will be { [0,0,1,0], [0,0,0,0], [1,1,0,0], [0,1,0,0], ... }. + * and the corresponding output \p tail_flags in those threads will be + * { [0,1,0,0], [0,0,0,1], [1,0,0,...], ..., [1,0,0,1] }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam FlagT [inferred] The flag type (must be an integer type) + * \tparam FlagOp [inferred] Binary predicate functor type having member T operator()(const T &a, const T &b) or member T operator()(const T &a, const T &b, unsigned int b_index), and returning \p true if a discontinuity exists between \p a and \p b, otherwise \p false. \p b_index is the rank of b in the aggregate tile of data. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + __device__ __forceinline__ void FlagHeadsAndTails( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + T tile_predecessor_item, ///< [in] [thread0 only] Item with which to compare the first tile item (input0 from thread0). + FlagT (&tail_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity tail_flags + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share first and last items + temp_storage.first_items[linear_tid] = input[0]; + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + T preds[ITEMS_PER_THREAD]; + + // Set flag for first thread-item + preds[0] = (linear_tid == 0) ? + tile_predecessor_item : // First thread + temp_storage.last_items[linear_tid - 1]; + + head_flags[0] = ApplyOp::FlagT( + flag_op, + preds[0], + input[0], + linear_tid * ITEMS_PER_THREAD); + + // Set flag for last thread-item + tail_flags[ITEMS_PER_THREAD - 1] = (linear_tid == BLOCK_THREADS - 1) ? + 1 : // Last thread + ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + temp_storage.first_items[linear_tid + 1], + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set head_flags for remaining items + Iterate::FlagHeads(linear_tid, head_flags, input, preds, flag_op); + + // Set tail_flags for remaining items + Iterate::FlagTails(linear_tid, tail_flags, input, flag_op); + } + + + /** + * \brief Sets both head and tail flags indicating discontinuities between items partitioned across the thread block. + * + * \par + * - The flag head_flagsi is set for item + * inputi when + * flag_op(previous-item, inputi) + * returns \p true (where previous-item is either the preceding item + * in the same thread or the last item in the previous thread). + * - For thread0, item input0 is compared + * against \p tile_predecessor_item. + * - The flag tail_flagsi is set for item + * inputi when + * flag_op(inputi, next-item) + * returns \p true (where next-item is either the next item + * in the same thread or the first item in the next thread). + * - For threadBLOCK_THREADS-1, item + * inputITEMS_PER_THREAD-1 is compared + * against \p tile_successor_item. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the head- and tail-flagging of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockDiscontinuity for a 1D block of 128 threads of type int + * typedef cub::BlockDiscontinuity BlockDiscontinuity; + * + * // Allocate shared memory for BlockDiscontinuity + * __shared__ typename BlockDiscontinuity::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Have thread0 obtain the predecessor item for the entire tile + * int tile_predecessor_item; + * if (threadIdx.x == 0) tile_predecessor_item == ... + * + * // Have thread127 obtain the successor item for the entire tile + * int tile_successor_item; + * if (threadIdx.x == 127) tile_successor_item == ... + * + * // Collectively compute head and flags for discontinuities in the segment + * int head_flags[4]; + * int tail_flags[4]; + * BlockDiscontinuity(temp_storage).FlagTails( + * head_flags, tile_predecessor_item, tail_flags, tile_successor_item, + * thread_data, cub::Inequality()); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [0,0,1,1], [1,1,1,1], [2,3,3,3], ..., [124,125,125,125] }, + * that the \p tile_predecessor_item is \p 0, and that the + * \p tile_successor_item is \p 125. The corresponding output \p head_flags + * in those threads will be { [0,0,1,0], [0,0,0,0], [1,1,0,0], [0,1,0,0], ... }. + * and the corresponding output \p tail_flags in those threads will be + * { [0,1,0,0], [0,0,0,1], [1,0,0,...], ..., [1,0,0,0] }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam FlagT [inferred] The flag type (must be an integer type) + * \tparam FlagOp [inferred] Binary predicate functor type having member T operator()(const T &a, const T &b) or member T operator()(const T &a, const T &b, unsigned int b_index), and returning \p true if a discontinuity exists between \p a and \p b, otherwise \p false. \p b_index is the rank of b in the aggregate tile of data. + */ + template < + int ITEMS_PER_THREAD, + typename FlagT, + typename FlagOp> + __device__ __forceinline__ void FlagHeadsAndTails( + FlagT (&head_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity head_flags + T tile_predecessor_item, ///< [in] [thread0 only] Item with which to compare the first tile item (input0 from thread0). + FlagT (&tail_flags)[ITEMS_PER_THREAD], ///< [out] Calling thread's discontinuity tail_flags + T tile_successor_item, ///< [in] [threadBLOCK_THREADS-1 only] Item with which to compare the last tile item (inputITEMS_PER_THREAD-1 from threadBLOCK_THREADS-1). + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + FlagOp flag_op) ///< [in] Binary boolean flag predicate + { + // Share first and last items + temp_storage.first_items[linear_tid] = input[0]; + temp_storage.last_items[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + T preds[ITEMS_PER_THREAD]; + + // Set flag for first thread-item + preds[0] = (linear_tid == 0) ? + tile_predecessor_item : // First thread + temp_storage.last_items[linear_tid - 1]; + + head_flags[0] = ApplyOp::FlagT( + flag_op, + preds[0], + input[0], + linear_tid * ITEMS_PER_THREAD); + + // Set flag for last thread-item + T successor_item = (linear_tid == BLOCK_THREADS - 1) ? + tile_successor_item : // Last thread + temp_storage.first_items[linear_tid + 1]; + + tail_flags[ITEMS_PER_THREAD - 1] = ApplyOp::FlagT( + flag_op, + input[ITEMS_PER_THREAD - 1], + successor_item, + (linear_tid * ITEMS_PER_THREAD) + ITEMS_PER_THREAD); + + // Set head_flags for remaining items + Iterate::FlagHeads(linear_tid, head_flags, input, preds, flag_op); + + // Set tail_flags for remaining items + Iterate::FlagTails(linear_tid, tail_flags, input, flag_op); + } + + + + + //@} end member group + +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_exchange.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_exchange.cuh new file mode 100644 index 0000000000000000000000000000000000000000..5f4bc2e84a8373ceb49969f69a291841ff77293c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_exchange.cuh @@ -0,0 +1,1144 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * The cub::BlockExchange class provides [collective](index.html#sec0) methods for rearranging data partitioned across a CUDA thread block. + */ + +#pragma once + +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +/** + * \brief The BlockExchange class provides [collective](index.html#sec0) methods for rearranging data partitioned across a CUDA thread block. ![](transpose_logo.png) + * \ingroup BlockModule + * + * \tparam T The data type to be exchanged. + * \tparam BLOCK_DIM_X The thread block length in threads along the X dimension + * \tparam ITEMS_PER_THREAD The number of items partitioned onto each thread. + * \tparam WARP_TIME_SLICING [optional] When \p true, only use enough shared memory for a single warp's worth of tile data, time-slicing the block-wide exchange over multiple synchronized rounds. Yields a smaller memory footprint at the expense of decreased parallelism. (Default: false) + * \tparam BLOCK_DIM_Y [optional] The thread block length in threads along the Y dimension (default: 1) + * \tparam BLOCK_DIM_Z [optional] The thread block length in threads along the Z dimension (default: 1) + * \tparam LEGACY_PTX_ARCH [optional] Unused. + * + * \par Overview + * - It is commonplace for blocks of threads to rearrange data items between + * threads. For example, the device-accessible memory subsystem prefers access patterns + * where data items are "striped" across threads (where consecutive threads access consecutive items), + * yet most block-wide operations prefer a "blocked" partitioning of items across threads + * (where consecutive items belong to a single thread). + * - BlockExchange supports the following types of data exchanges: + * - Transposing between [blocked](index.html#sec5sec3) and [striped](index.html#sec5sec3) arrangements + * - Transposing between [blocked](index.html#sec5sec3) and [warp-striped](index.html#sec5sec3) arrangements + * - Scattering ranked items to a [blocked arrangement](index.html#sec5sec3) + * - Scattering ranked items to a [striped arrangement](index.html#sec5sec3) + * - \rowmajor + * + * \par A Simple Example + * \blockcollective{BlockExchange} + * \par + * The code snippet below illustrates the conversion from a "blocked" to a "striped" arrangement + * of 512 integer items partitioned across 128 threads where each thread owns 4 items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * // Specialize BlockExchange for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockExchange BlockExchange; + * + * // Allocate shared memory for BlockExchange + * __shared__ typename BlockExchange::TempStorage temp_storage; + * + * // Load a tile of data striped across threads + * int thread_data[4]; + * cub::LoadDirectStriped<128>(threadIdx.x, d_data, thread_data); + * + * // Collectively exchange data into a blocked arrangement across threads + * BlockExchange(temp_storage).StripedToBlocked(thread_data); + * + * \endcode + * \par + * Suppose the set of striped input \p thread_data across the block of threads is + * { [0,128,256,384], [1,129,257,385], ..., [127,255,383,511] }. + * The corresponding output \p thread_data in those threads will be + * { [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [508,509,510,511] }. + * + * \par Performance Considerations + * - Proper device-specific padding ensures zero bank conflicts for most types. + * + * \par Re-using dynamically allocating shared memory + * The following example under the examples/block folder illustrates usage of + * dynamically shared memory with BlockReduce and how to re-purpose + * the same memory region: + * example_block_reduce_dyn_smem.cu + * + * This example can be easily adapted to the storage required by BlockExchange. + */ +template < + typename InputT, + int BLOCK_DIM_X, + int ITEMS_PER_THREAD, + bool WARP_TIME_SLICING = false, + int BLOCK_DIM_Y = 1, + int BLOCK_DIM_Z = 1, + int LEGACY_PTX_ARCH = 0> +class BlockExchange +{ +private: + + /****************************************************************************** + * Constants + ******************************************************************************/ + + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + + LOG_WARP_THREADS = CUB_LOG_WARP_THREADS(0), + WARP_THREADS = 1 << LOG_WARP_THREADS, + WARPS = (BLOCK_THREADS + WARP_THREADS - 1) / WARP_THREADS, + + LOG_SMEM_BANKS = CUB_LOG_SMEM_BANKS(0), + SMEM_BANKS = 1 << LOG_SMEM_BANKS, + + TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD, + + TIME_SLICES = (WARP_TIME_SLICING) ? WARPS : 1, + + TIME_SLICED_THREADS = (WARP_TIME_SLICING) ? CUB_MIN(BLOCK_THREADS, WARP_THREADS) : BLOCK_THREADS, + TIME_SLICED_ITEMS = TIME_SLICED_THREADS * ITEMS_PER_THREAD, + + WARP_TIME_SLICED_THREADS = CUB_MIN(BLOCK_THREADS, WARP_THREADS), + WARP_TIME_SLICED_ITEMS = WARP_TIME_SLICED_THREADS * ITEMS_PER_THREAD, + + // Insert padding to avoid bank conflicts during raking when items per thread is a power of two and > 4 (otherwise we can typically use 128b loads) + INSERT_PADDING = (ITEMS_PER_THREAD > 4) && (PowerOfTwo::VALUE), + PADDING_ITEMS = (INSERT_PADDING) ? (TIME_SLICED_ITEMS >> LOG_SMEM_BANKS) : 0, + }; + + /****************************************************************************** + * Type definitions + ******************************************************************************/ + + /// Shared memory storage layout type + struct __align__(16) _TempStorage + { + InputT buff[TIME_SLICED_ITEMS + PADDING_ITEMS]; + }; + +public: + + /// \smemstorage{BlockExchange} + struct TempStorage : Uninitialized<_TempStorage> {}; + +private: + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Linear thread-id + unsigned int linear_tid; + unsigned int lane_id; + unsigned int warp_id; + unsigned int warp_offset; + + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + + /** + * Transposes data items from blocked arrangement to striped arrangement. Specialized for no timeslicing. + */ + template + __device__ __forceinline__ void BlockedToStriped( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + Int2Type /*time_slicing*/) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = (linear_tid * ITEMS_PER_THREAD) + ITEM; + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = int(ITEM * BLOCK_THREADS) + linear_tid; + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + output_items[ITEM] = temp_storage.buff[item_offset]; + } + } + + + /** + * Transposes data items from blocked arrangement to striped arrangement. Specialized for warp-timeslicing. + */ + template + __device__ __forceinline__ void BlockedToStriped( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + Int2Type /*time_slicing*/) + { + InputT temp_items[ITEMS_PER_THREAD]; + + #pragma unroll + for (int SLICE = 0; SLICE < TIME_SLICES; SLICE++) + { + const int SLICE_OFFSET = SLICE * TIME_SLICED_ITEMS; + const int SLICE_OOB = SLICE_OFFSET + TIME_SLICED_ITEMS; + + CTA_SYNC(); + + if (warp_id == SLICE) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = (lane_id * ITEMS_PER_THREAD) + ITEM; + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + } + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + // Read a strip of items + const int STRIP_OFFSET = ITEM * BLOCK_THREADS; + const int STRIP_OOB = STRIP_OFFSET + BLOCK_THREADS; + + if ((SLICE_OFFSET < STRIP_OOB) && (SLICE_OOB > STRIP_OFFSET)) + { + int item_offset = STRIP_OFFSET + linear_tid - SLICE_OFFSET; + if ((item_offset >= 0) && (item_offset < TIME_SLICED_ITEMS)) + { + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + temp_items[ITEM] = temp_storage.buff[item_offset]; + } + } + } + } + + // Copy + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + output_items[ITEM] = temp_items[ITEM]; + } + } + + + /** + * Transposes data items from blocked arrangement to warp-striped arrangement. Specialized for no timeslicing + */ + template + __device__ __forceinline__ void BlockedToWarpStriped( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + Int2Type /*time_slicing*/) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = warp_offset + ITEM + (lane_id * ITEMS_PER_THREAD); + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + + WARP_SYNC(0xffffffff); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = warp_offset + (ITEM * WARP_TIME_SLICED_THREADS) + lane_id; + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + output_items[ITEM] = temp_storage.buff[item_offset]; + } + } + + /** + * Transposes data items from blocked arrangement to warp-striped arrangement. Specialized for warp-timeslicing + */ + template + __device__ __forceinline__ void BlockedToWarpStriped( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + Int2Type /*time_slicing*/) + { + if (warp_id == 0) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = ITEM + (lane_id * ITEMS_PER_THREAD); + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + + WARP_SYNC(0xffffffff); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = (ITEM * WARP_TIME_SLICED_THREADS) + lane_id; + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + output_items[ITEM] = temp_storage.buff[item_offset]; + } + } + + #pragma unroll + for (unsigned int SLICE = 1; SLICE < TIME_SLICES; ++SLICE) + { + CTA_SYNC(); + + if (warp_id == SLICE) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = ITEM + (lane_id * ITEMS_PER_THREAD); + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + + WARP_SYNC(0xffffffff); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = (ITEM * WARP_TIME_SLICED_THREADS) + lane_id; + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + output_items[ITEM] = temp_storage.buff[item_offset]; + } + } + } + } + + + /** + * Transposes data items from striped arrangement to blocked arrangement. Specialized for no timeslicing. + */ + template + __device__ __forceinline__ void StripedToBlocked( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + Int2Type /*time_slicing*/) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = int(ITEM * BLOCK_THREADS) + linear_tid; + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + + CTA_SYNC(); + + // No timeslicing + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = (linear_tid * ITEMS_PER_THREAD) + ITEM; + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + output_items[ITEM] = temp_storage.buff[item_offset]; + } + } + + + /** + * Transposes data items from striped arrangement to blocked arrangement. Specialized for warp-timeslicing. + */ + template + __device__ __forceinline__ void StripedToBlocked( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + Int2Type /*time_slicing*/) + { + // Warp time-slicing + InputT temp_items[ITEMS_PER_THREAD]; + + #pragma unroll + for (int SLICE = 0; SLICE < TIME_SLICES; SLICE++) + { + const int SLICE_OFFSET = SLICE * TIME_SLICED_ITEMS; + const int SLICE_OOB = SLICE_OFFSET + TIME_SLICED_ITEMS; + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + // Write a strip of items + const int STRIP_OFFSET = ITEM * BLOCK_THREADS; + const int STRIP_OOB = STRIP_OFFSET + BLOCK_THREADS; + + if ((SLICE_OFFSET < STRIP_OOB) && (SLICE_OOB > STRIP_OFFSET)) + { + int item_offset = STRIP_OFFSET + linear_tid - SLICE_OFFSET; + if ((item_offset >= 0) && (item_offset < TIME_SLICED_ITEMS)) + { + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + detail::uninitialized_copy(temp_storage.buff + + item_offset, + input_items[ITEM]); + } + } + } + + CTA_SYNC(); + + if (warp_id == SLICE) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = (lane_id * ITEMS_PER_THREAD) + ITEM; + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + temp_items[ITEM] = temp_storage.buff[item_offset]; + } + } + } + + // Copy + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + output_items[ITEM] = temp_items[ITEM]; + } + } + + + /** + * Transposes data items from warp-striped arrangement to blocked arrangement. Specialized for no timeslicing + */ + template + __device__ __forceinline__ void WarpStripedToBlocked( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + Int2Type /*time_slicing*/) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = warp_offset + (ITEM * WARP_TIME_SLICED_THREADS) + lane_id; + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + + WARP_SYNC(0xffffffff); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = warp_offset + ITEM + (lane_id * ITEMS_PER_THREAD); + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + detail::uninitialized_copy(output_items + ITEM, + temp_storage.buff[item_offset]); + } + } + + + /** + * Transposes data items from warp-striped arrangement to blocked arrangement. Specialized for warp-timeslicing + */ + template + __device__ __forceinline__ void WarpStripedToBlocked( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + Int2Type /*time_slicing*/) + { + #pragma unroll + for (unsigned int SLICE = 0; SLICE < TIME_SLICES; ++SLICE) + { + CTA_SYNC(); + + if (warp_id == SLICE) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = (ITEM * WARP_TIME_SLICED_THREADS) + lane_id; + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + + WARP_SYNC(0xffffffff); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = ITEM + (lane_id * ITEMS_PER_THREAD); + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + output_items[ITEM] = temp_storage.buff[item_offset]; + } + } + } + } + + + /** + * Exchanges data items annotated by rank into blocked arrangement. Specialized for no timeslicing. + */ + template + __device__ __forceinline__ void ScatterToBlocked( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + OffsetT (&ranks)[ITEMS_PER_THREAD], ///< [in] Corresponding scatter ranks + Int2Type /*time_slicing*/) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = ranks[ITEM]; + if (INSERT_PADDING) item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = (linear_tid * ITEMS_PER_THREAD) + ITEM; + if (INSERT_PADDING) item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + output_items[ITEM] = temp_storage.buff[item_offset]; + } + } + + /** + * Exchanges data items annotated by rank into blocked arrangement. Specialized for warp-timeslicing. + */ + template + __device__ __forceinline__ void ScatterToBlocked( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + OffsetT ranks[ITEMS_PER_THREAD], ///< [in] Corresponding scatter ranks + Int2Type /*time_slicing*/) + { + InputT temp_items[ITEMS_PER_THREAD]; + + #pragma unroll + for (int SLICE = 0; SLICE < TIME_SLICES; SLICE++) + { + CTA_SYNC(); + + const int SLICE_OFFSET = TIME_SLICED_ITEMS * SLICE; + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = ranks[ITEM] - SLICE_OFFSET; + if ((item_offset >= 0) && (item_offset < WARP_TIME_SLICED_ITEMS)) + { + if (INSERT_PADDING) item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + } + + CTA_SYNC(); + + if (warp_id == SLICE) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = (lane_id * ITEMS_PER_THREAD) + ITEM; + if (INSERT_PADDING) item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + temp_items[ITEM] = temp_storage.buff[item_offset]; + } + } + } + + // Copy + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + output_items[ITEM] = temp_items[ITEM]; + } + } + + + /** + * Exchanges data items annotated by rank into striped arrangement. Specialized for no timeslicing. + */ + template + __device__ __forceinline__ void ScatterToStriped( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + OffsetT (&ranks)[ITEMS_PER_THREAD], ///< [in] Corresponding scatter ranks + Int2Type /*time_slicing*/) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = ranks[ITEM]; + if (INSERT_PADDING) item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = int(ITEM * BLOCK_THREADS) + linear_tid; + if (INSERT_PADDING) item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + output_items[ITEM] = temp_storage.buff[item_offset]; + } + } + + + /** + * Exchanges data items annotated by rank into striped arrangement. Specialized for warp-timeslicing. + */ + template + __device__ __forceinline__ void ScatterToStriped( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between blocked and striped arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items to exchange, converting between blocked and striped arrangements. + OffsetT (&ranks)[ITEMS_PER_THREAD], ///< [in] Corresponding scatter ranks + Int2Type /*time_slicing*/) + { + InputT temp_items[ITEMS_PER_THREAD]; + + #pragma unroll + for (int SLICE = 0; SLICE < TIME_SLICES; SLICE++) + { + const int SLICE_OFFSET = SLICE * TIME_SLICED_ITEMS; + const int SLICE_OOB = SLICE_OFFSET + TIME_SLICED_ITEMS; + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = ranks[ITEM] - SLICE_OFFSET; + if ((item_offset >= 0) && (item_offset < WARP_TIME_SLICED_ITEMS)) + { + if (INSERT_PADDING) item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + detail::uninitialized_copy(temp_storage.buff + item_offset, + input_items[ITEM]); + } + } + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + // Read a strip of items + const int STRIP_OFFSET = ITEM * BLOCK_THREADS; + const int STRIP_OOB = STRIP_OFFSET + BLOCK_THREADS; + + if ((SLICE_OFFSET < STRIP_OOB) && (SLICE_OOB > STRIP_OFFSET)) + { + int item_offset = STRIP_OFFSET + linear_tid - SLICE_OFFSET; + if ((item_offset >= 0) && (item_offset < TIME_SLICED_ITEMS)) + { + if (INSERT_PADDING) item_offset += item_offset >> LOG_SMEM_BANKS; + temp_items[ITEM] = temp_storage.buff[item_offset]; + } + } + } + } + + // Copy + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + output_items[ITEM] = temp_items[ITEM]; + } + } + + +public: + + /******************************************************************//** + * \name Collective constructors + *********************************************************************/ + //@{ + + /** + * \brief Collective constructor using a private static allocation of shared memory as temporary storage. + */ + __device__ __forceinline__ BlockExchange() + : + temp_storage(PrivateStorage()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)), + lane_id(LaneId()), + warp_id((WARPS == 1) ? 0 : linear_tid / WARP_THREADS), + warp_offset(warp_id * WARP_TIME_SLICED_ITEMS) + {} + + + /** + * \brief Collective constructor using the specified memory allocation as temporary storage. + */ + __device__ __forceinline__ BlockExchange( + TempStorage &temp_storage) ///< [in] Reference to memory allocation having layout type TempStorage + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)), + lane_id(LaneId()), + warp_id((WARPS == 1) ? 0 : linear_tid / WARP_THREADS), + warp_offset(warp_id * WARP_TIME_SLICED_ITEMS) + {} + + + //@} end member group + /******************************************************************//** + * \name Structured exchanges + *********************************************************************/ + //@{ + + /** + * \brief Transposes data items from striped arrangement to blocked arrangement. + * + * \par + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the conversion from a "striped" to a "blocked" arrangement + * of 512 integer items partitioned across 128 threads where each thread owns 4 items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * // Specialize BlockExchange for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockExchange BlockExchange; + * + * // Allocate shared memory for BlockExchange + * __shared__ typename BlockExchange::TempStorage temp_storage; + * + * // Load a tile of ordered data into a striped arrangement across block threads + * int thread_data[4]; + * cub::LoadDirectStriped<128>(threadIdx.x, d_data, thread_data); + * + * // Collectively exchange data into a blocked arrangement across threads + * BlockExchange(temp_storage).StripedToBlocked(thread_data, thread_data); + * + * \endcode + * \par + * Suppose the set of striped input \p thread_data across the block of threads is + * { [0,128,256,384], [1,129,257,385], ..., [127,255,383,511] } after loading from device-accessible memory. + * The corresponding output \p thread_data in those threads will be + * { [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [508,509,510,511] }. + * + */ + template + __device__ __forceinline__ void StripedToBlocked( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between striped and blocked arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD]) ///< [out] Items from exchange, converting between striped and blocked arrangements. + { + StripedToBlocked(input_items, output_items, Int2Type()); + } + + + /** + * \brief Transposes data items from blocked arrangement to striped arrangement. + * + * \par + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the conversion from a "blocked" to a "striped" arrangement + * of 512 integer items partitioned across 128 threads where each thread owns 4 items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * // Specialize BlockExchange for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockExchange BlockExchange; + * + * // Allocate shared memory for BlockExchange + * __shared__ typename BlockExchange::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively exchange data into a striped arrangement across threads + * BlockExchange(temp_storage).BlockedToStriped(thread_data, thread_data); + * + * // Store data striped across block threads into an ordered tile + * cub::StoreDirectStriped(threadIdx.x, d_data, thread_data); + * + * \endcode + * \par + * Suppose the set of blocked input \p thread_data across the block of threads is + * { [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [508,509,510,511] }. + * The corresponding output \p thread_data in those threads will be + * { [0,128,256,384], [1,129,257,385], ..., [127,255,383,511] } in + * preparation for storing to device-accessible memory. + * + */ + template + __device__ __forceinline__ void BlockedToStriped( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between striped and blocked arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD]) ///< [out] Items from exchange, converting between striped and blocked arrangements. + { + BlockedToStriped(input_items, output_items, Int2Type()); + } + + + + /** + * \brief Transposes data items from warp-striped arrangement to blocked arrangement. + * + * \par + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the conversion from a "warp-striped" to a "blocked" arrangement + * of 512 integer items partitioned across 128 threads where each thread owns 4 items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * // Specialize BlockExchange for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockExchange BlockExchange; + * + * // Allocate shared memory for BlockExchange + * __shared__ typename BlockExchange::TempStorage temp_storage; + * + * // Load a tile of ordered data into a warp-striped arrangement across warp threads + * int thread_data[4]; + * cub::LoadSWarptriped(threadIdx.x, d_data, thread_data); + * + * // Collectively exchange data into a blocked arrangement across threads + * BlockExchange(temp_storage).WarpStripedToBlocked(thread_data); + * + * \endcode + * \par + * Suppose the set of warp-striped input \p thread_data across the block of threads is + * { [0,32,64,96], [1,33,65,97], [2,34,66,98], ..., [415,447,479,511] } + * after loading from device-accessible memory. (The first 128 items are striped across + * the first warp of 32 threads, the second 128 items are striped across the second warp, etc.) + * The corresponding output \p thread_data in those threads will be + * { [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [508,509,510,511] }. + * + */ + template + __device__ __forceinline__ void WarpStripedToBlocked( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between striped and blocked arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD]) ///< [out] Items from exchange, converting between striped and blocked arrangements. + { + WarpStripedToBlocked(input_items, output_items, Int2Type()); + } + + + + /** + * \brief Transposes data items from blocked arrangement to warp-striped arrangement. + * + * \par + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the conversion from a "blocked" to a "warp-striped" arrangement + * of 512 integer items partitioned across 128 threads where each thread owns 4 items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * // Specialize BlockExchange for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockExchange BlockExchange; + * + * // Allocate shared memory for BlockExchange + * __shared__ typename BlockExchange::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively exchange data into a warp-striped arrangement across threads + * BlockExchange(temp_storage).BlockedToWarpStriped(thread_data, thread_data); + * + * // Store data striped across warp threads into an ordered tile + * cub::StoreDirectStriped(threadIdx.x, d_data, thread_data); + * + * \endcode + * \par + * Suppose the set of blocked input \p thread_data across the block of threads is + * { [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [508,509,510,511] }. + * The corresponding output \p thread_data in those threads will be + * { [0,32,64,96], [1,33,65,97], [2,34,66,98], ..., [415,447,479,511] } + * in preparation for storing to device-accessible memory. (The first 128 items are striped across + * the first warp of 32 threads, the second 128 items are striped across the second warp, etc.) + * + */ + template + __device__ __forceinline__ void BlockedToWarpStriped( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between striped and blocked arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD]) ///< [out] Items from exchange, converting between striped and blocked arrangements. + { + BlockedToWarpStriped(input_items, output_items, Int2Type()); + } + + + + //@} end member group + /******************************************************************//** + * \name Scatter exchanges + *********************************************************************/ + //@{ + + + /** + * \brief Exchanges data items annotated by rank into blocked arrangement. + * + * \par + * - \smemreuse + * + * \tparam OffsetT [inferred] Signed integer type for local offsets + */ + template + __device__ __forceinline__ void ScatterToBlocked( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between striped and blocked arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items from exchange, converting between striped and blocked arrangements. + OffsetT (&ranks)[ITEMS_PER_THREAD]) ///< [in] Corresponding scatter ranks + { + ScatterToBlocked(input_items, output_items, ranks, Int2Type()); + } + + + + /** + * \brief Exchanges data items annotated by rank into striped arrangement. + * + * \par + * - \smemreuse + * + * \tparam OffsetT [inferred] Signed integer type for local offsets + */ + template + __device__ __forceinline__ void ScatterToStriped( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between striped and blocked arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items from exchange, converting between striped and blocked arrangements. + OffsetT (&ranks)[ITEMS_PER_THREAD]) ///< [in] Corresponding scatter ranks + { + ScatterToStriped(input_items, output_items, ranks, Int2Type()); + } + + + + /** + * \brief Exchanges data items annotated by rank into striped arrangement. Items with rank -1 are not exchanged. + * + * \par + * - \smemreuse + * + * \tparam OffsetT [inferred] Signed integer type for local offsets + */ + template + __device__ __forceinline__ void ScatterToStripedGuarded( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between striped and blocked arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items from exchange, converting between striped and blocked arrangements. + OffsetT (&ranks)[ITEMS_PER_THREAD]) ///< [in] Corresponding scatter ranks + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = ranks[ITEM]; + if (INSERT_PADDING) item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + if (ranks[ITEM] >= 0) + temp_storage.buff[item_offset] = input_items[ITEM]; + } + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = int(ITEM * BLOCK_THREADS) + linear_tid; + if (INSERT_PADDING) item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + output_items[ITEM] = temp_storage.buff[item_offset]; + } + } + + + + + /** + * \brief Exchanges valid data items annotated by rank into striped arrangement. + * + * \par + * - \smemreuse + * + * \tparam OffsetT [inferred] Signed integer type for local offsets + * \tparam ValidFlag [inferred] FlagT type denoting which items are valid + */ + template + __device__ __forceinline__ void ScatterToStripedFlagged( + InputT (&input_items)[ITEMS_PER_THREAD], ///< [in] Items to exchange, converting between striped and blocked arrangements. + OutputT (&output_items)[ITEMS_PER_THREAD], ///< [out] Items from exchange, converting between striped and blocked arrangements. + OffsetT (&ranks)[ITEMS_PER_THREAD], ///< [in] Corresponding scatter ranks + ValidFlag (&is_valid)[ITEMS_PER_THREAD]) ///< [in] Corresponding flag denoting item validity + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = ranks[ITEM]; + if (INSERT_PADDING) item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + if (is_valid[ITEM]) + temp_storage.buff[item_offset] = input_items[ITEM]; + } + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = int(ITEM * BLOCK_THREADS) + linear_tid; + if (INSERT_PADDING) item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + output_items[ITEM] = temp_storage.buff[item_offset]; + } + } + + + //@} end member group + + + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + + + __device__ __forceinline__ void StripedToBlocked( + InputT (&items)[ITEMS_PER_THREAD]) ///< [in-out] Items to exchange, converting between striped and blocked arrangements. + { + StripedToBlocked(items, items); + } + + __device__ __forceinline__ void BlockedToStriped( + InputT (&items)[ITEMS_PER_THREAD]) ///< [in-out] Items to exchange, converting between striped and blocked arrangements. + { + BlockedToStriped(items, items); + } + + __device__ __forceinline__ void WarpStripedToBlocked( + InputT (&items)[ITEMS_PER_THREAD]) ///< [in-out] Items to exchange, converting between striped and blocked arrangements. + { + WarpStripedToBlocked(items, items); + } + + __device__ __forceinline__ void BlockedToWarpStriped( + InputT (&items)[ITEMS_PER_THREAD]) ///< [in-out] Items to exchange, converting between striped and blocked arrangements. + { + BlockedToWarpStriped(items, items); + } + + template + __device__ __forceinline__ void ScatterToBlocked( + InputT (&items)[ITEMS_PER_THREAD], ///< [in-out] Items to exchange, converting between striped and blocked arrangements. + OffsetT (&ranks)[ITEMS_PER_THREAD]) ///< [in] Corresponding scatter ranks + { + ScatterToBlocked(items, items, ranks); + } + + template + __device__ __forceinline__ void ScatterToStriped( + InputT (&items)[ITEMS_PER_THREAD], ///< [in-out] Items to exchange, converting between striped and blocked arrangements. + OffsetT (&ranks)[ITEMS_PER_THREAD]) ///< [in] Corresponding scatter ranks + { + ScatterToStriped(items, items, ranks); + } + + template + __device__ __forceinline__ void ScatterToStripedGuarded( + InputT (&items)[ITEMS_PER_THREAD], ///< [in-out] Items to exchange, converting between striped and blocked arrangements. + OffsetT (&ranks)[ITEMS_PER_THREAD]) ///< [in] Corresponding scatter ranks + { + ScatterToStripedGuarded(items, items, ranks); + } + + template + __device__ __forceinline__ void ScatterToStripedFlagged( + InputT (&items)[ITEMS_PER_THREAD], ///< [in-out] Items to exchange, converting between striped and blocked arrangements. + OffsetT (&ranks)[ITEMS_PER_THREAD], ///< [in] Corresponding scatter ranks + ValidFlag (&is_valid)[ITEMS_PER_THREAD]) ///< [in] Corresponding flag denoting item validity + { + ScatterToStriped(items, items, ranks, is_valid); + } + +#endif // DOXYGEN_SHOULD_SKIP_THIS + + +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_histogram.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_histogram.cuh new file mode 100644 index 0000000000000000000000000000000000000000..b9ab759607d20404ca7abc660b74f2922573c26b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_histogram.cuh @@ -0,0 +1,416 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * The cub::BlockHistogram class provides [collective](index.html#sec0) methods for constructing block-wide histograms from data samples partitioned across a CUDA thread block. + */ + +#pragma once + +#include "specializations/block_histogram_sort.cuh" +#include "specializations/block_histogram_atomic.cuh" +#include "../config.cuh" +#include "../util_ptx.cuh" + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Algorithmic variants + ******************************************************************************/ + +/** + * \brief BlockHistogramAlgorithm enumerates alternative algorithms for the parallel construction of block-wide histograms. + */ +enum BlockHistogramAlgorithm +{ + + /** + * \par Overview + * Sorting followed by differentiation. Execution is comprised of two phases: + * -# Sort the data using efficient radix sort + * -# Look for "runs" of same-valued keys by detecting discontinuities; the run-lengths are histogram bin counts. + * + * \par Performance Considerations + * Delivers consistent throughput regardless of sample bin distribution. + */ + BLOCK_HISTO_SORT, + + + /** + * \par Overview + * Use atomic addition to update byte counts directly + * + * \par Performance Considerations + * Performance is strongly tied to the hardware implementation of atomic + * addition, and may be significantly degraded for non uniformly-random + * input distributions where many concurrent updates are likely to be + * made to the same bin counter. + */ + BLOCK_HISTO_ATOMIC, +}; + + + +/****************************************************************************** + * Block histogram + ******************************************************************************/ + + +/** + * \brief The BlockHistogram class provides [collective](index.html#sec0) methods for constructing block-wide histograms from data samples partitioned across a CUDA thread block. ![](histogram_logo.png) + * \ingroup BlockModule + * + * \tparam T The sample type being histogrammed (must be castable to an integer bin identifier) + * \tparam BLOCK_DIM_X The thread block length in threads along the X dimension + * \tparam ITEMS_PER_THREAD The number of items per thread + * \tparam BINS The number bins within the histogram + * \tparam ALGORITHM [optional] cub::BlockHistogramAlgorithm enumerator specifying the underlying algorithm to use (default: cub::BLOCK_HISTO_SORT) + * \tparam BLOCK_DIM_Y [optional] The thread block length in threads along the Y dimension (default: 1) + * \tparam BLOCK_DIM_Z [optional] The thread block length in threads along the Z dimension (default: 1) + * \tparam LEGACY_PTX_ARCH [optional] Unused. + * + * \par Overview + * - A histogram + * counts the number of observations that fall into each of the disjoint categories (known as bins). + * - The `T` type must be implicitly castable to an integer type. + * - BlockHistogram expects each integral `input[i]` value to satisfy + * `0 <= input[i] < BINS`. Values outside of this range result in undefined + * behavior. + * - BlockHistogram can be optionally specialized to use different algorithms: + * -# cub::BLOCK_HISTO_SORT. Sorting followed by differentiation. [More...](\ref cub::BlockHistogramAlgorithm) + * -# cub::BLOCK_HISTO_ATOMIC. Use atomic addition to update byte counts directly. [More...](\ref cub::BlockHistogramAlgorithm) + * + * \par Performance Considerations + * - \granularity + * + * \par A Simple Example + * \blockcollective{BlockHistogram} + * \par + * The code snippet below illustrates a 256-bin histogram of 512 integer samples that + * are partitioned across 128 threads where each thread owns 4 samples. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize a 256-bin BlockHistogram type for a 1D block of 128 threads having 4 character samples each + * typedef cub::BlockHistogram BlockHistogram; + * + * // Allocate shared memory for BlockHistogram + * __shared__ typename BlockHistogram::TempStorage temp_storage; + * + * // Allocate shared memory for block-wide histogram bin counts + * __shared__ unsigned int smem_histogram[256]; + * + * // Obtain input samples per thread + * unsigned char data[4]; + * ... + * + * // Compute the block-wide histogram + * BlockHistogram(temp_storage).Histogram(data, smem_histogram); + * + * \endcode + * + * \par Performance and Usage Considerations + * - All input values must fall between [0, BINS), or behavior is undefined. + * - The histogram output can be constructed in shared or device-accessible memory + * - See cub::BlockHistogramAlgorithm for performance details regarding algorithmic alternatives + * + * \par Re-using dynamically allocating shared memory + * The following example under the examples/block folder illustrates usage of + * dynamically shared memory with BlockReduce and how to re-purpose + * the same memory region: + * example_block_reduce_dyn_smem.cu + * + * This example can be easily adapted to the storage required by BlockHistogram. + */ +template < + typename T, + int BLOCK_DIM_X, + int ITEMS_PER_THREAD, + int BINS, + BlockHistogramAlgorithm ALGORITHM = BLOCK_HISTO_SORT, + int BLOCK_DIM_Y = 1, + int BLOCK_DIM_Z = 1, + int LEGACY_PTX_ARCH = 0> +class BlockHistogram +{ +private: + + /****************************************************************************** + * Constants and type definitions + ******************************************************************************/ + + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + }; + + /// Internal specialization. + using InternalBlockHistogram = + cub::detail::conditional_t, + BlockHistogramAtomic>; + + /// Shared memory storage layout type for BlockHistogram + typedef typename InternalBlockHistogram::TempStorage _TempStorage; + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Linear thread-id + unsigned int linear_tid; + + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + +public: + + /// \smemstorage{BlockHistogram} + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /******************************************************************//** + * \name Collective constructors + *********************************************************************/ + //@{ + + /** + * \brief Collective constructor using a private static allocation of shared memory as temporary storage. + */ + __device__ __forceinline__ BlockHistogram() + : + temp_storage(PrivateStorage()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + /** + * \brief Collective constructor using the specified memory allocation as temporary storage. + */ + __device__ __forceinline__ BlockHistogram( + TempStorage &temp_storage) ///< [in] Reference to memory allocation having layout type TempStorage + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + //@} end member group + /******************************************************************//** + * \name Histogram operations + *********************************************************************/ + //@{ + + + /** + * \brief Initialize the shared histogram counters to zero. + * + * \par Snippet + * The code snippet below illustrates a the initialization and update of a + * histogram of 512 integer samples that are partitioned across 128 threads + * where each thread owns 4 samples. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize a 256-bin BlockHistogram type for a 1D block of 128 threads having 4 character samples each + * typedef cub::BlockHistogram BlockHistogram; + * + * // Allocate shared memory for BlockHistogram + * __shared__ typename BlockHistogram::TempStorage temp_storage; + * + * // Allocate shared memory for block-wide histogram bin counts + * __shared__ unsigned int smem_histogram[256]; + * + * // Obtain input samples per thread + * unsigned char thread_samples[4]; + * ... + * + * // Initialize the block-wide histogram + * BlockHistogram(temp_storage).InitHistogram(smem_histogram); + * + * // Update the block-wide histogram + * BlockHistogram(temp_storage).Composite(thread_samples, smem_histogram); + * + * \endcode + * + * \tparam CounterT [inferred] Histogram counter type + */ + template + __device__ __forceinline__ void InitHistogram(CounterT histogram[BINS]) + { + // Initialize histogram bin counts to zeros + int histo_offset = 0; + + #pragma unroll + for(; histo_offset + BLOCK_THREADS <= BINS; histo_offset += BLOCK_THREADS) + { + histogram[histo_offset + linear_tid] = 0; + } + // Finish up with guarded initialization if necessary + if ((BINS % BLOCK_THREADS != 0) && (histo_offset + linear_tid < BINS)) + { + histogram[histo_offset + linear_tid] = 0; + } + } + + + /** + * \brief Constructs a block-wide histogram in shared/device-accessible memory. Each thread contributes an array of input elements. + * + * \par + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a 256-bin histogram of 512 integer samples that + * are partitioned across 128 threads where each thread owns 4 samples. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize a 256-bin BlockHistogram type for a 1D block of 128 threads having 4 character samples each + * typedef cub::BlockHistogram BlockHistogram; + * + * // Allocate shared memory for BlockHistogram + * __shared__ typename BlockHistogram::TempStorage temp_storage; + * + * // Allocate shared memory for block-wide histogram bin counts + * __shared__ unsigned int smem_histogram[256]; + * + * // Obtain input samples per thread + * unsigned char thread_samples[4]; + * ... + * + * // Compute the block-wide histogram + * BlockHistogram(temp_storage).Histogram(thread_samples, smem_histogram); + * + * \endcode + * + * \tparam CounterT [inferred] Histogram counter type + */ + template < + typename CounterT > + __device__ __forceinline__ void Histogram( + T (&items)[ITEMS_PER_THREAD], ///< [in] Calling thread's input values to histogram + CounterT histogram[BINS]) ///< [out] Reference to shared/device-accessible memory histogram + { + // Initialize histogram bin counts to zeros + InitHistogram(histogram); + + CTA_SYNC(); + + // Composite the histogram + InternalBlockHistogram(temp_storage).Composite(items, histogram); + } + + + + /** + * \brief Updates an existing block-wide histogram in shared/device-accessible memory. Each thread composites an array of input elements. + * + * \par + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a the initialization and update of a + * histogram of 512 integer samples that are partitioned across 128 threads + * where each thread owns 4 samples. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize a 256-bin BlockHistogram type for a 1D block of 128 threads having 4 character samples each + * typedef cub::BlockHistogram BlockHistogram; + * + * // Allocate shared memory for BlockHistogram + * __shared__ typename BlockHistogram::TempStorage temp_storage; + * + * // Allocate shared memory for block-wide histogram bin counts + * __shared__ unsigned int smem_histogram[256]; + * + * // Obtain input samples per thread + * unsigned char thread_samples[4]; + * ... + * + * // Initialize the block-wide histogram + * BlockHistogram(temp_storage).InitHistogram(smem_histogram); + * + * // Update the block-wide histogram + * BlockHistogram(temp_storage).Composite(thread_samples, smem_histogram); + * + * \endcode + * + * \tparam CounterT [inferred] Histogram counter type + */ + template < + typename CounterT > + __device__ __forceinline__ void Composite( + T (&items)[ITEMS_PER_THREAD], ///< [in] Calling thread's input values to histogram + CounterT histogram[BINS]) ///< [out] Reference to shared/device-accessible memory histogram + { + InternalBlockHistogram(temp_storage).Composite(items, histogram); + } + +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_load.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_load.cuh new file mode 100644 index 0000000000000000000000000000000000000000..b419ab6e726cdc4a77992a1b1fde3bc52a00d4a0 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_load.cuh @@ -0,0 +1,1306 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2016, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Operations for reading linear tiles of data into the CUDA thread block. + */ + +#pragma once + +#include +#include + +#include "../block/block_exchange.cuh" +#include "../iterator/cache_modified_input_iterator.cuh" +#include "../config.cuh" +#include "../util_ptx.cuh" +#include "../util_type.cuh" + +CUB_NAMESPACE_BEGIN + +/** + * \addtogroup UtilIo + * @{ + */ + + +/******************************************************************//** + * \name Blocked arrangement I/O (direct) + *********************************************************************/ +//@{ + + +/** + * \brief Load a linear segment of items into a blocked arrangement across the thread block. + * + * \blocked + * + * \tparam T [inferred] The data type to load. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam InputIteratorT [inferred] The random-access iterator type for input \iterator. + */ +template < + typename InputT, + int ITEMS_PER_THREAD, + typename InputIteratorT> +__device__ __forceinline__ void LoadDirectBlocked( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load +{ + // Load directly in thread-blocked order + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + items[ITEM] = block_itr[(linear_tid * ITEMS_PER_THREAD) + ITEM]; + } +} + + +/** + * \brief Load a linear segment of items into a blocked arrangement across the thread block, guarded by range. + * + * \blocked + * + * \tparam T [inferred] The data type to load. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam InputIteratorT [inferred] The random-access iterator type for input \iterator. + */ +template < + typename InputT, + int ITEMS_PER_THREAD, + typename InputIteratorT> +__device__ __forceinline__ void LoadDirectBlocked( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items) ///< [in] Number of valid items to load +{ + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + if ((linear_tid * ITEMS_PER_THREAD) + ITEM < valid_items) + { + items[ITEM] = block_itr[(linear_tid * ITEMS_PER_THREAD) + ITEM]; + } + } +} + + +/** + * \brief Load a linear segment of items into a blocked arrangement across the thread block, guarded by range, with a fall-back assignment of out-of-bound elements.. + * + * \blocked + * + * \tparam T [inferred] The data type to load. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam InputIteratorT [inferred] The random-access iterator type for input \iterator. + */ +template < + typename InputT, + typename DefaultT, + int ITEMS_PER_THREAD, + typename InputIteratorT> +__device__ __forceinline__ void LoadDirectBlocked( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items, ///< [in] Number of valid items to load + DefaultT oob_default) ///< [in] Default value to assign out-of-bound items +{ + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + items[ITEM] = oob_default; + + LoadDirectBlocked(linear_tid, block_itr, items, valid_items); +} + + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + +/** + * Internal implementation for load vectorization + */ +template < + CacheLoadModifier MODIFIER, + typename T, + int ITEMS_PER_THREAD> +__device__ __forceinline__ void InternalLoadDirectBlockedVectorized( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + T *block_ptr, ///< [in] Input pointer for loading from + T (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load +{ + // Biggest memory access word that T is a whole multiple of + typedef typename UnitWord::DeviceWord DeviceWord; + + enum + { + TOTAL_WORDS = sizeof(items) / sizeof(DeviceWord), + + VECTOR_SIZE = (TOTAL_WORDS % 4 == 0) ? + 4 : + (TOTAL_WORDS % 2 == 0) ? + 2 : + 1, + + VECTORS_PER_THREAD = TOTAL_WORDS / VECTOR_SIZE, + }; + + // Vector type + typedef typename CubVector::Type Vector; + + // Vector items + Vector vec_items[VECTORS_PER_THREAD]; + + // Aliased input ptr + Vector* vec_ptr = reinterpret_cast(block_ptr) + (linear_tid * VECTORS_PER_THREAD); + + // Load directly in thread-blocked order + #pragma unroll + for (int ITEM = 0; ITEM < VECTORS_PER_THREAD; ITEM++) + { + vec_items[ITEM] = ThreadLoad(vec_ptr + ITEM); + } + + // Copy + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + items[ITEM] = *(reinterpret_cast(vec_items) + ITEM); + } +} + +#endif // DOXYGEN_SHOULD_SKIP_THIS + + +/** + * \brief Load a linear segment of items into a blocked arrangement across the thread block. + * + * \blocked + * + * The input offset (\p block_ptr + \p block_offset) must be quad-item aligned + * + * The following conditions will prevent vectorization and loading will fall back to cub::BLOCK_LOAD_DIRECT: + * - \p ITEMS_PER_THREAD is odd + * - The data type \p T is not a built-in primitive or CUDA vector type (e.g., \p short, \p int2, \p double, \p float2, etc.) + * + * \tparam T [inferred] The data type to load. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + */ +template < + typename T, + int ITEMS_PER_THREAD> +__device__ __forceinline__ void LoadDirectBlockedVectorized( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + T *block_ptr, ///< [in] Input pointer for loading from + T (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load +{ + InternalLoadDirectBlockedVectorized(linear_tid, block_ptr, items); +} + + +//@} end member group +/******************************************************************//** + * \name Striped arrangement I/O (direct) + *********************************************************************/ +//@{ + + +/** + * \brief Load a linear segment of items into a striped arrangement across the thread block. + * + * \striped + * + * \tparam BLOCK_THREADS The thread block size in threads + * \tparam T [inferred] The data type to load. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam InputIteratorT [inferred] The random-access iterator type for input \iterator. + */ +template < + int BLOCK_THREADS, + typename InputT, + int ITEMS_PER_THREAD, + typename InputIteratorT> +__device__ __forceinline__ void LoadDirectStriped( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load +{ + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + items[ITEM] = block_itr[linear_tid + ITEM * BLOCK_THREADS]; + } +} + + +/** + * \brief Load a linear segment of items into a striped arrangement across the thread block, guarded by range + * + * \striped + * + * \tparam BLOCK_THREADS The thread block size in threads + * \tparam T [inferred] The data type to load. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam InputIteratorT [inferred] The random-access iterator type for input \iterator. + */ +template < + int BLOCK_THREADS, + typename InputT, + int ITEMS_PER_THREAD, + typename InputIteratorT> +__device__ __forceinline__ void LoadDirectStriped( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items) ///< [in] Number of valid items to load +{ + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + if (linear_tid + (ITEM * BLOCK_THREADS) < valid_items) + { + items[ITEM] = block_itr[linear_tid + ITEM * BLOCK_THREADS]; + } + } +} + + +/** + * \brief Load a linear segment of items into a striped arrangement across the thread block, guarded by range, with a fall-back assignment of out-of-bound elements. + * + * \striped + * + * \tparam BLOCK_THREADS The thread block size in threads + * \tparam T [inferred] The data type to load. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam InputIteratorT [inferred] The random-access iterator type for input \iterator. + */ +template < + int BLOCK_THREADS, + typename InputT, + typename DefaultT, + int ITEMS_PER_THREAD, + typename InputIteratorT> +__device__ __forceinline__ void LoadDirectStriped( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items, ///< [in] Number of valid items to load + DefaultT oob_default) ///< [in] Default value to assign out-of-bound items +{ + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + items[ITEM] = oob_default; + + LoadDirectStriped(linear_tid, block_itr, items, valid_items); +} + + + +//@} end member group +/******************************************************************//** + * \name Warp-striped arrangement I/O (direct) + *********************************************************************/ +//@{ + + +/** + * \brief Load a linear segment of items into a warp-striped arrangement across the thread block. + * + * \warpstriped + * + * \par Usage Considerations + * The number of threads in the thread block must be a multiple of the architecture's warp size. + * + * \tparam T [inferred] The data type to load. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam InputIteratorT [inferred] The random-access iterator type for input \iterator. + */ +template < + typename InputT, + int ITEMS_PER_THREAD, + typename InputIteratorT> +__device__ __forceinline__ void LoadDirectWarpStriped( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load +{ + int tid = linear_tid & (CUB_PTX_WARP_THREADS - 1); + int wid = linear_tid >> CUB_PTX_LOG_WARP_THREADS; + int warp_offset = wid * CUB_PTX_WARP_THREADS * ITEMS_PER_THREAD; + + // Load directly in warp-striped order + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + new(&items[ITEM]) InputT(block_itr[warp_offset + tid + (ITEM * CUB_PTX_WARP_THREADS)]); + } +} + + +/** + * \brief Load a linear segment of items into a warp-striped arrangement across the thread block, guarded by range + * + * \warpstriped + * + * \par Usage Considerations + * The number of threads in the thread block must be a multiple of the architecture's warp size. + * + * \tparam T [inferred] The data type to load. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam InputIteratorT [inferred] The random-access iterator type for input \iterator. + */ +template < + typename InputT, + int ITEMS_PER_THREAD, + typename InputIteratorT> +__device__ __forceinline__ void LoadDirectWarpStriped( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items) ///< [in] Number of valid items to load +{ + int tid = linear_tid & (CUB_PTX_WARP_THREADS - 1); + int wid = linear_tid >> CUB_PTX_LOG_WARP_THREADS; + int warp_offset = wid * CUB_PTX_WARP_THREADS * ITEMS_PER_THREAD; + + // Load directly in warp-striped order + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + if (warp_offset + tid + (ITEM * CUB_PTX_WARP_THREADS) < valid_items) + { + new(&items[ITEM]) InputT(block_itr[warp_offset + tid + (ITEM * CUB_PTX_WARP_THREADS)]); + } + } +} + + +/** + * \brief Load a linear segment of items into a warp-striped arrangement across the thread block, guarded by range, with a fall-back assignment of out-of-bound elements. + * + * \warpstriped + * + * \par Usage Considerations + * The number of threads in the thread block must be a multiple of the architecture's warp size. + * + * \tparam T [inferred] The data type to load. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam InputIteratorT [inferred] The random-access iterator type for input \iterator. + */ +template < + typename InputT, + typename DefaultT, + int ITEMS_PER_THREAD, + typename InputIteratorT> +__device__ __forceinline__ void LoadDirectWarpStriped( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items, ///< [in] Number of valid items to load + DefaultT oob_default) ///< [in] Default value to assign out-of-bound items +{ + // Load directly in warp-striped order + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + items[ITEM] = oob_default; + + LoadDirectWarpStriped(linear_tid, block_itr, items, valid_items); +} + + + +//@} end member group + +/** @} */ // end group UtilIo + + + +//----------------------------------------------------------------------------- +// Generic BlockLoad abstraction +//----------------------------------------------------------------------------- + +/** + * \brief cub::BlockLoadAlgorithm enumerates alternative algorithms for cub::BlockLoad to read a linear segment of data from memory into a blocked arrangement across a CUDA thread block. + */ +enum BlockLoadAlgorithm +{ + /** + * \par Overview + * + * A [blocked arrangement](index.html#sec5sec3) of data is read + * directly from memory. + * + * \par Performance Considerations + * The utilization of memory transactions (coalescing) decreases as the + * access stride between threads increases (i.e., the number items per thread). + */ + BLOCK_LOAD_DIRECT, + + /** + * \par Overview + * + * A [striped arrangement](index.html#sec5sec3) of data is read + * directly from memory. + * + * \par Performance Considerations + * The utilization of memory transactions (coalescing) doesn't depend on + * the number of items per thread. + */ + BLOCK_LOAD_STRIPED, + + /** + * \par Overview + * + * A [blocked arrangement](index.html#sec5sec3) of data is read + * from memory using CUDA's built-in vectorized loads as a coalescing optimization. + * For example, ld.global.v4.s32 instructions will be generated + * when \p T = \p int and \p ITEMS_PER_THREAD % 4 == 0. + * + * \par Performance Considerations + * - The utilization of memory transactions (coalescing) remains high until the the + * access stride between threads (i.e., the number items per thread) exceeds the + * maximum vector load width (typically 4 items or 64B, whichever is lower). + * - The following conditions will prevent vectorization and loading will fall + * back to cub::BLOCK_LOAD_DIRECT: + * - \p ITEMS_PER_THREAD is odd + * - The \p InputIteratorT is not a simple pointer type + * - The block input offset is not quadword-aligned + * - The data type \p T is not a built-in primitive or CUDA vector type + * (e.g., \p short, \p int2, \p double, \p float2, etc.) + */ + BLOCK_LOAD_VECTORIZE, + + /** + * \par Overview + * + * A [striped arrangement](index.html#sec5sec3) of data is read + * efficiently from memory and then locally transposed into a + * [blocked arrangement](index.html#sec5sec3). + * + * \par Performance Considerations + * - The utilization of memory transactions (coalescing) remains high regardless + * of items loaded per thread. + * - The local reordering incurs slightly longer latencies and throughput than the + * direct cub::BLOCK_LOAD_DIRECT and cub::BLOCK_LOAD_VECTORIZE alternatives. + */ + BLOCK_LOAD_TRANSPOSE, + + /** + * \par Overview + * + * A [warp-striped arrangement](index.html#sec5sec3) of data is + * read efficiently from memory and then locally transposed into a + * [blocked arrangement](index.html#sec5sec3). + * + * \par Usage Considerations + * - BLOCK_THREADS must be a multiple of WARP_THREADS + * + * \par Performance Considerations + * - The utilization of memory transactions (coalescing) remains high regardless + * of items loaded per thread. + * - The local reordering incurs slightly larger latencies than the + * direct cub::BLOCK_LOAD_DIRECT and cub::BLOCK_LOAD_VECTORIZE alternatives. + * - Provisions more shared storage, but incurs smaller latencies than the + * BLOCK_LOAD_WARP_TRANSPOSE_TIMESLICED alternative. + */ + BLOCK_LOAD_WARP_TRANSPOSE, + + /** + * \par Overview + * + * Like \p BLOCK_LOAD_WARP_TRANSPOSE, a [warp-striped arrangement](index.html#sec5sec3) + * of data is read directly from memory and then is locally transposed into a + * [blocked arrangement](index.html#sec5sec3). To reduce the shared memory + * requirement, only one warp's worth of shared memory is provisioned and is + * subsequently time-sliced among warps. + * + * \par Usage Considerations + * - BLOCK_THREADS must be a multiple of WARP_THREADS + * + * \par Performance Considerations + * - The utilization of memory transactions (coalescing) remains high regardless + * of items loaded per thread. + * - Provisions less shared memory temporary storage, but incurs larger + * latencies than the BLOCK_LOAD_WARP_TRANSPOSE alternative. + */ + BLOCK_LOAD_WARP_TRANSPOSE_TIMESLICED, +}; + + +/** + * \brief The BlockLoad class provides [collective](index.html#sec0) data movement methods for loading a linear segment of items from memory into a [blocked arrangement](index.html#sec5sec3) across a CUDA thread block. ![](block_load_logo.png) + * \ingroup BlockModule + * \ingroup UtilIo + * + * \tparam InputT The data type to read into (which must be convertible from the input iterator's value type). + * \tparam BLOCK_DIM_X The thread block length in threads along the X dimension + * \tparam ITEMS_PER_THREAD The number of consecutive items partitioned onto each thread. + * \tparam ALGORITHM [optional] cub::BlockLoadAlgorithm tuning policy. default: cub::BLOCK_LOAD_DIRECT. + * \tparam WARP_TIME_SLICING [optional] Whether or not only one warp's worth of shared memory should be allocated and time-sliced among block-warps during any load-related data transpositions (versus each warp having its own storage). (default: false) + * \tparam BLOCK_DIM_Y [optional] The thread block length in threads along the Y dimension (default: 1) + * \tparam BLOCK_DIM_Z [optional] The thread block length in threads along the Z dimension (default: 1) + * \tparam LEGACY_PTX_ARCH [optional] Unused. + * + * \par Overview + * - The BlockLoad class provides a single data movement abstraction that can be specialized + * to implement different cub::BlockLoadAlgorithm strategies. This facilitates different + * performance policies for different architectures, data types, granularity sizes, etc. + * - BlockLoad can be optionally specialized by different data movement strategies: + * -# cub::BLOCK_LOAD_DIRECT. A [blocked arrangement](index.html#sec5sec3) + * of data is read directly from memory. [More...](\ref cub::BlockLoadAlgorithm) +* -# cub::BLOCK_LOAD_STRIPED,. A [striped arrangement](index.html#sec5sec3) + * of data is read directly from memory. [More...](\ref cub::BlockLoadAlgorithm) + * -# cub::BLOCK_LOAD_VECTORIZE. A [blocked arrangement](index.html#sec5sec3) + * of data is read directly from memory using CUDA's built-in vectorized loads as a + * coalescing optimization. [More...](\ref cub::BlockLoadAlgorithm) + * -# cub::BLOCK_LOAD_TRANSPOSE. A [striped arrangement](index.html#sec5sec3) + * of data is read directly from memory and is then locally transposed into a + * [blocked arrangement](index.html#sec5sec3). [More...](\ref cub::BlockLoadAlgorithm) + * -# cub::BLOCK_LOAD_WARP_TRANSPOSE. A [warp-striped arrangement](index.html#sec5sec3) + * of data is read directly from memory and is then locally transposed into a + * [blocked arrangement](index.html#sec5sec3). [More...](\ref cub::BlockLoadAlgorithm) + * -# cub::BLOCK_LOAD_WARP_TRANSPOSE_TIMESLICED,. A [warp-striped arrangement](index.html#sec5sec3) + * of data is read directly from memory and is then locally transposed into a + * [blocked arrangement](index.html#sec5sec3) one warp at a time. [More...](\ref cub::BlockLoadAlgorithm) + * - \rowmajor + * + * \par A Simple Example + * \blockcollective{BlockLoad} + * \par + * The code snippet below illustrates the loading of a linear + * segment of 512 integers into a "blocked" arrangement across 128 threads where each + * thread owns 4 consecutive items. The load is specialized for \p BLOCK_LOAD_WARP_TRANSPOSE, + * meaning memory references are efficiently coalesced using a warp-striped access + * pattern (after which items are locally reordered among threads). + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * // Specialize BlockLoad for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockLoad BlockLoad; + * + * // Allocate shared memory for BlockLoad + * __shared__ typename BlockLoad::TempStorage temp_storage; + * + * // Load a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * BlockLoad(temp_storage).Load(d_data, thread_data); + * + * \endcode + * \par + * Suppose the input \p d_data is 0, 1, 2, 3, 4, 5, .... + * The set of \p thread_data across the block of threads in those threads will be + * { [0,1,2,3], [4,5,6,7], ..., [508,509,510,511] }. + * + * \par Re-using dynamically allocating shared memory + * The following example under the examples/block folder illustrates usage of + * dynamically shared memory with BlockReduce and how to re-purpose + * the same memory region: + * example_block_reduce_dyn_smem.cu + * + * This example can be easily adapted to the storage required by BlockLoad. + */ +template < + typename InputT, + int BLOCK_DIM_X, + int ITEMS_PER_THREAD, + BlockLoadAlgorithm ALGORITHM = BLOCK_LOAD_DIRECT, + int BLOCK_DIM_Y = 1, + int BLOCK_DIM_Z = 1, + int LEGACY_PTX_ARCH = 0> +class BlockLoad +{ +private: + + /****************************************************************************** + * Constants and typed definitions + ******************************************************************************/ + + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + }; + + + /****************************************************************************** + * Algorithmic variants + ******************************************************************************/ + + /// Load helper + template + struct LoadInternal; + + + /** + * BLOCK_LOAD_DIRECT specialization of load helper + */ + template + struct LoadInternal + { + /// Shared memory storage layout type + typedef NullType TempStorage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ LoadInternal( + TempStorage &/*temp_storage*/, + int linear_tid) + : + linear_tid(linear_tid) + {} + + /// Load a linear segment of items from memory + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load + { + LoadDirectBlocked(linear_tid, block_itr, items); + } + + /// Load a linear segment of items from memory, guarded by range + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items) ///< [in] Number of valid items to load + { + LoadDirectBlocked(linear_tid, block_itr, items, valid_items); + } + + /// Load a linear segment of items from memory, guarded by range, with a fall-back assignment of out-of-bound elements + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items, ///< [in] Number of valid items to load + DefaultT oob_default) ///< [in] Default value to assign out-of-bound items + { + LoadDirectBlocked(linear_tid, block_itr, items, valid_items, oob_default); + } + + }; + + + /** + * BLOCK_LOAD_STRIPED specialization of load helper + */ + template + struct LoadInternal + { + /// Shared memory storage layout type + typedef NullType TempStorage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ LoadInternal( + TempStorage &/*temp_storage*/, + int linear_tid) + : + linear_tid(linear_tid) + {} + + /// Load a linear segment of items from memory + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load + { + LoadDirectStriped(linear_tid, block_itr, items); + } + + /// Load a linear segment of items from memory, guarded by range + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items) ///< [in] Number of valid items to load + { + LoadDirectStriped(linear_tid, block_itr, items, valid_items); + } + + /// Load a linear segment of items from memory, guarded by range, with a fall-back assignment of out-of-bound elements + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items, ///< [in] Number of valid items to load + DefaultT oob_default) ///< [in] Default value to assign out-of-bound items + { + LoadDirectStriped(linear_tid, block_itr, items, valid_items, oob_default); + } + + }; + + + /** + * BLOCK_LOAD_VECTORIZE specialization of load helper + */ + template + struct LoadInternal + { + /// Shared memory storage layout type + typedef NullType TempStorage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ LoadInternal( + TempStorage &/*temp_storage*/, + int linear_tid) + : + linear_tid(linear_tid) + {} + + /// Load a linear segment of items from memory, specialized for native pointer types (attempts vectorization) + template + __device__ __forceinline__ void Load( + InputT *block_ptr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load + { + InternalLoadDirectBlockedVectorized(linear_tid, block_ptr, items); + } + + /// Load a linear segment of items from memory, specialized for native pointer types (attempts vectorization) + template + __device__ __forceinline__ void Load( + const InputT *block_ptr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load + { + InternalLoadDirectBlockedVectorized(linear_tid, block_ptr, items); + } + + /// Load a linear segment of items from memory, specialized for native pointer types (attempts vectorization) + template < + CacheLoadModifier MODIFIER, + typename ValueType, + typename OffsetT> + __device__ __forceinline__ void Load( + CacheModifiedInputIterator block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load + { + InternalLoadDirectBlockedVectorized(linear_tid, block_itr.ptr, items); + } + + /// Load a linear segment of items from memory, specialized for opaque input iterators (skips vectorization) + template + __device__ __forceinline__ void Load( + _InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load + { + LoadDirectBlocked(linear_tid, block_itr, items); + } + + /// Load a linear segment of items from memory, guarded by range (skips vectorization) + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items) ///< [in] Number of valid items to load + { + LoadDirectBlocked(linear_tid, block_itr, items, valid_items); + } + + /// Load a linear segment of items from memory, guarded by range, with a fall-back assignment of out-of-bound elements (skips vectorization) + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items, ///< [in] Number of valid items to load + DefaultT oob_default) ///< [in] Default value to assign out-of-bound items + { + LoadDirectBlocked(linear_tid, block_itr, items, valid_items, oob_default); + } + + }; + + + /** + * BLOCK_LOAD_TRANSPOSE specialization of load helper + */ + template + struct LoadInternal + { + // BlockExchange utility type for keys + typedef BlockExchange BlockExchange; + + /// Shared memory storage layout type + struct _TempStorage : BlockExchange::TempStorage + {}; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + /// Thread reference to shared storage + _TempStorage &temp_storage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ LoadInternal( + TempStorage &temp_storage, + int linear_tid) + : + temp_storage(temp_storage.Alias()), + linear_tid(linear_tid) + {} + + /// Load a linear segment of items from memory + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load{ + { + LoadDirectStriped(linear_tid, block_itr, items); + BlockExchange(temp_storage).StripedToBlocked(items, items); + } + + /// Load a linear segment of items from memory, guarded by range + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items) ///< [in] Number of valid items to load + { + LoadDirectStriped(linear_tid, block_itr, items, valid_items); + BlockExchange(temp_storage).StripedToBlocked(items, items); + } + + /// Load a linear segment of items from memory, guarded by range, with a fall-back assignment of out-of-bound elements + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items, ///< [in] Number of valid items to load + DefaultT oob_default) ///< [in] Default value to assign out-of-bound items + { + LoadDirectStriped(linear_tid, block_itr, items, valid_items, oob_default); + BlockExchange(temp_storage).StripedToBlocked(items, items); + } + + }; + + + /** + * BLOCK_LOAD_WARP_TRANSPOSE specialization of load helper + */ + template + struct LoadInternal + { + enum + { + WARP_THREADS = CUB_WARP_THREADS(0) + }; + + // Assert BLOCK_THREADS must be a multiple of WARP_THREADS + CUB_STATIC_ASSERT((int(BLOCK_THREADS) % int(WARP_THREADS) == 0), "BLOCK_THREADS must be a multiple of WARP_THREADS"); + + // BlockExchange utility type for keys + typedef BlockExchange BlockExchange; + + /// Shared memory storage layout type + struct _TempStorage : BlockExchange::TempStorage + {}; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + /// Thread reference to shared storage + _TempStorage &temp_storage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ LoadInternal( + TempStorage &temp_storage, + int linear_tid) + : + temp_storage(temp_storage.Alias()), + linear_tid(linear_tid) + {} + + /// Load a linear segment of items from memory + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load{ + { + LoadDirectWarpStriped(linear_tid, block_itr, items); + BlockExchange(temp_storage).WarpStripedToBlocked(items, items); + } + + /// Load a linear segment of items from memory, guarded by range + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items) ///< [in] Number of valid items to load + { + LoadDirectWarpStriped(linear_tid, block_itr, items, valid_items); + BlockExchange(temp_storage).WarpStripedToBlocked(items, items); + } + + + /// Load a linear segment of items from memory, guarded by range, with a fall-back assignment of out-of-bound elements + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items, ///< [in] Number of valid items to load + DefaultT oob_default) ///< [in] Default value to assign out-of-bound items + { + LoadDirectWarpStriped(linear_tid, block_itr, items, valid_items, oob_default); + BlockExchange(temp_storage).WarpStripedToBlocked(items, items); + } + }; + + + /** + * BLOCK_LOAD_WARP_TRANSPOSE_TIMESLICED specialization of load helper + */ + template + struct LoadInternal + { + enum + { + WARP_THREADS = CUB_WARP_THREADS(0) + }; + + // Assert BLOCK_THREADS must be a multiple of WARP_THREADS + CUB_STATIC_ASSERT((int(BLOCK_THREADS) % int(WARP_THREADS) == 0), "BLOCK_THREADS must be a multiple of WARP_THREADS"); + + // BlockExchange utility type for keys + typedef BlockExchange BlockExchange; + + /// Shared memory storage layout type + struct _TempStorage : BlockExchange::TempStorage + {}; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + /// Thread reference to shared storage + _TempStorage &temp_storage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ LoadInternal( + TempStorage &temp_storage, + int linear_tid) + : + temp_storage(temp_storage.Alias()), + linear_tid(linear_tid) + {} + + /// Load a linear segment of items from memory + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load{ + { + LoadDirectWarpStriped(linear_tid, block_itr, items); + BlockExchange(temp_storage).WarpStripedToBlocked(items, items); + } + + /// Load a linear segment of items from memory, guarded by range + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items) ///< [in] Number of valid items to load + { + LoadDirectWarpStriped(linear_tid, block_itr, items, valid_items); + BlockExchange(temp_storage).WarpStripedToBlocked(items, items); + } + + + /// Load a linear segment of items from memory, guarded by range, with a fall-back assignment of out-of-bound elements + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items, ///< [in] Number of valid items to load + DefaultT oob_default) ///< [in] Default value to assign out-of-bound items + { + LoadDirectWarpStriped(linear_tid, block_itr, items, valid_items, oob_default); + BlockExchange(temp_storage).WarpStripedToBlocked(items, items); + } + }; + + + /****************************************************************************** + * Type definitions + ******************************************************************************/ + + /// Internal load implementation to use + typedef LoadInternal InternalLoad; + + + /// Shared memory storage layout type + typedef typename InternalLoad::TempStorage _TempStorage; + + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Thread reference to shared storage + _TempStorage &temp_storage; + + /// Linear thread-id + int linear_tid; + +public: + + /// \smemstorage{BlockLoad} + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /******************************************************************//** + * \name Collective constructors + *********************************************************************/ + //@{ + + /** + * \brief Collective constructor using a private static allocation of shared memory as temporary storage. + */ + __device__ __forceinline__ BlockLoad() + : + temp_storage(PrivateStorage()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + /** + * \brief Collective constructor using the specified memory allocation as temporary storage. + */ + __device__ __forceinline__ BlockLoad( + TempStorage &temp_storage) ///< [in] Reference to memory allocation having layout type TempStorage + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + + + //@} end member group + /******************************************************************//** + * \name Data movement + *********************************************************************/ + //@{ + + + /** + * \brief Load a linear segment of items from memory. + * + * \par + * - \blocked + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the loading of a linear + * segment of 512 integers into a "blocked" arrangement across 128 threads where each + * thread owns 4 consecutive items. The load is specialized for \p BLOCK_LOAD_WARP_TRANSPOSE, + * meaning memory references are efficiently coalesced using a warp-striped access + * pattern (after which items are locally reordered among threads). + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * // Specialize BlockLoad for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockLoad BlockLoad; + * + * // Allocate shared memory for BlockLoad + * __shared__ typename BlockLoad::TempStorage temp_storage; + * + * // Load a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * BlockLoad(temp_storage).Load(d_data, thread_data); + * + * \endcode + * \par + * Suppose the input \p d_data is 0, 1, 2, 3, 4, 5, .... + * The set of \p thread_data across the block of threads in those threads will be + * { [0,1,2,3], [4,5,6,7], ..., [508,509,510,511] }. + * + */ + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load + { + InternalLoad(temp_storage, linear_tid).Load(block_itr, items); + } + + + /** + * \brief Load a linear segment of items from memory, guarded by range. + * + * \par + * - \blocked + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the guarded loading of a linear + * segment of 512 integers into a "blocked" arrangement across 128 threads where each + * thread owns 4 consecutive items. The load is specialized for \p BLOCK_LOAD_WARP_TRANSPOSE, + * meaning memory references are efficiently coalesced using a warp-striped access + * pattern (after which items are locally reordered among threads). + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, int valid_items, ...) + * { + * // Specialize BlockLoad for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockLoad BlockLoad; + * + * // Allocate shared memory for BlockLoad + * __shared__ typename BlockLoad::TempStorage temp_storage; + * + * // Load a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * BlockLoad(temp_storage).Load(d_data, thread_data, valid_items); + * + * \endcode + * \par + * Suppose the input \p d_data is 0, 1, 2, 3, 4, 5, 6... and \p valid_items is \p 5. + * The set of \p thread_data across the block of threads in those threads will be + * { [0,1,2,3], [4,?,?,?], ..., [?,?,?,?] }, with only the first two threads + * being unmasked to load portions of valid data (and other items remaining unassigned). + * + */ + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items) ///< [in] Number of valid items to load + { + InternalLoad(temp_storage, linear_tid).Load(block_itr, items, valid_items); + } + + + /** + * \brief Load a linear segment of items from memory, guarded by range, with a fall-back assignment of out-of-bound elements + * + * \par + * - \blocked + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the guarded loading of a linear + * segment of 512 integers into a "blocked" arrangement across 128 threads where each + * thread owns 4 consecutive items. The load is specialized for \p BLOCK_LOAD_WARP_TRANSPOSE, + * meaning memory references are efficiently coalesced using a warp-striped access + * pattern (after which items are locally reordered among threads). + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, int valid_items, ...) + * { + * // Specialize BlockLoad for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockLoad BlockLoad; + * + * // Allocate shared memory for BlockLoad + * __shared__ typename BlockLoad::TempStorage temp_storage; + * + * // Load a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * BlockLoad(temp_storage).Load(d_data, thread_data, valid_items, -1); + * + * \endcode + * \par + * Suppose the input \p d_data is 0, 1, 2, 3, 4, 5, 6..., + * \p valid_items is \p 5, and the out-of-bounds default is \p -1. + * The set of \p thread_data across the block of threads in those threads will be + * { [0,1,2,3], [4,-1,-1,-1], ..., [-1,-1,-1,-1] }, with only the first two threads + * being unmasked to load portions of valid data (and other items are assigned \p -1) + * + */ + template + __device__ __forceinline__ void Load( + InputIteratorT block_itr, ///< [in] The thread block's base input iterator for loading from + InputT (&items)[ITEMS_PER_THREAD], ///< [out] Data to load + int valid_items, ///< [in] Number of valid items to load + DefaultT oob_default) ///< [in] Default value to assign out-of-bound items + { + InternalLoad(temp_storage, linear_tid).Load(block_itr, items, valid_items, oob_default); + } + + + //@} end member group + +}; + +template > +struct BlockLoadType +{ + using type = cub::BlockLoad; +}; + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_merge_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_merge_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..dc07ef6c294352899b22ad5682dc82fe92d46b2b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_merge_sort.cuh @@ -0,0 +1,804 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include + + +CUB_NAMESPACE_BEGIN + + +// Additional details of the Merge-Path Algorithm can be found in: +// S. Odeh, O. Green, Z. Mwassi, O. Shmueli, Y. Birk, " Merge Path - Parallel +// Merging Made Simple", Multithreaded Architectures and Applications (MTAAP) +// Workshop, IEEE 26th International Parallel & Distributed Processing +// Symposium (IPDPS), 2012 +template +__device__ __forceinline__ OffsetT MergePath(KeyIteratorT keys1, + KeyIteratorT keys2, + OffsetT keys1_count, + OffsetT keys2_count, + OffsetT diag, + BinaryPred binary_pred) +{ + OffsetT keys1_begin = diag < keys2_count ? 0 : diag - keys2_count; + OffsetT keys1_end = (cub::min)(diag, keys1_count); + + while (keys1_begin < keys1_end) + { + OffsetT mid = cub::MidPoint(keys1_begin, keys1_end); + KeyT key1 = keys1[mid]; + KeyT key2 = keys2[diag - 1 - mid]; + bool pred = binary_pred(key2, key1); + + if (pred) + { + keys1_end = mid; + } + else + { + keys1_begin = mid + 1; + } + } + return keys1_begin; +} + +template +__device__ __forceinline__ void SerialMerge(KeyT *keys_shared, + int keys1_beg, + int keys2_beg, + int keys1_count, + int keys2_count, + KeyT (&output)[ITEMS_PER_THREAD], + int (&indices)[ITEMS_PER_THREAD], + CompareOp compare_op) +{ + int keys1_end = keys1_beg + keys1_count; + int keys2_end = keys2_beg + keys2_count; + + KeyT key1 = keys_shared[keys1_beg]; + KeyT key2 = keys_shared[keys2_beg]; + +#pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD; ++item) + { + bool p = (keys2_beg < keys2_end) && + ((keys1_beg >= keys1_end) + || compare_op(key2, key1)); + + output[item] = p ? key2 : key1; + indices[item] = p ? keys2_beg++ : keys1_beg++; + + if (p) + { + key2 = keys_shared[keys2_beg]; + } + else + { + key1 = keys_shared[keys1_beg]; + } + } +} + +/** + * @brief Generalized merge sort algorithm + * + * This class is used to reduce code duplication. Warp and Block merge sort + * differ only in how they compute thread index and how they synchronize + * threads. Since synchronization might require access to custom data + * (like member mask), CRTP is used. + * + * @par + * The code snippet below illustrates the way this class can be used. + * @par + * @code + * #include // or equivalently + * + * constexpr int BLOCK_THREADS = 256; + * constexpr int ITEMS_PER_THREAD = 9; + * + * class BlockMergeSort : public BlockMergeSortStrategy + * { + * using BlockMergeSortStrategyT = + * BlockMergeSortStrategy; + * public: + * __device__ __forceinline__ explicit BlockMergeSort( + * typename BlockMergeSortStrategyT::TempStorage &temp_storage) + * : BlockMergeSortStrategyT(temp_storage, threadIdx.x) + * {} + * + * __device__ __forceinline__ void SyncImplementation() const + * { + * __syncthreads(); + * } + * }; + * @endcode + * + * @tparam KeyT + * KeyT type + * + * @tparam ValueT + * ValueT type. cub::NullType indicates a keys-only sort + * + * @tparam SynchronizationPolicy + * Provides a way of synchronizing threads. Should be derived from + * `BlockMergeSortStrategy`. + */ +template +class BlockMergeSortStrategy +{ + static_assert(PowerOfTwo::VALUE, + "NUM_THREADS must be a power of two"); + +private: + + static constexpr int ITEMS_PER_TILE = ITEMS_PER_THREAD * NUM_THREADS; + + // Whether or not there are values to be trucked along with keys + static constexpr bool KEYS_ONLY = std::is_same::value; + + /// Shared memory type required by this thread block + union _TempStorage + { + KeyT keys_shared[ITEMS_PER_TILE + 1]; + ValueT items_shared[ITEMS_PER_TILE + 1]; + }; // union TempStorage + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + const unsigned int linear_tid; + +public: + /// \smemstorage{BlockMergeSort} + struct TempStorage : Uninitialized<_TempStorage> {}; + + BlockMergeSortStrategy() = delete; + explicit __device__ __forceinline__ + BlockMergeSortStrategy(unsigned int linear_tid) + : temp_storage(PrivateStorage()) + , linear_tid(linear_tid) + {} + + __device__ __forceinline__ BlockMergeSortStrategy(TempStorage &temp_storage, + unsigned int linear_tid) + : temp_storage(temp_storage.Alias()) + , linear_tid(linear_tid) + {} + + __device__ __forceinline__ unsigned int get_linear_tid() const + { + return linear_tid; + } + + /** + * @brief Sorts items partitioned across a CUDA thread block using + * a merge sorting method. + * + * @par + * Sort is not guaranteed to be stable. That is, suppose that i and j are + * equivalent: neither one is less than the other. It is not guaranteed + * that the relative order of these two elements will be preserved by sort. + * + * @tparam CompareOp + * functor type having member `bool operator()(KeyT lhs, KeyT rhs)`. + * `CompareOp` is a model of [Strict Weak Ordering]. + * + * @param[in,out] keys + * Keys to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + */ + template + __device__ __forceinline__ void Sort(KeyT (&keys)[ITEMS_PER_THREAD], + CompareOp compare_op) + { + ValueT items[ITEMS_PER_THREAD]; + Sort(keys, items, compare_op, ITEMS_PER_TILE, keys[0]); + } + + /** + * @brief Sorts items partitioned across a CUDA thread block using + * a merge sorting method. + * + * @par + * - Sort is not guaranteed to be stable. That is, suppose that `i` and `j` + * are equivalent: neither one is less than the other. It is not guaranteed + * that the relative order of these two elements will be preserved by sort. + * - The value of `oob_default` is assigned to all elements that are out of + * `valid_items` boundaries. It's expected that `oob_default` is ordered + * after any value in the `valid_items` boundaries. The algorithm always + * sorts a fixed amount of elements, which is equal to + * `ITEMS_PER_THREAD * BLOCK_THREADS`. If there is a value that is ordered + * after `oob_default`, it won't be placed within `valid_items` boundaries. + * + * @tparam CompareOp + * functor type having member `bool operator()(KeyT lhs, KeyT rhs)`. + * `CompareOp` is a model of [Strict Weak Ordering]. + * + * @param[in,out] keys + * Keys to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * @param[in] valid_items + * Number of valid items to sort + * + * @param[in] oob_default + * Default value to assign out-of-bound items + * + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + */ + template + __device__ __forceinline__ void Sort(KeyT (&keys)[ITEMS_PER_THREAD], + CompareOp compare_op, + int valid_items, + KeyT oob_default) + { + ValueT items[ITEMS_PER_THREAD]; + Sort(keys, items, compare_op, valid_items, oob_default); + } + + /** + * @brief Sorts items partitioned across a CUDA thread block using a merge sorting method. + * + * @par + * Sort is not guaranteed to be stable. That is, suppose that `i` and `j` are + * equivalent: neither one is less than the other. It is not guaranteed + * that the relative order of these two elements will be preserved by sort. + * + * @tparam CompareOp + * functor type having member `bool operator()(KeyT lhs, KeyT rhs)`. + * `CompareOp` is a model of [Strict Weak Ordering]. + * + * @param[in,out] keys + * Keys to sort + * + * @param[in,out] items + * Values to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + */ + template + __device__ __forceinline__ void Sort(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&items)[ITEMS_PER_THREAD], + CompareOp compare_op) + { + Sort(keys, items, compare_op, ITEMS_PER_TILE, keys[0]); + } + + /** + * @brief Sorts items partitioned across a CUDA thread block using + * a merge sorting method. + * + * @par + * - Sort is not guaranteed to be stable. That is, suppose that `i` and `j` + * are equivalent: neither one is less than the other. It is not guaranteed + * that the relative order of these two elements will be preserved by sort. + * - The value of `oob_default` is assigned to all elements that are out of + * `valid_items` boundaries. It's expected that `oob_default` is ordered + * after any value in the `valid_items` boundaries. The algorithm always + * sorts a fixed amount of elements, which is equal to + * `ITEMS_PER_THREAD * BLOCK_THREADS`. If there is a value that is ordered + * after `oob_default`, it won't be placed within `valid_items` boundaries. + * + * @tparam CompareOp + * functor type having member `bool operator()(KeyT lhs, KeyT rhs)` + * `CompareOp` is a model of [Strict Weak Ordering]. + * + * @tparam IS_LAST_TILE + * True if `valid_items` isn't equal to the `ITEMS_PER_TILE` + * + * @param[in,out] keys + * Keys to sort + * + * @param[in,out] items + * Values to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * @param[in] valid_items + * Number of valid items to sort + * + * @param[in] oob_default + * Default value to assign out-of-bound items + * + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + */ + template + __device__ __forceinline__ void Sort(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&items)[ITEMS_PER_THREAD], + CompareOp compare_op, + int valid_items, + KeyT oob_default) + { + if (IS_LAST_TILE) + { + // if last tile, find valid max_key + // and fill the remaining keys with it + // + KeyT max_key = oob_default; + + #pragma unroll + for (int item = 1; item < ITEMS_PER_THREAD; ++item) + { + if (ITEMS_PER_THREAD * linear_tid + item < valid_items) + { + max_key = compare_op(max_key, keys[item]) ? keys[item] : max_key; + } + else + { + keys[item] = max_key; + } + } + } + + // if first element of thread is in input range, stable sort items + // + if (!IS_LAST_TILE || ITEMS_PER_THREAD * linear_tid < valid_items) + { + StableOddEvenSort(keys, items, compare_op); + } + + // each thread has sorted keys + // merge sort keys in shared memory + // + for (int target_merged_threads_number = 2; + target_merged_threads_number <= NUM_THREADS; + target_merged_threads_number *= 2) + { + int merged_threads_number = target_merged_threads_number / 2; + int mask = target_merged_threads_number - 1; + + Sync(); + + // store keys in shmem + // + #pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD; ++item) + { + int idx = ITEMS_PER_THREAD * linear_tid + item; + temp_storage.keys_shared[idx] = keys[item]; + } + + Sync(); + + int indices[ITEMS_PER_THREAD]; + + int first_thread_idx_in_thread_group_being_merged = ~mask & linear_tid; + int start = ITEMS_PER_THREAD * first_thread_idx_in_thread_group_being_merged; + int size = ITEMS_PER_THREAD * merged_threads_number; + + int thread_idx_in_thread_group_being_merged = mask & linear_tid; + + int diag = + (cub::min)(valid_items, + ITEMS_PER_THREAD * thread_idx_in_thread_group_being_merged); + + int keys1_beg = (cub::min)(valid_items, start); + int keys1_end = (cub::min)(valid_items, keys1_beg + size); + int keys2_beg = keys1_end; + int keys2_end = (cub::min)(valid_items, keys2_beg + size); + + int keys1_count = keys1_end - keys1_beg; + int keys2_count = keys2_end - keys2_beg; + + int partition_diag = MergePath(&temp_storage.keys_shared[keys1_beg], + &temp_storage.keys_shared[keys2_beg], + keys1_count, + keys2_count, + diag, + compare_op); + + int keys1_beg_loc = keys1_beg + partition_diag; + int keys1_end_loc = keys1_end; + int keys2_beg_loc = keys2_beg + diag - partition_diag; + int keys2_end_loc = keys2_end; + int keys1_count_loc = keys1_end_loc - keys1_beg_loc; + int keys2_count_loc = keys2_end_loc - keys2_beg_loc; + SerialMerge(&temp_storage.keys_shared[0], + keys1_beg_loc, + keys2_beg_loc, + keys1_count_loc, + keys2_count_loc, + keys, + indices, + compare_op); + + if (!KEYS_ONLY) + { + Sync(); + + // store keys in shmem + // + #pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD; ++item) + { + int idx = ITEMS_PER_THREAD * linear_tid + item; + temp_storage.items_shared[idx] = items[item]; + } + + Sync(); + + // gather items from shmem + // + #pragma unroll + for (int item = 0; item < ITEMS_PER_THREAD; ++item) + { + items[item] = temp_storage.items_shared[indices[item]]; + } + } + } + } // func block_merge_sort + + /** + * @brief Sorts items partitioned across a CUDA thread block using + * a merge sorting method. + * + * @par + * StableSort is stable: it preserves the relative ordering of equivalent + * elements. That is, if `x` and `y` are elements such that `x` precedes `y`, + * and if the two elements are equivalent (neither `x < y` nor `y < x`) then + * a postcondition of StableSort is that `x` still precedes `y`. + * + * @tparam CompareOp + * functor type having member `bool operator()(KeyT lhs, KeyT rhs)`. + * `CompareOp` is a model of [Strict Weak Ordering]. + * + * @param[in,out] keys + * Keys to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + */ + template + __device__ __forceinline__ void StableSort(KeyT (&keys)[ITEMS_PER_THREAD], + CompareOp compare_op) + { + Sort(keys, compare_op); + } + + /** + * @brief Sorts items partitioned across a CUDA thread block using + * a merge sorting method. + * + * @par + * StableSort is stable: it preserves the relative ordering of equivalent + * elements. That is, if `x` and `y` are elements such that `x` precedes `y`, + * and if the two elements are equivalent (neither `x < y` nor `y < x`) then + * a postcondition of StableSort is that `x` still precedes `y`. + * + * @tparam CompareOp + * functor type having member `bool operator()(KeyT lhs, KeyT rhs)`. + * `CompareOp` is a model of [Strict Weak Ordering]. + * + * @param[in,out] keys + * Keys to sort + * + * @param[in,out] items + * Values to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + */ + template + __device__ __forceinline__ void StableSort(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&items)[ITEMS_PER_THREAD], + CompareOp compare_op) + { + Sort(keys, items, compare_op); + } + + /** + * @brief Sorts items partitioned across a CUDA thread block using + * a merge sorting method. + * + * @par + * - StableSort is stable: it preserves the relative ordering of equivalent + * elements. That is, if `x` and `y` are elements such that `x` precedes + * `y`, and if the two elements are equivalent (neither `x < y` nor `y < x`) + * then a postcondition of StableSort is that `x` still precedes `y`. + * - The value of `oob_default` is assigned to all elements that are out of + * `valid_items` boundaries. It's expected that `oob_default` is ordered + * after any value in the `valid_items` boundaries. The algorithm always + * sorts a fixed amount of elements, which is equal to + * `ITEMS_PER_THREAD * BLOCK_THREADS`. + * If there is a value that is ordered after `oob_default`, it won't be + * placed within `valid_items` boundaries. + * + * @tparam CompareOp + * functor type having member `bool operator()(KeyT lhs, KeyT rhs)`. + * `CompareOp` is a model of [Strict Weak Ordering]. + * + * @param[in,out] keys + * Keys to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * @param[in] valid_items + * Number of valid items to sort + * + * @param[in] oob_default + * Default value to assign out-of-bound items + * + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + */ + template + __device__ __forceinline__ void StableSort(KeyT (&keys)[ITEMS_PER_THREAD], + CompareOp compare_op, + int valid_items, + KeyT oob_default) + { + Sort(keys, compare_op, valid_items, oob_default); + } + + /** + * @brief Sorts items partitioned across a CUDA thread block using + * a merge sorting method. + * + * @par + * - StableSort is stable: it preserves the relative ordering of equivalent + * elements. That is, if `x` and `y` are elements such that `x` precedes + * `y`, and if the two elements are equivalent (neither `x < y` nor `y < x`) + * then a postcondition of StableSort is that `x` still precedes `y`. + * - The value of `oob_default` is assigned to all elements that are out of + * `valid_items` boundaries. It's expected that `oob_default` is ordered + * after any value in the `valid_items` boundaries. The algorithm always + * sorts a fixed amount of elements, which is equal to + * `ITEMS_PER_THREAD * BLOCK_THREADS`. If there is a value that is ordered + * after `oob_default`, it won't be placed within `valid_items` boundaries. + * + * @tparam CompareOp + * functor type having member `bool operator()(KeyT lhs, KeyT rhs)`. + * `CompareOp` is a model of [Strict Weak Ordering]. + * + * @tparam IS_LAST_TILE + * True if `valid_items` isn't equal to the `ITEMS_PER_TILE` + * + * @param[in,out] keys + * Keys to sort + * + * @param[in,out] items + * Values to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * @param[in] valid_items + * Number of valid items to sort + * + * @param[in] oob_default + * Default value to assign out-of-bound items + * + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + */ + template + __device__ __forceinline__ void StableSort(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&items)[ITEMS_PER_THREAD], + CompareOp compare_op, + int valid_items, + KeyT oob_default) + { + Sort(keys, + items, + compare_op, + valid_items, + oob_default); + } + +private: + __device__ __forceinline__ void Sync() const + { + static_cast(this)->SyncImplementation(); + } +}; + + +/** + * @brief The BlockMergeSort class provides methods for sorting items + * partitioned across a CUDA thread block using a merge sorting method. + * @ingroup BlockModule + * + * @tparam KeyT + * KeyT type + * + * @tparam BLOCK_DIM_X + * The thread block length in threads along the X dimension + * + * @tparam ITEMS_PER_THREAD + * The number of items per thread + * + * @tparam ValueT + * **[optional]** ValueT type (default: `cub::NullType`, which indicates + * a keys-only sort) + * + * @tparam BLOCK_DIM_Y + * **[optional]** The thread block length in threads along the Y dimension + * (default: 1) + * + * @tparam BLOCK_DIM_Z + * **[optional]** The thread block length in threads along the Z dimension + * (default: 1) + * + * @par Overview + * BlockMergeSort arranges items into ascending order using a comparison + * functor with less-than semantics. Merge sort can handle arbitrary types + * and comparison functors, but is slower than BlockRadixSort when sorting + * arithmetic types into ascending/descending order. + * + * @par A Simple Example + * @blockcollective{BlockMergeSort} + * @par + * The code snippet below illustrates a sort of 512 integer keys that are + * partitioned across 128 threads * where each thread owns 4 consecutive items. + * @par + * @code + * #include // or equivalently + * + * struct CustomLess + * { + * template + * __device__ bool operator()(const DataType &lhs, const DataType &rhs) + * { + * return lhs < rhs; + * } + * }; + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockMergeSort for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockMergeSort BlockMergeSort; + * + * // Allocate shared memory for BlockMergeSort + * __shared__ typename BlockMergeSort::TempStorage temp_storage_shuffle; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_keys[4]; + * ... + * + * BlockMergeSort(temp_storage_shuffle).Sort(thread_keys, CustomLess()); + * ... + * } + * @endcode + * @par + * Suppose the set of input `thread_keys` across the block of threads is + * `{ [0,511,1,510], [2,509,3,508], [4,507,5,506], ..., [254,257,255,256] }`. + * The corresponding output `thread_keys` in those threads will be + * `{ [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [508,509,510,511] }`. + * + * @par Re-using dynamically allocating shared memory + * The following example under the examples/block folder illustrates usage of + * dynamically shared memory with BlockReduce and how to re-purpose + * the same memory region: + * example_block_reduce_dyn_smem.cu + * + * This example can be easily adapted to the storage required by BlockMergeSort. + */ +template +class BlockMergeSort + : public BlockMergeSortStrategy> +{ +private: + // The thread block size in threads + static constexpr int BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z; + static constexpr int ITEMS_PER_TILE = ITEMS_PER_THREAD * BLOCK_THREADS; + + using BlockMergeSortStrategyT = + BlockMergeSortStrategy; + +public: + __device__ __forceinline__ BlockMergeSort() + : BlockMergeSortStrategyT( + RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + __device__ __forceinline__ explicit BlockMergeSort( + typename BlockMergeSortStrategyT::TempStorage &temp_storage) + : BlockMergeSortStrategyT( + temp_storage, + RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + +private: + __device__ __forceinline__ void SyncImplementation() const + { + CTA_SYNC(); + } + + friend BlockMergeSortStrategyT; +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_radix_rank.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_radix_rank.cuh new file mode 100644 index 0000000000000000000000000000000000000000..a661e9d1f1f3b0993bbc61fa346f9d1c4fd48d45 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_radix_rank.cuh @@ -0,0 +1,1240 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::BlockRadixRank provides operations for ranking unsigned integer types within a CUDA thread block + */ + +#pragma once + +#include + +#include "../thread/thread_reduce.cuh" +#include "../thread/thread_scan.cuh" +#include "../block/block_scan.cuh" +#include "../block/radix_rank_sort_operations.cuh" +#include "../config.cuh" +#include "../util_ptx.cuh" +#include "../util_type.cuh" + +#include + +CUB_NAMESPACE_BEGIN + + +/** + * \brief Radix ranking algorithm, the algorithm used to implement stable ranking of the + * keys from a single tile. Note that different ranking algorithms require different + * initial arrangements of keys to function properly. + */ +enum RadixRankAlgorithm +{ + /** Ranking using the BlockRadixRank algorithm with MEMOIZE_OUTER_SCAN == false. It + * uses thread-private histograms, and thus uses more shared memory. Requires blocked + * arrangement of keys. Does not support count callbacks. */ + RADIX_RANK_BASIC, + /** Ranking using the BlockRadixRank algorithm with MEMOIZE_OUTER_SCAN == + * true. Similar to RADIX_RANK BASIC, it requires blocked arrangement of + * keys and does not support count callbacks.*/ + RADIX_RANK_MEMOIZE, + /** Ranking using the BlockRadixRankMatch algorithm. It uses warp-private + * histograms and matching for ranking the keys in a single warp. Therefore, + * it uses less shared memory compared to RADIX_RANK_BASIC. It requires + * warp-striped key arrangement and supports count callbacks. */ + RADIX_RANK_MATCH, + /** Ranking using the BlockRadixRankMatchEarlyCounts algorithm with + * MATCH_ALGORITHM == WARP_MATCH_ANY. An alternative implementation of + * match-based ranking that computes bin counts early. Because of this, it + * works better with onesweep sorting, which requires bin counts for + * decoupled look-back. Assumes warp-striped key arrangement and supports + * count callbacks.*/ + RADIX_RANK_MATCH_EARLY_COUNTS_ANY, + /** Ranking using the BlockRadixRankEarlyCounts algorithm with + * MATCH_ALGORITHM == WARP_MATCH_ATOMIC_OR. It uses extra space in shared + * memory to generate warp match masks using atomicOr(). This is faster when + * there are few matches, but can lead to slowdowns if the number of + * matching keys among warp lanes is high. Assumes warp-striped key + * arrangement and supports count callbacks. */ + RADIX_RANK_MATCH_EARLY_COUNTS_ATOMIC_OR +}; + + +/** Empty callback implementation */ +template +struct BlockRadixRankEmptyCallback +{ + __device__ __forceinline__ void operator()(int (&bins)[BINS_PER_THREAD]) {} +}; + + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document +namespace detail +{ + +template +struct warp_in_block_matcher_t +{ + static __device__ std::uint32_t match_any(std::uint32_t label, std::uint32_t warp_id) + { + if (warp_id == static_cast(PartialWarpId)) + { + return MatchAny(label); + } + + return MatchAny(label); + } +}; + +template +struct warp_in_block_matcher_t +{ + static __device__ std::uint32_t match_any(std::uint32_t label, std::uint32_t warp_id) + { + return MatchAny(label); + } +}; + +} // namespace detail +#endif // DOXYGEN_SHOULD_SKIP_THIS + + +/** + * \brief BlockRadixRank provides operations for ranking unsigned integer types within a CUDA thread block. + * \ingroup BlockModule + * + * \tparam BLOCK_DIM_X The thread block length in threads along the X dimension + * \tparam RADIX_BITS The number of radix bits per digit place + * \tparam IS_DESCENDING Whether or not the sorted-order is high-to-low + * \tparam MEMOIZE_OUTER_SCAN [optional] Whether or not to buffer outer raking scan partials to incur fewer shared memory reads at the expense of higher register pressure (default: true for architectures SM35 and newer, false otherwise). See BlockScanAlgorithm::BLOCK_SCAN_RAKING_MEMOIZE for more details. + * \tparam INNER_SCAN_ALGORITHM [optional] The cub::BlockScanAlgorithm algorithm to use (default: cub::BLOCK_SCAN_WARP_SCANS) + * \tparam SMEM_CONFIG [optional] Shared memory bank mode (default: \p cudaSharedMemBankSizeFourByte) + * \tparam BLOCK_DIM_Y [optional] The thread block length in threads along the Y dimension (default: 1) + * \tparam BLOCK_DIM_Z [optional] The thread block length in threads along the Z dimension (default: 1) + * \tparam LEGACY_PTX_ARCH [optional] Unused. + * + * \par Overview + * Blah... + * - Keys must be in a form suitable for radix ranking (i.e., unsigned bits). + * - \blocked + * + * \par Performance Considerations + * - \granularity + * + * \par + * \code + * #include + * + * __global__ void ExampleKernel(...) + * { + * constexpr int block_threads = 2; + * constexpr int radix_bits = 5; + * + * // Specialize BlockRadixRank for a 1D block of 2 threads + * using block_radix_rank = cub::BlockRadixRank; + * using storage_t = typename block_radix_rank::TempStorage; + * + * // Allocate shared memory for BlockRadixSort + * __shared__ storage_t temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int keys[2]; + * int ranks[2]; + * ... + * + * cub::BFEDigitExtractor extractor(0, radix_bits); + * block_radix_rank(temp_storage).RankKeys(keys, ranks, extractor); + * + * ... + * \endcode + * Suppose the set of input `keys` across the block of threads is `{ [16,10], [9,11] }`. + * The corresponding output `ranks` in those threads will be `{ [3,1], [0,2] }`. + * + * \par Re-using dynamically allocating shared memory + * The following example under the examples/block folder illustrates usage of + * dynamically shared memory with BlockReduce and how to re-purpose + * the same memory region: + * example_block_reduce_dyn_smem.cu + * + * This example can be easily adapted to the storage required by BlockRadixRank. + */ +template < + int BLOCK_DIM_X, + int RADIX_BITS, + bool IS_DESCENDING, + bool MEMOIZE_OUTER_SCAN = true, + BlockScanAlgorithm INNER_SCAN_ALGORITHM = BLOCK_SCAN_WARP_SCANS, + cudaSharedMemConfig SMEM_CONFIG = cudaSharedMemBankSizeFourByte, + int BLOCK_DIM_Y = 1, + int BLOCK_DIM_Z = 1, + int LEGACY_PTX_ARCH = 0> +class BlockRadixRank +{ +private: + + /****************************************************************************** + * Type definitions and constants + ******************************************************************************/ + + // Integer type for digit counters (to be packed into words of type PackedCounters) + using DigitCounter = unsigned short; + + // Integer type for packing DigitCounters into columns of shared memory banks + using PackedCounter = + cub::detail::conditional_t; + + static constexpr DigitCounter max_tile_size = ::cuda::std::numeric_limits::max(); + + enum + { + // The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + + RADIX_DIGITS = 1 << RADIX_BITS, + + LOG_WARP_THREADS = CUB_LOG_WARP_THREADS(0), + WARP_THREADS = 1 << LOG_WARP_THREADS, + WARPS = (BLOCK_THREADS + WARP_THREADS - 1) / WARP_THREADS, + + BYTES_PER_COUNTER = sizeof(DigitCounter), + LOG_BYTES_PER_COUNTER = Log2::VALUE, + + PACKING_RATIO = static_cast(sizeof(PackedCounter) / sizeof(DigitCounter)), + LOG_PACKING_RATIO = Log2::VALUE, + + LOG_COUNTER_LANES = CUB_MAX((int(RADIX_BITS) - int(LOG_PACKING_RATIO)), 0), // Always at least one lane + COUNTER_LANES = 1 << LOG_COUNTER_LANES, + + // The number of packed counters per thread (plus one for padding) + PADDED_COUNTER_LANES = COUNTER_LANES + 1, + RAKING_SEGMENT = PADDED_COUNTER_LANES, + }; + +public: + + enum + { + /// Number of bin-starting offsets tracked per thread + BINS_TRACKED_PER_THREAD = CUB_MAX(1, (RADIX_DIGITS + BLOCK_THREADS - 1) / BLOCK_THREADS), + }; + +private: + + + /// BlockScan type + typedef BlockScan< + PackedCounter, + BLOCK_DIM_X, + INNER_SCAN_ALGORITHM, + BLOCK_DIM_Y, + BLOCK_DIM_Z> + BlockScan; + + + /// Shared memory storage layout type for BlockRadixRank + struct __align__(16) _TempStorage + { + union Aliasable + { + DigitCounter digit_counters[PADDED_COUNTER_LANES][BLOCK_THREADS][PACKING_RATIO]; + PackedCounter raking_grid[BLOCK_THREADS][RAKING_SEGMENT]; + + } aliasable; + + // Storage for scanning local ranks + typename BlockScan::TempStorage block_scan; + }; + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Linear thread-id + unsigned int linear_tid; + + /// Copy of raking segment, promoted to registers + PackedCounter cached_segment[RAKING_SEGMENT]; + + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + /** + * Internal storage allocator + */ + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + + /** + * Performs upsweep raking reduction, returning the aggregate + */ + __device__ __forceinline__ PackedCounter Upsweep() + { + PackedCounter *smem_raking_ptr = temp_storage.aliasable.raking_grid[linear_tid]; + PackedCounter *raking_ptr; + + if (MEMOIZE_OUTER_SCAN) + { + // Copy data into registers + #pragma unroll + for (int i = 0; i < RAKING_SEGMENT; i++) + { + cached_segment[i] = smem_raking_ptr[i]; + } + raking_ptr = cached_segment; + } + else + { + raking_ptr = smem_raking_ptr; + } + + return internal::ThreadReduce(raking_ptr, Sum()); + } + + + /// Performs exclusive downsweep raking scan + __device__ __forceinline__ void ExclusiveDownsweep( + PackedCounter raking_partial) + { + PackedCounter *smem_raking_ptr = temp_storage.aliasable.raking_grid[linear_tid]; + + PackedCounter *raking_ptr = (MEMOIZE_OUTER_SCAN) ? + cached_segment : + smem_raking_ptr; + + // Exclusive raking downsweep scan + internal::ThreadScanExclusive(raking_ptr, raking_ptr, Sum(), raking_partial); + + if (MEMOIZE_OUTER_SCAN) + { + // Copy data back to smem + #pragma unroll + for (int i = 0; i < RAKING_SEGMENT; i++) + { + smem_raking_ptr[i] = cached_segment[i]; + } + } + } + + + /** + * Reset shared memory digit counters + */ + __device__ __forceinline__ void ResetCounters() + { + // Reset shared memory digit counters + #pragma unroll + for (int LANE = 0; LANE < PADDED_COUNTER_LANES; LANE++) + { + *((PackedCounter*) temp_storage.aliasable.digit_counters[LANE][linear_tid]) = 0; + } + } + + + /** + * Block-scan prefix callback + */ + struct PrefixCallBack + { + __device__ __forceinline__ PackedCounter operator()(PackedCounter block_aggregate) + { + PackedCounter block_prefix = 0; + + // Propagate totals in packed fields + #pragma unroll + for (int PACKED = 1; PACKED < PACKING_RATIO; PACKED++) + { + block_prefix += block_aggregate << (sizeof(DigitCounter) * 8 * PACKED); + } + + return block_prefix; + } + }; + + + /** + * Scan shared memory digit counters. + */ + __device__ __forceinline__ void ScanCounters() + { + // Upsweep scan + PackedCounter raking_partial = Upsweep(); + + // Compute exclusive sum + PackedCounter exclusive_partial; + PrefixCallBack prefix_call_back; + BlockScan(temp_storage.block_scan).ExclusiveSum(raking_partial, exclusive_partial, prefix_call_back); + + // Downsweep scan with exclusive partial + ExclusiveDownsweep(exclusive_partial); + } + +public: + + /// \smemstorage{BlockScan} + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /******************************************************************//** + * \name Collective constructors + *********************************************************************/ + //@{ + + /** + * \brief Collective constructor using a private static allocation of shared memory as temporary storage. + */ + __device__ __forceinline__ BlockRadixRank() + : + temp_storage(PrivateStorage()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + /** + * \brief Collective constructor using the specified memory allocation as temporary storage. + */ + __device__ __forceinline__ BlockRadixRank( + TempStorage &temp_storage) ///< [in] Reference to memory allocation having layout type TempStorage + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + //@} end member group + /******************************************************************//** + * \name Raking + *********************************************************************/ + //@{ + + /** + * \brief Rank keys. + */ + template < + typename UnsignedBits, + int KEYS_PER_THREAD, + typename DigitExtractorT> + __device__ __forceinline__ void RankKeys( + UnsignedBits (&keys)[KEYS_PER_THREAD], ///< [in] Keys for this tile + int (&ranks)[KEYS_PER_THREAD], ///< [out] For each key, the local rank within the tile + DigitExtractorT digit_extractor) ///< [in] The digit extractor + { + static_assert(BLOCK_THREADS * KEYS_PER_THREAD <= max_tile_size, + "DigitCounter type is too small to hold this number of keys"); + + DigitCounter thread_prefixes[KEYS_PER_THREAD]; // For each key, the count of previous keys in this tile having the same digit + DigitCounter* digit_counters[KEYS_PER_THREAD]; // For each key, the byte-offset of its corresponding digit counter in smem + + // Reset shared memory digit counters + ResetCounters(); + + #pragma unroll + for (int ITEM = 0; ITEM < KEYS_PER_THREAD; ++ITEM) + { + // Get digit + std::uint32_t digit = digit_extractor.Digit(keys[ITEM]); + + // Get sub-counter + std::uint32_t sub_counter = digit >> LOG_COUNTER_LANES; + + // Get counter lane + std::uint32_t counter_lane = digit & (COUNTER_LANES - 1); + + if (IS_DESCENDING) + { + sub_counter = PACKING_RATIO - 1 - sub_counter; + counter_lane = COUNTER_LANES - 1 - counter_lane; + } + + // Pointer to smem digit counter + digit_counters[ITEM] = &temp_storage.aliasable.digit_counters[counter_lane][linear_tid][sub_counter]; + + // Load thread-exclusive prefix + thread_prefixes[ITEM] = *digit_counters[ITEM]; + + // Store inclusive prefix + *digit_counters[ITEM] = thread_prefixes[ITEM] + 1; + } + + CTA_SYNC(); + + // Scan shared memory counters + ScanCounters(); + + CTA_SYNC(); + + // Extract the local ranks of each key + #pragma unroll + for (int ITEM = 0; ITEM < KEYS_PER_THREAD; ++ITEM) + { + // Add in thread block exclusive prefix + ranks[ITEM] = thread_prefixes[ITEM] + *digit_counters[ITEM]; + } + } + + + /** + * \brief Rank keys. For the lower \p RADIX_DIGITS threads, digit counts for each digit are provided for the corresponding thread. + */ + template < + typename UnsignedBits, + int KEYS_PER_THREAD, + typename DigitExtractorT> + __device__ __forceinline__ void RankKeys( + UnsignedBits (&keys)[KEYS_PER_THREAD], ///< [in] Keys for this tile + int (&ranks)[KEYS_PER_THREAD], ///< [out] For each key, the local rank within the tile (out parameter) + DigitExtractorT digit_extractor, ///< [in] The digit extractor + int (&exclusive_digit_prefix)[BINS_TRACKED_PER_THREAD]) ///< [out] The exclusive prefix sum for the digits [(threadIdx.x * BINS_TRACKED_PER_THREAD) ... (threadIdx.x * BINS_TRACKED_PER_THREAD) + BINS_TRACKED_PER_THREAD - 1] + { + static_assert(BLOCK_THREADS * KEYS_PER_THREAD <= max_tile_size, + "DigitCounter type is too small to hold this number of keys"); + + // Rank keys + RankKeys(keys, ranks, digit_extractor); + + // Get the inclusive and exclusive digit totals corresponding to the calling thread. + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (linear_tid * BINS_TRACKED_PER_THREAD) + track; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + if (IS_DESCENDING) + bin_idx = RADIX_DIGITS - bin_idx - 1; + + // Obtain ex/inclusive digit counts. (Unfortunately these all reside in the + // first counter column, resulting in unavoidable bank conflicts.) + unsigned int counter_lane = (bin_idx & (COUNTER_LANES - 1)); + unsigned int sub_counter = bin_idx >> (LOG_COUNTER_LANES); + + exclusive_digit_prefix[track] = temp_storage.aliasable.digit_counters[counter_lane][0][sub_counter]; + } + } + } +}; + + + + + +/** + * Radix-rank using match.any + */ +template < + int BLOCK_DIM_X, + int RADIX_BITS, + bool IS_DESCENDING, + BlockScanAlgorithm INNER_SCAN_ALGORITHM = BLOCK_SCAN_WARP_SCANS, + int BLOCK_DIM_Y = 1, + int BLOCK_DIM_Z = 1, + int LEGACY_PTX_ARCH = 0> +class BlockRadixRankMatch +{ +private: + + /****************************************************************************** + * Type definitions and constants + ******************************************************************************/ + + typedef int32_t RankT; + typedef int32_t DigitCounterT; + + enum + { + // The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + + RADIX_DIGITS = 1 << RADIX_BITS, + + LOG_WARP_THREADS = CUB_LOG_WARP_THREADS(0), + WARP_THREADS = 1 << LOG_WARP_THREADS, + PARTIAL_WARP_THREADS = BLOCK_THREADS % WARP_THREADS, + WARPS = (BLOCK_THREADS + WARP_THREADS - 1) / WARP_THREADS, + + PADDED_WARPS = ((WARPS & 0x1) == 0) ? + WARPS + 1 : + WARPS, + + COUNTERS = PADDED_WARPS * RADIX_DIGITS, + RAKING_SEGMENT = (COUNTERS + BLOCK_THREADS - 1) / BLOCK_THREADS, + PADDED_RAKING_SEGMENT = ((RAKING_SEGMENT & 0x1) == 0) ? + RAKING_SEGMENT + 1 : + RAKING_SEGMENT, + }; + +public: + + enum + { + /// Number of bin-starting offsets tracked per thread + BINS_TRACKED_PER_THREAD = CUB_MAX(1, (RADIX_DIGITS + BLOCK_THREADS - 1) / BLOCK_THREADS), + }; + +private: + + /// BlockScan type + typedef BlockScan< + DigitCounterT, + BLOCK_THREADS, + INNER_SCAN_ALGORITHM, + BLOCK_DIM_Y, + BLOCK_DIM_Z> + BlockScanT; + + + /// Shared memory storage layout type for BlockRadixRank + struct __align__(16) _TempStorage + { + typename BlockScanT::TempStorage block_scan; + + union __align__(16) Aliasable + { + volatile DigitCounterT warp_digit_counters[RADIX_DIGITS][PADDED_WARPS]; + DigitCounterT raking_grid[BLOCK_THREADS][PADDED_RAKING_SEGMENT]; + + } aliasable; + }; + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Linear thread-id + unsigned int linear_tid; + + + +public: + + /// \smemstorage{BlockScan} + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /******************************************************************//** + * \name Collective constructors + *********************************************************************/ + //@{ + + + /** + * \brief Collective constructor using the specified memory allocation as temporary storage. + */ + __device__ __forceinline__ BlockRadixRankMatch( + TempStorage &temp_storage) ///< [in] Reference to memory allocation having layout type TempStorage + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + //@} end member group + /******************************************************************//** + * \name Raking + *********************************************************************/ + //@{ + + /** \brief Computes the count of keys for each digit value, and calls the + * callback with the array of key counts. + + * @tparam CountsCallback The callback type. It should implement an instance + * overload of operator()(int (&bins)[BINS_TRACKED_PER_THREAD]), where bins + * is an array of key counts for each digit value distributed in block + * distribution among the threads of the thread block. Key counts can be + * used, to update other data structures in global or shared + * memory. Depending on the implementation of the ranking algoirhtm + * (see BlockRadixRankMatchEarlyCounts), key counts may become available + * early, therefore, they are returned through a callback rather than a + * separate output parameter of RankKeys(). + */ + template + __device__ __forceinline__ void CallBack(CountsCallback callback) + { + int bins[BINS_TRACKED_PER_THREAD]; + // Get count for each digit + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (linear_tid * BINS_TRACKED_PER_THREAD) + track; + const int TILE_ITEMS = KEYS_PER_THREAD * BLOCK_THREADS; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + if (IS_DESCENDING) + { + bin_idx = RADIX_DIGITS - bin_idx - 1; + bins[track] = (bin_idx > 0 ? + temp_storage.aliasable.warp_digit_counters[bin_idx - 1][0] : TILE_ITEMS) - + temp_storage.aliasable.warp_digit_counters[bin_idx][0]; + } + else + { + bins[track] = (bin_idx < RADIX_DIGITS - 1 ? + temp_storage.aliasable.warp_digit_counters[bin_idx + 1][0] : TILE_ITEMS) - + temp_storage.aliasable.warp_digit_counters[bin_idx][0]; + } + } + } + callback(bins); + } + + /** + * \brief Rank keys. + */ + template < + typename UnsignedBits, + int KEYS_PER_THREAD, + typename DigitExtractorT, + typename CountsCallback> + __device__ __forceinline__ void RankKeys( + UnsignedBits (&keys)[KEYS_PER_THREAD], ///< [in] Keys for this tile + int (&ranks)[KEYS_PER_THREAD], ///< [out] For each key, the local rank within the tile + DigitExtractorT digit_extractor, ///< [in] The digit extractor + CountsCallback callback) + { + // Initialize shared digit counters + + #pragma unroll + for (int ITEM = 0; ITEM < PADDED_RAKING_SEGMENT; ++ITEM) + temp_storage.aliasable.raking_grid[linear_tid][ITEM] = 0; + + CTA_SYNC(); + + // Each warp will strip-mine its section of input, one strip at a time + + volatile DigitCounterT *digit_counters[KEYS_PER_THREAD]; + uint32_t warp_id = linear_tid >> LOG_WARP_THREADS; + uint32_t lane_mask_lt = LaneMaskLt(); + + #pragma unroll + for (int ITEM = 0; ITEM < KEYS_PER_THREAD; ++ITEM) + { + // My digit + std::uint32_t digit = digit_extractor.Digit(keys[ITEM]); + + if (IS_DESCENDING) + digit = RADIX_DIGITS - digit - 1; + + // Mask of peers who have same digit as me + uint32_t peer_mask = + detail::warp_in_block_matcher_t< + RADIX_BITS, + PARTIAL_WARP_THREADS, + WARPS - 1>::match_any(digit, warp_id); + + // Pointer to smem digit counter for this key + digit_counters[ITEM] = &temp_storage.aliasable.warp_digit_counters[digit][warp_id]; + + // Number of occurrences in previous strips + DigitCounterT warp_digit_prefix = *digit_counters[ITEM]; + + // Warp-sync + WARP_SYNC(0xFFFFFFFF); + + // Number of peers having same digit as me + int32_t digit_count = __popc(peer_mask); + + // Number of lower-ranked peers having same digit seen so far + int32_t peer_digit_prefix = __popc(peer_mask & lane_mask_lt); + + if (peer_digit_prefix == 0) + { + // First thread for each digit updates the shared warp counter + *digit_counters[ITEM] = DigitCounterT(warp_digit_prefix + digit_count); + } + + // Warp-sync + WARP_SYNC(0xFFFFFFFF); + + // Number of prior keys having same digit + ranks[ITEM] = warp_digit_prefix + DigitCounterT(peer_digit_prefix); + } + + CTA_SYNC(); + + // Scan warp counters + + DigitCounterT scan_counters[PADDED_RAKING_SEGMENT]; + + #pragma unroll + for (int ITEM = 0; ITEM < PADDED_RAKING_SEGMENT; ++ITEM) + scan_counters[ITEM] = temp_storage.aliasable.raking_grid[linear_tid][ITEM]; + + BlockScanT(temp_storage.block_scan).ExclusiveSum(scan_counters, scan_counters); + + #pragma unroll + for (int ITEM = 0; ITEM < PADDED_RAKING_SEGMENT; ++ITEM) + temp_storage.aliasable.raking_grid[linear_tid][ITEM] = scan_counters[ITEM]; + + CTA_SYNC(); + if (!std::is_same< + CountsCallback, + BlockRadixRankEmptyCallback>::value) + { + CallBack(callback); + } + + // Seed ranks with counter values from previous warps + #pragma unroll + for (int ITEM = 0; ITEM < KEYS_PER_THREAD; ++ITEM) + ranks[ITEM] += *digit_counters[ITEM]; + } + + template < + typename UnsignedBits, + int KEYS_PER_THREAD, + typename DigitExtractorT> + __device__ __forceinline__ void RankKeys( + UnsignedBits (&keys)[KEYS_PER_THREAD], int (&ranks)[KEYS_PER_THREAD], + DigitExtractorT digit_extractor) + { + RankKeys(keys, ranks, digit_extractor, + BlockRadixRankEmptyCallback()); + } + + /** + * \brief Rank keys. For the lower \p RADIX_DIGITS threads, digit counts for each digit are provided for the corresponding thread. + */ + template < + typename UnsignedBits, + int KEYS_PER_THREAD, + typename DigitExtractorT, + typename CountsCallback> + __device__ __forceinline__ void RankKeys( + UnsignedBits (&keys)[KEYS_PER_THREAD], ///< [in] Keys for this tile + int (&ranks)[KEYS_PER_THREAD], ///< [out] For each key, the local rank within the tile (out parameter) + DigitExtractorT digit_extractor, ///< [in] The digit extractor + int (&exclusive_digit_prefix)[BINS_TRACKED_PER_THREAD], ///< [out] The exclusive prefix sum for the digits [(threadIdx.x * BINS_TRACKED_PER_THREAD) ... (threadIdx.x * BINS_TRACKED_PER_THREAD) + BINS_TRACKED_PER_THREAD - 1] + CountsCallback callback) + { + RankKeys(keys, ranks, digit_extractor, callback); + + // Get exclusive count for each digit + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (linear_tid * BINS_TRACKED_PER_THREAD) + track; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + { + if (IS_DESCENDING) + bin_idx = RADIX_DIGITS - bin_idx - 1; + + exclusive_digit_prefix[track] = temp_storage.aliasable.warp_digit_counters[bin_idx][0]; + } + } + } + + template < + typename UnsignedBits, + int KEYS_PER_THREAD, + typename DigitExtractorT> + __device__ __forceinline__ void RankKeys( + UnsignedBits (&keys)[KEYS_PER_THREAD], ///< [in] Keys for this tile + int (&ranks)[KEYS_PER_THREAD], ///< [out] For each key, the local rank within the tile (out parameter) + DigitExtractorT digit_extractor, + int (&exclusive_digit_prefix)[BINS_TRACKED_PER_THREAD]) ///< [out] The exclusive prefix sum for the digits [(threadIdx.x * BINS_TRACKED_PER_THREAD) ... (threadIdx.x * BINS_TRACKED_PER_THREAD) + BINS_TRACKED_PER_THREAD - 1] + { + RankKeys(keys, ranks, digit_extractor, exclusive_digit_prefix, + BlockRadixRankEmptyCallback()); + } +}; + +enum WarpMatchAlgorithm +{ + WARP_MATCH_ANY, + WARP_MATCH_ATOMIC_OR +}; + +/** + * Radix-rank using matching which computes the counts of keys for each digit + * value early, at the expense of doing more work. This may be useful e.g. for + * decoupled look-back, where it reduces the time other thread blocks need to + * wait for digit counts to become available. + */ +template +struct BlockRadixRankMatchEarlyCounts +{ + // constants + enum + { + BLOCK_THREADS = BLOCK_DIM_X, + RADIX_DIGITS = 1 << RADIX_BITS, + BINS_PER_THREAD = (RADIX_DIGITS + BLOCK_THREADS - 1) / BLOCK_THREADS, + BINS_TRACKED_PER_THREAD = BINS_PER_THREAD, + FULL_BINS = BINS_PER_THREAD * BLOCK_THREADS == RADIX_DIGITS, + WARP_THREADS = CUB_PTX_WARP_THREADS, + PARTIAL_WARP_THREADS = BLOCK_THREADS % WARP_THREADS, + BLOCK_WARPS = BLOCK_THREADS / WARP_THREADS, + PARTIAL_WARP_ID = BLOCK_WARPS - 1, + WARP_MASK = ~0, + NUM_MATCH_MASKS = MATCH_ALGORITHM == WARP_MATCH_ATOMIC_OR ? BLOCK_WARPS : 0, + // Guard against declaring zero-sized array: + MATCH_MASKS_ALLOC_SIZE = NUM_MATCH_MASKS < 1 ? 1 : NUM_MATCH_MASKS, + }; + + // types + typedef cub::BlockScan BlockScan; + + + + // temporary storage + struct TempStorage + { + union + { + int warp_offsets[BLOCK_WARPS][RADIX_DIGITS]; + int warp_histograms[BLOCK_WARPS][RADIX_DIGITS][NUM_PARTS]; + }; + + int match_masks[MATCH_MASKS_ALLOC_SIZE][RADIX_DIGITS]; + + typename BlockScan::TempStorage prefix_tmp; + }; + + TempStorage& temp_storage; + + // internal ranking implementation + template + struct BlockRadixRankMatchInternal + { + TempStorage& s; + DigitExtractorT digit_extractor; + CountsCallback callback; + int warp; + int lane; + + __device__ __forceinline__ std::uint32_t Digit(UnsignedBits key) + { + std::uint32_t digit = digit_extractor.Digit(key); + return IS_DESCENDING ? RADIX_DIGITS - 1 - digit : digit; + } + + __device__ __forceinline__ int ThreadBin(int u) + { + int bin = threadIdx.x * BINS_PER_THREAD + u; + return IS_DESCENDING ? RADIX_DIGITS - 1 - bin : bin; + } + + __device__ __forceinline__ + void ComputeHistogramsWarp(UnsignedBits (&keys)[KEYS_PER_THREAD]) + { + //int* warp_offsets = &s.warp_offsets[warp][0]; + int (&warp_histograms)[RADIX_DIGITS][NUM_PARTS] = s.warp_histograms[warp]; + // compute warp-private histograms + #pragma unroll + for (int bin = lane; bin < RADIX_DIGITS; bin += WARP_THREADS) + { + #pragma unroll + for (int part = 0; part < NUM_PARTS; ++part) + { + warp_histograms[bin][part] = 0; + } + } + if (MATCH_ALGORITHM == WARP_MATCH_ATOMIC_OR) + { + int* match_masks = &s.match_masks[warp][0]; + #pragma unroll + for (int bin = lane; bin < RADIX_DIGITS; bin += WARP_THREADS) + { + match_masks[bin] = 0; + } + } + WARP_SYNC(WARP_MASK); + + // compute private per-part histograms + int part = lane % NUM_PARTS; + #pragma unroll + for (int u = 0; u < KEYS_PER_THREAD; ++u) + { + atomicAdd(&warp_histograms[Digit(keys[u])][part], 1); + } + + // sum different parts; + // no extra work is necessary if NUM_PARTS == 1 + if (NUM_PARTS > 1) + { + WARP_SYNC(WARP_MASK); + // TODO: handle RADIX_DIGITS % WARP_THREADS != 0 if it becomes necessary + const int WARP_BINS_PER_THREAD = RADIX_DIGITS / WARP_THREADS; + int bins[WARP_BINS_PER_THREAD]; + #pragma unroll + for (int u = 0; u < WARP_BINS_PER_THREAD; ++u) + { + int bin = lane + u * WARP_THREADS; + bins[u] = internal::ThreadReduce(warp_histograms[bin], Sum()); + } + CTA_SYNC(); + + // store the resulting histogram in shared memory + int* warp_offsets = &s.warp_offsets[warp][0]; + #pragma unroll + for (int u = 0; u < WARP_BINS_PER_THREAD; ++u) + { + int bin = lane + u * WARP_THREADS; + warp_offsets[bin] = bins[u]; + } + } + } + + __device__ __forceinline__ + void ComputeOffsetsWarpUpsweep(int (&bins)[BINS_PER_THREAD]) + { + // sum up warp-private histograms + #pragma unroll + for (int u = 0; u < BINS_PER_THREAD; ++u) + { + bins[u] = 0; + int bin = ThreadBin(u); + if (FULL_BINS || (bin >= 0 && bin < RADIX_DIGITS)) + { + #pragma unroll + for (int j_warp = 0; j_warp < BLOCK_WARPS; ++j_warp) + { + int warp_offset = s.warp_offsets[j_warp][bin]; + s.warp_offsets[j_warp][bin] = bins[u]; + bins[u] += warp_offset; + } + } + } + } + + __device__ __forceinline__ + void ComputeOffsetsWarpDownsweep(int (&offsets)[BINS_PER_THREAD]) + { + #pragma unroll + for (int u = 0; u < BINS_PER_THREAD; ++u) + { + int bin = ThreadBin(u); + if (FULL_BINS || (bin >= 0 && bin < RADIX_DIGITS)) + { + int digit_offset = offsets[u]; + #pragma unroll + for (int j_warp = 0; j_warp < BLOCK_WARPS; ++j_warp) + { + s.warp_offsets[j_warp][bin] += digit_offset; + } + } + } + } + + __device__ __forceinline__ + void ComputeRanksItem( + UnsignedBits (&keys)[KEYS_PER_THREAD], int (&ranks)[KEYS_PER_THREAD], + Int2Type) + { + // compute key ranks + int lane_mask = 1 << lane; + int* warp_offsets = &s.warp_offsets[warp][0]; + int* match_masks = &s.match_masks[warp][0]; + #pragma unroll + for (int u = 0; u < KEYS_PER_THREAD; ++u) + { + std::uint32_t bin = Digit(keys[u]); + int* p_match_mask = &match_masks[bin]; + atomicOr(p_match_mask, lane_mask); + WARP_SYNC(WARP_MASK); + int bin_mask = *p_match_mask; + int leader = (WARP_THREADS - 1) - __clz(bin_mask); + int warp_offset = 0; + int popc = __popc(bin_mask & LaneMaskLe()); + if (lane == leader) + { + // atomic is a bit faster + warp_offset = atomicAdd(&warp_offsets[bin], popc); + } + warp_offset = SHFL_IDX_SYNC(warp_offset, leader, WARP_MASK); + if (lane == leader) *p_match_mask = 0; + WARP_SYNC(WARP_MASK); + ranks[u] = warp_offset + popc - 1; + } + } + + __device__ __forceinline__ + void ComputeRanksItem( + UnsignedBits (&keys)[KEYS_PER_THREAD], int (&ranks)[KEYS_PER_THREAD], + Int2Type) + { + // compute key ranks + int* warp_offsets = &s.warp_offsets[warp][0]; + #pragma unroll + for (int u = 0; u < KEYS_PER_THREAD; ++u) + { + std::uint32_t bin = Digit(keys[u]); + int bin_mask = detail::warp_in_block_matcher_t::match_any(bin, + warp); + int leader = (WARP_THREADS - 1) - __clz(bin_mask); + int warp_offset = 0; + int popc = __popc(bin_mask & LaneMaskLe()); + if (lane == leader) + { + // atomic is a bit faster + warp_offset = atomicAdd(&warp_offsets[bin], popc); + } + warp_offset = SHFL_IDX_SYNC(warp_offset, leader, WARP_MASK); + ranks[u] = warp_offset + popc - 1; + } + } + + __device__ __forceinline__ void RankKeys( + UnsignedBits (&keys)[KEYS_PER_THREAD], + int (&ranks)[KEYS_PER_THREAD], + int (&exclusive_digit_prefix)[BINS_PER_THREAD]) + { + ComputeHistogramsWarp(keys); + + CTA_SYNC(); + int bins[BINS_PER_THREAD]; + ComputeOffsetsWarpUpsweep(bins); + callback(bins); + + BlockScan(s.prefix_tmp).ExclusiveSum(bins, exclusive_digit_prefix); + + ComputeOffsetsWarpDownsweep(exclusive_digit_prefix); + CTA_SYNC(); + ComputeRanksItem(keys, ranks, Int2Type()); + } + + __device__ __forceinline__ BlockRadixRankMatchInternal + (TempStorage& temp_storage, DigitExtractorT digit_extractor, CountsCallback callback) + : s(temp_storage), digit_extractor(digit_extractor), + callback(callback), warp(threadIdx.x / WARP_THREADS), lane(LaneId()) + {} + }; + + __device__ __forceinline__ BlockRadixRankMatchEarlyCounts + (TempStorage& temp_storage) : temp_storage(temp_storage) {} + + /** + * \brief Rank keys. For the lower \p RADIX_DIGITS threads, digit counts for each digit are provided for the corresponding thread. + */ + template + __device__ __forceinline__ void RankKeys( + UnsignedBits (&keys)[KEYS_PER_THREAD], + int (&ranks)[KEYS_PER_THREAD], + DigitExtractorT digit_extractor, + int (&exclusive_digit_prefix)[BINS_PER_THREAD], + CountsCallback callback) + { + BlockRadixRankMatchInternal + internal(temp_storage, digit_extractor, callback); + internal.RankKeys(keys, ranks, exclusive_digit_prefix); + } + + template + __device__ __forceinline__ void RankKeys( + UnsignedBits (&keys)[KEYS_PER_THREAD], + int (&ranks)[KEYS_PER_THREAD], + DigitExtractorT digit_extractor, + int (&exclusive_digit_prefix)[BINS_PER_THREAD]) + { + typedef BlockRadixRankEmptyCallback CountsCallback; + BlockRadixRankMatchInternal + internal(temp_storage, digit_extractor, CountsCallback()); + internal.RankKeys(keys, ranks, exclusive_digit_prefix); + } + + template + __device__ __forceinline__ void RankKeys( + UnsignedBits (&keys)[KEYS_PER_THREAD], + int (&ranks)[KEYS_PER_THREAD], + DigitExtractorT digit_extractor) + { + int exclusive_digit_prefix[BINS_PER_THREAD]; + RankKeys(keys, ranks, digit_extractor, exclusive_digit_prefix); + } +}; + + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document +namespace detail +{ + +// `BlockRadixRank` doesn't conform to the typical pattern, not exposing the algorithm +// template parameter. Other algorithms don't provide the same template parameters, not allowing +// multi-dimensional thread block specializations. +// +// TODO(senior-zero) for 3.0: +// - Put existing implementations into the detail namespace +// - Support multi-dimensional thread blocks in the rest of implementations +// - Repurpose BlockRadixRank as an entry name with the algorithm template parameter +template +using block_radix_rank_t = cub::detail::conditional_t< + RankAlgorithm == RADIX_RANK_BASIC, + BlockRadixRank, + cub::detail::conditional_t< + RankAlgorithm == RADIX_RANK_MEMOIZE, + BlockRadixRank, + cub::detail::conditional_t< + RankAlgorithm == RADIX_RANK_MATCH, + BlockRadixRankMatch, + cub::detail::conditional_t< + RankAlgorithm == RADIX_RANK_MATCH_EARLY_COUNTS_ANY, + BlockRadixRankMatchEarlyCounts, + BlockRadixRankMatchEarlyCounts>>>>; + +} // namespace detail +#endif // DOXYGEN_SHOULD_SKIP_THIS + + +CUB_NAMESPACE_END + + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_radix_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_radix_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..e275d6f611e9f9e642e06c2af3cc45c41f6d24f3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_radix_sort.cuh @@ -0,0 +1,2111 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * The cub::BlockRadixSort class provides [collective](index.html#sec0) methods for radix sorting of items partitioned across a CUDA thread block. + */ + + +#pragma once + +#include "block_exchange.cuh" +#include "block_radix_rank.cuh" +#include "radix_rank_sort_operations.cuh" +#include "../config.cuh" +#include "../util_ptx.cuh" +#include "../util_type.cuh" + +CUB_NAMESPACE_BEGIN + +//! @rst +//! BlockRadixSort class provides :ref:`collective ` methods for sorting +//! items partitioned across a CUDA thread block using a radix sorting method. +//! +//! .. image:: ../img/sorting_logo.png +//! :align: center +//! +//! Overview +//! -------------------------------------------------- +//! +//! The `radix sorting method `_ arranges +//! items into ascending order. It relies upon a positional representation for +//! keys, i.e., each key is comprised of an ordered sequence of symbols (e.g., digits, +//! characters, etc.) specified from least-significant to most-significant. For a +//! given input sequence of keys and a set of rules specifying a total ordering +//! of the symbolic alphabet, the radix sorting method produces a lexicographic +//! ordering of those keys. +//! +//! @rowmajor +//! +//! Supported Types +//! -------------------------------------------------- +//! +//! BlockRadixSort can sort all of the built-in C++ numeric primitive types +//! (``unsigned char``, ``int``, ``double``, etc.) as well as CUDA's ``__half`` +//! half-precision floating-point type. User-defined types are supported as long +//! as decomposer object is provided. +//! +//! Floating-Point Special Cases +//! -------------------------------------------------- +//! +//! - Positive and negative zeros are considered equivalent, and will be treated +//! as such in the output. +//! - No special handling is implemented for NaN values; these are sorted +//! according to their bit representations after any transformations. +//! +//! Bitwise Key Transformations +//! -------------------------------------------------- +//! +//! Although the direct radix sorting method can only be applied to unsigned +//! integral types, BlockRadixSort is able to sort signed and floating-point +//! types via simple bit-wise transformations that ensure lexicographic key +//! ordering. +//! +//! These transformations must be considered when restricting the +//! ``[begin_bit, end_bit)`` range, as the bitwise transformations will occur +//! before the bit-range truncation. +//! +//! Any transformations applied to the keys prior to sorting are reversed +//! while writing to the final output buffer. +//! +//! Type Specific Bitwise Transformations +//! -------------------------------------------------- +//! +//! To convert the input values into a radix-sortable bitwise representation, +//! the following transformations take place prior to sorting: +//! +//! * For unsigned integral values, the keys are used directly. +//! * For signed integral values, the sign bit is inverted. +//! * For positive floating point values, the sign bit is inverted. +//! * For negative floating point values, the full key is inverted. +//! +//! No Descending Sort Transformations +//! -------------------------------------------------- +//! +//! Unlike ``DeviceRadixSort``, ``BlockRadixSort`` does not invert the input key bits +//! when performing a descending sort. Instead, it has special logic to reverse +//! the order of the keys while sorting. +//! +//! Stability +//! -------------------------------------------------- +//! +//! BlockRadixSort is stable. For floating-point types -0.0 and +0.0 +//! are considered equal and appear in the result in the same order as they +//! appear in the input. +//! +//! +//! Performance Considerations +//! -------------------------------------------------- +//! +//! * @granularity +//! +//! A Simple Example +//! -------------------------------------------------- +//! +//! @blockcollective{BlockRadixSort} +//! +//! The code snippet below illustrates a sort of 512 integer keys that +//! are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads +//! where each thread owns 4 consecutive items. +//! +//! .. code-block:: c++ +//! +//! #include // or equivalently +//! +//! __global__ void ExampleKernel(...) +//! { +//! // Specialize BlockRadixSort for a 1D block of 128 threads owning 4 integer items each +//! typedef cub::BlockRadixSort BlockRadixSort; +//! +//! // Allocate shared memory for BlockRadixSort +//! __shared__ typename BlockRadixSort::TempStorage temp_storage; +//! +//! // Obtain a segment of consecutive items that are blocked across threads +//! int thread_keys[4]; +//! ... +//! +//! // Collectively sort the keys +//! BlockRadixSort(temp_storage).Sort(thread_keys); +//! +//! ... +//! +//! Suppose the set of input ``thread_keys`` across the block of threads is +//! ``{ [0,511,1,510], [2,509,3,508], [4,507,5,506], ..., [254,257,255,256] }``. +//! The corresponding output ``thread_keys`` in those threads will be +//! ``{ [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [508,509,510,511] }``. +//! +//! Re-using dynamically allocating shared memory +//! -------------------------------------------------- +//! +//! The following example under the examples/block folder illustrates usage of +//! dynamically shared memory with BlockReduce and how to re-purpose +//! the same memory region: +//! example_block_reduce_dyn_smem.cu +//! +//! This example can be easily adapted to the storage required by BlockRadixSort. +//! @endrst +//! +//! @ingroup BlockModule +//! +//! @tparam KeyT +//! KeyT type +//! +//! @tparam BLOCK_DIM_X +//! The thread block length in threads along the X dimension +//! +//! @tparam ITEMS_PER_THREAD +//! The number of items per thread +//! +//! @tparam ValueT +//! **[optional]** ValueT type (default: cub::NullType, which indicates a keys-only sort) +//! +//! @tparam RADIX_BITS +//! **[optional]** The number of radix bits per digit place (default: 4 bits) +//! +//! @tparam MEMOIZE_OUTER_SCAN +//! **[optional]** Whether or not to buffer outer raking scan partials to incur fewer shared memory +//! reads at the expense of higher register pressure (default: true for architectures SM35 and +//! newer, false otherwise). +//! +//! @tparam INNER_SCAN_ALGORITHM +//! **[optional]** The cub::BlockScanAlgorithm algorithm to use +//! (default: cub::BLOCK_SCAN_WARP_SCANS) +//! +//! @tparam SMEM_CONFIG +//! **[optional]*8 Shared memory bank mode (default: `cudaSharedMemBankSizeFourByte`) +//! +//! @tparam BLOCK_DIM_Y +//! **[optional]** The thread block length in threads along the Y dimension (default: 1) +//! +//! @tparam BLOCK_DIM_Z +//! **[optional]** The thread block length in threads along the Z dimension (default: 1) +//! +//! @tparam LEGACY_PTX_ARCH +//! **[optional]** Unused +template < + typename KeyT, + int BLOCK_DIM_X, + int ITEMS_PER_THREAD, + typename ValueT = NullType, + int RADIX_BITS = 4, + bool MEMOIZE_OUTER_SCAN = true, + BlockScanAlgorithm INNER_SCAN_ALGORITHM = BLOCK_SCAN_WARP_SCANS, + cudaSharedMemConfig SMEM_CONFIG = cudaSharedMemBankSizeFourByte, + int BLOCK_DIM_Y = 1, + int BLOCK_DIM_Z = 1, + int LEGACY_PTX_ARCH = 0> +class BlockRadixSort +{ +private: + + /****************************************************************************** + * Constants and type definitions + ******************************************************************************/ + + enum + { + // The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + + // Whether or not there are values to be trucked along with keys + KEYS_ONLY = std::is_same::value, + }; + + // KeyT traits and unsigned bits type + using traits = detail::radix::traits_t; + using bit_ordered_type = typename traits::bit_ordered_type; + using bit_ordered_conversion = typename traits::bit_ordered_conversion_policy; + + /// Ascending BlockRadixRank utility type + typedef BlockRadixRank< + BLOCK_DIM_X, + RADIX_BITS, + false, + MEMOIZE_OUTER_SCAN, + INNER_SCAN_ALGORITHM, + SMEM_CONFIG, + BLOCK_DIM_Y, + BLOCK_DIM_Z> + AscendingBlockRadixRank; + + /// Descending BlockRadixRank utility type + typedef BlockRadixRank< + BLOCK_DIM_X, + RADIX_BITS, + true, + MEMOIZE_OUTER_SCAN, + INNER_SCAN_ALGORITHM, + SMEM_CONFIG, + BLOCK_DIM_Y, + BLOCK_DIM_Z> + DescendingBlockRadixRank; + + /// Digit extractor type + using fundamental_digit_extractor_t = BFEDigitExtractor; + + /// BlockExchange utility type for keys + typedef BlockExchange BlockExchangeKeys; + + /// BlockExchange utility type for values + typedef BlockExchange BlockExchangeValues; + + /// Shared memory storage layout type + union _TempStorage + { + typename AscendingBlockRadixRank::TempStorage asending_ranking_storage; + typename DescendingBlockRadixRank::TempStorage descending_ranking_storage; + typename BlockExchangeKeys::TempStorage exchange_keys; + typename BlockExchangeValues::TempStorage exchange_values; + }; + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Linear thread-id + unsigned int linear_tid; + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + /// Rank keys (specialized for ascending sort) + template + __device__ __forceinline__ void RankKeys( + bit_ordered_type (&unsigned_keys)[ITEMS_PER_THREAD], + int (&ranks)[ITEMS_PER_THREAD], + DigitExtractorT digit_extractor, + Int2Type /*is_descending*/) + { + AscendingBlockRadixRank(temp_storage.asending_ranking_storage).RankKeys( + unsigned_keys, + ranks, + digit_extractor); + } + + /// Rank keys (specialized for descending sort) + template + __device__ __forceinline__ void RankKeys( + bit_ordered_type (&unsigned_keys)[ITEMS_PER_THREAD], + int (&ranks)[ITEMS_PER_THREAD], + DigitExtractorT digit_extractor, + Int2Type /*is_descending*/) + { + DescendingBlockRadixRank(temp_storage.descending_ranking_storage).RankKeys( + unsigned_keys, + ranks, + digit_extractor); + } + + /// ExchangeValues (specialized for key-value sort, to-blocked arrangement) + __device__ __forceinline__ void ExchangeValues( + ValueT (&values)[ITEMS_PER_THREAD], + int (&ranks)[ITEMS_PER_THREAD], + Int2Type /*is_keys_only*/, + Int2Type /*is_blocked*/) + { + CTA_SYNC(); + + // Exchange values through shared memory in blocked arrangement + BlockExchangeValues(temp_storage.exchange_values).ScatterToBlocked(values, ranks); + } + + /// ExchangeValues (specialized for key-value sort, to-striped arrangement) + __device__ __forceinline__ void ExchangeValues( + ValueT (&values)[ITEMS_PER_THREAD], + int (&ranks)[ITEMS_PER_THREAD], + Int2Type /*is_keys_only*/, + Int2Type /*is_blocked*/) + { + CTA_SYNC(); + + // Exchange values through shared memory in blocked arrangement + BlockExchangeValues(temp_storage.exchange_values).ScatterToStriped(values, ranks); + } + + /// ExchangeValues (specialized for keys-only sort) + template + __device__ __forceinline__ void ExchangeValues( + ValueT (&/*values*/)[ITEMS_PER_THREAD], + int (&/*ranks*/)[ITEMS_PER_THREAD], + Int2Type /*is_keys_only*/, + Int2Type /*is_blocked*/) + {} + + /// Sort blocked arrangement + template + __device__ __forceinline__ void SortBlocked( + KeyT (&keys)[ITEMS_PER_THREAD], ///< Keys to sort + ValueT (&values)[ITEMS_PER_THREAD], ///< Values to sort + int begin_bit, ///< The beginning (least-significant) bit index needed for key comparison + int end_bit, ///< The past-the-end (most-significant) bit index needed for key comparison + Int2Type is_descending, ///< Tag whether is a descending-order sort + Int2Type is_keys_only, ///< Tag whether is keys-only sort + DecomposerT decomposer = {}) + { + bit_ordered_type (&unsigned_keys)[ITEMS_PER_THREAD] = + reinterpret_cast(keys); + + #pragma unroll + for (int KEY = 0; KEY < ITEMS_PER_THREAD; KEY++) + { + unsigned_keys[KEY] = bit_ordered_conversion::to_bit_ordered(decomposer, unsigned_keys[KEY]); + } + + // Radix sorting passes + while (true) + { + int pass_bits = CUB_MIN(RADIX_BITS, end_bit - begin_bit); + auto digit_extractor = traits::template digit_extractor(begin_bit, pass_bits, decomposer); + + // Rank the blocked keys + int ranks[ITEMS_PER_THREAD]; + RankKeys(unsigned_keys, ranks, digit_extractor, is_descending); + begin_bit += RADIX_BITS; + + CTA_SYNC(); + + // Exchange keys through shared memory in blocked arrangement + BlockExchangeKeys(temp_storage.exchange_keys).ScatterToBlocked(keys, ranks); + + // Exchange values through shared memory in blocked arrangement + ExchangeValues(values, ranks, is_keys_only, Int2Type()); + + // Quit if done + if (begin_bit >= end_bit) break; + + CTA_SYNC(); + } + + // Untwiddle bits if necessary + #pragma unroll + for (int KEY = 0; KEY < ITEMS_PER_THREAD; KEY++) + { + unsigned_keys[KEY] = bit_ordered_conversion::from_bit_ordered(decomposer, unsigned_keys[KEY]); + } + } + +public: + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + + /// Sort blocked -> striped arrangement + template + __device__ __forceinline__ void SortBlockedToStriped( + KeyT (&keys)[ITEMS_PER_THREAD], ///< Keys to sort + ValueT (&values)[ITEMS_PER_THREAD], ///< Values to sort + int begin_bit, ///< The beginning (least-significant) bit index needed for key comparison + int end_bit, ///< The past-the-end (most-significant) bit index needed for key comparison + Int2Type is_descending, ///< Tag whether is a descending-order sort + Int2Type is_keys_only, ///< Tag whether is keys-only sort + DecomposerT decomposer = {}) + { + bit_ordered_type (&unsigned_keys)[ITEMS_PER_THREAD] = + reinterpret_cast(keys); + + #pragma unroll + for (int KEY = 0; KEY < ITEMS_PER_THREAD; KEY++) + { + unsigned_keys[KEY] = bit_ordered_conversion::to_bit_ordered(decomposer, unsigned_keys[KEY]); + } + + // Radix sorting passes + while (true) + { + int pass_bits = CUB_MIN(RADIX_BITS, end_bit - begin_bit); + auto digit_extractor = traits::template digit_extractor(begin_bit, pass_bits, decomposer); + + // Rank the blocked keys + int ranks[ITEMS_PER_THREAD]; + RankKeys(unsigned_keys, ranks, digit_extractor, is_descending); + begin_bit += RADIX_BITS; + + CTA_SYNC(); + + // Check if this is the last pass + if (begin_bit >= end_bit) + { + // Last pass exchanges keys through shared memory in striped arrangement + BlockExchangeKeys(temp_storage.exchange_keys).ScatterToStriped(keys, ranks); + + // Last pass exchanges through shared memory in striped arrangement + ExchangeValues(values, ranks, is_keys_only, Int2Type()); + + // Quit + break; + } + + // Exchange keys through shared memory in blocked arrangement + BlockExchangeKeys(temp_storage.exchange_keys).ScatterToBlocked(keys, ranks); + + // Exchange values through shared memory in blocked arrangement + ExchangeValues(values, ranks, is_keys_only, Int2Type()); + + CTA_SYNC(); + } + + // Untwiddle bits if necessary + #pragma unroll + for (int KEY = 0; KEY < ITEMS_PER_THREAD; KEY++) + { + unsigned_keys[KEY] = bit_ordered_conversion::from_bit_ordered(decomposer, unsigned_keys[KEY]); + } + } + +#endif // DOXYGEN_SHOULD_SKIP_THIS + + /// \smemstorage{BlockRadixSort} + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /******************************************************************//** + * \name Collective constructors + *********************************************************************/ + //@{ + + /** + * \brief Collective constructor using a private static allocation of shared memory as temporary storage. + */ + __device__ __forceinline__ BlockRadixSort() + : + temp_storage(PrivateStorage()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + /** + * \brief Collective constructor using the specified memory allocation as temporary storage. + */ + __device__ __forceinline__ BlockRadixSort( + TempStorage &temp_storage) ///< [in] Reference to memory allocation having layout type TempStorage + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + //@} end member group + /******************************************************************//** + * \name Sorting (blocked arrangements) + *********************************************************************/ + //@{ + + /** + * \brief Performs an ascending block-wide radix sort over a [blocked arrangement](index.html#sec5sec3) of keys. + * + * \par + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a sort of 512 integer keys that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive keys. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockRadixSort for a 1D block of 128 threads owning 4 integer keys each + * typedef cub::BlockRadixSort BlockRadixSort; + * + * // Allocate shared memory for BlockRadixSort + * __shared__ typename BlockRadixSort::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_keys[4]; + * ... + * + * // Collectively sort the keys + * BlockRadixSort(temp_storage).Sort(thread_keys); + * + * \endcode + * \par + * Suppose the set of input \p thread_keys across the block of threads is + * { [0,511,1,510], [2,509,3,508], [4,507,5,506], ..., [254,257,255,256] }. + * The corresponding output \p thread_keys in those threads will be + * { [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [508,509,510,511] }. + */ + __device__ __forceinline__ void Sort( + KeyT (&keys)[ITEMS_PER_THREAD], ///< [in-out] Keys to sort + int begin_bit = 0, ///< [in] [optional] The beginning (least-significant) bit index needed for key comparison + int end_bit = sizeof(KeyT) * 8) ///< [in] [optional] The past-the-end (most-significant) bit index needed for key comparison + { + NullType values[ITEMS_PER_THREAD]; + + SortBlocked(keys, values, begin_bit, end_bit, Int2Type(), Int2Type()); + } + + //! @rst + //! Performs an ascending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 2 keys that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 1 key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-bits + //! :end-before: example-end keys-bits + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + Sort(KeyT (&keys)[ITEMS_PER_THREAD], DecomposerT decomposer, int begin_bit, int end_bit) + { + NullType values[ITEMS_PER_THREAD]; + + SortBlocked(keys, + values, + begin_bit, + end_bit, + Int2Type(), + Int2Type(), + decomposer); + } + + //! @rst + //! Performs an ascending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 6 keys that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 3 consecutive keys. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys + //! :end-before: example-end keys + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + Sort(KeyT (&keys)[ITEMS_PER_THREAD], DecomposerT decomposer) + { + Sort(keys, decomposer, 0, detail::radix::traits_t::default_end_bit(decomposer)); + } + + /** + * \brief Performs an ascending block-wide radix sort across a [blocked arrangement](index.html#sec5sec3) of keys and values. + * + * \par + * - BlockRadixSort can only accommodate one associated tile of values. To "truck along" + * more than one tile of values, simply perform a key-value sort of the keys paired + * with a temporary value array that enumerates the key indices. The reordered indices + * can then be used as a gather-vector for exchanging other associated tile data through + * shared memory. + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a sort of 512 integer keys and values that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive pairs. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockRadixSort for a 1D block of 128 threads owning 4 integer keys and values each + * typedef cub::BlockRadixSort BlockRadixSort; + * + * // Allocate shared memory for BlockRadixSort + * __shared__ typename BlockRadixSort::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_keys[4]; + * int thread_values[4]; + * ... + * + * // Collectively sort the keys and values among block threads + * BlockRadixSort(temp_storage).Sort(thread_keys, thread_values); + * + * \endcode + * \par + * Suppose the set of input \p thread_keys across the block of threads is + * { [0,511,1,510], [2,509,3,508], [4,507,5,506], ..., [254,257,255,256] }. The + * corresponding output \p thread_keys in those threads will be + * { [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [508,509,510,511] }. + * + */ + __device__ __forceinline__ void Sort( + KeyT (&keys)[ITEMS_PER_THREAD], ///< [in-out] Keys to sort + ValueT (&values)[ITEMS_PER_THREAD], ///< [in-out] Values to sort + int begin_bit = 0, ///< [in] [optional] The beginning (least-significant) bit index needed for key comparison + int end_bit = sizeof(KeyT) * 8) ///< [in] [optional] The past-the-end (most-significant) bit index needed for key comparison + { + SortBlocked(keys, values, begin_bit, end_bit, Int2Type(), Int2Type()); + } + + //! @rst + //! Performs an ascending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys and values. + //! + //! * BlockRadixSort can only accommodate one associated tile of values. To "truck along" + //! more than one tile of values, simply perform a key-value sort of the keys paired + //! with a temporary value array that enumerates the key indices. The reordered indices + //! can then be used as a gather-vector for exchanging other associated tile data through + //! shared memory. + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 2 keys and values that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 1 pair. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-bits + //! :end-before: example-end pairs-bits + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param[in,out] values + //! Values to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + Sort(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&values)[ITEMS_PER_THREAD], + DecomposerT decomposer, + int begin_bit, + int end_bit) + { + SortBlocked(keys, + values, + begin_bit, + end_bit, + Int2Type(), + Int2Type(), + decomposer); + } + + //! @rst + //! Performs an ascending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys and values. + //! + //! * BlockRadixSort can only accommodate one associated tile of values. To "truck along" + //! more than one tile of values, simply perform a key-value sort of the keys paired + //! with a temporary value array that enumerates the key indices. The reordered indices + //! can then be used as a gather-vector for exchanging other associated tile data through + //! shared memory. + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 6 keys and values that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 3 consecutive pairs. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs + //! :end-before: example-end pairs + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param[in,out] values + //! Values to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + Sort(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&values)[ITEMS_PER_THREAD], + DecomposerT decomposer) + { + Sort(keys, + values, + decomposer, + 0, + detail::radix::traits_t::default_end_bit(decomposer)); + } + + /** + * \brief Performs a descending block-wide radix sort over a [blocked arrangement](index.html#sec5sec3) of keys. + * + * \par + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a sort of 512 integer keys that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive keys. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockRadixSort for a 1D block of 128 threads owning 4 integer keys each + * typedef cub::BlockRadixSort BlockRadixSort; + * + * // Allocate shared memory for BlockRadixSort + * __shared__ typename BlockRadixSort::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_keys[4]; + * ... + * + * // Collectively sort the keys + * BlockRadixSort(temp_storage).Sort(thread_keys); + * + * \endcode + * \par + * Suppose the set of input \p thread_keys across the block of threads is + * { [0,511,1,510], [2,509,3,508], [4,507,5,506], ..., [254,257,255,256] }. + * The corresponding output \p thread_keys in those threads will be + * { [511,510,509,508], [11,10,9,8], [7,6,5,4], ..., [3,2,1,0] }. + */ + __device__ __forceinline__ void SortDescending( + KeyT (&keys)[ITEMS_PER_THREAD], ///< [in-out] Keys to sort + int begin_bit = 0, ///< [in] [optional] The beginning (least-significant) bit index needed for key comparison + int end_bit = sizeof(KeyT) * 8) ///< [in] [optional] The past-the-end (most-significant) bit index needed for key comparison + { + NullType values[ITEMS_PER_THREAD]; + + SortBlocked(keys, values, begin_bit, end_bit, Int2Type(), Int2Type()); + } + + //! @rst + //! Performs a descending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 2 keys that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 1 key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-descending-bits + //! :end-before: example-end keys-descending-bits + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortDescending(KeyT (&keys)[ITEMS_PER_THREAD], + DecomposerT decomposer, + int begin_bit, + int end_bit) + { + NullType values[ITEMS_PER_THREAD]; + + SortBlocked(keys, + values, + begin_bit, + end_bit, + Int2Type(), + Int2Type(), + decomposer); + } + + //! @rst + //! Performs a descending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 6 keys that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 3 consecutive keys. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-descending + //! :end-before: example-end keys-descending + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortDescending(KeyT (&keys)[ITEMS_PER_THREAD], DecomposerT decomposer) + { + NullType values[ITEMS_PER_THREAD]; + + SortBlocked(keys, + values, + 0, + detail::radix::traits_t::default_end_bit(decomposer), + Int2Type(), + Int2Type(), + decomposer); + } + + /** + * \brief Performs a descending block-wide radix sort across a [blocked arrangement](index.html#sec5sec3) of keys and values. + * + * \par + * - BlockRadixSort can only accommodate one associated tile of values. To "truck along" + * more than one tile of values, simply perform a key-value sort of the keys paired + * with a temporary value array that enumerates the key indices. The reordered indices + * can then be used as a gather-vector for exchanging other associated tile data through + * shared memory. + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a sort of 512 integer keys and values that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive pairs. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockRadixSort for a 1D block of 128 threads owning 4 integer keys and values each + * typedef cub::BlockRadixSort BlockRadixSort; + * + * // Allocate shared memory for BlockRadixSort + * __shared__ typename BlockRadixSort::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_keys[4]; + * int thread_values[4]; + * ... + * + * // Collectively sort the keys and values among block threads + * BlockRadixSort(temp_storage).Sort(thread_keys, thread_values); + * + * \endcode + * \par + * Suppose the set of input \p thread_keys across the block of threads is + * { [0,511,1,510], [2,509,3,508], [4,507,5,506], ..., [254,257,255,256] }. The + * corresponding output \p thread_keys in those threads will be + * { [511,510,509,508], [11,10,9,8], [7,6,5,4], ..., [3,2,1,0] }. + * + */ + __device__ __forceinline__ void SortDescending( + KeyT (&keys)[ITEMS_PER_THREAD], ///< [in-out] Keys to sort + ValueT (&values)[ITEMS_PER_THREAD], ///< [in-out] Values to sort + int begin_bit = 0, ///< [in] [optional] The beginning (least-significant) bit index needed for key comparison + int end_bit = sizeof(KeyT) * 8) ///< [in] [optional] The past-the-end (most-significant) bit index needed for key comparison + { + SortBlocked(keys, values, begin_bit, end_bit, Int2Type(), Int2Type()); + } + + //! @rst + //! Performs a descending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys and values. + //! + //! * BlockRadixSort can only accommodate one associated tile of values. To "truck along" + //! more than one tile of values, simply perform a key-value sort of the keys paired + //! with a temporary value array that enumerates the key indices. The reordered indices + //! can then be used as a gather-vector for exchanging other associated tile data through + //! shared memory. + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 2 pairs that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 1 pair. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-descending-bits + //! :end-before: example-end pairs-descending-bits + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param[in,out] values + //! Values to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortDescending(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&values)[ITEMS_PER_THREAD], + DecomposerT decomposer, + int begin_bit, + int end_bit) + { + SortBlocked(keys, + values, + begin_bit, + end_bit, + Int2Type(), + Int2Type(), + decomposer); + } + + //! @rst + //! Performs a descending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys and values. + //! + //! * BlockRadixSort can only accommodate one associated tile of values. To "truck along" + //! more than one tile of values, simply perform a key-value sort of the keys paired + //! with a temporary value array that enumerates the key indices. The reordered indices + //! can then be used as a gather-vector for exchanging other associated tile data through + //! shared memory. + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 6 keys and values that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 3 consecutive pairs. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-descending + //! :end-before: example-end pairs-descending + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param[in,out] values + //! Values to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortDescending(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&values)[ITEMS_PER_THREAD], + DecomposerT decomposer) + { + SortBlocked(keys, + values, + 0, + detail::radix::traits_t::default_end_bit(decomposer), + Int2Type(), + Int2Type(), + decomposer); + } + + //@} end member group + /******************************************************************//** + * \name Sorting (blocked arrangement -> striped arrangement) + *********************************************************************/ + //@{ + + + /** + * \brief Performs an ascending radix sort across a [blocked arrangement](index.html#sec5sec3) of keys, leaving them in a [striped arrangement](index.html#sec5sec3). + * + * \par + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a sort of 512 integer keys that + * are initially partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive keys. The final partitioning is striped. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockRadixSort for a 1D block of 128 threads owning 4 integer keys each + * typedef cub::BlockRadixSort BlockRadixSort; + * + * // Allocate shared memory for BlockRadixSort + * __shared__ typename BlockRadixSort::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_keys[4]; + * ... + * + * // Collectively sort the keys + * BlockRadixSort(temp_storage).SortBlockedToStriped(thread_keys); + * + * \endcode + * \par + * Suppose the set of input \p thread_keys across the block of threads is + * { [0,511,1,510], [2,509,3,508], [4,507,5,506], ..., [254,257,255,256] }. The + * corresponding output \p thread_keys in those threads will be + * { [0,128,256,384], [1,129,257,385], [2,130,258,386], ..., [127,255,383,511] }. + * + */ + __device__ __forceinline__ void SortBlockedToStriped( + KeyT (&keys)[ITEMS_PER_THREAD], ///< [in-out] Keys to sort + int begin_bit = 0, ///< [in] [optional] The beginning (least-significant) bit index needed for key comparison + int end_bit = sizeof(KeyT) * 8) ///< [in] [optional] The past-the-end (most-significant) bit index needed for key comparison + { + NullType values[ITEMS_PER_THREAD]; + + SortBlockedToStriped(keys, values, begin_bit, end_bit, Int2Type(), Int2Type()); + } + + //! @rst + //! Performs an ascending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys, leaving them in a + //! :ref:`striped arrangement `. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 4 keys that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 2 consecutive keys. The final partitioning is striped. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-striped-bits + //! :end-before: example-end keys-striped-bits + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortBlockedToStriped(KeyT (&keys)[ITEMS_PER_THREAD], + DecomposerT decomposer, + int begin_bit, + int end_bit) + { + NullType values[ITEMS_PER_THREAD]; + + SortBlockedToStriped(keys, + values, + begin_bit, + end_bit, + Int2Type(), + Int2Type(), + decomposer); + } + + //! @rst + //! Performs an ascending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys, leaving them in a + //! :ref:`striped arrangement `. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 6 keys that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 3 consecutive keys. The final partitioning is striped. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-striped + //! :end-before: example-end keys-striped + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortBlockedToStriped(KeyT (&keys)[ITEMS_PER_THREAD], DecomposerT decomposer) + { + NullType values[ITEMS_PER_THREAD]; + + SortBlockedToStriped(keys, + values, + 0, + detail::radix::traits_t::default_end_bit(decomposer), + Int2Type(), + Int2Type(), + decomposer); + } + + /** + * \brief Performs an ascending radix sort across a [blocked arrangement](index.html#sec5sec3) of keys and values, leaving them in a [striped arrangement](index.html#sec5sec3). + * + * \par + * - BlockRadixSort can only accommodate one associated tile of values. To "truck along" + * more than one tile of values, simply perform a key-value sort of the keys paired + * with a temporary value array that enumerates the key indices. The reordered indices + * can then be used as a gather-vector for exchanging other associated tile data through + * shared memory. + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a sort of 512 integer keys and values that + * are initially partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive pairs. The final partitioning is striped. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockRadixSort for a 1D block of 128 threads owning 4 integer keys and values each + * typedef cub::BlockRadixSort BlockRadixSort; + * + * // Allocate shared memory for BlockRadixSort + * __shared__ typename BlockRadixSort::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_keys[4]; + * int thread_values[4]; + * ... + * + * // Collectively sort the keys and values among block threads + * BlockRadixSort(temp_storage).SortBlockedToStriped(thread_keys, thread_values); + * + * \endcode + * \par + * Suppose the set of input \p thread_keys across the block of threads is + * { [0,511,1,510], [2,509,3,508], [4,507,5,506], ..., [254,257,255,256] }. The + * corresponding output \p thread_keys in those threads will be + * { [0,128,256,384], [1,129,257,385], [2,130,258,386], ..., [127,255,383,511] }. + * + */ + __device__ __forceinline__ void SortBlockedToStriped( + KeyT (&keys)[ITEMS_PER_THREAD], ///< [in-out] Keys to sort + ValueT (&values)[ITEMS_PER_THREAD], ///< [in-out] Values to sort + int begin_bit = 0, ///< [in] [optional] The beginning (least-significant) bit index needed for key comparison + int end_bit = sizeof(KeyT) * 8) ///< [in] [optional] The past-the-end (most-significant) bit index needed for key comparison + { + SortBlockedToStriped(keys, values, begin_bit, end_bit, Int2Type(), Int2Type()); + } + + //! @rst + //! Performs an ascending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys and values, leaving them in a + //! :ref:`striped arrangement `. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 4 pairs that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 2 consecutive pairs. The final partitioning is striped. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-striped-bits + //! :end-before: example-end pairs-striped-bits + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param[in,out] values + //! Values to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortBlockedToStriped(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&values)[ITEMS_PER_THREAD], + DecomposerT decomposer, + int begin_bit, + int end_bit) + { + SortBlockedToStriped(keys, + values, + begin_bit, + end_bit, + Int2Type(), + Int2Type(), + decomposer); + } + + //! @rst + //! Performs an ascending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys and values, leaving them in a + //! :ref:`striped arrangement `. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 6 pairs that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 3 consecutive pairs. The final partitioning is striped. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-striped + //! :end-before: example-end pairs-striped + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param[in,out] values + //! Values to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortBlockedToStriped(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&values)[ITEMS_PER_THREAD], + DecomposerT decomposer) + { + SortBlockedToStriped(keys, + values, + 0, + detail::radix::traits_t::default_end_bit(decomposer), + Int2Type(), + Int2Type(), + decomposer); + } + + /** + * \brief Performs a descending radix sort across a [blocked arrangement](index.html#sec5sec3) of keys, leaving them in a [striped arrangement](index.html#sec5sec3). + * + * \par + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a sort of 512 integer keys that + * are initially partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive keys. The final partitioning is striped. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockRadixSort for a 1D block of 128 threads owning 4 integer keys each + * typedef cub::BlockRadixSort BlockRadixSort; + * + * // Allocate shared memory for BlockRadixSort + * __shared__ typename BlockRadixSort::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_keys[4]; + * ... + * + * // Collectively sort the keys + * BlockRadixSort(temp_storage).SortBlockedToStriped(thread_keys); + * + * \endcode + * \par + * Suppose the set of input \p thread_keys across the block of threads is + * { [0,511,1,510], [2,509,3,508], [4,507,5,506], ..., [254,257,255,256] }. The + * corresponding output \p thread_keys in those threads will be + * { [511,383,255,127], [386,258,130,2], [385,257,128,1], ..., [384,256,128,0] }. + * + */ + __device__ __forceinline__ void SortDescendingBlockedToStriped( + KeyT (&keys)[ITEMS_PER_THREAD], ///< [in-out] Keys to sort + int begin_bit = 0, ///< [in] [optional] The beginning (least-significant) bit index needed for key comparison + int end_bit = sizeof(KeyT) * 8) ///< [in] [optional] The past-the-end (most-significant) bit index needed for key comparison + { + NullType values[ITEMS_PER_THREAD]; + + SortBlockedToStriped(keys, values, begin_bit, end_bit, Int2Type(), Int2Type()); + } + + //! @rst + //! Performs a descending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys, leaving them in a + //! :ref:`striped arrangement `. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 4 keys that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 2 consecutive keys. The final partitioning is striped. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-striped-descending-bits + //! :end-before: example-end keys-striped-descending-bits + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortDescendingBlockedToStriped(KeyT (&keys)[ITEMS_PER_THREAD], + DecomposerT decomposer, + int begin_bit, + int end_bit) + { + NullType values[ITEMS_PER_THREAD]; + + SortBlockedToStriped(keys, + values, + begin_bit, + end_bit, + Int2Type(), + Int2Type(), + decomposer); + } + + //! @rst + //! Performs a descending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys, leaving them in a + //! :ref:`striped arrangement `. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 6 keys that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 3 consecutive keys. The final partitioning is striped. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-striped-descending + //! :end-before: example-end keys-striped-descending + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortDescendingBlockedToStriped(KeyT (&keys)[ITEMS_PER_THREAD], DecomposerT decomposer) + { + NullType values[ITEMS_PER_THREAD]; + + SortBlockedToStriped(keys, + values, + 0, + detail::radix::traits_t::default_end_bit(decomposer), + Int2Type(), + Int2Type(), + decomposer); + } + + /** + * \brief Performs a descending radix sort across a [blocked arrangement](index.html#sec5sec3) of keys and values, leaving them in a [striped arrangement](index.html#sec5sec3). + * + * \par + * - BlockRadixSort can only accommodate one associated tile of values. To "truck along" + * more than one tile of values, simply perform a key-value sort of the keys paired + * with a temporary value array that enumerates the key indices. The reordered indices + * can then be used as a gather-vector for exchanging other associated tile data through + * shared memory. + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a sort of 512 integer keys and values that + * are initially partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive pairs. The final partitioning is striped. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockRadixSort for a 1D block of 128 threads owning 4 integer keys and values each + * typedef cub::BlockRadixSort BlockRadixSort; + * + * // Allocate shared memory for BlockRadixSort + * __shared__ typename BlockRadixSort::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_keys[4]; + * int thread_values[4]; + * ... + * + * // Collectively sort the keys and values among block threads + * BlockRadixSort(temp_storage).SortBlockedToStriped(thread_keys, thread_values); + * + * \endcode + * \par + * Suppose the set of input \p thread_keys across the block of threads is + * { [0,511,1,510], [2,509,3,508], [4,507,5,506], ..., [254,257,255,256] }. The + * corresponding output \p thread_keys in those threads will be + * { [511,383,255,127], [386,258,130,2], [385,257,128,1], ..., [384,256,128,0] }. + * + */ + __device__ __forceinline__ void SortDescendingBlockedToStriped( + KeyT (&keys)[ITEMS_PER_THREAD], ///< [in-out] Keys to sort + ValueT (&values)[ITEMS_PER_THREAD], ///< [in-out] Values to sort + int begin_bit = 0, ///< [in] [optional] The beginning (least-significant) bit index needed for key comparison + int end_bit = sizeof(KeyT) * 8) ///< [in] [optional] The past-the-end (most-significant) bit index needed for key comparison + { + SortBlockedToStriped(keys, values, begin_bit, end_bit, Int2Type(), Int2Type()); + } + + //! @rst + //! Performs a descending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys and values, leaving them in a + //! :ref:`striped arrangement `. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 4 keys and values that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 2 consecutive pairs. The final partitioning is striped. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-striped-descending-bits + //! :end-before: example-end pairs-striped-descending-bits + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param[in,out] values + //! Values to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortDescendingBlockedToStriped(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&values)[ITEMS_PER_THREAD], + DecomposerT decomposer, + int begin_bit, + int end_bit) + { + SortBlockedToStriped(keys, + values, + begin_bit, + end_bit, + Int2Type(), + Int2Type(), + decomposer); + } + + //! @rst + //! Performs a descending block-wide radix sort over a + //! :ref:`blocked arrangement ` of keys and values, leaving them in a + //! :ref:`striped arrangement `. + //! + //! * @granularity + //! * @smemreuse + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The code snippet below illustrates a sort of 6 keys and values that + //! are partitioned in a :ref:`blocked arrangement ` across 2 threads + //! where each thread owns 3 consecutive pairs. The final partitioning is striped. + //! + //! .. literalinclude:: ../../test/catch2_test_block_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-striped-descending + //! :end-before: example-end pairs-striped-descending + //! + //! @endrst + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in,out] keys + //! Keys to sort + //! + //! @param[in,out] values + //! Values to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + template + __device__ __forceinline__ // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value>::type + SortDescendingBlockedToStriped(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&values)[ITEMS_PER_THREAD], + DecomposerT decomposer) + { + SortBlockedToStriped(keys, + values, + 0, + detail::radix::traits_t::default_end_bit(decomposer), + Int2Type(), + Int2Type(), + decomposer); + } + + //@} end member group + +}; + +/** + * \example example_block_radix_sort.cu + */ + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_raking_layout.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_raking_layout.cuh new file mode 100644 index 0000000000000000000000000000000000000000..4d49f54f2c8a90071c38f9a011a9933792bb84ed --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_raking_layout.cuh @@ -0,0 +1,145 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::BlockRakingLayout provides a conflict-free shared memory layout abstraction for warp-raking across thread block data. + */ + + +#pragma once + +#include "../config.cuh" +#include "../util_type.cuh" + +CUB_NAMESPACE_BEGIN + +/** + * \brief BlockRakingLayout provides a conflict-free shared memory layout abstraction for 1D raking across thread block data. ![](raking.png) + * \ingroup BlockModule + * + * \par Overview + * This type facilitates a shared memory usage pattern where a block of CUDA + * threads places elements into shared memory and then reduces the active + * parallelism to one "raking" warp of threads for serially aggregating consecutive + * sequences of shared items. Padding is inserted to eliminate bank conflicts + * (for most data types). + * + * \tparam T The data type to be exchanged. + * \tparam BLOCK_THREADS The thread block size in threads. + * \tparam LEGACY_PTX_ARCH [optional] Unused. + */ +template < + typename T, + int BLOCK_THREADS, + int LEGACY_PTX_ARCH = 0> +struct BlockRakingLayout +{ + //--------------------------------------------------------------------- + // Constants and type definitions + //--------------------------------------------------------------------- + + enum + { + /// The total number of elements that need to be cooperatively reduced + SHARED_ELEMENTS = BLOCK_THREADS, + + /// Maximum number of warp-synchronous raking threads + MAX_RAKING_THREADS = CUB_MIN(BLOCK_THREADS, CUB_WARP_THREADS(0)), + + /// Number of raking elements per warp-synchronous raking thread (rounded up) + SEGMENT_LENGTH = (SHARED_ELEMENTS + MAX_RAKING_THREADS - 1) / MAX_RAKING_THREADS, + + /// Never use a raking thread that will have no valid data (e.g., when BLOCK_THREADS is 62 and SEGMENT_LENGTH is 2, we should only use 31 raking threads) + RAKING_THREADS = (SHARED_ELEMENTS + SEGMENT_LENGTH - 1) / SEGMENT_LENGTH, + + /// Whether we will have bank conflicts (technically we should find out if the GCD is > 1) + HAS_CONFLICTS = (CUB_SMEM_BANKS(0) % SEGMENT_LENGTH == 0), + + /// Degree of bank conflicts (e.g., 4-way) + CONFLICT_DEGREE = (HAS_CONFLICTS) ? + (MAX_RAKING_THREADS * SEGMENT_LENGTH) / CUB_SMEM_BANKS(0) : + 1, + + /// Pad each segment length with one element if segment length is not relatively prime to warp size and can't be optimized as a vector load + USE_SEGMENT_PADDING = ((SEGMENT_LENGTH & 1) == 0) && (SEGMENT_LENGTH > 2), + + /// Total number of elements in the raking grid + GRID_ELEMENTS = RAKING_THREADS * (SEGMENT_LENGTH + USE_SEGMENT_PADDING), + + /// Whether or not we need bounds checking during raking (the number of reduction elements is not a multiple of the number of raking threads) + UNGUARDED = (SHARED_ELEMENTS % RAKING_THREADS == 0), + }; + + + /** + * \brief Shared memory storage type + */ + struct __align__(16) _TempStorage + { + T buff[BlockRakingLayout::GRID_ELEMENTS]; + }; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /** + * \brief Returns the location for the calling thread to place data into the grid + */ + static __device__ __forceinline__ T* PlacementPtr( + TempStorage &temp_storage, + unsigned int linear_tid) + { + // Offset for partial + unsigned int offset = linear_tid; + + // Add in one padding element for every segment + if (USE_SEGMENT_PADDING > 0) + { + offset += offset / SEGMENT_LENGTH; + } + + // Incorporating a block of padding partials every shared memory segment + return temp_storage.Alias().buff + offset; + } + + + /** + * \brief Returns the location for the calling thread to begin sequential raking + */ + static __device__ __forceinline__ T* RakingPtr( + TempStorage &temp_storage, + unsigned int linear_tid) + { + return temp_storage.Alias().buff + (linear_tid * (SEGMENT_LENGTH + USE_SEGMENT_PADDING)); + } +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_reduce.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_reduce.cuh new file mode 100644 index 0000000000000000000000000000000000000000..5a9db703db9f5ff86fcfa8fa2684b33ebe15c583 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_reduce.cuh @@ -0,0 +1,608 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * The cub::BlockReduce class provides [collective](index.html#sec0) methods for computing a parallel reduction of items partitioned across a CUDA thread block. + */ + +#pragma once + +#include "specializations/block_reduce_raking.cuh" +#include "specializations/block_reduce_raking_commutative_only.cuh" +#include "specializations/block_reduce_warp_reductions.cuh" +#include "../config.cuh" +#include "../util_ptx.cuh" +#include "../util_type.cuh" +#include "../thread/thread_operators.cuh" + +CUB_NAMESPACE_BEGIN + + + +/****************************************************************************** + * Algorithmic variants + ******************************************************************************/ + +/** + * BlockReduceAlgorithm enumerates alternative algorithms for parallel + * reduction across a CUDA thread block. + */ +enum BlockReduceAlgorithm +{ + + /** + * \par Overview + * An efficient "raking" reduction algorithm that only supports commutative + * reduction operators (true for most operations, e.g., addition). + * + * \par + * Execution is comprised of three phases: + * -# Upsweep sequential reduction in registers (if threads contribute more + * than one input each). Threads in warps other than the first warp place + * their partial reductions into shared memory. + * -# Upsweep sequential reduction in shared memory. Threads within the first + * warp continue to accumulate by raking across segments of shared partial reductions + * -# A warp-synchronous Kogge-Stone style reduction within the raking warp. + * + * \par + * \image html block_reduce.png + *
\p BLOCK_REDUCE_RAKING data flow for a hypothetical 16-thread thread block and 4-thread raking warp.
+ * + * \par Performance Considerations + * - This variant performs less communication than BLOCK_REDUCE_RAKING_NON_COMMUTATIVE + * and is preferable when the reduction operator is commutative. This variant + * applies fewer reduction operators than BLOCK_REDUCE_WARP_REDUCTIONS, and can provide higher overall + * throughput across the GPU when suitably occupied. However, turn-around latency may be + * higher than to BLOCK_REDUCE_WARP_REDUCTIONS and thus less-desirable + * when the GPU is under-occupied. + */ + BLOCK_REDUCE_RAKING_COMMUTATIVE_ONLY, + + + /** + * \par Overview + * An efficient "raking" reduction algorithm that supports commutative + * (e.g., addition) and non-commutative (e.g., string concatenation) reduction + * operators. \blocked. + * + * \par + * Execution is comprised of three phases: + * -# Upsweep sequential reduction in registers (if threads contribute more + * than one input each). Each thread then places the partial reduction + * of its item(s) into shared memory. + * -# Upsweep sequential reduction in shared memory. Threads within a + * single warp rake across segments of shared partial reductions. + * -# A warp-synchronous Kogge-Stone style reduction within the raking warp. + * + * \par + * \image html block_reduce.png + *
\p BLOCK_REDUCE_RAKING data flow for a hypothetical 16-thread thread block and 4-thread raking warp.
+ * + * \par Performance Considerations + * - This variant performs more communication than BLOCK_REDUCE_RAKING + * and is only preferable when the reduction operator is non-commutative. This variant + * applies fewer reduction operators than BLOCK_REDUCE_WARP_REDUCTIONS, and can provide higher overall + * throughput across the GPU when suitably occupied. However, turn-around latency may be + * higher than to BLOCK_REDUCE_WARP_REDUCTIONS and thus less-desirable + * when the GPU is under-occupied. + */ + BLOCK_REDUCE_RAKING, + + + /** + * \par Overview + * A quick "tiled warp-reductions" reduction algorithm that supports commutative + * (e.g., addition) and non-commutative (e.g., string concatenation) reduction + * operators. + * + * \par + * Execution is comprised of four phases: + * -# Upsweep sequential reduction in registers (if threads contribute more + * than one input each). Each thread then places the partial reduction + * of its item(s) into shared memory. + * -# Compute a shallow, but inefficient warp-synchronous Kogge-Stone style + * reduction within each warp. + * -# A propagation phase where the warp reduction outputs in each warp are + * updated with the aggregate from each preceding warp. + * + * \par + * \image html block_scan_warpscans.png + *
\p BLOCK_REDUCE_WARP_REDUCTIONS data flow for a hypothetical 16-thread thread block and 4-thread raking warp.
+ * + * \par Performance Considerations + * - This variant applies more reduction operators than BLOCK_REDUCE_RAKING + * or BLOCK_REDUCE_RAKING_NON_COMMUTATIVE, which may result in lower overall + * throughput across the GPU. However turn-around latency may be lower and + * thus useful when the GPU is under-occupied. + */ + BLOCK_REDUCE_WARP_REDUCTIONS, +}; + + +/****************************************************************************** + * Block reduce + ******************************************************************************/ + +/** + * \brief The BlockReduce class provides [collective](index.html#sec0) methods for computing a parallel reduction of items partitioned across a CUDA thread block. ![](reduce_logo.png) + * \ingroup BlockModule + * + * \tparam T Data type being reduced + * \tparam BLOCK_DIM_X The thread block length in threads along the X dimension + * \tparam ALGORITHM [optional] cub::BlockReduceAlgorithm enumerator specifying the underlying algorithm to use (default: cub::BLOCK_REDUCE_WARP_REDUCTIONS) + * \tparam BLOCK_DIM_Y [optional] The thread block length in threads along the Y dimension (default: 1) + * \tparam BLOCK_DIM_Z [optional] The thread block length in threads along the Z dimension (default: 1) + * \tparam LEGACY_PTX_ARCH [optional] Unused. + * + * \par Overview + * - A reduction (or fold) + * uses a binary combining operator to compute a single aggregate from a list of input elements. + * - \rowmajor + * - BlockReduce can be optionally specialized by algorithm to accommodate different latency/throughput workload profiles: + * -# cub::BLOCK_REDUCE_RAKING_COMMUTATIVE_ONLY. An efficient "raking" reduction algorithm that only supports commutative reduction operators. [More...](\ref cub::BlockReduceAlgorithm) + * -# cub::BLOCK_REDUCE_RAKING. An efficient "raking" reduction algorithm that supports commutative and non-commutative reduction operators. [More...](\ref cub::BlockReduceAlgorithm) + * -# cub::BLOCK_REDUCE_WARP_REDUCTIONS. A quick "tiled warp-reductions" reduction algorithm that supports commutative and non-commutative reduction operators. [More...](\ref cub::BlockReduceAlgorithm) + * + * \par Performance Considerations + * - \granularity + * - Very efficient (only one synchronization barrier). + * - Incurs zero bank conflicts for most types + * - Computation is slightly more efficient (i.e., having lower instruction overhead) for: + * - Summation (vs. generic reduction) + * - \p BLOCK_THREADS is a multiple of the architecture's warp size + * - Every thread has a valid input (i.e., full vs. partial-tiles) + * - See cub::BlockReduceAlgorithm for performance details regarding algorithmic alternatives + * + * \par A Simple Example + * \blockcollective{BlockReduce} + * \par + * The code snippet below illustrates a sum reduction of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockReduce for a 1D block of 128 threads of type int + * typedef cub::BlockReduce BlockReduce; + * + * // Allocate shared memory for BlockReduce + * __shared__ typename BlockReduce::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Compute the block-wide sum for thread0 + * int aggregate = BlockReduce(temp_storage).Sum(thread_data); + * + * \endcode + * + * \par Re-using dynamically allocating shared memory + * The following example under the examples/block folder illustrates usage of + * dynamically shared memory with BlockReduce and how to re-purpose + * the same memory region: + * example_block_reduce_dyn_smem.cu + */ +template < + typename T, + int BLOCK_DIM_X, + BlockReduceAlgorithm ALGORITHM = BLOCK_REDUCE_WARP_REDUCTIONS, + int BLOCK_DIM_Y = 1, + int BLOCK_DIM_Z = 1, + int LEGACY_PTX_ARCH = 0> +class BlockReduce +{ +private: + + /****************************************************************************** + * Constants and type definitions + ******************************************************************************/ + + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + }; + + typedef BlockReduceWarpReductions WarpReductions; + typedef BlockReduceRakingCommutativeOnly RakingCommutativeOnly; + typedef BlockReduceRaking Raking; + + /// Internal specialization type + using InternalBlockReduce = cub::detail::conditional_t< + ALGORITHM == BLOCK_REDUCE_WARP_REDUCTIONS, + WarpReductions, + cub::detail::conditional_t>; // BlockReduceRaking + + /// Shared memory storage layout type for BlockReduce + typedef typename InternalBlockReduce::TempStorage _TempStorage; + + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Linear thread-id + unsigned int linear_tid; + + +public: + + /// \smemstorage{BlockReduce} + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /******************************************************************//** + * \name Collective constructors + *********************************************************************/ + //@{ + + /** + * \brief Collective constructor using a private static allocation of shared memory as temporary storage. + */ + __device__ __forceinline__ BlockReduce() + : + temp_storage(PrivateStorage()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + /** + * \brief Collective constructor using the specified memory allocation as temporary storage. + */ + __device__ __forceinline__ BlockReduce( + TempStorage &temp_storage) ///< [in] Reference to memory allocation having layout type TempStorage + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + //@} end member group + /******************************************************************//** + * \name Generic reductions + *********************************************************************/ + //@{ + + + /** + * \brief Computes a block-wide reduction for thread0 using the specified binary reduction functor. Each thread contributes one input element. + * + * \par + * - The return value is undefined in threads other than thread0. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a max reduction of 128 integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockReduce for a 1D block of 128 threads of type int + * typedef cub::BlockReduce BlockReduce; + * + * // Allocate shared memory for BlockReduce + * __shared__ typename BlockReduce::TempStorage temp_storage; + * + * // Each thread obtains an input item + * int thread_data; + * ... + * + * // Compute the block-wide max for thread0 + * int aggregate = BlockReduce(temp_storage).Reduce(thread_data, cub::Max()); + * + * \endcode + * + * \tparam ReductionOp [inferred] Binary reduction functor type having member T operator()(const T &a, const T &b) + */ + template + __device__ __forceinline__ T Reduce( + T input, ///< [in] Calling thread's input + ReductionOp reduction_op) ///< [in] Binary reduction functor + { + return InternalBlockReduce(temp_storage).template Reduce(input, BLOCK_THREADS, reduction_op); + } + + + /** + * \brief Computes a block-wide reduction for thread0 using the specified binary reduction functor. Each thread contributes an array of consecutive input elements. + * + * \par + * - The return value is undefined in threads other than thread0. + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a max reduction of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockReduce for a 1D block of 128 threads of type int + * typedef cub::BlockReduce BlockReduce; + * + * // Allocate shared memory for BlockReduce + * __shared__ typename BlockReduce::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Compute the block-wide max for thread0 + * int aggregate = BlockReduce(temp_storage).Reduce(thread_data, cub::Max()); + * + * \endcode + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam ReductionOp [inferred] Binary reduction functor type having member T operator()(const T &a, const T &b) + */ + template < + int ITEMS_PER_THREAD, + typename ReductionOp> + __device__ __forceinline__ T Reduce( + T (&inputs)[ITEMS_PER_THREAD], ///< [in] Calling thread's input segment + ReductionOp reduction_op) ///< [in] Binary reduction functor + { + // Reduce partials + T partial = internal::ThreadReduce(inputs, reduction_op); + return Reduce(partial, reduction_op); + } + + + /** + * \brief Computes a block-wide reduction for thread0 using the specified binary reduction functor. The first \p num_valid threads each contribute one input element. + * + * \par + * - The return value is undefined in threads other than thread0. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a max reduction of a partially-full tile of integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int num_valid, ...) + * { + * // Specialize BlockReduce for a 1D block of 128 threads of type int + * typedef cub::BlockReduce BlockReduce; + * + * // Allocate shared memory for BlockReduce + * __shared__ typename BlockReduce::TempStorage temp_storage; + * + * // Each thread obtains an input item + * int thread_data; + * if (threadIdx.x < num_valid) thread_data = ... + * + * // Compute the block-wide max for thread0 + * int aggregate = BlockReduce(temp_storage).Reduce(thread_data, cub::Max(), num_valid); + * + * \endcode + * + * \tparam ReductionOp [inferred] Binary reduction functor type having member T operator()(const T &a, const T &b) + */ + template + __device__ __forceinline__ T Reduce( + T input, ///< [in] Calling thread's input + ReductionOp reduction_op, ///< [in] Binary reduction functor + int num_valid) ///< [in] Number of threads containing valid elements (may be less than BLOCK_THREADS) + { + // Determine if we skip bounds checking + if (num_valid >= BLOCK_THREADS) + { + return InternalBlockReduce(temp_storage).template Reduce(input, num_valid, reduction_op); + } + else + { + return InternalBlockReduce(temp_storage).template Reduce(input, num_valid, reduction_op); + } + } + + + //@} end member group + /******************************************************************//** + * \name Summation reductions + *********************************************************************/ + //@{ + + + /** + * \brief Computes a block-wide reduction for thread0 using addition (+) as the reduction operator. Each thread contributes one input element. + * + * \par + * - The return value is undefined in threads other than thread0. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a sum reduction of 128 integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockReduce for a 1D block of 128 threads of type int + * typedef cub::BlockReduce BlockReduce; + * + * // Allocate shared memory for BlockReduce + * __shared__ typename BlockReduce::TempStorage temp_storage; + * + * // Each thread obtains an input item + * int thread_data; + * ... + * + * // Compute the block-wide sum for thread0 + * int aggregate = BlockReduce(temp_storage).Sum(thread_data); + * + * \endcode + * + */ + __device__ __forceinline__ T Sum( + T input) ///< [in] Calling thread's input + { + return InternalBlockReduce(temp_storage).template Sum(input, BLOCK_THREADS); + } + + /** + * \brief Computes a block-wide reduction for thread0 using addition (+) as the reduction operator. Each thread contributes an array of consecutive input elements. + * + * \par + * - The return value is undefined in threads other than thread0. + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a sum reduction of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockReduce for a 1D block of 128 threads of type int + * typedef cub::BlockReduce BlockReduce; + * + * // Allocate shared memory for BlockReduce + * __shared__ typename BlockReduce::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Compute the block-wide sum for thread0 + * int aggregate = BlockReduce(temp_storage).Sum(thread_data); + * + * \endcode + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + */ + template + __device__ __forceinline__ T Sum( + T (&inputs)[ITEMS_PER_THREAD]) ///< [in] Calling thread's input segment + { + // Reduce partials + T partial = internal::ThreadReduce(inputs, cub::Sum()); + return Sum(partial); + } + + + /** + * \brief Computes a block-wide reduction for thread0 using addition (+) as the reduction operator. The first \p num_valid threads each contribute one input element. + * + * \par + * - The return value is undefined in threads other than thread0. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a sum reduction of a partially-full tile of integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int num_valid, ...) + * { + * // Specialize BlockReduce for a 1D block of 128 threads of type int + * typedef cub::BlockReduce BlockReduce; + * + * // Allocate shared memory for BlockReduce + * __shared__ typename BlockReduce::TempStorage temp_storage; + * + * // Each thread obtains an input item (up to num_items) + * int thread_data; + * if (threadIdx.x < num_valid) + * thread_data = ... + * + * // Compute the block-wide sum for thread0 + * int aggregate = BlockReduce(temp_storage).Sum(thread_data, num_valid); + * + * \endcode + * + */ + __device__ __forceinline__ T Sum( + T input, ///< [in] Calling thread's input + int num_valid) ///< [in] Number of threads containing valid elements (may be less than BLOCK_THREADS) + { + // Determine if we skip bounds checking + if (num_valid >= BLOCK_THREADS) + { + return InternalBlockReduce(temp_storage).template Sum(input, num_valid); + } + else + { + return InternalBlockReduce(temp_storage).template Sum(input, num_valid); + } + } + + + //@} end member group +}; + +/** + * \example example_block_reduce.cu + */ + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_run_length_decode.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_run_length_decode.cuh new file mode 100644 index 0000000000000000000000000000000000000000..41a3ab22b156dc57986889ac92196ce7157d3c20 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_run_length_decode.cuh @@ -0,0 +1,392 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + *AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include "../config.cuh" +#include "../thread/thread_search.cuh" +#include "../util_math.cuh" +#include "../util_namespace.cuh" +#include "../util_ptx.cuh" +#include "../util_type.cuh" +#include "block_scan.cuh" +#include +#include + +CUB_NAMESPACE_BEGIN + +/** + * \brief The BlockRunLengthDecode class supports decoding a run-length encoded array of items. That is, given + * the two arrays run_value[N] and run_lengths[N], run_value[i] is repeated run_lengths[i] many times in the output + * array. + * Due to the nature of the run-length decoding algorithm ("decompression"), the output size of the run-length decoded + * array is runtime-dependent and potentially without any upper bound. To address this, BlockRunLengthDecode allows + * retrieving a "window" from the run-length decoded array. The window's offset can be specified and BLOCK_THREADS * + * DECODED_ITEMS_PER_THREAD (i.e., referred to as window_size) decoded items from the specified window will be returned. + * + * \note: Trailing runs of length 0 are supported (i.e., they may only appear at the end of the run_lengths array). + * A run of length zero may not be followed by a run length that is not zero. + * + * \par + * \code + * __global__ void ExampleKernel(...) + * { + * // Specialising BlockRunLengthDecode to run-length decode items of type uint64_t + * using RunItemT = uint64_t; + * // Type large enough to index into the run-length decoded array + * using RunLengthT = uint32_t; + * + * // Specialising BlockRunLengthDecode for a 1D block of 128 threads + * constexpr int BLOCK_DIM_X = 128; + * // Specialising BlockRunLengthDecode to have each thread contribute 2 run-length encoded runs + * constexpr int RUNS_PER_THREAD = 2; + * // Specialising BlockRunLengthDecode to have each thread hold 4 run-length decoded items + * constexpr int DECODED_ITEMS_PER_THREAD = 4; + * + * // Specialize BlockRadixSort for a 1D block of 128 threads owning 4 integer items each + * using BlockRunLengthDecodeT = + * cub::BlockRunLengthDecode; + * + * // Allocate shared memory for BlockRunLengthDecode + * __shared__ typename BlockRunLengthDecodeT::TempStorage temp_storage; + * + * // The run-length encoded items and how often they shall be repeated in the run-length decoded output + * RunItemT run_values[RUNS_PER_THREAD]; + * RunLengthT run_lengths[RUNS_PER_THREAD]; + * ... + * + * // Initialize the BlockRunLengthDecode with the runs that we want to run-length decode + * uint32_t total_decoded_size = 0; + * BlockRunLengthDecodeT block_rld(temp_storage, run_values, run_lengths, total_decoded_size); + * + * // Run-length decode ("decompress") the runs into a window buffer of limited size. This is repeated until all runs + * // have been decoded. + * uint32_t decoded_window_offset = 0U; + * while (decoded_window_offset < total_decoded_size) + * { + * RunLengthT relative_offsets[DECODED_ITEMS_PER_THREAD]; + * RunItemT decoded_items[DECODED_ITEMS_PER_THREAD]; + * + * // The number of decoded items that are valid within this window (aka pass) of run-length decoding + * uint32_t num_valid_items = total_decoded_size - decoded_window_offset; + * block_rld.RunLengthDecode(decoded_items, relative_offsets, decoded_window_offset); + * + * decoded_window_offset += BLOCK_DIM_X * DECODED_ITEMS_PER_THREAD; + * + * ... + * } + * } + * \endcode + * \par + * Suppose the set of input \p run_values across the block of threads is + * { [0, 1], [2, 3], [4, 5], [6, 7], ..., [254, 255] } and + * \p run_lengths is { [1, 2], [3, 4], [5, 1], [2, 3], ..., [5, 1] }. + * The corresponding output \p decoded_items in those threads will be { [0, 1, 1, 2], [2, 2, 3, 3], [3, 3, 4, 4], + * [4, 4, 4, 5], ..., [169, 169, 170, 171] } and \p relative_offsets will be { [0, 0, 1, 0], [1, 2, 0, 1], [2, + * 3, 0, 1], [2, 3, 4, 0], ..., [3, 4, 0, 0] } during the first iteration of the while loop. + * + * \tparam ItemT The data type of the items being run-length decoded + * \tparam BLOCK_DIM_X The thread block length in threads along the X dimension + * \tparam RUNS_PER_THREAD The number of consecutive runs that each thread contributes + * \tparam DECODED_ITEMS_PER_THREAD The maximum number of decoded items that each thread holds + * \tparam DecodedOffsetT Type used to index into the block's decoded items (large enough to hold the sum over all the + * runs' lengths) + * \tparam BLOCK_DIM_Y The thread block length in threads along the Y dimension + * \tparam BLOCK_DIM_Z The thread block length in threads along the Z dimension + */ +template +class BlockRunLengthDecode +{ + //--------------------------------------------------------------------- + // CONFIGS & TYPE ALIASES + //--------------------------------------------------------------------- +private: + /// The thread block size in threads + static constexpr int BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z; + + /// The number of runs that the block decodes (out-of-bounds items may be padded with run lengths of '0') + static constexpr int BLOCK_RUNS = BLOCK_THREADS * RUNS_PER_THREAD; + + /// BlockScan used to determine the beginning of each run (i.e., prefix sum over the runs' length) + using RunOffsetScanT = BlockScan; + + /// Type used to index into the block's runs + using RunOffsetT = uint32_t; + + /// Shared memory type required by this thread block + union _TempStorage + { + typename RunOffsetScanT::TempStorage offset_scan; + struct + { + ItemT run_values[BLOCK_RUNS]; + DecodedOffsetT run_offsets[BLOCK_RUNS]; + } runs; + }; // union TempStorage + + /// Internal storage allocator (used when the user does not provide pre-allocated shared memory) + __device__ __forceinline__ _TempStorage &PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Linear thread-id + uint32_t linear_tid; + +public: + struct TempStorage : Uninitialized<_TempStorage> + {}; + + //--------------------------------------------------------------------- + // CONSTRUCTOR + //--------------------------------------------------------------------- + + /** + * \brief Constructor specialised for user-provided temporary storage, initializing using the runs' lengths. The + * algorithm's temporary storage may not be repurposed between the constructor call and subsequent + * RunLengthDecode calls. + */ + template + __device__ __forceinline__ BlockRunLengthDecode(TempStorage &temp_storage, + ItemT (&run_values)[RUNS_PER_THREAD], + RunLengthT (&run_lengths)[RUNS_PER_THREAD], + TotalDecodedSizeT &total_decoded_size) + : temp_storage(temp_storage.Alias()) + , linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + { + InitWithRunLengths(run_values, run_lengths, total_decoded_size); + } + + /** + * \brief Constructor specialised for user-provided temporary storage, initializing using the runs' offsets. The + * algorithm's temporary storage may not be repurposed between the constructor call and subsequent + * RunLengthDecode calls. + */ + template + __device__ __forceinline__ BlockRunLengthDecode(TempStorage &temp_storage, + ItemT (&run_values)[RUNS_PER_THREAD], + UserRunOffsetT (&run_offsets)[RUNS_PER_THREAD]) + : temp_storage(temp_storage.Alias()) + , linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + { + InitWithRunOffsets(run_values, run_offsets); + } + + /** + * \brief Constructor specialised for static temporary storage, initializing using the runs' lengths. + */ + template + __device__ __forceinline__ BlockRunLengthDecode(ItemT (&run_values)[RUNS_PER_THREAD], + RunLengthT (&run_lengths)[RUNS_PER_THREAD], + TotalDecodedSizeT &total_decoded_size) + : temp_storage(PrivateStorage()) + , linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + { + InitWithRunLengths(run_values, run_lengths, total_decoded_size); + } + + /** + * \brief Constructor specialised for static temporary storage, initializing using the runs' offsets. + */ + template + __device__ __forceinline__ BlockRunLengthDecode(ItemT (&run_values)[RUNS_PER_THREAD], + UserRunOffsetT (&run_offsets)[RUNS_PER_THREAD]) + : temp_storage(PrivateStorage()) + , linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + { + InitWithRunOffsets(run_values, run_offsets); + } + +private: + /** + * \brief Returns the offset of the first value within \p input which compares greater than \p val. This version takes + * \p MAX_NUM_ITEMS, an upper bound of the array size, which will be used to determine the number of binary search + * iterations at compile time. + */ + template + __device__ __forceinline__ OffsetT StaticUpperBound(InputIteratorT input, ///< [in] Input sequence + OffsetT num_items, ///< [in] Input sequence length + T val) ///< [in] Search key + { + OffsetT lower_bound = 0; + OffsetT upper_bound = num_items; +#pragma unroll + for (int i = 0; i <= Log2::VALUE; i++) + { + OffsetT mid = cub::MidPoint(lower_bound, upper_bound); + mid = (cub::min)(mid, num_items - 1); + + if (val < input[mid]) + { + upper_bound = mid; + } + else + { + lower_bound = mid + 1; + } + } + + return lower_bound; + } + + template + __device__ __forceinline__ void InitWithRunOffsets(ItemT (&run_values)[RUNS_PER_THREAD], + RunOffsetT (&run_offsets)[RUNS_PER_THREAD]) + { + // Keep the runs' items and the offsets of each run's beginning in the temporary storage + RunOffsetT thread_dst_offset = static_cast(linear_tid) * static_cast(RUNS_PER_THREAD); +#pragma unroll + for (int i = 0; i < RUNS_PER_THREAD; i++) + { + temp_storage.runs.run_values[thread_dst_offset] = run_values[i]; + temp_storage.runs.run_offsets[thread_dst_offset] = run_offsets[i]; + thread_dst_offset++; + } + + // Ensure run offsets and run values have been writen to shared memory + CTA_SYNC(); + } + + template + __device__ __forceinline__ void InitWithRunLengths(ItemT (&run_values)[RUNS_PER_THREAD], + RunLengthT (&run_lengths)[RUNS_PER_THREAD], + TotalDecodedSizeT &total_decoded_size) + { + // Compute the offset for the beginning of each run + DecodedOffsetT run_offsets[RUNS_PER_THREAD]; +#pragma unroll + for (int i = 0; i < RUNS_PER_THREAD; i++) + { + run_offsets[i] = static_cast(run_lengths[i]); + } + DecodedOffsetT decoded_size_aggregate; + RunOffsetScanT(this->temp_storage.offset_scan).ExclusiveSum(run_offsets, run_offsets, decoded_size_aggregate); + total_decoded_size = static_cast(decoded_size_aggregate); + + // Ensure the prefix scan's temporary storage can be reused (may be superfluous, but depends on scan implementation) + CTA_SYNC(); + + InitWithRunOffsets(run_values, run_offsets); + } + +public: + /** + * \brief Run-length decodes the runs previously passed via a call to Init(...) and returns the run-length decoded + * items in a blocked arrangement to \p decoded_items. If the number of run-length decoded items exceeds the + * run-length decode buffer (i.e., DECODED_ITEMS_PER_THREAD * BLOCK_THREADS), only the items that fit within + * the buffer are returned. Subsequent calls to RunLengthDecode adjusting \p from_decoded_offset can be + * used to retrieve the remaining run-length decoded items. Calling __syncthreads() between any two calls to + * RunLengthDecode is not required. + * \p item_offsets can be used to retrieve each run-length decoded item's relative index within its run. E.g., the + * run-length encoded array of `3, 1, 4` with the respective run lengths of `2, 1, 3` would yield the run-length + * decoded array of `3, 3, 1, 4, 4, 4` with the relative offsets of `0, 1, 0, 0, 1, 2`. + * \smemreuse + * + * \param[out] decoded_items The run-length decoded items to be returned in a blocked arrangement + * \param[out] item_offsets The run-length decoded items' relative offset within the run they belong to + * \param[in] from_decoded_offset If invoked with from_decoded_offset that is larger than total_decoded_size results + * in undefined behavior. + */ + template + __device__ __forceinline__ void RunLengthDecode(ItemT (&decoded_items)[DECODED_ITEMS_PER_THREAD], + RelativeOffsetT (&item_offsets)[DECODED_ITEMS_PER_THREAD], + DecodedOffsetT from_decoded_offset = 0) + { + // The (global) offset of the first item decoded by this thread + DecodedOffsetT thread_decoded_offset = from_decoded_offset + linear_tid * DECODED_ITEMS_PER_THREAD; + + // The run that the first decoded item of this thread belongs to + // If this thread's is already beyond the total decoded size, it will be assigned to the + // last run + RunOffsetT assigned_run = + StaticUpperBound(temp_storage.runs.run_offsets, BLOCK_RUNS, thread_decoded_offset) - + static_cast(1U); + + DecodedOffsetT assigned_run_begin = temp_storage.runs.run_offsets[assigned_run]; + + // If this thread is getting assigned the last run, we make sure it will not fetch any other run after this + DecodedOffsetT assigned_run_end = (assigned_run == BLOCK_RUNS - 1) + ? thread_decoded_offset + DECODED_ITEMS_PER_THREAD + : temp_storage.runs.run_offsets[assigned_run + 1]; + + ItemT val = temp_storage.runs.run_values[assigned_run]; + +#pragma unroll + for (DecodedOffsetT i = 0; i < DECODED_ITEMS_PER_THREAD; i++) + { + decoded_items[i] = val; + item_offsets[i] = thread_decoded_offset - assigned_run_begin; + if (thread_decoded_offset == assigned_run_end - 1) + { + // We make sure that a thread is not re-entering this conditional when being assigned to the last run already by + // extending the last run's length to all the thread's item + assigned_run++; + assigned_run_begin = temp_storage.runs.run_offsets[assigned_run]; + + // If this thread is getting assigned the last run, we make sure it will not fetch any other run after this + assigned_run_end = (assigned_run == BLOCK_RUNS - 1) ? thread_decoded_offset + DECODED_ITEMS_PER_THREAD + : temp_storage.runs.run_offsets[assigned_run + 1]; + val = temp_storage.runs.run_values[assigned_run]; + } + thread_decoded_offset++; + } + } + + /** + * \brief Run-length decodes the runs previously passed via a call to Init(...) and returns the run-length decoded + * items in a blocked arrangement to \p decoded_items. If the number of run-length decoded items exceeds the + * run-length decode buffer (i.e., DECODED_ITEMS_PER_THREAD * BLOCK_THREADS), only the items that fit within + * the buffer are returned. Subsequent calls to RunLengthDecode adjusting \p from_decoded_offset can be + * used to retrieve the remaining run-length decoded items. Calling __syncthreads() between any two calls to + * RunLengthDecode is not required. + * + * \param[out] decoded_items The run-length decoded items to be returned in a blocked arrangement + * \param[in] from_decoded_offset If invoked with from_decoded_offset that is larger than total_decoded_size results + * in undefined behavior. + */ + __device__ __forceinline__ void RunLengthDecode(ItemT (&decoded_items)[DECODED_ITEMS_PER_THREAD], + DecodedOffsetT from_decoded_offset = 0) + { + DecodedOffsetT item_offsets[DECODED_ITEMS_PER_THREAD]; + RunLengthDecode(decoded_items, item_offsets, from_decoded_offset); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_scan.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_scan.cuh new file mode 100644 index 0000000000000000000000000000000000000000..d1b6a66e984c5557fcf7a5d9e28d457a562cdca3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_scan.cuh @@ -0,0 +1,2131 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * The cub::BlockScan class provides [collective](index.html#sec0) methods for computing a parallel prefix sum/scan of items partitioned across a CUDA thread block. + */ + +#pragma once + +#include "specializations/block_scan_raking.cuh" +#include "specializations/block_scan_warp_scans.cuh" +#include "../config.cuh" +#include "../util_type.cuh" +#include "../util_ptx.cuh" + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Algorithmic variants + ******************************************************************************/ + +/** + * \brief BlockScanAlgorithm enumerates alternative algorithms for cub::BlockScan to compute a parallel prefix scan across a CUDA thread block. + */ +enum BlockScanAlgorithm +{ + + /** + * \par Overview + * An efficient "raking reduce-then-scan" prefix scan algorithm. Execution is comprised of five phases: + * -# Upsweep sequential reduction in registers (if threads contribute more than one input each). Each thread then places the partial reduction of its item(s) into shared memory. + * -# Upsweep sequential reduction in shared memory. Threads within a single warp rake across segments of shared partial reductions. + * -# A warp-synchronous Kogge-Stone style exclusive scan within the raking warp. + * -# Downsweep sequential exclusive scan in shared memory. Threads within a single warp rake across segments of shared partial reductions, seeded with the warp-scan output. + * -# Downsweep sequential scan in registers (if threads contribute more than one input), seeded with the raking scan output. + * + * \par + * \image html block_scan_raking.png + *
\p BLOCK_SCAN_RAKING data flow for a hypothetical 16-thread thread block and 4-thread raking warp.
+ * + * \par Performance Considerations + * - Although this variant may suffer longer turnaround latencies when the + * GPU is under-occupied, it can often provide higher overall throughput + * across the GPU when suitably occupied. + */ + BLOCK_SCAN_RAKING, + + + /** + * \par Overview + * Similar to cub::BLOCK_SCAN_RAKING, but with fewer shared memory reads at + * the expense of higher register pressure. Raking threads preserve their + * "upsweep" segment of values in registers while performing warp-synchronous + * scan, allowing the "downsweep" not to re-read them from shared memory. + */ + BLOCK_SCAN_RAKING_MEMOIZE, + + + /** + * \par Overview + * A quick "tiled warpscans" prefix scan algorithm. Execution is comprised of four phases: + * -# Upsweep sequential reduction in registers (if threads contribute more than one input each). Each thread then places the partial reduction of its item(s) into shared memory. + * -# Compute a shallow, but inefficient warp-synchronous Kogge-Stone style scan within each warp. + * -# A propagation phase where the warp scan outputs in each warp are updated with the aggregate from each preceding warp. + * -# Downsweep sequential scan in registers (if threads contribute more than one input), seeded with the raking scan output. + * + * \par + * \image html block_scan_warpscans.png + *
\p BLOCK_SCAN_WARP_SCANS data flow for a hypothetical 16-thread thread block and 4-thread raking warp.
+ * + * \par Performance Considerations + * - Although this variant may suffer lower overall throughput across the + * GPU because due to a heavy reliance on inefficient warpscans, it can + * often provide lower turnaround latencies when the GPU is under-occupied. + */ + BLOCK_SCAN_WARP_SCANS, +}; + + +/****************************************************************************** + * Block scan + ******************************************************************************/ + +/** + * \brief The BlockScan class provides [collective](index.html#sec0) methods for computing a parallel prefix sum/scan of items partitioned across a CUDA thread block. ![](block_scan_logo.png) + * \ingroup BlockModule + * + * \tparam T Data type being scanned + * \tparam BLOCK_DIM_X The thread block length in threads along the X dimension + * \tparam ALGORITHM [optional] cub::BlockScanAlgorithm enumerator specifying the underlying algorithm to use (default: cub::BLOCK_SCAN_RAKING) + * \tparam BLOCK_DIM_Y [optional] The thread block length in threads along the Y dimension (default: 1) + * \tparam BLOCK_DIM_Z [optional] The thread block length in threads along the Z dimension (default: 1) + * \tparam LEGACY_PTX_ARCH [optional] Unused. + * + * \par Overview + * - Given a list of input elements and a binary reduction operator, a [prefix scan](http://en.wikipedia.org/wiki/Prefix_sum) + * produces an output list where each element is computed to be the reduction + * of the elements occurring earlier in the input list. Prefix sum + * connotes a prefix scan with the addition operator. The term \em inclusive indicates + * that the ith output reduction incorporates the ith input. + * The term \em exclusive indicates the ith input is not incorporated into + * the ith output reduction. + * - \rowmajor + * - BlockScan can be optionally specialized by algorithm to accommodate different workload profiles: + * -# cub::BLOCK_SCAN_RAKING. An efficient (high throughput) "raking reduce-then-scan" prefix scan algorithm. [More...](\ref cub::BlockScanAlgorithm) + * -# cub::BLOCK_SCAN_RAKING_MEMOIZE. Similar to cub::BLOCK_SCAN_RAKING, but having higher throughput at the expense of additional register pressure for intermediate storage. [More...](\ref cub::BlockScanAlgorithm) + * -# cub::BLOCK_SCAN_WARP_SCANS. A quick (low latency) "tiled warpscans" prefix scan algorithm. [More...](\ref cub::BlockScanAlgorithm) + * + * \par Performance Considerations + * - \granularity + * - Uses special instructions when applicable (e.g., warp \p SHFL) + * - Uses synchronization-free communication between warp lanes when applicable + * - Invokes a minimal number of minimal block-wide synchronization barriers (only + * one or two depending on algorithm selection) + * - Incurs zero bank conflicts for most types + * - Computation is slightly more efficient (i.e., having lower instruction overhead) for: + * - Prefix sum variants (vs. generic scan) + * - \blocksize + * - See cub::BlockScanAlgorithm for performance details regarding algorithmic alternatives + * + * \par A Simple Example + * \blockcollective{BlockScan} + * \par + * The code snippet below illustrates an exclusive prefix sum of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute the block-wide exclusive prefix sum + * BlockScan(temp_storage).ExclusiveSum(thread_data, thread_data); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * {[1,1,1,1], [1,1,1,1], ..., [1,1,1,1]}. + * The corresponding output \p thread_data in those threads will be + * {[0,1,2,3], [4,5,6,7], ..., [508,509,510,511]}. + * + * \par Re-using dynamically allocating shared memory + * The following example under the examples/block folder illustrates usage of + * dynamically shared memory with BlockReduce and how to re-purpose + * the same memory region: + * example_block_reduce_dyn_smem.cu + * + * This example can be easily adapted to the storage required by BlockScan. + */ +template < + typename T, + int BLOCK_DIM_X, + BlockScanAlgorithm ALGORITHM = BLOCK_SCAN_RAKING, + int BLOCK_DIM_Y = 1, + int BLOCK_DIM_Z = 1, + int LEGACY_PTX_ARCH = 0> +class BlockScan +{ +private: + + /****************************************************************************** + * Constants and type definitions + ******************************************************************************/ + + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + }; + + /** + * Ensure the template parameterization meets the requirements of the + * specified algorithm. Currently, the BLOCK_SCAN_WARP_SCANS policy + * cannot be used with thread block sizes not a multiple of the + * architectural warp size. + */ + static const BlockScanAlgorithm SAFE_ALGORITHM = + ((ALGORITHM == BLOCK_SCAN_WARP_SCANS) && (BLOCK_THREADS % CUB_WARP_THREADS(0) != 0)) ? + BLOCK_SCAN_RAKING : + ALGORITHM; + + typedef BlockScanWarpScans WarpScans; + typedef BlockScanRaking Raking; + + /// Define the delegate type for the desired algorithm + using InternalBlockScan = + cub::detail::conditional_t< + SAFE_ALGORITHM == BLOCK_SCAN_WARP_SCANS, WarpScans, Raking>; + + /// Shared memory storage layout type for BlockScan + typedef typename InternalBlockScan::TempStorage _TempStorage; + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Linear thread-id + unsigned int linear_tid; + + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + + /****************************************************************************** + * Public types + ******************************************************************************/ +public: + + /// \smemstorage{BlockScan} + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /******************************************************************//** + * \name Collective constructors + *********************************************************************/ + //@{ + + /** + * \brief Collective constructor using a private static allocation of shared memory as temporary storage. + */ + __device__ __forceinline__ BlockScan() + : + temp_storage(PrivateStorage()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + /** + * \brief Collective constructor using the specified memory allocation as temporary storage. + */ + __device__ __forceinline__ BlockScan( + TempStorage &temp_storage) ///< [in] Reference to memory allocation having layout type TempStorage + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + + //@} end member group + /******************************************************************//** + * \name Exclusive prefix sum operations + *********************************************************************/ + //@{ + + + /** + * \brief Computes an exclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes one input element. The value of 0 is applied as the initial value, and is assigned to \p output in thread0. + * + * \par + * - \identityzero + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an exclusive prefix sum of 128 integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain input item for each thread + * int thread_data; + * ... + * + * // Collectively compute the block-wide exclusive prefix sum + * BlockScan(temp_storage).ExclusiveSum(thread_data, thread_data); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is 1, 1, ..., 1. The + * corresponding output \p thread_data in those threads will be 0, 1, ..., 127. + * + */ + __device__ __forceinline__ void ExclusiveSum( + T input, ///< [in] Calling thread's input item + T &output) ///< [out] Calling thread's output item (may be aliased to \p input) + { + T initial_value{}; + + ExclusiveScan(input, output, initial_value, cub::Sum()); + } + + + /** + * \brief Computes an exclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes one input element. The value of 0 is applied as the initial value, and is assigned to \p output in thread0. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - \identityzero + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an exclusive prefix sum of 128 integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain input item for each thread + * int thread_data; + * ... + * + * // Collectively compute the block-wide exclusive prefix sum + * int block_aggregate; + * BlockScan(temp_storage).ExclusiveSum(thread_data, thread_data, block_aggregate); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is 1, 1, ..., 1. The + * corresponding output \p thread_data in those threads will be 0, 1, ..., 127. + * Furthermore the value \p 128 will be stored in \p block_aggregate for all threads. + * + */ + __device__ __forceinline__ void ExclusiveSum( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + T &block_aggregate) ///< [out] block-wide aggregate reduction of input items + { + T initial_value{}; + + ExclusiveScan(input, output, initial_value, cub::Sum(), block_aggregate); + } + + + /** + * \brief Computes an exclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes one input element. Instead of using 0 as the block-wide prefix, the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - \identityzero + * - The \p block_prefix_callback_op functor must implement a member function T operator()(T block_aggregate). + * The functor's input parameter \p block_aggregate is the same value also returned by the scan operation. + * The functor will be invoked by the first warp of threads in the block, however only the return value from + * lane0 is applied as the block-wide prefix. Can be stateful. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a single thread block that progressively + * computes an exclusive prefix sum over multiple "tiles" of input using a + * prefix functor to maintain a running total between block-wide scans. Each tile consists + * of 128 integer items that are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * // A stateful callback functor that maintains a running prefix to be applied + * // during consecutive scan operations. + * struct BlockPrefixCallbackOp + * { + * // Running prefix + * int running_total; + * + * // Constructor + * __device__ BlockPrefixCallbackOp(int running_total) : running_total(running_total) {} + * + * // Callback operator to be entered by the first warp of threads in the block. + * // Thread-0 is responsible for returning a value for seeding the block-wide scan. + * __device__ int operator()(int block_aggregate) + * { + * int old_prefix = running_total; + * running_total += block_aggregate; + * return old_prefix; + * } + * }; + * + * __global__ void ExampleKernel(int *d_data, int num_items, ...) + * { + * // Specialize BlockScan for a 1D block of 128 threads + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Initialize running total + * BlockPrefixCallbackOp prefix_op(0); + * + * // Have the block iterate over segments of items + * for (int block_offset = 0; block_offset < num_items; block_offset += 128) + * { + * // Load a segment of consecutive items that are blocked across threads + * int thread_data = d_data[block_offset]; + * + * // Collectively compute the block-wide exclusive prefix sum + * BlockScan(temp_storage).ExclusiveSum( + * thread_data, thread_data, prefix_op); + * CTA_SYNC(); + * + * // Store scanned items to output segment + * d_data[block_offset] = thread_data; + * } + * \endcode + * \par + * Suppose the input \p d_data is 1, 1, 1, 1, 1, 1, 1, 1, .... + * The corresponding output for the first segment will be 0, 1, ..., 127. + * The output for the second segment will be 128, 129, ..., 255. + * + * \tparam BlockPrefixCallbackOp [inferred] Call-back functor type having member T operator()(T block_aggregate) + */ + template + __device__ __forceinline__ void ExclusiveSum( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a block-wide prefix to be applied to the logical input sequence. + { + ExclusiveScan(input, output, cub::Sum(), block_prefix_callback_op); + } + + + //@} end member group + /******************************************************************//** + * \name Exclusive prefix sum operations (multiple data per thread) + *********************************************************************/ + //@{ + + + /** + * \brief Computes an exclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes an array of consecutive input elements. The value of 0 is applied as the initial value, and is assigned to \p output[0] in thread0. + * + * \par + * - \identityzero + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an exclusive prefix sum of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute the block-wide exclusive prefix sum + * BlockScan(temp_storage).ExclusiveSum(thread_data, thread_data); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is { [1,1,1,1], [1,1,1,1], ..., [1,1,1,1] }. The + * corresponding output \p thread_data in those threads will be { [0,1,2,3], [4,5,6,7], ..., [508,509,510,511] }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + */ + template + __device__ __forceinline__ void ExclusiveSum( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD]) ///< [out] Calling thread's output items (may be aliased to \p input) + { + T initial_value{}; + + ExclusiveScan(input, output, initial_value, cub::Sum()); + } + + + /** + * \brief Computes an exclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes an array of consecutive input elements. The value of 0 is applied as the initial value, and is assigned to \p output[0] in thread0. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - \identityzero + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an exclusive prefix sum of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute the block-wide exclusive prefix sum + * int block_aggregate; + * BlockScan(temp_storage).ExclusiveSum(thread_data, thread_data, block_aggregate); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is { [1,1,1,1], [1,1,1,1], ..., [1,1,1,1] }. The + * corresponding output \p thread_data in those threads will be { [0,1,2,3], [4,5,6,7], ..., [508,509,510,511] }. + * Furthermore the value \p 512 will be stored in \p block_aggregate for all threads. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + */ + template + __device__ __forceinline__ void ExclusiveSum( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + T &block_aggregate) ///< [out] block-wide aggregate reduction of input items + { + // Reduce consecutive thread items in registers + T initial_value{}; + + ExclusiveScan(input, output, initial_value, cub::Sum(), block_aggregate); + } + + + /** + * \brief Computes an exclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes an array of consecutive input elements. Instead of using 0 as the block-wide prefix, the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - \identityzero + * - The \p block_prefix_callback_op functor must implement a member function T operator()(T block_aggregate). + * The functor's input parameter \p block_aggregate is the same value also returned by the scan operation. + * The functor will be invoked by the first warp of threads in the block, however only the return value from + * lane0 is applied as the block-wide prefix. Can be stateful. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a single thread block that progressively + * computes an exclusive prefix sum over multiple "tiles" of input using a + * prefix functor to maintain a running total between block-wide scans. Each tile consists + * of 512 integer items that are partitioned in a [blocked arrangement](index.html#sec5sec3) + * across 128 threads where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * // A stateful callback functor that maintains a running prefix to be applied + * // during consecutive scan operations. + * struct BlockPrefixCallbackOp + * { + * // Running prefix + * int running_total; + * + * // Constructor + * __device__ BlockPrefixCallbackOp(int running_total) : running_total(running_total) {} + * + * // Callback operator to be entered by the first warp of threads in the block. + * // Thread-0 is responsible for returning a value for seeding the block-wide scan. + * __device__ int operator()(int block_aggregate) + * { + * int old_prefix = running_total; + * running_total += block_aggregate; + * return old_prefix; + * } + * }; + * + * __global__ void ExampleKernel(int *d_data, int num_items, ...) + * { + * // Specialize BlockLoad, BlockStore, and BlockScan for a 1D block of 128 threads, 4 ints per thread + * typedef cub::BlockLoad BlockLoad; + * typedef cub::BlockStore BlockStore; + * typedef cub::BlockScan BlockScan; + * + * // Allocate aliased shared memory for BlockLoad, BlockStore, and BlockScan + * __shared__ union { + * typename BlockLoad::TempStorage load; + * typename BlockScan::TempStorage scan; + * typename BlockStore::TempStorage store; + * } temp_storage; + * + * // Initialize running total + * BlockPrefixCallbackOp prefix_op(0); + * + * // Have the block iterate over segments of items + * for (int block_offset = 0; block_offset < num_items; block_offset += 128 * 4) + * { + * // Load a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * BlockLoad(temp_storage.load).Load(d_data + block_offset, thread_data); + * CTA_SYNC(); + * + * // Collectively compute the block-wide exclusive prefix sum + * int block_aggregate; + * BlockScan(temp_storage.scan).ExclusiveSum( + * thread_data, thread_data, prefix_op); + * CTA_SYNC(); + * + * // Store scanned items to output segment + * BlockStore(temp_storage.store).Store(d_data + block_offset, thread_data); + * CTA_SYNC(); + * } + * \endcode + * \par + * Suppose the input \p d_data is 1, 1, 1, 1, 1, 1, 1, 1, .... + * The corresponding output for the first segment will be 0, 1, 2, 3, ..., 510, 511. + * The output for the second segment will be 512, 513, 514, 515, ..., 1022, 1023. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam BlockPrefixCallbackOp [inferred] Call-back functor type having member T operator()(T block_aggregate) + */ + template < + int ITEMS_PER_THREAD, + typename BlockPrefixCallbackOp> + __device__ __forceinline__ void ExclusiveSum( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a block-wide prefix to be applied to the logical input sequence. + { + ExclusiveScan(input, output, cub::Sum(), block_prefix_callback_op); + } + + + + //@} end member group // Exclusive prefix sums + /******************************************************************//** + * \name Exclusive prefix scan operations + *********************************************************************/ + //@{ + + + /** + * \brief Computes an exclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. + * + * \par + * - Supports non-commutative scan operators. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an exclusive prefix max scan of 128 integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain input item for each thread + * int thread_data; + * ... + * + * // Collectively compute the block-wide exclusive prefix max scan + * BlockScan(temp_storage).ExclusiveScan(thread_data, thread_data, INT_MIN, cub::Max()); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is 0, -1, 2, -3, ..., 126, -127. The + * corresponding output \p thread_data in those threads will be INT_MIN, 0, 0, 2, ..., 124, 126. + * + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + T initial_value, ///< [in] Initial value to seed the exclusive scan (and is assigned to \p output[0] in thread0) + ScanOp scan_op) ///< [in] Binary scan functor + { + InternalBlockScan(temp_storage).ExclusiveScan(input, output, initial_value, scan_op); + } + + + /** + * \brief Computes an exclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - Supports non-commutative scan operators. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an exclusive prefix max scan of 128 integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain input item for each thread + * int thread_data; + * ... + * + * // Collectively compute the block-wide exclusive prefix max scan + * int block_aggregate; + * BlockScan(temp_storage).ExclusiveScan(thread_data, thread_data, INT_MIN, cub::Max(), block_aggregate); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is 0, -1, 2, -3, ..., 126, -127. The + * corresponding output \p thread_data in those threads will be INT_MIN, 0, 0, 2, ..., 124, 126. + * Furthermore the value \p 126 will be stored in \p block_aggregate for all threads. + * + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input items + T &output, ///< [out] Calling thread's output items (may be aliased to \p input) + T initial_value, ///< [in] Initial value to seed the exclusive scan (and is assigned to \p output[0] in thread0) + ScanOp scan_op, ///< [in] Binary scan functor + T &block_aggregate) ///< [out] block-wide aggregate reduction of input items + { + InternalBlockScan(temp_storage).ExclusiveScan(input, output, initial_value, scan_op, block_aggregate); + } + + + /** + * \brief Computes an exclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - The \p block_prefix_callback_op functor must implement a member function T operator()(T block_aggregate). + * The functor's input parameter \p block_aggregate is the same value also returned by the scan operation. + * The functor will be invoked by the first warp of threads in the block, however only the return value from + * lane0 is applied as the block-wide prefix. Can be stateful. + * - Supports non-commutative scan operators. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a single thread block that progressively + * computes an exclusive prefix max scan over multiple "tiles" of input using a + * prefix functor to maintain a running total between block-wide scans. Each tile consists + * of 128 integer items that are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * // A stateful callback functor that maintains a running prefix to be applied + * // during consecutive scan operations. + * struct BlockPrefixCallbackOp + * { + * // Running prefix + * int running_total; + * + * // Constructor + * __device__ BlockPrefixCallbackOp(int running_total) : running_total(running_total) {} + * + * // Callback operator to be entered by the first warp of threads in the block. + * // Thread-0 is responsible for returning a value for seeding the block-wide scan. + * __device__ int operator()(int block_aggregate) + * { + * int old_prefix = running_total; + * running_total = (block_aggregate > old_prefix) ? block_aggregate : old_prefix; + * return old_prefix; + * } + * }; + * + * __global__ void ExampleKernel(int *d_data, int num_items, ...) + * { + * // Specialize BlockScan for a 1D block of 128 threads + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Initialize running total + * BlockPrefixCallbackOp prefix_op(INT_MIN); + * + * // Have the block iterate over segments of items + * for (int block_offset = 0; block_offset < num_items; block_offset += 128) + * { + * // Load a segment of consecutive items that are blocked across threads + * int thread_data = d_data[block_offset]; + * + * // Collectively compute the block-wide exclusive prefix max scan + * BlockScan(temp_storage).ExclusiveScan( + * thread_data, thread_data, INT_MIN, cub::Max(), prefix_op); + * CTA_SYNC(); + * + * // Store scanned items to output segment + * d_data[block_offset] = thread_data; + * } + * \endcode + * \par + * Suppose the input \p d_data is 0, -1, 2, -3, 4, -5, .... + * The corresponding output for the first segment will be INT_MIN, 0, 0, 2, ..., 124, 126. + * The output for the second segment will be 126, 128, 128, 130, ..., 252, 254. + * + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + * \tparam BlockPrefixCallbackOp [inferred] Call-back functor type having member T operator()(T block_aggregate) + */ + template < + typename ScanOp, + typename BlockPrefixCallbackOp> + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan functor + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a block-wide prefix to be applied to the logical input sequence. + { + InternalBlockScan(temp_storage).ExclusiveScan(input, output, scan_op, block_prefix_callback_op); + } + + + //@} end member group // Inclusive prefix sums + /******************************************************************//** + * \name Exclusive prefix scan operations (multiple data per thread) + *********************************************************************/ + //@{ + + + /** + * \brief Computes an exclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes an array of consecutive input elements. + * + * \par + * - Supports non-commutative scan operators. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an exclusive prefix max scan of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute the block-wide exclusive prefix max scan + * BlockScan(temp_storage).ExclusiveScan(thread_data, thread_data, INT_MIN, cub::Max()); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [0,-1,2,-3], [4,-5,6,-7], ..., [508,-509,510,-511] }. + * The corresponding output \p thread_data in those threads will be + * { [INT_MIN,0,0,2], [2,4,4,6], ..., [506,508,508,510] }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template < + int ITEMS_PER_THREAD, + typename ScanOp> + __device__ __forceinline__ void ExclusiveScan( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + T initial_value, ///< [in] Initial value to seed the exclusive scan (and is assigned to \p output[0] in thread0) + ScanOp scan_op) ///< [in] Binary scan functor + { + // Reduce consecutive thread items in registers + T thread_prefix = internal::ThreadReduce(input, scan_op); + + // Exclusive thread block-scan + ExclusiveScan(thread_prefix, thread_prefix, initial_value, scan_op); + + // Exclusive scan in registers with prefix as seed + internal::ThreadScanExclusive(input, output, scan_op, thread_prefix); + } + + + /** + * \brief Computes an exclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes an array of consecutive input elements. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - Supports non-commutative scan operators. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an exclusive prefix max scan of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute the block-wide exclusive prefix max scan + * int block_aggregate; + * BlockScan(temp_storage).ExclusiveScan(thread_data, thread_data, INT_MIN, cub::Max(), block_aggregate); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is { [0,-1,2,-3], [4,-5,6,-7], ..., [508,-509,510,-511] }. The + * corresponding output \p thread_data in those threads will be { [INT_MIN,0,0,2], [2,4,4,6], ..., [506,508,508,510] }. + * Furthermore the value \p 510 will be stored in \p block_aggregate for all threads. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template < + int ITEMS_PER_THREAD, + typename ScanOp> + __device__ __forceinline__ void ExclusiveScan( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + T initial_value, ///< [in] Initial value to seed the exclusive scan (and is assigned to \p output[0] in thread0) + ScanOp scan_op, ///< [in] Binary scan functor + T &block_aggregate) ///< [out] block-wide aggregate reduction of input items + { + // Reduce consecutive thread items in registers + T thread_prefix = internal::ThreadReduce(input, scan_op); + + // Exclusive thread block-scan + ExclusiveScan(thread_prefix, thread_prefix, initial_value, scan_op, block_aggregate); + + // Exclusive scan in registers with prefix as seed + internal::ThreadScanExclusive(input, output, scan_op, thread_prefix); + } + + + /** + * \brief Computes an exclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes an array of consecutive input elements. the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - The \p block_prefix_callback_op functor must implement a member function T operator()(T block_aggregate). + * The functor's input parameter \p block_aggregate is the same value also returned by the scan operation. + * The functor will be invoked by the first warp of threads in the block, however only the return value from + * lane0 is applied as the block-wide prefix. Can be stateful. + * - Supports non-commutative scan operators. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a single thread block that progressively + * computes an exclusive prefix max scan over multiple "tiles" of input using a + * prefix functor to maintain a running total between block-wide scans. Each tile consists + * of 128 integer items that are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * // A stateful callback functor that maintains a running prefix to be applied + * // during consecutive scan operations. + * struct BlockPrefixCallbackOp + * { + * // Running prefix + * int running_total; + * + * // Constructor + * __device__ BlockPrefixCallbackOp(int running_total) : running_total(running_total) {} + * + * // Callback operator to be entered by the first warp of threads in the block. + * // Thread-0 is responsible for returning a value for seeding the block-wide scan. + * __device__ int operator()(int block_aggregate) + * { + * int old_prefix = running_total; + * running_total = (block_aggregate > old_prefix) ? block_aggregate : old_prefix; + * return old_prefix; + * } + * }; + * + * __global__ void ExampleKernel(int *d_data, int num_items, ...) + * { + * // Specialize BlockLoad, BlockStore, and BlockScan for a 1D block of 128 threads, 4 ints per thread + * typedef cub::BlockLoad BlockLoad; + * typedef cub::BlockStore BlockStore; + * typedef cub::BlockScan BlockScan; + * + * // Allocate aliased shared memory for BlockLoad, BlockStore, and BlockScan + * __shared__ union { + * typename BlockLoad::TempStorage load; + * typename BlockScan::TempStorage scan; + * typename BlockStore::TempStorage store; + * } temp_storage; + * + * // Initialize running total + * BlockPrefixCallbackOp prefix_op(0); + * + * // Have the block iterate over segments of items + * for (int block_offset = 0; block_offset < num_items; block_offset += 128 * 4) + * { + * // Load a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * BlockLoad(temp_storage.load).Load(d_data + block_offset, thread_data); + * CTA_SYNC(); + * + * // Collectively compute the block-wide exclusive prefix max scan + * BlockScan(temp_storage.scan).ExclusiveScan( + * thread_data, thread_data, INT_MIN, cub::Max(), prefix_op); + * CTA_SYNC(); + * + * // Store scanned items to output segment + * BlockStore(temp_storage.store).Store(d_data + block_offset, thread_data); + * CTA_SYNC(); + * } + * \endcode + * \par + * Suppose the input \p d_data is 0, -1, 2, -3, 4, -5, .... + * The corresponding output for the first segment will be INT_MIN, 0, 0, 2, 2, 4, ..., 508, 510. + * The output for the second segment will be 510, 512, 512, 514, 514, 516, ..., 1020, 1022. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + * \tparam BlockPrefixCallbackOp [inferred] Call-back functor type having member T operator()(T block_aggregate) + */ + template < + int ITEMS_PER_THREAD, + typename ScanOp, + typename BlockPrefixCallbackOp> + __device__ __forceinline__ void ExclusiveScan( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan functor + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a block-wide prefix to be applied to the logical input sequence. + { + // Reduce consecutive thread items in registers + T thread_prefix = internal::ThreadReduce(input, scan_op); + + // Exclusive thread block-scan + ExclusiveScan(thread_prefix, thread_prefix, scan_op, block_prefix_callback_op); + + // Exclusive scan in registers with prefix as seed + internal::ThreadScanExclusive(input, output, scan_op, thread_prefix); + } + + + //@} end member group +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document no-initial-value scans + + /******************************************************************//** + * \name Exclusive prefix scan operations (no initial value, single datum per thread) + *********************************************************************/ + //@{ + + + /** + * \brief Computes an exclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. With no initial value, the output computed for thread0 is undefined. + * + * \par + * - Supports non-commutative scan operators. + * - \rowmajor + * - \smemreuse + * + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op) ///< [in] Binary scan functor + { + InternalBlockScan(temp_storage).ExclusiveScan(input, output, scan_op); + } + + + /** + * \brief Computes an exclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. Also provides every thread with the block-wide \p block_aggregate of all inputs. With no initial value, the output computed for thread0 is undefined. + * + * \par + * - Supports non-commutative scan operators. + * - \rowmajor + * - \smemreuse + * + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan functor + T &block_aggregate) ///< [out] block-wide aggregate reduction of input items + { + InternalBlockScan(temp_storage).ExclusiveScan(input, output, scan_op, block_aggregate); + } + + //@} end member group + /******************************************************************//** + * \name Exclusive prefix scan operations (no initial value, multiple data per thread) + *********************************************************************/ + //@{ + + + /** + * \brief Computes an exclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes an array of consecutive input elements. With no initial value, the output computed for thread0 is undefined. + * + * \par + * - Supports non-commutative scan operators. + * - \blocked + * - \granularity + * - \smemreuse + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template < + int ITEMS_PER_THREAD, + typename ScanOp> + __device__ __forceinline__ void ExclusiveScan( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + ScanOp scan_op) ///< [in] Binary scan functor + { + // Reduce consecutive thread items in registers + T thread_partial = internal::ThreadReduce(input, scan_op); + + // Exclusive thread block-scan + ExclusiveScan(thread_partial, thread_partial, scan_op); + + // Exclusive scan in registers with prefix + internal::ThreadScanExclusive(input, output, scan_op, thread_partial, (linear_tid != 0)); + } + + + /** + * \brief Computes an exclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes an array of consecutive input elements. Also provides every thread with the block-wide \p block_aggregate of all inputs. With no initial value, the output computed for thread0 is undefined. + * + * \par + * - Supports non-commutative scan operators. + * - \blocked + * - \granularity + * - \smemreuse + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template < + int ITEMS_PER_THREAD, + typename ScanOp> + __device__ __forceinline__ void ExclusiveScan( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan functor + T &block_aggregate) ///< [out] block-wide aggregate reduction of input items + { + // Reduce consecutive thread items in registers + T thread_partial = internal::ThreadReduce(input, scan_op); + + // Exclusive thread block-scan + ExclusiveScan(thread_partial, thread_partial, scan_op, block_aggregate); + + // Exclusive scan in registers with prefix + internal::ThreadScanExclusive(input, output, scan_op, thread_partial, (linear_tid != 0)); + } + + + //@} end member group +#endif // DOXYGEN_SHOULD_SKIP_THIS // Do not document no-initial-value scans + + /******************************************************************//** + * \name Inclusive prefix sum operations + *********************************************************************/ + //@{ + + + /** + * \brief Computes an inclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes one input element. + * + * \par + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an inclusive prefix sum of 128 integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain input item for each thread + * int thread_data; + * ... + * + * // Collectively compute the block-wide inclusive prefix sum + * BlockScan(temp_storage).InclusiveSum(thread_data, thread_data); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is 1, 1, ..., 1. The + * corresponding output \p thread_data in those threads will be 1, 2, ..., 128. + * + */ + __device__ __forceinline__ void InclusiveSum( + T input, ///< [in] Calling thread's input item + T &output) ///< [out] Calling thread's output item (may be aliased to \p input) + { + InclusiveScan(input, output, cub::Sum()); + } + + + /** + * \brief Computes an inclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes one input element. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an inclusive prefix sum of 128 integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain input item for each thread + * int thread_data; + * ... + * + * // Collectively compute the block-wide inclusive prefix sum + * int block_aggregate; + * BlockScan(temp_storage).InclusiveSum(thread_data, thread_data, block_aggregate); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is 1, 1, ..., 1. The + * corresponding output \p thread_data in those threads will be 1, 2, ..., 128. + * Furthermore the value \p 128 will be stored in \p block_aggregate for all threads. + * + */ + __device__ __forceinline__ void InclusiveSum( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + T &block_aggregate) ///< [out] block-wide aggregate reduction of input items + { + InclusiveScan(input, output, cub::Sum(), block_aggregate); + } + + + + /** + * \brief Computes an inclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes one input element. Instead of using 0 as the block-wide prefix, the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - The \p block_prefix_callback_op functor must implement a member function T operator()(T block_aggregate). + * The functor's input parameter \p block_aggregate is the same value also returned by the scan operation. + * The functor will be invoked by the first warp of threads in the block, however only the return value from + * lane0 is applied as the block-wide prefix. Can be stateful. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a single thread block that progressively + * computes an inclusive prefix sum over multiple "tiles" of input using a + * prefix functor to maintain a running total between block-wide scans. Each tile consists + * of 128 integer items that are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * // A stateful callback functor that maintains a running prefix to be applied + * // during consecutive scan operations. + * struct BlockPrefixCallbackOp + * { + * // Running prefix + * int running_total; + * + * // Constructor + * __device__ BlockPrefixCallbackOp(int running_total) : running_total(running_total) {} + * + * // Callback operator to be entered by the first warp of threads in the block. + * // Thread-0 is responsible for returning a value for seeding the block-wide scan. + * __device__ int operator()(int block_aggregate) + * { + * int old_prefix = running_total; + * running_total += block_aggregate; + * return old_prefix; + * } + * }; + * + * __global__ void ExampleKernel(int *d_data, int num_items, ...) + * { + * // Specialize BlockScan for a 1D block of 128 threads + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Initialize running total + * BlockPrefixCallbackOp prefix_op(0); + * + * // Have the block iterate over segments of items + * for (int block_offset = 0; block_offset < num_items; block_offset += 128) + * { + * // Load a segment of consecutive items that are blocked across threads + * int thread_data = d_data[block_offset]; + * + * // Collectively compute the block-wide inclusive prefix sum + * BlockScan(temp_storage).InclusiveSum( + * thread_data, thread_data, prefix_op); + * CTA_SYNC(); + * + * // Store scanned items to output segment + * d_data[block_offset] = thread_data; + * } + * \endcode + * \par + * Suppose the input \p d_data is 1, 1, 1, 1, 1, 1, 1, 1, .... + * The corresponding output for the first segment will be 1, 2, ..., 128. + * The output for the second segment will be 129, 130, ..., 256. + * + * \tparam BlockPrefixCallbackOp [inferred] Call-back functor type having member T operator()(T block_aggregate) + */ + template + __device__ __forceinline__ void InclusiveSum( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a block-wide prefix to be applied to the logical input sequence. + { + InclusiveScan(input, output, cub::Sum(), block_prefix_callback_op); + } + + + //@} end member group + /******************************************************************//** + * \name Inclusive prefix sum operations (multiple data per thread) + *********************************************************************/ + //@{ + + + /** + * \brief Computes an inclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes an array of consecutive input elements. + * + * \par + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an inclusive prefix sum of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute the block-wide inclusive prefix sum + * BlockScan(temp_storage).InclusiveSum(thread_data, thread_data); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is { [1,1,1,1], [1,1,1,1], ..., [1,1,1,1] }. The + * corresponding output \p thread_data in those threads will be { [1,2,3,4], [5,6,7,8], ..., [509,510,511,512] }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + */ + template + __device__ __forceinline__ void InclusiveSum( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD]) ///< [out] Calling thread's output items (may be aliased to \p input) + { + if (ITEMS_PER_THREAD == 1) + { + InclusiveSum(input[0], output[0]); + } + else + { + // Reduce consecutive thread items in registers + Sum scan_op; + T thread_prefix = internal::ThreadReduce(input, scan_op); + + // Exclusive thread block-scan + ExclusiveSum(thread_prefix, thread_prefix); + + // Inclusive scan in registers with prefix as seed + internal::ThreadScanInclusive(input, output, scan_op, thread_prefix, (linear_tid != 0)); + } + } + + + /** + * \brief Computes an inclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes an array of consecutive input elements. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an inclusive prefix sum of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute the block-wide inclusive prefix sum + * int block_aggregate; + * BlockScan(temp_storage).InclusiveSum(thread_data, thread_data, block_aggregate); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [1,1,1,1], [1,1,1,1], ..., [1,1,1,1] }. The + * corresponding output \p thread_data in those threads will be + * { [1,2,3,4], [5,6,7,8], ..., [509,510,511,512] }. + * Furthermore the value \p 512 will be stored in \p block_aggregate for all threads. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template + __device__ __forceinline__ void InclusiveSum( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + T &block_aggregate) ///< [out] block-wide aggregate reduction of input items + { + if (ITEMS_PER_THREAD == 1) + { + InclusiveSum(input[0], output[0], block_aggregate); + } + else + { + // Reduce consecutive thread items in registers + Sum scan_op; + T thread_prefix = internal::ThreadReduce(input, scan_op); + + // Exclusive thread block-scan + ExclusiveSum(thread_prefix, thread_prefix, block_aggregate); + + // Inclusive scan in registers with prefix as seed + internal::ThreadScanInclusive(input, output, scan_op, thread_prefix, (linear_tid != 0)); + } + } + + + /** + * \brief Computes an inclusive block-wide prefix scan using addition (+) as the scan operator. Each thread contributes an array of consecutive input elements. Instead of using 0 as the block-wide prefix, the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - The \p block_prefix_callback_op functor must implement a member function T operator()(T block_aggregate). + * The functor's input parameter \p block_aggregate is the same value also returned by the scan operation. + * The functor will be invoked by the first warp of threads in the block, however only the return value from + * lane0 is applied as the block-wide prefix. Can be stateful. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a single thread block that progressively + * computes an inclusive prefix sum over multiple "tiles" of input using a + * prefix functor to maintain a running total between block-wide scans. Each tile consists + * of 512 integer items that are partitioned in a [blocked arrangement](index.html#sec5sec3) + * across 128 threads where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * // A stateful callback functor that maintains a running prefix to be applied + * // during consecutive scan operations. + * struct BlockPrefixCallbackOp + * { + * // Running prefix + * int running_total; + * + * // Constructor + * __device__ BlockPrefixCallbackOp(int running_total) : running_total(running_total) {} + * + * // Callback operator to be entered by the first warp of threads in the block. + * // Thread-0 is responsible for returning a value for seeding the block-wide scan. + * __device__ int operator()(int block_aggregate) + * { + * int old_prefix = running_total; + * running_total += block_aggregate; + * return old_prefix; + * } + * }; + * + * __global__ void ExampleKernel(int *d_data, int num_items, ...) + * { + * // Specialize BlockLoad, BlockStore, and BlockScan for a 1D block of 128 threads, 4 ints per thread + * typedef cub::BlockLoad BlockLoad; + * typedef cub::BlockStore BlockStore; + * typedef cub::BlockScan BlockScan; + * + * // Allocate aliased shared memory for BlockLoad, BlockStore, and BlockScan + * __shared__ union { + * typename BlockLoad::TempStorage load; + * typename BlockScan::TempStorage scan; + * typename BlockStore::TempStorage store; + * } temp_storage; + * + * // Initialize running total + * BlockPrefixCallbackOp prefix_op(0); + * + * // Have the block iterate over segments of items + * for (int block_offset = 0; block_offset < num_items; block_offset += 128 * 4) + * { + * // Load a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * BlockLoad(temp_storage.load).Load(d_data + block_offset, thread_data); + * CTA_SYNC(); + * + * // Collectively compute the block-wide inclusive prefix sum + * BlockScan(temp_storage.scan).IncluisveSum( + * thread_data, thread_data, prefix_op); + * CTA_SYNC(); + * + * // Store scanned items to output segment + * BlockStore(temp_storage.store).Store(d_data + block_offset, thread_data); + * CTA_SYNC(); + * } + * \endcode + * \par + * Suppose the input \p d_data is 1, 1, 1, 1, 1, 1, 1, 1, .... + * The corresponding output for the first segment will be 1, 2, 3, 4, ..., 511, 512. + * The output for the second segment will be 513, 514, 515, 516, ..., 1023, 1024. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam BlockPrefixCallbackOp [inferred] Call-back functor type having member T operator()(T block_aggregate) + */ + template < + int ITEMS_PER_THREAD, + typename BlockPrefixCallbackOp> + __device__ __forceinline__ void InclusiveSum( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a block-wide prefix to be applied to the logical input sequence. + { + if (ITEMS_PER_THREAD == 1) + { + InclusiveSum(input[0], output[0], block_prefix_callback_op); + } + else + { + // Reduce consecutive thread items in registers + Sum scan_op; + T thread_prefix = internal::ThreadReduce(input, scan_op); + + // Exclusive thread block-scan + ExclusiveSum(thread_prefix, thread_prefix, block_prefix_callback_op); + + // Inclusive scan in registers with prefix as seed + internal::ThreadScanInclusive(input, output, scan_op, thread_prefix); + } + } + + + //@} end member group + /******************************************************************//** + * \name Inclusive prefix scan operations + *********************************************************************/ + //@{ + + + /** + * \brief Computes an inclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. + * + * \par + * - Supports non-commutative scan operators. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an inclusive prefix max scan of 128 integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain input item for each thread + * int thread_data; + * ... + * + * // Collectively compute the block-wide inclusive prefix max scan + * BlockScan(temp_storage).InclusiveScan(thread_data, thread_data, cub::Max()); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is 0, -1, 2, -3, ..., 126, -127. The + * corresponding output \p thread_data in those threads will be 0, 0, 2, 2, ..., 126, 126. + * + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op) ///< [in] Binary scan functor + { + InternalBlockScan(temp_storage).InclusiveScan(input, output, scan_op); + } + + + /** + * \brief Computes an inclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - Supports non-commutative scan operators. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an inclusive prefix max scan of 128 integer items that + * are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain input item for each thread + * int thread_data; + * ... + * + * // Collectively compute the block-wide inclusive prefix max scan + * int block_aggregate; + * BlockScan(temp_storage).InclusiveScan(thread_data, thread_data, cub::Max(), block_aggregate); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is 0, -1, 2, -3, ..., 126, -127. The + * corresponding output \p thread_data in those threads will be 0, 0, 2, 2, ..., 126, 126. + * Furthermore the value \p 126 will be stored in \p block_aggregate for all threads. + * + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan functor + T &block_aggregate) ///< [out] block-wide aggregate reduction of input items + { + InternalBlockScan(temp_storage).InclusiveScan(input, output, scan_op, block_aggregate); + } + + + /** + * \brief Computes an inclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - The \p block_prefix_callback_op functor must implement a member function T operator()(T block_aggregate). + * The functor's input parameter \p block_aggregate is the same value also returned by the scan operation. + * The functor will be invoked by the first warp of threads in the block, however only the return value from + * lane0 is applied as the block-wide prefix. Can be stateful. + * - Supports non-commutative scan operators. + * - \rowmajor + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a single thread block that progressively + * computes an inclusive prefix max scan over multiple "tiles" of input using a + * prefix functor to maintain a running total between block-wide scans. Each tile consists + * of 128 integer items that are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * // A stateful callback functor that maintains a running prefix to be applied + * // during consecutive scan operations. + * struct BlockPrefixCallbackOp + * { + * // Running prefix + * int running_total; + * + * // Constructor + * __device__ BlockPrefixCallbackOp(int running_total) : running_total(running_total) {} + * + * // Callback operator to be entered by the first warp of threads in the block. + * // Thread-0 is responsible for returning a value for seeding the block-wide scan. + * __device__ int operator()(int block_aggregate) + * { + * int old_prefix = running_total; + * running_total = (block_aggregate > old_prefix) ? block_aggregate : old_prefix; + * return old_prefix; + * } + * }; + * + * __global__ void ExampleKernel(int *d_data, int num_items, ...) + * { + * // Specialize BlockScan for a 1D block of 128 threads + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Initialize running total + * BlockPrefixCallbackOp prefix_op(INT_MIN); + * + * // Have the block iterate over segments of items + * for (int block_offset = 0; block_offset < num_items; block_offset += 128) + * { + * // Load a segment of consecutive items that are blocked across threads + * int thread_data = d_data[block_offset]; + * + * // Collectively compute the block-wide inclusive prefix max scan + * BlockScan(temp_storage).InclusiveScan( + * thread_data, thread_data, cub::Max(), prefix_op); + * CTA_SYNC(); + * + * // Store scanned items to output segment + * d_data[block_offset] = thread_data; + * } + * \endcode + * \par + * Suppose the input \p d_data is 0, -1, 2, -3, 4, -5, .... + * The corresponding output for the first segment will be 0, 0, 2, 2, ..., 126, 126. + * The output for the second segment will be 128, 128, 130, 130, ..., 254, 254. + * + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + * \tparam BlockPrefixCallbackOp [inferred] Call-back functor type having member T operator()(T block_aggregate) + */ + template < + typename ScanOp, + typename BlockPrefixCallbackOp> + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan functor + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a block-wide prefix to be applied to the logical input sequence. + { + InternalBlockScan(temp_storage).InclusiveScan(input, output, scan_op, block_prefix_callback_op); + } + + + //@} end member group + /******************************************************************//** + * \name Inclusive prefix scan operations (multiple data per thread) + *********************************************************************/ + //@{ + + + /** + * \brief Computes an inclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes an array of consecutive input elements. + * + * \par + * - Supports non-commutative scan operators. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an inclusive prefix max scan of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute the block-wide inclusive prefix max scan + * BlockScan(temp_storage).InclusiveScan(thread_data, thread_data, cub::Max()); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is { [0,-1,2,-3], [4,-5,6,-7], ..., [508,-509,510,-511] }. The + * corresponding output \p thread_data in those threads will be { [0,0,2,2], [4,4,6,6], ..., [508,508,510,510] }. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template < + int ITEMS_PER_THREAD, + typename ScanOp> + __device__ __forceinline__ void InclusiveScan( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + ScanOp scan_op) ///< [in] Binary scan functor + { + if (ITEMS_PER_THREAD == 1) + { + InclusiveScan(input[0], output[0], scan_op); + } + else + { + // Reduce consecutive thread items in registers + T thread_prefix = internal::ThreadReduce(input, scan_op); + + // Exclusive thread block-scan + ExclusiveScan(thread_prefix, thread_prefix, scan_op); + + // Inclusive scan in registers with prefix as seed (first thread does not seed) + internal::ThreadScanInclusive(input, output, scan_op, thread_prefix, (linear_tid != 0)); + } + } + + + /** + * \brief Computes an inclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes an array of consecutive input elements. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - Supports non-commutative scan operators. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates an inclusive prefix max scan of 512 integer items that + * are partitioned in a [blocked arrangement](index.html#sec5sec3) across 128 threads + * where each thread owns 4 consecutive items. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Specialize BlockScan for a 1D block of 128 threads of type int + * typedef cub::BlockScan BlockScan; + * + * // Allocate shared memory for BlockScan + * __shared__ typename BlockScan::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Collectively compute the block-wide inclusive prefix max scan + * int block_aggregate; + * BlockScan(temp_storage).InclusiveScan(thread_data, thread_data, cub::Max(), block_aggregate); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the block of threads is + * { [0,-1,2,-3], [4,-5,6,-7], ..., [508,-509,510,-511] }. + * The corresponding output \p thread_data in those threads will be + * { [0,0,2,2], [4,4,6,6], ..., [508,508,510,510] }. + * Furthermore the value \p 510 will be stored in \p block_aggregate for all threads. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + */ + template < + int ITEMS_PER_THREAD, + typename ScanOp> + __device__ __forceinline__ void InclusiveScan( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan functor + T &block_aggregate) ///< [out] block-wide aggregate reduction of input items + { + if (ITEMS_PER_THREAD == 1) + { + InclusiveScan(input[0], output[0], scan_op, block_aggregate); + } + else + { + // Reduce consecutive thread items in registers + T thread_prefix = internal::ThreadReduce(input, scan_op); + + // Exclusive thread block-scan (with no initial value) + ExclusiveScan(thread_prefix, thread_prefix, scan_op, block_aggregate); + + // Inclusive scan in registers with prefix as seed (first thread does not seed) + internal::ThreadScanInclusive(input, output, scan_op, thread_prefix, (linear_tid != 0)); + } + } + + + /** + * \brief Computes an inclusive block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes an array of consecutive input elements. the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + * + * \par + * - The \p block_prefix_callback_op functor must implement a member function T operator()(T block_aggregate). + * The functor's input parameter \p block_aggregate is the same value also returned by the scan operation. + * The functor will be invoked by the first warp of threads in the block, however only the return value from + * lane0 is applied as the block-wide prefix. Can be stateful. + * - Supports non-commutative scan operators. + * - \blocked + * - \granularity + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates a single thread block that progressively + * computes an inclusive prefix max scan over multiple "tiles" of input using a + * prefix functor to maintain a running total between block-wide scans. Each tile consists + * of 128 integer items that are partitioned across 128 threads. + * \par + * \code + * #include // or equivalently + * + * // A stateful callback functor that maintains a running prefix to be applied + * // during consecutive scan operations. + * struct BlockPrefixCallbackOp + * { + * // Running prefix + * int running_total; + * + * // Constructor + * __device__ BlockPrefixCallbackOp(int running_total) : running_total(running_total) {} + * + * // Callback operator to be entered by the first warp of threads in the block. + * // Thread-0 is responsible for returning a value for seeding the block-wide scan. + * __device__ int operator()(int block_aggregate) + * { + * int old_prefix = running_total; + * running_total = (block_aggregate > old_prefix) ? block_aggregate : old_prefix; + * return old_prefix; + * } + * }; + * + * __global__ void ExampleKernel(int *d_data, int num_items, ...) + * { + * // Specialize BlockLoad, BlockStore, and BlockScan for a 1D block of 128 threads, 4 ints per thread + * typedef cub::BlockLoad BlockLoad; + * typedef cub::BlockStore BlockStore; + * typedef cub::BlockScan BlockScan; + * + * // Allocate aliased shared memory for BlockLoad, BlockStore, and BlockScan + * __shared__ union { + * typename BlockLoad::TempStorage load; + * typename BlockScan::TempStorage scan; + * typename BlockStore::TempStorage store; + * } temp_storage; + * + * // Initialize running total + * BlockPrefixCallbackOp prefix_op(0); + * + * // Have the block iterate over segments of items + * for (int block_offset = 0; block_offset < num_items; block_offset += 128 * 4) + * { + * // Load a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * BlockLoad(temp_storage.load).Load(d_data + block_offset, thread_data); + * CTA_SYNC(); + * + * // Collectively compute the block-wide inclusive prefix max scan + * BlockScan(temp_storage.scan).InclusiveScan( + * thread_data, thread_data, cub::Max(), prefix_op); + * CTA_SYNC(); + * + * // Store scanned items to output segment + * BlockStore(temp_storage.store).Store(d_data + block_offset, thread_data); + * CTA_SYNC(); + * } + * \endcode + * \par + * Suppose the input \p d_data is 0, -1, 2, -3, 4, -5, .... + * The corresponding output for the first segment will be 0, 0, 2, 2, 4, 4, ..., 510, 510. + * The output for the second segment will be 512, 512, 514, 514, 516, 516, ..., 1022, 1022. + * + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam ScanOp [inferred] Binary scan functor type having member T operator()(const T &a, const T &b) + * \tparam BlockPrefixCallbackOp [inferred] Call-back functor type having member T operator()(T block_aggregate) + */ + template < + int ITEMS_PER_THREAD, + typename ScanOp, + typename BlockPrefixCallbackOp> + __device__ __forceinline__ void InclusiveScan( + T (&input)[ITEMS_PER_THREAD], ///< [in] Calling thread's input items + T (&output)[ITEMS_PER_THREAD], ///< [out] Calling thread's output items (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan functor + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a block-wide prefix to be applied to the logical input sequence. + { + if (ITEMS_PER_THREAD == 1) + { + InclusiveScan(input[0], output[0], scan_op, block_prefix_callback_op); + } + else + { + // Reduce consecutive thread items in registers + T thread_prefix = internal::ThreadReduce(input, scan_op); + + // Exclusive thread block-scan + ExclusiveScan(thread_prefix, thread_prefix, scan_op, block_prefix_callback_op); + + // Inclusive scan in registers with prefix as seed + internal::ThreadScanInclusive(input, output, scan_op, thread_prefix); + } + } + + //@} end member group + + +}; + +/** + * \example example_block_scan.cu + */ + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_shuffle.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_shuffle.cuh new file mode 100644 index 0000000000000000000000000000000000000000..58938301c1115758600f176ecb3ea097150a58ee --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_shuffle.cuh @@ -0,0 +1,296 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * The cub::BlockShuffle class provides [collective](index.html#sec0) methods for shuffling data partitioned across a CUDA thread block. + */ + +#pragma once + +#include "../config.cuh" +#include "../util_ptx.cuh" +#include "../util_type.cuh" + +CUB_NAMESPACE_BEGIN + +/** + * \brief The BlockShuffle class provides [collective](index.html#sec0) methods for shuffling data partitioned across a CUDA thread block. + * \ingroup BlockModule + * + * \tparam T The data type to be exchanged. + * \tparam BLOCK_DIM_X The thread block length in threads along the X dimension + * \tparam BLOCK_DIM_Y [optional] The thread block length in threads along the Y dimension (default: 1) + * \tparam BLOCK_DIM_Z [optional] The thread block length in threads along the Z dimension (default: 1) + * \tparam LEGACY_PTX_ARCH [optional] Unused. + * + * \par Overview + * It is commonplace for blocks of threads to rearrange data items between + * threads. The BlockShuffle abstraction allows threads to efficiently shift items + * either (a) up to their successor or (b) down to their predecessor. + * + */ +template < + typename T, + int BLOCK_DIM_X, + int BLOCK_DIM_Y = 1, + int BLOCK_DIM_Z = 1, + int LEGACY_PTX_ARCH = 0> +class BlockShuffle +{ +private: + + /****************************************************************************** + * Constants + ******************************************************************************/ + + enum + { + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + + LOG_WARP_THREADS = CUB_LOG_WARP_THREADS(0), + WARP_THREADS = 1 << LOG_WARP_THREADS, + WARPS = (BLOCK_THREADS + WARP_THREADS - 1) / WARP_THREADS, + }; + + /****************************************************************************** + * Type definitions + ******************************************************************************/ + + /// Shared memory storage layout type (last element from each thread's input) + typedef T _TempStorage[BLOCK_THREADS]; + + +public: + + /// \smemstorage{BlockShuffle} + struct TempStorage : Uninitialized<_TempStorage> {}; + +private: + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + + /// Linear thread-id + unsigned int linear_tid; + + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + +public: + + /******************************************************************//** + * \name Collective constructors + *********************************************************************/ + //@{ + + /** + * \brief Collective constructor using a private static allocation of shared memory as temporary storage. + */ + __device__ __forceinline__ BlockShuffle() + : + temp_storage(PrivateStorage()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + /** + * \brief Collective constructor using the specified memory allocation as temporary storage. + */ + __device__ __forceinline__ BlockShuffle( + TempStorage &temp_storage) ///< [in] Reference to memory allocation having layout type TempStorage + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + //@} end member group + /******************************************************************//** + * \name Shuffle movement + *********************************************************************/ + //@{ + + + /** + * \brief Each threadi obtains the \p input provided by threadi+distance. The offset \p distance may be negative. + * + * \par + * - \smemreuse + */ + __device__ __forceinline__ void Offset( + T input, ///< [in] The input item from the calling thread (threadi) + T& output, ///< [out] The \p input item from the successor (or predecessor) thread threadi+distance (may be aliased to \p input). This value is only updated for for threadi when 0 <= (i + \p distance) < BLOCK_THREADS-1 + int distance = 1) ///< [in] Offset distance (may be negative) + { + temp_storage[linear_tid] = input; + + CTA_SYNC(); + + const int offset_tid = static_cast(linear_tid) + distance; + if ((offset_tid >= 0) && (offset_tid < BLOCK_THREADS)) + { + output = temp_storage[static_cast(offset_tid)]; + } + } + + + /** + * \brief Each threadi obtains the \p input provided by threadi+distance. + * + * \par + * - \smemreuse + */ + __device__ __forceinline__ void Rotate( + T input, ///< [in] The calling thread's input item + T& output, ///< [out] The \p input item from thread thread(i+distance>)%BLOCK_THREADS (may be aliased to \p input). This value is not updated for threadBLOCK_THREADS-1 + unsigned int distance = 1) ///< [in] Offset distance (0 < \p distance < BLOCK_THREADS) + { + temp_storage[linear_tid] = input; + + CTA_SYNC(); + + unsigned int offset = linear_tid + distance; + if (offset >= BLOCK_THREADS) + offset -= BLOCK_THREADS; + + output = temp_storage[offset]; + } + + + /** + * \brief The thread block rotates its [blocked arrangement](index.html#sec5sec3) of \p input items, shifting it up by one item + * + * \par + * - \blocked + * - \granularity + * - \smemreuse + */ + template + __device__ __forceinline__ void Up( + T (&input)[ITEMS_PER_THREAD], ///< [in] The calling thread's input items + T (&prev)[ITEMS_PER_THREAD]) ///< [out] The corresponding predecessor items (may be aliased to \p input). The item \p prev[0] is not updated for thread0. + { + temp_storage[linear_tid] = input[ITEMS_PER_THREAD - 1]; + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = ITEMS_PER_THREAD - 1; ITEM > 0; --ITEM) + prev[ITEM] = input[ITEM - 1]; + + if (linear_tid > 0) + prev[0] = temp_storage[linear_tid - 1]; + } + + + /** + * \brief The thread block rotates its [blocked arrangement](index.html#sec5sec3) of \p input items, shifting it up by one item. All threads receive the \p input provided by threadBLOCK_THREADS-1. + * + * \par + * - \blocked + * - \granularity + * - \smemreuse + */ + template + __device__ __forceinline__ void Up( + T (&input)[ITEMS_PER_THREAD], ///< [in] The calling thread's input items + T (&prev)[ITEMS_PER_THREAD], ///< [out] The corresponding predecessor items (may be aliased to \p input). The item \p prev[0] is not updated for thread0. + T &block_suffix) ///< [out] The item \p input[ITEMS_PER_THREAD-1] from threadBLOCK_THREADS-1, provided to all threads + { + Up(input, prev); + block_suffix = temp_storage[BLOCK_THREADS - 1]; + } + + + /** + * \brief The thread block rotates its [blocked arrangement](index.html#sec5sec3) of \p input items, shifting it down by one item + * + * \par + * - \blocked + * - \granularity + * - \smemreuse + */ + template + __device__ __forceinline__ void Down( + T (&input)[ITEMS_PER_THREAD], ///< [in] The calling thread's input items + T (&prev)[ITEMS_PER_THREAD]) ///< [out] The corresponding predecessor items (may be aliased to \p input). The value \p prev[0] is not updated for threadBLOCK_THREADS-1. + { + temp_storage[linear_tid] = input[0]; + + CTA_SYNC(); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD - 1; ITEM++) + prev[ITEM] = input[ITEM + 1]; + + if (linear_tid < BLOCK_THREADS - 1) + prev[ITEMS_PER_THREAD - 1] = temp_storage[linear_tid + 1]; + } + + + /** + * \brief The thread block rotates its [blocked arrangement](index.html#sec5sec3) of input items, shifting it down by one item. All threads receive \p input[0] provided by thread0. + * + * \par + * - \blocked + * - \granularity + * - \smemreuse + */ + template + __device__ __forceinline__ void Down( + T (&input)[ITEMS_PER_THREAD], ///< [in] The calling thread's input items + T (&prev)[ITEMS_PER_THREAD], ///< [out] The corresponding predecessor items (may be aliased to \p input). The value \p prev[0] is not updated for threadBLOCK_THREADS-1. + T &block_prefix) ///< [out] The item \p input[0] from thread0, provided to all threads + { + Down(input, prev); + block_prefix = temp_storage[0]; + } + + //@} end member group + + +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_store.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_store.cuh new file mode 100644 index 0000000000000000000000000000000000000000..2cb6bee4337ca19e67a53060cfc02b586403d815 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/block_store.cuh @@ -0,0 +1,1070 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Operations for writing linear segments of data from the CUDA thread block + */ + +#pragma once + +#include +#include + +#include "block_exchange.cuh" +#include "../config.cuh" +#include "../util_ptx.cuh" +#include "../util_type.cuh" + +CUB_NAMESPACE_BEGIN + +/** + * \addtogroup UtilIo + * @{ + */ + + +/******************************************************************//** + * \name Blocked arrangement I/O (direct) + *********************************************************************/ +//@{ + +/** + * \brief Store a blocked arrangement of items across a thread block into a linear segment of items. + * + * \blocked + * + * \tparam T [inferred] The data type to store. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam OutputIteratorT [inferred] The random-access iterator type for output \iterator. + */ +template < + typename T, + int ITEMS_PER_THREAD, + typename OutputIteratorT> +__device__ __forceinline__ void StoreDirectBlocked( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD]) ///< [in] Data to store +{ + OutputIteratorT thread_itr = block_itr + (linear_tid * ITEMS_PER_THREAD); + + // Store directly in thread-blocked order + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + thread_itr[ITEM] = items[ITEM]; + } +} + + +/** + * \brief Store a blocked arrangement of items across a thread block into a linear segment of items, guarded by range + * + * \blocked + * + * \tparam T [inferred] The data type to store. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam OutputIteratorT [inferred] The random-access iterator type for output \iterator. + */ +template < + typename T, + int ITEMS_PER_THREAD, + typename OutputIteratorT> +__device__ __forceinline__ void StoreDirectBlocked( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD], ///< [in] Data to store + int valid_items) ///< [in] Number of valid items to write +{ + OutputIteratorT thread_itr = block_itr + (linear_tid * ITEMS_PER_THREAD); + + // Store directly in thread-blocked order + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + if (ITEM + (linear_tid * ITEMS_PER_THREAD) < valid_items) + { + thread_itr[ITEM] = items[ITEM]; + } + } +} + + +/** + * \brief Store a blocked arrangement of items across a thread block into a linear segment of items. + * + * \blocked + * + * The output offset (\p block_ptr + \p block_offset) must be quad-item aligned, + * which is the default starting offset returned by \p cudaMalloc() + * + * \par + * The following conditions will prevent vectorization and storing will fall back to cub::BLOCK_STORE_DIRECT: + * - \p ITEMS_PER_THREAD is odd + * - The data type \p T is not a built-in primitive or CUDA vector type (e.g., \p short, \p int2, \p double, \p float2, etc.) + * + * \tparam T [inferred] The data type to store. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * + */ +template < + typename T, + int ITEMS_PER_THREAD> +__device__ __forceinline__ void StoreDirectBlockedVectorized( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + T *block_ptr, ///< [in] Input pointer for storing from + T (&items)[ITEMS_PER_THREAD]) ///< [in] Data to store +{ + enum + { + // Maximum CUDA vector size is 4 elements + MAX_VEC_SIZE = CUB_MIN(4, ITEMS_PER_THREAD), + + // Vector size must be a power of two and an even divisor of the items per thread + VEC_SIZE = ((((MAX_VEC_SIZE - 1) & MAX_VEC_SIZE) == 0) && ((ITEMS_PER_THREAD % MAX_VEC_SIZE) == 0)) ? + MAX_VEC_SIZE : + 1, + + VECTORS_PER_THREAD = ITEMS_PER_THREAD / VEC_SIZE, + }; + + // Vector type + typedef typename CubVector::Type Vector; + + // Alias global pointer + Vector *block_ptr_vectors = reinterpret_cast(const_cast(block_ptr)); + + // Alias pointers (use "raw" array here which should get optimized away to prevent conservative PTXAS lmem spilling) + Vector raw_vector[VECTORS_PER_THREAD]; + T *raw_items = reinterpret_cast(raw_vector); + + // Copy + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + raw_items[ITEM] = items[ITEM]; + } + + // Direct-store using vector types + StoreDirectBlocked(linear_tid, block_ptr_vectors, raw_vector); +} + + + +//@} end member group +/******************************************************************//** + * \name Striped arrangement I/O (direct) + *********************************************************************/ +//@{ + + +/** + * \brief Store a striped arrangement of data across the thread block into a linear segment of items. + * + * \striped + * + * \tparam BLOCK_THREADS The thread block size in threads + * \tparam T [inferred] The data type to store. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam OutputIteratorT [inferred] The random-access iterator type for output \iterator. + */ +template < + int BLOCK_THREADS, + typename T, + int ITEMS_PER_THREAD, + typename OutputIteratorT> +__device__ __forceinline__ void StoreDirectStriped( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD]) ///< [in] Data to store +{ + OutputIteratorT thread_itr = block_itr + linear_tid; + + // Store directly in striped order + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + thread_itr[(ITEM * BLOCK_THREADS)] = items[ITEM]; + } +} + + +/** + * \brief Store a striped arrangement of data across the thread block into a linear segment of items, guarded by range + * + * \striped + * + * \tparam BLOCK_THREADS The thread block size in threads + * \tparam T [inferred] The data type to store. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam OutputIteratorT [inferred] The random-access iterator type for output \iterator. + */ +template < + int BLOCK_THREADS, + typename T, + int ITEMS_PER_THREAD, + typename OutputIteratorT> +__device__ __forceinline__ void StoreDirectStriped( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD], ///< [in] Data to store + int valid_items) ///< [in] Number of valid items to write +{ + OutputIteratorT thread_itr = block_itr + linear_tid; + + // Store directly in striped order + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + if ((ITEM * BLOCK_THREADS) + linear_tid < valid_items) + { + thread_itr[(ITEM * BLOCK_THREADS)] = items[ITEM]; + } + } +} + + + +//@} end member group +/******************************************************************//** + * \name Warp-striped arrangement I/O (direct) + *********************************************************************/ +//@{ + + +/** + * \brief Store a warp-striped arrangement of data across the thread block into a linear segment of items. + * + * \warpstriped + * + * \par Usage Considerations + * The number of threads in the thread block must be a multiple of the architecture's warp size. + * + * \tparam T [inferred] The data type to store. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam OutputIteratorT [inferred] The random-access iterator type for output \iterator. + */ +template < + typename T, + int ITEMS_PER_THREAD, + typename OutputIteratorT> +__device__ __forceinline__ void StoreDirectWarpStriped( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD]) ///< [out] Data to load +{ + int tid = linear_tid & (CUB_PTX_WARP_THREADS - 1); + int wid = linear_tid >> CUB_PTX_LOG_WARP_THREADS; + int warp_offset = wid * CUB_PTX_WARP_THREADS * ITEMS_PER_THREAD; + + OutputIteratorT thread_itr = block_itr + warp_offset + tid; + + // Store directly in warp-striped order + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + thread_itr[(ITEM * CUB_PTX_WARP_THREADS)] = items[ITEM]; + } +} + + +/** + * \brief Store a warp-striped arrangement of data across the thread block into a linear segment of items, guarded by range + * + * \warpstriped + * + * \par Usage Considerations + * The number of threads in the thread block must be a multiple of the architecture's warp size. + * + * \tparam T [inferred] The data type to store. + * \tparam ITEMS_PER_THREAD [inferred] The number of consecutive items partitioned onto each thread. + * \tparam OutputIteratorT [inferred] The random-access iterator type for output \iterator. + */ +template < + typename T, + int ITEMS_PER_THREAD, + typename OutputIteratorT> +__device__ __forceinline__ void StoreDirectWarpStriped( + int linear_tid, ///< [in] A suitable 1D thread-identifier for the calling thread (e.g., (threadIdx.y * blockDim.x) + linear_tid for 2D thread blocks) + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD], ///< [in] Data to store + int valid_items) ///< [in] Number of valid items to write +{ + int tid = linear_tid & (CUB_PTX_WARP_THREADS - 1); + int wid = linear_tid >> CUB_PTX_LOG_WARP_THREADS; + int warp_offset = wid * CUB_PTX_WARP_THREADS * ITEMS_PER_THREAD; + + OutputIteratorT thread_itr = block_itr + warp_offset + tid; + + // Store directly in warp-striped order + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + if (warp_offset + tid + (ITEM * CUB_PTX_WARP_THREADS) < valid_items) + { + thread_itr[(ITEM * CUB_PTX_WARP_THREADS)] = items[ITEM]; + } + } +} + + +//@} end member group + + +/** @} */ // end group UtilIo + + +//----------------------------------------------------------------------------- +// Generic BlockStore abstraction +//----------------------------------------------------------------------------- + +/** + * \brief cub::BlockStoreAlgorithm enumerates alternative algorithms for cub::BlockStore to write a blocked arrangement of items across a CUDA thread block to a linear segment of memory. + */ +enum BlockStoreAlgorithm +{ + /** + * \par Overview + * + * A [blocked arrangement](index.html#sec5sec3) of data is written + * directly to memory. + * + * \par Performance Considerations + * - The utilization of memory transactions (coalescing) decreases as the + * access stride between threads increases (i.e., the number items per thread). + */ + BLOCK_STORE_DIRECT, + + /** + * \par Overview + * A [striped arrangement](index.html#sec5sec3) of data is written + * directly to memory. + * + * \par Performance Considerations + * The utilization of memory transactions (coalescing) remains high regardless + * of items written per thread. + */ + BLOCK_STORE_STRIPED, + + /** + * \par Overview + * + * A [blocked arrangement](index.html#sec5sec3) of data is written directly + * to memory using CUDA's built-in vectorized stores as a coalescing optimization. + * For example, st.global.v4.s32 instructions will be generated + * when \p T = \p int and \p ITEMS_PER_THREAD % 4 == 0. + * + * \par Performance Considerations + * - The utilization of memory transactions (coalescing) remains high until the the + * access stride between threads (i.e., the number items per thread) exceeds the + * maximum vector store width (typically 4 items or 64B, whichever is lower). + * - The following conditions will prevent vectorization and writing will fall back to cub::BLOCK_STORE_DIRECT: + * - \p ITEMS_PER_THREAD is odd + * - The \p OutputIteratorT is not a simple pointer type + * - The block output offset is not quadword-aligned + * - The data type \p T is not a built-in primitive or CUDA vector type (e.g., \p short, \p int2, \p double, \p float2, etc.) + */ + BLOCK_STORE_VECTORIZE, + + /** + * \par Overview + * A [blocked arrangement](index.html#sec5sec3) is locally + * transposed and then efficiently written to memory as a [striped arrangement](index.html#sec5sec3). + * + * \par Performance Considerations + * - The utilization of memory transactions (coalescing) remains high regardless + * of items written per thread. + * - The local reordering incurs slightly longer latencies and throughput than the + * direct cub::BLOCK_STORE_DIRECT and cub::BLOCK_STORE_VECTORIZE alternatives. + */ + BLOCK_STORE_TRANSPOSE, + + /** + * \par Overview + * A [blocked arrangement](index.html#sec5sec3) is locally + * transposed and then efficiently written to memory as a + * [warp-striped arrangement](index.html#sec5sec3) + * + * \par Usage Considerations + * - BLOCK_THREADS must be a multiple of WARP_THREADS + * + * \par Performance Considerations + * - The utilization of memory transactions (coalescing) remains high regardless + * of items written per thread. + * - The local reordering incurs slightly longer latencies and throughput than the + * direct cub::BLOCK_STORE_DIRECT and cub::BLOCK_STORE_VECTORIZE alternatives. + */ + BLOCK_STORE_WARP_TRANSPOSE, + + /** + * \par Overview + * A [blocked arrangement](index.html#sec5sec3) is locally + * transposed and then efficiently written to memory as a + * [warp-striped arrangement](index.html#sec5sec3) + * To reduce the shared memory requirement, only one warp's worth of shared + * memory is provisioned and is subsequently time-sliced among warps. + * + * \par Usage Considerations + * - BLOCK_THREADS must be a multiple of WARP_THREADS + * + * \par Performance Considerations + * - The utilization of memory transactions (coalescing) remains high regardless + * of items written per thread. + * - Provisions less shared memory temporary storage, but incurs larger + * latencies than the BLOCK_STORE_WARP_TRANSPOSE alternative. + */ + BLOCK_STORE_WARP_TRANSPOSE_TIMESLICED, +}; + + +/** + * \brief The BlockStore class provides [collective](index.html#sec0) data movement methods for writing a [blocked arrangement](index.html#sec5sec3) of items partitioned across a CUDA thread block to a linear segment of memory. ![](block_store_logo.png) + * \ingroup BlockModule + * \ingroup UtilIo + * + * \tparam T The type of data to be written. + * \tparam BLOCK_DIM_X The thread block length in threads along the X dimension + * \tparam ITEMS_PER_THREAD The number of consecutive items partitioned onto each thread. + * \tparam ALGORITHM [optional] cub::BlockStoreAlgorithm tuning policy enumeration. default: cub::BLOCK_STORE_DIRECT. + * \tparam BLOCK_DIM_Y [optional] The thread block length in threads along the Y dimension (default: 1) + * \tparam BLOCK_DIM_Z [optional] The thread block length in threads along the Z dimension (default: 1) + * \tparam LEGACY_PTX_ARCH [optional] Unused. + * + * \par Overview + * - The BlockStore class provides a single data movement abstraction that can be specialized + * to implement different cub::BlockStoreAlgorithm strategies. This facilitates different + * performance policies for different architectures, data types, granularity sizes, etc. + * - BlockStore can be optionally specialized by different data movement strategies: + * -# cub::BLOCK_STORE_DIRECT. A [blocked arrangement](index.html#sec5sec3) of data is written + * directly to memory. [More...](\ref cub::BlockStoreAlgorithm) + * -# cub::BLOCK_STORE_STRIPED. A [striped arrangement](index.html#sec5sec3) + * of data is written directly to memory. [More...](\ref cub::BlockStoreAlgorithm) + * -# cub::BLOCK_STORE_VECTORIZE. A [blocked arrangement](index.html#sec5sec3) + * of data is written directly to memory using CUDA's built-in vectorized stores as a + * coalescing optimization. [More...](\ref cub::BlockStoreAlgorithm) + * -# cub::BLOCK_STORE_TRANSPOSE. A [blocked arrangement](index.html#sec5sec3) + * is locally transposed into a [striped arrangement](index.html#sec5sec3) which is + * then written to memory. [More...](\ref cub::BlockStoreAlgorithm) + * -# cub::BLOCK_STORE_WARP_TRANSPOSE. A [blocked arrangement](index.html#sec5sec3) + * is locally transposed into a [warp-striped arrangement](index.html#sec5sec3) which is + * then written to memory. [More...](\ref cub::BlockStoreAlgorithm) + * -# cub::BLOCK_STORE_WARP_TRANSPOSE_TIMESLICED. A [blocked arrangement](index.html#sec5sec3) + * is locally transposed into a [warp-striped arrangement](index.html#sec5sec3) which is + * then written to memory. To reduce the shared memory requireent, only one warp's worth of shared + * memory is provisioned and is subsequently time-sliced among warps. [More...](\ref cub::BlockStoreAlgorithm) + * - \rowmajor + * + * \par A Simple Example + * \blockcollective{BlockStore} + * \par + * The code snippet below illustrates the storing of a "blocked" arrangement + * of 512 integers across 128 threads (where each thread owns 4 consecutive items) + * into a linear segment of memory. The store is specialized for \p BLOCK_STORE_WARP_TRANSPOSE, + * meaning items are locally reordered among threads so that memory references will be + * efficiently coalesced using a warp-striped access pattern. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * // Specialize BlockStore for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockStore BlockStore; + * + * // Allocate shared memory for BlockStore + * __shared__ typename BlockStore::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Store items to linear memory + * BlockStore(temp_storage).Store(d_data, thread_data); + * + * \endcode + * \par + * Suppose the set of \p thread_data across the block of threads is + * { [0,1,2,3], [4,5,6,7], ..., [508,509,510,511] }. + * The output \p d_data will be 0, 1, 2, 3, 4, 5, .... + * + * \par Re-using dynamically allocating shared memory + * The following example under the examples/block folder illustrates usage of + * dynamically shared memory with BlockReduce and how to re-purpose + * the same memory region: + * example_block_reduce_dyn_smem.cu + * + * This example can be easily adapted to the storage required by BlockStore. + */ +template < + typename T, + int BLOCK_DIM_X, + int ITEMS_PER_THREAD, + BlockStoreAlgorithm ALGORITHM = BLOCK_STORE_DIRECT, + int BLOCK_DIM_Y = 1, + int BLOCK_DIM_Z = 1, + int LEGACY_PTX_ARCH = 0> +class BlockStore +{ +private: + /****************************************************************************** + * Constants and typed definitions + ******************************************************************************/ + + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + }; + + + /****************************************************************************** + * Algorithmic variants + ******************************************************************************/ + + /// Store helper + template + struct StoreInternal; + + + /** + * BLOCK_STORE_DIRECT specialization of store helper + */ + template + struct StoreInternal + { + /// Shared memory storage layout type + typedef NullType TempStorage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ StoreInternal( + TempStorage &/*temp_storage*/, + int linear_tid) + : + linear_tid(linear_tid) + {} + + /// Store items into a linear segment of memory + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD]) ///< [in] Data to store + { + StoreDirectBlocked(linear_tid, block_itr, items); + } + + /// Store items into a linear segment of memory, guarded by range + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD], ///< [in] Data to store + int valid_items) ///< [in] Number of valid items to write + { + StoreDirectBlocked(linear_tid, block_itr, items, valid_items); + } + }; + + + /** + * BLOCK_STORE_STRIPED specialization of store helper + */ + template + struct StoreInternal + { + /// Shared memory storage layout type + typedef NullType TempStorage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ StoreInternal( + TempStorage &/*temp_storage*/, + int linear_tid) + : + linear_tid(linear_tid) + {} + + /// Store items into a linear segment of memory + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD]) ///< [in] Data to store + { + StoreDirectStriped(linear_tid, block_itr, items); + } + + /// Store items into a linear segment of memory, guarded by range + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD], ///< [in] Data to store + int valid_items) ///< [in] Number of valid items to write + { + StoreDirectStriped(linear_tid, block_itr, items, valid_items); + } + }; + + + /** + * BLOCK_STORE_VECTORIZE specialization of store helper + */ + template + struct StoreInternal + { + /// Shared memory storage layout type + typedef NullType TempStorage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ StoreInternal( + TempStorage &/*temp_storage*/, + int linear_tid) + : + linear_tid(linear_tid) + {} + + /// Store items into a linear segment of memory, specialized for native pointer types (attempts vectorization) + __device__ __forceinline__ void Store( + T *block_ptr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD]) ///< [in] Data to store + { + StoreDirectBlockedVectorized(linear_tid, block_ptr, items); + } + + /// Store items into a linear segment of memory, specialized for opaque input iterators (skips vectorization) + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD]) ///< [in] Data to store + { + StoreDirectBlocked(linear_tid, block_itr, items); + } + + /// Store items into a linear segment of memory, guarded by range + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD], ///< [in] Data to store + int valid_items) ///< [in] Number of valid items to write + { + StoreDirectBlocked(linear_tid, block_itr, items, valid_items); + } + }; + + + /** + * BLOCK_STORE_TRANSPOSE specialization of store helper + */ + template + struct StoreInternal + { + // BlockExchange utility type for keys + typedef BlockExchange BlockExchange; + + /// Shared memory storage layout type + struct _TempStorage : BlockExchange::TempStorage + { + /// Temporary storage for partially-full block guard + volatile int valid_items; + }; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + /// Thread reference to shared storage + _TempStorage &temp_storage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ StoreInternal( + TempStorage &temp_storage, + int linear_tid) + : + temp_storage(temp_storage.Alias()), + linear_tid(linear_tid) + {} + + /// Store items into a linear segment of memory + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD]) ///< [in] Data to store + { + BlockExchange(temp_storage).BlockedToStriped(items); + StoreDirectStriped(linear_tid, block_itr, items); + } + + /// Store items into a linear segment of memory, guarded by range + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD], ///< [in] Data to store + int valid_items) ///< [in] Number of valid items to write + { + BlockExchange(temp_storage).BlockedToStriped(items); + if (linear_tid == 0) + temp_storage.valid_items = valid_items; // Move through volatile smem as a workaround to prevent RF spilling on subsequent loads + CTA_SYNC(); + StoreDirectStriped(linear_tid, block_itr, items, temp_storage.valid_items); + } + }; + + + /** + * BLOCK_STORE_WARP_TRANSPOSE specialization of store helper + */ + template + struct StoreInternal + { + enum + { + WARP_THREADS = CUB_WARP_THREADS(0) + }; + + // Assert BLOCK_THREADS must be a multiple of WARP_THREADS + CUB_STATIC_ASSERT((int(BLOCK_THREADS) % int(WARP_THREADS) == 0), "BLOCK_THREADS must be a multiple of WARP_THREADS"); + + // BlockExchange utility type for keys + typedef BlockExchange BlockExchange; + + /// Shared memory storage layout type + struct _TempStorage : BlockExchange::TempStorage + { + /// Temporary storage for partially-full block guard + volatile int valid_items; + }; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + /// Thread reference to shared storage + _TempStorage &temp_storage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ StoreInternal( + TempStorage &temp_storage, + int linear_tid) + : + temp_storage(temp_storage.Alias()), + linear_tid(linear_tid) + {} + + /// Store items into a linear segment of memory + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD]) ///< [in] Data to store + { + BlockExchange(temp_storage).BlockedToWarpStriped(items); + StoreDirectWarpStriped(linear_tid, block_itr, items); + } + + /// Store items into a linear segment of memory, guarded by range + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD], ///< [in] Data to store + int valid_items) ///< [in] Number of valid items to write + { + BlockExchange(temp_storage).BlockedToWarpStriped(items); + if (linear_tid == 0) + temp_storage.valid_items = valid_items; // Move through volatile smem as a workaround to prevent RF spilling on subsequent loads + CTA_SYNC(); + StoreDirectWarpStriped(linear_tid, block_itr, items, temp_storage.valid_items); + } + }; + + + /** + * BLOCK_STORE_WARP_TRANSPOSE_TIMESLICED specialization of store helper + */ + template + struct StoreInternal + { + enum + { + WARP_THREADS = CUB_WARP_THREADS(0) + }; + + // Assert BLOCK_THREADS must be a multiple of WARP_THREADS + CUB_STATIC_ASSERT((int(BLOCK_THREADS) % int(WARP_THREADS) == 0), "BLOCK_THREADS must be a multiple of WARP_THREADS"); + + // BlockExchange utility type for keys + typedef BlockExchange BlockExchange; + + /// Shared memory storage layout type + struct _TempStorage : BlockExchange::TempStorage + { + /// Temporary storage for partially-full block guard + volatile int valid_items; + }; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + /// Thread reference to shared storage + _TempStorage &temp_storage; + + /// Linear thread-id + int linear_tid; + + /// Constructor + __device__ __forceinline__ StoreInternal( + TempStorage &temp_storage, + int linear_tid) + : + temp_storage(temp_storage.Alias()), + linear_tid(linear_tid) + {} + + /// Store items into a linear segment of memory + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD]) ///< [in] Data to store + { + BlockExchange(temp_storage).BlockedToWarpStriped(items); + StoreDirectWarpStriped(linear_tid, block_itr, items); + } + + /// Store items into a linear segment of memory, guarded by range + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [in] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD], ///< [in] Data to store + int valid_items) ///< [in] Number of valid items to write + { + BlockExchange(temp_storage).BlockedToWarpStriped(items); + if (linear_tid == 0) + temp_storage.valid_items = valid_items; // Move through volatile smem as a workaround to prevent RF spilling on subsequent loads + CTA_SYNC(); + StoreDirectWarpStriped(linear_tid, block_itr, items, temp_storage.valid_items); + } + }; + + + /****************************************************************************** + * Type definitions + ******************************************************************************/ + + /// Internal load implementation to use + typedef StoreInternal InternalStore; + + + /// Shared memory storage layout type + typedef typename InternalStore::TempStorage _TempStorage; + + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage& PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Thread reference to shared storage + _TempStorage &temp_storage; + + /// Linear thread-id + int linear_tid; + +public: + + + /// \smemstorage{BlockStore} + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /******************************************************************//** + * \name Collective constructors + *********************************************************************/ + //@{ + + /** + * \brief Collective constructor using a private static allocation of shared memory as temporary storage. + */ + __device__ __forceinline__ BlockStore() + : + temp_storage(PrivateStorage()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + /** + * \brief Collective constructor using the specified memory allocation as temporary storage. + */ + __device__ __forceinline__ BlockStore( + TempStorage &temp_storage) ///< [in] Reference to memory allocation having layout type TempStorage + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + //@} end member group + /******************************************************************//** + * \name Data movement + *********************************************************************/ + //@{ + + + /** + * \brief Store items into a linear segment of memory. + * + * \par + * - \blocked + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the storing of a "blocked" arrangement + * of 512 integers across 128 threads (where each thread owns 4 consecutive items) + * into a linear segment of memory. The store is specialized for \p BLOCK_STORE_WARP_TRANSPOSE, + * meaning items are locally reordered among threads so that memory references will be + * efficiently coalesced using a warp-striped access pattern. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * // Specialize BlockStore for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockStore BlockStore; + * + * // Allocate shared memory for BlockStore + * __shared__ typename BlockStore::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Store items to linear memory + * int thread_data[4]; + * BlockStore(temp_storage).Store(d_data, thread_data); + * + * \endcode + * \par + * Suppose the set of \p thread_data across the block of threads is + * { [0,1,2,3], [4,5,6,7], ..., [508,509,510,511] }. + * The output \p d_data will be 0, 1, 2, 3, 4, 5, .... + * + */ + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [out] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD]) ///< [in] Data to store + { + InternalStore(temp_storage, linear_tid).Store(block_itr, items); + } + + /** + * \brief Store items into a linear segment of memory, guarded by range. + * + * \par + * - \blocked + * - \smemreuse + * + * \par Snippet + * The code snippet below illustrates the guarded storing of a "blocked" arrangement + * of 512 integers across 128 threads (where each thread owns 4 consecutive items) + * into a linear segment of memory. The store is specialized for \p BLOCK_STORE_WARP_TRANSPOSE, + * meaning items are locally reordered among threads so that memory references will be + * efficiently coalesced using a warp-striped access pattern. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, int valid_items, ...) + * { + * // Specialize BlockStore for a 1D block of 128 threads owning 4 integer items each + * typedef cub::BlockStore BlockStore; + * + * // Allocate shared memory for BlockStore + * __shared__ typename BlockStore::TempStorage temp_storage; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[4]; + * ... + * + * // Store items to linear memory + * int thread_data[4]; + * BlockStore(temp_storage).Store(d_data, thread_data, valid_items); + * + * \endcode + * \par + * Suppose the set of \p thread_data across the block of threads is + * { [0,1,2,3], [4,5,6,7], ..., [508,509,510,511] } and \p valid_items is \p 5. + * The output \p d_data will be 0, 1, 2, 3, 4, ?, ?, ?, ..., with + * only the first two threads being unmasked to store portions of valid data. + * + */ + template + __device__ __forceinline__ void Store( + OutputIteratorT block_itr, ///< [out] The thread block's base output iterator for storing to + T (&items)[ITEMS_PER_THREAD], ///< [in] Data to store + int valid_items) ///< [in] Number of valid items to write + { + InternalStore(temp_storage, linear_tid).Store(block_itr, items, valid_items); + } + + //@} end member group +}; + +template > +struct BlockStoreType +{ + using type = cub::BlockStore; +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/radix_rank_sort_operations.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/radix_rank_sort_operations.cuh new file mode 100644 index 0000000000000000000000000000000000000000..a2f7b83900692b3544535dc67050c6428a19abc7 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/radix_rank_sort_operations.cuh @@ -0,0 +1,628 @@ +/****************************************************************************** + * Copyright (c) 2011-2020, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * radix_rank_sort_operations.cuh contains common abstractions, definitions and + * operations used for radix sorting and ranking. + */ + +#pragma once + +#include + +#include +#include + +#include + +#include "../config.cuh" +#include "../util_ptx.cuh" +#include "../util_type.cuh" +#include "cub/detail/cpp_compatibility.cuh" +#include "cub/detail/type_traits.cuh" + + +CUB_NAMESPACE_BEGIN + +/** \brief Base struct for digit extractor. Contains common code to provide + special handling for floating-point -0.0. + + \note This handles correctly both the case when the keys are + bitwise-complemented after twiddling for descending sort (in onesweep) as + well as when the keys are not bit-negated, but the implementation handles + descending sort separately (in other implementations in CUB). Twiddling + alone maps -0.0f to 0x7fffffff and +0.0f to 0x80000000 for float, which are + subsequent bit patterns and bitwise complements of each other. For onesweep, + both -0.0f and +0.0f are mapped to the bit pattern of +0.0f (0x80000000) for + ascending sort, and to the pattern of -0.0f (0x7fffffff) for descending + sort. For all other sorting implementations in CUB, both are always mapped + to +0.0f. Since bit patterns for both -0.0f and +0.0f are next to each other + and only one of them is used, the sorting works correctly. For double, the + same applies, but with 64-bit patterns. +*/ +template ::CATEGORY> +struct BaseDigitExtractor +{ + using TraitsT = Traits; + using UnsignedBits = typename TraitsT::UnsignedBits; + + static __host__ __device__ __forceinline__ UnsignedBits ProcessFloatMinusZero(UnsignedBits key) + { + return key; + } +}; + +template +struct BaseDigitExtractor +{ + using TraitsT = Traits; + using UnsignedBits = typename TraitsT::UnsignedBits; + + static __host__ __device__ __forceinline__ UnsignedBits ProcessFloatMinusZero(UnsignedBits key) + { + UnsignedBits TWIDDLED_MINUS_ZERO_BITS = + TraitsT::TwiddleIn(UnsignedBits(1) << UnsignedBits(8 * sizeof(UnsignedBits) - 1)); + UnsignedBits TWIDDLED_ZERO_BITS = TraitsT::TwiddleIn(0); + return key == TWIDDLED_MINUS_ZERO_BITS ? TWIDDLED_ZERO_BITS : key; + } +}; + +/** \brief A wrapper type to extract digits. Uses the BFE intrinsic to extract a + * key from a digit. */ +template +struct BFEDigitExtractor : BaseDigitExtractor +{ + using typename BaseDigitExtractor::UnsignedBits; + + std::uint32_t bit_start; + std::uint32_t num_bits; + + explicit __device__ __forceinline__ BFEDigitExtractor( + std::uint32_t bit_start = 0, + std::uint32_t num_bits = 0) + : bit_start(bit_start) + , num_bits(num_bits) + { } + + __device__ __forceinline__ std::uint32_t Digit(UnsignedBits key) const + { + return BFE(this->ProcessFloatMinusZero(key), bit_start, num_bits); + } +}; + +/** \brief A wrapper type to extract digits. Uses a combination of shift and + * bitwise and to extract digits. */ +template +struct ShiftDigitExtractor : BaseDigitExtractor +{ + using typename BaseDigitExtractor::UnsignedBits; + + std::uint32_t bit_start; + std::uint32_t mask; + + explicit __device__ __forceinline__ ShiftDigitExtractor( + std::uint32_t bit_start = 0, std::uint32_t num_bits = 0) + : bit_start(bit_start) + , mask((1 << num_bits) - 1) + { } + + __device__ __forceinline__ std::uint32_t Digit(UnsignedBits key) const + { + return std::uint32_t(this->ProcessFloatMinusZero(key) >> UnsignedBits(bit_start)) & mask; + } +}; + + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document +namespace detail +{ + +template +struct logic_helper_t; + +template +struct true_t +{ + static constexpr bool value = true; +}; + +template +using all_t = // + ::cuda::std::is_same< // + logic_helper_t, // + logic_helper_t::value...>>; + +struct identity_decomposer_t +{ + template + __host__ __device__ T& operator()(T &key) const + { + return key; + } +}; + +template +__host__ __device__ void +for_each_member_impl_helper(F f, const ::cuda::std::tuple& tpl, THRUST_NS_QUALIFIER::index_sequence) +{ + auto sink = { (f(::cuda::std::get(tpl)), 0)... }; + (void)sink; +} + +template +__host__ __device__ void +for_each_member_impl(F f, const ::cuda::std::tuple& tpl) +{ + static_assert(sizeof...(Ts), "Empty aggregates are not supported"); + + // Most radix operations are indifferent to the order of operations. + // Conversely, the digit extractor traverses fields from the least significant + // to the most significant to imitate bitset printing where higher bits are on + // the left. It also maps to intuition, where something coming first is more + // important. Therefore, we traverse fields on the opposite order. + for_each_member_impl_helper(f, tpl, THRUST_NS_QUALIFIER::make_reversed_index_sequence{}); +} + +template +__host__ __device__ void for_each_member(F f, DecomposerT decomposer, T& aggregate) +{ + for_each_member_impl(f, decomposer(aggregate)); +} + +namespace radix +{ + +template +using void_t = void; + +template +struct is_fundamental_type +{ + static constexpr bool value = false; +}; + +template +struct is_fundamental_type::UnsignedBits>> +{ + static constexpr bool value = true; +}; + +template +struct is_tuple_of_references_to_fundamental_types_t : ::cuda::std::false_type +{}; + +template +struct is_tuple_of_references_to_fundamental_types_t< // + ::cuda::std::tuple, // + typename ::cuda::std::enable_if< // + all_t::value...>::value // + >::type> // + : ::cuda::std::true_type +{}; + +template +using decomposer_check_t = + is_tuple_of_references_to_fundamental_types_t>; + +template +struct bit_ordered_conversion_policy_t +{ + using bit_ordered_type = typename Traits::UnsignedBits; + + static __host__ __device__ bit_ordered_type to_bit_ordered(detail::identity_decomposer_t, + bit_ordered_type val) + { + return Traits::TwiddleIn(val); + } + + static __host__ __device__ bit_ordered_type from_bit_ordered(detail::identity_decomposer_t, + bit_ordered_type val) + { + return Traits::TwiddleOut(val); + } +}; + +template +struct bit_ordered_inversion_policy_t +{ + using bit_ordered_type = typename Traits::UnsignedBits; + + static __host__ __device__ bit_ordered_type inverse(detail::identity_decomposer_t, + bit_ordered_type val) + { + return ~val; + } +}; + +template ::value> +struct traits_t +{ + using bit_ordered_type = typename Traits::UnsignedBits; + using bit_ordered_conversion_policy = bit_ordered_conversion_policy_t; + using bit_ordered_inversion_policy = bit_ordered_inversion_policy_t; + + template + using digit_extractor_t = FundamentalExtractorT; + + static __host__ __device__ bit_ordered_type min_raw_binary_key(detail::identity_decomposer_t) + { + return Traits::LOWEST_KEY; + } + + static __host__ __device__ bit_ordered_type max_raw_binary_key(detail::identity_decomposer_t) + { + return Traits::MAX_KEY; + } + + static __host__ __device__ int default_end_bit(detail::identity_decomposer_t) + { + return sizeof(T) * 8; + } + + template + static __host__ + __device__ digit_extractor_t + digit_extractor(int begin_bit, int num_bits, detail::identity_decomposer_t) + { + return FundamentalExtractorT(begin_bit, num_bits); + } +}; + +template +struct min_raw_binary_key_f +{ + DecomposerT decomposer; + + template + __host__ __device__ void operator()(T &field) + { + using traits = traits_t::type>; + using bit_ordered_type = typename traits::bit_ordered_type; + reinterpret_cast(field) = + traits::min_raw_binary_key(detail::identity_decomposer_t{}); + } +}; + +template +__host__ __device__ void min_raw_binary_key(DecomposerT decomposer, T &aggregate) +{ + detail::for_each_member(min_raw_binary_key_f{decomposer}, decomposer, aggregate); +} + +template +struct max_raw_binary_key_f +{ + DecomposerT decomposer; + + template + __host__ __device__ void operator()(T &field) + { + using traits = traits_t::type>; + using bit_ordered_type = typename traits::bit_ordered_type; + reinterpret_cast(field) = + traits::max_raw_binary_key(detail::identity_decomposer_t{}); + } +}; + +template +__host__ __device__ void max_raw_binary_key(DecomposerT decomposer, T &aggregate) +{ + detail::for_each_member(max_raw_binary_key_f{decomposer}, decomposer, aggregate); +} + +template +struct to_bit_ordered_f +{ + DecomposerT decomposer; + + template + __host__ __device__ void operator()(T &field) + { + using traits = traits_t::type>; + using bit_ordered_type = typename traits::bit_ordered_type; + using bit_ordered_conversion = typename traits::bit_ordered_conversion_policy; + + auto &ordered_field = reinterpret_cast(field); + ordered_field = bit_ordered_conversion::to_bit_ordered(detail::identity_decomposer_t{}, + ordered_field); + } +}; + +template +__host__ __device__ void to_bit_ordered(DecomposerT decomposer, T &aggregate) +{ + detail::for_each_member(to_bit_ordered_f{decomposer}, decomposer, aggregate); +} + +template +struct from_bit_ordered_f +{ + DecomposerT decomposer; + + template + __host__ __device__ void operator()(T &field) + { + using traits = traits_t::type>; + using bit_ordered_type = typename traits::bit_ordered_type; + using bit_ordered_conversion = typename traits::bit_ordered_conversion_policy; + + auto &ordered_field = reinterpret_cast(field); + ordered_field = bit_ordered_conversion::from_bit_ordered(detail::identity_decomposer_t{}, + ordered_field); + } +}; + +template +__host__ __device__ void from_bit_ordered(DecomposerT decomposer, T &aggregate) +{ + detail::for_each_member(from_bit_ordered_f{decomposer}, decomposer, aggregate); +} + +template +struct inverse_f +{ + DecomposerT decomposer; + + template + __host__ __device__ void operator()(T &field) + { + using traits = traits_t::type>; + using bit_ordered_type = typename traits::bit_ordered_type; + + auto &ordered_field = reinterpret_cast(field); + ordered_field = ~ordered_field; + } +}; + +template +__host__ __device__ void inverse(DecomposerT decomposer, T &aggregate) +{ + detail::for_each_member(inverse_f{decomposer}, decomposer, aggregate); +} + +template +struct default_end_bit_f +{ + int &result; + DecomposerT decomposer; + + template + __host__ __device__ void operator()(T &field) + { + result += sizeof(field) * 8; + } +}; + +template +__host__ __device__ int default_end_bit(DecomposerT decomposer, T &aggregate) +{ + int result{}; + detail::for_each_member(default_end_bit_f{result, decomposer}, + decomposer, + aggregate); + return result; +} + +struct digit_f +{ + std::uint32_t &dst; + std::uint32_t &dst_bit_start; + std::uint32_t &src_bit_start; + std::uint32_t &num_bits; + + template + __host__ __device__ void operator()(T &src) + { + const std::uint32_t src_size = sizeof(T) * 8; + + if (src_bit_start >= src_size) + { + src_bit_start -= src_size; + } + else + { + using traits = traits_t::type>; + using bit_ordered_type = typename traits::bit_ordered_type; + + const std::uint32_t bits_to_copy = min(src_size - src_bit_start, num_bits); + + if (bits_to_copy) + { + bit_ordered_type ordered_src = BaseDigitExtractor::ProcessFloatMinusZero( + reinterpret_cast(src)); + + const std::uint32_t mask = (1 << bits_to_copy) - 1; + dst = dst | (((ordered_src >> src_bit_start) & mask) << dst_bit_start); + + num_bits -= bits_to_copy; + dst_bit_start += bits_to_copy; + } + src_bit_start = 0; + } + } +}; + +template +__host__ __device__ void digit(DecomposerT decomposer, + std::uint32_t &dst, + T &src, + std::uint32_t &dst_bit_start, + std::uint32_t &src_bit_start, + std::uint32_t &num_bits) +{ + detail::for_each_member(digit_f{dst, dst_bit_start, src_bit_start, num_bits}, decomposer, src); +} + +template +struct custom_digit_extractor_t +{ + DecomposerT decomposer; + std::uint32_t bit_start; + std::uint32_t num_bits; + + __host__ __device__ __forceinline__ custom_digit_extractor_t(DecomposerT decomposer, + std::uint32_t bit_start, + std::uint32_t num_bits) + : decomposer(decomposer) + , bit_start(bit_start) + , num_bits(num_bits) + {} + + template + __host__ __device__ __forceinline__ std::uint32_t Digit(T &key) const + { + std::uint32_t result{}; + std::uint32_t dst_bit_start{}; + std::uint32_t src_bit_start = bit_start; + std::uint32_t bits_remaining{num_bits}; + digit(decomposer, result, key, dst_bit_start, src_bit_start, bits_remaining); + return result; + } +}; + +struct custom_bit_conversion_policy_t +{ + template + static __host__ __device__ T to_bit_ordered(DecomposerT decomposer, T val) + { + detail::radix::to_bit_ordered(decomposer, val); + return val; + } + + template + static __host__ __device__ T from_bit_ordered(DecomposerT decomposer, T val) + { + detail::radix::from_bit_ordered(decomposer, val); + return val; + } +}; + +struct custom_bit_inversion_policy_t +{ + template + static __host__ __device__ T inverse(DecomposerT decomposer, T val) + { + detail::radix::inverse(decomposer, val); + return val; + } +}; + +template +struct traits_t +{ + using bit_ordered_type = T; + using bit_ordered_conversion_policy = custom_bit_conversion_policy_t; + using bit_ordered_inversion_policy = custom_bit_inversion_policy_t; + + template + using digit_extractor_t = custom_digit_extractor_t; + + template + static __host__ __device__ bit_ordered_type min_raw_binary_key(DecomposerT decomposer) + { + T val{}; + detail::radix::min_raw_binary_key(decomposer, val); + return val; + } + + template + static __host__ __device__ bit_ordered_type max_raw_binary_key(DecomposerT decomposer) + { + T val{}; + detail::radix::max_raw_binary_key(decomposer, val); + return val; + } + + template + static __host__ __device__ int default_end_bit(DecomposerT decomposer) + { + T aggregate{}; + return detail::radix::default_end_bit(decomposer, aggregate); + } + + template + static __host__ __device__ digit_extractor_t + digit_extractor(int begin_bit, int num_bits, DecomposerT decomposer) + { + return custom_digit_extractor_t(decomposer, begin_bit, num_bits); + } +}; + +} // namespace radix + +} // namespace detail +#endif // DOXYGEN_SHOULD_SKIP_THIS + +//! Twiddling keys for radix sort +template +struct RadixSortTwiddle +{ +private: + using traits = detail::radix::traits_t; + using bit_ordered_type = typename traits::bit_ordered_type; + using bit_ordered_conversion_policy = typename traits::bit_ordered_conversion_policy; + using bit_ordered_inversion_policy = typename traits::bit_ordered_inversion_policy; + +public: + template + static __host__ __device__ __forceinline__ // + bit_ordered_type + In(bit_ordered_type key, DecomposerT decomposer = {}) + { + key = bit_ordered_conversion_policy::to_bit_ordered(decomposer, key); + CUB_IF_CONSTEXPR(IS_DESCENDING) + { + key = bit_ordered_inversion_policy::inverse(decomposer, key); + } + return key; + } + + template + static __host__ __device__ __forceinline__ // + bit_ordered_type + Out(bit_ordered_type key, DecomposerT decomposer = {}) + { + CUB_IF_CONSTEXPR(IS_DESCENDING) + { + key = bit_ordered_inversion_policy::inverse(decomposer, key); + } + key = bit_ordered_conversion_policy::from_bit_ordered(decomposer, key); + return key; + } + + template + static __host__ __device__ __forceinline__ // + bit_ordered_type + DefaultKey(DecomposerT decomposer = {}) + { + return IS_DESCENDING ? traits::min_raw_binary_key(decomposer) + : traits::max_raw_binary_key(decomposer); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_histogram_atomic.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_histogram_atomic.cuh new file mode 100644 index 0000000000000000000000000000000000000000..93299fa7192b6081c6ab0de16d7e42014969b991 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_histogram_atomic.cuh @@ -0,0 +1,77 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * The cub::BlockHistogramAtomic class provides atomic-based methods for constructing block-wide histograms from data samples partitioned across a CUDA thread block. + */ + +#pragma once + +#include "../../config.cuh" + +CUB_NAMESPACE_BEGIN + + +/** + * \brief The BlockHistogramAtomic class provides atomic-based methods for constructing block-wide histograms from data samples partitioned across a CUDA thread block. + */ +template +struct BlockHistogramAtomic +{ + /// Shared memory storage layout type + struct TempStorage {}; + + + /// Constructor + __device__ __forceinline__ BlockHistogramAtomic( + TempStorage &temp_storage) + {} + + + /// Composite data onto an existing histogram + template < + typename T, + typename CounterT, + int ITEMS_PER_THREAD> + __device__ __forceinline__ void Composite( + T (&items)[ITEMS_PER_THREAD], ///< [in] Calling thread's input values to histogram + CounterT histogram[BINS]) ///< [out] Reference to shared/device-accessible memory histogram + { + // Update histogram + #pragma unroll + for (int i = 0; i < ITEMS_PER_THREAD; ++i) + { + atomicAdd(histogram + items[i], 1); + } + } + +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_histogram_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_histogram_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..79659ae106d9b0b8e5991345da27ae9956cc167e --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_histogram_sort.cuh @@ -0,0 +1,219 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * The cub::BlockHistogramSort class provides sorting-based methods for constructing block-wide histograms from data samples partitioned across a CUDA thread block. + */ + +#pragma once + +#include "../../block/block_radix_sort.cuh" +#include "../../block/block_discontinuity.cuh" +#include "../../config.cuh" +#include "../../util_ptx.cuh" + +CUB_NAMESPACE_BEGIN + + + +/** + * \brief The BlockHistogramSort class provides sorting-based methods for constructing block-wide histograms from data samples partitioned across a CUDA thread block. + */ +template < + typename T, ///< Sample type + int BLOCK_DIM_X, ///< The thread block length in threads along the X dimension + int ITEMS_PER_THREAD, ///< The number of samples per thread + int BINS, ///< The number of bins into which histogram samples may fall + int BLOCK_DIM_Y, ///< The thread block length in threads along the Y dimension + int BLOCK_DIM_Z, ///< The thread block length in threads along the Z dimension + int LEGACY_PTX_ARCH = 0> ///< The PTX compute capability for which to to specialize this collective (unused) +struct BlockHistogramSort +{ + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + }; + + // Parameterize BlockRadixSort type for our thread block + typedef BlockRadixSort< + T, + BLOCK_DIM_X, + ITEMS_PER_THREAD, + NullType, + 4, + true, + BLOCK_SCAN_WARP_SCANS, + cudaSharedMemBankSizeFourByte, + BLOCK_DIM_Y, + BLOCK_DIM_Z> + BlockRadixSortT; + + // Parameterize BlockDiscontinuity type for our thread block + typedef BlockDiscontinuity< + T, + BLOCK_DIM_X, + BLOCK_DIM_Y, + BLOCK_DIM_Z> + BlockDiscontinuityT; + + /// Shared memory + union _TempStorage + { + // Storage for sorting bin values + typename BlockRadixSortT::TempStorage sort; + + struct Discontinuities + { + // Storage for detecting discontinuities in the tile of sorted bin values + typename BlockDiscontinuityT::TempStorage flag; + + // Storage for noting begin/end offsets of bin runs in the tile of sorted bin values + unsigned int run_begin[BINS]; + unsigned int run_end[BINS]; + } discontinuities; + }; + + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + // Thread fields + _TempStorage &temp_storage; + unsigned int linear_tid; + + + /// Constructor + __device__ __forceinline__ BlockHistogramSort( + TempStorage &temp_storage) + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + // Discontinuity functor + struct DiscontinuityOp + { + // Reference to temp_storage + _TempStorage &temp_storage; + + // Constructor + __device__ __forceinline__ DiscontinuityOp(_TempStorage &temp_storage) : + temp_storage(temp_storage) + {} + + // Discontinuity predicate + __device__ __forceinline__ bool operator()(const T &a, const T &b, int b_index) + { + if (a != b) + { + // Note the begin/end offsets in shared storage + temp_storage.discontinuities.run_begin[b] = b_index; + temp_storage.discontinuities.run_end[a] = b_index; + + return true; + } + else + { + return false; + } + } + }; + + + // Composite data onto an existing histogram + template < + typename CounterT > + __device__ __forceinline__ void Composite( + T (&items)[ITEMS_PER_THREAD], ///< [in] Calling thread's input values to histogram + CounterT histogram[BINS]) ///< [out] Reference to shared/device-accessible memory histogram + { + enum { TILE_SIZE = BLOCK_THREADS * ITEMS_PER_THREAD }; + + // Sort bytes in blocked arrangement + BlockRadixSortT(temp_storage.sort).Sort(items); + + CTA_SYNC(); + + // Initialize the shared memory's run_begin and run_end for each bin + int histo_offset = 0; + + #pragma unroll + for(; histo_offset + BLOCK_THREADS <= BINS; histo_offset += BLOCK_THREADS) + { + temp_storage.discontinuities.run_begin[histo_offset + linear_tid] = TILE_SIZE; + temp_storage.discontinuities.run_end[histo_offset + linear_tid] = TILE_SIZE; + } + // Finish up with guarded initialization if necessary + if ((BINS % BLOCK_THREADS != 0) && (histo_offset + linear_tid < BINS)) + { + temp_storage.discontinuities.run_begin[histo_offset + linear_tid] = TILE_SIZE; + temp_storage.discontinuities.run_end[histo_offset + linear_tid] = TILE_SIZE; + } + + CTA_SYNC(); + + int flags[ITEMS_PER_THREAD]; // unused + + // Compute head flags to demarcate contiguous runs of the same bin in the sorted tile + DiscontinuityOp flag_op(temp_storage); + BlockDiscontinuityT(temp_storage.discontinuities.flag).FlagHeads(flags, items, flag_op); + + // Update begin for first item + if (linear_tid == 0) temp_storage.discontinuities.run_begin[items[0]] = 0; + + CTA_SYNC(); + + // Composite into histogram + histo_offset = 0; + + #pragma unroll + for(; histo_offset + BLOCK_THREADS <= BINS; histo_offset += BLOCK_THREADS) + { + int thread_offset = histo_offset + linear_tid; + CounterT count = temp_storage.discontinuities.run_end[thread_offset] - temp_storage.discontinuities.run_begin[thread_offset]; + histogram[thread_offset] += count; + } + + // Finish up with guarded composition if necessary + if ((BINS % BLOCK_THREADS != 0) && (histo_offset + linear_tid < BINS)) + { + int thread_offset = histo_offset + linear_tid; + CounterT count = temp_storage.discontinuities.run_end[thread_offset] - temp_storage.discontinuities.run_begin[thread_offset]; + histogram[thread_offset] += count; + } + } + +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_reduce_raking.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_reduce_raking.cuh new file mode 100644 index 0000000000000000000000000000000000000000..423f18f86797575ea4a2479aaf207c8a850ab6f3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_reduce_raking.cuh @@ -0,0 +1,221 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::BlockReduceRaking provides raking-based methods of parallel reduction across a CUDA thread block. Supports non-commutative reduction operators. + */ + +#pragma once + +#include "../../block/block_raking_layout.cuh" +#include "../../warp/warp_reduce.cuh" +#include "../../thread/thread_reduce.cuh" +#include "../../config.cuh" +#include "../../util_ptx.cuh" + +CUB_NAMESPACE_BEGIN + + +/** + * \brief BlockReduceRaking provides raking-based methods of parallel reduction across a CUDA thread block. Supports non-commutative reduction operators. + * + * Supports non-commutative binary reduction operators. Unlike commutative + * reduction operators (e.g., addition), the application of a non-commutative + * reduction operator (e.g, string concatenation) across a sequence of inputs must + * honor the relative ordering of items and partial reductions when applying the + * reduction operator. + * + * Compared to the implementation of BlockReduceRakingCommutativeOnly (which + * does not support non-commutative operators), this implementation requires a + * few extra rounds of inter-thread communication. + */ +template < + typename T, ///< Data type being reduced + int BLOCK_DIM_X, ///< The thread block length in threads along the X dimension + int BLOCK_DIM_Y, ///< The thread block length in threads along the Y dimension + int BLOCK_DIM_Z, ///< The thread block length in threads along the Z dimension + int LEGACY_PTX_ARCH = 0> ///< The PTX compute capability for which to to specialize this collective +struct BlockReduceRaking +{ + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + }; + + /// Layout type for padded thread block raking grid + typedef BlockRakingLayout BlockRakingLayout; + + /// WarpReduce utility type + typedef typename WarpReduce::InternalWarpReduce WarpReduce; + + /// Constants + enum + { + /// Number of raking threads + RAKING_THREADS = BlockRakingLayout::RAKING_THREADS, + + /// Number of raking elements per warp synchronous raking thread + SEGMENT_LENGTH = BlockRakingLayout::SEGMENT_LENGTH, + + /// Cooperative work can be entirely warp synchronous + WARP_SYNCHRONOUS = (int(RAKING_THREADS) == int(BLOCK_THREADS)), + + /// Whether or not warp-synchronous reduction should be unguarded (i.e., the warp-reduction elements is a power of two + WARP_SYNCHRONOUS_UNGUARDED = PowerOfTwo::VALUE, + + /// Whether or not accesses into smem are unguarded + RAKING_UNGUARDED = BlockRakingLayout::UNGUARDED, + + }; + + + /// Shared memory storage layout type + union _TempStorage + { + typename WarpReduce::TempStorage warp_storage; ///< Storage for warp-synchronous reduction + typename BlockRakingLayout::TempStorage raking_grid; ///< Padded thread block raking grid + }; + + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + // Thread fields + _TempStorage &temp_storage; + unsigned int linear_tid; + + + /// Constructor + __device__ __forceinline__ BlockReduceRaking( + TempStorage &temp_storage) + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + template + __device__ __forceinline__ T RakingReduction( + ReductionOp reduction_op, ///< [in] Binary reduction operator + T *raking_segment, + T partial, ///< [in] [lane0 only] Warp-wide aggregate reduction of input items + int num_valid, ///< [in] Number of valid elements (may be less than BLOCK_THREADS) + Int2Type /*iteration*/) + { + // Update partial if addend is in range + if ((IS_FULL_TILE && RAKING_UNGUARDED) || ((linear_tid * SEGMENT_LENGTH) + ITERATION < num_valid)) + { + T addend = raking_segment[ITERATION]; + partial = reduction_op(partial, addend); + } + return RakingReduction(reduction_op, raking_segment, partial, num_valid, Int2Type()); + } + + template + __device__ __forceinline__ T RakingReduction( + ReductionOp /*reduction_op*/, ///< [in] Binary reduction operator + T * /*raking_segment*/, + T partial, ///< [in] [lane0 only] Warp-wide aggregate reduction of input items + int /*num_valid*/, ///< [in] Number of valid elements (may be less than BLOCK_THREADS) + Int2Type /*iteration*/) + { + return partial; + } + + + + /// Computes a thread block-wide reduction using the specified reduction operator. The first num_valid threads each contribute one reduction partial. The return value is only valid for thread0. + template < + bool IS_FULL_TILE, + typename ReductionOp> + __device__ __forceinline__ T Reduce( + T partial, ///< [in] Calling thread's input partial reductions + int num_valid, ///< [in] Number of valid elements (may be less than BLOCK_THREADS) + ReductionOp reduction_op) ///< [in] Binary reduction operator + { + if (WARP_SYNCHRONOUS) + { + // Short-circuit directly to warp synchronous reduction (unguarded if active threads is a power-of-two) + partial = WarpReduce(temp_storage.warp_storage).template Reduce( + partial, + num_valid, + reduction_op); + } + else + { + // Place partial into shared memory grid. + *BlockRakingLayout::PlacementPtr(temp_storage.raking_grid, linear_tid) = partial; + + CTA_SYNC(); + + // Reduce parallelism to one warp + if (linear_tid < RAKING_THREADS) + { + // Raking reduction in grid + T *raking_segment = BlockRakingLayout::RakingPtr(temp_storage.raking_grid, linear_tid); + partial = raking_segment[0]; + + partial = RakingReduction(reduction_op, raking_segment, partial, num_valid, Int2Type<1>()); + + int valid_raking_threads = (IS_FULL_TILE) ? + RAKING_THREADS : + (num_valid + SEGMENT_LENGTH - 1) / SEGMENT_LENGTH; + + partial = WarpReduce(temp_storage.warp_storage).template Reduce( + partial, + valid_raking_threads, + reduction_op); + + } + } + + return partial; + } + + + /// Computes a thread block-wide reduction using addition (+) as the reduction operator. The first num_valid threads each contribute one reduction partial. The return value is only valid for thread0. + template + __device__ __forceinline__ T Sum( + T partial, ///< [in] Calling thread's input partial reductions + int num_valid) ///< [in] Number of valid elements (may be less than BLOCK_THREADS) + { + cub::Sum reduction_op; + + return Reduce(partial, num_valid, reduction_op); + } + + + +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_reduce_raking_commutative_only.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_reduce_raking_commutative_only.cuh new file mode 100644 index 0000000000000000000000000000000000000000..1fc1caab15aaf748fb41232b2d7abc9ee25539cf --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_reduce_raking_commutative_only.cuh @@ -0,0 +1,195 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::BlockReduceRakingCommutativeOnly provides raking-based methods of parallel reduction across a CUDA thread block. Does not support non-commutative reduction operators. + */ + +#pragma once + +#include "block_reduce_raking.cuh" +#include "../../warp/warp_reduce.cuh" +#include "../../thread/thread_reduce.cuh" +#include "../../config.cuh" +#include "../../util_ptx.cuh" + +CUB_NAMESPACE_BEGIN + + +/** + * \brief BlockReduceRakingCommutativeOnly provides raking-based methods of parallel reduction across a CUDA thread block. Does not support non-commutative reduction operators. Does not support block sizes that are not a multiple of the warp size. + */ +template < + typename T, ///< Data type being reduced + int BLOCK_DIM_X, ///< The thread block length in threads along the X dimension + int BLOCK_DIM_Y, ///< The thread block length in threads along the Y dimension + int BLOCK_DIM_Z, ///< The thread block length in threads along the Z dimension + int LEGACY_PTX_ARCH = 0> ///< The PTX compute capability for which to to specialize this collective +struct BlockReduceRakingCommutativeOnly +{ + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + }; + + // The fall-back implementation to use when BLOCK_THREADS is not a multiple of the warp size or not all threads have valid values + typedef BlockReduceRaking FallBack; + + /// Constants + enum + { + /// Number of warp threads + WARP_THREADS = CUB_WARP_THREADS(0), + + /// Whether or not to use fall-back + USE_FALLBACK = ((BLOCK_THREADS % WARP_THREADS != 0) || (BLOCK_THREADS <= WARP_THREADS)), + + /// Number of raking threads + RAKING_THREADS = WARP_THREADS, + + /// Number of threads actually sharing items with the raking threads + SHARING_THREADS = CUB_MAX(1, BLOCK_THREADS - RAKING_THREADS), + + /// Number of raking elements per warp synchronous raking thread + SEGMENT_LENGTH = SHARING_THREADS / WARP_THREADS, + }; + + /// WarpReduce utility type + typedef WarpReduce WarpReduce; + + /// Layout type for padded thread block raking grid + typedef BlockRakingLayout BlockRakingLayout; + + /// Shared memory storage layout type + union _TempStorage + { + struct DefaultStorage + { + typename WarpReduce::TempStorage warp_storage; ///< Storage for warp-synchronous reduction + typename BlockRakingLayout::TempStorage raking_grid; ///< Padded thread block raking grid + } default_storage; + + typename FallBack::TempStorage fallback_storage; ///< Fall-back storage for non-commutative block reduction + }; + + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + // Thread fields + _TempStorage &temp_storage; + unsigned int linear_tid; + + + /// Constructor + __device__ __forceinline__ BlockReduceRakingCommutativeOnly( + TempStorage &temp_storage) + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + /// Computes a thread block-wide reduction using addition (+) as the reduction operator. The first num_valid threads each contribute one reduction partial. The return value is only valid for thread0. + template + __device__ __forceinline__ T Sum( + T partial, ///< [in] Calling thread's input partial reductions + int num_valid) ///< [in] Number of valid elements (may be less than BLOCK_THREADS) + { + if (USE_FALLBACK || !FULL_TILE) + { + return FallBack(temp_storage.fallback_storage).template Sum(partial, num_valid); + } + else + { + // Place partial into shared memory grid + if (linear_tid >= RAKING_THREADS) + *BlockRakingLayout::PlacementPtr(temp_storage.default_storage.raking_grid, linear_tid - RAKING_THREADS) = partial; + + CTA_SYNC(); + + // Reduce parallelism to one warp + if (linear_tid < RAKING_THREADS) + { + // Raking reduction in grid + T *raking_segment = BlockRakingLayout::RakingPtr(temp_storage.default_storage.raking_grid, linear_tid); + partial = internal::ThreadReduce(raking_segment, cub::Sum(), partial); + + // Warp reduction + partial = WarpReduce(temp_storage.default_storage.warp_storage).Sum(partial); + } + } + + return partial; + } + + + /// Computes a thread block-wide reduction using the specified reduction operator. The first num_valid threads each contribute one reduction partial. The return value is only valid for thread0. + template < + bool FULL_TILE, + typename ReductionOp> + __device__ __forceinline__ T Reduce( + T partial, ///< [in] Calling thread's input partial reductions + int num_valid, ///< [in] Number of valid elements (may be less than BLOCK_THREADS) + ReductionOp reduction_op) ///< [in] Binary reduction operator + { + if (USE_FALLBACK || !FULL_TILE) + { + return FallBack(temp_storage.fallback_storage).template Reduce(partial, num_valid, reduction_op); + } + else + { + // Place partial into shared memory grid + if (linear_tid >= RAKING_THREADS) + *BlockRakingLayout::PlacementPtr(temp_storage.default_storage.raking_grid, linear_tid - RAKING_THREADS) = partial; + + CTA_SYNC(); + + // Reduce parallelism to one warp + if (linear_tid < RAKING_THREADS) + { + // Raking reduction in grid + T *raking_segment = BlockRakingLayout::RakingPtr(temp_storage.default_storage.raking_grid, linear_tid); + partial = internal::ThreadReduce(raking_segment, reduction_op, partial); + + // Warp reduction + partial = WarpReduce(temp_storage.default_storage.warp_storage).Reduce(partial, reduction_op); + } + } + + return partial; + } + +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_reduce_warp_reductions.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_reduce_warp_reductions.cuh new file mode 100644 index 0000000000000000000000000000000000000000..1e51a9fcfe101ac07ac4522500bcd53e2c97498a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_reduce_warp_reductions.cuh @@ -0,0 +1,214 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::BlockReduceWarpReductions provides variants of warp-reduction-based parallel reduction across a CUDA thread block. Supports non-commutative reduction operators. + */ + +#pragma once + +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * \brief BlockReduceWarpReductions provides variants of warp-reduction-based parallel reduction across a CUDA thread block. Supports non-commutative reduction operators. + */ +template < + typename T, ///< Data type being reduced + int BLOCK_DIM_X, ///< The thread block length in threads along the X dimension + int BLOCK_DIM_Y, ///< The thread block length in threads along the Y dimension + int BLOCK_DIM_Z, ///< The thread block length in threads along the Z dimension + int LEGACY_PTX_ARCH = 0> ///< The PTX compute capability for which to to specialize this collective +struct BlockReduceWarpReductions +{ + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + + /// Number of warp threads + WARP_THREADS = CUB_WARP_THREADS(0), + + /// Number of active warps + WARPS = (BLOCK_THREADS + WARP_THREADS - 1) / WARP_THREADS, + + /// The logical warp size for warp reductions + LOGICAL_WARP_SIZE = CUB_MIN(BLOCK_THREADS, WARP_THREADS), + + /// Whether or not the logical warp size evenly divides the thread block size + EVEN_WARP_MULTIPLE = (BLOCK_THREADS % LOGICAL_WARP_SIZE == 0) + }; + + + /// WarpReduce utility type + typedef typename WarpReduce::InternalWarpReduce WarpReduce; + + + /// Shared memory storage layout type + struct _TempStorage + { + typename WarpReduce::TempStorage warp_reduce[WARPS]; ///< Buffer for warp-synchronous reduction + T warp_aggregates[WARPS]; ///< Shared totals from each warp-synchronous reduction + T block_prefix; ///< Shared prefix for the entire thread block + }; + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + // Thread fields + _TempStorage &temp_storage; + int linear_tid; + int warp_id; + int lane_id; + + + /// Constructor + __device__ __forceinline__ BlockReduceWarpReductions( + TempStorage &temp_storage) + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)), + warp_id((WARPS == 1) ? 0 : linear_tid / WARP_THREADS), + lane_id(LaneId()) + {} + + + template + __device__ __forceinline__ T ApplyWarpAggregates( + ReductionOp reduction_op, ///< [in] Binary reduction operator + T warp_aggregate, ///< [in] [lane0 only] Warp-wide aggregate reduction of input items + int num_valid, ///< [in] Number of valid elements (may be less than BLOCK_THREADS) + Int2Type /*successor_warp*/) + { + if (FULL_TILE || (SUCCESSOR_WARP * LOGICAL_WARP_SIZE < num_valid)) + { + T addend = temp_storage.warp_aggregates[SUCCESSOR_WARP]; + warp_aggregate = reduction_op(warp_aggregate, addend); + } + return ApplyWarpAggregates(reduction_op, warp_aggregate, num_valid, Int2Type()); + } + + template + __device__ __forceinline__ T ApplyWarpAggregates( + ReductionOp /*reduction_op*/, ///< [in] Binary reduction operator + T warp_aggregate, ///< [in] [lane0 only] Warp-wide aggregate reduction of input items + int /*num_valid*/, ///< [in] Number of valid elements (may be less than BLOCK_THREADS) + Int2Type /*successor_warp*/) + { + return warp_aggregate; + } + + + /// Returns block-wide aggregate in thread0. + template < + bool FULL_TILE, + typename ReductionOp> + __device__ __forceinline__ T ApplyWarpAggregates( + ReductionOp reduction_op, ///< [in] Binary reduction operator + T warp_aggregate, ///< [in] [lane0 only] Warp-wide aggregate reduction of input items + int num_valid) ///< [in] Number of valid elements (may be less than BLOCK_THREADS) + { + // Share lane aggregates + if (lane_id == 0) + { + detail::uninitialized_copy(temp_storage.warp_aggregates + warp_id, + warp_aggregate); + } + + CTA_SYNC(); + + // Update total aggregate in warp 0, lane 0 + if (linear_tid == 0) + { + warp_aggregate = ApplyWarpAggregates(reduction_op, warp_aggregate, num_valid, Int2Type<1>()); + } + + return warp_aggregate; + } + + + /// Computes a thread block-wide reduction using addition (+) as the reduction operator. The first num_valid threads each contribute one reduction partial. The return value is only valid for thread0. + template + __device__ __forceinline__ T Sum( + T input, ///< [in] Calling thread's input partial reductions + int num_valid) ///< [in] Number of valid elements (may be less than BLOCK_THREADS) + { + cub::Sum reduction_op; + int warp_offset = (warp_id * LOGICAL_WARP_SIZE); + int warp_num_valid = ((FULL_TILE && EVEN_WARP_MULTIPLE) || (warp_offset + LOGICAL_WARP_SIZE <= num_valid)) ? + LOGICAL_WARP_SIZE : + num_valid - warp_offset; + + // Warp reduction in every warp + T warp_aggregate = WarpReduce(temp_storage.warp_reduce[warp_id]).template Reduce<(FULL_TILE && EVEN_WARP_MULTIPLE)>( + input, + warp_num_valid, + cub::Sum()); + + // Update outputs and block_aggregate with warp-wide aggregates from lane-0s + return ApplyWarpAggregates(reduction_op, warp_aggregate, num_valid); + } + + + /// Computes a thread block-wide reduction using the specified reduction operator. The first num_valid threads each contribute one reduction partial. The return value is only valid for thread0. + template < + bool FULL_TILE, + typename ReductionOp> + __device__ __forceinline__ T Reduce( + T input, ///< [in] Calling thread's input partial reductions + int num_valid, ///< [in] Number of valid elements (may be less than BLOCK_THREADS) + ReductionOp reduction_op) ///< [in] Binary reduction operator + { + int warp_offset = warp_id * LOGICAL_WARP_SIZE; + int warp_num_valid = ((FULL_TILE && EVEN_WARP_MULTIPLE) || (warp_offset + LOGICAL_WARP_SIZE <= num_valid)) ? + LOGICAL_WARP_SIZE : + num_valid - warp_offset; + + // Warp reduction in every warp + T warp_aggregate = WarpReduce(temp_storage.warp_reduce[warp_id]).template Reduce<(FULL_TILE && EVEN_WARP_MULTIPLE)>( + input, + warp_num_valid, + reduction_op); + + // Update outputs and block_aggregate with warp-wide aggregates from lane-0s + return ApplyWarpAggregates(reduction_op, warp_aggregate, num_valid); + } + +}; + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_scan_raking.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_scan_raking.cuh new file mode 100644 index 0000000000000000000000000000000000000000..4891dad141d1bc44323844b8946183c56969300e --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_scan_raking.cuh @@ -0,0 +1,662 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + + +/** + * \file + * cub::BlockScanRaking provides variants of raking-based parallel prefix scan across a CUDA thread block. + */ + +#pragma once + +#include + +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * \brief BlockScanRaking provides variants of raking-based parallel prefix scan across a CUDA thread block. + */ +template < + typename T, ///< Data type being scanned + int BLOCK_DIM_X, ///< The thread block length in threads along the X dimension + int BLOCK_DIM_Y, ///< The thread block length in threads along the Y dimension + int BLOCK_DIM_Z, ///< The thread block length in threads along the Z dimension + bool MEMOIZE, ///< Whether or not to buffer outer raking scan partials to incur fewer shared memory reads at the expense of higher register pressure + int LEGACY_PTX_ARCH = 0> ///< The PTX compute capability for which to to specialize this collective +struct BlockScanRaking +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + /// Constants + enum + { + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + }; + + /// Layout type for padded thread block raking grid + typedef BlockRakingLayout BlockRakingLayout; + + /// Constants + enum + { + /// Number of raking threads + RAKING_THREADS = BlockRakingLayout::RAKING_THREADS, + + /// Number of raking elements per warp synchronous raking thread + SEGMENT_LENGTH = BlockRakingLayout::SEGMENT_LENGTH, + + /// Cooperative work can be entirely warp synchronous + WARP_SYNCHRONOUS = (int(BLOCK_THREADS) == int(RAKING_THREADS)), + }; + + /// WarpScan utility type + typedef WarpScan WarpScan; + + /// Shared memory storage layout type + struct _TempStorage + { + typename WarpScan::TempStorage warp_scan; ///< Buffer for warp-synchronous scan + typename BlockRakingLayout::TempStorage raking_grid; ///< Padded thread block raking grid + T block_aggregate; ///< Block aggregate + }; + + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + // Thread fields + _TempStorage &temp_storage; + unsigned int linear_tid; + T cached_segment[SEGMENT_LENGTH]; + + + //--------------------------------------------------------------------- + // Utility methods + //--------------------------------------------------------------------- + + /// Templated reduction + template + __device__ __forceinline__ T GuardedReduce( + T* raking_ptr, ///< [in] Input array + ScanOp scan_op, ///< [in] Binary reduction operator + T raking_partial, ///< [in] Prefix to seed reduction with + Int2Type /*iteration*/) + { + if ((BlockRakingLayout::UNGUARDED) || (((linear_tid * SEGMENT_LENGTH) + ITERATION) < BLOCK_THREADS)) + { + T addend = raking_ptr[ITERATION]; + raking_partial = scan_op(raking_partial, addend); + } + + return GuardedReduce(raking_ptr, scan_op, raking_partial, Int2Type()); + } + + + /// Templated reduction (base case) + template + __device__ __forceinline__ T GuardedReduce( + T* /*raking_ptr*/, ///< [in] Input array + ScanOp /*scan_op*/, ///< [in] Binary reduction operator + T raking_partial, ///< [in] Prefix to seed reduction with + Int2Type /*iteration*/) + { + return raking_partial; + } + + + /// Templated copy + template + __device__ __forceinline__ void CopySegment( + T* out, ///< [out] Out array + T* in, ///< [in] Input array + Int2Type /*iteration*/) + { + out[ITERATION] = in[ITERATION]; + CopySegment(out, in, Int2Type()); + } + + + /// Templated copy (base case) + __device__ __forceinline__ void CopySegment( + T* /*out*/, ///< [out] Out array + T* /*in*/, ///< [in] Input array + Int2Type /*iteration*/) + {} + + + /// Performs upsweep raking reduction, returning the aggregate + template + __device__ __forceinline__ T Upsweep( + ScanOp scan_op) + { + T *smem_raking_ptr = BlockRakingLayout::RakingPtr(temp_storage.raking_grid, linear_tid); + + // Read data into registers + CopySegment(cached_segment, smem_raking_ptr, Int2Type<0>()); + + T raking_partial = cached_segment[0]; + + return GuardedReduce(cached_segment, scan_op, raking_partial, Int2Type<1>()); + } + + + /// Performs exclusive downsweep raking scan + template + __device__ __forceinline__ void ExclusiveDownsweep( + ScanOp scan_op, + T raking_partial, + bool apply_prefix = true) + { + T *smem_raking_ptr = BlockRakingLayout::RakingPtr(temp_storage.raking_grid, linear_tid); + + // Read data back into registers + if (!MEMOIZE) + { + CopySegment(cached_segment, smem_raking_ptr, Int2Type<0>()); + } + + internal::ThreadScanExclusive(cached_segment, cached_segment, scan_op, raking_partial, apply_prefix); + + // Write data back to smem + CopySegment(smem_raking_ptr, cached_segment, Int2Type<0>()); + } + + + /// Performs inclusive downsweep raking scan + template + __device__ __forceinline__ void InclusiveDownsweep( + ScanOp scan_op, + T raking_partial, + bool apply_prefix = true) + { + T *smem_raking_ptr = BlockRakingLayout::RakingPtr(temp_storage.raking_grid, linear_tid); + + // Read data back into registers + if (!MEMOIZE) + { + CopySegment(cached_segment, smem_raking_ptr, Int2Type<0>()); + } + + internal::ThreadScanInclusive(cached_segment, cached_segment, scan_op, raking_partial, apply_prefix); + + // Write data back to smem + CopySegment(smem_raking_ptr, cached_segment, Int2Type<0>()); + } + + + //--------------------------------------------------------------------- + // Constructors + //--------------------------------------------------------------------- + + /// Constructor + __device__ __forceinline__ BlockScanRaking( + TempStorage &temp_storage) + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)) + {} + + + //--------------------------------------------------------------------- + // Exclusive scans + //--------------------------------------------------------------------- + + /// Computes an exclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. With no initial value, the output computed for thread0 is undefined. + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input item + T &exclusive_output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op) ///< [in] Binary scan operator + { + if (WARP_SYNCHRONOUS) + { + // Short-circuit directly to warp-synchronous scan + WarpScan(temp_storage.warp_scan).ExclusiveScan(input, exclusive_output, scan_op); + } + else + { + // Place thread partial into shared memory raking grid + T *placement_ptr = BlockRakingLayout::PlacementPtr(temp_storage.raking_grid, linear_tid); + detail::uninitialized_copy(placement_ptr, input); + + CTA_SYNC(); + + // Reduce parallelism down to just raking threads + if (linear_tid < RAKING_THREADS) + { + // Raking upsweep reduction across shared partials + T upsweep_partial = Upsweep(scan_op); + + // Warp-synchronous scan + T exclusive_partial; + WarpScan(temp_storage.warp_scan).ExclusiveScan(upsweep_partial, exclusive_partial, scan_op); + + // Exclusive raking downsweep scan + ExclusiveDownsweep(scan_op, exclusive_partial, (linear_tid != 0)); + } + + CTA_SYNC(); + + // Grab thread prefix from shared memory + exclusive_output = *placement_ptr; + } + } + + /// Computes an exclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input items + T &output, ///< [out] Calling thread's output items (may be aliased to \p input) + const T &initial_value, ///< [in] Initial value to seed the exclusive scan + ScanOp scan_op) ///< [in] Binary scan operator + { + if (WARP_SYNCHRONOUS) + { + // Short-circuit directly to warp-synchronous scan + WarpScan(temp_storage.warp_scan).ExclusiveScan(input, output, initial_value, scan_op); + } + else + { + // Place thread partial into shared memory raking grid + T *placement_ptr = BlockRakingLayout::PlacementPtr(temp_storage.raking_grid, linear_tid); + detail::uninitialized_copy(placement_ptr, input); + + CTA_SYNC(); + + // Reduce parallelism down to just raking threads + if (linear_tid < RAKING_THREADS) + { + // Raking upsweep reduction across shared partials + T upsweep_partial = Upsweep(scan_op); + + // Exclusive Warp-synchronous scan + T exclusive_partial; + WarpScan(temp_storage.warp_scan).ExclusiveScan(upsweep_partial, exclusive_partial, initial_value, scan_op); + + // Exclusive raking downsweep scan + ExclusiveDownsweep(scan_op, exclusive_partial); + } + + CTA_SYNC(); + + // Grab exclusive partial from shared memory + output = *placement_ptr; + } + } + + + /// Computes an exclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. Also provides every thread with the block-wide \p block_aggregate of all inputs. With no initial value, the output computed for thread0 is undefined. + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + T &block_aggregate) ///< [out] Threadblock-wide aggregate reduction of input items + { + if (WARP_SYNCHRONOUS) + { + // Short-circuit directly to warp-synchronous scan + WarpScan(temp_storage.warp_scan).ExclusiveScan(input, output, scan_op, block_aggregate); + } + else + { + // Place thread partial into shared memory raking grid + T *placement_ptr = BlockRakingLayout::PlacementPtr(temp_storage.raking_grid, linear_tid); + detail::uninitialized_copy(placement_ptr, input); + + CTA_SYNC(); + + // Reduce parallelism down to just raking threads + if (linear_tid < RAKING_THREADS) + { + // Raking upsweep reduction across shared partials + T upsweep_partial= Upsweep(scan_op); + + // Warp-synchronous scan + T inclusive_partial; + T exclusive_partial; + WarpScan(temp_storage.warp_scan).Scan(upsweep_partial, inclusive_partial, exclusive_partial, scan_op); + + // Exclusive raking downsweep scan + ExclusiveDownsweep(scan_op, exclusive_partial, (linear_tid != 0)); + + // Broadcast aggregate to all threads + if (linear_tid == RAKING_THREADS - 1) + temp_storage.block_aggregate = inclusive_partial; + } + + CTA_SYNC(); + + // Grab thread prefix from shared memory + output = *placement_ptr; + + // Retrieve block aggregate + block_aggregate = temp_storage.block_aggregate; + } + } + + + /// Computes an exclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. Also provides every thread with the block-wide \p block_aggregate of all inputs. + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input items + T &output, ///< [out] Calling thread's output items (may be aliased to \p input) + const T &initial_value, ///< [in] Initial value to seed the exclusive scan + ScanOp scan_op, ///< [in] Binary scan operator + T &block_aggregate) ///< [out] Threadblock-wide aggregate reduction of input items + { + if (WARP_SYNCHRONOUS) + { + // Short-circuit directly to warp-synchronous scan + WarpScan(temp_storage.warp_scan).ExclusiveScan(input, output, initial_value, scan_op, block_aggregate); + } + else + { + // Place thread partial into shared memory raking grid + T *placement_ptr = BlockRakingLayout::PlacementPtr(temp_storage.raking_grid, linear_tid); + detail::uninitialized_copy(placement_ptr, input); + + CTA_SYNC(); + + // Reduce parallelism down to just raking threads + if (linear_tid < RAKING_THREADS) + { + // Raking upsweep reduction across shared partials + T upsweep_partial = Upsweep(scan_op); + + // Warp-synchronous scan + T exclusive_partial; + WarpScan(temp_storage.warp_scan).ExclusiveScan(upsweep_partial, exclusive_partial, initial_value, scan_op, block_aggregate); + + // Exclusive raking downsweep scan + ExclusiveDownsweep(scan_op, exclusive_partial); + + // Broadcast aggregate to other threads + if (linear_tid == 0) + temp_storage.block_aggregate = block_aggregate; + } + + CTA_SYNC(); + + // Grab exclusive partial from shared memory + output = *placement_ptr; + + // Retrieve block aggregate + block_aggregate = temp_storage.block_aggregate; + } + } + + + /// Computes an exclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + template < + typename ScanOp, + typename BlockPrefixCallbackOp> + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a thread block-wide prefix to be applied to all inputs. + { + if (WARP_SYNCHRONOUS) + { + // Short-circuit directly to warp-synchronous scan + T block_aggregate; + WarpScan warp_scan(temp_storage.warp_scan); + warp_scan.ExclusiveScan(input, output, scan_op, block_aggregate); + + // Obtain warp-wide prefix in lane0, then broadcast to other lanes + T block_prefix = block_prefix_callback_op(block_aggregate); + block_prefix = warp_scan.Broadcast(block_prefix, 0); + + output = scan_op(block_prefix, output); + if (linear_tid == 0) + output = block_prefix; + } + else + { + // Place thread partial into shared memory raking grid + T *placement_ptr = BlockRakingLayout::PlacementPtr(temp_storage.raking_grid, linear_tid); + detail::uninitialized_copy(placement_ptr, input); + + CTA_SYNC(); + + // Reduce parallelism down to just raking threads + if (linear_tid < RAKING_THREADS) + { + WarpScan warp_scan(temp_storage.warp_scan); + + // Raking upsweep reduction across shared partials + T upsweep_partial = Upsweep(scan_op); + + // Warp-synchronous scan + T exclusive_partial, block_aggregate; + warp_scan.ExclusiveScan(upsweep_partial, exclusive_partial, scan_op, block_aggregate); + + // Obtain block-wide prefix in lane0, then broadcast to other lanes + T block_prefix = block_prefix_callback_op(block_aggregate); + block_prefix = warp_scan.Broadcast(block_prefix, 0); + + // Update prefix with warpscan exclusive partial + T downsweep_prefix = scan_op(block_prefix, exclusive_partial); + if (linear_tid == 0) + downsweep_prefix = block_prefix; + + // Exclusive raking downsweep scan + ExclusiveDownsweep(scan_op, downsweep_prefix); + } + + CTA_SYNC(); + + // Grab thread prefix from shared memory + output = *placement_ptr; + } + } + + + //--------------------------------------------------------------------- + // Inclusive scans + //--------------------------------------------------------------------- + + /// Computes an inclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. + template + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op) ///< [in] Binary scan operator + { + if (WARP_SYNCHRONOUS) + { + // Short-circuit directly to warp-synchronous scan + WarpScan(temp_storage.warp_scan).InclusiveScan(input, output, scan_op); + } + else + { + // Place thread partial into shared memory raking grid + T *placement_ptr = BlockRakingLayout::PlacementPtr(temp_storage.raking_grid, linear_tid); + detail::uninitialized_copy(placement_ptr, input); + + CTA_SYNC(); + + // Reduce parallelism down to just raking threads + if (linear_tid < RAKING_THREADS) + { + // Raking upsweep reduction across shared partials + T upsweep_partial = Upsweep(scan_op); + + // Exclusive Warp-synchronous scan + T exclusive_partial; + WarpScan(temp_storage.warp_scan).ExclusiveScan(upsweep_partial, exclusive_partial, scan_op); + + // Inclusive raking downsweep scan + InclusiveDownsweep(scan_op, exclusive_partial, (linear_tid != 0)); + } + + CTA_SYNC(); + + // Grab thread prefix from shared memory + output = *placement_ptr; + } + } + + + /// Computes an inclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. Also provides every thread with the block-wide \p block_aggregate of all inputs. + template + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + T &block_aggregate) ///< [out] Threadblock-wide aggregate reduction of input items + { + if (WARP_SYNCHRONOUS) + { + // Short-circuit directly to warp-synchronous scan + WarpScan(temp_storage.warp_scan).InclusiveScan(input, output, scan_op, block_aggregate); + } + else + { + // Place thread partial into shared memory raking grid + T *placement_ptr = BlockRakingLayout::PlacementPtr(temp_storage.raking_grid, linear_tid); + detail::uninitialized_copy(placement_ptr, input); + + CTA_SYNC(); + + // Reduce parallelism down to just raking threads + if (linear_tid < RAKING_THREADS) + { + // Raking upsweep reduction across shared partials + T upsweep_partial = Upsweep(scan_op); + + // Warp-synchronous scan + T inclusive_partial; + T exclusive_partial; + WarpScan(temp_storage.warp_scan).Scan(upsweep_partial, inclusive_partial, exclusive_partial, scan_op); + + // Inclusive raking downsweep scan + InclusiveDownsweep(scan_op, exclusive_partial, (linear_tid != 0)); + + // Broadcast aggregate to all threads + if (linear_tid == RAKING_THREADS - 1) + temp_storage.block_aggregate = inclusive_partial; + } + + CTA_SYNC(); + + // Grab thread prefix from shared memory + output = *placement_ptr; + + // Retrieve block aggregate + block_aggregate = temp_storage.block_aggregate; + } + } + + + /// Computes an inclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + template < + typename ScanOp, + typename BlockPrefixCallbackOp> + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item + T &output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a thread block-wide prefix to be applied to all inputs. + { + if (WARP_SYNCHRONOUS) + { + // Short-circuit directly to warp-synchronous scan + T block_aggregate; + WarpScan warp_scan(temp_storage.warp_scan); + warp_scan.InclusiveScan(input, output, scan_op, block_aggregate); + + // Obtain warp-wide prefix in lane0, then broadcast to other lanes + T block_prefix = block_prefix_callback_op(block_aggregate); + block_prefix = warp_scan.Broadcast(block_prefix, 0); + + // Update prefix with exclusive warpscan partial + output = scan_op(block_prefix, output); + } + else + { + // Place thread partial into shared memory raking grid + T *placement_ptr = BlockRakingLayout::PlacementPtr(temp_storage.raking_grid, linear_tid); + detail::uninitialized_copy(placement_ptr, input); + + CTA_SYNC(); + + // Reduce parallelism down to just raking threads + if (linear_tid < RAKING_THREADS) + { + WarpScan warp_scan(temp_storage.warp_scan); + + // Raking upsweep reduction across shared partials + T upsweep_partial = Upsweep(scan_op); + + // Warp-synchronous scan + T exclusive_partial, block_aggregate; + warp_scan.ExclusiveScan(upsweep_partial, exclusive_partial, scan_op, block_aggregate); + + // Obtain block-wide prefix in lane0, then broadcast to other lanes + T block_prefix = block_prefix_callback_op(block_aggregate); + block_prefix = warp_scan.Broadcast(block_prefix, 0); + + // Update prefix with warpscan exclusive partial + T downsweep_prefix = scan_op(block_prefix, exclusive_partial); + if (linear_tid == 0) + downsweep_prefix = block_prefix; + + // Inclusive raking downsweep scan + InclusiveDownsweep(scan_op, downsweep_prefix); + } + + CTA_SYNC(); + + // Grab thread prefix from shared memory + output = *placement_ptr; + } + } + +}; + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_scan_warp_scans.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_scan_warp_scans.cuh new file mode 100644 index 0000000000000000000000000000000000000000..f76131a78569066c5f60970fa742d26f007a64a8 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/block/specializations/block_scan_warp_scans.cuh @@ -0,0 +1,393 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::BlockScanWarpscans provides warpscan-based variants of parallel prefix scan across a CUDA thread block. + */ + +#pragma once + +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +/** + * \brief BlockScanWarpScans provides warpscan-based variants of parallel prefix scan across a CUDA thread block. + */ +template < + typename T, + int BLOCK_DIM_X, ///< The thread block length in threads along the X dimension + int BLOCK_DIM_Y, ///< The thread block length in threads along the Y dimension + int BLOCK_DIM_Z, ///< The thread block length in threads along the Z dimension + int LEGACY_PTX_ARCH = 0> ///< The PTX compute capability for which to to specialize this collective +struct BlockScanWarpScans +{ + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + /// Constants + enum + { + /// Number of warp threads + WARP_THREADS = CUB_WARP_THREADS(0), + + /// The thread block size in threads + BLOCK_THREADS = BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z, + + /// Number of active warps + WARPS = (BLOCK_THREADS + WARP_THREADS - 1) / WARP_THREADS, + }; + + /// WarpScan utility type + typedef WarpScan WarpScanT; + + /// WarpScan utility type + typedef WarpScan WarpAggregateScan; + + /// Shared memory storage layout type + + struct __align__(32) _TempStorage + { + T warp_aggregates[WARPS]; + typename WarpScanT::TempStorage warp_scan[WARPS]; ///< Buffer for warp-synchronous scans + T block_prefix; ///< Shared prefix for the entire thread block + }; + + + /// Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + //--------------------------------------------------------------------- + // Per-thread fields + //--------------------------------------------------------------------- + + // Thread fields + _TempStorage &temp_storage; + unsigned int linear_tid; + unsigned int warp_id; + unsigned int lane_id; + + + //--------------------------------------------------------------------- + // Constructors + //--------------------------------------------------------------------- + + /// Constructor + __device__ __forceinline__ BlockScanWarpScans( + TempStorage &temp_storage) + : + temp_storage(temp_storage.Alias()), + linear_tid(RowMajorTid(BLOCK_DIM_X, BLOCK_DIM_Y, BLOCK_DIM_Z)), + warp_id((WARPS == 1) ? 0 : linear_tid / WARP_THREADS), + lane_id(LaneId()) + {} + + + //--------------------------------------------------------------------- + // Utility methods + //--------------------------------------------------------------------- + + template + __device__ __forceinline__ void ApplyWarpAggregates( + T &warp_prefix, ///< [out] The calling thread's partial reduction + ScanOp scan_op, ///< [in] Binary scan operator + T &block_aggregate, ///< [out] Threadblock-wide aggregate reduction of input items + Int2Type /*addend_warp*/) + { + if (warp_id == WARP) + warp_prefix = block_aggregate; + + T addend = temp_storage.warp_aggregates[WARP]; + block_aggregate = scan_op(block_aggregate, addend); + + ApplyWarpAggregates(warp_prefix, scan_op, block_aggregate, Int2Type()); + } + + template + __device__ __forceinline__ void ApplyWarpAggregates( + T &/*warp_prefix*/, ///< [out] The calling thread's partial reduction + ScanOp /*scan_op*/, ///< [in] Binary scan operator + T &/*block_aggregate*/, ///< [out] Threadblock-wide aggregate reduction of input items + Int2Type /*addend_warp*/) + {} + + + /// Use the warp-wide aggregates to compute the calling warp's prefix. Also returns block-wide aggregate in all threads. + template + __device__ __forceinline__ T ComputeWarpPrefix( + ScanOp scan_op, ///< [in] Binary scan operator + T warp_aggregate, ///< [in] [laneWARP_THREADS - 1 only] Warp-wide aggregate reduction of input items + T &block_aggregate) ///< [out] Threadblock-wide aggregate reduction of input items + { + // Last lane in each warp shares its warp-aggregate + if (lane_id == WARP_THREADS - 1) + { + detail::uninitialized_copy(temp_storage.warp_aggregates + warp_id, + warp_aggregate); + } + + CTA_SYNC(); + + // Accumulate block aggregates and save the one that is our warp's prefix + T warp_prefix; + block_aggregate = temp_storage.warp_aggregates[0]; + + // Use template unrolling (since the PTX backend can't handle unrolling it for SM1x) + ApplyWarpAggregates(warp_prefix, scan_op, block_aggregate, Int2Type<1>()); +/* + #pragma unroll + for (int WARP = 1; WARP < WARPS; ++WARP) + { + if (warp_id == WARP) + warp_prefix = block_aggregate; + + T addend = temp_storage.warp_aggregates[WARP]; + block_aggregate = scan_op(block_aggregate, addend); + } +*/ + + return warp_prefix; + } + + + /// Use the warp-wide aggregates and initial-value to compute the calling warp's prefix. Also returns block-wide aggregate in all threads. + template + __device__ __forceinline__ T ComputeWarpPrefix( + ScanOp scan_op, ///< [in] Binary scan operator + T warp_aggregate, ///< [in] [laneWARP_THREADS - 1 only] Warp-wide aggregate reduction of input items + T &block_aggregate, ///< [out] Threadblock-wide aggregate reduction of input items + const T &initial_value) ///< [in] Initial value to seed the exclusive scan + { + T warp_prefix = ComputeWarpPrefix(scan_op, warp_aggregate, block_aggregate); + + warp_prefix = scan_op(initial_value, warp_prefix); + + if (warp_id == 0) + warp_prefix = initial_value; + + return warp_prefix; + } + + //--------------------------------------------------------------------- + // Exclusive scans + //--------------------------------------------------------------------- + + /// Computes an exclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. With no initial value, the output computed for thread0 is undefined. + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input item + T &exclusive_output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op) ///< [in] Binary scan operator + { + // Compute block-wide exclusive scan. The exclusive output from tid0 is invalid. + T block_aggregate; + ExclusiveScan(input, exclusive_output, scan_op, block_aggregate); + } + + + /// Computes an exclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input items + T &exclusive_output, ///< [out] Calling thread's output items (may be aliased to \p input) + const T &initial_value, ///< [in] Initial value to seed the exclusive scan + ScanOp scan_op) ///< [in] Binary scan operator + { + T block_aggregate; + ExclusiveScan(input, exclusive_output, initial_value, scan_op, block_aggregate); + } + + + /// Computes an exclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. Also provides every thread with the block-wide \p block_aggregate of all inputs. With no initial value, the output computed for thread0 is undefined. + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input item + T &exclusive_output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + T &block_aggregate) ///< [out] Threadblock-wide aggregate reduction of input items + { + // Compute warp scan in each warp. The exclusive output from each lane0 is invalid. + T inclusive_output; + WarpScanT(temp_storage.warp_scan[warp_id]).Scan(input, inclusive_output, exclusive_output, scan_op); + + // Compute the warp-wide prefix and block-wide aggregate for each warp. Warp prefix for warp0 is invalid. + T warp_prefix = ComputeWarpPrefix(scan_op, inclusive_output, block_aggregate); + + // Apply warp prefix to our lane's partial + if (warp_id != 0) + { + exclusive_output = scan_op(warp_prefix, exclusive_output); + if (lane_id == 0) + exclusive_output = warp_prefix; + } + } + + + /// Computes an exclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. Also provides every thread with the block-wide \p block_aggregate of all inputs. + template + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input items + T &exclusive_output, ///< [out] Calling thread's output items (may be aliased to \p input) + const T &initial_value, ///< [in] Initial value to seed the exclusive scan + ScanOp scan_op, ///< [in] Binary scan operator + T &block_aggregate) ///< [out] Threadblock-wide aggregate reduction of input items + { + // Compute warp scan in each warp. The exclusive output from each lane0 is invalid. + T inclusive_output; + WarpScanT(temp_storage.warp_scan[warp_id]).Scan(input, inclusive_output, exclusive_output, scan_op); + + // Compute the warp-wide prefix and block-wide aggregate for each warp + T warp_prefix = ComputeWarpPrefix(scan_op, inclusive_output, block_aggregate, initial_value); + + // Apply warp prefix to our lane's partial + exclusive_output = scan_op(warp_prefix, exclusive_output); + if (lane_id == 0) + exclusive_output = warp_prefix; + } + + + /// Computes an exclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + template < + typename ScanOp, + typename BlockPrefixCallbackOp> + __device__ __forceinline__ void ExclusiveScan( + T input, ///< [in] Calling thread's input item + T &exclusive_output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a thread block-wide prefix to be applied to all inputs. + { + // Compute block-wide exclusive scan. The exclusive output from tid0 is invalid. + T block_aggregate; + ExclusiveScan(input, exclusive_output, scan_op, block_aggregate); + + // Use the first warp to determine the thread block prefix, returning the result in lane0 + if (warp_id == 0) + { + T block_prefix = block_prefix_callback_op(block_aggregate); + if (lane_id == 0) + { + // Share the prefix with all threads + detail::uninitialized_copy(&temp_storage.block_prefix, + block_prefix); + + exclusive_output = block_prefix; // The block prefix is the exclusive output for tid0 + } + } + + CTA_SYNC(); + + // Incorporate thread block prefix into outputs + T block_prefix = temp_storage.block_prefix; + if (linear_tid > 0) + { + exclusive_output = scan_op(block_prefix, exclusive_output); + } + } + + + //--------------------------------------------------------------------- + // Inclusive scans + //--------------------------------------------------------------------- + + /// Computes an inclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. + template + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item + T &inclusive_output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op) ///< [in] Binary scan operator + { + T block_aggregate; + InclusiveScan(input, inclusive_output, scan_op, block_aggregate); + } + + + /// Computes an inclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. Also provides every thread with the block-wide \p block_aggregate of all inputs. + template + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item + T &inclusive_output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + T &block_aggregate) ///< [out] Threadblock-wide aggregate reduction of input items + { + WarpScanT(temp_storage.warp_scan[warp_id]).InclusiveScan(input, inclusive_output, scan_op); + + // Compute the warp-wide prefix and block-wide aggregate for each warp. Warp prefix for warp0 is invalid. + T warp_prefix = ComputeWarpPrefix(scan_op, inclusive_output, block_aggregate); + + // Apply warp prefix to our lane's partial + if (warp_id != 0) + { + inclusive_output = scan_op(warp_prefix, inclusive_output); + } + } + + + /// Computes an inclusive thread block-wide prefix scan using the specified binary \p scan_op functor. Each thread contributes one input element. the call-back functor \p block_prefix_callback_op is invoked by the first warp in the block, and the value returned by lane0 in that warp is used as the "seed" value that logically prefixes the thread block's scan inputs. Also provides every thread with the block-wide \p block_aggregate of all inputs. + template < + typename ScanOp, + typename BlockPrefixCallbackOp> + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item + T &exclusive_output, ///< [out] Calling thread's output item (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + BlockPrefixCallbackOp &block_prefix_callback_op) ///< [in-out] [warp0 only] Call-back functor for specifying a thread block-wide prefix to be applied to all inputs. + { + T block_aggregate; + InclusiveScan(input, exclusive_output, scan_op, block_aggregate); + + // Use the first warp to determine the thread block prefix, returning the result in lane0 + if (warp_id == 0) + { + T block_prefix = block_prefix_callback_op(block_aggregate); + if (lane_id == 0) + { + // Share the prefix with all threads + detail::uninitialized_copy(&temp_storage.block_prefix, + block_prefix); + } + } + + CTA_SYNC(); + + // Incorporate thread block prefix into outputs + T block_prefix = temp_storage.block_prefix; + exclusive_output = scan_op(block_prefix, exclusive_output); + } + + +}; + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/config.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/config.cuh new file mode 100644 index 0000000000000000000000000000000000000000..b909bbf723708e59a121b5525c628f6715e24c86 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/config.cuh @@ -0,0 +1,40 @@ +/****************************************************************************** + * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Static configuration header for the CUB project. + */ + +#pragma once + +#include "util_arch.cuh" +#include "util_compiler.cuh" +#include "util_cpp_dialect.cuh" +#include "util_deprecated.cuh" +#include "util_macro.cuh" +#include "util_namespace.cuh" diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/cub.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/cub.cuh new file mode 100644 index 0000000000000000000000000000000000000000..18dc2c0034d5ff7bd21a827fc582ce216d06d2c2 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/cub.cuh @@ -0,0 +1,109 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * CUB umbrella include file + */ + +#pragma once + +// Static configuration +#include "config.cuh" + +// Block +#include "block/block_adjacent_difference.cuh" +#include "block/block_discontinuity.cuh" +#include "block/block_exchange.cuh" +#include "block/block_histogram.cuh" +#include "block/block_load.cuh" +#include "block/block_merge_sort.cuh" +#include "block/block_radix_rank.cuh" +#include "block/block_radix_sort.cuh" +#include "block/block_reduce.cuh" +#include "block/block_scan.cuh" +#include "block/block_store.cuh" +//#include "block/block_shift.cuh" + +// Device +#include "device/device_adjacent_difference.cuh" +#include "device/device_copy.cuh" +#include "device/device_histogram.cuh" +#include "device/device_memcpy.cuh" +#include "device/device_merge_sort.cuh" +#include "device/device_partition.cuh" +#include "device/device_radix_sort.cuh" +#include "device/device_reduce.cuh" +#include "device/device_run_length_encode.cuh" +#include "device/device_scan.cuh" +#include "device/device_segmented_radix_sort.cuh" +#include "device/device_segmented_reduce.cuh" +#include "device/device_segmented_sort.cuh" +#include "device/device_select.cuh" +#include "device/device_spmv.cuh" + +// Grid +//#include "grid/grid_barrier.cuh" +#include "grid/grid_even_share.cuh" +#include "grid/grid_mapping.cuh" +#include "grid/grid_queue.cuh" + +// Thread +#include "thread/thread_load.cuh" +#include "thread/thread_operators.cuh" +#include "thread/thread_reduce.cuh" +#include "thread/thread_scan.cuh" +#include "thread/thread_store.cuh" + +// Warp +#include "warp/warp_exchange.cuh" +#include "warp/warp_load.cuh" +#include "warp/warp_merge_sort.cuh" +#include "warp/warp_reduce.cuh" +#include "warp/warp_scan.cuh" +#include "warp/warp_store.cuh" + +// Iterator +#include "iterator/arg_index_input_iterator.cuh" +#include "iterator/cache_modified_input_iterator.cuh" +#include "iterator/cache_modified_output_iterator.cuh" +#include "iterator/constant_input_iterator.cuh" +#include "iterator/counting_input_iterator.cuh" +#include "iterator/discard_output_iterator.cuh" +#include "iterator/tex_obj_input_iterator.cuh" +#include "iterator/tex_ref_input_iterator.cuh" +#include "iterator/transform_input_iterator.cuh" + +// Util +#include "util_allocator.cuh" +#include "util_arch.cuh" +#include "util_debug.cuh" +#include "util_device.cuh" +#include "util_macro.cuh" +#include "util_ptx.cuh" +#include "util_type.cuh" diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/choose_offset.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/choose_offset.cuh new file mode 100644 index 0000000000000000000000000000000000000000..ed703e26c9db9eeb611883b6be851e0c2da13dc2 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/choose_offset.cuh @@ -0,0 +1,62 @@ +/****************************************************************************** + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include + +#include +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +/** + * ChooseOffsetT checks NumItemsT, the type of the num_items parameter, and + * selects the offset type based on it. + */ +template +struct ChooseOffsetT +{ + // NumItemsT must be an integral type (but not bool). + static_assert( + std::is_integral::value && + !std::is_same::type, bool>::value, + "NumItemsT must be an integral type, but not bool"); + + // Unsigned integer type for global offsets. + using Type = typename std::conditional::type; +}; + +} // namespace detail + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/cpp_compatibility.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/cpp_compatibility.cuh new file mode 100644 index 0000000000000000000000000000000000000000..c4fbe649692e003118c41d34077665c305a01d68 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/cpp_compatibility.cuh @@ -0,0 +1,28 @@ +/* +* Copyright 2022 NVIDIA Corporation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#pragma once + +#include + +#if CUB_CPP_DIALECT >= 2017 && __cpp_if_constexpr +# define CUB_IF_CONSTEXPR if constexpr +# define CUB_ELSE_IF_CONSTEXPR else if constexpr +#else +# define CUB_IF_CONSTEXPR if +# define CUB_ELSE_IF_CONSTEXPR else if +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/detect_cuda_runtime.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/detect_cuda_runtime.cuh new file mode 100644 index 0000000000000000000000000000000000000000..a2af93b7189bcff8de763a2fee12c68ecd096640 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/detect_cuda_runtime.cuh @@ -0,0 +1,116 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Utilities for CUDA dynamic parallelism. + */ + +#pragma once + +#include + +#include + +CUB_NAMESPACE_BEGIN +namespace detail +{ + +#ifdef DOXYGEN_SHOULD_SKIP_THIS // Only parse this during doxygen passes: + +/** + * \def CUB_DISABLE_CDP + * + * If defined, support for device-side usage of CUB is disabled. + */ +#define CUB_DISABLE_CDP + +/** + * \def CUB_RDC_ENABLED + * + * Defined if RDC is enabled and CUB_DISABLE_CDP is not defined. + */ +#define CUB_RDC_ENABLED + +/** + * \def CUB_RUNTIME_FUNCTION + * + * Execution space for functions that can use the CUDA runtime API (`__host__` + * when RDC is off, `__host__ __device__` when RDC is on). + */ +#define CUB_RUNTIME_FUNCTION + +/** + * \def CUB_RUNTIME_ENABLED + * + * Whether or not the active compiler pass is allowed to invoke device kernels + * or methods from the CUDA runtime API. + * + * This macro should not be used in CUB, as it depends on `__CUDA_ARCH__` + * and is not compatible with `NV_IF_TARGET`. It is provided for legacy + * purposes only. + * + * Replace any usages with `CUB_RDC_ENABLED` and `NV_IF_TARGET`. + */ +#define CUB_RUNTIME_ENABLED + +#else // Non-doxygen pass: + +#ifndef CUB_RUNTIME_FUNCTION + +#if defined(__CUDACC_RDC__) && !defined(CUB_DISABLE_CDP) + +#define CUB_RDC_ENABLED +#define CUB_RUNTIME_FUNCTION __host__ __device__ + +#else // RDC disabled: + +#define CUB_RUNTIME_FUNCTION __host__ + +#endif // RDC enabled + +#if !defined(__CUDA_ARCH__) || defined(__CUDACC_RDC__) +// Legacy only -- do not use in new code. +#define CUB_RUNTIME_ENABLED +#endif + +#endif // CUB_RUNTIME_FUNCTION predefined + +#ifdef CUB_RDC_ENABLED +// Detect available version of CDP: +#if __CUDACC_VER_MAJOR__ < 12 || defined(CUDA_FORCE_CDP1_IF_SUPPORTED) +#define CUB_DETAIL_CDPv1 +#else +#define CUB_DETAIL_CDPv2 +#endif +#endif + +#endif // Do not document + +} // namespace detail +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/device_double_buffer.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/device_double_buffer.cuh new file mode 100644 index 0000000000000000000000000000000000000000..c427dcb438ba3d1f808b8bcb0a80671f13fe8720 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/device_double_buffer.cuh @@ -0,0 +1,90 @@ +/* + * Copyright 2021 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + + +/** + * @brief It's a double-buffer storage wrapper for multi-pass stream + * transformations that require more than one storage array for + * streaming intermediate results back and forth. + * + * Many multi-pass computations require a pair of "ping-pong" storage buffers + * (e.g., one for reading from and the other for writing to, and then + * vice-versa for the subsequent pass). This structure wraps a set of device + * buffers. + * + * Unlike `cub::DoubleBuffer` this class doesn't provide a "selector" member + * to track which buffer is "current". The main reason for this class existence + * is the performance difference. Since `cub::DoubleBuffer` relies on the + * runtime variable to index pointers arrays, they are placed in the local + * memory instead of registers. Local memory accesses significantly affect + * performance. On the contrary, this class swaps pointer, so all operations + * can be performed in registers. + */ +template +class device_double_buffer +{ + /// Pair of device buffer pointers + T *m_current_buffer {}; + T *m_alternate_buffer {}; + +public: + /** + * @param d_current + * The currently valid buffer + * + * @param d_alternate + * Alternate storage buffer of the same size as @p d_current + */ + __host__ __device__ __forceinline__ device_double_buffer(T *current, + T *alternate) + : m_current_buffer(current) + , m_alternate_buffer(alternate) + {} + + /// \brief Return pointer to the currently valid buffer + __host__ __device__ __forceinline__ T *current() const + { + return m_current_buffer; + } + + /// \brief Return pointer to the currently invalid buffer + __host__ __device__ __forceinline__ T *alternate() const + { + return m_alternate_buffer; + } + + __host__ __device__ void swap() + { + T *tmp = m_current_buffer; + m_current_buffer = m_alternate_buffer; + m_alternate_buffer = tmp; + } +}; + + +} // namespace detail + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/device_synchronize.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/device_synchronize.cuh new file mode 100644 index 0000000000000000000000000000000000000000..9da0a361aff13ef689c2d6cd693b748353f8128b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/device_synchronize.cuh @@ -0,0 +1,71 @@ +/* + * Copyright 2021 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +#include + +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +/** + * Call `cudaDeviceSynchronize()` using the proper API for the current CUB and + * CUDA configuration. + */ +CUB_EXEC_CHECK_DISABLE +CUB_RUNTIME_FUNCTION inline cudaError_t device_synchronize() +{ + cudaError_t result = cudaErrorNotSupported; + + // Device-side sync is only available under CDPv1: +#if defined(CUB_DETAIL_CDPv1) + +#if ((__CUDACC_VER_MAJOR__ > 11) || \ + ((__CUDACC_VER_MAJOR__ == 11) && (__CUDACC_VER_MINOR__ >= 6))) + // CUDA >= 11.6 +#define CUB_TMP_DEVICE_SYNC_IMPL \ + result = __cudaDeviceSynchronizeDeprecationAvoidance(); +#else // CUDA < 11.6: +#define CUB_TMP_DEVICE_SYNC_IMPL result = cudaDeviceSynchronize(); +#endif + +#else // CDPv2 or no CDP: + +#define CUB_TMP_DEVICE_SYNC_IMPL /* unavailable */ + +#endif // CDP version + + NV_IF_TARGET(NV_IS_HOST, + (result = cudaDeviceSynchronize();), + (CUB_TMP_DEVICE_SYNC_IMPL)); + +#undef CUB_TMP_DEVICE_SYNC_IMPL + + return result; +} + +} // namespace detail + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/exec_check_disable.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/exec_check_disable.cuh new file mode 100644 index 0000000000000000000000000000000000000000..c5f4b4572c7b2d79e4c2917ea2fc546c5ca8f3be --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/exec_check_disable.cuh @@ -0,0 +1,41 @@ +/* +* Copyright 2021 NVIDIA Corporation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#pragma once + +#include + +/** + * @def CUB_EXEC_CHECK_DISABLE + * Wrapper around `#pragma nv_exec_check_disable`. + */ + +// #pragma nv_exec_check_disable is only recognized by NVCC. +#if defined(__CUDACC__) && \ + !defined(_NVHPC_CUDA) && \ + !(defined(__CUDA__) && defined(__clang__)) + +#if CUB_HOST_COMPILER == CUB_HOST_COMPILER_MSVC +#define CUB_EXEC_CHECK_DISABLE __pragma("nv_exec_check_disable") +#else // // !MSVC +#define CUB_EXEC_CHECK_DISABLE _Pragma("nv_exec_check_disable") +#endif // MSVC + +#else // !NVCC + +#define CUB_EXEC_CHECK_DISABLE + +#endif // NVCC diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/strong_load.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/strong_load.cuh new file mode 100644 index 0000000000000000000000000000000000000000..12e6672b9eb0752a5f1a24fec91b2819e706fb2f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/strong_load.cuh @@ -0,0 +1,182 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file Utilities for strong memory operations. + */ + +#pragma once + +#include +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + +namespace detail +{ + +static __device__ __forceinline__ uint4 load_relaxed(uint4 const *ptr) +{ + uint4 retval; + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("ld.relaxed.gpu.v4.u32 {%0, %1, %2, %3}, [%4];" + : "=r"(retval.x), "=r"(retval.y), "=r"(retval.z), "=r"(retval.w) + : _CUB_ASM_PTR_(ptr) + : "memory");), + (asm volatile("ld.cg.v4.u32 {%0, %1, %2, %3}, [%4];" + : "=r"(retval.x), "=r"(retval.y), "=r"(retval.z), "=r"(retval.w) + : _CUB_ASM_PTR_(ptr) + : "memory");)); + return retval; +} + +static __device__ __forceinline__ ulonglong2 load_relaxed(ulonglong2 const *ptr) +{ + ulonglong2 retval; + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("ld.relaxed.gpu.v2.u64 {%0, %1}, [%2];" + : "=l"(retval.x), "=l"(retval.y) + : _CUB_ASM_PTR_(ptr) + : "memory");), + (asm volatile("ld.cg.v2.u64 {%0, %1}, [%2];" + : "=l"(retval.x), "=l"(retval.y) + : _CUB_ASM_PTR_(ptr) + : "memory");)); + return retval; +} + +static __device__ __forceinline__ ushort4 load_relaxed(ushort4 const *ptr) +{ + ushort4 retval; + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("ld.relaxed.gpu.v4.u16 {%0, %1, %2, %3}, [%4];" + : "=h"(retval.x), "=h"(retval.y), "=h"(retval.z), "=h"(retval.w) + : _CUB_ASM_PTR_(ptr) + : "memory");), + (asm volatile("ld.cg.v4.u16 {%0, %1, %2, %3}, [%4];" + : "=h"(retval.x), "=h"(retval.y), "=h"(retval.z), "=h"(retval.w) + : _CUB_ASM_PTR_(ptr) + : "memory");)); + return retval; +} + +static __device__ __forceinline__ uint2 load_relaxed(uint2 const *ptr) +{ + uint2 retval; + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("ld.relaxed.gpu.v2.u32 {%0, %1}, [%2];" + : "=r"(retval.x), "=r"(retval.y) + : _CUB_ASM_PTR_(ptr) + : "memory");), + (asm volatile("ld.cg.v2.u32 {%0, %1}, [%2];" + : "=r"(retval.x), "=r"(retval.y) + : _CUB_ASM_PTR_(ptr) + : "memory");)); + return retval; +} + +static __device__ __forceinline__ unsigned long long load_relaxed(unsigned long long const *ptr) +{ + unsigned long long retval; + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("ld.relaxed.gpu.u64 %0, [%1];" + : "=l"(retval) + : _CUB_ASM_PTR_(ptr) + : "memory");), + (asm volatile("ld.cg.u64 %0, [%1];" + : "=l"(retval) + : _CUB_ASM_PTR_(ptr) + : "memory");)); + return retval; +} + +static __device__ __forceinline__ unsigned int load_relaxed(unsigned int const *ptr) +{ + unsigned int retval; + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("ld.relaxed.gpu.u32 %0, [%1];" + : "=r"(retval) + : _CUB_ASM_PTR_(ptr) + : "memory");), + (asm volatile("ld.cg.u32 %0, [%1];" + : "=r"(retval) + : _CUB_ASM_PTR_(ptr) + : "memory");)); + + return retval; +} + +static __device__ __forceinline__ unsigned short load_relaxed(unsigned short const *ptr) +{ + unsigned short retval; + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("ld.relaxed.gpu.u16 %0, [%1];" + : "=h"(retval) + : _CUB_ASM_PTR_(ptr) + : "memory");), + (asm volatile("ld.cg.u16 %0, [%1];" + : "=h"(retval) + : _CUB_ASM_PTR_(ptr) + : "memory");)); + return retval; +} + +static __device__ __forceinline__ unsigned char load_relaxed(unsigned char const *ptr) +{ + unsigned short retval; + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("{" + " .reg .u8 datum;" + " ld.relaxed.gpu.u8 datum, [%1];" + " cvt.u16.u8 %0, datum;" + "}" + : "=h"(retval) + : _CUB_ASM_PTR_(ptr) + : "memory");), + (asm volatile("{" + " .reg .u8 datum;" + " ld.cg.u8 datum, [%1];" + " cvt.u16.u8 %0, datum;" + "}" + : "=h"(retval) + : _CUB_ASM_PTR_(ptr) + : "memory");)); + return (unsigned char)retval; +} + +} // namespace detail + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/strong_store.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/strong_store.cuh new file mode 100644 index 0000000000000000000000000000000000000000..fd293519a38de904bfb344f6354457e1fcbf2612 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/strong_store.cuh @@ -0,0 +1,279 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file Utilities for strong memory operations. + */ + +#pragma once + +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + +namespace detail +{ + +static __device__ __forceinline__ void store_relaxed(uint4 *ptr, uint4 val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.relaxed.gpu.v4.u32 [%0], {%1, %2, %3, %4};" + : + : _CUB_ASM_PTR_(ptr), "r"(val.x), "r"(val.y), "r"(val.z), "r"(val.w) + : "memory");), + (asm volatile("st.cg.v4.u32 [%0], {%1, %2, %3, %4};" + : + : _CUB_ASM_PTR_(ptr), "r"(val.x), "r"(val.y), "r"(val.z), "r"(val.w) + : "memory");)); +} + +static __device__ __forceinline__ void store_relaxed(ulonglong2 *ptr, ulonglong2 val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.relaxed.gpu.v2.u64 [%0], {%1, %2};" + : + : _CUB_ASM_PTR_(ptr), "l"(val.x), "l"(val.y) + : "memory");), + (asm volatile("st.cg.v2.u64 [%0], {%1, %2};" + : + : _CUB_ASM_PTR_(ptr), "l"(val.x), "l"(val.y) + : "memory");)); +} + +static __device__ __forceinline__ void store_relaxed(ushort4 *ptr, ushort4 val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.relaxed.gpu.v4.u16 [%0], {%1, %2, %3, %4};" + : + : _CUB_ASM_PTR_(ptr), "h"(val.x), "h"(val.y), "h"(val.z), "h"(val.w) + : "memory");), + (asm volatile("st.cg.v4.u16 [%0], {%1, %2, %3, %4};" + : + : _CUB_ASM_PTR_(ptr), "h"(val.x), "h"(val.y), "h"(val.z), "h"(val.w) + : "memory");)); +} + +static __device__ __forceinline__ void store_relaxed(uint2 *ptr, uint2 val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.relaxed.gpu.v2.u32 [%0], {%1, %2};" + : + : _CUB_ASM_PTR_(ptr), "r"(val.x), "r"(val.y) + : "memory");), + (asm volatile("st.cg.v2.u32 [%0], {%1, %2};" + : + : _CUB_ASM_PTR_(ptr), "r"(val.x), "r"(val.y) + : "memory");)); +} + +static __device__ __forceinline__ void store_relaxed(unsigned long long *ptr, + unsigned long long val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.relaxed.gpu.u64 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "l"(val) + : "memory");), + (asm volatile("st.cg.u64 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "l"(val) + : "memory");)); +} + +static __device__ __forceinline__ void store_relaxed(unsigned int *ptr, unsigned int val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.relaxed.gpu.u32 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "r"(val) + : "memory");), + (asm volatile("st.cg.u32 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "r"(val) + : "memory");)); +} + +static __device__ __forceinline__ void store_relaxed(unsigned short *ptr, unsigned short val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.relaxed.gpu.u16 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "h"(val) + : "memory");), + (asm volatile("st.cg.u16 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "h"(val) + : "memory");)); +} + +static __device__ __forceinline__ void store_relaxed(unsigned char *ptr, unsigned char val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("{" + " .reg .u8 datum;" + " cvt.u8.u16 datum, %1;" + " st.relaxed.gpu.u8 [%0], datum;" + "}" + : + : _CUB_ASM_PTR_(ptr), "h"((unsigned short)val) + : "memory");), + (asm volatile("{" + " .reg .u8 datum;" + " cvt.u8.u16 datum, %1;" + " st.cg.u8 [%0], datum;" + "}" + : + : _CUB_ASM_PTR_(ptr), "h"((unsigned short)val) + : "memory");)); +} + +__device__ __forceinline__ void store_release(uint4 *ptr, uint4 val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.release.gpu.v4.u32 [%0], {%1, %2, %3, %4};" + : + : _CUB_ASM_PTR_(ptr), "r"(val.x), "r"(val.y), "r"(val.z), "r"(val.w) + : "memory");), + (__threadfence(); + asm volatile("st.cg.v4.u32 [%0], {%1, %2, %3, %4};" + : + : _CUB_ASM_PTR_(ptr), "r"(val.x), "r"(val.y), "r"(val.z), "r"(val.w) + : "memory");)); +} + +__device__ __forceinline__ void store_release(ulonglong2 *ptr, ulonglong2 val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.release.gpu.v2.u64 [%0], {%1, %2};" + : + : _CUB_ASM_PTR_(ptr), "l"(val.x), "l"(val.y) + : "memory");), + (__threadfence(); asm volatile("st.cg.v2.u64 [%0], {%1, %2};" + : + : _CUB_ASM_PTR_(ptr), "l"(val.x), "l"(val.y) + : "memory");)); +} + +__device__ __forceinline__ void store_release(ushort4 *ptr, ushort4 val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.release.gpu.v4.u16 [%0], {%1, %2, %3, %4};" + : + : _CUB_ASM_PTR_(ptr), "h"(val.x), "h"(val.y), "h"(val.z), "h"(val.w) + : "memory");), + (__threadfence(); + asm volatile("st.cg.v4.u16 [%0], {%1, %2, %3, %4};" + : + : _CUB_ASM_PTR_(ptr), "h"(val.x), "h"(val.y), "h"(val.z), "h"(val.w) + : "memory");)); +} + +__device__ __forceinline__ void store_release(uint2 *ptr, uint2 val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.release.gpu.v2.u32 [%0], {%1, %2};" + : + : _CUB_ASM_PTR_(ptr), "r"(val.x), "r"(val.y) + : "memory");), + (__threadfence(); asm volatile("st.cg.v2.u32 [%0], {%1, %2};" + : + : _CUB_ASM_PTR_(ptr), "r"(val.x), "r"(val.y) + : "memory");)); +} + +__device__ __forceinline__ void store_release(unsigned long long *ptr, unsigned long long val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.release.gpu.u64 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "l"(val) + : "memory");), + (__threadfence(); asm volatile("st.cg.u64 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "l"(val) + : "memory");)); +} + +__device__ __forceinline__ void store_release(unsigned int *ptr, unsigned int val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.release.gpu.u32 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "r"(val) + : "memory");), + (__threadfence(); asm volatile("st.cg.u32 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "r"(val) + : "memory");)); +} + +__device__ __forceinline__ void store_release(unsigned short *ptr, unsigned short val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("st.release.gpu.u16 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "h"(val) + : "memory");), + (__threadfence(); asm volatile("st.cg.u16 [%0], %1;" + : + : _CUB_ASM_PTR_(ptr), "h"(val) + : "memory");)); +} + +__device__ __forceinline__ void store_release(unsigned char *ptr, unsigned char val) +{ + NV_IF_TARGET(NV_PROVIDES_SM_70, + (asm volatile("{" + " .reg .u8 datum;" + " cvt.u8.u16 datum, %1;" + " st.release.gpu.u8 [%0], datum;" + "}" + : + : _CUB_ASM_PTR_(ptr), "h"((unsigned short)val) + : "memory");), + (__threadfence(); asm volatile("{" + " .reg .u8 datum;" + " cvt.u8.u16 datum, %1;" + " st.cg.u8 [%0], datum;" + "}" + : + : _CUB_ASM_PTR_(ptr), "h"((unsigned short)val) + : "memory");)); +} + +} // namespace detail + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/temporary_storage.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/temporary_storage.cuh new file mode 100644 index 0000000000000000000000000000000000000000..005a3763ef55f715ceb32bbef9f8b0db3ba9a02c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/temporary_storage.cuh @@ -0,0 +1,350 @@ +/* +* Copyright 2021 NVIDIA Corporation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#pragma once + +#include +#include + + +CUB_NAMESPACE_BEGIN + + +namespace detail +{ + + +namespace temporary_storage +{ + + +class slot; + +template +class alias; + +template +class layout; + + +/** + * @brief Temporary storage slot that can be considered a C++ union with an + * arbitrary fields count. + * + * @warning slot lifetime is defined by the lifetime of the associated layout. + * It's impossible to request new array if layout is already mapped. + * + * @par A Simple Example + * @code + * auto slot = temporary_storage.get_slot(0); + * + * // Add fields into the slot + * // Create an int alias with 0 elements: + * auto int_array = slot->create_alias(); + * // Create a double alias with 2 elements: + * auto double_array = slot->create_alias(2); + * // Create a char alias with 0 elements: + * auto empty_array = slot->create_alias(); + * // Slot size is defined by double_array size (2 * sizeof(double)) + * + * if (condition) + * { + * int_array.grow(42); + * // Now slot size is defined by int_array size (42 * sizeof(int)) + * } + * + * // Temporary storage mapping + * // ... + + * int *d_int_array = int_array.get(); + * double *d_double_array = double_array.get(); + * char *d_empty_array = empty_array.get(); // Guaranteed to return nullptr + * @endcode + */ +class slot +{ + std::size_t m_size{}; + void *m_pointer{}; + +public: + slot() = default; + + /** + * @brief Returns an array of type @p T and length @p elements + */ + template + __host__ __device__ alias create_alias(std::size_t elements = 0); + +private: + __host__ __device__ void set_bytes_required(std::size_t new_size) + { + m_size = (max)(m_size, new_size); + } + + __host__ __device__ std::size_t get_bytes_required() const + { + return m_size; + } + + __host__ __device__ void set_storage(void *ptr) { m_pointer = ptr; } + __host__ __device__ void *get_storage() const { return m_pointer; } + + template + friend class alias; + + template + friend class layout; +}; + + +/** + * @brief Named memory region of a temporary storage slot + * + * @par Overview + * This class provides a typed wrapper of a temporary slot memory region. + * It can be considered as a field in the C++ union. It's only possible to + * increase the array size. + * + * @warning alias lifetime is defined by the lifetime of the associated slot + * It's impossible to grow the array if the layout is already mapped. + */ +template +class alias +{ + slot &m_slot; + std::size_t m_elements{}; + + __host__ __device__ explicit alias(slot &slot, + std::size_t elements = 0) + : m_slot(slot) + , m_elements(elements) + { + this->update_slot(); + } + + __host__ __device__ void update_slot() + { + m_slot.set_bytes_required(m_elements * sizeof(T)); + } + +public: + alias() = delete; + + /** + * @brief Increases the number of elements + * + * @warning + * This method should be called before temporary storage mapping stage. + * + * @param[in] new_elements Increases the memory region occupied in the + * temporary slot to fit up to @p new_elements items + * of type @p T. + */ + __host__ __device__ void grow(std::size_t new_elements) + { + m_elements = new_elements; + this->update_slot(); + } + + /** + * @brief Returns pointer to array + * + * If the @p elements number is equal to zero, or storage layout isn't mapped, + * @p nullptr is returned. + */ + __host__ __device__ T *get() const + { + if (m_elements == 0) + { + return nullptr; + } + + return reinterpret_cast(m_slot.get_storage()); + } + + friend class slot; +}; + + +template +__host__ __device__ alias slot::create_alias(std::size_t elements) +{ + return alias(*this, elements); +} + + +/** + * @brief Temporary storage layout represents a structure with + * @p SlotsCount union-like fields + * + * The layout can be mapped to a temporary buffer only once. + * + * @par A Simple Example + * @code + * cub::detail::temporary_storage::layout<3> temporary_storage; + * + * auto slot_1 = temporary_storage.get_slot(0); + * auto slot_2 = temporary_storage.get_slot(1); + * + * // Add fields into the first slot + * auto int_array = slot_1->create_alias(1); + * auto double_array = slot_1->create_alias(2); + * + * // Add fields into the second slot + * auto char_array = slot_2->create_alias(); + * + * // The equivalent C++ structure could look like + * // struct StorageLayout + * // { + * // union { + * // } slot_0; + * // std::byte padding_0[256 - sizeof (slot_0)]; + * // + * // union { + * // int alias_0[1]; + * // double alias_1[2]; + * // } slot_1; + * // std::byte padding_1[256 - sizeof (slot_1)]; + * // + * // union { + * // char alias_0[0]; + * // } slot_2; + * // std::byte padding_2[256 - sizeof (slot_2)]; + * // }; + * + * // The third slot is empty + * + * // Temporary storage mapping + * if (d_temp_storage == nullptr) + * { + * temp_storage_bytes = temporary_storage.get_size(); + * return; + * } + * else + * { + * temporary_storage.map_to_buffer(d_temp_storage, temp_storage_bytes); + * } + * + * // Use pointers + * int *d_int_array = int_array.get(); + * double *d_double_array = double_array.get(); + * char *d_char_array = char_array.get(); + * @endcode + */ +template +class layout +{ + slot m_slots[SlotsCount]; + std::size_t m_sizes[SlotsCount]; + void *m_pointers[SlotsCount]; + bool m_layout_was_mapped {}; + +public: + layout() = default; + + __host__ __device__ slot *get_slot(int slot_id) + { + if (slot_id < SlotsCount) + { + return &m_slots[slot_id]; + } + + return nullptr; + } + + /** + * @brief Returns required temporary storage size in bytes + */ + __host__ __device__ std::size_t get_size() + { + this->prepare_interface(); + + // AliasTemporaries can return error only in mapping stage, + // so it's safe to ignore it here. + std::size_t temp_storage_bytes{}; + AliasTemporaries(nullptr, temp_storage_bytes, m_pointers, m_sizes); + + if (temp_storage_bytes == 0) + { + // The current CUB convention implies that there are two stages for each + // device-scope function call. The first one returns the required storage + // size. The second stage consumes temporary storage to perform some work. + // The only way to distinguish between the two stages is by checking the + // value of the temporary storage pointer. If zero bytes are requested, + // `cudaMalloc` will return `nullptr`. This fact makes it impossible to + // distinguish between the two stages, so we request some fixed amount of + // bytes (even if we don't need it) to have a non-null temporary storage + // pointer. + return 1; + } + + return temp_storage_bytes; + } + + /** + * @brief Maps the layout to the temporary storage buffer. + */ + __host__ __device__ cudaError_t map_to_buffer(void *d_temp_storage, + std::size_t temp_storage_bytes) + { + if (m_layout_was_mapped) + { + return cudaErrorAlreadyMapped; + } + + this->prepare_interface(); + + cudaError_t error = cudaSuccess; + if ((error = AliasTemporaries(d_temp_storage, + temp_storage_bytes, + m_pointers, + m_sizes))) + { + return error; + } + + for (std::size_t slot_id = 0; slot_id < SlotsCount; slot_id++) + { + m_slots[slot_id].set_storage(m_pointers[slot_id]); + } + + m_layout_was_mapped = true; + return error; + } + +private: + __host__ __device__ void prepare_interface() + { + if (m_layout_was_mapped) + { + return; + } + + for (std::size_t slot_id = 0; slot_id < SlotsCount; slot_id++) + { + const std::size_t slot_size = m_slots[slot_id].get_bytes_required(); + + m_sizes[slot_id] = slot_size; + m_pointers[slot_id] = nullptr; + } + } +}; + +} // namespace temporary_storage + +} // namespace detail + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/type_traits.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/type_traits.cuh new file mode 100644 index 0000000000000000000000000000000000000000..77903306250c57e207eeb69682727cc784028431 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/type_traits.cuh @@ -0,0 +1,58 @@ +/****************************************************************************** + * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Wrappers and extensions around utilities. + */ + +#pragma once + +#include +#include + +#include + + +CUB_NAMESPACE_BEGIN +namespace detail { + +template +using invoke_result_t = +#if CUB_CPP_DIALECT < 2017 + typename ::cuda::std::result_of::type; +#else // 2017+ + ::cuda::std::invoke_result_t; +#endif + +/// The type of intermediate accumulator (according to P2322R6) +template +using accumulator_t = + typename ::cuda::std::decay>::type; + +} // namespace detail +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/uninitialized_copy.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/uninitialized_copy.cuh new file mode 100644 index 0000000000000000000000000000000000000000..2b3e4b1da264feac918a8409b5bbfaa983de6b82 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/detail/uninitialized_copy.cuh @@ -0,0 +1,75 @@ +/****************************************************************************** + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include + +#include + +CUB_NAMESPACE_BEGIN + + +namespace detail +{ + +#if defined(_NVHPC_CUDA) +template +__host__ __device__ void uninitialized_copy(T *ptr, U &&val) +{ + // NVBug 3384810 + new (ptr) T(::cuda::std::forward(val)); +} +#else +template ::value, + int + >::type = 0> +__host__ __device__ void uninitialized_copy(T *ptr, U &&val) +{ + *ptr = ::cuda::std::forward(val); +} + +template ::value, + int + >::type = 0> +__host__ __device__ void uninitialized_copy(T *ptr, U &&val) +{ + new (ptr) T(::cuda::std::forward(val)); +} +#endif + +} // namespace detail + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_adjacent_difference.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_adjacent_difference.cuh new file mode 100644 index 0000000000000000000000000000000000000000..0f614d1876de0a78b083cc0ef1bf87911551f16c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_adjacent_difference.cuh @@ -0,0 +1,699 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include + + +CUB_NAMESPACE_BEGIN + + +/** + * @brief DeviceAdjacentDifference provides device-wide, parallel operations for + * computing the differences of adjacent elements residing within + * device-accessible memory. + * + * @ingroup SingleModule + * + * @par Overview + * - DeviceAdjacentDifference calculates the differences of adjacent elements in + * d_input. Because the binary operation could be noncommutative, there + * are two sets of methods. Methods named SubtractLeft subtract left element + * `*(i - 1)` of input sequence from current element `*i`. + * Methods named `SubtractRight` subtract current element `*i` from the + * right one `*(i + 1)`: + * @par + * @code + * int *d_values; // [1, 2, 3, 4] + * //... + * int *d_subtract_left_result <-- [ 1, 1, 1, 1 ] + * int *d_subtract_right_result <-- [ -1, -1, -1, 4 ] + * @endcode + * - For SubtractLeft, if the left element is out of bounds, the iterator is + * assigned to \*(result + (i - first)) without modification. + * - For SubtractRight, if the right element is out of bounds, the iterator is + * assigned to \*(result + (i - first)) without modification. + * + * @par Snippet + * The code snippet below illustrates how to use @p DeviceAdjacentDifference to + * compute the left difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * int num_items; // e.g., 8 + * int *d_values; // e.g., [1, 2, 1, 2, 1, 2, 1, 2] + * //... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * + * cub::DeviceAdjacentDifference::SubtractLeft( + * d_temp_storage, temp_storage_bytes, d_values, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run operation + * cub::DeviceAdjacentDifference::SubtractLeft( + * d_temp_storage, temp_storage_bytes, d_values, num_items); + * + * // d_values <-- [1, 1, -1, 1, -1, 1, -1, 1] + * @endcode + */ +struct DeviceAdjacentDifference +{ +private: + template + static CUB_RUNTIME_FUNCTION cudaError_t + AdjacentDifference(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_input, + OutputIteratorT d_output, + NumItemsT num_items, + DifferenceOpT difference_op, + cudaStream_t stream) + { + using OffsetT = typename detail::ChooseOffsetT::Type; + + using DispatchT = DispatchAdjacentDifference; + + return DispatchT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_input, + d_output, + static_cast(num_items), + difference_op, + stream); + } + +public: + + /** + * @brief Subtracts the left element of each adjacent pair of elements residing within device-accessible memory. + * @ingroup SingleModule + * + * @par Overview + * - Calculates the differences of adjacent elements in `d_input`. That is, + * `*d_input` is assigned to `*d_output`, and, for each iterator `i` in the + * range `[d_input + 1, d_input + num_items)`, the result of + * `difference_op(*i, *(i - 1))` is assigned to + * `*(d_output + (i - d_input))`. + * - Note that the behavior is undefined if the input and output ranges + * overlap in any way. + * + * @par Snippet + * The code snippet below illustrates how to use @p DeviceAdjacentDifference + * to compute the difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * struct CustomDifference + * { + * template + * __device__ DataType operator()(DataType &lhs, DataType &rhs) + * { + * return lhs - rhs; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers + * int num_items; // e.g., 8 + * int *d_input; // e.g., [1, 2, 1, 2, 1, 2, 1, 2] + * int *d_output; + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * + * cub::DeviceAdjacentDifference::SubtractLeftCopy( + * d_temp_storage, temp_storage_bytes, + * d_input, d_output, + * num_items, CustomDifference()); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run operation + * cub::DeviceAdjacentDifference::SubtractLeftCopy( + * d_temp_storage, temp_storage_bytes, + * d_input, d_output, + * num_items, CustomDifference()); + * + * // d_input <-- [1, 2, 1, 2, 1, 2, 1, 2] + * // d_output <-- [1, 1, -1, 1, -1, 1, -1, 1] + * @endcode + * + * @tparam InputIteratorT + * is a model of Input Iterator, + * and `x` and `y` are objects of `InputIteratorT`'s `value_type`, then + * `x - y` is defined, and `InputIteratorT`'s `value_type` is convertible to + * a type in `OutputIteratorT`'s set of `value_types`, and the return type + * of `x - y` is convertible to a type in `OutputIteratorT`'s set of + * `value_types`. + * + * @tparam OutputIteratorT + * is a model of Output Iterator. + * + * @tparam DifferenceOpT + * Its `result_type` is convertible to a type in `OutputIteratorT`'s set of + * `value_types`. + * + * @tparam NumItemsT **[inferred]** Type of num_items + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_input + * Pointer to the input sequence + * + * @param[out] d_output + * Pointer to the output sequence + * + * @param[in] num_items + * Number of items in the input sequence + * + * @param[in] difference_op + * The binary function used to compute differences + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0 + */ + template + static CUB_RUNTIME_FUNCTION cudaError_t + SubtractLeftCopy(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_input, + OutputIteratorT d_output, + NumItemsT num_items, + DifferenceOpT difference_op = {}, + cudaStream_t stream = 0) + { + constexpr bool may_alias = false; + constexpr bool read_left = true; + + return AdjacentDifference(d_temp_storage, + temp_storage_bytes, + d_input, + d_output, + num_items, + difference_op, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + static CUB_RUNTIME_FUNCTION cudaError_t + SubtractLeftCopy(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_input, + OutputIteratorT d_output, + NumItemsT num_items, + DifferenceOpT difference_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SubtractLeftCopy(d_temp_storage, + temp_storage_bytes, + d_input, + d_output, + num_items, + difference_op, + stream); + } + + /** + * @brief Subtracts the left element of each adjacent pair of elements + * residing within device-accessible memory. + * + * @ingroup SingleModule + * + * @par Overview + * Calculates the differences of adjacent elements in `d_input`. That is, for + * each iterator `i` in the range `[d_input + 1, d_input + num_items)`, the + * result of `difference_op(*i, *(i - 1))` is assigned to + * `*(d_input + (i - d_input))`. + * + * @par Snippet + * The code snippet below illustrates how to use @p DeviceAdjacentDifference + * to compute the difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * struct CustomDifference + * { + * template + * __device__ DataType operator()(DataType &lhs, DataType &rhs) + * { + * return lhs - rhs; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers + * int num_items; // e.g., 8 + * int *d_data; // e.g., [1, 2, 1, 2, 1, 2, 1, 2] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceAdjacentDifference::SubtractLeft( + * d_temp_storage, temp_storage_bytes, + * d_data, num_items, CustomDifference()); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run operation + * cub::DeviceAdjacentDifference::SubtractLeft( + * d_temp_storage, temp_storage_bytes, + * d_data, num_items, CustomDifference()); + * + * // d_data <-- [1, 1, -1, 1, -1, 1, -1, 1] + * @endcode + * + * @tparam RandomAccessIteratorT + * is a model of Random Access Iterator, + * `RandomAccessIteratorT` is mutable. If `x` and `y` are objects of + * `RandomAccessIteratorT`'s `value_type`, and `x - y` is defined, then the + * return type of `x - y` should be convertible to a type in + * `RandomAccessIteratorT`'s set of `value_types`. + * + * @tparam DifferenceOpT + * Its `result_type` is convertible to a type in `RandomAccessIteratorT`'s + * set of `value_types`. + * + * @tparam NumItemsT **[inferred]** Type of num_items + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in,out] d_input + * Pointer to the input sequence and the result + * + * @param[in] num_items + * Number of items in the input sequence + * + * @param[in] difference_op + * The binary function used to compute differences + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + static CUB_RUNTIME_FUNCTION cudaError_t + SubtractLeft(void *d_temp_storage, + std::size_t &temp_storage_bytes, + RandomAccessIteratorT d_input, + NumItemsT num_items, + DifferenceOpT difference_op = {}, + cudaStream_t stream = 0) + { + constexpr bool may_alias = true; + constexpr bool read_left = true; + + return AdjacentDifference(d_temp_storage, + temp_storage_bytes, + d_input, + d_input, + num_items, + difference_op, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + static CUB_RUNTIME_FUNCTION cudaError_t + SubtractLeft(void *d_temp_storage, + std::size_t &temp_storage_bytes, + RandomAccessIteratorT d_input, + NumItemsT num_items, + DifferenceOpT difference_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SubtractLeft(d_temp_storage, + temp_storage_bytes, + d_input, + num_items, + difference_op, + stream); + } + + /** + * @brief Subtracts the right element of each adjacent pair of elements + * residing within device-accessible memory. + * + * @ingroup SingleModule + * + * @par Overview + * - Calculates the right differences of adjacent elements in `d_input`. That + * is, `*(d_input + num_items - 1)` is assigned to + * `*(d_output + num_items - 1)`, and, for each iterator `i` in the range + * `[d_input, d_input + num_items - 1)`, the result of + * `difference_op(*i, *(i + 1))` is assigned to + * `*(d_output + (i - d_input))`. + * - Note that the behavior is undefined if the input and output ranges + * overlap in any way. + * + * @par Snippet + * The code snippet below illustrates how to use @p DeviceAdjacentDifference + * to compute the difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * struct CustomDifference + * { + * template + * __device__ DataType operator()(DataType &lhs, DataType &rhs) + * { + * return lhs - rhs; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers + * int num_items; // e.g., 8 + * int *d_input; // e.g., [1, 2, 1, 2, 1, 2, 1, 2] + * int *d_output; + * .. + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * size_t temp_storage_bytes = 0; + * cub::DeviceAdjacentDifference::SubtractRightCopy( + * d_temp_storage, temp_storage_bytes, + * d_input, d_output, num_items, CustomDifference()); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run operation + * cub::DeviceAdjacentDifference::SubtractRightCopy( + * d_temp_storage, temp_storage_bytes, + * d_input, d_output, num_items, CustomDifference()); + * + * // d_input <-- [1, 2, 1, 2, 1, 2, 1, 2] + * // d_data <-- [-1, 1, -1, 1, -1, 1, -1, 2] + * @endcode + * + * @tparam InputIteratorT + * is a model of Input Iterator, + * and `x` and `y` are objects of `InputIteratorT`'s `value_type`, then + * `x - y` is defined, and `InputIteratorT`'s `value_type` is convertible to + * a type in `OutputIteratorT`'s set of `value_types`, and the return type + * of `x - y` is convertible to a type in `OutputIteratorT`'s set of + * `value_types`. + * + * @tparam OutputIteratorT + * is a model of Output Iterator. + * + * @tparam DifferenceOpT + * Its `result_type` is convertible to a type in `RandomAccessIteratorT`'s + * set of `value_types`. + * + * @tparam NumItemsT **[inferred]** Type of num_items + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_input + * Pointer to the input sequence + * + * @param[out] d_output + * Pointer to the output sequence + * + * @param[in] num_items + * Number of items in the input sequence + * + * @param[in] difference_op + * The binary function used to compute differences. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + static CUB_RUNTIME_FUNCTION cudaError_t + SubtractRightCopy(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_input, + OutputIteratorT d_output, + NumItemsT num_items, + DifferenceOpT difference_op = {}, + cudaStream_t stream = 0) + { + constexpr bool may_alias = false; + constexpr bool read_left = false; + + return AdjacentDifference(d_temp_storage, + temp_storage_bytes, + d_input, + d_output, + num_items, + difference_op, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + static CUB_RUNTIME_FUNCTION cudaError_t + SubtractRightCopy(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_input, + OutputIteratorT d_output, + NumItemsT num_items, + DifferenceOpT difference_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SubtractRightCopy(d_temp_storage, + temp_storage_bytes, + d_input, + d_output, + num_items, + difference_op, + stream); + } + + /** + * @brief Subtracts the right element of each adjacent pair of elements + * residing within device-accessible memory. + * + * @ingroup SingleModule + * + * @par Overview + * Calculates the right differences of adjacent elements in `d_input`. That + * is, for each iterator `i` in the range + * `[d_input, d_input + num_items - 1)`, the result of + * `difference_op(*i, *(i + 1))` is assigned to + * `*(d_input + (i - d_input))`. + * + * @par Snippet + * The code snippet below illustrates how to use @p DeviceAdjacentDifference + * to compute the difference between adjacent elements. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * int num_items; // e.g., 8 + * int *d_data; // e.g., [1, 2, 1, 2, 1, 2, 1, 2] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceAdjacentDifference::SubtractRight( + * d_temp_storage, temp_storage_bytes, d_data, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run operation + * cub::DeviceAdjacentDifference::SubtractRight( + * d_temp_storage, temp_storage_bytes, d_data, num_items); + * + * // d_data <-- [-1, 1, -1, 1, -1, 1, -1, 2] + * @endcode + * + * @tparam RandomAccessIteratorT + * is a model of Random Access Iterator, + * `RandomAccessIteratorT` is mutable. If `x` and `y` are objects of + * `RandomAccessIteratorT`'s `value_type`, and `x - y` is defined, then the + * return type of `x - y` should be convertible to a type in + * `RandomAccessIteratorT`'s set of `value_types`. + * + * @tparam DifferenceOpT + * Its `result_type` is convertible to a type in `RandomAccessIteratorT`'s + * set of `value_types`. + * + * @tparam NumItemsT **[inferred]** Type of num_items + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_input + * Pointer to the input sequence + * + * @param[in] num_items + * Number of items in the input sequence + * + * @param[in] difference_op + * The binary function used to compute differences + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + static CUB_RUNTIME_FUNCTION cudaError_t + SubtractRight(void *d_temp_storage, + std::size_t &temp_storage_bytes, + RandomAccessIteratorT d_input, + NumItemsT num_items, + DifferenceOpT difference_op = {}, + cudaStream_t stream = 0) + { + constexpr bool may_alias = true; + constexpr bool read_left = false; + + return AdjacentDifference(d_temp_storage, + temp_storage_bytes, + d_input, + d_input, + num_items, + difference_op, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + static CUB_RUNTIME_FUNCTION cudaError_t + SubtractRight(void *d_temp_storage, + std::size_t &temp_storage_bytes, + RandomAccessIteratorT d_input, + NumItemsT num_items, + DifferenceOpT difference_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SubtractRight(d_temp_storage, + temp_storage_bytes, + d_input, + num_items, + difference_op, + stream); + } +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_copy.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_copy.cuh new file mode 100644 index 0000000000000000000000000000000000000000..445f5d862bc87c612f635efb4a12b6d60ec4617d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_copy.cuh @@ -0,0 +1,172 @@ +/****************************************************************************** + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::DeviceCopy provides device-wide, parallel operations for copying data. + */ + +#pragma once + +#include +#include + +#include + +#include + +CUB_NAMESPACE_BEGIN + +/** + * @brief cub::DeviceCopy provides device-wide, parallel operations for copying data. + * \ingroup SingleModule + */ +struct DeviceCopy +{ + /** + * @brief Copies data from a batch of given source ranges to their corresponding destination + * ranges. + * @note If any input range aliases any output range the behavior is undefined. If + * any output range aliases another output range the behavior is undefined. Input + * ranges can alias one another. + * + * @par Snippet + * The code snippet below illustrates usage of DeviceCopy::Batched to perform a DeviceRunLength + * Decode operation. + * @par + * @code + * struct GetIteratorToRange + * { + * __host__ __device__ __forceinline__ auto operator()(uint32_t index) + * { + * return thrust::make_constant_iterator(d_data_in[index]); + * } + * int32_t *d_data_in; + * }; + * + * struct GetPtrToRange + * { + * __host__ __device__ __forceinline__ auto operator()(uint32_t index) + * { + * return d_data_out + d_offsets[index]; + * } + * int32_t *d_data_out; + * uint32_t *d_offsets; + * }; + * + * struct GetRunLength + * { + * __host__ __device__ __forceinline__ uint32_t operator()(uint32_t index) + * { + * return d_offsets[index + 1] - d_offsets[index]; + * } + * uint32_t *d_offsets; + * }; + * + * uint32_t num_ranges = 5; + * int32_t *d_data_in; // e.g., [4, 2, 7, 3, 1] + * int32_t *d_data_out; // e.g., [0, ... ] + * uint32_t *d_offsets; // e.g., [0, 2, 5, 6, 9, 14] + * + * // Returns a constant iterator to the element of the i-th run + * thrust::counting_iterator iota(0); + * auto iterators_in = thrust::make_transform_iterator(iota, GetIteratorToRange{d_data_in}); + * + * // Returns the run length of the i-th run + * auto sizes = thrust::make_transform_iterator(iota, GetRunLength{d_offsets}); + * + * // Returns pointers to the output range for each run + * auto ptrs_out = thrust::make_transform_iterator(iota, GetPtrToRange{d_data_out, d_offsets}); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * size_t temp_storage_bytes = 0; + * cub::DeviceCopy::Batched(d_temp_storage, temp_storage_bytes, iterators_in, ptrs_out, sizes, + * num_ranges); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run batched copy algorithm (used to perform runlength decoding) + * cub::DeviceCopy::Batched(d_temp_storage, temp_storage_bytes, iterators_in, ptrs_out, sizes, + * num_ranges); + * + * // d_data_out <-- [4, 4, 2, 2, 2, 7, 3, 3, 3, 1, 1, 1, 1, 1] + * @endcode + * @tparam InputIt [inferred] Device-accessible random-access input iterator type + * providing the iterators to the source ranges + * @tparam OutputIt [inferred] Device-accessible random-access input iterator type + * providing the iterators to the destination ranges + * @tparam SizeIteratorT [inferred] Device-accessible random-access input iterator + * type providing the number of items to be copied for each pair of ranges + * @param d_temp_storage [in] Device-accessible allocation of temporary storage. When NULL, the + * required allocation size is written to \p temp_storage_bytes and no work is done. + * @param temp_storage_bytes [in,out] Reference to size in bytes of \p d_temp_storage allocation + * @param input_it [in] Device-accessible iterator providing the iterators to the source + * ranges + * @param output_it [in] Device-accessible iterator providing the iterators to the + * destination ranges + * @param sizes [in] Device-accessible iterator providing the number of elements to be copied + * for each pair of ranges + * @param num_ranges [in] The total number of range pairs + * @param stream [in] [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t Batched(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIt input_it, + OutputIt output_it, + SizeIteratorT sizes, + uint32_t num_ranges, + cudaStream_t stream = 0) + { + // Integer type large enough to hold any offset in [0, num_ranges) + using RangeOffsetT = uint32_t; + + // Integer type large enough to hold any offset in [0, num_thread_blocks_launched), where a safe + // uppper bound on num_thread_blocks_launched can be assumed to be given by + // IDIV_CEIL(num_ranges, 64) + using BlockOffsetT = uint32_t; + + return detail::DispatchBatchMemcpy, + false>::Dispatch(d_temp_storage, + temp_storage_bytes, + input_it, + output_it, + sizes, + num_ranges, + stream); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_histogram.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_histogram.cuh new file mode 100644 index 0000000000000000000000000000000000000000..4e71c04ed82e3a2f7814b55607ae39a0ec793d61 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_histogram.cuh @@ -0,0 +1,1672 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::DeviceHistogram provides device-wide parallel operations for + * constructing histogram(s) from a sequence of samples data residing + * within device-accessible memory. + */ + +#pragma once + +#include +#include +#include + +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * @brief DeviceHistogram provides device-wide parallel operations for + * constructing histogram(s) from a sequence of samples data residing + * within device-accessible memory. ![](histogram_logo.png) + * @ingroup SingleModule + * + * @par Overview + * A histogram + * counts the number of observations that fall into each of the disjoint categories (known as bins). + * + * @par Usage Considerations + * @cdp_class{DeviceHistogram} + * + */ +struct DeviceHistogram +{ + /******************************************************************//** + * @name Evenly-segmented bin ranges + *********************************************************************/ + //@{ + + /** + * @brief Computes an intensity histogram from a sequence of data samples + * using equal-width bins. + * + * @par + * - The number of histogram bins is (`num_levels - 1`) + * - All bins comprise the same width of sample values: + * `(upper_level - lower_level) / (num_levels - 1)`. + * - If the common type of `SampleT` and `LevelT` is of integral type, the bin for a sample is + * computed as `(sample - lower_level) * (num_levels - 1) / (upper_level - lower_level)`, round + * down to the nearest whole number. To protect against potential overflows, if the product + * `(upper_level - lower_level) * (num_levels - 1)` exceeds the number representable by an + * `uint64_t`, the cuda error `cudaErrorInvalidValue` is returned. If the common type is 128 + * bits wide, bin computation will use 128-bit arithmetic and `cudaErrorInvalidValue` will only + * be returned if bin computation would overflow for 128-bit arithmetic. + * - The ranges `[d_samples, d_samples + num_samples)` and + * `[d_histogram, d_histogram + num_levels - 1)` shall not overlap + * in any way. + * - `cuda::std::common_type` must be valid, and both LevelT + * and SampleT must be valid arithmetic types. The common type must be + * convertible to `int` and trivially copyable. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the computation of a six-bin histogram + * from a sequence of float samples + * + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input samples and output histogram + * int num_samples; // e.g., 10 + * float* d_samples; // e.g., [2.2, 6.1, 7.1, 2.9, 3.5, 0.3, 2.9, 2.1, 6.1, 999.5] + * int* d_histogram; // e.g., [ -, -, -, -, -, -] + * int num_levels; // e.g., 7 (seven level boundaries for six bins) + * float lower_level; // e.g., 0.0 (lower sample value boundary of lowest bin) + * float upper_level; // e.g., 12.0 (upper sample value boundary of upper bin) + * ... + * + * // Determine temporary device storage requirements + * void* d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceHistogram::HistogramEven( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, + * lower_level, upper_level, num_samples); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Compute histograms + * cub::DeviceHistogram::HistogramEven( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, + * lower_level, upper_level, num_samples); + * + * // d_histogram <-- [1, 5, 0, 3, 0, 0]; + * @endcode + * + * @tparam SampleIteratorT + * **[inferred]** Random-access input iterator type for reading input + * samples \iterator + * + * @tparam CounterT + * **[inferred]** Integer type for histogram bin counters + * + * @tparam LevelT + * **[inferred]** Type for specifying boundaries (levels) + * + * @tparam OffsetT + * **[inferred]** Signed integer type for sequence offsets, list lengths, + * pointer differences, etc. \offset_size1 + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_samples + * The pointer to the input sequence of data samples. + * + * @param[out] d_histogram + * The pointer to the histogram counter output array of length + * `num_levels - 1`. + * + * @param[in] num_levels + * The number of boundaries (levels) for delineating histogram samples. + * Implies that the number of bins is `num_levels - 1`. + * + * @param[in] lower_level + * The lower sample value bound (inclusive) for the lowest histogram bin. + * + * @param[in] upper_level + * The upper sample value bound (exclusive) for the highest histogram bin. + * + * @param[in] num_samples + * The number of input samples (i.e., the length of `d_samples`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + HistogramEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram, + int num_levels, + LevelT lower_level, + LevelT upper_level, + OffsetT num_samples, + cudaStream_t stream = 0) + { + /// The sample value type of the input iterator + using SampleT = cub::detail::value_t; + + CounterT *d_histogram1[1] = {d_histogram}; + int num_levels1[1] = {num_levels}; + LevelT lower_level1[1] = {lower_level}; + LevelT upper_level1[1] = {upper_level}; + + return MultiHistogramEven<1, 1>(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram1, + num_levels1, + lower_level1, + upper_level1, + num_samples, + static_cast(1), + sizeof(SampleT) * num_samples, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + HistogramEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram, + int num_levels, + LevelT lower_level, + LevelT upper_level, + OffsetT num_samples, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return HistogramEven(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + lower_level, + upper_level, + num_samples, + stream); + } + + /** + * @brief Computes an intensity histogram from a sequence of data samples + * using equal-width bins. + * + * @par + * - A two-dimensional *region of interest* within `d_samples` can be + * specified using the `num_row_samples`, `num_rows`, and + * `row_stride_bytes` parameters. + * - The row stride must be a whole multiple of the sample data type + * size, i.e., `(row_stride_bytes % sizeof(SampleT)) == 0`. + * - The number of histogram bins is (`num_levels - 1`) + * - All bins comprise the same width of sample values: + * `(upper_level - lower_level) / (num_levels - 1)` + * - If the common type of `SampleT` and `LevelT` is of integral type, the bin for a sample is + * computed as `(sample - lower_level) * (num_levels - 1) / (upper_level - lower_level)`, round + * down to the nearest whole number. To protect against potential overflows, if the product + * `(upper_level - lower_level) * (num_levels - 1)` exceeds the number representable by an + * `uint64_t`, the cuda error `cudaErrorInvalidValue` is returned. If the common type is 128 + * bits wide, bin computation will use 128-bit arithmetic and `cudaErrorInvalidValue` will only + * be returned if bin computation would overflow for 128-bit arithmetic. + * - For a given row `r` in `[0, num_rows)`, let + * `row_begin = d_samples + r * row_stride_bytes / sizeof(SampleT)` and + * `row_end = row_begin + num_row_samples`. The ranges + * `[row_begin, row_end)` and `[d_histogram, d_histogram + num_levels - 1)` + * shall not overlap in any way. + * - `cuda::std::common_type` must be valid, and both LevelT + * and SampleT must be valid arithmetic types. The common type must be + * convertible to `int` and trivially copyable. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the computation of a six-bin histogram + * from a 2x5 region of interest within a flattened 2x7 array of float samples. + * + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input samples and output histogram + * int num_row_samples; // e.g., 5 + * int num_rows; // e.g., 2; + * size_t row_stride_bytes; // e.g., 7 * sizeof(float) + * float* d_samples; // e.g., [2.2, 6.1, 7.1, 2.9, 3.5, -, -, + * // 0.3, 2.9, 2.1, 6.1, 999.5, -, -] + * int* d_histogram; // e.g., [ -, -, -, -, -, -] + * int num_levels; // e.g., 7 (seven level boundaries for six bins) + * float lower_level; // e.g., 0.0 (lower sample value boundary of lowest bin) + * float upper_level; // e.g., 12.0 (upper sample value boundary of upper bin) + * ... + * + * // Determine temporary device storage requirements + * void* d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceHistogram::HistogramEven( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, lower_level, upper_level, + * num_row_samples, num_rows, row_stride_bytes); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Compute histograms + * cub::DeviceHistogram::HistogramEven( + * d_temp_storage, temp_storage_bytes, d_samples, d_histogram, + * d_samples, d_histogram, num_levels, lower_level, upper_level, + * num_row_samples, num_rows, row_stride_bytes); + * + * // d_histogram <-- [1, 5, 0, 3, 0, 0]; + * @endcode + * + * @tparam SampleIteratorT + * **[inferred]** Random-access input iterator type for reading + * input samples. \iterator + * + * @tparam CounterT + * **[inferred]** Integer type for histogram bin counters + * + * @tparam LevelT + * **[inferred]** Type for specifying boundaries (levels) + * + * @tparam OffsetT + * **[inferred]** Signed integer type for sequence offsets, list lengths, + * pointer differences, etc. \offset_size1 + + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_samples + * The pointer to the input sequence of data samples. + * + * @param[out] d_histogram + * The pointer to the histogram counter output array of + * length `num_levels - 1`. + * + * @param[in] num_levels + * The number of boundaries (levels) for delineating histogram samples. + * Implies that the number of bins is `num_levels - 1`. + * + * @param[in] lower_level + * The lower sample value bound (inclusive) for the lowest histogram bin. + * + * @param[in] upper_level + * The upper sample value bound (exclusive) for the highest histogram bin. + * + * @param[in] num_row_samples + * The number of data samples per row in the region of interest + * + * @param[in] num_rows + * The number of rows in the region of interest + * + * @param[in] row_stride_bytes + * The number of bytes between starts of consecutive rows in + * the region of interest + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + HistogramEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram, + int num_levels, + LevelT lower_level, + LevelT upper_level, + OffsetT num_row_samples, + OffsetT num_rows, + size_t row_stride_bytes, + cudaStream_t stream = 0) + { + CounterT *d_histogram1[1] = {d_histogram}; + int num_levels1[1] = {num_levels}; + LevelT lower_level1[1] = {lower_level}; + LevelT upper_level1[1] = {upper_level}; + + return MultiHistogramEven<1, 1>(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram1, + num_levels1, + lower_level1, + upper_level1, + num_row_samples, + num_rows, + row_stride_bytes, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + HistogramEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram, + int num_levels, + LevelT lower_level, + LevelT upper_level, + OffsetT num_row_samples, + OffsetT num_rows, + size_t row_stride_bytes, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return HistogramEven(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + lower_level, + upper_level, + num_row_samples, + num_rows, + row_stride_bytes, + stream); + } + + /** + * @brief Computes per-channel intensity histograms from a sequence of + * multi-channel "pixel" data samples using equal-width bins. + * + * @par + * - The input is a sequence of *pixel* structures, where each pixel comprises + * a record of `NUM_CHANNELS` consecutive data samples + * (e.g., an *RGBA* pixel). + * - Of the `NUM_CHANNELS` specified, the function will only compute + * histograms for the first `NUM_ACTIVE_CHANNELS` + * (e.g., only *RGB* histograms from *RGBA* pixel samples). + * - The number of histogram bins for channeli is + * `num_levels[i] - 1`. + * - For channeli, the range of values for all histogram bins + * have the same width: + * `(upper_level[i] - lower_level[i]) / (num_levels[i] - 1)` + * - If the common type of sample and level is of integral type, the bin for a sample is + * computed as `(sample - lower_level[i]) * (num_levels - 1) / (upper_level[i] - + * lower_level[i])`, round down to the nearest whole number. To protect against potential + * overflows, if, for any channel `i`, the product `(upper_level[i] - lower_level[i]) * + * (num_levels[i] - 1)` exceeds the number representable by an `uint64_t`, the cuda error + * `cudaErrorInvalidValue` is returned. If the common type is 128 bits wide, bin computation + * will use 128-bit arithmetic and `cudaErrorInvalidValue` will only be returned if bin + * computation would overflow for 128-bit arithmetic. + * - For a given channel `c` in `[0, NUM_ACTIVE_CHANNELS)`, the ranges + * `[d_samples, d_samples + NUM_CHANNELS * num_pixels)` and + * `[d_histogram[c], d_histogram[c] + num_levels[c] - 1)` shall not overlap + * in any way. + * - `cuda::std::common_type` must be valid, and both LevelT + * and SampleT must be valid arithmetic types. The common type must be + * convertible to `int` and trivially copyable. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the computation of three 256-bin RGB histograms + * from a quad-channel sequence of RGBA pixels (8 bits per channel per pixel) + * + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input samples and output histograms + * int num_pixels; // e.g., 5 + * unsigned char* d_samples; // e.g., [(2, 6, 7, 5), (3, 0, 2, 1), (7, 0, 6, 2), + * // (0, 6, 7, 5), (3, 0, 2, 6)] + * int* d_histogram[3]; // e.g., three device pointers to three device buffers, + * // each allocated with 256 integer counters + * int num_levels[3]; // e.g., {257, 257, 257}; + * unsigned int lower_level[3]; // e.g., {0, 0, 0}; + * unsigned int upper_level[3]; // e.g., {256, 256, 256}; + * ... + * + * // Determine temporary device storage requirements + * void* d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceHistogram::MultiHistogramEven<4, 3>( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, + * lower_level, upper_level, num_pixels); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Compute histograms + * cub::DeviceHistogram::MultiHistogramEven<4, 3>( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, + * lower_level, upper_level, num_pixels); + * + * // d_histogram <-- [ [1, 0, 1, 2, 0, 0, 0, 1, 0, 0, 0, ..., 0], + * // [0, 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, ..., 0], + * // [0, 0, 2, 0, 0, 0, 1, 2, 0, 0, 0, ..., 0] ] + * @endcode + * + * @tparam NUM_CHANNELS + * Number of channels interleaved in the input data (may be greater than + * the number of channels being actively histogrammed) + * + * @tparam NUM_ACTIVE_CHANNELS + * **[inferred]** Number of channels actively being histogrammed + * + * @tparam SampleIteratorT + * **[inferred]** Random-access input iterator type for reading + * input samples. \iterator + * + * @tparam CounterT + * **[inferred]** Integer type for histogram bin counters + * + * @tparam LevelT + * **[inferred]** Type for specifying boundaries (levels) + * + * @tparam OffsetT + * **[inferred]** Signed integer type for sequence offsets, list lengths, + * pointer differences, etc. \offset_size1 + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_samples + * The pointer to the multi-channel input sequence of data samples. + * The samples from different channels are assumed to be interleaved + * (e.g., an array of 32-bit pixels where each pixel consists of four + * *RGBA* 8-bit samples). + * + * @param[out] d_histogram + * The pointers to the histogram counter output arrays, one for each active + * channel. For channeli, the allocation length of + * `d_histogram[i]` should be `num_levels[i] - 1`. + * + * @param[in] num_levels + * The number of boundaries (levels) for delineating histogram samples in + * each active channel. Implies that the number of bins for + * channeli is `num_levels[i] - 1`. + * + * @param[in] lower_level + * The lower sample value bound (inclusive) for the lowest histogram bin in + * each active channel. + * + * @param[in] upper_level + * The upper sample value bound (exclusive) for the highest histogram bin + * in each active channel. + * + * @param[in] num_pixels + * The number of multi-channel pixels + * (i.e., the length of `d_samples / NUM_CHANNELS`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + MultiHistogramEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram[NUM_ACTIVE_CHANNELS], + int num_levels[NUM_ACTIVE_CHANNELS], + LevelT lower_level[NUM_ACTIVE_CHANNELS], + LevelT upper_level[NUM_ACTIVE_CHANNELS], + OffsetT num_pixels, + cudaStream_t stream = 0) + { + /// The sample value type of the input iterator + using SampleT = cub::detail::value_t; + + return MultiHistogramEven( + d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + lower_level, + upper_level, + num_pixels, + static_cast(1), + sizeof(SampleT) * NUM_CHANNELS * num_pixels, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + MultiHistogramEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram[NUM_ACTIVE_CHANNELS], + int num_levels[NUM_ACTIVE_CHANNELS], + LevelT lower_level[NUM_ACTIVE_CHANNELS], + LevelT upper_level[NUM_ACTIVE_CHANNELS], + OffsetT num_pixels, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return MultiHistogramEven(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + lower_level, + upper_level, + num_pixels, + stream); + } + + /** + * @brief Computes per-channel intensity histograms from a sequence of + * multi-channel "pixel" data samples using equal-width bins. + * + * @par + * - The input is a sequence of *pixel* structures, where each pixel + * comprises a record of `NUM_CHANNELS` consecutive data samples + * (e.g., an *RGBA* pixel). + * - Of the `NUM_CHANNELS` specified, the function will only compute + * histograms for the first `NUM_ACTIVE_CHANNELS` (e.g., only *RGB* + * histograms from *RGBA* pixel samples). + * - A two-dimensional *region of interest* within `d_samples` can be + * specified using the `num_row_samples`, `num_rows`, and + * `row_stride_bytes` parameters. + * - The row stride must be a whole multiple of the sample data type + * size, i.e., `(row_stride_bytes % sizeof(SampleT)) == 0`. + * - The number of histogram bins for channeli is + * `num_levels[i] - 1`. + * - For channeli, the range of values for all histogram + * bins have the same width: + * `(upper_level[i] - lower_level[i]) / (num_levels[i] - 1)` + * - If the common type of sample and level is of integral type, the bin for a sample is + * computed as `(sample - lower_level[i]) * (num_levels - 1) / (upper_level[i] - + * lower_level[i])`, round down to the nearest whole number. To protect against potential + * overflows, if, for any channel `i`, the product `(upper_level[i] - lower_level[i]) * + * (num_levels[i] - 1)` exceeds the number representable by an `uint64_t`, the cuda error + * `cudaErrorInvalidValue` is returned. If the common type is 128 bits wide, bin computation + * will use 128-bit arithmetic and `cudaErrorInvalidValue` will only be returned if bin + * computation would overflow for 128-bit arithmetic. + * - For a given row `r` in `[0, num_rows)`, and sample `s` in + * `[0, num_row_pixels)`, let + * `row_begin = d_samples + r * row_stride_bytes / sizeof(SampleT)`, + * `sample_begin = row_begin + s * NUM_CHANNELS`, and + * `sample_end = sample_begin + NUM_ACTIVE_CHANNELS`. For a given channel + * `c` in `[0, NUM_ACTIVE_CHANNELS)`, the ranges + * `[sample_begin, sample_end)` and + * `[d_histogram[c], d_histogram[c] + num_levels[c] - 1)` shall not overlap + * in any way. + * - `cuda::std::common_type` must be valid, and both LevelT + * and SampleT must be valid arithmetic types. The common type must be + * convertible to `int` and trivially copyable. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the computation of three 256-bin + * *RGB* histograms from a 2x3 region of interest of within a flattened 2x4 + * array of quad-channel *RGBA* pixels (8 bits per channel per pixel). + * + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for input + * // samples and output histograms + * int num_row_pixels; // e.g., 3 + * int num_rows; // e.g., 2 + * size_t row_stride_bytes; // e.g., 4 * sizeof(unsigned char) * NUM_CHANNELS + * unsigned char* d_samples; // e.g., [(2, 6, 7, 5), (3, 0, 2, 1), (7, 0, 6, 2), (-, -, -, -), + * // (0, 6, 7, 5), (3, 0, 2, 6), (1, 1, 1, 1), (-, -, -, -)] + * int* d_histogram[3]; // e.g., three device pointers to three device buffers, + * // each allocated with 256 integer counters + * int num_levels[3]; // e.g., {257, 257, 257}; + * unsigned int lower_level[3]; // e.g., {0, 0, 0}; + * unsigned int upper_level[3]; // e.g., {256, 256, 256}; + * ... + * + * // Determine temporary device storage requirements + * void* d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceHistogram::MultiHistogramEven<4, 3>( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, lower_level, upper_level, + * num_row_pixels, num_rows, row_stride_bytes); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Compute histograms + * cub::DeviceHistogram::MultiHistogramEven<4, 3>( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, lower_level, upper_level, + * num_row_pixels, num_rows, row_stride_bytes); + * + * // d_histogram <-- [ [1, 1, 1, 2, 0, 0, 0, 1, 0, 0, 0, ..., 0], + * // [0, 4, 0, 0, 0, 0, 2, 0, 0, 0, 0, ..., 0], + * // [0, 1, 2, 0, 0, 0, 1, 2, 0, 0, 0, ..., 0] ] + * @endcode + * + * @tparam NUM_CHANNELS + * Number of channels interleaved in the input data (may be greater than + * the number of channels being actively histogrammed) + * + * @tparam NUM_ACTIVE_CHANNELS + * **[inferred]** Number of channels actively being histogrammed + * + * @tparam SampleIteratorT + * **[inferred]** Random-access input iterator type for reading input + * samples. \iterator + * + * @tparam CounterT + * **[inferred]** Integer type for histogram bin counters + * + * @tparam LevelT + * **[inferred]** Type for specifying boundaries (levels) + * + * @tparam OffsetT + * **[inferred]** Signed integer type for sequence offsets, list lengths, + * pointer differences, etc. \offset_size1 + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_samples + * The pointer to the multi-channel input sequence of data samples. The + * samples from different channels are assumed to be interleaved (e.g., + * an array of 32-bit pixels where each pixel consists of four + * *RGBA* 8-bit samples). + * + * @param[out] d_histogram + * The pointers to the histogram counter output arrays, one for each + * active channel. For channeli, the allocation length + * of `d_histogram[i]` should be `num_levels[i] - 1`. + * + * @param[in] num_levels + * The number of boundaries (levels) for delineating histogram samples in + * each active channel. Implies that the number of bins for + * channeli is `num_levels[i] - 1`. + * + * @param[in] lower_level + * The lower sample value bound (inclusive) for the lowest histogram bin in + * each active channel. + * + * @param[in] upper_level + * The upper sample value bound (exclusive) for the highest histogram bin + * in each active channel. + * + * @param[in] num_row_pixels + * The number of multi-channel pixels per row in the region of interest + * + * @param[in] num_rows + * The number of rows in the region of interest + * + * @param[in] row_stride_bytes + * The number of bytes between starts of consecutive rows in the region of + * interest + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + MultiHistogramEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram[NUM_ACTIVE_CHANNELS], + int num_levels[NUM_ACTIVE_CHANNELS], + LevelT lower_level[NUM_ACTIVE_CHANNELS], + LevelT upper_level[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + size_t row_stride_bytes, + cudaStream_t stream = 0) + { + /// The sample value type of the input iterator + using SampleT = cub::detail::value_t; + Int2Type is_byte_sample; + + if ((sizeof(OffsetT) > sizeof(int)) && + ((unsigned long long)(num_rows * row_stride_bytes) < + (unsigned long long)INT_MAX)) + { + // Down-convert OffsetT data type + return DispatchHistogram::DispatchEven(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + lower_level, + upper_level, + (int)num_row_pixels, + (int)num_rows, + (int)(row_stride_bytes / + sizeof(SampleT)), + stream, + is_byte_sample); + } + + return DispatchHistogram::DispatchEven(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + lower_level, + upper_level, + num_row_pixels, + num_rows, + (OffsetT)(row_stride_bytes / + sizeof(SampleT)), + stream, + is_byte_sample); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + MultiHistogramEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram[NUM_ACTIVE_CHANNELS], + int num_levels[NUM_ACTIVE_CHANNELS], + LevelT lower_level[NUM_ACTIVE_CHANNELS], + LevelT upper_level[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + size_t row_stride_bytes, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return MultiHistogramEven(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + lower_level, + upper_level, + num_row_pixels, + num_rows, + row_stride_bytes, + stream); + } + + //@} end member group + /******************************************************************//** + * @name Custom bin ranges + *********************************************************************/ + //@{ + + /** + * @brief Computes an intensity histogram from a sequence of data samples + * using the specified bin boundary levels. + * + * @par + * - The number of histogram bins is (`num_levels - 1`) + * - The value range for bini is `[level[i], level[i+1])` + * - The range `[d_histogram, d_histogram + num_levels - 1)` shall not + * overlap `[d_samples, d_samples + num_samples)` nor + * `[d_levels, d_levels + num_levels)` in any way. The ranges + * `[d_levels, d_levels + num_levels)` and + * `[d_samples, d_samples + num_samples)` may overlap. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the computation of an six-bin histogram + * from a sequence of float samples + * + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for input + * // samples and output histogram + * int num_samples; // e.g., 10 + * float* d_samples; // e.g., [2.2, 6.0, 7.1, 2.9, 3.5, 0.3, 2.9, 2.0, 6.1, 999.5] + * int* d_histogram; // e.g., [ -, -, -, -, -, -] + * int num_levels // e.g., 7 (seven level boundaries for six bins) + * float* d_levels; // e.g., [0.0, 2.0, 4.0, 6.0, 8.0, 12.0, 16.0] + * ... + * + * // Determine temporary device storage requirements + * void* d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceHistogram::HistogramRange( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, d_levels, num_samples); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Compute histograms + * cub::DeviceHistogram::HistogramRange( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, d_levels, num_samples); + * + * // d_histogram <-- [1, 5, 0, 3, 0, 0]; + * + * @endcode + * + * @tparam SampleIteratorT + * **[inferred]** Random-access input iterator type for reading + * input samples.\iterator + * + * @tparam CounterT + * **[inferred]** Integer type for histogram bin counters + * + * @tparam LevelT + * **[inferred]** Type for specifying boundaries (levels) + * + * @tparam OffsetT + * **[inferred]** Signed integer type for sequence offsets, list lengths, + * pointer differences, etc. \offset_size1 + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_samples + * The pointer to the input sequence of data samples. + * + * @param[out] d_histogram + * The pointer to the histogram counter output array of length + * `num_levels - 1`. + * + * @param[in] num_levels + * The number of boundaries (levels) for delineating histogram samples. + * Implies that the number of bins is `num_levels - 1`. + * + * @param[in] d_levels + * The pointer to the array of boundaries (levels). Bin ranges are defined + * by consecutive boundary pairings: lower sample value boundaries are + * inclusive and upper sample value boundaries are exclusive. + * + * @param[in] num_samples + * The number of data samples per row in the region of interest + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + HistogramRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram, + int num_levels, + LevelT *d_levels, + OffsetT num_samples, + cudaStream_t stream = 0) + { + /// The sample value type of the input iterator + using SampleT = cub::detail::value_t; + + CounterT *d_histogram1[1] = {d_histogram}; + int num_levels1[1] = {num_levels}; + LevelT *d_levels1[1] = {d_levels}; + + return MultiHistogramRange<1, 1>(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram1, + num_levels1, + d_levels1, + num_samples, + (OffsetT)1, + (size_t)(sizeof(SampleT) * num_samples), + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + HistogramRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram, + int num_levels, + LevelT *d_levels, + OffsetT num_samples, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return HistogramRange(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + d_levels, + num_samples, + stream); + } + + /** + * @brief Computes an intensity histogram from a sequence of data samples + * using the specified bin boundary levels. + * + * @par + * - A two-dimensional *region of interest* within `d_samples` can be + * specified using the `num_row_samples`, `num_rows`, and + * `row_stride_bytes` parameters. + * - The row stride must be a whole multiple of the sample data type + * size, i.e., `(row_stride_bytes % sizeof(SampleT)) == 0`. + * - The number of histogram bins is (`num_levels - 1`) + * - The value range for bini is `[level[i], level[i+1])` + * - For a given row `r` in `[0, num_rows)`, let + * `row_begin = d_samples + r * row_stride_bytes / sizeof(SampleT)` and + * `row_end = row_begin + num_row_samples`. The range + * `[d_histogram, d_histogram + num_levels - 1)` shall not overlap + * `[row_begin, row_end)` nor `[d_levels, d_levels + num_levels)`. + * The ranges `[d_levels, d_levels + num_levels)` and `[row_begin, row_end)` + * may overlap. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the computation of a six-bin histogram + * from a 2x5 region of interest within a flattened 2x7 array of float samples. + * + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for input samples and + * // output histogram + * int num_row_samples; // e.g., 5 + * int num_rows; // e.g., 2; + * int row_stride_bytes; // e.g., 7 * sizeof(float) + * float* d_samples; // e.g., [2.2, 6.0, 7.1, 2.9, 3.5, -, -, + * // 0.3, 2.9, 2.0, 6.1, 999.5, -, -] + * int* d_histogram; // e.g., [ -, -, -, -, -, -] + * int num_levels // e.g., 7 (seven level boundaries for six bins) + * float *d_levels; // e.g., [0.0, 2.0, 4.0, 6.0, 8.0, 12.0, 16.0] + * ... + * + * // Determine temporary device storage requirements + * void* d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceHistogram::HistogramRange( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, d_levels, + * num_row_samples, num_rows, row_stride_bytes); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Compute histograms + * cub::DeviceHistogram::HistogramRange( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, d_levels, + * num_row_samples, num_rows, row_stride_bytes); + * + * // d_histogram <-- [1, 5, 0, 3, 0, 0]; + * @endcode + * + * @tparam SampleIteratorT + * **[inferred]** Random-access input iterator type for reading + * input samples. \iterator + * + * @tparam CounterT + * **[inferred]** Integer type for histogram bin counters + * + * @tparam LevelT + * **[inferred]** Type for specifying boundaries (levels) + * + * @tparam OffsetT + * **[inferred]** Signed integer type for sequence offsets, list lengths, + * pointer differences, etc. \offset_size1 + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_samples + * The pointer to the input sequence of data samples. + * + * @param[out] d_histogram + * The pointer to the histogram counter output array of length + * `num_levels - 1`. + * + * @param[in] num_levels + * The number of boundaries (levels) for delineating histogram samples. + * Implies that the number of bins is `num_levels - 1`. + * + * @param[in] d_levels + * The pointer to the array of boundaries (levels). Bin ranges are defined + * by consecutive boundary pairings: lower sample value boundaries are + * inclusive and upper sample value boundaries are exclusive. + * + * @param[in] num_row_samples + * The number of data samples per row in the region of interest + * + * @param[in] num_rows + * The number of rows in the region of interest + * + * @param[in] row_stride_bytes + * The number of bytes between starts of consecutive rows in the region + * of interest + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + HistogramRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram, + int num_levels, + LevelT *d_levels, + OffsetT num_row_samples, + OffsetT num_rows, + size_t row_stride_bytes, + cudaStream_t stream = 0) + { + CounterT *d_histogram1[1] = {d_histogram}; + int num_levels1[1] = {num_levels}; + LevelT *d_levels1[1] = {d_levels}; + + return MultiHistogramRange<1, 1>(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram1, + num_levels1, + d_levels1, + num_row_samples, + num_rows, + row_stride_bytes, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + HistogramRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram, + int num_levels, + LevelT *d_levels, + OffsetT num_row_samples, + OffsetT num_rows, + size_t row_stride_bytes, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return HistogramRange(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + d_levels, + num_row_samples, + num_rows, + row_stride_bytes, + stream); + } + + /** + * @brief Computes per-channel intensity histograms from a sequence of + * multi-channel "pixel" data samples using the specified bin + * boundary levels. + * + * @par + * - The input is a sequence of *pixel* structures, where each pixel + * comprises a record of `NUM_CHANNELS` consecutive data samples + * (e.g., an *RGBA* pixel). + * - Of the `NUM_CHANNELS` specified, the function will only compute + * histograms for the first `NUM_ACTIVE_CHANNELS` (e.g., *RGB* histograms + * from *RGBA* pixel samples). + * - The number of histogram bins for channeli is + * `num_levels[i] - 1`. + * - For channeli, the range of values for all histogram + * bins have the same width: + * `(upper_level[i] - lower_level[i]) / (num_levels[i] - 1)` + * - For given channels `c1` and `c2` in `[0, NUM_ACTIVE_CHANNELS)`, the + * range `[d_histogram[c1], d_histogram[c1] + num_levels[c1] - 1)` shall + * not overlap `[d_samples, d_samples + NUM_CHANNELS * num_pixels)` nor + * `[d_levels[c2], d_levels[c2] + num_levels[c2])` in any way. + * The ranges `[d_levels[c2], d_levels[c2] + num_levels[c2])` and + * `[d_samples, d_samples + NUM_CHANNELS * num_pixels)` may overlap. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the computation of three 4-bin *RGB* + * histograms from a quad-channel sequence of *RGBA* pixels + * (8 bits per channel per pixel) + * + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input samples and output histograms + * int num_pixels; // e.g., 5 + * unsigned char *d_samples; // e.g., [(2, 6, 7, 5),(3, 0, 2, 1),(7, 0, 6, 2), + * // (0, 6, 7, 5),(3, 0, 2, 6)] + * unsigned int *d_histogram[3]; // e.g., [[ -, -, -, -],[ -, -, -, -],[ -, -, -, -]]; + * int num_levels[3]; // e.g., {5, 5, 5}; + * unsigned int *d_levels[3]; // e.g., [ [0, 2, 4, 6, 8], + * // [0, 2, 4, 6, 8], + * // [0, 2, 4, 6, 8] ]; + * ... + * + * // Determine temporary device storage requirements + * void* d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceHistogram::MultiHistogramRange<4, 3>( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, d_levels, num_pixels); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Compute histograms + * cub::DeviceHistogram::MultiHistogramRange<4, 3>( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, d_levels, num_pixels); + * + * // d_histogram <-- [ [1, 3, 0, 1], + * // [3, 0, 0, 2], + * // [0, 2, 0, 3] ] + * + * @endcode + * + * @tparam NUM_CHANNELS + * Number of channels interleaved in the input data (may be greater than + * the number of channels being actively histogrammed) + * + * @tparam NUM_ACTIVE_CHANNELS + * **[inferred]** Number of channels actively being histogrammed + * + * @tparam SampleIteratorT + * **[inferred]** Random-access input iterator type for reading + * input samples. \iterator + * + * @tparam CounterT + * **[inferred]** Integer type for histogram bin counters + * + * @tparam LevelT + * **[inferred]** Type for specifying boundaries (levels) + * + * @tparam OffsetT + * **[inferred]** Signed integer type for sequence offsets, list lengths, + * pointer differences, etc. \offset_size1 + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_samples + * The pointer to the multi-channel input sequence of data samples. + * The samples from different channels are assumed to be interleaved (e.g., + * an array of 32-bit pixels where each pixel consists of four *RGBA* + * 8-bit samples). + * + * @param[out] d_histogram + * The pointers to the histogram counter output arrays, one for each active + * channel. For channeli, the allocation length of + * `d_histogram[i]` should be `num_levels[i] - 1`. + * + * @param[in] num_levels + * The number of boundaries (levels) for delineating histogram samples in + * each active channel. Implies that the number of bins for + * channeli is `num_levels[i] - 1`. + * + * @param[in] d_levels + * The pointers to the arrays of boundaries (levels), one for each active + * channel. Bin ranges are defined by consecutive boundary pairings: lower + * sample value boundaries are inclusive and upper sample value boundaries + * are exclusive. + * + * @param[in] num_pixels + * The number of multi-channel pixels + * (i.e., the length of `d_samples / NUM_CHANNELS`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + MultiHistogramRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram[NUM_ACTIVE_CHANNELS], + int num_levels[NUM_ACTIVE_CHANNELS], + LevelT *d_levels[NUM_ACTIVE_CHANNELS], + OffsetT num_pixels, + cudaStream_t stream = 0) + { + /// The sample value type of the input iterator + using SampleT = cub::detail::value_t; + + return MultiHistogramRange( + d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + d_levels, + num_pixels, + (OffsetT)1, + (size_t)(sizeof(SampleT) * NUM_CHANNELS * num_pixels), + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + MultiHistogramRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram[NUM_ACTIVE_CHANNELS], + int num_levels[NUM_ACTIVE_CHANNELS], + LevelT *d_levels[NUM_ACTIVE_CHANNELS], + OffsetT num_pixels, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return MultiHistogramRange(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + d_levels, + num_pixels, + stream); + } + + /** + * @brief Computes per-channel intensity histograms from a sequence of + * multi-channel "pixel" data samples using the specified bin boundary + * levels. + * + * @par + * - The input is a sequence of *pixel* structures, where each pixel comprises + * a record of `NUM_CHANNELS` consecutive data samples + * (e.g., an *RGBA* pixel). + * - Of the `NUM_CHANNELS` specified, the function will only compute + * histograms for the first `NUM_ACTIVE_CHANNELS` (e.g., *RGB* histograms + * from *RGBA* pixel samples). + * - A two-dimensional *region of interest* within `d_samples` can be + * specified using the `num_row_samples`, `num_rows`, and `row_stride_bytes` + * parameters. + * - The row stride must be a whole multiple of the sample data type + * size, i.e., `(row_stride_bytes % sizeof(SampleT)) == 0`. + * - The number of histogram bins for channeli is + * `num_levels[i] - 1`. + * - For channeli, the range of values for all histogram + * bins have the same width: + * `(upper_level[i] - lower_level[i]) / (num_levels[i] - 1)` + * - For a given row `r` in `[0, num_rows)`, and sample `s` in + * `[0, num_row_pixels)`, let + * `row_begin = d_samples + r * row_stride_bytes / sizeof(SampleT)`, + * `sample_begin = row_begin + s * NUM_CHANNELS`, and + * `sample_end = sample_begin + NUM_ACTIVE_CHANNELS`. For given channels + * `c1` and `c2` in `[0, NUM_ACTIVE_CHANNELS)`, the range + * `[d_histogram[c1], d_histogram[c1] + num_levels[c1] - 1)` shall not + * overlap `[sample_begin, sample_end)` nor + * `[d_levels[c2], d_levels[c2] + num_levels[c2])` in any way. The ranges + * `[d_levels[c2], d_levels[c2] + num_levels[c2])` and + * `[sample_begin, sample_end)` may overlap. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the computation of three 4-bin *RGB* + * histograms from a 2x3 region of interest of within a flattened 2x4 array + * of quad-channel *RGBA* pixels (8 bits per channel per pixel). + * + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for input + * // samples and output histograms + * int num_row_pixels; // e.g., 3 + * int num_rows; // e.g., 2 + * size_t row_stride_bytes; // e.g., 4 * sizeof(unsigned char) * NUM_CHANNELS + * unsigned char* d_samples; // e.g., [(2, 6, 7, 5),(3, 0, 2, 1),(1, 1, 1, 1),(-, -, -, -), + * // (7, 0, 6, 2),(0, 6, 7, 5),(3, 0, 2, 6),(-, -, -, -)] + * int* d_histogram[3]; // e.g., [[ -, -, -, -],[ -, -, -, -],[ -, -, -, -]]; + * int num_levels[3]; // e.g., {5, 5, 5}; + * unsigned int* d_levels[3]; // e.g., [ [0, 2, 4, 6, 8], + * // [0, 2, 4, 6, 8], + * // [0, 2, 4, 6, 8] ]; + * ... + * + * // Determine temporary device storage requirements + * void* d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceHistogram::MultiHistogramRange<4, 3>( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, d_levels, + * num_row_pixels, num_rows, row_stride_bytes); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Compute histograms + * cub::DeviceHistogram::MultiHistogramRange<4, 3>( + * d_temp_storage, temp_storage_bytes, + * d_samples, d_histogram, num_levels, + * d_levels, num_row_pixels, num_rows, row_stride_bytes); + * + * // d_histogram <-- [ [2, 3, 0, 1], + * // [3, 0, 0, 2], + * // [1, 2, 0, 3] ] + * + * @endcode + * + * @tparam NUM_CHANNELS + * Number of channels interleaved in the input data (may be greater than + * the number of channels being actively histogrammed) + * + * @tparam NUM_ACTIVE_CHANNELS + * **[inferred]** Number of channels actively being histogrammed + * + * @tparam SampleIteratorT + * **[inferred]** Random-access input iterator type for reading input + * samples. \iterator + * + * @tparam CounterT + * **[inferred]** Integer type for histogram bin counters + * + * @tparam LevelT + * **[inferred]** Type for specifying boundaries (levels) + * + * @tparam OffsetT + * **[inferred]** Signed integer type for sequence offsets, list lengths, + * pointer differences, etc. \offset_size1 + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to \p temp_storage_bytes and no work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_samples + * The pointer to the multi-channel input sequence of data samples. The + * samples from different channels are assumed to be interleaved (e.g., an + * array of 32-bit pixels where each pixel consists of four + * *RGBA* 8-bit samples). + * + * @param[out] d_histogram + * The pointers to the histogram counter output arrays, one for each active + * channel. For channeli, the allocation length of + * `d_histogram[i]` should be `num_levels[i] - 1`. + * + * @param[in] num_levels + * The number of boundaries (levels) for delineating histogram samples in + * each active channel. Implies that the number of bins for + * channeli is `num_levels[i] - 1`. + * + * @param[in] d_levels + * The pointers to the arrays of boundaries (levels), one for each active + * channel. Bin ranges are defined by consecutive boundary pairings: lower + * sample value boundaries are inclusive and upper sample value boundaries + * are exclusive. + * + * @param[in] num_row_pixels + * The number of multi-channel pixels per row in the region of interest + * + * @param[in] num_rows + * The number of rows in the region of interest + * + * @param[in] row_stride_bytes + * The number of bytes between starts of consecutive rows in the + * region of interest + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + MultiHistogramRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram[NUM_ACTIVE_CHANNELS], + int num_levels[NUM_ACTIVE_CHANNELS], + LevelT *d_levels[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + size_t row_stride_bytes, + cudaStream_t stream = 0) + { + /// The sample value type of the input iterator + using SampleT = cub::detail::value_t; + Int2Type is_byte_sample; + + if ((sizeof(OffsetT) > sizeof(int)) && + ((unsigned long long)(num_rows * row_stride_bytes) < + (unsigned long long)INT_MAX)) + { + // Down-convert OffsetT data type + return DispatchHistogram::DispatchRange(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + d_levels, + (int)num_row_pixels, + (int)num_rows, + (int)(row_stride_bytes / + sizeof(SampleT)), + stream, + is_byte_sample); + } + + return DispatchHistogram::DispatchRange(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + d_levels, + num_row_pixels, + num_rows, + (OffsetT)(row_stride_bytes / + sizeof(SampleT)), + stream, + is_byte_sample); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + MultiHistogramRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_histogram[NUM_ACTIVE_CHANNELS], + int num_levels[NUM_ACTIVE_CHANNELS], + LevelT *d_levels[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + size_t row_stride_bytes, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return MultiHistogramRange(d_temp_storage, + temp_storage_bytes, + d_samples, + d_histogram, + num_levels, + d_levels, + num_row_pixels, + num_rows, + row_stride_bytes, + stream); + } + + //@} end member group +}; + +CUB_NAMESPACE_END + + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_memcpy.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_memcpy.cuh new file mode 100644 index 0000000000000000000000000000000000000000..a0f8fe5415f13b554a2fb5cc784e556a95e6bc53 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_memcpy.cuh @@ -0,0 +1,179 @@ +/****************************************************************************** + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::DeviceMemcpy provides device-wide, parallel operations for copying data. + */ + +#pragma once + +#include +#include + +#include +#include + +CUB_NAMESPACE_BEGIN + +/** + * @brief cub::DeviceMemcpy provides device-wide, parallel operations for copying data. + * \ingroup SingleModule + */ +struct DeviceMemcpy +{ + /** + * @brief Copies data from a batch of given source buffers to their corresponding destination + * buffer. + * @note If any input buffer aliases memory from any output buffer the behavior is undefined. If + * any output buffer aliases memory of another output buffer the behavior is undefined. Input + * buffers can alias one another. + * + * @par Snippet + * The code snippet below illustrates usage of DeviceMemcpy::Batched for mutating strings withing + * a single string buffer. + * @par + * @code + * struct GetPtrToStringItem + * { + * __host__ __device__ __forceinline__ void *operator()(uint32_t index) + * { + * return &d_string_data_in[d_string_offsets[index]]; + * } + * char *d_string_data_in; + * uint32_t *d_string_offsets; + * }; + * + * struct GetStringItemSize + * { + * __host__ __device__ __forceinline__ uint32_t operator()(uint32_t index) + * { + * return d_string_offsets[index + 1] - d_string_offsets[index]; + * } + * uint32_t *d_string_offsets; + * }; + * + * uint32_t num_strings = 5; + * char *d_string_data_in; // e.g., "TomatoesBananasApplesOrangesGrapes" + * char *d_string_data_out; // e.g., " ... " + * uint32_t *d_string_offsets_old; // e.g., [0, 8, 15, 21, 28, 34] + * uint32_t *d_string_offsets_new; // e.g., [0, 6, 13, 19, 26, 34] + * uint32_t *d_gather_index; // e.g., [2, 1, 4, 3, 0] + * + * // Initialize an iterator that returns d_gather_index[i] when the i-th item is dereferenced + * auto gather_iterator = thrust::make_permutation_iterator(thrust::make_counting_iterator(0), + * d_gather_index); + * + * // Returns pointers to the input buffer for each string + * auto str_ptrs_in = thrust::make_transform_iterator(gather_iterator, + * GetPtrToStringItem{d_string_data_in, + * d_string_offsets_old}); + * + * // Returns the string size of the i-th string + * auto str_sizes = thrust::make_transform_iterator(gather_iterator, + * GetStringItemSize{d_string_offsets_old}); + * + * // Returns pointers to the output buffer for each string + * auto str_ptrs_out = thrust::make_transform_iterator(thrust::make_counting_iterator(0), + * GetPtrToStringItem{d_string_data_out, + * d_string_offsets_new}); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * size_t temp_storage_bytes = 0; + * cub::DeviceMemcpy::Batched(d_temp_storage, temp_storage_bytes, str_ptrs_in, str_ptrs_out, + * str_sizes, num_strings); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run batched copy algorithm (used to permute strings) + * cub::DeviceMemcpy::Batched(d_temp_storage, temp_storage_bytes, str_ptrs_in, str_ptrs_out, + * str_sizes, num_strings); + * + * // d_string_data_out <-- "ApplesBananasGrapesOrangesTomatoe" + * @endcode + * @tparam InputBufferIt [inferred] Device-accessible random-access input iterator type + * providing the pointers to the source memory buffers + * @tparam OutputBufferIt [inferred] Device-accessible random-access input iterator type + * providing the pointers to the destination memory buffers + * @tparam BufferSizeIteratorT [inferred] Device-accessible random-access input iterator + * type providing the number of bytes to be copied for each pair of buffers + * @param d_temp_storage [in] Device-accessible allocation of temporary storage. When NULL, the + * required allocation size is written to \p temp_storage_bytes and no work is done. + * @param temp_storage_bytes [in,out] Reference to size in bytes of \p d_temp_storage allocation + * @param input_buffer_it [in] Device-accessible iterator providing the pointers to the source + * memory buffers + * @param output_buffer_it [in] Device-accessible iterator providing the pointers to the + * destination memory buffers + * @param buffer_sizes [in] Device-accessible iterator providing the number of bytes to be copied + * for each pair of buffers + * @param num_buffers [in] The total number of buffer pairs + * @param stream [in] [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t Batched(void *d_temp_storage, + size_t &temp_storage_bytes, + InputBufferIt input_buffer_it, + OutputBufferIt output_buffer_it, + BufferSizeIteratorT buffer_sizes, + uint32_t num_buffers, + cudaStream_t stream = 0) + { + static_assert(std::is_pointer>::value, + "DeviceMemcpy::Batched only supports copying of memory buffers." + "Please consider using DeviceCopy::Batched instead."); + static_assert(std::is_pointer>::value, + "DeviceMemcpy::Batched only supports copying of memory buffers." + "Please consider using DeviceCopy::Batched instead."); + + // Integer type large enough to hold any offset in [0, num_buffers) + using BufferOffsetT = uint32_t; + + // Integer type large enough to hold any offset in [0, num_thread_blocks_launched), where a safe + // uppper bound on num_thread_blocks_launched can be assumed to be given by + // IDIV_CEIL(num_buffers, 64) + using BlockOffsetT = uint32_t; + + return detail::DispatchBatchMemcpy, + true>::Dispatch(d_temp_storage, + temp_storage_bytes, + input_buffer_it, + output_buffer_it, + buffer_sizes, + num_buffers, + stream); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_merge_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_merge_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..9b17ac391257d937b05fc00c2a9eec14411a8f2b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_merge_sort.cuh @@ -0,0 +1,1118 @@ +/****************************************************************************** + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * @brief DeviceMergeSort provides device-wide, parallel operations for + * computing a merge sort across a sequence of data items residing within + * device-accessible memory. + * + * @ingroup SingleModule + * + * @par Overview + * - DeviceMergeSort arranges items into ascending order using a comparison + * functor with less-than semantics. Merge sort can handle arbitrary types (as + * long as a value of these types is a model of [LessThan Comparable]) and + * comparison functors, but is slower than DeviceRadixSort when sorting + * arithmetic types into ascending/descending order. + * - Another difference from RadixSort is the fact that DeviceMergeSort can + * handle arbitrary random-access iterators, as shown below. + * + * @par A Simple Example + * @par + * The code snippet below illustrates a thrust reverse iterator usage. + * @par + * @code + * #include // or equivalently + * + * struct CustomLess + * { + * template + * __device__ bool operator()(const DataType &lhs, const DataType &rhs) + * { + * return lhs < rhs; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * thrust::device_vector d_keys(num_items); + * thrust::device_vector d_values(num_items); + * // ... + * + * // Initialize iterator + * using KeyIterator = typename thrust::device_vector::iterator; + * thrust::reverse_iterator reverse_iter(d_keys.end()); + * + * // Determine temporary device storage requirements + * std::size_t temp_storage_bytes = 0; + * cub::DeviceMergeSort::SortPairs( + * nullptr, + * temp_storage_bytes, + * reverse_iter, + * thrust::raw_pointer_cast(d_values.data()), + * num_items, + * CustomLess()); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceMergeSort::SortPairs( + * d_temp_storage, + * temp_storage_bytes, + * reverse_iter, + * thrust::raw_pointer_cast(d_values.data()), + * num_items, + * CustomLess()); + * @endcode + * + * [LessThan Comparable]: https://en.cppreference.com/w/cpp/named_req/LessThanComparable + */ +struct DeviceMergeSort +{ + + /** + * @brief Sorts items using a merge sorting method. + * + * @par + * SortPairs is not guaranteed to be stable. That is, suppose that i and j are + * equivalent: neither one is less than the other. It is not guaranteed + * that the relative order of these two elements will be preserved by sort. + * + * @par Snippet + * The code snippet below illustrates the sorting of a device vector of `int` + * keys with associated vector of `int` values. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // sorting data + * int num_items; // e.g., 7 + * int *d_keys; // e.g., [8, 6, 6, 5, 3, 0, 9] + * int *d_values; // e.g., [0, 1, 2, 3, 4, 5, 6] + * ... + * + * // Initialize comparator + * CustomOpT custom_op; + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * std::size_t temp_storage_bytes = 0; + * cub::DeviceMergeSort::SortPairs( + * d_temp_storage, temp_storage_bytes, + * d_keys, d_values, num_items, custom_op); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceMergeSort::SortPairs( + * d_temp_storage, temp_storage_bytes, + * d_keys, d_values, num_items, custom_op); + * + * // d_keys <-- [0, 3, 5, 6, 6, 8, 9] + * // d_values <-- [5, 4, 3, 2, 1, 0, 6] + * + * @endcode + * + * @tparam KeyIteratorT + * is a model of [Random Access Iterator]. `KeyIteratorT` is mutable, and + * its `value_type` is a model of [LessThan Comparable]. This `value_type`'s + * ordering relation is a *strict weak ordering* as defined in + * the [LessThan Comparable] requirements. + * + * @tparam ValueIteratorT + * is a model of [Random Access Iterator], and `ValueIteratorT` is mutable. + * + * @tparam OffsetT + * is an integer type for global offsets. + * + * @tparam CompareOpT + * is a type of callable object with the signature + * `bool operator()(KeyT lhs, KeyT rhs)` that models + * the [Strict Weak Ordering] concept. + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_keys + * Pointer to the input sequence of unsorted input keys + * + * @param[in,out] d_items + * Pointer to the input sequence of unsorted input values + * + * @param[in] num_items + * Number of items to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. Default is + * stream0. + * + * [Random Access Iterator]: https://en.cppreference.com/w/cpp/iterator/random_access_iterator + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + * [LessThan Comparable]: https://en.cppreference.com/w/cpp/named_req/LessThanComparable + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyIteratorT d_keys, + ValueIteratorT d_items, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream = 0) + { + using DispatchMergeSortT = DispatchMergeSort; + + return DispatchMergeSortT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_items, + d_keys, + d_items, + num_items, + compare_op, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyIteratorT d_keys, + ValueIteratorT d_items, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairs( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_items, + num_items, + compare_op, + stream); + } + + /** + * @brief Sorts items using a merge sorting method. + * + * @par + * - SortPairsCopy is not guaranteed to be stable. That is, suppose + * that `i` and `j` are equivalent: neither one is less than the + * other. It is not guaranteed that the relative order of these + * two elements will be preserved by sort. + * - Input arrays `d_input_keys` and `d_input_items` are not modified. + * - Note that the behavior is undefined if the input and output ranges + * overlap in any way. + * + * @par Snippet + * The code snippet below illustrates the sorting of a device vector of + * `int` keys with associated vector of `int` values. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int *d_keys; // e.g., [8, 6, 6, 5, 3, 0, 9] + * int *d_values; // e.g., [0, 1, 2, 3, 4, 5, 6] + * ... + * + * // Initialize comparator + * CustomOpT custom_op; + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * std::size_t temp_storage_bytes = 0; + * cub::DeviceMergeSort::SortPairsCopy( + * d_temp_storage, temp_storage_bytes, + * d_keys, d_values, num_items, custom_op); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceMergeSort::SortPairsCopy( + * d_temp_storage, temp_storage_bytes, + * d_keys, d_values, num_items, custom_op); + * + * // d_keys <-- [0, 3, 5, 6, 6, 8, 9] + * // d_values <-- [5, 4, 3, 2, 1, 0, 6] + * + * @endcode + * + * @tparam KeyInputIteratorT + * is a model of [Random Access Iterator]. Its `value_type` is a model of + * [LessThan Comparable]. This `value_type`'s ordering relation is a + * *strict weak ordering* as defined in the [LessThan Comparable] + * requirements. + * + * @tparam ValueInputIteratorT + * is a model of [Random Access Iterator]. + * + * @tparam KeyIteratorT + * is a model of [Random Access Iterator]. `KeyIteratorT` is mutable, and + * its `value_type` is a model of [LessThan Comparable]. This `value_type`'s + * ordering relation is a *strict weak ordering* as defined in + * the [LessThan Comparable] requirements. + * + * @tparam ValueIteratorT + * is a model of [Random Access Iterator], and `ValueIteratorT` is mutable. + * + * @tparam OffsetT + * is an integer type for global offsets. + * + * @tparam CompareOpT + * is a type of callable object with the signature + * `bool operator()(KeyT lhs, KeyT rhs)` that models + * the [Strict Weak Ordering] concept. + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_input_keys + * Pointer to the input sequence of unsorted input keys + * + * @param[in] d_input_items + * Pointer to the input sequence of unsorted input values + * + * @param[out] d_output_keys + * Pointer to the output sequence of sorted input keys + * + * @param[out] d_output_items + * Pointer to the output sequence of sorted input values + * + * @param[in] num_items + * Number of items to sort + * + * @param[in] compare_op + * Comparison function object which returns `true` if the first argument is + * ordered before the second + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. Default is + * stream0. + * + * [Random Access Iterator]: https://en.cppreference.com/w/cpp/iterator/random_access_iterator + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + * [LessThan Comparable]: https://en.cppreference.com/w/cpp/named_req/LessThanComparable + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsCopy(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyInputIteratorT d_input_keys, + ValueInputIteratorT d_input_items, + KeyIteratorT d_output_keys, + ValueIteratorT d_output_items, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream = 0) + { + using DispatchMergeSortT = DispatchMergeSort; + + return DispatchMergeSortT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_input_keys, + d_input_items, + d_output_keys, + d_output_items, + num_items, + compare_op, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsCopy(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyInputIteratorT d_input_keys, + ValueInputIteratorT d_input_items, + KeyIteratorT d_output_keys, + ValueIteratorT d_output_items, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairsCopy(d_temp_storage, + temp_storage_bytes, + d_input_keys, + d_input_items, + d_output_keys, + d_output_items, + num_items, + compare_op, + stream); + } + + /** + * @brief Sorts items using a merge sorting method. + * + * @par + * SortKeys is not guaranteed to be stable. That is, suppose that `i` and `j` + * are equivalent: neither one is less than the other. It is not guaranteed + * that the relative order of these two elements will be preserved by sort. + * + * @par Snippet + * The code snippet below illustrates the sorting of a device vector of `int` + * keys. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int *d_keys; // e.g., [8, 6, 7, 5, 3, 0, 9] + * ... + * + * // Initialize comparator + * CustomOpT custom_op; + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * std::size_t temp_storage_bytes = 0; + * cub::DeviceMergeSort::SortKeys( + * d_temp_storage, temp_storage_bytes, + * d_keys, num_items, custom_op); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceMergeSort::SortKeys( + * d_temp_storage, temp_storage_bytes, + * d_keys, num_items, custom_op); + * + * // d_keys <-- [0, 3, 5, 6, 7, 8, 9] + * @endcode + * + * @tparam KeyIteratorT + * is a model of [Random Access Iterator]. `KeyIteratorT` is mutable, and + * its `value_type` is a model of [LessThan Comparable]. This `value_type`'s + * ordering relation is a *strict weak ordering* as defined in + * the [LessThan Comparable] requirements. + * + * @tparam OffsetT + * is an integer type for global offsets. + * + * @tparam CompareOpT + * is a type of callable object with the signature + * `bool operator()(KeyT lhs, KeyT rhs)` that models + * the [Strict Weak Ordering] concept. + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_keys + * Pointer to the input sequence of unsorted input keys + * + * @param[in] num_items + * Number of items to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. Default is + * stream0. + * + * [Random Access Iterator]: https://en.cppreference.com/w/cpp/iterator/random_access_iterator + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + * [LessThan Comparable]: https://en.cppreference.com/w/cpp/named_req/LessThanComparable + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyIteratorT d_keys, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream = 0) + { + using DispatchMergeSortT = DispatchMergeSort; + + return DispatchMergeSortT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + static_cast(nullptr), + d_keys, + static_cast(nullptr), + num_items, + compare_op, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyIteratorT d_keys, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeys(d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + compare_op, + stream); + } + + /** + * @brief Sorts items using a merge sorting method. + * + * @par + * - SortKeysCopy is not guaranteed to be stable. That is, suppose that `i` + * and `j` are equivalent: neither one is less than the other. It is not + * guaranteed that the relative order of these two elements will be + * preserved by sort. + * - Input array d_input_keys is not modified. + * - Note that the behavior is undefined if the input and output ranges + * overlap in any way. + * + * @par Snippet + * The code snippet below illustrates the sorting of a device vector of + * `int` keys. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // sorting data + * int num_items; // e.g., 7 + * int *d_keys; // e.g., [8, 6, 7, 5, 3, 0, 9] + * ... + * + * // Initialize comparator + * CustomOpT custom_op; + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * std::size_t temp_storage_bytes = 0; + * cub::DeviceMergeSort::SortKeysCopy( + * d_temp_storage, temp_storage_bytes, + * d_keys, num_items, custom_op); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceMergeSort::SortKeysCopy( + * d_temp_storage, temp_storage_bytes, + * d_keys, num_items, custom_op); + * + * // d_keys <-- [0, 3, 5, 6, 7, 8, 9] + * @endcode + * + * @tparam KeyInputIteratorT + * is a model of [Random Access Iterator]. Its `value_type` is a model of + * [LessThan Comparable]. This `value_type`'s ordering relation is a + * *strict weak ordering* as defined in the [LessThan Comparable] + * requirements. + * + * @tparam KeyIteratorT + * is a model of [Random Access Iterator]. `KeyIteratorT` is mutable, and + * its `value_type` is a model of [LessThan Comparable]. This `value_type`'s + * ordering relation is a *strict weak ordering* as defined in + * the [LessThan Comparable] requirements. + * + * @tparam OffsetT + * is an integer type for global offsets. + * + * @tparam CompareOpT + * is a type of callable object with the signature + * `bool operator()(KeyT lhs, KeyT rhs)` that models + * the [Strict Weak Ordering] concept. + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_input_keys + * Pointer to the input sequence of unsorted input keys + * + * @param[out] d_output_keys + * Pointer to the output sequence of sorted input keys + * + * @param[in] num_items + * Number of items to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. Default is + * stream0. + * + * [Random Access Iterator]: https://en.cppreference.com/w/cpp/iterator/random_access_iterator + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + * [LessThan Comparable]: https://en.cppreference.com/w/cpp/named_req/LessThanComparable + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysCopy(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyInputIteratorT d_input_keys, + KeyIteratorT d_output_keys, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream = 0) + { + using DispatchMergeSortT = DispatchMergeSort; + + return DispatchMergeSortT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_input_keys, + static_cast(nullptr), + d_output_keys, + static_cast(nullptr), + num_items, + compare_op, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysCopy(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyInputIteratorT d_input_keys, + KeyIteratorT d_output_keys, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeysCopy( + d_temp_storage, + temp_storage_bytes, + d_input_keys, + d_output_keys, + num_items, + compare_op, + stream); + } + + /** + * @brief Sorts items using a merge sorting method. + * + * @par + * StableSortPairs is stable: it preserves the relative ordering of equivalent + * elements. That is, if x and y are elements such that x precedes y, + * and if the two elements are equivalent (neither x < y nor y < x) then + * a postcondition of stable_sort is that x still precedes y. + * + * @par Snippet + * The code snippet below illustrates the sorting of a device vector of `int` + * keys with associated vector of `int` values. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // sorting data + * int num_items; // e.g., 7 + * int *d_keys; // e.g., [8, 6, 6, 5, 3, 0, 9] + * int *d_values; // e.g., [0, 1, 2, 3, 4, 5, 6] + * ... + * + * // Initialize comparator + * CustomOpT custom_op; + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * std::size_t temp_storage_bytes = 0; + * cub::DeviceMergeSort::StableSortPairs( + * d_temp_storage, temp_storage_bytes, + * d_keys, d_values, num_items, custom_op); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceMergeSort::StableSortPairs( + * d_temp_storage, temp_storage_bytes, + * d_keys, d_values, num_items, custom_op); + * + * // d_keys <-- [0, 3, 5, 6, 6, 8, 9] + * // d_values <-- [5, 4, 3, 1, 2, 0, 6] + * @endcode + * + * @tparam KeyIteratorT + * is a model of [Random Access Iterator]. `KeyIteratorT` is mutable, and + * its `value_type` is a model of [LessThan Comparable]. This `value_type`'s + * ordering relation is a *strict weak ordering* as defined in + * the [LessThan Comparable] requirements. + * + * @tparam ValueIteratorT + * is a model of [Random Access Iterator], and `ValueIteratorT` is mutable. + * + * @tparam OffsetT + * is an integer type for global offsets. + * + * @tparam CompareOpT + * is a type of callable object with the signature + * `bool operator()(KeyT lhs, KeyT rhs)` that models + * the [Strict Weak Ordering] concept. + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_keys + * Pointer to the input sequence of unsorted input keys + * + * @param[in,out] d_items + * Pointer to the input sequence of unsorted input values + * + * @param[in] num_items + * Number of items to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. Default is + * stream0. + * + * [Random Access Iterator]: https://en.cppreference.com/w/cpp/iterator/random_access_iterator + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + * [LessThan Comparable]: https://en.cppreference.com/w/cpp/named_req/LessThanComparable + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyIteratorT d_keys, + ValueIteratorT d_items, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream = 0) + { + return SortPairs( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_items, + num_items, + compare_op, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyIteratorT d_keys, + ValueIteratorT d_items, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return StableSortPairs( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_items, + num_items, + compare_op, + stream); + } + + /** + * @brief Sorts items using a merge sorting method. + * + * @par + * StableSortKeys is stable: it preserves the relative ordering of equivalent + * elements. That is, if `x` and `y` are elements such that `x` precedes `y`, + * and if the two elements are equivalent (neither `x < y` nor `y < x`) then + * a postcondition of stable_sort is that `x` still precedes `y`. + * + * @par Snippet + * The code snippet below illustrates the sorting of a device vector of `int` + * keys. + * \par + * \code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // sorting data + * int num_items; // e.g., 7 + * int *d_keys; // e.g., [8, 6, 7, 5, 3, 0, 9] + * ... + * + * // Initialize comparator + * CustomOpT custom_op; + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * std::size_t temp_storage_bytes = 0; + * cub::DeviceMergeSort::StableSortKeys( + * d_temp_storage, temp_storage_bytes, + * d_keys, num_items, custom_op); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceMergeSort::StableSortKeys( + * d_temp_storage, temp_storage_bytes, + * d_keys, num_items, custom_op); + * + * // d_keys <-- [0, 3, 5, 6, 7, 8, 9] + * @endcode + * + * @tparam KeyIteratorT + * is a model of [Random Access Iterator]. `KeyIteratorT` is mutable, and + * its `value_type` is a model of [LessThan Comparable]. This `value_type`'s + * ordering relation is a *strict weak ordering* as defined in + * the [LessThan Comparable] requirements. + * + * @tparam OffsetT + * is an integer type for global offsets. + * + * @tparam CompareOpT + * is a type of callable object with the signature + * `bool operator()(KeyT lhs, KeyT rhs)` that models + * the [Strict Weak Ordering] concept. + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_keys + * Pointer to the input sequence of unsorted input keys + * + * @param[in] num_items + * Number of items to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. Default is + * stream0. + * + * [Random Access Iterator]: https://en.cppreference.com/w/cpp/iterator/random_access_iterator + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + * [LessThan Comparable]: https://en.cppreference.com/w/cpp/named_req/LessThanComparable + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyIteratorT d_keys, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream = 0) + { + return SortKeys(d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + compare_op, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyIteratorT d_keys, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return StableSortKeys(d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + compare_op, + stream); + } + + /** + * @brief Sorts items using a merge sorting method. + * + * @par + * - StableSortKeysCopy is stable: it preserves the relative ordering of equivalent + * elements. That is, if `x` and `y` are elements such that `x` precedes `y`, + * and if the two elements are equivalent (neither `x < y` nor `y < x`) then + * a postcondition of stable_sort is that `x` still precedes `y`. + * - Input array d_input_keys is not modified + * - Note that the behavior is undefined if the input and output ranges overlap + * in any way. + * + * @par Snippet + * The code snippet below illustrates the sorting of a device vector of `int` + * keys. + * \par + * \code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // sorting data + * int num_items; // e.g., 7 + * int *d_input_keys; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_output_keys; // must hold at least num_items elements + * ... + * + * // Initialize comparator + * CustomOpT custom_op; + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * std::size_t temp_storage_bytes = 0; + * cub::DeviceMergeSort::StableSortKeysCopy( + * d_temp_storage, temp_storage_bytes, + * d_input_keys, d_output_keys, num_items, custom_op); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceMergeSort::StableSortKeysCopy( + * d_temp_storage, temp_storage_bytes, + * d_input_keys, d_output_keys, num_items, custom_op); + * + * // d_output_keys <-- [0, 3, 5, 6, 7, 8, 9] + * @endcode + * + * @tparam KeyInputIteratorT + * is a model of [Random Access Iterator]. Its `value_type` is a model of + * [LessThan Comparable]. This `value_type`'s ordering relation is a + * *strict weak ordering* as defined in the [LessThan Comparable] + * requirements. + * + * @tparam KeyIteratorT + * is a model of [Random Access Iterator]. `KeyIteratorT` is mutable, and + * its `value_type` is a model of [LessThan Comparable]. This `value_type`'s + * ordering relation is a *strict weak ordering* as defined in + * the [LessThan Comparable] requirements. + * + * @tparam OffsetT + * is an integer type for global offsets. + * + * @tparam CompareOpT + * is a type of callable object with the signature + * `bool operator()(KeyT lhs, KeyT rhs)` that models + * the [Strict Weak Ordering] concept. + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_input_keys + * Pointer to the input sequence of unsorted input keys + * + * @param[out] d_output_keys + * Pointer to the output sequence of sorted input keys + * + * @param[in] num_items + * Number of elements in d_input_keys to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. Default is + * stream0. + * + * [Random Access Iterator]: https://en.cppreference.com/w/cpp/iterator/random_access_iterator + * [Strict Weak Ordering]: https://en.cppreference.com/w/cpp/concepts/strict_weak_order + * [LessThan Comparable]: https://en.cppreference.com/w/cpp/named_req/LessThanComparable + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortKeysCopy(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyInputIteratorT d_input_keys, + KeyIteratorT d_output_keys, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream = 0) + { + return SortKeysCopy(d_temp_storage, + temp_storage_bytes, + d_input_keys, + d_output_keys, + num_items, + compare_op, + stream); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_partition.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_partition.cuh new file mode 100644 index 0000000000000000000000000000000000000000..6692a489b20bb9eb302abdbe28efe026add24e4d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_partition.cuh @@ -0,0 +1,717 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file + * cub::DevicePartition provides device-wide, parallel operations for + * partitioning sequences of data items residing within device-accessible memory. + */ + +#pragma once + +#include +#include + +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * @brief DevicePartition provides device-wide, parallel operations for + * partitioning sequences of data items residing within device-accessible + * memory. ![](partition_logo.png) + * @ingroup SingleModule + * + * @par Overview + * These operations apply a selection criterion to construct a partitioned + * output sequence from items selected/unselected from a specified input + * sequence. + * + * @par Usage Considerations + * \cdp_class{DevicePartition} + * + * @par Performance + * \linear_performance{partition} + * + * @par + * The following chart illustrates DevicePartition::If + * performance across different CUDA architectures for @p int32 items, + * where 50% of the items are randomly selected for the first partition. + * \plots_below + * + * @image html partition_if_int32_50_percent.png + * + */ +struct DevicePartition +{ + /** + * @brief Uses the @p d_flags sequence to split the corresponding items from + * @p d_in into a partitioned sequence @p d_out. The total number of + * items copied into the first partition is written to + * @p d_num_selected_out. ![](partition_flags_logo.png) + * + * @par + * - The value type of @p d_flags must be castable to @p bool (e.g., + * @p bool, @p char, @p int, etc.). + * - Copies of the selected items are compacted into @p d_out and maintain + * their original relative ordering, however copies of the unselected + * items are compacted into the rear of @p d_out in reverse order. + * - The range `[d_out, d_out + num_items)` shall not overlap + * `[d_in, d_in + num_items)` nor `[d_flags, d_flags + num_items)` in any + * way. The range `[d_in, d_in + num_items)` may overlap + * `[d_flags, d_flags + num_items)`. + * - \devicestorage + * + * @par Snippet + * The code snippet below illustrates the compaction of items selected from + * an @p int device vector. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input, flags, and output + * int num_items; // e.g., 8 + * int *d_in; // e.g., [1, 2, 3, 4, 5, 6, 7, 8] + * char *d_flags; // e.g., [1, 0, 0, 1, 0, 1, 1, 0] + * int *d_out; // e.g., [ , , , , , , , ] + * int *d_num_selected_out; // e.g., [ ] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * std::size_t temp_storage_bytes = 0; + * cub::DevicePartition::Flagged( + * d_temp_storage, temp_storage_bytes, + * d_in, d_flags, d_out, d_num_selected_out, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run selection + * cub::DevicePartition::Flagged( + * d_temp_storage, temp_storage_bytes, + * d_in, d_flags, d_out, d_num_selected_out, num_items); + * + * // d_out <-- [1, 4, 6, 7, 8, 5, 3, 2] + * // d_num_selected_out <-- [4] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading + * input items \iterator + * + * @tparam FlagIterator + * **[inferred]** Random-access input iterator type for reading + * selection flags \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Random-access output iterator type for writing + * output items \iterator + * + * @tparam NumSelectedIteratorT + * **[inferred]** Output iterator type for recording the number + * of items selected \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to @p temp_storage_bytes and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[in] d_flags + * Pointer to the input sequence of selection flags + * + * @param[out] d_out + * Pointer to the output sequence of partitioned data items + * + * @param[out] d_num_selected_out + * Pointer to the output total number of items selected (i.e., the + * offset of the unselected partition) + * + * @param[in] num_items + * Total number of items to select from + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Flagged(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + FlagIterator d_flags, + OutputIteratorT d_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + cudaStream_t stream = 0) + { + using OffsetT = int; // Signed integer type for global offsets + using SelectOp = NullType; // Selection op (not used) + using EqualityOp = NullType; // Equality operator (not used) + using DispatchSelectIfT = DispatchSelectIf; + + return DispatchSelectIfT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_flags, + d_out, + d_num_selected_out, + SelectOp{}, + EqualityOp{}, + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Flagged(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + FlagIterator d_flags, + OutputIteratorT d_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Flagged(d_temp_storage, + temp_storage_bytes, + d_in, + d_flags, + d_out, + d_num_selected_out, + num_items, + stream); + } + + + /** + * @brief Uses the @p select_op functor to split the corresponding items + * from @p d_in into a partitioned sequence @p d_out. The total + * number of items copied into the first partition is written to + * @p d_num_selected_out. ![](partition_logo.png) + * + * @par + * - Copies of the selected items are compacted into @p d_out and maintain + * their original relative ordering, however copies of the unselected + * items are compacted into the rear of @p d_out in reverse order. + * - The range `[d_out, d_out + num_items)` shall not overlap + * `[d_in, d_in + num_items)` in any way. + * - \devicestorage + * + * @par Performance + * The following charts illustrate saturated partition-if performance across + * different CUDA architectures for @p int32 and @p int64 items, + * respectively. Items are selected for the first partition with 50% + * probability. + * + * @image html partition_if_int32_50_percent.png + * @image html partition_if_int64_50_percent.png + * + * @par + * The following charts are similar, but 5% selection probability for the + * first partition: + * + * @image html partition_if_int32_5_percent.png + * @image html partition_if_int64_5_percent.png + * + * @par Snippet + * The code snippet below illustrates the compaction of items selected from + * an @p int device vector. + * @par + * @code + * #include + * // or equivalently + * + * // Functor type for selecting values less than some criteria + * struct LessThan + * { + * int compare; + * + * CUB_RUNTIME_FUNCTION __forceinline__ + * explicit LessThan(int compare) : compare(compare) {} + * + * CUB_RUNTIME_FUNCTION __forceinline__ + * bool operator()(const int &a) const + * { + * return (a < compare); + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 8 + * int *d_in; // e.g., [0, 2, 3, 9, 5, 2, 81, 8] + * int *d_out; // e.g., [ , , , , , , , ] + * int *d_num_selected_out; // e.g., [ ] + * LessThan select_op(7); + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * std::size_t temp_storage_bytes = 0; + * cub::DevicePartition::If( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, d_num_selected_out, num_items, select_op); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run selection + * cub::DevicePartition::If( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, d_num_selected_out, num_items, select_op); + * + * // d_out <-- [0, 2, 3, 5, 2, 8, 81, 9] + * // d_num_selected_out <-- [5] + * + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Random-access output iterator type for writing output + * items \iterator + * + * @tparam NumSelectedIteratorT + * **[inferred]** Output iterator type for recording the number of items + * selected \iterator + * + * @tparam SelectOp + * **[inferred]** Selection functor type having member + * `bool operator()(const T &a)` + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output sequence of partitioned data items + * + * @param[out] d_num_selected_out + * Pointer to the output total number of items selected (i.e., the + * offset of the unselected partition) + * + * @param[in] num_items + * Total number of items to select from + * + * @param[in] select_op + * Unary selection operator + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + If(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + SelectOp select_op, + cudaStream_t stream = 0) + { + using OffsetT = int; // Signed integer type for global offsets + using FlagIterator = NullType *; // FlagT iterator type (not used) + using EqualityOp = NullType; // Equality operator (not used) + + using DispatchSelectIfT = DispatchSelectIf; + + return DispatchSelectIfT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + nullptr, + d_out, + d_num_selected_out, + select_op, + EqualityOp{}, + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + If(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + SelectOp select_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return If( + d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + d_num_selected_out, + num_items, + select_op, + stream); + } + + /** + * @brief Uses two functors to split the corresponding items from @p d_in + * into a three partitioned sequences @p d_first_part_out + * @p d_second_part_out and @p d_unselected_out. + * The total number of items copied into the first partition is written + * to `d_num_selected_out[0]`, while the total number of items copied + * into the second partition is written to `d_num_selected_out[1]`. + * + * @par + * - Copies of the items selected by @p select_first_part_op are compacted + * into @p d_first_part_out and maintain their original relative ordering. + * - Copies of the items selected by @p select_second_part_op are compacted + * into @p d_second_part_out and maintain their original relative ordering. + * - Copies of the unselected items are compacted into the + * @p d_unselected_out in reverse order. + * - The ranges `[d_out, d_out + num_items)`, + * `[d_first_part_out, d_first_part_out + d_num_selected_out[0])`, + * `[d_second_part_out, d_second_part_out + d_num_selected_out[1])`, + * `[d_unselected_out, d_unselected_out + num_items - d_num_selected_out[0] - d_num_selected_out[1])`, + * shall not overlap in any way. + * + * @par Snippet + * The code snippet below illustrates how this algorithm can partition an + * input vector into small, medium, and large items so that the relative + * order of items remain deterministic. + * + * Let's consider any value that doesn't exceed six a small one. On the + * other hand, any value that exceeds 50 will be considered a large one. + * Since the value used to define a small part doesn't match one that + * defines the large part, the intermediate segment is implied. + * + * These definitions partition a value space into three categories. We want + * to preserve the order of items in which they appear in the input vector. + * Since the algorithm provides stable partitioning, this is possible. + * + * Since the number of items in each category is unknown beforehand, we need + * three output arrays of num_items elements each. To reduce the memory + * requirements, we can combine the output storage for two categories. + * + * Since each value falls precisely in one category, it's safe to add + * "large" values into the head of the shared output vector and the "middle" + * values into its tail. To add items into the tail of the output array, we + * can use `thrust::reverse_iterator`. + * @par + * @code + * #include + * // or equivalently + * + * // Functor type for selecting values less than some criteria + * struct LessThan + * { + * int compare; + * + * CUB_RUNTIME_FUNCTION __forceinline__ + * explicit LessThan(int compare) : compare(compare) {} + * + * CUB_RUNTIME_FUNCTION __forceinline__ + * bool operator()(const int &a) const + * { + * return a < compare; + * } + * }; + * + * // Functor type for selecting values greater than some criteria + * struct GreaterThan + * { + * int compare; + * + * CUB_RUNTIME_FUNCTION __forceinline__ + * explicit GreaterThan(int compare) : compare(compare) {} + * + * CUB_RUNTIME_FUNCTION __forceinline__ + * bool operator()(const int &a) const + * { + * return a > compare; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 8 + * int *d_in; // e.g., [0, 2, 3, 9, 5, 2, 81, 8] + * int *d_large_and_unselected_out; // e.g., [ , , , , , , , ] + * int *d_small_out; // e.g., [ , , , , , , , ] + * int *d_num_selected_out; // e.g., [ , ] + * thrust::reverse_iterator unselected_out(d_large_and_unselected_out + num_items); + * LessThan small_items_selector(7); + * GreaterThan large_items_selector(50); + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * std::size_t temp_storage_bytes = 0; + * cub::DevicePartition::If( + * d_temp_storage, temp_storage_bytes, + * d_in, d_large_and_medium_out, d_small_out, unselected_out, + * d_num_selected_out, num_items, + * large_items_selector, small_items_selector); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run selection + * cub::DevicePartition::If( + * d_temp_storage, temp_storage_bytes, + * d_in, d_large_and_medium_out, d_small_out, unselected_out, + * d_num_selected_out, num_items, + * large_items_selector, small_items_selector); + * + * // d_large_and_unselected_out <-- [ 81, , , , , , 8, 9 ] + * // d_small_out <-- [ 0, 2, 3, 5, 2, , , ] + * // d_num_selected_out <-- [ 1, 5 ] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading + * input items \iterator + * + * @tparam FirstOutputIteratorT + * **[inferred]** Random-access output iterator type for writing output + * items selected by first operator \iterator + * + * @tparam SecondOutputIteratorT + * **[inferred]** Random-access output iterator type for writing output + * items selected by second operator \iterator + * + * @tparam UnselectedOutputIteratorT + * **[inferred]** Random-access output iterator type for writing + * unselected items \iterator + * + * @tparam NumSelectedIteratorT + * **[inferred]** Output iterator type for recording the number of items + * selected \iterator + * + * @tparam SelectFirstPartOp + * **[inferred]** Selection functor type having member + * `bool operator()(const T &a)` + * + * @tparam SelectSecondPartOp + * **[inferred]** Selection functor type having member + * `bool operator()(const T &a)` + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to @p temp_storage_bytes and + * no work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_first_part_out + * Pointer to the output sequence of data items selected by + * @p select_first_part_op + * + * @param[out] d_second_part_out + * Pointer to the output sequence of data items selected by + * @p select_second_part_op + * + * @param[out] d_unselected_out + * Pointer to the output sequence of unselected data items + * + * @param[out] d_num_selected_out + * Pointer to the output array with two elements, where total number of + * items selected by @p select_first_part_op is stored as + * `d_num_selected_out[0]` and total number of items selected by + * @p select_second_part_op is stored as `d_num_selected_out[1]`, + * respectively + * + * @param[in] num_items + * Total number of items to select from + * + * @param[in] select_first_part_op + * Unary selection operator to select @p d_first_part_out + * + * @param[in] select_second_part_op + * Unary selection operator to select @p d_second_part_out + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + If(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_in, + FirstOutputIteratorT d_first_part_out, + SecondOutputIteratorT d_second_part_out, + UnselectedOutputIteratorT d_unselected_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + SelectFirstPartOp select_first_part_op, + SelectSecondPartOp select_second_part_op, + cudaStream_t stream = 0) + { + using OffsetT = int; + using DispatchThreeWayPartitionIfT = + DispatchThreeWayPartitionIf; + + return DispatchThreeWayPartitionIfT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_first_part_out, + d_second_part_out, + d_unselected_out, + d_num_selected_out, + select_first_part_op, + select_second_part_op, + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + If(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_in, + FirstOutputIteratorT d_first_part_out, + SecondOutputIteratorT d_second_part_out, + UnselectedOutputIteratorT d_unselected_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + SelectFirstPartOp select_first_part_op, + SelectSecondPartOp select_second_part_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return If(d_temp_storage, + temp_storage_bytes, + d_in, + d_first_part_out, + d_second_part_out, + d_unselected_out, + d_num_selected_out, + num_items, + select_first_part_op, + select_second_part_op, + stream); + } +}; + +/** + * @example example_device_partition_flagged.cu + * @example example_device_partition_if.cu + */ + +CUB_NAMESPACE_END + + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_radix_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_radix_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..da40a6654c61b041d9e71b6c6c599f74488821e2 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_radix_sort.cuh @@ -0,0 +1,3643 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +//! @file cub::DeviceRadixSort provides device-wide, parallel operations for +//! computing a radix sort across a sequence of data items residing within +//! device-accessible memory. + +#pragma once + +#include +#include +#include +#include + +#include + + +CUB_NAMESPACE_BEGIN + + +//! @brief DeviceRadixSort provides device-wide, parallel operations for +//! computing a radix sort across a sequence of data items residing +//! within device-accessible memory. ![](sorting_logo.png) +//! @ingroup SingleModule +//! +//! @par Overview +//! The [*radix sorting method*](http://en.wikipedia.org/wiki/Radix_sort) +//! arranges items into ascending (or descending) order. The algorithm relies +//! upon a positional representation for keys, i.e., each key is comprised of an +//! ordered sequence of symbols (e.g., digits, characters, etc.) specified from +//! least-significant to most-significant. For a given input sequence of keys +//! and a set of rules specifying a total ordering of the symbolic alphabet, the +//! radix sorting method produces a lexicographic ordering of those keys. +//! +//! @par Supported Types +//! DeviceRadixSort can sort all of the built-in C++ numeric primitive types +//! (`unsigned char`, `int`, `double`, etc.) as well as CUDA's `__half` +//! and `__nv_bfloat16` 16-bit floating-point types. User-defined types are +//! supported as long as decomposer object is provided. +//! +//! @par Floating-Point Special Cases +//! +//! - Positive and negative zeros are considered equivalent, and will be treated +//! as such in the output. +//! - No special handling is implemented for NaN values; these are sorted +//! according to their bit representations after any transformations. +//! +//! @par Transformations +//! Although the direct radix sorting method can only be applied to unsigned +//! integral types, DeviceRadixSort is able to sort signed and floating-point +//! types via simple bit-wise transformations that ensure lexicographic key +//! ordering. Additional transformations occur for descending sorts. These +//! transformations must be considered when restricting the +//! `[begin_bit, end_bit)` range, as the bitwise transformations will occur +//! before the bit-range truncation. +//! +//! Any transformations applied to the keys prior to sorting are reversed +//! while writing to the final output buffer. +//! +//! @par Type Specific Bitwise Transformations +//! To convert the input values into a radix-sortable bitwise representation, +//! the following transformations take place prior to sorting: +//! +//! - For unsigned integral values, the keys are used directly. +//! - For signed integral values, the sign bit is inverted. +//! - For positive floating point values, the sign bit is inverted. +//! - For negative floating point values, the full key is inverted. +//! +//! For floating point types, positive and negative zero are a special case and +//! will be considered equivalent during sorting. +//! +//! @par Descending Sort Bitwise Transformations +//! If descending sort is used, the keys are inverted after performing any +//! type-specific transformations, and the resulting keys are sorted in ascending +//! order. +//! +//! @par Stability +//! DeviceRadixSort is stable. For floating-point types, `-0.0` and `+0.0` are +//! considered equal and appear in the result in the same order as they appear in +//! the input. +//! +//! @par Usage Considerations +//! @cdp_class{DeviceRadixSort} +//! +//! @par Performance +//! @linear_performance{radix sort} The following chart illustrates +//! DeviceRadixSort::SortKeys performance across different CUDA architectures +//! for uniform-random `uint32` keys. +//! @plots_below +//! +//! @image html lsb_radix_sort_int32_keys.png +struct DeviceRadixSort +{ +private: + template + CUB_RUNTIME_FUNCTION static cudaError_t custom_radix_sort(::cuda::std::false_type, + void *d_temp_storage, + size_t &temp_storage_bytes, + bool is_overwrite_okay, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + NumItemsT num_items, + DecomposerT decomposer, + int begin_bit, + int end_bit, + cudaStream_t stream); + + template + CUB_RUNTIME_FUNCTION static cudaError_t custom_radix_sort(::cuda::std::true_type, + void *d_temp_storage, + size_t &temp_storage_bytes, + bool is_overwrite_okay, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + OffsetT num_items, + DecomposerT decomposer, + int begin_bit, + int end_bit, + cudaStream_t stream) + { + return DispatchRadixSort, + DecomposerT>::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + static_cast(num_items), + begin_bit, + end_bit, + is_overwrite_okay, + stream, + decomposer); + } + + template + CUB_RUNTIME_FUNCTION static cudaError_t custom_radix_sort(::cuda::std::false_type, + void *d_temp_storage, + size_t &temp_storage_bytes, + bool is_overwrite_okay, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + NumItemsT num_items, + DecomposerT decomposer, + cudaStream_t stream); + + template + CUB_RUNTIME_FUNCTION static cudaError_t custom_radix_sort(::cuda::std::true_type, + void *d_temp_storage, + size_t &temp_storage_bytes, + bool is_overwrite_okay, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + OffsetT num_items, + DecomposerT decomposer, + cudaStream_t stream) + { + const int begin_bit = 0; + const int end_bit = detail::radix::traits_t::default_end_bit(decomposer); + + return DeviceRadixSort::custom_radix_sort(::cuda::std::true_type{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + num_items, + decomposer, + begin_bit, + end_bit, + stream); + } + +public: + + //! @name KeyT-value pairs + //@{ + + //! @brief Sorts key-value pairs into ascending order. + //! (`~2N` auxiliary storage required) + //! + //! @par + //! - The contents of the input data are not altered by the sorting operation. + //! - Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! - In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! - `[d_keys_in, d_keys_in + num_items)` + //! - `[d_keys_out, d_keys_out + num_items)` + //! - `[d_values_in, d_values_in + num_items)` + //! - `[d_values_out, d_values_out + num_items)` + //! - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! - @devicestorageNP For sorting using only `O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! - @devicestorage + //! + //! @par Performance + //! The following charts illustrate saturated sorting performance across + //! different CUDA architectures for uniform-random `uint32, uint32` and + //! `uint64, uint64` pairs, respectively. + //! + //! @image html lsb_radix_sort_int32_pairs.png + //! @image html lsb_radix_sort_int64_pairs.png + //! + //! @par Snippet + //! The code snippet below illustrates the sorting of a device vector of `int` + //! keys with associated vector of `int` values. + //! @par + //! @code + //! #include + //! // or equivalently + //! + //! // Declare, allocate, and initialize device-accessible pointers + //! // for sorting data + //! int num_items; // e.g., 7 + //! int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + //! int *d_keys_out; // e.g., [ ... ] + //! int *d_values_in; // e.g., [0, 1, 2, 3, 4, 5, 6] + //! int *d_values_out; // e.g., [ ... ] + //! ... + //! + //! // Determine temporary device storage requirements + //! void *d_temp_storage = NULL; + //! size_t temp_storage_bytes = 0; + //! cub::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes, + //! d_keys_in, d_keys_out, d_values_in, d_values_out, num_items); + //! + //! // Allocate temporary storage + //! cudaMalloc(&d_temp_storage, temp_storage_bytes); + //! + //! // Run sorting operation + //! cub::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes, + //! d_keys_in, d_keys_out, d_values_in, d_values_out, num_items); + //! + //! // d_keys_out <-- [0, 3, 5, 6, 7, 8, 9] + //! // d_values_out <-- [5, 4, 3, 1, 2, 0, 6] + //! @endcode + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] d_values_in + //! Pointer to the corresponding input sequence of associated value items + //! + //! @param[out] d_values_out + //! Pointer to the correspondingly-reordered output sequence of associated + //! value items + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., sizeof(unsigned int) * 8) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + NumItemsT num_items, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Unsigned integer type for global offsets. + using OffsetT = typename detail::ChooseOffsetT::Type; + + // TODO API that doesn't accept decomposer should also contain a static + // assert that the key type is fundamental. + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values(const_cast(d_values_in), + d_values_out); + + return DispatchRadixSort::Dispatch( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + static_cast(num_items), + begin_bit, + end_bit, + is_overwrite_okay, + stream); + } + + #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + NumItemsT num_items, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairs(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + num_items, + begin_bit, + end_bit, + stream); + } + #endif + + //! @rst + //! Sorts key-value pairs into ascending order using :math:`\approx 2N` auxiliary storage. + //! + //! * The contents of the input data are not altered by the sorting operation. + //! * Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys_in, d_keys_in + num_items)`` + //! * ``[d_keys_out, d_keys_out + num_items)`` + //! * ``[d_values_in, d_values_in + num_items)`` + //! * ``[d_values_out, d_values_out + num_items)`` + //! + //! * A bit subrange ``[begin_bit, end_bit)`` is provided to specify + //! differentiating key bits. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! * @devicestorageNP For sorting using only :math:`O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortPairs``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-bits + //! :end-before: example-end pairs-bits + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] d_values_in + //! Pointer to the corresponding input sequence of associated value items + //! + //! @param[out] d_values_out + //! Pointer to the correspondingly-reordered output sequence of associated + //! value items + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + NumItemsT num_items, + DecomposerT decomposer, + int begin_bit, + int end_bit, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + constexpr bool is_descending = false; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values(const_cast(d_values_in), d_values_out); + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + begin_bit, + end_bit, + stream); + } + + //! @rst + //! Sorts key-value pairs into ascending order using :math:`\approx 2N` auxiliary storage. + //! + //! * The contents of the input data are not altered by the sorting operation. + //! * Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys_in, d_keys_in + num_items)`` + //! * ``[d_keys_out, d_keys_out + num_items)`` + //! * ``[d_values_in, d_values_in + num_items)`` + //! * ``[d_values_out, d_values_out + num_items)`` + //! + //! * @devicestorageNP For sorting using only :math:`O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortPairs``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs + //! :end-before: example-end pairs + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] d_values_in + //! Pointer to the corresponding input sequence of associated value items + //! + //! @param[out] d_values_out + //! Pointer to the correspondingly-reordered output sequence of associated + //! value items + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + NumItemsT num_items, + DecomposerT decomposer, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + constexpr bool is_descending = false; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values(const_cast(d_values_in), d_values_out); + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + stream); + } + + //! @brief Sorts key-value pairs into ascending order. + //! (`~N` auxiliary storage required) + //! + //! @par + //! - The sorting operation is given a pair of key buffers and a corresponding + //! pair of associated value buffers. Each pair is managed by a DoubleBuffer + //! structure that indicates which of the two buffers is "current" (and thus + //! contains the input data to be sorted). + //! - The contents of both buffers within each pair may be altered by the + //! sorting operation. + //! - In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! - `[d_keys.Current(), d_keys.Current() + num_items)` + //! - `[d_keys.Alternate(), d_keys.Alternate() + num_items)` + //! - `[d_values.Current(), d_values.Current() + num_items)` + //! - `[d_values.Alternate(), d_values.Alternate() + num_items)` + //! - Upon completion, the sorting operation will update the "current" + //! indicator within each DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the + //! number of key bits specified and the targeted device architecture). + //! - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! - @devicestorageP + //! - @devicestorage + //! + //! @par Performance + //! The following charts illustrate saturated sorting performance across + //! different CUDA architectures for uniform-random `uint32, uint32` and + //! `uint64, uint64` pairs, respectively. + //! + //! @image html lsb_radix_sort_int32_pairs.png + //! @image html lsb_radix_sort_int64_pairs.png + //! + //! @par Snippet + //! The code snippet below illustrates the sorting of a device vector of `int` + //! keys with associated vector of `int` values. + //! @par + //! @code + //! #include + //! // or equivalently + //! + //! // Declare, allocate, and initialize device-accessible pointers for + //! // sorting data + //! int num_items; // e.g., 7 + //! int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + //! int *d_key_alt_buf; // e.g., [ ... ] + //! int *d_value_buf; // e.g., [0, 1, 2, 3, 4, 5, 6] + //! int *d_value_alt_buf; // e.g., [ ... ] + //! ... + //! + //! // Create a set of DoubleBuffers to wrap pairs of device pointers + //! cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + //! cub::DoubleBuffer d_values(d_value_buf, d_value_alt_buf); + //! + //! // Determine temporary device storage requirements + //! void *d_temp_storage = NULL; + //! size_t temp_storage_bytes = 0; + //! cub::DeviceRadixSort::SortPairs( + //! d_temp_storage, temp_storage_bytes, d_keys, d_values, num_items); + //! + //! // Allocate temporary storage + //! cudaMalloc(&d_temp_storage, temp_storage_bytes); + //! + //! // Run sorting operation + //! cub::DeviceRadixSort::SortPairs( + //! d_temp_storage, temp_storage_bytes, d_keys, d_values, num_items); + //! + //! // d_keys.Current() <-- [0, 3, 5, 6, 7, 8, 9] + //! // d_values.Current() <-- [5, 4, 3, 1, 2, 0, 6] + //! + //! @endcode + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to @p temp_storage_bytes and no work is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in,out] d_values + //! Double-buffer of values whose "current" device-accessible buffer + //! contains the unsorted input values and, upon return, is updated to point + //! to the sorted output values + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `sizeof(unsigned int) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + NumItemsT num_items, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Unsigned integer type for global offsets. + using OffsetT = typename detail::ChooseOffsetT::Type; + + constexpr bool is_overwrite_okay = true; + + return DispatchRadixSort::Dispatch( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + begin_bit, + end_bit, + is_overwrite_okay, + stream); + } + + #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + NumItemsT num_items, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairs(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + begin_bit, + end_bit, + stream); + } + #endif + + //! @rst + //! Sorts key-value pairs into ascending order using :math:`\approx N` auxiliary storage. + //! + //! * The sorting operation is given a pair of key buffers and a corresponding + //! pair of associated value buffers. Each pair is managed by a DoubleBuffer + //! structure that indicates which of the two buffers is "current" (and thus + //! contains the input data to be sorted). + //! * The contents of both buffers within each pair may be altered by the + //! sorting operation. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! - ``[d_keys.Current(), d_keys.Current() + num_items)`` + //! - ``[d_keys.Alternate(), d_keys.Alternate() + num_items)`` + //! - ``[d_values.Current(), d_values.Current() + num_items)`` + //! - ``[d_values.Alternate(), d_values.Alternate() + num_items)`` + //! + //! - Upon completion, the sorting operation will update the "current" + //! indicator within each DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the + //! number of key bits specified and the targeted device architecture). + //! - @devicestorageP + //! - @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortPairs``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-db + //! :end-before: example-end pairs-db + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in,out] d_values + //! Double-buffer of values whose "current" device-accessible buffer + //! contains the unsorted input values and, upon return, is updated to point + //! to the sorted output values + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + NumItemsT num_items, + DecomposerT decomposer, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + constexpr bool is_overwrite_okay = true; + constexpr bool is_descending = false; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + stream); + } + + //! @rst + //! Sorts key-value pairs into ascending order using :math:`\approx N` auxiliary storage. + //! + //! * The sorting operation is given a pair of key buffers and a corresponding + //! pair of associated value buffers. Each pair is managed by a DoubleBuffer + //! structure that indicates which of the two buffers is "current" (and thus + //! contains the input data to be sorted). + //! * The contents of both buffers within each pair may be altered by the + //! sorting operation. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! - ``[d_keys.Current(), d_keys.Current() + num_items)`` + //! - ``[d_keys.Alternate(), d_keys.Alternate() + num_items)`` + //! - ``[d_values.Current(), d_values.Current() + num_items)`` + //! - ``[d_values.Alternate(), d_values.Alternate() + num_items)`` + //! + //! - Upon completion, the sorting operation will update the "current" + //! indicator within each DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the + //! number of key bits specified and the targeted device architecture). + //! - An optional bit subrange ``[begin_bit, end_bit)`` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! - @devicestorageP + //! - @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortPairs``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-bits-db + //! :end-before: example-end pairs-bits-db + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in,out] d_values + //! Double-buffer of values whose "current" device-accessible buffer + //! contains the unsorted input values and, upon return, is updated to point + //! to the sorted output values + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + NumItemsT num_items, + DecomposerT decomposer, + int begin_bit, + int end_bit, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + constexpr bool is_overwrite_okay = true; + constexpr bool is_descending = false; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + begin_bit, + end_bit, + stream); + } + + //! @brief Sorts key-value pairs into descending order. + //! (`~2N` auxiliary storage required). + //! + //! @par + //! - The contents of the input data are not altered by the sorting operation. + //! - Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! - In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! - `[d_keys_in, d_keys_in + num_items)` + //! - `[d_keys_out, d_keys_out + num_items)` + //! - `[d_values_in, d_values_in + num_items)` + //! - `[d_values_out, d_values_out + num_items)` + //! - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! - @devicestorageNP For sorting using only `O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! - @devicestorage + //! + //! @par Performance + //! Performance is similar to DeviceRadixSort::SortPairs. + //! + //! @par Snippet + //! The code snippet below illustrates the sorting of a device vector of `int` + //! keys with associated vector of `int` values. + //! @par + //! @code + //! #include + //! // or equivalently + //! + //! // Declare, allocate, and initialize device-accessible pointers + //! // for sorting data + //! int num_items; // e.g., 7 + //! int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + //! int *d_keys_out; // e.g., [ ... ] + //! int *d_values_in; // e.g., [0, 1, 2, 3, 4, 5, 6] + //! int *d_values_out; // e.g., [ ... ] + //! ... + //! + //! // Determine temporary device storage requirements + //! void *d_temp_storage = NULL; + //! size_t temp_storage_bytes = 0; + //! cub::DeviceRadixSort::SortPairsDescending( + //! d_temp_storage, temp_storage_bytes, + //! d_keys_in, d_keys_out, d_values_in, d_values_out, num_items); + //! + //! // Allocate temporary storage + //! cudaMalloc(&d_temp_storage, temp_storage_bytes); + //! + //! // Run sorting operation + //! cub::DeviceRadixSort::SortPairsDescending( + //! d_temp_storage, temp_storage_bytes, + //! d_keys_in, d_keys_out, d_values_in, d_values_out, num_items); + //! + //! // d_keys_out <-- [9, 8, 7, 6, 5, 3, 0] + //! // d_values_out <-- [6, 0, 2, 1, 3, 4, 5] + //! @endcode + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of @p d_temp_storage allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] d_values_in + //! Pointer to the corresponding input sequence of associated value items + //! + //! @param[out] d_values_out + //! Pointer to the correspondingly-reordered output sequence of associated + //! value items + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `sizeof(unsigned int) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + NumItemsT num_items, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Unsigned integer type for global offsets. + using OffsetT = typename detail::ChooseOffsetT::Type; + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values(const_cast(d_values_in), + d_values_out); + + return DispatchRadixSort::Dispatch( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + begin_bit, + end_bit, + is_overwrite_okay, + stream); + } + + #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + NumItemsT num_items, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairsDescending(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + num_items, + begin_bit, + end_bit, + stream); + } + #endif + + //! @rst + //! Sorts key-value pairs into descending order using :math:`\approx 2N` auxiliary storage. + //! + //! * The contents of the input data are not altered by the sorting operation. + //! * Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys_in, d_keys_in + num_items)`` + //! * ``[d_keys_out, d_keys_out + num_items)`` + //! * ``[d_values_in, d_values_in + num_items)`` + //! * ``[d_values_out, d_values_out + num_items)`` + //! + //! * A bit subrange ``[begin_bit, end_bit)`` is provided to specify + //! differentiating key bits. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! * @devicestorageNP For sorting using only :math:`O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortPairsDescending``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-descending-bits + //! :end-before: example-end pairs-descending-bits + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] d_values_in + //! Pointer to the corresponding input sequence of associated value items + //! + //! @param[out] d_values_out + //! Pointer to the correspondingly-reordered output sequence of associated + //! value items + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + NumItemsT num_items, + DecomposerT decomposer, + int begin_bit, + int end_bit, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + constexpr bool is_descending = true; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values(const_cast(d_values_in), d_values_out); + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + begin_bit, + end_bit, + stream); + } + + //! @rst + //! Sorts key-value pairs into descending order using :math:`\approx 2N` auxiliary storage. + //! + //! * The contents of the input data are not altered by the sorting operation. + //! * Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys_in, d_keys_in + num_items)`` + //! * ``[d_keys_out, d_keys_out + num_items)`` + //! * ``[d_values_in, d_values_in + num_items)`` + //! * ``[d_values_out, d_values_out + num_items)`` + //! + //! * @devicestorageNP For sorting using only :math:`O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortPairsDescending``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-descending + //! :end-before: example-end pairs-descending + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] d_values_in + //! Pointer to the corresponding input sequence of associated value items + //! + //! @param[out] d_values_out + //! Pointer to the correspondingly-reordered output sequence of associated + //! value items + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + NumItemsT num_items, + DecomposerT decomposer, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + constexpr bool is_descending = true; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values(const_cast(d_values_in), d_values_out); + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + stream); + } + + //! @brief Sorts key-value pairs into descending order. + //! (`~N` auxiliary storage required). + //! + //! @par + //! - The sorting operation is given a pair of key buffers and a corresponding + //! pair of associated value buffers. Each pair is managed by a DoubleBuffer + //! structure that indicates which of the two buffers is "current" (and thus + //! contains the input data to be sorted). + //! - The contents of both buffers within each pair may be altered by the + //! sorting operation. + //! - In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! - `[d_keys.Current(), d_keys.Current() + num_items)` + //! - `[d_keys.Alternate(), d_keys.Alternate() + num_items)` + //! - `[d_values.Current(), d_values.Current() + num_items)` + //! - `[d_values.Alternate(), d_values.Alternate() + num_items)` + //! - Upon completion, the sorting operation will update the "current" + //! indicator within each DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the number + //! of key bits specified and the targeted device architecture). + //! - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! - @devicestorageP + //! - @devicestorage + //! + //! @par Performance + //! Performance is similar to DeviceRadixSort::SortPairs. + //! + //! @par Snippet + //! The code snippet below illustrates the sorting of a device vector of `int` + //! keys with associated vector of `int` values. + //! @par + //! @code + //! #include + //! // or equivalently + //! + //! // Declare, allocate, and initialize device-accessible pointers + //! // for sorting data + //! int num_items; // e.g., 7 + //! int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + //! int *d_key_alt_buf; // e.g., [ ... ] + //! int *d_value_buf; // e.g., [0, 1, 2, 3, 4, 5, 6] + //! int *d_value_alt_buf; // e.g., [ ... ] + //! ... + //! + //! // Create a set of DoubleBuffers to wrap pairs of device pointers + //! cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + //! cub::DoubleBuffer d_values(d_value_buf, d_value_alt_buf); + //! + //! // Determine temporary device storage requirements + //! void *d_temp_storage = NULL; + //! size_t temp_storage_bytes = 0; + //! cub::DeviceRadixSort::SortPairsDescending( + //! d_temp_storage, temp_storage_bytes, d_keys, d_values, num_items); + //! + //! // Allocate temporary storage + //! cudaMalloc(&d_temp_storage, temp_storage_bytes); + //! + //! // Run sorting operation + //! cub::DeviceRadixSort::SortPairsDescending( + //! d_temp_storage, temp_storage_bytes, d_keys, d_values, num_items); + //! + //! // d_keys.Current() <-- [9, 8, 7, 6, 5, 3, 0] + //! // d_values.Current() <-- [6, 0, 2, 1, 3, 4, 5] + //! @endcode + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in,out] d_values + //! Double-buffer of values whose "current" device-accessible buffer + //! contains the unsorted input values and, upon return, is updated to point + //! to the sorted output values + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `sizeof(unsigned int) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + NumItemsT num_items, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Unsigned integer type for global offsets. + using OffsetT = typename detail::ChooseOffsetT::Type; + + constexpr bool is_overwrite_okay = true; + + return DispatchRadixSort::Dispatch( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + begin_bit, + end_bit, + is_overwrite_okay, + stream); + } + + #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + NumItemsT num_items, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairsDescending(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + begin_bit, + end_bit, + stream); + } + #endif + + //! @rst + //! Sorts key-value pairs into descending order using :math:`\approx N` auxiliary storage. + //! + //! * The sorting operation is given a pair of key buffers and a corresponding + //! pair of associated value buffers. Each pair is managed by a DoubleBuffer + //! structure that indicates which of the two buffers is "current" (and thus + //! contains the input data to be sorted). + //! * The contents of both buffers within each pair may be altered by the + //! sorting operation. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! - ``[d_keys.Current(), d_keys.Current() + num_items)`` + //! - ``[d_keys.Alternate(), d_keys.Alternate() + num_items)`` + //! - ``[d_values.Current(), d_values.Current() + num_items)`` + //! - ``[d_values.Alternate(), d_values.Alternate() + num_items)`` + //! + //! - Upon completion, the sorting operation will update the "current" + //! indicator within each DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the + //! number of key bits specified and the targeted device architecture). + //! - @devicestorageP + //! - @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortPairsDescending``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-descending-db + //! :end-before: example-end pairs-descending-db + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in,out] d_values + //! Double-buffer of values whose "current" device-accessible buffer + //! contains the unsorted input values and, upon return, is updated to point + //! to the sorted output values + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + NumItemsT num_items, + DecomposerT decomposer, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + constexpr bool is_overwrite_okay = true; + constexpr bool is_descending = true; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + stream); + } + + //! @rst + //! Sorts key-value pairs into descending order using :math:`\approx N` auxiliary storage. + //! + //! * The sorting operation is given a pair of key buffers and a corresponding + //! pair of associated value buffers. Each pair is managed by a DoubleBuffer + //! structure that indicates which of the two buffers is "current" (and thus + //! contains the input data to be sorted). + //! * The contents of both buffers within each pair may be altered by the + //! sorting operation. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! - ``[d_keys.Current(), d_keys.Current() + num_items)`` + //! - ``[d_keys.Alternate(), d_keys.Alternate() + num_items)`` + //! - ``[d_values.Current(), d_values.Current() + num_items)`` + //! - ``[d_values.Alternate(), d_values.Alternate() + num_items)`` + //! + //! - Upon completion, the sorting operation will update the "current" + //! indicator within each DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the + //! number of key bits specified and the targeted device architecture). + //! - An optional bit subrange ``[begin_bit, end_bit)`` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! - @devicestorageP + //! - @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortPairsDescending``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin pairs-descending-bits-db + //! :end-before: example-end pairs-descending-bits-db + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam ValueT + //! **[inferred]** ValueT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in,out] d_values + //! Double-buffer of values whose "current" device-accessible buffer + //! contains the unsorted input values and, upon return, is updated to point + //! to the sorted output values + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + NumItemsT num_items, + DecomposerT decomposer, + int begin_bit, + int end_bit, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + constexpr bool is_overwrite_okay = true; + constexpr bool is_descending = true; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + begin_bit, + end_bit, + stream); + } + + //@} end member group + /******************************************************************//** + * @name Keys-only + *********************************************************************/ + //@{ + + + //! @brief Sorts keys into ascending order. + //! (`~2N` auxiliary storage required) + //! + //! @par + //! - The contents of the input data are not altered by the sorting operation. + //! - Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! - In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! - `[d_keys_in, d_keys_in + num_items)` + //! - `[d_keys_out, d_keys_out + num_items)` + //! - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! - @devicestorageNP For sorting using only `O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! - @devicestorage + //! + //! @par Performance + //! The following charts illustrate saturated sorting performance across + //! different CUDA architectures for uniform-random `uint32` and `uint64` + //! keys, respectively. + //! + //! @image html lsb_radix_sort_int32_keys.png + //! @image html lsb_radix_sort_int64_keys.png + //! + //! @par Snippet + //! The code snippet below illustrates the sorting of a device vector of + //! `int` keys. + //! @par + //! @code + //! #include + //! // or equivalently + //! + //! // Declare, allocate, and initialize device-accessible pointers + //! // for sorting data + //! int num_items; // e.g., 7 + //! int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + //! int *d_keys_out; // e.g., [ ... ] + //! ... + //! + //! // Determine temporary device storage requirements + //! void *d_temp_storage = NULL; + //! size_t temp_storage_bytes = 0; + //! cub::DeviceRadixSort::SortKeys( + //! d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, num_items); + //! + //! // Allocate temporary storage + //! cudaMalloc(&d_temp_storage, temp_storage_bytes); + //! + //! // Run sorting operation + //! cub::DeviceRadixSort::SortKeys( + //! d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, num_items); + //! + //! // d_keys_out <-- [0, 3, 5, 6, 7, 8, 9] + //! @endcode + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `sizeof(unsigned int) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + NumItemsT num_items, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Unsigned integer type for global offsets. + using OffsetT = typename detail::ChooseOffsetT::Type; + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + // Null value type + DoubleBuffer d_values; + + return DispatchRadixSort::Dispatch( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + static_cast(num_items), + begin_bit, + end_bit, + is_overwrite_okay, + stream); + } + + //! @rst + //! Sorts keys into ascending order using :math:`\approx 2N` auxiliary storage. + //! + //! * The contents of the input data are not altered by the sorting operation. + //! * Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys_in, d_keys_in + num_items)`` + //! * ``[d_keys_out, d_keys_out + num_items)`` + //! + //! * A bit subrange ``[begin_bit, end_bit)`` is provided to specify + //! differentiating key bits. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! * @devicestorageNP For sorting using only :math:`O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortKeys``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-bits + //! :end-before: example-end keys-bits + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + NumItemsT num_items, + DecomposerT decomposer, + int begin_bit, + int end_bit, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + constexpr bool is_descending = false; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + begin_bit, + end_bit, + stream); + } + + //! @rst + //! Sorts keys into ascending order using :math:`\approx 2N` auxiliary storage. + //! + //! * The contents of the input data are not altered by the sorting operation. + //! * Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys_in, d_keys_in + num_items)`` + //! * ``[d_keys_out, d_keys_out + num_items)`` + //! + //! * An optional bit subrange ``[begin_bit, end_bit)`` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! * @devicestorageNP For sorting using only :math:`O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortKeys``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys + //! :end-before: example-end keys + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + NumItemsT num_items, + DecomposerT decomposer, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + constexpr bool is_descending = false; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + stream); + } + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + NumItemsT num_items, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeys(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + num_items, + begin_bit, + end_bit, + stream); + } + #endif + + + //! @brief Sorts keys into ascending order. (`~N` auxiliary storage required). + //! + //! @par + //! - The sorting operation is given a pair of key buffers managed by a + //! DoubleBuffer structure that indicates which of the two buffers is + //! "current" (and thus contains the input data to be sorted). + //! - The contents of both buffers may be altered by the sorting operation. + //! - In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! - `[d_keys.Current(), d_keys.Current() + num_items)` + //! - `[d_keys.Alternate(), d_keys.Alternate() + num_items)` + //! - Upon completion, the sorting operation will update the "current" + //! indicator within the DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the + //! number of key bits specified and the targeted device architecture). + //! - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! - @devicestorageP + //! - @devicestorage + //! + //! @par Performance + //! The following charts illustrate saturated sorting performance across + //! different CUDA architectures for uniform-random `uint32` and `uint64` + //! keys, respectively. + //! + //! @image html lsb_radix_sort_int32_keys.png + //! @image html lsb_radix_sort_int64_keys.png + //! + //! @par Snippet + //! The code snippet below illustrates the sorting of a device vector of + //! `int` keys. + //! @par + //! @code + //! #include + //! // or equivalently + //! + //! // Declare, allocate, and initialize device-accessible pointers + //! // for sorting data + //! int num_items; // e.g., 7 + //! int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + //! int *d_key_alt_buf; // e.g., [ ... ] + //! ... + //! + //! // Create a DoubleBuffer to wrap the pair of device pointers + //! cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + //! + //! // Determine temporary device storage requirements + //! void *d_temp_storage = NULL; + //! size_t temp_storage_bytes = 0; + //! cub::DeviceRadixSort::SortKeys( + //! d_temp_storage, temp_storage_bytes, d_keys, num_items); + //! + //! // Allocate temporary storage + //! cudaMalloc(&d_temp_storage, temp_storage_bytes); + //! + //! // Run sorting operation + //! cub::DeviceRadixSort::SortKeys( + //! d_temp_storage, temp_storage_bytes, d_keys, num_items); + //! + //! // d_keys.Current() <-- [0, 3, 5, 6, 7, 8, 9] + //! @endcode + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `sizeof(unsigned int) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + NumItemsT num_items, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Unsigned integer type for global offsets. + using OffsetT = typename detail::ChooseOffsetT::Type; + + constexpr bool is_overwrite_okay = true; + + // Null value type + DoubleBuffer d_values; + + return DispatchRadixSort::Dispatch( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + begin_bit, + end_bit, + is_overwrite_okay, + stream); + } + + #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + NumItemsT num_items, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeys(d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + begin_bit, + end_bit, + stream); + } + #endif + + //! @rst + //! Sorts keys into ascending order using :math:`\approx N` auxiliary storage. + //! + //! * The sorting operation is given a pair of key buffers managed by a + //! DoubleBuffer structure that indicates which of the two buffers is + //! "current" (and thus contains the input data to be sorted). + //! * The contents of both buffers may be altered by the sorting operation. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys.Current(), d_keys.Current() + num_items)`` + //! * ``[d_keys.Alternate(), d_keys.Alternate() + num_items)` + //! + //! * Upon completion, the sorting operation will update the "current" + //! indicator within the DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the + //! number of key bits specified and the targeted device architecture). + //! * @devicestorageP + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortKeys``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-db + //! :end-before: example-end keys-db + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + NumItemsT num_items, + DecomposerT decomposer, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + constexpr bool is_overwrite_okay = true; + constexpr bool is_descending = false; + DoubleBuffer d_values; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + stream); + } + + //! @rst + //! Sorts keys into ascending order using :math:`\approx N` auxiliary storage. + //! + //! * The sorting operation is given a pair of key buffers managed by a + //! DoubleBuffer structure that indicates which of the two buffers is + //! "current" (and thus contains the input data to be sorted). + //! * The contents of both buffers may be altered by the sorting operation. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys.Current(), d_keys.Current() + num_items)`` + //! * ``[d_keys.Alternate(), d_keys.Alternate() + num_items)` + //! + //! * A bit subrange ``[begin_bit, end_bit)`` is provided to specify + //! differentiating key bits. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! * Upon completion, the sorting operation will update the "current" + //! indicator within the DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the + //! number of key bits specified and the targeted device architecture). + //! * @devicestorageP + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortKeys``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-bits-db + //! :end-before: example-end keys-bits-db + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + NumItemsT num_items, + DecomposerT decomposer, + int begin_bit, + int end_bit, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + constexpr bool is_overwrite_okay = true; + constexpr bool is_descending = false; + DoubleBuffer d_values; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + begin_bit, + end_bit, + stream); + } + + //! @brief Sorts keys into descending order. + //! (`~2N` auxiliary storage required). + //! + //! @par + //! - The contents of the input data are not altered by the sorting operation. + //! - Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! - In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! - `[d_keys_in, d_keys_in + num_items)` + //! - `[d_keys_out, d_keys_out + num_items)` + //! - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! - @devicestorageNP For sorting using only `O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! - @devicestorage + //! + //! @par Performance + //! Performance is similar to DeviceRadixSort::SortKeys. + //! + //! @par Snippet + //! The code snippet below illustrates the sorting of a device vector of + //! `int` keys. + //! @par + //! @code + //! #include + //! // or equivalently + //! + //! // Declare, allocate, and initialize device-accessible pointers + //! // for sorting data + //! int num_items; // e.g., 7 + //! int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + //! int *d_keys_out; // e.g., [ ... ] + //! ... + //! + //! // Create a DoubleBuffer to wrap the pair of device pointers + //! cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + //! + //! // Determine temporary device storage requirements + //! void *d_temp_storage = NULL; + //! size_t temp_storage_bytes = 0; + //! cub::DeviceRadixSort::SortKeysDescending( + //! d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, num_items); + //! + //! // Allocate temporary storage + //! cudaMalloc(&d_temp_storage, temp_storage_bytes); + //! + //! // Run sorting operation + //! cub::DeviceRadixSort::SortKeysDescending( + //! d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, num_items); + //! + //! // d_keys_out <-- [9, 8, 7, 6, 5, 3, 0]s + //! + //! @endcode + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `sizeof(unsigned int) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + NumItemsT num_items, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Unsigned integer type for global offsets. + using OffsetT = typename detail::ChooseOffsetT::Type; + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values; + + return DispatchRadixSort::Dispatch( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + begin_bit, + end_bit, + is_overwrite_okay, + stream); + } + + #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + NumItemsT num_items, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeysDescending(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + num_items, + begin_bit, + end_bit, + stream); + } + #endif + + //! @rst + //! Sorts keys into descending order using :math:`\approx 2N` auxiliary storage. + //! + //! * The contents of the input data are not altered by the sorting operation. + //! * Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys_in, d_keys_in + num_items)`` + //! * ``[d_keys_out, d_keys_out + num_items)`` + //! + //! * An optional bit subrange ``[begin_bit, end_bit)`` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! * @devicestorageNP For sorting using only :math:`O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortKeysDescending``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-descending-bits + //! :end-before: example-end keys-descending-bits + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + NumItemsT num_items, + DecomposerT decomposer, + int begin_bit, + int end_bit, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + constexpr bool is_descending = true; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + begin_bit, + end_bit, + stream); + } + + //! @rst + //! Sorts keys into descending order using :math:`\approx 2N` auxiliary storage. + //! + //! * The contents of the input data are not altered by the sorting operation. + //! * Pointers to contiguous memory must be used; iterators are not currently + //! supported. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys_in, d_keys_in + num_items)`` + //! * ``[d_keys_out, d_keys_out + num_items)`` + //! + //! * @devicestorageNP For sorting using only :math:`O(P)` temporary storage, see + //! the sorting interface using DoubleBuffer wrappers below. + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortKeysDescending``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-descending + //! :end-before: example-end keys-descending + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in] d_keys_in + //! Pointer to the input data of key data to sort + //! + //! @param[out] d_keys_out + //! Pointer to the sorted output sequence of key data + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + NumItemsT num_items, + DecomposerT decomposer, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + // We cast away const-ness, but will *not* write to these arrays. + // `DispatchRadixSort::Dispatch` will allocate temporary storage and + // create a new double-buffer internally when the `is_overwrite_ok` flag + // is not set. + constexpr bool is_overwrite_okay = false; + constexpr bool is_descending = true; + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + stream); + } + + //! @brief Sorts keys into descending order. + //! (`~N` auxiliary storage required). + //! + //! @par + //! - The sorting operation is given a pair of key buffers managed by a + //! DoubleBuffer structure that indicates which of the two buffers is + //! "current" (and thus contains the input data to be sorted). + //! - The contents of both buffers may be altered by the sorting operation. + //! - In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! - `[d_keys.Current(), d_keys.Current() + num_items)` + //! - `[d_keys.Alternate(), d_keys.Alternate() + num_items)` + //! - Upon completion, the sorting operation will update the "current" + //! indicator within the DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the + //! number of key bits specified and the targeted device architecture). + //! - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + //! bits can be specified. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! - @devicestorageP + //! - @devicestorage + //! + //! @par Performance + //! Performance is similar to DeviceRadixSort::SortKeys. + //! + //! @par Snippet + //! The code snippet below illustrates the sorting of a device vector of @p int keys. + //! @par + //! @code + //! #include + //! // or equivalently + //! + //! // Declare, allocate, and initialize device-accessible pointers + //! // for sorting data + //! int num_items; // e.g., 7 + //! int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + //! int *d_key_alt_buf; // e.g., [ ... ] + //! ... + //! + //! // Create a DoubleBuffer to wrap the pair of device pointers + //! cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + //! + //! // Determine temporary device storage requirements + //! void *d_temp_storage = NULL; + //! size_t temp_storage_bytes = 0; + //! cub::DeviceRadixSort::SortKeysDescending( + //! d_temp_storage, temp_storage_bytes, d_keys, num_items); + //! + //! // Allocate temporary storage + //! cudaMalloc(&d_temp_storage, temp_storage_bytes); + //! + //! // Run sorting operation + //! cub::DeviceRadixSort::SortKeysDescending( + //! d_temp_storage, temp_storage_bytes, d_keys, num_items); + //! + //! // d_keys.Current() <-- [9, 8, 7, 6, 5, 3, 0] + //! @endcode + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `sizeof(unsigned int) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + NumItemsT num_items, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Unsigned integer type for global offsets. + using OffsetT = typename detail::ChooseOffsetT::Type; + + constexpr bool is_overwrite_okay = true; + + // Null value type + DoubleBuffer d_values; + + return DispatchRadixSort::Dispatch( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + begin_bit, + end_bit, + is_overwrite_okay, + stream); + } + + #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + NumItemsT num_items, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeysDescending(d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + begin_bit, + end_bit, + stream); + } + #endif + + //! @rst + //! Sorts keys into descending order using :math:`\approx N` auxiliary storage. + //! + //! * The sorting operation is given a pair of key buffers managed by a + //! DoubleBuffer structure that indicates which of the two buffers is + //! "current" (and thus contains the input data to be sorted). + //! * The contents of both buffers may be altered by the sorting operation. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys.Current(), d_keys.Current() + num_items)`` + //! * ``[d_keys.Alternate(), d_keys.Alternate() + num_items)` + //! + //! * Upon completion, the sorting operation will update the "current" + //! indicator within the DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the + //! number of key bits specified and the targeted device architecture). + //! * @devicestorageP + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortKeysDescending``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-descending-db + //! :end-before: example-end keys-descending-db + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + NumItemsT num_items, + DecomposerT decomposer, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + constexpr bool is_overwrite_okay = true; + constexpr bool is_descending = true; + DoubleBuffer d_values; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + stream); + } + + //! @rst + //! Sorts keys into descending order using :math:`\approx N` auxiliary storage. + //! + //! * The sorting operation is given a pair of key buffers managed by a + //! DoubleBuffer structure that indicates which of the two buffers is + //! "current" (and thus contains the input data to be sorted). + //! * The contents of both buffers may be altered by the sorting operation. + //! * In-place operations are not supported. There must be no overlap between + //! any of the provided ranges: + //! + //! * ``[d_keys.Current(), d_keys.Current() + num_items)`` + //! * ``[d_keys.Alternate(), d_keys.Alternate() + num_items)` + //! + //! * A bit subrange ``[begin_bit, end_bit)`` is provided to specify + //! differentiating key bits. This can reduce overall sorting overhead and + //! yield a corresponding performance improvement. + //! * Upon completion, the sorting operation will update the "current" + //! indicator within the DoubleBuffer wrapper to reference which of the two + //! buffers now contains the sorted output sequence (a function of the + //! number of key bits specified and the targeted device architecture). + //! * @devicestorageP + //! * @devicestorage + //! + //! Snippet + //! ========================================================================== + //! + //! Let's consider a user-defined ``custom_t`` type below. To sort an array of + //! ``custom_t`` objects, we have to tell CUB about relevant members of the + //! ``custom_t`` type. We do this by providing a decomposer that returns a + //! tuple of references to relevant members of the key. + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin custom-type + //! :end-before: example-end custom-type + //! + //! The following snippet shows how to sort an array of ``custom_t`` objects + //! using ``cub::DeviceRadixSort::SortKeysDescending``: + //! + //! .. literalinclude:: ../../test/catch2_test_device_radix_sort_custom.cu + //! :language: c++ + //! :dedent: + //! :start-after: example-begin keys-descending-bits-db + //! :end-before: example-end keys-descending-bits-db + //! + //! @endrst + //! + //! @tparam KeyT + //! **[inferred]** KeyT type + //! + //! @tparam NumItemsT + //! **[inferred]** Type of num_items + //! + //! @tparam DecomposerT + //! **[inferred]** Type of a callable object responsible for decomposing a + //! ``KeyT`` into a tuple of references to its constituent arithmetic types: + //! ``::cuda::std::tuple operator()(KeyT &key)``. + //! The leftmost element of the tuple is considered the most significant. + //! The call operator must not modify members of the key. + //! + //! @param[in] d_temp_storage + //! Device-accessible allocation of temporary storage. When `nullptr`, the + //! required allocation size is written to `temp_storage_bytes` and no work + //! is done. + //! + //! @param[in,out] temp_storage_bytes + //! Reference to size in bytes of `d_temp_storage` allocation + //! + //! @param[in,out] d_keys + //! Reference to the double-buffer of keys whose "current" device-accessible + //! buffer contains the unsorted input keys and, upon return, is updated to + //! point to the sorted output keys + //! + //! @param[in] num_items + //! Number of items to sort + //! + //! @param decomposer + //! Callable object responsible for decomposing a ``KeyT`` into a tuple of + //! references to its constituent arithmetic types. The leftmost element of + //! the tuple is considered the most significant. The call operator must not + //! modify members of the key. + //! + //! @param[in] begin_bit + //! **[optional]** The least-significant bit index (inclusive) needed for + //! key comparison + //! + //! @param[in] end_bit + //! **[optional]** The most-significant bit index (exclusive) needed for key + //! comparison (e.g., `(sizeof(float) + sizeof(long long int)) * 8`) + //! + //! @param[in] stream + //! **[optional]** CUDA stream to launch kernels within. + //! Default is stream0. + template + CUB_RUNTIME_FUNCTION static // + typename ::cuda::std::enable_if< // + !::cuda::std::is_convertible::value, // + cudaError_t>::type + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + NumItemsT num_items, + DecomposerT decomposer, + int begin_bit, + int end_bit, + cudaStream_t stream = 0) + { + // unsigned integer type for global offsets + using offset_t = typename detail::ChooseOffsetT::Type; + using decomposer_check_t = detail::radix::decomposer_check_t; + + static_assert(decomposer_check_t::value, + "DecomposerT must be a callable object returning a tuple of references to " + "arithmetic types"); + + constexpr bool is_overwrite_okay = true; + constexpr bool is_descending = true; + DoubleBuffer d_values; + + return DeviceRadixSort::custom_radix_sort(decomposer_check_t{}, + d_temp_storage, + temp_storage_bytes, + is_overwrite_okay, + d_keys, + d_values, + static_cast(num_items), + decomposer, + begin_bit, + end_bit, + stream); + } + + //@} end member group +}; + +/** + * @example example_device_radix_sort.cu + */ + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_reduce.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_reduce.cuh new file mode 100644 index 0000000000000000000000000000000000000000..f2c4090f8b597be7503864f8e55b8c075c70333f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_reduce.cuh @@ -0,0 +1,1213 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::DeviceReduce provides device-wide, parallel operations for + * computing a reduction across a sequence of data items residing within + * device-accessible memory. + */ + +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +//! @ingroup SingleModule +//! +//! @rst +//! DeviceReduce provides device-wide, parallel operations for computing +//! a reduction across a sequence of data items residing within +//! device-accessible memory. +//! +//! .. image:: ../img/reduce_logo.png +//! :align: center +//! +//! Overview +//! ==================================== +//! A `reduction `_ +//! (or *fold*) uses a binary combining operator to compute a single aggregate +//! from a sequence of input elements. +//! +//! Usage Considerations +//! ==================================== +//! @cdp_class{DeviceReduce} +//! +//! Performance +//! ==================================== +//! @linear_performance{reduction, reduce-by-key, and run-length encode} +//! +//! The following chart illustrates DeviceReduce::Sum +//! performance across different CUDA architectures for \p int32 keys. +//! +//! .. image:: ../img/reduce_int32.png +//! :align: center +//! +//! @par +//! The following chart illustrates DeviceReduce::ReduceByKey (summation) +//! performance across different CUDA architectures for `fp32` values. Segments +//! are identified by `int32` keys, and have lengths uniformly sampled +//! from `[1, 1000]`. +//! +//! .. image:: ../img/reduce_by_key_fp32_len_500.png +//! :align: center +//! +//! @endrst +struct DeviceReduce +{ + /** + * @brief Computes a device-wide reduction using the specified binary + * `reduction_op` functor and initial value `init`. + * + * @par + * - Does not support binary reduction operators that are non-commutative. + * - Provides "run-to-run" determinism for pseudo-associative reduction + * (e.g., addition of floating point types) on the same GPU device. + * However, results for pseudo-associative reduction may be inconsistent + * from one device to a another device of a different compute-capability + * because CUB can employ different tile-sizing for different architectures. + * - The range `[d_in, d_in + num_items)` shall not overlap `d_out`. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates a user-defined min-reduction of a + * device vector of `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // CustomMin functor + * struct CustomMin + * { + * template + * __device__ __forceinline__ + * T operator()(const T &a, const T &b) const { + * return (b < a) ? b : a; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [-] + * CustomMin min_op; + * int init; // e.g., INT_MAX + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceReduce::Reduce( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, num_items, min_op, init); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run reduction + * cub::DeviceReduce::Reduce( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, num_items, min_op, init); + * + * // d_out <-- [0] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced + * aggregate \iterator + * + * @tparam ReductionOpT + * **[inferred]** Binary reduction functor type having member + * `T operator()(const T &a, const T &b)` + * + * @tparam T + * **[inferred]** Data element type that is convertible to the `value` type + * of `InputIteratorT` + * + * @tparam NumItemsT **[inferred]** Type of num_items + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param d_in[in] + * Pointer to the input sequence of data items + * + * @param d_out[out] + * Pointer to the output aggregate + * + * @param num_items[in] + * Total number of input items (i.e., length of `d_in`) + * + * @param reduction_op[in] + * Binary reduction functor + * + * @param[in] init + * Initial value of the reduction + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t Reduce(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + NumItemsT num_items, + ReductionOpT reduction_op, + T init, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = typename detail::ChooseOffsetT::Type; + + return DispatchReduce::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + static_cast(num_items), + reduction_op, + init, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t Reduce(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + ReductionOpT reduction_op, + T init, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Reduce( + d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_items, + reduction_op, + init, + stream); + } + + /** + * @brief Computes a device-wide sum using the addition (`+`) operator. + * + * @par + * - Uses `0` as the initial value of the reduction. + * - Does not support \p + operators that are non-commutative.. + * - Provides "run-to-run" determinism for pseudo-associative reduction + * (e.g., addition of floating point types) on the same GPU device. + * However, results for pseudo-associative reduction may be inconsistent + * from one device to a another device of a different compute-capability + * because CUB can employ different tile-sizing for different architectures. + * - The range `[d_in, d_in + num_items)` shall not overlap `d_out`. + * - @devicestorage + * + * @par Performance + * The following charts illustrate saturated sum-reduction performance across + * different CUDA architectures for `int32` and `int64` items, respectively. + * + * @image html reduce_int32.png + * @image html reduce_int64.png + * + * @par Snippet + * The code snippet below illustrates the sum-reduction of a device vector + * of `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_items; // e.g., 7 + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [-] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceReduce::Sum( + * d_temp_storage, temp_storage_bytes, d_in, d_out, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sum-reduction + * cub::DeviceReduce::Sum( + * d_temp_storage, temp_storage_bytes, d_in, d_out, num_items); + * + * // d_out <-- [38] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced + * aggregate \iterator + * + * @tparam NumItemsT **[inferred]** Type of num_items + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t Sum(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + NumItemsT num_items, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = typename detail::ChooseOffsetT::Type; + + // The output value type + using OutputT = + cub::detail::non_void_value_t>; + + using InitT = OutputT; + + return DispatchReduce::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + static_cast(num_items), + cub::Sum(), + InitT{}, // zero-initialize + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t Sum(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Sum(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_items, + stream); + } + + /** + * @brief Computes a device-wide minimum using the less-than ('<') operator. + * + * @par + * - Uses `std::numeric_limits::max()` as the initial value of the reduction. + * - Does not support `<` operators that are non-commutative. + * - Provides "run-to-run" determinism for pseudo-associative reduction + * (e.g., addition of floating point types) on the same GPU device. + * However, results for pseudo-associative reduction may be inconsistent + * from one device to a another device of a different compute-capability + * because CUB can employ different tile-sizing for different architectures. + * - The range `[d_in, d_in + num_items)` shall not overlap `d_out`. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the min-reduction of a device vector of + * `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_items; // e.g., 7 + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [-] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceReduce::Min( + * d_temp_storage, temp_storage_bytes, d_in, d_out, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run min-reduction + * cub::DeviceReduce::Min( + * d_temp_storage, temp_storage_bytes, d_in, d_out, num_items); + * + * // d_out <-- [0] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced + * aggregate \iterator + * + * @tparam NumItemsT **[inferred]** Type of num_items + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t Min(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + NumItemsT num_items, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = typename detail::ChooseOffsetT::Type; + + // The input value type + using InputT = cub::detail::value_t; + + using InitT = InputT; + + return DispatchReduce::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + static_cast(num_items), + cub::Min(), + // replace with + // std::numeric_limits::max() when + // C++11 support is more prevalent + Traits::Max(), + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t Min(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Min(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_items, + stream); + } + + /** + * @brief Finds the first device-wide minimum using the less-than ('<') + * operator, also returning the index of that item. + * + * @par + * - The output value type of `d_out` is cub::KeyValuePair `` + * (assuming the value type of `d_in` is `T`) + * - The minimum is written to `d_out.value` and its offset in the input + * array is written to `d_out.key`. + * - The `{1, std::numeric_limits::max()}` tuple is produced for + * zero-length inputs + * - Does not support `<` operators that are non-commutative. + * - Provides "run-to-run" determinism for pseudo-associative reduction + * (e.g., addition of floating point types) on the same GPU device. + * However, results for pseudo-associative reduction may be inconsistent + * from one device to a another device of a different compute-capability + * because CUB can employ different tile-sizing for different architectures. + * - The range `[d_in, d_in + num_items)` shall not overlap `d_out`. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the argmin-reduction of a device vector + * of `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_items; // e.g., 7 + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * KeyValuePair *d_out; // e.g., [{-,-}] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceReduce::ArgMin( + * d_temp_storage, temp_storage_bytes, d_in, d_argmin, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run argmin-reduction + * cub::DeviceReduce::ArgMin( + * d_temp_storage, temp_storage_bytes, d_in, d_argmin, num_items); + * + * // d_out <-- [{5, 0}] + * + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input items + * (of some type `T`) \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced aggregate + * (having value type `cub::KeyValuePair`) \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to \p temp_storage_bytes and no work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t ArgMin(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + // The input type + using InputValueT = cub::detail::value_t; + + // The output tuple type + using OutputTupleT = + cub::detail::non_void_value_t>; + + using AccumT = OutputTupleT; + + using InitT = detail::reduce::empty_problem_init_t; + + // The output value type + using OutputValueT = typename OutputTupleT::Value; + + // Wrapped input iterator to produce index-value tuples + using ArgIndexInputIteratorT = + ArgIndexInputIterator; + + ArgIndexInputIteratorT d_indexed_in(d_in); + + // Initial value + // TODO Address https://github.com/NVIDIA/cub/issues/651 + InitT initial_value{AccumT(1, Traits::Max())}; + + return DispatchReduce::Dispatch(d_temp_storage, + temp_storage_bytes, + d_indexed_in, + d_out, + num_items, + cub::ArgMin(), + initial_value, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t ArgMin(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ArgMin(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_items, + stream); + } + + /** + * @brief Computes a device-wide maximum using the greater-than ('>') operator. + * + * @par + * - Uses `std::numeric_limits::lowest()` as the initial value of the + * reduction. + * - Does not support `>` operators that are non-commutative. + * - Provides "run-to-run" determinism for pseudo-associative reduction + * (e.g., addition of floating point types) on the same GPU device. + * However, results for pseudo-associative reduction may be inconsistent + * from one device to a another device of a different compute-capability + * because CUB can employ different tile-sizing for different architectures. + * - The range `[d_in, d_in + num_items)` shall not overlap `d_out`. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the max-reduction of a device vector of + * `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_items; // e.g., 7 + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [-] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceReduce::Max( + * d_temp_storage, temp_storage_bytes, d_in, d_max, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run max-reduction + * cub::DeviceReduce::Max( + * d_temp_storage, temp_storage_bytes, d_in, d_max, num_items); + * + * // d_out <-- [9] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced + * aggregate \iterator + * + * @tparam NumItemsT **[inferred]** Type of num_items + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t Max(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + NumItemsT num_items, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = typename detail::ChooseOffsetT::Type; + + // The input value type + using InputT = cub::detail::value_t; + + using InitT = InputT; + + return DispatchReduce::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + static_cast(num_items), + cub::Max(), + // replace with + // std::numeric_limits::lowest() + // when C++11 support is more + // prevalent + Traits::Lowest(), + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t Max(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Max(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_items, + stream); + } + + /** + * @brief Finds the first device-wide maximum using the greater-than ('>') + * operator, also returning the index of that item + * + * @par + * - The output value type of `d_out` is cub::KeyValuePair `` + * (assuming the value type of `d_in` is `T`) + * - The maximum is written to `d_out.value` and its offset in the input + * array is written to `d_out.key`. + * - The `{1, std::numeric_limits::lowest()}` tuple is produced for + * zero-length inputs + * - Does not support `>` operators that are non-commutative. + * - Provides "run-to-run" determinism for pseudo-associative reduction + * (e.g., addition of floating point types) on the same GPU device. + * However, results for pseudo-associative reduction may be inconsistent + * from one device to a another device of a different compute-capability + * because CUB can employ different tile-sizing for different architectures. + * - The range `[d_in, d_in + num_items)` shall not overlap `d_out`. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the argmax-reduction of a device vector + * of `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_items; // e.g., 7 + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * KeyValuePair *d_out; // e.g., [{-,-}] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceReduce::ArgMax( + * d_temp_storage, temp_storage_bytes, d_in, d_argmax, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run argmax-reduction + * cub::DeviceReduce::ArgMax( + * d_temp_storage, temp_storage_bytes, d_in, d_argmax, num_items); + * + * // d_out <-- [{6, 9}] + * + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input items + * (of some type \p T) \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced aggregate + * (having value type `cub::KeyValuePair`) \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t ArgMax(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + // The input type + using InputValueT = cub::detail::value_t; + + // The output tuple type + using OutputTupleT = + cub::detail::non_void_value_t>; + + using AccumT = OutputTupleT; + + // The output value type + using OutputValueT = typename OutputTupleT::Value; + + using InitT = detail::reduce::empty_problem_init_t; + + // Wrapped input iterator to produce index-value tuples + using ArgIndexInputIteratorT = + ArgIndexInputIterator; + + ArgIndexInputIteratorT d_indexed_in(d_in); + + // Initial value + // TODO Address https://github.com/NVIDIA/cub/issues/651 + InitT initial_value{AccumT(1, Traits::Lowest())}; + + return DispatchReduce::Dispatch(d_temp_storage, + temp_storage_bytes, + d_indexed_in, + d_out, + num_items, + cub::ArgMax(), + initial_value, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t ArgMax(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ArgMax(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_items, + stream); + } + + /** + * @brief Reduces segments of values, where segments are demarcated by + * corresponding runs of identical keys. + * + * @par + * This operation computes segmented reductions within `d_values_in` using + * the specified binary `reduction_op` functor. The segments are identified + * by "runs" of corresponding keys in `d_keys_in`, where runs are maximal + * ranges of consecutive, identical keys. For the *i*th run + * encountered, the first key of the run and the corresponding value + * aggregate of that run are written to `d_unique_out[i] and + * `d_aggregates_out[i]`, respectively. The total number of runs encountered + * is written to `d_num_runs_out`. + * + * @par + * - The `==` equality operator is used to determine whether keys are + * equivalent + * - Provides "run-to-run" determinism for pseudo-associative reduction + * (e.g., addition of floating point types) on the same GPU device. + * However, results for pseudo-associative reduction may be inconsistent + * from one device to a another device of a different compute-capability + * because CUB can employ different tile-sizing for different architectures. + * - Let `out` be any of + * `[d_unique_out, d_unique_out + *d_num_runs_out)` + * `[d_aggregates_out, d_aggregates_out + *d_num_runs_out)` + * `d_num_runs_out`. The ranges represented by `out` shall not overlap + * `[d_keys_in, d_keys_in + num_items)`, + * `[d_values_in, d_values_in + num_items)` nor `out` in any way. + * - @devicestorage + * + * @par Performance + * The following chart illustrates reduction-by-key (sum) performance across + * different CUDA architectures for `fp32` and `fp64` values, respectively. + * Segments are identified by `int32` keys, and have lengths uniformly + * sampled from `[1, 1000]`. + * + * @image html reduce_by_key_fp32_len_500.png + * @image html reduce_by_key_fp64_len_500.png + * + * @par + * The following charts are similar, but with segment lengths uniformly + * sampled from [1,10]: + * + * @image html reduce_by_key_fp32_len_5.png + * @image html reduce_by_key_fp64_len_5.png + * + * @par Snippet + * The code snippet below illustrates the segmented reduction of `int` values + * grouped by runs of associated `int` keys. + * @par + * @code + * #include + * // or equivalently + * + * // CustomMin functor + * struct CustomMin + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return (b < a) ? b : a; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_items; // e.g., 8 + * int *d_keys_in; // e.g., [0, 2, 2, 9, 5, 5, 5, 8] + * int *d_values_in; // e.g., [0, 7, 1, 6, 2, 5, 3, 4] + * int *d_unique_out; // e.g., [-, -, -, -, -, -, -, -] + * int *d_aggregates_out; // e.g., [-, -, -, -, -, -, -, -] + * int *d_num_runs_out; // e.g., [-] + * CustomMin reduction_op; + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceReduce::ReduceByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_unique_out, d_values_in, + * d_aggregates_out, d_num_runs_out, reduction_op, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run reduce-by-key + * cub::DeviceReduce::ReduceByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_unique_out, d_values_in, + * d_aggregates_out, d_num_runs_out, reduction_op, num_items); + * + * // d_unique_out <-- [0, 2, 9, 5, 8] + * // d_aggregates_out <-- [0, 1, 6, 2, 4] + * // d_num_runs_out <-- [5] + * @endcode + * + * @tparam KeysInputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * keys \iterator + * + * @tparam UniqueOutputIteratorT + * **[inferred]** Random-access output iterator type for writing unique + * output keys \iterator + * + * @tparam ValuesInputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * values \iterator + * + * @tparam AggregatesOutputIterator + * **[inferred]** Random-access output iterator type for writing output + * value aggregates \iterator + * + * @tparam NumRunsOutputIteratorT + * **[inferred]** Output iterator type for recording the number of runs + * encountered \iterator + * + * @tparam ReductionOpT + * **[inferred]*8 Binary reduction functor type having member + * `T operator()(const T &a, const T &b)` + * + * @tparam NumItemsT **[inferred]** Type of num_items + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Pointer to the input sequence of keys + * + * @param[out] d_unique_out + * Pointer to the output sequence of unique keys (one key per run) + * + * @param[in] d_values_in + * Pointer to the input sequence of corresponding values + * + * @param[out] d_aggregates_out + * Pointer to the output sequence of value aggregates + * (one aggregate per run) + * + * @param[out] d_num_runs_out + * Pointer to total number of runs encountered + * (i.e., the length of `d_unique_out`) + * + * @param[in] reduction_op + * Binary reduction functor + * + * @param[in] num_items + * Total number of associated key+value pairs + * (i.e., the length of `d_in_keys` and `d_in_values`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + ReduceByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + UniqueOutputIteratorT d_unique_out, + ValuesInputIteratorT d_values_in, + AggregatesOutputIteratorT d_aggregates_out, + NumRunsOutputIteratorT d_num_runs_out, + ReductionOpT reduction_op, + NumItemsT num_items, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = typename detail::ChooseOffsetT::Type; + + // FlagT iterator type (not used) + + // Selection op (not used) + + // Default == operator + typedef Equality EqualityOp; + + return DispatchReduceByKey::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_unique_out, + d_values_in, + d_aggregates_out, + d_num_runs_out, + EqualityOp(), + reduction_op, + static_cast(num_items), + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + ReduceByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + UniqueOutputIteratorT d_unique_out, + ValuesInputIteratorT d_values_in, + AggregatesOutputIteratorT d_aggregates_out, + NumRunsOutputIteratorT d_num_runs_out, + ReductionOpT reduction_op, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ReduceByKey(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_unique_out, + d_values_in, + d_aggregates_out, + d_num_runs_out, + reduction_op, + num_items, + stream); + } +}; + +/** + * @example example_device_reduce.cu + */ + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_run_length_encode.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_run_length_encode.cuh new file mode 100644 index 0000000000000000000000000000000000000000..2a8a546bd3868959765600a2bc22c0d2263e6d20 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_run_length_encode.cuh @@ -0,0 +1,451 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::DeviceRunLengthEncode provides device-wide, parallel operations + * for computing a run-length encoding across a sequence of data items + * residing within device-accessible memory. + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include + +#include + +CUB_NAMESPACE_BEGIN + + +/** + * @brief DeviceRunLengthEncode provides device-wide, parallel operations for + * demarcating "runs" of same-valued items within a sequence residing + * within device-accessible memory. ![](run_length_encode_logo.png) + * @ingroup SingleModule + * + * @par Overview + * A *run-length encoding* + * computes a simple compressed representation of a sequence of input elements + * such that each maximal "run" of consecutive same-valued data items is + * encoded as a single data value along with a count of the elements in that + * run. + * + * @par Usage Considerations + * @cdp_class{DeviceRunLengthEncode} + * + * @par Performance + * @linear_performance{run-length encode} + * + * @par + * The following chart illustrates DeviceRunLengthEncode::RunLengthEncode + * performance across different CUDA architectures for `int32` items. + * Segments have lengths uniformly sampled from `[1, 1000]`. + * + * @image html rle_int32_len_500.png + * + * @par + * @plots_below + */ +struct DeviceRunLengthEncode +{ + /** + * @brief Computes a run-length encoding of the sequence \p d_in. + * + * @par + * - For the *i*th run encountered, the first key of the run and + * its length are written to `d_unique_out[i]` and `d_counts_out[i]`, + * respectively. + * - The total number of runs encountered is written to `d_num_runs_out`. + * - The `==` equality operator is used to determine whether values are + * equivalent + * - In-place operations are not supported. There must be no overlap between + * any of the provided ranges: + * - `[d_unique_out, d_unique_out + *d_num_runs_out)` + * - `[d_counts_out, d_counts_out + *d_num_runs_out)` + * - `[d_num_runs_out, d_num_runs_out + 1)` + * - `[d_in, d_in + num_items)` + * - @devicestorage + * + * @par Performance + * The following charts illustrate saturated encode performance across + * different CUDA architectures for `int32` and `int64` items, respectively. + * Segments have lengths uniformly sampled from [1,1000]. + * + * @image html rle_int32_len_500.png + * @image html rle_int64_len_500.png + * + * @par + * The following charts are similar, but with segment lengths uniformly + * sampled from [1,10]: + * + * @image html rle_int32_len_5.png + * @image html rle_int64_len_5.png + * + * @par Snippet + * The code snippet below illustrates the run-length encoding of a sequence + * of `int` values. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 8 + * int *d_in; // e.g., [0, 2, 2, 9, 5, 5, 5, 8] + * int *d_unique_out; // e.g., [ , , , , , , , ] + * int *d_counts_out; // e.g., [ , , , , , , , ] + * int *d_num_runs_out; // e.g., [ ] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceRunLengthEncode::Encode( + * d_temp_storage, temp_storage_bytes, + * d_in, d_unique_out, d_counts_out, d_num_runs_out, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run encoding + * cub::DeviceRunLengthEncode::Encode( + * d_temp_storage, temp_storage_bytes, + * d_in, d_unique_out, d_counts_out, d_num_runs_out, num_items); + * + * // d_unique_out <-- [0, 2, 9, 5, 8] + * // d_counts_out <-- [1, 2, 1, 3, 1] + * // d_num_runs_out <-- [5] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam UniqueOutputIteratorT + * **[inferred]** Random-access output iterator type for writing unique + * output items \iterator + * + * @tparam LengthsOutputIteratorT + * **[inferred]** Random-access output iterator type for writing output + * counts \iterator + * + * @tparam NumRunsOutputIteratorT + * **[inferred]** Output iterator type for recording the number of runs + * encountered \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of keys + * + * @param[out] d_unique_out + * Pointer to the output sequence of unique keys (one key per run) + * + * @param[out] d_counts_out + * Pointer to the output sequence of run-lengths (one count per run) + * + * @param[out] d_num_runs_out + * Pointer to total number of runs + * + * @param[in] num_items + * Total number of associated key+value pairs (i.e., the length of + * `d_in_keys` and `d_in_values`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Encode(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + UniqueOutputIteratorT d_unique_out, + LengthsOutputIteratorT d_counts_out, + NumRunsOutputIteratorT d_num_runs_out, + int num_items, + cudaStream_t stream = 0) + { + using offset_t = int; // Signed integer type for global offsets + using equality_op = Equality; // Default == operator + using reduction_op = cub::Sum; // Value reduction operator + + // The lengths output value type + using length_t = + cub::detail::non_void_value_t; + + // Generator type for providing 1s values for run-length reduction + using lengths_input_iterator_t = ConstantInputIterator; + + using accum_t = detail::accumulator_t; + + using key_t = + cub::detail::non_void_value_t>; + + using policy_t = detail::device_run_length_encode_policy_hub; + + return DispatchReduceByKey::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_unique_out, + lengths_input_iterator_t((length_t)1), + d_counts_out, + d_num_runs_out, + equality_op(), + reduction_op(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Encode(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + UniqueOutputIteratorT d_unique_out, + LengthsOutputIteratorT d_counts_out, + NumRunsOutputIteratorT d_num_runs_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Encode(d_temp_storage, + temp_storage_bytes, + d_in, + d_unique_out, + d_counts_out, + d_num_runs_out, + num_items, + stream); + } + + /** + * @brief Enumerates the starting offsets and lengths of all non-trivial runs + * (of `length > 1`) of same-valued keys in the sequence `d_in`. + * + * @par + * - For the *i*th non-trivial run, the run's starting offset and + * its length are written to `d_offsets_out[i]` and `d_lengths_out[i]`, + * respectively. + * - The total number of runs encountered is written to `d_num_runs_out`. + * - The `==` equality operator is used to determine whether values are + * equivalent + * - In-place operations are not supported. There must be no overlap between + * any of the provided ranges: + * - `[d_offsets_out, d_offsets_out + *d_num_runs_out)` + * - `[d_lengths_out, d_lengths_out + *d_num_runs_out)` + * - `[d_num_runs_out, d_num_runs_out + 1)` + * - `[d_in, d_in + num_items)` + * - @devicestorage + * + * @par Performance + * + * @par Snippet + * The code snippet below illustrates the identification of non-trivial runs + * within a sequence of `int` values. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_items; // e.g., 8 + * int *d_in; // e.g., [0, 2, 2, 9, 5, 5, 5, 8] + * int *d_offsets_out; // e.g., [ , , , , , , , ] + * int *d_lengths_out; // e.g., [ , , , , , , , ] + * int *d_num_runs_out; // e.g., [ ] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceRunLengthEncode::NonTrivialRuns( + * d_temp_storage, temp_storage_bytes, + * d_in, d_offsets_out, d_lengths_out, d_num_runs_out, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run encoding + * cub::DeviceRunLengthEncode::NonTrivialRuns( + * d_temp_storage, temp_storage_bytes, + * d_in, d_offsets_out, d_lengths_out, d_num_runs_out, num_items); + * + * // d_offsets_out <-- [1, 4] + * // d_lengths_out <-- [2, 3] + * // d_num_runs_out <-- [2] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OffsetsOutputIteratorT + * **[inferred]** Random-access output iterator type for writing run-offset + * values \iterator + * + * @tparam LengthsOutputIteratorT + * **[inferred]** Random-access output iterator type for writing run-length + * values \iterator + * + * @tparam NumRunsOutputIteratorT + * **[inferred]** Output iterator type for recording the number of runs + * encountered \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to input sequence of data items + * + * @param[out] d_offsets_out + * Pointer to output sequence of run-offsets + * (one offset per non-trivial run) + * + * @param[out] d_lengths_out + * Pointer to output sequence of run-lengths + * (one count per non-trivial run) + * + * @param[out] d_num_runs_out + * Pointer to total number of runs (i.e., length of `d_offsets_out`) + * + * @param[in] num_items + * Total number of associated key+value pairs (i.e., the length of + * `d_in_keys` and `d_in_values`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + NonTrivialRuns(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OffsetsOutputIteratorT d_offsets_out, + LengthsOutputIteratorT d_lengths_out, + NumRunsOutputIteratorT d_num_runs_out, + int num_items, + cudaStream_t stream = 0) + { + using OffsetT = int; // Signed integer type for global offsets + using EqualityOp = Equality; // Default == operator + + return DeviceRleDispatch::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_offsets_out, + d_lengths_out, + d_num_runs_out, + EqualityOp(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + NonTrivialRuns(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OffsetsOutputIteratorT d_offsets_out, + LengthsOutputIteratorT d_lengths_out, + NumRunsOutputIteratorT d_num_runs_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return NonTrivialRuns(d_temp_storage, + temp_storage_bytes, + d_in, + d_offsets_out, + d_lengths_out, + d_num_runs_out, + num_items, + stream); + } +}; + +CUB_NAMESPACE_END + + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_scan.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_scan.cuh new file mode 100644 index 0000000000000000000000000000000000000000..20cb8ba872fe4db1430236e35080961269736276 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_scan.cuh @@ -0,0 +1,2268 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::DeviceScan provides device-wide, parallel operations for + * computing a prefix scan across a sequence of data items residing + * within device-accessible memory. + */ + +#pragma once + +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * @brief DeviceScan provides device-wide, parallel operations for computing a + * prefix scan across a sequence of data items residing within + * device-accessible memory. ![](device_scan.png) + * + * @ingroup SingleModule + * + * @par Overview + * Given a sequence of input elements and a binary reduction operator, a + * [*prefix scan*](http://en.wikipedia.org/wiki/Prefix_sum) produces an output + * sequence where each element is computed to be the reduction of the elements + * occurring earlier in the input sequence. *Prefix sum* connotes a prefix scan + * with the addition operator. The term *inclusive* indicates that the + * *i*th output reduction incorporates the *i*th input. + * The term *exclusive* indicates the *i*th input is not + * incorporated into the *i*th output reduction. When the input and + * output sequences are the same, the scan is performed in-place. + * + * @par + * As of CUB 1.0.1 (2013), CUB's device-wide scan APIs have implemented our + * *"decoupled look-back"* algorithm for performing global prefix scan with + * only a single pass through the input data, as described in our 2016 technical + * report [1]. The central idea is to leverage a small, constant factor of + * redundant work in order to overlap the latencies of global prefix + * propagation with local computation. As such, our algorithm requires only + * ~2*n* data movement (*n* inputs are read, *n* outputs are written), and + * typically proceeds at "memcpy" speeds. Our algorithm supports inplace + * operations. + * + * @par + * [1] [Duane Merrill and Michael Garland. "Single-pass Parallel Prefix Scan with Decoupled Look-back", NVIDIA Technical Report NVR-2016-002, 2016.](https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back) + * + * @par Usage Considerations + * @cdp_class{DeviceScan} + * + * @par Performance + * @linear_performance{prefix scan} + * + * @par + * The following chart illustrates DeviceScan::ExclusiveSum performance across + * different CUDA architectures for `int32` keys. + * @plots_below + * + * @image html scan_int32.png + * + */ +struct DeviceScan +{ + /******************************************************************//** + * \name Exclusive scans + *********************************************************************/ + //@{ + + /** + * @brief Computes a device-wide exclusive prefix sum. The value of `0` is + * applied as the initial value, and is assigned to `*d_out`. + * + * @par + * - Supports non-commutative sum operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - When `d_in` and `d_out` are equal, the scan is performed in-place. The + * range `[d_in, d_in + num_items)` and `[d_out, d_out + num_items)` + * shall not overlap in any other way. + * - @devicestorage + * + * @par Performance + * The following charts illustrate saturated exclusive sum performance across + * different CUDA architectures for `int32` and `int64` items, respectively. + * + * @image html scan_int32.png + * @image html scan_int64.png + * + * @par Snippet + * The code snippet below illustrates the exclusive prefix sum of an `int` + * device vector. + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [ , , , , , , ] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::ExclusiveSum( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run exclusive prefix sum + * cub::DeviceScan::ExclusiveSum( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, num_items); + * + * // d_out <-- [0, 8, 14, 21, 26, 29, 29] + * + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading scan + * inputs \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Random-access output iterator type for writing scan + * outputs \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Random-access iterator to the input sequence of data items + * + * @param[out] d_out + * Random-access iterator to the output sequence of data items + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveSum(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + using InitT = cub::detail::value_t; + + // Initial value + InitT init_value{}; + + return DispatchScan< + InputIteratorT, OutputIteratorT, Sum, detail::InputValue, + OffsetT>::Dispatch(d_temp_storage, temp_storage_bytes, d_in, d_out, + Sum(), detail::InputValue(init_value), + num_items, stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveSum(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ExclusiveSum(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_items, + stream); + } + + /** + * @brief Computes a device-wide exclusive prefix sum in-place. The value of + * `0` is applied as the initial value, and is assigned to `*d_data`. + * + * @par + * - Supports non-commutative sum operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - @devicestorage + * + * @par Performance + * The following charts illustrate saturated exclusive sum performance across + * different CUDA architectures for `int32` and `int64` items, respectively. + * + * @image html scan_int32.png + * @image html scan_int64.png + * + * @par Snippet + * The code snippet below illustrates the exclusive prefix sum of an `int` + * device vector. + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_data; // e.g., [8, 6, 7, 5, 3, 0, 9] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::ExclusiveSum( + * d_temp_storage, temp_storage_bytes, + * d_data, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run exclusive prefix sum + * cub::DeviceScan::ExclusiveSum( + * d_temp_storage, temp_storage_bytes, + * d_data, num_items); + * + * // d_data <-- [0, 8, 14, 21, 26, 29, 29] + * + * @endcode + * + * @tparam IteratorT + * **[inferred]** Random-access iterator type for reading scan + * inputs and wrigin scan outputs + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_data + * Random-access iterator to the sequence of data items + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveSum(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + int num_items, + cudaStream_t stream = 0) + { + return ExclusiveSum(d_temp_storage, + temp_storage_bytes, + d_data, + d_data, + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveSum(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ExclusiveSum(d_temp_storage, + temp_storage_bytes, + d_data, + num_items, + stream); + } + + /** + * @brief Computes a device-wide exclusive prefix scan using the specified + * binary `scan_op` functor. The `init_value` value is applied as + * the initial value, and is assigned to `*d_out`. + * + * @par + * - Supports non-commutative scan operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - When `d_in` and `d_out` are equal, the scan is performed in-place. The + * range `[d_in, d_in + num_items)` and `[d_out, d_out + num_items)` + * shall not overlap in any other way. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the exclusive prefix min-scan of an + * `int` device vector + * @par + * @code + * #include // or equivalently + * #include // for INT_MAX + * + * // CustomMin functor + * struct CustomMin + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return (b < a) ? b : a; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [ , , , , , , ] + * CustomMin min_op; + * ... + * + * // Determine temporary device storage requirements for exclusive + * // prefix scan + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::ExclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, min_op, (int) INT_MAX, num_items); + * + * // Allocate temporary storage for exclusive prefix scan + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run exclusive prefix min-scan + * cub::DeviceScan::ExclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, min_op, (int) INT_MAX, num_items); + * + * // d_out <-- [2147483647, 8, 6, 6, 5, 3, 0] + * + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading scan + * inputs \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Random-access output iterator type for writing scan + * outputs \iterator + * + * @tparam ScanOp + * **[inferred]** Binary scan functor type having member + * `T operator()(const T &a, const T &b)` + * + * @tparam InitValueT + * **[inferred]** Type of the `init_value` used Binary scan functor type + * having member `T operator()(const T &a, const T &b)` + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Random-access iterator to the input sequence of data items + * + * @param[out] d_out + * Random-access iterator to the output sequence of data items + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] init_value + * Initial value to seed the exclusive scan (and is assigned to *d_out) + * + * @param[in] num_items + * Total number of input items (i.e., the length of \p d_in) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. Default is + * stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + ScanOpT scan_op, + InitValueT init_value, + int num_items, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int ; + + return DispatchScan, + OffsetT>::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + scan_op, + detail::InputValue( + init_value), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + ScanOpT scan_op, + InitValueT init_value, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ExclusiveScan( + d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + scan_op, + init_value, + num_items, + stream); + } + + /** + * @brief Computes a device-wide exclusive prefix scan using the specified + * binary `scan_op` functor. The `init_value` value is applied as + * the initial value, and is assigned to `*d_data`. + * + * @par + * - Supports non-commutative scan operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the exclusive prefix min-scan of an + * `int` device vector + * @par + * @code + * #include // or equivalently + * #include // for INT_MAX + * + * // CustomMin functor + * struct CustomMin + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return (b < a) ? b : a; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_data; // e.g., [8, 6, 7, 5, 3, 0, 9] + * CustomMin min_op; + * ... + * + * // Determine temporary device storage requirements for exclusive + * // prefix scan + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::ExclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_data, min_op, (int) INT_MAX, num_items); + * + * // Allocate temporary storage for exclusive prefix scan + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run exclusive prefix min-scan + * cub::DeviceScan::ExclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_data, min_op, (int) INT_MAX, num_items); + * + * // d_data <-- [2147483647, 8, 6, 6, 5, 3, 0] + * + * @endcode + * + * @tparam IteratorT + * **[inferred]** Random-access input iterator type for reading scan + * inputs and writing scan outputs + * + * @tparam ScanOp + * **[inferred]** Binary scan functor type having member + * `T operator()(const T &a, const T &b)` + * + * @tparam InitValueT + * **[inferred]** Type of the `init_value` used Binary scan functor type + * having member `T operator()(const T &a, const T &b)` + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_data + * Random-access iterator to the sequence of data items + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] init_value + * Initial value to seed the exclusive scan (and is assigned to *d_out) + * + * @param[in] num_items + * Total number of input items (i.e., the length of \p d_in) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. Default is + * stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + ScanOpT scan_op, + InitValueT init_value, + int num_items, + cudaStream_t stream = 0) + { + return ExclusiveScan(d_temp_storage, + temp_storage_bytes, + d_data, + d_data, + scan_op, + init_value, + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + ScanOpT scan_op, + InitValueT init_value, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ExclusiveScan(d_temp_storage, + temp_storage_bytes, + d_data, + scan_op, + init_value, + num_items, + stream); + } + + /** + * @brief Computes a device-wide exclusive prefix scan using the specified + * binary `scan_op` functor. The `init_value` value is provided as + * a future value. + * + * @par + * - Supports non-commutative scan operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - When `d_in` and `d_out` are equal, the scan is performed in-place. The + * range `[d_in, d_in + num_items)` and `[d_out, d_out + num_items)` + * shall not overlap in any other way. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the exclusive prefix min-scan of an + * `int` device vector + * @par + * @code + * #include // or equivalently + * #include // for INT_MAX + * + * // CustomMin functor + * struct CustomMin + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return (b < a) ? b : a; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [ , , , , , , ] + * int *d_init_iter; // e.g., INT_MAX + * CustomMin min_op; + * + * auto future_init_value = + * cub::FutureValue(d_init_iter); + * + * ... + * + * // Determine temporary device storage requirements for exclusive + * // prefix scan + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::ExclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, min_op, future_init_value, num_items); + * + * // Allocate temporary storage for exclusive prefix scan + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run exclusive prefix min-scan + * cub::DeviceScan::ExclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, min_op, future_init_value, num_items); + * + * // d_out <-- [2147483647, 8, 6, 6, 5, 3, 0] + * + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading scan + * inputs \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Random-access output iterator type for writing scan + * outputs \iterator + * + * @tparam ScanOp + * **[inferred]** Binary scan functor type having member + * `T operator()(const T &a, const T &b)` + * + * @tparam InitValueT + * **[inferred]** Type of the `init_value` used Binary scan functor type + * having member `T operator()(const T &a, const T &b)` + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of \p d_temp_storage allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output sequence of data items + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] init_value + * Initial value to seed the exclusive scan (and is assigned to `*d_out`) + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + ScanOpT scan_op, + FutureValue init_value, + int num_items, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + return DispatchScan, + OffsetT>::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + scan_op, + detail::InputValue( + init_value), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + ScanOpT scan_op, + FutureValue init_value, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ExclusiveScan(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + scan_op, + init_value, + num_items, + stream); + } + + /** + * @brief Computes a device-wide exclusive prefix scan using the specified + * binary `scan_op` functor. The `init_value` value is provided as + * a future value. + * + * @par + * - Supports non-commutative scan operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the exclusive prefix min-scan of an + * `int` device vector + * @par + * @code + * #include // or equivalently + * #include // for INT_MAX + * + * // CustomMin functor + * struct CustomMin + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return (b < a) ? b : a; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_data; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_init_iter; // e.g., INT_MAX + * CustomMin min_op; + * + * auto future_init_value = + * cub::FutureValue(d_init_iter); + * + * ... + * + * // Determine temporary device storage requirements for exclusive + * // prefix scan + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::ExclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_data, min_op, future_init_value, num_items); + * + * // Allocate temporary storage for exclusive prefix scan + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run exclusive prefix min-scan + * cub::DeviceScan::ExclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_data, min_op, future_init_value, num_items); + * + * // d_data <-- [2147483647, 8, 6, 6, 5, 3, 0] + * + * @endcode + * + * @tparam IteratorT + * **[inferred]** Random-access input iterator type for reading scan + * inputs and writing scan outputs + * + * @tparam ScanOp + * **[inferred]** Binary scan functor type having member + * `T operator()(const T &a, const T &b)` + * + * @tparam InitValueT + * **[inferred]** Type of the `init_value` used Binary scan functor type + * having member `T operator()(const T &a, const T &b)` + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of \p d_temp_storage allocation + * + * @param[in,out] d_data + * Pointer to the sequence of data items + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] init_value + * Initial value to seed the exclusive scan (and is assigned to `*d_out`) + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + ScanOpT scan_op, + FutureValue init_value, + int num_items, + cudaStream_t stream = 0) + { + return ExclusiveScan(d_temp_storage, + temp_storage_bytes, + d_data, + d_data, + scan_op, + init_value, + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + ScanOpT scan_op, + FutureValue init_value, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ExclusiveScan( + d_temp_storage, + temp_storage_bytes, + d_data, + scan_op, + init_value, + num_items, + stream); + } + + //@} end member group + /******************************************************************//** + * @name Inclusive scans + *********************************************************************/ + //@{ + + + /** + * @brief Computes a device-wide inclusive prefix sum. + * + * @par + * - Supports non-commutative sum operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - When `d_in` and `d_out` are equal, the scan is performed in-place. The + * range `[d_in, d_in + num_items)` and `[d_out, d_out + num_items)` + * shall not overlap in any other way. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the inclusive prefix sum of an `int` + * device vector. + * + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [ , , , , , , ] + * ... + * + * // Determine temporary device storage requirements for inclusive + * // prefix sum + * void *d_temp_storage = nullptr; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::InclusiveSum( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, num_items); + * + * // Allocate temporary storage for inclusive prefix sum + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run inclusive prefix sum + * cub::DeviceScan::InclusiveSum( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, num_items); + * + * // d_out <-- [8, 14, 21, 26, 29, 29, 38] + * + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading scan + * inputs \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Random-access output iterator type for writing scan + * outputs \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Random-access iterator to the input sequence of data items + * + * @param[out] d_out + * Random-access iterator to the output sequence of data items + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveSum(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + return DispatchScan::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + Sum(), + NullType(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveSum(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return InclusiveSum(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_items, + stream); + } + + /** + * @brief Computes a device-wide inclusive prefix sum in-place. + * + * @par + * - Supports non-commutative sum operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the inclusive prefix sum of an `int` + * device vector. + * + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_data; // e.g., [8, 6, 7, 5, 3, 0, 9] + * ... + * + * // Determine temporary device storage requirements for inclusive + * // prefix sum + * void *d_temp_storage = nullptr; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::InclusiveSum( + * d_temp_storage, temp_storage_bytes, + * d_data, num_items); + * + * // Allocate temporary storage for inclusive prefix sum + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run inclusive prefix sum + * cub::DeviceScan::InclusiveSum( + * d_temp_storage, temp_storage_bytes, + * d_data, num_items); + * + * // d_data <-- [8, 14, 21, 26, 29, 29, 38] + * + * @endcode + * + * @tparam IteratorT + * **[inferred]** Random-access input iterator type for reading scan + * inputs and writing scan outputs + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_data + * Random-access iterator to the sequence of data items + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveSum(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + int num_items, + cudaStream_t stream = 0) + { + return InclusiveSum(d_temp_storage, + temp_storage_bytes, + d_data, + d_data, + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveSum(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return InclusiveSum(d_temp_storage, + temp_storage_bytes, + d_data, + num_items, + stream); + } + + /** + * @brief Computes a device-wide inclusive prefix scan using the specified + * binary `scan_op` functor. + * + * @par + * - Supports non-commutative scan operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - When `d_in` and `d_out` are equal, the scan is performed in-place. The + * range `[d_in, d_in + num_items)` and `[d_out, d_out + num_items)` + * shall not overlap in any other way. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the inclusive prefix min-scan of an + * `int` device vector. + * + * @par + * @code + * #include // or equivalently + * #include // for INT_MAX + * + * // CustomMin functor + * struct CustomMin + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return (b < a) ? b : a; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [ , , , , , , ] + * CustomMin min_op; + * ... + * + * // Determine temporary device storage requirements for inclusive + * // prefix scan + * void *d_temp_storage = nullptr; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::InclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, min_op, num_items); + * + * // Allocate temporary storage for inclusive prefix scan + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run inclusive prefix min-scan + * cub::DeviceScan::InclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, min_op, num_items); + * + * // d_out <-- [8, 6, 6, 5, 3, 0, 0] + * + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading scan + * inputs \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Random-access output iterator type for writing scan + * outputs \iterator + * + * @tparam ScanOp + * **[inferred]** Binary scan functor type having member + * `T operator()(const T &a, const T &b)` + * + * @param[in] + * d_temp_storage Device-accessible allocation of temporary storage. + * When `nullptr`, the required allocation size is written to + * `temp_storage_bytes` and no work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Random-access iterator to the input sequence of data items + * + * @param[out] d_out + * Random-access iterator to the output sequence of data items + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + ScanOpT scan_op, + int num_items, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + return DispatchScan::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + scan_op, + NullType(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + ScanOpT scan_op, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return InclusiveScan( + d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + scan_op, + num_items, + stream); + } + + /** + * @brief Computes a device-wide inclusive prefix scan using the specified + * binary `scan_op` functor. + * + * @par + * - Supports non-commutative scan operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the inclusive prefix min-scan of an + * `int` device vector. + * + * @par + * @code + * #include // or equivalently + * #include // for INT_MAX + * + * // CustomMin functor + * struct CustomMin + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return (b < a) ? b : a; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_data; // e.g., [8, 6, 7, 5, 3, 0, 9] + * CustomMin min_op; + * ... + * + * // Determine temporary device storage requirements for inclusive + * // prefix scan + * void *d_temp_storage = nullptr; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::InclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_data, min_op, num_items); + * + * // Allocate temporary storage for inclusive prefix scan + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run inclusive prefix min-scan + * cub::DeviceScan::InclusiveScan( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, min_op, num_items); + * + * // d_data <-- [8, 6, 6, 5, 3, 0, 0] + * + * @endcode + * + * @tparam IteratorT + * **[inferred]** Random-access input iterator type for reading scan + * inputs and writing scan outputs + * + * @tparam ScanOp + * **[inferred]** Binary scan functor type having member + * `T operator()(const T &a, const T &b)` + * + * @param[in] + * d_temp_storage Device-accessible allocation of temporary storage. + * When `nullptr`, the required allocation size is written to + * `temp_storage_bytes` and no work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_data + * Random-access iterator to the sequence of data items + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + ScanOpT scan_op, + int num_items, + cudaStream_t stream = 0) + { + return InclusiveScan(d_temp_storage, + temp_storage_bytes, + d_data, + d_data, + scan_op, + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveScan(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + ScanOpT scan_op, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return InclusiveScan(d_temp_storage, + temp_storage_bytes, + d_data, + scan_op, + num_items, + stream); + } + + /** + * @brief Computes a device-wide exclusive prefix sum-by-key with key equality + * defined by `equality_op`. The value of `0` is applied as the initial + * value, and is assigned to the beginning of each segment in + * `d_values_out`. + * + * @par + * - Supports non-commutative sum operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - `d_keys_in` may equal `d_values_out` but the range + * `[d_keys_in, d_keys_in + num_items)` and the range + * `[d_values_out, d_values_out + num_items)` shall not overlap otherwise. + * - `d_values_in` may equal `d_values_out` but the range + * `[d_values_in, d_values_in + num_items)` and the range + * `[d_values_out, d_values_out + num_items)` shall not overlap otherwise. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the exclusive prefix sum-by-key of an + * `int` device vector. + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_keys_in; // e.g., [0, 0, 1, 1, 1, 2, 2] + * int *d_values_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_values_out; // e.g., [ , , , , , , ] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = nullptr; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::ExclusiveSumByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_values_in, d_values_out, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run exclusive prefix sum + * cub::DeviceScan::ExclusiveSumByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_values_in, d_values_out, num_items); + * + * // d_values_out <-- [0, 8, 0, 7, 12, 0, 0] + * + * @endcode + * + * @tparam KeysInputIteratorT + * **[inferred]** Random-access input iterator type for reading scan keys + * inputs \iterator + * + * @tparam ValuesInputIteratorT + * **[inferred]** Random-access input iterator type for reading scan + * values inputs \iterator + * + * @tparam ValuesOutputIteratorT + * **[inferred]** Random-access output iterator type for writing scan + * values outputs \iterator + * + * @tparam EqualityOpT + * **[inferred]** Functor type having member + * `T operator()(const T &a, const T &b)` for binary operations that + * defines the equality of keys + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Random-access input iterator to the input sequence of key items + * + * @param[in] d_values_in + * Random-access input iterator to the input sequence of value items + * + * @param[out] d_values_out + * Random-access output iterator to the output sequence of value items + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_keys_in` and + * `d_values_in`) + * + * @param[in] equality_op + * Binary functor that defines the equality of keys. + * Default is cub::Equality(). + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveSumByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + int num_items, + EqualityOpT equality_op = EqualityOpT(), + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + using InitT = cub::detail::value_t; + + // Initial value + InitT init_value{}; + + return DispatchScanByKey::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_values_out, + equality_op, + Sum(), + init_value, + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveSumByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + int num_items, + EqualityOpT equality_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ExclusiveSumByKey(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_values_out, + num_items, + equality_op, + stream); + } + + /** + * @brief Computes a device-wide exclusive prefix scan-by-key using the + * specified binary `scan_op` functor. The key equality is defined by + * `equality_op`. The `init_value` value is applied as the initial + * value, and is assigned to the beginning of each segment in + * `d_values_out`. + * + * @par + * - Supports non-commutative scan operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - `d_keys_in` may equal `d_values_out` but the range + * `[d_keys_in, d_keys_in + num_items)` and the range + * `[d_values_out, d_values_out + num_items)` shall not overlap otherwise. + * - `d_values_in` may equal `d_values_out` but the range + * `[d_values_in, d_values_in + num_items)` and the range + * `[d_values_out, d_values_out + num_items)` shall not overlap otherwise. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the exclusive prefix min-scan-by-key of + * an `int` device vector + * @par + * @code + * #include // or equivalently + * #include // for INT_MAX + * + * // CustomMin functor + * struct CustomMin + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return (b < a) ? b : a; + * } + * }; + * + * // CustomEqual functor + * struct CustomEqual + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return a == b; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_keys_in; // e.g., [0, 0, 1, 1, 1, 2, 2] + * int *d_values_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_values_out; // e.g., [ , , , , , , ] + * CustomMin min_op; + * CustomEqual equality_op; + * ... + * + * // Determine temporary device storage requirements for exclusive + * // prefix scan + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::ExclusiveScanByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_values_in, d_values_out, min_op, + * (int) INT_MAX, num_items, equality_op); + * + * // Allocate temporary storage for exclusive prefix scan + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run exclusive prefix min-scan + * cub::DeviceScan::ExclusiveScanByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_values_in, d_values_out, min_op, + * (int) INT_MAX, num_items, equality_op); + * + * // d_values_out <-- [2147483647, 8, 2147483647, 7, 5, 2147483647, 0] + * + * @endcode + * + * @tparam KeysInputIteratorT + * **[inferred]** Random-access input iterator type for reading scan keys + * inputs \iterator + * + * @tparam ValuesInputIteratorT + * **[inferred]** Random-access input iterator type for reading scan values + * inputs \iterator + * + * @tparam ValuesOutputIteratorT + * **[inferred]** Random-access output iterator type for writing scan values + * outputs \iterator + * + * @tparam ScanOp + * **[inferred]** Binary scan functor type having member + * `T operator()(const T &a, const T &b)` + * + * @tparam InitValueT + * **[inferred]** Type of the `init_value` value used in Binary scan + * functor type having member `T operator()(const T &a, const T &b)` + * + * @tparam EqualityOpT + * **[inferred]** Functor type having member + * `T operator()(const T &a, const T &b)` for binary operations that + * defines the equality of keys + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Random-access input iterator to the input sequence of key items + * + * @param[in] d_values_in + * Random-access input iterator to the input sequence of value items + * + * @param[out] d_values_out + * Random-access output iterator to the output sequence of value items + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] init_value + * Initial value to seed the exclusive scan (and is assigned to the + * beginning of each segment in `d_values_out`) + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_keys_in` and + * `d_values_in`) + * + * @param[in] equality_op + * Binary functor that defines the equality of keys. + * Default is cub::Equality(). + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveScanByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + ScanOpT scan_op, + InitValueT init_value, + int num_items, + EqualityOpT equality_op = EqualityOpT(), + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int ; + + return DispatchScanByKey::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_values_out, + equality_op, + scan_op, + init_value, + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + ExclusiveScanByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + ScanOpT scan_op, + InitValueT init_value, + int num_items, + EqualityOpT equality_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ExclusiveScanByKey(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_values_out, + scan_op, + init_value, + num_items, + equality_op, + stream); + } + + /** + * @brief Computes a device-wide inclusive prefix sum-by-key with key + * equality defined by `equality_op`. + * + * @par + * - Supports non-commutative sum operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - `d_keys_in` may equal `d_values_out` but the range + * `[d_keys_in, d_keys_in + num_items)` and the range + * `[d_values_out, d_values_out + num_items)` shall not overlap otherwise. + * - `d_values_in` may equal `d_values_out` but the range + * `[d_values_in, d_values_in + num_items)` and the range + * `[d_values_out, d_values_out + num_items)` shall not overlap otherwise. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the inclusive prefix sum-by-key of an + * `int` device vector. + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_keys_in; // e.g., [0, 0, 1, 1, 1, 2, 2] + * int *d_values_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_values_out; // e.g., [ , , , , , , ] + * ... + * + * // Determine temporary device storage requirements for inclusive prefix sum + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::InclusiveSumByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_values_in, d_values_out, num_items); + * + * // Allocate temporary storage for inclusive prefix sum + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run inclusive prefix sum + * cub::DeviceScan::InclusiveSumByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_values_in, d_values_out, num_items); + * + * // d_out <-- [8, 14, 7, 12, 15, 0, 9] + * + * @endcode + * + * @tparam KeysInputIteratorT + * **[inferred]** Random-access input iterator type for reading scan + * keys inputs \iterator + * + * @tparam ValuesInputIteratorT + * **[inferred]** Random-access input iterator type for reading scan + * values inputs \iterator + * + * @tparam ValuesOutputIteratorT + * **[inferred]** Random-access output iterator type for writing scan + * values outputs \iterator + * + * @tparam EqualityOpT + * **[inferred]** Functor type having member + * `T operator()(const T &a, const T &b)` for binary operations that + * defines the equality of keys + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. + * When `nullptr`, the required allocation size is written to + * `temp_storage_bytes` and no work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Random-access input iterator to the input sequence of key items + * + * @param[in] d_values_in + * Random-access input iterator to the input sequence of value items + * + * @param[out] d_values_out + * Random-access output iterator to the output sequence of value items + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_keys_in` and + * `d_values_in`) + * + * @param[in] equality_op + * Binary functor that defines the equality of keys. + * Default is cub::Equality(). + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveSumByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + int num_items, + EqualityOpT equality_op = EqualityOpT(), + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int ; + + return DispatchScanByKey::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_values_out, + equality_op, + Sum(), + NullType(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveSumByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + int num_items, + EqualityOpT equality_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return InclusiveSumByKey(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_values_out, + num_items, + equality_op, + stream); + } + + /** + * @brief Computes a device-wide inclusive prefix scan-by-key using the + * specified binary `scan_op` functor. The key equality is defined + * by `equality_op`. + * + * @par + * - Supports non-commutative scan operators. + * - Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. Additional details can be found in + * the [decoupled look-back] description. + * - `d_keys_in` may equal `d_values_out` but the range + * `[d_keys_in, d_keys_in + num_items)` and the range + * `[d_values_out, d_values_out + num_items)` shall not overlap otherwise. + * - `d_values_in` may equal `d_values_out` but the range + * `[d_values_in, d_values_in + num_items)` and the range + * `[d_values_out, d_values_out + num_items)` shall not overlap otherwise. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the inclusive prefix min-scan-by-key + * of an `int` device vector. + * @par + * @code + * #include // or equivalently + * #include // for INT_MAX + * + * // CustomMin functor + * struct CustomMin + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return (b < a) ? b : a; + * } + * }; + * + * // CustomEqual functor + * struct CustomEqual + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return a == b; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers for + * // input and output + * int num_items; // e.g., 7 + * int *d_keys_in; // e.g., [0, 0, 1, 1, 1, 2, 2] + * int *d_values_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_values_out; // e.g., [ , , , , , , ] + * CustomMin min_op; + * CustomEqual equality_op; + * ... + * + * // Determine temporary device storage requirements for inclusive prefix scan + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceScan::InclusiveScanByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_values_in, d_values_out, min_op, num_items, equality_op); + * + * // Allocate temporary storage for inclusive prefix scan + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run inclusive prefix min-scan + * cub::DeviceScan::InclusiveScanByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_values_in, d_values_out, min_op, num_items, equality_op); + * + * // d_out <-- [8, 6, 7, 5, 3, 0, 0] + * + * @endcode + * + * @tparam KeysInputIteratorT + * **[inferred]** Random-access input iterator type for reading scan keys + * inputs \iterator + * + * @tparam ValuesInputIteratorT + * **[inferred]** Random-access input iterator type for reading scan + * values inputs \iterator + * + * @tparam ValuesOutputIteratorT + * **[inferred]** Random-access output iterator type for writing scan + * values outputs \iterator + * + * @tparam ScanOp + * **[inferred]** Binary scan functor type having member + * `T operator()(const T &a, const T &b)` + * + * @tparam EqualityOpT + * **[inferred]** Functor type having member + * `T operator()(const T &a, const T &b)` for binary operations that + * defines the equality of keys + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. + * When `nullptr`, the required allocation size is written to + * `temp_storage_bytes` and no work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Random-access input iterator to the input sequence of key items + * + * @param[in] d_values_in + * Random-access input iterator to the input sequence of value items + * + * @param[out] d_values_out + * Random-access output iterator to the output sequence of value items + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_keys_in` and + * `d_values_in`) + * + * @param[in] equality_op + * Binary functor that defines the equality of keys. + * Default is cub::Equality(). + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + * [decoupled look-back]: https://research.nvidia.com/publication/single-pass-parallel-prefix-scan-decoupled-look-back + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveScanByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + ScanOpT scan_op, + int num_items, + EqualityOpT equality_op = EqualityOpT(), + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + return DispatchScanByKey::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_values_out, + equality_op, + scan_op, + NullType(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + InclusiveScanByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + ScanOpT scan_op, + int num_items, + EqualityOpT equality_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return InclusiveScanByKey(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_values_out, + scan_op, + num_items, + equality_op, + stream); + } + + //@} end member group +}; + +/** + * @example example_device_scan.cu + */ + +CUB_NAMESPACE_END + + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_segmented_radix_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_segmented_radix_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..9c59e59fd89e6400a76df48159ae065d8a025837 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_segmented_radix_sort.cuh @@ -0,0 +1,1740 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::DeviceSegmentedRadixSort provides device-wide, parallel + * operations for computing a batched radix sort across multiple, + * non-overlapping sequences of data items residing within + * device-accessible memory. + */ + +#pragma once + +#include +#include + +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * @brief DeviceSegmentedRadixSort provides device-wide, parallel operations + * for computing a batched radix sort across multiple, non-overlapping + * sequences of data items residing within device-accessible memory. + * ![](segmented_sorting_logo.png) + * @ingroup SegmentedModule + * + * @par Overview + * The [*radix sorting method*](http://en.wikipedia.org/wiki/Radix_sort) + * arranges items into ascending (or descending) order. The algorithm relies + * upon a positional representation for keys, i.e., each key is comprised of an + * ordered sequence of symbols (e.g., digits, characters, etc.) specified from + * least-significant to most-significant. For a given input sequence of keys + * and a set of rules specifying a total ordering of the symbolic alphabet, the + * radix sorting method produces a lexicographic ordering of those keys. + * + * @par See Also + * DeviceSegmentedRadixSort shares its implementation with DeviceRadixSort. See + * that algorithm's documentation for more information. + * + * @par Segments are not required to be contiguous. Any element of input(s) or + * output(s) outside the specified segments will not be accessed nor modified. + * + * @par Usage Considerations + * @cdp_class{DeviceSegmentedRadixSort} + * + */ +struct DeviceSegmentedRadixSort +{ + /******************************************************************//** + * @name Key-value pairs + *********************************************************************/ + //@{ + + /** + * @brief Sorts segments of key-value pairs into ascending order. + * (`~2N` auxiliary storage required) + * + * @par + * - The contents of the input data are not altered by the sorting operation + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased + * for both the `d_begin_offsets` and `d_end_offsets` parameters (where + * the latter is specified as `segment_offsets + 1`). + * - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + * bits can be specified. This can reduce overall sorting overhead and + * yield a corresponding performance improvement. + * - Let `in` be one of `{d_keys_in, d_values_in}` and `out` be any of + * `{d_keys_out, d_values_out}`. The range `[out, out + num_items)` shall + * not overlap `[in, in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - @devicestorageNP For sorting using only `O(P)` temporary storage, see + * the sorting interface using DoubleBuffer wrappers below. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_values_in[i]`, + * `d_keys_out[i]`, `d_values_out[i]` will not be accessed nor modified. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of `int` keys with associated vector of + * `int` values. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * int *d_values_in; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_values_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedRadixSort::SortPairs( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedRadixSort::SortPairs( + d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [6, 7, 8, 0, 3, 5, 9] + * // d_values_out <-- [1, 2, 0, 5, 4, 3, 6] + * @endcode + * + * @tparam KeyT + * **[inferred]** Key type + * + * @tparam ValueT + * **[inferred]** Value type + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] d_values_in + * Device-accessible pointer to the corresponding input sequence of + * associated value items + * + * @param[out] d_values_out + * Device-accessible pointer to the correspondingly-reordered output + * sequence of associated value items + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. If + * `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + * considered empty. + * + * @param[in] begin_bit + * **[optional]** The least-significant bit index (inclusive) needed for + * key comparison + * + * @param[in] end_bit + * **[optional]** The most-significant bit index (exclusive) needed for key + * comparison (e.g., `sizeof(unsigned int) * 8`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values(const_cast(d_values_in), + d_values_out); + + return DispatchSegmentedRadixSort::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + false, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairs( + d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + stream); + } + + /** + * @brief Sorts segments of key-value pairs into ascending order. + * (`~N` auxiliary storage required) + * + * @par + * - The sorting operation is given a pair of key buffers and a corresponding + * pair of associated value buffers. Each pair is managed by a DoubleBuffer + * structure that indicates which of the two buffers is "current" (and thus + * contains the input data to be sorted). + * - The contents of both buffers within each pair may be altered by the + * sorting operation. + * - Upon completion, the sorting operation will update the "current" + * indicator within each DoubleBuffer wrapper to reference which of the two + * buffers now contains the sorted output sequence (a function of the number + * of key bits specified and the targeted device architecture). + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased for both + * the `d_begin_offsets` and `d_end_offsets` parameters (where the latter is + * specified as `segment_offsets + 1`). + * - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + * bits can be specified. This can reduce overall sorting overhead and yield + * a corresponding performance improvement. + * - Let `cur` be one of `{d_keys.Current(), d_values.Current()}` and `alt` + * be any of `{d_keys.Alternate(), d_values.Alternate()}`. The range + * `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_values.Current()[i]`, `d_keys.Alternate()[i]`, + * `d_values.Alternate()[i]` will not be accessed nor modified. + * - @devicestorageP + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of `int` keys with associated vector of + * `int` values. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * int *d_value_buf; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_value_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a set of DoubleBuffers to wrap pairs of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * cub::DoubleBuffer d_values(d_value_buf, d_value_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedRadixSort::SortPairs( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedRadixSort::SortPairs( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [6, 7, 8, 0, 3, 5, 9] + * // d_values.Current() <-- [5, 4, 3, 1, 2, 0, 6] + * + * @endcode + * + * @tparam KeyT + * **[inferred]** Key type + * + * @tparam ValueT + * **[inferred]** Value type + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in,out] d_values + * Double-buffer of values whose "current" device-accessible buffer + * contains the unsorted input values and, upon return, is updated to point + * to the sorted output values + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + * considered empty. + * + * @param[in] begin_bit + * **[optional]** The least-significant bit index (inclusive) needed for + * key comparison + * + * @param[in] end_bit + * **[optional]** The most-significant bit index (exclusive) needed for key + * comparison (e.g., `sizeof(unsigned int) * 8`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + return DispatchSegmentedRadixSort::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + true, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairs( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + stream); + } + + /** + * @brief Sorts segments of key-value pairs into descending order. + * (`~2N` auxiliary storage required). + * + * @par + * - The contents of the input data are not altered by the sorting operation + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased for both + * the `d_begin_offsets` and `d_end_offsets` parameters (where the latter is + * specified as `segment_offsets + 1`). + * - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + * bits can be specified. This can reduce overall sorting overhead and + * yield a corresponding performance improvement. + * - Let `in` be one of `{d_keys_in, d_values_in}` and `out` be any of + * `{d_keys_out, d_values_out}`. The range `[out, out + num_items)` shall + * not overlap `[in, in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - @devicestorageNP For sorting using only `O(P)` temporary storage, see + * the sorting interface using DoubleBuffer wrappers below. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_values_in[i]`, + * `d_keys_out[i]`, `d_values_out[i]` will not be accessed nor modified. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of `int` keys with associated vector of + * `int` values. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * int *d_values_in; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_values_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedRadixSort::SortPairsDescending( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedRadixSort::SortPairsDescending( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [8, 7, 6, 9, 5, 3, 0] + * // d_values_out <-- [0, 2, 1, 6, 3, 4, 5] + * @endcode + * + * @tparam KeyT + * **[inferred]** Key type + * + * @tparam ValueT + * **[inferred]** Value type + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] d_values_in + * Device-accessible pointer to the corresponding input sequence of + * associated value items + * + * @param[out] d_values_out + * Device-accessible pointer to the correspondingly-reordered output + * sequence of associated value items + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th + * is considered empty. + * + * @param[in] begin_bit + * **[optional]** The least-significant bit index (inclusive) needed for + * key comparison + * + * @param[in] end_bit + * **[optional]** The most-significant bit index (exclusive) needed for key + * comparison (e.g., `sizeof(unsigned int) * 8`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values(const_cast(d_values_in), + d_values_out); + + return DispatchSegmentedRadixSort::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + false, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairsDescending(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + stream); + } + + /** + * @brief Sorts segments of key-value pairs into descending order. + * (`~N` auxiliary storage required). + * + * @par + * - The sorting operation is given a pair of key buffers and a corresponding + * pair of associated value buffers. Each pair is managed by a DoubleBuffer + * structure that indicates which of the two buffers is "current" (and thus + * contains the input data to be sorted). + * - The contents of both buffers within each pair may be altered by the + * sorting operation. + * - Upon completion, the sorting operation will update the "current" + * indicator within each DoubleBuffer wrapper to reference which of the two + * buffers now contains the sorted output sequence (a function of the number + * of key bits specified and the targeted device architecture). + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased for both + * the `d_begin_offsets` and `d_end_offsets` parameters (where the latter is + * specified as `segment_offsets + 1`). + * - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + * bits can be specified. This can reduce overall sorting overhead and + * yield a corresponding performance improvement. + * - Let `cur` be one of `{d_keys.Current(), d_values.Current()}` and `alt` + * be any of `{d_keys.Alternate(), d_values.Alternate()}`. The range + * `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_values.Current()[i]`, `d_keys.Alternate()[i]`, + * `d_values.Alternate()[i]` will not be accessed nor modified. + * not to be modified. + * - @devicestorageP + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of `int` keys with associated vector of + * `int` values. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * int *d_value_buf; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_value_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a set of DoubleBuffers to wrap pairs of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * cub::DoubleBuffer d_values(d_value_buf, d_value_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedRadixSort::SortPairsDescending( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedRadixSort::SortPairsDescending( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [8, 7, 6, 9, 5, 3, 0] + * // d_values.Current() <-- [0, 2, 1, 6, 3, 4, 5] + * @endcode + * + * @tparam KeyT + * **[inferred]** Key type + * + * @tparam ValueT + * **[inferred]** Value type + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in,out] d_values + * Double-buffer of values whose "current" device-accessible buffer + * contains the unsorted input values and, upon return, is updated to point + * to the sorted output values + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th + * is considered empty. + * + * @param[in] begin_bit + * **[optional]** The least-significant bit index (inclusive) needed for + * key comparison + * + * @param[in] end_bit + * **[optional]** The most-significant bit index (exclusive) needed for key + * comparison (e.g., `sizeof(unsigned int) * 8`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + return DispatchSegmentedRadixSort::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + true, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairsDescending(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + stream); + } + + //@} end member group + /******************************************************************//** + * @name Keys-only + *********************************************************************/ + //@{ + + + /** + * @brief Sorts segments of keys into ascending order. + * (`~2N` auxiliary storage required) + * + * @par + * - The contents of the input data are not altered by the sorting operation + * - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + * bits can be specified. This can reduce overall sorting overhead and + * yield a corresponding performance improvement. + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased for both + * the `d_begin_offsets` and `d_end_offsets` parameters (where the latter + * is specified as `segment_offsets + 1`). + * - The range `[d_keys_out, d_keys_out + num_items)` shall not overlap + * `[d_keys_in, d_keys_in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - @devicestorageNP For sorting using only `O(P)` temporary storage, see + * the sorting interface using DoubleBuffer wrappers below. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_keys_out[i]` will not + * be accessed nor modified. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of `int` keys. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedRadixSort::SortKeys( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedRadixSort::SortKeys( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [6, 7, 8, 0, 3, 5, 9] + * + * @endcode + * + * @tparam KeyT + * **[inferred]** Key type + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of \p d_temp_storage allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + * considered empty. + * + * @param[in] begin_bit + * **[optional]** The least-significant bit index (inclusive) needed for + * key comparison + * + * @param[in] end_bit + * **[optional]** The most-significant bit index (exclusive) needed for key + * comparison (e.g., `sizeof(unsigned int) * 8`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + // Null value type + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values; + + return DispatchSegmentedRadixSort::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + false, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeys( + d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + stream); + } + + /** + * @brief Sorts segments of keys into ascending order. (~N auxiliary storage required). + * + * @par + * - The sorting operation is given a pair of key buffers managed by a + * DoubleBuffer structure that indicates which of the two buffers is + * "current" (and thus contains the input data to be sorted). + * - The contents of both buffers may be altered by the sorting operation. + * - Upon completion, the sorting operation will update the "current" + * indicator within the DoubleBuffer wrapper to reference which of the two + * buffers now contains the sorted output sequence (a function of the + * number of key bits specified and the targeted device architecture). + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased for both + * the `d_begin_offsets` and `d_end_offsets` parameters (where the latter + * is specified as `segment_offsets + 1`). + * - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + * bits can be specified. This can reduce overall sorting overhead and + * yield a corresponding performance improvement. + * - Let `cur = d_keys.Current()` and `alt = d_keys.Alternate()`. + * The range `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_keys[i].Alternate()[i]` will not be accessed nor modified. + * - @devicestorageP + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of `int` keys. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a DoubleBuffer to wrap the pair of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedRadixSort::SortKeys( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedRadixSort::SortKeys( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [6, 7, 8, 0, 3, 5, 9] + * + * @endcode + * + * @tparam KeyT + * **[inferred]** Key type + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1` <= d_begin_offsets[i]`, the *i*th + * is considered empty. + * + * @param[in] begin_bit + * **[optional]** The least-significant bit index (inclusive) + * needed for key comparison + * + * @param[in] end_bit + * **[optional]** The most-significant bit index (exclusive) needed for key + * comparison (e.g., `sizeof(unsigned int) * 8`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + // Null value type + DoubleBuffer d_values; + + return DispatchSegmentedRadixSort::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + true, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeys( + d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + stream); + } + + /** + * @brief Sorts segments of keys into descending order. + * (`~2N` auxiliary storage required). + * + * @par + * - The contents of the input data are not altered by the sorting operation + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased for both + * the `d_begin_offsets` and `d_end_offsets` parameters (where the latter + * is specified as `segment_offsets + 1`). + * - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + * bits can be specified. This can reduce overall sorting overhead and + * yield a corresponding performance improvement. + * - The range `[d_keys_out, d_keys_out + num_items)` shall not overlap + * `[d_keys_in, d_keys_in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - @devicestorageNP For sorting using only `O(P)` temporary storage, see + * the sorting interface using DoubleBuffer wrappers below. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_keys_out[i]` will not + * be accessed nor modified. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of `int` keys. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a DoubleBuffer to wrap the pair of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedRadixSort::SortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedRadixSort::SortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [8, 7, 6, 9, 5, 3, 0] + * + * @endcode + * + * @tparam KeyT + * **[inferred]** Key type + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + * considered empty. + * + * @param[in] begin_bit + * **[optional]** The least-significant bit index (inclusive) needed for + * key comparison + * + * @param[in] end_bit + * **[optional]** The most-significant bit index (exclusive) needed for key + * comparison (e.g., sizeof(unsigned int) * 8) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values; + + return DispatchSegmentedRadixSort::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + false, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeysDescending( + d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + stream); + } + + /** + * @brief Sorts segments of keys into descending order. + * (`~N` auxiliary storage required). + * + * @par + * - The sorting operation is given a pair of key buffers managed by a + * DoubleBuffer structure that indicates which of the two buffers is + * "current" (and thus contains the input data to be sorted). + * - The contents of both buffers may be altered by the sorting operation. + * - Upon completion, the sorting operation will update the "current" + * indicator within the DoubleBuffer wrapper to reference which of the two + * buffers now contains the sorted output sequence (a function of the + * number of key bits specified and the targeted device architecture). + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased + * for both the `d_begin_offsets` and `d_end_offsets` parameters (where + * the latter is specified as `segment_offsets + 1`). + * - An optional bit subrange `[begin_bit, end_bit)` of differentiating key + * bits can be specified. This can reduce overall sorting overhead and + * yield a corresponding performance improvement. + * - Let `cur = d_keys.Current()` and `alt = d_keys.Alternate()`. + * The range `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_keys[i].Alternate()[i]` will not be accessed nor modified. + * - @devicestorageP + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of `int` keys. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a DoubleBuffer to wrap the pair of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedRadixSort::SortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedRadixSort::SortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [8, 7, 6, 9, 5, 3, 0] + * @endcode + * + * @tparam KeyT + * **[inferred]** Key type + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i], the *i*th is + * considered empty. + * + * @param[in] begin_bit + * **[optional]** The least-significant bit index (inclusive) needed for + * key comparison + * + * @param[in] end_bit + * **[optional]** The most-significant bit index (exclusive) needed for key + * comparison (e.g., `sizeof(unsigned int) * 8`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit = 0, + int end_bit = sizeof(KeyT) * 8, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + // Null value type + DoubleBuffer d_values; + + return DispatchSegmentedRadixSort::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + true, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit, + int end_bit, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeysDescending( + d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + stream); + } + + //@} end member group +}; + +CUB_NAMESPACE_END + + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_segmented_reduce.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_segmented_reduce.cuh new file mode 100644 index 0000000000000000000000000000000000000000..52706f2b133a3f431cd3481f00645ebebebeada9 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_segmented_reduce.cuh @@ -0,0 +1,1203 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::DeviceSegmentedReduce provides device-wide, parallel operations + * for computing a batched reduction across multiple sequences of data + * items residing within device-accessible memory. + */ + +#pragma once + +#include + +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * @brief DeviceSegmentedReduce provides device-wide, parallel operations for + * computing a reduction across multiple sequences of data items + * residing within device-accessible memory. ![](reduce_logo.png) + * @ingroup SegmentedModule + * + * @par Overview + * A *reduction* + * (or *fold*) uses a binary combining operator to compute a single aggregate + * from a sequence of input elements. + * + * @par Usage Considerations + * @cdp_class{DeviceSegmentedReduce} + * + */ +struct DeviceSegmentedReduce +{ + /** + * @brief Computes a device-wide segmented reduction using the specified + * binary `reduction_op` functor. + * + * @par + * - Does not support binary reduction operators that are non-commutative. + * - Provides "run-to-run" determinism for pseudo-associative reduction + * (e.g., addition of floating point types) on the same GPU device. + * However, results for pseudo-associative reduction may be inconsistent + * from one device to a another device of a different compute-capability + * because CUB can employ different tile-sizing for different architectures. + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased + * for both the `d_begin_offsets` and `d_end_offsets` parameters (where + * the latter is specified as `segment_offsets + 1`). + * - Let `s` be in `[0, num_segments)`. The range + * `[d_out + d_begin_offsets[s], d_out + d_end_offsets[s])` shall not + * overlap `[d_in + d_begin_offsets[s], d_in + d_end_offsets[s])`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)`. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates a custom min-reduction of a device + * vector of `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // CustomMin functor + * struct CustomMin + * { + * template + * CUB_RUNTIME_FUNCTION __forceinline__ + * T operator()(const T &a, const T &b) const { + * return (b < a) ? b : a; + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [-, -, -] + * CustomMin min_op; + * int initial_value; // e.g., INT_MAX + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedReduce::Reduce( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1, min_op, initial_value); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run reduction + * cub::DeviceSegmentedReduce::Reduce( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1, min_op, initial_value); + * + * // d_out <-- [6, INT_MAX, 0] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced + * aggregate \iterator + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @tparam ReductionOp + * **[inferred]** Binary reduction functor type having member + * `T operator()(const T &a, const T &b)` + * + * @tparam T + * **[inferred]** Data element type that is convertible to the `value` type + * of `InputIteratorT` + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of \p d_temp_storage allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + * considered empty. + * + * @param[in] reduction_op + * Binary reduction functor + * + * @param[in] initial_value + * Initial value of the reduction for each segment + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + Reduce(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + ReductionOp reduction_op, + T initial_value, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + return DispatchSegmentedReduce::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + reduction_op, + initial_value, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + Reduce(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + ReductionOp reduction_op, + T initial_value, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Reduce(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + reduction_op, + initial_value, + stream); + } + + /** + * @brief Computes a device-wide segmented sum using the addition (`+`) + * operator. + * + * @par + * - Uses `0` as the initial value of the reduction for each segment. + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased + * for both the `d_begin_offsets` and `d_end_offsets` parameters (where + * the latter is specified as `segment_offsets + 1`). + * - Does not support `+` operators that are non-commutative. + * - Let `s` be in `[0, num_segments)`. The range + * `[d_out + d_begin_offsets[s], d_out + d_end_offsets[s])` shall not + * overlap `[d_in + d_begin_offsets[s], d_in + d_end_offsets[s])`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)`. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the sum reduction of a device vector of + * `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [-, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedReduce::Sum( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sum-reduction + * cub::DeviceSegmentedReduce::Sum( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1); + * + * // d_out <-- [21, 0, 17] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced aggregate + * \iterator + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + * considered empty. + * + * @param[in] stream + * **[optional] CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + Sum(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + // The output value type + using OutputT = + cub::detail::non_void_value_t>; + + return DispatchSegmentedReduce< + InputIteratorT, + OutputIteratorT, + BeginOffsetIteratorT, + EndOffsetIteratorT, + OffsetT, + cub::Sum>::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + cub::Sum(), + OutputT(), // zero-initialize + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + Sum(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Sum(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Computes a device-wide segmented minimum using the less-than + * (`<`) operator. + * + * @par + * - Uses `std::numeric_limits::max()` as the initial value of the + * reduction for each segment. + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased for both + * the `d_begin_offsets` and `d_end_offsets` parameters (where the latter is + * specified as `segment_offsets + 1`). + * - Does not support `<` operators that are non-commutative. + * - Let `s` be in `[0, num_segments)`. The range + * `[d_out + d_begin_offsets[s], d_out + d_end_offsets[s])` shall not + * overlap `[d_in + d_begin_offsets[s], d_in + d_end_offsets[s])`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)`. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the min-reduction of a device vector of + * `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [-, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedReduce::Min( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run min-reduction + * cub::DeviceSegmentedReduce::Min( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1); + * + * // d_out <-- [6, INT_MAX, 0] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced + * aggregate \iterator + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + * considered empty. + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + Min(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + // The input value type + using InputT = cub::detail::value_t; + + return DispatchSegmentedReduce< + InputIteratorT, + OutputIteratorT, + BeginOffsetIteratorT, + EndOffsetIteratorT, + OffsetT, + cub::Min>::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + cub::Min(), + Traits::Max(), // replace with + // std::numeric_limits::max() + // when C++11 support is more + // prevalent + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + Min(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Min(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Finds the first device-wide minimum in each segment using the + * less-than ('<') operator, also returning the in-segment index of + * that item. + * + * @par + * - The output value type of `d_out` is cub::KeyValuePair `` + * (assuming the value type of `d_in` is `T`) + * - The minimum of the *i*th segment is written to + * `d_out[i].value` and its offset in that segment is written to + * `d_out[i].key`. + * - The `{1, std::numeric_limits::max()}` tuple is produced for + * zero-length inputs + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased for both + * the `d_begin_offsets` and `d_end_offsets` parameters (where the latter + * is specified as `segment_offsets + 1`). + * - Does not support `<` operators that are non-commutative. + * - Let `s` be in `[0, num_segments)`. The range + * `[d_out + d_begin_offsets[s], d_out + d_end_offsets[s])` shall not + * overlap `[d_in + d_begin_offsets[s], d_in + d_end_offsets[s])`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)`. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the argmin-reduction of a device vector + * of `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * KeyValuePair *d_out; // e.g., [{-,-}, {-,-}, {-,-}] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedReduce::ArgMin( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run argmin-reduction + * cub::DeviceSegmentedReduce::ArgMin( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1); + * + * // d_out <-- [{1,6}, {1,INT_MAX}, {2,0}] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input items + * (of some type `T`) \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced aggregate + * (having value type `KeyValuePair`) \iterator + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the + * *i*th is considered empty. + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + ArgMin(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + // The input type + using InputValueT = cub::detail::value_t; + + // The output tuple type + using OutputTupleT = + cub::detail::non_void_value_t>; + + // The output value type + using OutputValueT = typename OutputTupleT::Value; + + using AccumT = OutputTupleT; + + using InitT = detail::reduce::empty_problem_init_t; + + // Wrapped input iterator to produce index-value tuples + using ArgIndexInputIteratorT = + ArgIndexInputIterator; + + ArgIndexInputIteratorT d_indexed_in(d_in); + + // Initial value + // TODO Address https://github.com/NVIDIA/cub/issues/651 + InitT initial_value{AccumT(1, Traits::Max())}; + + return DispatchSegmentedReduce::Dispatch(d_temp_storage, + temp_storage_bytes, + d_indexed_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + cub::ArgMin(), + initial_value, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + ArgMin(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ArgMin(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Computes a device-wide segmented maximum using the greater-than + * (`>`) operator. + * + * @par + * - Uses `std::numeric_limits::lowest()` as the initial value of the + * reduction. + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased + * for both the `d_begin_offsets` and `d_end_offsets` parameters (where + * the latter is specified as `segment_offsets + 1`). + * - Does not support `>` operators that are non-commutative. + * - Let `s` be in `[0, num_segments)`. The range + * `[d_out + d_begin_offsets[s], d_out + d_end_offsets[s])` shall not + * overlap `[d_in + d_begin_offsets[s], d_in + d_end_offsets[s])`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)`. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the max-reduction of a device vector + * of `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_out; // e.g., [-, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedReduce::Max( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run max-reduction + * cub::DeviceSegmentedReduce::Max( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1); + * + * // d_out <-- [8, INT_MIN, 9] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced + * aggregate \iterator + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + * considered empty. + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + Max(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + // The input value type + using InputT = cub::detail::value_t; + + return DispatchSegmentedReduce< + InputIteratorT, + OutputIteratorT, + BeginOffsetIteratorT, + EndOffsetIteratorT, + OffsetT, + cub::Max>::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + cub::Max(), + Traits::Lowest(), // replace with + // std::numeric_limits::lowest() + // when C++11 support is + // more prevalent + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + Max(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Max(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Finds the first device-wide maximum in each segment using the + * greater-than ('>') operator, also returning the in-segment index of + * that item + * + * @par + * - The output value type of `d_out` is `cub::KeyValuePair` + * (assuming the value type of `d_in` is `T`) + * - The maximum of the *i*th segment is written to + * `d_out[i].value` and its offset in that segment is written to + * `d_out[i].key`. + * - The `{1, std::numeric_limits::lowest()}` tuple is produced for + * zero-length inputs + * - When input a contiguous sequence of segments, a single sequence + * `segment_offsets` (of length `num_segments + 1`) can be aliased + * for both the `d_begin_offsets` and `d_end_offsets` parameters (where + * the latter is specified as `segment_offsets + 1`). + * - Does not support `>` operators that are non-commutative. + * - Let `s` be in `[0, num_segments)`. The range + * `[d_out + d_begin_offsets[s], d_out + d_end_offsets[s])` shall not + * overlap `[d_in + d_begin_offsets[s], d_in + d_end_offsets[s])`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)`. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the argmax-reduction of a device vector + * of `int` data elements. + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * KeyValuePair *d_out; // e.g., [{-,-}, {-,-}, {-,-}] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedReduce::ArgMax( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run argmax-reduction + * cub::DeviceSegmentedReduce::ArgMax( + * d_temp_storage, temp_storage_bytes, d_in, d_out, + * num_segments, d_offsets, d_offsets + 1); + * + * // d_out <-- [{0,8}, {1,INT_MIN}, {3,9}] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input items + * (of some type `T`) \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Output iterator type for recording the reduced aggregate + * (having value type `KeyValuePair`) \iterator + * + * @tparam BeginOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * **[inferred]** Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + * considered empty. + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + ArgMax(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + // Signed integer type for global offsets + using OffsetT = int; + + // The input type + using InputValueT = cub::detail::value_t; + + // The output tuple type + using OutputTupleT = + cub::detail::non_void_value_t>; + + using AccumT = OutputTupleT; + + using InitT = detail::reduce::empty_problem_init_t; + + // The output value type + using OutputValueT = typename OutputTupleT::Value; + + // Wrapped input iterator to produce index-value tuples + using ArgIndexInputIteratorT = + ArgIndexInputIterator; + + ArgIndexInputIteratorT d_indexed_in(d_in); + + // Initial value + // TODO Address https://github.com/NVIDIA/cub/issues/651 + InitT initial_value{AccumT(1, Traits::Lowest())}; + + return DispatchSegmentedReduce::Dispatch(d_temp_storage, + temp_storage_bytes, + d_indexed_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + cub::ArgMax(), + initial_value, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + ArgMax(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return ArgMax(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } +}; + +CUB_NAMESPACE_END + + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_segmented_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_segmented_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..2b86da950781aecc235daa3076208dd0707a9f4b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_segmented_sort.cuh @@ -0,0 +1,3098 @@ +/****************************************************************************** + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file + * cub::DeviceSegmentedSort provides device-wide, parallel operations for + * computing a batched sort across multiple, non-overlapping sequences of + * data items residing within device-accessible memory. + */ + +#pragma once + +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * @brief DeviceSegmentedSort provides device-wide, parallel operations for + * computing a batched sort across multiple, non-overlapping sequences of + * data items residing within device-accessible memory. + * ![](segmented_sorting_logo.png) + * @ingroup SegmentedModule + * + * @par Overview + * The algorithm arranges items into ascending (or descending) order. + * The underlying sorting algorithm is undefined. Depending on the segment size, + * it might be radix sort, merge sort or something else. Therefore, no + * assumptions on the underlying implementation should be made. + * + * @par Differences from DeviceSegmentedRadixSort + * DeviceSegmentedRadixSort is optimized for significantly large segments (tens + * of thousands of items and more). Nevertheless, some domains produce a wide + * range of segment sizes. DeviceSegmentedSort partitions segments into size + * groups and specialize sorting algorithms for each group. This approach leads + * to better resource utilization in the presence of segment size imbalance or + * moderate segment sizes (up to thousands of items). + * This algorithm is more complex and consists of multiple kernels. This fact + * leads to longer compilation times as well as larger binaries sizes. + * + * @par Supported Types + * The algorithm has to satisfy the underlying algorithms restrictions. Radix + * sort usage restricts the list of supported types. Therefore, + * DeviceSegmentedSort can sort all of the built-in C++ numeric primitive types + * (`unsigned char`, `int`, `double`, etc.) as well as CUDA's `__half` and + * `__nv_bfloat16` 16-bit floating-point types. + * + * @par Segments are not required to be contiguous. Any element of input(s) or + * output(s) outside the specified segments will not be accessed nor modified. + * + * @par A simple example + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * int *d_values_in; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_values_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::SortPairs( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::SortPairs( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [6, 7, 8, 0, 3, 5, 9] + * // d_values_out <-- [1, 2, 0, 5, 4, 3, 6] + * @endcode + */ +struct DeviceSegmentedSort +{ + + /*************************************************************************//** + * @name Keys-only + ****************************************************************************/ + //@{ + + /** + * @brief Sorts segments of keys into ascending order. Approximately + * `num_items + 2*num_segments` auxiliary storage required. + * + * @par + * - The contents of the input data are not altered by the sorting operation. + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - SortKeys is not guaranteed to be stable. That is, suppose that @p i and + * @p j are equivalent: neither one is less than the other. It is not + * guaranteed that the relative order of these two elements will be + * preserved by sort. + * - The range `[d_keys_out, d_keys_out + num_items)` shall not overlap + * `[d_keys_in, d_keys_in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_keys_out[i]` will not + * be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible + * // pointers for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::SortKeys( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::SortKeys( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [6, 7, 8, 0, 3, 5, 9] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When nullptr, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + constexpr bool is_descending = false; + constexpr bool is_overwrite_okay = false; + using DispatchT = DispatchSegmentedSort; + + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values; + + return DispatchT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + is_overwrite_okay, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeys( + d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of keys into descending order. Approximately + * `num_items + 2*num_segments` auxiliary storage required. + * + * @par + * - The contents of the input data are not altered by the sorting operation. + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments + 1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets + 1`). + * - SortKeysDescending is not guaranteed to be stable. That is, suppose that + * @p i and @p j are equivalent: neither one is less than the other. It is + * not guaranteed that the relative order of these two elements will be + * preserved by sort. + * - The range `[d_keys_out, d_keys_out + num_items)` shall not overlap + * `[d_keys_in, d_keys_in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_keys_out[i]` will not + * be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::SortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::SortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [8, 7, 6, 9, 5, 3, 0] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When nullptr, the + * required allocation size is written to @p temp_storage_bytes and no + * work is done + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i] - 1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + constexpr bool is_descending = true; + constexpr bool is_overwrite_okay = false; + using DispatchT = DispatchSegmentedSort; + + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values; + + return DispatchT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + is_overwrite_okay, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeysDescending( + d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of keys into ascending order. Approximately + * `2*num_segments` auxiliary storage required. + * + * @par + * - The sorting operation is given a pair of key buffers managed by a + * DoubleBuffer structure that indicates which of the two buffers is + * "current" (and thus contains the input data to be sorted). + * - The contents of both buffers may be altered by the sorting operation. + * - Upon completion, the sorting operation will update the "current" + * indicator within the DoubleBuffer wrapper to reference which of the two + * buffers now contains the sorted output sequence (a function of the number + * of key bits and the targeted device architecture). + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - SortKeys is not guaranteed to be stable. That is, suppose that + * @p i and @p j are equivalent: neither one is less than the other. It is + * not guaranteed that the relative order of these two elements will be + * preserved by sort. + * - Let `cur = d_keys.Current()` and `alt = d_keys.Alternate()`. + * The range `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_keys[i].Alternate()[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible + * // pointers for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a DoubleBuffer to wrap the pair of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::SortKeys( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::SortKeys( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [6, 7, 8, 0, 3, 5, 9] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When nullptr, the + * required allocation size is written to @p temp_storage_bytes and no + * work is done + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` + * and `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i] - 1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + constexpr bool is_descending = false; + constexpr bool is_overwrite_okay = true; + + using DispatchT = DispatchSegmentedSort; + + DoubleBuffer d_values; + + return DispatchT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + is_overwrite_okay, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeys( + d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of keys into descending order. Approximately + * `2*num_segments` auxiliary storage required. + * + * @par + * - The sorting operation is given a pair of key buffers managed by a + * DoubleBuffer structure that indicates which of the two buffers is + * "current" (and thus contains the input data to be sorted). + * - The contents of both buffers may be altered by the sorting operation. + * - Upon completion, the sorting operation will update the "current" + * indicator within the DoubleBuffer wrapper to reference which of the two + * buffers now contains the sorted output sequence (a function of the number + * of key bits and the targeted device architecture). + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments + 1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets + 1`). + * - SortKeysDescending is not guaranteed to be stable. That is, suppose that + * @p i and @p j are equivalent: neither one is less than the other. It is + * not guaranteed that the relative order of these two elements will be + * preserved by sort. + * - Let `cur = d_keys.Current()` and `alt = d_keys.Alternate()`. + * The range `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_keys[i].Alternate()[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a DoubleBuffer to wrap the pair of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::SortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::SortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [8, 7, 6, 9, 5, 3, 0] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i] - 1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1<= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + constexpr bool is_descending = true; + constexpr bool is_overwrite_okay = true; + + using DispatchT = DispatchSegmentedSort; + + DoubleBuffer d_values; + + return DispatchT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + is_overwrite_okay, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortKeysDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortKeysDescending( + d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of keys into ascending order. Approximately + * `num_items + 2*num_segments` auxiliary storage required. + * + * @par + * - The contents of the input data are not altered by the sorting operation. + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - StableSortKeys is stable: it preserves the relative ordering of + * equivalent elements. That is, if @p x and @p y are elements such that + * @p x precedes @p y, and if the two elements are equivalent (neither + * @p x < @p y nor @p y < @p x) then a postcondition of stable sort is that + * @p x still precedes @p y. + * - The range `[d_keys_out, d_keys_out + num_items)` shall not overlap + * `[d_keys_in, d_keys_in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_keys_out[i]` will not + * be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::StableSortKeys( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::StableSortKeys( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [6, 7, 8, 0, 3, 5, 9] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When nullptr, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + return SortKeys( + d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return StableSortKeys( + d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of keys into descending order. Approximately + * `num_items + 2*num_segments` auxiliary storage required. + * + * @par + * - The contents of the input data are not altered by the sorting operation. + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - StableSortKeysDescending is stable: it preserves the relative ordering of + * equivalent elements. That is, if @p x and @p y are elements such that + * @p x precedes @p y, and if the two elements are equivalent (neither + * @p x < @p y nor @p y < @p x) then a postcondition of stable sort is that + * @p x still precedes @p y. + * - The range `[d_keys_out, d_keys_out + num_items)` shall not overlap + * `[d_keys_in, d_keys_in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_keys_out[i]` will not + * be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::StableSortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::StableSortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [8, 7, 6, 9, 5, 3, 0] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When nullptr, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortKeysDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + return SortKeysDescending(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortKeysDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return StableSortKeysDescending(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of keys into ascending order. Approximately + * `2*num_segments` auxiliary storage required. + * + * @par + * - The sorting operation is given a pair of key buffers managed by a + * DoubleBuffer structure that indicates which of the two buffers is + * "current" (and thus contains the input data to be sorted). + * - The contents of both buffers may be altered by the sorting operation. + * - Upon completion, the sorting operation will update the "current" + * indicator within the DoubleBuffer wrapper to reference which of the two + * buffers now contains the sorted output sequence (a function of the number + * of key bits and the targeted device architecture). + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - StableSortKeys is stable: it preserves the relative ordering of + * equivalent elements. That is, if @p x and @p y are elements such that + * @p x precedes @p y, and if the two elements are equivalent (neither + * @p x < @p y nor @p y < @p x) then a postcondition of stable sort is that + * @p x still precedes @p y. + * - Let `cur = d_keys.Current()` and `alt = d_keys.Alternate()`. + * The range `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_keys[i].Alternate()[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a DoubleBuffer to wrap the pair of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::StableSortKeys( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::StableSortKeys( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [6, 7, 8, 0, 3, 5, 9] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When nullptr, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i] - 1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + return SortKeys( + d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortKeys(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return StableSortKeys( + d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of keys into descending order. Approximately + * `2*num_segments` auxiliary storage required. + * + * @par + * - The sorting operation is given a pair of key buffers managed by a + * DoubleBuffer structure that indicates which of the two buffers is + * "current" (and thus contains the input data to be sorted). + * - The contents of both buffers may be altered by the sorting operation. + * - Upon completion, the sorting operation will update the "current" + * indicator within the DoubleBuffer wrapper to reference which of the two + * buffers now contains the sorted output sequence (a function of the number + * of key bits and the targeted device architecture). + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - StableSortKeysDescending is stable: it preserves the relative ordering of + * equivalent elements. That is, if @p x and @p y are elements such that + * @p x precedes @p y, and if the two elements are equivalent (neither + * @p x < @p y nor @p y < @p x) then a postcondition of stable sort is that + * @p x still precedes @p y. + * - Let `cur = d_keys.Current()` and `alt = d_keys.Alternate()`. + * The range `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_keys[i].Alternate()[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a DoubleBuffer to wrap the pair of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::StableSortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::StableSortKeysDescending( + * d_temp_storage, temp_storage_bytes, d_keys, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [8, 7, 6, 9, 5, 3, 0] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When nullptr, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that d_end_offsets[i]-1 is the last + * element of the ith data segment in `d_keys_*` and + * `d_values_*`. If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the + * i-th segment is considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortKeysDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + return SortKeysDescending(d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortKeysDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return StableSortKeysDescending(d_temp_storage, + temp_storage_bytes, + d_keys, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + //@} end member group + /*************************************************************************//** + * @name Key-value pairs + ****************************************************************************/ + //@{ + + /** + * @brief Sorts segments of key-value pairs into ascending order. + * Approximately `2*num_items + 2*num_segments` auxiliary storage + * required. + * + * @par + * - The contents of the input data are not altered by the sorting operation. + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - SortPairs is not guaranteed to be stable. That is, suppose that @p i and + * @p j are equivalent: neither one is less than the other. It is not + * guaranteed that the relative order of these two elements will be + * preserved by sort. + * - Let `in` be one of `{d_keys_in, d_values_in}` and `out` be any of + * `{d_keys_out, d_values_out}`. The range `[out, out + num_items)` shall + * not overlap `[in, in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_values_in[i]`, + * `d_keys_out[i]`, `d_values_out[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys with associated vector of + * @p int values. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * int *d_values_in; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_values_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::SortPairs( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::SortPairs( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [6, 7, 8, 0, 3, 5, 9] + * // d_values_out <-- [1, 2, 0, 5, 4, 3, 6] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam ValueT + * [inferred] Value type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] d_values_in + * Device-accessible pointer to the corresponding input sequence of + * associated value items + * + * @param[out] d_values_out + * Device-accessible pointer to the correspondingly-reordered output + * sequence of associated value items + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + constexpr bool is_descending = false; + constexpr bool is_overwrite_okay = false; + using DispatchT = DispatchSegmentedSort; + + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values(const_cast(d_values_in), d_values_out); + + return DispatchT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + is_overwrite_okay, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairs( + d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of key-value pairs into descending order. Approximately + * `2*num_items + 2*num_segments` auxiliary storage required. + * + * @par + * - The contents of the input data are not altered by the sorting operation. + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - SortPairs is not guaranteed to be stable. That is, suppose that @p i and + * @p j are equivalent: neither one is less than the other. It is not + * guaranteed that the relative order of these two elements will be + * preserved by sort. + * - Let `in` be one of `{d_keys_in, d_values_in}` and `out` be any of + * `{d_keys_out, d_values_out}`. The range `[out, out + num_items)` shall + * not overlap `[in, in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_values_in[i]`, + * `d_keys_out[i]`, `d_values_out[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys with associated vector of + * @p int values. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * int *d_values_in; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_values_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::SortPairsDescending( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::SortPairsDescending( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [8, 7, 6, 9, 5, 3, 0] + * // d_values_out <-- [0, 2, 1, 6, 3, 4, 5] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam ValueT + * [inferred] Value type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When nullptr, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] d_values_in + * Device-accessible pointer to the corresponding input sequence of + * associated value items + * + * @param[out] d_values_out + * Device-accessible pointer to the correspondingly-reordered output + * sequence of associated value items + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + constexpr bool is_descending = true; + constexpr bool is_overwrite_okay = false; + using DispatchT = DispatchSegmentedSort; + + DoubleBuffer d_keys(const_cast(d_keys_in), d_keys_out); + DoubleBuffer d_values(const_cast(d_values_in), d_values_out); + + return DispatchT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + is_overwrite_okay, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairsDescending(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of key-value pairs into ascending order. + * Approximately `2*num_segments` auxiliary storage required. + * + * @par + * - The sorting operation is given a pair of key buffers and a corresponding + * pair of associated value buffers. Each pair is managed by a DoubleBuffer + * structure that indicates which of the two buffers is "current" (and thus + * contains the input data to be sorted). + * - The contents of both buffers within each pair may be altered by the sorting + * operation. + * - Upon completion, the sorting operation will update the "current" indicator + * within each DoubleBuffer wrapper to reference which of the two buffers + * now contains the sorted output sequence (a function of the number of key bits + * specified and the targeted device architecture). + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - SortPairs is not guaranteed to be stable. That is, suppose that @p i and + * @p j are equivalent: neither one is less than the other. It is not + * guaranteed that the relative order of these two elements will be + * preserved by sort. + * - Let `cur` be one of `{d_keys.Current(), d_values.Current()}` and `alt` + * be any of `{d_keys.Alternate(), d_values.Alternate()}`. The range + * `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_values.Current()[i]`, `d_keys.Alternate()[i]`, + * `d_values.Alternate()[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys with associated vector of + * @p int values. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * int *d_value_buf; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_value_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a set of DoubleBuffers to wrap pairs of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * cub::DoubleBuffer d_values(d_value_buf, d_value_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::SortPairs( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::SortPairs( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [6, 7, 8, 0, 3, 5, 9] + * // d_values.Current() <-- [5, 4, 3, 1, 2, 0, 6] + * + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam ValueT + * [inferred] Value type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in,out] d_values + * Double-buffer of values whose "current" device-accessible buffer contains + * the unsorted input values and, upon return, is updated to point to the + * sorted output values + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + constexpr bool is_descending = false; + constexpr bool is_overwrite_okay = true; + using DispatchT = DispatchSegmentedSort; + + return DispatchT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + is_overwrite_okay, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairs( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of key-value pairs into descending order. + * Approximately `2*num_segments` auxiliary storage required. + * + * @par + * - The sorting operation is given a pair of key buffers and a corresponding + * pair of associated value buffers. Each pair is managed by a DoubleBuffer + * structure that indicates which of the two buffers is "current" (and thus + * contains the input data to be sorted). + * - The contents of both buffers within each pair may be altered by the + * sorting operation. + * - Upon completion, the sorting operation will update the "current" + * indicator within each DoubleBuffer wrapper to reference which of the two + * buffers now contains the sorted output sequence (a function of the number + * of key bits specified and the targeted device architecture). + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length num_segments+1) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as segment_offsets+1). + * - SortPairsDescending is not guaranteed to be stable. That is, suppose that + * @p i and @p j are equivalent: neither one is less than the other. It is + * not guaranteed that the relative order of these two elements will be + * preserved by sort. + * - Let `cur` be one of `{d_keys.Current(), d_values.Current()}` and `alt` + * be any of `{d_keys.Alternate(), d_values.Alternate()}`. The range + * `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_values.Current()[i]`, `d_keys.Alternate()[i]`, + * `d_values.Alternate()[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys with associated vector of + * @p int values. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for + * // sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * int *d_value_buf; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_value_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a set of DoubleBuffers to wrap pairs of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * cub::DoubleBuffer d_values(d_value_buf, d_value_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::SortPairsDescending( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::SortPairsDescending( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [8, 7, 6, 9, 5, 3, 0] + * // d_values.Current() <-- [0, 2, 1, 6, 3, 4, 5] + * + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam ValueT + * [inferred] Value type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When nullptr, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in,out] d_values + * Double-buffer of values whose "current" device-accessible buffer contains + * the unsorted input values and, upon return, is updated to point to the + * sorted output values + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + constexpr bool is_descending = true; + constexpr bool is_overwrite_okay = true; + using DispatchT = DispatchSegmentedSort; + + return DispatchT::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + is_overwrite_okay, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + SortPairsDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return SortPairsDescending(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of key-value pairs into ascending order. Approximately + * `2*num_items + 2*num_segments` auxiliary storage required. + * + * @par + * - The contents of the input data are not altered by the sorting operation. + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - StableSortPairs is stable: it preserves the relative ordering of + * equivalent elements. That is, if @p x and @p y are elements such that + * @p x precedes @p y, and if the two elements are equivalent (neither + * @p x < @p y nor @p y < @p x) then a postcondition of stable sort is that + * @p x still precedes @p y. + * - Let `in` be one of `{d_keys_in, d_values_in}` and `out` be any of + * `{d_keys_out, d_values_out}`. The range `[out, out + num_items)` shall + * not overlap `[in, in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_values_in[i]`, + * `d_keys_out[i]`, `d_values_out[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys with associated vector of + * @p int values. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * int *d_values_in; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_values_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::StableSortPairs( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::StableSortPairs( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [6, 7, 8, 0, 3, 5, 9] + * // d_values_out <-- [1, 2, 0, 5, 4, 3, 6] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam ValueT + * [inferred] Value type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When nullptr, the + * required allocation size is written to @p temp_storage_bytes and no work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] d_values_in + * Device-accessible pointer to the corresponding input sequence of + * associated value items + * + * @param[out] d_values_out + * Device-accessible pointer to the correspondingly-reordered output + * sequence of associated value items + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + return SortPairs(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return StableSortPairs( + d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of key-value pairs into descending order. + * Approximately `2*num_items + 2*num_segments` auxiliary + * storage required. + * + * @par + * - The contents of the input data are not altered by the sorting operation. + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - StableSortPairsDescending is stable: it preserves the relative ordering + * of equivalent elements. That is, if @p x and @p y are elements such that + * @p x precedes @p y, and if the two elements are equivalent (neither + * @p x < @p y nor @p y < @p x) then a postcondition of stable sort is that + * @p x still precedes @p y. + * - Let `in` be one of `{d_keys_in, d_values_in}` and `out` be any of + * `{d_keys_out, d_values_out}`. The range `[out, out + num_items)` shall + * not overlap `[in, in + num_items)`, + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys_in[i]`, `d_values_in[i]`, + * `d_keys_out[i]`, `d_values_out[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys with associated vector of + * @p int values. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_keys_out; // e.g., [-, -, -, -, -, -, -] + * int *d_values_in; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_values_out; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::StableSortPairsDescending( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::StableSortPairsDescending( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_keys_out, d_values_in, d_values_out, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys_out <-- [8, 7, 6, 9, 5, 3, 0] + * // d_values_out <-- [0, 2, 1, 6, 3, 4, 5] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam ValueT + * [inferred] Value type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in] d_keys_in + * Device-accessible pointer to the input data of key data to sort + * + * @param[out] d_keys_out + * Device-accessible pointer to the sorted output sequence of key data + * + * @param[in] d_values_in + * Device-accessible pointer to the corresponding input sequence of + * associated value items + * + * @param[out] d_values_out + * Device-accessible pointer to the correspondingly-reordered output + * sequence of associated value items + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortPairsDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + return SortPairsDescending(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortPairsDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return StableSortPairsDescending(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of key-value pairs into ascending order. + * Approximately `2*num_segments` auxiliary storage required. + * + * @par + * - The sorting operation is given a pair of key buffers and a corresponding + * pair of associated value buffers. Each pair is managed by a DoubleBuffer + * structure that indicates which of the two buffers is "current" (and thus + * contains the input data to be sorted). + * - The contents of both buffers within each pair may be altered by the + * sorting operation. + * - Upon completion, the sorting operation will update the "current" + * indicator within each DoubleBuffer wrapper to reference which of the two + * buffers now contains the sorted output sequence (a function of the number + * of key bits specified and the targeted device architecture). + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - StableSortPairs is stable: it preserves the relative ordering + * of equivalent elements. That is, if @p x and @p y are elements such that + * @p x precedes @p y, and if the two elements are equivalent (neither + * @p x < @p y nor @p y < @p x) then a postcondition of stable sort is that + * @p x still precedes @p y. + * - Let `cur` be one of `{d_keys.Current(), d_values.Current()}` and `alt` + * be any of `{d_keys.Alternate(), d_values.Alternate()}`. The range + * `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_values.Current()[i]`, `d_keys.Alternate()[i]`, + * `d_values.Alternate()[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys with associated vector of + * @p int values. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * int *d_value_buf; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_value_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a set of DoubleBuffers to wrap pairs of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * cub::DoubleBuffer d_values(d_value_buf, d_value_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::StableSortPairs( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::StableSortPairs( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [6, 7, 8, 0, 3, 5, 9] + * // d_values.Current() <-- [5, 4, 3, 1, 2, 0, 6] + * + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam ValueT + * [inferred] Value type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in,out] d_values + * Double-buffer of values whose "current" device-accessible buffer contains + * the unsorted input values and, upon return, is updated to point to the + * sorted output values + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + return SortPairs(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortPairs(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return StableSortPairs( + d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + /** + * @brief Sorts segments of key-value pairs into descending order. + * Approximately `2*num_segments` auxiliary storage required. + * + * @par + * - The sorting operation is given a pair of key buffers and a corresponding + * pair of associated value buffers. Each pair is managed by a DoubleBuffer + * structure that indicates which of the two buffers is "current" (and thus + * contains the input data to be sorted). + * - The contents of both buffers within each pair may be altered by the sorting + * operation. + * - Upon completion, the sorting operation will update the "current" indicator + * within each DoubleBuffer wrapper to reference which of the two buffers + * now contains the sorted output sequence (a function of the number of key bits + * specified and the targeted device architecture). + * - When the input is a contiguous sequence of segments, a single sequence + * @p segment_offsets (of length `num_segments+1`) can be aliased + * for both the @p d_begin_offsets and @p d_end_offsets parameters (where + * the latter is specified as `segment_offsets+1`). + * - StableSortPairsDescending is stable: it preserves the relative ordering + * of equivalent elements. That is, if @p x and @p y are elements such that + * @p x precedes @p y, and if the two elements are equivalent (neither + * @p x < @p y nor @p y < @p x) then a postcondition of stable sort is that + * @p x still precedes @p y. + * - Let `cur` be one of `{d_keys.Current(), d_values.Current()}` and `alt` + * be any of `{d_keys.Alternate(), d_values.Alternate()}`. The range + * `[cur, cur + num_items)` shall not overlap + * `[alt, alt + num_items)`. Both ranges shall not overlap + * `[d_begin_offsets, d_begin_offsets + num_segments)` nor + * `[d_end_offsets, d_end_offsets + num_segments)` in any way. + * - Segments are not required to be contiguous. For all index values `i` + * outside the specified segments `d_keys.Current()[i]`, + * `d_values.Current()[i]`, `d_keys.Alternate()[i]`, + * `d_values.Alternate()[i]` will not be accessed nor modified. + * + * @par Snippet + * The code snippet below illustrates the batched sorting of three segments + * (with one zero-length segment) of @p int keys with associated vector of + * @p int values. + * + * @par + * @code + * #include + * // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for sorting data + * int num_items; // e.g., 7 + * int num_segments; // e.g., 3 + * int *d_offsets; // e.g., [0, 3, 3, 7] + * int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9] + * int *d_key_alt_buf; // e.g., [-, -, -, -, -, -, -] + * int *d_value_buf; // e.g., [0, 1, 2, 3, 4, 5, 6] + * int *d_value_alt_buf; // e.g., [-, -, -, -, -, -, -] + * ... + * + * // Create a set of DoubleBuffers to wrap pairs of device pointers + * cub::DoubleBuffer d_keys(d_key_buf, d_key_alt_buf); + * cub::DoubleBuffer d_values(d_value_buf, d_value_alt_buf); + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSegmentedSort::StableSortPairsDescending( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run sorting operation + * cub::DeviceSegmentedSort::StableSortPairsDescending( + * d_temp_storage, temp_storage_bytes, d_keys, d_values, + * num_items, num_segments, d_offsets, d_offsets + 1); + * + * // d_keys.Current() <-- [8, 7, 6, 9, 5, 3, 0] + * // d_values.Current() <-- [0, 2, 1, 6, 3, 4, 5] + * @endcode + * + * @tparam KeyT + * [inferred] Key type + * + * @tparam ValueT + * [inferred] Value type + * + * @tparam BeginOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * beginning offsets \iterator + * + * @tparam EndOffsetIteratorT + * [inferred] Random-access input iterator type for reading segment + * ending offsets \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of @p d_temp_storage allocation + * + * @param[in,out] d_keys + * Reference to the double-buffer of keys whose "current" device-accessible + * buffer contains the unsorted input keys and, upon return, is updated to + * point to the sorted output keys + * + * @param[in,out] d_values + * Double-buffer of values whose "current" device-accessible buffer contains + * the unsorted input values and, upon return, is updated to point to the + * sorted output values + * + * @param[in] num_items + * The total number of items to sort (across all segments) + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length @p num_segments, such that `d_begin_offsets[i]` is the first + * element of the ith data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of + * the ith data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + * + * @param[in] stream + * [optional] CUDA stream to launch kernels within. Default is + * stream0. + */ + template + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortPairsDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream = 0) + { + return SortPairsDescending(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t + StableSortPairsDescending(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return StableSortPairsDescending(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + stream); + } + + //@} end member group + +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_select.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_select.cuh new file mode 100644 index 0000000000000000000000000000000000000000..f21431391ab2885849367af7893be00d9656bb22 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_select.cuh @@ -0,0 +1,1095 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::DeviceSelect provides device-wide, parallel operations for + * compacting selected items from sequences of data items residing within + * device-accessible memory. + */ + +#pragma once + +#include +#include + +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * @brief DeviceSelect provides device-wide, parallel operations for compacting + * selected items from sequences of data items residing within + * device-accessible memory. ![](select_logo.png) + * @ingroup SingleModule + * + * @par Overview + * These operations apply a selection criterion to selectively copy + * items from a specified input sequence to a compact output sequence. + * + * @par Usage Considerations + * @cdp_class{DeviceSelect} + * + * @par Performance + * @linear_performance{select-flagged, select-if, and select-unique} + * + * @par + * The following chart illustrates DeviceSelect::If performance across + * different CUDA architectures for `int32` items, where 50% of the items are + * randomly selected. + * + * @image html select_if_int32_50_percent.png + * + * @par + * The following chart illustrates DeviceSelect::Unique performance across + * different CUDA architectures for `int32` items where segments have lengths + * uniformly sampled from `[1, 1000]`. + * + * @image html select_unique_int32_len_500.png + * + * @par + * @plots_below + * + */ +struct DeviceSelect +{ + /** + * @brief Uses the `d_flags` sequence to selectively copy the corresponding + * items from `d_in` into `d_out`. The total number of items selected + * is written to `d_num_selected_out`. ![](select_flags_logo.png) + * + * @par + * - The value type of `d_flags` must be castable to `bool` (e.g., `bool`, + * `char`, `int`, etc.). + * - Copies of the selected items are compacted into `d_out` and maintain + * their original relative ordering. + * - The range `[d_out, d_out + *d_num_selected_out)` shall not overlap + * `[d_in, d_in + num_items)`, `[d_flags, d_flags + num_items)` nor + * `d_num_selected_out` in any way. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the compaction of items selected from + * an `int` device vector. + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for input, + * // flags, and output + * int num_items; // e.g., 8 + * int *d_in; // e.g., [1, 2, 3, 4, 5, 6, 7, 8] + * char *d_flags; // e.g., [1, 0, 0, 1, 0, 1, 1, 0] + * int *d_out; // e.g., [ , , , , , , , ] + * int *d_num_selected_out; // e.g., [ ] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSelect::Flagged( + * d_temp_storage, temp_storage_bytes, + * d_in, d_flags, d_out, d_num_selected_out, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run selection + * cub::DeviceSelect::Flagged( + * d_temp_storage, temp_storage_bytes, + * d_in, d_flags, d_out, d_num_selected_out, num_items); + * + * // d_out <-- [1, 4, 6, 7] + * // d_num_selected_out <-- [4] + * + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam FlagIterator + * **[inferred]** Random-access input iterator type for reading selection + * flags \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Random-access output iterator type for writing selected + * items \iterator + * + * @tparam NumSelectedIteratorT + * **[inferred]** Output iterator type for recording the number of items + * selected \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[in] d_flags + * Pointer to the input sequence of selection flags + * + * @param[out] d_out + * Pointer to the output sequence of selected data items + * + * @param[out] d_num_selected_out + * Pointer to the output total number of items selected + * (i.e., length of `d_out`) + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Flagged(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + FlagIterator d_flags, + OutputIteratorT d_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + cudaStream_t stream = 0) + { + using OffsetT = int; // Signed integer type for global offsets + using SelectOp = NullType; // Selection op (not used) + using EqualityOp = NullType; // Equality operator (not used) + + return DispatchSelectIf::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_flags, + d_out, + d_num_selected_out, + SelectOp(), + EqualityOp(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Flagged(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + FlagIterator d_flags, + OutputIteratorT d_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Flagged(d_temp_storage, + temp_storage_bytes, + d_in, + d_flags, + d_out, + d_num_selected_out, + num_items, + stream); + } + + /** + * @brief Uses the `d_flags` sequence to selectively compact the items in + * `d_data`. The total number of items selected is written to + * `d_num_selected_out`. ![](select_flags_logo.png) + * + * @par + * - The value type of `d_flags` must be castable to `bool` (e.g., `bool`, + * `char`, `int`, etc.). + * - Copies of the selected items are compacted in-place and maintain + * their original relative ordering. + * - The `d_data` may equal `d_flags`. The range + * `[d_data, d_data + num_items)` shall not overlap + * `[d_flags, d_flags + num_items)` in any other way. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the compaction of items selected from + * an `int` device vector. + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for input, + * // flags, and output + * int num_items; // e.g., 8 + * int *d_data; // e.g., [1, 2, 3, 4, 5, 6, 7, 8] + * char *d_flags; // e.g., [1, 0, 0, 1, 0, 1, 1, 0] + * int *d_num_selected_out; // e.g., [ ] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSelect::Flagged( + * d_temp_storage, temp_storage_bytes, + * d_in, d_flags, d_num_selected_out, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run selection + * cub::DeviceSelect::Flagged( + * d_temp_storage, temp_storage_bytes, + * d_in, d_flags, d_num_selected_out, num_items); + * + * // d_data <-- [1, 4, 6, 7] + * // d_num_selected_out <-- [4] + * + * @endcode + * + * @tparam IteratorT + * **[inferred]** Random-access iterator type for reading and writing + * selected items \iterator + * + * @tparam FlagIterator + * **[inferred]** Random-access input iterator type for reading selection + * flags \iterator + * + * @tparam NumSelectedIteratorT + * **[inferred]** Output iterator type for recording the number of items + * selected \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_data + * Pointer to the sequence of data items + * + * @param[in] d_flags + * Pointer to the input sequence of selection flags + * + * @param[out] d_num_selected_out + * Pointer to the output total number of items selected + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_data`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Flagged(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + FlagIterator d_flags, + NumSelectedIteratorT d_num_selected_out, + int num_items, + cudaStream_t stream = 0) + { + using OffsetT = int; // Signed integer type for global offsets + using SelectOp = NullType; // Selection op (not used) + using EqualityOp = NullType; // Equality operator (not used) + + constexpr bool may_alias = true; + + return DispatchSelectIf::Dispatch(d_temp_storage, + temp_storage_bytes, + d_data, // in + d_flags, + d_data, // out + d_num_selected_out, + SelectOp(), + EqualityOp(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Flagged(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + FlagIterator d_flags, + NumSelectedIteratorT d_num_selected_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Flagged( + d_temp_storage, + temp_storage_bytes, + d_data, + d_flags, + d_num_selected_out, + num_items, + stream); + } + + /** + * @brief Uses the `select_op` functor to selectively copy items from `d_in` + * into `d_out`. The total number of items selected is written to + * `d_num_selected_out`. ![](select_logo.png) + * + * @par + * - Copies of the selected items are compacted into `d_out` and maintain + * their original relative ordering. + * - The range `[d_out, d_out + *d_num_selected_out)` shall not overlap + * `[d_in, d_in + num_items)` nor `d_num_selected_out` in any way. + * - @devicestorage + * + * @par Performance + * The following charts illustrate saturated select-if performance across + * different CUDA architectures for `int32` and `int64` items, respectively. + * Items are selected with 50% probability. + * + * @image html select_if_int32_50_percent.png + * @image html select_if_int64_50_percent.png + * + * @par + * The following charts are similar, but 5% selection probability: + * + * @image html select_if_int32_5_percent.png + * @image html select_if_int64_5_percent.png + * + * @par Snippet + * The code snippet below illustrates the compaction of items selected from + * an `int` device vector. + * @par + * @code + * #include // or equivalently + * + * // Functor type for selecting values less than some criteria + * struct LessThan + * { + * int compare; + * + * CUB_RUNTIME_FUNCTION __forceinline__ + * LessThan(int compare) : compare(compare) {} + * + * CUB_RUNTIME_FUNCTION __forceinline__ + * bool operator()(const int &a) const { + * return (a < compare); + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_items; // e.g., 8 + * int *d_in; // e.g., [0, 2, 3, 9, 5, 2, 81, 8] + * int *d_out; // e.g., [ , , , , , , , ] + * int *d_num_selected_out; // e.g., [ ] + * LessThan select_op(7); + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSelect::If( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, d_num_selected_out, num_items, select_op); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run selection + * cub::DeviceSelect::If( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, d_num_selected_out, num_items, select_op); + * + * // d_out <-- [0, 2, 3, 5, 2] + * // d_num_selected_out <-- [5] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Random-access output iterator type for writing selected + * items \iterator + * + * @tparam NumSelectedIteratorT + * **[inferred]** Output iterator type for recording the number of items + * selected \iterator + * + * @tparam SelectOp + * **[inferred]** Selection operator type having member + * `bool operator()(const T &a)` + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output sequence of selected data items + * + * @param[out] d_num_selected_out + * Pointer to the output total number of items selected + * (i.e., length of `d_out`) + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param[in] select_op + * Unary selection operator + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + If(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + SelectOp select_op, + cudaStream_t stream = 0) + { + using OffsetT = int; // Signed integer type for global offsets + using FlagIterator = NullType *; // FlagT iterator type (not used) + using EqualityOp = NullType; // Equality operator (not used) + + return DispatchSelectIf::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + NULL, + d_out, + d_num_selected_out, + select_op, + EqualityOp(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + If(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + SelectOp select_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return If( + d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + d_num_selected_out, + num_items, + select_op, + stream); + } + + /** + * @brief Uses the `select_op` functor to selectively compact items in + * `d_data`. The total number of items selected is written to + * `d_num_selected_out`. ![](select_logo.png) + * + * @par + * - Copies of the selected items are compacted in `d_data` and maintain + * their original relative ordering. + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the compaction of items selected from + * an `int` device vector. + * @par + * @code + * #include // or equivalently + * + * // Functor type for selecting values less than some criteria + * struct LessThan + * { + * int compare; + * + * CUB_RUNTIME_FUNCTION __forceinline__ + * LessThan(int compare) : compare(compare) {} + * + * CUB_RUNTIME_FUNCTION __forceinline__ + * bool operator()(const int &a) const { + * return (a < compare); + * } + * }; + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_items; // e.g., 8 + * int *d_data; // e.g., [0, 2, 3, 9, 5, 2, 81, 8] + * int *d_num_selected_out; // e.g., [ ] + * LessThan select_op(7); + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSelect::If( + * d_temp_storage, temp_storage_bytes, + * d_data, d_num_selected_out, num_items, select_op); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run selection + * cub::DeviceSelect::If( + * d_temp_storage, temp_storage_bytes, + * d_data, d_num_selected_out, num_items, select_op); + * + * // d_data <-- [0, 2, 3, 5, 2] + * // d_num_selected_out <-- [5] + * @endcode + * + * @tparam IteratorT + * **[inferred]** Random-access input iterator type for reading and + * writing items \iterator + * + * @tparam NumSelectedIteratorT + * **[inferred]** Output iterator type for recording the number of items + * selected \iterator + * + * @tparam SelectOp + * **[inferred]** Selection operator type having member + * `bool operator()(const T &a)` + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in,out] d_data + * Pointer to the sequence of data items + * + * @param[out] d_num_selected_out + * Pointer to the output total number of items selected + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_data`) + * + * @param[in] select_op + * Unary selection operator + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + If(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + NumSelectedIteratorT d_num_selected_out, + int num_items, + SelectOp select_op, + cudaStream_t stream = 0) + { + using OffsetT = int; // Signed integer type for global offsets + using FlagIterator = NullType *; // FlagT iterator type (not used) + using EqualityOp = NullType; // Equality operator (not used) + + constexpr bool may_alias = true; + + return DispatchSelectIf::Dispatch(d_temp_storage, + temp_storage_bytes, + d_data, // in + NULL, + d_data, // out + d_num_selected_out, + select_op, + EqualityOp(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + If(void *d_temp_storage, + size_t &temp_storage_bytes, + IteratorT d_data, + NumSelectedIteratorT d_num_selected_out, + int num_items, + SelectOp select_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return If(d_temp_storage, + temp_storage_bytes, + d_data, + d_num_selected_out, + num_items, + select_op, + stream); + } + + /** + * @brief Given an input sequence `d_in` having runs of consecutive + * equal-valued keys, only the first key from each run is selectively + * copied to `d_out`. The total number of items selected is written to + * `d_num_selected_out`. ![](unique_logo.png) + * + * @par + * - The `==` equality operator is used to determine whether keys are + * equivalent + * - Copies of the selected items are compacted into `d_out` and maintain + * their original relative ordering. + * - The range `[d_out, d_out + *d_num_selected_out)` shall not overlap + * `[d_in, d_in + num_items)` nor `d_num_selected_out` in any way. + * - @devicestorage + * + * @par Performance + * The following charts illustrate saturated select-unique performance across different + * CUDA architectures for `int32` and `int64` items, respectively. Segments + * have lengths uniformly sampled from `[1, 1000]`. + * + * @image html select_unique_int32_len_500.png + * @image html select_unique_int64_len_500.png + * + * @par + * The following charts are similar, but with segment lengths uniformly + * sampled from `[1, 10]`: + * + * @image html select_unique_int32_len_5.png + * @image html select_unique_int64_len_5.png + * + * @par Snippet + * The code snippet below illustrates the compaction of items selected from + * an `int` device vector. + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_items; // e.g., 8 + * int *d_in; // e.g., [0, 2, 2, 9, 5, 5, 5, 8] + * int *d_out; // e.g., [ , , , , , , , ] + * int *d_num_selected_out; // e.g., [ ] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSelect::Unique( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, d_num_selected_out, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run selection + * cub::DeviceSelect::Unique( + * d_temp_storage, temp_storage_bytes, + * d_in, d_out, d_num_selected_out, num_items); + * + * // d_out <-- [0, 2, 9, 5, 8] + * // d_num_selected_out <-- [5] + * @endcode + * + * @tparam InputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * items \iterator + * + * @tparam OutputIteratorT + * **[inferred]** Random-access output iterator type for writing selected + * items \iterator + * + * @tparam NumSelectedIteratorT + * **[inferred]** Output iterator type for recording the number of items + * selected \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output sequence of selected data items + * + * @param[out] d_num_selected_out + * Pointer to the output total number of items selected + * (i.e., length of `d_out`) + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Unique(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + cudaStream_t stream = 0) + { + using OffsetT = int; // Signed integer type for global offsets + using FlagIterator = NullType *; // FlagT iterator type (not used) + using SelectOp = NullType; // Selection op (not used) + using EqualityOp = Equality; // Default == operator + + return DispatchSelectIf::Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + NULL, + d_out, + d_num_selected_out, + SelectOp(), + EqualityOp(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Unique(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Unique( + d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + d_num_selected_out, + num_items, + stream); + } + + /** + * @brief Given an input sequence `d_keys_in` and `d_values_in` with runs of + * key-value pairs with consecutive equal-valued keys, only the first + * key and its value from each run is selectively copied to + * `d_keys_out` and `d_values_out`. The total number of items selected + * is written to `d_num_selected_out`. ![](unique_logo.png) + * + * @par + * - The `==` equality operator is used to determine whether keys are + * equivalent + * - Copies of the selected items are compacted into `d_out` and maintain + * their original relative ordering. + * - In-place operations are not supported. There must be no overlap between + * any of the provided ranges: + * - `[d_keys_in, d_keys_in + num_items)` + * - `[d_keys_out, d_keys_out + *d_num_selected_out)` + * - `[d_values_in, d_values_in + num_items)` + * - `[d_values_out, d_values_out + *d_num_selected_out)` + * - `[d_num_selected_out, d_num_selected_out + 1)` + * - @devicestorage + * + * @par Snippet + * The code snippet below illustrates the compaction of items selected from + * an `int` device vector. + * @par + * @code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers + * // for input and output + * int num_items; // e.g., 8 + * int *d_keys_in; // e.g., [0, 2, 2, 9, 5, 5, 5, 8] + * int *d_values_in; // e.g., [1, 2, 3, 4, 5, 6, 7, 8] + * int *d_keys_out; // e.g., [ , , , , , , , ] + * int *d_values_out; // e.g., [ , , , , , , , ] + * int *d_num_selected_out; // e.g., [ ] + * ... + * + * // Determine temporary device storage requirements + * void *d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSelect::UniqueByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_values_in, + * d_keys_out, d_values_out, d_num_selected_out, num_items); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run selection + * cub::DeviceSelect::UniqueByKey( + * d_temp_storage, temp_storage_bytes, + * d_keys_in, d_values_in, + * d_keys_out, d_values_out, d_num_selected_out, num_items); + * + * // d_keys_out <-- [0, 2, 9, 5, 8] + * // d_values_out <-- [1, 2, 4, 5, 8] + * // d_num_selected_out <-- [5] + * @endcode + * + * @tparam KeyInputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * keys \iterator + * + * @tparam ValueInputIteratorT + * **[inferred]** Random-access input iterator type for reading input + * values \iterator + * + * @tparam KeyOutputIteratorT + * **[inferred]** Random-access output iterator type for writing selected + * keys \iterator + * + * @tparam ValueOutputIteratorT + * **[inferred]** Random-access output iterator type for writing selected + * values \iterator + * + * @tparam NumSelectedIteratorT + * **[inferred]** Output iterator type for recording the number of items + * selected \iterator + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Pointer to the input sequence of keys + * + * @param[in] d_values_in + * Pointer to the input sequence of values + * + * @param[out] d_keys_out + * Pointer to the output sequence of selected keys + * + * @param[out] d_values_out + * Pointer to the output sequence of selected values + * + * @param[out] d_num_selected_out + * Pointer to the total number of items selected (i.e., length of + * `d_keys_out` or `d_values_out`) + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_keys_in` or + * `d_values_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + UniqueByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeyInputIteratorT d_keys_in, + ValueInputIteratorT d_values_in, + KeyOutputIteratorT d_keys_out, + ValueOutputIteratorT d_values_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + cudaStream_t stream = 0) + { + using OffsetT = int; + using EqualityOp = Equality; + + return DispatchUniqueByKey::Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_keys_out, + d_values_out, + d_num_selected_out, + EqualityOp(), + num_items, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + UniqueByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeyInputIteratorT d_keys_in, + ValueInputIteratorT d_values_in, + KeyOutputIteratorT d_keys_out, + ValueOutputIteratorT d_values_out, + NumSelectedIteratorT d_num_selected_out, + int num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return UniqueByKey(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_keys_out, + d_values_out, + d_num_selected_out, + num_items, + stream); + } +}; + +/** + * @example example_device_select_flagged.cu + * @example example_device_select_if.cu + * @example example_device_select_unique.cu + */ + +CUB_NAMESPACE_END + + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_spmv.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_spmv.cuh new file mode 100644 index 0000000000000000000000000000000000000000..22dcbe5fcf540934507bcdc5d6578200b2702a6d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/device_spmv.cuh @@ -0,0 +1,197 @@ + +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::DeviceSpmv provides device-wide parallel operations for performing sparse-matrix * vector multiplication (SpMV). + */ + +#pragma once + +#include +#include +#include + +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * \brief DeviceSpmv provides device-wide parallel operations for performing sparse-matrix * dense-vector multiplication (SpMV). + * \ingroup SingleModule + * + * \par Overview + * The [SpMV computation](http://en.wikipedia.org/wiki/Sparse_matrix-vector_multiplication) + * performs the matrix-vector operation + * y = A*x + y, + * where: + * - A is an mxn sparse matrix whose non-zero structure is specified in + * [compressed-storage-row (CSR) format](http://en.wikipedia.org/wiki/Sparse_matrix#Compressed_row_Storage_.28CRS_or_CSR.29) + * (i.e., three arrays: values, row_offsets, and column_indices) + * - x and y are dense vectors + * + * \par Usage Considerations + * \cdp_class{DeviceSpmv} + * + */ +struct DeviceSpmv +{ + /******************************************************************//** + * \name CSR matrix operations + *********************************************************************/ + //@{ + + /** + * \brief This function performs the matrix-vector operation y = A*x. + * + * \par Snippet + * The code snippet below illustrates SpMV upon a 9x9 CSR matrix A + * representing a 3x3 lattice (24 non-zeros). + * + * \par + * \code + * #include // or equivalently + * + * // Declare, allocate, and initialize device-accessible pointers for input matrix A, input vector x, + * // and output vector y + * int num_rows = 9; + * int num_cols = 9; + * int num_nonzeros = 24; + * + * float* d_values; // e.g., [1, 1, 1, 1, 1, 1, 1, 1, + * // 1, 1, 1, 1, 1, 1, 1, 1, + * // 1, 1, 1, 1, 1, 1, 1, 1] + * + * int* d_column_indices; // e.g., [1, 3, 0, 2, 4, 1, 5, 0, + * // 4, 6, 1, 3, 5, 7, 2, 4, + * // 8, 3, 7, 4, 6, 8, 5, 7] + * + * int* d_row_offsets; // e.g., [0, 2, 5, 7, 10, 14, 17, 19, 22, 24] + * + * float* d_vector_x; // e.g., [1, 1, 1, 1, 1, 1, 1, 1, 1] + * float* d_vector_y; // e.g., [ , , , , , , , , ] + * ... + * + * // Determine temporary device storage requirements + * void* d_temp_storage = NULL; + * size_t temp_storage_bytes = 0; + * cub::DeviceSpmv::CsrMV(d_temp_storage, temp_storage_bytes, d_values, + * d_row_offsets, d_column_indices, d_vector_x, d_vector_y, + * num_rows, num_cols, num_nonzeros); + * + * // Allocate temporary storage + * cudaMalloc(&d_temp_storage, temp_storage_bytes); + * + * // Run SpMV + * cub::DeviceSpmv::CsrMV(d_temp_storage, temp_storage_bytes, d_values, + * d_row_offsets, d_column_indices, d_vector_x, d_vector_y, + * num_rows, num_cols, num_nonzeros); + * + * // d_vector_y <-- [2, 3, 2, 3, 4, 3, 2, 3, 2] + * + * \endcode + * + * \tparam ValueT [inferred] Matrix and vector value type (e.g., /p float, /p double, etc.) + */ + template < + typename ValueT> + CUB_RUNTIME_FUNCTION + static cudaError_t CsrMV( + void* d_temp_storage, ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t& temp_storage_bytes, ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation + const ValueT* d_values, ///< [in] Pointer to the array of \p num_nonzeros values of the corresponding nonzero elements of matrix A. + const int* d_row_offsets, ///< [in] Pointer to the array of \p m + 1 offsets demarcating the start of every row in \p d_column_indices and \p d_values (with the final entry being equal to \p num_nonzeros) + const int* d_column_indices, ///< [in] Pointer to the array of \p num_nonzeros column-indices of the corresponding nonzero elements of matrix A. (Indices are zero-valued.) + const ValueT* d_vector_x, ///< [in] Pointer to the array of \p num_cols values corresponding to the dense input vector x + ValueT* d_vector_y, ///< [out] Pointer to the array of \p num_rows values corresponding to the dense output vector y + int num_rows, ///< [in] number of rows of matrix A. + int num_cols, ///< [in] number of columns of matrix A. + int num_nonzeros, ///< [in] number of nonzero elements of matrix A. + cudaStream_t stream = 0) ///< [in] [optional] CUDA stream to launch kernels within. Default is stream0. + { + SpmvParams spmv_params; + spmv_params.d_values = d_values; + spmv_params.d_row_end_offsets = d_row_offsets + 1; + spmv_params.d_column_indices = d_column_indices; + spmv_params.d_vector_x = d_vector_x; + spmv_params.d_vector_y = d_vector_y; + spmv_params.num_rows = num_rows; + spmv_params.num_cols = num_cols; + spmv_params.num_nonzeros = num_nonzeros; + spmv_params.alpha = ValueT{1}; + spmv_params.beta = ValueT{0}; + + return DispatchSpmv::Dispatch( + d_temp_storage, + temp_storage_bytes, + spmv_params, + stream); + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION static cudaError_t CsrMV(void *d_temp_storage, + size_t &temp_storage_bytes, + const ValueT *d_values, + const int *d_row_offsets, + const int *d_column_indices, + const ValueT *d_vector_x, + ValueT *d_vector_y, + int num_rows, + int num_cols, + int num_nonzeros, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return CsrMV(d_temp_storage, + temp_storage_bytes, + d_values, + d_row_offsets, + d_column_indices, + d_vector_x, + d_vector_y, + num_rows, + num_cols, + num_nonzeros, + stream); + } + + //@} end member group +}; + + + +CUB_NAMESPACE_END + + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_adjacent_difference.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_adjacent_difference.cuh new file mode 100644 index 0000000000000000000000000000000000000000..39d58de242997220b9755df8eb9846c843df7234 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_adjacent_difference.cuh @@ -0,0 +1,403 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +CUB_NAMESPACE_BEGIN + + +template +void __global__ DeviceAdjacentDifferenceInitKernel(InputIteratorT first, + InputT *result, + OffsetT num_tiles, + int items_per_tile) +{ + const int tile_idx = static_cast(blockIdx.x * blockDim.x + threadIdx.x); + AgentDifferenceInitT::Process(tile_idx, + first, + result, + num_tiles, + items_per_tile); +} + +template +void __global__ +DeviceAdjacentDifferenceDifferenceKernel(InputIteratorT input, + InputT *first_tile_previous, + OutputIteratorT result, + DifferenceOpT difference_op, + OffsetT num_items) +{ + using ActivePolicyT = + typename ChainedPolicyT::ActivePolicy::AdjacentDifferencePolicy; + + // It is OK to introspect the return type or parameter types of the + // `operator()` function of `__device__` extended lambda within device code. + using OutputT = detail::invoke_result_t; + + using Agent = AgentDifference; + + __shared__ typename Agent::TempStorage storage; + + Agent agent(storage, + input, + first_tile_previous, + result, + difference_op, + num_items); + + int tile_idx = static_cast(blockIdx.x); + OffsetT tile_base = static_cast(tile_idx) + * ActivePolicyT::ITEMS_PER_TILE; + + agent.Process(tile_idx, tile_base); +} + +template +struct DeviceAdjacentDifferencePolicy +{ + using ValueT = typename std::iterator_traits::value_type; + + //------------------------------------------------------------------------------ + // Architecture-specific tuning policies + //------------------------------------------------------------------------------ + + struct Policy300 : ChainedPolicy<300, Policy300, Policy300> + { + using AdjacentDifferencePolicy = + AgentAdjacentDifferencePolicy<128, + Nominal8BItemsToItems(7), + BLOCK_LOAD_WARP_TRANSPOSE, + LOAD_DEFAULT, + BLOCK_STORE_WARP_TRANSPOSE>; + }; + + struct Policy350 : ChainedPolicy<350, Policy350, Policy300> + { + using AdjacentDifferencePolicy = + AgentAdjacentDifferencePolicy<128, + Nominal8BItemsToItems(7), + BLOCK_LOAD_WARP_TRANSPOSE, + MayAlias ? LOAD_CA : LOAD_LDG, + BLOCK_STORE_WARP_TRANSPOSE>; + }; + + using MaxPolicy = Policy350; +}; + +template > +struct DispatchAdjacentDifference : public SelectedPolicy +{ + using InputT = typename std::iterator_traits::value_type; + + void *d_temp_storage; + std::size_t &temp_storage_bytes; + InputIteratorT d_input; + OutputIteratorT d_output; + OffsetT num_items; + DifferenceOpT difference_op; + cudaStream_t stream; + + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchAdjacentDifference(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_input, + OutputIteratorT d_output, + OffsetT num_items, + DifferenceOpT difference_op, + cudaStream_t stream) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_input(d_input) + , d_output(d_output) + , num_items(num_items) + , difference_op(difference_op) + , stream(stream) + {} + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_DEPRECATED CUB_RUNTIME_FUNCTION __forceinline__ + DispatchAdjacentDifference(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_input, + OutputIteratorT d_output, + OffsetT num_items, + DifferenceOpT difference_op, + cudaStream_t stream, + bool debug_synchronous) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_input(d_input) + , d_output(d_output) + , num_items(num_items) + , difference_op(difference_op) + , stream(stream) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + } + + /// Invocation + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke() + { + using AdjacentDifferencePolicyT = + typename ActivePolicyT::AdjacentDifferencePolicy; + + using MaxPolicyT = typename DispatchAdjacentDifference::MaxPolicy; + + cudaError error = cudaSuccess; + + do + { + const int tile_size = AdjacentDifferencePolicyT::ITEMS_PER_TILE; + const int num_tiles = + static_cast(DivideAndRoundUp(num_items, tile_size)); + + std::size_t first_tile_previous_size = MayAlias * num_tiles * + sizeof(InputT); + + void *allocations[1] = {nullptr}; + std::size_t allocation_sizes[1] = {MayAlias * first_tile_previous_size}; + + if (CubDebug(error = AliasTemporaries(d_temp_storage, + temp_storage_bytes, + allocations, + allocation_sizes))) + { + break; + } + + if (d_temp_storage == nullptr) + { + // Return if the caller is simply requesting the size of the storage + // allocation + + if (temp_storage_bytes == 0) + { + temp_storage_bytes = 1; + } + + break; + } + + if (num_items == OffsetT{}) + { + break; + } + + auto first_tile_previous = reinterpret_cast(allocations[0]); + + if (MayAlias) + { + using AgentDifferenceInitT = + AgentDifferenceInit; + + const int init_block_size = AgentDifferenceInitT::BLOCK_THREADS; + const int init_grid_size = DivideAndRoundUp(num_tiles, init_block_size); + + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking DeviceAdjacentDifferenceInitKernel" + "<<<%d, %d, 0, %lld>>>()\n", + init_grid_size, + init_block_size, + reinterpret_cast(stream)); + #endif + + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(init_grid_size, + init_block_size, + 0, + stream) + .doit(DeviceAdjacentDifferenceInitKernel, + d_input, + first_tile_previous, + num_tiles, + tile_size); + + error = detail::DebugSyncStream(stream); + + if (CubDebug(error)) + { + break; + } + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + } + + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking DeviceAdjacentDifferenceDifferenceKernel" + "<<<%d, %d, 0, %lld>>>()\n", + num_tiles, + AdjacentDifferencePolicyT::BLOCK_THREADS, + reinterpret_cast(stream)); + #endif + + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + num_tiles, + AdjacentDifferencePolicyT::BLOCK_THREADS, + 0, + stream) + .doit(DeviceAdjacentDifferenceDifferenceKernel, + d_input, + first_tile_previous, + d_output, + difference_op, + num_items); + + error = detail::DebugSyncStream(stream); + + if (CubDebug(error)) + { + break; + } + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + } while (0); + + return error; + } + + CUB_RUNTIME_FUNCTION + static cudaError_t Dispatch(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_input, + OutputIteratorT d_output, + OffsetT num_items, + DifferenceOpT difference_op, + cudaStream_t stream) + { + using MaxPolicyT = typename DispatchAdjacentDifference::MaxPolicy; + + cudaError error = cudaSuccess; + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + // Create dispatch functor + DispatchAdjacentDifference dispatch(d_temp_storage, + temp_storage_bytes, + d_input, + d_output, + num_items, + difference_op, + stream); + + // Dispatch to chained policy + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION + static cudaError_t Dispatch(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_input, + OutputIteratorT d_output, + OffsetT num_items, + DifferenceOpT difference_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_input, + d_output, + num_items, + difference_op, + stream); + } +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_batch_memcpy.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_batch_memcpy.cuh new file mode 100644 index 0000000000000000000000000000000000000000..a8b5a1f655002afcec3752a90e737edb5fb4b7be --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_batch_memcpy.cuh @@ -0,0 +1,746 @@ +/****************************************************************************** + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::DispatchBatchMemcpy provides device-wide, parallel operations for copying data from a number + * of given source buffers to their corresponding destination buffer. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +/** + * Parameterizable tuning policy type for AgentBatchMemcpy + */ +template +struct AgentBatchMemcpyLargeBuffersPolicy +{ + /// Threads per thread block + static constexpr uint32_t BLOCK_THREADS = _BLOCK_THREADS; + /// The number of bytes each thread copies + static constexpr uint32_t BYTES_PER_THREAD = _BYTES_PER_THREAD; +}; + +/** + * Initialization kernel for tile status initialization (multi-block) + */ +template +__global__ void InitTileStateKernel(BufferOffsetScanTileStateT buffer_offset_scan_tile_state, + BlockOffsetScanTileStateT block_offset_scan_tile_state, + TileOffsetT num_tiles) +{ + // Initialize tile status + buffer_offset_scan_tile_state.InitializeStatus(num_tiles); + block_offset_scan_tile_state.InitializeStatus(num_tiles); +} + +/** + * Kernel that copies buffers that need to be copied by at least one (and potentially many) thread + * blocks. + */ +template +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::AgentLargeBufferPolicyT::BLOCK_THREADS)) + __global__ void MultiBlockBatchMemcpyKernel(InputBufferIt input_buffer_it, + OutputBufferIt output_buffer_it, + BufferSizeIteratorT buffer_sizes, + BufferTileOffsetItT buffer_tile_offsets, + TileT buffer_offset_tile, + TileOffsetT last_tile_offset) +{ + using StatusWord = typename TileT::StatusWord; + using ActivePolicyT = typename ChainedPolicyT::ActivePolicy::AgentLargeBufferPolicyT; + using BufferSizeT = cub::detail::value_t; + /// Internal load/store type. For byte-wise memcpy, a single-byte type + using AliasT = typename ::cuda::std::conditional< + IsMemcpy, + std::iterator_traits, + std::iterator_traits>>::type::value_type; + /// Types of the input and output buffers + using InputBufferT = cub::detail::value_t; + using OutputBufferT = cub::detail::value_t; + + constexpr uint32_t BLOCK_THREADS = ActivePolicyT::BLOCK_THREADS; + constexpr uint32_t ITEMS_PER_THREAD = ActivePolicyT::BYTES_PER_THREAD; + constexpr BufferSizeT TILE_SIZE = static_cast(BLOCK_THREADS * ITEMS_PER_THREAD); + + BufferOffsetT num_blev_buffers = buffer_offset_tile.LoadValid(last_tile_offset); + + uint32_t tile_id = blockIdx.x; + + // No block-level buffers => we're done here + if (num_blev_buffers == 0) + { + return; + } + + // While there's still tiles of bytes from block-level buffers to copied + do + { + __shared__ BufferOffsetT block_buffer_id; + + // Make sure thread 0 does not overwrite the buffer id before other threads have finished with + // the prior iteration of the loop + CTA_SYNC(); + + // Binary search the buffer that this tile belongs to + if (threadIdx.x == 0) + block_buffer_id = UpperBound(buffer_tile_offsets, num_blev_buffers, tile_id) - 1; + + // Make sure thread 0 has written the buffer this thread block is assigned to + CTA_SYNC(); + + const BufferOffsetT buffer_id = block_buffer_id; + + // The relative offset of this tile within the buffer it's assigned to + BufferSizeT tile_offset_within_buffer = + static_cast(tile_id - buffer_tile_offsets[buffer_id]) * TILE_SIZE; + + // If the tile has already reached beyond the work of the end of the last buffer + if (buffer_id >= num_blev_buffers - 1 && tile_offset_within_buffer > buffer_sizes[buffer_id]) + { + return; + } + + // Tiny remainders are copied without vectorizing laods + if (buffer_sizes[buffer_id] - tile_offset_within_buffer <= 32) + { + BufferSizeT thread_offset = tile_offset_within_buffer + threadIdx.x; + for (int i = 0; i < ITEMS_PER_THREAD; i++) + { + if (thread_offset < buffer_sizes[buffer_id]) + { + const auto value = read_item(input_buffer_it[buffer_id], + thread_offset); + write_item(output_buffer_it[buffer_id], + thread_offset, + value); + } + thread_offset += BLOCK_THREADS; + } + } + else + { + copy_items( + input_buffer_it[buffer_id], + output_buffer_it[buffer_id], + (cub::min)(buffer_sizes[buffer_id] - tile_offset_within_buffer, TILE_SIZE), + tile_offset_within_buffer); + } + + tile_id += gridDim.x; + } while (true); +} + +/** + * @brief Kernel that copies data from a batch of given source buffers to their corresponding + * destination buffer. If a buffer's size is to large to be copied by a single thread block, that + * buffer is put into a queue of buffers that will get picked up later on, where multiple blocks + * collaborate on each of these buffers. All other buffers get copied straight away. + * + * @param input_buffer_it [in] Iterator providing the pointers to the source memory buffers + * @param output_buffer_it [in] Iterator providing the pointers to the destination memory buffers + * @param buffer_sizes [in] Iterator providing the number of bytes to be copied for each pair of + * buffers + * @param num_buffers [in] The total number of buffer pairs + * @param blev_buffer_srcs [out] The source pointers of buffers that require block-level + * collaboration + * @param blev_buffer_dsts [out] The destination pointers of buffers that require block-level + * collaboration + * @param blev_buffer_sizes [out] The sizes of buffers that require block-level collaboration + * @param blev_buffer_scan_state [in,out] Tile states for the prefix sum over the count of buffers + * requiring block-level collaboration (to "stream compact" (aka "select") BLEV-buffers) + * @param blev_block_scan_state [in,out] Tile states for the prefix sum over the number of thread + * blocks getting assigned to each buffer that requires block-level collaboration + */ +template +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::AgentSmallBufferPolicyT::BLOCK_THREADS)) + __global__ void BatchMemcpyKernel(InputBufferIt input_buffer_it, + OutputBufferIt output_buffer_it, + BufferSizeIteratorT buffer_sizes, + BufferOffsetT num_buffers, + BlevBufferSrcsOutItT blev_buffer_srcs, + BlevBufferDstsOutItT blev_buffer_dsts, + BlevBufferSizesOutItT blev_buffer_sizes, + BlevBufferTileOffsetsOutItT blev_buffer_tile_offsets, + BLevBufferOffsetTileState blev_buffer_scan_state, + BLevBlockOffsetTileState blev_block_scan_state) +{ + // Internal type used for storing a buffer's size + using BufferSizeT = cub::detail::value_t; + + // Alias the correct tuning policy for the current compilation pass' architecture + using AgentBatchMemcpyPolicyT = typename ChainedPolicyT::ActivePolicy::AgentSmallBufferPolicyT; + + // Block-level specialization + using AgentBatchMemcpyT = AgentBatchMemcpy; + + // Shared memory for AgentBatchMemcpy + __shared__ typename AgentBatchMemcpyT::TempStorage temp_storage; + + // Process this block's tile of input&output buffer pairs + AgentBatchMemcpyT(temp_storage, + input_buffer_it, + output_buffer_it, + buffer_sizes, + num_buffers, + blev_buffer_srcs, + blev_buffer_dsts, + blev_buffer_sizes, + blev_buffer_tile_offsets, + blev_buffer_scan_state, + blev_block_scan_state) + .ConsumeTile(blockIdx.x); +} + +template +struct DeviceBatchMemcpyPolicy +{ + static constexpr uint32_t BLOCK_THREADS = 128U; + static constexpr uint32_t BUFFERS_PER_THREAD = 4U; + static constexpr uint32_t TLEV_BYTES_PER_THREAD = 8U; + + static constexpr uint32_t LARGE_BUFFER_BLOCK_THREADS = 256U; + static constexpr uint32_t LARGE_BUFFER_BYTES_PER_THREAD = 32U; + + static constexpr uint32_t WARP_LEVEL_THRESHOLD = 128; + static constexpr uint32_t BLOCK_LEVEL_THRESHOLD = 8 * 1024; + + using buff_delay_constructor_t = detail::default_delay_constructor_t; + using block_delay_constructor_t = detail::default_delay_constructor_t; + + /// SM35 + struct Policy350 : ChainedPolicy<350, Policy350, Policy350> + { + static constexpr bool PREFER_POW2_BITS = true; + using AgentSmallBufferPolicyT = + AgentBatchMemcpyPolicy; + + using AgentLargeBufferPolicyT = + AgentBatchMemcpyLargeBuffersPolicy; + }; + + /// SM70 + struct Policy700 : ChainedPolicy<700, Policy700, Policy350> + { + static constexpr bool PREFER_POW2_BITS = false; + using AgentSmallBufferPolicyT = + AgentBatchMemcpyPolicy; + + using AgentLargeBufferPolicyT = + AgentBatchMemcpyLargeBuffersPolicy; + }; + + using MaxPolicy = Policy700; +}; + +/** + * @tparam InputBufferIt [inferred] Random-access input iterator type providing the pointers + * to the source memory buffers + * @tparam OutputBufferIt [inferred] Random-access input iterator type providing the pointers + * to the destination memory buffers + * @tparam BufferSizeIteratorT [inferred] Random-access input iterator type providing the + * number of bytes to be copied for each pair of buffers + * @tparam BufferOffsetT Integer type large enough to hold any offset in [0, num_buffers) + * @tparam BlockOffsetT Integer type large enough to hold any offset in [0, + * num_thread_blocks_launched) + */ +template , + bool IsMemcpy = true> +struct DispatchBatchMemcpy : SelectedPolicy +{ + //------------------------------------------------------------------------------ + // TYPE ALIASES + //------------------------------------------------------------------------------ + // Tile state for the single-pass prefix scan to "stream compact" (aka "select") the buffers + // requiring block-level collaboration + using BufferPartitionScanTileStateT = typename cub::ScanTileState; + + // Tile state for the single-pass prefix scan to keep track of how many blocks are assigned to + // each of the buffers requiring block-level collaboration + using BufferTileOffsetScanStateT = typename cub::ScanTileState; + + // Internal type used to keep track of a buffer's size + using BufferSizeT = cub::detail::value_t; + + //------------------------------------------------------------------------------ + // Member Veriables + //------------------------------------------------------------------------------ + void *d_temp_storage; + size_t &temp_storage_bytes; + InputBufferIt input_buffer_it; + OutputBufferIt output_buffer_it; + BufferSizeIteratorT buffer_sizes; + BufferOffsetT num_buffers; + cudaStream_t stream; + + //------------------------------------------------------------------------------ + // Constructor + //------------------------------------------------------------------------------ + CUB_RUNTIME_FUNCTION __forceinline__ DispatchBatchMemcpy(void *d_temp_storage, + size_t &temp_storage_bytes, + InputBufferIt input_buffer_it, + OutputBufferIt output_buffer_it, + BufferSizeIteratorT buffer_sizes, + BufferOffsetT num_buffers, + cudaStream_t stream) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , input_buffer_it(input_buffer_it) + , output_buffer_it(output_buffer_it) + , buffer_sizes(buffer_sizes) + , num_buffers(num_buffers) + , stream(stream) + {} + + //------------------------------------------------------------------------------ + // Chained policy invocation + //------------------------------------------------------------------------------ + /** + * @brief Tuning policy invocation. This member function template is getting instantiated for all + * tuning policies in the tuning policy chain. It is, however, *invoked* for the correct tuning + * policy only. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke() + { + using MaxPolicyT = typename DispatchBatchMemcpy::MaxPolicy; + + // Single-pass prefix scan tile states for the prefix-sum over the number of block-level buffers + using BLevBufferOffsetTileState = cub::ScanTileState; + + // Single-pass prefix scan tile states for the prefix sum over the number of thread blocks + // assigned to each of the block-level buffers + using BLevBlockOffsetTileState = cub::ScanTileState; + + cudaError error = cudaSuccess; + + enum : uint32_t + { + // Memory for the source pointers of the buffers that require block-level collaboration + MEM_BLEV_BUFFER_SRCS = 0, + // Memory for the destination pointers of the buffers that require block-level collaboration + MEM_BLEV_BUFFER_DSTS, + // Memory for the block-level buffers' sizes + MEM_BLEV_BUFFER_SIZES, + // Memory to keep track of the assignment of thread blocks to block-level buffers + MEM_BLEV_BUFFER_TBLOCK, + // Memory for the tile states of the prefix sum over the number of buffers that require + // block-level collaboration + MEM_BLEV_BUFFER_SCAN_STATE, + // Memory for the scan tile states of the prefix sum over the number of thread block's + // assigned up to and including a certain block-level buffer + MEM_BLEV_BLOCK_SCAN_STATE, + // Total number of distinct memory allocations in the temporary storage memory BLOB + MEM_NUM_ALLOCATIONS + }; + + // Number of threads per block for initializing the grid states + constexpr BlockOffsetT INIT_KERNEL_THREADS = 128U; + + // The number of buffers that get processed per thread block + constexpr uint32_t TILE_SIZE = ActivePolicyT::AgentSmallBufferPolicyT::BLOCK_THREADS * + ActivePolicyT::AgentSmallBufferPolicyT::BUFFERS_PER_THREAD; + + // The number of thread blocks (or tiles) required to process all of the given buffers + BlockOffsetT num_tiles = DivideAndRoundUp(num_buffers, TILE_SIZE); + + using BlevBufferSrcsOutT = + cub::detail::conditional_t>; + using BlevBufferDstOutT = + cub::detail::conditional_t>; + using BlevBufferSrcsOutItT = BlevBufferSrcsOutT *; + using BlevBufferDstsOutItT = BlevBufferDstOutT *; + using BlevBufferSizesOutItT = BufferSizeT *; + using BlevBufferTileOffsetsOutItT = BlockOffsetT *; + + temporary_storage::layout temporary_storage_layout; + + auto blev_buffer_srcs_slot = temporary_storage_layout.get_slot(MEM_BLEV_BUFFER_SRCS); + auto blev_buffer_dsts_slot = temporary_storage_layout.get_slot(MEM_BLEV_BUFFER_DSTS); + auto blev_buffer_sizes_slot = temporary_storage_layout.get_slot(MEM_BLEV_BUFFER_SIZES); + auto blev_buffer_block_slot = temporary_storage_layout.get_slot(MEM_BLEV_BUFFER_TBLOCK); + auto blev_buffer_scan_slot = temporary_storage_layout.get_slot(MEM_BLEV_BUFFER_SCAN_STATE); + auto blev_buffer_block_scan_slot = temporary_storage_layout.get_slot(MEM_BLEV_BLOCK_SCAN_STATE); + + auto blev_buffer_srcs_alloc = + blev_buffer_srcs_slot->template create_alias(); + auto blev_buffer_dsts_alloc = blev_buffer_dsts_slot->template create_alias(); + auto blev_buffer_sizes_alloc = blev_buffer_sizes_slot->template create_alias(); + auto blev_buffer_block_alloc = blev_buffer_block_slot->template create_alias(); + auto blev_buffer_scan_alloc = blev_buffer_scan_slot->template create_alias(); + auto blev_block_scan_alloc = blev_buffer_block_scan_slot->template create_alias(); + + std::size_t buffer_offset_scan_storage = 0; + std::size_t blev_block_scan_storage = 0; + CubDebug(error = BLevBufferOffsetTileState::AllocationSize(static_cast(num_tiles), + buffer_offset_scan_storage)); + if (error) + { + return error; + } + CubDebug(error = BLevBlockOffsetTileState::AllocationSize(static_cast(num_tiles), + blev_block_scan_storage)); + if (error) + { + return error; + } + + blev_buffer_srcs_alloc.grow(num_buffers); + blev_buffer_dsts_alloc.grow(num_buffers); + blev_buffer_sizes_alloc.grow(num_buffers); + blev_buffer_block_alloc.grow(num_buffers); + blev_buffer_scan_alloc.grow(buffer_offset_scan_storage); + blev_block_scan_alloc.grow(blev_block_scan_storage); + + // Just return if no temporary storage is provided + if (d_temp_storage == nullptr) + { + temp_storage_bytes = temporary_storage_layout.get_size(); + return error; + } + + // Return if empty problem + if (num_buffers == 0) + { + return error; + } + + // Alias memory buffers into the storage blob + if (CubDebug( + error = temporary_storage_layout.map_to_buffer(d_temp_storage, temp_storage_bytes))) + { + return error; + } + + // Alias into temporary storage allocation + BlevBufferSrcsOutItT d_blev_src_buffers = blev_buffer_srcs_alloc.get(); + BlevBufferDstsOutItT d_blev_dst_buffers = blev_buffer_dsts_alloc.get(); + BlevBufferSizesOutItT d_blev_buffer_sizes = blev_buffer_sizes_alloc.get(); + BlevBufferTileOffsetsOutItT d_blev_block_offsets = blev_buffer_block_alloc.get(); + + // Kernels' grid sizes + BlockOffsetT init_grid_size = DivideAndRoundUp(num_tiles, INIT_KERNEL_THREADS); + BlockOffsetT batch_memcpy_grid_size = num_tiles; + + // Kernels + auto init_scan_states_kernel = + InitTileStateKernel; + auto batch_memcpy_non_blev_kernel = BatchMemcpyKernel; + + auto multi_block_memcpy_kernel = MultiBlockBatchMemcpyKernel; + + constexpr uint32_t BLEV_BLOCK_THREADS = ActivePolicyT::AgentLargeBufferPolicyT::BLOCK_THREADS; + + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) + { + return error; + } + + // Get SM count + int sm_count; + if (CubDebug(error = cudaDeviceGetAttribute(&sm_count, + cudaDevAttrMultiProcessorCount, + device_ordinal))) + { + return error; + } + + // Get SM occupancy for the batch memcpy block-level buffers kernel + int batch_memcpy_blev_occupancy; + if (CubDebug(error = MaxSmOccupancy(batch_memcpy_blev_occupancy, + multi_block_memcpy_kernel, + BLEV_BLOCK_THREADS))) + { + return error; + } + + int batch_memcpy_blev_grid_size = + static_cast(sm_count * batch_memcpy_blev_occupancy * CUB_SUBSCRIPTION_FACTOR(0)); + + // Construct the tile status for the buffer prefix sum + BLevBufferOffsetTileState buffer_scan_tile_state; + if (CubDebug(error = buffer_scan_tile_state.Init(static_cast(num_tiles), + blev_buffer_scan_alloc.get(), + buffer_offset_scan_storage))) + { + return error; + } + + // Construct the tile status for thread blocks-to-buffer-assignment prefix sum + BLevBlockOffsetTileState block_scan_tile_state; + if (CubDebug(error = block_scan_tile_state.Init(static_cast(num_tiles), + blev_block_scan_alloc.get(), + blev_block_scan_storage))) + { + return error; + } + +#ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking " + "InitTileStateKernel<<<%d, %d, 0, %lld>>>()\n", + static_cast(init_grid_size), + INIT_KERNEL_THREADS, + (long long)stream); +#endif + + // Invoke init_kernel to initialize buffer prefix sum-tile descriptors + error = + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(init_grid_size, + INIT_KERNEL_THREADS, + 0, + stream) + .doit(init_scan_states_kernel, buffer_scan_tile_state, block_scan_tile_state, num_tiles); + + // Check for failure to launch + if (CubDebug(error)) + { + return error; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + + // Check for failure to launch + if (CubDebug(error)) + { + return error; + } + +#ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking " + "BatchMemcpyKernel<<<%d, %d, 0, %lld>>>()\n", + static_cast(batch_memcpy_grid_size), + ActivePolicyT::AgentSmallBufferPolicyT::BLOCK_THREADS, + (long long)stream); +#endif + + // Invoke kernel to copy small buffers and put the larger ones into a queue that will get picked + // up by next kernel + error = THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + batch_memcpy_grid_size, + ActivePolicyT::AgentSmallBufferPolicyT::BLOCK_THREADS, + 0, + stream) + .doit(batch_memcpy_non_blev_kernel, + input_buffer_it, + output_buffer_it, + buffer_sizes, + num_buffers, + d_blev_src_buffers, + d_blev_dst_buffers, + d_blev_buffer_sizes, + d_blev_block_offsets, + buffer_scan_tile_state, + block_scan_tile_state); + + // Check for failure to launch + if (CubDebug(error)) + { + return error; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + return error; + } + +#ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking " + "MultiBlockBatchMemcpyKernel<<<%d, %d, 0, %lld>>>()\n", + static_cast(batch_memcpy_blev_grid_size), + BLEV_BLOCK_THREADS, + (long long)stream); +#endif + + error = THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(batch_memcpy_blev_grid_size, + BLEV_BLOCK_THREADS, + 0, + stream) + .doit(multi_block_memcpy_kernel, + d_blev_src_buffers, + d_blev_dst_buffers, + d_blev_buffer_sizes, + d_blev_block_offsets, + buffer_scan_tile_state, + batch_memcpy_grid_size - 1); + + // Check for failure to launch + if (CubDebug(error)) + { + return error; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + + return error; + } + + //------------------------------------------------------------------------------ + // Dispatch entrypoints + //------------------------------------------------------------------------------ + /** + * Internal dispatch routine + */ + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + InputBufferIt input_buffer_it, + OutputBufferIt output_buffer_it, + BufferSizeIteratorT buffer_sizes, + BufferOffsetT num_buffers, + cudaStream_t stream) + { + using MaxPolicyT = typename DispatchBatchMemcpy::MaxPolicy; + + cudaError_t error = cudaSuccess; + + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + return error; + } + + // Create dispatch functor + DispatchBatchMemcpy dispatch(d_temp_storage, + temp_storage_bytes, + input_buffer_it, + output_buffer_it, + buffer_sizes, + num_buffers, + stream); + + // Dispatch to chained policy + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + return error; + } + return error; + } +}; + +} // namespace detail + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_histogram.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_histogram.cuh new file mode 100644 index 0000000000000000000000000000000000000000..b393d3c82454389be192fe1557509b4d4f6755e3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_histogram.cuh @@ -0,0 +1,1623 @@ + +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file + * cub::DeviceHistogram provides device-wide parallel operations for constructing histogram(s) + * from a sequence of samples data residing within device-accessible memory. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Histogram kernel entry points + *****************************************************************************/ + +/** + * Histogram initialization kernel entry point + * + * @tparam NUM_ACTIVE_CHANNELS + * Number of channels actively being histogrammed + * + * @tparam CounterT + * Integer type for counting sample occurrences per histogram bin + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @param num_output_bins_wrapper + * Number of output histogram bins per channel + * + * @param d_output_histograms_wrapper + * Histogram counter data having logical dimensions + * `CounterT[NUM_ACTIVE_CHANNELS][num_bins.array[CHANNEL]]` + * + * @param tile_queue + * Drain queue descriptor for dynamically mapping tile data onto thread blocks + */ +template +__global__ void +DeviceHistogramInitKernel(ArrayWrapper num_output_bins_wrapper, + ArrayWrapper d_output_histograms_wrapper, + GridQueue tile_queue) +{ + if ((threadIdx.x == 0) && (blockIdx.x == 0)) + { + tile_queue.ResetDrain(); + } + + int output_bin = (blockIdx.x * blockDim.x) + threadIdx.x; + +#pragma unroll + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + if (output_bin < num_output_bins_wrapper.array[CHANNEL]) + { + d_output_histograms_wrapper.array[CHANNEL][output_bin] = 0; + } + } +} + +/** + * Histogram privatized sweep kernel entry point (multi-block). + * Computes privatized histograms, one per thread block. + * + * + * @tparam AgentHistogramPolicyT + * Parameterized AgentHistogramPolicy tuning policy type + * + * @tparam PRIVATIZED_SMEM_BINS + * Maximum number of histogram bins per channel (e.g., up to 256) + * + * @tparam NUM_CHANNELS + * Number of channels interleaved in the input data (may be greater than the number of channels + * being actively histogrammed) + * + * @tparam NUM_ACTIVE_CHANNELS + * Number of channels actively being histogrammed + * + * @tparam SampleIteratorT + * The input iterator type. \iterator. + * + * @tparam CounterT + * Integer type for counting sample occurrences per histogram bin + * + * @tparam PrivatizedDecodeOpT + * The transform operator type for determining privatized counter indices from samples, + * one for each channel + * + * @tparam OutputDecodeOpT + * The transform operator type for determining output bin-ids from privatized counter indices, + * one for each channel + * + * @tparam OffsetT + * integer type for global offsets + * + * @param d_samples + * Input data to reduce + * + * @param num_output_bins_wrapper + * The number bins per final output histogram + * + * @param num_privatized_bins_wrapper + * The number bins per privatized histogram + * + * @param d_output_histograms_wrapper + * Reference to final output histograms + * + * @param d_privatized_histograms_wrapper + * Reference to privatized histograms + * + * @param output_decode_op_wrapper + * The transform operator for determining output bin-ids from privatized counter indices, + * one for each channel + * + * @param privatized_decode_op_wrapper + * The transform operator for determining privatized counter indices from samples, + * one for each channel + * + * @param num_row_pixels + * The number of multi-channel pixels per row in the region of interest + * + * @param num_rows + * The number of rows in the region of interest + * + * @param row_stride_samples + * The number of samples between starts of consecutive rows in the region of interest + * + * @param tiles_per_row + * Number of image tiles per row + * + * @param tile_queue + * Drain queue descriptor for dynamically mapping tile data onto thread blocks + */ +template +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::AgentHistogramPolicyT::BLOCK_THREADS)) __global__ + void DeviceHistogramSweepKernel( + SampleIteratorT d_samples, + ArrayWrapper num_output_bins_wrapper, + ArrayWrapper num_privatized_bins_wrapper, + ArrayWrapper d_output_histograms_wrapper, + ArrayWrapper d_privatized_histograms_wrapper, + ArrayWrapper output_decode_op_wrapper, + ArrayWrapper privatized_decode_op_wrapper, + OffsetT num_row_pixels, + OffsetT num_rows, + OffsetT row_stride_samples, + int tiles_per_row, + GridQueue tile_queue) +{ + // Thread block type for compositing input tiles + using AgentHistogramPolicyT = typename ChainedPolicyT::ActivePolicy::AgentHistogramPolicyT; + using AgentHistogramT = AgentHistogram; + + // Shared memory for AgentHistogram + __shared__ typename AgentHistogramT::TempStorage temp_storage; + + AgentHistogramT agent(temp_storage, + d_samples, + num_output_bins_wrapper.array, + num_privatized_bins_wrapper.array, + d_output_histograms_wrapper.array, + d_privatized_histograms_wrapper.array, + output_decode_op_wrapper.array, + privatized_decode_op_wrapper.array); + + // Initialize counters + agent.InitBinCounters(); + + // Consume input tiles + agent.ConsumeTiles(num_row_pixels, num_rows, row_stride_samples, tiles_per_row, tile_queue); + + // Store output to global (if necessary) + agent.StoreOutput(); +} + +namespace detail +{ + +template +struct dispatch_histogram +{ + void *d_temp_storage; + size_t &temp_storage_bytes; + SampleIteratorT d_samples; + CounterT **d_output_histograms; + int *num_privatized_levels; + PrivatizedDecodeOpT *privatized_decode_op; + int *num_output_levels; + OutputDecodeOpT *output_decode_op; + int max_num_output_bins; + OffsetT num_row_pixels; + OffsetT num_rows; + OffsetT row_stride_samples; + cudaStream_t stream; + + CUB_RUNTIME_FUNCTION + dispatch_histogram(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_output_histograms[NUM_ACTIVE_CHANNELS], + int num_privatized_levels[NUM_ACTIVE_CHANNELS], + PrivatizedDecodeOpT privatized_decode_op[NUM_ACTIVE_CHANNELS], + int num_output_levels[NUM_ACTIVE_CHANNELS], + OutputDecodeOpT output_decode_op[NUM_ACTIVE_CHANNELS], + int max_num_output_bins, + OffsetT num_row_pixels, + OffsetT num_rows, + OffsetT row_stride_samples, + cudaStream_t stream) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_samples(d_samples) + , d_output_histograms(d_output_histograms) + , num_privatized_levels(num_privatized_levels) + , privatized_decode_op(privatized_decode_op) + , num_output_levels(num_output_levels) + , output_decode_op(output_decode_op) + , max_num_output_bins(max_num_output_bins) + , num_row_pixels(num_row_pixels) + , num_rows(num_rows) + , row_stride_samples(row_stride_samples) + , stream(stream) + {} + + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t + Invoke(DeviceHistogramInitKernelT histogram_init_kernel, + DeviceHistogramSweepKernelT histogram_sweep_kernel) + { + cudaError error = cudaSuccess; + + const int block_threads = ActivePolicyT::AgentHistogramPolicyT::BLOCK_THREADS; + const int pixels_per_thread = ActivePolicyT::AgentHistogramPolicyT::PIXELS_PER_THREAD; + + do + { + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) + { + break; + } + + // Get SM count + int sm_count; + if (CubDebug(error = cudaDeviceGetAttribute(&sm_count, + cudaDevAttrMultiProcessorCount, + device_ordinal))) + { + break; + } + + // Get SM occupancy for histogram_sweep_kernel + int histogram_sweep_sm_occupancy; + if (CubDebug(error = MaxSmOccupancy(histogram_sweep_sm_occupancy, + histogram_sweep_kernel, + block_threads))) + { + break; + } + + // Get device occupancy for histogram_sweep_kernel + int histogram_sweep_occupancy = histogram_sweep_sm_occupancy * sm_count; + + if (num_row_pixels * NUM_CHANNELS == row_stride_samples) + { + // Treat as a single linear array of samples + num_row_pixels *= num_rows; + num_rows = 1; + row_stride_samples = num_row_pixels * NUM_CHANNELS; + } + + // Get grid dimensions, trying to keep total blocks ~histogram_sweep_occupancy + int pixels_per_tile = block_threads * pixels_per_thread; + int tiles_per_row = static_cast(cub::DivideAndRoundUp(num_row_pixels, pixels_per_tile)); + int blocks_per_row = CUB_MIN(histogram_sweep_occupancy, tiles_per_row); + int blocks_per_col = (blocks_per_row > 0) + ? int(CUB_MIN(histogram_sweep_occupancy / blocks_per_row, num_rows)) + : 0; + int num_thread_blocks = blocks_per_row * blocks_per_col; + + dim3 sweep_grid_dims; + sweep_grid_dims.x = (unsigned int)blocks_per_row; + sweep_grid_dims.y = (unsigned int)blocks_per_col; + sweep_grid_dims.z = 1; + + // Temporary storage allocation requirements + const int NUM_ALLOCATIONS = NUM_ACTIVE_CHANNELS + 1; + void *allocations[NUM_ALLOCATIONS] = {}; + size_t allocation_sizes[NUM_ALLOCATIONS]; + + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + allocation_sizes[CHANNEL] = size_t(num_thread_blocks) * + (num_privatized_levels[CHANNEL] - 1) * sizeof(CounterT); + } + + allocation_sizes[NUM_ALLOCATIONS - 1] = GridQueue::AllocationSize(); + + // Alias the temporary allocations from the single storage blob (or compute the + // necessary size of the blob) + if (CubDebug( + error = + AliasTemporaries(d_temp_storage, temp_storage_bytes, allocations, allocation_sizes))) + { + break; + } + + if (d_temp_storage == nullptr) + { + // Return if the caller is simply requesting the size of the storage allocation + break; + } + + // Construct the grid queue descriptor + GridQueue tile_queue(allocations[NUM_ALLOCATIONS - 1]); + + // Setup array wrapper for histogram channel output (because we can't pass static arrays + // as kernel parameters) + ArrayWrapper d_output_histograms_wrapper; + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + d_output_histograms_wrapper.array[CHANNEL] = d_output_histograms[CHANNEL]; + } + + // Setup array wrapper for privatized per-block histogram channel output (because we + // can't pass static arrays as kernel parameters) + ArrayWrapper d_privatized_histograms_wrapper; + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + d_privatized_histograms_wrapper.array[CHANNEL] = (CounterT *)allocations[CHANNEL]; + } + + // Setup array wrapper for sweep bin transforms (because we can't pass static arrays as + // kernel parameters) + ArrayWrapper privatized_decode_op_wrapper; + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + privatized_decode_op_wrapper.array[CHANNEL] = privatized_decode_op[CHANNEL]; + } + + // Setup array wrapper for aggregation bin transforms (because we can't pass static + // arrays as kernel parameters) + ArrayWrapper output_decode_op_wrapper; + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + output_decode_op_wrapper.array[CHANNEL] = output_decode_op[CHANNEL]; + } + + // Setup array wrapper for num privatized bins (because we can't pass static arrays as + // kernel parameters) + ArrayWrapper num_privatized_bins_wrapper; + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + num_privatized_bins_wrapper.array[CHANNEL] = num_privatized_levels[CHANNEL] - 1; + } + + // Setup array wrapper for num output bins (because we can't pass static arrays as + // kernel parameters) + ArrayWrapper num_output_bins_wrapper; + for (int CHANNEL = 0; CHANNEL < NUM_ACTIVE_CHANNELS; ++CHANNEL) + { + num_output_bins_wrapper.array[CHANNEL] = num_output_levels[CHANNEL] - 1; + } + + int histogram_init_block_threads = 256; + + int histogram_init_grid_dims = (max_num_output_bins + histogram_init_block_threads - 1) / + histogram_init_block_threads; + +// Log DeviceHistogramInitKernel configuration +#ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking DeviceHistogramInitKernel<<<%d, %d, 0, %lld>>>()\n", + histogram_init_grid_dims, + histogram_init_block_threads, + (long long)stream); +#endif + + // Invoke histogram_init_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(histogram_init_grid_dims, + histogram_init_block_threads, + 0, + stream) + .doit(histogram_init_kernel, + num_output_bins_wrapper, + d_output_histograms_wrapper, + tile_queue); + + // Return if empty problem + if ((blocks_per_row == 0) || (blocks_per_col == 0)) + { + break; + } + +// Log histogram_sweep_kernel configuration +#ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking histogram_sweep_kernel<<<{%d, %d, %d}, %d, 0, %lld>>>(), %d pixels " + "per thread, %d SM occupancy\n", + sweep_grid_dims.x, + sweep_grid_dims.y, + sweep_grid_dims.z, + block_threads, + (long long)stream, + pixels_per_thread, + histogram_sweep_sm_occupancy); +#endif + + // Invoke histogram_sweep_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(sweep_grid_dims, + block_threads, + 0, + stream) + .doit(histogram_sweep_kernel, + d_samples, + num_output_bins_wrapper, + num_privatized_bins_wrapper, + d_output_histograms_wrapper, + d_privatized_histograms_wrapper, + output_decode_op_wrapper, + privatized_decode_op_wrapper, + num_row_pixels, + num_rows, + row_stride_samples, + tiles_per_row, + tile_queue); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } while (0); + + return error; + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke() + { + return Invoke(DeviceHistogramInitKernel, + DeviceHistogramSweepKernel); + } +}; + +} // namespace detail + +/****************************************************************************** + * Dispatch + ******************************************************************************/ + +/** + * Utility class for dispatching the appropriately-tuned kernels for DeviceHistogram + * + * @tparam NUM_CHANNELS + * Number of channels interleaved in the input data (may be greater than the number of channels + * being actively histogrammed) + * + * @tparam NUM_ACTIVE_CHANNELS + * Number of channels actively being histogrammed + * + * @tparam SampleIteratorT + * Random-access input iterator type for reading input items \iterator + * + * @tparam CounterT + * Integer type for counting sample occurrences per histogram bin + * + * @tparam LevelT + * Type for specifying bin level boundaries + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam SelectedPolicy + * Implementation detail, do not specify directly, requirements on the + * content of this type are subject to breaking change. + */ +template , + CounterT, + NUM_CHANNELS, + NUM_ACTIVE_CHANNELS>> +struct DispatchHistogram : SelectedPolicy +{ +public: + //--------------------------------------------------------------------- + // Types and constants + //--------------------------------------------------------------------- + + /// The sample value type of the input iterator + using SampleT = cub::detail::value_t; + + enum + { + // Maximum number of bins per channel for which we will use a privatized smem strategy + MAX_PRIVATIZED_SMEM_BINS = 256 + }; + + //--------------------------------------------------------------------- + // Transform functors for converting samples to bin-ids + //--------------------------------------------------------------------- + + // Searches for bin given a list of bin-boundary levels + template + struct SearchTransform + { + LevelIteratorT d_levels; // Pointer to levels array + int num_output_levels; // Number of levels in array + + /** + * @brief Initializer + * + * @param d_levels_ Pointer to levels array + * @param num_output_levels_ Number of levels in array + */ + __host__ __device__ __forceinline__ void Init(LevelIteratorT d_levels_, int num_output_levels_) + { + this->d_levels = d_levels_; + this->num_output_levels = num_output_levels_; + } + + // Method for converting samples to bin-ids + template + __host__ __device__ __forceinline__ void BinSelect(_SampleT sample, int &bin, bool valid) + { + /// Level iterator wrapper type + // Wrap the native input pointer with CacheModifiedInputIterator + // or Directly use the supplied input iterator type + using WrappedLevelIteratorT = + cub::detail::conditional_t::value, + CacheModifiedInputIterator, + LevelIteratorT>; + + WrappedLevelIteratorT wrapped_levels(d_levels); + + int num_bins = num_output_levels - 1; + if (valid) + { + bin = UpperBound(wrapped_levels, num_output_levels, (LevelT)sample) - 1; + if (bin >= num_bins) + bin = -1; + } + } + }; + + // Scales samples to evenly-spaced bins + struct ScaleTransform + { + private: + using CommonT = typename ::cuda::std::common_type::type; + static_assert(::cuda::std::is_convertible::value, + "The common type of `LevelT` and `SampleT` must be " + "convertible to `int`."); + static_assert(::cuda::std::is_trivially_copyable::value, + "The common type of `LevelT` and `SampleT` must be " + "trivially copyable."); + + // An arithmetic type that's used for bin computation of integral types, guaranteed to not + // overflow for (max_level - min_level) * scale.fraction.bins. Since we drop invalid samples + // of less than min_level, (sample - min_level) is guaranteed to be non-negative. We use the + // rule: 2^l * 2^r = 2^(l + r) to determine a sufficiently large type to hold the + // multiplication result. + // If CommonT used to be a 128-bit wide integral type already, we use CommonT's arithmetic + using IntArithmeticT = cub::detail::conditional_t< // + sizeof(SampleT) + sizeof(CommonT) <= sizeof(uint32_t), // + uint32_t, // +#if CUB_IS_INT128_ENABLED + cub::detail::conditional_t< // + (::cuda::std::is_same::value || // + ::cuda::std::is_same::value), // + CommonT, // + uint64_t> // +#else + uint64_t +#endif + >; + + // Alias template that excludes __[u]int128 from the integral types + template + using is_integral_excl_int128 = +#if CUB_IS_INT128_ENABLED + cub::detail::conditional_t< + ::cuda::std::is_same::value && ::cuda::std::is_same::value, + ::cuda::std::false_type, + ::cuda::std::is_integral>; +#else + ::cuda::std::is_integral; +#endif + + union ScaleT + { + // Used when CommonT is not floating-point to avoid intermediate + // rounding errors (see NVIDIA/cub#489). + struct FractionT + { + CommonT bins; + CommonT range; + } fraction; + + // Used when CommonT is floating-point as an optimization. + CommonT reciprocal; + }; + + CommonT m_max; // Max sample level (exclusive) + CommonT m_min; // Min sample level (inclusive) + ScaleT m_scale; // Bin scaling + + template + __host__ __device__ __forceinline__ ScaleT + ComputeScale(int num_levels, T max_level, T min_level, ::cuda::std::true_type /* is_fp */) + { + ScaleT result; + result.reciprocal = + static_cast(static_cast(num_levels - 1) / static_cast(max_level - min_level)); + return result; + } + + template + __host__ __device__ __forceinline__ ScaleT + ComputeScale(int num_levels, T max_level, T min_level, ::cuda::std::false_type /* is_fp */) + { + ScaleT result; + result.fraction.bins = static_cast(num_levels - 1); + result.fraction.range = static_cast(max_level - min_level); + return result; + } + + template + __host__ __device__ __forceinline__ ScaleT ComputeScale(int num_levels, + T max_level, + T min_level) + { + return this->ComputeScale(num_levels, + max_level, + min_level, + ::cuda::std::is_floating_point{}); + } + +#ifdef __CUDA_FP16_TYPES_EXIST__ + __host__ __device__ __forceinline__ ScaleT ComputeScale(int num_levels, + __half max_level, + __half min_level) + { + NV_IF_TARGET( + NV_PROVIDES_SM_53, + (return this->ComputeScale(num_levels, max_level, min_level, ::cuda::std::true_type{});), + (return this->ComputeScale(num_levels, + __half2float(max_level), + __half2float(min_level), + ::cuda::std::true_type{});)); + } +#endif + + // All types but __half: + template + __host__ __device__ __forceinline__ int SampleIsValid(T sample, T max_level, T min_level) + { + return sample >= min_level && sample < max_level; + } + +#ifdef __CUDA_FP16_TYPES_EXIST__ + __host__ __device__ __forceinline__ int SampleIsValid(__half sample, + __half max_level, + __half min_level) + { + NV_IF_TARGET(NV_PROVIDES_SM_53, + (return sample >= min_level && sample < max_level;), + (return this->SampleIsValid(__half2float(sample), + __half2float(max_level), + __half2float(min_level));)); + } +#endif + + /** + * @brief Bin computation for floating point (and extended floating point) types + */ + template + __host__ __device__ __forceinline__ int + ComputeBin(T sample, T min_level, ScaleT scale, ::cuda::std::true_type /* is_fp */) + { + return static_cast((sample - min_level) * scale.reciprocal); + } + + /** + * @brief Bin computation for custom types and __[u]int128 + */ + template + __host__ __device__ __forceinline__ int + ComputeBin(T sample, T min_level, ScaleT scale, ::cuda::std::false_type /* is_fp */) + { + return static_cast(((sample - min_level) * scale.fraction.bins) / scale.fraction.range); + } + + /** + * @brief Bin computation for integral types of up to 64-bit types + */ + template ::value, int>::type = 0> + __host__ __device__ __forceinline__ int ComputeBin(T sample, T min_level, ScaleT scale) + { + return static_cast((static_cast(sample - min_level) * + static_cast(scale.fraction.bins)) / + static_cast(scale.fraction.range)); + } + + template ::value, int>::type = 0> + __host__ __device__ __forceinline__ int ComputeBin(T sample, T min_level, ScaleT scale) + { + return this->ComputeBin(sample, min_level, scale, ::cuda::std::is_floating_point{}); + } + +#ifdef __CUDA_FP16_TYPES_EXIST__ + __host__ __device__ __forceinline__ int ComputeBin(__half sample, + __half min_level, + ScaleT scale) + { + NV_IF_TARGET(NV_PROVIDES_SM_53, + (return this->ComputeBin(sample, min_level, scale, ::cuda::std::true_type{});), + (return static_cast((__half2float(sample) - __half2float(min_level)) * + __half2float(scale.reciprocal));)); + } +#endif + + __host__ __device__ __forceinline__ bool MayOverflow(CommonT /* num_bins */, + ::cuda::std::false_type /* is_integral */) + { + return false; + } + + /** + * @brief Returns true if the bin computation for a given combination of range `(max_level - + * min_level)` and number of bins may overflow. + */ + __host__ __device__ __forceinline__ bool MayOverflow(CommonT num_bins, + ::cuda::std::true_type /* is_integral */) + { + return static_cast(m_max - m_min) > + (::cuda::std::numeric_limits::max() / + static_cast(num_bins)); + } + + public: + /** + * @brief Initializes the ScaleTransform for the given parameters + * @return cudaErrorInvalidValue if the ScaleTransform for the given values may overflow, + * cudaSuccess otherwise + */ + __host__ __device__ __forceinline__ cudaError_t Init(int num_levels, + LevelT max_level, + LevelT min_level) + { + m_max = static_cast(max_level); + m_min = static_cast(min_level); + + // Check whether accurate bin computation for an integral sample type may overflow + if (MayOverflow(static_cast(num_levels - 1), ::cuda::std::is_integral{})) + { + return cudaErrorInvalidValue; + } + + m_scale = this->ComputeScale(num_levels, m_max, m_min); + return cudaSuccess; + } + + // Method for converting samples to bin-ids + template + __host__ __device__ __forceinline__ void BinSelect(SampleT sample, int &bin, bool valid) + { + const CommonT common_sample = static_cast(sample); + + if (valid && this->SampleIsValid(common_sample, m_max, m_min)) + { + bin = this->ComputeBin(common_sample, m_min, m_scale); + } + } + }; + + // Pass-through bin transform operator + struct PassThruTransform + { + // Method for converting samples to bin-ids + template + __host__ __device__ __forceinline__ void BinSelect(_SampleT sample, int &bin, bool valid) + { + if (valid) + bin = (int)sample; + } + }; + + //--------------------------------------------------------------------- + // Dispatch entrypoints + //--------------------------------------------------------------------- + + /** + * Dispatch routine for HistogramRange, specialized for sample types larger than 8bit + * + * @param d_temp_storage + * Device-accessible allocation of temporary storage. + * When NULL, the required allocation size is written to `temp_storage_bytes` and + * no work is done. + * + * @param temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param d_samples + * The pointer to the multi-channel input sequence of data samples. + * The samples from different channels are assumed to be interleaved + * (e.g., an array of 32-bit pixels where each pixel consists of four RGBA 8-bit samples). + * + * @param d_output_histograms + * The pointers to the histogram counter output arrays, one for each active channel. + * For channeli, the allocation length of `d_histograms[i]` should be + * `num_output_levels[i] - 1`. + * + * @param num_output_levels + * The number of boundaries (levels) for delineating histogram samples in each active channel. + * Implies that the number of bins for channeli is + * `num_output_levels[i] - 1`. + * + * @param d_levels + * The pointers to the arrays of boundaries (levels), one for each active channel. + * Bin ranges are defined by consecutive boundary pairings: lower sample value boundaries are + * inclusive and upper sample value boundaries are exclusive. + * + * @param num_row_pixels + * The number of multi-channel pixels per row in the region of interest + * + * @param num_rows + * The number of rows in the region of interest + * + * @param row_stride_samples + * The number of samples between starts of consecutive rows in the region of interest + * + * @param stream + * CUDA stream to launch kernels within. Default is stream0. + * + * @param is_byte_sample + * type indicating whether or not SampleT is a 8b type + */ + CUB_RUNTIME_FUNCTION + static cudaError_t DispatchRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_output_histograms[NUM_ACTIVE_CHANNELS], + int num_output_levels[NUM_ACTIVE_CHANNELS], + LevelT *d_levels[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + OffsetT row_stride_samples, + cudaStream_t stream, + Int2Type /*is_byte_sample*/) + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + cudaError error = cudaSuccess; + + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + // Use the search transform op for converting samples to privatized bins + typedef SearchTransform PrivatizedDecodeOpT; + + // Use the pass-thru transform op for converting privatized bins to output bins + typedef PassThruTransform OutputDecodeOpT; + + PrivatizedDecodeOpT privatized_decode_op[NUM_ACTIVE_CHANNELS]{}; + OutputDecodeOpT output_decode_op[NUM_ACTIVE_CHANNELS]{}; + int max_levels = num_output_levels[0]; + + for (int channel = 0; channel < NUM_ACTIVE_CHANNELS; ++channel) + { + privatized_decode_op[channel].Init(d_levels[channel], num_output_levels[channel]); + if (num_output_levels[channel] > max_levels) + { + max_levels = num_output_levels[channel]; + } + } + int max_num_output_bins = max_levels - 1; + + // Dispatch + if (max_num_output_bins > MAX_PRIVATIZED_SMEM_BINS) + { + // Too many bins to keep in shared memory. + const int PRIVATIZED_SMEM_BINS = 0; + + detail::dispatch_histogram + dispatch(d_temp_storage, + temp_storage_bytes, + d_samples, + d_output_histograms, + num_output_levels, + privatized_decode_op, + num_output_levels, + output_decode_op, + max_num_output_bins, + num_row_pixels, + num_rows, + row_stride_samples, + stream); + + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } + else + { + // Dispatch shared-privatized approach + const int PRIVATIZED_SMEM_BINS = MAX_PRIVATIZED_SMEM_BINS; + + detail::dispatch_histogram + dispatch(d_temp_storage, + temp_storage_bytes, + d_samples, + d_output_histograms, + num_output_levels, + privatized_decode_op, + num_output_levels, + output_decode_op, + max_num_output_bins, + num_row_pixels, + num_rows, + row_stride_samples, + stream); + + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION + static cudaError_t DispatchRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_output_histograms[NUM_ACTIVE_CHANNELS], + int num_output_levels[NUM_ACTIVE_CHANNELS], + LevelT *d_levels[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + OffsetT row_stride_samples, + cudaStream_t stream, + bool debug_synchronous, + Int2Type is_byte_sample) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return DispatchRange(d_temp_storage, + temp_storage_bytes, + d_samples, + d_output_histograms, + num_output_levels, + d_levels, + num_row_pixels, + num_rows, + row_stride_samples, + stream, + is_byte_sample); + } + + /** + * Dispatch routine for HistogramRange, specialized for 8-bit sample types + * (computes 256-bin privatized histograms and then reduces to user-specified levels) + * + * @param d_temp_storage + * Device-accessible allocation of temporary storage. + * When NULL, the required allocation size is written to `temp_storage_bytes` and + * no work is done. + * + * @param temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param d_samples + * The pointer to the multi-channel input sequence of data samples. + * The samples from different channels are assumed to be interleaved + * (e.g., an array of 32-bit pixels where each pixel consists of four RGBA 8-bit samples). + * + * @param d_output_histograms + * The pointers to the histogram counter output arrays, one for each active channel. + * For channeli, the allocation length of + * `d_histograms[i]` should be `num_output_levels[i] - 1`. + * + * @param num_output_levels + * The number of boundaries (levels) for delineating histogram samples in each active channel. + * Implies that the number of bins for channeli is + * `num_output_levels[i] - 1`. + * + * @param d_levels + * The pointers to the arrays of boundaries (levels), one for each active channel. + * Bin ranges are defined by consecutive boundary pairings: lower sample value boundaries are + * inclusive and upper sample value boundaries are exclusive. + * + * @param num_row_pixels + * The number of multi-channel pixels per row in the region of interest + * + * @param num_rows + * The number of rows in the region of interest + * + * @param row_stride_samples + * The number of samples between starts of consecutive rows in the region of interest + * + * @param stream + * CUDA stream to launch kernels within. Default is stream0. + * + * @param is_byte_sample + * Marker type indicating whether or not SampleT is a 8b type + */ + CUB_RUNTIME_FUNCTION + static cudaError_t DispatchRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_output_histograms[NUM_ACTIVE_CHANNELS], + int num_output_levels[NUM_ACTIVE_CHANNELS], + LevelT *d_levels[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + OffsetT row_stride_samples, + cudaStream_t stream, + Int2Type /*is_byte_sample*/) + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + cudaError error = cudaSuccess; + + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + // Use the pass-thru transform op for converting samples to privatized bins + typedef PassThruTransform PrivatizedDecodeOpT; + + // Use the search transform op for converting privatized bins to output bins + typedef SearchTransform OutputDecodeOpT; + + int num_privatized_levels[NUM_ACTIVE_CHANNELS]; + PrivatizedDecodeOpT privatized_decode_op[NUM_ACTIVE_CHANNELS]{}; + OutputDecodeOpT output_decode_op[NUM_ACTIVE_CHANNELS]{}; + int max_levels = num_output_levels[0]; // Maximum number of levels in any channel + + for (int channel = 0; channel < NUM_ACTIVE_CHANNELS; ++channel) + { + num_privatized_levels[channel] = 257; + output_decode_op[channel].Init(d_levels[channel], num_output_levels[channel]); + + if (num_output_levels[channel] > max_levels) + { + max_levels = num_output_levels[channel]; + } + } + int max_num_output_bins = max_levels - 1; + + const int PRIVATIZED_SMEM_BINS = 256; + + detail::dispatch_histogram + dispatch(d_temp_storage, + temp_storage_bytes, + d_samples, + d_output_histograms, + num_privatized_levels, + privatized_decode_op, + num_output_levels, + output_decode_op, + max_num_output_bins, + num_row_pixels, + num_rows, + row_stride_samples, + stream); + + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION + static cudaError_t DispatchRange(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_output_histograms[NUM_ACTIVE_CHANNELS], + int num_output_levels[NUM_ACTIVE_CHANNELS], + LevelT *d_levels[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + OffsetT row_stride_samples, + cudaStream_t stream, + bool debug_synchronous, + Int2Type is_byte_sample) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return DispatchRange(d_temp_storage, + temp_storage_bytes, + d_samples, + d_output_histograms, + num_output_levels, + d_levels, + num_row_pixels, + num_rows, + row_stride_samples, + stream, + is_byte_sample); + } + + /** + * Dispatch routine for HistogramEven, specialized for sample types larger than 8-bit + * + * @param d_temp_storage + * Device-accessible allocation of temporary storage. + * When NULL, the required allocation size is written to + * `temp_storage_bytes` and no work is done. + * + * @param temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param d_samples + * The pointer to the input sequence of sample items. + * The samples from different channels are assumed to be interleaved + * (e.g., an array of 32-bit pixels where each pixel consists of four RGBA 8-bit samples). + * + * @param d_output_histograms + * The pointers to the histogram counter output arrays, one for each active channel. + * For channeli, the allocation length of `d_histograms[i]` should be + * `num_output_levels[i] - 1`. + * + * @param num_output_levels + * The number of bin level boundaries for delineating histogram samples in each active channel. + * Implies that the number of bins for channeli is + * `num_output_levels[i] - 1`. + * + * @param lower_level + * The lower sample value bound (inclusive) for the lowest histogram bin in each active channel. + * + * @param upper_level + * The upper sample value bound (exclusive) for the highest histogram bin in each active + * channel. + * + * @param num_row_pixels + * The number of multi-channel pixels per row in the region of interest + * + * @param num_rows + * The number of rows in the region of interest + * + * @param row_stride_samples + * The number of samples between starts of consecutive rows in the region of interest + * + * @param stream + * CUDA stream to launch kernels within. Default is stream0. + * + * @param is_byte_sample + * Marker type indicating whether or not SampleT is a 8b type + */ + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + DispatchEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_output_histograms[NUM_ACTIVE_CHANNELS], + int num_output_levels[NUM_ACTIVE_CHANNELS], + LevelT lower_level[NUM_ACTIVE_CHANNELS], + LevelT upper_level[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + OffsetT row_stride_samples, + cudaStream_t stream, + Int2Type /*is_byte_sample*/) + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + cudaError error = cudaSuccess; + + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + // Use the scale transform op for converting samples to privatized bins + typedef ScaleTransform PrivatizedDecodeOpT; + + // Use the pass-thru transform op for converting privatized bins to output bins + typedef PassThruTransform OutputDecodeOpT; + + PrivatizedDecodeOpT privatized_decode_op[NUM_ACTIVE_CHANNELS]{}; + OutputDecodeOpT output_decode_op[NUM_ACTIVE_CHANNELS]{}; + int max_levels = num_output_levels[0]; + + for (int channel = 0; channel < NUM_ACTIVE_CHANNELS; ++channel) + { + error = privatized_decode_op[channel].Init(num_output_levels[channel], + upper_level[channel], + lower_level[channel]); + if (CubDebug(error != cudaSuccess)) + { + // Make sure to also return a reasonable value for `temp_storage_bytes` in case of + // an overflow of the bin computation, in which case a subsequent algorithm + // invocation will also fail + if (!d_temp_storage) + { + temp_storage_bytes = 1U; + } + return error; + } + + if (num_output_levels[channel] > max_levels) + { + max_levels = num_output_levels[channel]; + } + } + int max_num_output_bins = max_levels - 1; + + if (max_num_output_bins > MAX_PRIVATIZED_SMEM_BINS) + { + // Dispatch shared-privatized approach + const int PRIVATIZED_SMEM_BINS = 0; + + detail::dispatch_histogram + dispatch(d_temp_storage, + temp_storage_bytes, + d_samples, + d_output_histograms, + num_output_levels, + privatized_decode_op, + num_output_levels, + output_decode_op, + max_num_output_bins, + num_row_pixels, + num_rows, + row_stride_samples, + stream); + + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } + else + { + // Dispatch shared-privatized approach + const int PRIVATIZED_SMEM_BINS = MAX_PRIVATIZED_SMEM_BINS; + + detail::dispatch_histogram + dispatch(d_temp_storage, + temp_storage_bytes, + d_samples, + d_output_histograms, + num_output_levels, + privatized_decode_op, + num_output_levels, + output_decode_op, + max_num_output_bins, + num_row_pixels, + num_rows, + row_stride_samples, + stream); + + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + DispatchEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_output_histograms[NUM_ACTIVE_CHANNELS], + int num_output_levels[NUM_ACTIVE_CHANNELS], + LevelT lower_level[NUM_ACTIVE_CHANNELS], + LevelT upper_level[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + OffsetT row_stride_samples, + cudaStream_t stream, + bool debug_synchronous, + Int2Type is_byte_sample) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return DispatchEven(d_temp_storage, + temp_storage_bytes, + d_samples, + d_output_histograms, + num_output_levels, + lower_level, + upper_level, + num_row_pixels, + num_rows, + row_stride_samples, + stream, + is_byte_sample); + } + + /** + * Dispatch routine for HistogramEven, specialized for 8-bit sample types + * (computes 256-bin privatized histograms and then reduces to user-specified levels) + * + * @param d_temp_storage + * Device-accessible allocation of temporary storage. + * When NULL, the required allocation size is written to `temp_storage_bytes` and + * no work is done. + * + * @param temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param d_samples + * The pointer to the input sequence of sample items. The samples from different channels are + * assumed to be interleaved (e.g., an array of 32-bit pixels where each pixel consists of + * four RGBA 8-bit samples). + * + * @param d_output_histograms + * The pointers to the histogram counter output arrays, one for each active channel. + * For channeli, the allocation length of `d_histograms[i]` should be + * `num_output_levels[i] - 1`. + * + * @param num_output_levels + * The number of bin level boundaries for delineating histogram samples in each active channel. + * Implies that the number of bins for channeli is + * `num_output_levels[i] - 1`. + * + * @param lower_level + * The lower sample value bound (inclusive) for the lowest histogram bin in each active channel. + * + * @param upper_level + * The upper sample value bound (exclusive) for the highest histogram bin in each active + * channel. + * + * @param num_row_pixels + * The number of multi-channel pixels per row in the region of interest + * + * @param num_rows + * The number of rows in the region of interest + * + * @param row_stride_samples + * The number of samples between starts of consecutive rows in the region of interest + * + * @param stream + * CUDA stream to launch kernels within. Default is stream0. + * + * @param is_byte_sample + * type indicating whether or not SampleT is a 8b type + */ + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + DispatchEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_output_histograms[NUM_ACTIVE_CHANNELS], + int num_output_levels[NUM_ACTIVE_CHANNELS], + LevelT lower_level[NUM_ACTIVE_CHANNELS], + LevelT upper_level[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + OffsetT row_stride_samples, + cudaStream_t stream, + Int2Type /*is_byte_sample*/) + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + cudaError error = cudaSuccess; + + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + // Use the pass-thru transform op for converting samples to privatized bins + typedef PassThruTransform PrivatizedDecodeOpT; + + // Use the scale transform op for converting privatized bins to output bins + typedef ScaleTransform OutputDecodeOpT; + + int num_privatized_levels[NUM_ACTIVE_CHANNELS]; + PrivatizedDecodeOpT privatized_decode_op[NUM_ACTIVE_CHANNELS]{}; + OutputDecodeOpT output_decode_op[NUM_ACTIVE_CHANNELS]{}; + int max_levels = num_output_levels[0]; + + for (int channel = 0; channel < NUM_ACTIVE_CHANNELS; ++channel) + { + num_privatized_levels[channel] = 257; + + output_decode_op[channel].Init(num_output_levels[channel], + upper_level[channel], + lower_level[channel]); + + if (num_output_levels[channel] > max_levels) + { + max_levels = num_output_levels[channel]; + } + } + int max_num_output_bins = max_levels - 1; + + const int PRIVATIZED_SMEM_BINS = 256; + + detail::dispatch_histogram + dispatch(d_temp_storage, + temp_storage_bytes, + d_samples, + d_output_histograms, + num_privatized_levels, + privatized_decode_op, + num_output_levels, + output_decode_op, + max_num_output_bins, + num_row_pixels, + num_rows, + row_stride_samples, + stream); + + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (0); + + return error; + } + + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + DispatchEven(void *d_temp_storage, + size_t &temp_storage_bytes, + SampleIteratorT d_samples, + CounterT *d_output_histograms[NUM_ACTIVE_CHANNELS], + int num_output_levels[NUM_ACTIVE_CHANNELS], + LevelT lower_level[NUM_ACTIVE_CHANNELS], + LevelT upper_level[NUM_ACTIVE_CHANNELS], + OffsetT num_row_pixels, + OffsetT num_rows, + OffsetT row_stride_samples, + cudaStream_t stream, + bool debug_synchronous, + Int2Type is_byte_sample) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return DispatchEven(d_temp_storage, + temp_storage_bytes, + d_samples, + d_output_histograms, + num_output_levels, + lower_level, + upper_level, + num_row_pixels, + num_rows, + row_stride_samples, + stream, + is_byte_sample); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_merge_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_merge_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..5bbd3dfdd781948573eff21c7e09e5e1838b50b6 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_merge_sort.cuh @@ -0,0 +1,898 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +CUB_NAMESPACE_BEGIN + + +template +void __global__ __launch_bounds__(ChainedPolicyT::ActivePolicy::MergeSortPolicy::BLOCK_THREADS) +DeviceMergeSortBlockSortKernel(bool ping, + KeyInputIteratorT keys_in, + ValueInputIteratorT items_in, + KeyIteratorT keys_out, + ValueIteratorT items_out, + OffsetT keys_count, + KeyT *tmp_keys_out, + ValueT *tmp_items_out, + CompareOpT compare_op, + char *vshmem) +{ + extern __shared__ char shmem[]; + using ActivePolicyT = typename ChainedPolicyT::ActivePolicy::MergeSortPolicy; + + using AgentBlockSortT = AgentBlockSort; + + const OffsetT vshmem_offset = blockIdx.x * + AgentBlockSortT::SHARED_MEMORY_SIZE; + + typename AgentBlockSortT::TempStorage &storage = + *reinterpret_cast( + UseVShmem ? vshmem + vshmem_offset : shmem); + + AgentBlockSortT agent(ping, + storage, + THRUST_NS_QUALIFIER::cuda_cub::core::make_load_iterator(ActivePolicyT(), keys_in), + THRUST_NS_QUALIFIER::cuda_cub::core::make_load_iterator(ActivePolicyT(), items_in), + keys_count, + keys_out, + items_out, + tmp_keys_out, + tmp_items_out, + compare_op); + + agent.Process(); +} + +template +__global__ void DeviceMergeSortPartitionKernel(bool ping, + KeyIteratorT keys_ping, + KeyT *keys_pong, + OffsetT keys_count, + OffsetT num_partitions, + OffsetT *merge_partitions, + CompareOpT compare_op, + OffsetT target_merged_tiles_number, + int items_per_tile) +{ + OffsetT partition_idx = blockDim.x * blockIdx.x + threadIdx.x; + + if (partition_idx < num_partitions) + { + AgentPartition agent( + ping, + keys_ping, + keys_pong, + keys_count, + partition_idx, + merge_partitions, + compare_op, + target_merged_tiles_number, + items_per_tile); + + agent.Process(); + } +} + +template +void __global__ __launch_bounds__(ChainedPolicyT::ActivePolicy::MergeSortPolicy::BLOCK_THREADS) +DeviceMergeSortMergeKernel(bool ping, + KeyIteratorT keys_ping, + ValueIteratorT items_ping, + OffsetT keys_count, + KeyT *keys_pong, + ValueT *items_pong, + CompareOpT compare_op, + OffsetT *merge_partitions, + OffsetT target_merged_tiles_number, + char *vshmem) +{ + extern __shared__ char shmem[]; + + using ActivePolicyT = typename ChainedPolicyT::ActivePolicy::MergeSortPolicy; + using AgentMergeT = AgentMerge; + + const OffsetT vshmem_offset = blockIdx.x * AgentMergeT::SHARED_MEMORY_SIZE; + + typename AgentMergeT::TempStorage &storage = + *reinterpret_cast( + UseVShmem ? vshmem + vshmem_offset : shmem); + + AgentMergeT agent( + ping, + storage, + THRUST_NS_QUALIFIER::cuda_cub::core::make_load_iterator(ActivePolicyT(), keys_ping), + THRUST_NS_QUALIFIER::cuda_cub::core::make_load_iterator(ActivePolicyT(), items_ping), + THRUST_NS_QUALIFIER::cuda_cub::core::make_load_iterator(ActivePolicyT(), keys_pong), + THRUST_NS_QUALIFIER::cuda_cub::core::make_load_iterator(ActivePolicyT(), items_pong), + keys_count, + keys_pong, + items_pong, + keys_ping, + items_ping, + compare_op, + merge_partitions, + target_merged_tiles_number); + + agent.Process(); +} + +/******************************************************************************* + * Policy + ******************************************************************************/ + +template +struct DeviceMergeSortPolicy +{ + using KeyT = cub::detail::value_t; + + //---------------------------------------------------------------------------- + // Architecture-specific tuning policies + //---------------------------------------------------------------------------- + + struct Policy350 : ChainedPolicy<350, Policy350, Policy350> + { + using MergeSortPolicy = + AgentMergeSortPolicy<256, + Nominal4BItemsToItems(11), + cub::BLOCK_LOAD_WARP_TRANSPOSE, + cub::LOAD_LDG, + cub::BLOCK_STORE_WARP_TRANSPOSE>; + }; + +// NVBug 3384810 +#if defined(_NVHPC_CUDA) + using Policy520 = Policy350; +#else + struct Policy520 : ChainedPolicy<520, Policy520, Policy350> + { + using MergeSortPolicy = + AgentMergeSortPolicy<512, + Nominal4BItemsToItems(15), + cub::BLOCK_LOAD_WARP_TRANSPOSE, + cub::LOAD_LDG, + cub::BLOCK_STORE_WARP_TRANSPOSE>; + }; +#endif + + struct Policy600 : ChainedPolicy<600, Policy600, Policy520> + { + using MergeSortPolicy = + AgentMergeSortPolicy<256, + Nominal4BItemsToItems(17), + cub::BLOCK_LOAD_WARP_TRANSPOSE, + cub::LOAD_DEFAULT, + cub::BLOCK_STORE_WARP_TRANSPOSE>; + }; + + + /// MaxPolicy + using MaxPolicy = Policy600; +}; + +template +struct BlockSortLauncher +{ + int num_tiles; + std::size_t block_sort_shmem_size; + bool ping; + + KeyInputIteratorT d_input_keys; + ValueInputIteratorT d_input_items; + KeyIteratorT d_output_keys; + ValueIteratorT d_output_items; + OffsetT num_items; + CompareOpT compare_op; + cudaStream_t stream; + + KeyT *keys_buffer; + ValueT *items_buffer; + char* vshmem_ptr; + + CUB_RUNTIME_FUNCTION __forceinline__ + BlockSortLauncher(int num_tiles, + std::size_t block_sort_shmem_size, + bool ping, + KeyInputIteratorT d_input_keys, + ValueInputIteratorT d_input_items, + KeyIteratorT d_output_keys, + ValueIteratorT d_output_items, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream, + KeyT *keys_buffer, + ValueT *items_buffer, + char *vshmem_ptr) + : num_tiles(num_tiles) + , block_sort_shmem_size(block_sort_shmem_size) + , ping(ping) + , d_input_keys(d_input_keys) + , d_input_items(d_input_items) + , d_output_keys(d_output_keys) + , d_output_items(d_output_items) + , num_items(num_items) + , compare_op(compare_op) + , stream(stream) + , keys_buffer(keys_buffer) + , items_buffer(items_buffer) + , vshmem_ptr(vshmem_ptr) + {} + + CUB_RUNTIME_FUNCTION __forceinline__ + void launch() const + { + if (vshmem_ptr) + { + launch_impl(); + } + else + { + launch_impl(); + } + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ void launch_impl() const + { + constexpr bool use_vshmem = (AgentFitsIntoDefaultShmemSize == false) && + UseVShmem; + + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + num_tiles, + ActivePolicyT::MergeSortPolicy::BLOCK_THREADS, + use_vshmem ? 0 : block_sort_shmem_size, + stream) + .doit(DeviceMergeSortBlockSortKernel, + ping, + d_input_keys, + d_input_items, + d_output_keys, + d_output_items, + num_items, + keys_buffer, + items_buffer, + compare_op, + vshmem_ptr); + } +}; + +template +struct MergeLauncher +{ + int num_tiles; + std::size_t merge_shmem_size; + + KeyIteratorT d_keys; + ValueIteratorT d_items; + OffsetT num_items; + CompareOpT compare_op; + OffsetT *merge_partitions; + cudaStream_t stream; + + KeyT *keys_buffer; + ValueT *items_buffer; + char *vshmem_ptr; + + CUB_RUNTIME_FUNCTION __forceinline__ MergeLauncher(int num_tiles, + std::size_t merge_shmem_size, + KeyIteratorT d_keys, + ValueIteratorT d_items, + OffsetT num_items, + CompareOpT compare_op, + OffsetT *merge_partitions, + cudaStream_t stream, + KeyT *keys_buffer, + ValueT *items_buffer, + char *vshmem_ptr) + : num_tiles(num_tiles) + , merge_shmem_size(merge_shmem_size) + , d_keys(d_keys) + , d_items(d_items) + , num_items(num_items) + , compare_op(compare_op) + , merge_partitions(merge_partitions) + , stream(stream) + , keys_buffer(keys_buffer) + , items_buffer(items_buffer) + , vshmem_ptr(vshmem_ptr) + {} + + CUB_RUNTIME_FUNCTION __forceinline__ void + launch(bool ping, OffsetT target_merged_tiles_number) const + { + if (vshmem_ptr) + { + launch_impl(ping, target_merged_tiles_number); + } + else + { + launch_impl(ping, target_merged_tiles_number); + } + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ void + launch_impl(bool ping, OffsetT target_merged_tiles_number) const + { + constexpr bool use_vshmem = (AgentFitsIntoDefaultShmemSize == false) && + UseVShmem; + + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + num_tiles, + ActivePolicyT::MergeSortPolicy::BLOCK_THREADS, + use_vshmem ? 0 : merge_shmem_size, + stream) + .doit(DeviceMergeSortMergeKernel, + ping, + d_keys, + d_items, + num_items, + keys_buffer, + items_buffer, + compare_op, + merge_partitions, + target_merged_tiles_number, + vshmem_ptr); + } +}; + +template > +struct DispatchMergeSort : SelectedPolicy +{ + using KeyT = cub::detail::value_t; + using ValueT = cub::detail::value_t; + + /// Whether or not there are values to be trucked along with keys + static constexpr bool KEYS_ONLY = std::is_same::value; + + // Problem state + + /// Device-accessible allocation of temporary storage. When NULL, the required + /// allocation size is written to \p temp_storage_bytes and no work is done. + void *d_temp_storage; + + /// Reference to size in bytes of \p d_temp_storage allocation + std::size_t &temp_storage_bytes; + + /// Pointer to the input sequence of unsorted input keys + KeyInputIteratorT d_input_keys; + + /// Pointer to the input sequence of unsorted input values + ValueInputIteratorT d_input_items; + + /// Pointer to the output sequence of sorted input keys + KeyIteratorT d_output_keys; + + /// Pointer to the output sequence of sorted input values + ValueIteratorT d_output_items; + + /// Number of items to sort + OffsetT num_items; + + /// Comparison function object which returns true if the first argument is + /// ordered before the second + CompareOpT compare_op; + + /// CUDA stream to launch kernels within. Default is stream0. + cudaStream_t stream; + + int ptx_version; + + // Constructor + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchMergeSort(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyInputIteratorT d_input_keys, + ValueInputIteratorT d_input_items, + KeyIteratorT d_output_keys, + ValueIteratorT d_output_items, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream, + int ptx_version) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_input_keys(d_input_keys) + , d_input_items(d_input_items) + , d_output_keys(d_output_keys) + , d_output_items(d_output_items) + , num_items(num_items) + , compare_op(compare_op) + , stream(stream) + , ptx_version(ptx_version) + {} + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchMergeSort(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyInputIteratorT d_input_keys, + ValueInputIteratorT d_input_items, + KeyIteratorT d_output_keys, + ValueIteratorT d_output_items, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream, + bool debug_synchronous, + int ptx_version) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_input_keys(d_input_keys) + , d_input_items(d_input_items) + , d_output_keys(d_output_keys) + , d_output_items(d_output_items) + , num_items(num_items) + , compare_op(compare_op) + , stream(stream) + , ptx_version(ptx_version) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + } + + // Invocation + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke() + { + using MergePolicyT = typename ActivePolicyT::MergeSortPolicy; + using MaxPolicyT = typename DispatchMergeSort::MaxPolicy; + + using BlockSortAgentT = AgentBlockSort; + + using MergeAgentT = AgentMerge; + + cudaError error = cudaSuccess; + + if (num_items == 0) + return error; + + do + { + // Get device ordinal + int device_ordinal = 0; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) + { + break; + } + + // Get shared memory size + const auto tile_size = MergePolicyT::ITEMS_PER_TILE; + const auto num_tiles = cub::DivideAndRoundUp(num_items, tile_size); + + /** + * Merge sort supports large types, which can lead to excessive shared + * memory size requirements. In these cases, merge sort allocates virtual + * shared memory that resides in global memory: + * ``` + * extern __shared__ char shmem[]; + * typename AgentT::TempStorage &storage = + * *reinterpret_cast( + * UseVShmem ? vshmem + vshmem_offset : shmem); + * ``` + * Having `UseVShmem` as a runtime variable leads to the generation of + * generic loads and stores, which causes a slowdown. Therefore, + * `UseVShmem` has to be known at compilation time. + * In the generic case, available shared memory size is queried at runtime + * to check if kernels requirements are satisfied. Since the query result + * is not known at compile-time, merge sort kernels are specialized for + * both cases. + * To address increased compilation time, the dispatch layer checks + * whether kernels requirements fit into default shared memory + * size (48KB). In this case, there's no need for virtual shared + * memory specialization. + */ + constexpr std::size_t default_shared_memory_size = 48 * 1024; + constexpr auto block_sort_shmem_size = + static_cast(BlockSortAgentT::SHARED_MEMORY_SIZE); + constexpr bool block_sort_fits_into_default_shmem = + block_sort_shmem_size < default_shared_memory_size; + + constexpr auto merge_shmem_size = + static_cast(MergeAgentT::SHARED_MEMORY_SIZE); + constexpr bool merge_fits_into_default_shmem = merge_shmem_size < + default_shared_memory_size; + constexpr bool runtime_shmem_size_check_is_required = + !(merge_fits_into_default_shmem && block_sort_fits_into_default_shmem); + + const auto merge_partitions_size = + static_cast(1 + num_tiles) * sizeof(OffsetT); + + const auto temporary_keys_storage_size = + static_cast(num_items * sizeof(KeyT)); + + const auto temporary_values_storage_size = + static_cast(num_items * sizeof(ValueT)) * !KEYS_ONLY; + + std::size_t virtual_shared_memory_size = 0; + bool block_sort_requires_vshmem = false; + bool merge_requires_vshmem = false; + + if (runtime_shmem_size_check_is_required) + { + int max_shmem = 0; + if (CubDebug( + error = cudaDeviceGetAttribute(&max_shmem, + cudaDevAttrMaxSharedMemoryPerBlock, + device_ordinal))) + { + break; + } + + block_sort_requires_vshmem = block_sort_shmem_size > + static_cast(max_shmem); + merge_requires_vshmem = merge_shmem_size > + static_cast(max_shmem); + + virtual_shared_memory_size = + detail::VshmemSize(static_cast(max_shmem), + (cub::max)(block_sort_shmem_size, merge_shmem_size), + static_cast(num_tiles)); + } + + + void *allocations[4] = {nullptr, nullptr, nullptr, nullptr}; + std::size_t allocation_sizes[4] = {merge_partitions_size, + temporary_keys_storage_size, + temporary_values_storage_size, + virtual_shared_memory_size}; + + if (CubDebug(error = AliasTemporaries(d_temp_storage, + temp_storage_bytes, + allocations, + allocation_sizes))) + { + break; + } + + if (d_temp_storage == nullptr) + { + // Return if the caller is simply requesting the size of the storage + // allocation + break; + } + + const int num_passes = + static_cast(THRUST_NS_QUALIFIER::detail::log2_ri(num_tiles)); + + /* + * The algorithm consists of stages. At each stage, there are input and + * output arrays. There are two pairs of arrays allocated (keys and items). + * One pair is from function arguments and another from temporary storage. + * Ping is a helper variable that controls which of these two pairs of + * arrays is an input and which is an output for a current stage. If the + * ping is true - the current stage stores its result in the temporary + * storage. The temporary storage acts as input data otherwise. + * + * Block sort is executed before the main loop. It stores its result in + * the pair of arrays that will be an input of the next stage. The initial + * value of the ping variable is selected so that the result of the final + * stage is stored in the input arrays. + */ + bool ping = num_passes % 2 == 0; + + auto merge_partitions = reinterpret_cast(allocations[0]); + auto keys_buffer = reinterpret_cast(allocations[1]); + auto items_buffer = reinterpret_cast(allocations[2]); + + char *vshmem_ptr = virtual_shared_memory_size > 0 + ? reinterpret_cast(allocations[3]) + : nullptr; + + // Invoke DeviceReduceKernel + BlockSortLauncher + block_sort_launcher(static_cast(num_tiles), + block_sort_shmem_size, + ping, + d_input_keys, + d_input_items, + d_output_keys, + d_output_items, + num_items, + compare_op, + stream, + keys_buffer, + items_buffer, + block_sort_requires_vshmem ? vshmem_ptr : nullptr); + + block_sort_launcher.launch(); + + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + const OffsetT num_partitions = num_tiles + 1; + const int threads_per_partition_block = 256; + + const int partition_grid_size = static_cast( + cub::DivideAndRoundUp(num_partitions, threads_per_partition_block)); + + MergeLauncher + merge_launcher(static_cast(num_tiles), + merge_shmem_size, + d_output_keys, + d_output_items, + num_items, + compare_op, + merge_partitions, + stream, + keys_buffer, + items_buffer, + merge_requires_vshmem ? vshmem_ptr : nullptr); + + for (int pass = 0; pass < num_passes; ++pass, ping = !ping) + { + OffsetT target_merged_tiles_number = OffsetT(2) << pass; + + // Partition + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + partition_grid_size, + threads_per_partition_block, + 0, + stream) + .doit(DeviceMergeSortPartitionKernel, + ping, + d_output_keys, + keys_buffer, + num_items, + num_partitions, + merge_partitions, + compare_op, + target_merged_tiles_number, + tile_size); + + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Merge + merge_launcher.launch(ping, target_merged_tiles_number); + + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + } + } + while (0); + + return error; + } + + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyInputIteratorT d_input_keys, + ValueInputIteratorT d_input_items, + KeyIteratorT d_output_keys, + ValueIteratorT d_output_items, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream) + { + using MaxPolicyT = typename DispatchMergeSort::MaxPolicy; + + cudaError error = cudaSuccess; + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + // Create dispatch functor + DispatchMergeSort dispatch(d_temp_storage, + temp_storage_bytes, + d_input_keys, + d_input_items, + d_output_keys, + d_output_items, + num_items, + compare_op, + stream, + ptx_version); + + // Dispatch to chained policy + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + std::size_t &temp_storage_bytes, + KeyInputIteratorT d_input_keys, + ValueInputIteratorT d_input_items, + KeyIteratorT d_output_keys, + ValueIteratorT d_output_items, + OffsetT num_items, + CompareOpT compare_op, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_input_keys, + d_input_items, + d_output_keys, + d_output_items, + num_items, + compare_op, + stream); + } +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_radix_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_radix_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..84b6ccffd1928e6caab32f726b4b5db91537b397 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_radix_sort.cuh @@ -0,0 +1,2470 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::DeviceRadixSort provides device-wide, parallel operations for computing a radix sort across a sequence of data items residing within device-accessible memory. + */ + +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +// suppress warnings triggered by #pragma unroll: +// "warning: loop not unrolled: the optimizer was unable to perform the requested transformation; the transformation might be disabled or specified as part of an unsupported transformation ordering [-Wpass-failed=transform-warning]" +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpass-failed" +#endif + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * Kernel entry points + *****************************************************************************/ + +/** + * Upsweep digit-counting kernel entry point (multi-block). Computes privatized digit histograms, one per block. + */ +template < + typename ChainedPolicyT, ///< Chained tuning policy + bool ALT_DIGIT_BITS, ///< Whether or not to use the alternate (lower-bits) policy + bool IS_DESCENDING, ///< Whether or not the sorted-order is high-to-low + typename KeyT, ///< Key type + typename OffsetT, ///< Signed integer type for global offsets + typename DecomposerT = detail::identity_decomposer_t> +__launch_bounds__ (int((ALT_DIGIT_BITS) ? + int(ChainedPolicyT::ActivePolicy::AltUpsweepPolicy::BLOCK_THREADS) : + int(ChainedPolicyT::ActivePolicy::UpsweepPolicy::BLOCK_THREADS))) +__global__ void DeviceRadixSortUpsweepKernel( + const KeyT *d_keys, ///< [in] Input keys buffer + OffsetT *d_spine, ///< [out] Privatized (per block) digit histograms (striped, i.e., 0s counts from each block, then 1s counts from each block, etc.) + OffsetT /*num_items*/, ///< [in] Total number of input data items + int current_bit, ///< [in] Bit position of current radix digit + int num_bits, ///< [in] Number of bits of current radix digit + GridEvenShare even_share, ///< [in] Even-share descriptor for mapan equal number of tiles onto each thread block + DecomposerT decomposer = {}) +{ + using ActiveUpsweepPolicyT = + cub::detail::conditional_t< + ALT_DIGIT_BITS, + typename ChainedPolicyT::ActivePolicy::AltUpsweepPolicy, + typename ChainedPolicyT::ActivePolicy::UpsweepPolicy>; + + using ActiveDownsweepPolicyT = + cub::detail::conditional_t< + ALT_DIGIT_BITS, + typename ChainedPolicyT::ActivePolicy::AltDownsweepPolicy, + typename ChainedPolicyT::ActivePolicy::DownsweepPolicy>; + + enum { + TILE_ITEMS = CUB_MAX( + ActiveUpsweepPolicyT::BLOCK_THREADS * ActiveUpsweepPolicyT::ITEMS_PER_THREAD, + ActiveDownsweepPolicyT::BLOCK_THREADS * ActiveDownsweepPolicyT::ITEMS_PER_THREAD) + }; + + // Parameterize AgentRadixSortUpsweep type for the current configuration + typedef AgentRadixSortUpsweep< + ActiveUpsweepPolicyT, + KeyT, + OffsetT, + DecomposerT> + AgentRadixSortUpsweepT; + + // Shared memory storage + __shared__ typename AgentRadixSortUpsweepT::TempStorage temp_storage; + + // Initialize GRID_MAPPING_RAKE even-share descriptor for this thread block + even_share.template BlockInit(); + + AgentRadixSortUpsweepT upsweep(temp_storage, d_keys, current_bit, num_bits, decomposer); + + upsweep.ProcessRegion(even_share.block_offset, even_share.block_end); + + CTA_SYNC(); + + // Write out digit counts (striped) + upsweep.template ExtractCounts(d_spine, gridDim.x, blockIdx.x); +} + + +/** + * Spine scan kernel entry point (single-block). Computes an exclusive prefix sum over the privatized digit histograms + */ +template < + typename ChainedPolicyT, ///< Chained tuning policy + typename OffsetT> ///< Signed integer type for global offsets +__launch_bounds__ (int(ChainedPolicyT::ActivePolicy::ScanPolicy::BLOCK_THREADS), 1) +__global__ void RadixSortScanBinsKernel( + OffsetT *d_spine, ///< [in,out] Privatized (per block) digit histograms (striped, i.e., 0s counts from each block, then 1s counts from each block, etc.) + int num_counts) ///< [in] Total number of bin-counts +{ + // Parameterize the AgentScan type for the current configuration + typedef AgentScan< + typename ChainedPolicyT::ActivePolicy::ScanPolicy, + OffsetT*, + OffsetT*, + cub::Sum, + OffsetT, + OffsetT, + OffsetT> + AgentScanT; + + // Shared memory storage + __shared__ typename AgentScanT::TempStorage temp_storage; + + // Block scan instance + AgentScanT block_scan(temp_storage, d_spine, d_spine, cub::Sum(), OffsetT(0)) ; + + // Process full input tiles + int block_offset = 0; + BlockScanRunningPrefixOp prefix_op(0, Sum()); + while (block_offset + AgentScanT::TILE_ITEMS <= num_counts) + { + block_scan.template ConsumeTile(block_offset, prefix_op); + block_offset += AgentScanT::TILE_ITEMS; + } + + // Process the remaining partial tile (if any). + if (block_offset < num_counts) + { + block_scan.template ConsumeTile(block_offset, prefix_op, + num_counts - block_offset); + } +} + + +/** + * Downsweep pass kernel entry point (multi-block). Scatters keys (and values) into corresponding bins for the current digit place. + */ +template < + typename ChainedPolicyT, ///< Chained tuning policy + bool ALT_DIGIT_BITS, ///< Whether or not to use the alternate (lower-bits) policy + bool IS_DESCENDING, ///< Whether or not the sorted-order is high-to-low + typename KeyT, ///< Key type + typename ValueT, ///< Value type + typename OffsetT, ///< Signed integer type for global offsets + typename DecomposerT = detail::identity_decomposer_t> +__launch_bounds__ (int((ALT_DIGIT_BITS) ? + int(ChainedPolicyT::ActivePolicy::AltDownsweepPolicy::BLOCK_THREADS) : + int(ChainedPolicyT::ActivePolicy::DownsweepPolicy::BLOCK_THREADS))) +__global__ void DeviceRadixSortDownsweepKernel( + const KeyT *d_keys_in, ///< [in] Input keys buffer + KeyT *d_keys_out, ///< [in] Output keys buffer + const ValueT *d_values_in, ///< [in] Input values buffer + ValueT *d_values_out, ///< [in] Output values buffer + OffsetT *d_spine, ///< [in] Scan of privatized (per block) digit histograms (striped, i.e., 0s counts from each block, then 1s counts from each block, etc.) + OffsetT num_items, ///< [in] Total number of input data items + int current_bit, ///< [in] Bit position of current radix digit + int num_bits, ///< [in] Number of bits of current radix digit + GridEvenShare even_share, ///< [in] Even-share descriptor for mapan equal number of tiles onto each thread block + DecomposerT decomposer = {}) +{ + using ActiveUpsweepPolicyT = + cub::detail::conditional_t< + ALT_DIGIT_BITS, + typename ChainedPolicyT::ActivePolicy::AltUpsweepPolicy, + typename ChainedPolicyT::ActivePolicy::UpsweepPolicy>; + + using ActiveDownsweepPolicyT = + cub::detail::conditional_t< + ALT_DIGIT_BITS, + typename ChainedPolicyT::ActivePolicy::AltDownsweepPolicy, + typename ChainedPolicyT::ActivePolicy::DownsweepPolicy>; + + enum { + TILE_ITEMS = CUB_MAX( + ActiveUpsweepPolicyT::BLOCK_THREADS * ActiveUpsweepPolicyT::ITEMS_PER_THREAD, + ActiveDownsweepPolicyT::BLOCK_THREADS * ActiveDownsweepPolicyT::ITEMS_PER_THREAD) + }; + + // Parameterize AgentRadixSortDownsweep type for the current configuration + typedef AgentRadixSortDownsweep< + ActiveDownsweepPolicyT, + IS_DESCENDING, + KeyT, + ValueT, + OffsetT, + DecomposerT> + AgentRadixSortDownsweepT; + + // Shared memory storage + __shared__ typename AgentRadixSortDownsweepT::TempStorage temp_storage; + + // Initialize even-share descriptor for this thread block + even_share.template BlockInit(); + + // Process input tiles + AgentRadixSortDownsweepT(temp_storage, num_items, d_spine, d_keys_in, d_keys_out, d_values_in, d_values_out, current_bit, num_bits, decomposer).ProcessRegion( + even_share.block_offset, + even_share.block_end); +} + + +/** + * Single pass kernel entry point (single-block). Fully sorts a tile of input. + */ +template < + typename ChainedPolicyT, ///< Chained tuning policy + bool IS_DESCENDING, ///< Whether or not the sorted-order is high-to-low + typename KeyT, ///< Key type + typename ValueT, ///< Value type + typename OffsetT, ///< Signed integer type for global offsets + typename DecomposerT = detail::identity_decomposer_t> +__launch_bounds__ (int(ChainedPolicyT::ActivePolicy::SingleTilePolicy::BLOCK_THREADS), 1) +__global__ void DeviceRadixSortSingleTileKernel( + const KeyT *d_keys_in, ///< [in] Input keys buffer + KeyT *d_keys_out, ///< [in] Output keys buffer + const ValueT *d_values_in, ///< [in] Input values buffer + ValueT *d_values_out, ///< [in] Output values buffer + OffsetT num_items, ///< [in] Total number of input data items + int current_bit, ///< [in] Bit position of current radix digit + int end_bit, ///< [in] The past-the-end (most-significant) bit index needed for key comparison + DecomposerT decomposer = {}) +{ + // Constants + enum + { + BLOCK_THREADS = ChainedPolicyT::ActivePolicy::SingleTilePolicy::BLOCK_THREADS, + ITEMS_PER_THREAD = ChainedPolicyT::ActivePolicy::SingleTilePolicy::ITEMS_PER_THREAD, + KEYS_ONLY = std::is_same::value, + }; + + // BlockRadixSort type + typedef BlockRadixSort< + KeyT, + BLOCK_THREADS, + ITEMS_PER_THREAD, + ValueT, + ChainedPolicyT::ActivePolicy::SingleTilePolicy::RADIX_BITS, + (ChainedPolicyT::ActivePolicy::SingleTilePolicy::RANK_ALGORITHM == RADIX_RANK_MEMOIZE), + ChainedPolicyT::ActivePolicy::SingleTilePolicy::SCAN_ALGORITHM> + BlockRadixSortT; + + // BlockLoad type (keys) + typedef BlockLoad< + KeyT, + BLOCK_THREADS, + ITEMS_PER_THREAD, + ChainedPolicyT::ActivePolicy::SingleTilePolicy::LOAD_ALGORITHM> BlockLoadKeys; + + // BlockLoad type (values) + typedef BlockLoad< + ValueT, + BLOCK_THREADS, + ITEMS_PER_THREAD, + ChainedPolicyT::ActivePolicy::SingleTilePolicy::LOAD_ALGORITHM> BlockLoadValues; + + // Unsigned word for key bits + using traits = detail::radix::traits_t; + using bit_ordered_type = typename traits::bit_ordered_type; + + // Shared memory storage + __shared__ union TempStorage + { + typename BlockRadixSortT::TempStorage sort; + typename BlockLoadKeys::TempStorage load_keys; + typename BlockLoadValues::TempStorage load_values; + + } temp_storage; + + // Keys and values for the block + KeyT keys[ITEMS_PER_THREAD]; + ValueT values[ITEMS_PER_THREAD]; + + // Get default (min/max) value for out-of-bounds keys + bit_ordered_type default_key_bits = IS_DESCENDING + ? traits::min_raw_binary_key(decomposer) + : traits::max_raw_binary_key(decomposer); + + KeyT default_key = reinterpret_cast(default_key_bits); + + // Load keys + BlockLoadKeys(temp_storage.load_keys).Load(d_keys_in, keys, num_items, default_key); + + CTA_SYNC(); + + // Load values + if (!KEYS_ONLY) + { + // Register pressure work-around: moving num_items through shfl prevents compiler + // from reusing guards/addressing from prior guarded loads + num_items = ShuffleIndex(num_items, 0, 0xffffffff); + + BlockLoadValues(temp_storage.load_values).Load(d_values_in, values, num_items); + + CTA_SYNC(); + } + + // Sort tile + BlockRadixSortT(temp_storage.sort).SortBlockedToStriped( + keys, + values, + current_bit, + end_bit, + Int2Type(), + Int2Type(), + decomposer); + + // Store keys and values + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ++ITEM) + { + int item_offset = ITEM * BLOCK_THREADS + threadIdx.x; + if (item_offset < num_items) + { + d_keys_out[item_offset] = keys[ITEM]; + if (!KEYS_ONLY) + d_values_out[item_offset] = values[ITEM]; + } + } +} + + +/** + * Segmented radix sorting pass (one block per segment) + */ +template < + typename ChainedPolicyT, ///< Chained tuning policy + bool ALT_DIGIT_BITS, ///< Whether or not to use the alternate (lower-bits) policy + bool IS_DESCENDING, ///< Whether or not the sorted-order is high-to-low + typename KeyT, ///< Key type + typename ValueT, ///< Value type + typename BeginOffsetIteratorT, ///< Random-access input iterator type for reading segment beginning offsets \iterator + typename EndOffsetIteratorT, ///< Random-access input iterator type for reading segment ending offsets \iterator + typename OffsetT, ///< Signed integer type for global offsets + typename DecomposerT = detail::identity_decomposer_t> +__launch_bounds__ (int((ALT_DIGIT_BITS) ? + ChainedPolicyT::ActivePolicy::AltSegmentedPolicy::BLOCK_THREADS : + ChainedPolicyT::ActivePolicy::SegmentedPolicy::BLOCK_THREADS)) +__global__ void DeviceSegmentedRadixSortKernel( + const KeyT *d_keys_in, ///< [in] Input keys buffer + KeyT *d_keys_out, ///< [in] Output keys buffer + const ValueT *d_values_in, ///< [in] Input values buffer + ValueT *d_values_out, ///< [in] Output values buffer + BeginOffsetIteratorT d_begin_offsets, ///< [in] Random-access input iterator to the sequence of beginning offsets of length \p num_segments, such that d_begin_offsets[i] is the first element of the ith data segment in d_keys_* and d_values_* + EndOffsetIteratorT d_end_offsets, ///< [in] Random-access input iterator to the sequence of ending offsets of length \p num_segments, such that d_end_offsets[i]-1 is the last element of the ith data segment in d_keys_* and d_values_*. If d_end_offsets[i]-1 <= d_begin_offsets[i], the ith is considered empty. + int /*num_segments*/, ///< [in] The number of segments that comprise the sorting data + int current_bit, ///< [in] Bit position of current radix digit + int pass_bits, ///< [in] Number of bits of current radix digit + DecomposerT decomposer = {}) +{ + // + // Constants + // + + using SegmentedPolicyT = cub::detail::conditional_t< + ALT_DIGIT_BITS, + typename ChainedPolicyT::ActivePolicy::AltSegmentedPolicy, + typename ChainedPolicyT::ActivePolicy::SegmentedPolicy>; + + enum + { + BLOCK_THREADS = SegmentedPolicyT::BLOCK_THREADS, + ITEMS_PER_THREAD = SegmentedPolicyT::ITEMS_PER_THREAD, + RADIX_BITS = SegmentedPolicyT::RADIX_BITS, + TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD, + RADIX_DIGITS = 1 << RADIX_BITS, + KEYS_ONLY = std::is_same::value, + }; + + // Upsweep type + using BlockUpsweepT = + AgentRadixSortUpsweep; + + // Digit-scan type + using DigitScanT = BlockScan; + + // Downsweep type + using BlockDownsweepT = AgentRadixSortDownsweep; + + enum + { + /// Number of bin-starting offsets tracked per thread + BINS_TRACKED_PER_THREAD = BlockDownsweepT::BINS_TRACKED_PER_THREAD + }; + + // + // Process input tiles + // + + // Shared memory storage + __shared__ union + { + typename BlockUpsweepT::TempStorage upsweep; + typename BlockDownsweepT::TempStorage downsweep; + struct + { + volatile OffsetT reverse_counts_in[RADIX_DIGITS]; + volatile OffsetT reverse_counts_out[RADIX_DIGITS]; + typename DigitScanT::TempStorage scan; + }; + + } temp_storage; + + OffsetT segment_begin = d_begin_offsets[blockIdx.x]; + OffsetT segment_end = d_end_offsets[blockIdx.x]; + OffsetT num_items = segment_end - segment_begin; + + // Check if empty segment + if (num_items <= 0) + return; + + // Upsweep + BlockUpsweepT upsweep(temp_storage.upsweep, d_keys_in, current_bit, pass_bits, decomposer); + upsweep.ProcessRegion(segment_begin, segment_end); + + CTA_SYNC(); + + // The count of each digit value in this pass (valid in the first RADIX_DIGITS threads) + OffsetT bin_count[BINS_TRACKED_PER_THREAD]; + upsweep.ExtractCounts(bin_count); + + CTA_SYNC(); + + if (IS_DESCENDING) + { + // Reverse bin counts + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + temp_storage.reverse_counts_in[bin_idx] = bin_count[track]; + } + + CTA_SYNC(); + + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + bin_count[track] = temp_storage.reverse_counts_in[RADIX_DIGITS - bin_idx - 1]; + } + } + + // Scan + OffsetT bin_offset[BINS_TRACKED_PER_THREAD]; // The global scatter base offset for each digit value in this pass (valid in the first RADIX_DIGITS threads) + DigitScanT(temp_storage.scan).ExclusiveSum(bin_count, bin_offset); + + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + bin_offset[track] += segment_begin; + } + + if (IS_DESCENDING) + { + // Reverse bin offsets + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + temp_storage.reverse_counts_out[threadIdx.x] = bin_offset[track]; + } + + CTA_SYNC(); + + #pragma unroll + for (int track = 0; track < BINS_TRACKED_PER_THREAD; ++track) + { + int bin_idx = (threadIdx.x * BINS_TRACKED_PER_THREAD) + track; + + if ((BLOCK_THREADS == RADIX_DIGITS) || (bin_idx < RADIX_DIGITS)) + bin_offset[track] = temp_storage.reverse_counts_out[RADIX_DIGITS - bin_idx - 1]; + } + } + + CTA_SYNC(); + + // Downsweep + BlockDownsweepT downsweep(temp_storage.downsweep, bin_offset, num_items, d_keys_in, d_keys_out, d_values_in, d_values_out, current_bit, pass_bits, decomposer); + downsweep.ProcessRegion(segment_begin, segment_end); +} + + +/****************************************************************************** + * Onesweep kernels + ******************************************************************************/ + +/** + * Kernel for computing multiple histograms + */ + +/** + * Histogram kernel + */ +template +__global__ __launch_bounds__(ChainedPolicyT::ActivePolicy::HistogramPolicy::BLOCK_THREADS) +void DeviceRadixSortHistogramKernel(OffsetT *d_bins_out, + const KeyT *d_keys_in, + OffsetT num_items, + int start_bit, + int end_bit, + DecomposerT decomposer = {}) +{ + typedef typename ChainedPolicyT::ActivePolicy::HistogramPolicy HistogramPolicyT; + typedef AgentRadixSortHistogram AgentT; + __shared__ typename AgentT::TempStorage temp_storage; + AgentT agent(temp_storage, d_bins_out, d_keys_in, num_items, start_bit, end_bit, decomposer); + agent.Process(); +} + +template < + typename ChainedPolicyT, + bool IS_DESCENDING, + typename KeyT, + typename ValueT, + typename OffsetT, + typename PortionOffsetT, + typename AtomicOffsetT = PortionOffsetT, + typename DecomposerT = detail::identity_decomposer_t> +__global__ void __launch_bounds__(ChainedPolicyT::ActivePolicy::OnesweepPolicy::BLOCK_THREADS) +DeviceRadixSortOnesweepKernel + (AtomicOffsetT* d_lookback, AtomicOffsetT* d_ctrs, OffsetT* d_bins_out, + const OffsetT* d_bins_in, KeyT* d_keys_out, const KeyT* d_keys_in, ValueT* d_values_out, + const ValueT* d_values_in, PortionOffsetT num_items, int current_bit, int num_bits, + DecomposerT decomposer = {}) +{ + typedef typename ChainedPolicyT::ActivePolicy::OnesweepPolicy OnesweepPolicyT; + typedef AgentRadixSortOnesweep AgentT; + __shared__ typename AgentT::TempStorage s; + + AgentT agent(s, d_lookback, d_ctrs, d_bins_out, d_bins_in, d_keys_out, d_keys_in, + d_values_out, d_values_in, num_items, current_bit, num_bits, decomposer); + agent.Process(); +} + + +/** + * Exclusive sum kernel + */ +template < + typename ChainedPolicyT, + typename OffsetT> +__global__ void DeviceRadixSortExclusiveSumKernel(OffsetT* d_bins) +{ + typedef typename ChainedPolicyT::ActivePolicy::ExclusiveSumPolicy ExclusiveSumPolicyT; + const int RADIX_BITS = ExclusiveSumPolicyT::RADIX_BITS; + const int RADIX_DIGITS = 1 << RADIX_BITS; + const int BLOCK_THREADS = ExclusiveSumPolicyT::BLOCK_THREADS; + const int BINS_PER_THREAD = (RADIX_DIGITS + BLOCK_THREADS - 1) / BLOCK_THREADS; + typedef cub::BlockScan BlockScan; + __shared__ typename BlockScan::TempStorage temp_storage; + + // load the bins + OffsetT bins[BINS_PER_THREAD]; + int bin_start = blockIdx.x * RADIX_DIGITS; + #pragma unroll + for (int u = 0; u < BINS_PER_THREAD; ++u) + { + int bin = threadIdx.x * BINS_PER_THREAD + u; + if (bin >= RADIX_DIGITS) break; + bins[u] = d_bins[bin_start + bin]; + } + + // compute offsets + BlockScan(temp_storage).ExclusiveSum(bins, bins); + + // store the offsets + #pragma unroll + for (int u = 0; u < BINS_PER_THREAD; ++u) + { + int bin = threadIdx.x * BINS_PER_THREAD + u; + if (bin >= RADIX_DIGITS) break; + d_bins[bin_start + bin] = bins[u]; + } +} + +namespace detail +{ +namespace radix +{ + +// default +template +struct sm90_small_key_tuning +{ + static constexpr int threads = 384; + static constexpr int items = 23; +}; + +// clang-format off + +// keys +template <> struct sm90_small_key_tuning<1, 0, 4> { static constexpr int threads = 512; static constexpr int items = 19; }; +template <> struct sm90_small_key_tuning<1, 0, 8> { static constexpr int threads = 512; static constexpr int items = 19; }; +template <> struct sm90_small_key_tuning<2, 0, 4> { static constexpr int threads = 512; static constexpr int items = 19; }; +template <> struct sm90_small_key_tuning<2, 0, 8> { static constexpr int threads = 512; static constexpr int items = 19; }; + +// pairs 8:xx +template <> struct sm90_small_key_tuning<1, 1, 4> { static constexpr int threads = 512; static constexpr int items = 15; }; +template <> struct sm90_small_key_tuning<1, 1, 8> { static constexpr int threads = 448; static constexpr int items = 16; }; +template <> struct sm90_small_key_tuning<1, 2, 4> { static constexpr int threads = 512; static constexpr int items = 17; }; +template <> struct sm90_small_key_tuning<1, 2, 8> { static constexpr int threads = 512; static constexpr int items = 14; }; +template <> struct sm90_small_key_tuning<1, 4, 4> { static constexpr int threads = 512; static constexpr int items = 17; }; +template <> struct sm90_small_key_tuning<1, 4, 8> { static constexpr int threads = 512; static constexpr int items = 14; }; +template <> struct sm90_small_key_tuning<1, 8, 4> { static constexpr int threads = 384; static constexpr int items = 23; }; +template <> struct sm90_small_key_tuning<1, 8, 8> { static constexpr int threads = 384; static constexpr int items = 18; }; +template <> struct sm90_small_key_tuning<1, 16, 4> { static constexpr int threads = 512; static constexpr int items = 22; }; +template <> struct sm90_small_key_tuning<1, 16, 8> { static constexpr int threads = 512; static constexpr int items = 22; }; + +// pairs 16:xx +template <> struct sm90_small_key_tuning<2, 1, 4> { static constexpr int threads = 384; static constexpr int items = 14; }; +template <> struct sm90_small_key_tuning<2, 1, 8> { static constexpr int threads = 384; static constexpr int items = 16; }; +template <> struct sm90_small_key_tuning<2, 2, 4> { static constexpr int threads = 384; static constexpr int items = 15; }; +template <> struct sm90_small_key_tuning<2, 2, 8> { static constexpr int threads = 448; static constexpr int items = 16; }; +template <> struct sm90_small_key_tuning<2, 4, 4> { static constexpr int threads = 512; static constexpr int items = 17; }; +template <> struct sm90_small_key_tuning<2, 4, 8> { static constexpr int threads = 512; static constexpr int items = 12; }; +template <> struct sm90_small_key_tuning<2, 8, 4> { static constexpr int threads = 384; static constexpr int items = 23; }; +template <> struct sm90_small_key_tuning<2, 8, 8> { static constexpr int threads = 512; static constexpr int items = 23; }; +template <> struct sm90_small_key_tuning<2, 16, 4> { static constexpr int threads = 512; static constexpr int items = 21; }; +template <> struct sm90_small_key_tuning<2, 16, 8> { static constexpr int threads = 576; static constexpr int items = 22; }; +// clang-format on + +} // namespace radix +} // namespace detail + +/****************************************************************************** + * Policy + ******************************************************************************/ + +/** + * Tuning policy for kernel specialization + */ +template < + typename KeyT, ///< Key type + typename ValueT, ///< Value type + typename OffsetT> ///< Signed integer type for global offsets +struct DeviceRadixSortPolicy +{ + //------------------------------------------------------------------------------ + // Constants + //------------------------------------------------------------------------------ + + // Whether this is a keys-only (or key-value) sort + constexpr static bool KEYS_ONLY = std::is_same::value; + + // Dominant-sized key/value type + using DominantT = + cub::detail::conditional_t<(sizeof(ValueT) > sizeof(KeyT)), ValueT, KeyT>; + + //------------------------------------------------------------------------------ + // Architecture-specific tuning policies + //------------------------------------------------------------------------------ + + /// SM35 + struct Policy350 : ChainedPolicy<350, Policy350, Policy350> + { + enum { + PRIMARY_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, // 1.72B 32b keys/s, 1.17B 32b pairs/s, 1.55B 32b segmented keys/s (K40m) + ONESWEEP = false, + ONESWEEP_RADIX_BITS = 8, + }; + + // Histogram policy + typedef AgentRadixSortHistogramPolicy <256, 8, 1, KeyT, ONESWEEP_RADIX_BITS> HistogramPolicy; + + // Exclusive sum policy + typedef AgentRadixSortExclusiveSumPolicy <256, ONESWEEP_RADIX_BITS> ExclusiveSumPolicy; + + // Onesweep policy + typedef AgentRadixSortOnesweepPolicy <256, 21, DominantT, 1, + RADIX_RANK_MATCH_EARLY_COUNTS_ANY, BLOCK_SCAN_WARP_SCANS, RADIX_SORT_STORE_DIRECT, + ONESWEEP_RADIX_BITS> OnesweepPolicy; + + // Scan policy + typedef AgentScanPolicy <1024, 4, OffsetT, BLOCK_LOAD_VECTORIZE, LOAD_DEFAULT, BLOCK_STORE_VECTORIZE, BLOCK_SCAN_WARP_SCANS> ScanPolicy; + + // Keys-only downsweep policies + typedef AgentRadixSortDownsweepPolicy <128, 9, DominantT, BLOCK_LOAD_WARP_TRANSPOSE, LOAD_LDG, RADIX_RANK_MATCH, BLOCK_SCAN_WARP_SCANS, PRIMARY_RADIX_BITS> DownsweepPolicyKeys; + typedef AgentRadixSortDownsweepPolicy <64, 18, DominantT, BLOCK_LOAD_DIRECT, LOAD_LDG, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, PRIMARY_RADIX_BITS - 1> AltDownsweepPolicyKeys; + + // Key-value pairs downsweep policies + typedef DownsweepPolicyKeys DownsweepPolicyPairs; + typedef AgentRadixSortDownsweepPolicy <128, 15, DominantT, BLOCK_LOAD_DIRECT, LOAD_LDG, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, PRIMARY_RADIX_BITS - 1> AltDownsweepPolicyPairs; + + // Downsweep policies + using DownsweepPolicy = + cub::detail::conditional_t< + KEYS_ONLY, DownsweepPolicyKeys, DownsweepPolicyPairs>; + + using AltDownsweepPolicy = + cub::detail::conditional_t; + + // Upsweep policies + using UpsweepPolicy = DownsweepPolicy; + using AltUpsweepPolicy = AltDownsweepPolicy; + + // Single-tile policy + using SingleTilePolicy = DownsweepPolicy; + + // Segmented policies + using SegmentedPolicy = DownsweepPolicy; + using AltSegmentedPolicy = AltDownsweepPolicy; + }; + + + /// SM50 + struct Policy500 : ChainedPolicy<500, Policy500, Policy350> + { + enum { + PRIMARY_RADIX_BITS = (sizeof(KeyT) > 1) ? 7 : 5, // 3.5B 32b keys/s, 1.92B 32b pairs/s (TitanX) + SINGLE_TILE_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, + SEGMENTED_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, // 3.1B 32b segmented keys/s (TitanX) + ONESWEEP = false, + ONESWEEP_RADIX_BITS = 8, + }; + + // Histogram policy + typedef AgentRadixSortHistogramPolicy <256, 8, 1, KeyT, ONESWEEP_RADIX_BITS> HistogramPolicy; + + // Exclusive sum policy + typedef AgentRadixSortExclusiveSumPolicy <256, ONESWEEP_RADIX_BITS> ExclusiveSumPolicy; + + // Onesweep policy + typedef AgentRadixSortOnesweepPolicy <256, 21, DominantT, 1, + RADIX_RANK_MATCH_EARLY_COUNTS_ANY, BLOCK_SCAN_WARP_SCANS, RADIX_SORT_STORE_DIRECT, + ONESWEEP_RADIX_BITS> OnesweepPolicy; + + // ScanPolicy + typedef AgentScanPolicy <512, 23, OffsetT, BLOCK_LOAD_WARP_TRANSPOSE, LOAD_DEFAULT, BLOCK_STORE_WARP_TRANSPOSE, BLOCK_SCAN_RAKING_MEMOIZE> ScanPolicy; + + // Downsweep policies + typedef AgentRadixSortDownsweepPolicy <160, 39, DominantT, BLOCK_LOAD_WARP_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_BASIC, BLOCK_SCAN_WARP_SCANS, PRIMARY_RADIX_BITS> DownsweepPolicy; + typedef AgentRadixSortDownsweepPolicy <256, 16, DominantT, BLOCK_LOAD_DIRECT, LOAD_LDG, RADIX_RANK_MEMOIZE, BLOCK_SCAN_RAKING_MEMOIZE, PRIMARY_RADIX_BITS - 1> AltDownsweepPolicy; + + // Upsweep policies + typedef DownsweepPolicy UpsweepPolicy; + typedef AltDownsweepPolicy AltUpsweepPolicy; + + // Single-tile policy + typedef AgentRadixSortDownsweepPolicy <256, 19, DominantT, BLOCK_LOAD_DIRECT, LOAD_LDG, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SINGLE_TILE_RADIX_BITS> SingleTilePolicy; + + // Segmented policies + typedef AgentRadixSortDownsweepPolicy <192, 31, DominantT, BLOCK_LOAD_WARP_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SEGMENTED_RADIX_BITS> SegmentedPolicy; + typedef AgentRadixSortDownsweepPolicy <256, 11, DominantT, BLOCK_LOAD_WARP_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SEGMENTED_RADIX_BITS - 1> AltSegmentedPolicy; + }; + + + /// SM60 (GP100) + struct Policy600 : ChainedPolicy<600, Policy600, Policy500> + { + enum { + PRIMARY_RADIX_BITS = (sizeof(KeyT) > 1) ? 7 : 5, // 6.9B 32b keys/s (Quadro P100) + SINGLE_TILE_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, + SEGMENTED_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, // 5.9B 32b segmented keys/s (Quadro P100) + ONESWEEP = sizeof(KeyT) >= sizeof(uint32_t), // 10.0B 32b keys/s (GP100, 64M random keys) + ONESWEEP_RADIX_BITS = 8, + OFFSET_64BIT = sizeof(OffsetT) == 8, + }; + + // Histogram policy + typedef AgentRadixSortHistogramPolicy <256, 8, 8, KeyT, ONESWEEP_RADIX_BITS> HistogramPolicy; + + // Exclusive sum policy + typedef AgentRadixSortExclusiveSumPolicy <256, ONESWEEP_RADIX_BITS> ExclusiveSumPolicy; + + // Onesweep policy + typedef AgentRadixSortOnesweepPolicy <256, OFFSET_64BIT ? 29 : 30, DominantT, 2, + RADIX_RANK_MATCH_EARLY_COUNTS_ANY, BLOCK_SCAN_WARP_SCANS, + RADIX_SORT_STORE_DIRECT, ONESWEEP_RADIX_BITS> OnesweepPolicy; + + // ScanPolicy + typedef AgentScanPolicy <512, 23, OffsetT, BLOCK_LOAD_WARP_TRANSPOSE, LOAD_DEFAULT, BLOCK_STORE_WARP_TRANSPOSE, BLOCK_SCAN_RAKING_MEMOIZE> ScanPolicy; + + // Downsweep policies + typedef AgentRadixSortDownsweepPolicy <256, 25, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MATCH, BLOCK_SCAN_WARP_SCANS, PRIMARY_RADIX_BITS> DownsweepPolicy; + typedef AgentRadixSortDownsweepPolicy <192, OFFSET_64BIT ? 32 : 39, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, PRIMARY_RADIX_BITS - 1> AltDownsweepPolicy; + + // Upsweep policies + typedef DownsweepPolicy UpsweepPolicy; + typedef AltDownsweepPolicy AltUpsweepPolicy; + + // Single-tile policy + typedef AgentRadixSortDownsweepPolicy <256, 19, DominantT, BLOCK_LOAD_DIRECT, LOAD_LDG, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SINGLE_TILE_RADIX_BITS> SingleTilePolicy; + + // Segmented policies + typedef AgentRadixSortDownsweepPolicy <192, 39, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SEGMENTED_RADIX_BITS> SegmentedPolicy; + typedef AgentRadixSortDownsweepPolicy <384, 11, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SEGMENTED_RADIX_BITS - 1> AltSegmentedPolicy; + + }; + + + /// SM61 (GP104) + struct Policy610 : ChainedPolicy<610, Policy610, Policy600> + { + enum { + PRIMARY_RADIX_BITS = (sizeof(KeyT) > 1) ? 7 : 5, // 3.4B 32b keys/s, 1.83B 32b pairs/s (1080) + SINGLE_TILE_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, + SEGMENTED_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, // 3.3B 32b segmented keys/s (1080) + ONESWEEP = sizeof(KeyT) >= sizeof(uint32_t), + ONESWEEP_RADIX_BITS = 8, + }; + + // Histogram policy + typedef AgentRadixSortHistogramPolicy <256, 8, 8, KeyT, ONESWEEP_RADIX_BITS> HistogramPolicy; + + // Exclusive sum policy + typedef AgentRadixSortExclusiveSumPolicy <256, ONESWEEP_RADIX_BITS> ExclusiveSumPolicy; + + // Onesweep policy + typedef AgentRadixSortOnesweepPolicy <256, 30, DominantT, 2, + RADIX_RANK_MATCH_EARLY_COUNTS_ANY, BLOCK_SCAN_WARP_SCANS, + RADIX_SORT_STORE_DIRECT, ONESWEEP_RADIX_BITS> OnesweepPolicy; + + // ScanPolicy + typedef AgentScanPolicy <512, 23, OffsetT, BLOCK_LOAD_WARP_TRANSPOSE, LOAD_DEFAULT, BLOCK_STORE_WARP_TRANSPOSE, BLOCK_SCAN_RAKING_MEMOIZE> ScanPolicy; + + // Downsweep policies + typedef AgentRadixSortDownsweepPolicy <384, 31, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MATCH, BLOCK_SCAN_RAKING_MEMOIZE, PRIMARY_RADIX_BITS> DownsweepPolicy; + typedef AgentRadixSortDownsweepPolicy <256, 35, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_RAKING_MEMOIZE, PRIMARY_RADIX_BITS - 1> AltDownsweepPolicy; + + // Upsweep policies + typedef AgentRadixSortUpsweepPolicy <128, 16, DominantT, LOAD_LDG, PRIMARY_RADIX_BITS> UpsweepPolicy; + typedef AgentRadixSortUpsweepPolicy <128, 16, DominantT, LOAD_LDG, PRIMARY_RADIX_BITS - 1> AltUpsweepPolicy; + + // Single-tile policy + typedef AgentRadixSortDownsweepPolicy <256, 19, DominantT, BLOCK_LOAD_DIRECT, LOAD_LDG, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SINGLE_TILE_RADIX_BITS> SingleTilePolicy; + + // Segmented policies + typedef AgentRadixSortDownsweepPolicy <192, 39, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SEGMENTED_RADIX_BITS> SegmentedPolicy; + typedef AgentRadixSortDownsweepPolicy <384, 11, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SEGMENTED_RADIX_BITS - 1> AltSegmentedPolicy; + }; + + + /// SM62 (Tegra, less RF) + struct Policy620 : ChainedPolicy<620, Policy620, Policy610> + { + enum { + PRIMARY_RADIX_BITS = 5, + ALT_RADIX_BITS = PRIMARY_RADIX_BITS - 1, + ONESWEEP = sizeof(KeyT) >= sizeof(uint32_t), + ONESWEEP_RADIX_BITS = 8, + }; + + // Histogram policy + typedef AgentRadixSortHistogramPolicy <256, 8, 8, KeyT, ONESWEEP_RADIX_BITS> HistogramPolicy; + + // Exclusive sum policy + typedef AgentRadixSortExclusiveSumPolicy <256, ONESWEEP_RADIX_BITS> ExclusiveSumPolicy; + + // Onesweep policy + typedef AgentRadixSortOnesweepPolicy <256, 30, DominantT, 2, + RADIX_RANK_MATCH_EARLY_COUNTS_ANY, BLOCK_SCAN_WARP_SCANS, + RADIX_SORT_STORE_DIRECT, ONESWEEP_RADIX_BITS> OnesweepPolicy; + + // ScanPolicy + typedef AgentScanPolicy <512, 23, OffsetT, BLOCK_LOAD_WARP_TRANSPOSE, LOAD_DEFAULT, BLOCK_STORE_WARP_TRANSPOSE, BLOCK_SCAN_RAKING_MEMOIZE> ScanPolicy; + + // Downsweep policies + typedef AgentRadixSortDownsweepPolicy <256, 16, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_RAKING_MEMOIZE, PRIMARY_RADIX_BITS> DownsweepPolicy; + typedef AgentRadixSortDownsweepPolicy <256, 16, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_RAKING_MEMOIZE, ALT_RADIX_BITS> AltDownsweepPolicy; + + // Upsweep policies + typedef DownsweepPolicy UpsweepPolicy; + typedef AltDownsweepPolicy AltUpsweepPolicy; + + // Single-tile policy + typedef AgentRadixSortDownsweepPolicy <256, 19, DominantT, BLOCK_LOAD_DIRECT, LOAD_LDG, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, PRIMARY_RADIX_BITS> SingleTilePolicy; + + // Segmented policies + typedef DownsweepPolicy SegmentedPolicy; + typedef AltDownsweepPolicy AltSegmentedPolicy; + }; + + + /// SM70 (GV100) + struct Policy700 : ChainedPolicy<700, Policy700, Policy620> + { + enum { + PRIMARY_RADIX_BITS = (sizeof(KeyT) > 1) ? 7 : 5, // 7.62B 32b keys/s (GV100) + SINGLE_TILE_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, + SEGMENTED_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, // 8.7B 32b segmented keys/s (GV100) + ONESWEEP = sizeof(KeyT) >= sizeof(uint32_t), // 15.8B 32b keys/s (V100-SXM2, 64M random keys) + ONESWEEP_RADIX_BITS = 8, + OFFSET_64BIT = sizeof(OffsetT) == 8, + }; + + // Histogram policy + typedef AgentRadixSortHistogramPolicy <256, 8, 8, KeyT, ONESWEEP_RADIX_BITS> HistogramPolicy; + + // Exclusive sum policy + typedef AgentRadixSortExclusiveSumPolicy <256, ONESWEEP_RADIX_BITS> ExclusiveSumPolicy; + + // Onesweep policy + typedef AgentRadixSortOnesweepPolicy <256, + sizeof(KeyT) == 4 && sizeof(ValueT) == 4 ? 46 : 23, DominantT, 4, + RADIX_RANK_MATCH_EARLY_COUNTS_ANY, BLOCK_SCAN_WARP_SCANS, + RADIX_SORT_STORE_DIRECT, ONESWEEP_RADIX_BITS> OnesweepPolicy; + + + // ScanPolicy + typedef AgentScanPolicy <512, 23, OffsetT, BLOCK_LOAD_WARP_TRANSPOSE, LOAD_DEFAULT, BLOCK_STORE_WARP_TRANSPOSE, BLOCK_SCAN_RAKING_MEMOIZE> ScanPolicy; + + // Downsweep policies + typedef AgentRadixSortDownsweepPolicy <512, 23, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MATCH, BLOCK_SCAN_WARP_SCANS, PRIMARY_RADIX_BITS> DownsweepPolicy; + typedef AgentRadixSortDownsweepPolicy <(sizeof(KeyT) > 1) ? 256 : 128, OFFSET_64BIT ? 46 : 47, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, PRIMARY_RADIX_BITS - 1> AltDownsweepPolicy; + + // Upsweep policies + typedef AgentRadixSortUpsweepPolicy <256, 23, DominantT, LOAD_DEFAULT, PRIMARY_RADIX_BITS> UpsweepPolicy; + typedef AgentRadixSortUpsweepPolicy <256, OFFSET_64BIT ? 46 : 47, DominantT, LOAD_DEFAULT, PRIMARY_RADIX_BITS - 1> AltUpsweepPolicy; + + // Single-tile policy + typedef AgentRadixSortDownsweepPolicy <256, 19, DominantT, BLOCK_LOAD_DIRECT, LOAD_LDG, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SINGLE_TILE_RADIX_BITS> SingleTilePolicy; + + // Segmented policies + typedef AgentRadixSortDownsweepPolicy <192, 39, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SEGMENTED_RADIX_BITS> SegmentedPolicy; + typedef AgentRadixSortDownsweepPolicy <384, 11, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SEGMENTED_RADIX_BITS - 1> AltSegmentedPolicy; + }; + + + /// SM80 + struct Policy800 : ChainedPolicy<800, Policy800, Policy700> + { + enum { + PRIMARY_RADIX_BITS = (sizeof(KeyT) > 1) ? 7 : 5, + SINGLE_TILE_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, + SEGMENTED_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, + ONESWEEP = sizeof(KeyT) >= sizeof(uint32_t), + ONESWEEP_RADIX_BITS = 8, + OFFSET_64BIT = sizeof(OffsetT) == 8, + }; + + // Histogram policy + typedef AgentRadixSortHistogramPolicy <128, 16, 1, KeyT, ONESWEEP_RADIX_BITS> HistogramPolicy; + + // Exclusive sum policy + typedef AgentRadixSortExclusiveSumPolicy <256, ONESWEEP_RADIX_BITS> ExclusiveSumPolicy; + + // Onesweep policy + typedef AgentRadixSortOnesweepPolicy <384, + OFFSET_64BIT && sizeof(KeyT) == 4 && !KEYS_ONLY ? 17 : 21, DominantT, 1, + RADIX_RANK_MATCH_EARLY_COUNTS_ANY, BLOCK_SCAN_RAKING_MEMOIZE, + RADIX_SORT_STORE_DIRECT, ONESWEEP_RADIX_BITS> OnesweepPolicy; + + // ScanPolicy + typedef AgentScanPolicy <512, 23, OffsetT, BLOCK_LOAD_WARP_TRANSPOSE, LOAD_DEFAULT, BLOCK_STORE_WARP_TRANSPOSE, BLOCK_SCAN_RAKING_MEMOIZE> ScanPolicy; + + // Downsweep policies + typedef AgentRadixSortDownsweepPolicy <512, 23, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MATCH, BLOCK_SCAN_WARP_SCANS, PRIMARY_RADIX_BITS> DownsweepPolicy; + typedef AgentRadixSortDownsweepPolicy <(sizeof(KeyT) > 1) ? 256 : 128, 47, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, PRIMARY_RADIX_BITS - 1> AltDownsweepPolicy; + + // Upsweep policies + typedef AgentRadixSortUpsweepPolicy <256, 23, DominantT, LOAD_DEFAULT, PRIMARY_RADIX_BITS> UpsweepPolicy; + typedef AgentRadixSortUpsweepPolicy <256, 47, DominantT, LOAD_DEFAULT, PRIMARY_RADIX_BITS - 1> AltUpsweepPolicy; + + // Single-tile policy + typedef AgentRadixSortDownsweepPolicy <256, 19, DominantT, BLOCK_LOAD_DIRECT, LOAD_LDG, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SINGLE_TILE_RADIX_BITS> SingleTilePolicy; + + // Segmented policies + typedef AgentRadixSortDownsweepPolicy <192, 39, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SEGMENTED_RADIX_BITS> SegmentedPolicy; + typedef AgentRadixSortDownsweepPolicy <384, 11, DominantT, BLOCK_LOAD_TRANSPOSE, LOAD_DEFAULT, RADIX_RANK_MEMOIZE, BLOCK_SCAN_WARP_SCANS, SEGMENTED_RADIX_BITS - 1> AltSegmentedPolicy; + }; + + /// SM90 + struct Policy900 : ChainedPolicy<900, Policy900, Policy800> + { + enum { + PRIMARY_RADIX_BITS = (sizeof(KeyT) > 1) ? 7 : 5, + SINGLE_TILE_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, + SEGMENTED_RADIX_BITS = (sizeof(KeyT) > 1) ? 6 : 5, + ONESWEEP = true, + ONESWEEP_RADIX_BITS = 8, + OFFSET_64BIT = sizeof(OffsetT) == 8 ? 1 : 0, + FLOAT_KEYS = std::is_same::value ? 1 : 0, + }; + + using HistogramPolicy = + AgentRadixSortHistogramPolicy<128, 16, 1, KeyT, ONESWEEP_RADIX_BITS>; + using ExclusiveSumPolicy = AgentRadixSortExclusiveSumPolicy<256, ONESWEEP_RADIX_BITS>; + + using OnesweepPolicyKey32 = + AgentRadixSortOnesweepPolicy<384, + KEYS_ONLY ? 20 - OFFSET_64BIT - FLOAT_KEYS + : (sizeof(ValueT) < 8 ? (OFFSET_64BIT ? 17 : 23) + : (OFFSET_64BIT ? 29 : 30)), + DominantT, + 1, + RADIX_RANK_MATCH_EARLY_COUNTS_ANY, + BLOCK_SCAN_RAKING_MEMOIZE, + RADIX_SORT_STORE_DIRECT, + ONESWEEP_RADIX_BITS>; + + using OnesweepPolicyKey64 = AgentRadixSortOnesweepPolicy<384, + sizeof(ValueT) < 8 ? 30 : 24, + DominantT, + 1, + RADIX_RANK_MATCH_EARLY_COUNTS_ANY, + BLOCK_SCAN_RAKING_MEMOIZE, + RADIX_SORT_STORE_DIRECT, + ONESWEEP_RADIX_BITS>; + + using OnesweepLargeKeyPolicy = // + cub::detail::conditional_t; + + using OnesweepSmallKeyPolicySizes = // + detail::radix::sm90_small_key_tuning; + using OnesweepSmallKeyPolicy = AgentRadixSortOnesweepPolicy; + using OnesweepPolicy = // + cub::detail::conditional_t; + + using ScanPolicy = AgentScanPolicy<512, + 23, + OffsetT, + BLOCK_LOAD_WARP_TRANSPOSE, + LOAD_DEFAULT, + BLOCK_STORE_WARP_TRANSPOSE, + BLOCK_SCAN_RAKING_MEMOIZE>; + + using DownsweepPolicy = AgentRadixSortDownsweepPolicy<512, + 23, + DominantT, + BLOCK_LOAD_TRANSPOSE, + LOAD_DEFAULT, + RADIX_RANK_MATCH, + BLOCK_SCAN_WARP_SCANS, + PRIMARY_RADIX_BITS>; + + using AltDownsweepPolicy = AgentRadixSortDownsweepPolicy<(sizeof(KeyT) > 1) ? 256 : 128, + 47, + DominantT, + BLOCK_LOAD_TRANSPOSE, + LOAD_DEFAULT, + RADIX_RANK_MEMOIZE, + BLOCK_SCAN_WARP_SCANS, + PRIMARY_RADIX_BITS - 1>; + + using UpsweepPolicy = + AgentRadixSortUpsweepPolicy<256, 23, DominantT, LOAD_DEFAULT, PRIMARY_RADIX_BITS>; + using AltUpsweepPolicy = + AgentRadixSortUpsweepPolicy<256, 47, DominantT, LOAD_DEFAULT, PRIMARY_RADIX_BITS - 1>; + + using SingleTilePolicy = AgentRadixSortDownsweepPolicy<256, + 19, + DominantT, + BLOCK_LOAD_DIRECT, + LOAD_LDG, + RADIX_RANK_MEMOIZE, + BLOCK_SCAN_WARP_SCANS, + SINGLE_TILE_RADIX_BITS>; + + using SegmentedPolicy = AgentRadixSortDownsweepPolicy<192, + 39, + DominantT, + BLOCK_LOAD_TRANSPOSE, + LOAD_DEFAULT, + RADIX_RANK_MEMOIZE, + BLOCK_SCAN_WARP_SCANS, + SEGMENTED_RADIX_BITS>; + + using AltSegmentedPolicy = AgentRadixSortDownsweepPolicy<384, + 11, + DominantT, + BLOCK_LOAD_TRANSPOSE, + LOAD_DEFAULT, + RADIX_RANK_MEMOIZE, + BLOCK_SCAN_WARP_SCANS, + SEGMENTED_RADIX_BITS - 1>; + }; + + + using MaxPolicy = Policy900; +}; + + + +/****************************************************************************** + * Single-problem dispatch + ******************************************************************************/ + +/** + * Utility class for dispatching the appropriately-tuned kernels for device-wide radix sort + * + * @tparam IS_DESCENDING + * Whether or not the sorted-order is high-to-low + * + * @tparam KeyT + * Key type + * + * @tparam ValueT + * Value type + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam DecomposerT + * Implementation detail, do not specify directly, requirements on the + * content of this type are subject to breaking change. + */ +template , + typename DecomposerT = detail::identity_decomposer_t> +struct DispatchRadixSort : SelectedPolicy +{ + //------------------------------------------------------------------------------ + // Constants + //------------------------------------------------------------------------------ + + // Whether this is a keys-only (or key-value) sort + constexpr static bool KEYS_ONLY = std::is_same::value; + + //------------------------------------------------------------------------------ + // Problem state + //------------------------------------------------------------------------------ + + void *d_temp_storage; ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t &temp_storage_bytes; ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation + DoubleBuffer &d_keys; ///< [in,out] Double-buffer whose current buffer contains the unsorted input keys and, upon return, is updated to point to the sorted output keys + DoubleBuffer &d_values; ///< [in,out] Double-buffer whose current buffer contains the unsorted input values and, upon return, is updated to point to the sorted output values + OffsetT num_items; ///< [in] Number of items to sort + int begin_bit; ///< [in] The beginning (least-significant) bit index needed for key comparison + int end_bit; ///< [in] The past-the-end (most-significant) bit index needed for key comparison + cudaStream_t stream; ///< [in] CUDA stream to launch kernels within. Default is stream0. + int ptx_version; ///< [in] PTX version + bool is_overwrite_okay; ///< [in] Whether is okay to overwrite source buffers + DecomposerT decomposer; + + + //------------------------------------------------------------------------------ + // Constructor + //------------------------------------------------------------------------------ + + /// Constructor + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchRadixSort( + void* d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + OffsetT num_items, + int begin_bit, + int end_bit, + bool is_overwrite_okay, + cudaStream_t stream, + int ptx_version, + DecomposerT decomposer = {}) + : + d_temp_storage(d_temp_storage), + temp_storage_bytes(temp_storage_bytes), + d_keys(d_keys), + d_values(d_values), + num_items(num_items), + begin_bit(begin_bit), + end_bit(end_bit), + stream(stream), + ptx_version(ptx_version), + is_overwrite_okay(is_overwrite_okay), + decomposer(decomposer) + {} + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchRadixSort( + void* d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + OffsetT num_items, + int begin_bit, + int end_bit, + bool is_overwrite_okay, + cudaStream_t stream, + bool debug_synchronous, + int ptx_version) + : + d_temp_storage(d_temp_storage), + temp_storage_bytes(temp_storage_bytes), + d_keys(d_keys), + d_values(d_values), + num_items(num_items), + begin_bit(begin_bit), + end_bit(end_bit), + stream(stream), + ptx_version(ptx_version), + is_overwrite_okay(is_overwrite_okay) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + } + + + //------------------------------------------------------------------------------ + // Small-problem (single tile) invocation + //------------------------------------------------------------------------------ + + /// Invoke a single block to sort in-core + template < + typename ActivePolicyT, ///< Umbrella policy active for the target device + typename SingleTileKernelT> ///< Function type of cub::DeviceRadixSortSingleTileKernel + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t InvokeSingleTile( + SingleTileKernelT single_tile_kernel) ///< [in] Kernel function pointer to parameterization of cub::DeviceRadixSortSingleTileKernel + { + cudaError error = cudaSuccess; + do + { + // Return if the caller is simply requesting the size of the storage allocation + if (d_temp_storage == NULL) + { + temp_storage_bytes = 1; + break; + } + + // Log single_tile_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking single_tile_kernel<<<%d, %d, 0, %lld>>>(), %d items per thread, %d SM occupancy, current bit %d, bit_grain %d\n", + 1, ActivePolicyT::SingleTilePolicy::BLOCK_THREADS, (long long) stream, + ActivePolicyT::SingleTilePolicy::ITEMS_PER_THREAD, 1, begin_bit, ActivePolicyT::SingleTilePolicy::RADIX_BITS); + #endif + + // Invoke upsweep_kernel with same grid size as downsweep_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + 1, ActivePolicyT::SingleTilePolicy::BLOCK_THREADS, 0, stream + ).doit(single_tile_kernel, + d_keys.Current(), + d_keys.Alternate(), + d_values.Current(), + d_values.Alternate(), + num_items, + begin_bit, + end_bit, + decomposer); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Update selector + d_keys.selector ^= 1; + d_values.selector ^= 1; + } + while (0); + + return error; + } + + + //------------------------------------------------------------------------------ + // Normal problem size invocation + //------------------------------------------------------------------------------ + + /** + * Invoke a three-kernel sorting pass at the current bit. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t InvokePass( + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + OffsetT *d_spine, + int /*spine_length*/, + int ¤t_bit, + PassConfigT &pass_config) + { + cudaError error = cudaSuccess; + do + { + int pass_bits = CUB_MIN(pass_config.radix_bits, (end_bit - current_bit)); + + // Log upsweep_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking upsweep_kernel<<<%d, %d, 0, %lld>>>(), %d items per thread, %d SM occupancy, current bit %d, bit_grain %d\n", + pass_config.even_share.grid_size, pass_config.upsweep_config.block_threads, (long long) stream, + pass_config.upsweep_config.items_per_thread, pass_config.upsweep_config.sm_occupancy, current_bit, pass_bits); + #endif + + // Spine length written by the upsweep kernel in the current pass. + int pass_spine_length = pass_config.even_share.grid_size * pass_config.radix_digits; + + // Invoke upsweep_kernel with same grid size as downsweep_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + pass_config.even_share.grid_size, + pass_config.upsweep_config.block_threads, 0, stream + ).doit(pass_config.upsweep_kernel, + d_keys_in, + d_spine, + num_items, + current_bit, + pass_bits, + pass_config.even_share, + decomposer); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Log scan_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking scan_kernel<<<%d, %d, 0, %lld>>>(), %d items per thread\n", + 1, pass_config.scan_config.block_threads, (long long) stream, pass_config.scan_config.items_per_thread); + #endif + + // Invoke scan_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + 1, pass_config.scan_config.block_threads, 0, stream + ).doit(pass_config.scan_kernel, + d_spine, + pass_spine_length); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Log downsweep_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking downsweep_kernel<<<%d, %d, 0, %lld>>>(), %d items per thread, %d SM occupancy\n", + pass_config.even_share.grid_size, pass_config.downsweep_config.block_threads, (long long) stream, + pass_config.downsweep_config.items_per_thread, pass_config.downsweep_config.sm_occupancy); + #endif + + // Invoke downsweep_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + pass_config.even_share.grid_size, + pass_config.downsweep_config.block_threads, 0, stream + ).doit(pass_config.downsweep_kernel, + d_keys_in, + d_keys_out, + d_values_in, + d_values_out, + d_spine, + num_items, + current_bit, + pass_bits, + pass_config.even_share, + decomposer); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Update current bit + current_bit += pass_bits; + } + while (0); + + return error; + } + + + + /// Pass configuration structure + template < + typename UpsweepKernelT, + typename ScanKernelT, + typename DownsweepKernelT> + struct PassConfig + { + UpsweepKernelT upsweep_kernel; + KernelConfig upsweep_config; + ScanKernelT scan_kernel; + KernelConfig scan_config; + DownsweepKernelT downsweep_kernel; + KernelConfig downsweep_config; + int radix_bits; + int radix_digits; + int max_downsweep_grid_size; + GridEvenShare even_share; + + /// Initialize pass configuration + template < + typename UpsweepPolicyT, + typename ScanPolicyT, + typename DownsweepPolicyT> + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t InitPassConfig( + UpsweepKernelT upsweep_kernel, + ScanKernelT scan_kernel, + DownsweepKernelT downsweep_kernel, + int /*ptx_version*/, + int sm_count, + OffsetT num_items) + { + cudaError error = cudaSuccess; + do + { + this->upsweep_kernel = upsweep_kernel; + this->scan_kernel = scan_kernel; + this->downsweep_kernel = downsweep_kernel; + radix_bits = DownsweepPolicyT::RADIX_BITS; + radix_digits = 1 << radix_bits; + + if (CubDebug(error = upsweep_config.Init(upsweep_kernel))) break; + if (CubDebug(error = scan_config.Init(scan_kernel))) break; + if (CubDebug(error = downsweep_config.Init(downsweep_kernel))) break; + + max_downsweep_grid_size = (downsweep_config.sm_occupancy * sm_count) * CUB_SUBSCRIPTION_FACTOR(0); + + even_share.DispatchInit( + num_items, + max_downsweep_grid_size, + CUB_MAX(downsweep_config.tile_size, upsweep_config.tile_size)); + + } + while (0); + return error; + } + + }; + + template + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t InvokeOnesweep() + { + typedef typename DispatchRadixSort::MaxPolicy MaxPolicyT; + // PortionOffsetT is used for offsets within a portion, and must be signed. + typedef int PortionOffsetT; + typedef PortionOffsetT AtomicOffsetT; + + // compute temporary storage size + const int RADIX_BITS = ActivePolicyT::ONESWEEP_RADIX_BITS; + const int RADIX_DIGITS = 1 << RADIX_BITS; + const int ONESWEEP_ITEMS_PER_THREAD = ActivePolicyT::OnesweepPolicy::ITEMS_PER_THREAD; + const int ONESWEEP_BLOCK_THREADS = ActivePolicyT::OnesweepPolicy::BLOCK_THREADS; + const int ONESWEEP_TILE_ITEMS = ONESWEEP_ITEMS_PER_THREAD * ONESWEEP_BLOCK_THREADS; + // portions handle inputs with >=2**30 elements, due to the way lookback works + // for testing purposes, one portion is <= 2**28 elements + const PortionOffsetT PORTION_SIZE = ((1 << 28) - 1) / ONESWEEP_TILE_ITEMS * ONESWEEP_TILE_ITEMS; + int num_passes = cub::DivideAndRoundUp(end_bit - begin_bit, RADIX_BITS); + OffsetT num_portions = static_cast(cub::DivideAndRoundUp(num_items, PORTION_SIZE)); + PortionOffsetT max_num_blocks = cub::DivideAndRoundUp( + static_cast( + CUB_MIN(num_items, static_cast(PORTION_SIZE))), + ONESWEEP_TILE_ITEMS); + + size_t value_size = KEYS_ONLY ? 0 : sizeof(ValueT); + size_t allocation_sizes[] = + { + // bins + num_portions * num_passes * RADIX_DIGITS * sizeof(OffsetT), + // lookback + max_num_blocks * RADIX_DIGITS * sizeof(AtomicOffsetT), + // extra key buffer + is_overwrite_okay || num_passes <= 1 ? 0 : num_items * sizeof(KeyT), + // extra value buffer + is_overwrite_okay || num_passes <= 1 ? 0 : num_items * value_size, + // counters + num_portions * num_passes * sizeof(AtomicOffsetT), + }; + const int NUM_ALLOCATIONS = sizeof(allocation_sizes) / sizeof(allocation_sizes[0]); + void* allocations[NUM_ALLOCATIONS] = {}; + AliasTemporaries(d_temp_storage, temp_storage_bytes, + allocations, allocation_sizes); + + // just return if no temporary storage is provided + cudaError_t error = cudaSuccess; + if (d_temp_storage == NULL) return error; + + OffsetT* d_bins = (OffsetT*)allocations[0]; + AtomicOffsetT* d_lookback = (AtomicOffsetT*)allocations[1]; + KeyT* d_keys_tmp2 = (KeyT*)allocations[2]; + ValueT* d_values_tmp2 = (ValueT*)allocations[3]; + AtomicOffsetT* d_ctrs = (AtomicOffsetT*)allocations[4]; + + do { + // initialization + if (CubDebug(error = cudaMemsetAsync( + d_ctrs, 0, num_portions * num_passes * sizeof(AtomicOffsetT), stream))) break; + + // compute num_passes histograms with RADIX_DIGITS bins each + if (CubDebug(error = cudaMemsetAsync + (d_bins, 0, num_passes * RADIX_DIGITS * sizeof(OffsetT), stream))) break; + int device = -1; + int num_sms = 0; + if (CubDebug(error = cudaGetDevice(&device))) break; + if (CubDebug(error = cudaDeviceGetAttribute( + &num_sms, cudaDevAttrMultiProcessorCount, device))) break; + + const int HISTO_BLOCK_THREADS = ActivePolicyT::HistogramPolicy::BLOCK_THREADS; + int histo_blocks_per_sm = 1; + auto histogram_kernel = DeviceRadixSortHistogramKernel< + MaxPolicyT, IS_DESCENDING, KeyT, OffsetT, DecomposerT>; + if (CubDebug(error = cudaOccupancyMaxActiveBlocksPerMultiprocessor( + &histo_blocks_per_sm, histogram_kernel, HISTO_BLOCK_THREADS, 0))) break; + + // log histogram_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking histogram_kernel<<<%d, %d, 0, %lld>>>(), %d items per iteration, " + "%d SM occupancy, bit_grain %d\n", + histo_blocks_per_sm * num_sms, HISTO_BLOCK_THREADS, + reinterpret_cast(stream), + ActivePolicyT::HistogramPolicy::ITEMS_PER_THREAD, histo_blocks_per_sm, + ActivePolicyT::HistogramPolicy::RADIX_BITS); + #endif + + error = THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + histo_blocks_per_sm * num_sms, HISTO_BLOCK_THREADS, 0, stream + ).doit(histogram_kernel, + d_bins, d_keys.Current(), num_items, begin_bit, end_bit, decomposer); + if (CubDebug(error)) + { + break; + } + + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // exclusive sums to determine starts + const int SCAN_BLOCK_THREADS = ActivePolicyT::ExclusiveSumPolicy::BLOCK_THREADS; + + // log exclusive_sum_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking exclusive_sum_kernel<<<%d, %d, 0, %lld>>>(), bit_grain %d\n", + num_passes, SCAN_BLOCK_THREADS, reinterpret_cast(stream), + ActivePolicyT::ExclusiveSumPolicy::RADIX_BITS); + #endif + + error = THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + num_passes, SCAN_BLOCK_THREADS, 0, stream + ).doit(DeviceRadixSortExclusiveSumKernel, + d_bins); + if (CubDebug(error)) + { + break; + } + + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // use the other buffer if no overwrite is allowed + KeyT* d_keys_tmp = d_keys.Alternate(); + ValueT* d_values_tmp = d_values.Alternate(); + if (!is_overwrite_okay && num_passes % 2 == 0) + { + d_keys.d_buffers[1] = d_keys_tmp2; + d_values.d_buffers[1] = d_values_tmp2; + } + + for (int current_bit = begin_bit, pass = 0; current_bit < end_bit; + current_bit += RADIX_BITS, ++pass) + { + int num_bits = CUB_MIN(end_bit - current_bit, RADIX_BITS); + for (OffsetT portion = 0; portion < num_portions; ++portion) + { + PortionOffsetT portion_num_items = + static_cast( + CUB_MIN(num_items - portion * PORTION_SIZE, + static_cast(PORTION_SIZE))); + PortionOffsetT num_blocks = + cub::DivideAndRoundUp(portion_num_items, ONESWEEP_TILE_ITEMS); + if (CubDebug(error = cudaMemsetAsync( + d_lookback, 0, num_blocks * RADIX_DIGITS * sizeof(AtomicOffsetT), + stream))) break; + + // log onesweep_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking onesweep_kernel<<<%d, %d, 0, %lld>>>(), %d items per thread, " + "current bit %d, bit_grain %d, portion %d/%d\n", + num_blocks, ONESWEEP_BLOCK_THREADS, reinterpret_cast(stream), + ActivePolicyT::OnesweepPolicy::ITEMS_PER_THREAD, current_bit, + num_bits, static_cast(portion), static_cast(num_portions)); + #endif + + auto onesweep_kernel = DeviceRadixSortOnesweepKernel< + MaxPolicyT, IS_DESCENDING, KeyT, ValueT, OffsetT, PortionOffsetT, AtomicOffsetT, DecomposerT>; + + error = THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + num_blocks, ONESWEEP_BLOCK_THREADS, 0, stream + ).doit(onesweep_kernel, + d_lookback, d_ctrs + portion * num_passes + pass, + portion < num_portions - 1 ? + d_bins + ((portion + 1) * num_passes + pass) * RADIX_DIGITS : NULL, + d_bins + (portion * num_passes + pass) * RADIX_DIGITS, + d_keys.Alternate(), + d_keys.Current() + portion * PORTION_SIZE, + d_values.Alternate(), + d_values.Current() + portion * PORTION_SIZE, + portion_num_items, current_bit, num_bits, + decomposer); + if (CubDebug(error)) + { + break; + } + + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } + + if (error != cudaSuccess) + { + break; + } + + // use the temporary buffers if no overwrite is allowed + if (!is_overwrite_okay && pass == 0) + { + d_keys = num_passes % 2 == 0 ? + DoubleBuffer(d_keys_tmp, d_keys_tmp2) : + DoubleBuffer(d_keys_tmp2, d_keys_tmp); + d_values = num_passes % 2 == 0 ? + DoubleBuffer(d_values_tmp, d_values_tmp2) : + DoubleBuffer(d_values_tmp2, d_values_tmp); + } + d_keys.selector ^= 1; + d_values.selector ^= 1; + } + } while (0); + + return error; + } + + /// Invocation (run multiple digit passes) + template < + typename ActivePolicyT, ///< Umbrella policy active for the target device + typename UpsweepKernelT, ///< Function type of cub::DeviceRadixSortUpsweepKernel + typename ScanKernelT, ///< Function type of cub::SpineScanKernel + typename DownsweepKernelT> ///< Function type of cub::DeviceRadixSortDownsweepKernel + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t InvokePasses( + UpsweepKernelT upsweep_kernel, ///< [in] Kernel function pointer to parameterization of cub::DeviceRadixSortUpsweepKernel + UpsweepKernelT alt_upsweep_kernel, ///< [in] Alternate kernel function pointer to parameterization of cub::DeviceRadixSortUpsweepKernel + ScanKernelT scan_kernel, ///< [in] Kernel function pointer to parameterization of cub::SpineScanKernel + DownsweepKernelT downsweep_kernel, ///< [in] Kernel function pointer to parameterization of cub::DeviceRadixSortDownsweepKernel + DownsweepKernelT alt_downsweep_kernel) ///< [in] Alternate kernel function pointer to parameterization of cub::DeviceRadixSortDownsweepKernel + { + cudaError error = cudaSuccess; + do + { + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) break; + + // Get SM count + int sm_count; + if (CubDebug(error = cudaDeviceGetAttribute (&sm_count, cudaDevAttrMultiProcessorCount, device_ordinal))) break; + + // Init regular and alternate-digit kernel configurations + PassConfig pass_config, alt_pass_config; + error = pass_config.template InitPassConfig< + typename ActivePolicyT::UpsweepPolicy, + typename ActivePolicyT::ScanPolicy, + typename ActivePolicyT::DownsweepPolicy>(upsweep_kernel, + scan_kernel, + downsweep_kernel, + ptx_version, + sm_count, + num_items); + if (error) + { + break; + } + + error = alt_pass_config.template InitPassConfig< + typename ActivePolicyT::AltUpsweepPolicy, + typename ActivePolicyT::ScanPolicy, + typename ActivePolicyT::AltDownsweepPolicy>(alt_upsweep_kernel, + scan_kernel, + alt_downsweep_kernel, + ptx_version, + sm_count, + num_items); + if (error) + { + break; + } + + // Get maximum spine length + int max_grid_size = CUB_MAX(pass_config.max_downsweep_grid_size, alt_pass_config.max_downsweep_grid_size); + int spine_length = (max_grid_size * pass_config.radix_digits) + pass_config.scan_config.tile_size; + + // Temporary storage allocation requirements + void* allocations[3] = {}; + size_t allocation_sizes[3] = + { + spine_length * sizeof(OffsetT), // bytes needed for privatized block digit histograms + (is_overwrite_okay) ? 0 : num_items * sizeof(KeyT), // bytes needed for 3rd keys buffer + (is_overwrite_okay || (KEYS_ONLY)) ? 0 : num_items * sizeof(ValueT), // bytes needed for 3rd values buffer + }; + + // Alias the temporary allocations from the single storage blob (or compute the necessary size of the blob) + if (CubDebug(error = AliasTemporaries(d_temp_storage, temp_storage_bytes, allocations, allocation_sizes))) break; + + // Return if the caller is simply requesting the size of the storage allocation + if (d_temp_storage == NULL) + return cudaSuccess; + + // Pass planning. Run passes of the alternate digit-size configuration until we have an even multiple of our preferred digit size + int num_bits = end_bit - begin_bit; + int num_passes = cub::DivideAndRoundUp(num_bits, pass_config.radix_bits); + bool is_num_passes_odd = num_passes & 1; + int max_alt_passes = (num_passes * pass_config.radix_bits) - num_bits; + int alt_end_bit = CUB_MIN(end_bit, begin_bit + (max_alt_passes * alt_pass_config.radix_bits)); + + // Alias the temporary storage allocations + OffsetT *d_spine = static_cast(allocations[0]); + + DoubleBuffer d_keys_remaining_passes( + (is_overwrite_okay || is_num_passes_odd) ? d_keys.Alternate() : static_cast(allocations[1]), + (is_overwrite_okay) ? d_keys.Current() : (is_num_passes_odd) ? static_cast(allocations[1]) : d_keys.Alternate()); + + DoubleBuffer d_values_remaining_passes( + (is_overwrite_okay || is_num_passes_odd) ? d_values.Alternate() : static_cast(allocations[2]), + (is_overwrite_okay) ? d_values.Current() : (is_num_passes_odd) ? static_cast(allocations[2]) : d_values.Alternate()); + + // Run first pass, consuming from the input's current buffers + int current_bit = begin_bit; + if (CubDebug(error = InvokePass( + d_keys.Current(), d_keys_remaining_passes.Current(), + d_values.Current(), d_values_remaining_passes.Current(), + d_spine, spine_length, current_bit, + (current_bit < alt_end_bit) ? alt_pass_config : pass_config))) break; + + // Run remaining passes + while (current_bit < end_bit) + { + if (CubDebug(error = InvokePass( + d_keys_remaining_passes.d_buffers[d_keys_remaining_passes.selector], d_keys_remaining_passes.d_buffers[d_keys_remaining_passes.selector ^ 1], + d_values_remaining_passes.d_buffers[d_keys_remaining_passes.selector], d_values_remaining_passes.d_buffers[d_keys_remaining_passes.selector ^ 1], + d_spine, spine_length, current_bit, + (current_bit < alt_end_bit) ? alt_pass_config : pass_config))) break;; + + // Invert selectors + d_keys_remaining_passes.selector ^= 1; + d_values_remaining_passes.selector ^= 1; + } + + // Update selector + if (!is_overwrite_okay) { + num_passes = 1; // Sorted data always ends up in the other vector + } + + d_keys.selector = (d_keys.selector + num_passes) & 1; + d_values.selector = (d_values.selector + num_passes) & 1; + } + while (0); + + return error; + } + + + //------------------------------------------------------------------------------ + // Chained policy invocation + //------------------------------------------------------------------------------ + + template + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t InvokeManyTiles(Int2Type) + { + // Invoke upsweep-downsweep + typedef typename DispatchRadixSort::MaxPolicy MaxPolicyT; + return InvokePasses( + DeviceRadixSortUpsweepKernel< MaxPolicyT, false, IS_DESCENDING, KeyT, OffsetT, DecomposerT>, + DeviceRadixSortUpsweepKernel< MaxPolicyT, true, IS_DESCENDING, KeyT, OffsetT, DecomposerT>, + RadixSortScanBinsKernel< MaxPolicyT, OffsetT>, + DeviceRadixSortDownsweepKernel< MaxPolicyT, false, IS_DESCENDING, KeyT, ValueT, OffsetT, DecomposerT>, + DeviceRadixSortDownsweepKernel< MaxPolicyT, true, IS_DESCENDING, KeyT, ValueT, OffsetT, DecomposerT>); + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t InvokeManyTiles(Int2Type) + { + // Invoke onesweep + return InvokeOnesweep(); + } + + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t InvokeCopy() + { + // is_overwrite_okay == false here + // Return the number of temporary bytes if requested + if (d_temp_storage == nullptr) + { + temp_storage_bytes = 1; + return cudaSuccess; + } + + // Copy keys + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking async copy of %lld keys on stream %lld\n", (long long)num_items, + (long long)stream); + #endif + cudaError_t error = cudaSuccess; + error = cudaMemcpyAsync(d_keys.Alternate(), d_keys.Current(), num_items * sizeof(KeyT), + cudaMemcpyDefault, stream); + if (CubDebug(error)) + { + return error; + } + if (CubDebug(error = detail::DebugSyncStream(stream))) + { + return error; + } + d_keys.selector ^= 1; + + // Copy values if necessary + if (!KEYS_ONLY) + { + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking async copy of %lld values on stream %lld\n", + (long long)num_items, (long long)stream); + #endif + error = cudaMemcpyAsync(d_values.Alternate(), d_values.Current(), + num_items * sizeof(ValueT), cudaMemcpyDefault, stream); + if (CubDebug(error)) + { + return error; + } + if (CubDebug(error = detail::DebugSyncStream(stream))) + { + return error; + } + } + d_values.selector ^= 1; + + return error; + } + + /// Invocation + template + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t Invoke() + { + typedef typename DispatchRadixSort::MaxPolicy MaxPolicyT; + typedef typename ActivePolicyT::SingleTilePolicy SingleTilePolicyT; + + // Return if empty problem, or if no bits to sort and double-buffering is used + if (num_items == 0 || (begin_bit == end_bit && is_overwrite_okay)) + { + if (d_temp_storage == nullptr) + { + temp_storage_bytes = 1; + } + return cudaSuccess; + } + + // Check if simple copy suffices (is_overwrite_okay == false at this point) + if (begin_bit == end_bit) + { + bool has_uva = false; + cudaError_t error = detail::HasUVA(has_uva); + if (error != cudaSuccess) return error; + if (has_uva) + { + return InvokeCopy(); + } + } + + // Force kernel code-generation in all compiler passes + if (num_items <= (SingleTilePolicyT::BLOCK_THREADS * SingleTilePolicyT::ITEMS_PER_THREAD)) + { + // Small, single tile size + return InvokeSingleTile( + DeviceRadixSortSingleTileKernel); + } + else + { + // Regular size + return InvokeManyTiles(Int2Type()); + } + } + + + //------------------------------------------------------------------------------ + // Dispatch entrypoints + //------------------------------------------------------------------------------ + + /** + * Internal dispatch routine + */ + CUB_RUNTIME_FUNCTION __forceinline__ + static cudaError_t Dispatch( + void* d_temp_storage, ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t &temp_storage_bytes, ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation + DoubleBuffer &d_keys, ///< [in,out] Double-buffer whose current buffer contains the unsorted input keys and, upon return, is updated to point to the sorted output keys + DoubleBuffer &d_values, ///< [in,out] Double-buffer whose current buffer contains the unsorted input values and, upon return, is updated to point to the sorted output values + OffsetT num_items, ///< [in] Number of items to sort + int begin_bit, ///< [in] The beginning (least-significant) bit index needed for key comparison + int end_bit, ///< [in] The past-the-end (most-significant) bit index needed for key comparison + bool is_overwrite_okay, ///< [in] Whether is okay to overwrite source buffers + cudaStream_t stream, ///< [in] CUDA stream to launch kernels within. Default is stream0. + DecomposerT decomposer = {}) + { + typedef typename DispatchRadixSort::MaxPolicy MaxPolicyT; + + cudaError_t error; + do { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) break; + + // Create dispatch functor + DispatchRadixSort dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + begin_bit, + end_bit, + is_overwrite_okay, + stream, + ptx_version, + decomposer); + + // Dispatch to chained policy + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) break; + + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + OffsetT num_items, + int begin_bit, + int end_bit, + bool is_overwrite_okay, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + begin_bit, + end_bit, + is_overwrite_okay, + stream); + } +}; + + + + +/****************************************************************************** + * Segmented dispatch + ******************************************************************************/ + +/** + * Utility class for dispatching the appropriately-tuned kernels for segmented device-wide radix sort + */ +template < + bool IS_DESCENDING, ///< Whether or not the sorted-order is high-to-low + typename KeyT, ///< Key type + typename ValueT, ///< Value type + typename BeginOffsetIteratorT, ///< Random-access input iterator type for reading segment beginning offsets \iterator + typename EndOffsetIteratorT, ///< Random-access input iterator type for reading segment ending offsets \iterator + typename OffsetT, ///< Signed integer type for global offsets + typename SelectedPolicy = DeviceRadixSortPolicy, + typename DecomposerT = detail::identity_decomposer_t> +struct DispatchSegmentedRadixSort : SelectedPolicy +{ + //------------------------------------------------------------------------------ + // Constants + //------------------------------------------------------------------------------ + + // Whether this is a keys-only (or key-value) sort + constexpr static bool KEYS_ONLY = std::is_same::value; + + //------------------------------------------------------------------------------ + // Parameter members + //------------------------------------------------------------------------------ + + void *d_temp_storage; ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t &temp_storage_bytes; ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation + DoubleBuffer &d_keys; ///< [in,out] Double-buffer whose current buffer contains the unsorted input keys and, upon return, is updated to point to the sorted output keys + DoubleBuffer &d_values; ///< [in,out] Double-buffer whose current buffer contains the unsorted input values and, upon return, is updated to point to the sorted output values + OffsetT num_items; ///< [in] Number of items to sort + OffsetT num_segments; ///< [in] The number of segments that comprise the sorting data + BeginOffsetIteratorT d_begin_offsets; ///< [in] Random-access input iterator to the sequence of beginning offsets of length \p num_segments, such that d_begin_offsets[i] is the first element of the ith data segment in d_keys_* and d_values_* + EndOffsetIteratorT d_end_offsets; ///< [in] Random-access input iterator to the sequence of ending offsets of length \p num_segments, such that d_end_offsets[i]-1 is the last element of the ith data segment in d_keys_* and d_values_*. If d_end_offsets[i]-1 <= d_begin_offsets[i], the ith is considered empty. + int begin_bit; ///< [in] The beginning (least-significant) bit index needed for key comparison + int end_bit; ///< [in] The past-the-end (most-significant) bit index needed for key comparison + cudaStream_t stream; ///< [in] CUDA stream to launch kernels within. Default is stream0. + int ptx_version; ///< [in] PTX version + bool is_overwrite_okay; ///< [in] Whether is okay to overwrite source buffers + DecomposerT decomposer; + + + //------------------------------------------------------------------------------ + // Constructors + //------------------------------------------------------------------------------ + + /// Constructor + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchSegmentedRadixSort( + void* d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + OffsetT num_items, + OffsetT num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit, + int end_bit, + bool is_overwrite_okay, + cudaStream_t stream, + int ptx_version, + DecomposerT decomposer = {}) + : + d_temp_storage(d_temp_storage), + temp_storage_bytes(temp_storage_bytes), + d_keys(d_keys), + d_values(d_values), + num_items(num_items), + num_segments(num_segments), + d_begin_offsets(d_begin_offsets), + d_end_offsets(d_end_offsets), + begin_bit(begin_bit), + end_bit(end_bit), + stream(stream), + ptx_version(ptx_version), + is_overwrite_okay(is_overwrite_okay), + decomposer(decomposer) + {} + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchSegmentedRadixSort( + void* d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + OffsetT num_items, + OffsetT num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit, + int end_bit, + bool is_overwrite_okay, + cudaStream_t stream, + bool debug_synchronous, + int ptx_version) + : + d_temp_storage(d_temp_storage), + temp_storage_bytes(temp_storage_bytes), + d_keys(d_keys), + d_values(d_values), + num_items(num_items), + num_segments(num_segments), + d_begin_offsets(d_begin_offsets), + d_end_offsets(d_end_offsets), + begin_bit(begin_bit), + end_bit(end_bit), + stream(stream), + ptx_version(ptx_version), + is_overwrite_okay(is_overwrite_okay) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + } + + + //------------------------------------------------------------------------------ + // Multi-segment invocation + //------------------------------------------------------------------------------ + + /// Invoke a three-kernel sorting pass at the current bit. + template + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t InvokePass( + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + int ¤t_bit, + PassConfigT &pass_config) + { + cudaError error = cudaSuccess; + do + { + int pass_bits = CUB_MIN(pass_config.radix_bits, (end_bit - current_bit)); + + // Log kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking segmented_kernels<<<%lld, %lld, 0, %lld>>>(), " + "%lld items per thread, %lld SM occupancy, " + "current bit %d, bit_grain %d\n", + (long long)num_segments, + (long long)pass_config.segmented_config.block_threads, + (long long)stream, + (long long)pass_config.segmented_config.items_per_thread, + (long long)pass_config.segmented_config.sm_occupancy, + current_bit, + pass_bits); + #endif + + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + num_segments, pass_config.segmented_config.block_threads, 0, + stream + ).doit(pass_config.segmented_kernel, + d_keys_in, d_keys_out, + d_values_in, d_values_out, + d_begin_offsets, d_end_offsets, num_segments, + current_bit, pass_bits, decomposer); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Update current bit + current_bit += pass_bits; + } + while (0); + + return error; + } + + + /// PassConfig data structure + template + struct PassConfig + { + SegmentedKernelT segmented_kernel; + KernelConfig segmented_config; + int radix_bits; + int radix_digits; + + /// Initialize pass configuration + template + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t InitPassConfig(SegmentedKernelT segmented_kernel) + { + this->segmented_kernel = segmented_kernel; + this->radix_bits = SegmentedPolicyT::RADIX_BITS; + this->radix_digits = 1 << radix_bits; + + return CubDebug(segmented_config.Init(segmented_kernel)); + } + }; + + + /// Invocation (run multiple digit passes) + template < + typename ActivePolicyT, ///< Umbrella policy active for the target device + typename SegmentedKernelT> ///< Function type of cub::DeviceSegmentedRadixSortKernel + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t InvokePasses( + SegmentedKernelT segmented_kernel, ///< [in] Kernel function pointer to parameterization of cub::DeviceSegmentedRadixSortKernel + SegmentedKernelT alt_segmented_kernel) ///< [in] Alternate kernel function pointer to parameterization of cub::DeviceSegmentedRadixSortKernel + { + cudaError error = cudaSuccess; + do + { + // Init regular and alternate kernel configurations + PassConfig pass_config, alt_pass_config; + if ((error = pass_config.template InitPassConfig(segmented_kernel))) break; + if ((error = alt_pass_config.template InitPassConfig(alt_segmented_kernel))) break; + + // Temporary storage allocation requirements + void* allocations[2] = {}; + size_t allocation_sizes[2] = + { + (is_overwrite_okay) ? 0 : num_items * sizeof(KeyT), // bytes needed for 3rd keys buffer + (is_overwrite_okay || (KEYS_ONLY)) ? 0 : num_items * sizeof(ValueT), // bytes needed for 3rd values buffer + }; + + // Alias the temporary allocations from the single storage blob (or compute the necessary size of the blob) + if (CubDebug(error = AliasTemporaries(d_temp_storage, temp_storage_bytes, allocations, allocation_sizes))) break; + + // Return if the caller is simply requesting the size of the storage allocation + if (d_temp_storage == NULL) + { + if (temp_storage_bytes == 0) + temp_storage_bytes = 1; + return cudaSuccess; + } + + // Pass planning. Run passes of the alternate digit-size configuration until we have an even multiple of our preferred digit size + int radix_bits = ActivePolicyT::SegmentedPolicy::RADIX_BITS; + int alt_radix_bits = ActivePolicyT::AltSegmentedPolicy::RADIX_BITS; + int num_bits = end_bit - begin_bit; + int num_passes = CUB_MAX(DivideAndRoundUp(num_bits, radix_bits), 1); + bool is_num_passes_odd = num_passes & 1; + int max_alt_passes = (num_passes * radix_bits) - num_bits; + int alt_end_bit = CUB_MIN(end_bit, begin_bit + (max_alt_passes * alt_radix_bits)); + + DoubleBuffer d_keys_remaining_passes( + (is_overwrite_okay || is_num_passes_odd) ? d_keys.Alternate() : static_cast(allocations[0]), + (is_overwrite_okay) ? d_keys.Current() : (is_num_passes_odd) ? static_cast(allocations[0]) : d_keys.Alternate()); + + DoubleBuffer d_values_remaining_passes( + (is_overwrite_okay || is_num_passes_odd) ? d_values.Alternate() : static_cast(allocations[1]), + (is_overwrite_okay) ? d_values.Current() : (is_num_passes_odd) ? static_cast(allocations[1]) : d_values.Alternate()); + + // Run first pass, consuming from the input's current buffers + int current_bit = begin_bit; + + if (CubDebug(error = InvokePass( + d_keys.Current(), d_keys_remaining_passes.Current(), + d_values.Current(), d_values_remaining_passes.Current(), + current_bit, + (current_bit < alt_end_bit) ? alt_pass_config : pass_config))) break; + + // Run remaining passes + while (current_bit < end_bit) + { + if (CubDebug(error = InvokePass( + d_keys_remaining_passes.d_buffers[d_keys_remaining_passes.selector], d_keys_remaining_passes.d_buffers[d_keys_remaining_passes.selector ^ 1], + d_values_remaining_passes.d_buffers[d_keys_remaining_passes.selector], d_values_remaining_passes.d_buffers[d_keys_remaining_passes.selector ^ 1], + current_bit, + (current_bit < alt_end_bit) ? alt_pass_config : pass_config))) break; + + // Invert selectors and update current bit + d_keys_remaining_passes.selector ^= 1; + d_values_remaining_passes.selector ^= 1; + } + + // Update selector + if (!is_overwrite_okay) { + num_passes = 1; // Sorted data always ends up in the other vector + } + + d_keys.selector = (d_keys.selector + num_passes) & 1; + d_values.selector = (d_values.selector + num_passes) & 1; + } + while (0); + + return error; + } + + + //------------------------------------------------------------------------------ + // Chained policy invocation + //------------------------------------------------------------------------------ + + /// Invocation + template + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t Invoke() + { + typedef typename DispatchSegmentedRadixSort::MaxPolicy MaxPolicyT; + + // Return if empty problem, or if no bits to sort and double-buffering is used + if (num_items == 0 || (begin_bit == end_bit && is_overwrite_okay)) + { + if (d_temp_storage == nullptr) + { + temp_storage_bytes = 1; + } + return cudaSuccess; + } + + // Force kernel code-generation in all compiler passes + return InvokePasses( + DeviceSegmentedRadixSortKernel, + DeviceSegmentedRadixSortKernel); + } + + + //------------------------------------------------------------------------------ + // Dispatch entrypoints + //------------------------------------------------------------------------------ + + + /// Internal dispatch routine + CUB_RUNTIME_FUNCTION __forceinline__ + static cudaError_t Dispatch( + void* d_temp_storage, ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t &temp_storage_bytes, ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation + DoubleBuffer &d_keys, ///< [in,out] Double-buffer whose current buffer contains the unsorted input keys and, upon return, is updated to point to the sorted output keys + DoubleBuffer &d_values, ///< [in,out] Double-buffer whose current buffer contains the unsorted input values and, upon return, is updated to point to the sorted output values + int num_items, ///< [in] Number of items to sort + int num_segments, ///< [in] The number of segments that comprise the sorting data + BeginOffsetIteratorT d_begin_offsets, ///< [in] Random-access input iterator to the sequence of beginning offsets of length \p num_segments, such that d_begin_offsets[i] is the first element of the ith data segment in d_keys_* and d_values_* + EndOffsetIteratorT d_end_offsets, ///< [in] Random-access input iterator to the sequence of ending offsets of length \p num_segments, such that d_end_offsets[i]-1 is the last element of the ith data segment in d_keys_* and d_values_*. If d_end_offsets[i]-1 <= d_begin_offsets[i], the ith is considered empty. + int begin_bit, ///< [in] The beginning (least-significant) bit index needed for key comparison + int end_bit, ///< [in] The past-the-end (most-significant) bit index needed for key comparison + bool is_overwrite_okay, ///< [in] Whether is okay to overwrite source buffers + cudaStream_t stream) ///< [in] CUDA stream to launch kernels within. Default is stream0. + { + typedef typename DispatchSegmentedRadixSort::MaxPolicy MaxPolicyT; + + cudaError_t error; + do { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) break; + + // Create dispatch functor + DispatchSegmentedRadixSort dispatch( + d_temp_storage, temp_storage_bytes, + d_keys, d_values, + num_items, num_segments, d_begin_offsets, d_end_offsets, + begin_bit, end_bit, is_overwrite_okay, + stream, ptx_version); + + // Dispatch to chained policy + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) break; + + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + int num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int begin_bit, + int end_bit, + bool is_overwrite_okay, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + begin_bit, + end_bit, + is_overwrite_okay, + stream); + } +}; + + +CUB_NAMESPACE_END + + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_reduce.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_reduce.cuh new file mode 100644 index 0000000000000000000000000000000000000000..994adc0954c446a8253f4ee5eba8f2a798067987 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_reduce.cuh @@ -0,0 +1,1402 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::DeviceReduce provides device-wide, parallel operations for + * computing a reduction across a sequence of data items residing within + * device-accessible memory. + */ + +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ +namespace reduce +{ + +/** + * All cub::DeviceReduce::* algorithms are using the same implementation. Some of them, however, + * should use initial value only for empty problems. If this struct is used as initial value with + * one of the `DeviceReduce` algorithms, the `init` value wrapped by this struct will only be used + * for empty problems; it will not be incorporated into the aggregate of non-empty problems. + */ +template +struct empty_problem_init_t +{ + T init; + + __host__ __device__ operator T() const { return init; } +}; + +/** + * @brief Applies initial value to the block aggregate and stores the result to the output iterator. + * + * @param d_out Iterator to the output aggregate + * @param reduction_op Binary reduction functor + * @param init Initial value + * @param block_aggregate Aggregate value computed by the block + */ +template +__host__ __device__ void finalize_and_store_aggregate(OutputIteratorT d_out, + ReductionOpT reduction_op, + InitT init, + AccumT block_aggregate) +{ + *d_out = reduction_op(init, block_aggregate); +} + +/** + * @brief Ignores initial value and stores the block aggregate to the output iterator. + * + * @param d_out Iterator to the output aggregate + * @param block_aggregate Aggregate value computed by the block + */ +template +__host__ __device__ void finalize_and_store_aggregate(OutputIteratorT d_out, + ReductionOpT, + empty_problem_init_t, + AccumT block_aggregate) +{ + *d_out = block_aggregate; +} +} // namespace reduce +} // namespace detail + +/****************************************************************************** + * Kernel entry points + *****************************************************************************/ + +/** + * @brief Reduce region kernel entry point (multi-block). Computes privatized + * reductions, one per thread block. + * + * @tparam ChainedPolicyT + * Chained tuning policy + * + * @tparam InputIteratorT + * Random-access input iterator type for reading input items \iterator + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam ReductionOpT + * Binary reduction functor type having member + * `auto operator()(const T &a, const U &b)` + * + * @tparam InitT + * Initial value type + * + * @tparam AccumT + * Accumulator type + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_items + * Total number of input data items + * + * @param[in] even_share + * Even-share descriptor for mapping an equal number of tiles onto each + * thread block + * + * @param[in] reduction_op + * Binary reduction functor + */ +template +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::ReducePolicy::BLOCK_THREADS)) +__global__ void DeviceReduceKernel(InputIteratorT d_in, + AccumT* d_out, + OffsetT num_items, + GridEvenShare even_share, + ReductionOpT reduction_op) +{ + // Thread block type for reducing input tiles + using AgentReduceT = + AgentReduce; + + // Shared memory storage + __shared__ typename AgentReduceT::TempStorage temp_storage; + + // Consume input tiles + AccumT block_aggregate = + AgentReduceT(temp_storage, d_in, reduction_op).ConsumeTiles(even_share); + + // Output result + if (threadIdx.x == 0) + { + detail::uninitialized_copy(d_out + blockIdx.x, block_aggregate); + } +} + +/** + * @brief Reduce a single tile kernel entry point (single-block). Can be used + * to aggregate privatized thread block reductions from a previous + * multi-block reduction pass. + * + * @tparam ChainedPolicyT + * Chained tuning policy + * + * @tparam InputIteratorT + * Random-access input iterator type for reading input items \iterator + * + * @tparam OutputIteratorT + * Output iterator type for recording the reduced aggregate \iterator + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam ReductionOpT + * Binary reduction functor type having member + * `T operator()(const T &a, const U &b)` + * + * @tparam InitT + * Initial value type + * + * @tparam AccumT + * Accumulator type + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_items + * Total number of input data items + * + * @param[in] reduction_op + * Binary reduction functor + * + * @param[in] init + * The initial value of the reduction + */ +template +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::SingleTilePolicy::BLOCK_THREADS), 1) +__global__ void DeviceReduceSingleTileKernel(InputIteratorT d_in, + OutputIteratorT d_out, + OffsetT num_items, + ReductionOpT reduction_op, + InitT init) +{ + // Thread block type for reducing input tiles + using AgentReduceT = + AgentReduce; + + // Shared memory storage + __shared__ typename AgentReduceT::TempStorage temp_storage; + + // Check if empty problem + if (num_items == 0) + { + if (threadIdx.x == 0) + { + *d_out = init; + } + + return; + } + + // Consume input tiles + AccumT block_aggregate = AgentReduceT(temp_storage, d_in, reduction_op) + .ConsumeRange(OffsetT(0), num_items); + + // Output result + if (threadIdx.x == 0) + { + detail::reduce::finalize_and_store_aggregate(d_out, reduction_op, init, block_aggregate); + } +} + +/// Normalize input iterator to segment offset +template +__device__ __forceinline__ void NormalizeReductionOutput(T & /*val*/, + OffsetT /*base_offset*/, + IteratorT /*itr*/) +{} + +/// Normalize input iterator to segment offset (specialized for arg-index) +template +__device__ __forceinline__ void NormalizeReductionOutput( + KeyValuePairT &val, + OffsetT base_offset, + ArgIndexInputIterator /*itr*/) +{ + val.key -= base_offset; +} + +/** + * Segmented reduction (one block per segment) + * @tparam ChainedPolicyT + * Chained tuning policy + * + * @tparam InputIteratorT + * Random-access input iterator type for reading input items \iterator + * + * @tparam OutputIteratorT + * Output iterator type for recording the reduced aggregate \iterator + * + * @tparam BeginOffsetIteratorT + * Random-access input iterator type for reading segment beginning offsets + * \iterator + * + * @tparam EndOffsetIteratorT + * Random-access input iterator type for reading segment ending offsets + * \iterator + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam ReductionOpT + * Binary reduction functor type having member + * `T operator()(const T &a, const U &b)` + * + * @tparam InitT + * Initial value type + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first element + * of the *i*th data segment in `d_keys_*` and `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + * considered empty. + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] reduction_op + * Binary reduction functor + * + * @param[in] init + * The initial value of the reduction + */ +template +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::ReducePolicy::BLOCK_THREADS)) +__global__ void DeviceSegmentedReduceKernel( + InputIteratorT d_in, + OutputIteratorT d_out, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + int /*num_segments*/, + ReductionOpT reduction_op, + InitT init) +{ + // Thread block type for reducing input tiles + using AgentReduceT = + AgentReduce; + + // Shared memory storage + __shared__ typename AgentReduceT::TempStorage temp_storage; + + OffsetT segment_begin = d_begin_offsets[blockIdx.x]; + OffsetT segment_end = d_end_offsets[blockIdx.x]; + + // Check if empty problem + if (segment_begin == segment_end) + { + if (threadIdx.x == 0) + { + *(d_out + blockIdx.x) = init; + } + return; + } + + // Consume input tiles + AccumT block_aggregate = AgentReduceT(temp_storage, d_in, reduction_op) + .ConsumeRange(segment_begin, segment_end); + + // Normalize as needed + NormalizeReductionOutput(block_aggregate, segment_begin, d_in); + + if (threadIdx.x == 0) + { + detail::reduce::finalize_and_store_aggregate(d_out + blockIdx.x, + reduction_op, + init, + block_aggregate); + } +} + +/****************************************************************************** + * Policy + ******************************************************************************/ + +/** + * @tparam AccumT + * Accumulator data type + * + * OffsetT + * Signed integer type for global offsets + * + * ReductionOpT + * Binary reduction functor type having member + * `auto operator()(const T &a, const U &b)` + */ +template < + typename AccumT, + typename OffsetT, + typename ReductionOpT> +struct DeviceReducePolicy +{ + //--------------------------------------------------------------------------- + // Architecture-specific tuning policies + //--------------------------------------------------------------------------- + + /// SM30 + struct Policy300 : ChainedPolicy<300, Policy300, Policy300> + { + static constexpr int threads_per_block = 256; + static constexpr int items_per_thread = 20; + static constexpr int items_per_vec_load = 2; + + // ReducePolicy (GTX670: 154.0 @ 48M 4B items) + using ReducePolicy = AgentReducePolicy; + + // SingleTilePolicy + using SingleTilePolicy = ReducePolicy; + + // SegmentedReducePolicy + using SegmentedReducePolicy = ReducePolicy; + }; + + /// SM35 + struct Policy350 : ChainedPolicy<350, Policy350, Policy300> + { + static constexpr int threads_per_block = 256; + static constexpr int items_per_thread = 20; + static constexpr int items_per_vec_load = 4; + + // ReducePolicy (GTX Titan: 255.1 GB/s @ 48M 4B items; 228.7 GB/s @ 192M 1B + // items) + using ReducePolicy = AgentReducePolicy; + + // SingleTilePolicy + using SingleTilePolicy = ReducePolicy; + + // SegmentedReducePolicy + using SegmentedReducePolicy = ReducePolicy; + }; + + /// SM60 + struct Policy600 : ChainedPolicy<600, Policy600, Policy350> + { + static constexpr int threads_per_block = 256; + static constexpr int items_per_thread = 16; + static constexpr int items_per_vec_load = 4; + + // ReducePolicy (P100: 591 GB/s @ 64M 4B items; 583 GB/s @ 256M 1B items) + using ReducePolicy = AgentReducePolicy; + + // SingleTilePolicy + using SingleTilePolicy = ReducePolicy; + + // SegmentedReducePolicy + using SegmentedReducePolicy = ReducePolicy; + }; + + using MaxPolicy = Policy600; +}; + + + +/****************************************************************************** + * Single-problem dispatch + *****************************************************************************/ + +/** + * @brief Utility class for dispatching the appropriately-tuned kernels for + * device-wide reduction + * + * @tparam InputIteratorT + * Random-access input iterator type for reading input items \iterator + * + * @tparam OutputIteratorT + * Output iterator type for recording the reduced aggregate \iterator + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam ReductionOpT + * Binary reduction functor type having member + * `auto operator()(const T &a, const U &b)` + * + * @tparam InitT + * Initial value type + */ +template < + typename InputIteratorT, + typename OutputIteratorT, + typename OffsetT, + typename ReductionOpT, + typename InitT = + cub::detail::non_void_value_t< + OutputIteratorT, + cub::detail::value_t>, + typename AccumT = + detail::accumulator_t< + ReductionOpT, + InitT, + cub::detail::value_t>, + typename SelectedPolicy = DeviceReducePolicy> +struct DispatchReduce : SelectedPolicy +{ + //--------------------------------------------------------------------------- + // Problem state + //--------------------------------------------------------------------------- + + /// Device-accessible allocation of temporary storage. When `nullptr`, the + /// required allocation size is written to `temp_storage_bytes` and no work + /// is done. + void *d_temp_storage; + + /// Reference to size in bytes of `d_temp_storage` allocation + size_t &temp_storage_bytes; + + /// Pointer to the input sequence of data items + InputIteratorT d_in; + + /// Pointer to the output aggregate + OutputIteratorT d_out; + + /// Total number of input items (i.e., length of `d_in`) + OffsetT num_items; + + /// Binary reduction functor + ReductionOpT reduction_op; + + /// The initial value of the reduction + InitT init; + + /// CUDA stream to launch kernels within. Default is stream0. + cudaStream_t stream; + + int ptx_version; + + //--------------------------------------------------------------------------- + // Constructor + //--------------------------------------------------------------------------- + + /// Constructor + CUB_RUNTIME_FUNCTION __forceinline__ DispatchReduce(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + OffsetT num_items, + ReductionOpT reduction_op, + InitT init, + cudaStream_t stream, + int ptx_version) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_in(d_in) + , d_out(d_out) + , num_items(num_items) + , reduction_op(reduction_op) + , init(init) + , stream(stream) + , ptx_version(ptx_version) + {} + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchReduce(void* d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + OffsetT num_items, + ReductionOpT reduction_op, + InitT init, + cudaStream_t stream, + bool debug_synchronous, + int ptx_version) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_in(d_in) + , d_out(d_out) + , num_items(num_items) + , reduction_op(reduction_op) + , init(init) + , stream(stream) + , ptx_version(ptx_version) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + } + + //--------------------------------------------------------------------------- + // Small-problem (single tile) invocation + //--------------------------------------------------------------------------- + + /** + * @brief Invoke a single block block to reduce in-core + * + * @tparam ActivePolicyT + * Umbrella policy active for the target device + * + * @tparam SingleTileKernelT + * Function type of cub::DeviceReduceSingleTileKernel + * + * @param[in] single_tile_kernel + * Kernel function pointer to parameterization of + * cub::DeviceReduceSingleTileKernel + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t + InvokeSingleTile(SingleTileKernelT single_tile_kernel) + { + cudaError error = cudaSuccess; + do + { + // Return if the caller is simply requesting the size of the storage + // allocation + if (d_temp_storage == NULL) + { + temp_storage_bytes = 1; + break; + } + + // Log single_reduce_sweep_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking DeviceReduceSingleTileKernel<<<1, %d, 0, %lld>>>(), " + "%d items per thread\n", + ActivePolicyT::SingleTilePolicy::BLOCK_THREADS, + (long long)stream, + ActivePolicyT::SingleTilePolicy::ITEMS_PER_THREAD); + #endif + + // Invoke single_reduce_sweep_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + 1, ActivePolicyT::SingleTilePolicy::BLOCK_THREADS, 0, stream) + .doit(single_tile_kernel, d_in, d_out, num_items, reduction_op, init); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } while (0); + + return error; + } + + //--------------------------------------------------------------------------- + // Normal problem size invocation (two-pass) + //--------------------------------------------------------------------------- + + /** + * @brief Invoke two-passes to reduce + * @tparam ActivePolicyT + * Umbrella policy active for the target device + * + * @tparam ReduceKernelT + * Function type of cub::DeviceReduceKernel + * + * @tparam SingleTileKernelT + * Function type of cub::DeviceReduceSingleTileKernel + * + * @param[in] reduce_kernel + * Kernel function pointer to parameterization of cub::DeviceReduceKernel + * + * @param[in] single_tile_kernel + * Kernel function pointer to parameterization of + * cub::DeviceReduceSingleTileKernel + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t + InvokePasses(ReduceKernelT reduce_kernel, + SingleTileKernelT single_tile_kernel) + { + cudaError error = cudaSuccess; + do + { + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) + break; + + // Get SM count + int sm_count; + if (CubDebug( + error = cudaDeviceGetAttribute(&sm_count, + cudaDevAttrMultiProcessorCount, + device_ordinal))) + { + break; + } + + // Init regular kernel configuration + KernelConfig reduce_config; + if (CubDebug( + error = reduce_config.Init( + reduce_kernel))) + { + break; + } + + int reduce_device_occupancy = reduce_config.sm_occupancy * sm_count; + + // Even-share work distribution + int max_blocks = reduce_device_occupancy * CUB_SUBSCRIPTION_FACTOR(0); + GridEvenShare even_share; + even_share.DispatchInit(num_items, max_blocks, reduce_config.tile_size); + + // Temporary storage allocation requirements + void *allocations[1] = {}; + size_t allocation_sizes[1] = { + max_blocks * sizeof(AccumT) // bytes needed for privatized block + // reductions + }; + + // Alias the temporary allocations from the single storage blob (or + // compute the necessary size of the blob) + if (CubDebug(error = AliasTemporaries(d_temp_storage, + temp_storage_bytes, + allocations, + allocation_sizes))) + { + break; + } + + if (d_temp_storage == NULL) + { + // Return if the caller is simply requesting the size of the storage + // allocation + return cudaSuccess; + } + + // Alias the allocation for the privatized per-block reductions + AccumT *d_block_reductions = (AccumT *)allocations[0]; + + // Get grid size for device_reduce_sweep_kernel + int reduce_grid_size = even_share.grid_size; + + // Log device_reduce_sweep_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking DeviceReduceKernel<<<%d, %d, 0, %lld>>>(), %d items " + "per thread, %d SM occupancy\n", + reduce_grid_size, + ActivePolicyT::ReducePolicy::BLOCK_THREADS, + (long long)stream, + ActivePolicyT::ReducePolicy::ITEMS_PER_THREAD, + reduce_config.sm_occupancy); + #endif + + // Invoke DeviceReduceKernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + reduce_grid_size, + ActivePolicyT::ReducePolicy::BLOCK_THREADS, + 0, + stream) + .doit(reduce_kernel, + d_in, + d_block_reductions, + num_items, + even_share, + reduction_op); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Log single_reduce_sweep_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking DeviceReduceSingleTileKernel<<<1, %d, 0, %lld>>>(), " + "%d items per thread\n", + ActivePolicyT::SingleTilePolicy::BLOCK_THREADS, + (long long)stream, + ActivePolicyT::SingleTilePolicy::ITEMS_PER_THREAD); + #endif + + // Invoke DeviceReduceSingleTileKernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + 1, + ActivePolicyT::SingleTilePolicy::BLOCK_THREADS, + 0, + stream) + .doit(single_tile_kernel, + d_block_reductions, + d_out, + reduce_grid_size, // triple_chevron is not type safe, make sure to use int + reduction_op, + init); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } while (0); + + return error; + } + + //--------------------------------------------------------------------------- + // Chained policy invocation + //--------------------------------------------------------------------------- + + /// Invocation + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke() + { + typedef typename ActivePolicyT::SingleTilePolicy SingleTilePolicyT; + typedef typename DispatchReduce::MaxPolicy MaxPolicyT; + + // Force kernel code-generation in all compiler passes + if (num_items <= (SingleTilePolicyT::BLOCK_THREADS * + SingleTilePolicyT::ITEMS_PER_THREAD)) + { + // Small, single tile size + return InvokeSingleTile( + DeviceReduceSingleTileKernel); + } + else + { + // Regular size + return InvokePasses( + DeviceReduceKernel, + DeviceReduceSingleTileKernel); + } + } + + //--------------------------------------------------------------------------- + // Dispatch entrypoints + //--------------------------------------------------------------------------- + + /** + * @brief Internal dispatch routine for computing a device-wide reduction + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param[in] reduction_op + * Binary reduction functor + * + * @param[in] init + * The initial value of the reduction + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + OffsetT num_items, + ReductionOpT reduction_op, + InitT init, + cudaStream_t stream) + { + typedef typename DispatchReduce::MaxPolicy MaxPolicyT; + + cudaError error = cudaSuccess; + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + // Create dispatch functor + DispatchReduce dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_items, + reduction_op, + init, + stream, + ptx_version); + + // Dispatch to chained policy + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + OffsetT num_items, + ReductionOpT reduction_op, + InitT init, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_items, + reduction_op, + init, + stream); + } +}; + + + +/****************************************************************************** + * Segmented dispatch + *****************************************************************************/ + +/** + * @brief Utility class for dispatching the appropriately-tuned kernels for + * device-wide reduction + * + * @tparam InputIteratorT + * Random-access input iterator type for reading input items \iterator + * + * @tparam OutputIteratorT + * Output iterator type for recording the reduced aggregate \iterator + * + * @tparam BeginOffsetIteratorT + * Random-access input iterator type for reading segment beginning offsets + * \iterator + * + * @tparam EndOffsetIteratorT + * Random-access input iterator type for reading segment ending offsets + * \iterator + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam ReductionOpT + * Binary reduction functor type having member + * `auto operator()(const T &a, const U &b)` + * + * @tparam InitT + * value type + */ +template < + typename InputIteratorT, + typename OutputIteratorT, + typename BeginOffsetIteratorT, + typename EndOffsetIteratorT, + typename OffsetT, + typename ReductionOpT, + typename InitT = + cub::detail::non_void_value_t< + OutputIteratorT, + cub::detail::value_t>, + typename AccumT = + detail::accumulator_t< + ReductionOpT, + InitT, + cub::detail::value_t>, + typename SelectedPolicy = DeviceReducePolicy> +struct DispatchSegmentedReduce : SelectedPolicy +{ + //--------------------------------------------------------------------------- + // Problem state + //--------------------------------------------------------------------------- + + /// Device-accessible allocation of temporary storage. When `nullptr`, the + /// required allocation size is written to `temp_storage_bytes` and no work + /// is done. + void *d_temp_storage; + + /// Reference to size in bytes of `d_temp_storage` allocation + size_t &temp_storage_bytes; + + /// Pointer to the input sequence of data items + InputIteratorT d_in; + + /// Pointer to the output aggregate + OutputIteratorT d_out; + + /// The number of segments that comprise the sorting data + OffsetT num_segments; + + /// Random-access input iterator to the sequence of beginning offsets of + /// length `num_segments`, such that `d_begin_offsets[i]` is the first + /// element of the *i*th data segment in `d_keys_*` and + /// `d_values_*` + BeginOffsetIteratorT d_begin_offsets; + + /// Random-access input iterator to the sequence of ending offsets of length + /// `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + /// the *i*th data segment in `d_keys_*` and `d_values_*`. + /// If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + /// considered empty. + EndOffsetIteratorT d_end_offsets; + + /// Binary reduction functor + ReductionOpT reduction_op; + + /// The initial value of the reduction + InitT init; + + /// CUDA stream to launch kernels within. Default is stream0. + cudaStream_t stream; + + int ptx_version; + + //--------------------------------------------------------------------------- + // Constructor + //--------------------------------------------------------------------------- + + /// Constructor + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchSegmentedReduce(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + OffsetT num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + ReductionOpT reduction_op, + InitT init, + cudaStream_t stream, + int ptx_version) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_in(d_in) + , d_out(d_out) + , num_segments(num_segments) + , d_begin_offsets(d_begin_offsets) + , d_end_offsets(d_end_offsets) + , reduction_op(reduction_op) + , init(init) + , stream(stream) + , ptx_version(ptx_version) + {} + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchSegmentedReduce(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + OffsetT num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + ReductionOpT reduction_op, + InitT init, + cudaStream_t stream, + bool debug_synchronous, + int ptx_version) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_in(d_in) + , d_out(d_out) + , num_segments(num_segments) + , d_begin_offsets(d_begin_offsets) + , d_end_offsets(d_end_offsets) + , reduction_op(reduction_op) + , init(init) + , stream(stream) + , ptx_version(ptx_version) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + } + + //--------------------------------------------------------------------------- + // Chained policy invocation + //--------------------------------------------------------------------------- + + /** + * @brief Invocation + * + * @tparam ActivePolicyT + * Umbrella policy active for the target device + * + * @tparam DeviceSegmentedReduceKernelT + * Function type of cub::DeviceSegmentedReduceKernel + * + * @param[in] segmented_reduce_kernel + * Kernel function pointer to parameterization of + * cub::DeviceSegmentedReduceKernel + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t + InvokePasses(DeviceSegmentedReduceKernelT segmented_reduce_kernel) + { + cudaError error = cudaSuccess; + + do + { + // Return if the caller is simply requesting the size of the storage + // allocation + if (d_temp_storage == NULL) + { + temp_storage_bytes = 1; + return cudaSuccess; + } + + // Init kernel configuration + KernelConfig segmented_reduce_config; + if (CubDebug( + error = segmented_reduce_config + .Init( + segmented_reduce_kernel))) + { + break; + } + + // Log device_reduce_sweep_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking SegmentedDeviceReduceKernel<<<%d, %d, 0, %lld>>>(), " + "%d items per thread, %d SM occupancy\n", + num_segments, + ActivePolicyT::SegmentedReducePolicy::BLOCK_THREADS, + (long long)stream, + ActivePolicyT::SegmentedReducePolicy::ITEMS_PER_THREAD, + segmented_reduce_config.sm_occupancy); + #endif + + // Invoke DeviceReduceKernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + num_segments, + ActivePolicyT::SegmentedReducePolicy::BLOCK_THREADS, + 0, + stream) + .doit(segmented_reduce_kernel, + d_in, + d_out, + d_begin_offsets, + d_end_offsets, + num_segments, + reduction_op, + init); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } while (0); + + return error; + } + + /// Invocation + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke() + { + typedef typename DispatchSegmentedReduce::MaxPolicy MaxPolicyT; + + // Force kernel code-generation in all compiler passes + return InvokePasses( + DeviceSegmentedReduceKernel); + } + + //--------------------------------------------------------------------------- + // Dispatch entrypoints + //--------------------------------------------------------------------------- + + /** + * @brief Internal dispatch routine for computing a device-wide reduction + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no work + * is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[out] d_out + * Pointer to the output aggregate + * + * @param[in] num_segments + * The number of segments that comprise the sorting data + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of + * length `num_segments`, such that `d_begin_offsets[i]` is the first + * element of the *i*th data segment in `d_keys_*` and + * `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * `num_segments`, such that `d_end_offsets[i] - 1` is the last element of + * the *i*th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i] - 1 <= d_begin_offsets[i]`, the *i*th is + * considered empty. + * + * @param[in] reduction_op + * Binary reduction functor + * + * @param[in] init + * The initial value of the reduction + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + ReductionOpT reduction_op, + InitT init, + cudaStream_t stream) + { + typedef typename DispatchSegmentedReduce::MaxPolicy MaxPolicyT; + + if (num_segments <= 0) + { + return cudaSuccess; + } + + cudaError error = cudaSuccess; + + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + // Create dispatch functor + DispatchSegmentedReduce dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + reduction_op, + init, + stream, + ptx_version); + + // Dispatch to chained policy + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + ReductionOpT reduction_op, + InitT init, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_segments, + d_begin_offsets, + d_end_offsets, + reduction_op, + init, + stream); + } +}; + + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_reduce_by_key.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_reduce_by_key.cuh new file mode 100644 index 0000000000000000000000000000000000000000..d56f4cb4d02160e60da0b18f63fb1648506f7d4e --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_reduce_by_key.cuh @@ -0,0 +1,578 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::DeviceReduceByKey provides device-wide, parallel operations for + * reducing segments of values residing within device-accessible memory. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Kernel entry points + *****************************************************************************/ + +/** + * @brief Multi-block reduce-by-key sweep kernel entry point + * + * @tparam AgentReduceByKeyPolicyT + * Parameterized AgentReduceByKeyPolicyT tuning policy type + * + * @tparam KeysInputIteratorT + * Random-access input iterator type for keys + * + * @tparam UniqueOutputIteratorT + * Random-access output iterator type for keys + * + * @tparam ValuesInputIteratorT + * Random-access input iterator type for values + * + * @tparam AggregatesOutputIteratorT + * Random-access output iterator type for values + * + * @tparam NumRunsOutputIteratorT + * Output iterator type for recording number of segments encountered + * + * @tparam ScanTileStateT + * Tile status interface type + * + * @tparam EqualityOpT + * KeyT equality operator type + * + * @tparam ReductionOpT + * ValueT reduction operator type + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @param d_keys_in + * Pointer to the input sequence of keys + * + * @param d_unique_out + * Pointer to the output sequence of unique keys (one key per run) + * + * @param d_values_in + * Pointer to the input sequence of corresponding values + * + * @param d_aggregates_out + * Pointer to the output sequence of value aggregates (one aggregate per run) + * + * @param d_num_runs_out + * Pointer to total number of runs encountered + * (i.e., the length of d_unique_out) + * + * @param tile_state + * Tile status interface + * + * @param start_tile + * The starting tile for the current grid + * + * @param equality_op + * KeyT equality operator + * + * @param reduction_op + * ValueT reduction operator + * + * @param num_items + * Total number of items to select from + */ +template +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::ReduceByKeyPolicyT::BLOCK_THREADS)) __global__ + void DeviceReduceByKeyKernel(KeysInputIteratorT d_keys_in, + UniqueOutputIteratorT d_unique_out, + ValuesInputIteratorT d_values_in, + AggregatesOutputIteratorT d_aggregates_out, + NumRunsOutputIteratorT d_num_runs_out, + ScanTileStateT tile_state, + int start_tile, + EqualityOpT equality_op, + ReductionOpT reduction_op, + OffsetT num_items) +{ + using AgentReduceByKeyPolicyT = typename ChainedPolicyT::ActivePolicy::ReduceByKeyPolicyT; + + // Thread block type for reducing tiles of value segments + using AgentReduceByKeyT = AgentReduceByKey; + + // Shared memory for AgentReduceByKey + __shared__ typename AgentReduceByKeyT::TempStorage temp_storage; + + // Process tiles + AgentReduceByKeyT(temp_storage, + d_keys_in, + d_unique_out, + d_values_in, + d_aggregates_out, + d_num_runs_out, + equality_op, + reduction_op) + .ConsumeRange(num_items, tile_state, start_tile); +} + +/****************************************************************************** + * Dispatch + ******************************************************************************/ + +/** + * @brief Utility class for dispatching the appropriately-tuned kernels for + * DeviceReduceByKey + * + * @tparam KeysInputIteratorT + * Random-access input iterator type for keys + * + * @tparam UniqueOutputIteratorT + * Random-access output iterator type for keys + * + * @tparam ValuesInputIteratorT + * Random-access input iterator type for values + * + * @tparam AggregatesOutputIteratorT + * Random-access output iterator type for values + * + * @tparam NumRunsOutputIteratorT + * Output iterator type for recording number of segments encountered + * + * @tparam EqualityOpT + * KeyT equality operator type + * + * @tparam ReductionOpT + * ValueT reduction operator type + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam SelectedPolicy + * Implementation detail, do not specify directly, requirements on the + * content of this type are subject to breaking change. + */ +template , + cub::detail::value_t>, + typename SelectedPolicy = // + detail::device_reduce_by_key_policy_hub< // + ReductionOpT, // + AccumT, // + cub::detail::non_void_value_t< // + UniqueOutputIteratorT, // + cub::detail::value_t>>> +struct DispatchReduceByKey +{ + //------------------------------------------------------------------------- + // Types and constants + //------------------------------------------------------------------------- + + // The input values type + using ValueInputT = cub::detail::value_t; + + static constexpr int INIT_KERNEL_THREADS = 128; + + // Tile status descriptor interface type + using ScanTileStateT = ReduceByKeyScanTileState; + + void *d_temp_storage; + size_t &temp_storage_bytes; + KeysInputIteratorT d_keys_in; + UniqueOutputIteratorT d_unique_out; + ValuesInputIteratorT d_values_in; + AggregatesOutputIteratorT d_aggregates_out; + NumRunsOutputIteratorT d_num_runs_out; + EqualityOpT equality_op; + ReductionOpT reduction_op; + OffsetT num_items; + cudaStream_t stream; + + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchReduceByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + UniqueOutputIteratorT d_unique_out, + ValuesInputIteratorT d_values_in, + AggregatesOutputIteratorT d_aggregates_out, + NumRunsOutputIteratorT d_num_runs_out, + EqualityOpT equality_op, + ReductionOpT reduction_op, + OffsetT num_items, + cudaStream_t stream) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_keys_in(d_keys_in) + , d_unique_out(d_unique_out) + , d_values_in(d_values_in) + , d_aggregates_out(d_aggregates_out) + , d_num_runs_out(d_num_runs_out) + , equality_op(equality_op) + , reduction_op(reduction_op) + , num_items(num_items) + , stream(stream) + {} + + //--------------------------------------------------------------------- + // Dispatch entrypoints + //--------------------------------------------------------------------- + + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke(ScanInitKernelT init_kernel, + ReduceByKeyKernelT reduce_by_key_kernel) + { + using AgentReduceByKeyPolicyT = typename ActivePolicyT::ReduceByKeyPolicyT; + const int block_threads = AgentReduceByKeyPolicyT::BLOCK_THREADS; + const int items_per_thread = AgentReduceByKeyPolicyT::ITEMS_PER_THREAD; + + cudaError error = cudaSuccess; + do + { + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) + { + break; + } + + // Number of input tiles + int tile_size = block_threads * items_per_thread; + int num_tiles = static_cast(cub::DivideAndRoundUp(num_items, tile_size)); + + // Specify temporary storage allocation requirements + size_t allocation_sizes[1]; + if (CubDebug(error = ScanTileStateT::AllocationSize(num_tiles, allocation_sizes[0]))) + { + break; // bytes needed for tile status descriptors + } + + // Compute allocation pointers into the single storage blob (or compute + // the necessary size of the blob) + void *allocations[1] = {}; + if (CubDebug( + error = + AliasTemporaries(d_temp_storage, temp_storage_bytes, allocations, allocation_sizes))) + { + break; + } + + if (d_temp_storage == nullptr) + { + // Return if the caller is simply requesting the size of the storage + // allocation + break; + } + + // Construct the tile status interface + ScanTileStateT tile_state; + if (CubDebug(error = tile_state.Init(num_tiles, allocations[0], allocation_sizes[0]))) + { + break; + } + + // Log init_kernel configuration + int init_grid_size = CUB_MAX(1, cub::DivideAndRoundUp(num_tiles, INIT_KERNEL_THREADS)); + +#ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking init_kernel<<<%d, %d, 0, %lld>>>()\n", + init_grid_size, + INIT_KERNEL_THREADS, + (long long)stream); +#endif + + // Invoke init_kernel to initialize tile descriptors + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(init_grid_size, + INIT_KERNEL_THREADS, + 0, + stream) + .doit(init_kernel, tile_state, num_tiles, d_num_runs_out); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Return if empty problem + if (num_items == 0) + { + break; + } + + // Get SM occupancy for reduce_by_key_kernel + int reduce_by_key_sm_occupancy; + if (CubDebug(error = MaxSmOccupancy(reduce_by_key_sm_occupancy, + reduce_by_key_kernel, + block_threads))) + { + break; + } + + // Get max x-dimension of grid + int max_dim_x; + if (CubDebug( + error = cudaDeviceGetAttribute(&max_dim_x, cudaDevAttrMaxGridDimX, device_ordinal))) + { + break; + } + + // Run grids in epochs (in case number of tiles exceeds max x-dimension + int scan_grid_size = CUB_MIN(num_tiles, max_dim_x); + for (int start_tile = 0; start_tile < num_tiles; start_tile += scan_grid_size) + { +// Log reduce_by_key_kernel configuration +#ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking %d reduce_by_key_kernel<<<%d, %d, 0, %lld>>>(), %d " + "items per thread, %d SM occupancy\n", + start_tile, + scan_grid_size, + block_threads, + (long long)stream, + items_per_thread, + reduce_by_key_sm_occupancy); +#endif + + // Invoke reduce_by_key_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(scan_grid_size, + block_threads, + 0, + stream) + .doit(reduce_by_key_kernel, + d_keys_in, + d_unique_out, + d_values_in, + d_aggregates_out, + d_num_runs_out, + tile_state, + start_tile, + equality_op, + reduction_op, + num_items); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } + } while (0); + + return error; + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke() + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + return Invoke(DeviceCompactInitKernel, + DeviceReduceByKeyKernel); + } + + /** + * Internal dispatch routine + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Pointer to the input sequence of keys + * + * @param[out] d_unique_out + * Pointer to the output sequence of unique keys (one key per run) + * + * @param[in] d_values_in + * Pointer to the input sequence of corresponding values + * + * @param[out] d_aggregates_out + * Pointer to the output sequence of value aggregates + * (one aggregate per run) + * + * @param[out] d_num_runs_out + * Pointer to total number of runs encountered + * (i.e., the length of d_unique_out) + * + * @param[in] equality_op + * KeyT equality operator + * + * @param[in] reduction_op + * ValueT reduction operator + * + * @param[in] num_items + * Total number of items to select from + * + * @param[in] stream + * CUDA stream to launch kernels within. Default is stream0. + */ + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + UniqueOutputIteratorT d_unique_out, + ValuesInputIteratorT d_values_in, + AggregatesOutputIteratorT d_aggregates_out, + NumRunsOutputIteratorT d_num_runs_out, + EqualityOpT equality_op, + ReductionOpT reduction_op, + OffsetT num_items, + cudaStream_t stream) + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + + cudaError error = cudaSuccess; + + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + DispatchReduceByKey dispatch(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_unique_out, + d_values_in, + d_aggregates_out, + d_num_runs_out, + equality_op, + reduction_op, + num_items, + stream); + + // Dispatch + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + UniqueOutputIteratorT d_unique_out, + ValuesInputIteratorT d_values_in, + AggregatesOutputIteratorT d_aggregates_out, + NumRunsOutputIteratorT d_num_runs_out, + EqualityOpT equality_op, + ReductionOpT reduction_op, + OffsetT num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_unique_out, + d_values_in, + d_aggregates_out, + d_num_runs_out, + equality_op, + reduction_op, + num_items, + stream); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_rle.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_rle.cuh new file mode 100644 index 0000000000000000000000000000000000000000..6b978fa95fc8739439246fc541452ae742ff6ddb --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_rle.cuh @@ -0,0 +1,560 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file + * cub::DeviceRle provides device-wide, parallel operations for run-length-encoding sequences of + * data items residing within device-accessible memory. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Kernel entry points + *****************************************************************************/ + +/** + * Select kernel entry point (multi-block) + * + * Performs functor-based selection if SelectOp functor type != NullType + * Otherwise performs flag-based selection if FlagIterator's value type != NullType + * Otherwise performs discontinuity selection (keep unique) + * + * @tparam AgentRlePolicyT + * Parameterized AgentRlePolicyT tuning policy type + * + * @tparam InputIteratorT + * Random-access input iterator type for reading input items \iterator + * + * @tparam OffsetsOutputIteratorT + * Random-access output iterator type for writing run-offset values \iterator + * + * @tparam LengthsOutputIteratorT + * Random-access output iterator type for writing run-length values \iterator + * + * @tparam NumRunsOutputIteratorT + * Output iterator type for recording the number of runs encountered \iterator + * + * @tparam ScanTileStateT + * Tile status interface type + * + * @tparam EqualityOpT + * T equality operator type + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @param d_in + * Pointer to input sequence of data items + * + * @param d_offsets_out + * Pointer to output sequence of run-offsets + * + * @param d_lengths_out + * Pointer to output sequence of run-lengths + * + * @param d_num_runs_out + * Pointer to total number of runs (i.e., length of `d_offsets_out`) + * + * @param tile_status + * Tile status interface + * + * @param equality_op + * Equality operator for input items + * + * @param num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param num_tiles + * Total number of tiles for the entire problem + */ +template +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::RleSweepPolicyT::BLOCK_THREADS)) __global__ + void DeviceRleSweepKernel(InputIteratorT d_in, + OffsetsOutputIteratorT d_offsets_out, + LengthsOutputIteratorT d_lengths_out, + NumRunsOutputIteratorT d_num_runs_out, + ScanTileStateT tile_status, + EqualityOpT equality_op, + OffsetT num_items, + int num_tiles) +{ + using AgentRlePolicyT = typename ChainedPolicyT::ActivePolicy::RleSweepPolicyT; + + // Thread block type for selecting data from input tiles + using AgentRleT = AgentRle; + + // Shared memory for AgentRle + __shared__ typename AgentRleT::TempStorage temp_storage; + + // Process tiles + AgentRleT(temp_storage, d_in, d_offsets_out, d_lengths_out, equality_op, num_items) + .ConsumeRange(num_tiles, tile_status, d_num_runs_out); +} + +/****************************************************************************** + * Dispatch + ******************************************************************************/ + +/** + * Utility class for dispatching the appropriately-tuned kernels for DeviceRle + * + * @tparam InputIteratorT + * Random-access input iterator type for reading input items \iterator + * + * @tparam OffsetsOutputIteratorT + * Random-access output iterator type for writing run-offset values \iterator + * + * @tparam LengthsOutputIteratorT + * Random-access output iterator type for writing run-length values \iterator + * + * @tparam NumRunsOutputIteratorT + * Output iterator type for recording the number of runs encountered \iterator + * + * @tparam EqualityOpT + * T equality operator type + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam SelectedPolicy + * Implementation detail, do not specify directly, requirements on the + * content of this type are subject to breaking change. + */ +template , + cub::detail::value_t>> +struct DeviceRleDispatch +{ + /****************************************************************************** + * Types and constants + ******************************************************************************/ + + // The lengths output value type + using LengthT = cub::detail::non_void_value_t; + + enum + { + INIT_KERNEL_THREADS = 128, + }; + + // Tile status descriptor interface type + using ScanTileStateT = ReduceByKeyScanTileState; + + void *d_temp_storage; + size_t &temp_storage_bytes; + InputIteratorT d_in; + OffsetsOutputIteratorT d_offsets_out; + LengthsOutputIteratorT d_lengths_out; + NumRunsOutputIteratorT d_num_runs_out; + EqualityOpT equality_op; + OffsetT num_items; + cudaStream_t stream; + + CUB_RUNTIME_FUNCTION __forceinline__ DeviceRleDispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OffsetsOutputIteratorT d_offsets_out, + LengthsOutputIteratorT d_lengths_out, + NumRunsOutputIteratorT d_num_runs_out, + EqualityOpT equality_op, + OffsetT num_items, + cudaStream_t stream) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_in(d_in) + , d_offsets_out(d_offsets_out) + , d_lengths_out(d_lengths_out) + , d_num_runs_out(d_num_runs_out) + , equality_op(equality_op) + , num_items(num_items) + , stream(stream) + {} + + /****************************************************************************** + * Dispatch entrypoints + ******************************************************************************/ + + /** + * Internal dispatch routine for computing a device-wide run-length-encode using the + * specified kernel functions. + * + * @tparam DeviceScanInitKernelPtr + * Function type of cub::DeviceScanInitKernel + * + * @tparam DeviceRleSweepKernelPtr + * Function type of cub::DeviceRleSweepKernelPtr + * + * @param d_temp_storage + * Device-accessible allocation of temporary storage. + * When NULL, the required allocation size is written to + * `temp_storage_bytes` and no work is done. + * + * @param temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param d_in + * Pointer to the input sequence of data items + * + * @param d_offsets_out + * Pointer to the output sequence of run-offsets + * + * @param d_lengths_out + * Pointer to the output sequence of run-lengths + * + * @param d_num_runs_out + * Pointer to the total number of runs encountered (i.e., length of `d_offsets_out`) + * + * @param equality_op + * Equality operator for input items + * + * @param num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param stream + * CUDA stream to launch kernels within. Default is stream0. + * + * @param ptx_version + * PTX version of dispatch kernels + * + * @param device_scan_init_kernel + * Kernel function pointer to parameterization of cub::DeviceScanInitKernel + * + * @param device_rle_sweep_kernel + * Kernel function pointer to parameterization of cub::DeviceRleSweepKernel + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t + Invoke(DeviceScanInitKernelPtr device_scan_init_kernel, + DeviceRleSweepKernelPtr device_rle_sweep_kernel) + { + cudaError error = cudaSuccess; + + const int block_threads = ActivePolicyT::RleSweepPolicyT::BLOCK_THREADS; + const int items_per_thread = ActivePolicyT::RleSweepPolicyT::ITEMS_PER_THREAD; + + do + { + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) + break; + + // Number of input tiles + int tile_size = block_threads * items_per_thread; + int num_tiles = static_cast(cub::DivideAndRoundUp(num_items, tile_size)); + + // Specify temporary storage allocation requirements + size_t allocation_sizes[1]; + if (CubDebug(error = ScanTileStateT::AllocationSize(num_tiles, allocation_sizes[0]))) + { + break; // bytes needed for tile status descriptors + } + + // Compute allocation pointers into the single storage blob (or compute the necessary size of + // the blob) + void *allocations[1] = {}; + if (CubDebug( + error = + AliasTemporaries(d_temp_storage, temp_storage_bytes, allocations, allocation_sizes))) + { + break; + } + + if (d_temp_storage == nullptr) + { + // Return if the caller is simply requesting the size of the storage allocation + break; + } + + // Construct the tile status interface + ScanTileStateT tile_status; + if (CubDebug(error = tile_status.Init(num_tiles, allocations[0], allocation_sizes[0]))) + { + break; + } + + // Log device_scan_init_kernel configuration + int init_grid_size = CUB_MAX(1, cub::DivideAndRoundUp(num_tiles, INIT_KERNEL_THREADS)); + +#ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking device_scan_init_kernel<<<%d, %d, 0, %lld>>>()\n", + init_grid_size, + INIT_KERNEL_THREADS, + (long long)stream); +#endif + + // Invoke device_scan_init_kernel to initialize tile descriptors and queue descriptors + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(init_grid_size, + INIT_KERNEL_THREADS, + 0, + stream) + .doit(device_scan_init_kernel, tile_status, num_tiles, d_num_runs_out); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Return if empty problem + if (num_items == 0) + { + break; + } + + // Get SM occupancy for device_rle_sweep_kernel + int device_rle_kernel_sm_occupancy; + if (CubDebug(error = MaxSmOccupancy(device_rle_kernel_sm_occupancy, // out + device_rle_sweep_kernel, + block_threads))) + { + break; + } + + // Get max x-dimension of grid + int max_dim_x; + if (CubDebug( + error = cudaDeviceGetAttribute(&max_dim_x, cudaDevAttrMaxGridDimX, device_ordinal))) + { + break; + } + + // Get grid size for scanning tiles + dim3 scan_grid_size; + scan_grid_size.z = 1; + scan_grid_size.y = cub::DivideAndRoundUp(num_tiles, max_dim_x); + scan_grid_size.x = CUB_MIN(num_tiles, max_dim_x); + +// Log device_rle_sweep_kernel configuration +#ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking device_rle_sweep_kernel<<<{%d,%d,%d}, %d, 0, %lld>>>(), %d items per " + "thread, %d SM occupancy\n", + scan_grid_size.x, + scan_grid_size.y, + scan_grid_size.z, + block_threads, + (long long)stream, + items_per_thread, + device_rle_kernel_sm_occupancy); +#endif + + // Invoke device_rle_sweep_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(scan_grid_size, + block_threads, + 0, + stream) + .doit(device_rle_sweep_kernel, + d_in, + d_offsets_out, + d_lengths_out, + d_num_runs_out, + tile_status, + equality_op, + num_items, + num_tiles); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } while (0); + + return error; + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke() + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + return Invoke(DeviceCompactInitKernel, + DeviceRleSweepKernel); + } + + /** + * Internal dispatch routine + * + * @param d_temp_storage + * Device-accessible allocation of temporary storage. + * When NULL, the required allocation size is written to + * `temp_storage_bytes` and no work is done. + * + * @param temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param d_in + * Pointer to input sequence of data items + * + * @param d_offsets_out + * Pointer to output sequence of run-offsets + * + * @param d_lengths_out + * Pointer to output sequence of run-lengths + * + * @param d_num_runs_out + * Pointer to total number of runs (i.e., length of `d_offsets_out`) + * + * @param equality_op + * Equality operator for input items + * + * @param num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param stream + * [optional] CUDA stream to launch kernels within. + * Default is stream0. + */ + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OffsetsOutputIteratorT d_offsets_out, + LengthsOutputIteratorT d_lengths_out, + NumRunsOutputIteratorT d_num_runs_out, + EqualityOpT equality_op, + OffsetT num_items, + cudaStream_t stream) + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + + cudaError error = cudaSuccess; + + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + DeviceRleDispatch dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_offsets_out, + d_lengths_out, + d_num_runs_out, + equality_op, + num_items, + stream); + + // Dispatch + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (0); + + return error; + } + + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OffsetsOutputIteratorT d_offsets_out, + LengthsOutputIteratorT d_lengths_out, + NumRunsOutputIteratorT d_num_runs_out, + EqualityOpT equality_op, + OffsetT num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_offsets_out, + d_lengths_out, + d_num_runs_out, + equality_op, + num_items, + stream); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_scan.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_scan.cuh new file mode 100644 index 0000000000000000000000000000000000000000..a4bf2eff5fa6a87ebb2cf185a20603f57cdacba7 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_scan.cuh @@ -0,0 +1,636 @@ + +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file cub::DeviceScan provides device-wide, parallel operations for + * computing a prefix scan across a sequence of data items residing + * within device-accessible memory. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Kernel entry points + *****************************************************************************/ + +/** + * @brief Initialization kernel for tile status initialization (multi-block) + * + * @tparam ScanTileStateT + * Tile status interface type + * + * @param[in] tile_state + * Tile status interface + * + * @param[in] num_tiles + * Number of tiles + */ +template +__global__ void DeviceScanInitKernel(ScanTileStateT tile_state, int num_tiles) +{ + // Initialize tile status + tile_state.InitializeStatus(num_tiles); +} + +/** + * Initialization kernel for tile status initialization (multi-block) + * + * @tparam ScanTileStateT + * Tile status interface type + * + * @tparam NumSelectedIteratorT + * Output iterator type for recording the number of items selected + * + * @param[in] tile_state + * Tile status interface + * + * @param[in] num_tiles + * Number of tiles + * + * @param[out] d_num_selected_out + * Pointer to the total number of items selected + * (i.e., length of `d_selected_out`) + */ +template +__global__ void DeviceCompactInitKernel(ScanTileStateT tile_state, + int num_tiles, + NumSelectedIteratorT d_num_selected_out) +{ + // Initialize tile status + tile_state.InitializeStatus(num_tiles); + + // Initialize d_num_selected_out + if ((blockIdx.x == 0) && (threadIdx.x == 0)) + { + *d_num_selected_out = 0; + } +} + +/** + * @brief Scan kernel entry point (multi-block) + * + * + * @tparam ChainedPolicyT + * Chained tuning policy + * + * @tparam InputIteratorT + * Random-access input iterator type for reading scan inputs \iterator + * + * @tparam OutputIteratorT + * Random-access output iterator type for writing scan outputs \iterator + * + * @tparam ScanTileStateT + * Tile status interface type + * + * @tparam ScanOpT + * Binary scan functor type having member + * `auto operator()(const T &a, const U &b)` + * + * @tparam InitValueT + * Initial value to seed the exclusive scan + * (cub::NullType for inclusive scans) + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @paramInput d_in + * data + * + * @paramOutput d_out + * data + * + * @paramTile tile_state + * status interface + * + * @paramThe start_tile + * starting tile for the current grid + * + * @paramBinary scan_op + * scan functor + * + * @paramInitial init_value + * value to seed the exclusive scan + * + * @paramTotal num_items + * number of scan items for the entire problem + */ +template +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::ScanPolicyT::BLOCK_THREADS)) + __global__ void DeviceScanKernel(InputIteratorT d_in, + OutputIteratorT d_out, + ScanTileStateT tile_state, + int start_tile, + ScanOpT scan_op, + InitValueT init_value, + OffsetT num_items) +{ + using RealInitValueT = typename InitValueT::value_type; + typedef typename ChainedPolicyT::ActivePolicy::ScanPolicyT ScanPolicyT; + + // Thread block type for scanning input tiles + typedef AgentScan + AgentScanT; + + // Shared memory for AgentScan + __shared__ typename AgentScanT::TempStorage temp_storage; + + RealInitValueT real_init_value = init_value; + + // Process tiles + AgentScanT(temp_storage, d_in, d_out, scan_op, real_init_value) + .ConsumeRange(num_items, tile_state, start_tile); +} + +/****************************************************************************** + * Dispatch + ******************************************************************************/ + +/** + * @brief Utility class for dispatching the appropriately-tuned kernels for + * DeviceScan + * + * @tparam InputIteratorT + * Random-access input iterator type for reading scan inputs \iterator + * + * @tparam OutputIteratorT + * Random-access output iterator type for writing scan outputs \iterator + * + * @tparam ScanOpT + * Binary scan functor type having member + * `auto operator()(const T &a, const U &b)` + * + * @tparam InitValueT + * The init_value element type for ScanOpT (cub::NullType for inclusive scans) + * + * @tparam OffsetT + * Signed integer type for global offsets + * + */ +template ::value, + cub::detail::value_t, + typename InitValueT::value_type>, + cub::detail::value_t>, + typename SelectedPolicy = DeviceScanPolicy> +struct DispatchScan : SelectedPolicy +{ + //--------------------------------------------------------------------- + // Constants and Types + //--------------------------------------------------------------------- + + static constexpr int INIT_KERNEL_THREADS = 128; + + // The input value type + using InputT = cub::detail::value_t; + + /// Device-accessible allocation of temporary storage. When NULL, the + /// required allocation size is written to \p temp_storage_bytes and no work + /// is done. + void *d_temp_storage; + + /// Reference to size in bytes of \p d_temp_storage allocation + size_t &temp_storage_bytes; + + /// Iterator to the input sequence of data items + InputIteratorT d_in; + + /// Iterator to the output sequence of data items + OutputIteratorT d_out; + + /// Binary scan functor + ScanOpT scan_op; + + /// Initial value to seed the exclusive scan + InitValueT init_value; + + /// Total number of input items (i.e., the length of \p d_in) + OffsetT num_items; + + /// CUDA stream to launch kernels within. Default is stream0. + cudaStream_t stream; + + int ptx_version; + + /** + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Iterator to the input sequence of data items + * + * @param[out] d_out + * Iterator to the output sequence of data items + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] init_value + * Initial value to seed the exclusive scan + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + */ + CUB_RUNTIME_FUNCTION __forceinline__ DispatchScan(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + OffsetT num_items, + ScanOpT scan_op, + InitValueT init_value, + cudaStream_t stream, + int ptx_version) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_in(d_in) + , d_out(d_out) + , scan_op(scan_op) + , init_value(init_value) + , num_items(num_items) + , stream(stream) + , ptx_version(ptx_version) + {} + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ DispatchScan(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + OffsetT num_items, + ScanOpT scan_op, + InitValueT init_value, + cudaStream_t stream, + bool debug_synchronous, + int ptx_version) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_in(d_in) + , d_out(d_out) + , scan_op(scan_op) + , init_value(init_value) + , num_items(num_items) + , stream(stream) + , ptx_version(ptx_version) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + } + + template + CUB_RUNTIME_FUNCTION __host__ __forceinline__ cudaError_t + Invoke(InitKernel init_kernel, ScanKernel scan_kernel) + { + typedef typename ActivePolicyT::ScanPolicyT Policy; + typedef typename cub::ScanTileState ScanTileStateT; + + // `LOAD_LDG` makes in-place execution UB and doesn't lead to better + // performance. + static_assert(Policy::LOAD_MODIFIER != CacheLoadModifier::LOAD_LDG, + "The memory consistency model does not apply to texture " + "accesses"); + + cudaError error = cudaSuccess; + do + { + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) + { + break; + } + + // Number of input tiles + int tile_size = Policy::BLOCK_THREADS * Policy::ITEMS_PER_THREAD; + int num_tiles = + static_cast(cub::DivideAndRoundUp(num_items, tile_size)); + + // Specify temporary storage allocation requirements + size_t allocation_sizes[1]; + if (CubDebug(error = ScanTileStateT::AllocationSize(num_tiles, + allocation_sizes[0]))) + { + break; // bytes needed for tile status descriptors + } + + // Compute allocation pointers into the single storage blob (or compute + // the necessary size of the blob) + void *allocations[1] = {}; + if (CubDebug(error = AliasTemporaries(d_temp_storage, + temp_storage_bytes, + allocations, + allocation_sizes))) + { + break; + } + + if (d_temp_storage == NULL) + { + // Return if the caller is simply requesting the size of the storage + // allocation + break; + } + + // Return if empty problem + if (num_items == 0) + { + break; + } + + // Construct the tile status interface + ScanTileStateT tile_state; + if (CubDebug(error = tile_state.Init(num_tiles, + allocations[0], + allocation_sizes[0]))) + { + break; + } + + // Log init_kernel configuration + int init_grid_size = cub::DivideAndRoundUp(num_tiles, + INIT_KERNEL_THREADS); + + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking init_kernel<<<%d, %d, 0, %lld>>>()\n", + init_grid_size, + INIT_KERNEL_THREADS, + (long long)stream); + #endif + + // Invoke init_kernel to initialize tile descriptors + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + init_grid_size, + INIT_KERNEL_THREADS, + 0, + stream) + .doit(init_kernel, tile_state, num_tiles); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Get SM occupancy for scan_kernel + int scan_sm_occupancy; + if (CubDebug(error = MaxSmOccupancy(scan_sm_occupancy, // out + scan_kernel, + Policy::BLOCK_THREADS))) + { + break; + } + + // Get max x-dimension of grid + int max_dim_x; + if (CubDebug(error = cudaDeviceGetAttribute(&max_dim_x, + cudaDevAttrMaxGridDimX, + device_ordinal))) + { + break; + } + + // Run grids in epochs (in case number of tiles exceeds max x-dimension + int scan_grid_size = CUB_MIN(num_tiles, max_dim_x); + for (int start_tile = 0; start_tile < num_tiles; + start_tile += scan_grid_size) + { + // Log scan_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking %d scan_kernel<<<%d, %d, 0, %lld>>>(), %d items " + "per thread, %d SM occupancy\n", + start_tile, + scan_grid_size, + Policy::BLOCK_THREADS, + (long long)stream, + Policy::ITEMS_PER_THREAD, + scan_sm_occupancy); + #endif + + // Invoke scan_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + scan_grid_size, + Policy::BLOCK_THREADS, + 0, + stream) + .doit(scan_kernel, + d_in, + d_out, + tile_state, + start_tile, + scan_op, + init_value, + num_items); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } + } while (0); + + return error; + } + + template + CUB_RUNTIME_FUNCTION __host__ __forceinline__ cudaError_t Invoke() + { + typedef typename DispatchScan::MaxPolicy MaxPolicyT; + typedef typename cub::ScanTileState ScanTileStateT; + // Ensure kernels are instantiated. + return Invoke(DeviceScanInitKernel, + DeviceScanKernel); + } + + /** + * @brief Internal dispatch routine + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_in + * Iterator to the input sequence of data items + * + * @param[out] d_out + * Iterator to the output sequence of data items + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] init_value + * Initial value to seed the exclusive scan + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] stream + * **[optional]** CUDA stream to launch kernels within. + * Default is stream0. + * + */ + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + ScanOpT scan_op, + InitValueT init_value, + OffsetT num_items, + cudaStream_t stream) + { + typedef typename DispatchScan::MaxPolicy MaxPolicyT; + + cudaError_t error; + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + // Create dispatch functor + DispatchScan dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + num_items, + scan_op, + init_value, + stream, + ptx_version); + + // Dispatch to chained policy + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + OutputIteratorT d_out, + ScanOpT scan_op, + InitValueT init_value, + OffsetT num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_out, + scan_op, + init_value, + num_items, + stream); + } +}; + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_scan_by_key.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_scan_by_key.cuh new file mode 100644 index 0000000000000000000000000000000000000000..2139721f734e361448899af1f84a439717c6d50f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_scan_by_key.cuh @@ -0,0 +1,679 @@ +/****************************************************************************** + * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file DeviceScan provides device-wide, parallel operations for computing a + * prefix scan across a sequence of data items residing within + * device-accessible memory. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Kernel entry points + *****************************************************************************/ + +/** + * @brief Scan kernel entry point (multi-block) + * + * @tparam ChainedPolicyT + * Chained tuning policy + * + * @tparam KeysInputIteratorT + * Random-access input iterator type + * + * @tparam ValuesInputIteratorT + * Random-access input iterator type + * + * @tparam ValuesOutputIteratorT + * Random-access output iterator type + * + * @tparam ScanByKeyTileStateT + * Tile status interface type + * + * @tparam EqualityOp + * Equality functor type + * + * @tparam ScanOpT + * Scan functor type + * + * @tparam InitValueT + * The init_value element for ScanOpT type (cub::NullType for inclusive scan) + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @param d_keys_in + * Input keys data + * + * @param d_keys_prev_in + * Predecessor items for each tile + * + * @param d_values_in + * Input values data + * + * @param d_values_out + * Output values data + * + * @param tile_state + * Tile status interface + * + * @param start_tile + * The starting tile for the current grid + * + * @param equality_op + * Binary equality functor + * + * @param scan_op + * Binary scan functor + * + * @param init_value + * Initial value to seed the exclusive scan + * + * @param num_items + * Total number of scan items for the entire problem + */ +template > +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::ScanByKeyPolicyT::BLOCK_THREADS)) +__global__ void DeviceScanByKeyKernel(KeysInputIteratorT d_keys_in, + KeyT *d_keys_prev_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + ScanByKeyTileStateT tile_state, + int start_tile, + EqualityOp equality_op, + ScanOpT scan_op, + InitValueT init_value, + OffsetT num_items) +{ + using ScanByKeyPolicyT = + typename ChainedPolicyT::ActivePolicy::ScanByKeyPolicyT; + + // Thread block type for scanning input tiles + using AgentScanByKeyT = AgentScanByKey; + + // Shared memory for AgentScanByKey + __shared__ typename AgentScanByKeyT::TempStorage temp_storage; + + // Process tiles + AgentScanByKeyT(temp_storage, + d_keys_in, + d_keys_prev_in, + d_values_in, + d_values_out, + equality_op, + scan_op, + init_value) + .ConsumeRange(num_items, tile_state, start_tile); +} + +template +__global__ void DeviceScanByKeyInitKernel( + ScanTileStateT tile_state, + KeysInputIteratorT d_keys_in, + cub::detail::value_t *d_keys_prev_in, + unsigned items_per_tile, + int num_tiles) +{ + // Initialize tile status + tile_state.InitializeStatus(num_tiles); + + const unsigned tid = threadIdx.x + blockDim.x * blockIdx.x; + const unsigned tile_base = tid * items_per_tile; + + if (tid > 0 && tid < num_tiles) + { + d_keys_prev_in[tid] = d_keys_in[tile_base - 1]; + } +} + +/****************************************************************************** + * Dispatch + ******************************************************************************/ + +/** + * @brief Utility class for dispatching the appropriately-tuned kernels + * for DeviceScan + * + * @tparam KeysInputIteratorT + * Random-access input iterator type + * + * @tparam ValuesInputIteratorT + * Random-access input iterator type + * + * @tparam ValuesOutputIteratorT + * Random-access output iterator type + * + * @tparam EqualityOp + * Equality functor type + * + * @tparam ScanOpT + * Scan functor type + * + * @tparam InitValueT + * The init_value element for ScanOpT type (cub::NullType for inclusive scan) + * + * @tparam OffsetT + * Signed integer type for global offsets + * + */ +template < + typename KeysInputIteratorT, + typename ValuesInputIteratorT, + typename ValuesOutputIteratorT, + typename EqualityOp, + typename ScanOpT, + typename InitValueT, + typename OffsetT, + typename AccumT = + detail::accumulator_t::value, + cub::detail::value_t, + InitValueT>, + cub::detail::value_t>, + typename SelectedPolicy = DeviceScanByKeyPolicy, + ScanOpT>> +struct DispatchScanByKey : SelectedPolicy +{ + //--------------------------------------------------------------------- + // Constants and Types + //--------------------------------------------------------------------- + + static constexpr int INIT_KERNEL_THREADS = 128; + + // The input key type + using KeyT = cub::detail::value_t; + + // The input value type + using InputT = cub::detail::value_t; + + /// Device-accessible allocation of temporary storage. When `nullptr`, the + /// required allocation size is written to `temp_storage_bytes` and no work + /// is done. + void *d_temp_storage; + + /// Reference to size in bytes of `d_temp_storage` allocation + size_t &temp_storage_bytes; + + /// Iterator to the input sequence of key items + KeysInputIteratorT d_keys_in; + + /// Iterator to the input sequence of value items + ValuesInputIteratorT d_values_in; + + /// Iterator to the input sequence of value items + ValuesOutputIteratorT d_values_out; + + /// Binary equality functor + EqualityOp equality_op; + + /// Binary scan functor + ScanOpT scan_op; + + /// Initial value to seed the exclusive scan + InitValueT init_value; + + /// Total number of input items (i.e., the length of `d_in`) + OffsetT num_items; + + /// CUDA stream to launch kernels within. + cudaStream_t stream; + int ptx_version; + + /** + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Iterator to the input sequence of key items + * + * @param[in] d_values_in + * Iterator to the input sequence of value items + * + * @param[out] d_values_out + * Iterator to the input sequence of value items + * + * @param[in] equality_op + * Binary equality functor + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] init_value + * Initial value to seed the exclusive scan + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] stream + * CUDA stream to launch kernels within. + */ + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchScanByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + EqualityOp equality_op, + ScanOpT scan_op, + InitValueT init_value, + OffsetT num_items, + cudaStream_t stream, + int ptx_version) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_keys_in(d_keys_in) + , d_values_in(d_values_in) + , d_values_out(d_values_out) + , equality_op(equality_op) + , scan_op(scan_op) + , init_value(init_value) + , num_items(num_items) + , stream(stream) + , ptx_version(ptx_version) + {} + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchScanByKey(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + EqualityOp equality_op, + ScanOpT scan_op, + InitValueT init_value, + OffsetT num_items, + cudaStream_t stream, + bool debug_synchronous, + int ptx_version) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_keys_in(d_keys_in) + , d_values_in(d_values_in) + , d_values_out(d_values_out) + , equality_op(equality_op) + , scan_op(scan_op) + , init_value(init_value) + , num_items(num_items) + , stream(stream) + , ptx_version(ptx_version) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + } + + template + CUB_RUNTIME_FUNCTION __host__ __forceinline__ cudaError_t + Invoke(InitKernel init_kernel, ScanKernel scan_kernel) + { + using Policy = typename ActivePolicyT::ScanByKeyPolicyT; + using ScanByKeyTileStateT = ReduceByKeyScanTileState; + + cudaError error = cudaSuccess; + do + { + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) + { + break; + } + + // Number of input tiles + int tile_size = Policy::BLOCK_THREADS * Policy::ITEMS_PER_THREAD; + int num_tiles = + static_cast(cub::DivideAndRoundUp(num_items, tile_size)); + + // Specify temporary storage allocation requirements + size_t allocation_sizes[2]; + if (CubDebug( + error = ScanByKeyTileStateT::AllocationSize(num_tiles, + allocation_sizes[0]))) + { + break; // bytes needed for tile status descriptors + } + + allocation_sizes[1] = sizeof(KeyT) * (num_tiles + 1); + + // Compute allocation pointers into the single storage blob (or compute + // the necessary size of the blob) + void *allocations[2] = {}; + if (CubDebug(error = AliasTemporaries(d_temp_storage, + temp_storage_bytes, + allocations, + allocation_sizes))) + { + break; + } + + if (d_temp_storage == NULL) + { + // Return if the caller is simply requesting the size of the storage + // allocation + break; + } + + // Return if empty problem + if (num_items == 0) + { + break; + } + + KeyT *d_keys_prev_in = reinterpret_cast(allocations[1]); + + // Construct the tile status interface + ScanByKeyTileStateT tile_state; + if (CubDebug(error = tile_state.Init(num_tiles, + allocations[0], + allocation_sizes[0]))) + { + break; + } + + // Log init_kernel configuration + int init_grid_size = cub::DivideAndRoundUp(num_tiles, + INIT_KERNEL_THREADS); + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking init_kernel<<<%d, %d, 0, %lld>>>()\n", + init_grid_size, + INIT_KERNEL_THREADS, + (long long)stream); + #endif + + // Invoke init_kernel to initialize tile descriptors + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + init_grid_size, + INIT_KERNEL_THREADS, + 0, + stream) + .doit(init_kernel, + tile_state, + d_keys_in, + d_keys_prev_in, + tile_size, + num_tiles); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Get SM occupancy for scan_kernel + int scan_sm_occupancy; + if (CubDebug(error = MaxSmOccupancy(scan_sm_occupancy, // out + scan_kernel, + Policy::BLOCK_THREADS))) + { + break; + } + + // Get max x-dimension of grid + int max_dim_x; + if (CubDebug(error = cudaDeviceGetAttribute(&max_dim_x, + cudaDevAttrMaxGridDimX, + device_ordinal))) + { + break; + } + + // Run grids in epochs (in case number of tiles exceeds max x-dimension + int scan_grid_size = CUB_MIN(num_tiles, max_dim_x); + for (int start_tile = 0; start_tile < num_tiles; + start_tile += scan_grid_size) + { + // Log scan_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking %d scan_kernel<<<%d, %d, 0, %lld>>>(), %d items " + "per thread, %d SM occupancy\n", + start_tile, + scan_grid_size, + Policy::BLOCK_THREADS, + (long long)stream, + Policy::ITEMS_PER_THREAD, + scan_sm_occupancy); + #endif + + // Invoke scan_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + scan_grid_size, + Policy::BLOCK_THREADS, + 0, + stream) + .doit(scan_kernel, + d_keys_in, + d_keys_prev_in, + d_values_in, + d_values_out, + tile_state, + start_tile, + equality_op, + scan_op, + init_value, + num_items); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } + } while (0); + + return error; + } + + template + CUB_RUNTIME_FUNCTION __host__ __forceinline__ cudaError_t Invoke() + { + using MaxPolicyT = typename DispatchScanByKey::MaxPolicy; + using ScanByKeyTileStateT = ReduceByKeyScanTileState; + + // Ensure kernels are instantiated. + return Invoke( + DeviceScanByKeyInitKernel, + DeviceScanByKeyKernel); + } + + /** + * @brief Internal dispatch routine + * + * @param[in] d_temp_storage + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to `temp_storage_bytes` and no + * work is done. + * + * @param[in,out] temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param[in] d_keys_in + * Iterator to the input sequence of key items + * + * @param[in] d_values_in + * Iterator to the input sequence of value items + * + * @param[out] d_values_out + * Iterator to the input sequence of value items + * + * @param[in] equality_op + * Binary equality functor + * + * @param[in] scan_op + * Binary scan functor + * + * @param[in] init_value + * Initial value to seed the exclusive scan + * + * @param[in] num_items + * Total number of input items (i.e., the length of `d_in`) + * + * @param[in] stream + * CUDA stream to launch kernels within. + */ + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + EqualityOp equality_op, + ScanOpT scan_op, + InitValueT init_value, + OffsetT num_items, + cudaStream_t stream) + { + using MaxPolicyT = typename DispatchScanByKey::MaxPolicy; + + cudaError_t error; + + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + // Create dispatch functor + DispatchScanByKey dispatch(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_values_out, + equality_op, + scan_op, + init_value, + num_items, + stream, + ptx_version); + + // Dispatch to chained policy + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + KeysInputIteratorT d_keys_in, + ValuesInputIteratorT d_values_in, + ValuesOutputIteratorT d_values_out, + EqualityOp equality_op, + ScanOpT scan_op, + InitValueT init_value, + OffsetT num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_values_out, + equality_op, + scan_op, + init_value, + num_items, + stream); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_segmented_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_segmented_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..d00e998f165f63833969c56fedd1cd3bcdcc5a08 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_segmented_sort.cuh @@ -0,0 +1,1783 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + + +CUB_NAMESPACE_BEGIN + + +/** + * @brief Fallback kernel, in case there's not enough segments to + * take advantage of partitioning. + * + * In this case, the sorting method is still selected based on the segment size. + * If a single warp can sort the segment, the algorithm will use the sub-warp + * merge sort. Otherwise, the algorithm will use the in-shared-memory version of + * block radix sort. If data don't fit into shared memory, the algorithm will + * use in-global-memory radix sort. + * + * @param[in] d_keys_in_orig + * Input keys buffer + * + * @param[out] d_keys_out_orig + * Output keys buffer + * + * @param[in,out] d_keys_double_buffer + * Double keys buffer + * + * @param[in] d_values_in_orig + * Input values buffer + * + * @param[out] d_values_out_orig + * Output values buffer + * + * @param[in,out] d_values_double_buffer + * Double values buffer + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of length + * @p num_segments, such that `d_begin_offsets[i]` is the first element of the + * i-th data segment in `d_keys_*` and `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of the + * i-th data segment in `d_keys_*` and `d_values_*`. + * If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the i-th segment is + * considered empty. + */ +template +__launch_bounds__(ChainedPolicyT::ActivePolicy::LargeSegmentPolicy::BLOCK_THREADS) +__global__ void DeviceSegmentedSortFallbackKernel( + const KeyT *d_keys_in_orig, + KeyT *d_keys_out_orig, + cub::detail::device_double_buffer d_keys_double_buffer, + const ValueT *d_values_in_orig, + ValueT *d_values_out_orig, + cub::detail::device_double_buffer d_values_double_buffer, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets) +{ + using ActivePolicyT = typename ChainedPolicyT::ActivePolicy; + using LargeSegmentPolicyT = typename ActivePolicyT::LargeSegmentPolicy; + using MediumPolicyT = + typename ActivePolicyT::SmallAndMediumSegmentedSortPolicyT::MediumPolicyT; + + const unsigned int segment_id = blockIdx.x; + OffsetT segment_begin = d_begin_offsets[segment_id]; + OffsetT segment_end = d_end_offsets[segment_id]; + OffsetT num_items = segment_end - segment_begin; + + if (num_items <= 0) + { + return; + } + + using AgentSegmentedRadixSortT = + cub::AgentSegmentedRadixSort; + + using WarpReduceT = cub::WarpReduce; + + using AgentWarpMergeSortT = + AgentSubWarpSort; + + __shared__ union + { + typename AgentSegmentedRadixSortT::TempStorage block_sort; + typename WarpReduceT::TempStorage warp_reduce; + typename AgentWarpMergeSortT::TempStorage medium_warp_sort; + } temp_storage; + + constexpr bool keys_only = std::is_same::value; + AgentSegmentedRadixSortT agent(num_items, temp_storage.block_sort); + + constexpr int begin_bit = 0; + constexpr int end_bit = sizeof(KeyT) * 8; + + constexpr int cacheable_tile_size = LargeSegmentPolicyT::BLOCK_THREADS * + LargeSegmentPolicyT::ITEMS_PER_THREAD; + + d_keys_in_orig += segment_begin; + d_keys_out_orig += segment_begin; + + if (!keys_only) + { + d_values_in_orig += segment_begin; + d_values_out_orig += segment_begin; + } + + if (num_items <= MediumPolicyT::ITEMS_PER_TILE) + { + // Sort by a single warp + if (threadIdx.x < MediumPolicyT::WARP_THREADS) + { + AgentWarpMergeSortT(temp_storage.medium_warp_sort) + .ProcessSegment(num_items, + d_keys_in_orig, + d_keys_out_orig, + d_values_in_orig, + d_values_out_orig); + } + } + else if (num_items < cacheable_tile_size) + { + // Sort by a CTA if data fits into shared memory + agent.ProcessSinglePass(begin_bit, + end_bit, + d_keys_in_orig, + d_values_in_orig, + d_keys_out_orig, + d_values_out_orig); + } + else + { + // Sort by a CTA with multiple reads from global memory + int current_bit = begin_bit; + int pass_bits = (cub::min)(int{LargeSegmentPolicyT::RADIX_BITS}, + (end_bit - current_bit)); + + d_keys_double_buffer = cub::detail::device_double_buffer( + d_keys_double_buffer.current() + segment_begin, + d_keys_double_buffer.alternate() + segment_begin); + + if (!keys_only) + { + d_values_double_buffer = cub::detail::device_double_buffer( + d_values_double_buffer.current() + segment_begin, + d_values_double_buffer.alternate() + segment_begin); + } + + agent.ProcessIterative(current_bit, + pass_bits, + d_keys_in_orig, + d_values_in_orig, + d_keys_double_buffer.current(), + d_values_double_buffer.current()); + current_bit += pass_bits; + + #pragma unroll 1 + while (current_bit < end_bit) + { + pass_bits = (cub::min)(int{LargeSegmentPolicyT::RADIX_BITS}, + (end_bit - current_bit)); + + CTA_SYNC(); + agent.ProcessIterative(current_bit, + pass_bits, + d_keys_double_buffer.current(), + d_values_double_buffer.current(), + d_keys_double_buffer.alternate(), + d_values_double_buffer.alternate()); + + d_keys_double_buffer.swap(); + d_values_double_buffer.swap(); + current_bit += pass_bits; + } + } +} + + +/** + * @brief Single kernel for moderate size (less than a few thousand items) + * segments. + * + * This kernel allocates a sub-warp per segment. Therefore, this kernel assigns + * a single thread block to multiple segments. Segments fall into two + * categories. An architectural warp usually sorts segments in the medium-size + * category, while a few threads sort segments in the small-size category. Since + * segments are partitioned, we know the last thread block index assigned to + * sort medium-size segments. A particular thread block can check this number to + * find out which category it was assigned to sort. In both cases, the + * merge sort is used. + * + * @param[in] small_segments + * Number of segments that can be sorted by a warp part + * + * @param[in] medium_segments + * Number of segments that can be sorted by a warp + * + * @param[in] medium_blocks + * Number of CTAs assigned to process medium segments + * + * @param[in] d_small_segments_indices + * Small segments mapping of length @p small_segments, such that + * `d_small_segments_indices[i]` is the input segment index + * + * @param[in] d_medium_segments_indices + * Medium segments mapping of length @p medium_segments, such that + * `d_medium_segments_indices[i]` is the input segment index + * + * @param[in] d_keys_in_orig + * Input keys buffer + * + * @param[out] d_keys_out_orig + * Output keys buffer + * + * @param[in] d_values_in_orig + * Input values buffer + * + * @param[out] d_values_out_orig + * Output values buffer + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of length + * @p num_segments, such that `d_begin_offsets[i]` is the first element of the + * ith data segment in `d_keys_*` and `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of the + * ith data segment in `d_keys_*` and `d_values_*`. If + * `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the ith is + * considered empty. + */ +template +__launch_bounds__(ChainedPolicyT::ActivePolicy::SmallAndMediumSegmentedSortPolicyT::BLOCK_THREADS) +__global__ void DeviceSegmentedSortKernelSmall( + unsigned int small_segments, + unsigned int medium_segments, + unsigned int medium_blocks, + const unsigned int *d_small_segments_indices, + const unsigned int *d_medium_segments_indices, + const KeyT *d_keys_in, + KeyT *d_keys_out, + const ValueT *d_values_in, + ValueT *d_values_out, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets) +{ + const unsigned int tid = threadIdx.x; + const unsigned int bid = blockIdx.x; + + using ActivePolicyT = typename ChainedPolicyT::ActivePolicy; + using SmallAndMediumPolicyT = + typename ActivePolicyT::SmallAndMediumSegmentedSortPolicyT; + using MediumPolicyT = typename SmallAndMediumPolicyT::MediumPolicyT; + using SmallPolicyT = typename SmallAndMediumPolicyT::SmallPolicyT; + + constexpr int threads_per_medium_segment = MediumPolicyT::WARP_THREADS; + constexpr int threads_per_small_segment = SmallPolicyT::WARP_THREADS; + + using MediumAgentWarpMergeSortT = + AgentSubWarpSort; + + using SmallAgentWarpMergeSortT = + AgentSubWarpSort; + + constexpr auto segments_per_medium_block = + static_cast(SmallAndMediumPolicyT::SEGMENTS_PER_MEDIUM_BLOCK); + + constexpr auto segments_per_small_block = + static_cast(SmallAndMediumPolicyT::SEGMENTS_PER_SMALL_BLOCK); + + __shared__ union + { + typename MediumAgentWarpMergeSortT::TempStorage + medium_storage[segments_per_medium_block]; + + typename SmallAgentWarpMergeSortT::TempStorage + small_storage[segments_per_small_block]; + } temp_storage; + + if (bid < medium_blocks) + { + const unsigned int sid_within_block = tid / threads_per_medium_segment; + const unsigned int medium_segment_id = bid * segments_per_medium_block + + sid_within_block; + + if (medium_segment_id < medium_segments) + { + const unsigned int global_segment_id = + d_medium_segments_indices[medium_segment_id]; + + const OffsetT segment_begin = d_begin_offsets[global_segment_id]; + const OffsetT segment_end = d_end_offsets[global_segment_id]; + const OffsetT num_items = segment_end - segment_begin; + + MediumAgentWarpMergeSortT(temp_storage.medium_storage[sid_within_block]) + .ProcessSegment(num_items, + d_keys_in + segment_begin, + d_keys_out + segment_begin, + d_values_in + segment_begin, + d_values_out + segment_begin); + } + } + else + { + const unsigned int sid_within_block = tid / threads_per_small_segment; + const unsigned int small_segment_id = + (bid - medium_blocks) * segments_per_small_block + sid_within_block; + + if (small_segment_id < small_segments) + { + const unsigned int global_segment_id = + d_small_segments_indices[small_segment_id]; + + const OffsetT segment_begin = d_begin_offsets[global_segment_id]; + const OffsetT segment_end = d_end_offsets[global_segment_id]; + const OffsetT num_items = segment_end - segment_begin; + + SmallAgentWarpMergeSortT(temp_storage.small_storage[sid_within_block]) + .ProcessSegment(num_items, + d_keys_in + segment_begin, + d_keys_out + segment_begin, + d_values_in + segment_begin, + d_values_out + segment_begin); + } + } +} + +/** + * @brief Single kernel for large size (more than a few thousand items) segments. + * + * @param[in] d_keys_in_orig + * Input keys buffer + * + * @param[out] d_keys_out_orig + * Output keys buffer + * + * @param[in] d_values_in_orig + * Input values buffer + * + * @param[out] d_values_out_orig + * Output values buffer + * + * @param[in] d_begin_offsets + * Random-access input iterator to the sequence of beginning offsets of length + * @p num_segments, such that `d_begin_offsets[i]` is the first element of the + * ith data segment in `d_keys_*` and `d_values_*` + * + * @param[in] d_end_offsets + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that `d_end_offsets[i]-1` is the last element of the + * ith data segment in `d_keys_*` and `d_values_*`. If + * `d_end_offsets[i]-1 <= d_begin_offsets[i]`, the ith is + * considered empty. + */ +template +__launch_bounds__(ChainedPolicyT::ActivePolicy::LargeSegmentPolicy::BLOCK_THREADS) +__global__ void DeviceSegmentedSortKernelLarge( + const unsigned int *d_segments_indices, + const KeyT *d_keys_in_orig, + KeyT *d_keys_out_orig, + cub::detail::device_double_buffer d_keys_double_buffer, + const ValueT *d_values_in_orig, + ValueT *d_values_out_orig, + cub::detail::device_double_buffer d_values_double_buffer, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets) +{ + using ActivePolicyT = typename ChainedPolicyT::ActivePolicy; + using LargeSegmentPolicyT = typename ActivePolicyT::LargeSegmentPolicy; + + constexpr int small_tile_size = LargeSegmentPolicyT::BLOCK_THREADS * + LargeSegmentPolicyT::ITEMS_PER_THREAD; + + using AgentSegmentedRadixSortT = + cub::AgentSegmentedRadixSort; + + __shared__ typename AgentSegmentedRadixSortT::TempStorage storage; + + const unsigned int bid = blockIdx.x; + + constexpr int begin_bit = 0; + constexpr int end_bit = sizeof(KeyT) * 8; + + const unsigned int global_segment_id = d_segments_indices[bid]; + const OffsetT segment_begin = d_begin_offsets[global_segment_id]; + const OffsetT segment_end = d_end_offsets[global_segment_id]; + const OffsetT num_items = segment_end - segment_begin; + + constexpr bool keys_only = std::is_same::value; + AgentSegmentedRadixSortT agent(num_items, storage); + + d_keys_in_orig += segment_begin; + d_keys_out_orig += segment_begin; + + if (!keys_only) + { + d_values_in_orig += segment_begin; + d_values_out_orig += segment_begin; + } + + if (num_items < small_tile_size) + { + // Sort in shared memory if the segment fits into it + agent.ProcessSinglePass(begin_bit, + end_bit, + d_keys_in_orig, + d_values_in_orig, + d_keys_out_orig, + d_values_out_orig); + } + else + { + // Sort reading global memory multiple times + int current_bit = begin_bit; + int pass_bits = (cub::min)(int{LargeSegmentPolicyT::RADIX_BITS}, + (end_bit - current_bit)); + + d_keys_double_buffer = cub::detail::device_double_buffer( + d_keys_double_buffer.current() + segment_begin, + d_keys_double_buffer.alternate() + segment_begin); + + if (!keys_only) + { + d_values_double_buffer = cub::detail::device_double_buffer( + d_values_double_buffer.current() + segment_begin, + d_values_double_buffer.alternate() + segment_begin); + } + + agent.ProcessIterative(current_bit, + pass_bits, + d_keys_in_orig, + d_values_in_orig, + d_keys_double_buffer.current(), + d_values_double_buffer.current()); + current_bit += pass_bits; + + #pragma unroll 1 + while (current_bit < end_bit) + { + pass_bits = (cub::min)(int{LargeSegmentPolicyT::RADIX_BITS}, + (end_bit - current_bit)); + + CTA_SYNC(); + agent.ProcessIterative(current_bit, + pass_bits, + d_keys_double_buffer.current(), + d_values_double_buffer.current(), + d_keys_double_buffer.alternate(), + d_values_double_buffer.alternate()); + + d_keys_double_buffer.swap(); + d_values_double_buffer.swap(); + current_bit += pass_bits; + } + } +} + +/* + * Continuation is called after the partitioning stage. It launches kernels + * to sort large and small segments using the partitioning results. Separation + * of this stage is required to eliminate device-side synchronization in + * the CDP mode. + */ +template +CUB_RUNTIME_FUNCTION cudaError_t +DeviceSegmentedSortContinuation( + LargeKernelT large_kernel, + SmallKernelT small_kernel, + int num_segments, + KeyT *d_current_keys, + KeyT *d_final_keys, + detail::device_double_buffer d_keys_double_buffer, + ValueT *d_current_values, + ValueT *d_final_values, + detail::device_double_buffer d_values_double_buffer, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + unsigned int *group_sizes, + unsigned int *large_and_medium_segments_indices, + unsigned int *small_segments_indices, + cudaStream_t stream) +{ + cudaError error = cudaSuccess; + + const unsigned int large_segments = group_sizes[0]; + + if (large_segments > 0) + { + // One CTA per segment + const unsigned int blocks_in_grid = large_segments; + + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking " + "DeviceSegmentedSortKernelLarge<<<%d, %d, 0, %lld>>>()\n", + static_cast(blocks_in_grid), + LargeSegmentPolicyT::BLOCK_THREADS, + (long long)stream); + #endif + + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + blocks_in_grid, + LargeSegmentPolicyT::BLOCK_THREADS, + 0, + stream) + .doit(large_kernel, + large_and_medium_segments_indices, + d_current_keys, + d_final_keys, + d_keys_double_buffer, + d_current_values, + d_final_values, + d_values_double_buffer, + d_begin_offsets, + d_end_offsets); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + return error; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + return error; + } + } + + const unsigned int small_segments = group_sizes[1]; + const unsigned int medium_segments = + static_cast(num_segments) - + (large_segments + small_segments); + + const unsigned int small_blocks = + DivideAndRoundUp(small_segments, + SmallAndMediumPolicyT::SEGMENTS_PER_SMALL_BLOCK); + + const unsigned int medium_blocks = + DivideAndRoundUp(medium_segments, + SmallAndMediumPolicyT::SEGMENTS_PER_MEDIUM_BLOCK); + + const unsigned int small_and_medium_blocks_in_grid = small_blocks + + medium_blocks; + + if (small_and_medium_blocks_in_grid) + { + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking " + "DeviceSegmentedSortKernelSmall<<<%d, %d, 0, %lld>>>()\n", + static_cast(small_and_medium_blocks_in_grid), + SmallAndMediumPolicyT::BLOCK_THREADS, + (long long)stream); + #endif + + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + small_and_medium_blocks_in_grid, + SmallAndMediumPolicyT::BLOCK_THREADS, + 0, + stream) + .doit(small_kernel, + small_segments, + medium_segments, + medium_blocks, + small_segments_indices, + large_and_medium_segments_indices + num_segments - medium_segments, + d_current_keys, + d_final_keys, + d_current_values, + d_final_values, + d_begin_offsets, + d_end_offsets); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + return error; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + return error; + } + } + + return error; +} + +#ifdef CUB_RDC_ENABLED +/* + * Continuation kernel is used only in the CDP mode. It's used to + * launch DeviceSegmentedSortContinuation as a separate kernel. + */ +template +__launch_bounds__(1) __global__ void +DeviceSegmentedSortContinuationKernel( + LargeKernelT large_kernel, + SmallKernelT small_kernel, + int num_segments, + KeyT *d_current_keys, + KeyT *d_final_keys, + detail::device_double_buffer d_keys_double_buffer, + ValueT *d_current_values, + ValueT *d_final_values, + detail::device_double_buffer d_values_double_buffer, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + unsigned int *group_sizes, + unsigned int *large_and_medium_segments_indices, + unsigned int *small_segments_indices) +{ + using ActivePolicyT = typename ChainedPolicyT::ActivePolicy; + using LargeSegmentPolicyT = typename ActivePolicyT::LargeSegmentPolicy; + using SmallAndMediumPolicyT = + typename ActivePolicyT::SmallAndMediumSegmentedSortPolicyT; + + // In case of CDP: + // 1. each CTA has a different main stream + // 2. all streams are non-blocking + // 3. child grid always completes before the parent grid + // 4. streams can be used only from the CTA in which they were created + // 5. streams created on the host cannot be used on the device + // + // Due to (4, 5), we can't pass the user-provided stream in the continuation. + // Due to (1, 2, 3) it's safe to pass the main stream. + cudaError_t error = + DeviceSegmentedSortContinuation( + large_kernel, + small_kernel, + num_segments, + d_current_keys, + d_final_keys, + d_keys_double_buffer, + d_current_values, + d_final_values, + d_values_double_buffer, + d_begin_offsets, + d_end_offsets, + group_sizes, + large_and_medium_segments_indices, + small_segments_indices, + 0); // always launching on the main stream (see motivation above) + + CubDebug(error); +} +#endif // CUB_RDC_ENABLED + +template +struct DeviceSegmentedSortPolicy +{ + using DominantT = + cub::detail::conditional_t<(sizeof(ValueT) > sizeof(KeyT)), ValueT, KeyT>; + + constexpr static int KEYS_ONLY = std::is_same::value; + + //---------------------------------------------------------------------------- + // Architecture-specific tuning policies + //---------------------------------------------------------------------------- + + struct Policy350 : ChainedPolicy<350, Policy350, Policy350> + { + constexpr static int BLOCK_THREADS = 128; + constexpr static int RADIX_BITS = sizeof(KeyT) > 1 ? 6 : 4; + constexpr static int PARTITIONING_THRESHOLD = 300; + + using LargeSegmentPolicy = + AgentRadixSortDownsweepPolicy; + + constexpr static int ITEMS_PER_SMALL_THREAD = + Nominal4BItemsToItems(5); + + constexpr static int ITEMS_PER_MEDIUM_THREAD = + Nominal4BItemsToItems(5); + + using SmallAndMediumSegmentedSortPolicyT = + AgentSmallAndMediumSegmentedSortPolicy< + + BLOCK_THREADS, + + // Small policy + cub::AgentSubWarpMergeSortPolicy<4, + ITEMS_PER_SMALL_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>, + + // Medium policy + cub::AgentSubWarpMergeSortPolicy<32, + ITEMS_PER_MEDIUM_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>>; + }; + + struct Policy500 : ChainedPolicy<500, Policy500, Policy350> + { + constexpr static int BLOCK_THREADS = 256; + constexpr static int RADIX_BITS = sizeof(KeyT) > 1 ? 6 : 4; + constexpr static int PARTITIONING_THRESHOLD = 300; + + using LargeSegmentPolicy = + AgentRadixSortDownsweepPolicy; + + constexpr static int ITEMS_PER_SMALL_THREAD = + Nominal4BItemsToItems(7); + + constexpr static int ITEMS_PER_MEDIUM_THREAD = + Nominal4BItemsToItems(7); + + using SmallAndMediumSegmentedSortPolicyT = + AgentSmallAndMediumSegmentedSortPolicy< + + BLOCK_THREADS, + + // Small policy + cub::AgentSubWarpMergeSortPolicy<4, // Threads per segment + ITEMS_PER_SMALL_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>, + + // Medium policy + cub::AgentSubWarpMergeSortPolicy<32, // Threads per segment + ITEMS_PER_MEDIUM_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>>; + }; + + struct Policy600 : ChainedPolicy<600, Policy600, Policy500> + { + constexpr static int BLOCK_THREADS = 256; + constexpr static int RADIX_BITS = sizeof(KeyT) > 1 ? 6 : 4; + constexpr static int PARTITIONING_THRESHOLD = 500; + + using LargeSegmentPolicy = + AgentRadixSortDownsweepPolicy; + + constexpr static int ITEMS_PER_SMALL_THREAD = + Nominal4BItemsToItems(9); + + constexpr static int ITEMS_PER_MEDIUM_THREAD = + Nominal4BItemsToItems(9); + + using SmallAndMediumSegmentedSortPolicyT = + AgentSmallAndMediumSegmentedSortPolicy< + + BLOCK_THREADS, + + // Small policy + cub::AgentSubWarpMergeSortPolicy<4, // Threads per segment + ITEMS_PER_SMALL_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>, + + // Medium policy + cub::AgentSubWarpMergeSortPolicy<32, // Threads per segment + ITEMS_PER_MEDIUM_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>>; + }; + + struct Policy610 : ChainedPolicy<610, Policy610, Policy600> + { + constexpr static int BLOCK_THREADS = 256; + constexpr static int RADIX_BITS = sizeof(KeyT) > 1 ? 6 : 4; + constexpr static int PARTITIONING_THRESHOLD = 500; + + using LargeSegmentPolicy = + AgentRadixSortDownsweepPolicy; + + constexpr static int ITEMS_PER_SMALL_THREAD = + Nominal4BItemsToItems(9); + + constexpr static int ITEMS_PER_MEDIUM_THREAD = + Nominal4BItemsToItems(9); + + using SmallAndMediumSegmentedSortPolicyT = + AgentSmallAndMediumSegmentedSortPolicy< + + BLOCK_THREADS, + + // Small policy + cub::AgentSubWarpMergeSortPolicy<4, // Threads per segment + ITEMS_PER_SMALL_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>, + + // Medium policy + cub::AgentSubWarpMergeSortPolicy<32, // Threads per segment + ITEMS_PER_MEDIUM_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>>; + }; + + struct Policy620 : ChainedPolicy<620, Policy620, Policy610> + { + constexpr static int BLOCK_THREADS = 256; + constexpr static int RADIX_BITS = sizeof(KeyT) > 1 ? 5 : 4; + constexpr static int PARTITIONING_THRESHOLD = 500; + + using LargeSegmentPolicy = + AgentRadixSortDownsweepPolicy; + + constexpr static int ITEMS_PER_SMALL_THREAD = + Nominal4BItemsToItems(9); + + constexpr static int ITEMS_PER_MEDIUM_THREAD = + Nominal4BItemsToItems(9); + + using SmallAndMediumSegmentedSortPolicyT = + AgentSmallAndMediumSegmentedSortPolicy< + + BLOCK_THREADS, + + // Small policy + cub::AgentSubWarpMergeSortPolicy<4, // Threads per segment + ITEMS_PER_SMALL_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>, + + // Medium policy + cub::AgentSubWarpMergeSortPolicy<32, // Threads per segment + ITEMS_PER_MEDIUM_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>>; + }; + + struct Policy700 : ChainedPolicy<700, Policy700, Policy620> + { + constexpr static int BLOCK_THREADS = 256; + constexpr static int RADIX_BITS = sizeof(KeyT) > 1 ? 6 : 4; + constexpr static int PARTITIONING_THRESHOLD = 500; + + using LargeSegmentPolicy = + AgentRadixSortDownsweepPolicy; + + constexpr static int ITEMS_PER_SMALL_THREAD = + Nominal4BItemsToItems(7); + + constexpr static int ITEMS_PER_MEDIUM_THREAD = + Nominal4BItemsToItems(KEYS_ONLY ? 11 : 7); + + using SmallAndMediumSegmentedSortPolicyT = + AgentSmallAndMediumSegmentedSortPolicy< + + BLOCK_THREADS, + + // Small policy + cub::AgentSubWarpMergeSortPolicy<(KEYS_ONLY ? 4 : 8), // Threads per segment + ITEMS_PER_SMALL_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>, + + // Medium policy + cub::AgentSubWarpMergeSortPolicy<32, // Threads per segment + ITEMS_PER_MEDIUM_THREAD, + WarpLoadAlgorithm::WARP_LOAD_DIRECT, + CacheLoadModifier::LOAD_DEFAULT>>; + }; + + struct Policy800 : ChainedPolicy<800, Policy800, Policy700> + { + constexpr static int BLOCK_THREADS = 256; + constexpr static int PARTITIONING_THRESHOLD = 500; + + using LargeSegmentPolicy = + cub::AgentRadixSortDownsweepPolicy 1) ? 6 : 4>; + + constexpr static int ITEMS_PER_SMALL_THREAD = + Nominal4BItemsToItems(9); + + constexpr static int ITEMS_PER_MEDIUM_THREAD = + Nominal4BItemsToItems(KEYS_ONLY ? 7 : 11); + + using SmallAndMediumSegmentedSortPolicyT = + AgentSmallAndMediumSegmentedSortPolicy< + + BLOCK_THREADS, + + // Small policy + cub::AgentSubWarpMergeSortPolicy<(KEYS_ONLY ? 4 : 2), // Threads per segment + ITEMS_PER_SMALL_THREAD, + WarpLoadAlgorithm::WARP_LOAD_TRANSPOSE, + CacheLoadModifier::LOAD_DEFAULT>, + + // Medium policy + cub::AgentSubWarpMergeSortPolicy<32, // Threads per segment + ITEMS_PER_MEDIUM_THREAD, + WarpLoadAlgorithm::WARP_LOAD_TRANSPOSE, + CacheLoadModifier::LOAD_DEFAULT>>; + }; + + struct Policy860 : ChainedPolicy<860, Policy860, Policy800> + { + constexpr static int BLOCK_THREADS = 256; + constexpr static int PARTITIONING_THRESHOLD = 500; + + using LargeSegmentPolicy = + cub::AgentRadixSortDownsweepPolicy 1) ? 6 : 4>; + + constexpr static bool LARGE_ITEMS = sizeof(DominantT) > 4; + + constexpr static int ITEMS_PER_SMALL_THREAD = + Nominal4BItemsToItems(LARGE_ITEMS ? 7 : 9); + + constexpr static int ITEMS_PER_MEDIUM_THREAD = + Nominal4BItemsToItems(LARGE_ITEMS ? 9 : 7); + + using SmallAndMediumSegmentedSortPolicyT = + AgentSmallAndMediumSegmentedSortPolicy< + + BLOCK_THREADS, + + // Small policy + cub::AgentSubWarpMergeSortPolicy<(LARGE_ITEMS ? 8 : 2), // Threads per segment + ITEMS_PER_SMALL_THREAD, + WarpLoadAlgorithm::WARP_LOAD_TRANSPOSE, + CacheLoadModifier::LOAD_LDG>, + + // Medium policy + cub::AgentSubWarpMergeSortPolicy<16, // Threads per segment + ITEMS_PER_MEDIUM_THREAD, + WarpLoadAlgorithm::WARP_LOAD_TRANSPOSE, + CacheLoadModifier::LOAD_LDG>>; + }; + + /// MaxPolicy + using MaxPolicy = Policy860; +}; + +template > +struct DispatchSegmentedSort : SelectedPolicy +{ + static constexpr int KEYS_ONLY = std::is_same::value; + + struct LargeSegmentsSelectorT + { + OffsetT value{}; + BeginOffsetIteratorT d_offset_begin{}; + EndOffsetIteratorT d_offset_end{}; + + __host__ __device__ __forceinline__ + LargeSegmentsSelectorT(OffsetT value, + BeginOffsetIteratorT d_offset_begin, + EndOffsetIteratorT d_offset_end) + : value(value) + , d_offset_begin(d_offset_begin) + , d_offset_end(d_offset_end) + {} + + __host__ __device__ __forceinline__ bool + operator()(unsigned int segment_id) const + { + const OffsetT segment_size = d_offset_end[segment_id] - + d_offset_begin[segment_id]; + return segment_size > value; + } + }; + + struct SmallSegmentsSelectorT + { + OffsetT value{}; + BeginOffsetIteratorT d_offset_begin{}; + EndOffsetIteratorT d_offset_end{}; + + __host__ __device__ __forceinline__ + SmallSegmentsSelectorT(OffsetT value, + BeginOffsetIteratorT d_offset_begin, + EndOffsetIteratorT d_offset_end) + : value(value) + , d_offset_begin(d_offset_begin) + , d_offset_end(d_offset_end) + {} + + __host__ __device__ __forceinline__ bool + operator()(unsigned int segment_id) const + { + const OffsetT segment_size = d_offset_end[segment_id] - + d_offset_begin[segment_id]; + return segment_size < value; + } + }; + + // Partition selects large and small groups. The middle group is not selected. + constexpr static std::size_t num_selected_groups = 2; + + /** + * Device-accessible allocation of temporary storage. When `nullptr`, the + * required allocation size is written to @p temp_storage_bytes and no work + * is done. + */ + void *d_temp_storage; + + /// Reference to size in bytes of @p d_temp_storage allocation + std::size_t &temp_storage_bytes; + + /** + * Double-buffer whose current buffer contains the unsorted input keys and, + * upon return, is updated to point to the sorted output keys + */ + DoubleBuffer &d_keys; + + /** + * Double-buffer whose current buffer contains the unsorted input values and, + * upon return, is updated to point to the sorted output values + */ + DoubleBuffer &d_values; + + /// Number of items to sort + OffsetT num_items; + + /// The number of segments that comprise the sorting data + int num_segments; + + /** + * Random-access input iterator to the sequence of beginning offsets of length + * @p num_segments, such that `d_begin_offsets[i]` is the first element of the + * ith data segment in `d_keys_*` and `d_values_*` + */ + BeginOffsetIteratorT d_begin_offsets; + + /** + * Random-access input iterator to the sequence of ending offsets of length + * @p num_segments, such that d_end_offsets[i]-1 is the last element + * of the ith data segment in `d_keys_*` and + * `d_values_*`. If `d_end_offsets[i]-1 <= d_begin_offsets[i]`, + * the ith is considered empty. + */ + EndOffsetIteratorT d_end_offsets; + + /// Whether is okay to overwrite source buffers + bool is_overwrite_okay; + + /// CUDA stream to launch kernels within. + cudaStream_t stream; + + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchSegmentedSort(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + OffsetT num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + bool is_overwrite_okay, + cudaStream_t stream) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_keys(d_keys) + , d_values(d_values) + , num_items(num_items) + , num_segments(num_segments) + , d_begin_offsets(d_begin_offsets) + , d_end_offsets(d_end_offsets) + , is_overwrite_okay(is_overwrite_okay) + , stream(stream) + {} + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchSegmentedSort(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + OffsetT num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + bool is_overwrite_okay, + cudaStream_t stream, + bool debug_synchronous) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_keys(d_keys) + , d_values(d_values) + , num_items(num_items) + , num_segments(num_segments) + , d_begin_offsets(d_begin_offsets) + , d_end_offsets(d_end_offsets) + , is_overwrite_okay(is_overwrite_okay) + , stream(stream) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke() + { + using MaxPolicyT = typename DispatchSegmentedSort::MaxPolicy; + using LargeSegmentPolicyT = typename ActivePolicyT::LargeSegmentPolicy; + using SmallAndMediumPolicyT = + typename ActivePolicyT::SmallAndMediumSegmentedSortPolicyT; + + static_assert( + LargeSegmentPolicyT::LOAD_MODIFIER != CacheLoadModifier::LOAD_LDG, + "The memory consistency model does not apply to texture accesses"); + + static_assert( + KEYS_ONLY + || LargeSegmentPolicyT::LOAD_ALGORITHM != BLOCK_LOAD_STRIPED + || SmallAndMediumPolicyT::MediumPolicyT::LOAD_ALGORITHM != WARP_LOAD_STRIPED + || SmallAndMediumPolicyT::SmallPolicyT::LOAD_ALGORITHM != WARP_LOAD_STRIPED, + "Striped load will make this algorithm unstable"); + + static_assert( + SmallAndMediumPolicyT::MediumPolicyT::STORE_ALGORITHM != WARP_STORE_STRIPED + || SmallAndMediumPolicyT::SmallPolicyT::STORE_ALGORITHM != WARP_STORE_STRIPED, + "Striped stores will produce unsorted results"); + + constexpr int radix_bits = LargeSegmentPolicyT::RADIX_BITS; + + cudaError error = cudaSuccess; + + do + { + //------------------------------------------------------------------------ + // Prepare temporary storage layout + //------------------------------------------------------------------------ + + const bool partition_segments = num_segments > + ActivePolicyT::PARTITIONING_THRESHOLD; + + cub::detail::temporary_storage::layout<5> temporary_storage_layout; + + auto keys_slot = temporary_storage_layout.get_slot(0); + auto values_slot = temporary_storage_layout.get_slot(1); + auto large_and_medium_partitioning_slot = temporary_storage_layout.get_slot(2); + auto small_partitioning_slot = temporary_storage_layout.get_slot(3); + auto group_sizes_slot = temporary_storage_layout.get_slot(4); + + auto keys_allocation = keys_slot->create_alias(); + auto values_allocation = values_slot->create_alias(); + + if (!is_overwrite_okay) + { + keys_allocation.grow(num_items); + + if (!KEYS_ONLY) + { + values_allocation.grow(num_items); + } + } + + auto large_and_medium_segments_indices = + large_and_medium_partitioning_slot->create_alias(); + auto small_segments_indices = + small_partitioning_slot->create_alias(); + auto group_sizes = group_sizes_slot->create_alias(); + + std::size_t three_way_partition_temp_storage_bytes {}; + + LargeSegmentsSelectorT large_segments_selector( + SmallAndMediumPolicyT::MediumPolicyT::ITEMS_PER_TILE, + d_begin_offsets, + d_end_offsets); + + SmallSegmentsSelectorT small_segments_selector( + SmallAndMediumPolicyT::SmallPolicyT::ITEMS_PER_TILE + 1, + d_begin_offsets, + d_end_offsets); + + auto device_partition_temp_storage = + keys_slot->create_alias(); + + if (partition_segments) + { + large_and_medium_segments_indices.grow(num_segments); + small_segments_indices.grow(num_segments); + group_sizes.grow(num_selected_groups); + + auto medium_indices_iterator = + THRUST_NS_QUALIFIER::make_reverse_iterator( + large_and_medium_segments_indices.get()); + + cub::DevicePartition::If( + nullptr, + three_way_partition_temp_storage_bytes, + THRUST_NS_QUALIFIER::counting_iterator(0), + large_and_medium_segments_indices.get(), + small_segments_indices.get(), + medium_indices_iterator, + group_sizes.get(), + num_segments, + large_segments_selector, + small_segments_selector, + stream); + + device_partition_temp_storage.grow( + three_way_partition_temp_storage_bytes); + } + + if (d_temp_storage == nullptr) + { + temp_storage_bytes = temporary_storage_layout.get_size(); + + // Return if the caller is simply requesting the size of the storage + // allocation + break; + } + + if (num_items == 0 || num_segments == 0) + { + break; + } + + if (CubDebug( + error = temporary_storage_layout.map_to_buffer(d_temp_storage, + temp_storage_bytes))) + { + break; + } + + //------------------------------------------------------------------------ + // Sort + //------------------------------------------------------------------------ + + const bool is_num_passes_odd = GetNumPasses(radix_bits) & 1; + + /** + * This algorithm sorts segments that don't fit into shared memory with + * the in-global-memory radix sort. Radix sort splits key representation + * into multiple "digits". Each digit is RADIX_BITS wide. The algorithm + * iterates over these digits. Each of these iterations consists of a + * couple of stages. The first stage computes a histogram for a current + * digit in each segment key. This histogram helps to determine the + * starting position of the keys group with a similar digit. + * For example: + * keys_digits = [ 1, 0, 0, 1 ] + * digit_prefix = [ 0, 2 ] + * The second stage checks the keys again and increments the prefix to + * determine the final position of the key: + * + * expression | key | idx | result + * ----------------------------------- | ----- | ------- | -------------- + * result[prefix[keys[0]]++] = keys[0] | 1 | 2 | [ ?, ?, 1, ? ] + * result[prefix[keys[1]]++] = keys[0] | 0 | 0 | [ 0, ?, 1, ? ] + * result[prefix[keys[2]]++] = keys[0] | 0 | 1 | [ 0, 0, 1, ? ] + * result[prefix[keys[3]]++] = keys[0] | 1 | 3 | [ 0, 0, 1, 1 ] + * + * If the resulting memory is aliased to the input one, we'll face the + * following issues: + * + * input | key | idx | result/input | issue + * -------------- | ----- | ------- | ---------------- | ---------------- + * [ 1, 0, 0, 1 ] | 1 | 2 | [ 1, 0, 1, 1 ] | overwrite keys[2] + * [ 1, 0, 1, 1 ] | 0 | 0 | [ 0, 0, 1, 1 ] | + * [ 0, 0, 1, 1 ] | 1 | 3 | [ 0, 0, 1, 1 ] | extra key + * [ 0, 0, 1, 1 ] | 1 | 4 | [ 0, 0, 1, 1 ] 1 | OOB access + * + * To avoid these issues, we have to use extra memory. The extra memory + * holds temporary storage for writing intermediate results of each stage. + * Since we iterate over digits in keys, we potentially need: + * `sizeof(KeyT) * num_items * DivideAndRoundUp(sizeof(KeyT),RADIX_BITS)` + * auxiliary memory bytes. To reduce the auxiliary memory storage + * requirements, the algorithm relies on a double buffer facility. The + * idea behind it is in swapping destination and source buffers at each + * iteration. This way, we can use only two buffers. One of these buffers + * can be the final algorithm output destination. Therefore, only one + * auxiliary array is needed. Depending on the number of iterations, we + * can initialize the double buffer so that the algorithm output array + * will match the double buffer result one at the final iteration. + * A user can provide this algorithm with a double buffer straightaway to + * further reduce the auxiliary memory requirements. `is_overwrite_okay` + * indicates this use case. + */ + detail::device_double_buffer d_keys_double_buffer( + (is_overwrite_okay || is_num_passes_odd) ? d_keys.Alternate() : keys_allocation.get(), + (is_overwrite_okay) ? d_keys.Current() : (is_num_passes_odd) ? keys_allocation.get() : d_keys.Alternate()); + + detail::device_double_buffer d_values_double_buffer( + (is_overwrite_okay || is_num_passes_odd) ? d_values.Alternate() : values_allocation.get(), + (is_overwrite_okay) ? d_values.Current() : (is_num_passes_odd) ? values_allocation.get() : d_values.Alternate()); + + if (partition_segments) + { + // Partition input segments into size groups and assign specialized + // kernels for each of them. + error = + SortWithPartitioning( + DeviceSegmentedSortKernelLarge, + DeviceSegmentedSortKernelSmall, + three_way_partition_temp_storage_bytes, + d_keys_double_buffer, + d_values_double_buffer, + large_segments_selector, + small_segments_selector, + device_partition_temp_storage, + large_and_medium_segments_indices, + small_segments_indices, + group_sizes); + } + else + { + // If there are not enough segments, there's no reason to spend time + // on extra partitioning steps. + + error = SortWithoutPartitioning( + DeviceSegmentedSortFallbackKernel, + d_keys_double_buffer, + d_values_double_buffer); + } + + d_keys.selector = GetFinalSelector(d_keys.selector, radix_bits); + d_values.selector = GetFinalSelector(d_values.selector, radix_bits); + + } while (false); + + return error; + } + + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + OffsetT num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + bool is_overwrite_okay, + cudaStream_t stream) + { + using MaxPolicyT = typename DispatchSegmentedSort::MaxPolicy; + + cudaError error = cudaSuccess; + + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) + { + break; + } + + // Create dispatch functor + DispatchSegmentedSort dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + is_overwrite_okay, + stream); + + // Dispatch to chained policy + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (false); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + std::size_t &temp_storage_bytes, + DoubleBuffer &d_keys, + DoubleBuffer &d_values, + OffsetT num_items, + int num_segments, + BeginOffsetIteratorT d_begin_offsets, + EndOffsetIteratorT d_end_offsets, + bool is_overwrite_okay, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys, + d_values, + num_items, + num_segments, + d_begin_offsets, + d_end_offsets, + is_overwrite_okay, + stream); + } + +private: + CUB_RUNTIME_FUNCTION __forceinline__ + int GetNumPasses(int radix_bits) + { + const int byte_size = 8; + const int num_bits = sizeof(KeyT) * byte_size; + const int num_passes = DivideAndRoundUp(num_bits, radix_bits); + return num_passes; + } + + CUB_RUNTIME_FUNCTION __forceinline__ + int GetFinalSelector(int selector, int radix_bits) + { + // Sorted data always ends up in the other vector + if (!is_overwrite_okay) + { + return (selector + 1) & 1; + } + + return (selector + GetNumPasses(radix_bits)) & 1; + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ + T* GetFinalOutput(int radix_bits, + DoubleBuffer &buffer) + { + const int final_selector = GetFinalSelector(buffer.selector, radix_bits); + return buffer.d_buffers[final_selector]; + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t + SortWithPartitioning( + LargeKernelT large_kernel, + SmallKernelT small_kernel, + std::size_t three_way_partition_temp_storage_bytes, + cub::detail::device_double_buffer &d_keys_double_buffer, + cub::detail::device_double_buffer &d_values_double_buffer, + LargeSegmentsSelectorT &large_segments_selector, + SmallSegmentsSelectorT &small_segments_selector, + cub::detail::temporary_storage::alias &device_partition_temp_storage, + cub::detail::temporary_storage::alias &large_and_medium_segments_indices, + cub::detail::temporary_storage::alias &small_segments_indices, + cub::detail::temporary_storage::alias &group_sizes) + { + cudaError_t error = cudaSuccess; + + auto medium_indices_iterator = + THRUST_NS_QUALIFIER::make_reverse_iterator( + large_and_medium_segments_indices.get() + num_segments); + + error = cub::DevicePartition::If( + device_partition_temp_storage.get(), + three_way_partition_temp_storage_bytes, + THRUST_NS_QUALIFIER::counting_iterator(0), + large_and_medium_segments_indices.get(), + small_segments_indices.get(), + medium_indices_iterator, + group_sizes.get(), + num_segments, + large_segments_selector, + small_segments_selector, + stream); + if (CubDebug(error)) + { + return error; + } + + // The device path is only used (and only compiles) when CDP is enabled. + // It's defined in a macro since we can't put `#ifdef`s inside of + // `NV_IF_TARGET`. +#ifndef CUB_RDC_ENABLED + +#define CUB_TEMP_DEVICE_CODE + +#else // CUB_RDC_ENABLED + +#define CUB_TEMP_DEVICE_CODE \ + using MaxPolicyT = typename DispatchSegmentedSort::MaxPolicy; \ + error = \ + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(1, 1, 0, stream) \ + .doit(DeviceSegmentedSortContinuationKernel, \ + large_kernel, \ + small_kernel, \ + num_segments, \ + d_keys.Current(), \ + GetFinalOutput(LargeSegmentPolicyT::RADIX_BITS, d_keys), \ + d_keys_double_buffer, \ + d_values.Current(), \ + GetFinalOutput(LargeSegmentPolicyT::RADIX_BITS, d_values), \ + d_values_double_buffer, \ + d_begin_offsets, \ + d_end_offsets, \ + group_sizes.get(), \ + large_and_medium_segments_indices.get(), \ + small_segments_indices.get()); \ + \ + if (CubDebug(error)) \ + { \ + return error; \ + } \ + \ + error = detail::DebugSyncStream(stream); \ + if (CubDebug(error)) \ + { \ + return error; \ + } + +#endif // CUB_RDC_ENABLED + + // Clang format mangles some of this NV_IF_TARGET block + // clang-format off + NV_IF_TARGET( + NV_IS_HOST, + ( + unsigned int h_group_sizes[num_selected_groups]; + + if (CubDebug(error = cudaMemcpyAsync(h_group_sizes, + group_sizes.get(), + num_selected_groups * + sizeof(unsigned int), + cudaMemcpyDeviceToHost, + stream))) + { + return error; + } + + if (CubDebug(error = SyncStream(stream))) + { + return error; + } + + error = DeviceSegmentedSortContinuation( + large_kernel, + small_kernel, + num_segments, + d_keys.Current(), + GetFinalOutput(LargeSegmentPolicyT::RADIX_BITS, d_keys), + d_keys_double_buffer, + d_values.Current(), + GetFinalOutput(LargeSegmentPolicyT::RADIX_BITS, d_values), + d_values_double_buffer, + d_begin_offsets, + d_end_offsets, + h_group_sizes, + large_and_medium_segments_indices.get(), + small_segments_indices.get(), + stream);), + // NV_IS_DEVICE: + (CUB_TEMP_DEVICE_CODE)); + // clang-format on + +#undef CUB_TEMP_DEVICE_CODE + + return error; + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t SortWithoutPartitioning( + FallbackKernelT fallback_kernel, + cub::detail::device_double_buffer &d_keys_double_buffer, + cub::detail::device_double_buffer &d_values_double_buffer) + { + cudaError_t error = cudaSuccess; + + const auto blocks_in_grid = static_cast(num_segments); + const auto threads_in_block = + static_cast(LargeSegmentPolicyT::BLOCK_THREADS); + + // Log kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking DeviceSegmentedSortFallbackKernel<<<%d, %d, " + "0, %lld>>>(), %d items per thread, bit_grain %d\n", + blocks_in_grid, + threads_in_block, + (long long)stream, + LargeSegmentPolicyT::ITEMS_PER_THREAD, + LargeSegmentPolicyT::RADIX_BITS); + #endif + + // Invoke fallback kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(blocks_in_grid, + threads_in_block, + 0, + stream) + .doit(fallback_kernel, + d_keys.Current(), + GetFinalOutput(LargeSegmentPolicyT::RADIX_BITS, d_keys), + d_keys_double_buffer, + d_values.Current(), + GetFinalOutput(LargeSegmentPolicyT::RADIX_BITS, d_values), + d_values_double_buffer, + d_begin_offsets, + d_end_offsets); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + return error; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + return error; + } + + return error; + } +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_select_if.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_select_if.cuh new file mode 100644 index 0000000000000000000000000000000000000000..a2f3536ed2e8f48592d4c3782343f4ba3f5b25b7 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_select_if.cuh @@ -0,0 +1,600 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file + * cub::DeviceSelect provides device-wide, parallel operations for selecting items from sequences + * of data items residing within device-accessible memory. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Kernel entry points + *****************************************************************************/ + +/** + * Select kernel entry point (multi-block) + * + * Performs functor-based selection if SelectOpT functor type != NullType + * Otherwise performs flag-based selection if FlagsInputIterator's value type != NullType + * Otherwise performs discontinuity selection (keep unique) + * + * @tparam InputIteratorT + * Random-access input iterator type for reading input items + * + * @tparam FlagsInputIteratorT + * Random-access input iterator type for reading selection flags (NullType* if a selection functor + * or discontinuity flagging is to be used for selection) + * + * @tparam SelectedOutputIteratorT + * Random-access output iterator type for writing selected items + * + * @tparam NumSelectedIteratorT + * Output iterator type for recording the number of items selected + * + * @tparam ScanTileStateT + * Tile status interface type + * + * @tparam SelectOpT + * Selection operator type (NullType if selection flags or discontinuity flagging is + * to be used for selection) + * + * @tparam EqualityOpT + * Equality operator type (NullType if selection functor or selection flags is + * to be used for selection) + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam KEEP_REJECTS + * Whether or not we push rejected items to the back of the output + * + * @param[in] d_in + * Pointer to the input sequence of data items + * + * @param[in] d_flags + * Pointer to the input sequence of selection flags (if applicable) + * + * @param[out] d_selected_out + * Pointer to the output sequence of selected data items + * + * @param[out] d_num_selected_out + * Pointer to the total number of items selected (i.e., length of \p d_selected_out) + * + * @param[in] tile_status + * Tile status interface + * + * @param[in] select_op + * Selection operator + * + * @param[in] equality_op + * Equality operator + * + * @param[in] num_items + * Total number of input items (i.e., length of \p d_in) + * + * @param[in] num_tiles + * Total number of tiles for the entire problem + */ +template +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::SelectIfPolicyT::BLOCK_THREADS)) __global__ + void DeviceSelectSweepKernel(InputIteratorT d_in, + FlagsInputIteratorT d_flags, + SelectedOutputIteratorT d_selected_out, + NumSelectedIteratorT d_num_selected_out, + ScanTileStateT tile_status, + SelectOpT select_op, + EqualityOpT equality_op, + OffsetT num_items, + int num_tiles) +{ + using AgentSelectIfPolicyT = typename ChainedPolicyT::ActivePolicy::SelectIfPolicyT; + + // Thread block type for selecting data from input tiles + using AgentSelectIfT = AgentSelectIf; + + // Shared memory for AgentSelectIf + __shared__ typename AgentSelectIfT::TempStorage temp_storage; + + // Process tiles + AgentSelectIfT(temp_storage, d_in, d_flags, d_selected_out, select_op, equality_op, num_items).ConsumeRange( + num_tiles, + tile_status, + d_num_selected_out); +} + + +/****************************************************************************** + * Dispatch + ******************************************************************************/ + +/** + * Utility class for dispatching the appropriately-tuned kernels for DeviceSelect + * + * @tparam InputIteratorT + * Random-access input iterator type for reading input items + * + * @tparam FlagsInputIteratorT + * Random-access input iterator type for reading selection flags + * (NullType* if a selection functor or discontinuity flagging is to be used for selection) + * + * @tparam SelectedOutputIteratorT + * Random-access output iterator type for writing selected items + * + * @tparam NumSelectedIteratorT + * Output iterator type for recording the number of items selected + * + * @tparam SelectOpT + * Selection operator type (NullType if selection flags or discontinuity flagging is + * to be used for selection) + * + * @tparam EqualityOpT + * Equality operator type (NullType if selection functor or selection flags is to + * be used for selection) + * + * @tparam OffsetT + * Signed integer type for global offsets + * + * @tparam KEEP_REJECTS + * Whether or not we push rejected items to the back of the output + */ +template , + cub::detail::value_t, + OffsetT, + MayAlias, + KEEP_REJECTS>> +struct DispatchSelectIf : SelectedPolicy +{ + /****************************************************************************** + * Types and constants + ******************************************************************************/ + + // Tile status descriptor interface type + using ScanTileStateT = ScanTileState; + + static constexpr int INIT_KERNEL_THREADS = 128; + + /// Device-accessible allocation of temporary storage. + /// When `nullptr`, the required allocation size is written to `temp_storage_bytes` + /// and no work is done. + void* d_temp_storage; + + /// Reference to size in bytes of `d_temp_storage` allocation + size_t& temp_storage_bytes; + + /// Pointer to the input sequence of data items + InputIteratorT d_in; + + /// Pointer to the input sequence of selection flags (if applicable) + FlagsInputIteratorT d_flags; + + /// Pointer to the output sequence of selected data items + SelectedOutputIteratorT d_selected_out; + + /// Pointer to the total number of items selected (i.e., length of `d_selected_out`) + NumSelectedIteratorT d_num_selected_out; + + /// Selection operator + SelectOpT select_op; + + /// Equality operator + EqualityOpT equality_op; + + /// Total number of input items (i.e., length of `d_in`) + OffsetT num_items; + + /// CUDA stream to launch kernels within. Default is stream0. + cudaStream_t stream; + + int ptx_version; + + /** + * @param d_temp_storage + * Device-accessible allocation of temporary storage. + * When `nullptr`, the required allocation size is written to `temp_storage_bytes` + * and no work is done. + * + * @param temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param d_in + * Pointer to the input sequence of data items + * + * @param d_flags + * Pointer to the input sequence of selection flags (if applicable) + * + * @param d_selected_out + * Pointer to the output sequence of selected data items + * + * @param d_num_selected_out + * Pointer to the total number of items selected (i.e., length of `d_selected_out`) + * + * @param select_op + * Selection operator + * + * @param equality_op + * Equality operator + * + * @param num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param stream + * CUDA stream to launch kernels within. Default is stream0. + */ + CUB_RUNTIME_FUNCTION __forceinline__ DispatchSelectIf(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + FlagsInputIteratorT d_flags, + SelectedOutputIteratorT d_selected_out, + NumSelectedIteratorT d_num_selected_out, + SelectOpT select_op, + EqualityOpT equality_op, + OffsetT num_items, + cudaStream_t stream, + int ptx_version) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_in(d_in) + , d_flags(d_flags) + , d_selected_out(d_selected_out) + , d_num_selected_out(d_num_selected_out) + , select_op(select_op) + , equality_op(equality_op) + , num_items(num_items) + , stream(stream) + , ptx_version(ptx_version) + {} + + /****************************************************************************** + * Dispatch entrypoints + ******************************************************************************/ + + /** + * Internal dispatch routine for computing a device-wide selection using the + * specified kernel functions. + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke(ScanInitKernelPtrT scan_init_kernel, + SelectIfKernelPtrT select_if_kernel) + { + cudaError error = cudaSuccess; + + const int block_threads = ActivePolicyT::SelectIfPolicyT::BLOCK_THREADS; + const int items_per_thread = ActivePolicyT::SelectIfPolicyT::ITEMS_PER_THREAD; + const int tile_size = block_threads * items_per_thread; + + do + { + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) + { + break; + } + + // Number of input tiles + int num_tiles = static_cast(cub::DivideAndRoundUp(num_items, tile_size)); + + // Specify temporary storage allocation requirements + size_t allocation_sizes[1]; + + // bytes needed for tile status descriptors + if (CubDebug(error = ScanTileStateT::AllocationSize(num_tiles, allocation_sizes[0]))) + { + break; + } + + // Compute allocation pointers into the single storage blob (or compute the necessary size of the blob) + void* allocations[1] = {}; + if (CubDebug(error = AliasTemporaries(d_temp_storage, temp_storage_bytes, allocations, allocation_sizes))) + { + break; + } + + if (d_temp_storage == nullptr) + { + // Return if the caller is simply requesting the size of the storage allocation + break; + } + + // Construct the tile status interface + ScanTileStateT tile_status; + if (CubDebug(error = tile_status.Init(num_tiles, allocations[0], allocation_sizes[0]))) + { + break; + } + + // Log scan_init_kernel configuration + int init_grid_size = CUB_MAX(1, cub::DivideAndRoundUp(num_tiles, INIT_KERNEL_THREADS)); + + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking scan_init_kernel<<<%d, %d, 0, %lld>>>()\n", init_grid_size, INIT_KERNEL_THREADS, (long long) stream); + #endif + + // Invoke scan_init_kernel to initialize tile descriptors + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + init_grid_size, INIT_KERNEL_THREADS, 0, stream + ).doit(scan_init_kernel, + tile_status, + num_tiles, + d_num_selected_out); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Return if empty problem + if (num_items == 0) + { + break; + } + + // Get max x-dimension of grid + int max_dim_x; + if (CubDebug(error = cudaDeviceGetAttribute(&max_dim_x, cudaDevAttrMaxGridDimX, device_ordinal))) + { + break; + } + + // Get grid size for scanning tiles + dim3 scan_grid_size; + scan_grid_size.z = 1; + scan_grid_size.y = cub::DivideAndRoundUp(num_tiles, max_dim_x); + scan_grid_size.x = CUB_MIN(num_tiles, max_dim_x); + + // Log select_if_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + { + // Get SM occupancy for select_if_kernel + int range_select_sm_occupancy; + if (CubDebug(error = MaxSmOccupancy(range_select_sm_occupancy, // out + select_if_kernel, + block_threads))) + { + break; + } + + _CubLog("Invoking select_if_kernel<<<{%d,%d,%d}, %d, 0, " + "%lld>>>(), %d items per thread, %d SM occupancy\n", + scan_grid_size.x, + scan_grid_size.y, + scan_grid_size.z, + block_threads, + (long long)stream, + items_per_thread, + range_select_sm_occupancy); + } + #endif + + // Invoke select_if_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + scan_grid_size, block_threads, 0, stream + ).doit(select_if_kernel, + d_in, + d_flags, + d_selected_out, + d_num_selected_out, + tile_status, + select_op, + equality_op, + num_items, + num_tiles); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } + while (0); + + return error; + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t Invoke() + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + + return Invoke(DeviceCompactInitKernel, + DeviceSelectSweepKernel); + } + + /** + * Internal dispatch routine + * + * @param d_temp_storage + * Device-accessible allocation of temporary storage. + * When `nullptr`, the required allocation size is written to `temp_storage_bytes` + * and no work is done. + * + * @param temp_storage_bytes + * Reference to size in bytes of `d_temp_storage` allocation + * + * @param d_in + * Pointer to the input sequence of data items + * + * @param d_flags + * Pointer to the input sequence of selection flags (if applicable) + * + * @param d_selected_out + * Pointer to the output sequence of selected data items + * + * @param d_num_selected_out + * Pointer to the total number of items selected (i.e., length of `d_selected_out`) + * + * @param select_op + * Selection operator + * + * @param equality_op + * Equality operator + * + * @param num_items + * Total number of input items (i.e., length of `d_in`) + * + * @param stream + * CUDA stream to launch kernels within. Default is stream0. + */ + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + InputIteratorT d_in, + FlagsInputIteratorT d_flags, + SelectedOutputIteratorT d_selected_out, + NumSelectedIteratorT d_num_selected_out, + SelectOpT select_op, + EqualityOpT equality_op, + OffsetT num_items, + cudaStream_t stream) + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + + int ptx_version = 0; + if (cudaError_t error = CubDebug(PtxVersion(ptx_version))) + { + return error; + } + + DispatchSelectIf dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_flags, + d_selected_out, + d_num_selected_out, + select_op, + equality_op, + num_items, + stream, + ptx_version); + + return CubDebug(MaxPolicyT::Invoke(ptx_version, dispatch)); + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ + static cudaError_t Dispatch( + void* d_temp_storage, + size_t& temp_storage_bytes, + InputIteratorT d_in, + FlagsInputIteratorT d_flags, + SelectedOutputIteratorT d_selected_out, + NumSelectedIteratorT d_num_selected_out, + SelectOpT select_op, + EqualityOpT equality_op, + OffsetT num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_flags, + d_selected_out, + d_num_selected_out, + select_op, + equality_op, + num_items, + stream); + } +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_spmv_orig.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_spmv_orig.cuh new file mode 100644 index 0000000000000000000000000000000000000000..c38c4bfb48896056b0550452b17f72bd94ca3ee3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_spmv_orig.cuh @@ -0,0 +1,875 @@ + +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::DeviceSpmv provides device-wide parallel operations for performing sparse-matrix * vector multiplication (SpMV). + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + + +/****************************************************************************** + * SpMV kernel entry points + *****************************************************************************/ + +/** + * Spmv search kernel. Identifies merge path starting coordinates for each tile. + */ +template < + typename AgentSpmvPolicyT, ///< Parameterized SpmvPolicy tuning policy type + typename ValueT, ///< Matrix and vector value type + typename OffsetT> ///< Signed integer type for sequence offsets +__global__ void DeviceSpmv1ColKernel( + SpmvParams spmv_params) ///< [in] SpMV input parameter bundle +{ + typedef CacheModifiedInputIterator< + AgentSpmvPolicyT::VECTOR_VALUES_LOAD_MODIFIER, + ValueT, + OffsetT> + VectorValueIteratorT; + + VectorValueIteratorT wrapped_vector_x(spmv_params.d_vector_x); + + int row_idx = (blockIdx.x * blockDim.x) + threadIdx.x; + if (row_idx < spmv_params.num_rows) + { + OffsetT end_nonzero_idx = spmv_params.d_row_end_offsets[row_idx]; + OffsetT nonzero_idx = spmv_params.d_row_end_offsets[row_idx - 1]; + + ValueT value = 0.0; + if (end_nonzero_idx != nonzero_idx) + { + value = spmv_params.d_values[nonzero_idx] * wrapped_vector_x[spmv_params.d_column_indices[nonzero_idx]]; + } + + spmv_params.d_vector_y[row_idx] = value; + } +} + + +/** + * Spmv search kernel. Identifies merge path starting coordinates for each tile. + */ +template < + typename SpmvPolicyT, ///< Parameterized SpmvPolicy tuning policy type + typename OffsetT, ///< Signed integer type for sequence offsets + typename CoordinateT, ///< Merge path coordinate type + typename SpmvParamsT> ///< SpmvParams type +__global__ void DeviceSpmvSearchKernel( + int num_merge_tiles, ///< [in] Number of SpMV merge tiles (spmv grid size) + CoordinateT* d_tile_coordinates, ///< [out] Pointer to the temporary array of tile starting coordinates + SpmvParamsT spmv_params) ///< [in] SpMV input parameter bundle +{ + /// Constants + enum + { + BLOCK_THREADS = SpmvPolicyT::BLOCK_THREADS, + ITEMS_PER_THREAD = SpmvPolicyT::ITEMS_PER_THREAD, + TILE_ITEMS = BLOCK_THREADS * ITEMS_PER_THREAD, + }; + + typedef CacheModifiedInputIterator< + SpmvPolicyT::ROW_OFFSETS_SEARCH_LOAD_MODIFIER, + OffsetT, + OffsetT> + RowOffsetsSearchIteratorT; + + // Find the starting coordinate for all tiles (plus the end coordinate of the last one) + int tile_idx = (blockIdx.x * blockDim.x) + threadIdx.x; + if (tile_idx < num_merge_tiles + 1) + { + OffsetT diagonal = (tile_idx * TILE_ITEMS); + CoordinateT tile_coordinate; + CountingInputIterator nonzero_indices(0); + + // Search the merge path + MergePathSearch( + diagonal, + RowOffsetsSearchIteratorT(spmv_params.d_row_end_offsets), + nonzero_indices, + spmv_params.num_rows, + spmv_params.num_nonzeros, + tile_coordinate); + + // Output starting offset + d_tile_coordinates[tile_idx] = tile_coordinate; + } +} + + +/** + * Spmv agent entry point + */ +template < + typename SpmvPolicyT, ///< Parameterized SpmvPolicy tuning policy type + typename ScanTileStateT, ///< Tile status interface type + typename ValueT, ///< Matrix and vector value type + typename OffsetT, ///< Signed integer type for sequence offsets + typename CoordinateT, ///< Merge path coordinate type + bool HAS_ALPHA, ///< Whether the input parameter Alpha is 1 + bool HAS_BETA> ///< Whether the input parameter Beta is 0 +__launch_bounds__ (int(SpmvPolicyT::BLOCK_THREADS)) +__global__ void DeviceSpmvKernel( + SpmvParams spmv_params, ///< [in] SpMV input parameter bundle + CoordinateT* d_tile_coordinates, ///< [in] Pointer to the temporary array of tile starting coordinates + KeyValuePair* d_tile_carry_pairs, ///< [out] Pointer to the temporary array carry-out dot product row-ids, one per block + int num_tiles, ///< [in] Number of merge tiles + ScanTileStateT tile_state, ///< [in] Tile status interface for fixup reduce-by-key kernel + int num_segment_fixup_tiles) ///< [in] Number of reduce-by-key tiles (fixup grid size) +{ + // Spmv agent type specialization + typedef AgentSpmv< + SpmvPolicyT, + ValueT, + OffsetT, + HAS_ALPHA, + HAS_BETA> + AgentSpmvT; + + // Shared memory for AgentSpmv + __shared__ typename AgentSpmvT::TempStorage temp_storage; + + AgentSpmvT(temp_storage, spmv_params).ConsumeTile( + d_tile_coordinates, + d_tile_carry_pairs, + num_tiles); + + // Initialize fixup tile status + tile_state.InitializeStatus(num_segment_fixup_tiles); + +} + +template ///< Whether the input parameter Beta is 0 +__global__ void DeviceSpmvEmptyMatrixKernel(SpmvParams spmv_params) +{ + const int row = static_cast(threadIdx.x + blockIdx.x * blockDim.x); + + if (row < spmv_params.num_rows) + { + ValueT result = 0.0; + + CUB_IF_CONSTEXPR(HAS_BETA) + { + result += spmv_params.beta * spmv_params.d_vector_y[row]; + } + + spmv_params.d_vector_y[row] = result; + } +} + +/** + * Multi-block reduce-by-key sweep kernel entry point + */ +template < + typename AgentSegmentFixupPolicyT, ///< Parameterized AgentSegmentFixupPolicy tuning policy type + typename PairsInputIteratorT, ///< Random-access input iterator type for keys + typename AggregatesOutputIteratorT, ///< Random-access output iterator type for values + typename OffsetT, ///< Signed integer type for global offsets + typename ScanTileStateT> ///< Tile status interface type +__launch_bounds__ (int(AgentSegmentFixupPolicyT::BLOCK_THREADS)) +__global__ void DeviceSegmentFixupKernel( + PairsInputIteratorT d_pairs_in, ///< [in] Pointer to the array carry-out dot product row-ids, one per spmv block + AggregatesOutputIteratorT d_aggregates_out, ///< [in,out] Output value aggregates + OffsetT num_items, ///< [in] Total number of items to select from + int num_tiles, ///< [in] Total number of tiles for the entire problem + ScanTileStateT tile_state) ///< [in] Tile status interface +{ + // Thread block type for reducing tiles of value segments + typedef AgentSegmentFixup< + AgentSegmentFixupPolicyT, + PairsInputIteratorT, + AggregatesOutputIteratorT, + cub::Equality, + cub::Sum, + OffsetT> + AgentSegmentFixupT; + + // Shared memory for AgentSegmentFixup + __shared__ typename AgentSegmentFixupT::TempStorage temp_storage; + + // Process tiles + AgentSegmentFixupT(temp_storage, d_pairs_in, d_aggregates_out, cub::Equality(), cub::Sum()).ConsumeRange( + num_items, + num_tiles, + tile_state); +} + + +/****************************************************************************** + * Dispatch + ******************************************************************************/ + +/** + * Utility class for dispatching the appropriately-tuned kernels for DeviceSpmv + */ +template < + typename ValueT, ///< Matrix and vector value type + typename OffsetT> ///< Signed integer type for global offsets +struct DispatchSpmv +{ + //--------------------------------------------------------------------- + // Constants and Types + //--------------------------------------------------------------------- + + enum + { + INIT_KERNEL_THREADS = 128, + EMPTY_MATRIX_KERNEL_THREADS = 128 + }; + + // SpmvParams bundle type + typedef SpmvParams SpmvParamsT; + + // 2D merge path coordinate type + typedef typename CubVector::Type CoordinateT; + + // Tile status descriptor interface type + typedef ReduceByKeyScanTileState ScanTileStateT; + + // Tuple type for scanning (pairs accumulated segment-value with segment-index) + typedef KeyValuePair KeyValuePairT; + + + //--------------------------------------------------------------------- + // Tuning policies + //--------------------------------------------------------------------- + + /// SM35 + struct Policy350 + { + typedef AgentSpmvPolicy< + (sizeof(ValueT) > 4) ? 96 : 128, + (sizeof(ValueT) > 4) ? 4 : 7, + LOAD_LDG, + LOAD_CA, + LOAD_LDG, + LOAD_LDG, + LOAD_LDG, + (sizeof(ValueT) > 4) ? true : false, + BLOCK_SCAN_WARP_SCANS> + SpmvPolicyT; + + typedef AgentSegmentFixupPolicy< + 128, + 3, + BLOCK_LOAD_VECTORIZE, + LOAD_LDG, + BLOCK_SCAN_WARP_SCANS> + SegmentFixupPolicyT; + }; + + + /// SM37 + struct Policy370 + { + + typedef AgentSpmvPolicy< + (sizeof(ValueT) > 4) ? 128 : 128, + (sizeof(ValueT) > 4) ? 9 : 14, + LOAD_LDG, + LOAD_CA, + LOAD_LDG, + LOAD_LDG, + LOAD_LDG, + false, + BLOCK_SCAN_WARP_SCANS> + SpmvPolicyT; + + typedef AgentSegmentFixupPolicy< + 128, + 3, + BLOCK_LOAD_VECTORIZE, + LOAD_LDG, + BLOCK_SCAN_WARP_SCANS> + SegmentFixupPolicyT; + }; + + /// SM50 + struct Policy500 + { + typedef AgentSpmvPolicy< + (sizeof(ValueT) > 4) ? 64 : 128, + (sizeof(ValueT) > 4) ? 6 : 7, + LOAD_LDG, + LOAD_DEFAULT, + (sizeof(ValueT) > 4) ? LOAD_LDG : LOAD_DEFAULT, + (sizeof(ValueT) > 4) ? LOAD_LDG : LOAD_DEFAULT, + LOAD_LDG, + (sizeof(ValueT) > 4) ? true : false, + (sizeof(ValueT) > 4) ? BLOCK_SCAN_WARP_SCANS : BLOCK_SCAN_RAKING_MEMOIZE> + SpmvPolicyT; + + + typedef AgentSegmentFixupPolicy< + 128, + 3, + BLOCK_LOAD_VECTORIZE, + LOAD_LDG, + BLOCK_SCAN_RAKING_MEMOIZE> + SegmentFixupPolicyT; + }; + + + /// SM60 + struct Policy600 + { + typedef AgentSpmvPolicy< + (sizeof(ValueT) > 4) ? 64 : 128, + (sizeof(ValueT) > 4) ? 5 : 7, + LOAD_DEFAULT, + LOAD_DEFAULT, + LOAD_DEFAULT, + LOAD_DEFAULT, + LOAD_DEFAULT, + false, + BLOCK_SCAN_WARP_SCANS> + SpmvPolicyT; + + + typedef AgentSegmentFixupPolicy< + 128, + 3, + BLOCK_LOAD_DIRECT, + LOAD_LDG, + BLOCK_SCAN_WARP_SCANS> + SegmentFixupPolicyT; + }; + + + + //--------------------------------------------------------------------- + // Tuning policies of current PTX compiler pass + //--------------------------------------------------------------------- + +#if (CUB_PTX_ARCH >= 600) + typedef Policy600 PtxPolicy; + +#elif (CUB_PTX_ARCH >= 500) + typedef Policy500 PtxPolicy; + +#elif (CUB_PTX_ARCH >= 370) + typedef Policy370 PtxPolicy; + +#else + typedef Policy350 PtxPolicy; + +#endif + + // "Opaque" policies (whose parameterizations aren't reflected in the type signature) + struct PtxSpmvPolicyT : PtxPolicy::SpmvPolicyT {}; + struct PtxSegmentFixupPolicy : PtxPolicy::SegmentFixupPolicyT {}; + + + //--------------------------------------------------------------------- + // Utilities + //--------------------------------------------------------------------- + + /** + * Initialize kernel dispatch configurations with the policies corresponding to the PTX assembly we will use + */ + template + CUB_RUNTIME_FUNCTION __forceinline__ + static void InitConfigs( + int ptx_version, + KernelConfig &spmv_config, + KernelConfig &segment_fixup_config) + { + NV_IF_TARGET( + NV_IS_DEVICE, + ( // We're on the device, so initialize the kernel dispatch + // configurations with the current PTX policy + spmv_config.template Init(); + segment_fixup_config.template Init();), + ( + // We're on the host, so lookup and initialize the kernel dispatch + // configurations with the policies that match the device's PTX + // version + if (ptx_version >= 600) { + spmv_config.template Init(); + segment_fixup_config + .template Init(); + } else if (ptx_version >= 500) { + spmv_config.template Init(); + segment_fixup_config + .template Init(); + } else if (ptx_version >= 370) { + spmv_config.template Init(); + segment_fixup_config + .template Init(); + } else { + spmv_config.template Init(); + segment_fixup_config + .template Init(); + })); + } + + + /** + * Kernel kernel dispatch configuration. + */ + struct KernelConfig + { + int block_threads; + int items_per_thread; + int tile_items; + + template + CUB_RUNTIME_FUNCTION __forceinline__ + void Init() + { + block_threads = PolicyT::BLOCK_THREADS; + items_per_thread = PolicyT::ITEMS_PER_THREAD; + tile_items = block_threads * items_per_thread; + } + }; + + + //--------------------------------------------------------------------- + // Dispatch entrypoints + //--------------------------------------------------------------------- + + /** + * Internal dispatch routine for computing a device-wide reduction using the + * specified kernel functions. + * + * If the input is larger than a single tile, this method uses two-passes of + * kernel invocations. + */ + template < + typename Spmv1ColKernelT, ///< Function type of cub::DeviceSpmv1ColKernel + typename SpmvSearchKernelT, ///< Function type of cub::AgentSpmvSearchKernel + typename SpmvKernelT, ///< Function type of cub::AgentSpmvKernel + typename SegmentFixupKernelT, ///< Function type of cub::DeviceSegmentFixupKernelT + typename SpmvEmptyMatrixKernelT> ///< Function type of cub::DeviceSpmvEmptyMatrixKernel + CUB_RUNTIME_FUNCTION __forceinline__ + static cudaError_t Dispatch( + void* d_temp_storage, ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t& temp_storage_bytes, ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation + SpmvParamsT& spmv_params, ///< SpMV input parameter bundle + cudaStream_t stream, ///< [in] CUDA stream to launch kernels within. Default is stream0. + Spmv1ColKernelT spmv_1col_kernel, ///< [in] Kernel function pointer to parameterization of DeviceSpmv1ColKernel + SpmvSearchKernelT spmv_search_kernel, ///< [in] Kernel function pointer to parameterization of AgentSpmvSearchKernel + SpmvKernelT spmv_kernel, ///< [in] Kernel function pointer to parameterization of AgentSpmvKernel + SegmentFixupKernelT segment_fixup_kernel, ///< [in] Kernel function pointer to parameterization of cub::DeviceSegmentFixupKernel + SpmvEmptyMatrixKernelT spmv_empty_matrix_kernel, ///< [in] Kernel function pointer to parameterization of cub::DeviceSpmvEmptyMatrixKernel + KernelConfig spmv_config, ///< [in] Dispatch parameters that match the policy that \p spmv_kernel was compiled for + KernelConfig segment_fixup_config) ///< [in] Dispatch parameters that match the policy that \p segment_fixup_kernel was compiled for + { + cudaError error = cudaSuccess; + do + { + if (spmv_params.num_rows < 0 || spmv_params.num_cols < 0) + { + return cudaErrorInvalidValue; + } + + if (spmv_params.num_rows == 0 || spmv_params.num_cols == 0) + { // Empty problem, no-op. + if (d_temp_storage == NULL) + { + temp_storage_bytes = 1; + } + + break; + } + + if (spmv_params.num_nonzeros == 0) + { + if (d_temp_storage == NULL) + { + // Return if the caller is simply requesting the size of the storage allocation + temp_storage_bytes = 1; + break; + } + + const int threads_in_block = EMPTY_MATRIX_KERNEL_THREADS; + const int blocks_in_grid = cub::DivideAndRoundUp(spmv_params.num_rows, + threads_in_block); + + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking spmv_empty_matrix_kernel<<<%d, %d, 0, %lld>>>()\n", + blocks_in_grid, + threads_in_block, + (long long)stream); + #endif + error = THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(blocks_in_grid, + threads_in_block, + 0, + stream) + .doit(spmv_empty_matrix_kernel, spmv_params); + + if (CubDebug(error)) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + break; + } + + if (spmv_params.num_cols == 1) + { + if (d_temp_storage == NULL) + { + // Return if the caller is simply requesting the size of the storage allocation + temp_storage_bytes = 1; + break; + } + + // Get search/init grid dims + int degen_col_kernel_block_size = INIT_KERNEL_THREADS; + int degen_col_kernel_grid_size = cub::DivideAndRoundUp(spmv_params.num_rows, degen_col_kernel_block_size); + + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking spmv_1col_kernel<<<%d, %d, 0, %lld>>>()\n", + degen_col_kernel_grid_size, degen_col_kernel_block_size, (long long) stream); + #endif + + // Invoke spmv_search_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + degen_col_kernel_grid_size, degen_col_kernel_block_size, 0, + stream + ).doit(spmv_1col_kernel, + spmv_params); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + break; + } + + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) break; + + // Get SM count + int sm_count; + if (CubDebug(error = cudaDeviceGetAttribute (&sm_count, cudaDevAttrMultiProcessorCount, device_ordinal))) break; + + // Get max x-dimension of grid + int max_dim_x; + if (CubDebug(error = cudaDeviceGetAttribute(&max_dim_x, cudaDevAttrMaxGridDimX, device_ordinal))) break; + + // Total number of spmv work items + int num_merge_items = spmv_params.num_rows + spmv_params.num_nonzeros; + + // Tile sizes of kernels + int merge_tile_size = spmv_config.block_threads * spmv_config.items_per_thread; + int segment_fixup_tile_size = segment_fixup_config.block_threads * segment_fixup_config.items_per_thread; + + // Number of tiles for kernels + int num_merge_tiles = cub::DivideAndRoundUp(num_merge_items, merge_tile_size); + int num_segment_fixup_tiles = cub::DivideAndRoundUp(num_merge_tiles, segment_fixup_tile_size); + + // Get SM occupancy for kernels + int spmv_sm_occupancy; + if (CubDebug(error = MaxSmOccupancy( + spmv_sm_occupancy, + spmv_kernel, + spmv_config.block_threads))) break; + + int segment_fixup_sm_occupancy; + if (CubDebug(error = MaxSmOccupancy( + segment_fixup_sm_occupancy, + segment_fixup_kernel, + segment_fixup_config.block_threads))) break; + + // Get grid dimensions + dim3 spmv_grid_size( + CUB_MIN(num_merge_tiles, max_dim_x), + cub::DivideAndRoundUp(num_merge_tiles, max_dim_x), + 1); + + dim3 segment_fixup_grid_size( + CUB_MIN(num_segment_fixup_tiles, max_dim_x), + cub::DivideAndRoundUp(num_segment_fixup_tiles, max_dim_x), + 1); + + // Get the temporary storage allocation requirements + size_t allocation_sizes[3]; + if (CubDebug(error = ScanTileStateT::AllocationSize(num_segment_fixup_tiles, allocation_sizes[0]))) break; // bytes needed for reduce-by-key tile status descriptors + allocation_sizes[1] = num_merge_tiles * sizeof(KeyValuePairT); // bytes needed for block carry-out pairs + allocation_sizes[2] = (num_merge_tiles + 1) * sizeof(CoordinateT); // bytes needed for tile starting coordinates + + // Alias the temporary allocations from the single storage blob (or compute the necessary size of the blob) + void* allocations[3] = {}; + if (CubDebug(error = AliasTemporaries(d_temp_storage, temp_storage_bytes, allocations, allocation_sizes))) break; + if (d_temp_storage == NULL) + { + // Return if the caller is simply requesting the size of the storage allocation + break; + } + + // Construct the tile status interface + ScanTileStateT tile_state; + if (CubDebug(error = tile_state.Init(num_segment_fixup_tiles, allocations[0], allocation_sizes[0]))) break; + + // Alias the other allocations + KeyValuePairT* d_tile_carry_pairs = (KeyValuePairT*) allocations[1]; // Agent carry-out pairs + CoordinateT* d_tile_coordinates = (CoordinateT*) allocations[2]; // Agent starting coordinates + + // Get search/init grid dims + int search_block_size = INIT_KERNEL_THREADS; + int search_grid_size = cub::DivideAndRoundUp(num_merge_tiles + 1, search_block_size); + + if (search_grid_size < sm_count) +// if (num_merge_tiles < spmv_sm_occupancy * sm_count) + { + // Not enough spmv tiles to saturate the device: have spmv blocks search their own staring coords + d_tile_coordinates = NULL; + } + else + { + // Use separate search kernel if we have enough spmv tiles to saturate the device + + // Log spmv_search_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking spmv_search_kernel<<<%d, %d, 0, %lld>>>()\n", + search_grid_size, search_block_size, (long long) stream); + #endif + + // Invoke spmv_search_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + search_grid_size, search_block_size, 0, stream + ).doit(spmv_search_kernel, + num_merge_tiles, + d_tile_coordinates, + spmv_params); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) break; + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } + + // Log spmv_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking spmv_kernel<<<{%d,%d,%d}, %d, 0, %lld>>>(), %d items per thread, %d SM occupancy\n", + spmv_grid_size.x, spmv_grid_size.y, spmv_grid_size.z, spmv_config.block_threads, (long long) stream, spmv_config.items_per_thread, spmv_sm_occupancy); + #endif + + // Invoke spmv_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + spmv_grid_size, spmv_config.block_threads, 0, stream + ).doit(spmv_kernel, + spmv_params, + d_tile_coordinates, + d_tile_carry_pairs, + num_merge_tiles, + tile_state, + num_segment_fixup_tiles); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) break; + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Run reduce-by-key fixup if necessary + if (num_merge_tiles > 1) + { + // Log segment_fixup_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking segment_fixup_kernel<<<{%d,%d,%d}, %d, 0, %lld>>>(), %d items per thread, %d SM occupancy\n", + segment_fixup_grid_size.x, segment_fixup_grid_size.y, segment_fixup_grid_size.z, segment_fixup_config.block_threads, (long long) stream, segment_fixup_config.items_per_thread, segment_fixup_sm_occupancy); + #endif + + // Invoke segment_fixup_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + segment_fixup_grid_size, segment_fixup_config.block_threads, + 0, stream + ).doit(segment_fixup_kernel, + d_tile_carry_pairs, + spmv_params.d_vector_y, + num_merge_tiles, + num_segment_fixup_tiles, + tile_state); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) break; + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } + } + while (0); + + return error; + } + + template + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + SpmvParamsT &spmv_params, + cudaStream_t stream, + bool debug_synchronous, + Spmv1ColKernelT spmv_1col_kernel, + SpmvSearchKernelT spmv_search_kernel, + SpmvKernelT spmv_kernel, + SegmentFixupKernelT segment_fixup_kernel, + SpmvEmptyMatrixKernelT spmv_empty_matrix_kernel, + KernelConfig spmv_config, + KernelConfig segment_fixup_config) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + spmv_params, + stream, + spmv_1col_kernel, + spmv_search_kernel, + spmv_kernel, + segment_fixup_kernel, + spmv_empty_matrix_kernel, + spmv_config, + segment_fixup_config); + } + + /** + * Internal dispatch routine for computing a device-wide reduction + */ + CUB_RUNTIME_FUNCTION __forceinline__ + static cudaError_t Dispatch( + void* d_temp_storage, ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t& temp_storage_bytes, ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation + SpmvParamsT& spmv_params, ///< SpMV input parameter bundle + cudaStream_t stream = 0) ///< [in] [optional] CUDA stream to launch kernels within. Default is stream0. + { + cudaError error = cudaSuccess; + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) break; + + // Get kernel kernel dispatch configurations + KernelConfig spmv_config, segment_fixup_config; + InitConfigs(ptx_version, spmv_config, segment_fixup_config); + + constexpr bool has_alpha = false; + constexpr bool has_beta = false; + + if (CubDebug(error = Dispatch( + d_temp_storage, temp_storage_bytes, spmv_params, stream, + DeviceSpmv1ColKernel, + DeviceSpmvSearchKernel, + DeviceSpmvKernel, + DeviceSegmentFixupKernel, + DeviceSpmvEmptyMatrixKernel, + spmv_config, segment_fixup_config))) break; + + } + while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + size_t &temp_storage_bytes, + SpmvParamsT &spmv_params, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, temp_storage_bytes, spmv_params, stream); + } +}; + + +CUB_NAMESPACE_END + + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_three_way_partition.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_three_way_partition.cuh new file mode 100644 index 0000000000000000000000000000000000000000..ed22bc86b121b42db5dc0fee72e4e131fa432a48 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_three_way_partition.cuh @@ -0,0 +1,480 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Kernel entry points + *****************************************************************************/ + +template +__launch_bounds__(int(ChainedPolicyT::ActivePolicy::ThreeWayPartitionPolicy::BLOCK_THREADS)) __global__ + void DeviceThreeWayPartitionKernel(InputIteratorT d_in, + FirstOutputIteratorT d_first_part_out, + SecondOutputIteratorT d_second_part_out, + UnselectedOutputIteratorT d_unselected_out, + NumSelectedIteratorT d_num_selected_out, + ScanTileStateT tile_status, + SelectFirstPartOp select_first_part_op, + SelectSecondPartOp select_second_part_op, + OffsetT num_items, + int num_tiles) +{ + using AgentThreeWayPartitionPolicyT = + typename ChainedPolicyT::ActivePolicy::ThreeWayPartitionPolicy; + + // Thread block type for selecting data from input tiles + using AgentThreeWayPartitionT = AgentThreeWayPartition; + + // Shared memory for AgentThreeWayPartition + __shared__ typename AgentThreeWayPartitionT::TempStorage temp_storage; + + // Process tiles + AgentThreeWayPartitionT(temp_storage, + d_in, + d_first_part_out, + d_second_part_out, + d_unselected_out, + select_first_part_op, + select_second_part_op, + num_items) + .ConsumeRange(num_tiles, tile_status, d_num_selected_out); +} + +/** + * @brief Initialization kernel for tile status initialization (multi-block) + * + * @tparam ScanTileStateT + * Tile status interface type + * + * @tparam NumSelectedIteratorT + * Output iterator type for recording the number of items selected + * + * @param[in] tile_state_1 + * Tile status interface + * + * @param[in] tile_state_2 + * Tile status interface + * + * @param[in] num_tiles + * Number of tiles + * + * @param[out] d_num_selected_out + * Pointer to the total number of items selected + * (i.e., length of @p d_selected_out) + */ +template +__global__ void DeviceThreeWayPartitionInitKernel(ScanTileStateT tile_state, + int num_tiles, + NumSelectedIteratorT d_num_selected_out) +{ + // Initialize tile status + tile_state.InitializeStatus(num_tiles); + + // Initialize d_num_selected_out + if (blockIdx.x == 0) + { + if (threadIdx.x < 2) + { + d_num_selected_out[threadIdx.x] = 0; + } + } +} + +/****************************************************************************** + * Dispatch + ******************************************************************************/ + +template < + typename InputIteratorT, + typename FirstOutputIteratorT, + typename SecondOutputIteratorT, + typename UnselectedOutputIteratorT, + typename NumSelectedIteratorT, + typename SelectFirstPartOp, + typename SelectSecondPartOp, + typename OffsetT, + typename SelectedPolicy = + detail::device_three_way_partition_policy_hub, OffsetT>> +struct DispatchThreeWayPartitionIf +{ + /***************************************************************************** + * Types and constants + ****************************************************************************/ + + using AccumPackHelperT = detail::three_way_partition::accumulator_pack_t; + using AccumPackT = typename AccumPackHelperT::pack_t; + using ScanTileStateT = cub::ScanTileState; + + constexpr static int INIT_KERNEL_THREADS = 256; + + void *d_temp_storage; + std::size_t &temp_storage_bytes; + InputIteratorT d_in; + FirstOutputIteratorT d_first_part_out; + SecondOutputIteratorT d_second_part_out; + UnselectedOutputIteratorT d_unselected_out; + NumSelectedIteratorT d_num_selected_out; + SelectFirstPartOp select_first_part_op; + SelectSecondPartOp select_second_part_op; + OffsetT num_items; + cudaStream_t stream; + + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchThreeWayPartitionIf(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_in, + FirstOutputIteratorT d_first_part_out, + SecondOutputIteratorT d_second_part_out, + UnselectedOutputIteratorT d_unselected_out, + NumSelectedIteratorT d_num_selected_out, + SelectFirstPartOp select_first_part_op, + SelectSecondPartOp select_second_part_op, + OffsetT num_items, + cudaStream_t stream) + : d_temp_storage(d_temp_storage) + , temp_storage_bytes(temp_storage_bytes) + , d_in(d_in) + , d_first_part_out(d_first_part_out) + , d_second_part_out(d_second_part_out) + , d_unselected_out(d_unselected_out) + , d_num_selected_out(d_num_selected_out) + , select_first_part_op(select_first_part_op) + , select_second_part_op(select_second_part_op) + , num_items(num_items) + , stream(stream) + {} + + /***************************************************************************** + * Dispatch entrypoints + ****************************************************************************/ + + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t + Invoke(ScanInitKernelPtrT three_way_partition_init_kernel, + SelectIfKernelPtrT three_way_partition_kernel) + { + cudaError error = cudaSuccess; + + const int block_threads = ActivePolicyT::ThreeWayPartitionPolicy::BLOCK_THREADS; + const int items_per_thread = ActivePolicyT::ThreeWayPartitionPolicy::ITEMS_PER_THREAD; + + do + { + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) + { + break; + } + + // Number of input tiles + int tile_size = block_threads * items_per_thread; + int num_tiles = static_cast(DivideAndRoundUp(num_items, tile_size)); + + // Specify temporary storage allocation requirements + size_t allocation_sizes[1]; // bytes needed for tile status descriptors + + if (CubDebug(error = ScanTileStateT::AllocationSize(num_tiles, allocation_sizes[0]))) + { + break; + } + + // Compute allocation pointers into the single storage blob (or compute + // the necessary size of the blob) + void *allocations[1] = {}; + if (CubDebug(error = cub::AliasTemporaries(d_temp_storage, + temp_storage_bytes, + allocations, + allocation_sizes))) + { + break; + } + + if (d_temp_storage == nullptr) + { + // Return if the caller is simply requesting the size of the storage + // allocation + break; + } + + // Return if empty problem + if (num_items == 0) + { + break; + } + + // Construct the tile status interface + ScanTileStateT tile_status; + + if (CubDebug(error = tile_status.Init(num_tiles, allocations[0], allocation_sizes[0]))) + { + break; + } + + // Log three_way_partition_init_kernel configuration + int init_grid_size = CUB_MAX(1, DivideAndRoundUp(num_tiles, INIT_KERNEL_THREADS)); + +#ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking three_way_partition_init_kernel<<<%d, %d, 0, %lld>>>()\n", + init_grid_size, + INIT_KERNEL_THREADS, + reinterpret_cast(stream)); +#endif + + // Invoke three_way_partition_init_kernel to initialize tile descriptors + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron(init_grid_size, + INIT_KERNEL_THREADS, + 0, + stream) + .doit(three_way_partition_init_kernel, + tile_status, + num_tiles, + d_num_selected_out); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Get max x-dimension of grid + int max_dim_x; + if (CubDebug( + error = cudaDeviceGetAttribute(&max_dim_x, cudaDevAttrMaxGridDimX, device_ordinal))) + { + break; + } + + // Get grid size for scanning tiles + dim3 scan_grid_size; + scan_grid_size.z = 1; + scan_grid_size.y = DivideAndRoundUp(num_tiles, max_dim_x); + scan_grid_size.x = CUB_MIN(num_tiles, max_dim_x); + +// Log select_if_kernel configuration +#ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + { + // Get SM occupancy for select_if_kernel + int range_select_sm_occupancy; + if (CubDebug(error = MaxSmOccupancy(range_select_sm_occupancy, // out + three_way_partition_kernel, + block_threads))) + { + break; + } + + _CubLog("Invoking three_way_partition_kernel<<<{%d,%d,%d}, %d, 0, %lld>>>(), %d " + "items per thread, %d SM occupancy\n", + scan_grid_size.x, + scan_grid_size.y, + scan_grid_size.z, + block_threads, + reinterpret_cast(stream), + items_per_thread, + range_select_sm_occupancy); + } +#endif + + // Invoke select_if_kernel + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + scan_grid_size, + block_threads, + 0, + stream) + .doit(three_way_partition_kernel, + d_in, + d_first_part_out, + d_second_part_out, + d_unselected_out, + d_num_selected_out, + tile_status, + select_first_part_op, + select_second_part_op, + num_items, + num_tiles); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } while (0); + + return error; + } + + template + CUB_RUNTIME_FUNCTION __forceinline__ cudaError_t + Invoke() + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + return Invoke( + DeviceThreeWayPartitionInitKernel, + DeviceThreeWayPartitionKernel); + } + + /** + * Internal dispatch routine + */ + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_in, + FirstOutputIteratorT d_first_part_out, + SecondOutputIteratorT d_second_part_out, + UnselectedOutputIteratorT d_unselected_out, + NumSelectedIteratorT d_num_selected_out, + SelectFirstPartOp select_first_part_op, + SelectSecondPartOp select_second_part_op, + OffsetT num_items, + cudaStream_t stream) + { + using MaxPolicyT = typename SelectedPolicy::MaxPolicy; + + cudaError error = cudaSuccess; + + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = cub::PtxVersion(ptx_version))) + { + break; + } + + DispatchThreeWayPartitionIf dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_first_part_out, + d_second_part_out, + d_unselected_out, + d_num_selected_out, + select_first_part_op, + select_second_part_op, + num_items, + stream); + + // Dispatch + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) + { + break; + } + } while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ static cudaError_t + Dispatch(void *d_temp_storage, + std::size_t &temp_storage_bytes, + InputIteratorT d_in, + FirstOutputIteratorT d_first_part_out, + SecondOutputIteratorT d_second_part_out, + UnselectedOutputIteratorT d_unselected_out, + NumSelectedIteratorT d_num_selected_out, + SelectFirstPartOp select_first_part_op, + SelectSecondPartOp select_second_part_op, + OffsetT num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_in, + d_first_part_out, + d_second_part_out, + d_unselected_out, + d_num_selected_out, + select_first_part_op, + select_second_part_op, + num_items, + stream); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_unique_by_key.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_unique_by_key.cuh new file mode 100644 index 0000000000000000000000000000000000000000..07aeb59526fde1ff703431341f055f9896f72f24 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/dispatch_unique_by_key.cuh @@ -0,0 +1,444 @@ + +/****************************************************************************** + * Copyright (c) NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::DeviceSelect::UniqueByKey provides device-wide, parallel operations for selecting unique items by key from sequences of data items residing within device-accessible memory. + */ + +#include +#include +#include +#include +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +/****************************************************************************** + * Kernel entry points + *****************************************************************************/ + +/** + * Unique by key kernel entry point (multi-block) + */ +template < + typename ChainedPolicyT, + typename KeyInputIteratorT, ///< Random-access input iterator type for keys + typename ValueInputIteratorT, ///< Random-access input iterator type for values + typename KeyOutputIteratorT, ///< Random-access output iterator type for keys + typename ValueOutputIteratorT, ///< Random-access output iterator type for values + typename NumSelectedIteratorT, ///< Output iterator type for recording the number of items selected + typename ScanTileStateT, ///< Tile status interface type + typename EqualityOpT, ///< Equality operator type + typename OffsetT> ///< Signed integer type for global offsets +__launch_bounds__ (int(ChainedPolicyT::ActivePolicy::UniqueByKeyPolicyT::BLOCK_THREADS)) +__global__ void DeviceUniqueByKeySweepKernel( + KeyInputIteratorT d_keys_in, ///< [in] Pointer to the input sequence of keys + ValueInputIteratorT d_values_in, ///< [in] Pointer to the input sequence of values + KeyOutputIteratorT d_keys_out, ///< [out] Pointer to the output sequence of selected data items + ValueOutputIteratorT d_values_out, ///< [out] Pointer to the output sequence of selected data items + NumSelectedIteratorT d_num_selected_out, ///< [out] Pointer to the total number of items selected (i.e., length of \p d_keys_out or \p d_values_out) + ScanTileStateT tile_state, ///< [in] Tile status interface + EqualityOpT equality_op, ///< [in] Equality operator + OffsetT num_items, ///< [in] Total number of input items (i.e., length of \p d_keys_in or \p d_values_in) + int num_tiles) ///< [in] Total number of tiles for the entire problem +{ + using AgentUniqueByKeyPolicyT = typename ChainedPolicyT::ActivePolicy::UniqueByKeyPolicyT; + + // Thread block type for selecting data from input tiles + using AgentUniqueByKeyT = AgentUniqueByKey; + + // Shared memory for AgentUniqueByKey + __shared__ typename AgentUniqueByKeyT::TempStorage temp_storage; + + // Process tiles + AgentUniqueByKeyT(temp_storage, d_keys_in, d_values_in, d_keys_out, d_values_out, equality_op, num_items).ConsumeRange( + num_tiles, + tile_state, + d_num_selected_out); +} + + +/****************************************************************************** + * Dispatch + ******************************************************************************/ + +/** + * Utility class for dispatching the appropriately-tuned kernels for DeviceSelect + */ +template < + typename KeyInputIteratorT, ///< Random-access input iterator type for keys + typename ValueInputIteratorT, ///< Random-access input iterator type for values + typename KeyOutputIteratorT, ///< Random-access output iterator type for keys + typename ValueOutputIteratorT, ///< Random-access output iterator type for values + typename NumSelectedIteratorT, ///< Output iterator type for recording the number of items selected + typename EqualityOpT, ///< Equality operator type + typename OffsetT, ///< Signed integer type for global offsets + typename SelectedPolicy = DeviceUniqueByKeyPolicy> +struct DispatchUniqueByKey : SelectedPolicy +{ + /****************************************************************************** + * Types and constants + ******************************************************************************/ + + enum + { + INIT_KERNEL_THREADS = 128, + }; + + // The input key and value type + using KeyT = typename std::iterator_traits::value_type; + using ValueT = typename std::iterator_traits::value_type; + + // Tile status descriptor interface type + using ScanTileStateT = ScanTileState; + + + void* d_temp_storage; ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t& temp_storage_bytes; ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation + KeyInputIteratorT d_keys_in; ///< [in] Pointer to the input sequence of keys + ValueInputIteratorT d_values_in; ///< [in] Pointer to the input sequence of values + KeyOutputIteratorT d_keys_out; ///< [out] Pointer to the output sequence of selected data items + ValueOutputIteratorT d_values_out; ///< [out] Pointer to the output sequence of selected data items + NumSelectedIteratorT d_num_selected_out; ///< [out] Pointer to the total number of items selected (i.e., length of \p d_keys_out or \p d_values_out) + EqualityOpT equality_op; ///< [in] Equality operator + OffsetT num_items; ///< [in] Total number of input items (i.e., length of \p d_keys_in or \p d_values_in) + cudaStream_t stream; ///< [in] [optional] CUDA stream to launch kernels within. Default is stream0. + + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchUniqueByKey( + void* d_temp_storage, ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t& temp_storage_bytes, ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation + KeyInputIteratorT d_keys_in, ///< [in] Pointer to the input sequence of keys + ValueInputIteratorT d_values_in, ///< [in] Pointer to the input sequence of values + KeyOutputIteratorT d_keys_out, ///< [out] Pointer to the output sequence of selected data items + ValueOutputIteratorT d_values_out, ///< [out] Pointer to the output sequence of selected data items + NumSelectedIteratorT d_num_selected_out, ///< [out] Pointer to the total number of items selected (i.e., length of \p d_keys_out or \p d_values_out) + EqualityOpT equality_op, ///< [in] Equality operator + OffsetT num_items, ///< [in] Total number of input items (i.e., length of \p d_keys_in or \p d_values_in) + cudaStream_t stream ///< [in] [optional] CUDA stream to launch kernels within. Default is stream0. + ): + d_temp_storage(d_temp_storage), + temp_storage_bytes(temp_storage_bytes), + d_keys_in(d_keys_in), + d_values_in(d_values_in), + d_keys_out(d_keys_out), + d_values_out(d_values_out), + d_num_selected_out(d_num_selected_out), + equality_op(equality_op), + num_items(num_items), + stream(stream) + {} + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ + DispatchUniqueByKey( + void* d_temp_storage, + size_t& temp_storage_bytes, + KeyInputIteratorT d_keys_in, + ValueInputIteratorT d_values_in, + KeyOutputIteratorT d_keys_out, + ValueOutputIteratorT d_values_out, + NumSelectedIteratorT d_num_selected_out, + EqualityOpT equality_op, + OffsetT num_items, + cudaStream_t stream, + bool debug_synchronous + ): + d_temp_storage(d_temp_storage), + temp_storage_bytes(temp_storage_bytes), + d_keys_in(d_keys_in), + d_values_in(d_values_in), + d_keys_out(d_keys_out), + d_values_out(d_values_out), + d_num_selected_out(d_num_selected_out), + equality_op(equality_op), + num_items(num_items), + stream(stream) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + } + + + /****************************************************************************** + * Dispatch entrypoints + ******************************************************************************/ + + template + CUB_RUNTIME_FUNCTION __host__ __forceinline__ + cudaError_t Invoke(InitKernel init_kernel, ScanKernel scan_kernel) + { + using Policy = typename ActivePolicyT::UniqueByKeyPolicyT; + using UniqueByKeyAgentT = AgentUniqueByKey; + + cudaError error = cudaSuccess; + do + { + // Get device ordinal + int device_ordinal; + if (CubDebug(error = cudaGetDevice(&device_ordinal))) break; + + // Number of input tiles + int tile_size = Policy::BLOCK_THREADS * Policy::ITEMS_PER_THREAD; + int num_tiles = static_cast(cub::DivideAndRoundUp(num_items, tile_size)); + + // Size of virtual shared memory + int max_shmem = 0; + if (CubDebug( + error = cudaDeviceGetAttribute(&max_shmem, + cudaDevAttrMaxSharedMemoryPerBlock, + device_ordinal))) + { + break; + } + std::size_t vshmem_size = detail::VshmemSize(max_shmem, sizeof(typename UniqueByKeyAgentT::TempStorage), num_tiles); + + // Specify temporary storage allocation requirements + size_t allocation_sizes[2] = {0, vshmem_size}; + if (CubDebug(error = ScanTileStateT::AllocationSize(num_tiles, allocation_sizes[0]))) break; // bytes needed for tile status descriptors + + // Compute allocation pointers into the single storage blob (or compute the necessary size of the blob) + void *allocations[2] = {NULL, NULL}; + if (CubDebug(error = AliasTemporaries(d_temp_storage, temp_storage_bytes, allocations, allocation_sizes))) break; + if (d_temp_storage == NULL) + { + // Return if the caller is simply requesting the size of the storage allocation + break; + } + + // Construct the tile status interface + ScanTileStateT tile_state; + if (CubDebug(error = tile_state.Init(num_tiles, allocations[0], allocation_sizes[0]))) break; + + // Log init_kernel configuration + num_tiles = CUB_MAX(1, num_tiles); + int init_grid_size = cub::DivideAndRoundUp(num_tiles, INIT_KERNEL_THREADS); + + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + _CubLog("Invoking init_kernel<<<%d, %d, 0, %lld>>>()\n", init_grid_size, INIT_KERNEL_THREADS, (long long) stream); + #endif + + // Invoke init_kernel to initialize tile descriptors + THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + init_grid_size, INIT_KERNEL_THREADS, 0, stream + ).doit(init_kernel, tile_state, num_tiles, d_num_selected_out); + + // Check for failure to launch + if (CubDebug(error = cudaPeekAtLastError())) break; + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + + // Return if empty problem + if (num_items == 0) break; + + // Get max x-dimension of grid + int max_dim_x; + if (CubDebug(error = cudaDeviceGetAttribute(&max_dim_x, cudaDevAttrMaxGridDimX, device_ordinal))) break; + + // Get grid size for scanning tiles + dim3 scan_grid_size; + scan_grid_size.z = 1; + scan_grid_size.y = cub::DivideAndRoundUp(num_tiles, max_dim_x); + scan_grid_size.x = CUB_MIN(num_tiles, max_dim_x); + + // Log select_if_kernel configuration + #ifdef CUB_DETAIL_DEBUG_ENABLE_LOG + { + // Get SM occupancy for unique_by_key_kernel + int scan_sm_occupancy; + if (CubDebug(error = MaxSmOccupancy(scan_sm_occupancy, // out + scan_kernel, + Policy::BLOCK_THREADS))) + { + break; + } + + _CubLog("Invoking unique_by_key_kernel<<<{%d,%d,%d}, %d, 0, " + "%lld>>>(), %d items per thread, %d SM occupancy\n", + scan_grid_size.x, + scan_grid_size.y, + scan_grid_size.z, + Policy::BLOCK_THREADS, + (long long)stream, + Policy::ITEMS_PER_THREAD, + scan_sm_occupancy); + } + #endif + + // Invoke select_if_kernel + error = THRUST_NS_QUALIFIER::cuda_cub::launcher::triple_chevron( + scan_grid_size, Policy::BLOCK_THREADS, 0, stream + ).doit(scan_kernel, + d_keys_in, + d_values_in, + d_keys_out, + d_values_out, + d_num_selected_out, + tile_state, + equality_op, + num_items, + num_tiles); + + // Check for failure to launch + if (CubDebug(error)) + { + break; + } + + // Sync the stream if specified to flush runtime errors + error = detail::DebugSyncStream(stream); + if (CubDebug(error)) + { + break; + } + } + while(0); + + return error; + } + + template + CUB_RUNTIME_FUNCTION __host__ __forceinline__ + cudaError_t Invoke() + { + using MaxPolicyT = typename DispatchUniqueByKey::MaxPolicy; + + // Ensure kernels are instantiated. + return Invoke( + DeviceCompactInitKernel, + DeviceUniqueByKeySweepKernel< + MaxPolicyT, + KeyInputIteratorT, + ValueInputIteratorT, + KeyOutputIteratorT, + ValueOutputIteratorT, + NumSelectedIteratorT, + ScanTileStateT, + EqualityOpT, + OffsetT> + ); + } + + + /** + * Internal dispatch routine + */ + CUB_RUNTIME_FUNCTION __forceinline__ + static cudaError_t Dispatch( + void* d_temp_storage, ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t &temp_storage_bytes, ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation + KeyInputIteratorT d_keys_in, ///< [in] Pointer to the input sequence of keys + ValueInputIteratorT d_values_in, ///< [in] Pointer to the input sequence of values + KeyOutputIteratorT d_keys_out, ///< [out] Pointer to the output sequence of selected data items + ValueOutputIteratorT d_values_out, ///< [out] Pointer to the output sequence of selected data items + NumSelectedIteratorT d_num_selected_out, ///< [out] Pointer to the total number of items selected (i.e., length of \p d_keys_out or \p d_values_out) + EqualityOpT equality_op, ///< [in] Equality operator + OffsetT num_items, ///< [in] Total number of input items (i.e., the length of \p d_in) + cudaStream_t stream) ///< [in] [optional] CUDA stream to launch kernels within. Default is stream0. + { + using MaxPolicyT = typename DispatchUniqueByKey::MaxPolicy; + + cudaError_t error; + do + { + // Get PTX version + int ptx_version = 0; + if (CubDebug(error = PtxVersion(ptx_version))) break; + + // Create dispatch functor + DispatchUniqueByKey dispatch( + d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_keys_out, + d_values_out, + d_num_selected_out, + equality_op, + num_items, + stream); + + // Dispatch to chained policy + if (CubDebug(error = MaxPolicyT::Invoke(ptx_version, dispatch))) break; + } + while (0); + + return error; + } + + CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED + CUB_RUNTIME_FUNCTION __forceinline__ + static cudaError_t Dispatch( + void* d_temp_storage, + size_t &temp_storage_bytes, + KeyInputIteratorT d_keys_in, + ValueInputIteratorT d_values_in, + KeyOutputIteratorT d_keys_out, + ValueOutputIteratorT d_values_out, + NumSelectedIteratorT d_num_selected_out, + EqualityOpT equality_op, + OffsetT num_items, + cudaStream_t stream, + bool debug_synchronous) + { + CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG + + return Dispatch(d_temp_storage, + temp_storage_bytes, + d_keys_in, + d_values_in, + d_keys_out, + d_values_out, + d_num_selected_out, + equality_op, + num_items, + stream); + } +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_histogram.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_histogram.cuh new file mode 100644 index 0000000000000000000000000000000000000000..f53ae3a27ba863aef77b9f3d77fc60602bed8654 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_histogram.cuh @@ -0,0 +1,197 @@ +/****************************************************************************** + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +namespace histogram +{ + +enum class primitive_sample +{ + no, + yes +}; + +enum class sample_size +{ + _1, + _2, + unknown +}; + +enum class counter_size +{ + _4, + unknown +}; + +template +constexpr primitive_sample is_primitive_sample() +{ + return Traits::PRIMITIVE ? primitive_sample::yes : primitive_sample::no; +} + +template +constexpr counter_size classify_counter_size() +{ + return sizeof(CounterT) == 4 ? counter_size::_4 : counter_size::unknown; +} + +template +constexpr sample_size classify_sample_size() +{ + return sizeof(SampleT) == 1 ? sample_size::_1 + : sizeof(SampleT) == 2 ? sample_size::_2 + : sample_size::unknown; +} + +template +constexpr int v_scale() +{ + return (sizeof(SampleT) + sizeof(int) - 1) / sizeof(int); +} + +template +constexpr int t_scale() +{ + return CUB_MAX((NominalItemsPerThread / NumActiveChannels / v_scale()), 1); +} + +template (), + sample_size SampleSize = classify_sample_size()> +struct sm90_tuning +{ + static constexpr int threads = 384; + static constexpr int items = t_scale(); + + static constexpr CacheLoadModifier load_modifier = LOAD_LDG; + static constexpr BlockHistogramMemoryPreference mem_preference = SMEM; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr bool rle_compress = true; + static constexpr bool work_stealing = false; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 768; + static constexpr int items = 12; + + static constexpr CacheLoadModifier load_modifier = LOAD_LDG; + static constexpr BlockHistogramMemoryPreference mem_preference = SMEM; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr bool rle_compress = false; + static constexpr bool work_stealing = false; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 960; + static constexpr int items = 10; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + static constexpr BlockHistogramMemoryPreference mem_preference = SMEM; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr bool rle_compress = true; + static constexpr bool work_stealing = false; +}; + +} // namespace histogram + +template +struct device_histogram_policy_hub +{ + template + struct TScale + { + enum + { + V_SCALE = (sizeof(SampleT) + sizeof(int) - 1) / sizeof(int), + VALUE = CUB_MAX((NOMINAL_ITEMS_PER_THREAD / NumActiveChannels / V_SCALE), 1) + }; + }; + + /// SM35 + struct Policy350 : ChainedPolicy<350, Policy350, Policy350> + { + // TODO This might be worth it to separate usual histogram and the multi one + using AgentHistogramPolicyT = + AgentHistogramPolicy<128, TScale<8>::VALUE, BLOCK_LOAD_DIRECT, LOAD_LDG, true, BLEND, true>; + }; + + /// SM50 + struct Policy500 : ChainedPolicy<500, Policy500, Policy350> + { + // TODO This might be worth it to separate usual histogram and the multi one + using AgentHistogramPolicyT = + AgentHistogramPolicy<384, TScale<16>::VALUE, cub::BLOCK_LOAD_DIRECT, LOAD_LDG, true, SMEM, false>; + }; + + /// SM900 + struct Policy900 : ChainedPolicy<900, Policy900, Policy500> + { + using tuning = detail::histogram::sm90_tuning()>; + + using AgentHistogramPolicyT = AgentHistogramPolicy; + }; + + using MaxPolicy = Policy900; +}; + +} // namespace detail + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_reduce_by_key.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_reduce_by_key.cuh new file mode 100644 index 0000000000000000000000000000000000000000..d06e2f7fb866419051c413d12ff30f777a23ce02 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_reduce_by_key.cuh @@ -0,0 +1,650 @@ +/****************************************************************************** + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +namespace reduce_by_key +{ + +enum class primitive_key +{ + no, + yes +}; +enum class primitive_accum +{ + no, + yes +}; +enum class primitive_op +{ + no, + yes +}; +enum class key_size +{ + _1, + _2, + _4, + _8, + _16, + unknown +}; +enum class accum_size +{ + _1, + _2, + _4, + _8, + _16, + unknown +}; + +template +constexpr primitive_key is_primitive_key() +{ + return Traits::PRIMITIVE ? primitive_key::yes : primitive_key::no; +} + +template +constexpr primitive_accum is_primitive_accum() +{ + return Traits::PRIMITIVE ? primitive_accum::yes : primitive_accum::no; +} + +template +constexpr primitive_op is_primitive_op() +{ + return basic_binary_op_t::value ? primitive_op::yes : primitive_op::no; +} + +template +constexpr key_size classify_key_size() +{ + return sizeof(KeyT) == 1 ? key_size::_1 + : sizeof(KeyT) == 2 ? key_size::_2 + : sizeof(KeyT) == 4 ? key_size::_4 + : sizeof(KeyT) == 8 ? key_size::_8 + : sizeof(KeyT) == 16 ? key_size::_16 + : key_size::unknown; +} + +template +constexpr accum_size classify_accum_size() +{ + return sizeof(AccumT) == 1 ? accum_size::_1 + : sizeof(AccumT) == 2 ? accum_size::_2 + : sizeof(AccumT) == 4 ? accum_size::_4 + : sizeof(AccumT) == 8 ? accum_size::_8 + : sizeof(AccumT) == 16 ? accum_size::_16 + : accum_size::unknown; +} + +template (), + primitive_accum PrimitiveAccum = is_primitive_accum(), + key_size KeySize = classify_key_size(), + accum_size AccumSize = classify_accum_size()> +struct sm90_tuning +{ + static constexpr int max_input_bytes = CUB_MAX(sizeof(KeyT), sizeof(AccumT)); + static constexpr int combined_input_bytes = sizeof(KeyT) + sizeof(AccumT); + + static constexpr int threads = 128; + + static constexpr int nominal_4b_items_per_thread = 6; + static constexpr int items = + (max_input_bytes <= 8) + ? 6 + : CUB_MIN(nominal_4b_items_per_thread, + CUB_MAX(1, + ((nominal_4b_items_per_thread * 8) + combined_input_bytes - 1) / + combined_input_bytes)); + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::default_reduce_by_key_delay_constructor_t; +}; + +// 8-bit key +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 13; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<720>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 320; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<865>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 192; + + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<735>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 13; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<580>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1100>; +}; + +// 16-bit key +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<985>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<276, 650>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<240, 765>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 19; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1190>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1175>; +}; + +// 32-bit key +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 13; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<404, 645>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 18; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1160>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 18; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1170>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 13; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1055>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1195>; +}; + +// 64-bit key +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 10; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<1170>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 9; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<236, 1030>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 13; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<152, 560>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1030>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1125>; +}; + +// 128-bit key +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1080>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<320, 1005>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<232, 1100>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1195>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1150>; +}; +} // namespace reduce_by_key + +template +struct device_reduce_by_key_policy_hub +{ + static constexpr int MAX_INPUT_BYTES = CUB_MAX(sizeof(KeyT), sizeof(AccumT)); + static constexpr int COMBINED_INPUT_BYTES = sizeof(KeyT) + sizeof(AccumT); + + /// SM35 + struct Policy350 : ChainedPolicy<350, Policy350, Policy350> + { + static constexpr int NOMINAL_4B_ITEMS_PER_THREAD = 6; + static constexpr int ITEMS_PER_THREAD = + (MAX_INPUT_BYTES <= 8) + ? 6 + : CUB_MIN(NOMINAL_4B_ITEMS_PER_THREAD, + CUB_MAX(1, + ((NOMINAL_4B_ITEMS_PER_THREAD * 8) + COMBINED_INPUT_BYTES - 1) / + COMBINED_INPUT_BYTES)); + + using ReduceByKeyPolicyT = + AgentReduceByKeyPolicy<128, + ITEMS_PER_THREAD, + BLOCK_LOAD_DIRECT, + LOAD_LDG, + BLOCK_SCAN_WARP_SCANS, + detail::default_reduce_by_key_delay_constructor_t>; + }; + + /// SM90 + struct Policy900 : ChainedPolicy<900, Policy900, Policy350> + { + using tuning = detail::reduce_by_key:: + sm90_tuning()>; + + using ReduceByKeyPolicyT = AgentReduceByKeyPolicy; + }; + + using MaxPolicy = Policy900; +}; + +} // namespace detail + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_run_length_encode.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_run_length_encode.cuh new file mode 100644 index 0000000000000000000000000000000000000000..80282592915fbbf330c440f3ef6e7b5bea0d3b96 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_run_length_encode.cuh @@ -0,0 +1,652 @@ +/****************************************************************************** + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +namespace rle +{ + +enum class primitive_key { no, yes }; +enum class primitive_length { no, yes }; +enum class key_size { _1, _2, _4, _8, _16, unknown }; +enum class length_size { _4, unknown }; + +template +constexpr primitive_key is_primitive_key() +{ + return Traits::PRIMITIVE ? primitive_key::yes : primitive_key::no; +} + +template +constexpr primitive_length is_primitive_length() +{ + return Traits::PRIMITIVE ? primitive_length::yes : primitive_length::no; +} + +template +constexpr key_size classify_key_size() +{ + return sizeof(KeyT) == 1 ? key_size::_1 + : sizeof(KeyT) == 2 ? key_size::_2 + : sizeof(KeyT) == 4 ? key_size::_4 + : sizeof(KeyT) == 8 ? key_size::_8 + : sizeof(KeyT) == 16 ? key_size::_16 + : key_size::unknown; +} + +template +constexpr length_size classify_length_size() +{ + return sizeof(LengthT) == 4 ? length_size::_4 : length_size::unknown; +} + +namespace encode { + +template (), + primitive_key PrimitiveKey = is_primitive_key(), + length_size LengthSize = classify_length_size(), + key_size KeySize = classify_key_size()> +struct sm90_tuning +{ + static constexpr int max_input_bytes = CUB_MAX(sizeof(KeyT), sizeof(LengthT)); + static constexpr int combined_input_bytes = sizeof(KeyT) + sizeof(LengthT); + + static constexpr int threads = 128; + + static constexpr int nominal_4b_items_per_thread = 6; + + static constexpr int items = + (max_input_bytes <= 8) + ? 6 + : CUB_MIN(nominal_4b_items_per_thread, + CUB_MAX(1, + ((nominal_4b_items_per_thread * 8) + combined_input_bytes - 1) / + combined_input_bytes)); + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::default_reduce_by_key_delay_constructor_t; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 13; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<620>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 22; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<775>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 192; + + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<284, 480>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 19; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<515>; +}; + +#if CUB_IS_INT128_ENABLED +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<428, 930>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<428, 930>; +}; +#endif + +template (), + primitive_key PrimitiveKey = is_primitive_key(), + length_size LengthSize = classify_length_size(), + key_size KeySize = classify_key_size()> +struct sm80_tuning +{ + static constexpr int max_input_bytes = CUB_MAX(sizeof(KeyT), sizeof(LengthT)); + static constexpr int combined_input_bytes = sizeof(KeyT) + sizeof(LengthT); + + static constexpr int threads = 128; + + static constexpr int nominal_4b_items_per_thread = 6; + + static constexpr int items = + (max_input_bytes <= 8) + ? 6 + : CUB_MIN(nominal_4b_items_per_thread, + CUB_MAX(1, + ((nominal_4b_items_per_thread * 8) + combined_input_bytes - 1) / + combined_input_bytes)); + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::default_reduce_by_key_delay_constructor_t; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<640>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 13; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<900>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 13; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<1080>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 224; + + static constexpr int items = 9; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1075>; +}; + +#if CUB_IS_INT128_ENABLED +template +struct sm80_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 7; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<630>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 7; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<630>; +}; +#endif + +} // namespace encode + +namespace non_trivial_runs +{ + +template (), + primitive_key PrimitiveKey = is_primitive_key(), + length_size LengthSize = classify_length_size(), + key_size KeySize = classify_key_size()> +struct sm90_tuning +{ + static constexpr int threads = 96; + + static constexpr int nominal_4b_items_per_thread = 15; + + static constexpr int items = CUB_MIN(nominal_4b_items_per_thread, + CUB_MAX(1, (nominal_4b_items_per_thread * 4 / sizeof(KeyT)))); + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr bool store_with_time_slicing = true; + + using delay_constructor = detail::default_reduce_by_key_delay_constructor_t; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 18; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::no_delay_constructor_t<385>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 224; + + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::no_delay_constructor_t<675>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 18; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::no_delay_constructor_t<695>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 224; + + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::no_delay_constructor_t<840>; +}; + +#if CUB_IS_INT128_ENABLED +template +struct sm90_tuning +{ + static constexpr int threads = 288; + + static constexpr int items = 9; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::fixed_delay_constructor_t<484, 1150>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 288; + + static constexpr int items = 9; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::fixed_delay_constructor_t<484, 1150>; +}; +#endif + +template (), + primitive_key PrimitiveKey = is_primitive_key(), + length_size LengthSize = classify_length_size(), + key_size KeySize = classify_key_size()> +struct sm80_tuning +{ + static constexpr int threads = 96; + + static constexpr int nominal_4b_items_per_thread = 15; + + static constexpr int items = CUB_MIN(nominal_4b_items_per_thread, + CUB_MAX(1, (nominal_4b_items_per_thread * 4 / sizeof(KeyT)))); + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr bool store_with_time_slicing = true; + + using delay_constructor = detail::default_reduce_by_key_delay_constructor_t; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 192; + + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::no_delay_constructor_t<630>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 192; + + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::no_delay_constructor_t<1015>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 224; + + static constexpr int items = 15; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::no_delay_constructor_t<915>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 13; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::no_delay_constructor_t<1065>; +}; + +#if CUB_IS_INT128_ENABLED +template +struct sm80_tuning +{ + static constexpr int threads = 192; + + static constexpr int items = 13; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::no_delay_constructor_t<1050>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 192; + + static constexpr int items = 13; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr bool store_with_time_slicing = false; + + using delay_constructor = detail::no_delay_constructor_t<1050>; +}; +#endif + +} // namespace non_trivial_runs + + +} // namespace rle + +template +struct device_run_length_encode_policy_hub +{ + static constexpr int MAX_INPUT_BYTES = CUB_MAX(sizeof(KeyT), sizeof(LengthT)); + static constexpr int COMBINED_INPUT_BYTES = sizeof(KeyT) + sizeof(LengthT); + + struct DefaultTuning + { + static constexpr int NOMINAL_4B_ITEMS_PER_THREAD = 6; + static constexpr int ITEMS_PER_THREAD = + (MAX_INPUT_BYTES <= 8) + ? 6 + : CUB_MIN(NOMINAL_4B_ITEMS_PER_THREAD, + CUB_MAX(1, + ((NOMINAL_4B_ITEMS_PER_THREAD * 8) + COMBINED_INPUT_BYTES - 1) / + COMBINED_INPUT_BYTES)); + + using ReduceByKeyPolicyT = + AgentReduceByKeyPolicy<128, + ITEMS_PER_THREAD, + BLOCK_LOAD_DIRECT, + LOAD_LDG, + BLOCK_SCAN_WARP_SCANS, + detail::default_reduce_by_key_delay_constructor_t>; + }; + + /// SM35 + struct Policy350 + : DefaultTuning + , ChainedPolicy<350, Policy350, Policy350> + {}; + + /// SM80 + struct Policy800 : ChainedPolicy<800, Policy800, Policy350> + { + using tuning = detail::rle::encode::sm80_tuning; + + using ReduceByKeyPolicyT = + AgentReduceByKeyPolicy; + }; + + // SM86 + struct Policy860 + : DefaultTuning + , ChainedPolicy<860, Policy860, Policy800> + {}; + + /// SM90 + struct Policy900 : ChainedPolicy<900, Policy900, Policy860> + { + using tuning = detail::rle::encode::sm90_tuning; + + using ReduceByKeyPolicyT = + AgentReduceByKeyPolicy; + }; + + using MaxPolicy = Policy900; +}; + +template +struct device_non_trivial_runs_policy_hub +{ + struct DefaultTuning + { + enum + { + NOMINAL_4B_ITEMS_PER_THREAD = 15, + + ITEMS_PER_THREAD = CUB_MIN(NOMINAL_4B_ITEMS_PER_THREAD, + CUB_MAX(1, (NOMINAL_4B_ITEMS_PER_THREAD * 4 / sizeof(KeyT)))), + }; + + using RleSweepPolicyT = + AgentRlePolicy<96, + ITEMS_PER_THREAD, + BLOCK_LOAD_DIRECT, + LOAD_LDG, + true, + BLOCK_SCAN_WARP_SCANS, + detail::default_reduce_by_key_delay_constructor_t>; + }; + + /// SM35 + struct Policy350 + : DefaultTuning + , ChainedPolicy<350, Policy350, Policy350> + {}; + + // SM80 + struct Policy800 : ChainedPolicy<800, Policy800, Policy350> + { + using tuning = detail::rle::non_trivial_runs::sm80_tuning; + + using RleSweepPolicyT = AgentRlePolicy; + }; + + // SM86 + struct Policy860 + : DefaultTuning + , ChainedPolicy<860, Policy860, Policy800> + {}; + + // SM90 + struct Policy900 : ChainedPolicy<900, Policy900, Policy860> + { + using tuning = detail::rle::non_trivial_runs::sm90_tuning; + + using RleSweepPolicyT = + AgentRlePolicy; + }; + + using MaxPolicy = Policy900; +}; + +} // namespace detail + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_scan.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_scan.cuh new file mode 100644 index 0000000000000000000000000000000000000000..0ea5c41ad62030e07f6971f285aca977f2007cde --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_scan.cuh @@ -0,0 +1,349 @@ +/****************************************************************************** + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ +namespace scan +{ + +enum class keep_rejects { no, yes }; +enum class primitive_accum { no, yes }; +enum class primitive_op { no, yes }; +enum class offset_size { _4, _8, unknown }; +enum class accum_size { _1, _2, _4, _8, _16, unknown }; + +template +constexpr primitive_accum is_primitive_accum() +{ + return Traits::PRIMITIVE ? primitive_accum::yes : primitive_accum::no; +} + +template +constexpr primitive_op is_primitive_op() +{ + return basic_binary_op_t::value ? primitive_op::yes : primitive_op::no; +} + +template +constexpr accum_size classify_accum_size() +{ + return sizeof(AccumT) == 1 ? accum_size::_1 + : sizeof(AccumT) == 2 ? accum_size::_2 + : sizeof(AccumT) == 4 ? accum_size::_4 + : sizeof(AccumT) == 8 ? accum_size::_8 + : sizeof(AccumT) == 16 ? accum_size::_16 + : accum_size::unknown; +} + +template +struct tuning +{ + static constexpr int threads = Threads; + static constexpr int items = Items; + + using delay_constructor = detail::fixed_delay_constructor_t; +}; + +template (), + accum_size AccumSize = classify_accum_size()> +struct sm90_tuning +{ + static constexpr int threads = 128; + static constexpr int items = 15; + + using delay_constructor = detail::default_delay_constructor_t; +}; + +// clang-format off +template struct sm90_tuning : tuning<192, 22, 168, 1140> {}; +template struct sm90_tuning : tuning<512, 12, 376, 1125> {}; +template struct sm90_tuning : tuning<128, 24, 648, 1245> {}; +template struct sm90_tuning : tuning<224, 24, 632, 1290> {}; + +template <> struct sm90_tuning : tuning<128, 24, 688, 1140> {}; +template <> struct sm90_tuning : tuning<224, 24, 576, 1215> {}; + +#if CUB_IS_INT128_ENABLED +template <> struct sm90_tuning< __int128_t, primitive_op::yes, primitive_accum::no, accum_size::_16> : tuning<576, 21, 860, 630> {}; +template <> struct sm90_tuning<__uint128_t, primitive_op::yes, primitive_accum::no, accum_size::_16> : tuning<576, 21, 860, 630> {}; +#endif +// clang-format on + +template (), + accum_size AccumSize = classify_accum_size()> +struct sm80_tuning +{ + static constexpr int threads = 128; + static constexpr int items = 15; + + using delay_constructor = detail::default_delay_constructor_t; + + static constexpr bool LargeValues = sizeof(AccumT) > 128; + + static constexpr BlockLoadAlgorithm load_algorithm = // + LargeValues ? BLOCK_LOAD_WARP_TRANSPOSE_TIMESLICED : BLOCK_LOAD_WARP_TRANSPOSE; + static constexpr BlockStoreAlgorithm store_algorithm = // + LargeValues ? BLOCK_STORE_WARP_TRANSPOSE_TIMESLICED : BLOCK_STORE_WARP_TRANSPOSE; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 320; + static constexpr int items = 14; + + using delay_constructor = detail::fixed_delay_constructor_t<368, 725>; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 352; + static constexpr int items = 16; + + using delay_constructor = detail::fixed_delay_constructor_t<488, 1040>; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 320; + static constexpr int items = 12; + + using delay_constructor = detail::fixed_delay_constructor_t<268, 1180>; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 288; + static constexpr int items = 22; + + using delay_constructor = detail::fixed_delay_constructor_t<716, 785>; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; +}; + +template <> +struct sm80_tuning +{ + static constexpr int threads = 288; + static constexpr int items = 8; + + using delay_constructor = detail::fixed_delay_constructor_t<724, 1050>; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; +}; + +template <> +struct sm80_tuning +{ + static constexpr int threads = 384; + static constexpr int items = 12; + + using delay_constructor = detail::fixed_delay_constructor_t<388, 1100>; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; +}; + +#if CUB_IS_INT128_ENABLED +template <> +struct sm80_tuning<__int128_t, primitive_op::yes, primitive_accum::no, accum_size::_16> +{ + static constexpr int threads = 640; + static constexpr int items = 24; + + using delay_constructor = detail::no_delay_constructor_t<1200>; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_DIRECT; +}; + +template <> +struct sm80_tuning<__uint128_t, primitive_op::yes, primitive_accum::no, accum_size::_16> +{ + static constexpr int threads = 640; + static constexpr int items = 24; + + using delay_constructor = detail::no_delay_constructor_t<1200>; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_DIRECT; +}; +#endif + +} // namespace scan +} // namespace detail + + +template +struct DeviceScanPolicy +{ + // For large values, use timesliced loads/stores to fit shared memory. + static constexpr bool LargeValues = sizeof(AccumT) > 128; + static constexpr BlockLoadAlgorithm ScanTransposedLoad = + LargeValues ? BLOCK_LOAD_WARP_TRANSPOSE_TIMESLICED + : BLOCK_LOAD_WARP_TRANSPOSE; + static constexpr BlockStoreAlgorithm ScanTransposedStore = + LargeValues ? BLOCK_STORE_WARP_TRANSPOSE_TIMESLICED + : BLOCK_STORE_WARP_TRANSPOSE; + + template + using policy_t = + AgentScanPolicy, + DelayConstructorT>; + + /// SM350 + struct Policy350 : ChainedPolicy<350, Policy350, Policy350> + { + // GTX Titan: 29.5B items/s (232.4 GB/s) @ 48M 32-bit T + using ScanPolicyT = policy_t<128, + 12, ///< Threads per block, items per thread + AccumT, + BLOCK_LOAD_DIRECT, + LOAD_CA, + BLOCK_STORE_WARP_TRANSPOSE_TIMESLICED, + BLOCK_SCAN_RAKING, + detail::default_delay_constructor_t>; + }; + + /// SM520 + struct Policy520 : ChainedPolicy<520, Policy520, Policy350> + { + // Titan X: 32.47B items/s @ 48M 32-bit T + using ScanPolicyT = policy_t<128, + 12, ///< Threads per block, items per thread + AccumT, + BLOCK_LOAD_DIRECT, + LOAD_CA, + ScanTransposedStore, + BLOCK_SCAN_WARP_SCANS, + detail::default_delay_constructor_t>; + }; + + /// SM600 + struct DefaultTuning + { + using ScanPolicyT = policy_t<128, + 15, ///< Threads per block, items per thread + AccumT, + ScanTransposedLoad, + LOAD_DEFAULT, + ScanTransposedStore, + BLOCK_SCAN_WARP_SCANS, + detail::default_delay_constructor_t>; + }; + + /// SM600 + struct Policy600 + : DefaultTuning + , ChainedPolicy<600, Policy600, Policy520> + {}; + + /// SM800 + struct Policy800 : ChainedPolicy<800, Policy800, Policy600> + { + using tuning = detail::scan::sm80_tuning()>; + + using ScanPolicyT = policy_t; + }; + + /// SM860 + struct Policy860 + : DefaultTuning + , ChainedPolicy<860, Policy860, Policy800> + {}; + + /// SM900 + struct Policy900 : ChainedPolicy<900, Policy900, Policy860> + { + using tuning = detail::scan::sm90_tuning()>; + + using ScanPolicyT = policy_t; + }; + + using MaxPolicy = Policy900; +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_scan_by_key.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_scan_by_key.cuh new file mode 100644 index 0000000000000000000000000000000000000000..68faf6b3ab3ad6a9049cf10a41d045f360b7947f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_scan_by_key.cuh @@ -0,0 +1,620 @@ +/****************************************************************************** + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ +namespace scan_by_key +{ + +enum class primitive_accum { no, yes }; +enum class primitive_op { no, yes }; +enum class offset_size { _4, _8, unknown }; +enum class val_size { _1, _2, _4, _8, _16, unknown }; +enum class key_size { _1, _2, _4, _8, _16, unknown }; + +template +constexpr primitive_accum is_primitive_accum() +{ + return Traits::PRIMITIVE ? primitive_accum::yes : primitive_accum::no; +} + +template +constexpr primitive_op is_primitive_op() +{ + return basic_binary_op_t::value ? primitive_op::yes : primitive_op::no; +} + +template +constexpr val_size classify_val_size() +{ + return sizeof(ValueT) == 1 ? val_size::_1 + : sizeof(ValueT) == 2 ? val_size::_2 + : sizeof(ValueT) == 4 ? val_size::_4 + : sizeof(ValueT) == 8 ? val_size::_8 + : sizeof(ValueT) == 16 ? val_size::_16 + : val_size::unknown; +} + +template +constexpr key_size classify_key_size() +{ + return sizeof(KeyT) == 1 ? key_size::_1 + : sizeof(KeyT) == 2 ? key_size::_2 + : sizeof(KeyT) == 4 ? key_size::_4 + : sizeof(KeyT) == 8 ? key_size::_8 + : sizeof(KeyT) == 16 ? key_size::_16 + : key_size::unknown; +} + +template (), + val_size AccumSize = classify_val_size(), + primitive_accum PrimitiveAccumulator = is_primitive_accum()> +struct sm90_tuning +{ + static constexpr int nominal_4b_items_per_thread = 9; + + static constexpr int threads = 256; + + static constexpr size_t max_input_bytes = (cub::max)(sizeof(KeyT), sizeof(AccumT)); + + static constexpr size_t combined_input_bytes = sizeof(KeyT) + sizeof(AccumT); + + static constexpr int items = + ((max_input_bytes <= 8) + ? 9 + : Nominal4BItemsToItemsCombined(nominal_4b_items_per_thread, combined_input_bytes)); + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::default_reduce_by_key_delay_constructor_t; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<650>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 16; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<124, 995>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 15; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<488, 545>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 224; + + static constexpr int items = 10; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<488, 1070>; +}; + +#if CUB_IS_INT128_ENABLED +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<936, 1105>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<936, 1105>; +}; +#endif + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<136, 785>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<445>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 22; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<312, 865>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 224; + + static constexpr int items = 10; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<352, 1170>; +}; + +#if CUB_IS_INT128_ENABLED +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<504, 1190>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<504, 1190>; +}; +#endif + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<850>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<128, 965>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 288; + + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<700, 1005>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 224; + + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<556, 1195>; +}; + +#if CUB_IS_INT128_ENABLED +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<512, 1030>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<512, 1030>; +}; +#endif + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<504, 1010>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 224; + + static constexpr int items = 10; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<420, 970>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 192; + + static constexpr int items = 10; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<500, 1125>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 224; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<600, 930>; +}; + +#if CUB_IS_INT128_ENABLED +template +struct sm90_tuning +{ + static constexpr int threads = 192; + + static constexpr int items = 15; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<364, 1085>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 192; + + static constexpr int items = 15; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<364, 1085>; +}; +#endif + +template +struct sm90_tuning +{ + static constexpr int threads = 192; + + static constexpr int items = 7; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<500, 975>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 224; + + static constexpr int items = 10; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<164, 1075>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 9; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<268, 1120>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 192; + + static constexpr int items = 9; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<320, 1200>; +}; + +#if CUB_IS_INT128_ENABLED +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<364, 1050>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr BlockStoreAlgorithm store_algorithm = BLOCK_STORE_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<364, 1050>; +}; +#endif +} // namespace scan_by_key +} // namespace detail + + +template +struct DeviceScanByKeyPolicy +{ + using KeyT = cub::detail::value_t; + + static constexpr size_t MaxInputBytes = (cub::max)(sizeof(KeyT), + sizeof(AccumT)); + + static constexpr size_t CombinedInputBytes = sizeof(KeyT) + sizeof(AccumT); + + // SM350 + struct Policy350 : ChainedPolicy<350, Policy350, Policy350> + { + static constexpr int NOMINAL_4B_ITEMS_PER_THREAD = 6; + static constexpr int ITEMS_PER_THREAD = + ((MaxInputBytes <= 8) + ? 6 + : Nominal4BItemsToItemsCombined(NOMINAL_4B_ITEMS_PER_THREAD, + CombinedInputBytes)); + + using ScanByKeyPolicyT = + AgentScanByKeyPolicy<128, + ITEMS_PER_THREAD, + BLOCK_LOAD_WARP_TRANSPOSE, + LOAD_CA, + BLOCK_SCAN_WARP_SCANS, + BLOCK_STORE_WARP_TRANSPOSE, + detail::default_reduce_by_key_delay_constructor_t>; + }; + + // SM520 + struct Policy520 : ChainedPolicy<520, Policy520, Policy350> + { + static constexpr int NOMINAL_4B_ITEMS_PER_THREAD = 9; + static constexpr int ITEMS_PER_THREAD = + ((MaxInputBytes <= 8) + ? 9 + : Nominal4BItemsToItemsCombined(NOMINAL_4B_ITEMS_PER_THREAD, + CombinedInputBytes)); + + using ScanByKeyPolicyT = + AgentScanByKeyPolicy<256, + ITEMS_PER_THREAD, + BLOCK_LOAD_WARP_TRANSPOSE, + LOAD_CA, + BLOCK_SCAN_WARP_SCANS, + BLOCK_STORE_WARP_TRANSPOSE, + detail::default_reduce_by_key_delay_constructor_t>; + }; + + // SM900 + struct Policy900 : ChainedPolicy<900, Policy900, Policy520> + { + using tuning = + detail::scan_by_key::sm90_tuning()>; + + using ScanByKeyPolicyT = AgentScanByKeyPolicy; + }; + + using MaxPolicy = Policy900; +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_select_if.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_select_if.cuh new file mode 100644 index 0000000000000000000000000000000000000000..27247ca70e5114e9aef7f409bf4c77ca974cfff5 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_select_if.cuh @@ -0,0 +1,749 @@ +/****************************************************************************** + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +namespace select +{ + +enum class flagged { no, yes }; +enum class keep_rejects { no, yes }; +enum class primitive { no, yes }; +enum class offset_size { _4, _8, unknown }; +enum class input_size { _1, _2, _4, _8, _16, unknown }; + +template +constexpr primitive is_primitive() +{ + return Traits::PRIMITIVE ? primitive::yes : primitive::no; +} + +template +constexpr flagged is_flagged() +{ + return std::is_same::value ? flagged::no : flagged::yes; +} + +template +constexpr keep_rejects are_rejects_kept() +{ + return KeepRejects ? keep_rejects::yes : keep_rejects::no; +} + +template +constexpr input_size classify_input_size() +{ + return sizeof(InputT) == 1 ? input_size::_1 + : sizeof(InputT) == 2 ? input_size::_2 + : sizeof(InputT) == 4 ? input_size::_4 + : sizeof(InputT) == 8 ? input_size::_8 + : sizeof(InputT) == 16 ? input_size::_16 + : input_size::unknown; +} + +template +constexpr offset_size classify_offset_size() +{ + return sizeof(OffsetT) == 4 ? offset_size::_4 + : sizeof(OffsetT) == 8 ? offset_size::_8 + : offset_size::unknown; +} + +template (), + input_size InputSize = classify_input_size()> +struct sm90_tuning +{ + static constexpr int threads = 128; + + static constexpr int nominal_4b_items_per_thread = 10; + + static constexpr int items = + CUB_MIN(nominal_4b_items_per_thread, + CUB_MAX(1, (nominal_4b_items_per_thread * 4 / sizeof(InputT)))); + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<350, 450>; +}; + +// select::if +template +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 22; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<580>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 22; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<320, 605>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 384; + static constexpr int items = 17; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<76, 1150>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 384; + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<380, 1140>; +}; + +#if CUB_IS_INT128_ENABLED +template <> +struct sm90_tuning<__int128_t, flagged::no, keep_rejects::no, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 512; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<460, 1145>; +}; + +template <> +struct sm90_tuning<__uint128_t, flagged::no, keep_rejects::no, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 512; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<460, 1145>; +}; +#endif + +// select::flagged +template +struct sm90_tuning +{ + static constexpr int threads = 448; + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<715>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 448; + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<504, 765>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 384; + static constexpr int items = 15; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<415, 1125>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 384; + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<360, 1170>; +}; + +#if CUB_IS_INT128_ENABLED +template <> +struct sm90_tuning<__int128_t, flagged::yes, keep_rejects::no, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 512; + static constexpr int items = 3; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<284, 1130>; +}; + +template <> +struct sm90_tuning<__uint128_t, flagged::yes, keep_rejects::no, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 512; + static constexpr int items = 3; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<284, 1130>; +}; +#endif + +// partition::if +template +struct sm90_tuning +{ + static constexpr int threads = 384; + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<908, 995>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 320; + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<500, 560>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<536, 1055>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<512, 1075>; +}; + +#if CUB_IS_INT128_ENABLED +template <> +struct sm90_tuning<__int128_t, flagged::no, keep_rejects::yes, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 192; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<1616, 1115>; +}; + +template <> +struct sm90_tuning<__uint128_t, flagged::no, keep_rejects::yes, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 192; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<1616, 1115>; +}; +#endif + +// partition::flagged +template +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<580, 850>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 512; + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<388, 1055>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<72, 1165>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 224; + static constexpr int items = 6; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<532, 1180>; +}; + +#if CUB_IS_INT128_ENABLED +template <> +struct sm90_tuning<__int128_t, flagged::yes, keep_rejects::yes, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 160; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<720, 1105>; +}; + +template <> +struct sm90_tuning<__uint128_t, flagged::yes, keep_rejects::yes, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 160; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<720, 1105>; +}; +#endif + + +template (), + input_size InputSize = classify_input_size()> +struct sm80_tuning +{ + static constexpr int threads = 128; + + static constexpr int nominal_4b_items_per_thread = 10; + + static constexpr int items = + CUB_MIN(nominal_4b_items_per_thread, + CUB_MAX(1, (nominal_4b_items_per_thread * 4 / sizeof(InputT)))); + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<350, 450>; +}; + +// select::if +template +struct sm80_tuning +{ + static constexpr int threads = 992; + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<395>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 576; + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<870>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 18; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1130>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 192; + static constexpr int items = 10; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<832, 1165>; +}; + +#if CUB_IS_INT128_ENABLED +template <> +struct sm80_tuning<__int128_t, flagged::no, keep_rejects::no, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 384; + static constexpr int items = 4; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<1140>; +}; + +template <> +struct sm80_tuning<__uint128_t, flagged::no, keep_rejects::no, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 384; + static constexpr int items = 4; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<1140>; +}; +#endif + +// select::flagged +template +struct sm80_tuning +{ + static constexpr int threads = 224; + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<735>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1155>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 320; + static constexpr int items = 10; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<124, 1115>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 384; + static constexpr int items = 6; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<1130>; +}; + +#if CUB_IS_INT128_ENABLED +template <> +struct sm80_tuning<__int128_t, flagged::yes, keep_rejects::no, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 256; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<464, 1025>; +}; + +template <> +struct sm80_tuning<__uint128_t, flagged::yes, keep_rejects::no, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 256; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<464, 1025>; +}; +#endif + +// partition::if +template +struct sm80_tuning +{ + static constexpr int threads = 512; + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<510>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 224; + static constexpr int items = 18; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1045>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 192; + static constexpr int items = 15; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<1040>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 192; + static constexpr int items = 10; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<68, 1160>; +}; + +#if CUB_IS_INT128_ENABLED +template <> +struct sm80_tuning<__int128_t, flagged::no, keep_rejects::yes, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 256; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<400, 1090>; +}; + +template <> +struct sm80_tuning<__uint128_t, flagged::no, keep_rejects::yes, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 256; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<400, 1090>; +}; +#endif + +// partition::flagged +template +struct sm80_tuning +{ + static constexpr int threads = 512; + static constexpr int items = 20; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<595>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 224; + static constexpr int items = 18; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1105>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 192; + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<912, 1025>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 192; + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<884, 1130>; +}; + +#if CUB_IS_INT128_ENABLED +template <> +struct sm80_tuning<__int128_t, flagged::yes, keep_rejects::yes, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 256; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<400, 1090>; +}; + +template <> +struct sm80_tuning<__uint128_t, flagged::yes, keep_rejects::yes, offset_size::_4, primitive::no, input_size::_16> +{ + static constexpr int threads = 256; + static constexpr int items = 5; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<400, 1090>; +}; +#endif + +} // namespace select + +template +struct device_select_policy_hub +{ + struct DefaultTuning + { + static constexpr int NOMINAL_4B_ITEMS_PER_THREAD = 10; + + static constexpr int ITEMS_PER_THREAD = + CUB_MIN(NOMINAL_4B_ITEMS_PER_THREAD, + CUB_MAX(1, (NOMINAL_4B_ITEMS_PER_THREAD * 4 / sizeof(InputT)))); + + using SelectIfPolicyT = AgentSelectIfPolicy<128, + ITEMS_PER_THREAD, + BLOCK_LOAD_DIRECT, + MayAlias ? LOAD_CA : LOAD_LDG, + BLOCK_SCAN_WARP_SCANS, + detail::fixed_delay_constructor_t<350, 450>>; + }; + + struct Policy350 + : DefaultTuning + , ChainedPolicy<350, Policy350, Policy350> + {}; + + struct Policy800 : ChainedPolicy<800, Policy800, Policy350> + { + using tuning = detail::select::sm80_tuning(), + select::are_rejects_kept(), + select::classify_offset_size()>; + + using SelectIfPolicyT = AgentSelectIfPolicy; + }; + + struct Policy860 + : DefaultTuning + , ChainedPolicy<860, Policy860, Policy800> + {}; + + struct Policy900 : ChainedPolicy<900, Policy900, Policy860> + { + using tuning = detail::select::sm90_tuning(), + select::are_rejects_kept(), + select::classify_offset_size()>; + + using SelectIfPolicyT = AgentSelectIfPolicy; + }; + + using MaxPolicy = Policy900; +}; + +} // detail + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_three_way_partition.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_three_way_partition.cuh new file mode 100644 index 0000000000000000000000000000000000000000..8c8fabe79e0297fd20c778d2a69354e7ecdf73ff --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_three_way_partition.cuh @@ -0,0 +1,327 @@ +/****************************************************************************** + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +namespace three_way_partition +{ + +enum class input_size +{ + _1, + _2, + _4, + _8, + _16, + unknown +}; + +enum class offset_size +{ + _4, + _8, + unknown +}; + +template +constexpr input_size classify_input_size() +{ + return sizeof(InputT) == 1 ? input_size::_1 + : sizeof(InputT) == 2 ? input_size::_2 + : sizeof(InputT) == 4 ? input_size::_4 + : sizeof(InputT) == 8 ? input_size::_8 + : sizeof(InputT) == 16 ? input_size::_16 + : input_size::unknown; +} + +template +constexpr offset_size classify_offset_size() +{ + return sizeof(OffsetT) == 4 ? offset_size::_4 + : sizeof(OffsetT) == 8 ? offset_size::_8 + : offset_size::unknown; +} + +template (), + offset_size OffsetSize = classify_offset_size()> +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = Nominal4BItemsToItems(9); + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using AccumPackHelperT = detail::three_way_partition::accumulator_pack_t; + using AccumPackT = typename AccumPackHelperT::pack_t; + using delay_constructor = detail::default_delay_constructor_t; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<445>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<104, 512>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 320; + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::no_delay_constructor_t<1105>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 384; + static constexpr int items = 7; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<464, 1165>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 128; + static constexpr int items = 7; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1040>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 24; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using delay_constructor = detail::fixed_delay_constructor_t<4, 285>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 640; + static constexpr int items = 24; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<245>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<910>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 18; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1145>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1050>; +}; + +template (), + offset_size OffsetSize = classify_offset_size()> +struct sm80_tuning +{ + static constexpr int threads = 256; + static constexpr int items = Nominal4BItemsToItems(9); + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + using AccumPackHelperT = detail::three_way_partition::accumulator_pack_t; + using AccumPackT = typename AccumPackHelperT::pack_t; + using delay_constructor = detail::default_delay_constructor_t; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<910>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 256; + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::no_delay_constructor_t<1120>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 224; + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<264, 1080>; +}; + +template +struct sm80_tuning +{ + static constexpr int threads = 128; + static constexpr int items = 10; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + using delay_constructor = detail::fixed_delay_constructor_t<672, 1120>; +}; + +} // namespace three_way_partition + +template +struct device_three_way_partition_policy_hub +{ + struct DefaultTuning + { + constexpr static int ITEMS_PER_THREAD = Nominal4BItemsToItems(9); + + using ThreeWayPartitionPolicy = cub::AgentThreeWayPartitionPolicy<256, + ITEMS_PER_THREAD, + cub::BLOCK_LOAD_DIRECT, + cub::LOAD_DEFAULT, + cub::BLOCK_SCAN_WARP_SCANS>; + }; + + /// SM35 + struct Policy350 + : DefaultTuning + , ChainedPolicy<350, Policy350, Policy350> + {}; + + struct Policy800 : ChainedPolicy<800, Policy800, Policy350> + { + using tuning = detail::three_way_partition::sm80_tuning; + + using ThreeWayPartitionPolicy = + AgentThreeWayPartitionPolicy; + }; + + struct Policy860 + : DefaultTuning + , ChainedPolicy<860, Policy860, Policy800> + {}; + + /// SM90 + struct Policy900 : ChainedPolicy<900, Policy900, Policy860> + { + using tuning = detail::three_way_partition::sm90_tuning; + + using ThreeWayPartitionPolicy = + AgentThreeWayPartitionPolicy; + }; + + using MaxPolicy = Policy900; +}; + +} // namespace detail + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_unique_by_key.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_unique_by_key.cuh new file mode 100644 index 0000000000000000000000000000000000000000..360e555e31157f6ec7aee0d4b9ad7bf7c0c55f60 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/device/dispatch/tuning/tuning_unique_by_key.cuh @@ -0,0 +1,475 @@ +/****************************************************************************** + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +namespace unique_by_key +{ + +enum class primitive_key +{ + no, + yes +}; +enum class primitive_val +{ + no, + yes +}; +enum class key_size +{ + _1, + _2, + _4, + _8, + _16, + unknown +}; +enum class val_size +{ + _1, + _2, + _4, + _8, + _16, + unknown +}; + +template +constexpr primitive_key is_primitive_key() +{ + return Traits::PRIMITIVE ? primitive_key::yes : primitive_key::no; +} + +template +constexpr primitive_val is_primitive_val() +{ + return Traits::PRIMITIVE ? primitive_val::yes : primitive_val::no; +} + +template +constexpr key_size classify_key_size() +{ + return sizeof(KeyT) == 1 ? key_size::_1 + : sizeof(KeyT) == 2 ? key_size::_2 + : sizeof(KeyT) == 4 ? key_size::_4 + : sizeof(KeyT) == 8 ? key_size::_8 + : sizeof(KeyT) == 16 ? key_size::_16 + : key_size::unknown; +} + +template +constexpr val_size classify_val_size() +{ + return sizeof(ValueT) == 1 ? val_size::_1 + : sizeof(ValueT) == 2 ? val_size::_2 + : sizeof(ValueT) == 4 ? val_size::_4 + : sizeof(ValueT) == 8 ? val_size::_8 + : sizeof(ValueT) == 16 ? val_size::_16 + : val_size::unknown; +} + +template (), + primitive_val PrimitiveAccum = is_primitive_val(), + key_size KeySize = classify_key_size(), + val_size AccumSize = classify_val_size()> +struct sm90_tuning +{ + static constexpr int threads = 64; + + static constexpr int nominal_4b_items_per_thread = 11; + + static constexpr int items = Nominal4BItemsToItems(nominal_4b_items_per_thread); + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr CacheLoadModifier load_modifier = LOAD_LDG; + + using delay_constructor = detail::default_delay_constructor_t; +}; + +// 8-bit key +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<550>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 448; + + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<725>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<1130>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 512; + + static constexpr int items = 10; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<1100>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 288; + + static constexpr int items = 7; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::fixed_delay_constructor_t<344, 1165>; +}; + +// 16-bit key +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<640>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 288; + + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::fixed_delay_constructor_t<404, 710>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 512; + + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<525>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 23; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<1200>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 224; + + static constexpr int items = 9; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::fixed_delay_constructor_t<424, 1055>; +}; + +// 32-bit key +template +struct sm90_tuning +{ + static constexpr int threads = 448; + + static constexpr int items = 12; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::fixed_delay_constructor_t<348, 580>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 384; + + static constexpr int items = 9; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<1060>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 512; + + static constexpr int items = 14; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<1045>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 512; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<1120>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 384; + + static constexpr int items = 7; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<1025>; +}; + +// 64-bit key +template +struct sm90_tuning +{ + static constexpr int threads = 384; + + static constexpr int items = 9; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<1060>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 384; + + static constexpr int items = 9; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::fixed_delay_constructor_t<964, 1125>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 640; + + static constexpr int items = 7; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<1070>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 448; + + static constexpr int items = 11; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<1190>; +}; + +template +struct sm90_tuning +{ + static constexpr int threads = 256; + + static constexpr int items = 9; + + static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_WARP_TRANSPOSE; + + static constexpr CacheLoadModifier load_modifier = LOAD_DEFAULT; + + using delay_constructor = detail::no_delay_constructor_t<1155>; +}; + +} // namespace unique_by_key +} // namespace detail + +template +struct DeviceUniqueByKeyPolicy +{ + using KeyT = typename std::iterator_traits::value_type; + using ValueT = typename std::iterator_traits::value_type; + + // SM350 + struct Policy350 : ChainedPolicy<350, Policy350, Policy350> + { + const static int INPUT_SIZE = sizeof(KeyT); + enum + { + NOMINAL_4B_ITEMS_PER_THREAD = 9, + ITEMS_PER_THREAD = Nominal4BItemsToItems(NOMINAL_4B_ITEMS_PER_THREAD), + }; + + using UniqueByKeyPolicyT = AgentUniqueByKeyPolicy<128, + ITEMS_PER_THREAD, + cub::BLOCK_LOAD_WARP_TRANSPOSE, + cub::LOAD_LDG, + cub::BLOCK_SCAN_WARP_SCANS, + detail::default_delay_constructor_t>; + }; + + // SM520 + struct Policy520 : ChainedPolicy<520, Policy520, Policy350> + { + const static int INPUT_SIZE = sizeof(KeyT); + enum + { + NOMINAL_4B_ITEMS_PER_THREAD = 11, + ITEMS_PER_THREAD = Nominal4BItemsToItems(NOMINAL_4B_ITEMS_PER_THREAD), + }; + + using UniqueByKeyPolicyT = AgentUniqueByKeyPolicy<64, + ITEMS_PER_THREAD, + cub::BLOCK_LOAD_WARP_TRANSPOSE, + cub::LOAD_LDG, + cub::BLOCK_SCAN_WARP_SCANS, + detail::default_delay_constructor_t>; + }; + + /// SM90 + struct Policy900 : ChainedPolicy<900, Policy900, Policy520> + { + using tuning = detail::unique_by_key::sm90_tuning; + + using UniqueByKeyPolicyT = AgentUniqueByKeyPolicy; + }; + + using MaxPolicy = Policy900; +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_barrier.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_barrier.cuh new file mode 100644 index 0000000000000000000000000000000000000000..ca946f3cc84095ce9150160107a956e8cff9bd75 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_barrier.cuh @@ -0,0 +1,206 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::GridBarrier implements a software global barrier among thread blocks within a CUDA grid + */ + +#pragma once + +#include "../util_debug.cuh" +#include "../config.cuh" +#include "../thread/thread_load.cuh" + +CUB_NAMESPACE_BEGIN + + +/** + * \addtogroup GridModule + * @{ + */ + + +/** + * \brief GridBarrier implements a software global barrier among thread blocks within a CUDA grid + */ +class GridBarrier +{ +protected : + + typedef unsigned int SyncFlag; + + // Counters in global device memory + SyncFlag* d_sync; + +public: + + /** + * Constructor + */ + GridBarrier() : d_sync(NULL) {} + + + /** + * Synchronize + */ + __device__ __forceinline__ void Sync() const + { + volatile SyncFlag *d_vol_sync = d_sync; + + // Threadfence and syncthreads to make sure global writes are visible before + // thread-0 reports in with its sync counter + __threadfence(); + CTA_SYNC(); + + if (blockIdx.x == 0) + { + // Report in ourselves + if (threadIdx.x == 0) + { + d_vol_sync[blockIdx.x] = 1; + } + + CTA_SYNC(); + + // Wait for everyone else to report in + for (int peer_block = threadIdx.x; peer_block < gridDim.x; peer_block += blockDim.x) + { + while (ThreadLoad(d_sync + peer_block) == 0) + { + __threadfence_block(); + } + } + + CTA_SYNC(); + + // Let everyone know it's safe to proceed + for (int peer_block = threadIdx.x; peer_block < gridDim.x; peer_block += blockDim.x) + { + d_vol_sync[peer_block] = 0; + } + } + else + { + if (threadIdx.x == 0) + { + // Report in + d_vol_sync[blockIdx.x] = 1; + + // Wait for acknowledgment + while (ThreadLoad(d_sync + blockIdx.x) == 1) + { + __threadfence_block(); + } + } + + CTA_SYNC(); + } + } +}; + + +/** + * \brief GridBarrierLifetime extends GridBarrier to provide lifetime management of the temporary device storage needed for cooperation. + * + * Uses RAII for lifetime, i.e., device resources are reclaimed when + * the destructor is called. + */ +class GridBarrierLifetime : public GridBarrier +{ +protected: + + // Number of bytes backed by d_sync + size_t sync_bytes; + +public: + + /** + * Constructor + */ + GridBarrierLifetime() : GridBarrier(), sync_bytes(0) {} + + + /** + * DeviceFrees and resets the progress counters + */ + cudaError_t HostReset() + { + cudaError_t retval = cudaSuccess; + if (d_sync) + { + CubDebug(retval = cudaFree(d_sync)); + d_sync = NULL; + } + sync_bytes = 0; + return retval; + } + + + /** + * Destructor + */ + virtual ~GridBarrierLifetime() + { + HostReset(); + } + + + /** + * Sets up the progress counters for the next kernel launch (lazily + * allocating and initializing them if necessary) + */ + cudaError_t Setup(int sweep_grid_size) + { + cudaError_t retval = cudaSuccess; + do { + size_t new_sync_bytes = sweep_grid_size * sizeof(SyncFlag); + if (new_sync_bytes > sync_bytes) + { + if (d_sync) + { + if (CubDebug(retval = cudaFree(d_sync))) break; + } + + sync_bytes = new_sync_bytes; + + // Allocate and initialize to zero + if (CubDebug(retval = cudaMalloc((void**) &d_sync, sync_bytes))) break; + if (CubDebug(retval = cudaMemset(d_sync, 0, new_sync_bytes))) break; + } + } while (0); + + return retval; + } +}; + + +/** @} */ // end group GridModule + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_even_share.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_even_share.cuh new file mode 100644 index 0000000000000000000000000000000000000000..d2150511321c299680f42d49aefb86183fba0bb5 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_even_share.cuh @@ -0,0 +1,222 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::GridEvenShare is a descriptor utility for distributing input among CUDA thread blocks in an "even-share" fashion. Each thread block gets roughly the same number of fixed-size work units (grains). + */ + + +#pragma once + +#include "../config.cuh" +#include "../util_namespace.cuh" +#include "../util_macro.cuh" +#include "../util_math.cuh" +#include "../util_type.cuh" +#include "grid_mapping.cuh" + +CUB_NAMESPACE_BEGIN + + +/** + * \addtogroup GridModule + * @{ + */ + + +/** + * \brief GridEvenShare is a descriptor utility for distributing input among + * CUDA thread blocks in an "even-share" fashion. Each thread block gets roughly + * the same number of input tiles. + * + * \par Overview + * Each thread block is assigned a consecutive sequence of input tiles. To help + * preserve alignment and eliminate the overhead of guarded loads for all but the + * last thread block, to GridEvenShare assigns one of three different amounts of + * work to a given thread block: "big", "normal", or "last". The "big" workloads + * are one scheduling grain larger than "normal". The "last" work unit for the + * last thread block may be partially-full if the input is not an even multiple of + * the scheduling grain size. + * + * \par + * Before invoking a child grid, a parent thread will typically construct an + * instance of GridEvenShare. The instance can be passed to child thread blocks + * which can initialize their per-thread block offsets using \p BlockInit(). + */ +template +struct GridEvenShare +{ +private: + + int total_tiles; + int big_shares; + OffsetT big_share_items; + OffsetT normal_share_items; + OffsetT normal_base_offset; + +public: + + /// Total number of input items + OffsetT num_items; + + /// Grid size in thread blocks + int grid_size; + + /// OffsetT into input marking the beginning of the owning thread block's segment of input tiles + OffsetT block_offset; + + /// OffsetT into input of marking the end (one-past) of the owning thread block's segment of input tiles + OffsetT block_end; + + /// Stride between input tiles + OffsetT block_stride; + + + /** + * \brief Constructor. + */ + __host__ __device__ __forceinline__ GridEvenShare() : + total_tiles(0), + big_shares(0), + big_share_items(0), + normal_share_items(0), + normal_base_offset(0), + num_items(0), + grid_size(0), + block_offset(0), + block_end(0), + block_stride(0) + {} + + + /** + * \brief Dispatch initializer. To be called prior prior to kernel launch. + */ + __host__ __device__ __forceinline__ void DispatchInit( + OffsetT num_items_, ///< Total number of input items + int max_grid_size, ///< Maximum grid size allowable (actual grid size may be less if not warranted by the the number of input items) + int tile_items) ///< Number of data items per input tile + { + this->block_offset = num_items_; // Initialize past-the-end + this->block_end = num_items_; // Initialize past-the-end + this->num_items = num_items_; + this->total_tiles = static_cast(cub::DivideAndRoundUp(num_items_, tile_items)); + this->grid_size = CUB_MIN(total_tiles, max_grid_size); + int avg_tiles_per_block = total_tiles / grid_size; + // leftover grains go to big blocks: + this->big_shares = total_tiles - (avg_tiles_per_block * grid_size); + this->normal_share_items = avg_tiles_per_block * tile_items; + this->normal_base_offset = big_shares * tile_items; + this->big_share_items = normal_share_items + tile_items; + } + + + /** + * \brief Initializes ranges for the specified thread block index. Specialized + * for a "raking" access pattern in which each thread block is assigned a + * consecutive sequence of input tiles. + */ + template + __device__ __forceinline__ void BlockInit( + int block_id, + Int2Type /*strategy_tag*/) + { + block_stride = TILE_ITEMS; + if (block_id < big_shares) + { + // This thread block gets a big share of grains (avg_tiles_per_block + 1) + block_offset = (block_id * big_share_items); + block_end = block_offset + big_share_items; + } + else if (block_id < total_tiles) + { + // This thread block gets a normal share of grains (avg_tiles_per_block) + block_offset = normal_base_offset + (block_id * normal_share_items); + // Avoid generating values greater than num_items, as it may cause overflow + block_end = block_offset + CUB_MIN(num_items - block_offset, normal_share_items); + } + // Else default past-the-end + } + + + /** + * \brief Block-initialization, specialized for a "raking" access + * pattern in which each thread block is assigned a consecutive sequence + * of input tiles. + */ + template + __device__ __forceinline__ void BlockInit( + int block_id, + Int2Type /*strategy_tag*/) + { + block_stride = grid_size * TILE_ITEMS; + block_offset = (block_id * TILE_ITEMS); + block_end = num_items; + } + + + /** + * \brief Block-initialization, specialized for "strip mining" access + * pattern in which the input tiles assigned to each thread block are + * separated by a stride equal to the the extent of the grid. + */ + template < + int TILE_ITEMS, + GridMappingStrategy STRATEGY> + __device__ __forceinline__ void BlockInit() + { + BlockInit(blockIdx.x, Int2Type()); + } + + + /** + * \brief Block-initialization, specialized for a "raking" access + * pattern in which each thread block is assigned a consecutive sequence + * of input tiles. + */ + template + __device__ __forceinline__ void BlockInit( + OffsetT block_offset, ///< [in] Threadblock begin offset (inclusive) + OffsetT block_end) ///< [in] Threadblock end offset (exclusive) + { + this->block_offset = block_offset; + this->block_end = block_end; + this->block_stride = TILE_ITEMS; + } + + +}; + + + + + +/** @} */ // end group GridModule + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_mapping.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_mapping.cuh new file mode 100644 index 0000000000000000000000000000000000000000..b57f193deb883f421076fc52bff75f23423251d6 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_mapping.cuh @@ -0,0 +1,108 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::GridMappingStrategy enumerates alternative strategies for mapping constant-sized tiles of device-wide data onto a grid of CUDA thread blocks. + */ + +#pragma once + +#include "../config.cuh" + +CUB_NAMESPACE_BEGIN + + +/** + * \addtogroup GridModule + * @{ + */ + + +/****************************************************************************** + * Mapping policies + *****************************************************************************/ + + +/** + * \brief cub::GridMappingStrategy enumerates alternative strategies for mapping constant-sized tiles of device-wide data onto a grid of CUDA thread blocks. + */ +enum GridMappingStrategy +{ + /** + * \brief An a "raking" access pattern in which each thread block is + * assigned a consecutive sequence of input tiles + * + * \par Overview + * The input is evenly partitioned into \p p segments, where \p p is + * constant and corresponds loosely to the number of thread blocks that may + * actively reside on the target device. Each segment is comprised of + * consecutive tiles, where a tile is a small, constant-sized unit of input + * to be processed to completion before the thread block terminates or + * obtains more work. The kernel invokes \p p thread blocks, each + * of which iteratively consumes a segment of n/p elements + * in tile-size increments. + */ + GRID_MAPPING_RAKE, + + /** + * \brief An a "strip mining" access pattern in which the input tiles assigned + * to each thread block are separated by a stride equal to the the extent of + * the grid. + * + * \par Overview + * The input is evenly partitioned into \p p sets, where \p p is + * constant and corresponds loosely to the number of thread blocks that may + * actively reside on the target device. Each set is comprised of + * data tiles separated by stride \p tiles, where a tile is a small, + * constant-sized unit of input to be processed to completion before the + * thread block terminates or obtains more work. The kernel invokes \p p + * thread blocks, each of which iteratively consumes a segment of + * n/p elements in tile-size increments. + */ + GRID_MAPPING_STRIP_MINE, + + /** + * \brief A dynamic "queue-based" strategy for assigning input tiles to thread blocks. + * + * \par Overview + * The input is treated as a queue to be dynamically consumed by a grid of + * thread blocks. Work is atomically dequeued in tiles, where a tile is a + * unit of input to be processed to completion before the thread block + * terminates or obtains more work. The grid size \p p is constant, + * loosely corresponding to the number of thread blocks that may actively + * reside on the target device. + */ + GRID_MAPPING_DYNAMIC, +}; + + +/** @} */ // end group GridModule + +CUB_NAMESPACE_END + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_queue.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_queue.cuh new file mode 100644 index 0000000000000000000000000000000000000000..e1933e3d3819b0ad251857cb10312d0ccf93babd --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/grid/grid_queue.cuh @@ -0,0 +1,237 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::GridQueue is a descriptor utility for dynamic queue management. + */ + +#pragma once + +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + + +/** + * \addtogroup GridModule + * @{ + */ + + +/** + * \brief GridQueue is a descriptor utility for dynamic queue management. + * + * \par Overview + * GridQueue descriptors provides abstractions for "filling" or + * "draining" globally-shared vectors. + * + * \par + * A "filling" GridQueue works by atomically-adding to a zero-initialized counter, + * returning a unique offset for the calling thread to write its items. + * The GridQueue maintains the total "fill-size". The fill counter must be reset + * using GridQueue::ResetFill by the host or kernel instance prior to the kernel instance that + * will be filling. + * + * \par + * Similarly, a "draining" GridQueue works by works by atomically-incrementing a + * zero-initialized counter, returning a unique offset for the calling thread to + * read its items. Threads can safely drain until the array's logical fill-size is + * exceeded. The drain counter must be reset using GridQueue::ResetDrain or + * GridQueue::FillAndResetDrain by the host or kernel instance prior to the kernel instance that + * will be filling. (For dynamic work distribution of existing data, the corresponding fill-size + * is simply the number of elements in the array.) + * + * \par + * Iterative work management can be implemented simply with a pair of flip-flopping + * work buffers, each with an associated set of fill and drain GridQueue descriptors. + * + * \tparam OffsetT Signed integer type for global offsets + */ +template +class GridQueue +{ +private: + + /// Counter indices + enum + { + FILL = 0, + DRAIN = 1, + }; + + /// Pair of counters + OffsetT *d_counters; + +public: + + /// Returns the device allocation size in bytes needed to construct a GridQueue instance + __host__ __device__ __forceinline__ + static size_t AllocationSize() + { + return sizeof(OffsetT) * 2; + } + + + /// Constructs an invalid GridQueue descriptor + __host__ __device__ __forceinline__ GridQueue() + : + d_counters(NULL) + {} + + + /// Constructs a GridQueue descriptor around the device storage allocation + __host__ __device__ __forceinline__ GridQueue( + void *d_storage) ///< Device allocation to back the GridQueue. Must be at least as big as AllocationSize(). + : + d_counters((OffsetT*) d_storage) + {} + + + /// This operation sets the fill-size and resets the drain counter, preparing the GridQueue for draining in the next kernel instance. To be called by the host or by a kernel prior to that which will be draining. + __host__ __device__ __forceinline__ cudaError_t FillAndResetDrain( + OffsetT fill_size, + cudaStream_t stream = 0) + { + cudaError_t result = cudaErrorUnknown; + + NV_IF_TARGET(NV_IS_DEVICE, + ( + (void)stream; + d_counters[FILL] = fill_size; + d_counters[DRAIN] = 0; + result = cudaSuccess; + ), ( + OffsetT counters[2]; + counters[FILL] = fill_size; + counters[DRAIN] = 0; + result = CubDebug(cudaMemcpyAsync(d_counters, counters, sizeof(OffsetT) * 2, cudaMemcpyHostToDevice, stream)); + )); + + return result; + } + + + /// This operation resets the drain so that it may advance to meet the existing fill-size. To be called by the host or by a kernel prior to that which will be draining. + __host__ __device__ __forceinline__ cudaError_t ResetDrain(cudaStream_t stream = 0) + { + cudaError_t result = cudaErrorUnknown; + + NV_IF_TARGET(NV_IS_DEVICE, + ( + (void)stream; + d_counters[DRAIN] = 0; + result = cudaSuccess; + ), ( + result = CubDebug(cudaMemsetAsync(d_counters + DRAIN, 0, sizeof(OffsetT), stream)); + )); + + return result; + } + + + /// This operation resets the fill counter. To be called by the host or by a kernel prior to that which will be filling. + __host__ __device__ __forceinline__ cudaError_t ResetFill(cudaStream_t stream = 0) + { + cudaError_t result = cudaErrorUnknown; + + NV_IF_TARGET(NV_IS_DEVICE, + ( + (void)stream; + d_counters[FILL] = 0; + result = cudaSuccess; + ), ( + result = CubDebug(cudaMemsetAsync(d_counters + FILL, 0, sizeof(OffsetT), stream)); + )); + + return result; + } + + + /// Returns the fill-size established by the parent or by the previous kernel. + __host__ __device__ __forceinline__ cudaError_t FillSize( + OffsetT &fill_size, + cudaStream_t stream = 0) + { + cudaError_t result = cudaErrorUnknown; + + NV_IF_TARGET(NV_IS_DEVICE, + ( + (void)stream; + fill_size = d_counters[FILL]; + result = cudaSuccess; + ), ( + result = CubDebug(cudaMemcpyAsync(&fill_size, d_counters + FILL, sizeof(OffsetT), cudaMemcpyDeviceToHost, stream)); + )); + + return result; + } + + + /// Drain \p num_items from the queue. Returns offset from which to read items. To be called from CUDA kernel. + __device__ __forceinline__ OffsetT Drain(OffsetT num_items) + { + return atomicAdd(d_counters + DRAIN, num_items); + } + + + /// Fill \p num_items into the queue. Returns offset from which to write items. To be called from CUDA kernel. + __device__ __forceinline__ OffsetT Fill(OffsetT num_items) + { + return atomicAdd(d_counters + FILL, num_items); + } +}; + + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + + +/** + * Reset grid queue (call with 1 block of 1 thread) + */ +template +__global__ void FillAndResetDrainKernel( + GridQueue grid_queue, + OffsetT num_items) +{ + grid_queue.FillAndResetDrain(num_items); +} + + + +#endif // DOXYGEN_SHOULD_SKIP_THIS + + +/** @} */ // end group GridModule + +CUB_NAMESPACE_END + + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/host/mutex.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/host/mutex.cuh new file mode 100644 index 0000000000000000000000000000000000000000..4ee4028845295ce43fb12a8af5a6d10396456d63 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/host/mutex.cuh @@ -0,0 +1,66 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Simple portable mutex + */ + +#pragma once + +#include + +#include +#include + + +CUB_NAMESPACE_BEGIN + + +/** + * Wraps std::mutex + * @deprecated [Since CUB 2.1.0] The `cub::Mutex` is deprecated and will be removed + * in a future release. Use `std::mutex` instead. + */ +struct CUB_DEPRECATED Mutex +{ + std::mutex mtx; + + void Lock() + { + mtx.lock(); + } + + void Unlock() + { + mtx.unlock(); + } +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/arg_index_input_iterator.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/arg_index_input_iterator.cuh new file mode 100644 index 0000000000000000000000000000000000000000..822869a5a54ef9d7aa79cdf223c6ffabfbc55496 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/arg_index_input_iterator.cuh @@ -0,0 +1,254 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Random-access iterator types + */ + +#pragma once + +#include +#include + +#include "../config.cuh" +#include "../thread/thread_load.cuh" +#include "../thread/thread_store.cuh" +#include "../util_device.cuh" + +#include + +#if (THRUST_VERSION >= 100700) + // This iterator is compatible with Thrust API 1.7 and newer + #include + #include +#endif // THRUST_VERSION + +CUB_NAMESPACE_BEGIN + +/** + * \addtogroup UtilIterator + * @{ + */ + + +/** + * \brief A random-access input wrapper for pairing dereferenced values with their corresponding indices (forming \p KeyValuePair tuples). + * + * \par Overview + * - ArgIndexInputIteratorTwraps a random access input iterator \p itr of type \p InputIteratorT. + * Dereferencing an ArgIndexInputIteratorTat offset \p i produces a \p KeyValuePair value whose + * \p key field is \p i and whose \p value field is itr[i]. + * - Can be used with any data type. + * - Can be constructed, manipulated, and exchanged within and between host and device + * functions. Wrapped host memory can only be dereferenced on the host, and wrapped + * device memory can only be dereferenced on the device. + * - Compatible with Thrust API v1.7 or newer. + * + * \par Snippet + * The code snippet below illustrates the use of \p ArgIndexInputIteratorTto + * dereference an array of doubles + * \par + * \code + * #include // or equivalently + * + * // Declare, allocate, and initialize a device array + * double *d_in; // e.g., [8.0, 6.0, 7.0, 5.0, 3.0, 0.0, 9.0] + * + * // Create an iterator wrapper + * cub::ArgIndexInputIterator itr(d_in); + * + * // Within device code: + * typedef typename cub::ArgIndexInputIterator::value_type Tuple; + * Tuple item_offset_pair.key = *itr; + * printf("%f @ %d\n", + * item_offset_pair.value, + * item_offset_pair.key); // 8.0 @ 0 + * + * itr = itr + 6; + * item_offset_pair.key = *itr; + * printf("%f @ %d\n", + * item_offset_pair.value, + * item_offset_pair.key); // 9.0 @ 6 + * + * \endcode + * + * \tparam InputIteratorT The value type of the wrapped input iterator + * \tparam OffsetT The difference type of this iterator (Default: \p ptrdiff_t) + * \tparam OutputValueT The paired value type of the tuple (Default: value type of input iterator) + */ +template < + typename InputIteratorT, + typename OffsetT = ptrdiff_t, + typename OutputValueT = cub::detail::value_t> +class ArgIndexInputIterator +{ +public: + + // Required iterator traits + typedef ArgIndexInputIterator self_type; ///< My own type + typedef OffsetT difference_type; ///< Type to express the result of subtracting one iterator from another + typedef KeyValuePair value_type; ///< The type of the element the iterator can point to + typedef value_type* pointer; ///< The type of a pointer to an element the iterator can point to + typedef value_type reference; ///< The type of a reference to an element the iterator can point to + +#if (THRUST_VERSION >= 100700) + // Use Thrust's iterator categories so we can use these iterators in Thrust 1.7 (or newer) methods + typedef typename THRUST_NS_QUALIFIER::detail::iterator_facade_category< + THRUST_NS_QUALIFIER::any_system_tag, + THRUST_NS_QUALIFIER::random_access_traversal_tag, + value_type, + reference + >::type iterator_category; ///< The iterator category +#else + typedef std::random_access_iterator_tag iterator_category; ///< The iterator category +#endif // THRUST_VERSION + +private: + + InputIteratorT itr; + difference_type offset; + +public: + + /// Constructor + __host__ __device__ __forceinline__ ArgIndexInputIterator( + InputIteratorT itr, ///< Input iterator to wrap + difference_type offset = 0) ///< OffsetT (in items) from \p itr denoting the position of the iterator + : + itr(itr), + offset(offset) + {} + + /// Postfix increment + __host__ __device__ __forceinline__ self_type operator++(int) + { + self_type retval = *this; + offset++; + return retval; + } + + /// Prefix increment + __host__ __device__ __forceinline__ self_type operator++() + { + offset++; + return *this; + } + + /// Indirection + __host__ __device__ __forceinline__ reference operator*() const + { + value_type retval; + retval.value = itr[offset]; + retval.key = offset; + return retval; + } + + /// Addition + template + __host__ __device__ __forceinline__ self_type operator+(Distance n) const + { + self_type retval(itr, offset + n); + return retval; + } + + /// Addition assignment + template + __host__ __device__ __forceinline__ self_type& operator+=(Distance n) + { + offset += n; + return *this; + } + + /// Subtraction + template + __host__ __device__ __forceinline__ self_type operator-(Distance n) const + { + self_type retval(itr, offset - n); + return retval; + } + + /// Subtraction assignment + template + __host__ __device__ __forceinline__ self_type& operator-=(Distance n) + { + offset -= n; + return *this; + } + + /// Distance + __host__ __device__ __forceinline__ difference_type operator-(self_type other) const + { + return offset - other.offset; + } + + /// Array subscript + template + __host__ __device__ __forceinline__ reference operator[](Distance n) const + { + self_type offset = (*this) + n; + return *offset; + } + + /// Structure dereference + __host__ __device__ __forceinline__ pointer operator->() + { + return &(*(*this)); + } + + /// Equal to + __host__ __device__ __forceinline__ bool operator==(const self_type& rhs) + { + return ((itr == rhs.itr) && (offset == rhs.offset)); + } + + /// Not equal to + __host__ __device__ __forceinline__ bool operator!=(const self_type& rhs) + { + return ((itr != rhs.itr) || (offset != rhs.offset)); + } + + /// Normalize + __host__ __device__ __forceinline__ void normalize() + { + itr += offset; + offset = 0; + } + + /// ostream operator + friend std::ostream& operator<<(std::ostream& os, const self_type& /*itr*/) + { + return os; + } +}; + + + +/** @} */ // end group UtilIterator + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/cache_modified_input_iterator.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/cache_modified_input_iterator.cuh new file mode 100644 index 0000000000000000000000000000000000000000..6dcf2c8c02f9adfdea53891e5a949b322ab8c6ca --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/cache_modified_input_iterator.cuh @@ -0,0 +1,235 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Random-access iterator types + */ + +#pragma once + +#include +#include + +#include "../config.cuh" +#include "../thread/thread_load.cuh" +#include "../thread/thread_store.cuh" +#include "../util_device.cuh" + +#if (THRUST_VERSION >= 100700) + // This iterator is compatible with Thrust API 1.7 and newer + #include + #include +#endif // THRUST_VERSION + + +CUB_NAMESPACE_BEGIN + + + +/** + * \addtogroup UtilIterator + * @{ + */ + + +/** + * \brief A random-access input wrapper for dereferencing array values using a PTX cache load modifier. + * + * \par Overview + * - CacheModifiedInputIterator is a random-access input iterator that wraps a native + * device pointer of type ValueType*. \p ValueType references are + * made by reading \p ValueType values through loads modified by \p MODIFIER. + * - Can be used to load any data type from memory using PTX cache load modifiers (e.g., "LOAD_LDG", + * "LOAD_CG", "LOAD_CA", "LOAD_CS", "LOAD_CV", etc.). + * - Can be constructed, manipulated, and exchanged within and between host and device + * functions, but can only be dereferenced within device functions. + * - Compatible with Thrust API v1.7 or newer. + * + * \par Snippet + * The code snippet below illustrates the use of \p CacheModifiedInputIterator to + * dereference a device array of double using the "ldg" PTX load modifier + * (i.e., load values through texture cache). + * \par + * \code + * #include // or equivalently + * + * // Declare, allocate, and initialize a device array + * double *d_in; // e.g., [8.0, 6.0, 7.0, 5.0, 3.0, 0.0, 9.0] + * + * // Create an iterator wrapper + * cub::CacheModifiedInputIterator itr(d_in); + * + * // Within device code: + * printf("%f\n", itr[0]); // 8.0 + * printf("%f\n", itr[1]); // 6.0 + * printf("%f\n", itr[6]); // 9.0 + * + * \endcode + * + * \tparam CacheLoadModifier The cub::CacheLoadModifier to use when accessing data + * \tparam ValueType The value type of this iterator + * \tparam OffsetT The difference type of this iterator (Default: \p ptrdiff_t) + */ +template < + CacheLoadModifier MODIFIER, + typename ValueType, + typename OffsetT = ptrdiff_t> +class CacheModifiedInputIterator +{ +public: + + // Required iterator traits + typedef CacheModifiedInputIterator self_type; ///< My own type + typedef OffsetT difference_type; ///< Type to express the result of subtracting one iterator from another + typedef ValueType value_type; ///< The type of the element the iterator can point to + typedef ValueType* pointer; ///< The type of a pointer to an element the iterator can point to + typedef ValueType reference; ///< The type of a reference to an element the iterator can point to + +#if (THRUST_VERSION >= 100700) + // Use Thrust's iterator categories so we can use these iterators in Thrust 1.7 (or newer) methods + typedef typename THRUST_NS_QUALIFIER::detail::iterator_facade_category< + THRUST_NS_QUALIFIER::device_system_tag, + THRUST_NS_QUALIFIER::random_access_traversal_tag, + value_type, + reference + >::type iterator_category; ///< The iterator category +#else + typedef std::random_access_iterator_tag iterator_category; ///< The iterator category +#endif // THRUST_VERSION + + +public: + + /// Wrapped native pointer + ValueType* ptr; + + /// Constructor + template + __host__ __device__ __forceinline__ CacheModifiedInputIterator( + QualifiedValueType* ptr) ///< Native pointer to wrap + : + ptr(const_cast::type *>(ptr)) + {} + + /// Postfix increment + __host__ __device__ __forceinline__ self_type operator++(int) + { + self_type retval = *this; + ptr++; + return retval; + } + + /// Prefix increment + __host__ __device__ __forceinline__ self_type operator++() + { + ptr++; + return *this; + } + + /// Indirection + __device__ __forceinline__ reference operator*() const + { + return ThreadLoad(ptr); + } + + /// Addition + template + __host__ __device__ __forceinline__ self_type operator+(Distance n) const + { + self_type retval(ptr + n); + return retval; + } + + /// Addition assignment + template + __host__ __device__ __forceinline__ self_type& operator+=(Distance n) + { + ptr += n; + return *this; + } + + /// Subtraction + template + __host__ __device__ __forceinline__ self_type operator-(Distance n) const + { + self_type retval(ptr - n); + return retval; + } + + /// Subtraction assignment + template + __host__ __device__ __forceinline__ self_type& operator-=(Distance n) + { + ptr -= n; + return *this; + } + + /// Distance + __host__ __device__ __forceinline__ difference_type operator-(self_type other) const + { + return ptr - other.ptr; + } + + /// Array subscript + template + __device__ __forceinline__ reference operator[](Distance n) const + { + return ThreadLoad(ptr + n); + } + + /// Structure dereference + __device__ __forceinline__ pointer operator->() + { + return &ThreadLoad(ptr); + } + + /// Equal to + __host__ __device__ __forceinline__ bool operator==(const self_type& rhs) const + { + return (ptr == rhs.ptr); + } + + /// Not equal to + __host__ __device__ __forceinline__ bool operator!=(const self_type& rhs) const + { + return (ptr != rhs.ptr); + } + + /// ostream operator + friend std::ostream& operator<<(std::ostream& os, const self_type& /*itr*/) + { + return os; + } +}; + + + +/** @} */ // end group UtilIterator + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/cache_modified_output_iterator.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/cache_modified_output_iterator.cuh new file mode 100644 index 0000000000000000000000000000000000000000..be08dbce0bffc502b7f130b1a60593989d61748d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/cache_modified_output_iterator.cuh @@ -0,0 +1,249 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Random-access iterator types + */ + +#pragma once + +#include +#include + +#include "../thread/thread_load.cuh" +#include "../thread/thread_store.cuh" +#include "../config.cuh" +#include "../util_device.cuh" + +#if (THRUST_VERSION >= 100700) + // This iterator is compatible with Thrust API 1.7 and newer + #include + #include +#endif // THRUST_VERSION + + +CUB_NAMESPACE_BEGIN + + +/** + * \addtogroup UtilIterator + * @{ + */ + + +/** + * \brief A random-access output wrapper for storing array values using a PTX cache-modifier. + * + * \par Overview + * - CacheModifiedOutputIterator is a random-access output iterator that wraps a native + * device pointer of type ValueType*. \p ValueType references are + * made by writing \p ValueType values through stores modified by \p MODIFIER. + * - Can be used to store any data type to memory using PTX cache store modifiers (e.g., "STORE_WB", + * "STORE_CG", "STORE_CS", "STORE_WT", etc.). + * - Can be constructed, manipulated, and exchanged within and between host and device + * functions, but can only be dereferenced within device functions. + * - Compatible with Thrust API v1.7 or newer. + * + * \par Snippet + * The code snippet below illustrates the use of \p CacheModifiedOutputIterator to + * dereference a device array of doubles using the "wt" PTX load modifier + * (i.e., write-through to system memory). + * \par + * \code + * #include // or equivalently + * + * // Declare, allocate, and initialize a device array + * double *d_out; // e.g., [, , , , , , ] + * + * // Create an iterator wrapper + * cub::CacheModifiedOutputIterator itr(d_out); + * + * // Within device code: + * itr[0] = 8.0; + * itr[1] = 66.0; + * itr[55] = 24.0; + * + * \endcode + * + * \par Usage Considerations + * - Can only be dereferenced within device code + * + * \tparam CacheStoreModifier The cub::CacheStoreModifier to use when accessing data + * \tparam ValueType The value type of this iterator + * \tparam OffsetT The difference type of this iterator (Default: \p ptrdiff_t) + */ +template < + CacheStoreModifier MODIFIER, + typename ValueType, + typename OffsetT = ptrdiff_t> +class CacheModifiedOutputIterator +{ +private: + + // Proxy object + struct Reference + { + ValueType* ptr; + + /// Constructor + __host__ __device__ __forceinline__ Reference(ValueType* ptr) : ptr(ptr) {} + + /// Assignment + __device__ __forceinline__ ValueType operator =(ValueType val) + { + ThreadStore(ptr, val); + return val; + } + }; + +public: + + // Required iterator traits + typedef CacheModifiedOutputIterator self_type; ///< My own type + typedef OffsetT difference_type; ///< Type to express the result of subtracting one iterator from another + typedef void value_type; ///< The type of the element the iterator can point to + typedef void pointer; ///< The type of a pointer to an element the iterator can point to + typedef Reference reference; ///< The type of a reference to an element the iterator can point to + +#if (THRUST_VERSION >= 100700) + // Use Thrust's iterator categories so we can use these iterators in Thrust 1.7 (or newer) methods + typedef typename THRUST_NS_QUALIFIER::detail::iterator_facade_category< + THRUST_NS_QUALIFIER::device_system_tag, + THRUST_NS_QUALIFIER::random_access_traversal_tag, + value_type, + reference + >::type iterator_category; ///< The iterator category +#else + typedef std::random_access_iterator_tag iterator_category; ///< The iterator category +#endif // THRUST_VERSION + +private: + + ValueType* ptr; + +public: + + /// Constructor + template + __host__ __device__ __forceinline__ CacheModifiedOutputIterator( + QualifiedValueType* ptr) ///< Native pointer to wrap + : + ptr(const_cast::type *>(ptr)) + {} + + /// Postfix increment + __host__ __device__ __forceinline__ self_type operator++(int) + { + self_type retval = *this; + ptr++; + return retval; + } + + + /// Prefix increment + __host__ __device__ __forceinline__ self_type operator++() + { + ptr++; + return *this; + } + + /// Indirection + __host__ __device__ __forceinline__ reference operator*() const + { + return Reference(ptr); + } + + /// Addition + template + __host__ __device__ __forceinline__ self_type operator+(Distance n) const + { + self_type retval(ptr + n); + return retval; + } + + /// Addition assignment + template + __host__ __device__ __forceinline__ self_type& operator+=(Distance n) + { + ptr += n; + return *this; + } + + /// Subtraction + template + __host__ __device__ __forceinline__ self_type operator-(Distance n) const + { + self_type retval(ptr - n); + return retval; + } + + /// Subtraction assignment + template + __host__ __device__ __forceinline__ self_type& operator-=(Distance n) + { + ptr -= n; + return *this; + } + + /// Distance + __host__ __device__ __forceinline__ difference_type operator-(self_type other) const + { + return ptr - other.ptr; + } + + /// Array subscript + template + __host__ __device__ __forceinline__ reference operator[](Distance n) const + { + return Reference(ptr + n); + } + + /// Equal to + __host__ __device__ __forceinline__ bool operator==(const self_type& rhs) + { + return (ptr == rhs.ptr); + } + + /// Not equal to + __host__ __device__ __forceinline__ bool operator!=(const self_type& rhs) + { + return (ptr != rhs.ptr); + } + + /// ostream operator + friend std::ostream& operator<<(std::ostream& os, const self_type& itr) + { + return os; + } +}; + + +/** @} */ // end group UtilIterator + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/constant_input_iterator.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/constant_input_iterator.cuh new file mode 100644 index 0000000000000000000000000000000000000000..3de5123df34d45eb2b4d1a4fb2008db321714999 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/constant_input_iterator.cuh @@ -0,0 +1,230 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Random-access iterator types + */ + +#pragma once + +#include +#include + +#include "../thread/thread_load.cuh" +#include "../thread/thread_store.cuh" +#include "../config.cuh" + +#if (THRUST_VERSION >= 100700) + // This iterator is compatible with Thrust API 1.7 and newer + #include + #include +#endif // THRUST_VERSION + + +CUB_NAMESPACE_BEGIN + + +/** + * \addtogroup UtilIterator + * @{ + */ + + +/** + * \brief A random-access input generator for dereferencing a sequence of homogeneous values + * + * \par Overview + * - Read references to a ConstantInputIteratorTiterator always return the supplied constant + * of type \p ValueType. + * - Can be used with any data type. + * - Can be constructed, manipulated, dereferenced, and exchanged within and between host and device + * functions. + * - Compatible with Thrust API v1.7 or newer. + * + * \par Snippet + * The code snippet below illustrates the use of \p ConstantInputIteratorTto + * dereference a sequence of homogeneous doubles. + * \par + * \code + * #include // or equivalently + * + * cub::ConstantInputIterator itr(5.0); + * + * printf("%f\n", itr[0]); // 5.0 + * printf("%f\n", itr[1]); // 5.0 + * printf("%f\n", itr[2]); // 5.0 + * printf("%f\n", itr[50]); // 5.0 + * + * \endcode + * + * \tparam ValueType The value type of this iterator + * \tparam OffsetT The difference type of this iterator (Default: \p ptrdiff_t) + */ +template < + typename ValueType, + typename OffsetT = ptrdiff_t> +class ConstantInputIterator +{ +public: + + // Required iterator traits + typedef ConstantInputIterator self_type; ///< My own type + typedef OffsetT difference_type; ///< Type to express the result of subtracting one iterator from another + typedef ValueType value_type; ///< The type of the element the iterator can point to + typedef ValueType* pointer; ///< The type of a pointer to an element the iterator can point to + typedef ValueType reference; ///< The type of a reference to an element the iterator can point to + +#if (THRUST_VERSION >= 100700) + // Use Thrust's iterator categories so we can use these iterators in Thrust 1.7 (or newer) methods + typedef typename THRUST_NS_QUALIFIER::detail::iterator_facade_category< + THRUST_NS_QUALIFIER::any_system_tag, + THRUST_NS_QUALIFIER::random_access_traversal_tag, + value_type, + reference + >::type iterator_category; ///< The iterator category +#else + typedef std::random_access_iterator_tag iterator_category; ///< The iterator category +#endif // THRUST_VERSION + +private: + + ValueType val; + OffsetT offset; +#ifdef _WIN32 + OffsetT pad[CUB_MAX(1, (16 / sizeof(OffsetT) - 1))]; // Workaround for win32 parameter-passing bug (ulonglong2 argmin DeviceReduce) +#endif + +public: + + /// Constructor + __host__ __device__ __forceinline__ ConstantInputIterator( + ValueType val, ///< Starting value for the iterator instance to report + OffsetT offset = 0) ///< Base offset + : + val(val), + offset(offset) + {} + + /// Postfix increment + __host__ __device__ __forceinline__ self_type operator++(int) + { + self_type retval = *this; + offset++; + return retval; + } + + /// Prefix increment + __host__ __device__ __forceinline__ self_type operator++() + { + offset++; + return *this; + } + + /// Indirection + __host__ __device__ __forceinline__ reference operator*() const + { + return val; + } + + /// Addition + template + __host__ __device__ __forceinline__ self_type operator+(Distance n) const + { + self_type retval(val, offset + n); + return retval; + } + + /// Addition assignment + template + __host__ __device__ __forceinline__ self_type& operator+=(Distance n) + { + offset += n; + return *this; + } + + /// Subtraction + template + __host__ __device__ __forceinline__ self_type operator-(Distance n) const + { + self_type retval(val, offset - n); + return retval; + } + + /// Subtraction assignment + template + __host__ __device__ __forceinline__ self_type& operator-=(Distance n) + { + offset -= n; + return *this; + } + + /// Distance + __host__ __device__ __forceinline__ difference_type operator-(self_type other) const + { + return offset - other.offset; + } + + /// Array subscript + template + __host__ __device__ __forceinline__ reference operator[](Distance /*n*/) const + { + return val; + } + + /// Structure dereference + __host__ __device__ __forceinline__ pointer operator->() + { + return &val; + } + + /// Equal to + __host__ __device__ __forceinline__ bool operator==(const self_type& rhs) const + { + return (offset == rhs.offset) && ((val == rhs.val)); + } + + /// Not equal to + __host__ __device__ __forceinline__ bool operator!=(const self_type& rhs) const + { + return (offset != rhs.offset) || (val!= rhs.val); + } + + /// ostream operator + friend std::ostream& operator<<(std::ostream& os, const self_type& itr) + { + os << "[" << itr.val << "," << itr.offset << "]"; + return os; + } + +}; + + +/** @} */ // end group UtilIterator + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/counting_input_iterator.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/counting_input_iterator.cuh new file mode 100644 index 0000000000000000000000000000000000000000..0272543710e081fb3ecf3e90b7430e13b995e081 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/counting_input_iterator.cuh @@ -0,0 +1,223 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Random-access iterator types + */ + +#pragma once + +#include +#include + +#include "../thread/thread_load.cuh" +#include "../thread/thread_store.cuh" +#include "../config.cuh" +#include "../util_device.cuh" + +#if (THRUST_VERSION >= 100700) + // This iterator is compatible with Thrust API 1.7 and newer + #include + #include +#endif // THRUST_VERSION + + +CUB_NAMESPACE_BEGIN + +/** + * \addtogroup UtilIterator + * @{ + */ + +/** + * \brief A random-access input generator for dereferencing a sequence of incrementing integer values. + * + * \par Overview + * - After initializing a CountingInputIteratorTto a certain integer \p base, read references + * at \p offset will return the value \p base + \p offset. + * - Can be constructed, manipulated, dereferenced, and exchanged within and between host and device + * functions. + * - Compatible with Thrust API v1.7 or newer. + * + * \par Snippet + * The code snippet below illustrates the use of \p CountingInputIteratorTto + * dereference a sequence of incrementing integers. + * \par + * \code + * #include // or equivalently + * + * cub::CountingInputIterator itr(5); + * + * printf("%d\n", itr[0]); // 5 + * printf("%d\n", itr[1]); // 6 + * printf("%d\n", itr[2]); // 7 + * printf("%d\n", itr[50]); // 55 + * + * \endcode + * + * \tparam ValueType The value type of this iterator + * \tparam OffsetT The difference type of this iterator (Default: \p ptrdiff_t) + */ +template < + typename ValueType, + typename OffsetT = ptrdiff_t> +class CountingInputIterator +{ +public: + + // Required iterator traits + typedef CountingInputIterator self_type; ///< My own type + typedef OffsetT difference_type; ///< Type to express the result of subtracting one iterator from another + typedef ValueType value_type; ///< The type of the element the iterator can point to + typedef ValueType* pointer; ///< The type of a pointer to an element the iterator can point to + typedef ValueType reference; ///< The type of a reference to an element the iterator can point to + +#if (THRUST_VERSION >= 100700) + // Use Thrust's iterator categories so we can use these iterators in Thrust 1.7 (or newer) methods + typedef typename THRUST_NS_QUALIFIER::detail::iterator_facade_category< + THRUST_NS_QUALIFIER::any_system_tag, + THRUST_NS_QUALIFIER::random_access_traversal_tag, + value_type, + reference + >::type iterator_category; ///< The iterator category +#else + typedef std::random_access_iterator_tag iterator_category; ///< The iterator category +#endif // THRUST_VERSION + +private: + + ValueType val; + +public: + + /// Constructor + __host__ __device__ __forceinline__ CountingInputIterator( + const ValueType &val) ///< Starting value for the iterator instance to report + : + val(val) + {} + + /// Postfix increment + __host__ __device__ __forceinline__ self_type operator++(int) + { + self_type retval = *this; + val++; + return retval; + } + + /// Prefix increment + __host__ __device__ __forceinline__ self_type operator++() + { + val++; + return *this; + } + + /// Indirection + __host__ __device__ __forceinline__ reference operator*() const + { + return val; + } + + /// Addition + template + __host__ __device__ __forceinline__ self_type operator+(Distance n) const + { + self_type retval(val + (ValueType) n); + return retval; + } + + /// Addition assignment + template + __host__ __device__ __forceinline__ self_type& operator+=(Distance n) + { + val += (ValueType) n; + return *this; + } + + /// Subtraction + template + __host__ __device__ __forceinline__ self_type operator-(Distance n) const + { + self_type retval(val - (ValueType) n); + return retval; + } + + /// Subtraction assignment + template + __host__ __device__ __forceinline__ self_type& operator-=(Distance n) + { + val -= n; + return *this; + } + + /// Distance + __host__ __device__ __forceinline__ difference_type operator-(self_type other) const + { + return (difference_type) (val - other.val); + } + + /// Array subscript + template + __host__ __device__ __forceinline__ reference operator[](Distance n) const + { + return val + (ValueType) n; + } + + /// Structure dereference + __host__ __device__ __forceinline__ pointer operator->() + { + return &val; + } + + /// Equal to + __host__ __device__ __forceinline__ bool operator==(const self_type& rhs) const + { + return (val == rhs.val); + } + + /// Not equal to + __host__ __device__ __forceinline__ bool operator!=(const self_type& rhs) const + { + return (val != rhs.val); + } + + /// ostream operator + friend std::ostream& operator<<(std::ostream& os, const self_type& itr) + { + os << "[" << itr.val << "]"; + return os; + } + +}; + + + +/** @} */ // end group UtilIterator + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/discard_output_iterator.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/discard_output_iterator.cuh new file mode 100644 index 0000000000000000000000000000000000000000..ac47a3ff344026bcf96c05e2981bd2adeccc43db --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/discard_output_iterator.cuh @@ -0,0 +1,208 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Random-access iterator types + */ + +#pragma once + +#include +#include + +#include "../config.cuh" + +#if (THRUST_VERSION >= 100700) + // This iterator is compatible with Thrust API 1.7 and newer + #include + #include +#endif // THRUST_VERSION + + +CUB_NAMESPACE_BEGIN + + +/** + * \addtogroup UtilIterator + * @{ + */ + + +/** + * \brief A discard iterator + */ +template +class DiscardOutputIterator +{ +public: + + // Required iterator traits + typedef DiscardOutputIterator self_type; ///< My own type + typedef OffsetT difference_type; ///< Type to express the result of subtracting one iterator from another + typedef void value_type; ///< The type of the element the iterator can point to + typedef void pointer; ///< The type of a pointer to an element the iterator can point to + typedef void reference; ///< The type of a reference to an element the iterator can point to + +#if (THRUST_VERSION >= 100700) + // Use Thrust's iterator categories so we can use these iterators in Thrust 1.7 (or newer) methods + typedef typename THRUST_NS_QUALIFIER::detail::iterator_facade_category< + THRUST_NS_QUALIFIER::any_system_tag, + THRUST_NS_QUALIFIER::random_access_traversal_tag, + value_type, + reference + >::type iterator_category; ///< The iterator category +#else + typedef std::random_access_iterator_tag iterator_category; ///< The iterator category +#endif // THRUST_VERSION + +private: + + OffsetT offset; + +#if defined(_WIN32) || !defined(_WIN64) + // Workaround for win32 parameter-passing bug (ulonglong2 argmin DeviceReduce) + OffsetT pad[CUB_MAX(1, (16 / sizeof(OffsetT) - 1))] = {}; +#endif + +public: + + /// Constructor + __host__ __device__ __forceinline__ DiscardOutputIterator( + OffsetT offset = 0) ///< Base offset + : + offset(offset) + {} + + /// Postfix increment + __host__ __device__ __forceinline__ self_type operator++(int) + { + self_type retval = *this; + offset++; + return retval; + } + + /// Prefix increment + __host__ __device__ __forceinline__ self_type operator++() + { + offset++; + return *this; + } + + /// Indirection + __host__ __device__ __forceinline__ self_type& operator*() + { + // return self reference, which can be assigned to anything + return *this; + } + + /// Addition + template + __host__ __device__ __forceinline__ self_type operator+(Distance n) const + { + self_type retval(offset + n); + return retval; + } + + /// Addition assignment + template + __host__ __device__ __forceinline__ self_type& operator+=(Distance n) + { + offset += n; + return *this; + } + + /// Subtraction + template + __host__ __device__ __forceinline__ self_type operator-(Distance n) const + { + self_type retval(offset - n); + return retval; + } + + /// Subtraction assignment + template + __host__ __device__ __forceinline__ self_type& operator-=(Distance n) + { + offset -= n; + return *this; + } + + /// Distance + __host__ __device__ __forceinline__ difference_type operator-(self_type other) const + { + return offset - other.offset; + } + + /// Array subscript + template + __host__ __device__ __forceinline__ self_type& operator[](Distance n) + { + // return self reference, which can be assigned to anything + return *this; + } + + /// Structure dereference + __host__ __device__ __forceinline__ pointer operator->() + { + return; + } + + /// Assignment to anything else (no-op) + template + __host__ __device__ __forceinline__ void operator=(T const&) + {} + + /// Cast to void* operator + __host__ __device__ __forceinline__ operator void*() const { return NULL; } + + /// Equal to + __host__ __device__ __forceinline__ bool operator==(const self_type& rhs) + { + return (offset == rhs.offset); + } + + /// Not equal to + __host__ __device__ __forceinline__ bool operator!=(const self_type& rhs) + { + return (offset != rhs.offset); + } + + /// ostream operator + friend std::ostream& operator<<(std::ostream& os, const self_type& itr) + { + os << "[" << itr.offset << "]"; + return os; + } + +}; + + +/** @} */ // end group UtilIterator + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/tex_obj_input_iterator.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/tex_obj_input_iterator.cuh new file mode 100644 index 0000000000000000000000000000000000000000..6ac249ce3186efc703691231d111ed2d10463bfe --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/tex_obj_input_iterator.cuh @@ -0,0 +1,315 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Random-access iterator types + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include + +#include +#include + +#if (THRUST_VERSION >= 100700) + // This iterator is compatible with Thrust API 1.7 and newer + #include + #include +#endif // THRUST_VERSION + + +CUB_NAMESPACE_BEGIN + +/** + * \addtogroup UtilIterator + * @{ + */ + + + +/** + * \brief A random-access input wrapper for dereferencing array values through texture cache. Uses newer Kepler-style texture objects. + * + * \par Overview + * - TexObjInputIterator wraps a native device pointer of type ValueType*. References + * to elements are to be loaded through texture cache. + * - Can be used to load any data type from memory through texture cache. + * - Can be manipulated and exchanged within and between host and device + * functions, can only be constructed within host functions, and can only be + * dereferenced within device functions. + * - With regard to nested/dynamic parallelism, TexObjInputIterator iterators may only be + * created by the host thread, but can be used by any descendant kernel. + * - Compatible with Thrust API v1.7 or newer. + * + * \par Snippet + * The code snippet below illustrates the use of \p TexObjInputIterator to + * dereference a device array of doubles through texture cache. + * \par + * \code + * #include // or equivalently + * + * // Declare, allocate, and initialize a device array + * int num_items; // e.g., 7 + * double *d_in; // e.g., [8.0, 6.0, 7.0, 5.0, 3.0, 0.0, 9.0] + * + * // Create an iterator wrapper + * cub::TexObjInputIterator itr; + * itr.BindTexture(d_in, sizeof(double) * num_items); + * ... + * + * // Within device code: + * printf("%f\n", itr[0]); // 8.0 + * printf("%f\n", itr[1]); // 6.0 + * printf("%f\n", itr[6]); // 9.0 + * + * ... + * itr.UnbindTexture(); + * + * \endcode + * + * \tparam T The value type of this iterator + * \tparam OffsetT The difference type of this iterator (Default: \p ptrdiff_t) + */ +template < + typename T, + typename OffsetT = ptrdiff_t> +class TexObjInputIterator +{ +public: + + // Required iterator traits + typedef TexObjInputIterator self_type; ///< My own type + typedef OffsetT difference_type; ///< Type to express the result of subtracting one iterator from another + typedef T value_type; ///< The type of the element the iterator can point to + typedef T* pointer; ///< The type of a pointer to an element the iterator can point to + typedef T reference; ///< The type of a reference to an element the iterator can point to + +#if (THRUST_VERSION >= 100700) + // Use Thrust's iterator categories so we can use these iterators in Thrust 1.7 (or newer) methods + typedef typename THRUST_NS_QUALIFIER::detail::iterator_facade_category< + THRUST_NS_QUALIFIER::device_system_tag, + THRUST_NS_QUALIFIER::random_access_traversal_tag, + value_type, + reference + >::type iterator_category; ///< The iterator category +#else + typedef std::random_access_iterator_tag iterator_category; ///< The iterator category +#endif // THRUST_VERSION + +private: + + // Largest texture word we can use in device + typedef typename UnitWord::TextureWord TextureWord; + + // Number of texture words per T + enum { + TEXTURE_MULTIPLE = sizeof(T) / sizeof(TextureWord) + }; + +private: + + T* ptr; + difference_type tex_offset; + cudaTextureObject_t tex_obj; + +public: + + /// Constructor + __host__ __device__ __forceinline__ TexObjInputIterator() + : + ptr(NULL), + tex_offset(0), + tex_obj(0) + {} + + /// Use this iterator to bind \p ptr with a texture reference + template + cudaError_t BindTexture( + QualifiedT *ptr, ///< Native pointer to wrap that is aligned to cudaDeviceProp::textureAlignment + size_t bytes, ///< Number of bytes in the range + size_t tex_offset = 0) ///< OffsetT (in items) from \p ptr denoting the position of the iterator + { + this->ptr = const_cast::type *>(ptr); + this->tex_offset = static_cast(tex_offset); + + cudaChannelFormatDesc channel_desc = cudaCreateChannelDesc(); + cudaResourceDesc res_desc; + cudaTextureDesc tex_desc; + memset(&res_desc, 0, sizeof(cudaResourceDesc)); + memset(&tex_desc, 0, sizeof(cudaTextureDesc)); + res_desc.resType = cudaResourceTypeLinear; + res_desc.res.linear.devPtr = this->ptr; + res_desc.res.linear.desc = channel_desc; + res_desc.res.linear.sizeInBytes = bytes; + tex_desc.readMode = cudaReadModeElementType; + return CubDebug(cudaCreateTextureObject(&tex_obj, &res_desc, &tex_desc, NULL)); + } + + /// Unbind this iterator from its texture reference + cudaError_t UnbindTexture() + { + return CubDebug(cudaDestroyTextureObject(tex_obj)); + } + + /// Postfix increment + __host__ __device__ __forceinline__ self_type operator++(int) + { + self_type retval = *this; + tex_offset++; + return retval; + } + + /// Prefix increment + __host__ __device__ __forceinline__ self_type operator++() + { + tex_offset++; + return *this; + } + + /// Indirection + __host__ __device__ __forceinline__ reference operator*() const + { + NV_IF_TARGET(NV_IS_HOST, + (return ptr[tex_offset];), + (return this->device_deref();)); + } + + /// Addition + template + __host__ __device__ __forceinline__ self_type operator+(Distance n) const + { + self_type retval; + retval.ptr = ptr; + retval.tex_obj = tex_obj; + retval.tex_offset = tex_offset + n; + return retval; + } + + /// Addition assignment + template + __host__ __device__ __forceinline__ self_type& operator+=(Distance n) + { + tex_offset += n; + return *this; + } + + /// Subtraction + template + __host__ __device__ __forceinline__ self_type operator-(Distance n) const + { + self_type retval; + retval.ptr = ptr; + retval.tex_obj = tex_obj; + retval.tex_offset = tex_offset - n; + return retval; + } + + /// Subtraction assignment + template + __host__ __device__ __forceinline__ self_type& operator-=(Distance n) + { + tex_offset -= n; + return *this; + } + + /// Distance + __host__ __device__ __forceinline__ difference_type operator-(self_type other) const + { + return tex_offset - other.tex_offset; + } + + /// Array subscript + template + __host__ __device__ __forceinline__ reference operator[](Distance n) const + { + self_type offset = (*this) + n; + return *offset; + } + + /// Structure dereference + __host__ __device__ __forceinline__ pointer operator->() + { + return &(*(*this)); + } + + /// Equal to + __host__ __device__ __forceinline__ bool operator==(const self_type& rhs) const + { + return ((ptr == rhs.ptr) && (tex_offset == rhs.tex_offset) && (tex_obj == rhs.tex_obj)); + } + + /// Not equal to + __host__ __device__ __forceinline__ bool operator!=(const self_type& rhs) const + { + return ((ptr != rhs.ptr) || (tex_offset != rhs.tex_offset) || (tex_obj != rhs.tex_obj)); + } + + /// ostream operator + friend std::ostream& operator<<(std::ostream& os, const self_type& itr) + { + os << "cub::TexObjInputIterator( ptr=" << itr.ptr + << ", offset=" << itr.tex_offset + << ", tex_obj=" << itr.tex_obj << " )"; + return os; + } + +private: + // This is hoisted out of operator* because #pragma can't be used inside of + // NV_IF_TARGET + __device__ __forceinline__ reference device_deref() const + { + // Move array of uninitialized words, then alias and assign to return + // value + TextureWord words[TEXTURE_MULTIPLE]; + + const auto tex_idx_base = tex_offset * TEXTURE_MULTIPLE; + + #pragma unroll + for (int i = 0; i < TEXTURE_MULTIPLE; ++i) + { + words[i] = tex1Dfetch(tex_obj, tex_idx_base + i); + } + + // Load from words + return *reinterpret_cast(words); + } +}; + + + +/** @} */ // end group UtilIterator + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/tex_ref_input_iterator.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/tex_ref_input_iterator.cuh new file mode 100644 index 0000000000000000000000000000000000000000..0d877e1db49972ac0f207ee54e983bba8bbba3e9 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/tex_ref_input_iterator.cuh @@ -0,0 +1,108 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Random-access iterator types + */ + +#pragma once + +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +/** + * \addtogroup UtilIterator + * @{ + */ + +/** + * \brief A random-access input wrapper for dereferencing array values through texture cache. + * + * \deprecated [Since 1.13.0] The CUDA texture management APIs used by + * TexRefInputIterator are deprecated. Use cub::TexObjInputIterator instead. + * + * \par Overview + * - TexRefInputIterator wraps a native device pointer of type ValueType*. References + * to elements are to be loaded through texture cache. + * - Can be used to load any data type from memory through texture cache. + * - Can be manipulated and exchanged within and between host and device + * functions, can only be constructed within host functions, and can only be + * dereferenced within device functions. + * - The \p UNIQUE_ID template parameter is used to statically name the underlying texture + * reference. Only one TexRefInputIterator instance can be bound at any given time for a + * specific combination of (1) data type \p T, (2) \p UNIQUE_ID, (3) host + * thread, and (4) compilation .o unit. + * - With regard to nested/dynamic parallelism, TexRefInputIterator iterators may only be + * created by the host thread and used by a top-level kernel (i.e. the one which is launched + * from the host). + * - Compatible with Thrust API v1.7 or newer. + * + * \par Snippet + * The code snippet below illustrates the use of \p TexRefInputIterator to + * dereference a device array of doubles through texture cache. + * \par + * \code + * #include // or equivalently + * + * // Declare, allocate, and initialize a device array + * int num_items; // e.g., 7 + * double *d_in; // e.g., [8.0, 6.0, 7.0, 5.0, 3.0, 0.0, 9.0] + * + * // Create an iterator wrapper + * cub::TexRefInputIterator itr; + * itr.BindTexture(d_in, sizeof(double) * num_items); + * ... + * + * // Within device code: + * printf("%f\n", itr[0]); // 8.0 + * printf("%f\n", itr[1]); // 6.0 + * printf("%f\n", itr[6]); // 9.0 + * + * ... + * itr.UnbindTexture(); + * + * \endcode + * + * \tparam T The value type of this iterator + * \tparam UNIQUE_ID A globally-unique identifier (within the compilation unit) to name the underlying texture reference + * \tparam OffsetT The difference type of this iterator (Default: \p ptrdiff_t) + */ +template < + typename T, + int /*UNIQUE_ID*/, + typename OffsetT = std::ptrdiff_t> +using TexRefInputIterator CUB_DEPRECATED = cub::TexObjInputIterator; + +/** @} */ // end group UtilIterator + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/transform_input_iterator.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/transform_input_iterator.cuh new file mode 100644 index 0000000000000000000000000000000000000000..2ef7269c6760040d8d0ed9b9345f16c29b5fa9f0 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/iterator/transform_input_iterator.cuh @@ -0,0 +1,241 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Random-access iterator types + */ + +#pragma once + +#include +#include + +#include "../thread/thread_load.cuh" +#include "../thread/thread_store.cuh" +#include "../config.cuh" +#include "../util_device.cuh" + +#if (THRUST_VERSION >= 100700) + // This iterator is compatible with Thrust API 1.7 and newer + #include + #include +#endif // THRUST_VERSION + + +CUB_NAMESPACE_BEGIN + +/** + * \addtogroup UtilIterator + * @{ + */ + + +/** + * \brief A random-access input wrapper for transforming dereferenced values. + * + * \par Overview + * - TransformInputIteratorTwraps a unary conversion functor of type \p + * ConversionOp and a random-access input iterator of type InputIteratorT, + * using the former to produce references of type \p ValueType from the latter. + * - Can be used with any data type. + * - Can be constructed, manipulated, and exchanged within and between host and device + * functions. Wrapped host memory can only be dereferenced on the host, and wrapped + * device memory can only be dereferenced on the device. + * - Compatible with Thrust API v1.7 or newer. + * + * \par Snippet + * The code snippet below illustrates the use of \p TransformInputIteratorTto + * dereference an array of integers, tripling the values and converting them to doubles. + * \par + * \code + * #include // or equivalently + * + * // Functor for tripling integer values and converting to doubles + * struct TripleDoubler + * { + * __host__ __device__ __forceinline__ + * double operator()(const int &a) const { + * return double(a * 3); + * } + * }; + * + * // Declare, allocate, and initialize a device array + * int *d_in; // e.g., [8, 6, 7, 5, 3, 0, 9] + * TripleDoubler conversion_op; + * + * // Create an iterator wrapper + * cub::TransformInputIterator itr(d_in, conversion_op); + * + * // Within device code: + * printf("%f\n", itr[0]); // 24.0 + * printf("%f\n", itr[1]); // 18.0 + * printf("%f\n", itr[6]); // 27.0 + * + * \endcode + * + * \tparam ValueType The value type of this iterator + * \tparam ConversionOp Unary functor type for mapping objects of type \p InputType to type \p ValueType. Must have member ValueType operator()(const InputType &datum). + * \tparam InputIteratorT The type of the wrapped input iterator + * \tparam OffsetT The difference type of this iterator (Default: \p ptrdiff_t) + * + */ +template < + typename ValueType, + typename ConversionOp, + typename InputIteratorT, + typename OffsetT = ptrdiff_t> +class TransformInputIterator +{ +public: + + // Required iterator traits + typedef TransformInputIterator self_type; ///< My own type + typedef OffsetT difference_type; ///< Type to express the result of subtracting one iterator from another + typedef ValueType value_type; ///< The type of the element the iterator can point to + typedef ValueType* pointer; ///< The type of a pointer to an element the iterator can point to + typedef ValueType reference; ///< The type of a reference to an element the iterator can point to + +#if (THRUST_VERSION >= 100700) + // Use Thrust's iterator categories so we can use these iterators in Thrust 1.7 (or newer) methods + typedef typename THRUST_NS_QUALIFIER::detail::iterator_facade_category< + THRUST_NS_QUALIFIER::any_system_tag, + THRUST_NS_QUALIFIER::random_access_traversal_tag, + value_type, + reference + >::type iterator_category; ///< The iterator category +#else + typedef std::random_access_iterator_tag iterator_category; ///< The iterator category +#endif // THRUST_VERSION + +private: + + ConversionOp conversion_op; + InputIteratorT input_itr; + +public: + + /// Constructor + __host__ __device__ __forceinline__ TransformInputIterator( + InputIteratorT input_itr, ///< Input iterator to wrap + ConversionOp conversion_op) ///< Conversion functor to wrap + : + conversion_op(conversion_op), + input_itr(input_itr) + {} + + /// Postfix increment + __host__ __device__ __forceinline__ self_type operator++(int) + { + self_type retval = *this; + input_itr++; + return retval; + } + + /// Prefix increment + __host__ __device__ __forceinline__ self_type operator++() + { + input_itr++; + return *this; + } + + /// Indirection + __host__ __device__ __forceinline__ reference operator*() const + { + return conversion_op(*input_itr); + } + + /// Addition + template + __host__ __device__ __forceinline__ self_type operator+(Distance n) const + { + self_type retval(input_itr + n, conversion_op); + return retval; + } + + /// Addition assignment + template + __host__ __device__ __forceinline__ self_type& operator+=(Distance n) + { + input_itr += n; + return *this; + } + + /// Subtraction + template + __host__ __device__ __forceinline__ self_type operator-(Distance n) const + { + self_type retval(input_itr - n, conversion_op); + return retval; + } + + /// Subtraction assignment + template + __host__ __device__ __forceinline__ self_type& operator-=(Distance n) + { + input_itr -= n; + return *this; + } + + /// Distance + __host__ __device__ __forceinline__ difference_type operator-(self_type other) const + { + return input_itr - other.input_itr; + } + + /// Array subscript + template + __host__ __device__ __forceinline__ reference operator[](Distance n) const + { + return conversion_op(input_itr[n]); + } + + /// Equal to + __host__ __device__ __forceinline__ bool operator==(const self_type& rhs) const + { + return (input_itr == rhs.input_itr); + } + + /// Not equal to + __host__ __device__ __forceinline__ bool operator!=(const self_type& rhs) const + { + return (input_itr != rhs.input_itr); + } + + /// ostream operator + friend std::ostream& operator<<(std::ostream& os, const self_type& /* itr */) + { + return os; + } +}; + + + +/** @} */ // end group UtilIterator + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_load.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_load.cuh new file mode 100644 index 0000000000000000000000000000000000000000..73d251c33168506e55b64f0e373ffa8a7a4c027d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_load.cuh @@ -0,0 +1,409 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Thread utilities for reading memory using PTX cache modifiers. + */ + +#pragma once + +#include + +#include "../config.cuh" +#include "../util_ptx.cuh" +#include "../util_type.cuh" + +CUB_NAMESPACE_BEGIN + +/** + * \addtogroup UtilIo + * @{ + */ + +//----------------------------------------------------------------------------- +// Tags and constants +//----------------------------------------------------------------------------- + +/** + * \brief Enumeration of cache modifiers for memory load operations. + */ +enum CacheLoadModifier +{ + LOAD_DEFAULT, ///< Default (no modifier) + LOAD_CA, ///< Cache at all levels + LOAD_CG, ///< Cache at global level + LOAD_CS, ///< Cache streaming (likely to be accessed once) + LOAD_CV, ///< Cache as volatile (including cached system lines) + LOAD_LDG, ///< Cache as texture + LOAD_VOLATILE, ///< Volatile (any memory space) +}; + + +/** + * \name Thread I/O (cache modified) + * @{ + */ + +/** + * \brief Thread utility for reading memory using cub::CacheLoadModifier cache modifiers. Can be used to load any data type. + * + * \par Example + * \code + * #include // or equivalently + * + * // 32-bit load using cache-global modifier: + * int *d_in; + * int val = cub::ThreadLoad(d_in + threadIdx.x); + * + * // 16-bit load using default modifier + * short *d_in; + * short val = cub::ThreadLoad(d_in + threadIdx.x); + * + * // 256-bit load using cache-volatile modifier + * double4 *d_in; + * double4 val = cub::ThreadLoad(d_in + threadIdx.x); + * + * // 96-bit load using cache-streaming modifier + * struct TestFoo { bool a; short b; }; + * TestFoo *d_struct; + * TestFoo val = cub::ThreadLoad(d_in + threadIdx.x); + * \endcode + * + * \tparam MODIFIER [inferred] CacheLoadModifier enumeration + * \tparam InputIteratorT [inferred] Input iterator type \iterator + */ +template +__device__ __forceinline__ cub::detail::value_t +ThreadLoad(InputIteratorT itr); + +//@} end member group + + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + + +/// Helper structure for templated load iteration (inductive case) +template +struct IterateThreadLoad +{ + template + static __device__ __forceinline__ void Load(T const *ptr, T *vals) + { + vals[COUNT] = ThreadLoad(ptr + COUNT); + IterateThreadLoad::template Load(ptr, vals); + } + + template + static __device__ __forceinline__ void Dereference(InputIteratorT itr, T *vals) + { + vals[COUNT] = itr[COUNT]; + IterateThreadLoad::Dereference(itr, vals); + } +}; + + +/// Helper structure for templated load iteration (termination case) +template +struct IterateThreadLoad +{ + template + static __device__ __forceinline__ void Load(T const * /*ptr*/, T * /*vals*/) {} + + template + static __device__ __forceinline__ void Dereference(InputIteratorT /*itr*/, T * /*vals*/) {} +}; + + +/** + * Define a uint4 (16B) ThreadLoad specialization for the given Cache load modifier + */ +#define _CUB_LOAD_16(cub_modifier, ptx_modifier) \ + template<> \ + __device__ __forceinline__ uint4 ThreadLoad(uint4 const *ptr) \ + { \ + uint4 retval; \ + asm volatile ("ld."#ptx_modifier".v4.u32 {%0, %1, %2, %3}, [%4];" : \ + "=r"(retval.x), \ + "=r"(retval.y), \ + "=r"(retval.z), \ + "=r"(retval.w) : \ + _CUB_ASM_PTR_(ptr)); \ + return retval; \ + } \ + template<> \ + __device__ __forceinline__ ulonglong2 ThreadLoad(ulonglong2 const *ptr) \ + { \ + ulonglong2 retval; \ + asm volatile ("ld."#ptx_modifier".v2.u64 {%0, %1}, [%2];" : \ + "=l"(retval.x), \ + "=l"(retval.y) : \ + _CUB_ASM_PTR_(ptr)); \ + return retval; \ + } + +/** + * Define a uint2 (8B) ThreadLoad specialization for the given Cache load modifier + */ +#define _CUB_LOAD_8(cub_modifier, ptx_modifier) \ + template<> \ + __device__ __forceinline__ ushort4 ThreadLoad(ushort4 const *ptr) \ + { \ + ushort4 retval; \ + asm volatile ("ld."#ptx_modifier".v4.u16 {%0, %1, %2, %3}, [%4];" : \ + "=h"(retval.x), \ + "=h"(retval.y), \ + "=h"(retval.z), \ + "=h"(retval.w) : \ + _CUB_ASM_PTR_(ptr)); \ + return retval; \ + } \ + template<> \ + __device__ __forceinline__ uint2 ThreadLoad(uint2 const *ptr) \ + { \ + uint2 retval; \ + asm volatile ("ld."#ptx_modifier".v2.u32 {%0, %1}, [%2];" : \ + "=r"(retval.x), \ + "=r"(retval.y) : \ + _CUB_ASM_PTR_(ptr)); \ + return retval; \ + } \ + template<> \ + __device__ __forceinline__ unsigned long long ThreadLoad(unsigned long long const *ptr) \ + { \ + unsigned long long retval; \ + asm volatile ("ld."#ptx_modifier".u64 %0, [%1];" : \ + "=l"(retval) : \ + _CUB_ASM_PTR_(ptr)); \ + return retval; \ + } + +/** + * Define a uint (4B) ThreadLoad specialization for the given Cache load modifier + */ +#define _CUB_LOAD_4(cub_modifier, ptx_modifier) \ + template<> \ + __device__ __forceinline__ unsigned int ThreadLoad(unsigned int const *ptr) \ + { \ + unsigned int retval; \ + asm volatile ("ld."#ptx_modifier".u32 %0, [%1];" : \ + "=r"(retval) : \ + _CUB_ASM_PTR_(ptr)); \ + return retval; \ + } + + +/** + * Define a unsigned short (2B) ThreadLoad specialization for the given Cache load modifier + */ +#define _CUB_LOAD_2(cub_modifier, ptx_modifier) \ + template<> \ + __device__ __forceinline__ unsigned short ThreadLoad(unsigned short const *ptr) \ + { \ + unsigned short retval; \ + asm volatile ("ld."#ptx_modifier".u16 %0, [%1];" : \ + "=h"(retval) : \ + _CUB_ASM_PTR_(ptr)); \ + return retval; \ + } + + +/** + * Define an unsigned char (1B) ThreadLoad specialization for the given Cache load modifier + */ +#define _CUB_LOAD_1(cub_modifier, ptx_modifier) \ + template<> \ + __device__ __forceinline__ unsigned char ThreadLoad(unsigned char const *ptr) \ + { \ + unsigned short retval; \ + asm volatile ( \ + "{" \ + " .reg .u8 datum;" \ + " ld."#ptx_modifier".u8 datum, [%1];" \ + " cvt.u16.u8 %0, datum;" \ + "}" : \ + "=h"(retval) : \ + _CUB_ASM_PTR_(ptr)); \ + return (unsigned char) retval; \ + } + + +/** + * Define powers-of-two ThreadLoad specializations for the given Cache load modifier + */ +#define _CUB_LOAD_ALL(cub_modifier, ptx_modifier) \ + _CUB_LOAD_16(cub_modifier, ptx_modifier) \ + _CUB_LOAD_8(cub_modifier, ptx_modifier) \ + _CUB_LOAD_4(cub_modifier, ptx_modifier) \ + _CUB_LOAD_2(cub_modifier, ptx_modifier) \ + _CUB_LOAD_1(cub_modifier, ptx_modifier) \ + + +/** + * Define powers-of-two ThreadLoad specializations for the various Cache load modifiers + */ +_CUB_LOAD_ALL(LOAD_CA, ca) +_CUB_LOAD_ALL(LOAD_CG, cg) +_CUB_LOAD_ALL(LOAD_CS, cs) +_CUB_LOAD_ALL(LOAD_CV, cv) +_CUB_LOAD_ALL(LOAD_LDG, global.nc) + + +// Macro cleanup +#undef _CUB_LOAD_ALL +#undef _CUB_LOAD_1 +#undef _CUB_LOAD_2 +#undef _CUB_LOAD_4 +#undef _CUB_LOAD_8 +#undef _CUB_LOAD_16 + + + +/** + * ThreadLoad definition for LOAD_DEFAULT modifier on iterator types + */ +template +__device__ __forceinline__ cub::detail::value_t +ThreadLoad(InputIteratorT itr, + Int2Type /*modifier*/, + Int2Type /*is_pointer*/) +{ + return *itr; +} + + +/** + * ThreadLoad definition for LOAD_DEFAULT modifier on pointer types + */ +template +__device__ __forceinline__ T ThreadLoad( + T *ptr, + Int2Type /*modifier*/, + Int2Type /*is_pointer*/) +{ + return *ptr; +} + + +/** + * ThreadLoad definition for LOAD_VOLATILE modifier on primitive pointer types + */ +template +__device__ __forceinline__ T ThreadLoadVolatilePointer( + T *ptr, + Int2Type /*is_primitive*/) +{ + T retval = *reinterpret_cast(ptr); + return retval; +} + + +/** + * ThreadLoad definition for LOAD_VOLATILE modifier on non-primitive pointer types + */ +template +__device__ __forceinline__ T ThreadLoadVolatilePointer( + T *ptr, + Int2Type /*is_primitive*/) +{ + typedef typename UnitWord::VolatileWord VolatileWord; // Word type for memcopying + + const int VOLATILE_MULTIPLE = sizeof(T) / sizeof(VolatileWord); + + T retval; + VolatileWord *words = reinterpret_cast(&retval); + IterateThreadLoad<0, VOLATILE_MULTIPLE>::Dereference( + reinterpret_cast(ptr), + words); + return retval; +} + + +/** + * ThreadLoad definition for LOAD_VOLATILE modifier on pointer types + */ +template +__device__ __forceinline__ T ThreadLoad( + T *ptr, + Int2Type /*modifier*/, + Int2Type /*is_pointer*/) +{ + // Apply tags for partial-specialization + return ThreadLoadVolatilePointer(ptr, Int2Type::PRIMITIVE>()); +} + + +/** + * ThreadLoad definition for generic modifiers on pointer types + */ +template +__device__ __forceinline__ T ThreadLoad( + T const *ptr, + Int2Type /*modifier*/, + Int2Type /*is_pointer*/) +{ + typedef typename UnitWord::DeviceWord DeviceWord; + + const int DEVICE_MULTIPLE = sizeof(T) / sizeof(DeviceWord); + + DeviceWord words[DEVICE_MULTIPLE]; + + IterateThreadLoad<0, DEVICE_MULTIPLE>::template Load( + reinterpret_cast(const_cast(ptr)), + words); + + return *reinterpret_cast(words); +} + + +/** + * ThreadLoad definition for generic modifiers + */ +template < + CacheLoadModifier MODIFIER, + typename InputIteratorT> +__device__ __forceinline__ cub::detail::value_t +ThreadLoad(InputIteratorT itr) +{ + // Apply tags for partial-specialization + return ThreadLoad( + itr, + Int2Type(), + Int2Type::value>()); +} + + + +#endif // DOXYGEN_SHOULD_SKIP_THIS + + +/** @} */ // end group UtilIo + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_operators.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_operators.cuh new file mode 100644 index 0000000000000000000000000000000000000000..c6b097ea354f7a8039eaafa204b0ac1f3598b190 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_operators.cuh @@ -0,0 +1,423 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file + * Simple binary operator functor types + */ + +/****************************************************************************** + * Simple functor operators + ******************************************************************************/ + +#pragma once + +#include +#include +#include + +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * @addtogroup UtilModule + * @{ + */ + +/// @brief Inequality functor (wraps equality functor) +template +struct InequalityWrapper +{ + /// Wrapped equality operator + EqualityOp op; + + /// Constructor + __host__ __device__ __forceinline__ InequalityWrapper(EqualityOp op) + : op(op) + {} + + /// Boolean inequality operator, returns `t != u` + template + __host__ __device__ __forceinline__ bool operator()(T &&t, U &&u) + { + return !op(::cuda::std::forward(t), ::cuda::std::forward(u)); + } +}; + +#if CUB_CPP_DIALECT > 2011 +using Equality = ::cuda::std::equal_to<>; +using Inequality = ::cuda::std::not_equal_to<>; +using Sum = ::cuda::std::plus<>; +using Difference = ::cuda::std::minus<>; +using Division = ::cuda::std::divides<>; +#else +/// @brief Default equality functor +struct Equality +{ + /// Boolean equality operator, returns `t == u` + template + __host__ __device__ __forceinline__ bool operator()(T &&t, U &&u) const + { + return ::cuda::std::forward(t) == ::cuda::std::forward(u); + } +}; + +/// @brief Default inequality functor +struct Inequality +{ + /// Boolean inequality operator, returns `t != u` + template + __host__ __device__ __forceinline__ bool operator()(T &&t, U &&u) const + { + return ::cuda::std::forward(t) != ::cuda::std::forward(u); + } +}; + +/// @brief Default sum functor +struct Sum +{ + /// Binary sum operator, returns `t + u` + template + __host__ __device__ __forceinline__ auto operator()(T &&t, U &&u) const + -> decltype(::cuda::std::forward(t) + ::cuda::std::forward(u)) + { + return ::cuda::std::forward(t) + ::cuda::std::forward(u); + } +}; + +/// @brief Default difference functor +struct Difference +{ + /// Binary difference operator, returns `t - u` + template + __host__ __device__ __forceinline__ auto operator()(T &&t, U &&u) const + -> decltype(::cuda::std::forward(t) - ::cuda::std::forward(u)) + { + return ::cuda::std::forward(t) - ::cuda::std::forward(u); + } +}; + +/// @brief Default division functor +struct Division +{ + /// Binary division operator, returns `t / u` + template + __host__ __device__ __forceinline__ auto operator()(T &&t, U &&u) const + -> decltype(::cuda::std::forward(t) / ::cuda::std::forward(u)) + { + return ::cuda::std::forward(t) / ::cuda::std::forward(u); + } +}; +#endif + +/// @brief Default max functor +struct Max +{ + /// Boolean max operator, returns `(t > u) ? t : u` + template + __host__ __device__ __forceinline__ + typename ::cuda::std::common_type::type + operator()(T &&t, U &&u) const + { + return CUB_MAX(t, u); + } +}; + +/// @brief Arg max functor (keeps the value and offset of the first occurrence +/// of the larger item) +struct ArgMax +{ + /// Boolean max operator, preferring the item having the smaller offset in + /// case of ties + template + __host__ __device__ __forceinline__ KeyValuePair + operator()(const KeyValuePair &a, + const KeyValuePair &b) const + { + // Mooch BUG (device reduce argmax gk110 3.2 million random fp32) + // return ((b.value > a.value) || + // ((a.value == b.value) && (b.key < a.key))) + // ? b : a; + + if ((b.value > a.value) || ((a.value == b.value) && (b.key < a.key))) + { + return b; + } + + return a; + } +}; + +/// @brief Default min functor +struct Min +{ + /// Boolean min operator, returns `(t < u) ? t : u` + template + __host__ __device__ __forceinline__ + typename ::cuda::std::common_type::type + operator()(T &&t, U &&u) const + { + return CUB_MIN(t, u); + } +}; + +/// @brief Arg min functor (keeps the value and offset of the first occurrence +/// of the smallest item) +struct ArgMin +{ + /// Boolean min operator, preferring the item having the smaller offset in + /// case of ties + template + __host__ __device__ __forceinline__ KeyValuePair + operator()(const KeyValuePair &a, + const KeyValuePair &b) const + { + // Mooch BUG (device reduce argmax gk110 3.2 million random fp32) + // return ((b.value < a.value) || + // ((a.value == b.value) && (b.key < a.key))) + // ? b : a; + + if ((b.value < a.value) || ((a.value == b.value) && (b.key < a.key))) + { + return b; + } + + return a; + } +}; + +namespace detail +{ +template +struct basic_binary_op_t +{ + static constexpr bool value = false; +}; + +template <> +struct basic_binary_op_t +{ + static constexpr bool value = true; +}; + +template <> +struct basic_binary_op_t +{ + static constexpr bool value = true; +}; + +template <> +struct basic_binary_op_t +{ + static constexpr bool value = true; +}; +} // namespace detail + +/// @brief Default cast functor +template +struct CastOp +{ + /// Cast operator, returns `(B) a` + template + __host__ __device__ __forceinline__ B operator()(A &&a) const + { + return (B)a; + } +}; + +/// @brief Binary operator wrapper for switching non-commutative scan arguments +template +class SwizzleScanOp +{ +private: + /// Wrapped scan operator + ScanOp scan_op; + +public: + /// Constructor + __host__ __device__ __forceinline__ SwizzleScanOp(ScanOp scan_op) + : scan_op(scan_op) + {} + + /// Switch the scan arguments + template + __host__ __device__ __forceinline__ T operator()(const T &a, const T &b) + { + T _a(a); + T _b(b); + + return scan_op(_b, _a); + } +}; + +/** + * @brief Reduce-by-segment functor. + * + * Given two cub::KeyValuePair inputs `a` and `b` and a binary associative + * combining operator `f(const T &x, const T &y)`, an instance of this functor + * returns a cub::KeyValuePair whose `key` field is `a.key + b.key`, and whose + * `value` field is either `b.value` if `b.key` is non-zero, or + * `f(a.value, b.value)` otherwise. + * + * ReduceBySegmentOp is an associative, non-commutative binary combining + * operator for input sequences of cub::KeyValuePair pairings. Such sequences + * are typically used to represent a segmented set of values to be reduced + * and a corresponding set of {0,1}-valued integer "head flags" demarcating the + * first value of each segment. + * + * @tparam ReductionOpT Binary reduction operator to apply to values + */ +template +struct ReduceBySegmentOp +{ + /// Wrapped reduction operator + ReductionOpT op; + + /// Constructor + __host__ __device__ __forceinline__ ReduceBySegmentOp() {} + + /// Constructor + __host__ __device__ __forceinline__ ReduceBySegmentOp(ReductionOpT op) + : op(op) + {} + + /** + * @brief Scan operator + * + * @tparam KeyValuePairT + * KeyValuePair pairing of T (value) and OffsetT (head flag) + * + * @param[in] first + * First partial reduction + * + * @param[in] second + * Second partial reduction + */ + template + __host__ __device__ __forceinline__ KeyValuePairT + operator()(const KeyValuePairT &first, const KeyValuePairT &second) + { + KeyValuePairT retval; + retval.key = first.key + second.key; +#ifdef _NVHPC_CUDA // WAR bug on nvc++ + if (second.key) + { + retval.value = second.value; + } + else + { + // If second.value isn't copied into a temporary here, nvc++ will + // crash while compiling the TestScanByKeyWithLargeTypes test in + // thrust/testing/scan_by_key.cu: + auto v2 = second.value; + retval.value = op(first.value, v2); + } +#else // not nvc++: + // if (second.key) { + // The second partial reduction spans a segment reset, so it's value + // aggregate becomes the running aggregate + // else { + // The second partial reduction does not span a reset, so accumulate both + // into the running aggregate + // } + retval.value = (second.key) ? second.value : op(first.value, second.value); +#endif + return retval; + } +}; + +/** + * @tparam ReductionOpT Binary reduction operator to apply to values + */ +template +struct ReduceByKeyOp +{ + /// Wrapped reduction operator + ReductionOpT op; + + /// Constructor + __host__ __device__ __forceinline__ ReduceByKeyOp() {} + + /// Constructor + __host__ __device__ __forceinline__ ReduceByKeyOp(ReductionOpT op) + : op(op) + {} + + /** + * @brief Scan operator + * + * @param[in] first First partial reduction + * @param[in] second Second partial reduction + */ + template + __host__ __device__ __forceinline__ KeyValuePairT + operator()(const KeyValuePairT &first, const KeyValuePairT &second) + { + KeyValuePairT retval = second; + + if (first.key == second.key) + { + retval.value = op(first.value, retval.value); + } + + return retval; + } +}; + +template +struct BinaryFlip +{ + BinaryOpT binary_op; + + __device__ __host__ explicit BinaryFlip(BinaryOpT binary_op) + : binary_op(binary_op) + {} + + template + __device__ auto + operator()(T &&t, U &&u) -> decltype(binary_op(::cuda::std::forward(u), + ::cuda::std::forward(t))) + { + return binary_op(::cuda::std::forward(u), ::cuda::std::forward(t)); + } +}; + +template +__device__ __host__ BinaryFlip MakeBinaryFlip(BinaryOpT binary_op) +{ + return BinaryFlip(binary_op); +} + +/** @} */ // end group UtilModule + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_reduce.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_reduce.cuh new file mode 100644 index 0000000000000000000000000000000000000000..82042a176671a345c6e06c56cecedef856ee6086 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_reduce.cuh @@ -0,0 +1,154 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Thread utilities for sequential reduction over statically-sized array types + */ + +#pragma once + +#include "../thread/thread_operators.cuh" +#include "../detail/type_traits.cuh" +#include "../config.cuh" + +CUB_NAMESPACE_BEGIN + +/// Internal namespace (to prevent ADL mishaps between static functions when mixing different CUB installations) +namespace internal { + +/** + * Sequential reduction over statically-sized array types + */ +template < + int LENGTH, + typename T, + typename ReductionOp, + typename PrefixT, + typename AccumT = detail::accumulator_t> +__device__ __forceinline__ AccumT ThreadReduce( + T* input, ///< [in] Input array + ReductionOp reduction_op, ///< [in] Binary reduction operator + PrefixT prefix, ///< [in] Prefix to seed reduction with + Int2Type /*length*/) +{ + AccumT retval = prefix; + + #pragma unroll + for (int i = 0; i < LENGTH; ++i) + retval = reduction_op(retval, input[i]); + + return retval; +} + + +/** + * \brief Perform a sequential reduction over \p LENGTH elements of the \p input array, seeded with the specified \p prefix. The aggregate is returned. + * + * \tparam LENGTH LengthT of input array + * \tparam T [inferred] The data type to be reduced. + * \tparam ReductionOp [inferred] Binary reduction operator type having member T operator()(const T &a, const T &b) + */ +template < + int LENGTH, + typename T, + typename ReductionOp, + typename PrefixT, + typename AccumT = detail::accumulator_t> +__device__ __forceinline__ AccumT ThreadReduce( + T* input, ///< [in] Input array + ReductionOp reduction_op, ///< [in] Binary reduction operator + PrefixT prefix) ///< [in] Prefix to seed reduction with +{ + return ThreadReduce(input, reduction_op, prefix, Int2Type()); +} + + +/** + * \brief Perform a sequential reduction over \p LENGTH elements of the \p input array. The aggregate is returned. + * + * \tparam LENGTH LengthT of input array + * \tparam T [inferred] The data type to be reduced. + * \tparam ReductionOp [inferred] Binary reduction operator type having member T operator()(const T &a, const T &b) + */ +template < + int LENGTH, + typename T, + typename ReductionOp> +__device__ __forceinline__ T ThreadReduce( + T* input, ///< [in] Input array + ReductionOp reduction_op) ///< [in] Binary reduction operator +{ + T prefix = input[0]; + return ThreadReduce(input + 1, reduction_op, prefix); +} + + +/** + * \brief Perform a sequential reduction over the statically-sized \p input array, seeded with the specified \p prefix. The aggregate is returned. + * + * \tparam LENGTH [inferred] LengthT of \p input array + * \tparam T [inferred] The data type to be reduced. + * \tparam ReductionOp [inferred] Binary reduction operator type having member T operator()(const T &a, const T &b) + */ +template < + int LENGTH, + typename T, + typename ReductionOp, + typename PrefixT, + typename AccumT = detail::accumulator_t> +__device__ __forceinline__ AccumT ThreadReduce( + T (&input)[LENGTH], ///< [in] Input array + ReductionOp reduction_op, ///< [in] Binary reduction operator + PrefixT prefix) ///< [in] Prefix to seed reduction with +{ + return ThreadReduce(input, reduction_op, prefix, Int2Type()); +} + + +/** + * \brief Serial reduction with the specified operator + * + * \tparam LENGTH [inferred] LengthT of \p input array + * \tparam T [inferred] The data type to be reduced. + * \tparam ReductionOp [inferred] Binary reduction operator type having member T operator()(const T &a, const T &b) + */ +template < + int LENGTH, + typename T, + typename ReductionOp> +__device__ __forceinline__ T ThreadReduce( + T (&input)[LENGTH], ///< [in] Input array + ReductionOp reduction_op) ///< [in] Binary reduction operator +{ + return ThreadReduce((T*) input, reduction_op); +} + + +} // internal namespace +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_scan.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_scan.cuh new file mode 100644 index 0000000000000000000000000000000000000000..b5e42710fcda7f6de4764887daa0642a47e0fec1 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_scan.cuh @@ -0,0 +1,263 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Thread utilities for sequential prefix scan over statically-sized array types + */ + +#pragma once + +#include "../config.cuh" +#include "../thread/thread_operators.cuh" + +CUB_NAMESPACE_BEGIN + +/// Internal namespace (to prevent ADL mishaps between static functions when mixing different CUB installations) +namespace internal { + + +/** + * \addtogroup UtilModule + * @{ + */ + +/** + * \name Sequential prefix scan over statically-sized array types + * @{ + */ + +template < + int LENGTH, + typename T, + typename ScanOp> +__device__ __forceinline__ T ThreadScanExclusive( + T inclusive, + T exclusive, + T *input, ///< [in] Input array + T *output, ///< [out] Output array (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + Int2Type /*length*/) +{ + #pragma unroll + for (int i = 0; i < LENGTH; ++i) + { + inclusive = scan_op(exclusive, input[i]); + output[i] = exclusive; + exclusive = inclusive; + } + + return inclusive; +} + + + +/** + * \brief Perform a sequential exclusive prefix scan over \p LENGTH elements of the \p input array, seeded with the specified \p prefix. The aggregate is returned. + * + * \tparam LENGTH LengthT of \p input and \p output arrays + * \tparam T [inferred] The data type to be scanned. + * \tparam ScanOp [inferred] Binary scan operator type having member T operator()(const T &a, const T &b) + */ +template < + int LENGTH, + typename T, + typename ScanOp> +__device__ __forceinline__ T ThreadScanExclusive( + T *input, ///< [in] Input array + T *output, ///< [out] Output array (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + T prefix, ///< [in] Prefix to seed scan with + bool apply_prefix = true) ///< [in] Whether or not the calling thread should apply its prefix. If not, the first output element is undefined. (Handy for preventing thread-0 from applying a prefix.) +{ + T inclusive = input[0]; + if (apply_prefix) + { + inclusive = scan_op(prefix, inclusive); + } + output[0] = prefix; + T exclusive = inclusive; + + return ThreadScanExclusive(inclusive, exclusive, input + 1, output + 1, scan_op, Int2Type()); +} + + +/** + * \brief Perform a sequential exclusive prefix scan over the statically-sized \p input array, seeded with the specified \p prefix. The aggregate is returned. + * + * \tparam LENGTH [inferred] LengthT of \p input and \p output arrays + * \tparam T [inferred] The data type to be scanned. + * \tparam ScanOp [inferred] Binary scan operator type having member T operator()(const T &a, const T &b) + */ +template < + int LENGTH, + typename T, + typename ScanOp> +__device__ __forceinline__ T ThreadScanExclusive( + T (&input)[LENGTH], ///< [in] Input array + T (&output)[LENGTH], ///< [out] Output array (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + T prefix, ///< [in] Prefix to seed scan with + bool apply_prefix = true) ///< [in] Whether or not the calling thread should apply its prefix. (Handy for preventing thread-0 from applying a prefix.) +{ + return ThreadScanExclusive((T*) input, (T*) output, scan_op, prefix, apply_prefix); +} + + + + + + + + + +template < + int LENGTH, + typename T, + typename ScanOp> +__device__ __forceinline__ T ThreadScanInclusive( + T inclusive, + T *input, ///< [in] Input array + T *output, ///< [out] Output array (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + Int2Type /*length*/) +{ + #pragma unroll + for (int i = 0; i < LENGTH; ++i) + { + inclusive = scan_op(inclusive, input[i]); + output[i] = inclusive; + } + + return inclusive; +} + + +/** + * \brief Perform a sequential inclusive prefix scan over \p LENGTH elements of the \p input array. The aggregate is returned. + * + * \tparam LENGTH LengthT of \p input and \p output arrays + * \tparam T [inferred] The data type to be scanned. + * \tparam ScanOp [inferred] Binary scan operator type having member T operator()(const T &a, const T &b) + */ +template < + int LENGTH, + typename T, + typename ScanOp> +__device__ __forceinline__ T ThreadScanInclusive( + T *input, ///< [in] Input array + T *output, ///< [out] Output array (may be aliased to \p input) + ScanOp scan_op) ///< [in] Binary scan operator +{ + T inclusive = input[0]; + output[0] = inclusive; + + // Continue scan + return ThreadScanInclusive(inclusive, input + 1, output + 1, scan_op, Int2Type()); +} + + +/** + * \brief Perform a sequential inclusive prefix scan over the statically-sized \p input array. The aggregate is returned. + * + * \tparam LENGTH [inferred] LengthT of \p input and \p output arrays + * \tparam T [inferred] The data type to be scanned. + * \tparam ScanOp [inferred] Binary scan operator type having member T operator()(const T &a, const T &b) + */ +template < + int LENGTH, + typename T, + typename ScanOp> +__device__ __forceinline__ T ThreadScanInclusive( + T (&input)[LENGTH], ///< [in] Input array + T (&output)[LENGTH], ///< [out] Output array (may be aliased to \p input) + ScanOp scan_op) ///< [in] Binary scan operator +{ + return ThreadScanInclusive((T*) input, (T*) output, scan_op); +} + + +/** + * \brief Perform a sequential inclusive prefix scan over \p LENGTH elements of the \p input array, seeded with the specified \p prefix. The aggregate is returned. + * + * \tparam LENGTH LengthT of \p input and \p output arrays + * \tparam T [inferred] The data type to be scanned. + * \tparam ScanOp [inferred] Binary scan operator type having member T operator()(const T &a, const T &b) + */ +template < + int LENGTH, + typename T, + typename ScanOp> +__device__ __forceinline__ T ThreadScanInclusive( + T *input, ///< [in] Input array + T *output, ///< [out] Output array (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + T prefix, ///< [in] Prefix to seed scan with + bool apply_prefix = true) ///< [in] Whether or not the calling thread should apply its prefix. (Handy for preventing thread-0 from applying a prefix.) +{ + T inclusive = input[0]; + if (apply_prefix) + { + inclusive = scan_op(prefix, inclusive); + } + output[0] = inclusive; + + // Continue scan + return ThreadScanInclusive(inclusive, input + 1, output + 1, scan_op, Int2Type()); +} + + +/** + * \brief Perform a sequential inclusive prefix scan over the statically-sized \p input array, seeded with the specified \p prefix. The aggregate is returned. + * + * \tparam LENGTH [inferred] LengthT of \p input and \p output arrays + * \tparam T [inferred] The data type to be scanned. + * \tparam ScanOp [inferred] Binary scan operator type having member T operator()(const T &a, const T &b) + */ +template < + int LENGTH, + typename T, + typename ScanOp> +__device__ __forceinline__ T ThreadScanInclusive( + T (&input)[LENGTH], ///< [in] Input array + T (&output)[LENGTH], ///< [out] Output array (may be aliased to \p input) + ScanOp scan_op, ///< [in] Binary scan operator + T prefix, ///< [in] Prefix to seed scan with + bool apply_prefix = true) ///< [in] Whether or not the calling thread should apply its prefix. (Handy for preventing thread-0 from applying a prefix.) +{ + return ThreadScanInclusive((T*) input, (T*) output, scan_op, prefix, apply_prefix); +} + + +//@} end member group + +/** @} */ // end group UtilModule + + +} // internal namespace +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_search.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_search.cuh new file mode 100644 index 0000000000000000000000000000000000000000..62b3cdb4e5d499c4d6a8611ecf2aca06d964ecf5 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_search.cuh @@ -0,0 +1,185 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Thread utilities for sequential search + */ + +#pragma once + +#include +#include +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + + +/** + * Computes the begin offsets into A and B for the specific diagonal + */ +template < + typename AIteratorT, + typename BIteratorT, + typename OffsetT, + typename CoordinateT> +__host__ __device__ __forceinline__ void MergePathSearch( + OffsetT diagonal, + AIteratorT a, + BIteratorT b, + OffsetT a_len, + OffsetT b_len, + CoordinateT& path_coordinate) +{ + /// The value type of the input iterator + using T = cub::detail::value_t; + + OffsetT split_min = CUB_MAX(diagonal - b_len, 0); + OffsetT split_max = CUB_MIN(diagonal, a_len); + + while (split_min < split_max) + { + OffsetT split_pivot = (split_min + split_max) >> 1; + if (a[split_pivot] <= b[diagonal - split_pivot - 1]) + { + // Move candidate split range up A, down B + split_min = split_pivot + 1; + } + else + { + // Move candidate split range up B, down A + split_max = split_pivot; + } + } + + path_coordinate.x = CUB_MIN(split_min, a_len); + path_coordinate.y = diagonal - split_min; +} + + + +/** + * \brief Returns the offset of the first value within \p input which does not compare less than \p val + */ +template < + typename InputIteratorT, + typename OffsetT, + typename T> +__device__ __forceinline__ OffsetT LowerBound( + InputIteratorT input, ///< [in] Input sequence + OffsetT num_items, ///< [in] Input sequence length + T val) ///< [in] Search key +{ + OffsetT retval = 0; + while (num_items > 0) + { + OffsetT half = num_items >> 1; + if (input[retval + half] < val) + { + retval = retval + (half + 1); + num_items = num_items - (half + 1); + } + else + { + num_items = half; + } + } + + return retval; +} + + +/** + * \brief Returns the offset of the first value within \p input which compares greater than \p val + */ +template < + typename InputIteratorT, + typename OffsetT, + typename T> +__device__ __forceinline__ OffsetT UpperBound( + InputIteratorT input, ///< [in] Input sequence + OffsetT num_items, ///< [in] Input sequence length + T val) ///< [in] Search key +{ + OffsetT retval = 0; + while (num_items > 0) + { + OffsetT half = num_items >> 1; + if (val < input[retval + half]) + { + num_items = half; + } + else + { + retval = retval + (half + 1); + num_items = num_items - (half + 1); + } + } + + return retval; +} + + +#if defined(__CUDA_FP16_TYPES_EXIST__) +template < + typename InputIteratorT, + typename OffsetT> +__device__ __forceinline__ OffsetT UpperBound( + InputIteratorT input, ///< [in] Input sequence + OffsetT num_items, ///< [in] Input sequence length + __half val) ///< [in] Search key +{ + OffsetT retval = 0; + while (num_items > 0) + { + OffsetT half = num_items >> 1; + + bool lt; + NV_IF_TARGET(NV_PROVIDES_SM_53, + (lt = val < input[retval + half];), + (lt = __half2float(val) < __half2float(input[retval + half]);)); + + if (lt) + { + num_items = half; + } + else + { + retval = retval + (half + 1); + num_items = num_items - (half + 1); + } + } + + return retval; +} +#endif + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..5d486789684c3e1c2c59c6cfc7044398c0ce51da --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_sort.cuh @@ -0,0 +1,105 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include "../config.cuh" +#include "../util_ptx.cuh" +#include "../util_type.cuh" + +CUB_NAMESPACE_BEGIN + + +template +__device__ __forceinline__ void Swap(T &lhs, T &rhs) +{ + T temp = lhs; + lhs = rhs; + rhs = temp; +} + + +/** + * @brief Sorts data using odd-even sort method + * + * The sorting method is stable. Further details can be found in: + * A. Nico Habermann. Parallel neighbor sort (or the glory of the induction + * principle). Technical Report AD-759 248, Carnegie Mellon University, 1972. + * + * @tparam KeyT + * Key type + * + * @tparam ValueT + * Value type. If `cub::NullType` is used as `ValueT`, only keys are sorted. + * + * @tparam CompareOp + * functor type having member `bool operator()(KeyT lhs, KeyT rhs)` + * + * @tparam ITEMS_PER_THREAD + * The number of items per thread + * + * @param[in,out] keys + * Keys to sort + * + * @param[in,out] items + * Values to sort + * + * @param[in] compare_op + * Comparison function object which returns true if the first argument is + * ordered before the second + */ +template +__device__ __forceinline__ void +StableOddEvenSort(KeyT (&keys)[ITEMS_PER_THREAD], + ValueT (&items)[ITEMS_PER_THREAD], + CompareOp compare_op) +{ + constexpr bool KEYS_ONLY = std::is_same::value; + + #pragma unroll + for (int i = 0; i < ITEMS_PER_THREAD; ++i) + { + #pragma unroll + for (int j = 1 & i; j < ITEMS_PER_THREAD - 1; j += 2) + { + if (compare_op(keys[j + 1], keys[j])) + { + Swap(keys[j], keys[j + 1]); + if (!KEYS_ONLY) + { + Swap(items[j], items[j + 1]); + } + } + } // inner loop + } // outer loop +} + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_store.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_store.cuh new file mode 100644 index 0000000000000000000000000000000000000000..7f711bf0619d8cff96809bad59bb5aa5ce573fd6 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/thread/thread_store.cuh @@ -0,0 +1,407 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Thread utilities for writing memory using PTX cache modifiers. + */ + +#pragma once + +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +/** + * \addtogroup UtilIo + * @{ + */ + + +//----------------------------------------------------------------------------- +// Tags and constants +//----------------------------------------------------------------------------- + +/** + * \brief Enumeration of cache modifiers for memory store operations. + */ +enum CacheStoreModifier +{ + STORE_DEFAULT, ///< Default (no modifier) + STORE_WB, ///< Cache write-back all coherent levels + STORE_CG, ///< Cache at global level + STORE_CS, ///< Cache streaming (likely to be accessed once) + STORE_WT, ///< Cache write-through (to system memory) + STORE_VOLATILE, ///< Volatile shared (any memory space) +}; + + +/** + * \name Thread I/O (cache modified) + * @{ + */ + +/** + * \brief Thread utility for writing memory using cub::CacheStoreModifier cache modifiers. Can be used to store any data type. + * + * \par Example + * \code + * #include // or equivalently + * + * // 32-bit store using cache-global modifier: + * int *d_out; + * int val; + * cub::ThreadStore(d_out + threadIdx.x, val); + * + * // 16-bit store using default modifier + * short *d_out; + * short val; + * cub::ThreadStore(d_out + threadIdx.x, val); + * + * // 256-bit store using write-through modifier + * double4 *d_out; + * double4 val; + * cub::ThreadStore(d_out + threadIdx.x, val); + * + * // 96-bit store using cache-streaming cache modifier + * struct TestFoo { bool a; short b; }; + * TestFoo *d_struct; + * TestFoo val; + * cub::ThreadStore(d_out + threadIdx.x, val); + * \endcode + * + * \tparam MODIFIER [inferred] CacheStoreModifier enumeration + * \tparam InputIteratorT [inferred] Output iterator type \iterator + * \tparam T [inferred] Data type of output value + */ +template < + CacheStoreModifier MODIFIER, + typename OutputIteratorT, + typename T> +__device__ __forceinline__ void ThreadStore(OutputIteratorT itr, T val); + + +//@} end member group + + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + + +/// Helper structure for templated store iteration (inductive case) +template +struct IterateThreadStore +{ + template + static __device__ __forceinline__ void Store(T *ptr, T *vals) + { + ThreadStore(ptr + COUNT, vals[COUNT]); + IterateThreadStore::template Store(ptr, vals); + } + + template + static __device__ __forceinline__ void Dereference(OutputIteratorT ptr, T *vals) + { + ptr[COUNT] = vals[COUNT]; + IterateThreadStore::Dereference(ptr, vals); + } + +}; + +/// Helper structure for templated store iteration (termination case) +template +struct IterateThreadStore +{ + template + static __device__ __forceinline__ void Store(T * /*ptr*/, T * /*vals*/) {} + + template + static __device__ __forceinline__ void Dereference(OutputIteratorT /*ptr*/, T * /*vals*/) {} +}; + + +/** + * Define a uint4 (16B) ThreadStore specialization for the given Cache load modifier + */ +#define _CUB_STORE_16(cub_modifier, ptx_modifier) \ + template<> \ + __device__ __forceinline__ void ThreadStore(uint4* ptr, uint4 val) \ + { \ + asm volatile ("st."#ptx_modifier".v4.u32 [%0], {%1, %2, %3, %4};" : : \ + _CUB_ASM_PTR_(ptr), \ + "r"(val.x), \ + "r"(val.y), \ + "r"(val.z), \ + "r"(val.w)); \ + } \ + template<> \ + __device__ __forceinline__ void ThreadStore(ulonglong2* ptr, ulonglong2 val) \ + { \ + asm volatile ("st."#ptx_modifier".v2.u64 [%0], {%1, %2};" : : \ + _CUB_ASM_PTR_(ptr), \ + "l"(val.x), \ + "l"(val.y)); \ + } + + +/** + * Define a uint2 (8B) ThreadStore specialization for the given Cache load modifier + */ +#define _CUB_STORE_8(cub_modifier, ptx_modifier) \ + template<> \ + __device__ __forceinline__ void ThreadStore(ushort4* ptr, ushort4 val) \ + { \ + asm volatile ("st."#ptx_modifier".v4.u16 [%0], {%1, %2, %3, %4};" : : \ + _CUB_ASM_PTR_(ptr), \ + "h"(val.x), \ + "h"(val.y), \ + "h"(val.z), \ + "h"(val.w)); \ + } \ + template<> \ + __device__ __forceinline__ void ThreadStore(uint2* ptr, uint2 val) \ + { \ + asm volatile ("st."#ptx_modifier".v2.u32 [%0], {%1, %2};" : : \ + _CUB_ASM_PTR_(ptr), \ + "r"(val.x), \ + "r"(val.y)); \ + } \ + template<> \ + __device__ __forceinline__ void ThreadStore(unsigned long long* ptr, unsigned long long val) \ + { \ + asm volatile ("st."#ptx_modifier".u64 [%0], %1;" : : \ + _CUB_ASM_PTR_(ptr), \ + "l"(val)); \ + } + +/** + * Define a unsigned int (4B) ThreadStore specialization for the given Cache load modifier + */ +#define _CUB_STORE_4(cub_modifier, ptx_modifier) \ + template<> \ + __device__ __forceinline__ void ThreadStore(unsigned int* ptr, unsigned int val) \ + { \ + asm volatile ("st."#ptx_modifier".u32 [%0], %1;" : : \ + _CUB_ASM_PTR_(ptr), \ + "r"(val)); \ + } + + +/** + * Define a unsigned short (2B) ThreadStore specialization for the given Cache load modifier + */ +#define _CUB_STORE_2(cub_modifier, ptx_modifier) \ + template<> \ + __device__ __forceinline__ void ThreadStore(unsigned short* ptr, unsigned short val) \ + { \ + asm volatile ("st."#ptx_modifier".u16 [%0], %1;" : : \ + _CUB_ASM_PTR_(ptr), \ + "h"(val)); \ + } + + +/** + * Define a unsigned char (1B) ThreadStore specialization for the given Cache load modifier + */ +#define _CUB_STORE_1(cub_modifier, ptx_modifier) \ + template<> \ + __device__ __forceinline__ void ThreadStore(unsigned char* ptr, unsigned char val) \ + { \ + asm volatile ( \ + "{" \ + " .reg .u8 datum;" \ + " cvt.u8.u16 datum, %1;" \ + " st."#ptx_modifier".u8 [%0], datum;" \ + "}" : : \ + _CUB_ASM_PTR_(ptr), \ + "h"((unsigned short) val)); \ + } + +/** + * Define powers-of-two ThreadStore specializations for the given Cache load modifier + */ +#define _CUB_STORE_ALL(cub_modifier, ptx_modifier) \ + _CUB_STORE_16(cub_modifier, ptx_modifier) \ + _CUB_STORE_8(cub_modifier, ptx_modifier) \ + _CUB_STORE_4(cub_modifier, ptx_modifier) \ + _CUB_STORE_2(cub_modifier, ptx_modifier) \ + _CUB_STORE_1(cub_modifier, ptx_modifier) \ + + +/** + * Define ThreadStore specializations for the various Cache load modifiers + */ +_CUB_STORE_ALL(STORE_WB, wb) +_CUB_STORE_ALL(STORE_CG, cg) +_CUB_STORE_ALL(STORE_CS, cs) +_CUB_STORE_ALL(STORE_WT, wt) + +// Macro cleanup +#undef _CUB_STORE_ALL +#undef _CUB_STORE_1 +#undef _CUB_STORE_2 +#undef _CUB_STORE_4 +#undef _CUB_STORE_8 +#undef _CUB_STORE_16 + + +/** + * ThreadStore definition for STORE_DEFAULT modifier on iterator types + */ +template +__device__ __forceinline__ void ThreadStore( + OutputIteratorT itr, + T val, + Int2Type /*modifier*/, + Int2Type /*is_pointer*/) +{ + *itr = val; +} + + +/** + * ThreadStore definition for STORE_DEFAULT modifier on pointer types + */ +template +__device__ __forceinline__ void ThreadStore( + T *ptr, + T val, + Int2Type /*modifier*/, + Int2Type /*is_pointer*/) +{ + *ptr = val; +} + + +/** + * ThreadStore definition for STORE_VOLATILE modifier on primitive pointer types + */ +template +__device__ __forceinline__ void ThreadStoreVolatilePtr( + T *ptr, + T val, + Int2Type /*is_primitive*/) +{ + *reinterpret_cast(ptr) = val; +} + + +/** + * ThreadStore definition for STORE_VOLATILE modifier on non-primitive pointer types + */ +template +__device__ __forceinline__ void ThreadStoreVolatilePtr( + T *ptr, + T val, + Int2Type /*is_primitive*/) +{ + // Create a temporary using shuffle-words, then store using volatile-words + typedef typename UnitWord::VolatileWord VolatileWord; + typedef typename UnitWord::ShuffleWord ShuffleWord; + + const int VOLATILE_MULTIPLE = sizeof(T) / sizeof(VolatileWord); + const int SHUFFLE_MULTIPLE = sizeof(T) / sizeof(ShuffleWord); + + VolatileWord words[VOLATILE_MULTIPLE]; + + #pragma unroll + for (int i = 0; i < SHUFFLE_MULTIPLE; ++i) + reinterpret_cast(words)[i] = reinterpret_cast(&val)[i]; + + IterateThreadStore<0, VOLATILE_MULTIPLE>::template Dereference( + reinterpret_cast(ptr), + words); +} + + +/** + * ThreadStore definition for STORE_VOLATILE modifier on pointer types + */ +template +__device__ __forceinline__ void ThreadStore( + T *ptr, + T val, + Int2Type /*modifier*/, + Int2Type /*is_pointer*/) +{ + ThreadStoreVolatilePtr(ptr, val, Int2Type::PRIMITIVE>()); +} + + +/** + * ThreadStore definition for generic modifiers on pointer types + */ +template +__device__ __forceinline__ void ThreadStore( + T *ptr, + T val, + Int2Type /*modifier*/, + Int2Type /*is_pointer*/) +{ + // Create a temporary using shuffle-words, then store using device-words + typedef typename UnitWord::DeviceWord DeviceWord; + typedef typename UnitWord::ShuffleWord ShuffleWord; + + const int DEVICE_MULTIPLE = sizeof(T) / sizeof(DeviceWord); + const int SHUFFLE_MULTIPLE = sizeof(T) / sizeof(ShuffleWord); + + DeviceWord words[DEVICE_MULTIPLE]; + + #pragma unroll + for (int i = 0; i < SHUFFLE_MULTIPLE; ++i) + reinterpret_cast(words)[i] = reinterpret_cast(&val)[i]; + + IterateThreadStore<0, DEVICE_MULTIPLE>::template Store( + reinterpret_cast(ptr), + words); +} + + +/** + * ThreadStore definition for generic modifiers + */ +template +__device__ __forceinline__ void ThreadStore(OutputIteratorT itr, T val) +{ + ThreadStore( + itr, + val, + Int2Type(), + Int2Type::value>()); +} + + + +#endif // DOXYGEN_SHOULD_SKIP_THIS + + +/** @} */ // end group UtilIo + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_allocator.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_allocator.cuh new file mode 100644 index 0000000000000000000000000000000000000000..bb6d6a41784a30bcd25db89774b7ec5103eccc6d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_allocator.cuh @@ -0,0 +1,716 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/****************************************************************************** + * Simple caching allocator for device memory allocations. The allocator is + * thread-safe and capable of managing device allocations on multiple devices. + ******************************************************************************/ + +#pragma once + +#include "util_namespace.cuh" +#include "util_debug.cuh" + +#include +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + + +/** + * \addtogroup UtilMgmt + * @{ + */ + + +/****************************************************************************** + * CachingDeviceAllocator (host use) + ******************************************************************************/ + +/** + * \brief A simple caching allocator for device memory allocations. + * + * \par Overview + * The allocator is thread-safe and stream-safe and is capable of managing cached + * device allocations on multiple devices. It behaves as follows: + * + * \par + * - Allocations from the allocator are associated with an \p active_stream. Once freed, + * the allocation becomes available immediately for reuse within the \p active_stream + * with which it was associated with during allocation, and it becomes available for + * reuse within other streams when all prior work submitted to \p active_stream has completed. + * - Allocations are categorized and cached by bin size. A new allocation request of + * a given size will only consider cached allocations within the corresponding bin. + * - Bin limits progress geometrically in accordance with the growth factor + * \p bin_growth provided during construction. Unused device allocations within + * a larger bin cache are not reused for allocation requests that categorize to + * smaller bin sizes. + * - Allocation requests below (\p bin_growth ^ \p min_bin) are rounded up to + * (\p bin_growth ^ \p min_bin). + * - Allocations above (\p bin_growth ^ \p max_bin) are not rounded up to the nearest + * bin and are simply freed when they are deallocated instead of being returned + * to a bin-cache. + * - If the total storage of cached allocations on a given device will exceed + * \p max_cached_bytes, allocations for that device are simply freed when they are + * deallocated instead of being returned to their bin-cache. + * + * \par + * For example, the default-constructed CachingDeviceAllocator is configured with: + * - \p bin_growth = 8 + * - \p min_bin = 3 + * - \p max_bin = 7 + * - \p max_cached_bytes = 6MB - 1B + * + * \par + * which delineates five bin-sizes: 512B, 4KB, 32KB, 256KB, and 2MB + * and sets a maximum of 6,291,455 cached bytes per device + * + */ +struct CachingDeviceAllocator +{ + + //--------------------------------------------------------------------- + // Constants + //--------------------------------------------------------------------- + + /// Out-of-bounds bin + static const unsigned int INVALID_BIN = (unsigned int) -1; + + /// Invalid size + static const size_t INVALID_SIZE = (size_t) -1; + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + + /// Invalid device ordinal + static const int INVALID_DEVICE_ORDINAL = -1; + + //--------------------------------------------------------------------- + // Type definitions and helper types + //--------------------------------------------------------------------- + + /** + * Descriptor for device memory allocations + */ + struct BlockDescriptor + { + void* d_ptr; // Device pointer + size_t bytes; // Size of allocation in bytes + unsigned int bin; // Bin enumeration + int device; // device ordinal + cudaStream_t associated_stream; // Associated associated_stream + cudaEvent_t ready_event; // Signal when associated stream has run to the point at which this block was freed + + // Constructor (suitable for searching maps for a specific block, given its pointer and device) + BlockDescriptor(void *d_ptr, int device) : + d_ptr(d_ptr), + bytes(0), + bin(INVALID_BIN), + device(device), + associated_stream(0), + ready_event(0) + {} + + // Constructor (suitable for searching maps for a range of suitable blocks, given a device) + BlockDescriptor(int device) : + d_ptr(NULL), + bytes(0), + bin(INVALID_BIN), + device(device), + associated_stream(0), + ready_event(0) + {} + + // Comparison functor for comparing device pointers + static bool PtrCompare(const BlockDescriptor &a, const BlockDescriptor &b) + { + if (a.device == b.device) + return (a.d_ptr < b.d_ptr); + else + return (a.device < b.device); + } + + // Comparison functor for comparing allocation sizes + static bool SizeCompare(const BlockDescriptor &a, const BlockDescriptor &b) + { + if (a.device == b.device) + return (a.bytes < b.bytes); + else + return (a.device < b.device); + } + }; + + /// BlockDescriptor comparator function interface + typedef bool (*Compare)(const BlockDescriptor &, const BlockDescriptor &); + + class TotalBytes { + public: + size_t free; + size_t live; + TotalBytes() { free = live = 0; } + }; + + /// Set type for cached blocks (ordered by size) + typedef std::multiset CachedBlocks; + + /// Set type for live blocks (ordered by ptr) + typedef std::multiset BusyBlocks; + + /// Map type of device ordinals to the number of cached bytes cached by each device + typedef std::map GpuCachedBytes; + + + //--------------------------------------------------------------------- + // Utility functions + //--------------------------------------------------------------------- + + /** + * Integer pow function for unsigned base and exponent + */ + static unsigned int IntPow( + unsigned int base, + unsigned int exp) + { + unsigned int retval = 1; + while (exp > 0) + { + if (exp & 1) { + retval = retval * base; // multiply the result by the current base + } + base = base * base; // square the base + exp = exp >> 1; // divide the exponent in half + } + return retval; + } + + + /** + * Round up to the nearest power-of + */ + void NearestPowerOf( + unsigned int &power, + size_t &rounded_bytes, + unsigned int base, + size_t value) + { + power = 0; + rounded_bytes = 1; + + if (value * base < value) + { + // Overflow + power = sizeof(size_t) * 8; + rounded_bytes = size_t(0) - 1; + return; + } + + while (rounded_bytes < value) + { + rounded_bytes *= base; + power++; + } + } + + + //--------------------------------------------------------------------- + // Fields + //--------------------------------------------------------------------- + + std::mutex mutex; /// Mutex for thread-safety + + unsigned int bin_growth; /// Geometric growth factor for bin-sizes + unsigned int min_bin; /// Minimum bin enumeration + unsigned int max_bin; /// Maximum bin enumeration + + size_t min_bin_bytes; /// Minimum bin size + size_t max_bin_bytes; /// Maximum bin size + size_t max_cached_bytes; /// Maximum aggregate cached bytes per device + + const bool skip_cleanup; /// Whether or not to skip a call to FreeAllCached() when destructor is called. (The CUDA runtime may have already shut down for statically declared allocators) + bool debug; /// Whether or not to print (de)allocation events to stdout + + GpuCachedBytes cached_bytes; /// Map of device ordinal to aggregate cached bytes on that device + CachedBlocks cached_blocks; /// Set of cached device allocations available for reuse + BusyBlocks live_blocks; /// Set of live device allocations currently in use + +#endif // DOXYGEN_SHOULD_SKIP_THIS + + //--------------------------------------------------------------------- + // Methods + //--------------------------------------------------------------------- + + /** + * \brief Constructor. + */ + CachingDeviceAllocator( + unsigned int bin_growth, ///< Geometric growth factor for bin-sizes + unsigned int min_bin = 1, ///< Minimum bin (default is bin_growth ^ 1) + unsigned int max_bin = INVALID_BIN, ///< Maximum bin (default is no max bin) + size_t max_cached_bytes = INVALID_SIZE, ///< Maximum aggregate cached bytes per device (default is no limit) + bool skip_cleanup = false, ///< Whether or not to skip a call to \p FreeAllCached() when the destructor is called (default is to deallocate) + bool debug = false) ///< Whether or not to print (de)allocation events to stdout (default is no stderr output) + : + bin_growth(bin_growth), + min_bin(min_bin), + max_bin(max_bin), + min_bin_bytes(IntPow(bin_growth, min_bin)), + max_bin_bytes(IntPow(bin_growth, max_bin)), + max_cached_bytes(max_cached_bytes), + skip_cleanup(skip_cleanup), + debug(debug), + cached_blocks(BlockDescriptor::SizeCompare), + live_blocks(BlockDescriptor::PtrCompare) + {} + + + /** + * \brief Default constructor. + * + * Configured with: + * \par + * - \p bin_growth = 8 + * - \p min_bin = 3 + * - \p max_bin = 7 + * - \p max_cached_bytes = (\p bin_growth ^ \p max_bin) * 3) - 1 = 6,291,455 bytes + * + * which delineates five bin-sizes: 512B, 4KB, 32KB, 256KB, and 2MB and + * sets a maximum of 6,291,455 cached bytes per device + */ + CachingDeviceAllocator( + bool skip_cleanup = false, + bool debug = false) + : + bin_growth(8), + min_bin(3), + max_bin(7), + min_bin_bytes(IntPow(bin_growth, min_bin)), + max_bin_bytes(IntPow(bin_growth, max_bin)), + max_cached_bytes((max_bin_bytes * 3) - 1), + skip_cleanup(skip_cleanup), + debug(debug), + cached_blocks(BlockDescriptor::SizeCompare), + live_blocks(BlockDescriptor::PtrCompare) + {} + + + /** + * \brief Sets the limit on the number bytes this allocator is allowed to cache per device. + * + * Changing the ceiling of cached bytes does not cause any allocations (in-use or + * cached-in-reserve) to be freed. See \p FreeAllCached(). + */ + cudaError_t SetMaxCachedBytes(size_t max_cached_bytes_) + { + // Lock + mutex.lock(); + + if (debug) _CubLog("Changing max_cached_bytes (%lld -> %lld)\n", (long long) this->max_cached_bytes, (long long) max_cached_bytes_); + + this->max_cached_bytes = max_cached_bytes_; + + // Unlock + mutex.unlock(); + + return cudaSuccess; + } + + + /** + * \brief Provides a suitable allocation of device memory for the given size on the specified device. + * + * Once freed, the allocation becomes available immediately for reuse within the \p active_stream + * with which it was associated with during allocation, and it becomes available for reuse within other + * streams when all prior work submitted to \p active_stream has completed. + */ + cudaError_t DeviceAllocate( + int device, ///< [in] Device on which to place the allocation + void **d_ptr, ///< [out] Reference to pointer to the allocation + size_t bytes, ///< [in] Minimum number of bytes for the allocation + cudaStream_t active_stream = 0) ///< [in] The stream to be associated with this allocation + { + *d_ptr = NULL; + int entrypoint_device = INVALID_DEVICE_ORDINAL; + cudaError_t error = cudaSuccess; + + if (device == INVALID_DEVICE_ORDINAL) + { + if (CubDebug(error = cudaGetDevice(&entrypoint_device))) return error; + device = entrypoint_device; + } + + // Create a block descriptor for the requested allocation + bool found = false; + BlockDescriptor search_key(device); + search_key.associated_stream = active_stream; + NearestPowerOf(search_key.bin, search_key.bytes, bin_growth, bytes); + + if (search_key.bin > max_bin) + { + // Bin is greater than our maximum bin: allocate the request + // exactly and give out-of-bounds bin. It will not be cached + // for reuse when returned. + search_key.bin = INVALID_BIN; + search_key.bytes = bytes; + } + else + { + // Search for a suitable cached allocation: lock + mutex.lock(); + + if (search_key.bin < min_bin) + { + // Bin is less than minimum bin: round up + search_key.bin = min_bin; + search_key.bytes = min_bin_bytes; + } + + // Iterate through the range of cached blocks on the same device in the same bin + CachedBlocks::iterator block_itr = cached_blocks.lower_bound(search_key); + while ((block_itr != cached_blocks.end()) + && (block_itr->device == device) + && (block_itr->bin == search_key.bin)) + { + // To prevent races with reusing blocks returned by the host but still + // in use by the device, only consider cached blocks that are + // either (from the active stream) or (from an idle stream) + bool is_reusable = false; + if (active_stream == block_itr->associated_stream) + { + is_reusable = true; + } + else + { + const cudaError_t event_status = cudaEventQuery(block_itr->ready_event); + if(event_status != cudaErrorNotReady) + { + CubDebug(event_status); + is_reusable = true; + } + } + + if(is_reusable) + { + // Reuse existing cache block. Insert into live blocks. + found = true; + search_key = *block_itr; + search_key.associated_stream = active_stream; + live_blocks.insert(search_key); + + // Remove from free blocks + cached_bytes[device].free -= search_key.bytes; + cached_bytes[device].live += search_key.bytes; + + if (debug) _CubLog("\tDevice %d reused cached block at %p (%lld bytes) for stream %lld (previously associated with stream %lld).\n", + device, search_key.d_ptr, (long long) search_key.bytes, (long long) search_key.associated_stream, (long long) block_itr->associated_stream); + + cached_blocks.erase(block_itr); + + break; + } + block_itr++; + } + + // Done searching: unlock + mutex.unlock(); + } + + // Allocate the block if necessary + if (!found) + { + // Set runtime's current device to specified device (entrypoint may not be set) + if (device != entrypoint_device) + { + if (CubDebug(error = cudaGetDevice(&entrypoint_device))) return error; + if (CubDebug(error = cudaSetDevice(device))) return error; + } + + // Attempt to allocate + if (CubDebug(error = cudaMalloc(&search_key.d_ptr, search_key.bytes)) == cudaErrorMemoryAllocation) + { + // The allocation attempt failed: free all cached blocks on device and retry + if (debug) _CubLog("\tDevice %d failed to allocate %lld bytes for stream %lld, retrying after freeing cached allocations", + device, (long long) search_key.bytes, (long long) search_key.associated_stream); + + error = cudaSuccess; // Reset the error we will return + cudaGetLastError(); // Reset CUDART's error + + // Lock + mutex.lock(); + + // Iterate the range of free blocks on the same device + BlockDescriptor free_key(device); + CachedBlocks::iterator block_itr = cached_blocks.lower_bound(free_key); + + while ((block_itr != cached_blocks.end()) && (block_itr->device == device)) + { + // No need to worry about synchronization with the device: cudaFree is + // blocking and will synchronize across all kernels executing + // on the current device + + // Free device memory and destroy stream event. + if (CubDebug(error = cudaFree(block_itr->d_ptr))) break; + if (CubDebug(error = cudaEventDestroy(block_itr->ready_event))) break; + + // Reduce balance and erase entry + cached_bytes[device].free -= block_itr->bytes; + + if (debug) _CubLog("\tDevice %d freed %lld bytes.\n\t\t %lld available blocks cached (%lld bytes), %lld live blocks (%lld bytes) outstanding.\n", + device, (long long) block_itr->bytes, (long long) cached_blocks.size(), (long long) cached_bytes[device].free, (long long) live_blocks.size(), (long long) cached_bytes[device].live); + + block_itr = cached_blocks.erase(block_itr); + } + + // Unlock + mutex.unlock(); + + // Return under error + if (error) return error; + + // Try to allocate again + if (CubDebug(error = cudaMalloc(&search_key.d_ptr, search_key.bytes))) return error; + } + + // Create ready event + if (CubDebug(error = cudaEventCreateWithFlags(&search_key.ready_event, cudaEventDisableTiming))) + return error; + + // Insert into live blocks + mutex.lock(); + live_blocks.insert(search_key); + cached_bytes[device].live += search_key.bytes; + mutex.unlock(); + + if (debug) _CubLog("\tDevice %d allocated new device block at %p (%lld bytes associated with stream %lld).\n", + device, search_key.d_ptr, (long long) search_key.bytes, (long long) search_key.associated_stream); + + // Attempt to revert back to previous device if necessary + if ((entrypoint_device != INVALID_DEVICE_ORDINAL) && (entrypoint_device != device)) + { + if (CubDebug(error = cudaSetDevice(entrypoint_device))) return error; + } + } + + // Copy device pointer to output parameter + *d_ptr = search_key.d_ptr; + + if (debug) _CubLog("\t\t%lld available blocks cached (%lld bytes), %lld live blocks outstanding(%lld bytes).\n", + (long long) cached_blocks.size(), (long long) cached_bytes[device].free, (long long) live_blocks.size(), (long long) cached_bytes[device].live); + + return error; + } + + + /** + * \brief Provides a suitable allocation of device memory for the given size on the current device. + * + * Once freed, the allocation becomes available immediately for reuse within the \p active_stream + * with which it was associated with during allocation, and it becomes available for reuse within other + * streams when all prior work submitted to \p active_stream has completed. + */ + cudaError_t DeviceAllocate( + void **d_ptr, ///< [out] Reference to pointer to the allocation + size_t bytes, ///< [in] Minimum number of bytes for the allocation + cudaStream_t active_stream = 0) ///< [in] The stream to be associated with this allocation + { + return DeviceAllocate(INVALID_DEVICE_ORDINAL, d_ptr, bytes, active_stream); + } + + + /** + * \brief Frees a live allocation of device memory on the specified device, returning it to the allocator. + * + * Once freed, the allocation becomes available immediately for reuse within the \p active_stream + * with which it was associated with during allocation, and it becomes available for reuse within other + * streams when all prior work submitted to \p active_stream has completed. + */ + cudaError_t DeviceFree( + int device, + void* d_ptr) + { + int entrypoint_device = INVALID_DEVICE_ORDINAL; + cudaError_t error = cudaSuccess; + + if (device == INVALID_DEVICE_ORDINAL) + { + if (CubDebug(error = cudaGetDevice(&entrypoint_device))) + return error; + device = entrypoint_device; + } + + // Lock + mutex.lock(); + + // Find corresponding block descriptor + bool recached = false; + BlockDescriptor search_key(d_ptr, device); + BusyBlocks::iterator block_itr = live_blocks.find(search_key); + if (block_itr != live_blocks.end()) + { + // Remove from live blocks + search_key = *block_itr; + live_blocks.erase(block_itr); + cached_bytes[device].live -= search_key.bytes; + + // Keep the returned allocation if bin is valid and we won't exceed the max cached threshold + if ((search_key.bin != INVALID_BIN) && (cached_bytes[device].free + search_key.bytes <= max_cached_bytes)) + { + // Insert returned allocation into free blocks + recached = true; + cached_blocks.insert(search_key); + cached_bytes[device].free += search_key.bytes; + + if (debug) _CubLog("\tDevice %d returned %lld bytes from associated stream %lld.\n\t\t %lld available blocks cached (%lld bytes), %lld live blocks outstanding. (%lld bytes)\n", + device, (long long) search_key.bytes, (long long) search_key.associated_stream, (long long) cached_blocks.size(), + (long long) cached_bytes[device].free, (long long) live_blocks.size(), (long long) cached_bytes[device].live); + } + } + + // Unlock + mutex.unlock(); + + // First set to specified device (entrypoint may not be set) + if (device != entrypoint_device) + { + if (CubDebug(error = cudaGetDevice(&entrypoint_device))) return error; + if (CubDebug(error = cudaSetDevice(device))) return error; + } + + if (recached) + { + // Insert the ready event in the associated stream (must have current device set properly) + if (CubDebug(error = cudaEventRecord(search_key.ready_event, search_key.associated_stream))) return error; + } + + if (!recached) + { + // Free the allocation from the runtime and cleanup the event. + if (CubDebug(error = cudaFree(d_ptr))) return error; + if (CubDebug(error = cudaEventDestroy(search_key.ready_event))) return error; + + if (debug) _CubLog("\tDevice %d freed %lld bytes from associated stream %lld.\n\t\t %lld available blocks cached (%lld bytes), %lld live blocks (%lld bytes) outstanding.\n", + device, (long long) search_key.bytes, (long long) search_key.associated_stream, (long long) cached_blocks.size(), (long long) cached_bytes[device].free, (long long) live_blocks.size(), (long long) cached_bytes[device].live); + } + + // Reset device + if ((entrypoint_device != INVALID_DEVICE_ORDINAL) && (entrypoint_device != device)) + { + if (CubDebug(error = cudaSetDevice(entrypoint_device))) return error; + } + + return error; + } + + + /** + * \brief Frees a live allocation of device memory on the current device, returning it to the allocator. + * + * Once freed, the allocation becomes available immediately for reuse within the \p active_stream + * with which it was associated with during allocation, and it becomes available for reuse within other + * streams when all prior work submitted to \p active_stream has completed. + */ + cudaError_t DeviceFree( + void* d_ptr) + { + return DeviceFree(INVALID_DEVICE_ORDINAL, d_ptr); + } + + + /** + * \brief Frees all cached device allocations on all devices + */ + cudaError_t FreeAllCached() + { + cudaError_t error = cudaSuccess; + int entrypoint_device = INVALID_DEVICE_ORDINAL; + int current_device = INVALID_DEVICE_ORDINAL; + + mutex.lock(); + + while (!cached_blocks.empty()) + { + // Get first block + CachedBlocks::iterator begin = cached_blocks.begin(); + + // Get entry-point device ordinal if necessary + if (entrypoint_device == INVALID_DEVICE_ORDINAL) + { + if (CubDebug(error = cudaGetDevice(&entrypoint_device))) break; + } + + // Set current device ordinal if necessary + if (begin->device != current_device) + { + if (CubDebug(error = cudaSetDevice(begin->device))) break; + current_device = begin->device; + } + + // Free device memory + if (CubDebug(error = cudaFree(begin->d_ptr))) break; + if (CubDebug(error = cudaEventDestroy(begin->ready_event))) break; + + // Reduce balance and erase entry + const size_t block_bytes = begin->bytes; + cached_bytes[current_device].free -= block_bytes; + cached_blocks.erase(begin); + + if (debug) _CubLog("\tDevice %d freed %lld bytes.\n\t\t %lld available blocks cached (%lld bytes), %lld live blocks (%lld bytes) outstanding.\n", + current_device, (long long) block_bytes, (long long) cached_blocks.size(), (long long) cached_bytes[current_device].free, (long long) live_blocks.size(), (long long) cached_bytes[current_device].live); + + } + + mutex.unlock(); + + // Attempt to revert back to entry-point device if necessary + if (entrypoint_device != INVALID_DEVICE_ORDINAL) + { + if (CubDebug(error = cudaSetDevice(entrypoint_device))) return error; + } + + return error; + } + + + /** + * \brief Destructor + */ + virtual ~CachingDeviceAllocator() + { + if (!skip_cleanup) + FreeAllCached(); + } + +}; + + + + +/** @} */ // end group UtilMgmt + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_arch.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_arch.cuh new file mode 100644 index 0000000000000000000000000000000000000000..d2506e93cfca9a7f5005076a46eb009a43b64d5b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_arch.cuh @@ -0,0 +1,164 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Static architectural properties by SM version. + */ + +#pragma once + +#include +#include +#include + +// Legacy include; this functionality used to be defined in here. +#include + +CUB_NAMESPACE_BEGIN + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + +// \deprecated [Since 2.1.0] +#define CUB_USE_COOPERATIVE_GROUPS + +/// In device code, CUB_PTX_ARCH expands to the PTX version for which we are +/// compiling. In host code, CUB_PTX_ARCH's value is implementation defined. +#ifndef CUB_PTX_ARCH + #if defined(_NVHPC_CUDA) + // __NVCOMPILER_CUDA_ARCH__ is the target PTX version, and is defined + // when compiling both host code and device code. Currently, only one + // PTX version can be targeted. + #define CUB_PTX_ARCH __NVCOMPILER_CUDA_ARCH__ + #elif !defined(__CUDA_ARCH__) + #define CUB_PTX_ARCH 0 + #else + #define CUB_PTX_ARCH __CUDA_ARCH__ + #endif +#endif + +// These definitions were intended for internal use only and are now obsolete. +// If you relied on them, consider porting your code to use the functionality +// in libcu++'s header. +// For a temporary workaround, define CUB_PROVIDE_LEGACY_ARCH_MACROS to make +// them available again. These should be considered deprecated and will be +// fully removed in a future version. +#ifdef CUB_PROVIDE_LEGACY_ARCH_MACROS + #ifndef CUB_IS_DEVICE_CODE + #if defined(_NVHPC_CUDA) + #define CUB_IS_DEVICE_CODE __builtin_is_device_code() + #define CUB_IS_HOST_CODE (!__builtin_is_device_code()) + #define CUB_INCLUDE_DEVICE_CODE 1 + #define CUB_INCLUDE_HOST_CODE 1 + #elif CUB_PTX_ARCH > 0 + #define CUB_IS_DEVICE_CODE 1 + #define CUB_IS_HOST_CODE 0 + #define CUB_INCLUDE_DEVICE_CODE 1 + #define CUB_INCLUDE_HOST_CODE 0 + #else + #define CUB_IS_DEVICE_CODE 0 + #define CUB_IS_HOST_CODE 1 + #define CUB_INCLUDE_DEVICE_CODE 0 + #define CUB_INCLUDE_HOST_CODE 1 + #endif + #endif +#endif // CUB_PROVIDE_LEGACY_ARCH_MACROS + +/// Maximum number of devices supported. +#ifndef CUB_MAX_DEVICES + #define CUB_MAX_DEVICES (128) +#endif + +static_assert(CUB_MAX_DEVICES > 0, "CUB_MAX_DEVICES must be greater than 0."); + + +/// Number of threads per warp +#ifndef CUB_LOG_WARP_THREADS + #define CUB_LOG_WARP_THREADS(unused) (5) + #define CUB_WARP_THREADS(unused) (1 << CUB_LOG_WARP_THREADS(0)) + + #define CUB_PTX_WARP_THREADS CUB_WARP_THREADS(0) + #define CUB_PTX_LOG_WARP_THREADS CUB_LOG_WARP_THREADS(0) +#endif + + +/// Number of smem banks +#ifndef CUB_LOG_SMEM_BANKS + #define CUB_LOG_SMEM_BANKS(unused) (5) + #define CUB_SMEM_BANKS(unused) (1 << CUB_LOG_SMEM_BANKS(0)) + + #define CUB_PTX_LOG_SMEM_BANKS CUB_LOG_SMEM_BANKS(0) + #define CUB_PTX_SMEM_BANKS CUB_SMEM_BANKS +#endif + + +/// Oversubscription factor +#ifndef CUB_SUBSCRIPTION_FACTOR + #define CUB_SUBSCRIPTION_FACTOR(unused) (5) + #define CUB_PTX_SUBSCRIPTION_FACTOR CUB_SUBSCRIPTION_FACTOR(0) +#endif + + +/// Prefer padding overhead vs X-way conflicts greater than this threshold +#ifndef CUB_PREFER_CONFLICT_OVER_PADDING + #define CUB_PREFER_CONFLICT_OVER_PADDING(unused) (1) + #define CUB_PTX_PREFER_CONFLICT_OVER_PADDING CUB_PREFER_CONFLICT_OVER_PADDING(0) +#endif + + +template < + int NOMINAL_4B_BLOCK_THREADS, + int NOMINAL_4B_ITEMS_PER_THREAD, + typename T> +struct RegBoundScaling +{ + enum { + ITEMS_PER_THREAD = CUB_MAX(1, NOMINAL_4B_ITEMS_PER_THREAD * 4 / CUB_MAX(4, sizeof(T))), + BLOCK_THREADS = CUB_MIN(NOMINAL_4B_BLOCK_THREADS, (((1024 * 48) / (sizeof(T) * ITEMS_PER_THREAD)) + 31) / 32 * 32), + }; +}; + + +template < + int NOMINAL_4B_BLOCK_THREADS, + int NOMINAL_4B_ITEMS_PER_THREAD, + typename T> +struct MemBoundScaling +{ + enum { + ITEMS_PER_THREAD = CUB_MAX(1, CUB_MIN(NOMINAL_4B_ITEMS_PER_THREAD * 4 / sizeof(T), NOMINAL_4B_ITEMS_PER_THREAD * 2)), + BLOCK_THREADS = CUB_MIN(NOMINAL_4B_BLOCK_THREADS, (((1024 * 48) / (sizeof(T) * ITEMS_PER_THREAD)) + 31) / 32 * 32), + }; +}; + + + + +#endif // Do not document + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_compiler.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_compiler.cuh new file mode 100644 index 0000000000000000000000000000000000000000..7cda3c44012496b7cce26c8f94cc7e17fa5179e0 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_compiler.cuh @@ -0,0 +1,81 @@ +/****************************************************************************** + * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + *AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Detect compiler information. + */ + +#pragma once + +// enumerate host compilers we know about +#define CUB_HOST_COMPILER_UNKNOWN 0 +#define CUB_HOST_COMPILER_MSVC 1 +#define CUB_HOST_COMPILER_GCC 2 +#define CUB_HOST_COMPILER_CLANG 3 + +// enumerate device compilers we know about +#define CUB_DEVICE_COMPILER_UNKNOWN 0 +#define CUB_DEVICE_COMPILER_MSVC 1 +#define CUB_DEVICE_COMPILER_GCC 2 +#define CUB_DEVICE_COMPILER_NVCC 3 +#define CUB_DEVICE_COMPILER_CLANG 4 + +// figure out which host compiler we're using +#if defined(_MSC_VER) +# define CUB_HOST_COMPILER CUB_HOST_COMPILER_MSVC +# define CUB_MSVC_VERSION _MSC_VER +# define CUB_MSVC_VERSION_FULL _MSC_FULL_VER +#elif defined(__clang__) +# define CUB_HOST_COMPILER CUB_HOST_COMPILER_CLANG +# define CUB_CLANG_VERSION \ + (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) +#elif defined(__GNUC__) +# define CUB_HOST_COMPILER CUB_HOST_COMPILER_GCC +# define CUB_GCC_VERSION \ + (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +#else +# define CUB_HOST_COMPILER CUB_HOST_COMPILER_UNKNOWN +#endif // CUB_HOST_COMPILER + +// figure out which device compiler we're using +#if defined(__CUDACC__) || defined(_NVHPC_CUDA) +# define CUB_DEVICE_COMPILER CUB_DEVICE_COMPILER_NVCC +#elif CUB_HOST_COMPILER == CUB_HOST_COMPILER_MSVC +# define CUB_DEVICE_COMPILER CUB_DEVICE_COMPILER_MSVC +#elif CUB_HOST_COMPILER == CUB_HOST_COMPILER_GCC +# define CUB_DEVICE_COMPILER CUB_DEVICE_COMPILER_GCC +#elif CUB_HOST_COMPILER == CUB_HOST_COMPILER_CLANG +// CUDA-capable clang should behave similar to NVCC. +# if defined(__CUDA__) +# define CUB_DEVICE_COMPILER CUB_DEVICE_COMPILER_NVCC +# else +# define CUB_DEVICE_COMPILER CUB_DEVICE_COMPILER_CLANG +# endif +#else +# define CUB_DEVICE_COMPILER CUB_DEVICE_COMPILER_UNKNOWN +#endif diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_cpp_dialect.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_cpp_dialect.cuh new file mode 100644 index 0000000000000000000000000000000000000000..23adf8e8dc79c263b7fb964f7d1a4c456018e85e --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_cpp_dialect.cuh @@ -0,0 +1,151 @@ +/****************************************************************************** + * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + *AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/*! \file + * \brief Detect the version of the C++ standard used by the compiler. + */ + +#pragma once + +#include "util_compiler.cuh" + +// Deprecation warnings may be silenced by defining the following macros. These +// may be combined. +// - CUB_IGNORE_DEPRECATED_CPP_DIALECT: +// Ignore all deprecated C++ dialects and outdated compilers. +// - CUB_IGNORE_DEPRECATED_CPP_11: +// Ignore deprecation warnings when compiling with C++11. C++03 and outdated +// compilers will still issue warnings. +// - CUB_IGNORE_DEPRECATED_COMPILER +// Ignore deprecation warnings when using deprecated compilers. Compiling +// with C++03 and C++11 will still issue warnings. + +// Check for the thrust opt-outs as well: +#if !defined(CUB_IGNORE_DEPRECATED_CPP_DIALECT) && \ + defined(THRUST_IGNORE_DEPRECATED_CPP_DIALECT) +# define CUB_IGNORE_DEPRECATED_CPP_DIALECT +#endif +#if !defined(CUB_IGNORE_DEPRECATED_CPP_11) && \ + defined(THRUST_IGNORE_DEPRECATED_CPP_11) +# define CUB_IGNORE_DEPRECATED_CPP_11 +#endif +#if !defined(CUB_IGNORE_DEPRECATED_COMPILER) && \ + defined(THRUST_IGNORE_DEPRECATED_COMPILER) +# define CUB_IGNORE_DEPRECATED_COMPILER +#endif + +#ifdef CUB_IGNORE_DEPRECATED_CPP_DIALECT +# define CUB_IGNORE_DEPRECATED_CPP_11 +# define CUB_IGNORE_DEPRECATED_COMPILER +#endif + +// Define this to override the built-in detection. +#ifndef CUB_CPP_DIALECT + +// MSVC does not define __cplusplus correctly. _MSVC_LANG is used instead. +// This macro is only defined in MSVC 2015U3+. +# ifdef _MSVC_LANG // Do not replace with CUB_HOST_COMPILER test (see above) +// MSVC2015 reports C++14 but lacks extended constexpr support. Treat as C++11. +# if CUB_MSVC_VERSION < 1910 && _MSVC_LANG > 201103L /* MSVC < 2017 && CPP > 2011 */ +# define CUB_CPLUSPLUS 201103L /* Fix to 2011 */ +# else +# define CUB_CPLUSPLUS _MSVC_LANG /* We'll trust this for now. */ +# endif // MSVC 2015 C++14 fix +# else +# define CUB_CPLUSPLUS __cplusplus +# endif + +// Detect current dialect: +# if CUB_CPLUSPLUS < 201103L +# define CUB_CPP_DIALECT 2003 +# elif CUB_CPLUSPLUS < 201402L +# define CUB_CPP_DIALECT 2011 +# elif CUB_CPLUSPLUS < 201703L +# define CUB_CPP_DIALECT 2014 +# elif CUB_CPLUSPLUS == 201703L +# define CUB_CPP_DIALECT 2017 +# elif CUB_CPLUSPLUS > 201703L // unknown, but is higher than 2017. +# define CUB_CPP_DIALECT 2020 +# endif + +# undef CUB_CPLUSPLUS // cleanup + +#endif // !CUB_CPP_DIALECT + +// Define CUB_COMPILER_DEPRECATION macro: +#if CUB_HOST_COMPILER == CUB_HOST_COMPILER_MSVC +# define CUB_COMP_DEPR_IMPL(msg) \ + __pragma(message(__FILE__ ":" CUB_COMP_DEPR_IMPL0(__LINE__) ": warning: " #msg)) +# define CUB_COMP_DEPR_IMPL0(x) CUB_COMP_DEPR_IMPL1(x) +# define CUB_COMP_DEPR_IMPL1(x) #x +#else // clang / gcc: +# define CUB_COMP_DEPR_IMPL(msg) CUB_COMP_DEPR_IMPL0(GCC warning #msg) +# define CUB_COMP_DEPR_IMPL0(expr) _Pragma(#expr) +# define CUB_COMP_DEPR_IMPL1 /* intentionally blank */ +#endif + +#define CUB_COMPILER_DEPRECATION(REQ) \ + CUB_COMP_DEPR_IMPL(CUB requires at least REQ. Define CUB_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message.) + +#define CUB_COMPILER_DEPRECATION_SOFT(REQ, CUR) \ + CUB_COMP_DEPR_IMPL(CUB requires at least REQ. CUR is deprecated but still supported. CUR support will be removed in a future release. Define CUB_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message.) + +#ifndef CUB_IGNORE_DEPRECATED_COMPILER + +// Compiler checks: +# if CUB_HOST_COMPILER == CUB_HOST_COMPILER_GCC && CUB_GCC_VERSION < 50000 + CUB_COMPILER_DEPRECATION(GCC 5.0); +# elif CUB_HOST_COMPILER == CUB_HOST_COMPILER_CLANG && CUB_CLANG_VERSION < 70000 + CUB_COMPILER_DEPRECATION(Clang 7.0); +# elif CUB_HOST_COMPILER == CUB_HOST_COMPILER_MSVC && CUB_MSVC_VERSION < 1910 + // <2017. Hard upgrade message: + CUB_COMPILER_DEPRECATION(MSVC 2019 (19.20/16.0/14.20)); +# elif CUB_HOST_COMPILER == CUB_HOST_COMPILER_MSVC && CUB_MSVC_VERSION < 1920 + // >=2017, <2019. Soft deprecation message: + CUB_COMPILER_DEPRECATION_SOFT(MSVC 2019 (19.20/16.0/14.20), MSVC 2017); +# endif + +#endif // CUB_IGNORE_DEPRECATED_COMPILER + +#ifndef CUB_IGNORE_DEPRECATED_DIALECT + +// Dialect checks: +# if CUB_CPP_DIALECT < 2011 + // +#include + +#include + +#include + +CUB_NAMESPACE_BEGIN + + +#ifdef DOXYGEN_SHOULD_SKIP_THIS // Only parse this during doxygen passes: + +/** + * @def CUB_DEBUG_LOG + * + * Causes kernel launch configurations to be printed to the console + */ +#define CUB_DEBUG_LOG + +/** + * @def CUB_DEBUG_SYNC + * + * Causes synchronization of the stream after every kernel launch to check + * for errors. Also causes kernel launch configurations to be printed to the + * console. + */ +#define CUB_DEBUG_SYNC + +/** + * @def CUB_DEBUG_HOST_ASSERTIONS + * + * Extends `CUB_DEBUG_SYNC` effects by checking host-side precondition + * assertions. + */ +#define CUB_DEBUG_HOST_ASSERTIONS + +/** + * @def CUB_DEBUG_DEVICE_ASSERTIONS + * + * Extends `CUB_DEBUG_HOST_ASSERTIONS` effects by checking device-side + * precondition assertions. + */ +#define CUB_DEBUG_DEVICE_ASSERTIONS + +/** + * @def CUB_DEBUG_ALL + * + * Causes host and device-side precondition assertions to be checked. Apart + * from that, causes synchronization of the stream after every kernel launch to + * check for errors. Also causes kernel launch configurations to be printed to + * the console. + */ +#define CUB_DEBUG_ALL + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +/** + * \addtogroup UtilMgmt + * @{ + */ + + +// `CUB_DETAIL_DEBUG_LEVEL_*`: Implementation details, internal use only: + +#define CUB_DETAIL_DEBUG_LEVEL_NONE 0 +#define CUB_DETAIL_DEBUG_LEVEL_HOST_ASSERTIONS_ONLY 1 +#define CUB_DETAIL_DEBUG_LEVEL_LOG 2 +#define CUB_DETAIL_DEBUG_LEVEL_SYNC 3 +#define CUB_DETAIL_DEBUG_LEVEL_HOST_ASSERTIONS 4 +#define CUB_DETAIL_DEBUG_LEVEL_DEVICE_ASSERTIONS 5 +#define CUB_DETAIL_DEBUG_LEVEL_ALL 1000 + +// `CUB_DEBUG_*`: User interfaces: + +// Extra logging, no syncs +#ifdef CUB_DEBUG_LOG +#define CUB_DETAIL_DEBUG_LEVEL CUB_DETAIL_DEBUG_LEVEL_LOG +#endif + +// Logging + syncs +#ifdef CUB_DEBUG_SYNC +#define CUB_DETAIL_DEBUG_LEVEL CUB_DETAIL_DEBUG_LEVEL_SYNC +#endif + +// Logging + syncs + host assertions +#ifdef CUB_DEBUG_HOST_ASSERTIONS +#define CUB_DETAIL_DEBUG_LEVEL CUB_DETAIL_DEBUG_LEVEL_HOST_ASSERTIONS +#endif + +// Logging + syncs + host assertions + device assertions +#ifdef CUB_DEBUG_DEVICE_ASSERTIONS +#define CUB_DETAIL_DEBUG_LEVEL CUB_DETAIL_DEBUG_LEVEL_DEVICE_ASSERTIONS +#endif + +// All +#ifdef CUB_DEBUG_ALL +#define CUB_DETAIL_DEBUG_LEVEL CUB_DETAIL_DEBUG_LEVEL_ALL +#endif + +// Default case, no extra debugging: +#ifndef CUB_DETAIL_DEBUG_LEVEL +#ifdef NDEBUG +#define CUB_DETAIL_DEBUG_LEVEL CUB_DETAIL_DEBUG_LEVEL_NONE +#else +#define CUB_DETAIL_DEBUG_LEVEL CUB_DETAIL_DEBUG_LEVEL_HOST_ASSERTIONS_ONLY +#endif +#endif + +/* + * `CUB_DETAIL_DEBUG_ENABLE_*`: + * Internal implementation details, used for testing enabled debug features: + */ + +#if CUB_DETAIL_DEBUG_LEVEL >= CUB_DETAIL_DEBUG_LEVEL_LOG +#define CUB_DETAIL_DEBUG_ENABLE_LOG +#endif + +#if CUB_DETAIL_DEBUG_LEVEL >= CUB_DETAIL_DEBUG_LEVEL_SYNC +#define CUB_DETAIL_DEBUG_ENABLE_SYNC +#endif + +#if (CUB_DETAIL_DEBUG_LEVEL >= CUB_DETAIL_DEBUG_LEVEL_HOST_ASSERTIONS) || \ + (CUB_DETAIL_DEBUG_LEVEL == CUB_DETAIL_DEBUG_LEVEL_HOST_ASSERTIONS_ONLY) +#define CUB_DETAIL_DEBUG_ENABLE_HOST_ASSERTIONS +#endif + +#if CUB_DETAIL_DEBUG_LEVEL >= CUB_DETAIL_DEBUG_LEVEL_DEVICE_ASSERTIONS +#define CUB_DETAIL_DEBUG_ENABLE_DEVICE_ASSERTIONS +#endif + + +/// CUB error reporting macro (prints error messages to stderr) +#if (defined(DEBUG) || defined(_DEBUG)) && !defined(CUB_STDERR) + #define CUB_STDERR +#endif + +/** + * \brief %If \p CUB_STDERR is defined and \p error is not \p cudaSuccess, the + * corresponding error message is printed to \p stderr (or \p stdout in device + * code) along with the supplied source context. + * + * \return The CUDA error. + */ +__host__ __device__ +__forceinline__ +cudaError_t Debug(cudaError_t error, const char *filename, int line) +{ + // Clear the global CUDA error state which may have been set by the last + // call. Otherwise, errors may "leak" to unrelated kernel launches. + + // clang-format off + #ifndef CUB_RDC_ENABLED + #define CUB_TEMP_DEVICE_CODE + #else + #define CUB_TEMP_DEVICE_CODE cudaGetLastError() + #endif + + NV_IF_TARGET( + NV_IS_HOST, + (cudaGetLastError();), + (CUB_TEMP_DEVICE_CODE;) + ); + + #undef CUB_TEMP_DEVICE_CODE + // clang-format on + +#ifdef CUB_STDERR + if (error) + { + NV_IF_TARGET( + NV_IS_HOST, ( + fprintf(stderr, + "CUDA error %d [%s, %d]: %s\n", + error, + filename, + line, + cudaGetErrorString(error)); + fflush(stderr); + ), + ( + printf("CUDA error %d [block (%d,%d,%d) thread (%d,%d,%d), %s, %d]\n", + error, + blockIdx.z, + blockIdx.y, + blockIdx.x, + threadIdx.z, + threadIdx.y, + threadIdx.x, + filename, + line); + ) + ); + } +#else + (void)filename; + (void)line; +#endif + + return error; +} + +/** + * \brief Debug macro + */ +#ifndef CubDebug + #define CubDebug(e) CUB_NS_QUALIFIER::Debug((cudaError_t) (e), __FILE__, __LINE__) +#endif + + +/** + * \brief Debug macro with exit + */ +#ifndef CubDebugExit + #define CubDebugExit(e) if (CUB_NS_QUALIFIER::Debug((cudaError_t) (e), __FILE__, __LINE__)) { exit(1); } +#endif + + +/** + * \brief Log macro for printf statements. + */ +#if !defined(_CubLog) +#if defined(_NVHPC_CUDA) || !(defined(__clang__) && defined(__CUDA__)) + +// NVCC / NVC++ +#define _CubLog(format, ...) \ + do \ + { \ + NV_IF_TARGET(NV_IS_HOST, \ + (printf(format, __VA_ARGS__);), \ + (printf("[block (%d,%d,%d), thread (%d,%d,%d)]: " format, \ + blockIdx.z, \ + blockIdx.y, \ + blockIdx.x, \ + threadIdx.z, \ + threadIdx.y, \ + threadIdx.x, \ + __VA_ARGS__);)); \ + } while (false) + +#else // Clang: + +// XXX shameless hack for clang around variadic printf... +// Compilies w/o supplying -std=c++11 but shows warning, +// so we silence them :) +#pragma clang diagnostic ignored "-Wc++11-extensions" +#pragma clang diagnostic ignored "-Wunnamed-type-template-args" +template +inline __host__ __device__ void va_printf(char const *format, + Args const &...args) +{ +#ifdef __CUDA_ARCH__ + printf(format, + blockIdx.z, + blockIdx.y, + blockIdx.x, + threadIdx.z, + threadIdx.y, + threadIdx.x, + args...); +#else + printf(format, args...); +#endif +} +#ifndef __CUDA_ARCH__ +#define _CubLog(format, ...) CUB_NS_QUALIFIER::va_printf(format, __VA_ARGS__); +#else +#define _CubLog(format, ...) \ + CUB_NS_QUALIFIER::va_printf("[block (%d,%d,%d), thread " \ + "(%d,%d,%d)]: " format, \ + __VA_ARGS__); +#endif +#endif +#endif + +/** @} */ // end group UtilMgmt + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_deprecated.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_deprecated.cuh new file mode 100644 index 0000000000000000000000000000000000000000..a988c9fca908ef44306b4af48d55cedc6cca32a5 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_deprecated.cuh @@ -0,0 +1,79 @@ +/****************************************************************************** + * Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + *AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Define CUB_DEPRECATED macro. + */ + +#pragma once + + +#include +#include +#include +#include + + +#if defined(THRUST_IGNORE_DEPRECATED_API) && !defined(CUB_IGNORE_DEPRECATED_API) +# define CUB_IGNORE_DEPRECATED_API +#endif + +#ifdef CUB_IGNORE_DEPRECATED_API +# define CUB_DEPRECATED +# define CUB_DEPRECATED_BECAUSE(MSG) +#elif CUB_CPP_DIALECT >= 2014 +# define CUB_DEPRECATED [[deprecated]] +# define CUB_DEPRECATED_BECAUSE(MSG) [[deprecated(MSG)]] +#elif CUB_HOST_COMPILER == CUB_HOST_COMPILER_MSVC +# define CUB_DEPRECATED __declspec(deprecated) +# define CUB_DEPRECATED_BECAUSE(MSG) __declspec(deprecated(MSG)) +#elif CUB_HOST_COMPILER == CUB_HOST_COMPILER_CLANG +# define CUB_DEPRECATED __attribute__((deprecated)) +# define CUB_DEPRECATED_BECAUSE(MSG) __attribute__((deprecated(MSG))) +#elif CUB_HOST_COMPILER == CUB_HOST_COMPILER_GCC +# define CUB_DEPRECATED __attribute__((deprecated)) +# define CUB_DEPRECATED_BECAUSE(MSG) __attribute__((deprecated(MSG))) +#else +# define CUB_DEPRECATED +# define CUB_DEPRECATED_BECAUSE(MSG) +#endif + +#define CUB_DETAIL_RUNTIME_DEBUG_SYNC_IS_NOT_SUPPORTED \ + CUB_DEPRECATED_BECAUSE( \ + "CUB no longer accepts `debug_synchronous` parameter. " \ + "Define CUB_DEBUG_SYNC instead, or silence this message with " \ + "CUB_IGNORE_DEPRECATED_API.") + +#define CUB_DETAIL_RUNTIME_DEBUG_SYNC_USAGE_LOG \ + if (debug_synchronous) \ + { \ + _CubLog("%s\n", \ + "CUB no longer accepts `debug_synchronous` parameter. " \ + "Define CUB_DEBUG_SYNC instead."); \ + } + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_device.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_device.cuh new file mode 100644 index 0000000000000000000000000000000000000000..cb798372fc3ee668d1a4b3c2eefe8f71b894f5c0 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_device.cuh @@ -0,0 +1,714 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2020, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Properties of a given CUDA device and the corresponding PTX bundle + */ + +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +CUB_NAMESPACE_BEGIN + + +/** + * \addtogroup UtilMgmt + * @{ + */ + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + + +/** + * \brief Alias temporaries to externally-allocated device storage (or simply return the amount of storage needed). + */ +template +__host__ __device__ __forceinline__ +cudaError_t AliasTemporaries( + void *d_temp_storage, ///< [in] Device-accessible allocation of temporary storage. When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done. + size_t& temp_storage_bytes, ///< [in,out] Size in bytes of \t d_temp_storage allocation + void* (&allocations)[ALLOCATIONS], ///< [in,out] Pointers to device allocations needed + size_t (&allocation_sizes)[ALLOCATIONS]) ///< [in] Sizes in bytes of device allocations needed +{ + const int ALIGN_BYTES = 256; + const int ALIGN_MASK = ~(ALIGN_BYTES - 1); + + // Compute exclusive prefix sum over allocation requests + size_t allocation_offsets[ALLOCATIONS]; + size_t bytes_needed = 0; + for (int i = 0; i < ALLOCATIONS; ++i) + { + size_t allocation_bytes = (allocation_sizes[i] + ALIGN_BYTES - 1) & ALIGN_MASK; + allocation_offsets[i] = bytes_needed; + bytes_needed += allocation_bytes; + } + bytes_needed += ALIGN_BYTES - 1; + + // Check if the caller is simply requesting the size of the storage allocation + if (!d_temp_storage) + { + temp_storage_bytes = bytes_needed; + return cudaSuccess; + } + + // Check if enough storage provided + if (temp_storage_bytes < bytes_needed) + { + return CubDebug(cudaErrorInvalidValue); + } + + // Alias + d_temp_storage = (void *) ((size_t(d_temp_storage) + ALIGN_BYTES - 1) & ALIGN_MASK); + for (int i = 0; i < ALLOCATIONS; ++i) + { + allocations[i] = static_cast(d_temp_storage) + allocation_offsets[i]; + } + + return cudaSuccess; +} + + +/** + * \brief Empty kernel for querying PTX manifest metadata (e.g., version) for the current device + */ +template +__global__ void EmptyKernel(void) { } + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +/** + * \brief Returns the current device or -1 if an error occurred. + */ +CUB_RUNTIME_FUNCTION inline int CurrentDevice() +{ + int device = -1; + if (CubDebug(cudaGetDevice(&device))) return -1; + return device; +} + +/** + * \brief RAII helper which saves the current device and switches to the + * specified device on construction and switches to the saved device on + * destruction. + */ +struct SwitchDevice +{ +private: + int const old_device; + bool const needs_reset; +public: + __host__ inline SwitchDevice(int new_device) + : old_device(CurrentDevice()), needs_reset(old_device != new_device) + { + if (needs_reset) + CubDebug(cudaSetDevice(new_device)); + } + + __host__ inline ~SwitchDevice() + { + if (needs_reset) + CubDebug(cudaSetDevice(old_device)); + } +}; + +/** + * \brief Returns the number of CUDA devices available or -1 if an error + * occurred. + */ +CUB_RUNTIME_FUNCTION inline int DeviceCountUncached() +{ + int count = -1; + if (CubDebug(cudaGetDeviceCount(&count))) + // CUDA makes no guarantees about the state of the output parameter if + // `cudaGetDeviceCount` fails; in practice, they don't, but out of + // paranoia we'll reset `count` to `-1`. + count = -1; + return count; +} + +/** + * \brief Cache for an arbitrary value produced by a nullary function. + */ +template +struct ValueCache +{ + T const value; + + /** + * \brief Call the nullary function to produce the value and construct the + * cache. + */ + __host__ inline ValueCache() : value(Function()) {} +}; + +// Host code, only safely usable in C++11 or newer, where thread-safe +// initialization of static locals is guaranteed. This is a separate function +// to avoid defining a local static in a host/device function. +__host__ inline int DeviceCountCachedValue() +{ + static ValueCache cache; + return cache.value; +} + +/** + * \brief Returns the number of CUDA devices available. + * + * \note This function may cache the result internally. + * + * \note This function is thread safe. + */ +CUB_RUNTIME_FUNCTION inline int DeviceCount() +{ + int result = -1; + + NV_IF_TARGET(NV_IS_HOST, + (result = DeviceCountCachedValue();), + (result = DeviceCountUncached();)); + + return result; +} + +/** + * \brief Per-device cache for a CUDA attribute value; the attribute is queried + * and stored for each device upon construction. + */ +struct PerDeviceAttributeCache +{ + struct DevicePayload + { + int attribute; + cudaError_t error; + }; + + // Each entry starts in the `DeviceEntryEmpty` state, then proceeds to the + // `DeviceEntryInitializing` state, and then proceeds to the + // `DeviceEntryReady` state. These are the only state transitions allowed; + // e.g. a linear sequence of transitions. + enum DeviceEntryStatus + { + DeviceEntryEmpty = 0, + DeviceEntryInitializing, + DeviceEntryReady + }; + + struct DeviceEntry + { + std::atomic flag; + DevicePayload payload; + }; + +private: + std::array entries_; + +public: + /** + * \brief Construct the cache. + */ + __host__ inline PerDeviceAttributeCache() : entries_() + { + assert(DeviceCount() <= CUB_MAX_DEVICES); + } + + /** + * \brief Retrieves the payload of the cached function \p f for \p device. + * + * \note You must pass a morally equivalent function in to every call or + * this function has undefined behavior. + */ + template + __host__ DevicePayload operator()(Invocable&& f, int device) + { + if (device >= DeviceCount()) + return DevicePayload{0, cudaErrorInvalidDevice}; + + auto& entry = entries_[device]; + auto& flag = entry.flag; + auto& payload = entry.payload; + + DeviceEntryStatus old_status = DeviceEntryEmpty; + + // First, check for the common case of the entry being ready. + if (flag.load(std::memory_order_acquire) != DeviceEntryReady) + { + // Assume the entry is empty and attempt to lock it so we can fill + // it by trying to set the state from `DeviceEntryReady` to + // `DeviceEntryInitializing`. + if (flag.compare_exchange_strong(old_status, DeviceEntryInitializing, + std::memory_order_acq_rel, + std::memory_order_acquire)) + { + // We successfully set the state to `DeviceEntryInitializing`; + // we have the lock and it's our job to initialize this entry + // and then release it. + + // We don't use `CubDebug` here because we let the user code + // decide whether or not errors are hard errors. + payload.error = ::cuda::std::forward(f)(payload.attribute); + if (payload.error) + // Clear the global CUDA error state which may have been + // set by the last call. Otherwise, errors may "leak" to + // unrelated kernel launches. + cudaGetLastError(); + + // Release the lock by setting the state to `DeviceEntryReady`. + flag.store(DeviceEntryReady, std::memory_order_release); + } + + // If the `compare_exchange_weak` failed, then `old_status` has + // been updated with the value of `flag` that it observed. + + else if (old_status == DeviceEntryInitializing) + { + // Another execution agent is initializing this entry; we need + // to wait for them to finish; we'll know they're done when we + // observe the entry status as `DeviceEntryReady`. + do { old_status = flag.load(std::memory_order_acquire); } + while (old_status != DeviceEntryReady); + // FIXME: Use `atomic::wait` instead when we have access to + // host-side C++20 atomics. We could use libcu++, but it only + // supports atomics for SM60 and up, even if you're only using + // them in host code. + } + } + + // We now know that the state of our entry is `DeviceEntryReady`, so + // just return the entry's payload. + return entry.payload; + } +}; + +/** + * \brief Retrieves the PTX version that will be used on the current device (major * 100 + minor * 10). + */ +CUB_RUNTIME_FUNCTION inline cudaError_t PtxVersionUncached(int& ptx_version) +{ + // Instantiate `EmptyKernel` in both host and device code to ensure + // it can be called. + typedef void (*EmptyKernelPtr)(); + EmptyKernelPtr empty_kernel = EmptyKernel; + + // This is necessary for unused variable warnings in host compilers. The + // usual syntax of (void)empty_kernel; was not sufficient on MSVC2015. + (void)reinterpret_cast(empty_kernel); + + // Define a temporary macro that expands to the current target ptx version + // in device code. + // may provide an abstraction for this eventually. For now, + // we have to keep this usage of __CUDA_ARCH__. +#if defined(_NVHPC_CUDA) +#define CUB_TEMP_GET_PTX __builtin_current_device_sm() +#else +#define CUB_TEMP_GET_PTX __CUDA_ARCH__ +#endif + + cudaError_t result = cudaSuccess; + NV_IF_TARGET( + NV_IS_HOST, + ( + cudaFuncAttributes empty_kernel_attrs; + + result = cudaFuncGetAttributes(&empty_kernel_attrs, + reinterpret_cast(empty_kernel)); + CubDebug(result); + + ptx_version = empty_kernel_attrs.ptxVersion * 10; + ), + // NV_IS_DEVICE + ( + // This is necessary to ensure instantiation of EmptyKernel in device + // code. The `reinterpret_cast` is necessary to suppress a + // set-but-unused warnings. This is a meme now: + // https://twitter.com/blelbach/status/1222391615576100864 + (void)reinterpret_cast(empty_kernel); + + ptx_version = CUB_TEMP_GET_PTX; + )); + +#undef CUB_TEMP_GET_PTX + + return result; +} + +/** + * \brief Retrieves the PTX version that will be used on \p device (major * 100 + minor * 10). + */ +__host__ inline cudaError_t PtxVersionUncached(int& ptx_version, int device) +{ + SwitchDevice sd(device); + (void)sd; + return PtxVersionUncached(ptx_version); +} + +template +__host__ inline PerDeviceAttributeCache& GetPerDeviceAttributeCache() +{ + // C++11 guarantees that initialization of static locals is thread safe. + static PerDeviceAttributeCache cache; + return cache; +} + +struct PtxVersionCacheTag {}; +struct SmVersionCacheTag {}; + +/** + * \brief Retrieves the PTX version that will be used on \p device (major * 100 + minor * 10). + * + * \note This function may cache the result internally. + * + * \note This function is thread safe. + */ +__host__ inline cudaError_t PtxVersion(int& ptx_version, int device) +{ + auto const payload = GetPerDeviceAttributeCache()( + // If this call fails, then we get the error code back in the payload, + // which we check with `CubDebug` below. + [=] (int& pv) { return PtxVersionUncached(pv, device); }, + device); + + if (!CubDebug(payload.error)) + ptx_version = payload.attribute; + + return payload.error; +} + +/** + * \brief Retrieves the PTX version that will be used on the current device (major * 100 + minor * 10). + * + * \note This function may cache the result internally. + * + * \note This function is thread safe. + */ +CUB_RUNTIME_FUNCTION inline cudaError_t PtxVersion(int &ptx_version) +{ + cudaError_t result = cudaErrorUnknown; + NV_IF_TARGET( + NV_IS_HOST, + ( + auto const device = CurrentDevice(); + auto const payload = GetPerDeviceAttributeCache()( + // If this call fails, then we get the error code back in the payload, + // which we check with `CubDebug` below. + [=](int &pv) { return PtxVersionUncached(pv, device); }, + device); + + if (!CubDebug(payload.error)) + { + ptx_version = payload.attribute; + } + + result = payload.error; + ), + ( // NV_IS_DEVICE: + result = PtxVersionUncached(ptx_version); + )); + + return result; +} + +/** + * \brief Retrieves the SM version of \p device (major * 100 + minor * 10) + */ +CUB_RUNTIME_FUNCTION inline cudaError_t SmVersionUncached(int& sm_version, int device = CurrentDevice()) +{ + cudaError_t error = cudaSuccess; + do + { + int major = 0, minor = 0; + if (CubDebug(error = cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, device))) break; + if (CubDebug(error = cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, device))) break; + sm_version = major * 100 + minor * 10; + } + while (0); + + return error; +} + +/** + * \brief Retrieves the SM version of \p device (major * 100 + minor * 10) + * + * \note This function may cache the result internally. + * + * \note This function is thread safe. + */ +CUB_RUNTIME_FUNCTION inline cudaError_t SmVersion(int &sm_version, + int device = CurrentDevice()) +{ + cudaError_t result = cudaErrorUnknown; + + NV_IF_TARGET( + NV_IS_HOST, + ( + auto const payload = GetPerDeviceAttributeCache()( + // If this call fails, then we get the error code back in + // the payload, which we check with `CubDebug` below. + [=](int &pv) { return SmVersionUncached(pv, device); }, + device); + + if (!CubDebug(payload.error)) + { + sm_version = payload.attribute; + }; + + result = payload.error; + ), + ( // NV_IS_DEVICE + result = SmVersionUncached(sm_version, device); + )); + + return result; +} + +/** + * Synchronize the specified \p stream. + */ +CUB_RUNTIME_FUNCTION inline cudaError_t SyncStream(cudaStream_t stream) +{ + cudaError_t result = cudaErrorNotSupported; + + NV_IF_TARGET(NV_IS_HOST, + (result = CubDebug(cudaStreamSynchronize(stream));), + ((void)stream; + result = CubDebug(cub::detail::device_synchronize());)); + + return result; +} + +namespace detail +{ + +/** + * Same as SyncStream, but intended for use with the debug_synchronous flags + * in device algorithms. This should not be used if synchronization is required + * for correctness. + * + * If `debug_synchronous` is false, this function will immediately return + * cudaSuccess. If true, one of the following will occur: + * + * If synchronization is supported by the current compilation target and + * settings, the sync is performed and the sync result is returned. + * + * If syncs are not supported then no sync is performed, but a message is logged + * via _CubLog and cudaSuccess is returned. + */ +CUB_RUNTIME_FUNCTION inline cudaError_t DebugSyncStream(cudaStream_t stream) +{ +#ifndef CUB_DETAIL_DEBUG_ENABLE_SYNC + + (void)stream; + return cudaSuccess; + +#else // CUB_DETAIL_DEBUG_ENABLE_SYNC: + +#define CUB_TMP_SYNC_AVAILABLE \ + _CubLog("%s\n", "Synchronizing..."); \ + return SyncStream(stream) + +#define CUB_TMP_DEVICE_SYNC_UNAVAILABLE \ + (void)stream; \ + _CubLog("WARNING: Skipping CUB `debug_synchronous` synchronization (%s).\n", \ + "device-side sync requires // or equivalently + * + * template + * __global__ void ExampleKernel() + * { + * // Allocate shared memory for BlockScan + * __shared__ volatile T buffer[4096]; + * + * ... + * } + * + * ... + * + * // Determine SM occupancy for ExampleKernel specialized for unsigned char + * int max_sm_occupancy; + * MaxSmOccupancy(max_sm_occupancy, ExampleKernel, 64); + * + * // max_sm_occupancy <-- 4 on SM10 + * // max_sm_occupancy <-- 8 on SM20 + * // max_sm_occupancy <-- 12 on SM35 + * + * \endcode + * + */ +template +CUB_RUNTIME_FUNCTION inline +cudaError_t MaxSmOccupancy( + int& max_sm_occupancy, ///< [out] maximum number of thread blocks that can reside on a single SM + KernelPtr kernel_ptr, ///< [in] Kernel pointer for which to compute SM occupancy + int block_threads, ///< [in] Number of threads per thread block + int dynamic_smem_bytes = 0) ///< [in] Dynamically allocated shared memory in bytes. Default is 0. +{ + return CubDebug(cudaOccupancyMaxActiveBlocksPerMultiprocessor( + &max_sm_occupancy, + kernel_ptr, + block_threads, + dynamic_smem_bytes)); +} + + +/****************************************************************************** + * Policy management + ******************************************************************************/ + +/** + * Kernel dispatch configuration + */ +struct KernelConfig +{ + int block_threads; + int items_per_thread; + int tile_size; + int sm_occupancy; + + CUB_RUNTIME_FUNCTION __forceinline__ + KernelConfig() : block_threads(0), items_per_thread(0), tile_size(0), sm_occupancy(0) {} + + template + CUB_RUNTIME_FUNCTION __forceinline__ + cudaError_t Init(KernelPtrT kernel_ptr) + { + block_threads = AgentPolicyT::BLOCK_THREADS; + items_per_thread = AgentPolicyT::ITEMS_PER_THREAD; + tile_size = block_threads * items_per_thread; + cudaError_t retval = MaxSmOccupancy(sm_occupancy, kernel_ptr, block_threads); + return retval; + } +}; + + + +/// Helper for dispatching into a policy chain +template +struct ChainedPolicy +{ + /// The policy for the active compiler pass + using ActivePolicy = + cub::detail::conditional_t<(CUB_PTX_ARCH < PTX_VERSION), + typename PrevPolicyT::ActivePolicy, + PolicyT>; + + /// Specializes and dispatches op in accordance to the first policy in the chain of adequate PTX version + template + CUB_RUNTIME_FUNCTION __forceinline__ + static cudaError_t Invoke(int ptx_version, FunctorT& op) + { + if (ptx_version < PTX_VERSION) { + return PrevPolicyT::Invoke(ptx_version, op); + } + return op.template Invoke(); + } +}; + +/// Helper for dispatching into a policy chain (end-of-chain specialization) +template +struct ChainedPolicy +{ + /// The policy for the active compiler pass + typedef PolicyT ActivePolicy; + + /// Specializes and dispatches op in accordance to the first policy in the chain of adequate PTX version + template + CUB_RUNTIME_FUNCTION __forceinline__ + static cudaError_t Invoke(int /*ptx_version*/, FunctorT& op) { + return op.template Invoke(); + } +}; + + + + +/** @} */ // end group UtilMgmt + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_macro.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_macro.cuh new file mode 100644 index 0000000000000000000000000000000000000000..c486aa439f672abe07d60ac9c6aff448ddfcb55f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_macro.cuh @@ -0,0 +1,118 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/****************************************************************************** + * Common C/C++ macro utilities + ******************************************************************************/ + +#pragma once + +#include + +#include "util_namespace.cuh" + +CUB_NAMESPACE_BEGIN + + +/** + * \addtogroup UtilModule + * @{ + */ + +#ifndef CUB_ALIGN + #if defined(_WIN32) || defined(_WIN64) + /// Align struct + #define CUB_ALIGN(bytes) __declspec(align(32)) + #else + /// Align struct + #define CUB_ALIGN(bytes) __attribute__((aligned(bytes))) + #endif +#endif + +#define CUB_PREVENT_MACRO_SUBSTITUTION + +template +constexpr __host__ __device__ auto min CUB_PREVENT_MACRO_SUBSTITUTION(T &&t, + U &&u) + -> decltype(t < u ? ::cuda::std::forward(t) : ::cuda::std::forward(u)) +{ + return t < u ? ::cuda::std::forward(t) : ::cuda::std::forward(u); +} + +template +constexpr __host__ __device__ auto max CUB_PREVENT_MACRO_SUBSTITUTION(T &&t, + U &&u) + -> decltype(t < u ? ::cuda::std::forward(u) : ::cuda::std::forward(t)) +{ + return t < u ? ::cuda::std::forward(u) : ::cuda::std::forward(t); +} + +#ifndef CUB_MAX + /// Select maximum(a, b) + #define CUB_MAX(a, b) (((b) > (a)) ? (b) : (a)) +#endif + +#ifndef CUB_MIN + /// Select minimum(a, b) + #define CUB_MIN(a, b) (((b) < (a)) ? (b) : (a)) +#endif + +#ifndef CUB_QUOTIENT_FLOOR + /// Quotient of x/y rounded down to nearest integer + #define CUB_QUOTIENT_FLOOR(x, y) ((x) / (y)) +#endif + +#ifndef CUB_QUOTIENT_CEILING + /// Quotient of x/y rounded up to nearest integer + #define CUB_QUOTIENT_CEILING(x, y) (((x) + (y) - 1) / (y)) +#endif + +#ifndef CUB_ROUND_UP_NEAREST + /// x rounded up to the nearest multiple of y + #define CUB_ROUND_UP_NEAREST(x, y) ((((x) + (y) - 1) / (y)) * y) +#endif + +#ifndef CUB_ROUND_DOWN_NEAREST + /// x rounded down to the nearest multiple of y + #define CUB_ROUND_DOWN_NEAREST(x, y) (((x) / (y)) * y) +#endif + + +#ifndef CUB_STATIC_ASSERT + #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + #define CUB_CAT_(a, b) a ## b + #define CUB_CAT(a, b) CUB_CAT_(a, b) + #endif // DOXYGEN_SHOULD_SKIP_THIS + + /// Static assert + #define CUB_STATIC_ASSERT(cond, msg) typedef int CUB_CAT(cub_static_assert, __LINE__)[(cond) ? 1 : -1] +#endif + +/** @} */ // end group UtilModule + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_math.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_math.cuh new file mode 100644 index 0000000000000000000000000000000000000000..d69fc2ee2d5976e85d7e3452c4b2f3426a80c445 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_math.cuh @@ -0,0 +1,123 @@ +/****************************************************************************** + * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + *AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Define helper math functions. + */ + +#pragma once + +#include + +#include "util_namespace.cuh" +#include "util_macro.cuh" + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +template +using is_integral_or_enum = + std::integral_constant::value || std::is_enum::value>; + +__host__ __device__ __forceinline__ constexpr std::size_t +VshmemSize(std::size_t max_shmem, + std::size_t shmem_per_block, + std::size_t num_blocks) +{ + return shmem_per_block > max_shmem ? shmem_per_block * num_blocks : 0; +} + +} + +/** + * Divide n by d, round up if any remainder, and return the result. + * + * Effectively performs `(n + d - 1) / d`, but is robust against the case where + * `(n + d - 1)` would overflow. + */ +template +__host__ __device__ __forceinline__ constexpr NumeratorT +DivideAndRoundUp(NumeratorT n, DenominatorT d) +{ + static_assert(cub::detail::is_integral_or_enum::value && + cub::detail::is_integral_or_enum::value, + "DivideAndRoundUp is only intended for integral types."); + + // Static cast to undo integral promotion. + return static_cast(n / d + (n % d != 0 ? 1 : 0)); +} + +constexpr __device__ __host__ int +Nominal4BItemsToItemsCombined(int nominal_4b_items_per_thread, int combined_bytes) +{ + return (cub::min)(nominal_4b_items_per_thread, + (cub::max)(1, + nominal_4b_items_per_thread * 8 / + combined_bytes)); +} + +template +constexpr __device__ __host__ int +Nominal4BItemsToItems(int nominal_4b_items_per_thread) +{ + return (cub::min)(nominal_4b_items_per_thread, + (cub::max)(1, + nominal_4b_items_per_thread * 4 / + static_cast(sizeof(T)))); +} + +template +constexpr __device__ __host__ int +Nominal8BItemsToItems(int nominal_8b_items_per_thread) +{ + return sizeof(ItemT) <= 8u + ? nominal_8b_items_per_thread + : (cub::min)(nominal_8b_items_per_thread, + (cub::max)(1, + ((nominal_8b_items_per_thread * 8) + + static_cast(sizeof(ItemT)) - 1) / + static_cast(sizeof(ItemT)))); +} + +/** + * \brief Computes the midpoint of the integers + * + * Extra operation is performed in order to prevent overflow. + * + * \return Half the sum of \p begin and \p end + */ +template +constexpr __device__ __host__ T MidPoint(T begin, T end) +{ + return begin + (end - begin) / 2; +} + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_namespace.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_namespace.cuh new file mode 100644 index 0000000000000000000000000000000000000000..cc8e353767fc98690721e5aaea02e51234f99af0 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_namespace.cuh @@ -0,0 +1,216 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file util_namespace.cuh + * \brief Utilities that allow `cub::` to be placed inside an + * application-specific namespace. + */ + + +#pragma once + +// This is not used by this file; this is a hack so that we can detect the +// CUB version from Thrust on older versions of CUB that did not have +// version.cuh. +#include "version.cuh" + +// Prior to 1.13.1, only the PREFIX/POSTFIX macros were used. Notify users +// that they must now define the qualifier macro, too. +#if (defined(CUB_NS_PREFIX) || defined(CUB_NS_POSTFIX)) && !defined(CUB_NS_QUALIFIER) +#error CUB requires a definition of CUB_NS_QUALIFIER when CUB_NS_PREFIX/POSTFIX are defined. +#endif + +/** + * \def THRUST_CUB_WRAPPED_NAMESPACE + * If defined, this value will be used as the name of a namespace that wraps the + * `thrust::` and `cub::` namespaces. + * This macro should not be used with any other CUB namespace macros. + */ +#ifdef THRUST_CUB_WRAPPED_NAMESPACE +#define CUB_WRAPPED_NAMESPACE THRUST_CUB_WRAPPED_NAMESPACE +#endif + +/** + * \def CUB_WRAPPED_NAMESPACE + * If defined, this value will be used as the name of a namespace that wraps the + * `cub::` namespace. + * If THRUST_CUB_WRAPPED_NAMESPACE is set, this will inherit that macro's value. + * This macro should not be used with any other CUB namespace macros. + */ +#ifdef CUB_WRAPPED_NAMESPACE +#define CUB_NS_PREFIX \ + namespace CUB_WRAPPED_NAMESPACE \ + { + +#define CUB_NS_POSTFIX } + +#define CUB_NS_QUALIFIER ::CUB_WRAPPED_NAMESPACE::cub +#endif + +/** + * \def CUB_NS_PREFIX + * This macro is inserted prior to all `namespace cub { ... }` blocks. It is + * derived from CUB_WRAPPED_NAMESPACE, if set, and will be empty otherwise. + * It may be defined by users, in which case CUB_NS_PREFIX, + * CUB_NS_POSTFIX, and CUB_NS_QUALIFIER must all be set consistently. + */ +#ifndef CUB_NS_PREFIX +#define CUB_NS_PREFIX +#endif + +/** + * \def CUB_NS_POSTFIX + * This macro is inserted following the closing braces of all + * `namespace cub { ... }` block. It is defined appropriately when + * CUB_WRAPPED_NAMESPACE is set, and will be empty otherwise. It may be + * defined by users, in which case CUB_NS_PREFIX, CUB_NS_POSTFIX, and + * CUB_NS_QUALIFIER must all be set consistently. + */ +#ifndef CUB_NS_POSTFIX +#define CUB_NS_POSTFIX +#endif + +/** + * \def CUB_NS_QUALIFIER + * This macro is used to qualify members of cub:: when accessing them from + * outside of their namespace. By default, this is just `::cub`, and will be + * set appropriately when CUB_WRAPPED_NAMESPACE is defined. This macro may be + * defined by users, in which case CUB_NS_PREFIX, CUB_NS_POSTFIX, and + * CUB_NS_QUALIFIER must all be set consistently. + */ +#ifndef CUB_NS_QUALIFIER +#define CUB_NS_QUALIFIER ::cub +#endif + +#if !defined(CUB_DETAIL_MAGIC_NS_NAME) +#define CUB_DETAIL_COUNT_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, \ + _14, _15, _16, _17, _18, _19, _20, N, ...) \ + N +#define CUB_DETAIL_COUNT(...) \ + CUB_DETAIL_IDENTITY(CUB_DETAIL_COUNT_N(__VA_ARGS__, 20, 19, 18, 17, 16, 15, 14, 13, 12, \ + 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)) +#define CUB_DETAIL_IDENTITY(N) N +#define CUB_DETAIL_APPLY(MACRO, ...) CUB_DETAIL_IDENTITY(MACRO(__VA_ARGS__)) +#define CUB_DETAIL_MAGIC_NS_NAME1(P1) \ + CUB_##P1##_NS +#define CUB_DETAIL_MAGIC_NS_NAME2(P1, P2) \ + CUB_##P1##_##P2##_NS +#define CUB_DETAIL_MAGIC_NS_NAME3(P1, P2, P3) \ + CUB_##P1##_##P2##_##P3##_NS +#define CUB_DETAIL_MAGIC_NS_NAME4(P1, P2, P3, P4) \ + CUB_##P1##_##P2##_##P3##_##P4##_NS +#define CUB_DETAIL_MAGIC_NS_NAME5(P1, P2, P3, P4, P5) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_NS +#define CUB_DETAIL_MAGIC_NS_NAME6(P1, P2, P3, P4, P5, P6) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_NS +#define CUB_DETAIL_MAGIC_NS_NAME7(P1, P2, P3, P4, P5, P6, P7) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_NS +#define CUB_DETAIL_MAGIC_NS_NAME8(P1, P2, P3, P4, P5, P6, P7, P8) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_NS +#define CUB_DETAIL_MAGIC_NS_NAME9(P1, P2, P3, P4, P5, P6, P7, P8, P9) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_NS +#define CUB_DETAIL_MAGIC_NS_NAME10(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_NS +#define CUB_DETAIL_MAGIC_NS_NAME11(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_NS +#define CUB_DETAIL_MAGIC_NS_NAME12(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_NS +#define CUB_DETAIL_MAGIC_NS_NAME13(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_NS +#define CUB_DETAIL_MAGIC_NS_NAME14(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_NS +#define CUB_DETAIL_MAGIC_NS_NAME15(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_NS +#define CUB_DETAIL_MAGIC_NS_NAME16(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_##P16##_NS +#define CUB_DETAIL_MAGIC_NS_NAME17(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_##P16##_##P17##_NS +#define CUB_DETAIL_MAGIC_NS_NAME18(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_##P16##_##P17##_##P18##_NS +#define CUB_DETAIL_MAGIC_NS_NAME19(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_##P16##_##P17##_##P18##_##P19##_NS +#define CUB_DETAIL_MAGIC_NS_NAME20(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20) \ + CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_##P16##_##P17##_##P18##_##P19##_##P20##_NS +#define CUB_DETAIL_DISPATCH(N) CUB_DETAIL_MAGIC_NS_NAME ## N +#define CUB_DETAIL_MAGIC_NS_NAME(...) CUB_DETAIL_IDENTITY(CUB_DETAIL_APPLY(CUB_DETAIL_DISPATCH, CUB_DETAIL_COUNT(__VA_ARGS__))(__VA_ARGS__)) +#endif // !defined(CUB_DETAIL_MAGIC_NS_NAME) + +#if defined(CUB_DISABLE_NAMESPACE_MAGIC) +#if !defined(CUB_WRAPPED_NAMESPACE) +#if !defined(CUB_IGNORE_NAMESPACE_MAGIC_ERROR) +#error "Disabling namespace magic is unsafe without wrapping namespace" +#endif // !defined(CUB_IGNORE_NAMESPACE_MAGIC_ERROR) +#endif // !defined(CUB_WRAPPED_NAMESPACE) +#define CUB_DETAIL_MAGIC_NS_BEGIN +#define CUB_DETAIL_MAGIC_NS_END +#else // not defined(CUB_DISABLE_NAMESPACE_MAGIC) +#if defined(_NVHPC_CUDA) +#define CUB_DETAIL_MAGIC_NS_BEGIN inline namespace CUB_DETAIL_MAGIC_NS_NAME(CUB_VERSION, NV_TARGET_SM_INTEGER_LIST) { +#define CUB_DETAIL_MAGIC_NS_END } +#else // not defined(_NVHPC_CUDA) +#define CUB_DETAIL_MAGIC_NS_BEGIN inline namespace CUB_DETAIL_MAGIC_NS_NAME(CUB_VERSION, __CUDA_ARCH_LIST__) { +#define CUB_DETAIL_MAGIC_NS_END } +#endif // not defined(_NVHPC_CUDA) +#endif // not defined(CUB_DISABLE_NAMESPACE_MAGIC) + +/** + * \def CUB_NAMESPACE_BEGIN + * This macro is used to open a `cub::` namespace block, along with any + * enclosing namespaces requested by CUB_WRAPPED_NAMESPACE, etc. + * This macro is defined by CUB and may not be overridden. + */ +#define CUB_NAMESPACE_BEGIN \ + CUB_NS_PREFIX \ + namespace cub \ + { \ + CUB_DETAIL_MAGIC_NS_BEGIN + +/** + * \def CUB_NAMESPACE_END + * This macro is used to close a `cub::` namespace block, along with any + * enclosing namespaces requested by CUB_WRAPPED_NAMESPACE, etc. + * This macro is defined by CUB and may not be overridden. + */ +#define CUB_NAMESPACE_END \ + CUB_DETAIL_MAGIC_NS_END \ + } /* end namespace cub */ \ + CUB_NS_POSTFIX + +// Declare these namespaces here for the purpose of Doxygenating them +CUB_NS_PREFIX + +/*! \namespace cub + * \brief \p cub is the top-level namespace which contains all CUB + * functions and types. + */ +namespace cub +{ +} + +CUB_NS_POSTFIX diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_ptx.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_ptx.cuh new file mode 100644 index 0000000000000000000000000000000000000000..0fb9b35735008cb4b6ed97a7e24a591a4231e239 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_ptx.cuh @@ -0,0 +1,806 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * PTX intrinsics + */ + + +#pragma once + +#include "util_type.cuh" +#include "util_arch.cuh" +#include "util_namespace.cuh" +#include "util_debug.cuh" + + +CUB_NAMESPACE_BEGIN + + +/** + * \addtogroup UtilPtx + * @{ + */ + + +/****************************************************************************** + * PTX helper macros + ******************************************************************************/ + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + +/** + * Register modifier for pointer-types (for inlining PTX assembly) + */ +#if defined(_WIN64) || defined(__LP64__) + #define __CUB_LP64__ 1 + // 64-bit register modifier for inlined asm + #define _CUB_ASM_PTR_ "l" + #define _CUB_ASM_PTR_SIZE_ "u64" +#else + #define __CUB_LP64__ 0 + // 32-bit register modifier for inlined asm + #define _CUB_ASM_PTR_ "r" + #define _CUB_ASM_PTR_SIZE_ "u32" +#endif + +#endif // DOXYGEN_SHOULD_SKIP_THIS + + +/****************************************************************************** + * Inlined PTX intrinsics + ******************************************************************************/ + +namespace detail +{ +/** + * @brief Shifts @p val left by the amount specified by unsigned 32-bit value in @p num_bits. If @p + * num_bits is larger than 32 bits, @p num_bits is clamped to 32. + */ +__device__ __forceinline__ uint32_t LogicShiftLeft(uint32_t val, uint32_t num_bits) +{ + uint32_t ret{}; + asm("shl.b32 %0, %1, %2;" : "=r"(ret) : "r"(val), "r"(num_bits)); + return ret; +} + +/** + * @brief Shifts @p val right by the amount specified by unsigned 32-bit value in @p num_bits. If @p + * num_bits is larger than 32 bits, @p num_bits is clamped to 32. + */ +__device__ __forceinline__ uint32_t LogicShiftRight(uint32_t val, uint32_t num_bits) +{ + uint32_t ret{}; + asm("shr.b32 %0, %1, %2;" : "=r"(ret) : "r"(val), "r"(num_bits)); + return ret; +} +} // namespace detail + +/** + * \brief Shift-right then add. Returns (\p x >> \p shift) + \p addend. + */ +__device__ __forceinline__ unsigned int SHR_ADD( + unsigned int x, + unsigned int shift, + unsigned int addend) +{ + unsigned int ret; + asm ("vshr.u32.u32.u32.clamp.add %0, %1, %2, %3;" : + "=r"(ret) : "r"(x), "r"(shift), "r"(addend)); + return ret; +} + + +/** + * \brief Shift-left then add. Returns (\p x << \p shift) + \p addend. + */ +__device__ __forceinline__ unsigned int SHL_ADD( + unsigned int x, + unsigned int shift, + unsigned int addend) +{ + unsigned int ret; + asm ("vshl.u32.u32.u32.clamp.add %0, %1, %2, %3;" : + "=r"(ret) : "r"(x), "r"(shift), "r"(addend)); + return ret; +} + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + +/** + * Bitfield-extract. + */ +template +__device__ __forceinline__ unsigned int BFE( + UnsignedBits source, + unsigned int bit_start, + unsigned int num_bits, + Int2Type /*byte_len*/) +{ + unsigned int bits; + asm ("bfe.u32 %0, %1, %2, %3;" : "=r"(bits) : "r"((unsigned int) source), "r"(bit_start), "r"(num_bits)); + return bits; +} + + +/** + * Bitfield-extract for 64-bit types. + */ +template +__device__ __forceinline__ unsigned int BFE( + UnsignedBits source, + unsigned int bit_start, + unsigned int num_bits, + Int2Type<8> /*byte_len*/) +{ + const unsigned long long MASK = (1ull << num_bits) - 1; + return (source >> bit_start) & MASK; +} + +#if CUB_IS_INT128_ENABLED +/** + * Bitfield-extract for 128-bit types. + */ +template +__device__ __forceinline__ unsigned int BFE( + UnsignedBits source, + unsigned int bit_start, + unsigned int num_bits, + Int2Type<16> /*byte_len*/) +{ + const __uint128_t MASK = (__uint128_t{1} << num_bits) - 1; + return (source >> bit_start) & MASK; +} +#endif + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +/** + * \brief Bitfield-extract. Extracts \p num_bits from \p source starting at bit-offset \p bit_start. The input \p source may be an 8b, 16b, 32b, or 64b unsigned integer type. + */ +template +__device__ __forceinline__ unsigned int BFE( + UnsignedBits source, + unsigned int bit_start, + unsigned int num_bits) +{ + return BFE(source, bit_start, num_bits, Int2Type()); +} + + +/** + * \brief Bitfield insert. Inserts the \p num_bits least significant bits of \p y into \p x at bit-offset \p bit_start. + */ +__device__ __forceinline__ void BFI( + unsigned int &ret, + unsigned int x, + unsigned int y, + unsigned int bit_start, + unsigned int num_bits) +{ + asm ("bfi.b32 %0, %1, %2, %3, %4;" : + "=r"(ret) : "r"(y), "r"(x), "r"(bit_start), "r"(num_bits)); +} + + +/** + * \brief Three-operand add. Returns \p x + \p y + \p z. + */ +__device__ __forceinline__ unsigned int IADD3(unsigned int x, unsigned int y, unsigned int z) +{ + asm ("vadd.u32.u32.u32.add %0, %1, %2, %3;" : "=r"(x) : "r"(x), "r"(y), "r"(z)); + return x; +} + + +/** + * \brief Byte-permute. Pick four arbitrary bytes from two 32-bit registers, and reassemble them into a 32-bit destination register. For SM2.0 or later. + * + * \par + * The bytes in the two source registers \p a and \p b are numbered from 0 to 7: + * {\p b, \p a} = {{b7, b6, b5, b4}, {b3, b2, b1, b0}}. For each of the four bytes + * {b3, b2, b1, b0} selected in the return value, a 4-bit selector is defined within + * the four lower "nibbles" of \p index: {\p index } = {n7, n6, n5, n4, n3, n2, n1, n0} + * + * \par Snippet + * The code snippet below illustrates byte-permute. + * \par + * \code + * #include + * + * __global__ void ExampleKernel(...) + * { + * int a = 0x03020100; + * int b = 0x07060504; + * int index = 0x00007531; + * + * int selected = PRMT(a, b, index); // 0x07050301 + * + * \endcode + * + */ +__device__ __forceinline__ int PRMT(unsigned int a, unsigned int b, unsigned int index) +{ + int ret; + asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(ret) : "r"(a), "r"(b), "r"(index)); + return ret; +} + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + +/** + * Sync-threads barrier. + */ +__device__ __forceinline__ void BAR(int count) +{ + asm volatile("bar.sync 1, %0;" : : "r"(count)); +} + +/** + * CTA barrier + */ +__device__ __forceinline__ void CTA_SYNC() +{ + __syncthreads(); +} + + +/** + * CTA barrier with predicate + */ +__device__ __forceinline__ int CTA_SYNC_AND(int p) +{ + return __syncthreads_and(p); +} + + +/** + * CTA barrier with predicate + */ +__device__ __forceinline__ int CTA_SYNC_OR(int p) +{ + return __syncthreads_or(p); +} + + +/** + * Warp barrier + */ +__device__ __forceinline__ void WARP_SYNC(unsigned int member_mask) +{ + __syncwarp(member_mask); +} + + +/** + * Warp any + */ +__device__ __forceinline__ int WARP_ANY(int predicate, unsigned int member_mask) +{ + return __any_sync(member_mask, predicate); +} + + +/** + * Warp any + */ +__device__ __forceinline__ int WARP_ALL(int predicate, unsigned int member_mask) +{ + return __all_sync(member_mask, predicate); +} + + +/** + * Warp ballot + */ +__device__ __forceinline__ int WARP_BALLOT(int predicate, unsigned int member_mask) +{ + return __ballot_sync(member_mask, predicate); +} + + +/** + * Warp synchronous shfl_up + */ +__device__ __forceinline__ +unsigned int SHFL_UP_SYNC(unsigned int word, int src_offset, int flags, unsigned int member_mask) +{ + asm volatile("shfl.sync.up.b32 %0, %1, %2, %3, %4;" + : "=r"(word) : "r"(word), "r"(src_offset), "r"(flags), "r"(member_mask)); + return word; +} + +/** + * Warp synchronous shfl_down + */ +__device__ __forceinline__ +unsigned int SHFL_DOWN_SYNC(unsigned int word, int src_offset, int flags, unsigned int member_mask) +{ + asm volatile("shfl.sync.down.b32 %0, %1, %2, %3, %4;" + : "=r"(word) : "r"(word), "r"(src_offset), "r"(flags), "r"(member_mask)); + return word; +} + +/** + * Warp synchronous shfl_idx + */ +__device__ __forceinline__ +unsigned int SHFL_IDX_SYNC(unsigned int word, int src_lane, int flags, unsigned int member_mask) +{ + asm volatile("shfl.sync.idx.b32 %0, %1, %2, %3, %4;" + : "=r"(word) : "r"(word), "r"(src_lane), "r"(flags), "r"(member_mask)); + return word; +} + +/** + * Warp synchronous shfl_idx + */ +__device__ __forceinline__ +unsigned int SHFL_IDX_SYNC(unsigned int word, int src_lane, unsigned int member_mask) +{ + return __shfl_sync(member_mask, word, src_lane); +} + +/** + * Floating point multiply. (Mantissa LSB rounds towards zero.) + */ +__device__ __forceinline__ float FMUL_RZ(float a, float b) +{ + float d; + asm ("mul.rz.f32 %0, %1, %2;" : "=f"(d) : "f"(a), "f"(b)); + return d; +} + + +/** + * Floating point multiply-add. (Mantissa LSB rounds towards zero.) + */ +__device__ __forceinline__ float FFMA_RZ(float a, float b, float c) +{ + float d; + asm ("fma.rz.f32 %0, %1, %2, %3;" : "=f"(d) : "f"(a), "f"(b), "f"(c)); + return d; +} + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +/** + * \brief Terminates the calling thread + */ +__device__ __forceinline__ void ThreadExit() { + asm volatile("exit;"); +} + + +/** + * \brief Abort execution and generate an interrupt to the host CPU + */ +__device__ __forceinline__ void ThreadTrap() { + asm volatile("trap;"); +} + + +/** + * \brief Returns the row-major linear thread identifier for a multidimensional thread block + */ +__device__ __forceinline__ int RowMajorTid(int block_dim_x, int block_dim_y, int block_dim_z) +{ + return ((block_dim_z == 1) ? 0 : (threadIdx.z * block_dim_x * block_dim_y)) + + ((block_dim_y == 1) ? 0 : (threadIdx.y * block_dim_x)) + + threadIdx.x; +} + + +/** + * \brief Returns the warp lane ID of the calling thread + */ +__device__ __forceinline__ unsigned int LaneId() +{ + unsigned int ret; + asm ("mov.u32 %0, %%laneid;" : "=r"(ret) ); + return ret; +} + + +/** + * \brief Returns the warp ID of the calling thread. Warp ID is guaranteed to be unique among warps, but may not correspond to a zero-based ranking within the thread block. + */ +__device__ __forceinline__ unsigned int WarpId() +{ + unsigned int ret; + asm ("mov.u32 %0, %%warpid;" : "=r"(ret) ); + return ret; +} + +/** + * @brief Returns the warp mask for a warp of @p LOGICAL_WARP_THREADS threads + * + * @par + * If the number of threads assigned to the virtual warp is not a power of two, + * it's assumed that only one virtual warp exists. + * + * @tparam LOGICAL_WARP_THREADS [optional] The number of threads per + * "logical" warp (may be less than the number of + * hardware warp threads). + * @param warp_id Id of virtual warp within architectural warp + */ +template +__host__ __device__ __forceinline__ +unsigned int WarpMask(unsigned int warp_id) +{ + constexpr bool is_pow_of_two = PowerOfTwo::VALUE; + constexpr bool is_arch_warp = LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0); + + unsigned int member_mask = 0xFFFFFFFFu >> + (CUB_WARP_THREADS(0) - LOGICAL_WARP_THREADS); + + if (is_pow_of_two && !is_arch_warp) + { + member_mask <<= warp_id * LOGICAL_WARP_THREADS; + } + + return member_mask; +} + +/** + * \brief Returns the warp lane mask of all lanes less than the calling thread + */ +__device__ __forceinline__ unsigned int LaneMaskLt() +{ + unsigned int ret; + asm ("mov.u32 %0, %%lanemask_lt;" : "=r"(ret) ); + return ret; +} + +/** + * \brief Returns the warp lane mask of all lanes less than or equal to the calling thread + */ +__device__ __forceinline__ unsigned int LaneMaskLe() +{ + unsigned int ret; + asm ("mov.u32 %0, %%lanemask_le;" : "=r"(ret) ); + return ret; +} + +/** + * \brief Returns the warp lane mask of all lanes greater than the calling thread + */ +__device__ __forceinline__ unsigned int LaneMaskGt() +{ + unsigned int ret; + asm ("mov.u32 %0, %%lanemask_gt;" : "=r"(ret) ); + return ret; +} + +/** + * \brief Returns the warp lane mask of all lanes greater than or equal to the calling thread + */ +__device__ __forceinline__ unsigned int LaneMaskGe() +{ + unsigned int ret; + asm ("mov.u32 %0, %%lanemask_ge;" : "=r"(ret) ); + return ret; +} + +/** @} */ // end group UtilPtx + + + + +/** + * \brief Shuffle-up for any data type. Each warp-lanei obtains the value \p input contributed by warp-lanei-src_offset. For thread lanes \e i < src_offset, the thread's own \p input is returned to the thread. ![](shfl_up_logo.png) + * \ingroup WarpModule + * + * \tparam LOGICAL_WARP_THREADS The number of threads per "logical" warp. Must be a power-of-two <= 32. + * \tparam T [inferred] The input/output element type + * + * \par + * - Available only for SM3.0 or newer + * + * \par Snippet + * The code snippet below illustrates each thread obtaining a \p double value from the + * predecessor of its predecessor. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Obtain one input item per thread + * double thread_data = ... + * + * // Obtain item from two ranks below + * double peer_data = ShuffleUp<32>(thread_data, 2, 0, 0xffffffff); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the first warp of threads is {1.0, 2.0, 3.0, 4.0, 5.0, ..., 32.0}. + * The corresponding output \p peer_data will be {1.0, 2.0, 1.0, 2.0, 3.0, ..., 30.0}. + * + */ +template < + int LOGICAL_WARP_THREADS, ///< Number of threads per logical warp + typename T> +__device__ __forceinline__ T ShuffleUp( + T input, ///< [in] The value to broadcast + int src_offset, ///< [in] The relative down-offset of the peer to read from + int first_thread, ///< [in] Index of first lane in logical warp (typically 0) + unsigned int member_mask) ///< [in] 32-bit mask of participating warp lanes +{ + /// The 5-bit SHFL mask for logically splitting warps into sub-segments starts 8-bits up + enum { + SHFL_C = (32 - LOGICAL_WARP_THREADS) << 8 + }; + + typedef typename UnitWord::ShuffleWord ShuffleWord; + + const int WORDS = (sizeof(T) + sizeof(ShuffleWord) - 1) / sizeof(ShuffleWord); + + T output; + ShuffleWord *output_alias = reinterpret_cast(&output); + ShuffleWord *input_alias = reinterpret_cast(&input); + + unsigned int shuffle_word; + shuffle_word = SHFL_UP_SYNC((unsigned int)input_alias[0], src_offset, first_thread | SHFL_C, member_mask); + output_alias[0] = shuffle_word; + + #pragma unroll + for (int WORD = 1; WORD < WORDS; ++WORD) + { + shuffle_word = SHFL_UP_SYNC((unsigned int)input_alias[WORD], src_offset, first_thread | SHFL_C, member_mask); + output_alias[WORD] = shuffle_word; + } + + return output; +} + + +/** + * \brief Shuffle-down for any data type. Each warp-lanei obtains the value \p input contributed by warp-lanei+src_offset. For thread lanes \e i >= WARP_THREADS, the thread's own \p input is returned to the thread. ![](shfl_down_logo.png) + * \ingroup WarpModule + * + * \tparam LOGICAL_WARP_THREADS The number of threads per "logical" warp. Must be a power-of-two <= 32. + * \tparam T [inferred] The input/output element type + * + * \par + * - Available only for SM3.0 or newer + * + * \par Snippet + * The code snippet below illustrates each thread obtaining a \p double value from the + * successor of its successor. + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Obtain one input item per thread + * double thread_data = ... + * + * // Obtain item from two ranks below + * double peer_data = ShuffleDown<32>(thread_data, 2, 31, 0xffffffff); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the first warp of threads is {1.0, 2.0, 3.0, 4.0, 5.0, ..., 32.0}. + * The corresponding output \p peer_data will be {3.0, 4.0, 5.0, 6.0, 7.0, ..., 32.0}. + * + */ +template < + int LOGICAL_WARP_THREADS, ///< Number of threads per logical warp + typename T> +__device__ __forceinline__ T ShuffleDown( + T input, ///< [in] The value to broadcast + int src_offset, ///< [in] The relative up-offset of the peer to read from + int last_thread, ///< [in] Index of last thread in logical warp (typically 31 for a 32-thread warp) + unsigned int member_mask) ///< [in] 32-bit mask of participating warp lanes +{ + /// The 5-bit SHFL mask for logically splitting warps into sub-segments starts 8-bits up + enum { + SHFL_C = (32 - LOGICAL_WARP_THREADS) << 8 + }; + + typedef typename UnitWord::ShuffleWord ShuffleWord; + + const int WORDS = (sizeof(T) + sizeof(ShuffleWord) - 1) / sizeof(ShuffleWord); + + T output; + ShuffleWord *output_alias = reinterpret_cast(&output); + ShuffleWord *input_alias = reinterpret_cast(&input); + + unsigned int shuffle_word; + shuffle_word = SHFL_DOWN_SYNC((unsigned int)input_alias[0], src_offset, last_thread | SHFL_C, member_mask); + output_alias[0] = shuffle_word; + + #pragma unroll + for (int WORD = 1; WORD < WORDS; ++WORD) + { + shuffle_word = SHFL_DOWN_SYNC((unsigned int)input_alias[WORD], src_offset, last_thread | SHFL_C, member_mask); + output_alias[WORD] = shuffle_word; + } + + return output; +} + + +/** + * \brief Shuffle-broadcast for any data type. Each warp-lanei obtains the value \p input + * contributed by warp-lanesrc_lane. For \p src_lane < 0 or \p src_lane >= WARP_THREADS, + * then the thread's own \p input is returned to the thread. ![](shfl_broadcast_logo.png) + * + * \tparam LOGICAL_WARP_THREADS The number of threads per "logical" warp. Must be a power-of-two <= 32. + * \tparam T [inferred] The input/output element type + * + * \ingroup WarpModule + * + * \par + * - Available only for SM3.0 or newer + * + * \par Snippet + * The code snippet below illustrates each thread obtaining a \p double value from warp-lane0. + * + * \par + * \code + * #include // or equivalently + * + * __global__ void ExampleKernel(...) + * { + * // Obtain one input item per thread + * double thread_data = ... + * + * // Obtain item from thread 0 + * double peer_data = ShuffleIndex<32>(thread_data, 0, 0xffffffff); + * + * \endcode + * \par + * Suppose the set of input \p thread_data across the first warp of threads is {1.0, 2.0, 3.0, 4.0, 5.0, ..., 32.0}. + * The corresponding output \p peer_data will be {1.0, 1.0, 1.0, 1.0, 1.0, ..., 1.0}. + * + */ +template < + int LOGICAL_WARP_THREADS, ///< Number of threads per logical warp + typename T> +__device__ __forceinline__ T ShuffleIndex( + T input, ///< [in] The value to broadcast + int src_lane, ///< [in] Which warp lane is to do the broadcasting + unsigned int member_mask) ///< [in] 32-bit mask of participating warp lanes +{ + /// The 5-bit SHFL mask for logically splitting warps into sub-segments starts 8-bits up + enum { + SHFL_C = ((32 - LOGICAL_WARP_THREADS) << 8) | (LOGICAL_WARP_THREADS - 1) + }; + + typedef typename UnitWord::ShuffleWord ShuffleWord; + + const int WORDS = (sizeof(T) + sizeof(ShuffleWord) - 1) / sizeof(ShuffleWord); + + T output; + ShuffleWord *output_alias = reinterpret_cast(&output); + ShuffleWord *input_alias = reinterpret_cast(&input); + + unsigned int shuffle_word; + shuffle_word = SHFL_IDX_SYNC((unsigned int)input_alias[0], + src_lane, + SHFL_C, + member_mask); + + output_alias[0] = shuffle_word; + + #pragma unroll + for (int WORD = 1; WORD < WORDS; ++WORD) + { + shuffle_word = SHFL_IDX_SYNC((unsigned int)input_alias[WORD], + src_lane, + SHFL_C, + member_mask); + + output_alias[WORD] = shuffle_word; + } + + return output; +} + + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document +namespace detail +{ + +/** + * Implementation detail for `MatchAny`. It provides specializations for full and partial warps. + * For partial warps, inactive threads must be masked out. This is done in the partial warp + * specialization below. + * Usage: + * ``` + * // returns a mask of threads with the same 4 least-significant bits of `label` + * // in a warp with 16 active threads + * warp_matcher_t<4, 16>::match_any(label); + * + * // returns a mask of threads with the same 4 least-significant bits of `label` + * // in a warp with 32 active threads (no extra work is done) + * warp_matcher_t<4, 32>::match_any(label); + * ``` + */ +template +struct warp_matcher_t +{ + + static __device__ unsigned int match_any(unsigned int label) + { + return warp_matcher_t::match_any(label) & ~(~0 << WARP_ACTIVE_THREADS); + } + +}; + +template +struct warp_matcher_t +{ + + // match.any.sync.b32 is slower when matching a few bits + // using a ballot loop instead + static __device__ unsigned int match_any(unsigned int label) + { + unsigned int retval; + + // Extract masks of common threads for each bit + #pragma unroll + for (int BIT = 0; BIT < LABEL_BITS; ++BIT) + { + unsigned int mask; + unsigned int current_bit = 1 << BIT; + asm ("{\n" + " .reg .pred p;\n" + " and.b32 %0, %1, %2;" + " setp.eq.u32 p, %0, %2;\n" + " vote.ballot.sync.b32 %0, p, 0xffffffff;\n" + " @!p not.b32 %0, %0;\n" + "}\n" : "=r"(mask) : "r"(label), "r"(current_bit)); + + // Remove peers who differ + retval = (BIT == 0) ? mask : retval & mask; + } + + return retval; + } + +}; + +} // namespace detail +#endif // DOXYGEN_SHOULD_SKIP_THIS + +/** + * Compute a 32b mask of threads having the same least-significant + * LABEL_BITS of \p label as the calling thread. + */ +template +inline __device__ unsigned int MatchAny(unsigned int label) +{ + return detail::warp_matcher_t::match_any(label); +} + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_type.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_type.cuh new file mode 100644 index 0000000000000000000000000000000000000000..d0fa9c9c608e6f0b56bfaf8396fa9ebeb1e22766 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/util_type.cuh @@ -0,0 +1,1320 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * Common type manipulation (metaprogramming) utilities + */ + +#pragma once + +#include +#include +#include +#include + +#include + +#if !_NVHPC_CUDA + #include +#endif +#if !_NVHPC_CUDA && !defined(CUB_DISABLE_BF16_SUPPORT) + #include +#endif + +#include +#include +#include +#include +#include +#include + +#include + +CUB_NAMESPACE_BEGIN + +#ifndef CUB_IS_INT128_ENABLED +#if defined(__CUDACC_RTC__) +#if defined(__CUDACC_RTC_INT128__) +#define CUB_IS_INT128_ENABLED 1 +#endif // !defined(__CUDACC_RTC_INT128__) +#else // !defined(__CUDACC_RTC__) +#if CUDA_VERSION >= 11050 +#if (CUB_HOST_COMPILER == CUB_HOST_COMPILER_GCC) || \ + (CUB_HOST_COMPILER == CUB_HOST_COMPILER_CLANG) || \ + defined(__ICC) || defined(_NVHPC_CUDA) +#define CUB_IS_INT128_ENABLED 1 +#endif // GCC || CLANG || ICC || NVHPC +#endif // CTK >= 11.5 +#endif // !defined(__CUDACC_RTC__) +#endif // !defined(CUB_IS_INT128_ENABLED) + +/** + * \addtogroup UtilModule + * @{ + */ + + + +/****************************************************************************** + * Conditional types + ******************************************************************************/ + + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document +namespace detail +{ + + +template +using conditional_t = typename std::conditional::type; + + +template +using value_t = typename std::iterator_traits::value_type; + +template ::type>::type, + void>::value> +struct non_void_value_impl +{ + using type = FallbackT; +}; + +template +struct non_void_value_impl +{ + using type = typename ::cuda::std::conditional< + ::cuda::std::is_same::value_type, void>::value, + FallbackT, + typename std::iterator_traits::value_type>::type; +}; + +/** + * The output value type + * type = (if IteratorT's value type is void) ? + * ... then the FallbackT, + * ... else the IteratorT's value type + */ +template +using non_void_value_t = typename non_void_value_impl::type; +} // namespace detail + + +/** + * \brief Type selection (IF ? ThenType : ElseType) + * + * \deprecated [Since 1.16.0] The cub::If APIs are deprecated. + * Use cub::detail::conditional_t instead. + */ +template +struct CUB_DEPRECATED If +{ + using Type = cub::detail::conditional_t; +}; + + +/****************************************************************************** + * Type equality + ******************************************************************************/ + +/** + * \brief Type equality test + * + * \deprecated [Since 1.16.0] The cub::Equals APIs are deprecated. + * Use std::is_same instead. + */ +template +struct CUB_DEPRECATED Equals +{ + static constexpr int VALUE = std::is_same::value ? 1 : 0; + static constexpr int NEGATE = VALUE ? 0 : 1; +}; + + +/****************************************************************************** + * Static math + ******************************************************************************/ + +/** + * \brief Statically determine log2(N), rounded up. + * + * For example: + * Log2<8>::VALUE // 3 + * Log2<3>::VALUE // 2 + */ +template +struct Log2 +{ + /// Static logarithm value + enum { VALUE = Log2> 1), COUNT + 1>::VALUE }; // Inductive case +}; + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + +template +struct Log2 +{ + enum {VALUE = (1 << (COUNT - 1) < N) ? // Base case + COUNT : + COUNT - 1 }; +}; + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +/** + * \brief Statically determine if N is a power-of-two + */ +template +struct PowerOfTwo +{ + enum { VALUE = ((N & (N - 1)) == 0) }; +}; + + + +/****************************************************************************** + * Pointer vs. iterator detection + ******************************************************************************/ + +/** + * \brief Pointer vs. iterator + * + * \deprecated [Since 1.16.0] The cub::IsPointer APIs are deprecated. + * Use std::is_pointer instead. + */ +template +struct CUB_DEPRECATED IsPointer +{ + static constexpr int VALUE = std::is_pointer::value; +}; + + +/****************************************************************************** + * Qualifier detection + ******************************************************************************/ + +/** + * \brief Volatile modifier test + * + * \deprecated [Since 1.16.0] The cub::IsVolatile APIs are deprecated. + * Use std::is_volatile instead. + */ +template +struct CUB_DEPRECATED IsVolatile +{ + static constexpr int VALUE = std::is_volatile::value; +}; + +/****************************************************************************** + * Qualifier removal + ******************************************************************************/ + +/** + * \brief Removes \p const and \p volatile qualifiers from type \p Tp. + * + * \deprecated [Since 1.16.0] The cub::RemoveQualifiers APIs are deprecated. + * Use std::remove_cv instead. + * + * For example: + * typename RemoveQualifiers::Type // int; + */ +template +struct CUB_DEPRECATED RemoveQualifiers +{ + using Type = typename std::remove_cv::type; +}; +#endif // DOXYGEN_SHOULD_SKIP_THIS + + +/****************************************************************************** + * Marker types + ******************************************************************************/ + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + +/** + * \brief A simple "NULL" marker type + */ +struct NullType +{ + using value_type = NullType; + + template + __host__ __device__ __forceinline__ NullType& operator =(const T&) { return *this; } + + __host__ __device__ __forceinline__ bool operator ==(const NullType&) { return true; } + + __host__ __device__ __forceinline__ bool operator !=(const NullType&) { return false; } +}; + + +/** + * \brief Allows for the treatment of an integral constant as a type at compile-time (e.g., to achieve static call dispatch based on constant integral values) + */ +template +struct Int2Type +{ + enum {VALUE = A}; +}; + +/** + * \brief Allows algorithms that take a value as input to take a future value that is not computed yet at launch time. + * + * Note that it is user's responsibility to ensure that the result will be ready before use via external synchronization + * or stream-ordering dependencies. + * + * \code + * int *d_intermediate_result; + * allocator.DeviceAllocate((void **)&d_intermediate_result, sizeof(int)); + * compute_intermediate_result<<>>( + * d_intermediate_result, // output + * arg1, // input + * arg2); // input + * cub::FutureValue init_value(d_intermediate_result); + * cub::DeviceScan::ExclusiveScan( + * d_temp_storage, + * temp_storage_bytes, + * d_in, + * d_out, + * cub::Sum(), + * init_value, + * num_items); + * allocator.DeviceFree(d_intermediate_result); + * \endcode + */ +template +struct FutureValue +{ + using value_type = T; + using iterator_type = IterT; + explicit __host__ __device__ __forceinline__ FutureValue(IterT iter):m_iter(iter) {} + __host__ __device__ __forceinline__ operator T() { + return *m_iter; + } + +private: + IterT m_iter; +}; + +namespace detail { + +/** + * \brief Allows algorithms to instantiate a single kernel to support both immediate value and future value. + */ +template +struct InputValue +{ + using value_type = T; + using iterator_type = IterT; + __host__ __device__ __forceinline__ operator T() { + if (m_is_future) { + return m_future_value; + } + return m_immediate_value; + } + explicit __host__ __device__ __forceinline__ InputValue(T immediate_value): m_is_future(false), m_immediate_value(immediate_value) {} + explicit __host__ __device__ __forceinline__ InputValue(FutureValue future_value): m_is_future(true), m_future_value(future_value) {} + __host__ __device__ __forceinline__ InputValue(const InputValue &other): m_is_future(other.m_is_future) { + if (m_is_future) { + m_future_value = other.m_future_value; + } else { + detail::uninitialized_copy(&m_immediate_value, + other.m_immediate_value); + } + } + +private: + bool m_is_future; + union + { + FutureValue m_future_value; + T m_immediate_value; + }; +}; + +} // namespace detail + + +/****************************************************************************** + * Size and alignment + ******************************************************************************/ + +/// Structure alignment +template +struct AlignBytes +{ + struct Pad + { + T val; + char byte; + }; + + enum + { + /// The "true CUDA" alignment of T in bytes + ALIGN_BYTES = sizeof(Pad) - sizeof(T) + }; + + /// The "truly aligned" type + typedef T Type; +}; + +// Specializations where host C++ compilers (e.g., 32-bit Windows) may disagree +// with device C++ compilers (EDG) on types passed as template parameters through +// kernel functions + +#define __CUB_ALIGN_BYTES(t, b) \ + template <> struct AlignBytes \ + { enum { ALIGN_BYTES = b }; typedef __align__(b) t Type; }; + +__CUB_ALIGN_BYTES(short4, 8) +__CUB_ALIGN_BYTES(ushort4, 8) +__CUB_ALIGN_BYTES(int2, 8) +__CUB_ALIGN_BYTES(uint2, 8) +__CUB_ALIGN_BYTES(long long, 8) +__CUB_ALIGN_BYTES(unsigned long long, 8) +__CUB_ALIGN_BYTES(float2, 8) +__CUB_ALIGN_BYTES(double, 8) +#ifdef _WIN32 + __CUB_ALIGN_BYTES(long2, 8) + __CUB_ALIGN_BYTES(ulong2, 8) +#else + __CUB_ALIGN_BYTES(long2, 16) + __CUB_ALIGN_BYTES(ulong2, 16) +#endif +__CUB_ALIGN_BYTES(int4, 16) +__CUB_ALIGN_BYTES(uint4, 16) +__CUB_ALIGN_BYTES(float4, 16) +__CUB_ALIGN_BYTES(long4, 16) +__CUB_ALIGN_BYTES(ulong4, 16) +__CUB_ALIGN_BYTES(longlong2, 16) +__CUB_ALIGN_BYTES(ulonglong2, 16) +__CUB_ALIGN_BYTES(double2, 16) +__CUB_ALIGN_BYTES(longlong4, 16) +__CUB_ALIGN_BYTES(ulonglong4, 16) +__CUB_ALIGN_BYTES(double4, 16) + +// clang-format off +template struct AlignBytes : AlignBytes {}; +template struct AlignBytes : AlignBytes {}; +template struct AlignBytes : AlignBytes {}; +// clang-format on + +/// Unit-words of data movement +template +struct UnitWord +{ + enum { + ALIGN_BYTES = AlignBytes::ALIGN_BYTES + }; + + template + struct IsMultiple + { + enum { + UNIT_ALIGN_BYTES = AlignBytes::ALIGN_BYTES, + IS_MULTIPLE = (sizeof(T) % sizeof(Unit) == 0) && (int(ALIGN_BYTES) % int(UNIT_ALIGN_BYTES) == 0) + }; + }; + + /// Biggest shuffle word that T is a whole multiple of and is not larger than + /// the alignment of T + using ShuffleWord = cub::detail::conditional_t< + IsMultiple::IS_MULTIPLE, + unsigned int, + cub::detail::conditional_t::IS_MULTIPLE, + unsigned short, + unsigned char>>; + + /// Biggest volatile word that T is a whole multiple of and is not larger than + /// the alignment of T + using VolatileWord = + cub::detail::conditional_t::IS_MULTIPLE, + unsigned long long, + ShuffleWord>; + + /// Biggest memory-access word that T is a whole multiple of and is not larger + /// than the alignment of T + using DeviceWord = + cub::detail::conditional_t::IS_MULTIPLE, + ulonglong2, + VolatileWord>; + + /// Biggest texture reference word that T is a whole multiple of and is not + /// larger than the alignment of T + using TextureWord = cub::detail::conditional_t< + IsMultiple::IS_MULTIPLE, + uint4, + cub::detail::conditional_t::IS_MULTIPLE, uint2, ShuffleWord>>; +}; + +// float2 specialization workaround (for SM10-SM13) +template <> +struct UnitWord +{ + typedef int ShuffleWord; + typedef unsigned long long VolatileWord; + typedef unsigned long long DeviceWord; + typedef float2 TextureWord; +}; + +// float4 specialization workaround (for SM10-SM13) +template <> +struct UnitWord +{ + typedef int ShuffleWord; + typedef unsigned long long VolatileWord; + typedef ulonglong2 DeviceWord; + typedef float4 TextureWord; +}; + + +// char2 specialization workaround (for SM10-SM13) +template <> +struct UnitWord +{ + typedef unsigned short ShuffleWord; + typedef unsigned short VolatileWord; + typedef unsigned short DeviceWord; + typedef unsigned short TextureWord; +}; + +// clang-format off +template struct UnitWord : UnitWord {}; +template struct UnitWord : UnitWord {}; +template struct UnitWord : UnitWord {}; +// clang-format on + + +/****************************************************************************** + * Vector type inference utilities. + ******************************************************************************/ + +/** + * \brief Exposes a member typedef \p Type that names the corresponding CUDA vector type if one exists. Otherwise \p Type refers to the CubVector structure itself, which will wrap the corresponding \p x, \p y, etc. vector fields. + */ +template struct CubVector; + + +enum +{ + /// The maximum number of elements in CUDA vector types + MAX_VEC_ELEMENTS = 4, +}; + + +/** + * Generic vector-1 type + */ +template +struct CubVector +{ + T x; + + typedef T BaseType; + typedef CubVector Type; +}; + +/** + * Generic vector-2 type + */ +template +struct CubVector +{ + T x; + T y; + + typedef T BaseType; + typedef CubVector Type; +}; + +/** + * Generic vector-3 type + */ +template +struct CubVector +{ + T x; + T y; + T z; + + typedef T BaseType; + typedef CubVector Type; +}; + +/** + * Generic vector-4 type + */ +template +struct CubVector +{ + T x; + T y; + T z; + T w; + + typedef T BaseType; + typedef CubVector Type; +}; + + +/** + * Macro for expanding partially-specialized built-in vector types + */ +#define CUB_DEFINE_VECTOR_TYPE(base_type,short_type) \ + \ + template<> struct CubVector : short_type##1 \ + { \ + typedef base_type BaseType; \ + typedef short_type##1 Type; \ + __host__ __device__ __forceinline__ CubVector operator+(const CubVector &other) const { \ + CubVector retval; \ + retval.x = x + other.x; \ + return retval; \ + } \ + __host__ __device__ __forceinline__ CubVector operator-(const CubVector &other) const { \ + CubVector retval; \ + retval.x = x - other.x; \ + return retval; \ + } \ + }; \ + \ + template<> struct CubVector : short_type##2 \ + { \ + typedef base_type BaseType; \ + typedef short_type##2 Type; \ + __host__ __device__ __forceinline__ CubVector operator+(const CubVector &other) const { \ + CubVector retval; \ + retval.x = x + other.x; \ + retval.y = y + other.y; \ + return retval; \ + } \ + __host__ __device__ __forceinline__ CubVector operator-(const CubVector &other) const { \ + CubVector retval; \ + retval.x = x - other.x; \ + retval.y = y - other.y; \ + return retval; \ + } \ + }; \ + \ + template<> struct CubVector : short_type##3 \ + { \ + typedef base_type BaseType; \ + typedef short_type##3 Type; \ + __host__ __device__ __forceinline__ CubVector operator+(const CubVector &other) const { \ + CubVector retval; \ + retval.x = x + other.x; \ + retval.y = y + other.y; \ + retval.z = z + other.z; \ + return retval; \ + } \ + __host__ __device__ __forceinline__ CubVector operator-(const CubVector &other) const { \ + CubVector retval; \ + retval.x = x - other.x; \ + retval.y = y - other.y; \ + retval.z = z - other.z; \ + return retval; \ + } \ + }; \ + \ + template<> struct CubVector : short_type##4 \ + { \ + typedef base_type BaseType; \ + typedef short_type##4 Type; \ + __host__ __device__ __forceinline__ CubVector operator+(const CubVector &other) const { \ + CubVector retval; \ + retval.x = x + other.x; \ + retval.y = y + other.y; \ + retval.z = z + other.z; \ + retval.w = w + other.w; \ + return retval; \ + } \ + __host__ __device__ __forceinline__ CubVector operator-(const CubVector &other) const { \ + CubVector retval; \ + retval.x = x - other.x; \ + retval.y = y - other.y; \ + retval.z = z - other.z; \ + retval.w = w - other.w; \ + return retval; \ + } \ + }; + + + +// Expand CUDA vector types for built-in primitives +// clang-format off +CUB_DEFINE_VECTOR_TYPE(char, char) +CUB_DEFINE_VECTOR_TYPE(signed char, char) +CUB_DEFINE_VECTOR_TYPE(short, short) +CUB_DEFINE_VECTOR_TYPE(int, int) +CUB_DEFINE_VECTOR_TYPE(long, long) +CUB_DEFINE_VECTOR_TYPE(long long, longlong) +CUB_DEFINE_VECTOR_TYPE(unsigned char, uchar) +CUB_DEFINE_VECTOR_TYPE(unsigned short, ushort) +CUB_DEFINE_VECTOR_TYPE(unsigned int, uint) +CUB_DEFINE_VECTOR_TYPE(unsigned long, ulong) +CUB_DEFINE_VECTOR_TYPE(unsigned long long, ulonglong) +CUB_DEFINE_VECTOR_TYPE(float, float) +CUB_DEFINE_VECTOR_TYPE(double, double) +CUB_DEFINE_VECTOR_TYPE(bool, uchar) +// clang-format on + +// Undefine macros +#undef CUB_DEFINE_VECTOR_TYPE + + +/****************************************************************************** + * Wrapper types + ******************************************************************************/ + +/** + * \brief A storage-backing wrapper that allows types with non-trivial constructors to be aliased in unions + */ +template +struct Uninitialized +{ + /// Biggest memory-access word that T is a whole multiple of and is not larger than the alignment of T + typedef typename UnitWord::DeviceWord DeviceWord; + + static constexpr std::size_t DATA_SIZE = sizeof(T); + static constexpr std::size_t WORD_SIZE = sizeof(DeviceWord); + static constexpr std::size_t WORDS = DATA_SIZE / WORD_SIZE; + + /// Backing storage + DeviceWord storage[WORDS]; + + /// Alias + __host__ __device__ __forceinline__ T& Alias() + { + return reinterpret_cast(*this); + } +}; + + +/** + * \brief A key identifier paired with a corresponding value + */ +template < + typename _Key, + typename _Value +#if defined(_WIN32) && !defined(_WIN64) + , bool KeyIsLT = (AlignBytes<_Key>::ALIGN_BYTES < AlignBytes<_Value>::ALIGN_BYTES) + , bool ValIsLT = (AlignBytes<_Value>::ALIGN_BYTES < AlignBytes<_Key>::ALIGN_BYTES) +#endif // #if defined(_WIN32) && !defined(_WIN64) + > +struct KeyValuePair +{ + typedef _Key Key; ///< Key data type + typedef _Value Value; ///< Value data type + + Key key; ///< Item key + Value value; ///< Item value + + /// Constructor + __host__ __device__ __forceinline__ + KeyValuePair() {} + + /// Constructor + __host__ __device__ __forceinline__ + KeyValuePair(Key const& key, Value const& value) : key(key), value(value) {} + + /// Inequality operator + __host__ __device__ __forceinline__ bool operator !=(const KeyValuePair &b) + { + return (value != b.value) || (key != b.key); + } +}; + +#if defined(_WIN32) && !defined(_WIN64) + +/** + * Win32 won't do 16B alignment. This can present two problems for + * should-be-16B-aligned (but actually 8B aligned) built-in and intrinsics members: + * 1) If a smaller-aligned item were to be listed first, the host compiler places the + * should-be-16B item at too early an offset (and disagrees with device compiler) + * 2) Or, if a smaller-aligned item lists second, the host compiler gets the size + * of the struct wrong (and disagrees with device compiler) + * + * So we put the larger-should-be-aligned item first, and explicitly pad the + * end of the struct + */ + +/// Smaller key specialization +template +struct KeyValuePair +{ + typedef K Key; + typedef V Value; + + typedef char Pad[AlignBytes::ALIGN_BYTES - AlignBytes::ALIGN_BYTES]; + + Value value; // Value has larger would-be alignment and goes first + Key key; + Pad pad; + + /// Constructor + __host__ __device__ __forceinline__ + KeyValuePair() {} + + /// Constructor + __host__ __device__ __forceinline__ + KeyValuePair(Key const& key, Value const& value) : key(key), value(value) {} + + /// Inequality operator + __host__ __device__ __forceinline__ bool operator !=(const KeyValuePair &b) + { + return (value != b.value) || (key != b.key); + } +}; + + +/// Smaller value specialization +template +struct KeyValuePair +{ + typedef K Key; + typedef V Value; + + typedef char Pad[AlignBytes::ALIGN_BYTES - AlignBytes::ALIGN_BYTES]; + + Key key; // Key has larger would-be alignment and goes first + Value value; + Pad pad; + + /// Constructor + __host__ __device__ __forceinline__ + KeyValuePair() {} + + /// Constructor + __host__ __device__ __forceinline__ + KeyValuePair(Key const& key, Value const& value) : key(key), value(value) {} + + /// Inequality operator + __host__ __device__ __forceinline__ bool operator !=(const KeyValuePair &b) + { + return (value != b.value) || (key != b.key); + } +}; + +#endif // #if defined(_WIN32) && !defined(_WIN64) + + +/** + * \brief A wrapper for passing simple static arrays as kernel parameters + */ +template +struct ArrayWrapper +{ + + /// Statically-sized array of type \p T + T array[COUNT]; + + /// Constructor + __host__ __device__ __forceinline__ ArrayWrapper() {} +}; + + +/** + * \brief Double-buffer storage wrapper for multi-pass stream transformations that require more than one storage array for streaming intermediate results back and forth. + * + * Many multi-pass computations require a pair of "ping-pong" storage + * buffers (e.g., one for reading from and the other for writing to, and then + * vice-versa for the subsequent pass). This structure wraps a set of device + * buffers and a "selector" member to track which is "current". + */ +template +struct DoubleBuffer +{ + /// Pair of device buffer pointers + T *d_buffers[2]; + + /// Selector into \p d_buffers (i.e., the active/valid buffer) + int selector; + + /// \brief Constructor + __host__ __device__ __forceinline__ DoubleBuffer() + { + selector = 0; + d_buffers[0] = NULL; + d_buffers[1] = NULL; + } + + /// \brief Constructor + __host__ __device__ __forceinline__ DoubleBuffer( + T *d_current, ///< The currently valid buffer + T *d_alternate) ///< Alternate storage buffer of the same size as \p d_current + { + selector = 0; + d_buffers[0] = d_current; + d_buffers[1] = d_alternate; + } + + /// \brief Return pointer to the currently valid buffer + __host__ __device__ __forceinline__ T* Current() { return d_buffers[selector]; } + + /// \brief Return pointer to the currently invalid buffer + __host__ __device__ __forceinline__ T* Alternate() { return d_buffers[selector ^ 1]; } + +}; + + + +/****************************************************************************** + * Typedef-detection + ******************************************************************************/ + + +/** + * \brief Defines a structure \p detector_name that is templated on type \p T. The \p detector_name struct exposes a constant member \p VALUE indicating whether or not parameter \p T exposes a nested type \p nested_type_name + */ +#define CUB_DEFINE_DETECT_NESTED_TYPE(detector_name, nested_type_name) \ + template \ + struct detector_name \ + { \ + template \ + static char& test(typename C::nested_type_name*); \ + template \ + static int& test(...); \ + enum \ + { \ + VALUE = sizeof(test(0)) < sizeof(int) \ + }; \ + }; + + + +/****************************************************************************** + * Simple enable-if (similar to Boost) + ******************************************************************************/ + +/** + * \brief Simple enable-if (similar to Boost) + * + * \deprecated [Since 1.16.0] The cub::If APIs are deprecated. + * Use std::enable_if instead. + */ +template +struct CUB_DEPRECATED EnableIf +{ + using Type = typename std::enable_if::type; +}; + +/****************************************************************************** + * Typedef-detection + ******************************************************************************/ + +/** + * \brief Determine whether or not BinaryOp's functor is of the form bool operator()(const T& a, const T&b) or bool operator()(const T& a, const T&b, unsigned int idx) + */ +template +struct BinaryOpHasIdxParam +{ +private: +/* + template struct SFINAE1 {}; + template struct SFINAE2 {}; + template struct SFINAE3 {}; + template struct SFINAE4 {}; +*/ + template struct SFINAE5 {}; + template struct SFINAE6 {}; + template struct SFINAE7 {}; + template struct SFINAE8 {}; +/* + template static char Test(SFINAE1 *); + template static char Test(SFINAE2 *); + template static char Test(SFINAE3 *); + template static char Test(SFINAE4 *); +*/ + template __host__ __device__ static char Test(SFINAE5 *); + template __host__ __device__ static char Test(SFINAE6 *); + template __host__ __device__ static char Test(SFINAE7 *); + template __host__ __device__ static char Test(SFINAE8 *); + + template static int Test(...); + +public: + + /// Whether the functor BinaryOp has a third unsigned int index param + static const bool HAS_PARAM = sizeof(Test(NULL)) == sizeof(char); +}; + + + + +/****************************************************************************** + * Simple type traits utilities. + * + * For example: + * Traits::CATEGORY // SIGNED_INTEGER + * Traits::NULL_TYPE // true + * Traits::CATEGORY // NOT_A_NUMBER + * Traits::PRIMITIVE; // false + * + ******************************************************************************/ + +/** + * \brief Basic type traits categories + */ +enum Category +{ + NOT_A_NUMBER, + SIGNED_INTEGER, + UNSIGNED_INTEGER, + FLOATING_POINT +}; + + +/** + * \brief Basic type traits + */ +template +struct BaseTraits +{ + /// Category + static const Category CATEGORY = _CATEGORY; + enum + { + PRIMITIVE = _PRIMITIVE, + NULL_TYPE = _NULL_TYPE, + }; +}; + + +/** + * Basic type traits (unsigned primitive specialization) + */ +template +struct BaseTraits +{ + typedef _UnsignedBits UnsignedBits; + + static const Category CATEGORY = UNSIGNED_INTEGER; + static const UnsignedBits LOWEST_KEY = UnsignedBits(0); + static const UnsignedBits MAX_KEY = UnsignedBits(-1); + + enum + { + PRIMITIVE = true, + NULL_TYPE = false, + }; + + + static __host__ __device__ __forceinline__ UnsignedBits TwiddleIn(UnsignedBits key) + { + return key; + } + + static __host__ __device__ __forceinline__ UnsignedBits TwiddleOut(UnsignedBits key) + { + return key; + } + + static __host__ __device__ __forceinline__ T Max() + { + UnsignedBits retval_bits = MAX_KEY; + T retval; + memcpy(&retval, &retval_bits, sizeof(T)); + return retval; + } + + static __host__ __device__ __forceinline__ T Lowest() + { + UnsignedBits retval_bits = LOWEST_KEY; + T retval; + memcpy(&retval, &retval_bits, sizeof(T)); + return retval; + } +}; + + +/** + * Basic type traits (signed primitive specialization) + */ +template +struct BaseTraits +{ + typedef _UnsignedBits UnsignedBits; + + static const Category CATEGORY = SIGNED_INTEGER; + static const UnsignedBits HIGH_BIT = UnsignedBits(1) << ((sizeof(UnsignedBits) * 8) - 1); + static const UnsignedBits LOWEST_KEY = HIGH_BIT; + static const UnsignedBits MAX_KEY = UnsignedBits(-1) ^ HIGH_BIT; + + enum + { + PRIMITIVE = true, + NULL_TYPE = false, + }; + + static __host__ __device__ __forceinline__ UnsignedBits TwiddleIn(UnsignedBits key) + { + return key ^ HIGH_BIT; + }; + + static __host__ __device__ __forceinline__ UnsignedBits TwiddleOut(UnsignedBits key) + { + return key ^ HIGH_BIT; + }; + + static __host__ __device__ __forceinline__ T Max() + { + UnsignedBits retval = MAX_KEY; + return reinterpret_cast(retval); + } + + static __host__ __device__ __forceinline__ T Lowest() + { + UnsignedBits retval = LOWEST_KEY; + return reinterpret_cast(retval); + } +}; + +template +struct FpLimits; + +template <> +struct FpLimits +{ + static __host__ __device__ __forceinline__ float Max() { + return FLT_MAX; + } + + static __host__ __device__ __forceinline__ float Lowest() { + return FLT_MAX * float(-1); + } +}; + +template <> +struct FpLimits +{ + static __host__ __device__ __forceinline__ double Max() { + return DBL_MAX; + } + + static __host__ __device__ __forceinline__ double Lowest() { + return DBL_MAX * double(-1); + } +}; + +#if !_NVHPC_CUDA +template <> +struct FpLimits<__half> +{ + static __host__ __device__ __forceinline__ __half Max() { + unsigned short max_word = 0x7BFF; + return reinterpret_cast<__half&>(max_word); + } + + static __host__ __device__ __forceinline__ __half Lowest() { + unsigned short lowest_word = 0xFBFF; + return reinterpret_cast<__half&>(lowest_word); + } +}; +#endif + +#if !_NVHPC_CUDA && !defined(CUB_DISABLE_BF16_SUPPORT) +template <> +struct FpLimits<__nv_bfloat16> +{ + static __host__ __device__ __forceinline__ __nv_bfloat16 Max() { + unsigned short max_word = 0x7F7F; + return reinterpret_cast<__nv_bfloat16&>(max_word); + } + + static __host__ __device__ __forceinline__ __nv_bfloat16 Lowest() { + unsigned short lowest_word = 0xFF7F; + return reinterpret_cast<__nv_bfloat16&>(lowest_word); + } +}; +#endif + +/** + * Basic type traits (fp primitive specialization) + */ +template +struct BaseTraits +{ + typedef _UnsignedBits UnsignedBits; + + static const Category CATEGORY = FLOATING_POINT; + static const UnsignedBits HIGH_BIT = UnsignedBits(1) << ((sizeof(UnsignedBits) * 8) - 1); + static const UnsignedBits LOWEST_KEY = UnsignedBits(-1); + static const UnsignedBits MAX_KEY = UnsignedBits(-1) ^ HIGH_BIT; + + enum + { + PRIMITIVE = true, + NULL_TYPE = false, + }; + + static __host__ __device__ __forceinline__ UnsignedBits TwiddleIn(UnsignedBits key) + { + UnsignedBits mask = (key & HIGH_BIT) ? UnsignedBits(-1) : HIGH_BIT; + return key ^ mask; + }; + + static __host__ __device__ __forceinline__ UnsignedBits TwiddleOut(UnsignedBits key) + { + UnsignedBits mask = (key & HIGH_BIT) ? HIGH_BIT : UnsignedBits(-1); + return key ^ mask; + }; + + static __host__ __device__ __forceinline__ T Max() { + return FpLimits::Max(); + } + + static __host__ __device__ __forceinline__ T Lowest() { + return FpLimits::Lowest(); + } +}; + + +/** + * \brief Numeric type traits + */ +// clang-format off +template struct NumericTraits : BaseTraits {}; + +template <> struct NumericTraits : BaseTraits {}; + +template <> struct NumericTraits : BaseTraits<(std::numeric_limits::is_signed) ? SIGNED_INTEGER : UNSIGNED_INTEGER, true, false, unsigned char, char> {}; +template <> struct NumericTraits : BaseTraits {}; +template <> struct NumericTraits : BaseTraits {}; +template <> struct NumericTraits : BaseTraits {}; +template <> struct NumericTraits : BaseTraits {}; +template <> struct NumericTraits : BaseTraits {}; + +template <> struct NumericTraits : BaseTraits {}; +template <> struct NumericTraits : BaseTraits {}; +template <> struct NumericTraits : BaseTraits {}; +template <> struct NumericTraits : BaseTraits {}; +template <> struct NumericTraits : BaseTraits {}; + + +#if CUB_IS_INT128_ENABLED +template <> +struct NumericTraits<__uint128_t> +{ + using T = __uint128_t; + using UnsignedBits = __uint128_t; + + static constexpr Category CATEGORY = UNSIGNED_INTEGER; + static constexpr UnsignedBits LOWEST_KEY = UnsignedBits(0); + static constexpr UnsignedBits MAX_KEY = UnsignedBits(-1); + + static constexpr bool PRIMITIVE = false; + static constexpr bool NULL_TYPE = false; + + static __host__ __device__ __forceinline__ UnsignedBits TwiddleIn(UnsignedBits key) + { + return key; + } + + static __host__ __device__ __forceinline__ UnsignedBits TwiddleOut(UnsignedBits key) + { + return key; + } + + static __host__ __device__ __forceinline__ T Max() + { + return MAX_KEY; + } + + static __host__ __device__ __forceinline__ T Lowest() + { + return LOWEST_KEY; + } +}; + +template <> +struct NumericTraits<__int128_t> +{ + using T = __int128_t; + using UnsignedBits = __uint128_t; + + static constexpr Category CATEGORY = SIGNED_INTEGER; + static constexpr UnsignedBits HIGH_BIT = UnsignedBits(1) << ((sizeof(UnsignedBits) * 8) - 1); + static constexpr UnsignedBits LOWEST_KEY = HIGH_BIT; + static constexpr UnsignedBits MAX_KEY = UnsignedBits(-1) ^ HIGH_BIT; + + static constexpr bool PRIMITIVE = false; + static constexpr bool NULL_TYPE = false; + + static __host__ __device__ __forceinline__ UnsignedBits TwiddleIn(UnsignedBits key) + { + return key ^ HIGH_BIT; + }; + + static __host__ __device__ __forceinline__ UnsignedBits TwiddleOut(UnsignedBits key) + { + return key ^ HIGH_BIT; + }; + + static __host__ __device__ __forceinline__ T Max() + { + UnsignedBits retval = MAX_KEY; + return reinterpret_cast(retval); + } + + static __host__ __device__ __forceinline__ T Lowest() + { + UnsignedBits retval = LOWEST_KEY; + return reinterpret_cast(retval); + } +}; +#endif + +template <> struct NumericTraits : BaseTraits {}; +template <> struct NumericTraits : BaseTraits {}; +#if !_NVHPC_CUDA + template <> struct NumericTraits<__half> : BaseTraits {}; +#endif +#if !_NVHPC_CUDA && !defined(CUB_DISABLE_BF16_SUPPORT) + template <> struct NumericTraits<__nv_bfloat16> : BaseTraits {}; +#endif + +template <> struct NumericTraits : BaseTraits::VolatileWord, bool> {}; +// clang-format on + +/** + * \brief Type traits + */ +template +struct Traits : NumericTraits::type> {}; + + +#endif // DOXYGEN_SHOULD_SKIP_THIS + + +/** @} */ // end group UtilModule + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/version.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/version.cuh new file mode 100644 index 0000000000000000000000000000000000000000..d51023912fa30731cb54543a891917e2aee6d623 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/version.cuh @@ -0,0 +1,70 @@ +/****************************************************************************** + * Copyright (c) 2011-2022, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/*! \file version.cuh + * \brief Compile-time macros encoding CUB release version + * + * is the only CUB header that is guaranteed to + * change with every CUB release. + * + */ + +#pragma once + +/*! \def CUB_VERSION + * \brief The preprocessor macro \p CUB_VERSION encodes the version + * number of the CUB library. + * + * CUB_VERSION % 100 is the sub-minor version. + * CUB_VERSION / 100 % 1000 is the minor version. + * CUB_VERSION / 100000 is the major version. + */ +#define CUB_VERSION 200200 + +/*! \def CUB_MAJOR_VERSION + * \brief The preprocessor macro \p CUB_MAJOR_VERSION encodes the + * major version number of the CUB library. + */ +#define CUB_MAJOR_VERSION (CUB_VERSION / 100000) + +/*! \def CUB_MINOR_VERSION + * \brief The preprocessor macro \p CUB_MINOR_VERSION encodes the + * minor version number of the CUB library. + */ +#define CUB_MINOR_VERSION (CUB_VERSION / 100 % 1000) + +/*! \def CUB_SUBMINOR_VERSION + * \brief The preprocessor macro \p CUB_SUBMINOR_VERSION encodes the + * sub-minor version number of the CUB library. + */ +#define CUB_SUBMINOR_VERSION (CUB_VERSION % 100) + +/*! \def CUB_PATCH_NUMBER + * \brief The preprocessor macro \p CUB_PATCH_NUMBER encodes the + * patch number of the CUB library. + */ +#define CUB_PATCH_NUMBER 0 diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_exchange_shfl.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_exchange_shfl.cuh new file mode 100644 index 0000000000000000000000000000000000000000..38e2cd81b9789040e72f3b4ed95b2aaea3447cd8 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_exchange_shfl.cuh @@ -0,0 +1,327 @@ +/****************************************************************************** + * Copyright (c) 2011-2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +template +class WarpExchangeShfl +{ + static_assert(PowerOfTwo::VALUE, + "LOGICAL_WARP_THREADS must be a power of two"); + + static_assert(ITEMS_PER_THREAD == LOGICAL_WARP_THREADS, + "WARP_EXCHANGE_SHUFFLE currently only works when ITEMS_PER_THREAD == " + "LOGICAL_WARP_THREADS"); + + constexpr static bool IS_ARCH_WARP = LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0); + + // concrete recursion class + template + class CompileTimeArray : protected CompileTimeArray + { + protected: + InputT val; + + template + __device__ void Foreach(const bool xor_bit_set, const unsigned mask) + { + // The implementation here is a recursive divide-and-conquer approach + // that takes inspiration from: + // https://forums.developer.nvidia.com/t/transposing-register-held-matrices-with-warp-shuffles-need-help/38652/2 + // + // At its core, the problem can be boiled down to transposing the matrix + // + // A B + // C D + // + // by swapping the off-diagonal elements/sub-matrices B and C recursively. + // + // This implementation requires power-of-two matrices. In order to avoid + // the use of local or shared memory, all index computation has to occur + // at compile-time, since registers cannot be indexed dynamically. + // Furthermore, using recursive templates reduces the mental load on the + // optimizer, since lowering for-loops into registers oftentimes requires + // finagling them with #pragma unroll, which leads to brittle code. + // + // To illustrate this algorithm, let's pretend we have warpSize = 8, + // where t0, ..., t7 denote the 8 threads, and thread i has an array of + // size 8 with data = [Ai, Bi, ..., Hi] (the columns in the schematics). + // + // In the first round, we exchange the largest 4x4 off-diagonal + // submatrix. Boxes illustrate the submatrices to be exchanged. + // + // ROUND 1 + // ======= + // t0 t1 t2 t3 t4 t5 t6 t7 + // ┌──────────────┐ + // A0 A1 A2 A3 │A4 A5 A6 A7│ NUM_ENTRIES == 4 tells us how many + // │ │ entries we have in a submatrix, + // │ │ in this case 4 and the size of + // B0 B1 B2 B3 │B4 B5 B6 B7│ the jumps between submatrices. + // │ │ + // │ │ 1. t[0,1,2,3] data[4] swap with t[4,5,6,7]'s data[0] + // C0 C1 C2 C3 │C4 C5 C6 C7│ 2. t[0,1,2,3] data[5] swap with t[4,5,6,7]'s data[1] + // │ │ 3. t[0,1,2,3] data[6] swap with t[4,5,6,7]'s data[2] + // │ │ 4. t[0,1,2,3] data[7] swap with t[4,5,6,7]'s data[3] + // D0 D1 D2 D3 │D4 D5 D6 D7│ + // └──────────────┘ + // ┌──────────────┐ + // │E0 E1 E2 E3│ E4 E5 E6 E7 + // │ │ + // │ │ + // │F0 F1 F2 F3│ F4 F5 F6 F7 + // │ │ + // │ │ + // │G0 G1 G2 G3│ G4 G5 G6 G7 + // │ │ + // │ │ + // │H0 H1 H2 H3│ H4 H5 H6 H7 + // └──────────────┘ + // + // ROUND 2 + // ======= + // t0 t1 t2 t3 t4 t5 t6 t7 + // ┌──────┐ ┌──────┐ + // A0 A1 │A2 A3│ E0 E1 │E2 E3│ NUM_ENTRIES == 2 so we have 2 + // │ │ │ │ submatrices per thread and there + // │ │ │ │ are 2 elements between these + // B0 B1 │B2 B3│ F0 F1 │F2 F3│ submatrices. + // └──────┘ └──────┘ + // ┌──────┐ ┌──────┐ 1. t[0,1,4,5] data[2] swap with t[2,3,6,7]'s data[0] + // │C0 C1│ C2 C3 │G0 G1│ G2 G3 2. t[0,1,4,5] data[3] swap with t[2,3,6,7]'s data[1] + // │ │ │ │ 3. t[0,1,4,5] data[6] swap with t[2,3,6,7]'s data[4] + // │ │ │ │ 4. t[0,1,4,5] data[7] swap with t[2,3,6,7]'s data[5] + // │D0 D1│ D2 D3 │H0 H1│ H2 H3 + // └──────┘ └──────┘ + // ┌──────┐ ┌──────┐ + // A4 A5 │A6 A7│ E4 E5 │E6 E7│ + // │ │ │ │ + // │ │ │ │ + // B4 B5 │B6 B7│ F4 F5 │F6 F7│ + // └──────┘ └──────┘ + // ┌──────┐ ┌──────┐ + // │C4 C5│ C6 C7 │G4 G5│ G6 G7 + // │ │ │ │ + // │ │ │ │ + // │D4 D5│ D6 D7 │H4 H5│ H6 H7 + // └──────┘ └──────┘ + // + // ROUND 3 + // ======= + // t0 t1 t2 t3 t4 t5 t6 t7 + // ┌──┐ ┌──┐ ┌──┐ ┌──┐ + // A0 │A1│ C0 │C1│ E0 │E1│ G0 │G1│ NUM_ENTRIES == 1 so we have 4 + // └──┘ └──┘ └──┘ └──┘ submatrices per thread and there + // ┌──┐ ┌──┐ ┌──┐ ┌──┐ is 1 element between these + // │B0│ B1 │D0│ D1 │F0│ F1 │H0│ H1 submatrices. + // └──┘ └──┘ └──┘ └──┘ + // ┌──┐ ┌──┐ ┌──┐ ┌──┐ 1. t[0,2,4,6] data[1] swap with t[1,3,5,7]'s data[0] + // A2 │A3│ C2 │C3│ E2 │E3│ G2 │G3│ 2. t[0,2,4,6] data[3] swap with t[1,3,5,7]'s data[2] + // └──┘ └──┘ └──┘ └──┘ 3. t[0,2,4,6] data[5] swap with t[1,3,5,7]'s data[4] + // ┌──┐ ┌──┐ ┌──┐ ┌──┐ 4. t[0,2,4,6] data[7] swap with t[1,3,5,7]'s data[6] + // │B2│ B3 │D2│ D3 │F2│ F3 │H2│ H3 + // └──┘ └──┘ └──┘ └──┘ + // ┌──┐ ┌──┐ ┌──┐ ┌──┐ + // A4 │A5│ C4 │C5│ E4 │E5│ G4 │G5│ + // └──┘ └──┘ └──┘ └──┘ + // ┌──┐ ┌──┐ ┌──┐ ┌──┐ + // │B4│ B5 │D4│ D5 │F4│ F5 │H4│ H5 + // └──┘ └──┘ └──┘ └──┘ + // ┌──┐ ┌──┐ ┌──┐ ┌──┐ + // A6 │A7│ C6 │C7│ E6 │E7│ G6 │G7│ + // └──┘ └──┘ └──┘ └──┘ + // ┌──┐ ┌──┐ ┌──┐ ┌──┐ + // │B6│ B7 │D6│ D7 │F6│ F7 │H6│ H7 + // └──┘ └──┘ └──┘ └──┘ + // + // RESULT + // ====== + // t0 t1 t2 t3 t4 t5 t6 t7 + // + // A0 B0 C0 D0 E0 F0 G0 H0 + // + // + // A1 B1 C1 D1 E1 F1 G1 H1 + // + // + // A2 B2 C2 D2 E2 F2 G2 H2 + // + // + // A3 B3 C3 D3 E3 F3 G3 H3 + // + // + // A4 B4 C4 D4 E4 F4 G4 H4 + // + // + // A5 B5 C5 D5 E5 F5 G5 H5 + // + // + // A6 B6 C6 D6 E6 F6 G6 H6 + // + // + // A7 B7 C7 D7 E7 F7 G7 H7 + // + + // NOTE: Do *NOT* try to refactor this code to use a reference, since nvcc + // tends to choke on it and then drop everything into local memory. + const InputT send_val = (xor_bit_set ? CompileTimeArray::val + : CompileTimeArray::val); + const InputT recv_val = __shfl_xor_sync(mask, send_val, NUM_ENTRIES, LOGICAL_WARP_THREADS); + (xor_bit_set ? CompileTimeArray::val + : CompileTimeArray::val) = recv_val; + + constexpr int next_idx = IDX + 1 + ((IDX + 1) % NUM_ENTRIES == 0) * NUM_ENTRIES; + CompileTimeArray::template Foreach(xor_bit_set, mask); + } + + // terminate recursion + __device__ void TransposeImpl(unsigned int, unsigned int, Int2Type<0>) {} + + template + __device__ void TransposeImpl(const unsigned int lane_id, + const unsigned int mask, + Int2Type) + { + const bool xor_bit_set = lane_id & NUM_ENTRIES; + Foreach(xor_bit_set, mask); + + TransposeImpl(lane_id, mask, Int2Type()); + } + + public: + __device__ CompileTimeArray(const InputT (&input_items)[ITEMS_PER_THREAD], + OutputT (&output_items)[ITEMS_PER_THREAD]) + : CompileTimeArray{input_items, output_items} + , val{input_items[IDX]} + {} + + __device__ ~CompileTimeArray() { this->output_items[IDX] = val; } + + __device__ void Transpose(const unsigned int lane_id, const unsigned int mask) + { + TransposeImpl(lane_id, mask, Int2Type()); + } + }; + + // terminating partial specialization + template + class CompileTimeArray + { + protected: + // used for dumping back the individual values after transposing + InputT (&output_items)[ITEMS_PER_THREAD]; + + template + __device__ void Foreach(bool, unsigned) + {} + + public: + __device__ CompileTimeArray(const InputT (&)[ITEMS_PER_THREAD], + OutputT (&output_items)[ITEMS_PER_THREAD]) + : output_items{output_items} + {} + }; + + + const unsigned int lane_id; + const unsigned int warp_id; + const unsigned int member_mask; + +public: + using TempStorage = NullType; + + WarpExchangeShfl() = delete; + + explicit __device__ __forceinline__ WarpExchangeShfl(TempStorage &) + : lane_id(IS_ARCH_WARP ? LaneId() : (LaneId() % LOGICAL_WARP_THREADS)) + , warp_id(IS_ARCH_WARP ? 0 : (LaneId() / LOGICAL_WARP_THREADS)) + , member_mask(WarpMask(warp_id)) + {} + + template + __device__ __forceinline__ void BlockedToStriped(const InputT (&input_items)[ITEMS_PER_THREAD], + OutputT (&output_items)[ITEMS_PER_THREAD]) + { + CompileTimeArray arr{input_items, output_items}; + arr.Transpose(lane_id, member_mask); + } + + template + __device__ __forceinline__ void StripedToBlocked(const InputT (&input_items)[ITEMS_PER_THREAD], + OutputT (&output_items)[ITEMS_PER_THREAD]) + { + BlockedToStriped(input_items, output_items); + } + + // Trick to keep the compiler from inferring that the + // condition in the static_assert is always false. + template + struct dependent_false + { + static constexpr bool value = false; + }; + + template + __device__ __forceinline__ void + ScatterToStriped(InputT (&)[ITEMS_PER_THREAD], + OffsetT (&)[ITEMS_PER_THREAD]) + { + static_assert(dependent_false::value, + "Shuffle specialization of warp exchange does not support\n" + "ScatterToStriped(InputT (&items)[ITEMS_PER_THREAD],\n" + " OffsetT (&ranks)[ITEMS_PER_THREAD])"); + } + + template + __device__ __forceinline__ void + ScatterToStriped(const InputT (&)[ITEMS_PER_THREAD], + OutputT (&)[ITEMS_PER_THREAD], + OffsetT (&)[ITEMS_PER_THREAD]) + { + static_assert(dependent_false::value, + "Shuffle specialization of warp exchange does not support\n" + "ScatterToStriped(const InputT (&input_items)[ITEMS_PER_THREAD],\n" + " OutputT (&output_items)[ITEMS_PER_THREAD],\n" + " OffsetT (&ranks)[ITEMS_PER_THREAD])"); + } +}; + +} // namespace detail + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_exchange_smem.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_exchange_smem.cuh new file mode 100644 index 0000000000000000000000000000000000000000..1a377d8e68438107739de95bbe1174e49aae1b85 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_exchange_smem.cuh @@ -0,0 +1,178 @@ +/****************************************************************************** + * Copyright (c) 2011-2023, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file + * The cub::WarpExchangeSmem class provides [collective](index.html#sec0) + * methods for rearranging data partitioned across a CUDA warp. + */ + +#pragma once + +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +namespace detail +{ + +template +class WarpExchangeSmem +{ + static_assert(PowerOfTwo::VALUE, + "LOGICAL_WARP_THREADS must be a power of two"); + + constexpr static int ITEMS_PER_TILE = + ITEMS_PER_THREAD * LOGICAL_WARP_THREADS + 1; + + constexpr static bool IS_ARCH_WARP = LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0); + + constexpr static int LOG_SMEM_BANKS = CUB_LOG_SMEM_BANKS(0); + + // Insert padding if the number of items per thread is a power of two + // and > 4 (otherwise we can typically use 128b loads) + constexpr static bool INSERT_PADDING = (ITEMS_PER_THREAD > 4) && + (PowerOfTwo::VALUE); + + constexpr static int PADDING_ITEMS = INSERT_PADDING + ? (ITEMS_PER_TILE >> LOG_SMEM_BANKS) + : 0; + + union _TempStorage + { + InputT items_shared[ITEMS_PER_TILE + PADDING_ITEMS]; + }; // union TempStorage + + /// Shared storage reference + _TempStorage &temp_storage; + + const unsigned int lane_id; + const unsigned int warp_id; + const unsigned int member_mask; + +public: + + struct TempStorage : Uninitialized<_TempStorage> {}; + + WarpExchangeSmem() = delete; + + explicit __device__ __forceinline__ + WarpExchangeSmem(TempStorage &temp_storage) + : temp_storage(temp_storage.Alias()) + , lane_id(IS_ARCH_WARP ? LaneId() : (LaneId() % LOGICAL_WARP_THREADS)) + , warp_id(IS_ARCH_WARP ? 0 : (LaneId() / LOGICAL_WARP_THREADS)) + , member_mask(WarpMask(warp_id)) + {} + + template + __device__ __forceinline__ void + BlockedToStriped(const InputT (&input_items)[ITEMS_PER_THREAD], + OutputT (&output_items)[ITEMS_PER_THREAD]) + { + for (int item = 0; item < ITEMS_PER_THREAD; item++) + { + const int idx = ITEMS_PER_THREAD * lane_id + item; + temp_storage.items_shared[idx] = input_items[item]; + } + WARP_SYNC(member_mask); + + for (int item = 0; item < ITEMS_PER_THREAD; item++) + { + const int idx = LOGICAL_WARP_THREADS * item + lane_id; + output_items[item] = temp_storage.items_shared[idx]; + } + } + + template + __device__ __forceinline__ void + StripedToBlocked(const InputT (&input_items)[ITEMS_PER_THREAD], + OutputT (&output_items)[ITEMS_PER_THREAD]) + { + for (int item = 0; item < ITEMS_PER_THREAD; item++) + { + const int idx = LOGICAL_WARP_THREADS * item + lane_id; + temp_storage.items_shared[idx] = input_items[item]; + } + WARP_SYNC(member_mask); + + for (int item = 0; item < ITEMS_PER_THREAD; item++) + { + const int idx = ITEMS_PER_THREAD * lane_id + item; + output_items[item] = temp_storage.items_shared[idx]; + } + } + + template + __device__ __forceinline__ void + ScatterToStriped(InputT (&items)[ITEMS_PER_THREAD], + OffsetT (&ranks)[ITEMS_PER_THREAD]) + { + ScatterToStriped(items, items, ranks); + } + + template + __device__ __forceinline__ void + ScatterToStriped(const InputT (&input_items)[ITEMS_PER_THREAD], + OutputT (&output_items)[ITEMS_PER_THREAD], + OffsetT (&ranks)[ITEMS_PER_THREAD]) + { + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + if (INSERT_PADDING) + { + ranks[ITEM] = SHR_ADD(ranks[ITEM], LOG_SMEM_BANKS, ranks[ITEM]); + } + + temp_storage.items_shared[ranks[ITEM]] = input_items[ITEM]; + } + + WARP_SYNC(member_mask); + + #pragma unroll + for (int ITEM = 0; ITEM < ITEMS_PER_THREAD; ITEM++) + { + int item_offset = (ITEM * LOGICAL_WARP_THREADS) + lane_id; + + if (INSERT_PADDING) + { + item_offset = SHR_ADD(item_offset, LOG_SMEM_BANKS, item_offset); + } + + output_items[ITEM] = temp_storage.items_shared[item_offset]; + } + } +}; + +} // namespace detail + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_reduce_shfl.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_reduce_shfl.cuh new file mode 100644 index 0000000000000000000000000000000000000000..ad6d2512f92440e9f0a6f9eaf3e3202e62f11a4d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_reduce_shfl.cuh @@ -0,0 +1,583 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::WarpReduceShfl provides SHFL-based variants of parallel reduction of items partitioned across a CUDA thread warp. + */ + +#pragma once + +#include "../../config.cuh" +#include "../../thread/thread_operators.cuh" +#include "../../util_ptx.cuh" +#include "../../util_type.cuh" + +#include + +#include +#include + +CUB_NAMESPACE_BEGIN + + +namespace detail +{ + +template +struct reduce_add_exists : ::cuda::std::false_type +{}; + +template +struct reduce_add_exists : ::cuda::std::true_type +{}; + +template +struct reduce_min_exists : ::cuda::std::false_type +{}; + +template +struct reduce_min_exists : ::cuda::std::true_type +{}; + +template +struct reduce_max_exists : ::cuda::std::false_type +{}; + +template +struct reduce_max_exists : ::cuda::std::true_type +{}; + +} + + +/** + * \brief WarpReduceShfl provides SHFL-based variants of parallel reduction of items partitioned across a CUDA thread warp. + * + * LOGICAL_WARP_THREADS must be a power-of-two + */ +template < + typename T, ///< Data type being reduced + int LOGICAL_WARP_THREADS, ///< Number of threads per logical warp + int LEGACY_PTX_ARCH = 0> ///< The PTX compute capability for which to to specialize this collective +struct WarpReduceShfl +{ + static_assert(PowerOfTwo::VALUE, + "LOGICAL_WARP_THREADS must be a power of two"); + + //--------------------------------------------------------------------- + // Constants and type definitions + //--------------------------------------------------------------------- + + enum + { + /// Whether the logical warp size and the PTX warp size coincide + IS_ARCH_WARP = (LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0)), + + /// The number of warp reduction steps + STEPS = Log2::VALUE, + + /// Number of logical warps in a PTX warp + LOGICAL_WARPS = CUB_WARP_THREADS(0) / LOGICAL_WARP_THREADS, + + /// The 5-bit SHFL mask for logically splitting warps into sub-segments starts 8-bits up + SHFL_C = (CUB_WARP_THREADS(0) - LOGICAL_WARP_THREADS) << 8 + + }; + + template + struct IsInteger + { + enum { + ///Whether the data type is a small (32b or less) integer for which we can use a single SFHL instruction per exchange + IS_SMALL_UNSIGNED = (Traits::CATEGORY == UNSIGNED_INTEGER) && (sizeof(S) <= sizeof(unsigned int)) + }; + }; + + + /// Shared memory storage layout type + typedef NullType TempStorage; + + + //--------------------------------------------------------------------- + // Thread fields + //--------------------------------------------------------------------- + + /// Lane index in logical warp + int lane_id; + + /// Logical warp index in 32-thread physical warp + int warp_id; + + /// 32-thread physical warp member mask of logical warp + uint32_t member_mask; + + + //--------------------------------------------------------------------- + // Construction + //--------------------------------------------------------------------- + + /// Constructor + __device__ __forceinline__ WarpReduceShfl( + TempStorage &/*temp_storage*/) + : lane_id(static_cast(LaneId())) + , warp_id(IS_ARCH_WARP ? 0 : (lane_id / LOGICAL_WARP_THREADS)) + , member_mask(WarpMask(warp_id)) + { + if (!IS_ARCH_WARP) + { + lane_id = lane_id % LOGICAL_WARP_THREADS; + } + } + + + //--------------------------------------------------------------------- + // Reduction steps + //--------------------------------------------------------------------- + + /// Reduction (specialized for summation across uint32 types) + __device__ __forceinline__ unsigned int ReduceStep( + unsigned int input, ///< [in] Calling thread's input item. + cub::Sum /*reduction_op*/, ///< [in] Binary reduction operator + int last_lane, ///< [in] Index of last lane in segment + int offset) ///< [in] Up-offset to pull from + { + unsigned int output; + int shfl_c = last_lane | SHFL_C; // Shuffle control (mask and last_lane) + + // Use predicate set from SHFL to guard against invalid peers + asm volatile( + "{" + " .reg .u32 r0;" + " .reg .pred p;" + " shfl.sync.down.b32 r0|p, %1, %2, %3, %5;" + " @p add.u32 r0, r0, %4;" + " mov.u32 %0, r0;" + "}" + : "=r"(output) : "r"(input), "r"(offset), "r"(shfl_c), "r"(input), "r"(member_mask)); + + return output; + } + + + /// Reduction (specialized for summation across fp32 types) + __device__ __forceinline__ float ReduceStep( + float input, ///< [in] Calling thread's input item. + cub::Sum /*reduction_op*/, ///< [in] Binary reduction operator + int last_lane, ///< [in] Index of last lane in segment + int offset) ///< [in] Up-offset to pull from + { + float output; + int shfl_c = last_lane | SHFL_C; // Shuffle control (mask and last_lane) + + // Use predicate set from SHFL to guard against invalid peers + asm volatile( + "{" + " .reg .f32 r0;" + " .reg .pred p;" + " shfl.sync.down.b32 r0|p, %1, %2, %3, %5;" + " @p add.f32 r0, r0, %4;" + " mov.f32 %0, r0;" + "}" + : "=f"(output) : "f"(input), "r"(offset), "r"(shfl_c), "f"(input), "r"(member_mask)); + + return output; + } + + + /// Reduction (specialized for summation across unsigned long long types) + __device__ __forceinline__ unsigned long long ReduceStep( + unsigned long long input, ///< [in] Calling thread's input item. + cub::Sum /*reduction_op*/, ///< [in] Binary reduction operator + int last_lane, ///< [in] Index of last lane in segment + int offset) ///< [in] Up-offset to pull from + { + unsigned long long output; + int shfl_c = last_lane | SHFL_C; // Shuffle control (mask and last_lane) + + asm volatile( + "{" + " .reg .u32 lo;" + " .reg .u32 hi;" + " .reg .pred p;" + " mov.b64 {lo, hi}, %1;" + " shfl.sync.down.b32 lo|p, lo, %2, %3, %4;" + " shfl.sync.down.b32 hi|p, hi, %2, %3, %4;" + " mov.b64 %0, {lo, hi};" + " @p add.u64 %0, %0, %1;" + "}" + : "=l"(output) : "l"(input), "r"(offset), "r"(shfl_c), "r"(member_mask)); + + return output; + } + + + /// Reduction (specialized for summation across long long types) + __device__ __forceinline__ long long ReduceStep( + long long input, ///< [in] Calling thread's input item. + cub::Sum /*reduction_op*/, ///< [in] Binary reduction operator + int last_lane, ///< [in] Index of last lane in segment + int offset) ///< [in] Up-offset to pull from + { + long long output; + int shfl_c = last_lane | SHFL_C; // Shuffle control (mask and last_lane) + + // Use predicate set from SHFL to guard against invalid peers + asm volatile( + "{" + " .reg .u32 lo;" + " .reg .u32 hi;" + " .reg .pred p;" + " mov.b64 {lo, hi}, %1;" + " shfl.sync.down.b32 lo|p, lo, %2, %3, %4;" + " shfl.sync.down.b32 hi|p, hi, %2, %3, %4;" + " mov.b64 %0, {lo, hi};" + " @p add.s64 %0, %0, %1;" + "}" + : "=l"(output) : "l"(input), "r"(offset), "r"(shfl_c), "r"(member_mask)); + + return output; + } + + + /// Reduction (specialized for summation across double types) + __device__ __forceinline__ double ReduceStep( + double input, ///< [in] Calling thread's input item. + cub::Sum /*reduction_op*/, ///< [in] Binary reduction operator + int last_lane, ///< [in] Index of last lane in segment + int offset) ///< [in] Up-offset to pull from + { + double output; + int shfl_c = last_lane | SHFL_C; // Shuffle control (mask and last_lane) + + // Use predicate set from SHFL to guard against invalid peers + asm volatile( + "{" + " .reg .u32 lo;" + " .reg .u32 hi;" + " .reg .pred p;" + " .reg .f64 r0;" + " mov.b64 %0, %1;" + " mov.b64 {lo, hi}, %1;" + " shfl.sync.down.b32 lo|p, lo, %2, %3, %4;" + " shfl.sync.down.b32 hi|p, hi, %2, %3, %4;" + " mov.b64 r0, {lo, hi};" + " @p add.f64 %0, %0, r0;" + "}" + : "=d"(output) : "d"(input), "r"(offset), "r"(shfl_c), "r"(member_mask)); + + return output; + } + + + /// Reduction (specialized for swizzled ReduceByKeyOp across KeyValuePair types) + template + __device__ __forceinline__ KeyValuePair ReduceStep( + KeyValuePair input, ///< [in] Calling thread's input item. + SwizzleScanOp > /*reduction_op*/, ///< [in] Binary reduction operator + int last_lane, ///< [in] Index of last lane in segment + int offset) ///< [in] Up-offset to pull from + { + KeyValuePair output; + + KeyT other_key = ShuffleDown(input.key, offset, last_lane, member_mask); + + output.key = input.key; + output.value = ReduceStep( + input.value, + cub::Sum(), + last_lane, + offset, + Int2Type::IS_SMALL_UNSIGNED>()); + + if (input.key != other_key) + output.value = input.value; + + return output; + } + + + + /// Reduction (specialized for swizzled ReduceBySegmentOp across KeyValuePair types) + template + __device__ __forceinline__ KeyValuePair ReduceStep( + KeyValuePair input, ///< [in] Calling thread's input item. + SwizzleScanOp > /*reduction_op*/, ///< [in] Binary reduction operator + int last_lane, ///< [in] Index of last lane in segment + int offset) ///< [in] Up-offset to pull from + { + KeyValuePair output; + + output.value = ReduceStep(input.value, cub::Sum(), last_lane, offset, Int2Type::IS_SMALL_UNSIGNED>()); + output.key = ReduceStep(input.key, cub::Sum(), last_lane, offset, Int2Type::IS_SMALL_UNSIGNED>()); + + if (input.key > 0) + output.value = input.value; + + return output; + } + + + /// Reduction step (generic) + template + __device__ __forceinline__ _T ReduceStep( + _T input, ///< [in] Calling thread's input item. + ReductionOp reduction_op, ///< [in] Binary reduction operator + int last_lane, ///< [in] Index of last lane in segment + int offset) ///< [in] Up-offset to pull from + { + _T output = input; + + _T temp = ShuffleDown(output, offset, last_lane, member_mask); + + // Perform reduction op if valid + if (offset + lane_id <= last_lane) + output = reduction_op(input, temp); + + return output; + } + + + /// Reduction step (specialized for small unsigned integers size 32b or less) + template + __device__ __forceinline__ _T ReduceStep( + _T input, ///< [in] Calling thread's input item. + ReductionOp reduction_op, ///< [in] Binary reduction operator + int last_lane, ///< [in] Index of last lane in segment + int offset, ///< [in] Up-offset to pull from + Int2Type /*is_small_unsigned*/) ///< [in] Marker type indicating whether T is a small unsigned integer + { + return ReduceStep(input, reduction_op, last_lane, offset); + } + + + /// Reduction step (specialized for types other than small unsigned integers size 32b or less) + template + __device__ __forceinline__ _T ReduceStep( + _T input, ///< [in] Calling thread's input item. + ReductionOp reduction_op, ///< [in] Binary reduction operator + int last_lane, ///< [in] Index of last lane in segment + int offset, ///< [in] Up-offset to pull from + Int2Type /*is_small_unsigned*/) ///< [in] Marker type indicating whether T is a small unsigned integer + { + return ReduceStep(input, reduction_op, last_lane, offset); + } + + + //--------------------------------------------------------------------- + // Templated reduction iteration + //--------------------------------------------------------------------- + + template + __device__ __forceinline__ void ReduceStep( + T& input, ///< [in] Calling thread's input item. + ReductionOp reduction_op, ///< [in] Binary reduction operator + int last_lane, ///< [in] Index of last lane in segment + Int2Type /*step*/) + { + input = ReduceStep(input, reduction_op, last_lane, 1 << STEP, Int2Type::IS_SMALL_UNSIGNED>()); + + ReduceStep(input, reduction_op, last_lane, Int2Type()); + } + + template + __device__ __forceinline__ void ReduceStep( + T& /*input*/, ///< [in] Calling thread's input item. + ReductionOp /*reduction_op*/, ///< [in] Binary reduction operator + int /*last_lane*/, ///< [in] Index of last lane in segment + Int2Type /*step*/) + {} + + + //--------------------------------------------------------------------- + // Reduction operations + //--------------------------------------------------------------------- + template + __device__ __forceinline__ T ReduceImpl( + Int2Type<0> /* all_lanes_valid */, + T input, ///< [in] Calling thread's input + int valid_items, ///< [in] Total number of valid items across the logical warp + ReductionOp reduction_op) ///< [in] Binary reduction operator + { + int last_lane = valid_items - 1; + + T output = input; + + // Template-iterate reduction steps + ReduceStep(output, reduction_op, last_lane, Int2Type<0>()); + + return output; + } + + template + __device__ __forceinline__ T ReduceImpl( + Int2Type<1> /* all_lanes_valid */, + T input, ///< [in] Calling thread's input + int /* valid_items */, ///< [in] Total number of valid items across the logical warp + ReductionOp reduction_op) ///< [in] Binary reduction operator + { + int last_lane = LOGICAL_WARP_THREADS - 1; + + T output = input; + + // Template-iterate reduction steps + ReduceStep(output, reduction_op, last_lane, Int2Type<0>()); + + return output; + } + + template + __device__ __forceinline__ + typename std::enable_if< + (std::is_same::value || std::is_same::value) + && detail::reduce_add_exists<>::value, T>::type + ReduceImpl(Int2Type<1> /* all_lanes_valid */, + T input, + int /* valid_items */, + cub::Sum /* reduction_op */) + { + T output = input; + + NV_IF_TARGET(NV_PROVIDES_SM_80, + (output = __reduce_add_sync(member_mask, input);), + (output = ReduceImpl(Int2Type<1>{}, + input, + LOGICAL_WARP_THREADS, + cub::Sum{});)); + + return output; + } + + template + __device__ __forceinline__ + typename std::enable_if< + (std::is_same::value || std::is_same::value) + && detail::reduce_min_exists<>::value, T>::type + ReduceImpl(Int2Type<1> /* all_lanes_valid */, + T input, + int /* valid_items */, + cub::Min /* reduction_op */) + { + T output = input; + + NV_IF_TARGET(NV_PROVIDES_SM_80, + (output = __reduce_min_sync(member_mask, input);), + (output = ReduceImpl(Int2Type<1>{}, + input, + LOGICAL_WARP_THREADS, + cub::Min{});)); + + return output; + } + + template + __device__ __forceinline__ + typename std::enable_if< + (std::is_same::value || std::is_same::value) + && detail::reduce_max_exists<>::value, T>::type + ReduceImpl(Int2Type<1> /* all_lanes_valid */, + T input, + int /* valid_items */, + cub::Max /* reduction_op */) + { + T output = input; + + NV_IF_TARGET(NV_PROVIDES_SM_80, + (output = __reduce_max_sync(member_mask, input);), + (output = ReduceImpl(Int2Type<1>{}, + input, + LOGICAL_WARP_THREADS, + cub::Max{});)); + + return output; + } + + /// Reduction + template < + bool ALL_LANES_VALID, ///< Whether all lanes in each warp are contributing a valid fold of items + typename ReductionOp> + __device__ __forceinline__ T Reduce( + T input, ///< [in] Calling thread's input + int valid_items, ///< [in] Total number of valid items across the logical warp + ReductionOp reduction_op) ///< [in] Binary reduction operator + { + return ReduceImpl( + Int2Type{}, input, valid_items, reduction_op); + } + + + /// Segmented reduction + template < + bool HEAD_SEGMENTED, ///< Whether flags indicate a segment-head or a segment-tail + typename FlagT, + typename ReductionOp> + __device__ __forceinline__ T SegmentedReduce( + T input, ///< [in] Calling thread's input + FlagT flag, ///< [in] Whether or not the current lane is a segment head/tail + ReductionOp reduction_op) ///< [in] Binary reduction operator + { + // Get the start flags for each thread in the warp. + int warp_flags = WARP_BALLOT(flag, member_mask); + + // Convert to tail-segmented + if (HEAD_SEGMENTED) + warp_flags >>= 1; + + // Mask out the bits below the current thread + warp_flags &= LaneMaskGe(); + + // Mask of physical lanes outside the logical warp and convert to logical lanemask + if (!IS_ARCH_WARP) + { + warp_flags = (warp_flags & member_mask) >> (warp_id * LOGICAL_WARP_THREADS); + } + + // Mask in the last lane of logical warp + warp_flags |= 1u << (LOGICAL_WARP_THREADS - 1); + + // Find the next set flag + int last_lane = __clz(__brev(warp_flags)); + + T output = input; + +// // Iterate reduction steps +// #pragma unroll +// for (int STEP = 0; STEP < STEPS; STEP++) +// { +// output = ReduceStep(output, reduction_op, last_lane, 1 << STEP, Int2Type::IS_SMALL_UNSIGNED>()); +// } + + // Template-iterate reduction steps + ReduceStep(output, reduction_op, last_lane, Int2Type<0>()); + + return output; + } +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_reduce_smem.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_reduce_smem.cuh new file mode 100644 index 0000000000000000000000000000000000000000..bd083fccfc20b6d7c624b067999d6e867e79a4b7 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_reduce_smem.cuh @@ -0,0 +1,360 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::WarpReduceSmem provides smem-based variants of parallel reduction of items partitioned across a CUDA thread warp. + */ + +#pragma once + +#include "../../config.cuh" +#include "../../thread/thread_operators.cuh" +#include "../../thread/thread_load.cuh" +#include "../../thread/thread_store.cuh" +#include "../../util_type.cuh" + +CUB_NAMESPACE_BEGIN + +/** + * \brief WarpReduceSmem provides smem-based variants of parallel reduction of items partitioned across a CUDA thread warp. + */ +template < + typename T, ///< Data type being reduced + int LOGICAL_WARP_THREADS, ///< Number of threads per logical warp + int LEGACY_PTX_ARCH = 0> ///< The PTX compute capability for which to to specialize this collective +struct WarpReduceSmem +{ + /****************************************************************************** + * Constants and type definitions + ******************************************************************************/ + + enum + { + /// Whether the logical warp size and the PTX warp size coincide + IS_ARCH_WARP = (LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0)), + + /// Whether the logical warp size is a power-of-two + IS_POW_OF_TWO = PowerOfTwo::VALUE, + + /// The number of warp reduction steps + STEPS = Log2::VALUE, + + /// The number of threads in half a warp + HALF_WARP_THREADS = 1 << (STEPS - 1), + + /// The number of shared memory elements per warp + WARP_SMEM_ELEMENTS = LOGICAL_WARP_THREADS + HALF_WARP_THREADS, + + /// FlagT status (when not using ballot) + UNSET = 0x0, // Is initially unset + SET = 0x1, // Is initially set + SEEN = 0x2, // Has seen another head flag from a successor peer + }; + + /// Shared memory flag type + typedef unsigned char SmemFlag; + + /// Shared memory storage layout type (1.5 warps-worth of elements for each warp) + struct _TempStorage + { + T reduce[WARP_SMEM_ELEMENTS]; + SmemFlag flags[WARP_SMEM_ELEMENTS]; + }; + + // Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + _TempStorage &temp_storage; + unsigned int lane_id; + unsigned int member_mask; + + + /****************************************************************************** + * Construction + ******************************************************************************/ + + /// Constructor + explicit __device__ __forceinline__ WarpReduceSmem(TempStorage &temp_storage) + : temp_storage(temp_storage.Alias()) + , lane_id(IS_ARCH_WARP ? LaneId() : LaneId() % LOGICAL_WARP_THREADS) + , member_mask( + WarpMask(LaneId() / LOGICAL_WARP_THREADS)) + {} + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + //--------------------------------------------------------------------- + // Regular reduction + //--------------------------------------------------------------------- + + /** + * Reduction step + */ + template < + bool ALL_LANES_VALID, ///< Whether all lanes in each warp are contributing a valid fold of items + typename ReductionOp, + int STEP> + __device__ __forceinline__ T ReduceStep( + T input, ///< [in] Calling thread's input + int valid_items, ///< [in] Total number of valid items across the logical warp + ReductionOp reduction_op, ///< [in] Reduction operator + Int2Type /*step*/) + { + const int OFFSET = 1 << STEP; + + // Share input through buffer + ThreadStore(&temp_storage.reduce[lane_id], input); + + WARP_SYNC(member_mask); + + // Update input if peer_addend is in range + if ((ALL_LANES_VALID && IS_POW_OF_TWO) || ((lane_id + OFFSET) < valid_items)) + { + T peer_addend = ThreadLoad(&temp_storage.reduce[lane_id + OFFSET]); + input = reduction_op(input, peer_addend); + } + + WARP_SYNC(member_mask); + + return ReduceStep(input, valid_items, reduction_op, Int2Type()); + } + + + /** + * Reduction step (terminate) + */ + template < + bool ALL_LANES_VALID, ///< Whether all lanes in each warp are contributing a valid fold of items + typename ReductionOp> + __device__ __forceinline__ T ReduceStep( + T input, ///< [in] Calling thread's input + int valid_items, ///< [in] Total number of valid items across the logical warp + ReductionOp /*reduction_op*/, ///< [in] Reduction operator + Int2Type /*step*/) + { + return input; + } + + + //--------------------------------------------------------------------- + // Segmented reduction + //--------------------------------------------------------------------- + + + /** + * Ballot-based segmented reduce + */ + template < + bool HEAD_SEGMENTED, ///< Whether flags indicate a segment-head or a segment-tail + typename FlagT, + typename ReductionOp> + __device__ __forceinline__ T SegmentedReduce( + T input, ///< [in] Calling thread's input + FlagT flag, ///< [in] Whether or not the current lane is a segment head/tail + ReductionOp reduction_op, ///< [in] Reduction operator + Int2Type /*has_ballot*/) ///< [in] Marker type for whether the target arch has ballot functionality + { + // Get the start flags for each thread in the warp. + int warp_flags = WARP_BALLOT(flag, member_mask); + + if (!HEAD_SEGMENTED) + warp_flags <<= 1; + + // Keep bits above the current thread. + warp_flags &= LaneMaskGt(); + + // Accommodate packing of multiple logical warps in a single physical warp + if (!IS_ARCH_WARP) + { + warp_flags >>= (LaneId() / LOGICAL_WARP_THREADS) * LOGICAL_WARP_THREADS; + } + + // Find next flag + int next_flag = __clz(__brev(warp_flags)); + + // Clip the next segment at the warp boundary if necessary + if (LOGICAL_WARP_THREADS != 32) + next_flag = CUB_MIN(next_flag, LOGICAL_WARP_THREADS); + + #pragma unroll + for (int STEP = 0; STEP < STEPS; STEP++) + { + const int OFFSET = 1 << STEP; + + // Share input into buffer + ThreadStore(&temp_storage.reduce[lane_id], input); + + WARP_SYNC(member_mask); + + // Update input if peer_addend is in range + if (OFFSET + lane_id < next_flag) + { + T peer_addend = ThreadLoad(&temp_storage.reduce[lane_id + OFFSET]); + input = reduction_op(input, peer_addend); + } + + WARP_SYNC(member_mask); + } + + return input; + } + + + /** + * Smem-based segmented reduce + */ + template < + bool HEAD_SEGMENTED, ///< Whether flags indicate a segment-head or a segment-tail + typename FlagT, + typename ReductionOp> + __device__ __forceinline__ T SegmentedReduce( + T input, ///< [in] Calling thread's input + FlagT flag, ///< [in] Whether or not the current lane is a segment head/tail + ReductionOp reduction_op, ///< [in] Reduction operator + Int2Type /*has_ballot*/) ///< [in] Marker type for whether the target arch has ballot functionality + { + enum + { + UNSET = 0x0, // Is initially unset + SET = 0x1, // Is initially set + SEEN = 0x2, // Has seen another head flag from a successor peer + }; + + // Alias flags onto shared data storage + volatile SmemFlag *flag_storage = temp_storage.flags; + + SmemFlag flag_status = (flag) ? SET : UNSET; + + for (int STEP = 0; STEP < STEPS; STEP++) + { + const int OFFSET = 1 << STEP; + + // Share input through buffer + ThreadStore(&temp_storage.reduce[lane_id], input); + + WARP_SYNC(member_mask); + + // Get peer from buffer + T peer_addend = ThreadLoad(&temp_storage.reduce[lane_id + OFFSET]); + + WARP_SYNC(member_mask); + + // Share flag through buffer + flag_storage[lane_id] = flag_status; + + // Get peer flag from buffer + SmemFlag peer_flag_status = flag_storage[lane_id + OFFSET]; + + // Update input if peer was in range + if (lane_id < LOGICAL_WARP_THREADS - OFFSET) + { + if (HEAD_SEGMENTED) + { + // Head-segmented + if ((flag_status & SEEN) == 0) + { + // Has not seen a more distant head flag + if (peer_flag_status & SET) + { + // Has now seen a head flag + flag_status |= SEEN; + } + else + { + // Peer is not a head flag: grab its count + input = reduction_op(input, peer_addend); + } + + // Update seen status to include that of peer + flag_status |= (peer_flag_status & SEEN); + } + } + else + { + // Tail-segmented. Simply propagate flag status + if (!flag_status) + { + input = reduction_op(input, peer_addend); + flag_status |= peer_flag_status; + } + + } + } + } + + return input; + } + + + /****************************************************************************** + * Interface + ******************************************************************************/ + + /** + * Reduction + */ + template < + bool ALL_LANES_VALID, ///< Whether all lanes in each warp are contributing a valid fold of items + typename ReductionOp> + __device__ __forceinline__ T Reduce( + T input, ///< [in] Calling thread's input + int valid_items, ///< [in] Total number of valid items across the logical warp + ReductionOp reduction_op) ///< [in] Reduction operator + { + return ReduceStep(input, valid_items, reduction_op, Int2Type<0>()); + } + + + /** + * Segmented reduction + */ + template < + bool HEAD_SEGMENTED, ///< Whether flags indicate a segment-head or a segment-tail + typename FlagT, + typename ReductionOp> + __device__ __forceinline__ T SegmentedReduce( + T input, ///< [in] Calling thread's input + FlagT flag, ///< [in] Whether or not the current lane is a segment head/tail + ReductionOp reduction_op) ///< [in] Reduction operator + { + return SegmentedReduce(input, flag, reduction_op, Int2Type()); + } + + +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_scan_shfl.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_scan_shfl.cuh new file mode 100644 index 0000000000000000000000000000000000000000..c2988711c8dfecc523e7fee0380180f9c66b2912 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_scan_shfl.cuh @@ -0,0 +1,537 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::WarpScanShfl provides SHFL-based variants of parallel prefix scan of items partitioned across a CUDA thread warp. + */ + +#pragma once + +#include "../../config.cuh" +#include "../../thread/thread_operators.cuh" +#include "../../util_type.cuh" +#include "../../util_ptx.cuh" + +CUB_NAMESPACE_BEGIN + +/** + * \brief WarpScanShfl provides SHFL-based variants of parallel prefix scan of items partitioned across a CUDA thread warp. + * + * LOGICAL_WARP_THREADS must be a power-of-two + */ +template < + typename T, ///< Data type being scanned + int LOGICAL_WARP_THREADS, ///< Number of threads per logical warp + int LEGACY_PTX_ARCH = 0> ///< The PTX compute capability for which to to specialize this collective +struct WarpScanShfl +{ + //--------------------------------------------------------------------- + // Constants and type definitions + //--------------------------------------------------------------------- + + enum + { + /// Whether the logical warp size and the PTX warp size coincide + IS_ARCH_WARP = (LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0)), + + /// The number of warp scan steps + STEPS = Log2::VALUE, + + /// The 5-bit SHFL mask for logically splitting warps into sub-segments starts 8-bits up + SHFL_C = (CUB_WARP_THREADS(0) - LOGICAL_WARP_THREADS) << 8 + }; + + template + struct IntegerTraits + { + enum { + ///Whether the data type is a small (32b or less) integer for which we can use a single SFHL instruction per exchange + IS_SMALL_UNSIGNED = (Traits::CATEGORY == UNSIGNED_INTEGER) && (sizeof(S) <= sizeof(unsigned int)) + }; + }; + + /// Shared memory storage layout type + struct TempStorage {}; + + + //--------------------------------------------------------------------- + // Thread fields + //--------------------------------------------------------------------- + + /// Lane index in logical warp + unsigned int lane_id; + + /// Logical warp index in 32-thread physical warp + unsigned int warp_id; + + /// 32-thread physical warp member mask of logical warp + unsigned int member_mask; + + //--------------------------------------------------------------------- + // Construction + //--------------------------------------------------------------------- + + /// Constructor + explicit __device__ __forceinline__ + WarpScanShfl(TempStorage & /*temp_storage*/) + : lane_id(LaneId()) + , warp_id(IS_ARCH_WARP ? 0 : (lane_id / LOGICAL_WARP_THREADS)) + , member_mask(WarpMask(warp_id)) + { + if (!IS_ARCH_WARP) + { + lane_id = lane_id % LOGICAL_WARP_THREADS; + } + } + + + //--------------------------------------------------------------------- + // Inclusive scan steps + //--------------------------------------------------------------------- + + /// Inclusive prefix scan step (specialized for summation across int32 types) + __device__ __forceinline__ int InclusiveScanStep( + int input, ///< [in] Calling thread's input item. + cub::Sum /*scan_op*/, ///< [in] Binary scan operator + int first_lane, ///< [in] Index of first lane in segment + int offset) ///< [in] Up-offset to pull from + { + int output; + int shfl_c = first_lane | SHFL_C; // Shuffle control (mask and first-lane) + + // Use predicate set from SHFL to guard against invalid peers + asm volatile( + "{" + " .reg .s32 r0;" + " .reg .pred p;" + " shfl.sync.up.b32 r0|p, %1, %2, %3, %5;" + " @p add.s32 r0, r0, %4;" + " mov.s32 %0, r0;" + "}" + : "=r"(output) : "r"(input), "r"(offset), "r"(shfl_c), "r"(input), "r"(member_mask)); + + return output; + } + + /// Inclusive prefix scan step (specialized for summation across uint32 types) + __device__ __forceinline__ unsigned int InclusiveScanStep( + unsigned int input, ///< [in] Calling thread's input item. + cub::Sum /*scan_op*/, ///< [in] Binary scan operator + int first_lane, ///< [in] Index of first lane in segment + int offset) ///< [in] Up-offset to pull from + { + unsigned int output; + int shfl_c = first_lane | SHFL_C; // Shuffle control (mask and first-lane) + + // Use predicate set from SHFL to guard against invalid peers + asm volatile( + "{" + " .reg .u32 r0;" + " .reg .pred p;" + " shfl.sync.up.b32 r0|p, %1, %2, %3, %5;" + " @p add.u32 r0, r0, %4;" + " mov.u32 %0, r0;" + "}" + : "=r"(output) : "r"(input), "r"(offset), "r"(shfl_c), "r"(input), "r"(member_mask)); + + return output; + } + + + /// Inclusive prefix scan step (specialized for summation across fp32 types) + __device__ __forceinline__ float InclusiveScanStep( + float input, ///< [in] Calling thread's input item. + cub::Sum /*scan_op*/, ///< [in] Binary scan operator + int first_lane, ///< [in] Index of first lane in segment + int offset) ///< [in] Up-offset to pull from + { + float output; + int shfl_c = first_lane | SHFL_C; // Shuffle control (mask and first-lane) + + // Use predicate set from SHFL to guard against invalid peers + asm volatile( + "{" + " .reg .f32 r0;" + " .reg .pred p;" + " shfl.sync.up.b32 r0|p, %1, %2, %3, %5;" + " @p add.f32 r0, r0, %4;" + " mov.f32 %0, r0;" + "}" + : "=f"(output) : "f"(input), "r"(offset), "r"(shfl_c), "f"(input), "r"(member_mask)); + + return output; + } + + + /// Inclusive prefix scan step (specialized for summation across unsigned long long types) + __device__ __forceinline__ unsigned long long InclusiveScanStep( + unsigned long long input, ///< [in] Calling thread's input item. + cub::Sum /*scan_op*/, ///< [in] Binary scan operator + int first_lane, ///< [in] Index of first lane in segment + int offset) ///< [in] Up-offset to pull from + { + unsigned long long output; + int shfl_c = first_lane | SHFL_C; // Shuffle control (mask and first-lane) + + // Use predicate set from SHFL to guard against invalid peers + asm volatile( + "{" + " .reg .u64 r0;" + " .reg .u32 lo;" + " .reg .u32 hi;" + " .reg .pred p;" + " mov.b64 {lo, hi}, %1;" + " shfl.sync.up.b32 lo|p, lo, %2, %3, %5;" + " shfl.sync.up.b32 hi|p, hi, %2, %3, %5;" + " mov.b64 r0, {lo, hi};" + " @p add.u64 r0, r0, %4;" + " mov.u64 %0, r0;" + "}" + : "=l"(output) : "l"(input), "r"(offset), "r"(shfl_c), "l"(input), "r"(member_mask)); + + return output; + } + + + /// Inclusive prefix scan step (specialized for summation across long long types) + __device__ __forceinline__ long long InclusiveScanStep( + long long input, ///< [in] Calling thread's input item. + cub::Sum /*scan_op*/, ///< [in] Binary scan operator + int first_lane, ///< [in] Index of first lane in segment + int offset) ///< [in] Up-offset to pull from + { + long long output; + int shfl_c = first_lane | SHFL_C; // Shuffle control (mask and first-lane) + + // Use predicate set from SHFL to guard against invalid peers + asm volatile( + "{" + " .reg .s64 r0;" + " .reg .u32 lo;" + " .reg .u32 hi;" + " .reg .pred p;" + " mov.b64 {lo, hi}, %1;" + " shfl.sync.up.b32 lo|p, lo, %2, %3, %5;" + " shfl.sync.up.b32 hi|p, hi, %2, %3, %5;" + " mov.b64 r0, {lo, hi};" + " @p add.s64 r0, r0, %4;" + " mov.s64 %0, r0;" + "}" + : "=l"(output) : "l"(input), "r"(offset), "r"(shfl_c), "l"(input), "r"(member_mask)); + + return output; + } + + + /// Inclusive prefix scan step (specialized for summation across fp64 types) + __device__ __forceinline__ double InclusiveScanStep( + double input, ///< [in] Calling thread's input item. + cub::Sum /*scan_op*/, ///< [in] Binary scan operator + int first_lane, ///< [in] Index of first lane in segment + int offset) ///< [in] Up-offset to pull from + { + double output; + int shfl_c = first_lane | SHFL_C; // Shuffle control (mask and first-lane) + + // Use predicate set from SHFL to guard against invalid peers + asm volatile( + "{" + " .reg .u32 lo;" + " .reg .u32 hi;" + " .reg .pred p;" + " .reg .f64 r0;" + " mov.b64 %0, %1;" + " mov.b64 {lo, hi}, %1;" + " shfl.sync.up.b32 lo|p, lo, %2, %3, %4;" + " shfl.sync.up.b32 hi|p, hi, %2, %3, %4;" + " mov.b64 r0, {lo, hi};" + " @p add.f64 %0, %0, r0;" + "}" + : "=d"(output) : "d"(input), "r"(offset), "r"(shfl_c), "r"(member_mask)); + + return output; + } + + +/* + /// Inclusive prefix scan (specialized for ReduceBySegmentOp across KeyValuePair types) + template + __device__ __forceinline__ KeyValuePairInclusiveScanStep( + KeyValuePair input, ///< [in] Calling thread's input item. + ReduceBySegmentOp scan_op, ///< [in] Binary scan operator + int first_lane, ///< [in] Index of first lane in segment + int offset) ///< [in] Up-offset to pull from + { + KeyValuePair output; + + output.value = InclusiveScanStep(input.value, cub::Sum(), first_lane, offset, Int2Type::IS_SMALL_UNSIGNED>()); + output.key = InclusiveScanStep(input.key, cub::Sum(), first_lane, offset, Int2Type::IS_SMALL_UNSIGNED>()); + + if (input.key > 0) + output.value = input.value; + + return output; + } +*/ + + /// Inclusive prefix scan step (generic) + template + __device__ __forceinline__ _T InclusiveScanStep( + _T input, ///< [in] Calling thread's input item. + ScanOpT scan_op, ///< [in] Binary scan operator + int first_lane, ///< [in] Index of first lane in segment + int offset) ///< [in] Up-offset to pull from + { + _T temp = ShuffleUp(input, offset, first_lane, member_mask); + + // Perform scan op if from a valid peer + _T output = scan_op(temp, input); + if (static_cast(lane_id) < first_lane + offset) + output = input; + + return output; + } + + + /// Inclusive prefix scan step (specialized for small integers size 32b or less) + template + __device__ __forceinline__ _T InclusiveScanStep( + _T input, ///< [in] Calling thread's input item. + ScanOpT scan_op, ///< [in] Binary scan operator + int first_lane, ///< [in] Index of first lane in segment + int offset, ///< [in] Up-offset to pull from + Int2Type /*is_small_unsigned*/) ///< [in] Marker type indicating whether T is a small integer + { + return InclusiveScanStep(input, scan_op, first_lane, offset); + } + + + /// Inclusive prefix scan step (specialized for types other than small integers size 32b or less) + template + __device__ __forceinline__ _T InclusiveScanStep( + _T input, ///< [in] Calling thread's input item. + ScanOpT scan_op, ///< [in] Binary scan operator + int first_lane, ///< [in] Index of first lane in segment + int offset, ///< [in] Up-offset to pull from + Int2Type /*is_small_unsigned*/) ///< [in] Marker type indicating whether T is a small integer + { + return InclusiveScanStep(input, scan_op, first_lane, offset); + } + + + /****************************************************************************** + * Interface + ******************************************************************************/ + + //--------------------------------------------------------------------- + // Broadcast + //--------------------------------------------------------------------- + + /// Broadcast + __device__ __forceinline__ T Broadcast( + T input, ///< [in] The value to broadcast + int src_lane) ///< [in] Which warp lane is to do the broadcasting + { + return ShuffleIndex(input, src_lane, member_mask); + } + + + //--------------------------------------------------------------------- + // Inclusive operations + //--------------------------------------------------------------------- + + /// Inclusive scan + template + __device__ __forceinline__ void InclusiveScan( + _T input, ///< [in] Calling thread's input item. + _T &inclusive_output, ///< [out] Calling thread's output item. May be aliased with \p input. + ScanOpT scan_op) ///< [in] Binary scan operator + { + inclusive_output = input; + + // Iterate scan steps + int segment_first_lane = 0; + + // Iterate scan steps + #pragma unroll + for (int STEP = 0; STEP < STEPS; STEP++) + { + inclusive_output = InclusiveScanStep( + inclusive_output, + scan_op, + segment_first_lane, + (1 << STEP), + Int2Type::IS_SMALL_UNSIGNED>()); + } + + } + + /// Inclusive scan, specialized for reduce-value-by-key + template + __device__ __forceinline__ void InclusiveScan( + KeyValuePair input, ///< [in] Calling thread's input item. + KeyValuePair &inclusive_output, ///< [out] Calling thread's output item. May be aliased with \p input. + ReduceByKeyOp scan_op) ///< [in] Binary scan operator + { + inclusive_output = input; + + KeyT pred_key = ShuffleUp(inclusive_output.key, 1, 0, member_mask); + + unsigned int ballot = WARP_BALLOT((pred_key != inclusive_output.key), member_mask); + + // Mask away all lanes greater than ours + ballot = ballot & LaneMaskLe(); + + // Find index of first set bit + int segment_first_lane = CUB_MAX(0, 31 - __clz(ballot)); + + // Iterate scan steps + #pragma unroll + for (int STEP = 0; STEP < STEPS; STEP++) + { + inclusive_output.value = InclusiveScanStep( + inclusive_output.value, + scan_op.op, + segment_first_lane, + (1 << STEP), + Int2Type::IS_SMALL_UNSIGNED>()); + } + } + + + /// Inclusive scan with aggregate + template + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item. + T &inclusive_output, ///< [out] Calling thread's output item. May be aliased with \p input. + ScanOpT scan_op, ///< [in] Binary scan operator + T &warp_aggregate) ///< [out] Warp-wide aggregate reduction of input items. + { + InclusiveScan(input, inclusive_output, scan_op); + + // Grab aggregate from last warp lane + warp_aggregate = ShuffleIndex(inclusive_output, LOGICAL_WARP_THREADS - 1, member_mask); + } + + + //--------------------------------------------------------------------- + // Get exclusive from inclusive + //--------------------------------------------------------------------- + + /// Update inclusive and exclusive using input and inclusive + template + __device__ __forceinline__ void Update( + T /*input*/, ///< [in] + T &inclusive, ///< [in, out] + T &exclusive, ///< [out] + ScanOpT /*scan_op*/, ///< [in] + IsIntegerT /*is_integer*/) ///< [in] + { + // initial value unknown + exclusive = ShuffleUp(inclusive, 1, 0, member_mask); + } + + /// Update inclusive and exclusive using input and inclusive (specialized for summation of integer types) + __device__ __forceinline__ void Update( + T input, + T &inclusive, + T &exclusive, + cub::Sum /*scan_op*/, + Int2Type /*is_integer*/) + { + // initial value presumed 0 + exclusive = inclusive - input; + } + + /// Update inclusive and exclusive using initial value using input, inclusive, and initial value + template + __device__ __forceinline__ void Update ( + T /*input*/, + T &inclusive, + T &exclusive, + ScanOpT scan_op, + T initial_value, + IsIntegerT /*is_integer*/) + { + inclusive = scan_op(initial_value, inclusive); + exclusive = ShuffleUp(inclusive, 1, 0, member_mask); + + if (lane_id == 0) + exclusive = initial_value; + } + + /// Update inclusive and exclusive using initial value using input and inclusive (specialized for summation of integer types) + __device__ __forceinline__ void Update ( + T input, + T &inclusive, + T &exclusive, + cub::Sum scan_op, + T initial_value, + Int2Type /*is_integer*/) + { + inclusive = scan_op(initial_value, inclusive); + exclusive = inclusive - input; + } + + + /// Update inclusive, exclusive, and warp aggregate using input and inclusive + template + __device__ __forceinline__ void Update ( + T input, + T &inclusive, + T &exclusive, + T &warp_aggregate, + ScanOpT scan_op, + IsIntegerT is_integer) + { + warp_aggregate = ShuffleIndex(inclusive, LOGICAL_WARP_THREADS - 1, member_mask); + Update(input, inclusive, exclusive, scan_op, is_integer); + } + + /// Update inclusive, exclusive, and warp aggregate using input, inclusive, and initial value + template + __device__ __forceinline__ void Update ( + T input, + T &inclusive, + T &exclusive, + T &warp_aggregate, + ScanOpT scan_op, + T initial_value, + IsIntegerT is_integer) + { + warp_aggregate = ShuffleIndex(inclusive, LOGICAL_WARP_THREADS - 1, member_mask); + Update(input, inclusive, exclusive, scan_op, initial_value, is_integer); + } + + + +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_scan_smem.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_scan_smem.cuh new file mode 100644 index 0000000000000000000000000000000000000000..bd17118e999617a99d5a9b7fdc4af588e3af73c1 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/specializations/warp_scan_smem.cuh @@ -0,0 +1,388 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * \file + * cub::WarpScanSmem provides smem-based variants of parallel prefix scan of items partitioned across a CUDA thread warp. + */ + +#pragma once + +#include "../../config.cuh" +#include "../../thread/thread_operators.cuh" +#include "../../thread/thread_load.cuh" +#include "../../thread/thread_store.cuh" +#include "../../util_type.cuh" + +CUB_NAMESPACE_BEGIN + +/** + * \brief WarpScanSmem provides smem-based variants of parallel prefix scan of items partitioned across a CUDA thread warp. + */ +template < + typename T, ///< Data type being scanned + int LOGICAL_WARP_THREADS, ///< Number of threads per logical warp + int LEGACY_PTX_ARCH = 0> ///< The PTX compute capability for which to to specialize this collective +struct WarpScanSmem +{ + /****************************************************************************** + * Constants and type definitions + ******************************************************************************/ + + enum + { + /// Whether the logical warp size and the PTX warp size coincide + IS_ARCH_WARP = (LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0)), + + /// The number of warp scan steps + STEPS = Log2::VALUE, + + /// The number of threads in half a warp + HALF_WARP_THREADS = 1 << (STEPS - 1), + + /// The number of shared memory elements per warp + WARP_SMEM_ELEMENTS = LOGICAL_WARP_THREADS + HALF_WARP_THREADS, + }; + + /// Storage cell type (workaround for SM1x compiler bugs with custom-ops like Max() on signed chars) + using CellT = T; + + /// Shared memory storage layout type (1.5 warps-worth of elements for each warp) + typedef CellT _TempStorage[WARP_SMEM_ELEMENTS]; + + // Alias wrapper allowing storage to be unioned + struct TempStorage : Uninitialized<_TempStorage> {}; + + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + _TempStorage &temp_storage; + unsigned int lane_id; + unsigned int member_mask; + + + /****************************************************************************** + * Construction + ******************************************************************************/ + + /// Constructor + explicit __device__ __forceinline__ WarpScanSmem( + TempStorage &temp_storage) + : + temp_storage(temp_storage.Alias()), + + lane_id(IS_ARCH_WARP ? + LaneId() : + LaneId() % LOGICAL_WARP_THREADS), + + member_mask( + WarpMask(LaneId() / LOGICAL_WARP_THREADS)) + {} + + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + + /// Basic inclusive scan iteration (template unrolled, inductive-case specialization) + template < + bool HAS_IDENTITY, + int STEP, + typename ScanOp> + __device__ __forceinline__ void ScanStep( + T &partial, + ScanOp scan_op, + Int2Type /*step*/) + { + const int OFFSET = 1 << STEP; + + // Share partial into buffer + ThreadStore(&temp_storage[HALF_WARP_THREADS + lane_id], (CellT) partial); + + WARP_SYNC(member_mask); + + // Update partial if addend is in range + if (HAS_IDENTITY || (lane_id >= OFFSET)) + { + T addend = (T) ThreadLoad(&temp_storage[HALF_WARP_THREADS + lane_id - OFFSET]); + partial = scan_op(addend, partial); + } + WARP_SYNC(member_mask); + + ScanStep(partial, scan_op, Int2Type()); + } + + + /// Basic inclusive scan iteration(template unrolled, base-case specialization) + template < + bool HAS_IDENTITY, + typename ScanOp> + __device__ __forceinline__ void ScanStep( + T &/*partial*/, + ScanOp /*scan_op*/, + Int2Type /*step*/) + {} + + + /// Inclusive prefix scan (specialized for summation across primitive types) + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item. + T &output, ///< [out] Calling thread's output item. May be aliased with \p input. + Sum scan_op, ///< [in] Binary scan operator + Int2Type /*is_primitive*/) ///< [in] Marker type indicating whether T is primitive type + { + T identity = 0; + ThreadStore(&temp_storage[lane_id], (CellT) identity); + + WARP_SYNC(member_mask); + + // Iterate scan steps + output = input; + ScanStep(output, scan_op, Int2Type<0>()); + } + + + /// Inclusive prefix scan + template + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item. + T &output, ///< [out] Calling thread's output item. May be aliased with \p input. + ScanOp scan_op, ///< [in] Binary scan operator + Int2Type /*is_primitive*/) ///< [in] Marker type indicating whether T is primitive type + { + // Iterate scan steps + output = input; + ScanStep(output, scan_op, Int2Type<0>()); + } + + + /****************************************************************************** + * Interface + ******************************************************************************/ + + //--------------------------------------------------------------------- + // Broadcast + //--------------------------------------------------------------------- + + /// Broadcast + __device__ __forceinline__ T Broadcast( + T input, ///< [in] The value to broadcast + unsigned int src_lane) ///< [in] Which warp lane is to do the broadcasting + { + if (lane_id == src_lane) + { + ThreadStore(temp_storage, (CellT) input); + } + + WARP_SYNC(member_mask); + + return (T)ThreadLoad(temp_storage); + } + + + //--------------------------------------------------------------------- + // Inclusive operations + //--------------------------------------------------------------------- + + /// Inclusive scan + template + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item. + T &inclusive_output, ///< [out] Calling thread's output item. May be aliased with \p input. + ScanOp scan_op) ///< [in] Binary scan operator + { + InclusiveScan(input, inclusive_output, scan_op, Int2Type::PRIMITIVE>()); + } + + + /// Inclusive scan with aggregate + template + __device__ __forceinline__ void InclusiveScan( + T input, ///< [in] Calling thread's input item. + T &inclusive_output, ///< [out] Calling thread's output item. May be aliased with \p input. + ScanOp scan_op, ///< [in] Binary scan operator + T &warp_aggregate) ///< [out] Warp-wide aggregate reduction of input items. + { + InclusiveScan(input, inclusive_output, scan_op); + + // Retrieve aggregate + ThreadStore(&temp_storage[HALF_WARP_THREADS + lane_id], (CellT) inclusive_output); + + WARP_SYNC(member_mask); + + warp_aggregate = (T) ThreadLoad(&temp_storage[WARP_SMEM_ELEMENTS - 1]); + + WARP_SYNC(member_mask); + } + + + //--------------------------------------------------------------------- + // Get exclusive from inclusive + //--------------------------------------------------------------------- + + /// Update inclusive and exclusive using input and inclusive + template + __device__ __forceinline__ void Update( + T /*input*/, ///< [in] + T &inclusive, ///< [in, out] + T &exclusive, ///< [out] + ScanOpT /*scan_op*/, ///< [in] + IsIntegerT /*is_integer*/) ///< [in] + { + // initial value unknown + ThreadStore(&temp_storage[HALF_WARP_THREADS + lane_id], (CellT) inclusive); + + WARP_SYNC(member_mask); + + exclusive = (T) ThreadLoad(&temp_storage[HALF_WARP_THREADS + lane_id - 1]); + } + + /// Update inclusive and exclusive using input and inclusive (specialized for summation of integer types) + __device__ __forceinline__ void Update( + T input, + T &inclusive, + T &exclusive, + cub::Sum /*scan_op*/, + Int2Type /*is_integer*/) + { + // initial value presumed 0 + exclusive = inclusive - input; + } + + /// Update inclusive and exclusive using initial value using input, inclusive, and initial value + template + __device__ __forceinline__ void Update ( + T /*input*/, + T &inclusive, + T &exclusive, + ScanOpT scan_op, + T initial_value, + IsIntegerT /*is_integer*/) + { + inclusive = scan_op(initial_value, inclusive); + ThreadStore(&temp_storage[HALF_WARP_THREADS + lane_id], (CellT) inclusive); + + WARP_SYNC(member_mask); + + exclusive = (T) ThreadLoad(&temp_storage[HALF_WARP_THREADS + lane_id - 1]); + if (lane_id == 0) + exclusive = initial_value; + } + + /// Update inclusive and exclusive using initial value using input and inclusive (specialized for summation of integer types) + __device__ __forceinline__ void Update ( + T input, + T &inclusive, + T &exclusive, + cub::Sum scan_op, + T initial_value, + Int2Type /*is_integer*/) + { + inclusive = scan_op(initial_value, inclusive); + exclusive = inclusive - input; + } + + + /// Update inclusive, exclusive, and warp aggregate using input and inclusive + template + __device__ __forceinline__ void Update ( + T /*input*/, + T &inclusive, + T &exclusive, + T &warp_aggregate, + ScanOpT /*scan_op*/, + IsIntegerT /*is_integer*/) + { + // Initial value presumed to be unknown or identity (either way our padding is correct) + ThreadStore(&temp_storage[HALF_WARP_THREADS + lane_id], (CellT) inclusive); + + WARP_SYNC(member_mask); + + exclusive = (T) ThreadLoad(&temp_storage[HALF_WARP_THREADS + lane_id - 1]); + warp_aggregate = (T) ThreadLoad(&temp_storage[WARP_SMEM_ELEMENTS - 1]); + } + + /// Update inclusive, exclusive, and warp aggregate using input and inclusive (specialized for summation of integer types) + __device__ __forceinline__ void Update ( + T input, + T &inclusive, + T &exclusive, + T &warp_aggregate, + cub::Sum /*scan_o*/, + Int2Type /*is_integer*/) + { + // Initial value presumed to be unknown or identity (either way our padding is correct) + ThreadStore(&temp_storage[HALF_WARP_THREADS + lane_id], (CellT) inclusive); + + WARP_SYNC(member_mask); + + warp_aggregate = (T) ThreadLoad(&temp_storage[WARP_SMEM_ELEMENTS - 1]); + exclusive = inclusive - input; + } + + /// Update inclusive, exclusive, and warp aggregate using input, inclusive, and initial value + template + __device__ __forceinline__ void Update ( + T /*input*/, + T &inclusive, + T &exclusive, + T &warp_aggregate, + ScanOpT scan_op, + T initial_value, + IsIntegerT /*is_integer*/) + { + // Broadcast warp aggregate + ThreadStore(&temp_storage[HALF_WARP_THREADS + lane_id], (CellT) inclusive); + + WARP_SYNC(member_mask); + + warp_aggregate = (T) ThreadLoad(&temp_storage[WARP_SMEM_ELEMENTS - 1]); + + WARP_SYNC(member_mask); + + // Update inclusive with initial value + inclusive = scan_op(initial_value, inclusive); + + // Get exclusive from exclusive + ThreadStore(&temp_storage[HALF_WARP_THREADS + lane_id - 1], (CellT) inclusive); + + WARP_SYNC(member_mask); + + exclusive = (T) ThreadLoad(&temp_storage[HALF_WARP_THREADS + lane_id - 2]); + + if (lane_id == 0) + exclusive = initial_value; + } + + +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_exchange.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_exchange.cuh new file mode 100644 index 0000000000000000000000000000000000000000..e863f67b103a5e80e78215675c49ec0ac277afb4 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_exchange.cuh @@ -0,0 +1,423 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +/** + * @file + * The cub::WarpExchange class provides [collective](index.html#sec0) + * methods for rearranging data partitioned across a CUDA warp. + */ + +#pragma once + +#include +#include +#include +#include +#include + + +CUB_NAMESPACE_BEGIN + + +enum WarpExchangeAlgorithm +{ + WARP_EXCHANGE_SMEM, + WARP_EXCHANGE_SHUFFLE, +}; + +namespace detail +{ +template +using InternalWarpExchangeImpl = + cub::detail::conditional_t, + WarpExchangeShfl>; +} // namespace detail + +/** + * @brief The WarpExchange class provides [collective](index.html#sec0) + * methods for rearranging data partitioned across a CUDA warp. + * @ingroup WarpModule + * + * @tparam T + * The data type to be exchanged. + * + * @tparam ITEMS_PER_THREAD + * The number of items partitioned onto each thread. + * + * @tparam LOGICAL_WARP_THREADS + * [optional] The number of threads per "logical" warp (may be less + * than the number of hardware warp threads). Default is the warp size of the + * targeted CUDA compute-capability (e.g., 32 threads for SM86). Must be a + * power of two. + * + * @tparam LEGACY_PTX_ARCH + * Unused. + * + * @par Overview + * - It is commonplace for a warp of threads to rearrange data items between + * threads. For example, the global memory accesses prefer patterns where + * data items are "striped" across threads (where consecutive threads access + * consecutive items), yet most warp-wide operations prefer a "blocked" + * partitioning of items across threads (where consecutive items belong to a + * single thread). + * - WarpExchange supports the following types of data exchanges: + * - Transposing between [blocked](index.html#sec5sec3) and + * [striped](index.html#sec5sec3) arrangements + * - Scattering ranked items to a + * [striped arrangement](index.html#sec5sec3) + * + * @par A Simple Example + * @par + * The code snippet below illustrates the conversion from a "blocked" to a + * "striped" arrangement of 64 integer items partitioned across 16 threads where + * each thread owns 4 items. + * @par + * @code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * constexpr int warp_threads = 16; + * constexpr int block_threads = 256; + * constexpr int items_per_thread = 4; + * constexpr int warps_per_block = block_threads / warp_threads; + * const int warp_id = static_cast(threadIdx.x) / warp_threads; + * + * // Specialize WarpExchange for a virtual warp of 16 threads owning 4 integer items each + * using WarpExchangeT = + * cub::WarpExchange; + * + * // Allocate shared memory for WarpExchange + * __shared__ typename WarpExchangeT::TempStorage temp_storage[warps_per_block]; + * + * // Load a tile of data striped across threads + * int thread_data[items_per_thread]; + * // ... + * + * // Collectively exchange data into a blocked arrangement across threads + * WarpExchangeT(temp_storage[warp_id]).StripedToBlocked(thread_data, thread_data); + * @endcode + * @par + * Suppose the set of striped input @p thread_data across the block of threads + * is { [0,16,32,48], [1,17,33,49], ..., [15, 32, 47, 63] }. + * The corresponding output @p thread_data in those threads will be + * { [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [60,61,62,63] }. + */ +template +class WarpExchange : private detail::InternalWarpExchangeImpl< + InputT, + ITEMS_PER_THREAD, + LOGICAL_WARP_THREADS, + WARP_EXCHANGE_ALGORITHM> +{ + using InternalWarpExchange = detail::InternalWarpExchangeImpl< + InputT, + ITEMS_PER_THREAD, + LOGICAL_WARP_THREADS, + WARP_EXCHANGE_ALGORITHM>; + +public: + + /// \smemstorage{WarpExchange} + using TempStorage = typename InternalWarpExchange::TempStorage; + + /*************************************************************************//** + * @name Collective constructors + ****************************************************************************/ + //@{ + + WarpExchange() = delete; + + /** + * @brief Collective constructor using the specified memory allocation as + * temporary storage. + */ + explicit __device__ __forceinline__ + WarpExchange(TempStorage &temp_storage) + : InternalWarpExchange(temp_storage) + { + + } + + //@} end member group + /*************************************************************************//** + * @name Data movement + ****************************************************************************/ + //@{ + + /** + * @brief Transposes data items from blocked arrangement to + * striped arrangement. + * + * @par + * @smemwarpreuse + * + * @par Snippet + * The code snippet below illustrates the conversion from a "blocked" to a + * "striped" arrangement of 64 integer items partitioned across 16 threads + * where each thread owns 4 items. + * @par + * @code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * constexpr int warp_threads = 16; + * constexpr int block_threads = 256; + * constexpr int items_per_thread = 4; + * constexpr int warps_per_block = block_threads / warp_threads; + * const int warp_id = static_cast(threadIdx.x) / warp_threads; + * + * // Specialize WarpExchange for a virtual warp of 16 threads owning 4 integer items each + * using WarpExchangeT = cub::WarpExchange; + * + * // Allocate shared memory for WarpExchange + * __shared__ typename WarpExchangeT::TempStorage temp_storage[warps_per_block]; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[items_per_thread]; + * // ... + * + * // Collectively exchange data into a striped arrangement across threads + * WarpExchangeT(temp_storage[warp_id]).BlockedToStriped(thread_data, thread_data); + * @endcode + * @par + * Suppose the set of striped input @p thread_data across the block of threads + * is { [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [60,61,62,63] }. + * The corresponding output @p thread_data in those threads will be + * { [0,16,32,48], [1,17,33,49], ..., [15, 32, 47, 63] }. + * + * @param[in] input_items + * Items to exchange, converting between blocked and + * striped arrangements. + * + * @param[out] output_items + * Items from exchange, converting between striped and + * blocked arrangements. May be aliased to @p input_items. + */ + template + __device__ __forceinline__ void + BlockedToStriped(const InputT (&input_items)[ITEMS_PER_THREAD], + OutputT (&output_items)[ITEMS_PER_THREAD]) + { + InternalWarpExchange::BlockedToStriped(input_items, output_items); + } + + /** + * @brief Transposes data items from striped arrangement to + * blocked arrangement. + * + * @par + * @smemwarpreuse + * + * @par Snippet + * The code snippet below illustrates the conversion from a "striped" to a + * "blocked" arrangement of 64 integer items partitioned across 16 threads + * where each thread owns 4 items. + * @par + * @code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * constexpr int warp_threads = 16; + * constexpr int block_threads = 256; + * constexpr int items_per_thread = 4; + * constexpr int warps_per_block = block_threads / warp_threads; + * const int warp_id = static_cast(threadIdx.x) / warp_threads; + * + * // Specialize WarpExchange for a virtual warp of 16 threads owning 4 integer items each + * using WarpExchangeT = cub::WarpExchange; + * + * // Allocate shared memory for WarpExchange + * __shared__ typename WarpExchangeT::TempStorage temp_storage[warps_per_block]; + * + * // Load a tile of data striped across threads + * int thread_data[items_per_thread]; + * // ... + * + * // Collectively exchange data into a blocked arrangement across threads + * WarpExchangeT(temp_storage[warp_id]).StripedToBlocked(thread_data, thread_data); + * @endcode + * @par + * Suppose the set of striped input @p thread_data across the block of threads + * is { [0,16,32,48], [1,17,33,49], ..., [15, 32, 47, 63] }. + * The corresponding output @p thread_data in those threads will be + * { [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [60,61,62,63] }. + * + * @param[in] input_items + * Items to exchange + * + * @param[out] output_items + * Items from exchange. May be aliased to @p input_items. + */ + template + __device__ __forceinline__ void + StripedToBlocked(const InputT (&input_items)[ITEMS_PER_THREAD], + OutputT (&output_items)[ITEMS_PER_THREAD]) + { + InternalWarpExchange::StripedToBlocked(input_items, output_items); + } + + /** + * @brief Exchanges valid data items annotated by rank + * into striped arrangement. + * + * @par + * @smemwarpreuse + * + * @par Snippet + * The code snippet below illustrates the conversion from a "scatter" to a + * "striped" arrangement of 64 integer items partitioned across 16 threads + * where each thread owns 4 items. + * @par + * @code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * constexpr int warp_threads = 16; + * constexpr int block_threads = 256; + * constexpr int items_per_thread = 4; + * constexpr int warps_per_block = block_threads / warp_threads; + * const int warp_id = static_cast(threadIdx.x) / warp_threads; + * + * // Specialize WarpExchange for a virtual warp of 16 threads owning 4 integer items each + * using WarpExchangeT = cub::WarpExchange; + * + * // Allocate shared memory for WarpExchange + * __shared__ typename WarpExchangeT::TempStorage temp_storage[warps_per_block]; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_data[items_per_thread]; + * int thread_ranks[items_per_thread]; + * // ... + * + * // Collectively exchange data into a striped arrangement across threads + * WarpExchangeT(temp_storage[warp_id]).ScatterToStriped( + * thread_data, thread_ranks); + * @endcode + * @par + * Suppose the set of input @p thread_data across the block of threads + * is `{ [0,1,2,3], [4,5,6,7], ..., [60,61,62,63] }`, and the set of + * @p thread_ranks is `{ [63,62,61,60], ..., [7,6,5,4], [3,2,1,0] }`. The + * corresponding output @p thread_data in those threads will be + * `{ [63, 47, 31, 15], [62, 46, 30, 14], ..., [48, 32, 16, 0] }`. + * + * @tparam OffsetT [inferred] Signed integer type for local offsets + * + * @param[in,out] items Items to exchange + * @param[in] ranks Corresponding scatter ranks + */ + template + __device__ __forceinline__ void + ScatterToStriped(InputT (&items)[ITEMS_PER_THREAD], + OffsetT (&ranks)[ITEMS_PER_THREAD]) + { + InternalWarpExchange::ScatterToStriped(items, ranks); + } + + /** + * @brief Exchanges valid data items annotated by rank + * into striped arrangement. + * + * @par + * @smemwarpreuse + * + * @par Snippet + * The code snippet below illustrates the conversion from a "scatter" to a + * "striped" arrangement of 64 integer items partitioned across 16 threads + * where each thread owns 4 items. + * @par + * @code + * #include // or equivalently + * + * __global__ void ExampleKernel(int *d_data, ...) + * { + * constexpr int warp_threads = 16; + * constexpr int block_threads = 256; + * constexpr int items_per_thread = 4; + * constexpr int warps_per_block = block_threads / warp_threads; + * const int warp_id = static_cast(threadIdx.x) / warp_threads; + * + * // Specialize WarpExchange for a virtual warp of 16 threads owning 4 integer items each + * using WarpExchangeT = cub::WarpExchange; + * + * // Allocate shared memory for WarpExchange + * __shared__ typename WarpExchangeT::TempStorage temp_storage[warps_per_block]; + * + * // Obtain a segment of consecutive items that are blocked across threads + * int thread_input[items_per_thread]; + * int thread_ranks[items_per_thread]; + * // ... + * + * // Collectively exchange data into a striped arrangement across threads + * int thread_output[items_per_thread]; + * WarpExchangeT(temp_storage[warp_id]).ScatterToStriped( + * thread_input, thread_output, thread_ranks); + * @endcode + * @par + * Suppose the set of input @p thread_input across the block of threads + * is `{ [0,1,2,3], [4,5,6,7], ..., [60,61,62,63] }`, and the set of + * @p thread_ranks is `{ [63,62,61,60], ..., [7,6,5,4], [3,2,1,0] }`. The + * corresponding @p thread_output in those threads will be + * `{ [63, 47, 31, 15], [62, 46, 30, 14], ..., [48, 32, 16, 0] }`. + * + * @tparam OffsetT [inferred] Signed integer type for local offsets + * + * @param[in] input_items + * Items to exchange + * + * @param[out] output_items + * Items from exchange. May be aliased to @p input_items. + * + * @param[in] ranks + * Corresponding scatter ranks + */ + template + __device__ __forceinline__ void + ScatterToStriped(const InputT (&input_items)[ITEMS_PER_THREAD], + OutputT (&output_items)[ITEMS_PER_THREAD], + OffsetT (&ranks)[ITEMS_PER_THREAD]) + { + InternalWarpExchange::ScatterToStriped(input_items, output_items, ranks); + } + + //@} end member group +}; + + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_load.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_load.cuh new file mode 100644 index 0000000000000000000000000000000000000000..df4ea98fcced030cb285c93b015e18abf7b39388 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_load.cuh @@ -0,0 +1,638 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +//! @file Operations for reading linear tiles of data into the CUDA warp. + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include + +CUB_NAMESPACE_BEGIN + +//! @rst +//! ``cub::WarpLoadAlgorithm`` enumerates alternative algorithms for :cpp:struct:`cub::WarpLoad` to +//! read a linear segment of data from memory into a CUDA warp. +//! @endrst +enum WarpLoadAlgorithm +{ + //! @rst + //! Overview + //! ++++++++++++++++++++++++++ + //! + //! A :ref:`blocked arrangement ` of data is read directly from memory. + //! + //! Performance Considerations + //! ++++++++++++++++++++++++++ + //! + //! The utilization of memory transactions (coalescing) decreases as the + //! access stride between threads increases (i.e., the number items per thread). + //! @endrst + WARP_LOAD_DIRECT, + + //! @rst + //! Overview + //! ++++++++++++++++++++++++++ + //! + //! A :ref:`striped arrangement ` of data is read directly from memory. + //! + //! Performance Considerations + //! ++++++++++++++++++++++++++ + //! + //! The utilization of memory transactions (coalescing) doesn't depend on + //! the number of items per thread. + //! @endrst + WARP_LOAD_STRIPED, + + //! @rst + //! Overview + //! ++++++++++++++++++++++++++ + //! + //! A :ref:`blocked arrangement ` of data is read from memory using + //! CUDA's built-in vectorized loads as a coalescing optimization. + //! For example, ``ld.global.v4.s32`` instructions will be generated when ``T = int`` and + //! ``ITEMS_PER_THREAD % 4 == 0``. + //! + //! Performance Considerations + //! ++++++++++++++++++++++++++ + //! + //! - The utilization of memory transactions (coalescing) remains high until the the + //! access stride between threads (i.e., the number items per thread) exceeds the + //! maximum vector load width (typically 4 items or 64B, whichever is lower). + //! - The following conditions will prevent vectorization and loading will fall + //! back to cub::WARP_LOAD_DIRECT: + //! + //! - ``ITEMS_PER_THREAD`` is odd + //! - The ``InputIteratorT`` is not a simple pointer type + //! - The block input offset is not quadword-aligned + //! - The data type ``T`` is not a built-in primitive or CUDA vector type + //! (e.g., ``short``, ``int2``, ``double``, ``float2``, etc.) + //! @endrst + WARP_LOAD_VECTORIZE, + + //! @rst + //! Overview + //! ++++++++++++++++++++++++++ + //! + //! A :ref:`striped arrangement ` of data is read efficiently from + //! memory and then locally transposed into a + //! :ref:`blocked arrangement `. + //! + //! Performance Considerations + //! ++++++++++++++++++++++++++ + //! + //! - The utilization of memory transactions (coalescing) remains high + //! regardless of items loaded per thread. + //! - The local reordering incurs slightly longer latencies and throughput than the direct + //! ``cub::WARP_LOAD_DIRECT`` and ``cub::WARP_LOAD_VECTORIZE`` alternatives. + //! @endrst + WARP_LOAD_TRANSPOSE +}; + +//! @rst +//! The WarpLoad class provides :ref:`collective ` data movement methods for +//! loading a linear segment of items from memory into a +//! :ref:`blocked arrangement ` across a CUDA thread warp. +//! +//! Overview +//! ++++++++++++++++ +//! +//! - The WarpLoad class provides a single data movement abstraction that can be +//! specialized to implement different cub::WarpLoadAlgorithm strategies. This +//! facilitates different performance policies for different architectures, data +//! types, granularity sizes, etc. +//! - WarpLoad can be optionally specialized by different data movement strategies: +//! +//! #. :cpp:enumerator:`cub::WARP_LOAD_DIRECT`: +//! a :ref:`blocked arrangement ` of data is read directly from +//! memory. +//! #. :cpp:enumerator:`cub::WARP_LOAD_STRIPED`: +//! a :ref:`striped arrangement ` of data is read directly from +//! memory. +//! #. :cpp:enumerator:`cub::WARP_LOAD_VECTORIZE`: +//! a :ref:`blocked arrangement ` of data is read directly from +//! memory using CUDA's built-in vectorized loads as a coalescing optimization. +//! #. :cpp:enumerator:`cub::WARP_LOAD_TRANSPOSE`: +//! a :ref:`striped arrangement ` of data is read directly from +//! memory and is then locally transposed into a +//! :ref:`blocked arrangement `. +//! +//! A Simple Example +//! ++++++++++++++++ +//! +//! The code snippet below illustrates the loading of a linear segment of 64 +//! integers into a "blocked" arrangement across 16 threads where each thread +//! owns 4 consecutive items. The load is specialized for ``WARP_LOAD_TRANSPOSE``, +//! meaning memory references are efficiently coalesced using a warp-striped access +//! pattern (after which items are locally reordered among threads). +//! +//! .. code-block:: c++ +//! +//! #include // or equivalently +//! +//! __global__ void ExampleKernel(int *d_data, ...) +//! { +//! constexpr int warp_threads = 16; +//! constexpr int block_threads = 256; +//! constexpr int items_per_thread = 4; +//! +//! // Specialize WarpLoad for a warp of 16 threads owning 4 integer items each +//! using WarpLoadT = WarpLoad; +//! +//! constexpr int warps_in_block = block_threads / warp_threads; +//! constexpr int tile_size = items_per_thread * warp_threads; +//! const int warp_id = static_cast(threadIdx.x) / warp_threads; +//! +//! // Allocate shared memory for WarpLoad +//! __shared__ typename WarpLoadT::TempStorage temp_storage[warps_in_block]; +//! +//! // Load a segment of consecutive items that are blocked across threads +//! int thread_data[items_per_thread]; +//! WarpLoadT(temp_storage[warp_id]).Load(d_data + warp_id * tile_size, +//! thread_data); +//! +//! Suppose the input ``d_data`` is ``0, 1, 2, 3, 4, 5, ...``. +//! The set of ``thread_data`` across the first logical warp of threads in those +//! threads will be: ``{ [0,1,2,3], [4,5,6,7], ..., [60,61,62,63] }``. +//! @endrst +//! +//! @tparam InputT +//! The data type to read into (which must be convertible from the input +//! iterator's value type). +//! +//! @tparam ITEMS_PER_THREAD +//! The number of consecutive items partitioned onto each thread. +//! +//! @tparam ALGORITHM +//! [optional] cub::WarpLoadAlgorithm tuning policy. +//! default: cub::WARP_LOAD_DIRECT. +//! +//! @tparam LOGICAL_WARP_THREADS +//! [optional] The number of threads per "logical" warp (may be less +//! than the number of hardware warp threads). Default is the warp size of the +//! targeted CUDA compute-capability (e.g., 32 threads for SM86). Must be a +//! power of two. +//! +//! @tparam LEGACY_PTX_ARCH +//! Unused. +template +class WarpLoad +{ + constexpr static bool IS_ARCH_WARP = LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0); + + static_assert(PowerOfTwo::VALUE, + "LOGICAL_WARP_THREADS must be a power of two"); + +private: + /***************************************************************************** + * Algorithmic variants + ****************************************************************************/ + + /// Load helper + template + struct LoadInternal; + + template + struct LoadInternal + { + using TempStorage = NullType; + + int linear_tid; + + __device__ __forceinline__ LoadInternal(TempStorage & /*temp_storage*/, int linear_tid) + : linear_tid(linear_tid) + {} + + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD]) + { + LoadDirectBlocked(linear_tid, block_itr, items); + } + + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD], + int valid_items) + { + LoadDirectBlocked(linear_tid, block_itr, items, valid_items); + } + + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD], + int valid_items, + DefaultT oob_default) + { + LoadDirectBlocked(linear_tid, block_itr, items, valid_items, oob_default); + } + }; + + template + struct LoadInternal + { + using TempStorage = NullType; + + int linear_tid; + + __device__ __forceinline__ LoadInternal(TempStorage & /*temp_storage*/, int linear_tid) + : linear_tid(linear_tid) + {} + + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD]) + { + LoadDirectStriped(linear_tid, block_itr, items); + } + + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD], + int valid_items) + { + LoadDirectStriped(linear_tid, block_itr, items, valid_items); + } + + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD], + int valid_items, + DefaultT oob_default) + { + LoadDirectStriped(linear_tid, + block_itr, + items, + valid_items, + oob_default); + } + }; + + template + struct LoadInternal + { + using TempStorage = NullType; + + int linear_tid; + + __device__ __forceinline__ LoadInternal(TempStorage & /*temp_storage*/, int linear_tid) + : linear_tid(linear_tid) + {} + + template + __device__ __forceinline__ void Load(InputT *block_ptr, InputT (&items)[ITEMS_PER_THREAD]) + { + InternalLoadDirectBlockedVectorized(linear_tid, block_ptr, items); + } + + template + __device__ __forceinline__ void Load(const InputT *block_ptr, InputT (&items)[ITEMS_PER_THREAD]) + { + InternalLoadDirectBlockedVectorized(linear_tid, block_ptr, items); + } + + template + __device__ __forceinline__ void + Load(CacheModifiedInputIterator block_itr, + InputT (&items)[ITEMS_PER_THREAD]) + { + InternalLoadDirectBlockedVectorized(linear_tid, block_itr.ptr, items); + } + + template + __device__ __forceinline__ void Load(_InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD]) + { + LoadDirectBlocked(linear_tid, block_itr, items); + } + + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD], + int valid_items) + { + LoadDirectBlocked(linear_tid, block_itr, items, valid_items); + } + + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD], + int valid_items, + DefaultT oob_default) + { + LoadDirectBlocked(linear_tid, block_itr, items, valid_items, oob_default); + } + }; + + template + struct LoadInternal + { + using WarpExchangeT = WarpExchange; + + struct _TempStorage : WarpExchangeT::TempStorage + {}; + + struct TempStorage : Uninitialized<_TempStorage> + {}; + + _TempStorage &temp_storage; + + int linear_tid; + + __device__ __forceinline__ LoadInternal(TempStorage &temp_storage, int linear_tid) + : temp_storage(temp_storage.Alias()) + , linear_tid(linear_tid) + {} + + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD]) + { + LoadDirectStriped(linear_tid, block_itr, items); + WarpExchangeT(temp_storage).StripedToBlocked(items, items); + } + + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD], + int valid_items) + { + LoadDirectStriped(linear_tid, block_itr, items, valid_items); + WarpExchangeT(temp_storage).StripedToBlocked(items, items); + } + + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD], + int valid_items, + DefaultT oob_default) + { + LoadDirectStriped(linear_tid, + block_itr, + items, + valid_items, + oob_default); + WarpExchangeT(temp_storage).StripedToBlocked(items, items); + } + }; + + /***************************************************************************** + * Type definitions + ****************************************************************************/ + + /// Internal load implementation to use + using InternalLoad = LoadInternal; + + /// Shared memory storage layout type + using _TempStorage = typename InternalLoad::TempStorage; + + /***************************************************************************** + * Utility methods + ****************************************************************************/ + + /// Internal storage allocator + __device__ __forceinline__ _TempStorage &PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + /***************************************************************************** + * Thread fields + ****************************************************************************/ + + /// Thread reference to shared storage + _TempStorage &temp_storage; + + /// Linear thread-id + int linear_tid; + +public: + /// @smemstorage{WarpLoad} + struct TempStorage : Uninitialized<_TempStorage> + {}; + + //! @name Collective constructors + //! @{ + + //! @brief Collective constructor using a private static allocation of + //! shared memory as temporary storage. + __device__ __forceinline__ WarpLoad() + : temp_storage(PrivateStorage()) + , linear_tid(IS_ARCH_WARP ? LaneId() : (LaneId() % LOGICAL_WARP_THREADS)) + {} + + //! @brief Collective constructor using the specified memory allocation as + //! temporary storage. + __device__ __forceinline__ WarpLoad(TempStorage &temp_storage) + : temp_storage(temp_storage.Alias()) + , linear_tid(IS_ARCH_WARP ? LaneId() : (LaneId() % LOGICAL_WARP_THREADS)) + {} + + //! @} end member group + //! @name Data movement + //! @{ + + //! @rst + //! Load a linear segment of items from memory. + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! .. code-block:: c++ + //! + //! #include // or equivalently + //! + //! __global__ void ExampleKernel(int *d_data, ...) + //! { + //! constexpr int warp_threads = 16; + //! constexpr int block_threads = 256; + //! constexpr int items_per_thread = 4; + //! + //! // Specialize WarpLoad for a warp of 16 threads owning 4 integer items each + //! using WarpLoadT = WarpLoad; + //! + //! constexpr int warps_in_block = block_threads / warp_threads; + //! constexpr int tile_size = items_per_thread * warp_threads; + //! const int warp_id = static_cast(threadIdx.x) / warp_threads; + //! + //! // Allocate shared memory for WarpLoad + //! __shared__ typename WarpLoadT::TempStorage temp_storage[warps_in_block]; + //! + //! // Load a segment of consecutive items that are blocked across threads + //! int thread_data[items_per_thread]; + //! WarpLoadT(temp_storage[warp_id]).Load(d_data + warp_id * tile_size, + //! thread_data); + //! + //! Suppose the input ``d_data`` is ``0, 1, 2, 3, 4, 5, ...``, + //! The set of ``thread_data`` across the first logical warp of threads in those + //! threads will be: ``{ [0,1,2,3], [4,5,6,7], ..., [60,61,62,63] }``. + //! @endrst + //! + //! @param[in] block_itr The thread block's base input iterator for loading from + //! @param[out] items Data to load + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, InputT (&items)[ITEMS_PER_THREAD]) + { + InternalLoad(temp_storage, linear_tid).Load(block_itr, items); + } + + //! @rst + //! Load a linear segment of items from memory, guarded by range. + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! .. code-block:: c++ + //! + //! #include // or equivalently + //! + //! __global__ void ExampleKernel(int *d_data, int valid_items, ...) + //! { + //! constexpr int warp_threads = 16; + //! constexpr int block_threads = 256; + //! constexpr int items_per_thread = 4; + //! + //! // Specialize WarpLoad for a warp of 16 threads owning 4 integer items each + //! using WarpLoadT = WarpLoad; + //! + //! constexpr int warps_in_block = block_threads / warp_threads; + //! constexpr int tile_size = items_per_thread * warp_threads; + //! const int warp_id = static_cast(threadIdx.x) / warp_threads; + //! + //! // Allocate shared memory for WarpLoad + //! __shared__ typename WarpLoadT::TempStorage temp_storage[warps_in_block]; + //! + //! // Load a segment of consecutive items that are blocked across threads + //! int thread_data[items_per_thread]; + //! WarpLoadT(temp_storage[warp_id]).Load(d_data + warp_id * tile_size, + //! thread_data, + //! valid_items); + //! + //! Suppose the input ``d_data`` is ``0, 1, 2, 3, 4, 5, ...`` and ``valid_items`` is ``5``. + //! The set of ``thread_data`` across the first logical warp of threads in those threads will be: + //! ``{ [0,1,2,3], [4,?,?,?], ..., [?,?,?,?] }`` with only the first two threads being unmasked to + //! load portions of valid data (and other items remaining unassigned). + //! @endrst + //! + //! @param[in] block_itr The thread block's base input iterator for loading from + //! @param[out] items Data to load + //! @param[in] valid_items Number of valid items to load + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD], + int valid_items) + { + InternalLoad(temp_storage, linear_tid).Load(block_itr, items, valid_items); + } + + //! @rst + //! Load a linear segment of items from memory, guarded by range. + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! .. code-block:: c++ + //! + //! #include // or equivalently + //! + //! __global__ void ExampleKernel(int *d_data, int valid_items, ...) + //! { + //! constexpr int warp_threads = 16; + //! constexpr int block_threads = 256; + //! constexpr int items_per_thread = 4; + //! + //! // Specialize WarpLoad for a warp of 16 threads owning 4 integer items each + //! using WarpLoadT = WarpLoad; + //! + //! constexpr int warps_in_block = block_threads / warp_threads; + //! constexpr int tile_size = items_per_thread * warp_threads; + //! const int warp_id = static_cast(threadIdx.x) / warp_threads; + //! + //! // Allocate shared memory for WarpLoad + //! __shared__ typename WarpLoadT::TempStorage temp_storage[warps_in_block]; + //! + //! // Load a segment of consecutive items that are blocked across threads + //! int thread_data[items_per_thread]; + //! WarpLoadT(temp_storage[warp_id]).Load(d_data + warp_id * tile_size, + //! thread_data, + //! valid_items, + //! -1); + //! + //! Suppose the input ``d_data`` is ``0, 1, 2, 3, 4, 5, ...``, ``valid_items`` is ``5``, and the + //! out-of-bounds default is ``-1``. The set of ``thread_data`` across the first logical warp of + //! threads in those threads will be: ``{ [0,1,2,3], [4,-1,-1,-1], ..., [-1,-1,-1,-1] }`` with + //! only the first two threads being unmasked to load portions of valid data (and other items + //! are assigned ``-1``). + //! @endrst + //! + //! @param[in] block_itr The thread block's base input iterator for loading from + //! @param[out] items Data to load + //! @param[in] valid_items Number of valid items to load + //! @param[in] oob_default Default value to assign out-of-bound items + template + __device__ __forceinline__ void Load(InputIteratorT block_itr, + InputT (&items)[ITEMS_PER_THREAD], + int valid_items, + DefaultT oob_default) + { + InternalLoad(temp_storage, linear_tid).Load(block_itr, items, valid_items, oob_default); + } + + //! @} end member group +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_merge_sort.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_merge_sort.cuh new file mode 100644 index 0000000000000000000000000000000000000000..59892e925276f74534105dd47a35016f18650175 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_merge_sort.cuh @@ -0,0 +1,159 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +//! @rst +//! The WarpMergeSort class provides methods for sorting items partitioned across a CUDA warp +//! using a merge sorting method. +//! +//! Overview +//! ++++++++++++++++ +//! +//! WarpMergeSort arranges items into ascending order using a comparison +//! functor with less-than semantics. Merge sort can handle arbitrary types +//! and comparison functors. +//! +//! A Simple Example +//! ++++++++++++++++ +//! +//! The code snippet below illustrates a sort of 64 integer keys that are +//! partitioned across 16 threads where each thread owns 4 consecutive items. +//! +//! .. code-block:: c++ +//! +//! #include // or equivalently +//! +//! struct CustomLess +//! { +//! template +//! __device__ bool operator()(const DataType &lhs, const DataType &rhs) +//! { +//! return lhs < rhs; +//! } +//! }; +//! +//! __global__ void ExampleKernel(...) +//! { +//! constexpr int warp_threads = 16; +//! constexpr int block_threads = 256; +//! constexpr int items_per_thread = 4; +//! constexpr int warps_per_block = block_threads / warp_threads; +//! const int warp_id = static_cast(threadIdx.x) / warp_threads; +//! +//! // Specialize WarpMergeSort for a virtual warp of 16 threads +//! // owning 4 integer items each +//! using WarpMergeSortT = +//! cub::WarpMergeSort; +//! +//! // Allocate shared memory for WarpMergeSort +//! __shared__ typename WarpMergeSortT::TempStorage temp_storage[warps_per_block]; +//! +//! // Obtain a segment of consecutive items that are blocked across threads +//! int thread_keys[items_per_thread]; +//! // ... +//! +//! WarpMergeSortT(temp_storage[warp_id]).Sort(thread_keys, CustomLess()); +//! // ... +//! } +//! +//! Suppose the set of input ``thread_keys`` across a warp of threads is +//! ``{ [0,64,1,63], [2,62,3,61], [4,60,5,59], ..., [31,34,32,33] }``. +//! The corresponding output ``thread_keys`` in those threads will be +//! ``{ [0,1,2,3], [4,5,6,7], [8,9,10,11], ..., [31,32,33,34] }``. +//! @endrst +//! +//! @tparam KeyT +//! Key type +//! +//! @tparam ITEMS_PER_THREAD +//! The number of items per thread +//! +//! @tparam LOGICAL_WARP_THREADS +//! [optional] The number of threads per "logical" warp (may be less +//! than the number of hardware warp threads). Default is the warp size of the +//! targeted CUDA compute-capability (e.g., 32 threads for SM86). Must be a +//! power of two. +//! +//! @tparam ValueT +//! [optional] Value type (default: cub::NullType, which indicates a +//! keys-only sort) +//! +//! @tparam LEGACY_PTX_ARCH +//! Unused. +//! +template +class WarpMergeSort + : public BlockMergeSortStrategy< + KeyT, + ValueT, + LOGICAL_WARP_THREADS, + ITEMS_PER_THREAD, + WarpMergeSort> +{ +private: + constexpr static bool IS_ARCH_WARP = LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0); + constexpr static bool KEYS_ONLY = std::is_same::value; + constexpr static int TILE_SIZE = ITEMS_PER_THREAD * LOGICAL_WARP_THREADS; + + using BlockMergeSortStrategyT = + BlockMergeSortStrategy; + + const unsigned int warp_id; + const unsigned int member_mask; + +public: + WarpMergeSort() = delete; + + __device__ __forceinline__ + WarpMergeSort(typename BlockMergeSortStrategyT::TempStorage &temp_storage) + : BlockMergeSortStrategyT(temp_storage, + IS_ARCH_WARP ? LaneId() : (LaneId() % LOGICAL_WARP_THREADS)) + , warp_id(IS_ARCH_WARP ? 0 : (LaneId() / LOGICAL_WARP_THREADS)) + , member_mask(WarpMask(warp_id)) + {} + + __device__ __forceinline__ unsigned int get_member_mask() const { return member_mask; } + +private: + __device__ __forceinline__ void SyncImplementation() const { WARP_SYNC(member_mask); } + + friend BlockMergeSortStrategyT; +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_reduce.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_reduce.cuh new file mode 100644 index 0000000000000000000000000000000000000000..2901f56bbcc4c6fc4fba561d92ffb1a5f4571064 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_reduce.cuh @@ -0,0 +1,747 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +//! @file +//! @rst +//! The ``cub::WarpReduce`` class provides :ref:`collective ` methods for +//! computing a parallel reduction of items partitioned across a CUDA thread warp. +//! @endrst + +#pragma once + +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +//! @rst +//! The ``WarpReduce`` class provides :ref:`collective ` methods for +//! computing a parallel reduction of items partitioned across a CUDA thread warp. +//! +//! .. image:: ../img/warp_reduce_logo.png +//! :align: center +//! +//! Overview +//! ++++++++++++++++++++++++++ +//! +//! - A `reduction `__ (or *fold*) +//! uses a binary combining operator to compute a single aggregate from a list of input elements. +//! - Supports "logical" warps smaller than the physical warp size (e.g., logical warps of 8 +//! threads) +//! - The number of entrant threads must be an multiple of ``LOGICAL_WARP_THREADS`` +//! +//! Performance Considerations +//! ++++++++++++++++++++++++++ +//! +//! - Uses special instructions when applicable (e.g., warp ``SHFL`` instructions) +//! - Uses synchronization-free communication between warp lanes when applicable +//! - Incurs zero bank conflicts for most types +//! - Computation is slightly more efficient (i.e., having lower instruction overhead) for: +//! +//! - Summation (**vs.** generic reduction) +//! - The architecture's warp size is a whole multiple of ``LOGICAL_WARP_THREADS`` +//! +//! Simple Examples +//! ++++++++++++++++++++++++++ +//! +//! @warpcollective{WarpReduce} +//! +//! The code snippet below illustrates four concurrent warp sum reductions within a block of +//! 128 threads (one per each of the 32-thread warps). +//! +//! .. code-block:: c++ +//! +//! #include +//! +//! __global__ void ExampleKernel(...) +//! { +//! // Specialize WarpReduce for type int +//! typedef cub::WarpReduce WarpReduce; +//! +//! // Allocate WarpReduce shared memory for 4 warps +//! __shared__ typename WarpReduce::TempStorage temp_storage[4]; +//! +//! // Obtain one input item per thread +//! int thread_data = ... +//! +//! // Return the warp-wide sums to each lane0 (threads 0, 32, 64, and 96) +//! int warp_id = threadIdx.x / 32; +//! int aggregate = WarpReduce(temp_storage[warp_id]).Sum(thread_data); +//! +//! Suppose the set of input ``thread_data`` across the block of threads is +//! ``{0, 1, 2, 3, ..., 127}``. The corresponding output ``aggregate`` in threads 0, 32, 64, and 96 +//! will be ``496``, ``1520``, ``2544``, and ``3568``, respectively +//! (and is undefined in other threads). +//! +//! The code snippet below illustrates a single warp sum reduction within a block of +//! 128 threads. +//! +//! .. code-block:: c++ +//! +//! #include +//! +//! __global__ void ExampleKernel(...) +//! { +//! // Specialize WarpReduce for type int +//! typedef cub::WarpReduce WarpReduce; +//! +//! // Allocate WarpReduce shared memory for one warp +//! __shared__ typename WarpReduce::TempStorage temp_storage; +//! ... +//! +//! // Only the first warp performs a reduction +//! if (threadIdx.x < 32) +//! { +//! // Obtain one input item per thread +//! int thread_data = ... +//! +//! // Return the warp-wide sum to lane0 +//! int aggregate = WarpReduce(temp_storage).Sum(thread_data); +//! +//! Suppose the set of input ``thread_data`` across the warp of threads is +//! ``{0, 1, 2, 3, ..., 31}``. The corresponding output ``aggregate`` in thread0 will be ``496`` +//! (and is undefined in other threads). +//! @endrst +//! +//! @tparam T +//! The reduction input/output element type +//! +//! @tparam LOGICAL_WARP_THREADS +//! [optional] The number of threads per "logical" warp (may be less than the number of +//! hardware warp threads). Default is the warp size of the targeted CUDA compute-capability +//! (e.g., 32 threads for SM20). +//! +//! @tparam LEGACY_PTX_ARCH +//! [optional] Unused. +template +class WarpReduce +{ +private: + /****************************************************************************** + * Constants and type definitions + ******************************************************************************/ + + enum + { + /// Whether the logical warp size and the PTX warp size coincide + IS_ARCH_WARP = (LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0)), + + /// Whether the logical warp size is a power-of-two + IS_POW_OF_TWO = PowerOfTwo::VALUE, + }; + +public: +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document + + /// Internal specialization. + /// Use SHFL-based reduction if LOGICAL_WARP_THREADS is a power-of-two + using InternalWarpReduce = cub::detail::conditional_t, + WarpReduceSmem>; + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +private: + /// Shared memory storage layout type for WarpReduce + using _TempStorage = typename InternalWarpReduce::TempStorage; + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + + /****************************************************************************** + * Utility methods + ******************************************************************************/ + +public: + /// \smemstorage{WarpReduce} + struct TempStorage : Uninitialized<_TempStorage> + {}; + + //! @name Collective constructors + //! @{ + + //! @rst + //! Collective constructor using the specified memory allocation as temporary storage. + //! Logical warp and lane identifiers are constructed from ``threadIdx.x``. + //! @endrst + //! + //! @param[in] temp_storage Reference to memory allocation having layout type TempStorage + __device__ __forceinline__ WarpReduce(TempStorage &temp_storage) + : temp_storage(temp_storage.Alias()) + {} + + //! @} end member group + //! @name Summation reductions + //! @{ + + //! @rst + //! Computes a warp-wide sum in the calling warp. + //! The output is valid in warp *lane*\ :sub:`0`. + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp sum reductions within a block of + //! 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpReduce for type int + //! typedef cub::WarpReduce WarpReduce; + //! + //! // Allocate WarpReduce shared memory for 4 warps + //! __shared__ typename WarpReduce::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Return the warp-wide sums to each lane0 + //! int warp_id = threadIdx.x / 32; + //! int aggregate = WarpReduce(temp_storage[warp_id]).Sum(thread_data); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{0, 1, 2, 3, ..., 127}``. + //! The corresponding output ``aggregate`` in threads 0, 32, 64, and 96 will ``496``, ``1520``, + //! ``2544``, and ``3568``, respectively (and is undefined in other threads). + //! @endrst + //! + //! @param[in] input Calling thread's input + __device__ __forceinline__ T Sum(T input) + { + return InternalWarpReduce(temp_storage) + .template Reduce(input, LOGICAL_WARP_THREADS, cub::Sum()); + } + + //! @rst + //! Computes a partially-full warp-wide sum in the calling warp. + //! The output is valid in warp *lane*\ :sub:`0`. + //! + //! All threads across the calling warp must agree on the same value for ``valid_items``. + //! Otherwise the result is undefined. + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates a sum reduction within a single, partially-full + //! block of 32 threads (one warp). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(int *d_data, int valid_items) + //! { + //! // Specialize WarpReduce for type int + //! typedef cub::WarpReduce WarpReduce; + //! + //! // Allocate WarpReduce shared memory for one warp + //! __shared__ typename WarpReduce::TempStorage temp_storage; + //! + //! // Obtain one input item per thread if in range + //! int thread_data; + //! if (threadIdx.x < valid_items) + //! thread_data = d_data[threadIdx.x]; + //! + //! // Return the warp-wide sums to each lane0 + //! int aggregate = WarpReduce(temp_storage).Sum( + //! thread_data, valid_items); + //! + //! Suppose the input ``d_data`` is ``{0, 1, 2, 3, 4, ...`` and ``valid_items`` is ``4``. + //! The corresponding output ``aggregate`` in *lane*\ :sub:`0` is ``6`` + //! (and is undefined in other threads). + //! @endrst + //! + //! @param[in] input + //! Calling thread's input + //! + //! @param[in] valid_items + //! Total number of valid items in the calling thread's logical warp + //! (may be less than ``LOGICAL_WARP_THREADS``) + __device__ __forceinline__ T Sum(T input, int valid_items) + { + // Determine if we don't need bounds checking + return InternalWarpReduce(temp_storage).template Reduce(input, valid_items, cub::Sum()); + } + + //! @rst + //! Computes a segmented sum in the calling warp where segments are defined by head-flags. + //! The sum of each segment is returned to the first lane in that segment + //! (which always includes *lane*\ :sub:`0`). + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates a head-segmented warp sum + //! reduction within a block of 32 threads (one warp). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpReduce for type int + //! typedef cub::WarpReduce WarpReduce; + //! + //! // Allocate WarpReduce shared memory for one warp + //! __shared__ typename WarpReduce::TempStorage temp_storage; + //! + //! // Obtain one input item and flag per thread + //! int thread_data = ... + //! int head_flag = ... + //! + //! // Return the warp-wide sums to each lane0 + //! int aggregate = WarpReduce(temp_storage).HeadSegmentedSum( + //! thread_data, head_flag); + //! + //! Suppose the set of input ``thread_data`` and ``head_flag`` across the block of threads + //! is ``{0, 1, 2, 3, ..., 31`` and is ``{1, 0, 0, 0, 1, 0, 0, 0, ..., 1, 0, 0, 0``, + //! respectively. The corresponding output ``aggregate`` in threads 0, 4, 8, etc. will be + //! ``6``, ``22``, ``38``, etc. (and is undefined in other threads). + //! @endrst + //! + //! @tparam ReductionOp + //! **[inferred]** Binary reduction operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input + //! + //! @param[in] head_flag + //! Head flag denoting whether or not `input` is the start of a new segment + template + __device__ __forceinline__ T HeadSegmentedSum(T input, FlagT head_flag) + { + return HeadSegmentedReduce(input, head_flag, cub::Sum()); + } + + //! @rst + //! Computes a segmented sum in the calling warp where segments are defined by tail-flags. + //! The sum of each segment is returned to the first lane in that segment + //! (which always includes *lane*\ :sub:`0`). + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates a tail-segmented warp sum reduction within a block of 32 + //! threads (one warp). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpReduce for type int + //! typedef cub::WarpReduce WarpReduce; + //! + //! // Allocate WarpReduce shared memory for one warp + //! __shared__ typename WarpReduce::TempStorage temp_storage; + //! + //! // Obtain one input item and flag per thread + //! int thread_data = ... + //! int tail_flag = ... + //! + //! // Return the warp-wide sums to each lane0 + //! int aggregate = WarpReduce(temp_storage).TailSegmentedSum( + //! thread_data, tail_flag); + //! + //! Suppose the set of input ``thread_data`` and ``tail_flag`` across the block of threads + //! is ``{0, 1, 2, 3, ..., 31}`` and is ``{0, 0, 0, 1, 0, 0, 0, 1, ..., 0, 0, 0, 1}``, + //! respectively. The corresponding output ``aggregate`` in threads 0, 4, 8, etc. will be + //! ``6``, ``22``, ``38``, etc. (and is undefined in other threads). + //! @endrst + //! + //! @tparam ReductionOp + //! **[inferred]** Binary reduction operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input + //! + //! @param[in] tail_flag + //! Head flag denoting whether or not `input` is the start of a new segment + template + __device__ __forceinline__ T TailSegmentedSum(T input, FlagT tail_flag) + { + return TailSegmentedReduce(input, tail_flag, cub::Sum()); + } + + //! @} end member group + //! @name Generic reductions + //! @{ + + //! @rst + //! Computes a warp-wide reduction in the calling warp using the specified binary reduction + //! functor. The output is valid in warp *lane*\ :sub:`0`. + //! + //! Supports non-commutative reduction operators + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp max reductions within a block of + //! 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpReduce for type int + //! typedef cub::WarpReduce WarpReduce; + //! + //! // Allocate WarpReduce shared memory for 4 warps + //! __shared__ typename WarpReduce::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Return the warp-wide reductions to each lane0 + //! int warp_id = threadIdx.x / 32; + //! int aggregate = WarpReduce(temp_storage[warp_id]).Reduce( + //! thread_data, cub::Max()); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{0, 1, 2, 3, ..., 127}``. The corresponding output ``aggregate`` in threads 0, 32, 64, and + //! 96 will be ``31``, ``63``, ``95``, and ``127``, respectively + //! (and is undefined in other threads). + //! @endrst + //! + //! @tparam ReductionOp + //! **[inferred]** Binary reduction operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input + //! + //! @param[in] reduction_op + //! Binary reduction operator + template + __device__ __forceinline__ T Reduce(T input, ReductionOp reduction_op) + { + return InternalWarpReduce(temp_storage) + .template Reduce(input, LOGICAL_WARP_THREADS, reduction_op); + } + + //! @rst + //! Computes a partially-full warp-wide reduction in the calling warp using the specified binary + //! reduction functor. The output is valid in warp *lane*\ :sub:`0`. + //! + //! All threads across the calling warp must agree on the same value for ``valid_items``. + //! Otherwise the result is undefined. + //! + //! Supports non-commutative reduction operators + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates a max reduction within a single, partially-full + //! block of 32 threads (one warp). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(int *d_data, int valid_items) + //! { + //! // Specialize WarpReduce for type int + //! typedef cub::WarpReduce WarpReduce; + //! + //! // Allocate WarpReduce shared memory for one warp + //! __shared__ typename WarpReduce::TempStorage temp_storage; + //! + //! // Obtain one input item per thread if in range + //! int thread_data; + //! if (threadIdx.x < valid_items) + //! thread_data = d_data[threadIdx.x]; + //! + //! // Return the warp-wide reductions to each lane0 + //! int aggregate = WarpReduce(temp_storage).Reduce( + //! thread_data, cub::Max(), valid_items); + //! + //! Suppose the input ``d_data`` is ``{0, 1, 2, 3, 4, ... }`` and ``valid_items`` + //! is ``4``. The corresponding output ``aggregate`` in thread0 is ``3`` (and is + //! undefined in other threads). + //! @endrst + //! + //! @tparam ReductionOp + //! **[inferred]** Binary reduction operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input + //! + //! @param[in] reduction_op + //! Binary reduction operator + //! + //! @param[in] valid_items + //! Total number of valid items in the calling thread's logical warp + //! (may be less than ``LOGICAL_WARP_THREADS``) + template + __device__ __forceinline__ T Reduce(T input, ReductionOp reduction_op, int valid_items) + { + return InternalWarpReduce(temp_storage).template Reduce(input, valid_items, reduction_op); + } + + //! @rst + //! Computes a segmented reduction in the calling warp where segments are defined by head-flags. + //! The reduction of each segment is returned to the first lane in that segment + //! (which always includes *lane*\ :sub:`0`). + //! + //! Supports non-commutative reduction operators + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates a head-segmented warp max + //! reduction within a block of 32 threads (one warp). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpReduce for type int + //! typedef cub::WarpReduce WarpReduce; + //! + //! // Allocate WarpReduce shared memory for one warp + //! __shared__ typename WarpReduce::TempStorage temp_storage; + //! + //! // Obtain one input item and flag per thread + //! int thread_data = ... + //! int head_flag = ... + //! + //! // Return the warp-wide reductions to each lane0 + //! int aggregate = WarpReduce(temp_storage).HeadSegmentedReduce( + //! thread_data, head_flag, cub::Max()); + //! + //! Suppose the set of input ``thread_data`` and ``head_flag`` across the block of threads + //! is ``{0, 1, 2, 3, ..., 31}`` and is ``{1, 0, 0, 0, 1, 0, 0, 0, ..., 1, 0, 0, 0}``, + //! respectively. The corresponding output ``aggregate`` in threads 0, 4, 8, etc. will be + //! ``3``, ``7``, ``11``, etc. (and is undefined in other threads). + //! @endrst + //! + //! @tparam ReductionOp + //! **[inferred]** Binary reduction operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input + //! + //! @param[in] head_flag + //! Head flag denoting whether or not `input` is the start of a new segment + //! + //! @param[in] reduction_op + //! Reduction operator + template + __device__ __forceinline__ T HeadSegmentedReduce(T input, + FlagT head_flag, + ReductionOp reduction_op) + { + return InternalWarpReduce(temp_storage) + .template SegmentedReduce(input, head_flag, reduction_op); + } + + //! @rst + //! Computes a segmented reduction in the calling warp where segments are defined by tail-flags. + //! The reduction of each segment is returned to the first lane in that segment + //! (which always includes *lane*\ :sub:`0`). + //! + //! Supports non-commutative reduction operators + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates a tail-segmented warp max + //! reduction within a block of 32 threads (one warp). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpReduce for type int + //! typedef cub::WarpReduce WarpReduce; + //! + //! // Allocate WarpReduce shared memory for one warp + //! __shared__ typename WarpReduce::TempStorage temp_storage; + //! + //! // Obtain one input item and flag per thread + //! int thread_data = ... + //! int tail_flag = ... + //! + //! // Return the warp-wide reductions to each lane0 + //! int aggregate = WarpReduce(temp_storage).TailSegmentedReduce( + //! thread_data, tail_flag, cub::Max()); + //! + //! Suppose the set of input ``thread_data`` and ``tail_flag`` across the block of threads + //! is ``{0, 1, 2, 3, ..., 31}`` and is ``{0, 0, 0, 1, 0, 0, 0, 1, ..., 0, 0, 0, 1}``, + //! respectively. The corresponding output ``aggregate`` in threads 0, 4, 8, etc. will be + //! ``3``, ``7``, ``11``, etc. (and is undefined in other threads). + //! @endrst + //! + //! @tparam ReductionOp + //! **[inferred]** Binary reduction operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input + //! + //! @param[in] tail_flag + //! Tail flag denoting whether or not \p input is the end of the current segment + //! + //! @param[in] reduction_op + //! Reduction operator + template + __device__ __forceinline__ T TailSegmentedReduce(T input, + FlagT tail_flag, + ReductionOp reduction_op) + { + return InternalWarpReduce(temp_storage) + .template SegmentedReduce(input, tail_flag, reduction_op); + } + + //! @} end member group +}; + +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document +template +class WarpReduce +{ +private: + using _TempStorage = cub::NullType; + +public: + struct InternalWarpReduce + { + struct TempStorage : Uninitialized<_TempStorage> + {}; + + __device__ __forceinline__ InternalWarpReduce(TempStorage & /*temp_storage */) {} + + template + __device__ __forceinline__ T Reduce(T input, + int /* valid_items */, + ReductionOp /* reduction_op */) + { + return input; + } + + template + __device__ __forceinline__ T SegmentedReduce(T input, + FlagT /* flag */, + ReductionOp /* reduction_op */) + { + return input; + } + }; + + using TempStorage = typename InternalWarpReduce::TempStorage; + + __device__ __forceinline__ WarpReduce(TempStorage & /*temp_storage */) {} + + __device__ __forceinline__ T Sum(T input) { return input; } + + __device__ __forceinline__ T Sum(T input, int /* valid_items */) { return input; } + + template + __device__ __forceinline__ T HeadSegmentedSum(T input, FlagT /* head_flag */) + { + return input; + } + + template + __device__ __forceinline__ T TailSegmentedSum(T input, FlagT /* tail_flag */) + { + return input; + } + + template + __device__ __forceinline__ T Reduce(T input, ReductionOp /* reduction_op */) + { + return input; + } + + template + __device__ __forceinline__ T Reduce(T input, + ReductionOp /* reduction_op */, + int /* valid_items */) + { + return input; + } + + template + __device__ __forceinline__ T HeadSegmentedReduce(T input, + FlagT /* head_flag */, + ReductionOp /* reduction_op */) + { + return input; + } + + template + __device__ __forceinline__ T TailSegmentedReduce(T input, + FlagT /* tail_flag */, + ReductionOp /* reduction_op */) + { + return input; + } +}; +#endif // DOXYGEN_SHOULD_SKIP_THIS + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_scan.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_scan.cuh new file mode 100644 index 0000000000000000000000000000000000000000..feff7ffe69d812590be8bf557b0287ea6d0b5690 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_scan.cuh @@ -0,0 +1,1043 @@ +/****************************************************************************** + * Copyright (c) 2011, Duane Merrill. All rights reserved. + * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +//! @file +//! @rst +//! The ``cub::WarpScan`` class provides :ref:`collective ` methods for +//! computing a parallel prefix scan of items partitioned across a CUDA thread warp. +//! @endrst + +#pragma once + +#include +#include +#include +#include +#include + +CUB_NAMESPACE_BEGIN + +//! @rst +//! The WarpScan class provides :ref:`collective ` methods for computing a +//! parallel prefix scan of items partitioned across a CUDA thread warp. +//! +//! .. image:: ../img/warp_scan_logo.png +//! :align: center +//! +//! Overview +//! ++++++++++++++++++++++++++ +//! +//! * Given a list of input elements and a binary reduction operator, a +//! `prefix scan `__ produces an output list where each +//! element is computed to be the reduction of the elements occurring earlier in the input list. +//! *Prefix sum* connotes a prefix scan with the addition operator. The term *inclusive* +//! indicates that the *i*\ :sup:`th` output reduction incorporates the *i*\ :sup:`th` input. +//! The term *exclusive* indicates the *i*\ :sup:`th` input is not incorporated into +//! the *i*\ :sup:`th` output reduction. +//! * Supports non-commutative scan operators +//! * Supports "logical" warps smaller than the physical warp size +//! (e.g., a logical warp of 8 threads) +//! * The number of entrant threads must be an multiple of ``LOGICAL_WARP_THREADS`` +//! +//! Performance Considerations +//! ++++++++++++++++++++++++++ +//! +//! * Uses special instructions when applicable (e.g., warp ``SHFL``) +//! * Uses synchronization-free communication between warp lanes when applicable +//! * Incurs zero bank conflicts for most types +//! * Computation is slightly more efficient (i.e., having lower instruction overhead) for: +//! +//! * Summation (**vs.** generic scan) +//! * The architecture's warp size is a whole multiple of ``LOGICAL_WARP_THREADS`` +//! +//! Simple Examples +//! ++++++++++++++++++++++++++ +//! +//! @warpcollective{WarpScan} +//! +//! The code snippet below illustrates four concurrent warp prefix sums within a block of +//! 128 threads (one per each of the 32-thread warps). +//! +//! .. code-block:: c++ +//! +//! #include +//! +//! __global__ void ExampleKernel(...) +//! { +//! // Specialize WarpScan for type int +//! typedef cub::WarpScan WarpScan; +//! +//! // Allocate WarpScan shared memory for 4 warps +//! __shared__ typename WarpScan::TempStorage temp_storage[4]; +//! +//! // Obtain one input item per thread +//! int thread_data = ... +//! +//! // Compute warp-wide prefix sums +//! int warp_id = threadIdx.x / 32; +//! WarpScan(temp_storage[warp_id]).ExclusiveSum(thread_data, thread_data); +//! +//! Suppose the set of input ``thread_data`` across the block of threads is +//! ``{1, 1, 1, 1, ...}``. The corresponding output ``thread_data`` in each of the four warps of +//! threads will be ``0, 1, 2, 3, ..., 31}``. +//! +//! The code snippet below illustrates a single warp prefix sum within a block of +//! 128 threads. +//! +//! .. code-block:: c++ +//! +//! #include +//! +//! __global__ void ExampleKernel(...) +//! { +//! // Specialize WarpScan for type int +//! typedef cub::WarpScan WarpScan; +//! +//! // Allocate WarpScan shared memory for one warp +//! __shared__ typename WarpScan::TempStorage temp_storage; +//! ... +//! +//! // Only the first warp performs a prefix sum +//! if (threadIdx.x < 32) +//! { +//! // Obtain one input item per thread +//! int thread_data = ... +//! +//! // Compute warp-wide prefix sums +//! WarpScan(temp_storage).ExclusiveSum(thread_data, thread_data); +//! +//! Suppose the set of input ``thread_data`` across the warp of threads is +//! ``{1, 1, 1, 1, ...}``. The corresponding output ``thread_data`` will be +//! ``{0, 1, 2, 3, ..., 31}``. +//! @endrst +//! +//! @tparam T +//! The scan input/output element type +//! +//! @tparam LOGICAL_WARP_THREADS +//! **[optional]** The number of threads per "logical" warp (may be less than the number of +//! hardware warp threads). Default is the warp size associated with the CUDA Compute Capability +//! targeted by the compiler (e.g., 32 threads for SM20). +//! +//! @tparam LEGACY_PTX_ARCH +//! **[optional]** Unused. +template +class WarpScan +{ +private: + /****************************************************************************** + * Constants and type definitions + ******************************************************************************/ + + enum + { + /// Whether the logical warp size and the PTX warp size coincide + IS_ARCH_WARP = (LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0)), + + /// Whether the logical warp size is a power-of-two + IS_POW_OF_TWO = ((LOGICAL_WARP_THREADS & (LOGICAL_WARP_THREADS - 1)) == 0), + + /// Whether the data type is an integer (which has fully-associative addition) + IS_INTEGER = ((Traits::CATEGORY == SIGNED_INTEGER) || + (Traits::CATEGORY == UNSIGNED_INTEGER)) + }; + + /// Internal specialization. + /// Use SHFL-based scan if LOGICAL_WARP_THREADS is a power-of-two + using InternalWarpScan = cub::detail::conditional_t, + WarpScanSmem>; + + /// Shared memory storage layout type for WarpScan + using _TempStorage = typename InternalWarpScan::TempStorage; + + /****************************************************************************** + * Thread fields + ******************************************************************************/ + + /// Shared storage reference + _TempStorage &temp_storage; + unsigned int lane_id; + + /****************************************************************************** + * Public types + ******************************************************************************/ + +public: + /// @smemstorage{WarpScan} + struct TempStorage : Uninitialized<_TempStorage> + {}; + + //! @name Collective constructors + //! @{ + + //! @brief Collective constructor using the specified memory allocation as temporary storage. + //! Logical warp and lane identifiers are constructed from `threadIdx.x`. + //! + //! @param[in] temp_storage + //! Reference to memory allocation having layout type TempStorage + __device__ __forceinline__ WarpScan(TempStorage &temp_storage) + : temp_storage(temp_storage.Alias()) + , lane_id(IS_ARCH_WARP ? LaneId() : LaneId() % LOGICAL_WARP_THREADS) + {} + + //! @} end member group + //! @name Inclusive prefix sums + //! @{ + + //! @rst + //! Computes an inclusive prefix sum across the calling warp. + //! + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide inclusive prefix sums within a + //! block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute inclusive warp-wide prefix sums + //! int warp_id = threadIdx.x / 32; + //! WarpScan(temp_storage[warp_id]).InclusiveSum(thread_data, thread_data); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{1, 1, 1, 1, ...}``. The corresponding output ``thread_data`` in each of the four warps + //! of threads will be ``1, 2, 3, ..., 32}``. + //! @endrst + //! + //! @param[in] input + //! Calling thread's input item. + //! + //! @param[out] inclusive_output + //! Calling thread's output item. May be aliased with `input`. + __device__ __forceinline__ void InclusiveSum(T input, T &inclusive_output) + { + InclusiveScan(input, inclusive_output, cub::Sum()); + } + + //! @rst + //! Computes an inclusive prefix sum across the calling warp. + //! Also provides every thread with the warp-wide ``warp_aggregate`` of all inputs. + //! + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide inclusive prefix sums within a + //! block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute inclusive warp-wide prefix sums + //! int warp_aggregate; + //! int warp_id = threadIdx.x / 32; + //! WarpScan(temp_storage[warp_id]).InclusiveSum(thread_data, + //! thread_data, + //! warp_aggregate); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{1, 1, 1, 1, ...}``. The corresponding output ``thread_data`` in each of the four warps + //! of threads will be ``1, 2, 3, ..., 32}``. Furthermore, ``warp_aggregate`` for all threads + //! in all warps will be ``32``. + //! @endrst + //! + //! @param[in] input + //! Calling thread's input item + //! + //! @param[out] inclusive_output + //! Calling thread's output item. May be aliased with `input` + //! + //! @param[out] warp_aggregate + //! Warp-wide aggregate reduction of input items + __device__ __forceinline__ void InclusiveSum(T input, T &inclusive_output, T &warp_aggregate) + { + InclusiveScan(input, inclusive_output, cub::Sum(), warp_aggregate); + } + + //! @} end member group + //! @name Exclusive prefix sums + //! @{ + + //! @rst + //! Computes an exclusive prefix sum across the calling warp. The value of 0 is applied as the + //! initial value, and is assigned to ``exclusive_output`` in *lane*\ :sub:`0`. + //! + //! * @identityzero + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide exclusive prefix sums within a + //! block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute exclusive warp-wide prefix sums + //! int warp_id = threadIdx.x / 32; + //! WarpScan(temp_storage[warp_id]).ExclusiveSum(thread_data, thread_data); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{1, 1, 1, 1, ...}``. The corresponding output ``thread_data`` in each of the four warps + //! of threads will be ``0, 1, 2, ..., 31}``. + //! @endrst + //! + //! @param[in] input + //! Calling thread's input item. + //! + //! @param[out] exclusive_output + //! Calling thread's output item. May be aliased with `input`. + __device__ __forceinline__ void ExclusiveSum(T input, T &exclusive_output) + { + T initial_value{}; + ExclusiveScan(input, exclusive_output, initial_value, cub::Sum()); + } + + //! @rst + //! Computes an exclusive prefix sum across the calling warp. The value of 0 is applied as the + //! initial value, and is assigned to ``exclusive_output`` in *lane*\ :sub:`0`. + //! Also provides every thread with the warp-wide ``warp_aggregate`` of all inputs. + //! + //! * @identityzero + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide exclusive prefix sums within a + //! block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute exclusive warp-wide prefix sums + //! int warp_aggregate; + //! int warp_id = threadIdx.x / 32; + //! WarpScan(temp_storage[warp_id]).ExclusiveSum(thread_data, + //! thread_data, + //! warp_aggregate); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{1, 1, 1, 1, ...}``. The corresponding output ``thread_data`` in each of the four warps + //! of threads will be ``0, 1, 2, ..., 31}``. Furthermore, ``warp_aggregate`` for all threads + //! in all warps will be ``32``. + //! @endrst + //! + //! + //! @param[in] input + //! Calling thread's input item + //! + //! @param[out] exclusive_output + //! Calling thread's output item. May be aliased with `input` + //! + //! @param[out] warp_aggregate + //! Warp-wide aggregate reduction of input items + __device__ __forceinline__ void ExclusiveSum(T input, T &exclusive_output, T &warp_aggregate) + { + T initial_value{}; + ExclusiveScan(input, exclusive_output, initial_value, cub::Sum(), warp_aggregate); + } + + //! @} end member group + //! @name Inclusive prefix scans + //! @{ + + //! @rst + //! Computes an inclusive prefix scan using the specified binary scan functor across the + //! calling warp. + //! + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide inclusive prefix max scans + //! within a block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute inclusive warp-wide prefix max scans + //! int warp_id = threadIdx.x / 32; + //! WarpScan(temp_storage[warp_id]).InclusiveScan(thread_data, thread_data, cub::Max()); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{0, -1, 2, -3, ..., 126, -127}``. The corresponding output ``thread_data`` in the first + //! warp would be ``0, 0, 2, 2, ..., 30, 30``, the output for the second warp would be + //! ``32, 32, 34, 34, ..., 62, 62``, etc. + //! @endrst + //! + //! @tparam ScanOp + //! **[inferred]** Binary scan operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input item + //! + //! @param[out] inclusive_output + //! Calling thread's output item. May be aliased with `input` + //! + //! @param[in] can_op + //! Binary scan operator + template + __device__ __forceinline__ void InclusiveScan(T input, T &inclusive_output, ScanOp scan_op) + { + InternalWarpScan(temp_storage).InclusiveScan(input, inclusive_output, scan_op); + } + + //! @rst + //! Computes an inclusive prefix scan using the specified binary scan functor across the + //! calling warp. Also provides every thread with the warp-wide ``warp_aggregate`` of + //! all inputs. + //! + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide inclusive prefix max scans + //! within a block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute inclusive warp-wide prefix max scans + //! int warp_aggregate; + //! int warp_id = threadIdx.x / 32; + //! WarpScan(temp_storage[warp_id]).InclusiveScan( + //! thread_data, thread_data, cub::Max(), warp_aggregate); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{0, -1, 2, -3, ..., 126, -127}``. The corresponding output ``thread_data`` in the first + //! warp would be ``0, 0, 2, 2, ..., 30, 30``, the output for the second warp would be + //! ``32, 32, 34, 34, ..., 62, 62``, etc. Furthermore, ``warp_aggregate`` would be assigned + //! ``30`` for threads in the first warp, ``62`` for threads in the second warp, etc. + //! @endrst + //! + //! @tparam ScanOp + //! **[inferred]** Binary scan operator type having member + //! `T operator()(const T &a, const T &b)` + //! @param[in] input + //! Calling thread's input item + //! + //! @param[out] inclusive_output + //! Calling thread's output item. May be aliased with ``input`` + //! + //! @param[in] scan_op + //! Binary scan operator + //! + //! @param[out] warp_aggregate + //! Warp-wide aggregate reduction of input items. + template + __device__ __forceinline__ void + InclusiveScan(T input, T &inclusive_output, ScanOp scan_op, T &warp_aggregate) + { + InternalWarpScan(temp_storage).InclusiveScan(input, inclusive_output, scan_op, warp_aggregate); + } + + //! @} end member group + //! @name Exclusive prefix scans + //! @{ + + //! @rst + //! Computes an exclusive prefix scan using the specified binary scan functor across the + //! calling warp. Because no initial value is supplied, the ``output`` computed for + //! *lane*\ :sub:`0` is undefined. + //! + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide exclusive prefix max scans + //! within a block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute exclusive warp-wide prefix max scans + //! int warp_id = threadIdx.x / 32; + //! WarpScan(temp_storage[warp_id]).ExclusiveScan(thread_data, thread_data, cub::Max()); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{0, -1, 2, -3, ..., 126, -127}``. The corresponding output ``thread_data`` in the first + //! warp would be ``?, 0, 0, 2, ..., 28, 30``, the output for the second warp would be + //! ``?, 32, 32, 34, ..., 60, 62``, etc. + //! (The output ``thread_data`` in warp *lane*\ :sub:`0` is undefined.) + //! @endrst + //! + //! @tparam ScanOp + //! **[inferred]** Binary scan operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input item + //! + //! @param[out] exclusive_output + //! Calling thread's output item. May be aliased with `input` + //! + //! @param[in] scan_op + //! Binary scan operator + template + __device__ __forceinline__ void ExclusiveScan(T input, T &exclusive_output, ScanOp scan_op) + { + InternalWarpScan internal(temp_storage); + + T inclusive_output; + internal.InclusiveScan(input, inclusive_output, scan_op); + + internal.Update(input, inclusive_output, exclusive_output, scan_op, Int2Type()); + } + + //! @rst + //! Computes an exclusive prefix scan using the specified binary scan functor across the + //! calling warp. + //! + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide exclusive prefix max scans + //! within a block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute exclusive warp-wide prefix max scans + //! int warp_id = threadIdx.x / 32; + //! WarpScan(temp_storage[warp_id]).ExclusiveScan(thread_data, + //! thread_data, + //! INT_MIN, + //! cub::Max()); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{0, -1, 2, -3, ..., 126, -127}``. The corresponding output ``thread_data`` in the first + //! warp would be ``INT_MIN, 0, 0, 2, ..., 28, 30``, the output for the second warp would be + //! ``30, 32, 32, 34, ..., 60, 62``, etc. + //! @endrst + //! + //! @tparam ScanOp + //! **[inferred]** Binary scan operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input item + //! + //! @param[out] exclusive_output + //! Calling thread's output item. May be aliased with `input` + //! + //! @param[in] initial_value + //! Initial value to seed the exclusive scan + //! + //! @param[in] scan_op + //! Binary scan operator + template + __device__ __forceinline__ void + ExclusiveScan(T input, T &exclusive_output, T initial_value, ScanOp scan_op) + { + InternalWarpScan internal(temp_storage); + + T inclusive_output; + internal.InclusiveScan(input, inclusive_output, scan_op); + + internal.Update(input, + inclusive_output, + exclusive_output, + scan_op, + initial_value, + Int2Type()); + } + + //! @rst + //! Computes an exclusive prefix scan using the specified binary scan functor across the + //! calling warp. Because no initial value is supplied, the ``output`` computed for + //! *lane*\ :sub:`0` is undefined. Also provides every thread with the warp-wide + //! ``warp_aggregate`` of all inputs. + //! + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide exclusive prefix max scans + //! within a block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute exclusive warp-wide prefix max scans + //! int warp_aggregate; + //! int warp_id = threadIdx.x / 32; + //! WarpScan(temp_storage[warp_id]).ExclusiveScan(thread_data, + //! thread_data, + //! cub::Max(), + //! warp_aggregate); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{0, -1, 2, -3, ..., 126, -127}``. The corresponding output ``thread_data`` in the first + //! warp would be ``?, 0, 0, 2, ..., 28, 30``, the output for the second warp would be + //! ``?, 32, 32, 34, ..., 60, 62``, etc. (The output ``thread_data`` in warp *lane*\ :sub:`0` + //! is undefined). Furthermore, ``warp_aggregate`` would be assigned ``30`` for threads in the + //! first warp, \p 62 for threads in the second warp, etc. + //! @endrst + //! + //! @tparam ScanOp + //! **[inferred]** Binary scan operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input item + //! + //! @param[out] exclusive_output + //! Calling thread's output item. May be aliased with `input` + //! + //! @param[in] scan_op + //! Binary scan operator + //! + //! @param[out] warp_aggregate + //! Warp-wide aggregate reduction of input items + template + __device__ __forceinline__ void + ExclusiveScan(T input, T &exclusive_output, ScanOp scan_op, T &warp_aggregate) + { + InternalWarpScan internal(temp_storage); + + T inclusive_output; + internal.InclusiveScan(input, inclusive_output, scan_op); + + internal.Update(input, + inclusive_output, + exclusive_output, + warp_aggregate, + scan_op, + Int2Type()); + } + + //! @rst + //! Computes an exclusive prefix scan using the specified binary scan functor across the + //! calling warp. Also provides every thread with the warp-wide ``warp_aggregate`` of + //! all inputs. + //! + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide exclusive prefix max scans + //! within a block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute exclusive warp-wide prefix max scans + //! int warp_aggregate; + //! int warp_id = threadIdx.x / 32; + //! WarpScan(temp_storage[warp_id]).ExclusiveScan(thread_data, + //! thread_data, + //! INT_MIN, + //! cub::Max(), + //! warp_aggregate); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{0, -1, 2, -3, ..., 126, -127}``. The corresponding output ``thread_data`` in the first + //! warp would be ``INT_MIN, 0, 0, 2, ..., 28, 30``, the output for the second warp would be + //! ``30, 32, 32, 34, ..., 60, 62``, etc. Furthermore, ``warp_aggregate`` would be assigned + //! ``30`` for threads in the first warp, ``62`` for threads in the second warp, etc. + //! @endrst + //! + //! @tparam ScanOp + //! **[inferred]** Binary scan operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input item + //! + //! @param[out] exclusive_output + //! Calling thread's output item. May be aliased with `input` + //! + //! @param[in] initial_value + //! Initial value to seed the exclusive scan + //! + //! @param[in] scan_op + //! Binary scan operator + //! + //! @param[out] warp_aggregate + //! Warp-wide aggregate reduction of input items + //! + template + __device__ __forceinline__ void + ExclusiveScan(T input, T &exclusive_output, T initial_value, ScanOp scan_op, T &warp_aggregate) + { + InternalWarpScan internal(temp_storage); + + T inclusive_output; + internal.InclusiveScan(input, inclusive_output, scan_op); + + internal.Update(input, + inclusive_output, + exclusive_output, + warp_aggregate, + scan_op, + initial_value, + Int2Type()); + } + + //! @} end member group + //! @name Combination (inclusive & exclusive) prefix scans + //! @{ + + //! @rst + //! Computes both inclusive and exclusive prefix scans using the specified binary scan functor + //! across the calling warp. Because no initial value is supplied, the ``exclusive_output`` + //! computed for *lane*\ :sub:`0` is undefined. + //! + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide exclusive prefix max scans + //! within a block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute exclusive warp-wide prefix max scans + //! int inclusive_partial, exclusive_partial; + //! WarpScan(temp_storage[warp_id]).Scan(thread_data, + //! inclusive_partial, + //! exclusive_partial, + //! cub::Max()); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{0, -1, 2, -3, ..., 126, -127}``. The corresponding output ``inclusive_partial`` in the + //! first warp would be ``0, 0, 2, 2, ..., 30, 30``, the output for the second warp would be + //! ``32, 32, 34, 34, ..., 62, 62``, etc. The corresponding output ``exclusive_partial`` in the + //! first warp would be ``?, 0, 0, 2, ..., 28, 30``, the output for the second warp would be + //! ``?, 32, 32, 34, ..., 60, 62``, etc. + //! (The output ``thread_data`` in warp *lane*\ :sub:`0` is undefined.) + //! @endrst + //! + //! @tparam ScanOp + //! **[inferred]** Binary scan operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input item + //! + //! @param[out] inclusive_output + //! Calling thread's inclusive-scan output item + //! + //! @param[out] exclusive_output + //! Calling thread's exclusive-scan output item + //! + //! @param[in] scan_op + //! Binary scan operator + template + __device__ __forceinline__ void + Scan(T input, T &inclusive_output, T &exclusive_output, ScanOp scan_op) + { + InternalWarpScan internal(temp_storage); + + internal.InclusiveScan(input, inclusive_output, scan_op); + + internal.Update(input, inclusive_output, exclusive_output, scan_op, Int2Type()); + } + + //! @rst + //! Computes both inclusive and exclusive prefix scans using the specified binary scan functor + //! across the calling warp. + //! + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates four concurrent warp-wide prefix max scans within a + //! block of 128 threads (one per each of the 32-thread warps). + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Compute inclusive warp-wide prefix max scans + //! int warp_id = threadIdx.x / 32; + //! int inclusive_partial, exclusive_partial; + //! WarpScan(temp_storage[warp_id]).Scan(thread_data, + //! inclusive_partial, + //! exclusive_partial, + //! INT_MIN, + //! cub::Max()); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{0, -1, 2, -3, ..., 126, -127}``. The corresponding output ``inclusive_partial`` in the + //! first warp would be ``0, 0, 2, 2, ..., 30, 30``, the output for the second warp would be + //! ``32, 32, 34, 34, ..., 62, 62``, etc. The corresponding output ``exclusive_partial`` in the + //! first warp would be ``INT_MIN, 0, 0, 2, ..., 28, 30``, the output for the second warp would + //! be ``30, 32, 32, 34, ..., 60, 62``, etc. + //! @endrst + //! + //! @tparam ScanOp + //! **[inferred]** Binary scan operator type having member + //! `T operator()(const T &a, const T &b)` + //! + //! @param[in] input + //! Calling thread's input item + //! + //! @param[out] inclusive_output + //! Calling thread's inclusive-scan output item + //! + //! @param[out] exclusive_output + //! Calling thread's exclusive-scan output item + //! + //! @param[in] initial_value + //! Initial value to seed the exclusive scan + //! + //! @param[in] scan_op + //! Binary scan operator + template + __device__ __forceinline__ void + Scan(T input, T &inclusive_output, T &exclusive_output, T initial_value, ScanOp scan_op) + { + InternalWarpScan internal(temp_storage); + + internal.InclusiveScan(input, inclusive_output, scan_op); + + internal.Update(input, + inclusive_output, + exclusive_output, + scan_op, + initial_value, + Int2Type()); + } + + //! @} end member group + //! @name Data exchange + //! @{ + + //! @rst + //! Broadcast the value ``input`` from *lane*\ :sub:`src_lane` to all lanes in the warp + //! + //! * @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates the warp-wide broadcasts of values from *lane*\ :sub:`0` + //! in each of four warps to all other threads in those warps. + //! + //! .. code-block:: c++ + //! + //! #include + //! + //! __global__ void ExampleKernel(...) + //! { + //! // Specialize WarpScan for type int + //! typedef cub::WarpScan WarpScan; + //! + //! // Allocate WarpScan shared memory for 4 warps + //! __shared__ typename WarpScan::TempStorage temp_storage[4]; + //! + //! // Obtain one input item per thread + //! int thread_data = ... + //! + //! // Broadcast from lane0 in each warp to all other threads in the warp + //! int warp_id = threadIdx.x / 32; + //! thread_data = WarpScan(temp_storage[warp_id]).Broadcast(thread_data, 0); + //! + //! Suppose the set of input ``thread_data`` across the block of threads is + //! ``{0, 1, 2, 3, ..., 127}``. The corresponding output ``thread_data`` will be + //! ``{0, 0, ..., 0}`` in warp\ :sub:`0`, + //! ``{32, 32, ..., 32}`` in warp\ :sub:`1`, + //! ``{64, 64, ..., 64}`` in warp\ :sub:`2`, etc. + //! @endrst + //! + //! @param[in] input + //! The value to broadcast + //! + //! @param[in] src_lane + //! Which warp lane is to do the broadcasting + __device__ __forceinline__ T Broadcast(T input, unsigned int src_lane) + { + return InternalWarpScan(temp_storage).Broadcast(input, src_lane); + } + + //@} end member group +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_store.cuh b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_store.cuh new file mode 100644 index 0000000000000000000000000000000000000000..37a9d6519f7f8fddc59f70b576b714deb769f201 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cub/warp/warp_store.cuh @@ -0,0 +1,523 @@ +/****************************************************************************** + * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the NVIDIA CORPORATION nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + +//! @file Operations for writing linear segments of data from the CUDA warp + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +CUB_NAMESPACE_BEGIN + +//! @rst +//! ``cub::WarpStoreAlgorithm`` enumerates alternative algorithms for :cpp:struct:`cub::WarpStore` +//! to write a blocked arrangement of items across a CUDA warp to a linear segment of memory. +//! @endrst +enum WarpStoreAlgorithm +{ + //! @rst + //! Overview + //! ++++++++++++++++++++++++++ + //! + //! A :ref:`blocked arrangement ` of data is written directly + //! to memory. + //! + //! Performance Considerations + //! ++++++++++++++++++++++++++ + //! + //! The utilization of memory transactions (coalescing) decreases as the + //! access stride between threads increases (i.e., the number items per thread). + //! @endrst + WARP_STORE_DIRECT, + + //! @rst + //! Overview + //! ++++++++++++++++++++++++++ + //! + //! A :ref:`striped arrangement ` of data is written + //! directly to memory. + //! + //! Performance Considerations + //! ++++++++++++++++++++++++++ + //! + //! The utilization of memory transactions (coalescing) remains high regardless + //! of items written per thread. + //! @endrst + WARP_STORE_STRIPED, + + //! @rst + //! Overview + //! ++++++++++++++++++++++++++ + //! + //! A :ref:`blocked arrangement ` of data is written + //! directly to memory using CUDA's built-in vectorized stores as a coalescing + //! optimization. For example, ``st.global.v4.s32`` instructions will be + //! generated when ``T = int`` and ``ITEMS_PER_THREAD % 4 == 0``. + //! + //! Performance Considerations + //! ++++++++++++++++++++++++++ + //! + //! * The utilization of memory transactions (coalescing) remains high until + //! the the access stride between threads (i.e., the number items per thread) + //! exceeds the maximum vector store width (typically 4 items or 64B, + //! whichever is lower). + //! * The following conditions will prevent vectorization and writing will fall + //! back to ``cub::WARP_STORE_DIRECT``: + //! + //! * ``ITEMS_PER_THREAD`` is odd + //! * The ``OutputIteratorT`` is not a simple pointer type + //! * The block output offset is not quadword-aligned + //! * The data type ``T`` is not a built-in primitive or CUDA vector type + //! (e.g., ``short``, ``int2``, ``double``, ``float2``, etc.) + //! + //! @endrst + WARP_STORE_VECTORIZE, + + //! @rst + //! Overview + //! ++++++++++++++++++++++++++ + //! + //! A :ref:`blocked arrangement ` is locally + //! transposed and then efficiently written to memory as a + //! :ref:`striped arrangement `. + //! + //! Performance Considerations + //! ++++++++++++++++++++++++++ + //! + //! * The utilization of memory transactions (coalescing) remains high + //! regardless of items written per thread. + //! * The local reordering incurs slightly longer latencies and throughput than the + //! direct ``cub::WARP_STORE_DIRECT`` and ``cub::WARP_STORE_VECTORIZE`` alternatives. + //! + //! @endrst + WARP_STORE_TRANSPOSE +}; + +//! @rst +//! The WarpStore class provides :ref:`collective ` +//! data movement methods for writing a :ref:`blocked arrangement ` +//! of items partitioned across a CUDA warp to a linear segment of memory. +//! +//! Overview +//! ++++++++++++++++ +//! +//! * The WarpStore class provides a single data movement abstraction that can be +//! specialized to implement different cub::WarpStoreAlgorithm strategies. This +//! facilitates different performance policies for different architectures, +//! data types, granularity sizes, etc. +//! * WarpStore can be optionally specialized by different data movement strategies: +//! +//! #. :cpp:enumerator:`cub::WARP_STORE_DIRECT`: +//! a :ref:`blocked arrangement ` of data is written directly to +//! memory. +//! #. :cpp:enumerator:`cub::WARP_STORE_STRIPED`: +//! a :ref:`striped arrangement ` of data is written directly to +//! memory. +//! #. :cpp:enumerator:`cub::WARP_STORE_VECTORIZE`: +//! a :ref:`blocked arrangement ` of data is written directly to +//! memory using CUDA's built-in vectorized stores as a coalescing optimization. +//! #. :cpp:enumerator:`cub::WARP_STORE_TRANSPOSE`: +//! a :ref:`blocked arrangement ` is locally transposed into a +//! :ref:`striped arrangement ` which is then written to memory. +//! +//! * @rowmajor +//! +//! A Simple Example +//! ++++++++++++++++ +//! +//! The code snippet below illustrates the storing of a "blocked" arrangement +//! of 64 integers across 16 threads (where each thread owns 4 consecutive items) +//! into a linear segment of memory. The store is specialized for +//! ``WARP_STORE_TRANSPOSE``, meaning items are locally reordered among threads so +//! that memory references will be efficiently coalesced using a warp-striped +//! access pattern. +//! +//! .. code-block:: c++ +//! +//! #include // or equivalently +//! +//! __global__ void ExampleKernel(int *d_data, ...) +//! { +//! constexpr int warp_threads = 16; +//! constexpr int block_threads = 256; +//! constexpr int items_per_thread = 4; +//! +//! // Specialize WarpStore for a virtual warp of 16 threads owning 4 integer items each +//! using WarpStoreT = WarpStore; +//! +//! constexpr int warps_in_block = block_threads / warp_threads; +//! constexpr int tile_size = items_per_thread * warp_threads; +//! const int warp_id = static_cast(threadIdx.x) / warp_threads; +//! +//! // Allocate shared memory for WarpStore +//! __shared__ typename WarpStoreT::TempStorage temp_storage[warps_in_block]; +//! +//! // Obtain a segment of consecutive items that are blocked across threads +//! int thread_data[4]; +//! ... +//! +//! // Store items to linear memory +//! WarpStoreT(temp_storage[warp_id]).Store(d_data + warp_id * tile_size, thread_data); +//! +//! Suppose the set of ``thread_data`` across the warp threads is +//! ``{ [0,1,2,3], [4,5,6,7], ..., [60,61,62,63] }``. +//! The output ``d_data`` will be ``0, 1, 2, 3, 4, 5, ...``. +//! @endrst +//! +//! @tparam T +//! The type of data to be written. +//! +//! @tparam ITEMS_PER_THREAD +//! The number of consecutive items partitioned onto each thread. +//! +//! @tparam ALGORITHM +//! [optional] cub::WarpStoreAlgorithm tuning policy enumeration. +//! default: cub::WARP_STORE_DIRECT. +//! +//! @tparam LOGICAL_WARP_THREADS +//! [optional] The number of threads per "logical" warp (may be less +//! than the number of hardware warp threads). Default is the warp size of the +//! targeted CUDA compute-capability (e.g., 32 threads for SM86). Must be a +//! power of two. +//! +//! @tparam LEGACY_PTX_ARCH +//! Unused. +template +class WarpStore +{ + static_assert(PowerOfTwo::VALUE, + "LOGICAL_WARP_THREADS must be a power of two"); + + constexpr static bool IS_ARCH_WARP = LOGICAL_WARP_THREADS == CUB_WARP_THREADS(0); + +private: + /// Store helper + template + struct StoreInternal; + + template + struct StoreInternal + { + using TempStorage = NullType; + + int linear_tid; + + __device__ __forceinline__ StoreInternal(TempStorage & /*temp_storage*/, int linear_tid) + : linear_tid(linear_tid) + {} + + template + __device__ __forceinline__ void Store(OutputIteratorT block_itr, T (&items)[ITEMS_PER_THREAD]) + { + StoreDirectBlocked(linear_tid, block_itr, items); + } + + template + __device__ __forceinline__ void Store(OutputIteratorT block_itr, + T (&items)[ITEMS_PER_THREAD], + int valid_items) + { + StoreDirectBlocked(linear_tid, block_itr, items, valid_items); + } + }; + + template + struct StoreInternal + { + using TempStorage = NullType; + + int linear_tid; + + __device__ __forceinline__ StoreInternal(TempStorage & /*temp_storage*/, int linear_tid) + : linear_tid(linear_tid) + {} + + template + __device__ __forceinline__ void Store(OutputIteratorT block_itr, T (&items)[ITEMS_PER_THREAD]) + { + StoreDirectStriped(linear_tid, block_itr, items); + } + + template + __device__ __forceinline__ void Store(OutputIteratorT block_itr, + T (&items)[ITEMS_PER_THREAD], + int valid_items) + { + StoreDirectStriped(linear_tid, block_itr, items, valid_items); + } + }; + + template + struct StoreInternal + { + using TempStorage = NullType; + + int linear_tid; + + __device__ __forceinline__ StoreInternal(TempStorage & /*temp_storage*/, int linear_tid) + : linear_tid(linear_tid) + {} + + __device__ __forceinline__ void Store(T *block_ptr, T (&items)[ITEMS_PER_THREAD]) + { + StoreDirectBlockedVectorized(linear_tid, block_ptr, items); + } + + template + __device__ __forceinline__ void Store(OutputIteratorT block_itr, T (&items)[ITEMS_PER_THREAD]) + { + StoreDirectBlocked(linear_tid, block_itr, items); + } + + template + __device__ __forceinline__ void Store(OutputIteratorT block_itr, + T (&items)[ITEMS_PER_THREAD], + int valid_items) + { + StoreDirectBlocked(linear_tid, block_itr, items, valid_items); + } + }; + + template + struct StoreInternal + { + using WarpExchangeT = WarpExchange; + + struct _TempStorage : WarpExchangeT::TempStorage + {}; + + struct TempStorage : Uninitialized<_TempStorage> + {}; + + _TempStorage &temp_storage; + + int linear_tid; + + __device__ __forceinline__ StoreInternal(TempStorage &temp_storage, int linear_tid) + : temp_storage(temp_storage.Alias()) + , linear_tid(linear_tid) + {} + + template + __device__ __forceinline__ void Store(OutputIteratorT block_itr, T (&items)[ITEMS_PER_THREAD]) + { + WarpExchangeT(temp_storage).BlockedToStriped(items, items); + StoreDirectStriped(linear_tid, block_itr, items); + } + + template + __device__ __forceinline__ void Store(OutputIteratorT block_itr, + T (&items)[ITEMS_PER_THREAD], + int valid_items) + { + WarpExchangeT(temp_storage).BlockedToStriped(items, items); + StoreDirectStriped(linear_tid, block_itr, items, valid_items); + } + }; + + /// Internal load implementation to use + using InternalStore = StoreInternal; + + /// Shared memory storage layout type + using _TempStorage = typename InternalStore::TempStorage; + + __device__ __forceinline__ _TempStorage &PrivateStorage() + { + __shared__ _TempStorage private_storage; + return private_storage; + } + + _TempStorage &temp_storage; + + int linear_tid; + +public: + struct TempStorage : Uninitialized<_TempStorage> + {}; + + //! @name Collective constructors + //! @{ + + //! @brief Collective constructor using a private static allocation of shared + //! memory as temporary storage. + __device__ __forceinline__ WarpStore() + : temp_storage(PrivateStorage()) + , linear_tid(IS_ARCH_WARP ? LaneId() : (LaneId() % LOGICAL_WARP_THREADS)) + {} + + //! @brief Collective constructor using the specified memory allocation as + //! temporary storage. + __device__ __forceinline__ WarpStore(TempStorage &temp_storage) + : temp_storage(temp_storage.Alias()) + , linear_tid(IS_ARCH_WARP ? LaneId() : (LaneId() % LOGICAL_WARP_THREADS)) + {} + + //! @} end member group + //! @name Data movement + //! @{ + + //! @rst + //! Store items into a linear segment of memory. + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates the storing of a "blocked" arrangement + //! of 64 integers across 16 threads (where each thread owns 4 consecutive items) + //! into a linear segment of memory. The store is specialized for + //! ``WARP_STORE_TRANSPOSE``, meaning items are locally reordered among threads so + //! that memory references will be efficiently coalesced using a warp-striped + //! access pattern. + //! + //! .. code-block:: c++ + //! + //! #include // or equivalently + //! + //! __global__ void ExampleKernel(int *d_data, ...) + //! { + //! constexpr int warp_threads = 16; + //! constexpr int block_threads = 256; + //! constexpr int items_per_thread = 4; + //! + //! // Specialize WarpStore for a virtual warp of 16 threads owning 4 integer items each + //! using WarpStoreT = WarpStore; + //! + //! constexpr int warps_in_block = block_threads / warp_threads; + //! constexpr int tile_size = items_per_thread * warp_threads; + //! const int warp_id = static_cast(threadIdx.x) / warp_threads; + //! + //! // Allocate shared memory for WarpStore + //! __shared__ typename WarpStoreT::TempStorage temp_storage[warps_in_block]; + //! + //! // Obtain a segment of consecutive items that are blocked across threads + //! int thread_data[4]; + //! ... + //! + //! // Store items to linear memory + //! WarpStoreT(temp_storage[warp_id]).Store(d_data + warp_id * tile_size, thread_data); + //! + //! Suppose the set of ``thread_data`` across the warp threads is + //! ``{ [0,1,2,3], [4,5,6,7], ..., [60,61,62,63] }``. + //! The output ``d_data`` will be ``0, 1, 2, 3, 4, 5, ...``. + //! @endrst + //! + //! @param[out] block_itr The thread block's base output iterator for storing to + //! @param[in] items Data to store + template + __device__ __forceinline__ void Store(OutputIteratorT block_itr, T (&items)[ITEMS_PER_THREAD]) + { + InternalStore(temp_storage, linear_tid).Store(block_itr, items); + } + + //! @rst + //! Store items into a linear segment of memory, guarded by range. + //! + //! @smemwarpreuse + //! + //! Snippet + //! +++++++ + //! + //! The code snippet below illustrates the storing of a "blocked" arrangement + //! of 64 integers across 16 threads (where each thread owns 4 consecutive items) + //! into a linear segment of memory. The store is specialized for + //! ``WARP_STORE_TRANSPOSE``, meaning items are locally reordered among threads so + //! that memory references will be efficiently coalesced using a warp-striped + //! access pattern. + //! + //! .. code-block:: c++ + //! + //! #include // or equivalently + //! + //! __global__ void ExampleKernel(int *d_data, int valid_items ...) + //! { + //! constexpr int warp_threads = 16; + //! constexpr int block_threads = 256; + //! constexpr int items_per_thread = 4; + //! + //! // Specialize WarpStore for a virtual warp of 16 threads owning 4 integer items each + //! using WarpStoreT = WarpStore; + //! + //! constexpr int warps_in_block = block_threads / warp_threads; + //! constexpr int tile_size = items_per_thread * warp_threads; + //! const int warp_id = static_cast(threadIdx.x) / warp_threads; + //! + //! // Allocate shared memory for WarpStore + //! __shared__ typename WarpStoreT::TempStorage temp_storage[warps_in_block]; + //! + //! // Obtain a segment of consecutive items that are blocked across threads + //! int thread_data[4]; + //! ... + //! + //! // Store items to linear memory + //! WarpStoreT(temp_storage[warp_id]).Store( + //! d_data + warp_id * tile_size, thread_data, valid_items); + //! + //! Suppose the set of ``thread_data`` across the warp threads is + //! ``{ [0,1,2,3], [4,5,6,7], ..., [60,61,62,63] }`` and ``valid_items`` + //! is ``5``. The output ``d_data`` will be ``0, 1, 2, 3, 4, ?, ?, ...``, + //! with only the first two threads being unmasked to store portions of valid + //! data. + //! @endrst + //! + //! @param[out] block_itr The thread block's base output iterator for storing to + //! @param[in] items Data to store + //! @param[in] valid_items Number of valid items to write + //! + template + __device__ __forceinline__ void Store(OutputIteratorT block_itr, + T (&items)[ITEMS_PER_THREAD], + int valid_items) + { + InternalStore(temp_storage, linear_tid).Store(block_itr, items, valid_items); + } + + //! @} end member group +}; + +CUB_NAMESPACE_END diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/annotated_ptr b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/annotated_ptr new file mode 100644 index 0000000000000000000000000000000000000000..e20b6f58ba3e952a7d2317d80d154f9c89fa3902 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/annotated_ptr @@ -0,0 +1,336 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * NVIDIA SOFTWARE LICENSE + * + * This license is a legal agreement between you and NVIDIA Corporation ("NVIDIA") and governs your use of the NVIDIA/CUDA C++ Library software and materials provided hereunder (“SOFTWARE”). + * + * This license can be accepted only by an adult of legal age of majority in the country in which the SOFTWARE is used. If you are under the legal age of majority, you must ask your parent or legal guardian to consent to this license. By taking delivery of the SOFTWARE, you affirm that you have reached the legal age of majority, you accept the terms of this license, and you take legal and financial responsibility for the actions of your permitted users. + * + * You agree to use the SOFTWARE only for purposes that are permitted by (a) this license, and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions. + * + * 1. LICENSE. Subject to the terms of this license, NVIDIA grants you a non-exclusive limited license to: (a) install and use the SOFTWARE, and (b) distribute the SOFTWARE subject to the distribution requirements described in this license. NVIDIA reserves all rights, title and interest in and to the SOFTWARE not expressly granted to you under this license. + * + * 2. DISTRIBUTION REQUIREMENTS. These are the distribution requirements for you to exercise the distribution grant: + * a. The terms under which you distribute the SOFTWARE must be consistent with the terms of this license, including (without limitation) terms relating to the license grant and license restrictions and protection of NVIDIA’s intellectual property rights. + * b. You agree to notify NVIDIA in writing of any known or suspected distribution or use of the SOFTWARE not in compliance with the requirements of this license, and to enforce the terms of your agreements with respect to distributed SOFTWARE. + * + * 3. LIMITATIONS. Your license to use the SOFTWARE is restricted as follows: + * a. The SOFTWARE is licensed for you to develop applications only for use in systems with NVIDIA GPUs. + * b. You may not reverse engineer, decompile or disassemble, or remove copyright or other proprietary notices from any portion of the SOFTWARE or copies of the SOFTWARE. + * c. You may not modify or create derivative works of any portion of the SOFTWARE. + * d. You may not bypass, disable, or circumvent any technical measure, encryption, security, digital rights management or authentication mechanism in the SOFTWARE. + * e. You may not use the SOFTWARE in any manner that would cause it to become subject to an open source software license. As examples, licenses that require as a condition of use, modification, and/or distribution that the SOFTWARE be (i) disclosed or distributed in source code form; (ii) licensed for the purpose of making derivative works; or (iii) redistributable at no charge. + * f. Unless you have an agreement with NVIDIA for this purpose, you may not use the SOFTWARE with any system or application where the use or failure of the system or application can reasonably be expected to threaten or result in personal injury, death, or catastrophic loss. Examples include use in avionics, navigation, military, medical, life support or other life critical applications. NVIDIA does not design, test or manufacture the SOFTWARE for these critical uses and NVIDIA shall not be liable to you or any third party, in whole or in part, for any claims or damages arising from such uses. + * g. You agree to defend, indemnify and hold harmless NVIDIA and its affiliates, and their respective employees, contractors, agents, officers and directors, from and against any and all claims, damages, obligations, losses, liabilities, costs or debt, fines, restitutions and expenses (including but not limited to attorney’s fees and costs incident to establishing the right of indemnification) arising out of or related to use of the SOFTWARE outside of the scope of this Agreement, or not in compliance with its terms. + * + * 4. PRE-RELEASE. SOFTWARE versions identified as alpha, beta, preview, early access or otherwise as pre-release may not be fully functional, may contain errors or design flaws, and may have reduced or different security, privacy, availability, and reliability standards relative to commercial versions of NVIDIA software and materials. You may use a pre-release SOFTWARE version at your own risk, understanding that these versions are not intended for use in production or business-critical systems. + * + * 5. OWNERSHIP. The SOFTWARE and the related intellectual property rights therein are and will remain the sole and exclusive property of NVIDIA or its licensors. The SOFTWARE is copyrighted and protected by the laws of the United States and other countries, and international treaty provisions. NVIDIA may make changes to the SOFTWARE, at any time without notice, but is not obligated to support or update the SOFTWARE. + * + * 6. COMPONENTS UNDER OTHER LICENSES. The SOFTWARE may include NVIDIA or third-party components with separate legal notices or terms as may be described in proprietary notices accompanying the SOFTWARE. If and to the extent there is a conflict between the terms in this license and the license terms associated with a component, the license terms associated with the components control only to the extent necessary to resolve the conflict. + * + * 7. FEEDBACK. You may, but don’t have to, provide to NVIDIA any Feedback. “Feedback” means any suggestions, bug fixes, enhancements, modifications, feature requests or other feedback regarding the SOFTWARE. For any Feedback that you voluntarily provide, you hereby grant NVIDIA and its affiliates a perpetual, non-exclusive, worldwide, irrevocable license to use, reproduce, modify, license, sublicense (through multiple tiers of sublicensees), and distribute (through multiple tiers of distributors) the Feedback without the payment of any royalties or fees to you. NVIDIA will use Feedback at its choice. + * + * 8. NO WARRANTIES. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. NVIDIA DOES NOT WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION THEREOF WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ALL ERRORS WILL BE CORRECTED. + * + * 9. LIMITATIONS OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY LAW, NVIDIA AND ITS AFFILIATES SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR ANY LOST PROFITS, PROJECT DELAYS, LOSS OF USE, LOSS OF DATA OR LOSS OF GOODWILL, OR THE COSTS OF PROCURING SUBSTITUTE PRODUCTS, ARISING OUT OF OR IN CONNECTION WITH THIS LICENSE OR THE USE OR PERFORMANCE OF THE SOFTWARE, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCT LIABILITY OR ANY OTHER CAUSE OF ACTION OR THEORY OF LIABILITY, EVEN IF NVIDIA HAS PREVIOUSLY BEEN ADVISED OF, OR COULD REASONABLY HAVE FORESEEN, THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL NVIDIA’S AND ITS AFFILIATES TOTAL CUMULATIVE LIABILITY UNDER OR ARISING OUT OF THIS LICENSE EXCEED US$10.00. THE NATURE OF THE LIABILITY OR THE NUMBER OF CLAIMS OR SUITS SHALL NOT ENLARGE OR EXTEND THIS LIMIT. + * + * 10. TERMINATION. Your rights under this license will terminate automatically without notice from NVIDIA if you fail to comply with any term and condition of this license or if you commence or participate in any legal proceeding against NVIDIA with respect to the SOFTWARE. NVIDIA may terminate this license with advance written notice to you if NVIDIA decides to no longer provide the SOFTWARE in a country or, in NVIDIA’s sole discretion, the continued use of it is no longer commercially viable. Upon any termination of this license, you agree to promptly discontinue use of the SOFTWARE and destroy all copies in your possession or control. Your prior distributions in accordance with this license are not affected by the termination of this license. All provisions of this license will survive termination, except for the license granted to you. + * + * 11. APPLICABLE LAW. This license will be governed in all respects by the laws of the United States and of the State of Delaware as those laws are applied to contracts entered into and performed entirely within Delaware by Delaware residents, without regard to the conflicts of laws principles. The United Nations Convention on Contracts for the International Sale of Goods is specifically disclaimed. You agree to all terms of this Agreement in the English language. The state or federal courts residing in Santa Clara County, California shall have exclusive jurisdiction over any dispute or claim arising out of this license. Notwithstanding this, you agree that NVIDIA shall still be allowed to apply for injunctive remedies or an equivalent type of urgent legal relief in any jurisdiction. + * + * 12. NO ASSIGNMENT. This license and your rights and obligations thereunder may not be assigned by you by any means or operation of law without NVIDIA’s permission. Any attempted assignment not approved by NVIDIA in writing shall be void and of no effect. + * + * 13. EXPORT. The SOFTWARE is subject to United States export laws and regulations. You agree that you will not ship, transfer or export the SOFTWARE into any country, or use the SOFTWARE in any manner, prohibited by the United States Bureau of Industry and Security or economic sanctions regulations administered by the U.S. Department of Treasury’s Office of Foreign Assets Control (OFAC), or any applicable export laws, restrictions or regulations. These laws include restrictions on destinations, end users and end use. By accepting this license, you confirm that you are not a resident or citizen of any country currently embargoed by the U.S. and that you are not otherwise prohibited from receiving the SOFTWARE. + * + * 14. GOVERNMENT USE. The SOFTWARE has been developed entirely at private expense and is “commercial items” consisting of “commercial computer software” and “commercial computer software documentation” provided with RESTRICTED RIGHTS. Use, duplication or disclosure by the U.S. Government or a U.S. Government subcontractor is subject to the restrictions in this license pursuant to DFARS 227.7202-3(a) or as set forth in subparagraphs (b)(1) and (2) of the Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, as applicable. Contractor/manufacturer is NVIDIA, 2788 San Tomas Expressway, Santa Clara, CA 95051. + * + * 15. ENTIRE AGREEMENT. This license is the final, complete and exclusive agreement between the parties relating to the subject matter of this license and supersedes all prior or contemporaneous understandings and agreements relating to this subject matter, whether oral or written. If any court of competent jurisdiction determines that any provision of this license is illegal, invalid or unenforceable, the remaining provisions will remain in full force and effect. This license may only be modified in a writing signed by an authorized representative of each party. + * + * (v. August 20, 2021) + */ + +#ifndef _CUDA_ANNOTATED_PTR +#define _CUDA_ANNOTATED_PTR + +#include +#include + +#include "std/detail/__access_property" + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +class access_property { + private: + std::uint64_t __descriptor = 0; + + public: + struct shared {}; + struct global {}; + struct persisting { + _LIBCUDACXX_HOST_DEVICE constexpr operator cudaAccessProperty() const noexcept { + return cudaAccessProperty::cudaAccessPropertyPersisting; + } + }; + struct streaming { + _LIBCUDACXX_HOST_DEVICE constexpr operator cudaAccessProperty() const noexcept { + return cudaAccessProperty::cudaAccessPropertyStreaming; + } + }; + struct normal { + _LIBCUDACXX_HOST_DEVICE constexpr operator cudaAccessProperty() const noexcept { + return cudaAccessProperty::cudaAccessPropertyNormal; + } + }; + + _LIBCUDACXX_HOST_DEVICE constexpr access_property(global) noexcept : __descriptor(__detail_ap::__sm_80::__interleave_normal()) {} + _LIBCUDACXX_HOST_DEVICE constexpr access_property() noexcept : __descriptor(__detail_ap::__sm_80::__interleave_normal()) {} + constexpr access_property(access_property const&) noexcept = default; + access_property& operator=(const access_property& other) noexcept = default; + + _LIBCUDACXX_HOST_DEVICE constexpr access_property(normal, float __fraction) : __descriptor(__detail_ap::__interleave(normal{}, __fraction)) {} + _LIBCUDACXX_HOST_DEVICE constexpr access_property(streaming, float __fraction) : __descriptor(__detail_ap::__interleave(streaming{}, __fraction)) {} + _LIBCUDACXX_HOST_DEVICE constexpr access_property(persisting, float __fraction) : __descriptor(__detail_ap::__interleave(persisting{}, __fraction)) {} + _LIBCUDACXX_HOST_DEVICE constexpr access_property(normal, float __fraction, streaming) : __descriptor(__detail_ap::__interleave(normal{}, __fraction, streaming{})) {} + _LIBCUDACXX_HOST_DEVICE constexpr access_property(persisting, float __fraction, streaming) : __descriptor(__detail_ap::__interleave(persisting{}, __fraction, streaming{})) {} + + _LIBCUDACXX_HOST_DEVICE constexpr access_property(normal) noexcept : access_property(normal{}, 1.0) {} + _LIBCUDACXX_HOST_DEVICE constexpr access_property(streaming) noexcept : access_property(streaming{}, 1.0) {} + _LIBCUDACXX_HOST_DEVICE constexpr access_property(persisting) noexcept : access_property(persisting{}, 1.0) {} + + _LIBCUDACXX_HOST_DEVICE constexpr access_property(void* __ptr, std::size_t __hit_bytes, std::size_t __total_bytes, normal) + : __descriptor(__detail_ap::__block(__ptr, __hit_bytes, __total_bytes, normal{})) {} + _LIBCUDACXX_HOST_DEVICE constexpr access_property(void* __ptr, std::size_t __hit_bytes, std::size_t __total_bytes, streaming) + : __descriptor(__detail_ap::__block(__ptr, __hit_bytes, __total_bytes, streaming{})) {} + _LIBCUDACXX_HOST_DEVICE constexpr access_property(void* __ptr, std::size_t __hit_bytes, std::size_t __total_bytes, persisting) + : __descriptor(__detail_ap::__block(__ptr, __hit_bytes, __total_bytes, persisting{})) {} + _LIBCUDACXX_HOST_DEVICE constexpr access_property(void* __ptr, std::size_t __hit_bytes, std::size_t __total_bytes, normal, streaming) + : __descriptor(__detail_ap::__block(__ptr, __hit_bytes, __total_bytes, normal{}, streaming{})) {} + _LIBCUDACXX_HOST_DEVICE constexpr access_property(void* __ptr, std::size_t __hit_bytes, std::size_t __total_bytes, persisting, streaming) + : __descriptor(__detail_ap::__block(__ptr, __hit_bytes, __total_bytes, persisting{}, streaming{})) {} + + _LIBCUDACXX_HOST_DEVICE constexpr explicit operator std::uint64_t() const noexcept { return __descriptor; } +}; + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#include "std/detail/__annotated_ptr" + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +template +_LIBCUDACXX_HOST_DEVICE +_Tp* associate_access_property(_Tp* __ptr, _Property __prop) { + static_assert( + std::is_same<_Property, access_property>::value || + std::is_same<_Property, access_property::persisting>::value || + std::is_same<_Property, access_property::streaming>::value || + std::is_same<_Property, access_property::normal>::value || + std::is_same<_Property, access_property::global>::value || + std::is_same<_Property, access_property::shared>::value + , "property is not convertible to cuda::access_property"); + return __detail_ap::__associate(__ptr, __prop); +} + +template +_LIBCUDACXX_HOST_DEVICE +void apply_access_property(const volatile void* __ptr, const _Shape __shape, access_property::persisting __prop) noexcept { + NV_IF_TARGET(NV_PROVIDES_SM_80,( + if (!__isGlobal((void*)__ptr)) return; + + char* __p = reinterpret_cast(const_cast(__ptr)); + static constexpr std::size_t _LINE_SIZE = 128; + std::size_t __nbytes = static_cast(__shape); + std::size_t __end = ((std::uintptr_t)(__p + __nbytes) % _LINE_SIZE) ? __nbytes + _LINE_SIZE : __nbytes; + __end /= _LINE_SIZE; + + //Apply to all 128 bytes aligned cache lines inclusive of __p + for (std::size_t __i = 0; __i < __end; __i += _LINE_SIZE) { + asm volatile ("prefetch.global.L2::evict_last [%0];" ::"l"(__p + (__i * _LINE_SIZE)) :); + } + )) +} + +template +_LIBCUDACXX_HOST_DEVICE +void apply_access_property(const volatile void* __ptr, const _Shape __shape, access_property::normal __prop) noexcept { + NV_IF_TARGET(NV_PROVIDES_SM_80,( + if (!__isGlobal((void*)__ptr)) return; + + char* __p = reinterpret_cast(const_cast(__ptr)); + static constexpr std::size_t _LINE_SIZE = 128; + std::size_t __nbytes = static_cast(__shape); + std::size_t __end = ((std::uintptr_t)(__p + __nbytes) % _LINE_SIZE) ? __nbytes + _LINE_SIZE : __nbytes; + __end /= _LINE_SIZE; + + //Apply to all 128 bytes aligned cache lines inclusive of __p + for (std::size_t __i = 0; __i < __end; __i += _LINE_SIZE) { + asm volatile ("prefetch.global.L2::evict_normal [%0];" ::"l"(__p + (__i * _LINE_SIZE)) :); + } + )) +} + +inline +_LIBCUDACXX_HOST_DEVICE +void discard_memory(volatile void* __ptr, std::size_t __nbytes) noexcept { + NV_IF_TARGET(NV_PROVIDES_SM_80,( + if (!__isGlobal((void*)__ptr)) return; + + char* __p = reinterpret_cast(const_cast(__ptr)); + static constexpr std::size_t _LINE_SIZE = 128; + std::size_t __start = (reinterpret_cast(__p) % _LINE_SIZE) ? 1 : 0; + std::size_t __end = (reinterpret_cast(__p + __nbytes) % _LINE_SIZE) ? __nbytes - _LINE_SIZE : __nbytes; + __end /= _LINE_SIZE; + + //Trim the first block and last block if they're not 128 bytes aligned + for (std::size_t __i = __start; __i < __end; __i += _LINE_SIZE) { + asm volatile ("discard.global.L2 [%0], 128;" ::"l"(__p + (__i * _LINE_SIZE)) :); + } + )) +} + +template +class annotated_ptr: public __detail_ap::__annotated_ptr_base<_Property> { + public: + using value_type = _Tp; + using size_type = std::size_t; + using reference = value_type&; + using pointer = value_type*; + using const_pointer = value_type const*; + using difference_type = std::ptrdiff_t; + + private: + using __self = annotated_ptr<_Tp, _Property>; + + // Converting from a 64-bit to 32-bit shared pointer and maybe back just for storage might or might not be profitable. + pointer __repr = (pointer)((size_type)nullptr); + + _LIBCUDACXX_HOST_DEVICE pointer __get(bool __skip_prop = false, difference_type __n = 0) const { + NV_IF_TARGET(NV_IS_DEVICE,( + if (!__skip_prop) { + return static_cast(this->__apply_prop(const_cast(static_cast(__repr + __n)))); + } + )) + return __repr + __n; + } + _LIBCUDACXX_HOST_DEVICE pointer __offset(difference_type __n, bool __skip_prop = false) const { + return __get(__skip_prop, __n); + } + + public: + _LIBCUDACXX_HOST_DEVICE pointer operator->() const { + return __get(); + } + + _LIBCUDACXX_HOST_DEVICE reference operator*() const { + return *__get(); + } + + _LIBCUDACXX_HOST_DEVICE reference operator[](difference_type __n) const { + return *__offset(__n); + } + + _LIBCUDACXX_HOST_DEVICE constexpr difference_type operator-(annotated_ptr o) const { + return __repr - o.__repr; + } + + constexpr annotated_ptr() noexcept = default; + constexpr annotated_ptr(annotated_ptr const&) noexcept = default; + // No constexpr for c11 as the method can't be const + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 annotated_ptr& operator=(annotated_ptr const& other) noexcept = default; + + _LIBCUDACXX_HOST_DEVICE explicit annotated_ptr(pointer __p) + : __repr(__p) + { + NV_IF_TARGET(NV_IS_DEVICE,( + _LIBCUDACXX_DEBUG_ASSERT((std::is_same<_Property, shared>::value && __isShared(__p) || __isGlobal(__p)), ""); + )) + } + + template + _LIBCUDACXX_HOST_DEVICE annotated_ptr(pointer __p, _RuntimeProperty __prop) + : __detail_ap::__annotated_ptr_base<_Property>(static_cast(access_property(__prop))), __repr(__p) + { + static_assert(std::is_same<_Property, access_property>::value, + "This method requires annotated_ptr"); + static_assert(std::is_same<_RuntimeProperty, access_property::global>::value || + std::is_same<_RuntimeProperty, access_property::normal>::value || + std::is_same<_RuntimeProperty, access_property::streaming>::value || + std::is_same<_RuntimeProperty, access_property::persisting>::value || + std::is_same<_RuntimeProperty, access_property>::value, + "This method requires RuntimeProperty=global|normal|streaming|persisting|access_property"); + NV_IF_TARGET(NV_IS_DEVICE,( + _LIBCUDACXX_DEBUG_ASSERT((__isGlobal(__p) == true), ""); + )) + } + + template + _LIBCUDACXX_HOST_DEVICE annotated_ptr(const annotated_ptr<_TTp,_Prop>& __other); + + _LIBCUDACXX_HOST_DEVICE constexpr explicit operator bool() const noexcept { + return __repr != nullptr; + } + + _LIBCUDACXX_HOST_DEVICE pointer get() const noexcept { + constexpr bool __is_shared = std::is_same<_Property, access_property::shared>::value; + return __is_shared ? __repr : &(*annotated_ptr(__repr)); + } + + _LIBCUDACXX_HOST_DEVICE _Property __property() const noexcept { + return this->__get_property(); + } +}; + + +template +template +_LIBCUDACXX_HOST_DEVICE annotated_ptr<_Tp, _Property>::annotated_ptr(const annotated_ptr<_TTp,_Prop>& __other) + : __detail_ap::__annotated_ptr_base<_Property>(__other.__property()), __repr(__other.get()) +{ + static_assert(std::is_assignable::value, "pointer must be assignable from other pointer"); + static_assert((std::is_same<_Property, access_property>::value && !std::is_same<_Prop, access_property::shared>::value) || + std::is_same<_Property, _Prop>::value, "Property must be either access_property or other property, and both properties must have same address space"); + // note: precondition "__other.__rep must be compatible with _Property" currently always holds +} + +template +_LIBCUDACXX_HOST_DEVICE +void memcpy_async(_Dst* __dst, + annotated_ptr<_Src,_SrcProperty> __src, + _Shape __shape, _Sync & __sync) { + memcpy_async(__dst, &(*__src), __shape, __sync); +} + +template +_LIBCUDACXX_HOST_DEVICE +void memcpy_async(annotated_ptr<_Dst,_DstProperty> __dst, + annotated_ptr<_Src,_SrcProperty> __src, + _Shape __shape, _Sync & __sync){ + memcpy_async(&(*__dst), &(*__src), __shape, __sync); +} + +template +_LIBCUDACXX_HOST_DEVICE +void memcpy_async(const _Group & __group, + _Dst * __dst, + annotated_ptr<_Src,_SrcProperty> __src, + _Shape __shape, _Sync & __sync) { + memcpy_async(__group, __dst, &(*__src), __shape, __sync); +} + +template +_LIBCUDACXX_HOST_DEVICE +void memcpy_async(const _Group & __group, + annotated_ptr<_Dst,_DstProperty> __dst, + annotated_ptr<_Src,_SrcProperty> __src, + _Shape __shape, _Sync & __sync) { + memcpy_async(__group, &(*__dst), &(*__src), __shape, __sync); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CUDA_ANNOTATED_PTR diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/atomic b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/atomic new file mode 100644 index 0000000000000000000000000000000000000000..8f8b3673236d803e41a6e4fb2aacad875216a3a0 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/atomic @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_ATOMIC +#define _CUDA_ATOMIC + +#include "std/atomic" + +#endif // _CUDA_ATOMIC diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/barrier b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/barrier new file mode 100644 index 0000000000000000000000000000000000000000..7e57cd585f8ac55cce730b5ebfd7fe84e06395f8 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/barrier @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_BARRIER +#define _CUDA_BARRIER + +#include "std/barrier" + +#endif // _CUDA_BARRIER diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/functional b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/functional new file mode 100644 index 0000000000000000000000000000000000000000..40343338c901736baf945dd37a15f28fc176687e --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/functional @@ -0,0 +1,155 @@ +// -*- C++ -*- +/* + * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * NVIDIA SOFTWARE LICENSE + * + * This license is a legal agreement between you and NVIDIA Corporation ("NVIDIA") and governs your use of the NVIDIA/CUDA C++ Library software and materials provided hereunder (“SOFTWARE”). + * + * This license can be accepted only by an adult of legal age of majority in the country in which the SOFTWARE is used. If you are under the legal age of majority, you must ask your parent or legal guardian to consent to this license. By taking delivery of the SOFTWARE, you affirm that you have reached the legal age of majority, you accept the terms of this license, and you take legal and financial responsibility for the actions of your permitted users. + * + * You agree to use the SOFTWARE only for purposes that are permitted by (a) this license, and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions. + * + * 1. LICENSE. Subject to the terms of this license, NVIDIA grants you a non-exclusive limited license to: (a) install and use the SOFTWARE, and (b) distribute the SOFTWARE subject to the distribution requirements described in this license. NVIDIA reserves all rights, title and interest in and to the SOFTWARE not expressly granted to you under this license. + * + * 2. DISTRIBUTION REQUIREMENTS. These are the distribution requirements for you to exercise the distribution grant: + * a. The terms under which you distribute the SOFTWARE must be consistent with the terms of this license, including (without limitation) terms relating to the license grant and license restrictions and protection of NVIDIA’s intellectual property rights. + * b. You agree to notify NVIDIA in writing of any known or suspected distribution or use of the SOFTWARE not in compliance with the requirements of this license, and to enforce the terms of your agreements with respect to distributed SOFTWARE. + * + * 3. LIMITATIONS. Your license to use the SOFTWARE is restricted as follows: + * a. The SOFTWARE is licensed for you to develop applications only for use in systems with NVIDIA GPUs. + * b. You may not reverse engineer, decompile or disassemble, or remove copyright or other proprietary notices from any portion of the SOFTWARE or copies of the SOFTWARE. + * c. You may not modify or create derivative works of any portion of the SOFTWARE. + * d. You may not bypass, disable, or circumvent any technical measure, encryption, security, digital rights management or authentication mechanism in the SOFTWARE. + * e. You may not use the SOFTWARE in any manner that would cause it to become subject to an open source software license. As examples, licenses that require as a condition of use, modification, and/or distribution that the SOFTWARE be (i) disclosed or distributed in source code form; (ii) licensed for the purpose of making derivative works; or (iii) redistributable at no charge. + * f. Unless you have an agreement with NVIDIA for this purpose, you may not use the SOFTWARE with any system or application where the use or failure of the system or application can reasonably be expected to threaten or result in personal injury, death, or catastrophic loss. Examples include use in avionics, navigation, military, medical, life support or other life critical applications. NVIDIA does not design, test or manufacture the SOFTWARE for these critical uses and NVIDIA shall not be liable to you or any third party, in whole or in part, for any claims or damages arising from such uses. + * g. You agree to defend, indemnify and hold harmless NVIDIA and its affiliates, and their respective employees, contractors, agents, officers and directors, from and against any and all claims, damages, obligations, losses, liabilities, costs or debt, fines, restitutions and expenses (including but not limited to attorney’s fees and costs incident to establishing the right of indemnification) arising out of or related to use of the SOFTWARE outside of the scope of this Agreement, or not in compliance with its terms. + * + * 4. PRE-RELEASE. SOFTWARE versions identified as alpha, beta, preview, early access or otherwise as pre-release may not be fully functional, may contain errors or design flaws, and may have reduced or different security, privacy, availability, and reliability standards relative to commercial versions of NVIDIA software and materials. You may use a pre-release SOFTWARE version at your own risk, understanding that these versions are not intended for use in production or business-critical systems. + * + * 5. OWNERSHIP. The SOFTWARE and the related intellectual property rights therein are and will remain the sole and exclusive property of NVIDIA or its licensors. The SOFTWARE is copyrighted and protected by the laws of the United States and other countries, and international treaty provisions. NVIDIA may make changes to the SOFTWARE, at any time without notice, but is not obligated to support or update the SOFTWARE. + * + * 6. COMPONENTS UNDER OTHER LICENSES. The SOFTWARE may include NVIDIA or third-party components with separate legal notices or terms as may be described in proprietary notices accompanying the SOFTWARE. If and to the extent there is a conflict between the terms in this license and the license terms associated with a component, the license terms associated with the components control only to the extent necessary to resolve the conflict. + * + * 7. FEEDBACK. You may, but don’t have to, provide to NVIDIA any Feedback. “Feedback” means any suggestions, bug fixes, enhancements, modifications, feature requests or other feedback regarding the SOFTWARE. For any Feedback that you voluntarily provide, you hereby grant NVIDIA and its affiliates a perpetual, non-exclusive, worldwide, irrevocable license to use, reproduce, modify, license, sublicense (through multiple tiers of sublicensees), and distribute (through multiple tiers of distributors) the Feedback without the payment of any royalties or fees to you. NVIDIA will use Feedback at its choice. + * + * 8. NO WARRANTIES. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. NVIDIA DOES NOT WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION THEREOF WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ALL ERRORS WILL BE CORRECTED. + * + * 9. LIMITATIONS OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY LAW, NVIDIA AND ITS AFFILIATES SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR ANY LOST PROFITS, PROJECT DELAYS, LOSS OF USE, LOSS OF DATA OR LOSS OF GOODWILL, OR THE COSTS OF PROCURING SUBSTITUTE PRODUCTS, ARISING OUT OF OR IN CONNECTION WITH THIS LICENSE OR THE USE OR PERFORMANCE OF THE SOFTWARE, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCT LIABILITY OR ANY OTHER CAUSE OF ACTION OR THEORY OF LIABILITY, EVEN IF NVIDIA HAS PREVIOUSLY BEEN ADVISED OF, OR COULD REASONABLY HAVE FORESEEN, THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL NVIDIA’S AND ITS AFFILIATES TOTAL CUMULATIVE LIABILITY UNDER OR ARISING OUT OF THIS LICENSE EXCEED US$10.00. THE NATURE OF THE LIABILITY OR THE NUMBER OF CLAIMS OR SUITS SHALL NOT ENLARGE OR EXTEND THIS LIMIT. + * + * 10. TERMINATION. Your rights under this license will terminate automatically without notice from NVIDIA if you fail to comply with any term and condition of this license or if you commence or participate in any legal proceeding against NVIDIA with respect to the SOFTWARE. NVIDIA may terminate this license with advance written notice to you if NVIDIA decides to no longer provide the SOFTWARE in a country or, in NVIDIA’s sole discretion, the continued use of it is no longer commercially viable. Upon any termination of this license, you agree to promptly discontinue use of the SOFTWARE and destroy all copies in your possession or control. Your prior distributions in accordance with this license are not affected by the termination of this license. All provisions of this license will survive termination, except for the license granted to you. + * + * 11. APPLICABLE LAW. This license will be governed in all respects by the laws of the United States and of the State of Delaware as those laws are applied to contracts entered into and performed entirely within Delaware by Delaware residents, without regard to the conflicts of laws principles. The United Nations Convention on Contracts for the International Sale of Goods is specifically disclaimed. You agree to all terms of this Agreement in the English language. The state or federal courts residing in Santa Clara County, California shall have exclusive jurisdiction over any dispute or claim arising out of this license. Notwithstanding this, you agree that NVIDIA shall still be allowed to apply for injunctive remedies or an equivalent type of urgent legal relief in any jurisdiction. + * + * 12. NO ASSIGNMENT. This license and your rights and obligations thereunder may not be assigned by you by any means or operation of law without NVIDIA’s permission. Any attempted assignment not approved by NVIDIA in writing shall be void and of no effect. + * + * 13. EXPORT. The SOFTWARE is subject to United States export laws and regulations. You agree that you will not ship, transfer or export the SOFTWARE into any country, or use the SOFTWARE in any manner, prohibited by the United States Bureau of Industry and Security or economic sanctions regulations administered by the U.S. Department of Treasury’s Office of Foreign Assets Control (OFAC), or any applicable export laws, restrictions or regulations. These laws include restrictions on destinations, end users and end use. By accepting this license, you confirm that you are not a resident or citizen of any country currently embargoed by the U.S. and that you are not otherwise prohibited from receiving the SOFTWARE. + * + * 14. GOVERNMENT USE. The SOFTWARE has been developed entirely at private expense and is “commercial items” consisting of “commercial computer software” and “commercial computer software documentation” provided with RESTRICTED RIGHTS. Use, duplication or disclosure by the U.S. Government or a U.S. Government subcontractor is subject to the restrictions in this license pursuant to DFARS 227.7202-3(a) or as set forth in subparagraphs (b)(1) and (2) of the Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, as applicable. Contractor/manufacturer is NVIDIA, 2788 San Tomas Expressway, Santa Clara, CA 95051. + * + * 15. ENTIRE AGREEMENT. This license is the final, complete and exclusive agreement between the parties relating to the subject matter of this license and supersedes all prior or contemporaneous understandings and agreements relating to this subject matter, whether oral or written. If any court of competent jurisdiction determines that any provision of this license is illegal, invalid or unenforceable, the remaining provisions will remain in full force and effect. This license may only be modified in a writing signed by an authorized representative of each party. + * + * (v. August 20, 2021) + */ + +#ifndef _CUDA_FUNCTIONAL_ +#define _CUDA_FUNCTIONAL_ + +#include +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA +namespace __detail +{ + +template +class __return_type_wrapper { + private: + _DecayFn __fn_; + + public: + __return_type_wrapper() = delete; + + template , _DecayFn>::value>> + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 + explicit __return_type_wrapper(_Fn &&__fn) noexcept + : __fn_(_CUDA_VSTD::forward<_Fn>(__fn)) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 + _Ret operator()(_As&&... __as) & noexcept { +#if !defined(__NVCC__) || defined(__CUDA_ARCH__) + static_assert( + _CUDA_VSTD::is_same< + _Ret, + typename _CUDA_VSTD::__invoke_of<_DecayFn&, _As...>::type + >::value, + "Return type shall match the proclaimed one exactly"); +#endif + + return _CUDA_VSTD::__invoke(__fn_, _CUDA_VSTD::forward<_As>(__as)...); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 + _Ret operator()(_As&&... __as) && noexcept { +#if !defined(__NVCC__) || defined(__CUDA_ARCH__) + static_assert( + _CUDA_VSTD::is_same< + _Ret, + typename _CUDA_VSTD::__invoke_of<_DecayFn, _As...>::type + >::value, + "Return type shall match the proclaimed one exactly"); +#endif + + return _CUDA_VSTD::__invoke(_CUDA_VSTD::move(__fn_), + _CUDA_VSTD::forward<_As>(__as)...); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 + _Ret operator()(_As&&... __as) const& noexcept { +#if !defined(__NVCC__) || defined(__CUDA_ARCH__) + static_assert( + _CUDA_VSTD::is_same< + _Ret, + typename _CUDA_VSTD::__invoke_of::type + >::value, + "Return type shall match the proclaimed one exactly"); +#endif + + return _CUDA_VSTD::__invoke(__fn_, _CUDA_VSTD::forward<_As>(__as)...); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 + _Ret operator()(_As&&... __as) const&& noexcept { +#if !defined(__NVCC__) || defined(__CUDA_ARCH__) + static_assert( + _CUDA_VSTD::is_same< + _Ret, + typename _CUDA_VSTD::__invoke_of::type + >::value, + "Return type shall match the proclaimed one exactly"); +#endif + + return _CUDA_VSTD::__invoke(_CUDA_VSTD::move(__fn_), + _CUDA_VSTD::forward<_As>(__as)...); + } +}; + +} // __detail + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__detail::__return_type_wrapper<_Ret, _CUDA_VSTD::__decay_t<_Fn>> +proclaim_return_type(_Fn&& __fn) noexcept { + return __detail::__return_type_wrapper<_Ret, _CUDA_VSTD::__decay_t<_Fn>>( + _CUDA_VSTD::forward<_Fn>(__fn)); +} +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CUDA_FUNCTIONAL_ + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/latch b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/latch new file mode 100644 index 0000000000000000000000000000000000000000..e78c1287505173c76dee9ae1e8012473f77a3807 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/latch @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_LATCH +#define _CUDA_LATCH + +#include "std/latch" + +#endif // _CUDA_LATCH diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/memory_resource b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/memory_resource new file mode 100644 index 0000000000000000000000000000000000000000..368ada07284f495328d9153f371cbf85e1b1c351 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/memory_resource @@ -0,0 +1,632 @@ +//===----------------------------------------------------------------------===// +// +// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_MEMORY_RESOURCE +#define _CUDA_MEMORY_RESOURCE + +// clang-format off +/* + memory_resource synopsis +namespace cuda { +namespace mr { +template +concept resource = equality_comparable + && requires(Resource& res, void* ptr, size_t size, size_t alignment) { + { res.allocate(size, alignment) } -> same_as; + { res.deallocate(ptr, size, alignment) } -> same_as; +}; + +template +concept async_resource = resource + && requires(Resource& res, void* ptr, size_t size, size_t alignment, cuda_stream_ref stream) { + { res.allocate_async(size, alignment, stream) } -> same_as; + { res.deallocate_async(ptr, size, alignment, stream) } -> same_as; +}; + +template +concept has_property = resource && requires(const Resource& res, Property prop) { + get_property(res, prop); +}; + +template +concept property_with_value = requires { + typename Property::value_type; +}; + +template +concept has_property_with = resource + && property_with_value + && same_as + && requires(const Resource& res, Property prop) { + get_property(res, prop) -> Return; +}; + +template +concept resource_with = resource && (has_property && ...); + +template +concept async_resource_with = async_resource && (has_property && ...); + +template +class resource_ref { + template Resource> + resource_ref(Resource&) noexcept; + + void* allocate(size_t size, size_t alignment); + void deallocate(void* ptr, size_t size, size_t alignment); + + template + requires resource_with + && resource_with, Properties...> + friend bool operator==(const resource_ref& left, const resource_ref& right); + + template + requires has_property + friend typename Property::value_type get_property(const resource_ref& ref, Property) noexcept; + + template + requires (has_property && !property_with_value) + friend void get_property(const resource_ref& ref, Property) noexcept; +}; + +} // mr +} // cuda +*/ +// clang-format on + +#ifdef LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE + +#include + +#include +#include + +#include + +#include + +#if _LIBCUDACXX_STD_VER > 11 +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +/////////////////////////////////////////////////////////////////////////////// +// properties + +/// \concept has_property +/// \brief The \c has_property concept +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __has_property_, + requires(const _Resource& __res)( + get_property(__res, _Property{}) + )); +template +_LIBCUDACXX_CONCEPT has_property = _LIBCUDACXX_FRAGMENT(__has_property_, _Resource, _Property); + +/// \concept property_with_value +/// \brief The \c property_with_value concept +template +using __property_value_t = typename _Property::value_type; + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __property_with_value_, + requires()( + typename(__property_value_t<_Property>) + )); +template +_LIBCUDACXX_CONCEPT property_with_value = _LIBCUDACXX_FRAGMENT(__property_with_value_, _Property); + +/// \concept has_property_with +/// \brief The \c has_property_with concept +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __has_property_with_, + requires(const _Resource& __res)( + requires(property_with_value<_Property>), + requires(_CUDA_VSTD::same_as<_Return, decltype(get_property(__res, _Property{}))>) + )); +template +_LIBCUDACXX_CONCEPT has_property_with = _LIBCUDACXX_FRAGMENT(__has_property_with_, _Resource, _Property, _Return); + +/// \concept __has_upstream_resource +/// \brief The \c __has_upstream_resource concept +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __has_upstream_resource_, + requires(const _Resource& __res)( + requires(_CUDA_VSTD::same_as<_CUDA_VSTD::__remove_const_ref_t, _Upstream>) + )); +template +_LIBCUDACXX_CONCEPT __has_upstream_resource = _LIBCUDACXX_FRAGMENT(__has_upstream_resource_, _Resource, _Upstream); + +/// class forward_property +/// \brief The \c forward_property crtp template simplifies the user facing side of forwarding properties +/// We can just derive from it to properly forward all properties +_LIBCUDACXX_BEGIN_NAMESPACE_CPO(__forward_property) +template +struct __fn { + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_TEMPLATE(class _Property) + (requires (!property_with_value<_Property>) _LIBCUDACXX_AND has_property<_Upstream, _Property>) + _LIBCUDACXX_INLINE_VISIBILITY friend constexpr void get_property(const _Derived&, _Property) noexcept {} + + // The indirection is needed, otherwise the compiler might believe that _Derived is an incomplete type + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_TEMPLATE(class _Property, class _Derived2 = _Derived) + (requires property_with_value<_Property> _LIBCUDACXX_AND has_property<_Upstream, _Property> _LIBCUDACXX_AND + __has_upstream_resource<_Derived2, _Upstream>) + _LIBCUDACXX_INLINE_VISIBILITY friend constexpr __property_value_t<_Property> get_property( + const _Derived& __res, _Property __prop) { + return get_property(__res.upstream_resource(), __prop); + } +}; +_LIBCUDACXX_END_NAMESPACE_CPO + +template +using forward_property = __forward_property::__fn<_Derived, _Upstream>; + +/// class get_property +/// \brief The \c get_property crtp temaplate simplifies the user facing side of forwarding properties +/// We can always tell people to just derive from it to properly forward all properties +_LIBCUDACXX_BEGIN_NAMESPACE_CPO(__get_property) +struct __fn { + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_TEMPLATE(class _Upstream, class _Property) + (requires (!property_with_value<_Property>) _LIBCUDACXX_AND has_property<_Upstream, _Property>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr void operator()(const _Upstream&, _Property) const noexcept {} + + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_TEMPLATE(class _Upstream, class _Property) + (requires (property_with_value<_Property>) _LIBCUDACXX_AND has_property<_Upstream, _Property>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr __property_value_t<_Property> operator()( + const _Upstream& __res, _Property __prop) const { + return get_property(__res, __prop); + } +}; +_LIBCUDACXX_END_NAMESPACE_CPO + +inline namespace __cpo { + _LIBCUDACXX_CPO_ACCESSIBILITY auto get_property = __get_property::__fn{}; +} // namespace __cpo + +namespace mr +{ + +/////////////////////////////////////////////////////////////////////////////// +// memory_resource + +/// \concept resource +/// \brief The \c resource concept +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __resource_, + requires(_Resource& __res, void* __ptr, size_t __bytes, size_t __alignment) ( + requires(_CUDA_VSTD::same_as), + requires(_CUDA_VSTD::same_as), + requires(_CUDA_VSTD::equality_comparable<_Resource>) + )); + +template +_LIBCUDACXX_CONCEPT resource = _LIBCUDACXX_FRAGMENT(__resource_, _Resource); + +/// \concept async_resource +/// \brief The \c async_resource concept +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __async_resource_, + requires(_Resource& __res, void* __ptr, size_t __bytes, size_t __alignment, cuda::stream_ref __stream) ( + requires(resource<_Resource>), + requires(_CUDA_VSTD::same_as), + requires(_CUDA_VSTD::same_as), + requires(_CUDA_VSTD::equality_comparable<_Resource>) + )); + +template +_LIBCUDACXX_CONCEPT async_resource = _LIBCUDACXX_FRAGMENT(__async_resource_, _Resource); + +/// \concept resource_with +/// \brief The \c resource_with concept +template +#if _LIBCUDACXX_STD_VER < 17 +_LIBCUDACXX_CONCEPT resource_with = + resource<_Resource>&& _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant>...>; +#else +_LIBCUDACXX_CONCEPT resource_with = resource<_Resource> && (has_property<_Resource, _Properties> && ...); +#endif + +/// \concept async_resource_with +/// \brief The \c async_resource_with concept +template +#if _LIBCUDACXX_STD_VER < 17 +_LIBCUDACXX_CONCEPT async_resource_with = async_resource<_Resource> && + _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant>...>; +#else +_LIBCUDACXX_CONCEPT async_resource_with = async_resource<_Resource> && + (has_property<_Resource, _Properties> && ...); +#endif + +/////////////////////////////////////////////////////////////////////////////// +/// class resource_ref +/// class async_resource_ref +enum class _AllocType +{ + _Default, + _Async, +}; + +struct _Alloc_vtable +{ + using _AllocFn = void* (*)(void*, size_t, size_t); + using _DeallocFn = void (*)(void*, void*, size_t, size_t); + using _EqualFn = bool (*)(void*, void*); + + _AllocFn __alloc_fn; + _DeallocFn __dealloc_fn; + _EqualFn __equal_fn; + + constexpr _Alloc_vtable(_AllocFn __alloc_fn_, _DeallocFn __dealloc_fn_, _EqualFn __equal_fn_) noexcept + : __alloc_fn(__alloc_fn_) + , __dealloc_fn(__dealloc_fn_) + , __equal_fn(__equal_fn_) + {} +}; + +struct _Async_alloc_vtable : public _Alloc_vtable +{ + using _AsyncAllocFn = void* (*)(void*, size_t, size_t, cuda::stream_ref); + using _AsyncDeallocFn = void (*)(void*, void*, size_t, size_t, cuda::stream_ref); + + _AsyncAllocFn __async_alloc_fn; + _AsyncDeallocFn __async_dealloc_fn; + + constexpr _Async_alloc_vtable(_Alloc_vtable::_AllocFn __alloc_fn_, + _Alloc_vtable::_DeallocFn __dealloc_fn_, + _Alloc_vtable::_EqualFn __equal_fn_, + _AsyncAllocFn __async_alloc_fn_, + _AsyncDeallocFn __async_dealloc_fn_) noexcept + : _Alloc_vtable(__alloc_fn_, __dealloc_fn_, __equal_fn_) + , __async_alloc_fn(__async_alloc_fn_) + , __async_dealloc_fn(__async_dealloc_fn_) + {} +}; + +// clang-format off +struct _Resource_vtable_builder +{ + template + static __property_value_t<_Property> _Get_property(void* __res) noexcept { + return get_property(*static_cast(__res), _Property{}); + } + + template + static void* _Alloc(void* __object, size_t __bytes, size_t __alignment) { + return static_cast<_Resource *>(__object)->allocate(__bytes, __alignment); + } + + template + static void _Dealloc(void* __object, void* __ptr, size_t __bytes, size_t __alignment) { + return static_cast<_Resource *>(__object)->deallocate(__ptr, __bytes, __alignment); + } + + template + static void* _Alloc_async(void* __object, size_t __bytes, size_t __alignment, cuda::stream_ref __stream) { + return static_cast<_Resource *>(__object)->allocate_async(__bytes, __alignment, __stream); + } + + template + static void _Dealloc_async(void* __object, void* __ptr, size_t __bytes, size_t __alignment, cuda::stream_ref __stream) { + return static_cast<_Resource *>(__object)->deallocate_async(__ptr, __bytes, __alignment, __stream); + } + + template + static bool _Equal(void* __left, void* __right) { + return *static_cast<_Resource *>(__left) == *static_cast<_Resource *>(__right); + } + + _LIBCUDACXX_TEMPLATE(class _Resource, _AllocType _Alloc_type) + (requires(_Alloc_type == _AllocType::_Default)) // + static constexpr _Alloc_vtable _Create() noexcept + { + return {&_Resource_vtable_builder::_Alloc<_Resource>, + &_Resource_vtable_builder::_Dealloc<_Resource>, + &_Resource_vtable_builder::_Equal<_Resource>}; + } + + _LIBCUDACXX_TEMPLATE(class _Resource, _AllocType _Alloc_type) + (requires(_Alloc_type == _AllocType::_Async)) // + static constexpr _Async_alloc_vtable _Create() noexcept + { + return {&_Resource_vtable_builder::_Alloc<_Resource>, + &_Resource_vtable_builder::_Dealloc<_Resource>, + &_Resource_vtable_builder::_Equal<_Resource>, + &_Resource_vtable_builder::_Alloc_async<_Resource>, + &_Resource_vtable_builder::_Dealloc_async<_Resource>}; + } +}; +// clang-format on + +template +struct _Property_vtable +{ + using _PropertyFn = __property_value_t<_Property> (*)(void*); + _PropertyFn __property_fn = nullptr; + + constexpr _Property_vtable(_PropertyFn __property_fn_) noexcept + : __property_fn(__property_fn_) + {} +}; + +template <_AllocType _Alloc_type, class... _Properties> // +class basic_resource_ref; + +template +struct _Resource_vtable : public _Property_vtable<_Properties>... +{ + template + constexpr _Resource_vtable(_PropertyFns... __property_fn_) noexcept + : _Property_vtable<_Properties>(__property_fn_)... + {} + + template <_AllocType _Alloc_type, class... _OtherProperties> + constexpr _Resource_vtable(basic_resource_ref<_Alloc_type, _OtherProperties...>& __ref) noexcept + : _Property_vtable<_Properties>(__ref._Property_vtable<_Properties>::__property_fn)... + {} + + template + static constexpr _Resource_vtable _Create() noexcept + { + return {&_Resource_vtable_builder::_Get_property<_Resource, _Properties>...}; + } +}; + +template +struct _Filtered; + +template +struct _Property_filter +{ + template + using _Filtered_properties = + typename _Filtered<_Properties...>::_Filtered_vtable::template _Append_property<_Property>; +}; +template <> +struct _Property_filter +{ + template + using _Filtered_properties = typename _Filtered<_Properties...>::_Filtered_vtable; +}; + +template +struct _Filtered<_Property, _Properties...> +{ + using _Filtered_vtable = + typename _Property_filter && !_CUDA_VSTD::_One_of<_Property, _Properties...>>:: + template _Filtered_properties<_Property, _Properties...>; + + template + using _Append_property = _Filtered<_OtherPropery, _Property, _Properties...>; + + using _Vtable = _Resource_vtable<_Property, _Properties...>; +}; + +template <> +struct _Filtered<> +{ + using _Filtered_vtable = _Filtered<>; + + template + using _Append_property = _Filtered<_OtherPropery>; + + using _Vtable = _Resource_vtable<>; +}; + +template +using _Filtered_vtable = typename _Filtered<_Properties...>::_Filtered_vtable::_Vtable; + +template +struct _Alloc_base +{ + static_assert(_CUDA_VSTD::is_base_of_v<_Alloc_vtable, _Vtable>, ""); + + _Alloc_base(void* __object_, const _Vtable* __static_vtabl_) noexcept + : __object(__object_) + , __static_vtable(__static_vtabl_) + {} + + void* allocate(size_t __bytes, size_t __alignment = alignof(max_align_t)) + { + return __static_vtable->__alloc_fn(__object, __bytes, __alignment); + } + + void deallocate(void* _Ptr, size_t __bytes, size_t __alignment = alignof(max_align_t)) + { + __static_vtable->__dealloc_fn(__object, _Ptr, __bytes, __alignment); + } + +protected: + void* __object = nullptr; + const _Vtable* __static_vtable = nullptr; +}; + +template +struct _Async_alloc_base : public _Alloc_base<_Vtable> +{ + static_assert(_CUDA_VSTD::is_base_of_v<_Async_alloc_vtable, _Vtable>, ""); + + _Async_alloc_base(void* __object_, const _Vtable* __static_vtabl_) noexcept + : _Alloc_base<_Vtable>(__object_, __static_vtabl_) + {} + + void* allocate_async(size_t __bytes, size_t __alignment, cuda::stream_ref __stream) + { + return this->__static_vtable->__async_alloc_fn(this->__object, __bytes, __alignment, __stream); + } + + void* allocate_async(size_t __bytes, cuda::stream_ref __stream) + { + return this->__static_vtable->__async_alloc_fn(this->__object, __bytes, alignof(max_align_t), __stream); + } + + void deallocate_async(void* _Ptr, size_t __bytes, cuda::stream_ref __stream) + { + this->__static_vtable->__async_dealloc_fn(this->__object, _Ptr, __bytes, alignof(max_align_t), __stream); + } + + void deallocate_async(void* _Ptr, size_t __bytes, size_t __alignment, cuda::stream_ref __stream) + { + this->__static_vtable->__async_dealloc_fn(this->__object, _Ptr, __bytes, __alignment, __stream); + } +}; + +template <_AllocType _Alloc_type> +using _Resource_ref_base = _CUDA_VSTD:: + _If<_Alloc_type == _AllocType::_Default, _Alloc_base<_Alloc_vtable>, _Async_alloc_base<_Async_alloc_vtable>>; + +template <_AllocType _Alloc_type> +using _Vtable_store = _CUDA_VSTD::_If<_Alloc_type == _AllocType::_Default, _Alloc_vtable, _Async_alloc_vtable>; + +template <_AllocType _Alloc_type, class _Resource> +_LIBCUDACXX_INLINE_VAR constexpr _Vtable_store<_Alloc_type> + __alloc_vtable = _Resource_vtable_builder::template _Create<_Resource, _Alloc_type>(); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool _Is_basic_resource_ref = false; + +template <_AllocType _Alloc_type, class... _Properties> // +class basic_resource_ref + : public _Resource_ref_base<_Alloc_type> + , private _Filtered_vtable<_Properties...> +{ +private: + template <_AllocType, class...> + friend class basic_resource_ref; + + template + friend struct _Resource_vtable; + +public: + // clang-format off + _LIBCUDACXX_TEMPLATE(class _Resource) + (requires (!_Is_basic_resource_ref<_Resource> + && (((_Alloc_type == _AllocType::_Default) && resource_with<_Resource, _Properties...>) // + ||((_Alloc_type == _AllocType::_Async) && async_resource_with<_Resource, _Properties...>)))) // + basic_resource_ref(_Resource& __res) noexcept + : _Resource_ref_base<_Alloc_type>(_CUDA_VSTD::addressof(__res), &__alloc_vtable<_Alloc_type, _Resource>) + , _Filtered_vtable<_Properties...>(_Filtered_vtable<_Properties...>::template _Create<_Resource>()) + {} + + _LIBCUDACXX_TEMPLATE(class _Resource) + (requires (!_Is_basic_resource_ref<_Resource> + && (((_Alloc_type == _AllocType::_Default) && resource_with<_Resource, _Properties...>) // + ||((_Alloc_type == _AllocType::_Async) && async_resource_with<_Resource, _Properties...>)))) // + basic_resource_ref(_Resource* __res) noexcept + : _Resource_ref_base<_Alloc_type>(__res, &__alloc_vtable<_Alloc_type, _Resource>) + , _Filtered_vtable<_Properties...>(_Filtered_vtable<_Properties...>::template _Create<_Resource>()) + {} + + #if _LIBCUDACXX_STD_VER > 14 + _LIBCUDACXX_TEMPLATE(class... _OtherProperties) + (requires (_CUDA_VSTD::_One_of<_Properties, _OtherProperties...> && ...)) + #else + _LIBCUDACXX_TEMPLATE(class... _OtherProperties) + (requires _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant< + _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>) + #endif + basic_resource_ref( + basic_resource_ref<_Alloc_type, _OtherProperties...> __ref) noexcept + : _Resource_ref_base<_Alloc_type>(__ref.__object, __ref.__static_vtable) + , _Filtered_vtable<_Properties...>(__ref) + {} + + #if _LIBCUDACXX_STD_VER > 14 + _LIBCUDACXX_TEMPLATE(class... _OtherProperties) + (requires (_Alloc_type == _AllocType::_Default) + && (_CUDA_VSTD::_One_of<_Properties, _OtherProperties...> && ...)) + #else + _LIBCUDACXX_TEMPLATE(class... _OtherProperties) + (requires (_Alloc_type == _AllocType::_Default) + && _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant< + _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>) + #endif + basic_resource_ref( + basic_resource_ref<_AllocType::_Async, _OtherProperties...> __ref) noexcept + : _Resource_ref_base<_Alloc_type>(__ref.__object, __ref.__static_vtable) + , _Filtered_vtable<_Properties...>(__ref) + {} + + #if _LIBCUDACXX_STD_VER > 14 + _LIBCUDACXX_TEMPLATE(class... _OtherProperties) + (requires(sizeof...(_Properties) == sizeof...(_OtherProperties)) + && (_CUDA_VSTD::_One_of<_Properties, _OtherProperties...> && ...)) + #else + _LIBCUDACXX_TEMPLATE(class... _OtherProperties) + (requires (sizeof...(_Properties) == sizeof...(_OtherProperties)) + && _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant< + _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>) + #endif + bool operator==( + const basic_resource_ref<_Alloc_type, _OtherProperties...> &__right) const { + return (this->__static_vtable->__equal_fn == __right.__static_vtable->__equal_fn) // + && this->__static_vtable->__equal_fn(this->__object, __right.__object); + } + + #if _LIBCUDACXX_STD_VER > 14 + _LIBCUDACXX_TEMPLATE(class... _OtherProperties) + (requires (sizeof...(_Properties) == sizeof...(_OtherProperties)) + && (_CUDA_VSTD::_One_of<_Properties, _OtherProperties...> && ...)) + #else + _LIBCUDACXX_TEMPLATE(class... _OtherProperties) + (requires (sizeof...(_Properties) == sizeof...(_OtherProperties)) + && _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant< + _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>) + #endif + bool operator!=( + const basic_resource_ref<_Alloc_type, _OtherProperties...> &__right) const { + return !(*this == __right); + } + + _LIBCUDACXX_TEMPLATE(class _Property) + (requires (!property_with_value<_Property>) _LIBCUDACXX_AND _CUDA_VSTD::_One_of<_Property, _Properties...>) // + friend void get_property(const basic_resource_ref &, _Property) noexcept {} + + _LIBCUDACXX_TEMPLATE(class _Property) + (requires property_with_value<_Property> _LIBCUDACXX_AND _CUDA_VSTD::_One_of<_Property, _Properties...>) // + friend __property_value_t<_Property> get_property( + const basic_resource_ref &__res, _Property) noexcept { + return __res._Property_vtable<_Property>::__property_fn(__res.__object); + } + // clang-format on +}; + +template <_AllocType _Alloc_type, class... _Properties> +_LIBCUDACXX_INLINE_VAR constexpr bool _Is_basic_resource_ref> = true; + +template // +using resource_ref = basic_resource_ref<_AllocType::_Default, _Properties...>; + +template // +using async_resource_ref = basic_resource_ref<_AllocType::_Async, _Properties...>; + +/// \struct device_accessible +/// \brief The \c device_accessible property signals that the allocated memory is device accessible +struct device_accessible{}; + +/// \struct host_accessible +/// \brief The \c host_accessible property signals that the allocated memory is host accessible +struct host_accessible{}; + +} // namespace mr +_LIBCUDACXX_END_NAMESPACE_CUDA +#endif // _LIBCUDACXX_STD_VER > 11 + +#include + +#endif // LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE + +#endif //_LIBCUDACXX_BEGIN_NAMESPACE_CUDA diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/pipeline b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/pipeline new file mode 100644 index 0000000000000000000000000000000000000000..ec5cbd1c93efb520cc2c79e2e7e7bb4640d9fe2c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/pipeline @@ -0,0 +1,575 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * NVIDIA SOFTWARE LICENSE + * + * This license is a legal agreement between you and NVIDIA Corporation ("NVIDIA") and governs your use of the NVIDIA/CUDA C++ Library software and materials provided hereunder (“SOFTWARE”). + * + * This license can be accepted only by an adult of legal age of majority in the country in which the SOFTWARE is used. If you are under the legal age of majority, you must ask your parent or legal guardian to consent to this license. By taking delivery of the SOFTWARE, you affirm that you have reached the legal age of majority, you accept the terms of this license, and you take legal and financial responsibility for the actions of your permitted users. + * + * You agree to use the SOFTWARE only for purposes that are permitted by (a) this license, and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions. + * + * 1. LICENSE. Subject to the terms of this license, NVIDIA grants you a non-exclusive limited license to: (a) install and use the SOFTWARE, and (b) distribute the SOFTWARE subject to the distribution requirements described in this license. NVIDIA reserves all rights, title and interest in and to the SOFTWARE not expressly granted to you under this license. + * + * 2. DISTRIBUTION REQUIREMENTS. These are the distribution requirements for you to exercise the distribution grant: + * a. The terms under which you distribute the SOFTWARE must be consistent with the terms of this license, including (without limitation) terms relating to the license grant and license restrictions and protection of NVIDIA’s intellectual property rights. + * b. You agree to notify NVIDIA in writing of any known or suspected distribution or use of the SOFTWARE not in compliance with the requirements of this license, and to enforce the terms of your agreements with respect to distributed SOFTWARE. + * + * 3. LIMITATIONS. Your license to use the SOFTWARE is restricted as follows: + * a. The SOFTWARE is licensed for you to develop applications only for use in systems with NVIDIA GPUs. + * b. You may not reverse engineer, decompile or disassemble, or remove copyright or other proprietary notices from any portion of the SOFTWARE or copies of the SOFTWARE. + * c. You may not modify or create derivative works of any portion of the SOFTWARE. + * d. You may not bypass, disable, or circumvent any technical measure, encryption, security, digital rights management or authentication mechanism in the SOFTWARE. + * e. You may not use the SOFTWARE in any manner that would cause it to become subject to an open source software license. As examples, licenses that require as a condition of use, modification, and/or distribution that the SOFTWARE be (i) disclosed or distributed in source code form; (ii) licensed for the purpose of making derivative works; or (iii) redistributable at no charge. + * f. Unless you have an agreement with NVIDIA for this purpose, you may not use the SOFTWARE with any system or application where the use or failure of the system or application can reasonably be expected to threaten or result in personal injury, death, or catastrophic loss. Examples include use in avionics, navigation, military, medical, life support or other life critical applications. NVIDIA does not design, test or manufacture the SOFTWARE for these critical uses and NVIDIA shall not be liable to you or any third party, in whole or in part, for any claims or damages arising from such uses. + * g. You agree to defend, indemnify and hold harmless NVIDIA and its affiliates, and their respective employees, contractors, agents, officers and directors, from and against any and all claims, damages, obligations, losses, liabilities, costs or debt, fines, restitutions and expenses (including but not limited to attorney’s fees and costs incident to establishing the right of indemnification) arising out of or related to use of the SOFTWARE outside of the scope of this Agreement, or not in compliance with its terms. + * + * 4. PRE-RELEASE. SOFTWARE versions identified as alpha, beta, preview, early access or otherwise as pre-release may not be fully functional, may contain errors or design flaws, and may have reduced or different security, privacy, availability, and reliability standards relative to commercial versions of NVIDIA software and materials. You may use a pre-release SOFTWARE version at your own risk, understanding that these versions are not intended for use in production or business-critical systems. + * + * 5. OWNERSHIP. The SOFTWARE and the related intellectual property rights therein are and will remain the sole and exclusive property of NVIDIA or its licensors. The SOFTWARE is copyrighted and protected by the laws of the United States and other countries, and international treaty provisions. NVIDIA may make changes to the SOFTWARE, at any time without notice, but is not obligated to support or update the SOFTWARE. + * + * 6. COMPONENTS UNDER OTHER LICENSES. The SOFTWARE may include NVIDIA or third-party components with separate legal notices or terms as may be described in proprietary notices accompanying the SOFTWARE. If and to the extent there is a conflict between the terms in this license and the license terms associated with a component, the license terms associated with the components control only to the extent necessary to resolve the conflict. + * + * 7. FEEDBACK. You may, but don’t have to, provide to NVIDIA any Feedback. “Feedback” means any suggestions, bug fixes, enhancements, modifications, feature requests or other feedback regarding the SOFTWARE. For any Feedback that you voluntarily provide, you hereby grant NVIDIA and its affiliates a perpetual, non-exclusive, worldwide, irrevocable license to use, reproduce, modify, license, sublicense (through multiple tiers of sublicensees), and distribute (through multiple tiers of distributors) the Feedback without the payment of any royalties or fees to you. NVIDIA will use Feedback at its choice. + * + * 8. NO WARRANTIES. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. NVIDIA DOES NOT WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION THEREOF WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ALL ERRORS WILL BE CORRECTED. + * + * 9. LIMITATIONS OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY LAW, NVIDIA AND ITS AFFILIATES SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR ANY LOST PROFITS, PROJECT DELAYS, LOSS OF USE, LOSS OF DATA OR LOSS OF GOODWILL, OR THE COSTS OF PROCURING SUBSTITUTE PRODUCTS, ARISING OUT OF OR IN CONNECTION WITH THIS LICENSE OR THE USE OR PERFORMANCE OF THE SOFTWARE, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCT LIABILITY OR ANY OTHER CAUSE OF ACTION OR THEORY OF LIABILITY, EVEN IF NVIDIA HAS PREVIOUSLY BEEN ADVISED OF, OR COULD REASONABLY HAVE FORESEEN, THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL NVIDIA’S AND ITS AFFILIATES TOTAL CUMULATIVE LIABILITY UNDER OR ARISING OUT OF THIS LICENSE EXCEED US$10.00. THE NATURE OF THE LIABILITY OR THE NUMBER OF CLAIMS OR SUITS SHALL NOT ENLARGE OR EXTEND THIS LIMIT. + * + * 10. TERMINATION. Your rights under this license will terminate automatically without notice from NVIDIA if you fail to comply with any term and condition of this license or if you commence or participate in any legal proceeding against NVIDIA with respect to the SOFTWARE. NVIDIA may terminate this license with advance written notice to you if NVIDIA decides to no longer provide the SOFTWARE in a country or, in NVIDIA’s sole discretion, the continued use of it is no longer commercially viable. Upon any termination of this license, you agree to promptly discontinue use of the SOFTWARE and destroy all copies in your possession or control. Your prior distributions in accordance with this license are not affected by the termination of this license. All provisions of this license will survive termination, except for the license granted to you. + * + * 11. APPLICABLE LAW. This license will be governed in all respects by the laws of the United States and of the State of Delaware as those laws are applied to contracts entered into and performed entirely within Delaware by Delaware residents, without regard to the conflicts of laws principles. The United Nations Convention on Contracts for the International Sale of Goods is specifically disclaimed. You agree to all terms of this Agreement in the English language. The state or federal courts residing in Santa Clara County, California shall have exclusive jurisdiction over any dispute or claim arising out of this license. Notwithstanding this, you agree that NVIDIA shall still be allowed to apply for injunctive remedies or an equivalent type of urgent legal relief in any jurisdiction. + * + * 12. NO ASSIGNMENT. This license and your rights and obligations thereunder may not be assigned by you by any means or operation of law without NVIDIA’s permission. Any attempted assignment not approved by NVIDIA in writing shall be void and of no effect. + * + * 13. EXPORT. The SOFTWARE is subject to United States export laws and regulations. You agree that you will not ship, transfer or export the SOFTWARE into any country, or use the SOFTWARE in any manner, prohibited by the United States Bureau of Industry and Security or economic sanctions regulations administered by the U.S. Department of Treasury’s Office of Foreign Assets Control (OFAC), or any applicable export laws, restrictions or regulations. These laws include restrictions on destinations, end users and end use. By accepting this license, you confirm that you are not a resident or citizen of any country currently embargoed by the U.S. and that you are not otherwise prohibited from receiving the SOFTWARE. + * + * 14. GOVERNMENT USE. The SOFTWARE has been developed entirely at private expense and is “commercial items” consisting of “commercial computer software” and “commercial computer software documentation” provided with RESTRICTED RIGHTS. Use, duplication or disclosure by the U.S. Government or a U.S. Government subcontractor is subject to the restrictions in this license pursuant to DFARS 227.7202-3(a) or as set forth in subparagraphs (b)(1) and (2) of the Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, as applicable. Contractor/manufacturer is NVIDIA, 2788 San Tomas Expressway, Santa Clara, CA 95051. + * + * 15. ENTIRE AGREEMENT. This license is the final, complete and exclusive agreement between the parties relating to the subject matter of this license and supersedes all prior or contemporaneous understandings and agreements relating to this subject matter, whether oral or written. If any court of competent jurisdiction determines that any provision of this license is illegal, invalid or unenforceable, the remaining provisions will remain in full force and effect. This license may only be modified in a writing signed by an authorized representative of each party. + * + * (v. August 20, 2021) + */ +#ifndef _CUDA_PIPELINE +#define _CUDA_PIPELINE + +#include "barrier" +#include "atomic" +#include "std/chrono" + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + + // Forward declaration in barrier of pipeline + enum class pipeline_role { + producer, + consumer + }; + + template + struct __pipeline_stage { + barrier<_Scope> __produced; + barrier<_Scope> __consumed; + }; + + template + class pipeline_shared_state { + public: + pipeline_shared_state() = default; + pipeline_shared_state(const pipeline_shared_state &) = delete; + pipeline_shared_state(pipeline_shared_state &&) = delete; + pipeline_shared_state & operator=(pipeline_shared_state &&) = delete; + pipeline_shared_state & operator=(const pipeline_shared_state &) = delete; + + private: + __pipeline_stage<_Scope> __stages[_Stages_count]; + atomic __refcount; + + template + friend class pipeline; + + template + friend _LIBCUDACXX_INLINE_VISIBILITY + pipeline<_Pipeline_scope> make_pipeline(const _Group & __group, pipeline_shared_state<_Pipeline_scope, _Pipeline_stages_count> * __shared_state); + + template + friend _LIBCUDACXX_INLINE_VISIBILITY + pipeline<_Pipeline_scope> make_pipeline(const _Group & __group, pipeline_shared_state<_Pipeline_scope, _Pipeline_stages_count> * __shared_state, size_t __producer_count); + + template + friend _LIBCUDACXX_INLINE_VISIBILITY + pipeline<_Pipeline_scope> make_pipeline(const _Group & __group, pipeline_shared_state<_Pipeline_scope, _Pipeline_stages_count> * __shared_state, pipeline_role __role); + }; + + struct __pipeline_asm_helper { + _LIBCUDACXX_DEVICE + static inline uint32_t __lane_id() + { + NV_IF_ELSE_TARGET( + NV_IS_DEVICE, + ( + uint32_t __lane_id; + asm volatile ("mov.u32 %0, %%laneid;" : "=r"(__lane_id)); + return __lane_id; + ), + ( + return 0; + ) + ) + } + }; + + template + class pipeline { + public: + pipeline(pipeline &&) = default; + pipeline(const pipeline &) = delete; + pipeline & operator=(pipeline &&) = delete; + pipeline & operator=(const pipeline &) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY + ~pipeline() + { + if (__active) { + (void)quit(); + } + } + + _LIBCUDACXX_INLINE_VISIBILITY + bool quit() + { + bool __elected; + uint32_t __sub_count; +NV_IF_TARGET(NV_IS_DEVICE, + const uint32_t __match_mask = __match_any_sync(__activemask(), reinterpret_cast(__shared_state_get_refcount())); + const uint32_t __elected_id = __ffs(__match_mask) - 1; + __elected = (__pipeline_asm_helper::__lane_id() == __elected_id); + __sub_count = __popc(__match_mask); +, + __elected = true; + __sub_count = 1; +) + bool __released = false; + if (__elected) { + const uint32_t __old = __shared_state_get_refcount()->fetch_sub(__sub_count); + const bool __last = (__old == __sub_count); + if (__last) { + for (uint8_t __stage = 0; __stage < __stages_count; ++__stage) { + __shared_state_get_stage(__stage)->__produced.~barrier(); + __shared_state_get_stage(__stage)->__consumed.~barrier(); + } + __released = true; + } + } + __active = false; + return __released; + } + + _LIBCUDACXX_INLINE_VISIBILITY + void producer_acquire() + { + barrier<_Scope> & __stage_barrier = __shared_state_get_stage(__head)->__consumed; + __stage_barrier.wait_parity(__consumed_phase_parity); + } + + _LIBCUDACXX_INLINE_VISIBILITY + void producer_commit() + { + barrier<_Scope> & __stage_barrier = __shared_state_get_stage(__head)->__produced; + __memcpy_arrive_on_impl::__arrive_on(__stage_barrier, async_contract_fulfillment::async); + (void)__stage_barrier.arrive(); + if (++__head == __stages_count) { + __head = 0; + __consumed_phase_parity = !__consumed_phase_parity; + } + } + + _LIBCUDACXX_INLINE_VISIBILITY + void consumer_wait() + { + barrier<_Scope> & __stage_barrier = __shared_state_get_stage(__tail)->__produced; + __stage_barrier.wait_parity(__produced_phase_parity); + } + + _LIBCUDACXX_INLINE_VISIBILITY + void consumer_release() + { + (void)__shared_state_get_stage(__tail)->__consumed.arrive(); + if (++__tail == __stages_count) { + __tail = 0; + __produced_phase_parity = !__produced_phase_parity; + } + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + bool consumer_wait_for(const _CUDA_VSTD::chrono::duration<_Rep, _Period> & __duration) + { + barrier<_Scope> & __stage_barrier = __shared_state_get_stage(__tail)->__produced; + return _CUDA_VSTD::__libcpp_thread_poll_with_backoff( + _CUDA_VSTD::__barrier_poll_tester_parity>( + &__stage_barrier, + __produced_phase_parity), + _CUDA_VSTD::chrono::duration_cast<_CUDA_VSTD::chrono::nanoseconds>(__duration) + ); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + bool consumer_wait_until(const _CUDA_VSTD::chrono::time_point<_Clock, _Duration> & __time_point) + { + return consumer_wait_for(__time_point - _Clock::now()); + } + + private: + uint8_t __head : 8; + uint8_t __tail : 8; + const uint8_t __stages_count : 8; + bool __consumed_phase_parity : 1; + bool __produced_phase_parity : 1; + bool __active : 1; + // TODO: Remove partitioned on next ABI break + const bool __partitioned : 1; + char * const __shared_state; + + + _LIBCUDACXX_INLINE_VISIBILITY + pipeline(char * __shared_state, uint8_t __stages_count, bool __partitioned) + : __head(0) + , __tail(0) + , __stages_count(__stages_count) + , __consumed_phase_parity(true) + , __produced_phase_parity(false) + , __active(true) + , __partitioned(__partitioned) + , __shared_state(__shared_state) + {} + + _LIBCUDACXX_INLINE_VISIBILITY + __pipeline_stage<_Scope> * __shared_state_get_stage(uint8_t __stage) + { + ptrdiff_t __stage_offset = __stage * sizeof(__pipeline_stage<_Scope>); + return reinterpret_cast<__pipeline_stage<_Scope>*>(__shared_state + __stage_offset); + } + + _LIBCUDACXX_INLINE_VISIBILITY + atomic * __shared_state_get_refcount() + { + ptrdiff_t __refcount_offset = __stages_count * sizeof(__pipeline_stage<_Scope>); + return reinterpret_cast*>(__shared_state + __refcount_offset); + } + + template + friend _LIBCUDACXX_INLINE_VISIBILITY + pipeline<_Pipeline_scope> make_pipeline(const _Group & __group, pipeline_shared_state<_Pipeline_scope, _Pipeline_stages_count> * __shared_state); + + template + friend _LIBCUDACXX_INLINE_VISIBILITY + pipeline<_Pipeline_scope> make_pipeline(const _Group & __group, pipeline_shared_state<_Pipeline_scope, _Pipeline_stages_count> * __shared_state, size_t __producer_count); + + template + friend _LIBCUDACXX_INLINE_VISIBILITY + pipeline<_Pipeline_scope> make_pipeline(const _Group & __group, pipeline_shared_state<_Pipeline_scope, _Pipeline_stages_count> * __shared_state, pipeline_role __role); + }; + + template + _LIBCUDACXX_INLINE_VISIBILITY + pipeline<_Scope> make_pipeline(const _Group & __group, pipeline_shared_state<_Scope, _Stages_count> * __shared_state) + { + const uint32_t __group_size = static_cast(__group.size()); + const uint32_t __thread_rank = static_cast(__group.thread_rank()); + + if (__thread_rank == 0) { + for (uint8_t __stage = 0; __stage < _Stages_count; ++__stage) { + init(&__shared_state->__stages[__stage].__consumed, __group_size); + init(&__shared_state->__stages[__stage].__produced, __group_size); + } + __shared_state->__refcount.store(__group_size, std::memory_order_relaxed); + } + __group.sync(); + + return pipeline<_Scope>(reinterpret_cast(__shared_state->__stages), _Stages_count, false); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + pipeline<_Scope> make_pipeline(const _Group & __group, pipeline_shared_state<_Scope, _Stages_count> * __shared_state, size_t __producer_count) + { + const uint32_t __group_size = static_cast(__group.size()); + const uint32_t __thread_rank = static_cast(__group.thread_rank()); + + if (__thread_rank == 0) { + const size_t __consumer_count = __group_size - __producer_count; + for (uint8_t __stage = 0; __stage < _Stages_count; ++__stage) { + init(&__shared_state->__stages[__stage].__consumed, __consumer_count); + init(&__shared_state->__stages[__stage].__produced, __producer_count); + } + __shared_state->__refcount.store(__group_size, std::memory_order_relaxed); + } + __group.sync(); + + return pipeline<_Scope>(reinterpret_cast(__shared_state->__stages), _Stages_count, true); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + pipeline<_Scope> make_pipeline(const _Group & __group, pipeline_shared_state<_Scope, _Stages_count> * __shared_state, pipeline_role __role) + { + const uint32_t __group_size = static_cast(__group.size()); + const uint32_t __thread_rank = static_cast(__group.thread_rank()); + + if (__thread_rank == 0) { + __shared_state->__refcount.store(0, std::memory_order_relaxed); + } + __group.sync(); + + if (__role == pipeline_role::producer) { + bool __elected; + uint32_t __add_count; +NV_IF_TARGET(NV_IS_DEVICE, + const uint32_t __match_mask = __match_any_sync(__activemask(), reinterpret_cast(&__shared_state->__refcount)); + const uint32_t __elected_id = __ffs(__match_mask) - 1; + __elected = (__pipeline_asm_helper::__lane_id() == __elected_id); + __add_count = __popc(__match_mask); +, + __elected = true; + __add_count = 1; +) + if (__elected) { + (void)__shared_state->__refcount.fetch_add(__add_count, std::memory_order_relaxed); + } + } + __group.sync(); + + if (__thread_rank == 0) { + const uint32_t __producer_count = __shared_state->__refcount.load(std::memory_order_relaxed); + const uint32_t __consumer_count = __group_size - __producer_count; + for (uint8_t __stage = 0; __stage < _Stages_count; ++__stage) { + init(&__shared_state->__stages[__stage].__consumed, __consumer_count); + init(&__shared_state->__stages[__stage].__produced, __producer_count); + } + __shared_state->__refcount.store(__group_size, std::memory_order_relaxed); + } + __group.sync(); + + return pipeline<_Scope>(reinterpret_cast(__shared_state->__stages), _Stages_count, true); + } + +_LIBCUDACXX_END_NAMESPACE_CUDA + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_DEVICE + + template + _LIBCUDACXX_DEVICE + void __pipeline_consumer_wait(pipeline & __pipeline); + + _LIBCUDACXX_DEVICE + inline void __pipeline_consumer_wait(pipeline & __pipeline, uint8_t __prior); + +_LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + + template<> + class pipeline { + public: + pipeline(pipeline &&) = default; + pipeline(const pipeline &) = delete; + pipeline & operator=(pipeline &&) = delete; + pipeline & operator=(const pipeline &) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY + ~pipeline() {} + + _LIBCUDACXX_INLINE_VISIBILITY + bool quit() + { + return true; + } + + _LIBCUDACXX_INLINE_VISIBILITY + void producer_acquire() {} + + _LIBCUDACXX_INLINE_VISIBILITY + void producer_commit() + { +NV_IF_TARGET(NV_PROVIDES_SM_80, + asm volatile ("cp.async.commit_group;"); + ++__head; +) + } + + _LIBCUDACXX_INLINE_VISIBILITY + void consumer_wait() + { +NV_IF_TARGET(NV_PROVIDES_SM_80, + if (__head == __tail) { + return; + } + + const uint8_t __prior = __head - __tail - 1; + device::__pipeline_consumer_wait(*this, __prior); + ++__tail; +) + } + + _LIBCUDACXX_INLINE_VISIBILITY + void consumer_release() {} + + template + _LIBCUDACXX_INLINE_VISIBILITY + bool consumer_wait_for(const _CUDA_VSTD::chrono::duration<_Rep, _Period> & __duration) + { + (void)__duration; + consumer_wait(); + return true; + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + bool consumer_wait_until(const _CUDA_VSTD::chrono::time_point<_Clock, _Duration> & __time_point) + { + (void)__time_point; + consumer_wait(); + return true; + } + + private: + uint8_t __head; + uint8_t __tail; + + _LIBCUDACXX_INLINE_VISIBILITY + pipeline() + : __head(0) + , __tail(0) + {} + + friend _LIBCUDACXX_INLINE_VISIBILITY inline pipeline make_pipeline(); + + template + friend _LIBCUDACXX_INLINE_VISIBILITY + void pipeline_consumer_wait_prior(pipeline & __pipeline); + + template + friend _LIBCUDACXX_INLINE_VISIBILITY + pipeline<_Pipeline_scope> __make_pipeline(const _Group & __group, pipeline_shared_state<_Pipeline_scope, _Pipeline_stages_count> * __shared_state); + }; + +_LIBCUDACXX_END_NAMESPACE_CUDA + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_DEVICE + + template + _LIBCUDACXX_DEVICE + void __pipeline_consumer_wait(pipeline & __pipeline) + { + (void)__pipeline; +NV_IF_TARGET(NV_PROVIDES_SM_80, + constexpr uint8_t __max_prior = 8; + + asm volatile ("cp.async.wait_group %0;" + : + : "n"(_Prior < __max_prior ? _Prior : __max_prior)); +) + } + + _LIBCUDACXX_DEVICE + inline void __pipeline_consumer_wait(pipeline & __pipeline, uint8_t __prior) + { + switch (__prior) { + case 0: device::__pipeline_consumer_wait<0>(__pipeline); break; + case 1: device::__pipeline_consumer_wait<1>(__pipeline); break; + case 2: device::__pipeline_consumer_wait<2>(__pipeline); break; + case 3: device::__pipeline_consumer_wait<3>(__pipeline); break; + case 4: device::__pipeline_consumer_wait<4>(__pipeline); break; + case 5: device::__pipeline_consumer_wait<5>(__pipeline); break; + case 6: device::__pipeline_consumer_wait<6>(__pipeline); break; + case 7: device::__pipeline_consumer_wait<7>(__pipeline); break; + default: device::__pipeline_consumer_wait<8>(__pipeline); break; + } + } + +_LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + + _LIBCUDACXX_INLINE_VISIBILITY + inline pipeline make_pipeline() + { + return pipeline(); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + void pipeline_consumer_wait_prior(pipeline & __pipeline) + { + NV_IF_TARGET(NV_PROVIDES_SM_80, + device::__pipeline_consumer_wait<_Prior>(__pipeline); + __pipeline.__tail = __pipeline.__head - _Prior; + ) + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + void pipeline_producer_commit(pipeline & __pipeline, barrier<_Scope> & __barrier) + { + (void)__pipeline; + NV_IF_TARGET(NV_PROVIDES_SM_80, + __memcpy_arrive_on_impl::__arrive_on(__barrier, async_contract_fulfillment::async); + ) + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + async_contract_fulfillment memcpy_async(_Group const & __group, _Type * __destination, _Type const * __source, std::size_t __size, pipeline<_Scope> & __pipeline) { + // When compiling with NVCC and GCC 4.8, certain user defined types that _are_ trivially copyable are + // incorrectly classified as not trivially copyable. Remove this assertion to allow for their usage with + // memcpy_async when compiling with GCC 4.8. + // FIXME: remove the #if once GCC 4.8 is no longer supported. + #if !defined(_LIBCUDACXX_COMPILER_GCC) || _GNUC_VER > 408 + static_assert(std::is_trivially_copyable<_Type>::value, "memcpy_async requires a trivially copyable type"); + #endif + + return __memcpy_async(__group, reinterpret_cast(__destination), reinterpret_cast(__source), __size, __pipeline); + } + + template _Alignment) ? alignof(_Type) : _Alignment> + _LIBCUDACXX_INLINE_VISIBILITY + async_contract_fulfillment memcpy_async(_Group const & __group, _Type * __destination, _Type const * __source, aligned_size_t<_Alignment> __size, pipeline<_Scope> & __pipeline) { + // When compiling with NVCC and GCC 4.8, certain user defined types that _are_ trivially copyable are + // incorrectly classified as not trivially copyable. Remove this assertion to allow for their usage with + // memcpy_async when compiling with GCC 4.8. + // FIXME: remove the #if once GCC 4.8 is no longer supported. + #if !defined(_LIBCUDACXX_COMPILER_GCC) || _GNUC_VER > 408 + static_assert(std::is_trivially_copyable<_Type>::value, "memcpy_async requires a trivially copyable type"); + #endif + + return __memcpy_async<_Larger_alignment>(__group, reinterpret_cast(__destination), reinterpret_cast(__source), __size, __pipeline); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + async_contract_fulfillment memcpy_async(_Type * __destination, _Type const * __source, _Size __size, pipeline<_Scope> & __pipeline) { + return memcpy_async(__single_thread_group{}, __destination, __source, __size, __pipeline); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + async_contract_fulfillment memcpy_async(_Group const & __group, void * __destination, void const * __source, std::size_t __size, pipeline<_Scope> & __pipeline) { + return __memcpy_async<1>(__group, reinterpret_cast(__destination), reinterpret_cast(__source), __size, __pipeline); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + async_contract_fulfillment memcpy_async(_Group const & __group, void * __destination, void const * __source, aligned_size_t<_Alignment> __size, pipeline<_Scope> & __pipeline) { + return __memcpy_async<_Alignment>(__group, reinterpret_cast(__destination), reinterpret_cast(__source), __size, __pipeline, std::false_type()); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + async_contract_fulfillment memcpy_async(void * __destination, void const * __source, _Size __size, pipeline<_Scope> & __pipeline) { + return memcpy_async(__single_thread_group{}, __destination, __source, __size, __pipeline); + } + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif //_CUDA_PIPELINE diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/semaphore b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/semaphore new file mode 100644 index 0000000000000000000000000000000000000000..e2d06d15c3198d0f7f63727856bea84ad463c9f4 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/semaphore @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_SEMAPHORE +#define _CUDA_SEMAPHORE + +#include "std/semaphore" + +#endif // _CUDA_SEMAPHORE diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/array b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/array new file mode 100644 index 0000000000000000000000000000000000000000..775194ae29295fc4879d4a327517c4cd4556515a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/array @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_ARRAY +#define _CUDA_STD_ARRAY + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/array" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_ARRAY diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/atomic b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/atomic new file mode 100644 index 0000000000000000000000000000000000000000..bf52d11c2350802621030963b34068b10cdf6895 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/atomic @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_ATOMIC +#define _CUDA_STD_ATOMIC + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/atomic" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_ATOMIC diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/barrier b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/barrier new file mode 100644 index 0000000000000000000000000000000000000000..fff3e842afaa523c9e099575947286b46006abe7 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/barrier @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_BARRIER +#define _CUDA_STD_BARRIER + +#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 700 +# error "CUDA synchronization primitives are only supported for sm_70 and up." +#endif + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/barrier" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_BARRIER diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/bit b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/bit new file mode 100644 index 0000000000000000000000000000000000000000..87dfb73d2e19f321f0bb91b62d6d050e7eab4ce2 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/bit @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_BIT +#define _CUDA_STD_BIT + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/bit" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_BIT diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cassert b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cassert new file mode 100644 index 0000000000000000000000000000000000000000..e6676b4d0a0fed70cdbdae7e4102c90322229c8a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cassert @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CASSERT +#define _CUDA_STD_CASSERT + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/cassert" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CASSERT diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/ccomplex b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/ccomplex new file mode 100644 index 0000000000000000000000000000000000000000..bedbc0c643d00e829744c64f8825724dd3ce2197 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/ccomplex @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CCOMPLEX +#define _CUDA_STD_CCOMPLEX + +#include "complex" + +#endif // _CUDA_STD_CCOMPLEX diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cfloat b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cfloat new file mode 100644 index 0000000000000000000000000000000000000000..1b9a4f935e4139df6444eca4dfd85057bffe003a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cfloat @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CFLOAT +#define _CUDA_STD_CFLOAT + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/cfloat" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CFLOAT diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/chrono b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/chrono new file mode 100644 index 0000000000000000000000000000000000000000..a4d45b619c0aa704bee3bf7386f879534435124a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/chrono @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CHRONO +#define _CUDA_STD_CHRONO + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/chrono" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CHRONO diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/climits b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/climits new file mode 100644 index 0000000000000000000000000000000000000000..dd733eb12f601ce4db2746b395527bbfba620f7e --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/climits @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CLIMITS +#define _CUDA_STD_CLIMITS + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/climits" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CLIMITS diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cmath b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cmath new file mode 100644 index 0000000000000000000000000000000000000000..7944a9506d5546e72a368da6bfc91c93e2bc8d4b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cmath @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CMATH +#define _CUDA_STD_CMATH + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/cmath" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CMATH diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/complex b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/complex new file mode 100644 index 0000000000000000000000000000000000000000..f0f7d97740fa9ad5fb3e7f536368b5c37edcd25c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/complex @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_COMPLEX +#define _CUDA_STD_COMPLEX + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/complex" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_COMPLEX diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/concepts b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/concepts new file mode 100644 index 0000000000000000000000000000000000000000..536d92809302bbf1e9e4993918065252118ea62c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/concepts @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CONCEPTS +#define _CUDA_STD_CONCEPTS + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/concepts" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CONCEPTS diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cstddef b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cstddef new file mode 100644 index 0000000000000000000000000000000000000000..006821979e42efeeacb57657aac3dd94e9672789 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cstddef @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CSTDDEF +#define _CUDA_STD_CSTDDEF + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/cstddef" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CSTDDEF diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cstdint b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cstdint new file mode 100644 index 0000000000000000000000000000000000000000..9ff2cd96ac4600416f2911d74a14313a24dcf2eb --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/cstdint @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CSTDINT +#define _CUDA_STD_CSTDINT + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/cstdint" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CSTDINT diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/ctime b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/ctime new file mode 100644 index 0000000000000000000000000000000000000000..eac6f3b272d3b930983ad72619c5acfa524abc2d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/ctime @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CTIME +#define _CUDA_STD_CTIME + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/ctime" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CTIME diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__access_property b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__access_property new file mode 100644 index 0000000000000000000000000000000000000000..9ee3856771b567bf9dff10ac9cda0754179519a8 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__access_property @@ -0,0 +1,327 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * NVIDIA SOFTWARE LICENSE + * + * This license is a legal agreement between you and NVIDIA Corporation ("NVIDIA") and governs your use of the NVIDIA/CUDA C++ Library software and materials provided hereunder (“SOFTWARE”). + * + * This license can be accepted only by an adult of legal age of majority in the country in which the SOFTWARE is used. If you are under the legal age of majority, you must ask your parent or legal guardian to consent to this license. By taking delivery of the SOFTWARE, you affirm that you have reached the legal age of majority, you accept the terms of this license, and you take legal and financial responsibility for the actions of your permitted users. + * + * You agree to use the SOFTWARE only for purposes that are permitted by (a) this license, and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions. + * + * 1. LICENSE. Subject to the terms of this license, NVIDIA grants you a non-exclusive limited license to: (a) install and use the SOFTWARE, and (b) distribute the SOFTWARE subject to the distribution requirements described in this license. NVIDIA reserves all rights, title and interest in and to the SOFTWARE not expressly granted to you under this license. + * + * 2. DISTRIBUTION REQUIREMENTS. These are the distribution requirements for you to exercise the distribution grant: + * a. The terms under which you distribute the SOFTWARE must be consistent with the terms of this license, including (without limitation) terms relating to the license grant and license restrictions and protection of NVIDIA’s intellectual property rights. + * b. You agree to notify NVIDIA in writing of any known or suspected distribution or use of the SOFTWARE not in compliance with the requirements of this license, and to enforce the terms of your agreements with respect to distributed SOFTWARE. + * + * 3. LIMITATIONS. Your license to use the SOFTWARE is restricted as follows: + * a. The SOFTWARE is licensed for you to develop applications only for use in systems with NVIDIA GPUs. + * b. You may not reverse engineer, decompile or disassemble, or remove copyright or other proprietary notices from any portion of the SOFTWARE or copies of the SOFTWARE. + * c. You may not modify or create derivative works of any portion of the SOFTWARE. + * d. You may not bypass, disable, or circumvent any technical measure, encryption, security, digital rights management or authentication mechanism in the SOFTWARE. + * e. You may not use the SOFTWARE in any manner that would cause it to become subject to an open source software license. As examples, licenses that require as a condition of use, modification, and/or distribution that the SOFTWARE be (i) disclosed or distributed in source code form; (ii) licensed for the purpose of making derivative works; or (iii) redistributable at no charge. + * f. Unless you have an agreement with NVIDIA for this purpose, you may not use the SOFTWARE with any system or application where the use or failure of the system or application can reasonably be expected to threaten or result in personal injury, death, or catastrophic loss. Examples include use in avionics, navigation, military, medical, life support or other life critical applications. NVIDIA does not design, test or manufacture the SOFTWARE for these critical uses and NVIDIA shall not be liable to you or any third party, in whole or in part, for any claims or damages arising from such uses. + * g. You agree to defend, indemnify and hold harmless NVIDIA and its affiliates, and their respective employees, contractors, agents, officers and directors, from and against any and all claims, damages, obligations, losses, liabilities, costs or debt, fines, restitutions and expenses (including but not limited to attorney’s fees and costs incident to establishing the right of indemnification) arising out of or related to use of the SOFTWARE outside of the scope of this Agreement, or not in compliance with its terms. + * + * 4. PRE-RELEASE. SOFTWARE versions identified as alpha, beta, preview, early access or otherwise as pre-release may not be fully functional, may contain errors or design flaws, and may have reduced or different security, privacy, availability, and reliability standards relative to commercial versions of NVIDIA software and materials. You may use a pre-release SOFTWARE version at your own risk, understanding that these versions are not intended for use in production or business-critical systems. + * + * 5. OWNERSHIP. The SOFTWARE and the related intellectual property rights therein are and will remain the sole and exclusive property of NVIDIA or its licensors. The SOFTWARE is copyrighted and protected by the laws of the United States and other countries, and international treaty provisions. NVIDIA may make changes to the SOFTWARE, at any time without notice, but is not obligated to support or update the SOFTWARE. + * + * 6. COMPONENTS UNDER OTHER LICENSES. The SOFTWARE may include NVIDIA or third-party components with separate legal notices or terms as may be described in proprietary notices accompanying the SOFTWARE. If and to the extent there is a conflict between the terms in this license and the license terms associated with a component, the license terms associated with the components control only to the extent necessary to resolve the conflict. + * + * 7. FEEDBACK. You may, but don’t have to, provide to NVIDIA any Feedback. “Feedback” means any suggestions, bug fixes, enhancements, modifications, feature requests or other feedback regarding the SOFTWARE. For any Feedback that you voluntarily provide, you hereby grant NVIDIA and its affiliates a perpetual, non-exclusive, worldwide, irrevocable license to use, reproduce, modify, license, sublicense (through multiple tiers of sublicensees), and distribute (through multiple tiers of distributors) the Feedback without the payment of any royalties or fees to you. NVIDIA will use Feedback at its choice. + * + * 8. NO WARRANTIES. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. NVIDIA DOES NOT WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION THEREOF WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ALL ERRORS WILL BE CORRECTED. + * + * 9. LIMITATIONS OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY LAW, NVIDIA AND ITS AFFILIATES SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR ANY LOST PROFITS, PROJECT DELAYS, LOSS OF USE, LOSS OF DATA OR LOSS OF GOODWILL, OR THE COSTS OF PROCURING SUBSTITUTE PRODUCTS, ARISING OUT OF OR IN CONNECTION WITH THIS LICENSE OR THE USE OR PERFORMANCE OF THE SOFTWARE, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCT LIABILITY OR ANY OTHER CAUSE OF ACTION OR THEORY OF LIABILITY, EVEN IF NVIDIA HAS PREVIOUSLY BEEN ADVISED OF, OR COULD REASONABLY HAVE FORESEEN, THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL NVIDIA’S AND ITS AFFILIATES TOTAL CUMULATIVE LIABILITY UNDER OR ARISING OUT OF THIS LICENSE EXCEED US$10.00. THE NATURE OF THE LIABILITY OR THE NUMBER OF CLAIMS OR SUITS SHALL NOT ENLARGE OR EXTEND THIS LIMIT. + * + * 10. TERMINATION. Your rights under this license will terminate automatically without notice from NVIDIA if you fail to comply with any term and condition of this license or if you commence or participate in any legal proceeding against NVIDIA with respect to the SOFTWARE. NVIDIA may terminate this license with advance written notice to you if NVIDIA decides to no longer provide the SOFTWARE in a country or, in NVIDIA’s sole discretion, the continued use of it is no longer commercially viable. Upon any termination of this license, you agree to promptly discontinue use of the SOFTWARE and destroy all copies in your possession or control. Your prior distributions in accordance with this license are not affected by the termination of this license. All provisions of this license will survive termination, except for the license granted to you. + * + * 11. APPLICABLE LAW. This license will be governed in all respects by the laws of the United States and of the State of Delaware as those laws are applied to contracts entered into and performed entirely within Delaware by Delaware residents, without regard to the conflicts of laws principles. The United Nations Convention on Contracts for the International Sale of Goods is specifically disclaimed. You agree to all terms of this Agreement in the English language. The state or federal courts residing in Santa Clara County, California shall have exclusive jurisdiction over any dispute or claim arising out of this license. Notwithstanding this, you agree that NVIDIA shall still be allowed to apply for injunctive remedies or an equivalent type of urgent legal relief in any jurisdiction. + * + * 12. NO ASSIGNMENT. This license and your rights and obligations thereunder may not be assigned by you by any means or operation of law without NVIDIA’s permission. Any attempted assignment not approved by NVIDIA in writing shall be void and of no effect. + * + * 13. EXPORT. The SOFTWARE is subject to United States export laws and regulations. You agree that you will not ship, transfer or export the SOFTWARE into any country, or use the SOFTWARE in any manner, prohibited by the United States Bureau of Industry and Security or economic sanctions regulations administered by the U.S. Department of Treasury’s Office of Foreign Assets Control (OFAC), or any applicable export laws, restrictions or regulations. These laws include restrictions on destinations, end users and end use. By accepting this license, you confirm that you are not a resident or citizen of any country currently embargoed by the U.S. and that you are not otherwise prohibited from receiving the SOFTWARE. + * + * 14. GOVERNMENT USE. The SOFTWARE has been developed entirely at private expense and is “commercial items” consisting of “commercial computer software” and “commercial computer software documentation” provided with RESTRICTED RIGHTS. Use, duplication or disclosure by the U.S. Government or a U.S. Government subcontractor is subject to the restrictions in this license pursuant to DFARS 227.7202-3(a) or as set forth in subparagraphs (b)(1) and (2) of the Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, as applicable. Contractor/manufacturer is NVIDIA, 2788 San Tomas Expressway, Santa Clara, CA 95051. + * + * 15. ENTIRE AGREEMENT. This license is the final, complete and exclusive agreement between the parties relating to the subject matter of this license and supersedes all prior or contemporaneous understandings and agreements relating to this subject matter, whether oral or written. If any court of competent jurisdiction determines that any provision of this license is illegal, invalid or unenforceable, the remaining provisions will remain in full force and effect. This license may only be modified in a writing signed by an authorized representative of each party. + * + * (v. August 20, 2021) + */ + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +namespace __detail_ap { + + _LIBCUDACXX_HOST_DEVICE + constexpr uint32_t __ap_floor_log2(uint32_t __x) { + return (__x == 1 | __x == 0) ? 0 : 1 + __ap_floor_log2(__x >> 1); + } + + _LIBCUDACXX_HOST_DEVICE + constexpr uint32_t __ap_ceil_log2(uint32_t __x) { + return (__x == 1 | __x == 0) ? 0 : __ap_floor_log2(__x - 1) + 1; + } + + _LIBCUDACXX_HOST_DEVICE + constexpr uint32_t __ap_min(uint32_t __a, uint32_t __b) noexcept { + return (__a < __b) ? __a : __b; + } + + _LIBCUDACXX_HOST_DEVICE + constexpr uint32_t __ap_max(uint32_t __a, uint32_t __b) noexcept { + return (__a > __b) ? __a : __b; + } + +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414 +// Specifically search for 8.4 and 9.3 and above to guarantee uint64_t enum. +#if defined(_LIBCUDACXX_COMPILER_GCC) && ( \ + ((_GNUC_VER < 804)) || \ + ((_GNUC_VER < 903)) \ + ) +# define _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION +#else +# define _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION : uint64_t +#endif + + namespace __sm_80 { + namespace __off { + enum __l2_cop_off_t _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION { + _L2_EVICT_NORMAL = 0, + _L2_EVICT_FIRST = 1, + }; + } // namespace __off + + namespace __on { + enum __l2_cop_on_t _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION { + _L2_EVICT_NORMAL = 0, + _L2_EVICT_FIRST = 1, + _L2_EVICT_LAST = 2, + _L2_EVICT_NORMAL_DEMOTE = 3, + }; + } // namespace __on + + enum __l2_descriptor_mode_t _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION { + _DESC_IMPLICIT = 0, + _DESC_INTERLEAVED = 2, + _DESC_BLOCK_TYPE = 3, + }; + + enum __l2_eviction_max_way_t _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION { + _CUDA_AMPERE_MAX_L2_WAYS = std::uint32_t{16}, + }; + + enum __block_size_t _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION { + _BLOCKSIZE_4K = 0, + _BLOCKSIZE_8K = 1, + _BLOCKSIZE_16K = 2, + _BLOCKSIZE_32K = 3, + _BLOCKSIZE_64K = 4, + _BLOCKSIZE_128K = 5, + _BLOCKSIZE_256K = 6, + _BLOCKSIZE_512K = 7, + _BLOCKSIZE_1M = 8, + _BLOCKSIZE_2M = 9, + _BLOCKSIZE_4M = 10, + _BLOCKSIZE_8M = 11, + _BLOCKSIZE_16M = 12, + _BLOCKSIZE_32M = 13, + }; + + struct __block_desc_t { + uint64_t __ap_reserved : 37; + uint64_t __block_count: 7; + uint64_t __block_start: 7; + uint64_t __ap_reserved2 : 1; + __block_size_t __block_size : 4; + __off::__l2_cop_off_t __l2_cop_off : 1; + __on::__l2_cop_on_t __l2_cop_on : 2; + __l2_descriptor_mode_t __l2_descriptor_mode : 2; + uint64_t __l1_inv_dont_allocate : 1; + uint64_t __l2_sector_promote_256B : 1; + uint64_t __ap_reserved3 : 1; + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __get_descriptor_cexpr() const noexcept { + return + std::uint64_t(__ap_reserved) << 0 | + std::uint64_t(__block_count) << 37 | + std::uint64_t(__block_start) << 44 | + std::uint64_t(__ap_reserved2) << 51 | + std::uint64_t(__block_size) << 52 | + std::uint64_t(__l2_cop_off) << 56 | + std::uint64_t(__l2_cop_on) << 57 | + std::uint64_t(__l2_descriptor_mode) << 59 | + std::uint64_t(__l1_inv_dont_allocate) << 61 | + std::uint64_t(__l2_sector_promote_256B) << 62 | + std::uint64_t(__ap_reserved3) << 63; + } + + inline + _LIBCUDACXX_HOST_DEVICE + std::uint64_t __get_descriptor_non_cexpr() const noexcept { return *reinterpret_cast(this); } + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __get_descriptor() const noexcept { +#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) + return cuda::std::is_constant_evaluated() ? + __get_descriptor_cexpr() : + __get_descriptor_non_cexpr(); +#else + return __get_descriptor_cexpr(); +#endif + } + }; + static_assert(sizeof(__block_desc_t) == 8, "__block_desc_t should be 8 bytes"); + static_assert(sizeof(__block_desc_t) == sizeof(std::uint64_t), ""); + static_assert( + __block_desc_t{(uint64_t)1, (uint64_t)1, (uint64_t)1, (uint64_t)1, __block_size_t::_BLOCKSIZE_8K, __off::_L2_EVICT_FIRST, __on::_L2_EVICT_FIRST, __l2_descriptor_mode_t::_DESC_INTERLEAVED, (uint64_t)1, (uint64_t)1, (uint64_t)1}.__get_descriptor() + == 0xF318102000000001, ""); + + /* Factory like struct to build a __block_desc_t due to constexpr C++11 + */ + struct __block_descriptor_builder { //variable declaration order matters == usage order + std::uint32_t __offset; + __block_size_t __block_size; + std::uint32_t __block_start, __end_hit; + std::uint32_t __block_count; + __off::__l2_cop_off_t __l2_cop_off; + __on::__l2_cop_on_t __l2_cop_on; + __l2_descriptor_mode_t __l2_descriptor_mode; + bool __l1_inv_dont_allocate, __l2_sector_promote_256B; + + _LIBCUDACXX_HOST_DEVICE static constexpr std::uint32_t __calc_offset(std::size_t __total_bytes) { + return __ap_max(std::uint32_t{12}, static_cast(__ap_ceil_log2(static_cast(__total_bytes))) - std::uint32_t{7}); + } + + _LIBCUDACXX_HOST_DEVICE static constexpr std::uint32_t __calc_block_start(std::uintptr_t __ptr, std::size_t __total_bytes) { + return static_cast(__ptr >> __calc_offset(static_cast(__total_bytes))); + } + + _LIBCUDACXX_HOST_DEVICE static constexpr std::uint32_t __calc_end_hit(std::uintptr_t __ptr, std::size_t __hit_bytes, std::size_t __total_bytes) { + return static_cast((__ptr + __hit_bytes + (std::uintptr_t{1} << (__calc_offset(static_cast(__total_bytes)))) - 1) >> __calc_offset(static_cast(__total_bytes))); + } + + _LIBCUDACXX_HOST_DEVICE constexpr __block_descriptor_builder(std::uintptr_t __ptr, std::size_t __hit_bytes, std::size_t __total_bytes, __on::__l2_cop_on_t __hit_prop, __off::__l2_cop_off_t __miss_prop) + : __offset(__calc_offset(__total_bytes)) + , __block_size(static_cast<__block_size_t>(__calc_offset(__total_bytes) - std::uint32_t{12})) + , __block_start(__calc_block_start(__ptr, __total_bytes)) + , __end_hit(__calc_end_hit(__ptr, __hit_bytes, __total_bytes)) + , __block_count(__calc_end_hit(__ptr, __hit_bytes, __total_bytes) - __calc_block_start(__ptr, __total_bytes)) + , __l2_cop_off(__miss_prop) + , __l2_cop_on(__hit_prop) + , __l2_descriptor_mode(_DESC_BLOCK_TYPE) + , __l1_inv_dont_allocate(false) + , __l2_sector_promote_256B(false) + {} + + _LIBCUDACXX_HOST_DEVICE + constexpr __block_desc_t __get_block() const noexcept { + return __block_desc_t { 0, __ap_min(std::uint32_t{0x7f}, __block_count), (__block_start & std::uint32_t{0x7f}), 0, __block_size, __l2_cop_off, __l2_cop_on, _DESC_BLOCK_TYPE, false, false, 0 }; + } + }; + static_assert(sizeof(std::uintptr_t) > 4, "std::uintptr_t needs at least 5 bytes for this code to work"); + + struct __interleave_descriptor_t { + uint64_t __ap_reserved : 52; + uint64_t __fraction : 4; + __off::__l2_cop_off_t __l2_cop_off : 1; + __on::__l2_cop_on_t __l2_cop_on : 2; + __l2_descriptor_mode_t __l2_descriptor_mode : 2; + uint64_t __l1_inv_dont_allocate : 1; + uint64_t __l2_sector_promote_256B : 1; + uint64_t __ap_reserved2 : 1; + + _LIBCUDACXX_HOST_DEVICE + constexpr __interleave_descriptor_t( + __on::__l2_cop_on_t __hit_prop, + std::uint32_t __hit_ratio, + __off::__l2_cop_off_t __miss_prop) noexcept + : __fraction(__hit_ratio), + __l2_cop_off(__miss_prop), + __l2_cop_on(__hit_prop), + __l2_descriptor_mode(_DESC_INTERLEAVED), + __l1_inv_dont_allocate(0x0), + __l2_sector_promote_256B(0x0), + __ap_reserved(0x0), + __ap_reserved2(0x0) {} + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __get_descriptor_cexpr() const { + return + std::uint64_t(__ap_reserved) << 0 | + std::uint64_t(__fraction) << 52 | + std::uint64_t(__l2_cop_off) << 56 | + std::uint64_t(__l2_cop_on) << 57 | + std::uint64_t(__l2_descriptor_mode) << 59 | + std::uint64_t(__l1_inv_dont_allocate) << 61 | + std::uint64_t(__l2_sector_promote_256B) << 62 | + std::uint64_t(__ap_reserved2) << 63; + } + + inline + _LIBCUDACXX_HOST_DEVICE + std::uint64_t __get_descriptor_non_cexpr() const noexcept { return *reinterpret_cast(this); } + + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __get_descriptor() const noexcept { +#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) + return cuda::std::is_constant_evaluated() ? + __get_descriptor_cexpr() : + __get_descriptor_non_cexpr(); +#else + return __get_descriptor_cexpr(); +#endif + } + }; + static_assert(sizeof(__interleave_descriptor_t) == 8, "__interleave_descriptor_t should be 8 bytes"); + static_assert(sizeof(__interleave_descriptor_t) == sizeof(std::uint64_t), ""); + + _LIBCUDACXX_HOST_DEVICE + static constexpr std::uint64_t __interleave_normal() noexcept { + return 0x10F0000000000000; + } + + _LIBCUDACXX_HOST_DEVICE + static constexpr std::uint64_t __interleave_streaming() noexcept { + return 0x12F0000000000000; + } + + _LIBCUDACXX_HOST_DEVICE + static constexpr std::uint64_t __interleave_persisting() noexcept { + return 0x14F0000000000000; + } + + _LIBCUDACXX_HOST_DEVICE + static constexpr std::uint64_t __interleave_normal_demote() noexcept { + return 0x16F0000000000000; + } + + } // namespace __sm_80 + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __interleave(cudaAccessProperty __hit_prop, float __hit_ratio, cudaAccessProperty __miss_prop = cudaAccessPropertyNormal) { + return __sm_80::__interleave_descriptor_t( + ((__hit_prop == cudaAccessPropertyNormal) ? __sm_80::__on::__l2_cop_on_t::_L2_EVICT_NORMAL_DEMOTE : static_cast<__sm_80::__on::__l2_cop_on_t>(__hit_prop)), + __ap_min((static_cast(__hit_ratio) * __sm_80::__l2_eviction_max_way_t::_CUDA_AMPERE_MAX_L2_WAYS), static_cast(__sm_80::__l2_eviction_max_way_t::_CUDA_AMPERE_MAX_L2_WAYS - 1)), + static_cast<__sm_80::__off::__l2_cop_off_t>(__miss_prop) + ).__get_descriptor(); + } + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __block(void* __ptr, std::size_t __hit_bytes, std::size_t __total_bytes, cudaAccessProperty __hit_prop, cudaAccessProperty __miss_prop = cudaAccessPropertyNormal) { + return (__total_bytes <= (size_t{0xFFFFFFFF}) & __total_bytes != 0 & __hit_bytes <= __total_bytes) ? __sm_80::__block_descriptor_builder( + reinterpret_cast(__ptr), + __hit_bytes, + __total_bytes, + (__hit_prop == cudaAccessPropertyNormal) ? __sm_80::__on::_L2_EVICT_NORMAL_DEMOTE : static_cast<__sm_80::__on::__l2_cop_on_t>(__hit_prop), + static_cast<__sm_80::__off::__l2_cop_off_t>(__miss_prop) + ).__get_block().__get_descriptor() + : __sm_80::__interleave_normal(); + } +} // namespace __detail_ap + +_LIBCUDACXX_END_NAMESPACE_CUDA diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__annotated_ptr b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__annotated_ptr new file mode 100644 index 0000000000000000000000000000000000000000..e52c17f6dec956752fab0133f1df9bca04c47a53 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__annotated_ptr @@ -0,0 +1,227 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * NVIDIA SOFTWARE LICENSE + * + * This license is a legal agreement between you and NVIDIA Corporation ("NVIDIA") and governs your use of the NVIDIA/CUDA C++ Library software and materials provided hereunder (“SOFTWARE”). + * + * This license can be accepted only by an adult of legal age of majority in the country in which the SOFTWARE is used. If you are under the legal age of majority, you must ask your parent or legal guardian to consent to this license. By taking delivery of the SOFTWARE, you affirm that you have reached the legal age of majority, you accept the terms of this license, and you take legal and financial responsibility for the actions of your permitted users. + * + * You agree to use the SOFTWARE only for purposes that are permitted by (a) this license, and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions. + * + * 1. LICENSE. Subject to the terms of this license, NVIDIA grants you a non-exclusive limited license to: (a) install and use the SOFTWARE, and (b) distribute the SOFTWARE subject to the distribution requirements described in this license. NVIDIA reserves all rights, title and interest in and to the SOFTWARE not expressly granted to you under this license. + * + * 2. DISTRIBUTION REQUIREMENTS. These are the distribution requirements for you to exercise the distribution grant: + * a. The terms under which you distribute the SOFTWARE must be consistent with the terms of this license, including (without limitation) terms relating to the license grant and license restrictions and protection of NVIDIA’s intellectual property rights. + * b. You agree to notify NVIDIA in writing of any known or suspected distribution or use of the SOFTWARE not in compliance with the requirements of this license, and to enforce the terms of your agreements with respect to distributed SOFTWARE. + * + * 3. LIMITATIONS. Your license to use the SOFTWARE is restricted as follows: + * a. The SOFTWARE is licensed for you to develop applications only for use in systems with NVIDIA GPUs. + * b. You may not reverse engineer, decompile or disassemble, or remove copyright or other proprietary notices from any portion of the SOFTWARE or copies of the SOFTWARE. + * c. You may not modify or create derivative works of any portion of the SOFTWARE. + * d. You may not bypass, disable, or circumvent any technical measure, encryption, security, digital rights management or authentication mechanism in the SOFTWARE. + * e. You may not use the SOFTWARE in any manner that would cause it to become subject to an open source software license. As examples, licenses that require as a condition of use, modification, and/or distribution that the SOFTWARE be (i) disclosed or distributed in source code form; (ii) licensed for the purpose of making derivative works; or (iii) redistributable at no charge. + * f. Unless you have an agreement with NVIDIA for this purpose, you may not use the SOFTWARE with any system or application where the use or failure of the system or application can reasonably be expected to threaten or result in personal injury, death, or catastrophic loss. Examples include use in avionics, navigation, military, medical, life support or other life critical applications. NVIDIA does not design, test or manufacture the SOFTWARE for these critical uses and NVIDIA shall not be liable to you or any third party, in whole or in part, for any claims or damages arising from such uses. + * g. You agree to defend, indemnify and hold harmless NVIDIA and its affiliates, and their respective employees, contractors, agents, officers and directors, from and against any and all claims, damages, obligations, losses, liabilities, costs or debt, fines, restitutions and expenses (including but not limited to attorney’s fees and costs incident to establishing the right of indemnification) arising out of or related to use of the SOFTWARE outside of the scope of this Agreement, or not in compliance with its terms. + * + * 4. PRE-RELEASE. SOFTWARE versions identified as alpha, beta, preview, early access or otherwise as pre-release may not be fully functional, may contain errors or design flaws, and may have reduced or different security, privacy, availability, and reliability standards relative to commercial versions of NVIDIA software and materials. You may use a pre-release SOFTWARE version at your own risk, understanding that these versions are not intended for use in production or business-critical systems. + * + * 5. OWNERSHIP. The SOFTWARE and the related intellectual property rights therein are and will remain the sole and exclusive property of NVIDIA or its licensors. The SOFTWARE is copyrighted and protected by the laws of the United States and other countries, and international treaty provisions. NVIDIA may make changes to the SOFTWARE, at any time without notice, but is not obligated to support or update the SOFTWARE. + * + * 6. COMPONENTS UNDER OTHER LICENSES. The SOFTWARE may include NVIDIA or third-party components with separate legal notices or terms as may be described in proprietary notices accompanying the SOFTWARE. If and to the extent there is a conflict between the terms in this license and the license terms associated with a component, the license terms associated with the components control only to the extent necessary to resolve the conflict. + * + * 7. FEEDBACK. You may, but don’t have to, provide to NVIDIA any Feedback. “Feedback” means any suggestions, bug fixes, enhancements, modifications, feature requests or other feedback regarding the SOFTWARE. For any Feedback that you voluntarily provide, you hereby grant NVIDIA and its affiliates a perpetual, non-exclusive, worldwide, irrevocable license to use, reproduce, modify, license, sublicense (through multiple tiers of sublicensees), and distribute (through multiple tiers of distributors) the Feedback without the payment of any royalties or fees to you. NVIDIA will use Feedback at its choice. + * + * 8. NO WARRANTIES. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. NVIDIA DOES NOT WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION THEREOF WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ALL ERRORS WILL BE CORRECTED. + * + * 9. LIMITATIONS OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY LAW, NVIDIA AND ITS AFFILIATES SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR ANY LOST PROFITS, PROJECT DELAYS, LOSS OF USE, LOSS OF DATA OR LOSS OF GOODWILL, OR THE COSTS OF PROCURING SUBSTITUTE PRODUCTS, ARISING OUT OF OR IN CONNECTION WITH THIS LICENSE OR THE USE OR PERFORMANCE OF THE SOFTWARE, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCT LIABILITY OR ANY OTHER CAUSE OF ACTION OR THEORY OF LIABILITY, EVEN IF NVIDIA HAS PREVIOUSLY BEEN ADVISED OF, OR COULD REASONABLY HAVE FORESEEN, THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL NVIDIA’S AND ITS AFFILIATES TOTAL CUMULATIVE LIABILITY UNDER OR ARISING OUT OF THIS LICENSE EXCEED US$10.00. THE NATURE OF THE LIABILITY OR THE NUMBER OF CLAIMS OR SUITS SHALL NOT ENLARGE OR EXTEND THIS LIMIT. + * + * 10. TERMINATION. Your rights under this license will terminate automatically without notice from NVIDIA if you fail to comply with any term and condition of this license or if you commence or participate in any legal proceeding against NVIDIA with respect to the SOFTWARE. NVIDIA may terminate this license with advance written notice to you if NVIDIA decides to no longer provide the SOFTWARE in a country or, in NVIDIA’s sole discretion, the continued use of it is no longer commercially viable. Upon any termination of this license, you agree to promptly discontinue use of the SOFTWARE and destroy all copies in your possession or control. Your prior distributions in accordance with this license are not affected by the termination of this license. All provisions of this license will survive termination, except for the license granted to you. + * + * 11. APPLICABLE LAW. This license will be governed in all respects by the laws of the United States and of the State of Delaware as those laws are applied to contracts entered into and performed entirely within Delaware by Delaware residents, without regard to the conflicts of laws principles. The United Nations Convention on Contracts for the International Sale of Goods is specifically disclaimed. You agree to all terms of this Agreement in the English language. The state or federal courts residing in Santa Clara County, California shall have exclusive jurisdiction over any dispute or claim arising out of this license. Notwithstanding this, you agree that NVIDIA shall still be allowed to apply for injunctive remedies or an equivalent type of urgent legal relief in any jurisdiction. + * + * 12. NO ASSIGNMENT. This license and your rights and obligations thereunder may not be assigned by you by any means or operation of law without NVIDIA’s permission. Any attempted assignment not approved by NVIDIA in writing shall be void and of no effect. + * + * 13. EXPORT. The SOFTWARE is subject to United States export laws and regulations. You agree that you will not ship, transfer or export the SOFTWARE into any country, or use the SOFTWARE in any manner, prohibited by the United States Bureau of Industry and Security or economic sanctions regulations administered by the U.S. Department of Treasury’s Office of Foreign Assets Control (OFAC), or any applicable export laws, restrictions or regulations. These laws include restrictions on destinations, end users and end use. By accepting this license, you confirm that you are not a resident or citizen of any country currently embargoed by the U.S. and that you are not otherwise prohibited from receiving the SOFTWARE. + * + * 14. GOVERNMENT USE. The SOFTWARE has been developed entirely at private expense and is “commercial items” consisting of “commercial computer software” and “commercial computer software documentation” provided with RESTRICTED RIGHTS. Use, duplication or disclosure by the U.S. Government or a U.S. Government subcontractor is subject to the restrictions in this license pursuant to DFARS 227.7202-3(a) or as set forth in subparagraphs (b)(1) and (2) of the Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, as applicable. Contractor/manufacturer is NVIDIA, 2788 San Tomas Expressway, Santa Clara, CA 95051. + * + * 15. ENTIRE AGREEMENT. This license is the final, complete and exclusive agreement between the parties relating to the subject matter of this license and supersedes all prior or contemporaneous understandings and agreements relating to this subject matter, whether oral or written. If any court of competent jurisdiction determines that any provision of this license is illegal, invalid or unenforceable, the remaining provisions will remain in full force and effect. This license may only be modified in a writing signed by an authorized representative of each party. + * + * (v. August 20, 2021) + */ + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +namespace __detail_ap { + + template + _LIBCUDACXX_DEVICE + void* __associate_address_space(void* __ptr, _Property __prop) { + if (std::is_same<_Property, access_property::shared>::value == true) { + bool __b = __isShared(__ptr); + _LIBCUDACXX_ASSERT(__b, ""); +#if !defined(_LIBCUDACXX_CUDACC_BELOW_11_2) + __builtin_assume(__b); +#endif // !defined(_LIBCUDACXX_CUDACC_BELOW_11_2) + } else if (std::is_same<_Property, access_property::global>::value == true || + std::is_same<_Property, access_property::normal>::value == true || + std::is_same<_Property, access_property::persisting>::value == true || + std::is_same<_Property, access_property::streaming>::value == true || + std::is_same<_Property, access_property>::value) { + bool __b = __isGlobal(__ptr); + _LIBCUDACXX_ASSERT(__b, ""); +#if !defined(_LIBCUDACXX_CUDACC_BELOW_11_2) + __builtin_assume(__b); +#endif // !defined(_LIBCUDACXX_CUDACC_BELOW_11_2) + } + + return __ptr; + } + + template + _LIBCUDACXX_DEVICE + void* __associate_descriptor(void* __ptr, __Prop __prop) { + return __associate_descriptor(__ptr, static_cast(access_property(__prop))); + } + + template <> + inline _LIBCUDACXX_DEVICE + void* __associate_descriptor(void* __ptr, std::uint64_t __prop) { + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_80,( + return __nv_associate_access_property(__ptr, __prop); + ),( + return __ptr; + )) + } + + template<> + inline _LIBCUDACXX_DEVICE + void* __associate_descriptor(void* __ptr, access_property::shared) { + return __ptr; + } + + template + _LIBCUDACXX_HOST_DEVICE + _Type* __associate(_Type* __ptr, _Property __prop) { + NV_IF_ELSE_TARGET(NV_IS_DEVICE,( + return static_cast<_Type*>(__associate_descriptor( + __associate_address_space(const_cast(static_cast(__ptr)), __prop), + __prop)); + ),( + return __ptr; + )) + } + + + template + class __annotated_ptr_base { + using __error = typename _Property::__unknown_access_property_type; + }; + + template<> + class __annotated_ptr_base { + protected: + static constexpr std::uint64_t __prop = 0; + + constexpr __annotated_ptr_base() noexcept = default; + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property::shared) noexcept {} + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, access_property::shared{}); + } + _LIBCUDACXX_HOST_DEVICE constexpr access_property::shared __get_property() const noexcept { + return access_property::shared{}; + } + }; + + template<> + class __annotated_ptr_base { + protected: + static constexpr std::uint64_t __prop = __sm_80::__interleave_normal(); + + constexpr __annotated_ptr_base() noexcept = default; + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property::global) noexcept {} + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, access_property::global{}); + } + _LIBCUDACXX_HOST_DEVICE constexpr access_property::global __get_property() const noexcept { + return access_property::global{}; + } + }; + + template<> + class __annotated_ptr_base { + protected: + static constexpr std::uint64_t __prop = __sm_80::__interleave_normal_demote(); + + constexpr __annotated_ptr_base() noexcept = default; + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property::normal) noexcept {} + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, access_property::normal{}); + } + _LIBCUDACXX_HOST_DEVICE constexpr access_property::normal __get_property() const noexcept { + return access_property::normal{}; + } + }; + + template<> + class __annotated_ptr_base { + protected: + static constexpr std::uint64_t __prop = __sm_80::__interleave_persisting(); + + constexpr __annotated_ptr_base() noexcept = default; + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property::persisting) noexcept {} + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, access_property::persisting{}); + } + _LIBCUDACXX_HOST_DEVICE constexpr access_property::persisting __get_property() const noexcept { + return access_property::persisting{}; + } + }; + + template<> + class __annotated_ptr_base { + protected: + static constexpr std::uint64_t __prop = __sm_80::__interleave_streaming(); + + constexpr __annotated_ptr_base() noexcept = default; + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property::streaming) noexcept {} + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, access_property::streaming{}); + } + _LIBCUDACXX_HOST_DEVICE constexpr access_property::streaming __get_property() const noexcept { + return access_property::streaming{}; + } + }; + + template<> + class __annotated_ptr_base { + protected: + std::uint64_t __prop; + + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base() noexcept : __prop(access_property()) {} + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(std::uint64_t __property) noexcept : __prop(__property) {} + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property __property) noexcept + : __annotated_ptr_base(static_cast(__property)) {} + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, __prop); + } + _LIBCUDACXX_HOST_DEVICE access_property __get_property() const noexcept { + return reinterpret_cast(const_cast(__prop)); + } + }; +} // namespace __detail_ap + +_LIBCUDACXX_END_NAMESPACE_CUDA diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__config b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__config new file mode 100644 index 0000000000000000000000000000000000000000..b6dee85435b4939af58de45d2421c6d3ccdf01a9 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__config @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef __cuda_std__ +#define __cuda_std__ + +#define _LIBCUDACXX_CUDA_API_VERSION 2002000 + +#define _LIBCUDACXX_CUDA_API_VERSION_MAJOR \ + (_LIBCUDACXX_CUDA_API_VERSION / 1000000) + +#define _LIBCUDACXX_CUDA_API_VERSION_MINOR \ + (_LIBCUDACXX_CUDA_API_VERSION / 1000 % 1000) + +#define _LIBCUDACXX_CUDA_API_VERSION_PATCH \ + (_LIBCUDACXX_CUDA_API_VERSION % 1000) + +#ifndef _LIBCUDACXX_CUDA_ABI_VERSION_LATEST +# define _LIBCUDACXX_CUDA_ABI_VERSION_LATEST 4 +#endif + +#ifdef _LIBCUDACXX_CUDA_ABI_VERSION +# if _LIBCUDACXX_CUDA_ABI_VERSION != 2 && _LIBCUDACXX_CUDA_ABI_VERSION != 3 && _LIBCUDACXX_CUDA_ABI_VERSION != 4 +# error Unsupported libcu++ ABI version requested. Please define _LIBCUDACXX_CUDA_ABI_VERSION to either 2 or 3. +# endif +#else +# define _LIBCUDACXX_CUDA_ABI_VERSION _LIBCUDACXX_CUDA_ABI_VERSION_LATEST +#endif + +#ifdef _LIBCUDACXX_PIPELINE_ASSUMED_ABI_VERSION +# if _LIBCUDACXX_PIPELINE_ASSUMED_ABI_VERSION != _LIBCUDACXX_CUDA_ABI_VERSION +# error cuda_pipeline.h has assumed a different libcu++ ABI version than provided by this library. To fix this, please include a libcu++ header before including cuda_pipeline.h, or upgrade to a version of the toolkit this version of libcu++ shipped in. +# endif +#endif + +#include "libcxx/include/__config" + +#endif //__cuda_std__ diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__pragma_pop b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__pragma_pop new file mode 100644 index 0000000000000000000000000000000000000000..834c9ea541a9687df2c09da4c1674318a86595ce --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__pragma_pop @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#include "libcxx/include/__pragma_pop" + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__pragma_push b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__pragma_push new file mode 100644 index 0000000000000000000000000000000000000000..1b7ba00994c13e00b8d020afd61d40a9b5569a2f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/__pragma_push @@ -0,0 +1,13 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#include "libcxx/include/__pragma_push" +#include "libcxx/include/__undef_macros" + diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__algorithm/swap_ranges.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__algorithm/swap_ranges.h new file mode 100644 index 0000000000000000000000000000000000000000..fc315ba628523ac9e906a6a6524054a4a6911825 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__algorithm/swap_ranges.h @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ALGORITHM_SWAP_RANGES_H +#define _LIBCUDACXX___ALGORITHM_SWAP_RANGES_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__utility/swap.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +_ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) +{ + for(; __first1 != __last1; ++__first1, (void) ++__first2) + swap(*__first1, *__first2); + return __first2; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ALGORITHM_SWAP_RANGES_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__assert b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__assert new file mode 100644 index 0000000000000000000000000000000000000000..1d3eea00d84780251e723da38b0b43ad8cb4832a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__assert @@ -0,0 +1,66 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ASSERT +#define _LIBCUDACXX___ASSERT + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "__verbose_abort" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +// This is for backwards compatibility with code that might have been enabling +// assertions through the Debug mode previously. +// TODO: In LLVM 16, make it an error to define _LIBCUDACXX_DEBUG +#if defined(_LIBCUDACXX_DEBUG) +# ifndef _LIBCUDACXX_ENABLE_ASSERTIONS +# define _LIBCUDACXX_ENABLE_ASSERTIONS 1 +# endif +#endif + +// Automatically enable assertions when the debug mode is enabled. +#if defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) +# ifndef _LIBCUDACXX_ENABLE_ASSERTIONS +# define _LIBCUDACXX_ENABLE_ASSERTIONS 1 +# endif +#endif + +#ifndef _LIBCUDACXX_ENABLE_ASSERTIONS +# define _LIBCUDACXX_ENABLE_ASSERTIONS _LIBCUDACXX_ENABLE_ASSERTIONS_DEFAULT +#endif + +#if _LIBCUDACXX_ENABLE_ASSERTIONS != 0 && _LIBCUDACXX_ENABLE_ASSERTIONS != 1 +# error "_LIBCUDACXX_ENABLE_ASSERTIONS must be set to 0 or 1" +#endif + +#if _LIBCUDACXX_ENABLE_ASSERTIONS +# define _LIBCUDACXX_ASSERT(expression, message) \ + (_LIBCUDACXX_DIAGNOSTIC_PUSH \ + _LIBCUDACXX_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \ + __builtin_expect(static_cast(expression), 1) ? \ + (void)0 : \ + ::_CUDA_VSTD::__libcpp_verbose_abort("%s:%d: assertion %s failed: %s", __FILE__, __LINE__, #expression, message) + _LIBCUDACXX_DIAGNOSTIC_POP) +#elif 0 // !defined(_LIBCUDACXX_ASSERTIONS_DISABLE_ASSUME) && __has_builtin(__builtin_assume) +# define _LIBCUDACXX_ASSERT(expression, message) \ + (_LIBCUDACXX_DIAGNOSTIC_PUSH \ + _LIBCUDACXX_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \ + __builtin_assume(static_cast(expression)) \ + _LIBCUDACXX_DIAGNOSTIC_POP) +#else +# define _LIBCUDACXX_ASSERT(expression, message) ((void)0) +#endif + +#endif // _LIBCUDACXX___ASSERT diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__availability b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__availability new file mode 100644 index 0000000000000000000000000000000000000000..ef401c005c6419b6f83999f7cc809bd60742d866 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__availability @@ -0,0 +1,302 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___AVAILABILITY +#define _LIBCUDACXX___AVAILABILITY + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +// Libc++ is shipped by various vendors. In particular, it is used as a system +// library on macOS, iOS and other Apple platforms. In order for users to be +// able to compile a binary that is intended to be deployed to an older version +// of a platform, Clang provides availability attributes [1]. These attributes +// can be placed on declarations and are used to describe the life cycle of a +// symbol in the library. +// +// The main goal is to ensure a compile-time error if a symbol that hasn't been +// introduced in a previously released library is used in a program that targets +// that previously released library. Normally, this would be a load-time error +// when one tries to launch the program against the older library. +// +// For example, the filesystem library was introduced in the dylib in macOS 10.15. +// If a user compiles on a macOS 10.15 host but targets macOS 10.13 with their +// program, the compiler would normally not complain (because the required +// declarations are in the headers), but the dynamic loader would fail to find +// the symbols when actually trying to launch the program on macOS 10.13. To +// turn this into a compile-time issue instead, declarations are annotated with +// when they were introduced, and the compiler can produce a diagnostic if the +// program references something that isn't available on the deployment target. +// +// This mechanism is general in nature, and any vendor can add their markup to +// the library (see below). Whenever a new feature is added that requires support +// in the shared library, a macro should be added below to mark this feature +// as unavailable. When vendors decide to ship the feature as part of their +// shared library, they can update the markup appropriately. +// +// Furthermore, many features in the standard library have corresponding +// feature-test macros. When a feature is made unavailable on some deployment +// target, a macro should be defined to signal that it is unavailable. That +// macro can then be picked up when feature-test macros are generated (see +// generate_feature_test_macro_components.py) to make sure that feature-test +// macros don't announce a feature as being implemented if it has been marked +// as unavailable. +// +// Note that this mechanism is disabled by default in the "upstream" libc++. +// Availability annotations are only meaningful when shipping libc++ inside +// a platform (i.e. as a system library), and so vendors that want them should +// turn those annotations on at CMake configuration time. +// +// [1]: https://clang.llvm.org/docs/AttributeReference.html#availability + + +// For backwards compatibility, allow users to define _LIBCUDACXX_DISABLE_AVAILABILITY +// for a while. +#if defined(_LIBCUDACXX_DISABLE_AVAILABILITY) +# if !defined(_LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) +# define _LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS +# endif +#endif + +// Availability markup is disabled when building the library, or when the compiler +// doesn't support the proper attributes. +#if defined(_LIBCUDACXX_BUILDING_LIBRARY) || \ + defined(_LIBCXXABI_BUILDING_LIBRARY) || \ + !__has_feature(attribute_availability_with_strict) || \ + !__has_feature(attribute_availability_in_templates) || \ + !__has_extension(pragma_clang_attribute_external_declaration) +# if !defined(_LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) +# define _LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS +# endif +#endif + +#if defined(_LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) + + // This controls the availability of std::shared_mutex and std::shared_timed_mutex, + // which were added to the dylib later. +# define _LIBCUDACXX_AVAILABILITY_SHARED_MUTEX +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_mutex +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex + + // These macros control the availability of std::bad_optional_access and + // other exception types. These were put in the shared library to prevent + // code bloat from every user program defining the vtable for these exception + // types. + // + // Note that when exceptions are disabled, the methods that normally throw + // these exceptions can be used even on older deployment targets, but those + // methods will abort instead of throwing. +# define _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS +# define _LIBCUDACXX_AVAILABILITY_BAD_VARIANT_ACCESS +# define _LIBCUDACXX_AVAILABILITY_BAD_ANY_CAST + + // This controls the availability of std::uncaught_exceptions(). +# define _LIBCUDACXX_AVAILABILITY_UNCAUGHT_EXCEPTIONS + + // This controls the availability of the sized version of ::operator delete, + // ::operator delete[], and their align_val_t variants, which were all added + // in C++17, and hence not present in early dylibs. +# define _LIBCUDACXX_AVAILABILITY_SIZED_NEW_DELETE + + // This controls the availability of the std::future_error exception. + // + // Note that when exceptions are disabled, the methods that normally throw + // std::future_error can be used even on older deployment targets, but those + // methods will abort instead of throwing. +# define _LIBCUDACXX_AVAILABILITY_FUTURE_ERROR + + // This controls the availability of std::type_info's vtable. + // I can't imagine how using std::type_info can work at all if + // this isn't supported. +# define _LIBCUDACXX_AVAILABILITY_TYPEINFO_VTABLE + + // This controls the availability of std::locale::category members + // (e.g. std::locale::collate), which are defined in the dylib. +# define _LIBCUDACXX_AVAILABILITY_LOCALE_CATEGORY + + // This controls the availability of atomic operations on std::shared_ptr + // (e.g. `std::atomic_store(std::shared_ptr)`), which require a shared + // lock table located in the dylib. +# define _LIBCUDACXX_AVAILABILITY_ATOMIC_SHARED_PTR + + // These macros control the availability of all parts of that + // depend on something in the dylib. +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_PUSH +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_POP +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem + + // This controls the availability of floating-point std::to_chars functions. + // These overloads were added later than the integer overloads. +# define _LIBCUDACXX_AVAILABILITY_TO_CHARS_FLOATING_POINT + + // This controls the availability of the C++20 synchronization library, + // which requires shared library support for various operations + // (see libcxx/src/atomic.cpp). This includes , , + // , and notification functions on std::atomic. +# define _LIBCUDACXX_AVAILABILITY_SYNC +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_latch +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore + + // This controls the availability of the C++20 format library. + // The library is in development and not ABI stable yet. P2216 is + // retroactively accepted in C++20. This paper contains ABI breaking + // changes. +# define _LIBCUDACXX_AVAILABILITY_FORMAT +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_format + + // This controls whether the default verbose termination function is + // provided by the library. + // + // Note that when users provide their own custom function, it doesn't + // matter whether the dylib provides a default function, and the + // availability markup can actually give a false positive diagnostic + // (it will think that no function is provided, when in reality the + // user has provided their own). + // + // Users can pass -D_LIBCUDACXX_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED + // to the compiler to tell the library not to define its own verbose abort. + // Note that defining this macro but failing to define a custom function + // will lead to a load-time error on back-deployment targets, so it should + // be avoided. +// # define _LIBCUDACXX_HAS_NO_VERBOSE_ABORT_IN_LIBRARY + +#elif defined(__APPLE__) + +# define _LIBCUDACXX_AVAILABILITY_SHARED_MUTEX \ + __attribute__((availability(macos,strict,introduced=10.12))) \ + __attribute__((availability(ios,strict,introduced=10.0))) \ + __attribute__((availability(tvos,strict,introduced=10.0))) \ + __attribute__((availability(watchos,strict,introduced=3.0))) +# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 100000) || \ + (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 100000) || \ + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 30000) +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_mutex +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex +# endif + + // Note: bad_optional_access & friends were not introduced in the matching + // macOS and iOS versions, so the version mismatch between macOS and others + // is intended. +# define _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS \ + __attribute__((availability(macos,strict,introduced=10.13))) \ + __attribute__((availability(ios,strict,introduced=12.0))) \ + __attribute__((availability(tvos,strict,introduced=12.0))) \ + __attribute__((availability(watchos,strict,introduced=5.0))) +# define _LIBCUDACXX_AVAILABILITY_BAD_VARIANT_ACCESS \ + _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS +# define _LIBCUDACXX_AVAILABILITY_BAD_ANY_CAST \ + _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS + +# define _LIBCUDACXX_AVAILABILITY_UNCAUGHT_EXCEPTIONS \ + __attribute__((availability(macos,strict,introduced=10.12))) \ + __attribute__((availability(ios,strict,introduced=10.0))) \ + __attribute__((availability(tvos,strict,introduced=10.0))) \ + __attribute__((availability(watchos,strict,introduced=3.0))) + +# define _LIBCUDACXX_AVAILABILITY_SIZED_NEW_DELETE \ + __attribute__((availability(macos,strict,introduced=10.12))) \ + __attribute__((availability(ios,strict,introduced=10.0))) \ + __attribute__((availability(tvos,strict,introduced=10.0))) \ + __attribute__((availability(watchos,strict,introduced=3.0))) + +# define _LIBCUDACXX_AVAILABILITY_FUTURE_ERROR \ + __attribute__((availability(ios,strict,introduced=6.0))) + +# define _LIBCUDACXX_AVAILABILITY_TYPEINFO_VTABLE \ + __attribute__((availability(macos,strict,introduced=10.9))) \ + __attribute__((availability(ios,strict,introduced=7.0))) + +# define _LIBCUDACXX_AVAILABILITY_LOCALE_CATEGORY \ + __attribute__((availability(macos,strict,introduced=10.9))) \ + __attribute__((availability(ios,strict,introduced=7.0))) + +# define _LIBCUDACXX_AVAILABILITY_ATOMIC_SHARED_PTR \ + __attribute__((availability(macos,strict,introduced=10.9))) \ + __attribute__((availability(ios,strict,introduced=7.0))) + +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM \ + __attribute__((availability(macos,strict,introduced=10.15))) \ + __attribute__((availability(ios,strict,introduced=13.0))) \ + __attribute__((availability(tvos,strict,introduced=13.0))) \ + __attribute__((availability(watchos,strict,introduced=6.0))) +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_PUSH \ + _Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))") +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_POP \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") +# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \ + (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000) || \ + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000) +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem +# endif + +# define _LIBCUDACXX_AVAILABILITY_TO_CHARS_FLOATING_POINT \ + __attribute__((unavailable)) + +# define _LIBCUDACXX_AVAILABILITY_SYNC \ + __attribute__((availability(macos,strict,introduced=11.0))) \ + __attribute__((availability(ios,strict,introduced=14.0))) \ + __attribute__((availability(tvos,strict,introduced=14.0))) \ + __attribute__((availability(watchos,strict,introduced=7.0))) +# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000) || \ + (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 140000) || \ + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 70000) +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_latch +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore +# endif + +# define _LIBCUDACXX_AVAILABILITY_FORMAT \ + __attribute__((unavailable)) +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_format + +# define _LIBCUDACXX_HAS_NO_VERBOSE_ABORT_IN_LIBRARY + +#else + +// ...New vendors can add availability markup here... + +# error "It looks like you're trying to enable vendor availability markup, but you haven't defined the corresponding macros yet!" + +#endif + +// Define availability attributes that depend on _LIBCUDACXX_NO_EXCEPTIONS. +// Those are defined in terms of the availability attributes above, and +// should not be vendor-specific. +#if defined(_LIBCUDACXX_NO_EXCEPTIONS) +# define _LIBCUDACXX_AVAILABILITY_FUTURE +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_ANY_CAST +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +#else +# define _LIBCUDACXX_AVAILABILITY_FUTURE _LIBCUDACXX_AVAILABILITY_FUTURE_ERROR +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_ANY_CAST _LIBCUDACXX_AVAILABILITY_BAD_ANY_CAST +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_VARIANT_ACCESS _LIBCUDACXX_AVAILABILITY_BAD_VARIANT_ACCESS +#endif + +#endif // _LIBCUDACXX___AVAILABILITY diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__bit_reference b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__bit_reference new file mode 100644 index 0000000000000000000000000000000000000000..851cbeacfc594544c282115bc5aac2afd77e08b7 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__bit_reference @@ -0,0 +1,1289 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___BIT_REFERENCE +#define _LIBCUDACXX___BIT_REFERENCE + +#include <__config> +#include +#include + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_PUSH_MACROS +#include <__undef_macros> + + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template class __bit_iterator; +template class __bit_const_reference; + +template +struct __has_storage_type +{ + static const bool value = false; +}; + +template ::value> +class __bit_reference +{ + typedef typename _Cp::__storage_type __storage_type; + typedef typename _Cp::__storage_pointer __storage_pointer; + + __storage_pointer __seg_; + __storage_type __mask_; + + friend typename _Cp::__self; + + friend class __bit_const_reference<_Cp>; + friend class __bit_iterator<_Cp, false>; +public: + _LIBCUDACXX_INLINE_VISIBILITY + __bit_reference(const __bit_reference&) = default; + + _LIBCUDACXX_INLINE_VISIBILITY operator bool() const _NOEXCEPT + {return static_cast(*__seg_ & __mask_);} + _LIBCUDACXX_INLINE_VISIBILITY bool operator ~() const _NOEXCEPT + {return !static_cast(*this);} + + _LIBCUDACXX_INLINE_VISIBILITY + __bit_reference& operator=(bool __x) _NOEXCEPT + { + if (__x) + *__seg_ |= __mask_; + else + *__seg_ &= ~__mask_; + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT + {return operator=(static_cast(__x));} + + _LIBCUDACXX_INLINE_VISIBILITY void flip() _NOEXCEPT {*__seg_ ^= __mask_;} + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator<_Cp, false> operator&() const _NOEXCEPT + {return __bit_iterator<_Cp, false>(__seg_, static_cast(__libcpp_ctz(__mask_)));} +private: + _LIBCUDACXX_INLINE_VISIBILITY + __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT + : __seg_(__s), __mask_(__m) {} +}; + +template +class __bit_reference<_Cp, false> +{ +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(bool& __x, __bit_reference<_Cp> __y) _NOEXCEPT +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template +class __bit_const_reference +{ + typedef typename _Cp::__storage_type __storage_type; + typedef typename _Cp::__const_storage_pointer __storage_pointer; + + __storage_pointer __seg_; + __storage_type __mask_; + + friend typename _Cp::__self; + friend class __bit_iterator<_Cp, true>; +public: + _LIBCUDACXX_INLINE_VISIBILITY + __bit_const_reference(const __bit_const_reference&) = default; + + _LIBCUDACXX_INLINE_VISIBILITY + __bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT + : __seg_(__x.__seg_), __mask_(__x.__mask_) {} + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR operator bool() const _NOEXCEPT + {return static_cast(*__seg_ & __mask_);} + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const _NOEXCEPT + {return __bit_iterator<_Cp, true>(__seg_, static_cast(__libcpp_ctz(__mask_)));} +private: + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR + __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT + : __seg_(__s), __mask_(__m) {} + + __bit_const_reference& operator=(const __bit_const_reference&) = delete; +}; + +// find + +template +__bit_iterator<_Cp, _IsConst> +__find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + static const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(__b))); + if (__n == __dn) + return __first + __n; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + if (*__first.__seg_) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(*__first.__seg_))); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(__b))); + } + return _It(__first.__seg_, static_cast(__n)); +} + +template +__bit_iterator<_Cp, _IsConst> +__find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = ~*__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(__b))); + if (__n == __dn) + return __first + __n; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + { + __storage_type __b = ~*__first.__seg_; + if (__b) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(__b))); + } + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = ~*__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(__b))); + } + return _It(__first.__seg_, static_cast(__n)); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<_Cp, _IsConst> +find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_) +{ + if (static_cast(__value_)) + return __find_bool_true(__first, static_cast(__last - __first)); + return __find_bool_false(__first, static_cast(__last - __first)); +} + +// count + +template +typename __bit_iterator<_Cp, _IsConst>::difference_type +__count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + typedef typename _It::difference_type difference_type; + const int __bits_per_word = _It::__bits_per_word; + difference_type __r = 0; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __r = _CUDA_VSTD::__libcpp_popcount(*__first.__seg_ & __m); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + __r += _CUDA_VSTD::__libcpp_popcount(*__first.__seg_); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __r += _CUDA_VSTD::__libcpp_popcount(*__first.__seg_ & __m); + } + return __r; +} + +template +typename __bit_iterator<_Cp, _IsConst>::difference_type +__count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + typedef typename _It::difference_type difference_type; + const int __bits_per_word = _It::__bits_per_word; + difference_type __r = 0; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __r = _CUDA_VSTD::__libcpp_popcount(~*__first.__seg_ & __m); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + __r += _CUDA_VSTD::__libcpp_popcount(~*__first.__seg_); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __r += _CUDA_VSTD::__libcpp_popcount(~*__first.__seg_ & __m); + } + return __r; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __bit_iterator<_Cp, _IsConst>::difference_type +count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_) +{ + if (static_cast(__value_)) + return __count_bool_true(__first, static_cast(__last - __first)); + return __count_bool_false(__first, static_cast(__last - __first)); +} + +// fill_n + +template +void +__fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, false> _It; + typedef typename _It::__storage_type __storage_type; + const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + *__first.__seg_ &= ~__m; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + __storage_type __nw = __n / __bits_per_word; + _CUDA_VSTD::memset(_CUDA_VSTD::__to_raw_pointer(__first.__seg_), 0, __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last partial word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__first.__seg_ &= ~__m; + } +} + +template +void +__fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, false> _It; + typedef typename _It::__storage_type __storage_type; + const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + *__first.__seg_ |= __m; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + __storage_type __nw = __n / __bits_per_word; + _CUDA_VSTD::memset(_CUDA_VSTD::__to_raw_pointer(__first.__seg_), -1, __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last partial word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__first.__seg_ |= __m; + } +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __value_) +{ + if (__n > 0) + { + if (__value_) + __fill_n_true(__first, __n); + else + __fill_n_false(__first, __n); + } +} + +// fill + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool __value_) +{ + _CUDA_VSTD::fill_n(__first, static_cast(__last - __first), __value_); +} + +// copy + +template +__bit_iterator<_Cp, false> +__copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + __storage_type __b = *__first.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + __storage_type __nw = __n / __bits_per_word; + _CUDA_VSTD::memmove(_CUDA_VSTD::__to_raw_pointer(__result.__seg_), + _CUDA_VSTD::__to_raw_pointer(__first.__seg_), + __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + __result.__seg_ += __nw; + // do last word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast(__n); + } + } + return __result; +} + +template +__bit_iterator<_Cp, false> +__copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + static const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _CUDA_VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __first.__ctz_) + *__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_); + else + *__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_); + __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> (__first.__ctz_ + __ddn); + __result.__ctz_ = static_cast(__dn); + } + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __m = ~__storage_type(0) << __result.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) + { + __storage_type __b = *__first.__seg_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << __result.__ctz_; + ++__result.__seg_; + *__result.__seg_ &= __m; + *__result.__seg_ |= __b >> __clz_r; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + __storage_type __dn = _CUDA_VSTD::min(__n, static_cast(__clz_r)); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << __result.__ctz_; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> __dn; + __result.__ctz_ = static_cast(__n); + } + } + } + return __result; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + if (__first.__ctz_ == __result.__ctz_) + return __copy_aligned(__first, __last, __result); + return __copy_unaligned(__first, __last, __result); +} + +// copy_backward + +template +__bit_iterator<_Cp, false> +__copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__last.__ctz_ != 0) + { + difference_type __dn = _CUDA_VSTD::min(static_cast(__last.__ctz_), __n); + __n -= __dn; + unsigned __clz = __bits_per_word - __last.__ctz_; + __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz); + __storage_type __b = *__last.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + // __last.__ctz_ = 0 + } + // __last.__ctz_ == 0 || __n == 0 + // __result.__ctz_ == 0 || __n == 0 + // do middle words + __storage_type __nw = __n / __bits_per_word; + __result.__seg_ -= __nw; + __last.__seg_ -= __nw; + _CUDA_VSTD::memmove(_CUDA_VSTD::__to_raw_pointer(__result.__seg_), + _CUDA_VSTD::__to_raw_pointer(__last.__seg_), + __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) << (__bits_per_word - __n); + __storage_type __b = *--__last.__seg_ & __m; + *--__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); + } + } + return __result; +} + +template +__bit_iterator<_Cp, false> +__copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__last.__ctz_ != 0) + { + difference_type __dn = _CUDA_VSTD::min(static_cast(__last.__ctz_), __n); + __n -= __dn; + unsigned __clz_l = __bits_per_word - __last.__ctz_; + __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_l); + __storage_type __b = *__last.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _CUDA_VSTD::min(__dn, static_cast(__result.__ctz_)); + if (__ddn > 0) + { + __m = (~__storage_type(0) << (__result.__ctz_ - __ddn)) & (~__storage_type(0) >> __clz_r); + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __last.__ctz_) + *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); + else + *__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_); + __result.__ctz_ = static_cast(((-__ddn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + } + if (__dn > 0) + { + // __result.__ctz_ == 0 + --__result.__seg_; + __result.__ctz_ = static_cast(-__dn & (__bits_per_word - 1)); + __m = ~__storage_type(0) << __result.__ctz_; + *__result.__seg_ &= ~__m; + __last.__ctz_ -= __dn + __ddn; + *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); + } + // __last.__ctz_ = 0 + } + // __last.__ctz_ == 0 || __n == 0 + // __result.__ctz_ != 0 || __n == 0 + // do middle words + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __m = ~__storage_type(0) >> __clz_r; + for (; __n >= __bits_per_word; __n -= __bits_per_word) + { + __storage_type __b = *--__last.__seg_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> __clz_r; + *--__result.__seg_ &= __m; + *__result.__seg_ |= __b << __result.__ctz_; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) << (__bits_per_word - __n); + __storage_type __b = *--__last.__seg_ & __m; + __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __dn = _CUDA_VSTD::min(__n, static_cast(__result.__ctz_)); + __m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_); + __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + // __result.__ctz_ == 0 + --__result.__seg_; + __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); + __m = ~__storage_type(0) << __result.__ctz_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn)); + } + } + } + return __result; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +copy_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + if (__last.__ctz_ == __result.__ctz_) + return __copy_backward_aligned(__first, __last, __result); + return __copy_backward_unaligned(__first, __last, __result); +} + +// move + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +move(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + return _CUDA_VSTD::copy(__first, __last, __result); +} + +// move_backward + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +move_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + return _CUDA_VSTD::copy_backward(__first, __last, __result); +} + +// swap_ranges + +template +__bit_iterator<__C2, false> +__swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, + __bit_iterator<__C2, false> __result) +{ + typedef __bit_iterator<__C1, false> _I1; + typedef typename _I1::difference_type difference_type; + typedef typename _I1::__storage_type __storage_type; + const int __bits_per_word = _I1::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1; + *__first.__seg_ |= __b2; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_) + swap(*__first.__seg_, *__result.__seg_); + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1; + *__first.__seg_ |= __b2; + __result.__ctz_ = static_cast(__n); + } + } + return __result; +} + +template +__bit_iterator<__C2, false> +__swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, + __bit_iterator<__C2, false> __result) +{ + typedef __bit_iterator<__C1, false> _I1; + typedef typename _I1::difference_type difference_type; + typedef typename _I1::__storage_type __storage_type; + const int __bits_per_word = _I1::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _CUDA_VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __first.__ctz_) + { + unsigned __s = __result.__ctz_ - __first.__ctz_; + *__result.__seg_ |= __b1 << __s; + *__first.__seg_ |= __b2 >> __s; + } + else + { + unsigned __s = __first.__ctz_ - __result.__ctz_; + *__result.__seg_ |= __b1 >> __s; + *__first.__seg_ |= __b2 << __s; + } + __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + unsigned __s = __first.__ctz_ + __ddn; + *__result.__seg_ |= __b1 >> __s; + *__first.__seg_ |= __b2 << __s; + __result.__ctz_ = static_cast(__dn); + } + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + __storage_type __m = ~__storage_type(0) << __result.__ctz_; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) + { + __storage_type __b1 = *__first.__seg_; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 << __result.__ctz_; + *__first.__seg_ = __b2 >> __result.__ctz_; + ++__result.__seg_; + __b2 = *__result.__seg_ & ~__m; + *__result.__seg_ &= __m; + *__result.__seg_ |= __b1 >> __clz_r; + *__first.__seg_ |= __b2 << __clz_r; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __dn = _CUDA_VSTD::min<__storage_type>(__n, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 << __result.__ctz_; + *__first.__seg_ |= __b2 >> __result.__ctz_; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 >> __dn; + *__first.__seg_ |= __b2 << __dn; + __result.__ctz_ = static_cast(__n); + } + } + } + return __result; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<__C2, false> +swap_ranges(__bit_iterator<__C1, false> __first1, __bit_iterator<__C1, false> __last1, + __bit_iterator<__C2, false> __first2) +{ + if (__first1.__ctz_ == __first2.__ctz_) + return __swap_ranges_aligned(__first1, __last1, __first2); + return __swap_ranges_unaligned(__first1, __last1, __first2); +} + +// rotate + +template +struct __bit_array +{ + typedef typename _Cp::difference_type difference_type; + typedef typename _Cp::__storage_type __storage_type; + typedef typename _Cp::__storage_pointer __storage_pointer; + typedef typename _Cp::iterator iterator; + static const unsigned __bits_per_word = _Cp::__bits_per_word; + static const unsigned _Np = 4; + + difference_type __size_; + __storage_type __word_[_Np]; + + _LIBCUDACXX_INLINE_VISIBILITY static difference_type capacity() + {return static_cast(_Np * __bits_per_word);} + _LIBCUDACXX_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {} + _LIBCUDACXX_INLINE_VISIBILITY iterator begin() + { + return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0); + } + _LIBCUDACXX_INLINE_VISIBILITY iterator end() + { + return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word, + static_cast(__size_ % __bits_per_word)); + } +}; + +template +__bit_iterator<_Cp, false> +rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last) +{ + typedef __bit_iterator<_Cp, false> _I1; + typedef typename _I1::difference_type difference_type; + difference_type __d1 = __middle - __first; + difference_type __d2 = __last - __middle; + _I1 __r = __first + __d2; + while (__d1 != 0 && __d2 != 0) + { + if (__d1 <= __d2) + { + if (__d1 <= __bit_array<_Cp>::capacity()) + { + __bit_array<_Cp> __b(__d1); + _CUDA_VSTD::copy(__first, __middle, __b.begin()); + _CUDA_VSTD::copy(__b.begin(), __b.end(), _CUDA_VSTD::copy(__middle, __last, __first)); + break; + } + else + { + __bit_iterator<_Cp, false> __mp = _CUDA_VSTD::swap_ranges(__first, __middle, __middle); + __first = __middle; + __middle = __mp; + __d2 -= __d1; + } + } + else + { + if (__d2 <= __bit_array<_Cp>::capacity()) + { + __bit_array<_Cp> __b(__d2); + _CUDA_VSTD::copy(__middle, __last, __b.begin()); + _CUDA_VSTD::copy_backward(__b.begin(), __b.end(), _CUDA_VSTD::copy_backward(__first, __middle, __last)); + break; + } + else + { + __bit_iterator<_Cp, false> __mp = __first + __d2; + _CUDA_VSTD::swap_ranges(__first, __mp, __middle); + __first = __mp; + __d1 -= __d2; + } + } + } + return __r; +} + +// equal + +template +bool +__equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, + __bit_iterator<_Cp, _IC2> __first2) +{ + typedef __bit_iterator<_Cp, _IC1> _It; + typedef typename _It::difference_type difference_type; + typedef typename _It::__storage_type __storage_type; + static const int __bits_per_word = _It::__bits_per_word; + difference_type __n = __last1 - __first1; + if (__n > 0) + { + // do first word + if (__first1.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first1.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first1.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __first2.__ctz_; + __storage_type __ddn = _CUDA_VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + if (__first2.__ctz_ > __first1.__ctz_) + { + if ((*__first2.__seg_ & __m) != (__b << (__first2.__ctz_ - __first1.__ctz_))) + return false; + } + else + { + if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ - __first2.__ctz_))) + return false; + } + __first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word; + __first2.__ctz_ = static_cast((__ddn + __first2.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ + __ddn))) + return false; + __first2.__ctz_ = static_cast(__dn); + } + ++__first1.__seg_; + // __first1.__ctz_ = 0; + } + // __first1.__ctz_ == 0; + // do middle words + unsigned __clz_r = __bits_per_word - __first2.__ctz_; + __storage_type __m = ~__storage_type(0) << __first2.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_) + { + __storage_type __b = *__first1.__seg_; + if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) + return false; + ++__first2.__seg_; + if ((*__first2.__seg_ & ~__m) != (__b >> __clz_r)) + return false; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first1.__seg_ & __m; + __storage_type __dn = _CUDA_VSTD::min(__n, static_cast(__clz_r)); + __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) + return false; + __first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word; + __first2.__ctz_ = static_cast((__dn + __first2.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + if ((*__first2.__seg_ & __m) != (__b >> __dn)) + return false; + } + } + } + return true; +} + +template +bool +__equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, + __bit_iterator<_Cp, _IC2> __first2) +{ + typedef __bit_iterator<_Cp, _IC1> _It; + typedef typename _It::difference_type difference_type; + typedef typename _It::__storage_type __storage_type; + static const int __bits_per_word = _It::__bits_per_word; + difference_type __n = __last1 - __first1; + if (__n > 0) + { + // do first word + if (__first1.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first1.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) + return false; + ++__first2.__seg_; + ++__first1.__seg_; + // __first1.__ctz_ = 0; + // __first2.__ctz_ = 0; + } + // __first1.__ctz_ == 0; + // __first2.__ctz_ == 0; + // do middle words + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_) + if (*__first2.__seg_ != *__first1.__seg_) + return false; + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) + return false; + } + } + return true; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) +{ + if (__first1.__ctz_ == __first2.__ctz_) + return __equal_aligned(__first1, __last1, __first2); + return __equal_unaligned(__first1, __last1, __first2); +} + +template +class __bit_iterator +{ +public: + typedef typename _Cp::difference_type difference_type; + typedef bool value_type; + typedef __bit_iterator pointer; + typedef typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >::type reference; + typedef random_access_iterator_tag iterator_category; + +private: + typedef typename _Cp::__storage_type __storage_type; + typedef typename conditional<_IsConst, typename _Cp::__const_storage_pointer, + typename _Cp::__storage_pointer>::type __storage_pointer; + static const unsigned __bits_per_word = _Cp::__bits_per_word; + + __storage_pointer __seg_; + unsigned __ctz_; + +public: + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator() _NOEXCEPT +#if _LIBCUDACXX_STD_VER > 11 + : __seg_(nullptr), __ctz_(0) +#endif + {} + // avoid re-declaring a copy constructor for the non-const version. + using __type_for_copy_to_const = + _If<_IsConst, __bit_iterator<_Cp, false>, struct __private_nat>; + + _LIBCUDACXX_INLINE_VISIBILITY + __bit_iterator(const __type_for_copy_to_const& __it) _NOEXCEPT + : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {} + + _LIBCUDACXX_INLINE_VISIBILITY reference operator*() const _NOEXCEPT + {return reference(__seg_, __storage_type(1) << __ctz_);} + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator& operator++() + { + if (__ctz_ != __bits_per_word-1) + ++__ctz_; + else + { + __ctz_ = 0; + ++__seg_; + } + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator operator++(int) + { + __bit_iterator __tmp = *this; + ++(*this); + return __tmp; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator& operator--() + { + if (__ctz_ != 0) + --__ctz_; + else + { + __ctz_ = __bits_per_word - 1; + --__seg_; + } + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator operator--(int) + { + __bit_iterator __tmp = *this; + --(*this); + return __tmp; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator& operator+=(difference_type __n) + { + if (__n >= 0) + __seg_ += (__n + __ctz_) / __bits_per_word; + else + __seg_ += static_cast(__n - __bits_per_word + __ctz_ + 1) + / static_cast(__bits_per_word); + __n &= (__bits_per_word - 1); + __ctz_ = static_cast((__n + __ctz_) % __bits_per_word); + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator& operator-=(difference_type __n) + { + return *this += -__n; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator operator+(difference_type __n) const + { + __bit_iterator __t(*this); + __t += __n; + return __t; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator operator-(difference_type __n) const + { + __bit_iterator __t(*this); + __t -= __n; + return __t; + } + + _LIBCUDACXX_INLINE_VISIBILITY + friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) {return __it + __n;} + + _LIBCUDACXX_INLINE_VISIBILITY + friend difference_type operator-(const __bit_iterator& __x, const __bit_iterator& __y) + {return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_;} + + _LIBCUDACXX_INLINE_VISIBILITY reference operator[](difference_type __n) const {return *(*this + __n);} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y) + {return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_;} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__x == __y);} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y) + {return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_);} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y) + {return __y < __x;} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__y < __x);} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__x < __y);} + +private: + _LIBCUDACXX_INLINE_VISIBILITY + __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT + : __seg_(__s), __ctz_(__ctz) {} + + friend typename _Cp::__self; + + friend class __bit_reference<_Cp>; + friend class __bit_const_reference<_Cp>; + friend class __bit_iterator<_Cp, true>; + template friend struct __bit_array; + template friend void __fill_n_false(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); + template friend void __fill_n_true(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); + template friend __bit_iterator<_Dp, false> __copy_aligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<_Dp, false> __copy_unaligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<_Dp, false> copy(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<_Dp, false> __copy_backward_aligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<_Dp, false> __copy_backward_unaligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<_Dp, false> copy_backward(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template friend __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template friend __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>, + __bit_iterator<_Dp, false>, + __bit_iterator<_Dp, false>); + template friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC2>); + template friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC2>); + template friend bool equal(__bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC2>); + template friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>, + typename _Dp::size_type); + template friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>, + typename _Dp::size_type); + template friend typename __bit_iterator<_Dp, _IC>::difference_type + __count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); + template friend typename __bit_iterator<_Dp, _IC>::difference_type + __count_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +_LIBCUDACXX_POP_MACROS + +#endif // _LIBCUDACXX___BIT_REFERENCE diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__bsd_locale_defaults.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__bsd_locale_defaults.h new file mode 100644 index 0000000000000000000000000000000000000000..609865abd163d9fd05cc4e467110fabd2c77f6c4 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__bsd_locale_defaults.h @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===---------------------- __bsd_locale_defaults.h -----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// The BSDs have lots of *_l functions. We don't want to define those symbols +// on other platforms though, for fear of conflicts with user code. So here, +// we will define the mapping from an internal macro to the real BSD symbol. +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_BSD_LOCALE_DEFAULTS_H +#define _LIBCUDACXX_BSD_LOCALE_DEFAULTS_H + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#define __libcpp_mb_cur_max_l(loc) MB_CUR_MAX_L(loc) +#define __libcpp_btowc_l(ch, loc) btowc_l(ch, loc) +#define __libcpp_wctob_l(wch, loc) wctob_l(wch, loc) +#define __libcpp_wcsnrtombs_l(dst, src, nwc, len, ps, loc) wcsnrtombs_l(dst, src, nwc, len, ps, loc) +#define __libcpp_wcrtomb_l(src, wc, ps, loc) wcrtomb_l(src, wc, ps, loc) +#define __libcpp_mbsnrtowcs_l(dst, src, nms, len, ps, loc) mbsnrtowcs_l(dst, src, nms, len, ps, loc) +#define __libcpp_mbrtowc_l(pwc, s, n, ps, l) mbrtowc_l(pwc, s, n, ps, l) +#define __libcpp_mbtowc_l(pwc, pmb, max, l) mbtowc_l(pwc, pmb, max, l) +#define __libcpp_mbrlen_l(s, n, ps, l) mbrlen_l(s, n, ps, l) +#define __libcpp_localeconv_l(l) localeconv_l(l) +#define __libcpp_mbsrtowcs_l(dest, src, len, ps, l) mbsrtowcs_l(dest, src, len, ps, l) +#define __libcpp_snprintf_l(...) snprintf_l(__VA_ARGS__) +#define __libcpp_asprintf_l(...) asprintf_l(__VA_ARGS__) +#define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__) + +#endif // _LIBCUDACXX_BSD_LOCALE_DEFAULTS_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__bsd_locale_fallbacks.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__bsd_locale_fallbacks.h new file mode 100644 index 0000000000000000000000000000000000000000..58220977d76db105a50fc4f294fd94eca9a92371 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__bsd_locale_fallbacks.h @@ -0,0 +1,139 @@ +// -*- C++ -*- +//===---------------------- __bsd_locale_fallbacks.h ----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// The BSDs have lots of *_l functions. This file provides reimplementations +// of those functions for non-BSD platforms. +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_BSD_LOCALE_FALLBACKS_DEFAULTS_H +#define _LIBCUDACXX_BSD_LOCALE_FALLBACKS_DEFAULTS_H + +#include +#include +#include + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +inline _LIBCUDACXX_INLINE_VISIBILITY +decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return MB_CUR_MAX; +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +wint_t __libcpp_btowc_l(int __c, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return btowc(__c); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +int __libcpp_wctob_l(wint_t __c, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return wctob(__c); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc, + size_t __len, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return wcsnrtombs(__dest, __src, __nwc, __len, __ps); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return wcrtomb(__s, __wc, __ps); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms, + size_t __len, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbsnrtowcs(__dest, __src, __nms, __len, __ps); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n, + mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbrtowc(__pwc, __s, __n, __ps); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +int __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbtowc(__pwc, __pmb, __max); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbrlen(__s, __n, __ps); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +lconv *__libcpp_localeconv_l(locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return localeconv(); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len, + mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbsrtowcs(__dest, __src, __len, __ps); +} + +inline +int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); + __libcpp_locale_guard __current(__l); + int __res = vsnprintf(__s, __n, __format, __va); + va_end(__va); + return __res; +} + +inline +int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); + __libcpp_locale_guard __current(__l); + int __res = vasprintf(__s, __format, __va); + va_end(__va); + return __res; +} + +inline +int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); + __libcpp_locale_guard __current(__l); + int __res = vsscanf(__s, __format, __va); + va_end(__va); + return __res; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_BSD_LOCALE_FALLBACKS_DEFAULTS_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/_One_of.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/_One_of.h new file mode 100644 index 0000000000000000000000000000000000000000..3b9f9976017f2fbd48b964b6662cb14e5a5c6908 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/_One_of.h @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_ONE_OF_H +#define _LIBCUDACXX___CONCEPTS_ONE_OF_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__type_traits/disjunction.h" +#include "../__type_traits/is_same.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 +template +_LIBCUDACXX_CONCEPT _One_of = (is_same_v<_Ty, _Others> || ...); +#elif _LIBCUDACXX_STD_VER > 11 +template +_LIBCUDACXX_CONCEPT _One_of = _LIBCUDACXX_TRAIT(disjunction, is_same<_Ty, _Others>...); +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_ONE_OF_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/__concept_macros.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/__concept_macros.h new file mode 100644 index 0000000000000000000000000000000000000000..0486b53c840064adb95c76294ee0b87cb1bd32a2 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/__concept_macros.h @@ -0,0 +1,299 @@ +//===----------------------------------------------------------------------===// +// +// Copyright (c) Facebook, Inc. and its affiliates. +// Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA___CONCEPTS +#define _CUDA___CONCEPTS + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#if _LIBCUDACXX_STD_VER > 11 + +#define _LIBCUDACXX_PP_CAT_(_Xp, ...) _Xp##__VA_ARGS__ +#define _LIBCUDACXX_PP_CAT(_Xp, ...) _LIBCUDACXX_PP_CAT_(_Xp, __VA_ARGS__) + +#define _LIBCUDACXX_PP_CAT2_(_Xp, ...) _Xp##__VA_ARGS__ +#define _LIBCUDACXX_PP_CAT2(_Xp, ...) _LIBCUDACXX_PP_CAT2_(_Xp, __VA_ARGS__) + +#define _LIBCUDACXX_PP_CAT3_(_Xp, ...) _Xp##__VA_ARGS__ +#define _LIBCUDACXX_PP_CAT3(_Xp, ...) _LIBCUDACXX_PP_CAT3_(_Xp, __VA_ARGS__) + +#define _LIBCUDACXX_PP_CAT4_(_Xp, ...) _Xp##__VA_ARGS__ +#define _LIBCUDACXX_PP_CAT4(_Xp, ...) _LIBCUDACXX_PP_CAT4_(_Xp, __VA_ARGS__) + +#define _LIBCUDACXX_PP_EVAL_(_Xp, _ARGS) _Xp _ARGS +#define _LIBCUDACXX_PP_EVAL(_Xp, ...) _LIBCUDACXX_PP_EVAL_(_Xp, (__VA_ARGS__)) + +#define _LIBCUDACXX_PP_EVAL2_(_Xp, _ARGS) _Xp _ARGS +#define _LIBCUDACXX_PP_EVAL2(_Xp, ...) _LIBCUDACXX_PP_EVAL2_(_Xp, (__VA_ARGS__)) + +#define _LIBCUDACXX_PP_EXPAND(...) __VA_ARGS__ +#define _LIBCUDACXX_PP_EAT(...) + +#define _LIBCUDACXX_PP_CHECK(...) \ + _LIBCUDACXX_PP_EXPAND(_LIBCUDACXX_PP_CHECK_N(__VA_ARGS__, 0, )) +#define _LIBCUDACXX_PP_CHECK_N(_Xp, _Num, ...) _Num +#define _LIBCUDACXX_PP_PROBE(_Xp) _Xp, 1, +#define _LIBCUDACXX_PP_PROBE_N(_Xp, _Num) _Xp, _Num, + +#define _LIBCUDACXX_PP_IS_PAREN(_Xp) \ + _LIBCUDACXX_PP_CHECK(_LIBCUDACXX_PP_IS_PAREN_PROBE _Xp) +#define _LIBCUDACXX_PP_IS_PAREN_PROBE(...) _LIBCUDACXX_PP_PROBE(~) + +// The final _LIBCUDACXX_PP_EXPAND here is to avoid +// https://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly +#define _LIBCUDACXX_PP_COUNT(...) \ + _LIBCUDACXX_PP_EXPAND(_LIBCUDACXX_PP_COUNT_( \ + __VA_ARGS__, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, \ + 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, \ + 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, )) \ + /**/ +#define _LIBCUDACXX_PP_COUNT_( \ + _01, _02, _03, _04, _05, _06, _07, _08, _09, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \ + _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, \ + _46, _47, _48, _49, _50, _Np, ...) \ + _Np /**/ + +#define _LIBCUDACXX_PP_IIF(_BIT) _LIBCUDACXX_PP_CAT_(_LIBCUDACXX_PP_IIF_, _BIT) +#define _LIBCUDACXX_PP_IIF_0(_TRUE, ...) __VA_ARGS__ +#define _LIBCUDACXX_PP_IIF_1(_TRUE, ...) _TRUE + +#define _LIBCUDACXX_PP_LPAREN ( + +#define _LIBCUDACXX_PP_NOT(_BIT) _LIBCUDACXX_PP_CAT_(_LIBCUDACXX_PP_NOT_, _BIT) +#define _LIBCUDACXX_PP_NOT_0 1 +#define _LIBCUDACXX_PP_NOT_1 0 + +#define _LIBCUDACXX_PP_EMPTY() +#define _LIBCUDACXX_PP_COMMA() , +#define _LIBCUDACXX_PP_LBRACE() { +#define _LIBCUDACXX_PP_RBRACE() } +#define _LIBCUDACXX_PP_COMMA_IIF(_Xp) \ + _LIBCUDACXX_PP_IIF(_Xp)(_LIBCUDACXX_PP_EMPTY, _LIBCUDACXX_PP_COMMA)() /**/ + +#define _LIBCUDACXX_PP_FOR_EACH(_Mp, ...) \ + _LIBCUDACXX_PP_FOR_EACH_N(_LIBCUDACXX_PP_COUNT(__VA_ARGS__), _Mp, __VA_ARGS__) +#define _LIBCUDACXX_PP_FOR_EACH_N(_Np, _Mp, ...) \ + _LIBCUDACXX_PP_CAT2(_LIBCUDACXX_PP_FOR_EACH_, _Np)(_Mp, __VA_ARGS__) +#define _LIBCUDACXX_PP_FOR_EACH_1(_Mp, _1) _Mp(_1) +#define _LIBCUDACXX_PP_FOR_EACH_2(_Mp, _1, _2) _Mp(_1) _Mp(_2) +#define _LIBCUDACXX_PP_FOR_EACH_3(_Mp, _1, _2, _3) _Mp(_1) _Mp(_2) _Mp(_3) +#define _LIBCUDACXX_PP_FOR_EACH_4(_Mp, _1, _2, _3, _4) \ + _Mp(_1) _Mp(_2) _Mp(_3) _Mp(_4) +#define _LIBCUDACXX_PP_FOR_EACH_5(_Mp, _1, _2, _3, _4, _5) \ + _Mp(_1) _Mp(_2) _Mp(_3) _Mp(_4) _Mp(_5) +#define _LIBCUDACXX_PP_FOR_EACH_6(_Mp, _1, _2, _3, _4, _5, _6) \ + _Mp(_1) _Mp(_2) _Mp(_3) _Mp(_4) _Mp(_5) _Mp(_6) +#define _LIBCUDACXX_PP_FOR_EACH_7(_Mp, _1, _2, _3, _4, _5, _6, _7) \ + _Mp(_1) _Mp(_2) _Mp(_3) _Mp(_4) _Mp(_5) _Mp(_6) _Mp(_7) +#define _LIBCUDACXX_PP_FOR_EACH_8(_Mp, _1, _2, _3, _4, _5, _6, _7, _8) \ + _Mp(_1) _Mp(_2) _Mp(_3) _Mp(_4) _Mp(_5) _Mp(_6) _Mp(_7) _Mp(_8) + +#define _LIBCUDACXX_PP_PROBE_EMPTY_PROBE__LIBCUDACXX_PP_PROBE_EMPTY \ + _LIBCUDACXX_PP_PROBE(~) + +#define _LIBCUDACXX_PP_PROBE_EMPTY() +#define _LIBCUDACXX_PP_IS_NOT_EMPTY(...) \ + _LIBCUDACXX_PP_EVAL( \ + _LIBCUDACXX_PP_CHECK, \ + _LIBCUDACXX_PP_CAT(_LIBCUDACXX_PP_PROBE_EMPTY_PROBE_, \ + _LIBCUDACXX_PP_PROBE_EMPTY __VA_ARGS__())) \ + /**/ + +#define _LIBCUDACXX_PP_TAIL(_, ...) __VA_ARGS__ + +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M0(_REQ) \ + _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_(_REQ)(_REQ) +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M1(_REQ) _LIBCUDACXX_PP_EXPAND _REQ +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_(...) \ + { _LIBCUDACXX_PP_FOR_EACH(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__) } +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_(_REQ) \ + _LIBCUDACXX_PP_CAT3( \ + _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_, \ + _LIBCUDACXX_PP_EVAL( \ + _LIBCUDACXX_PP_CHECK, \ + _LIBCUDACXX_PP_CAT3(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_, \ + _REQ))) \ + /**/ +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_requires \ + _LIBCUDACXX_PP_PROBE_N(~, 1) +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_noexcept \ + _LIBCUDACXX_PP_PROBE_N(~, 2) +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_typename \ + _LIBCUDACXX_PP_PROBE_N(~, 3) + +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_0 _LIBCUDACXX_PP_EXPAND +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_1 \ + _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_OR_NOEXCEPT +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_2 \ + _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_OR_NOEXCEPT +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_3 \ + _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_OR_NOEXCEPT +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_OR_NOEXCEPT(_REQ) \ + _LIBCUDACXX_PP_CAT4(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_, _REQ) +#define _LIBCUDACXX_PP_EAT_TYPENAME_PROBE_typename _LIBCUDACXX_PP_PROBE(~) +#define _LIBCUDACXX_PP_EAT_TYPENAME_SELECT_(_Xp, ...) \ + _LIBCUDACXX_PP_CAT3( \ + _LIBCUDACXX_PP_EAT_TYPENAME_SELECT_, \ + _LIBCUDACXX_PP_EVAL( \ + _LIBCUDACXX_PP_CHECK, \ + _LIBCUDACXX_PP_CAT3(_LIBCUDACXX_PP_EAT_TYPENAME_PROBE_, _Xp))) +#define _LIBCUDACXX_PP_EAT_TYPENAME_(...) \ + _LIBCUDACXX_PP_EVAL2(_LIBCUDACXX_PP_EAT_TYPENAME_SELECT_, __VA_ARGS__, ) \ + (__VA_ARGS__) +#define _LIBCUDACXX_PP_EAT_TYPENAME_SELECT_0(...) __VA_ARGS__ +#define _LIBCUDACXX_PP_EAT_TYPENAME_SELECT_1(...) \ + _LIBCUDACXX_PP_CAT3(_LIBCUDACXX_PP_EAT_TYPENAME_, __VA_ARGS__) +#define _LIBCUDACXX_PP_EAT_TYPENAME_typename + +#if (defined(__cpp_concepts) && _LIBCUDACXX_STD_VER >= 20) || \ + defined(_LIBCUDACXX_DOXYGEN_INVOKED) + +#define _LIBCUDACXX_CONCEPT concept + +#define _LIBCUDACXX_CONCEPT_FRAGMENT(_NAME, ...) \ + concept _NAME = \ + _LIBCUDACXX_PP_CAT(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_, __VA_ARGS__) +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_requires(...) \ + requires(__VA_ARGS__) _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_ +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M(_REQ) \ + _LIBCUDACXX_PP_CAT2(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M, \ + _LIBCUDACXX_PP_IS_PAREN(_REQ)) \ + (_REQ); +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_requires(...) \ + requires __VA_ARGS__ +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_typename(...) \ + typename _LIBCUDACXX_PP_EAT_TYPENAME_(__VA_ARGS__) +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_noexcept(...) \ + { __VA_ARGS__ } \ + noexcept + +#define _LIBCUDACXX_FRAGMENT(_NAME, ...) _NAME<__VA_ARGS__> + +#else + +#define _LIBCUDACXX_CONCEPT _LIBCUDACXX_INLINE_VAR constexpr bool + +#define _LIBCUDACXX_CONCEPT_FRAGMENT(_NAME, ...) \ + _LIBCUDACXX_INLINE_VISIBILITY auto _NAME##_LIBCUDACXX_CONCEPT_FRAGMENT_impl_ \ + _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_##__VA_ARGS__ > {} \ + template \ + _LIBCUDACXX_INLINE_VISIBILITY char _NAME##_LIBCUDACXX_CONCEPT_FRAGMENT_( \ + _Concept::_Tag<_As...> *, \ + decltype(&_NAME##_LIBCUDACXX_CONCEPT_FRAGMENT_impl_<_As...>)); \ + _LIBCUDACXX_INLINE_VISIBILITY char( \ + &_NAME##_LIBCUDACXX_CONCEPT_FRAGMENT_(...))[2] /**/ +#if defined(_MSC_VER) && !defined(__clang__) +#define _LIBCUDACXX_CONCEPT_FRAGMENT_TRUE(...) \ + _Concept::_Is_true() +#else +#define _LIBCUDACXX_CONCEPT_FRAGMENT_TRUE(...) \ + !(decltype(_LIBCUDACXX_PP_FOR_EACH(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M, \ + __VA_ARGS__) void(), \ + false){}) +#endif +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_requires(...) \ + (__VA_ARGS__)->_Concept::_Enable_if_t < _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_2_ +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_2_(...) \ + _LIBCUDACXX_CONCEPT_FRAGMENT_TRUE(__VA_ARGS__) +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M(_REQ) \ + _LIBCUDACXX_PP_CAT2(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M, \ + _LIBCUDACXX_PP_IS_PAREN(_REQ)) \ + (_REQ), +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_requires(...) \ + _Concept::_Requires<__VA_ARGS__> +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_typename(...) \ + static_cast<_Concept::_Tag<__VA_ARGS__> *>(nullptr) +#if defined(_LIBCUDACXX_COMPILER_GCC) +// GCC can't mangle noexcept expressions, so just check that the +// expression is well-formed. +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70790 +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_noexcept(...) __VA_ARGS__ +#else +#define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_noexcept(...) \ + _Concept::_Requires +#endif + +#define _LIBCUDACXX_FRAGMENT(_NAME, ...) \ + (1u == sizeof(_NAME##_LIBCUDACXX_CONCEPT_FRAGMENT_( \ + static_cast<_Concept::_Tag<__VA_ARGS__> *>(nullptr), nullptr))) + +#endif + +//////////////////////////////////////////////////////////////////////////////// +// _LIBCUDACXX_TEMPLATE +// Usage: +// _LIBCUDACXX_TEMPLATE(typename A, typename _Bp) +// (requires Concept1 _LIBCUDACXX_AND Concept2<_Bp>) +// void foo(A a, _Bp b) +// {} +#if (defined(__cpp_concepts) && _LIBCUDACXX_STD_VER >= 20) +#define _LIBCUDACXX_TEMPLATE(...) \ + template <__VA_ARGS__> _LIBCUDACXX_PP_EXPAND /**/ +#define _LIBCUDACXX_AND && /**/ +#define _LIBCUDACXX_TRAILING_REQUIRES(...) \ + -> __VA_ARGS__ _LIBCUDACXX_PP_EXPAND +#else +#define _LIBCUDACXX_TEMPLATE(...) \ + template <__VA_ARGS__ _LIBCUDACXX_TEMPLATE_SFINAE_AUX_ /**/ +#define _LIBCUDACXX_AND \ + &&_LIBCUDACXX_true_, int > = 0, _Concept::_Enable_if_t < /**/ +#define _LIBCUDACXX_TRAILING_REQUIRES(...) \ + -> _Concept::_Requires_t<__VA_ARGS__ _LIBCUDACXX_TRAILING_REQUIRES_AUX_ +#endif + +#define _LIBCUDACXX_TEMPLATE_SFINAE(...) \ + template <__VA_ARGS__ _LIBCUDACXX_TEMPLATE_SFINAE_AUX_ /**/ +#define _LIBCUDACXX_TEMPLATE_SFINAE_AUX_(...) \ + , bool _LIBCUDACXX_true_ = true, \ + _Concept::_Enable_if_t < \ + _LIBCUDACXX_PP_CAT(_LIBCUDACXX_TEMPLATE_SFINAE_AUX_3_, \ + __VA_ARGS__) && \ + _LIBCUDACXX_true_, \ + int > = 0 > /**/ +#define _LIBCUDACXX_TRAILING_REQUIRES_AUX_(...) \ + , _LIBCUDACXX_PP_CAT(_LIBCUDACXX_TEMPLATE_SFINAE_AUX_3_, __VA_ARGS__)> /**/ +#define _LIBCUDACXX_TEMPLATE_SFINAE_AUX_3_requires + +namespace _Concept { +template struct _Select {}; + +template <> struct _Select { template using type = _Tp; }; + +template +using _Enable_if_t = typename _Select<_Bp>::template type<_Tp>; + +template +using _Requires_t = typename _Select<_Bp>::template type<_Tp>; + +template struct _Tag; +template +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool _Is_true() { + return true; +} + +#if defined(_LIBCUDACXX_COMPILER_CLANG) || defined(_LIBCUDACXX_COMPILER_MSVC) +template +_LIBCUDACXX_INLINE_VISIBILITY _Concept::_Enable_if_t<_Bp> _Requires() {} +#else +template = 0> +_LIBCUDACXX_INLINE_VAR constexpr int _Requires = 0; +#endif +} // namespace _Concept + +#endif // _LIBCUDACXX_STD_VER > 11 + +#endif //_CUDA___CONCEPTS diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/arithmetic.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/arithmetic.h new file mode 100644 index 0000000000000000000000000000000000000000..eb0030bdf1289cdc2fe13fd993ed1d278c3be3d7 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/arithmetic.h @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_ARITHMETIC_H +#define _LIBCUDACXX___CONCEPTS_ARITHMETIC_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__type_traits/is_arithmetic.h" +#include "../__type_traits/is_floating_point.h" +#include "../__type_traits/is_integral.h" +#include "../__type_traits/is_signed_integer.h" +#include "../__type_traits/is_signed.h" +#include "../__type_traits/is_unsigned_integer.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +// [concepts.arithmetic], arithmetic concepts + +template +_LIBCUDACXX_CONCEPT integral = _LIBCUDACXX_TRAIT(is_integral, _Tp); + +template +_LIBCUDACXX_CONCEPT signed_integral = integral<_Tp> && _LIBCUDACXX_TRAIT(is_signed, _Tp); + +template +_LIBCUDACXX_CONCEPT unsigned_integral = integral<_Tp> && !signed_integral<_Tp>; + +template +_LIBCUDACXX_CONCEPT floating_point = _LIBCUDACXX_TRAIT(is_floating_point, _Tp); + +// Concept helpers for the internal type traits for the fundamental types. +template +_LIBCUDACXX_CONCEPT __libcpp_unsigned_integer = __libcpp_is_unsigned_integer<_Tp>::value; +template +_LIBCUDACXX_CONCEPT __libcpp_signed_integer = __libcpp_is_signed_integer<_Tp>::value; + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_ARITHMETIC_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/assignable.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/assignable.h new file mode 100644 index 0000000000000000000000000000000000000000..b942a2bb0efda38e7391cb783f554ce199786e62 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/assignable.h @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_ASSIGNABLE_H +#define _LIBCUDACXX___CONCEPTS_ASSIGNABLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/common_reference_with.h" +#include "../__concepts/same_as.h" +#include "../__type_traits/is_reference.h" +#include "../__type_traits/make_const_lvalue_ref.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.assignable] + +template +concept assignable_from = + is_lvalue_reference_v<_Lhs> && + common_reference_with<__make_const_lvalue_ref<_Lhs>, __make_const_lvalue_ref<_Rhs>> && + requires (_Lhs __lhs, _Rhs&& __rhs) { + { __lhs = _CUDA_VSTD::forward<_Rhs>(__rhs) } -> same_as<_Lhs>; + }; + +#elif _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __assignable_from_, + requires(_Lhs __lhs, _Rhs&& __rhs)( + requires(_LIBCUDACXX_TRAIT(is_lvalue_reference, _Lhs)), + requires(common_reference_with<__make_const_lvalue_ref<_Lhs>, __make_const_lvalue_ref<_Rhs>>), + requires(same_as<_Lhs, decltype(__lhs = _CUDA_VSTD::forward<_Rhs>(__rhs))>) + )); + +template +_LIBCUDACXX_CONCEPT assignable_from = _LIBCUDACXX_FRAGMENT(__assignable_from_, _Lhs, _Rhs); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_ASSIGNABLE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/boolean_testable.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/boolean_testable.h new file mode 100644 index 0000000000000000000000000000000000000000..d1fa4ec7861e269400b00b051b208b0d59fd3a6e --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/boolean_testable.h @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_BOOLEAN_TESTABLE_H +#define _LIBCUDACXX___CONCEPTS_BOOLEAN_TESTABLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/convertible_to.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concepts.booleantestable] + +template +concept __boolean_testable_impl = convertible_to<_Tp, bool>; + +template +concept __boolean_testable = __boolean_testable_impl<_Tp> && requires(_Tp&& __t) { + { !_CUDA_VSTD::forward<_Tp>(__t) } -> __boolean_testable_impl; +}; + +#elif _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT __boolean_testable_impl = convertible_to<_Tp, bool>; + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __boolean_testable_, + requires(_Tp&& __t)( + requires(__boolean_testable_impl<_Tp>), + requires(__boolean_testable_impl(__t))>) + )); + +template +_LIBCUDACXX_CONCEPT __boolean_testable = _LIBCUDACXX_FRAGMENT(__boolean_testable_, _Tp); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_BOOLEAN_TESTABLE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/class_or_enum.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/class_or_enum.h new file mode 100644 index 0000000000000000000000000000000000000000..6e6b2a5cc49d5ff317939bdf464ccef306cab198 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/class_or_enum.h @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_CLASS_OR_ENUM_H +#define _LIBCUDACXX___CONCEPTS_CLASS_OR_ENUM_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__type_traits/is_class.h" +#include "../__type_traits/is_enum.h" +#include "../__type_traits/is_union.h" +#include "../__type_traits/remove_cvref.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT __class_or_enum = _LIBCUDACXX_TRAIT(is_class, _Tp) || _LIBCUDACXX_TRAIT(is_union, _Tp) || _LIBCUDACXX_TRAIT(is_enum, _Tp); + +// Work around Clang bug https://llvm.org/PR52970 +// TODO: remove this workaround once libc++ no longer has to support Clang 13 (it was fixed in Clang 14). +template +_LIBCUDACXX_CONCEPT __workaround_52970 = _LIBCUDACXX_TRAIT(is_class, remove_cvref_t<_Tp>) || _LIBCUDACXX_TRAIT(is_union, remove_cvref_t<_Tp>); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_CLASS_OR_ENUM_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/common_reference_with.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/common_reference_with.h new file mode 100644 index 0000000000000000000000000000000000000000..d0f8ef6d127c32adc86d970fa68ce1f097257b18 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/common_reference_with.h @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_COMMON_REFERENCE_WITH_H +#define _LIBCUDACXX___CONCEPTS_COMMON_REFERENCE_WITH_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/convertible_to.h" +#include "../__concepts/same_as.h" +#include "../__type_traits/common_reference.h" +#include "../__type_traits/copy_cv.h" +#include "../__type_traits/copy_cvref.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.commonref] + +template +concept common_reference_with = + same_as, common_reference_t<_Up, _Tp>> && + convertible_to<_Tp, common_reference_t<_Tp, _Up>> && + convertible_to<_Up, common_reference_t<_Tp, _Up>>; + +#elif _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __common_reference_exists_, + requires()( + typename(common_reference_t<_Tp, _Up>), + typename(common_reference_t<_Up, _Tp>) + )); + +template +_LIBCUDACXX_CONCEPT _Common_reference_exists = _LIBCUDACXX_FRAGMENT(__common_reference_exists_, _Tp, _Up); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __common_reference_with_, + requires()( + requires(_Common_reference_exists<_Tp, _Up>), + requires(same_as, common_reference_t<_Up, _Tp>>), + requires(convertible_to<_Tp, common_reference_t<_Tp, _Up>>), + requires(convertible_to<_Up, common_reference_t<_Tp, _Up>>) + )); + +template +_LIBCUDACXX_CONCEPT common_reference_with = _LIBCUDACXX_FRAGMENT(__common_reference_with_, _Tp, _Up); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_COMMON_REFERENCE_WITH_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/common_with.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/common_with.h new file mode 100644 index 0000000000000000000000000000000000000000..de51e0398dca95f619dcd4849eb52379281fec0b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/common_with.h @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_COMMON_WITH_H +#define _LIBCUDACXX___CONCEPTS_COMMON_WITH_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/common_reference_with.h" +#include "../__concepts/same_as.h" +#include "../__type_traits/add_lvalue_reference.h" +#include "../__type_traits/common_type.h" +#include "../__utility/declval.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.common] + +template +concept common_with = + same_as, common_type_t<_Up, _Tp>> && + requires { + static_cast>(_CUDA_VSTD::declval<_Tp>()); + static_cast>(_CUDA_VSTD::declval<_Up>()); + } && + common_reference_with< + add_lvalue_reference_t, + add_lvalue_reference_t> && + common_reference_with< + add_lvalue_reference_t>, + common_reference_t< + add_lvalue_reference_t, + add_lvalue_reference_t>>; + +#elif _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __common_type_exists_, + requires()( + typename(common_type_t<_Tp, _Up>), + typename(common_type_t<_Up, _Tp>) + )); + +template +_LIBCUDACXX_CONCEPT _Common_type_exists = _LIBCUDACXX_FRAGMENT(__common_type_exists_, _Tp, _Up); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __common_type_constructible_, + requires()( + requires(_Common_type_exists<_Tp, _Up>), + static_cast>(_CUDA_VSTD::declval<_Tp>()), + static_cast>(_CUDA_VSTD::declval<_Up>()) + )); + +template +_LIBCUDACXX_CONCEPT _Common_type_constructible = _LIBCUDACXX_FRAGMENT(__common_type_constructible_, _Tp, _Up); + + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __common_with_, + requires()( + requires(_Common_type_constructible<_Tp, _Up>), + requires(same_as, common_type_t<_Up, _Tp>>), + requires(common_reference_with< + add_lvalue_reference_t, + add_lvalue_reference_t>), + requires(common_reference_with< + add_lvalue_reference_t>, + common_reference_t< + add_lvalue_reference_t, + add_lvalue_reference_t>>))); + +template +_LIBCUDACXX_CONCEPT common_with = _LIBCUDACXX_FRAGMENT(__common_with_, _Tp, _Up); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_COMMON_WITH_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/constructible.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/constructible.h new file mode 100644 index 0000000000000000000000000000000000000000..a0f33cb27d01f7084ba204301c49276548440ff8 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/constructible.h @@ -0,0 +1,121 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_CONSTRUCTIBLE_H +#define _LIBCUDACXX___CONCEPTS_CONSTRUCTIBLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/convertible_to.h" +#include "../__concepts/destructible.h" +#include "../__type_traits/add_lvalue_reference.h" +#include "../__type_traits/is_constructible.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.constructible] +template +concept constructible_from = + destructible<_Tp> && is_constructible_v<_Tp, _Args...>; + +// [concept.default.init] +template +concept __default_initializable = requires { ::new _Tp; }; + +template +concept default_initializable = constructible_from<_Tp> && + requires { _Tp{}; } && __default_initializable<_Tp>; + +// [concept.moveconstructible] +template +concept move_constructible = + constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>; + +// [concept.copyconstructible] +template +concept copy_constructible = + move_constructible<_Tp> && + constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp> && + constructible_from<_Tp, const _Tp&> && convertible_to && + constructible_from<_Tp, const _Tp> && convertible_to; + +#elif _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __constructible_from_, + requires()( + requires(destructible<_Tp>), + requires(_LIBCUDACXX_TRAIT(is_constructible, _Tp, _Args...)) + )); + +template +_LIBCUDACXX_CONCEPT constructible_from = _LIBCUDACXX_FRAGMENT(__constructible_from_, _Tp, _Args...); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __default_initializable_, + requires()( + (::new _Tp) + )); + +template +_LIBCUDACXX_CONCEPT __default_initializable = _LIBCUDACXX_FRAGMENT(__default_initializable_, _Tp); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + _Default_initializable_, + requires(_Tp = _Tp{}) ( + requires(constructible_from<_Tp>), + requires(__default_initializable<_Tp>) + )); + +template +_LIBCUDACXX_CONCEPT default_initializable = _LIBCUDACXX_FRAGMENT(_Default_initializable_, _Tp); + +// [concept.moveconstructible] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __move_constructible_, + requires()( + requires(constructible_from<_Tp, _Tp>), + requires(convertible_to<_Tp, _Tp>) + )); + +template +_LIBCUDACXX_CONCEPT move_constructible = _LIBCUDACXX_FRAGMENT(__move_constructible_, _Tp); + +// [concept.copyconstructible] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __copy_constructible_, + requires()( + requires(move_constructible<_Tp>), + requires(constructible_from<_Tp, add_lvalue_reference_t<_Tp>> && convertible_to, _Tp>), + requires(constructible_from<_Tp, const add_lvalue_reference_t<_Tp>> && convertible_to, _Tp>), + requires(constructible_from<_Tp, const _Tp> && convertible_to) + )); + +template +_LIBCUDACXX_CONCEPT copy_constructible = _LIBCUDACXX_FRAGMENT(__copy_constructible_, _Tp); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_CONSTRUCTIBLE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/convertible_to.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/convertible_to.h new file mode 100644 index 0000000000000000000000000000000000000000..b2a869dcd7c0c30546c14277c82b1c7d47c9e4e3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/convertible_to.h @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_CONVERTIBLE_TO_H +#define _LIBCUDACXX___CONCEPTS_CONVERTIBLE_TO_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__type_traits/is_convertible.h" +#include "../__utility/declval.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.convertible] + +template +concept convertible_to = + is_convertible_v<_From, _To> && + requires { + static_cast<_To>(_CUDA_VSTD::declval<_From>()); + }; + +#elif _LIBCUDACXX_STD_VER > 11 + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +_LIBCUDACXX_NV_DIAG_SUPPRESS(1211) // nonstandard cast to array type ignored +#endif // _LIBCUDACXX_COMPILER_MSVC + +// We cannot put this conversion check with the other constraint, as types with deleted operator will break here +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __test_conversion_, + requires()( + static_cast<_To>(_CUDA_VSTD::declval<_From>()) + )); + +template +_LIBCUDACXX_CONCEPT __test_conversion = _LIBCUDACXX_FRAGMENT(__test_conversion_, _From, _To); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __convertible_to_, + requires()( + requires(_LIBCUDACXX_TRAIT(is_convertible, _From, _To)), + requires(__test_conversion<_From, _To>) + )); + +template +_LIBCUDACXX_CONCEPT convertible_to = _LIBCUDACXX_FRAGMENT(__convertible_to_, _From, _To); + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +_LIBCUDACXX_NV_DIAG_DEFAULT(1211) // nonstandard cast to array type ignored +#endif // _LIBCUDACXX_COMPILER_MSVC + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_CONVERTIBLE_TO_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/copyable.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/copyable.h new file mode 100644 index 0000000000000000000000000000000000000000..cd309f71e84407d2192ff3c0b72a568f1517b386 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/copyable.h @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_COPYABLE_H +#define _LIBCUDACXX___CONCEPTS_COPYABLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/assignable.h" +#include "../__concepts/constructible.h" +#include "../__concepts/movable.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concepts.object] + +template +concept copyable = + copy_constructible<_Tp> && + movable<_Tp> && + assignable_from<_Tp&, _Tp&> && + assignable_from<_Tp&, const _Tp&> && + assignable_from<_Tp&, const _Tp>; + +#elif _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __copyable_, + requires()( + requires(copy_constructible<_Tp>), + requires(movable<_Tp>), + requires(assignable_from<_Tp&, _Tp&>), + requires(assignable_from<_Tp&, const _Tp&>), + requires(assignable_from<_Tp&, const _Tp>) + )); + +template +_LIBCUDACXX_CONCEPT copyable = _LIBCUDACXX_FRAGMENT(__copyable_,_Tp); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_COPYABLE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/derived_from.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/derived_from.h new file mode 100644 index 0000000000000000000000000000000000000000..1e92e5f2f1336a79d559e5a879de5158fff28214 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/derived_from.h @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_DERIVED_FROM_H +#define _LIBCUDACXX___CONCEPTS_DERIVED_FROM_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__type_traits/add_pointer.h" +#include "../__type_traits/is_base_of.h" +#include "../__type_traits/is_convertible.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.derived] + +template +concept derived_from = + is_base_of_v<_Bp, _Dp> && + is_convertible_v; + +#elif _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __derived_from_, + requires()( + requires(_LIBCUDACXX_TRAIT(is_base_of, _Bp, _Dp)), + requires(_LIBCUDACXX_TRAIT(is_convertible, add_pointer_t, add_pointer_t)) + )); + +template +_LIBCUDACXX_CONCEPT derived_from = _LIBCUDACXX_FRAGMENT(__derived_from_, _Dp, _Bp); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_DERIVED_FROM_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/destructible.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/destructible.h new file mode 100644 index 0000000000000000000000000000000000000000..6a0ad1bff4446fa26a4256d124ebc22cad08a662 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/destructible.h @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_DESTRUCTIBLE_H +#define _LIBCUDACXX___CONCEPTS_DESTRUCTIBLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_destructible.h" +#include "../__type_traits/is_object.h" +#include "../__type_traits/is_nothrow_destructible.h" +#include "../__type_traits/void_t.h" +#include "../__utility/declval.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +#if defined(_LIBCUDACXX_COMPILER_MSVC) + +template +_LIBCUDACXX_CONCEPT destructible = __is_nothrow_destructible(_Tp); + +#else // ^^^ _LIBCUDACXX_COMPILER_MSVC ^^^ / vvv !_LIBCUDACXX_COMPILER_MSVC vvv + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __destructible_impl = false; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __destructible_impl<_Tp, + __enable_if_t<_LIBCUDACXX_TRAIT(is_object, _Tp)>, +#if defined(_LIBCUDACXX_COMPILER_GCC) + __enable_if_t<_LIBCUDACXX_TRAIT(is_destructible, _Tp)>> +#else // ^^^ defined(_LIBCUDACXX_COMPILER_GCC) ^^^ / vvv !_LIBCUDACXX_COMPILER_GCC vvv + __void_t().~_Tp())>> +#endif // !_LIBCUDACXX_COMPILER_GCC + = noexcept(_CUDA_VSTD::declval<_Tp>().~_Tp()); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __destructible = __destructible_impl<_Tp>; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __destructible<_Tp&> = true; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __destructible<_Tp&&> = true; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __destructible<_Tp[_Nm]> = __destructible<_Tp>; + +template +_LIBCUDACXX_CONCEPT destructible = __destructible<_Tp>; + +#endif // !_LIBCUDACXX_COMPILER_MSVC + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_DESTRUCTIBLE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/different_from.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/different_from.h new file mode 100644 index 0000000000000000000000000000000000000000..c4b146ded36f182de178400bc947ee7403daf4ce --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/different_from.h @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_DIFFERENT_FROM_H +#define _LIBCUDACXX___CONCEPTS_DIFFERENT_FROM_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/same_as.h" +#include "../__type_traits/remove_cvref.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT __different_from = !same_as, remove_cvref_t<_Up>>; + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_DIFFERENT_FROM_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/equality_comparable.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/equality_comparable.h new file mode 100644 index 0000000000000000000000000000000000000000..8a431b980acd414276b6d6eed28b391e56e532ca --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/equality_comparable.h @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_EQUALITY_COMPARABLE_H +#define _LIBCUDACXX___CONCEPTS_EQUALITY_COMPARABLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/boolean_testable.h" +#include "../__concepts/common_reference_with.h" +#include "../__type_traits/common_reference.h" +#include "../__type_traits/make_const_lvalue_ref.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.equalitycomparable] + +template +concept __weakly_equality_comparable_with = + requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) { + { __t == __u } -> __boolean_testable; + { __t != __u } -> __boolean_testable; + { __u == __t } -> __boolean_testable; + { __u != __t } -> __boolean_testable; + }; + +template +concept equality_comparable = __weakly_equality_comparable_with<_Tp, _Tp>; + +template +concept equality_comparable_with = + equality_comparable<_Tp> && equality_comparable<_Up> && + common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> && + equality_comparable< + common_reference_t< + __make_const_lvalue_ref<_Tp>, + __make_const_lvalue_ref<_Up>>> && + __weakly_equality_comparable_with<_Tp, _Up>; + +#elif _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __with_lvalue_reference_, + requires()( + typename(__make_const_lvalue_ref<_Tp>) + )); + +template +_LIBCUDACXX_CONCEPT _With_lvalue_reference = _LIBCUDACXX_FRAGMENT(__with_lvalue_reference_, _Tp); + + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __weakly_equality_comparable_with_, + requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) // + (requires(_With_lvalue_reference<_Tp>), + requires(_With_lvalue_reference<_Up>), + requires(__boolean_testable), + requires(__boolean_testable), + requires(__boolean_testable), + requires(__boolean_testable))); + +template +_LIBCUDACXX_CONCEPT __weakly_equality_comparable_with = + _LIBCUDACXX_FRAGMENT(__weakly_equality_comparable_with_, _Tp, _Up); + +template +_LIBCUDACXX_CONCEPT equality_comparable = __weakly_equality_comparable_with<_Tp, _Tp>; + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __equality_comparable_with_, + requires()( + requires(equality_comparable<_Tp>), + requires(equality_comparable<_Up>), + requires(common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>>), + requires(equality_comparable< + common_reference_t< + __make_const_lvalue_ref<_Tp>, + __make_const_lvalue_ref<_Up>>>), + requires(__weakly_equality_comparable_with<_Tp, _Up>))); + +template +_LIBCUDACXX_CONCEPT equality_comparable_with = _LIBCUDACXX_FRAGMENT(__equality_comparable_with_, _Tp, _Up); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_EQUALITY_COMPARABLE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/invocable.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/invocable.h new file mode 100644 index 0000000000000000000000000000000000000000..51c2bd209ddc33f78fb4de818b73ed7545c43f9d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/invocable.h @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_INVOCABLE_H +#define _LIBCUDACXX___CONCEPTS_INVOCABLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__functional/invoke.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.invocable] + +template +concept invocable = requires(_Fn&& __fn, _Args&&... __args) { + _CUDA_VSTD::__invoke(_CUDA_VSTD::forward<_Fn>(__fn), _CUDA_VSTD::forward<_Args>(__args)...); // not required to be equality preserving +}; + +// [concept.regular.invocable] + +template +concept regular_invocable = invocable<_Fn, _Args...>; + +template +concept __invoke_constructible = requires(_Fun&& __fun, _Args&&... __args) { + static_cast>>( + _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...)); +}; + +#elif _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + _Invocable_, + requires(_Fn&& __fn, _Args&&... __args) // + (_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn>(__fn), _CUDA_VSTD::forward<_Args>(__args)...))); + +template +_LIBCUDACXX_CONCEPT invocable = _LIBCUDACXX_FRAGMENT(_Invocable_, _Fn, _Args...); + +template +_LIBCUDACXX_CONCEPT regular_invocable = invocable<_Fn, _Args...>; + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __invoke_constructible_, + requires(_Fun&& __fun, _Args&&... __args)( + (static_cast<__remove_cvref_t>>( + _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...))) + )); +template +_LIBCUDACXX_CONCEPT __invoke_constructible = _LIBCUDACXX_FRAGMENT(__invoke_constructible_, _Fun, _Args...); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_INVOCABLE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/movable.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/movable.h new file mode 100644 index 0000000000000000000000000000000000000000..8eb604286378a72ef1f5864d8df1a5ea6a9ac81d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/movable.h @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_MOVABLE_H +#define _LIBCUDACXX___CONCEPTS_MOVABLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/assignable.h" +#include "../__concepts/constructible.h" +#include "../__concepts/swappable.h" +#include "../__type_traits/is_object.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +template +concept movable = + is_object_v<_Tp> && + move_constructible<_Tp>&& + assignable_from<_Tp&, _Tp> && + swappable<_Tp>; + +#elif _LIBCUDACXX_STD_VER > 11 + +// [concepts.object] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + _Movable_, + requires() + (requires(is_object_v<_Tp>), + requires(move_constructible<_Tp>), + requires(assignable_from<_Tp&, _Tp>), + requires(swappable<_Tp>))); + +template +_LIBCUDACXX_CONCEPT movable = _LIBCUDACXX_FRAGMENT(_Movable_, _Tp); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_MOVABLE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/predicate.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/predicate.h new file mode 100644 index 0000000000000000000000000000000000000000..5478b5fdce1d0b8e27eda5436cb3fa806ab5b67e --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/predicate.h @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_PREDICATE_H +#define _LIBCUDACXX___CONCEPTS_PREDICATE_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/boolean_testable.h" +#include "../__concepts/invocable.h" +#include "../__functional/invoke.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +template +concept predicate = + regular_invocable<_Fn, _Args...> && __boolean_testable>; + +#elif _LIBCUDACXX_STD_VER > 11 + +// [concept.predicate] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + _Predicate_, + requires() + (requires(regular_invocable<_Fn, _Args...>), + requires(__boolean_testable>))); + +template +_LIBCUDACXX_CONCEPT predicate = _LIBCUDACXX_FRAGMENT(_Predicate_, _Fn, _Args...); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_PREDICATE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/regular.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/regular.h new file mode 100644 index 0000000000000000000000000000000000000000..118e88c3018ee4f3061283a92073f49022e21c92 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/regular.h @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_REGULAR_H +#define _LIBCUDACXX___CONCEPTS_REGULAR_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/equality_comparable.h" +#include "../__concepts/semiregular.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.object] + +template +concept regular = semiregular<_Tp> && equality_comparable<_Tp>; + +#elif _LIBCUDACXX_STD_VER > 11 + +// [concept.object] + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __regular_, + requires()( + requires(semiregular<_Tp>), + requires(equality_comparable<_Tp>) + )); + +template +_LIBCUDACXX_CONCEPT regular = _LIBCUDACXX_FRAGMENT(__regular_, _Tp); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_REGULAR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/relation.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/relation.h new file mode 100644 index 0000000000000000000000000000000000000000..5e46686cdcbabc4a0e01787decbb29e318789924 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/relation.h @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_RELATION_H +#define _LIBCUDACXX___CONCEPTS_RELATION_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/predicate.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.relation] + +template +concept relation = + predicate<_Rp, _Tp, _Tp> && predicate<_Rp, _Up, _Up> && + predicate<_Rp, _Tp, _Up> && predicate<_Rp, _Up, _Tp>; + +// [concept.equiv] + +template +concept equivalence_relation = relation<_Rp, _Tp, _Up>; + +// [concept.strictweakorder] + +template +concept strict_weak_order = relation<_Rp, _Tp, _Up>; + +#elif _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __relation_, + requires()( + requires(predicate<_Rp, _Tp, _Tp>), + requires(predicate<_Rp, _Up, _Up>), + requires(predicate<_Rp, _Tp, _Up>), + requires(predicate<_Rp, _Up, _Tp>) + )); + +template +_LIBCUDACXX_CONCEPT relation = _LIBCUDACXX_FRAGMENT(__relation_, _Rp, _Tp, _Up); + +// [concept.equiv] + +template +_LIBCUDACXX_CONCEPT equivalence_relation = relation<_Rp, _Tp, _Up>; + +// [concept.strictweakorder] + +template +_LIBCUDACXX_CONCEPT strict_weak_order = relation<_Rp, _Tp, _Up>; + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_RELATION_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/same_as.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/same_as.h new file mode 100644 index 0000000000000000000000000000000000000000..039b09e2dadcb271441282cc229366a99283a8b3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/same_as.h @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_SAME_AS_H +#define _LIBCUDACXX___CONCEPTS_SAME_AS_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__type_traits/is_same.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +// [concept.same] + +template +_LIBCUDACXX_CONCEPT __same_as_impl = _IsSame<_Tp, _Up>::value; + +template +_LIBCUDACXX_CONCEPT same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>; + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_SAME_AS_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/semiregular.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/semiregular.h new file mode 100644 index 0000000000000000000000000000000000000000..22663849435e5650cff840475df73f2a284b31d2 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/semiregular.h @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_SEMIREGULAR_H +#define _LIBCUDACXX___CONCEPTS_SEMIREGULAR_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/constructible.h" +#include "../__concepts/copyable.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.object] + +template +concept semiregular = copyable<_Tp> && default_initializable<_Tp>; + +#elif _LIBCUDACXX_STD_VER > 11 + +// [concept.object] + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __semiregular_, + requires()( + requires(copyable<_Tp>), + requires(default_initializable<_Tp>) + )); + +template +_LIBCUDACXX_CONCEPT semiregular = _LIBCUDACXX_FRAGMENT(__semiregular_, _Tp); + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_SEMIREGULAR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/swappable.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/swappable.h new file mode 100644 index 0000000000000000000000000000000000000000..b1cfad2c96891145f4876c7d08b2dd1c6a71bb4d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/swappable.h @@ -0,0 +1,224 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_SWAPPABLE_H +#define _LIBCUDACXX___CONCEPTS_SWAPPABLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/assignable.h" +#include "../__concepts/class_or_enum.h" +#include "../__concepts/common_reference_with.h" +#include "../__concepts/constructible.h" +#include "../__type_traits/extent.h" +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/is_nothrow_move_assignable.h" +#include "../__type_traits/is_nothrow_move_constructible.h" +#include "../__type_traits/remove_cvref.h" +#include "../__type_traits/type_identity.h" +#include "../__type_traits/void_t.h" +#include "../__utility/declval.h" +#include "../__utility/exchange.h" +#include "../__utility/forward.h" +#include "../__utility/move.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +_LIBCUDACXX_NV_DIAG_SUPPRESS(461) // nonstandard cast to array type ignored +#endif // _LIBCUDACXX_COMPILER_MSVC + +#if _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES + +// [concept.swappable] + +_LIBCUDACXX_BEGIN_NAMESPACE_CPO(__swap) + + template + void swap(_Tp&, _Tp&) = delete; + +#if _LIBCUDACXX_STD_VER > 17 + template + concept __unqualified_swappable_with = + (__class_or_enum> || __class_or_enum>) && + requires(_Tp&& __t, _Up&& __u) { + swap(_CUDA_VSTD::forward<_Tp>(__t), _CUDA_VSTD::forward<_Up>(__u)); + }; + + template + concept __exchangeable = + !__unqualified_swappable_with<_Tp&, _Tp&> && + move_constructible<_Tp> && + assignable_from<_Tp&, _Tp>; + +#else // ^^^ CXX20 ^^^ / vvv CXX17 vvv + + template + _LIBCUDACXX_CONCEPT_FRAGMENT( + __unqualified_swappable_with_, + requires(_Tp&& __t, _Up&& __u)( + (swap(_CUDA_VSTD::forward<_Tp>(__t), _CUDA_VSTD::forward<_Up>(__u))) + )); + + template + _LIBCUDACXX_CONCEPT __unqualified_swappable_with = _LIBCUDACXX_FRAGMENT(__unqualified_swappable_with_, _Tp, _Up); + + template + _LIBCUDACXX_CONCEPT_FRAGMENT( + __exchangeable_, + requires()( + requires(!__unqualified_swappable_with<_Tp&, _Tp&>), + requires(move_constructible<_Tp>), + requires(assignable_from<_Tp&, _Tp>) + )); + + template + _LIBCUDACXX_CONCEPT __exchangeable = _LIBCUDACXX_FRAGMENT(__exchangeable_, _Tp); +#endif // _LIBCUDACXX_STD_VER < 20 + + +#if _LIBCUDACXX_STD_VER > 17 && !defined(_LIBCUDACXX_COMPILER_NVHPC) // nvbug4051640 + struct __fn; + +_LIBCUDACXX_NV_DIAG_SUPPRESS(2642) + template + concept __swappable_arrays = + !__unqualified_swappable_with<_Tp(&)[_Size], _Up(&)[_Size]> && + extent_v<_Tp> == extent_v<_Up> && + requires(_Tp(& __t)[_Size], _Up(& __u)[_Size], const __fn& __swap) { + __swap(__t[0], __u[0]); + }; +_LIBCUDACXX_NV_DIAG_DEFAULT(2642) + +#else + template + _LIBCUDACXX_INLINE_VAR constexpr bool __swappable_arrays = false; +#endif // _LIBCUDACXX_STD_VER < 20 || defined(_LIBCUDACXX_COMPILER_NVHPC) + + + template + _LIBCUDACXX_INLINE_VAR constexpr bool __noexcept_swappable_arrays = false; + + struct __fn { + // 2.1 `S` is `(void)swap(E1, E2)`* if `E1` or `E2` has class or enumeration type and... + // *The name `swap` is used here unqualified. + _LIBCUDACXX_TEMPLATE(class _Tp, class _Up) + (requires __unqualified_swappable_with<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr void operator()(_Tp&& __t, _Up&& __u) const + noexcept(noexcept(swap(_CUDA_VSTD::forward<_Tp>(__t), _CUDA_VSTD::forward<_Up>(__u)))) + { + swap(_CUDA_VSTD::forward<_Tp>(__t), _CUDA_VSTD::forward<_Up>(__u)); + } + + // 2.2 Otherwise, if `E1` and `E2` are lvalues of array types with equal extent and... + _LIBCUDACXX_TEMPLATE(class _Tp, class _Up, size_t _Size) + (requires __swappable_arrays<_Tp, _Up, _Size>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr void operator()(_Tp(& __t)[_Size], _Up(& __u)[_Size]) const + noexcept(__noexcept_swappable_arrays<_Tp, _Up>) + { + // TODO(cjdb): replace with `_CUDA_VRANGES::swap_ranges`. + for (size_t __i = 0; __i < _Size; ++__i) { + (*this)(__t[__i], __u[__i]); + } + } + + // 2.3 Otherwise, if `E1` and `E2` are lvalues of the same type `T` that models... + _LIBCUDACXX_TEMPLATE(class _Tp) + (requires __exchangeable<_Tp>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr void operator()(_Tp& __x, _Tp& __y) const + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp) && _LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Tp)) + { + __y = _CUDA_VSTD::exchange(__x, _CUDA_VSTD::move(__y)); + } + }; + +#if _LIBCUDACXX_STD_VER < 20 || defined(_LIBCUDACXX_COMPILER_NVHPC) + template + _LIBCUDACXX_CONCEPT_FRAGMENT( + __swappable_arrays_, + requires(_Tp(& __t)[_Size::value], _Up(& __u)[_Size::value], const __fn& __swap)( + requires(!__unqualified_swappable_with<_Tp(&)[_Size::value], _Up(&)[_Size::value]>), + requires(_LIBCUDACXX_TRAIT(extent, _Tp) == _LIBCUDACXX_TRAIT(extent, _Up)), + (__swap(__t[0], __u[0])) + )); + + template + _LIBCUDACXX_INLINE_VAR constexpr bool __swappable_arrays<_Tp, _Up, _Size, void_t>> = + _LIBCUDACXX_FRAGMENT(__swappable_arrays_, _Tp, _Up, _CUDA_VSTD::integral_constant); +#endif // _LIBCUDACXX_STD_VER < 20 || defined(_LIBCUDACXX_COMPILER_NVHPC) + + template + _LIBCUDACXX_INLINE_VAR constexpr bool __noexcept_swappable_arrays<_Tp, _Up, void_t>> = + noexcept(__swap::__fn{}(_CUDA_VSTD::declval<_Tp&>(), _CUDA_VSTD::declval<_Up&>())); + +_LIBCUDACXX_END_NAMESPACE_CPO + +inline namespace __cpo { + _LIBCUDACXX_CPO_ACCESSIBILITY auto swap = __swap::__fn{}; +} // namespace __cpo +_LIBCUDACXX_END_NAMESPACE_RANGES + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 +template +concept swappable = requires(_Tp& __a, _Tp& __b) { _CUDA_VRANGES::swap(__a, __b); }; + +template +concept swappable_with = + common_reference_with<_Tp, _Up> && + requires(_Tp&& __t, _Up&& __u) { + _CUDA_VRANGES::swap(_CUDA_VSTD::forward<_Tp>(__t), _CUDA_VSTD::forward<_Tp>(__t)); + _CUDA_VRANGES::swap(_CUDA_VSTD::forward<_Up>(__u), _CUDA_VSTD::forward<_Up>(__u)); + _CUDA_VRANGES::swap(_CUDA_VSTD::forward<_Tp>(__t), _CUDA_VSTD::forward<_Up>(__u)); + _CUDA_VRANGES::swap(_CUDA_VSTD::forward<_Up>(__u), _CUDA_VSTD::forward<_Tp>(__t)); + }; +#else +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __swappable_, + requires(_Tp& __a, _Tp& __b)( + (_CUDA_VRANGES::swap(__a, __b)) + )); + +template +_LIBCUDACXX_CONCEPT swappable = _LIBCUDACXX_FRAGMENT(__swappable_, _Tp); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __swappable_with_, + requires(_Tp&& __t, _Up&& __u)( + requires(common_reference_with<_Tp, _Up>), + (_CUDA_VRANGES::swap(_CUDA_VSTD::forward<_Tp>(__t), _CUDA_VSTD::forward<_Tp>(__t))), + (_CUDA_VRANGES::swap(_CUDA_VSTD::forward<_Up>(__u), _CUDA_VSTD::forward<_Up>(__u))), + (_CUDA_VRANGES::swap(_CUDA_VSTD::forward<_Tp>(__t), _CUDA_VSTD::forward<_Up>(__u))), + (_CUDA_VRANGES::swap(_CUDA_VSTD::forward<_Up>(__u), _CUDA_VSTD::forward<_Tp>(__t))) + )); + +template +_LIBCUDACXX_CONCEPT swappable_with = _LIBCUDACXX_FRAGMENT(__swappable_with_, _Tp, _Up); +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_STD_VER > 11 + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +_LIBCUDACXX_NV_DIAG_DEFAULT(461) // nonstandard cast to array type ignored +#endif // _LIBCUDACXX_COMPILER_MSVC + + +#endif // _LIBCUDACXX___CONCEPTS_SWAPPABLE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/totally_ordered.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/totally_ordered.h new file mode 100644 index 0000000000000000000000000000000000000000..30df04eb4fd23eb6f988250ac19bcb374343b9b2 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__concepts/totally_ordered.h @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CONCEPTS_TOTALLY_ORDERED_H +#define _LIBCUDACXX___CONCEPTS_TOTALLY_ORDERED_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__concepts/boolean_testable.h" +#include "../__concepts/equality_comparable.h" +#include "../__type_traits/common_reference.h" +#include "../__type_traits/make_const_lvalue_ref.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [concept.totallyordered] + +template +concept __partially_ordered_with = + requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) { + { __t < __u } -> __boolean_testable; + { __t > __u } -> __boolean_testable; + { __t <= __u } -> __boolean_testable; + { __t >= __u } -> __boolean_testable; + { __u < __t } -> __boolean_testable; + { __u > __t } -> __boolean_testable; + { __u <= __t } -> __boolean_testable; + { __u >= __t } -> __boolean_testable; + }; + +template +concept totally_ordered = equality_comparable<_Tp> && __partially_ordered_with<_Tp, _Tp>; + +template +concept totally_ordered_with = + totally_ordered<_Tp> && totally_ordered<_Up> && + equality_comparable_with<_Tp, _Up> && + totally_ordered< + common_reference_t< + __make_const_lvalue_ref<_Tp>, + __make_const_lvalue_ref<_Up>>> && + __partially_ordered_with<_Tp, _Up>; + +#elif _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __partially_ordered_with_, + requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) // + (requires(__boolean_testable), + requires(__boolean_testable __u)>), + requires(__boolean_testable), + requires(__boolean_testable= __u)>), + requires(__boolean_testable), + requires(__boolean_testable __t)>), + requires(__boolean_testable), + requires(__boolean_testable= __t)>))); + +template +_LIBCUDACXX_CONCEPT __partially_ordered_with = _LIBCUDACXX_FRAGMENT(__partially_ordered_with_, _Tp, _Up); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __totally_ordered_, + requires()( + requires(equality_comparable<_Tp>), + requires(__partially_ordered_with<_Tp, _Tp>) + )); + +template +_LIBCUDACXX_CONCEPT totally_ordered = _LIBCUDACXX_FRAGMENT(__totally_ordered_, _Tp); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __totally_ordered_with_, + requires()( + requires(totally_ordered<_Tp>), + requires(totally_ordered<_Up>), + requires(equality_comparable_with<_Tp, _Up>), + requires(totally_ordered< + common_reference_t< + __make_const_lvalue_ref<_Tp>, + __make_const_lvalue_ref<_Up>>>), + requires(__partially_ordered_with<_Tp, _Up>))); + +template +_LIBCUDACXX_CONCEPT totally_ordered_with = _LIBCUDACXX_FRAGMENT(__totally_ordered_with_, _Tp, _Up);; + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CONCEPTS_TOTALLY_ORDERED_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__config b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__config new file mode 100644 index 0000000000000000000000000000000000000000..404e690d7ad643c2930c56e7f95b33a6412a1fdd --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__config @@ -0,0 +1,2258 @@ +// -*- C++ -*- +//===--------------------------- __config ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_CONFIG +#define _LIBCUDACXX_CONFIG + +#if defined(__NVCOMPILER) +# define _LIBCUDACXX_COMPILER_NVHPC +#elif defined(__clang__) +# define _LIBCUDACXX_COMPILER_CLANG +# ifndef __apple_build_version__ +# define _LIBCUDACXX_CLANG_VER (__clang_major__ * 100 + __clang_minor__) +# endif +#elif defined(__GNUC__) +# define _LIBCUDACXX_COMPILER_GCC +#elif defined(_MSC_VER) +# define _LIBCUDACXX_COMPILER_MSVC +#elif defined(__IBMCPP__) +# define _LIBCUDACXX_COMPILER_IBM +#elif defined(__CUDACC_RTC__) +# define _LIBCUDACXX_COMPILER_NVRTC +#endif + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +#if _MSC_VER < 1917 +#define _LIBCUDACXX_COMPILER_MSVC_2017 +#elif _MSC_VER < 1930 +#define _LIBCUDACXX_COMPILER_MSVC_2019 +#else +#define _LIBCUDACXX_COMPILER_MSVC_2022 +#endif +#endif // defined(_LIBCUDACXX_COMPILER_MSVC) + +#if defined(__NVCC__) +// This is not mutually exclusive with other compilers, as NVCC uses a host +// compiler. +# define _LIBCUDACXX_COMPILER_NVCC +#elif defined(_NVHPC_CUDA) +# define _LIBCUDACXX_COMPILER_NVHPC_CUDA +#elif defined(__CUDA__) && defined(_LIBCUDACXX_COMPILER_CLANG) +# define _LIBCUDACXX_COMPILER_CLANG_CUDA +#endif + +#ifdef __CUDACC__ +# define _LIBCUDACXX_CUDACC +# define _LIBCUDACXX_CUDACC_VER_MAJOR __CUDACC_VER_MAJOR__ +# define _LIBCUDACXX_CUDACC_VER_MINOR __CUDACC_VER_MINOR__ +# define _LIBCUDACXX_CUDACC_VER_BUILD __CUDACC_VER_BUILD__ +# define _LIBCUDACXX_CUDACC_VER \ + _LIBCUDACXX_CUDACC_VER_MAJOR * 100000 + _LIBCUDACXX_CUDACC_VER_MINOR * 1000 + \ + _LIBCUDACXX_CUDACC_VER_BUILD + +// TODO: Determine if this is necessary, I don't know why we automatically include this in +# if defined(__clang__) || defined(__FLT16_MANT_DIG__) +# include +# endif +#endif + +// Some convenience macros to filter CUDACC versions +#if defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1102000 +#define _LIBCUDACXX_CUDACC_BELOW_11_2 +#endif // defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1102000 +#if defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1103000 +#define _LIBCUDACXX_CUDACC_BELOW_11_3 +#endif // defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1103000 +#if defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1108000 +#define _LIBCUDACXX_CUDACC_BELOW_11_8 +#endif // defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1108000 + +#if defined(_MSC_VER) && !defined(__clang__) +# define _LIBCUDACXX_HAS_PRAGMA_MSVC_WARNING +# if !defined(_LIBCUDACXX_DISABLE_PRAGMA_MSVC_WARNING) +# define _LIBCUDACXX_USE_PRAGMA_MSVC_WARNING +# endif +#else +# if !defined(_LIBCUDACXX_DISABLE_PRAGMA_GCC_SYSTEM_HEADER) && !defined(_LIBCUDACXX_COMPILER_NVRTC) +# define _LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER +# endif +#endif + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef __cplusplus + +// __config may be included in `extern "C"` contexts, switch back to include +extern "C++" { +#include +} + +#ifdef __GNUC__ +# define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__) +#else +# define _GNUC_VER 0 +#endif + +#define _LIBCUDACXX_VERSION 10000 + +#ifndef _LIBCUDACXX_ABI_VERSION +# define _LIBCUDACXX_ABI_VERSION 1 +#endif + +#ifndef _LIBCUDACXX_STD_VER +# if defined(_MSC_VER) +# if _MSVC_LANG <= 201103L +# define _LIBCUDACXX_STD_VER 11 +# elif _MSVC_LANG <= 201402L +# define _LIBCUDACXX_STD_VER 14 +# elif _MSVC_LANG <= 201703L +# define _LIBCUDACXX_STD_VER 17 +# elif _MSVC_LANG <= 202002L +# define _LIBCUDACXX_STD_VER 20 +# else +# define _LIBCUDACXX_STD_VER 23 // current year, or date of c++2b ratification +# endif +# else +# if __cplusplus <= 201103L +# define _LIBCUDACXX_STD_VER 11 +# elif __cplusplus <= 201402L +# define _LIBCUDACXX_STD_VER 14 +# elif __cplusplus <= 201703L +# define _LIBCUDACXX_STD_VER 17 +# elif __cplusplus <= 202002L +# define _LIBCUDACXX_STD_VER 20 +# else +# define _LIBCUDACXX_STD_VER 23 // current year, or date of c++2b ratification +# endif +# endif +#endif // _LIBCUDACXX_STD_VER + +#if _LIBCUDACXX_STD_VER < 11 +#define _LIBCUDACXX_CXX03_LANG +#endif + +#if (defined(_LIBCUDACXX_COMPILER_NVHPC) && defined(__linux__)) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) + #define __ELF__ +#endif + +#if defined(__ELF__) +# define _LIBCUDACXX_OBJECT_FORMAT_ELF 1 +#elif defined(__MACH__) +# define _LIBCUDACXX_OBJECT_FORMAT_MACHO 1 +#elif defined(_WIN32) +# define _LIBCUDACXX_OBJECT_FORMAT_COFF 1 +#elif defined(__wasm__) +# define _LIBCUDACXX_OBJECT_FORMAT_WASM 1 +#else +# error Unknown object file format +#endif + +#if defined(_LIBCUDACXX_ABI_UNSTABLE) || _LIBCUDACXX_ABI_VERSION >= 2 || defined(__cuda_std__) +// Change short string representation so that string data starts at offset 0, +// improving its alignment in some cases. +# define _LIBCUDACXX_ABI_ALTERNATE_STRING_LAYOUT +// Fix deque iterator type in order to support incomplete types. +# define _LIBCUDACXX_ABI_INCOMPLETE_TYPES_IN_DEQUE +// Fix undefined behavior in how std::list stores its linked nodes. +# define _LIBCUDACXX_ABI_LIST_REMOVE_NODE_POINTER_UB +// Fix undefined behavior in how __tree stores its end and parent nodes. +# define _LIBCUDACXX_ABI_TREE_REMOVE_NODE_POINTER_UB +// Fix undefined behavior in how __hash_table stores its pointer types. +# define _LIBCUDACXX_ABI_FIX_UNORDERED_NODE_POINTER_UB +# define _LIBCUDACXX_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB +# define _LIBCUDACXX_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE +// Don't use a nullptr_t simulation type in C++03 instead using C++11 nullptr +// provided under the alternate keyword __nullptr, which changes the mangling +// of nullptr_t. This option is ABI incompatible with GCC in C++03 mode. +# define _LIBCUDACXX_ABI_ALWAYS_USE_CXX11_NULLPTR +// Define the `pointer_safety` enum as a C++11 strongly typed enumeration +// instead of as a class simulating an enum. If this option is enabled +// `pointer_safety` and `get_pointer_safety()` will no longer be available +// in C++03. +# define _LIBCUDACXX_ABI_POINTER_SAFETY_ENUM_TYPE +// Define a key function for `bad_function_call` in the library, to centralize +// its vtable and typeinfo to libc++ rather than having all other libraries +// using that class define their own copies. +# define _LIBCUDACXX_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION +// Enable optimized version of __do_get_(un)signed which avoids redundant copies. +# define _LIBCUDACXX_ABI_OPTIMIZED_LOCALE_NUM_GET +// Use the smallest possible integer type to represent the index of the variant. +// Previously libc++ used "unsigned int" exclusively. +# define _LIBCUDACXX_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION +// Unstable attempt to provide a more optimized std::function +# define _LIBCUDACXX_ABI_OPTIMIZED_FUNCTION +// All the regex constants must be distinct and nonzero. +# define _LIBCUDACXX_ABI_REGEX_CONSTANTS_NONZERO +#elif _LIBCUDACXX_ABI_VERSION == 1 +# if !defined(_LIBCUDACXX_OBJECT_FORMAT_COFF) +// Enable compiling copies of now inline methods into the dylib to support +// applications compiled against older libraries. This is unnecessary with +// COFF dllexport semantics, since dllexport forces a non-inline definition +// of inline functions to be emitted anyway. Our own non-inline copy would +// conflict with the dllexport-emitted copy, so we disable it. +# define _LIBCUDACXX_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS +# endif +// Feature macros for disabling pre ABI v1 features. All of these options +// are deprecated. +# if defined(__FreeBSD__) +# define _LIBCUDACXX_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR +# endif +#endif + +#ifdef _LIBCUDACXX_TRIVIAL_PAIR_COPY_CTOR +#error "_LIBCUDACXX_TRIVIAL_PAIR_COPY_CTOR" is no longer supported. \ + use _LIBCUDACXX_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR instead +#endif + +#ifndef __has_attribute +#define __has_attribute(__x) 0 +#endif + +#ifndef __has_builtin +#define __has_builtin(__x) 0 +#endif + +#ifndef __has_extension +#define __has_extension(__x) 0 +#endif + +#ifndef __has_feature +#define __has_feature(__x) 0 +#endif + +#ifndef __has_cpp_attribute +#define __has_cpp_attribute(__x) 0 +#endif + +// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by +// the compiler and '1' otherwise. +#ifndef __is_identifier +#define __is_identifier(__x) 1 +#endif + +#ifndef __has_declspec_attribute +#define __has_declspec_attribute(__x) 0 +#endif + +#define __has_keyword(__x) !(__is_identifier(__x)) + +#ifndef __has_include +#define __has_include(...) 0 +#endif + +#if !defined(_LIBCUDACXX_COMPILER_NVCC) && !defined(_LIBCUDACXX_COMPILER_NVRTC) +// If NVCC is not being used can safely use `long double` without warnings +# define _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE +// NVCC does not have a way of silencing non '_' prefixed UDLs +# define _LIBCUDACXX_HAS_STL_LITERALS +#endif + +#if defined(_LIBCUDACXX_COMPILER_GCC) && __cplusplus < 201103L +#error "libc++ does not support using GCC with C++03. Please enable C++11" +#endif + +// FIXME: ABI detection should be done via compiler builtin macros. This +// is just a placeholder until Clang implements such macros. For now assume +// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, +// and allow the user to explicitly specify the ABI to handle cases where this +// heuristic falls short. +#if defined(_LIBCUDACXX_ABI_FORCE_ITANIUM) && defined(_LIBCUDACXX_ABI_FORCE_MICROSOFT) +# error "Only one of _LIBCUDACXX_ABI_FORCE_ITANIUM and _LIBCUDACXX_ABI_FORCE_MICROSOFT can be defined" +#elif defined(_LIBCUDACXX_ABI_FORCE_ITANIUM) +# define _LIBCUDACXX_ABI_ITANIUM +#elif defined(_LIBCUDACXX_ABI_FORCE_MICROSOFT) +# define _LIBCUDACXX_ABI_MICROSOFT +#else +# if defined(_WIN32) && defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_ABI_MICROSOFT +# else +# define _LIBCUDACXX_ABI_ITANIUM +# endif +#endif + +#if defined(_LIBCUDACXX_ABI_MICROSOFT) && !defined(_LIBCUDACXX_NO_VCRUNTIME) +# define _LIBCUDACXX_ABI_VCRUNTIME +#endif + +// Need to detect which libc we're using if we're on Linux. +#if defined(__linux__) +# include +# if defined(__GLIBC_PREREQ) +# define _LIBCUDACXX_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) +# else +# define _LIBCUDACXX_GLIBC_PREREQ(a, b) 0 +# endif // defined(__GLIBC_PREREQ) +#endif // defined(__linux__) + +#ifdef __LITTLE_ENDIAN__ +# if __LITTLE_ENDIAN__ +# define _LIBCUDACXX_LITTLE_ENDIAN +# endif // __LITTLE_ENDIAN__ +#endif // __LITTLE_ENDIAN__ + +#ifdef __BIG_ENDIAN__ +# if __BIG_ENDIAN__ +# define _LIBCUDACXX_BIG_ENDIAN +# endif // __BIG_ENDIAN__ +#endif // __BIG_ENDIAN__ + +#ifdef __BYTE_ORDER__ +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define _LIBCUDACXX_LITTLE_ENDIAN +# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define _LIBCUDACXX_BIG_ENDIAN +# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#endif // __BYTE_ORDER__ + +#ifdef __FreeBSD__ +# include +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCUDACXX_LITTLE_ENDIAN +# else // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCUDACXX_BIG_ENDIAN +# endif // _BYTE_ORDER == _LITTLE_ENDIAN +# ifndef __LONG_LONG_SUPPORTED +# define _LIBCUDACXX_HAS_NO_LONG_LONG +# endif // __LONG_LONG_SUPPORTED +#endif // __FreeBSD__ + +#ifdef __NetBSD__ +# include +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCUDACXX_LITTLE_ENDIAN +# else // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCUDACXX_BIG_ENDIAN +# endif // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCUDACXX_HAS_QUICK_EXIT +#endif // __NetBSD__ + +#if defined(_WIN32) +# define _LIBCUDACXX_WIN32API +# define _LIBCUDACXX_LITTLE_ENDIAN +# define _LIBCUDACXX_SHORT_WCHAR 1 +// Both MinGW and native MSVC provide a "MSVC"-like environment +# define _LIBCUDACXX_MSVCRT_LIKE +// If mingw not explicitly detected, assume using MS C runtime only if +// a MS compatibility version is specified. +# if defined(_LIBCUDACXX_COMPILER_MSVC) && !defined(__MINGW32__) +# define _LIBCUDACXX_MSVCRT // Using Microsoft's C Runtime library +# endif +# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) +# define _LIBCUDACXX_HAS_BITSCAN64 +# endif +# define _LIBCUDACXX_HAS_OPEN_WITH_WCHAR +# if defined(_LIBCUDACXX_MSVCRT) +# define _LIBCUDACXX_HAS_QUICK_EXIT +# endif + +// Some CRT APIs are unavailable to store apps +# if defined(WINAPI_FAMILY) +# include +# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && \ + (!defined(WINAPI_PARTITION_SYSTEM) || \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM)) +# define _LIBCUDACXX_WINDOWS_STORE_APP +# endif +# endif +#endif // defined(_WIN32) + +#ifdef __sun__ +# include +# ifdef _LITTLE_ENDIAN +# define _LIBCUDACXX_LITTLE_ENDIAN +# else +# define _LIBCUDACXX_BIG_ENDIAN +# endif +#endif // __sun__ + +#if defined(__CloudABI__) + // Certain architectures provide arc4random(). Prefer using + // arc4random() over /dev/{u,}random to make it possible to obtain + // random data even when using sandboxing mechanisms such as chroots, + // Capsicum, etc. +# define _LIBCUDACXX_USING_ARC4_RANDOM +#elif defined(__Fuchsia__) || defined(__wasi__) +# define _LIBCUDACXX_USING_GETENTROPY +#elif defined(__native_client__) + // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, + // including accesses to the special files under /dev. C++11's + // std::random_device is instead exposed through a NaCl syscall. +# define _LIBCUDACXX_USING_NACL_RANDOM +#elif defined(_LIBCUDACXX_WIN32API) +# define _LIBCUDACXX_USING_WIN32_RANDOM +#else +# define _LIBCUDACXX_USING_DEV_RANDOM +#endif + +#ifndef _LIBCUDACXX_LITTLE_ENDIAN +#if defined(_LIBCUDACXX_COMPILER_NVRTC) +# define _LIBCUDACXX_LITTLE_ENDIAN +#endif +#endif // _LIBCUDACXX_LITTLE_ENDIAN + +#if !defined(_LIBCUDACXX_LITTLE_ENDIAN) && !defined(_LIBCUDACXX_BIG_ENDIAN) +# include +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define _LIBCUDACXX_LITTLE_ENDIAN +# elif __BYTE_ORDER == __BIG_ENDIAN +# define _LIBCUDACXX_BIG_ENDIAN +# else // __BYTE_ORDER == __BIG_ENDIAN +# error unable to determine endian +# endif +#endif // !defined(_LIBCUDACXX_LITTLE_ENDIAN) && !defined(_LIBCUDACXX_BIG_ENDIAN) + +#if __has_attribute(__no_sanitize__) && !defined(_LIBCUDACXX_COMPILER_GCC) +# define _LIBCUDACXX_NO_CFI __attribute__((__no_sanitize__("cfi"))) +#else +# define _LIBCUDACXX_NO_CFI +#endif + +#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L +# if defined(__FreeBSD__) +# define _LIBCUDACXX_HAS_QUICK_EXIT +# define _LIBCUDACXX_HAS_C11_FEATURES +# elif defined(__Fuchsia__) || defined(__wasi__) +# define _LIBCUDACXX_HAS_QUICK_EXIT +# define _LIBCUDACXX_HAS_TIMESPEC_GET +# define _LIBCUDACXX_HAS_C11_FEATURES +# elif defined(__linux__) +# if !defined(_LIBCUDACXX_HAS_MUSL_LIBC) +# if _LIBCUDACXX_GLIBC_PREREQ(2, 15) || defined(__BIONIC__) +# define _LIBCUDACXX_HAS_QUICK_EXIT +# endif +# if _LIBCUDACXX_GLIBC_PREREQ(2, 17) +# define _LIBCUDACXX_HAS_C11_FEATURES +# define _LIBCUDACXX_HAS_TIMESPEC_GET +# endif +# else // defined(_LIBCUDACXX_HAS_MUSL_LIBC) +# define _LIBCUDACXX_HAS_QUICK_EXIT +# define _LIBCUDACXX_HAS_TIMESPEC_GET +# define _LIBCUDACXX_HAS_C11_FEATURES +# endif +# endif // __linux__ +#endif + +#if defined(_LIBCUDACXX_COMPILER_NVRTC) +# define __alignof(x) alignof(x) +#endif // _LIBCUDACXX_COMPILER_NVRTC + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +# define __alignof__ __alignof +#endif + +#define _LIBCUDACXX_ALIGNOF(_Tp) alignof(_Tp) +#define _LIBCUDACXX_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _ALIGNAS_TYPE(x) alignas(x) +# define _ALIGNAS(x) __declspec(align(x)) +#elif __has_feature(cxx_alignas) +# define _ALIGNAS_TYPE(x) alignas(x) +# define _ALIGNAS(x) alignas(x) +#else +# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCUDACXX_ALIGNOF(x)))) +# define _ALIGNAS(x) __attribute__((__aligned__(x))) +#endif // !_LIBCUDACXX_COMPILER_MSVC && !__has_feature(cxx_alignas) + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +#define _LIBCUDACXX_ALWAYS_INLINE __forceinline +#else +#define _LIBCUDACXX_ALWAYS_INLINE __attribute__ ((__always_inline__)) +#endif // !_LIBCUDACXX_COMPILER_MSVC + +#if defined(__cuda_std__) +#define _LIBCUDACXX_ATOMIC_ALWAYS_LOCK_FREE(size, ptr) (size <= 8) +#elif defined(_LIBCUDACXX_COMPILER_CLANG) || defined(_LIBCUDACXX_COMPILER_GCC) +#define _LIBCUDACXX_ATOMIC_ALWAYS_LOCK_FREE(...) __atomic_always_lock_free(__VA_ARGS__) +#endif // __cuda_std__ + +// https://bugs.llvm.org/show_bug.cgi?id=44517 +#define __check_builtin(__x) (__has_builtin(__##__x) || \ + __has_keyword(__##__x) || \ + __has_feature(__x)) + +// We work around old clang versions (before clang-10) not supporting __has_builtin via __check_builtin +// We work around old intel versions (before 2021.3) not supporting __has_builtin via __check_builtin +// We work around old nvhpc versions (before 2022.11) not supporting __has_builtin via __check_builtin +// MSVC needs manual handling, has no real way of checking builtins so all is manual +// GCC needs manual handling, before gcc-10 as that finally supports __has_builtin + +#if __check_builtin(array_rank) +#define _LIBCUDACXX_ARRAY_RANK(...) __array_rank(__VA_ARGS__) +#endif // __check_builtin(array_rank) + +// nvhpc has a bug where it supports __builtin_addressof but does not mark it via __check_builtin +#if __check_builtin(builtin_addressof) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 700) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVHPC) +#define _LIBCUDACXX_ADDRESSOF(...) __builtin_addressof(__VA_ARGS__) +#endif // __check_builtin(builtin_addressof) + +#if __check_builtin(builtin_bit_cast) \ + || (defined(_LIBCUDACXX_COMPILER_MSVC) && _MSC_VER > 1925) +#define _LIBCUDACXX_BIT_CAST(...) __builtin_bit_cast(__VA_ARGS__) +#endif // __check_builtin(builtin_bit_cast) + +#if __check_builtin(builtin_is_constant_evaluated) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 900) \ + || (defined(_LIBCUDACXX_COMPILER_MSVC) && _MSC_VER > 1924) +#define _LIBCUDACXX_IS_CONSTANT_EVALUATED(...) __builtin_is_constant_evaluated(__VA_ARGS__) +#endif // __check_builtin(builtin_is_constant_evaluated) + +// NVCC and NVRTC in C++11 mode freaks out about `__builtin_is_constant_evaluated`. +#if _LIBCUDACXX_STD_VER < 14 \ + && (defined(_LIBCUDACXX_COMPILER_NVCC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || defined(_LIBCUDACXX_COMPILER_NVHPC)) +#undef _LIBCUDACXX_IS_CONSTANT_EVALUATED +#endif // _LIBCUDACXX_STD_VER < 14 && defined(_LIBCUDACXX_COMPILER_NVCC) + +#if __check_builtin(builtin_launder) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 700) +#define _LIBCUDACXX_LAUNDER(...) __builtin_launder(__VA_ARGS__) +#endif // __check_builtin(builtin_launder) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(decay) +#define _LIBCUDACXX_DECAY(...) __decay(__VA_ARGS__) +#endif // __check_builtin(decay) + +#if __check_builtin(has_nothrow_assign) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_NOTHROW_ASSIGN(...) __has_nothrow_assign(__VA_ARGS__) +#endif // __check_builtin(has_nothrow_assign) + +#if __check_builtin(has_nothrow_constructor) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_NOTHROW_CONSTRUCTOR(...) __has_nothrow_constructor(__VA_ARGS__) +#endif // __check_builtin(has_nothrow_constructor) + +#if __check_builtin(has_nothrow_copy) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_NOTHROW_COPY(...) __has_nothrow_copy(__VA_ARGS__) +#endif // __check_builtin(has_nothrow_copy) + +#if __check_builtin(has_trivial_constructor) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_TRIVIAL_CONSTRUCTOR(...) __has_trivial_constructor(__VA_ARGS__) +#endif // __check_builtin(has_trivial_constructor) + +#if __check_builtin(has_trivial_destructor) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_TRIVIAL_DESTRUCTOR(...) __has_trivial_destructor(__VA_ARGS__) +#endif // __check_builtin(has_trivial_destructor) + +#if __check_builtin(has_unique_object_representations) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 700) +#define _LIBCUDACXX_HAS_UNIQUE_OBJECT_REPRESENTATIONS(...) __has_unique_object_representations(__VA_ARGS__) +#endif // __check_builtin(has_unique_object_representations) + +#if __check_builtin(has_virtual_destructor) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_VIRTUAL_DESTRUCTOR(...) __has_virtual_destructor(__VA_ARGS__) +#endif // __check_builtin(has_virtual_destructor) + +#if __check_builtin(is_aggregate) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 700) \ + || (defined(_LIBCUDACXX_COMPILER_MSVC) && _MSC_VER > 1914) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_AGGREGATE(...) __is_aggregate(__VA_ARGS__) +#endif // __check_builtin(is_aggregate) + +#if __check_builtin(is_array) +#define _LIBCUDACXX_IS_ARRAY(...) __is_array(__VA_ARGS__) +#endif // __check_builtin(is_array) + +// TODO: Clang incorrectly reports that __is_array is true for T[0]. +// Re-enable the branch once https://llvm.org/PR54705 is fixed. +#if defined(_LIBCUDACXX_COMPILER_CLANG) +#define _LIBCUDACXX_USE_IS_ARRAY_FALLBACK +#endif // _LIBCUDACXX_COMPILER_CLANG + +#if __check_builtin(is_assignable) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) +#define _LIBCUDACXX_IS_ASSIGNABLE(...) __is_assignable(__VA_ARGS__) +#endif // __check_builtin(is_assignable) + +#if __check_builtin(is_base_of) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_BASE_OF(...) __is_base_of(__VA_ARGS__) +#endif // __check_builtin(is_base_of) + +#if __check_builtin(is_class) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_CLASS(...) __is_class(__VA_ARGS__) +#endif // __check_builtin(is_class) + +#if __check_builtin(is_constructible) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 800) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_CONSTRUCTIBLE(...) __is_constructible(__VA_ARGS__) +#endif // __check_builtin(is_constructible) + +#if __check_builtin(is_convertible_to) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_CONVERTIBLE_TO(...) __is_convertible_to(__VA_ARGS__) +#endif // __check_builtin(is_convertible_to) + +#if __check_builtin(is_destructible) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) +#define _LIBCUDACXX_IS_DESTRUCTIBLE(...) __is_destructible(__VA_ARGS__) +#endif // __check_builtin(is_destructible) + +#if __check_builtin(is_empty) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_EMPTY(...) __is_empty(__VA_ARGS__) +#endif // __check_builtin(is_empty) + +#if __check_builtin(is_enum) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_ENUM(...) __is_enum(__VA_ARGS__) +#endif // __check_builtin(is_enum) + +#if __check_builtin(is_final) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 407) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_FINAL(...) __is_final(__VA_ARGS__) +#endif // __check_builtin(is_final) + +#if __check_builtin(is_function) \ + && !defined(_LIBCUDACXX_COMPILER_NVCC) +#define _LIBCUDACXX_IS_FUNCTION(...) __is_function(__VA_ARGS__) +#endif // __check_builtin(is_function) + +#if __check_builtin(is_literal_type) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 406) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_LITERAL(...) __is_literal_type(__VA_ARGS__) +#endif // __check_builtin(is_literal_type) + +#if __check_builtin(is_lvalue_reference) +#define _LIBCUDACXX_IS_LVALUE_REFERENCE(...) __is_lvalue_reference(__VA_ARGS__) +#endif // __check_builtin(is_lvalue_reference) + +#if defined(_LIBCUDACXX_CUDACC_BELOW_11_3) +#define _LIBCUDACXX_USE_IS_LVALUE_REFERENCE_FALLBACK +#endif // nvcc < 11.3 + +#if __check_builtin(is_nothrow_assignable) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_NOTHROW_ASSIGNABLE(...) __is_nothrow_assignable(__VA_ARGS__) +#endif // __check_builtin(is_nothrow_assignable) + +#if __check_builtin(is_nothrow_constructible) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_NOTHROW_CONSTRUCTIBLE(...) __is_nothrow_constructible(__VA_ARGS__) +#endif // __check_builtin(is_nothrow_constructible) + +#if __check_builtin(is_nothrow_destructible) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_NOTHROW_DESTRUCTIBLE(...) __is_nothrow_destructible(__VA_ARGS__) +#endif // __check_builtin(is_nothrow_destructible) + +#if __check_builtin(is_object) +#define _LIBCUDACXX_IS_OBJECT(...) __is_object(__VA_ARGS__) +#endif // __check_builtin(is_object) + +#if defined(_LIBCUDACXX_CUDACC_BELOW_11_3) +#define _LIBCUDACXX_USE_IS_OBJECT_FALLBACK +#endif // nvcc < 11.3 + +#if __check_builtin(is_pod) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_POD(...) __is_pod(__VA_ARGS__) +#endif // __check_builtin(is_pod) + +// libstdc++ defines this as a function, breaking functionality +#if 0 // __check_builtin(is_pointer) +#define _LIBCUDACXX_IS_POINTER(...) __is_pointer(__VA_ARGS__) +#endif // __check_builtin(is_pointer) + +#if __check_builtin(is_polymorphic) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_POLYMORPHIC(...) __is_polymorphic(__VA_ARGS__) +#endif // __check_builtin(is_polymorphic) + +#if __check_builtin(is_reference) +#define _LIBCUDACXX_IS_REFERENCE(...) __is_reference(__VA_ARGS__) +#endif // __check_builtin(is_reference) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(is_referenceable) +#define _LIBCUDACXX_IS_REFERENCEABLE(...) __is_referenceable(__VA_ARGS__) +#endif // __check_builtin(is_referenceable) + +#if __check_builtin(is_rvalue_reference) +#define _LIBCUDACXX_IS_RVALUE_REFERENCE(...) __is_rvalue_reference(__VA_ARGS__) +#endif // __check_builtin(is_rvalue_reference) + +#if __check_builtin(is_same) \ + && !defined(_LIBCUDACXX_COMPILER_NVCC) +#define _LIBCUDACXX_IS_SAME(...) __is_same(__VA_ARGS__) +#endif // __check_builtin(is_same) + +// libstdc++ defines this as a function, breaking functionality +#if 0 // __check_builtin(is_scalar) +#define _LIBCUDACXX_IS_SCALAR(...) __is_scalar(__VA_ARGS__) +#endif // __check_builtin(is_scalar) + +// libstdc++ defines this as a function, breaking functionality +#if 0 // __check_builtin(is_signed) +#define _LIBCUDACXX_IS_SIGNED(...) __is_signed(__VA_ARGS__) +#endif // __check_builtin(is_signed) + +#if __check_builtin(is_standard_layout) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 407) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_STANDARD_LAYOUT(...) __is_standard_layout(__VA_ARGS__) +#endif // __check_builtin(is_standard_layout) + +#if __check_builtin(is_trivial) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 405) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_TRIVIAL(...) __is_trivial(__VA_ARGS__) +#endif // __check_builtin(is_trivial) + +#if __check_builtin(is_trivially_assignable) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 501) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_TRIVIALLY_ASSIGNABLE(...) __is_trivially_assignable(__VA_ARGS__) +#endif // __check_builtin(is_trivially_assignable) + +#if __check_builtin(is_trivially_constructible) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 501) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_TRIVIALLY_CONSTRUCTIBLE(...) __is_trivially_constructible(__VA_ARGS__) +#endif // __check_builtin(is_trivially_constructible) + +#if __check_builtin(is_trivially_copyable) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 501) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_TRIVIALLY_COPYABLE(...) __is_trivially_copyable(__VA_ARGS__) +#endif // __check_builtin(is_trivially_copyable) + +#if __check_builtin(is_trivially_destructible) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) +#define _LIBCUDACXX_IS_TRIVIALLY_DESTRUCTIBLE(...) __is_trivially_destructible(__VA_ARGS__) +#endif // __check_builtin(is_trivially_destructible) + +#if __check_builtin(is_union) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_UNION(...) __is_union(__VA_ARGS__) +#endif // __check_builtin(is_union) + +#if __check_builtin(is_unsigned) +#define _LIBCUDACXX_IS_UNSIGNED(...) __is_unsigned(__VA_ARGS__) +#endif // __check_builtin(is_unsigned) + +#if defined(_LIBCUDACXX_CUDACC_BELOW_11_3) +#define _LIBCUDACXX_USE_IS_UNSIGNED_FALLBACK +#endif // nvcc < 11.3 + +// libstdc++ defines this as a function, breaking functionality +#if 0 // __check_builtin(is_void) +#define _LIBCUDACXX_IS_VOID(...) __is_void(__VA_ARGS__) +#endif // __check_builtin(is_void) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(make_signed) +#define _LIBCUDACXX_MAKE_SIGNED(...) __make_signed(__VA_ARGS__) +#endif // __check_builtin(make_signed) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(make_unsigned) +#define _LIBCUDACXX_MAKE_UNSIGNED(...) __make_unsigned(__VA_ARGS__) +#endif // __check_builtin(make_unsigned) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_all_extents) +#define _LIBCUDACXX_REMOVE_ALL_EXTENTS(...) __remove_all_extents(__VA_ARGS__) +#endif // __check_builtin(remove_all_extents) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_const) +#define _LIBCUDACXX_REMOVE_CONST(...) __remove_const(__VA_ARGS__) +#endif // __check_builtin(remove_const) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_cv) +#define _LIBCUDACXX_REMOVE_CV(...) __remove_cv(__VA_ARGS__) +#endif // __check_builtin(remove_cv) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_cvref) +#define _LIBCUDACXX_REMOVE_CVREF(...) __remove_cvref(__VA_ARGS__) +#endif // __check_builtin(remove_cvref) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_extent) +#define _LIBCUDACXX_REMOVE_EXTENT(...) __remove_extent(__VA_ARGS__) +#endif // __check_builtin(remove_extent) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_pointer) +#define _LIBCUDACXX_REMOVE_POINTER(...) __remove_pointer(__VA_ARGS__) +#endif // __check_builtin(remove_pointer) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_reference_t) +#define _LIBCUDACXX_REMOVE_REFERENCE_T(...) __remove_reference_t(__VA_ARGS__) +#endif // __check_builtin(remove_reference_t) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_volatile) +#define _LIBCUDACXX_REMOVE_VOLATILE(...) __remove_volatile(__VA_ARGS__) +#endif // __check_builtin(remove_volatile) + +#if __check_builtin(underlying_type) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 407) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_UNDERLYING_TYPE(...) __underlying_type(__VA_ARGS__) +#endif // __check_builtin(underlying_type) + +#define _LIBCUDACXX_TOSTRING2(_STR) #_STR +#define _LIBCUDACXX_TOSTRING(_STR) _LIBCUDACXX_TOSTRING2(_STR) +#if defined(_LIBCUDACXX_CUDACC) +# if defined(__NVCC_DIAG_PRAGMA_SUPPORT__) +# if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) __pragma(_LIBCUDACXX_TOSTRING(nv_diag_suppress _WARNING)) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) __pragma(_LIBCUDACXX_TOSTRING(nv_diag_default _WARNING)) +# else // ^^^ MSVC ^^^ / vvv not MSVC +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) \ + _Pragma(_LIBCUDACXX_TOSTRING(nv_diagnostic push)) \ + _Pragma(_LIBCUDACXX_TOSTRING(nv_diag_suppress _WARNING)) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) _Pragma(_LIBCUDACXX_TOSTRING(nv_diagnostic pop)) +# endif // not MSVC +# elif defined(_LIBCUDACXX_COMPILER_NVHPC) +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) \ + _Pragma(_LIBCUDACXX_TOSTRING(diagnostic push)) \ + _Pragma(_LIBCUDACXX_TOSTRING(diag_suppress _WARNING)) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) _Pragma(_LIBCUDACXX_TOSTRING(diagnostic pop)) +# else // _LIBCUDACXX_CUDACC_BELOW_11_3 +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) _Pragma(_LIBCUDACXX_TOSTRING(diag_suppress _WARNING)) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) _Pragma(_LIBCUDACXX_TOSTRING(diag_default _WARNING)) +# endif // !__NVCC_DIAG_PRAGMA_SUPPORT__ +#else // ^^^ _LIBCUDACXX_CUDACC ^^^ / vvv other compiler vvv +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) +#endif // other compilers + +#if defined(_LIBCUDACXX_COMPILER_CLANG) + +// _LIBCUDACXX_ALTERNATE_STRING_LAYOUT is an old name for +// _LIBCUDACXX_ABI_ALTERNATE_STRING_LAYOUT left here for backward compatibility. +#if defined(_LIBCUDACXX_ALTERNATE_STRING_LAYOUT) +#define _LIBCUDACXX_ABI_ALTERNATE_STRING_LAYOUT +#endif + +#if __cplusplus < 201103L +typedef __char16_t char16_t; +typedef __char32_t char32_t; +#endif + +#if !(__has_feature(cxx_strong_enums)) +#define _LIBCUDACXX_HAS_NO_STRONG_ENUMS +#endif + +#if !(__has_feature(cxx_lambdas)) +#define _LIBCUDACXX_HAS_NO_LAMBDAS +#endif + +#if !(__has_feature(cxx_nullptr)) +# if (__has_extension(cxx_nullptr) || __has_keyword(__nullptr)) && defined(_LIBCUDACXX_ABI_ALWAYS_USE_CXX11_NULLPTR) +# define nullptr __nullptr +# else +# define _LIBCUDACXX_HAS_NO_NULLPTR +# endif +#endif + +#if !(__has_feature(cxx_rvalue_references)) +#define _LIBCUDACXX_HAS_NO_RVALUE_REFERENCES +#endif + +#if !(__has_feature(cxx_auto_type)) +#define _LIBCUDACXX_HAS_NO_AUTO_TYPE +#endif + +#if !(__has_feature(cxx_variadic_templates)) +#define _LIBCUDACXX_HAS_NO_VARIADICS +#endif + +#if !(__has_feature(cxx_generalized_initializers)) +#define _LIBCUDACXX_HAS_NO_GENERALIZED_INITIALIZERS +#endif + +// Objective-C++ features (opt-in) +#if __has_feature(objc_arc) +#define _LIBCUDACXX_HAS_OBJC_ARC +#endif + +#if __has_feature(objc_arc_weak) +#define _LIBCUDACXX_HAS_OBJC_ARC_WEAK +#endif + +#if !(__has_feature(cxx_relaxed_constexpr)) +#define _LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR +#endif + +#if !(__has_feature(cxx_variable_templates)) +#define _LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES +#endif + +#if !(__has_feature(cxx_noexcept)) +#define _LIBCUDACXX_HAS_NO_NOEXCEPT +#endif + +// Allow for build-time disabling of unsigned integer sanitization +#if !defined(_LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK) && __has_attribute(no_sanitize) +#define _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) +#endif + +#define _LIBCUDACXX_DISABLE_EXTENSION_WARNING __extension__ + +#elif defined(_LIBCUDACXX_COMPILER_GCC) + +// FIXME: GCC 8.0 supports this trait, but it has a bug. +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91592 +// https://godbolt.org/z/IljfIw +#define _LIBCUDACXX_USE_IS_ASSIGNABLE_FALLBACK + + +// Determine if GCC supports relaxed constexpr +#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L +#define _LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR +#endif + +// GCC 5 supports variable templates +#if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L +#define _LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES +#endif + +#if _GNUC_VER < 600 +#define _LIBCUDACXX_GCC_MATH_IN_STD +#endif + +// NVCC cannot properly handle some deductions occuring within NOEXCEPT +// C++17 mode causes reference instatiation errors in tuple +#if (_GNUC_VER >= 702 && _GNUC_VER <= 805) +#if defined(_LIBCUDACXX_COMPILER_NVCC) && _LIBCUDACXX_STD_VER == 17 +#define _LIBCUDACXX_NO_TUPLE_NOEXCEPT +#endif +#endif + +#define _LIBCUDACXX_DISABLE_EXTENSION_WARNING __extension__ + +#elif defined(_LIBCUDACXX_COMPILER_MSVC) + +#define _LIBCUDACXX_WARNING(x) __pragma(message(__FILE__ "(" _LIBCUDACXX_TOSTRING(__LINE__) ") : warning note: " x)) + +// https://github.com/microsoft/STL/blob/master/stl/inc/yvals_core.h#L353 +// warning C4100: 'quack': unreferenced formal parameter +// warning C4127: conditional expression is constant +// warning C4180: qualifier applied to function type has no meaning; ignored +// warning C4197: 'purr': top-level volatile in cast is ignored +// warning C4324: 'roar': structure was padded due to alignment specifier +// warning C4455: literal suffix identifiers that do not start with an underscore are reserved +// warning C4503: 'hum': decorated name length exceeded, name was truncated +// warning C4522: 'woof' : multiple assignment operators specified +// warning C4668: 'meow' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' +// warning C4800: 'boo': forcing value to bool 'true' or 'false' (performance warning) +// warning C4996: 'meow': was declared deprecated +#define _LIBCUDACXX_MSVC_DISABLED_WARNINGS \ + 4100 \ + 4127 \ + 4180 \ + 4197 \ + 4296 \ + 4324 \ + 4455 \ + 4503 \ + 4522 \ + 4668 \ + 4800 \ + 4996 \ + /**/ + +#if _MSC_VER < 1900 +#error "MSVC versions prior to Visual Studio 2015 are not supported" +#endif + +// MSVC implemented P0030R1 in 15.7, only available under C++17 +#if _MSC_VER < 1914 +#define _LIBCUDACXX_NO_HOST_CPP17_HYPOT +#endif + +#if _MSC_VER < 1920 +#define _LIBCUDACXX_HAS_NO_NOEXCEPT_SFINAE +#define _LIBCUDACXX_HAS_NO_LOGICAL_METAFUNCTION_ALIASES +#endif + +// MSVC exposed __iso_volatile intrinsics beginning on 1924 for x86 +#if _MSC_VER < 1924 + #define _LIBCUDACXX_MSVC_HAS_NO_ISO_INTRIN +#endif + +#if _LIBCUDACXX_STD_VER < 14 +#define _LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR +#define _LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES +#endif + +#define _LIBCUDACXX_WEAK + +#define _LIBCUDACXX_HAS_NO_VECTOR_EXTENSION + +#define _LIBCUDACXX_DISABLE_EXTENSION_WARNING + +#elif defined(_LIBCUDACXX_COMPILER_IBM) + +#define _ATTRIBUTE(x) __attribute__((x)) + +#define _LIBCUDACXX_HAS_NO_UNICODE_CHARS +#define _LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES + +#if defined(_AIX) +#define __MULTILOCALE_API +#endif + +#define _LIBCUDACXX_HAS_NO_VECTOR_EXTENSION + +#elif defined(_LIBCUDACXX_COMPILER_NVRTC) || defined(_LIBCUDACXX_COMPILER_NVHPC) + +#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L +#define _LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR +#endif + +#if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L +#define _LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES +#endif + +#define _LIBCUDACXX_DISABLE_EXTENSION_WARNING + +#endif // _LIBCUDACXX_COMPILER_[CLANG|GCC|MSVC|IBM|NVRTC] + +#if defined(_LIBCUDACXX_COMPILER_NVHPC) && !defined(__cuda_std__) +// Forcefully disable visibility controls when used as the standard library with NVC++. +// TODO: reevaluate. +#define _LIBCUDACXX_HIDE_FROM_ABI +#ifndef _LIBCUDACXX_DISABLE_EXTERN_TEMPLATE +#define _LIBCUDACXX_DISABLE_EXTERN_TEMPLATE +#endif +#endif + +#ifndef _LIBCUDACXX_FREESTANDING +#if defined(__cuda_std__) \ + || !defined(__STDC_HOSTED__) +# define _LIBCUDACXX_FREESTANDING +#endif +#endif // !_LIBCUDACXX_FREESTANDING + +#ifndef _LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_COMPILER_NVHPC) && !defined(__cuda_std__)) +# define _LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS +#endif +#endif // _LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS + +#ifndef _LIBCUDACXX_HAS_CUDA_ATOMIC_EXT +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_CUDA_ATOMIC_EXT +#endif +#endif // _LIBCUDACXX_HAS_CUDA_ATOMIC_EXT + +#ifndef _LIBCUDACXX_HAS_EXTERNAL_ATOMIC_IMP +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_EXTERNAL_ATOMIC_IMP +#endif +#endif // _LIBCUDACXX_HAS_EXTERNAL_ATOMIC_IMP + +#ifndef _LIBCUDACXX_HAS_NO_ASAN +#if defined(_LIBCUDACXX_COMPILER_GCC) +# if !defined(__SANITIZE_ADDRESS__) +# define _LIBCUDACXX_HAS_NO_ASAN +# endif // !__SANITIZE_ADDRESS__ +#elif defined(_LIBCUDACXX_COMPILER_CLANG) +# if !__has_feature(address_sanitizer) +# define _LIBCUDACXX_HAS_NO_ASAN +# endif // !__has_feature(address_sanitizer) +#else +# define _LIBCUDACXX_HAS_NO_ASAN +#endif // _LIBCUDACXX_COMPILER[MSVC|IBM|NVHPC|NVRTC] +#endif // _LIBCUDACXX_HAS_NO_ASAN + +#ifndef _LIBCUDACXX_HAS_NO_CXX20_CHRONO_LITERALS +#if defined(__cuda_std__) \ + || (defined(_LIBCUDACXX_COMPILER_CLANG) && _LIBCUDACXX_CLANG_VER < 800) +# define _LIBCUDACXX_HAS_NO_CXX20_CHRONO_LITERALS +#endif // __cuda_std__ +#endif // _LIBCUDACXX_HAS_NO_CXX20_CHRONO_LITERALS + +#ifndef _LIBCUDACXX_HAS_NO_INT128 +#if defined(_LIBCUDACXX_COMPILER_MSVC) \ + || (defined(_LIBCUDACXX_COMPILER_NVRTC) && !defined(__CUDACC_RTC_INT128__)) \ + || (defined(_LIBCUDACXX_COMPILER_NVCC) && (_LIBCUDACXX_CUDACC_VER < 1105000)) \ + || !defined(__SIZEOF_INT128__) +# define _LIBCUDACXX_HAS_NO_INT128 +#endif +#endif // !_LIBCUDACXX_HAS_NO_INT128 + +#ifndef _LIBCUDACXX_HAS_NO_LONG_DOUBLE +#if defined(_LIBCUDACXX_CUDACC) +# define _LIBCUDACXX_HAS_NO_LONG_DOUBLE +#endif +#endif // _LIBCUDACXX_HAS_NO_LONG_DOUBLE + +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +#if __has_cpp_attribute(msvc::no_unique_address) +// MSVC implements [[no_unique_address]] as a silent no-op currently. +// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) +// However, MSVC implements [[msvc::no_unique_address]] which does what +// [[no_unique_address]] is supposed to do, in general. + +// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or +// [[msvc::no_unique_address]] though. If/when it does implement +// [[msvc::no_unique_address]], this should be preferred though. +# define _LIBCUDACXX_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] +#elif defined(_LIBCUDACXX_CUDACC_BELOW_11_3) \ + || (__has_cpp_attribute(no_unique_address) < 201803L) +# define _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +# define _LIBCUDACXX_NO_UNIQUE_ADDRESS +#elif __has_cpp_attribute(no_unique_address) +# define _LIBCUDACXX_NO_UNIQUE_ADDRESS [[no_unique_address]] +#else +# define _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +# define _LIBCUDACXX_NO_UNIQUE_ADDRESS +// Note that this can be replaced by #error as soon as clang-cl +// implements msvc::no_unique_address, since there should be no C++20 +// compiler that doesn't support one of the two attributes at that point. +// We generally don't want to use this macro outside of C++20-only code, +// because using it conditionally in one language version only would make +// the ABI inconsistent. +#endif +#endif // _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + +#ifndef _LIBCUDACXX_HAS_NO_MONOTONIC_CLOCK +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_NO_MONOTONIC_CLOCK +#endif +#endif // _LIBCUDACXX_HAS_NO_MONOTONIC_CLOCK + +#ifndef _LIBCUDACXX_HAS_NO_PLATFORM_WAIT +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_NO_PLATFORM_WAIT +#endif +#endif // _LIBCUDACXX_HAS_NO_PLATFORM_WAIT + +#ifndef _LIBCUDACXX_HAS_NO_PRAGMA_PUSH_POP_MACRO +#if (defined(_LIBCUDACXX_COMPILER_MSVC) && _MSC_VER < 1920) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || defined(_LIBCUDACXX_COMPILER_IBM) +#define _LIBCUDACXX_HAS_NO_PRAGMA_PUSH_POP_MACRO +#endif +#endif // _LIBCUDACXX_HAS_NO_PRAGMA_PUSH_POP_MACRO + +#ifndef _LIBCUDACXX_HAS_NO_THREAD_CONTENTION_TABLE +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_NO_THREAD_CONTENTION_TABLE +#endif +#endif // _LIBCUDACXX_HAS_NO_THREAD_CONTENTION_TABLE + +#ifndef _LIBCUDACXX_HAS_NO_TREE_BARRIER +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_NO_TREE_BARRIER +#endif +#endif // _LIBCUDACXX_HAS_NO_TREE_BARRIER + +#ifndef _LIBCUDACXX_HAS_NO_WCHAR_H +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_NO_WCHAR_H +#endif +#endif // _LIBCUDACXX_HAS_NO_WCHAR_H + +#ifndef _LIBCUDACXX_NO_EXCEPTIONS +#if defined(__cuda_std__) \ + || (defined(_LIBCUDACXX_COMPILER_CLANG) && !(__has_feature(cxx_exceptions))) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && !__EXCEPTIONS) +# define _LIBCUDACXX_NO_EXCEPTIONS +#endif +#endif // !_LIBCUDACXX_NO_EXCEPTIONS + +// Try to find out if RTTI is disabled. +// g++ and cl.exe have RTTI on by default and define a macro when it is. +#ifndef _LIBCUDACXX_NO_RTTI +#if defined(__cuda_std__) \ + || (defined(_LIBCUDACXX_COMPILER_CLANG) && !(__has_feature(cxx_rtti))) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && !defined(__GXX_RTTI)) \ + || (defined(_LIBCUDACXX_COMPILER_MSVC) && !defined(_CPPRTTI)) +# define _LIBCUDACXX_NO_RTTI +#endif +#endif // !_LIBCUDACXX_NO_RTTI + +#ifndef _LIBCUDACXX_NODEBUG_TYPE +#if defined(__cuda_std__) +# define _LIBCUDACXX_NODEBUG_TYPE +#elif __has_attribute(__nodebug__) \ + && (defined(_LIBCUDACXX_COMPILER_CLANG) && _LIBCUDACXX_CLANG_VER >= 1210) +# define _LIBCUDACXX_NODEBUG_TYPE __attribute__((nodebug)) +#else +# define _LIBCUDACXX_NODEBUG_TYPE +#endif +#endif // !_LIBCUDACXX_NODEBUG_TYPE + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_NORETURN __declspec(noreturn) +#elif __has_feature(cxx_attributes) +# define _LIBCUDACXX_NORETURN [[noreturn]] +#else +# define _LIBCUDACXX_NORETURN __attribute__ ((noreturn)) +#endif + +#if defined(_LIBCUDACXX_OBJECT_FORMAT_COFF) + +#ifdef _DLL +# define _LIBCUDACXX_CRT_FUNC __declspec(dllimport) +#else +# define _LIBCUDACXX_CRT_FUNC +#endif + +#if defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_DLL_VIS +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS +# define _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS +# define _LIBCUDACXX_OVERRIDABLE_FUNC_VIS +# define _LIBCUDACXX_EXPORTED_FROM_ABI +#elif defined(_LIBCUDACXX_BUILDING_LIBRARY) +# define _LIBCUDACXX_DLL_VIS __declspec(dllexport) +# if defined(__MINGW32__) +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS _LIBCUDACXX_DLL_VIS +# define _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS +# else +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS +# define _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCUDACXX_DLL_VIS +# endif +# define _LIBCUDACXX_OVERRIDABLE_FUNC_VIS _LIBCUDACXX_DLL_VIS +# define _LIBCUDACXX_EXPORTED_FROM_ABI __declspec(dllexport) +#else +# define _LIBCUDACXX_DLL_VIS __declspec(dllimport) +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS _LIBCUDACXX_DLL_VIS +# define _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS +# define _LIBCUDACXX_OVERRIDABLE_FUNC_VIS +# define _LIBCUDACXX_EXPORTED_FROM_ABI __declspec(dllimport) +#endif + +#define _LIBCUDACXX_TYPE_VIS _LIBCUDACXX_DLL_VIS +#define _LIBCUDACXX_FUNC_VIS _LIBCUDACXX_DLL_VIS +#define _LIBCUDACXX_EXCEPTION_ABI _LIBCUDACXX_DLL_VIS +#define _LIBCUDACXX_HIDDEN +#define _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS +#define _LIBCUDACXX_TEMPLATE_VIS +#define _LIBCUDACXX_ENUM_VIS + +#endif // defined(_LIBCUDACXX_OBJECT_FORMAT_COFF) + +#ifndef _LIBCUDACXX_HIDDEN +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_HIDDEN __attribute__ ((__visibility__("hidden"))) +# else +# define _LIBCUDACXX_HIDDEN +# endif +#endif + +#ifndef _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +// The inline should be removed once PR32114 is resolved +# define _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCUDACXX_HIDDEN +# else +# define _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_FUNC_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_FUNC_VIS __attribute__ ((__visibility__("default"))) +# else +# define _LIBCUDACXX_FUNC_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_TYPE_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_TYPE_VIS __attribute__ ((__visibility__("default"))) +# else +# define _LIBCUDACXX_TYPE_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_TEMPLATE_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# if __has_attribute(__type_visibility__) +# define _LIBCUDACXX_TEMPLATE_VIS __attribute__ ((__type_visibility__("default"))) +# else +# define _LIBCUDACXX_TEMPLATE_VIS __attribute__ ((__visibility__("default"))) +# endif +# else +# define _LIBCUDACXX_TEMPLATE_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_EXPORTED_FROM_ABI +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_EXPORTED_FROM_ABI __attribute__((__visibility__("default"))) +# else +# define _LIBCUDACXX_EXPORTED_FROM_ABI +# endif +#endif + +#ifndef _LIBCUDACXX_OVERRIDABLE_FUNC_VIS +#define _LIBCUDACXX_OVERRIDABLE_FUNC_VIS _LIBCUDACXX_FUNC_VIS +#endif + +#ifndef _LIBCUDACXX_EXCEPTION_ABI +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_EXCEPTION_ABI __attribute__ ((__visibility__("default"))) +# else +# define _LIBCUDACXX_EXCEPTION_ABI +# endif +#endif + +#ifndef _LIBCUDACXX_ENUM_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) +# define _LIBCUDACXX_ENUM_VIS __attribute__ ((__type_visibility__("default"))) +# else +# define _LIBCUDACXX_ENUM_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS __attribute__ ((__visibility__("default"))) +# else +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS +#define _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS +#endif + +#if __has_attribute(internal_linkage) +# define _LIBCUDACXX_INTERNAL_LINKAGE __attribute__ ((internal_linkage)) +#else +# define _LIBCUDACXX_INTERNAL_LINKAGE _LIBCUDACXX_ALWAYS_INLINE +#endif + +#if __has_attribute(exclude_from_explicit_instantiation) +# define _LIBCUDACXX_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__ ((__exclude_from_explicit_instantiation__)) +#else + // Try to approximate the effect of exclude_from_explicit_instantiation + // (which is that entities are not assumed to be provided by explicit + // template instantiations in the dylib) by always inlining those entities. +# define _LIBCUDACXX_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCUDACXX_ALWAYS_INLINE +#endif + +#ifndef _LIBCUDACXX_HIDE_FROM_ABI_PER_TU +# ifndef _LIBCUDACXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT +# define _LIBCUDACXX_HIDE_FROM_ABI_PER_TU 0 +# else +# define _LIBCUDACXX_HIDE_FROM_ABI_PER_TU 1 +# endif +#endif + +#ifndef _LIBCUDACXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT +# ifdef _LIBCUDACXX_OBJECT_FORMAT_COFF // Windows binaries can't merge typeinfos. +# define _LIBCUDACXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT 0 +#else +// TODO: This isn't strictly correct on ELF platforms due to llvm.org/PR37398 +// And we should consider defaulting to OFF. +# define _LIBCUDACXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT 1 +#endif +#endif + +#ifndef _LIBCUDACXX_HIDE_FROM_ABI +# if _LIBCUDACXX_HIDE_FROM_ABI_PER_TU +# define _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_HIDDEN _LIBCUDACXX_INTERNAL_LINKAGE +# else +# define _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_HIDDEN _LIBCUDACXX_EXCLUDE_FROM_EXPLICIT_INSTANTIATION +# endif +#endif + +#ifdef _LIBCUDACXX_BUILDING_LIBRARY +# if _LIBCUDACXX_ABI_VERSION > 1 +# define _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1 _LIBCUDACXX_HIDE_FROM_ABI +# else +# define _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1 +# endif +#else +# define _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1 _LIBCUDACXX_HIDE_FROM_ABI +#endif + +#ifdef _LIBCUDACXX_CUDACC +# define _LIBCUDACXX_HOST __host__ +# define _LIBCUDACXX_DEVICE __device__ +# define _LIBCUDACXX_HOST_DEVICE __host__ __device__ +# define _LIBCUDACXX_FORCE_INLINE __forceinline__ +#else // ^^^ _LIBCUDACXX_CUDACC ^^^ / vvv !_LIBCUDACXX_CUDACC +# define _LIBCUDACXX_HOST +# define _LIBCUDACXX_DEVICE +# define _LIBCUDACXX_HOST_DEVICE +# define _LIBCUDACXX_FORCE_INLINE +#endif // !_LIBCUDACXX_CUDACC + +// Just so we can migrate to the new macros gradually. + +#ifdef __cuda_std__ +# define _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_HOST_DEVICE +#else +# define _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_HIDE_FROM_ABI +#endif // __cuda_std__ + +#define _LIBCUDACXX_CONCAT1(_LIBCUDACXX_X,_LIBCUDACXX_Y) _LIBCUDACXX_X##_LIBCUDACXX_Y +#define _LIBCUDACXX_CONCAT(_LIBCUDACXX_X,_LIBCUDACXX_Y) _LIBCUDACXX_CONCAT1(_LIBCUDACXX_X,_LIBCUDACXX_Y) + +#ifndef _LIBCUDACXX_ABI_NAMESPACE +#ifdef __cuda_std__ +# define _LIBCUDACXX_ABI_NAMESPACE _LIBCUDACXX_CONCAT(__,_LIBCUDACXX_CUDA_ABI_VERSION) +#else +# define _LIBCUDACXX_ABI_NAMESPACE _LIBCUDACXX_CONCAT(__,_LIBCUDACXX_ABI_VERSION) +#endif // __cuda_std__ +#endif // _LIBCUDACXX_ABI_NAMESPACE + +#ifdef __cuda_std__ +# define _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION namespace cuda { namespace std { +# define _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION } } +# define _CUDA_VSTD cuda::std::_LIBCUDACXX_ABI_NAMESPACE +# define _CUDA_VRANGES cuda::std::ranges::_LIBCUDACXX_ABI_NAMESPACE +#else +# define _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION namespace std { +# define _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION } +# define _CUDA_VSTD std::_LIBCUDACXX_ABI_NAMESPACE +# define _CUDA_VRANGES std::ranges::_LIBCUDACXX_ABI_NAMESPACE +#endif + +#ifdef __cuda_std__ +#define _LIBCUDACXX_BEGIN_NAMESPACE_CUDA namespace cuda { inline namespace _LIBCUDACXX_ABI_NAMESPACE { +#define _LIBCUDACXX_END_NAMESPACE_CUDA } } +#define _LIBCUDACXX_BEGIN_NAMESPACE_CUDA_DEVICE namespace cuda { namespace device { inline namespace _LIBCUDACXX_ABI_NAMESPACE { +#define _LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE } } } +#endif + +// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. +#define _LIBCUDACXX_BEGIN_NAMESPACE_STD _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION inline namespace _LIBCUDACXX_ABI_NAMESPACE { +#define _LIBCUDACXX_END_NAMESPACE_STD } _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION + +#ifndef __cuda_std__ +_LIBCUDACXX_BEGIN_NAMESPACE_STD _LIBCUDACXX_END_NAMESPACE_STD +#endif + +#define _LIBCUDACXX_BEGIN_NAMESPACE_RANGES _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION namespace ranges { inline namespace _LIBCUDACXX_ABI_NAMESPACE { +#define _LIBCUDACXX_END_NAMESPACE_RANGES } } _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION + +#if !defined(__cuda_std__) +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES _LIBCUDACXX_END_NAMESPACE_RANGES +#endif + +#if _LIBCUDACXX_STD_VER > 17 +#define _LIBCUDACXX_BEGIN_NAMESPACE_RANGES_ABI inline namespace __cxx20 { +#else +#define _LIBCUDACXX_BEGIN_NAMESPACE_RANGES_ABI inline namespace __cxx17 { +#endif +#define _LIBCUDACXX_END_NAMESPACE_RANGES_ABI } + +#define _LIBCUDACXX_BEGIN_NAMESPACE_CPO(_CPO) namespace _CPO { _LIBCUDACXX_BEGIN_NAMESPACE_RANGES_ABI +#define _LIBCUDACXX_END_NAMESPACE_CPO } } + +#if _LIBCUDACXX_STD_VER >= 17 +#define _LIBCUDACXX_BEGIN_NAMESPACE_FILESYSTEM \ + _LIBCUDACXX_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem { +#else +#define _LIBCUDACXX_BEGIN_NAMESPACE_FILESYSTEM \ + _LIBCUDACXX_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem { +#endif + +#define _LIBCUDACXX_END_NAMESPACE_FILESYSTEM \ + _LIBCUDACXX_END_NAMESPACE_STD } } + +#define _CUDA_VSTD_FS _CUDA_VSTD::__fs::filesystem + +#ifndef _LIBCUDACXX_PREFERRED_OVERLOAD +# if __has_attribute(__enable_if__) +# define _LIBCUDACXX_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, ""))) +# endif +#endif + +#ifndef _LIBCUDACXX_HAS_NO_NOEXCEPT +# define _NOEXCEPT noexcept +# define _NOEXCEPT_(x) noexcept(x) +#else +# define _NOEXCEPT throw() +# define _NOEXCEPT_(x) +#endif + +#ifdef _LIBCUDACXX_HAS_NO_UNICODE_CHARS +typedef unsigned short char16_t; +typedef unsigned int char32_t; +#endif // _LIBCUDACXX_HAS_NO_UNICODE_CHARS + +#ifdef _LIBCUDACXX_CXX03_LANG +# define static_assert(...) _Static_assert(__VA_ARGS__) +# define decltype(...) __decltype(__VA_ARGS__) +#endif // _LIBCUDACXX_CXX03_LANG + +#ifdef _LIBCUDACXX_CXX03_LANG +# define _LIBCUDACXX_CONSTEXPR +#else +# define _LIBCUDACXX_CONSTEXPR constexpr +#endif + +#ifdef _LIBCUDACXX_CXX03_LANG +# define _LIBCUDACXX_DEFAULT {} +#else +# define _LIBCUDACXX_DEFAULT = default; +#endif + +#ifdef _LIBCUDACXX_CXX03_LANG +# define _LIBCUDACXX_EQUAL_DELETE +#else +# define _LIBCUDACXX_EQUAL_DELETE = delete +#endif + +#if defined(_LIBCUDACXX_COMPILER_GCC) \ + || defined(_LIBCUDACXX_COMPILER_CLANG) +# define _LIBCUDACXX_NOALIAS __attribute__((__malloc__)) +#else +# define _LIBCUDACXX_NOALIAS +#endif + +#if __has_feature(cxx_explicit_conversions) \ + || defined(_LIBCUDACXX_COMPILER_IBM) \ + || defined(_LIBCUDACXX_COMPILER_GCC) \ + || defined(_LIBCUDACXX_COMPILER_CLANG) +# define _LIBCUDACXX_EXPLICIT explicit +#else +# define _LIBCUDACXX_EXPLICIT +#endif + +#if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete) +#define _LIBCUDACXX_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE +#endif + +#ifdef _LIBCUDACXX_HAS_NO_STRONG_ENUMS +# define _LIBCUDACXX_DECLARE_STRONG_ENUM(x) struct _LIBCUDACXX_TYPE_VIS x { enum __lx +# define _LIBCUDACXX_DECLARE_STRONG_ENUM_EPILOG(x) \ + __lx __v_; \ + _LIBCUDACXX_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \ + _LIBCUDACXX_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ + _LIBCUDACXX_INLINE_VISIBILITY operator int() const {return __v_;} \ + }; +#else // _LIBCUDACXX_HAS_NO_STRONG_ENUMS +# define _LIBCUDACXX_DECLARE_STRONG_ENUM(x) enum class _LIBCUDACXX_ENUM_VIS x +# define _LIBCUDACXX_DECLARE_STRONG_ENUM_EPILOG(x) +#endif // _LIBCUDACXX_HAS_NO_STRONG_ENUMS + +#ifdef _LIBCUDACXX_DEBUG +# if _LIBCUDACXX_DEBUG == 0 +# define _LIBCUDACXX_DEBUG_LEVEL 1 +# elif _LIBCUDACXX_DEBUG == 1 +# define _LIBCUDACXX_DEBUG_LEVEL 2 +# else +# error Supported values for _LIBCUDACXX_DEBUG are 0 and 1 +# endif +# if !defined(_LIBCUDACXX_BUILDING_LIBRARY) +# define _LIBCUDACXX_EXTERN_TEMPLATE(...) +# endif +#endif + +#ifdef _LIBCUDACXX_DISABLE_EXTERN_TEMPLATE +#define _LIBCUDACXX_EXTERN_TEMPLATE(...) +#define _LIBCUDACXX_EXTERN_TEMPLATE2(...) +#endif + +#ifndef _LIBCUDACXX_EXTERN_TEMPLATE +#define _LIBCUDACXX_EXTERN_TEMPLATE(...) extern template __VA_ARGS__; +#endif + +#ifndef _LIBCUDACXX_EXTERN_TEMPLATE2 +#define _LIBCUDACXX_EXTERN_TEMPLATE2(...) extern template __VA_ARGS__; +#endif + +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCUDACXX_MSVCRT_LIKE) || \ + defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__) +#define _LIBCUDACXX_LOCALE__L_EXTENSIONS 1 +#endif + +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +// Most unix variants have catopen. These are the specific ones that don't. +# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) +# define _LIBCUDACXX_HAS_CATOPEN 1 +# endif +#endif + +#ifdef __FreeBSD__ +#define _DECLARE_C99_LDBL_MATH 1 +#endif + +#if defined(_LIBCUDACXX_ABI_MICROSOFT) && !defined(_LIBCUDACXX_NO_VCRUNTIME) +# define _LIBCUDACXX_DEFER_NEW_TO_VCRUNTIME +#endif + +// If we are getting operator new from the MSVC CRT, then allocation overloads +// for align_val_t were added in 19.12, aka VS 2017 version 15.3. +#if defined(_LIBCUDACXX_MSVCRT) && defined(_LIBCUDACXX_COMPILER_MSVC) && _MSC_VER < 1912 +# define _LIBCUDACXX_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +#elif defined(_LIBCUDACXX_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) + // We're deferring to Microsoft's STL to provide aligned new et al. We don't + // have it unless the language feature test macro is defined. +# define _LIBCUDACXX_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +#endif + +#if defined(__APPLE__) +# if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \ + defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) +# define __MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ +# endif +#endif // defined(__APPLE__) + +#if !defined(_LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION) && \ + (defined(_LIBCUDACXX_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \ + (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)) +# define _LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION +#endif + +#if defined(__APPLE__) || defined(__FreeBSD__) +#define _LIBCUDACXX_HAS_DEFAULTRUNELOCALE +#endif + +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__) +#define _LIBCUDACXX_WCTYPE_IS_MASK +#endif + +#if _LIBCUDACXX_STD_VER <= 17 || !defined(__cpp_char8_t) +#define _LIBCUDACXX_NO_HAS_CHAR8_T +#endif + +// Deprecation macros. +// +// Deprecations warnings are always enabled, except when users explicitly opt-out +// by defining _LIBCUDACXX_DISABLE_DEPRECATION_WARNINGS. +// NVCC 11.1 and 11.2 are broken with the deprecated attribute, so disable it +#if !defined(_LIBCUDACXX_DISABLE_DEPRECATION_WARNINGS) \ + && !defined(_LIBCUDACXX_CUDACC_BELOW_11_3) +# if __has_attribute(deprecated) +# define _LIBCUDACXX_DEPRECATED __attribute__ ((deprecated)) +# elif _LIBCUDACXX_STD_VER > 11 +# define _LIBCUDACXX_DEPRECATED [[deprecated]] +# else +# define _LIBCUDACXX_DEPRECATED +# endif +#else +# define _LIBCUDACXX_DEPRECATED +#endif + +#if !defined(_LIBCUDACXX_CXX03_LANG) +# define _LIBCUDACXX_DEPRECATED_IN_CXX11 _LIBCUDACXX_DEPRECATED +#else +# define _LIBCUDACXX_DEPRECATED_IN_CXX11 +#endif + +#if _LIBCUDACXX_STD_VER >= 14 +# define _LIBCUDACXX_DEPRECATED_IN_CXX14 _LIBCUDACXX_DEPRECATED +#else +# define _LIBCUDACXX_DEPRECATED_IN_CXX14 +#endif + +#if _LIBCUDACXX_STD_VER >= 17 +# define _LIBCUDACXX_DEPRECATED_IN_CXX17 _LIBCUDACXX_DEPRECATED +#else +# define _LIBCUDACXX_DEPRECATED_IN_CXX17 +#endif + +#if _LIBCUDACXX_STD_VER <= 11 +# define _LIBCUDACXX_EXPLICIT_AFTER_CXX11 +#else +# define _LIBCUDACXX_EXPLICIT_AFTER_CXX11 explicit +#endif + +#if _LIBCUDACXX_STD_VER > 11 && !defined(_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR) +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 constexpr +#else +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +#endif + +#if _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR) +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 constexpr +#else +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +#endif + +#if _LIBCUDACXX_STD_VER > 17 && !defined(_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR) +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 constexpr +#else +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +#endif + +// Macros to enter and leave a state where deprecation warnings are suppressed. +#if defined(_LIBCUDACXX_COMPILER_CLANG) || defined(_LIBCUDACXX_COMPILER_GCC) +# define _LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +# define _LIBCUDACXX_SUPPRESS_DEPRECATED_POP \ + _Pragma("GCC diagnostic pop") +#else +# define _LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH +# define _LIBCUDACXX_SUPPRESS_DEPRECATED_POP +#endif + +// The _LIBCUDACXX_NODISCARD_ATTRIBUTE should only be used to define other +// NODISCARD macros to the correct attribute. +#if __has_cpp_attribute(nodiscard) || (defined(_LIBCUDACXX_COMPILER_MSVC) && _LIBCUDACXX_STD_VER > 14) +# define _LIBCUDACXX_NODISCARD_ATTRIBUTE [[nodiscard]] +#elif defined(_LIBCUDACXX_COMPILER_CLANG) && !defined(_LIBCUDACXX_CXX03_LANG) +# define _LIBCUDACXX_NODISCARD_ATTRIBUTE [[clang::warn_unused_result]] +#else +// We can't use GCC's [[gnu::warn_unused_result]] and +// __attribute__((warn_unused_result)), because GCC does not silence them via +// (void) cast. +# define _LIBCUDACXX_NODISCARD_ATTRIBUTE +#endif + +# ifdef _LIBCUDACXX_COMPILER_CLANG +# define _LIBCUDACXX_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") +# define _LIBCUDACXX_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") +# define _LIBCUDACXX_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCUDACXX_TOSTRING(clang diagnostic ignored str)) +# define _LIBCUDACXX_GCC_DIAGNOSTIC_IGNORED(str) +# elif defined(_LIBCUDACXX_COMPILER_GCC) +# define _LIBCUDACXX_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") +# define _LIBCUDACXX_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") +# define _LIBCUDACXX_CLANG_DIAGNOSTIC_IGNORED(str) +# define _LIBCUDACXX_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCUDACXX_TOSTRING(GCC diagnostic ignored str)) +# else +# define _LIBCUDACXX_DIAGNOSTIC_PUSH +# define _LIBCUDACXX_DIAGNOSTIC_POP +# define _LIBCUDACXX_CLANG_DIAGNOSTIC_IGNORED(str) +# define _LIBCUDACXX_GCC_DIAGNOSTIC_IGNORED(str) +# endif + +// _LIBCUDACXX_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not +// specified as such as an extension. +#if defined(_LIBCUDACXX_ENABLE_NODISCARD) && !defined(_LIBCUDACXX_DISABLE_NODISCARD_EXT) +# define _LIBCUDACXX_NODISCARD_EXT _LIBCUDACXX_NODISCARD_ATTRIBUTE +#else +# define _LIBCUDACXX_NODISCARD_EXT +#endif + +#if !defined(_LIBCUDACXX_DISABLE_NODISCARD_AFTER_CXX17) && \ + (_LIBCUDACXX_STD_VER > 17 || defined(_LIBCUDACXX_ENABLE_NODISCARD)) +# define _LIBCUDACXX_NODISCARD_AFTER_CXX17 _LIBCUDACXX_NODISCARD_ATTRIBUTE +#else +# define _LIBCUDACXX_NODISCARD_AFTER_CXX17 +#endif + +#if _LIBCUDACXX_STD_VER > 14 && defined(__cpp_inline_variables) && (__cpp_inline_variables >= 201606L) +# define _LIBCUDACXX_INLINE_VAR inline +#else +# define _LIBCUDACXX_INLINE_VAR +#endif + +#ifdef _LIBCUDACXX_HAS_NO_RVALUE_REFERENCES +# define _LIBCUDACXX_EXPLICIT_MOVE(x) _CUDA_VSTD::move(x) +#else +# define _LIBCUDACXX_EXPLICIT_MOVE(x) (x) +#endif + +#ifndef _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +#if defined(_LIBCUDACXX_DEBUG) || defined(_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR) +#define _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +#else +#define _LIBCUDACXX_CONSTEXPR_IF_NODEBUG constexpr +#endif +#endif + +#if __has_attribute(no_destroy) +# define _LIBCUDACXX_NO_DESTROY __attribute__((__no_destroy__)) +#else +# define _LIBCUDACXX_NO_DESTROY +#endif + +#ifndef _LIBCUDACXX_HAS_NO_ASAN +extern "C" _LIBCUDACXX_FUNC_VIS void __sanitizer_annotate_contiguous_container( + const void *, const void *, const void *, const void *); +#endif + +#ifndef _LIBCUDACXX_WEAK +#define _LIBCUDACXX_WEAK __attribute__((__weak__)) +#endif + +// Redefine some macros for internal use +#if defined(__cuda_std__) +# undef _LIBCUDACXX_FUNC_VIS +# define _LIBCUDACXX_FUNC_VIS _LIBCUDACXX_INLINE_VISIBILITY +# undef _LIBCUDACXX_TYPE_VIS +# define _LIBCUDACXX_TYPE_VIS +#endif // __cuda_std__ + +// Thread API +#ifndef _LIBCUDACXX_HAS_THREAD_API_EXTERNAL +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || defined(__EMSCRIPTEN__) +# define _LIBCUDACXX_HAS_THREAD_API_EXTERNAL +#endif +#endif // _LIBCUDACXX_HAS_THREAD_API_EXTERNAL + +#ifndef _LIBCUDACXX_HAS_THREAD_API_CUDA +#if defined(__cuda_std__) \ + && (defined(__CUDA_ARCH__) || defined(__EMSCRIPTEN__)) +# define _LIBCUDACXX_HAS_THREAD_API_CUDA +#endif // __cuda_std__ +#endif // _LIBCUDACXX_HAS_THREAD_API_CUDA + +#ifndef _LIBCUDACXX_HAS_THREAD_API_WIN32 +#if defined(_LIBCUDACXX_COMPILER_MSVC) \ + && !defined(_LIBCUDACXX_HAS_THREAD_API_CUDA) +# define _LIBCUDACXX_HAS_THREAD_API_WIN32 +#endif +#endif // _LIBCUDACXX_HAS_THREAD_API_WIN32 + +#if !defined(_LIBCUDACXX_HAS_NO_THREADS) \ + && !defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) \ + && !defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) \ + && !defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) +# if defined(__FreeBSD__) || \ + defined(__Fuchsia__) || \ + defined(__wasi__) || \ + defined(__NetBSD__) || \ + defined(__linux__) || \ + defined(__GNU__) || \ + defined(__APPLE__) || \ + defined(__CloudABI__) || \ + defined(__sun__) || \ + (defined(__MINGW32__) && __has_include()) +# define _LIBCUDACXX_HAS_THREAD_API_PTHREAD +# elif defined(_LIBCUDACXX_WIN32API) +# define _LIBCUDACXX_HAS_THREAD_API_WIN32 +# else +# define _LIBCUDACXX_UNSUPPORTED_THREAD_API +# endif // _LIBCUDACXX_HAS_THREAD_API +#endif // _LIBCUDACXX_HAS_NO_THREADS + +#if defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) +#if defined(__ANDROID__) && __ANDROID_API__ >= 30 +#define _LIBCUDACXX_HAS_COND_CLOCKWAIT +#elif defined(_LIBCUDACXX_GLIBC_PREREQ) +#if _LIBCUDACXX_GLIBC_PREREQ(2, 30) +#define _LIBCUDACXX_HAS_COND_CLOCKWAIT +#endif +#endif +#endif + +#if defined(_LIBCUDACXX_HAS_NO_THREADS) && defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) +#error _LIBCUDACXX_HAS_THREAD_API_PTHREAD may only be defined when \ + _LIBCUDACXX_HAS_NO_THREADS is not defined. +#endif + +#if defined(_LIBCUDACXX_HAS_NO_THREADS) && defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) +#error _LIBCUDACXX_HAS_THREAD_API_EXTERNAL may not be defined when \ + _LIBCUDACXX_HAS_NO_THREADS is defined. +#endif + +#if defined(__STDCPP_THREADS__) && defined(_LIBCUDACXX_HAS_NO_THREADS) +#error _LIBCUDACXX_HAS_NO_THREADS cannot be set when __STDCPP_THREADS__ is set. +#endif + +#if !defined(_LIBCUDACXX_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) +#define __STDCPP_THREADS__ 1 +#endif + +// The glibc and Bionic implementation of pthreads implements +// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 +// mutexes have no destroy mechanism. +// +// This optimization can't be performed on Apple platforms, where +// pthread_mutex_destroy can allow the kernel to release resources. +// See https://llvm.org/D64298 for details. +// +// TODO(EricWF): Enable this optimization on Bionic after speaking to their +// respective stakeholders. +#if (defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \ + || defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) +# define _LIBCUDACXX_HAS_TRIVIAL_MUTEX_DESTRUCTION +#endif + +// Destroying a condvar is a nop on Windows. +// +// This optimization can't be performed on Apple platforms, where +// pthread_cond_destroy can allow the kernel to release resources. +// See https://llvm.org/D64298 for details. +// +// TODO(EricWF): This is potentially true for some pthread implementations +// as well. +#if defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) +# define _LIBCUDACXX_HAS_TRIVIAL_CONDVAR_DESTRUCTION +#endif + +// Systems that use capability-based security (FreeBSD with Capsicum, +// Nuxi CloudABI) may only provide local filesystem access (using *at()). +// Functions like open(), rename(), unlink() and stat() should not be +// used, as they attempt to access the global filesystem namespace. +#ifdef __CloudABI__ +#define _LIBCUDACXX_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +#endif + +// CloudABI is intended for running networked services. Processes do not +// have standard input and output channels. +#ifdef __CloudABI__ +#define _LIBCUDACXX_HAS_NO_STDIN +#define _LIBCUDACXX_HAS_NO_STDOUT +#endif + +// Some systems do not provide gets() in their C library, for security reasons. +#ifndef _LIBCUDACXX_C_HAS_NO_GETS +# if defined(_LIBCUDACXX_MSVCRT) || (defined(__FreeBSD__) && __FreeBSD__ >= 13) +# define _LIBCUDACXX_C_HAS_NO_GETS +# endif +#endif + +#if defined(__BIONIC__) || defined(__CloudABI__) || \ + defined(__Fuchsia__) || defined(__wasi__) || defined(_LIBCUDACXX_HAS_MUSL_LIBC) +#define _LIBCUDACXX_PROVIDES_DEFAULT_RUNE_TABLE +#endif + +// Thread-unsafe functions such as strtok() and localtime() +// are not available. +#ifdef __CloudABI__ +#define _LIBCUDACXX_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +#endif + +// TODO: Support C11 Atomics? +// #if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) +// # define _LIBCUDACXX_HAS_C_ATOMIC_IMP +#if defined(_LIBCUDACXX_COMPILER_CLANG) +# define _LIBCUDACXX_HAS_GCC_ATOMIC_IMP +#elif defined(_LIBCUDACXX_COMPILER_GCC) || defined(_LIBCUDACXX_COMPILER_NVHPC) +# define _LIBCUDACXX_HAS_GCC_ATOMIC_IMP +#elif defined(_LIBCUDACXX_COMPILER_NVHPC) +# define _LIBCUDACXX_HAS_GCC_ATOMIC_IMP +#elif defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_HAS_MSVC_ATOMIC_IMPL +#endif + +// CUDA Atomics supersede host atomics in order to insert the host/device dispatch layer +#if defined(_LIBCUDACXX_COMPILER_NVCC) || defined(_LIBCUDACXX_COMPILER_NVRTC) || defined(_LIBCUDACXX_COMPILER_NVHPC) || defined(_LIBCUDACXX_CUDACC) +# define _LIBCUDACXX_HAS_CUDA_ATOMIC_IMPL +#endif + +#if (!defined(_LIBCUDACXX_HAS_C_ATOMIC_IMP) && \ + !defined(_LIBCUDACXX_HAS_GCC_ATOMIC_IMP) && \ + !defined(_LIBCUDACXX_HAS_EXTERNAL_ATOMIC_IMP)) \ + || defined(_LIBCUDACXX_HAS_NO_THREADS) +# define _LIBCUDACXX_HAS_NO_ATOMIC_HEADER +#else +# ifdef __cuda_std__ +# undef _LIBCUDACXX_ATOMIC_FLAG_TYPE +# define _LIBCUDACXX_ATOMIC_FLAG_TYPE int +# endif +# ifndef _LIBCUDACXX_ATOMIC_FLAG_TYPE +# define _LIBCUDACXX_ATOMIC_FLAG_TYPE bool +# endif +# ifdef _LIBCUDACXX_FREESTANDING +# define _LIBCUDACXX_ATOMIC_ONLY_USE_BUILTINS +# endif +#endif + +#ifndef _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +#define _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +#endif + +#if defined(_LIBCUDACXX_ENABLE_THREAD_SAFETY_ANNOTATIONS) +# if defined(_LIBCUDACXX_COMPILER_CLANG) && __has_attribute(acquire_capability) +// Work around the attribute handling in clang. When both __declspec and +// __attribute__ are present, the processing goes awry preventing the definition +// of the types. +# if !defined(_LIBCUDACXX_OBJECT_FORMAT_COFF) +# define _LIBCUDACXX_HAS_THREAD_SAFETY_ANNOTATIONS +# endif +# endif +#endif + +#if __has_attribute(require_constant_initialization) +# define _LIBCUDACXX_SAFE_STATIC __attribute__((__require_constant_initialization__)) +#else +# define _LIBCUDACXX_SAFE_STATIC +#endif + +#if !defined(_LIBCUDACXX_HAS_NO_OFF_T_FUNCTIONS) +# if defined(_LIBCUDACXX_MSVCRT) || defined(_NEWLIB_VERSION) +# define _LIBCUDACXX_HAS_NO_OFF_T_FUNCTIONS +# endif +#endif + +#if __has_attribute(diagnose_if) && !defined(_LIBCUDACXX_DISABLE_ADDITIONAL_DIAGNOSTICS) +# define _LIBCUDACXX_DIAGNOSE_WARNING(...) \ + __attribute__((diagnose_if(__VA_ARGS__, "warning"))) +# define _LIBCUDACXX_DIAGNOSE_ERROR(...) \ + __attribute__((diagnose_if(__VA_ARGS__, "error"))) +#else +# define _LIBCUDACXX_DIAGNOSE_WARNING(...) +# define _LIBCUDACXX_DIAGNOSE_ERROR(...) +#endif + +// Use a function like macro to imply that it must be followed by a semicolon +#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough) +# define _LIBCUDACXX_FALLTHROUGH() [[fallthrough]] +#elif defined(_LIBCUDACXX_COMPILER_NVRTC) +# define _LIBCUDACXX_FALLTHROUGH() ((void)0) +#elif __has_cpp_attribute(clang::fallthrough) +# define _LIBCUDACXX_FALLTHROUGH() [[clang::fallthrough]] +#elif defined(_LIBCUDACXX_COMPILER_NVHPC) +# define _LIBCUDACXX_FALLTHROUGH() +#elif __has_attribute(fallthough) || _GNUC_VER >= 700 +# define _LIBCUDACXX_FALLTHROUGH() __attribute__((__fallthrough__)) +#else +# define _LIBCUDACXX_FALLTHROUGH() ((void)0) +#endif + +#if __has_attribute(__nodebug__) +#define _LIBCUDACXX_NODEBUG __attribute__((__nodebug__)) +#else +#define _LIBCUDACXX_NODEBUG +#endif + +# if __has_attribute(__preferred_name__) +# define _LIBCUDACXX_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) +# else +# define _LIBCUDACXX_PREFERRED_NAME(x) +# endif + +#if defined(_LIBCUDACXX_ABI_MICROSOFT) && \ + (defined(_LIBCUDACXX_COMPILER_MSVC) || __has_declspec_attribute(empty_bases)) +# define _LIBCUDACXX_DECLSPEC_EMPTY_BASES __declspec(empty_bases) +#else +# define _LIBCUDACXX_DECLSPEC_EMPTY_BASES +#endif + +#if defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_FEATURES) +#define _LIBCUDACXX_ENABLE_CXX17_REMOVED_AUTO_PTR +#define _LIBCUDACXX_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS +#define _LIBCUDACXX_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE +#define _LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS +#endif // _LIBCUDACXX_ENABLE_CXX17_REMOVED_FEATURES + +#if !defined(__cpp_deduction_guides) || __cpp_deduction_guides < 201611 +#define _LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES +#endif + +#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L +#define _LIBCUDACXX_HAS_NO_COROUTINES +#endif + +// We need `is_constant_evaluated` for clang and gcc. MSVC also needs extensive rework +#if !defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) +#define _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS +#elif defined(__CUDACC_RTC__) +#define _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS +#elif defined(_MSC_VER) +#define _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS +#elif defined(_LIBCUDACXX_CUDACC_BELOW_11_8) +#define _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS +#endif + +// FIXME: Correct this macro when either (A) a feature test macro for the +// spaceship operator is provided, or (B) a compiler provides a complete +// implementation. +#define _LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR + +#define _LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS + +// The stream API was dropped and re-added in the dylib shipped on macOS +// and iOS. We can only assume the dylib to provide these definitions for +// macosx >= 10.9 and ios >= 7.0. Otherwise, the definitions are available +// from the headers, but not from the dylib. Explicit instantiation +// declarations for streams exist conditionally to this; if we provide +// an explicit instantiation declaration and we try to deploy to a dylib +// that does not provide those symbols, we'll get a load-time error. +#if !defined(_LIBCUDACXX_BUILDING_LIBRARY) && \ + ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1090) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 70000)) +# define _LIBCUDACXX_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB +#endif + +#if defined(_LIBCUDACXX_HAS_NO_PRAGMA_PUSH_POP_MACRO) +# define _LIBCUDACXX_PUSH_MACROS +# define _LIBCUDACXX_POP_MACROS +#else + // Don't warn about macro conflicts when we can restore them at the + // end of the header. +# ifndef _LIBCUDACXX_DISABLE_MACRO_CONFLICT_WARNINGS +# define _LIBCUDACXX_DISABLE_MACRO_CONFLICT_WARNINGS +# endif +# if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_PUSH_MACROS \ + __pragma(push_macro("min")) \ + __pragma(push_macro("max")) +# define _LIBCUDACXX_POP_MACROS \ + __pragma(pop_macro("min")) \ + __pragma(pop_macro("max")) +# else +# define _LIBCUDACXX_PUSH_MACROS \ + _Pragma("push_macro(\"min\")") \ + _Pragma("push_macro(\"max\")") +# define _LIBCUDACXX_POP_MACROS \ + _Pragma("pop_macro(\"min\")") \ + _Pragma("pop_macro(\"max\")") +# endif +#endif // defined(_LIBCUDACXX_HAS_NO_PRAGMA_PUSH_POP_MACRO) + +#if !defined(_LIBCUDACXX_NO_AUTO_LINK) && !defined(__cuda_std__) +# if defined(_LIBCUDACXX_ABI_MICROSOFT) && !defined(_LIBCUDACXX_BUILDING_LIBRARY) +# if defined(_DLL) +# pragma comment(lib, "c++.lib") +# else +# pragma comment(lib, "libc++.lib") +# endif +# endif // defined(_LIBCUDACXX_ABI_MICROSOFT) && !defined(_LIBCUDACXX_BUILDING_LIBRARY) +#endif // !defined(_LIBCUDACXX_NO_AUTO_LINK) + +#define _LIBCUDACXX_UNUSED_VAR(x) ((void)(x)) + +// Configures the fopen close-on-exec mode character, if any. This string will +// be appended to any mode string used by fstream for fopen/fdopen. +// +// Not all platforms support this, but it helps avoid fd-leaks on platforms that +// do. +#if defined(__BIONIC__) +# define _LIBCUDACXX_FOPEN_CLOEXEC_MODE "e" +#else +# define _LIBCUDACXX_FOPEN_CLOEXEC_MODE +#endif + +# if __has_attribute(__format__) +// The attribute uses 1-based indices for ordinary and static member functions. +// The attribute uses 2-based indices for non-static member functions. +# define _LIBCUDACXX_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ + __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) +# else +# define _LIBCUDACXX_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ +# endif + +#ifndef _LIBCUDACXX_SYS_CLOCK_DURATION +#if defined(__cuda_std__) +# define _LIBCUDACXX_SYS_CLOCK_DURATION nanoseconds +#else +# define _LIBCUDACXX_SYS_CLOCK_DURATION microseconds +#endif +#endif // _LIBCUDACXX_SYS_CLOCK_DURATION + +// There are a handful of public standard library types that are intended to +// support CTAD but don't need any explicit deduction guides to do so. This +// macro is used to mark them as such, which suppresses the +// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code +// with these classes. +#if (!defined(_LIBCUDACXX_COMPILER_GCC) || __GNUC__ > 6) \ + && _LIBCUDACXX_STD_VER >= 17 +# define _LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ + template \ + _ClassName(typename _Tag::__allow_ctad...) -> _ClassName<_Tag...> +#else +# define _LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") +#endif + +#if (defined(__CUDACC_VER_MAJOR__) && __CUDACC_VER_MAJOR__ <= 11) \ + && (defined(__CUDACC_VER_MINOR__) && __CUDACC_VER_MINOR__ <= 2) +# define _LIBCUDACXX_CONSTEXPR_GLOBAL const +#else +# define _LIBCUDACXX_CONSTEXPR_GLOBAL constexpr +#endif + +#if defined(__CUDA_ARCH__) +# define _LIBCUDACXX_CPO_ACCESSIBILITY _LIBCUDACXX_DEVICE _LIBCUDACXX_CONSTEXPR_GLOBAL +#else +# define _LIBCUDACXX_CPO_ACCESSIBILITY _LIBCUDACXX_INLINE_VAR constexpr +#endif + +#if _LIBCUDACXX_STD_VER > 14 +# define _LIBCUDACXX_TRAIT(__TRAIT, ...) __TRAIT##_v<__VA_ARGS__> +#else +# define _LIBCUDACXX_TRAIT(__TRAIT, ...) __TRAIT<__VA_ARGS__>::value +#endif + +// Older nvcc do not handle the constraint of `construct_at` in earlier std modes +// So to preserve our performance optimization we default to the unconstrained +// `__construct_at` and only in C++20 use `construct_at` +#if _LIBCUDACXX_STD_VER > 17 +# define _LIBCUDACXX_CONSTRUCT_AT(_LOCATION, ...) \ + _CUDA_VSTD::construct_at(_CUDA_VSTD::addressof(_LOCATION), __VA_ARGS__) +#else +# define _LIBCUDACXX_CONSTRUCT_AT(_LOCATION, ...) \ + _CUDA_VSTD::__construct_at(_CUDA_VSTD::addressof(_LOCATION), __VA_ARGS__) +#endif + +#if !defined(_LIBCUDACXX_DISABLE_EXEC_CHECK) +#if defined(_LIBCUDACXX_CUDACC) \ + && !defined(_LIBCUDACXX_COMPILER_NVRTC) \ + && !defined(_LIBCUDACXX_COMPILER_NVHPC_CUDA) \ + && !defined(_LIBCUDACXX_COMPILER_CLANG_CUDA) +# if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_DISABLE_EXEC_CHECK __pragma("nv_exec_check_disable") +# else // ^^^ _LIBCUDACXX_COMPILER_MSVC ^^^ / vvv !_LIBCUDACXX_COMPILER_MSVC vvv +# define _LIBCUDACXX_DISABLE_EXEC_CHECK _Pragma("nv_exec_check_disable") +# endif // !_LIBCUDACXX_COMPILER_MSVC +#else // ^^^ !NVRTC && !NVHPC-cuda && !clang-cuda ^^^ / vvv NVRTC || NVHPC-cuda || clang-cuda vvv +# define _LIBCUDACXX_DISABLE_EXEC_CHECK +#endif // NVRTC || NVHPC-cuda || clang-cuda +#endif // !_LIBCUDACXX_DISABLE_EXEC_CHECK + +#define _LIBCUDACXX_HAS_NO_INCOMPLETE_RANGES + +#endif // __cplusplus + +#endif // _LIBCUDACXX_CONFIG diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__config_site.in b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__config_site.in new file mode 100644 index 0000000000000000000000000000000000000000..ab65c9554b0b4b5697cb3baeff154a784328ea8c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__config_site.in @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_CONFIG_SITE +#define _LIBCUDACXX_CONFIG_SITE + +#cmakedefine _LIBCUDACXX_ABI_VERSION @_LIBCUDACXX_ABI_VERSION@ +#cmakedefine _LIBCUDACXX_ABI_UNSTABLE +#cmakedefine _LIBCUDACXX_ABI_FORCE_ITANIUM +#cmakedefine _LIBCUDACXX_ABI_FORCE_MICROSOFT +#cmakedefine _LIBCUDACXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT +#cmakedefine _LIBCUDACXX_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +#cmakedefine _LIBCUDACXX_HAS_NO_STDIN +#cmakedefine _LIBCUDACXX_HAS_NO_STDOUT +#cmakedefine _LIBCUDACXX_HAS_NO_THREADS +#cmakedefine _LIBCUDACXX_HAS_NO_MONOTONIC_CLOCK +#cmakedefine _LIBCUDACXX_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +#cmakedefine _LIBCUDACXX_HAS_MUSL_LIBC +#cmakedefine _LIBCUDACXX_HAS_THREAD_API_PTHREAD +#cmakedefine _LIBCUDACXX_HAS_THREAD_API_EXTERNAL +#cmakedefine _LIBCUDACXX_HAS_THREAD_API_WIN32 +#cmakedefine _LIBCUDACXX_HAS_THREAD_LIBRARY_EXTERNAL +#cmakedefine _LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS +#cmakedefine _LIBCUDACXX_NO_VCRUNTIME +#cmakedefine01 _LIBCUDACXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT +#cmakedefine _LIBCUDACXX_ABI_NAMESPACE @_LIBCUDACXX_ABI_NAMESPACE@ +#cmakedefine _LIBCUDACXX_HAS_PARALLEL_ALGORITHMS + +@_LIBCUDACXX_ABI_DEFINES@ + +#endif // _LIBCUDACXX_CONFIG_SITE diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/atomic.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/atomic.h new file mode 100644 index 0000000000000000000000000000000000000000..20249e8ffcd5dfb2dd7e2797869255fddb2b1576 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/atomic.h @@ -0,0 +1,260 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_ATOMIC_H +#define _LIBCUDACXX___CUDA_ATOMIC_H + +#ifndef __cuda_std__ +#error "<__cuda/atomic> should only be included in from " +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +using std::__detail::thread_scope; +using std::__detail::thread_scope_system; +using std::__detail::thread_scope_device; +using std::__detail::thread_scope_block; +using std::__detail::thread_scope_thread; + +namespace __detail { +using std::__detail::__thread_scope_block_tag; +using std::__detail::__thread_scope_device_tag; +using std::__detail::__thread_scope_system_tag; +} + +using memory_order = std::memory_order; + +constexpr memory_order memory_order_relaxed = std::memory_order_relaxed; +constexpr memory_order memory_order_consume = std::memory_order_consume; +constexpr memory_order memory_order_acquire = std::memory_order_acquire; +constexpr memory_order memory_order_release = std::memory_order_release; +constexpr memory_order memory_order_acq_rel = std::memory_order_acq_rel; +constexpr memory_order memory_order_seq_cst = std::memory_order_seq_cst; + +// atomic + +template +struct atomic + : public std::__atomic_base<_Tp, _Sco> +{ + typedef std::__atomic_base<_Tp, _Sco> __base; + + constexpr atomic() noexcept = default; + _LIBCUDACXX_HOST_DEVICE + constexpr atomic(_Tp __d) noexcept : __base(__d) {} + + _LIBCUDACXX_HOST_DEVICE + _Tp operator=(_Tp __d) volatile noexcept + {__base::store(__d); return __d;} + _LIBCUDACXX_HOST_DEVICE + _Tp operator=(_Tp __d) noexcept + {__base::store(__d); return __d;} + + _LIBCUDACXX_HOST_DEVICE + _Tp fetch_max(const _Tp & __op, memory_order __m = memory_order_seq_cst) volatile noexcept + { + return std::__detail::__cxx_atomic_fetch_max(&this->__a_, __op, __m); + } + + _LIBCUDACXX_HOST_DEVICE + _Tp fetch_min(const _Tp & __op, memory_order __m = memory_order_seq_cst) volatile noexcept + { + return std::__detail::__cxx_atomic_fetch_min(&this->__a_, __op, __m); + } +}; + +// atomic + +template +struct atomic<_Tp*, _Sco> + : public std::__atomic_base<_Tp*, _Sco> +{ + typedef std::__atomic_base<_Tp*, _Sco> __base; + + constexpr atomic() noexcept = default; + _LIBCUDACXX_HOST_DEVICE + constexpr atomic(_Tp* __d) noexcept : __base(__d) {} + + _LIBCUDACXX_HOST_DEVICE + _Tp* operator=(_Tp* __d) volatile noexcept + {__base::store(__d); return __d;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator=(_Tp* __d) noexcept + {__base::store(__d); return __d;} + + _LIBCUDACXX_HOST_DEVICE + _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) + volatile noexcept + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCUDACXX_HOST_DEVICE + _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) noexcept + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCUDACXX_HOST_DEVICE + _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) + volatile noexcept + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} + _LIBCUDACXX_HOST_DEVICE + _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) noexcept + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} + + _LIBCUDACXX_HOST_DEVICE + _Tp* operator++(int) volatile noexcept {return fetch_add(1);} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator++(int) noexcept {return fetch_add(1);} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator--(int) volatile noexcept {return fetch_sub(1);} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator--(int) noexcept {return fetch_sub(1);} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator++() volatile noexcept {return fetch_add(1) + 1;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator++() noexcept {return fetch_add(1) + 1;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator--() volatile noexcept {return fetch_sub(1) - 1;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator--() noexcept {return fetch_sub(1) - 1;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator+=(ptrdiff_t __op) volatile noexcept {return fetch_add(__op) + __op;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator+=(ptrdiff_t __op) noexcept {return fetch_add(__op) + __op;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator-=(ptrdiff_t __op) volatile noexcept {return fetch_sub(__op) - __op;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator-=(ptrdiff_t __op) noexcept {return fetch_sub(__op) - __op;} +}; + +// atomic_ref + +template +struct atomic_ref + : public std::__atomic_base_ref<_Tp, _Sco> +{ + typedef std::__atomic_base_ref<_Tp, _Sco> __base; + + _LIBCUDACXX_HOST_DEVICE + constexpr atomic_ref(_Tp& __d) noexcept : __base(__d) {} + + _LIBCUDACXX_HOST_DEVICE + _Tp operator=(_Tp __d) const volatile noexcept + {__base::store(__d); return __d;} + _LIBCUDACXX_HOST_DEVICE + _Tp operator=(_Tp __d) const noexcept + {__base::store(__d); return __d;} + + _LIBCUDACXX_HOST_DEVICE + _Tp fetch_max(const _Tp & __op, memory_order __m = memory_order_seq_cst) const volatile noexcept + { + return std::__detail::__cxx_atomic_fetch_max(&this->__a_, __op, __m); + } + + _LIBCUDACXX_HOST_DEVICE + _Tp fetch_min(const _Tp & __op, memory_order __m = memory_order_seq_cst) const volatile noexcept + { + return std::__detail::__cxx_atomic_fetch_min(&this->__a_, __op, __m); + } +}; + +// atomic_ref + +template +struct atomic_ref<_Tp*, _Sco> + : public std::__atomic_base_ref<_Tp*, _Sco> +{ + typedef std::__atomic_base_ref<_Tp*, _Sco> __base; + + _LIBCUDACXX_HOST_DEVICE + constexpr atomic_ref(_Tp*& __d) noexcept : __base(__d) {} + + _LIBCUDACXX_HOST_DEVICE + _Tp* operator=(_Tp* __d) const volatile noexcept + {__base::store(__d); return __d;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator=(_Tp* __d) const noexcept + {__base::store(__d); return __d;} + + _LIBCUDACXX_HOST_DEVICE + _Tp* fetch_add(ptrdiff_t __op, + memory_order __m = memory_order_seq_cst) const volatile noexcept + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCUDACXX_HOST_DEVICE + _Tp* fetch_add(ptrdiff_t __op, + memory_order __m = memory_order_seq_cst) const noexcept + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCUDACXX_HOST_DEVICE + _Tp* fetch_sub(ptrdiff_t __op, + memory_order __m = memory_order_seq_cst) const volatile noexcept + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} + _LIBCUDACXX_HOST_DEVICE + _Tp* fetch_sub(ptrdiff_t __op, + memory_order __m = memory_order_seq_cst) const noexcept + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} + + _LIBCUDACXX_HOST_DEVICE + _Tp* operator++(int) const volatile noexcept {return fetch_add(1);} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator++(int) const noexcept {return fetch_add(1);} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator--(int) const volatile noexcept {return fetch_sub(1);} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator--(int) const noexcept {return fetch_sub(1);} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator++() const volatile noexcept {return fetch_add(1) + 1;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator++() const noexcept {return fetch_add(1) + 1;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator--() const volatile noexcept {return fetch_sub(1) - 1;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator--() const noexcept {return fetch_sub(1) - 1;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator+=(ptrdiff_t __op) const volatile noexcept {return fetch_add(__op) + __op;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator+=(ptrdiff_t __op) const noexcept {return fetch_add(__op) + __op;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator-=(ptrdiff_t __op) const volatile noexcept {return fetch_sub(__op) - __op;} + _LIBCUDACXX_HOST_DEVICE + _Tp* operator-=(ptrdiff_t __op) const noexcept {return fetch_sub(__op) - __op;} +}; + +inline _LIBCUDACXX_HOST_DEVICE void atomic_thread_fence(memory_order __m, thread_scope _Scope = thread_scope::thread_scope_system) { + NV_DISPATCH_TARGET( + NV_IS_DEVICE, ( + switch(_Scope) { + case thread_scope::thread_scope_system: + std::__detail::__atomic_thread_fence_cuda((int)__m, __detail::__thread_scope_system_tag()); + break; + case thread_scope::thread_scope_device: + std::__detail::__atomic_thread_fence_cuda((int)__m, __detail::__thread_scope_device_tag()); + break; + case thread_scope::thread_scope_block: + std::__detail::__atomic_thread_fence_cuda((int)__m, __detail::__thread_scope_block_tag()); + break; + // Atomics scoped to themselves do not require fencing + case thread_scope::thread_scope_thread: + break; + } + ), + NV_IS_HOST, ( + (void) _Scope; + std::atomic_thread_fence(__m); + ) + ) +} + +inline _LIBCUDACXX_HOST_DEVICE void atomic_signal_fence(memory_order __m) { + std::atomic_signal_fence(__m); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _LIBCUDACXX___CUDA_ATOMIC_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/atomic_prelude.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/atomic_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..1333435b9591c0f149a72701fedcf04df85f814a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/atomic_prelude.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_ATOMIC_PRELUDE_H +#define _LIBCUDACXX___CUDA_ATOMIC_PRELUDE_H + +#ifndef __cuda_std__ +#error "<__cuda/atomic_prelude> should only be included in from " +#endif // __cuda_std__ + +#ifndef _LIBCUDACXX_COMPILER_NVRTC + #include "../cassert" // TRANSITION: Fix transitive includes + #include + static_assert(ATOMIC_BOOL_LOCK_FREE == 2, ""); + static_assert(ATOMIC_CHAR_LOCK_FREE == 2, ""); + static_assert(ATOMIC_CHAR16_T_LOCK_FREE == 2, ""); + static_assert(ATOMIC_CHAR32_T_LOCK_FREE == 2, ""); + static_assert(ATOMIC_WCHAR_T_LOCK_FREE == 2, ""); + static_assert(ATOMIC_SHORT_LOCK_FREE == 2, ""); + static_assert(ATOMIC_INT_LOCK_FREE == 2, ""); + static_assert(ATOMIC_LONG_LOCK_FREE == 2, ""); + static_assert(ATOMIC_LLONG_LOCK_FREE == 2, ""); + static_assert(ATOMIC_POINTER_LOCK_FREE == 2, ""); + #undef ATOMIC_BOOL_LOCK_FREE + #undef ATOMIC_BOOL_LOCK_FREE + #undef ATOMIC_CHAR_LOCK_FREE + #undef ATOMIC_CHAR16_T_LOCK_FREE + #undef ATOMIC_CHAR32_T_LOCK_FREE + #undef ATOMIC_WCHAR_T_LOCK_FREE + #undef ATOMIC_SHORT_LOCK_FREE + #undef ATOMIC_INT_LOCK_FREE + #undef ATOMIC_LONG_LOCK_FREE + #undef ATOMIC_LLONG_LOCK_FREE + #undef ATOMIC_POINTER_LOCK_FREE + #undef ATOMIC_FLAG_INIT + #undef ATOMIC_VAR_INIT +#endif // _LIBCUDACXX_COMPILER_NVRTC + +// pre-define lock free query for heterogeneous compatibility +#ifndef _LIBCUDACXX_ATOMIC_IS_LOCK_FREE +#define _LIBCUDACXX_ATOMIC_IS_LOCK_FREE(__x) (__x <= 8) +#endif + +#ifndef _LIBCUDACXX_COMPILER_NVRTC +#include +#include +#endif // _LIBCUDACXX_COMPILER_NVRTC + +#endif // _LIBCUDACXX___CUDA_ATOMIC_PRELUDE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/barrier.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/barrier.h new file mode 100644 index 0000000000000000000000000000000000000000..90a13f658f5ec283a2534379aa3e88dd98ca1ff8 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/barrier.h @@ -0,0 +1,826 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_BARRIER_H +#define _LIBCUDACXX___CUDA_BARRIER_H + +#ifndef __cuda_std__ +#error "<__cuda/barrier> should only be included in from " +#endif // __cuda_std__ + +#if defined(__CUDA_MINIMUM_ARCH__) && __CUDA_MINIMUM_ARCH__ < 700 +# error "CUDA synchronization primitives are only supported for sm_70 and up." +#endif + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_OFFSET_IS_ZERO(type, member) !(&(((type *)0)->member)) +#else +#define _LIBCUDACXX_OFFSET_IS_ZERO(type, member) !offsetof(type, member) +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +// foward declaration required for memcpy_async, pipeline "sync" defined here +template +class pipeline; + +template<_CUDA_VSTD::size_t _Alignment> +struct aligned_size_t { + static constexpr _CUDA_VSTD::size_t align = _Alignment; + _CUDA_VSTD::size_t value; + _LIBCUDACXX_INLINE_VISIBILITY + explicit aligned_size_t(size_t __s) : value(__s) { } + _LIBCUDACXX_INLINE_VISIBILITY + operator size_t() const { return value; } +}; + +// Type only used for logging purpose +enum async_contract_fulfillment +{ + none, + async +}; + +template +class barrier : public _CUDA_VSTD::__barrier_base<_CompletionF, _Sco> { +public: + barrier() = default; + + barrier(const barrier &) = delete; + barrier & operator=(const barrier &) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR + barrier(_CUDA_VSTD::ptrdiff_t __expected, _CompletionF __completion = _CompletionF()) + : _CUDA_VSTD::__barrier_base<_CompletionF, _Sco>(__expected, __completion) { + } + + _LIBCUDACXX_INLINE_VISIBILITY + friend void init(barrier * __b, _CUDA_VSTD::ptrdiff_t __expected) { +#if (_LIBCUDACXX_DEBUG_LEVEL >= 2) + _LIBCUDACXX_DEBUG_ASSERT(__expected >= 0); +#endif + + new (__b) barrier(__expected); + } + + _LIBCUDACXX_INLINE_VISIBILITY + friend void init(barrier * __b, _CUDA_VSTD::ptrdiff_t __expected, _CompletionF __completion) { +#if (_LIBCUDACXX_DEBUG_LEVEL >= 2) + _LIBCUDACXX_DEBUG_ASSERT(__expected >= 0); +#endif + new (__b) barrier(__expected, __completion); + } +}; + +struct __block_scope_barrier_base {}; + +_LIBCUDACXX_END_NAMESPACE_CUDA + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_DEVICE + +_LIBCUDACXX_DEVICE +inline _CUDA_VSTD::uint64_t * barrier_native_handle(barrier & b); + +_LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +template<> +class barrier : public __block_scope_barrier_base { + using __barrier_base = _CUDA_VSTD::__barrier_base<_CUDA_VSTD::__empty_completion, (int)thread_scope_block>; + __barrier_base __barrier; + + _LIBCUDACXX_DEVICE + friend inline _CUDA_VSTD::uint64_t * device::_LIBCUDACXX_ABI_NAMESPACE::barrier_native_handle(barrier & b); + +template +friend class _CUDA_VSTD::__barrier_poll_tester_phase; +template +friend class _CUDA_VSTD::__barrier_poll_tester_parity; + +public: + using arrival_token = typename __barrier_base::arrival_token; + barrier() = default; + + barrier(const barrier &) = delete; + barrier & operator=(const barrier &) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY + barrier(_CUDA_VSTD::ptrdiff_t __expected, _CUDA_VSTD::__empty_completion __completion = _CUDA_VSTD::__empty_completion()) { + static_assert(_LIBCUDACXX_OFFSET_IS_ZERO(barrier, __barrier), "fatal error: bad barrier layout"); + init(this, __expected, __completion); + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~barrier() { + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_90, ( + if (__isShared(&__barrier)) { + asm volatile ("mbarrier.inval.shared.b64 [%0];" + :: "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))) + : "memory"); + } + else if (__isClusterShared(&__barrier)) { + __trap(); + } + ), NV_PROVIDES_SM_80, ( + if (__isShared(&__barrier)) { + asm volatile ("mbarrier.inval.shared.b64 [%0];" + :: "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))) + : "memory"); + } + ) + ) + } + + _LIBCUDACXX_INLINE_VISIBILITY + friend void init(barrier * __b, _CUDA_VSTD::ptrdiff_t __expected, _CUDA_VSTD::__empty_completion __completion = _CUDA_VSTD::__empty_completion()) { + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_90, ( + if (__isShared(&__b->__barrier)) { + asm volatile ("mbarrier.init.shared.b64 [%0], %1;" + :: "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__b->__barrier))), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__expected)) + : "memory"); + } + else if (__isClusterShared(&__b->__barrier)) + { + __trap(); + } + else + { + new (&__b->__barrier) __barrier_base(__expected); + } + ), + NV_PROVIDES_SM_80, ( + if (__isShared(&__b->__barrier)) { + asm volatile ("mbarrier.init.shared.b64 [%0], %1;" + :: "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__b->__barrier))), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__expected)) + : "memory"); + } + else + { + new (&__b->__barrier) __barrier_base(__expected); + } + ), NV_ANY_TARGET, ( + new (&__b->__barrier) __barrier_base(__expected); + ) + ) + } + + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + arrival_token arrive(_CUDA_VSTD::ptrdiff_t __update = 1) { +#if (_LIBCUDACXX_DEBUG_LEVEL >= 2) + _LIBCUDACXX_DEBUG_ASSERT(__update >= 0); + _LIBCUDACXX_DEBUG_ASSERT(__expected_unit >=0); +#endif + arrival_token __token = {}; + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_90, ( + if (!__isClusterShared(&__barrier)) { + return __barrier.arrive(__update); + } + else if (!__isShared(&__barrier)) { + __trap(); + } + + asm volatile ("mbarrier.arrive.shared.b64 %0, [%1], %2;" + : "=l"(__token) + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__update)) + : "memory"); + ), NV_PROVIDES_SM_80, ( + if (!__isShared(&__barrier)) { + return __barrier.arrive(__update); + } + + // Need 2 instructions, can't finish barrier with arrive > 1 + if (__update > 1) { + asm volatile ("mbarrier.arrive.noComplete.shared.b64 %0, [%1], %2;" + : "=l"(__token) + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__update - 1)) + : "memory"); + } + asm volatile ("mbarrier.arrive.shared.b64 %0, [%1];" + : "=l"(__token) + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))) + : "memory"); + ), NV_IS_DEVICE, ( + if (!__isShared(&__barrier)) { + return __barrier.arrive(__update); + } + + unsigned int __mask = __activemask(); + unsigned int __activeA = __match_any_sync(__mask, __update); + unsigned int __activeB = __match_any_sync(__mask, reinterpret_cast<_CUDA_VSTD::uintptr_t>(&__barrier)); + unsigned int __active = __activeA & __activeB; + int __inc = __popc(__active) * __update; + + unsigned __laneid; + asm ("mov.u32 %0, %laneid;" : "=r"(__laneid)); + int __leader = __ffs(__active) - 1; + // All threads in mask synchronize here, establishing cummulativity to the __leader: + __syncwarp(__mask); + if(__leader == __laneid) + { + __token = __barrier.arrive(__inc); + } + __token = __shfl_sync(__active, __token, __leader); + ), NV_IS_HOST, ( + __token = __barrier.arrive(__update); + ) + ) + return __token; + } + +private: + + _LIBCUDACXX_INLINE_VISIBILITY + inline bool __test_wait_sm_80(arrival_token __token) const { + int32_t __ready = 0; + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_80, ( + asm volatile ("{\n\t" + ".reg .pred p;\n\t" + "mbarrier.test_wait.shared.b64 p, [%1], %2;\n\t" + "selp.b32 %0, 1, 0, p;\n\t" + "}" + : "=r"(__ready) + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))), + "l"(__token) + : "memory"); + ) + ) + return __ready; + } + + // Document de drop > uint32_t for __nanosec on public for APIs + _LIBCUDACXX_INLINE_VISIBILITY + bool __try_wait(arrival_token __token) const { + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_90, ( + int32_t __ready = 0; + if (!__isClusterShared(&__barrier)) { + return _CUDA_VSTD::__call_try_wait(__barrier, _CUDA_VSTD::move(__token)); + } + else if (!__isShared(&__barrier)) { + __trap(); + } + asm volatile ("{\n\t" + ".reg .pred p;\n\t" + "mbarrier.try_wait.shared.b64 p, [%1], %2;\n\t" + "selp.b32 %0, 1, 0, p;\n\t" + "}" + : "=r"(__ready) + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))), + "l"(__token) + : "memory"); + return __ready; + ), NV_PROVIDES_SM_80, ( + if (!__isShared(&__barrier)) { + return _CUDA_VSTD::__call_try_wait(__barrier, _CUDA_VSTD::move(__token)); + } + return __test_wait_sm_80(__token); + ), NV_ANY_TARGET, ( + return _CUDA_VSTD::__call_try_wait(__barrier, _CUDA_VSTD::move(__token)); + ) + ) + } + + // Document de drop > uint32_t for __nanosec on public for APIs + _LIBCUDACXX_INLINE_VISIBILITY + bool __try_wait(arrival_token __token, _CUDA_VSTD::chrono::nanoseconds __nanosec) const { + if (__nanosec.count() < 1) { + return __try_wait(_CUDA_VSTD::move(__token)); + } + + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_90, ( + int32_t __ready = 0; + if (!__isClusterShared(&__barrier)) { + return _CUDA_VSTD::__libcpp_thread_poll_with_backoff( + _CUDA_VSTD::__barrier_poll_tester_phase(this, _CUDA_VSTD::move(__token)), + __nanosec); + } + else if (!__isShared(&__barrier)) { + __trap(); + } + + _CUDA_VSTD::chrono::high_resolution_clock::time_point const __start = _CUDA_VSTD::chrono::high_resolution_clock::now(); + _CUDA_VSTD::chrono::nanoseconds __elapsed; + do { + const _CUDA_VSTD::uint32_t __wait_nsec = static_cast<_CUDA_VSTD::uint32_t>((__nanosec - __elapsed).count()); + asm volatile ("{\n\t" + ".reg .pred p;\n\t" + "mbarrier.try_wait.shared.b64 p, [%1], %2, %3;\n\t" + "selp.b32 %0, 1, 0, p;\n\t" + "}" + : "=r"(__ready) + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))), + "l"(__token) + "r"(__wait_nsec) + : "memory"); + __elapsed = _CUDA_VSTD::chrono::high_resolution_clock::now() - __start; + } while (!__ready && (__nanosec > __elapsed)); + return __ready; + ), NV_PROVIDES_SM_80, ( + bool __ready = 0; + if (!__isShared(&__barrier)) { + return _CUDA_VSTD::__libcpp_thread_poll_with_backoff( + _CUDA_VSTD::__barrier_poll_tester_phase(this, _CUDA_VSTD::move(__token)), + __nanosec); + } + + _CUDA_VSTD::chrono::high_resolution_clock::time_point const __start = _CUDA_VSTD::chrono::high_resolution_clock::now(); + do { + __ready = __test_wait_sm_80(__token); + } while (!__ready && + __nanosec > (_CUDA_VSTD::chrono::high_resolution_clock::now() - __start)); + return __ready; + ), NV_ANY_TARGET, ( + return _CUDA_VSTD::__libcpp_thread_poll_with_backoff( + _CUDA_VSTD::__barrier_poll_tester_phase(this, _CUDA_VSTD::move(__token)), + _CUDA_VSTD::chrono::nanoseconds(__nanosec)); + ) + ) + } + + _LIBCUDACXX_INLINE_VISIBILITY + inline bool __test_wait_parity_sm_80(bool __phase_parity) const { + uint16_t __ready = 0; + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_80, ( + asm volatile ("{" + ".reg .pred %p;" + "mbarrier.test_wait.parity.shared.b64 %p, [%1], %2;" + "selp.u16 %0, 1, 0, %p;" + "}" + : "=h"(__ready) + : "r"(static_cast(__cvta_generic_to_shared(&__barrier))), + "r"(static_cast(__phase_parity)) + : "memory"); + ) + ) + return __ready; + } + + _LIBCUDACXX_INLINE_VISIBILITY + bool __try_wait_parity(bool __phase_parity) const { + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_90, ( + if (!__isClusterShared(&__barrier)) { + return _CUDA_VSTD::__call_try_wait_parity(__barrier, __phase_parity); + } + else if (!__isShared(&__barrier)) { + __trap(); + } + int32_t __ready = 0; + + asm volatile ("{\n\t" + ".reg .pred p;\n\t" + "mbarrier.try_wait.parity.shared.b64 p, [%1], %2;\n\t" + "selp.b32 %0, 1, 0, p;\n\t" + "}" + : "=r"(__ready) + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__phase_parity)) + :); + + return __ready; + ), NV_PROVIDES_SM_80, ( + if (!__isShared(&__barrier)) { + return _CUDA_VSTD::__call_try_wait_parity(__barrier, __phase_parity); + } + + return __test_wait_parity_sm_80(__phase_parity); + ), NV_ANY_TARGET, ( + return _CUDA_VSTD::__call_try_wait_parity(__barrier, __phase_parity); + ) + ) + } + + _LIBCUDACXX_INLINE_VISIBILITY + bool __try_wait_parity(bool __phase_parity, _CUDA_VSTD::chrono::nanoseconds __nanosec) const { + if (__nanosec.count() < 1) { + return __try_wait_parity(__phase_parity); + } + + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_90, ( + int32_t __ready = 0; + if (!__isClusterShared(&__barrier)) { + return _CUDA_VSTD::__libcpp_thread_poll_with_backoff( + _CUDA_VSTD::__barrier_poll_tester_parity(this, __phase_parity), + __nanosec); + } + else if (!__isShared(&__barrier)) { + __trap(); + } + + _CUDA_VSTD::chrono::high_resolution_clock::time_point const __start = _CUDA_VSTD::chrono::high_resolution_clock::now(); + _CUDA_VSTD::chrono::nanoseconds __elapsed; + do { + const _CUDA_VSTD::uint32_t __wait_nsec = static_cast<_CUDA_VSTD::uint32_t>((__nanosec - __elapsed).count()); + asm volatile ("{\n\t" + ".reg .pred p;\n\t" + "mbarrier.try_wait.parity.shared.b64 p, [%1], %2, %3;\n\t" + "selp.b32 %0, 1, 0, p;\n\t" + "}" + : "=r"(__ready) + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__phase_parity)), + "r"(__wait_nsec) + : "memory"); + __elapsed = _CUDA_VSTD::chrono::high_resolution_clock::now() - __start; + } while (!__ready && (__nanosec > __elapsed)); + + return __ready; + ), NV_PROVIDES_SM_80, ( + bool __ready = 0; + if (!__isShared(&__barrier)) { + return _CUDA_VSTD::__libcpp_thread_poll_with_backoff( + _CUDA_VSTD::__barrier_poll_tester_parity(this, __phase_parity), + __nanosec); + } + + _CUDA_VSTD::chrono::high_resolution_clock::time_point const __start = _CUDA_VSTD::chrono::high_resolution_clock::now(); + do { + __ready = __test_wait_parity_sm_80(__phase_parity); + } while (!__ready && + __nanosec > (_CUDA_VSTD::chrono::high_resolution_clock::now() - __start)); + + return __ready; + ), NV_ANY_TARGET, ( + return _CUDA_VSTD::__libcpp_thread_poll_with_backoff( + _CUDA_VSTD::__barrier_poll_tester_parity(this, __phase_parity), + __nanosec); + ) + ) + } + +public: + _LIBCUDACXX_INLINE_VISIBILITY + void wait(arrival_token && __phase) const { + _CUDA_VSTD::__libcpp_thread_poll_with_backoff(_CUDA_VSTD::__barrier_poll_tester_phase(this, _CUDA_VSTD::move(__phase))); + } + + _LIBCUDACXX_INLINE_VISIBILITY + void wait_parity(bool __phase_parity) const { + _CUDA_VSTD::__libcpp_thread_poll_with_backoff(_CUDA_VSTD::__barrier_poll_tester_parity(this, __phase_parity)); + } + + inline _LIBCUDACXX_INLINE_VISIBILITY + void arrive_and_wait() { + wait(arrive()); + } + + _LIBCUDACXX_INLINE_VISIBILITY + void arrive_and_drop() { + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_90, ( + if (!__isClusterShared(&__barrier)) { + return __barrier.arrive_and_drop(); + } + else if (!__isShared(&__barrier)) { + __trap(); + } + + asm volatile ("mbarrier.arrive_drop.shared.b64 _, [%0];" + :: "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))) + : "memory"); + ), NV_PROVIDES_SM_80, ( + // Fallback to slowpath on device + if (!__isShared(&__barrier)) { + __barrier.arrive_and_drop(); + return; + } + + asm volatile ("mbarrier.arrive_drop.shared.b64 _, [%0];" + :: "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))) + : "memory"); + ), NV_ANY_TARGET, ( + // Fallback to slowpath on device + __barrier.arrive_and_drop(); + ) + ) + } + + _LIBCUDACXX_INLINE_VISIBILITY + static constexpr ptrdiff_t max() noexcept { + return (1 << 20) - 1; + } + + template + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + bool try_wait_for(arrival_token && __token, const _CUDA_VSTD::chrono::duration<_Rep, _Period>& __dur) { + auto __nanosec = _CUDA_VSTD::chrono::duration_cast<_CUDA_VSTD::chrono::nanoseconds>(__dur); + + return __try_wait(_CUDA_VSTD::move(__token), __nanosec); + } + + template + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + bool try_wait_until(arrival_token && __token, const _CUDA_VSTD::chrono::time_point<_Clock, _Duration>& __time) { + return try_wait_for(_CUDA_VSTD::move(__token), (__time - _Clock::now())); + } + + template + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + bool try_wait_parity_for(bool __phase_parity, const _CUDA_VSTD::chrono::duration<_Rep, _Period>& __dur) { + auto __nanosec = _CUDA_VSTD::chrono::duration_cast<_CUDA_VSTD::chrono::nanoseconds>(__dur); + + return __try_wait_parity(__phase_parity, __nanosec); + } + + template + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + bool try_wait_parity_until(bool __phase_parity, const _CUDA_VSTD::chrono::time_point<_Clock, _Duration>& __time) { + return try_wait_parity_for(__phase_parity, (__time - _Clock::now())); + } +}; + +_LIBCUDACXX_END_NAMESPACE_CUDA + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_DEVICE + +_LIBCUDACXX_DEVICE +inline _CUDA_VSTD::uint64_t * barrier_native_handle(barrier & b) { + return reinterpret_cast<_CUDA_VSTD::uint64_t *>(&b.__barrier); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +template<> +class barrier : private barrier { + using __base = barrier; + +public: + using __base::__base; + + _LIBCUDACXX_INLINE_VISIBILITY + friend void init(barrier * __b, _CUDA_VSTD::ptrdiff_t __expected, _CUDA_VSTD::__empty_completion __completion = _CUDA_VSTD::__empty_completion()) { + init(static_cast<__base *>(__b), __expected, __completion); + } + + using __base::arrive; + using __base::wait; + using __base::arrive_and_wait; + using __base::arrive_and_drop; + using __base::max; +}; + +template +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool __unused(_Ty...) {return true;} + +template +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool __unused(_Ty&) {return true;} + +template<_CUDA_VSTD::size_t _Alignment> +_LIBCUDACXX_INLINE_VISIBILITY +inline void __strided_memcpy(char * __destination, char const * __source, _CUDA_VSTD::size_t __total_size, _CUDA_VSTD::size_t __rank, _CUDA_VSTD::size_t __stride = 1) { + if (__stride == 1) { + memcpy(__destination, __source, __total_size); + } + else { + for (_CUDA_VSTD::size_t __offset = __rank * _Alignment; __offset < __total_size; __offset += __stride * _Alignment) { + memcpy(__destination + __offset, __source + __offset, _Alignment); + } + } +} + +template<_CUDA_VSTD::size_t _Alignment, bool _Large = (_Alignment > 16)> +struct __memcpy_async_impl { + _LIBCUDACXX_DEVICE static inline async_contract_fulfillment __copy(char * __destination, char const * __source, _CUDA_VSTD::size_t __total_size, _CUDA_VSTD::size_t __rank, _CUDA_VSTD::size_t __stride) { + __strided_memcpy<_Alignment>(__destination, __source, __total_size, __rank, __stride); + return async_contract_fulfillment::none; + } +}; + +template<> +struct __memcpy_async_impl<4, false> { + _LIBCUDACXX_DEVICE static inline async_contract_fulfillment __copy(char * __destination, char const * __source, _CUDA_VSTD::size_t __total_size, _CUDA_VSTD::size_t __rank, _CUDA_VSTD::size_t __stride) { + // Guard from host visibility when compiling in host only contexts + NV_IF_TARGET( + NV_IS_DEVICE, ( + for (_CUDA_VSTD::size_t __offset = __rank * 4; __offset < __total_size; __offset += __stride * 4) { + asm volatile ("cp.async.ca.shared.global [%0], [%1], 4, 4;" + :: "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__destination + __offset))), + "l"(__source + __offset) + : "memory"); + } + ) + ) + return async_contract_fulfillment::async; + } +}; + +template<> +struct __memcpy_async_impl<8, false> { + _LIBCUDACXX_DEVICE static inline async_contract_fulfillment __copy(char * __destination, char const * __source, _CUDA_VSTD::size_t __total_size, _CUDA_VSTD::size_t __rank, _CUDA_VSTD::size_t __stride) { + // Guard from host visibility when compiling in host only contexts + NV_IF_TARGET( + NV_IS_DEVICE, ( + for (_CUDA_VSTD::size_t __offset = __rank * 8; __offset < __total_size; __offset += __stride * 8) { + asm volatile ("cp.async.ca.shared.global [%0], [%1], 8, 8;" + :: "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__destination + __offset))), + "l"(__source + __offset) + : "memory"); + } + ) + ) + return async_contract_fulfillment::async; + } +}; + +template<> +struct __memcpy_async_impl<16, false> { + _LIBCUDACXX_DEVICE static inline async_contract_fulfillment __copy(char * __destination, char const * __source, _CUDA_VSTD::size_t __total_size, _CUDA_VSTD::size_t __rank, _CUDA_VSTD::size_t __stride) { + // Guard from host visibility when compiling in host only contexts + NV_IF_TARGET( + NV_IS_DEVICE, ( + for (_CUDA_VSTD::size_t __offset = __rank * 16; __offset < __total_size; __offset += __stride * 16) { + asm volatile ("cp.async.cg.shared.global [%0], [%1], 16, 16;" + :: "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__destination + __offset))), + "l"(__source + __offset) + : "memory"); + } + ) + ) + return async_contract_fulfillment::async; + } +}; + +template<_CUDA_VSTD::size_t _Alignment> +struct __memcpy_async_impl<_Alignment, true> : public __memcpy_async_impl<16, false> { }; + +struct __memcpy_arrive_on_impl { + template= thread_scope_block) && _CUDA_VSTD::is_same<_CompF, _CUDA_VSTD::__empty_completion>::value> + _LIBCUDACXX_INLINE_VISIBILITY static inline void __arrive_on(barrier<_Sco, _CompF> & __barrier, async_contract_fulfillment __is_async) { + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_90, ( + if (_Is_mbarrier && __isClusterShared(&__barrier) && !__isShared(&__barrier)) { + __trap(); + } + ) + ) + + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_80, ( + if (__is_async == async_contract_fulfillment::async) { + if (_Is_mbarrier && __isShared(&__barrier)) { + asm volatile ("cp.async.mbarrier.arrive.shared.b64 [%0];" + :: "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(&__barrier))) + : "memory"); + } + else { + asm volatile ("cp.async.wait_all;" + ::: "memory"); + } + } + ) + ) + } + + template + _LIBCUDACXX_INLINE_VISIBILITY static inline void __arrive_on(pipeline<_Sco> & __pipeline, async_contract_fulfillment __is_async) { + // pipeline does not sync on memcpy_async, defeat pipeline purpose otherwise + __unused(__pipeline); + __unused(__is_async); + } +}; + +template<_CUDA_VSTD::size_t _Native_alignment, typename _Group, typename _Sync> +_LIBCUDACXX_INLINE_VISIBILITY +void inline __memcpy_async_sm_dispatch( + _Group const & __group, char * __destination, char const * __source, + _CUDA_VSTD::size_t __size, _Sync & __sync, async_contract_fulfillment & __is_async) { + // Broken out of __memcpy_async to avoid nesting dispatches + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_80, + __is_async = __memcpy_async_impl<16>::__copy(__destination, __source, __size, __group.thread_rank(), __group.size()); + ) +} + +template<_CUDA_VSTD::size_t _Native_alignment, typename _Group, typename _Sync> +_LIBCUDACXX_INLINE_VISIBILITY +async_contract_fulfillment inline __memcpy_async( + _Group const & __group, char * __destination, char const * __source, + _CUDA_VSTD::size_t __size, _Sync & __sync) { + async_contract_fulfillment __is_async = async_contract_fulfillment::none; + + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_80, + + if (__isShared(__destination) && __isGlobal(__source)) { + if (_Native_alignment < 4) { + auto __source_address = reinterpret_cast<_CUDA_VSTD::uintptr_t>(__source); + auto __destination_address = reinterpret_cast<_CUDA_VSTD::uintptr_t>(__destination); + + // Lowest bit set will tell us what the common alignment of the three values is. + auto _Alignment = __ffs(__source_address | __destination_address | __size); + + switch (_Alignment) { + default: + __memcpy_async_sm_dispatch<_Native_alignment>(__group, __destination, __source, __size, __sync, __is_async); + case 4: __is_async = __memcpy_async_impl<8>::__copy(__destination, __source, __size, __group.thread_rank(), __group.size()); break; + case 3: __is_async = __memcpy_async_impl<4>::__copy(__destination, __source, __size, __group.thread_rank(), __group.size()); break; + case 2: // fallthrough + case 1: __is_async = __memcpy_async_impl<1>::__copy(__destination, __source, __size, __group.thread_rank(), __group.size()); break; + } + } + else { + __is_async = __memcpy_async_impl<_Native_alignment>::__copy(__destination, __source, __size, __group.thread_rank(), __group.size()); + } + } + else + { + __strided_memcpy<_Native_alignment>(__destination, __source, __size, __group.thread_rank(), __group.size()); + } + + __memcpy_arrive_on_impl::__arrive_on(__sync, __is_async); + , NV_ANY_TARGET, + __strided_memcpy<_Native_alignment>(__destination, __source, __size, __group.thread_rank(), __group.size()); + ) + + return __is_async; +} + +struct __single_thread_group { + _LIBCUDACXX_INLINE_VISIBILITY + void sync() const {} + _LIBCUDACXX_INLINE_VISIBILITY + constexpr _CUDA_VSTD::size_t size() const { return 1; }; + _LIBCUDACXX_INLINE_VISIBILITY + constexpr _CUDA_VSTD::size_t thread_rank() const { return 0; }; +}; + +template +_LIBCUDACXX_INLINE_VISIBILITY +async_contract_fulfillment memcpy_async(_Group const & __group, _Tp * __destination, _Tp const * __source, _CUDA_VSTD::size_t __size, barrier<_Sco, _CompF> & __barrier) { + // When compiling with NVCC and GCC 4.8, certain user defined types that _are_ trivially copyable are + // incorrectly classified as not trivially copyable. Remove this assertion to allow for their usage with + // memcpy_async when compiling with GCC 4.8. + // FIXME: remove the #if once GCC 4.8 is no longer supported. +#if !defined(_LIBCUDACXX_COMPILER_GCC) || _GNUC_VER > 408 + static_assert(_CUDA_VSTD::is_trivially_copyable<_Tp>::value, "memcpy_async requires a trivially copyable type"); +#endif + + return __memcpy_async(__group, reinterpret_cast(__destination), reinterpret_cast(__source), __size, __barrier); +} + +template _Alignment) ? alignof(_Tp) : _Alignment> +_LIBCUDACXX_INLINE_VISIBILITY +async_contract_fulfillment memcpy_async(_Group const & __group, _Tp * __destination, _Tp const * __source, aligned_size_t<_Alignment> __size, barrier<_Sco, _CompF> & __barrier) { + // When compiling with NVCC and GCC 4.8, certain user defined types that _are_ trivially copyable are + // incorrectly classified as not trivially copyable. Remove this assertion to allow for their usage with + // memcpy_async when compiling with GCC 4.8. + // FIXME: remove the #if once GCC 4.8 is no longer supported. +#if !defined(_LIBCUDACXX_COMPILER_GCC) || _GNUC_VER > 408 + static_assert(_CUDA_VSTD::is_trivially_copyable<_Tp>::value, "memcpy_async requires a trivially copyable type"); +#endif + + return __memcpy_async<_Larger_alignment>(__group, reinterpret_cast(__destination), reinterpret_cast(__source), __size, __barrier); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +async_contract_fulfillment memcpy_async(_Tp * __destination, _Tp const * __source, _Size __size, barrier<_Sco, _CompF> & __barrier) { + return memcpy_async(__single_thread_group{}, __destination, __source, __size, __barrier); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +async_contract_fulfillment memcpy_async(_Group const & __group, void * __destination, void const * __source, _CUDA_VSTD::size_t __size, barrier<_Sco, _CompF> & __barrier) { + return __memcpy_async<1>(__group, reinterpret_cast(__destination), reinterpret_cast(__source), __size, __barrier); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +async_contract_fulfillment memcpy_async(_Group const & __group, void * __destination, void const * __source, aligned_size_t<_Alignment> __size, barrier<_Sco, _CompF> & __barrier) { + return __memcpy_async<_Alignment>(__group, reinterpret_cast(__destination), reinterpret_cast(__source), __size, __barrier); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +async_contract_fulfillment memcpy_async(void * __destination, void const * __source, _Size __size, barrier<_Sco, _CompF> & __barrier) { + return memcpy_async(__single_thread_group{}, __destination, __source, __size, __barrier); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _LIBCUDACXX___CUDA_BARRIER_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/chrono.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/chrono.h new file mode 100644 index 0000000000000000000000000000000000000000..07a3afca7dcf9c9e873d8eab0bc204e32fde85ef --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/chrono.h @@ -0,0 +1,61 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_CHRONO_H +#define _LIBCUDACXX___CUDA_CHRONO_H + +#ifndef __cuda_std__ +#error "<__cuda/chrono> should only be included in from " +#endif // __cuda_std__ + +#include + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +namespace chrono { + +inline _LIBCUDACXX_INLINE_VISIBILITY +system_clock::time_point system_clock::now() _NOEXCEPT +{ +NV_DISPATCH_TARGET( +NV_IS_DEVICE, ( + uint64_t __time; + asm volatile("mov.u64 %0, %%globaltimer;":"=l"(__time)::); + return time_point(duration_cast(nanoseconds(__time))); +), +NV_IS_HOST, ( + return time_point(duration_cast(nanoseconds( + ::std::chrono::duration_cast<::std::chrono::nanoseconds>( + ::std::chrono::system_clock::now().time_since_epoch() + ).count() + ))); +)); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +time_t system_clock::to_time_t(const system_clock::time_point& __t) _NOEXCEPT +{ + return time_t(duration_cast(__t.time_since_epoch()).count()); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +system_clock::time_point system_clock::from_time_t(time_t __t) _NOEXCEPT +{ + return time_point(seconds(__t));; +} +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CUDA_CHRONO_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/climits_prelude.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/climits_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..5100f6e46437dc72375c562960610d16e6e6d69a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/climits_prelude.h @@ -0,0 +1,95 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_CLIMITS_PRELUDE_H +#define _LIBCUDACXX___CUDA_CLIMITS_PRELUDE_H + +#ifndef __cuda_std__ +#error "<__cuda/climits_prelude> should only be included in from " +#endif // __cuda_std__ + +#ifndef _LIBCUDACXX_COMPILER_NVRTC + #include + #include + #include +#else // ^^^ !_LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv _LIBCUDACXX_COMPILER_NVRTC vvv + #define CHAR_BIT 8 + + #define SCHAR_MIN (-128) + #define SCHAR_MAX 127 + #define UCHAR_MAX 255 + #define __CHAR_UNSIGNED__ ('\xff' > 0) // CURSED + #if __CHAR_UNSIGNED__ + #define CHAR_MIN 0 + #define CHAR_MAX UCHAR_MAX + #else + #define CHAR_MIN SCHAR_MIN + #define CHAR_MAX SCHAR_MAX + #endif + #define SHRT_MIN (-SHRT_MAX - 1) + #define SHRT_MAX 0x7fff + #define USHRT_MAX 0xffff + #define INT_MIN (-INT_MAX - 1) + #define INT_MAX 0x7fffffff + #define UINT_MAX 0xffffffff + #define LONG_MIN (-LONG_MAX - 1) + #ifdef __LP64__ + #define LONG_MAX LLONG_MAX + #define ULONG_MAX ULLONG_MAX + #else + #define LONG_MAX INT_MAX + #define ULONG_MAX UINT_MAX + #endif + #define LLONG_MIN (-LLONG_MAX - 1) + #define LLONG_MAX 0x7fffffffffffffffLL + #define ULLONG_MAX 0xffffffffffffffffUL + + #define __FLT_RADIX__ 2 + #define __FLT_MANT_DIG__ 24 + #define __FLT_DIG__ 6 + #define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F + #define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F + #define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F + #define __FLT_MIN_EXP__ (-125) + #define __FLT_MIN_10_EXP__ (-37) + #define __FLT_MAX_EXP__ 128 + #define __FLT_MAX_10_EXP__ 38 + #define __FLT_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F + #define __DBL_MANT_DIG__ 53 + #define __DBL_DIG__ 15 + #define __DBL_MIN__ 2.22507385850720138309023271733240406e-308 + #define __DBL_MAX__ 1.79769313486231570814527423731704357e+308 + #define __DBL_EPSILON__ 2.22044604925031308084726333618164062e-16 + #define __DBL_MIN_EXP__ (-1021) + #define __DBL_MIN_10_EXP__ (-307) + #define __DBL_MAX_EXP__ 1024 + #define __DBL_MAX_10_EXP__ 308 + #define __DBL_DENORM_MIN__ 4.94065645841246544176568792868221372e-324 + + template + static _LIBCUDACXX_DEVICE _LIBCUDACXX_FORCE_INLINE + _To __cowchild_cast(_From __from) + { + static_assert(sizeof(_From) == sizeof(_To), ""); + union __cast { _From __from; _To __to; }; + __cast __c; + __c.__from = __from; + return __c.__to; + } + + #define __builtin_huge_valf() __cowchild_cast(0x7f800000) + #define __builtin_nanf(__dummy) __cowchild_cast(0x7fc00000) + #define __builtin_nansf(__dummy) __cowchild_cast(0x7fa00000) + #define __builtin_huge_val() __cowchild_cast(0x7ff0000000000000) + #define __builtin_nan(__dummy) __cowchild_cast(0x7ff8000000000000) + #define __builtin_nans(__dummy) __cowchild_cast(0x7ff4000000000000) +#endif // _LIBCUDACXX_COMPILER_NVRTC + +#endif // _LIBCUDACXX___CUDA_CLIMITS_PRELUDE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/cstddef_prelude.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/cstddef_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..992288ce0fae2e2b16f31c62a8921d358da24516 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/cstddef_prelude.h @@ -0,0 +1,31 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_CSTDDEF_PRELUDE_H +#define _LIBCUDACXX___CUDA_CSTDDEF_PRELUDE_H + +#ifndef __cuda_std__ +#error "<__cuda/cstddef_prelude> should only be included in from " +#endif // __cuda_std__ + +#ifndef _LIBCUDACXX_COMPILER_NVRTC +#include +#include +#else +#define offsetof(type, member) (_CUDA_VSTD::size_t)((char*)&(((type *)0)->member) - (char*)0) +#endif // _LIBCUDACXX_COMPILER_NVRTC + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +typedef decltype(nullptr) nullptr_t; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CUDA_CSTDDEF_PRELUDE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/cstdint_prelude.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/cstdint_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..1f4b35eb301664892161214fa47564511b527187 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/cstdint_prelude.h @@ -0,0 +1,84 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_CSTDINT_PRELUDE_H +#define _LIBCUDACXX___CUDA_CSTDINT_PRELUDE_H + +#ifndef __cuda_std__ +#error "<__cuda/cstdint_prelude> should only be included in from " +#endif // __cuda_std__ + +#ifndef _LIBCUDACXX_COMPILER_NVRTC + #include +#else // ^^^ !_LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv _LIBCUDACXX_COMPILER_NVRTC vvv + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef signed short int16_t; + typedef unsigned short uint16_t; + typedef signed int int32_t; + typedef unsigned int uint32_t; + typedef signed long long int64_t; + typedef unsigned long long uint64_t; + +#define _LIBCUDACXX_ADDITIONAL_INTS(N) \ + typedef int##N##_t int_fast##N##_t; \ + typedef uint##N##_t uint_fast##N##_t; \ + typedef int##N##_t int_least##N##_t; \ + typedef uint##N##_t uint_least##N##_t + + _LIBCUDACXX_ADDITIONAL_INTS(8); + _LIBCUDACXX_ADDITIONAL_INTS(16); + _LIBCUDACXX_ADDITIONAL_INTS(32); + _LIBCUDACXX_ADDITIONAL_INTS(64); +#undef _LIBCUDACXX_ADDITIONAL_INTS + + typedef int64_t intptr_t; + typedef uint64_t uintptr_t; + typedef int64_t intmax_t; + typedef uint64_t uintmax_t; + + #define INT8_MIN SCHAR_MIN + #define INT16_MIN SHRT_MIN + #define INT32_MIN INT_MIN + #define INT64_MIN LLONG_MIN + #define INT8_MAX SCHAR_MAX + #define INT16_MAX SHRT_MAX + #define INT32_MAX INT_MAX + #define INT64_MAX LLONG_MAX + #define UINT8_MAX UCHAR_MAX + #define UINT16_MAX USHRT_MAX + #define UINT32_MAX UINT_MAX + #define UINT64_MAX ULLONG_MAX + #define INT_FAST8_MIN SCHAR_MIN + #define INT_FAST16_MIN SHRT_MIN + #define INT_FAST32_MIN INT_MIN + #define INT_FAST64_MIN LLONG_MIN + #define INT_FAST8_MAX SCHAR_MAX + #define INT_FAST16_MAX SHRT_MAX + #define INT_FAST32_MAX INT_MAX + #define INT_FAST64_MAX LLONG_MAX + #define UINT_FAST8_MAX UCHAR_MAX + #define UINT_FAST16_MAX USHRT_MAX + #define UINT_FAST32_MAX UINT_MAX + #define UINT_FAST64_MAX ULLONG_MAX + + #define INT8_C(X) ((int_least8_t)(X)) + #define INT16_C(X) ((int_least16_t)(X)) + #define INT32_C(X) ((int_least32_t)(X)) + #define INT64_C(X) ((int_least64_t)(X)) + #define UINT8_C(X) ((uint_least8_t)(X)) + #define UINT16_C(X) ((uint_least16_t)(X)) + #define UINT32_C(X) ((uint_least32_t)(X)) + #define UINT64_C(X) ((uint_least64_t)(X)) + #define INTMAX_C(X) ((intmax_t)(X)) + #define UINTMAX_C(X) ((uintmax_t)(X)) +#endif // _LIBCUDACXX_COMPILER_NVRTC + +#endif // _LIBCUDACXX___CUDA_CSTDINT_PRELUDE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/latch.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/latch.h new file mode 100644 index 0000000000000000000000000000000000000000..8db2b68fd9090bcc4034054de55a0ee55ec1b798 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/latch.h @@ -0,0 +1,31 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_LATCH_H +#define _LIBCUDACXX___CUDA_LATCH_H + +#ifndef __cuda_std__ +#error "<__cuda/latch> should only be included in from " +#endif // __cuda_std__ + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +template +class latch : public _CUDA_VSTD::__latch_base<_Sco> { +public: + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR + latch(_CUDA_VSTD::ptrdiff_t __count) + : _CUDA_VSTD::__latch_base<_Sco>(__count) { + } +}; + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _LIBCUDACXX___CUDA_LATCH_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/semaphore.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/semaphore.h new file mode 100644 index 0000000000000000000000000000000000000000..dc9b7c6a78ac6004e7f6e4d4c08d76d532909524 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__cuda/semaphore.h @@ -0,0 +1,42 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_SEMAPHORE_H +#define _LIBCUDACXX___CUDA_SEMAPHORE_H + +#ifndef __cuda_std__ +#error "<__cuda/semaphore> should only be included in from " +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +template +class counting_semaphore : public _CUDA_VSTD::__semaphore_base<__least_max_value, _Sco> +{ + static_assert(__least_max_value <= _CUDA_VSTD::__semaphore_base<__least_max_value, _Sco>::max(), ""); +public: + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR + counting_semaphore(ptrdiff_t __count = 0) : _CUDA_VSTD::__semaphore_base<__least_max_value, _Sco>(__count) { } + ~counting_semaphore() = default; + + counting_semaphore(const counting_semaphore&) = delete; + counting_semaphore& operator=(const counting_semaphore&) = delete; +}; + +template +using binary_semaphore = counting_semaphore<_Sco, 1>; + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _LIBCUDACXX___CUDA_SEMAPHORE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__debug b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__debug new file mode 100644 index 0000000000000000000000000000000000000000..0dd3e4f29f5cdac65be029e0fcbeb4afb9585e06 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__debug @@ -0,0 +1,275 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___DEBUG +#define _LIBCUDACXX___DEBUG + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "__assert" +#include "__type_traits/is_constant_evaluated.h" +#include "cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) && !defined(_LIBCUDACXX_CXX03_LANG) && !defined(_LIBCUDACXX_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY) +# define _LIBCUDACXX_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY +#endif + +#if defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) && !defined(_LIBCUDACXX_DEBUG_ITERATOR_BOUNDS_CHECKING) +# define _LIBCUDACXX_DEBUG_ITERATOR_BOUNDS_CHECKING +#endif + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE +# define _LIBCUDACXX_DEBUG_ASSERT(x, m) _LIBCUDACXX_ASSERT(::std::__libcpp_is_constant_evaluated() || (x), m) +#else +# define _LIBCUDACXX_DEBUG_ASSERT(x, m) ((void)0) +#endif + +#if defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) || defined(_LIBCUDACXX_BUILDING_LIBRARY) + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +struct _LIBCUDACXX_TYPE_VIS __c_node; + +struct _LIBCUDACXX_TYPE_VIS __i_node +{ + void* __i_; + __i_node* __next_; + __c_node* __c_; + + __i_node(const __i_node&) = delete; + __i_node& operator=(const __i_node&) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY + __i_node(void* __i, __i_node* __next, __c_node* __c) + : __i_(__i), __next_(__next), __c_(__c) {} + ~__i_node(); +}; + +struct _LIBCUDACXX_TYPE_VIS __c_node +{ + void* __c_; + __c_node* __next_; + __i_node** beg_; + __i_node** end_; + __i_node** cap_; + + __c_node(const __c_node&) = delete; + __c_node& operator=(const __c_node&) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __c_node(void* __c, __c_node* __next) + : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} + virtual ~__c_node(); + + virtual bool __dereferenceable(const void*) const = 0; + virtual bool __decrementable(const void*) const = 0; + virtual bool __addable(const void*, ptrdiff_t) const = 0; + virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; + + void __add(__i_node* __i); + _LIBCUDACXX_HIDDEN void __remove(__i_node* __i); +}; + +template +struct _C_node + : public __c_node +{ + explicit _C_node(void* __c, __c_node* __n) + : __c_node(__c, __n) {} + + bool __dereferenceable(const void*) const override; + bool __decrementable(const void*) const override; + bool __addable(const void*, ptrdiff_t) const override; + bool __subscriptable(const void*, ptrdiff_t) const override; +}; + +template +inline bool +_C_node<_Cont>::__dereferenceable(const void* __i) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__dereferenceable(__j); +} + +template +inline bool +_C_node<_Cont>::__decrementable(const void* __i) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__decrementable(__j); +} + +template +inline bool +_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__addable(__j, __n); +} + +template +inline bool +_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__subscriptable(__j, __n); +} + +class _LIBCUDACXX_TYPE_VIS __libcpp_db +{ + __c_node** __cbeg_; + __c_node** __cend_; + size_t __csz_; + __i_node** __ibeg_; + __i_node** __iend_; + size_t __isz_; + + explicit __libcpp_db(); +public: + __libcpp_db(const __libcpp_db&) = delete; + __libcpp_db& operator=(const __libcpp_db&) = delete; + + ~__libcpp_db(); + + class __db_c_iterator; + class __db_c_const_iterator; + class __db_i_iterator; + class __db_i_const_iterator; + + __db_c_const_iterator __c_end() const; + __db_i_const_iterator __i_end() const; + + typedef __c_node*(_InsertConstruct)(void*, void*, __c_node*); + + template + _LIBCUDACXX_INLINE_VISIBILITY static __c_node* __create_C_node(void *__mem, void *__c, __c_node *__next) { + return ::new (__mem) _C_node<_Cont>(__c, __next); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + void __insert_c(_Cont* __c) + { + __insert_c(static_cast(__c), &__create_C_node<_Cont>); + } + + void __insert_i(void* __i); + void __insert_c(void* __c, _InsertConstruct* __fn); + void __erase_c(void* __c); + + void __insert_ic(void* __i, const void* __c); + void __iterator_copy(void* __i, const void* __i0); + void __erase_i(void* __i); + + void* __find_c_from_i(void* __i) const; + void __invalidate_all(void* __c); + __c_node* __find_c_and_lock(void* __c) const; + __c_node* __find_c(void* __c) const; + void unlock() const; + + void swap(void* __c1, void* __c2); + + + bool __dereferenceable(const void* __i) const; + bool __decrementable(const void* __i) const; + bool __addable(const void* __i, ptrdiff_t __n) const; + bool __subscriptable(const void* __i, ptrdiff_t __n) const; + bool __less_than_comparable(const void* __i, const void* __j) const; +private: + _LIBCUDACXX_HIDDEN + __i_node* __insert_iterator(void* __i); + _LIBCUDACXX_HIDDEN + __i_node* __find_iterator(const void* __i) const; + + friend _LIBCUDACXX_FUNC_VIS __libcpp_db* __get_db(); +}; + +_LIBCUDACXX_FUNC_VIS __libcpp_db* __get_db(); +_LIBCUDACXX_FUNC_VIS const __libcpp_db* __get_const_db(); + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) || defined(_LIBCUDACXX_BUILDING_LIBRARY) + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_c(_Tp* __c) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(__c); +#else + (void)(__c); +#endif +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_i(_Tp* __i) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_i(__i); +#else + (void)(__i); +#endif +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 inline void __debug_db_erase_c(_Tp* __c) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + if (!__libcpp_is_constant_evaluated()) + __get_db()->__erase_c(__c); +#else + (void)(__c); +#endif +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 inline void __debug_db_swap(_Tp* __lhs, _Tp* __rhs) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + if (!__libcpp_is_constant_evaluated()) + __get_db()->swap(__lhs, __rhs); +#else + (void)(__lhs); + (void)(__rhs); +#endif +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 inline void __debug_db_invalidate_all(_Tp* __c) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + if (!__libcpp_is_constant_evaluated()) + __get_db()->__invalidate_all(__c); +#else + (void)(__c); +#endif +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___DEBUG diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__errc b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__errc new file mode 100644 index 0000000000000000000000000000000000000000..03382fa86500fb4150bbc9552af448c984b3b5d3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__errc @@ -0,0 +1,217 @@ +// -*- C++ -*- +//===---------------------------- __errc ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ERRC +#define _LIBCUDACXX___ERRC + +/* + system_error synopsis + +namespace std +{ + +enum class errc +{ + address_family_not_supported, // EAFNOSUPPORT + address_in_use, // EADDRINUSE + address_not_available, // EADDRNOTAVAIL + already_connected, // EISCONN + argument_list_too_long, // E2BIG + argument_out_of_domain, // EDOM + bad_address, // EFAULT + bad_file_descriptor, // EBADF + bad_message, // EBADMSG + broken_pipe, // EPIPE + connection_aborted, // ECONNABORTED + connection_already_in_progress, // EALREADY + connection_refused, // ECONNREFUSED + connection_reset, // ECONNRESET + cross_device_link, // EXDEV + destination_address_required, // EDESTADDRREQ + device_or_resource_busy, // EBUSY + directory_not_empty, // ENOTEMPTY + executable_format_error, // ENOEXEC + file_exists, // EEXIST + file_too_large, // EFBIG + filename_too_long, // ENAMETOOLONG + function_not_supported, // ENOSYS + host_unreachable, // EHOSTUNREACH + identifier_removed, // EIDRM + illegal_byte_sequence, // EILSEQ + inappropriate_io_control_operation, // ENOTTY + interrupted, // EINTR + invalid_argument, // EINVAL + invalid_seek, // ESPIPE + io_error, // EIO + is_a_directory, // EISDIR + message_size, // EMSGSIZE + network_down, // ENETDOWN + network_reset, // ENETRESET + network_unreachable, // ENETUNREACH + no_buffer_space, // ENOBUFS + no_child_process, // ECHILD + no_link, // ENOLINK + no_lock_available, // ENOLCK + no_message_available, // ENODATA + no_message, // ENOMSG + no_protocol_option, // ENOPROTOOPT + no_space_on_device, // ENOSPC + no_stream_resources, // ENOSR + no_such_device_or_address, // ENXIO + no_such_device, // ENODEV + no_such_file_or_directory, // ENOENT + no_such_process, // ESRCH + not_a_directory, // ENOTDIR + not_a_socket, // ENOTSOCK + not_a_stream, // ENOSTR + not_connected, // ENOTCONN + not_enough_memory, // ENOMEM + not_supported, // ENOTSUP + operation_canceled, // ECANCELED + operation_in_progress, // EINPROGRESS + operation_not_permitted, // EPERM + operation_not_supported, // EOPNOTSUPP + operation_would_block, // EWOULDBLOCK + owner_dead, // EOWNERDEAD + permission_denied, // EACCES + protocol_error, // EPROTO + protocol_not_supported, // EPROTONOSUPPORT + read_only_file_system, // EROFS + resource_deadlock_would_occur, // EDEADLK + resource_unavailable_try_again, // EAGAIN + result_out_of_range, // ERANGE + state_not_recoverable, // ENOTRECOVERABLE + stream_timeout, // ETIME + text_file_busy, // ETXTBSY + timed_out, // ETIMEDOUT + too_many_files_open_in_system, // ENFILE + too_many_files_open, // EMFILE + too_many_links, // EMLINK + too_many_symbolic_link_levels, // ELOOP + value_too_large, // EOVERFLOW + wrong_protocol_type // EPROTOTYPE +}; + +*/ + +#include <__config> +#include + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +// Some error codes are not present on all platforms, so we provide equivalents +// for them: + +//enum class errc +_LIBCUDACXX_DECLARE_STRONG_ENUM(errc) +{ + address_family_not_supported = EAFNOSUPPORT, + address_in_use = EADDRINUSE, + address_not_available = EADDRNOTAVAIL, + already_connected = EISCONN, + argument_list_too_long = E2BIG, + argument_out_of_domain = EDOM, + bad_address = EFAULT, + bad_file_descriptor = EBADF, + bad_message = EBADMSG, + broken_pipe = EPIPE, + connection_aborted = ECONNABORTED, + connection_already_in_progress = EALREADY, + connection_refused = ECONNREFUSED, + connection_reset = ECONNRESET, + cross_device_link = EXDEV, + destination_address_required = EDESTADDRREQ, + device_or_resource_busy = EBUSY, + directory_not_empty = ENOTEMPTY, + executable_format_error = ENOEXEC, + file_exists = EEXIST, + file_too_large = EFBIG, + filename_too_long = ENAMETOOLONG, + function_not_supported = ENOSYS, + host_unreachable = EHOSTUNREACH, + identifier_removed = EIDRM, + illegal_byte_sequence = EILSEQ, + inappropriate_io_control_operation = ENOTTY, + interrupted = EINTR, + invalid_argument = EINVAL, + invalid_seek = ESPIPE, + io_error = EIO, + is_a_directory = EISDIR, + message_size = EMSGSIZE, + network_down = ENETDOWN, + network_reset = ENETRESET, + network_unreachable = ENETUNREACH, + no_buffer_space = ENOBUFS, + no_child_process = ECHILD, + no_link = ENOLINK, + no_lock_available = ENOLCK, +#ifdef ENODATA + no_message_available = ENODATA, +#else + no_message_available = ENOMSG, +#endif + no_message = ENOMSG, + no_protocol_option = ENOPROTOOPT, + no_space_on_device = ENOSPC, +#ifdef ENOSR + no_stream_resources = ENOSR, +#else + no_stream_resources = ENOMEM, +#endif + no_such_device_or_address = ENXIO, + no_such_device = ENODEV, + no_such_file_or_directory = ENOENT, + no_such_process = ESRCH, + not_a_directory = ENOTDIR, + not_a_socket = ENOTSOCK, +#ifdef ENOSTR + not_a_stream = ENOSTR, +#else + not_a_stream = EINVAL, +#endif + not_connected = ENOTCONN, + not_enough_memory = ENOMEM, + not_supported = ENOTSUP, + operation_canceled = ECANCELED, + operation_in_progress = EINPROGRESS, + operation_not_permitted = EPERM, + operation_not_supported = EOPNOTSUPP, + operation_would_block = EWOULDBLOCK, + owner_dead = EOWNERDEAD, + permission_denied = EACCES, + protocol_error = EPROTO, + protocol_not_supported = EPROTONOSUPPORT, + read_only_file_system = EROFS, + resource_deadlock_would_occur = EDEADLK, + resource_unavailable_try_again = EAGAIN, + result_out_of_range = ERANGE, + state_not_recoverable = ENOTRECOVERABLE, +#ifdef ETIME + stream_timeout = ETIME, +#else + stream_timeout = ETIMEDOUT, +#endif + text_file_busy = ETXTBSY, + timed_out = ETIMEDOUT, + too_many_files_open_in_system = ENFILE, + too_many_files_open = EMFILE, + too_many_links = EMLINK, + too_many_symbolic_link_levels = ELOOP, + value_too_large = EOVERFLOW, + wrong_protocol_type = EPROTOTYPE +}; +_LIBCUDACXX_DECLARE_STRONG_ENUM_EPILOG(errc) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ERRC diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/bad_expected_access.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/bad_expected_access.h new file mode 100644 index 0000000000000000000000000000000000000000..fe5dc6e50b7f74c68c47a561c7ddd326e00fb16a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/bad_expected_access.h @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCUDACXX___EXPECTED_BAD_EXPECTED_ACCESS_H +#define _LIBCUDACXX___EXPECTED_BAD_EXPECTED_ACCESS_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__utility/move.h" +#include "../exception" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +class bad_expected_access; + +template <> +class bad_expected_access : public exception { +protected: + bad_expected_access() noexcept = default; + bad_expected_access(const bad_expected_access&) = default; + bad_expected_access(bad_expected_access&&) = default; + bad_expected_access& operator=(const bad_expected_access&) = default; + bad_expected_access& operator=(bad_expected_access&&) = default; + ~bad_expected_access() override = default; + +public: + // The way this has been designed (by using a class template below) means that we'll already + // have a profusion of these vtables in TUs, and the dynamic linker will already have a bunch + // of work to do. So it is not worth hiding the specialization in the dylib, given that + // it adds deployment target restrictions. + _LIBCUDACXX_INLINE_VISIBILITY + const char* what() const noexcept override { return "bad access to _CUDA_VSTD::expected"; } +}; + +template +class bad_expected_access : public bad_expected_access { +public: + _LIBCUDACXX_INLINE_VISIBILITY + explicit bad_expected_access(_Err __e) : __unex_(_CUDA_VSTD::move(__e)) {} + + _LIBCUDACXX_INLINE_VISIBILITY + _Err& error() & noexcept { return __unex_; } + + _LIBCUDACXX_INLINE_VISIBILITY + const _Err& error() const& noexcept { return __unex_; } + + _LIBCUDACXX_INLINE_VISIBILITY + _Err&& error() && noexcept { return _CUDA_VSTD::move(__unex_); } + + _LIBCUDACXX_INLINE_VISIBILITY + const _Err&& error() const&& noexcept { return _CUDA_VSTD::move(__unex_); } + +private: + _Err __unex_; +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_STD_VER > 11 + +#endif // _LIBCUDACXX___EXPECTED_BAD_EXPECTED_ACCESS_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/expected.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/expected.h new file mode 100644 index 0000000000000000000000000000000000000000..7c5b85a97efd702188c1a9b218f08173874eec39 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/expected.h @@ -0,0 +1,1786 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCUDACXX___EXPECTED_EXPECTED_H +#define _LIBCUDACXX___EXPECTED_EXPECTED_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__assert" +#include "../__concepts/invocable.h" +#ifndef _LIBCUDACXX_NO_EXCEPTIONS +#include "../__expected/bad_expected_access.h" +#endif // _LIBCUDACXX_NO_EXCEPTIONS +#include "../__expected/expected_base.h" +#include "../__expected/unexpect.h" +#include "../__expected/unexpected.h" +#include "../__memory/addressof.h" +#include "../__memory/construct_at.h" +#include "../__type_traits/conjunction.h" +#include "../__type_traits/disjunction.h" +#include "../__type_traits/is_assignable.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_copy_assignable.h" +#include "../__type_traits/is_copy_constructible.h" +#include "../__type_traits/is_default_constructible.h" +#include "../__type_traits/is_function.h" +#include "../__type_traits/is_move_assignable.h" +#include "../__type_traits/is_move_constructible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__type_traits/is_nothrow_copy_assignable.h" +#include "../__type_traits/is_nothrow_copy_constructible.h" +#include "../__type_traits/is_nothrow_default_constructible.h" +#include "../__type_traits/is_nothrow_move_assignable.h" +#include "../__type_traits/is_nothrow_move_constructible.h" +#include "../__type_traits/is_reference.h" +#include "../__type_traits/is_same.h" +#include "../__type_traits/is_swappable.h" +#include "../__type_traits/is_trivially_copy_constructible.h" +#include "../__type_traits/is_trivially_destructible.h" +#include "../__type_traits/is_trivially_move_constructible.h" +#include "../__type_traits/is_void.h" +#include "../__type_traits/lazy.h" +#include "../__type_traits/negation.h" +#include "../__type_traits/remove_cv.h" +#include "../__type_traits/remove_cvref.h" +#include "../__utility/exception_guard.h" +#include "../__utility/forward.h" +#include "../__utility/in_place.h" +#include "../__utility/move.h" +#include "../__utility/swap.h" + +#include "../cstdlib" +#include "../initializer_list" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +class expected; + +namespace __expected { + + template + _LIBCUDACXX_INLINE_VISIBILITY + void __throw_bad_expected_access(_Arg&& __arg) { +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + throw _CUDA_STD::bad_expected_access<_Err>(_CUDA_VSTD::forward<_Arg>(__arg)); +#else + (void)__arg; + _LIBCUDACXX_UNREACHABLE(); +#endif // _LIBCUDACXX_NO_EXCEPTIONS + } + + template + _LIBCUDACXX_INLINE_VAR constexpr bool __valid_expected = + !_LIBCUDACXX_TRAIT(is_reference, _Tp) && + !_LIBCUDACXX_TRAIT(is_function, _Tp) && + !_LIBCUDACXX_TRAIT(is_same, __remove_cv_t<_Tp>, in_place_t) && + !_LIBCUDACXX_TRAIT(is_same, __remove_cv_t<_Tp>, unexpect_t) && + !__unexpected::__is_unexpected<__remove_cv_t<_Tp>> && + __unexpected::__valid_unexpected<_Err>; + + template + _LIBCUDACXX_INLINE_VAR constexpr bool __is_expected = false; + + template + _LIBCUDACXX_INLINE_VAR constexpr bool __is_expected> = true; + + template + _LIBCUDACXX_INLINE_VAR constexpr bool __is_expected_nonvoid = __is_expected<_Tp>; + + template + _LIBCUDACXX_INLINE_VAR constexpr bool __is_expected_nonvoid> = false; + + template + _LIBCUDACXX_INLINE_VAR constexpr bool __can_swap = + _LIBCUDACXX_TRAIT(is_swappable, _Tp) + && _LIBCUDACXX_TRAIT(is_swappable, _Err) + && _LIBCUDACXX_TRAIT(is_move_constructible, _Tp) + && _LIBCUDACXX_TRAIT(is_move_constructible, _Err) + && (_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp) + || _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err)); + + template + _LIBCUDACXX_INLINE_VAR constexpr bool __can_swap = + _LIBCUDACXX_TRAIT(is_swappable, _Err) + && _LIBCUDACXX_TRAIT(is_move_constructible, _Err); +} // namespace __expected + +template +class expected : private __expected_move_assign<_Tp, _Err> + , private __expected_sfinae_ctor_base_t<_Tp, _Err> + , private __expected_sfinae_assign_base_t<_Tp, _Err> +{ + using __base = __expected_move_assign<_Tp, _Err>; + + static_assert(__expected::__valid_expected<_Tp, _Err>, + "[expected.object.general] A program that instantiates the definition of template expected for a " + "reference type, a function type, or for possibly cv-qualified types in_place_t, unexpect_t, or a " + "specialization of unexpected for the T parameter is ill-formed. A program that instantiates the " + "definition of the template expected with a type for the E parameter that is not a valid " + "template argument for unexpected is ill-formed."); + + template + friend class expected; + +public: + using value_type = _Tp; + using error_type = _Err; + using unexpected_type = unexpected<_Err>; + + template + using rebind = expected<_Up, error_type>; + + // [expected.object.ctor], constructors + _LIBCUDACXX_TEMPLATE(class _Tp2 = _Tp) + (requires _LIBCUDACXX_TRAIT(is_default_constructible, _Tp2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + expected() noexcept(_LIBCUDACXX_TRAIT(is_nothrow_default_constructible, _Tp2)) + : __base(true) + {} + + constexpr expected(const expected&) = default; + constexpr expected(expected&&) = default; + constexpr expected& operator=(const expected&) = default; + constexpr expected& operator=(expected&&) = default; + +private: + template + using __can_convert = + _And< is_constructible<_Tp, _UfQual>, + is_constructible<_Err, _OtherErrQual>, + _Not&>>, + _Not>>, + _Not&>>, + _Not>>, + _Not&, _Tp>>, + _Not&&, _Tp>>, + _Not&, _Tp>>, + _Not&&, _Tp>>, + _Not, expected<_Up, _OtherErr>&>>, + _Not, expected<_Up, _OtherErr>>>, + _Not, const expected<_Up, _OtherErr>&>>, + _Not, const expected<_Up, _OtherErr>>> >; + + +public: + _LIBCUDACXX_TEMPLATE(class _Up, class _OtherErr) + (requires __can_convert<_Up, _OtherErr, const _Up&, const _OtherErr&>::value _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_convertible, const _Up&, _Tp) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_convertible, const _OtherErr&, _Err) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + expected(const expected<_Up, _OtherErr>& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, const _Up&) && + _LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, const _OtherErr&)) // strengthened + : __base(__other.__has_val_) + { + if (__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__val_, __other.__union_.__val_); + } else { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, __other.__union_.__unex_); + } + } + + _LIBCUDACXX_TEMPLATE(class _Up, class _OtherErr) + (requires __can_convert<_Up, _OtherErr, const _Up&, const _OtherErr&>::value _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_convertible, const _Up&, _Tp) || !_LIBCUDACXX_TRAIT(is_convertible, const _OtherErr&, _Err)) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + explicit expected(const expected<_Up, _OtherErr>& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, const _Up&) && + _LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, const _OtherErr&)) // strengthened + : __base(__other.__has_val_) + { + if (__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__val_, __other.__union_.__val_); + } else { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, __other.__union_.__unex_); + } + } + + _LIBCUDACXX_TEMPLATE(class _Up, class _OtherErr) + (requires __can_convert<_Up, _OtherErr, _Up, _OtherErr>::value _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_convertible, _OtherErr, _Err) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + expected(expected<_Up, _OtherErr>&& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Up) && + _LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _OtherErr)) // strengthened + : __base(__other.__has_val_) + { + if (__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__val_, _CUDA_VSTD::move(__other.__union_.__val_)); + } else { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, _CUDA_VSTD::move(__other.__union_.__unex_)); + } + } + + _LIBCUDACXX_TEMPLATE(class _Up, class _OtherErr) + (requires __can_convert<_Up, _OtherErr, _Up, _OtherErr>::value _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp) || !_LIBCUDACXX_TRAIT(is_convertible, _OtherErr, _Err)) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + explicit expected(expected<_Up, _OtherErr>&& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Up) && + _LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _OtherErr)) // strengthened + : __base(__other.__has_val_) + { + if (__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__val_, _CUDA_VSTD::move(__other.__union_.__val_)); + } else { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, _CUDA_VSTD::move(__other.__union_.__unex_)); + } + } + + _LIBCUDACXX_TEMPLATE(class _Up = _Tp) + (requires (!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, in_place_t)) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_same, expected, __remove_cvref_t<_Up>)) _LIBCUDACXX_AND + (!__unexpected::__is_unexpected<__remove_cvref_t<_Up>>) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + expected(_Up&& __u) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Up)) // strengthened + : __base(in_place, _CUDA_VSTD::forward<_Up>(__u)) + {} + + _LIBCUDACXX_TEMPLATE(class _Up = _Tp) + (requires (!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, in_place_t)) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_same, expected, __remove_cvref_t<_Up>)) _LIBCUDACXX_AND + (!__unexpected::__is_unexpected<__remove_cvref_t<_Up>>) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp)) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(_Up&& __u) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Up)) // strengthened + : __base(in_place, _CUDA_VSTD::forward<_Up>(__u)) + {} + + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, const _OtherErr&) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_convertible, const _OtherErr&, _Err) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + expected(const unexpected<_OtherErr>& __unex) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, const _OtherErr&)) // strengthened + : __base(unexpect, __unex.error()) + {} + + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, const _OtherErr&) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_convertible, const _OtherErr&, _Err)) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(const unexpected<_OtherErr>& __unex) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, const _OtherErr&)) // strengthened + : __base(unexpect, __unex.error()) + {} + + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, _OtherErr) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_convertible, _OtherErr, _Err) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + expected(unexpected<_OtherErr>&& __unex) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _OtherErr)) // strengthened + : __base(unexpect, _CUDA_VSTD::move(__unex.error())) + {} + + + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, _OtherErr) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_convertible, _OtherErr, _Err)) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(unexpected<_OtherErr>&& __unex) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _OtherErr)) // strengthened + : __base(unexpect, _CUDA_VSTD::move(__unex.error())) + {} + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Args...)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(in_place_t, _Args&&... __args) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args...)) // strengthened + : __base(in_place, _CUDA_VSTD::forward<_Args>(__args)...) + {} + + _LIBCUDACXX_TEMPLATE(class _Up, class... _Args) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Tp, initializer_list<_Up>&, _Args...)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(in_place_t, initializer_list<_Up> __il, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, initializer_list<_Up>&, _Args...)) // strengthened + : __base(in_place, __il, _CUDA_VSTD::forward<_Args>(__args)...) + {} + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, _Args...)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(unexpect_t, _Args&&... __args) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...)) // strengthened + : __base(unexpect, _CUDA_VSTD::forward<_Args>(__args)...) + {} + + _LIBCUDACXX_TEMPLATE(class _Up, class... _Args) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, initializer_list<_Up>&, _Args...)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(unexpect_t, initializer_list<_Up> __il, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, initializer_list<_Up>&, _Args...)) // strengthened + : __base(unexpect, __il, _CUDA_VSTD::forward<_Args>(__args)...) + {} + +private: + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + expected(__expected_construct_from_invoke_tag, in_place_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, invoke_result_t<_Fun, _Args...>)) + : __base(__expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + {} + + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + expected(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __base(__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + {} + +public: + // [expected.object.assign], assignment + _LIBCUDACXX_TEMPLATE(class _Up = _Tp) + (requires (!_LIBCUDACXX_TRAIT(is_same, expected, __remove_cvref_t<_Up>)) _LIBCUDACXX_AND + (!__unexpected::__is_unexpected<__remove_cvref_t<_Up>>) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_assignable, _Tp&, _Up) _LIBCUDACXX_AND + (_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Up) || + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp) || + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err)) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + expected& operator=(_Up&& __v) { + if (this->__has_val_) { + this->__union_.__val_ = _CUDA_VSTD::forward<_Up>(__v); + } else { + this->__reinit_expected(this->__union_.__val_, this->__union_.__unex_, _CUDA_VSTD::forward<_Up>(__v)); + this->__has_val_ = true; + } + return *this; + } + +private: + template + static constexpr bool __can_assign_from_unexpected = + _And< is_constructible<_Err, _OtherErrQual>, + is_assignable<_Err&, _OtherErrQual>, + _Lazy<_Or, + is_nothrow_constructible<_Err, _OtherErrQual>, + is_nothrow_move_constructible<_Tp>, + is_nothrow_move_constructible<_Err>> >::value; + +public: + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires __can_assign_from_unexpected) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + expected& operator=(const unexpected<_OtherErr>& __un) { + if (this->__has_val_) { + this->__reinit_expected(this->__union_.__unex_, this->__union_.__val_, __un.error()); + this->__has_val_ = false; + } else { + this->__union_.__unex_ = __un.error(); + } + return *this; + } + + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires __can_assign_from_unexpected<_OtherErr>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + expected& operator=(unexpected<_OtherErr>&& __un) { + if (this->__has_val_) { + this->__reinit_expected(this->__union_.__unex_, this->__union_.__val_, _CUDA_VSTD::move(__un.error())); + this->__has_val_ = false; + } else { + this->__union_.__unex_ = _CUDA_VSTD::move(__un.error()); + } + return *this; + } + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires _LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args...)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + _Tp& emplace(_Args&&... __args) noexcept { + if (this->__has_val_) { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(this->__union_.__val_)); + } else { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(this->__union_.__unex_)); + this->__has_val_ = true; + } + return *_LIBCUDACXX_CONSTRUCT_AT(this->__union_.__val_, _CUDA_VSTD::forward<_Args>(__args)...); + } + + _LIBCUDACXX_TEMPLATE(class _Up, class... _Args) + (requires _LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, initializer_list<_Up>&, _Args...)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) noexcept { + if (this->__has_val_) { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(this->__union_.__val_)); + } else { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(this->__union_.__unex_)); + this->__has_val_ = true; + } + return *_LIBCUDACXX_CONSTRUCT_AT(this->__union_.__val_, __il, _CUDA_VSTD::forward<_Args>(__args)...); + } + + +public: + // [expected.object.swap], swap + _LIBCUDACXX_TEMPLATE(class _Tp2 = _Tp, class _Err2 = _Err) + (requires __expected::__can_swap<_Tp2, _Err2>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + void swap(expected<_Tp2, _Err>& __rhs) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp2) && + _LIBCUDACXX_TRAIT(is_nothrow_swappable, _Tp2) && + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err) && + _LIBCUDACXX_TRAIT(is_nothrow_swappable, _Err)) + { + if (this->__has_val_) { + if (__rhs.__has_val_) { + using _CUDA_VSTD::swap; + swap(this->__union_.__val_, __rhs.__union_.__val_); + } else { + this->__swap_val_unex_impl(*this, __rhs); + } + } else { + if (__rhs.__has_val_) { + this->__swap_val_unex_impl(__rhs, *this); + } else { + using _CUDA_VSTD::swap; + swap(this->__union_.__unex_, __rhs.__union_.__unex_); + } + } + } + + template + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + auto swap(expected& __x, expected& __y) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp2) && + _LIBCUDACXX_TRAIT(is_nothrow_swappable, _Tp2) && + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err2) && + _LIBCUDACXX_TRAIT(is_nothrow_swappable, _Err2)) + _LIBCUDACXX_TRAILING_REQUIRES(void)(requires __expected::__can_swap<_Tp2, _Err2>) + { + return __x.swap(__y); // some compiler warn about non void function without return + } + + // [expected.object.obs], observers + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr const _Tp* operator->() const noexcept { + _LIBCUDACXX_ASSERT(this->__has_val_, "expected::operator-> requires the expected to contain a value"); + return _CUDA_VSTD::addressof(this->__union_.__val_); + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp* operator->() noexcept { + _LIBCUDACXX_ASSERT(this->__has_val_, "expected::operator-> requires the expected to contain a value"); + return _CUDA_VSTD::addressof(this->__union_.__val_); + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr const _Tp& operator*() const& noexcept { + _LIBCUDACXX_ASSERT(this->__has_val_, "expected::operator* requires the expected to contain a value"); + return this->__union_.__val_; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp& operator*() & noexcept { + _LIBCUDACXX_ASSERT(this->__has_val_, "expected::operator* requires the expected to contain a value"); + return this->__union_.__val_; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr const _Tp&& operator*() const&& noexcept { + _LIBCUDACXX_ASSERT(this->__has_val_, "expected::operator* requires the expected to contain a value"); + return _CUDA_VSTD::move(this->__union_.__val_); + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp&& operator*() && noexcept { + _LIBCUDACXX_ASSERT(this->__has_val_, "expected::operator* requires the expected to contain a value"); + return _CUDA_VSTD::move(this->__union_.__val_); + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit operator bool() const noexcept { return this->__has_val_; } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr bool has_value() const noexcept { return this->__has_val_; } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr const _Tp& value() const& { + if (!this->__has_val_) { + __expected::__throw_bad_expected_access<_Err>(this->__union_.__unex_); + } + return this->__union_.__val_; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + _Tp& value() & { + if (!this->__has_val_) { + __expected::__throw_bad_expected_access<_Err>(this->__union_.__unex_); + } + return this->__union_.__val_; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + const _Tp&& value() const&& { + if (!this->__has_val_) { + __expected::__throw_bad_expected_access<_Err>(_CUDA_VSTD::move(this->__union_.__unex_)); + } + return _CUDA_VSTD::move(this->__union_.__val_); + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + _Tp&& value() && { + if (!this->__has_val_) { + __expected::__throw_bad_expected_access<_Err>(_CUDA_VSTD::move(this->__union_.__unex_)); + } + return _CUDA_VSTD::move(this->__union_.__val_); + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + const _Err& error() const& noexcept { + _LIBCUDACXX_ASSERT(!this->__has_val_, "expected::error requires the expected to contain an error"); + return this->__union_.__unex_; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + _Err& error() & noexcept { + _LIBCUDACXX_ASSERT(!this->__has_val_, "expected::error requires the expected to contain an error"); + return this->__union_.__unex_; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + const _Err&& error() const&& noexcept { + _LIBCUDACXX_ASSERT(!this->__has_val_, "expected::error requires the expected to contain an error"); + return _CUDA_VSTD::move(this->__union_.__unex_); + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + _Err&& error() && noexcept { + _LIBCUDACXX_ASSERT(!this->__has_val_, "expected::error requires the expected to contain an error"); + return _CUDA_VSTD::move(this->__union_.__unex_); + } + + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + _Tp value_or(_Up&& __v) const& { + static_assert(_LIBCUDACXX_TRAIT(is_copy_constructible, _Tp), "value_type has to be copy constructible"); + static_assert(_LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp), "argument has to be convertible to value_type"); + return this->__has_val_ ? this->__union_.__val_ : static_cast<_Tp>(_CUDA_VSTD::forward<_Up>(__v)); + } + + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + _Tp value_or(_Up&& __v) && { + static_assert(_LIBCUDACXX_TRAIT(is_move_constructible, _Tp), "value_type has to be move constructible"); + static_assert(_LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp), "argument has to be convertible to value_type"); + return this->__has_val_ ? _CUDA_VSTD::move(this->__union_.__val_) : static_cast<_Tp>(_CUDA_VSTD::forward<_Up>(__v)); + } + + // [expected.object.monadic] + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, _Err2&)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto and_then(_Fun&& __fun) & { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of f(value()) must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::error_type, _Err), + "The error type of the result of f(value()) must be the same as that of std::expected"); + + if (this->__has_val_) { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__val_); + } else { + return _Res{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_copy_constructible, _Err2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto and_then(_Fun&& __fun) const& { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of f(value()) must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::error_type, _Err), + "The error type of the result of f(value()) must be the same as that of std::expected"); + + if (this->__has_val_) { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__val_); + } else { + return _Res{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_move_constructible, _Err2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto and_then(_Fun&& __fun) && { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of f(value()) must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::error_type, _Err), + "The error type of the result of f(value()) must be the same as that of std::expected"); + + if (this->__has_val_) { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::move(this->__union_.__val_)); + } else { + return _Res{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, const _Err2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto and_then(_Fun&& __fun) const&& { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of f(value()) must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::error_type, _Err), + "The error type of the result of f(value()) must be the same as that of std::expected"); + + if (this->__has_val_) { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::move(this->__union_.__val_)); + } else { + return _Res{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Tp2, _Tp2&)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto or_else(_Fun&& __fun) & { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of std::expected::or_else must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::value_type, _Tp), + "The value type of the result of std::expected::or_else must be the same as that of std::expected"); + + if (this->__has_val_) { + return _Res{in_place, this->__union_.__val_}; + } else { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__unex_); + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp) + (requires _LIBCUDACXX_TRAIT(is_copy_constructible, _Tp2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto or_else(_Fun&& __fun) const& { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of std::expected::or_else must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::value_type, _Tp), + "The value type of the result of std::expected::or_else must be the same as that of std::expected"); + + if (this->__has_val_) { + return _Res{in_place, this->__union_.__val_}; + } else { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__unex_); + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp) + (requires _LIBCUDACXX_TRAIT(is_move_constructible, _Tp2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto or_else(_Fun&& __fun) && { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of std::expected::or_else must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::value_type, _Tp), + "The value type of the result of std::expected::or_else must be the same as that of std::expected"); + + if (this->__has_val_) { + return _Res{in_place, _CUDA_VSTD::move(this->__union_.__val_)}; + } else { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::move(this->__union_.__unex_)); + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Tp2, const _Tp2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto or_else(_Fun&& __fun) const&& { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of std::expected::or_else must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::value_type, _Tp), + "The value type of the result of std::expected::or_else must be the same as that of std::expected"); + + if (this->__has_val_) { + return _Res{in_place, _CUDA_VSTD::move(this->__union_.__val_)}; + } else { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::move(this->__union_.__unex_)); + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, _Err2&) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) & { + static_assert(invocable<_Fun, _Tp&>, + "std::expected::transform requires that F must be invocable with T."); + using _Res = __remove_cv_t>; + + if (this->__has_val_) { + _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__val_); + return expected{}; + } else { + return expected<_Res, _Err>{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, _Err2&) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void))) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) & { + static_assert(invocable<_Fun, _Tp&>, + "std::expected::transform requires that F must be invocable with T."); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, _Tp&>, + "std::expected::transform requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Res, _Err>, + "std::expected::transform requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Res, _Err>{ + __expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__val_}; + } else { + return expected<_Res, _Err>{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_copy_constructible, _Err2) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) const& { + static_assert(invocable<_Fun, const _Tp&>, + "std::expected::transform requires that F must be invocable with T."); + using _Res = __remove_cv_t>; + + if (this->__has_val_) { + _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__val_); + return expected<_Res, _Err>{}; + } else { + return expected<_Res, _Err>{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_copy_constructible, _Err2) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void))) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) const& { + static_assert(invocable<_Fun, const _Tp&>, + "std::expected::transform requires that F must be invocable with T"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, const _Tp&>, + "std::expected::transform requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Res, _Err>, + "std::expected::transform requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Res, _Err>{ + __expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__val_}; + } else { + return expected<_Res, _Err>{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_move_constructible, _Err2) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) && { + static_assert(invocable<_Fun, _Tp>, + "std::expected::transform requires that F must be invocable with T."); + using _Res = __remove_cv_t>; + + if (this->__has_val_) { + _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::move(this->__union_.__val_)); + return expected<_Res, _Err>{}; + } else { + return expected<_Res, _Err>{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_move_constructible, _Err2) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void))) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) && { + static_assert(invocable<_Fun, _Tp>, + "std::expected::transform requires that F must be invocable with T"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, _Tp>, + "std::expected::transform requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Res, _Err>, + "std::expected::transform requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Res, _Err>{ + __expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::move(this->__union_.__val_)}; + } else { + return expected<_Res, _Err>{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, const _Err2) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) const&& { + static_assert(invocable<_Fun, const _Tp>, + "std::expected::transform requires that F must be invocable with T."); + using _Res = __remove_cv_t>; + + if (this->__has_val_) { + _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::move(this->__union_.__val_)); + return expected<_Res, _Err>{}; + } else { + return expected<_Res, _Err>{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, const _Err2) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void))) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) const&& { + static_assert(invocable<_Fun, const _Tp>, + "std::expected::transform requires that F must be invocable with T"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, const _Tp>, + "std::expected::transform requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Res, _Err>, + "std::expected::transform requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Res, _Err>{ + __expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::move(this->__union_.__val_)}; + } else { + return expected<_Res, _Err>{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Tp2, _Tp2&)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform_error(_Fun&& __fun) & { + static_assert(invocable<_Fun, _Err&>, + "std::expected::transform_error requires that F must be invocable with E"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, _Err&>, + "std::expected::transform_error requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Tp, _Res>, + "std::expected::transform_error requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Tp, _Res>{in_place, this->__union_.__val_}; + } else { + return expected<_Tp, _Res>{ + __expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp) + (requires _LIBCUDACXX_TRAIT(is_copy_constructible, _Tp2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform_error(_Fun&& __fun) const& { + static_assert(invocable<_Fun, const _Err&>, + "std::expected::transform_error requires that F must be invocable with E"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, const _Err&>, + "std::expected::transform_error requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Tp, _Res>, + "std::expected::transform_error requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Tp, _Res>{in_place, this->__union_.__val_}; + } else { + return expected<_Tp, _Res>{ + __expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp) + (requires _LIBCUDACXX_TRAIT(is_move_constructible, _Tp2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform_error(_Fun&& __fun) && { + static_assert(invocable<_Fun, _Err>, + "std::expected::transform_error requires that F must be invocable with E"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, _Err>, + "std::expected::transform_error requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Tp, _Res>, + "std::expected::transform_error requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Tp, _Res>{in_place, _CUDA_VSTD::move(this->__union_.__val_)}; + } else { + return expected<_Tp, _Res>{__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), + _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Tp2 = _Tp) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Tp2, const _Tp2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform_error(_Fun&& __fun) const&& { + static_assert(invocable<_Fun, const _Err>, + "std::expected::transform_error requires that F must be invocable with E"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, const _Err>, + "std::expected::transform_error requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Tp, _Res>, + "std::expected::transform_error requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Tp, _Res>{in_place, _CUDA_VSTD::move(this->__union_.__val_)}; + } else { + return expected<_Tp, _Res>{__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), + _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + // [expected.object.eq], equality operators + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator==(const expected& __x, const expected& __y) { + if (__x.__has_val_ != __y.has_value()) { + return false; + } else { + if (__x.__has_val_) { + return __x.__union_.__val_ == __y.value(); + } else { + return __x.__union_.__unex_ == __y.error(); + } + } + } + +#if _LIBCUDACXX_STD_VER < 20 + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator!=(const expected& __x, const expected& __y) { + return !(__x == __y); + } +#endif // _LIBCUDACXX_STD_VER < 20 + + _LIBCUDACXX_TEMPLATE(class _T2, class _E2) + (requires (!_LIBCUDACXX_TRAIT(is_void, _T2))) + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator==(const expected& __x, const expected<_T2, _E2>& __y) { + if (__x.__has_val_ != __y.has_value()) { + return false; + } else { + if (__x.__has_val_) { + return __x.__union_.__val_ == __y.value(); + } else { + return __x.__union_.__unex_ == __y.error(); + } + } + } + +#if _LIBCUDACXX_STD_VER < 20 + _LIBCUDACXX_TEMPLATE(class _T2, class _E2) + (requires (!_LIBCUDACXX_TRAIT(is_void, _T2))) + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator!=(const expected& __x, const expected<_T2, _E2>& __y) { + return !(__x == __y); + } +#endif // _LIBCUDACXX_STD_VER < 20 + + _LIBCUDACXX_TEMPLATE(class _T2) + (requires (!__expected::__is_expected_nonvoid<_T2>)) + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator==(const expected& __x, const _T2& __v) { + return __x.__has_val_ && static_cast(__x.__union_.__val_ == __v); + } +#if _LIBCUDACXX_STD_VER < 20 + _LIBCUDACXX_TEMPLATE(class _T2) + (requires (!__expected::__is_expected_nonvoid<_T2>)) + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator==(const _T2& __v, const expected& __x) { + return __x.__has_val_ && static_cast(__x.__union_.__val_ == __v); + } + _LIBCUDACXX_TEMPLATE(class _T2) + (requires (!__expected::__is_expected_nonvoid<_T2>)) + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator!=(const expected& __x, const _T2& __v) { + return !__x.__has_val_ || static_cast(__x.__union_.__val_ != __v); + } + _LIBCUDACXX_TEMPLATE(class _T2) + (requires (!__expected::__is_expected_nonvoid<_T2>)) + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator!=(const _T2& __v, const expected& __x) { + return !__x.__has_val_ || static_cast(__x.__union_.__val_ != __v); + } +#endif // _LIBCUDACXX_STD_VER < 20 + + template + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator==(const expected& __x, const unexpected<_E2>& __e) { + return !__x.__has_val_ && static_cast(__x.__union_.__unex_ == __e.error()); + } +#if _LIBCUDACXX_STD_VER < 20 + template + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator==(const unexpected<_E2>& __e, const expected& __x) { + return !__x.__has_val_ && static_cast(__x.__union_.__unex_ == __e.error()); + } + template + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator!=(const expected& __x, const unexpected<_E2>& __e) { + return __x.__has_val_ || static_cast(__x.__union_.__unex_ != __e.error()); + } + template + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator!=(const unexpected<_E2>& __e, const expected& __x) { + return __x.__has_val_ || static_cast(__x.__union_.__unex_ != __e.error()); + } +#endif // _LIBCUDACXX_STD_VER < 20 +}; + + +template +class expected : private __expected_move_assign + , private __expected_void_sfinae_ctor_base_t<_Err> + , private __expected_void_sfinae_assign_base_t<_Err> +{ + using __base = __expected_move_assign; + static_assert(__unexpected::__valid_unexpected<_Err>, + "[expected.void.general] A program that instantiates expected with a E that is not a " + "valid argument for unexpected is ill-formed"); + + template + friend class expected; + + template + using __can_convert = + _And< is_void<_Up>, + is_constructible<_Err, _OtherErrQual>, + _Not, expected<_Up, _OtherErr>&>>, + _Not, expected<_Up, _OtherErr>>>, + _Not, const expected<_Up, _OtherErr>&>>, + _Not, const expected<_Up, _OtherErr>>>>; + +public: + using value_type = void; + using error_type = _Err; + using unexpected_type = unexpected<_Err>; + + template + using rebind = expected<_Up, error_type>; + + // [expected.void.ctor], constructors + constexpr expected() = default; + constexpr expected(const expected&) = default; + constexpr expected(expected&&) = default; + constexpr expected& operator=(const expected&) = default; + constexpr expected& operator=(expected&&) = default; + + _LIBCUDACXX_TEMPLATE(class _Up, class _OtherErr) + (requires __can_convert<_Up, _OtherErr, const _OtherErr&>::value _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_convertible, const _OtherErr&, _Err) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + expected(const expected<_Up, _OtherErr>& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, const _OtherErr&)) // strengthened + : __base(__other.__has_val_) + { + if (!__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, __other.__union_.__unex_); + } + } + + _LIBCUDACXX_TEMPLATE(class _Up, class _OtherErr) + (requires __can_convert<_Up, _OtherErr, const _OtherErr&>::value _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_convertible, const _OtherErr&, _Err)) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + explicit expected(const expected<_Up, _OtherErr>& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, const _OtherErr&)) // strengthened + : __base(__other.__has_val_) + { + if (!__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, __other.__union_.__unex_); + } + } + + _LIBCUDACXX_TEMPLATE(class _Up, class _OtherErr) + (requires __can_convert<_Up, _OtherErr, _OtherErr>::value _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_convertible, _OtherErr, _Err) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + expected(expected<_Up, _OtherErr>&& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _OtherErr)) // strengthened + : __base(__other.__has_val_) + { + if (!__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, _CUDA_VSTD::move(__other.__union_.__unex_)); + } + } + + _LIBCUDACXX_TEMPLATE(class _Up, class _OtherErr) + (requires __can_convert<_Up, _OtherErr, _OtherErr>::value _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_convertible, _OtherErr, _Err)) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + explicit expected(expected<_Up, _OtherErr>&& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _OtherErr)) // strengthened + : __base(__other.__has_val_) + { + if (!__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, _CUDA_VSTD::move(__other.__union_.__unex_)); + } + } + + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, const _OtherErr&) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_convertible, const _OtherErr&, _Err) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + expected(const unexpected<_OtherErr>& __unex) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, const _OtherErr&)) // strengthened + : __base(unexpect, __unex.error()) + {} + + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, const _OtherErr&) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_convertible, const _OtherErr&, _Err)) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(const unexpected<_OtherErr>& __unex) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, const _OtherErr&)) // strengthened + : __base(unexpect, __unex.error()) + {} + + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, _OtherErr) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_convertible, _OtherErr, _Err)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + expected(unexpected<_OtherErr>&& __unex) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _OtherErr)) // strengthened + : __base(unexpect, _CUDA_VSTD::move(__unex.error())) + {} + + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, _OtherErr) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_convertible, _OtherErr, _Err)) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(unexpected<_OtherErr>&& __unex) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _OtherErr)) // strengthened + : __base(unexpect, _CUDA_VSTD::move(__unex.error())) + {} + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(in_place_t) noexcept : __base(true) {} + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, _Args...)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(unexpect_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...)) // strengthened + : __base(unexpect, _CUDA_VSTD::forward<_Args>(__args)...) + {} + + _LIBCUDACXX_TEMPLATE(class _Up, class... _Args) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, initializer_list<_Up>&, _Args...)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit expected(unexpect_t, initializer_list<_Up> __il, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, initializer_list<_Up>, _Args...)) // strengthened + : __base(unexpect, __il, _CUDA_VSTD::forward<_Args>(__args)...) + {} + +private: + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + expected(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __base(__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + {} + +public: + + // [expected.void.dtor], destructor + // [expected.void.assign], assignment + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, const _OtherErr&) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_assignable, _Err&, const _OtherErr&) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + expected& operator=(const unexpected<_OtherErr>& __un) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_assignable, _Err&, const _OtherErr&) && + _LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, const _OtherErr&)) // strengthened + { + if (this->__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, __un.error()); + this->__has_val_ = false; + } else { + this->__union_.__unex_ = __un.error(); + } + return *this; + } + + _LIBCUDACXX_TEMPLATE(class _OtherErr) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, _OtherErr) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_assignable, _Err&, _OtherErr) + ) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + expected& operator=(unexpected<_OtherErr>&& __un) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_assignable, _Err&, _OtherErr) && + _LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _OtherErr)) + { + if (this->__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, _CUDA_VSTD::move(__un.error())); + this->__has_val_ = false; + } else { + this->__union_.__unex_ = _CUDA_VSTD::move(__un.error()); + } + return *this; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + void emplace() noexcept + { + if (!this->__has_val_) { + this->__union_.__unex_.~_Err(); + this->__has_val_ = true; + } + } + + // [expected.void.swap], swap + _LIBCUDACXX_TEMPLATE(class _Err2 = _Err) + (requires __expected::__can_swap) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + void swap(expected& __rhs) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err2) && + _LIBCUDACXX_TRAIT(is_nothrow_swappable, _Err2)) + { + if (this->__has_val_) { + if (!__rhs.__has_val_) { + this->__swap_val_unex_impl(*this, __rhs); + } + } else { + if (__rhs.__has_val_) { + this->__swap_val_unex_impl(__rhs, *this); + } else { + using _CUDA_VSTD::swap; + swap(this->__union_.__unex_, __rhs.__union_.__unex_); + } + } + } + + template + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + auto swap(expected& __x, expected& __y) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err2) && + _LIBCUDACXX_TRAIT(is_nothrow_swappable, _Err2)) + _LIBCUDACXX_TRAILING_REQUIRES(void)(requires __expected::__can_swap) + { + return __x.swap(__y); // some compiler warn about non void function without return + } + + // [expected.void.obs], observers + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr explicit operator bool() const noexcept { return this->__has_val_; } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr bool has_value() const noexcept { return this->__has_val_; } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr void operator*() const noexcept { + _LIBCUDACXX_ASSERT(this->__has_val_, "expected::operator* requires the expected to contain a value"); + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr void value() const& { + if (!this->__has_val_) { + __expected::__throw_bad_expected_access<_Err>(this->__union_.__unex_); + } + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr void value() && { + if (!this->__has_val_) { + __expected::__throw_bad_expected_access<_Err>(_CUDA_VSTD::move(this->__union_.__unex_)); + } + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr const _Err& error() const& noexcept { + _LIBCUDACXX_ASSERT(!this->__has_val_, "expected::error requires the expected to contain an error"); + return this->__union_.__unex_; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr _Err& error() & noexcept { + _LIBCUDACXX_ASSERT(!this->__has_val_, "expected::error requires the expected to contain an error"); + return this->__union_.__unex_; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr const _Err&& error() const&& noexcept { + _LIBCUDACXX_ASSERT(!this->__has_val_, "expected::error requires the expected to contain an error"); + return _CUDA_VSTD::move(this->__union_.__unex_); + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr _Err&& error() && noexcept { + _LIBCUDACXX_ASSERT(!this->__has_val_, "expected::error requires the expected to contain an error"); + return _CUDA_VSTD::move(this->__union_.__unex_); + } + + // [expected.void.monadic] + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, _Err2&)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto and_then(_Fun&& __fun) & { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of f(value()) must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::error_type, _Err), + "The error type of the result of f(value()) must be the same as that of std::expected"); + + if (this->__has_val_) { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun)); + } else { + return _Res{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_copy_constructible, _Err2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto and_then(_Fun&& __fun) const& { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of f(value()) must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::error_type, _Err), + "The error type of the result of f(value()) must be the same as that of std::expected"); + + if (this->__has_val_) { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun)); + } else { + return _Res{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_move_constructible, _Err2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto and_then(_Fun&& __fun) && { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of f(value()) must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::error_type, _Err), + "The error type of the result of f(value()) must be the same as that of std::expected"); + + if (this->__has_val_) { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun)); + } else { + return _Res{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, const _Err2)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto and_then(_Fun&& __fun) const&& { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of f(value()) must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::error_type, _Err), + "The error type of the result of f(value()) must be the same as that of std::expected"); + + if (this->__has_val_) { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun)); + } else { + return _Res{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto or_else(_Fun&& __fun) & { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of std::expected::or_else must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::value_type, void), + "The value type of the result of std::expected::or_else must be the same as that of std::expected"); + + if (this->__has_val_) { + return _Res{}; + } else { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__unex_); + } + } + + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto or_else(_Fun&& __fun) const& { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of std::expected::or_else must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::value_type, void), + "The value type of the result of std::expected::or_else must be the same as that of std::expected"); + + if (this->__has_val_) { + return _Res{}; + } else { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__unex_); + } + } + + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto or_else(_Fun&& __fun) && { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of std::expected::or_else must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::value_type, void), + "The value type of the result of std::expected::or_else must be the same as that of std::expected"); + + if (this->__has_val_) { + return _Res{}; + } else { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::move(this->__union_.__unex_)); + } + } + + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto or_else(_Fun&& __fun) const&& { + using _Res = __remove_cvref_t>; + + static_assert(__expected::__is_expected<_Res>, + "Result of std::expected::or_else must be a specialization of std::expected"); + static_assert(_LIBCUDACXX_TRAIT(is_same, typename _Res::value_type, void), + "The value type of the result of std::expected::or_else must be the same as that of std::expected"); + + if (this->__has_val_) { + return _Res{}; + } else { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::move(this->__union_.__unex_)); + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, _Err2&) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) & { + static_assert(invocable<_Fun>, + "std::expected::transform requires that F must be invocable with T."); + if (this->__has_val_) { + _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun)); + return expected{}; + } else { + return expected{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, _Err2&) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void))) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) & { + static_assert(invocable<_Fun>, + "std::expected::transform requires that F must be invocable with T."); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun>, + "std::expected::transform requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Res, _Err>, + "std::expected::transform requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Res, _Err>{ + __expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun)}; + } else { + return expected<_Res, _Err>{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_copy_constructible, _Err2) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) const& { + static_assert(invocable<_Fun>, + "std::expected::transform requires that F must be invocable with T."); + if (this->__has_val_) { + _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun)); + return expected{}; + } else { + return expected{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_copy_constructible, _Err2) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void))) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) const& { + static_assert(invocable<_Fun>, + "std::expected::transform requires that F must be invocable with T"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun>, + "std::expected::transform requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Res, _Err>, + "std::expected::transform requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Res, _Err>{ + __expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun)}; + } else { + return expected<_Res, _Err>{unexpect, this->__union_.__unex_}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_move_constructible, _Err2) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) && { + static_assert(invocable<_Fun>, + "std::expected::transform requires that F must be invocable with T."); + if (this->__has_val_) { + _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun)); + return expected{}; + } else { + return expected{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_move_constructible, _Err2) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void))) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) && { + static_assert(invocable<_Fun>, + "std::expected::transform requires that F must be invocable with T"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun>, + "std::expected::transform requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Res, _Err>, + "std::expected::transform requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Res, _Err>{ + __expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun)}; + } else { + return expected<_Res, _Err>{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, const _Err2) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void)) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) const&& { + static_assert(invocable<_Fun>, + "std::expected::transform requires that F must be invocable with T."); + if (this->__has_val_) { + _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun)); + return expected{}; + } else { + return expected{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + _LIBCUDACXX_TEMPLATE(class _Fun, class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err2, const _Err2) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t>, void))) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform(_Fun&& __fun) const&& { + static_assert(invocable<_Fun>, + "std::expected::transform requires that F must be invocable with T"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun>, + "std::expected::transform requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected<_Res, _Err>, + "std::expected::transform requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected<_Res, _Err>{ + __expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun)}; + } else { + return expected<_Res, _Err>{unexpect, _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform_error(_Fun&& __fun) & { + static_assert(invocable<_Fun, _Err&>, + "std::expected::transform_error requires that F must be invocable with E"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, _Err&>, + "std::expected::transform_error requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected, + "std::expected::transform_error requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected{}; + } else { + return expected{ + __expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__unex_}; + } + } + + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform_error(_Fun&& __fun) const& { + static_assert(invocable<_Fun, const _Err&>, + "std::expected::transform_error requires that F must be invocable with E"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, const _Err&>, + "std::expected::transform_error requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected, + "std::expected::transform_error requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected{}; + } else { + return expected{ + __expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), this->__union_.__unex_}; + } + } + + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform_error(_Fun&& __fun) && { + static_assert(invocable<_Fun, _Err>, + "std::expected::transform_error requires that F must be invocable with E"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, _Err>, + "std::expected::transform_error requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected, + "std::expected::transform_error requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected{}; + } else { + return expected{__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), + _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + auto transform_error(_Fun&& __fun) const&& { + static_assert(invocable<_Fun, const _Err>, + "std::expected::transform_error requires that F must be invocable with E"); + using _Res = __remove_cv_t>; + + static_assert(__invoke_constructible<_Fun, const _Err>, + "std::expected::transform_error requires that the return type of F is constructible with the result of invoking F"); + static_assert(__expected::__valid_expected, + "std::expected::transform_error requires that the return type of F must be a valid argument for std::expected"); + + if (this->__has_val_) { + return expected{}; + } else { + return expected{__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), + _CUDA_VSTD::move(this->__union_.__unex_)}; + } + } + + // [expected.void.eq], equality operators + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator==(const expected& __x, const expected& __y) noexcept { + if (__x.__has_val_ != __y.has_value()) { + return false; + } else { + return __x.__has_val_ || static_cast(__x.__union_.__unex_ == __y.error()); + } + } +#if _LIBCUDACXX_STD_VER < 20 + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator!=(const expected& __x, const expected& __y) noexcept { + return !(__x == __y); + } +#endif + + template + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator==(const expected& __x, const expected& __y) noexcept { + if (__x.__has_val_ != __y.has_value()) { + return false; + } else { + return __x.__has_val_ || static_cast(__x.__union_.__unex_ == __y.error()); + } + } +#if _LIBCUDACXX_STD_VER < 20 + template + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator!=(const expected& __x, const expected& __y) noexcept { + return !(__x == __y); + } +#endif + + template + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator==(const expected& __x, const unexpected<_E2>& __y) noexcept { + return !__x.__has_val_ && static_cast(__x.__union_.__unex_ == __y.error()); + } +#if _LIBCUDACXX_STD_VER < 20 + template + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + bool operator==(const unexpected<_E2>& __y, const expected& __x) noexcept { + return !__x.__has_val_ && static_cast(__x.__union_.__unex_ == __y.error()); + } + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + friend constexpr bool operator!=(const expected& __x, const unexpected<_E2>& __y) noexcept { + return __x.__has_val_ || static_cast(__x.__union_.__unex_ != __y.error()); + } + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + friend constexpr bool operator!=(const unexpected<_E2>& __y, const expected& __x) noexcept { + return __x.__has_val_ || static_cast(__x.__union_.__unex_ != __y.error()); + } +#endif +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_STD_VER > 11 + +#endif // _LIBCUDACXX___EXPECTED_EXPECTED_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/expected_base.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/expected_base.h new file mode 100644 index 0000000000000000000000000000000000000000..5db982e74049d10c57309551bbebfe195663ee92 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/expected_base.h @@ -0,0 +1,1044 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCUDACXX___EXPECTED_EXPECTED_BASE_H +#define _LIBCUDACXX___EXPECTED_EXPECTED_BASE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__assert" +#include "../__concepts/__concept_macros.h" +#include "../__concepts/invocable.h" +#include "../__expected/unexpect.h" +#include "../__memory/addressof.h" +#include "../__memory/construct_at.h" +#include "../__tuple_dir/sfinae_helpers.h" +#include "../__type_traits/is_assignable.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_copy_assignable.h" +#include "../__type_traits/is_copy_constructible.h" +#include "../__type_traits/is_default_constructible.h" +#include "../__type_traits/is_move_assignable.h" +#include "../__type_traits/is_move_constructible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__type_traits/is_nothrow_copy_assignable.h" +#include "../__type_traits/is_nothrow_copy_constructible.h" +#include "../__type_traits/is_nothrow_default_constructible.h" +#include "../__type_traits/is_nothrow_move_assignable.h" +#include "../__type_traits/is_nothrow_move_constructible.h" +#include "../__type_traits/is_trivially_copy_assignable.h" +#include "../__type_traits/is_trivially_copy_constructible.h" +#include "../__type_traits/is_trivially_destructible.h" +#include "../__type_traits/is_trivially_move_assignable.h" +#include "../__type_traits/is_trivially_move_constructible.h" +#include "../__type_traits/is_void.h" +#include "../__utility/exception_guard.h" +#include "../__utility/forward.h" +#include "../__utility/in_place.h" +#include "../__utility/move.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +// MSVC complains about [[no_unique_address]] prior to C++20 as a vendor extension +#if defined(_LIBCUDACXX_COMPILER_MSVC) +#pragma warning(push) +#pragma warning(disable : 4848) +#endif // _LIBCUDACXX_COMPILER_MSVC + +struct __expected_construct_from_invoke_tag { + explicit __expected_construct_from_invoke_tag() = default; +}; + +template +union __expected_union_t { + struct __empty_t {}; + + _LIBCUDACXX_TEMPLATE(class _Tp2 = _Tp) + (requires _LIBCUDACXX_TRAIT(is_default_constructible, _Tp2)) + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t() noexcept(_LIBCUDACXX_TRAIT(is_nothrow_default_constructible, _Tp2)) : __val_() {} + + _LIBCUDACXX_TEMPLATE(class _Tp2 = _Tp) + (requires (!_LIBCUDACXX_TRAIT(is_default_constructible, _Tp2))) + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t() noexcept : __empty_() {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(in_place_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args...)) + : __val_(_CUDA_VSTD::forward<_Args>(__args)...) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(unexpect_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...)) + : __unex_(_CUDA_VSTD::forward<_Args>(__args)...) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(__expected_construct_from_invoke_tag, in_place_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, invoke_result_t<_Fun, _Args...>)) + : __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...)) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __unex_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...)) {} + + // the __expected_destruct's destructor handles this + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + ~__expected_union_t() {} + + _LIBCUDACXX_NO_UNIQUE_ADDRESS __empty_t __empty_; + _LIBCUDACXX_NO_UNIQUE_ADDRESS _Tp __val_; + _LIBCUDACXX_NO_UNIQUE_ADDRESS _Err __unex_; +}; + +template +union __expected_union_t<_Tp, _Err, true> { + struct __empty_t {}; + + _LIBCUDACXX_TEMPLATE(class _Tp2 = _Tp) + (requires _LIBCUDACXX_TRAIT(is_default_constructible, _Tp2)) + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t() noexcept(_LIBCUDACXX_TRAIT(is_nothrow_default_constructible, _Tp2)) : __val_() {} + + _LIBCUDACXX_TEMPLATE(class _Tp2 = _Tp) + (requires (!_LIBCUDACXX_TRAIT(is_default_constructible, _Tp2))) + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t() noexcept : __empty_() {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(in_place_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args...)) + : __val_(_CUDA_VSTD::forward<_Args>(__args)...) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(unexpect_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...)) + : __unex_(_CUDA_VSTD::forward<_Args>(__args)...) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(__expected_construct_from_invoke_tag, in_place_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, invoke_result_t<_Fun, _Args...>)) + : __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...)) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __unex_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...)) {} + + _LIBCUDACXX_NO_UNIQUE_ADDRESS __empty_t __empty_; + _LIBCUDACXX_NO_UNIQUE_ADDRESS _Tp __val_; + _LIBCUDACXX_NO_UNIQUE_ADDRESS _Err __unex_; +}; + +template +struct __expected_destruct; + +template +struct __expected_destruct<_Tp, _Err, false, false> { + _LIBCUDACXX_NO_UNIQUE_ADDRESS __expected_union_t<_Tp, _Err> __union_{}; + bool __has_val_{true}; + + constexpr __expected_destruct() noexcept = default; + + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(const bool __has_val) noexcept : __has_val_(__has_val) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(in_place_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args...)) + : __union_(in_place, _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(unexpect_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...)) + : __union_(unexpect, _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(__expected_construct_from_invoke_tag, in_place_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, invoke_result_t<_Fun, _Args...>)) + : __union_(__expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __union_(__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + ~__expected_destruct() { + if (__has_val_) { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__union_.__val_)); + } else { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__union_.__unex_)); + } + } +}; + +template +struct __expected_destruct<_Tp, _Err, true, false> { + _LIBCUDACXX_NO_UNIQUE_ADDRESS __expected_union_t<_Tp, _Err> __union_{}; + bool __has_val_{true}; + + constexpr __expected_destruct() noexcept = default; + + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(const bool __has_val) noexcept : __has_val_(__has_val) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(in_place_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args...)) + : __union_(in_place, _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(unexpect_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args...)) + : __union_(unexpect, _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(__expected_construct_from_invoke_tag, in_place_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, invoke_result_t<_Fun, _Args...>)) + : __union_(__expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __union_(__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + ~__expected_destruct() { + if (!__has_val_) { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__union_.__unex_)); + } + } +}; + +template +struct __expected_destruct<_Tp, _Err, false, true> { + _LIBCUDACXX_NO_UNIQUE_ADDRESS __expected_union_t<_Tp, _Err> __union_{}; + bool __has_val_{true}; + + constexpr __expected_destruct() noexcept = default; + + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(const bool __has_val) noexcept : __has_val_(__has_val) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(in_place_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args...)) + : __union_(in_place, _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(unexpect_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args...)) + : __union_(unexpect, _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(__expected_construct_from_invoke_tag, in_place_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, invoke_result_t<_Fun, _Args...>)) + : __union_(__expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __union_(__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + ~__expected_destruct() { + if (__has_val_) { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__union_.__val_)); + } + } +}; + +template +struct __expected_destruct<_Tp, _Err, true, true> { + // This leads to an ICE with nvcc, see nvbug4103076 + /* _LIBCUDACXX_NO_UNIQUE_ADDRESS */ __expected_union_t<_Tp, _Err> __union_{}; + bool __has_val_{true}; + + constexpr __expected_destruct() noexcept = default; + + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(const bool __has_val) noexcept : __has_val_(__has_val) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(in_place_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args...)) + : __union_(in_place, _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(unexpect_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args...)) + : __union_(unexpect, _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(__expected_construct_from_invoke_tag, in_place_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, invoke_result_t<_Fun, _Args...>)) + : __union_(__expected_construct_from_invoke_tag{}, in_place, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __union_(__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} +}; + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +#pragma warning(pop) +#endif // _LIBCUDACXX_COMPILER_MSVC + +template +struct __expected_storage : __expected_destruct<_Tp, _Err> +{ + using __base = __expected_destruct<_Tp, _Err>; + +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + constexpr __expected_storage() noexcept = default; + + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_storage(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + + _LIBCUDACXX_TEMPLATE(class _T1, class _T2, class... _Args) + (requires _LIBCUDACXX_TRAIT(is_nothrow_constructible, _T1, _Args...)) + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + void __reinit_expected(_T1& __newval, _T2& __oldval, _Args&&... __args) noexcept { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__oldval)); + _LIBCUDACXX_CONSTRUCT_AT(__newval, _CUDA_VSTD::forward<_Args>(__args)...); + } + + _LIBCUDACXX_TEMPLATE(class _T1, class _T2, class... _Args) + (requires (!_LIBCUDACXX_TRAIT(is_nothrow_constructible, _T1, _Args...)) _LIBCUDACXX_AND + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _T1) + ) + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + void __reinit_expected(_T1& __newval, _T2& __oldval, _Args&&... __args) { + _T1 __tmp(_CUDA_VSTD::forward<_Args>(__args)...); + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__oldval)); + _LIBCUDACXX_CONSTRUCT_AT(__newval, _CUDA_VSTD::move(__tmp)); + } + + _LIBCUDACXX_TEMPLATE(class _T1, class _T2, class... _Args) + (requires (!_LIBCUDACXX_TRAIT(is_nothrow_constructible, _T1, _Args...)) _LIBCUDACXX_AND + (!_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _T1)) + ) + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + void __reinit_expected(_T1& __newval, _T2& __oldval, _Args&&... __args) { + static_assert(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _T2), + "To provide strong exception guarantee, T2 has to satisfy `is_nothrow_move_constructible_v` so that it can " + "be reverted to the previous state in case an exception is thrown during the assignment."); + _T2 __tmp(_CUDA_VSTD::move(__oldval)); + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__oldval)); + auto __trans = + _CUDA_VSTD::__make_exception_guard([&] { _LIBCUDACXX_CONSTRUCT_AT(__oldval, _CUDA_VSTD::move(__tmp)); }); + _LIBCUDACXX_CONSTRUCT_AT(__newval, _CUDA_VSTD::forward<_Args>(__args)...); + __trans.__complete(); + } + + _LIBCUDACXX_TEMPLATE(class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err2)) + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + void __swap_val_unex_impl(__expected_storage<_Tp, _Err2>& __with_val, __expected_storage& __with_err) { + _Err __tmp(_CUDA_VSTD::move(__with_err.__union_.__unex_)); + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__with_err.__union_.__unex_)); + auto __trans = _CUDA_VSTD::__make_exception_guard([&] { + _LIBCUDACXX_CONSTRUCT_AT(__with_err.__union_.__unex_, _CUDA_VSTD::move(__tmp)); + }); + _LIBCUDACXX_CONSTRUCT_AT(__with_err.__union_.__val_, _CUDA_VSTD::move(__with_val.__union_.__val_)); + __trans.__complete(); + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__with_val.__union_.__val_)); + _LIBCUDACXX_CONSTRUCT_AT(__with_val.__union_.__unex_, _CUDA_VSTD::move(__tmp)); + __with_val.__has_val_ = false; + __with_err.__has_val_ = true; + } + + _LIBCUDACXX_TEMPLATE(class _Err2 = _Err) + (requires (!_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err2))) + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + void __swap_val_unex_impl(__expected_storage<_Tp, _Err2>& __with_val, __expected_storage& __with_err) { + static_assert(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp), + "To provide strong exception guarantee, Tp has to satisfy `is_nothrow_move_constructible_v` so " + "that it can be reverted to the previous state in case an exception is thrown during swap."); + _Tp __tmp(_CUDA_VSTD::move(__with_val.__union_.__val_)); + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__with_val.__union_.__val_)); + auto __trans = _CUDA_VSTD::__make_exception_guard([&] { + _LIBCUDACXX_CONSTRUCT_AT(__with_val.__union_.__val_, _CUDA_VSTD::move(__tmp)); + }); + _LIBCUDACXX_CONSTRUCT_AT(__with_val.__union_.__unex_, _CUDA_VSTD::move(__with_err.__union_.__unex_)); + __trans.__complete(); + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__with_err.__union_.__unex_)); + _LIBCUDACXX_CONSTRUCT_AT(__with_err.__union_.__val_, _CUDA_VSTD::move(__tmp)); + __with_val.__has_val_ = false; + __with_err.__has_val_ = true; + } +}; + +template +struct __expected_copy : __expected_storage<_Tp, _Err> +{ + using __base = __expected_storage<_Tp, _Err>; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + constexpr __expected_copy() noexcept = default; + + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_copy(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 +}; + +template +struct __expected_copy<_Tp, _Err, false> : __expected_storage<_Tp, _Err> +{ + using __base = __expected_storage<_Tp, _Err>; + +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_copy(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + + constexpr __expected_copy() noexcept = default; + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __expected_copy(const __expected_copy& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_copy_constructible, _Tp) + && _LIBCUDACXX_TRAIT(is_nothrow_copy_constructible, _Err)) + : __base(__other.__has_val_) + { + if (__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__val_, __other.__union_.__val_); + } else { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, __other.__union_.__unex_); + } + } + + __expected_copy(__expected_copy&&) = default; + __expected_copy& operator=(const __expected_copy&) = default; + __expected_copy& operator=(__expected_copy&&) = default; +}; + +template +struct __expected_move : __expected_copy<_Tp, _Err> +{ + using __base = __expected_copy<_Tp, _Err>; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + constexpr __expected_move() noexcept = default; + + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_move(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 +}; + +template +struct __expected_move<_Tp, _Err, false> : __expected_copy<_Tp, _Err> +{ + using __base = __expected_copy<_Tp, _Err>; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_move(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + + __expected_move() = default; + __expected_move(const __expected_move&) = default; + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __expected_move(__expected_move&& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp) + && _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err)) + : __base(__other.__has_val_) + { + if (__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__val_, _CUDA_VSTD::move(__other.__union_.__val_)); + } else { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, _CUDA_VSTD::move(__other.__union_.__unex_)); + } + } + + __expected_move& operator=(const __expected_move&) = default; + __expected_move& operator=(__expected_move&&) = default; +}; + +template +struct __expected_copy_assign : __expected_move<_Tp, _Err> +{ + using __base = __expected_move<_Tp, _Err>; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + constexpr __expected_copy_assign() noexcept = default; + + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_copy_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 +}; + +template +struct __expected_copy_assign<_Tp, _Err, false> : __expected_move<_Tp, _Err> +{ + using __base = __expected_move<_Tp, _Err>; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_copy_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + + __expected_copy_assign() = default; + __expected_copy_assign(const __expected_copy_assign&) = default; + __expected_copy_assign(__expected_copy_assign&&) = default; + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __expected_copy_assign& operator=(const __expected_copy_assign& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_copy_assignable, _Tp) && + _LIBCUDACXX_TRAIT(is_nothrow_copy_constructible, _Tp) && + _LIBCUDACXX_TRAIT(is_nothrow_copy_assignable, _Err) && + _LIBCUDACXX_TRAIT(is_nothrow_copy_constructible, _Err)) // strengthened + { + if (this->__has_val_ && __other.__has_val_) { + this->__union_.__val_ = __other.__union_.__val_; + } else if (this->__has_val_ && !__other.__has_val_) { + this->__reinit_expected(this->__union_.__unex_, this->__union_.__val_, __other.__union_.__unex_); + this->__has_val_ = false; + } else if (!this->__has_val_ && __other.__has_val_) { + this->__reinit_expected(this->__union_.__val_, this->__union_.__unex_, __other.__union_.__val_); + this->__has_val_ = true; + } else { // !this->__has_val_ && !__other.__has_val_ + this->__union_.__unex_ = __other.__union_.__unex_; + } + return *this; + } + + __expected_copy_assign& operator=(__expected_copy_assign&&) = default; +}; + +template +struct __expected_move_assign : __expected_copy_assign<_Tp, _Err> +{ + using __base = __expected_copy_assign<_Tp, _Err>; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + constexpr __expected_move_assign() noexcept = default; + + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_move_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 +}; + +template +struct __expected_move_assign<_Tp, _Err, false> : __expected_copy_assign<_Tp, _Err> +{ + using __base = __expected_copy_assign<_Tp, _Err>; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_move_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + + __expected_move_assign() = default; + __expected_move_assign(const __expected_move_assign&) = default; + __expected_move_assign(__expected_move_assign&&) = default; + __expected_move_assign& operator=(const __expected_move_assign&) = default; + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __expected_move_assign& operator=(__expected_move_assign&& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Tp) && + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp) && + _LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Err) && + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err)) // strengthened + { + if (this->__has_val_ && __other.__has_val_) { + this->__union_.__val_ = _CUDA_VSTD::move(__other.__union_.__val_); + } else if (this->__has_val_ && !__other.__has_val_) { + this->__reinit_expected(this->__union_.__unex_, this->__union_.__val_, _CUDA_VSTD::move(__other.__union_.__unex_)); + this->__has_val_ = false; + } else if (!this->__has_val_ && __other.__has_val_) { + this->__reinit_expected(this->__union_.__val_, this->__union_.__unex_, _CUDA_VSTD::move(__other.__union_.__val_)); + this->__has_val_ = true; + } else { // !this->__has_val_ && !__other.__has_val_ + this->__union_.__unex_ = _CUDA_VSTD::move(__other.__union_.__unex_); + } + return *this; + } +}; + +template +using __expected_sfinae_ctor_base_t = __sfinae_ctor_base< + _LIBCUDACXX_TRAIT(is_copy_constructible, _Tp) && _LIBCUDACXX_TRAIT(is_copy_constructible, _Err), + _LIBCUDACXX_TRAIT(is_move_constructible, _Tp) && _LIBCUDACXX_TRAIT(is_move_constructible, _Err) +>; + +template +using __expected_sfinae_assign_base_t = __sfinae_assign_base< + _LIBCUDACXX_TRAIT(is_copy_constructible, _Tp) && _LIBCUDACXX_TRAIT(is_copy_constructible, _Err) && + _LIBCUDACXX_TRAIT(is_copy_assignable, _Tp) && _LIBCUDACXX_TRAIT(is_copy_assignable, _Err) && + (_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp) || _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err)), + _LIBCUDACXX_TRAIT(is_move_constructible, _Tp) && _LIBCUDACXX_TRAIT(is_move_constructible, _Err) && + _LIBCUDACXX_TRAIT(is_move_assignable, _Tp) && _LIBCUDACXX_TRAIT(is_move_assignable, _Err) && + (_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp) || _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err)) +>; + +// expected base classtemplate +// MSVC complains about [[no_unique_address]] prior to C++20 as a vendor extension +#if defined(_LIBCUDACXX_COMPILER_MSVC) +#pragma warning(push) +#pragma warning(disable : 4848) +#endif // _LIBCUDACXX_COMPILER_MSVC + +template +struct __expected_destruct { + _LIBCUDACXX_NO_UNIQUE_ADDRESS union __expected_union_t { + struct __empty_t {}; + + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t() noexcept : __empty_() {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(unexpect_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...)) + : __unex_(_CUDA_VSTD::forward<_Args>(__args)...) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __unex_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...)) {} + + // the __expected_destruct's destructor handles this + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + ~__expected_union_t() {} + + _LIBCUDACXX_NO_UNIQUE_ADDRESS __empty_t __empty_; + _LIBCUDACXX_NO_UNIQUE_ADDRESS _Err __unex_; + } __union_{}; + bool __has_val_{true}; + + constexpr __expected_destruct() noexcept = default; + + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(const bool __has_val) noexcept : __has_val_(__has_val) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(unexpect_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...)) + : __union_(unexpect, _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __union_(__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + ~__expected_destruct() { + if (!__has_val_) { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__union_.__unex_)); + } + } +}; + +template +struct __expected_destruct { + // Using `_LIBCUDACXX_NO_UNIQUE_ADDRESS` here crashes nvcc + /* _LIBCUDACXX_NO_UNIQUE_ADDRESS */ union __expected_union_t { + struct __empty_t {}; + + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t() noexcept : __empty_() {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(unexpect_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...)) + : __unex_(_CUDA_VSTD::forward<_Args>(__args)...) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_union_t(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __unex_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...)) {} + + _LIBCUDACXX_NO_UNIQUE_ADDRESS __empty_t __empty_; + _LIBCUDACXX_NO_UNIQUE_ADDRESS _Err __unex_; + } __union_{}; + bool __has_val_{true}; + + constexpr __expected_destruct() noexcept = default; + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(in_place_t) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...)) + : __union_() + , __has_val_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(unexpect_t, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...)) + : __union_(unexpect, _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(__expected_construct_from_invoke_tag, unexpect_t, _Fun&& __fun, _Args&&... __args) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, invoke_result_t<_Fun, _Args...>)) + : __union_(__expected_construct_from_invoke_tag{}, unexpect, _CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...) + , __has_val_(false) + {} + + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_destruct(const bool __has_val) noexcept : __has_val_(__has_val) {} +}; + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +#pragma warning(pop) +#endif // _LIBCUDACXX_COMPILER_MSVC + +template +struct __expected_storage : __expected_destruct +{ + using __base = __expected_destruct; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + constexpr __expected_storage() noexcept = default; + + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_storage(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + void __swap_val_unex_impl(__expected_storage& __with_val, __expected_storage& __with_err) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err)) { + _LIBCUDACXX_CONSTRUCT_AT(__with_val.__union_.__unex_, _CUDA_VSTD::move(__with_err.__union_.__unex_)); + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(__with_err.__union_.__unex_)); + __with_val.__has_val_ = false; + __with_err.__has_val_ = true; + } +}; + +template +struct __expected_copy : __expected_storage +{ + using __base = __expected_storage; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_copy(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + + constexpr __expected_copy() = default; + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __expected_copy(const __expected_copy& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_copy_constructible, _Err)) + : __base(__other.__has_val_) + { + if (!__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, __other.__union_.__unex_); + } + } + + __expected_copy(__expected_copy&&) = default; + __expected_copy& operator=(const __expected_copy&) = default; + __expected_copy& operator=(__expected_copy&&) = default; +}; + +template +struct __expected_move : __expected_copy +{ + using __base = __expected_copy; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_move(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + + __expected_move() = default; + __expected_move(const __expected_move&) = default; + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __expected_move(__expected_move&& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err)) + : __base(__other.__has_val_) + { + if (!__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, _CUDA_VSTD::move(__other.__union_.__unex_)); + } + } + + __expected_move& operator=(const __expected_move&) = default; + __expected_move& operator=(__expected_move&&) = default; +}; + +template +struct __expected_copy_assign : __expected_move +{ + using __base = __expected_move; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_copy_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + + __expected_copy_assign() = default; + __expected_copy_assign(const __expected_copy_assign&) = default; + __expected_copy_assign(__expected_copy_assign&&) = default; + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __expected_copy_assign& operator=(const __expected_copy_assign& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_copy_assignable, _Err) && + _LIBCUDACXX_TRAIT(is_nothrow_copy_constructible, _Err)) // strengthened + { + if (this->__has_val_ && __other.__has_val_) { + // nothing to do + } else if (this->__has_val_ && !__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, __other.__union_.__unex_); + this->__has_val_ = false; + } else if (!this->__has_val_ && __other.__has_val_) { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(this->__union_.__unex_)); + this->__has_val_ = true; + } else { // !this->__has_val_ && !__other.__has_val_ + this->__union_.__unex_ = __other.__union_.__unex_; + } + return *this; + } + + __expected_copy_assign& operator=(__expected_copy_assign&&) = default; +}; + +template +struct __expected_move_assign : __expected_copy_assign +{ + using __base = __expected_copy_assign; +// nvbug3961621 +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_CUDACC_BELOW_11_3) && defined(_LIBCUDACXX_COMPILER_CLANG)) + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __expected_move_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base::__base; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + + __expected_move_assign() = default; + __expected_move_assign(const __expected_move_assign&) = default; + __expected_move_assign(__expected_move_assign&&) = default; + __expected_move_assign& operator=(const __expected_move_assign&) = default; + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __expected_move_assign& operator=(__expected_move_assign&& __other) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Err) && + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Err)) // strengthened + { + if (this->__has_val_ && __other.__has_val_) { + // nothing to do + } else if (this->__has_val_ && !__other.__has_val_) { + _LIBCUDACXX_CONSTRUCT_AT(this->__union_.__unex_, _CUDA_VSTD::move(__other.__union_.__unex_)); + this->__has_val_ = false; + } else if (!this->__has_val_ && __other.__has_val_) { + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(this->__union_.__unex_)); + this->__has_val_ = true; + } else { // !this->__has_val_ && !__other.__has_val_ + this->__union_.__unex_ = _CUDA_VSTD::move(__other.__union_.__unex_); + } + return *this; + } +}; + +template +using __expected_void_sfinae_ctor_base_t = __sfinae_ctor_base< + _LIBCUDACXX_TRAIT(is_copy_constructible, _Err), + _LIBCUDACXX_TRAIT(is_move_constructible, _Err) +>; + +template +using __expected_void_sfinae_assign_base_t = __sfinae_assign_base< + _LIBCUDACXX_TRAIT(is_copy_constructible, _Err) && + _LIBCUDACXX_TRAIT(is_copy_assignable, _Err), + _LIBCUDACXX_TRAIT(is_move_constructible, _Err) && + _LIBCUDACXX_TRAIT(is_move_assignable, _Err) +>; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_STD_VER > 11 + +#endif // _LIBCUDACXX___EXPECTED_EXPECTED_BASE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/unexpect.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/unexpect.h new file mode 100644 index 0000000000000000000000000000000000000000..7dd8c52ebbc79ccd491314716824c9672f2e2dc4 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/unexpect.h @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCUDACXX___EXPECTED_UNEXPECT_H +#define _LIBCUDACXX___EXPECTED_UNEXPECT_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +struct unexpect_t { + explicit unexpect_t() = default; +}; + +_LIBCUDACXX_CPO_ACCESSIBILITY unexpect_t unexpect{}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_STD_VER > 11 + +#endif // _LIBCUDACXX___EXPECTED_UNEXPECT_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/unexpected.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/unexpected.h new file mode 100644 index 0000000000000000000000000000000000000000..0f8770c8004dde4380be34e4612d07a902e75b17 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__expected/unexpected.h @@ -0,0 +1,166 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___EXPECTED_UNEXPECTED_H +#define _LIBCUDACXX___EXPECTED_UNEXPECTED_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/is_array.h" +#include "../__type_traits/is_const.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__type_traits/is_object.h" +#include "../__type_traits/is_same.h" +#include "../__type_traits/is_swappable.h" +#include "../__type_traits/is_volatile.h" +#include "../__type_traits/remove_cvref.h" +#include "../__utility/forward.h" +#include "../__utility/in_place.h" +#include "../__utility/move.h" + +#include "../initializer_list" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +template +class unexpected; + +namespace __unexpected { +template +_LIBCUDACXX_INLINE_VAR constexpr bool __is_unexpected = false; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __is_unexpected> = true; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __valid_unexpected = _LIBCUDACXX_TRAIT(is_object, _Tp) && + !_LIBCUDACXX_TRAIT(is_array, _Tp) && + !__is_unexpected<_Tp> && + !_LIBCUDACXX_TRAIT(is_const, _Tp) && + !_LIBCUDACXX_TRAIT(is_volatile, _Tp); +} // namespace __unexpected + +// [expected.un.general] +template +class unexpected { + static_assert(__unexpected::__valid_unexpected<_Err>, + "[expected.un.general] states a program that instantiates std::unexpected for a non-object type, an " + "array type, a specialization of unexpected, or a cv-qualified type is ill-formed."); + + template + friend class expected; + +public: + // [expected.un.ctor] + _LIBCUDACXX_HIDE_FROM_ABI unexpected(const unexpected&) = default; + _LIBCUDACXX_HIDE_FROM_ABI unexpected(unexpected&&) = default; + + _LIBCUDACXX_TEMPLATE(class _Error = _Err) + (requires (!_LIBCUDACXX_TRAIT(is_same, remove_cvref_t<_Error>, unexpected) && + !_LIBCUDACXX_TRAIT(is_same, remove_cvref_t<_Error>, in_place_t) && + _LIBCUDACXX_TRAIT(is_constructible, _Err, _Error))) + _LIBCUDACXX_INLINE_VISIBILITY + constexpr explicit unexpected(_Error&& __error) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Error)) + : __unex_(_CUDA_VSTD::forward<_Error>(__error)) {} + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, _Args...)) + _LIBCUDACXX_INLINE_VISIBILITY + constexpr explicit unexpected(in_place_t, _Args&&... __args) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...)) + : __unex_(_CUDA_VSTD::forward<_Args>(__args)...) {} + + _LIBCUDACXX_TEMPLATE(class _Up, class... _Args) + (requires _LIBCUDACXX_TRAIT(is_constructible, _Err, initializer_list<_Up>&, _Args...)) + _LIBCUDACXX_INLINE_VISIBILITY + constexpr explicit unexpected(in_place_t, initializer_list<_Up> __il, _Args&&... __args) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, initializer_list<_Up>&, _Args...)) + : __unex_(__il, _CUDA_VSTD::forward<_Args>(__args)...) {} + + constexpr unexpected& operator=(const unexpected&) = default; + constexpr unexpected& operator=(unexpected&&) = default; + + // [expected.un.obs] + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_NODISCARD_ATTRIBUTE constexpr const _Err& error() const& noexcept { + return __unex_; + } + + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_NODISCARD_ATTRIBUTE constexpr _Err& error() & noexcept { + return __unex_; + } + + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_NODISCARD_ATTRIBUTE constexpr const _Err&& error() const&& noexcept { + return _CUDA_VSTD::move(__unex_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_NODISCARD_ATTRIBUTE constexpr _Err&& error() && noexcept { + return _CUDA_VSTD::move(__unex_); + } + + // [expected.un.swap] + _LIBCUDACXX_INLINE_VISIBILITY + constexpr void swap(unexpected& __other) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_swappable, _Err)) { + static_assert(_LIBCUDACXX_TRAIT(is_swappable, _Err), "E must be swappable"); + using _CUDA_VSTD::swap; + swap(__unex_, __other.__unex_); + } + + _LIBCUDACXX_TEMPLATE(class _Err2 = _Err) + (requires _LIBCUDACXX_TRAIT(is_swappable, _Err2)) + friend _LIBCUDACXX_INLINE_VISIBILITY constexpr + void swap(unexpected& __lhs, unexpected& __rhs) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_swappable, _Err2)) + { + __lhs.swap(__rhs); + return; + } + + // [expected.un.eq] + template + friend _LIBCUDACXX_INLINE_VISIBILITY constexpr + _LIBCUDACXX_NODISCARD_EXT bool operator==(const unexpected& __lhs, const unexpected<_UErr>& __rhs) noexcept( + noexcept(static_cast(__lhs.error() == __rhs.error()))) { + return __lhs.error() == __rhs.error(); + } +#if _LIBCUDACXX_STD_VER < 20 + template + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_NODISCARD_EXT friend constexpr bool operator!=(const unexpected& __lhs, const unexpected<_UErr>& __rhs) noexcept( + noexcept(static_cast(__lhs.error() != __rhs.error()))) { + return __lhs.error() != __rhs.error(); + } +#endif + +private: + _Err __unex_; +}; + +#if _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES) +template +unexpected(_Err) -> unexpected<_Err>; +#endif // _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES) + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___EXPECTED_UNEXPECTED_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binary_function.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..e476e68c076620ffa5d7312f8edbe1ac73b7ada2 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binary_function.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BINARY_FUNCTION_H +#define _LIBCUDACXX___FUNCTIONAL_BINARY_FUNCTION_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION) + +template +struct _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 binary_function +{ + typedef _Arg1 first_argument_type; + typedef _Arg2 second_argument_type; + typedef _Result result_type; +}; + +#endif // _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION) + +template struct __binary_function_keep_layout_base { +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using first_argument_type _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Arg1; + using second_argument_type _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Arg2; + using result_type _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Result; +#endif +}; + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION) +_LIBCUDACXX_DIAGNOSTIC_PUSH +_LIBCUDACXX_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") +template +using __binary_function = binary_function<_Arg1, _Arg2, _Result>; +_LIBCUDACXX_DIAGNOSTIC_POP +#else +template +using __binary_function = __binary_function_keep_layout_base<_Arg1, _Arg2, _Result>; +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BINARY_FUNCTION_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binary_negate.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binary_negate.h new file mode 100644 index 0000000000000000000000000000000000000000..3adaaa2dd0165a696467a7dd545c4b3f6f7ea14d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binary_negate.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BINARY_NEGATE_H +#define _LIBCUDACXX___FUNCTIONAL_BINARY_NEGATE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_NEGATORS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX17 binary_negate + : public __binary_function +{ + _Predicate __pred_; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 + binary_negate(const _Predicate& __pred) : __pred_(__pred) {} + + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const typename _Predicate::first_argument_type& __x, + const typename _Predicate::second_argument_type& __y) const + {return !__pred_(__x, __y);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX17 inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY +binary_negate<_Predicate> +not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} + +#endif // _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_NEGATORS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BINARY_NEGATE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/bind.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/bind.h new file mode 100644 index 0000000000000000000000000000000000000000..3f6a3aca92c4483d2bcb852ead88a39fb9aea0b9 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/bind.h @@ -0,0 +1,418 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BIND_H +#define _LIBCUDACXX___FUNCTIONAL_BIND_H + +// `cuda::std::bind` is not currently supported. + +#ifndef __cuda_std__ + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/invoke.h" +#include "../__functional/reference_wrapper.h" +#include "../__functional/weak_result_type.h" +#include "../__fwd/get.h" +#include "../__tuple_dir/tuple_element.h" +#include "../__tuple_dir/tuple_indices.h" +#include "../__tuple_dir/tuple_size.h" +#include "../__type_traits/conditional.h" +#include "../__type_traits/decay.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_same.h" +#include "../__type_traits/is_void.h" +#include "../__type_traits/remove_cvref.h" +#include "../__type_traits/remove_reference.h" +#include "../__utility/forward.h" + +#include "../cstddef" +#include "../tuple" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct is_bind_expression : _If< + _IsSame<_Tp, __remove_cvref_t<_Tp> >::value, + false_type, + is_bind_expression<__remove_cvref_t<_Tp> > +> {}; + +#if _LIBCUDACXX_STD_VER > 14 +template +inline constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; +#endif + +template +struct is_placeholder : _If< + _IsSame<_Tp, __remove_cvref_t<_Tp> >::value, + integral_constant, + is_placeholder<__remove_cvref_t<_Tp> > +> {}; + +#if _LIBCUDACXX_STD_VER > 14 +template +inline constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; +#endif + +namespace placeholders +{ + +template struct __ph {}; + +#if defined(_LIBCUDACXX_CXX03_LANG) || defined(_LIBCUDACXX_BUILDING_LIBRARY) +_LIBCUDACXX_FUNC_VIS extern const __ph<1> _1; +_LIBCUDACXX_FUNC_VIS extern const __ph<2> _2; +_LIBCUDACXX_FUNC_VIS extern const __ph<3> _3; +_LIBCUDACXX_FUNC_VIS extern const __ph<4> _4; +_LIBCUDACXX_FUNC_VIS extern const __ph<5> _5; +_LIBCUDACXX_FUNC_VIS extern const __ph<6> _6; +_LIBCUDACXX_FUNC_VIS extern const __ph<7> _7; +_LIBCUDACXX_FUNC_VIS extern const __ph<8> _8; +_LIBCUDACXX_FUNC_VIS extern const __ph<9> _9; +_LIBCUDACXX_FUNC_VIS extern const __ph<10> _10; +#else +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<1> _1{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<2> _2{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<3> _3{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<4> _4{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<5> _5{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<6> _6{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<7> _7{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<8> _8{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<9> _9{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<10> _10{}; +#endif // defined(_LIBCUDACXX_CXX03_LANG) || defined(_LIBCUDACXX_BUILDING_LIBRARY) + +} // namespace placeholders + +template +struct is_placeholder > + : public integral_constant {}; + + +#ifndef _LIBCUDACXX_CXX03_LANG + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +_Tp& +__mu(reference_wrapper<_Tp> __t, _Uj&) +{ + return __t.get(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __invoke_of<_Ti&, _Uj...>::type +__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) +{ + return __ti(_CUDA_VSTD::forward<_Uj>(_CUDA_VSTD::get<_Indx>(__uj))...); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__enable_if_t +< + is_bind_expression<_Ti>::value, + __invoke_of<_Ti&, _Uj...> +> +__mu(_Ti& __ti, tuple<_Uj...>& __uj) +{ + typedef typename __make_tuple_indices::type __indices; + return _CUDA_VSTD::__mu_expand(__ti, __uj, __indices()); +} + +template +struct __mu_return2 {}; + +template +struct __mu_return2 +{ + typedef typename tuple_element::value - 1, _Uj>::type type; +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__enable_if_t +< + 0 < is_placeholder<_Ti>::value, + typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type +> +__mu(_Ti&, _Uj& __uj) +{ + const size_t _Indx = is_placeholder<_Ti>::value - 1; + return _CUDA_VSTD::forward::type>(_CUDA_VSTD::get<_Indx>(__uj)); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__enable_if_t +< + !is_bind_expression<_Ti>::value && + is_placeholder<_Ti>::value == 0 && + !__is_reference_wrapper<_Ti>::value, + _Ti& +> +__mu(_Ti& __ti, _Uj&) +{ + return __ti; +} + +template +struct __mu_return_impl; + +template +struct __mu_return_invokable // false +{ + typedef __nat type; +}; + +template +struct __mu_return_invokable +{ + typedef typename __invoke_of<_Ti&, _Uj...>::type type; +}; + +template +struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> > + : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> +{ +}; + +template +struct __mu_return_impl<_Ti, false, false, true, _TupleUj> +{ + typedef typename tuple_element::value - 1, + _TupleUj>::type&& type; +}; + +template +struct __mu_return_impl<_Ti, true, false, false, _TupleUj> +{ + typedef typename _Ti::type& type; +}; + +template +struct __mu_return_impl<_Ti, false, false, false, _TupleUj> +{ + typedef _Ti& type; +}; + +template +struct __mu_return + : public __mu_return_impl<_Ti, + __is_reference_wrapper<_Ti>::value, + is_bind_expression<_Ti>::value, + 0 < is_placeholder<_Ti>::value && + is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, + _TupleUj> +{ +}; + +template +struct __is_valid_bind_return +{ + static const bool value = false; +}; + +template +struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> +{ + static const bool value = __invokable<_Fp, + typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; +}; + +template +struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> +{ + static const bool value = __invokable<_Fp, + typename __mu_return::type...>::value; +}; + +template ::value> +struct __bind_return; + +template +struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> +{ + typedef typename __invoke_of + < + _Fp&, + typename __mu_return + < + _BoundArgs, + _TupleUj + >::type... + >::type type; +}; + +template +struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> +{ + typedef typename __invoke_of + < + _Fp&, + typename __mu_return + < + const _BoundArgs, + _TupleUj + >::type... + >::type type; +}; + +template +using __bind_return_t = typename __bind_return<_Fp, _BoundArgs, _TupleUj>::type; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bind_return_t<_Fp, _BoundArgs, _Args> +__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, + _Args&& __args) +{ + return _CUDA_VSTD::__invoke(__f, _CUDA_VSTD::__mu(_CUDA_VSTD::get<_Indx>(__bound_args), __args)...); +} + +template +class __bind : public __weak_result_type<__decay_t<_Fp>> +{ +protected: + typedef __decay_t<_Fp> _Fd; + typedef tuple<__decay_t<_BoundArgs>...> _Td; +private: + _Fd __f_; + _Td __bound_args_; + + typedef typename __make_tuple_indices::type __indices; +public: + template ::value && + !is_same<__libcpp_remove_reference_t<_Gp>, + __bind>::value + >> + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + explicit __bind(_Gp&& __f, _BA&& ...__bound_args) + : __f_(_CUDA_VSTD::forward<_Gp>(__f)), + __bound_args_(_CUDA_VSTD::forward<_BA>(__bound_args)...) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __bind_return_t<_Fd, _Td, tuple<_Args&&...>> + operator()(_Args&& ...__args) + { + return _CUDA_VSTD::__apply_functor(__f_, __bound_args_, __indices(), + tuple<_Args&&...>(_CUDA_VSTD::forward<_Args>(__args)...)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __bind_return_t> + operator()(_Args&& ...__args) const + { + return _CUDA_VSTD::__apply_functor(__f_, __bound_args_, __indices(), + tuple<_Args&&...>(_CUDA_VSTD::forward<_Args>(__args)...)); + } +}; + +template +struct is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; + +template +class __bind_r + : public __bind<_Fp, _BoundArgs...> +{ + typedef __bind<_Fp, _BoundArgs...> base; + typedef typename base::_Fd _Fd; + typedef typename base::_Td _Td; +public: + typedef _Rp result_type; + + + template ::value && + !is_same<__libcpp_remove_reference_t<_Gp>, + __bind_r>::value + >> + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) + : base(_CUDA_VSTD::forward<_Gp>(__f), + _CUDA_VSTD::forward<_BA>(__bound_args)...) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __enable_if_t + < + is_convertible<__bind_return_t<_Fd, _Td, tuple<_Args&&...>>, + result_type>::value || is_void<_Rp>::value, + result_type + > + operator()(_Args&& ...__args) + { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(static_cast(*this), _CUDA_VSTD::forward<_Args>(__args)...); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __enable_if_t + < + is_convertible<__bind_return_t>, + result_type>::value || is_void<_Rp>::value, + result_type + > + operator()(_Args&& ...__args) const + { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(static_cast(*this), _CUDA_VSTD::forward<_Args>(__args)...); + } +}; + +template +struct is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +__bind<_Fp, _BoundArgs...> +bind(_Fp&& __f, _BoundArgs&&... __bound_args) +{ + typedef __bind<_Fp, _BoundArgs...> type; + return type(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_BoundArgs>(__bound_args)...); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +__bind_r<_Rp, _Fp, _BoundArgs...> +bind(_Fp&& __f, _BoundArgs&&... __bound_args) +{ + typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; + return type(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_BoundArgs>(__bound_args)...); +} + +#endif // _LIBCUDACXX_CXX03_LANG + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // __cuda_std__ + +#endif // _LIBCUDACXX___FUNCTIONAL_BIND_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/bind_back.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/bind_back.h new file mode 100644 index 0000000000000000000000000000000000000000..a9a4a8896641c7f8cc995eedd291a2ef2293c3ee --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/bind_back.h @@ -0,0 +1,75 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BIND_BACK_H +#define _LIBCUDACXX___FUNCTIONAL_BIND_BACK_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/invoke.h" +#include "../__functional/perfect_forward.h" +#include "../__fwd/get.h" +#include "../__tuple_dir/tuple_size.h" +#include "../__type_traits/decay.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_move_constructible.h" +#include "../__utility/forward.h" +#include "../__utility/integer_sequence.h" + +#include "../tuple" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +template > +struct __bind_back_op; + +template +struct __bind_back_op<_NBound, index_sequence<_Ip...>> { + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr auto operator()(_Fn&& __f, _BoundArgs&& __bound_args, _Args&&... __args) const + noexcept(noexcept(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward<_Args>(__args)..., _CUDA_VSTD::get<_Ip>(_CUDA_VSTD::forward<_BoundArgs>(__bound_args))...))) + -> decltype( _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward<_Args>(__args)..., _CUDA_VSTD::get<_Ip>(_CUDA_VSTD::forward<_BoundArgs>(__bound_args))...)) + { return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward<_Args>(__args)..., _CUDA_VSTD::get<_Ip>(_CUDA_VSTD::forward<_BoundArgs>(__bound_args))...); } +}; + +template +struct __bind_back_t : __perfect_forward<__bind_back_op>, _Fn, _BoundArgs> { + using __perfect_forward<__bind_back_op>, _Fn, _BoundArgs>::__perfect_forward; +}; + +template , _Fn>, + is_move_constructible>, + is_constructible, _Args>..., + is_move_constructible>... + >::value +>> +_LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY +constexpr auto __bind_back(_Fn&& __f, _Args&&... __args) + noexcept(noexcept(__bind_back_t, tuple...>>(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::forward<_Args>(__args)...)))) + -> decltype( __bind_back_t, tuple...>>(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::forward<_Args>(__args)...))) + { return __bind_back_t, tuple...>>(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::forward<_Args>(__args)...)); } + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BIND_BACK_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/bind_front.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/bind_front.h new file mode 100644 index 0000000000000000000000000000000000000000..7ce9e676069cb7b3b922b81cedb3967795835606 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/bind_front.h @@ -0,0 +1,78 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BIND_FRONT_H +#define _LIBCUDACXX___FUNCTIONAL_BIND_FRONT_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__functional/invoke.h" +#include "../__functional/perfect_forward.h" +#include "../__type_traits/decay.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_move_constructible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +struct __bind_front_op { + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr auto operator()(_Args&& ...__args) const + noexcept(noexcept(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...)) + { return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...); } +}; + +template +struct __bind_front_t : __perfect_forward<__bind_front_op, _Fn, _BoundArgs...> { + using __base = __perfect_forward<__bind_front_op, _Fn, _BoundArgs...>; +#if defined(_LIBCUDACXX_COMPILER_NVRTC) + constexpr __bind_front_t() noexcept = default; + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __bind_front_t(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) + : __base(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else + using __base::__base; +#endif +}; + +template +_LIBCUDACXX_CONCEPT __can_bind_front = is_constructible_v, _Fn> && + is_move_constructible_v> && + (is_constructible_v, _Args> && ...) && + (is_move_constructible_v> && ... ); + +_LIBCUDACXX_TEMPLATE(class _Fn, class... _Args) + (requires __can_bind_front<_Fn, _Args...>) +_LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY +constexpr auto bind_front(_Fn&& __f, _Args&&... __args) noexcept(is_nothrow_constructible_v...>, _Args&&...>) { + return __bind_front_t, decay_t<_Args>...>(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward<_Args>(__args)...); +} + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BIND_FRONT_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binder1st.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binder1st.h new file mode 100644 index 0000000000000000000000000000000000000000..094b92cd97231ae6f065f6bbc45d7e1ec6bcdcc9 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binder1st.h @@ -0,0 +1,59 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BINDER1ST_H +#define _LIBCUDACXX___FUNCTIONAL_BINDER1ST_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/unary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 binder1st + : public __unary_function +{ +protected: + __Operation op; + typename __Operation::first_argument_type value; +public: + _LIBCUDACXX_INLINE_VISIBILITY binder1st(const __Operation& __x, + const typename __Operation::first_argument_type __y) + : op(__x), value(__y) {} + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() + (typename __Operation::second_argument_type& __x) const + {return op(value, __x);} + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() + (const typename __Operation::second_argument_type& __x) const + {return op(value, __x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +binder1st<__Operation> +bind1st(const __Operation& __op, const _Tp& __x) + {return binder1st<__Operation>(__op, __x);} + +#endif // _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BINDER1ST_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binder2nd.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binder2nd.h new file mode 100644 index 0000000000000000000000000000000000000000..e02ce01a7710d876b7e1cf783a5956371218ab68 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/binder2nd.h @@ -0,0 +1,59 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BINDER2ND_H +#define _LIBCUDACXX___FUNCTIONAL_BINDER2ND_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/unary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 binder2nd + : public __unary_function +{ +protected: + __Operation op; + typename __Operation::second_argument_type value; +public: + _LIBCUDACXX_INLINE_VISIBILITY + binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) + : op(__x), value(__y) {} + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() + ( typename __Operation::first_argument_type& __x) const + {return op(__x, value);} + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() + (const typename __Operation::first_argument_type& __x) const + {return op(__x, value);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +binder2nd<__Operation> +bind2nd(const __Operation& __op, const _Tp& __x) + {return binder2nd<__Operation>(__op, __x);} + +#endif // _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BINDER2ND_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/compose.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/compose.h new file mode 100644 index 0000000000000000000000000000000000000000..b1ab0445856307cb93162f9251a18dc53eb6b466 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/compose.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_COMPOSE_H +#define _LIBCUDACXX___FUNCTIONAL_COMPOSE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/invoke.h" +#include "../__functional/perfect_forward.h" +#include "../__type_traits/decay.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +struct __compose_op { + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr auto operator()(_Fn1&& __f1, _Fn2&& __f2, _Args&&... __args) const + noexcept(noexcept(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn2>(__f2), _CUDA_VSTD::forward<_Args>(__args)...)))) + -> decltype( _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn2>(__f2), _CUDA_VSTD::forward<_Args>(__args)...))) + { return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn2>(__f2), _CUDA_VSTD::forward<_Args>(__args)...)); } +}; + +template +struct __compose_t : __perfect_forward<__compose_op, _Fn1, _Fn2> { + using __perfect_forward<__compose_op, _Fn1, _Fn2>::__perfect_forward; +}; + +template +_LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY +constexpr auto __compose(_Fn1&& __f1, _Fn2&& __f2) + noexcept(noexcept(__compose_t, decay_t<_Fn2>>(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::forward<_Fn2>(__f2)))) + -> decltype( __compose_t, decay_t<_Fn2>>(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::forward<_Fn2>(__f2))) + { return __compose_t, decay_t<_Fn2>>(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::forward<_Fn2>(__f2)); } + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_COMPOSE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/default_searcher.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/default_searcher.h new file mode 100644 index 0000000000000000000000000000000000000000..3b76674073f7d98a599b9b6504bc986e420dc163 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/default_searcher.h @@ -0,0 +1,148 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_DEFAULT_SEARCHER_H +#define _LIBCUDACXX___FUNCTIONAL_DEFAULT_SEARCHER_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +// #include "../__algorithm/search.h" +#include "../__functional/identity.h" +#include "../__functional/operations.h" +#include "../__iterator/iterator_traits.h" +#include "../__utility/pair.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +pair<_ForwardIterator1, _ForwardIterator1> +__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, + forward_iterator_tag, forward_iterator_tag) +{ + if (__first2 == __last2) + return _CUDA_VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence + while (true) + { + // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks + while (true) + { + if (__first1 == __last1) // return __last1 if no element matches *__first2 + return _CUDA_VSTD::make_pair(__last1, __last1); + if (__pred(*__first1, *__first2)) + break; + ++__first1; + } + // *__first1 matches *__first2, now match elements after here + _ForwardIterator1 __m1 = __first1; + _ForwardIterator2 __m2 = __first2; + while (true) + { + if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) + return _CUDA_VSTD::make_pair(__first1, __m1); + if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found + return _CUDA_VSTD::make_pair(__last1, __last1); + if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 + { + ++__first1; + break; + } // else there is a match, check next elements + } + } +} + +template +_LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +pair<_RandomAccessIterator1, _RandomAccessIterator1> +__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, + _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, + random_access_iterator_tag, random_access_iterator_tag) +{ + typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _Diff1; + typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _Diff2; + // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern + const _Diff2 __len2 = __last2 - __first2; + if (__len2 == 0) + return _CUDA_VSTD::make_pair(__first1, __first1); + const _Diff1 __len1 = __last1 - __first1; + if (__len1 < __len2) + return _CUDA_VSTD::make_pair(__last1, __last1); + const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here + + while (true) + { + while (true) + { + if (__first1 == __s) + return _CUDA_VSTD::make_pair(__last1, __last1); + if (__pred(*__first1, *__first2)) + break; + ++__first1; + } + + _RandomAccessIterator1 __m1 = __first1; + _RandomAccessIterator2 __m2 = __first2; + while (true) + { + if (++__m2 == __last2) + return _CUDA_VSTD::make_pair(__first1, __first1 + __len2); + ++__m1; // no need to check range on __m1 because __s guarantees we have enough source + if (!__pred(*__m1, *__m2)) + { + ++__first1; + break; + } + } + } +} + +#ifndef __cuda_std__ + +#if _LIBCUDACXX_STD_VER > 14 + +// default searcher +template> +class _LIBCUDACXX_TEMPLATE_VIS default_searcher { +public: + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + default_searcher(_ForwardIterator __f, _ForwardIterator __l, + _BinaryPredicate __p = _BinaryPredicate()) + : __first_(__f), __last_(__l), __pred_(__p) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + pair<_ForwardIterator2, _ForwardIterator2> + operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const + { + return _CUDA_VSTD::__search(__f, __l, __first_, __last_, __pred_, + typename _CUDA_VSTD::iterator_traits<_ForwardIterator>::iterator_category(), + typename _CUDA_VSTD::iterator_traits<_ForwardIterator2>::iterator_category()); + } + +private: + _ForwardIterator __first_; + _ForwardIterator __last_; + _BinaryPredicate __pred_; +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(default_searcher); + +#endif // _LIBCUDACXX_STD_VER > 14 +#endif // __cuda_std__ + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_DEFAULT_SEARCHER_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/function.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/function.h new file mode 100644 index 0000000000000000000000000000000000000000..d04601dde9b591b0b64feccedce125320f2ae6d0 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/function.h @@ -0,0 +1,1261 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_FUNCTION_H +#define _LIBCUDACXX___FUNCTIONAL_FUNCTION_H + +#ifndef __cuda_std__ + +#ifndef __cuda_std__ +#include <__config> +#include +#include +#include +#include +#endif // __cuda_std__ + +#include "__assert" +#include "../__debug" +#include "../__functional_base" +#include "../__functional/binary_function.h" +#include "../__functional/invoke.h" +#include "../__functional/unary_function.h" +#include "../__iterator/iterator_traits.h" +#include "../__type_traits/conditional.h" +#include "../__type_traits/decay.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_nothrow_copy_constructible.h" +#include "../__type_traits/is_same.h" +#include "../__type_traits/is_scalar.h" +#include "../__type_traits/is_trivially_copy_constructible.h" +#include "../__type_traits/is_trivially_destructible.h" +#include "../__type_traits/is_void.h" +#include "../__type_traits/remove_cvref.h" +#include "../__utility/forward.h" +#include "../__utility/move.h" +#include "../__utility/piecewise_construct.h" +#include "../__utility/swap.h" +#include "../tuple" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifndef _LIBCUDACXX_CXX03_LANG + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +// bad_function_call + +class _LIBCUDACXX_EXCEPTION_ABI bad_function_call + : public exception +{ +#ifdef _LIBCUDACXX_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION +public: + virtual ~bad_function_call() _NOEXCEPT; + + virtual const char* what() const _NOEXCEPT; +#endif +}; + +_LIBCUDACXX_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY +void __throw_bad_function_call() +{ +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + throw bad_function_call(); +#else + _CUDA_VSTD::abort(); +#endif +} + +template class _LIBCUDACXX_TEMPLATE_VIS function; // undefined + +namespace __function +{ + +template +struct __maybe_derive_from_unary_function +{ +}; + +template +struct __maybe_derive_from_unary_function<_Rp(_A1)> + : public __unary_function<_A1, _Rp> +{ +}; + +template +struct __maybe_derive_from_binary_function +{ +}; + +template +struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> + : public __binary_function<_A1, _A2, _Rp> +{ +}; + +template +_LIBCUDACXX_INLINE_VISIBILITY +bool __not_null(_Fp const&) { return true; } + +template +_LIBCUDACXX_INLINE_VISIBILITY +bool __not_null(_Fp* __ptr) { return __ptr; } + +template +_LIBCUDACXX_INLINE_VISIBILITY +bool __not_null(_Ret _Class::*__ptr) { return __ptr; } + +template +_LIBCUDACXX_INLINE_VISIBILITY +bool __not_null(function<_Fp> const& __f) { return !!__f; } + +#ifdef _LIBCUDACXX_HAS_EXTENSION_BLOCKS +template +_LIBCUDACXX_INLINE_VISIBILITY +bool __not_null(_Rp (^__p)(_Args...)) { return __p; } +#endif + +} // namespace __function + +#ifndef _LIBCUDACXX_CXX03_LANG + +namespace __function { + +// __alloc_func holds a functor and an allocator. + +template class __alloc_func; +template +class __default_alloc_func; + +template +class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> +{ + __compressed_pair<_Fp, _Ap> __f_; + + public: + typedef _LIBCUDACXX_NODEBUG_TYPE _Fp _Target; + typedef _LIBCUDACXX_NODEBUG_TYPE _Ap _Alloc; + + _LIBCUDACXX_INLINE_VISIBILITY + const _Target& __target() const { return __f_.first(); } + + // WIN32 APIs may define __allocator, so use __get_allocator instead. + _LIBCUDACXX_INLINE_VISIBILITY + const _Alloc& __get_allocator() const { return __f_.second(); } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __alloc_func(_Target&& __f) + : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__f)), + _CUDA_VSTD::forward_as_tuple()) + { + } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __alloc_func(const _Target& __f, const _Alloc& __a) + : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(__f), + _CUDA_VSTD::forward_as_tuple(__a)) + { + } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __alloc_func(const _Target& __f, _Alloc&& __a) + : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(__f), + _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__a))) + { + } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __alloc_func(_Target&& __f, _Alloc&& __a) + : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__f)), + _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__a))) + { + } + + _LIBCUDACXX_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __arg) + { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_.first(), + _CUDA_VSTD::forward<_ArgTypes>(__arg)...); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __alloc_func* __clone() const + { + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type _AA; + _AA __a(__f_.second()); + typedef __allocator_destructor<_AA> _Dp; + unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a)); + return __hold.release(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); } + + static void __destroy_and_delete(__alloc_func* __f) { + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type _FunAlloc; + _FunAlloc __a(__f->__get_allocator()); + __f->destroy(); + __a.deallocate(__f, 1); + } +}; + +template +class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> { + _Fp __f_; + +public: + typedef _LIBCUDACXX_NODEBUG_TYPE _Fp _Target; + + _LIBCUDACXX_INLINE_VISIBILITY + const _Target& __target() const { return __f_; } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __default_alloc_func(_Target&& __f) : __f_(_CUDA_VSTD::move(__f)) {} + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __default_alloc_func(const _Target& __f) : __f_(__f) {} + + _LIBCUDACXX_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __arg) { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_, _CUDA_VSTD::forward<_ArgTypes>(__arg)...); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __default_alloc_func* __clone() const { + __builtin_new_allocator::__holder_t __hold = + __builtin_new_allocator::__allocate_type<__default_alloc_func>(1); + __default_alloc_func* __res = + ::new ((void*)__hold.get()) __default_alloc_func(__f_); + (void)__hold.release(); + return __res; + } + + _LIBCUDACXX_INLINE_VISIBILITY + void destroy() _NOEXCEPT { __f_.~_Target(); } + + static void __destroy_and_delete(__default_alloc_func* __f) { + __f->destroy(); + __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1); + } +}; + +// __base provides an abstract interface for copyable functors. + +template class _LIBCUDACXX_TEMPLATE_VIS __base; + +template +class __base<_Rp(_ArgTypes...)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + _LIBCUDACXX_INLINE_VISIBILITY __base() {} + _LIBCUDACXX_INLINE_VISIBILITY virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() _NOEXCEPT = 0; + virtual void destroy_deallocate() _NOEXCEPT = 0; + virtual _Rp operator()(_ArgTypes&& ...) = 0; +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const _NOEXCEPT = 0; + virtual const type_info& target_type() const _NOEXCEPT = 0; +#endif // _LIBCUDACXX_NO_RTTI +}; + +// __func implements __base for a given functor type. + +template class __func; + +template +class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> + : public __base<_Rp(_ArgTypes...)> +{ + __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_; +public: + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(_Fp&& __f) + : __f_(_CUDA_VSTD::move(__f)) {} + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(const _Fp& __f, const _Alloc& __a) + : __f_(__f, __a) {} + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(const _Fp& __f, _Alloc&& __a) + : __f_(__f, _CUDA_VSTD::move(__a)) {} + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(_Fp&& __f, _Alloc&& __a) + : __f_(_CUDA_VSTD::move(__f), _CUDA_VSTD::move(__a)) {} + + virtual __base<_Rp(_ArgTypes...)>* __clone() const; + virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; + virtual void destroy() _NOEXCEPT; + virtual void destroy_deallocate() _NOEXCEPT; + virtual _Rp operator()(_ArgTypes&&... __arg); +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const _NOEXCEPT; + virtual const type_info& target_type() const _NOEXCEPT; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +__base<_Rp(_ArgTypes...)>* +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.__get_allocator()); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a)); + return __hold.release(); +} + +template +void +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const +{ + ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator()); +} + +template +void +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT +{ + __f_.destroy(); +} + +template +void +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.__get_allocator()); + __f_.destroy(); + __a.deallocate(this, 1); +} + +template +_Rp +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) +{ + return __f_(_CUDA_VSTD::forward<_ArgTypes>(__arg)...); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const void* +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT +{ + if (__ti == typeid(_Fp)) + return _CUDA_VSTD::addressof(__f_.__target()); + return nullptr; +} + +template +const type_info& +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT +{ + return typeid(_Fp); +} + +#endif // _LIBCUDACXX_NO_RTTI + +// __value_func creates a value-type from a __func. + +template class __value_func; + +template class __value_func<_Rp(_ArgTypes...)> +{ + typename aligned_storage<3 * sizeof(void*)>::type __buf_; + + typedef __base<_Rp(_ArgTypes...)> __func; + __func* __f_; + + _LIBCUDACXX_NO_CFI static __func* __as_base(void* __p) + { + return reinterpret_cast<__func*>(__p); + } + + public: + _LIBCUDACXX_INLINE_VISIBILITY + __value_func() _NOEXCEPT : __f_(nullptr) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a) + : __f_(nullptr) + { + typedef allocator_traits<_Alloc> __alloc_traits; + typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; + typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type _FunAlloc; + + if (__function::__not_null(__f)) + { + _FunAlloc __af(__a); + if (sizeof(_Fun) <= sizeof(__buf_) && + is_nothrow_copy_constructible<_Fp>::value && + is_nothrow_copy_constructible<_FunAlloc>::value) + { + __f_ = + ::new ((void*)&__buf_) _Fun(_CUDA_VSTD::move(__f), _Alloc(__af)); + } + else + { + typedef __allocator_destructor<_FunAlloc> _Dp; + unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); + ::new ((void*)__hold.get()) _Fun(_CUDA_VSTD::move(__f), _Alloc(__a)); + __f_ = __hold.release(); + } + } + } + + template , __value_func>::value>> + _LIBCUDACXX_INLINE_VISIBILITY explicit __value_func(_Fp&& __f) + : __value_func(_CUDA_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {} + + _LIBCUDACXX_INLINE_VISIBILITY + __value_func(const __value_func& __f) + { + if (__f.__f_ == nullptr) + __f_ = nullptr; + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f_ = __as_base(&__buf_); + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __value_func(__value_func&& __f) _NOEXCEPT + { + if (__f.__f_ == nullptr) + __f_ = nullptr; + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f_ = __as_base(&__buf_); + __f.__f_->__clone(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = nullptr; + } + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__value_func() + { + if ((void*)__f_ == &__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __value_func& operator=(__value_func&& __f) + { + *this = nullptr; + if (__f.__f_ == nullptr) + __f_ = nullptr; + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f_ = __as_base(&__buf_); + __f.__f_->__clone(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = nullptr; + } + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __value_func& operator=(nullptr_t) + { + __func* __f = __f_; + __f_ = nullptr; + if ((void*)__f == &__buf_) + __f->destroy(); + else if (__f) + __f->destroy_deallocate(); + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __args) const + { + if (__f_ == nullptr) + __throw_bad_function_call(); + return (*__f_)(_CUDA_VSTD::forward<_ArgTypes>(__args)...); + } + + _LIBCUDACXX_INLINE_VISIBILITY + void swap(__value_func& __f) _NOEXCEPT + { + if (&__f == this) + return; + if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __func* __t = __as_base(&__tempbuf); + __f_->__clone(__t); + __f_->destroy(); + __f_ = nullptr; + __f.__f_->__clone(__as_base(&__buf_)); + __f.__f_->destroy(); + __f.__f_ = nullptr; + __f_ = __as_base(&__buf_); + __t->__clone(__as_base(&__f.__buf_)); + __t->destroy(); + __f.__f_ = __as_base(&__f.__buf_); + } + else if ((void*)__f_ == &__buf_) + { + __f_->__clone(__as_base(&__f.__buf_)); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = __as_base(&__f.__buf_); + } + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f.__f_->__clone(__as_base(&__buf_)); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = __as_base(&__buf_); + } + else + _CUDA_VSTD::swap(__f_, __f.__f_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != nullptr; } + +#ifndef _LIBCUDACXX_NO_RTTI + _LIBCUDACXX_INLINE_VISIBILITY + const type_info& target_type() const _NOEXCEPT + { + if (__f_ == nullptr) + return typeid(void); + return __f_->target_type(); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT + { + if (__f_ == nullptr) + return nullptr; + return (const _Tp*)__f_->target(typeid(_Tp)); + } +#endif // _LIBCUDACXX_NO_RTTI +}; + +// Storage for a functor object, to be used with __policy to manage copy and +// destruction. +union __policy_storage +{ + mutable char __small[sizeof(void*) * 2]; + void* __large; +}; + +// True if _Fun can safely be held in __policy_storage.__small. +template +struct __use_small_storage + : public integral_constant< + bool, sizeof(_Fun) <= sizeof(__policy_storage) && + _LIBCUDACXX_ALIGNOF(_Fun) <= _LIBCUDACXX_ALIGNOF(__policy_storage) && + is_trivially_copy_constructible<_Fun>::value && + is_trivially_destructible<_Fun>::value> {}; + +// Policy contains information about how to copy, destroy, and move the +// underlying functor. You can think of it as a vtable of sorts. +struct __policy +{ + // Used to copy or destroy __large values. null for trivial objects. + void* (*const __clone)(const void*); + void (*const __destroy)(void*); + + // True if this is the null policy (no value). + const bool __is_null; + + // The target type. May be null if RTTI is disabled. + const type_info* const __type_info; + + // Returns a pointer to a static policy object suitable for the functor + // type. + template + _LIBCUDACXX_INLINE_VISIBILITY static const __policy* __create() + { + return __choose_policy<_Fun>(__use_small_storage<_Fun>()); + } + + _LIBCUDACXX_INLINE_VISIBILITY + static const __policy* __create_empty() + { + static const _LIBCUDACXX_CONSTEXPR __policy __policy_ = {nullptr, nullptr, + true, +#ifndef _LIBCUDACXX_NO_RTTI + &typeid(void) +#else + nullptr +#endif + }; + return &__policy_; + } + + private: + template static void* __large_clone(const void* __s) + { + const _Fun* __f = static_cast(__s); + return __f->__clone(); + } + + template + static void __large_destroy(void* __s) { + _Fun::__destroy_and_delete(static_cast<_Fun*>(__s)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY static const __policy* + __choose_policy(/* is_small = */ false_type) { + static const _LIBCUDACXX_CONSTEXPR __policy __policy_ = { + &__large_clone<_Fun>, &__large_destroy<_Fun>, false, +#ifndef _LIBCUDACXX_NO_RTTI + &typeid(typename _Fun::_Target) +#else + nullptr +#endif + }; + return &__policy_; + } + + template + _LIBCUDACXX_INLINE_VISIBILITY static const __policy* + __choose_policy(/* is_small = */ true_type) + { + static const _LIBCUDACXX_CONSTEXPR __policy __policy_ = { + nullptr, nullptr, false, +#ifndef _LIBCUDACXX_NO_RTTI + &typeid(typename _Fun::_Target) +#else + nullptr +#endif + }; + return &__policy_; + } +}; + +// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is +// faster for types that can be passed in registers. +template +using __fast_forward = __conditional_t::value, _Tp, _Tp&&>; + +// __policy_invoker calls an instance of __alloc_func held in __policy_storage. + +template struct __policy_invoker; + +template +struct __policy_invoker<_Rp(_ArgTypes...)> +{ + typedef _Rp (*__Call)(const __policy_storage*, + __fast_forward<_ArgTypes>...); + + __Call __call_; + + // Creates an invoker that throws bad_function_call. + _LIBCUDACXX_INLINE_VISIBILITY + __policy_invoker() : __call_(&__call_empty) {} + + // Creates an invoker that calls the given instance of __func. + template + _LIBCUDACXX_INLINE_VISIBILITY static __policy_invoker __create() + { + return __policy_invoker(&__call_impl<_Fun>); + } + + private: + _LIBCUDACXX_INLINE_VISIBILITY + explicit __policy_invoker(__Call __c) : __call_(__c) {} + + static _Rp __call_empty(const __policy_storage*, + __fast_forward<_ArgTypes>...) + { + __throw_bad_function_call(); + } + + template + static _Rp __call_impl(const __policy_storage* __buf, + __fast_forward<_ArgTypes>... __args) + { + _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value + ? &__buf->__small + : __buf->__large); + return (*__f)(_CUDA_VSTD::forward<_ArgTypes>(__args)...); + } +}; + +// __policy_func uses a __policy and __policy_invoker to create a type-erased, +// copyable functor. + +template class __policy_func; + +template class __policy_func<_Rp(_ArgTypes...)> +{ + // Inline storage for small objects. + __policy_storage __buf_; + + // Calls the value stored in __buf_. This could technically be part of + // policy, but storing it here eliminates a level of indirection inside + // operator(). + typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker; + __invoker __invoker_; + + // The policy that describes how to move / copy / destroy __buf_. Never + // null, even if the function is empty. + const __policy* __policy_; + + public: + _LIBCUDACXX_INLINE_VISIBILITY + __policy_func() : __policy_(__policy::__create_empty()) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a) + : __policy_(__policy::__create_empty()) + { + typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type _FunAlloc; + + if (__function::__not_null(__f)) + { + __invoker_ = __invoker::template __create<_Fun>(); + __policy_ = __policy::__create<_Fun>(); + + _FunAlloc __af(__a); + if (__use_small_storage<_Fun>()) + { + ::new ((void*)&__buf_.__small) + _Fun(_CUDA_VSTD::move(__f), _Alloc(__af)); + } + else + { + typedef __allocator_destructor<_FunAlloc> _Dp; + unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); + ::new ((void*)__hold.get()) + _Fun(_CUDA_VSTD::move(__f), _Alloc(__af)); + __buf_.__large = __hold.release(); + } + } + } + + template , __policy_func>::value>> + _LIBCUDACXX_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f) + : __policy_(__policy::__create_empty()) { + typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun; + + if (__function::__not_null(__f)) { + __invoker_ = __invoker::template __create<_Fun>(); + __policy_ = __policy::__create<_Fun>(); + if (__use_small_storage<_Fun>()) { + ::new ((void*)&__buf_.__small) _Fun(_CUDA_VSTD::move(__f)); + } else { + __builtin_new_allocator::__holder_t __hold = + __builtin_new_allocator::__allocate_type<_Fun>(1); + __buf_.__large = ::new ((void*)__hold.get()) _Fun(_CUDA_VSTD::move(__f)); + (void)__hold.release(); + } + } + } + + _LIBCUDACXX_INLINE_VISIBILITY + __policy_func(const __policy_func& __f) + : __buf_(__f.__buf_), __invoker_(__f.__invoker_), + __policy_(__f.__policy_) + { + if (__policy_->__clone) + __buf_.__large = __policy_->__clone(__f.__buf_.__large); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __policy_func(__policy_func&& __f) + : __buf_(__f.__buf_), __invoker_(__f.__invoker_), + __policy_(__f.__policy_) + { + if (__policy_->__destroy) + { + __f.__policy_ = __policy::__create_empty(); + __f.__invoker_ = __invoker(); + } + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__policy_func() + { + if (__policy_->__destroy) + __policy_->__destroy(__buf_.__large); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __policy_func& operator=(__policy_func&& __f) + { + *this = nullptr; + __buf_ = __f.__buf_; + __invoker_ = __f.__invoker_; + __policy_ = __f.__policy_; + __f.__policy_ = __policy::__create_empty(); + __f.__invoker_ = __invoker(); + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __policy_func& operator=(nullptr_t) + { + const __policy* __p = __policy_; + __policy_ = __policy::__create_empty(); + __invoker_ = __invoker(); + if (__p->__destroy) + __p->__destroy(__buf_.__large); + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __args) const + { + return __invoker_.__call_(_CUDA_VSTD::addressof(__buf_), + _CUDA_VSTD::forward<_ArgTypes>(__args)...); + } + + _LIBCUDACXX_INLINE_VISIBILITY + void swap(__policy_func& __f) + { + _CUDA_VSTD::swap(__invoker_, __f.__invoker_); + _CUDA_VSTD::swap(__policy_, __f.__policy_); + _CUDA_VSTD::swap(__buf_, __f.__buf_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit operator bool() const _NOEXCEPT + { + return !__policy_->__is_null; + } + +#ifndef _LIBCUDACXX_NO_RTTI + _LIBCUDACXX_INLINE_VISIBILITY + const type_info& target_type() const _NOEXCEPT + { + return *__policy_->__type_info; + } + + template + _LIBCUDACXX_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT + { + if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info) + return nullptr; + if (__policy_->__clone) // Out of line storage. + return reinterpret_cast(__buf_.__large); + else + return reinterpret_cast(&__buf_.__small); + } +#endif // _LIBCUDACXX_NO_RTTI +}; + +#if defined(_LIBCUDACXX_HAS_BLOCKS_RUNTIME) + +extern "C" void *_Block_copy(const void *); +extern "C" void _Block_release(const void *); + +template +class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> + : public __base<_Rp(_ArgTypes...)> +{ + typedef _Rp1(^__block_type)(_ArgTypes1...); + __block_type __f_; + +public: + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(__block_type const& __f) +#ifdef _LIBCUDACXX_HAS_OBJC_ARC + : __f_(__f) +#else + : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) +#endif + { } + + // [TODO] add && to save on a retain + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(__block_type __f, const _Alloc& /* unused */) +#ifdef _LIBCUDACXX_HAS_OBJC_ARC + : __f_(__f) +#else + : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) +#endif + { } + + virtual __base<_Rp(_ArgTypes...)>* __clone() const { + _LIBCUDACXX_ASSERT(false, + "Block pointers are just pointers, so they should always fit into " + "std::function's small buffer optimization. This function should " + "never be invoked."); + return nullptr; + } + + virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const { + ::new ((void*)__p) __func(__f_); + } + + virtual void destroy() _NOEXCEPT { +#ifndef _LIBCUDACXX_HAS_OBJC_ARC + if (__f_) + _Block_release(__f_); +#endif + __f_ = 0; + } + + virtual void destroy_deallocate() _NOEXCEPT { + _LIBCUDACXX_ASSERT(false, + "Block pointers are just pointers, so they should always fit into " + "std::function's small buffer optimization. This function should " + "never be invoked."); + } + + virtual _Rp operator()(_ArgTypes&& ... __arg) { + return _CUDA_VSTD::__invoke(__f_, _CUDA_VSTD::forward<_ArgTypes>(__arg)...); + } + +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(type_info const& __ti) const _NOEXCEPT { + if (__ti == typeid(__func::__block_type)) + return &__f_; + return (const void*)nullptr; + } + + virtual const type_info& target_type() const _NOEXCEPT { + return typeid(__func::__block_type); + } +#endif // _LIBCUDACXX_NO_RTTI +}; + +#endif // _LIBCUDACXX_HAS_EXTENSION_BLOCKS + +} // namespace __function + +template +class _LIBCUDACXX_TEMPLATE_VIS function<_Rp(_ArgTypes...)> + : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, + public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> +{ +#ifndef _LIBCUDACXX_ABI_OPTIMIZED_FUNCTION + typedef __function::__value_func<_Rp(_ArgTypes...)> __func; +#else + typedef __function::__policy_func<_Rp(_ArgTypes...)> __func; +#endif + + __func __f_; + + template , function>, + __invokable<_Fp, _ArgTypes...> + >::value> + struct __callable; + template + struct __callable<_Fp, true> + { + static const bool value = is_void<_Rp>::value || + __is_core_convertible::type, + _Rp>::value; + }; + template + struct __callable<_Fp, false> + { + static const bool value = false; + }; + + template + using _EnableIfLValueCallable = __enable_if_t<__callable<_Fp&>::value>; +public: + typedef _Rp result_type; + + // construct/copy/destroy: + _LIBCUDACXX_INLINE_VISIBILITY + function() _NOEXCEPT { } + _LIBCUDACXX_INLINE_VISIBILITY + function(nullptr_t) _NOEXCEPT {} + function(const function&); + function(function&&) _NOEXCEPT; + template> + function(_Fp); + +#if _LIBCUDACXX_STD_VER <= 14 + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) _NOEXCEPT {} + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {} + template + function(allocator_arg_t, const _Alloc&, const function&); + template + function(allocator_arg_t, const _Alloc&, function&&); + template> + function(allocator_arg_t, const _Alloc& __a, _Fp __f); +#endif + + function& operator=(const function&); + function& operator=(function&&) _NOEXCEPT; + function& operator=(nullptr_t) _NOEXCEPT; + template>> + function& operator=(_Fp&&); + + ~function(); + + // function modifiers: + void swap(function&) _NOEXCEPT; + +#if _LIBCUDACXX_STD_VER <= 14 + template + _LIBCUDACXX_INLINE_VISIBILITY + void assign(_Fp&& __f, const _Alloc& __a) + {function(allocator_arg, __a, _CUDA_VSTD::forward<_Fp>(__f)).swap(*this);} +#endif + + // function capacity: + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_EXPLICIT operator bool() const _NOEXCEPT { + return static_cast(__f_); + } + + // deleted overloads close possible hole in the type system + template + bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; + template + bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; +public: + // function invocation: + _Rp operator()(_ArgTypes...) const; + +#ifndef _LIBCUDACXX_NO_RTTI + // function target access: + const type_info& target_type() const _NOEXCEPT; + template _Tp* target() _NOEXCEPT; + template const _Tp* target() const _NOEXCEPT; +#endif // _LIBCUDACXX_NO_RTTI +}; + +#if _LIBCUDACXX_STD_VER > 14 +template +function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>; + +template +struct __strip_signature; + +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); }; + +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); }; + +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); }; + +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); }; + +template::type> +function(_Fp) -> function<_Stripped>; +#endif // _LIBCUDACXX_STD_VER > 14 + +template +function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {} + +#if _LIBCUDACXX_STD_VER <= 14 +template +template +function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, + const function& __f) : __f_(__f.__f_) {} +#endif + +template +function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT + : __f_(_CUDA_VSTD::move(__f.__f_)) {} + +#if _LIBCUDACXX_STD_VER <= 14 +template +template +function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, + function&& __f) + : __f_(_CUDA_VSTD::move(__f.__f_)) {} +#endif + +template +template +function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_CUDA_VSTD::move(__f)) {} + +#if _LIBCUDACXX_STD_VER <= 14 +template +template +function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a, + _Fp __f) + : __f_(_CUDA_VSTD::move(__f), __a) {} +#endif + +template +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(const function& __f) +{ + function(__f).swap(*this); + return *this; +} + +template +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT +{ + __f_ = _CUDA_VSTD::move(__f.__f_); + return *this; +} + +template +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT +{ + __f_ = nullptr; + return *this; +} + +template +template +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) +{ + function(_CUDA_VSTD::forward<_Fp>(__f)).swap(*this); + return *this; +} + +template +function<_Rp(_ArgTypes...)>::~function() {} + +template +void +function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT +{ + __f_.swap(__f.__f_); +} + +template +_Rp +function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const +{ + return __f_(_CUDA_VSTD::forward<_ArgTypes>(__arg)...); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const type_info& +function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT +{ + return __f_.target_type(); +} + +template +template +_Tp* +function<_Rp(_ArgTypes...)>::target() _NOEXCEPT +{ + return (_Tp*)(__f_.template target<_Tp>()); +} + +template +template +const _Tp* +function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT +{ + return __f_.template target<_Tp>(); +} + +#endif // _LIBCUDACXX_NO_RTTI + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT +{return __x.swap(__y);} + +#else // _LIBCUDACXX_CXX03_LANG + +#include <__functional_03> + +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_CXX03_LANG + +#endif // __cuda_std__ + +#endif // _LIBCUDACXX___FUNCTIONAL_FUNCTION_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/hash.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/hash.h new file mode 100644 index 0000000000000000000000000000000000000000..0c4805145a17a536582321da55192e793d64ac4e --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/hash.h @@ -0,0 +1,692 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_HASH_H +#define _LIBCUDACXX___FUNCTIONAL_HASH_H + +#ifndef __cuda_std__ +#include <__config> +#include +#endif // __cuda_std__ + +#include "../__functional/invoke.h" +#include "../__functional/unary_function.h" +#include "../__fwd/hash.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/is_enum.h" +#include "../__type_traits/is_copy_constructible.h" +#include "../__type_traits/is_default_constructible.h" +#include "../__type_traits/is_move_constructible.h" +#include "../__type_traits/underlying_type.h" +#include "../__utility/forward.h" +#include "../__utility/move.h" +#include "../__utility/pair.h" +#include "../__utility/swap.h" +#include "../cstdint" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifndef __cuda_std__ + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +_Size +__loadword(const void* __p) +{ + _Size __r; + std::memcpy(&__r, __p, sizeof(__r)); + return __r; +} + +// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t +// is 64 bits. This is because cityhash64 uses 64bit x 64bit +// multiplication, which can be very slow on 32-bit systems. +template +struct __murmur2_or_cityhash; + +template +struct __murmur2_or_cityhash<_Size, 32> +{ + inline _Size operator()(const void* __key, _Size __len) + _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK; +}; + +// murmur2 +template +_Size +__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) +{ + const _Size __m = 0x5bd1e995; + const _Size __r = 24; + _Size __h = __len; + const unsigned char* __data = static_cast(__key); + for (; __len >= 4; __data += 4, __len -= 4) + { + _Size __k = __loadword<_Size>(__data); + __k *= __m; + __k ^= __k >> __r; + __k *= __m; + __h *= __m; + __h ^= __k; + } + switch (__len) + { + case 3: + __h ^= static_cast<_Size>(__data[2] << 16); + _LIBCUDACXX_FALLTHROUGH(); + case 2: + __h ^= static_cast<_Size>(__data[1] << 8); + _LIBCUDACXX_FALLTHROUGH(); + case 1: + __h ^= __data[0]; + __h *= __m; + } + __h ^= __h >> 13; + __h *= __m; + __h ^= __h >> 15; + return __h; +} + +template +struct __murmur2_or_cityhash<_Size, 64> +{ + inline _Size operator()(const void* __key, _Size __len) _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK; + + private: + // Some primes between 2^63 and 2^64. + static const _Size __k0 = 0xc3a5c85c97cb3127ULL; + static const _Size __k1 = 0xb492b66fbe98f273ULL; + static const _Size __k2 = 0x9ae16a3b2f90404fULL; + static const _Size __k3 = 0xc949d7c7509e6557ULL; + + static _Size __rotate(_Size __val, int __shift) { + return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift))); + } + + static _Size __rotate_by_at_least_1(_Size __val, int __shift) { + return (__val >> __shift) | (__val << (64 - __shift)); + } + + static _Size __shift_mix(_Size __val) { + return __val ^ (__val >> 47); + } + + static _Size __hash_len_16(_Size __u, _Size __v) + _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + const _Size __mul = 0x9ddfea08eb382d69ULL; + _Size __a = (__u ^ __v) * __mul; + __a ^= (__a >> 47); + _Size __b = (__v ^ __a) * __mul; + __b ^= (__b >> 47); + __b *= __mul; + return __b; + } + + static _Size __hash_len_0_to_16(const char* __s, _Size __len) + _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + if (__len > 8) { + const _Size __a = __loadword<_Size>(__s); + const _Size __b = __loadword<_Size>(__s + __len - 8); + return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b; + } + if (__len >= 4) { + const uint32_t __a = __loadword(__s); + const uint32_t __b = __loadword(__s + __len - 4); + return __hash_len_16(__len + (static_cast<_Size>(__a) << 3), __b); + } + if (__len > 0) { + const unsigned char __a = static_cast(__s[0]); + const unsigned char __b = static_cast(__s[__len >> 1]); + const unsigned char __c = static_cast(__s[__len - 1]); + const uint32_t __y = static_cast(__a) + + (static_cast(__b) << 8); + const uint32_t __z = __len + (static_cast(__c) << 2); + return __shift_mix(__y * __k2 ^ __z * __k3) * __k2; + } + return __k2; + } + + static _Size __hash_len_17_to_32(const char *__s, _Size __len) + _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + const _Size __a = __loadword<_Size>(__s) * __k1; + const _Size __b = __loadword<_Size>(__s + 8); + const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2; + const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0; + return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d, + __a + __rotate(__b ^ __k3, 20) - __c + __len); + } + + // Return a 16-byte hash for 48 bytes. Quick and dirty. + // Callers do best to use "random-looking" values for a and b. + static pair<_Size, _Size> __weak_hash_len_32_with_seeds( + _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) + _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + __a += __w; + __b = __rotate(__b + __a + __z, 21); + const _Size __c = __a; + __a += __x; + __a += __y; + __b += __rotate(__a, 44); + return pair<_Size, _Size>(__a + __z, __b + __c); + } + + // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty. + static pair<_Size, _Size> __weak_hash_len_32_with_seeds( + const char* __s, _Size __a, _Size __b) + _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s), + __loadword<_Size>(__s + 8), + __loadword<_Size>(__s + 16), + __loadword<_Size>(__s + 24), + __a, + __b); + } + + // Return an 8-byte hash for 33 to 64 bytes. + static _Size __hash_len_33_to_64(const char *__s, size_t __len) + _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + _Size __z = __loadword<_Size>(__s + 24); + _Size __a = __loadword<_Size>(__s) + + (__len + __loadword<_Size>(__s + __len - 16)) * __k0; + _Size __b = __rotate(__a + __z, 52); + _Size __c = __rotate(__a, 37); + __a += __loadword<_Size>(__s + 8); + __c += __rotate(__a, 7); + __a += __loadword<_Size>(__s + 16); + _Size __vf = __a + __z; + _Size __vs = __b + __rotate(__a, 31) + __c; + __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32); + __z += __loadword<_Size>(__s + __len - 8); + __b = __rotate(__a + __z, 52); + __c = __rotate(__a, 37); + __a += __loadword<_Size>(__s + __len - 24); + __c += __rotate(__a, 7); + __a += __loadword<_Size>(__s + __len - 16); + _Size __wf = __a + __z; + _Size __ws = __b + __rotate(__a, 31) + __c; + _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0); + return __shift_mix(__r * __k0 + __vs) * __k2; + } +}; + +// cityhash64 +template +_Size +__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) +{ + const char* __s = static_cast(__key); + if (__len <= 32) { + if (__len <= 16) { + return __hash_len_0_to_16(__s, __len); + } else { + return __hash_len_17_to_32(__s, __len); + } + } else if (__len <= 64) { + return __hash_len_33_to_64(__s, __len); + } + + // For strings over 64 bytes we hash the end first, and then as we + // loop we keep 56 bytes of state: v, w, x, y, and z. + _Size __x = __loadword<_Size>(__s + __len - 40); + _Size __y = __loadword<_Size>(__s + __len - 16) + + __loadword<_Size>(__s + __len - 56); + _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len, + __loadword<_Size>(__s + __len - 24)); + pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z); + pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x); + __x = __x * __k1 + __loadword<_Size>(__s); + + // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. + __len = (__len - 1) & ~static_cast<_Size>(63); + do { + __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1; + __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1; + __x ^= __w.second; + __y += __v.first + __loadword<_Size>(__s + 40); + __z = __rotate(__z + __w.first, 33) * __k1; + __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first); + __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second, + __y + __loadword<_Size>(__s + 16)); + _CUDA_VSTD::swap(__z, __x); + __s += 64; + __len -= 64; + } while (__len != 0); + return __hash_len_16( + __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z, + __hash_len_16(__v.second, __w.second) + __x); +} + +template +struct __scalar_hash; + +template +struct __scalar_hash<_Tp, 0> + : public __unary_function<_Tp, size_t> +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + size_t __a; + } __u; + __u.__a = 0; + __u.__t = __v; + return __u.__a; + } +}; + +template +struct __scalar_hash<_Tp, 1> + : public __unary_function<_Tp, size_t> +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + size_t __a; + } __u; + __u.__t = __v; + return __u.__a; + } +}; + +template +struct __scalar_hash<_Tp, 2> + : public __unary_function<_Tp, size_t> +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + struct + { + size_t __a; + size_t __b; + } __s; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash()(&__u, sizeof(__u)); + } +}; + +template +struct __scalar_hash<_Tp, 3> + : public __unary_function<_Tp, size_t> +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + struct + { + size_t __a; + size_t __b; + size_t __c; + } __s; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash()(&__u, sizeof(__u)); + } +}; + +template +struct __scalar_hash<_Tp, 4> + : public __unary_function<_Tp, size_t> +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + struct + { + size_t __a; + size_t __b; + size_t __c; + size_t __d; + } __s; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash()(&__u, sizeof(__u)); + } +}; + +struct _PairT { + size_t first; + size_t second; +}; + +_LIBCUDACXX_INLINE_VISIBILITY +inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT { + typedef __scalar_hash<_PairT> _HashT; + const _PairT __p = {__lhs, __rhs}; + return _HashT()(__p); +} + +template +struct _LIBCUDACXX_TEMPLATE_VIS hash<_Tp*> + : public __unary_function<_Tp*, size_t> +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(_Tp* __v) const _NOEXCEPT + { + union + { + _Tp* __t; + size_t __a; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash()(&__u, sizeof(__u)); + } +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(bool __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(char __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(signed char __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast(__v);} +}; + +#ifndef _LIBCUDACXX_HAS_NO_UNICODE_CHARS +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast(__v);} +}; +#endif // _LIBCUDACXX_HAS_NO_UNICODE_CHARS + +#ifndef _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast(__v);} +}; +#endif // _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(short __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(int __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(long __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __scalar_hash +{ +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __scalar_hash +{ +}; + +#ifndef _LIBCUDACXX_HAS_NO_INT128 + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash<__int128_t> + : public __scalar_hash<__int128_t> +{ +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash<__uint128_t> + : public __scalar_hash<__uint128_t> +{ +}; + +#endif + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __scalar_hash +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(float __v) const _NOEXCEPT + { + // -0.0 and 0.0 should return same hash + if (__v == 0.0f) + return 0; + return __scalar_hash::operator()(__v); + } +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __scalar_hash +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(double __v) const _NOEXCEPT + { + // -0.0 and 0.0 should return same hash + if (__v == 0.0) + return 0; + return __scalar_hash::operator()(__v); + } +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __scalar_hash +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(long double __v) const _NOEXCEPT + { + // -0.0 and 0.0 should return same hash + if (__v == 0.0L) + return 0; +#if defined(__i386__) || (defined(__x86_64__) && defined(__ILP32__)) + // Zero out padding bits + union + { + long double __t; + struct + { + size_t __a; + size_t __b; + size_t __c; + size_t __d; + } __s; + } __u; + __u.__s.__a = 0; + __u.__s.__b = 0; + __u.__s.__c = 0; + __u.__s.__d = 0; + __u.__t = __v; + return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d; +#elif defined(__x86_64__) + // Zero out padding bits + union + { + long double __t; + struct + { + size_t __a; + size_t __b; + } __s; + } __u; + __u.__s.__a = 0; + __u.__s.__b = 0; + __u.__t = __v; + return __u.__s.__a ^ __u.__s.__b; +#else + return __scalar_hash::operator()(__v); +#endif + } +}; + +template ::value> +struct _LIBCUDACXX_TEMPLATE_VIS __enum_hash + : public __unary_function<_Tp, size_t> +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + typedef typename underlying_type<_Tp>::type type; + return hash()(static_cast(__v)); + } +}; +template +struct _LIBCUDACXX_TEMPLATE_VIS __enum_hash<_Tp, false> { + __enum_hash() = delete; + __enum_hash(__enum_hash const&) = delete; + __enum_hash& operator=(__enum_hash const&) = delete; +}; + +template +struct _LIBCUDACXX_TEMPLATE_VIS hash : public __enum_hash<_Tp> +{ +}; + +#if _LIBCUDACXX_STD_VER > 14 + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS hash + : public __unary_function +{ + _LIBCUDACXX_INLINE_VISIBILITY + size_t operator()(nullptr_t) const _NOEXCEPT { + return 662607004ull; + } +}; +#endif + +#ifndef _LIBCUDACXX_CXX03_LANG +template +using __check_hash_requirements _LIBCUDACXX_NODEBUG_TYPE = integral_constant::value && + is_move_constructible<_Hash>::value && + __invokable_r::value +>; + +template > +using __has_enabled_hash _LIBCUDACXX_NODEBUG_TYPE = integral_constant::value && + is_default_constructible<_Hash>::value +>; + +#if _LIBCUDACXX_STD_VER > 14 +template +using __enable_hash_helper_imp _LIBCUDACXX_NODEBUG_TYPE = _Type; + +template +using __enable_hash_helper _LIBCUDACXX_NODEBUG_TYPE = __enable_hash_helper_imp<_Type, + __enable_if_t<__all<__has_enabled_hash<_Keys>::value...>::value> +>; +#else +template +using __enable_hash_helper _LIBCUDACXX_NODEBUG_TYPE = _Type; +#endif + +#endif // !_LIBCUDACXX_CXX03_LANG + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // __cuda_std__ + +#endif // _LIBCUDACXX___FUNCTIONAL_HASH_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/identity.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/identity.h new file mode 100644 index 0000000000000000000000000000000000000000..592bc7d2f85bf104c141f66bac9ff9ed174ed9fd --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/identity.h @@ -0,0 +1,50 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_IDENTITY_H +#define _LIBCUDACXX___FUNCTIONAL_IDENTITY_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +struct __identity { + template + _LIBCUDACXX_NODISCARD_EXT _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR _Tp&& operator()(_Tp&& __t) const _NOEXCEPT { + return _CUDA_VSTD::forward<_Tp>(__t); + } + + using is_transparent = void; +}; + +#if _LIBCUDACXX_STD_VER > 11 + +struct identity { + template + _LIBCUDACXX_NODISCARD_EXT _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp&& operator()(_Tp&& __t) const noexcept + { + return _CUDA_VSTD::forward<_Tp>(__t); + } + + using is_transparent = void; +}; +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_IDENTITY_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/invoke.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/invoke.h new file mode 100644 index 0000000000000000000000000000000000000000..6def3acfbb397b6fe32024a1160506c07b73a05b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/invoke.h @@ -0,0 +1,561 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_INVOKE_H +#define _LIBCUDACXX___FUNCTIONAL_INVOKE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__type_traits/add_lvalue_reference.h" +#include "../__type_traits/apply_cv.h" +#include "../__type_traits/conditional.h" +#include "../__type_traits/decay.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/is_base_of.h" +#include "../__type_traits/is_core_convertible.h" +#include "../__type_traits/is_member_function_pointer.h" +#include "../__type_traits/is_member_object_pointer.h" +#include "../__type_traits/is_reference_wrapper.h" +#include "../__type_traits/is_same.h" +#include "../__type_traits/is_void.h" +#include "../__type_traits/nat.h" +#include "../__type_traits/remove_cv.h" +#include "../__utility/declval.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +// TODO: Disentangle the type traits and _CUDA_VSTD::invoke properly + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +struct __any +{ + _LIBCUDACXX_INLINE_VISIBILITY __any(...); +}; + +template +struct __member_pointer_traits_imp +{ +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false> +{ + typedef _Class& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &, true, false> +{ + typedef _Class& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false> +{ + typedef _Class const& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&, true, false> +{ + typedef _Class const& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false> +{ + typedef _Class volatile& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&, true, false> +{ + typedef _Class volatile& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false> +{ + typedef _Class const volatile& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&, true, false> +{ + typedef _Class const volatile& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false> +{ + typedef _Class&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &&, true, false> +{ + typedef _Class&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false> +{ + typedef _Class const&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&&, true, false> +{ + typedef _Class const&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false> +{ + typedef _Class volatile&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&&, true, false> +{ + typedef _Class volatile&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false> +{ + typedef _Class const volatile&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&&, true, false> +{ + typedef _Class const volatile&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template +struct __member_pointer_traits_imp<_Rp _Class::*, false, true> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; +}; + +template +struct __member_pointer_traits + : public __member_pointer_traits_imp<__remove_cv_t<_MP>, + is_member_function_pointer<_MP>::value, + is_member_object_pointer<_MP>::value> +{ +// typedef ... _ClassType; +// typedef ... _ReturnType; +// typedef ... _FnType; +}; + +template +struct __member_pointer_class_type {}; + +template +struct __member_pointer_class_type<_Ret _ClassType::*> { + typedef _ClassType type; +}; + +template , + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet1 = __enable_if_t + < + is_member_function_pointer<_DecayFp>::value + && is_base_of<_ClassT, _DecayA0>::value + >; + +template , + class _DecayA0 = typename decay<_A0>::type> +using __enable_if_bullet2 = __enable_if_t + < + is_member_function_pointer<_DecayFp>::value + && __is_reference_wrapper<_DecayA0>::value + >; + +template , + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet3 =__enable_if_t + < + is_member_function_pointer<_DecayFp>::value + && !is_base_of<_ClassT, _DecayA0>::value + && !__is_reference_wrapper<_DecayA0>::value + >; + +template , + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet4 = __enable_if_t + < + is_member_object_pointer<_DecayFp>::value + && is_base_of<_ClassT, _DecayA0>::value + >; + +template , + class _DecayA0 = typename decay<_A0>::type> +using __enable_if_bullet5 = __enable_if_t + < + is_member_object_pointer<_DecayFp>::value + && __is_reference_wrapper<_DecayA0>::value + >; + +template , + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet6 = __enable_if_t + < + is_member_object_pointer<_DecayFp>::value + && !is_base_of<_ClassT, _DecayA0>::value + && !__is_reference_wrapper<_DecayA0>::value + >; + +// __invoke forward declarations + +// fall back - none of the bullets + +template +_LIBCUDACXX_INLINE_VISIBILITY __nat __invoke(__any, _Args&& ...__args); + +// bullets 1, 2 and 3 + +_LIBCUDACXX_DISABLE_EXEC_CHECK +template > +inline _LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR decltype((_CUDA_VSTD::declval<_A0>().*_CUDA_VSTD::declval<_Fp>())(_CUDA_VSTD::declval<_Args>()...)) +__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) + _NOEXCEPT_(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))) + { return (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); } + +_LIBCUDACXX_DISABLE_EXEC_CHECK +template > +inline _LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR decltype((_CUDA_VSTD::declval<_A0>().get().*_CUDA_VSTD::declval<_Fp>())(_CUDA_VSTD::declval<_Args>()...)) +__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) + _NOEXCEPT_(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...))) + { return (__a0.get().*__f)(static_cast<_Args&&>(__args)...); } + +_LIBCUDACXX_DISABLE_EXEC_CHECK +template > +inline _LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR decltype(((*_CUDA_VSTD::declval<_A0>()).*_CUDA_VSTD::declval<_Fp>())(_CUDA_VSTD::declval<_Args>()...)) +__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) + _NOEXCEPT_(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))) + { return ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); } + +// bullets 4, 5 and 6 + +_LIBCUDACXX_DISABLE_EXEC_CHECK +template > +inline _LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR decltype(_CUDA_VSTD::declval<_A0>().*_CUDA_VSTD::declval<_Fp>()) +__invoke(_Fp&& __f, _A0&& __a0) + _NOEXCEPT_(noexcept(static_cast<_A0&&>(__a0).*__f)) + { return static_cast<_A0&&>(__a0).*__f; } + +_LIBCUDACXX_DISABLE_EXEC_CHECK +template > +inline _LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR decltype(_CUDA_VSTD::declval<_A0>().get().*_CUDA_VSTD::declval<_Fp>()) +__invoke(_Fp&& __f, _A0&& __a0) + _NOEXCEPT_(noexcept(__a0.get().*__f)) + { return __a0.get().*__f; } + +_LIBCUDACXX_DISABLE_EXEC_CHECK +template > +inline _LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR decltype((*_CUDA_VSTD::declval<_A0>()).*_CUDA_VSTD::declval<_Fp>()) +__invoke(_Fp&& __f, _A0&& __a0) + _NOEXCEPT_(noexcept((*static_cast<_A0&&>(__a0)).*__f)) + { return (*static_cast<_A0&&>(__a0)).*__f; } + +// bullet 7 + +_LIBCUDACXX_DISABLE_EXEC_CHECK +template +inline _LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR decltype(_CUDA_VSTD::declval<_Fp>()(_CUDA_VSTD::declval<_Args>()...)) +__invoke(_Fp&& __f, _Args&& ...__args) + _NOEXCEPT_(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))) + { return static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); } + +// __invokable +template +struct __invokable_r +{ + template + _LIBCUDACXX_INLINE_VISIBILITY + static decltype(_CUDA_VSTD::__invoke(_CUDA_VSTD::declval<_XFp>(), _CUDA_VSTD::declval<_XArgs>()...)) __try_call(int); + + template + _LIBCUDACXX_INLINE_VISIBILITY + static __nat __try_call(...); + + // FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void, + // or incomplete array types as required by the standard. + using _Result = decltype(__try_call<_Fp, _Args...>(0)); + + using type = __conditional_t< + _IsNotSame<_Result, __nat>::value, + __conditional_t::value, true_type, __is_core_convertible<_Result, _Ret> >, + false_type>; + static const bool value = type::value; +}; +template +using __invokable = __invokable_r; + +template +struct __nothrow_invokable_r_imp { + static const bool value = false; +}; + +template +struct __nothrow_invokable_r_imp +{ + typedef __nothrow_invokable_r_imp _ThisT; + + template + _LIBCUDACXX_INLINE_VISIBILITY + static void __test_noexcept(_Tp) _NOEXCEPT; + + static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>( + _CUDA_VSTD::__invoke(declval<_Fp>(), _CUDA_VSTD::declval<_Args>()...))); +}; + +template +struct __nothrow_invokable_r_imp +{ + static const bool value = noexcept( + _CUDA_VSTD::__invoke(_CUDA_VSTD::declval<_Fp>(), _CUDA_VSTD::declval<_Args>()...)); +}; + +template +using __nothrow_invokable_r = + __nothrow_invokable_r_imp< + __invokable_r<_Ret, _Fp, _Args...>::value, + is_void<_Ret>::value, + _Ret, _Fp, _Args... + >; + +template +using __nothrow_invokable = + __nothrow_invokable_r_imp< + __invokable<_Fp, _Args...>::value, + true, void, _Fp, _Args... + >; + +template +struct __invoke_of + : public enable_if< + __invokable<_Fp, _Args...>::value, + typename __invokable_r::_Result> +{ +#if defined(__NVCC__) && defined(__CUDACC_EXTENDED_LAMBDA__) && \ + !defined(__CUDA_ARCH__) + static_assert(!__nv_is_extended_device_lambda_closure_type(_Fp), + "Attempt to use an extended __device__ lambda in a context " + "that requires querying its return type in host code. Use a " + "named function object, a __host__ __device__ lambda, or " + "cuda::proclaim_return_type instead."); +#endif +}; + +template ::value> +struct __invoke_void_return_wrapper +{ + template + _LIBCUDACXX_INLINE_VISIBILITY static _Ret __call(_Args&&... __args) { + return _CUDA_VSTD::__invoke(_CUDA_VSTD::forward<_Args>(__args)...); + } +}; + +template +struct __invoke_void_return_wrapper<_Ret, true> +{ + template + _LIBCUDACXX_INLINE_VISIBILITY static void __call(_Args&&... __args) { + _CUDA_VSTD::__invoke(_CUDA_VSTD::forward<_Args>(__args)...); + } +}; + +#if _LIBCUDACXX_STD_VER > 11 + +// is_invocable + +template +struct _LIBCUDACXX_TEMPLATE_VIS is_invocable + : integral_constant::value> {}; + +template +struct _LIBCUDACXX_TEMPLATE_VIS is_invocable_r + : integral_constant::value> {}; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, _Args...>::value; + +// is_nothrow_invocable + +template +struct _LIBCUDACXX_TEMPLATE_VIS is_nothrow_invocable + : integral_constant::value> {}; + +template +struct _LIBCUDACXX_TEMPLATE_VIS is_nothrow_invocable_r + : integral_constant::value> {}; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value; + +template +struct _LIBCUDACXX_TEMPLATE_VIS invoke_result + : __invoke_of<_Fn, _Args...> +{ +}; + +template +using invoke_result_t = typename invoke_result<_Fn, _Args...>::type; + +template +_LIBCUDACXX_INLINE_VISIBILITY constexpr invoke_result_t<_Fn, _Args...> +invoke(_Fn&& __f, _Args&&... __args) + noexcept(is_nothrow_invocable_v<_Fn, _Args...>) +{ + return _CUDA_VSTD::__invoke(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward<_Args>(__args)...); +} + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_INVOKE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/is_transparent.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/is_transparent.h new file mode 100644 index 0000000000000000000000000000000000000000..997718aa72f60f08a0881bec045c5d0a89c192b9 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/is_transparent.h @@ -0,0 +1,40 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_IS_TRANSPARENT +#define _LIBCUDACXX___FUNCTIONAL_IS_TRANSPARENT + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/void_t.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +template +struct __is_transparent : false_type {}; + +template +struct __is_transparent<_Tp, _Up, __void_t > + : true_type {}; + +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_IS_TRANSPARENT diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/mem_fn.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/mem_fn.h new file mode 100644 index 0000000000000000000000000000000000000000..4c0a1b901b0cfa954b0efffb5197cb82d04b8ef0 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/mem_fn.h @@ -0,0 +1,61 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_MEM_FN_H +#define _LIBCUDACXX___FUNCTIONAL_MEM_FN_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" +#include "../__functional/invoke.h" +#include "../__functional/weak_result_type.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +class __mem_fn : public __weak_result_type<_Tp> +{ +public: + // types + typedef _Tp type; +private: + type __f_; + +public: + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} + + // invoke + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + typename __invoke_return::type + operator() (_ArgTypes&&... __args) const { + return _CUDA_VSTD::__invoke(__f_, _CUDA_VSTD::forward<_ArgTypes>(__args)...); + } +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +__mem_fn<_Rp _Tp::*> +mem_fn(_Rp _Tp::* __pm) _NOEXCEPT +{ + return __mem_fn<_Rp _Tp::*>(__pm); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_MEM_FN_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/mem_fun_ref.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/mem_fun_ref.h new file mode 100644 index 0000000000000000000000000000000000000000..105adbff6e4045f03c197521f8d04d3fdf3b133a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/mem_fun_ref.h @@ -0,0 +1,177 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_MEM_FUN_REF_H +#define _LIBCUDACXX___FUNCTIONAL_MEM_FUN_REF_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" +#include "../__functional/unary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun_t + : public __unary_function<_Tp*, _Sp> +{ + _Sp (_Tp::*__p_)(); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const + {return (__p->*__p_)();} +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun1_t + : public __binary_function<_Tp*, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const + {return (__p->*__p_)(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +mem_fun_t<_Sp,_Tp> +mem_fun(_Sp (_Tp::*__f)()) + {return mem_fun_t<_Sp,_Tp>(__f);} + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +mem_fun1_t<_Sp,_Tp,_Ap> +mem_fun(_Sp (_Tp::*__f)(_Ap)) + {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun_ref_t + : public __unary_function<_Tp, _Sp> +{ + _Sp (_Tp::*__p_)(); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const + {return (__p.*__p_)();} +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun1_ref_t + : public __binary_function<_Tp, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const + {return (__p.*__p_)(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +mem_fun_ref_t<_Sp,_Tp> +mem_fun_ref(_Sp (_Tp::*__f)()) + {return mem_fun_ref_t<_Sp,_Tp>(__f);} + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +mem_fun1_ref_t<_Sp,_Tp,_Ap> +mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) + {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun_t + : public __unary_function +{ + _Sp (_Tp::*__p_)() const; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const + {return (__p->*__p_)();} +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun1_t + : public __binary_function +{ + _Sp (_Tp::*__p_)(_Ap) const; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const + {return (__p->*__p_)(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +const_mem_fun_t<_Sp,_Tp> +mem_fun(_Sp (_Tp::*__f)() const) + {return const_mem_fun_t<_Sp,_Tp>(__f);} + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +const_mem_fun1_t<_Sp,_Tp,_Ap> +mem_fun(_Sp (_Tp::*__f)(_Ap) const) + {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun_ref_t + : public __unary_function<_Tp, _Sp> +{ + _Sp (_Tp::*__p_)() const; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const + {return (__p.*__p_)();} +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t + : public __binary_function<_Tp, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap) const; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const + {return (__p.*__p_)(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +const_mem_fun_ref_t<_Sp,_Tp> +mem_fun_ref(_Sp (_Tp::*__f)() const) + {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +const_mem_fun1_ref_t<_Sp,_Tp,_Ap> +mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) + {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} + +#endif // _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_MEM_FUN_REF_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/not_fn.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/not_fn.h new file mode 100644 index 0000000000000000000000000000000000000000..b93ca6112497c3eadf38f7a43dce39c16c087742 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/not_fn.h @@ -0,0 +1,73 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_NOT_FN_H +#define _LIBCUDACXX___FUNCTIONAL_NOT_FN_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/invoke.h" +#include "../__functional/perfect_forward.h" +#include "../__type_traits/decay.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_move_constructible.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +struct __not_fn_op { + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 auto operator()(_Args&&... __args) const + noexcept(noexcept(!_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( !_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...)) + { return !_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...); } +}; + +template +struct __not_fn_t : __perfect_forward<__not_fn_op, _Fn> { + using __base = __perfect_forward<__not_fn_op, _Fn>; +#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug 3961621 + constexpr __not_fn_t() noexcept = default; + + _LIBCUDACXX_TEMPLATE(class _OrigFn) + (requires _LIBCUDACXX_TRAIT(is_same, _Fn, __decay_t<_OrigFn>)) + _LIBCUDACXX_INLINE_VISIBILITY constexpr + __not_fn_t(_OrigFn&& __fn) noexcept(noexcept(__base(_CUDA_VSTD::declval<_OrigFn>()))) + : __base(_CUDA_VSTD::forward<_OrigFn>(__fn)) + {} +#else + using __base::__base; +#endif +}; + +template , _Fn> && + is_move_constructible_v> +>> +inline _LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f) { + return __not_fn_t>(_CUDA_VSTD::forward<_Fn>(__f)); +} + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_NOT_FN_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/operations.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/operations.h new file mode 100644 index 0000000000000000000000000000000000000000..a4400bf43d1f035d04e316d1aeda6e4aee8cec84 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/operations.h @@ -0,0 +1,622 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_OPERATIONS_H +#define _LIBCUDACXX___FUNCTIONAL_OPERATIONS_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" +#include "../__functional/unary_function.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +// Arithmetic operations + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS plus + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x + __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(plus); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS plus +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) + _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) + _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) + _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS minus + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x - __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(minus); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS minus +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) - _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) - _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) - _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS multiplies + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x * __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(multiplies); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS multiplies +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) * _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) * _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) * _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS divides + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x / __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(divides); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS divides +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) / _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) / _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) / _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS modulus + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x % __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(modulus); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS modulus +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) % _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) % _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) % _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS negate + : __unary_function<_Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return -__x;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(negate); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS negate +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_Tp&& __x) const + noexcept(noexcept(- _CUDA_VSTD::forward<_Tp>(__x))) + -> decltype( - _CUDA_VSTD::forward<_Tp>(__x)) + { return - _CUDA_VSTD::forward<_Tp>(__x); } + typedef void is_transparent; +}; +#endif + +// Bitwise operations + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS bit_and + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x & __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_and); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS bit_and +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) & _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) & _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) & _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +struct _LIBCUDACXX_TEMPLATE_VIS bit_not + : __unary_function<_Tp, _Tp> +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return ~__x;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_not); + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS bit_not +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_Tp&& __x) const + noexcept(noexcept(~_CUDA_VSTD::forward<_Tp>(__x))) + -> decltype( ~_CUDA_VSTD::forward<_Tp>(__x)) + { return ~_CUDA_VSTD::forward<_Tp>(__x); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS bit_or + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x | __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_or); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS bit_or +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) | _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) | _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) | _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS bit_xor + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x ^ __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_xor); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS bit_xor +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) ^ _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) ^ _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) ^ _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +// Comparison operations + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS equal_to + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x == __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(equal_to); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS equal_to +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) == _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) == _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) == _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x != __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(not_equal_to); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) != _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) != _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) != _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS less + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x < __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(less); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS less +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) < _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) < _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) < _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS less_equal + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x <= __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(less_equal); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS less_equal +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) <= _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) <= _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) <= _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS greater_equal + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x >= __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(greater_equal); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS greater_equal +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) >= _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) >= _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) >= _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS greater + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x > __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(greater); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS greater +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) > _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) > _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) > _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +// Logical operations + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS logical_and + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x && __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_and); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS logical_and +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) && _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) && _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) && _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS logical_not + : __unary_function<_Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x) const + {return !__x;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_not); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS logical_not +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_Tp&& __x) const + noexcept(noexcept(!_CUDA_VSTD::forward<_Tp>(__x))) + -> decltype( !_CUDA_VSTD::forward<_Tp>(__x)) + { return !_CUDA_VSTD::forward<_Tp>(__x); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS logical_or + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x || __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_or); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS logical_or +{ + _LIBCUDACXX_DISABLE_EXEC_CHECK + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) || _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) || _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) || _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_OPERATIONS_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/perfect_forward.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/perfect_forward.h new file mode 100644 index 0000000000000000000000000000000000000000..6fc538d947a9229164bb288401800c197846b7b7 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/perfect_forward.h @@ -0,0 +1,113 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_PERFECT_FORWARD_H +#define _LIBCUDACXX___FUNCTIONAL_PERFECT_FORWARD_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__functional/invoke.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__utility/declval.h" +#include "../__utility/forward.h" +#include "../__utility/integer_sequence.h" +#include "../__utility/move.h" + +#include "../tuple" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +template +struct __perfect_forward_impl; + +template +struct __perfect_forward_impl<_Op, index_sequence<_Idx...>, _BoundArgs...> { +private: + tuple<_BoundArgs...> __bound_args_; + +public: + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires is_constructible_v, _Args&&...>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + explicit constexpr __perfect_forward_impl(_Args&&... __bound_args) + noexcept(is_nothrow_constructible_v, _Args&&...>) + : __bound_args_(_CUDA_VSTD::forward<_Args>(__bound_args)...) {} + + __perfect_forward_impl(__perfect_forward_impl const&) = default; + __perfect_forward_impl(__perfect_forward_impl&&) = default; + + __perfect_forward_impl& operator=(__perfect_forward_impl const&) = default; + __perfect_forward_impl& operator=(__perfect_forward_impl&&) = default; + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires is_invocable_v<_Op, _BoundArgs&..., _Args...>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) & + noexcept(noexcept(_Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( _Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...)) + { return _Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...); } + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires (!is_invocable_v<_Op, _BoundArgs&..., _Args...>)) + _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_Args&&...) & = delete; + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires is_invocable_v<_Op, _BoundArgs const&..., _Args...>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const& + noexcept(noexcept(_Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( _Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...)) + { return _Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...); } + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires (!is_invocable_v<_Op, _BoundArgs const&..., _Args...>)) + _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_Args&&...) const& = delete; + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires is_invocable_v<_Op, _BoundArgs..., _Args...>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) && + noexcept(noexcept(_Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( _Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...)) + { return _Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...); } + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires (!is_invocable_v<_Op, _BoundArgs..., _Args...>)) + _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_Args&&...) && = delete; + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires is_invocable_v<_Op, _BoundArgs const..., _Args...>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&& + noexcept(noexcept(_Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( _Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...)) + { return _Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...); } + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires (!is_invocable_v<_Op, _BoundArgs const..., _Args...>)) + _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_Args&&...) const&& = delete; +}; + +// __perfect_forward implements a perfect-forwarding call wrapper as explained in [func.require]. +template +using __perfect_forward = __perfect_forward_impl<_Op, index_sequence_for<_Args...>, _Args...>; + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_PERFECT_FORWARD_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/pointer_to_binary_function.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/pointer_to_binary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..d76f447e4b479684926150964357d82f452a9987 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/pointer_to_binary_function.h @@ -0,0 +1,50 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_POINTER_TO_BINARY_FUNCTION_H +#define _LIBCUDACXX___FUNCTIONAL_POINTER_TO_BINARY_FUNCTION_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 pointer_to_binary_function + : public __binary_function<_Arg1, _Arg2, _Result> +{ + _Result (*__f_)(_Arg1, _Arg2); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) + : __f_(__f) {} + _LIBCUDACXX_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const + {return __f_(__x, __y);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +pointer_to_binary_function<_Arg1,_Arg2,_Result> +ptr_fun(_Result (*__f)(_Arg1,_Arg2)) + {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} + +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_POINTER_TO_BINARY_FUNCTION_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/pointer_to_unary_function.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/pointer_to_unary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..eb87609f8b63efdf5f5e344f8fc365375eec53e8 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/pointer_to_unary_function.h @@ -0,0 +1,50 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_POINTER_TO_UNARY_FUNCTION_H +#define _LIBCUDACXX___FUNCTIONAL_POINTER_TO_UNARY_FUNCTION_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/unary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 pointer_to_unary_function + : public __unary_function<_Arg, _Result> +{ + _Result (*__f_)(_Arg); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) + : __f_(__f) {} + _LIBCUDACXX_INLINE_VISIBILITY _Result operator()(_Arg __x) const + {return __f_(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +pointer_to_unary_function<_Arg,_Result> +ptr_fun(_Result (*__f)(_Arg)) + {return pointer_to_unary_function<_Arg,_Result>(__f);} + +#endif // _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_POINTER_TO_UNARY_FUNCTION_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/reference_wrapper.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/reference_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..4fa4fb93c46dd11a689d71f749eaab09c4676cd0 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/reference_wrapper.h @@ -0,0 +1,103 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_REFERENCE_WRAPPER_H +#define _LIBCUDACXX___FUNCTIONAL_REFERENCE_WRAPPER_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/weak_result_type.h" +#include "../__memory/addressof.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +class _LIBCUDACXX_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> +{ +public: + // types + typedef _Tp type; +private: + type* __f_; + + static _LIBCUDACXX_INLINE_VISIBILITY void __fun(_Tp&) _NOEXCEPT; + static void __fun(_Tp&&) = delete; + +public: + template ::value, decltype(__fun(declval<_Up>())) > > + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + reference_wrapper(_Up&& __u) _NOEXCEPT_(noexcept(__fun(declval<_Up>()))) { + type& __f = static_cast<_Up&&>(__u); + __f_ = _CUDA_VSTD::addressof(__f); + } + + // access + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + operator type&() const _NOEXCEPT {return *__f_;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + type& get() const _NOEXCEPT {return *__f_;} + + // invoke + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + typename __invoke_of::type + operator() (_ArgTypes&&... __args) const { + return _CUDA_VSTD::__invoke(get(), _CUDA_VSTD::forward<_ArgTypes>(__args)...); + } +}; + +#if _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES) +template +reference_wrapper(_Tp&) -> reference_wrapper<_Tp>; +#endif + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +reference_wrapper<_Tp> +ref(_Tp& __t) _NOEXCEPT +{ + return reference_wrapper<_Tp>(__t); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +reference_wrapper<_Tp> +ref(reference_wrapper<_Tp> __t) _NOEXCEPT +{ + return __t; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +reference_wrapper +cref(const _Tp& __t) _NOEXCEPT +{ + return reference_wrapper(__t); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +reference_wrapper +cref(reference_wrapper<_Tp> __t) _NOEXCEPT +{ + return __t; +} + +template void ref(const _Tp&&) = delete; +template void cref(const _Tp&&) = delete; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_REFERENCE_WRAPPER_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/unary_function.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/unary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..f6b27e71a00dee8cb99e828b4ea41d45b5157a58 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/unary_function.h @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_UNARY_FUNCTION_H +#define _LIBCUDACXX___FUNCTIONAL_UNARY_FUNCTION_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION) + +template +struct _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 unary_function +{ + typedef _Arg argument_type; + typedef _Result result_type; +}; + +#endif // _LIBCUDACXX_STD_VER <= 14 + +template struct __unary_function_keep_layout_base { +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using argument_type _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Arg; + using result_type _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Result; +#endif +}; + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION) +_LIBCUDACXX_DIAGNOSTIC_PUSH +_LIBCUDACXX_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") +template +using __unary_function = unary_function<_Arg, _Result>; +_LIBCUDACXX_DIAGNOSTIC_POP +#else +template +using __unary_function = __unary_function_keep_layout_base<_Arg, _Result>; +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_UNARY_FUNCTION_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/unary_negate.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/unary_negate.h new file mode 100644 index 0000000000000000000000000000000000000000..601c27282295a69761a714a66b70fbd5a9edb8b1 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/unary_negate.h @@ -0,0 +1,52 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_UNARY_NEGATE_H +#define _LIBCUDACXX___FUNCTIONAL_UNARY_NEGATE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/unary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_NEGATORS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX17 unary_negate + : public __unary_function +{ + _Predicate __pred_; +public: + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + explicit unary_negate(const _Predicate& __pred) + : __pred_(__pred) {} + _LIBCUDACXX_DISABLE_EXEC_CHECK + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const typename _Predicate::argument_type& __x) const + {return !__pred_(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX17 inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY +unary_negate<_Predicate> +not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} + +#endif // _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_NEGATORS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_UNARY_NEGATE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/unwrap_ref.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/unwrap_ref.h new file mode 100644 index 0000000000000000000000000000000000000000..291de09f111e208d6cefdaad95b02b905b5c99c6 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/unwrap_ref.h @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_UNWRAP_REF_H +#define _LIBCUDACXX___FUNCTIONAL_UNWRAP_REF_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct __unwrap_reference { typedef _LIBCUDACXX_NODEBUG_TYPE _Tp type; }; + +template +class reference_wrapper; + +template +struct __unwrap_reference > { typedef _LIBCUDACXX_NODEBUG_TYPE _Tp& type; }; + +template +struct decay; + +#if _LIBCUDACXX_STD_VER > 17 +template +struct unwrap_reference : __unwrap_reference<_Tp> { }; + +template +using unwrap_reference_t = typename unwrap_reference<_Tp>::type; + +template +struct unwrap_ref_decay : unwrap_reference::type> { }; + +template +using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type; +#endif // _LIBCUDACXX_STD_VER > 17 + +template +struct __unwrap_ref_decay +#if _LIBCUDACXX_STD_VER > 17 + : unwrap_ref_decay<_Tp> +#else + : __unwrap_reference::type> +#endif +{ }; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_UNWRAP_REF_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/weak_result_type.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/weak_result_type.h new file mode 100644 index 0000000000000000000000000000000000000000..1b1315306772fbe1ddf1654de575015ce47dfdfb --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional/weak_result_type.h @@ -0,0 +1,297 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_WEAK_RESULT_TYPE_H +#define _LIBCUDACXX___FUNCTIONAL_WEAK_RESULT_TYPE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" +#include "../__functional/invoke.h" +#include "../__functional/unary_function.h" +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/is_same.h" +#include "../__utility/declval.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct __has_result_type +{ +private: + template _LIBCUDACXX_INLINE_VISIBILITY static false_type __test(...); + template _LIBCUDACXX_INLINE_VISIBILITY static true_type __test(typename _Up::result_type* = 0); +public: + static const bool value = decltype(__test<_Tp>(0))::value; +}; + +// __weak_result_type + +template +struct __derives_from_unary_function +{ +private: + struct __two {char __lx; char __lxx;}; + static _LIBCUDACXX_INLINE_VISIBILITY __two __test(...); + template + static _LIBCUDACXX_INLINE_VISIBILITY __unary_function<_Ap, _Rp> + __test(const volatile __unary_function<_Ap, _Rp>*); + +public: + static const bool value = !is_same::value; + typedef decltype(__test((_Tp*)0)) type; +}; + +template +struct __derives_from_binary_function +{ +private: + struct __two {char __lx; char __lxx;}; + static __two _LIBCUDACXX_INLINE_VISIBILITY __test(...); + template + static _LIBCUDACXX_INLINE_VISIBILITY __binary_function<_A1, _A2, _Rp> + __test(const volatile __binary_function<_A1, _A2, _Rp>*); + +public: + static const bool value = !is_same::value; + typedef decltype(__test((_Tp*)0)) type; +}; + +template ::value> +struct __maybe_derive_from_unary_function // bool is true + : public __derives_from_unary_function<_Tp>::type +{ +}; + +template +struct __maybe_derive_from_unary_function<_Tp, false> +{ +}; + +template ::value> +struct __maybe_derive_from_binary_function // bool is true + : public __derives_from_binary_function<_Tp>::type +{ +}; + +template +struct __maybe_derive_from_binary_function<_Tp, false> +{ +}; + +template ::value> +struct __weak_result_type_imp // bool is true + : public __maybe_derive_from_unary_function<_Tp>, + public __maybe_derive_from_binary_function<_Tp> +{ +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using result_type _LIBCUDACXX_NODEBUG_TYPE _LIBCUDACXX_DEPRECATED_IN_CXX17 = typename _Tp::result_type; +#endif +}; + +template +struct __weak_result_type_imp<_Tp, false> + : public __maybe_derive_from_unary_function<_Tp>, + public __maybe_derive_from_binary_function<_Tp> +{ +}; + +template +struct __weak_result_type + : public __weak_result_type_imp<_Tp> +{ +}; + +// 0 argument case + +template +struct __weak_result_type<_Rp ()> +{ +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using result_type _LIBCUDACXX_NODEBUG_TYPE _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Rp; +#endif +}; + +template +struct __weak_result_type<_Rp (&)()> +{ +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using result_type _LIBCUDACXX_NODEBUG_TYPE _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Rp; +#endif +}; + +template +struct __weak_result_type<_Rp (*)()> +{ +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using result_type _LIBCUDACXX_NODEBUG_TYPE _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Rp; +#endif +}; + +// 1 argument case + +template +struct __weak_result_type<_Rp (_A1)> + : public __unary_function<_A1, _Rp> +{ +}; + +template +struct __weak_result_type<_Rp (&)(_A1)> + : public __unary_function<_A1, _Rp> +{ +}; + +template +struct __weak_result_type<_Rp (*)(_A1)> + : public __unary_function<_A1, _Rp> +{ +}; + +template +struct __weak_result_type<_Rp (_Cp::*)()> + : public __unary_function<_Cp*, _Rp> +{ +}; + +template +struct __weak_result_type<_Rp (_Cp::*)() const> + : public __unary_function +{ +}; + +template +struct __weak_result_type<_Rp (_Cp::*)() volatile> + : public __unary_function +{ +}; + +template +struct __weak_result_type<_Rp (_Cp::*)() const volatile> + : public __unary_function +{ +}; + +// 2 argument case + +template +struct __weak_result_type<_Rp (_A1, _A2)> + : public __binary_function<_A1, _A2, _Rp> +{ +}; + +template +struct __weak_result_type<_Rp (*)(_A1, _A2)> + : public __binary_function<_A1, _A2, _Rp> +{ +}; + +template +struct __weak_result_type<_Rp (&)(_A1, _A2)> + : public __binary_function<_A1, _A2, _Rp> +{ +}; + +template +struct __weak_result_type<_Rp (_Cp::*)(_A1)> + : public __binary_function<_Cp*, _A1, _Rp> +{ +}; + +template +struct __weak_result_type<_Rp (_Cp::*)(_A1) const> + : public __binary_function +{ +}; + +template +struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile> + : public __binary_function +{ +}; + +template +struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile> + : public __binary_function +{ +}; + +// 3 or more arguments + +template +struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)> +{ +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using result_type _LIBCUDACXX_NODEBUG_TYPE _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Rp; +#endif +}; + +template +struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)> +{ +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using result_type _LIBCUDACXX_NODEBUG_TYPE _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Rp; +#endif +}; + +template +struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)> +{ +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using result_type _LIBCUDACXX_NODEBUG_TYPE _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Rp; +#endif +}; + +template +struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)> +{ +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using result_type _LIBCUDACXX_NODEBUG_TYPE _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Rp; +#endif +}; + +template +struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const> +{ +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using result_type _LIBCUDACXX_NODEBUG_TYPE _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Rp; +#endif +}; + +template +struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile> +{ +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using result_type _LIBCUDACXX_NODEBUG_TYPE _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Rp; +#endif +}; + +template +struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> +{ +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using result_type _LIBCUDACXX_NODEBUG_TYPE _LIBCUDACXX_DEPRECATED_IN_CXX17 = _Rp; +#endif +}; + +template +struct __invoke_return +{ + typedef decltype(_CUDA_VSTD::__invoke(declval<_Tp>(), declval<_Args>()...)) type; +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_WEAK_RESULT_TYPE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional_03 b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional_03 new file mode 100644 index 0000000000000000000000000000000000000000..f9610b6ea384df8c08e717317d39fbe93b87f8e3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional_03 @@ -0,0 +1,1595 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_FUNCTIONAL_03 +#define _LIBCUDACXX_FUNCTIONAL_03 + +// manual variadic expansion for + +#include <__pragma_push> + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +namespace __function { + +template class __base; + +template +class __base<_Rp()> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _Rp operator()() = 0; +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +class __base<_Rp(_A0)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _Rp operator()(_A0) = 0; +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +class __base<_Rp(_A0, _A1)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _Rp operator()(_A0, _A1) = 0; +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +class __base<_Rp(_A0, _A1, _A2)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _Rp operator()(_A0, _A1, _A2) = 0; +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template class __func; + +template +class __func<_Fp, _Alloc, _Rp()> + : public __base<_Rp()> +{ + __compressed_pair<_Fp, _Alloc> __f_; +public: + explicit __func(_Fp __f) : __f_(_CUDA_VSTD::move(__f)) {} + explicit __func(_Fp __f, _Alloc __a) : __f_(_CUDA_VSTD::move(__f), _CUDA_VSTD::move(__a)) {} + virtual __base<_Rp()>* __clone() const; + virtual void __clone(__base<_Rp()>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _Rp operator()(); +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +__base<_Rp()>* +__func<_Fp, _Alloc, _Rp()>::__clone() const +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template +void +__func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template +void +__func<_Fp, _Alloc, _Rp()>::destroy() +{ + __f_.~__compressed_pair<_Fp, _Alloc>(); +} + +template +void +__func<_Fp, _Alloc, _Rp()>::destroy_deallocate() +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + __f_.~__compressed_pair<_Fp, _Alloc>(); + __a.deallocate(this, 1); +} + +template +_Rp +__func<_Fp, _Alloc, _Rp()>::operator()() +{ + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_.first()); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const void* +__func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const +{ + if (__ti == typeid(_Fp)) + return &__f_.first(); + return (const void*)0; +} + +template +const std::type_info& +__func<_Fp, _Alloc, _Rp()>::target_type() const +{ + return typeid(_Fp); +} + +#endif // _LIBCUDACXX_NO_RTTI + +template +class __func<_Fp, _Alloc, _Rp(_A0)> + : public __base<_Rp(_A0)> +{ + __compressed_pair<_Fp, _Alloc> __f_; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_CUDA_VSTD::move(__f)) {} + _LIBCUDACXX_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) + : __f_(_CUDA_VSTD::move(__f), _CUDA_VSTD::move(__a)) {} + virtual __base<_Rp(_A0)>* __clone() const; + virtual void __clone(__base<_Rp(_A0)>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _Rp operator()(_A0); +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +__base<_Rp(_A0)>* +__func<_Fp, _Alloc, _Rp(_A0)>::__clone() const +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template +void +__func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template +void +__func<_Fp, _Alloc, _Rp(_A0)>::destroy() +{ + __f_.~__compressed_pair<_Fp, _Alloc>(); +} + +template +void +__func<_Fp, _Alloc, _Rp(_A0)>::destroy_deallocate() +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + __f_.~__compressed_pair<_Fp, _Alloc>(); + __a.deallocate(this, 1); +} + +template +_Rp +__func<_Fp, _Alloc, _Rp(_A0)>::operator()(_A0 __a0) +{ + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_.first(), __a0); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const void* +__func<_Fp, _Alloc, _Rp(_A0)>::target(const type_info& __ti) const +{ + if (__ti == typeid(_Fp)) + return &__f_.first(); + return (const void*)0; +} + +template +const std::type_info& +__func<_Fp, _Alloc, _Rp(_A0)>::target_type() const +{ + return typeid(_Fp); +} + +#endif // _LIBCUDACXX_NO_RTTI + +template +class __func<_Fp, _Alloc, _Rp(_A0, _A1)> + : public __base<_Rp(_A0, _A1)> +{ + __compressed_pair<_Fp, _Alloc> __f_; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_CUDA_VSTD::move(__f)) {} + _LIBCUDACXX_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) + : __f_(_CUDA_VSTD::move(__f), _CUDA_VSTD::move(__a)) {} + virtual __base<_Rp(_A0, _A1)>* __clone() const; + virtual void __clone(__base<_Rp(_A0, _A1)>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _Rp operator()(_A0, _A1); +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +__base<_Rp(_A0, _A1)>* +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template +void +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone(__base<_Rp(_A0, _A1)>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template +void +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy() +{ + __f_.~__compressed_pair<_Fp, _Alloc>(); +} + +template +void +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy_deallocate() +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + __f_.~__compressed_pair<_Fp, _Alloc>(); + __a.deallocate(this, 1); +} + +template +_Rp +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) +{ + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_.first(), __a0, __a1); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const void* +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target(const type_info& __ti) const +{ + if (__ti == typeid(_Fp)) + return &__f_.first(); + return (const void*)0; +} + +template +const std::type_info& +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target_type() const +{ + return typeid(_Fp); +} + +#endif // _LIBCUDACXX_NO_RTTI + +template +class __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> + : public __base<_Rp(_A0, _A1, _A2)> +{ + __compressed_pair<_Fp, _Alloc> __f_; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_CUDA_VSTD::move(__f)) {} + _LIBCUDACXX_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) + : __f_(_CUDA_VSTD::move(__f), _CUDA_VSTD::move(__a)) {} + virtual __base<_Rp(_A0, _A1, _A2)>* __clone() const; + virtual void __clone(__base<_Rp(_A0, _A1, _A2)>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _Rp operator()(_A0, _A1, _A2); +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +__base<_Rp(_A0, _A1, _A2)>* +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template +void +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone(__base<_Rp(_A0, _A1, _A2)>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template +void +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy() +{ + __f_.~__compressed_pair<_Fp, _Alloc>(); +} + +template +void +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy_deallocate() +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + __f_.~__compressed_pair<_Fp, _Alloc>(); + __a.deallocate(this, 1); +} + +template +_Rp +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) +{ + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_.first(), __a0, __a1, __a2); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const void* +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target(const type_info& __ti) const +{ + if (__ti == typeid(_Fp)) + return &__f_.first(); + return (const void*)0; +} + +template +const std::type_info& +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const +{ + return typeid(_Fp); +} + +#endif // _LIBCUDACXX_NO_RTTI + +} // __function + +template +class _LIBCUDACXX_TEMPLATE_VIS function<_Rp()> +{ + typedef __function::__base<_Rp()> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + +public: + typedef _Rp result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCUDACXX_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCUDACXX_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template + function(_Fp, + typename enable_if::value>::type* = 0); + + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template + function(allocator_arg_t, const _Alloc&, const function&); + template + function(allocator_arg_t, const _Alloc& __a, _Fp __f, + typename enable_if::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template + typename enable_if + < + !is_integral<_Fp>::value, + function& + >::type + operator=(_Fp); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template + _LIBCUDACXX_INLINE_VISIBILITY + void assign(_Fp __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + _LIBCUDACXX_INLINE_VISIBILITY operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template + bool operator==(const function<_R2()>&) const;// = delete; + template + bool operator!=(const function<_R2()>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _Rp operator()() const; + +#ifndef _LIBCUDACXX_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template _Tp* target(); + template const _Tp* target() const; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +function<_Rp()>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_Rp()>::function(_Fp __f, + typename enable_if::value>::type*) + : __f_(0) +{ + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _Ap; + _Ap __a; + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + __f_ = __hold.release(); + } + } +} + +template +template +function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, + typename enable_if::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, _Alloc, _Rp()> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f, __a0); + } + else + { + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + _Ap __a(__a0); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template +function<_Rp()>& +function<_Rp()>::operator=(const function& __f) +{ + if (__f) + function(__f).swap(*this); + else + *this = nullptr; + return *this; +} + +template +function<_Rp()>& +function<_Rp()>::operator=(nullptr_t) +{ + __base* __t = __f_; + __f_ = 0; + if (__t == (__base*)&__buf_) + __t->destroy(); + else if (__t) + __t->destroy_deallocate(); + return *this; +} + +template +template +typename enable_if +< + !is_integral<_Fp>::value, + function<_Rp()>& +>::type +function<_Rp()>::operator=(_Fp __f) +{ + function(_CUDA_VSTD::move(__f)).swap(*this); + return *this; +} + +template +function<_Rp()>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template +void +function<_Rp()>::swap(function& __f) +{ + if (_CUDA_VSTD::addressof(__f) == this) + return; + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _CUDA_VSTD::swap(__f_, __f.__f_); +} + +template +_Rp +function<_Rp()>::operator()() const +{ + if (__f_ == 0) + __throw_bad_function_call(); + return (*__f_)(); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const std::type_info& +function<_Rp()>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template +template +_Tp* +function<_Rp()>::target() +{ + if (__f_ == 0) + return (_Tp*)0; + return (_Tp*) const_cast(__f_->target(typeid(_Tp))); +} + +template +template +const _Tp* +function<_Rp()>::target() const +{ + if (__f_ == 0) + return (const _Tp*)0; + return (const _Tp*)__f_->target(typeid(_Tp)); +} + +#endif // _LIBCUDACXX_NO_RTTI + +template +class _LIBCUDACXX_TEMPLATE_VIS function<_Rp(_A0)> + : public unary_function<_A0, _Rp> +{ + typedef __function::__base<_Rp(_A0)> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + +public: + typedef _Rp result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCUDACXX_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCUDACXX_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template + function(_Fp, + typename enable_if::value>::type* = 0); + + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template + function(allocator_arg_t, const _Alloc&, const function&); + template + function(allocator_arg_t, const _Alloc& __a, _Fp __f, + typename enable_if::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template + typename enable_if + < + !is_integral<_Fp>::value, + function& + >::type + operator=(_Fp); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template + _LIBCUDACXX_INLINE_VISIBILITY + void assign(_Fp __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + _LIBCUDACXX_INLINE_VISIBILITY operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template + bool operator==(const function<_R2(_B0)>&) const;// = delete; + template + bool operator!=(const function<_R2(_B0)>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _Rp operator()(_A0) const; + +#ifndef _LIBCUDACXX_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template _Tp* target(); + template const _Tp* target() const; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +function<_Rp(_A0)>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_Rp(_A0)>::function(_Fp __f, + typename enable_if::value>::type*) + : __f_(0) +{ + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _Ap; + _Ap __a; + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + __f_ = __hold.release(); + } + } +} + +template +template +function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, + typename enable_if::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f, __a0); + } + else + { + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + _Ap __a(__a0); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template +function<_Rp(_A0)>& +function<_Rp(_A0)>::operator=(const function& __f) +{ + if (__f) + function(__f).swap(*this); + else + *this = nullptr; + return *this; +} + +template +function<_Rp(_A0)>& +function<_Rp(_A0)>::operator=(nullptr_t) +{ + __base* __t = __f_; + __f_ = 0; + if (__t == (__base*)&__buf_) + __t->destroy(); + else if (__t) + __t->destroy_deallocate(); + return *this; +} + +template +template +typename enable_if +< + !is_integral<_Fp>::value, + function<_Rp(_A0)>& +>::type +function<_Rp(_A0)>::operator=(_Fp __f) +{ + function(_CUDA_VSTD::move(__f)).swap(*this); + return *this; +} + +template +function<_Rp(_A0)>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template +void +function<_Rp(_A0)>::swap(function& __f) +{ + if (_CUDA_VSTD::addressof(__f) == this) + return; + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _CUDA_VSTD::swap(__f_, __f.__f_); +} + +template +_Rp +function<_Rp(_A0)>::operator()(_A0 __a0) const +{ + if (__f_ == 0) + __throw_bad_function_call(); + return (*__f_)(__a0); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const std::type_info& +function<_Rp(_A0)>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template +template +_Tp* +function<_Rp(_A0)>::target() +{ + if (__f_ == 0) + return (_Tp*)0; + return (_Tp*) const_cast(__f_->target(typeid(_Tp))); +} + +template +template +const _Tp* +function<_Rp(_A0)>::target() const +{ + if (__f_ == 0) + return (const _Tp*)0; + return (const _Tp*)__f_->target(typeid(_Tp)); +} + +#endif // _LIBCUDACXX_NO_RTTI + +template +class _LIBCUDACXX_TEMPLATE_VIS function<_Rp(_A0, _A1)> + : public binary_function<_A0, _A1, _Rp> +{ + typedef __function::__base<_Rp(_A0, _A1)> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + +public: + typedef _Rp result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCUDACXX_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCUDACXX_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template + function(_Fp, + typename enable_if::value>::type* = 0); + + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template + function(allocator_arg_t, const _Alloc&, const function&); + template + function(allocator_arg_t, const _Alloc& __a, _Fp __f, + typename enable_if::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template + typename enable_if + < + !is_integral<_Fp>::value, + function& + >::type + operator=(_Fp); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template + _LIBCUDACXX_INLINE_VISIBILITY + void assign(_Fp __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template + bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete; + template + bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _Rp operator()(_A0, _A1) const; + +#ifndef _LIBCUDACXX_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template _Tp* target(); + template const _Tp* target() const; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +function<_Rp(_A0, _A1)>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_Rp(_A0, _A1)>::function(_Fp __f, + typename enable_if::value>::type*) + : __f_(0) +{ + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _Ap; + _Ap __a; + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + __f_ = __hold.release(); + } + } +} + +template +template +function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, + typename enable_if::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f, __a0); + } + else + { + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + _Ap __a(__a0); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template +function<_Rp(_A0, _A1)>& +function<_Rp(_A0, _A1)>::operator=(const function& __f) +{ + if (__f) + function(__f).swap(*this); + else + *this = nullptr; + return *this; +} + +template +function<_Rp(_A0, _A1)>& +function<_Rp(_A0, _A1)>::operator=(nullptr_t) +{ + __base* __t = __f_; + __f_ = 0; + if (__t == (__base*)&__buf_) + __t->destroy(); + else if (__t) + __t->destroy_deallocate(); + return *this; +} + +template +template +typename enable_if +< + !is_integral<_Fp>::value, + function<_Rp(_A0, _A1)>& +>::type +function<_Rp(_A0, _A1)>::operator=(_Fp __f) +{ + function(_CUDA_VSTD::move(__f)).swap(*this); + return *this; +} + +template +function<_Rp(_A0, _A1)>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template +void +function<_Rp(_A0, _A1)>::swap(function& __f) +{ + if (_CUDA_VSTD::addressof(__f) == this) + return; + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _CUDA_VSTD::swap(__f_, __f.__f_); +} + +template +_Rp +function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const +{ + if (__f_ == 0) + __throw_bad_function_call(); + return (*__f_)(__a0, __a1); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const std::type_info& +function<_Rp(_A0, _A1)>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template +template +_Tp* +function<_Rp(_A0, _A1)>::target() +{ + if (__f_ == 0) + return (_Tp*)0; + return (_Tp*) const_cast(__f_->target(typeid(_Tp))); +} + +template +template +const _Tp* +function<_Rp(_A0, _A1)>::target() const +{ + if (__f_ == 0) + return (const _Tp*)0; + return (const _Tp*)__f_->target(typeid(_Tp)); +} + +#endif // _LIBCUDACXX_NO_RTTI + +template +class _LIBCUDACXX_TEMPLATE_VIS function<_Rp(_A0, _A1, _A2)> +{ + typedef __function::__base<_Rp(_A0, _A1, _A2)> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + +public: + typedef _Rp result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCUDACXX_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCUDACXX_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template + function(_Fp, + typename enable_if::value>::type* = 0); + + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template + function(allocator_arg_t, const _Alloc&, const function&); + template + function(allocator_arg_t, const _Alloc& __a, _Fp __f, + typename enable_if::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template + typename enable_if + < + !is_integral<_Fp>::value, + function& + >::type + operator=(_Fp); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template + _LIBCUDACXX_INLINE_VISIBILITY + void assign(_Fp __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + _LIBCUDACXX_INLINE_VISIBILITY operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template + bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; + template + bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _Rp operator()(_A0, _A1, _A2) const; + +#ifndef _LIBCUDACXX_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template _Tp* target(); + template const _Tp* target() const; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +function<_Rp(_A0, _A1, _A2)>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&, + const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_Rp(_A0, _A1, _A2)>::function(_Fp __f, + typename enable_if::value>::type*) + : __f_(0) +{ + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _Ap; + _Ap __a; + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + __f_ = __hold.release(); + } + } +} + +template +template +function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, + typename enable_if::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f, __a0); + } + else + { + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + _Ap __a(__a0); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template +function<_Rp(_A0, _A1, _A2)>& +function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f) +{ + if (__f) + function(__f).swap(*this); + else + *this = nullptr; + return *this; +} + +template +function<_Rp(_A0, _A1, _A2)>& +function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t) +{ + __base* __t = __f_; + __f_ = 0; + if (__t == (__base*)&__buf_) + __t->destroy(); + else if (__t) + __t->destroy_deallocate(); + return *this; +} + +template +template +typename enable_if +< + !is_integral<_Fp>::value, + function<_Rp(_A0, _A1, _A2)>& +>::type +function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f) +{ + function(_CUDA_VSTD::move(__f)).swap(*this); + return *this; +} + +template +function<_Rp(_A0, _A1, _A2)>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template +void +function<_Rp(_A0, _A1, _A2)>::swap(function& __f) +{ + if (_CUDA_VSTD::addressof(__f) == this) + return; + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _CUDA_VSTD::swap(__f_, __f.__f_); +} + +template +_Rp +function<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const +{ + if (__f_ == 0) + __throw_bad_function_call(); + return (*__f_)(__a0, __a1, __a2); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const std::type_info& +function<_Rp(_A0, _A1, _A2)>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template +template +_Tp* +function<_Rp(_A0, _A1, _A2)>::target() +{ + if (__f_ == 0) + return (_Tp*)0; + return (_Tp*) const_cast(__f_->target(typeid(_Tp))); +} + +template +template +const _Tp* +function<_Rp(_A0, _A1, _A2)>::target() const +{ + if (__f_ == 0) + return (const _Tp*)0; + return (const _Tp*)__f_->target(typeid(_Tp)); +} + +#endif // _LIBCUDACXX_NO_RTTI + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator==(const function<_Fp>& __f, nullptr_t) {return !__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator==(nullptr_t, const function<_Fp>& __f) {return !__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(function<_Fp>& __x, function<_Fp>& __y) +{return __x.swap(__y);} + +#include <__pragma_pop> + +#endif // _LIBCUDACXX_FUNCTIONAL_03 diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional_base b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional_base new file mode 100644 index 0000000000000000000000000000000000000000..71d1bcf1dba49a6ec74eeb47e8c40b171d0b0b90 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional_base @@ -0,0 +1,144 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_FUNCTIONAL_BASE +#define _LIBCUDACXX_FUNCTIONAL_BASE + +#ifndef __cuda_std__ +#include <__config> +#include +#include +#include +#endif // __cuda_std__ + +#include "__functional/binary_function.h" +#include "__functional/operations.h" +#include "__functional/reference_wrapper.h" +#include "__functional/unary_function.h" +#include "__functional/weak_result_type.h" +#include "__type_traits/integral_constant.h" +#include "__type_traits/is_constructible.h" +#include "__type_traits/is_convertible.h" +#include "__type_traits/remove_cvref.h" +#include "__utility/forward.h" + +#ifndef __cuda_std__ +#include <__pragma_push> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#ifdef _LIBCUDACXX_CXX03_LANG + +#include <__functional_base_03> + +#endif // !defined(_LIBCUDACXX_CXX03_LANG) + +// allocator_arg_t + +struct _LIBCUDACXX_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; }; + +#if defined(_LIBCUDACXX_CXX03_LANG) || defined(_LIBCUDACXX_BUILDING_LIBRARY) +extern _LIBCUDACXX_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg; +#else +/* _LIBCUDACXX_INLINE_VAR */ constexpr allocator_arg_t allocator_arg = allocator_arg_t(); +#endif + +// uses_allocator + +template +struct __has_allocator_type +{ +private: + struct __two {char __lx; char __lxx;}; + template _LIBCUDACXX_INLINE_VISIBILITY static __two __test(...); + template _LIBCUDACXX_INLINE_VISIBILITY static char __test(typename _Up::allocator_type* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template ::value> +struct __uses_allocator + : public integral_constant::value> +{ +}; + +template +struct __uses_allocator<_Tp, _Alloc, false> + : public false_type +{ +}; + +template +struct _LIBCUDACXX_TEMPLATE_VIS uses_allocator + : public __uses_allocator<_Tp, _Alloc> +{ +}; + +#if _LIBCUDACXX_STD_VER > 14 +template +_LIBCUDACXX_INLINE_VAR constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value; +#endif + +#ifndef _LIBCUDACXX_CXX03_LANG + +// allocator construction + +template +struct __uses_alloc_ctor_imp +{ + typedef _LIBCUDACXX_NODEBUG_TYPE __remove_cvref_t<_Alloc> _RawAlloc; + static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value; + static const bool __ic = + is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; + static const int value = __ua ? 2 - __ic : 0; +}; + +template +struct __uses_alloc_ctor + : integral_constant::value> + {}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void __user_alloc_construct_impl (integral_constant, _Tp *__storage, const _Allocator &, _Args &&... __args ) +{ + new (__storage) _Tp (_CUDA_VSTD::forward<_Args>(__args)...); +} + +// FIXME: This should have a version which takes a non-const alloc. +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void __user_alloc_construct_impl (integral_constant, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) +{ + new (__storage) _Tp (allocator_arg, __a, _CUDA_VSTD::forward<_Args>(__args)...); +} + +// FIXME: This should have a version which takes a non-const alloc. +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void __user_alloc_construct_impl (integral_constant, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) +{ + new (__storage) _Tp (_CUDA_VSTD::forward<_Args>(__args)..., __a); +} + +#endif // _LIBCUDACXX_CXX03_LANG + +_LIBCUDACXX_END_NAMESPACE_STD + +#ifndef __cuda_std__ +#include <__pragma_pop> +#endif // __cuda_std__ + +#endif // _LIBCUDACXX_FUNCTIONAL_BASE diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional_base_03 b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional_base_03 new file mode 100644 index 0000000000000000000000000000000000000000..4187e9f5cf1dc848a802e02cc1a7aef8cf41af72 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__functional_base_03 @@ -0,0 +1,223 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_FUNCTIONAL_BASE_03 +#define _LIBCUDACXX_FUNCTIONAL_BASE_03 + +// manual variadic expansion for + +// __invoke + +template +struct __enable_invoke_imp; + +template +struct __enable_invoke_imp<_Ret, _T1, true, true> { + typedef _Ret _Bullet1; + typedef _Bullet1 type; +}; + +template +struct __enable_invoke_imp<_Ret, _T1, true, false> { + typedef _Ret _Bullet2; + typedef _Bullet2 type; +}; + +template +struct __enable_invoke_imp<_Ret, _T1, false, true> { + typedef typename add_lvalue_reference< + typename __apply_cv<_T1, _Ret>::type + >::type _Bullet3; + typedef _Bullet3 type; +}; + +template +struct __enable_invoke_imp<_Ret, _T1, false, false> { + typedef typename add_lvalue_reference< + typename __apply_cv()), _Ret>::type + >::type _Bullet4; + typedef _Bullet4 type; +}; + +template +struct __enable_invoke_imp<_Ret, _T1*, false, false> { + typedef typename add_lvalue_reference< + typename __apply_cv<_T1, _Ret>::type + >::type _Bullet4; + typedef _Bullet4 type; +}; + +template , + class _Ret = typename _Traits::_ReturnType, + class _Class = typename _Traits::_ClassType> +struct __enable_invoke : __enable_invoke_imp< + _Ret, _T1, + is_member_function_pointer<_Fn>::value, + is_base_of<_Class, typename remove_reference<_T1>::type>::value> +{ +}; + +__nat __invoke(__any, ...); + +// first bullet + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1) { + return (__t1.*__f)(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1, _A0& __a0) { + return (__t1.*__f)(__a0); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) { + return (__t1.*__f)(__a0, __a1); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) { + return (__t1.*__f)(__a0, __a1, __a2); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1) { + return ((*__t1).*__f)(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1, _A0& __a0) { + return ((*__t1).*__f)(__a0); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) { + return ((*__t1).*__f)(__a0, __a1); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) { + return ((*__t1).*__f)(__a0, __a1, __a2); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet3 +__invoke(_Fn __f, _T1& __t1) { + return __t1.*__f; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet4 +__invoke(_Fn __f, _T1& __t1) { + return (*__t1).*__f; +} + +// fifth bullet + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +decltype(_CUDA_VSTD::declval<_Fp&>()()) +__invoke(_Fp& __f) +{ + return __f(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +decltype(_CUDA_VSTD::declval<_Fp&>()(_CUDA_VSTD::declval<_A0&>())) +__invoke(_Fp& __f, _A0& __a0) +{ + return __f(__a0); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +decltype(_CUDA_VSTD::declval<_Fp&>()(_CUDA_VSTD::declval<_A0&>(), _CUDA_VSTD::declval<_A1&>())) +__invoke(_Fp& __f, _A0& __a0, _A1& __a1) +{ + return __f(__a0, __a1); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +decltype(_CUDA_VSTD::declval<_Fp&>()(_CUDA_VSTD::declval<_A0&>(), _CUDA_VSTD::declval<_A1&>(), _CUDA_VSTD::declval<_A2&>())) +__invoke(_Fp& __f, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return __f(__a0, __a1, __a2); +} + +template >::value> +struct __invoke_return +{ + typedef typename __weak_result_type<_Fp>::result_type type; +}; + +template +struct __invoke_return<_Fp, false> +{ + typedef decltype(__invoke(_CUDA_VSTD::declval<_Fp&>())) type; +}; + +template +struct __invoke_return0 +{ + typedef decltype(__invoke(_CUDA_VSTD::declval<_Tp&>(), _CUDA_VSTD::declval<_A0&>())) type; +}; + +template +struct __invoke_return0<_Rp _Tp::*, _A0> +{ + typedef typename __enable_invoke<_Rp _Tp::*, _A0>::type type; +}; + +template +struct __invoke_return1 +{ + typedef decltype(__invoke(_CUDA_VSTD::declval<_Tp&>(), _CUDA_VSTD::declval<_A0&>(), + _CUDA_VSTD::declval<_A1&>())) type; +}; + +template +struct __invoke_return1<_Rp _Class::*, _A0, _A1> { + typedef typename __enable_invoke<_Rp _Class::*, _A0>::type type; +}; + +template +struct __invoke_return2 +{ + typedef decltype(__invoke(_CUDA_VSTD::declval<_Tp&>(), _CUDA_VSTD::declval<_A0&>(), + _CUDA_VSTD::declval<_A1&>(), + _CUDA_VSTD::declval<_A2&>())) type; +}; + +template +struct __invoke_return2<_Ret _Class::*, _A0, _A1, _A2> { + typedef typename __enable_invoke<_Ret _Class::*, _A0>::type type; +}; +#endif // _LIBCUDACXX_FUNCTIONAL_BASE_03 diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/array.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/array.h new file mode 100644 index 0000000000000000000000000000000000000000..af3240d40bbf163b48cffa5677a42920318aa71f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/array.h @@ -0,0 +1,30 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FWD_ARRAY_H +#define _LIBCUDACXX___FWD_ARRAY_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct _LIBCUDACXX_TEMPLATE_VIS array; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_ARRAY_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/get.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/get.h new file mode 100644 index 0000000000000000000000000000000000000000..6cafa280c1207fcf8051a38bb7509fdafa6bade6 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/get.h @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FWD_GET_H +#define _LIBCUDACXX___FWD_GET_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__fwd/array.h" +#include "../__fwd/pair.h" +#include "../__fwd/tuple.h" +#include "../__tuple_dir/tuple_element.h" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#ifndef _LIBCUDACXX_CXX03_LANG + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(tuple<_Tp...>&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(const tuple<_Tp...>&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(tuple<_Tp...>&&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(const tuple<_Tp...>&&) _NOEXCEPT; + +#endif // _LIBCUDACXX_CXX03_LANG + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(pair<_T1, _T2>&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(const pair<_T1, _T2>&) _NOEXCEPT; + +#ifndef _LIBCUDACXX_CXX03_LANG +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(pair<_T1, _T2>&&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(const pair<_T1, _T2>&&) _NOEXCEPT; +#endif // _LIBCUDACXX_CXX03_LANG + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +_Tp& +get(array<_Tp, _Size>&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +const _Tp& +get(const array<_Tp, _Size>&) _NOEXCEPT; + +#ifndef _LIBCUDACXX_CXX03_LANG +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +_Tp&& +get(array<_Tp, _Size>&&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +const _Tp&& +get(const array<_Tp, _Size>&&) _NOEXCEPT; +#endif // _LIBCUDACXX_CXX03_LANG + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_GET_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/hash.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/hash.h new file mode 100644 index 0000000000000000000000000000000000000000..67cef524e4500142b97d07984bbaf85b09d88369 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/hash.h @@ -0,0 +1,28 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FWD_HASH_H +#define _LIBCUDACXX___FWD_HASH_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct _LIBCUDACXX_TEMPLATE_VIS hash; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_HASH_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/memory_resource.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/memory_resource.h new file mode 100644 index 0000000000000000000000000000000000000000..fe6b74d38ac4e6a739331926338a43893d9a46a9 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/memory_resource.h @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FWD_MEMORY_RESOURCE_H +#define _LIBCUDACXX___FWD_MEMORY_RESOURCE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +namespace pmr { +template +class _LIBCUDACXX_TEMPLATE_VIS polymorphic_allocator; +} // namespace pmr + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_MEMORY_RESOURCE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/pair.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/pair.h new file mode 100644 index 0000000000000000000000000000000000000000..eeb3b0a9bc2d7f45473d5409a5750a6a79dcc863 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/pair.h @@ -0,0 +1,28 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FWD_PAIR_H +#define _LIBCUDACXX___FWD_PAIR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct _LIBCUDACXX_TEMPLATE_VIS pair; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_PAIR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/span.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/span.h new file mode 100644 index 0000000000000000000000000000000000000000..10d19205499f4298587f1ef03e0a2a3990d0fc01 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/span.h @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FWD_SPAN_H +#define _LIBCUDACXX___FWD_SPAN_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_INLINE_VAR constexpr size_t dynamic_extent = static_cast(-1); +template class span; + +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + + +#endif // _LIBCUDACXX___FWD_SPAN_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/string.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/string.h new file mode 100644 index 0000000000000000000000000000000000000000..a24c849692e0aab30a8baf438d92386886867e24 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/string.h @@ -0,0 +1,114 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FWD_STRING_H +#define _LIBCUDACXX___FWD_STRING_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__fwd/memory_resource.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct _LIBCUDACXX_TEMPLATE_VIS char_traits; +template <> +struct char_traits; + +#ifndef _LIBCUDACXX_NO_HAS_CHAR8_T +template <> +struct char_traits; +#endif + +template <> +struct char_traits; +template <> +struct char_traits; + +#ifndef _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS +template <> +struct char_traits; +#endif + +template +class _LIBCUDACXX_TEMPLATE_VIS allocator; + +template , class _Allocator = allocator<_CharT> > +class _LIBCUDACXX_TEMPLATE_VIS basic_string; + +using string = basic_string; + +#ifndef _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS +using wstring = basic_string; +#endif + +#ifndef _LIBCUDACXX_NO_HAS_CHAR8_T +using u8string = basic_string; +#endif + +using u16string = basic_string; +using u32string = basic_string; + +#if _LIBCUDACXX_STD_VER >= 17 + +namespace pmr { +template > +using basic_string = std::basic_string<_CharT, _Traits, polymorphic_allocator<_CharT>>; + +using string = basic_string; + +# ifndef _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS +using wstring = basic_string; +# endif + +# ifndef _LIBCUDACXX_NO_HAS_CHAR8_T +using u8string = basic_string; +# endif + +using u16string = basic_string; +using u32string = basic_string; + +} // namespace pmr + +#endif // _LIBCUDACXX_STD_VER >= 17 + +// clang-format off +template +class _LIBCUDACXX_PREFERRED_NAME(string) +#ifndef _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS + _LIBCUDACXX_PREFERRED_NAME(wstring) +#endif +#ifndef _LIBCUDACXX_NO_HAS_CHAR8_T + _LIBCUDACXX_PREFERRED_NAME(u8string) +#endif + _LIBCUDACXX_PREFERRED_NAME(u16string) + _LIBCUDACXX_PREFERRED_NAME(u32string) +#if _LIBCUDACXX_STD_VER >= 17 + _LIBCUDACXX_PREFERRED_NAME(pmr::string) +# ifndef _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS + _LIBCUDACXX_PREFERRED_NAME(pmr::wstring) +# endif +# ifndef _LIBCUDACXX_NO_HAS_CHAR8_T + _LIBCUDACXX_PREFERRED_NAME(pmr::u8string) +# endif + _LIBCUDACXX_PREFERRED_NAME(pmr::u16string) + _LIBCUDACXX_PREFERRED_NAME(pmr::u32string) +#endif + basic_string; +// clang-format on + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_STRING_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/string_view.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/string_view.h new file mode 100644 index 0000000000000000000000000000000000000000..e82026ddd74a88e18a8aeaf0bf7ec0e954367561 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/string_view.h @@ -0,0 +1,54 @@ +// -*- C++ -*- +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FWD_STRING_VIEW_H +#define _LIBCUDACXX___FWD_STRING_VIEW_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__fwd/string.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template > +class _LIBCUDACXX_TEMPLATE_VIS basic_string_view; + +typedef basic_string_view string_view; +#ifndef _LIBCUDACXX_NO_HAS_CHAR8_T +typedef basic_string_view u8string_view; +#endif +typedef basic_string_view u16string_view; +typedef basic_string_view u32string_view; +#ifndef _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS +typedef basic_string_view wstring_view; +#endif + +// clang-format off +template +class _LIBCUDACXX_PREFERRED_NAME(string_view) +#ifndef _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS + _LIBCUDACXX_PREFERRED_NAME(wstring_view) +#endif +#ifndef _LIBCUDACXX_NO_HAS_CHAR8_T + _LIBCUDACXX_PREFERRED_NAME(u8string_view) +#endif + _LIBCUDACXX_PREFERRED_NAME(u16string_view) + _LIBCUDACXX_PREFERRED_NAME(u32string_view) + basic_string_view; +// clang-format on +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_STRING_VIEW_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/tuple.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/tuple.h new file mode 100644 index 0000000000000000000000000000000000000000..7803b15cef137073f0079ec4e45a7533e99e350b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__fwd/tuple.h @@ -0,0 +1,32 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FWD_TUPLE_H +#define _LIBCUDACXX___FWD_TUPLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#ifndef _LIBCUDACXX_CXX03_LANG + +template +class _LIBCUDACXX_TEMPLATE_VIS tuple; + +#endif // _LIBCUDACXX_CXX03_LANG + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_TUPLE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__hash_table b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__hash_table new file mode 100644 index 0000000000000000000000000000000000000000..ef190dfb7f763d0b374e9534b881c0672e7a6e79 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__hash_table @@ -0,0 +1,2927 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX__HASH_TABLE +#define _LIBCUDACXX__HASH_TABLE + +#include <__config> +#include +#include +#include +#include +#include +#include +#include + +#include "__assert" // all public C++ headers provide the assertion handler +#include "__debug" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_PUSH_MACROS +#include <__undef_macros> + + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct __hash_value_type; + +#ifndef _LIBCUDACXX_CXX03_LANG +template +struct __is_hash_value_type_imp : false_type {}; + +template +struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {}; + +template +struct __is_hash_value_type : false_type {}; + +template +struct __is_hash_value_type<_One> : __is_hash_value_type_imp<__remove_cvref_t<_One>> {}; +#endif + +_LIBCUDACXX_FUNC_VIS +size_t __next_prime(size_t __n); + +template +struct __hash_node_base +{ + typedef typename pointer_traits<_NodePtr>::element_type __node_type; + typedef __hash_node_base __first_node; + typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer; + typedef _NodePtr __node_pointer; + +#if defined(_LIBCUDACXX_ABI_FIX_UNORDERED_NODE_POINTER_UB) + typedef __node_base_pointer __next_pointer; +#else + typedef typename conditional< + is_pointer<__node_pointer>::value, + __node_base_pointer, + __node_pointer>::type __next_pointer; +#endif + + __next_pointer __next_; + + _LIBCUDACXX_INLINE_VISIBILITY + __next_pointer __ptr() _NOEXCEPT { + return static_cast<__next_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(*this)); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __node_pointer __upcast() _NOEXCEPT { + return static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(*this)); + } + + _LIBCUDACXX_INLINE_VISIBILITY + size_t __hash() const _NOEXCEPT { + return static_cast<__node_type const&>(*this).__hash_; + } + + _LIBCUDACXX_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {} +}; + +template +struct __hash_node + : public __hash_node_base + < + typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type + > +{ + typedef _Tp __node_value_type; + + size_t __hash_; + __node_value_type __value_; +}; + +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +__is_hash_power2(size_t __bc) +{ + return __bc > 2 && !(__bc & (__bc - 1)); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t +__constrain_hash(size_t __h, size_t __bc) +{ + return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : + (__h < __bc ? __h : __h % __bc); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t +__next_hash_pow2(size_t __n) +{ + return __n < 2 ? __n : (size_t(1) << (std::numeric_limits::digits - __libcpp_clz(__n-1))); +} + + +template class __hash_table; + +template class _LIBCUDACXX_TEMPLATE_VIS __hash_iterator; +template class _LIBCUDACXX_TEMPLATE_VIS __hash_const_iterator; +template class _LIBCUDACXX_TEMPLATE_VIS __hash_local_iterator; +template class _LIBCUDACXX_TEMPLATE_VIS __hash_const_local_iterator; +template class _LIBCUDACXX_TEMPLATE_VIS __hash_map_iterator; +template class _LIBCUDACXX_TEMPLATE_VIS __hash_map_const_iterator; + +template +struct __hash_key_value_types { + static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, ""); + typedef _Tp key_type; + typedef _Tp __node_value_type; + typedef _Tp __container_value_type; + static const bool __is_map = false; + + _LIBCUDACXX_INLINE_VISIBILITY + static key_type const& __get_key(_Tp const& __v) { + return __v; + } + _LIBCUDACXX_INLINE_VISIBILITY + static __container_value_type const& __get_value(__node_value_type const& __v) { + return __v; + } + _LIBCUDACXX_INLINE_VISIBILITY + static __container_value_type* __get_ptr(__node_value_type& __n) { + return _CUDA_VSTD::addressof(__n); + } +#ifndef _LIBCUDACXX_CXX03_LANG + _LIBCUDACXX_INLINE_VISIBILITY + static __container_value_type&& __move(__node_value_type& __v) { + return _CUDA_VSTD::move(__v); + } +#endif +}; + +template +struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > { + typedef _Key key_type; + typedef _Tp mapped_type; + typedef __hash_value_type<_Key, _Tp> __node_value_type; + typedef pair __container_value_type; + typedef __container_value_type __map_value_type; + static const bool __is_map = true; + + _LIBCUDACXX_INLINE_VISIBILITY + static key_type const& __get_key(__container_value_type const& __v) { + return __v.first; + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value, + __container_value_type const&>::type + __get_value(_Up& __t) { + return __t.__get_value(); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, + __container_value_type const&>::type + __get_value(_Up& __t) { + return __t; + } + + _LIBCUDACXX_INLINE_VISIBILITY + static __container_value_type* __get_ptr(__node_value_type& __n) { + return _CUDA_VSTD::addressof(__n.__get_value()); + } +#ifndef _LIBCUDACXX_CXX03_LANG + _LIBCUDACXX_INLINE_VISIBILITY + static pair __move(__node_value_type& __v) { + return __v.__move(); + } +#endif + +}; + +template , + bool = _KVTypes::__is_map> +struct __hash_map_pointer_types {}; + +template +struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { + typedef typename _KVTypes::__map_value_type _Mv; + typedef typename __rebind_pointer<_AllocPtr, _Mv>::type + __map_value_type_pointer; + typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type + __const_map_value_type_pointer; +}; + +template ::element_type> +struct __hash_node_types; + +template +struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> > + : public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr> + +{ + typedef __hash_key_value_types<_Tp> __base; + +public: + typedef ptrdiff_t difference_type; + typedef size_t size_type; + + typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer; + + typedef typename pointer_traits<_NodePtr>::element_type __node_type; + typedef _NodePtr __node_pointer; + + typedef __hash_node_base<__node_pointer> __node_base_type; + typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type + __node_base_pointer; + + typedef typename __node_base_type::__next_pointer __next_pointer; + + typedef _Tp __node_value_type; + typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type + __node_value_type_pointer; + typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type + __const_node_value_type_pointer; + +private: + static_assert(!is_const<__node_type>::value, + "_NodePtr should never be a pointer to const"); + static_assert((is_same::element_type, void>::value), + "_VoidPtr does not point to unqualified void type"); + static_assert((is_same::type, + _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr."); +}; + +template +struct __hash_node_types_from_iterator; +template +struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; +template +struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; +template +struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; +template +struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; + + +template +struct __make_hash_node_types { + typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp; + typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr; + typedef __hash_node_types<_NodePtr> type; +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS __hash_iterator +{ + typedef __hash_node_types<_NodePtr> _NodeTypes; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef value_type& reference; + typedef typename _NodeTypes::__node_value_type_pointer pointer; + + _LIBCUDACXX_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__insert_i(this)); +#endif + } + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator(const __hash_iterator& __i) + : __node_(__i.__node_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__hash_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator& operator=(const __hash_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + } + return *this; + } +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + + _LIBCUDACXX_INLINE_VISIBILITY + reference operator*() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container iterator"); + return __node_->__upcast()->__value_; + } + + _LIBCUDACXX_INLINE_VISIBILITY + pointer operator->() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container iterator"); + return pointer_traits::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator& operator++() { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container iterator"); + __node_ = __node_->__next_; + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator operator++(int) + { + __hash_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator==(const __hash_iterator& __x, const __hash_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y) + {return !(__x == __y);} + +private: +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT + : __node_(__node) + { + __get_db()->__insert_ic(this, __c); + } +#else + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator(__next_pointer __node) _NOEXCEPT + : __node_(__node) + {} +#endif + template friend class __hash_table; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_const_iterator; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_map_iterator; + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_map; + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_multimap; +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS __hash_const_iterator +{ + static_assert(!is_const::element_type>::value, ""); + typedef __hash_node_types<_NodePtr> _NodeTypes; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + +public: + typedef __hash_iterator<_NodePtr> __non_const_iterator; + + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef const value_type& reference; + typedef typename _NodeTypes::__const_node_value_type_pointer pointer; + + + _LIBCUDACXX_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__insert_i(this)); +#endif + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT + : __node_(__x.__node_) + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); +#endif + } + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator(const __hash_const_iterator& __i) + : __node_(__i.__node_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__hash_const_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator& operator=(const __hash_const_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + } + return *this; + } +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + + _LIBCUDACXX_INLINE_VISIBILITY + reference operator*() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_iterator"); + return __node_->__upcast()->__value_; + } + _LIBCUDACXX_INLINE_VISIBILITY + pointer operator->() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_iterator"); + return pointer_traits::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator& operator++() { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container const_iterator"); + __node_ = __node_->__next_; + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator operator++(int) + { + __hash_const_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y) + {return !(__x == __y);} + +private: +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT + : __node_(__node) + { + __get_db()->__insert_ic(this, __c); + } +#else + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator(__next_pointer __node) _NOEXCEPT + : __node_(__node) + {} +#endif + template friend class __hash_table; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_map_const_iterator; + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_map; + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_multimap; +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS __hash_local_iterator +{ + typedef __hash_node_types<_NodePtr> _NodeTypes; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + size_t __bucket_; + size_t __bucket_count_; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef value_type& reference; + typedef typename _NodeTypes::__node_value_type_pointer pointer; + + _LIBCUDACXX_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__insert_i(this)); +#endif + } + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator(const __hash_local_iterator& __i) + : __node_(__i.__node_), + __bucket_(__i.__bucket_), + __bucket_count_(__i.__bucket_count_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__hash_local_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator& operator=(const __hash_local_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + __bucket_ = __i.__bucket_; + __bucket_count_ = __i.__bucket_count_; + } + return *this; + } +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + + _LIBCUDACXX_INLINE_VISIBILITY + reference operator*() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container local_iterator"); + return __node_->__upcast()->__value_; + } + + _LIBCUDACXX_INLINE_VISIBILITY + pointer operator->() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container local_iterator"); + return pointer_traits::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator& operator++() { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container local_iterator"); + __node_ = __node_->__next_; + if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) + __node_ = nullptr; + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator operator++(int) + { + __hash_local_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y) + {return !(__x == __y);} + +private: +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count, const void* __c) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + __get_db()->__insert_ic(this, __c); + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#else + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#endif + template friend class __hash_table; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_const_local_iterator; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_map_iterator; +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS __hash_const_local_iterator +{ + typedef __hash_node_types<_ConstNodePtr> _NodeTypes; + typedef _ConstNodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + size_t __bucket_; + size_t __bucket_count_; + + typedef pointer_traits<__node_pointer> __pointer_traits; + typedef typename __pointer_traits::element_type __node; + typedef __remove_const_t<__node> __non_const_node; + typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type + __non_const_node_pointer; +public: + typedef __hash_local_iterator<__non_const_node_pointer> + __non_const_iterator; + + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef const value_type& reference; + typedef typename _NodeTypes::__const_node_value_type_pointer pointer; + + + _LIBCUDACXX_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__insert_i(this)); +#endif + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT + : __node_(__x.__node_), + __bucket_(__x.__bucket_), + __bucket_count_(__x.__bucket_count_) + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); +#endif + } + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator(const __hash_const_local_iterator& __i) + : __node_(__i.__node_), + __bucket_(__i.__bucket_), + __bucket_count_(__i.__bucket_count_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__hash_const_local_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + __bucket_ = __i.__bucket_; + __bucket_count_ = __i.__bucket_count_; + } + return *this; + } +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + + _LIBCUDACXX_INLINE_VISIBILITY + reference operator*() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); + return __node_->__upcast()->__value_; + } + + _LIBCUDACXX_INLINE_VISIBILITY + pointer operator->() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); + return pointer_traits::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator& operator++() { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container const_local_iterator"); + __node_ = __node_->__next_; + if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) + __node_ = nullptr; + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator operator++(int) + { + __hash_const_local_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) + {return !(__x == __y);} + +private: +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count, const void* __c) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + __get_db()->__insert_ic(this, __c); + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#else + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#endif + template friend class __hash_table; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_map_const_iterator; +}; + +template +class __bucket_list_deallocator +{ + typedef _Alloc allocator_type; + typedef allocator_traits __alloc_traits; + typedef typename __alloc_traits::size_type size_type; + + __compressed_pair __data_; +public: + typedef typename __alloc_traits::pointer pointer; + + _LIBCUDACXX_INLINE_VISIBILITY + __bucket_list_deallocator() + _NOEXCEPT_(is_nothrow_default_constructible::value) + : __data_(0) {} + + _LIBCUDACXX_INLINE_VISIBILITY + __bucket_list_deallocator(const allocator_type& __a, size_type __size) + _NOEXCEPT_(is_nothrow_copy_constructible::value) + : __data_(__size, __a) {} + +#ifndef _LIBCUDACXX_CXX03_LANG + _LIBCUDACXX_INLINE_VISIBILITY + __bucket_list_deallocator(__bucket_list_deallocator&& __x) + _NOEXCEPT_(is_nothrow_move_constructible::value) + : __data_(_CUDA_VSTD::move(__x.__data_)) + { + __x.size() = 0; + } +#endif + + _LIBCUDACXX_INLINE_VISIBILITY + size_type& size() _NOEXCEPT {return __data_.first();} + _LIBCUDACXX_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __data_.first();} + + _LIBCUDACXX_INLINE_VISIBILITY + allocator_type& __alloc() _NOEXCEPT {return __data_.second();} + _LIBCUDACXX_INLINE_VISIBILITY + const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();} + + _LIBCUDACXX_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + __alloc_traits::deallocate(__alloc(), __p, size()); + } +}; + +template class __hash_map_node_destructor; + +template +class __hash_node_destructor +{ + typedef _Alloc allocator_type; + typedef allocator_traits __alloc_traits; + +public: + typedef typename __alloc_traits::pointer pointer; +private: + typedef __hash_node_types _NodeTypes; + + allocator_type& __na_; + +public: + bool __value_constructed; + + __hash_node_destructor(__hash_node_destructor const&) = default; + __hash_node_destructor& operator=(const __hash_node_destructor&) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __hash_node_destructor(allocator_type& __na, + bool __constructed = false) _NOEXCEPT + : __na_(__na), + __value_constructed(__constructed) + {} + + _LIBCUDACXX_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + if (__value_constructed) + __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } + + template friend class __hash_map_node_destructor; +}; + +#if _LIBCUDACXX_STD_VER > 14 +template +struct __generic_container_node_destructor; + +template +struct __generic_container_node_destructor<__hash_node<_Tp, _VoidPtr>, _Alloc> + : __hash_node_destructor<_Alloc> +{ + using __hash_node_destructor<_Alloc>::__hash_node_destructor; +}; +#endif + +template +struct __enforce_unordered_container_requirements { +#ifndef _LIBCUDACXX_CXX03_LANG + static_assert(__check_hash_requirements<_Key, _Hash>::value, + "the specified hash does not meet the Hash requirements"); + static_assert(is_copy_constructible<_Equal>::value, + "the specified comparator is required to be copy constructible"); +#endif + typedef int type; +}; + +template +#ifndef _LIBCUDACXX_CXX03_LANG + _LIBCUDACXX_DIAGNOSE_WARNING(!__invokable<_Equal const&, _Key const&, _Key const&>::value, + "the specified comparator type does not provide a viable const call operator") + _LIBCUDACXX_DIAGNOSE_WARNING(!__invokable<_Hash const&, _Key const&>::value, + "the specified hash functor does not provide a viable const call operator") +#endif +typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type +__diagnose_unordered_container_requirements(int); + +// This dummy overload is used so that the compiler won't emit a spurious +// "no matching function for call to __diagnose_unordered_xxx" diagnostic +// when the overload above causes a hard error. +template +int __diagnose_unordered_container_requirements(void*); + +template +class __hash_table +{ +public: + typedef _Tp value_type; + typedef _Hash hasher; + typedef _Equal key_equal; + typedef _Alloc allocator_type; + +private: + typedef allocator_traits __alloc_traits; + typedef typename + __make_hash_node_types::type + _NodeTypes; +public: + + typedef typename _NodeTypes::__node_value_type __node_value_type; + typedef typename _NodeTypes::__container_value_type __container_value_type; + typedef typename _NodeTypes::key_type key_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; +#ifndef _LIBCUDACXX_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE + typedef typename __alloc_traits::size_type size_type; +#else + typedef typename _NodeTypes::size_type size_type; +#endif + typedef typename _NodeTypes::difference_type difference_type; +public: + // Create __node + + typedef typename _NodeTypes::__node_type __node; + typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; + typedef allocator_traits<__node_allocator> __node_traits; + typedef typename _NodeTypes::__void_pointer __void_pointer; + typedef typename _NodeTypes::__node_pointer __node_pointer; + typedef typename _NodeTypes::__node_pointer __node_const_pointer; + typedef typename _NodeTypes::__node_base_type __first_node; + typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + +private: + // check for sane allocator pointer rebinding semantics. Rebinding the + // allocator for a new pointer type should be exactly the same as rebinding + // the pointer using 'pointer_traits'. + static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), + "Allocator does not rebind pointers in a sane manner."); + typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type + __node_base_allocator; + typedef allocator_traits<__node_base_allocator> __node_base_traits; + static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), + "Allocator does not rebind pointers in a sane manner."); + +private: + + typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator; + typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; + typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list; + typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; + typedef typename __bucket_list_deleter::pointer __node_pointer_pointer; + + // --- Member data begin --- + __bucket_list __bucket_list_; + __compressed_pair<__first_node, __node_allocator> __p1_; + __compressed_pair __p2_; + __compressed_pair __p3_; + // --- Member data end --- + + _LIBCUDACXX_INLINE_VISIBILITY + size_type& size() _NOEXCEPT {return __p2_.first();} +public: + _LIBCUDACXX_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __p2_.first();} + + _LIBCUDACXX_INLINE_VISIBILITY + hasher& hash_function() _NOEXCEPT {return __p2_.second();} + _LIBCUDACXX_INLINE_VISIBILITY + const hasher& hash_function() const _NOEXCEPT {return __p2_.second();} + + _LIBCUDACXX_INLINE_VISIBILITY + float& max_load_factor() _NOEXCEPT {return __p3_.first();} + _LIBCUDACXX_INLINE_VISIBILITY + float max_load_factor() const _NOEXCEPT {return __p3_.first();} + + _LIBCUDACXX_INLINE_VISIBILITY + key_equal& key_eq() _NOEXCEPT {return __p3_.second();} + _LIBCUDACXX_INLINE_VISIBILITY + const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();} + + _LIBCUDACXX_INLINE_VISIBILITY + __node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();} + _LIBCUDACXX_INLINE_VISIBILITY + const __node_allocator& __node_alloc() const _NOEXCEPT + {return __p1_.second();} + +public: + typedef __hash_iterator<__node_pointer> iterator; + typedef __hash_const_iterator<__node_pointer> const_iterator; + typedef __hash_local_iterator<__node_pointer> local_iterator; + typedef __hash_const_local_iterator<__node_pointer> const_local_iterator; + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_table() + _NOEXCEPT_( + is_nothrow_default_constructible<__bucket_list>::value && + is_nothrow_default_constructible<__first_node>::value && + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_default_constructible::value && + is_nothrow_default_constructible::value); + _LIBCUDACXX_INLINE_VISIBILITY + __hash_table(const hasher& __hf, const key_equal& __eql); + __hash_table(const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); + explicit __hash_table(const allocator_type& __a); + __hash_table(const __hash_table& __u); + __hash_table(const __hash_table& __u, const allocator_type& __a); +#ifndef _LIBCUDACXX_CXX03_LANG + __hash_table(__hash_table&& __u) + _NOEXCEPT_( + is_nothrow_move_constructible<__bucket_list>::value && + is_nothrow_move_constructible<__first_node>::value && + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible::value && + is_nothrow_move_constructible::value); + __hash_table(__hash_table&& __u, const allocator_type& __a); +#endif // _LIBCUDACXX_CXX03_LANG + ~__hash_table(); + + __hash_table& operator=(const __hash_table& __u); +#ifndef _LIBCUDACXX_CXX03_LANG + _LIBCUDACXX_INLINE_VISIBILITY + __hash_table& operator=(__hash_table&& __u) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value); +#endif + template + void __assign_unique(_InputIterator __first, _InputIterator __last); + template + void __assign_multi(_InputIterator __first, _InputIterator __last); + + _LIBCUDACXX_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT + { + return std::min( + __node_traits::max_size(__node_alloc()), + numeric_limits::max() + ); + } + +private: + _LIBCUDACXX_INLINE_VISIBILITY + __next_pointer __node_insert_multi_prepare(size_t __cp_hash, + value_type& __cp_val); + _LIBCUDACXX_INLINE_VISIBILITY + void __node_insert_multi_perform(__node_pointer __cp, + __next_pointer __pn) _NOEXCEPT; + + _LIBCUDACXX_INLINE_VISIBILITY + __next_pointer __node_insert_unique_prepare(size_t __nd_hash, + value_type& __nd_val); + _LIBCUDACXX_INLINE_VISIBILITY + void __node_insert_unique_perform(__node_pointer __ptr) _NOEXCEPT; + +public: + _LIBCUDACXX_INLINE_VISIBILITY + pair __node_insert_unique(__node_pointer __nd); + _LIBCUDACXX_INLINE_VISIBILITY + iterator __node_insert_multi(__node_pointer __nd); + _LIBCUDACXX_INLINE_VISIBILITY + iterator __node_insert_multi(const_iterator __p, + __node_pointer __nd); + +#ifndef _LIBCUDACXX_CXX03_LANG + template + _LIBCUDACXX_INLINE_VISIBILITY + pair __emplace_unique_key_args(_Key const& __k, _Args&&... __args); + + template + _LIBCUDACXX_INLINE_VISIBILITY + pair __emplace_unique_impl(_Args&&... __args); + + template + _LIBCUDACXX_INLINE_VISIBILITY + pair __emplace_unique(_Pp&& __x) { + return __emplace_unique_extract_key(_CUDA_VSTD::forward<_Pp>(__x), + __can_extract_key<_Pp, key_type>()); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + typename enable_if< + __can_extract_map_key<_First, key_type, __container_value_type>::value, + pair + >::type __emplace_unique(_First&& __f, _Second&& __s) { + return __emplace_unique_key_args(__f, _CUDA_VSTD::forward<_First>(__f), + _CUDA_VSTD::forward<_Second>(__s)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + pair __emplace_unique(_Args&&... __args) { + return __emplace_unique_impl(_CUDA_VSTD::forward<_Args>(__args)...); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + pair + __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { + return __emplace_unique_impl(_CUDA_VSTD::forward<_Pp>(__x)); + } + template + _LIBCUDACXX_INLINE_VISIBILITY + pair + __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { + return __emplace_unique_key_args(__x, _CUDA_VSTD::forward<_Pp>(__x)); + } + template + _LIBCUDACXX_INLINE_VISIBILITY + pair + __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { + return __emplace_unique_key_args(__x.first, _CUDA_VSTD::forward<_Pp>(__x)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __emplace_multi(_Args&&... __args); + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); + + + _LIBCUDACXX_INLINE_VISIBILITY + pair + __insert_unique(__container_value_type&& __x) { + return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _CUDA_VSTD::move(__x)); + } + + template ::value + >::type> + _LIBCUDACXX_INLINE_VISIBILITY + pair __insert_unique(_Pp&& __x) { + return __emplace_unique(_CUDA_VSTD::forward<_Pp>(__x)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __insert_multi(_Pp&& __x) { + return __emplace_multi(_CUDA_VSTD::forward<_Pp>(__x)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __insert_multi(const_iterator __p, _Pp&& __x) { + return __emplace_hint_multi(__p, _CUDA_VSTD::forward<_Pp>(__x)); + } + +#else // !defined(_LIBCUDACXX_CXX03_LANG) + template + _LIBCUDACXX_INLINE_VISIBILITY + pair __emplace_unique_key_args(_Key const&, _Args& __args); + + iterator __insert_multi(const __container_value_type& __x); + iterator __insert_multi(const_iterator __p, const __container_value_type& __x); +#endif + + _LIBCUDACXX_INLINE_VISIBILITY + pair __insert_unique(const __container_value_type& __x) { + return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x); + } + +#if _LIBCUDACXX_STD_VER > 14 + template + _LIBCUDACXX_INLINE_VISIBILITY + _InsertReturnType __node_handle_insert_unique(_NodeHandle&& __nh); + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __node_handle_insert_unique(const_iterator __hint, + _NodeHandle&& __nh); + template + _LIBCUDACXX_INLINE_VISIBILITY + void __node_handle_merge_unique(_Table& __source); + + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __node_handle_insert_multi(_NodeHandle&& __nh); + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __node_handle_insert_multi(const_iterator __hint, _NodeHandle&& __nh); + template + _LIBCUDACXX_INLINE_VISIBILITY + void __node_handle_merge_multi(_Table& __source); + + template + _LIBCUDACXX_INLINE_VISIBILITY + _NodeHandle __node_handle_extract(key_type const& __key); + template + _LIBCUDACXX_INLINE_VISIBILITY + _NodeHandle __node_handle_extract(const_iterator __it); +#endif + + void clear() _NOEXCEPT; + void rehash(size_type __n); + _LIBCUDACXX_INLINE_VISIBILITY void reserve(size_type __n) + {rehash(static_cast(ceil(__n / max_load_factor())));} + + _LIBCUDACXX_INLINE_VISIBILITY + size_type bucket_count() const _NOEXCEPT + { + return __bucket_list_.get_deleter().size(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + iterator begin() _NOEXCEPT; + _LIBCUDACXX_INLINE_VISIBILITY + iterator end() _NOEXCEPT; + _LIBCUDACXX_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT; + _LIBCUDACXX_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT; + + template + _LIBCUDACXX_INLINE_VISIBILITY + size_type bucket(const _Key& __k) const + { + _LIBCUDACXX_ASSERT(bucket_count() > 0, + "unordered container::bucket(key) called when bucket_count() == 0"); + return __constrain_hash(hash_function()(__k), bucket_count()); + } + + template + iterator find(const _Key& __x); + template + const_iterator find(const _Key& __x) const; + + typedef __hash_node_destructor<__node_allocator> _Dp; + typedef unique_ptr<__node, _Dp> __node_holder; + + iterator erase(const_iterator __p); + iterator erase(const_iterator __first, const_iterator __last); + template + size_type __erase_unique(const _Key& __k); + template + size_type __erase_multi(const _Key& __k); + __node_holder remove(const_iterator __p) _NOEXCEPT; + + template + _LIBCUDACXX_INLINE_VISIBILITY + size_type __count_unique(const _Key& __k) const; + template + size_type __count_multi(const _Key& __k) const; + + template + pair + __equal_range_unique(const _Key& __k); + template + pair + __equal_range_unique(const _Key& __k) const; + + template + pair + __equal_range_multi(const _Key& __k); + template + pair + __equal_range_multi(const _Key& __k) const; + + void swap(__hash_table& __u) +#if _LIBCUDACXX_STD_VER <= 11 + _NOEXCEPT_( + __is_nothrow_swappable::value && __is_nothrow_swappable::value + && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value + || __is_nothrow_swappable<__pointer_allocator>::value) + && (!__node_traits::propagate_on_container_swap::value + || __is_nothrow_swappable<__node_allocator>::value) + ); +#else + _NOEXCEPT_(__is_nothrow_swappable::value && __is_nothrow_swappable::value); +#endif + + _LIBCUDACXX_INLINE_VISIBILITY + size_type max_bucket_count() const _NOEXCEPT + {return max_size(); } + size_type bucket_size(size_type __n) const; + _LIBCUDACXX_INLINE_VISIBILITY float load_factor() const _NOEXCEPT + { + size_type __bc = bucket_count(); + return __bc != 0 ? (float)size() / __bc : 0.f; + } + _LIBCUDACXX_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT + { + _LIBCUDACXX_ASSERT(__mlf > 0, + "unordered container::max_load_factor(lf) called with lf <= 0"); + max_load_factor() = _CUDA_VSTD::max(__mlf, load_factor()); + } + + _LIBCUDACXX_INLINE_VISIBILITY + local_iterator + begin(size_type __n) + { + _LIBCUDACXX_ASSERT(__n < bucket_count(), + "unordered container::begin(n) called with n >= bucket_count()"); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return local_iterator(__bucket_list_[__n], __n, bucket_count(), this); +#else + return local_iterator(__bucket_list_[__n], __n, bucket_count()); +#endif + } + + _LIBCUDACXX_INLINE_VISIBILITY + local_iterator + end(size_type __n) + { + _LIBCUDACXX_ASSERT(__n < bucket_count(), + "unordered container::end(n) called with n >= bucket_count()"); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return local_iterator(nullptr, __n, bucket_count(), this); +#else + return local_iterator(nullptr, __n, bucket_count()); +#endif + } + + _LIBCUDACXX_INLINE_VISIBILITY + const_local_iterator + cbegin(size_type __n) const + { + _LIBCUDACXX_ASSERT(__n < bucket_count(), + "unordered container::cbegin(n) called with n >= bucket_count()"); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this); +#else + return const_local_iterator(__bucket_list_[__n], __n, bucket_count()); +#endif + } + + _LIBCUDACXX_INLINE_VISIBILITY + const_local_iterator + cend(size_type __n) const + { + _LIBCUDACXX_ASSERT(__n < bucket_count(), + "unordered container::cend(n) called with n >= bucket_count()"); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return const_local_iterator(nullptr, __n, bucket_count(), this); +#else + return const_local_iterator(nullptr, __n, bucket_count()); +#endif + } + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + + bool __dereferenceable(const const_iterator* __i) const; + bool __decrementable(const const_iterator* __i) const; + bool __addable(const const_iterator* __i, ptrdiff_t __n) const; + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; + +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + +private: + void __rehash(size_type __n); + +#ifndef _LIBCUDACXX_CXX03_LANG + template + __node_holder __construct_node(_Args&& ...__args); + + template + __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest); +#else // _LIBCUDACXX_CXX03_LANG + __node_holder __construct_node(const __container_value_type& __v); + __node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v); +#endif + + + _LIBCUDACXX_INLINE_VISIBILITY + void __copy_assign_alloc(const __hash_table& __u) + {__copy_assign_alloc(__u, integral_constant());} + void __copy_assign_alloc(const __hash_table& __u, true_type); + _LIBCUDACXX_INLINE_VISIBILITY + void __copy_assign_alloc(const __hash_table&, false_type) {} + +#ifndef _LIBCUDACXX_CXX03_LANG + void __move_assign(__hash_table& __u, false_type); + void __move_assign(__hash_table& __u, true_type) + _NOEXCEPT_( + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value); + _LIBCUDACXX_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table& __u) + _NOEXCEPT_( + !__node_traits::propagate_on_container_move_assignment::value || + (is_nothrow_move_assignable<__pointer_allocator>::value && + is_nothrow_move_assignable<__node_allocator>::value)) + {__move_assign_alloc(__u, integral_constant());} + _LIBCUDACXX_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table& __u, true_type) + _NOEXCEPT_( + is_nothrow_move_assignable<__pointer_allocator>::value && + is_nothrow_move_assignable<__node_allocator>::value) + { + __bucket_list_.get_deleter().__alloc() = + _CUDA_VSTD::move(__u.__bucket_list_.get_deleter().__alloc()); + __node_alloc() = _CUDA_VSTD::move(__u.__node_alloc()); + } + _LIBCUDACXX_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {} +#endif // _LIBCUDACXX_CXX03_LANG + + void __deallocate_node(__next_pointer __np) _NOEXCEPT; + __next_pointer __detach() _NOEXCEPT; + + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_map; + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_multimap; +}; + +template +inline +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() + _NOEXCEPT_( + is_nothrow_default_constructible<__bucket_list>::value && + is_nothrow_default_constructible<__first_node>::value && + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_default_constructible::value && + is_nothrow_default_constructible::value) + : __p2_(0), + __p3_(1.0f) +{ +} + +template +inline +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, + const key_equal& __eql) + : __bucket_list_(nullptr, __bucket_list_deleter()), + __p1_(), + __p2_(0, __hf), + __p3_(1.0f, __eql) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0, __hf), + __p3_(1.0f, __eql) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0), + __p3_(1.0f) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) + : __bucket_list_(nullptr, + __bucket_list_deleter(allocator_traits<__pointer_allocator>:: + select_on_container_copy_construction( + __u.__bucket_list_.get_deleter().__alloc()), 0)), + __p1_(__second_tag(), allocator_traits<__node_allocator>:: + select_on_container_copy_construction(__u.__node_alloc())), + __p2_(0, __u.hash_function()), + __p3_(__u.__p3_) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0, __u.hash_function()), + __p3_(__u.__p3_) +{ +} + +#ifndef _LIBCUDACXX_CXX03_LANG + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) + _NOEXCEPT_( + is_nothrow_move_constructible<__bucket_list>::value && + is_nothrow_move_constructible<__first_node>::value && + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible::value && + is_nothrow_move_constructible::value) + : __bucket_list_(_CUDA_VSTD::move(__u.__bucket_list_)), + __p1_(_CUDA_VSTD::move(__u.__p1_)), + __p2_(_CUDA_VSTD::move(__u.__p2_)), + __p3_(_CUDA_VSTD::move(__u.__p3_)) +{ + if (size() > 0) + { + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + __u.__p1_.first().__next_ = nullptr; + __u.size() = 0; + } +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0, _CUDA_VSTD::move(__u.hash_function())), + __p3_(_CUDA_VSTD::move(__u.__p3_)) +{ + if (__a == allocator_type(__u.__node_alloc())) + { + __bucket_list_.reset(__u.__bucket_list_.release()); + __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); + __u.__bucket_list_.get_deleter().size() = 0; + if (__u.size() > 0) + { + __p1_.first().__next_ = __u.__p1_.first().__next_; + __u.__p1_.first().__next_ = nullptr; + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + size() = __u.size(); + __u.size() = 0; + } + } +} + +#endif // _LIBCUDACXX_CXX03_LANG + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() +{ +#if defined(_LIBCUDACXX_CXX03_LANG) + static_assert((is_copy_constructible::value), + "Predicate must be copy-constructible."); + static_assert((is_copy_constructible::value), + "Hasher must be copy-constructible."); +#endif + + __deallocate_node(__p1_.first().__next_); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __get_db()->__erase_c(this); +#endif +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc( + const __hash_table& __u, true_type) +{ + if (__node_alloc() != __u.__node_alloc()) + { + clear(); + __bucket_list_.reset(); + __bucket_list_.get_deleter().size() = 0; + } + __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc(); + __node_alloc() = __u.__node_alloc(); +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>& +__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u) +{ + if (this != &__u) + { + __copy_assign_alloc(__u); + hash_function() = __u.hash_function(); + key_eq() = __u.key_eq(); + max_load_factor() = __u.max_load_factor(); + __assign_multi(__u.begin(), __u.end()); + } + return *this; +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np) + _NOEXCEPT +{ + __node_allocator& __na = __node_alloc(); + while (__np != nullptr) + { + __next_pointer __next = __np->__next_; +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast((*__p)->__i_); + if (__i->__node_ == __np) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __node_pointer __real_np = __np->__upcast(); + __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_)); + __node_traits::deallocate(__na, __real_np, 1); + __np = __next; + } +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT +{ + size_type __bc = bucket_count(); + for (size_type __i = 0; __i < __bc; ++__i) + __bucket_list_[__i] = nullptr; + size() = 0; + __next_pointer __cache = __p1_.first().__next_; + __p1_.first().__next_ = nullptr; + return __cache; +} + +#ifndef _LIBCUDACXX_CXX03_LANG + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( + __hash_table& __u, true_type) + _NOEXCEPT_( + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value) +{ + clear(); + __bucket_list_.reset(__u.__bucket_list_.release()); + __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); + __u.__bucket_list_.get_deleter().size() = 0; + __move_assign_alloc(__u); + size() = __u.size(); + hash_function() = _CUDA_VSTD::move(__u.hash_function()); + max_load_factor() = __u.max_load_factor(); + key_eq() = _CUDA_VSTD::move(__u.key_eq()); + __p1_.first().__next_ = __u.__p1_.first().__next_; + if (size() > 0) + { + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + __u.__p1_.first().__next_ = nullptr; + __u.size() = 0; + } +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __get_db()->swap(this, &__u); +#endif +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( + __hash_table& __u, false_type) +{ + if (__node_alloc() == __u.__node_alloc()) + __move_assign(__u, true_type()); + else + { + hash_function() = _CUDA_VSTD::move(__u.hash_function()); + key_eq() = _CUDA_VSTD::move(__u.key_eq()); + max_load_factor() = __u.max_load_factor(); + if (bucket_count() != 0) + { + __next_pointer __cache = __detach(); +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + try + { +#endif // _LIBCUDACXX_NO_EXCEPTIONS + const_iterator __i = __u.begin(); + while (__cache != nullptr && __u.size() != 0) + { + __cache->__upcast()->__value_ = + _CUDA_VSTD::move(__u.remove(__i++)->__value_); + __next_pointer __next = __cache->__next_; + __node_insert_multi(__cache->__upcast()); + __cache = __next; + } +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + } + catch (...) + { + __deallocate_node(__cache); + throw; + } +#endif // _LIBCUDACXX_NO_EXCEPTIONS + __deallocate_node(__cache); + } + const_iterator __i = __u.begin(); + while (__u.size() != 0) + { + __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_)); + __node_insert_multi(__h.get()); + __h.release(); + } + } +} + +template +inline +__hash_table<_Tp, _Hash, _Equal, _Alloc>& +__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value) +{ + __move_assign(__u, integral_constant()); + return *this; +} + +#endif // _LIBCUDACXX_CXX03_LANG + +template +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first, + _InputIterator __last) +{ + typedef iterator_traits<_InputIterator> _ITraits; + typedef typename _ITraits::value_type _ItValueType; + static_assert((is_same<_ItValueType, __container_value_type>::value), + "__assign_unique may only be called with the containers value type"); + + if (bucket_count() != 0) + { + __next_pointer __cache = __detach(); +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + try + { +#endif // _LIBCUDACXX_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__upcast()->__value_ = *__first; + __next_pointer __next = __cache->__next_; + __node_insert_unique(__cache->__upcast()); + __cache = __next; + } +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + } + catch (...) + { + __deallocate_node(__cache); + throw; + } +#endif // _LIBCUDACXX_NO_EXCEPTIONS + __deallocate_node(__cache); + } + for (; __first != __last; ++__first) + __insert_unique(*__first); +} + +template +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first, + _InputIterator __last) +{ + typedef iterator_traits<_InputIterator> _ITraits; + typedef typename _ITraits::value_type _ItValueType; + static_assert((is_same<_ItValueType, __container_value_type>::value || + is_same<_ItValueType, __node_value_type>::value), + "__assign_multi may only be called with the containers value type" + " or the nodes value type"); + if (bucket_count() != 0) + { + __next_pointer __cache = __detach(); +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + try + { +#endif // _LIBCUDACXX_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__upcast()->__value_ = *__first; + __next_pointer __next = __cache->__next_; + __node_insert_multi(__cache->__upcast()); + __cache = __next; + } +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + } + catch (...) + { + __deallocate_node(__cache); + throw; + } +#endif // _LIBCUDACXX_NO_EXCEPTIONS + __deallocate_node(__cache); + } + for (; __first != __last; ++__first) + __insert_multi(_NodeTypes::__get_value(*__first)); +} + +template +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator(__p1_.first().__next_, this); +#else + return iterator(__p1_.first().__next_); +#endif +} + +template +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator(nullptr, this); +#else + return iterator(nullptr); +#endif +} + +template +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return const_iterator(__p1_.first().__next_, this); +#else + return const_iterator(__p1_.first().__next_); +#endif +} + +template +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return const_iterator(nullptr, this); +#else + return const_iterator(nullptr); +#endif +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT +{ + if (size() > 0) + { + __deallocate_node(__p1_.first().__next_); + __p1_.first().__next_ = nullptr; + size_type __bc = bucket_count(); + for (size_type __i = 0; __i < __bc; ++__i) + __bucket_list_[__i] = nullptr; + size() = 0; + } +} + + +// Prepare the container for an insertion of the value __value with the hash +// __hash. This does a lookup into the container to see if __value is already +// present, and performs a rehash if necessary. Returns a pointer to the +// existing element if it exists, otherwise nullptr. +// +// Note that this function does forward exceptions if key_eq() throws, and never +// mutates __value or actually inserts into the map. +template +_LIBCUDACXX_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare( + size_t __hash, value_type& __value) +{ + size_type __bc = bucket_count(); + + if (__bc != 0) + { + size_t __chash = __constrain_hash(__hash, __bc); + __next_pointer __ndptr = __bucket_list_[__chash]; + if (__ndptr != nullptr) + { + for (__ndptr = __ndptr->__next_; __ndptr != nullptr && + __constrain_hash(__ndptr->__hash(), __bc) == __chash; + __ndptr = __ndptr->__next_) + { + if (key_eq()(__ndptr->__upcast()->__value_, __value)) + return __ndptr; + } + } + } + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_CUDA_VSTD::max(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + } + return nullptr; +} + +// Insert the node __nd into the container by pushing it into the right bucket, +// and updating size(). Assumes that __nd->__hash is up-to-date, and that +// rehashing has already occurred and that no element with the same key exists +// in the map. +template +_LIBCUDACXX_INLINE_VISIBILITY +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform( + __node_pointer __nd) _NOEXCEPT +{ + size_type __bc = bucket_count(); + size_t __chash = __constrain_hash(__nd->__hash(), __bc); + // insert_after __bucket_list_[__chash], or __first_node if bucket is null + __next_pointer __pn = __bucket_list_[__chash]; + if (__pn == nullptr) + { + __pn =__p1_.first().__ptr(); + __nd->__next_ = __pn->__next_; + __pn->__next_ = __nd->__ptr(); + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__nd->__next_ != nullptr) + __bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr(); + } + else + { + __nd->__next_ = __pn->__next_; + __pn->__next_ = __nd->__ptr(); + } + ++size(); +} + +template +pair::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd) +{ + __nd->__hash_ = hash_function()(__nd->__value_); + __next_pointer __existing_node = + __node_insert_unique_prepare(__nd->__hash(), __nd->__value_); + + // Insert the node, unless it already exists in the container. + bool __inserted = false; + if (__existing_node == nullptr) + { + __node_insert_unique_perform(__nd); + __existing_node = __nd->__ptr(); + __inserted = true; + } +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return pair(iterator(__existing_node, this), __inserted); +#else + return pair(iterator(__existing_node), __inserted); +#endif +} + +// Prepare the container for an insertion of the value __cp_val with the hash +// __cp_hash. This does a lookup into the container to see if __cp_value is +// already present, and performs a rehash if necessary. Returns a pointer to the +// last occurance of __cp_val in the map. +// +// Note that this function does forward exceptions if key_eq() throws, and never +// mutates __value or actually inserts into the map. +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare( + size_t __cp_hash, value_type& __cp_val) +{ + size_type __bc = bucket_count(); + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_CUDA_VSTD::max(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + } + size_t __chash = __constrain_hash(__cp_hash, __bc); + __next_pointer __pn = __bucket_list_[__chash]; + if (__pn != nullptr) + { + for (bool __found = false; __pn->__next_ != nullptr && + __constrain_hash(__pn->__next_->__hash(), __bc) == __chash; + __pn = __pn->__next_) + { + // __found key_eq() action + // false false loop + // true true loop + // false true set __found to true + // true false break + if (__found != (__pn->__next_->__hash() == __cp_hash && + key_eq()(__pn->__next_->__upcast()->__value_, __cp_val))) + { + if (!__found) + __found = true; + else + break; + } + } + } + return __pn; +} + +// Insert the node __cp into the container after __pn (which is the last node in +// the bucket that compares equal to __cp). Rehashing, and checking for +// uniqueness has already been performed (in __node_insert_multi_prepare), so +// all we need to do is update the bucket and size(). Assumes that __cp->__hash +// is up-to-date. +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform( + __node_pointer __cp, __next_pointer __pn) _NOEXCEPT +{ + size_type __bc = bucket_count(); + size_t __chash = __constrain_hash(__cp->__hash_, __bc); + if (__pn == nullptr) + { + __pn =__p1_.first().__ptr(); + __cp->__next_ = __pn->__next_; + __pn->__next_ = __cp->__ptr(); + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__cp->__next_ != nullptr) + __bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)] + = __cp->__ptr(); + } + else + { + __cp->__next_ = __pn->__next_; + __pn->__next_ = __cp->__ptr(); + if (__cp->__next_ != nullptr) + { + size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc); + if (__nhash != __chash) + __bucket_list_[__nhash] = __cp->__ptr(); + } + } + ++size(); +} + + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp) +{ + __cp->__hash_ = hash_function()(__cp->__value_); + __next_pointer __pn = __node_insert_multi_prepare(__cp->__hash(), __cp->__value_); + __node_insert_multi_perform(__cp, __pn); + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator(__cp->__ptr(), this); +#else + return iterator(__cp->__ptr()); +#endif +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( + const_iterator __p, __node_pointer __cp) +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered container"); +#endif + if (__p != end() && key_eq()(*__p, __cp->__value_)) + { + __next_pointer __np = __p.__node_; + __cp->__hash_ = __np->__hash(); + size_type __bc = bucket_count(); + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_CUDA_VSTD::max(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + } + size_t __chash = __constrain_hash(__cp->__hash_, __bc); + __next_pointer __pp = __bucket_list_[__chash]; + while (__pp->__next_ != __np) + __pp = __pp->__next_; + __cp->__next_ = __np; + __pp->__next_ = static_cast<__next_pointer>(__cp); + ++size(); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator(static_cast<__next_pointer>(__cp), this); +#else + return iterator(static_cast<__next_pointer>(__cp)); +#endif + } + return __node_insert_multi(__cp); +} + + + +#ifndef _LIBCUDACXX_CXX03_LANG +template +template +pair::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) +#else +template +template +pair::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args) +#endif +{ + + size_t __hash = hash_function()(__k); + size_type __bc = bucket_count(); + bool __inserted = false; + __next_pointer __nd; + size_t __chash; + if (__bc != 0) + { + __chash = __constrain_hash(__hash, __bc); + __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash); + __nd = __nd->__next_) + { + if (key_eq()(__nd->__upcast()->__value_, __k)) + goto __done; + } + } + } + { +#ifndef _LIBCUDACXX_CXX03_LANG + __node_holder __h = __construct_node_hash(__hash, _CUDA_VSTD::forward<_Args>(__args)...); +#else + __node_holder __h = __construct_node_hash(__hash, __args); +#endif + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_CUDA_VSTD::max(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + __chash = __constrain_hash(__hash, __bc); + } + // insert_after __bucket_list_[__chash], or __first_node if bucket is null + __next_pointer __pn = __bucket_list_[__chash]; + if (__pn == nullptr) + { + __pn = __p1_.first().__ptr(); + __h->__next_ = __pn->__next_; + __pn->__next_ = __h.get()->__ptr(); + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__h->__next_ != nullptr) + __bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)] + = __h.get()->__ptr(); + } + else + { + __h->__next_ = __pn->__next_; + __pn->__next_ = static_cast<__next_pointer>(__h.get()); + } + __nd = static_cast<__next_pointer>(__h.release()); + // increment size + ++size(); + __inserted = true; + } +__done: +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return pair(iterator(__nd, this), __inserted); +#else + return pair(iterator(__nd), __inserted); +#endif +} + +#ifndef _LIBCUDACXX_CXX03_LANG + +template +template +pair::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args) +{ + __node_holder __h = __construct_node(_CUDA_VSTD::forward<_Args>(__args)...); + pair __r = __node_insert_unique(__h.get()); + if (__r.second) + __h.release(); + return __r; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args) +{ + __node_holder __h = __construct_node(_CUDA_VSTD::forward<_Args>(__args)...); + iterator __r = __node_insert_multi(__h.get()); + __h.release(); + return __r; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi( + const_iterator __p, _Args&&... __args) +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered container"); +#endif + __node_holder __h = __construct_node(_CUDA_VSTD::forward<_Args>(__args)...); + iterator __r = __node_insert_multi(__p, __h.get()); + __h.release(); + return __r; +} + +#else // _LIBCUDACXX_CXX03_LANG + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x) +{ + __node_holder __h = __construct_node(__x); + iterator __r = __node_insert_multi(__h.get()); + __h.release(); + return __r; +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p, + const __container_value_type& __x) +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::insert(const_iterator, lvalue) called with an iterator not" + " referring to this unordered container"); +#endif + __node_holder __h = __construct_node(__x); + iterator __r = __node_insert_multi(__p, __h.get()); + __h.release(); + return __r; +} + +#endif // _LIBCUDACXX_CXX03_LANG + +#if _LIBCUDACXX_STD_VER > 14 +template +template +_LIBCUDACXX_INLINE_VISIBILITY +_InsertReturnType +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique( + _NodeHandle&& __nh) +{ + if (__nh.empty()) + return _InsertReturnType{end(), false, _NodeHandle()}; + pair __result = __node_insert_unique(__nh.__ptr_); + if (__result.second) + __nh.__release_ptr(); + return _InsertReturnType{__result.first, __result.second, _CUDA_VSTD::move(__nh)}; +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique( + const_iterator, _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + pair __result = __node_insert_unique(__nh.__ptr_); + if (__result.second) + __nh.__release_ptr(); + return __result.first; +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +_NodeHandle +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract( + key_type const& __key) +{ + iterator __i = find(__key); + if (__i == end()) + return _NodeHandle(); + return __node_handle_extract<_NodeHandle>(__i); +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +_NodeHandle +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract( + const_iterator __p) +{ + allocator_type __alloc(__node_alloc()); + return _NodeHandle(remove(__p).release(), __alloc); +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_unique( + _Table& __source) +{ + static_assert(is_same<__node, typename _Table::__node>::value, ""); + + for (typename _Table::iterator __it = __source.begin(); + __it != __source.end();) + { + __node_pointer __src_ptr = __it.__node_->__upcast(); + size_t __hash = hash_function()(__src_ptr->__value_); + __next_pointer __existing_node = + __node_insert_unique_prepare(__hash, __src_ptr->__value_); + auto __prev_iter = __it++; + if (__existing_node == nullptr) + { + (void)__source.remove(__prev_iter).release(); + __src_ptr->__hash_ = __hash; + __node_insert_unique_perform(__src_ptr); + } + } +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi( + _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + iterator __result = __node_insert_multi(__nh.__ptr_); + __nh.__release_ptr(); + return __result; +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi( + const_iterator __hint, _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + iterator __result = __node_insert_multi(__hint, __nh.__ptr_); + __nh.__release_ptr(); + return __result; +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_multi( + _Table& __source) +{ + static_assert(is_same::value, ""); + + for (typename _Table::iterator __it = __source.begin(); + __it != __source.end();) + { + __node_pointer __src_ptr = __it.__node_->__upcast(); + size_t __src_hash = hash_function()(__src_ptr->__value_); + __next_pointer __pn = + __node_insert_multi_prepare(__src_hash, __src_ptr->__value_); + (void)__source.remove(__it++).release(); + __src_ptr->__hash_ = __src_hash; + __node_insert_multi_perform(__src_ptr, __pn); + } +} +#endif // _LIBCUDACXX_STD_VER > 14 + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n) +_LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +{ + if (__n == 1) + __n = 2; + else if (__n & (__n - 1)) + __n = __next_prime(__n); + size_type __bc = bucket_count(); + if (__n > __bc) + __rehash(__n); + else if (__n < __bc) + { + __n = _CUDA_VSTD::max + ( + __n, + __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) : + __next_prime(size_t(ceil(float(size()) / max_load_factor()))) + ); + if (__n < __bc) + __rehash(__n); + } +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc) +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __get_db()->__invalidate_all(this); +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc(); + __bucket_list_.reset(__nbc > 0 ? + __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr); + __bucket_list_.get_deleter().size() = __nbc; + if (__nbc > 0) + { + for (size_type __i = 0; __i < __nbc; ++__i) + __bucket_list_[__i] = nullptr; + __next_pointer __pp = __p1_.first().__ptr(); + __next_pointer __cp = __pp->__next_; + if (__cp != nullptr) + { + size_type __chash = __constrain_hash(__cp->__hash(), __nbc); + __bucket_list_[__chash] = __pp; + size_type __phash = __chash; + for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr; + __cp = __pp->__next_) + { + __chash = __constrain_hash(__cp->__hash(), __nbc); + if (__chash == __phash) + __pp = __cp; + else + { + if (__bucket_list_[__chash] == nullptr) + { + __bucket_list_[__chash] = __pp; + __pp = __cp; + __phash = __chash; + } + else + { + __next_pointer __np = __cp; + for (; __np->__next_ != nullptr && + key_eq()(__cp->__upcast()->__value_, + __np->__next_->__upcast()->__value_); + __np = __np->__next_) + ; + __pp->__next_ = __np->__next_; + __np->__next_ = __bucket_list_[__chash]->__next_; + __bucket_list_[__chash]->__next_ = __cp; + + } + } + } + } + } +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) +{ + size_t __hash = hash_function()(__k); + size_type __bc = bucket_count(); + if (__bc != 0) + { + size_t __chash = __constrain_hash(__hash, __bc); + __next_pointer __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + (__nd->__hash() == __hash + || __constrain_hash(__nd->__hash(), __bc) == __chash); + __nd = __nd->__next_) + { + if ((__nd->__hash() == __hash) + && key_eq()(__nd->__upcast()->__value_, __k)) +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator(__nd, this); +#else + return iterator(__nd); +#endif + } + } + } + return end(); +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const +{ + size_t __hash = hash_function()(__k); + size_type __bc = bucket_count(); + if (__bc != 0) + { + size_t __chash = __constrain_hash(__hash, __bc); + __next_pointer __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + (__hash == __nd->__hash() + || __constrain_hash(__nd->__hash(), __bc) == __chash); + __nd = __nd->__next_) + { + if ((__nd->__hash() == __hash) + && key_eq()(__nd->__upcast()->__value_, __k)) +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return const_iterator(__nd, this); +#else + return const_iterator(__nd); +#endif + } + } + + } + return end(); +} + +#ifndef _LIBCUDACXX_CXX03_LANG + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args) +{ + static_assert(!__is_hash_value_type<_Args...>::value, + "Construct cannot be called with a hash value type"); + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _CUDA_VSTD::forward<_Args>(__args)...); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = hash_function()(__h->__value_); + __h->__next_ = nullptr; + return __h; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash( + size_t __hash, _First&& __f, _Rest&& ...__rest) +{ + static_assert(!__is_hash_value_type<_First, _Rest...>::value, + "Construct cannot be called with a hash value type"); + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), + _CUDA_VSTD::forward<_First>(__f), + _CUDA_VSTD::forward<_Rest>(__rest)...); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = __hash; + __h->__next_ = nullptr; + return __h; +} + +#else // _LIBCUDACXX_CXX03_LANG + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v) +{ + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = hash_function()(__h->__value_); + __h->__next_ = nullptr; + return _LIBCUDACXX_EXPLICIT_MOVE(__h); // explicitly moved for C++03 +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash, + const __container_value_type& __v) +{ + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = __hash; + __h->__next_ = nullptr; + return _LIBCUDACXX_EXPLICIT_MOVE(__h); // explicitly moved for C++03 +} + +#endif // _LIBCUDACXX_CXX03_LANG + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p) +{ + __next_pointer __np = __p.__node_; +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container erase(iterator) called with an iterator not" + " referring to this container"); + _LIBCUDACXX_ASSERT(__p != end(), + "unordered container erase(iterator) called with a non-dereferenceable iterator"); + iterator __r(__np, this); +#else + iterator __r(__np); +#endif + ++__r; + remove(__p); + return __r; +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, + const_iterator __last) +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, + "unodered container::erase(iterator, iterator) called with an iterator not" + " referring to this unodered container"); + _LIBCUDACXX_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, + "unodered container::erase(iterator, iterator) called with an iterator not" + " referring to this unodered container"); +#endif + for (const_iterator __p = __first; __first != __last; __p = __first) + { + ++__first; + erase(__p); + } + __next_pointer __np = __last.__node_; +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator (__np, this); +#else + return iterator (__np); +#endif +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k) +{ + iterator __i = find(__k); + if (__i == end()) + return 0; + erase(__i); + return 1; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k) +{ + size_type __r = 0; + iterator __i = find(__k); + if (__i != end()) + { + iterator __e = end(); + do + { + erase(__i++); + ++__r; + } while (__i != __e && key_eq()(*__i, __k)); + } + return __r; +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT +{ + // current node + __next_pointer __cn = __p.__node_; + size_type __bc = bucket_count(); + size_t __chash = __constrain_hash(__cn->__hash(), __bc); + // find previous node + __next_pointer __pn = __bucket_list_[__chash]; + for (; __pn->__next_ != __cn; __pn = __pn->__next_) + ; + // Fix up __bucket_list_ + // if __pn is not in same bucket (before begin is not in same bucket) && + // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) + if (__pn == __p1_.first().__ptr() + || __constrain_hash(__pn->__hash(), __bc) != __chash) + { + if (__cn->__next_ == nullptr + || __constrain_hash(__cn->__next_->__hash(), __bc) != __chash) + __bucket_list_[__chash] = nullptr; + } + // if __cn->__next_ is not in same bucket (nullptr is in same bucket) + if (__cn->__next_ != nullptr) + { + size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc); + if (__nhash != __chash) + __bucket_list_[__nhash] = __pn; + } + // remove __cn + __pn->__next_ = __cn->__next_; + __cn->__next_ = nullptr; + --size(); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __dp = __c->end_; __dp != __c->beg_; ) + { + --__dp; + iterator* __i = static_cast((*__dp)->__i_); + if (__i->__node_ == __cn) + { + (*__dp)->__c_ = nullptr; + if (--__c->end_ != __dp) + memmove(__dp, __dp+1, (__c->end_ - __dp)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true)); +} + +template +template +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const +{ + return static_cast(find(__k) != end()); +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const +{ + size_type __r = 0; + const_iterator __i = find(__k); + if (__i != end()) + { + const_iterator __e = end(); + do + { + ++__i; + ++__r; + } while (__i != __e && key_eq()(*__i, __k)); + } + return __r; +} + +template +template +pair::iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( + const _Key& __k) +{ + iterator __i = find(__k); + iterator __j = __i; + if (__i != end()) + ++__j; + return pair(__i, __j); +} + +template +template +pair::const_iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( + const _Key& __k) const +{ + const_iterator __i = find(__k); + const_iterator __j = __i; + if (__i != end()) + ++__j; + return pair(__i, __j); +} + +template +template +pair::iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( + const _Key& __k) +{ + iterator __i = find(__k); + iterator __j = __i; + if (__i != end()) + { + iterator __e = end(); + do + { + ++__j; + } while (__j != __e && key_eq()(*__j, __k)); + } + return pair(__i, __j); +} + +template +template +pair::const_iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( + const _Key& __k) const +{ + const_iterator __i = find(__k); + const_iterator __j = __i; + if (__i != end()) + { + const_iterator __e = end(); + do + { + ++__j; + } while (__j != __e && key_eq()(*__j, __k)); + } + return pair(__i, __j); +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) +#if _LIBCUDACXX_STD_VER <= 11 + _NOEXCEPT_( + __is_nothrow_swappable::value && __is_nothrow_swappable::value + && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value + || __is_nothrow_swappable<__pointer_allocator>::value) + && (!__node_traits::propagate_on_container_swap::value + || __is_nothrow_swappable<__node_allocator>::value) + ) +#else + _NOEXCEPT_(__is_nothrow_swappable::value && __is_nothrow_swappable::value) +#endif +{ + _LIBCUDACXX_ASSERT(__node_traits::propagate_on_container_swap::value || + this->__node_alloc() == __u.__node_alloc(), + "list::swap: Either propagate_on_container_swap must be true" + " or the allocators must compare equal"); + { + __node_pointer_pointer __npp = __bucket_list_.release(); + __bucket_list_.reset(__u.__bucket_list_.release()); + __u.__bucket_list_.reset(__npp); + } + _CUDA_VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size()); + __swap_allocator(__bucket_list_.get_deleter().__alloc(), + __u.__bucket_list_.get_deleter().__alloc()); + __swap_allocator(__node_alloc(), __u.__node_alloc()); + _CUDA_VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_); + __p2_.swap(__u.__p2_); + __p3_.swap(__u.__p3_); + if (size() > 0) + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + if (__u.size() > 0) + __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = + __u.__p1_.first().__ptr(); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __get_db()->swap(this, &__u); +#endif +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const +{ + _LIBCUDACXX_ASSERT(__n < bucket_count(), + "unordered container::bucket_size(n) called with n >= bucket_count()"); + __next_pointer __np = __bucket_list_[__n]; + size_type __bc = bucket_count(); + size_type __r = 0; + if (__np != nullptr) + { + for (__np = __np->__next_; __np != nullptr && + __constrain_hash(__np->__hash(), __bc) == __n; + __np = __np->__next_, ++__r) + ; + } + return __r; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x, + __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + +template +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const +{ + return __i->__node_ != nullptr; +} + +template +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const +{ + return false; +} + +template +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const +{ + return false; +} + +template +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const +{ + return false; +} + +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + +_LIBCUDACXX_END_NAMESPACE_STD + +_LIBCUDACXX_POP_MACROS + +#endif // _LIBCUDACXX__HASH_TABLE diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/access.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/access.h new file mode 100644 index 0000000000000000000000000000000000000000..dec5ef35be23e195f4d9dd257adc4d8313de5c4a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/access.h @@ -0,0 +1,133 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_ACCESS_H +#define _LIBCUDACXX___ITERATOR_ACCESS_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +_Tp* +begin(_Tp (&__array)[_Np]) +{ + return __array; +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +_Tp* +end(_Tp (&__array)[_Np]) +{ + return __array + _Np; +} + +#if !defined(_LIBCUDACXX_CXX03_LANG) + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto +begin(_Cp& __c) -> decltype(__c.begin()) +{ + return __c.begin(); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto +begin(const _Cp& __c) -> decltype(__c.begin()) +{ + return __c.begin(); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto +end(_Cp& __c) -> decltype(__c.end()) +{ + return __c.end(); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto +end(const _Cp& __c) -> decltype(__c.end()) +{ + return __c.end(); +} + +#if _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +auto cbegin(const _Cp& __c) -> decltype(_CUDA_VSTD::begin(__c)) +{ + return _CUDA_VSTD::begin(__c); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +auto cend(const _Cp& __c) -> decltype(_CUDA_VSTD::end(__c)) +{ + return _CUDA_VSTD::end(__c); +} + +#endif + + +#else // defined(_LIBCUDACXX_CXX03_LANG) + +template +_LIBCUDACXX_INLINE_VISIBILITY +typename _Cp::iterator +begin(_Cp& __c) +{ + return __c.begin(); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +typename _Cp::const_iterator +begin(const _Cp& __c) +{ + return __c.begin(); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +typename _Cp::iterator +end(_Cp& __c) +{ + return __c.end(); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +typename _Cp::const_iterator +end(const _Cp& __c) +{ + return __c.end(); +} + +#endif // !defined(_LIBCUDACXX_CXX03_LANG) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_ACCESS_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/advance.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/advance.h new file mode 100644 index 0000000000000000000000000000000000000000..e8e52742cb097d5fc5c8cc0a9c2b9fa7f531884a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/advance.h @@ -0,0 +1,70 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_ADVANCE_H +#define _LIBCUDACXX___ITERATOR_ADVANCE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__assert" +#include "../__iterator/iterator_traits.h" +#include "../cstdlib" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +void __advance(_InputIter& __i, + typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) +{ + for (; __n > 0; --__n) + ++__i; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +void __advance(_BiDirIter& __i, + typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) +{ + if (__n >= 0) + for (; __n > 0; --__n) + ++__i; + else + for (; __n < 0; ++__n) + --__i; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +void __advance(_RandIter& __i, + typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) +{ + __i += __n; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +void advance(_InputIter& __i, + typename iterator_traits<_InputIter>::difference_type __n) +{ + _LIBCUDACXX_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, + "Attempt to advance(it, -n) on a non-bidi iterator"); + __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_ADVANCE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/back_insert_iterator.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/back_insert_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..d367450c82ef2b2432eedbc47997489033dbe92a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/back_insert_iterator.h @@ -0,0 +1,69 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_BACK_INSERT_ITERATOR_H +#define _LIBCUDACXX___ITERATOR_BACK_INSERT_ITERATOR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/iterator.h" +#include "../__iterator/iterator_traits.h" +#include "../__memory/addressof.h" +#include "../__utility/move.h" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +_LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH +template +class _LIBCUDACXX_TEMPLATE_VIS back_insert_iterator +#if _LIBCUDACXX_STD_VER <= 14 || !defined(_LIBCUDACXX_ABI_NO_ITERATOR_BASES) + : public iterator +#endif +{ +_LIBCUDACXX_SUPPRESS_DEPRECATED_POP +protected: + _Container* container; +public: + typedef _Container container_type; + + _LIBCUDACXX_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_CUDA_VSTD::addressof(__x)) {} + _LIBCUDACXX_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_) + {container->push_back(__value_); return *this;} +#ifndef _LIBCUDACXX_CXX03_LANG + _LIBCUDACXX_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_) + {container->push_back(_CUDA_VSTD::move(__value_)); return *this;} +#endif // _LIBCUDACXX_CXX03_LANG + _LIBCUDACXX_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;} + _LIBCUDACXX_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;} + _LIBCUDACXX_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;} +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +back_insert_iterator<_Container> +back_inserter(_Container& __x) +{ + return back_insert_iterator<_Container>(__x); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_BACK_INSERT_ITERATOR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/concepts.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/concepts.h new file mode 100644 index 0000000000000000000000000000000000000000..44643feb8387ec06ac1aea2e4c9c0de87fcdc322 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/concepts.h @@ -0,0 +1,717 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_CONCEPTS_H +#define _LIBCUDACXX___ITERATOR_CONCEPTS_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/arithmetic.h" +#include "../__concepts/assignable.h" +#include "../__concepts/common_reference_with.h" +#include "../__concepts/constructible.h" +#include "../__concepts/copyable.h" +#include "../__concepts/derived_from.h" +#include "../__concepts/equality_comparable.h" +#include "../__concepts/invocable.h" +#include "../__concepts/movable.h" +#include "../__concepts/predicate.h" +#include "../__concepts/regular.h" +#include "../__concepts/relation.h" +#include "../__concepts/same_as.h" +#include "../__concepts/semiregular.h" +#include "../__concepts/totally_ordered.h" +#include "../__functional/invoke.h" +#include "../__iterator/incrementable_traits.h" +#include "../__iterator/iter_move.h" +#include "../__iterator/iterator_traits.h" +#include "../__iterator/readable_traits.h" +#include "../__memory/pointer_traits.h" +#include "../__utility/forward.h" +#include "../__type_traits/add_pointer.h" +#include "../__type_traits/common_reference.h" +#include "../__type_traits/conjunction.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/remove_cv.h" +#include "../__type_traits/remove_cvref.h" +#include "../__type_traits/void_t.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [iterator.concept.readable] +template +concept __indirectly_readable_impl = + requires(const _In __i) { + typename iter_value_t<_In>; + typename iter_reference_t<_In>; + typename iter_rvalue_reference_t<_In>; + { *__i } -> same_as>; + { _CUDA_VRANGES::iter_move(__i) } -> same_as>; + } && + common_reference_with&&, iter_value_t<_In>&> && + common_reference_with&&, iter_rvalue_reference_t<_In>&&> && + common_reference_with&&, const iter_value_t<_In>&>; + +template +concept indirectly_readable = __indirectly_readable_impl>; + +template +using iter_common_reference_t = common_reference_t, iter_value_t<_Tp>&>; + +// [iterator.concept.writable] +template +concept indirectly_writable = + requires(_Out&& __o, _Tp&& __t) { + *__o = _CUDA_VSTD::forward<_Tp>(__t); // not required to be equality-preserving + *_CUDA_VSTD::forward<_Out>(__o) = _CUDA_VSTD::forward<_Tp>(__t); // not required to be equality-preserving + const_cast&&>(*__o) = _CUDA_VSTD::forward<_Tp>(__t); // not required to be equality-preserving + const_cast&&>(*_CUDA_VSTD::forward<_Out>(__o)) = _CUDA_VSTD::forward<_Tp>(__t); // not required to be equality-preserving + }; + +// [iterator.concept.winc] +template +concept __integer_like = integral<_Tp> && !same_as<_Tp, bool>; + +template +concept __signed_integer_like = signed_integral<_Tp>; + +template +concept weakly_incrementable = + // TODO: remove this once the clang bug is fixed (bugs.llvm.org/PR48173). + !same_as<_Ip, bool> && // Currently, clang does not handle bool correctly. + movable<_Ip> && + requires(_Ip __i) { + typename iter_difference_t<_Ip>; + requires __signed_integer_like>; + { ++__i } -> same_as<_Ip&>; // not required to be equality-preserving + __i++; // not required to be equality-preserving + }; + +// [iterator.concept.inc] +template +concept incrementable = + regular<_Ip> && + weakly_incrementable<_Ip> && + requires(_Ip __i) { + { __i++ } -> same_as<_Ip>; + }; + +// [iterator.concept.iterator] +template +concept input_or_output_iterator = + requires(_Ip __i) { + { *__i } -> __can_reference; + } && + weakly_incrementable<_Ip>; + +// [iterator.concept.sentinel] +template +concept sentinel_for = + semiregular<_Sp> && + input_or_output_iterator<_Ip> && + __weakly_equality_comparable_with<_Sp, _Ip>; + +template +inline constexpr bool disable_sized_sentinel_for = false; + +template +concept sized_sentinel_for = + sentinel_for<_Sp, _Ip> && + !disable_sized_sentinel_for, remove_cv_t<_Ip>> && + requires(const _Ip& __i, const _Sp& __s) { + { __s - __i } -> same_as>; + { __i - __s } -> same_as>; + }; + +// [iterator.concept.input] +template +concept input_iterator = + input_or_output_iterator<_Ip> && + indirectly_readable<_Ip> && + requires { typename _ITER_CONCEPT<_Ip>; } && + derived_from<_ITER_CONCEPT<_Ip>, input_iterator_tag>; + +// [iterator.concept.output] +template +concept output_iterator = + input_or_output_iterator<_Ip> && + indirectly_writable<_Ip, _Tp> && + requires (_Ip __it, _Tp&& __t) { + *__it++ = _CUDA_VSTD::forward<_Tp>(__t); // not required to be equality-preserving + }; + +// [iterator.concept.forward] +template +concept forward_iterator = + input_iterator<_Ip> && + derived_from<_ITER_CONCEPT<_Ip>, forward_iterator_tag> && + incrementable<_Ip> && + sentinel_for<_Ip, _Ip>; + +// [iterator.concept.bidir] +template +concept bidirectional_iterator = + forward_iterator<_Ip> && + derived_from<_ITER_CONCEPT<_Ip>, bidirectional_iterator_tag> && + requires(_Ip __i) { + { --__i } -> same_as<_Ip&>; + { __i-- } -> same_as<_Ip>; + }; + +template +concept random_access_iterator = + bidirectional_iterator<_Ip> && + derived_from<_ITER_CONCEPT<_Ip>, random_access_iterator_tag> && + totally_ordered<_Ip> && + sized_sentinel_for<_Ip, _Ip> && + requires(_Ip __i, const _Ip __j, const iter_difference_t<_Ip> __n) { + { __i += __n } -> same_as<_Ip&>; + { __j + __n } -> same_as<_Ip>; + { __n + __j } -> same_as<_Ip>; + { __i -= __n } -> same_as<_Ip&>; + { __j - __n } -> same_as<_Ip>; + { __j[__n] } -> same_as>; + }; + +template +concept contiguous_iterator = + random_access_iterator<_Ip> && + derived_from<_ITER_CONCEPT<_Ip>, contiguous_iterator_tag> && + is_lvalue_reference_v> && + same_as, remove_cvref_t>> && + requires(const _Ip& __i) { + { _CUDA_VSTD::to_address(__i) } -> same_as>>; + }; + +template +concept __has_arrow = input_iterator<_Ip> && (is_pointer_v<_Ip> || requires(_Ip __i) { __i.operator->(); }); + +template +concept __has_const_arrow = (is_pointer_v<_Ip> || requires(const _Ip __i) { __i.operator->(); }); + +// [indirectcallable.indirectinvocable] +template +concept indirectly_unary_invocable = + indirectly_readable<_It> && + copy_constructible<_Fp> && + invocable<_Fp&, iter_value_t<_It>&> && + invocable<_Fp&, iter_reference_t<_It>> && + invocable<_Fp&, iter_common_reference_t<_It>> && + common_reference_with< + invoke_result_t<_Fp&, iter_value_t<_It>&>, + invoke_result_t<_Fp&, iter_reference_t<_It>>>; + +template +concept indirectly_regular_unary_invocable = + indirectly_readable<_It> && + copy_constructible<_Fp> && + regular_invocable<_Fp&, iter_value_t<_It>&> && + regular_invocable<_Fp&, iter_reference_t<_It>> && + regular_invocable<_Fp&, iter_common_reference_t<_It>> && + common_reference_with< + invoke_result_t<_Fp&, iter_value_t<_It>&>, + invoke_result_t<_Fp&, iter_reference_t<_It>>>; + +template +concept indirect_unary_predicate = + indirectly_readable<_It> && + copy_constructible<_Fp> && + predicate<_Fp&, iter_value_t<_It>&> && + predicate<_Fp&, iter_reference_t<_It>> && + predicate<_Fp&, iter_common_reference_t<_It>>; + +template +concept indirect_binary_predicate = + indirectly_readable<_It1> && indirectly_readable<_It2> && + copy_constructible<_Fp> && + predicate<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&> && + predicate<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>> && + predicate<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&> && + predicate<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>> && + predicate<_Fp&, iter_common_reference_t<_It1>, iter_common_reference_t<_It2>>; + +template +concept indirect_equivalence_relation = + indirectly_readable<_It1> && indirectly_readable<_It2> && + copy_constructible<_Fp> && + equivalence_relation<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&> && + equivalence_relation<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>> && + equivalence_relation<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&> && + equivalence_relation<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>> && + equivalence_relation<_Fp&, iter_common_reference_t<_It1>, iter_common_reference_t<_It2>>; + +template +concept indirect_strict_weak_order = + indirectly_readable<_It1> && indirectly_readable<_It2> && + copy_constructible<_Fp> && + strict_weak_order<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&> && + strict_weak_order<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>> && + strict_weak_order<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&> && + strict_weak_order<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>> && + strict_weak_order<_Fp&, iter_common_reference_t<_It1>, iter_common_reference_t<_It2>>; + +template + requires (indirectly_readable<_Its> && ...) && invocable<_Fp, iter_reference_t<_Its>...> +using indirect_result_t = invoke_result_t<_Fp, iter_reference_t<_Its>...>; + +template +concept indirectly_movable = + indirectly_readable<_In> && + indirectly_writable<_Out, iter_rvalue_reference_t<_In>>; + +template +concept indirectly_movable_storable = + indirectly_movable<_In, _Out> && + indirectly_writable<_Out, iter_value_t<_In>> && + movable> && + constructible_from, iter_rvalue_reference_t<_In>> && + assignable_from&, iter_rvalue_reference_t<_In>>; + +template +concept indirectly_copyable = + indirectly_readable<_In> && + indirectly_writable<_Out, iter_reference_t<_In>>; + +template +concept indirectly_copyable_storable = + indirectly_copyable<_In, _Out> && + indirectly_writable<_Out, iter_value_t<_In>&> && + indirectly_writable<_Out, const iter_value_t<_In>&> && + indirectly_writable<_Out, iter_value_t<_In>&&> && + indirectly_writable<_Out, const iter_value_t<_In>&&> && + copyable> && + constructible_from, iter_reference_t<_In>> && + assignable_from&, iter_reference_t<_In>>; + +// Note: indirectly_swappable is located in iter_swap.h to prevent a dependency cycle +// (both iter_swap and indirectly_swappable require indirectly_readable). + +#elif _LIBCUDACXX_STD_VER > 14 + +// [iterator.concept.readable] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirectly_readable_impl_, + requires(const _In __i)( + typename(iter_value_t<_In>), + typename(iter_reference_t<_In>), + typename(iter_rvalue_reference_t<_In>), + requires(same_as, decltype(*__i)>), + requires(same_as, decltype(_CUDA_VRANGES::iter_move(__i))>), + requires(common_reference_with&&, iter_value_t<_In>&>), + requires(common_reference_with&&, iter_rvalue_reference_t<_In>&&>), + requires(common_reference_with&&, const iter_value_t<_In>&>) + )); + +template +_LIBCUDACXX_CONCEPT indirectly_readable = _LIBCUDACXX_FRAGMENT(__indirectly_readable_impl_, remove_cvref_t<_In>); + +template +using iter_common_reference_t = enable_if_t, + common_reference_t, iter_value_t<_Tp>&>>; +// [iterator.concept.writable] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirectly_writable_, + requires(_Out&& __o, _Tp&& __t)( + typename(decltype(*__o = _CUDA_VSTD::forward<_Tp>(__t))), + typename(decltype(*_CUDA_VSTD::forward<_Out>(__o) = _CUDA_VSTD::forward<_Tp>(__t))), + typename(decltype(const_cast&&>(*__o) = _CUDA_VSTD::forward<_Tp>(__t))), + typename(decltype(const_cast&&>(*_CUDA_VSTD::forward<_Out>(__o)) = _CUDA_VSTD::forward<_Tp>(__t))) + )); + +template +_LIBCUDACXX_CONCEPT indirectly_writable = _LIBCUDACXX_FRAGMENT(__indirectly_writable_, _Out, _Tp); + +// [iterator.concept.winc] +template +_LIBCUDACXX_CONCEPT __integer_like = integral<_Tp> && !same_as<_Tp, bool>; + +template +_LIBCUDACXX_CONCEPT __signed_integer_like = signed_integral<_Tp>; + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __weakly_incrementable_, + requires(_Ip __i)( + typename(iter_difference_t<_Ip>), + requires(!same_as<_Ip, bool>), + requires(movable<_Ip>), + requires(__signed_integer_like>), + requires(same_as<_Ip&, decltype(++__i)>), + (__i++) + )); + +template +_LIBCUDACXX_CONCEPT weakly_incrementable = _LIBCUDACXX_FRAGMENT(__weakly_incrementable_, _Ip); + +// [iterator.concept.inc] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __incrementable_, + requires(_Ip __i)( + requires(regular<_Ip>), + requires(weakly_incrementable<_Ip>), + requires(same_as<_Ip, decltype(__i++)>) + )); + +template +_LIBCUDACXX_CONCEPT incrementable = _LIBCUDACXX_FRAGMENT(__incrementable_, _Ip); + +// [iterator.concept.iterator] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __input_or_output_iterator_, + requires(_Ip __i)( + requires(weakly_incrementable<_Ip>), + requires(__can_reference) + )); + +template +_LIBCUDACXX_CONCEPT input_or_output_iterator = _LIBCUDACXX_FRAGMENT(__input_or_output_iterator_, _Ip); + +// [iterator.concept.sentinel] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __sentinel_for_, + requires()( + requires(semiregular<_Sp>), + requires(input_or_output_iterator<_Ip>), + requires(__weakly_equality_comparable_with<_Sp, _Ip>) + )); + +template +_LIBCUDACXX_CONCEPT sentinel_for = _LIBCUDACXX_FRAGMENT(__sentinel_for_, _Sp, _Ip); + +template +inline constexpr bool disable_sized_sentinel_for = false; + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __sized_sentinel_for_, + requires(const _Ip& __i, const _Sp& __s)( + requires(sentinel_for<_Sp, _Ip>), + requires(!disable_sized_sentinel_for, remove_cv_t<_Ip>>), + requires(same_as, decltype(__s - __i)>), + requires(same_as, decltype(__i - __s)>) + )); + +template +_LIBCUDACXX_CONCEPT sized_sentinel_for = _LIBCUDACXX_FRAGMENT(__sized_sentinel_for_, _Sp, _Ip); + +// [iterator.concept.input] +// NOTE: The ordering here is load bearing. MSVC has issues with finding iterator_traits +// We can work around this by checking other constraints first +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __input_iterator_, + requires()( + requires(input_or_output_iterator<_Ip>), + requires(indirectly_readable<_Ip>), + typename(_ITER_CONCEPT<_Ip>), + requires(derived_from<_ITER_CONCEPT<_Ip>, input_iterator_tag>) + )); + +template +_LIBCUDACXX_CONCEPT input_iterator = _LIBCUDACXX_FRAGMENT(__input_iterator_, _Ip); + +// [iterator.concept.output] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __output_iterator_, + requires(_Ip __it, _Tp&& __t)( + requires(input_or_output_iterator<_Ip>), + requires(indirectly_writable<_Ip, _Tp>), + (*__it++ = _CUDA_VSTD::forward<_Tp>(__t)) + )); + +template +_LIBCUDACXX_CONCEPT output_iterator = _LIBCUDACXX_FRAGMENT(__output_iterator_, _Ip, _Tp); + +// [iterator.concept.forward] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __forward_iterator_, + requires()( + requires(input_iterator<_Ip>), + requires(derived_from<_ITER_CONCEPT<_Ip>, forward_iterator_tag>), + requires(incrementable<_Ip>), + requires(sentinel_for<_Ip, _Ip>) + )); + +template +_LIBCUDACXX_CONCEPT forward_iterator = _LIBCUDACXX_FRAGMENT(__forward_iterator_, _Ip); + +// [iterator.concept.bidir] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __bidirectional_iterator_, + requires(_Ip __i)( + requires(forward_iterator<_Ip>), + requires(derived_from<_ITER_CONCEPT<_Ip>, bidirectional_iterator_tag>), + requires(same_as<_Ip&, decltype(--__i)>), + requires(same_as<_Ip, decltype(__i--)>) + )); + +template +_LIBCUDACXX_CONCEPT bidirectional_iterator = _LIBCUDACXX_FRAGMENT(__bidirectional_iterator_, _Ip); + +// [iterator.concept.random.access] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __random_access_iterator_operations_, + requires(_Ip __i, const _Ip __j, const iter_difference_t<_Ip> __n)( + requires(same_as<_Ip&, decltype(__i += __n)>), + requires(same_as<_Ip, decltype(__j + __n)>), + requires(same_as<_Ip, decltype(__n + __j)>), + requires(same_as<_Ip&, decltype(__i -= __n)>), + requires(same_as<_Ip, decltype(__j - __n)>), + requires(same_as, decltype(__j[__n])>) + )); + +template +_LIBCUDACXX_CONCEPT __random_access_iterator_operations = _LIBCUDACXX_FRAGMENT(__random_access_iterator_operations_, _Ip); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __random_access_iterator_, + requires()( + requires(bidirectional_iterator<_Ip>), + requires(derived_from<_ITER_CONCEPT<_Ip>, random_access_iterator_tag>), + requires(totally_ordered<_Ip>), + requires(sized_sentinel_for<_Ip, _Ip>), + requires(__random_access_iterator_operations<_Ip>) + )); + +template +_LIBCUDACXX_CONCEPT random_access_iterator = _LIBCUDACXX_FRAGMENT(__random_access_iterator_, _Ip); + +// [iterator.concept.contiguous] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __contiguous_iterator_, + requires(const _Ip& __i)( + requires(random_access_iterator<_Ip>), + requires(derived_from<_ITER_CONCEPT<_Ip>, contiguous_iterator_tag>), + requires(is_lvalue_reference_v>), + requires(same_as, remove_cvref_t>>), + requires(same_as>, decltype(_CUDA_VSTD::to_address(__i))>) + )); + +template +_LIBCUDACXX_CONCEPT contiguous_iterator = _LIBCUDACXX_FRAGMENT(__contiguous_iterator_, _Ip); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __has_arrow_, + requires(_Ip __i)( + (__i.operator->()) + )); + +template +_LIBCUDACXX_CONCEPT __has_arrow = input_iterator<_Ip> + && (is_pointer_v<_Ip> || _LIBCUDACXX_FRAGMENT(__has_arrow_, _Ip)); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __has_const_arrow_, + requires(const _Ip __i)( + (__i.operator->()) + )); + +template +_LIBCUDACXX_CONCEPT __has_const_arrow = (is_pointer_v<_Ip> || _LIBCUDACXX_FRAGMENT(__has_const_arrow_, _Ip)); + +// [indirectcallable.indirectinvocable] +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirectly_unary_invocable, + requires()( + requires(indirectly_readable<_It>), + requires(copy_constructible<_Fp>), + requires(invocable<_Fp&, iter_value_t<_It>&>), + requires(invocable<_Fp&, iter_reference_t<_It>>), + requires(invocable<_Fp&, iter_common_reference_t<_It>>), + requires(common_reference_with&>, + invoke_result_t<_Fp&, iter_reference_t<_It>>>) + )); + +template +_LIBCUDACXX_CONCEPT indirectly_unary_invocable = _LIBCUDACXX_FRAGMENT(__indirectly_unary_invocable, _Fp, _It); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirectly_regular_unary_invocable_, + requires()( + requires(indirectly_readable<_It>), + requires(copy_constructible<_Fp>), + requires(regular_invocable<_Fp&, iter_value_t<_It>&>), + requires(regular_invocable<_Fp&, iter_reference_t<_It>>), + requires(regular_invocable<_Fp&, iter_common_reference_t<_It>>), + requires(common_reference_with&>, + invoke_result_t<_Fp&, iter_reference_t<_It>>>) + )); + +template +_LIBCUDACXX_CONCEPT indirectly_regular_unary_invocable = _LIBCUDACXX_FRAGMENT(__indirectly_regular_unary_invocable_, _Fp, _It); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirect_unary_predicate_, + requires()( + requires(indirectly_readable<_It>), + requires(copy_constructible<_Fp>), + requires(predicate<_Fp&, iter_value_t<_It>&>), + requires(predicate<_Fp&, iter_reference_t<_It>>), + requires(predicate<_Fp&, iter_common_reference_t<_It>>) + )); + +template +_LIBCUDACXX_CONCEPT indirect_unary_predicate = _LIBCUDACXX_FRAGMENT(__indirect_unary_predicate_, _Fp, _It); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirect_binary_predicate_, + requires()( + requires(indirectly_readable<_It1>), + requires(indirectly_readable<_It2>), + requires(copy_constructible<_Fp>), + requires(predicate<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&>), + requires(predicate<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>>), + requires(predicate<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&>), + requires(predicate<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>>), + requires(predicate<_Fp&, iter_common_reference_t<_It1>, iter_common_reference_t<_It2>>) + )); + +template +_LIBCUDACXX_CONCEPT indirect_binary_predicate = _LIBCUDACXX_FRAGMENT(__indirect_binary_predicate_, _Fp, _It1, _It2); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirect_equivalence_relation_, + requires()( + requires(indirectly_readable<_It1>), + requires(indirectly_readable<_It2>), + requires(copy_constructible<_Fp>), + requires(equivalence_relation<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&>), + requires(equivalence_relation<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>>), + requires(equivalence_relation<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&>), + requires(equivalence_relation<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>>), + requires(equivalence_relation<_Fp&, iter_common_reference_t<_It1>, iter_common_reference_t<_It2>>) + )); + +template +_LIBCUDACXX_CONCEPT indirect_equivalence_relation = _LIBCUDACXX_FRAGMENT(__indirect_equivalence_relation_, _Fp, _It1, _It2); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirect_strict_weak_order_, + requires()( + requires(indirectly_readable<_It1>), + requires(indirectly_readable<_It2>), + requires(copy_constructible<_Fp>), + requires(strict_weak_order<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&>), + requires(strict_weak_order<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>>), + requires(strict_weak_order<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&>), + requires(strict_weak_order<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>>), + requires(strict_weak_order<_Fp&, iter_common_reference_t<_It1>, iter_common_reference_t<_It2>>) + )); + +template +_LIBCUDACXX_CONCEPT indirect_strict_weak_order = _LIBCUDACXX_FRAGMENT(__indirect_strict_weak_order_, _Fp, _It1, _It2); + +#if _LIBCUDACXX_STD_VER > 14 +template +using indirect_result_t = enable_if_t<(indirectly_readable<_Its> && ...) && invocable<_Fp, iter_reference_t<_Its>...>, invoke_result_t<_Fp, iter_reference_t<_Its>...>>; +#else +template +using indirect_result_t = enable_if_t>...> + && invocable<_Fp, iter_reference_t<_Its>...>, + invoke_result_t<_Fp, iter_reference_t<_Its>...>>; +#endif // _LIBCUDACXX_STD_VER > 14 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirectly_movable_, + requires()( + requires(indirectly_readable<_In>), + requires(indirectly_writable<_Out, iter_rvalue_reference_t<_In>>) + )); + +template +_LIBCUDACXX_CONCEPT indirectly_movable = _LIBCUDACXX_FRAGMENT(__indirectly_movable_, _In, _Out); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirectly_movable_storable_, + requires()( + requires(indirectly_movable<_In, _Out>), + requires(indirectly_writable<_Out, iter_value_t<_In>>), + requires(movable>), + requires(constructible_from, iter_rvalue_reference_t<_In>>), + requires(assignable_from&, iter_rvalue_reference_t<_In>>) + )); + +template +_LIBCUDACXX_CONCEPT indirectly_movable_storable = _LIBCUDACXX_FRAGMENT(__indirectly_movable_storable_, _In, _Out); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirectly_copyable_, + requires()( + requires(indirectly_readable<_In>), + requires(indirectly_writable<_Out, iter_reference_t<_In>>) + )); + +template +_LIBCUDACXX_CONCEPT indirectly_copyable = _LIBCUDACXX_FRAGMENT(__indirectly_copyable_, _In, _Out); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirectly_copyable_storable_, + requires()( + requires(indirectly_copyable<_In, _Out>), + requires(indirectly_writable<_Out, iter_value_t<_In>&>), + requires(indirectly_writable<_Out, const iter_value_t<_In>&>), + requires(indirectly_writable<_Out, iter_value_t<_In>&&>), + requires(indirectly_writable<_Out, const iter_value_t<_In>&&>), + requires(copyable>), + requires(constructible_from, iter_reference_t<_In>>), + requires(assignable_from&, iter_reference_t<_In>>) + )); + +template +_LIBCUDACXX_CONCEPT indirectly_copyable_storable =_LIBCUDACXX_FRAGMENT(__indirectly_copyable_storable_, _In, _Out); + +template +inline constexpr bool __has_iter_category = false; + +template +inline constexpr bool __has_iter_category<_Ip, void_t> = true; + +template +inline constexpr bool __has_iter_concept = false; + +template +inline constexpr bool __has_iter_concept<_Ip, void_t> = true; + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_CONCEPTS_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/data.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/data.h new file mode 100644 index 0000000000000000000000000000000000000000..7439964f621f5fc0b6a135f00cdb93962c7e5885 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/data.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_DATA_H +#define _LIBCUDACXX___ITERATOR_DATA_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../cstddef" +#include "../initializer_list" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +template constexpr +_LIBCUDACXX_INLINE_VISIBILITY +auto data(_Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } + +template constexpr +_LIBCUDACXX_INLINE_VISIBILITY +auto data(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } + +template +_LIBCUDACXX_INLINE_VISIBILITY +constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } + +template +_LIBCUDACXX_INLINE_VISIBILITY +constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } + +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_DATA_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/default_sentinel.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/default_sentinel.h new file mode 100644 index 0000000000000000000000000000000000000000..0ee17a956c340fb799488861e088be300ce1881c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/default_sentinel.h @@ -0,0 +1,33 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_DEFAULT_SENTINEL_H +#define _LIBCUDACXX___ITERATOR_DEFAULT_SENTINEL_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +struct default_sentinel_t { }; +inline constexpr default_sentinel_t default_sentinel{}; + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_DEFAULT_SENTINEL_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/distance.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/distance.h new file mode 100644 index 0000000000000000000000000000000000000000..e0b0cad4a79234ab073afc8656167e9901ac7cc4 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/distance.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_DISTANCE_H +#define _LIBCUDACXX___ITERATOR_DISTANCE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/iterator_traits.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +typename iterator_traits<_InputIter>::difference_type +__distance(_InputIter __first, _InputIter __last, input_iterator_tag) +{ + typename iterator_traits<_InputIter>::difference_type __r(0); + for (; __first != __last; ++__first) + ++__r; + return __r; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +typename iterator_traits<_RandIter>::difference_type +__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) +{ + return __last - __first; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +typename iterator_traits<_InputIter>::difference_type +distance(_InputIter __first, _InputIter __last) +{ + return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); +} + + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_DISTANCE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/empty.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/empty.h new file mode 100644 index 0000000000000000000000000000000000000000..536a2d0ed3737cac4972bd177d0946805fe76ddf --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/empty.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_EMPTY_H +#define _LIBCUDACXX___ITERATOR_EMPTY_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../cstddef" +#include "../initializer_list" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_NODISCARD_AFTER_CXX17 _LIBCUDACXX_INLINE_VISIBILITY +constexpr auto empty(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.empty())) +-> decltype (__c.empty()) +{ return __c.empty(); } + +template +_LIBCUDACXX_NODISCARD_AFTER_CXX17 _LIBCUDACXX_INLINE_VISIBILITY +constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } + +template +_LIBCUDACXX_NODISCARD_AFTER_CXX17 _LIBCUDACXX_INLINE_VISIBILITY +constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } + +#endif // _LIBCUDACXX_STD_VER > 17 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_EMPTY_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/erase_if_container.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/erase_if_container.h new file mode 100644 index 0000000000000000000000000000000000000000..ec26718362cda05c0c37863fbfab51a88982a9c1 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/erase_if_container.h @@ -0,0 +1,43 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_ERASE_IF_CONTAINER_H +#define _LIBCUDACXX___ITERATOR_ERASE_IF_CONTAINER_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_INLINE_VISIBILITY +typename _Container::size_type +__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) { + typename _Container::size_type __old_size = __c.size(); + + const typename _Container::iterator __last = __c.end(); + for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) { + if (__pred(*__iter)) + __iter = __c.erase(__iter); + else + ++__iter; + } + + return __old_size - __c.size(); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_ERASE_IF_CONTAINER_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/front_insert_iterator.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/front_insert_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..a989a3bba794668a36f6cc799dc3d230ee6d4320 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/front_insert_iterator.h @@ -0,0 +1,69 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_FRONT_INSERT_ITERATOR_H +#define _LIBCUDACXX___ITERATOR_FRONT_INSERT_ITERATOR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/iterator.h" +#include "../__iterator/iterator_traits.h" +#include "../__memory/addressof.h" +#include "../__utility/move.h" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +_LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH +template +class _LIBCUDACXX_TEMPLATE_VIS front_insert_iterator +#if _LIBCUDACXX_STD_VER <= 14 || !defined(_LIBCUDACXX_ABI_NO_ITERATOR_BASES) + : public iterator +#endif +{ +_LIBCUDACXX_SUPPRESS_DEPRECATED_POP +protected: + _Container* container; +public: + typedef _Container container_type; + + _LIBCUDACXX_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_CUDA_VSTD::addressof(__x)) {} + _LIBCUDACXX_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_) + {container->push_front(__value_); return *this;} +#ifndef _LIBCUDACXX_CXX03_LANG + _LIBCUDACXX_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_) + {container->push_front(_CUDA_VSTD::move(__value_)); return *this;} +#endif // _LIBCUDACXX_CXX03_LANG + _LIBCUDACXX_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;} + _LIBCUDACXX_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;} + _LIBCUDACXX_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;} +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +front_insert_iterator<_Container> +front_inserter(_Container& __x) +{ + return front_insert_iterator<_Container>(__x); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_FRONT_INSERT_ITERATOR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/incrementable_traits.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/incrementable_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..441d9326f9037f2568bc583747af8d2203976f50 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/incrementable_traits.h @@ -0,0 +1,136 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_INCREMENTABLE_TRAITS_H +#define _LIBCUDACXX___ITERATOR_INCREMENTABLE_TRAITS_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__concepts/arithmetic.h" +#include "../__type_traits/conditional.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_const.h" +#include "../__type_traits/is_pointer.h" +#include "../__type_traits/is_primary_template.h" +#include "../__type_traits/make_signed.h" +#include "../__type_traits/remove_cvref.h" +#include "../__type_traits/void_t.h" +#include "../__utility/declval.h" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [incrementable.traits] +template struct incrementable_traits {}; + +template +requires is_object_v<_Tp> +struct incrementable_traits<_Tp*> { + using difference_type = ptrdiff_t; +}; + +template +struct incrementable_traits : incrementable_traits<_Ip> {}; + +template +concept __has_member_difference_type = requires { typename _Tp::difference_type; }; + +template<__has_member_difference_type _Tp> +struct incrementable_traits<_Tp> { + using difference_type = typename _Tp::difference_type; +}; + +template +concept __has_integral_minus = + requires(const _Tp& __x, const _Tp& __y) { + { __x - __y } -> integral; + }; + +template<__has_integral_minus _Tp> +requires (!__has_member_difference_type<_Tp>) +struct incrementable_traits<_Tp> { + using difference_type = make_signed_t() - declval<_Tp>())>; +}; + +template +struct _LIBCUDACXX_TEMPLATE_VIS iterator_traits; + +// Let `RI` be `remove_cvref_t`. The type `iter_difference_t` denotes +// `incrementable_traits::difference_type` if `iterator_traits` names a specialization +// generated from the primary template, and `iterator_traits::difference_type` otherwise. +template +using iter_difference_t = typename conditional_t<__is_primary_template>>::value, + incrementable_traits >, + iterator_traits > >::difference_type; + +#elif _LIBCUDACXX_STD_VER > 14 + +// [incrementable.traits] +template struct incrementable_traits {}; + +template +struct incrementable_traits<_Tp*, enable_if_t<_LIBCUDACXX_TRAIT(is_object, _Tp)>> { + using difference_type = ptrdiff_t; +}; + +template +struct incrementable_traits : incrementable_traits<_Ip> {}; + +template +inline constexpr bool __has_member_difference_type = false; + +template +inline constexpr bool __has_member_difference_type<_Tp, void_t> = true; + +template +inline constexpr bool __has_integral_minus = false; + +// In C++17 we get issues trying to bind void* to a const& so special case it here +template +inline constexpr bool __has_integral_minus<_Tp, enable_if_t>, + void_t() - _CUDA_VSTD::declval())>> + = integral() - _CUDA_VSTD::declval())>; + +template +struct incrementable_traits<_Tp, enable_if_t>> { + using difference_type = typename _Tp::difference_type; +}; + +template +struct incrementable_traits<_Tp, enable_if_t && __has_integral_minus<_Tp>>> { + using difference_type = make_signed_t() - declval<_Tp>())>; +}; + +template +struct _LIBCUDACXX_TEMPLATE_VIS iterator_traits; + +// Let `RI` be `remove_cvref_t`. The type `iter_difference_t` denotes +// `incrementable_traits::difference_type` if `iterator_traits` names a specialization +// generated from the primary template, and `iterator_traits::difference_type` otherwise. +template +using iter_difference_t = typename conditional_t<__is_primary_template>>::value, + incrementable_traits >, + iterator_traits > >::difference_type; + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_INCREMENTABLE_TRAITS_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/insert_iterator.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/insert_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..35a866afaaf9622256c916f5a51dc25ba8e0a9ab --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/insert_iterator.h @@ -0,0 +1,71 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_INSERT_ITERATOR_H +#define _LIBCUDACXX___ITERATOR_INSERT_ITERATOR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/iterator_traits.h" +#include "../__iterator/iterator.h" +#include "../__memory/addressof.h" +#include "../__utility/move.h" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +_LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH +template +class _LIBCUDACXX_TEMPLATE_VIS insert_iterator +#if _LIBCUDACXX_STD_VER <= 14 || !defined(_LIBCUDACXX_ABI_NO_ITERATOR_BASES) + : public iterator +#endif +{ +_LIBCUDACXX_SUPPRESS_DEPRECATED_POP +protected: + _Container* container; + typename _Container::iterator iter; +public: + typedef _Container container_type; + + _LIBCUDACXX_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i) + : container(_CUDA_VSTD::addressof(__x)), iter(__i) {} + _LIBCUDACXX_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_) + {iter = container->insert(iter, __value_); ++iter; return *this;} +#ifndef _LIBCUDACXX_CXX03_LANG + _LIBCUDACXX_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_) + {iter = container->insert(iter, _CUDA_VSTD::move(__value_)); ++iter; return *this;} +#endif // _LIBCUDACXX_CXX03_LANG + _LIBCUDACXX_INLINE_VISIBILITY insert_iterator& operator*() {return *this;} + _LIBCUDACXX_INLINE_VISIBILITY insert_iterator& operator++() {return *this;} + _LIBCUDACXX_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;} +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +insert_iterator<_Container> +inserter(_Container& __x, typename _Container::iterator __i) +{ + return insert_iterator<_Container>(__x, __i); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_INSERT_ITERATOR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/istream_iterator.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/istream_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..48e397b6e18008f1ef4af758b7ee9fd77106e57a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/istream_iterator.h @@ -0,0 +1,97 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_ISTREAM_ITERATOR_H +#define _LIBCUDACXX___ITERATOR_ISTREAM_ITERATOR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/iterator.h" +#include "../__memory/addressof.h" +#include "../cstddef" +#include "../iosfwd" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +_LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH +template , class _Distance = ptrdiff_t> +class _LIBCUDACXX_TEMPLATE_VIS istream_iterator +#if _LIBCUDACXX_STD_VER <= 14 || !defined(_LIBCUDACXX_ABI_NO_ITERATOR_BASES) + : public iterator +#endif +{ +_LIBCUDACXX_SUPPRESS_DEPRECATED_POP +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef basic_istream<_CharT,_Traits> istream_type; +private: + istream_type* __in_stream_; + _Tp __value_; +public: + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {} + _LIBCUDACXX_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_CUDA_VSTD::addressof(__s)) + { + if (!(*__in_stream_ >> __value_)) + __in_stream_ = 0; + } + + _LIBCUDACXX_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} + _LIBCUDACXX_INLINE_VISIBILITY const _Tp* operator->() const {return _CUDA_VSTD::addressof((operator*()));} + _LIBCUDACXX_INLINE_VISIBILITY istream_iterator& operator++() + { + if (!(*__in_stream_ >> __value_)) + __in_stream_ = 0; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY istream_iterator operator++(int) + {istream_iterator __t(*this); ++(*this); return __t;} + + template + friend _LIBCUDACXX_INLINE_VISIBILITY + bool + operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, + const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); + + template + friend _LIBCUDACXX_INLINE_VISIBILITY + bool + operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, + const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, + const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) +{ + return __x.__in_stream_ == __y.__in_stream_; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, + const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) +{ + return !(__x == __y); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_ISTREAM_ITERATOR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/istreambuf_iterator.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/istreambuf_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..9424085d52d9f85de38051bed2dbf819bce2544a --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/istreambuf_iterator.h @@ -0,0 +1,104 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_ISTREAMBUF_ITERATOR_H +#define _LIBCUDACXX___ITERATOR_ISTREAMBUF_ITERATOR_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__iterator/iterator.h" +#include "../__iterator/iterator_traits.h" +#include "../iosfwd" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +_LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH +template +class _LIBCUDACXX_TEMPLATE_VIS istreambuf_iterator +#if _LIBCUDACXX_STD_VER <= 14 || !defined(_LIBCUDACXX_ABI_NO_ITERATOR_BASES) + : public iterator +#endif +{ +_LIBCUDACXX_SUPPRESS_DEPRECATED_POP +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename _Traits::int_type int_type; + typedef basic_streambuf<_CharT,_Traits> streambuf_type; + typedef basic_istream<_CharT,_Traits> istream_type; +private: + mutable streambuf_type* __sbuf_; + + class __proxy + { + char_type __keep_; + streambuf_type* __sbuf_; + _LIBCUDACXX_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) + : __keep_(__c), __sbuf_(__s) {} + friend class istreambuf_iterator; + public: + _LIBCUDACXX_INLINE_VISIBILITY char_type operator*() const {return __keep_;} + }; + + _LIBCUDACXX_INLINE_VISIBILITY + bool __test_for_eof() const + { + if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) + __sbuf_ = 0; + return __sbuf_ == 0; + } +public: + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {} + _LIBCUDACXX_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT + : __sbuf_(__s.rdbuf()) {} + _LIBCUDACXX_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT + : __sbuf_(__s) {} + _LIBCUDACXX_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT + : __sbuf_(__p.__sbuf_) {} + + _LIBCUDACXX_INLINE_VISIBILITY char_type operator*() const + {return static_cast(__sbuf_->sgetc());} + _LIBCUDACXX_INLINE_VISIBILITY istreambuf_iterator& operator++() + { + __sbuf_->sbumpc(); + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY __proxy operator++(int) + { + return __proxy(__sbuf_->sbumpc(), __sbuf_); + } + + _LIBCUDACXX_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const + {return __test_for_eof() == __b.__test_for_eof();} +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a, + const istreambuf_iterator<_CharT,_Traits>& __b) + {return __a.equal(__b);} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, + const istreambuf_iterator<_CharT,_Traits>& __b) + {return !__a.equal(__b);} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_ISTREAMBUF_ITERATOR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/iter_move.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/iter_move.h new file mode 100644 index 0000000000000000000000000000000000000000..95da21565c53cada577e4222d4e4d7c83edfbaaf --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/iter_move.h @@ -0,0 +1,177 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_ITER_MOVE_H +#define _LIBCUDACXX___ITERATOR_ITER_MOVE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__concepts/class_or_enum.h" +#include "../__iterator/iterator_traits.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_reference.h" +#include "../__type_traits/remove_cvref.h" +#include "../__utility/declval.h" +#include "../__utility/forward.h" +#include "../__utility/move.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wvoid-ptr-dereference" +#endif + + +#if _LIBCUDACXX_STD_VER > 14 + +// [iterator.cust.move] + +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES +_LIBCUDACXX_BEGIN_NAMESPACE_CPO(__iter_move) + +_LIBCUDACXX_INLINE_VISIBILITY +void iter_move(); + +#if LIBCUDACXX_STD_VER > 17 +template +concept __unqualified_iter_move = + __class_or_enum> && + requires (_Tp&& __t) { + iter_move(_CUDA_VSTD::forward<_Tp>(__t)); + }; + +template +concept __move_deref = + !__unqualified_iter_move<_Tp> && + requires (_Tp&& __t) { + *__t; + requires is_lvalue_reference_v; + }; + +template +concept __just_deref = + !__unqualified_iter_move<_Tp> && + !__move_deref<_Tp> && + requires (_Tp&& __t) { + *__t; + requires (!is_lvalue_reference_v); + }; + +#else // ^^^ CXX20 ^^^ / vvv CXX17 vvv + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __unqualified_iter_move_, + requires(_Tp&& __t)( + requires(__class_or_enum>), + (iter_move(_CUDA_VSTD::forward<_Tp>(__t))) + )); + +template +_LIBCUDACXX_CONCEPT __unqualified_iter_move = _LIBCUDACXX_FRAGMENT(__unqualified_iter_move_, _Tp); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __move_deref_, + requires(_Tp&& __t)( + requires(!__unqualified_iter_move<_Tp>), + requires(is_lvalue_reference_v) + )); + +template +_LIBCUDACXX_CONCEPT __move_deref = _LIBCUDACXX_FRAGMENT(__move_deref_, _Tp); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __just_deref_, + requires(_Tp&& __t)( + requires(!__unqualified_iter_move<_Tp>), + requires(!__move_deref<_Tp>), + requires(!is_lvalue_reference_v) + )); + +template +_LIBCUDACXX_CONCEPT __just_deref = _LIBCUDACXX_FRAGMENT(__just_deref_, _Tp); +#endif // LIBCUDACXX_STD_VER < 20 + +// [iterator.cust.move] + +struct __fn { + _LIBCUDACXX_TEMPLATE(class _Ip) + (requires __unqualified_iter_move<_Ip>) + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + constexpr decltype(auto) operator()(_Ip&& __i) const + noexcept(noexcept(iter_move(_CUDA_VSTD::forward<_Ip>(__i)))) + { + return iter_move(_CUDA_VSTD::forward<_Ip>(__i)); + } + + _LIBCUDACXX_TEMPLATE(class _Ip) + (requires __move_deref<_Ip>) + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY constexpr auto operator()(_Ip&& __i) const + noexcept(noexcept(_CUDA_VSTD::move(*_CUDA_VSTD::forward<_Ip>(__i)))) + -> decltype( _CUDA_VSTD::move(*_CUDA_VSTD::forward<_Ip>(__i))) + { return _CUDA_VSTD::move(*_CUDA_VSTD::forward<_Ip>(__i)); } + + _LIBCUDACXX_TEMPLATE(class _Ip) + (requires __just_deref<_Ip>) + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY constexpr auto operator()(_Ip&& __i) const + noexcept(noexcept(*_CUDA_VSTD::forward<_Ip>(__i))) + -> decltype( *_CUDA_VSTD::forward<_Ip>(__i)) + { return *_CUDA_VSTD::forward<_Ip>(__i); } +}; +_LIBCUDACXX_END_NAMESPACE_CPO +inline namespace __cpo { + _LIBCUDACXX_CPO_ACCESSIBILITY auto iter_move = __iter_move::__fn{}; +} // namespace __cpo +_LIBCUDACXX_END_NAMESPACE_RANGES + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 +template<__dereferenceable _Tp> + requires requires(_Tp& __t) { { _CUDA_VRANGES::iter_move(__t) } -> __can_reference; } +using iter_rvalue_reference_t = decltype(_CUDA_VRANGES::iter_move(_CUDA_VSTD::declval<_Tp&>())); + +#else + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __can_iter_rvalue_reference_t_, + requires(_Tp& __t)( + requires(__dereferenceable<_Tp>), + requires(__can_reference) + )); + +template +_LIBCUDACXX_CONCEPT __can_iter_rvalue_reference_t = _LIBCUDACXX_FRAGMENT(__can_iter_rvalue_reference_t_, _Tp); + +template +using __iter_rvalue_reference_t = decltype(_CUDA_VRANGES::iter_move(_CUDA_VSTD::declval<_Tp&>())); + +template +using iter_rvalue_reference_t = enable_if_t<__can_iter_rvalue_reference_t<_Tp>, + __iter_rvalue_reference_t<_Tp>>; +#endif // LIBCUDACXX_STD_VER < 20 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_STD_VER > 14 + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + +#endif // _LIBCUDACXX___ITERATOR_ITER_MOVE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/iterator.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..a22b37161c8a8e47d71378232529e50361ade5bc --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/iterator.h @@ -0,0 +1,39 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_ITERATOR_H +#define _LIBCUDACXX___ITERATOR_ITERATOR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX17 iterator +{ + typedef _Tp value_type; + typedef _Distance difference_type; + typedef _Pointer pointer; + typedef _Reference reference; + typedef _Category iterator_category; +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_ITERATOR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/iterator_traits.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/iterator_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..f36329a43452e68ec6179fd51f468c5ad20cdb27 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/iterator_traits.h @@ -0,0 +1,846 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_ITERATOR_TRAITS_H +#define _LIBCUDACXX___ITERATOR_ITERATOR_TRAITS_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__concepts/arithmetic.h" +#include "../__concepts/constructible.h" +#include "../__concepts/convertible_to.h" +#include "../__concepts/copyable.h" +#include "../__concepts/equality_comparable.h" +#include "../__concepts/same_as.h" +#include "../__concepts/totally_ordered.h" +#include "../__fwd/pair.h" +#include "../__iterator/incrementable_traits.h" +#include "../__iterator/readable_traits.h" +#include "../__type_traits/add_const.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_primary_template.h" +#include "../__type_traits/remove_cv.h" +#include "../__type_traits/void_t.h" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +template +using __with_reference = _Tp&; + +template +concept __can_reference = requires { + typename __with_reference<_Tp>; +}; + +template +concept __dereferenceable = requires(_Tp& __t) { + { *__t } -> __can_reference; // not required to be equality-preserving +}; + +// [iterator.traits] +template<__dereferenceable _Tp> +using iter_reference_t = decltype(*declval<_Tp&>()); + +template +struct _LIBCUDACXX_TEMPLATE_VIS iterator_traits; + +#elif _LIBCUDACXX_STD_VER > 14 + +template +using __with_reference = _Tp&; + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __can_reference_, + requires() // + (typename(__with_reference<_Tp>))); + +template +_LIBCUDACXX_CONCEPT __can_reference = _LIBCUDACXX_FRAGMENT(__can_reference_, _Tp); + +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wvoid-ptr-dereference" +#endif +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __dereferenceable_, + requires(_Tp& __t)( + requires(__can_reference) + )); +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + +template +_LIBCUDACXX_CONCEPT __dereferenceable = _LIBCUDACXX_FRAGMENT(__dereferenceable_, _Tp); + +// [iterator.traits] +template +using iter_reference_t = enable_if_t<__dereferenceable<_Tp>, decltype(*_CUDA_VSTD::declval<_Tp&>())>; + +template +struct _LIBCUDACXX_TEMPLATE_VIS iterator_traits; +#else +template +struct _LIBCUDACXX_TEMPLATE_VIS iterator_traits; +#endif // _LIBCUDACXX_STD_VER > 11 + +struct _LIBCUDACXX_TEMPLATE_VIS input_iterator_tag {}; +struct _LIBCUDACXX_TEMPLATE_VIS output_iterator_tag {}; +struct _LIBCUDACXX_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {}; +struct _LIBCUDACXX_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {}; +struct _LIBCUDACXX_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {}; +#if _LIBCUDACXX_STD_VER > 11 +struct _LIBCUDACXX_TEMPLATE_VIS contiguous_iterator_tag : public random_access_iterator_tag {}; +#endif + +template +struct __iter_traits_cache { + using type = _If< + __is_primary_template>::value, + _Iter, + iterator_traits<_Iter> + >; +}; +template +using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type; + +struct __iter_concept_concept_test { + template + using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept; +}; +struct __iter_concept_category_test { + template + using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category; +}; +struct __iter_concept_random_fallback { + template + using _Apply = __enable_if_t< + __is_primary_template>::value, + random_access_iterator_tag + >; +}; + +template struct __test_iter_concept + : _IsValidExpansion<_Tester::template _Apply, _Iter>, + _Tester +{ +}; + +template +struct __iter_concept_cache { + using type = _Or< + __test_iter_concept<_Iter, __iter_concept_concept_test>, + __test_iter_concept<_Iter, __iter_concept_category_test>, + __test_iter_concept<_Iter, __iter_concept_random_fallback> + >; +}; + +template +using _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>; + + +template +struct __has_iterator_typedefs +{ +private: + template + _LIBCUDACXX_INLINE_VISIBILITY static false_type __test(...); + template + _LIBCUDACXX_INLINE_VISIBILITY static true_type __test(__void_t* = nullptr, + __void_t* = nullptr, + __void_t* = nullptr, + __void_t* = nullptr, + __void_t* = nullptr); +public: + static const bool value = decltype(__test<_Tp>(0,0,0,0,0))::value; +}; + +template +struct __has_iterator_category +{ +private: + template _LIBCUDACXX_INLINE_VISIBILITY static false_type __test(...); + template _LIBCUDACXX_INLINE_VISIBILITY static true_type __test(typename _Up::iterator_category* = nullptr); +public: + static const bool value = decltype(__test<_Tp>(nullptr))::value; +}; + +template +struct __has_iterator_concept +{ +private: + template _LIBCUDACXX_INLINE_VISIBILITY static false_type __test(...); + template _LIBCUDACXX_INLINE_VISIBILITY static true_type __test(typename _Up::iterator_concept* = nullptr); +public: + static const bool value = decltype(__test<_Tp>(nullptr))::value; +}; + +#if _LIBCUDACXX_STD_VER > 17 + +// The `cpp17-*-iterator` exposition-only concepts have very similar names to the `Cpp17*Iterator` named requirements +// from `[iterator.cpp17]`. To avoid confusion between the two, the exposition-only concepts have been banished to +// a "detail" namespace indicating they have a niche use-case. +namespace __iterator_traits_detail { +template +concept __cpp17_iterator = + requires(_Ip __i) { + { *__i } -> __can_reference; + { ++__i } -> same_as<_Ip&>; + { *__i++ } -> __can_reference; + } && + copyable<_Ip>; + +template +concept __cpp17_input_iterator = + __cpp17_iterator<_Ip> && + equality_comparable<_Ip> && + requires(_Ip __i) { + typename incrementable_traits<_Ip>::difference_type; + typename indirectly_readable_traits<_Ip>::value_type; + typename common_reference_t&&, + typename indirectly_readable_traits<_Ip>::value_type&>; + typename common_reference_t::value_type&>; + requires signed_integral::difference_type>; + }; + +template +concept __cpp17_forward_iterator = + __cpp17_input_iterator<_Ip> && + constructible_from<_Ip> && + is_lvalue_reference_v> && + same_as>, + typename indirectly_readable_traits<_Ip>::value_type> && + requires(_Ip __i) { + { __i++ } -> convertible_to<_Ip const&>; + { *__i++ } -> same_as>; + }; + +template +concept __cpp17_bidirectional_iterator = + __cpp17_forward_iterator<_Ip> && + requires(_Ip __i) { + { --__i } -> same_as<_Ip&>; + { __i-- } -> convertible_to<_Ip const&>; + { *__i-- } -> same_as>; + }; + +template +concept __cpp17_random_access_iterator = + __cpp17_bidirectional_iterator<_Ip> && + totally_ordered<_Ip> && + requires(_Ip __i, typename incrementable_traits<_Ip>::difference_type __n) { + { __i += __n } -> same_as<_Ip&>; + { __i -= __n } -> same_as<_Ip&>; + { __i + __n } -> same_as<_Ip>; + { __n + __i } -> same_as<_Ip>; + { __i - __n } -> same_as<_Ip>; + { __i - __i } -> same_as; // NOLINT(misc-redundant-expression) ; This is llvm.org/PR54114 + { __i[__n] } -> convertible_to>; + }; +} // namespace __iterator_traits_detail + +template +concept __has_member_reference = requires { typename _Ip::reference; }; + +template +concept __has_member_pointer = requires { typename _Ip::pointer; }; + +template +concept __has_member_iterator_category = requires { typename _Ip::iterator_category; }; + +template +concept __specifies_members = requires { + typename _Ip::value_type; + typename _Ip::difference_type; + requires __has_member_reference<_Ip>; + requires __has_member_iterator_category<_Ip>; + }; + +template +struct __iterator_traits_member_pointer_or_void { + using type = void; +}; + +template<__has_member_pointer _Tp> +struct __iterator_traits_member_pointer_or_void<_Tp> { + using type = typename _Tp::pointer; +}; + +template +concept __cpp17_iterator_missing_members = + !__specifies_members<_Tp> && + __iterator_traits_detail::__cpp17_iterator<_Tp>; + +template +concept __cpp17_input_iterator_missing_members = + __cpp17_iterator_missing_members<_Tp> && + __iterator_traits_detail::__cpp17_input_iterator<_Tp>; + +// Otherwise, `pointer` names `void`. +template +struct __iterator_traits_member_pointer_or_arrow_or_void { using type = void; }; + +// [iterator.traits]/3.2.1 +// If the qualified-id `I::pointer` is valid and denotes a type, `pointer` names that type. +template<__has_member_pointer _Ip> +struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> { using type = typename _Ip::pointer; }; + +// Otherwise, if `decltype(declval().operator->())` is well-formed, then `pointer` names that +// type. +template + requires requires(_Ip& __i) { __i.operator->(); } && (!__has_member_pointer<_Ip>) +struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> { + using type = decltype(declval<_Ip&>().operator->()); +}; + +// Otherwise, `reference` names `iter-reference-t`. +template +struct __iterator_traits_member_reference { using type = iter_reference_t<_Ip>; }; + +// [iterator.traits]/3.2.2 +// If the qualified-id `I::reference` is valid and denotes a type, `reference` names that type. +template<__has_member_reference _Ip> +struct __iterator_traits_member_reference<_Ip> { using type = typename _Ip::reference; }; + +// [iterator.traits]/3.2.3.4 +// input_iterator_tag +template +struct __deduce_iterator_category { + using type = input_iterator_tag; +}; + +// [iterator.traits]/3.2.3.1 +// `random_access_iterator_tag` if `I` satisfies `cpp17-random-access-iterator`, or otherwise +template<__iterator_traits_detail::__cpp17_random_access_iterator _Ip> +struct __deduce_iterator_category<_Ip> { + using type = random_access_iterator_tag; +}; + +// [iterator.traits]/3.2.3.2 +// `bidirectional_iterator_tag` if `I` satisfies `cpp17-bidirectional-iterator`, or otherwise +template<__iterator_traits_detail::__cpp17_bidirectional_iterator _Ip> + requires (!__iterator_traits_detail::__cpp17_random_access_iterator<_Ip>) // nvbug 3885350 +struct __deduce_iterator_category<_Ip> { + using type = bidirectional_iterator_tag; +}; + +// [iterator.traits]/3.2.3.3 +// `forward_iterator_tag` if `I` satisfies `cpp17-forward-iterator`, or otherwise +template<__iterator_traits_detail::__cpp17_forward_iterator _Ip> + requires (!__iterator_traits_detail::__cpp17_bidirectional_iterator<_Ip>) // nvbug 3885350 +struct __deduce_iterator_category<_Ip> { + using type = forward_iterator_tag; +}; + +template +struct __iterator_traits_iterator_category : __deduce_iterator_category<_Ip> {}; + +// [iterator.traits]/3.2.3 +// If the qualified-id `I::iterator-category` is valid and denotes a type, `iterator-category` names +// that type. +template<__has_member_iterator_category _Ip> +struct __iterator_traits_iterator_category<_Ip> { + using type = typename _Ip::iterator_category; +}; + +// otherwise, it names void. +template +struct __iterator_traits_difference_type { using type = void; }; + +// If the qualified-id `incrementable_traits::difference_type` is valid and denotes a type, then +// `difference_type` names that type; +template +requires requires { typename incrementable_traits<_Ip>::difference_type; } +struct __iterator_traits_difference_type<_Ip> { + using type = typename incrementable_traits<_Ip>::difference_type; +}; + +// [iterator.traits]/3.4 +// Otherwise, `iterator_traits` has no members by any of the above names. +template +struct __iterator_traits {}; + +// [iterator.traits]/3.1 +// If `I` has valid ([temp.deduct]) member types `difference-type`, `value-type`, `reference`, and +// `iterator-category`, then `iterator-traits` has the following publicly accessible members: +template<__specifies_members _Ip> +struct __iterator_traits<_Ip> { + using iterator_category = typename _Ip::iterator_category; + using value_type = typename _Ip::value_type; + using difference_type = typename _Ip::difference_type; + using pointer = typename __iterator_traits_member_pointer_or_void<_Ip>::type; + using reference = typename _Ip::reference; +}; + +// [iterator.traits]/3.2 +// Otherwise, if `I` satisfies the exposition-only concept `cpp17-input-iterator`, +// `iterator-traits` has the following publicly accessible members: +template<__cpp17_input_iterator_missing_members _Ip> +struct __iterator_traits<_Ip> { + using iterator_category = typename __iterator_traits_iterator_category<_Ip>::type; + using value_type = typename indirectly_readable_traits<_Ip>::value_type; + using difference_type = typename incrementable_traits<_Ip>::difference_type; + using pointer = typename __iterator_traits_member_pointer_or_arrow_or_void<_Ip>::type; + using reference = typename __iterator_traits_member_reference<_Ip>::type; +}; + +// Otherwise, if `I` satisfies the exposition-only concept `cpp17-iterator`, then +// `iterator_traits` has the following publicly accessible members: +template<__cpp17_iterator_missing_members _Ip> + requires (!__cpp17_input_iterator_missing_members<_Ip>) // nvbug 3885350 +struct __iterator_traits<_Ip> { + using iterator_category = output_iterator_tag; + using value_type = void; + using difference_type = typename __iterator_traits_difference_type<_Ip>::type; + using pointer = void; + using reference = void; +}; + +template +struct _LIBCUDACXX_TEMPLATE_VIS iterator_traits : __iterator_traits<_Ip> { + using __primary_template = iterator_traits; +}; + +#elif _LIBCUDACXX_STD_VER > 14 + +// The `cpp17-*-iterator` exposition-only concepts have very similar names to the `Cpp17*Iterator` named requirements +// from `[iterator.cpp17]`. To avoid confusion between the two, the exposition-only concepts have been banished to +// a "detail" namespace indicating they have a niche use-case. +namespace __iterator_traits_detail { +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __cpp17_iterator_, + requires(_Ip __i) // + (requires(__can_reference), + requires(same_as<_Ip&, decltype(++__i)>), + requires(__can_reference), + requires(copyable<_Ip>))); + +template +_LIBCUDACXX_CONCEPT __cpp17_iterator = _LIBCUDACXX_FRAGMENT(__cpp17_iterator_, _Ip); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __cpp17_input_iterator_, + requires(_Ip __i)( + typename(common_reference_t&&, typename indirectly_readable_traits<_Ip>::value_type&>), + typename(common_reference_t::value_type&>), + requires(__cpp17_iterator<_Ip>), + requires(equality_comparable<_Ip>), + requires(__has_member_difference_type>), + requires(__has_member_value_type>), + requires(signed_integral::difference_type>) + )); + +template +_LIBCUDACXX_CONCEPT __cpp17_input_iterator = _LIBCUDACXX_FRAGMENT(__cpp17_input_iterator_, _Ip); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __cpp17_forward_iterator_, + requires(_Ip __i)( + requires(__cpp17_input_iterator<_Ip>), + requires(convertible_to), + requires(same_as, decltype(*__i++)>), + requires(constructible_from<_Ip>), + requires(_LIBCUDACXX_TRAIT(is_lvalue_reference, iter_reference_t<_Ip>)), + requires(same_as>, typename indirectly_readable_traits<_Ip>::value_type>) + )); + +template +_LIBCUDACXX_CONCEPT __cpp17_forward_iterator = _LIBCUDACXX_FRAGMENT(__cpp17_forward_iterator_, _Ip); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __cpp17_bidirectional_iterator_, + requires(_Ip __i)( + requires(__cpp17_forward_iterator<_Ip>), + requires(same_as<_Ip&, decltype(--__i)>), + requires(convertible_to), + requires(same_as, decltype(*__i--)>) + )); + +template +_LIBCUDACXX_CONCEPT __cpp17_bidirectional_iterator = _LIBCUDACXX_FRAGMENT(__cpp17_bidirectional_iterator_, _Ip); + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __cpp17_random_access_iterator_, + requires(_Ip __i, typename incrementable_traits<_Ip>::difference_type __n) // + (requires(same_as<_Ip&, decltype(__i += __n)>), + requires(same_as<_Ip&, decltype(__i -= __n)>), + requires(same_as<_Ip, decltype(__i + __n)>), + requires(same_as<_Ip, decltype(__n + __i)>), + requires(same_as<_Ip, decltype(__i - __n)>), + requires(same_as), + requires(convertible_to>))); + +template +_LIBCUDACXX_CONCEPT __cpp17_random_access_iterator = + __cpp17_bidirectional_iterator<_Ip> && + totally_ordered<_Ip> && + _LIBCUDACXX_FRAGMENT(__cpp17_random_access_iterator_, _Ip); +} // namespace __iterator_traits_detail + +template +inline constexpr bool __has_member_reference = false; + +template +inline constexpr bool __has_member_reference<_Tp, void_t> = true; + +template +inline constexpr bool __has_member_pointer = false; + +template +inline constexpr bool __has_member_pointer<_Tp, void_t> = true; + +template +inline constexpr bool __has_member_iterator_category = false; + +template +inline constexpr bool __has_member_iterator_category<_Tp, void_t> = true; + +template +_LIBCUDACXX_CONCEPT __specifies_members = + __has_member_value_type<_Ip> && + __has_member_difference_type<_Ip> && + __has_member_reference<_Ip> && + __has_member_iterator_category<_Ip>; + +template +struct __iterator_traits_member_pointer_or_void { + using type = void; +}; + +template +struct __iterator_traits_member_pointer_or_void<_Tp, enable_if_t<__has_member_pointer<_Tp>>> { + using type = typename _Tp::pointer; +}; + +template +_LIBCUDACXX_CONCEPT __cpp17_iterator_missing_members = + !__specifies_members<_Tp> && + __iterator_traits_detail::__cpp17_iterator<_Tp>; + +template +_LIBCUDACXX_CONCEPT __cpp17_input_iterator_missing_members = + __cpp17_iterator_missing_members<_Tp> && + __iterator_traits_detail::__cpp17_input_iterator<_Tp>; + +// Otherwise, `pointer` names `void`. +template +struct __iterator_traits_member_pointer_or_arrow_or_void { using type = void; }; + +// [iterator.traits]/3.2.1 +// If the qualified-id `I::pointer` is valid and denotes a type, `pointer` names that type. +template +struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip, enable_if_t<__has_member_pointer<_Ip>>> +{ using type = typename _Ip::pointer; }; + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __has_operator_arrow_, + requires(_Ip& __i) // + (__i.operator->())); + +template +_LIBCUDACXX_CONCEPT __has_operator_arrow = _LIBCUDACXX_FRAGMENT(__has_operator_arrow_, _Ip); + +// Otherwise, if `decltype(declval().operator->())` is well-formed, then `pointer` names that +// type. +template +struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip, + enable_if_t<__has_operator_arrow<_Ip> && !__has_member_pointer<_Ip>>> { + using type = decltype(declval<_Ip&>().operator->()); +}; + +// Otherwise, `reference` names `iter-reference-t`. +template +struct __iterator_traits_member_reference { using type = iter_reference_t<_Ip>; }; + +// [iterator.traits]/3.2.2 +// If the qualified-id `I::reference` is valid and denotes a type, `reference` names that type. +template +struct __iterator_traits_member_reference<_Ip, enable_if_t<__has_member_reference<_Ip>>> +{ using type = typename _Ip::reference; }; + +// [iterator.traits]/3.2.3.4 +// input_iterator_tag +template +struct __deduce_iterator_category { + using type = input_iterator_tag; +}; + +// [iterator.traits]/3.2.3.1 +// `random_access_iterator_tag` if `I` satisfies `cpp17-random-access-iterator`, or otherwise +template +struct __deduce_iterator_category<_Ip, enable_if_t< + __iterator_traits_detail::__cpp17_random_access_iterator<_Ip>>> { + using type = random_access_iterator_tag; +}; + +// [iterator.traits]/3.2.3.2 +// `bidirectional_iterator_tag` if `I` satisfies `cpp17-bidirectional-iterator`, or otherwise +template +struct __deduce_iterator_category<_Ip, enable_if_t< + !__iterator_traits_detail::__cpp17_random_access_iterator<_Ip> && + __iterator_traits_detail::__cpp17_bidirectional_iterator<_Ip>>> { + using type = bidirectional_iterator_tag; +}; + +// [iterator.traits]/3.2.3.3 +// `forward_iterator_tag` if `I` satisfies `cpp17-forward-iterator`, or otherwise +template +struct __deduce_iterator_category<_Ip, enable_if_t< + !__iterator_traits_detail::__cpp17_bidirectional_iterator<_Ip> && + __iterator_traits_detail::__cpp17_forward_iterator<_Ip>>> { + using type = forward_iterator_tag; +}; + +template +struct __iterator_traits_iterator_category : __deduce_iterator_category<_Ip> {}; + +// [iterator.traits]/3.2.3 +// If the qualified-id `I::iterator-category` is valid and denotes a type, `iterator-category` names +// that type. +template +struct __iterator_traits_iterator_category<_Ip, enable_if_t< + __has_member_iterator_category<_Ip>>> { + using type = typename _Ip::iterator_category; +}; + +// otherwise, it names void. +template +struct __iterator_traits_difference_type { using type = void; }; + +// If the qualified-id `incrementable_traits::difference_type` is valid and denotes a type, then +// `difference_type` names that type; +template +struct __iterator_traits_difference_type<_Ip, void_t< + typename incrementable_traits<_Ip>::difference_type>> { + using type = typename incrementable_traits<_Ip>::difference_type; +}; + +// [iterator.traits]/3.4 +// Otherwise, `iterator_traits` has no members by any of the above names. +template +struct __iterator_traits {}; + +// [iterator.traits]/3.1 +// If `I` has valid ([temp.deduct]) member types `difference-type`, `value-type`, `reference`, and +// `iterator-category`, then `iterator-traits` has the following publicly accessible members: +template +struct __iterator_traits<_Ip, enable_if_t<__specifies_members<_Ip>>> { + using iterator_category = typename _Ip::iterator_category; + using value_type = typename _Ip::value_type; + using difference_type = typename _Ip::difference_type; + using pointer = typename __iterator_traits_member_pointer_or_void<_Ip>::type; + using reference = typename _Ip::reference; +}; + +// [iterator.traits]/3.2 +// Otherwise, if `I` satisfies the exposition-only concept `cpp17-input-iterator`, +// `iterator-traits` has the following publicly accessible members: +template +struct __iterator_traits<_Ip, enable_if_t && + __cpp17_input_iterator_missing_members<_Ip>>> { + using iterator_category = typename __iterator_traits_iterator_category<_Ip>::type; + using value_type = typename indirectly_readable_traits<_Ip>::value_type; + using difference_type = typename incrementable_traits<_Ip>::difference_type; + using pointer = typename __iterator_traits_member_pointer_or_arrow_or_void<_Ip>::type; + using reference = typename __iterator_traits_member_reference<_Ip>::type; +}; + +// Otherwise, if `I` satisfies the exposition-only concept `cpp17-iterator`, then +// `iterator_traits` has the following publicly accessible members: +template +struct __iterator_traits<_Ip, enable_if_t && + !__cpp17_input_iterator_missing_members<_Ip> && + __cpp17_iterator_missing_members<_Ip>>> { + using iterator_category = output_iterator_tag; + using value_type = void; + using difference_type = typename __iterator_traits_difference_type<_Ip>::type; + using pointer = void; + using reference = void; +}; + +template +struct _LIBCUDACXX_TEMPLATE_VIS iterator_traits : __iterator_traits<_Ip> { + using __primary_template = iterator_traits; +}; + +#else // _LIBCUDACXX_STD_VER > 11 + +template struct __iterator_traits {}; + +template struct __iterator_traits_impl {}; + +template +struct __iterator_traits_impl<_Iter, true> +{ + typedef typename _Iter::difference_type difference_type; + typedef typename _Iter::value_type value_type; + typedef typename _Iter::pointer pointer; + typedef typename _Iter::reference reference; + typedef typename _Iter::iterator_category iterator_category; +}; + +template +struct __iterator_traits<_Iter, true> + : __iterator_traits_impl + < + _Iter, + is_convertible::value || + is_convertible::value + > +{}; + +// iterator_traits will only have the nested types if Iterator::iterator_category +// exists. Else iterator_traits will be an empty class. This is a +// conforming extension which allows some programs to compile and behave as +// the client expects instead of failing at compile time. + +template +struct _LIBCUDACXX_TEMPLATE_VIS iterator_traits + : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> { + + using __primary_template = iterator_traits; +}; +#endif // _LIBCUDACXX_STD_VER < 17 + +template +#if _LIBCUDACXX_STD_VER > 17 +requires is_object_v<_Tp> +#endif +struct _LIBCUDACXX_TEMPLATE_VIS iterator_traits<_Tp*> +{ + typedef ptrdiff_t difference_type; + typedef __remove_cv_t<_Tp> value_type; + typedef _Tp* pointer; + typedef typename add_lvalue_reference<_Tp>::type reference; + typedef random_access_iterator_tag iterator_category; +#if _LIBCUDACXX_STD_VER > 14 + typedef contiguous_iterator_tag iterator_concept; +#endif +}; + +template >::value> +struct __has_iterator_category_convertible_to + : is_convertible::iterator_category, _Up> +{}; + +template +struct __has_iterator_category_convertible_to<_Tp, _Up, false> : false_type {}; + +template ::value> +struct __has_iterator_concept_convertible_to + : is_convertible +{}; + +template +struct __has_iterator_concept_convertible_to<_Tp, _Up, false> : false_type {}; + +template +struct __is_cpp17_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {}; + +template +struct __is_cpp17_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {}; + +template +struct __is_cpp17_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {}; + +template +struct __is_cpp17_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {}; + +// __is_cpp17_contiguous_iterator determines if an iterator is known by +// libc++ to be contiguous, either because it advertises itself as such +// (in C++20) or because it is a pointer type or a known trivial wrapper +// around a (possibly fancy) pointer type, such as __wrap_iter. +// Such iterators receive special "contiguous" optimizations in +// std::copy and std::sort. +// +#if _LIBCUDACXX_STD_VER > 14 +template +struct __is_cpp17_contiguous_iterator : _Or< + __has_iterator_category_convertible_to<_Tp, contiguous_iterator_tag>, + __has_iterator_concept_convertible_to<_Tp, contiguous_iterator_tag> +> {}; +#else +template +struct __is_cpp17_contiguous_iterator : false_type {}; +#endif + +// Any native pointer which is an iterator is also a contiguous iterator. +template +struct __is_cpp17_contiguous_iterator<_Up*> : true_type {}; + + +template +class __wrap_iter; + +template +struct __is_exactly_cpp17_input_iterator + : public integral_constant::value && + !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {}; + +template +struct __is_exactly_cpp17_forward_iterator + : public integral_constant::value && + !__has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>::value> {}; + +template +struct __is_exactly_cpp17_bidirectional_iterator + : public integral_constant::value && + !__has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>::value> {}; + +template +using __iter_value_type = typename iterator_traits<_InputIterator>::value_type; + +template +using __iter_key_type = typename remove_const::value_type::first_type>::type; + +template +using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type; + +template +using __iter_to_alloc_type = pair< + typename add_const::value_type::first_type>::type, + typename iterator_traits<_InputIterator>::value_type::second_type>; + +template +using __iterator_category_type = typename iterator_traits<_Iter>::iterator_category; + +template +using __iterator_pointer_type = typename iterator_traits<_Iter>::pointer; + +template +using __iter_diff_t = typename iterator_traits<_Iter>::difference_type; + +template +using __iter_value_type = typename iterator_traits<_InputIterator>::value_type; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_ITERATOR_TRAITS_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/move_iterator.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/move_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..0a088bb480213ab1b853c40ba5260016eb2d8d3f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/move_iterator.h @@ -0,0 +1,171 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_MOVE_ITERATOR_H +#define _LIBCUDACXX___ITERATOR_MOVE_ITERATOR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/iterator_traits.h" +#include "../__type_traits/conditional.h" +#include "../__type_traits/is_reference.h" +#include "../__type_traits/remove_reference.h" +#include "../__utility/move.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + + +template +class _LIBCUDACXX_TEMPLATE_VIS move_iterator +{ +private: + _Iter __i; +public: + typedef _Iter iterator_type; + typedef typename iterator_traits::iterator_category iterator_category; + typedef typename iterator_traits::value_type value_type; + typedef typename iterator_traits::difference_type difference_type; + typedef iterator_type pointer; +#ifndef _LIBCUDACXX_CXX03_LANG + typedef typename iterator_traits::reference __reference; + typedef __conditional_t< + is_reference<__reference>::value, + __libcpp_remove_reference_t<__reference>&&, + __reference + > reference; +#else + typedef typename iterator_traits::reference reference; +#endif + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + move_iterator() : __i() {} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + explicit move_iterator(_Iter __x) : __i(__x) {} + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reference operator*() const { return static_cast(*__i); } + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + pointer operator->() const { return __i;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + move_iterator& operator++() {++__i; return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + move_iterator& operator--() {--__i; return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + move_iterator& operator+=(difference_type __n) {__i += __n; return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reference operator[](difference_type __n) const { return _CUDA_VSTD::move(__i[__n]); } +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() == __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() < __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() != __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() > __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() >= __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() <= __y.base(); +} + +#ifndef _LIBCUDACXX_CXX03_LANG +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto +operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +-> decltype(__x.base() - __y.base()) +{ + return __x.base() - __y.base(); +} +#else +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename move_iterator<_Iter1>::difference_type +operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() - __y.base(); +} +#endif + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +move_iterator<_Iter> +operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) +{ + return move_iterator<_Iter>(__x.base() + __n); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +move_iterator<_Iter> +make_move_iterator(_Iter __i) +{ + return move_iterator<_Iter>(__i); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_MOVE_ITERATOR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/next.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/next.h new file mode 100644 index 0000000000000000000000000000000000000000..3ea7022f82e0e51a2db5b1c516952c4f19a38561 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/next.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_NEXT_H +#define _LIBCUDACXX___ITERATOR_NEXT_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__assert" +#include "../__iterator/advance.h" +#include "../__iterator/iterator_traits.h" +#include "../__type_traits/enable_if.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +__enable_if_t +< + __is_cpp17_input_iterator<_InputIter>::value, + _InputIter +> +next(_InputIter __x, + typename iterator_traits<_InputIter>::difference_type __n = 1) +{ + _LIBCUDACXX_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, + "Attempt to next(it, -n) on a non-bidi iterator"); + + _CUDA_VSTD::advance(__x, __n); + return __x; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_NEXT_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/ostream_iterator.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/ostream_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..d2f620032114b2b9a7691b147fc3115aab0652f7 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/ostream_iterator.h @@ -0,0 +1,65 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_OSTREAM_ITERATOR_H +#define _LIBCUDACXX___ITERATOR_OSTREAM_ITERATOR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/iterator.h" +#include "../__iterator/iterator_traits.h" +#include "../__memory/addressof.h" +#include "../cstddef" +#include "../iosfwd" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +_LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH +template > +class _LIBCUDACXX_TEMPLATE_VIS ostream_iterator +#if _LIBCUDACXX_STD_VER <= 14 || !defined(_LIBCUDACXX_ABI_NO_ITERATOR_BASES) + : public iterator +#endif +{ +_LIBCUDACXX_SUPPRESS_DEPRECATED_POP +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef basic_ostream<_CharT,_Traits> ostream_type; +private: + ostream_type* __out_stream_; + const char_type* __delim_; +public: + _LIBCUDACXX_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT + : __out_stream_(_CUDA_VSTD::addressof(__s)), __delim_(0) {} + _LIBCUDACXX_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT + : __out_stream_(_CUDA_VSTD::addressof(__s)), __delim_(__delimiter) {} + _LIBCUDACXX_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) + { + *__out_stream_ << __value_; + if (__delim_) + *__out_stream_ << __delim_; + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} + _LIBCUDACXX_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} + _LIBCUDACXX_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_OSTREAM_ITERATOR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/ostreambuf_iterator.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/ostreambuf_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..68207b14a699608cd55fb92fe7c520b4d729df90 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/ostreambuf_iterator.h @@ -0,0 +1,71 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_OSTREAMBUF_ITERATOR_H +#define _LIBCUDACXX___ITERATOR_OSTREAMBUF_ITERATOR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/iterator.h" +#include "../__iterator/iterator_traits.h" +#include "../cstddef" +#include "../iosfwd" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +_LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH +template +class _LIBCUDACXX_TEMPLATE_VIS ostreambuf_iterator +#if _LIBCUDACXX_STD_VER <= 14 || !defined(_LIBCUDACXX_ABI_NO_ITERATOR_BASES) + : public iterator +#endif +{ +_LIBCUDACXX_SUPPRESS_DEPRECATED_POP +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef basic_streambuf<_CharT,_Traits> streambuf_type; + typedef basic_ostream<_CharT,_Traits> ostream_type; +private: + streambuf_type* __sbuf_; +public: + _LIBCUDACXX_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT + : __sbuf_(__s.rdbuf()) {} + _LIBCUDACXX_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT + : __sbuf_(__s) {} + _LIBCUDACXX_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) + { + if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) + __sbuf_ = 0; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} + _LIBCUDACXX_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} + _LIBCUDACXX_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} + _LIBCUDACXX_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;} + + template + friend + _LIBCUDACXX_HIDDEN _LIBCUDACXX_HOST_DEVICE + ostreambuf_iterator<_Ch, _Tr> + __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, + const _Ch* __ob, const _Ch* __op, const _Ch* __oe, + ios_base& __iob, _Ch __fl); +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_OSTREAMBUF_ITERATOR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/prev.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/prev.h new file mode 100644 index 0000000000000000000000000000000000000000..2a42936622243d836ad82390db2d2f3e6f1cf20e --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/prev.h @@ -0,0 +1,47 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_PREV_H +#define _LIBCUDACXX___ITERATOR_PREV_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__assert" +#include "../__iterator/advance.h" +#include "../__iterator/iterator_traits.h" +#include "../__type_traits/enable_if.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +__enable_if_t +< + __is_cpp17_input_iterator<_InputIter>::value, + _InputIter +> +prev(_InputIter __x, + typename iterator_traits<_InputIter>::difference_type __n = 1) +{ + _LIBCUDACXX_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, + "Attempt to prev(it, +n) on a non-bidi iterator"); + _CUDA_VSTD::advance(__x, -__n); + return __x; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_PREV_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/readable_traits.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/readable_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..e8a74fc921dcc60911b72c7d02e0c143de3dd1c4 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/readable_traits.h @@ -0,0 +1,159 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_READABLE_TRAITS_H +#define _LIBCUDACXX___ITERATOR_READABLE_TRAITS_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__type_traits/is_primary_template.h" +#include "../__type_traits/conditional.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_array.h" +#include "../__type_traits/is_const.h" +#include "../__type_traits/is_object.h" +#include "../__type_traits/is_primary_template.h" +#include "../__type_traits/remove_cv.h" +#include "../__type_traits/remove_cvref.h" +#include "../__type_traits/remove_extent.h" +#include "../__type_traits/void_t.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +// [readable.traits] +template struct __cond_value_type {}; + +template +requires is_object_v<_Tp> +struct __cond_value_type<_Tp> { using value_type = remove_cv_t<_Tp>; }; + +template +concept __has_member_value_type = requires { typename _Tp::value_type; }; + +template +concept __has_member_element_type = requires { typename _Tp::element_type; }; + +template struct indirectly_readable_traits {}; + +template +requires is_array_v<_Ip> +struct indirectly_readable_traits<_Ip> { + using value_type = remove_cv_t>; +}; + +template +struct indirectly_readable_traits : indirectly_readable_traits<_Ip> {}; + +template +struct indirectly_readable_traits<_Tp*> : __cond_value_type<_Tp> {}; + +template<__has_member_value_type _Tp> +struct indirectly_readable_traits<_Tp> + : __cond_value_type {}; + +template<__has_member_element_type _Tp> +struct indirectly_readable_traits<_Tp> + : __cond_value_type {}; + +template<__has_member_value_type _Tp> + requires __has_member_element_type<_Tp> +struct indirectly_readable_traits<_Tp> {}; + +template<__has_member_value_type _Tp> + requires __has_member_element_type<_Tp> && + same_as, + remove_cv_t> +struct indirectly_readable_traits<_Tp> + : __cond_value_type {}; + +template +struct _LIBCUDACXX_TEMPLATE_VIS iterator_traits; + +// Let `RI` be `remove_cvref_t`. The type `iter_value_t` denotes +// `indirectly_readable_traits::value_type` if `iterator_traits` names a specialization +// generated from the primary template, and `iterator_traits::value_type` otherwise. +template +using iter_value_t = typename conditional_t<__is_primary_template>>::value, + indirectly_readable_traits >, + iterator_traits > >::value_type; + +#elif _LIBCUDACXX_STD_VER > 14 + +// [readable.traits] +template struct __cond_value_type {}; + +template +struct __cond_value_type<_Tp, enable_if_t<_LIBCUDACXX_TRAIT(is_object, _Tp)>> { using value_type = remove_cv_t<_Tp>; }; + +template +inline constexpr bool __has_member_value_type = false; + +template +inline constexpr bool __has_member_value_type<_Tp, void_t> = true; + +template +inline constexpr bool __has_member_element_type = false; + +template +inline constexpr bool __has_member_element_type<_Tp, void_t> = true; + +template struct indirectly_readable_traits {}; + +template +struct indirectly_readable_traits<_Ip, enable_if_t> { + using value_type = remove_cv_t>; +}; + +template +struct indirectly_readable_traits + : indirectly_readable_traits<_Ip> {}; + +template +struct indirectly_readable_traits<_Tp*> + : __cond_value_type<_Tp> {}; + +template +struct indirectly_readable_traits<_Tp, enable_if_t && !__has_member_element_type<_Tp>>> + : __cond_value_type {}; + +template +struct indirectly_readable_traits<_Tp, enable_if_t && __has_member_element_type<_Tp>>> + : __cond_value_type {}; + +template +struct indirectly_readable_traits<_Tp, enable_if_t && __has_member_element_type<_Tp> && + same_as, + remove_cv_t>>> + : __cond_value_type {}; + +template +struct _LIBCUDACXX_TEMPLATE_VIS iterator_traits; + +// Let `RI` be `remove_cvref_t`. The type `iter_value_t` denotes +// `indirectly_readable_traits::value_type` if `iterator_traits` names a specialization +// generated from the primary template, and `iterator_traits::value_type` otherwise. +template +using iter_value_t = typename conditional_t<__is_primary_template>>::value, + indirectly_readable_traits >, + iterator_traits > >::value_type; + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_READABLE_TRAITS_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/reverse_access.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/reverse_access.h new file mode 100644 index 0000000000000000000000000000000000000000..6b9140a360979668923eee0f397a37975748865c --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/reverse_access.h @@ -0,0 +1,104 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_REVERSE_ACCESS_H +#define _LIBCUDACXX___ITERATOR_REVERSE_ACCESS_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/reverse_iterator.h" +#include "../cstddef" +#include "../initializer_list" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) +{ + return reverse_iterator<_Tp*>(__array + _Np); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) +{ + return reverse_iterator<_Tp*>(__array); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +reverse_iterator rbegin(initializer_list<_Ep> __il) +{ + return reverse_iterator(__il.end()); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +reverse_iterator rend(initializer_list<_Ep> __il) +{ + return reverse_iterator(__il.begin()); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) +{ + return __c.rbegin(); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) +{ + return __c.rbegin(); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto rend(_Cp& __c) -> decltype(__c.rend()) +{ + return __c.rend(); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto rend(const _Cp& __c) -> decltype(__c.rend()) +{ + return __c.rend(); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto crbegin(const _Cp& __c) -> decltype(_CUDA_VSTD::rbegin(__c)) +{ + return _CUDA_VSTD::rbegin(__c); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto crend(const _Cp& __c) -> decltype(_CUDA_VSTD::rend(__c)) +{ + return _CUDA_VSTD::rend(__c); +} + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_REVERSE_ACCESS_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/reverse_iterator.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/reverse_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..75896e2f27ebd410131873901074d54c229afd80 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/reverse_iterator.h @@ -0,0 +1,186 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_REVERSE_ITERATOR_H +#define _LIBCUDACXX___ITERATOR_REVERSE_ITERATOR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/iterator.h" +#include "../__iterator/iterator_traits.h" +#include "../__memory/addressof.h" +#include "../__type_traits/void_t.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct __is_cpp17_stashing_iterator : false_type {}; + +template +struct __is_cpp17_stashing_iterator<_Tp, __void_t> + : true_type {}; + +_LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH +template +class _LIBCUDACXX_TEMPLATE_VIS reverse_iterator +#if _LIBCUDACXX_STD_VER <= 14 || !defined(_LIBCUDACXX_ABI_NO_ITERATOR_BASES) + : public iterator::iterator_category, + typename iterator_traits<_Iter>::value_type, + typename iterator_traits<_Iter>::difference_type, + typename iterator_traits<_Iter>::pointer, + typename iterator_traits<_Iter>::reference> +#endif +{ +_LIBCUDACXX_SUPPRESS_DEPRECATED_POP +private: + /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break + + static_assert(!__is_cpp17_stashing_iterator<_Iter>::value, + "The specified iterator type cannot be used with reverse_iterator; " + "Using stashing iterators with reverse_iterator causes undefined behavior"); + +protected: + _Iter current; +public: + typedef _Iter iterator_type; + typedef typename iterator_traits<_Iter>::difference_type difference_type; + typedef typename iterator_traits<_Iter>::reference reference; + typedef typename iterator_traits<_Iter>::pointer pointer; + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reverse_iterator() : __t(), current() {} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {} + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator=(const reverse_iterator<_Up>& __u) + { __t = current = __u.base(); return *this; } + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + _Iter base() const {return current;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reference operator*() const {_Iter __tmp = current; return *--__tmp;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + pointer operator->() const {return _CUDA_VSTD::addressof(operator*());} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator++() {--current; return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator--() {++current; return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 + reference operator[](difference_type __n) const {return *(*this + __n);} +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() == __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() > __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() != __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() < __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() <= __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +bool +operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() >= __y.base(); +} + +#ifndef _LIBCUDACXX_CXX03_LANG +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +auto +operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +-> decltype(__y.base() - __x.base()) +{ + return __y.base() - __x.base(); +} +#else +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename reverse_iterator<_Iter1>::difference_type +operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __y.base() - __x.base(); +} +#endif + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +reverse_iterator<_Iter> +operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) +{ + return reverse_iterator<_Iter>(__x.base() - __n); +} + +#if _LIBCUDACXX_STD_VER > 11 +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +reverse_iterator<_Iter> make_reverse_iterator(_Iter __i) +{ + return reverse_iterator<_Iter>(__i); +} +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_REVERSE_ITERATOR_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/size.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/size.h new file mode 100644 index 0000000000000000000000000000000000000000..9a976b5c2c958ec953baa2bcf1ce27ac8a619249 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/size.h @@ -0,0 +1,65 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_SIZE_H +#define _LIBCUDACXX___ITERATOR_SIZE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__type_traits/common_type.h" +#include "../__type_traits/make_signed.h" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 +template +_LIBCUDACXX_INLINE_VISIBILITY +constexpr auto size(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.size())) +-> decltype (__c.size()) +{ return __c.size(); } + +template +_LIBCUDACXX_INLINE_VISIBILITY +constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } +#endif // _LIBCUDACXX_STD_VER > 11 + +#if _LIBCUDACXX_STD_VER > 17 +template +_LIBCUDACXX_INLINE_VISIBILITY +constexpr auto ssize(const _Cont& __c) +_NOEXCEPT_(noexcept(static_cast>>(__c.size()))) +-> common_type_t> +{ return static_cast>>(__c.size()); } + +// GCC complains about the implicit conversion from ptrdiff_t to size_t in +// the array bound. +# if defined(_LIBCUDACXX_COMPILER_GCC) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wsign-conversion" +# endif // _LIBCUDACXX_COMPILER_GCC +template +_LIBCUDACXX_INLINE_VISIBILITY +constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; } +# if defined(_LIBCUDACXX_COMPILER_GCC) +# pragma GCC diagnostic pop +# endif // _LIBCUDACXX_COMPILER_GCC +#endif // _LIBCUDACXX_STD_VER > 17 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_SIZE_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/wrap_iter.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/wrap_iter.h new file mode 100644 index 0000000000000000000000000000000000000000..8896077685c9d494f77178f667d5b9aeeab8d262 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__iterator/wrap_iter.h @@ -0,0 +1,445 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_WRAP_ITER_H +#define _LIBCUDACXX___ITERATOR_WRAP_ITER_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__debug" +#include "../__iterator/iterator_traits.h" +#include "../__memory/addressof.h" +#include "../__memory/pointer_traits.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_trivially_copy_assignable.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + + +// __wrap_iter + +template class __wrap_iter; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +#ifndef _LIBCUDACXX_CXX03_LANG +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +auto +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +-> decltype(__x.base() - __y.base()); +#else +template +_LIBCUDACXX_INLINE_VISIBILITY +typename __wrap_iter<_Iter1>::difference_type +operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +#endif + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +__wrap_iter<_Iter> +operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT; + +template _Op _LIBCUDACXX_INLINE_VISIBILITY copy(_Ip, _Ip, _Op); +template _B2 _LIBCUDACXX_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2); +template _Op _LIBCUDACXX_INLINE_VISIBILITY move(_Ip, _Ip, _Op); +template _B2 _LIBCUDACXX_INLINE_VISIBILITY move_backward(_B1, _B1, _B2); + +#if _LIBCUDACXX_DEBUG_LEVEL < 2 + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +__enable_if_t +< + is_trivially_copy_assignable<_Tp>::value, + _Tp* +> +__unwrap_iter(__wrap_iter<_Tp*>); + +#else + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +__enable_if_t +< + is_trivially_copy_assignable<_Tp>::value, + __wrap_iter<_Tp*> +> +__unwrap_iter(__wrap_iter<_Tp*> __i); + +#endif + +template +class __wrap_iter +{ +public: + typedef _Iter iterator_type; + typedef typename iterator_traits::iterator_category iterator_category; + typedef typename iterator_traits::value_type value_type; + typedef typename iterator_traits::difference_type difference_type; + typedef typename iterator_traits::pointer pointer; + typedef typename iterator_traits::reference reference; +private: + iterator_type __i; +public: + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT +#if _LIBCUDACXX_STD_VER > 11 + : __i{} +#endif + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __get_db()->__insert_i(this); +#endif + } + template _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG + __wrap_iter(const __wrap_iter<_Up>& __u, + __enable_if_t::value>* = 0) _NOEXCEPT + : __i(__u.base()) + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __get_db()->__iterator_copy(this, &__u); +#endif + } +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG + __wrap_iter(const __wrap_iter& __x) + : __i(__x.base()) + { + __get_db()->__iterator_copy(this, &__x); + } + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG + __wrap_iter& operator=(const __wrap_iter& __x) + { + if (this != &__x) + { + __get_db()->__iterator_copy(this, &__x); + __i = __x.__i; + } + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG + ~__wrap_iter() + { + __get_db()->__erase_i(this); + } +#endif + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable iterator"); +#endif + return *__i; + } + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable iterator"); +#endif + return (pointer)_CUDA_VSTD::addressof(*__i); + } + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable iterator"); +#endif + ++__i; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT + {__wrap_iter __tmp(*this); ++(*this); return __tmp;} + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__decrementable(this), + "Attempted to decrement non-decrementable iterator"); +#endif + --__i; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT + {__wrap_iter __tmp(*this); --(*this); return __tmp;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT + {__wrap_iter __w(*this); __w += __n; return __w;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__addable(this, __n), + "Attempted to add/subtract iterator outside of valid range"); +#endif + __i += __n; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT + {return *this + (-__n);} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT + {*this += -__n; return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__subscriptable(this, __n), + "Attempted to subscript iterator outside of valid range"); +#endif + return __i[__n]; + } + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;} + +private: +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x) + { + __get_db()->__insert_ic(this, __p); + } +#else + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} +#endif + + template friend class __wrap_iter; + template friend class basic_string; + template friend class vector; + template friend class span; + + template + _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend + bool + operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend + bool + operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend + bool + operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend + bool + operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend + bool + operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend + bool + operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +#ifndef _LIBCUDACXX_CXX03_LANG + template + _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend + auto + operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT + -> decltype(__x.base() - __y.base()); +#else + template + _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend + typename __wrap_iter<_Iter1>::difference_type + operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +#endif + + template + _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend + __wrap_iter<_Iter1> + operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT; + + template _LIBCUDACXX_HOST_DEVICE friend _Op copy(_Ip, _Ip, _Op); + template _LIBCUDACXX_HOST_DEVICE friend _B2 copy_backward(_B1, _B1, _B2); + template _LIBCUDACXX_HOST_DEVICE friend _Op move(_Ip, _Ip, _Op); + template _LIBCUDACXX_HOST_DEVICE friend _B2 move_backward(_B1, _B1, _B2); + +#if _LIBCUDACXX_DEBUG_LEVEL < 2 + template + _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend + __enable_if_t + < + is_trivially_copy_assignable<_Tp>::value, + _Tp* + > + __unwrap_iter(__wrap_iter<_Tp*>); +#else + template + inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG + __enable_if_t + < + is_trivially_copy_assignable<_Tp>::value, + __wrap_iter<_Tp*> + > + __unwrap_iter(__wrap_iter<_Tp*> __i); +#endif +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return __x.base() == __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), + "Attempted to compare incomparable iterators"); +#endif + return __x.base() < __y.base(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return !(__x == __y); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return __y < __x; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return !(__x < __y); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return !(__y < __x); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +{ + return !(__x == __y); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +{ + return __y < __x; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +{ + return !(__x < __y); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +bool +operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +{ + return !(__y < __x); +} + +#ifndef _LIBCUDACXX_CXX03_LANG +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +auto +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +-> decltype(__x.base() - __y.base()) +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), + "Attempted to subtract incompatible iterators"); +#endif + return __x.base() - __y.base(); +} +#else +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +typename __wrap_iter<_Iter1>::difference_type +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), + "Attempted to subtract incompatible iterators"); +#endif + return __x.base() - __y.base(); +} +#endif + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +__wrap_iter<_Iter> +operator+(typename __wrap_iter<_Iter>::difference_type __n, + __wrap_iter<_Iter> __x) _NOEXCEPT +{ + __x += __n; + return __x; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_WRAP_ITER_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__libcpp_version b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__libcpp_version new file mode 100644 index 0000000000000000000000000000000000000000..5caff40c4a0ce4ed0dcb3aa983da623641af1b06 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__libcpp_version @@ -0,0 +1 @@ +10000 diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__locale b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__locale new file mode 100644 index 0000000000000000000000000000000000000000..2b2df18624efeafabfc2c79d676dd527083eaa70 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__locale @@ -0,0 +1,1553 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___LOCALE +#define _LIBCUDACXX___LOCALE + +#include <__config> +#include +#include +#include +#include +#include +#include +#include +#if defined(_LIBCUDACXX_MSVCRT_LIKE) +# include +# include +#elif defined(_AIX) +# include +#elif defined(__ANDROID__) +# include +#elif defined(__sun__) +# include +# include +#elif defined(_NEWLIB_VERSION) +# include +#elif (defined(__APPLE__) || defined(__FreeBSD__) \ + || defined(__EMSCRIPTEN__) || defined(__IBMCPP__)) +# include +#elif defined(__Fuchsia__) +# include +#elif defined(__wasi__) +// WASI libc uses musl's locales support. +# include +#elif defined(_LIBCUDACXX_HAS_MUSL_LIBC) +# include +#endif + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCUDACXX_LOCALE__L_EXTENSIONS) +struct __libcpp_locale_guard { + _LIBCUDACXX_INLINE_VISIBILITY + __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {} + + _LIBCUDACXX_INLINE_VISIBILITY + ~__libcpp_locale_guard() { + if (__old_loc_) + uselocale(__old_loc_); + } + + locale_t __old_loc_; +private: + __libcpp_locale_guard(__libcpp_locale_guard const&); + __libcpp_locale_guard& operator=(__libcpp_locale_guard const&); +}; +#elif defined(_LIBCUDACXX_MSVCRT_LIKE) +struct __libcpp_locale_guard { + __libcpp_locale_guard(locale_t __l) : + __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) { + // Setting the locale can be expensive even when the locale given is + // already the current locale, so do an explicit check to see if the + // current locale is already the one we want. + const char* __lc = __setlocale(nullptr); + // If every category is the same, the locale string will simply be the + // locale name, otherwise it will be a semicolon-separated string listing + // each category. In the second case, we know at least one category won't + // be what we want, so we only have to check the first case. + if (strcmp(__l.__get_locale(), __lc) != 0) { + __locale_all = _strdup(__lc); + if (__locale_all == nullptr) + __throw_bad_alloc(); + __setlocale(__l.__get_locale()); + } + } + ~__libcpp_locale_guard() { + // The CRT documentation doesn't explicitly say, but setlocale() does the + // right thing when given a semicolon-separated list of locale settings + // for the different categories in the same format as returned by + // setlocale(LC_ALL, nullptr). + if (__locale_all != nullptr) { + __setlocale(__locale_all); + free(__locale_all); + } + _configthreadlocale(__status); + } + static const char* __setlocale(const char* __locale) { + const char* __new_locale = setlocale(LC_ALL, __locale); + if (__new_locale == nullptr) + __throw_bad_alloc(); + return __new_locale; + } + int __status; + char* __locale_all = nullptr; +}; +#endif + + +class _LIBCUDACXX_TYPE_VIS locale; + +template +_LIBCUDACXX_INLINE_VISIBILITY +bool +has_facet(const locale&) _NOEXCEPT; + +template +_LIBCUDACXX_INLINE_VISIBILITY +const _Facet& +use_facet(const locale&); + +class _LIBCUDACXX_TYPE_VIS locale +{ +public: + // types: + class _LIBCUDACXX_TYPE_VIS facet; + class _LIBCUDACXX_TYPE_VIS id; + + typedef int category; + _LIBCUDACXX_AVAILABILITY_LOCALE_CATEGORY + static const category // values assigned here are for exposition only + none = 0, + collate = LC_COLLATE_MASK, + ctype = LC_CTYPE_MASK, + monetary = LC_MONETARY_MASK, + numeric = LC_NUMERIC_MASK, + time = LC_TIME_MASK, + messages = LC_MESSAGES_MASK, + all = collate | ctype | monetary | numeric | time | messages; + + // construct/copy/destroy: + locale() _NOEXCEPT; + locale(const locale&) _NOEXCEPT; + explicit locale(const char*); + explicit locale(const string&); + locale(const locale&, const char*, category); + locale(const locale&, const string&, category); + template + _LIBCUDACXX_INLINE_VISIBILITY locale(const locale&, _Facet*); + locale(const locale&, const locale&, category); + + ~locale(); + + const locale& operator=(const locale&) _NOEXCEPT; + + template + _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + locale combine(const locale&) const; + + // locale operations: + string name() const; + bool operator==(const locale&) const; + bool operator!=(const locale& __y) const {return !(*this == __y);} + template + _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + bool operator()(const basic_string<_CharT, _Traits, _Allocator>&, + const basic_string<_CharT, _Traits, _Allocator>&) const; + + // global locale objects: + static locale global(const locale&); + static const locale& classic(); + +private: + class __imp; + __imp* __locale_; + + void __install_ctor(const locale&, facet*, long); + static locale& __global(); + bool has_facet(id&) const; + const facet* use_facet(id&) const; + + template friend bool has_facet(const locale&) _NOEXCEPT; + template friend const _Facet& use_facet(const locale&); +}; + +class _LIBCUDACXX_TYPE_VIS locale::facet + : public __shared_count +{ +protected: + _LIBCUDACXX_INLINE_VISIBILITY + explicit facet(size_t __refs = 0) + : __shared_count(static_cast(__refs)-1) {} + + virtual ~facet(); + +// facet(const facet&) = delete; // effectively done in __shared_count +// void operator=(const facet&) = delete; +private: + virtual void __on_zero_shared() _NOEXCEPT; +}; + +class _LIBCUDACXX_TYPE_VIS locale::id +{ + once_flag __flag_; + int32_t __id_; + + static int32_t __next_id; +public: + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR id() :__id_(0) {} +private: + void __init(); + void operator=(const id&); // = delete; + id(const id&); // = delete; +public: // only needed for tests + long __get(); + + friend class locale; + friend class locale::__imp; +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +locale::locale(const locale& __other, _Facet* __f) +{ + __install_ctor(__other, __f, __f ? __f->id.__get() : 0); +} + +template +locale +locale::combine(const locale& __other) const +{ + if (!_CUDA_VSTD::has_facet<_Facet>(__other)) + __throw_runtime_error("locale::combine: locale missing facet"); + + return locale(*this, &const_cast<_Facet&>(_CUDA_VSTD::use_facet<_Facet>(__other))); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +has_facet(const locale& __l) _NOEXCEPT +{ + return __l.has_facet(_Facet::id); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +const _Facet& +use_facet(const locale& __l) +{ + return static_cast(*__l.use_facet(_Facet::id)); +} + +// template class collate; + +template +class _LIBCUDACXX_TEMPLATE_VIS collate + : public locale::facet +{ +public: + typedef _CharT char_type; + typedef basic_string string_type; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit collate(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCUDACXX_INLINE_VISIBILITY + int compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const + { + return do_compare(__lo1, __hi1, __lo2, __hi2); + } + + // FIXME(EricWF): The _LIBCUDACXX_ALWAYS_INLINE is needed on Windows to work + // around a dllimport bug that expects an external instantiation. + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_ALWAYS_INLINE + string_type transform(const char_type* __lo, const char_type* __hi) const + { + return do_transform(__lo, __hi); + } + + _LIBCUDACXX_INLINE_VISIBILITY + long hash(const char_type* __lo, const char_type* __hi) const + { + return do_hash(__lo, __hi); + } + + static locale::id id; + +protected: + ~collate(); + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const + {return string_type(__lo, __hi);} + virtual long do_hash(const char_type* __lo, const char_type* __hi) const; +}; + +template locale::id collate<_CharT>::id; + +template +collate<_CharT>::~collate() +{ +} + +template +int +collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const +{ + for (; __lo2 != __hi2; ++__lo1, ++__lo2) + { + if (__lo1 == __hi1 || *__lo1 < *__lo2) + return -1; + if (*__lo2 < *__lo1) + return 1; + } + return __lo1 != __hi1; +} + +template +long +collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const +{ + size_t __h = 0; + const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8; + const size_t __mask = size_t(0xF) << (__sr + 4); + for(const char_type* __p = __lo; __p != __hi; ++__p) + { + __h = (__h << 4) + static_cast(*__p); + size_t __g = __h & __mask; + __h ^= __g | (__g >> __sr); + } + return static_cast(__h); +} + +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS collate) +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS collate) + +// template class collate_byname; + +template class _LIBCUDACXX_TEMPLATE_VIS collate_byname; + +template <> +class _LIBCUDACXX_TYPE_VIS collate_byname + : public collate +{ + locale_t __l; +public: + typedef char char_type; + typedef basic_string string_type; + + explicit collate_byname(const char* __n, size_t __refs = 0); + explicit collate_byname(const string& __n, size_t __refs = 0); + +protected: + ~collate_byname(); + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; +}; + +template <> +class _LIBCUDACXX_TYPE_VIS collate_byname + : public collate +{ + locale_t __l; +public: + typedef wchar_t char_type; + typedef basic_string string_type; + + explicit collate_byname(const char* __n, size_t __refs = 0); + explicit collate_byname(const string& __n, size_t __refs = 0); + +protected: + ~collate_byname(); + + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; +}; + +template +bool +locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, + const basic_string<_CharT, _Traits, _Allocator>& __y) const +{ + return _CUDA_VSTD::use_facet<_CUDA_VSTD::collate<_CharT> >(*this).compare( + __x.data(), __x.data() + __x.size(), + __y.data(), __y.data() + __y.size()) < 0; +} + +// template class ctype + +class _LIBCUDACXX_TYPE_VIS ctype_base +{ +public: +#if defined(__GLIBC__) + typedef unsigned short mask; + static const mask space = _ISspace; + static const mask print = _ISprint; + static const mask cntrl = _IScntrl; + static const mask upper = _ISupper; + static const mask lower = _ISlower; + static const mask alpha = _ISalpha; + static const mask digit = _ISdigit; + static const mask punct = _ISpunct; + static const mask xdigit = _ISxdigit; + static const mask blank = _ISblank; +#if defined(__mips__) + static const mask __regex_word = static_cast(_ISbit(15)); +#else + static const mask __regex_word = 0x80; +#endif +#elif defined(_LIBCUDACXX_MSVCRT_LIKE) + typedef unsigned short mask; + static const mask space = _SPACE; + static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT; + static const mask cntrl = _CONTROL; + static const mask upper = _UPPER; + static const mask lower = _LOWER; + static const mask alpha = _ALPHA; + static const mask digit = _DIGIT; + static const mask punct = _PUNCT; + static const mask xdigit = _HEX; + static const mask blank = _BLANK; + static const mask __regex_word = 0x80; +# define _LIBCUDACXX_CTYPE_MASK_IS_COMPOSITE_PRINT +#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) +# ifdef __APPLE__ + typedef __uint32_t mask; +# elif defined(__FreeBSD__) + typedef unsigned long mask; +# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__) + typedef unsigned short mask; +# endif + static const mask space = _CTYPE_S; + static const mask print = _CTYPE_R; + static const mask cntrl = _CTYPE_C; + static const mask upper = _CTYPE_U; + static const mask lower = _CTYPE_L; + static const mask alpha = _CTYPE_A; + static const mask digit = _CTYPE_D; + static const mask punct = _CTYPE_P; + static const mask xdigit = _CTYPE_X; + +# if defined(__NetBSD__) + static const mask blank = _CTYPE_BL; + // NetBSD defines classes up to 0x2000 + // see sys/ctype_bits.h, _CTYPE_Q + static const mask __regex_word = 0x8000; +# else + static const mask blank = _CTYPE_B; + static const mask __regex_word = 0x80; +# endif +#elif defined(__sun__) || defined(_AIX) + typedef unsigned int mask; + static const mask space = _ISSPACE; + static const mask print = _ISPRINT; + static const mask cntrl = _ISCNTRL; + static const mask upper = _ISUPPER; + static const mask lower = _ISLOWER; + static const mask alpha = _ISALPHA; + static const mask digit = _ISDIGIT; + static const mask punct = _ISPUNCT; + static const mask xdigit = _ISXDIGIT; + static const mask blank = _ISBLANK; + static const mask __regex_word = 0x80; +#elif defined(_NEWLIB_VERSION) + // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h. + typedef char mask; + static const mask space = _S; + static const mask print = _P | _U | _L | _N | _B; + static const mask cntrl = _C; + static const mask upper = _U; + static const mask lower = _L; + static const mask alpha = _U | _L; + static const mask digit = _N; + static const mask punct = _P; + static const mask xdigit = _X | _N; + static const mask blank = _B; + static const mask __regex_word = 0x80; +# define _LIBCUDACXX_CTYPE_MASK_IS_COMPOSITE_PRINT +# define _LIBCUDACXX_CTYPE_MASK_IS_COMPOSITE_ALPHA +# define _LIBCUDACXX_CTYPE_MASK_IS_COMPOSITE_XDIGIT +#else + typedef unsigned long mask; + static const mask space = 1<<0; + static const mask print = 1<<1; + static const mask cntrl = 1<<2; + static const mask upper = 1<<3; + static const mask lower = 1<<4; + static const mask alpha = 1<<5; + static const mask digit = 1<<6; + static const mask punct = 1<<7; + static const mask xdigit = 1<<8; + static const mask blank = 1<<9; + static const mask __regex_word = 1<<10; +#endif + static const mask alnum = alpha | digit; + static const mask graph = alnum | punct; + + _LIBCUDACXX_INLINE_VISIBILITY ctype_base() {} +}; + +template class _LIBCUDACXX_TEMPLATE_VIS ctype; + +template <> +class _LIBCUDACXX_TYPE_VIS ctype + : public locale::facet, + public ctype_base +{ +public: + typedef wchar_t char_type; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit ctype(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCUDACXX_INLINE_VISIBILITY + bool is(mask __m, char_type __c) const + { + return do_is(__m, __c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const + { + return do_is(__low, __high, __vec); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const + { + return do_scan_is(__m, __low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const + { + return do_scan_not(__m, __low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type toupper(char_type __c) const + { + return do_toupper(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* toupper(char_type* __low, const char_type* __high) const + { + return do_toupper(__low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type tolower(char_type __c) const + { + return do_tolower(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* tolower(char_type* __low, const char_type* __high) const + { + return do_tolower(__low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type widen(char __c) const + { + return do_widen(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char* widen(const char* __low, const char* __high, char_type* __to) const + { + return do_widen(__low, __high, __to); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char narrow(char_type __c, char __dfault) const + { + return do_narrow(__c, __dfault); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const + { + return do_narrow(__low, __high, __dfault, __to); + } + + static locale::id id; + +protected: + ~ctype(); + virtual bool do_is(mask __m, char_type __c) const; + virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; + virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; + virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; + virtual char do_narrow(char_type, char __dfault) const; + virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; +}; + +template <> +class _LIBCUDACXX_TYPE_VIS ctype + : public locale::facet, public ctype_base +{ + const mask* __tab_; + bool __del_; +public: + typedef char char_type; + + explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0); + + _LIBCUDACXX_INLINE_VISIBILITY + bool is(mask __m, char_type __c) const + { + return isascii(__c) ? (__tab_[static_cast(__c)] & __m) !=0 : false; + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const + { + for (; __low != __high; ++__low, ++__vec) + *__vec = isascii(*__low) ? __tab_[static_cast(*__low)] : 0; + return __low; + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const + { + for (; __low != __high; ++__low) + if (isascii(*__low) && (__tab_[static_cast(*__low)] & __m)) + break; + return __low; + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const + { + for (; __low != __high; ++__low) + if (!(isascii(*__low) && (__tab_[static_cast(*__low)] & __m))) + break; + return __low; + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type toupper(char_type __c) const + { + return do_toupper(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* toupper(char_type* __low, const char_type* __high) const + { + return do_toupper(__low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type tolower(char_type __c) const + { + return do_tolower(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* tolower(char_type* __low, const char_type* __high) const + { + return do_tolower(__low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type widen(char __c) const + { + return do_widen(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char* widen(const char* __low, const char* __high, char_type* __to) const + { + return do_widen(__low, __high, __to); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char narrow(char_type __c, char __dfault) const + { + return do_narrow(__c, __dfault); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const + { + return do_narrow(__low, __high, __dfault, __to); + } + + static locale::id id; + +#ifdef _CACHED_RUNES + static const size_t table_size = _CACHED_RUNES; +#else + static const size_t table_size = 256; // FIXME: Don't hardcode this. +#endif + _LIBCUDACXX_INLINE_VISIBILITY const mask* table() const _NOEXCEPT {return __tab_;} + static const mask* classic_table() _NOEXCEPT; +#if defined(__GLIBC__) || defined(__EMSCRIPTEN__) + static const int* __classic_upper_table() _NOEXCEPT; + static const int* __classic_lower_table() _NOEXCEPT; +#endif +#if defined(__NetBSD__) + static const short* __classic_upper_table() _NOEXCEPT; + static const short* __classic_lower_table() _NOEXCEPT; +#endif + +protected: + ~ctype(); + virtual char_type do_toupper(char_type __c) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type __c) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char __c) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const; + virtual char do_narrow(char_type __c, char __dfault) const; + virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const; +}; + +// template class ctype_byname; + +template class _LIBCUDACXX_TEMPLATE_VIS ctype_byname; + +template <> +class _LIBCUDACXX_TYPE_VIS ctype_byname + : public ctype +{ + locale_t __l; + +public: + explicit ctype_byname(const char*, size_t = 0); + explicit ctype_byname(const string&, size_t = 0); + +protected: + ~ctype_byname(); + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; +}; + +template <> +class _LIBCUDACXX_TYPE_VIS ctype_byname + : public ctype +{ + locale_t __l; + +public: + explicit ctype_byname(const char*, size_t = 0); + explicit ctype_byname(const string&, size_t = 0); + +protected: + ~ctype_byname(); + virtual bool do_is(mask __m, char_type __c) const; + virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; + virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; + virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; + virtual char do_narrow(char_type, char __dfault) const; + virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isspace(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::space, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isprint(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::print, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +iscntrl(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::cntrl, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isupper(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::upper, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +islower(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::lower, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isalpha(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::alpha, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isdigit(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::digit, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +ispunct(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::punct, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isxdigit(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::xdigit, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isalnum(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::alnum, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isgraph(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::graph, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +_CharT +toupper(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).toupper(__c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +_CharT +tolower(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).tolower(__c); +} + +// codecvt_base + +class _LIBCUDACXX_TYPE_VIS codecvt_base +{ +public: + _LIBCUDACXX_INLINE_VISIBILITY codecvt_base() {} + enum result {ok, partial, error, noconv}; +}; + +// template class codecvt; + +template class _LIBCUDACXX_TEMPLATE_VIS codecvt; + +// template <> class codecvt + +template <> +class _LIBCUDACXX_TYPE_VIS codecvt + : public locale::facet, + public codecvt_base +{ +public: + typedef char intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCUDACXX_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template <> class codecvt + +template <> +class _LIBCUDACXX_TYPE_VIS codecvt + : public locale::facet, + public codecvt_base +{ + locale_t __l; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + explicit codecvt(size_t __refs = 0); + + _LIBCUDACXX_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + explicit codecvt(const char*, size_t __refs = 0); + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template <> class codecvt + +template <> +class _LIBCUDACXX_TYPE_VIS codecvt + : public locale::facet, + public codecvt_base +{ +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCUDACXX_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template <> class codecvt + +template <> +class _LIBCUDACXX_TYPE_VIS codecvt + : public locale::facet, + public codecvt_base +{ +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCUDACXX_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template class codecvt_byname + +template +class _LIBCUDACXX_TEMPLATE_VIS codecvt_byname + : public codecvt<_InternT, _ExternT, _StateT> +{ +public: + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt_byname(const char* __nm, size_t __refs = 0) + : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {} + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt_byname(const string& __nm, size_t __refs = 0) + : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {} +protected: + ~codecvt_byname(); +}; + +template +codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() +{ +} + +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) + +template +struct __narrow_to_utf8 +{ + template + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const; +}; + +template <> +struct __narrow_to_utf8<8> +{ + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + for (; __wb < __we; ++__wb, ++__s) + *__s = *__wb; + return __s; + } +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS __narrow_to_utf8<16> + : public codecvt +{ + _LIBCUDACXX_INLINE_VISIBILITY + __narrow_to_utf8() : codecvt(1) {} + + _LIBCUDACXX_EXPORTED_FROM_ABI ~__narrow_to_utf8(); + + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + result __r = ok; + mbstate_t __mb; + while (__wb < __we && __r != error) + { + const int __sz = 32; + char __buf[__sz]; + char* __bn; + const char16_t* __wn = (const char16_t*)__wb; + __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __wn == (const char16_t*)__wb) + __throw_runtime_error("locale not supported"); + for (const char* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = *__p; + __wb = (const _CharT*)__wn; + } + return __s; + } +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS __narrow_to_utf8<32> + : public codecvt +{ + _LIBCUDACXX_INLINE_VISIBILITY + __narrow_to_utf8() : codecvt(1) {} + + _LIBCUDACXX_EXPORTED_FROM_ABI ~__narrow_to_utf8(); + + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + result __r = ok; + mbstate_t __mb; + while (__wb < __we && __r != error) + { + const int __sz = 32; + char __buf[__sz]; + char* __bn; + const char32_t* __wn = (const char32_t*)__wb; + __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __wn == (const char32_t*)__wb) + __throw_runtime_error("locale not supported"); + for (const char* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = *__p; + __wb = (const _CharT*)__wn; + } + return __s; + } +}; + +template +struct __widen_from_utf8 +{ + template + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const; +}; + +template <> +struct __widen_from_utf8<8> +{ + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + for (; __nb < __ne; ++__nb, ++__s) + *__s = *__nb; + return __s; + } +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS __widen_from_utf8<16> + : public codecvt +{ + _LIBCUDACXX_INLINE_VISIBILITY + __widen_from_utf8() : codecvt(1) {} + + _LIBCUDACXX_EXPORTED_FROM_ABI ~__widen_from_utf8(); + + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + result __r = ok; + mbstate_t __mb; + while (__nb < __ne && __r != error) + { + const int __sz = 32; + char16_t __buf[__sz]; + char16_t* __bn; + const char* __nn = __nb; + __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __nn == __nb) + __throw_runtime_error("locale not supported"); + for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = (wchar_t)*__p; + __nb = __nn; + } + return __s; + } +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS __widen_from_utf8<32> + : public codecvt +{ + _LIBCUDACXX_INLINE_VISIBILITY + __widen_from_utf8() : codecvt(1) {} + + _LIBCUDACXX_EXPORTED_FROM_ABI ~__widen_from_utf8(); + + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + result __r = ok; + mbstate_t __mb; + while (__nb < __ne && __r != error) + { + const int __sz = 32; + char32_t __buf[__sz]; + char32_t* __bn; + const char* __nn = __nb; + __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __nn == __nb) + __throw_runtime_error("locale not supported"); + for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = (wchar_t)*__p; + __nb = __nn; + } + return __s; + } +}; + +// template class numpunct + +template class _LIBCUDACXX_TEMPLATE_VIS numpunct; + +template <> +class _LIBCUDACXX_TYPE_VIS numpunct + : public locale::facet +{ +public: + typedef char char_type; + typedef basic_string string_type; + + explicit numpunct(size_t __refs = 0); + + _LIBCUDACXX_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();} + _LIBCUDACXX_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();} + _LIBCUDACXX_INLINE_VISIBILITY string grouping() const {return do_grouping();} + _LIBCUDACXX_INLINE_VISIBILITY string_type truename() const {return do_truename();} + _LIBCUDACXX_INLINE_VISIBILITY string_type falsename() const {return do_falsename();} + + static locale::id id; + +protected: + ~numpunct(); + virtual char_type do_decimal_point() const; + virtual char_type do_thousands_sep() const; + virtual string do_grouping() const; + virtual string_type do_truename() const; + virtual string_type do_falsename() const; + + char_type __decimal_point_; + char_type __thousands_sep_; + string __grouping_; +}; + +template <> +class _LIBCUDACXX_TYPE_VIS numpunct + : public locale::facet +{ +public: + typedef wchar_t char_type; + typedef basic_string string_type; + + explicit numpunct(size_t __refs = 0); + + _LIBCUDACXX_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();} + _LIBCUDACXX_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();} + _LIBCUDACXX_INLINE_VISIBILITY string grouping() const {return do_grouping();} + _LIBCUDACXX_INLINE_VISIBILITY string_type truename() const {return do_truename();} + _LIBCUDACXX_INLINE_VISIBILITY string_type falsename() const {return do_falsename();} + + static locale::id id; + +protected: + ~numpunct(); + virtual char_type do_decimal_point() const; + virtual char_type do_thousands_sep() const; + virtual string do_grouping() const; + virtual string_type do_truename() const; + virtual string_type do_falsename() const; + + char_type __decimal_point_; + char_type __thousands_sep_; + string __grouping_; +}; + +// template class numpunct_byname + +template class _LIBCUDACXX_TEMPLATE_VIS numpunct_byname; + +template <> +class _LIBCUDACXX_TYPE_VIS numpunct_byname +: public numpunct +{ +public: + typedef char char_type; + typedef basic_string string_type; + + explicit numpunct_byname(const char* __nm, size_t __refs = 0); + explicit numpunct_byname(const string& __nm, size_t __refs = 0); + +protected: + ~numpunct_byname(); + +private: + void __init(const char*); +}; + +template <> +class _LIBCUDACXX_TYPE_VIS numpunct_byname +: public numpunct +{ +public: + typedef wchar_t char_type; + typedef basic_string string_type; + + explicit numpunct_byname(const char* __nm, size_t __refs = 0); + explicit numpunct_byname(const string& __nm, size_t __refs = 0); + +protected: + ~numpunct_byname(); + +private: + void __init(const char*); +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___LOCALE diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h new file mode 100644 index 0000000000000000000000000000000000000000..07fe2bdd55e285ee8c5379b92b107cc35de1f38b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h @@ -0,0 +1,240 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_COMPRESSED_PAIR_HPP +#define _LIBCUDACXX___MDSPAN_COMPRESSED_PAIR_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/macros.h" +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +#include "../__mdspan/no_unique_address.h" +#endif +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_empty.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +namespace __detail { + +// For no unique address emulation, this is the case taken when neither are empty. +// For real `[[no_unique_address]]`, this case is always taken. +template struct __compressed_pair { + _LIBCUDACXX_NO_UNIQUE_ADDRESS _Tp __t_val; + _LIBCUDACXX_NO_UNIQUE_ADDRESS _Up __u_val; + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp &__first() noexcept { return __t_val; } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__first() const noexcept { + return __t_val; + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up &__second() noexcept { return __u_val; } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up const &__second() const noexcept { + return __u_val; + } + + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair(__compressed_pair const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair(__compressed_pair &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair & + operator=(__compressed_pair const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair & + operator=(__compressed_pair &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~__compressed_pair() noexcept = default; + template + __MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_TLike &&__t, _ULike &&__u) + : __t_val((_TLike &&) __t), __u_val((_ULike &&) __u) {} +}; + +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + +// First empty. +template +struct __compressed_pair< + _Tp, _Up, + _CUDA_VSTD::enable_if_t<_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_empty, _Tp) && !_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_empty, _Up)>> + : private _Tp { + _Up __u_val; + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp &__first() noexcept { + return *static_cast<_Tp *>(this); + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__first() const noexcept { + return *static_cast<_Tp const *>(this); + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up &__second() noexcept { return __u_val; } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up const &__second() const noexcept { + return __u_val; + } + + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair(__compressed_pair const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair(__compressed_pair &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair & + operator=(__compressed_pair const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair & + operator=(__compressed_pair &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~__compressed_pair() noexcept = default; + template + __MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_TLike &&__t, _ULike &&__u) + : _Tp((_TLike &&) __t), __u_val((_ULike &&) __u) {} +}; + +// Second empty. +template +struct __compressed_pair< + _Tp, _Up, + _CUDA_VSTD::enable_if_t> + : private _Up { + _Tp __t_val; + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp &__first() noexcept { return __t_val; } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__first() const noexcept { + return __t_val; + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up &__second() noexcept { + return *static_cast<_Up *>(this); + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up const &__second() const noexcept { + return *static_cast<_Up const *>(this); + } + + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair(__compressed_pair const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair(__compressed_pair &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair & + operator=(__compressed_pair const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair & + operator=(__compressed_pair &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~__compressed_pair() noexcept = default; + + template + __MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_TLike &&__t, _ULike &&__u) + : _Up((_ULike &&) __u), __t_val((_TLike &&) __t) {} +}; + +// Both empty. +template +struct __compressed_pair< + _Tp, _Up, + _CUDA_VSTD::enable_if_t<_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_empty, _Tp) && _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_empty, _Up)>> + // We need to use the __no_unique_address_emulation wrapper here to avoid + // base class ambiguities. +#ifdef __MDSPAN_COMPILER_MSVC +// MSVC doesn't allow you to access public static member functions of a type +// when you *happen* to privately inherit from that type. + : protected __no_unique_address_emulation<_Tp, 0>, + protected __no_unique_address_emulation<_Up, 1> +#else + : private __no_unique_address_emulation<_Tp, 0>, + private __no_unique_address_emulation<_Up, 1> +#endif +{ + using __first_base_t = __no_unique_address_emulation<_Tp, 0>; + using __second_base_t = __no_unique_address_emulation<_Up, 1>; + + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp &__first() noexcept { + return this->__first_base_t::__ref(); + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__first() const noexcept { + return this->__first_base_t::__ref(); + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up &__second() noexcept { + return this->__second_base_t::__ref(); + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up const &__second() const noexcept { + return this->__second_base_t::__ref(); + } + + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair(__compressed_pair const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __compressed_pair(__compressed_pair &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair & + operator=(__compressed_pair const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair & + operator=(__compressed_pair &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~__compressed_pair() noexcept = default; + template + __MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_TLike &&__t, _ULike &&__u) noexcept + : __first_base_t(_Tp((_TLike &&) __t)), + __second_base_t(_Up((_ULike &&) __u)) + { } +}; + +#endif // !_LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + +} // end namespace __detail + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MDSPAN_COMPRESSED_PAIR_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/config.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/config.h new file mode 100644 index 0000000000000000000000000000000000000000..dc2de57dbd8b071e1507ff08e05ae79540f624cc --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/config.h @@ -0,0 +1,287 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_CONFIG_HPP +#define _LIBCUDACXX___MDSPAN_CONFIG_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if _LIBCUDACXX_STD_VER > 11 + +#ifndef __has_include +# define __has_include(x) 0 +#endif + +#ifndef __cuda_std__ +#if __has_include() +# include +#else +# include +# include +#endif +#endif + +#ifdef _MSVC_LANG +#define __MDSPAN_CPLUSPLUS _MSVC_LANG +#else +#define __MDSPAN_CPLUSPLUS __cplusplus +#endif + +#define __MDSPAN_CXX_STD_14 201402L +#define __MDSPAN_CXX_STD_17 201703L +#define __MDSPAN_CXX_STD_20 202002L + +#define __MDSPAN_HAS_CXX_14 (__MDSPAN_CPLUSPLUS >= __MDSPAN_CXX_STD_14) +#define __MDSPAN_HAS_CXX_17 (__MDSPAN_CPLUSPLUS >= __MDSPAN_CXX_STD_17) +#define __MDSPAN_HAS_CXX_20 (__MDSPAN_CPLUSPLUS >= __MDSPAN_CXX_STD_20) + +static_assert(__MDSPAN_CPLUSPLUS >= __MDSPAN_CXX_STD_14, "mdspan requires C++14 or later."); + +#ifndef __MDSPAN_COMPILER_CLANG +# if defined(__clang__) +# define __MDSPAN_COMPILER_CLANG __clang__ +# endif +#endif + +#if !defined(__MDSPAN_COMPILER_MSVC) && !defined(__MDSPAN_COMPILER_MSVC_CLANG) +# if defined(_MSC_VER) +# if !defined(__MDSPAN_COMPILER_CLANG) +# define __MDSPAN_COMPILER_MSVC _MSC_VER +# else +# define __MDSPAN_COMPILER_MSVC_CLANG _MSC_VER +# endif +# endif +#endif + +#ifndef __MDSPAN_COMPILER_INTEL +# ifdef __INTEL_COMPILER +# define __MDSPAN_COMPILER_INTEL __INTEL_COMPILER +# endif +#endif + +#ifndef __MDSPAN_COMPILER_APPLECLANG +# ifdef __apple_build_version__ +# define __MDSPAN_COMPILER_APPLECLANG __apple_build_version__ +# endif +#endif + +#ifndef __MDSPAN_HAS_CUDA +# if defined(__CUDACC__) +# define __MDSPAN_HAS_CUDA __CUDACC__ +# endif +#endif + +#ifndef __MDSPAN_HAS_HIP +# if defined(__HIPCC__) +# define __MDSPAN_HAS_HIP __HIPCC__ +# endif +#endif + +#ifndef __has_cpp_attribute +# define __has_cpp_attribute(x) 0 +#endif + +#ifndef __MDSPAN_PRESERVE_STANDARD_LAYOUT +// Preserve standard layout by default, but we're not removing the old version +// that turns this off until we're sure this doesn't have an unreasonable cost +// to the compiler or optimizer. +# define __MDSPAN_PRESERVE_STANDARD_LAYOUT 1 +#endif + +#ifndef __MDSPAN_USE_CONCEPTS +// Looks like concepts doesn't work in CUDA 12 +# if defined(__cpp_concepts) && __cpp_concepts >= 201507L && !defined __cuda_std__ +# define __MDSPAN_USE_CONCEPTS 1 +# endif +#endif + +#ifndef __MDSPAN_USE_FOLD_EXPRESSIONS +# if (defined(__cpp_fold_expressions) && __cpp_fold_expressions >= 201603L) \ + || (!defined(__cpp_fold_expressions) && __MDSPAN_HAS_CXX_17) +# define __MDSPAN_USE_FOLD_EXPRESSIONS 1 +# endif +#endif + +#ifndef __MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS +# if (!(defined(__cpp_lib_type_trait_variable_templates) && __cpp_lib_type_trait_variable_templates >= 201510L) \ + || !__MDSPAN_HAS_CXX_17) +# if !(defined(__MDSPAN_COMPILER_APPLECLANG) && __MDSPAN_HAS_CXX_17) +# define __MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS 1 +# endif +# endif +#endif + +#ifndef __MDSPAN_USE_VARIABLE_TEMPLATES +# if (defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 && __MDSPAN_HAS_CXX_17) \ + || (!defined(__cpp_variable_templates) && __MDSPAN_HAS_CXX_17) +# define __MDSPAN_USE_VARIABLE_TEMPLATES 1 +# endif +#endif // __MDSPAN_USE_VARIABLE_TEMPLATES + +#ifndef __MDSPAN_USE_CONSTEXPR_14 +# if (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) \ + || (!defined(__cpp_constexpr) && __MDSPAN_HAS_CXX_14) \ + && (!(defined(__INTEL_COMPILER) && __INTEL_COMPILER <= 1700)) +# define __MDSPAN_USE_CONSTEXPR_14 1 +# endif +#endif + +#ifndef __MDSPAN_USE_INTEGER_SEQUENCE +# if defined(__MDSPAN_COMPILER_MSVC) +# if (defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304) +# define __MDSPAN_USE_INTEGER_SEQUENCE 1 +# endif +# endif +#endif +#ifndef __MDSPAN_USE_INTEGER_SEQUENCE +# if (defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304) \ + || (!defined(__cpp_lib_integer_sequence) && __MDSPAN_HAS_CXX_14) \ + /* as far as I can tell, libc++ seems to think this is a C++11 feature... */ \ + || (defined(__GLIBCXX__) && __GLIBCXX__ > 20150422 && __GNUC__ < 5 && !defined(__INTEL_CXX11_MODE__)) + // several compilers lie about integer_sequence working properly unless the C++14 standard is used +# define __MDSPAN_USE_INTEGER_SEQUENCE 1 +# elif defined(__MDSPAN_COMPILER_APPLECLANG) && __MDSPAN_HAS_CXX_14 + // appleclang seems to be missing the __cpp_lib_... macros, but doesn't seem to lie about C++14 making + // integer_sequence work +# define __MDSPAN_USE_INTEGER_SEQUENCE 1 +# endif +#endif + +#ifndef __MDSPAN_USE_RETURN_TYPE_DEDUCTION +# if (defined(__cpp_return_type_deduction) && __cpp_return_type_deduction >= 201304) \ + || (!defined(__cpp_return_type_deduction) && __MDSPAN_HAS_CXX_14) +# define __MDSPAN_USE_RETURN_TYPE_DEDUCTION 1 +# endif +#endif + +#ifndef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION +// GCC 10 is known not to work with CTAD for this case. +# if (defined(__MDSPAN_COMPILER_CLANG) || !defined(_LIBCUDACXX_COMPILER_GCC) || __GNUC__ >= 11) \ + && ((defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201703) \ + || (!defined(__cpp_deduction_guides) && __MDSPAN_HAS_CXX_17)) +# define __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1 +# endif +#endif + +#ifndef __MDSPAN_USE_ALIAS_TEMPLATE_ARGUMENT_DEDUCTION +// GCC 10 is known not to work with CTAD for this case. +# if (defined(__MDSPAN_COMPILER_CLANG) || !defined(_LIBCUDACXX_COMPILER_GCC) || __GNUC__ >= 11) \ + && ((defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201907) \ + || (!defined(__cpp_deduction_guides) && __MDSPAN_HAS_CXX_20)) +# define __MDSPAN_USE_ALIAS_TEMPLATE_ARGUMENT_DEDUCTION 1 +# endif +#endif + +#ifndef __MDSPAN_USE_STANDARD_TRAIT_ALIASES +# if (defined(__cpp_lib_transformation_trait_aliases) && __cpp_lib_transformation_trait_aliases >= 201304) \ + || (!defined(__cpp_lib_transformation_trait_aliases) && __MDSPAN_HAS_CXX_14) +# define __MDSPAN_USE_STANDARD_TRAIT_ALIASES 1 +# elif defined(__MDSPAN_COMPILER_APPLECLANG) && __MDSPAN_HAS_CXX_14 + // appleclang seems to be missing the __cpp_lib_... macros, but doesn't seem to lie about C++14 +# define __MDSPAN_USE_STANDARD_TRAIT_ALIASES 1 +# endif +#endif + +#ifndef __MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND +# ifdef __GNUC__ +# if __GNUC__ < 9 +# define __MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND 1 +# endif +# endif +#endif + +#ifndef __MDSPAN_CONDITIONAL_EXPLICIT +# if __MDSPAN_HAS_CXX_20 && !defined(__MDSPAN_COMPILER_MSVC) +# define __MDSPAN_CONDITIONAL_EXPLICIT(COND) explicit(COND) +# else +# define __MDSPAN_CONDITIONAL_EXPLICIT(COND) +# endif +#endif + +#ifndef __MDSPAN_USE_BRACKET_OPERATOR +# if defined(__cpp_multidimensional_subscript) +# define __MDSPAN_USE_BRACKET_OPERATOR 1 +# else +# define __MDSPAN_USE_BRACKET_OPERATOR 0 +# endif +#endif + +#ifndef __MDSPAN_USE_PAREN_OPERATOR +# if !__MDSPAN_USE_BRACKET_OPERATOR +# define __MDSPAN_USE_PAREN_OPERATOR 1 +# else +# define __MDSPAN_USE_PAREN_OPERATOR 0 +# endif +#endif + +#if __MDSPAN_USE_BRACKET_OPERATOR +# define __MDSPAN_OP(mds,...) mds[__VA_ARGS__] +// Corentins demo compiler for subscript chokes on empty [] call, +// though I believe the proposal supports it? +#ifdef __MDSPAN_NO_EMPTY_BRACKET_OPERATOR +# define __MDSPAN_OP0(mds) mds.accessor().access(mds.data_handle(),0) +#else +# define __MDSPAN_OP0(mds) mds[] +#endif +# define __MDSPAN_OP1(mds, a) mds[a] +# define __MDSPAN_OP2(mds, a, b) mds[a,b] +# define __MDSPAN_OP3(mds, a, b, c) mds[a,b,c] +# define __MDSPAN_OP4(mds, a, b, c, d) mds[a,b,c,d] +# define __MDSPAN_OP5(mds, a, b, c, d, e) mds[a,b,c,d,e] +# define __MDSPAN_OP6(mds, a, b, c, d, e, f) mds[a,b,c,d,e,f] +#else +# define __MDSPAN_OP(mds,...) mds(__VA_ARGS__) +# define __MDSPAN_OP0(mds) mds() +# define __MDSPAN_OP1(mds, a) mds(a) +# define __MDSPAN_OP2(mds, a, b) mds(a,b) +# define __MDSPAN_OP3(mds, a, b, c) mds(a,b,c) +# define __MDSPAN_OP4(mds, a, b, c, d) mds(a,b,c,d) +# define __MDSPAN_OP5(mds, a, b, c, d, e) mds(a,b,c,d,e) +# define __MDSPAN_OP6(mds, a, b, c, d, e, f) mds(a,b,c,d,e,f) +#endif + +#endif // _LIBCUDACXX_STD_VER > 11 + +#endif // _LIBCUDACXX___MDSPAN_CONFIG_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h new file mode 100644 index 0000000000000000000000000000000000000000..45f87823de1bc59df426b1555e8ec06d8ee67b47 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h @@ -0,0 +1,99 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_DEFAULT_ACCESSOR_HPP +#define _LIBCUDACXX___MDSPAN_DEFAULT_ACCESSOR_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/macros.h" +#include "../__type_traits/is_convertible.h" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +template +struct default_accessor { + + using offset_policy = default_accessor; + using element_type = _ElementType; + using reference = _ElementType&; + using data_handle_type = _ElementType*; + + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr default_accessor() noexcept = default; + + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherElementType, + /* requires */ ( + _LIBCUDACXX_TRAIT(is_convertible, _OtherElementType(*)[], element_type(*)[]) + ) + ) + __MDSPAN_INLINE_FUNCTION + constexpr default_accessor(default_accessor<_OtherElementType>) noexcept {} + + __MDSPAN_INLINE_FUNCTION + constexpr data_handle_type + offset(data_handle_type __p, size_t __i) const noexcept { + return __p + __i; + } + + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr reference access(data_handle_type __p, size_t __i) const noexcept { + return __p[__i]; + } + +}; + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MDSPAN_DEFAULT_ACCESSOR_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h new file mode 100644 index 0000000000000000000000000000000000000000..0fb760c9f2deaa0a4af6f1c308e9ab12e67d43a3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h @@ -0,0 +1,83 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_DYNAMIC_EXTENT_HPP +#define _LIBCUDACXX___MDSPAN_DYNAMIC_EXTENT_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__fwd/span.h" // dynamic_extent +#include "../__mdspan/macros.h" +#include "../cstddef" +#include "../limits" // numeric_limits + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +namespace __detail { + +template +_LIBCUDACXX_HOST_DEVICE constexpr auto __make_dynamic_extent() { + return dynamic_extent; +} + +template +_LIBCUDACXX_HOST_DEVICE constexpr auto __make_dynamic_extent_integral() { + return dynamic_extent; +} + +} // end namespace __detail + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +//============================================================================================================== + +#endif // _LIBCUDACXX___MDSPAN_DYNAMIC_EXTENT_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/extents.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/extents.h new file mode 100644 index 0000000000000000000000000000000000000000..1f82f3a3895d5256f86abf7b7e1b9983d558b0a3 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/extents.h @@ -0,0 +1,579 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_EXTENTS_HPP +#define _LIBCUDACXX___MDSPAN_EXTENTS_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/macros.h" +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +#include "../__mdspan/no_unique_address.h" +#endif +#include "../__mdspan/static_array.h" +#include "../__mdspan/standard_layout_static_array.h" +#include "../__type_traits/conditional.h" +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__type_traits/make_unsigned.h" +#include "../__utility/integer_sequence.h" +#include "../array" +#include "../cstddef" +#include "../span" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if defined(_LIBCUDACXX_PUSH_MACROS) + _LIBCUDACXX_PUSH_MACROS +#endif +#include "../__undef_macros" + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +namespace __detail { + +template +struct __count_dynamic_extents; + +template +struct __count_dynamic_extents<_Ep,_Extents...> { + static constexpr size_t val = (_Ep==dynamic_extent?1:0) + __count_dynamic_extents<_Extents...>::val; +}; + +template<> +struct __count_dynamic_extents<> { + static constexpr size_t val = 0; +}; + +template +_LIBCUDACXX_HOST_DEVICE +static constexpr false_type __check_compatible_extents( + false_type, _CUDA_VSTD::integer_sequence, _CUDA_VSTD::integer_sequence +) noexcept { return { }; } + +// This helper prevents ICE's on MSVC. +template +struct __compare_extent_compatible : integral_constant +{}; + +template +static integral_constant< + bool, + __MDSPAN_FOLD_AND( + ( + __compare_extent_compatible<_Extents, _OtherExtents>::value + ) /* && ... */ + ) +> +_LIBCUDACXX_HOST_DEVICE +__check_compatible_extents( + true_type, _CUDA_VSTD::integer_sequence, _CUDA_VSTD::integer_sequence +) noexcept { return { }; } + +struct __extents_tag { }; + +} // end namespace __detail + +template +class extents +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : private __detail::__no_unique_address_emulation< + __detail::__partially_static_sizes_tagged<__detail::__extents_tag, _ThisIndexType , size_t, _Extents...>> +#endif +{ +public: + + using rank_type = size_t; + using index_type = _ThisIndexType; + using size_type = make_unsigned_t; + +// internal typedefs which for technical reasons are public + using __storage_t = __detail::__partially_static_sizes_tagged<__detail::__extents_tag, index_type, size_t, _Extents...>; + +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + _LIBCUDACXX_NO_UNIQUE_ADDRESS __storage_t __storage_; +#else + using __base_t = __detail::__no_unique_address_emulation<__storage_t>; +#endif + +// private members dealing with the way we internally store dynamic extents + private: + + __MDSPAN_FORCE_INLINE_FUNCTION constexpr + __storage_t& __storage() noexcept { +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + return __storage_; +#else + return this->__base_t::__ref(); +#endif + } + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr __storage_t const& __storage() const noexcept { +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + return __storage_; +#else + return this->__base_t::__ref(); +#endif + } + + template + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr + index_type _static_extent_impl(size_t __n, _CUDA_VSTD::integer_sequence) noexcept { + return __MDSPAN_FOLD_PLUS_RIGHT(((_Idxs == __n) ? _Extents : 0), /* + ... + */ 0); + } + + template + friend class extents; + + template + __MDSPAN_INLINE_FUNCTION + constexpr bool _eq_impl(_CUDA_VSTD::extents<_OtherIndexType, _OtherExtents...>, false_type, _CUDA_VSTD::index_sequence<_Idxs...>) const noexcept { return false; } + template + __MDSPAN_INLINE_FUNCTION + constexpr bool _eq_impl( + _CUDA_VSTD::extents<_OtherIndexType, _OtherExtents...> __other, + true_type, _CUDA_VSTD::index_sequence<_Idxs...> + ) const noexcept { + return __MDSPAN_FOLD_AND( + (__storage().template __get_n<_Idxs>() == __other.__storage().template __get_n<_Idxs>()) /* && ... */ + ); + } + + template + __MDSPAN_INLINE_FUNCTION + constexpr bool _not_eq_impl(_CUDA_VSTD::extents<_OtherIndexType, _OtherExtents...>, false_type, _CUDA_VSTD::index_sequence<_Idxs...>) const noexcept { return true; } + template + __MDSPAN_INLINE_FUNCTION + constexpr bool _not_eq_impl( + _CUDA_VSTD::extents<_OtherIndexType, _OtherExtents...> __other, + true_type, _CUDA_VSTD::index_sequence<_Idxs...> + ) const noexcept { + return __MDSPAN_FOLD_OR( + (__storage().template __get_n<_Idxs>() != __other.__storage().template __get_n<_Idxs>()) /* || ... */ + ); + } + +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + __MDSPAN_INLINE_FUNCTION constexpr explicit + extents(__base_t&& __b) noexcept + : __base_t(_CUDA_VSTD::move(__b)) + { } +#endif + + +// public interface: +public: + /* Defined above for use in the private code + using rank_type = size_t; + using index_type = _ThisIndexType; + */ + + __MDSPAN_INLINE_FUNCTION + static constexpr rank_type rank() noexcept { return sizeof...(_Extents); } + __MDSPAN_INLINE_FUNCTION + static constexpr rank_type rank_dynamic() noexcept { return __MDSPAN_FOLD_PLUS_RIGHT((rank_type(_Extents == dynamic_extent)), /* + ... + */ 0); } + + //-------------------------------------------------------------------------------- + // Constructors, Destructors, and Assignment + + // Default constructor + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents() noexcept = default; + + // Converting constructor + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherIndexType, size_t... _OtherExtents, + /* requires */ ( + /* multi-stage check to protect from invalid pack expansion when sizes don't match? */ + decltype(__detail::__check_compatible_extents( + integral_constant{}, + _CUDA_VSTD::integer_sequence{}, + _CUDA_VSTD::integer_sequence{} + ))::value + ) + ) + __MDSPAN_INLINE_FUNCTION + __MDSPAN_CONDITIONAL_EXPLICIT( + (((_Extents != dynamic_extent) && (_OtherExtents == dynamic_extent)) || ...) || + (_CUDA_VSTD::numeric_limits::max() < _CUDA_VSTD::numeric_limits<_OtherIndexType>::max())) + constexpr extents(const extents<_OtherIndexType, _OtherExtents...>& __other) + noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __storage_{ +#else + : __base_t(__base_t{__storage_t{ +#endif + __other.__storage().__enable_psa_conversion() +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + }}) +#endif + { + /* TODO: precondition check + * __other.extent(r) equals Er for each r for which Er is a static extent, and + * either + * - sizeof...(_OtherExtents) is zero, or + * - __other.extent(r) is a representable value of type index_type for all rank index r of __other + */ + } + +#ifdef __NVCC__ + __MDSPAN_TEMPLATE_REQUIRES( + class... _Integral, + /* requires */ ( + // TODO: check whether the other version works with newest NVCC, doesn't with 11.4 + // NVCC seems to pick up rank_dynamic from the wrong extents type??? + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _Integral, index_type) /* && ... */) && + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _Integral) /* && ... */) && + // NVCC chokes on the fold thingy here so wrote the workaround + ((sizeof...(_Integral) == __detail::__count_dynamic_extents<_Extents...>::val) || + (sizeof...(_Integral) == sizeof...(_Extents))) + ) + ) +#else + __MDSPAN_TEMPLATE_REQUIRES( + class... _Integral, + /* requires */ ( + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _Integral, index_type) /* && ... */) && + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _Integral) /* && ... */) && + ((sizeof...(_Integral) == rank_dynamic()) || (sizeof...(_Integral) == rank())) + ) + ) +#endif + __MDSPAN_INLINE_FUNCTION + explicit constexpr extents(_Integral... __exts) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __storage_{ +#else + : __base_t(__base_t{typename __base_t::__stored_type{ +#endif + _CUDA_VSTD::conditional_t(), + static_cast(__exts)... +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + }}) +#endif + { + /* TODO: precondition check + * If sizeof...(_IndexTypes) != rank_dynamic() is true, exts_arr[r] equals Er for each r for which Er is a static extent, and + * either + * - sizeof...(__exts) == 0 is true, or + * - each element of __exts is nonnegative and is a representable value of type index_type. + */ + } + + // TODO: check whether this works with newest NVCC, doesn't with 11.4 +#ifdef __NVCC__ + // NVCC seems to pick up rank_dynamic from the wrong extents type??? + // NVCC chokes on the fold thingy here so wrote the workaround + __MDSPAN_TEMPLATE_REQUIRES( + class _IndexType, size_t _Np, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _IndexType, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _IndexType) && + ((_Np == __detail::__count_dynamic_extents<_Extents...>::val) || + (_Np == sizeof...(_Extents))) + ) + ) +#else + __MDSPAN_TEMPLATE_REQUIRES( + class _IndexType, size_t _Np, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _IndexType, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _IndexType) && + (_Np == rank() || _Np == rank_dynamic()) + ) + ) +#endif + __MDSPAN_CONDITIONAL_EXPLICIT(_Np != rank_dynamic()) + __MDSPAN_INLINE_FUNCTION + constexpr + extents(_CUDA_VSTD::array<_IndexType, _Np> const& __exts) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __storage_{ +#else + : __base_t(__base_t{typename __base_t::__stored_type{ +#endif + _CUDA_VSTD::conditional_t<_Np==rank_dynamic(), + __detail::__construct_psa_from_dynamic_exts_array_tag_t<0>, + __detail::__construct_psa_from_all_exts_array_tag_t>(), + _CUDA_VSTD::array<_IndexType,_Np>{__exts} +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + }}) +#endif + { + /* TODO: precondition check + * If _Np != rank_dynamic() is true, __exts[r] equals Er for each r for which Er is a static extent, and + * either + * - _Np is zero, or + * - __exts[r] is nonnegative and is a representable value of type index_type for all rank index r + */ + } + + // TODO: check whether the below works with newest NVCC, doesn't with 11.4 +#ifdef __NVCC__ + // NVCC seems to pick up rank_dynamic from the wrong extents type??? + // NVCC chokes on the fold thingy here so wrote the workaround + __MDSPAN_TEMPLATE_REQUIRES( + class _IndexType, size_t _Np, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _IndexType, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _IndexType) && + ((_Np == __detail::__count_dynamic_extents<_Extents...>::val) || + (_Np == sizeof...(_Extents))) + ) + ) +#else + __MDSPAN_TEMPLATE_REQUIRES( + class _IndexType, size_t _Np, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _IndexType, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _IndexType) && + (_Np == rank() || _Np == rank_dynamic()) + ) + ) +#endif + __MDSPAN_CONDITIONAL_EXPLICIT(_Np != rank_dynamic()) + __MDSPAN_INLINE_FUNCTION + constexpr + extents(_CUDA_VSTD::span<_IndexType, _Np> __exts) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __storage_{ +#else + : __base_t(__base_t{typename __base_t::__stored_type{ +#endif + _CUDA_VSTD::conditional_t<_Np==rank_dynamic(), + __detail::__construct_psa_from_dynamic_exts_array_tag_t<0>, + __detail::__construct_psa_from_all_exts_array_tag_t>(), + __exts +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + }}) +#endif + { + /* TODO: precondition check + * If _Np != rank_dynamic() is true, __exts[r] equals Er for each r for which Er is a static extent, and + * either + * - _Np is zero, or + * - __exts[r] is nonnegative and is a representable value of type index_type for all rank index r + */ + } + + // Need this constructor for some submdspan implementation stuff + // for the layout_stride case where I use an extents object for strides + __MDSPAN_INLINE_FUNCTION + constexpr explicit + extents(__storage_t const& __sto ) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __storage_{ +#else + : __base_t(__base_t{ +#endif + __sto +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + }) +#endif + { } + + //-------------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION + static constexpr + size_t static_extent(size_t __n) noexcept { + // Can't do assert here since that breaks true constexpr ness + // assert(__n{}); + } + + __MDSPAN_INLINE_FUNCTION + constexpr + index_type extent(size_t __n) const noexcept { + // Can't do assert here since that breaks true constexpr ness + // assert(__n + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator==(extents const& lhs, extents<_OtherIndexType, _RHS...> const& __rhs) noexcept { + return lhs._eq_impl( + __rhs, integral_constant{}, + _CUDA_VSTD::make_index_sequence{} + ); + } + +#if !(__MDSPAN_HAS_CXX_20) + template + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator!=(extents const& lhs, extents<_OtherIndexType, _RHS...> const& __rhs) noexcept { + return lhs._not_eq_impl( + __rhs, integral_constant{}, + _CUDA_VSTD::make_index_sequence{} + ); + } +#endif + + // End of public interface + +public: // (but not really) + + __MDSPAN_INLINE_FUNCTION static constexpr + extents __make_extents_impl(__detail::__partially_static_sizes&& __bs) noexcept { + // This effectively amounts to a sideways cast that can be done in a constexpr + // context, but we have to do it to handle the case where the extents and the + // strides could accidentally end up with the same types in their hierarchies + // somehow (which would cause layout_stride::mapping to not be standard_layout) + return extents( +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + __base_t{ +#endif + _CUDA_VSTD::move(__bs.template __with_tag<__detail::__extents_tag>()) +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#endif + ); + } + + template + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr + index_type __extent() const noexcept { + return __storage().template __get_n<_Np>(); + } + + template + __MDSPAN_INLINE_FUNCTION + static constexpr + index_type __static_extent() noexcept { + return __storage_t::template __get_static_n<_Np, _Default>(); + } + +}; + +namespace __detail { + +template > +struct __make_dextents; + +template +struct __make_dextents<_IndexType, _Rank, _CUDA_VSTD::extents<_IndexType, _ExtentsPack...>> { + using type = typename __make_dextents<_IndexType, _Rank - 1, + _CUDA_VSTD::extents<_IndexType, _CUDA_VSTD::dynamic_extent, _ExtentsPack...>>::type; +}; + +template +struct __make_dextents<_IndexType, 0, _CUDA_VSTD::extents<_IndexType, _ExtentsPack...>> { + using type = _CUDA_VSTD::extents<_IndexType, _ExtentsPack...>; +}; + +} // end namespace __detail + +template +using dextents = typename __detail::__make_dextents<_IndexType, _Rank>::type; + +#if defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) +template +extents(_IndexTypes...) + // Workaround for nvcc + //-> extents()...>; + // Adding "(void)" so that clang doesn't complain this is unused + -> extents; +#endif + +namespace __detail { + +template +struct __is_extents : false_type {}; + +template +struct __is_extents<_CUDA_VSTD::extents<_IndexType, _ExtentsPack...>> : true_type {}; + +template +static constexpr bool __is_extents_v = __is_extents<_Tp>::value; + + +template +struct __extents_to_partially_static_sizes; + +template +struct __extents_to_partially_static_sizes<_CUDA_VSTD::extents<_IndexType, _ExtentsPack...>> { + using type = __detail::__partially_static_sizes< + typename _CUDA_VSTD::extents<_IndexType, _ExtentsPack...>::index_type, size_t, + _ExtentsPack...>; +}; + +template +using __extents_to_partially_static_sizes_t = typename __extents_to_partially_static_sizes<_Extents>::type; + +} // end namespace __detail + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#if defined(_LIBCUDACXX_POP_MACROS) + _LIBCUDACXX_POP_MACROS +#endif + +#endif // _LIBCUDACXX___MDSPAN_EXTENTS_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h new file mode 100644 index 0000000000000000000000000000000000000000..294ba6c6af883f15bcbbcc5d6caf4b0c706ab2f7 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h @@ -0,0 +1,69 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_FULL_EXTENT_T_HPP +#define _LIBCUDACXX___MDSPAN_FULL_EXTENT_T_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/macros.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +struct full_extent_t { explicit full_extent_t() = default; }; + +_LIBCUDACXX_INLINE_VAR constexpr auto full_extent = full_extent_t{ }; + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MDSPAN_FULL_EXTENT_T_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h new file mode 100644 index 0000000000000000000000000000000000000000..c9d446b8c8446a0631b819ebd2afe20f33af0d03 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h @@ -0,0 +1,270 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_LAYOUT_LEFT_HPP +#define _LIBCUDACXX___MDSPAN_LAYOUT_LEFT_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__assert" +#include "../__mdspan/extents.h" +#include "../__mdspan/macros.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__utility/integer_sequence.h" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +//============================================================================== + +template +class layout_left::mapping { + public: + using extents_type = _Extents; + using index_type = typename extents_type::index_type; + using size_type = typename extents_type::size_type; + using rank_type = typename extents_type::rank_type; + using layout_type = layout_left; + private: + + static_assert(__detail::__is_extents_v, "layout_left::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); + + template + friend class mapping; + + // i0+(i1 + E(1)*(i2 + E(2)*i3)) + template + struct __rank_count {}; + + template + _LIBCUDACXX_HOST_DEVICE + constexpr index_type __compute_offset( + __rank_count<_r,_Rank>, const _Ip& __i, _Indices... __idx) const { + return __compute_offset(__rank_count<_r+1,_Rank>(), __idx...) * + __extents.template __extent<_r>() + __i; + } + + template + _LIBCUDACXX_HOST_DEVICE + constexpr index_type __compute_offset( + __rank_count, const _Ip& __i) const { + return __i; + } + + _LIBCUDACXX_HOST_DEVICE + constexpr index_type __compute_offset(__rank_count<0,0>) const { return 0; } + + public: + + //-------------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping(mapping const&) noexcept = default; + + _LIBCUDACXX_HOST_DEVICE + constexpr mapping(extents_type const& __exts) noexcept + :__extents(__exts) + { } + + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherExtents, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, extents_type, _OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!_CUDA_VSTD::is_convertible<_OtherExtents, extents_type>::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION constexpr + mapping(mapping<_OtherExtents> const& __other) noexcept // NOLINT(google-explicit-constructor) + :__extents(__other.extents()) + { + /* + * TODO: check precondition + * __other.required_span_size() is a representable value of type index_type + */ + } + + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherExtents, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, extents_type, _OtherExtents) && + (extents_type::rank() <= 1) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!_CUDA_VSTD::is_convertible<_OtherExtents, extents_type>::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION constexpr + mapping(layout_right::mapping<_OtherExtents> const& __other) noexcept // NOLINT(google-explicit-constructor) + :__extents(__other.extents()) + { + /* + * TODO: check precondition + * __other.required_span_size() is a representable value of type index_type + */ + } + + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherExtents, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, extents_type, _OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((extents_type::rank() > 0)) + __MDSPAN_INLINE_FUNCTION constexpr + mapping(layout_stride::mapping<_OtherExtents> const& __other) // NOLINT(google-explicit-constructor) + :__extents(__other.extents()) + { + /* + * TODO: check precondition + * __other.required_span_size() is a representable value of type index_type + */ + NV_IF_TARGET(NV_IS_HOST,( + size_t __stride = 1; + for(rank_type __r=0; __r<__extents.rank(); __r++) { + _LIBCUDACXX_THROW_RUNTIME_ERROR(__stride == static_cast(__other.stride(__r)), + "Assigning layout_stride to layout_left with invalid strides."); + __stride *= __extents.extent(__r); + } + )) + } + + __MDSPAN_INLINE_FUNCTION_DEFAULTED __MDSPAN_CONSTEXPR_14_DEFAULTED mapping& operator=(mapping const&) noexcept = default; + + __MDSPAN_INLINE_FUNCTION + constexpr const extents_type& extents() const noexcept { + return __extents; + } + + __MDSPAN_INLINE_FUNCTION + constexpr index_type required_span_size() const noexcept { + index_type __value = 1; + for(rank_type __r=0; __r(), static_cast(__idxs)...); + } + + + + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { return true; } + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_exhaustive() noexcept { return true; } + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { return true; } + + __MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const noexcept { return true; } + __MDSPAN_INLINE_FUNCTION constexpr bool is_exhaustive() const noexcept { return true; } + __MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { return true; } + + __MDSPAN_TEMPLATE_REQUIRES( + class _Ext = _Extents, + /* requires */ ( + _Ext::rank() > 0 + ) + ) + __MDSPAN_INLINE_FUNCTION + constexpr index_type stride(rank_type __i) const noexcept { + index_type __value = 1; + for(rank_type __r=0; __r<__i; __r++) __value*=__extents.extent(__r); + return __value; + } + + template + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator==(mapping const& __lhs, mapping<_OtherExtents> const& __rhs) noexcept { + return __lhs.extents() == __rhs.extents(); + } + + // In C++ 20 the not equal exists if equal is found +#if !(__MDSPAN_HAS_CXX_20) + template + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator!=(mapping const& __lhs, mapping<_OtherExtents> const& __rhs) noexcept { + return __lhs.extents() != __rhs.extents(); + } +#endif + + // Not really public, but currently needed to implement fully constexpr useable submdspan: + template + _LIBCUDACXX_HOST_DEVICE + constexpr index_type __get_stride(_CUDA_VSTD::extents<_SizeType, _Ep...>,_CUDA_VSTD::integer_sequence) const { + return __MDSPAN_FOLD_TIMES_RIGHT((_Idx<_Np? __extents.template __extent<_Idx>():1),1); + } + template + _LIBCUDACXX_HOST_DEVICE + constexpr index_type stride() const noexcept { + return __get_stride<_Np>(__extents, _CUDA_VSTD::make_index_sequence()); + } + +private: + _LIBCUDACXX_NO_UNIQUE_ADDRESS extents_type __extents{}; + +}; + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MDSPAN_LAYOUT_LEFT_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h new file mode 100644 index 0000000000000000000000000000000000000000..74ad81f92fa63935ea690d285fbaf5b067daa867 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h @@ -0,0 +1,270 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_LAYOUT_RIGHT_HPP +#define _LIBCUDACXX___MDSPAN_LAYOUT_RIGHT_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__assert" +#include "../__mdspan/extents.h" +#include "../__mdspan/layout_stride.h" +#include "../__mdspan/macros.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__utility/integer_sequence.h" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +//============================================================================== +template +class layout_right::mapping { + public: + using extents_type = _Extents; + using index_type = typename extents_type::index_type; + using size_type = typename extents_type::size_type; + using rank_type = typename extents_type::rank_type; + using layout_type = layout_right; + private: + + static_assert(__detail::__is_extents_v, "layout_right::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); + + template + friend class mapping; + + // i0+(i1 + E(1)*(i2 + E(2)*i3)) + template + struct __rank_count {}; + + template + _LIBCUDACXX_HOST_DEVICE + constexpr index_type __compute_offset( + index_type __offset, __rank_count<_r,_Rank>, const _Ip& __i, _Indices... __idx) const { + return __compute_offset(__offset * __extents.template __extent<_r>() + __i,__rank_count<_r+1,_Rank>(), __idx...); + } + + template + _LIBCUDACXX_HOST_DEVICE + constexpr index_type __compute_offset( + __rank_count<0,extents_type::rank()>, const _Ip& __i, _Indices... __idx) const { + return __compute_offset(__i,__rank_count<1,extents_type::rank()>(),__idx...); + } + + _LIBCUDACXX_HOST_DEVICE + constexpr index_type __compute_offset(size_t __offset, __rank_count) const { + return static_cast(__offset); + } + + _LIBCUDACXX_HOST_DEVICE + constexpr index_type __compute_offset(__rank_count<0,0>) const { return 0; } + + public: + + //-------------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping(mapping const&) noexcept = default; + + _LIBCUDACXX_HOST_DEVICE + constexpr mapping(extents_type const& __exts) noexcept + :__extents(__exts) + { } + + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherExtents, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, extents_type, _OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!_CUDA_VSTD::is_convertible<_OtherExtents, extents_type>::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION constexpr + mapping(mapping<_OtherExtents> const& __other) noexcept // NOLINT(google-explicit-constructor) + :__extents(__other.extents()) + { + /* + * TODO: check precondition + * __other.required_span_size() is a representable value of type index_type + */ + } + + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherExtents, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, extents_type, _OtherExtents) && + (extents_type::rank() <= 1) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!_CUDA_VSTD::is_convertible<_OtherExtents, extents_type>::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION constexpr + mapping(layout_left::mapping<_OtherExtents> const& __other) noexcept // NOLINT(google-explicit-constructor) + :__extents(__other.extents()) + { + /* + * TODO: check precondition + * __other.required_span_size() is a representable value of type index_type + */ + } + + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherExtents, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, extents_type, _OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((extents_type::rank() > 0)) + __MDSPAN_INLINE_FUNCTION constexpr + mapping(layout_stride::mapping<_OtherExtents> const& __other) // NOLINT(google-explicit-constructor) + :__extents(__other.extents()) + { + /* + * TODO: check precondition + * __other.required_span_size() is a representable value of type index_type + */ + NV_IF_TARGET(NV_IS_HOST,( + size_t __stride = 1; + for(rank_type __r=__extents.rank(); __r>0; __r--) { + _LIBCUDACXX_THROW_RUNTIME_ERROR(__stride == static_cast(__other.stride(__r-1)), + "Assigning layout_stride to layout_right with invalid strides."); + __stride *= __extents.extent(__r-1); + } + )) + } + + __MDSPAN_INLINE_FUNCTION_DEFAULTED __MDSPAN_CONSTEXPR_14_DEFAULTED mapping& operator=(mapping const&) noexcept = default; + + __MDSPAN_INLINE_FUNCTION + constexpr const extents_type& extents() const noexcept { + return __extents; + } + + __MDSPAN_INLINE_FUNCTION + constexpr index_type required_span_size() const noexcept { + index_type __value = 1; + for(rank_type __r=0; __r != extents_type::rank(); ++__r) __value*=__extents.extent(__r); + return __value; + } + + //-------------------------------------------------------------------------------- + + __MDSPAN_TEMPLATE_REQUIRES( + class... _Indices, + /* requires */ ( + (sizeof...(_Indices) == extents_type::rank()) && + __MDSPAN_FOLD_AND( + (_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _Indices, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _Indices)) + ) + ) + ) + _LIBCUDACXX_HOST_DEVICE + constexpr index_type operator()(_Indices... __idxs) const noexcept { + return __compute_offset(__rank_count<0, extents_type::rank()>(), static_cast(__idxs)...); + } + + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { return true; } + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_exhaustive() noexcept { return true; } + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { return true; } + __MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const noexcept { return true; } + __MDSPAN_INLINE_FUNCTION constexpr bool is_exhaustive() const noexcept { return true; } + __MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { return true; } + + __MDSPAN_TEMPLATE_REQUIRES( + class _Ext = _Extents, + /* requires */ ( + _Ext::rank() > 0 + ) + ) + __MDSPAN_INLINE_FUNCTION + constexpr index_type stride(rank_type __i) const noexcept { + index_type __value = 1; + for(rank_type __r=extents_type::rank()-1; __r>__i; __r--) __value*=__extents.extent(__r); + return __value; + } + + template + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator==(mapping const& __lhs, mapping<_OtherExtents> const& __rhs) noexcept { + return __lhs.extents() == __rhs.extents(); + } + + // In C++ 20 the not equal exists if equal is found +#if !(__MDSPAN_HAS_CXX_20) + template + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator!=(mapping const& __lhs, mapping<_OtherExtents> const& __rhs) noexcept { + return __lhs.extents() != __rhs.extents(); + } +#endif + + // Not really public, but currently needed to implement fully constexpr useable submdspan: + template + _LIBCUDACXX_HOST_DEVICE + constexpr index_type __get_stride(_CUDA_VSTD::extents<_SizeType, _Ep...>,_CUDA_VSTD::integer_sequence) const { + return __MDSPAN_FOLD_TIMES_RIGHT((_Idx>_Np? __extents.template __extent<_Idx>():1),1); + } + template + _LIBCUDACXX_HOST_DEVICE + constexpr index_type __stride() const noexcept { + return __get_stride<_Np>(__extents, _CUDA_VSTD::make_index_sequence()); + } + +private: + _LIBCUDACXX_NO_UNIQUE_ADDRESS extents_type __extents{}; + +}; + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MDSPAN_LAYOUT_RIGHT_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h new file mode 100644 index 0000000000000000000000000000000000000000..b5ef97af4db812f8e07ee7046a8384f7fca54683 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h @@ -0,0 +1,555 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_LAYOUT_STRIDE_HPP +#define _LIBCUDACXX___MDSPAN_LAYOUT_STRIDE_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/compressed_pair.h" +#include "../__mdspan/extents.h" +#include "../__mdspan/macros.h" +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +#include "../__mdspan/no_unique_address.h" +#endif +#include "../__mdspan/static_array.h" +#include "../__type_traits/is_same.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__type_traits/remove_const.h" +#include "../__utility/integer_sequence.h" +#include "../__utility/move.h" +#include "../algorithm" +#include "../array" +#if __MDSPAN_USE_CONCEPTS && __MDSPAN_HAS_CXX_20 +#include "../concepts" +#endif +#include "../numeric" +#include "../span" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +struct layout_left { + template + class mapping; +}; +struct layout_right { + template + class mapping; +}; + +namespace __detail { + template + constexpr bool __is_mapping_of = + _CUDA_VSTD::is_same, _Mapping>::value; + +#if __MDSPAN_USE_CONCEPTS && __MDSPAN_HAS_CXX_20 + template + concept __layout_mapping_alike = requires { + requires __is_extents::value; + { _Mp::is_always_strided() } -> same_as; + { _Mp::is_always_exhaustive() } -> same_as; + { _Mp::is_always_unique() } -> same_as; + bool_constant<_Mp::is_always_strided()>::value; + bool_constant<_Mp::is_always_exhaustive()>::value; + bool_constant<_Mp::is_always_unique()>::value; + }; +#endif +} // namespace __detail + +struct layout_stride { + template + class mapping +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : private __detail::__no_unique_address_emulation< + __detail::__compressed_pair< + _Extents, + _CUDA_VSTD::array + > + > +#endif + { + public: + using extents_type = _Extents; + using index_type = typename extents_type::index_type; + using size_type = typename extents_type::size_type; + using rank_type = typename extents_type::rank_type; + using layout_type = layout_stride; + + // This could be a `requires`, but I think it's better and clearer as a `static_assert`. + static_assert(__detail::__is_extents_v<_Extents>, "layout_stride::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); + + + private: + + //---------------------------------------------------------------------------- + + using __strides_storage_t = _CUDA_VSTD::array;//_CUDA_VSTD::dextents; + using __member_pair_t = __detail::__compressed_pair; + +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + _LIBCUDACXX_NO_UNIQUE_ADDRESS __member_pair_t __members; +#else + using __base_t = __detail::__no_unique_address_emulation<__member_pair_t>; +#endif + + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __strides_storage_t const& + __strides_storage() const noexcept { +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + return __members.__second(); +#else + return this->__base_t::__ref().__second(); +#endif + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __strides_storage_t& + __strides_storage() noexcept { +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + return __members.__second(); +#else + return this->__base_t::__ref().__second(); +#endif + } + + template + _LIBCUDACXX_HOST_DEVICE + constexpr index_type __get_size(_CUDA_VSTD::extents<_SizeType, _Ep...>,_CUDA_VSTD::integer_sequence) const { + return __MDSPAN_FOLD_TIMES_RIGHT( static_cast(extents().extent(_Idx)), 1 ); + } + + //---------------------------------------------------------------------------- + + template + friend class mapping; + + //---------------------------------------------------------------------------- + + // Workaround for non-deducibility of the index sequence template parameter if it's given at the top level + template + struct __deduction_workaround; + + template + struct __deduction_workaround<_CUDA_VSTD::index_sequence<_Idxs...>> + { + template + __MDSPAN_INLINE_FUNCTION + static constexpr bool _eq_impl(mapping const& __self, mapping<_OtherExtents> const& __other) noexcept { + return __MDSPAN_FOLD_AND((__self.stride(_Idxs) == __other.stride(_Idxs)) /* && ... */) + && __MDSPAN_FOLD_AND((__self.extents().extent(_Idxs) == __other.extents().extent(_Idxs)) /* || ... */); + } + template + __MDSPAN_INLINE_FUNCTION + static constexpr bool _not_eq_impl(mapping const& __self, mapping<_OtherExtents> const& __other) noexcept { + return __MDSPAN_FOLD_OR((__self.stride(_Idxs) != __other.stride(_Idxs)) /* || ... */) + || __MDSPAN_FOLD_OR((__self.extents().extent(_Idxs) != __other.extents().extent(_Idxs)) /* || ... */); + } + + template + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr size_t _call_op_impl(mapping const& __self, _Integral... __idxs) noexcept { + return __MDSPAN_FOLD_PLUS_RIGHT((__idxs * __self.stride(_Idxs)), /* + ... + */ 0); + } + + __MDSPAN_INLINE_FUNCTION + static constexpr size_t _req_span_size_impl(mapping const& __self) noexcept { + // assumes no negative strides; not sure if I'm allowed to assume that or not + return __impl::_call_op_impl(__self, (__self.extents().template __extent<_Idxs>() - 1)...) + 1; + } + + template + __MDSPAN_INLINE_FUNCTION + static constexpr const __strides_storage_t fill_strides(const _OtherMapping& __map) { + return __strides_storage_t{static_cast(__map.stride(_Idxs))...}; + } + + __MDSPAN_INLINE_FUNCTION + static constexpr const __strides_storage_t& fill_strides(const __strides_storage_t& __s) { + return __s; + } + + template + __MDSPAN_INLINE_FUNCTION + static constexpr const __strides_storage_t fill_strides(const _CUDA_VSTD::array<_IntegralType,extents_type::rank()>& __s) { + return __strides_storage_t{static_cast(__s[_Idxs])...}; + } + + template + __MDSPAN_INLINE_FUNCTION + static constexpr const __strides_storage_t fill_strides(const _CUDA_VSTD::span<_IntegralType,extents_type::rank()>& __s) { + return __strides_storage_t{static_cast(__s[_Idxs])...}; + } + + __MDSPAN_INLINE_FUNCTION + static constexpr const __strides_storage_t fill_strides( + __detail::__extents_to_partially_static_sizes_t< + _CUDA_VSTD::dextents>&& __s) { + return __strides_storage_t{static_cast(__s.template __get_n<_Idxs>())...}; + } + + template + __MDSPAN_INLINE_FUNCTION + static constexpr size_t __return_zero() { return 0; } + + template + __MDSPAN_INLINE_FUNCTION + static constexpr typename _Mapping::index_type + __OFFSET(const _Mapping& m) { return m(__return_zero<_Idxs>()...); } + }; + + // Can't use defaulted parameter in the __deduction_workaround template because of a bug in MSVC warning C4348. + using __impl = __deduction_workaround<_CUDA_VSTD::make_index_sequence<_Extents::rank()>>; + + + //---------------------------------------------------------------------------- + +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + __MDSPAN_INLINE_FUNCTION constexpr explicit + mapping(__member_pair_t&& __m) : __members(_CUDA_VSTD::move(__m)) {} +#else + __MDSPAN_INLINE_FUNCTION constexpr explicit + mapping(__base_t&& __b) : __base_t(_CUDA_VSTD::move(__b)) {} +#endif + + public: // but not really + __MDSPAN_INLINE_FUNCTION + static constexpr mapping + __make_mapping( + __detail::__extents_to_partially_static_sizes_t<_Extents>&& __exts, + __detail::__extents_to_partially_static_sizes_t< + _CUDA_VSTD::dextents>&& __strs + ) noexcept { + // call the private constructor we created for this purpose + return mapping( +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + __base_t{ +#endif + __member_pair_t( + extents_type::__make_extents_impl(_CUDA_VSTD::move(__exts)), + __strides_storage_t{__impl::fill_strides(_CUDA_VSTD::move(__strs))} + ) +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#endif + ); + } + //---------------------------------------------------------------------------- + + + public: + + //-------------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping(mapping const&) noexcept = default; + + __MDSPAN_TEMPLATE_REQUIRES( + class _IntegralTypes, + /* requires */ ( + // MSVC 19.32 does not like using index_type here, requires the typename _Extents::index_type + // error C2641: cannot deduce template arguments for '_CUDA_VSTD::layout_stride::mapping' + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, const remove_const_t<_IntegralTypes>&, typename _Extents::index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, typename _Extents::index_type, const remove_const_t<_IntegralTypes>&) + ) + ) + __MDSPAN_INLINE_FUNCTION + constexpr + mapping( + extents_type const& __e, + _CUDA_VSTD::array<_IntegralTypes, extents_type::rank()> const& __s + ) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __members{ +#else + : __base_t(__base_t{__member_pair_t( +#endif + __e, __strides_storage_t(__impl::fill_strides(__s)) +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { + /* + * TODO: check preconditions + * - __s[i] > 0 is true for all i in the range [0, rank_ ). + * - REQUIRED-SPAN-SIZE(__e, __s) is a representable value of type index_type ([basic.fundamental]). + * - If rank_ is greater than 0, then there exists a permutation P of the integers in the + * range [0, rank_), such that __s[ pi ] >= __s[ pi − 1 ] * __e.extent( pi − 1 ) is true for + * all i in the range [1, rank_ ), where pi is the ith element of P. + */ + } + + __MDSPAN_TEMPLATE_REQUIRES( + class _IntegralTypes, + /* requires */ ( + // MSVC 19.32 does not like using index_type here, requires the typename _Extents::index_type + // error C2641: cannot deduce template arguments for '_CUDA_VSTD::layout_stride::mapping' + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, const remove_const_t<_IntegralTypes>&, typename _Extents::index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, typename _Extents::index_type, const remove_const_t<_IntegralTypes>&) + ) + ) + __MDSPAN_INLINE_FUNCTION + constexpr + mapping( + extents_type const& __e, + _CUDA_VSTD::span<_IntegralTypes, extents_type::rank()> const& __s + ) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __members{ +#else + : __base_t(__base_t{__member_pair_t( +#endif + __e, __strides_storage_t(__impl::fill_strides(__s)) +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { + /* + * TODO: check preconditions + * - __s[i] > 0 is true for all i in the range [0, rank_ ). + * - REQUIRED-SPAN-SIZE(__e, __s) is a representable value of type index_type ([basic.fundamental]). + * - If rank_ is greater than 0, then there exists a permutation P of the integers in the + * range [0, rank_), such that __s[ pi ] >= __s[ pi − 1 ] * __e.extent( pi − 1 ) is true for + * all i in the range [1, rank_ ), where pi is the ith element of P. + */ + } + +#if !(__MDSPAN_USE_CONCEPTS && __MDSPAN_HAS_CXX_20) + __MDSPAN_TEMPLATE_REQUIRES( + class _StridedLayoutMapping, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, extents_type, typename _StridedLayoutMapping::extents_type) && + __detail::__is_mapping_of && + _StridedLayoutMapping::is_always_unique() && + _StridedLayoutMapping::is_always_strided() + ) + ) +#else + template + requires( + __detail::__layout_mapping_alike<_StridedLayoutMapping> && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, extents_type, typename _StridedLayoutMapping::extents_type) && + _StridedLayoutMapping::is_always_unique() && + _StridedLayoutMapping::is_always_strided() + ) +#endif + __MDSPAN_CONDITIONAL_EXPLICIT( + (!_CUDA_VSTD::is_convertible::value) && + (__detail::__is_mapping_of || + __detail::__is_mapping_of || + __detail::__is_mapping_of) + ) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION constexpr + mapping(_StridedLayoutMapping const& __other) noexcept // NOLINT(google-explicit-constructor) +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __members{ +#else + : __base_t(__base_t{__member_pair_t( +#endif + __other.extents(), __strides_storage_t(__impl::fill_strides(__other)) +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { + /* + * TODO: check preconditions + * - __other.stride(i) > 0 is true for all i in the range [0, rank_ ). + * - __other.required_span_size() is a representable value of type index_type ([basic.fundamental]). + * - OFFSET(__other) == 0 + */ + } + + //-------------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED __MDSPAN_CONSTEXPR_14_DEFAULTED + mapping& operator=(mapping const&) noexcept = default; + + __MDSPAN_INLINE_FUNCTION constexpr const extents_type& extents() const noexcept { +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + return __members.__first(); +#else + return this->__base_t::__ref().__first(); +#endif + }; + + __MDSPAN_INLINE_FUNCTION + constexpr _CUDA_VSTD::array< index_type, extents_type::rank() > strides() const noexcept { + return __strides_storage(); + } + + __MDSPAN_INLINE_FUNCTION + constexpr index_type required_span_size() const noexcept { + index_type __span_size = 1; + for(unsigned __r = 0; __r < extents_type::rank(); __r++) { + // Return early if any of the extents are zero + if(extents().extent(__r)==0) return 0; + __span_size += ( static_cast(extents().extent(__r) - 1 ) * __strides_storage()[__r]); + } + return __span_size; + } + + + __MDSPAN_TEMPLATE_REQUIRES( + class... _Indices, + /* requires */ ( + sizeof...(_Indices) == _Extents::rank() && + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _Indices, index_type) /*&& ...*/ ) && + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _Indices) /*&& ...*/) + ) + ) + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr index_type operator()(_Indices... __idxs) const noexcept { + // Should the op_impl operate in terms of `index_type` rather than `size_t`? + // Casting `size_t` to `index_type` here. + return static_cast(__impl::_call_op_impl(*this, static_cast(__idxs)...)); + } + + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { return true; } + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_exhaustive() noexcept { + return false; + } + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { return true; } + + __MDSPAN_INLINE_FUNCTION static constexpr bool is_unique() noexcept { return true; } + __MDSPAN_INLINE_FUNCTION constexpr bool is_exhaustive() const noexcept { + return required_span_size() == __get_size( extents(), _CUDA_VSTD::make_index_sequence()); + } + __MDSPAN_INLINE_FUNCTION static constexpr bool is_strided() noexcept { return true; } + + + __MDSPAN_TEMPLATE_REQUIRES( + class _Ext = _Extents, + /* requires */ ( + _Ext::rank() > 0 + ) + ) + __MDSPAN_INLINE_FUNCTION + constexpr index_type stride(rank_type __r) const noexcept { + return __strides_storage()[__r]; + } + +#if !(__MDSPAN_USE_CONCEPTS && __MDSPAN_HAS_CXX_20) + __MDSPAN_TEMPLATE_REQUIRES( + class _StridedLayoutMapping, + /* requires */ ( + __detail::__is_mapping_of && + (extents_type::rank() == _StridedLayoutMapping::extents_type::rank()) && + _StridedLayoutMapping::is_always_strided() + ) + ) +#else + template + requires( + __detail::__layout_mapping_alike<_StridedLayoutMapping> && + (extents_type::rank() == _StridedLayoutMapping::extents_type::rank()) && + _StridedLayoutMapping::is_always_strided() + ) +#endif + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator==(const mapping& __x, const _StridedLayoutMapping& __y) noexcept { + bool __strides_match = true; + for(rank_type __r = 0; __r < extents_type::rank(); __r++) + __strides_match = __strides_match && (__x.stride(__r) == __y.stride(__r)); + return (__x.extents() == __y.extents()) && + (__impl::__OFFSET(__y)== static_cast(0)) && + __strides_match; + } + + // This one is not technically part of the proposal. Just here to make implementation a bit more optimal hopefully + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherExtents, + /* requires */ ( + (extents_type::rank() == _OtherExtents::rank()) + ) + ) + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator==(mapping const& __lhs, mapping<_OtherExtents> const& __rhs) noexcept { + return __impl::_eq_impl(__lhs, __rhs); + } + +#if !__MDSPAN_HAS_CXX_20 + __MDSPAN_TEMPLATE_REQUIRES( + class _StridedLayoutMapping, + /* requires */ ( + __detail::__is_mapping_of && + (extents_type::rank() == _StridedLayoutMapping::extents_type::rank()) && + _StridedLayoutMapping::is_always_strided() + ) + ) + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator!=(const mapping& __x, const _StridedLayoutMapping& __y) noexcept { + return not (__x == __y); + } + + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherExtents, + /* requires */ ( + (extents_type::rank() == _OtherExtents::rank()) + ) + ) + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator!=(mapping const& __lhs, mapping<_OtherExtents> const& __rhs) noexcept { + return __impl::_not_eq_impl(__lhs, __rhs); + } +#endif + + }; +}; + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MDSPAN_LAYOUT_STRIDE_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/macros.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/macros.h new file mode 100644 index 0000000000000000000000000000000000000000..0a14f21debf0a71f9a9011bc2240d94f2670eb6f --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/macros.h @@ -0,0 +1,639 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + + +#ifndef _LIBCUDACXX___MDSPAN_MACROS_HPP +#define _LIBCUDACXX___MDSPAN_MACROS_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/config.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_void.h" +#include "../__type_traits/remove_reference.h" +#include "../__utility/declval.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if _LIBCUDACXX_STD_VER > 11 + +#ifndef __MDSPAN_FORCE_INLINE_FUNCTION +# ifdef __MDSPAN_COMPILER_MSVC // Microsoft compilers +# define __MDSPAN_FORCE_INLINE_FUNCTION __forceinline _LIBCUDACXX_HOST_DEVICE +# else +# define __MDSPAN_FORCE_INLINE_FUNCTION __attribute__((always_inline)) _LIBCUDACXX_HOST_DEVICE +# endif +#endif + +#ifndef __MDSPAN_INLINE_FUNCTION +# define __MDSPAN_INLINE_FUNCTION inline _LIBCUDACXX_HOST_DEVICE +#endif + +// In CUDA defaulted functions do not need host device markup +#ifndef __MDSPAN_INLINE_FUNCTION_DEFAULTED +# define __MDSPAN_INLINE_FUNCTION_DEFAULTED +#endif + +//============================================================================== +// {{{1 + +#define __MDSPAN_PP_COUNT(...) \ + __MDSPAN_PP_INTERNAL_EXPAND_ARGS_PRIVATE( \ + __MDSPAN_PP_INTERNAL_ARGS_AUGMENTER(__VA_ARGS__) \ + ) + +#define __MDSPAN_PP_INTERNAL_ARGS_AUGMENTER(...) unused, __VA_ARGS__ +#define __MDSPAN_PP_INTERNAL_EXPAND(x) x +#define __MDSPAN_PP_INTERNAL_EXPAND_ARGS_PRIVATE(...) \ + __MDSPAN_PP_INTERNAL_EXPAND( \ + __MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ + __VA_ARGS__, 69, 68, 67, 66, 65, 64, 63, 62, 61, \ + 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, \ + 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, \ + 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, \ + 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, \ + 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 \ + ) \ + ) +# define __MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ + _1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, \ + _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, \ + _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, \ + _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, \ + _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, \ + _70, count, ...) count \ + /**/ + +#define __MDSPAN_PP_STRINGIFY_IMPL(x) #x +#define __MDSPAN_PP_STRINGIFY(x) __MDSPAN_PP_STRINGIFY_IMPL(x) + +#define __MDSPAN_PP_CAT_IMPL(x, y) x ## y +#define __MDSPAN_PP_CAT(x, y) __MDSPAN_PP_CAT_IMPL(x, y) + +#define __MDSPAN_PP_EVAL(X, ...) X(__VA_ARGS__) + +#define __MDSPAN_PP_REMOVE_PARENS_IMPL(...) __VA_ARGS__ +#define __MDSPAN_PP_REMOVE_PARENS(...) __MDSPAN_PP_REMOVE_PARENS_IMPL __VA_ARGS__ + +// end Preprocessor helpers }}}1 +//============================================================================== + +//============================================================================== +// {{{1 + +// These compatibility macros don't help with partial ordering, but they should do the trick +// for what we need to do with concepts in mdspan +#ifdef __MDSPAN_USE_CONCEPTS +# define __MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) > requires REQ +# define __MDSPAN_FUNCTION_REQUIRES(PAREN_PREQUALS, FNAME, PAREN_PARAMS, QUALS, REQ) \ + __MDSPAN_PP_REMOVE_PARENS(PAREN_PREQUALS) FNAME PAREN_PARAMS QUALS requires REQ \ + /**/ +#else +# define __MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) , typename _CUDA_VSTD::enable_if<(REQ), int>::type = 0> +# define __MDSPAN_FUNCTION_REQUIRES(PAREN_PREQUALS, FNAME, PAREN_PARAMS, QUALS, REQ) \ + __MDSPAN_TEMPLATE_REQUIRES( \ + class __function_requires_ignored=void, \ + (_CUDA_VSTD::is_void<__function_requires_ignored>::value && REQ) \ + ) __MDSPAN_PP_REMOVE_PARENS(PAREN_PREQUALS) FNAME PAREN_PARAMS QUALS \ + /**/ +#endif + + +#if defined(__MDSPAN_COMPILER_MSVC) +# define __MDSPAN_TEMPLATE_REQUIRES(...) \ + __MDSPAN_PP_CAT( \ + __MDSPAN_PP_CAT(__MDSPAN_TEMPLATE_REQUIRES_, __MDSPAN_PP_COUNT(__VA_ARGS__))\ + (__VA_ARGS__), \ + ) \ + /**/ +#else +# define __MDSPAN_TEMPLATE_REQUIRES(...) \ + __MDSPAN_PP_EVAL( \ + __MDSPAN_PP_CAT(__MDSPAN_TEMPLATE_REQUIRES_, __MDSPAN_PP_COUNT(__VA_ARGS__)), \ + __VA_ARGS__ \ + ) \ + /**/ +#endif + +#define __MDSPAN_TEMPLATE_REQUIRES_2(TP1, REQ) \ + template end Concept emulation }}}1 +//============================================================================== + +//============================================================================== +// {{{1 + +#if __MDSPAN_USE_RETURN_TYPE_DEDUCTION +# define __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ + auto __MDSPAN_PP_REMOVE_PARENS(SIGNATURE) { return __MDSPAN_PP_REMOVE_PARENS(BODY); } +# define __MDSPAN_DEDUCE_DECLTYPE_AUTO_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ + decltype(auto) __MDSPAN_PP_REMOVE_PARENS(SIGNATURE) { return __MDSPAN_PP_REMOVE_PARENS(BODY); } +#else +# define __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ + auto __MDSPAN_PP_REMOVE_PARENS(SIGNATURE) \ + -> _CUDA_VSTD::remove_cv_t<_CUDA_VSTD::remove_reference_t> \ + { return __MDSPAN_PP_REMOVE_PARENS(BODY); } +# define __MDSPAN_DEDUCE_DECLTYPE_AUTO_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ + auto __MDSPAN_PP_REMOVE_PARENS(SIGNATURE) \ + -> decltype(BODY) \ + { return __MDSPAN_PP_REMOVE_PARENS(BODY); } + +#endif + +// end Return type deduction }}}1 +//============================================================================== + +//============================================================================== +// {{{1 + +struct __mdspan_enable_fold_comma { }; + +#ifdef __MDSPAN_USE_FOLD_EXPRESSIONS +# define __MDSPAN_FOLD_AND(...) ((__VA_ARGS__) && ...) +# define __MDSPAN_FOLD_AND_TEMPLATE(...) ((__VA_ARGS__) && ...) +# define __MDSPAN_FOLD_OR(...) ((__VA_ARGS__) || ...) +# define __MDSPAN_FOLD_ASSIGN_LEFT(__INIT, ...) (__INIT = ... = (__VA_ARGS__)) +# define __MDSPAN_FOLD_ASSIGN_RIGHT(__PACK, ...) (__PACK = ... = (__VA_ARGS__)) +# define __MDSPAN_FOLD_TIMES_RIGHT(__PACK, ...) (__PACK * ... * (__VA_ARGS__)) +# define __MDSPAN_FOLD_PLUS_RIGHT(__PACK, ...) (__PACK + ... + (__VA_ARGS__)) +# define __MDSPAN_FOLD_COMMA(...) ((__VA_ARGS__), ...) +#else + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +namespace __fold_compatibility_impl { + +// We could probably be more clever here, but at the (small) risk of losing some compiler understanding. For the +// few operations we need, it's not worth generalizing over the operation + +#if __MDSPAN_USE_RETURN_TYPE_DEDUCTION + +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr decltype(auto) __fold_right_and_impl() { + return true; +} + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr decltype(auto) __fold_right_and_impl(_Arg&& __arg, _Args&&... __args) { + return ((_Arg&&)__arg) && __fold_compatibility_impl::__fold_right_and_impl((_Args&&)__args...); +} + +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr decltype(auto) __fold_right_or_impl() { + return false; +} + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr auto __fold_right_or_impl(_Arg&& __arg, _Args&&... __args) { + return ((_Arg&&)__arg) || __fold_compatibility_impl::__fold_right_or_impl((_Args&&)__args...); +} + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr auto __fold_left_assign_impl(_Arg1&& __arg1) { + return (_Arg1&&)__arg1; +} + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr auto __fold_left_assign_impl(_Arg1&& __arg1, _Arg2&& __arg2, _Args&&... __args) { + return __fold_compatibility_impl::__fold_left_assign_impl((((_Arg1&&)__arg1) = ((_Arg2&&)__arg2)), (_Args&&)__args...); +} + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr auto __fold_right_assign_impl(_Arg1&& __arg1) { + return (_Arg1&&)__arg1; +} + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr auto __fold_right_assign_impl(_Arg1&& __arg1, _Arg2&& __arg2, _Args&&... __args) { + return ((_Arg1&&)__arg1) = __fold_compatibility_impl::__fold_right_assign_impl((_Arg2&&)__arg2, (_Args&&)__args...); +} + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr auto __fold_right_plus_impl(_Arg1&& __arg1) { + return (_Arg1&&)__arg1; +} + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr auto __fold_right_plus_impl(_Arg1&& __arg1, _Arg2&& __arg2, _Args&&... __args) { + return ((_Arg1&&)__arg1) + __fold_compatibility_impl::__fold_right_plus_impl((_Arg2&&)__arg2, (_Args&&)__args...); +} + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr auto __fold_right_times_impl(_Arg1&& __arg1) { + return (_Arg1&&)__arg1; +} + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr auto __fold_right_times_impl(_Arg1&& __arg1, _Arg2&& __arg2, _Args&&... __args) { + return ((_Arg1&&)__arg1) * __fold_compatibility_impl::__fold_right_times_impl((_Arg2&&)__arg2, (_Args&&)__args...); +} + +#else + +//------------------------------------------------------------------------------ +// {{{2 + +template +struct __fold_right_and_impl_; +template <> +struct __fold_right_and_impl_<> { + using __rv = bool; + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl() noexcept { + return true; + } +}; +template +struct __fold_right_and_impl_<_Arg, _Args...> { + using __next_t = __fold_right_and_impl_<_Args...>; + using __rv = decltype(_CUDA_VSTD::declval<_Arg>() && _CUDA_VSTD::declval()); + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl(_Arg&& __arg, _Args&&... __args) noexcept { + return ((_Arg&&)__arg) && __next_t::__impl((_Args&&)__args...); + } +}; + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr typename __fold_right_and_impl_<_Args...>::__rv +__fold_right_and_impl(_Args&&... __args) { + return __fold_right_and_impl_<_Args...>::__impl((_Args&&)__args...); +} + +// end right and }}}2 +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// {{{2 + +template +struct __fold_right_or_impl_; +template <> +struct __fold_right_or_impl_<> { + using __rv = bool; + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl() noexcept { + return false; + } +}; +template +struct __fold_right_or_impl_<_Arg, _Args...> { + using __next_t = __fold_right_or_impl_<_Args...>; + using __rv = decltype(_CUDA_VSTD::declval<_Arg>() || _CUDA_VSTD::declval()); + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl(_Arg&& __arg, _Args&&... __args) noexcept { + return ((_Arg&&)__arg) || __next_t::__impl((_Args&&)__args...); + } +}; + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr typename __fold_right_or_impl_<_Args...>::__rv +__fold_right_or_impl(_Args&&... __args) { + return __fold_right_or_impl_<_Args...>::__impl((_Args&&)__args...); +} + +// end right or }}}2 +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// {{{2 + +template +struct __fold_right_plus_impl_; +template +struct __fold_right_plus_impl_<_Arg> { + using __rv = _Arg&&; + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl(_Arg&& __arg) noexcept { + return (_Arg&&)__arg; + } +}; +template +struct __fold_right_plus_impl_<_Arg1, _Arg2, _Args...> { + using __next_t = __fold_right_plus_impl_<_Arg2, _Args...>; + using __rv = decltype(_CUDA_VSTD::declval<_Arg1>() + _CUDA_VSTD::declval()); + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl(_Arg1&& __arg, _Arg2&& __arg2, _Args&&... __args) noexcept { + return ((_Arg1&&)__arg) + __next_t::__impl((_Arg2&&)__arg2, (_Args&&)__args...); + } +}; + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr typename __fold_right_plus_impl_<_Args...>::__rv +__fold_right_plus_impl(_Args&&... __args) { + return __fold_right_plus_impl_<_Args...>::__impl((_Args&&)__args...); +} + +// end right plus }}}2 +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// {{{2 + +template +struct __fold_right_times_impl_; +template +struct __fold_right_times_impl_<_Arg> { + using __rv = _Arg&&; + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl(_Arg&& __arg) noexcept { + return (_Arg&&)__arg; + } +}; +template +struct __fold_right_times_impl_<_Arg1, _Arg2, _Args...> { + using __next_t = __fold_right_times_impl_<_Arg2, _Args...>; + using __rv = decltype(_CUDA_VSTD::declval<_Arg1>() * _CUDA_VSTD::declval()); + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl(_Arg1&& __arg, _Arg2&& __arg2, _Args&&... __args) noexcept { + return ((_Arg1&&)__arg) * __next_t::__impl((_Arg2&&)__arg2, (_Args&&)__args...); + } +}; + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr typename __fold_right_times_impl_<_Args...>::__rv +__fold_right_times_impl(_Args&&... __args) { + return __fold_right_times_impl_<_Args...>::__impl((_Args&&)__args...); +} + +// end right times }}}2 +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// {{{2 + +template +struct __fold_right_assign_impl_; +template +struct __fold_right_assign_impl_<_Arg> { + using __rv = _Arg&&; + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl(_Arg&& __arg) noexcept { + return (_Arg&&)__arg; + } +}; +template +struct __fold_right_assign_impl_<_Arg1, _Arg2, _Args...> { + using __next_t = __fold_right_assign_impl_<_Arg2, _Args...>; + using __rv = decltype(_CUDA_VSTD::declval<_Arg1>() = _CUDA_VSTD::declval()); + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl(_Arg1&& __arg, _Arg2&& __arg2, _Args&&... __args) noexcept { + return ((_Arg1&&)__arg) = __next_t::__impl((_Arg2&&)__arg2, (_Args&&)__args...); + } +}; + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr typename __fold_right_assign_impl_<_Args...>::__rv +__fold_right_assign_impl(_Args&&... __args) { + return __fold_right_assign_impl_<_Args...>::__impl((_Args&&)__args...); +} + +// end right assign }}}2 +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// {{{2 + +template +struct __fold_left_assign_impl_; +template +struct __fold_left_assign_impl_<_Arg> { + using __rv = _Arg&&; + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl(_Arg&& __arg) noexcept { + return (_Arg&&)__arg; + } +}; +template +struct __fold_left_assign_impl_<_Arg1, _Arg2, _Args...> { + using __assign_result_t = decltype(_CUDA_VSTD::declval<_Arg1>() = _CUDA_VSTD::declval<_Arg2>()); + using __next_t = __fold_left_assign_impl_<__assign_result_t, _Args...>; + using __rv = typename __next_t::__rv; + __MDSPAN_FORCE_INLINE_FUNCTION + static constexpr __rv + __impl(_Arg1&& __arg, _Arg2&& __arg2, _Args&&... __args) noexcept { + return __next_t::__impl(((_Arg1&&)__arg) = (_Arg2&&)__arg2, (_Args&&)__args...); + } +}; + +template +__MDSPAN_FORCE_INLINE_FUNCTION +constexpr typename __fold_left_assign_impl_<_Args...>::__rv +__fold_left_assign_impl(_Args&&... __args) { + return __fold_left_assign_impl_<_Args...>::__impl((_Args&&)__args...); +} + +// end left assign }}}2 +//------------------------------------------------------------------------------ + +#endif + + +template +_LIBCUDACXX_HOST_DEVICE +constexpr __mdspan_enable_fold_comma __fold_comma_impl(_Args&&...) noexcept { return { }; } + +template +struct __bools; + +} // __fold_compatibility_impl + +_LIBCUDACXX_END_NAMESPACE_STD + +# define __MDSPAN_FOLD_AND(...) _CUDA_VSTD::__fold_compatibility_impl::__fold_right_and_impl((__VA_ARGS__)...) +# define __MDSPAN_FOLD_OR(...) _CUDA_VSTD::__fold_compatibility_impl::__fold_right_or_impl((__VA_ARGS__)...) +# define __MDSPAN_FOLD_ASSIGN_LEFT(__INIT, ...) _CUDA_VSTD::__fold_compatibility_impl::__fold_left_assign_impl(__INIT, (__VA_ARGS__)...) +# define __MDSPAN_FOLD_ASSIGN_RIGHT(__PACK, ...) _CUDA_VSTD::__fold_compatibility_impl::__fold_right_assign_impl((__PACK)..., __VA_ARGS__) +# define __MDSPAN_FOLD_TIMES_RIGHT(__PACK, ...) _CUDA_VSTD::__fold_compatibility_impl::__fold_right_times_impl((__PACK)..., __VA_ARGS__) +# define __MDSPAN_FOLD_PLUS_RIGHT(__PACK, ...) _CUDA_VSTD::__fold_compatibility_impl::__fold_right_plus_impl((__PACK)..., __VA_ARGS__) +# define __MDSPAN_FOLD_COMMA(...) _CUDA_VSTD::__fold_compatibility_impl::__fold_comma_impl((__VA_ARGS__)...) + +# define __MDSPAN_FOLD_AND_TEMPLATE(...) \ + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_same, __fold_compatibility_impl::__bools<(__VA_ARGS__)..., true>, __fold_compatibility_impl::__bools) + +#endif + +// end Variable template compatibility }}}1 +//============================================================================== + +//============================================================================== +// {{{1 + +#if __MDSPAN_USE_CONSTEXPR_14 +// Workaround for a bug (I think?) in EDG frontends +# ifdef __EDG__ +# define __MDSPAN_CONSTEXPR_14_DEFAULTED +# else +# define __MDSPAN_CONSTEXPR_14_DEFAULTED constexpr +# endif +#else +# define __MDSPAN_CONSTEXPR_14_DEFAULTED +#endif + +// end Pre-C++14 constexpr }}}1 +//============================================================================== + +#endif // _LIBCUDACXX_STD_VER > 11 + +#ifndef _LIBCUDACXX_NO_EXCEPTIONS +#define _LIBCUDACXX_THROW_RUNTIME_ERROR(_COND, _MESSAGE) \ + if (!(_COND)) __throw_runtime_error(_MESSAGE) +#else +#define _LIBCUDACXX_THROW_RUNTIME_ERROR(_COND, _MESSAGE) \ + _LIBCUDACXX_ASSERT(_COND, _MESSAGE) +#endif + +#endif // _LIBCUDACXX___MDSPAN_MACROS_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h new file mode 100644 index 0000000000000000000000000000000000000000..a6a41aca87248cb599e1534bd18dec66bf7083ba --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h @@ -0,0 +1,167 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_MAYBE_STATIC_VALUE_HPP +#define _LIBCUDACXX___MDSPAN_MAYBE_STATIC_VALUE_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/dynamic_extent.h" +#include "../__mdspan/macros.h" +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +#include "../__mdspan/no_unique_address.h" +#endif + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +// This is only needed for the non-standard-layout version of partially +// static array. +// Needs to be after the includes above to work with the single header generator +#if !__MDSPAN_PRESERVE_STANDARD_LAYOUT + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +//============================================================================== + +namespace __detail { + +// static case +template +struct __maybe_static_value { + static constexpr _static_t __static_value = __v; + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t __value() const noexcept { + return static_cast<_dynamic_t>(__v); + } + template + __MDSPAN_FORCE_INLINE_FUNCTION constexpr + __mdspan_enable_fold_comma + __set_value(_Up&& /*__rhs*/) noexcept { + // Should we assert that the value matches the static value here? + return {}; + } + + //-------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __maybe_static_value() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __maybe_static_value(__maybe_static_value const&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __maybe_static_value(__maybe_static_value&&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __maybe_static_value& operator=(__maybe_static_value const&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __maybe_static_value& operator=(__maybe_static_value&&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~__maybe_static_value() noexcept = default; + + __MDSPAN_INLINE_FUNCTION + constexpr explicit __maybe_static_value(_dynamic_t const&) noexcept { + // Should we assert that the value matches the static value here? + } + + //-------------------------------------------------------------------------- + +}; + +// dynamic case +template +struct __maybe_static_value<_dynamic_t, _static_t, __is_dynamic_sentinal, __is_dynamic_sentinal, + __array_entry_index> +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __no_unique_address_emulation<_Tp> +#endif +{ + static constexpr _static_t __static_value = __is_dynamic_sentinal; +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + _LIBCUDACXX_NO_UNIQUE_ADDRESS _dynamic_t __v = {}; + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t __value() const noexcept { + return __v; + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t &__ref() noexcept { + return __v; + } + template + __MDSPAN_FORCE_INLINE_FUNCTION constexpr + __mdspan_enable_fold_comma + __set_value(_Up&& __rhs) noexcept { + __v = (_Up &&)rhs; + return {}; + } +#else + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t __value() const noexcept { + return this->__no_unique_address_emulation<_dynamic_t>::__ref(); + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t &__ref() noexcept { + return this->__no_unique_address_emulation<_dynamic_t>::__ref(); + } + template + __MDSPAN_FORCE_INLINE_FUNCTION constexpr + __mdspan_enable_fold_comma + __set_value(_Up&& __rhs) noexcept { + this->__no_unique_address_emulation<_dynamic_t>::__ref() = (_Up &&)__rhs; + return {}; + } +#endif +}; + +} // namespace __detail + +//============================================================================== + + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // !__MDSPAN_PRESERVE_STANDARD_LAYOUT + +#endif // _LIBCUDACXX___MDSPAN_MAYBE_STATIC_VALUE_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h new file mode 100644 index 0000000000000000000000000000000000000000..f5323a72ced0f05f91075286f2d9b3a07fb76345 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h @@ -0,0 +1,466 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + + +#ifndef _LIBCUDACXX___MDSPAN_MDSPAN_HPP +#define _LIBCUDACXX___MDSPAN_MDSPAN_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/default_accessor.h" +#include "../__mdspan/layout_right.h" +#include "../__mdspan/extents.h" +#include "../__mdspan/compressed_pair.h" +#include "../__type_traits/extent.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_default_constructible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__type_traits/rank.h" +#include "../__type_traits/remove_cv.h" +#include "../__type_traits/remove_pointer.h" +#include "../__type_traits/remove_reference.h" +#include "../__type_traits/remove_all_extents.h" +#include "../__utility/as_const.h" +#include "../__utility/integer_sequence.h" +#include "../__utility/move.h" +#include "../array" +#include "../span" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +template < + class _ElementType, + class _Extents, + class _LayoutPolicy = layout_right, + class _AccessorPolicy = default_accessor<_ElementType> +> +class mdspan +{ +private: + static_assert(__detail::__is_extents_v<_Extents>, "mdspan's Extents template parameter must be a specialization of _CUDA_VSTD::extents."); + + // Workaround for non-deducibility of the index sequence template parameter if it's given at the top level + template + struct __deduction_workaround; + + template + struct __deduction_workaround<_CUDA_VSTD::index_sequence<_Idxs...>> + { + __MDSPAN_FORCE_INLINE_FUNCTION static constexpr + size_t __size(mdspan const& __self) noexcept { + return __MDSPAN_FOLD_TIMES_RIGHT((__self.__mapping_ref().extents().template __extent<_Idxs>()), /* * ... * */ size_t(1)); + } + __MDSPAN_FORCE_INLINE_FUNCTION static constexpr + bool __empty(mdspan const& __self) noexcept { + return (__self.rank()>0) && __MDSPAN_FOLD_OR((__self.__mapping_ref().extents().template __extent<_Idxs>()==index_type(0))); + } + template + __MDSPAN_FORCE_INLINE_FUNCTION static constexpr + _ReferenceType __callop(mdspan const& __self, const _CUDA_VSTD::array<_SizeType, _Np>& __indices) noexcept { + return __self.__accessor_ref().access(__self.__ptr_ref(), __self.__mapping_ref()(__indices[_Idxs]...)); + } + template + __MDSPAN_FORCE_INLINE_FUNCTION static constexpr + _ReferenceType __callop(mdspan const& __self, const _CUDA_VSTD::span<_SizeType, _Np>& __indices) noexcept { + return __self.__accessor_ref().access(__self.__ptr_ref(), __self.__mapping_ref()(__indices[_Idxs]...)); + } + }; + +public: + + //-------------------------------------------------------------------------------- + // Domain and codomain types + + using extents_type = _Extents; + using layout_type = _LayoutPolicy; + using accessor_type = _AccessorPolicy; + using mapping_type = typename layout_type::template mapping; + using element_type = _ElementType; + using value_type = _CUDA_VSTD::remove_cv_t; + using index_type = typename extents_type::index_type; + using size_type = typename extents_type::size_type; + using rank_type = typename extents_type::rank_type; + using data_handle_type = typename accessor_type::data_handle_type; + using reference = typename accessor_type::reference; + + __MDSPAN_INLINE_FUNCTION static constexpr size_t rank() noexcept { return extents_type::rank(); } + __MDSPAN_INLINE_FUNCTION static constexpr size_t rank_dynamic() noexcept { return extents_type::rank_dynamic(); } + __MDSPAN_INLINE_FUNCTION static constexpr size_t static_extent(size_t __r) noexcept { return extents_type::static_extent(__r); } + __MDSPAN_INLINE_FUNCTION constexpr index_type extent(size_t __r) const noexcept { return __mapping_ref().extents().extent(__r); }; + +private: + + // Can't use defaulted parameter in the __deduction_workaround template because of a bug in MSVC warning C4348. + using __impl = __deduction_workaround<_CUDA_VSTD::make_index_sequence>; + + using __map_acc_pair_t = __detail::__compressed_pair; + +public: + + //-------------------------------------------------------------------------------- + // [mdspan.basic.cons], mdspan constructors, assignment, and destructor + +#if !__MDSPAN_HAS_CXX_20 + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mdspan() = default; +#else + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mdspan() + requires( + // Directly using rank_dynamic()>0 here doesn't work for nvcc + (extents_type::rank_dynamic() >0) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_default_constructible, data_handle_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_default_constructible, mapping_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_default_constructible, accessor_type) + ) = default; +#endif + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mdspan(const mdspan&) = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mdspan(mdspan&&) = default; + + __MDSPAN_TEMPLATE_REQUIRES( + class... _SizeTypes, + /* requires */ ( + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SizeTypes, index_type) /* && ... */) && + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeTypes) /* && ... */) && + ((sizeof...(_SizeTypes) == rank()) || (sizeof...(_SizeTypes) == rank_dynamic())) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, mapping_type, extents_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_default_constructible, accessor_type) + ) + ) + __MDSPAN_INLINE_FUNCTION + explicit constexpr mdspan(data_handle_type __p, _SizeTypes... __dynamic_extents) + // TODO @proposal-bug shouldn't I be allowed to do `move(__p)` here? + : __members(_CUDA_VSTD::move(__p), __map_acc_pair_t(mapping_type(extents_type(static_cast(_CUDA_VSTD::move(__dynamic_extents))...)), accessor_type())) + { } + + __MDSPAN_TEMPLATE_REQUIRES( + class _SizeType, size_t _Np, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeType) && + ((_Np == rank()) || (_Np == rank_dynamic())) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, mapping_type, extents_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_default_constructible, accessor_type) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT(_Np != rank_dynamic()) + __MDSPAN_INLINE_FUNCTION + constexpr mdspan(data_handle_type __p, const _CUDA_VSTD::array<_SizeType, _Np>& __dynamic_extents) + : __members(_CUDA_VSTD::move(__p), __map_acc_pair_t(mapping_type(extents_type(__dynamic_extents)), accessor_type())) + { } + + __MDSPAN_TEMPLATE_REQUIRES( + class _SizeType, size_t _Np, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeType) && + ((_Np == rank()) || (_Np == rank_dynamic())) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, mapping_type, extents_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_default_constructible, accessor_type) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT(_Np != rank_dynamic()) + __MDSPAN_INLINE_FUNCTION + constexpr mdspan(data_handle_type __p, _CUDA_VSTD::span<_SizeType, _Np> __dynamic_extents) + : __members(_CUDA_VSTD::move(__p), __map_acc_pair_t(mapping_type(extents_type(_CUDA_VSTD::as_const(__dynamic_extents))), accessor_type())) + { } + + __MDSPAN_FUNCTION_REQUIRES( + (__MDSPAN_INLINE_FUNCTION constexpr), + mdspan, (data_handle_type __p, const extents_type& __exts), , + /* requires */ (_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_default_constructible, accessor_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, mapping_type, extents_type)) + ) : __members(_CUDA_VSTD::move(__p), __map_acc_pair_t(mapping_type(__exts), accessor_type())) + { } + + __MDSPAN_FUNCTION_REQUIRES( + (__MDSPAN_INLINE_FUNCTION constexpr), + mdspan, (data_handle_type __p, const mapping_type& __m), , + /* requires */ (_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_default_constructible, accessor_type)) + ) : __members(_CUDA_VSTD::move(__p), __map_acc_pair_t(__m, accessor_type())) + { } + + __MDSPAN_INLINE_FUNCTION + constexpr mdspan(data_handle_type __p, const mapping_type& __m, const accessor_type& __a) + : __members(_CUDA_VSTD::move(__p), __map_acc_pair_t(__m, __a)) + { } + + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherElementType, class _OtherExtents, class _OtherLayoutPolicy, class _OtherAccessor, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, mapping_type, typename _OtherLayoutPolicy::template mapping<_OtherExtents>) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, accessor_type, _OtherAccessor) + ) + ) + __MDSPAN_INLINE_FUNCTION + constexpr mdspan(const mdspan<_OtherElementType, _OtherExtents, _OtherLayoutPolicy, _OtherAccessor>& __other) + : __members(__other.__ptr_ref(), __map_acc_pair_t(__other.__mapping_ref(), __other.__accessor_ref())) + { + static_assert(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, data_handle_type, typename _OtherAccessor::data_handle_type),"Incompatible data_handle_type for mdspan construction"); + static_assert(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_constructible, extents_type, _OtherExtents),"Incompatible extents for mdspan construction"); + /* + * TODO: Check precondition + * For each rank index __r of extents_type, static_extent(__r) == dynamic_extent || static_extent(__r) == __other.extent(__r) is true. + */ + } + + /* Might need this on NVIDIA? + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~mdspan() = default; + */ + + __MDSPAN_INLINE_FUNCTION_DEFAULTED __MDSPAN_CONSTEXPR_14_DEFAULTED mdspan& operator=(const mdspan&) = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED __MDSPAN_CONSTEXPR_14_DEFAULTED mdspan& operator=(mdspan&&) = default; + + + //-------------------------------------------------------------------------------- + // [mdspan.basic.mapping], mdspan mapping domain multidimensional index to access codomain element + + #if __MDSPAN_USE_BRACKET_OPERATOR + __MDSPAN_TEMPLATE_REQUIRES( + class... _SizeTypes, + /* requires */ ( + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SizeTypes, index_type) /* && ... */) && + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeTypes) /* && ... */) && + (rank() == sizeof...(_SizeTypes)) + ) + ) + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr reference operator[](_SizeTypes... __indices) const + { + return __accessor_ref().access(__ptr_ref(), __mapping_ref()(index_type(__indices)...)); + } + #endif + + __MDSPAN_TEMPLATE_REQUIRES( + class _SizeType, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeType) + ) + ) + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr reference operator[](const _CUDA_VSTD::array<_SizeType, rank()>& __indices) const + { + return __impl::template __callop(*this, __indices); + } + + __MDSPAN_TEMPLATE_REQUIRES( + class _SizeType, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeType) + ) + ) + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr reference operator[](_CUDA_VSTD::span<_SizeType, rank()> __indices) const + { + return __impl::template __callop(*this, __indices); + } + + #if !__MDSPAN_USE_BRACKET_OPERATOR + __MDSPAN_TEMPLATE_REQUIRES( + class _Index, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _Index, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _Index) && + extents_type::rank() == 1 + ) + ) + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr reference operator[](_Index __idx) const + { + return __accessor_ref().access(__ptr_ref(), __mapping_ref()(index_type(__idx))); + } + #endif + + #if __MDSPAN_USE_PAREN_OPERATOR + __MDSPAN_TEMPLATE_REQUIRES( + class... _SizeTypes, + /* requires */ ( + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SizeTypes, index_type) /* && ... */) && + __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeTypes) /* && ... */) && + extents_type::rank() == sizeof...(_SizeTypes) + ) + ) + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr reference operator()(_SizeTypes... __indices) const + { + return __accessor_ref().access(__ptr_ref(), __mapping_ref()(__indices...)); + } + + __MDSPAN_TEMPLATE_REQUIRES( + class _SizeType, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeType) + ) + ) + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr reference operator()(const _CUDA_VSTD::array<_SizeType, rank()>& __indices) const + { + return __impl::template __callop(*this, __indices); + } + + __MDSPAN_TEMPLATE_REQUIRES( + class _SizeType, + /* requires */ ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeType) + ) + ) + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr reference operator()(_CUDA_VSTD::span<_SizeType, rank()> __indices) const + { + return __impl::template __callop(*this, __indices); + } + #endif // __MDSPAN_USE_PAREN_OPERATOR + + __MDSPAN_INLINE_FUNCTION constexpr size_t size() const noexcept { + return __impl::__size(*this); + }; + + __MDSPAN_INLINE_FUNCTION constexpr bool empty() const noexcept { + return __impl::__empty(*this); + }; + + __MDSPAN_INLINE_FUNCTION + friend constexpr void swap(mdspan& __x, mdspan& __y) noexcept { + swap(__x.__ptr_ref(), __y.__ptr_ref()); + swap(__x.__mapping_ref(), __y.__mapping_ref()); + swap(__x.__accessor_ref(), __y.__accessor_ref()); + } + + //-------------------------------------------------------------------------------- + // [mdspan.basic.domobs], mdspan observers of the domain multidimensional index space + + + __MDSPAN_INLINE_FUNCTION constexpr const extents_type& extents() const noexcept { return __mapping_ref().extents(); }; + __MDSPAN_INLINE_FUNCTION constexpr const data_handle_type& data_handle() const noexcept { return __ptr_ref(); }; + __MDSPAN_INLINE_FUNCTION constexpr const mapping_type& mapping() const noexcept { return __mapping_ref(); }; + __MDSPAN_INLINE_FUNCTION constexpr const accessor_type& accessor() const noexcept { return __accessor_ref(); }; + + //-------------------------------------------------------------------------------- + // [mdspan.basic.obs], mdspan observers of the mapping + + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { return mapping_type::is_always_unique(); }; + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_exhaustive() noexcept { return mapping_type::is_always_exhaustive(); }; + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { return mapping_type::is_always_strided(); }; + + __MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const noexcept { return __mapping_ref().is_unique(); }; + __MDSPAN_INLINE_FUNCTION constexpr bool is_exhaustive() const noexcept { return __mapping_ref().is_exhaustive(); }; + __MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { return __mapping_ref().is_strided(); }; + __MDSPAN_INLINE_FUNCTION constexpr index_type stride(size_t __r) const { return __mapping_ref().stride(__r); }; + +private: + + __detail::__compressed_pair __members{}; + + __MDSPAN_FORCE_INLINE_FUNCTION constexpr data_handle_type& __ptr_ref() noexcept { return __members.__first(); } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr data_handle_type const& __ptr_ref() const noexcept { return __members.__first(); } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr mapping_type& __mapping_ref() noexcept { return __members.__second().__first(); } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr mapping_type const& __mapping_ref() const noexcept { return __members.__second().__first(); } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr accessor_type& __accessor_ref() noexcept { return __members.__second().__second(); } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr accessor_type const& __accessor_ref() const noexcept { return __members.__second().__second(); } + + template + friend class mdspan; + +}; + +#if defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) +__MDSPAN_TEMPLATE_REQUIRES( + class _ElementType, class... _SizeTypes, + /* requires */ __MDSPAN_FOLD_AND(_LIBCUDACXX_TRAIT(is_integral, _SizeTypes) /* && ... */) && + (sizeof...(_SizeTypes) > 0) +) +explicit mdspan(_ElementType*, _SizeTypes...) + -> mdspan<_ElementType, dextents>; + +__MDSPAN_TEMPLATE_REQUIRES( + class _Pointer, + (_LIBCUDACXX_TRAIT(is_pointer, _CUDA_VSTD::remove_reference_t<_Pointer>)) +) +mdspan(_Pointer&&) -> mdspan<_CUDA_VSTD::remove_pointer_t<_CUDA_VSTD::remove_reference_t<_Pointer>>, extents>; +__MDSPAN_TEMPLATE_REQUIRES( + class _CArray, + (_LIBCUDACXX_TRAIT(is_array, _CArray) && (rank_v<_CArray> == 1)) +) +mdspan(_CArray&) -> mdspan<_CUDA_VSTD::remove_all_extents_t<_CArray>, extents>>; + +template +mdspan(_ElementType*, const _CUDA_VSTD::array<_SizeType, _Np>&) + -> mdspan<_ElementType, dextents>; + +template +mdspan(_ElementType*, _CUDA_VSTD::span<_SizeType, _Np>) + -> mdspan<_ElementType, dextents>; + +// This one is necessary because all the constructors take `data_handle_type`s, not +// `_ElementType*`s, and `data_handle_type` is taken from `accessor_type::data_handle_type`, which +// seems to throw off automatic deduction guides. +template +mdspan(_ElementType*, const extents<_SizeType, _ExtentsPack...>&) + -> mdspan<_ElementType, extents<_SizeType, _ExtentsPack...>>; + +template +mdspan(_ElementType*, const _MappingType&) + -> mdspan<_ElementType, typename _MappingType::extents_type, typename _MappingType::layout_type>; + +template +mdspan(const typename _AccessorType::data_handle_type, const _MappingType&, const _AccessorType&) + -> mdspan; +#endif + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MDSPAN_MDSPAN_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h new file mode 100644 index 0000000000000000000000000000000000000000..c26892f031c1026b33292ee23ba6fb67e07ac042 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h @@ -0,0 +1,145 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX__LIBCUDACXX_NO_UNIQUE_ADDRESS_HPP +#define _LIBCUDACXX__LIBCUDACXX_NO_UNIQUE_ADDRESS_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/macros.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_empty.h" +#include "../__type_traits/is_trivially_destructible.h" +#include "../__utility/move.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +namespace __detail { + +//============================================================================== + +template +struct __no_unique_address_emulation { + using __stored_type = _Tp; + _Tp __v; + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__ref() const noexcept { + return __v; + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp &__ref() noexcept { + return __v; + } +}; + +// Empty case +// This doesn't work if _Tp is final, of course, but we're not using anything +// like that currently. That kind of thing could be added pretty easily though +template +struct __no_unique_address_emulation< + _Tp, _Disambiguator, + _CUDA_VSTD::enable_if_t<_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_empty, _Tp) && + // If the type isn't trivially destructible, its destructor + // won't be called at the right time, so don't use this + // specialization + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_trivially_destructible, _Tp)>> : +#ifdef __MDSPAN_COMPILER_MSVC + // MSVC doesn't allow you to access public static member functions of a type + // when you *happen* to privately inherit from that type. + protected +#else + // But we still want this to be private if possible so that we don't accidentally + // access members of _Tp directly rather than calling __ref() first, which wouldn't + // work if _Tp happens to be stateful and thus we're using the unspecialized definition + // of __no_unique_address_emulation above. + private +#endif + _Tp { + using __stored_type = _Tp; + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__ref() const noexcept { + return *static_cast<_Tp const *>(this); + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp &__ref() noexcept { + return *static_cast<_Tp *>(this); + } + + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __no_unique_address_emulation() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __no_unique_address_emulation( + __no_unique_address_emulation const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __no_unique_address_emulation( + __no_unique_address_emulation &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __no_unique_address_emulation & + operator=(__no_unique_address_emulation const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __no_unique_address_emulation & + operator=(__no_unique_address_emulation &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~__no_unique_address_emulation() noexcept = default; + + // Explicitly make this not a reference so that the copy or move + // constructor still gets called. + __MDSPAN_INLINE_FUNCTION + explicit constexpr __no_unique_address_emulation(_Tp const& __v) noexcept : _Tp(__v) {} + __MDSPAN_INLINE_FUNCTION + explicit constexpr __no_unique_address_emulation(_Tp&& __v) noexcept : _Tp(_CUDA_VSTD::move(__v)) {} +}; + +//============================================================================== + +} // end namespace __detail + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX__LIBCUDACXX_NO_UNIQUE_ADDRESS_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h new file mode 100644 index 0000000000000000000000000000000000000000..13d9c89f0ec22845075b80875cc725fb01c1ce2d --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h @@ -0,0 +1,699 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_STANDARD_LAYOUT_STATIC_ARRAY_HPP +#define _LIBCUDACXX___MDSPAN_STANDARD_LAYOUT_STATIC_ARRAY_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/compressed_pair.h" +#include "../__mdspan/dynamic_extent.h" +#include "../__mdspan/macros.h" +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +#include "../__mdspan/no_unique_address.h" +#endif +#include "../__type_traits/enable_if.h" +#include "../__utility/integer_sequence.h" +#include "../array" +#include "../cstddef" +#include "../span" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +namespace __detail { + +//============================================================================== + +struct __construct_psa_from_dynamic_exts_values_tag_t {}; +_LIBCUDACXX_CPO_ACCESSIBILITY __construct_psa_from_dynamic_exts_values_tag_t __construct_psa_from_dynamic_exts_values_tag; + +struct __construct_psa_from_all_exts_values_tag_t {}; +_LIBCUDACXX_CPO_ACCESSIBILITY __construct_psa_from_all_exts_values_tag_t __construct_psa_from_all_exts_values_tag; + +struct __construct_psa_from_all_exts_array_tag_t {}; +template +struct __construct_psa_from_dynamic_exts_array_tag_t {}; + +//============================================================================== + +template using __repeated_with_idxs = _Tp; + +//============================================================================== + +#if __MDSPAN_PRESERVE_STANDARD_LAYOUT + +/** + * PSA = "partially static array" + * + * @tparam _Tp + * @tparam _ValsSeq + * @tparam __sentinal + */ +template (dynamic_extent), + class _IdxsSeq = _CUDA_VSTD::make_index_sequence<_ValsSeq::size()>> +struct __standard_layout_psa; + +//============================================================================== +// Static case +template +struct __standard_layout_psa< + _Tag, _Tp, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __value, __values_or_sentinals...>, + __sentinal, _CUDA_VSTD::integer_sequence> +#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : private __no_unique_address_emulation<__standard_layout_psa< + _Tag, _Tp, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>, __sentinal, + _CUDA_VSTD::integer_sequence>> +#endif +{ + + //-------------------------------------------------------------------------- + + using __next_t = + __standard_layout_psa<_Tag, _Tp, _static_t, + _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>, + __sentinal, _CUDA_VSTD::integer_sequence>; + +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + _LIBCUDACXX_NO_UNIQUE_ADDRESS __next_t __next_; +#else + using __base_t = __no_unique_address_emulation<__next_t>; +#endif + + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t &__next() noexcept { +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + return __next_; +#else + return this->__base_t::__ref(); +#endif + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t const &__next() const noexcept { +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + return __next_; +#else + return this->__base_t::__ref(); +#endif + } + + static constexpr auto __size = sizeof...(_Idxs) + 1; + static constexpr auto __size_dynamic = __next_t::__size_dynamic; + + //-------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __standard_layout_psa() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __standard_layout_psa(__standard_layout_psa const &) noexcept = + default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __standard_layout_psa(__standard_layout_psa &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __standard_layout_psa & + operator=(__standard_layout_psa const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __standard_layout_psa & + operator=(__standard_layout_psa &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~__standard_layout_psa() noexcept = default; + + //-------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION + constexpr __standard_layout_psa( + __construct_psa_from_all_exts_values_tag_t, _Tp const & /*__val*/, + __repeated_with_idxs<_Idxs, _Tp> const &... __vals) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __construct_psa_from_all_exts_values_tag, __vals... +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { } + + template + __MDSPAN_INLINE_FUNCTION constexpr __standard_layout_psa( + __construct_psa_from_dynamic_exts_values_tag_t, + _Ts const &... __vals) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __construct_psa_from_dynamic_exts_values_tag, __vals... +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { } + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + array<_Up, _Np> const &__vals) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __vals +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { } + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_all_exts_array_tag_t const & __tag, + array<_Up, _NStatic> const &__vals) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __tag, __vals +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { } + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_dynamic_exts_array_tag_t<_IDynamic> __tag, + array<_Up, _NDynamic> const &__vals) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __tag, __vals +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { } + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + _CUDA_VSTD::span<_Up, _Np> const &__vals) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __vals +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { } + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_all_exts_array_tag_t const & __tag, + _CUDA_VSTD::span<_Up, _NStatic> const &__vals) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __tag, __vals +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { } + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_dynamic_exts_array_tag_t<_IDynamic> __tag, + _CUDA_VSTD::span<_Up, _NDynamic> const &__vals) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __tag, __vals +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { } + + template + __MDSPAN_INLINE_FUNCTION constexpr __standard_layout_psa( + __standard_layout_psa<_UTag, _Up, _static_U, _UValsSeq, __u_sentinal, _IdxsSeq> const + &__rhs) noexcept +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __rhs.__next() +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + } +#else + )}) +#endif + { } + + //-------------------------------------------------------------------------- + + // See https://godbolt.org/z/_KSDNX for a summary-by-example of why this is + // necessary. We're using inheritance here instead of an alias template + // because we have to deduce __values_or_sentinals in several places, and + // alias templates don't permit that in this context. + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr __standard_layout_psa const &__enable_psa_conversion() const + noexcept { + return *this; + } + + template = 0> + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp __get_n() const noexcept { + return __next().template __get_n<_Ip>(); + } + template = 1> + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp __get_n() const noexcept { + return __value; + } + template = 0> + __MDSPAN_FORCE_INLINE_FUNCTION constexpr void + __set_n(_Tp const &__rhs) noexcept { + __next().__set_value(__rhs); + } + template = 1> + __MDSPAN_FORCE_INLINE_FUNCTION constexpr void + __set_n(_Tp const &) noexcept { + // Don't assert here because that would break constexpr. This better + // not change anything, though + } + template = __sentinal> + __MDSPAN_FORCE_INLINE_FUNCTION static constexpr _static_t __get_static_n() noexcept { + return __value; + } + template __default = __sentinal> + __MDSPAN_FORCE_INLINE_FUNCTION static constexpr _static_t __get_static_n() noexcept { + return __next_t::template __get_static_n<_Ip, __default>(); + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp __get(size_t __n) const noexcept { + return __value * (_Tp(_Idx == __n)) + __next().__get(__n); + } + + //-------------------------------------------------------------------------- +}; + +//============================================================================== + +// Dynamic case, __next_t may or may not be empty +template +struct __standard_layout_psa< + _Tag, _Tp, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __sentinal, __values_or_sentinals...>, + __sentinal, _CUDA_VSTD::integer_sequence> { + //-------------------------------------------------------------------------- + + using __next_t = + __standard_layout_psa<_Tag, _Tp, _static_t, + _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>, + __sentinal, _CUDA_VSTD::integer_sequence>; + + using __value_pair_t = __compressed_pair<_Tp, __next_t>; + __value_pair_t __value_pair; + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t &__next() noexcept { + return __value_pair.__second(); + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t const &__next() const noexcept { + return __value_pair.__second(); + } + + static constexpr auto __size = sizeof...(_Idxs) + 1; + static constexpr auto __size_dynamic = 1 + __next_t::__size_dynamic; + + //-------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __standard_layout_psa() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __standard_layout_psa(__standard_layout_psa const &) noexcept = + default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __standard_layout_psa(__standard_layout_psa &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __standard_layout_psa & + operator=(__standard_layout_psa const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __standard_layout_psa & + operator=(__standard_layout_psa &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~__standard_layout_psa() noexcept = default; + + //-------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION + constexpr __standard_layout_psa( + __construct_psa_from_all_exts_values_tag_t, _Tp const &__val, + __repeated_with_idxs<_Idxs, _Tp> const &... __vals) noexcept + : __value_pair(__val, + __next_t(__construct_psa_from_all_exts_values_tag, + __vals...)) {} + + template + __MDSPAN_INLINE_FUNCTION constexpr __standard_layout_psa( + __construct_psa_from_dynamic_exts_values_tag_t, _Tp const &__val, + _Ts const &... __vals) noexcept + : __value_pair(__val, + __next_t(__construct_psa_from_dynamic_exts_values_tag, + __vals...)) {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + array<_Up, _Np> const &__vals) noexcept + : __value_pair(_CUDA_VSTD::get<_Idx>(__vals), __vals) {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_all_exts_array_tag_t __tag, + array<_Up, _NStatic> const &__vals) noexcept + : __value_pair( + _CUDA_VSTD::get<_Idx>(__vals), + __next_t(__tag, + __vals)) {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_dynamic_exts_array_tag_t<_IDynamic>, + array<_Up, _NDynamic> const &__vals) noexcept + : __value_pair( + _CUDA_VSTD::get<_IDynamic>(__vals), + __next_t(__construct_psa_from_dynamic_exts_array_tag_t<_IDynamic + 1>{}, + __vals)) {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + _CUDA_VSTD::span<_Up, _Np> const &__vals) noexcept + : __value_pair(__vals[_Idx], __vals) {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_all_exts_array_tag_t __tag, + _CUDA_VSTD::span<_Up, _NStatic> const &__vals) noexcept + : __value_pair( + __vals[_Idx], + __next_t(__tag, + __vals)) {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_dynamic_exts_array_tag_t<_IDynamic>, + _CUDA_VSTD::span<_Up, _NDynamic> const &__vals) noexcept + : __value_pair( + __vals[_IDynamic], + __next_t(__construct_psa_from_dynamic_exts_array_tag_t<_IDynamic + 1>{}, + __vals)) {} + + template + __MDSPAN_INLINE_FUNCTION constexpr __standard_layout_psa( + __standard_layout_psa<_UTag, _Up, _static_U, _UValsSeq, __u_sentinal, _UIdxsSeq> const + &__rhs) noexcept + : __value_pair(__rhs.template __get_n<_Idx>(), __rhs.__next()) {} + + //-------------------------------------------------------------------------- + + // See comment in the previous partial specialization for why this is + // necessary. Or just trust me that it's messy. + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr __standard_layout_psa const &__enable_psa_conversion() const + noexcept { + return *this; + } + + template = 0> + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp __get_n() const noexcept { + return __next().template __get_n<_Ip>(); + } + template = 1> + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp __get_n() const noexcept { + return __value_pair.__first(); + } + template = 0> + __MDSPAN_FORCE_INLINE_FUNCTION constexpr void + __set_n(_Tp const &__rhs) noexcept { + __next().__set_value(__rhs); + } + template = 1> + __MDSPAN_FORCE_INLINE_FUNCTION constexpr void + __set_n(_Tp const &__rhs) noexcept { + __value_pair.__first() = __rhs; + } + template __default = __sentinal> + __MDSPAN_FORCE_INLINE_FUNCTION static constexpr _static_t __get_static_n() noexcept { + return __default; + } + template __default = __sentinal> + __MDSPAN_FORCE_INLINE_FUNCTION static constexpr _static_t __get_static_n() noexcept { + return __next_t::template __get_static_n<_Ip, __default>(); + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp __get(size_t __n) const noexcept { + return __value_pair.__first() * (_Tp(_Idx == __n)) + __next().__get(__n); + } + + //-------------------------------------------------------------------------- +}; + +// empty/terminal case +template +struct __standard_layout_psa<_Tag, _Tp, _static_t, _CUDA_VSTD::integer_sequence<_static_t>, __sentinal, + _CUDA_VSTD::integer_sequence> { + //-------------------------------------------------------------------------- + + static constexpr auto __size = 0; + static constexpr auto __size_dynamic = 0; + + //-------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __standard_layout_psa() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __standard_layout_psa(__standard_layout_psa const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __standard_layout_psa(__standard_layout_psa &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __standard_layout_psa & + operator=(__standard_layout_psa const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __standard_layout_psa & + operator=(__standard_layout_psa &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~__standard_layout_psa() noexcept = default; + + __MDSPAN_INLINE_FUNCTION + constexpr __standard_layout_psa( + __construct_psa_from_all_exts_values_tag_t) noexcept {} + + template + __MDSPAN_INLINE_FUNCTION constexpr __standard_layout_psa( + __construct_psa_from_dynamic_exts_values_tag_t) noexcept {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + array<_Up, _Np> const &) noexcept {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_all_exts_array_tag_t, + array<_Up, _NStatic> const &) noexcept {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_dynamic_exts_array_tag_t<_IDynamic>, + array<_Up, _NDynamic> const &) noexcept {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + _CUDA_VSTD::span<_Up, _Np> const &) noexcept {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_all_exts_array_tag_t, + _CUDA_VSTD::span<_Up, _NStatic> const &) noexcept {} + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + __construct_psa_from_dynamic_exts_array_tag_t<_IDynamic>, + _CUDA_VSTD::span<_Up, _NDynamic> const &) noexcept {} + + template + __MDSPAN_INLINE_FUNCTION constexpr __standard_layout_psa( + __standard_layout_psa<_UTag, _Up, _static_U, _UValsSeq, __u_sentinal, _UIdxsSeq> const&) noexcept {} + + // See comment in the previous partial specialization for why this is + // necessary. Or just trust me that it's messy. + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr __standard_layout_psa const &__enable_psa_conversion() const + noexcept { + return *this; + } + + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp __get(size_t /*n*/) const noexcept { + return 0; + } +}; + +// Same thing, but with a disambiguator so that same-base issues doesn't cause +// a loss of standard-layout-ness. +template +struct __partially_static_sizes_tagged + : __standard_layout_psa< + _Tag, T, _static_t, + _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>> { + using __tag_t = _Tag; + using __psa_impl_t = __standard_layout_psa< + _Tag, T, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>>; +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || defined(_LIBCUDACXX_CUDACC_BELOW_11_3) + template = 0> + __MDSPAN_FORCE_INLINE_FUNCTION constexpr + __partially_static_sizes_tagged(_Args&&... __args) noexcept(noexcept(__psa_impl_t(_CUDA_VSTD::declval<_Args>()...))) + : __psa_impl_t(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __psa_impl_t::__psa_impl_t; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 +#ifdef __MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND + __MDSPAN_INLINE_FUNCTION +#endif + constexpr __partially_static_sizes_tagged() noexcept +#ifdef __MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND + : __psa_impl_t() { } +#else + = default; +#endif + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __partially_static_sizes_tagged( + __partially_static_sizes_tagged const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __partially_static_sizes_tagged( + __partially_static_sizes_tagged &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __partially_static_sizes_tagged & + operator=(__partially_static_sizes_tagged const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __partially_static_sizes_tagged & + operator=(__partially_static_sizes_tagged &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~__partially_static_sizes_tagged() noexcept = default; + + template + __MDSPAN_FORCE_INLINE_FUNCTION constexpr explicit __partially_static_sizes_tagged( + __partially_static_sizes_tagged<_UTag, T, _static_t, __values_or_sentinals...> const& __vals + ) noexcept : __psa_impl_t(__vals.__enable_psa_conversion()) { } +}; + +struct __no_tag {}; +template +struct __partially_static_sizes + : __partially_static_sizes_tagged<__no_tag, T, _static_t, __values_or_sentinals...> { +private: + using __base_t = + __partially_static_sizes_tagged<__no_tag, T, _static_t, __values_or_sentinals...>; + template + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __partially_static_sizes( + __partially_static_sizes_tagged<_UTag, T, _static_t, __values_or_sentinals...>&& __vals + ) noexcept : __base_t(_CUDA_VSTD::move(__vals)) { } +public: +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || defined(_LIBCUDACXX_CUDACC_BELOW_11_3) + template = 0> + __MDSPAN_FORCE_INLINE_FUNCTION constexpr + __partially_static_sizes(_Args&&... __args) noexcept(noexcept(__base_t(_CUDA_VSTD::declval<_Args>()...))) + : __base_t(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base_t::__base_t; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + +#ifdef __MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND + __MDSPAN_INLINE_FUNCTION + constexpr __partially_static_sizes() noexcept : __base_t() { } +#endif + template + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __partially_static_sizes_tagged< + _UTag, T, _static_t, __values_or_sentinals...> + __with_tag() const noexcept { + return __partially_static_sizes_tagged<_UTag, T, _static_t, __values_or_sentinals...>(*this); + } +}; + +#endif // __MDSPAN_PRESERVE_STATIC_LAYOUT + +} // end namespace __detail + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MDSPAN_STANDARD_LAYOUT_STATIC_ARRAY_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h new file mode 100644 index 0000000000000000000000000000000000000000..84df90d64c14b5eb2305c0c90b822ffe92982d22 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h @@ -0,0 +1,321 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_STATIC_ARRAY_HPP +#define _LIBCUDACXX___MDSPAN_STATIC_ARRAY_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__fwd/span.h" // dynamic_extent +#include "../__mdspan/dynamic_extent.h" +#include "../__mdspan/macros.h" +#include "../__mdspan/maybe_static_value.h" +#include "../__mdspan/standard_layout_static_array.h" +#include "../__mdspan/type_list.h" +#include "../__utility/integer_sequence.h" +#include "../array" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if !__MDSPAN_PRESERVE_STANDARD_LAYOUT + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +namespace __detail { + +//============================================================================== + +template struct __mask_element {}; + +template +struct __mask_sequence_assign_op { + template <_Tp _V> + __mask_sequence_assign_op<_Tp, _Result..., _V> + operator=(__mask_element<_Tp, _V, true>&&); + template <_Tp _V> + __mask_sequence_assign_op<_Tp, _Result...> + operator=(__mask_element<_Tp, _V, false>&&); + using __result = _CUDA_VSTD::integer_sequence<_Tp, _Result...>; +}; + +template +struct __mask_sequence; + +template +struct __mask_sequence<_CUDA_VSTD::integer_sequence<_Tp, _Vals...>, _CUDA_VSTD::integer_sequence> +{ + using type = typename decltype( + __MDSPAN_FOLD_ASSIGN_LEFT( + __mask_sequence_assign_op<_Tp>{}, /* = ... = */ __mask_element<_Tp, _Vals, _Masks>{} + ) + )::__result; +}; + +//============================================================================== + +template +class __partially_static_array_impl; + +template < + class _Tp, class _static_t, + _static_t... __values_or_sentinals, _static_t __sentinal, + size_t... _Idxs, + size_t... _IdxsDynamic, + size_t... _IdxsDynamicIdxs +> +class __partially_static_array_impl< + _Tp, + _static_t, + _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>, + __sentinal, + _CUDA_VSTD::integer_sequence, + _CUDA_VSTD::integer_sequence, + _CUDA_VSTD::integer_sequence +> + : private __maybe_static_value<_Tp, _static_t, __values_or_sentinals, __sentinal, + _Idxs>... { +private: + + template + using __base_n = typename __type_at<_Np, + __type_list<__maybe_static_value<_Tp, _static_t, __values_or_sentinals, __sentinal, _Idxs>...> + >::type; + +public: + + static constexpr auto __size = sizeof...(_Idxs); + static constexpr auto __size_dynamic = + __MDSPAN_FOLD_PLUS_RIGHT(static_cast((__values_or_sentinals == __sentinal)), /* + ... + */ 0); + + //-------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __partially_static_array_impl() = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __partially_static_array_impl( + __partially_static_array_impl const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + constexpr __partially_static_array_impl( + __partially_static_array_impl &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __partially_static_array_impl & + operator=(__partially_static_array_impl const &) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + __MDSPAN_CONSTEXPR_14_DEFAULTED __partially_static_array_impl & + operator=(__partially_static_array_impl &&) noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED + ~__partially_static_array_impl() noexcept = default; + + __MDSPAN_INLINE_FUNCTION + constexpr __partially_static_array_impl( + __construct_psa_from_all_exts_values_tag_t, + __repeated_with_idxs<_Idxs, _Tp> const &... __vals) noexcept + : __base_n<_Idxs>(__base_n<_Idxs>{{__vals}})... {} + + __MDSPAN_INLINE_FUNCTION + constexpr __partially_static_array_impl( + __construct_psa_from_dynamic_exts_values_tag_t, + __repeated_with_idxs<_IdxsDynamicIdxs, _Tp> const &... __vals) noexcept + : __base_n<_IdxsDynamic>(__base_n<_IdxsDynamic>{{__vals}})... {} + + __MDSPAN_INLINE_FUNCTION constexpr explicit __partially_static_array_impl( + _CUDA_VSTD::array<_Tp, sizeof...(_Idxs)> const& __vals) noexcept + : __partially_static_array_impl( + __construct_psa_from_all_exts_values_tag, + _CUDA_VSTD::get<_Idxs>(__vals)...) {} + + // clang-format off + __MDSPAN_FUNCTION_REQUIRES( + (__MDSPAN_INLINE_FUNCTION constexpr explicit), + __partially_static_array_impl, + (_CUDA_VSTD::array<_Tp, __size_dynamic> const &__vals), noexcept, + /* requires */ + (sizeof...(_Idxs) != __size_dynamic) + ): __partially_static_array_impl( + __construct_psa_from_dynamic_exts_values_tag, + _CUDA_VSTD::get<_IdxsDynamicIdxs>(__vals)...) {} + // clang-format on + + template + __MDSPAN_INLINE_FUNCTION constexpr __partially_static_array_impl( + __partially_static_array_impl< + _Up, _static_u, _UValsSeq, __u_sentinal, _UIdxsSeq, + _UIdxsDynamicSeq, _UIdxsDynamicIdxsSeq> const &__rhs) noexcept + : __partially_static_array_impl( + __construct_psa_from_all_exts_values_tag, + __rhs.template __get_n<_Idxs>()...) {} + + //-------------------------------------------------------------------------- + + // See comment in the previous partial specialization for why this is + // necessary. Or just trust me that it's messy. + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr __partially_static_array_impl const &__enable_psa_conversion() const + noexcept { + return *this; + } + + template + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp __get_n() const noexcept { + return static_cast<__base_n<_Ip> const*>(this)->__value(); + } + + template + __MDSPAN_FORCE_INLINE_FUNCTION constexpr void __set_n(_Up&& __rhs) noexcept { + static_cast<__base_n<_Ip>*>(this)->__set_value((_Up&&)__rhs); + } + + template + __MDSPAN_FORCE_INLINE_FUNCTION static constexpr _static_t + __get_static_n() noexcept { + return __base_n<_Ip>::__static_value == __sentinal ? + __default : __base_n<_Ip>::__static_value; + } + + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp + __get(size_t __n) const noexcept { + return __MDSPAN_FOLD_PLUS_RIGHT( + (_Tp(_Idxs == __n) * __get_n<_Idxs>()), /* + ... + */ _Tp(0) + ); + } + +}; + +//============================================================================== + +template > +struct __partially_static_array_impl_maker; + +template < + class _Tp, class _static_t, _static_t... _Vals, _static_t __sentinal, size_t... _Idxs +> +struct __partially_static_array_impl_maker< + _Tp, _static_t, _CUDA_VSTD::integer_sequence<_static_t, _Vals...>, __sentinal, _CUDA_VSTD::integer_sequence +> +{ + using __dynamic_idxs = typename __mask_sequence< + _CUDA_VSTD::integer_sequence, + _CUDA_VSTD::integer_sequence + >::type; + using __impl_base = + __partially_static_array_impl<_Tp, _static_t, + _CUDA_VSTD::integer_sequence<_static_t, _Vals...>, + __sentinal, _CUDA_VSTD::integer_sequence, + __dynamic_idxs, + _CUDA_VSTD::make_index_sequence<__dynamic_idxs::size()> + >; +}; + +template +class __partially_static_array_with_sentinal + : public __partially_static_array_impl_maker<_Tp, _static_t, _ValsSeq, __sentinal>::__impl_base +{ +private: + using __base_t = typename __partially_static_array_impl_maker<_Tp, _static_t, _ValsSeq, __sentinal>::__impl_base; +public: +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || defined(_LIBCUDACXX_CUDACC_BELOW_11_3) + constexpr __partially_static_array_with_sentinal() = default; + + template + __MDSPAN_FORCE_INLINE_FUNCTION constexpr + __partially_static_array_with_sentinal(_Args&&... __args) noexcept(noexcept(__base_t(_CUDA_VSTD::declval<_Args>()...))) + : __base_t(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base_t::__base_t; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 +}; + +//============================================================================== + +template +struct __partially_static_sizes : + __partially_static_array_with_sentinal< + T, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>> +{ +private: + using __base_t = __partially_static_array_with_sentinal< + T, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>>; +public: +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || defined(_LIBCUDACXX_CUDACC_BELOW_11_3) + constexpr __partially_static_sizes() = default; + + template + __MDSPAN_FORCE_INLINE_FUNCTION constexpr + __partially_static_sizes(_Args&&... __args) noexcept(noexcept(__base_t(_CUDA_VSTD::declval<_Args>()...))) + : __base_t(_CUDA_VSTD::forward<_Args>(__args)...) + {} +#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv + using __base_t::__base_t; +#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 + template + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __partially_static_sizes + __with_tag() const noexcept { + return *this; + } +}; + +// Tags are needed for the standard layout version, but not here +template +using __partially_static_sizes_tagged = __partially_static_sizes; + +} // end namespace __detail + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // !__MDSPAN_PRESERVE_STANDARD_LAYOUT + +#endif // _LIBCUDACXX___MDSPAN_STATIC_ARRAY_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h new file mode 100644 index 0000000000000000000000000000000000000000..b551fab61a88b8f8e247d4a424ec0b08b4f271a0 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h @@ -0,0 +1,605 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + + +#ifndef _LIBCUDACXX___MDSPAN_SUBMDSPAN_HPP +#define _LIBCUDACXX___MDSPAN_SUBMDSPAN_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/dynamic_extent.h" +#include "../__mdspan/full_extent_t.h" +#include "../__mdspan/layout_left.h" +#include "../__mdspan/layout_right.h" +#include "../__mdspan/layout_stride.h" +#include "../__mdspan/macros.h" +#include "../__mdspan/mdspan.h" +#include "../__type_traits/conditional.h" +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_same.h" +#include "../__type_traits/is_signed.h" +#include "../__type_traits/remove_const.h" +#include "../__type_traits/remove_reference.h" +#include "../__utility/move.h" +#include "../__utility/pair.h" +#include "../tuple" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +namespace __detail { + +template +struct __slice_wrap { + _Tp slice; + size_t old_extent; + size_t old_stride; +}; + +//-------------------------------------------------------------------------------- + +template +__MDSPAN_INLINE_FUNCTION constexpr +__slice_wrap<_OldExtent, _OldStaticStride, size_t> +__wrap_slice(size_t __val, size_t __ext, size_t __stride) { return { __val, __ext, __stride }; } + +template +__MDSPAN_INLINE_FUNCTION constexpr +__slice_wrap<_OldExtent, _OldStaticStride, integral_constant<_IntegerType, _Value0>> +__wrap_slice(size_t __val, size_t __ext, integral_constant<_IntegerType, _Value0> __stride) +{ +#if __MDSPAN_HAS_CXX_17 + if constexpr (_CUDA_VSTD::is_signed_v<_IntegerType>) { + static_assert(_Value0 >= _IntegerType(0), "Invalid slice specifier"); + } +#endif // __MDSPAN_HAS_CXX_17 + + return { __val, __ext, __stride }; +} + +template +__MDSPAN_INLINE_FUNCTION constexpr +__slice_wrap<_OldExtent, _OldStaticStride, full_extent_t> +__wrap_slice(full_extent_t __val, size_t __ext, size_t __stride) { return { __val, __ext, __stride }; } + +// TODO generalize this to anything that works with get<0> and get<1> +template +__MDSPAN_INLINE_FUNCTION constexpr +__slice_wrap<_OldExtent, _OldStaticStride, _CUDA_VSTD::tuple> +__wrap_slice(_CUDA_VSTD::tuple const& __val, size_t __ext, size_t __stride) +{ + return { __val, __ext, __stride }; +} + +template +__MDSPAN_INLINE_FUNCTION constexpr + __slice_wrap<_OldExtent, _OldStaticStride, + _CUDA_VSTD::tuple, + integral_constant<_IntegerType1, _Value1>>> +__wrap_slice(_CUDA_VSTD::tuple, integral_constant<_IntegerType1, _Value1>> const& __val, size_t __ext, size_t __stride) +{ + static_assert(_Value1 >= _Value0, "Invalid slice tuple"); + return { __val, __ext, __stride }; +} + +//-------------------------------------------------------------------------------- + + +// a layout right remains a layout right if it is indexed by 0 or more scalars, +// then optionally a pair and finally 0 or more all +template < + // what we encountered until now preserves the layout right + bool _Result=true, + // we only encountered 0 or more scalars, no pair or all + bool _EncounteredOnlyScalar=true +> +struct preserve_layout_right_analysis : integral_constant { + using layout_type_if_preserved = layout_right; + using encounter_pair = preserve_layout_right_analysis< + // if we encounter a pair, the layout remains a layout right only if it was one before + // and that only scalars were encountered until now + _Result && _EncounteredOnlyScalar, + // if we encounter a pair, we didn't encounter scalars only + false + >; + using encounter_all = preserve_layout_right_analysis< + // if we encounter a all, the layout remains a layout right if it was one before + _Result, + // if we encounter a all, we didn't encounter scalars only + false + >; + using encounter_scalar = preserve_layout_right_analysis< + // if we encounter a scalar, the layout remains a layout right only if it was one before + // and that only scalars were encountered until now + _Result && _EncounteredOnlyScalar, + // if we encounter a scalar, the fact that we encountered scalars only doesn't change + _EncounteredOnlyScalar + >; +}; + +// a layout left remains a layout left if it is indexed by 0 or more all, +// then optionally a pair and finally 0 or more scalars +template < + bool _Result=true, + bool _EncounteredOnlyAll=true +> +struct preserve_layout_left_analysis : integral_constant { + using layout_type_if_preserved = layout_left; + using encounter_pair = preserve_layout_left_analysis< + // if we encounter a pair, the layout remains a layout left only if it was one before + // and that only all were encountered until now + _Result && _EncounteredOnlyAll, + // if we encounter a pair, we didn't encounter all only + false + >; + using encounter_all = preserve_layout_left_analysis< + // if we encounter a all, the layout remains a layout left only if it was one before + // and that only all were encountered until now + _Result && _EncounteredOnlyAll, + // if we encounter a all, the fact that we encountered scalars all doesn't change + _EncounteredOnlyAll + >; + using encounter_scalar = preserve_layout_left_analysis< + // if we encounter a scalar, the layout remains a layout left if it was one before + _Result, + // if we encounter a scalar, we didn't encounter scalars only + false + >; +}; + +struct ignore_layout_preservation : integral_constant { + using layout_type_if_preserved = void; + using encounter_pair = ignore_layout_preservation; + using encounter_all = ignore_layout_preservation; + using encounter_scalar = ignore_layout_preservation; +}; + +template +struct preserve_layout_analysis + : ignore_layout_preservation { }; +template <> +struct preserve_layout_analysis + : preserve_layout_right_analysis<> { }; +template <> +struct preserve_layout_analysis + : preserve_layout_left_analysis<> { }; + +//-------------------------------------------------------------------------------- + +template < + class _IndexT, + class _PreserveLayoutAnalysis, + class _OffsetsArray=__partially_static_sizes<_IndexT, size_t>, + class _ExtsArray=__partially_static_sizes<_IndexT, size_t>, + class _StridesArray=__partially_static_sizes<_IndexT, size_t>, + class = _CUDA_VSTD::make_index_sequence<_OffsetsArray::__size>, + class = _CUDA_VSTD::make_index_sequence<_ExtsArray::__size>, + class = _CUDA_VSTD::make_index_sequence<_StridesArray::__size> +> +struct __assign_op_slice_handler; + +/* clang-format: off */ +template < + class _IndexT, + class _PreserveLayoutAnalysis, + size_t... _Offsets, + size_t... _Exts, + size_t... _Strides, + size_t... _OffsetIdxs, + size_t... _ExtIdxs, + size_t... _StrideIdxs> +struct __assign_op_slice_handler< + _IndexT, + _PreserveLayoutAnalysis, + __partially_static_sizes<_IndexT, size_t, _Offsets...>, + __partially_static_sizes<_IndexT, size_t, _Exts...>, + __partially_static_sizes<_IndexT, size_t, _Strides...>, + _CUDA_VSTD::integer_sequence, + _CUDA_VSTD::integer_sequence, + _CUDA_VSTD::integer_sequence> +{ + // TODO remove this for better compiler performance + static_assert( + __MDSPAN_FOLD_AND((_Strides == dynamic_extent || _Strides > 0) /* && ... */), + " " + ); + static_assert( + __MDSPAN_FOLD_AND((_Offsets == dynamic_extent || _Offsets >= 0) /* && ... */), + " " + ); + + using __offsets_storage_t = __partially_static_sizes<_IndexT, size_t, _Offsets...>; + using __extents_storage_t = __partially_static_sizes<_IndexT, size_t, _Exts...>; + using __strides_storage_t = __partially_static_sizes<_IndexT, size_t, _Strides...>; + __offsets_storage_t __offsets; + __extents_storage_t __exts; + __strides_storage_t __strides; + +#ifdef __INTEL_COMPILER +#if __INTEL_COMPILER <= 1800 + __MDSPAN_INLINE_FUNCTION constexpr __assign_op_slice_handler(__assign_op_slice_handler&& __other) noexcept + : __offsets(_CUDA_VSTD::move(__other.__offsets)), __exts(_CUDA_VSTD::move(__other.__exts)), __strides(_CUDA_VSTD::move(__other.__strides)) + { } + __MDSPAN_INLINE_FUNCTION constexpr __assign_op_slice_handler( + __offsets_storage_t&& __o, + __extents_storage_t&& __e, + __strides_storage_t&& __s + ) noexcept + : __offsets(_CUDA_VSTD::move(__o)), __exts(_CUDA_VSTD::move(__e)), __strides(_CUDA_VSTD::move(__s)) + { } +#endif +#endif + +// Don't define this unless we need it; they have a cost to compile +#ifndef __MDSPAN_USE_RETURN_TYPE_DEDUCTION + using __extents_type = _CUDA_VSTD::extents<_IndexT, _Exts...>; +#endif + + // For size_t slice, skip the extent and stride, but add an offset corresponding to the value + template + __MDSPAN_FORCE_INLINE_FUNCTION // NOLINT (misc-unconventional-assign-operator) + constexpr auto + operator=(__slice_wrap<_OldStaticExtent, _OldStaticStride, size_t>&& __slice) noexcept + -> __assign_op_slice_handler< + _IndexT, + typename _PreserveLayoutAnalysis::encounter_scalar, + __partially_static_sizes<_IndexT, size_t, _Offsets..., dynamic_extent>, + __partially_static_sizes<_IndexT, size_t, _Exts...>, + __partially_static_sizes<_IndexT, size_t, _Strides...>/* intentional space here to work around ICC bug*/> { + return { + __partially_static_sizes<_IndexT, size_t, _Offsets..., dynamic_extent>( + __construct_psa_from_all_exts_values_tag, + __offsets.template __get_n<_OffsetIdxs>()..., __slice.slice), + _CUDA_VSTD::move(__exts), + _CUDA_VSTD::move(__strides) + }; + } + + // Treat integral_constant slice like size_t slice, but with a compile-time offset. + // The result's extents_type can't take advantage of that, + // but it might help for specialized layouts. + template + __MDSPAN_FORCE_INLINE_FUNCTION // NOLINT (misc-unconventional-assign-operator) + constexpr auto + operator=(__slice_wrap<_OldStaticExtent, _OldStaticStride, integral_constant<_IntegerType, _Value0>>&&) noexcept + -> __assign_op_slice_handler< + _IndexT, + typename _PreserveLayoutAnalysis::encounter_scalar, + __partially_static_sizes<_IndexT, size_t, _Offsets..., _Value0>, + __partially_static_sizes<_IndexT, size_t, _Exts...>, + __partially_static_sizes<_IndexT, size_t, _Strides...>/* intentional space here to work around ICC bug*/> { +#if __MDSPAN_HAS_CXX_17 + if constexpr (_CUDA_VSTD::is_signed_v<_IntegerType>) { + static_assert(_Value0 >= _IntegerType(0), "Invalid slice specifier"); + } +#endif // __MDSPAN_HAS_CXX_17 + return { + __partially_static_sizes<_IndexT, size_t, _Offsets..., _Value0>( + __construct_psa_from_all_exts_values_tag, + __offsets.template __get_n<_OffsetIdxs>()..., size_t(_Value0)), + _CUDA_VSTD::move(__exts), + _CUDA_VSTD::move(__strides) + }; + } + + // For a _CUDA_VSTD::full_extent, offset 0 and old extent + template + __MDSPAN_FORCE_INLINE_FUNCTION // NOLINT (misc-unconventional-assign-operator) + constexpr auto + operator=(__slice_wrap<_OldStaticExtent, _OldStaticStride, full_extent_t>&& __slice) noexcept + -> __assign_op_slice_handler< + _IndexT, + typename _PreserveLayoutAnalysis::encounter_all, + __partially_static_sizes<_IndexT, size_t, _Offsets..., 0>, + __partially_static_sizes<_IndexT, size_t, _Exts..., _OldStaticExtent>, + __partially_static_sizes<_IndexT, size_t, _Strides..., _OldStaticStride>/* intentional space here to work around ICC bug*/> { + return { + __partially_static_sizes<_IndexT, size_t, _Offsets..., 0>( + __construct_psa_from_all_exts_values_tag, + __offsets.template __get_n<_OffsetIdxs>()..., size_t(0)), + __partially_static_sizes<_IndexT, size_t, _Exts..., _OldStaticExtent>( + __construct_psa_from_all_exts_values_tag, + __exts.template __get_n<_ExtIdxs>()..., __slice.old_extent), + __partially_static_sizes<_IndexT, size_t, _Strides..., _OldStaticStride>( + __construct_psa_from_all_exts_values_tag, + __strides.template __get_n<_StrideIdxs>()..., __slice.old_stride) + }; + } + + // For a _CUDA_VSTD::tuple, add an offset and add a new dynamic extent (strides still preserved) + template + __MDSPAN_FORCE_INLINE_FUNCTION // NOLINT (misc-unconventional-assign-operator) + constexpr auto + operator=(__slice_wrap<_OldStaticExtent, _OldStaticStride, tuple>&& __slice) noexcept + -> __assign_op_slice_handler< + _IndexT, + typename _PreserveLayoutAnalysis::encounter_pair, + __partially_static_sizes<_IndexT, size_t, _Offsets..., dynamic_extent>, + __partially_static_sizes<_IndexT, size_t, _Exts..., dynamic_extent>, + __partially_static_sizes<_IndexT, size_t, _Strides..., _OldStaticStride>/* intentional space here to work around ICC bug*/> { + return { + __partially_static_sizes<_IndexT, size_t, _Offsets..., dynamic_extent>( + __construct_psa_from_all_exts_values_tag, + __offsets.template __get_n<_OffsetIdxs>()..., _CUDA_VSTD::get<0>(__slice.slice)), + __partially_static_sizes<_IndexT, size_t, _Exts..., dynamic_extent>( + __construct_psa_from_all_exts_values_tag, + __exts.template __get_n<_ExtIdxs>()..., _CUDA_VSTD::get<1>(__slice.slice) - _CUDA_VSTD::get<0>(__slice.slice)), + __partially_static_sizes<_IndexT, size_t, _Strides..., _OldStaticStride>( + __construct_psa_from_all_exts_values_tag, + __strides.template __get_n<_StrideIdxs>()..., __slice.old_stride) + }; + } + + // For a _CUDA_VSTD::tuple of two integral_constant, do something like + // we did above for a tuple of two size_t, but make sure the + // result's extents type make the values compile-time constants. + template + __MDSPAN_FORCE_INLINE_FUNCTION // NOLINT (misc-unconventional-assign-operator) + constexpr auto + operator=(__slice_wrap<_OldStaticExtent, _OldStaticStride, tuple, integral_constant<_IntegerType1, _Value1>>>&& __slice) noexcept + -> __assign_op_slice_handler< + _IndexT, + typename _PreserveLayoutAnalysis::encounter_pair, + __partially_static_sizes<_IndexT, size_t, _Offsets..., size_t(_Value0)>, + __partially_static_sizes<_IndexT, size_t, _Exts..., size_t(_Value1 - _Value0)>, + __partially_static_sizes<_IndexT, size_t, _Strides..., _OldStaticStride>/* intentional space here to work around ICC bug*/> { + static_assert(_Value1 >= _Value0, "Invalid slice specifier"); + return { + // We're still turning the template parameters _Value0 and _Value1 + // into (constexpr) run-time values here. + __partially_static_sizes<_IndexT, size_t, _Offsets..., size_t(_Value0) > ( + __construct_psa_from_all_exts_values_tag, + __offsets.template __get_n<_OffsetIdxs>()..., _Value0), + __partially_static_sizes<_IndexT, size_t, _Exts..., size_t(_Value1 - _Value0) > ( + __construct_psa_from_all_exts_values_tag, + __exts.template __get_n<_ExtIdxs>()..., _Value1 - _Value0), + __partially_static_sizes<_IndexT, size_t, _Strides..., _OldStaticStride>( + __construct_psa_from_all_exts_values_tag, + __strides.template __get_n<_StrideIdxs>()..., __slice.old_stride) + }; + } + + // TODO defer instantiation of this? + using layout_type = conditional_t< + _PreserveLayoutAnalysis::value, + typename _PreserveLayoutAnalysis::layout_type_if_preserved, + layout_stride + >; + + // TODO noexcept specification + template + __MDSPAN_INLINE_FUNCTION + __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( + ( + constexpr /* auto */ + _make_layout_mapping_impl(NewLayout) noexcept + ), + ( + /* not layout stride, so don't pass dynamic_strides */ + /* return */ typename NewLayout::template mapping<_CUDA_VSTD::extents<_IndexT, _Exts...>>( + extents<_IndexT, _Exts...>::__make_extents_impl(_CUDA_VSTD::move(__exts)) + ) /* ; */ + ) + ) + + __MDSPAN_INLINE_FUNCTION + __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( + ( + constexpr /* auto */ + _make_layout_mapping_impl(layout_stride) noexcept + ), + ( + /* return */ layout_stride::template mapping<_CUDA_VSTD::extents<_IndexT, _Exts...>> + ::__make_mapping(_CUDA_VSTD::move(__exts), _CUDA_VSTD::move(__strides)) /* ; */ + ) + ) + + template // mostly for deferred instantiation, but maybe we'll use this in the future + __MDSPAN_INLINE_FUNCTION + __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( + ( + constexpr /* auto */ + make_layout_mapping(_OldLayoutMapping const&) noexcept + ), + ( + /* return */ this->_make_layout_mapping_impl(layout_type{}) /* ; */ + ) + ) +}; + +//============================================================================== + +#if __MDSPAN_USE_RETURN_TYPE_DEDUCTION +// Forking this because the C++11 version will be *completely* unreadable +template +__MDSPAN_INLINE_FUNCTION +constexpr auto _submdspan_impl( + _CUDA_VSTD::integer_sequence, + mdspan<_ET, _CUDA_VSTD::extents<_ST, _Exts...>, _LP, _AP> const& __src, + _SliceSpecs&&... __slices +) noexcept +{ + using __index_t = _ST; + auto __handled = + __MDSPAN_FOLD_ASSIGN_LEFT( + ( + __detail::__assign_op_slice_handler< + __index_t, + __detail::preserve_layout_analysis<_LP> + >{ + __partially_static_sizes<__index_t, size_t>{}, + __partially_static_sizes<__index_t, size_t>{}, + __partially_static_sizes<__index_t, size_t>{} + } + ), + /* = ... = */ + __detail::__wrap_slice< + _Exts, dynamic_extent + >( + __slices, __src.extents().template __extent<_Idxs>(), + __src.mapping().stride(_Idxs) + ) + ); + + size_t __offset_size = __src.mapping()(__handled.__offsets.template __get_n<_Idxs>()...); + auto __offset_ptr = __src.accessor().offset(__src.data_handle(), __offset_size); + auto __map = __handled.make_layout_mapping(__src.mapping()); + auto __acc_pol = typename _AP::offset_policy(__src.accessor()); + return mdspan< + _ET, remove_const_t<_CUDA_VSTD::remove_reference_t>, + typename decltype(__handled)::layout_type, remove_const_t<_CUDA_VSTD::remove_reference_t> + >( + _CUDA_VSTD::move(__offset_ptr), _CUDA_VSTD::move(__map), _CUDA_VSTD::move(__acc_pol) + ); +} +#else + +template +auto _submdspan_impl_helper(_Src&& __src, _Handled&& __h, _CUDA_VSTD::integer_sequence) + -> mdspan< + _ET, typename _Handled::__extents_type, typename _Handled::layout_type, typename _AP::offset_policy + > +{ + return { + __src.accessor().offset(__src.data_handle(), __src.mapping()(__h.__offsets.template __get_n<_Idxs>()...)), + __h.make_layout_mapping(__src.mapping()), + typename _AP::offset_policy(__src.accessor()) + }; +} + +template +__MDSPAN_INLINE_FUNCTION +__MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( + ( + constexpr /* auto */ _submdspan_impl( + _CUDA_VSTD::integer_sequence __seq, + mdspan<_ET, _CUDA_VSTD::extents<_ST, _Exts...>, _LP, _AP> const& __src, + _SliceSpecs&&... __slices + ) noexcept + ), + ( + /* return */ _submdspan_impl_helper<_ET, _AP>( + __src, + __MDSPAN_FOLD_ASSIGN_LEFT( + ( + __detail::__assign_op_slice_handler< + size_t, + __detail::preserve_layout_analysis<_LP> + >{ + __partially_static_sizes<_ST, size_t>{}, + __partially_static_sizes<_ST, size_t>{}, + __partially_static_sizes<_ST, size_t>{} + } + ), + /* = ... = */ + __detail::__wrap_slice< + _Exts, dynamic_extent + >( + __slices, __src.extents().template __extent<_Idxs>(), __src.mapping().stride(_Idxs) + ) + ), + __seq + ) /* ; */ + ) +) + +#endif + +template struct _is_layout_stride : false_type { }; +template<> +struct _is_layout_stride< + layout_stride +> : true_type +{ }; + +} // namespace __detail + +//============================================================================== + +__MDSPAN_TEMPLATE_REQUIRES( + class _ET, class _EXT, class _LP, class _AP, class... _SliceSpecs, + /* requires */ ( + ( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_same, _LP, layout_left) + || _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_same, _LP, layout_right) + || __detail::_is_layout_stride<_LP>::value + ) && + __MDSPAN_FOLD_AND(( + _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SliceSpecs, size_t) + || _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SliceSpecs, tuple) + || _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_convertible, _SliceSpecs, full_extent_t) + ) /* && ... */) && + sizeof...(_SliceSpecs) == _EXT::rank() + ) +) +__MDSPAN_INLINE_FUNCTION +__MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( + ( + constexpr submdspan( + mdspan<_ET, _EXT, _LP, _AP> const& __src, _SliceSpecs... __slices + ) noexcept + ), + ( + /* return */ + __detail::_submdspan_impl(_CUDA_VSTD::make_index_sequence{}, __src, __slices...) /*;*/ + ) +) +/* clang-format: on */ + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MDSPAN_SUBMDSPAN_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h new file mode 100644 index 0000000000000000000000000000000000000000..bd9389d05cc9b44e6ee7c2af49a288a959acfbfd --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h @@ -0,0 +1,132 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_TYPE_LIST_HPP +#define _LIBCUDACXX___MDSPAN_TYPE_LIST_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/macros.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +//============================================================================== + +namespace __detail { + +template struct __type_list { static constexpr auto __size = sizeof...(_Ts); }; + +// Implementation of type_list at() that's heavily optimized for small typelists +template struct __type_at; +template > struct __type_at_large_impl; + +template +struct __type_at_entry { }; + +template +struct __type_at_assign_op_ignore_rest { + template + _LIBCUDACXX_HOST_DEVICE + __type_at_assign_op_ignore_rest<_Result> operator=(_Tp&&); + using type = _Result; +}; + +struct __type_at_assign_op_impl { + template + _LIBCUDACXX_HOST_DEVICE + __type_at_assign_op_impl operator=(__type_at_entry<_Ip, _Idx, _Tp>&&); + template + _LIBCUDACXX_HOST_DEVICE + __type_at_assign_op_ignore_rest<_Tp> operator=(__type_at_entry<_Ip, _Ip, _Tp>&&); +}; + +template +struct __type_at_large_impl<_Ip, __type_list<_Ts...>, _CUDA_VSTD::integer_sequence> + : decltype( + __MDSPAN_FOLD_ASSIGN_LEFT(__type_at_assign_op_impl{}, /* = ... = */ __type_at_entry<_Ip, _Idxs, _Ts>{}) + ) +{ }; + +template +struct __type_at<_Ip, __type_list<_Ts...>> + : __type_at_large_impl<_Ip, __type_list<_Ts...>> +{ }; + +template +struct __type_at<0, __type_list<_T0, _Ts...>> { + using type = _T0; +}; + +template +struct __type_at<1, __type_list<_T0, _T1, _Ts...>> { + using type = _T1; +}; + +template +struct __type_at<2, __type_list<_T0, _T1, _T2, _Ts...>> { + using type = _T2; +}; + +template +struct __type_at<3, __type_list<_T0, _T1, _T2, _T3, _Ts...>> { + using type = _T3; +}; + + +} // namespace __detail + +//============================================================================== + +#endif // _LIBCUDACXX_STD_VER > 11 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MDSPAN_TYPE_LIST_HPP diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__memory/addressof.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__memory/addressof.h new file mode 100644 index 0000000000000000000000000000000000000000..6beb6588c441e2ad2ecf35dd91dea24e266a3d5b --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__memory/addressof.h @@ -0,0 +1,96 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___MEMORY_ADDRESSOF_H +#define _LIBCUDACXX___MEMORY_ADDRESSOF_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +// addressof +// NVCXX has the builtin defined but did not mark it as supported +#if defined(_LIBCUDACXX_ADDRESSOF) + +template +inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +_LIBCUDACXX_NO_CFI _LIBCUDACXX_INLINE_VISIBILITY +_Tp* +addressof(_Tp& __x) _NOEXCEPT +{ + return __builtin_addressof(__x); +} + +#else + +template +inline _LIBCUDACXX_NO_CFI _LIBCUDACXX_INLINE_VISIBILITY +_Tp* +addressof(_Tp& __x) _NOEXCEPT +{ + return reinterpret_cast<_Tp *>( + const_cast(&reinterpret_cast(__x))); +} + +#endif // defined(_LIBCUDACXX_ADDRESSOF) + +#if defined(_LIBCUDACXX_HAS_OBJC_ARC) && !defined(_LIBCUDACXX_PREDEFINED_OBJC_ARC_ADDRESSOF) +// Objective-C++ Automatic Reference Counting uses qualified pointers +// that require special addressof() signatures. When +// _LIBCUDACXX_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler +// itself is providing these definitions. Otherwise, we provide them. +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__strong _Tp* +addressof(__strong _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +#ifdef _LIBCUDACXX_HAS_OBJC_ARC_WEAK +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__weak _Tp* +addressof(__weak _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__autoreleasing _Tp* +addressof(__autoreleasing _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__unsafe_unretained _Tp* +addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + +#if !defined(_LIBCUDACXX_CXX03_LANG) +template _Tp* addressof(const _Tp&&) noexcept = delete; +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MEMORY_ADDRESSOF_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__memory/construct_at.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__memory/construct_at.h new file mode 100644 index 0000000000000000000000000000000000000000..44b747efd9a7ac9e45931ec22b808b79fdf6f924 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__memory/construct_at.h @@ -0,0 +1,209 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___MEMORY_CONSTRUCT_AT_H +#define _LIBCUDACXX___MEMORY_CONSTRUCT_AT_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__assert" +#include "../__iterator/access.h" +#include "../__memory/addressof.h" +#include "../__memory/voidify.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_array.h" +#include "../__type_traits/is_constant_evaluated.h" +#include "../__type_traits/is_trivially_move_assignable.h" +#include "../__type_traits/is_trivially_constructible.h" +#include "../__utility/forward.h" +#include "../__utility/move.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if defined(__cuda_std__) && _LIBCUDACXX_STD_VER > 17 // need to backfill ::std::construct_at +#ifndef _LIBCUDACXX_COMPILER_NVRTC +#include +#endif // _LIBCUDACXX_COMPILER_NVRTC + +#ifndef __cpp_lib_constexpr_dynamic_alloc +namespace std { +template ()) _Tp(_CUDA_VSTD::declval<_Args>()...))> +_LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp* construct_at(_Tp* __location, _Args&&... __args) { +#if defined(_LIBCUDACXX_ADDRESSOF) + return ::new (_CUDA_VSTD::__voidify(*__location)) _Tp(_CUDA_VSTD::forward<_Args>(__args)...); +#else + return ::new (const_cast(static_cast(__location))) _Tp(_CUDA_VSTD::forward<_Args>(__args)...); +#endif +} +} // namespace std +#endif // __cpp_lib_constexpr_dynamic_alloc +#endif // __cuda_std__ && _LIBCUDACXX_STD_VER > 17 + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +// There is a performance issue with placement new, where EDG based compiler insert a nullptr check that is superfluous +// Because this is a noticable performance regression, we specialize for trivially constructible types +// This is possible because we are calling ::new ignoring any user defined overloads of operator placement new + +// construct_at +#if _LIBCUDACXX_STD_VER > 17 + +_LIBCUDACXX_DISABLE_EXEC_CHECK +template ()) _Tp(_CUDA_VSTD::declval<_Args>()...))> +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +__enable_if_t || + !is_trivially_move_assignable_v<_Tp>, _Tp*> +construct_at(_Tp* __location, _Args&&... __args) { + _LIBCUDACXX_ASSERT(__location != nullptr, "null pointer given to construct_at"); +#if defined(__cuda_std__) + // Need to go through `std::construct_at` as that is the explicitly blessed function + if (__libcpp_is_constant_evaluated()) { + return ::std::construct_at(__location, _CUDA_VSTD::forward<_Args>(__args)...); + } +#endif // __cuda_std__ + return ::new (_CUDA_VSTD::__voidify(*__location)) _Tp(_CUDA_VSTD::forward<_Args>(__args)...); +} + +_LIBCUDACXX_DISABLE_EXEC_CHECK +template ()) _Tp(_CUDA_VSTD::declval<_Args>()...))> +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +__enable_if_t && + is_trivially_move_assignable_v<_Tp>, _Tp*> +construct_at(_Tp* __location, _Args&&... __args) { + _LIBCUDACXX_ASSERT(__location != nullptr, "null pointer given to construct_at"); +#if defined(__cuda_std__) + // Need to go through `std::construct_at` as that is the explicitly blessed function + if (__libcpp_is_constant_evaluated()) { + return ::std::construct_at(__location, _CUDA_VSTD::forward<_Args>(__args)...); + } + *__location = _Tp{_CUDA_VSTD::forward<_Args>(__args)...}; + return __location; +#else // ^^^ __cuda_std__ ^^^ / vvv !__cuda_std__ vvv + // NVCC always considers construction + move assignment, other compilers are smarter using copy construction + // So rather than adding all kinds of workarounds simply fall back to the correct implementation for libcxx mode + return ::new (_CUDA_VSTD::__voidify(*__location)) _Tp(_CUDA_VSTD::forward<_Args>(__args)...); +#endif // !__cuda_std__ +} + +#endif // _LIBCUDACXX_STD_VER > 17 + +_LIBCUDACXX_DISABLE_EXEC_CHECK +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +__enable_if_t +__construct_at(_Tp* __location, _Args&&... __args) { + _LIBCUDACXX_ASSERT(__location != nullptr, "null pointer given to construct_at"); +#if defined(__cuda_std__) && _LIBCUDACXX_STD_VER > 17 + // Need to go through `std::construct_at` as that is the explicitly blessed function + if (__libcpp_is_constant_evaluated()) { + return ::std::construct_at(__location, _CUDA_VSTD::forward<_Args>(__args)...); + } +#endif // __cuda_std__ && _LIBCUDACXX_STD_VER > 17 + return ::new (_CUDA_VSTD::__voidify(*__location)) _Tp(_CUDA_VSTD::forward<_Args>(__args)...); +} + +_LIBCUDACXX_DISABLE_EXEC_CHECK +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +__enable_if_t<_LIBCUDACXX_TRAIT(is_trivially_constructible, _Tp, _Args...) && _LIBCUDACXX_TRAIT(is_trivially_move_assignable, _Tp), _Tp*> +__construct_at(_Tp* __location, _Args&&... __args) { + _LIBCUDACXX_ASSERT(__location != nullptr, "null pointer given to construct_at"); +#if defined(__cuda_std__) && _LIBCUDACXX_STD_VER > 17 + // Need to go through `std::construct_at` as that is the explicitly blessed function + if (__libcpp_is_constant_evaluated()) { + return ::std::construct_at(__location, _CUDA_VSTD::forward<_Args>(__args)...); + } +#endif // __cuda_std__ && _LIBCUDACXX_STD_VER > 17 + *__location = _Tp{_CUDA_VSTD::forward<_Args>(__args)...}; + return __location; +} + +// destroy_at + +// The internal functions are available regardless of the language version (with the exception of the `__destroy_at` +// taking an array). +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +_ForwardIterator __destroy(_ForwardIterator, _ForwardIterator); + +template ::value, int> = 0> +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +void __destroy_at(_Tp* __loc) { + _LIBCUDACXX_ASSERT(__loc != nullptr, "null pointer given to destroy_at"); + __loc->~_Tp(); +} + +#if _LIBCUDACXX_STD_VER > 17 +template ::value, int> = 0> +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +void __destroy_at(_Tp* __loc) { + _LIBCUDACXX_ASSERT(__loc != nullptr, "null pointer given to destroy_at"); + _CUDA_VSTD::__destroy(_CUDA_VSTD::begin(*__loc), _CUDA_VSTD::end(*__loc)); +} +#endif + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +_ForwardIterator __destroy(_ForwardIterator __first, _ForwardIterator __last) { + for (; __first != __last; ++__first) + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(*__first)); + return __first; +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +_BidirectionalIterator __reverse_destroy(_BidirectionalIterator __first, _BidirectionalIterator __last) { + while (__last != __first) { + --__last; + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(*__last)); + } + return __last; +} + +#if _LIBCUDACXX_STD_VER > 14 + +template , int> = 0> +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +void destroy_at(_Tp* __loc) { + _LIBCUDACXX_ASSERT(__loc != nullptr, "null pointer given to destroy_at"); + __loc->~_Tp(); +} + +#if _LIBCUDACXX_STD_VER > 17 +template , int> = 0> +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +void destroy_at(_Tp* __loc) { + _CUDA_VSTD::__destroy_at(__loc); +} +#endif // _LIBCUDACXX_STD_VER > 17 + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +void destroy(_ForwardIterator __first, _ForwardIterator __last) { + (void)_CUDA_VSTD::__destroy(_CUDA_VSTD::move(__first), _CUDA_VSTD::move(__last)); +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { + for (; __n > 0; (void)++__first, --__n) + _CUDA_VSTD::__destroy_at(_CUDA_VSTD::addressof(*__first)); + return __first; +} + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MEMORY_CONSTRUCT_AT_H diff --git a/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__memory/pointer_traits.h b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__memory/pointer_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..b3fa8b6af63cb9e59f001e0999057ecd57050667 --- /dev/null +++ b/miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/third_party/gpus/cuda/include/cuda/std/detail/libcxx/include/__memory/pointer_traits.h @@ -0,0 +1,380 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___MEMORY_POINTER_TRAITS_H +#define _LIBCUDACXX___MEMORY_POINTER_TRAITS_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__memory/addressof.h" +#include "../__type_traits/conjunction.h" +#include "../__type_traits/conditional.h" +#include "../__type_traits/decay.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/is_class.h" +#include "../__type_traits/is_function.h" +#include "../__type_traits/is_void.h" +#include "../__type_traits/void_t.h" +#include "../__utility/declval.h" +#include "../cstddef" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct __has_element_type : false_type {}; + +template +struct __has_element_type<_Tp, + __void_t> : true_type {}; + +template ::value> +struct __pointer_traits_element_type; + +template +struct __pointer_traits_element_type<_Ptr, true> +{ + typedef _LIBCUDACXX_NODEBUG_TYPE typename _Ptr::element_type type; +}; + +#ifndef _LIBCUDACXX_HAS_NO_VARIADICS + +template