diff --git a/cuda_toolkit/include/__algorithm/swap_ranges.h b/cuda_toolkit/include/__algorithm/swap_ranges.h new file mode 100644 index 0000000000000000000000000000000000000000..05027c2c049f14b13da4cebb5c6cdbe9dc964a5f --- /dev/null +++ b/cuda_toolkit/include/__algorithm/swap_ranges.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 +// +//===----------------------------------------------------------------------===// + +#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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__cccl/ptx_isa.h b/cuda_toolkit/include/__cccl/ptx_isa.h new file mode 100644 index 0000000000000000000000000000000000000000..68e218f29f44268779ace255abc6fa9a9a769382 --- /dev/null +++ b/cuda_toolkit/include/__cccl/ptx_isa.h @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef __CCCL_PTX_ISA_H_ +#define __CCCL_PTX_ISA_H_ + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include // __CUDA_MINIMUM_ARCH__ and friends + +/* + * Targeting macros + * + * Information from: + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#release-notes + */ + +// PTX ISA 8.3 is available from CUDA 12.3, driver r545 +// The first define is for future major versions of CUDACC. +// We make sure that these get the highest known PTX ISA version. +#if (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ > 12)) || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 830ULL +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 12 && __CUDACC_VER_MINOR__ >= 3)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 830ULL +// PTX ISA 8.2 is available from CUDA 12.2, driver r535 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 12 && __CUDACC_VER_MINOR__ >= 2)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 820ULL +// PTX ISA 8.1 is available from CUDA 12.1, driver r530 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 12 && __CUDACC_VER_MINOR__ >= 1)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 810ULL +// PTX ISA 8.0 is available from CUDA 12.0, driver r525 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 12 && __CUDACC_VER_MINOR__ >= 0)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 800ULL +// PTX ISA 7.8 is available from CUDA 11.8, driver r520 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 11 && __CUDACC_VER_MINOR__ >= 8)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 780ULL +// PTX ISA 7.7 is available from CUDA 11.7, driver r515 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 11 && __CUDACC_VER_MINOR__ >= 7)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 770ULL +// PTX ISA 7.6 is available from CUDA 11.6, driver r510 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 11 && __CUDACC_VER_MINOR__ >= 6)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 760ULL +// PTX ISA 7.5 is available from CUDA 11.5, driver r495 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 11 && __CUDACC_VER_MINOR__ >= 5)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 750ULL +// PTX ISA 7.4 is available from CUDA 11.4, driver r470 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 11 && __CUDACC_VER_MINOR__ >= 4)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 740ULL +// PTX ISA 7.3 is available from CUDA 11.3, driver r465 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 11 && __CUDACC_VER_MINOR__ >= 3)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 730ULL +// PTX ISA 7.2 is available from CUDA 11.2, driver r460 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 11 && __CUDACC_VER_MINOR__ >= 2)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 720ULL +// PTX ISA 7.1 is available from CUDA 11.1, driver r455 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 11 && __CUDACC_VER_MINOR__ >= 1)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 710ULL +// PTX ISA 7.0 is available from CUDA 11.0, driver r445 +#elif (defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 11 && __CUDACC_VER_MINOR__ >= 0)) \ + || (!defined(__CUDACC_VER_MAJOR__)) +# define __cccl_ptx_isa 700ULL +// Fallback case. Define the ISA version to be zero. This ensures that the macro is always defined. +#else +# define __cccl_ptx_isa 0ULL +#endif + +// We define certain feature test macros depending on availability. When +// __CUDA_MINIMUM_ARCH__ is not available, we define the following features +// depending on PTX ISA. This permits checking for the feature in host code. +// When __CUDA_MINIMUM_ARCH__ is available, we only enable the feature when the +// hardware supports it. +#if __cccl_ptx_isa >= 800 +#if (!defined(__CUDA_MINIMUM_ARCH__)) \ + || (defined(__CUDA_MINIMUM_ARCH__) && 900 <= __CUDA_MINIMUM_ARCH__) +# define __cccl_lib_local_barrier_arrive_tx +# define __cccl_lib_experimental_ctk12_cp_async_exposure +#endif +#endif // __cccl_ptx_isa >= 800 + +#endif // __CCCL_PTX_ISA_H_ diff --git a/cuda_toolkit/include/__cccl/version.h b/cuda_toolkit/include/__cccl/version.h new file mode 100644 index 0000000000000000000000000000000000000000..1c68f987f38bc93d4045786777ff5a4bc5d7a32f --- /dev/null +++ b/cuda_toolkit/include/__cccl/version.h @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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 __CCCL_VERSION_H +#define __CCCL_VERSION_H + +#define CCCL_VERSION 2003002 +#define CCCL_MAJOR_VERSION (CCCL_VERSION / 1000000) +#define CCCL_MINOR_VERSION (((CCCL_VERSION / 1000) % 1000)) +#define CCCL_PATCH_VERSION (CCCL_VERSION % 1000) + +#if CCCL_PATCH_VERSION > 99 +#error "CCCL patch version cannot be greater than 99 for compatibility with Thrust/CUB's MMMmmmpp format." +#endif + +#endif // __CCCL_VERSION_H diff --git a/cuda_toolkit/include/__cccl/visibility.h b/cuda_toolkit/include/__cccl/visibility.h new file mode 100644 index 0000000000000000000000000000000000000000..9034dbfd099723d7d1848140e9f608d93d6a4612 --- /dev/null +++ b/cuda_toolkit/include/__cccl/visibility.h @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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 __CCCL_VISIBILITY_H +#define __CCCL_VISIBILITY_H + +#ifndef __CCCL_CONFIG +#error "<__cccl/visibility.h> should only be included in from " +#endif // __CCCL_CONFIG + +// We want to ensure that all warning emmiting from this header are supressed +#if defined(_CCCL_FORCE_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_FORCE_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_FORCE_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// For unknown reasons, nvc++ need to selectively disable this warning +// We do not want to use our usual macro because that would have push / pop semantics +#if defined(_CCCL_COMPILER_NVHPC) +# pragma nv_diag_suppress 1407 +#endif // _CCCL_COMPILER_NVHPC + +// Enable us to hide kernels +#if defined(_CCCL_COMPILER_MSVC) +# define _CCCL_ATTRIBUTE_HIDDEN +#elif defined(_CCCL_COMPILER_NVRTC) +# define _CCCL_ATTRIBUTE_HIDDEN +#else // ^^^ _CCCL_COMPILER_NVRTC ^^^ / vvv _CCCL_COMPILER_NVRTC vvv +# define _CCCL_ATTRIBUTE_HIDDEN __attribute__ ((__visibility__("hidden"))) +#endif // !_CCCL_COMPILER_NVRTC + +#if !defined(CCCL_DETAIL_KERNEL_ATTRIBUTES) +# define CCCL_DETAIL_KERNEL_ATTRIBUTES __global__ _CCCL_ATTRIBUTE_HIDDEN +#endif // !CCCL_DETAIL_KERNEL_ATTRIBUTES + +#endif // __CCCL_VISIBILITY_H diff --git a/cuda_toolkit/include/__concepts/_One_of.h b/cuda_toolkit/include/__concepts/_One_of.h new file mode 100644 index 0000000000000000000000000000000000000000..5e4d138959524e09e7f6b0b84157a786b33a782d --- /dev/null +++ b/cuda_toolkit/include/__concepts/_One_of.h @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/__concept_macros.h b/cuda_toolkit/include/__concepts/__concept_macros.h new file mode 100644 index 0000000000000000000000000000000000000000..93375b7b3cebf9b4854e075b9a23b75122dff24f --- /dev/null +++ b/cuda_toolkit/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 defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#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) +// _LIBCUDACXX_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__> +#define _LIBCUDACXX_REQUIRES(...) requires __VA_ARGS__ +#define _LIBCUDACXX_AND && +#define _LIBCUDACXX_TRAILING_REQUIRES(...) -> __VA_ARGS__ requires _LIBCUDACXX_PP_EXPAND +#else +#define _LIBCUDACXX_TEMPLATE(...) template <__VA_ARGS__ +#define _LIBCUDACXX_REQUIRES(...) \ + , bool _LIBCUDACXX_true_ = true, \ + _Concept::_Enable_if_t <__VA_ARGS__ && \ + _LIBCUDACXX_true_, \ + int > = 0 > /**/ +#define _LIBCUDACXX_AND \ + && _LIBCUDACXX_true_, int > = 0, _Concept::_Enable_if_t < +#define _LIBCUDACXX_TRAILING_REQUIRES_AUX_(...) \ + , __VA_ARGS__> +#define _LIBCUDACXX_TRAILING_REQUIRES(...) \ + -> _Concept::_Requires_t<__VA_ARGS__ _LIBCUDACXX_TRAILING_REQUIRES_AUX_ +#endif + +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/cuda_toolkit/include/__concepts/arithmetic.h b/cuda_toolkit/include/__concepts/arithmetic.h new file mode 100644 index 0000000000000000000000000000000000000000..5808d7d1dbbe827690de012beb7fa876613dfcc1 --- /dev/null +++ b/cuda_toolkit/include/__concepts/arithmetic.h @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/assignable.h b/cuda_toolkit/include/__concepts/assignable.h new file mode 100644 index 0000000000000000000000000000000000000000..3d9522466c2617eadeb729ca2cfb2bc48dec391e --- /dev/null +++ b/cuda_toolkit/include/__concepts/assignable.h @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/boolean_testable.h b/cuda_toolkit/include/__concepts/boolean_testable.h new file mode 100644 index 0000000000000000000000000000000000000000..4a6c97a17ea6f3cbcb5d555e0ddb6df8da67c5f9 --- /dev/null +++ b/cuda_toolkit/include/__concepts/boolean_testable.h @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/class_or_enum.h b/cuda_toolkit/include/__concepts/class_or_enum.h new file mode 100644 index 0000000000000000000000000000000000000000..df59bd78dd424dd077e34b55592a3aa01764a727 --- /dev/null +++ b/cuda_toolkit/include/__concepts/class_or_enum.h @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/common_reference_with.h b/cuda_toolkit/include/__concepts/common_reference_with.h new file mode 100644 index 0000000000000000000000000000000000000000..b54e78be12c84c25b5eb37417b4af86dfaa74978 --- /dev/null +++ b/cuda_toolkit/include/__concepts/common_reference_with.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_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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/common_with.h b/cuda_toolkit/include/__concepts/common_with.h new file mode 100644 index 0000000000000000000000000000000000000000..8fb9fcb79631b5f48b7d7558251cdd4ff526e7ce --- /dev/null +++ b/cuda_toolkit/include/__concepts/common_with.h @@ -0,0 +1,102 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/constructible.h b/cuda_toolkit/include/__concepts/constructible.h new file mode 100644 index 0000000000000000000000000000000000000000..c338467d85763cad37d67bae9da7299402e44b51 --- /dev/null +++ b/cuda_toolkit/include/__concepts/constructible.h @@ -0,0 +1,125 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/convertible_to.h b/cuda_toolkit/include/__concepts/convertible_to.h new file mode 100644 index 0000000000000000000000000000000000000000..5ac5f4cc42c992e50cd5083b9b3e94391475cd6e --- /dev/null +++ b/cuda_toolkit/include/__concepts/convertible_to.h @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/copyable.h b/cuda_toolkit/include/__concepts/copyable.h new file mode 100644 index 0000000000000000000000000000000000000000..8a4b6dede369d3c406b6e258c7fdde058040b0be --- /dev/null +++ b/cuda_toolkit/include/__concepts/copyable.h @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/derived_from.h b/cuda_toolkit/include/__concepts/derived_from.h new file mode 100644 index 0000000000000000000000000000000000000000..0075ae97c4eeed6782a14aff7d92610007b432a1 --- /dev/null +++ b/cuda_toolkit/include/__concepts/derived_from.h @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/destructible.h b/cuda_toolkit/include/__concepts/destructible.h new file mode 100644 index 0000000000000000000000000000000000000000..2bb831945d725b1baf5f4513fc5a0994caa4cc99 --- /dev/null +++ b/cuda_toolkit/include/__concepts/destructible.h @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/different_from.h b/cuda_toolkit/include/__concepts/different_from.h new file mode 100644 index 0000000000000000000000000000000000000000..f157d3c7119d37a6b0f5e6310c612bef90d2cdfa --- /dev/null +++ b/cuda_toolkit/include/__concepts/different_from.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_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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/equality_comparable.h b/cuda_toolkit/include/__concepts/equality_comparable.h new file mode 100644 index 0000000000000000000000000000000000000000..c2b9d1166cdb4cd04fabf3f2f5baed5057209e28 --- /dev/null +++ b/cuda_toolkit/include/__concepts/equality_comparable.h @@ -0,0 +1,111 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/invocable.h b/cuda_toolkit/include/__concepts/invocable.h new file mode 100644 index 0000000000000000000000000000000000000000..33ad53c07047554ede93e6c7e0813e4b747fef2c --- /dev/null +++ b/cuda_toolkit/include/__concepts/invocable.h @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/movable.h b/cuda_toolkit/include/__concepts/movable.h new file mode 100644 index 0000000000000000000000000000000000000000..233af6d63ba0ae3db62870eb067ba424a259bb74 --- /dev/null +++ b/cuda_toolkit/include/__concepts/movable.h @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/predicate.h b/cuda_toolkit/include/__concepts/predicate.h new file mode 100644 index 0000000000000000000000000000000000000000..f3b54c313be97178708986359187da755bfcfcde --- /dev/null +++ b/cuda_toolkit/include/__concepts/predicate.h @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/regular.h b/cuda_toolkit/include/__concepts/regular.h new file mode 100644 index 0000000000000000000000000000000000000000..e3dbf1fd83767050edf2e3e580ba98e31a9daabf --- /dev/null +++ b/cuda_toolkit/include/__concepts/regular.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_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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/relation.h b/cuda_toolkit/include/__concepts/relation.h new file mode 100644 index 0000000000000000000000000000000000000000..8a5da7ad81a09c8298fc0e07b33d7e4be883cf45 --- /dev/null +++ b/cuda_toolkit/include/__concepts/relation.h @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/same_as.h b/cuda_toolkit/include/__concepts/same_as.h new file mode 100644 index 0000000000000000000000000000000000000000..0ba84b5cbe67ecf4bd5da73b884bccac0e502830 --- /dev/null +++ b/cuda_toolkit/include/__concepts/same_as.h @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/semiregular.h b/cuda_toolkit/include/__concepts/semiregular.h new file mode 100644 index 0000000000000000000000000000000000000000..208fefeb6382cc1395bc7c75f6e308743a466b79 --- /dev/null +++ b/cuda_toolkit/include/__concepts/semiregular.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_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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__concepts/swappable.h b/cuda_toolkit/include/__concepts/swappable.h new file mode 100644 index 0000000000000000000000000000000000000000..b2a93adf471f740ccfe315b07238d4000e580c91 --- /dev/null +++ b/cuda_toolkit/include/__concepts/swappable.h @@ -0,0 +1,228 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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/cuda_toolkit/include/__concepts/totally_ordered.h b/cuda_toolkit/include/__concepts/totally_ordered.h new file mode 100644 index 0000000000000000000000000000000000000000..9b9a2815d11ee8ade82612f03582609d0a74627e --- /dev/null +++ b/cuda_toolkit/include/__concepts/totally_ordered.h @@ -0,0 +1,113 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__cuda/atomic.h b/cuda_toolkit/include/__cuda/atomic.h new file mode 100644 index 0000000000000000000000000000000000000000..52c03fb1f05de1fa7d8d9c595f1b86ee04b4ccac --- /dev/null +++ b/cuda_toolkit/include/__cuda/atomic.h @@ -0,0 +1,264 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__cuda/atomic_prelude.h b/cuda_toolkit/include/__cuda/atomic_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..1333435b9591c0f149a72701fedcf04df85f814a --- /dev/null +++ b/cuda_toolkit/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/cuda_toolkit/include/__cuda/barrier.h b/cuda_toolkit/include/__cuda/barrier.h new file mode 100644 index 0000000000000000000000000000000000000000..d8710e5f18d33b358bd195822ff43418721179b8 --- /dev/null +++ b/cuda_toolkit/include/__cuda/barrier.h @@ -0,0 +1,1257 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include "../cstdlib" // _LIBCUDACXX_UNREACHABLE +#include "../__type_traits/void_t.h" // _CUDA_VSTD::__void_t + +#if defined(_CCCL_CUDA_COMPILER) +#include "../__cuda/ptx.h" // cuda::ptx::* +#endif // _CCCL_CUDA_COMPILER + +#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 +}; + +// __completion_mechanism allows memcpy_async to report back what completion +// mechanism it used. This is necessary to determine in which way to synchronize +// the memcpy_async with a sync object (barrier or pipeline). +// +// In addition, we use this enum to create bit flags so that calling functions +// can specify which completion mechanisms can be used (__sync is always +// allowed). +enum class __completion_mechanism { + __sync = 0, + __mbarrier_complete_tx = 1 << 0, // Use powers of two here to support the + __async_group = 1 << 1, // bit flag use case + __async_bulk_group = 1 << 2, +}; + +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 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) { + _LIBCUDACXX_DEBUG_ASSERT(__expected >= 0, "Cannot initialize barrier with negative arrival count"); + new (__b) barrier(__expected); + } + + _LIBCUDACXX_INLINE_VISIBILITY + friend void init(barrier * __b, _CUDA_VSTD::ptrdiff_t __expected, _CompletionF __completion) { + _LIBCUDACXX_DEBUG_ASSERT(__expected >= 0, "Cannot initialize barrier with negative arrival count"); + 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) { + _LIBCUDACXX_DEBUG_ASSERT(__update >= 0, "Arrival count update must be non-negative."); + arrival_token __token = {}; + NV_DISPATCH_TARGET( + NV_PROVIDES_SM_90, ( + if (!__isClusterShared(&__barrier)) { + return __barrier.arrive(__update); + } + else if (!__isShared(&__barrier)) { + __trap(); + } + // Cannot use cuda::device::barrier_native_handle here, as it is + // only defined for block-scope barriers. This barrier may be a + // non-block scoped barrier. + auto __bh = reinterpret_cast<_CUDA_VSTD::uint64_t*>(&__barrier); + __token = _CUDA_VPTX::mbarrier_arrive(__bh, __update); + ), NV_PROVIDES_SM_80, ( + if (!__isShared(&__barrier)) { + return __barrier.arrive(__update); + } + auto __bh = reinterpret_cast<_CUDA_VSTD::uint64_t*>(&__barrier); + // Need 2 instructions, can't finish barrier with arrive > 1 + if (__update > 1) { + _CUDA_VPTX::mbarrier_arrive_no_complete(__bh, __update - 1); + } + __token = _CUDA_VPTX::mbarrier_arrive( __bh); + ), 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 == static_cast(__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); +} + +#if defined(_CCCL_CUDA_COMPILER) + +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE void __cuda_ptx_barrier_arrive_tx_is_not_supported_before_SM_90__(); +_LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_DEVICE inline +barrier::arrival_token barrier_arrive_tx( + barrier & __b, + _CUDA_VSTD::ptrdiff_t __arrive_count_update, + _CUDA_VSTD::ptrdiff_t __transaction_count_update) { + + _LIBCUDACXX_DEBUG_ASSERT(__isShared(barrier_native_handle(__b)), "Barrier must be located in local shared memory."); + _LIBCUDACXX_DEBUG_ASSERT(1 <= __arrive_count_update, "Arrival count update must be at least one."); + _LIBCUDACXX_DEBUG_ASSERT(__arrive_count_update <= (1 << 20) - 1, "Arrival count update cannot exceed 2^20 - 1."); + _LIBCUDACXX_DEBUG_ASSERT(__transaction_count_update >= 0, "Transaction count update must be non-negative."); + // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#contents-of-the-mbarrier-object + _LIBCUDACXX_DEBUG_ASSERT(__transaction_count_update <= (1 << 20) - 1, "Transaction count update cannot exceed 2^20 - 1."); + + barrier::arrival_token __token = {}; + NV_IF_ELSE_TARGET( + // On architectures pre-sm90, arrive_tx is not supported. + NV_PROVIDES_SM_90, ( + // We do not check for the statespace of the barrier here. This is + // on purpose. This allows debugging tools like memcheck/racecheck + // to detect that we are passing a pointer with the wrong state + // space to mbarrier.arrive. If we checked for the state space here, + // and __trap() if wrong, then those tools would not be able to help + // us in release builds. In debug builds, the error would be caught + // by the asserts at the top of this function. + + auto __native_handle = barrier_native_handle(__b); + auto __bh = __cvta_generic_to_shared(__native_handle); + if (__arrive_count_update == 1) { + __token = _CUDA_VPTX::mbarrier_arrive_expect_tx( + _CUDA_VPTX::sem_release, _CUDA_VPTX::scope_cta, _CUDA_VPTX::space_shared, __native_handle, __transaction_count_update + ); + } else { + asm ( + "mbarrier.expect_tx.relaxed.cta.shared::cta.b64 [%0], %1;" + : + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__bh)), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__transaction_count_update)) + : "memory"); + __token = _CUDA_VPTX::mbarrier_arrive( + _CUDA_VPTX::sem_release, _CUDA_VPTX::scope_cta, _CUDA_VPTX::space_shared, __native_handle, __arrive_count_update + ); + } + ),( + __cuda_ptx_barrier_arrive_tx_is_not_supported_before_SM_90__(); + ) + ); + return __token; +} + +extern "C" _LIBCUDACXX_DEVICE void __cuda_ptx_barrier_expect_tx_is_not_supported_before_SM_90__(); +_LIBCUDACXX_DEVICE inline +void barrier_expect_tx( + barrier & __b, + _CUDA_VSTD::ptrdiff_t __transaction_count_update) { + + _LIBCUDACXX_DEBUG_ASSERT(__isShared(barrier_native_handle(__b)), "Barrier must be located in local shared memory."); + _LIBCUDACXX_DEBUG_ASSERT(__transaction_count_update >= 0, "Transaction count update must be non-negative."); + // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#contents-of-the-mbarrier-object + _LIBCUDACXX_DEBUG_ASSERT(__transaction_count_update <= (1 << 20) - 1, "Transaction count update cannot exceed 2^20 - 1."); + + // We do not check for the statespace of the barrier here. This is + // on purpose. This allows debugging tools like memcheck/racecheck + // to detect that we are passing a pointer with the wrong state + // space to mbarrier.arrive. If we checked for the state space here, + // and __trap() if wrong, then those tools would not be able to help + // us in release builds. In debug builds, the error would be caught + // by the asserts at the top of this function. + NV_IF_ELSE_TARGET( + // On architectures pre-sm90, arrive_tx is not supported. + NV_PROVIDES_SM_90, ( + auto __bh = __cvta_generic_to_shared(barrier_native_handle(__b)); + asm ( + "mbarrier.expect_tx.relaxed.cta.shared::cta.b64 [%0], %1;" + : + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__bh)), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__transaction_count_update)) + : "memory"); + ),( + __cuda_ptx_barrier_expect_tx_is_not_supported_before_SM_90__(); + )); +} + +extern "C" _LIBCUDACXX_DEVICE void __cuda_ptx_memcpy_async_tx_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE inline async_contract_fulfillment memcpy_async_tx( + _Tp* __dest, + const _Tp* __src, + ::cuda::aligned_size_t<_Alignment> __size, + ::cuda::barrier<::cuda::thread_scope_block> & __b) { + // 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_tx requires a trivially copyable type"); +#endif + static_assert(16 <= _Alignment, "mempcy_async_tx expects arguments to be at least 16 byte aligned."); + + _LIBCUDACXX_DEBUG_ASSERT(__isShared(barrier_native_handle(__b)), "Barrier must be located in local shared memory."); + _LIBCUDACXX_DEBUG_ASSERT(__isShared(__dest), "dest must point to shared memory."); + _LIBCUDACXX_DEBUG_ASSERT(__isGlobal(__src), "src must point to global memory."); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + auto __bh = __cvta_generic_to_shared(barrier_native_handle(__b)); + if (__isShared(__dest) && __isGlobal(__src)) { + asm volatile( + "cp.async.bulk.shared::cluster.global.mbarrier::complete_tx::bytes [%0], [%1], %2, [%3];\n" + : + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__dest))), + "l"(static_cast<_CUDA_VSTD::uint64_t>(__cvta_generic_to_global(__src))), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__size)), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__bh)) + : "memory"); + } else { + // memcpy_async_tx only supports copying from global to shared + // or from shared to remote cluster dsmem. To copy to remote + // dsmem, we need to arrive on a cluster-scoped barrier, which + // is not yet implemented. So we trap in this case as well. + _LIBCUDACXX_UNREACHABLE(); + } + ),( + __cuda_ptx_memcpy_async_tx_is_not_supported_before_SM_90__(); + )); + + return async_contract_fulfillment::async; +} +#endif // __cccl_ptx_isa >= 800 +#endif // _CCCL_CUDA_COMPILER + +_LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE + +#if defined(_CCCL_CUDA_COMPILER) + +_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;} + +// __is_local_smem_barrier returns true if barrier is (1) block-scoped and (2) located in shared memory. +template::value> +_LIBCUDACXX_INLINE_VISIBILITY +bool __is_local_smem_barrier(barrier<_Sco, _CompF> & __barrier) { + NV_IF_ELSE_TARGET( + NV_IS_DEVICE, ( + return _Is_mbarrier && __isShared(&__barrier); + ),( + return false; + ) + ); +} + +// __try_get_barrier_handle returns barrier handle of block-scoped barriers and a nullptr otherwise. +template +_LIBCUDACXX_INLINE_VISIBILITY inline +_CUDA_VSTD::uint64_t * __try_get_barrier_handle(barrier<_Sco, _CompF> & __barrier) { + return nullptr; +} + +template<> +_LIBCUDACXX_INLINE_VISIBILITY inline +_CUDA_VSTD::uint64_t * __try_get_barrier_handle<::cuda::thread_scope_block, _CUDA_VSTD::__empty_completion>(barrier<::cuda::thread_scope_block> & __barrier) { + NV_DISPATCH_TARGET( + NV_IS_DEVICE, ( + return ::cuda::device::barrier_native_handle(__barrier); + ), + NV_ANY_TARGET, ( + return nullptr; + ) + ); +} + +// This struct contains functions to defer the completion of a barrier phase +// or pipeline stage until a specific memcpy_async operation *initiated by +// this thread* has completed. + +// The user is still responsible for arriving and waiting on (or otherwise +// synchronizing with) the barrier or pipeline barrier to see the results of +// copies from other threads participating in the synchronization object. +struct __memcpy_completion_impl { + + template + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY static + async_contract_fulfillment __defer( + __completion_mechanism __cm, _Group const & __group, _CUDA_VSTD::size_t __size, barrier<::cuda::thread_scope_block> & __barrier) { + // In principle, this is the overload for shared memory barriers. However, a + // block-scope barrier may also be located in global memory. Therefore, we + // check if the barrier is a non-smem barrier and handle that separately. + if (! __is_local_smem_barrier(__barrier)) { + return __defer_non_smem_barrier(__cm, __group, __size, __barrier); + } + + switch (__cm) { + case __completion_mechanism::__async_group: + // Pre-SM80, the async_group mechanism is not available. + NV_IF_TARGET(NV_PROVIDES_SM_80, ( + // Non-Blocking: unbalance barrier by 1, barrier will be + // rebalanced when all thread-local cp.async instructions + // have completed writing to shared memory. + _CUDA_VSTD::uint64_t * __bh = __try_get_barrier_handle(__barrier); + + asm volatile ("cp.async.mbarrier.arrive.shared.b64 [%0];" + :: "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__bh))) + : "memory"); + )); + return async_contract_fulfillment::async; + case __completion_mechanism::__async_bulk_group: + // This completion mechanism should not be used with a shared + // memory barrier. Or at least, we do not currently envision + // bulk group to be used with shared memory barriers. + _LIBCUDACXX_UNREACHABLE(); + case __completion_mechanism::__mbarrier_complete_tx: +#if __cccl_ptx_isa >= 800 + // Pre-sm90, the mbarrier_complete_tx completion mechanism is not available. + NV_IF_TARGET(NV_PROVIDES_SM_90, ( + // Only perform the expect_tx operation with the leader thread + if (__group.thread_rank() == 0) { + ::cuda::device::barrier_expect_tx(__barrier, __size); + } + )); +#endif // __cccl_ptx_isa >= 800 + return async_contract_fulfillment::async; + case __completion_mechanism::__sync: + // sync: In this case, we do not need to do anything. The user will have + // to issue `bar.arrive_wait();` to see the effect of the transaction. + return async_contract_fulfillment::none; + default: + // Get rid of "control reaches end of non-void function": + _LIBCUDACXX_UNREACHABLE(); + } + } + + template + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY static + async_contract_fulfillment __defer( + __completion_mechanism __cm, _Group const & __group, _CUDA_VSTD::size_t __size, barrier<_Sco, _CompF> & __barrier) { + return __defer_non_smem_barrier(__cm, __group, __size, __barrier); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY static + async_contract_fulfillment __defer_non_smem_barrier( + __completion_mechanism __cm, _Group const & __group, _CUDA_VSTD::size_t __size, barrier<_Sco, _CompF> & __barrier) { + // Overload for non-smem barriers. + + switch (__cm) { + case __completion_mechanism::__async_group: + // Pre-SM80, the async_group mechanism is not available. + NV_IF_TARGET(NV_PROVIDES_SM_80, ( + // Blocking: wait for all thread-local cp.async instructions to have + // completed writing to shared memory. + asm volatile ("cp.async.wait_all;" ::: "memory"); + )); + return async_contract_fulfillment::async; + case __completion_mechanism::__mbarrier_complete_tx: + // Non-smem barriers do not have an mbarrier_complete_tx mechanism.. + _LIBCUDACXX_UNREACHABLE(); + case __completion_mechanism::__async_bulk_group: + // This completion mechanism is currently not expected to be used with barriers. + _LIBCUDACXX_UNREACHABLE(); + case __completion_mechanism::__sync: + // sync: In this case, we do not need to do anything. + return async_contract_fulfillment::none; + default: + // Get rid of "control reaches end of non-void function": + _LIBCUDACXX_UNREACHABLE(); + } + } + + template + _LIBCUDACXX_INLINE_VISIBILITY static + async_contract_fulfillment __defer(__completion_mechanism __cm, _Group const & __group, _CUDA_VSTD::size_t __size, pipeline<_Sco> & __pipeline) { + // pipeline does not sync on memcpy_async, defeat pipeline purpose otherwise + __unused(__pipeline); + __unused(__size); + __unused(__group); + + switch (__cm) { + case __completion_mechanism::__async_group: return async_contract_fulfillment::async; + case __completion_mechanism::__async_bulk_group: return async_contract_fulfillment::async; + case __completion_mechanism::__mbarrier_complete_tx: return async_contract_fulfillment::async; + case __completion_mechanism::__sync: return async_contract_fulfillment::none; + default: + // Get rid of "control reaches end of non-void function": + _LIBCUDACXX_UNREACHABLE(); + } + } +}; + +/*********************************************************************** + * memcpy_async code: + * + * A call to cuda::memcpy_async(dest, src, size, barrier) can dispatch to any of + * these PTX instructions: + * + * 1. normal synchronous copy (fallback) + * 2. cp.async: shared <- global + * 3. cp.async.bulk: shared <- global + * 4. TODO: cp.async.bulk: global <- shared + * 5. TODO: cp.async.bulk: cluster <- shared + * + * Which of these options is chosen, depends on: + * + * 1. The alignment of dest, src, and size; + * 2. The direction of the copy + * 3. The current compute capability + * 4. The requested completion mechanism + * + * PTX has 3 asynchronous completion mechanisms: + * + * 1. Async group - local to a thread. Used by cp.async + * 2. Bulk async group - local to a thread. Used by cp.async.bulk (shared -> global) + * 3. mbarrier::complete_tx - shared memory barier. Used by cp.async.bulk (other directions) + * + * The code is organized as follows: + * + * 1. Asynchronous copy mechanisms that wrap the PTX instructions + * + * 2. Device memcpy_async implementation per copy direction (global to shared, + * shared to global, etc). Dispatches to fastest mechanism based on requested + * completion mechanism(s), pointer alignment, and architecture. + * + * 3. Host and device memcpy_async implementations. Host implementation is + * basically a memcpy wrapper; device implementation dispatches based on the + * direction of the copy. + * + * 4. __memcpy_async_barrier: + * a) Sets the allowed completion mechanisms based on the barrier location + * b) Calls the host or device memcpy_async implementation + * c) If necessary, synchronizes with the barrier based on the returned + * completion mechanism. + * + * 5. The public memcpy_async function overloads. Call into + * __memcpy_async_barrier. + * + ***********************************************************************/ + +/*********************************************************************** + * Asynchronous copy mechanisms: + * + * 1. cp.async.bulk: shared <- global + * 2. TODO: cp.async.bulk: cluster <- shared + * 3. TODO: cp.async.bulk: global <- shared + * 4. cp.async: shared <- global + * 5. normal synchronous copy (fallback) + ***********************************************************************/ + +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE void __cuda_ptx_cp_async_bulk_shared_global_is_not_supported_before_SM_90__(); +template +inline __device__ +void __cp_async_bulk_shared_global(const _Group &__g, char * __dest, const char * __src, size_t __size, uint64_t *__bar_handle) { + // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async-bulk + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + if (__g.thread_rank() == 0) { + asm volatile( + "cp.async.bulk.shared::cluster.global.mbarrier::complete_tx::bytes [%0], [%1], %2, [%3];\n" + : + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__dest))), + "l"(static_cast<_CUDA_VSTD::uint64_t>(__cvta_generic_to_global(__src))), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__size)), + "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__bar_handle))) + : "memory"); + } + ),( + __cuda_ptx_cp_async_bulk_shared_global_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + +extern "C" _LIBCUDACXX_DEVICE void __cuda_ptx_cp_async_shared_global_is_not_supported_before_SM_80__(); +template +inline __device__ +void __cp_async_shared_global(char * __dest, const char * __src) { + // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async + + // If `if constexpr` is not available, this function gets instantiated even + // if is not called. Do not static_assert in that case. +#if _LIBCUDACXX_STD_VER >= 17 + static_assert(_Copy_size == 4 || _Copy_size == 8 || _Copy_size == 16, "cp.async.shared.global requires a copy size of 4, 8, or 16."); +#endif // _LIBCUDACXX_STD_VER >= 17 + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_80,( + asm volatile( + "cp.async.ca.shared.global [%0], [%1], %2, %2;" + : + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__dest))), + "l"(static_cast<_CUDA_VSTD::uint64_t>(__cvta_generic_to_global(__src))), + "n"(_Copy_size) + : "memory"); + ),( + __cuda_ptx_cp_async_shared_global_is_not_supported_before_SM_80__(); + )); +} + +template <> +inline __device__ +void __cp_async_shared_global<16>(char * __dest, const char * __src) { + // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async + // When copying 16 bytes, it is possible to skip L1 cache (.cg). + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_80,( + asm volatile( + "cp.async.cg.shared.global [%0], [%1], %2, %2;" + : + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__dest))), + "l"(static_cast<_CUDA_VSTD::uint64_t>(__cvta_generic_to_global(__src))), + "n"(16) + : "memory"); + ),( + __cuda_ptx_cp_async_shared_global_is_not_supported_before_SM_80__(); + )); +} + +template +inline __device__ +void __cp_async_shared_global_mechanism(_Group __g, char * __dest, const char * __src, _CUDA_VSTD::size_t __size) { + // If `if constexpr` is not available, this function gets instantiated even + // if is not called. Do not static_assert in that case. +#if _LIBCUDACXX_STD_VER >= 17 + static_assert(4 <= _Alignment, "cp.async requires at least 4-byte alignment"); +#endif // _LIBCUDACXX_STD_VER >= 17 + + // Maximal copy size is 16. + constexpr int __copy_size = (_Alignment > 16) ? 16 : _Alignment; + // We use an int offset here, because we are copying to shared memory, + // which is easily addressable using int. + const int __group_size = __g.size(); + const int __group_rank = __g.thread_rank(); + const int __stride = __group_size * __copy_size; + for (int __offset = __group_rank * __copy_size; __offset < static_cast(__size); __offset += __stride) { + __cp_async_shared_global<__copy_size>(__dest + __offset, __src + __offset); + } +} + +template +struct __copy_chunk { + _ALIGNAS(_Copy_size) char data[_Copy_size]; +}; + +template +inline __host__ __device__ +void __cp_async_fallback_mechanism(_Group __g, char * __dest, const char * __src, _CUDA_VSTD::size_t __size) { + // Maximal copy size is 16 bytes + constexpr _CUDA_VSTD::size_t __copy_size = (_Alignment > 16) ? 16 : _Alignment; + using __chunk_t = __copy_chunk<__copy_size>; + + // "Group"-strided loop over memory + const size_t __stride = __g.size() * __copy_size; + + // An unroll factor of 64 ought to be enough for anybody. This unroll pragma + // is mainly intended to place an upper bound on loop unrolling. The number + // is more than high enough for the intended use case: an unroll factor of + // 64 allows moving 4 * 64 * 256 = 64kb in one unrolled loop with 256 + // threads (copying ints). On the other hand, in the unfortunate case that + // we have to move 1024 bytes / thread with char width, then we prevent + // fully unrolling the loop to 1024 copy instructions. This prevents the + // compile times from increasing unreasonably, and also has neglibible + // impact on runtime performance. +_LIBCUDACXX_PRAGMA_UNROLL(64) + for (_CUDA_VSTD::size_t __offset = __g.thread_rank() * __copy_size; __offset < __size; __offset += __stride) { + __chunk_t tmp = *reinterpret_cast(__src + __offset); + *reinterpret_cast<__chunk_t *>(__dest + __offset) = tmp; + } +} + +/*********************************************************************** + * cuda::memcpy_async dispatch helper functions + * + * - __get_size_align struct to determine the alignment from a size type. + ***********************************************************************/ + +// The __get_size_align struct provides a way to query the guaranteed +// "alignment" of a provided size. In this case, an n-byte aligned size means +// that the size is a multiple of n. +// +// Use as follows: +// static_assert(__get_size_align::align == 1) +// static_assert(__get_size_align>::align == n) + +// Default impl: always returns 1. +template +struct __get_size_align { + static constexpr int align = 1; +}; + +// aligned_size_t overload: return n. +template +struct __get_size_align> { + static constexpr int align = T::align; +}; + +/*********************************************************************** + * cuda::memcpy_async dispatch + * + * The dispatch mechanism takes all the arguments and dispatches to the + * fastest asynchronous copy mechanism available. + * + * It returns a __completion_mechanism that indicates which completion mechanism + * was used by the copy mechanism. This value can be used by the sync object to + * further synchronize if necessary. + * + ***********************************************************************/ + +template<_CUDA_VSTD::size_t _Align, typename _Group> +_LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_DEVICE inline +__completion_mechanism __dispatch_memcpy_async_any_to_any(_Group const & __group, char * __dest_char, char const * __src_char, _CUDA_VSTD::size_t __size, uint32_t __allowed_completions, uint64_t* __bar_handle) { + __cp_async_fallback_mechanism<_Align>(__group, __dest_char, __src_char, __size); + return __completion_mechanism::__sync; +} + +template<_CUDA_VSTD::size_t _Align, typename _Group> +_LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_DEVICE inline +__completion_mechanism __dispatch_memcpy_async_global_to_shared(_Group const & __group, char * __dest_char, char const * __src_char, _CUDA_VSTD::size_t __size, uint32_t __allowed_completions, uint64_t* __bar_handle) { +#if __cccl_ptx_isa >= 800 + NV_IF_TARGET(NV_PROVIDES_SM_90, ( + const bool __can_use_complete_tx = __allowed_completions & uint32_t(__completion_mechanism::__mbarrier_complete_tx); + _LIBCUDACXX_DEBUG_ASSERT(__can_use_complete_tx == (nullptr != __bar_handle), "Pass non-null bar_handle if and only if can_use_complete_tx."); + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (_Align >= 16) { + if (__can_use_complete_tx && __isShared(__bar_handle)) { + __cp_async_bulk_shared_global(__group, __dest_char, __src_char, __size, __bar_handle); + return __completion_mechanism::__mbarrier_complete_tx; + } + } + // Fallthrough to SM 80.. + )); +#endif // __cccl_ptx_isa >= 800 + + NV_IF_TARGET(NV_PROVIDES_SM_80, ( + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (_Align >= 4) { + const bool __can_use_async_group = __allowed_completions & uint32_t(__completion_mechanism::__async_group); + if (__can_use_async_group) { + __cp_async_shared_global_mechanism<_Align>(__group, __dest_char, __src_char, __size); + return __completion_mechanism::__async_group; + } + } + // Fallthrough.. + )); + + __cp_async_fallback_mechanism<_Align>(__group, __dest_char, __src_char, __size); + return __completion_mechanism::__sync; +} + +// __dispatch_memcpy_async is the internal entry point for dispatching to the correct memcpy_async implementation. +template<_CUDA_VSTD::size_t _Align, typename _Group> +_LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY +__completion_mechanism __dispatch_memcpy_async(_Group const & __group, char * __dest_char, char const * __src_char, size_t __size, _CUDA_VSTD::uint32_t __allowed_completions, uint64_t* __bar_handle) { + NV_IF_ELSE_TARGET(NV_IS_DEVICE, ( + // Dispatch based on direction of the copy: global to shared, shared to + // global, etc. + + // CUDA compilers <= 12.2 may not propagate assumptions about the state space + // of pointers correctly. Therefore, we + // 1) put the code for each copy direction in a separate function, and + // 2) make sure none of the code paths can reach each other by "falling through". + // + // See nvbug 4074679 and also PR #478. + if (__isGlobal(__src_char) && __isShared(__dest_char)) { + return __dispatch_memcpy_async_global_to_shared<_Align>(__group, __dest_char, __src_char, __size, __allowed_completions, __bar_handle); + } else { + return __dispatch_memcpy_async_any_to_any<_Align>(__group, __dest_char, __src_char, __size, __allowed_completions, __bar_handle); + } + ), ( + // Host code path: + if (__group.thread_rank() == 0) { + memcpy(__dest_char, __src_char, __size); + } + return __completion_mechanism::__sync; + )); +} + +template<_CUDA_VSTD::size_t _Align, typename _Group> +_LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY +__completion_mechanism __dispatch_memcpy_async(_Group const & __group, char * __dest_char, char const * __src_char, _CUDA_VSTD::size_t __size, _CUDA_VSTD::uint32_t __allowed_completions) { + _LIBCUDACXX_DEBUG_ASSERT(! (__allowed_completions & uint32_t(__completion_mechanism::__mbarrier_complete_tx)), "Cannot allow mbarrier_complete_tx completion mechanism when not passing a barrier. "); + return __dispatch_memcpy_async<_Align>(__group, __dest_char, __src_char, __size, __allowed_completions, nullptr); +} + +//////////////////////////////////////////////////////////////////////////////// + +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_barrier(_Group const & __group, _Tp * __destination, _Tp const * __source, _Size __size, barrier<_Sco, _CompF> & __barrier) { + static_assert(_CUDA_VSTD::is_trivially_copyable<_Tp>::value, "memcpy_async requires a trivially copyable type"); + + // 1. Determine which completion mechanisms can be used with the current + // barrier. A local shared memory barrier, i.e., block-scope barrier in local + // shared memory, supports the mbarrier_complete_tx mechanism in addition to + // the async group mechanism. + _CUDA_VSTD::uint32_t __allowed_completions = __is_local_smem_barrier(__barrier) + ? ( _CUDA_VSTD::uint32_t(__completion_mechanism::__async_group) | _CUDA_VSTD::uint32_t(__completion_mechanism::__mbarrier_complete_tx)) + : _CUDA_VSTD::uint32_t(__completion_mechanism::__async_group); + + // Alignment: Use the maximum of the alignment of _Tp and that of a possible cuda::aligned_size_t. + constexpr _CUDA_VSTD::size_t __size_align = __get_size_align<_Size>::align; + constexpr _CUDA_VSTD::size_t __align = (alignof(_Tp) < __size_align) ? __size_align : alignof(_Tp); + // Cast to char pointers. We don't need the type for alignment anymore and + // erasing the types reduces the number of instantiations of down-stream + // functions. + char * __dest_char = reinterpret_cast(__destination); + char const * __src_char = reinterpret_cast(__source); + + // 2. Issue actual copy instructions. + auto __bh = __try_get_barrier_handle(__barrier); + auto __cm = __dispatch_memcpy_async<__align>(__group, __dest_char, __src_char, __size, __allowed_completions, __bh); + + // 3. Synchronize barrier with copy instructions. + return __memcpy_completion_impl::__defer(__cm, __group, __size, __barrier); +} + +template +_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) { + return __memcpy_async_barrier(__group, __destination, __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_barrier(__single_thread_group{}, __destination, __source, __size, __barrier); +} + +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) { + + return __memcpy_async_barrier(__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_barrier(__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_barrier(__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_barrier(__single_thread_group{}, reinterpret_cast(__destination), reinterpret_cast(__source), __size, __barrier); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CCCL_CUDA_COMPILER + +#endif // _LIBCUDACXX___CUDA_BARRIER_H diff --git a/cuda_toolkit/include/__cuda/chrono.h b/cuda_toolkit/include/__cuda/chrono.h new file mode 100644 index 0000000000000000000000000000000000000000..76798c0ac583b90f06d3e1d56637046112a60ea1 --- /dev/null +++ b/cuda_toolkit/include/__cuda/chrono.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___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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__cuda/climits_prelude.h b/cuda_toolkit/include/__cuda/climits_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..5100f6e46437dc72375c562960610d16e6e6d69a --- /dev/null +++ b/cuda_toolkit/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/cuda_toolkit/include/__cuda/cstddef_prelude.h b/cuda_toolkit/include/__cuda/cstddef_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..992288ce0fae2e2b16f31c62a8921d358da24516 --- /dev/null +++ b/cuda_toolkit/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/cuda_toolkit/include/__cuda/cstdint_prelude.h b/cuda_toolkit/include/__cuda/cstdint_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..1f4b35eb301664892161214fa47564511b527187 --- /dev/null +++ b/cuda_toolkit/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/cuda_toolkit/include/__cuda/latch.h b/cuda_toolkit/include/__cuda/latch.h new file mode 100644 index 0000000000000000000000000000000000000000..1a2af3c408d0ce5e7ee06a598bd7fac24130d34e --- /dev/null +++ b/cuda_toolkit/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 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/cuda_toolkit/include/__cuda/ptx.h b/cuda_toolkit/include/__cuda/ptx.h new file mode 100644 index 0000000000000000000000000000000000000000..20ffafde10935cafc8a1f496b17a323eb92ecd9e --- /dev/null +++ b/cuda_toolkit/include/__cuda/ptx.h @@ -0,0 +1,1373 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCUDACXX___CUDA_PTX_H +#define _LIBCUDACXX___CUDA_PTX_H + +#ifndef __cuda_std__ +#error "<__cuda/ptx.h> should only be included in from " +#endif // __cuda_std__ + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include // __CUDA_MINIMUM_ARCH__ and friends + +#include "../__cuda/ptx/ptx_dot_variants.h" +#include "../__cuda/ptx/ptx_helper_functions.h" +#include "../__cuda/ptx/parallel_synchronization_and_communication_instructions_mbarrier.h" +#include "../cstdint" // uint32_t +/* + * The cuda::ptx namespace intends to provide PTX wrappers for new hardware + * features and new PTX instructions so that they can be experimented with + * before higher-level C++ APIs are designed and developed. + * + * The wrappers have the following responsibilities: + * + * - They must prevent any PTX assembler errors, that is: + * - They are defined only for versions of the CUDA Toolkit in which nvcc/ptxas + * actually recognizes the instruction. + * - Sizes and types of parameters are correct. + * - They must convert state spaces correctly. + * - They adhere to the libcu++ coding standards of using: + * - Reserved identifiers for all parameters, variables. E.g. `__meow` or `_Woof` + * - _CUDA_VSTD:: namespace for types + * + * The wrappers should not do the following: + * + * - Use any non-native types. For example, an mbarrier instruction wrapper + * takes the barrier address as a uint64_t pointer. + * + * This header is intended for: + * + * - internal consumption by higher-level APIs such as cuda::barrier, + * - outside developers who want to experiment with the latest features of the + * hardware. + * + * Stability: + * + * - These headers are intended to present a stable API (not ABI) within one + * major version of the CTK. This means that: + * - All functions are marked inline + * - The type of a function parameter can be changed to be more generic if + * that means that code that called the original version can still be + * compiled. + * + * - Good exposure of the PTX should be high priority. If, at a new major + * version, we face a difficult choice between breaking backward-compatibility + * and an improvement of the PTX exposure, we will tend to the latter option + * more easily than in other parts of libcu++. + */ + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_PTX + +/* + * Instructions + * + * The organization of the instructions below follows that of the PTX ISA documentation: + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#instructions + * + * To improve code organization, some sections are separated into their own + * header. For instance, the mbarrier instructions are found in: + * __cuda/ptx/parallel_synchronization_and_communication_instructions_mbarrier.h + * + */ + +/* + * 9.7.1. Integer Arithmetic Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions + * + */ + +// 9.7.1.7. Integer Arithmetic Instructions: sad +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-sad + +// 9.7.1.8. Integer Arithmetic Instructions: div +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-div + +// 9.7.1.9. Integer Arithmetic Instructions: rem +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-rem + +// 9.7.1.10. Integer Arithmetic Instructions: abs +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-abs + +// 9.7.1.11. Integer Arithmetic Instructions: neg +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-neg + +// 9.7.1.12. Integer Arithmetic Instructions: min +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-min + +// 9.7.1.13. Integer Arithmetic Instructions: max +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-max + +// 9.7.1.14. Integer Arithmetic Instructions: popc +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-popc + +// 9.7.1.15. Integer Arithmetic Instructions: clz +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-clz + +// 9.7.1.16. Integer Arithmetic Instructions: bfind +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-bfind + +// 9.7.1.17. Integer Arithmetic Instructions: fns +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-fns + +// 9.7.1.18. Integer Arithmetic Instructions: brev +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-brev + +// 9.7.1.19. Integer Arithmetic Instructions: bfe +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-bfe + +// 9.7.1.20. Integer Arithmetic Instructions: bfi +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-bfi + +// 9.7.1.21. Integer Arithmetic Instructions: szext +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-szext + +// 9.7.1.22. Integer Arithmetic Instructions: bmsk +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-bmsk + +// 9.7.1.23. Integer Arithmetic Instructions: dp4a +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-dp4a + +// 9.7.1.24. Integer Arithmetic Instructions: dp2a +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#integer-arithmetic-instructions-dp2a + + +/* + * 9.7.2. Extended-Precision Integer Arithmetic Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#extended-precision-integer-arithmetic-instructions + * + */ + +// 9.7.2.1. Extended-Precision Arithmetic Instructions: add.cc +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#extended-precision-arithmetic-instructions-add-cc + +// 9.7.2.2. Extended-Precision Arithmetic Instructions: addc +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#extended-precision-arithmetic-instructions-addc + +// 9.7.2.3. Extended-Precision Arithmetic Instructions: sub.cc +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#extended-precision-arithmetic-instructions-sub-cc + +// 9.7.2.4. Extended-Precision Arithmetic Instructions: subc +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#extended-precision-arithmetic-instructions-subc + +// 9.7.2.5. Extended-Precision Arithmetic Instructions: mad.cc +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#extended-precision-arithmetic-instructions-mad-cc + +// 9.7.2.6. Extended-Precision Arithmetic Instructions: madc +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#extended-precision-arithmetic-instructions-madc + + +/* + * 9.7.3. Floating-Point Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions + * + */ + +// 9.7.3.1. Floating Point Instructions: testp +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-testp + +// 9.7.3.2. Floating Point Instructions: copysign +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-copysign + +// 9.7.3.3. Floating Point Instructions: add +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-add + +// 9.7.3.4. Floating Point Instructions: sub +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-sub + +// 9.7.3.5. Floating Point Instructions: mul +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-mul + +// 9.7.3.6. Floating Point Instructions: fma +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-fma + +// 9.7.3.7. Floating Point Instructions: mad +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-mad + +// 9.7.3.8. Floating Point Instructions: div +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-div + +// 9.7.3.9. Floating Point Instructions: abs +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-abs + +// 9.7.3.10. Floating Point Instructions: neg +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-neg + +// 9.7.3.11. Floating Point Instructions: min +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-min + +// 9.7.3.12. Floating Point Instructions: max +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-max + +// 9.7.3.13. Floating Point Instructions: rcp +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-rcp + +// 9.7.3.14. Floating Point Instructions: rcp.approx.ftz.f64 +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-rcp-approx-ftz-f64 + +// 9.7.3.15. Floating Point Instructions: sqrt +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-sqrt + +// 9.7.3.16. Floating Point Instructions: rsqrt +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-rsqrt + +// 9.7.3.17. Floating Point Instructions: rsqrt.approx.ftz.f64 +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-rsqrt-approx-ftz-f64 + +// 9.7.3.18. Floating Point Instructions: sin +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-sin + +// 9.7.3.19. Floating Point Instructions: cos +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-cos + +// 9.7.3.20. Floating Point Instructions: lg2 +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-lg2 + +// 9.7.3.21. Floating Point Instructions: ex2 +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-ex2 + +// 9.7.3.22. Floating Point Instructions: tanh +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#floating-point-instructions-tanh + + +/* + * 9.7.4. Half Precision Floating-Point Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions + * + */ + +// 9.7.4.1. Half Precision Floating Point Instructions: add +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions-add + +// 9.7.4.2. Half Precision Floating Point Instructions: sub +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions-sub + +// 9.7.4.3. Half Precision Floating Point Instructions: mul +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions-mul + +// 9.7.4.4. Half Precision Floating Point Instructions: fma +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions-fma + +// 9.7.4.5. Half Precision Floating Point Instructions: neg +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions-neg + +// 9.7.4.6. Half Precision Floating Point Instructions: abs +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions-abs + +// 9.7.4.7. Half Precision Floating Point Instructions: min +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions-min + +// 9.7.4.8. Half Precision Floating Point Instructions: max +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions-max + +// 9.7.4.9. Half Precision Floating Point Instructions: tanh +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions-tanh + +// 9.7.4.10. Half Precision Floating Point Instructions: ex2 +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions-ex2 + + +/* + * 9.7.5. Comparison and Selection Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#comparison-and-selection-instructions + * + */ + +// 9.7.5.1. Comparison and Selection Instructions: set +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#comparison-and-selection-instructions-set + +// 9.7.5.2. Comparison and Selection Instructions: setp +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#comparison-and-selection-instructions-setp + +// 9.7.5.3. Comparison and Selection Instructions: selp +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#comparison-and-selection-instructions-selp + +// 9.7.5.4. Comparison and Selection Instructions: slct +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#comparison-and-selection-instructions-slct + + +/* + * 9.7.6. Half Precision Comparison Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-comparison-instructions + * + */ + +// 9.7.6.1. Half Precision Comparison Instructions: set +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-comparison-instructions-set + +// 9.7.6.2. Half Precision Comparison Instructions: setp +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-comparison-instructions-setp + + +/* + * 9.7.7. Logic and Shift Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions + * + */ + +// 9.7.7.1. Logic and Shift Instructions: and +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-and + +// 9.7.7.2. Logic and Shift Instructions: or +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-or + +// 9.7.7.3. Logic and Shift Instructions: xor +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-xor + +// 9.7.7.4. Logic and Shift Instructions: not +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-not + +// 9.7.7.5. Logic and Shift Instructions: cnot +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-cnot + +// 9.7.7.6. Logic and Shift Instructions: lop3 +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-lop3 + +// 9.7.7.7. Logic and Shift Instructions: shf +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-shf + +// 9.7.7.8. Logic and Shift Instructions: shl +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-shl + +// 9.7.7.9. Logic and Shift Instructions: shr +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-shr + + +/* + * 9.7.8. Data Movement and Conversion Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions + * + */ + +// 9.7.8.3. Data Movement and Conversion Instructions: mov +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-mov + +// 9.7.8.4. Data Movement and Conversion Instructions: mov +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-mov-2 + +// 9.7.8.5. Data Movement and Conversion Instructions: shfl (deprecated) +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-shfl-deprecated + +// 9.7.8.6. Data Movement and Conversion Instructions: shfl.sync +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-shfl-sync + +// 9.7.8.7. Data Movement and Conversion Instructions: prmt +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-prmt + +// 9.7.8.8. Data Movement and Conversion Instructions: ld +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-ld + +// 9.7.8.9. Data Movement and Conversion Instructions: ld.global.nc +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-ld-global-nc + +// 9.7.8.10. Data Movement and Conversion Instructions: ldu +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-ldu + +// 9.7.8.11. Data Movement and Conversion Instructions: st +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-st + +// 9.7.8.12. Data Movement and Conversion Instructions: st.async +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-st-async + +/* +// st.async.weak.shared::cluster.mbarrier::complete_tx::bytes{.type} [addr], value, [remote_bar]; // 1. PTX ISA 81, SM_90 +// .type = { .b32, .b64 } +template +__device__ static inline void st_async( + Type* addr, + const Type& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_st_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void st_async( + _Type* __addr, + const _Type& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + static_assert(sizeof(_Type) == 4 || sizeof(_Type) == 8, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (sizeof(_Type) == 4) { + asm ( + "st.async.weak.shared::cluster.mbarrier::complete_tx::bytes.b32 [%0], %1, [%2]; // 1. " + : + : "r"(__as_ptr_remote_dsmem(__addr)), + "r"(__as_b32(__value)), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + } else if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (sizeof(_Type) == 8) { + asm ( + "st.async.weak.shared::cluster.mbarrier::complete_tx::bytes.b64 [%0], %1, [%2]; // 1. " + : + : "r"(__as_ptr_remote_dsmem(__addr)), + "l"(__as_b64(__value)), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + } + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_st_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// st.async.weak.shared::cluster.mbarrier::complete_tx::bytes.v2{.type} [addr], value, [remote_bar]; // 2. PTX ISA 81, SM_90 +// .type = { .b32, .b64 } +template +__device__ static inline void st_async( + Type* addr, + const Type (&value)[2], + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_st_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void st_async( + _Type* __addr, + const _Type (&__value)[2], + _CUDA_VSTD::uint64_t* __remote_bar) +{ + static_assert(sizeof(_Type) == 4 || sizeof(_Type) == 8, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (sizeof(_Type) == 4) { + asm ( + "st.async.weak.shared::cluster.mbarrier::complete_tx::bytes.v2.b32 [%0], {%1, %2}, [%3]; // 2. " + : + : "r"(__as_ptr_remote_dsmem(__addr)), + "r"(__as_b32(__value[0])), + "r"(__as_b32(__value[1])), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + } else if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (sizeof(_Type) == 8) { + asm ( + "st.async.weak.shared::cluster.mbarrier::complete_tx::bytes.v2.b64 [%0], {%1, %2}, [%3]; // 2. " + : + : "r"(__as_ptr_remote_dsmem(__addr)), + "l"(__as_b64(__value[0])), + "l"(__as_b64(__value[1])), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + } + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_st_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// st.async.weak.shared::cluster.mbarrier::complete_tx::bytes.v4.b32 [addr], value, [remote_bar]; // 3. PTX ISA 81, SM_90 +template +__device__ static inline void st_async( + B32* addr, + const B32 (&value)[4], + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_st_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void st_async( + _B32* __addr, + const _B32 (&__value)[4], + _CUDA_VSTD::uint64_t* __remote_bar) +{ + static_assert(sizeof(_B32) == 4, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "st.async.weak.shared::cluster.mbarrier::complete_tx::bytes.v4.b32 [%0], {%1, %2, %3, %4}, [%5]; // 3. " + : + : "r"(__as_ptr_remote_dsmem(__addr)), + "r"(__as_b32(__value[0])), + "r"(__as_b32(__value[1])), + "r"(__as_b32(__value[2])), + "r"(__as_b32(__value[3])), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_st_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + + +// 9.7.8.13. Data Movement and Conversion Instructions: multimem.ld_reduce, multimem.st, multimem.red +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-multimem-ld-reduce-multimem-st-multimem-red + +// 9.7.8.14. Data Movement and Conversion Instructions: prefetch, prefetchu +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-prefetch-prefetchu + +// 9.7.8.15. Data Movement and Conversion Instructions: applypriority +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-applypriority + +// 9.7.8.16. Data Movement and Conversion Instructions: discard +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-discard + +// 9.7.8.17. Data Movement and Conversion Instructions: createpolicy +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-createpolicy + +// 9.7.8.18. Data Movement and Conversion Instructions: isspacep +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-isspacep + +// 9.7.8.19. Data Movement and Conversion Instructions: cvta +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cvta + +// 9.7.8.20. Data Movement and Conversion Instructions: cvt +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cvt + +// 9.7.8.21. Data Movement and Conversion Instructions: cvt.pack +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cvt-pack + +// 9.7.8.22. Data Movement and Conversion Instructions: mapa +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-mapa + +// 9.7.8.23. Data Movement and Conversion Instructions: getctarank +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-getctarank + + +/* + * 9.7.8.24. Data Movement and Conversion Instructions: Asynchronous copy + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-asynchronous-copy + * + */ + +// 9.7.8.24.3. Data Movement and Conversion Instructions: cp.async +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async + +// 9.7.8.24.4. Data Movement and Conversion Instructions: cp.async.commit_group +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async-commit-group + +// 9.7.8.24.5. Data Movement and Conversion Instructions: cp.async.wait_group / cp.async.wait_all +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async-wait-group-cp-async-wait-all + +// 9.7.8.24.6. Data Movement and Conversion Instructions: cp.async.bulk +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async-bulk + +// 9.7.8.24.7. Data Movement and Conversion Instructions: cp.reduce.async.bulk +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-reduce-async-bulk + +// 9.7.8.24.8. Data Movement and Conversion Instructions: cp.async.bulk.prefetch +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async-bulk-prefetch + +// 9.7.8.24.9. Data Movement and Conversion Instructions: cp.async.bulk.tensor +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async-bulk-tensor + +// 9.7.8.24.10. Data Movement and Conversion Instructions: cp.reduce.async.bulk.tensor +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-reduce-async-bulk-tensor + +// 9.7.8.24.11. Data Movement and Conversion Instructions: cp.async.bulk.prefetch.tensor +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async-bulk-prefetch-tensor + +// 9.7.8.24.12. Data Movement and Conversion Instructions: cp.async.bulk.commit_group +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async-bulk-commit-group + +// 9.7.8.24.13. Data Movement and Conversion Instructions: cp.async.bulk.wait_group +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async-bulk-wait-group + +// 9.7.8.25. Data Movement and Conversion Instructions: tensormap.replace +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-tensormap-replace + + +/* + * 9.7.9. Texture Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#texture-instructions + * + */ + +// 9.7.9.3. Texture Instructions: tex +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#texture-instructions-tex + +// 9.7.9.4. Texture Instructions: tld4 +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#texture-instructions-tld4 + +// 9.7.9.5. Texture Instructions: txq +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#texture-instructions-txq + +// 9.7.9.6. Texture Instructions: istypep +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#texture-instructions-istypep + + +/* + * 9.7.10. Surface Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#surface-instructions + * + */ + +// 9.7.10.1. Surface Instructions: suld +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#surface-instructions-suld + +// 9.7.10.2. Surface Instructions: sust +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#surface-instructions-sust + +// 9.7.10.3. Surface Instructions: sured +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#surface-instructions-sured + +// 9.7.10.4. Surface Instructions: suq +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#surface-instructions-suq + + +/* + * 9.7.11. Control Flow Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#control-flow-instructions + * + */ + +// 9.7.11.1. Control Flow Instructions: {} +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#control-flow-instructions-curly-braces + +// 9.7.11.2. Control Flow Instructions: @ +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#control-flow-instructions-at + +// 9.7.11.3. Control Flow Instructions: bra +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#control-flow-instructions-bra + +// 9.7.11.4. Control Flow Instructions: brx.idx +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#control-flow-instructions-brx-idx + +// 9.7.11.5. Control Flow Instructions: call +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#control-flow-instructions-call + +// 9.7.11.6. Control Flow Instructions: ret +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#control-flow-instructions-ret + +// 9.7.11.7. Control Flow Instructions: exit +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#control-flow-instructions-exit + + +/* + * 9.7.12. Parallel Synchronization and Communication Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions + * + */ + +// 9.7.12.1. Parallel Synchronization and Communication Instructions: bar, barrier +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-bar-barrier + +// 9.7.12.2. Parallel Synchronization and Communication Instructions: bar.warp.sync +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-bar-warp-sync + +// 9.7.12.3. Parallel Synchronization and Communication Instructions: barrier.cluster +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-barrier-cluster + +// 9.7.12.4. Parallel Synchronization and Communication Instructions: membar/fence +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-membar-fence + +// 9.7.12.5. Parallel Synchronization and Communication Instructions: atom +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-atom + +// 9.7.12.6. Parallel Synchronization and Communication Instructions: red +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-red + +// 9.7.12.7. Parallel Synchronization and Communication Instructions: red.async +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-red-async + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .u32 } +// .op = { .inc } +template +__device__ static inline void red_async( + cuda::ptx::op_inc_t, + uint32_t* dest, + const uint32_t& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_inc_t, + _CUDA_VSTD::uint32_t* __dest, + const _CUDA_VSTD::uint32_t& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_u32 (due to parameter type constraint) + // __op == op_inc (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.inc.u32 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "r"(__value), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .u32 } +// .op = { .dec } +template +__device__ static inline void red_async( + cuda::ptx::op_dec_t, + uint32_t* dest, + const uint32_t& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_dec_t, + _CUDA_VSTD::uint32_t* __dest, + const _CUDA_VSTD::uint32_t& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_u32 (due to parameter type constraint) + // __op == op_dec (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.dec.u32 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "r"(__value), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .u32 } +// .op = { .min } +template +__device__ static inline void red_async( + cuda::ptx::op_min_t, + uint32_t* dest, + const uint32_t& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_min_t, + _CUDA_VSTD::uint32_t* __dest, + const _CUDA_VSTD::uint32_t& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_u32 (due to parameter type constraint) + // __op == op_min (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.min.u32 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "r"(__value), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .u32 } +// .op = { .max } +template +__device__ static inline void red_async( + cuda::ptx::op_max_t, + uint32_t* dest, + const uint32_t& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_max_t, + _CUDA_VSTD::uint32_t* __dest, + const _CUDA_VSTD::uint32_t& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_u32 (due to parameter type constraint) + // __op == op_max (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.max.u32 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "r"(__value), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .u32 } +// .op = { .add } +template +__device__ static inline void red_async( + cuda::ptx::op_add_t, + uint32_t* dest, + const uint32_t& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_add_t, + _CUDA_VSTD::uint32_t* __dest, + const _CUDA_VSTD::uint32_t& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_u32 (due to parameter type constraint) + // __op == op_add (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.add.u32 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "r"(__value), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .s32 } +// .op = { .min } +template +__device__ static inline void red_async( + cuda::ptx::op_min_t, + int32_t* dest, + const int32_t& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_min_t, + _CUDA_VSTD::int32_t* __dest, + const _CUDA_VSTD::int32_t& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_s32 (due to parameter type constraint) + // __op == op_min (due to parameter type constraint) + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.min.s32 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "r"(__value), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .s32 } +// .op = { .max } +template +__device__ static inline void red_async( + cuda::ptx::op_max_t, + int32_t* dest, + const int32_t& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_max_t, + _CUDA_VSTD::int32_t* __dest, + const _CUDA_VSTD::int32_t& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_s32 (due to parameter type constraint) + // __op == op_max (due to parameter type constraint) + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.max.s32 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "r"(__value), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .s32 } +// .op = { .add } +template +__device__ static inline void red_async( + cuda::ptx::op_add_t, + int32_t* dest, + const int32_t& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_add_t, + _CUDA_VSTD::int32_t* __dest, + const _CUDA_VSTD::int32_t& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_s32 (due to parameter type constraint) + // __op == op_add (due to parameter type constraint) + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.add.s32 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "r"(__value), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .b32 } +// .op = { .and } +template +__device__ static inline void red_async( + cuda::ptx::op_and_op_t, + B32* dest, + const B32& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_and_op_t, + _B32* __dest, + const _B32& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_b32 (due to parameter type constraint) + // __op == op_and_op (due to parameter type constraint) + static_assert(sizeof(_B32) == 4, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.and.b32 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "r"(__as_b32(__value)), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .b32 } +// .op = { .or } +template +__device__ static inline void red_async( + cuda::ptx::op_or_op_t, + B32* dest, + const B32& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_or_op_t, + _B32* __dest, + const _B32& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_b32 (due to parameter type constraint) + // __op == op_or_op (due to parameter type constraint) + static_assert(sizeof(_B32) == 4, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.or.b32 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "r"(__as_b32(__value)), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .b32 } +// .op = { .xor } +template +__device__ static inline void red_async( + cuda::ptx::op_xor_op_t, + B32* dest, + const B32& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_xor_op_t, + _B32* __dest, + const _B32& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_b32 (due to parameter type constraint) + // __op == op_xor_op (due to parameter type constraint) + static_assert(sizeof(_B32) == 4, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.xor.b32 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "r"(__as_b32(__value)), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}{.type} [dest], value, [remote_bar]; // PTX ISA 81, SM_90 +// .type = { .u64 } +// .op = { .add } +template +__device__ static inline void red_async( + cuda::ptx::op_add_t, + uint64_t* dest, + const uint64_t& value, + uint64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_add_t, + _CUDA_VSTD::uint64_t* __dest, + const _CUDA_VSTD::uint64_t& __value, + _CUDA_VSTD::uint64_t* __remote_bar) +{ + // __type == type_u64 (due to parameter type constraint) + // __op == op_add (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.add.u64 [%0], %1, [%2]; " + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "l"(__value), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + +/* +// red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes{.op}.u64 [dest], value, [remote_bar]; // .u64 intentional PTX ISA 81, SM_90 +// .op = { .add } +template +__device__ static inline void red_async( + cuda::ptx::op_add_t, + int64_t* dest, + const int64_t& value, + int64_t* remote_bar); +*/ +#if __cccl_ptx_isa >= 810 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void red_async( + op_add_t, + _CUDA_VSTD::int64_t* __dest, + const _CUDA_VSTD::int64_t& __value, + _CUDA_VSTD::int64_t* __remote_bar) +{ + // __op == op_add (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "red.async.relaxed.cluster.shared::cluster.mbarrier::complete_tx::bytes.add.u64 [%0], %1, [%2]; // .u64 intentional" + : + : "r"(__as_ptr_remote_dsmem(__dest)), + "l"(__value), + "r"(__as_ptr_remote_dsmem(__remote_bar)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_red_async_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 810 + + +// 9.7.12.8. Parallel Synchronization and Communication Instructions: vote (deprecated) +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-vote-deprecated + +// 9.7.12.9. Parallel Synchronization and Communication Instructions: vote.sync +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-vote-sync + +// 9.7.12.10. Parallel Synchronization and Communication Instructions: match.sync +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-match-sync + +// 9.7.12.11. Parallel Synchronization and Communication Instructions: activemask +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-activemask + +// 9.7.12.12. Parallel Synchronization and Communication Instructions: redux.sync +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-redux-sync + +// 9.7.12.13. Parallel Synchronization and Communication Instructions: griddepcontrol +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-griddepcontrol + +// 9.7.12.14. Parallel Synchronization and Communication Instructions: elect.sync +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-elect-sync + +/* + * 9.7.12.15. Parallel Synchronization and Communication Instructions: mbarrier + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-mbarrier + * + * Contained in: __cuda/ptx/parallel_synchronization_and_communication_instructions_mbarrier.h + */ + +// 9.7.12.15.18. Parallel Synchronization and Communication Instructions: tensormap.cp_fenceproxy +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-tensormap-cp-fenceproxy + + +/* + * 9.7.13. Warp Level Matrix Multiply-Accumulate Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#warp-level-matrix-multiply-accumulate-instructions + * + */ + +// 9.7.13.3.3. Warp-level Matrix Load Instruction: wmma.load +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#warp-level-matrix-load-instruction-wmma-load + +// 9.7.13.3.4. Warp-level Matrix Store Instruction: wmma.store +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#warp-level-matrix-store-instruction-wmma-store + +// 9.7.13.3.5. Warp-level Matrix Multiply-and-Accumulate Instruction: wmma.mma +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#warp-level-matrix-multiply-and-accumulate-instruction-wmma-mma + +// 9.7.13.4.14. Multiply-and-Accumulate Instruction: mma +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#multiply-and-accumulate-instruction-mma + +// 9.7.13.4.15. Warp-level matrix load instruction: ldmatrix +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#warp-level-matrix-load-instruction-ldmatrix + +// 9.7.13.4.16. Warp-level matrix store instruction: stmatrix +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#warp-level-matrix-store-instruction-stmatrix + +// 9.7.13.4.17. Warp-level matrix transpose instruction: movmatrix +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#warp-level-matrix-transpose-instruction-movmatrix + +// 9.7.13.5.3. Multiply-and-Accumulate Instruction: mma.sp +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#multiply-and-accumulate-instruction-mma-sp + + +/* + * 9.7.14. Asynchronous Warpgroup Level Matrix Multiply-Accumulate Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#asynchronous-warpgroup-level-matrix-multiply-accumulate-instructions + * + */ + +// 9.7.14.5.2. Asynchronous Multiply-and-Accumulate Instruction: wgmma.mma_async +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#asynchronous-multiply-and-accumulate-instruction-wgmma-mma-async + +// 9.7.14.6.4. Asynchronous Multiply-and-Accumulate Instruction: wgmma.mma_async.sp +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#asynchronous-multiply-and-accumulate-instruction-wgmma-mma-async-sp + +// 9.7.14.7.1. Asynchronous Multiply-and-Accumulate Instruction: wgmma.fence +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#asynchronous-multiply-and-accumulate-instruction-wgmma-fence + +// 9.7.14.7.2. Asynchronous Multiply-and-Accumulate Instruction: wgmma.commit_group +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#asynchronous-multiply-and-accumulate-instruction-wgmma-commit-group + +// 9.7.14.7.3. Asynchronous Multiply-and-Accumulate Instruction: wgmma.wait_group +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#asynchronous-multiply-and-accumulate-instruction-wgmma-wait-group + + +/* + * 9.7.15. Stack Manipulation Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#stack-manipulation-instructions + * + */ + +// 9.7.15.1. Stack Manipulation Instructions: stacksave +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#stack-manipulation-instructions-stacksave + +// 9.7.15.2. Stack Manipulation Instructions: stackrestore +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#stack-manipulation-instructions-stackrestore + +// 9.7.15.3. Stack Manipulation Instructions: alloca +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#stack-manipulation-instructions-alloca + + +/* + * 9.7.16. Video Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#video-instructions + * + */ + +// 9.7.16.1.1. Scalar Video Instructions: vadd, vsub, vabsdiff, vmin, vmax +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#scalar-video-instructions-vadd-vsub-vabsdiff-vmin-vmax + +// 9.7.16.1.2. Scalar Video Instructions: vshl, vshr +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#scalar-video-instructions-vshl-vshr + +// 9.7.16.1.3. Scalar Video Instructions: vmad +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#scalar-video-instructions-vmad + +// 9.7.16.1.4. Scalar Video Instructions: vset +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#scalar-video-instructions-vset + + +/* + * 9.7.16.2. SIMD Video Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#simd-video-instructions + * + */ + +// 9.7.16.2.1. SIMD Video Instructions: vadd2, vsub2, vavrg2, vabsdiff2, vmin2, vmax2 +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#simd-video-instructions-vadd2-vsub2-vavrg2-vabsdiff2-vmin2-vmax2 + +// 9.7.16.2.2. SIMD Video Instructions: vset2 +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#simd-video-instructions-vset2 + +// 9.7.16.2.3. SIMD Video Instructions: vadd4, vsub4, vavrg4, vabsdiff4, vmin4, vmax4 +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#simd-video-instructions-vadd4-vsub4-vavrg4-vabsdiff4-vmin4-vmax4 + +// 9.7.16.2.4. SIMD Video Instructions: vset4 +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#simd-video-instructions-vset4 + + +/* + * 9.7.17. Miscellaneous Instructions + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#miscellaneous-instructions + * + */ + +// 9.7.17.1. Miscellaneous Instructions: brkpt +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#miscellaneous-instructions-brkpt + +// 9.7.17.2. Miscellaneous Instructions: nanosleep +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#miscellaneous-instructions-nanosleep + +// 9.7.17.3. Miscellaneous Instructions: pmevent +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#miscellaneous-instructions-pmevent + +// 9.7.17.4. Miscellaneous Instructions: trap +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#miscellaneous-instructions-trap + +// 9.7.17.5. Miscellaneous Instructions: setmaxnreg +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#miscellaneous-instructions-setmaxnreg + +_LIBCUDACXX_END_NAMESPACE_CUDA_PTX + +#endif // _LIBCUDACXX___CUDA_PTX_H diff --git a/cuda_toolkit/include/__cuda/ptx/parallel_synchronization_and_communication_instructions_mbarrier.h b/cuda_toolkit/include/__cuda/ptx/parallel_synchronization_and_communication_instructions_mbarrier.h new file mode 100644 index 0000000000000000000000000000000000000000..6f7f1d735805d00f70869220c4b602b5336e46be --- /dev/null +++ b/cuda_toolkit/include/__cuda/ptx/parallel_synchronization_and_communication_instructions_mbarrier.h @@ -0,0 +1,1070 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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_PTX_PARALLEL_SYNCHRONIZATION_AND_COMMUNICATION_INSTRUCTIONS_MBARRIER_H_ +#define _CUDA_PTX_PARALLEL_SYNCHRONIZATION_AND_COMMUNICATION_INSTRUCTIONS_MBARRIER_H_ + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include "ptx_dot_variants.h" +#include "ptx_helper_functions.h" +#include "../../cstdint" + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_PTX + +/* + * 9.7.12.15. Parallel Synchronization and Communication Instructions: mbarrier + * https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-mbarrier + * + */ + +// 9.7.12.15.9. Parallel Synchronization and Communication Instructions: mbarrier.init +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-mbarrier-init + +// 9.7.12.15.10. Parallel Synchronization and Communication Instructions: mbarrier.inval +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-mbarrier-inval + +// 9.7.12.15.11. Parallel Synchronization and Communication Instructions: mbarrier.expect_tx +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-mbarrier-expect-tx + +// 9.7.12.15.12. Parallel Synchronization and Communication Instructions: mbarrier.complete_tx +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-mbarrier-complete-tx + +// 9.7.12.15.13. Parallel Synchronization and Communication Instructions: mbarrier.arrive +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-mbarrier-arrive + +/* +PTX ISA docs: + +// mbarrier.arrive: +mbarrier.arrive{.shared}.b64 state, [addr]; // 1. PTX ISA 70, SM_80 +mbarrier.arrive{.shared{::cta}}.b64 state, [addr]{, count}; // 2. PTX ISA 78, SM_90 (due to count) + +mbarrier.arrive{.sem}{.scope}{.shared{::cta}}.b64 state, [addr]{, count}; // 3. PTX ISA 80, SM_90 (some variants are SM_80, but are covered by 1) +mbarrier.arrive{.sem}{.scope}{.shared::cluster}.b64 _, [addr] {,count} // 4. PTX ISA 80, SM_90 + +.sem = { .release } +.scope = { .cta, .cluster } + + +// mbarrier.arrive.noComplete: +mbarrier.arrive.noComplete{.shared}.b64 state, [addr], count; // 5. PTX ISA 70, SM_80 +mbarrier.arrive.noComplete{.shared{::cta}}.b64 state, [addr], count; // 6. PTX ISA 78, Not exposed. Just a spelling change (shared -> shared::cta) +mbarrier.arrive.noComplete{.sem}{.cta}{.shared{::cta}}.b64 state, [addr], count; // 7. PTX ISA 80, Not exposed. Adds .release, and .cta scope. + + +// mbarrier.arrive.expect_tx: +mbarrier.arrive.expect_tx{.sem}{.scope}{.shared{::cta}}.b64 state, [addr], tx_count; // 8. PTX ISA 80, SM_90 +mbarrier.arrive.expect_tx{.sem}{.scope}{.shared::cluster}.b64 _, [addr], tx_count; // 9. PTX ISA 80, SM_90 + +.sem = { .release } +.scope = { .cta, .cluster } + + +Corresponding Exposure: + +// mbarrier_arrive: +mbarrier.arrive.shared.b64 state, [addr]; // 1. PTX ISA 70, SM_80, !memory +// count is non-optional, otherwise 3 would not be distinguishable from 1 +mbarrier.arrive.shared::cta.b64 state, [addr], count; // 2. PTX ISA 78, SM_90, !memory +mbarrier.arrive{.sem}{.scope}{.space}.b64 state, [addr]; // 3a. PTX ISA 80, SM_90, !memory +.space = { .shared::cta} +.sem = { .release } +.scope = { .cta, .cluster } + +mbarrier.arrive{.sem}{.scope}{.space}.b64 state, [addr], count; // 3b. PTX ISA 80, SM_90, !memory +.space = { .shared::cta} +.sem = { .release } +.scope = { .cta, .cluster } + +// NOTE: .scope=.cta is dropped on purpose +mbarrier.arrive{.sem}{.scope}{.space}.b64 _, [addr]; // 4a. PTX ISA 80, SM_90, !memory +.space = { .shared::cluster} +.sem = { .release } +.scope = { .cluster } + +// NOTE: .scope=.cta is dropped on purpose +mbarrier.arrive{.sem}{.scope}{.space}.b64 _, [addr], count; // 4b. PTX ISA 80, SM_90, !memory +.space = { .shared::cluster} +.sem = { .release } +.scope = { .cluster } + + +// mbarrier_arrive_no_complete: +mbarrier.arrive.noComplete.shared.b64 state, [addr], count; // 5. PTX ISA 70, SM_80, !memory + + +mbarrier.arrive.expect_tx{.sem}{.scope}{.space}.b64 state, [addr], tx_count; // 8. PTX ISA 80, SM_90, !memory +.space = { .shared::cta } +.sem = { .release } +.scope = { .cta, .cluster } + +// NOTE: .scope=.cta is dropped on purpose +mbarrier.arrive.expect_tx{.sem}{.scope}{.space}.b64 _, [addr], tx_count; // 9. PTX ISA 80, SM_90, !memory +.space = { .shared::cluster } +.sem = { .release } +.scope = { .cluster } + +*/ + +/* +// mbarrier.arrive.shared.b64 state, [addr]; // 1. PTX ISA 70, SM_80 +template +__device__ static inline uint64_t mbarrier_arrive( + uint64_t* addr); +*/ +#if __cccl_ptx_isa >= 700 +extern "C" _LIBCUDACXX_DEVICE _CUDA_VSTD::uint64_t ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_80__(); +template +_LIBCUDACXX_DEVICE static inline _CUDA_VSTD::uint64_t mbarrier_arrive( + _CUDA_VSTD::uint64_t* __addr) +{ + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_80,( + _CUDA_VSTD::uint64_t __state; + asm ( + "mbarrier.arrive.shared.b64 %0, [%1]; // 1. " + : "=l"(__state) + : "r"(__as_ptr_smem(__addr)) + : "memory" + ); + return __state; + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_80__(); + )); +} +#endif // __cccl_ptx_isa >= 700 + +/* +// mbarrier.arrive.shared::cta.b64 state, [addr], count; // 2. PTX ISA 78, SM_90 +template +__device__ static inline uint64_t mbarrier_arrive( + uint64_t* addr, + const uint32_t& count); +*/ +#if __cccl_ptx_isa >= 780 +extern "C" _LIBCUDACXX_DEVICE _CUDA_VSTD::uint64_t ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline _CUDA_VSTD::uint64_t mbarrier_arrive( + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __count) +{ + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint64_t __state; + asm ( + "mbarrier.arrive.shared::cta.b64 %0, [%1], %2; // 2. " + : "=l"(__state) + : "r"(__as_ptr_smem(__addr)), + "r"(__count) + : "memory" + ); + return __state; + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 780 + +/* +// mbarrier.arrive{.sem}{.scope}{.space}.b64 state, [addr]; // 3a. PTX ISA 80, SM_90 +// .sem = { .release } +// .scope = { .cta, .cluster } +// .space = { .shared::cta } +template +__device__ static inline uint64_t mbarrier_arrive( + cuda::ptx::sem_release_t, + cuda::ptx::scope_t scope, + cuda::ptx::space_shared_t, + uint64_t* addr); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE _CUDA_VSTD::uint64_t ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline _CUDA_VSTD::uint64_t mbarrier_arrive( + sem_release_t, + scope_t<_Scope> __scope, + space_shared_t, + _CUDA_VSTD::uint64_t* __addr) +{ + // __sem == sem_release (due to parameter type constraint) + static_assert(__scope == scope_cta || __scope == scope_cluster, ""); + // __space == space_shared (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint64_t __state; + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cta) { + asm ( + "mbarrier.arrive.release.cta.shared.b64 %0, [%1]; // 3a. " + : "=l"(__state) + : "r"(__as_ptr_smem(__addr)) + : "memory" + ); + } else if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cluster) { + asm ( + "mbarrier.arrive.release.cluster.shared.b64 %0, [%1]; // 3a. " + : "=l"(__state) + : "r"(__as_ptr_smem(__addr)) + : "memory" + ); + } + return __state; + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + +/* +// mbarrier.arrive{.sem}{.scope}{.space}.b64 state, [addr], count; // 3b. PTX ISA 80, SM_90 +// .sem = { .release } +// .scope = { .cta, .cluster } +// .space = { .shared::cta } +template +__device__ static inline uint64_t mbarrier_arrive( + cuda::ptx::sem_release_t, + cuda::ptx::scope_t scope, + cuda::ptx::space_shared_t, + uint64_t* addr, + const uint32_t& count); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE _CUDA_VSTD::uint64_t ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline _CUDA_VSTD::uint64_t mbarrier_arrive( + sem_release_t, + scope_t<_Scope> __scope, + space_shared_t, + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __count) +{ + // __sem == sem_release (due to parameter type constraint) + static_assert(__scope == scope_cta || __scope == scope_cluster, ""); + // __space == space_shared (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint64_t __state; + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cta) { + asm ( + "mbarrier.arrive.release.cta.shared.b64 %0, [%1], %2; // 3b. " + : "=l"(__state) + : "r"(__as_ptr_smem(__addr)), + "r"(__count) + : "memory" + ); + } else if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cluster) { + asm ( + "mbarrier.arrive.release.cluster.shared.b64 %0, [%1], %2; // 3b. " + : "=l"(__state) + : "r"(__as_ptr_smem(__addr)), + "r"(__count) + : "memory" + ); + } + return __state; + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + +/* +// mbarrier.arrive{.sem}{.scope}{.space}.b64 _, [addr]; // 4a. PTX ISA 80, SM_90 +// .sem = { .release } +// .scope = { .cluster } +// .space = { .shared::cluster } +template +__device__ static inline void mbarrier_arrive( + cuda::ptx::sem_release_t, + cuda::ptx::scope_cluster_t, + cuda::ptx::space_cluster_t, + uint64_t* addr); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void mbarrier_arrive( + sem_release_t, + scope_cluster_t, + space_cluster_t, + _CUDA_VSTD::uint64_t* __addr) +{ + // __sem == sem_release (due to parameter type constraint) + // __scope == scope_cluster (due to parameter type constraint) + // __space == space_cluster (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "mbarrier.arrive.release.cluster.shared::cluster.b64 _, [%0]; // 4a. " + : + : "r"(__as_ptr_smem(__addr)) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + +/* +// mbarrier.arrive{.sem}{.scope}{.space}.b64 _, [addr], count; // 4b. PTX ISA 80, SM_90 +// .sem = { .release } +// .scope = { .cluster } +// .space = { .shared::cluster } +template +__device__ static inline void mbarrier_arrive( + cuda::ptx::sem_release_t, + cuda::ptx::scope_cluster_t, + cuda::ptx::space_cluster_t, + uint64_t* addr, + const uint32_t& count); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void mbarrier_arrive( + sem_release_t, + scope_cluster_t, + space_cluster_t, + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __count) +{ + // __sem == sem_release (due to parameter type constraint) + // __scope == scope_cluster (due to parameter type constraint) + // __space == space_cluster (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "mbarrier.arrive.release.cluster.shared::cluster.b64 _, [%0], %1; // 4b. " + : + : "r"(__as_ptr_smem(__addr)), + "r"(__count) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_mbarrier_arrive_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + +/* +// mbarrier.arrive.noComplete.shared.b64 state, [addr], count; // 5. PTX ISA 70, SM_80 +template +__device__ static inline uint64_t mbarrier_arrive_no_complete( + uint64_t* addr, + const uint32_t& count); +*/ +#if __cccl_ptx_isa >= 700 +extern "C" _LIBCUDACXX_DEVICE _CUDA_VSTD::uint64_t ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_no_complete_is_not_supported_before_SM_80__(); +template +_LIBCUDACXX_DEVICE static inline _CUDA_VSTD::uint64_t mbarrier_arrive_no_complete( + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __count) +{ + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_80,( + _CUDA_VSTD::uint64_t __state; + asm ( + "mbarrier.arrive.noComplete.shared.b64 %0, [%1], %2; // 5. " + : "=l"(__state) + : "r"(__as_ptr_smem(__addr)), + "r"(__count) + : "memory" + ); + return __state; + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_no_complete_is_not_supported_before_SM_80__(); + )); +} +#endif // __cccl_ptx_isa >= 700 + +/* +// mbarrier.arrive.expect_tx{.sem}{.scope}{.space}.b64 state, [addr], tx_count; // 8. PTX ISA 80, SM_90 +// .sem = { .release } +// .scope = { .cta, .cluster } +// .space = { .shared::cta } +template +__device__ static inline uint64_t mbarrier_arrive_expect_tx( + cuda::ptx::sem_release_t, + cuda::ptx::scope_t scope, + cuda::ptx::space_shared_t, + uint64_t* addr, + const uint32_t& tx_count); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE _CUDA_VSTD::uint64_t ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_expect_tx_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline _CUDA_VSTD::uint64_t mbarrier_arrive_expect_tx( + sem_release_t, + scope_t<_Scope> __scope, + space_shared_t, + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __tx_count) +{ + // __sem == sem_release (due to parameter type constraint) + static_assert(__scope == scope_cta || __scope == scope_cluster, ""); + // __space == space_shared (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint64_t __state; + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cta) { + asm ( + "mbarrier.arrive.expect_tx.release.cta.shared.b64 %0, [%1], %2; // 8. " + : "=l"(__state) + : "r"(__as_ptr_smem(__addr)), + "r"(__tx_count) + : "memory" + ); + } else if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cluster) { + asm ( + "mbarrier.arrive.expect_tx.release.cluster.shared.b64 %0, [%1], %2; // 8. " + : "=l"(__state) + : "r"(__as_ptr_smem(__addr)), + "r"(__tx_count) + : "memory" + ); + } + return __state; + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return ___cuda_vstd_uint64_t__cuda_ptx_mbarrier_arrive_expect_tx_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + +/* +// mbarrier.arrive.expect_tx{.sem}{.scope}{.space}.b64 _, [addr], tx_count; // 9. PTX ISA 80, SM_90 +// .sem = { .release } +// .scope = { .cluster } +// .space = { .shared::cluster } +template +__device__ static inline void mbarrier_arrive_expect_tx( + cuda::ptx::sem_release_t, + cuda::ptx::scope_cluster_t, + cuda::ptx::space_cluster_t, + uint64_t* addr, + const uint32_t& tx_count); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE void __void__cuda_ptx_mbarrier_arrive_expect_tx_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline void mbarrier_arrive_expect_tx( + sem_release_t, + scope_cluster_t, + space_cluster_t, + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __tx_count) +{ + // __sem == sem_release (due to parameter type constraint) + // __scope == scope_cluster (due to parameter type constraint) + // __space == space_cluster (due to parameter type constraint) + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + asm ( + "mbarrier.arrive.expect_tx.release.cluster.shared::cluster.b64 _, [%0], %1; // 9. " + : + : "r"(__as_ptr_smem(__addr)), + "r"(__tx_count) + : "memory" + ); + + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __void__cuda_ptx_mbarrier_arrive_expect_tx_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + + + + +// 9.7.12.15.14. Parallel Synchronization and Communication Instructions: mbarrier.arrive_drop +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-mbarrier-arrive-drop + +// 9.7.12.15.15. Parallel Synchronization and Communication Instructions: cp.async.mbarrier.arrive +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-cp-async-mbarrier-arrive + +// 9.7.12.15.16. Parallel Synchronization and Communication Instructions: mbarrier.test_wait/mbarrier.try_wait +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-mbarrier-test-wait-mbarrier-try-wait + +/* +// mbarrier.test_wait.shared.b64 waitComplete, [addr], state; // 1. PTX ISA 70, SM_80 +template +__device__ static inline bool mbarrier_test_wait( + uint64_t* addr, + const uint64_t& state); +*/ +#if __cccl_ptx_isa >= 700 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_test_wait_is_not_supported_before_SM_80__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_test_wait( + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint64_t& __state) +{ + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_80,( + _CUDA_VSTD::uint32_t __waitComplete; + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.test_wait.shared.b64 P_OUT, [%1], %2; // 1. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "l"(__state) + : "memory" + ); + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_test_wait_is_not_supported_before_SM_80__(); + )); +} +#endif // __cccl_ptx_isa >= 700 + +/* +// mbarrier.test_wait{.sem}{.scope}.shared::cta.b64 waitComplete, [addr], state; // 2. PTX ISA 80, SM_90 +// .sem = { .acquire } +// .scope = { .cta, .cluster } +template +__device__ static inline bool mbarrier_test_wait( + cuda::ptx::sem_acquire_t, + cuda::ptx::scope_t scope, + uint64_t* addr, + const uint64_t& state); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_test_wait_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_test_wait( + sem_acquire_t, + scope_t<_Scope> __scope, + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint64_t& __state) +{ + // __sem == sem_acquire (due to parameter type constraint) + static_assert(__scope == scope_cta || __scope == scope_cluster, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint32_t __waitComplete; + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cta) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.test_wait.acquire.cta.shared::cta.b64 P_OUT, [%1], %2; // 2. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "l"(__state) + : "memory" + ); + } else if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cluster) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.test_wait.acquire.cluster.shared::cta.b64 P_OUT, [%1], %2; // 2. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "l"(__state) + : "memory" + ); + } + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_test_wait_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + +/* +// mbarrier.test_wait.parity.shared.b64 waitComplete, [addr], phaseParity; // 3. PTX ISA 71, SM_80 +template +__device__ static inline bool mbarrier_test_wait_parity( + uint64_t* addr, + const uint32_t& phaseParity); +*/ +#if __cccl_ptx_isa >= 710 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_test_wait_parity_is_not_supported_before_SM_80__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_test_wait_parity( + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __phaseParity) +{ + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_80,( + _CUDA_VSTD::uint32_t __waitComplete; + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.test_wait.parity.shared.b64 P_OUT, [%1], %2; // 3. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "r"(__phaseParity) + : "memory" + ); + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_test_wait_parity_is_not_supported_before_SM_80__(); + )); +} +#endif // __cccl_ptx_isa >= 710 + +/* +// mbarrier.test_wait.parity{.sem}{.scope}.shared::cta.b64 waitComplete, [addr], phaseParity; // 4. PTX ISA 80, SM_90 +// .sem = { .acquire } +// .scope = { .cta, .cluster } +template +__device__ static inline bool mbarrier_test_wait_parity( + cuda::ptx::sem_acquire_t, + cuda::ptx::scope_t scope, + uint64_t* addr, + const uint32_t& phaseParity); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_test_wait_parity_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_test_wait_parity( + sem_acquire_t, + scope_t<_Scope> __scope, + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __phaseParity) +{ + // __sem == sem_acquire (due to parameter type constraint) + static_assert(__scope == scope_cta || __scope == scope_cluster, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint32_t __waitComplete; + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cta) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.test_wait.parity.acquire.cta.shared::cta.b64 P_OUT, [%1], %2; // 4. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "r"(__phaseParity) + : "memory" + ); + } else if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cluster) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.test_wait.parity.acquire.cluster.shared::cta.b64 P_OUT, [%1], %2; // 4. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "r"(__phaseParity) + : "memory" + ); + } + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_test_wait_parity_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + +/* +// mbarrier.try_wait.shared::cta.b64 waitComplete, [addr], state; // 5a. PTX ISA 78, SM_90 +template +__device__ static inline bool mbarrier_try_wait( + uint64_t* addr, + const uint64_t& state); +*/ +#if __cccl_ptx_isa >= 780 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_try_wait_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_try_wait( + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint64_t& __state) +{ + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint32_t __waitComplete; + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.shared::cta.b64 P_OUT, [%1], %2; // 5a. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "l"(__state) + : "memory" + ); + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_try_wait_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 780 + +/* +// mbarrier.try_wait.shared::cta.b64 waitComplete, [addr], state, suspendTimeHint; // 5b. PTX ISA 78, SM_90 +template +__device__ static inline bool mbarrier_try_wait( + uint64_t* addr, + const uint64_t& state, + const uint32_t& suspendTimeHint); +*/ +#if __cccl_ptx_isa >= 780 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_try_wait_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_try_wait( + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint64_t& __state, + const _CUDA_VSTD::uint32_t& __suspendTimeHint) +{ + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint32_t __waitComplete; + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.shared::cta.b64 P_OUT, [%1], %2, %3; // 5b. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "l"(__state), + "r"(__suspendTimeHint) + : "memory" + ); + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_try_wait_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 780 + +/* +// mbarrier.try_wait{.sem}{.scope}.shared::cta.b64 waitComplete, [addr], state; // 6a. PTX ISA 80, SM_90 +// .sem = { .acquire } +// .scope = { .cta, .cluster } +template +__device__ static inline bool mbarrier_try_wait( + cuda::ptx::sem_acquire_t, + cuda::ptx::scope_t scope, + uint64_t* addr, + const uint64_t& state); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_try_wait_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_try_wait( + sem_acquire_t, + scope_t<_Scope> __scope, + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint64_t& __state) +{ + // __sem == sem_acquire (due to parameter type constraint) + static_assert(__scope == scope_cta || __scope == scope_cluster, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint32_t __waitComplete; + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cta) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.acquire.cta.shared::cta.b64 P_OUT, [%1], %2; // 6a. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "l"(__state) + : "memory" + ); + } else if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cluster) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.acquire.cluster.shared::cta.b64 P_OUT, [%1], %2; // 6a. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "l"(__state) + : "memory" + ); + } + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_try_wait_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + +/* +// mbarrier.try_wait{.sem}{.scope}.shared::cta.b64 waitComplete, [addr], state , suspendTimeHint; // 6b. PTX ISA 80, SM_90 +// .sem = { .acquire } +// .scope = { .cta, .cluster } +template +__device__ static inline bool mbarrier_try_wait( + cuda::ptx::sem_acquire_t, + cuda::ptx::scope_t scope, + uint64_t* addr, + const uint64_t& state, + const uint32_t& suspendTimeHint); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_try_wait_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_try_wait( + sem_acquire_t, + scope_t<_Scope> __scope, + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint64_t& __state, + const _CUDA_VSTD::uint32_t& __suspendTimeHint) +{ + // __sem == sem_acquire (due to parameter type constraint) + static_assert(__scope == scope_cta || __scope == scope_cluster, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint32_t __waitComplete; + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cta) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.acquire.cta.shared::cta.b64 P_OUT, [%1], %2 , %3; // 6b. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "l"(__state), + "r"(__suspendTimeHint) + : "memory" + ); + } else if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cluster) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.acquire.cluster.shared::cta.b64 P_OUT, [%1], %2 , %3; // 6b. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "l"(__state), + "r"(__suspendTimeHint) + : "memory" + ); + } + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_try_wait_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + +/* +// mbarrier.try_wait.parity.shared::cta.b64 waitComplete, [addr], phaseParity; // 7a. PTX ISA 78, SM_90 +template +__device__ static inline bool mbarrier_try_wait_parity( + uint64_t* addr, + const uint32_t& phaseParity); +*/ +#if __cccl_ptx_isa >= 780 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_try_wait_parity_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_try_wait_parity( + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __phaseParity) +{ + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint32_t __waitComplete; + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.parity.shared::cta.b64 P_OUT, [%1], %2; // 7a. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "r"(__phaseParity) + : "memory" + ); + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_try_wait_parity_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 780 + +/* +// mbarrier.try_wait.parity.shared::cta.b64 waitComplete, [addr], phaseParity, suspendTimeHint; // 7b. PTX ISA 78, SM_90 +template +__device__ static inline bool mbarrier_try_wait_parity( + uint64_t* addr, + const uint32_t& phaseParity, + const uint32_t& suspendTimeHint); +*/ +#if __cccl_ptx_isa >= 780 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_try_wait_parity_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_try_wait_parity( + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __phaseParity, + const _CUDA_VSTD::uint32_t& __suspendTimeHint) +{ + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint32_t __waitComplete; + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.parity.shared::cta.b64 P_OUT, [%1], %2, %3; // 7b. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "r"(__phaseParity), + "r"(__suspendTimeHint) + : "memory" + ); + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_try_wait_parity_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 780 + +/* +// mbarrier.try_wait.parity{.sem}{.scope}.shared::cta.b64 waitComplete, [addr], phaseParity; // 8a. PTX ISA 80, SM_90 +// .sem = { .acquire } +// .scope = { .cta, .cluster } +template +__device__ static inline bool mbarrier_try_wait_parity( + cuda::ptx::sem_acquire_t, + cuda::ptx::scope_t scope, + uint64_t* addr, + const uint32_t& phaseParity); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_try_wait_parity_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_try_wait_parity( + sem_acquire_t, + scope_t<_Scope> __scope, + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __phaseParity) +{ + // __sem == sem_acquire (due to parameter type constraint) + static_assert(__scope == scope_cta || __scope == scope_cluster, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint32_t __waitComplete; + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cta) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.parity.acquire.cta.shared::cta.b64 P_OUT, [%1], %2; // 8a. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "r"(__phaseParity) + : "memory" + ); + } else if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cluster) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.parity.acquire.cluster.shared::cta.b64 P_OUT, [%1], %2; // 8a. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "r"(__phaseParity) + : "memory" + ); + } + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_try_wait_parity_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + +/* +// mbarrier.try_wait.parity{.sem}{.scope}.shared::cta.b64 waitComplete, [addr], phaseParity, suspendTimeHint; // 8b. PTX ISA 80, SM_90 +// .sem = { .acquire } +// .scope = { .cta, .cluster } +template +__device__ static inline bool mbarrier_try_wait_parity( + cuda::ptx::sem_acquire_t, + cuda::ptx::scope_t scope, + uint64_t* addr, + const uint32_t& phaseParity, + const uint32_t& suspendTimeHint); +*/ +#if __cccl_ptx_isa >= 800 +extern "C" _LIBCUDACXX_DEVICE bool __bool__cuda_ptx_mbarrier_try_wait_parity_is_not_supported_before_SM_90__(); +template +_LIBCUDACXX_DEVICE static inline bool mbarrier_try_wait_parity( + sem_acquire_t, + scope_t<_Scope> __scope, + _CUDA_VSTD::uint64_t* __addr, + const _CUDA_VSTD::uint32_t& __phaseParity, + const _CUDA_VSTD::uint32_t& __suspendTimeHint) +{ + // __sem == sem_acquire (due to parameter type constraint) + static_assert(__scope == scope_cta || __scope == scope_cluster, ""); + + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,( + _CUDA_VSTD::uint32_t __waitComplete; + if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cta) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.parity.acquire.cta.shared::cta.b64 P_OUT, [%1], %2, %3; // 8b. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "r"(__phaseParity), + "r"(__suspendTimeHint) + : "memory" + ); + } else if _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 (__scope == scope_cluster) { + asm ( + "{\n\t .reg .pred P_OUT; \n\t" + "mbarrier.try_wait.parity.acquire.cluster.shared::cta.b64 P_OUT, [%1], %2, %3; // 8b. \n\t" + "selp.b32 %0, 1, 0, P_OUT; \n" + "}" + : "=r"(__waitComplete) + : "r"(__as_ptr_smem(__addr)), + "r"(__phaseParity), + "r"(__suspendTimeHint) + : "memory" + ); + } + return static_cast(__waitComplete); // Deliberate downcast. + ),( + // Unsupported architectures will have a linker error with a semi-decent error message + return __bool__cuda_ptx_mbarrier_try_wait_parity_is_not_supported_before_SM_90__(); + )); +} +#endif // __cccl_ptx_isa >= 800 + + +// 9.7.12.15.17. Parallel Synchronization and Communication Instructions: mbarrier.pending_count +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-mbarrier-pending-count + +_LIBCUDACXX_END_NAMESPACE_CUDA_PTX + +#endif // _CUDA_PTX_PARALLEL_SYNCHRONIZATION_AND_COMMUNICATION_INSTRUCTIONS_MBARRIER_H_ diff --git a/cuda_toolkit/include/__cuda/ptx/ptx_dot_variants.h b/cuda_toolkit/include/__cuda/ptx/ptx_dot_variants.h new file mode 100644 index 0000000000000000000000000000000000000000..fdd4ca47b566ba766f30e4d6c7b1862ba5d85450 --- /dev/null +++ b/cuda_toolkit/include/__cuda/ptx/ptx_dot_variants.h @@ -0,0 +1,176 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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_PTX_DOT_VARIANTS_H_ +#define _CUDA_PTX_DOT_VARIANTS_H_ + +#include "../../__type_traits/integral_constant.h" // std::integral_constant + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +/* + * Public integral constant types and values for ".variant"s: + * + * - .sem: acquire, release, .. + * - .space: global, shared, constant, .. + * - .scope: cta, cluster, gpu, .. + * - .op: add, min, cas, .. + * + * For each .variant, the code below defines: + * - An enum `dot_variant` with each possible value + * - A type template `variant_t` + * - Types `variant_A_t`, ..., `variant_Z_t` + * - Constexpr values `variant_A` of type `variant_A_t` + * + * These types enable specifying fine-grained overloads of a PTX binding. If a + * binding can handle multiple variants, then it is defined as: + * + * template + * [...] void ptx_binding(variant_t __v) { ... } + * + * If it only handles a single variant, then it is defined as: + * + * [...] void ptx_binding(variant_A __v) { ... } + * + * If two variants have different behaviors or return types (see .space + * overloads of mbarrier.arrive.expect_tx for an example), then these can be + * provided as separate overloads of the same function: + * + * [...] void ptx_binding(variant_A __v) { ... } + * [...] int ptx_binding(variant_B __v) { ... } + * + */ + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_PTX + +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#operation-types +enum class dot_sem +{ + acq_rel, + acquire, + relaxed, + release, + sc, + weak +}; + +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#state-spaces +enum class dot_space +{ + global, + cluster, // The PTX spelling is shared::cluster + shared, // The PTX spelling is shared::cta + + // The following state spaces are unlikely to be used in cuda::ptx in the near + // future, so they are not exposed: + + // reg, + // sreg, + // const_mem, // Using const_mem as `const` is reserved in C++. + // local, + // param, + // tex // deprecated +}; + +// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#scope +enum class dot_scope +{ + cta, + cluster, + gpu, + sys +}; + +enum class dot_op +{ + add, + dec, + inc, + max, + min, + and_op, // Using and_op, as `and, or, xor` are reserved in C++. + or_op, + xor_op, + cas, + exch +}; + +template +using sem_t = _CUDA_VSTD::integral_constant; +using sem_acq_rel_t = sem_t; +using sem_acquire_t = sem_t; +using sem_relaxed_t = sem_t; +using sem_release_t = sem_t; +using sem_sc_t = sem_t; +using sem_weak_t = sem_t; + +static constexpr sem_acq_rel_t sem_acq_rel{}; +static constexpr sem_acquire_t sem_acquire{}; +static constexpr sem_relaxed_t sem_relaxed{}; +static constexpr sem_release_t sem_release{}; +static constexpr sem_sc_t sem_sc{}; +static constexpr sem_weak_t sem_weak{}; + +template +using space_t = _CUDA_VSTD::integral_constant; +using space_global_t = space_t; +using space_shared_t = space_t; +using space_cluster_t = space_t; + +static constexpr space_global_t space_global{}; +static constexpr space_shared_t space_shared{}; +static constexpr space_cluster_t space_cluster{}; + +template +using scope_t = _CUDA_VSTD::integral_constant; +using scope_cluster_t = scope_t; +using scope_cta_t = scope_t; +using scope_gpu_t = scope_t; +using scope_sys_t = scope_t; + +static constexpr scope_cluster_t scope_cluster{}; +static constexpr scope_cta_t scope_cta{}; +static constexpr scope_gpu_t scope_gpu{}; +static constexpr scope_sys_t scope_sys{}; + +template +using op_t = _CUDA_VSTD::integral_constant; +using op_add_t = op_t; +using op_dec_t = op_t; +using op_inc_t = op_t; +using op_max_t = op_t; +using op_min_t = op_t; +using op_and_op_t = op_t; +using op_or_op_t = op_t; +using op_xor_op_t = op_t; +using op_cas_t = op_t; +using op_exch_t = op_t; + +static constexpr op_add_t op_add{}; +static constexpr op_dec_t op_dec{}; +static constexpr op_inc_t op_inc{}; +static constexpr op_max_t op_max{}; +static constexpr op_min_t op_min{}; +static constexpr op_and_op_t op_and_op{}; +static constexpr op_or_op_t op_or_op{}; +static constexpr op_xor_op_t op_xor_op{}; +static constexpr op_cas_t op_cas{}; +static constexpr op_exch_t op_exch{}; + +_LIBCUDACXX_END_NAMESPACE_CUDA_PTX + +#endif // _CUDA_PTX_DOT_VARIANTS_H_ diff --git a/cuda_toolkit/include/__cuda/ptx/ptx_helper_functions.h b/cuda_toolkit/include/__cuda/ptx/ptx_helper_functions.h new file mode 100644 index 0000000000000000000000000000000000000000..699316c6e440b46e2027ae3222b05dc22e0bcb51 --- /dev/null +++ b/cuda_toolkit/include/__cuda/ptx/ptx_helper_functions.h @@ -0,0 +1,68 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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_PTX_HELPER_FUNCTIONS_H_ +#define _CUDA_PTX_HELPER_FUNCTIONS_H_ + +#include "../../cstdint" // uint32_t + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_PTX + +inline _LIBCUDACXX_DEVICE _CUDA_VSTD::uint32_t __as_ptr_smem(const void* __ptr) +{ + // Consider adding debug asserts here. + return static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__ptr)); +} + +inline _LIBCUDACXX_DEVICE _CUDA_VSTD::uint32_t __as_ptr_remote_dsmem(const void* __ptr) +{ + // No difference in implementation to __as_ptr_smem. + // Consider adding debug asserts here. + return static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__ptr)); +} + +inline _LIBCUDACXX_DEVICE _CUDA_VSTD::uint64_t __as_ptr_gmem(const void* __ptr) +{ + // Consider adding debug asserts here. + return static_cast<_CUDA_VSTD::uint64_t>(__cvta_generic_to_global(__ptr)); +} + +template +inline _LIBCUDACXX_DEVICE _CUDA_VSTD::uint32_t __as_b32(_Tp __val) +{ +#if _LIBCUDACXX_STD_VER >= 17 && !defined(_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR) + static_assert(sizeof(_Tp) == 4, ""); +#endif // _LIBCUDACXX_STD_VER >= 17 && !_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR + // Consider using std::bitcast + return *reinterpret_cast<_CUDA_VSTD::uint32_t*>(&__val); +} + +template +inline _LIBCUDACXX_DEVICE _CUDA_VSTD::uint64_t __as_b64(_Tp __val) +{ +#if _LIBCUDACXX_STD_VER >= 17 && !defined(_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR) + static_assert(sizeof(_Tp) == 8, ""); +#endif // _LIBCUDACXX_STD_VER >= 17 && !_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR + // Consider using std::bitcast + return *reinterpret_cast<_CUDA_VSTD::uint64_t*>(&__val); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA_PTX + +#endif // _CUDA_PTX_HELPER_FUNCTIONS_H_ diff --git a/cuda_toolkit/include/__cuda/semaphore.h b/cuda_toolkit/include/__cuda/semaphore.h new file mode 100644 index 0000000000000000000000000000000000000000..27e9e4ff08d7ef8a65a94280942b1cb16d62ebba --- /dev/null +++ b/cuda_toolkit/include/__cuda/semaphore.h @@ -0,0 +1,46 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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 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/cuda_toolkit/include/__expected/bad_expected_access.h b/cuda_toolkit/include/__expected/bad_expected_access.h new file mode 100644 index 0000000000000000000000000000000000000000..d77b56c1352e6ef1d49dd8b9b37202a3255eea31 --- /dev/null +++ b/cuda_toolkit/include/__expected/bad_expected_access.h @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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__ + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include "../__utility/move.h" +#include "../exception" + +#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() noexcept 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 std::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/cuda_toolkit/include/__expected/expected.h b/cuda_toolkit/include/__expected/expected.h new file mode 100644 index 0000000000000000000000000000000000000000..1550b16d2ea6a8650c773d17cacad427b1e6b008 --- /dev/null +++ b/cuda_toolkit/include/__expected/expected.h @@ -0,0 +1,1790 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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)(__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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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)(__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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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/cuda_toolkit/include/__expected/expected_base.h b/cuda_toolkit/include/__expected/expected_base.h new file mode 100644 index 0000000000000000000000000000000000000000..c8cc960e13ed3472b72b5b9945d8be9ccde9f0cf --- /dev/null +++ b/cuda_toolkit/include/__expected/expected_base.h @@ -0,0 +1,1048 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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/cuda_toolkit/include/__expected/unexpect.h b/cuda_toolkit/include/__expected/unexpect.h new file mode 100644 index 0000000000000000000000000000000000000000..f9a0f8a522dc6b27611df09130913168a8a10f21 --- /dev/null +++ b/cuda_toolkit/include/__expected/unexpect.h @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#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/cuda_toolkit/include/__expected/unexpected.h b/cuda_toolkit/include/__expected/unexpected.h new file mode 100644 index 0000000000000000000000000000000000000000..7020365c1aed0dd66dfe5b75bf2c4f700834bb54 --- /dev/null +++ b/cuda_toolkit/include/__expected/unexpected.h @@ -0,0 +1,170 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + constexpr const _Err& error() const& noexcept { + return __unex_; + } + + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + constexpr _Err& error() & noexcept { + return __unex_; + } + + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + constexpr const _Err&& error() const&& noexcept { + return _CUDA_VSTD::move(__unex_); + } + + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + 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) + _LIBCUDACXX_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/cuda_toolkit/include/__functional/binary_function.h b/cuda_toolkit/include/__functional/binary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..22bd6068faf8ac62a43cdb3a16de4bfabac30660 --- /dev/null +++ b/cuda_toolkit/include/__functional/binary_function.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 +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BINARY_FUNCTION_H +#define _LIBCUDACXX___FUNCTIONAL_BINARY_FUNCTION_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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) +_CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH +template +using __binary_function = binary_function<_Arg1, _Arg2, _Result>; +_CCCL_DIAG_SUPPRESS_DEPRECATED_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/cuda_toolkit/include/__functional/binary_negate.h b/cuda_toolkit/include/__functional/binary_negate.h new file mode 100644 index 0000000000000000000000000000000000000000..9b45f479fc99256b57d72ac3f177004e490aee74 --- /dev/null +++ b/cuda_toolkit/include/__functional/binary_negate.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_BINARY_NEGATE_H +#define _LIBCUDACXX___FUNCTIONAL_BINARY_NEGATE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__functional/bind.h b/cuda_toolkit/include/__functional/bind.h new file mode 100644 index 0000000000000000000000000000000000000000..9e573a23320632d922fc5b25141e028fd23a88a5 --- /dev/null +++ b/cuda_toolkit/include/__functional/bind.h @@ -0,0 +1,417 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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_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_BUILDING_LIBRARY) + +} // namespace placeholders + +template +struct is_placeholder > + : public integral_constant {}; + + +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 __make_tuple_indices_t __indices; + return _CUDA_VSTD::__mu_expand(__ti, __uj, __indices()); +} + +template +struct __mu_return2 {}; + +template +struct __mu_return2 +{ + typedef __tuple_element_t::value - 1, _Uj> 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<__tuple_element_t<_Indx, _Uj>>(_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 __tuple_element_t::value - 1, _TupleUj>&& 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 __make_tuple_indices_t __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)...); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // __cuda_std__ + +#endif // _LIBCUDACXX___FUNCTIONAL_BIND_H diff --git a/cuda_toolkit/include/__functional/bind_back.h b/cuda_toolkit/include/__functional/bind_back.h new file mode 100644 index 0000000000000000000000000000000000000000..927511f3c7e925c3c65095ade19e21abd89826cc --- /dev/null +++ b/cuda_toolkit/include/__functional/bind_back.h @@ -0,0 +1,79 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__functional/bind_front.h b/cuda_toolkit/include/__functional/bind_front.h new file mode 100644 index 0000000000000000000000000000000000000000..33b334d3f3f59110750a2329299f3e6c3c31d869 --- /dev/null +++ b/cuda_toolkit/include/__functional/bind_front.h @@ -0,0 +1,82 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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) + _LIBCUDACXX_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/cuda_toolkit/include/__functional/binder1st.h b/cuda_toolkit/include/__functional/binder1st.h new file mode 100644 index 0000000000000000000000000000000000000000..501157bcfb74f6c9ec2ff89deb2d0a821c9e4cb0 --- /dev/null +++ b/cuda_toolkit/include/__functional/binder1st.h @@ -0,0 +1,67 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH + +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);} + +_CCCL_DIAG_SUPPRESS_DEPRECATED_POP + +#endif // _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BINDER1ST_H diff --git a/cuda_toolkit/include/__functional/binder2nd.h b/cuda_toolkit/include/__functional/binder2nd.h new file mode 100644 index 0000000000000000000000000000000000000000..535ff2d3acb80983ea5535b41f31459f4214c8ee --- /dev/null +++ b/cuda_toolkit/include/__functional/binder2nd.h @@ -0,0 +1,67 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH + +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);} + +_CCCL_DIAG_SUPPRESS_DEPRECATED_POP + +#endif // _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BINDER2ND_H diff --git a/cuda_toolkit/include/__functional/compose.h b/cuda_toolkit/include/__functional/compose.h new file mode 100644 index 0000000000000000000000000000000000000000..c7a9fdb2b50406ceb419cd186da02fb95045f152 --- /dev/null +++ b/cuda_toolkit/include/__functional/compose.h @@ -0,0 +1,60 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__functional/default_searcher.h b/cuda_toolkit/include/__functional/default_searcher.h new file mode 100644 index 0000000000000000000000000000000000000000..864a1e86fba0941e57083b71848cce979254cc05 --- /dev/null +++ b/cuda_toolkit/include/__functional/default_searcher.h @@ -0,0 +1,152 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__functional/function.h b/cuda_toolkit/include/__functional/function.h new file mode 100644 index 0000000000000000000000000000000000000000..b1cb54c6c4824ea0e9c8cc5d17a1d52732ed2a13 --- /dev/null +++ b/cuda_toolkit/include/__functional/function.h @@ -0,0 +1,1254 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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 + +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 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 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 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);} + + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // __cuda_std__ + +#endif // _LIBCUDACXX___FUNCTIONAL_FUNCTION_H diff --git a/cuda_toolkit/include/__functional/hash.h b/cuda_toolkit/include/__functional/hash.h new file mode 100644 index 0000000000000000000000000000000000000000..711a06ee2e4e7449c71a3037d46096f5fffcd53d --- /dev/null +++ b/cuda_toolkit/include/__functional/hash.h @@ -0,0 +1,693 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#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 + +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 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // __cuda_std__ + +#endif // _LIBCUDACXX___FUNCTIONAL_HASH_H diff --git a/cuda_toolkit/include/__functional/identity.h b/cuda_toolkit/include/__functional/identity.h new file mode 100644 index 0000000000000000000000000000000000000000..0c5611241032567e8601e050bdc4afb078034708 --- /dev/null +++ b/cuda_toolkit/include/__functional/identity.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___FUNCTIONAL_IDENTITY_H +#define _LIBCUDACXX___FUNCTIONAL_IDENTITY_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__utility/forward.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +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; +}; + +#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/cuda_toolkit/include/__functional/invoke.h b/cuda_toolkit/include/__functional/invoke.h new file mode 100644 index 0000000000000000000000000000000000000000..6be9dd5cfefce71492f5d4147a87f2975ed2b6af --- /dev/null +++ b/cuda_toolkit/include/__functional/invoke.h @@ -0,0 +1,565 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// 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 +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 +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 +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 +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 +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 +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 +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/cuda_toolkit/include/__functional/is_transparent.h b/cuda_toolkit/include/__functional/is_transparent.h new file mode 100644 index 0000000000000000000000000000000000000000..45d5aaba2e4cae79562730df457529dd022f80f9 --- /dev/null +++ b/cuda_toolkit/include/__functional/is_transparent.h @@ -0,0 +1,44 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__functional/mem_fn.h b/cuda_toolkit/include/__functional/mem_fn.h new file mode 100644 index 0000000000000000000000000000000000000000..d2011874819ccf61ec8c337fb1568a0767ca2105 --- /dev/null +++ b/cuda_toolkit/include/__functional/mem_fn.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___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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__functional/mem_fun_ref.h b/cuda_toolkit/include/__functional/mem_fun_ref.h new file mode 100644 index 0000000000000000000000000000000000000000..216b3b7a90b474392369211d7973ff0f6eff1512 --- /dev/null +++ b/cuda_toolkit/include/__functional/mem_fun_ref.h @@ -0,0 +1,185 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH + +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);} + +_CCCL_DIAG_SUPPRESS_DEPRECATED_POP + +#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/cuda_toolkit/include/__functional/not_fn.h b/cuda_toolkit/include/__functional/not_fn.h new file mode 100644 index 0000000000000000000000000000000000000000..4b6b0fb3ccd7fca6ac44d7ac87e331b908209147 --- /dev/null +++ b/cuda_toolkit/include/__functional/not_fn.h @@ -0,0 +1,77 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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) + _LIBCUDACXX_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/cuda_toolkit/include/__functional/operations.h b/cuda_toolkit/include/__functional/operations.h new file mode 100644 index 0000000000000000000000000000000000000000..2fb6df4d6f1e90897a7d31a0223d4bf51794e81b --- /dev/null +++ b/cuda_toolkit/include/__functional/operations.h @@ -0,0 +1,626 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__functional/perfect_forward.h b/cuda_toolkit/include/__functional/perfect_forward.h new file mode 100644 index 0000000000000000000000000000000000000000..98e5638992721f6f5687b28207b3f394c58f3f14 --- /dev/null +++ b/cuda_toolkit/include/__functional/perfect_forward.h @@ -0,0 +1,117 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_REQUIRES( (!is_invocable_v<_Op, _BoundArgs&..., _Args...>)) + _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_Args&&...) & = delete; + + _LIBCUDACXX_TEMPLATE(class... _Args) + _LIBCUDACXX_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) + _LIBCUDACXX_REQUIRES( (!is_invocable_v<_Op, _BoundArgs const&..., _Args...>)) + _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_Args&&...) const& = delete; + + _LIBCUDACXX_TEMPLATE(class... _Args) + _LIBCUDACXX_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) + _LIBCUDACXX_REQUIRES( (!is_invocable_v<_Op, _BoundArgs..., _Args...>)) + _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_Args&&...) && = delete; + + _LIBCUDACXX_TEMPLATE(class... _Args) + _LIBCUDACXX_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) + _LIBCUDACXX_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/cuda_toolkit/include/__functional/pointer_to_binary_function.h b/cuda_toolkit/include/__functional/pointer_to_binary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..784fda73fed96063814364a598b95549a7fd8353 --- /dev/null +++ b/cuda_toolkit/include/__functional/pointer_to_binary_function.h @@ -0,0 +1,58 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH + +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);} + +_CCCL_DIAG_SUPPRESS_DEPRECATED_POP + +#endif // _LIBCUDACXX_STD_VER <= 14 || _LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_POINTER_TO_BINARY_FUNCTION_H diff --git a/cuda_toolkit/include/__functional/pointer_to_unary_function.h b/cuda_toolkit/include/__functional/pointer_to_unary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..523665e9406756a4c6eb0059223441963e3ff087 --- /dev/null +++ b/cuda_toolkit/include/__functional/pointer_to_unary_function.h @@ -0,0 +1,58 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH + +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);} + +_CCCL_DIAG_SUPPRESS_DEPRECATED_POP + +#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/cuda_toolkit/include/__functional/ranges_operations.h b/cuda_toolkit/include/__functional/ranges_operations.h new file mode 100644 index 0000000000000000000000000000000000000000..7445367470a82f0dad7e48c40425af6232acc26f --- /dev/null +++ b/cuda_toolkit/include/__functional/ranges_operations.h @@ -0,0 +1,111 @@ +// -*- 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_RANGES_OPERATIONS_H +#define _LIBCUDACXX___FUNCTIONAL_RANGES_OPERATIONS_H + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "../__concepts/equality_comparable.h" +#include "../__concepts/totally_ordered.h" +#include "../__utility/forward.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#if _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES_ABI + +struct equal_to { + _LIBCUDACXX_TEMPLATE(class _Tp, class _Up) + _LIBCUDACXX_REQUIRES( equality_comparable_with<_Tp, _Up>) + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + constexpr bool operator()(_Tp &&__t, _Up &&__u) const + noexcept(noexcept(bool(_CUDA_VSTD::forward<_Tp>(__t) == _CUDA_VSTD::forward<_Up>(__u)))) { + return _CUDA_VSTD::forward<_Tp>(__t) == _CUDA_VSTD::forward<_Up>(__u); + } + + using is_transparent = void; +}; + +struct not_equal_to { + _LIBCUDACXX_TEMPLATE(class _Tp, class _Up) + _LIBCUDACXX_REQUIRES( equality_comparable_with<_Tp, _Up>) + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + constexpr bool operator()(_Tp &&__t, _Up &&__u) const + noexcept(noexcept(bool(!(_CUDA_VSTD::forward<_Tp>(__t) == _CUDA_VSTD::forward<_Up>(__u))))) { + return !(_CUDA_VSTD::forward<_Tp>(__t) == _CUDA_VSTD::forward<_Up>(__u)); + } + + using is_transparent = void; +}; + +struct less { + _LIBCUDACXX_TEMPLATE(class _Tp, class _Up) + _LIBCUDACXX_REQUIRES( totally_ordered_with<_Tp, _Up>) + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + constexpr bool operator()(_Tp &&__t, _Up &&__u) const + noexcept(noexcept(bool(_CUDA_VSTD::forward<_Tp>(__t) < _CUDA_VSTD::forward<_Up>(__u)))) { + return _CUDA_VSTD::forward<_Tp>(__t) < _CUDA_VSTD::forward<_Up>(__u); + } + + using is_transparent = void; +}; + +struct less_equal { + _LIBCUDACXX_TEMPLATE(class _Tp, class _Up) + _LIBCUDACXX_REQUIRES( totally_ordered_with<_Tp, _Up>) + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + constexpr bool operator()(_Tp &&__t, _Up &&__u) const + noexcept(noexcept(bool(!(_CUDA_VSTD::forward<_Up>(__u) < _CUDA_VSTD::forward<_Tp>(__t))))) { + return !(_CUDA_VSTD::forward<_Up>(__u) < _CUDA_VSTD::forward<_Tp>(__t)); + } + + using is_transparent = void; +}; + +struct greater { + _LIBCUDACXX_TEMPLATE(class _Tp, class _Up) + _LIBCUDACXX_REQUIRES( totally_ordered_with<_Tp, _Up>) + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + constexpr bool operator()(_Tp &&__t, _Up &&__u) const + noexcept(noexcept(bool(_CUDA_VSTD::forward<_Up>(__u) < _CUDA_VSTD::forward<_Tp>(__t)))) { + return _CUDA_VSTD::forward<_Up>(__u) < _CUDA_VSTD::forward<_Tp>(__t); + } + + using is_transparent = void; +}; + +struct greater_equal { + _LIBCUDACXX_TEMPLATE(class _Tp, class _Up) + _LIBCUDACXX_REQUIRES( totally_ordered_with<_Tp, _Up>) + _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY + constexpr bool operator()(_Tp &&__t, _Up &&__u) const + noexcept(noexcept(bool(!(_CUDA_VSTD::forward<_Tp>(__t) < _CUDA_VSTD::forward<_Up>(__u))))) { + return !(_CUDA_VSTD::forward<_Tp>(__t) < _CUDA_VSTD::forward<_Up>(__u)); + } + + using is_transparent = void; +}; +_LIBCUDACXX_END_NAMESPACE_RANGES_ABI +_LIBCUDACXX_END_NAMESPACE_RANGES + +#endif // _LIBCUDACXX_STD_VER > 14 + + +#endif // _LIBCUDACXX___FUNCTIONAL_RANGES_OPERATIONS_H diff --git a/cuda_toolkit/include/__functional/reference_wrapper.h b/cuda_toolkit/include/__functional/reference_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..afd61e7e2fd11ac115b3e9329ea5eb556cdda979 --- /dev/null +++ b/cuda_toolkit/include/__functional/reference_wrapper.h @@ -0,0 +1,107 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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 +_LIBCUDACXX_HOST_DEVICE 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/cuda_toolkit/include/__functional/unary_function.h b/cuda_toolkit/include/__functional/unary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..90bcfe38421408355d3a182a802cdacef52834df --- /dev/null +++ b/cuda_toolkit/include/__functional/unary_function.h @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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) + +_CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH +template +using __unary_function = unary_function<_Arg, _Result>; +_CCCL_DIAG_SUPPRESS_DEPRECATED_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/cuda_toolkit/include/__functional/unary_negate.h b/cuda_toolkit/include/__functional/unary_negate.h new file mode 100644 index 0000000000000000000000000000000000000000..c0f833d8d08b1642afc6a1fac9021026bb8506cf --- /dev/null +++ b/cuda_toolkit/include/__functional/unary_negate.h @@ -0,0 +1,60 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_NEGATORS) + +_CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH + +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);} + +_CCCL_DIAG_SUPPRESS_DEPRECATED_POP + +#endif // _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_NEGATORS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_UNARY_NEGATE_H diff --git a/cuda_toolkit/include/__functional/unwrap_ref.h b/cuda_toolkit/include/__functional/unwrap_ref.h new file mode 100644 index 0000000000000000000000000000000000000000..398ff118919bb1d7680b691bbeeac9295d540bfb --- /dev/null +++ b/cuda_toolkit/include/__functional/unwrap_ref.h @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__functional/weak_result_type.h b/cuda_toolkit/include/__functional/weak_result_type.h new file mode 100644 index 0000000000000000000000000000000000000000..8c5b5232d89a259ce78d93b9abd76de1ce98a9cf --- /dev/null +++ b/cuda_toolkit/include/__functional/weak_result_type.h @@ -0,0 +1,301 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__fwd/array.h b/cuda_toolkit/include/__fwd/array.h new file mode 100644 index 0000000000000000000000000000000000000000..d07e5642bb9df4b74fd081ec3f33e36e70ae23bd --- /dev/null +++ b/cuda_toolkit/include/__fwd/array.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) 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct _LIBCUDACXX_TEMPLATE_VIS array; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_ARRAY_H diff --git a/cuda_toolkit/include/__fwd/get.h b/cuda_toolkit/include/__fwd/get.h new file mode 100644 index 0000000000000000000000000000000000000000..3d246552b84b4f360f2cca326139f24682a71a75 --- /dev/null +++ b/cuda_toolkit/include/__fwd/get.h @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __tuple_element_t<_Ip, tuple<_Tp...>>& get( + tuple<_Tp...>&) noexcept; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 const __tuple_element_t<_Ip, tuple<_Tp...>>& get( + const tuple<_Tp...>&) noexcept; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __tuple_element_t<_Ip, tuple<_Tp...>>&& get( + tuple<_Tp...>&&) noexcept; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 const __tuple_element_t<_Ip, tuple<_Tp...>>&& get( + const tuple<_Tp...>&&) noexcept; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __tuple_element_t<_Ip, pair<_T1, _T2>>& get( + pair<_T1, _T2>&) noexcept; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 const __tuple_element_t<_Ip, pair<_T1, _T2>>& get( + const pair<_T1, _T2>&) noexcept; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __tuple_element_t<_Ip, pair<_T1, _T2>>&& get( + pair<_T1, _T2>&&) noexcept; + +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 const __tuple_element_t<_Ip, pair<_T1, _T2>>&& get( + const pair<_T1, _T2>&&) noexcept; + +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; + +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; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_GET_H diff --git a/cuda_toolkit/include/__fwd/hash.h b/cuda_toolkit/include/__fwd/hash.h new file mode 100644 index 0000000000000000000000000000000000000000..b91a9b6a82582a17200d4883e8e164ba02dd3c86 --- /dev/null +++ b/cuda_toolkit/include/__fwd/hash.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_HASH_H +#define _LIBCUDACXX___FWD_HASH_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct _LIBCUDACXX_TEMPLATE_VIS hash; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_HASH_H diff --git a/cuda_toolkit/include/__fwd/memory_resource.h b/cuda_toolkit/include/__fwd/memory_resource.h new file mode 100644 index 0000000000000000000000000000000000000000..38803984ec081d44029d1c9bb2f4423864395978 --- /dev/null +++ b/cuda_toolkit/include/__fwd/memory_resource.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) 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__fwd/pair.h b/cuda_toolkit/include/__fwd/pair.h new file mode 100644 index 0000000000000000000000000000000000000000..85fd027daef2c1b8a976b6034cfeec1b7eaffe59 --- /dev/null +++ b/cuda_toolkit/include/__fwd/pair.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_PAIR_H +#define _LIBCUDACXX___FWD_PAIR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct _LIBCUDACXX_TEMPLATE_VIS pair; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_PAIR_H diff --git a/cuda_toolkit/include/__fwd/span.h b/cuda_toolkit/include/__fwd/span.h new file mode 100644 index 0000000000000000000000000000000000000000..4bb75bf880344a400fede8fac86d26650bab3704 --- /dev/null +++ b/cuda_toolkit/include/__fwd/span.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___FWD_SPAN_H +#define _LIBCUDACXX___FWD_SPAN_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../cstddef" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__fwd/string.h b/cuda_toolkit/include/__fwd/string.h new file mode 100644 index 0000000000000000000000000000000000000000..6086f44adf4e23734c85a62728bb2045bf4473d5 --- /dev/null +++ b/cuda_toolkit/include/__fwd/string.h @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__fwd/string_view.h b/cuda_toolkit/include/__fwd/string_view.h new file mode 100644 index 0000000000000000000000000000000000000000..12e640f01acf8b7cfedebb0fb4e8cb5fd061c42b --- /dev/null +++ b/cuda_toolkit/include/__fwd/string_view.h @@ -0,0 +1,58 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__fwd/tuple.h b/cuda_toolkit/include/__fwd/tuple.h new file mode 100644 index 0000000000000000000000000000000000000000..0a3b523052166e5fa2d1bf9e6c1ca47d293778bc --- /dev/null +++ b/cuda_toolkit/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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +class _LIBCUDACXX_TEMPLATE_VIS tuple; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FWD_TUPLE_H diff --git a/cuda_toolkit/include/__iterator/access.h b/cuda_toolkit/include/__iterator/access.h new file mode 100644 index 0000000000000000000000000000000000000000..54d0bf4aa50cb3654b9a40a5c563e75610abbb32 --- /dev/null +++ b/cuda_toolkit/include/__iterator/access.h @@ -0,0 +1,98 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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; +} + +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 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_ACCESS_H diff --git a/cuda_toolkit/include/__iterator/advance.h b/cuda_toolkit/include/__iterator/advance.h new file mode 100644 index 0000000000000000000000000000000000000000..bfb9818ebd30f599941bb0df3bbfb6bd3d4840e0 --- /dev/null +++ b/cuda_toolkit/include/__iterator/advance.h @@ -0,0 +1,250 @@ +// -*- 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 "../__concepts/assignable.h" +#include "../__concepts/same_as.h" +#include "../__iterator/concepts.h" +#include "../__iterator/incrementable_traits.h" +#include "../__iterator/iterator_traits.h" +#include "../__utility/convert_to_integral.h" +#include "../__utility/move.h" +#include "../cstdlib" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_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 +_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 +_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 < class _InputIter, + class _Distance, + class _IntegralDistance = decltype(_CUDA_VSTD::__convert_to_integral(_CUDA_VSTD::declval<_Distance>())), + class = __enable_if_t::value> > +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 void advance(_InputIter& __i, _Distance __orig_n) +{ + typedef typename iterator_traits<_InputIter>::difference_type _Difference; + _Difference __n = static_cast<_Difference>(_CUDA_VSTD::__convert_to_integral(__orig_n)); + _LIBCUDACXX_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, + "Attempt to advance(it, n) with negative n on a non-bidirectional iterator"); + _CUDA_VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 && !defined(_LICBUDACXX_COMPILER_MSVC_2017) + +// [range.iter.op.advance] + +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES +_LIBCUDACXX_BEGIN_NAMESPACE_CPO(__advance) +struct __fn +{ +private: + template + _LIBCUDACXX_INLINE_VISIBILITY static constexpr void __advance_forward(_Ip& __i, iter_difference_t<_Ip> __n) + { + while (__n > 0) + { + --__n; + ++__i; + } + } + + template + _LIBCUDACXX_INLINE_VISIBILITY static constexpr void __advance_backward(_Ip& __i, iter_difference_t<_Ip> __n) + { + while (__n < 0) + { + ++__n; + --__i; + } + } + + template + _LIBCUDACXX_INLINE_VISIBILITY static constexpr auto + __magnitude_geq(_Iter_difference __a, _Iter_difference __b) noexcept + { + return __a == 0 ? __b == 0 : // + __a > 0 ? __a >= __b + : __a <= __b; + }; + +public: + // Preconditions: If `I` does not model `bidirectional_iterator`, `n` is not negative. + + _LIBCUDACXX_TEMPLATE(class _Ip) + _LIBCUDACXX_REQUIRES(input_or_output_iterator<_Ip>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr void + operator()(_Ip& __i, iter_difference_t<_Ip> __n) const + { + _LIBCUDACXX_ASSERT(__n >= 0 || bidirectional_iterator<_Ip>, + "If `n < 0`, then `bidirectional_iterator` must be true."); + + // If `I` models `random_access_iterator`, equivalent to `i += n`. + if constexpr (random_access_iterator<_Ip>) + { + __i += __n; + return; + } + else if constexpr (bidirectional_iterator<_Ip>) + { + // Otherwise, if `n` is non-negative, increments `i` by `n`. + __advance_forward(__i, __n); + // Otherwise, decrements `i` by `-n`. + __advance_backward(__i, __n); + return; + } + else + { + // Otherwise, if `n` is non-negative, increments `i` by `n`. + __advance_forward(__i, __n); + return; + } + } + + _LIBCUDACXX_TEMPLATE(class _Ip, class _Sp) + _LIBCUDACXX_REQUIRES(input_or_output_iterator<_Ip> _LIBCUDACXX_AND sentinel_for<_Sp, _Ip>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr void operator()(_Ip& __i, _Sp __bound_sentinel) const + { + // If `I` and `S` model `assignable_from`, equivalent to `i = std::move(bound_sentinel)`. + if constexpr (assignable_from<_Ip&, _Sp>) + { + __i = _CUDA_VSTD::move(__bound_sentinel); + } + // Otherwise, if `S` and `I` model `sized_sentinel_for`, + // equivalent to `ranges::advance(i, bound_sentinel - i)`. + else if constexpr (sized_sentinel_for<_Sp, _Ip>) + { + (*this)(__i, __bound_sentinel - __i); + } + // Otherwise, while `bool(i != bound_sentinel)` is true, increments `i`. + else + { + while (__i != __bound_sentinel) + { + ++__i; + } + } + } + + // Preconditions: + // * If `n > 0`, [i, bound_sentinel) denotes a range. + // * If `n == 0`, [i, bound_sentinel) or [bound_sentinel, i) denotes a range. + // * If `n < 0`, [bound_sentinel, i) denotes a range, `I` models `bidirectional_iterator`, + // and `I` and `S` model `same_as`. + // Returns: `n - M`, where `M` is the difference between the ending and starting position. + _LIBCUDACXX_TEMPLATE(class _Ip, class _Sp) + _LIBCUDACXX_REQUIRES(input_or_output_iterator<_Ip> _LIBCUDACXX_AND sentinel_for<_Sp, _Ip>) + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> + operator()(_Ip& __i, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const + { + _LIBCUDACXX_ASSERT((__n >= 0) || (bidirectional_iterator<_Ip> && same_as<_Ip, _Sp>), + "If `n < 0`, then `bidirectional_iterator && same_as` must be true."); + // If `S` and `I` model `sized_sentinel_for`: + if constexpr (sized_sentinel_for<_Sp, _Ip>) + { + // If |n| >= |bound_sentinel - i|, equivalent to `ranges::advance(i, bound_sentinel)`. + // __magnitude_geq(a, b) returns |a| >= |b|, assuming they have the same sign. + const auto __M = __bound_sentinel - __i; + if (__magnitude_geq(__n, __M)) + { + (*this)(__i, __bound_sentinel); + return __n - __M; + } + + // Otherwise, equivalent to `ranges::advance(i, n)`. + (*this)(__i, __n); + return 0; + } + else + { + // Otherwise, if `n` is non-negative, while `bool(i != bound_sentinel)` is true, increments `i` but at + // most `n` times. + while (__i != __bound_sentinel && __n > 0) + { + ++__i; + --__n; + } + + // Otherwise, while `bool(i != bound_sentinel)` is true, decrements `i` but at most `-n` times. + if constexpr (bidirectional_iterator<_Ip> && same_as<_Ip, _Sp>) + { + while (__i != __bound_sentinel && __n < 0) + { + --__i; + ++__n; + } + } + return __n; + } + _LIBCUDACXX_UNREACHABLE(); + } +}; +_LIBCUDACXX_END_NAMESPACE_CPO + +inline namespace __cpo +{ +_LIBCUDACXX_CPO_ACCESSIBILITY auto advance = __advance::__fn{}; +} // namespace __cpo + +_LIBCUDACXX_END_NAMESPACE_RANGES + +#endif // _LIBCUDACXX_STD_VER > 14 && !_LICBUDACXX_COMPILER_MSVC_2017 + +#endif // _LIBCUDACXX___ITERATOR_ADVANCE_H diff --git a/cuda_toolkit/include/__iterator/back_insert_iterator.h b/cuda_toolkit/include/__iterator/back_insert_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..a977729934f480d34a1df7096cbcfb031a384db3 --- /dev/null +++ b/cuda_toolkit/include/__iterator/back_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_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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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;} + _LIBCUDACXX_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_) + {container->push_back(_CUDA_VSTD::move(__value_)); return *this;} + _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/cuda_toolkit/include/__iterator/bounded_iter.h b/cuda_toolkit/include/__iterator/bounded_iter.h new file mode 100644 index 0000000000000000000000000000000000000000..2a8619cae90c99d0d8bde32b19b136d6dcf727eb --- /dev/null +++ b/cuda_toolkit/include/__iterator/bounded_iter.h @@ -0,0 +1,263 @@ +// -*- 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_BOUNDED_ITER_H +#define _LIBCUDACXX___ITERATOR_BOUNDED_ITER_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__assert" +#include "../__iterator/iterator_traits.h" +#include "../__memory/pointer_traits.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_convertible.h" +#include "../__utility/move.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +// Iterator wrapper that carries the valid range it is allowed to access. +// +// This is a simple iterator wrapper for contiguous iterators that points +// within a [begin, end) range and carries these bounds with it. The iterator +// ensures that it is pointing within that [begin, end) range when it is +// dereferenced. +// +// Arithmetic operations are allowed and the bounds of the resulting iterator +// are not checked. Hence, it is possible to create an iterator pointing outside +// its range, but it is not possible to dereference it. +template ::value > > +struct __bounded_iter { + using value_type = typename iterator_traits<_Iterator>::value_type; + using difference_type = typename iterator_traits<_Iterator>::difference_type; + using pointer = typename iterator_traits<_Iterator>::pointer; + using reference = typename iterator_traits<_Iterator>::reference; + using iterator_category = typename iterator_traits<_Iterator>::iterator_category; +#if _LIBCUDACXX_STD_VER > 14 + using iterator_concept = contiguous_iterator_tag; +#endif + + // Create a singular iterator. + // + // Such an iterator does not point to any object and is conceptually out of bounds, so it is + // not dereferenceable. Observing operations like comparison and assignment are valid. + __bounded_iter() = default; + + __bounded_iter(__bounded_iter const&) = default; + __bounded_iter(__bounded_iter&&) = default; + + template ::value > > + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr __bounded_iter(__bounded_iter<_OtherIterator> const& __other) noexcept + : __current_(__other.__current_), + __begin_(__other.__begin_), + __end_(__other.__end_) {} + + // Assign a bounded iterator to another one, rebinding the bounds of the iterator as well. + __bounded_iter& operator=(__bounded_iter const&) = default; + __bounded_iter& operator=(__bounded_iter&&) = default; + +private: + // Create an iterator wrapping the given iterator, and whose bounds are described + // by the provided [begin, end) range. + // + // This constructor does not check whether the resulting iterator is within its bounds. + // However, it does check that the provided [begin, end) range is a valid range (that + // is, begin <= end). + // + // Since it is non-standard for iterators to have this constructor, __bounded_iter must + // be created via `_CUDA_VSTD::__make_bounded_iter`. + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 explicit __bounded_iter( + _Iterator __current, _Iterator __begin, _Iterator __end) + : __current_(__current), __begin_(__begin), __end_(__end) { + _LIBCUDACXX_ASSERT(__begin <= __end, "__bounded_iter(current, begin, end): [begin, end) is not a valid range"); + } + + template + friend _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr __bounded_iter<_It> __make_bounded_iter(_It, _It, _It); + +public: + // Dereference and indexing operations. + // + // These operations check that the iterator is dereferenceable, that is within [begin, end). + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 reference operator*() const noexcept { + _LIBCUDACXX_ASSERT( + __in_bounds(__current_), "__bounded_iter::operator*: Attempt to dereference an out-of-range iterator"); + return *__current_; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 pointer operator->() const noexcept { + _LIBCUDACXX_ASSERT( + __in_bounds(__current_), "__bounded_iter::operator->: Attempt to dereference an out-of-range iterator"); + return _CUDA_VSTD::__to_address(__current_); + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 reference operator[](difference_type __n) const noexcept { + _LIBCUDACXX_ASSERT( + __in_bounds(__current_ + __n), "__bounded_iter::operator[]: Attempt to index an iterator out-of-range"); + return __current_[__n]; + } + + // Arithmetic operations. + // + // These operations do not check that the resulting iterator is within the bounds, since that + // would make it impossible to create a past-the-end iterator. + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator++() noexcept { + ++__current_; + return *this; + } + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __bounded_iter operator++(int) noexcept { + __bounded_iter __tmp(*this); + ++*this; + return __tmp; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator--() noexcept { + --__current_; + return *this; + } + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __bounded_iter operator--(int) noexcept { + __bounded_iter __tmp(*this); + --*this; + return __tmp; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator+=(difference_type __n) noexcept { + __current_ += __n; + return *this; + } + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 friend __bounded_iter + operator+(__bounded_iter const& __self, difference_type __n) noexcept { + __bounded_iter __tmp(__self); + __tmp += __n; + return __tmp; + } + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 friend __bounded_iter + operator+(difference_type __n, __bounded_iter const& __self) noexcept { + __bounded_iter __tmp(__self); + __tmp += __n; + return __tmp; + } + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator-=(difference_type __n) noexcept { + __current_ -= __n; + return *this; + } + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 friend __bounded_iter + operator-(__bounded_iter const& __self, difference_type __n) noexcept { + __bounded_iter __tmp(__self); + __tmp -= __n; + return __tmp; + } + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 friend difference_type + operator-(__bounded_iter const& __x, __bounded_iter const& __y) noexcept { + return __x.__current_ - __y.__current_; + } + + // Comparison operations. + // + // These operations do not check whether the iterators are within their bounds. + // The valid range for each iterator is also not considered as part of the comparison, + // i.e. two iterators pointing to the same location will be considered equal even + // if they have different validity ranges. + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr friend bool + operator==(__bounded_iter const& __x, __bounded_iter const& __y) noexcept { + return __x.__current_ == __y.__current_; + } + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr friend bool + operator!=(__bounded_iter const& __x, __bounded_iter const& __y) noexcept { + return __x.__current_ != __y.__current_; + } + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr friend bool + operator<(__bounded_iter const& __x, __bounded_iter const& __y) noexcept { + return __x.__current_ < __y.__current_; + } + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr friend bool + operator>(__bounded_iter const& __x, __bounded_iter const& __y) noexcept { + return __x.__current_ > __y.__current_; + } + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr friend bool + operator<=(__bounded_iter const& __x, __bounded_iter const& __y) noexcept { + return __x.__current_ <= __y.__current_; + } + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr friend bool + operator>=(__bounded_iter const& __x, __bounded_iter const& __y) noexcept { + return __x.__current_ >= __y.__current_; + } + +private: + // Return whether the given iterator is in the bounds of this __bounded_iter. + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr bool __in_bounds(_Iterator const& __iter) const { + return __iter >= __begin_ && __iter < __end_; + } + + template + friend struct pointer_traits; + _Iterator __current_; // current iterator + _Iterator __begin_, __end_; // valid range represented as [begin, end) +}; + +template +_LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY +constexpr __bounded_iter<_It> __make_bounded_iter(_It __it, _It __begin, _It __end) { + return __bounded_iter<_It>(_CUDA_VSTD::move(__it), _CUDA_VSTD::move(__begin), _CUDA_VSTD::move(__end)); +} + +#if _LIBCUDACXX_STD_VER <= 17 +template +struct __is_cpp17_contiguous_iterator<__bounded_iter<_Iterator> > : true_type {}; +#endif + +template +struct pointer_traits<__bounded_iter<_Iterator> > { + using pointer = __bounded_iter<_Iterator>; + using element_type = typename pointer_traits<_Iterator>::element_type; + using difference_type = typename pointer_traits<_Iterator>::difference_type; + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr static element_type* to_address(pointer __it) noexcept { + return _CUDA_VSTD::__to_address(__it.__current_); + } +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_BOUNDED_ITER_H diff --git a/cuda_toolkit/include/__iterator/concepts.h b/cuda_toolkit/include/__iterator/concepts.h new file mode 100644 index 0000000000000000000000000000000000000000..70b361e81404be344ff5feae1532b84a7ae70989 --- /dev/null +++ b/cuda_toolkit/include/__iterator/concepts.h @@ -0,0 +1,721 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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 +_LIBCUDACXX_INLINE_VAR 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 +_LIBCUDACXX_INLINE_VAR constexpr bool __has_iter_category = false; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __has_iter_category<_Ip, void_t> = true; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __has_iter_concept = false; + +template +_LIBCUDACXX_INLINE_VAR 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/cuda_toolkit/include/__iterator/data.h b/cuda_toolkit/include/__iterator/data.h new file mode 100644 index 0000000000000000000000000000000000000000..255922a3fddf532faa47e3bc27291269fba6a6fa --- /dev/null +++ b/cuda_toolkit/include/__iterator/data.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___ITERATOR_DATA_H +#define _LIBCUDACXX___ITERATOR_DATA_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../cstddef" +#include "../initializer_list" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__iterator/default_sentinel.h b/cuda_toolkit/include/__iterator/default_sentinel.h new file mode 100644 index 0000000000000000000000000000000000000000..e378ce0fb9cca003edb7965df4060eca5e9c6a56 --- /dev/null +++ b/cuda_toolkit/include/__iterator/default_sentinel.h @@ -0,0 +1,37 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__iterator/distance.h b/cuda_toolkit/include/__iterator/distance.h new file mode 100644 index 0000000000000000000000000000000000000000..c6ea9e9843cd829e16c4c74b7b35d2a18ca65cfd --- /dev/null +++ b/cuda_toolkit/include/__iterator/distance.h @@ -0,0 +1,60 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__iterator/empty.h b/cuda_toolkit/include/__iterator/empty.h new file mode 100644 index 0000000000000000000000000000000000000000..cb9602bf51bf438e87cb403652881c50cf14c630 --- /dev/null +++ b/cuda_toolkit/include/__iterator/empty.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___ITERATOR_EMPTY_H +#define _LIBCUDACXX___ITERATOR_EMPTY_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../cstddef" +#include "../initializer_list" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__iterator/erase_if_container.h b/cuda_toolkit/include/__iterator/erase_if_container.h new file mode 100644 index 0000000000000000000000000000000000000000..07e3ad8ff969413818c9a4c6222b0554f119de87 --- /dev/null +++ b/cuda_toolkit/include/__iterator/erase_if_container.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_ERASE_IF_CONTAINER_H +#define _LIBCUDACXX___ITERATOR_ERASE_IF_CONTAINER_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__iterator/front_insert_iterator.h b/cuda_toolkit/include/__iterator/front_insert_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..aef0098a4e51413fd980d2c9f90f98cb9d46f7bc --- /dev/null +++ b/cuda_toolkit/include/__iterator/front_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_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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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;} + _LIBCUDACXX_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_) + {container->push_front(_CUDA_VSTD::move(__value_)); return *this;} + _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/cuda_toolkit/include/__iterator/incrementable_traits.h b/cuda_toolkit/include/__iterator/incrementable_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..02fe7652133ddba11071d266198b1a7db46447ee --- /dev/null +++ b/cuda_toolkit/include/__iterator/incrementable_traits.h @@ -0,0 +1,142 @@ +// -*- 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 "../__concepts/same_as.h" +#include "../__type_traits/conditional.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_const.h" +#include "../__type_traits/is_object.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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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 +_LIBCUDACXX_INLINE_VAR constexpr bool __has_member_difference_type = false; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __has_member_difference_type<_Tp, void_t> = true; + +template +_LIBCUDACXX_INLINE_VAR 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 +_LIBCUDACXX_INLINE_VAR 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/cuda_toolkit/include/__iterator/indirectly_comparable.h b/cuda_toolkit/include/__iterator/indirectly_comparable.h new file mode 100644 index 0000000000000000000000000000000000000000..9dc038aa7aa3c742a8fba15d4155fd596eafc284 --- /dev/null +++ b/cuda_toolkit/include/__iterator/indirectly_comparable.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___ITERATOR_INDIRECTLY_COMPARABLE_H +#define _LIBCUDACXX___ITERATOR_INDIRECTLY_COMPARABLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/identity.h" +#include "../__iterator/concepts.h" +#include "../__iterator/projected.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +template +concept indirectly_comparable = + indirect_binary_predicate<_BinaryPred, projected<_Iter1, _Proj1>, + projected<_Iter2, _Proj2>>; + +#elif _LIBCUDACXX_STD_VER > 14 + +// clang-format off + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirectly_comparable_, + requires()( + requires(indirect_binary_predicate<_BinaryPred, projected<_Iter1, _Proj1>, projected<_Iter2, _Proj2>>) + )); + +template +_LIBCUDACXX_CONCEPT indirectly_comparable = + _LIBCUDACXX_FRAGMENT(__indirectly_comparable_, _Iter1, _Iter2, _BinaryPred, _Proj1, _Proj2); + +// clang-format on + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_INDIRECTLY_COMPARABLE_H diff --git a/cuda_toolkit/include/__iterator/insert_iterator.h b/cuda_toolkit/include/__iterator/insert_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..50ccebf31a9ac806bd616b0c90882f06f5f4dfaf --- /dev/null +++ b/cuda_toolkit/include/__iterator/insert_iterator.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___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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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;} + _LIBCUDACXX_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_) + {iter = container->insert(iter, _CUDA_VSTD::move(__value_)); ++iter; return *this;} + _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/cuda_toolkit/include/__iterator/istream_iterator.h b/cuda_toolkit/include/__iterator/istream_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..b7646fc17ef558b30658e82d6766b3d54a9768a2 --- /dev/null +++ b/cuda_toolkit/include/__iterator/istream_iterator.h @@ -0,0 +1,102 @@ +// -*- 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_traits.h" +#include "../__iterator/iterator.h" +#include "../__memory/addressof.h" +#include "../cstddef" +#include "../iosfwd" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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 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/cuda_toolkit/include/__iterator/istreambuf_iterator.h b/cuda_toolkit/include/__iterator/istreambuf_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..9dbbc64e18f859924a7202c89f5e945e85f36808 --- /dev/null +++ b/cuda_toolkit/include/__iterator/istreambuf_iterator.h @@ -0,0 +1,108 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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 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/cuda_toolkit/include/__iterator/iter_move.h b/cuda_toolkit/include/__iterator/iter_move.h new file mode 100644 index 0000000000000000000000000000000000000000..6f23c8304ef768895d290e692d84413f993350b0 --- /dev/null +++ b/cuda_toolkit/include/__iterator/iter_move.h @@ -0,0 +1,181 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#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) + _LIBCUDACXX_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) + _LIBCUDACXX_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) + _LIBCUDACXX_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/cuda_toolkit/include/__iterator/iter_swap.h b/cuda_toolkit/include/__iterator/iter_swap.h new file mode 100644 index 0000000000000000000000000000000000000000..624a034f6c3f88b0088d4c6c3fcd5e864ac128c3 --- /dev/null +++ b/cuda_toolkit/include/__iterator/iter_swap.h @@ -0,0 +1,180 @@ +// -*- 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_SWAP_H +#define _LIBCUDACXX___ITERATOR_ITER_SWAP_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__concepts/class_or_enum.h" +#include "../__concepts/swappable.h" +#include "../__iterator/concepts.h" +#include "../__iterator/iter_move.h" +#include "../__iterator/iterator_traits.h" +#include "../__iterator/readable_traits.h" +#include "../__type_traits/remove_cvref.h" +#include "../__utility/forward.h" +#include "../__utility/move.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#if _LIBCUDACXX_STD_VER > 14 + +// [iter.cust.swap] + +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES +_LIBCUDACXX_BEGIN_NAMESPACE_CPO(__iter_swap) + template + void iter_swap(_I1, _I2) = delete; + +#if _LIBCUDACXX_STD_VER > 17 + template + concept __unqualified_iter_swap = + (__class_or_enum> || __class_or_enum>) && + requires (_T1&& __x, _T2&& __y) { + iter_swap(_CUDA_VSTD::forward<_T1>(__x), _CUDA_VSTD::forward<_T2>(__y)); + }; + + template + concept __readable_swappable = !__unqualified_iter_swap<_T1, _T2> + && indirectly_readable<_T1> + && indirectly_readable<_T2> + && swappable_with, iter_reference_t<_T2>>; + + template + concept __moveable_storable = !__unqualified_iter_swap<_T1, _T2> + && !__readable_swappable<_T1, _T2> + && indirectly_movable_storable<_T1, _T2> + && indirectly_movable_storable<_T2, _T1>; +#else + template + _LIBCUDACXX_CONCEPT_FRAGMENT( + __unqualified_iter_swap_, + requires(_T1&& __x, _T2&& __y)( + requires(__class_or_enum> || __class_or_enum>), + ((void) iter_swap(_CUDA_VSTD::forward<_T1>(__x), _CUDA_VSTD::forward<_T2>(__y))) + )); + + template + _LIBCUDACXX_CONCEPT __unqualified_iter_swap = _LIBCUDACXX_FRAGMENT(__unqualified_iter_swap_, _T1, _T2); + + template + _LIBCUDACXX_CONCEPT_FRAGMENT( + __readable_swappable_, + requires()( + requires(!__unqualified_iter_swap<_T1, _T2>), + requires(indirectly_readable<_T1>), + requires(indirectly_readable<_T2>), + requires(swappable_with, iter_reference_t<_T2>>) + )); + + template + _LIBCUDACXX_CONCEPT __readable_swappable = _LIBCUDACXX_FRAGMENT(__readable_swappable_, _T1, _T2); + + template + _LIBCUDACXX_CONCEPT_FRAGMENT( + __moveable_storable_, + requires()( + requires(!__unqualified_iter_swap<_T1, _T2>), + requires(!__readable_swappable<_T1, _T2>), + requires(indirectly_movable_storable<_T1, _T2>), + requires(indirectly_movable_storable<_T2, _T1>) + )); + + template + _LIBCUDACXX_CONCEPT __moveable_storable = _LIBCUDACXX_FRAGMENT(__moveable_storable_, _T1, _T2); +#endif // _LIBCUDACXX_STD_VER > 11 + + struct __fn { + _LIBCUDACXX_TEMPLATE(class _T1, class _T2) + _LIBCUDACXX_REQUIRES( __unqualified_iter_swap<_T1, _T2>) + _LIBCUDACXX_INLINE_VISIBILITY + constexpr void operator()(_T1&& __x, _T2&& __y) const + noexcept(noexcept(iter_swap(_CUDA_VSTD::forward<_T1>(__x), _CUDA_VSTD::forward<_T2>(__y)))) + { + (void)iter_swap(_CUDA_VSTD::forward<_T1>(__x), _CUDA_VSTD::forward<_T2>(__y)); + } + + _LIBCUDACXX_TEMPLATE(class _T1, class _T2) + _LIBCUDACXX_REQUIRES( __readable_swappable<_T1, _T2>) + _LIBCUDACXX_INLINE_VISIBILITY + constexpr void operator()(_T1&& __x, _T2&& __y) const + noexcept(noexcept(_CUDA_VRANGES::swap(*_CUDA_VSTD::forward<_T1>(__x), *_CUDA_VSTD::forward<_T2>(__y)))) + { + _CUDA_VRANGES::swap(*_CUDA_VSTD::forward<_T1>(__x), *_CUDA_VSTD::forward<_T2>(__y)); + } + + _LIBCUDACXX_TEMPLATE(class _T1, class _T2) + _LIBCUDACXX_REQUIRES( __moveable_storable<_T2, _T1>) + _LIBCUDACXX_INLINE_VISIBILITY + constexpr void operator()(_T1&& __x, _T2&& __y) const + noexcept(noexcept(iter_value_t<_T2>(_CUDA_VRANGES::iter_move(__y))) && + noexcept(*__y = _CUDA_VRANGES::iter_move(__x)) && + noexcept(*_CUDA_VSTD::forward<_T1>(__x) = declval>())) + { + iter_value_t<_T2> __old(_CUDA_VRANGES::iter_move(__y)); + *__y = _CUDA_VRANGES::iter_move(__x); + *_CUDA_VSTD::forward<_T1>(__x) = _CUDA_VSTD::move(__old); + } + }; +_LIBCUDACXX_END_NAMESPACE_CPO + +inline namespace __cpo { + _LIBCUDACXX_CPO_ACCESSIBILITY auto iter_swap = __iter_swap::__fn{}; +} // namespace __cpo +_LIBCUDACXX_END_NAMESPACE_RANGES + +_LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 17 +template +concept indirectly_swappable = + indirectly_readable<_I1> && indirectly_readable<_I2> && + requires(const _I1 __i1, const _I2 __i2) { + _CUDA_VRANGES::iter_swap(__i1, __i1); + _CUDA_VRANGES::iter_swap(__i2, __i2); + _CUDA_VRANGES::iter_swap(__i1, __i2); + _CUDA_VRANGES::iter_swap(__i2, __i1); + }; +#else +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __indirectly_swappable_, + requires(const _I1 __i1, const _I2 __i2)( + requires(indirectly_readable<_I1>), + requires(indirectly_readable<_I2>), + (_CUDA_VRANGES::iter_swap(__i1, __i1)), + (_CUDA_VRANGES::iter_swap(__i2, __i2)), + (_CUDA_VRANGES::iter_swap(__i1, __i2)), + (_CUDA_VRANGES::iter_swap(__i2, __i1)) + )); + +template +_LIBCUDACXX_CONCEPT indirectly_swappable = _LIBCUDACXX_FRAGMENT(__indirectly_swappable_, _I1, _I2); +#endif // _LIBCUDACXX_STD_VER > 17 + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __noexcept_swappable = false; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __noexcept_swappable<_I1, _I2, __enable_if_t>> + = noexcept(_CUDA_VRANGES::iter_swap(_CUDA_VSTD::declval<_I1&>(), _CUDA_VSTD::declval<_I2&>())); + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_STD_VER > 14 + +#endif // _LIBCUDACXX___ITERATOR_ITER_SWAP_H diff --git a/cuda_toolkit/include/__iterator/iterator.h b/cuda_toolkit/include/__iterator/iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..1f00b0aed7815e485963925e0282d88f064d3abe --- /dev/null +++ b/cuda_toolkit/include/__iterator/iterator.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_ITERATOR_H +#define _LIBCUDACXX___ITERATOR_ITERATOR_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../cstddef" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__iterator/iterator_traits.h b/cuda_toolkit/include/__iterator/iterator_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..8471b8a47200cb3108a1abbcd6cbdc5259cbd3da --- /dev/null +++ b/cuda_toolkit/include/__iterator/iterator_traits.h @@ -0,0 +1,852 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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 +_LIBCUDACXX_INLINE_VAR constexpr bool __has_member_reference = false; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __has_member_reference<_Tp, void_t> = true; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __has_member_pointer = false; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __has_member_pointer<_Tp, void_t> = true; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __has_member_iterator_category = false; + +template +_LIBCUDACXX_INLINE_VAR 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/cuda_toolkit/include/__iterator/mergeable.h b/cuda_toolkit/include/__iterator/mergeable.h new file mode 100644 index 0000000000000000000000000000000000000000..c7a97485e29af6baf8945d78cecfef75d2410639 --- /dev/null +++ b/cuda_toolkit/include/__iterator/mergeable.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_MERGEABLE_H +#define _LIBCUDACXX___ITERATOR_MERGEABLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/identity.h" +#include "../__functional/ranges_operations.h" +#include "../__iterator/concepts.h" +#include "../__iterator/projected.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +template +concept mergeable = + input_iterator<_Input1> && + input_iterator<_Input2> && + weakly_incrementable<_Output> && + indirectly_copyable<_Input1, _Output> && + indirectly_copyable<_Input2, _Output> && + indirect_strict_weak_order<_Comp, projected<_Input1, _Proj1>, projected<_Input2, _Proj2>>; + +#elif _LIBCUDACXX_STD_VER > 14 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __mergeable_, + requires()( + requires(input_iterator<_Input1>), + requires(input_iterator<_Input2>), + requires(weakly_incrementable<_Output>), + requires(indirectly_copyable<_Input1, _Output>), + requires(indirectly_copyable<_Input2, _Output>), + requires(indirect_strict_weak_order<_Comp, projected<_Input1, _Proj1>, projected<_Input2, _Proj2>>) + )); + +template +_LIBCUDACXX_CONCEPT mergeable = + _LIBCUDACXX_FRAGMENT(__mergeable_, _Input1, _Input2, _Output, _Comp, _Proj1, _Proj2); + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_MERGEABLE_H diff --git a/cuda_toolkit/include/__iterator/move_iterator.h b/cuda_toolkit/include/__iterator/move_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..48f2bbada335fb72ee627aa39c493c57e53050c6 --- /dev/null +++ b/cuda_toolkit/include/__iterator/move_iterator.h @@ -0,0 +1,161 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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; + typedef typename iterator_traits::reference __reference; + typedef __conditional_t< + is_reference<__reference>::value, + __libcpp_remove_reference_t<__reference>&&, + __reference + > reference; + + _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(); +} + +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(); +} + +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/cuda_toolkit/include/__iterator/move_sentinel.h b/cuda_toolkit/include/__iterator/move_sentinel.h new file mode 100644 index 0000000000000000000000000000000000000000..5ad1922b731a53679f7b50aedc54c3de2208a83b --- /dev/null +++ b/cuda_toolkit/include/__iterator/move_sentinel.h @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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_MOVE_SENTINEL_H +#define _LIBCUDACXX___ITERATOR_MOVE_SENTINEL_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__concepts/assignable.h" +#include "../__concepts/convertible_to.h" +#include "../__concepts/semiregular.h" +#include "../__utility/move.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#if _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 +template +#else +template, int> = 0> +#endif +class _LIBCUDACXX_TEMPLATE_VIS move_sentinel +{ +public: + _LIBCUDACXX_HIDE_FROM_ABI + constexpr move_sentinel() = default; + + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + explicit move_sentinel(_Sent __s) : __last_(_CUDA_VSTD::move(__s)) {} + + _LIBCUDACXX_TEMPLATE(class _S2) + _LIBCUDACXX_REQUIRES( convertible_to) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + move_sentinel(const move_sentinel<_S2>& __s) : __last_(__s.base()) {} + + _LIBCUDACXX_TEMPLATE(class _S2) + _LIBCUDACXX_REQUIRES( assignable_from) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr + move_sentinel& operator=(const move_sentinel<_S2>& __s) + { __last_ = __s.base(); return *this; } + + _LIBCUDACXX_INLINE_VISIBILITY constexpr _Sent base() const { return __last_; } + +private: + _Sent __last_ = _Sent(); +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_STD_VER > 14 + +#endif // _LIBCUDACXX___ITERATOR_MOVE_SENTINEL_H diff --git a/cuda_toolkit/include/__iterator/next.h b/cuda_toolkit/include/__iterator/next.h new file mode 100644 index 0000000000000000000000000000000000000000..4dc2b6643d70be4b8356b82d0810ddef0fc264b0 --- /dev/null +++ b/cuda_toolkit/include/__iterator/next.h @@ -0,0 +1,94 @@ +// -*- 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/concepts.h" +#include "../__iterator/incrementable_traits.h" +#include "../__iterator/iterator_traits.h" +#include "../__type_traits/enable_if.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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) with negative n on a non-bidirectional iterator"); + + _CUDA_VSTD::advance(__x, __n); + return __x; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_COMPILER_MSVC_2017) + +// [range.iter.op.next] + +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES +_LIBCUDACXX_BEGIN_NAMESPACE_CPO(__next) +struct __fn { + _LIBCUDACXX_TEMPLATE(class _Ip) + _LIBCUDACXX_REQUIRES(input_or_output_iterator<_Ip>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr _Ip operator()(_Ip __x) const { + ++__x; + return __x; + } + + _LIBCUDACXX_TEMPLATE(class _Ip) + _LIBCUDACXX_REQUIRES(input_or_output_iterator<_Ip>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const { + _CUDA_VRANGES::advance(__x, __n); + return __x; + } + + _LIBCUDACXX_TEMPLATE(class _Ip, class _Sp) + _LIBCUDACXX_REQUIRES(input_or_output_iterator<_Ip> && sentinel_for<_Sp, _Ip>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const { + _CUDA_VRANGES::advance(__x, __bound_sentinel); + return __x; + } + + _LIBCUDACXX_TEMPLATE(class _Ip, class _Sp) + _LIBCUDACXX_REQUIRES(input_or_output_iterator<_Ip> && sentinel_for<_Sp, _Ip>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const { + _CUDA_VRANGES::advance(__x, __n, __bound_sentinel); + return __x; + } +}; +_LIBCUDACXX_END_NAMESPACE_CPO + +inline namespace __cpo { + _LIBCUDACXX_CPO_ACCESSIBILITY auto next = __next::__fn{}; +} // namespace __cpo +_LIBCUDACXX_END_NAMESPACE_RANGES + +#endif // _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_COMPILER_MSVC_2017) + +#endif // _LIBCUDACXX___ITERATOR_NEXT_H diff --git a/cuda_toolkit/include/__iterator/ostream_iterator.h b/cuda_toolkit/include/__iterator/ostream_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..a13650fee5a9058fbaa4aabacef62ce6ff5bb918 --- /dev/null +++ b/cuda_toolkit/include/__iterator/ostream_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_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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__iterator/ostreambuf_iterator.h b/cuda_toolkit/include/__iterator/ostreambuf_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..48bc890d84344dae2ae23556423f1fec5b23f436 --- /dev/null +++ b/cuda_toolkit/include/__iterator/ostreambuf_iterator.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___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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__iterator/permutable.h b/cuda_toolkit/include/__iterator/permutable.h new file mode 100644 index 0000000000000000000000000000000000000000..d3afdafab2f62af5f530cab5712415e153016a2b --- /dev/null +++ b/cuda_toolkit/include/__iterator/permutable.h @@ -0,0 +1,57 @@ +// -*- 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_PERMUTABLE_H +#define _LIBCUDACXX___ITERATOR_PERMUTABLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/concepts.h" +#include "../__iterator/iter_swap.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +template +concept permutable = + forward_iterator<_Iterator> && + indirectly_movable_storable<_Iterator, _Iterator> && + indirectly_swappable<_Iterator, _Iterator>; + +#elif _LIBCUDACXX_STD_VER > 14 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __permutable_, + requires()( + requires(forward_iterator<_Iterator>), + requires(indirectly_movable_storable<_Iterator, _Iterator>), + requires(indirectly_swappable<_Iterator, _Iterator>) + )); + +template +_LIBCUDACXX_CONCEPT permutable = _LIBCUDACXX_FRAGMENT(__permutable_, _Iterator); + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_PERMUTABLE_H diff --git a/cuda_toolkit/include/__iterator/prev.h b/cuda_toolkit/include/__iterator/prev.h new file mode 100644 index 0000000000000000000000000000000000000000..0c3798bcd8495b62579437b5fc0c20226a44d624 --- /dev/null +++ b/cuda_toolkit/include/__iterator/prev.h @@ -0,0 +1,51 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__iterator/projected.h b/cuda_toolkit/include/__iterator/projected.h new file mode 100644 index 0000000000000000000000000000000000000000..867604548180cdc1b153da1770d94fcd10ff1d35 --- /dev/null +++ b/cuda_toolkit/include/__iterator/projected.h @@ -0,0 +1,57 @@ +// -*- 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_PROJECTED_H +#define _LIBCUDACXX___ITERATOR_PROJECTED_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/concepts.h" +#include "../__iterator/incrementable_traits.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/remove_cvref.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_TEMPLATE(class _It, class _Proj) + _LIBCUDACXX_REQUIRES( indirectly_readable<_It> _LIBCUDACXX_AND indirectly_regular_unary_invocable<_Proj, _It>) +struct projected { + using value_type = remove_cvref_t>; + _LIBCUDACXX_INLINE_VISIBILITY indirect_result_t<_Proj&, _It> operator*() const; // not defined +}; + +#if _LIBCUDACXX_STD_VER > 17 +template +struct incrementable_traits> { + using difference_type = iter_difference_t<_It>; +}; +#else +template +struct incrementable_traits, enable_if_t>> { + using difference_type = iter_difference_t<_It>; +}; +#endif // _LIBCUDACXX_STD_VER > 17 + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_PROJECTED_H diff --git a/cuda_toolkit/include/__iterator/readable_traits.h b/cuda_toolkit/include/__iterator/readable_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..c80f927473395b3c961d2d1ccdb41c644dd88bf9 --- /dev/null +++ b/cuda_toolkit/include/__iterator/readable_traits.h @@ -0,0 +1,165 @@ +// -*- 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 "../__concepts/same_as.h" +#include "../__iterator/incrementable_traits.h" +#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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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 +_LIBCUDACXX_INLINE_VAR constexpr bool __has_member_value_type = false; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __has_member_value_type<_Tp, void_t> = true; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __has_member_element_type = false; + +template +_LIBCUDACXX_INLINE_VAR 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/cuda_toolkit/include/__iterator/reverse_access.h b/cuda_toolkit/include/__iterator/reverse_access.h new file mode 100644 index 0000000000000000000000000000000000000000..b326ec7a14e6b3f60b12f37357c6eeb76831a210 --- /dev/null +++ b/cuda_toolkit/include/__iterator/reverse_access.h @@ -0,0 +1,108 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__iterator/reverse_iterator.h b/cuda_toolkit/include/__iterator/reverse_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..379dc97efd67ce4b29cff40a5ecb4aee5385a613 --- /dev/null +++ b/cuda_toolkit/include/__iterator/reverse_iterator.h @@ -0,0 +1,180 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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(); +} + +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(); +} + +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/cuda_toolkit/include/__iterator/size.h b/cuda_toolkit/include/__iterator/size.h new file mode 100644 index 0000000000000000000000000000000000000000..7207e552a23a83e78db32169ceaf2499677b3c19 --- /dev/null +++ b/cuda_toolkit/include/__iterator/size.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_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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__iterator/sortable.h b/cuda_toolkit/include/__iterator/sortable.h new file mode 100644 index 0000000000000000000000000000000000000000..6ddeddc5ed4ec3cc1ff28f3f44df0c0119411b6a --- /dev/null +++ b/cuda_toolkit/include/__iterator/sortable.h @@ -0,0 +1,58 @@ +// -*- 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_SORTABLE_H +#define _LIBCUDACXX___ITERATOR_SORTABLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/identity.h" +#include "../__functional/ranges_operations.h" +#include "../__iterator/concepts.h" +#include "../__iterator/permutable.h" +#include "../__iterator/projected.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 17 + +template +concept sortable = + permutable<_Iter> && + indirect_strict_weak_order<_Comp, projected<_Iter, _Proj>>; + +#elif _LIBCUDACXX_STD_VER > 14 + +template +_LIBCUDACXX_CONCEPT_FRAGMENT( + __sortable_, + requires()( // + requires(permutable<_Iter>), + requires(indirect_strict_weak_order<_Comp, projected<_Iter, _Proj>>) + )); + +template +_LIBCUDACXX_CONCEPT sortable = _LIBCUDACXX_FRAGMENT(__sortable_, _Iter, _Comp, _Proj); + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ITERATOR_SORTABLE_H diff --git a/cuda_toolkit/include/__iterator/unreachable_sentinel.h b/cuda_toolkit/include/__iterator/unreachable_sentinel.h new file mode 100644 index 0000000000000000000000000000000000000000..455651699121f79a0a8407fecc5c38372128b3a9 --- /dev/null +++ b/cuda_toolkit/include/__iterator/unreachable_sentinel.h @@ -0,0 +1,91 @@ +// -*- 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 Microsoft Corporation. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ITERATOR_UNREACHABLE_SENTINEL_H +#define _LIBCUDACXX___ITERATOR_UNREACHABLE_SENTINEL_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__iterator/concepts.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#if _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_BEGIN_NAMESPACE_STD +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES_ABI + +// MSVC requires an interesting workaround for a /permissive- bug +// We cannot simply define unreachable_sentinel_t with it friendfunctions, +// but we must derive from a base class in a different namespace so that they +// are only ever found through ADL + +struct unreachable_sentinel_t +#ifdef _LIBCUDACXX_COMPILER_MSVC + ; +namespace __unreachable_sentinel_detail { +struct __unreachable_base +#endif // _LIBCUDACXX_COMPILER_MSVC +{ + _LIBCUDACXX_TEMPLATE(class _Iter) + _LIBCUDACXX_REQUIRES(weakly_incrementable<_Iter>) + _LIBCUDACXX_HIDE_FROM_ABI + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_NODISCARD_FRIEND constexpr bool + operator==(const unreachable_sentinel_t &, const _Iter &) noexcept { + return false; + } +#if _LIBCUDACXX_STD_VER < 20 + _LIBCUDACXX_TEMPLATE(class _Iter) + _LIBCUDACXX_REQUIRES(weakly_incrementable<_Iter>) + _LIBCUDACXX_HIDE_FROM_ABI + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_NODISCARD_FRIEND constexpr bool + operator==(const _Iter &, const unreachable_sentinel_t &) noexcept { + return false; + } + _LIBCUDACXX_TEMPLATE(class _Iter) + _LIBCUDACXX_REQUIRES(weakly_incrementable<_Iter>) + _LIBCUDACXX_HIDE_FROM_ABI + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_NODISCARD_FRIEND constexpr bool + operator!=(const unreachable_sentinel_t &, const _Iter &) noexcept { + return true; + } + _LIBCUDACXX_TEMPLATE(class _Iter) + _LIBCUDACXX_REQUIRES(weakly_incrementable<_Iter>) + _LIBCUDACXX_HIDE_FROM_ABI + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_NODISCARD_FRIEND constexpr bool + operator!=(const _Iter &, const unreachable_sentinel_t &) noexcept { + return true; + } +#endif // _LIBCUDACXX_STD_VER < 20 +}; + +#ifdef _LIBCUDACXX_COMPILER_MSVC +} // namespace __unreachable_sentinel_detail +struct unreachable_sentinel_t + : __unreachable_sentinel_detail::__unreachable_base {}; +#endif // _LIBCUDACXX_COMPILER_MSVC + +_LIBCUDACXX_END_NAMESPACE_RANGES_ABI + +_LIBCUDACXX_CPO_ACCESSIBILITY unreachable_sentinel_t unreachable_sentinel{}; +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_STD_VER > 14 + +#endif // _LIBCUDACXX___ITERATOR_UNREACHABLE_SENTINEL_H diff --git a/cuda_toolkit/include/__iterator/wrap_iter.h b/cuda_toolkit/include/__iterator/wrap_iter.h new file mode 100644 index 0000000000000000000000000000000000000000..7da69520feca7a06d59856091afd0539a14f366b --- /dev/null +++ b/cuda_toolkit/include/__iterator/wrap_iter.h @@ -0,0 +1,421 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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; + +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()); + +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; + + 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()); + + 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); +} + +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(); +} + +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/cuda_toolkit/include/__mdspan/compressed_pair.h b/cuda_toolkit/include/__mdspan/compressed_pair.h new file mode 100644 index 0000000000000000000000000000000000000000..f122a439efafa8967afae23b6761c50c8bb3f3b0 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/compressed_pair.h @@ -0,0 +1,244 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__mdspan/config.h b/cuda_toolkit/include/__mdspan/config.h new file mode 100644 index 0000000000000000000000000000000000000000..dc2de57dbd8b071e1507ff08e05ae79540f624cc --- /dev/null +++ b/cuda_toolkit/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/cuda_toolkit/include/__mdspan/default_accessor.h b/cuda_toolkit/include/__mdspan/default_accessor.h new file mode 100644 index 0000000000000000000000000000000000000000..e20e176f96333730331339d1595f460a456e9536 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/default_accessor.h @@ -0,0 +1,103 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__mdspan/dynamic_extent.h b/cuda_toolkit/include/__mdspan/dynamic_extent.h new file mode 100644 index 0000000000000000000000000000000000000000..bcfb9b24273d7b8a73c54a4121ed4ac8bac7124d --- /dev/null +++ b/cuda_toolkit/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 + +#ifdef _LIBCUDACXX_IMPLICIT_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/cuda_toolkit/include/__mdspan/extents.h b/cuda_toolkit/include/__mdspan/extents.h new file mode 100644 index 0000000000000000000000000000000000000000..606535b508a09c3bd3809f779741e7cffd6a8fb7 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/extents.h @@ -0,0 +1,583 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#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 +_LIBCUDACXX_HOST_DEVICE 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/cuda_toolkit/include/__mdspan/full_extent_t.h b/cuda_toolkit/include/__mdspan/full_extent_t.h new file mode 100644 index 0000000000000000000000000000000000000000..3b7ef55d1c1820a95e7bb8b3b14df858f63ee888 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/full_extent_t.h @@ -0,0 +1,73 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__mdspan/layout_left.h b/cuda_toolkit/include/__mdspan/layout_left.h new file mode 100644 index 0000000000000000000000000000000000000000..0d40e662a72f08141f7e27caa6b66c0f3e7ffe63 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/layout_left.h @@ -0,0 +1,275 @@ +/* +//@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/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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__mdspan/layout_right.h b/cuda_toolkit/include/__mdspan/layout_right.h new file mode 100644 index 0000000000000000000000000000000000000000..fdcd42408dec7d5700380a152d8b2c25b4a7f0e7 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/layout_right.h @@ -0,0 +1,274 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__mdspan/layout_stride.h b/cuda_toolkit/include/__mdspan/layout_stride.h new file mode 100644 index 0000000000000000000000000000000000000000..6ccc53851fe31c07592b7b238f6bbf2df3c90a96 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/layout_stride.h @@ -0,0 +1,559 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__mdspan/macros.h b/cuda_toolkit/include/__mdspan/macros.h new file mode 100644 index 0000000000000000000000000000000000000000..0821035963126725746d93f4aae8f552966e8794 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/macros.h @@ -0,0 +1,643 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#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/cuda_toolkit/include/__mdspan/maybe_static_value.h b/cuda_toolkit/include/__mdspan/maybe_static_value.h new file mode 100644 index 0000000000000000000000000000000000000000..0f3c858d6f6a97eb6932db73527e18ccf5e746c4 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/maybe_static_value.h @@ -0,0 +1,171 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// 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/cuda_toolkit/include/__mdspan/mdspan.h b/cuda_toolkit/include/__mdspan/mdspan.h new file mode 100644 index 0000000000000000000000000000000000000000..52bc8ebe482ed42efa6364de48bab32124e4a82a --- /dev/null +++ b/cuda_toolkit/include/__mdspan/mdspan.h @@ -0,0 +1,470 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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) +) +_LIBCUDACXX_HOST_DEVICE explicit mdspan(_ElementType*, _SizeTypes...) + -> mdspan<_ElementType, dextents>; + +__MDSPAN_TEMPLATE_REQUIRES( + class _Pointer, + (_LIBCUDACXX_TRAIT(is_pointer, _CUDA_VSTD::remove_reference_t<_Pointer>)) +) +_LIBCUDACXX_HOST_DEVICE 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)) +) +_LIBCUDACXX_HOST_DEVICE mdspan(_CArray&) -> mdspan<_CUDA_VSTD::remove_all_extents_t<_CArray>, extents>>; + +template +_LIBCUDACXX_HOST_DEVICE mdspan(_ElementType*, const _CUDA_VSTD::array<_SizeType, _Np>&) + -> mdspan<_ElementType, dextents>; + +template +_LIBCUDACXX_HOST_DEVICE 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 +_LIBCUDACXX_HOST_DEVICE mdspan(_ElementType*, const extents<_SizeType, _ExtentsPack...>&) + -> mdspan<_ElementType, extents<_SizeType, _ExtentsPack...>>; + +template +_LIBCUDACXX_HOST_DEVICE mdspan(_ElementType*, const _MappingType&) + -> mdspan<_ElementType, typename _MappingType::extents_type, typename _MappingType::layout_type>; + +template +_LIBCUDACXX_HOST_DEVICE 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/cuda_toolkit/include/__mdspan/no_unique_address.h b/cuda_toolkit/include/__mdspan/no_unique_address.h new file mode 100644 index 0000000000000000000000000000000000000000..1ce2d40e373de3e8798734f497fad6cef74d0587 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/no_unique_address.h @@ -0,0 +1,149 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__mdspan/standard_layout_static_array.h b/cuda_toolkit/include/__mdspan/standard_layout_static_array.h new file mode 100644 index 0000000000000000000000000000000000000000..b6155432c3fb8cf510cc6a5b38b7ee98ab757d1e --- /dev/null +++ b/cuda_toolkit/include/__mdspan/standard_layout_static_array.h @@ -0,0 +1,703 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__mdspan/static_array.h b/cuda_toolkit/include/__mdspan/static_array.h new file mode 100644 index 0000000000000000000000000000000000000000..ef7479a7f7150207a6330a8b544d5609342ced0a --- /dev/null +++ b/cuda_toolkit/include/__mdspan/static_array.h @@ -0,0 +1,325 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#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/cuda_toolkit/include/__mdspan/submdspan.h b/cuda_toolkit/include/__mdspan/submdspan.h new file mode 100644 index 0000000000000000000000000000000000000000..ef93663e915768bbc4ce70316a76df84d4e71f95 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/submdspan.h @@ -0,0 +1,609 @@ +/* +//@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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__mdspan/type_list.h b/cuda_toolkit/include/__mdspan/type_list.h new file mode 100644 index 0000000000000000000000000000000000000000..66c0e623069b6cf7a9b16ba76e7f66b402edd5b8 --- /dev/null +++ b/cuda_toolkit/include/__mdspan/type_list.h @@ -0,0 +1,137 @@ +/* +//@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" +#include "../__utility/integer_sequence.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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/cuda_toolkit/include/__memory/addressof.h b/cuda_toolkit/include/__memory/addressof.h new file mode 100644 index 0000000000000000000000000000000000000000..b7024fcf868f62b16580b75a04057bdd11c97854 --- /dev/null +++ b/cuda_toolkit/include/__memory/addressof.h @@ -0,0 +1,98 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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 + +template _Tp* addressof(const _Tp&&) noexcept = delete; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MEMORY_ADDRESSOF_H diff --git a/cuda_toolkit/include/__memory/construct_at.h b/cuda_toolkit/include/__memory/construct_at.h new file mode 100644 index 0000000000000000000000000000000000000000..e86b13442b42ed44403075eb561dbc8c7524052b --- /dev/null +++ b/cuda_toolkit/include/__memory/construct_at.h @@ -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___MEMORY_CONSTRUCT_AT_H +#define _LIBCUDACXX___MEMORY_CONSTRUCT_AT_H + +#ifndef __cuda_std__ +# include <__config> +#endif //__cuda_std__ + +#include "../__assert" +#include "../__concepts/__concept_macros.h" +#include "../__iterator/access.h" +#include "../__memory/addressof.h" +#include "../__memory/voidify.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/is_arithmetic.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 "../__type_traits/void_t.h" +#include "../__utility/declval.h" +#include "../__utility/forward.h" +#include "../__utility/move.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#ifdef _LIBCUDACXX_COMPILER_CLANG_CUDA +# include +#endif // _LIBCUDACXX_COMPILER_CLANG_CUDA + +#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 it for certain types +// This is possible because we are calling ::new ignoring any user defined overloads of operator placement new +namespace __detail +{ +// We cannot allow narrowing conversions between arithmetic types as the assignment will give errors +template +struct __is_narrowing_impl : false_type +{}; + +template +struct __is_narrowing_impl<_To, _From> : true_type +{}; + +// This is a bit hacky, but we rely on the fact that arithmetic types cannot have more than one argument to their constructor +template +struct __is_narrowing_impl<_To, _From, __void_t()})>> : false_type +{}; + +template +using __is_narrowing = _If<_LIBCUDACXX_TRAIT(is_arithmetic, _Tp), __is_narrowing_impl<_Tp, _Args...>, false_type>; + +// The destination type must be trivially constructible from the arguments and also trivially assignable, because we +// technically move assign in the optimization +template +struct __can_optimize_construct_at + : integral_constant::value> +{}; +} // namespace __detail + +// 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::value, _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<__detail::__can_optimize_construct_at<_Tp, _Args...>::value, _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::value, _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 + 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<__detail::__can_optimize_construct_at<_Tp, _Args...>::value, _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/cuda_toolkit/include/__memory/pointer_traits.h b/cuda_toolkit/include/__memory/pointer_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..fbea61af92d54b86fed2e5dca48faa1f96653c21 --- /dev/null +++ b/cuda_toolkit/include/__memory/pointer_traits.h @@ -0,0 +1,347 @@ +// -*- 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(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_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