diff --git a/cuda_toolkit/include/cuda/std/array b/cuda_toolkit/include/cuda/std/array new file mode 100644 index 0000000000000000000000000000000000000000..775194ae29295fc4879d4a327517c4cd4556515a --- /dev/null +++ b/cuda_toolkit/include/cuda/std/array @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_ARRAY +#define _CUDA_STD_ARRAY + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/array" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_ARRAY diff --git a/cuda_toolkit/include/cuda/std/atomic b/cuda_toolkit/include/cuda/std/atomic new file mode 100644 index 0000000000000000000000000000000000000000..bf52d11c2350802621030963b34068b10cdf6895 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/atomic @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_ATOMIC +#define _CUDA_STD_ATOMIC + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/atomic" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_ATOMIC diff --git a/cuda_toolkit/include/cuda/std/barrier b/cuda_toolkit/include/cuda/std/barrier new file mode 100644 index 0000000000000000000000000000000000000000..fff3e842afaa523c9e099575947286b46006abe7 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/barrier @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_BARRIER +#define _CUDA_STD_BARRIER + +#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 700 +# error "CUDA synchronization primitives are only supported for sm_70 and up." +#endif + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/barrier" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_BARRIER diff --git a/cuda_toolkit/include/cuda/std/bit b/cuda_toolkit/include/cuda/std/bit new file mode 100644 index 0000000000000000000000000000000000000000..87dfb73d2e19f321f0bb91b62d6d050e7eab4ce2 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/bit @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_BIT +#define _CUDA_STD_BIT + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/bit" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_BIT diff --git a/cuda_toolkit/include/cuda/std/cassert b/cuda_toolkit/include/cuda/std/cassert new file mode 100644 index 0000000000000000000000000000000000000000..e6676b4d0a0fed70cdbdae7e4102c90322229c8a --- /dev/null +++ b/cuda_toolkit/include/cuda/std/cassert @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CASSERT +#define _CUDA_STD_CASSERT + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/cassert" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CASSERT diff --git a/cuda_toolkit/include/cuda/std/ccomplex b/cuda_toolkit/include/cuda/std/ccomplex new file mode 100644 index 0000000000000000000000000000000000000000..bedbc0c643d00e829744c64f8825724dd3ce2197 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/ccomplex @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CCOMPLEX +#define _CUDA_STD_CCOMPLEX + +#include "complex" + +#endif // _CUDA_STD_CCOMPLEX diff --git a/cuda_toolkit/include/cuda/std/cfloat b/cuda_toolkit/include/cuda/std/cfloat new file mode 100644 index 0000000000000000000000000000000000000000..1b9a4f935e4139df6444eca4dfd85057bffe003a --- /dev/null +++ b/cuda_toolkit/include/cuda/std/cfloat @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CFLOAT +#define _CUDA_STD_CFLOAT + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/cfloat" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CFLOAT diff --git a/cuda_toolkit/include/cuda/std/chrono b/cuda_toolkit/include/cuda/std/chrono new file mode 100644 index 0000000000000000000000000000000000000000..a4d45b619c0aa704bee3bf7386f879534435124a --- /dev/null +++ b/cuda_toolkit/include/cuda/std/chrono @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CHRONO +#define _CUDA_STD_CHRONO + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/chrono" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CHRONO diff --git a/cuda_toolkit/include/cuda/std/climits b/cuda_toolkit/include/cuda/std/climits new file mode 100644 index 0000000000000000000000000000000000000000..dd733eb12f601ce4db2746b395527bbfba620f7e --- /dev/null +++ b/cuda_toolkit/include/cuda/std/climits @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CLIMITS +#define _CUDA_STD_CLIMITS + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/climits" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CLIMITS diff --git a/cuda_toolkit/include/cuda/std/cmath b/cuda_toolkit/include/cuda/std/cmath new file mode 100644 index 0000000000000000000000000000000000000000..7944a9506d5546e72a368da6bfc91c93e2bc8d4b --- /dev/null +++ b/cuda_toolkit/include/cuda/std/cmath @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CMATH +#define _CUDA_STD_CMATH + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/cmath" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CMATH diff --git a/cuda_toolkit/include/cuda/std/complex b/cuda_toolkit/include/cuda/std/complex new file mode 100644 index 0000000000000000000000000000000000000000..f0f7d97740fa9ad5fb3e7f536368b5c37edcd25c --- /dev/null +++ b/cuda_toolkit/include/cuda/std/complex @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_COMPLEX +#define _CUDA_STD_COMPLEX + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/complex" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_COMPLEX diff --git a/cuda_toolkit/include/cuda/std/concepts b/cuda_toolkit/include/cuda/std/concepts new file mode 100644 index 0000000000000000000000000000000000000000..536d92809302bbf1e9e4993918065252118ea62c --- /dev/null +++ b/cuda_toolkit/include/cuda/std/concepts @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CONCEPTS +#define _CUDA_STD_CONCEPTS + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/concepts" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CONCEPTS diff --git a/cuda_toolkit/include/cuda/std/cstddef b/cuda_toolkit/include/cuda/std/cstddef new file mode 100644 index 0000000000000000000000000000000000000000..006821979e42efeeacb57657aac3dd94e9672789 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/cstddef @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CSTDDEF +#define _CUDA_STD_CSTDDEF + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/cstddef" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CSTDDEF diff --git a/cuda_toolkit/include/cuda/std/cstdint b/cuda_toolkit/include/cuda/std/cstdint new file mode 100644 index 0000000000000000000000000000000000000000..9ff2cd96ac4600416f2911d74a14313a24dcf2eb --- /dev/null +++ b/cuda_toolkit/include/cuda/std/cstdint @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CSTDINT +#define _CUDA_STD_CSTDINT + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/cstdint" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CSTDINT diff --git a/cuda_toolkit/include/cuda/std/ctime b/cuda_toolkit/include/cuda/std/ctime new file mode 100644 index 0000000000000000000000000000000000000000..eac6f3b272d3b930983ad72619c5acfa524abc2d --- /dev/null +++ b/cuda_toolkit/include/cuda/std/ctime @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_STD_CTIME +#define _CUDA_STD_CTIME + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/ctime" + +#include "detail/__pragma_pop" + +#endif // _CUDA_STD_CTIME diff --git a/cuda_toolkit/include/cuda/std/detail/__access_property b/cuda_toolkit/include/cuda/std/detail/__access_property new file mode 100644 index 0000000000000000000000000000000000000000..9ee3856771b567bf9dff10ac9cda0754179519a8 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/__access_property @@ -0,0 +1,327 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * NVIDIA SOFTWARE LICENSE + * + * This license is a legal agreement between you and NVIDIA Corporation ("NVIDIA") and governs your use of the NVIDIA/CUDA C++ Library software and materials provided hereunder (“SOFTWARE”). + * + * This license can be accepted only by an adult of legal age of majority in the country in which the SOFTWARE is used. If you are under the legal age of majority, you must ask your parent or legal guardian to consent to this license. By taking delivery of the SOFTWARE, you affirm that you have reached the legal age of majority, you accept the terms of this license, and you take legal and financial responsibility for the actions of your permitted users. + * + * You agree to use the SOFTWARE only for purposes that are permitted by (a) this license, and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions. + * + * 1. LICENSE. Subject to the terms of this license, NVIDIA grants you a non-exclusive limited license to: (a) install and use the SOFTWARE, and (b) distribute the SOFTWARE subject to the distribution requirements described in this license. NVIDIA reserves all rights, title and interest in and to the SOFTWARE not expressly granted to you under this license. + * + * 2. DISTRIBUTION REQUIREMENTS. These are the distribution requirements for you to exercise the distribution grant: + * a. The terms under which you distribute the SOFTWARE must be consistent with the terms of this license, including (without limitation) terms relating to the license grant and license restrictions and protection of NVIDIA’s intellectual property rights. + * b. You agree to notify NVIDIA in writing of any known or suspected distribution or use of the SOFTWARE not in compliance with the requirements of this license, and to enforce the terms of your agreements with respect to distributed SOFTWARE. + * + * 3. LIMITATIONS. Your license to use the SOFTWARE is restricted as follows: + * a. The SOFTWARE is licensed for you to develop applications only for use in systems with NVIDIA GPUs. + * b. You may not reverse engineer, decompile or disassemble, or remove copyright or other proprietary notices from any portion of the SOFTWARE or copies of the SOFTWARE. + * c. You may not modify or create derivative works of any portion of the SOFTWARE. + * d. You may not bypass, disable, or circumvent any technical measure, encryption, security, digital rights management or authentication mechanism in the SOFTWARE. + * e. You may not use the SOFTWARE in any manner that would cause it to become subject to an open source software license. As examples, licenses that require as a condition of use, modification, and/or distribution that the SOFTWARE be (i) disclosed or distributed in source code form; (ii) licensed for the purpose of making derivative works; or (iii) redistributable at no charge. + * f. Unless you have an agreement with NVIDIA for this purpose, you may not use the SOFTWARE with any system or application where the use or failure of the system or application can reasonably be expected to threaten or result in personal injury, death, or catastrophic loss. Examples include use in avionics, navigation, military, medical, life support or other life critical applications. NVIDIA does not design, test or manufacture the SOFTWARE for these critical uses and NVIDIA shall not be liable to you or any third party, in whole or in part, for any claims or damages arising from such uses. + * g. You agree to defend, indemnify and hold harmless NVIDIA and its affiliates, and their respective employees, contractors, agents, officers and directors, from and against any and all claims, damages, obligations, losses, liabilities, costs or debt, fines, restitutions and expenses (including but not limited to attorney’s fees and costs incident to establishing the right of indemnification) arising out of or related to use of the SOFTWARE outside of the scope of this Agreement, or not in compliance with its terms. + * + * 4. PRE-RELEASE. SOFTWARE versions identified as alpha, beta, preview, early access or otherwise as pre-release may not be fully functional, may contain errors or design flaws, and may have reduced or different security, privacy, availability, and reliability standards relative to commercial versions of NVIDIA software and materials. You may use a pre-release SOFTWARE version at your own risk, understanding that these versions are not intended for use in production or business-critical systems. + * + * 5. OWNERSHIP. The SOFTWARE and the related intellectual property rights therein are and will remain the sole and exclusive property of NVIDIA or its licensors. The SOFTWARE is copyrighted and protected by the laws of the United States and other countries, and international treaty provisions. NVIDIA may make changes to the SOFTWARE, at any time without notice, but is not obligated to support or update the SOFTWARE. + * + * 6. COMPONENTS UNDER OTHER LICENSES. The SOFTWARE may include NVIDIA or third-party components with separate legal notices or terms as may be described in proprietary notices accompanying the SOFTWARE. If and to the extent there is a conflict between the terms in this license and the license terms associated with a component, the license terms associated with the components control only to the extent necessary to resolve the conflict. + * + * 7. FEEDBACK. You may, but don’t have to, provide to NVIDIA any Feedback. “Feedback” means any suggestions, bug fixes, enhancements, modifications, feature requests or other feedback regarding the SOFTWARE. For any Feedback that you voluntarily provide, you hereby grant NVIDIA and its affiliates a perpetual, non-exclusive, worldwide, irrevocable license to use, reproduce, modify, license, sublicense (through multiple tiers of sublicensees), and distribute (through multiple tiers of distributors) the Feedback without the payment of any royalties or fees to you. NVIDIA will use Feedback at its choice. + * + * 8. NO WARRANTIES. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. NVIDIA DOES NOT WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION THEREOF WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ALL ERRORS WILL BE CORRECTED. + * + * 9. LIMITATIONS OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY LAW, NVIDIA AND ITS AFFILIATES SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR ANY LOST PROFITS, PROJECT DELAYS, LOSS OF USE, LOSS OF DATA OR LOSS OF GOODWILL, OR THE COSTS OF PROCURING SUBSTITUTE PRODUCTS, ARISING OUT OF OR IN CONNECTION WITH THIS LICENSE OR THE USE OR PERFORMANCE OF THE SOFTWARE, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCT LIABILITY OR ANY OTHER CAUSE OF ACTION OR THEORY OF LIABILITY, EVEN IF NVIDIA HAS PREVIOUSLY BEEN ADVISED OF, OR COULD REASONABLY HAVE FORESEEN, THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL NVIDIA’S AND ITS AFFILIATES TOTAL CUMULATIVE LIABILITY UNDER OR ARISING OUT OF THIS LICENSE EXCEED US$10.00. THE NATURE OF THE LIABILITY OR THE NUMBER OF CLAIMS OR SUITS SHALL NOT ENLARGE OR EXTEND THIS LIMIT. + * + * 10. TERMINATION. Your rights under this license will terminate automatically without notice from NVIDIA if you fail to comply with any term and condition of this license or if you commence or participate in any legal proceeding against NVIDIA with respect to the SOFTWARE. NVIDIA may terminate this license with advance written notice to you if NVIDIA decides to no longer provide the SOFTWARE in a country or, in NVIDIA’s sole discretion, the continued use of it is no longer commercially viable. Upon any termination of this license, you agree to promptly discontinue use of the SOFTWARE and destroy all copies in your possession or control. Your prior distributions in accordance with this license are not affected by the termination of this license. All provisions of this license will survive termination, except for the license granted to you. + * + * 11. APPLICABLE LAW. This license will be governed in all respects by the laws of the United States and of the State of Delaware as those laws are applied to contracts entered into and performed entirely within Delaware by Delaware residents, without regard to the conflicts of laws principles. The United Nations Convention on Contracts for the International Sale of Goods is specifically disclaimed. You agree to all terms of this Agreement in the English language. The state or federal courts residing in Santa Clara County, California shall have exclusive jurisdiction over any dispute or claim arising out of this license. Notwithstanding this, you agree that NVIDIA shall still be allowed to apply for injunctive remedies or an equivalent type of urgent legal relief in any jurisdiction. + * + * 12. NO ASSIGNMENT. This license and your rights and obligations thereunder may not be assigned by you by any means or operation of law without NVIDIA’s permission. Any attempted assignment not approved by NVIDIA in writing shall be void and of no effect. + * + * 13. EXPORT. The SOFTWARE is subject to United States export laws and regulations. You agree that you will not ship, transfer or export the SOFTWARE into any country, or use the SOFTWARE in any manner, prohibited by the United States Bureau of Industry and Security or economic sanctions regulations administered by the U.S. Department of Treasury’s Office of Foreign Assets Control (OFAC), or any applicable export laws, restrictions or regulations. These laws include restrictions on destinations, end users and end use. By accepting this license, you confirm that you are not a resident or citizen of any country currently embargoed by the U.S. and that you are not otherwise prohibited from receiving the SOFTWARE. + * + * 14. GOVERNMENT USE. The SOFTWARE has been developed entirely at private expense and is “commercial items” consisting of “commercial computer software” and “commercial computer software documentation” provided with RESTRICTED RIGHTS. Use, duplication or disclosure by the U.S. Government or a U.S. Government subcontractor is subject to the restrictions in this license pursuant to DFARS 227.7202-3(a) or as set forth in subparagraphs (b)(1) and (2) of the Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, as applicable. Contractor/manufacturer is NVIDIA, 2788 San Tomas Expressway, Santa Clara, CA 95051. + * + * 15. ENTIRE AGREEMENT. This license is the final, complete and exclusive agreement between the parties relating to the subject matter of this license and supersedes all prior or contemporaneous understandings and agreements relating to this subject matter, whether oral or written. If any court of competent jurisdiction determines that any provision of this license is illegal, invalid or unenforceable, the remaining provisions will remain in full force and effect. This license may only be modified in a writing signed by an authorized representative of each party. + * + * (v. August 20, 2021) + */ + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +namespace __detail_ap { + + _LIBCUDACXX_HOST_DEVICE + constexpr uint32_t __ap_floor_log2(uint32_t __x) { + return (__x == 1 | __x == 0) ? 0 : 1 + __ap_floor_log2(__x >> 1); + } + + _LIBCUDACXX_HOST_DEVICE + constexpr uint32_t __ap_ceil_log2(uint32_t __x) { + return (__x == 1 | __x == 0) ? 0 : __ap_floor_log2(__x - 1) + 1; + } + + _LIBCUDACXX_HOST_DEVICE + constexpr uint32_t __ap_min(uint32_t __a, uint32_t __b) noexcept { + return (__a < __b) ? __a : __b; + } + + _LIBCUDACXX_HOST_DEVICE + constexpr uint32_t __ap_max(uint32_t __a, uint32_t __b) noexcept { + return (__a > __b) ? __a : __b; + } + +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414 +// Specifically search for 8.4 and 9.3 and above to guarantee uint64_t enum. +#if defined(_LIBCUDACXX_COMPILER_GCC) && ( \ + ((_GNUC_VER < 804)) || \ + ((_GNUC_VER < 903)) \ + ) +# define _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION +#else +# define _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION : uint64_t +#endif + + namespace __sm_80 { + namespace __off { + enum __l2_cop_off_t _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION { + _L2_EVICT_NORMAL = 0, + _L2_EVICT_FIRST = 1, + }; + } // namespace __off + + namespace __on { + enum __l2_cop_on_t _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION { + _L2_EVICT_NORMAL = 0, + _L2_EVICT_FIRST = 1, + _L2_EVICT_LAST = 2, + _L2_EVICT_NORMAL_DEMOTE = 3, + }; + } // namespace __on + + enum __l2_descriptor_mode_t _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION { + _DESC_IMPLICIT = 0, + _DESC_INTERLEAVED = 2, + _DESC_BLOCK_TYPE = 3, + }; + + enum __l2_eviction_max_way_t _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION { + _CUDA_AMPERE_MAX_L2_WAYS = std::uint32_t{16}, + }; + + enum __block_size_t _LIBCUDACXX_AP_ENUM_TYPE_ANNOTATION { + _BLOCKSIZE_4K = 0, + _BLOCKSIZE_8K = 1, + _BLOCKSIZE_16K = 2, + _BLOCKSIZE_32K = 3, + _BLOCKSIZE_64K = 4, + _BLOCKSIZE_128K = 5, + _BLOCKSIZE_256K = 6, + _BLOCKSIZE_512K = 7, + _BLOCKSIZE_1M = 8, + _BLOCKSIZE_2M = 9, + _BLOCKSIZE_4M = 10, + _BLOCKSIZE_8M = 11, + _BLOCKSIZE_16M = 12, + _BLOCKSIZE_32M = 13, + }; + + struct __block_desc_t { + uint64_t __ap_reserved : 37; + uint64_t __block_count: 7; + uint64_t __block_start: 7; + uint64_t __ap_reserved2 : 1; + __block_size_t __block_size : 4; + __off::__l2_cop_off_t __l2_cop_off : 1; + __on::__l2_cop_on_t __l2_cop_on : 2; + __l2_descriptor_mode_t __l2_descriptor_mode : 2; + uint64_t __l1_inv_dont_allocate : 1; + uint64_t __l2_sector_promote_256B : 1; + uint64_t __ap_reserved3 : 1; + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __get_descriptor_cexpr() const noexcept { + return + std::uint64_t(__ap_reserved) << 0 | + std::uint64_t(__block_count) << 37 | + std::uint64_t(__block_start) << 44 | + std::uint64_t(__ap_reserved2) << 51 | + std::uint64_t(__block_size) << 52 | + std::uint64_t(__l2_cop_off) << 56 | + std::uint64_t(__l2_cop_on) << 57 | + std::uint64_t(__l2_descriptor_mode) << 59 | + std::uint64_t(__l1_inv_dont_allocate) << 61 | + std::uint64_t(__l2_sector_promote_256B) << 62 | + std::uint64_t(__ap_reserved3) << 63; + } + + inline + _LIBCUDACXX_HOST_DEVICE + std::uint64_t __get_descriptor_non_cexpr() const noexcept { return *reinterpret_cast(this); } + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __get_descriptor() const noexcept { +#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) + return cuda::std::is_constant_evaluated() ? + __get_descriptor_cexpr() : + __get_descriptor_non_cexpr(); +#else + return __get_descriptor_cexpr(); +#endif + } + }; + static_assert(sizeof(__block_desc_t) == 8, "__block_desc_t should be 8 bytes"); + static_assert(sizeof(__block_desc_t) == sizeof(std::uint64_t), ""); + static_assert( + __block_desc_t{(uint64_t)1, (uint64_t)1, (uint64_t)1, (uint64_t)1, __block_size_t::_BLOCKSIZE_8K, __off::_L2_EVICT_FIRST, __on::_L2_EVICT_FIRST, __l2_descriptor_mode_t::_DESC_INTERLEAVED, (uint64_t)1, (uint64_t)1, (uint64_t)1}.__get_descriptor() + == 0xF318102000000001, ""); + + /* Factory like struct to build a __block_desc_t due to constexpr C++11 + */ + struct __block_descriptor_builder { //variable declaration order matters == usage order + std::uint32_t __offset; + __block_size_t __block_size; + std::uint32_t __block_start, __end_hit; + std::uint32_t __block_count; + __off::__l2_cop_off_t __l2_cop_off; + __on::__l2_cop_on_t __l2_cop_on; + __l2_descriptor_mode_t __l2_descriptor_mode; + bool __l1_inv_dont_allocate, __l2_sector_promote_256B; + + _LIBCUDACXX_HOST_DEVICE static constexpr std::uint32_t __calc_offset(std::size_t __total_bytes) { + return __ap_max(std::uint32_t{12}, static_cast(__ap_ceil_log2(static_cast(__total_bytes))) - std::uint32_t{7}); + } + + _LIBCUDACXX_HOST_DEVICE static constexpr std::uint32_t __calc_block_start(std::uintptr_t __ptr, std::size_t __total_bytes) { + return static_cast(__ptr >> __calc_offset(static_cast(__total_bytes))); + } + + _LIBCUDACXX_HOST_DEVICE static constexpr std::uint32_t __calc_end_hit(std::uintptr_t __ptr, std::size_t __hit_bytes, std::size_t __total_bytes) { + return static_cast((__ptr + __hit_bytes + (std::uintptr_t{1} << (__calc_offset(static_cast(__total_bytes)))) - 1) >> __calc_offset(static_cast(__total_bytes))); + } + + _LIBCUDACXX_HOST_DEVICE constexpr __block_descriptor_builder(std::uintptr_t __ptr, std::size_t __hit_bytes, std::size_t __total_bytes, __on::__l2_cop_on_t __hit_prop, __off::__l2_cop_off_t __miss_prop) + : __offset(__calc_offset(__total_bytes)) + , __block_size(static_cast<__block_size_t>(__calc_offset(__total_bytes) - std::uint32_t{12})) + , __block_start(__calc_block_start(__ptr, __total_bytes)) + , __end_hit(__calc_end_hit(__ptr, __hit_bytes, __total_bytes)) + , __block_count(__calc_end_hit(__ptr, __hit_bytes, __total_bytes) - __calc_block_start(__ptr, __total_bytes)) + , __l2_cop_off(__miss_prop) + , __l2_cop_on(__hit_prop) + , __l2_descriptor_mode(_DESC_BLOCK_TYPE) + , __l1_inv_dont_allocate(false) + , __l2_sector_promote_256B(false) + {} + + _LIBCUDACXX_HOST_DEVICE + constexpr __block_desc_t __get_block() const noexcept { + return __block_desc_t { 0, __ap_min(std::uint32_t{0x7f}, __block_count), (__block_start & std::uint32_t{0x7f}), 0, __block_size, __l2_cop_off, __l2_cop_on, _DESC_BLOCK_TYPE, false, false, 0 }; + } + }; + static_assert(sizeof(std::uintptr_t) > 4, "std::uintptr_t needs at least 5 bytes for this code to work"); + + struct __interleave_descriptor_t { + uint64_t __ap_reserved : 52; + uint64_t __fraction : 4; + __off::__l2_cop_off_t __l2_cop_off : 1; + __on::__l2_cop_on_t __l2_cop_on : 2; + __l2_descriptor_mode_t __l2_descriptor_mode : 2; + uint64_t __l1_inv_dont_allocate : 1; + uint64_t __l2_sector_promote_256B : 1; + uint64_t __ap_reserved2 : 1; + + _LIBCUDACXX_HOST_DEVICE + constexpr __interleave_descriptor_t( + __on::__l2_cop_on_t __hit_prop, + std::uint32_t __hit_ratio, + __off::__l2_cop_off_t __miss_prop) noexcept + : __fraction(__hit_ratio), + __l2_cop_off(__miss_prop), + __l2_cop_on(__hit_prop), + __l2_descriptor_mode(_DESC_INTERLEAVED), + __l1_inv_dont_allocate(0x0), + __l2_sector_promote_256B(0x0), + __ap_reserved(0x0), + __ap_reserved2(0x0) {} + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __get_descriptor_cexpr() const { + return + std::uint64_t(__ap_reserved) << 0 | + std::uint64_t(__fraction) << 52 | + std::uint64_t(__l2_cop_off) << 56 | + std::uint64_t(__l2_cop_on) << 57 | + std::uint64_t(__l2_descriptor_mode) << 59 | + std::uint64_t(__l1_inv_dont_allocate) << 61 | + std::uint64_t(__l2_sector_promote_256B) << 62 | + std::uint64_t(__ap_reserved2) << 63; + } + + inline + _LIBCUDACXX_HOST_DEVICE + std::uint64_t __get_descriptor_non_cexpr() const noexcept { return *reinterpret_cast(this); } + + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __get_descriptor() const noexcept { +#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) + return cuda::std::is_constant_evaluated() ? + __get_descriptor_cexpr() : + __get_descriptor_non_cexpr(); +#else + return __get_descriptor_cexpr(); +#endif + } + }; + static_assert(sizeof(__interleave_descriptor_t) == 8, "__interleave_descriptor_t should be 8 bytes"); + static_assert(sizeof(__interleave_descriptor_t) == sizeof(std::uint64_t), ""); + + _LIBCUDACXX_HOST_DEVICE + static constexpr std::uint64_t __interleave_normal() noexcept { + return 0x10F0000000000000; + } + + _LIBCUDACXX_HOST_DEVICE + static constexpr std::uint64_t __interleave_streaming() noexcept { + return 0x12F0000000000000; + } + + _LIBCUDACXX_HOST_DEVICE + static constexpr std::uint64_t __interleave_persisting() noexcept { + return 0x14F0000000000000; + } + + _LIBCUDACXX_HOST_DEVICE + static constexpr std::uint64_t __interleave_normal_demote() noexcept { + return 0x16F0000000000000; + } + + } // namespace __sm_80 + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __interleave(cudaAccessProperty __hit_prop, float __hit_ratio, cudaAccessProperty __miss_prop = cudaAccessPropertyNormal) { + return __sm_80::__interleave_descriptor_t( + ((__hit_prop == cudaAccessPropertyNormal) ? __sm_80::__on::__l2_cop_on_t::_L2_EVICT_NORMAL_DEMOTE : static_cast<__sm_80::__on::__l2_cop_on_t>(__hit_prop)), + __ap_min((static_cast(__hit_ratio) * __sm_80::__l2_eviction_max_way_t::_CUDA_AMPERE_MAX_L2_WAYS), static_cast(__sm_80::__l2_eviction_max_way_t::_CUDA_AMPERE_MAX_L2_WAYS - 1)), + static_cast<__sm_80::__off::__l2_cop_off_t>(__miss_prop) + ).__get_descriptor(); + } + + _LIBCUDACXX_HOST_DEVICE + constexpr std::uint64_t __block(void* __ptr, std::size_t __hit_bytes, std::size_t __total_bytes, cudaAccessProperty __hit_prop, cudaAccessProperty __miss_prop = cudaAccessPropertyNormal) { + return (__total_bytes <= (size_t{0xFFFFFFFF}) & __total_bytes != 0 & __hit_bytes <= __total_bytes) ? __sm_80::__block_descriptor_builder( + reinterpret_cast(__ptr), + __hit_bytes, + __total_bytes, + (__hit_prop == cudaAccessPropertyNormal) ? __sm_80::__on::_L2_EVICT_NORMAL_DEMOTE : static_cast<__sm_80::__on::__l2_cop_on_t>(__hit_prop), + static_cast<__sm_80::__off::__l2_cop_off_t>(__miss_prop) + ).__get_block().__get_descriptor() + : __sm_80::__interleave_normal(); + } +} // namespace __detail_ap + +_LIBCUDACXX_END_NAMESPACE_CUDA diff --git a/cuda_toolkit/include/cuda/std/detail/__annotated_ptr b/cuda_toolkit/include/cuda/std/detail/__annotated_ptr new file mode 100644 index 0000000000000000000000000000000000000000..1356baa2ed1c6492ef7f24b88005e3bfa1fba6eb --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/__annotated_ptr @@ -0,0 +1,231 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * NVIDIA SOFTWARE LICENSE + * + * This license is a legal agreement between you and NVIDIA Corporation ("NVIDIA") and governs your use of the NVIDIA/CUDA C++ Library software and materials provided hereunder (“SOFTWARE”). + * + * This license can be accepted only by an adult of legal age of majority in the country in which the SOFTWARE is used. If you are under the legal age of majority, you must ask your parent or legal guardian to consent to this license. By taking delivery of the SOFTWARE, you affirm that you have reached the legal age of majority, you accept the terms of this license, and you take legal and financial responsibility for the actions of your permitted users. + * + * You agree to use the SOFTWARE only for purposes that are permitted by (a) this license, and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions. + * + * 1. LICENSE. Subject to the terms of this license, NVIDIA grants you a non-exclusive limited license to: (a) install and use the SOFTWARE, and (b) distribute the SOFTWARE subject to the distribution requirements described in this license. NVIDIA reserves all rights, title and interest in and to the SOFTWARE not expressly granted to you under this license. + * + * 2. DISTRIBUTION REQUIREMENTS. These are the distribution requirements for you to exercise the distribution grant: + * a. The terms under which you distribute the SOFTWARE must be consistent with the terms of this license, including (without limitation) terms relating to the license grant and license restrictions and protection of NVIDIA’s intellectual property rights. + * b. You agree to notify NVIDIA in writing of any known or suspected distribution or use of the SOFTWARE not in compliance with the requirements of this license, and to enforce the terms of your agreements with respect to distributed SOFTWARE. + * + * 3. LIMITATIONS. Your license to use the SOFTWARE is restricted as follows: + * a. The SOFTWARE is licensed for you to develop applications only for use in systems with NVIDIA GPUs. + * b. You may not reverse engineer, decompile or disassemble, or remove copyright or other proprietary notices from any portion of the SOFTWARE or copies of the SOFTWARE. + * c. You may not modify or create derivative works of any portion of the SOFTWARE. + * d. You may not bypass, disable, or circumvent any technical measure, encryption, security, digital rights management or authentication mechanism in the SOFTWARE. + * e. You may not use the SOFTWARE in any manner that would cause it to become subject to an open source software license. As examples, licenses that require as a condition of use, modification, and/or distribution that the SOFTWARE be (i) disclosed or distributed in source code form; (ii) licensed for the purpose of making derivative works; or (iii) redistributable at no charge. + * f. Unless you have an agreement with NVIDIA for this purpose, you may not use the SOFTWARE with any system or application where the use or failure of the system or application can reasonably be expected to threaten or result in personal injury, death, or catastrophic loss. Examples include use in avionics, navigation, military, medical, life support or other life critical applications. NVIDIA does not design, test or manufacture the SOFTWARE for these critical uses and NVIDIA shall not be liable to you or any third party, in whole or in part, for any claims or damages arising from such uses. + * g. You agree to defend, indemnify and hold harmless NVIDIA and its affiliates, and their respective employees, contractors, agents, officers and directors, from and against any and all claims, damages, obligations, losses, liabilities, costs or debt, fines, restitutions and expenses (including but not limited to attorney’s fees and costs incident to establishing the right of indemnification) arising out of or related to use of the SOFTWARE outside of the scope of this Agreement, or not in compliance with its terms. + * + * 4. PRE-RELEASE. SOFTWARE versions identified as alpha, beta, preview, early access or otherwise as pre-release may not be fully functional, may contain errors or design flaws, and may have reduced or different security, privacy, availability, and reliability standards relative to commercial versions of NVIDIA software and materials. You may use a pre-release SOFTWARE version at your own risk, understanding that these versions are not intended for use in production or business-critical systems. + * + * 5. OWNERSHIP. The SOFTWARE and the related intellectual property rights therein are and will remain the sole and exclusive property of NVIDIA or its licensors. The SOFTWARE is copyrighted and protected by the laws of the United States and other countries, and international treaty provisions. NVIDIA may make changes to the SOFTWARE, at any time without notice, but is not obligated to support or update the SOFTWARE. + * + * 6. COMPONENTS UNDER OTHER LICENSES. The SOFTWARE may include NVIDIA or third-party components with separate legal notices or terms as may be described in proprietary notices accompanying the SOFTWARE. If and to the extent there is a conflict between the terms in this license and the license terms associated with a component, the license terms associated with the components control only to the extent necessary to resolve the conflict. + * + * 7. FEEDBACK. You may, but don’t have to, provide to NVIDIA any Feedback. “Feedback” means any suggestions, bug fixes, enhancements, modifications, feature requests or other feedback regarding the SOFTWARE. For any Feedback that you voluntarily provide, you hereby grant NVIDIA and its affiliates a perpetual, non-exclusive, worldwide, irrevocable license to use, reproduce, modify, license, sublicense (through multiple tiers of sublicensees), and distribute (through multiple tiers of distributors) the Feedback without the payment of any royalties or fees to you. NVIDIA will use Feedback at its choice. + * + * 8. NO WARRANTIES. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. NVIDIA DOES NOT WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION THEREOF WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ALL ERRORS WILL BE CORRECTED. + * + * 9. LIMITATIONS OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY LAW, NVIDIA AND ITS AFFILIATES SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR ANY LOST PROFITS, PROJECT DELAYS, LOSS OF USE, LOSS OF DATA OR LOSS OF GOODWILL, OR THE COSTS OF PROCURING SUBSTITUTE PRODUCTS, ARISING OUT OF OR IN CONNECTION WITH THIS LICENSE OR THE USE OR PERFORMANCE OF THE SOFTWARE, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCT LIABILITY OR ANY OTHER CAUSE OF ACTION OR THEORY OF LIABILITY, EVEN IF NVIDIA HAS PREVIOUSLY BEEN ADVISED OF, OR COULD REASONABLY HAVE FORESEEN, THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL NVIDIA’S AND ITS AFFILIATES TOTAL CUMULATIVE LIABILITY UNDER OR ARISING OUT OF THIS LICENSE EXCEED US$10.00. THE NATURE OF THE LIABILITY OR THE NUMBER OF CLAIMS OR SUITS SHALL NOT ENLARGE OR EXTEND THIS LIMIT. + * + * 10. TERMINATION. Your rights under this license will terminate automatically without notice from NVIDIA if you fail to comply with any term and condition of this license or if you commence or participate in any legal proceeding against NVIDIA with respect to the SOFTWARE. NVIDIA may terminate this license with advance written notice to you if NVIDIA decides to no longer provide the SOFTWARE in a country or, in NVIDIA’s sole discretion, the continued use of it is no longer commercially viable. Upon any termination of this license, you agree to promptly discontinue use of the SOFTWARE and destroy all copies in your possession or control. Your prior distributions in accordance with this license are not affected by the termination of this license. All provisions of this license will survive termination, except for the license granted to you. + * + * 11. APPLICABLE LAW. This license will be governed in all respects by the laws of the United States and of the State of Delaware as those laws are applied to contracts entered into and performed entirely within Delaware by Delaware residents, without regard to the conflicts of laws principles. The United Nations Convention on Contracts for the International Sale of Goods is specifically disclaimed. You agree to all terms of this Agreement in the English language. The state or federal courts residing in Santa Clara County, California shall have exclusive jurisdiction over any dispute or claim arising out of this license. Notwithstanding this, you agree that NVIDIA shall still be allowed to apply for injunctive remedies or an equivalent type of urgent legal relief in any jurisdiction. + * + * 12. NO ASSIGNMENT. This license and your rights and obligations thereunder may not be assigned by you by any means or operation of law without NVIDIA’s permission. Any attempted assignment not approved by NVIDIA in writing shall be void and of no effect. + * + * 13. EXPORT. The SOFTWARE is subject to United States export laws and regulations. You agree that you will not ship, transfer or export the SOFTWARE into any country, or use the SOFTWARE in any manner, prohibited by the United States Bureau of Industry and Security or economic sanctions regulations administered by the U.S. Department of Treasury’s Office of Foreign Assets Control (OFAC), or any applicable export laws, restrictions or regulations. These laws include restrictions on destinations, end users and end use. By accepting this license, you confirm that you are not a resident or citizen of any country currently embargoed by the U.S. and that you are not otherwise prohibited from receiving the SOFTWARE. + * + * 14. GOVERNMENT USE. The SOFTWARE has been developed entirely at private expense and is “commercial items” consisting of “commercial computer software” and “commercial computer software documentation” provided with RESTRICTED RIGHTS. Use, duplication or disclosure by the U.S. Government or a U.S. Government subcontractor is subject to the restrictions in this license pursuant to DFARS 227.7202-3(a) or as set forth in subparagraphs (b)(1) and (2) of the Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, as applicable. Contractor/manufacturer is NVIDIA, 2788 San Tomas Expressway, Santa Clara, CA 95051. + * + * 15. ENTIRE AGREEMENT. This license is the final, complete and exclusive agreement between the parties relating to the subject matter of this license and supersedes all prior or contemporaneous understandings and agreements relating to this subject matter, whether oral or written. If any court of competent jurisdiction determines that any provision of this license is illegal, invalid or unenforceable, the remaining provisions will remain in full force and effect. This license may only be modified in a writing signed by an authorized representative of each party. + * + * (v. August 20, 2021) + */ + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +namespace __detail_ap { + + template + _LIBCUDACXX_DEVICE + void* __associate_address_space(void* __ptr, _Property __prop) { + if (std::is_same<_Property, access_property::shared>::value == true) { + bool __b = __isShared(__ptr); + _LIBCUDACXX_ASSERT(__b, ""); +#if !defined(_LIBCUDACXX_CUDACC_BELOW_11_2) + __builtin_assume(__b); +#else // ^^^ !_LIBCUDACXX_CUDACC_BELOW_11_2 ^^^ / vvv _LIBCUDACXX_CUDACC_BELOW_11_2 vvv + (void)__b; +#endif // _LIBCUDACXX_CUDACC_BELOW_11_2 + } else if (std::is_same<_Property, access_property::global>::value == true || + std::is_same<_Property, access_property::normal>::value == true || + std::is_same<_Property, access_property::persisting>::value == true || + std::is_same<_Property, access_property::streaming>::value == true || + std::is_same<_Property, access_property>::value) { + bool __b = __isGlobal(__ptr); + _LIBCUDACXX_ASSERT(__b, ""); +#if !defined(_LIBCUDACXX_CUDACC_BELOW_11_2) + __builtin_assume(__b); +#else // ^^^ !_LIBCUDACXX_CUDACC_BELOW_11_2 ^^^ / vvv _LIBCUDACXX_CUDACC_BELOW_11_2 vvv + (void)__b; +#endif // _LIBCUDACXX_CUDACC_BELOW_11_2 + } + + return __ptr; + } + + template + _LIBCUDACXX_DEVICE + void* __associate_descriptor(void* __ptr, __Prop __prop) { + return __associate_descriptor(__ptr, static_cast(access_property(__prop))); + } + + template <> + inline _LIBCUDACXX_DEVICE + void* __associate_descriptor(void* __ptr, std::uint64_t __prop) { + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_80,( + return __nv_associate_access_property(__ptr, __prop); + ),( + return __ptr; + )) + } + + template<> + inline _LIBCUDACXX_DEVICE + void* __associate_descriptor(void* __ptr, access_property::shared) { + return __ptr; + } + + template + _LIBCUDACXX_HOST_DEVICE + _Type* __associate(_Type* __ptr, _Property __prop) { + NV_IF_ELSE_TARGET(NV_IS_DEVICE,( + return static_cast<_Type*>(__associate_descriptor( + __associate_address_space(const_cast(static_cast(__ptr)), __prop), + __prop)); + ),( + return __ptr; + )) + } + + + template + class __annotated_ptr_base { + using __error = typename _Property::__unknown_access_property_type; + }; + + template<> + class __annotated_ptr_base { + protected: + static constexpr std::uint64_t __prop = 0; + + constexpr __annotated_ptr_base() noexcept = default; + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property::shared) noexcept {} + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, access_property::shared{}); + } + _LIBCUDACXX_HOST_DEVICE constexpr access_property::shared __get_property() const noexcept { + return access_property::shared{}; + } + }; + + template<> + class __annotated_ptr_base { + protected: + static constexpr std::uint64_t __prop = __sm_80::__interleave_normal(); + + constexpr __annotated_ptr_base() noexcept = default; + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property::global) noexcept {} + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, access_property::global{}); + } + _LIBCUDACXX_HOST_DEVICE constexpr access_property::global __get_property() const noexcept { + return access_property::global{}; + } + }; + + template<> + class __annotated_ptr_base { + protected: + static constexpr std::uint64_t __prop = __sm_80::__interleave_normal_demote(); + + constexpr __annotated_ptr_base() noexcept = default; + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property::normal) noexcept {} + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, access_property::normal{}); + } + _LIBCUDACXX_HOST_DEVICE constexpr access_property::normal __get_property() const noexcept { + return access_property::normal{}; + } + }; + + template<> + class __annotated_ptr_base { + protected: + static constexpr std::uint64_t __prop = __sm_80::__interleave_persisting(); + + constexpr __annotated_ptr_base() noexcept = default; + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property::persisting) noexcept {} + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, access_property::persisting{}); + } + _LIBCUDACXX_HOST_DEVICE constexpr access_property::persisting __get_property() const noexcept { + return access_property::persisting{}; + } + }; + + template<> + class __annotated_ptr_base { + protected: + static constexpr std::uint64_t __prop = __sm_80::__interleave_streaming(); + + constexpr __annotated_ptr_base() noexcept = default; + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property::streaming) noexcept {} + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, access_property::streaming{}); + } + _LIBCUDACXX_HOST_DEVICE constexpr access_property::streaming __get_property() const noexcept { + return access_property::streaming{}; + } + }; + + template<> + class __annotated_ptr_base { + protected: + std::uint64_t __prop; + + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base() noexcept : __prop(access_property()) {} + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(std::uint64_t __property) noexcept : __prop(__property) {} + _LIBCUDACXX_HOST_DEVICE constexpr __annotated_ptr_base(access_property __property) noexcept + : __annotated_ptr_base(static_cast(__property)) {} + constexpr __annotated_ptr_base(__annotated_ptr_base const&) = default; + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 __annotated_ptr_base& operator=(const __annotated_ptr_base&) = default; + inline _LIBCUDACXX_DEVICE void* __apply_prop(void* __p) const { + return __associate(__p, __prop); + } + _LIBCUDACXX_HOST_DEVICE access_property __get_property() const noexcept { + return reinterpret_cast(const_cast(__prop)); + } + }; +} // namespace __detail_ap + +_LIBCUDACXX_END_NAMESPACE_CUDA diff --git a/cuda_toolkit/include/cuda/std/detail/__config b/cuda_toolkit/include/cuda/std/detail/__config new file mode 100644 index 0000000000000000000000000000000000000000..ed1bad96c43b6d4b6e0fff94cc2c6a05c5ae5875 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/__config @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef __cuda_std__ +#define __cuda_std__ + +#include + +#define _LIBCUDACXX_CUDA_API_VERSION CCCL_VERSION +#define _LIBCUDACXX_CUDA_API_VERSION_MAJOR CCCL_MAJOR_VERSION +#define _LIBCUDACXX_CUDA_API_VERSION_MINOR CCCL_MINOR_VERSION +#define _LIBCUDACXX_CUDA_API_VERSION_PATCH CCCL_PATCH_VERSION + +#ifndef _LIBCUDACXX_CUDA_ABI_VERSION_LATEST +# define _LIBCUDACXX_CUDA_ABI_VERSION_LATEST 4 +#endif + +#ifdef _LIBCUDACXX_CUDA_ABI_VERSION +# if _LIBCUDACXX_CUDA_ABI_VERSION != 2 && _LIBCUDACXX_CUDA_ABI_VERSION != 3 && _LIBCUDACXX_CUDA_ABI_VERSION != 4 +# error Unsupported libcu++ ABI version requested. Please define _LIBCUDACXX_CUDA_ABI_VERSION to either 2 or 3. +# endif +#else +# define _LIBCUDACXX_CUDA_ABI_VERSION _LIBCUDACXX_CUDA_ABI_VERSION_LATEST +#endif + +#ifdef _LIBCUDACXX_PIPELINE_ASSUMED_ABI_VERSION +# if _LIBCUDACXX_PIPELINE_ASSUMED_ABI_VERSION != _LIBCUDACXX_CUDA_ABI_VERSION +# error cuda_pipeline.h has assumed a different libcu++ ABI version than provided by this library. To fix this, please include a libcu++ header before including cuda_pipeline.h, or upgrade to a version of the toolkit this version of libcu++ shipped in. +# endif +#endif + +#include "libcxx/include/__config" + +#endif //__cuda_std__ diff --git a/cuda_toolkit/include/cuda/std/detail/__pragma_pop b/cuda_toolkit/include/cuda/std/detail/__pragma_pop new file mode 100644 index 0000000000000000000000000000000000000000..834c9ea541a9687df2c09da4c1674318a86595ce --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/__pragma_pop @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#include "libcxx/include/__pragma_pop" + diff --git a/cuda_toolkit/include/cuda/std/detail/__pragma_push b/cuda_toolkit/include/cuda/std/detail/__pragma_push new file mode 100644 index 0000000000000000000000000000000000000000..1b7ba00994c13e00b8d020afd61d40a9b5569a2f --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/__pragma_push @@ -0,0 +1,13 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#include "libcxx/include/__pragma_push" +#include "libcxx/include/__undef_macros" + diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__algorithm/swap_ranges.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__algorithm/swap_ranges.h new file mode 100644 index 0000000000000000000000000000000000000000..05027c2c049f14b13da4cebb5c6cdbe9dc964a5f --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__assert b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__assert new file mode 100644 index 0000000000000000000000000000000000000000..2e378d0912010cb93968e7a16c79f03b96c615f5 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__assert @@ -0,0 +1,70 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ASSERT +#define _LIBCUDACXX___ASSERT + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "__verbose_abort" + +#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 for backwards compatibility with code that might have been enabling +// assertions through the Debug mode previously. +// TODO: In LLVM 16, make it an error to define _LIBCUDACXX_DEBUG +#if defined(_LIBCUDACXX_DEBUG) +# ifndef _LIBCUDACXX_ENABLE_ASSERTIONS +# define _LIBCUDACXX_ENABLE_ASSERTIONS 1 +# endif +#endif + +// Automatically enable assertions when the debug mode is enabled. +#if defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) +# ifndef _LIBCUDACXX_ENABLE_ASSERTIONS +# define _LIBCUDACXX_ENABLE_ASSERTIONS 1 +# endif +#endif + +#ifndef _LIBCUDACXX_ENABLE_ASSERTIONS +# define _LIBCUDACXX_ENABLE_ASSERTIONS _LIBCUDACXX_ENABLE_ASSERTIONS_DEFAULT +#endif + +#if _LIBCUDACXX_ENABLE_ASSERTIONS != 0 && _LIBCUDACXX_ENABLE_ASSERTIONS != 1 +# error "_LIBCUDACXX_ENABLE_ASSERTIONS must be set to 0 or 1" +#endif + +#if _LIBCUDACXX_ENABLE_ASSERTIONS +# define _LIBCUDACXX_ASSERT(expression, message) \ + (_CCCL_DIAG_PUSH \ + _CCCL_DIAG_SUPPRESS_CLANG("-Wassume") \ + __builtin_expect(static_cast(expression), 1) ? \ + (void)0 : \ + ::_CUDA_VSTD::__libcpp_verbose_abort("%s:%d: assertion %s failed: %s", __FILE__, __LINE__, #expression, message) + _CCCL_DIAG_POP) +#elif 0 // !defined(_LIBCUDACXX_ASSERTIONS_DISABLE_ASSUME) && __has_builtin(__builtin_assume) +# define _LIBCUDACXX_ASSERT(expression, message) \ + (_CCCL_DIAG_PUSH \ + _CCCL_DIAG_SUPPRESS_CLANG("-Wassume") \ + __builtin_assume(static_cast(expression)) \ + _CCCL_DIAG_POP) +#else +# define _LIBCUDACXX_ASSERT(expression, message) ((void)0) +#endif + +#endif // _LIBCUDACXX___ASSERT diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__availability b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__availability new file mode 100644 index 0000000000000000000000000000000000000000..1331d6600259ed47ee51b0dade2466e9c608372e --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__availability @@ -0,0 +1,306 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___AVAILABILITY +#define _LIBCUDACXX___AVAILABILITY + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_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 + +// Libc++ is shipped by various vendors. In particular, it is used as a system +// library on macOS, iOS and other Apple platforms. In order for users to be +// able to compile a binary that is intended to be deployed to an older version +// of a platform, Clang provides availability attributes [1]. These attributes +// can be placed on declarations and are used to describe the life cycle of a +// symbol in the library. +// +// The main goal is to ensure a compile-time error if a symbol that hasn't been +// introduced in a previously released library is used in a program that targets +// that previously released library. Normally, this would be a load-time error +// when one tries to launch the program against the older library. +// +// For example, the filesystem library was introduced in the dylib in macOS 10.15. +// If a user compiles on a macOS 10.15 host but targets macOS 10.13 with their +// program, the compiler would normally not complain (because the required +// declarations are in the headers), but the dynamic loader would fail to find +// the symbols when actually trying to launch the program on macOS 10.13. To +// turn this into a compile-time issue instead, declarations are annotated with +// when they were introduced, and the compiler can produce a diagnostic if the +// program references something that isn't available on the deployment target. +// +// This mechanism is general in nature, and any vendor can add their markup to +// the library (see below). Whenever a new feature is added that requires support +// in the shared library, a macro should be added below to mark this feature +// as unavailable. When vendors decide to ship the feature as part of their +// shared library, they can update the markup appropriately. +// +// Furthermore, many features in the standard library have corresponding +// feature-test macros. When a feature is made unavailable on some deployment +// target, a macro should be defined to signal that it is unavailable. That +// macro can then be picked up when feature-test macros are generated (see +// generate_feature_test_macro_components.py) to make sure that feature-test +// macros don't announce a feature as being implemented if it has been marked +// as unavailable. +// +// Note that this mechanism is disabled by default in the "upstream" libc++. +// Availability annotations are only meaningful when shipping libc++ inside +// a platform (i.e. as a system library), and so vendors that want them should +// turn those annotations on at CMake configuration time. +// +// [1]: https://clang.llvm.org/docs/AttributeReference.html#availability + + +// For backwards compatibility, allow users to define _LIBCUDACXX_DISABLE_AVAILABILITY +// for a while. +#if defined(_LIBCUDACXX_DISABLE_AVAILABILITY) +# if !defined(_LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) +# define _LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS +# endif +#endif + +// Availability markup is disabled when building the library, or when the compiler +// doesn't support the proper attributes. +#if defined(_LIBCUDACXX_BUILDING_LIBRARY) || \ + defined(_LIBCXXABI_BUILDING_LIBRARY) || \ + !__has_feature(attribute_availability_with_strict) || \ + !__has_feature(attribute_availability_in_templates) || \ + !__has_extension(pragma_clang_attribute_external_declaration) +# if !defined(_LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) +# define _LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS +# endif +#endif + +#if defined(_LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) + + // This controls the availability of std::shared_mutex and std::shared_timed_mutex, + // which were added to the dylib later. +# define _LIBCUDACXX_AVAILABILITY_SHARED_MUTEX +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_mutex +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex + + // These macros control the availability of std::bad_optional_access and + // other exception types. These were put in the shared library to prevent + // code bloat from every user program defining the vtable for these exception + // types. + // + // Note that when exceptions are disabled, the methods that normally throw + // these exceptions can be used even on older deployment targets, but those + // methods will abort instead of throwing. +# define _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS +# define _LIBCUDACXX_AVAILABILITY_BAD_VARIANT_ACCESS +# define _LIBCUDACXX_AVAILABILITY_BAD_ANY_CAST + + // This controls the availability of std::uncaught_exceptions(). +# define _LIBCUDACXX_AVAILABILITY_UNCAUGHT_EXCEPTIONS + + // This controls the availability of the sized version of ::operator delete, + // ::operator delete[], and their align_val_t variants, which were all added + // in C++17, and hence not present in early dylibs. +# define _LIBCUDACXX_AVAILABILITY_SIZED_NEW_DELETE + + // This controls the availability of the std::future_error exception. + // + // Note that when exceptions are disabled, the methods that normally throw + // std::future_error can be used even on older deployment targets, but those + // methods will abort instead of throwing. +# define _LIBCUDACXX_AVAILABILITY_FUTURE_ERROR + + // This controls the availability of std::type_info's vtable. + // I can't imagine how using std::type_info can work at all if + // this isn't supported. +# define _LIBCUDACXX_AVAILABILITY_TYPEINFO_VTABLE + + // This controls the availability of std::locale::category members + // (e.g. std::locale::collate), which are defined in the dylib. +# define _LIBCUDACXX_AVAILABILITY_LOCALE_CATEGORY + + // This controls the availability of atomic operations on std::shared_ptr + // (e.g. `std::atomic_store(std::shared_ptr)`), which require a shared + // lock table located in the dylib. +# define _LIBCUDACXX_AVAILABILITY_ATOMIC_SHARED_PTR + + // These macros control the availability of all parts of that + // depend on something in the dylib. +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_PUSH +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_POP +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem + + // This controls the availability of floating-point std::to_chars functions. + // These overloads were added later than the integer overloads. +# define _LIBCUDACXX_AVAILABILITY_TO_CHARS_FLOATING_POINT + + // This controls the availability of the C++20 synchronization library, + // which requires shared library support for various operations + // (see libcxx/src/atomic.cpp). This includes , , + // , and notification functions on std::atomic. +# define _LIBCUDACXX_AVAILABILITY_SYNC +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_latch +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore + + // This controls the availability of the C++20 format library. + // The library is in development and not ABI stable yet. P2216 is + // retroactively accepted in C++20. This paper contains ABI breaking + // changes. +# define _LIBCUDACXX_AVAILABILITY_FORMAT +// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_format + + // This controls whether the default verbose termination function is + // provided by the library. + // + // Note that when users provide their own custom function, it doesn't + // matter whether the dylib provides a default function, and the + // availability markup can actually give a false positive diagnostic + // (it will think that no function is provided, when in reality the + // user has provided their own). + // + // Users can pass -D_LIBCUDACXX_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED + // to the compiler to tell the library not to define its own verbose abort. + // Note that defining this macro but failing to define a custom function + // will lead to a load-time error on back-deployment targets, so it should + // be avoided. +// # define _LIBCUDACXX_HAS_NO_VERBOSE_ABORT_IN_LIBRARY + +#elif defined(__APPLE__) + +# define _LIBCUDACXX_AVAILABILITY_SHARED_MUTEX \ + __attribute__((availability(macos,strict,introduced=10.12))) \ + __attribute__((availability(ios,strict,introduced=10.0))) \ + __attribute__((availability(tvos,strict,introduced=10.0))) \ + __attribute__((availability(watchos,strict,introduced=3.0))) +# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 100000) || \ + (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 100000) || \ + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 30000) +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_mutex +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex +# endif + + // Note: bad_optional_access & friends were not introduced in the matching + // macOS and iOS versions, so the version mismatch between macOS and others + // is intended. +# define _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS \ + __attribute__((availability(macos,strict,introduced=10.13))) \ + __attribute__((availability(ios,strict,introduced=12.0))) \ + __attribute__((availability(tvos,strict,introduced=12.0))) \ + __attribute__((availability(watchos,strict,introduced=5.0))) +# define _LIBCUDACXX_AVAILABILITY_BAD_VARIANT_ACCESS \ + _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS +# define _LIBCUDACXX_AVAILABILITY_BAD_ANY_CAST \ + _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS + +# define _LIBCUDACXX_AVAILABILITY_UNCAUGHT_EXCEPTIONS \ + __attribute__((availability(macos,strict,introduced=10.12))) \ + __attribute__((availability(ios,strict,introduced=10.0))) \ + __attribute__((availability(tvos,strict,introduced=10.0))) \ + __attribute__((availability(watchos,strict,introduced=3.0))) + +# define _LIBCUDACXX_AVAILABILITY_SIZED_NEW_DELETE \ + __attribute__((availability(macos,strict,introduced=10.12))) \ + __attribute__((availability(ios,strict,introduced=10.0))) \ + __attribute__((availability(tvos,strict,introduced=10.0))) \ + __attribute__((availability(watchos,strict,introduced=3.0))) + +# define _LIBCUDACXX_AVAILABILITY_FUTURE_ERROR \ + __attribute__((availability(ios,strict,introduced=6.0))) + +# define _LIBCUDACXX_AVAILABILITY_TYPEINFO_VTABLE \ + __attribute__((availability(macos,strict,introduced=10.9))) \ + __attribute__((availability(ios,strict,introduced=7.0))) + +# define _LIBCUDACXX_AVAILABILITY_LOCALE_CATEGORY \ + __attribute__((availability(macos,strict,introduced=10.9))) \ + __attribute__((availability(ios,strict,introduced=7.0))) + +# define _LIBCUDACXX_AVAILABILITY_ATOMIC_SHARED_PTR \ + __attribute__((availability(macos,strict,introduced=10.9))) \ + __attribute__((availability(ios,strict,introduced=7.0))) + +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM \ + __attribute__((availability(macos,strict,introduced=10.15))) \ + __attribute__((availability(ios,strict,introduced=13.0))) \ + __attribute__((availability(tvos,strict,introduced=13.0))) \ + __attribute__((availability(watchos,strict,introduced=6.0))) +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_PUSH \ + _Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))") +# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_POP \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") +# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \ + (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000) || \ + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000) +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem +# endif + +# define _LIBCUDACXX_AVAILABILITY_TO_CHARS_FLOATING_POINT \ + __attribute__((unavailable)) + +# define _LIBCUDACXX_AVAILABILITY_SYNC \ + __attribute__((availability(macos,strict,introduced=11.0))) \ + __attribute__((availability(ios,strict,introduced=14.0))) \ + __attribute__((availability(tvos,strict,introduced=14.0))) \ + __attribute__((availability(watchos,strict,introduced=7.0))) +# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000) || \ + (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 140000) || \ + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 70000) +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_latch +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore +# endif + +# define _LIBCUDACXX_AVAILABILITY_FORMAT \ + __attribute__((unavailable)) +# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_format + +# define _LIBCUDACXX_HAS_NO_VERBOSE_ABORT_IN_LIBRARY + +#else + +// ...New vendors can add availability markup here... + +# error "It looks like you're trying to enable vendor availability markup, but you haven't defined the corresponding macros yet!" + +#endif + +// Define availability attributes that depend on _LIBCUDACXX_NO_EXCEPTIONS. +// Those are defined in terms of the availability attributes above, and +// should not be vendor-specific. +#if defined(_LIBCUDACXX_NO_EXCEPTIONS) +# define _LIBCUDACXX_AVAILABILITY_FUTURE +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_ANY_CAST +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +#else +# define _LIBCUDACXX_AVAILABILITY_FUTURE _LIBCUDACXX_AVAILABILITY_FUTURE_ERROR +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_ANY_CAST _LIBCUDACXX_AVAILABILITY_BAD_ANY_CAST +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS +# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_VARIANT_ACCESS _LIBCUDACXX_AVAILABILITY_BAD_VARIANT_ACCESS +#endif + +#endif // _LIBCUDACXX___AVAILABILITY diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__bit_reference b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__bit_reference new file mode 100644 index 0000000000000000000000000000000000000000..14377c0b1bc2a5e837dd13d65a858b4612265713 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__bit_reference @@ -0,0 +1,1293 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___BIT_REFERENCE +#define _LIBCUDACXX___BIT_REFERENCE + +#include <__config> +#include +#include + +#if defined(_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_PUSH_MACROS +#include <__undef_macros> + + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template class __bit_iterator; +template class __bit_const_reference; + +template +struct __has_storage_type +{ + static const bool value = false; +}; + +template ::value> +class __bit_reference +{ + typedef typename _Cp::__storage_type __storage_type; + typedef typename _Cp::__storage_pointer __storage_pointer; + + __storage_pointer __seg_; + __storage_type __mask_; + + friend typename _Cp::__self; + + friend class __bit_const_reference<_Cp>; + friend class __bit_iterator<_Cp, false>; +public: + _LIBCUDACXX_INLINE_VISIBILITY + __bit_reference(const __bit_reference&) = default; + + _LIBCUDACXX_INLINE_VISIBILITY operator bool() const noexcept + {return static_cast(*__seg_ & __mask_);} + _LIBCUDACXX_INLINE_VISIBILITY bool operator ~() const noexcept + {return !static_cast(*this);} + + _LIBCUDACXX_INLINE_VISIBILITY + __bit_reference& operator=(bool __x) noexcept + { + if (__x) + *__seg_ |= __mask_; + else + *__seg_ &= ~__mask_; + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __bit_reference& operator=(const __bit_reference& __x) noexcept + {return operator=(static_cast(__x));} + + _LIBCUDACXX_INLINE_VISIBILITY void flip() noexcept {*__seg_ ^= __mask_;} + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator<_Cp, false> operator&() const noexcept + {return __bit_iterator<_Cp, false>(__seg_, static_cast(__libcpp_ctz(__mask_)));} +private: + _LIBCUDACXX_INLINE_VISIBILITY + __bit_reference(__storage_pointer __s, __storage_type __m) noexcept + : __seg_(__s), __mask_(__m) {} +}; + +template +class __bit_reference<_Cp, false> +{ +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) noexcept +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) noexcept +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(__bit_reference<_Cp> __x, bool& __y) noexcept +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(bool& __x, __bit_reference<_Cp> __y) noexcept +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template +class __bit_const_reference +{ + typedef typename _Cp::__storage_type __storage_type; + typedef typename _Cp::__const_storage_pointer __storage_pointer; + + __storage_pointer __seg_; + __storage_type __mask_; + + friend typename _Cp::__self; + friend class __bit_iterator<_Cp, true>; +public: + _LIBCUDACXX_INLINE_VISIBILITY + __bit_const_reference(const __bit_const_reference&) = default; + + _LIBCUDACXX_INLINE_VISIBILITY + __bit_const_reference(const __bit_reference<_Cp>& __x) noexcept + : __seg_(__x.__seg_), __mask_(__x.__mask_) {} + + _LIBCUDACXX_INLINE_VISIBILITY constexpr operator bool() const noexcept + {return static_cast(*__seg_ & __mask_);} + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const noexcept + {return __bit_iterator<_Cp, true>(__seg_, static_cast(__libcpp_ctz(__mask_)));} +private: + _LIBCUDACXX_INLINE_VISIBILITY + constexpr + __bit_const_reference(__storage_pointer __s, __storage_type __m) noexcept + : __seg_(__s), __mask_(__m) {} + + __bit_const_reference& operator=(const __bit_const_reference&) = delete; +}; + +// find + +template +__bit_iterator<_Cp, _IsConst> +__find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + static const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(__b))); + if (__n == __dn) + return __first + __n; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + if (*__first.__seg_) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(*__first.__seg_))); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(__b))); + } + return _It(__first.__seg_, static_cast(__n)); +} + +template +__bit_iterator<_Cp, _IsConst> +__find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = ~*__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(__b))); + if (__n == __dn) + return __first + __n; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + { + __storage_type __b = ~*__first.__seg_; + if (__b) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(__b))); + } + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = ~*__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast(_CUDA_VSTD::__libcpp_ctz(__b))); + } + return _It(__first.__seg_, static_cast(__n)); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<_Cp, _IsConst> +find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_) +{ + if (static_cast(__value_)) + return __find_bool_true(__first, static_cast(__last - __first)); + return __find_bool_false(__first, static_cast(__last - __first)); +} + +// count + +template +typename __bit_iterator<_Cp, _IsConst>::difference_type +__count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + typedef typename _It::difference_type difference_type; + const int __bits_per_word = _It::__bits_per_word; + difference_type __r = 0; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __r = _CUDA_VSTD::__libcpp_popcount(*__first.__seg_ & __m); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + __r += _CUDA_VSTD::__libcpp_popcount(*__first.__seg_); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __r += _CUDA_VSTD::__libcpp_popcount(*__first.__seg_ & __m); + } + return __r; +} + +template +typename __bit_iterator<_Cp, _IsConst>::difference_type +__count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + typedef typename _It::difference_type difference_type; + const int __bits_per_word = _It::__bits_per_word; + difference_type __r = 0; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __r = _CUDA_VSTD::__libcpp_popcount(~*__first.__seg_ & __m); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + __r += _CUDA_VSTD::__libcpp_popcount(~*__first.__seg_); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __r += _CUDA_VSTD::__libcpp_popcount(~*__first.__seg_ & __m); + } + return __r; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __bit_iterator<_Cp, _IsConst>::difference_type +count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_) +{ + if (static_cast(__value_)) + return __count_bool_true(__first, static_cast(__last - __first)); + return __count_bool_false(__first, static_cast(__last - __first)); +} + +// fill_n + +template +void +__fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, false> _It; + typedef typename _It::__storage_type __storage_type; + const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + *__first.__seg_ &= ~__m; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + __storage_type __nw = __n / __bits_per_word; + _CUDA_VSTD::memset(_CUDA_VSTD::__to_raw_pointer(__first.__seg_), 0, __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last partial word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__first.__seg_ &= ~__m; + } +} + +template +void +__fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, false> _It; + typedef typename _It::__storage_type __storage_type; + const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _CUDA_VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + *__first.__seg_ |= __m; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + __storage_type __nw = __n / __bits_per_word; + _CUDA_VSTD::memset(_CUDA_VSTD::__to_raw_pointer(__first.__seg_), -1, __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last partial word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__first.__seg_ |= __m; + } +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __value_) +{ + if (__n > 0) + { + if (__value_) + __fill_n_true(__first, __n); + else + __fill_n_false(__first, __n); + } +} + +// fill + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool __value_) +{ + _CUDA_VSTD::fill_n(__first, static_cast(__last - __first), __value_); +} + +// copy + +template +__bit_iterator<_Cp, false> +__copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + __storage_type __b = *__first.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + __storage_type __nw = __n / __bits_per_word; + _CUDA_VSTD::memmove(_CUDA_VSTD::__to_raw_pointer(__result.__seg_), + _CUDA_VSTD::__to_raw_pointer(__first.__seg_), + __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + __result.__seg_ += __nw; + // do last word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast(__n); + } + } + return __result; +} + +template +__bit_iterator<_Cp, false> +__copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + static const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _CUDA_VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __first.__ctz_) + *__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_); + else + *__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_); + __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> (__first.__ctz_ + __ddn); + __result.__ctz_ = static_cast(__dn); + } + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __m = ~__storage_type(0) << __result.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) + { + __storage_type __b = *__first.__seg_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << __result.__ctz_; + ++__result.__seg_; + *__result.__seg_ &= __m; + *__result.__seg_ |= __b >> __clz_r; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + __storage_type __dn = _CUDA_VSTD::min(__n, static_cast(__clz_r)); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << __result.__ctz_; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> __dn; + __result.__ctz_ = static_cast(__n); + } + } + } + return __result; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + if (__first.__ctz_ == __result.__ctz_) + return __copy_aligned(__first, __last, __result); + return __copy_unaligned(__first, __last, __result); +} + +// copy_backward + +template +__bit_iterator<_Cp, false> +__copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__last.__ctz_ != 0) + { + difference_type __dn = _CUDA_VSTD::min(static_cast(__last.__ctz_), __n); + __n -= __dn; + unsigned __clz = __bits_per_word - __last.__ctz_; + __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz); + __storage_type __b = *__last.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + // __last.__ctz_ = 0 + } + // __last.__ctz_ == 0 || __n == 0 + // __result.__ctz_ == 0 || __n == 0 + // do middle words + __storage_type __nw = __n / __bits_per_word; + __result.__seg_ -= __nw; + __last.__seg_ -= __nw; + _CUDA_VSTD::memmove(_CUDA_VSTD::__to_raw_pointer(__result.__seg_), + _CUDA_VSTD::__to_raw_pointer(__last.__seg_), + __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) << (__bits_per_word - __n); + __storage_type __b = *--__last.__seg_ & __m; + *--__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); + } + } + return __result; +} + +template +__bit_iterator<_Cp, false> +__copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__last.__ctz_ != 0) + { + difference_type __dn = _CUDA_VSTD::min(static_cast(__last.__ctz_), __n); + __n -= __dn; + unsigned __clz_l = __bits_per_word - __last.__ctz_; + __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_l); + __storage_type __b = *__last.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _CUDA_VSTD::min(__dn, static_cast(__result.__ctz_)); + if (__ddn > 0) + { + __m = (~__storage_type(0) << (__result.__ctz_ - __ddn)) & (~__storage_type(0) >> __clz_r); + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __last.__ctz_) + *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); + else + *__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_); + __result.__ctz_ = static_cast(((-__ddn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + } + if (__dn > 0) + { + // __result.__ctz_ == 0 + --__result.__seg_; + __result.__ctz_ = static_cast(-__dn & (__bits_per_word - 1)); + __m = ~__storage_type(0) << __result.__ctz_; + *__result.__seg_ &= ~__m; + __last.__ctz_ -= __dn + __ddn; + *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); + } + // __last.__ctz_ = 0 + } + // __last.__ctz_ == 0 || __n == 0 + // __result.__ctz_ != 0 || __n == 0 + // do middle words + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __m = ~__storage_type(0) >> __clz_r; + for (; __n >= __bits_per_word; __n -= __bits_per_word) + { + __storage_type __b = *--__last.__seg_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> __clz_r; + *--__result.__seg_ &= __m; + *__result.__seg_ |= __b << __result.__ctz_; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) << (__bits_per_word - __n); + __storage_type __b = *--__last.__seg_ & __m; + __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __dn = _CUDA_VSTD::min(__n, static_cast(__result.__ctz_)); + __m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_); + __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + // __result.__ctz_ == 0 + --__result.__seg_; + __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); + __m = ~__storage_type(0) << __result.__ctz_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn)); + } + } + } + return __result; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +copy_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + if (__last.__ctz_ == __result.__ctz_) + return __copy_backward_aligned(__first, __last, __result); + return __copy_backward_unaligned(__first, __last, __result); +} + +// move + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +move(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + return _CUDA_VSTD::copy(__first, __last, __result); +} + +// move_backward + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +move_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + return _CUDA_VSTD::copy_backward(__first, __last, __result); +} + +// swap_ranges + +template +__bit_iterator<__C2, false> +__swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, + __bit_iterator<__C2, false> __result) +{ + typedef __bit_iterator<__C1, false> _I1; + typedef typename _I1::difference_type difference_type; + typedef typename _I1::__storage_type __storage_type; + const int __bits_per_word = _I1::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1; + *__first.__seg_ |= __b2; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_) + swap(*__first.__seg_, *__result.__seg_); + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1; + *__first.__seg_ |= __b2; + __result.__ctz_ = static_cast(__n); + } + } + return __result; +} + +template +__bit_iterator<__C2, false> +__swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, + __bit_iterator<__C2, false> __result) +{ + typedef __bit_iterator<__C1, false> _I1; + typedef typename _I1::difference_type difference_type; + typedef typename _I1::__storage_type __storage_type; + const int __bits_per_word = _I1::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _CUDA_VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __first.__ctz_) + { + unsigned __s = __result.__ctz_ - __first.__ctz_; + *__result.__seg_ |= __b1 << __s; + *__first.__seg_ |= __b2 >> __s; + } + else + { + unsigned __s = __first.__ctz_ - __result.__ctz_; + *__result.__seg_ |= __b1 >> __s; + *__first.__seg_ |= __b2 << __s; + } + __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + unsigned __s = __first.__ctz_ + __ddn; + *__result.__seg_ |= __b1 >> __s; + *__first.__seg_ |= __b2 << __s; + __result.__ctz_ = static_cast(__dn); + } + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + __storage_type __m = ~__storage_type(0) << __result.__ctz_; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) + { + __storage_type __b1 = *__first.__seg_; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 << __result.__ctz_; + *__first.__seg_ = __b2 >> __result.__ctz_; + ++__result.__seg_; + __b2 = *__result.__seg_ & ~__m; + *__result.__seg_ &= __m; + *__result.__seg_ |= __b1 >> __clz_r; + *__first.__seg_ |= __b2 << __clz_r; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __dn = _CUDA_VSTD::min<__storage_type>(__n, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 << __result.__ctz_; + *__first.__seg_ |= __b2 >> __result.__ctz_; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 >> __dn; + *__first.__seg_ |= __b2 << __dn; + __result.__ctz_ = static_cast(__n); + } + } + } + return __result; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bit_iterator<__C2, false> +swap_ranges(__bit_iterator<__C1, false> __first1, __bit_iterator<__C1, false> __last1, + __bit_iterator<__C2, false> __first2) +{ + if (__first1.__ctz_ == __first2.__ctz_) + return __swap_ranges_aligned(__first1, __last1, __first2); + return __swap_ranges_unaligned(__first1, __last1, __first2); +} + +// rotate + +template +struct __bit_array +{ + typedef typename _Cp::difference_type difference_type; + typedef typename _Cp::__storage_type __storage_type; + typedef typename _Cp::__storage_pointer __storage_pointer; + typedef typename _Cp::iterator iterator; + static const unsigned __bits_per_word = _Cp::__bits_per_word; + static const unsigned _Np = 4; + + difference_type __size_; + __storage_type __word_[_Np]; + + _LIBCUDACXX_INLINE_VISIBILITY static difference_type capacity() + {return static_cast(_Np * __bits_per_word);} + _LIBCUDACXX_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {} + _LIBCUDACXX_INLINE_VISIBILITY iterator begin() + { + return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0); + } + _LIBCUDACXX_INLINE_VISIBILITY iterator end() + { + return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word, + static_cast(__size_ % __bits_per_word)); + } +}; + +template +__bit_iterator<_Cp, false> +rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last) +{ + typedef __bit_iterator<_Cp, false> _I1; + typedef typename _I1::difference_type difference_type; + difference_type __d1 = __middle - __first; + difference_type __d2 = __last - __middle; + _I1 __r = __first + __d2; + while (__d1 != 0 && __d2 != 0) + { + if (__d1 <= __d2) + { + if (__d1 <= __bit_array<_Cp>::capacity()) + { + __bit_array<_Cp> __b(__d1); + _CUDA_VSTD::copy(__first, __middle, __b.begin()); + _CUDA_VSTD::copy(__b.begin(), __b.end(), _CUDA_VSTD::copy(__middle, __last, __first)); + break; + } + else + { + __bit_iterator<_Cp, false> __mp = _CUDA_VSTD::swap_ranges(__first, __middle, __middle); + __first = __middle; + __middle = __mp; + __d2 -= __d1; + } + } + else + { + if (__d2 <= __bit_array<_Cp>::capacity()) + { + __bit_array<_Cp> __b(__d2); + _CUDA_VSTD::copy(__middle, __last, __b.begin()); + _CUDA_VSTD::copy_backward(__b.begin(), __b.end(), _CUDA_VSTD::copy_backward(__first, __middle, __last)); + break; + } + else + { + __bit_iterator<_Cp, false> __mp = __first + __d2; + _CUDA_VSTD::swap_ranges(__first, __mp, __middle); + __first = __mp; + __d1 -= __d2; + } + } + } + return __r; +} + +// equal + +template +bool +__equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, + __bit_iterator<_Cp, _IC2> __first2) +{ + typedef __bit_iterator<_Cp, _IC1> _It; + typedef typename _It::difference_type difference_type; + typedef typename _It::__storage_type __storage_type; + static const int __bits_per_word = _It::__bits_per_word; + difference_type __n = __last1 - __first1; + if (__n > 0) + { + // do first word + if (__first1.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first1.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first1.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __first2.__ctz_; + __storage_type __ddn = _CUDA_VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + if (__first2.__ctz_ > __first1.__ctz_) + { + if ((*__first2.__seg_ & __m) != (__b << (__first2.__ctz_ - __first1.__ctz_))) + return false; + } + else + { + if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ - __first2.__ctz_))) + return false; + } + __first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word; + __first2.__ctz_ = static_cast((__ddn + __first2.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ + __ddn))) + return false; + __first2.__ctz_ = static_cast(__dn); + } + ++__first1.__seg_; + // __first1.__ctz_ = 0; + } + // __first1.__ctz_ == 0; + // do middle words + unsigned __clz_r = __bits_per_word - __first2.__ctz_; + __storage_type __m = ~__storage_type(0) << __first2.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_) + { + __storage_type __b = *__first1.__seg_; + if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) + return false; + ++__first2.__seg_; + if ((*__first2.__seg_ & ~__m) != (__b >> __clz_r)) + return false; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first1.__seg_ & __m; + __storage_type __dn = _CUDA_VSTD::min(__n, static_cast(__clz_r)); + __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) + return false; + __first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word; + __first2.__ctz_ = static_cast((__dn + __first2.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + if ((*__first2.__seg_ & __m) != (__b >> __dn)) + return false; + } + } + } + return true; +} + +template +bool +__equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, + __bit_iterator<_Cp, _IC2> __first2) +{ + typedef __bit_iterator<_Cp, _IC1> _It; + typedef typename _It::difference_type difference_type; + typedef typename _It::__storage_type __storage_type; + static const int __bits_per_word = _It::__bits_per_word; + difference_type __n = __last1 - __first1; + if (__n > 0) + { + // do first word + if (__first1.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first1.__ctz_; + difference_type __dn = _CUDA_VSTD::min(static_cast(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) + return false; + ++__first2.__seg_; + ++__first1.__seg_; + // __first1.__ctz_ = 0; + // __first2.__ctz_ = 0; + } + // __first1.__ctz_ == 0; + // __first2.__ctz_ == 0; + // do middle words + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_) + if (*__first2.__seg_ != *__first1.__seg_) + return false; + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) + return false; + } + } + return true; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) +{ + if (__first1.__ctz_ == __first2.__ctz_) + return __equal_aligned(__first1, __last1, __first2); + return __equal_unaligned(__first1, __last1, __first2); +} + +template +class __bit_iterator +{ +public: + typedef typename _Cp::difference_type difference_type; + typedef bool value_type; + typedef __bit_iterator pointer; + typedef typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >::type reference; + typedef random_access_iterator_tag iterator_category; + +private: + typedef typename _Cp::__storage_type __storage_type; + typedef typename conditional<_IsConst, typename _Cp::__const_storage_pointer, + typename _Cp::__storage_pointer>::type __storage_pointer; + static const unsigned __bits_per_word = _Cp::__bits_per_word; + + __storage_pointer __seg_; + unsigned __ctz_; + +public: + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator() noexcept +#if _LIBCUDACXX_STD_VER > 11 + : __seg_(nullptr), __ctz_(0) +#endif + {} + // avoid re-declaring a copy constructor for the non-const version. + using __type_for_copy_to_const = + _If<_IsConst, __bit_iterator<_Cp, false>, struct __private_nat>; + + _LIBCUDACXX_INLINE_VISIBILITY + __bit_iterator(const __type_for_copy_to_const& __it) noexcept + : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {} + + _LIBCUDACXX_INLINE_VISIBILITY reference operator*() const noexcept + {return reference(__seg_, __storage_type(1) << __ctz_);} + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator& operator++() + { + if (__ctz_ != __bits_per_word-1) + ++__ctz_; + else + { + __ctz_ = 0; + ++__seg_; + } + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator operator++(int) + { + __bit_iterator __tmp = *this; + ++(*this); + return __tmp; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator& operator--() + { + if (__ctz_ != 0) + --__ctz_; + else + { + __ctz_ = __bits_per_word - 1; + --__seg_; + } + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator operator--(int) + { + __bit_iterator __tmp = *this; + --(*this); + return __tmp; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator& operator+=(difference_type __n) + { + if (__n >= 0) + __seg_ += (__n + __ctz_) / __bits_per_word; + else + __seg_ += static_cast(__n - __bits_per_word + __ctz_ + 1) + / static_cast(__bits_per_word); + __n &= (__bits_per_word - 1); + __ctz_ = static_cast((__n + __ctz_) % __bits_per_word); + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator& operator-=(difference_type __n) + { + return *this += -__n; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator operator+(difference_type __n) const + { + __bit_iterator __t(*this); + __t += __n; + return __t; + } + + _LIBCUDACXX_INLINE_VISIBILITY __bit_iterator operator-(difference_type __n) const + { + __bit_iterator __t(*this); + __t -= __n; + return __t; + } + + _LIBCUDACXX_INLINE_VISIBILITY + friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) {return __it + __n;} + + _LIBCUDACXX_INLINE_VISIBILITY + friend difference_type operator-(const __bit_iterator& __x, const __bit_iterator& __y) + {return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_;} + + _LIBCUDACXX_INLINE_VISIBILITY reference operator[](difference_type __n) const {return *(*this + __n);} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y) + {return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_;} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__x == __y);} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y) + {return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_);} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y) + {return __y < __x;} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__y < __x);} + + _LIBCUDACXX_INLINE_VISIBILITY friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__x < __y);} + +private: + _LIBCUDACXX_INLINE_VISIBILITY + __bit_iterator(__storage_pointer __s, unsigned __ctz) noexcept + : __seg_(__s), __ctz_(__ctz) {} + + friend typename _Cp::__self; + + friend class __bit_reference<_Cp>; + friend class __bit_const_reference<_Cp>; + friend class __bit_iterator<_Cp, true>; + template friend struct __bit_array; + template friend void __fill_n_false(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); + template friend void __fill_n_true(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); + template friend __bit_iterator<_Dp, false> __copy_aligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<_Dp, false> __copy_unaligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<_Dp, false> copy(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<_Dp, false> __copy_backward_aligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<_Dp, false> __copy_backward_unaligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<_Dp, false> copy_backward(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template friend __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template friend __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template friend __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>, + __bit_iterator<_Dp, false>, + __bit_iterator<_Dp, false>); + template friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC2>); + template friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC2>); + template friend bool equal(__bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC2>); + template friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>, + typename _Dp::size_type); + template friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>, + typename _Dp::size_type); + template friend typename __bit_iterator<_Dp, _IC>::difference_type + __count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); + template friend typename __bit_iterator<_Dp, _IC>::difference_type + __count_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +_LIBCUDACXX_POP_MACROS + +#endif // _LIBCUDACXX___BIT_REFERENCE diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__bsd_locale_defaults.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__bsd_locale_defaults.h new file mode 100644 index 0000000000000000000000000000000000000000..128c049b38be04b5a246a80b1d82cd3fc195329b --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__bsd_locale_defaults.h @@ -0,0 +1,40 @@ +// -*- C++ -*- +//===---------------------- __bsd_locale_defaults.h -----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// The BSDs have lots of *_l functions. We don't want to define those symbols +// on other platforms though, for fear of conflicts with user code. So here, +// we will define the mapping from an internal macro to the real BSD symbol. +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_BSD_LOCALE_DEFAULTS_H +#define _LIBCUDACXX_BSD_LOCALE_DEFAULTS_H + +#if defined(_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 + +#define __libcpp_mb_cur_max_l(loc) MB_CUR_MAX_L(loc) +#define __libcpp_btowc_l(ch, loc) btowc_l(ch, loc) +#define __libcpp_wctob_l(wch, loc) wctob_l(wch, loc) +#define __libcpp_wcsnrtombs_l(dst, src, nwc, len, ps, loc) wcsnrtombs_l(dst, src, nwc, len, ps, loc) +#define __libcpp_wcrtomb_l(src, wc, ps, loc) wcrtomb_l(src, wc, ps, loc) +#define __libcpp_mbsnrtowcs_l(dst, src, nms, len, ps, loc) mbsnrtowcs_l(dst, src, nms, len, ps, loc) +#define __libcpp_mbrtowc_l(pwc, s, n, ps, l) mbrtowc_l(pwc, s, n, ps, l) +#define __libcpp_mbtowc_l(pwc, pmb, max, l) mbtowc_l(pwc, pmb, max, l) +#define __libcpp_mbrlen_l(s, n, ps, l) mbrlen_l(s, n, ps, l) +#define __libcpp_localeconv_l(l) localeconv_l(l) +#define __libcpp_mbsrtowcs_l(dest, src, len, ps, l) mbsrtowcs_l(dest, src, len, ps, l) +#define __libcpp_snprintf_l(...) snprintf_l(__VA_ARGS__) +#define __libcpp_asprintf_l(...) asprintf_l(__VA_ARGS__) +#define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__) + +#endif // _LIBCUDACXX_BSD_LOCALE_DEFAULTS_H diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__bsd_locale_fallbacks.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__bsd_locale_fallbacks.h new file mode 100644 index 0000000000000000000000000000000000000000..a52324f0db1f86cca77f42316900a8933c1c9859 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__bsd_locale_fallbacks.h @@ -0,0 +1,143 @@ +// -*- C++ -*- +//===---------------------- __bsd_locale_fallbacks.h ----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// The BSDs have lots of *_l functions. This file provides reimplementations +// of those functions for non-BSD platforms. +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_BSD_LOCALE_FALLBACKS_DEFAULTS_H +#define _LIBCUDACXX_BSD_LOCALE_FALLBACKS_DEFAULTS_H + +#include +#include +#include + +#if defined(_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 + +inline _LIBCUDACXX_INLINE_VISIBILITY +decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return MB_CUR_MAX; +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +wint_t __libcpp_btowc_l(int __c, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return btowc(__c); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +int __libcpp_wctob_l(wint_t __c, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return wctob(__c); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc, + size_t __len, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return wcsnrtombs(__dest, __src, __nwc, __len, __ps); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return wcrtomb(__s, __wc, __ps); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms, + size_t __len, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbsnrtowcs(__dest, __src, __nms, __len, __ps); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n, + mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbrtowc(__pwc, __s, __n, __ps); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +int __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbtowc(__pwc, __pmb, __max); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbrlen(__s, __n, __ps); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +lconv *__libcpp_localeconv_l(locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return localeconv(); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len, + mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbsrtowcs(__dest, __src, __len, __ps); +} + +inline +int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); + __libcpp_locale_guard __current(__l); + int __res = vsnprintf(__s, __n, __format, __va); + va_end(__va); + return __res; +} + +inline +int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); + __libcpp_locale_guard __current(__l); + int __res = vasprintf(__s, __format, __va); + va_end(__va); + return __res; +} + +inline +int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); + __libcpp_locale_guard __current(__l); + int __res = vsscanf(__s, __format, __va); + va_end(__va); + return __res; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_BSD_LOCALE_FALLBACKS_DEFAULTS_H diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cccl/ptx_isa.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cccl/ptx_isa.h new file mode 100644 index 0000000000000000000000000000000000000000..68e218f29f44268779ace255abc6fa9a9a769382 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__cccl/version.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cccl/version.h new file mode 100644 index 0000000000000000000000000000000000000000..1c68f987f38bc93d4045786777ff5a4bc5d7a32f --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__cccl/visibility.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cccl/visibility.h new file mode 100644 index 0000000000000000000000000000000000000000..9034dbfd099723d7d1848140e9f608d93d6a4612 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__cccl_config b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cccl_config new file mode 100644 index 0000000000000000000000000000000000000000..c1d2a381a581873a48fc0471fc715439056cbbf2 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cccl_config @@ -0,0 +1,194 @@ +//===----------------------------------------------------------------------===// +// +// 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_CONFIG +#define __CCCL_CONFIG + +// Determine the host compiler +#if defined(__INTEL_LLVM_COMPILER) +# define _CCCL_COMPILER_ICC_LLVM +#elif defined(__INTEL_COMPILER) +# define _CCCL_COMPILER_ICC +#elif defined(__NVCOMPILER) +# define _CCCL_COMPILER_NVHPC +#elif defined(__clang__) +# define _CCCL_COMPILER_CLANG +#elif defined(__GNUC__) +# define _CCCL_COMPILER_GCC +#elif defined(_MSC_VER) +# define _CCCL_COMPILER_MSVC +#elif defined(__IBMCPP__) +# define _CCCL_COMPILER_IBM +#elif defined(__CUDACC_RTC__) +# define _CCCL_COMPILER_NVRTC +#endif + +// Convenient shortcut to determine which version of MSVC we are dealing with +#if defined(_CCCL_COMPILER_MSVC) +# if _MSC_VER < 1917 +# define _CCCL_COMPILER_MSVC_2017 +# elif _MSC_VER < 1930 +# define _CCCL_COMPILER_MSVC_2019 +# else // _MSC_VER < 1940 +# define _CCCL_COMPILER_MSVC_2022 +# endif // _MSC_VER < 1940 +#endif // _CCCL_COMPILER_MSVC + +// Determine the cuda compiler +#if defined(__NVCC__) +# define _CCCL_CUDA_COMPILER_NVCC +#elif defined(_NVHPC_CUDA) +# define _CCCL_CUDA_COMPILER_NVHPC +#elif defined(__CUDA__) && defined(_CCCL_COMPILER_CLANG) +# define _CCCL_CUDA_COMPILER_CLANG +#endif + +// Shorthand to check whether there is a cuda compiler available +#if defined(_CCCL_CUDA_COMPILER_NVCC) || defined(_CCCL_CUDA_COMPILER_NVHPC) || defined(_CCCL_CUDA_COMPILER_CLANG) \ + || defined(_CCCL_COMPILER_NVRTC) +# define _CCCL_CUDA_COMPILER +#endif // cuda compiler available + +// Enforce that cccl headers are treated as system headers +#if defined(_CCCL_COMPILER_GCC) || defined(_CCCL_COMPILER_NVHPC) || defined(_CCCL_COMPILER_ICC) \ + || defined(_CCCL_COMPILER_ICC_LLVM) +# define _CCCL_FORCE_SYSTEM_HEADER_GCC +#elif defined(_CCCL_COMPILER_CLANG) +# define _CCCL_FORCE_SYSTEM_HEADER_CLANG +#elif defined(_CCCL_COMPILER_MSVC) +# define _CCCL_FORCE_SYSTEM_HEADER_MSVC +#endif // other compilers + +// Potentially enable that cccl headers are treated as system headers +#if !defined(_CCCL_NO_SYSTEM_HEADER) \ + && !(defined(_CCCL_COMPILER_MSVC) && defined(_LIBCUDACXX_DISABLE_PRAGMA_MSVC_WARNING)) \ + && !defined(_CCCL_COMPILER_NVRTC) && !defined(_LIBCUDACXX_DISABLE_PRAGMA_GCC_SYSTEM_HEADER) +# if defined(_CCCL_COMPILER_GCC) || defined(_CCCL_COMPILER_NVHPC) || defined(_CCCL_COMPILER_ICC) \ + || defined(_CCCL_COMPILER_ICC_LLVM) +# define _CCCL_IMPLICIT_SYSTEM_HEADER_GCC +# elif defined(_CCCL_COMPILER_CLANG) +# define _CCCL_IMPLICIT_SYSTEM_HEADER_CLANG +# elif defined(_CCCL_COMPILER_MSVC) +# define _CCCL_IMPLICIT_SYSTEM_HEADER_MSVC +# endif // other compilers +#endif // Use system header + +// Potentially silence all warnings from this header +#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 + +// Enable us to selectively silence host compiler warnings +#define _CCCL_TOSTRING2(_STR) #_STR +#define _CCCL_TOSTRING(_STR) _CCCL_TOSTRING2(_STR) +#ifdef _CCCL_COMPILER_CLANG +# define _CCCL_DIAG_PUSH _Pragma("clang diagnostic push") +# define _CCCL_DIAG_POP _Pragma("clang diagnostic pop") +# define _CCCL_DIAG_SUPPRESS_CLANG(str) _Pragma(_CCCL_TOSTRING(clang diagnostic ignored str)) +# define _CCCL_DIAG_SUPPRESS_GCC(str) +# define _CCCL_DIAG_SUPPRESS_NVHPC(str) +# define _CCCL_DIAG_SUPPRESS_MSVC(str) +#elif defined(_CCCL_COMPILER_GCC) +# define _CCCL_DIAG_PUSH _Pragma("GCC diagnostic push") +# define _CCCL_DIAG_POP _Pragma("GCC diagnostic pop") +# define _CCCL_DIAG_SUPPRESS_CLANG(str) +# define _CCCL_DIAG_SUPPRESS_GCC(str) _Pragma(_CCCL_TOSTRING(GCC diagnostic ignored str)) +# define _CCCL_DIAG_SUPPRESS_NVHPC(str) +# define _CCCL_DIAG_SUPPRESS_MSVC(str) +#elif defined(_CCCL_COMPILER_NVHPC) +# define _CCCL_DIAG_PUSH _Pragma("diagnostic push") +# define _CCCL_DIAG_POP _Pragma("diagnostic pop") +# define _CCCL_DIAG_SUPPRESS_CLANG(str) +# define _CCCL_DIAG_SUPPRESS_GCC(str) +# define _CCCL_DIAG_SUPPRESS_NVHPC(str) _Pragma(_CCCL_TOSTRING(diag_suppress str)) +# define _CCCL_DIAG_SUPPRESS_MSVC(str) +#elif defined(_CCCL_COMPILER_MSVC) +# define _CCCL_DIAG_PUSH __pragma(warning(push)) +# define _CCCL_DIAG_POP __pragma(warning(pop)) +# define _CCCL_DIAG_SUPPRESS_CLANG(str) +# define _CCCL_DIAG_SUPPRESS_GCC(str) +# define _CCCL_DIAG_SUPPRESS_NVHPC(str) +# define _CCCL_DIAG_SUPPRESS_MSVC(str) __pragma(warning(disable : str)) +#else +# define _CCCL_DIAG_PUSH +# define _CCCL_DIAG_POP +# define _CCCL_DIAG_SUPPRESS_CLANG(str) +# define _CCCL_DIAG_SUPPRESS_GCC(str) +# define _CCCL_DIAG_SUPPRESS_NVHPC(str) +# define _CCCL_DIAG_SUPPRESS_MSVC(str) +#endif + +// Convenient shortcuts to silence common warnings +#if defined(_CCCL_COMPILER_CLANG) +# define _CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH \ + _CCCL_DIAG_PUSH \ + _CCCL_DIAG_SUPPRESS_CLANG("-Wdeprecated") \ + _CCCL_DIAG_SUPPRESS_CLANG("-Wdeprecated-declarations") +# define _CCCL_DIAG_SUPPRESS_DEPRECATED_POP _CCCL_DIAG_POP +#elif defined(_CCCL_COMPILER_GCC) +# define _CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH \ + _CCCL_DIAG_PUSH \ + _CCCL_DIAG_SUPPRESS_GCC("-Wdeprecated") \ + _CCCL_DIAG_SUPPRESS_GCC("-Wdeprecated-declarations") +# define _CCCL_DIAG_SUPPRESS_DEPRECATED_POP _CCCL_DIAG_POP +#elif defined(_CCCL_COMPILER_MSVC) +# define _CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH \ + _CCCL_DIAG_PUSH \ + _CCCL_DIAG_SUPPRESS_MSVC(4996) +# define _CCCL_DIAG_SUPPRESS_DEPRECATED_POP _CCCL_DIAG_POP +#else // !_CCCL_COMPILER_CLANG && !_CCCL_COMPILER_GCC +# define _CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH +# define _CCCL_DIAG_SUPPRESS_DEPRECATED_POP +#endif // !_CCCL_COMPILER_CLANG && !_CCCL_COMPILER_GCC + +// Enable us to selectively silence cuda compiler warnings +#if defined(__CUDACC__) +# if !defined(_CCCL_CUDA_COMPILER_CLANG) +# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) +# define _CCCL_NV_DIAG_DEFAULT(_WARNING) +# elif defined(__NVCC_DIAG_PRAGMA_SUPPORT__) +# if defined(_CCCL_COMPILER_MSVC) +# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) __pragma(_CCCL_TOSTRING(nv_diag_suppress _WARNING)) +# define _CCCL_NV_DIAG_DEFAULT(_WARNING) __pragma(_CCCL_TOSTRING(nv_diag_default _WARNING)) +# else // ^^^ _CCCL_COMPILER_MSVC ^^^ / vvv !_CCCL_COMPILER_MSVC vvv +# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) \ + _Pragma(_CCCL_TOSTRING(nv_diagnostic push)) _Pragma(_CCCL_TOSTRING(nv_diag_suppress _WARNING)) +# define _CCCL_NV_DIAG_DEFAULT(_WARNING) _Pragma(_CCCL_TOSTRING(nv_diagnostic pop)) +# endif // !_CCCL_COMPILER_MSVC +# elif defined(_CCCL_COMPILER_NVHPC) +# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) \ + _Pragma(_CCCL_TOSTRING(diagnostic push)) _Pragma(_CCCL_TOSTRING(diag_suppress _WARNING)) +# define _CCCL_NV_DIAG_DEFAULT(_WARNING) _Pragma(_CCCL_TOSTRING(diagnostic pop)) +# else // ^^^ __NVCC_DIAG_PRAGMA_SUPPORT__ ^^^ / vvv !__NVCC_DIAG_PRAGMA_SUPPORT__ vvv +# if defined(_CCCL_COMPILER_MSVC_2017) // MSVC 2017 has issues with restoring the warning +# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) __pragma(_CCCL_TOSTRING(diag_suppress _WARNING)) +# define _CCCL_NV_DIAG_DEFAULT(_WARNING) +# elif defined(_CCCL_COMPILER_MSVC) +# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) __pragma(_CCCL_TOSTRING(diag_suppress _WARNING)) +# define _CCCL_NV_DIAG_DEFAULT(_WARNING) __pragma(_CCCL_TOSTRING(diag_default _WARNING)) +# else // ^^^ _CCCL_COMPILER_MSVC ^^^ / vvv !_CCCL_COMPILER_MSVC vvv +# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) _Pragma(_CCCL_TOSTRING(diag_suppress _WARNING)) +# define _CCCL_NV_DIAG_DEFAULT(_WARNING) _Pragma(_CCCL_TOSTRING(diag_default _WARNING)) +# endif // !_CCCL_COMPILER_MSVC +# endif // !__NVCC_DIAG_PRAGMA_SUPPORT__ +#else // ^^^ __CUDACC__ ^^^ / vvv !__CUDACC__ vvv +# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) +# define _CCCL_NV_DIAG_DEFAULT(_WARNING) +#endif // other compilers + +#include "__cccl/ptx_isa.h" +#include "__cccl/version.h" +#include "__cccl/visibility.h" + +#endif // __CCCL_CONFIG diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/_One_of.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/_One_of.h new file mode 100644 index 0000000000000000000000000000000000000000..5e4d138959524e09e7f6b0b84157a786b33a782d --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/__concept_macros.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/__concept_macros.h new file mode 100644 index 0000000000000000000000000000000000000000..93375b7b3cebf9b4854e075b9a23b75122dff24f --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/__concept_macros.h @@ -0,0 +1,299 @@ +//===----------------------------------------------------------------------===// +// +// Copyright (c) Facebook, Inc. and its affiliates. +// Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA___CONCEPTS +#define _CUDA___CONCEPTS + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#if 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/cuda/std/detail/libcxx/include/__concepts/arithmetic.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/arithmetic.h new file mode 100644 index 0000000000000000000000000000000000000000..5808d7d1dbbe827690de012beb7fa876613dfcc1 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/assignable.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/assignable.h new file mode 100644 index 0000000000000000000000000000000000000000..3d9522466c2617eadeb729ca2cfb2bc48dec391e --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/boolean_testable.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/boolean_testable.h new file mode 100644 index 0000000000000000000000000000000000000000..4a6c97a17ea6f3cbcb5d555e0ddb6df8da67c5f9 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/class_or_enum.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/class_or_enum.h new file mode 100644 index 0000000000000000000000000000000000000000..df59bd78dd424dd077e34b55592a3aa01764a727 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/common_reference_with.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/common_reference_with.h new file mode 100644 index 0000000000000000000000000000000000000000..b54e78be12c84c25b5eb37417b4af86dfaa74978 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/common_with.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/common_with.h new file mode 100644 index 0000000000000000000000000000000000000000..8fb9fcb79631b5f48b7d7558251cdd4ff526e7ce --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/constructible.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/constructible.h new file mode 100644 index 0000000000000000000000000000000000000000..c338467d85763cad37d67bae9da7299402e44b51 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/convertible_to.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/convertible_to.h new file mode 100644 index 0000000000000000000000000000000000000000..5ac5f4cc42c992e50cd5083b9b3e94391475cd6e --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/copyable.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/copyable.h new file mode 100644 index 0000000000000000000000000000000000000000..8a4b6dede369d3c406b6e258c7fdde058040b0be --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/derived_from.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/derived_from.h new file mode 100644 index 0000000000000000000000000000000000000000..0075ae97c4eeed6782a14aff7d92610007b432a1 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/destructible.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/destructible.h new file mode 100644 index 0000000000000000000000000000000000000000..2bb831945d725b1baf5f4513fc5a0994caa4cc99 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/different_from.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/different_from.h new file mode 100644 index 0000000000000000000000000000000000000000..f157d3c7119d37a6b0f5e6310c612bef90d2cdfa --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/equality_comparable.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/equality_comparable.h new file mode 100644 index 0000000000000000000000000000000000000000..c2b9d1166cdb4cd04fabf3f2f5baed5057209e28 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/invocable.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/invocable.h new file mode 100644 index 0000000000000000000000000000000000000000..33ad53c07047554ede93e6c7e0813e4b747fef2c --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/movable.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/movable.h new file mode 100644 index 0000000000000000000000000000000000000000..233af6d63ba0ae3db62870eb067ba424a259bb74 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/predicate.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/predicate.h new file mode 100644 index 0000000000000000000000000000000000000000..f3b54c313be97178708986359187da755bfcfcde --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/regular.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/regular.h new file mode 100644 index 0000000000000000000000000000000000000000..e3dbf1fd83767050edf2e3e580ba98e31a9daabf --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/relation.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/relation.h new file mode 100644 index 0000000000000000000000000000000000000000..8a5da7ad81a09c8298fc0e07b33d7e4be883cf45 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/same_as.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/same_as.h new file mode 100644 index 0000000000000000000000000000000000000000..0ba84b5cbe67ecf4bd5da73b884bccac0e502830 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/semiregular.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/semiregular.h new file mode 100644 index 0000000000000000000000000000000000000000..208fefeb6382cc1395bc7c75f6e308743a466b79 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/swappable.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/swappable.h new file mode 100644 index 0000000000000000000000000000000000000000..b2a93adf471f740ccfe315b07238d4000e580c91 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__concepts/totally_ordered.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__concepts/totally_ordered.h new file mode 100644 index 0000000000000000000000000000000000000000..9b9a2815d11ee8ade82612f03582609d0a74627e --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/std/detail/libcxx/include/__config b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__config new file mode 100644 index 0000000000000000000000000000000000000000..7c04dc13eec71d441aa4a28a3cb3b9d40db3f3b5 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__config @@ -0,0 +1,2250 @@ +// -*- C++ -*- +//===--------------------------- __config ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_CONFIG +#define _LIBCUDACXX_CONFIG + +#include "__cccl_config" + +#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(__INTEL_LLVM_COMPILER) +# define _LIBCUDACXX_COMPILER_ICC_LLVM +#elif defined(__INTEL_COMPILER) +# define _LIBCUDACXX_COMPILER_ICC +#elif defined(__NVCOMPILER) +# define _LIBCUDACXX_COMPILER_NVHPC +#elif defined(__clang__) +# define _LIBCUDACXX_COMPILER_CLANG +# ifndef __apple_build_version__ +# define _LIBCUDACXX_CLANG_VER (__clang_major__ * 100 + __clang_minor__) +# endif +#elif defined(__GNUC__) +# define _LIBCUDACXX_COMPILER_GCC +#elif defined(_MSC_VER) +# define _LIBCUDACXX_COMPILER_MSVC +#elif defined(__IBMCPP__) +# define _LIBCUDACXX_COMPILER_IBM +#elif defined(__CUDACC_RTC__) +# define _LIBCUDACXX_COMPILER_NVRTC +#endif + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +#if _MSC_VER < 1917 +#define _LIBCUDACXX_COMPILER_MSVC_2017 +#elif _MSC_VER < 1930 +#define _LIBCUDACXX_COMPILER_MSVC_2019 +#else +#define _LIBCUDACXX_COMPILER_MSVC_2022 +#endif +#endif // defined(_LIBCUDACXX_COMPILER_MSVC) + +#if defined(__NVCC__) +// This is not mutually exclusive with other compilers, as NVCC uses a host +// compiler. +# define _LIBCUDACXX_COMPILER_NVCC +#elif defined(_NVHPC_CUDA) +# define _LIBCUDACXX_COMPILER_NVHPC_CUDA +#elif defined(__CUDA__) && defined(_LIBCUDACXX_COMPILER_CLANG) +# define _LIBCUDACXX_COMPILER_CLANG_CUDA +#endif + +#ifdef __CUDACC__ +# define _LIBCUDACXX_CUDACC +# define _LIBCUDACXX_CUDACC_VER_MAJOR __CUDACC_VER_MAJOR__ +# define _LIBCUDACXX_CUDACC_VER_MINOR __CUDACC_VER_MINOR__ +# define _LIBCUDACXX_CUDACC_VER_BUILD __CUDACC_VER_BUILD__ +# define _LIBCUDACXX_CUDACC_VER \ + _LIBCUDACXX_CUDACC_VER_MAJOR * 100000 + _LIBCUDACXX_CUDACC_VER_MINOR * 1000 + \ + _LIBCUDACXX_CUDACC_VER_BUILD + +// TODO: Determine if this is necessary, I don't know why we automatically include this in +# if defined(__clang__) || defined(__FLT16_MANT_DIG__) +# include +# endif +#endif + +// Some convenience macros to filter CUDACC versions +#if defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1102000 +#define _LIBCUDACXX_CUDACC_BELOW_11_2 +#endif // defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1102000 +#if defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1103000 +#define _LIBCUDACXX_CUDACC_BELOW_11_3 +#endif // defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1103000 +#if defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1108000 +#define _LIBCUDACXX_CUDACC_BELOW_11_8 +#endif // defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1108000 +#if defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1203000 +#define _LIBCUDACXX_CUDACC_BELOW_12_3 +#endif // defined(_LIBCUDACXX_CUDACC) && _LIBCUDACXX_CUDACC_VER < 1203000 + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_HAS_PRAGMA_MSVC_WARNING +# if !defined(_LIBCUDACXX_DISABLE_PRAGMA_MSVC_WARNING) +# define _LIBCUDACXX_USE_PRAGMA_MSVC_WARNING +# endif // !_LIBCUDACXX_DISABLE_PRAGMA_MSVC_WARNING +#endif // _LIBCUDACXX_COMPILER_MSVC + +#ifdef __cplusplus + +// __config may be included in `extern "C"` contexts, switch back to include +extern "C++" { +#include +} + +#ifdef __GNUC__ +# define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__) +#else +# define _GNUC_VER 0 +#endif + +#define _LIBCUDACXX_VERSION 10000 + +#ifndef _LIBCUDACXX_ABI_VERSION +# define _LIBCUDACXX_ABI_VERSION 1 +#endif + +#ifndef _LIBCUDACXX_STD_VER +# if defined(_MSC_VER) +# if _MSVC_LANG <= 201103L +# define _LIBCUDACXX_STD_VER 11 +# elif _MSVC_LANG <= 201402L +# define _LIBCUDACXX_STD_VER 14 +# elif _MSVC_LANG <= 201703L +# define _LIBCUDACXX_STD_VER 17 +# elif _MSVC_LANG <= 202002L +# define _LIBCUDACXX_STD_VER 20 +# else +# define _LIBCUDACXX_STD_VER 23 // current year, or date of c++2b ratification +# endif +# else +# if __cplusplus <= 201103L +# define _LIBCUDACXX_STD_VER 11 +# elif __cplusplus <= 201402L +# define _LIBCUDACXX_STD_VER 14 +# elif __cplusplus <= 201703L +# define _LIBCUDACXX_STD_VER 17 +# elif __cplusplus <= 202002L +# define _LIBCUDACXX_STD_VER 20 +# else +# define _LIBCUDACXX_STD_VER 23 // current year, or date of c++2b ratification +# endif +# endif +#endif // _LIBCUDACXX_STD_VER + +#if _LIBCUDACXX_STD_VER < 11 +# error libcu++ requires C++11 or later +#endif + +#if (defined(_LIBCUDACXX_COMPILER_NVHPC) && defined(__linux__)) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) + #define __ELF__ +#endif + +#if defined(__ELF__) +# define _LIBCUDACXX_OBJECT_FORMAT_ELF 1 +#elif defined(__MACH__) +# define _LIBCUDACXX_OBJECT_FORMAT_MACHO 1 +#elif defined(_WIN32) +# define _LIBCUDACXX_OBJECT_FORMAT_COFF 1 +#elif defined(__wasm__) +# define _LIBCUDACXX_OBJECT_FORMAT_WASM 1 +#else +# error Unknown object file format +#endif + +#if defined(_LIBCUDACXX_ABI_UNSTABLE) || _LIBCUDACXX_ABI_VERSION >= 2 || defined(__cuda_std__) +// Change short string representation so that string data starts at offset 0, +// improving its alignment in some cases. +# define _LIBCUDACXX_ABI_ALTERNATE_STRING_LAYOUT +// Fix deque iterator type in order to support incomplete types. +# define _LIBCUDACXX_ABI_INCOMPLETE_TYPES_IN_DEQUE +// Fix undefined behavior in how std::list stores its linked nodes. +# define _LIBCUDACXX_ABI_LIST_REMOVE_NODE_POINTER_UB +// Fix undefined behavior in how __tree stores its end and parent nodes. +# define _LIBCUDACXX_ABI_TREE_REMOVE_NODE_POINTER_UB +// Fix undefined behavior in how __hash_table stores its pointer types. +# define _LIBCUDACXX_ABI_FIX_UNORDERED_NODE_POINTER_UB +# define _LIBCUDACXX_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB +# define _LIBCUDACXX_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE +// Don't use a nullptr_t simulation type in C++03 instead using C++11 nullptr +// provided under the alternate keyword __nullptr, which changes the mangling +// of nullptr_t. This option is ABI incompatible with GCC in C++03 mode. +# define _LIBCUDACXX_ABI_ALWAYS_USE_CXX11_NULLPTR +// Define the `pointer_safety` enum as a C++11 strongly typed enumeration +// instead of as a class simulating an enum. If this option is enabled +// `pointer_safety` and `get_pointer_safety()` will no longer be available +// in C++03. +# define _LIBCUDACXX_ABI_POINTER_SAFETY_ENUM_TYPE +// Define a key function for `bad_function_call` in the library, to centralize +// its vtable and typeinfo to libc++ rather than having all other libraries +// using that class define their own copies. +# define _LIBCUDACXX_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION +// Enable optimized version of __do_get_(un)signed which avoids redundant copies. +# define _LIBCUDACXX_ABI_OPTIMIZED_LOCALE_NUM_GET +// Use the smallest possible integer type to represent the index of the variant. +// Previously libc++ used "unsigned int" exclusively. +# define _LIBCUDACXX_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION +// Unstable attempt to provide a more optimized std::function +# define _LIBCUDACXX_ABI_OPTIMIZED_FUNCTION +// All the regex constants must be distinct and nonzero. +# define _LIBCUDACXX_ABI_REGEX_CONSTANTS_NONZERO +#elif _LIBCUDACXX_ABI_VERSION == 1 +# if !defined(_LIBCUDACXX_OBJECT_FORMAT_COFF) +// Enable compiling copies of now inline methods into the dylib to support +// applications compiled against older libraries. This is unnecessary with +// COFF dllexport semantics, since dllexport forces a non-inline definition +// of inline functions to be emitted anyway. Our own non-inline copy would +// conflict with the dllexport-emitted copy, so we disable it. +# define _LIBCUDACXX_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS +# endif +#endif + +#ifndef __has_attribute +#define __has_attribute(__x) 0 +#endif + +#ifndef __has_builtin +#define __has_builtin(__x) 0 +#endif + +#ifndef __has_extension +#define __has_extension(__x) 0 +#endif + +#ifndef __has_feature +#define __has_feature(__x) 0 +#endif + +#ifndef __has_cpp_attribute +#define __has_cpp_attribute(__x) 0 +#endif + +// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by +// the compiler and '1' otherwise. +#ifndef __is_identifier +#define __is_identifier(__x) 1 +#endif + +#ifndef __has_declspec_attribute +#define __has_declspec_attribute(__x) 0 +#endif + +#define __has_keyword(__x) !(__is_identifier(__x)) + +#ifndef __has_include +#define __has_include(...) 0 +#endif + +#if !defined(_LIBCUDACXX_COMPILER_NVCC) && !defined(_LIBCUDACXX_COMPILER_NVRTC) +// If NVCC is not being used can safely use `long double` without warnings +# define _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE +// NVCC does not have a way of silencing non '_' prefixed UDLs +# define _LIBCUDACXX_HAS_STL_LITERALS +#endif + +#if defined(_LIBCUDACXX_COMPILER_GCC) && __cplusplus < 201103L +#error "libc++ does not support using GCC with C++03. Please enable C++11" +#endif + +// FIXME: ABI detection should be done via compiler builtin macros. This +// is just a placeholder until Clang implements such macros. For now assume +// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, +// and allow the user to explicitly specify the ABI to handle cases where this +// heuristic falls short. +#if defined(_LIBCUDACXX_ABI_FORCE_ITANIUM) && defined(_LIBCUDACXX_ABI_FORCE_MICROSOFT) +# error "Only one of _LIBCUDACXX_ABI_FORCE_ITANIUM and _LIBCUDACXX_ABI_FORCE_MICROSOFT can be defined" +#elif defined(_LIBCUDACXX_ABI_FORCE_ITANIUM) +# define _LIBCUDACXX_ABI_ITANIUM +#elif defined(_LIBCUDACXX_ABI_FORCE_MICROSOFT) +# define _LIBCUDACXX_ABI_MICROSOFT +#else +# if defined(_WIN32) && defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_ABI_MICROSOFT +# else +# define _LIBCUDACXX_ABI_ITANIUM +# endif +#endif + +#if defined(_LIBCUDACXX_ABI_MICROSOFT) && !defined(_LIBCUDACXX_NO_VCRUNTIME) +# define _LIBCUDACXX_ABI_VCRUNTIME +#endif + +// Need to detect which libc we're using if we're on Linux. +#if defined(__linux__) +# include +# if defined(__GLIBC_PREREQ) +# define _LIBCUDACXX_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) +# else +# define _LIBCUDACXX_GLIBC_PREREQ(a, b) 0 +# endif // defined(__GLIBC_PREREQ) +#endif // defined(__linux__) + +#ifdef __LITTLE_ENDIAN__ +# if __LITTLE_ENDIAN__ +# define _LIBCUDACXX_LITTLE_ENDIAN +# endif // __LITTLE_ENDIAN__ +#endif // __LITTLE_ENDIAN__ + +#ifdef __BIG_ENDIAN__ +# if __BIG_ENDIAN__ +# define _LIBCUDACXX_BIG_ENDIAN +# endif // __BIG_ENDIAN__ +#endif // __BIG_ENDIAN__ + +#ifdef __BYTE_ORDER__ +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define _LIBCUDACXX_LITTLE_ENDIAN +# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define _LIBCUDACXX_BIG_ENDIAN +# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#endif // __BYTE_ORDER__ + +#ifdef __FreeBSD__ +# include +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCUDACXX_LITTLE_ENDIAN +# else // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCUDACXX_BIG_ENDIAN +# endif // _BYTE_ORDER == _LITTLE_ENDIAN +# ifndef __LONG_LONG_SUPPORTED +# define _LIBCUDACXX_HAS_NO_LONG_LONG +# endif // __LONG_LONG_SUPPORTED +#endif // __FreeBSD__ + +#ifdef __NetBSD__ +# include +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCUDACXX_LITTLE_ENDIAN +# else // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCUDACXX_BIG_ENDIAN +# endif // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCUDACXX_HAS_QUICK_EXIT +#endif // __NetBSD__ + +#if defined(_WIN32) +# define _LIBCUDACXX_WIN32API +# define _LIBCUDACXX_LITTLE_ENDIAN +# define _LIBCUDACXX_SHORT_WCHAR 1 +// Both MinGW and native MSVC provide a "MSVC"-like environment +# define _LIBCUDACXX_MSVCRT_LIKE +// If mingw not explicitly detected, assume using MS C runtime only if +// a MS compatibility version is specified. +# if defined(_LIBCUDACXX_COMPILER_MSVC) && !defined(__MINGW32__) +# define _LIBCUDACXX_MSVCRT // Using Microsoft's C Runtime library +# endif +# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) +# define _LIBCUDACXX_HAS_BITSCAN64 +# endif +# define _LIBCUDACXX_HAS_OPEN_WITH_WCHAR +# if defined(_LIBCUDACXX_MSVCRT) +# define _LIBCUDACXX_HAS_QUICK_EXIT +# endif + +// Some CRT APIs are unavailable to store apps +# if defined(WINAPI_FAMILY) +# include +# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && \ + (!defined(WINAPI_PARTITION_SYSTEM) || \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM)) +# define _LIBCUDACXX_WINDOWS_STORE_APP +# endif +# endif +#endif // defined(_WIN32) + +#ifdef __sun__ +# include +# ifdef _LITTLE_ENDIAN +# define _LIBCUDACXX_LITTLE_ENDIAN +# else +# define _LIBCUDACXX_BIG_ENDIAN +# endif +#endif // __sun__ + +#if defined(__CloudABI__) + // Certain architectures provide arc4random(). Prefer using + // arc4random() over /dev/{u,}random to make it possible to obtain + // random data even when using sandboxing mechanisms such as chroots, + // Capsicum, etc. +# define _LIBCUDACXX_USING_ARC4_RANDOM +#elif defined(__Fuchsia__) || defined(__wasi__) +# define _LIBCUDACXX_USING_GETENTROPY +#elif defined(__native_client__) + // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, + // including accesses to the special files under /dev. C++11's + // std::random_device is instead exposed through a NaCl syscall. +# define _LIBCUDACXX_USING_NACL_RANDOM +#elif defined(_LIBCUDACXX_WIN32API) +# define _LIBCUDACXX_USING_WIN32_RANDOM +#else +# define _LIBCUDACXX_USING_DEV_RANDOM +#endif + +#ifndef _LIBCUDACXX_LITTLE_ENDIAN +#if defined(_LIBCUDACXX_COMPILER_NVRTC) +# define _LIBCUDACXX_LITTLE_ENDIAN +#endif +#endif // _LIBCUDACXX_LITTLE_ENDIAN + +#if !defined(_LIBCUDACXX_LITTLE_ENDIAN) && !defined(_LIBCUDACXX_BIG_ENDIAN) +# include +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define _LIBCUDACXX_LITTLE_ENDIAN +# elif __BYTE_ORDER == __BIG_ENDIAN +# define _LIBCUDACXX_BIG_ENDIAN +# else // __BYTE_ORDER == __BIG_ENDIAN +# error unable to determine endian +# endif +#endif // !defined(_LIBCUDACXX_LITTLE_ENDIAN) && !defined(_LIBCUDACXX_BIG_ENDIAN) + +#if __has_attribute(__no_sanitize__) && !defined(_LIBCUDACXX_COMPILER_GCC) +# define _LIBCUDACXX_NO_CFI __attribute__((__no_sanitize__("cfi"))) +#else +# define _LIBCUDACXX_NO_CFI +#endif + +#if (defined(__ISO_C_VISIBLE) && __ISO_C_VISIBLE >= 2011) || __cplusplus >= 201103L +# if defined(__FreeBSD__) +# define _LIBCUDACXX_HAS_QUICK_EXIT +# define _LIBCUDACXX_HAS_C11_FEATURES +# elif defined(__Fuchsia__) || defined(__wasi__) +# define _LIBCUDACXX_HAS_QUICK_EXIT +# define _LIBCUDACXX_HAS_TIMESPEC_GET +# define _LIBCUDACXX_HAS_C11_FEATURES +# elif defined(__linux__) +# if !defined(_LIBCUDACXX_HAS_MUSL_LIBC) +# if _LIBCUDACXX_GLIBC_PREREQ(2, 15) || defined(__BIONIC__) +# define _LIBCUDACXX_HAS_QUICK_EXIT +# endif +# if _LIBCUDACXX_GLIBC_PREREQ(2, 17) +# define _LIBCUDACXX_HAS_C11_FEATURES +# define _LIBCUDACXX_HAS_TIMESPEC_GET +# endif +# else // defined(_LIBCUDACXX_HAS_MUSL_LIBC) +# define _LIBCUDACXX_HAS_QUICK_EXIT +# define _LIBCUDACXX_HAS_TIMESPEC_GET +# define _LIBCUDACXX_HAS_C11_FEATURES +# endif +# endif // __linux__ +#endif + +#if defined(_LIBCUDACXX_COMPILER_NVRTC) +# define __alignof(x) alignof(x) +#endif // _LIBCUDACXX_COMPILER_NVRTC + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +# define __alignof__ __alignof +#endif + +#define _LIBCUDACXX_ALIGNOF(_Tp) alignof(_Tp) +#define _LIBCUDACXX_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _ALIGNAS_TYPE(x) alignas(x) +# define _ALIGNAS(x) __declspec(align(x)) +#elif __has_feature(cxx_alignas) +# define _ALIGNAS_TYPE(x) alignas(x) +# define _ALIGNAS(x) alignas(x) +#else +# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCUDACXX_ALIGNOF(x)))) +# define _ALIGNAS(x) __attribute__((__aligned__(x))) +#endif // !_LIBCUDACXX_COMPILER_MSVC && !__has_feature(cxx_alignas) + +// This is wrapped in __CUDA_ARCH__ to prevent error: "ignoring '#pragma unroll' +// [-Werror=unknown-pragmas]" +#if defined(__CUDA_ARCH__) +#if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_PRAGMA_UNROLL(_N) __pragma(_LIBCUDACXX_TOSTRING(unroll _N)) +#else // ^^^ _LIBCUDACXX_COMPILER_MSVC ^^^ / vvv !_LIBCUDACXX_COMPILER_MSVC vvv +# define _LIBCUDACXX_PRAGMA_UNROLL(_N) _Pragma(_LIBCUDACXX_TOSTRING(unroll _N)) +#endif // !_LIBCUDACXX_COMPILER_MSVC +#else // ^^^ _LIBCUDACXX_CUDACC ^^^ / vvv !_LIBCUDACXX_CUDACCvvv +# define _LIBCUDACXX_PRAGMA_UNROLL(_N) +#endif // !__CUDA_ARCH__ + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +#define _LIBCUDACXX_ALWAYS_INLINE __forceinline +#else +#define _LIBCUDACXX_ALWAYS_INLINE __attribute__ ((__always_inline__)) +#endif // !_LIBCUDACXX_COMPILER_MSVC + +#if defined(__cuda_std__) +#define _LIBCUDACXX_ATOMIC_ALWAYS_LOCK_FREE(size, ptr) (size <= 8) +#elif defined(_LIBCUDACXX_COMPILER_CLANG) || defined(_LIBCUDACXX_COMPILER_GCC) +#define _LIBCUDACXX_ATOMIC_ALWAYS_LOCK_FREE(...) __atomic_always_lock_free(__VA_ARGS__) +#endif // __cuda_std__ + +// https://bugs.llvm.org/show_bug.cgi?id=44517 +#define __check_builtin(__x) (__has_builtin(__##__x) || \ + __has_keyword(__##__x) || \ + __has_feature(__x)) + +// We work around old clang versions (before clang-10) not supporting __has_builtin via __check_builtin +// We work around old intel versions (before 2021.3) not supporting __has_builtin via __check_builtin +// We work around old nvhpc versions (before 2022.11) not supporting __has_builtin via __check_builtin +// MSVC needs manual handling, has no real way of checking builtins so all is manual +// GCC needs manual handling, before gcc-10 as that finally supports __has_builtin + +#if __check_builtin(array_rank) +#define _LIBCUDACXX_ARRAY_RANK(...) __array_rank(__VA_ARGS__) +#endif // __check_builtin(array_rank) + +// nvhpc has a bug where it supports __builtin_addressof but does not mark it via __check_builtin +#if __check_builtin(builtin_addressof) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 700) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVHPC) +#define _LIBCUDACXX_ADDRESSOF(...) __builtin_addressof(__VA_ARGS__) +#endif // __check_builtin(builtin_addressof) + +#if __check_builtin(builtin_bit_cast) \ + || (defined(_LIBCUDACXX_COMPILER_MSVC) && _MSC_VER > 1925) +#define _LIBCUDACXX_BIT_CAST(...) __builtin_bit_cast(__VA_ARGS__) +#endif // __check_builtin(builtin_bit_cast) + +#if __check_builtin(builtin_is_constant_evaluated) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 900) \ + || (defined(_LIBCUDACXX_COMPILER_MSVC) && _MSC_VER > 1924 && !defined(_LIBCUDACXX_CUDACC_BELOW_11_3)) +#define _LIBCUDACXX_IS_CONSTANT_EVALUATED(...) __builtin_is_constant_evaluated(__VA_ARGS__) +#endif // __check_builtin(builtin_is_constant_evaluated) + +// NVCC and NVRTC in C++11 mode freaks out about `__builtin_is_constant_evaluated`. +#if _LIBCUDACXX_STD_VER < 14 \ + && (defined(_LIBCUDACXX_COMPILER_NVCC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || defined(_LIBCUDACXX_COMPILER_NVHPC)) +#undef _LIBCUDACXX_IS_CONSTANT_EVALUATED +#endif // _LIBCUDACXX_STD_VER < 14 && defined(_LIBCUDACXX_COMPILER_NVCC) + +#if __check_builtin(builtin_launder) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 700) +#define _LIBCUDACXX_LAUNDER(...) __builtin_launder(__VA_ARGS__) +#endif // __check_builtin(builtin_launder) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(decay) +#define _LIBCUDACXX_DECAY(...) __decay(__VA_ARGS__) +#endif // __check_builtin(decay) + +#if __check_builtin(has_nothrow_assign) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_NOTHROW_ASSIGN(...) __has_nothrow_assign(__VA_ARGS__) +#endif // __check_builtin(has_nothrow_assign) + +#if __check_builtin(has_nothrow_constructor) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_NOTHROW_CONSTRUCTOR(...) __has_nothrow_constructor(__VA_ARGS__) +#endif // __check_builtin(has_nothrow_constructor) + +#if __check_builtin(has_nothrow_copy) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_NOTHROW_COPY(...) __has_nothrow_copy(__VA_ARGS__) +#endif // __check_builtin(has_nothrow_copy) + +#if __check_builtin(has_trivial_constructor) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_TRIVIAL_CONSTRUCTOR(...) __has_trivial_constructor(__VA_ARGS__) +#endif // __check_builtin(has_trivial_constructor) + +#if __check_builtin(has_trivial_destructor) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_TRIVIAL_DESTRUCTOR(...) __has_trivial_destructor(__VA_ARGS__) +#endif // __check_builtin(has_trivial_destructor) + +#if __check_builtin(has_unique_object_representations) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 700) +#define _LIBCUDACXX_HAS_UNIQUE_OBJECT_REPRESENTATIONS(...) __has_unique_object_representations(__VA_ARGS__) +#endif // __check_builtin(has_unique_object_representations) + +#if __check_builtin(has_virtual_destructor) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_HAS_VIRTUAL_DESTRUCTOR(...) __has_virtual_destructor(__VA_ARGS__) +#endif // __check_builtin(has_virtual_destructor) + +#if __check_builtin(is_aggregate) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 700) \ + || (defined(_LIBCUDACXX_COMPILER_MSVC) && _MSC_VER > 1914) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_AGGREGATE(...) __is_aggregate(__VA_ARGS__) +#endif // __check_builtin(is_aggregate) + +#if __check_builtin(is_array) +#define _LIBCUDACXX_IS_ARRAY(...) __is_array(__VA_ARGS__) +#endif // __check_builtin(is_array) + +// TODO: Clang incorrectly reports that __is_array is true for T[0]. +// Re-enable the branch once https://llvm.org/PR54705 is fixed. +#ifndef _LIBCUDACXX_USE_IS_ARRAY_FALLBACK +#if defined(_LIBCUDACXX_COMPILER_CLANG) +#define _LIBCUDACXX_USE_IS_ARRAY_FALLBACK +#endif // _LIBCUDACXX_COMPILER_CLANG +#endif // !_LIBCUDACXX_USE_IS_ARRAY_FALLBACK + +#if __check_builtin(is_assignable) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) +#define _LIBCUDACXX_IS_ASSIGNABLE(...) __is_assignable(__VA_ARGS__) +#endif // __check_builtin(is_assignable) + +#if __check_builtin(is_base_of) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_BASE_OF(...) __is_base_of(__VA_ARGS__) +#endif // __check_builtin(is_base_of) + +#if __check_builtin(is_class) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_CLASS(...) __is_class(__VA_ARGS__) +#endif // __check_builtin(is_class) + +#if __check_builtin(is_constructible) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 800) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_CONSTRUCTIBLE(...) __is_constructible(__VA_ARGS__) +#endif // __check_builtin(is_constructible) + +#if __check_builtin(is_convertible_to) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_CONVERTIBLE_TO(...) __is_convertible_to(__VA_ARGS__) +#endif // __check_builtin(is_convertible_to) + +#if __check_builtin(is_destructible) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) +#define _LIBCUDACXX_IS_DESTRUCTIBLE(...) __is_destructible(__VA_ARGS__) +#endif // __check_builtin(is_destructible) + +#if __check_builtin(is_empty) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_EMPTY(...) __is_empty(__VA_ARGS__) +#endif // __check_builtin(is_empty) + +#if __check_builtin(is_enum) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_ENUM(...) __is_enum(__VA_ARGS__) +#endif // __check_builtin(is_enum) + +#if __check_builtin(is_final) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 407) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_FINAL(...) __is_final(__VA_ARGS__) +#endif // __check_builtin(is_final) + +#if __check_builtin(is_function) \ + && !defined(_LIBCUDACXX_COMPILER_NVCC) +#define _LIBCUDACXX_IS_FUNCTION(...) __is_function(__VA_ARGS__) +#endif // __check_builtin(is_function) + +#if __check_builtin(is_literal_type) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 406) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_LITERAL(...) __is_literal_type(__VA_ARGS__) +#endif // __check_builtin(is_literal_type) + +#if __check_builtin(is_lvalue_reference) +#define _LIBCUDACXX_IS_LVALUE_REFERENCE(...) __is_lvalue_reference(__VA_ARGS__) +#endif // __check_builtin(is_lvalue_reference) + +#ifndef _LIBCUDACXX_USE_IS_LVALUE_REFERENCE_FALLBACK +#if defined(_LIBCUDACXX_CUDACC_BELOW_11_3) +#define _LIBCUDACXX_USE_IS_LVALUE_REFERENCE_FALLBACK +#endif // nvcc < 11.3 +#endif // !_LIBCUDACXX_USE_IS_LVALUE_REFERENCE_FALLBACK + +#if __check_builtin(is_nothrow_assignable) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_NOTHROW_ASSIGNABLE(...) __is_nothrow_assignable(__VA_ARGS__) +#endif // __check_builtin(is_nothrow_assignable) + +#if __check_builtin(is_nothrow_constructible) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_NOTHROW_CONSTRUCTIBLE(...) __is_nothrow_constructible(__VA_ARGS__) +#endif // __check_builtin(is_nothrow_constructible) + +#if __check_builtin(is_nothrow_destructible) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_NOTHROW_DESTRUCTIBLE(...) __is_nothrow_destructible(__VA_ARGS__) +#endif // __check_builtin(is_nothrow_destructible) + +#if __check_builtin(is_object) +#define _LIBCUDACXX_IS_OBJECT(...) __is_object(__VA_ARGS__) +#endif // __check_builtin(is_object) + +#ifndef _LIBCUDACXX_USE_IS_OBJECT_FALLBACK +#if defined(_LIBCUDACXX_CUDACC_BELOW_11_3) +#define _LIBCUDACXX_USE_IS_OBJECT_FALLBACK +#endif // nvcc < 11.3 +#endif // !_LIBCUDACXX_USE_IS_OBJECT_FALLBACK + +#if __check_builtin(is_pod) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_POD(...) __is_pod(__VA_ARGS__) +#endif // __check_builtin(is_pod) + +// libstdc++ defines this as a function, breaking functionality +#if 0 // __check_builtin(is_pointer) +#define _LIBCUDACXX_IS_POINTER(...) __is_pointer(__VA_ARGS__) +#endif // __check_builtin(is_pointer) + +#if __check_builtin(is_polymorphic) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_POLYMORPHIC(...) __is_polymorphic(__VA_ARGS__) +#endif // __check_builtin(is_polymorphic) + +#if __check_builtin(is_reference) +#define _LIBCUDACXX_IS_REFERENCE(...) __is_reference(__VA_ARGS__) +#endif // __check_builtin(is_reference) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(is_referenceable) +#define _LIBCUDACXX_IS_REFERENCEABLE(...) __is_referenceable(__VA_ARGS__) +#endif // __check_builtin(is_referenceable) + +#if __check_builtin(is_rvalue_reference) +#define _LIBCUDACXX_IS_RVALUE_REFERENCE(...) __is_rvalue_reference(__VA_ARGS__) +#endif // __check_builtin(is_rvalue_reference) + +#if __check_builtin(is_same) \ + && !defined(_LIBCUDACXX_COMPILER_NVCC) +#define _LIBCUDACXX_IS_SAME(...) __is_same(__VA_ARGS__) +#endif // __check_builtin(is_same) + +// libstdc++ defines this as a function, breaking functionality +#if 0 // __check_builtin(is_scalar) +#define _LIBCUDACXX_IS_SCALAR(...) __is_scalar(__VA_ARGS__) +#endif // __check_builtin(is_scalar) + +// libstdc++ defines this as a function, breaking functionality +#if 0 // __check_builtin(is_signed) +#define _LIBCUDACXX_IS_SIGNED(...) __is_signed(__VA_ARGS__) +#endif // __check_builtin(is_signed) + +#if __check_builtin(is_standard_layout) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 407) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_STANDARD_LAYOUT(...) __is_standard_layout(__VA_ARGS__) +#endif // __check_builtin(is_standard_layout) + +#if __check_builtin(is_trivial) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 405) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_TRIVIAL(...) __is_trivial(__VA_ARGS__) +#endif // __check_builtin(is_trivial) + +#if __check_builtin(is_trivially_assignable) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 501) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_TRIVIALLY_ASSIGNABLE(...) __is_trivially_assignable(__VA_ARGS__) +#endif // __check_builtin(is_trivially_assignable) + +#if __check_builtin(is_trivially_constructible) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 501) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_TRIVIALLY_CONSTRUCTIBLE(...) __is_trivially_constructible(__VA_ARGS__) +#endif // __check_builtin(is_trivially_constructible) + +#if __check_builtin(is_trivially_copyable) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 501) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_TRIVIALLY_COPYABLE(...) __is_trivially_copyable(__VA_ARGS__) +#endif // __check_builtin(is_trivially_copyable) + +#if __check_builtin(is_trivially_destructible) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) +#define _LIBCUDACXX_IS_TRIVIALLY_DESTRUCTIBLE(...) __is_trivially_destructible(__VA_ARGS__) +#endif // __check_builtin(is_trivially_destructible) + +#if __check_builtin(is_union) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 403) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_IS_UNION(...) __is_union(__VA_ARGS__) +#endif // __check_builtin(is_union) + +#if __check_builtin(is_unsigned) +#define _LIBCUDACXX_IS_UNSIGNED(...) __is_unsigned(__VA_ARGS__) +#endif // __check_builtin(is_unsigned) + +#ifndef _LIBCUDACXX_USE_IS_UNSIGNED_FALLBACK +#if defined(_LIBCUDACXX_CUDACC_BELOW_11_3) +#define _LIBCUDACXX_USE_IS_UNSIGNED_FALLBACK +#endif // nvcc < 11.3 +#endif // !_LIBCUDACXX_USE_IS_UNSIGNED_FALLBACK + +// libstdc++ defines this as a function, breaking functionality +#if 0 // __check_builtin(is_void) +#define _LIBCUDACXX_IS_VOID(...) __is_void(__VA_ARGS__) +#endif // __check_builtin(is_void) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(make_signed) +#define _LIBCUDACXX_MAKE_SIGNED(...) __make_signed(__VA_ARGS__) +#endif // __check_builtin(make_signed) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(make_unsigned) +#define _LIBCUDACXX_MAKE_UNSIGNED(...) __make_unsigned(__VA_ARGS__) +#endif // __check_builtin(make_unsigned) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_all_extents) +#define _LIBCUDACXX_REMOVE_ALL_EXTENTS(...) __remove_all_extents(__VA_ARGS__) +#endif // __check_builtin(remove_all_extents) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_const) +#define _LIBCUDACXX_REMOVE_CONST(...) __remove_const(__VA_ARGS__) +#endif // __check_builtin(remove_const) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_cv) +#define _LIBCUDACXX_REMOVE_CV(...) __remove_cv(__VA_ARGS__) +#endif // __check_builtin(remove_cv) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_cvref) +#define _LIBCUDACXX_REMOVE_CVREF(...) __remove_cvref(__VA_ARGS__) +#endif // __check_builtin(remove_cvref) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_extent) +#define _LIBCUDACXX_REMOVE_EXTENT(...) __remove_extent(__VA_ARGS__) +#endif // __check_builtin(remove_extent) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_pointer) +#define _LIBCUDACXX_REMOVE_POINTER(...) __remove_pointer(__VA_ARGS__) +#endif // __check_builtin(remove_pointer) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_reference_t) +#define _LIBCUDACXX_REMOVE_REFERENCE_T(...) __remove_reference_t(__VA_ARGS__) +#endif // __check_builtin(remove_reference_t) + +// Disabled due to libstdc++ conflict +#if 0 // __check_builtin(remove_volatile) +#define _LIBCUDACXX_REMOVE_VOLATILE(...) __remove_volatile(__VA_ARGS__) +#endif // __check_builtin(remove_volatile) + +#if __check_builtin(underlying_type) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER >= 407) \ + || defined(_LIBCUDACXX_COMPILER_MSVC) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) +#define _LIBCUDACXX_UNDERLYING_TYPE(...) __underlying_type(__VA_ARGS__) +#endif // __check_builtin(underlying_type) + +#define _LIBCUDACXX_TOSTRING2(_STR) #_STR +#define _LIBCUDACXX_TOSTRING(_STR) _LIBCUDACXX_TOSTRING2(_STR) +#if defined(_LIBCUDACXX_CUDACC) && !defined(_LIBCUDACXX_COMPILER_CLANG_CUDA) +# if defined(__NVCC_DIAG_PRAGMA_SUPPORT__) +# if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) __pragma(_LIBCUDACXX_TOSTRING(nv_diag_suppress _WARNING)) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) __pragma(_LIBCUDACXX_TOSTRING(nv_diag_default _WARNING)) +# else // ^^^ MSVC ^^^ / vvv not MSVC +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) \ + _Pragma(_LIBCUDACXX_TOSTRING(nv_diagnostic push)) \ + _Pragma(_LIBCUDACXX_TOSTRING(nv_diag_suppress _WARNING)) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) _Pragma(_LIBCUDACXX_TOSTRING(nv_diagnostic pop)) +# endif // not MSVC +# elif defined(_LIBCUDACXX_COMPILER_NVHPC) +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) \ + _Pragma(_LIBCUDACXX_TOSTRING(diagnostic push)) \ + _Pragma(_LIBCUDACXX_TOSTRING(diag_suppress _WARNING)) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) _Pragma(_LIBCUDACXX_TOSTRING(diagnostic pop)) +# else // _LIBCUDACXX_CUDACC_BELOW_11_3 +# if defined(_LIBCUDACXX_COMPILER_MSVC_2017) // MSVC 2017 has issues with restoring the warning +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) __pragma(_LIBCUDACXX_TOSTRING(diag_suppress _WARNING)) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) +# elif defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) __pragma(_LIBCUDACXX_TOSTRING(diag_suppress _WARNING)) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) __pragma(_LIBCUDACXX_TOSTRING(diag_default _WARNING)) +# else // ^^^ MSVC ^^^ / vvv not MSVC +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) _Pragma(_LIBCUDACXX_TOSTRING(diag_suppress _WARNING)) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) _Pragma(_LIBCUDACXX_TOSTRING(diag_default _WARNING)) +# endif // not MSVC +# endif // !__NVCC_DIAG_PRAGMA_SUPPORT__ +#else // ^^^ _LIBCUDACXX_CUDACC ^^^ / vvv other compiler vvv +# define _LIBCUDACXX_NV_DIAG_SUPPRESS(_WARNING) +# define _LIBCUDACXX_NV_DIAG_DEFAULT(_WARNING) +#endif // other compilers + +#if defined(_LIBCUDACXX_COMPILER_CLANG) + +// _LIBCUDACXX_ALTERNATE_STRING_LAYOUT is an old name for +// _LIBCUDACXX_ABI_ALTERNATE_STRING_LAYOUT left here for backward compatibility. +#if defined(_LIBCUDACXX_ALTERNATE_STRING_LAYOUT) +#define _LIBCUDACXX_ABI_ALTERNATE_STRING_LAYOUT +#endif + +#if __cplusplus < 201103L +typedef __char16_t char16_t; +typedef __char32_t char32_t; +#endif + +#if !(__has_feature(cxx_strong_enums)) +#define _LIBCUDACXX_HAS_NO_STRONG_ENUMS +#endif + +#if !(__has_feature(cxx_lambdas)) +#define _LIBCUDACXX_HAS_NO_LAMBDAS +#endif + +#if !(__has_feature(cxx_nullptr)) +# if (__has_extension(cxx_nullptr) || __has_keyword(__nullptr)) && defined(_LIBCUDACXX_ABI_ALWAYS_USE_CXX11_NULLPTR) +# define nullptr __nullptr +# else +# define _LIBCUDACXX_HAS_NO_NULLPTR +# endif +#endif + +#if !(__has_feature(cxx_rvalue_references)) +#define _LIBCUDACXX_HAS_NO_RVALUE_REFERENCES +#endif + +#if !(__has_feature(cxx_auto_type)) +#define _LIBCUDACXX_HAS_NO_AUTO_TYPE +#endif + +#if !(__has_feature(cxx_variadic_templates)) +#define _LIBCUDACXX_HAS_NO_VARIADICS +#endif + +#if !(__has_feature(cxx_generalized_initializers)) +#define _LIBCUDACXX_HAS_NO_GENERALIZED_INITIALIZERS +#endif + +// Objective-C++ features (opt-in) +#if __has_feature(objc_arc) +#define _LIBCUDACXX_HAS_OBJC_ARC +#endif + +#if __has_feature(objc_arc_weak) +#define _LIBCUDACXX_HAS_OBJC_ARC_WEAK +#endif + +#if !(__has_feature(cxx_relaxed_constexpr)) +#define _LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR +#endif + +#if !(__has_feature(cxx_variable_templates)) +#define _LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES +#endif + +#if !(__has_feature(cxx_noexcept)) +#define _LIBCUDACXX_HAS_NO_NOEXCEPT +#endif + +// Allow for build-time disabling of unsigned integer sanitization +#if !defined(_LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK) && __has_attribute(no_sanitize) +#define _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) +#endif + +#define _LIBCUDACXX_DISABLE_EXTENSION_WARNING __extension__ + +#elif defined(_LIBCUDACXX_COMPILER_GCC) + +#ifndef _LIBCUDACXX_USE_IS_ASSIGNABLE_FALLBACK +// FIXME: GCC 8.0 supports this trait, but it has a bug. +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91592 +// https://godbolt.org/z/IljfIw +#define _LIBCUDACXX_USE_IS_ASSIGNABLE_FALLBACK +#endif // _LIBCUDACXX_USE_IS_ASSIGNABLE_FALLBACK + +// Determine if GCC supports relaxed constexpr +#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L +#define _LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR +#endif + +// GCC 5 supports variable templates +#if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L +#define _LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES +#endif + +#if _GNUC_VER < 600 +#define _LIBCUDACXX_GCC_MATH_IN_STD +#endif + +// NVCC cannot properly handle some deductions occuring within NOEXCEPT +// C++17 mode causes reference instatiation errors in tuple +#if (_GNUC_VER >= 702 && _GNUC_VER <= 805) +#if defined(_LIBCUDACXX_COMPILER_NVCC) && _LIBCUDACXX_STD_VER == 17 +#define _LIBCUDACXX_NO_TUPLE_NOEXCEPT +#endif +#endif + +#define _LIBCUDACXX_DISABLE_EXTENSION_WARNING __extension__ + +#elif defined(_LIBCUDACXX_COMPILER_MSVC) + +#define _LIBCUDACXX_WARNING(x) __pragma(message(__FILE__ "(" _LIBCUDACXX_TOSTRING(__LINE__) ") : warning note: " x)) + +// https://github.com/microsoft/STL/blob/master/stl/inc/yvals_core.h#L353 +// warning C4100: 'quack': unreferenced formal parameter +// warning C4127: conditional expression is constant +// warning C4180: qualifier applied to function type has no meaning; ignored +// warning C4197: 'purr': top-level volatile in cast is ignored +// warning C4324: 'roar': structure was padded due to alignment specifier +// warning C4455: literal suffix identifiers that do not start with an underscore are reserved +// warning C4503: 'hum': decorated name length exceeded, name was truncated +// warning C4522: 'woof' : multiple assignment operators specified +// warning C4668: 'meow' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' +// warning C4800: 'boo': forcing value to bool 'true' or 'false' (performance warning) +// warning C4996: 'meow': was declared deprecated +#define _LIBCUDACXX_MSVC_DISABLED_WARNINGS \ + 4100 \ + 4127 \ + 4180 \ + 4197 \ + 4296 \ + 4324 \ + 4455 \ + 4503 \ + 4522 \ + 4668 \ + 4800 \ + 4996 \ + /**/ + +#if _MSC_VER < 1900 +#error "MSVC versions prior to Visual Studio 2015 are not supported" +#endif + +// MSVC implemented P0030R1 in 15.7, only available under C++17 +#if _MSC_VER < 1914 +#define _LIBCUDACXX_NO_HOST_CPP17_HYPOT +#endif + +#if _MSC_VER < 1920 +#define _LIBCUDACXX_HAS_NO_NOEXCEPT_SFINAE +#define _LIBCUDACXX_HAS_NO_LOGICAL_METAFUNCTION_ALIASES +#endif + +// MSVC exposed __iso_volatile intrinsics beginning on 1924 for x86 +#if _MSC_VER < 1924 + #define _LIBCUDACXX_MSVC_HAS_NO_ISO_INTRIN +#endif + +#if _LIBCUDACXX_STD_VER < 14 +#define _LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR +#define _LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES +#endif + +#define _LIBCUDACXX_WEAK + +#define _LIBCUDACXX_HAS_NO_VECTOR_EXTENSION + +#define _LIBCUDACXX_DISABLE_EXTENSION_WARNING + +#elif defined(_LIBCUDACXX_COMPILER_IBM) + +#define _ATTRIBUTE(x) __attribute__((x)) + +#define _LIBCUDACXX_HAS_NO_UNICODE_CHARS +#define _LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES + +#if defined(_AIX) +#define __MULTILOCALE_API +#endif + +#define _LIBCUDACXX_HAS_NO_VECTOR_EXTENSION + +#elif defined(_LIBCUDACXX_COMPILER_NVRTC) || defined(_LIBCUDACXX_COMPILER_NVHPC) + +#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L +#define _LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR +#endif + +#if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L +#define _LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES +#endif + +#define _LIBCUDACXX_DISABLE_EXTENSION_WARNING + +#endif // _LIBCUDACXX_COMPILER_[CLANG|GCC|MSVC|IBM|NVRTC] + +#if defined(_LIBCUDACXX_COMPILER_NVHPC) && !defined(__cuda_std__) +// Forcefully disable visibility controls when used as the standard library with NVC++. +// TODO: reevaluate. +#define _LIBCUDACXX_HIDE_FROM_ABI +#ifndef _LIBCUDACXX_DISABLE_EXTERN_TEMPLATE +#define _LIBCUDACXX_DISABLE_EXTERN_TEMPLATE +#endif +#endif + +#ifndef _LIBCUDACXX_FREESTANDING +#if defined(__cuda_std__) \ + || !defined(__STDC_HOSTED__) +# define _LIBCUDACXX_FREESTANDING +#endif +#endif // !_LIBCUDACXX_FREESTANDING + +#ifndef _LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || (defined(_LIBCUDACXX_COMPILER_NVHPC) && !defined(__cuda_std__)) +# define _LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS +#endif +#endif // _LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS + +#ifndef _LIBCUDACXX_HAS_CUDA_ATOMIC_EXT +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_CUDA_ATOMIC_EXT +#endif +#endif // _LIBCUDACXX_HAS_CUDA_ATOMIC_EXT + +#ifndef _LIBCUDACXX_HAS_EXTERNAL_ATOMIC_IMP +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_EXTERNAL_ATOMIC_IMP +#endif +#endif // _LIBCUDACXX_HAS_EXTERNAL_ATOMIC_IMP + +#ifndef _LIBCUDACXX_HAS_NO_ASAN +#if defined(_LIBCUDACXX_COMPILER_GCC) +# if !defined(__SANITIZE_ADDRESS__) +# define _LIBCUDACXX_HAS_NO_ASAN +# endif // !__SANITIZE_ADDRESS__ +#elif defined(_LIBCUDACXX_COMPILER_CLANG) +# if !__has_feature(address_sanitizer) +# define _LIBCUDACXX_HAS_NO_ASAN +# endif // !__has_feature(address_sanitizer) +#else +# define _LIBCUDACXX_HAS_NO_ASAN +#endif // _LIBCUDACXX_COMPILER[MSVC|IBM|NVHPC|NVRTC] +#endif // _LIBCUDACXX_HAS_NO_ASAN + +#ifndef _LIBCUDACXX_HAS_NO_CXX20_CHRONO_LITERALS +#if defined(__cuda_std__) \ + || (defined(_LIBCUDACXX_COMPILER_CLANG) && _LIBCUDACXX_CLANG_VER < 800) +# define _LIBCUDACXX_HAS_NO_CXX20_CHRONO_LITERALS +#endif // __cuda_std__ +#endif // _LIBCUDACXX_HAS_NO_CXX20_CHRONO_LITERALS + +#ifndef _LIBCUDACXX_HAS_NO_INT128 +#if defined(_LIBCUDACXX_COMPILER_MSVC) \ + || (defined(_LIBCUDACXX_COMPILER_NVRTC) && !defined(__CUDACC_RTC_INT128__)) \ + || (defined(_LIBCUDACXX_COMPILER_NVCC) && (_LIBCUDACXX_CUDACC_VER < 1105000)) \ + || !defined(__SIZEOF_INT128__) +# define _LIBCUDACXX_HAS_NO_INT128 +#endif +#endif // !_LIBCUDACXX_HAS_NO_INT128 + +#ifndef _LIBCUDACXX_HAS_NO_LONG_DOUBLE +#if defined(_LIBCUDACXX_CUDACC) +# define _LIBCUDACXX_HAS_NO_LONG_DOUBLE +#endif +#endif // _LIBCUDACXX_HAS_NO_LONG_DOUBLE + +#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +#if __has_cpp_attribute(msvc::no_unique_address) +// MSVC implements [[no_unique_address]] as a silent no-op currently. +// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) +// However, MSVC implements [[msvc::no_unique_address]] which does what +// [[no_unique_address]] is supposed to do, in general. + +// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or +// [[msvc::no_unique_address]] though. If/when it does implement +// [[msvc::no_unique_address]], this should be preferred though. +# define _LIBCUDACXX_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] +#elif defined(_LIBCUDACXX_CUDACC_BELOW_11_3) \ + || (__has_cpp_attribute(no_unique_address) < 201803L) +# define _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +# define _LIBCUDACXX_NO_UNIQUE_ADDRESS +#elif __has_cpp_attribute(no_unique_address) +# define _LIBCUDACXX_NO_UNIQUE_ADDRESS [[no_unique_address]] +#else +# define _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +# define _LIBCUDACXX_NO_UNIQUE_ADDRESS +// Note that this can be replaced by #error as soon as clang-cl +// implements msvc::no_unique_address, since there should be no C++20 +// compiler that doesn't support one of the two attributes at that point. +// We generally don't want to use this macro outside of C++20-only code, +// because using it conditionally in one language version only would make +// the ABI inconsistent. +#endif +#endif // _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS + +#ifndef _LIBCUDACXX_HAS_NO_MONOTONIC_CLOCK +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_NO_MONOTONIC_CLOCK +#endif +#endif // _LIBCUDACXX_HAS_NO_MONOTONIC_CLOCK + +#ifndef _LIBCUDACXX_HAS_NO_PLATFORM_WAIT +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_NO_PLATFORM_WAIT +#endif +#endif // _LIBCUDACXX_HAS_NO_PLATFORM_WAIT + +#ifndef _LIBCUDACXX_HAS_NO_PRAGMA_PUSH_POP_MACRO +#if (defined(_LIBCUDACXX_COMPILER_MSVC) && _MSC_VER < 1920) \ + || defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || defined(_LIBCUDACXX_COMPILER_IBM) +#define _LIBCUDACXX_HAS_NO_PRAGMA_PUSH_POP_MACRO +#endif +#endif // _LIBCUDACXX_HAS_NO_PRAGMA_PUSH_POP_MACRO + +#ifndef _LIBCUDACXX_HAS_NO_THREAD_CONTENTION_TABLE +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_NO_THREAD_CONTENTION_TABLE +#endif +#endif // _LIBCUDACXX_HAS_NO_THREAD_CONTENTION_TABLE + +#ifndef _LIBCUDACXX_HAS_NO_TREE_BARRIER +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_NO_TREE_BARRIER +#endif +#endif // _LIBCUDACXX_HAS_NO_TREE_BARRIER + +#ifndef _LIBCUDACXX_HAS_NO_WCHAR_H +#if defined(__cuda_std__) +# define _LIBCUDACXX_HAS_NO_WCHAR_H +#endif +#endif // _LIBCUDACXX_HAS_NO_WCHAR_H + +#ifndef _LIBCUDACXX_NO_EXCEPTIONS +#if defined(__cuda_std__) \ + || (defined(_LIBCUDACXX_COMPILER_CLANG) && !(__has_feature(cxx_exceptions))) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && !__EXCEPTIONS) +# define _LIBCUDACXX_NO_EXCEPTIONS +#endif +#endif // !_LIBCUDACXX_NO_EXCEPTIONS + +// Try to find out if RTTI is disabled. +// g++ and cl.exe have RTTI on by default and define a macro when it is. +#ifndef _LIBCUDACXX_NO_RTTI +#if defined(__cuda_std__) \ + || (defined(_LIBCUDACXX_COMPILER_CLANG) && !(__has_feature(cxx_rtti))) \ + || (defined(_LIBCUDACXX_COMPILER_GCC) && !defined(__GXX_RTTI)) \ + || (defined(_LIBCUDACXX_COMPILER_MSVC) && !defined(_CPPRTTI)) +# define _LIBCUDACXX_NO_RTTI +#endif +#endif // !_LIBCUDACXX_NO_RTTI + +#ifndef _LIBCUDACXX_NODEBUG_TYPE +#if defined(__cuda_std__) +# define _LIBCUDACXX_NODEBUG_TYPE +#elif __has_attribute(__nodebug__) \ + && (defined(_LIBCUDACXX_COMPILER_CLANG) && _LIBCUDACXX_CLANG_VER >= 1210) +# define _LIBCUDACXX_NODEBUG_TYPE __attribute__((nodebug)) +#else +# define _LIBCUDACXX_NODEBUG_TYPE +#endif +#endif // !_LIBCUDACXX_NODEBUG_TYPE + +#if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_NORETURN __declspec(noreturn) +#elif __has_feature(cxx_attributes) +# define _LIBCUDACXX_NORETURN [[noreturn]] +#else +# define _LIBCUDACXX_NORETURN __attribute__ ((noreturn)) +#endif + +#if defined(_LIBCUDACXX_OBJECT_FORMAT_COFF) + +#ifdef _DLL +# define _LIBCUDACXX_CRT_FUNC __declspec(dllimport) +#else +# define _LIBCUDACXX_CRT_FUNC +#endif + +#if defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_DLL_VIS +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS +# define _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS +# define _LIBCUDACXX_OVERRIDABLE_FUNC_VIS +# define _LIBCUDACXX_EXPORTED_FROM_ABI +#elif defined(_LIBCUDACXX_BUILDING_LIBRARY) +# define _LIBCUDACXX_DLL_VIS __declspec(dllexport) +# if defined(__MINGW32__) +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS _LIBCUDACXX_DLL_VIS +# define _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS +# else +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS +# define _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCUDACXX_DLL_VIS +# endif +# define _LIBCUDACXX_OVERRIDABLE_FUNC_VIS _LIBCUDACXX_DLL_VIS +# define _LIBCUDACXX_EXPORTED_FROM_ABI __declspec(dllexport) +#else +# define _LIBCUDACXX_DLL_VIS __declspec(dllimport) +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS _LIBCUDACXX_DLL_VIS +# define _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS +# define _LIBCUDACXX_OVERRIDABLE_FUNC_VIS +# define _LIBCUDACXX_EXPORTED_FROM_ABI __declspec(dllimport) +#endif + +#define _LIBCUDACXX_TYPE_VIS _LIBCUDACXX_DLL_VIS +#define _LIBCUDACXX_FUNC_VIS _LIBCUDACXX_DLL_VIS +#define _LIBCUDACXX_EXCEPTION_ABI _LIBCUDACXX_DLL_VIS +#define _LIBCUDACXX_HIDDEN +#define _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS +#define _LIBCUDACXX_TEMPLATE_VIS +#define _LIBCUDACXX_ENUM_VIS + +#endif // defined(_LIBCUDACXX_OBJECT_FORMAT_COFF) + +#ifndef _LIBCUDACXX_HIDDEN +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_HIDDEN __attribute__ ((__visibility__("hidden"))) +# else +# define _LIBCUDACXX_HIDDEN +# endif +#endif + +#ifndef _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +// The inline should be removed once PR32114 is resolved +# define _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCUDACXX_HIDDEN +# else +# define _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_FUNC_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_FUNC_VIS __attribute__ ((__visibility__("default"))) +# else +# define _LIBCUDACXX_FUNC_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_TYPE_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_TYPE_VIS __attribute__ ((__visibility__("default"))) +# else +# define _LIBCUDACXX_TYPE_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_TEMPLATE_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# if __has_attribute(__type_visibility__) +# define _LIBCUDACXX_TEMPLATE_VIS __attribute__ ((__type_visibility__("default"))) +# else +# define _LIBCUDACXX_TEMPLATE_VIS __attribute__ ((__visibility__("default"))) +# endif +# else +# define _LIBCUDACXX_TEMPLATE_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_EXPORTED_FROM_ABI +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_EXPORTED_FROM_ABI __attribute__((__visibility__("default"))) +# else +# define _LIBCUDACXX_EXPORTED_FROM_ABI +# endif +#endif + +#ifndef _LIBCUDACXX_OVERRIDABLE_FUNC_VIS +#define _LIBCUDACXX_OVERRIDABLE_FUNC_VIS _LIBCUDACXX_FUNC_VIS +#endif + +#ifndef _LIBCUDACXX_EXCEPTION_ABI +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCUDACXX_EXCEPTION_ABI __attribute__ ((__visibility__("default"))) +# else +# define _LIBCUDACXX_EXCEPTION_ABI +# endif +#endif + +#ifndef _LIBCUDACXX_ENUM_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) +# define _LIBCUDACXX_ENUM_VIS __attribute__ ((__type_visibility__("default"))) +# else +# define _LIBCUDACXX_ENUM_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS +# if !defined(_LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS __attribute__ ((__visibility__("default"))) +# else +# define _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS +# endif +#endif + +#ifndef _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS +#define _LIBCUDACXX_CLASS_TEMPLATE_INSTANTIATION_VIS +#endif + +#if __has_attribute(internal_linkage) +# define _LIBCUDACXX_INTERNAL_LINKAGE __attribute__ ((internal_linkage)) +#else +# define _LIBCUDACXX_INTERNAL_LINKAGE _LIBCUDACXX_ALWAYS_INLINE +#endif + +#if __has_attribute(exclude_from_explicit_instantiation) +# define _LIBCUDACXX_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__ ((__exclude_from_explicit_instantiation__)) +#else + // Try to approximate the effect of exclude_from_explicit_instantiation + // (which is that entities are not assumed to be provided by explicit + // template instantiations in the dylib) by always inlining those entities. +# define _LIBCUDACXX_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCUDACXX_ALWAYS_INLINE +#endif + +#ifndef _LIBCUDACXX_HIDE_FROM_ABI_PER_TU +# ifndef _LIBCUDACXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT +# define _LIBCUDACXX_HIDE_FROM_ABI_PER_TU 0 +# else +# define _LIBCUDACXX_HIDE_FROM_ABI_PER_TU 1 +# endif +#endif + +#ifndef _LIBCUDACXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT +# ifdef _LIBCUDACXX_OBJECT_FORMAT_COFF // Windows binaries can't merge typeinfos. +# define _LIBCUDACXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT 0 +#else +// TODO: This isn't strictly correct on ELF platforms due to llvm.org/PR37398 +// And we should consider defaulting to OFF. +# define _LIBCUDACXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT 1 +#endif +#endif + +#ifndef _LIBCUDACXX_HIDE_FROM_ABI +# if _LIBCUDACXX_HIDE_FROM_ABI_PER_TU +# define _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_HIDDEN _LIBCUDACXX_INTERNAL_LINKAGE +# else +# define _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_HIDDEN _LIBCUDACXX_EXCLUDE_FROM_EXPLICIT_INSTANTIATION +# endif +#endif + +#ifdef _LIBCUDACXX_BUILDING_LIBRARY +# if _LIBCUDACXX_ABI_VERSION > 1 +# define _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1 _LIBCUDACXX_HIDE_FROM_ABI +# else +# define _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1 +# endif +#else +# define _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1 _LIBCUDACXX_HIDE_FROM_ABI +#endif + +#ifdef _LIBCUDACXX_CUDACC +# define _LIBCUDACXX_HOST __host__ +# define _LIBCUDACXX_DEVICE __device__ +# define _LIBCUDACXX_HOST_DEVICE __host__ __device__ +# define _LIBCUDACXX_FORCE_INLINE __forceinline__ +#else // ^^^ _LIBCUDACXX_CUDACC ^^^ / vvv !_LIBCUDACXX_CUDACC +# define _LIBCUDACXX_HOST +# define _LIBCUDACXX_DEVICE +# define _LIBCUDACXX_HOST_DEVICE +# define _LIBCUDACXX_FORCE_INLINE +#endif // !_LIBCUDACXX_CUDACC + +// Just so we can migrate to the new macros gradually. + +#ifdef __cuda_std__ +# define _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_HOST_DEVICE +#else +# define _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_HIDE_FROM_ABI +#endif // __cuda_std__ + +#define _LIBCUDACXX_CONCAT1(_LIBCUDACXX_X,_LIBCUDACXX_Y) _LIBCUDACXX_X##_LIBCUDACXX_Y +#define _LIBCUDACXX_CONCAT(_LIBCUDACXX_X,_LIBCUDACXX_Y) _LIBCUDACXX_CONCAT1(_LIBCUDACXX_X,_LIBCUDACXX_Y) + +#ifndef _LIBCUDACXX_ABI_NAMESPACE +#ifdef __cuda_std__ +# define _LIBCUDACXX_ABI_NAMESPACE _LIBCUDACXX_CONCAT(__,_LIBCUDACXX_CUDA_ABI_VERSION) +#else +# define _LIBCUDACXX_ABI_NAMESPACE _LIBCUDACXX_CONCAT(__,_LIBCUDACXX_ABI_VERSION) +#endif // __cuda_std__ +#endif // _LIBCUDACXX_ABI_NAMESPACE + +#ifdef __cuda_std__ +# define _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION namespace cuda { namespace std { +# define _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION } } +# define _CUDA_VSTD ::cuda::std::_LIBCUDACXX_ABI_NAMESPACE +# define _CUDA_VRANGES ::cuda::std::ranges::_LIBCUDACXX_ABI_NAMESPACE +#else +# define _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION namespace std { +# define _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION } +# define _CUDA_VSTD ::std::_LIBCUDACXX_ABI_NAMESPACE +# define _CUDA_VRANGES ::std::ranges::_LIBCUDACXX_ABI_NAMESPACE +#endif + +#ifdef __cuda_std__ +#define _LIBCUDACXX_BEGIN_NAMESPACE_CUDA namespace cuda { inline namespace _LIBCUDACXX_ABI_NAMESPACE { +#define _LIBCUDACXX_END_NAMESPACE_CUDA } } +#define _LIBCUDACXX_BEGIN_NAMESPACE_CUDA_DEVICE namespace cuda { namespace device { inline namespace _LIBCUDACXX_ABI_NAMESPACE { +#define _LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE } } } +#define _LIBCUDACXX_BEGIN_NAMESPACE_CUDA_PTX namespace cuda { namespace ptx { inline namespace _LIBCUDACXX_ABI_NAMESPACE { +#define _LIBCUDACXX_END_NAMESPACE_CUDA_PTX } } } +#define _CUDA_VPTX ::cuda::ptx::_LIBCUDACXX_ABI_NAMESPACE +#define _LIBCUDACXX_BEGIN_NAMESPACE_CUDA_DEVICE_EXPERIMENTAL namespace cuda { namespace device { namespace experimental { inline namespace _LIBCUDACXX_ABI_NAMESPACE { +#define _LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE_EXPERIMENTAL } } } } +#endif + +// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. +#define _LIBCUDACXX_BEGIN_NAMESPACE_STD _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION inline namespace _LIBCUDACXX_ABI_NAMESPACE { +#define _LIBCUDACXX_END_NAMESPACE_STD } _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION + +#ifndef __cuda_std__ +_LIBCUDACXX_BEGIN_NAMESPACE_STD _LIBCUDACXX_END_NAMESPACE_STD +#endif + +#define _LIBCUDACXX_BEGIN_NAMESPACE_RANGES _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION namespace ranges { inline namespace _LIBCUDACXX_ABI_NAMESPACE { +#define _LIBCUDACXX_END_NAMESPACE_RANGES } } _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION + +#if !defined(__cuda_std__) +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES _LIBCUDACXX_END_NAMESPACE_RANGES +#endif + +#if _LIBCUDACXX_STD_VER > 17 +#define _LIBCUDACXX_BEGIN_NAMESPACE_RANGES_ABI inline namespace __cxx20 { +#else +#define _LIBCUDACXX_BEGIN_NAMESPACE_RANGES_ABI inline namespace __cxx17 { +#endif +#define _LIBCUDACXX_END_NAMESPACE_RANGES_ABI } + +#define _LIBCUDACXX_BEGIN_NAMESPACE_CPO(_CPO) namespace _CPO { _LIBCUDACXX_BEGIN_NAMESPACE_RANGES_ABI +#define _LIBCUDACXX_END_NAMESPACE_CPO } } + +#if _LIBCUDACXX_STD_VER >= 17 +#define _LIBCUDACXX_BEGIN_NAMESPACE_FILESYSTEM \ + _LIBCUDACXX_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem { +#else +#define _LIBCUDACXX_BEGIN_NAMESPACE_FILESYSTEM \ + _LIBCUDACXX_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem { +#endif + +#define _LIBCUDACXX_END_NAMESPACE_FILESYSTEM \ + _LIBCUDACXX_END_NAMESPACE_STD } } + +#define _CUDA_VSTD_FS _CUDA_VSTD::__fs::filesystem + +#ifndef _LIBCUDACXX_PREFERRED_OVERLOAD +# if __has_attribute(__enable_if__) +# define _LIBCUDACXX_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, ""))) +# endif +#endif + +#ifdef _LIBCUDACXX_HAS_NO_UNICODE_CHARS +typedef unsigned short char16_t; +typedef unsigned int char32_t; +#endif // _LIBCUDACXX_HAS_NO_UNICODE_CHARS + +#if defined(_LIBCUDACXX_COMPILER_GCC) \ + || defined(_LIBCUDACXX_COMPILER_CLANG) +# define _LIBCUDACXX_NOALIAS __attribute__((__malloc__)) +#else +# define _LIBCUDACXX_NOALIAS +#endif + +#if __has_feature(cxx_explicit_conversions) \ + || defined(_LIBCUDACXX_COMPILER_IBM) \ + || defined(_LIBCUDACXX_COMPILER_GCC) \ + || defined(_LIBCUDACXX_COMPILER_CLANG) +# define _LIBCUDACXX_EXPLICIT explicit +#else +# define _LIBCUDACXX_EXPLICIT +#endif + +#if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete) +#define _LIBCUDACXX_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE +#endif + +#ifdef _LIBCUDACXX_HAS_NO_STRONG_ENUMS +# define _LIBCUDACXX_DECLARE_STRONG_ENUM(x) struct _LIBCUDACXX_TYPE_VIS x { enum __lx +# define _LIBCUDACXX_DECLARE_STRONG_ENUM_EPILOG(x) \ + __lx __v_; \ + _LIBCUDACXX_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \ + _LIBCUDACXX_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ + _LIBCUDACXX_INLINE_VISIBILITY operator int() const {return __v_;} \ + }; +#else // _LIBCUDACXX_HAS_NO_STRONG_ENUMS +# define _LIBCUDACXX_DECLARE_STRONG_ENUM(x) enum class _LIBCUDACXX_ENUM_VIS x +# define _LIBCUDACXX_DECLARE_STRONG_ENUM_EPILOG(x) +#endif // _LIBCUDACXX_HAS_NO_STRONG_ENUMS + +#ifdef _LIBCUDACXX_DEBUG +# if _LIBCUDACXX_DEBUG == 0 +# define _LIBCUDACXX_DEBUG_LEVEL 1 +# elif _LIBCUDACXX_DEBUG == 1 +# define _LIBCUDACXX_DEBUG_LEVEL 2 +# else +# error Supported values for _LIBCUDACXX_DEBUG are 0 and 1 +# endif +# if !defined(_LIBCUDACXX_BUILDING_LIBRARY) +# define _LIBCUDACXX_EXTERN_TEMPLATE(...) +# endif +#endif + +#ifdef _LIBCUDACXX_DISABLE_EXTERN_TEMPLATE +#define _LIBCUDACXX_EXTERN_TEMPLATE(...) +#define _LIBCUDACXX_EXTERN_TEMPLATE2(...) +#endif + +#ifndef _LIBCUDACXX_EXTERN_TEMPLATE +#define _LIBCUDACXX_EXTERN_TEMPLATE(...) extern template __VA_ARGS__; +#endif + +#ifndef _LIBCUDACXX_EXTERN_TEMPLATE2 +#define _LIBCUDACXX_EXTERN_TEMPLATE2(...) extern template __VA_ARGS__; +#endif + +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCUDACXX_MSVCRT_LIKE) || \ + defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__) +#define _LIBCUDACXX_LOCALE__L_EXTENSIONS 1 +#endif + +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +// Most unix variants have catopen. These are the specific ones that don't. +# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) +# define _LIBCUDACXX_HAS_CATOPEN 1 +# endif +#endif + +#ifdef __FreeBSD__ +#define _DECLARE_C99_LDBL_MATH 1 +#endif + +#if defined(_LIBCUDACXX_ABI_MICROSOFT) && !defined(_LIBCUDACXX_NO_VCRUNTIME) +# define _LIBCUDACXX_DEFER_NEW_TO_VCRUNTIME +#endif + +// If we are getting operator new from the MSVC CRT, then allocation overloads +// for align_val_t were added in 19.12, aka VS 2017 version 15.3. +#if defined(_LIBCUDACXX_MSVCRT) && defined(_LIBCUDACXX_COMPILER_MSVC) && _MSC_VER < 1912 +# define _LIBCUDACXX_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +#elif defined(_LIBCUDACXX_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) + // We're deferring to Microsoft's STL to provide aligned new et al. We don't + // have it unless the language feature test macro is defined. +# define _LIBCUDACXX_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +#endif + +#if defined(__APPLE__) +# if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \ + defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) +# define __MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ +# endif +#endif // defined(__APPLE__) + +#if !defined(_LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION) && \ + (defined(_LIBCUDACXX_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \ + (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)) +# define _LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION +#endif + +#if defined(__APPLE__) || defined(__FreeBSD__) +#define _LIBCUDACXX_HAS_DEFAULTRUNELOCALE +#endif + +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__) +#define _LIBCUDACXX_WCTYPE_IS_MASK +#endif + +#if _LIBCUDACXX_STD_VER <= 17 || !defined(__cpp_char8_t) +#define _LIBCUDACXX_NO_HAS_CHAR8_T +#endif + +// Deprecation macros. +// +// Deprecations warnings are always enabled, except when users explicitly opt-out +// by defining _LIBCUDACXX_DISABLE_DEPRECATION_WARNINGS. +// NVCC 11.1 and 11.2 are broken with the deprecated attribute, so disable it +#if !defined(_LIBCUDACXX_DISABLE_DEPRECATION_WARNINGS) \ + && !defined(_LIBCUDACXX_CUDACC_BELOW_11_3) +# if __has_attribute(deprecated) +# define _LIBCUDACXX_DEPRECATED __attribute__ ((deprecated)) +# elif _LIBCUDACXX_STD_VER > 11 +# define _LIBCUDACXX_DEPRECATED [[deprecated]] +# else +# define _LIBCUDACXX_DEPRECATED +# endif +#else +# define _LIBCUDACXX_DEPRECATED +#endif + +#define _LIBCUDACXX_DEPRECATED_IN_CXX11 _LIBCUDACXX_DEPRECATED + +#if _LIBCUDACXX_STD_VER >= 14 +# define _LIBCUDACXX_DEPRECATED_IN_CXX14 _LIBCUDACXX_DEPRECATED +#else +# define _LIBCUDACXX_DEPRECATED_IN_CXX14 +#endif + +#if _LIBCUDACXX_STD_VER >= 17 +# define _LIBCUDACXX_DEPRECATED_IN_CXX17 _LIBCUDACXX_DEPRECATED +#else +# define _LIBCUDACXX_DEPRECATED_IN_CXX17 +#endif + +#if _LIBCUDACXX_STD_VER <= 11 +# define _LIBCUDACXX_EXPLICIT_AFTER_CXX11 +#else +# define _LIBCUDACXX_EXPLICIT_AFTER_CXX11 explicit +#endif + +#if _LIBCUDACXX_STD_VER > 11 && !defined(_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR) +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 constexpr +#else +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +#endif + +#if _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR) +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 constexpr +#else +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 +#endif + +#if _LIBCUDACXX_STD_VER > 17 && !defined(_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR) +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 constexpr +#else +# define _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +#endif + +// Macros to enter and leave a state where deprecation warnings are suppressed. +#if defined(_LIBCUDACXX_COMPILER_CLANG) || defined(_LIBCUDACXX_COMPILER_GCC) +# define _LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +# define _LIBCUDACXX_SUPPRESS_DEPRECATED_POP \ + _Pragma("GCC diagnostic pop") +#else +# define _LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH +# define _LIBCUDACXX_SUPPRESS_DEPRECATED_POP +#endif + +// The _LIBCUDACXX_NODISCARD_ATTRIBUTE should only be used to define other +// NODISCARD macros to the correct attribute. +#if __has_cpp_attribute(nodiscard) || (defined(_LIBCUDACXX_COMPILER_MSVC) && _LIBCUDACXX_STD_VER > 14) +# define _LIBCUDACXX_NODISCARD_ATTRIBUTE [[nodiscard]] +#elif defined(_LIBCUDACXX_COMPILER_CLANG) +# define _LIBCUDACXX_NODISCARD_ATTRIBUTE [[clang::warn_unused_result]] +#else +// We can't use GCC's [[gnu::warn_unused_result]] and +// __attribute__((warn_unused_result)), because GCC does not silence them via +// (void) cast. +# define _LIBCUDACXX_NODISCARD_ATTRIBUTE +#endif + +// NVCC below 11.3 does not support nodiscard on friend functions +// It always fails with clang +#if defined(_LIBCUDACXX_CUDACC_BELOW_11_3) \ + || defined(_LIBCUDACXX_COMPILER_CLANG) +# define _LIBCUDACXX_NODISCARD_FRIEND friend +#else // ^^^ _LIBCUDACXX_CUDACC_BELOW_11_3 ^^^ / vvv !_LIBCUDACXX_CUDACC_BELOW_11_3 vvv +# define _LIBCUDACXX_NODISCARD_FRIEND _LIBCUDACXX_NODISCARD_ATTRIBUTE friend +#endif // !_LIBCUDACXX_CUDACC_BELOW_11_3 && !_LIBCUDACXX_COMPILER_CLANG + +// _LIBCUDACXX_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not +// specified as such as an extension. +#if defined(_LIBCUDACXX_ENABLE_NODISCARD) && !defined(_LIBCUDACXX_DISABLE_NODISCARD_EXT) +# define _LIBCUDACXX_NODISCARD_EXT _LIBCUDACXX_NODISCARD_ATTRIBUTE +#else +# define _LIBCUDACXX_NODISCARD_EXT +#endif + +#if !defined(_LIBCUDACXX_DISABLE_NODISCARD_AFTER_CXX17) && \ + (_LIBCUDACXX_STD_VER > 17 || defined(_LIBCUDACXX_ENABLE_NODISCARD)) +# define _LIBCUDACXX_NODISCARD_AFTER_CXX17 _LIBCUDACXX_NODISCARD_ATTRIBUTE +#else +# define _LIBCUDACXX_NODISCARD_AFTER_CXX17 +#endif + +#if _LIBCUDACXX_STD_VER > 14 && defined(__cpp_inline_variables) && (__cpp_inline_variables >= 201606L) +# define _LIBCUDACXX_INLINE_VAR inline +#else +# define _LIBCUDACXX_INLINE_VAR +#endif + +#ifdef _LIBCUDACXX_HAS_NO_RVALUE_REFERENCES +# define _LIBCUDACXX_EXPLICIT_MOVE(x) _CUDA_VSTD::move(x) +#else +# define _LIBCUDACXX_EXPLICIT_MOVE(x) (x) +#endif + +#ifndef _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +#if defined(_LIBCUDACXX_DEBUG) || defined(_LIBCUDACXX_HAS_NO_CXX14_CONSTEXPR) +#define _LIBCUDACXX_CONSTEXPR_IF_NODEBUG +#else +#define _LIBCUDACXX_CONSTEXPR_IF_NODEBUG _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +#endif +#endif + +#if __has_attribute(no_destroy) +# define _LIBCUDACXX_NO_DESTROY __attribute__((__no_destroy__)) +#else +# define _LIBCUDACXX_NO_DESTROY +#endif + +#ifndef _LIBCUDACXX_HAS_NO_ASAN +extern "C" _LIBCUDACXX_FUNC_VIS void __sanitizer_annotate_contiguous_container( + const void *, const void *, const void *, const void *); +#endif + +#ifndef _LIBCUDACXX_WEAK +#define _LIBCUDACXX_WEAK __attribute__((__weak__)) +#endif + +// Redefine some macros for internal use +#if defined(__cuda_std__) +# undef _LIBCUDACXX_FUNC_VIS +# define _LIBCUDACXX_FUNC_VIS _LIBCUDACXX_INLINE_VISIBILITY +# undef _LIBCUDACXX_TYPE_VIS +# define _LIBCUDACXX_TYPE_VIS +#endif // __cuda_std__ + +// Thread API +#ifndef _LIBCUDACXX_HAS_THREAD_API_EXTERNAL +#if defined(_LIBCUDACXX_COMPILER_NVRTC) \ + || defined(__EMSCRIPTEN__) +# define _LIBCUDACXX_HAS_THREAD_API_EXTERNAL +#endif +#endif // _LIBCUDACXX_HAS_THREAD_API_EXTERNAL + +#ifndef _LIBCUDACXX_HAS_THREAD_API_CUDA +#if defined(__cuda_std__) \ + && (defined(__CUDA_ARCH__) || defined(__EMSCRIPTEN__)) +# define _LIBCUDACXX_HAS_THREAD_API_CUDA +#endif // __cuda_std__ +#endif // _LIBCUDACXX_HAS_THREAD_API_CUDA + +#ifndef _LIBCUDACXX_HAS_THREAD_API_WIN32 +#if defined(_LIBCUDACXX_COMPILER_MSVC) \ + && !defined(_LIBCUDACXX_HAS_THREAD_API_CUDA) +# define _LIBCUDACXX_HAS_THREAD_API_WIN32 +#endif +#endif // _LIBCUDACXX_HAS_THREAD_API_WIN32 + +#if !defined(_LIBCUDACXX_HAS_NO_THREADS) \ + && !defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) \ + && !defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) \ + && !defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) +# if defined(__FreeBSD__) || \ + defined(__Fuchsia__) || \ + defined(__wasi__) || \ + defined(__NetBSD__) || \ + defined(__linux__) || \ + defined(__GNU__) || \ + defined(__APPLE__) || \ + defined(__CloudABI__) || \ + defined(__sun__) || \ + (defined(__MINGW32__) && __has_include()) +# define _LIBCUDACXX_HAS_THREAD_API_PTHREAD +# elif defined(_LIBCUDACXX_WIN32API) +# define _LIBCUDACXX_HAS_THREAD_API_WIN32 +# else +# define _LIBCUDACXX_UNSUPPORTED_THREAD_API +# endif // _LIBCUDACXX_HAS_THREAD_API +#endif // _LIBCUDACXX_HAS_NO_THREADS + +#if defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) +#if defined(__ANDROID__) && __ANDROID_API__ >= 30 +#define _LIBCUDACXX_HAS_COND_CLOCKWAIT +#elif defined(_LIBCUDACXX_GLIBC_PREREQ) +#if _LIBCUDACXX_GLIBC_PREREQ(2, 30) +#define _LIBCUDACXX_HAS_COND_CLOCKWAIT +#endif +#endif +#endif + +#if defined(_LIBCUDACXX_HAS_NO_THREADS) && defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) +#error _LIBCUDACXX_HAS_THREAD_API_PTHREAD may only be defined when \ + _LIBCUDACXX_HAS_NO_THREADS is not defined. +#endif + +#if defined(_LIBCUDACXX_HAS_NO_THREADS) && defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) +#error _LIBCUDACXX_HAS_THREAD_API_EXTERNAL may not be defined when \ + _LIBCUDACXX_HAS_NO_THREADS is defined. +#endif + +#if defined(__STDCPP_THREADS__) && defined(_LIBCUDACXX_HAS_NO_THREADS) +#error _LIBCUDACXX_HAS_NO_THREADS cannot be set when __STDCPP_THREADS__ is set. +#endif + +#if !defined(_LIBCUDACXX_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) +#define __STDCPP_THREADS__ 1 +#endif + +// The glibc and Bionic implementation of pthreads implements +// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 +// mutexes have no destroy mechanism. +// +// This optimization can't be performed on Apple platforms, where +// pthread_mutex_destroy can allow the kernel to release resources. +// See https://llvm.org/D64298 for details. +// +// TODO(EricWF): Enable this optimization on Bionic after speaking to their +// respective stakeholders. +#if (defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \ + || defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) +# define _LIBCUDACXX_HAS_TRIVIAL_MUTEX_DESTRUCTION +#endif + +// Destroying a condvar is a nop on Windows. +// +// This optimization can't be performed on Apple platforms, where +// pthread_cond_destroy can allow the kernel to release resources. +// See https://llvm.org/D64298 for details. +// +// TODO(EricWF): This is potentially true for some pthread implementations +// as well. +#if defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) +# define _LIBCUDACXX_HAS_TRIVIAL_CONDVAR_DESTRUCTION +#endif + +// Systems that use capability-based security (FreeBSD with Capsicum, +// Nuxi CloudABI) may only provide local filesystem access (using *at()). +// Functions like open(), rename(), unlink() and stat() should not be +// used, as they attempt to access the global filesystem namespace. +#ifdef __CloudABI__ +#define _LIBCUDACXX_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +#endif + +// CloudABI is intended for running networked services. Processes do not +// have standard input and output channels. +#ifdef __CloudABI__ +#define _LIBCUDACXX_HAS_NO_STDIN +#define _LIBCUDACXX_HAS_NO_STDOUT +#endif + +// Some systems do not provide gets() in their C library, for security reasons. +#ifndef _LIBCUDACXX_C_HAS_NO_GETS +# if defined(_LIBCUDACXX_MSVCRT) || (defined(__FreeBSD__) && __FreeBSD__ >= 13) +# define _LIBCUDACXX_C_HAS_NO_GETS +# endif +#endif + +#if defined(__BIONIC__) || defined(__CloudABI__) || \ + defined(__Fuchsia__) || defined(__wasi__) || defined(_LIBCUDACXX_HAS_MUSL_LIBC) +#define _LIBCUDACXX_PROVIDES_DEFAULT_RUNE_TABLE +#endif + +// Thread-unsafe functions such as strtok() and localtime() +// are not available. +#ifdef __CloudABI__ +#define _LIBCUDACXX_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +#endif + +// TODO: Support C11 Atomics? +// #if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) +// # define _LIBCUDACXX_HAS_C_ATOMIC_IMP +#if defined(_LIBCUDACXX_COMPILER_ICC) +# define _LIBCUDACXX_HAS_GCC_ATOMIC_IMP +#elif defined(_LIBCUDACXX_COMPILER_CLANG) +# define _LIBCUDACXX_HAS_GCC_ATOMIC_IMP +#elif defined(_LIBCUDACXX_COMPILER_GCC) +# define _LIBCUDACXX_HAS_GCC_ATOMIC_IMP +#elif defined(_LIBCUDACXX_COMPILER_NVHPC) +# define _LIBCUDACXX_HAS_GCC_ATOMIC_IMP +#elif defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_HAS_MSVC_ATOMIC_IMPL +#endif + +// CUDA Atomics supersede host atomics in order to insert the host/device dispatch layer +#if defined(_LIBCUDACXX_COMPILER_NVCC) || defined(_LIBCUDACXX_COMPILER_NVRTC) || defined(_LIBCUDACXX_COMPILER_NVHPC) || defined(_LIBCUDACXX_CUDACC) +# define _LIBCUDACXX_HAS_CUDA_ATOMIC_IMPL +#endif + +#if (!defined(_LIBCUDACXX_HAS_C_ATOMIC_IMP) && \ + !defined(_LIBCUDACXX_HAS_GCC_ATOMIC_IMP) && \ + !defined(_LIBCUDACXX_HAS_EXTERNAL_ATOMIC_IMP)) \ + || defined(_LIBCUDACXX_HAS_NO_THREADS) +# define _LIBCUDACXX_HAS_NO_ATOMIC_HEADER +#else +# ifdef __cuda_std__ +# undef _LIBCUDACXX_ATOMIC_FLAG_TYPE +# define _LIBCUDACXX_ATOMIC_FLAG_TYPE int +# endif +# ifndef _LIBCUDACXX_ATOMIC_FLAG_TYPE +# define _LIBCUDACXX_ATOMIC_FLAG_TYPE bool +# endif +# ifdef _LIBCUDACXX_FREESTANDING +# define _LIBCUDACXX_ATOMIC_ONLY_USE_BUILTINS +# endif +#endif + +#ifndef _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +#define _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +#endif + +#if defined(_LIBCUDACXX_ENABLE_THREAD_SAFETY_ANNOTATIONS) +# if defined(_LIBCUDACXX_COMPILER_CLANG) && __has_attribute(acquire_capability) +// Work around the attribute handling in clang. When both __declspec and +// __attribute__ are present, the processing goes awry preventing the definition +// of the types. +# if !defined(_LIBCUDACXX_OBJECT_FORMAT_COFF) +# define _LIBCUDACXX_HAS_THREAD_SAFETY_ANNOTATIONS +# endif +# endif +#endif + +#if __has_attribute(require_constant_initialization) +# define _LIBCUDACXX_SAFE_STATIC __attribute__((__require_constant_initialization__)) +#else +# define _LIBCUDACXX_SAFE_STATIC +#endif + +#if !defined(_LIBCUDACXX_HAS_NO_OFF_T_FUNCTIONS) +# if defined(_LIBCUDACXX_MSVCRT) || defined(_NEWLIB_VERSION) +# define _LIBCUDACXX_HAS_NO_OFF_T_FUNCTIONS +# endif +#endif + +#if __has_attribute(diagnose_if) && !defined(_LIBCUDACXX_DISABLE_ADDITIONAL_DIAGNOSTICS) +# define _LIBCUDACXX_DIAGNOSE_WARNING(...) \ + __attribute__((diagnose_if(__VA_ARGS__, "warning"))) +# define _LIBCUDACXX_DIAGNOSE_ERROR(...) \ + __attribute__((diagnose_if(__VA_ARGS__, "error"))) +#else +# define _LIBCUDACXX_DIAGNOSE_WARNING(...) +# define _LIBCUDACXX_DIAGNOSE_ERROR(...) +#endif + +// Use a function like macro to imply that it must be followed by a semicolon +#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough) +# define _LIBCUDACXX_FALLTHROUGH() [[fallthrough]] +#elif defined(_LIBCUDACXX_COMPILER_NVRTC) +# define _LIBCUDACXX_FALLTHROUGH() ((void)0) +#elif __has_cpp_attribute(clang::fallthrough) +# define _LIBCUDACXX_FALLTHROUGH() [[clang::fallthrough]] +#elif defined(_LIBCUDACXX_COMPILER_NVHPC) +# define _LIBCUDACXX_FALLTHROUGH() +#elif __has_attribute(fallthough) || _GNUC_VER >= 700 +# define _LIBCUDACXX_FALLTHROUGH() __attribute__((__fallthrough__)) +#else +# define _LIBCUDACXX_FALLTHROUGH() ((void)0) +#endif + +#if __has_attribute(__nodebug__) +#define _LIBCUDACXX_NODEBUG __attribute__((__nodebug__)) +#else +#define _LIBCUDACXX_NODEBUG +#endif + +# if __has_attribute(__preferred_name__) +# define _LIBCUDACXX_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) +# else +# define _LIBCUDACXX_PREFERRED_NAME(x) +# endif + +#if defined(_LIBCUDACXX_ABI_MICROSOFT) && \ + (defined(_LIBCUDACXX_COMPILER_MSVC) || __has_declspec_attribute(empty_bases)) +# define _LIBCUDACXX_DECLSPEC_EMPTY_BASES __declspec(empty_bases) +#else +# define _LIBCUDACXX_DECLSPEC_EMPTY_BASES +#endif + +#if defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_FEATURES) +#define _LIBCUDACXX_ENABLE_CXX17_REMOVED_AUTO_PTR +#define _LIBCUDACXX_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS +#define _LIBCUDACXX_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE +#define _LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS +#endif // _LIBCUDACXX_ENABLE_CXX17_REMOVED_FEATURES + +#if !defined(__cpp_deduction_guides) || __cpp_deduction_guides < 201611 +#define _LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES +#endif + +#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L +#define _LIBCUDACXX_HAS_NO_COROUTINES +#endif + +// We need `is_constant_evaluated` for clang and gcc. MSVC also needs extensive rework +#if !defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) +#define _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS +#elif defined(__CUDACC_RTC__) +#define _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS +#elif defined(_MSC_VER) +#define _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS +#elif defined(_LIBCUDACXX_CUDACC_BELOW_11_8) +#define _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS +#endif + +// FIXME: Correct this macro when either (A) a feature test macro for the +// spaceship operator is provided, or (B) a compiler provides a complete +// implementation. +#define _LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR + +#define _LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS + +// The stream API was dropped and re-added in the dylib shipped on macOS +// and iOS. We can only assume the dylib to provide these definitions for +// macosx >= 10.9 and ios >= 7.0. Otherwise, the definitions are available +// from the headers, but not from the dylib. Explicit instantiation +// declarations for streams exist conditionally to this; if we provide +// an explicit instantiation declaration and we try to deploy to a dylib +// that does not provide those symbols, we'll get a load-time error. +#if !defined(_LIBCUDACXX_BUILDING_LIBRARY) && \ + ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1090) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 70000)) +# define _LIBCUDACXX_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB +#endif + +#if defined(_LIBCUDACXX_HAS_NO_PRAGMA_PUSH_POP_MACRO) +# define _LIBCUDACXX_PUSH_MACROS +# define _LIBCUDACXX_POP_MACROS +#else + // Don't warn about macro conflicts when we can restore them at the + // end of the header. +# ifndef _LIBCUDACXX_DISABLE_MACRO_CONFLICT_WARNINGS +# define _LIBCUDACXX_DISABLE_MACRO_CONFLICT_WARNINGS +# endif +# if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_PUSH_MACROS \ + __pragma(push_macro("min")) \ + __pragma(push_macro("max")) +# define _LIBCUDACXX_POP_MACROS \ + __pragma(pop_macro("min")) \ + __pragma(pop_macro("max")) +# else +# define _LIBCUDACXX_PUSH_MACROS \ + _Pragma("push_macro(\"min\")") \ + _Pragma("push_macro(\"max\")") +# define _LIBCUDACXX_POP_MACROS \ + _Pragma("pop_macro(\"min\")") \ + _Pragma("pop_macro(\"max\")") +# endif +#endif // defined(_LIBCUDACXX_HAS_NO_PRAGMA_PUSH_POP_MACRO) + +#if !defined(_LIBCUDACXX_NO_AUTO_LINK) && !defined(__cuda_std__) +# if defined(_LIBCUDACXX_ABI_MICROSOFT) && !defined(_LIBCUDACXX_BUILDING_LIBRARY) +# if defined(_DLL) +# pragma comment(lib, "c++.lib") +# else +# pragma comment(lib, "libc++.lib") +# endif +# endif // defined(_LIBCUDACXX_ABI_MICROSOFT) && !defined(_LIBCUDACXX_BUILDING_LIBRARY) +#endif // !defined(_LIBCUDACXX_NO_AUTO_LINK) + +#define _LIBCUDACXX_UNUSED_VAR(x) ((void)(x)) + +// Configures the fopen close-on-exec mode character, if any. This string will +// be appended to any mode string used by fstream for fopen/fdopen. +// +// Not all platforms support this, but it helps avoid fd-leaks on platforms that +// do. +#if defined(__BIONIC__) +# define _LIBCUDACXX_FOPEN_CLOEXEC_MODE "e" +#else +# define _LIBCUDACXX_FOPEN_CLOEXEC_MODE +#endif + +# if __has_attribute(__format__) +// The attribute uses 1-based indices for ordinary and static member functions. +// The attribute uses 2-based indices for non-static member functions. +# define _LIBCUDACXX_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ + __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) +# else +# define _LIBCUDACXX_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ +# endif + +#ifndef _LIBCUDACXX_SYS_CLOCK_DURATION +#if defined(__cuda_std__) +# define _LIBCUDACXX_SYS_CLOCK_DURATION nanoseconds +#else +# define _LIBCUDACXX_SYS_CLOCK_DURATION microseconds +#endif +#endif // _LIBCUDACXX_SYS_CLOCK_DURATION + +// There are a handful of public standard library types that are intended to +// support CTAD but don't need any explicit deduction guides to do so. This +// macro is used to mark them as such, which suppresses the +// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code +// with these classes. +#if (!defined(_LIBCUDACXX_COMPILER_GCC) || __GNUC__ > 6) \ + && _LIBCUDACXX_STD_VER >= 17 +# define _LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ + template \ + _ClassName(typename _Tag::__allow_ctad...) -> _ClassName<_Tag...> +#else +# define _LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") +#endif + +#if (defined(__CUDACC_VER_MAJOR__) && __CUDACC_VER_MAJOR__ <= 11) \ + && (defined(__CUDACC_VER_MINOR__) && __CUDACC_VER_MINOR__ <= 2) +# define _LIBCUDACXX_CONSTEXPR_GLOBAL const +#else +# define _LIBCUDACXX_CONSTEXPR_GLOBAL constexpr +#endif + +#if defined(__CUDA_ARCH__) +# define _LIBCUDACXX_CPO_ACCESSIBILITY _LIBCUDACXX_DEVICE _LIBCUDACXX_CONSTEXPR_GLOBAL +#else +# define _LIBCUDACXX_CPO_ACCESSIBILITY _LIBCUDACXX_INLINE_VAR constexpr +#endif + +#if _LIBCUDACXX_STD_VER > 14 +# define _LIBCUDACXX_TRAIT(__TRAIT, ...) __TRAIT##_v<__VA_ARGS__> +#else +# define _LIBCUDACXX_TRAIT(__TRAIT, ...) __TRAIT<__VA_ARGS__>::value +#endif + +// Older nvcc do not handle the constraint of `construct_at` in earlier std modes +// So to preserve our performance optimization we default to the unconstrained +// `__construct_at` and only in C++20 use `construct_at` +#if _LIBCUDACXX_STD_VER > 17 +# define _LIBCUDACXX_CONSTRUCT_AT(_LOCATION, ...) \ + _CUDA_VSTD::construct_at(_CUDA_VSTD::addressof(_LOCATION), __VA_ARGS__) +#else +# define _LIBCUDACXX_CONSTRUCT_AT(_LOCATION, ...) \ + _CUDA_VSTD::__construct_at(_CUDA_VSTD::addressof(_LOCATION), __VA_ARGS__) +#endif + +#if !defined(_LIBCUDACXX_DISABLE_EXEC_CHECK) +#if defined(_LIBCUDACXX_CUDACC) \ + && !defined(_LIBCUDACXX_COMPILER_NVRTC) \ + && !defined(_LIBCUDACXX_COMPILER_NVHPC_CUDA) \ + && !defined(_LIBCUDACXX_COMPILER_CLANG_CUDA) +# if defined(_LIBCUDACXX_COMPILER_MSVC) +# define _LIBCUDACXX_DISABLE_EXEC_CHECK __pragma("nv_exec_check_disable") +# else // ^^^ _LIBCUDACXX_COMPILER_MSVC ^^^ / vvv !_LIBCUDACXX_COMPILER_MSVC vvv +# define _LIBCUDACXX_DISABLE_EXEC_CHECK _Pragma("nv_exec_check_disable") +# endif // !_LIBCUDACXX_COMPILER_MSVC +#else // ^^^ !NVRTC && !NVHPC-cuda && !clang-cuda ^^^ / vvv NVRTC || NVHPC-cuda || clang-cuda vvv +# define _LIBCUDACXX_DISABLE_EXEC_CHECK +#endif // NVRTC || NVHPC-cuda || clang-cuda +#endif // !_LIBCUDACXX_DISABLE_EXEC_CHECK + +#define _LIBCUDACXX_HAS_NO_INCOMPLETE_RANGES + +#endif // __cplusplus + +#endif // _LIBCUDACXX_CONFIG diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__config_site.in b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__config_site.in new file mode 100644 index 0000000000000000000000000000000000000000..ab65c9554b0b4b5697cb3baeff154a784328ea8c --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__config_site.in @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_CONFIG_SITE +#define _LIBCUDACXX_CONFIG_SITE + +#cmakedefine _LIBCUDACXX_ABI_VERSION @_LIBCUDACXX_ABI_VERSION@ +#cmakedefine _LIBCUDACXX_ABI_UNSTABLE +#cmakedefine _LIBCUDACXX_ABI_FORCE_ITANIUM +#cmakedefine _LIBCUDACXX_ABI_FORCE_MICROSOFT +#cmakedefine _LIBCUDACXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT +#cmakedefine _LIBCUDACXX_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +#cmakedefine _LIBCUDACXX_HAS_NO_STDIN +#cmakedefine _LIBCUDACXX_HAS_NO_STDOUT +#cmakedefine _LIBCUDACXX_HAS_NO_THREADS +#cmakedefine _LIBCUDACXX_HAS_NO_MONOTONIC_CLOCK +#cmakedefine _LIBCUDACXX_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +#cmakedefine _LIBCUDACXX_HAS_MUSL_LIBC +#cmakedefine _LIBCUDACXX_HAS_THREAD_API_PTHREAD +#cmakedefine _LIBCUDACXX_HAS_THREAD_API_EXTERNAL +#cmakedefine _LIBCUDACXX_HAS_THREAD_API_WIN32 +#cmakedefine _LIBCUDACXX_HAS_THREAD_LIBRARY_EXTERNAL +#cmakedefine _LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS +#cmakedefine _LIBCUDACXX_NO_VCRUNTIME +#cmakedefine01 _LIBCUDACXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT +#cmakedefine _LIBCUDACXX_ABI_NAMESPACE @_LIBCUDACXX_ABI_NAMESPACE@ +#cmakedefine _LIBCUDACXX_HAS_PARALLEL_ALGORITHMS + +@_LIBCUDACXX_ABI_DEFINES@ + +#endif // _LIBCUDACXX_CONFIG_SITE diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/atomic.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/atomic.h new file mode 100644 index 0000000000000000000000000000000000000000..52c03fb1f05de1fa7d8d9c595f1b86ee04b4ccac --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/std/detail/libcxx/include/__cuda/atomic_prelude.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/atomic_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..1333435b9591c0f149a72701fedcf04df85f814a --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/atomic_prelude.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_ATOMIC_PRELUDE_H +#define _LIBCUDACXX___CUDA_ATOMIC_PRELUDE_H + +#ifndef __cuda_std__ +#error "<__cuda/atomic_prelude> should only be included in from " +#endif // __cuda_std__ + +#ifndef _LIBCUDACXX_COMPILER_NVRTC + #include "../cassert" // TRANSITION: Fix transitive includes + #include + static_assert(ATOMIC_BOOL_LOCK_FREE == 2, ""); + static_assert(ATOMIC_CHAR_LOCK_FREE == 2, ""); + static_assert(ATOMIC_CHAR16_T_LOCK_FREE == 2, ""); + static_assert(ATOMIC_CHAR32_T_LOCK_FREE == 2, ""); + static_assert(ATOMIC_WCHAR_T_LOCK_FREE == 2, ""); + static_assert(ATOMIC_SHORT_LOCK_FREE == 2, ""); + static_assert(ATOMIC_INT_LOCK_FREE == 2, ""); + static_assert(ATOMIC_LONG_LOCK_FREE == 2, ""); + static_assert(ATOMIC_LLONG_LOCK_FREE == 2, ""); + static_assert(ATOMIC_POINTER_LOCK_FREE == 2, ""); + #undef ATOMIC_BOOL_LOCK_FREE + #undef ATOMIC_BOOL_LOCK_FREE + #undef ATOMIC_CHAR_LOCK_FREE + #undef ATOMIC_CHAR16_T_LOCK_FREE + #undef ATOMIC_CHAR32_T_LOCK_FREE + #undef ATOMIC_WCHAR_T_LOCK_FREE + #undef ATOMIC_SHORT_LOCK_FREE + #undef ATOMIC_INT_LOCK_FREE + #undef ATOMIC_LONG_LOCK_FREE + #undef ATOMIC_LLONG_LOCK_FREE + #undef ATOMIC_POINTER_LOCK_FREE + #undef ATOMIC_FLAG_INIT + #undef ATOMIC_VAR_INIT +#endif // _LIBCUDACXX_COMPILER_NVRTC + +// pre-define lock free query for heterogeneous compatibility +#ifndef _LIBCUDACXX_ATOMIC_IS_LOCK_FREE +#define _LIBCUDACXX_ATOMIC_IS_LOCK_FREE(__x) (__x <= 8) +#endif + +#ifndef _LIBCUDACXX_COMPILER_NVRTC +#include +#include +#endif // _LIBCUDACXX_COMPILER_NVRTC + +#endif // _LIBCUDACXX___CUDA_ATOMIC_PRELUDE_H diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/barrier.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/barrier.h new file mode 100644 index 0000000000000000000000000000000000000000..d8710e5f18d33b358bd195822ff43418721179b8 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/std/detail/libcxx/include/__cuda/chrono.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/chrono.h new file mode 100644 index 0000000000000000000000000000000000000000..76798c0ac583b90f06d3e1d56637046112a60ea1 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/std/detail/libcxx/include/__cuda/climits_prelude.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/climits_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..5100f6e46437dc72375c562960610d16e6e6d69a --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/climits_prelude.h @@ -0,0 +1,95 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_CLIMITS_PRELUDE_H +#define _LIBCUDACXX___CUDA_CLIMITS_PRELUDE_H + +#ifndef __cuda_std__ +#error "<__cuda/climits_prelude> should only be included in from " +#endif // __cuda_std__ + +#ifndef _LIBCUDACXX_COMPILER_NVRTC + #include + #include + #include +#else // ^^^ !_LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv _LIBCUDACXX_COMPILER_NVRTC vvv + #define CHAR_BIT 8 + + #define SCHAR_MIN (-128) + #define SCHAR_MAX 127 + #define UCHAR_MAX 255 + #define __CHAR_UNSIGNED__ ('\xff' > 0) // CURSED + #if __CHAR_UNSIGNED__ + #define CHAR_MIN 0 + #define CHAR_MAX UCHAR_MAX + #else + #define CHAR_MIN SCHAR_MIN + #define CHAR_MAX SCHAR_MAX + #endif + #define SHRT_MIN (-SHRT_MAX - 1) + #define SHRT_MAX 0x7fff + #define USHRT_MAX 0xffff + #define INT_MIN (-INT_MAX - 1) + #define INT_MAX 0x7fffffff + #define UINT_MAX 0xffffffff + #define LONG_MIN (-LONG_MAX - 1) + #ifdef __LP64__ + #define LONG_MAX LLONG_MAX + #define ULONG_MAX ULLONG_MAX + #else + #define LONG_MAX INT_MAX + #define ULONG_MAX UINT_MAX + #endif + #define LLONG_MIN (-LLONG_MAX - 1) + #define LLONG_MAX 0x7fffffffffffffffLL + #define ULLONG_MAX 0xffffffffffffffffUL + + #define __FLT_RADIX__ 2 + #define __FLT_MANT_DIG__ 24 + #define __FLT_DIG__ 6 + #define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F + #define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F + #define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F + #define __FLT_MIN_EXP__ (-125) + #define __FLT_MIN_10_EXP__ (-37) + #define __FLT_MAX_EXP__ 128 + #define __FLT_MAX_10_EXP__ 38 + #define __FLT_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F + #define __DBL_MANT_DIG__ 53 + #define __DBL_DIG__ 15 + #define __DBL_MIN__ 2.22507385850720138309023271733240406e-308 + #define __DBL_MAX__ 1.79769313486231570814527423731704357e+308 + #define __DBL_EPSILON__ 2.22044604925031308084726333618164062e-16 + #define __DBL_MIN_EXP__ (-1021) + #define __DBL_MIN_10_EXP__ (-307) + #define __DBL_MAX_EXP__ 1024 + #define __DBL_MAX_10_EXP__ 308 + #define __DBL_DENORM_MIN__ 4.94065645841246544176568792868221372e-324 + + template + static _LIBCUDACXX_DEVICE _LIBCUDACXX_FORCE_INLINE + _To __cowchild_cast(_From __from) + { + static_assert(sizeof(_From) == sizeof(_To), ""); + union __cast { _From __from; _To __to; }; + __cast __c; + __c.__from = __from; + return __c.__to; + } + + #define __builtin_huge_valf() __cowchild_cast(0x7f800000) + #define __builtin_nanf(__dummy) __cowchild_cast(0x7fc00000) + #define __builtin_nansf(__dummy) __cowchild_cast(0x7fa00000) + #define __builtin_huge_val() __cowchild_cast(0x7ff0000000000000) + #define __builtin_nan(__dummy) __cowchild_cast(0x7ff8000000000000) + #define __builtin_nans(__dummy) __cowchild_cast(0x7ff4000000000000) +#endif // _LIBCUDACXX_COMPILER_NVRTC + +#endif // _LIBCUDACXX___CUDA_CLIMITS_PRELUDE_H diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/cstddef_prelude.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/cstddef_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..992288ce0fae2e2b16f31c62a8921d358da24516 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/cstddef_prelude.h @@ -0,0 +1,31 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_CSTDDEF_PRELUDE_H +#define _LIBCUDACXX___CUDA_CSTDDEF_PRELUDE_H + +#ifndef __cuda_std__ +#error "<__cuda/cstddef_prelude> should only be included in from " +#endif // __cuda_std__ + +#ifndef _LIBCUDACXX_COMPILER_NVRTC +#include +#include +#else +#define offsetof(type, member) (_CUDA_VSTD::size_t)((char*)&(((type *)0)->member) - (char*)0) +#endif // _LIBCUDACXX_COMPILER_NVRTC + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +typedef decltype(nullptr) nullptr_t; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___CUDA_CSTDDEF_PRELUDE_H diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/cstdint_prelude.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/cstdint_prelude.h new file mode 100644 index 0000000000000000000000000000000000000000..1f4b35eb301664892161214fa47564511b527187 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/cstdint_prelude.h @@ -0,0 +1,84 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_CSTDINT_PRELUDE_H +#define _LIBCUDACXX___CUDA_CSTDINT_PRELUDE_H + +#ifndef __cuda_std__ +#error "<__cuda/cstdint_prelude> should only be included in from " +#endif // __cuda_std__ + +#ifndef _LIBCUDACXX_COMPILER_NVRTC + #include +#else // ^^^ !_LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv _LIBCUDACXX_COMPILER_NVRTC vvv + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef signed short int16_t; + typedef unsigned short uint16_t; + typedef signed int int32_t; + typedef unsigned int uint32_t; + typedef signed long long int64_t; + typedef unsigned long long uint64_t; + +#define _LIBCUDACXX_ADDITIONAL_INTS(N) \ + typedef int##N##_t int_fast##N##_t; \ + typedef uint##N##_t uint_fast##N##_t; \ + typedef int##N##_t int_least##N##_t; \ + typedef uint##N##_t uint_least##N##_t + + _LIBCUDACXX_ADDITIONAL_INTS(8); + _LIBCUDACXX_ADDITIONAL_INTS(16); + _LIBCUDACXX_ADDITIONAL_INTS(32); + _LIBCUDACXX_ADDITIONAL_INTS(64); +#undef _LIBCUDACXX_ADDITIONAL_INTS + + typedef int64_t intptr_t; + typedef uint64_t uintptr_t; + typedef int64_t intmax_t; + typedef uint64_t uintmax_t; + + #define INT8_MIN SCHAR_MIN + #define INT16_MIN SHRT_MIN + #define INT32_MIN INT_MIN + #define INT64_MIN LLONG_MIN + #define INT8_MAX SCHAR_MAX + #define INT16_MAX SHRT_MAX + #define INT32_MAX INT_MAX + #define INT64_MAX LLONG_MAX + #define UINT8_MAX UCHAR_MAX + #define UINT16_MAX USHRT_MAX + #define UINT32_MAX UINT_MAX + #define UINT64_MAX ULLONG_MAX + #define INT_FAST8_MIN SCHAR_MIN + #define INT_FAST16_MIN SHRT_MIN + #define INT_FAST32_MIN INT_MIN + #define INT_FAST64_MIN LLONG_MIN + #define INT_FAST8_MAX SCHAR_MAX + #define INT_FAST16_MAX SHRT_MAX + #define INT_FAST32_MAX INT_MAX + #define INT_FAST64_MAX LLONG_MAX + #define UINT_FAST8_MAX UCHAR_MAX + #define UINT_FAST16_MAX USHRT_MAX + #define UINT_FAST32_MAX UINT_MAX + #define UINT_FAST64_MAX ULLONG_MAX + + #define INT8_C(X) ((int_least8_t)(X)) + #define INT16_C(X) ((int_least16_t)(X)) + #define INT32_C(X) ((int_least32_t)(X)) + #define INT64_C(X) ((int_least64_t)(X)) + #define UINT8_C(X) ((uint_least8_t)(X)) + #define UINT16_C(X) ((uint_least16_t)(X)) + #define UINT32_C(X) ((uint_least32_t)(X)) + #define UINT64_C(X) ((uint_least64_t)(X)) + #define INTMAX_C(X) ((intmax_t)(X)) + #define UINTMAX_C(X) ((uintmax_t)(X)) +#endif // _LIBCUDACXX_COMPILER_NVRTC + +#endif // _LIBCUDACXX___CUDA_CSTDINT_PRELUDE_H diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/latch.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/latch.h new file mode 100644 index 0000000000000000000000000000000000000000..1a2af3c408d0ce5e7ee06a598bd7fac24130d34e --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/latch.h @@ -0,0 +1,31 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___CUDA_LATCH_H +#define _LIBCUDACXX___CUDA_LATCH_H + +#ifndef __cuda_std__ +#error "<__cuda/latch> should only be included in from " +#endif // __cuda_std__ + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +template +class latch : public _CUDA_VSTD::__latch_base<_Sco> { +public: + _LIBCUDACXX_INLINE_VISIBILITY 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/std/detail/libcxx/include/__cuda/ptx.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/ptx.h new file mode 100644 index 0000000000000000000000000000000000000000..20ffafde10935cafc8a1f496b17a323eb92ecd9e --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/std/detail/libcxx/include/__cuda/semaphore.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__cuda/semaphore.h new file mode 100644 index 0000000000000000000000000000000000000000..27e9e4ff08d7ef8a65a94280942b1cb16d62ebba --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__debug b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__debug new file mode 100644 index 0000000000000000000000000000000000000000..30d5f9b2843f1b933ed392fa845028ab250ce961 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__debug @@ -0,0 +1,279 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___DEBUG +#define _LIBCUDACXX___DEBUG + +#ifndef __cuda_std__ +#include <__config> +#endif //__cuda_std__ + +#include "__assert" +#include "__type_traits/is_constant_evaluated.h" +#include "cstddef" + +#if defined(_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_ENABLE_DEBUG_MODE) && !defined(_LIBCUDACXX_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY) +# define _LIBCUDACXX_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY +#endif + +#if defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) && !defined(_LIBCUDACXX_DEBUG_ITERATOR_BOUNDS_CHECKING) +# define _LIBCUDACXX_DEBUG_ITERATOR_BOUNDS_CHECKING +#endif + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE +# define _LIBCUDACXX_DEBUG_ASSERT(x, m) _LIBCUDACXX_ASSERT(::std::__libcpp_is_constant_evaluated() || (x), m) +#else +# define _LIBCUDACXX_DEBUG_ASSERT(x, m) ((void)0) +#endif + +#if defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) || defined(_LIBCUDACXX_BUILDING_LIBRARY) + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +struct _LIBCUDACXX_TYPE_VIS __c_node; + +struct _LIBCUDACXX_TYPE_VIS __i_node +{ + void* __i_; + __i_node* __next_; + __c_node* __c_; + + __i_node(const __i_node&) = delete; + __i_node& operator=(const __i_node&) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY + __i_node(void* __i, __i_node* __next, __c_node* __c) + : __i_(__i), __next_(__next), __c_(__c) {} + ~__i_node(); +}; + +struct _LIBCUDACXX_TYPE_VIS __c_node +{ + void* __c_; + __c_node* __next_; + __i_node** beg_; + __i_node** end_; + __i_node** cap_; + + __c_node(const __c_node&) = delete; + __c_node& operator=(const __c_node&) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __c_node(void* __c, __c_node* __next) + : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} + virtual ~__c_node(); + + virtual bool __dereferenceable(const void*) const = 0; + virtual bool __decrementable(const void*) const = 0; + virtual bool __addable(const void*, ptrdiff_t) const = 0; + virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; + + void __add(__i_node* __i); + _LIBCUDACXX_HIDDEN void __remove(__i_node* __i); +}; + +template +struct _C_node + : public __c_node +{ + explicit _C_node(void* __c, __c_node* __n) + : __c_node(__c, __n) {} + + bool __dereferenceable(const void*) const override; + bool __decrementable(const void*) const override; + bool __addable(const void*, ptrdiff_t) const override; + bool __subscriptable(const void*, ptrdiff_t) const override; +}; + +template +inline bool +_C_node<_Cont>::__dereferenceable(const void* __i) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__dereferenceable(__j); +} + +template +inline bool +_C_node<_Cont>::__decrementable(const void* __i) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__decrementable(__j); +} + +template +inline bool +_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__addable(__j, __n); +} + +template +inline bool +_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__subscriptable(__j, __n); +} + +class _LIBCUDACXX_TYPE_VIS __libcpp_db +{ + __c_node** __cbeg_; + __c_node** __cend_; + size_t __csz_; + __i_node** __ibeg_; + __i_node** __iend_; + size_t __isz_; + + explicit __libcpp_db(); +public: + __libcpp_db(const __libcpp_db&) = delete; + __libcpp_db& operator=(const __libcpp_db&) = delete; + + ~__libcpp_db(); + + class __db_c_iterator; + class __db_c_const_iterator; + class __db_i_iterator; + class __db_i_const_iterator; + + __db_c_const_iterator __c_end() const; + __db_i_const_iterator __i_end() const; + + typedef __c_node*(_InsertConstruct)(void*, void*, __c_node*); + + template + _LIBCUDACXX_INLINE_VISIBILITY static __c_node* __create_C_node(void *__mem, void *__c, __c_node *__next) { + return ::new (__mem) _C_node<_Cont>(__c, __next); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + void __insert_c(_Cont* __c) + { + __insert_c(static_cast(__c), &__create_C_node<_Cont>); + } + + void __insert_i(void* __i); + void __insert_c(void* __c, _InsertConstruct* __fn); + void __erase_c(void* __c); + + void __insert_ic(void* __i, const void* __c); + void __iterator_copy(void* __i, const void* __i0); + void __erase_i(void* __i); + + void* __find_c_from_i(void* __i) const; + void __invalidate_all(void* __c); + __c_node* __find_c_and_lock(void* __c) const; + __c_node* __find_c(void* __c) const; + void unlock() const; + + void swap(void* __c1, void* __c2); + + + bool __dereferenceable(const void* __i) const; + bool __decrementable(const void* __i) const; + bool __addable(const void* __i, ptrdiff_t __n) const; + bool __subscriptable(const void* __i, ptrdiff_t __n) const; + bool __less_than_comparable(const void* __i, const void* __j) const; +private: + _LIBCUDACXX_HIDDEN + __i_node* __insert_iterator(void* __i); + _LIBCUDACXX_HIDDEN + __i_node* __find_iterator(const void* __i) const; + + friend _LIBCUDACXX_FUNC_VIS __libcpp_db* __get_db(); +}; + +_LIBCUDACXX_FUNC_VIS __libcpp_db* __get_db(); +_LIBCUDACXX_FUNC_VIS const __libcpp_db* __get_const_db(); + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) || defined(_LIBCUDACXX_BUILDING_LIBRARY) + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_c(_Tp* __c) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(__c); +#else + (void)(__c); +#endif +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_i(_Tp* __i) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_i(__i); +#else + (void)(__i); +#endif +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 inline void __debug_db_erase_c(_Tp* __c) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + if (!__libcpp_is_constant_evaluated()) + __get_db()->__erase_c(__c); +#else + (void)(__c); +#endif +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 inline void __debug_db_swap(_Tp* __lhs, _Tp* __rhs) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + if (!__libcpp_is_constant_evaluated()) + __get_db()->swap(__lhs, __rhs); +#else + (void)(__lhs); + (void)(__rhs); +#endif +} + +template +_LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 inline void __debug_db_invalidate_all(_Tp* __c) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + if (!__libcpp_is_constant_evaluated()) + __get_db()->__invalidate_all(__c); +#else + (void)(__c); +#endif +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___DEBUG diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__errc b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__errc new file mode 100644 index 0000000000000000000000000000000000000000..f58e63e436e3ae811cc6fa7d86488d91b4ac3ee3 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__errc @@ -0,0 +1,221 @@ +// -*- C++ -*- +//===---------------------------- __errc ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___ERRC +#define _LIBCUDACXX___ERRC + +/* + system_error synopsis + +namespace std +{ + +enum class errc +{ + address_family_not_supported, // EAFNOSUPPORT + address_in_use, // EADDRINUSE + address_not_available, // EADDRNOTAVAIL + already_connected, // EISCONN + argument_list_too_long, // E2BIG + argument_out_of_domain, // EDOM + bad_address, // EFAULT + bad_file_descriptor, // EBADF + bad_message, // EBADMSG + broken_pipe, // EPIPE + connection_aborted, // ECONNABORTED + connection_already_in_progress, // EALREADY + connection_refused, // ECONNREFUSED + connection_reset, // ECONNRESET + cross_device_link, // EXDEV + destination_address_required, // EDESTADDRREQ + device_or_resource_busy, // EBUSY + directory_not_empty, // ENOTEMPTY + executable_format_error, // ENOEXEC + file_exists, // EEXIST + file_too_large, // EFBIG + filename_too_long, // ENAMETOOLONG + function_not_supported, // ENOSYS + host_unreachable, // EHOSTUNREACH + identifier_removed, // EIDRM + illegal_byte_sequence, // EILSEQ + inappropriate_io_control_operation, // ENOTTY + interrupted, // EINTR + invalid_argument, // EINVAL + invalid_seek, // ESPIPE + io_error, // EIO + is_a_directory, // EISDIR + message_size, // EMSGSIZE + network_down, // ENETDOWN + network_reset, // ENETRESET + network_unreachable, // ENETUNREACH + no_buffer_space, // ENOBUFS + no_child_process, // ECHILD + no_link, // ENOLINK + no_lock_available, // ENOLCK + no_message_available, // ENODATA + no_message, // ENOMSG + no_protocol_option, // ENOPROTOOPT + no_space_on_device, // ENOSPC + no_stream_resources, // ENOSR + no_such_device_or_address, // ENXIO + no_such_device, // ENODEV + no_such_file_or_directory, // ENOENT + no_such_process, // ESRCH + not_a_directory, // ENOTDIR + not_a_socket, // ENOTSOCK + not_a_stream, // ENOSTR + not_connected, // ENOTCONN + not_enough_memory, // ENOMEM + not_supported, // ENOTSUP + operation_canceled, // ECANCELED + operation_in_progress, // EINPROGRESS + operation_not_permitted, // EPERM + operation_not_supported, // EOPNOTSUPP + operation_would_block, // EWOULDBLOCK + owner_dead, // EOWNERDEAD + permission_denied, // EACCES + protocol_error, // EPROTO + protocol_not_supported, // EPROTONOSUPPORT + read_only_file_system, // EROFS + resource_deadlock_would_occur, // EDEADLK + resource_unavailable_try_again, // EAGAIN + result_out_of_range, // ERANGE + state_not_recoverable, // ENOTRECOVERABLE + stream_timeout, // ETIME + text_file_busy, // ETXTBSY + timed_out, // ETIMEDOUT + too_many_files_open_in_system, // ENFILE + too_many_files_open, // EMFILE + too_many_links, // EMLINK + too_many_symbolic_link_levels, // ELOOP + value_too_large, // EOVERFLOW + wrong_protocol_type // EPROTOTYPE +}; + +*/ + +#include <__config> +#include + +#if defined(_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 + +// Some error codes are not present on all platforms, so we provide equivalents +// for them: + +//enum class errc +_LIBCUDACXX_DECLARE_STRONG_ENUM(errc) +{ + address_family_not_supported = EAFNOSUPPORT, + address_in_use = EADDRINUSE, + address_not_available = EADDRNOTAVAIL, + already_connected = EISCONN, + argument_list_too_long = E2BIG, + argument_out_of_domain = EDOM, + bad_address = EFAULT, + bad_file_descriptor = EBADF, + bad_message = EBADMSG, + broken_pipe = EPIPE, + connection_aborted = ECONNABORTED, + connection_already_in_progress = EALREADY, + connection_refused = ECONNREFUSED, + connection_reset = ECONNRESET, + cross_device_link = EXDEV, + destination_address_required = EDESTADDRREQ, + device_or_resource_busy = EBUSY, + directory_not_empty = ENOTEMPTY, + executable_format_error = ENOEXEC, + file_exists = EEXIST, + file_too_large = EFBIG, + filename_too_long = ENAMETOOLONG, + function_not_supported = ENOSYS, + host_unreachable = EHOSTUNREACH, + identifier_removed = EIDRM, + illegal_byte_sequence = EILSEQ, + inappropriate_io_control_operation = ENOTTY, + interrupted = EINTR, + invalid_argument = EINVAL, + invalid_seek = ESPIPE, + io_error = EIO, + is_a_directory = EISDIR, + message_size = EMSGSIZE, + network_down = ENETDOWN, + network_reset = ENETRESET, + network_unreachable = ENETUNREACH, + no_buffer_space = ENOBUFS, + no_child_process = ECHILD, + no_link = ENOLINK, + no_lock_available = ENOLCK, +#ifdef ENODATA + no_message_available = ENODATA, +#else + no_message_available = ENOMSG, +#endif + no_message = ENOMSG, + no_protocol_option = ENOPROTOOPT, + no_space_on_device = ENOSPC, +#ifdef ENOSR + no_stream_resources = ENOSR, +#else + no_stream_resources = ENOMEM, +#endif + no_such_device_or_address = ENXIO, + no_such_device = ENODEV, + no_such_file_or_directory = ENOENT, + no_such_process = ESRCH, + not_a_directory = ENOTDIR, + not_a_socket = ENOTSOCK, +#ifdef ENOSTR + not_a_stream = ENOSTR, +#else + not_a_stream = EINVAL, +#endif + not_connected = ENOTCONN, + not_enough_memory = ENOMEM, + not_supported = ENOTSUP, + operation_canceled = ECANCELED, + operation_in_progress = EINPROGRESS, + operation_not_permitted = EPERM, + operation_not_supported = EOPNOTSUPP, + operation_would_block = EWOULDBLOCK, + owner_dead = EOWNERDEAD, + permission_denied = EACCES, + protocol_error = EPROTO, + protocol_not_supported = EPROTONOSUPPORT, + read_only_file_system = EROFS, + resource_deadlock_would_occur = EDEADLK, + resource_unavailable_try_again = EAGAIN, + result_out_of_range = ERANGE, + state_not_recoverable = ENOTRECOVERABLE, +#ifdef ETIME + stream_timeout = ETIME, +#else + stream_timeout = ETIMEDOUT, +#endif + text_file_busy = ETXTBSY, + timed_out = ETIMEDOUT, + too_many_files_open_in_system = ENFILE, + too_many_files_open = EMFILE, + too_many_links = EMLINK, + too_many_symbolic_link_levels = ELOOP, + value_too_large = EOVERFLOW, + wrong_protocol_type = EPROTOTYPE +}; +_LIBCUDACXX_DECLARE_STRONG_ENUM_EPILOG(errc) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___ERRC diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__expected/bad_expected_access.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__expected/bad_expected_access.h new file mode 100644 index 0000000000000000000000000000000000000000..d77b56c1352e6ef1d49dd8b9b37202a3255eea31 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__expected/expected.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__expected/expected.h new file mode 100644 index 0000000000000000000000000000000000000000..1550b16d2ea6a8650c773d17cacad427b1e6b008 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__expected/expected_base.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__expected/expected_base.h new file mode 100644 index 0000000000000000000000000000000000000000..c8cc960e13ed3472b72b5b9945d8be9ccde9f0cf --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__expected/unexpect.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__expected/unexpect.h new file mode 100644 index 0000000000000000000000000000000000000000..f9a0f8a522dc6b27611df09130913168a8a10f21 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__expected/unexpected.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__expected/unexpected.h new file mode 100644 index 0000000000000000000000000000000000000000..7020365c1aed0dd66dfe5b75bf2c4f700834bb54 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/binary_function.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/binary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..22bd6068faf8ac62a43cdb3a16de4bfabac30660 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/binary_negate.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/binary_negate.h new file mode 100644 index 0000000000000000000000000000000000000000..9b45f479fc99256b57d72ac3f177004e490aee74 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/bind.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/bind.h new file mode 100644 index 0000000000000000000000000000000000000000..9e573a23320632d922fc5b25141e028fd23a88a5 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/bind_back.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/bind_back.h new file mode 100644 index 0000000000000000000000000000000000000000..927511f3c7e925c3c65095ade19e21abd89826cc --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/bind_front.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/bind_front.h new file mode 100644 index 0000000000000000000000000000000000000000..33b334d3f3f59110750a2329299f3e6c3c31d869 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/binder1st.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/binder1st.h new file mode 100644 index 0000000000000000000000000000000000000000..501157bcfb74f6c9ec2ff89deb2d0a821c9e4cb0 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/binder2nd.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/binder2nd.h new file mode 100644 index 0000000000000000000000000000000000000000..535ff2d3acb80983ea5535b41f31459f4214c8ee --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/compose.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/compose.h new file mode 100644 index 0000000000000000000000000000000000000000..c7a9fdb2b50406ceb419cd186da02fb95045f152 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/default_searcher.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/default_searcher.h new file mode 100644 index 0000000000000000000000000000000000000000..864a1e86fba0941e57083b71848cce979254cc05 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/function.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/function.h new file mode 100644 index 0000000000000000000000000000000000000000..b1cb54c6c4824ea0e9c8cc5d17a1d52732ed2a13 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/hash.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/hash.h new file mode 100644 index 0000000000000000000000000000000000000000..711a06ee2e4e7449c71a3037d46096f5fffcd53d --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/identity.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/identity.h new file mode 100644 index 0000000000000000000000000000000000000000..0c5611241032567e8601e050bdc4afb078034708 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/invoke.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/invoke.h new file mode 100644 index 0000000000000000000000000000000000000000..6be9dd5cfefce71492f5d4147a87f2975ed2b6af --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/is_transparent.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/is_transparent.h new file mode 100644 index 0000000000000000000000000000000000000000..45d5aaba2e4cae79562730df457529dd022f80f9 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/mem_fn.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/mem_fn.h new file mode 100644 index 0000000000000000000000000000000000000000..d2011874819ccf61ec8c337fb1568a0767ca2105 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/mem_fun_ref.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/mem_fun_ref.h new file mode 100644 index 0000000000000000000000000000000000000000..216b3b7a90b474392369211d7973ff0f6eff1512 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/not_fn.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/not_fn.h new file mode 100644 index 0000000000000000000000000000000000000000..4b6b0fb3ccd7fca6ac44d7ac87e331b908209147 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/operations.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/operations.h new file mode 100644 index 0000000000000000000000000000000000000000..2fb6df4d6f1e90897a7d31a0223d4bf51794e81b --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/perfect_forward.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/perfect_forward.h new file mode 100644 index 0000000000000000000000000000000000000000..98e5638992721f6f5687b28207b3f394c58f3f14 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/pointer_to_binary_function.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/pointer_to_binary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..784fda73fed96063814364a598b95549a7fd8353 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/pointer_to_unary_function.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/pointer_to_unary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..523665e9406756a4c6eb0059223441963e3ff087 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/ranges_operations.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/ranges_operations.h new file mode 100644 index 0000000000000000000000000000000000000000..7445367470a82f0dad7e48c40425af6232acc26f --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/reference_wrapper.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/reference_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..afd61e7e2fd11ac115b3e9329ea5eb556cdda979 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/unary_function.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/unary_function.h new file mode 100644 index 0000000000000000000000000000000000000000..90bcfe38421408355d3a182a802cdacef52834df --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/unary_negate.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/unary_negate.h new file mode 100644 index 0000000000000000000000000000000000000000..c0f833d8d08b1642afc6a1fac9021026bb8506cf --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/unwrap_ref.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/unwrap_ref.h new file mode 100644 index 0000000000000000000000000000000000000000..398ff118919bb1d7680b691bbeeac9295d540bfb --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional/weak_result_type.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional/weak_result_type.h new file mode 100644 index 0000000000000000000000000000000000000000..8c5b5232d89a259ce78d93b9abd76de1ce98a9cf --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__functional_base b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional_base new file mode 100644 index 0000000000000000000000000000000000000000..b3a3b064adb0afbcd1b0f1f58946fcc7553cb1cf --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__functional_base @@ -0,0 +1,138 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX_FUNCTIONAL_BASE +#define _LIBCUDACXX_FUNCTIONAL_BASE + +#ifndef __cuda_std__ +#include <__config> +#include +#include +#include +#endif // __cuda_std__ + +#include "__functional/binary_function.h" +#include "__functional/operations.h" +#include "__functional/reference_wrapper.h" +#include "__functional/unary_function.h" +#include "__functional/weak_result_type.h" +#include "__type_traits/integral_constant.h" +#include "__type_traits/is_constructible.h" +#include "__type_traits/is_convertible.h" +#include "__type_traits/remove_cvref.h" +#include "__utility/forward.h" + +#ifndef __cuda_std__ +#include <__pragma_push> +#endif // __cuda_std__ + +#if defined(_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 + +// allocator_arg_t + +struct _LIBCUDACXX_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; }; + +#if defined(_LIBCUDACXX_BUILDING_LIBRARY) +extern _LIBCUDACXX_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg; +#else +/* _LIBCUDACXX_INLINE_VAR */ constexpr allocator_arg_t allocator_arg = allocator_arg_t(); +#endif + +// uses_allocator + +template +struct __has_allocator_type +{ +private: + struct __two {char __lx; char __lxx;}; + template _LIBCUDACXX_INLINE_VISIBILITY static __two __test(...); + template _LIBCUDACXX_INLINE_VISIBILITY static char __test(typename _Up::allocator_type* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template ::value> +struct __uses_allocator + : public integral_constant::value> +{ +}; + +template +struct __uses_allocator<_Tp, _Alloc, false> + : public false_type +{ +}; + +template +struct _LIBCUDACXX_TEMPLATE_VIS uses_allocator + : public __uses_allocator<_Tp, _Alloc> +{ +}; + +#if _LIBCUDACXX_STD_VER > 14 +template +_LIBCUDACXX_INLINE_VAR constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value; +#endif + +// allocator construction + +template +struct __uses_alloc_ctor_imp +{ + typedef _LIBCUDACXX_NODEBUG_TYPE __remove_cvref_t<_Alloc> _RawAlloc; + static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value; + static const bool __ic = + is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; + static const int value = __ua ? 2 - __ic : 0; +}; + +template +struct __uses_alloc_ctor + : integral_constant::value> + {}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void __user_alloc_construct_impl (integral_constant, _Tp *__storage, const _Allocator &, _Args &&... __args ) +{ + new (__storage) _Tp (_CUDA_VSTD::forward<_Args>(__args)...); +} + +// FIXME: This should have a version which takes a non-const alloc. +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void __user_alloc_construct_impl (integral_constant, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) +{ + new (__storage) _Tp (allocator_arg, __a, _CUDA_VSTD::forward<_Args>(__args)...); +} + +// FIXME: This should have a version which takes a non-const alloc. +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void __user_alloc_construct_impl (integral_constant, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) +{ + new (__storage) _Tp (_CUDA_VSTD::forward<_Args>(__args)..., __a); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#ifndef __cuda_std__ +#include <__pragma_pop> +#endif // __cuda_std__ + +#endif // _LIBCUDACXX_FUNCTIONAL_BASE diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__fwd/array.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__fwd/array.h new file mode 100644 index 0000000000000000000000000000000000000000..d07e5642bb9df4b74fd081ec3f33e36e70ae23bd --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__fwd/get.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__fwd/get.h new file mode 100644 index 0000000000000000000000000000000000000000..3d246552b84b4f360f2cca326139f24682a71a75 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__fwd/hash.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__fwd/hash.h new file mode 100644 index 0000000000000000000000000000000000000000..b91a9b6a82582a17200d4883e8e164ba02dd3c86 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__fwd/memory_resource.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__fwd/memory_resource.h new file mode 100644 index 0000000000000000000000000000000000000000..38803984ec081d44029d1c9bb2f4423864395978 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__fwd/pair.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__fwd/pair.h new file mode 100644 index 0000000000000000000000000000000000000000..85fd027daef2c1b8a976b6034cfeec1b7eaffe59 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__fwd/span.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__fwd/span.h new file mode 100644 index 0000000000000000000000000000000000000000..4bb75bf880344a400fede8fac86d26650bab3704 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__fwd/string.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__fwd/string.h new file mode 100644 index 0000000000000000000000000000000000000000..6086f44adf4e23734c85a62728bb2045bf4473d5 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__fwd/string_view.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__fwd/string_view.h new file mode 100644 index 0000000000000000000000000000000000000000..12e640f01acf8b7cfedebb0fb4e8cb5fd061c42b --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__fwd/tuple.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__fwd/tuple.h new file mode 100644 index 0000000000000000000000000000000000000000..0a3b523052166e5fa2d1bf9e6c1ca47d293778bc --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__fwd/tuple.h @@ -0,0 +1,32 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FWD_TUPLE_H +#define _LIBCUDACXX___FWD_TUPLE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if defined(_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/cuda/std/detail/libcxx/include/__hash_table b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__hash_table new file mode 100644 index 0000000000000000000000000000000000000000..fe07ded537471e6b8093984d8ea4731d7259646a --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__hash_table @@ -0,0 +1,2806 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX__HASH_TABLE +#define _LIBCUDACXX__HASH_TABLE + +#include <__config> +#include +#include +#include +#include +#include +#include +#include + +#include "__assert" // all public C++ headers provide the assertion handler +#include "__debug" + +#if defined(_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_PUSH_MACROS +#include <__undef_macros> + + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct __hash_value_type; + +template +struct __is_hash_value_type_imp : false_type {}; + +template +struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {}; + +template +struct __is_hash_value_type : false_type {}; + +template +struct __is_hash_value_type<_One> : __is_hash_value_type_imp<__remove_cvref_t<_One>> {}; + +_LIBCUDACXX_FUNC_VIS +size_t __next_prime(size_t __n); + +template +struct __hash_node_base +{ + typedef typename pointer_traits<_NodePtr>::element_type __node_type; + typedef __hash_node_base __first_node; + typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer; + typedef _NodePtr __node_pointer; + +#if defined(_LIBCUDACXX_ABI_FIX_UNORDERED_NODE_POINTER_UB) + typedef __node_base_pointer __next_pointer; +#else + typedef typename conditional< + is_pointer<__node_pointer>::value, + __node_base_pointer, + __node_pointer>::type __next_pointer; +#endif + + __next_pointer __next_; + + _LIBCUDACXX_INLINE_VISIBILITY + __next_pointer __ptr() noexcept { + return static_cast<__next_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(*this)); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __node_pointer __upcast() noexcept { + return static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(*this)); + } + + _LIBCUDACXX_INLINE_VISIBILITY + size_t __hash() const noexcept { + return static_cast<__node_type const&>(*this).__hash_; + } + + _LIBCUDACXX_INLINE_VISIBILITY __hash_node_base() noexcept : __next_(nullptr) {} +}; + +template +struct __hash_node + : public __hash_node_base + < + typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type + > +{ + typedef _Tp __node_value_type; + + size_t __hash_; + __node_value_type __value_; +}; + +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +__is_hash_power2(size_t __bc) +{ + return __bc > 2 && !(__bc & (__bc - 1)); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t +__constrain_hash(size_t __h, size_t __bc) +{ + return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : + (__h < __bc ? __h : __h % __bc); +} + +inline _LIBCUDACXX_INLINE_VISIBILITY +size_t +__next_hash_pow2(size_t __n) +{ + return __n < 2 ? __n : (size_t(1) << (std::numeric_limits::digits - __libcpp_clz(__n-1))); +} + + +template class __hash_table; + +template class _LIBCUDACXX_TEMPLATE_VIS __hash_iterator; +template class _LIBCUDACXX_TEMPLATE_VIS __hash_const_iterator; +template class _LIBCUDACXX_TEMPLATE_VIS __hash_local_iterator; +template class _LIBCUDACXX_TEMPLATE_VIS __hash_const_local_iterator; +template class _LIBCUDACXX_TEMPLATE_VIS __hash_map_iterator; +template class _LIBCUDACXX_TEMPLATE_VIS __hash_map_const_iterator; + +template +struct __hash_key_value_types { + static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, ""); + typedef _Tp key_type; + typedef _Tp __node_value_type; + typedef _Tp __container_value_type; + static const bool __is_map = false; + + _LIBCUDACXX_INLINE_VISIBILITY + static key_type const& __get_key(_Tp const& __v) { + return __v; + } + _LIBCUDACXX_INLINE_VISIBILITY + static __container_value_type const& __get_value(__node_value_type const& __v) { + return __v; + } + _LIBCUDACXX_INLINE_VISIBILITY + static __container_value_type* __get_ptr(__node_value_type& __n) { + return _CUDA_VSTD::addressof(__n); + } + _LIBCUDACXX_INLINE_VISIBILITY + static __container_value_type&& __move(__node_value_type& __v) { + return _CUDA_VSTD::move(__v); + } +}; + +template +struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > { + typedef _Key key_type; + typedef _Tp mapped_type; + typedef __hash_value_type<_Key, _Tp> __node_value_type; + typedef pair __container_value_type; + typedef __container_value_type __map_value_type; + static const bool __is_map = true; + + _LIBCUDACXX_INLINE_VISIBILITY + static key_type const& __get_key(__container_value_type const& __v) { + return __v.first; + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value, + __container_value_type const&>::type + __get_value(_Up& __t) { + return __t.__get_value(); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, + __container_value_type const&>::type + __get_value(_Up& __t) { + return __t; + } + + _LIBCUDACXX_INLINE_VISIBILITY + static __container_value_type* __get_ptr(__node_value_type& __n) { + return _CUDA_VSTD::addressof(__n.__get_value()); + } + _LIBCUDACXX_INLINE_VISIBILITY + static pair __move(__node_value_type& __v) { + return __v.__move(); + } +}; + +template , + bool = _KVTypes::__is_map> +struct __hash_map_pointer_types {}; + +template +struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { + typedef typename _KVTypes::__map_value_type _Mv; + typedef typename __rebind_pointer<_AllocPtr, _Mv>::type + __map_value_type_pointer; + typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type + __const_map_value_type_pointer; +}; + +template ::element_type> +struct __hash_node_types; + +template +struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> > + : public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr> + +{ + typedef __hash_key_value_types<_Tp> __base; + +public: + typedef ptrdiff_t difference_type; + typedef size_t size_type; + + typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer; + + typedef typename pointer_traits<_NodePtr>::element_type __node_type; + typedef _NodePtr __node_pointer; + + typedef __hash_node_base<__node_pointer> __node_base_type; + typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type + __node_base_pointer; + + typedef typename __node_base_type::__next_pointer __next_pointer; + + typedef _Tp __node_value_type; + typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type + __node_value_type_pointer; + typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type + __const_node_value_type_pointer; + +private: + static_assert(!is_const<__node_type>::value, + "_NodePtr should never be a pointer to const"); + static_assert((is_same::element_type, void>::value), + "_VoidPtr does not point to unqualified void type"); + static_assert((is_same::type, + _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr."); +}; + +template +struct __hash_node_types_from_iterator; +template +struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; +template +struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; +template +struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; +template +struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; + + +template +struct __make_hash_node_types { + typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp; + typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr; + typedef __hash_node_types<_NodePtr> type; +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS __hash_iterator +{ + typedef __hash_node_types<_NodePtr> _NodeTypes; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef value_type& reference; + typedef typename _NodeTypes::__node_value_type_pointer pointer; + + _LIBCUDACXX_INLINE_VISIBILITY __hash_iterator() noexcept : __node_(nullptr) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__insert_i(this)); +#endif + } + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator(const __hash_iterator& __i) + : __node_(__i.__node_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__hash_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator& operator=(const __hash_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + } + return *this; + } +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + + _LIBCUDACXX_INLINE_VISIBILITY + reference operator*() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container iterator"); + return __node_->__upcast()->__value_; + } + + _LIBCUDACXX_INLINE_VISIBILITY + pointer operator->() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container iterator"); + return pointer_traits::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator& operator++() { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container iterator"); + __node_ = __node_->__next_; + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator operator++(int) + { + __hash_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator==(const __hash_iterator& __x, const __hash_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y) + {return !(__x == __y);} + +private: +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator(__next_pointer __node, const void* __c) noexcept + : __node_(__node) + { + __get_db()->__insert_ic(this, __c); + } +#else + _LIBCUDACXX_INLINE_VISIBILITY + __hash_iterator(__next_pointer __node) noexcept + : __node_(__node) + {} +#endif + template friend class __hash_table; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_const_iterator; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_map_iterator; + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_map; + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_multimap; +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS __hash_const_iterator +{ + static_assert(!is_const::element_type>::value, ""); + typedef __hash_node_types<_NodePtr> _NodeTypes; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + +public: + typedef __hash_iterator<_NodePtr> __non_const_iterator; + + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef const value_type& reference; + typedef typename _NodeTypes::__const_node_value_type_pointer pointer; + + + _LIBCUDACXX_INLINE_VISIBILITY __hash_const_iterator() noexcept : __node_(nullptr) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__insert_i(this)); +#endif + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator(const __non_const_iterator& __x) noexcept + : __node_(__x.__node_) + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); +#endif + } + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator(const __hash_const_iterator& __i) + : __node_(__i.__node_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__hash_const_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator& operator=(const __hash_const_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + } + return *this; + } +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + + _LIBCUDACXX_INLINE_VISIBILITY + reference operator*() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_iterator"); + return __node_->__upcast()->__value_; + } + _LIBCUDACXX_INLINE_VISIBILITY + pointer operator->() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_iterator"); + return pointer_traits::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator& operator++() { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container const_iterator"); + __node_ = __node_->__next_; + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator operator++(int) + { + __hash_const_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y) + {return !(__x == __y);} + +private: +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator(__next_pointer __node, const void* __c) noexcept + : __node_(__node) + { + __get_db()->__insert_ic(this, __c); + } +#else + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_iterator(__next_pointer __node) noexcept + : __node_(__node) + {} +#endif + template friend class __hash_table; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_map_const_iterator; + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_map; + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_multimap; +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS __hash_local_iterator +{ + typedef __hash_node_types<_NodePtr> _NodeTypes; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + size_t __bucket_; + size_t __bucket_count_; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef value_type& reference; + typedef typename _NodeTypes::__node_value_type_pointer pointer; + + _LIBCUDACXX_INLINE_VISIBILITY __hash_local_iterator() noexcept : __node_(nullptr) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__insert_i(this)); +#endif + } + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator(const __hash_local_iterator& __i) + : __node_(__i.__node_), + __bucket_(__i.__bucket_), + __bucket_count_(__i.__bucket_count_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__hash_local_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator& operator=(const __hash_local_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + __bucket_ = __i.__bucket_; + __bucket_count_ = __i.__bucket_count_; + } + return *this; + } +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + + _LIBCUDACXX_INLINE_VISIBILITY + reference operator*() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container local_iterator"); + return __node_->__upcast()->__value_; + } + + _LIBCUDACXX_INLINE_VISIBILITY + pointer operator->() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container local_iterator"); + return pointer_traits::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator& operator++() { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container local_iterator"); + __node_ = __node_->__next_; + if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) + __node_ = nullptr; + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator operator++(int) + { + __hash_local_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y) + {return !(__x == __y);} + +private: +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count, const void* __c) noexcept + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + __get_db()->__insert_ic(this, __c); + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#else + _LIBCUDACXX_INLINE_VISIBILITY + __hash_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count) noexcept + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#endif + template friend class __hash_table; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_const_local_iterator; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_map_iterator; +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS __hash_const_local_iterator +{ + typedef __hash_node_types<_ConstNodePtr> _NodeTypes; + typedef _ConstNodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + size_t __bucket_; + size_t __bucket_count_; + + typedef pointer_traits<__node_pointer> __pointer_traits; + typedef typename __pointer_traits::element_type __node; + typedef __remove_const_t<__node> __non_const_node; + typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type + __non_const_node_pointer; +public: + typedef __hash_local_iterator<__non_const_node_pointer> + __non_const_iterator; + + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef const value_type& reference; + typedef typename _NodeTypes::__const_node_value_type_pointer pointer; + + + _LIBCUDACXX_INLINE_VISIBILITY __hash_const_local_iterator() noexcept : __node_(nullptr) { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__insert_i(this)); +#endif + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator(const __non_const_iterator& __x) noexcept + : __node_(__x.__node_), + __bucket_(__x.__bucket_), + __bucket_count_(__x.__bucket_count_) + { +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); +#endif + } + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator(const __hash_const_local_iterator& __i) + : __node_(__i.__node_), + __bucket_(__i.__bucket_), + __bucket_count_(__i.__bucket_count_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__hash_const_local_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + __bucket_ = __i.__bucket_; + __bucket_count_ = __i.__bucket_count_; + } + return *this; + } +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + + _LIBCUDACXX_INLINE_VISIBILITY + reference operator*() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); + return __node_->__upcast()->__value_; + } + + _LIBCUDACXX_INLINE_VISIBILITY + pointer operator->() const { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); + return pointer_traits::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator& operator++() { + _LIBCUDACXX_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container const_local_iterator"); + __node_ = __node_->__next_; + if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) + __node_ = nullptr; + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator operator++(int) + { + __hash_const_local_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCUDACXX_INLINE_VISIBILITY + bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) + {return !(__x == __y);} + +private: +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count, const void* __c) noexcept + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + __get_db()->__insert_ic(this, __c); + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#else + _LIBCUDACXX_INLINE_VISIBILITY + __hash_const_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count) noexcept + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#endif + template friend class __hash_table; + template friend class _LIBCUDACXX_TEMPLATE_VIS __hash_map_const_iterator; +}; + +template +class __bucket_list_deallocator +{ + typedef _Alloc allocator_type; + typedef allocator_traits __alloc_traits; + typedef typename __alloc_traits::size_type size_type; + + __compressed_pair __data_; +public: + typedef typename __alloc_traits::pointer pointer; + + _LIBCUDACXX_INLINE_VISIBILITY + __bucket_list_deallocator() + noexcept(is_nothrow_default_constructible::value) + : __data_(0) {} + + _LIBCUDACXX_INLINE_VISIBILITY + __bucket_list_deallocator(const allocator_type& __a, size_type __size) + noexcept(is_nothrow_copy_constructible::value) + : __data_(__size, __a) {} + + _LIBCUDACXX_INLINE_VISIBILITY + __bucket_list_deallocator(__bucket_list_deallocator&& __x) + noexcept(is_nothrow_move_constructible::value) + : __data_(_CUDA_VSTD::move(__x.__data_)) + { + __x.size() = 0; + } + + _LIBCUDACXX_INLINE_VISIBILITY + size_type& size() noexcept {return __data_.first();} + _LIBCUDACXX_INLINE_VISIBILITY + size_type size() const noexcept {return __data_.first();} + + _LIBCUDACXX_INLINE_VISIBILITY + allocator_type& __alloc() noexcept {return __data_.second();} + _LIBCUDACXX_INLINE_VISIBILITY + const allocator_type& __alloc() const noexcept {return __data_.second();} + + _LIBCUDACXX_INLINE_VISIBILITY + void operator()(pointer __p) noexcept + { + __alloc_traits::deallocate(__alloc(), __p, size()); + } +}; + +template class __hash_map_node_destructor; + +template +class __hash_node_destructor +{ + typedef _Alloc allocator_type; + typedef allocator_traits __alloc_traits; + +public: + typedef typename __alloc_traits::pointer pointer; +private: + typedef __hash_node_types _NodeTypes; + + allocator_type& __na_; + +public: + bool __value_constructed; + + __hash_node_destructor(__hash_node_destructor const&) = default; + __hash_node_destructor& operator=(const __hash_node_destructor&) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __hash_node_destructor(allocator_type& __na, + bool __constructed = false) noexcept + : __na_(__na), + __value_constructed(__constructed) + {} + + _LIBCUDACXX_INLINE_VISIBILITY + void operator()(pointer __p) noexcept + { + if (__value_constructed) + __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } + + template friend class __hash_map_node_destructor; +}; + +#if _LIBCUDACXX_STD_VER > 14 +template +struct __generic_container_node_destructor; + +template +struct __generic_container_node_destructor<__hash_node<_Tp, _VoidPtr>, _Alloc> + : __hash_node_destructor<_Alloc> +{ + using __hash_node_destructor<_Alloc>::__hash_node_destructor; +}; +#endif + +template +struct __enforce_unordered_container_requirements { + static_assert(__check_hash_requirements<_Key, _Hash>::value, + "the specified hash does not meet the Hash requirements"); + static_assert(is_copy_constructible<_Equal>::value, + "the specified comparator is required to be copy constructible"); + typedef int type; +}; + +template + _LIBCUDACXX_DIAGNOSE_WARNING(!__invokable<_Equal const&, _Key const&, _Key const&>::value, + "the specified comparator type does not provide a viable const call operator") + _LIBCUDACXX_DIAGNOSE_WARNING(!__invokable<_Hash const&, _Key const&>::value, + "the specified hash functor does not provide a viable const call operator") +typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type +__diagnose_unordered_container_requirements(int); + +// This dummy overload is used so that the compiler won't emit a spurious +// "no matching function for call to __diagnose_unordered_xxx" diagnostic +// when the overload above causes a hard error. +template +int __diagnose_unordered_container_requirements(void*); + +template +class __hash_table +{ +public: + typedef _Tp value_type; + typedef _Hash hasher; + typedef _Equal key_equal; + typedef _Alloc allocator_type; + +private: + typedef allocator_traits __alloc_traits; + typedef typename + __make_hash_node_types::type + _NodeTypes; +public: + + typedef typename _NodeTypes::__node_value_type __node_value_type; + typedef typename _NodeTypes::__container_value_type __container_value_type; + typedef typename _NodeTypes::key_type key_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; +#ifndef _LIBCUDACXX_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE + typedef typename __alloc_traits::size_type size_type; +#else + typedef typename _NodeTypes::size_type size_type; +#endif + typedef typename _NodeTypes::difference_type difference_type; +public: + // Create __node + + typedef typename _NodeTypes::__node_type __node; + typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; + typedef allocator_traits<__node_allocator> __node_traits; + typedef typename _NodeTypes::__void_pointer __void_pointer; + typedef typename _NodeTypes::__node_pointer __node_pointer; + typedef typename _NodeTypes::__node_pointer __node_const_pointer; + typedef typename _NodeTypes::__node_base_type __first_node; + typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + +private: + // check for sane allocator pointer rebinding semantics. Rebinding the + // allocator for a new pointer type should be exactly the same as rebinding + // the pointer using 'pointer_traits'. + static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), + "Allocator does not rebind pointers in a sane manner."); + typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type + __node_base_allocator; + typedef allocator_traits<__node_base_allocator> __node_base_traits; + static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), + "Allocator does not rebind pointers in a sane manner."); + +private: + + typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator; + typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; + typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list; + typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; + typedef typename __bucket_list_deleter::pointer __node_pointer_pointer; + + // --- Member data begin --- + __bucket_list __bucket_list_; + __compressed_pair<__first_node, __node_allocator> __p1_; + __compressed_pair __p2_; + __compressed_pair __p3_; + // --- Member data end --- + + _LIBCUDACXX_INLINE_VISIBILITY + size_type& size() noexcept {return __p2_.first();} +public: + _LIBCUDACXX_INLINE_VISIBILITY + size_type size() const noexcept {return __p2_.first();} + + _LIBCUDACXX_INLINE_VISIBILITY + hasher& hash_function() noexcept {return __p2_.second();} + _LIBCUDACXX_INLINE_VISIBILITY + const hasher& hash_function() const noexcept {return __p2_.second();} + + _LIBCUDACXX_INLINE_VISIBILITY + float& max_load_factor() noexcept {return __p3_.first();} + _LIBCUDACXX_INLINE_VISIBILITY + float max_load_factor() const noexcept {return __p3_.first();} + + _LIBCUDACXX_INLINE_VISIBILITY + key_equal& key_eq() noexcept {return __p3_.second();} + _LIBCUDACXX_INLINE_VISIBILITY + const key_equal& key_eq() const noexcept {return __p3_.second();} + + _LIBCUDACXX_INLINE_VISIBILITY + __node_allocator& __node_alloc() noexcept {return __p1_.second();} + _LIBCUDACXX_INLINE_VISIBILITY + const __node_allocator& __node_alloc() const noexcept + {return __p1_.second();} + +public: + typedef __hash_iterator<__node_pointer> iterator; + typedef __hash_const_iterator<__node_pointer> const_iterator; + typedef __hash_local_iterator<__node_pointer> local_iterator; + typedef __hash_const_local_iterator<__node_pointer> const_local_iterator; + + _LIBCUDACXX_INLINE_VISIBILITY + __hash_table() + noexcept( + is_nothrow_default_constructible<__bucket_list>::value && + is_nothrow_default_constructible<__first_node>::value && + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_default_constructible::value && + is_nothrow_default_constructible::value); + _LIBCUDACXX_INLINE_VISIBILITY + __hash_table(const hasher& __hf, const key_equal& __eql); + __hash_table(const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); + explicit __hash_table(const allocator_type& __a); + __hash_table(const __hash_table& __u); + __hash_table(const __hash_table& __u, const allocator_type& __a); + __hash_table(__hash_table&& __u) + noexcept( + is_nothrow_move_constructible<__bucket_list>::value && + is_nothrow_move_constructible<__first_node>::value && + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible::value && + is_nothrow_move_constructible::value); + __hash_table(__hash_table&& __u, const allocator_type& __a); + ~__hash_table(); + + __hash_table& operator=(const __hash_table& __u); + _LIBCUDACXX_INLINE_VISIBILITY + __hash_table& operator=(__hash_table&& __u) + noexcept( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value); + template + void __assign_unique(_InputIterator __first, _InputIterator __last); + template + void __assign_multi(_InputIterator __first, _InputIterator __last); + + _LIBCUDACXX_INLINE_VISIBILITY + size_type max_size() const noexcept + { + return std::min( + __node_traits::max_size(__node_alloc()), + numeric_limits::max() + ); + } + +private: + _LIBCUDACXX_INLINE_VISIBILITY + __next_pointer __node_insert_multi_prepare(size_t __cp_hash, + value_type& __cp_val); + _LIBCUDACXX_INLINE_VISIBILITY + void __node_insert_multi_perform(__node_pointer __cp, + __next_pointer __pn) noexcept; + + _LIBCUDACXX_INLINE_VISIBILITY + __next_pointer __node_insert_unique_prepare(size_t __nd_hash, + value_type& __nd_val); + _LIBCUDACXX_INLINE_VISIBILITY + void __node_insert_unique_perform(__node_pointer __ptr) noexcept; + +public: + _LIBCUDACXX_INLINE_VISIBILITY + pair __node_insert_unique(__node_pointer __nd); + _LIBCUDACXX_INLINE_VISIBILITY + iterator __node_insert_multi(__node_pointer __nd); + _LIBCUDACXX_INLINE_VISIBILITY + iterator __node_insert_multi(const_iterator __p, + __node_pointer __nd); + + template + _LIBCUDACXX_INLINE_VISIBILITY + pair __emplace_unique_key_args(_Key const& __k, _Args&&... __args); + + template + _LIBCUDACXX_INLINE_VISIBILITY + pair __emplace_unique_impl(_Args&&... __args); + + template + _LIBCUDACXX_INLINE_VISIBILITY + pair __emplace_unique(_Pp&& __x) { + return __emplace_unique_extract_key(_CUDA_VSTD::forward<_Pp>(__x), + __can_extract_key<_Pp, key_type>()); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + typename enable_if< + __can_extract_map_key<_First, key_type, __container_value_type>::value, + pair + >::type __emplace_unique(_First&& __f, _Second&& __s) { + return __emplace_unique_key_args(__f, _CUDA_VSTD::forward<_First>(__f), + _CUDA_VSTD::forward<_Second>(__s)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + pair __emplace_unique(_Args&&... __args) { + return __emplace_unique_impl(_CUDA_VSTD::forward<_Args>(__args)...); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + pair + __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { + return __emplace_unique_impl(_CUDA_VSTD::forward<_Pp>(__x)); + } + template + _LIBCUDACXX_INLINE_VISIBILITY + pair + __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { + return __emplace_unique_key_args(__x, _CUDA_VSTD::forward<_Pp>(__x)); + } + template + _LIBCUDACXX_INLINE_VISIBILITY + pair + __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { + return __emplace_unique_key_args(__x.first, _CUDA_VSTD::forward<_Pp>(__x)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __emplace_multi(_Args&&... __args); + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); + + + _LIBCUDACXX_INLINE_VISIBILITY + pair + __insert_unique(__container_value_type&& __x) { + return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _CUDA_VSTD::move(__x)); + } + + template ::value + >::type> + _LIBCUDACXX_INLINE_VISIBILITY + pair __insert_unique(_Pp&& __x) { + return __emplace_unique(_CUDA_VSTD::forward<_Pp>(__x)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __insert_multi(_Pp&& __x) { + return __emplace_multi(_CUDA_VSTD::forward<_Pp>(__x)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __insert_multi(const_iterator __p, _Pp&& __x) { + return __emplace_hint_multi(__p, _CUDA_VSTD::forward<_Pp>(__x)); + } + + _LIBCUDACXX_INLINE_VISIBILITY + pair __insert_unique(const __container_value_type& __x) { + return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x); + } + +#if _LIBCUDACXX_STD_VER > 14 + template + _LIBCUDACXX_INLINE_VISIBILITY + _InsertReturnType __node_handle_insert_unique(_NodeHandle&& __nh); + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __node_handle_insert_unique(const_iterator __hint, + _NodeHandle&& __nh); + template + _LIBCUDACXX_INLINE_VISIBILITY + void __node_handle_merge_unique(_Table& __source); + + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __node_handle_insert_multi(_NodeHandle&& __nh); + template + _LIBCUDACXX_INLINE_VISIBILITY + iterator __node_handle_insert_multi(const_iterator __hint, _NodeHandle&& __nh); + template + _LIBCUDACXX_INLINE_VISIBILITY + void __node_handle_merge_multi(_Table& __source); + + template + _LIBCUDACXX_INLINE_VISIBILITY + _NodeHandle __node_handle_extract(key_type const& __key); + template + _LIBCUDACXX_INLINE_VISIBILITY + _NodeHandle __node_handle_extract(const_iterator __it); +#endif + + void clear() noexcept; + void rehash(size_type __n); + _LIBCUDACXX_INLINE_VISIBILITY void reserve(size_type __n) + {rehash(static_cast(ceil(__n / max_load_factor())));} + + _LIBCUDACXX_INLINE_VISIBILITY + size_type bucket_count() const noexcept + { + return __bucket_list_.get_deleter().size(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + iterator begin() noexcept; + _LIBCUDACXX_INLINE_VISIBILITY + iterator end() noexcept; + _LIBCUDACXX_INLINE_VISIBILITY + const_iterator begin() const noexcept; + _LIBCUDACXX_INLINE_VISIBILITY + const_iterator end() const noexcept; + + template + _LIBCUDACXX_INLINE_VISIBILITY + size_type bucket(const _Key& __k) const + { + _LIBCUDACXX_ASSERT(bucket_count() > 0, + "unordered container::bucket(key) called when bucket_count() == 0"); + return __constrain_hash(hash_function()(__k), bucket_count()); + } + + template + iterator find(const _Key& __x); + template + const_iterator find(const _Key& __x) const; + + typedef __hash_node_destructor<__node_allocator> _Dp; + typedef unique_ptr<__node, _Dp> __node_holder; + + iterator erase(const_iterator __p); + iterator erase(const_iterator __first, const_iterator __last); + template + size_type __erase_unique(const _Key& __k); + template + size_type __erase_multi(const _Key& __k); + __node_holder remove(const_iterator __p) noexcept; + + template + _LIBCUDACXX_INLINE_VISIBILITY + size_type __count_unique(const _Key& __k) const; + template + size_type __count_multi(const _Key& __k) const; + + template + pair + __equal_range_unique(const _Key& __k); + template + pair + __equal_range_unique(const _Key& __k) const; + + template + pair + __equal_range_multi(const _Key& __k); + template + pair + __equal_range_multi(const _Key& __k) const; + + void swap(__hash_table& __u) +#if _LIBCUDACXX_STD_VER <= 11 + noexcept( + __is_nothrow_swappable::value && __is_nothrow_swappable::value + && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value + || __is_nothrow_swappable<__pointer_allocator>::value) + && (!__node_traits::propagate_on_container_swap::value + || __is_nothrow_swappable<__node_allocator>::value) + ); +#else + noexcept(__is_nothrow_swappable::value && __is_nothrow_swappable::value); +#endif + + _LIBCUDACXX_INLINE_VISIBILITY + size_type max_bucket_count() const noexcept + {return max_size(); } + size_type bucket_size(size_type __n) const; + _LIBCUDACXX_INLINE_VISIBILITY float load_factor() const noexcept + { + size_type __bc = bucket_count(); + return __bc != 0 ? (float)size() / __bc : 0.f; + } + _LIBCUDACXX_INLINE_VISIBILITY void max_load_factor(float __mlf) noexcept + { + _LIBCUDACXX_ASSERT(__mlf > 0, + "unordered container::max_load_factor(lf) called with lf <= 0"); + max_load_factor() = _CUDA_VSTD::max(__mlf, load_factor()); + } + + _LIBCUDACXX_INLINE_VISIBILITY + local_iterator + begin(size_type __n) + { + _LIBCUDACXX_ASSERT(__n < bucket_count(), + "unordered container::begin(n) called with n >= bucket_count()"); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return local_iterator(__bucket_list_[__n], __n, bucket_count(), this); +#else + return local_iterator(__bucket_list_[__n], __n, bucket_count()); +#endif + } + + _LIBCUDACXX_INLINE_VISIBILITY + local_iterator + end(size_type __n) + { + _LIBCUDACXX_ASSERT(__n < bucket_count(), + "unordered container::end(n) called with n >= bucket_count()"); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return local_iterator(nullptr, __n, bucket_count(), this); +#else + return local_iterator(nullptr, __n, bucket_count()); +#endif + } + + _LIBCUDACXX_INLINE_VISIBILITY + const_local_iterator + cbegin(size_type __n) const + { + _LIBCUDACXX_ASSERT(__n < bucket_count(), + "unordered container::cbegin(n) called with n >= bucket_count()"); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this); +#else + return const_local_iterator(__bucket_list_[__n], __n, bucket_count()); +#endif + } + + _LIBCUDACXX_INLINE_VISIBILITY + const_local_iterator + cend(size_type __n) const + { + _LIBCUDACXX_ASSERT(__n < bucket_count(), + "unordered container::cend(n) called with n >= bucket_count()"); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return const_local_iterator(nullptr, __n, bucket_count(), this); +#else + return const_local_iterator(nullptr, __n, bucket_count()); +#endif + } + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + + bool __dereferenceable(const const_iterator* __i) const; + bool __decrementable(const const_iterator* __i) const; + bool __addable(const const_iterator* __i, ptrdiff_t __n) const; + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; + +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + +private: + void __rehash(size_type __n); + + template + __node_holder __construct_node(_Args&& ...__args); + + template + __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest); + + _LIBCUDACXX_INLINE_VISIBILITY + void __copy_assign_alloc(const __hash_table& __u) + {__copy_assign_alloc(__u, integral_constant());} + void __copy_assign_alloc(const __hash_table& __u, true_type); + _LIBCUDACXX_INLINE_VISIBILITY + void __copy_assign_alloc(const __hash_table&, false_type) {} + + void __move_assign(__hash_table& __u, false_type); + void __move_assign(__hash_table& __u, true_type) + noexcept( + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value); + _LIBCUDACXX_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table& __u) + noexcept( + !__node_traits::propagate_on_container_move_assignment::value || + (is_nothrow_move_assignable<__pointer_allocator>::value && + is_nothrow_move_assignable<__node_allocator>::value)) + {__move_assign_alloc(__u, integral_constant());} + _LIBCUDACXX_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table& __u, true_type) + noexcept( + is_nothrow_move_assignable<__pointer_allocator>::value && + is_nothrow_move_assignable<__node_allocator>::value) + { + __bucket_list_.get_deleter().__alloc() = + _CUDA_VSTD::move(__u.__bucket_list_.get_deleter().__alloc()); + __node_alloc() = _CUDA_VSTD::move(__u.__node_alloc()); + } + _LIBCUDACXX_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table&, false_type) noexcept {} + + void __deallocate_node(__next_pointer __np) noexcept; + __next_pointer __detach() noexcept; + + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_map; + template friend class _LIBCUDACXX_TEMPLATE_VIS unordered_multimap; +}; + +template +inline +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() + noexcept( + is_nothrow_default_constructible<__bucket_list>::value && + is_nothrow_default_constructible<__first_node>::value && + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_default_constructible::value && + is_nothrow_default_constructible::value) + : __p2_(0), + __p3_(1.0f) +{ +} + +template +inline +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, + const key_equal& __eql) + : __bucket_list_(nullptr, __bucket_list_deleter()), + __p1_(), + __p2_(0, __hf), + __p3_(1.0f, __eql) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0, __hf), + __p3_(1.0f, __eql) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0), + __p3_(1.0f) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) + : __bucket_list_(nullptr, + __bucket_list_deleter(allocator_traits<__pointer_allocator>:: + select_on_container_copy_construction( + __u.__bucket_list_.get_deleter().__alloc()), 0)), + __p1_(__second_tag(), allocator_traits<__node_allocator>:: + select_on_container_copy_construction(__u.__node_alloc())), + __p2_(0, __u.hash_function()), + __p3_(__u.__p3_) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0, __u.hash_function()), + __p3_(__u.__p3_) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) + noexcept( + is_nothrow_move_constructible<__bucket_list>::value && + is_nothrow_move_constructible<__first_node>::value && + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible::value && + is_nothrow_move_constructible::value) + : __bucket_list_(_CUDA_VSTD::move(__u.__bucket_list_)), + __p1_(_CUDA_VSTD::move(__u.__p1_)), + __p2_(_CUDA_VSTD::move(__u.__p2_)), + __p3_(_CUDA_VSTD::move(__u.__p3_)) +{ + if (size() > 0) + { + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + __u.__p1_.first().__next_ = nullptr; + __u.size() = 0; + } +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0, _CUDA_VSTD::move(__u.hash_function())), + __p3_(_CUDA_VSTD::move(__u.__p3_)) +{ + if (__a == allocator_type(__u.__node_alloc())) + { + __bucket_list_.reset(__u.__bucket_list_.release()); + __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); + __u.__bucket_list_.get_deleter().size() = 0; + if (__u.size() > 0) + { + __p1_.first().__next_ = __u.__p1_.first().__next_; + __u.__p1_.first().__next_ = nullptr; + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + size() = __u.size(); + __u.size() = 0; + } + } +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() +{ + __deallocate_node(__p1_.first().__next_); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __get_db()->__erase_c(this); +#endif +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc( + const __hash_table& __u, true_type) +{ + if (__node_alloc() != __u.__node_alloc()) + { + clear(); + __bucket_list_.reset(); + __bucket_list_.get_deleter().size() = 0; + } + __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc(); + __node_alloc() = __u.__node_alloc(); +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>& +__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u) +{ + if (this != &__u) + { + __copy_assign_alloc(__u); + hash_function() = __u.hash_function(); + key_eq() = __u.key_eq(); + max_load_factor() = __u.max_load_factor(); + __assign_multi(__u.begin(), __u.end()); + } + return *this; +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np) + noexcept +{ + __node_allocator& __na = __node_alloc(); + while (__np != nullptr) + { + __next_pointer __next = __np->__next_; +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast((*__p)->__i_); + if (__i->__node_ == __np) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __node_pointer __real_np = __np->__upcast(); + __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_)); + __node_traits::deallocate(__na, __real_np, 1); + __np = __next; + } +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() noexcept +{ + size_type __bc = bucket_count(); + for (size_type __i = 0; __i < __bc; ++__i) + __bucket_list_[__i] = nullptr; + size() = 0; + __next_pointer __cache = __p1_.first().__next_; + __p1_.first().__next_ = nullptr; + return __cache; +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( + __hash_table& __u, true_type) + noexcept( + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value) +{ + clear(); + __bucket_list_.reset(__u.__bucket_list_.release()); + __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); + __u.__bucket_list_.get_deleter().size() = 0; + __move_assign_alloc(__u); + size() = __u.size(); + hash_function() = _CUDA_VSTD::move(__u.hash_function()); + max_load_factor() = __u.max_load_factor(); + key_eq() = _CUDA_VSTD::move(__u.key_eq()); + __p1_.first().__next_ = __u.__p1_.first().__next_; + if (size() > 0) + { + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + __u.__p1_.first().__next_ = nullptr; + __u.size() = 0; + } +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __get_db()->swap(this, &__u); +#endif +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( + __hash_table& __u, false_type) +{ + if (__node_alloc() == __u.__node_alloc()) + __move_assign(__u, true_type()); + else + { + hash_function() = _CUDA_VSTD::move(__u.hash_function()); + key_eq() = _CUDA_VSTD::move(__u.key_eq()); + max_load_factor() = __u.max_load_factor(); + if (bucket_count() != 0) + { + __next_pointer __cache = __detach(); +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + try + { +#endif // _LIBCUDACXX_NO_EXCEPTIONS + const_iterator __i = __u.begin(); + while (__cache != nullptr && __u.size() != 0) + { + __cache->__upcast()->__value_ = + _CUDA_VSTD::move(__u.remove(__i++)->__value_); + __next_pointer __next = __cache->__next_; + __node_insert_multi(__cache->__upcast()); + __cache = __next; + } +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + } + catch (...) + { + __deallocate_node(__cache); + throw; + } +#endif // _LIBCUDACXX_NO_EXCEPTIONS + __deallocate_node(__cache); + } + const_iterator __i = __u.begin(); + while (__u.size() != 0) + { + __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_)); + __node_insert_multi(__h.get()); + __h.release(); + } + } +} + +template +inline +__hash_table<_Tp, _Hash, _Equal, _Alloc>& +__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u) + noexcept( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value) +{ + __move_assign(__u, integral_constant()); + return *this; +} + +template +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first, + _InputIterator __last) +{ + typedef iterator_traits<_InputIterator> _ITraits; + typedef typename _ITraits::value_type _ItValueType; + static_assert((is_same<_ItValueType, __container_value_type>::value), + "__assign_unique may only be called with the containers value type"); + + if (bucket_count() != 0) + { + __next_pointer __cache = __detach(); +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + try + { +#endif // _LIBCUDACXX_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__upcast()->__value_ = *__first; + __next_pointer __next = __cache->__next_; + __node_insert_unique(__cache->__upcast()); + __cache = __next; + } +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + } + catch (...) + { + __deallocate_node(__cache); + throw; + } +#endif // _LIBCUDACXX_NO_EXCEPTIONS + __deallocate_node(__cache); + } + for (; __first != __last; ++__first) + __insert_unique(*__first); +} + +template +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first, + _InputIterator __last) +{ + typedef iterator_traits<_InputIterator> _ITraits; + typedef typename _ITraits::value_type _ItValueType; + static_assert((is_same<_ItValueType, __container_value_type>::value || + is_same<_ItValueType, __node_value_type>::value), + "__assign_multi may only be called with the containers value type" + " or the nodes value type"); + if (bucket_count() != 0) + { + __next_pointer __cache = __detach(); +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + try + { +#endif // _LIBCUDACXX_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__upcast()->__value_ = *__first; + __next_pointer __next = __cache->__next_; + __node_insert_multi(__cache->__upcast()); + __cache = __next; + } +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + } + catch (...) + { + __deallocate_node(__cache); + throw; + } +#endif // _LIBCUDACXX_NO_EXCEPTIONS + __deallocate_node(__cache); + } + for (; __first != __last; ++__first) + __insert_multi(_NodeTypes::__get_value(*__first)); +} + +template +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() noexcept +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator(__p1_.first().__next_, this); +#else + return iterator(__p1_.first().__next_); +#endif +} + +template +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() noexcept +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator(nullptr, this); +#else + return iterator(nullptr); +#endif +} + +template +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const noexcept +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return const_iterator(__p1_.first().__next_, this); +#else + return const_iterator(__p1_.first().__next_); +#endif +} + +template +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const noexcept +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return const_iterator(nullptr, this); +#else + return const_iterator(nullptr); +#endif +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() noexcept +{ + if (size() > 0) + { + __deallocate_node(__p1_.first().__next_); + __p1_.first().__next_ = nullptr; + size_type __bc = bucket_count(); + for (size_type __i = 0; __i < __bc; ++__i) + __bucket_list_[__i] = nullptr; + size() = 0; + } +} + + +// Prepare the container for an insertion of the value __value with the hash +// __hash. This does a lookup into the container to see if __value is already +// present, and performs a rehash if necessary. Returns a pointer to the +// existing element if it exists, otherwise nullptr. +// +// Note that this function does forward exceptions if key_eq() throws, and never +// mutates __value or actually inserts into the map. +template +_LIBCUDACXX_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare( + size_t __hash, value_type& __value) +{ + size_type __bc = bucket_count(); + + if (__bc != 0) + { + size_t __chash = __constrain_hash(__hash, __bc); + __next_pointer __ndptr = __bucket_list_[__chash]; + if (__ndptr != nullptr) + { + for (__ndptr = __ndptr->__next_; __ndptr != nullptr && + __constrain_hash(__ndptr->__hash(), __bc) == __chash; + __ndptr = __ndptr->__next_) + { + if (key_eq()(__ndptr->__upcast()->__value_, __value)) + return __ndptr; + } + } + } + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_CUDA_VSTD::max(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + } + return nullptr; +} + +// Insert the node __nd into the container by pushing it into the right bucket, +// and updating size(). Assumes that __nd->__hash is up-to-date, and that +// rehashing has already occurred and that no element with the same key exists +// in the map. +template +_LIBCUDACXX_INLINE_VISIBILITY +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform( + __node_pointer __nd) noexcept +{ + size_type __bc = bucket_count(); + size_t __chash = __constrain_hash(__nd->__hash(), __bc); + // insert_after __bucket_list_[__chash], or __first_node if bucket is null + __next_pointer __pn = __bucket_list_[__chash]; + if (__pn == nullptr) + { + __pn =__p1_.first().__ptr(); + __nd->__next_ = __pn->__next_; + __pn->__next_ = __nd->__ptr(); + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__nd->__next_ != nullptr) + __bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr(); + } + else + { + __nd->__next_ = __pn->__next_; + __pn->__next_ = __nd->__ptr(); + } + ++size(); +} + +template +pair::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd) +{ + __nd->__hash_ = hash_function()(__nd->__value_); + __next_pointer __existing_node = + __node_insert_unique_prepare(__nd->__hash(), __nd->__value_); + + // Insert the node, unless it already exists in the container. + bool __inserted = false; + if (__existing_node == nullptr) + { + __node_insert_unique_perform(__nd); + __existing_node = __nd->__ptr(); + __inserted = true; + } +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return pair(iterator(__existing_node, this), __inserted); +#else + return pair(iterator(__existing_node), __inserted); +#endif +} + +// Prepare the container for an insertion of the value __cp_val with the hash +// __cp_hash. This does a lookup into the container to see if __cp_value is +// already present, and performs a rehash if necessary. Returns a pointer to the +// last occurance of __cp_val in the map. +// +// Note that this function does forward exceptions if key_eq() throws, and never +// mutates __value or actually inserts into the map. +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare( + size_t __cp_hash, value_type& __cp_val) +{ + size_type __bc = bucket_count(); + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_CUDA_VSTD::max(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + } + size_t __chash = __constrain_hash(__cp_hash, __bc); + __next_pointer __pn = __bucket_list_[__chash]; + if (__pn != nullptr) + { + for (bool __found = false; __pn->__next_ != nullptr && + __constrain_hash(__pn->__next_->__hash(), __bc) == __chash; + __pn = __pn->__next_) + { + // __found key_eq() action + // false false loop + // true true loop + // false true set __found to true + // true false break + if (__found != (__pn->__next_->__hash() == __cp_hash && + key_eq()(__pn->__next_->__upcast()->__value_, __cp_val))) + { + if (!__found) + __found = true; + else + break; + } + } + } + return __pn; +} + +// Insert the node __cp into the container after __pn (which is the last node in +// the bucket that compares equal to __cp). Rehashing, and checking for +// uniqueness has already been performed (in __node_insert_multi_prepare), so +// all we need to do is update the bucket and size(). Assumes that __cp->__hash +// is up-to-date. +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform( + __node_pointer __cp, __next_pointer __pn) noexcept +{ + size_type __bc = bucket_count(); + size_t __chash = __constrain_hash(__cp->__hash_, __bc); + if (__pn == nullptr) + { + __pn =__p1_.first().__ptr(); + __cp->__next_ = __pn->__next_; + __pn->__next_ = __cp->__ptr(); + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__cp->__next_ != nullptr) + __bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)] + = __cp->__ptr(); + } + else + { + __cp->__next_ = __pn->__next_; + __pn->__next_ = __cp->__ptr(); + if (__cp->__next_ != nullptr) + { + size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc); + if (__nhash != __chash) + __bucket_list_[__nhash] = __cp->__ptr(); + } + } + ++size(); +} + + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp) +{ + __cp->__hash_ = hash_function()(__cp->__value_); + __next_pointer __pn = __node_insert_multi_prepare(__cp->__hash(), __cp->__value_); + __node_insert_multi_perform(__cp, __pn); + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator(__cp->__ptr(), this); +#else + return iterator(__cp->__ptr()); +#endif +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( + const_iterator __p, __node_pointer __cp) +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered container"); +#endif + if (__p != end() && key_eq()(*__p, __cp->__value_)) + { + __next_pointer __np = __p.__node_; + __cp->__hash_ = __np->__hash(); + size_type __bc = bucket_count(); + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_CUDA_VSTD::max(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + } + size_t __chash = __constrain_hash(__cp->__hash_, __bc); + __next_pointer __pp = __bucket_list_[__chash]; + while (__pp->__next_ != __np) + __pp = __pp->__next_; + __cp->__next_ = __np; + __pp->__next_ = static_cast<__next_pointer>(__cp); + ++size(); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator(static_cast<__next_pointer>(__cp), this); +#else + return iterator(static_cast<__next_pointer>(__cp)); +#endif + } + return __node_insert_multi(__cp); +} + + + +template +template +pair::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) +{ + + size_t __hash = hash_function()(__k); + size_type __bc = bucket_count(); + bool __inserted = false; + __next_pointer __nd; + size_t __chash; + if (__bc != 0) + { + __chash = __constrain_hash(__hash, __bc); + __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash); + __nd = __nd->__next_) + { + if (key_eq()(__nd->__upcast()->__value_, __k)) + goto __done; + } + } + } + { + __node_holder __h = __construct_node_hash(__hash, _CUDA_VSTD::forward<_Args>(__args)...); + + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_CUDA_VSTD::max(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + __chash = __constrain_hash(__hash, __bc); + } + // insert_after __bucket_list_[__chash], or __first_node if bucket is null + __next_pointer __pn = __bucket_list_[__chash]; + if (__pn == nullptr) + { + __pn = __p1_.first().__ptr(); + __h->__next_ = __pn->__next_; + __pn->__next_ = __h.get()->__ptr(); + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__h->__next_ != nullptr) + __bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)] + = __h.get()->__ptr(); + } + else + { + __h->__next_ = __pn->__next_; + __pn->__next_ = static_cast<__next_pointer>(__h.get()); + } + __nd = static_cast<__next_pointer>(__h.release()); + // increment size + ++size(); + __inserted = true; + } +__done: +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return pair(iterator(__nd, this), __inserted); +#else + return pair(iterator(__nd), __inserted); +#endif +} + +template +template +pair::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args) +{ + __node_holder __h = __construct_node(_CUDA_VSTD::forward<_Args>(__args)...); + pair __r = __node_insert_unique(__h.get()); + if (__r.second) + __h.release(); + return __r; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args) +{ + __node_holder __h = __construct_node(_CUDA_VSTD::forward<_Args>(__args)...); + iterator __r = __node_insert_multi(__h.get()); + __h.release(); + return __r; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi( + const_iterator __p, _Args&&... __args) +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered container"); +#endif + __node_holder __h = __construct_node(_CUDA_VSTD::forward<_Args>(__args)...); + iterator __r = __node_insert_multi(__p, __h.get()); + __h.release(); + return __r; +} + +#if _LIBCUDACXX_STD_VER > 14 +template +template +_LIBCUDACXX_INLINE_VISIBILITY +_InsertReturnType +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique( + _NodeHandle&& __nh) +{ + if (__nh.empty()) + return _InsertReturnType{end(), false, _NodeHandle()}; + pair __result = __node_insert_unique(__nh.__ptr_); + if (__result.second) + __nh.__release_ptr(); + return _InsertReturnType{__result.first, __result.second, _CUDA_VSTD::move(__nh)}; +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique( + const_iterator, _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + pair __result = __node_insert_unique(__nh.__ptr_); + if (__result.second) + __nh.__release_ptr(); + return __result.first; +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +_NodeHandle +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract( + key_type const& __key) +{ + iterator __i = find(__key); + if (__i == end()) + return _NodeHandle(); + return __node_handle_extract<_NodeHandle>(__i); +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +_NodeHandle +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract( + const_iterator __p) +{ + allocator_type __alloc(__node_alloc()); + return _NodeHandle(remove(__p).release(), __alloc); +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_unique( + _Table& __source) +{ + static_assert(is_same<__node, typename _Table::__node>::value, ""); + + for (typename _Table::iterator __it = __source.begin(); + __it != __source.end();) + { + __node_pointer __src_ptr = __it.__node_->__upcast(); + size_t __hash = hash_function()(__src_ptr->__value_); + __next_pointer __existing_node = + __node_insert_unique_prepare(__hash, __src_ptr->__value_); + auto __prev_iter = __it++; + if (__existing_node == nullptr) + { + (void)__source.remove(__prev_iter).release(); + __src_ptr->__hash_ = __hash; + __node_insert_unique_perform(__src_ptr); + } + } +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi( + _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + iterator __result = __node_insert_multi(__nh.__ptr_); + __nh.__release_ptr(); + return __result; +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi( + const_iterator __hint, _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + iterator __result = __node_insert_multi(__hint, __nh.__ptr_); + __nh.__release_ptr(); + return __result; +} + +template +template +_LIBCUDACXX_INLINE_VISIBILITY +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_multi( + _Table& __source) +{ + static_assert(is_same::value, ""); + + for (typename _Table::iterator __it = __source.begin(); + __it != __source.end();) + { + __node_pointer __src_ptr = __it.__node_->__upcast(); + size_t __src_hash = hash_function()(__src_ptr->__value_); + __next_pointer __pn = + __node_insert_multi_prepare(__src_hash, __src_ptr->__value_); + (void)__source.remove(__it++).release(); + __src_ptr->__hash_ = __src_hash; + __node_insert_multi_perform(__src_ptr, __pn); + } +} +#endif // _LIBCUDACXX_STD_VER > 14 + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n) +_LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +{ + if (__n == 1) + __n = 2; + else if (__n & (__n - 1)) + __n = __next_prime(__n); + size_type __bc = bucket_count(); + if (__n > __bc) + __rehash(__n); + else if (__n < __bc) + { + __n = _CUDA_VSTD::max + ( + __n, + __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) : + __next_prime(size_t(ceil(float(size()) / max_load_factor()))) + ); + if (__n < __bc) + __rehash(__n); + } +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc) +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __get_db()->__invalidate_all(this); +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc(); + __bucket_list_.reset(__nbc > 0 ? + __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr); + __bucket_list_.get_deleter().size() = __nbc; + if (__nbc > 0) + { + for (size_type __i = 0; __i < __nbc; ++__i) + __bucket_list_[__i] = nullptr; + __next_pointer __pp = __p1_.first().__ptr(); + __next_pointer __cp = __pp->__next_; + if (__cp != nullptr) + { + size_type __chash = __constrain_hash(__cp->__hash(), __nbc); + __bucket_list_[__chash] = __pp; + size_type __phash = __chash; + for (__pp = __cp, void(), __cp = __cp->__next_; __cp != nullptr; + __cp = __pp->__next_) + { + __chash = __constrain_hash(__cp->__hash(), __nbc); + if (__chash == __phash) + __pp = __cp; + else + { + if (__bucket_list_[__chash] == nullptr) + { + __bucket_list_[__chash] = __pp; + __pp = __cp; + __phash = __chash; + } + else + { + __next_pointer __np = __cp; + for (; __np->__next_ != nullptr && + key_eq()(__cp->__upcast()->__value_, + __np->__next_->__upcast()->__value_); + __np = __np->__next_) + ; + __pp->__next_ = __np->__next_; + __np->__next_ = __bucket_list_[__chash]->__next_; + __bucket_list_[__chash]->__next_ = __cp; + + } + } + } + } + } +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) +{ + size_t __hash = hash_function()(__k); + size_type __bc = bucket_count(); + if (__bc != 0) + { + size_t __chash = __constrain_hash(__hash, __bc); + __next_pointer __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + (__nd->__hash() == __hash + || __constrain_hash(__nd->__hash(), __bc) == __chash); + __nd = __nd->__next_) + { + if ((__nd->__hash() == __hash) + && key_eq()(__nd->__upcast()->__value_, __k)) +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator(__nd, this); +#else + return iterator(__nd); +#endif + } + } + } + return end(); +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const +{ + size_t __hash = hash_function()(__k); + size_type __bc = bucket_count(); + if (__bc != 0) + { + size_t __chash = __constrain_hash(__hash, __bc); + __next_pointer __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + (__hash == __nd->__hash() + || __constrain_hash(__nd->__hash(), __bc) == __chash); + __nd = __nd->__next_) + { + if ((__nd->__hash() == __hash) + && key_eq()(__nd->__upcast()->__value_, __k)) +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return const_iterator(__nd, this); +#else + return const_iterator(__nd); +#endif + } + } + + } + return end(); +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args) +{ + static_assert(!__is_hash_value_type<_Args...>::value, + "Construct cannot be called with a hash value type"); + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _CUDA_VSTD::forward<_Args>(__args)...); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = hash_function()(__h->__value_); + __h->__next_ = nullptr; + return __h; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash( + size_t __hash, _First&& __f, _Rest&& ...__rest) +{ + static_assert(!__is_hash_value_type<_First, _Rest...>::value, + "Construct cannot be called with a hash value type"); + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), + _CUDA_VSTD::forward<_First>(__f), + _CUDA_VSTD::forward<_Rest>(__rest)...); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = __hash; + __h->__next_ = nullptr; + return __h; +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p) +{ + __next_pointer __np = __p.__node_; +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container erase(iterator) called with an iterator not" + " referring to this container"); + _LIBCUDACXX_ASSERT(__p != end(), + "unordered container erase(iterator) called with a non-dereferenceable iterator"); + iterator __r(__np, this); +#else + iterator __r(__np); +#endif + ++__r; + remove(__p); + return __r; +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, + const_iterator __last) +{ +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + _LIBCUDACXX_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, + "unodered container::erase(iterator, iterator) called with an iterator not" + " referring to this unodered container"); + _LIBCUDACXX_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, + "unodered container::erase(iterator, iterator) called with an iterator not" + " referring to this unodered container"); +#endif + for (const_iterator __p = __first; __first != __last; __p = __first) + { + ++__first; + erase(__p); + } + __next_pointer __np = __last.__node_; +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + return iterator (__np, this); +#else + return iterator (__np); +#endif +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k) +{ + iterator __i = find(__k); + if (__i == end()) + return 0; + erase(__i); + return 1; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k) +{ + size_type __r = 0; + iterator __i = find(__k); + if (__i != end()) + { + iterator __e = end(); + do + { + erase(__i++); + ++__r; + } while (__i != __e && key_eq()(*__i, __k)); + } + return __r; +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) noexcept +{ + // current node + __next_pointer __cn = __p.__node_; + size_type __bc = bucket_count(); + size_t __chash = __constrain_hash(__cn->__hash(), __bc); + // find previous node + __next_pointer __pn = __bucket_list_[__chash]; + for (; __pn->__next_ != __cn; __pn = __pn->__next_) + ; + // Fix up __bucket_list_ + // if __pn is not in same bucket (before begin is not in same bucket) && + // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) + if (__pn == __p1_.first().__ptr() + || __constrain_hash(__pn->__hash(), __bc) != __chash) + { + if (__cn->__next_ == nullptr + || __constrain_hash(__cn->__next_->__hash(), __bc) != __chash) + __bucket_list_[__chash] = nullptr; + } + // if __cn->__next_ is not in same bucket (nullptr is in same bucket) + if (__cn->__next_ != nullptr) + { + size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc); + if (__nhash != __chash) + __bucket_list_[__nhash] = __pn; + } + // remove __cn + __pn->__next_ = __cn->__next_; + __cn->__next_ = nullptr; + --size(); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __dp = __c->end_; __dp != __c->beg_; ) + { + --__dp; + iterator* __i = static_cast((*__dp)->__i_); + if (__i->__node_ == __cn) + { + (*__dp)->__c_ = nullptr; + if (--__c->end_ != __dp) + memmove(__dp, __dp+1, (__c->end_ - __dp)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true)); +} + +template +template +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const +{ + return static_cast(find(__k) != end()); +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const +{ + size_type __r = 0; + const_iterator __i = find(__k); + if (__i != end()) + { + const_iterator __e = end(); + do + { + ++__i; + ++__r; + } while (__i != __e && key_eq()(*__i, __k)); + } + return __r; +} + +template +template +pair::iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( + const _Key& __k) +{ + iterator __i = find(__k); + iterator __j = __i; + if (__i != end()) + ++__j; + return pair(__i, __j); +} + +template +template +pair::const_iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( + const _Key& __k) const +{ + const_iterator __i = find(__k); + const_iterator __j = __i; + if (__i != end()) + ++__j; + return pair(__i, __j); +} + +template +template +pair::iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( + const _Key& __k) +{ + iterator __i = find(__k); + iterator __j = __i; + if (__i != end()) + { + iterator __e = end(); + do + { + ++__j; + } while (__j != __e && key_eq()(*__j, __k)); + } + return pair(__i, __j); +} + +template +template +pair::const_iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( + const _Key& __k) const +{ + const_iterator __i = find(__k); + const_iterator __j = __i; + if (__i != end()) + { + const_iterator __e = end(); + do + { + ++__j; + } while (__j != __e && key_eq()(*__j, __k)); + } + return pair(__i, __j); +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) +#if _LIBCUDACXX_STD_VER <= 11 + noexcept( + __is_nothrow_swappable::value && __is_nothrow_swappable::value + && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value + || __is_nothrow_swappable<__pointer_allocator>::value) + && (!__node_traits::propagate_on_container_swap::value + || __is_nothrow_swappable<__node_allocator>::value) + ) +#else + noexcept(__is_nothrow_swappable::value && __is_nothrow_swappable::value) +#endif +{ + _LIBCUDACXX_ASSERT(__node_traits::propagate_on_container_swap::value || + this->__node_alloc() == __u.__node_alloc(), + "list::swap: Either propagate_on_container_swap must be true" + " or the allocators must compare equal"); + { + __node_pointer_pointer __npp = __bucket_list_.release(); + __bucket_list_.reset(__u.__bucket_list_.release()); + __u.__bucket_list_.reset(__npp); + } + _CUDA_VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size()); + __swap_allocator(__bucket_list_.get_deleter().__alloc(), + __u.__bucket_list_.get_deleter().__alloc()); + __swap_allocator(__node_alloc(), __u.__node_alloc()); + _CUDA_VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_); + __p2_.swap(__u.__p2_); + __p3_.swap(__u.__p3_); + if (size() > 0) + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + if (__u.size() > 0) + __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = + __u.__p1_.first().__ptr(); +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + __get_db()->swap(this, &__u); +#endif +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const +{ + _LIBCUDACXX_ASSERT(__n < bucket_count(), + "unordered container::bucket_size(n) called with n >= bucket_count()"); + __next_pointer __np = __bucket_list_[__n]; + size_type __bc = bucket_count(); + size_type __r = 0; + if (__np != nullptr) + { + for (__np = __np->__next_; __np != nullptr && + __constrain_hash(__np->__hash(), __bc) == __n; + __np = __np->__next_, ++__r) + ; + } + return __r; +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x, + __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y) + noexcept(noexcept(__x.swap(__y))) +{ + __x.swap(__y); +} + +#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE + +template +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const +{ + return __i->__node_ != nullptr; +} + +template +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const +{ + return false; +} + +template +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const +{ + return false; +} + +template +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const +{ + return false; +} + +#endif // _LIBCUDACXX_ENABLE_DEBUG_MODE + +_LIBCUDACXX_END_NAMESPACE_STD + +_LIBCUDACXX_POP_MACROS + +#endif // _LIBCUDACXX__HASH_TABLE diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/access.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/access.h new file mode 100644 index 0000000000000000000000000000000000000000..54d0bf4aa50cb3654b9a40a5c563e75610abbb32 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/advance.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/advance.h new file mode 100644 index 0000000000000000000000000000000000000000..bfb9818ebd30f599941bb0df3bbfb6bd3d4840e0 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/back_insert_iterator.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/back_insert_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..a977729934f480d34a1df7096cbcfb031a384db3 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/bounded_iter.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/bounded_iter.h new file mode 100644 index 0000000000000000000000000000000000000000..2a8619cae90c99d0d8bde32b19b136d6dcf727eb --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/concepts.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/concepts.h new file mode 100644 index 0000000000000000000000000000000000000000..70b361e81404be344ff5feae1532b84a7ae70989 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/data.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/data.h new file mode 100644 index 0000000000000000000000000000000000000000..255922a3fddf532faa47e3bc27291269fba6a6fa --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/default_sentinel.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/default_sentinel.h new file mode 100644 index 0000000000000000000000000000000000000000..e378ce0fb9cca003edb7965df4060eca5e9c6a56 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/distance.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/distance.h new file mode 100644 index 0000000000000000000000000000000000000000..c6ea9e9843cd829e16c4c74b7b35d2a18ca65cfd --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/empty.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/empty.h new file mode 100644 index 0000000000000000000000000000000000000000..cb9602bf51bf438e87cb403652881c50cf14c630 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/erase_if_container.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/erase_if_container.h new file mode 100644 index 0000000000000000000000000000000000000000..07e3ad8ff969413818c9a4c6222b0554f119de87 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/front_insert_iterator.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/front_insert_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..aef0098a4e51413fd980d2c9f90f98cb9d46f7bc --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/incrementable_traits.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/incrementable_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..02fe7652133ddba11071d266198b1a7db46447ee --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/indirectly_comparable.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/indirectly_comparable.h new file mode 100644 index 0000000000000000000000000000000000000000..9dc038aa7aa3c742a8fba15d4155fd596eafc284 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/insert_iterator.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/insert_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..50ccebf31a9ac806bd616b0c90882f06f5f4dfaf --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/istream_iterator.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/istream_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..b7646fc17ef558b30658e82d6766b3d54a9768a2 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/istreambuf_iterator.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/istreambuf_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..9dbbc64e18f859924a7202c89f5e945e85f36808 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/iter_move.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/iter_move.h new file mode 100644 index 0000000000000000000000000000000000000000..6f23c8304ef768895d290e692d84413f993350b0 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/iter_swap.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/iter_swap.h new file mode 100644 index 0000000000000000000000000000000000000000..624a034f6c3f88b0088d4c6c3fcd5e864ac128c3 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/iterator.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..1f00b0aed7815e485963925e0282d88f064d3abe --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/iterator_traits.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/iterator_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..8471b8a47200cb3108a1abbcd6cbdc5259cbd3da --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/mergeable.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/mergeable.h new file mode 100644 index 0000000000000000000000000000000000000000..c7a97485e29af6baf8945d78cecfef75d2410639 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/move_iterator.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/move_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..48f2bbada335fb72ee627aa39c493c57e53050c6 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/move_sentinel.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/move_sentinel.h new file mode 100644 index 0000000000000000000000000000000000000000..5ad1922b731a53679f7b50aedc54c3de2208a83b --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/next.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/next.h new file mode 100644 index 0000000000000000000000000000000000000000..4dc2b6643d70be4b8356b82d0810ddef0fc264b0 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/ostream_iterator.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/ostream_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..a13650fee5a9058fbaa4aabacef62ce6ff5bb918 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/ostreambuf_iterator.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/ostreambuf_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..48bc890d84344dae2ae23556423f1fec5b23f436 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/permutable.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/permutable.h new file mode 100644 index 0000000000000000000000000000000000000000..d3afdafab2f62af5f530cab5712415e153016a2b --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/prev.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/prev.h new file mode 100644 index 0000000000000000000000000000000000000000..0c3798bcd8495b62579437b5fc0c20226a44d624 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/projected.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/projected.h new file mode 100644 index 0000000000000000000000000000000000000000..867604548180cdc1b153da1770d94fcd10ff1d35 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/readable_traits.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/readable_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..c80f927473395b3c961d2d1ccdb41c644dd88bf9 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/reverse_access.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/reverse_access.h new file mode 100644 index 0000000000000000000000000000000000000000..b326ec7a14e6b3f60b12f37357c6eeb76831a210 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/reverse_iterator.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/reverse_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..379dc97efd67ce4b29cff40a5ecb4aee5385a613 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/size.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/size.h new file mode 100644 index 0000000000000000000000000000000000000000..7207e552a23a83e78db32169ceaf2499677b3c19 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/sortable.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/sortable.h new file mode 100644 index 0000000000000000000000000000000000000000..6ddeddc5ed4ec3cc1ff28f3f44df0c0119411b6a --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/unreachable_sentinel.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/unreachable_sentinel.h new file mode 100644 index 0000000000000000000000000000000000000000..455651699121f79a0a8407fecc5c38372128b3a9 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__iterator/wrap_iter.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__iterator/wrap_iter.h new file mode 100644 index 0000000000000000000000000000000000000000..7da69520feca7a06d59856091afd0539a14f366b --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__libcpp_version b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__libcpp_version new file mode 100644 index 0000000000000000000000000000000000000000..5caff40c4a0ce4ed0dcb3aa983da623641af1b06 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__libcpp_version @@ -0,0 +1 @@ +10000 diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__locale b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__locale new file mode 100644 index 0000000000000000000000000000000000000000..17773f6bce705a7b18ffd49eca624f72f5ca2a94 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__locale @@ -0,0 +1,1557 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___LOCALE +#define _LIBCUDACXX___LOCALE + +#include <__config> +#include +#include +#include +#include +#include +#include +#include +#if defined(_LIBCUDACXX_MSVCRT_LIKE) +# include +# include +#elif defined(_AIX) +# include +#elif defined(__ANDROID__) +# include +#elif defined(__sun__) +# include +# include +#elif defined(_NEWLIB_VERSION) +# include +#elif (defined(__APPLE__) || defined(__FreeBSD__) \ + || defined(__EMSCRIPTEN__) || defined(__IBMCPP__)) +# include +#elif defined(__Fuchsia__) +# include +#elif defined(__wasi__) +// WASI libc uses musl's locales support. +# include +#elif defined(_LIBCUDACXX_HAS_MUSL_LIBC) +# include +#endif + +#if defined(_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 !defined(_LIBCUDACXX_LOCALE__L_EXTENSIONS) +struct __libcpp_locale_guard { + _LIBCUDACXX_INLINE_VISIBILITY + __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {} + + _LIBCUDACXX_INLINE_VISIBILITY + ~__libcpp_locale_guard() { + if (__old_loc_) + uselocale(__old_loc_); + } + + locale_t __old_loc_; +private: + __libcpp_locale_guard(__libcpp_locale_guard const&); + __libcpp_locale_guard& operator=(__libcpp_locale_guard const&); +}; +#elif defined(_LIBCUDACXX_MSVCRT_LIKE) +struct __libcpp_locale_guard { + __libcpp_locale_guard(locale_t __l) : + __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) { + // Setting the locale can be expensive even when the locale given is + // already the current locale, so do an explicit check to see if the + // current locale is already the one we want. + const char* __lc = __setlocale(nullptr); + // If every category is the same, the locale string will simply be the + // locale name, otherwise it will be a semicolon-separated string listing + // each category. In the second case, we know at least one category won't + // be what we want, so we only have to check the first case. + if (strcmp(__l.__get_locale(), __lc) != 0) { + __locale_all = _strdup(__lc); + if (__locale_all == nullptr) + __throw_bad_alloc(); + __setlocale(__l.__get_locale()); + } + } + ~__libcpp_locale_guard() { + // The CRT documentation doesn't explicitly say, but setlocale() does the + // right thing when given a semicolon-separated list of locale settings + // for the different categories in the same format as returned by + // setlocale(LC_ALL, nullptr). + if (__locale_all != nullptr) { + __setlocale(__locale_all); + free(__locale_all); + } + _configthreadlocale(__status); + } + static const char* __setlocale(const char* __locale) { + const char* __new_locale = setlocale(LC_ALL, __locale); + if (__new_locale == nullptr) + __throw_bad_alloc(); + return __new_locale; + } + int __status; + char* __locale_all = nullptr; +}; +#endif + + +class _LIBCUDACXX_TYPE_VIS locale; + +template +_LIBCUDACXX_INLINE_VISIBILITY +bool +has_facet(const locale&) noexcept; + +template +_LIBCUDACXX_INLINE_VISIBILITY +const _Facet& +use_facet(const locale&); + +class _LIBCUDACXX_TYPE_VIS locale +{ +public: + // types: + class _LIBCUDACXX_TYPE_VIS facet; + class _LIBCUDACXX_TYPE_VIS id; + + typedef int category; + _LIBCUDACXX_AVAILABILITY_LOCALE_CATEGORY + static const category // values assigned here are for exposition only + none = 0, + collate = LC_COLLATE_MASK, + ctype = LC_CTYPE_MASK, + monetary = LC_MONETARY_MASK, + numeric = LC_NUMERIC_MASK, + time = LC_TIME_MASK, + messages = LC_MESSAGES_MASK, + all = collate | ctype | monetary | numeric | time | messages; + + // construct/copy/destroy: + locale() noexcept; + locale(const locale&) noexcept; + explicit locale(const char*); + explicit locale(const string&); + locale(const locale&, const char*, category); + locale(const locale&, const string&, category); + template + _LIBCUDACXX_INLINE_VISIBILITY locale(const locale&, _Facet*); + locale(const locale&, const locale&, category); + + ~locale(); + + const locale& operator=(const locale&) noexcept; + + template + _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + locale combine(const locale&) const; + + // locale operations: + string name() const; + bool operator==(const locale&) const; + bool operator!=(const locale& __y) const {return !(*this == __y);} + template + _LIBCUDACXX_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + bool operator()(const basic_string<_CharT, _Traits, _Allocator>&, + const basic_string<_CharT, _Traits, _Allocator>&) const; + + // global locale objects: + static locale global(const locale&); + static const locale& classic(); + +private: + class __imp; + __imp* __locale_; + + void __install_ctor(const locale&, facet*, long); + static locale& __global(); + bool has_facet(id&) const; + const facet* use_facet(id&) const; + + template friend bool has_facet(const locale&) noexcept; + template friend const _Facet& use_facet(const locale&); +}; + +class _LIBCUDACXX_TYPE_VIS locale::facet + : public __shared_count +{ +protected: + _LIBCUDACXX_INLINE_VISIBILITY + explicit facet(size_t __refs = 0) + : __shared_count(static_cast(__refs)-1) {} + + virtual ~facet(); + +// facet(const facet&) = delete; // effectively done in __shared_count +// void operator=(const facet&) = delete; +private: + virtual void __on_zero_shared() noexcept; +}; + +class _LIBCUDACXX_TYPE_VIS locale::id +{ + once_flag __flag_; + int32_t __id_; + + static int32_t __next_id; +public: + _LIBCUDACXX_INLINE_VISIBILITY constexpr id() :__id_(0) {} +private: + void __init(); + void operator=(const id&); // = delete; + id(const id&); // = delete; +public: // only needed for tests + long __get(); + + friend class locale; + friend class locale::__imp; +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +locale::locale(const locale& __other, _Facet* __f) +{ + __install_ctor(__other, __f, __f ? __f->id.__get() : 0); +} + +template +locale +locale::combine(const locale& __other) const +{ + if (!_CUDA_VSTD::has_facet<_Facet>(__other)) + __throw_runtime_error("locale::combine: locale missing facet"); + + return locale(*this, &const_cast<_Facet&>(_CUDA_VSTD::use_facet<_Facet>(__other))); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +has_facet(const locale& __l) noexcept +{ + return __l.has_facet(_Facet::id); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +const _Facet& +use_facet(const locale& __l) +{ + return static_cast(*__l.use_facet(_Facet::id)); +} + +// template class collate; + +template +class _LIBCUDACXX_TEMPLATE_VIS collate + : public locale::facet +{ +public: + typedef _CharT char_type; + typedef basic_string string_type; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit collate(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCUDACXX_INLINE_VISIBILITY + int compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const + { + return do_compare(__lo1, __hi1, __lo2, __hi2); + } + + // FIXME(EricWF): The _LIBCUDACXX_ALWAYS_INLINE is needed on Windows to work + // around a dllimport bug that expects an external instantiation. + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_ALWAYS_INLINE + string_type transform(const char_type* __lo, const char_type* __hi) const + { + return do_transform(__lo, __hi); + } + + _LIBCUDACXX_INLINE_VISIBILITY + long hash(const char_type* __lo, const char_type* __hi) const + { + return do_hash(__lo, __hi); + } + + static locale::id id; + +protected: + ~collate(); + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const + {return string_type(__lo, __hi);} + virtual long do_hash(const char_type* __lo, const char_type* __hi) const; +}; + +template locale::id collate<_CharT>::id; + +template +collate<_CharT>::~collate() +{ +} + +template +int +collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const +{ + for (; __lo2 != __hi2; ++__lo1, ++__lo2) + { + if (__lo1 == __hi1 || *__lo1 < *__lo2) + return -1; + if (*__lo2 < *__lo1) + return 1; + } + return __lo1 != __hi1; +} + +template +long +collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const +{ + size_t __h = 0; + const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8; + const size_t __mask = size_t(0xF) << (__sr + 4); + for(const char_type* __p = __lo; __p != __hi; ++__p) + { + __h = (__h << 4) + static_cast(*__p); + size_t __g = __h & __mask; + __h ^= __g | (__g >> __sr); + } + return static_cast(__h); +} + +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS collate) +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS collate) + +// template class collate_byname; + +template class _LIBCUDACXX_TEMPLATE_VIS collate_byname; + +template <> +class _LIBCUDACXX_TYPE_VIS collate_byname + : public collate +{ + locale_t __l; +public: + typedef char char_type; + typedef basic_string string_type; + + explicit collate_byname(const char* __n, size_t __refs = 0); + explicit collate_byname(const string& __n, size_t __refs = 0); + +protected: + ~collate_byname(); + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; +}; + +template <> +class _LIBCUDACXX_TYPE_VIS collate_byname + : public collate +{ + locale_t __l; +public: + typedef wchar_t char_type; + typedef basic_string string_type; + + explicit collate_byname(const char* __n, size_t __refs = 0); + explicit collate_byname(const string& __n, size_t __refs = 0); + +protected: + ~collate_byname(); + + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; +}; + +template +bool +locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, + const basic_string<_CharT, _Traits, _Allocator>& __y) const +{ + return _CUDA_VSTD::use_facet<_CUDA_VSTD::collate<_CharT> >(*this).compare( + __x.data(), __x.data() + __x.size(), + __y.data(), __y.data() + __y.size()) < 0; +} + +// template class ctype + +class _LIBCUDACXX_TYPE_VIS ctype_base +{ +public: +#if defined(__GLIBC__) + typedef unsigned short mask; + static const mask space = _ISspace; + static const mask print = _ISprint; + static const mask cntrl = _IScntrl; + static const mask upper = _ISupper; + static const mask lower = _ISlower; + static const mask alpha = _ISalpha; + static const mask digit = _ISdigit; + static const mask punct = _ISpunct; + static const mask xdigit = _ISxdigit; + static const mask blank = _ISblank; +#if defined(__mips__) + static const mask __regex_word = static_cast(_ISbit(15)); +#else + static const mask __regex_word = 0x80; +#endif +#elif defined(_LIBCUDACXX_MSVCRT_LIKE) + typedef unsigned short mask; + static const mask space = _SPACE; + static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT; + static const mask cntrl = _CONTROL; + static const mask upper = _UPPER; + static const mask lower = _LOWER; + static const mask alpha = _ALPHA; + static const mask digit = _DIGIT; + static const mask punct = _PUNCT; + static const mask xdigit = _HEX; + static const mask blank = _BLANK; + static const mask __regex_word = 0x80; +# define _LIBCUDACXX_CTYPE_MASK_IS_COMPOSITE_PRINT +#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) +# ifdef __APPLE__ + typedef __uint32_t mask; +# elif defined(__FreeBSD__) + typedef unsigned long mask; +# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__) + typedef unsigned short mask; +# endif + static const mask space = _CTYPE_S; + static const mask print = _CTYPE_R; + static const mask cntrl = _CTYPE_C; + static const mask upper = _CTYPE_U; + static const mask lower = _CTYPE_L; + static const mask alpha = _CTYPE_A; + static const mask digit = _CTYPE_D; + static const mask punct = _CTYPE_P; + static const mask xdigit = _CTYPE_X; + +# if defined(__NetBSD__) + static const mask blank = _CTYPE_BL; + // NetBSD defines classes up to 0x2000 + // see sys/ctype_bits.h, _CTYPE_Q + static const mask __regex_word = 0x8000; +# else + static const mask blank = _CTYPE_B; + static const mask __regex_word = 0x80; +# endif +#elif defined(__sun__) || defined(_AIX) + typedef unsigned int mask; + static const mask space = _ISSPACE; + static const mask print = _ISPRINT; + static const mask cntrl = _ISCNTRL; + static const mask upper = _ISUPPER; + static const mask lower = _ISLOWER; + static const mask alpha = _ISALPHA; + static const mask digit = _ISDIGIT; + static const mask punct = _ISPUNCT; + static const mask xdigit = _ISXDIGIT; + static const mask blank = _ISBLANK; + static const mask __regex_word = 0x80; +#elif defined(_NEWLIB_VERSION) + // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h. + typedef char mask; + static const mask space = _S; + static const mask print = _P | _U | _L | _N | _B; + static const mask cntrl = _C; + static const mask upper = _U; + static const mask lower = _L; + static const mask alpha = _U | _L; + static const mask digit = _N; + static const mask punct = _P; + static const mask xdigit = _X | _N; + static const mask blank = _B; + static const mask __regex_word = 0x80; +# define _LIBCUDACXX_CTYPE_MASK_IS_COMPOSITE_PRINT +# define _LIBCUDACXX_CTYPE_MASK_IS_COMPOSITE_ALPHA +# define _LIBCUDACXX_CTYPE_MASK_IS_COMPOSITE_XDIGIT +#else + typedef unsigned long mask; + static const mask space = 1<<0; + static const mask print = 1<<1; + static const mask cntrl = 1<<2; + static const mask upper = 1<<3; + static const mask lower = 1<<4; + static const mask alpha = 1<<5; + static const mask digit = 1<<6; + static const mask punct = 1<<7; + static const mask xdigit = 1<<8; + static const mask blank = 1<<9; + static const mask __regex_word = 1<<10; +#endif + static const mask alnum = alpha | digit; + static const mask graph = alnum | punct; + + _LIBCUDACXX_INLINE_VISIBILITY ctype_base() {} +}; + +template class _LIBCUDACXX_TEMPLATE_VIS ctype; + +template <> +class _LIBCUDACXX_TYPE_VIS ctype + : public locale::facet, + public ctype_base +{ +public: + typedef wchar_t char_type; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit ctype(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCUDACXX_INLINE_VISIBILITY + bool is(mask __m, char_type __c) const + { + return do_is(__m, __c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const + { + return do_is(__low, __high, __vec); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const + { + return do_scan_is(__m, __low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const + { + return do_scan_not(__m, __low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type toupper(char_type __c) const + { + return do_toupper(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* toupper(char_type* __low, const char_type* __high) const + { + return do_toupper(__low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type tolower(char_type __c) const + { + return do_tolower(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* tolower(char_type* __low, const char_type* __high) const + { + return do_tolower(__low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type widen(char __c) const + { + return do_widen(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char* widen(const char* __low, const char* __high, char_type* __to) const + { + return do_widen(__low, __high, __to); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char narrow(char_type __c, char __dfault) const + { + return do_narrow(__c, __dfault); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const + { + return do_narrow(__low, __high, __dfault, __to); + } + + static locale::id id; + +protected: + ~ctype(); + virtual bool do_is(mask __m, char_type __c) const; + virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; + virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; + virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; + virtual char do_narrow(char_type, char __dfault) const; + virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; +}; + +template <> +class _LIBCUDACXX_TYPE_VIS ctype + : public locale::facet, public ctype_base +{ + const mask* __tab_; + bool __del_; +public: + typedef char char_type; + + explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0); + + _LIBCUDACXX_INLINE_VISIBILITY + bool is(mask __m, char_type __c) const + { + return isascii(__c) ? (__tab_[static_cast(__c)] & __m) !=0 : false; + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const + { + for (; __low != __high; ++__low, ++__vec) + *__vec = isascii(*__low) ? __tab_[static_cast(*__low)] : 0; + return __low; + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const + { + for (; __low != __high; ++__low) + if (isascii(*__low) && (__tab_[static_cast(*__low)] & __m)) + break; + return __low; + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const + { + for (; __low != __high; ++__low) + if (!(isascii(*__low) && (__tab_[static_cast(*__low)] & __m))) + break; + return __low; + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type toupper(char_type __c) const + { + return do_toupper(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* toupper(char_type* __low, const char_type* __high) const + { + return do_toupper(__low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type tolower(char_type __c) const + { + return do_tolower(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char_type* tolower(char_type* __low, const char_type* __high) const + { + return do_tolower(__low, __high); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char_type widen(char __c) const + { + return do_widen(__c); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char* widen(const char* __low, const char* __high, char_type* __to) const + { + return do_widen(__low, __high, __to); + } + + _LIBCUDACXX_INLINE_VISIBILITY + char narrow(char_type __c, char __dfault) const + { + return do_narrow(__c, __dfault); + } + + _LIBCUDACXX_INLINE_VISIBILITY + const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const + { + return do_narrow(__low, __high, __dfault, __to); + } + + static locale::id id; + +#ifdef _CACHED_RUNES + static const size_t table_size = _CACHED_RUNES; +#else + static const size_t table_size = 256; // FIXME: Don't hardcode this. +#endif + _LIBCUDACXX_INLINE_VISIBILITY const mask* table() const noexcept {return __tab_;} + static const mask* classic_table() noexcept; +#if defined(__GLIBC__) || defined(__EMSCRIPTEN__) + static const int* __classic_upper_table() noexcept; + static const int* __classic_lower_table() noexcept; +#endif +#if defined(__NetBSD__) + static const short* __classic_upper_table() noexcept; + static const short* __classic_lower_table() noexcept; +#endif + +protected: + ~ctype(); + virtual char_type do_toupper(char_type __c) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type __c) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char __c) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const; + virtual char do_narrow(char_type __c, char __dfault) const; + virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const; +}; + +// template class ctype_byname; + +template class _LIBCUDACXX_TEMPLATE_VIS ctype_byname; + +template <> +class _LIBCUDACXX_TYPE_VIS ctype_byname + : public ctype +{ + locale_t __l; + +public: + explicit ctype_byname(const char*, size_t = 0); + explicit ctype_byname(const string&, size_t = 0); + +protected: + ~ctype_byname(); + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; +}; + +template <> +class _LIBCUDACXX_TYPE_VIS ctype_byname + : public ctype +{ + locale_t __l; + +public: + explicit ctype_byname(const char*, size_t = 0); + explicit ctype_byname(const string&, size_t = 0); + +protected: + ~ctype_byname(); + virtual bool do_is(mask __m, char_type __c) const; + virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; + virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; + virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; + virtual char do_narrow(char_type, char __dfault) const; + virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isspace(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::space, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isprint(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::print, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +iscntrl(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::cntrl, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isupper(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::upper, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +islower(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::lower, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isalpha(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::alpha, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isdigit(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::digit, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +ispunct(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::punct, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isxdigit(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::xdigit, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isalnum(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::alnum, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +isgraph(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::graph, __c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +_CharT +toupper(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).toupper(__c); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +_CharT +tolower(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).tolower(__c); +} + +// codecvt_base + +class _LIBCUDACXX_TYPE_VIS codecvt_base +{ +public: + _LIBCUDACXX_INLINE_VISIBILITY codecvt_base() {} + enum result {ok, partial, error, noconv}; +}; + +// template class codecvt; + +template class _LIBCUDACXX_TEMPLATE_VIS codecvt; + +// template <> class codecvt + +template <> +class _LIBCUDACXX_TYPE_VIS codecvt + : public locale::facet, + public codecvt_base +{ +public: + typedef char intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCUDACXX_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int encoding() const noexcept + { + return do_encoding(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + bool always_noconv() const noexcept + { + return do_always_noconv(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int max_length() const noexcept + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const noexcept; + virtual bool do_always_noconv() const noexcept; + virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const noexcept; +}; + +// template <> class codecvt + +template <> +class _LIBCUDACXX_TYPE_VIS codecvt + : public locale::facet, + public codecvt_base +{ + locale_t __l; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + explicit codecvt(size_t __refs = 0); + + _LIBCUDACXX_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int encoding() const noexcept + { + return do_encoding(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + bool always_noconv() const noexcept + { + return do_always_noconv(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int max_length() const noexcept + { + return do_max_length(); + } + + static locale::id id; + +protected: + explicit codecvt(const char*, size_t __refs = 0); + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const noexcept; + virtual bool do_always_noconv() const noexcept; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const noexcept; +}; + +// template <> class codecvt + +template <> +class _LIBCUDACXX_TYPE_VIS codecvt + : public locale::facet, + public codecvt_base +{ +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCUDACXX_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int encoding() const noexcept + { + return do_encoding(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + bool always_noconv() const noexcept + { + return do_always_noconv(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int max_length() const noexcept + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const noexcept; + virtual bool do_always_noconv() const noexcept; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const noexcept; +}; + +// template <> class codecvt + +template <> +class _LIBCUDACXX_TYPE_VIS codecvt + : public locale::facet, + public codecvt_base +{ +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCUDACXX_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int encoding() const noexcept + { + return do_encoding(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + bool always_noconv() const noexcept + { + return do_always_noconv(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCUDACXX_INLINE_VISIBILITY + int max_length() const noexcept + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const noexcept; + virtual bool do_always_noconv() const noexcept; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const noexcept; +}; + +// template class codecvt_byname + +template +class _LIBCUDACXX_TEMPLATE_VIS codecvt_byname + : public codecvt<_InternT, _ExternT, _StateT> +{ +public: + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt_byname(const char* __nm, size_t __refs = 0) + : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {} + _LIBCUDACXX_INLINE_VISIBILITY + explicit codecvt_byname(const string& __nm, size_t __refs = 0) + : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {} +protected: + ~codecvt_byname(); +}; + +template +codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() +{ +} + +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) +_LIBCUDACXX_EXTERN_TEMPLATE2(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) + +template +struct __narrow_to_utf8 +{ + template + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const; +}; + +template <> +struct __narrow_to_utf8<8> +{ + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + for (; __wb < __we; ++__wb, ++__s) + *__s = *__wb; + return __s; + } +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS __narrow_to_utf8<16> + : public codecvt +{ + _LIBCUDACXX_INLINE_VISIBILITY + __narrow_to_utf8() : codecvt(1) {} + + _LIBCUDACXX_EXPORTED_FROM_ABI ~__narrow_to_utf8(); + + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + result __r = ok; + mbstate_t __mb; + while (__wb < __we && __r != error) + { + const int __sz = 32; + char __buf[__sz]; + char* __bn; + const char16_t* __wn = (const char16_t*)__wb; + __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __wn == (const char16_t*)__wb) + __throw_runtime_error("locale not supported"); + for (const char* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = *__p; + __wb = (const _CharT*)__wn; + } + return __s; + } +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS __narrow_to_utf8<32> + : public codecvt +{ + _LIBCUDACXX_INLINE_VISIBILITY + __narrow_to_utf8() : codecvt(1) {} + + _LIBCUDACXX_EXPORTED_FROM_ABI ~__narrow_to_utf8(); + + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + result __r = ok; + mbstate_t __mb; + while (__wb < __we && __r != error) + { + const int __sz = 32; + char __buf[__sz]; + char* __bn; + const char32_t* __wn = (const char32_t*)__wb; + __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __wn == (const char32_t*)__wb) + __throw_runtime_error("locale not supported"); + for (const char* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = *__p; + __wb = (const _CharT*)__wn; + } + return __s; + } +}; + +template +struct __widen_from_utf8 +{ + template + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const; +}; + +template <> +struct __widen_from_utf8<8> +{ + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + for (; __nb < __ne; ++__nb, ++__s) + *__s = *__nb; + return __s; + } +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS __widen_from_utf8<16> + : public codecvt +{ + _LIBCUDACXX_INLINE_VISIBILITY + __widen_from_utf8() : codecvt(1) {} + + _LIBCUDACXX_EXPORTED_FROM_ABI ~__widen_from_utf8(); + + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + result __r = ok; + mbstate_t __mb; + while (__nb < __ne && __r != error) + { + const int __sz = 32; + char16_t __buf[__sz]; + char16_t* __bn; + const char* __nn = __nb; + __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __nn == __nb) + __throw_runtime_error("locale not supported"); + for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = (wchar_t)*__p; + __nb = __nn; + } + return __s; + } +}; + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS __widen_from_utf8<32> + : public codecvt +{ + _LIBCUDACXX_INLINE_VISIBILITY + __widen_from_utf8() : codecvt(1) {} + + _LIBCUDACXX_EXPORTED_FROM_ABI ~__widen_from_utf8(); + + template + _LIBCUDACXX_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + result __r = ok; + mbstate_t __mb; + while (__nb < __ne && __r != error) + { + const int __sz = 32; + char32_t __buf[__sz]; + char32_t* __bn; + const char* __nn = __nb; + __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __nn == __nb) + __throw_runtime_error("locale not supported"); + for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = (wchar_t)*__p; + __nb = __nn; + } + return __s; + } +}; + +// template class numpunct + +template class _LIBCUDACXX_TEMPLATE_VIS numpunct; + +template <> +class _LIBCUDACXX_TYPE_VIS numpunct + : public locale::facet +{ +public: + typedef char char_type; + typedef basic_string string_type; + + explicit numpunct(size_t __refs = 0); + + _LIBCUDACXX_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();} + _LIBCUDACXX_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();} + _LIBCUDACXX_INLINE_VISIBILITY string grouping() const {return do_grouping();} + _LIBCUDACXX_INLINE_VISIBILITY string_type truename() const {return do_truename();} + _LIBCUDACXX_INLINE_VISIBILITY string_type falsename() const {return do_falsename();} + + static locale::id id; + +protected: + ~numpunct(); + virtual char_type do_decimal_point() const; + virtual char_type do_thousands_sep() const; + virtual string do_grouping() const; + virtual string_type do_truename() const; + virtual string_type do_falsename() const; + + char_type __decimal_point_; + char_type __thousands_sep_; + string __grouping_; +}; + +template <> +class _LIBCUDACXX_TYPE_VIS numpunct + : public locale::facet +{ +public: + typedef wchar_t char_type; + typedef basic_string string_type; + + explicit numpunct(size_t __refs = 0); + + _LIBCUDACXX_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();} + _LIBCUDACXX_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();} + _LIBCUDACXX_INLINE_VISIBILITY string grouping() const {return do_grouping();} + _LIBCUDACXX_INLINE_VISIBILITY string_type truename() const {return do_truename();} + _LIBCUDACXX_INLINE_VISIBILITY string_type falsename() const {return do_falsename();} + + static locale::id id; + +protected: + ~numpunct(); + virtual char_type do_decimal_point() const; + virtual char_type do_thousands_sep() const; + virtual string do_grouping() const; + virtual string_type do_truename() const; + virtual string_type do_falsename() const; + + char_type __decimal_point_; + char_type __thousands_sep_; + string __grouping_; +}; + +// template class numpunct_byname + +template class _LIBCUDACXX_TEMPLATE_VIS numpunct_byname; + +template <> +class _LIBCUDACXX_TYPE_VIS numpunct_byname +: public numpunct +{ +public: + typedef char char_type; + typedef basic_string string_type; + + explicit numpunct_byname(const char* __nm, size_t __refs = 0); + explicit numpunct_byname(const string& __nm, size_t __refs = 0); + +protected: + ~numpunct_byname(); + +private: + void __init(const char*); +}; + +template <> +class _LIBCUDACXX_TYPE_VIS numpunct_byname +: public numpunct +{ +public: + typedef wchar_t char_type; + typedef basic_string string_type; + + explicit numpunct_byname(const char* __nm, size_t __refs = 0); + explicit numpunct_byname(const string& __nm, size_t __refs = 0); + +protected: + ~numpunct_byname(); + +private: + void __init(const char*); +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___LOCALE diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h new file mode 100644 index 0000000000000000000000000000000000000000..f122a439efafa8967afae23b6761c50c8bb3f3b0 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/config.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/config.h new file mode 100644 index 0000000000000000000000000000000000000000..dc2de57dbd8b071e1507ff08e05ae79540f624cc --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/config.h @@ -0,0 +1,287 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_CONFIG_HPP +#define _LIBCUDACXX___MDSPAN_CONFIG_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#if _LIBCUDACXX_STD_VER > 11 + +#ifndef __has_include +# define __has_include(x) 0 +#endif + +#ifndef __cuda_std__ +#if __has_include() +# include +#else +# include +# include +#endif +#endif + +#ifdef _MSVC_LANG +#define __MDSPAN_CPLUSPLUS _MSVC_LANG +#else +#define __MDSPAN_CPLUSPLUS __cplusplus +#endif + +#define __MDSPAN_CXX_STD_14 201402L +#define __MDSPAN_CXX_STD_17 201703L +#define __MDSPAN_CXX_STD_20 202002L + +#define __MDSPAN_HAS_CXX_14 (__MDSPAN_CPLUSPLUS >= __MDSPAN_CXX_STD_14) +#define __MDSPAN_HAS_CXX_17 (__MDSPAN_CPLUSPLUS >= __MDSPAN_CXX_STD_17) +#define __MDSPAN_HAS_CXX_20 (__MDSPAN_CPLUSPLUS >= __MDSPAN_CXX_STD_20) + +static_assert(__MDSPAN_CPLUSPLUS >= __MDSPAN_CXX_STD_14, "mdspan requires C++14 or later."); + +#ifndef __MDSPAN_COMPILER_CLANG +# if defined(__clang__) +# define __MDSPAN_COMPILER_CLANG __clang__ +# endif +#endif + +#if !defined(__MDSPAN_COMPILER_MSVC) && !defined(__MDSPAN_COMPILER_MSVC_CLANG) +# if defined(_MSC_VER) +# if !defined(__MDSPAN_COMPILER_CLANG) +# define __MDSPAN_COMPILER_MSVC _MSC_VER +# else +# define __MDSPAN_COMPILER_MSVC_CLANG _MSC_VER +# endif +# endif +#endif + +#ifndef __MDSPAN_COMPILER_INTEL +# ifdef __INTEL_COMPILER +# define __MDSPAN_COMPILER_INTEL __INTEL_COMPILER +# endif +#endif + +#ifndef __MDSPAN_COMPILER_APPLECLANG +# ifdef __apple_build_version__ +# define __MDSPAN_COMPILER_APPLECLANG __apple_build_version__ +# endif +#endif + +#ifndef __MDSPAN_HAS_CUDA +# if defined(__CUDACC__) +# define __MDSPAN_HAS_CUDA __CUDACC__ +# endif +#endif + +#ifndef __MDSPAN_HAS_HIP +# if defined(__HIPCC__) +# define __MDSPAN_HAS_HIP __HIPCC__ +# endif +#endif + +#ifndef __has_cpp_attribute +# define __has_cpp_attribute(x) 0 +#endif + +#ifndef __MDSPAN_PRESERVE_STANDARD_LAYOUT +// Preserve standard layout by default, but we're not removing the old version +// that turns this off until we're sure this doesn't have an unreasonable cost +// to the compiler or optimizer. +# define __MDSPAN_PRESERVE_STANDARD_LAYOUT 1 +#endif + +#ifndef __MDSPAN_USE_CONCEPTS +// Looks like concepts doesn't work in CUDA 12 +# if defined(__cpp_concepts) && __cpp_concepts >= 201507L && !defined __cuda_std__ +# define __MDSPAN_USE_CONCEPTS 1 +# endif +#endif + +#ifndef __MDSPAN_USE_FOLD_EXPRESSIONS +# if (defined(__cpp_fold_expressions) && __cpp_fold_expressions >= 201603L) \ + || (!defined(__cpp_fold_expressions) && __MDSPAN_HAS_CXX_17) +# define __MDSPAN_USE_FOLD_EXPRESSIONS 1 +# endif +#endif + +#ifndef __MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS +# if (!(defined(__cpp_lib_type_trait_variable_templates) && __cpp_lib_type_trait_variable_templates >= 201510L) \ + || !__MDSPAN_HAS_CXX_17) +# if !(defined(__MDSPAN_COMPILER_APPLECLANG) && __MDSPAN_HAS_CXX_17) +# define __MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS 1 +# endif +# endif +#endif + +#ifndef __MDSPAN_USE_VARIABLE_TEMPLATES +# if (defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 && __MDSPAN_HAS_CXX_17) \ + || (!defined(__cpp_variable_templates) && __MDSPAN_HAS_CXX_17) +# define __MDSPAN_USE_VARIABLE_TEMPLATES 1 +# endif +#endif // __MDSPAN_USE_VARIABLE_TEMPLATES + +#ifndef __MDSPAN_USE_CONSTEXPR_14 +# if (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) \ + || (!defined(__cpp_constexpr) && __MDSPAN_HAS_CXX_14) \ + && (!(defined(__INTEL_COMPILER) && __INTEL_COMPILER <= 1700)) +# define __MDSPAN_USE_CONSTEXPR_14 1 +# endif +#endif + +#ifndef __MDSPAN_USE_INTEGER_SEQUENCE +# if defined(__MDSPAN_COMPILER_MSVC) +# if (defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304) +# define __MDSPAN_USE_INTEGER_SEQUENCE 1 +# endif +# endif +#endif +#ifndef __MDSPAN_USE_INTEGER_SEQUENCE +# if (defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304) \ + || (!defined(__cpp_lib_integer_sequence) && __MDSPAN_HAS_CXX_14) \ + /* as far as I can tell, libc++ seems to think this is a C++11 feature... */ \ + || (defined(__GLIBCXX__) && __GLIBCXX__ > 20150422 && __GNUC__ < 5 && !defined(__INTEL_CXX11_MODE__)) + // several compilers lie about integer_sequence working properly unless the C++14 standard is used +# define __MDSPAN_USE_INTEGER_SEQUENCE 1 +# elif defined(__MDSPAN_COMPILER_APPLECLANG) && __MDSPAN_HAS_CXX_14 + // appleclang seems to be missing the __cpp_lib_... macros, but doesn't seem to lie about C++14 making + // integer_sequence work +# define __MDSPAN_USE_INTEGER_SEQUENCE 1 +# endif +#endif + +#ifndef __MDSPAN_USE_RETURN_TYPE_DEDUCTION +# if (defined(__cpp_return_type_deduction) && __cpp_return_type_deduction >= 201304) \ + || (!defined(__cpp_return_type_deduction) && __MDSPAN_HAS_CXX_14) +# define __MDSPAN_USE_RETURN_TYPE_DEDUCTION 1 +# endif +#endif + +#ifndef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION +// GCC 10 is known not to work with CTAD for this case. +# if (defined(__MDSPAN_COMPILER_CLANG) || !defined(_LIBCUDACXX_COMPILER_GCC) || __GNUC__ >= 11) \ + && ((defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201703) \ + || (!defined(__cpp_deduction_guides) && __MDSPAN_HAS_CXX_17)) +# define __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1 +# endif +#endif + +#ifndef __MDSPAN_USE_ALIAS_TEMPLATE_ARGUMENT_DEDUCTION +// GCC 10 is known not to work with CTAD for this case. +# if (defined(__MDSPAN_COMPILER_CLANG) || !defined(_LIBCUDACXX_COMPILER_GCC) || __GNUC__ >= 11) \ + && ((defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201907) \ + || (!defined(__cpp_deduction_guides) && __MDSPAN_HAS_CXX_20)) +# define __MDSPAN_USE_ALIAS_TEMPLATE_ARGUMENT_DEDUCTION 1 +# endif +#endif + +#ifndef __MDSPAN_USE_STANDARD_TRAIT_ALIASES +# if (defined(__cpp_lib_transformation_trait_aliases) && __cpp_lib_transformation_trait_aliases >= 201304) \ + || (!defined(__cpp_lib_transformation_trait_aliases) && __MDSPAN_HAS_CXX_14) +# define __MDSPAN_USE_STANDARD_TRAIT_ALIASES 1 +# elif defined(__MDSPAN_COMPILER_APPLECLANG) && __MDSPAN_HAS_CXX_14 + // appleclang seems to be missing the __cpp_lib_... macros, but doesn't seem to lie about C++14 +# define __MDSPAN_USE_STANDARD_TRAIT_ALIASES 1 +# endif +#endif + +#ifndef __MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND +# ifdef __GNUC__ +# if __GNUC__ < 9 +# define __MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND 1 +# endif +# endif +#endif + +#ifndef __MDSPAN_CONDITIONAL_EXPLICIT +# if __MDSPAN_HAS_CXX_20 && !defined(__MDSPAN_COMPILER_MSVC) +# define __MDSPAN_CONDITIONAL_EXPLICIT(COND) explicit(COND) +# else +# define __MDSPAN_CONDITIONAL_EXPLICIT(COND) +# endif +#endif + +#ifndef __MDSPAN_USE_BRACKET_OPERATOR +# if defined(__cpp_multidimensional_subscript) +# define __MDSPAN_USE_BRACKET_OPERATOR 1 +# else +# define __MDSPAN_USE_BRACKET_OPERATOR 0 +# endif +#endif + +#ifndef __MDSPAN_USE_PAREN_OPERATOR +# if !__MDSPAN_USE_BRACKET_OPERATOR +# define __MDSPAN_USE_PAREN_OPERATOR 1 +# else +# define __MDSPAN_USE_PAREN_OPERATOR 0 +# endif +#endif + +#if __MDSPAN_USE_BRACKET_OPERATOR +# define __MDSPAN_OP(mds,...) mds[__VA_ARGS__] +// Corentins demo compiler for subscript chokes on empty [] call, +// though I believe the proposal supports it? +#ifdef __MDSPAN_NO_EMPTY_BRACKET_OPERATOR +# define __MDSPAN_OP0(mds) mds.accessor().access(mds.data_handle(),0) +#else +# define __MDSPAN_OP0(mds) mds[] +#endif +# define __MDSPAN_OP1(mds, a) mds[a] +# define __MDSPAN_OP2(mds, a, b) mds[a,b] +# define __MDSPAN_OP3(mds, a, b, c) mds[a,b,c] +# define __MDSPAN_OP4(mds, a, b, c, d) mds[a,b,c,d] +# define __MDSPAN_OP5(mds, a, b, c, d, e) mds[a,b,c,d,e] +# define __MDSPAN_OP6(mds, a, b, c, d, e, f) mds[a,b,c,d,e,f] +#else +# define __MDSPAN_OP(mds,...) mds(__VA_ARGS__) +# define __MDSPAN_OP0(mds) mds() +# define __MDSPAN_OP1(mds, a) mds(a) +# define __MDSPAN_OP2(mds, a, b) mds(a,b) +# define __MDSPAN_OP3(mds, a, b, c) mds(a,b,c) +# define __MDSPAN_OP4(mds, a, b, c, d) mds(a,b,c,d) +# define __MDSPAN_OP5(mds, a, b, c, d, e) mds(a,b,c,d,e) +# define __MDSPAN_OP6(mds, a, b, c, d, e, f) mds(a,b,c,d,e,f) +#endif + +#endif // _LIBCUDACXX_STD_VER > 11 + +#endif // _LIBCUDACXX___MDSPAN_CONFIG_HPP diff --git a/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h new file mode 100644 index 0000000000000000000000000000000000000000..e20e176f96333730331339d1595f460a456e9536 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h new file mode 100644 index 0000000000000000000000000000000000000000..bcfb9b24273d7b8a73c54a4121ed4ac8bac7124d --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h @@ -0,0 +1,83 @@ +/* +//@HEADER +// ************************************************************************ +// +// Kokkos v. 2.0 +// Copyright (2019) Sandia Corporation +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the Corporation nor the names of the +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Christian R. Trott (crtrott@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef _LIBCUDACXX___MDSPAN_DYNAMIC_EXTENT_HPP +#define _LIBCUDACXX___MDSPAN_DYNAMIC_EXTENT_HPP + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__fwd/span.h" // dynamic_extent +#include "../__mdspan/macros.h" +#include "../cstddef" +#include "../limits" // numeric_limits + +#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/cuda/std/detail/libcxx/include/__mdspan/extents.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/extents.h new file mode 100644 index 0000000000000000000000000000000000000000..606535b508a09c3bd3809f779741e7cffd6a8fb7 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h new file mode 100644 index 0000000000000000000000000000000000000000..3b7ef55d1c1820a95e7bb8b3b14df858f63ee888 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/layout_left.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h new file mode 100644 index 0000000000000000000000000000000000000000..0d40e662a72f08141f7e27caa6b66c0f3e7ffe63 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/layout_right.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h new file mode 100644 index 0000000000000000000000000000000000000000..fdcd42408dec7d5700380a152d8b2c25b4a7f0e7 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h new file mode 100644 index 0000000000000000000000000000000000000000..6ccc53851fe31c07592b7b238f6bbf2df3c90a96 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/macros.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/macros.h new file mode 100644 index 0000000000000000000000000000000000000000..0821035963126725746d93f4aae8f552966e8794 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h new file mode 100644 index 0000000000000000000000000000000000000000..0f3c858d6f6a97eb6932db73527e18ccf5e746c4 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/mdspan.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h new file mode 100644 index 0000000000000000000000000000000000000000..52bc8ebe482ed42efa6364de48bab32124e4a82a --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h new file mode 100644 index 0000000000000000000000000000000000000000..1ce2d40e373de3e8798734f497fad6cef74d0587 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h new file mode 100644 index 0000000000000000000000000000000000000000..b6155432c3fb8cf510cc6a5b38b7ee98ab757d1e --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/static_array.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h new file mode 100644 index 0000000000000000000000000000000000000000..ef7479a7f7150207a6330a8b544d5609342ced0a --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/submdspan.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h new file mode 100644 index 0000000000000000000000000000000000000000..ef93663e915768bbc4ce70316a76df84d4e71f95 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__mdspan/type_list.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h new file mode 100644 index 0000000000000000000000000000000000000000..66c0e623069b6cf7a9b16ba76e7f66b402edd5b8 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__memory/addressof.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__memory/addressof.h new file mode 100644 index 0000000000000000000000000000000000000000..b7024fcf868f62b16580b75a04057bdd11c97854 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__memory/construct_at.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__memory/construct_at.h new file mode 100644 index 0000000000000000000000000000000000000000..e86b13442b42ed44403075eb561dbc8c7524052b --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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/cuda/std/detail/libcxx/include/__memory/pointer_traits.h b/cuda_toolkit/include/cuda/std/detail/libcxx/include/__memory/pointer_traits.h new file mode 100644 index 0000000000000000000000000000000000000000..fbea61af92d54b86fed2e5dca48faa1f96653c21 --- /dev/null +++ b/cuda_toolkit/include/cuda/std/detail/libcxx/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