From 8beb664aa1c08697a6c5590d02bf63bf84a920e4 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Wed, 8 Feb 2023 11:52:33 +0100 Subject: [PATCH 1/7] Move `as_const` into its own file Also make it available in C++14 onwards --- .../meta.trans.cv/add_const.pass.cpp | 1 + .../as_const/as_const.compile.fail.cpp | 25 ++++++++++ .../utility/as_const/as_const.pass.cpp | 50 +++++++++++++++++++ .../std/detail/libcxx/include/CMakeLists.txt | 1 + .../libcxx/include/__utility/as_const.h | 35 +++++++++++++ .../cuda/std/detail/libcxx/include/utility | 6 +-- 6 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 .upstream-tests/test/std/utilities/utility/as_const/as_const.compile.fail.cpp create mode 100644 .upstream-tests/test/std/utilities/utility/as_const/as_const.pass.cpp create mode 100644 include/cuda/std/detail/libcxx/include/__utility/as_const.h diff --git a/.upstream-tests/test/std/utilities/meta/meta.trans/meta.trans.cv/add_const.pass.cpp b/.upstream-tests/test/std/utilities/meta/meta.trans/meta.trans.cv/add_const.pass.cpp index dd33517aa8..655ca88104 100644 --- a/.upstream-tests/test/std/utilities/meta/meta.trans/meta.trans.cv/add_const.pass.cpp +++ b/.upstream-tests/test/std/utilities/meta/meta.trans/meta.trans.cv/add_const.pass.cpp @@ -3,6 +3,7 @@ // Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. // //===----------------------------------------------------------------------===// diff --git a/.upstream-tests/test/std/utilities/utility/as_const/as_const.compile.fail.cpp b/.upstream-tests/test/std/utilities/utility/as_const/as_const.compile.fail.cpp new file mode 100644 index 0000000000..f32432ae45 --- /dev/null +++ b/.upstream-tests/test/std/utilities/utility/as_const/as_const.compile.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11 +// UNSUPPORTED: nvrtc + +// template constexpr add_const& as_const(T& t) noexcept; // C++17 +// template add_const& as_const(const T&&) = delete; // C++17 + +#include + +struct S {int i;}; + +int main(int, char**) +{ + cuda::std::as_const(S{}); + + return 0; +} diff --git a/.upstream-tests/test/std/utilities/utility/as_const/as_const.pass.cpp b/.upstream-tests/test/std/utilities/utility/as_const/as_const.pass.cpp new file mode 100644 index 0000000000..75e67f9ab7 --- /dev/null +++ b/.upstream-tests/test/std/utilities/utility/as_const/as_const.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11 + +// template constexpr add_const& as_const(T& t) noexcept; // C++17 +// template add_const& as_const(const T&&) = delete; // C++17 + +#include +#include + +#include "test_macros.h" + +struct S {int i;}; +__host__ __device__ bool operator==(const S& x, const S& y) { return x.i == y.i; } +__host__ __device__ bool operator==(const volatile S& x, const volatile S& y) { return x.i == y.i; } + +template +__host__ __device__ void test(T& t) +{ + static_assert(cuda::std::is_const::type>::value, ""); + static_assert(cuda::std::is_const(t))>::type>::value, ""); + static_assert(cuda::std::is_const(t))>::type>::value, ""); + static_assert(cuda::std::is_const(t))>::type>::value, ""); + static_assert(cuda::std::is_const(t))>::type>::value, ""); + + assert(cuda::std::as_const(t) == t); + assert(cuda::std::as_const< T>(t) == t); + assert(cuda::std::as_const(t) == t); + assert(cuda::std::as_const(t) == t); + assert(cuda::std::as_const(t) == t); +} + +int main(int, char**) +{ + int i = 3; + double d = 4.0; + S s{2}; + test(i); + test(d); + test(s); + + return 0; +} diff --git a/include/cuda/std/detail/libcxx/include/CMakeLists.txt b/include/cuda/std/detail/libcxx/include/CMakeLists.txt index 54df66f4fd..1e575e1f03 100644 --- a/include/cuda/std/detail/libcxx/include/CMakeLists.txt +++ b/include/cuda/std/detail/libcxx/include/CMakeLists.txt @@ -178,6 +178,7 @@ set(files __tuple __type_traits/is_constant_evaluated.h __undef_macros + __utility/as_const.h __utility/convert_to_integral.h __utility/declval.h __utility/forward.h diff --git a/include/cuda/std/detail/libcxx/include/__utility/as_const.h b/include/cuda/std/detail/libcxx/include/__utility/as_const.h new file mode 100644 index 0000000000..127b3b25d7 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__utility/as_const.h @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___UTILITY_AS_CONST_H +#define _LIBCUDACXX___UTILITY_AS_CONST_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__type_traits/add_const.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 +template +_LIBCUDACXX_NODISCARD_EXT _LIBCUDACXX_INLINE_VISIBILITY constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; } + +template +void as_const(const _Tp&&) = delete; +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___UTILITY_AS_CONST_H diff --git a/include/cuda/std/detail/libcxx/include/utility b/include/cuda/std/detail/libcxx/include/utility index e8e5cb6ceb..4a9a6a4a1d 100644 --- a/include/cuda/std/detail/libcxx/include/utility +++ b/include/cuda/std/detail/libcxx/include/utility @@ -220,6 +220,7 @@ template #include "__functional/reference_wrapper.h" #include "__functional/unary_function.h" #include "__functional/weak_result_type.h" +#include "__utility/as_const.h" #include "__utility/convert_to_integral.h" #include "__utility/declval.h" #include "__utility/forward.h" @@ -279,11 +280,6 @@ operator>=(const _Tp& __x, const _Tp& __y) // swap is defined in -#if _LIBCUDACXX_STD_VER > 14 -template constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; } -template void as_const(const _Tp&&) = delete; -#endif - #endif //__cuda_std__ struct _LIBCUDACXX_TEMPLATE_VIS piecewise_construct_t { explicit piecewise_construct_t() = default; }; From 41d52dbe7ffd657f2ddc51a5d19d1ac17a48cac2 Mon Sep 17 00:00:00 2001 From: youyu3 Date: Thu, 9 Feb 2023 08:50:37 +0100 Subject: [PATCH 2/7] Implement `std::mdspan` --- .../views/mdspan/foo_customizations.hpp | 228 ++++++ .../access.pass.cpp | 27 + .../copy.pass.cpp | 30 + .../offset.pass.cpp | 27 + .../mdspan.extents.cmp/compare.pass.cpp | 58 ++ .../mdspan/mdspan.extents.cons/array.pass.cpp | 67 ++ .../convertible_to_size_t.pass.cpp | 45 ++ .../mdspan/mdspan.extents.cons/copy.pass.cpp | 60 ++ .../mdspan.extents.cons/default.pass.cpp | 44 ++ .../mdspan.extents.cons/param_pack.pass.cpp | 89 +++ .../mdspan/mdspan.extents.cons/span.pass.cpp | 68 ++ .../mdspan/mdspan.extents.obs/extent.pass.cpp | 67 ++ .../mdspan/mdspan.extents.obs/rank.pass.cpp | 61 ++ .../mdspan.extents.obs/static_extent.pass.cpp | 66 ++ .../extents_element.fail.cpp | 43 ++ .../index_type.fail.cpp | 43 ++ .../mdspan.extents.util/extents_util.hpp | 51 ++ .../mdspan.layout.left.cons/copy.pass.cpp | 48 ++ .../layout_right_init.pass.cpp | 53 ++ .../layout_stride_init.pass.cpp | 48 ++ .../list_init.pass.cpp | 73 ++ .../mdspan.layout.left.obs/compare.fail.cpp | 33 + .../mdspan.layout.left.obs/compare.pass.cpp | 58 ++ .../mdspan.layout.left.obs/extents.pass.cpp | 48 ++ .../is_exhaustive.pass.cpp | 38 + .../is_strided.pass.cpp | 28 + .../mdspan.layout.left.obs/is_unique.pass.cpp | 38 + .../mdspan.layout.left.obs/paren_op.pass.cpp | 72 ++ .../required_span_size.pass.cpp | 44 ++ .../mdspan.layout.left.obs/stride.pass.cpp | 53 ++ .../mdspan.layout.right.cons/copy.pass.cpp | 48 ++ .../layout_left_init.pass.cpp | 53 ++ .../layout_stride_init.pass.cpp | 48 ++ .../list_init.pass.cpp | 70 ++ .../mdspan.layout.right.obs/compare.fail.cpp | 33 + .../mdspan.layout.right.obs/compare.pass.cpp | 58 ++ .../mdspan.layout.right.obs/extents.pass.cpp | 48 ++ .../is_exhaustive.pass.cpp | 38 + .../is_strided.pass.cpp | 28 + .../is_unique.pass.cpp | 38 + .../mdspan.layout.right.obs/paren_op.pass.cpp | 72 ++ .../required_span_size.pass.cpp | 44 ++ .../mdspan.layout.right.obs/stride.pass.cpp | 53 ++ .../list_init.pass.cpp | 67 ++ .../mdspan.layout.stride.obs/compare.fail.cpp | 36 + .../mdspan.layout.stride.obs/compare.pass.cpp | 84 +++ .../mdspan.layout.stride.obs/extents.pass.cpp | 32 + .../is_exhaustive.pass.cpp | 76 ++ .../is_strided.pass.cpp | 28 + .../is_unique.pass.cpp | 40 ++ .../paren_op.pass.cpp | 84 +++ .../required_span_size.pass.cpp | 63 ++ .../mdspan.layout.stride.obs/stride.pass.cpp | 66 ++ .../mdspan.layout.stride.obs/strides.pass.cpp | 53 ++ .../mdspan/mdspan.layout.util/layout_util.hpp | 169 +++++ .../array_init_extents.pass.cpp | 105 +++ .../mdspan/mdspan.mdspan.cons/copy.pass.cpp | 73 ++ .../mdspan.mdspan.cons/ctad_c_array.pass.cpp | 50 ++ .../ctad_const_c_array.pass.cpp | 40 ++ .../mdspan.mdspan.cons/ctad_copy.pass.cpp | 35 + .../mdspan.mdspan.cons/ctad_extents.pass.cpp | 76 ++ .../ctad_extents_pack.pass.cpp | 37 + .../mdspan.mdspan.cons/ctad_layouts.pass.cpp | 58 ++ .../mdspan.mdspan.cons/ctad_mapping.pass.cpp | 49 ++ .../mdspan.mdspan.cons/ctad_pointer.pass.cpp | 56 ++ .../custom_accessor.pass.cpp | 40 ++ .../mdspan.mdspan.cons/custom_layout.pass.cpp | 36 + .../mdspan.mdspan.cons/data_c_array.pass.cpp | 40 ++ .../mdspan.mdspan.cons/default.pass.cpp | 38 + .../mdspan.mdspan.cons/extents.pass.cpp | 81 +++ .../mdspan.mdspan.cons/extents_pack.pass.cpp | 112 +++ .../list_init_layout_left.pass.cpp | 39 + .../list_init_layout_right.pass.cpp | 39 + .../list_init_layout_stride.pass.cpp | 40 ++ .../mdspan.mdspan.cons/mapping.pass.cpp | 77 ++ .../span_init_extents.pass.cpp | 96 +++ .../mdspan.mdspan.members/accessor.pass.cpp | 32 + .../brackets_op.pass.cpp | 162 +++++ .../data_handle.pass.cpp | 69 ++ .../mdspan.mdspan.members/empty.pass.cpp | 50 ++ .../mdspan.mdspan.members/extent.pass.cpp | 67 ++ .../mdspan.mdspan.members/extents.pass.cpp | 29 + .../is_exhaustive.pass.cpp | 50 ++ .../mdspan.mdspan.members/is_strided.pass.cpp | 49 ++ .../mdspan.mdspan.members/is_unique.pass.cpp | 45 ++ .../mdspan.mdspan.members/mapping.pass.cpp | 45 ++ .../mdspan.mdspan.members/rank.pass.cpp | 53 ++ .../mdspan.mdspan.members/size.pass.cpp | 48 ++ .../mdspan.mdspan.members/stride.pass.cpp | 60 ++ .../mdspan.mdspan.members/swap.pass.cpp | 88 +++ .../mdspan/mdspan.mdspan.util/mdspan_util.hpp | 16 + .../dim_reduction.pass.cpp | 74 ++ .../pair_init.pass.cpp | 33 + .../return_type.pass.cpp | 141 ++++ .../tuple_init.pass.cpp | 33 + .../containers/views/mdspan/my_accessor.hpp | 37 + .../std/containers/views/mdspan/my_int.hpp | 45 ++ include/cuda/std/detail/__config | 4 + .../std/detail/libcxx/include/CMakeLists.txt | 18 + .../libcxx/include/__mdspan/compressed_pair.h | 225 ++++++ .../detail/libcxx/include/__mdspan/config.h | 296 ++++++++ .../include/__mdspan/default_accessor.h | 90 +++ .../libcxx/include/__mdspan/dynamic_extent.h | 75 ++ .../detail/libcxx/include/__mdspan/extents.h | 548 ++++++++++++++ .../libcxx/include/__mdspan/full_extent_t.h | 57 ++ .../libcxx/include/__mdspan/layout_left.h | 255 +++++++ .../libcxx/include/__mdspan/layout_right.h | 256 +++++++ .../libcxx/include/__mdspan/layout_stride.h | 537 ++++++++++++++ .../detail/libcxx/include/__mdspan/macros.h | 653 +++++++++++++++++ .../include/__mdspan/maybe_static_value.h | 155 ++++ .../detail/libcxx/include/__mdspan/mdspan.h | 439 ++++++++++++ .../include/__mdspan/no_unique_address.h | 127 ++++ .../__mdspan/standard_layout_static_array.h | 671 ++++++++++++++++++ .../libcxx/include/__mdspan/static_array.h | 288 ++++++++ .../libcxx/include/__mdspan/submdspan.h | 588 +++++++++++++++ .../libcxx/include/__mdspan/type_list.h | 121 ++++ include/cuda/std/detail/libcxx/include/mdspan | 79 +++ .../cuda/std/detail/libcxx/include/numeric | 18 +- include/cuda/std/mdspan | 32 + 119 files changed, 11109 insertions(+), 3 deletions(-) create mode 100644 .upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/access.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/copy.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/offset.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cmp/compare.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/array.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/convertible_to_size_t.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/copy.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/default.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/param_pack.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/span.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/extent.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/rank.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/static_extent.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.overview/extents_element.fail.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.overview/index_type.fail.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.extents.util/extents_util.hpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/copy.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_right_init.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_stride_init.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/list_init.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.fail.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/extents.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_exhaustive.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_strided.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_unique.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/paren_op.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/required_span_size.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/stride.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/copy.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_left_init.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_stride_init.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/list_init.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.fail.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/extents.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_exhaustive.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_strided.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_unique.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/paren_op.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/required_span_size.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/stride.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.cons/list_init.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.fail.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/extents.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_exhaustive.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_strided.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_unique.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/paren_op.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/required_span_size.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/stride.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/strides.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.layout.util/layout_util.hpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/array_init_extents.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/copy.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_c_array.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_const_c_array.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_copy.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents_pack.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_layouts.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_mapping.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_pointer.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_accessor.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_layout.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/data_c_array.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/default.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents_pack.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_left.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_right.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_stride.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/mapping.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/span_init_extents.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/accessor.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/brackets_op.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/data_handle.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/empty.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/extent.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/extents.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_exhaustive.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_strided.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_unique.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/mapping.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/rank.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/size.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/stride.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/swap.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.util/mdspan_util.hpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/dim_reduction.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/pair_init.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/return_type.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/tuple_init.pass.cpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/my_accessor.hpp create mode 100644 .upstream-tests/test/std/containers/views/mdspan/my_int.hpp create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/config.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/extents.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/macros.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/static_array.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h create mode 100644 include/cuda/std/detail/libcxx/include/__mdspan/type_list.h create mode 100644 include/cuda/std/detail/libcxx/include/mdspan create mode 100644 include/cuda/std/mdspan diff --git a/.upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp b/.upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp new file mode 100644 index 0000000000..626fa3e378 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp @@ -0,0 +1,228 @@ +#ifndef _FOO_CUSTOMIZATIONS_HPP +#define _FOO_CUSTOMIZATIONS_HPP + +// Taken from the reference implementation repo + +namespace Foo { + template + struct foo_ptr { + T* data; + __MDSPAN_HOST_DEVICE + constexpr foo_ptr(T* ptr):data(ptr) {} + }; + + template + struct foo_accessor { + using offset_policy = foo_accessor; + using element_type = T; + using reference = T&; + using data_handle_type = foo_ptr; + + __MDSPAN_INLINE_FUNCTION + constexpr foo_accessor(int* ptr = nullptr) noexcept { flag = ptr; } + + template + __MDSPAN_INLINE_FUNCTION + constexpr foo_accessor(cuda::std::default_accessor) noexcept { flag = nullptr; } + + template + __MDSPAN_INLINE_FUNCTION + constexpr foo_accessor(foo_accessor other) noexcept { flag = other.flag; } + + + constexpr reference access(data_handle_type p, size_t i) const noexcept { + return p.data[i]; + } + + constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept { + return data_handle_type(p.data+i); + } + int* flag; + + friend constexpr void swap(foo_accessor& x, foo_accessor& y) { + x.flag[0] = 99; + y.flag[0] = 77; + cuda::std::swap(x.flag, y.flag); + } + }; + +struct layout_foo { + template + class mapping; +}; + +template +class layout_foo::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_foo; + private: + + static_assert(cuda::std::detail::__is_extents_v, + "layout_foo::mapping must be instantiated with a specialization of cuda::std::extents."); + static_assert(extents_type::rank() < 3, "layout_foo only supports 0D, 1D and 2D"); + + template + friend class mapping; + + public: + + //-------------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping(mapping const&) noexcept = default; + + __MDSPAN_HOST_DEVICE + constexpr mapping(extents_type const& __exts) noexcept + :__extents(__exts) + { } + + __MDSPAN_TEMPLATE_REQUIRES( + class OtherExtents, + /* requires */ ( + __MDSPAN_TRAIT(cuda::std::is_constructible, extents_type, OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!cuda::std::is_convertible::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + mapping(mapping 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 */ ( + __MDSPAN_TRAIT(cuda::std::is_constructible, extents_type, OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!cuda::std::is_convertible::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + mapping(cuda::std::layout_right::mapping const& other) noexcept // NOLINT(google-explicit-constructor) + :__extents(other.extents()) + {} + + __MDSPAN_TEMPLATE_REQUIRES( + class OtherExtents, + /* requires */ ( + __MDSPAN_TRAIT(cuda::std::is_constructible, extents_type, OtherExtents) && + (extents_type::rank() <= 1) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!cuda::std::is_convertible::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + mapping(cuda::std::layout_left::mapping const& other) noexcept // NOLINT(google-explicit-constructor) + :__extents(other.extents()) + {} + + __MDSPAN_TEMPLATE_REQUIRES( + class OtherExtents, + /* requires */ ( + __MDSPAN_TRAIT(cuda::std::is_constructible, extents_type, OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((extents_type::rank() > 0)) + __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + mapping(cuda::std::layout_stride::mapping const& other) // NOLINT(google-explicit-constructor) + :__extents(other.extents()) + { + /* + * TODO: check precondition + * other.required_span_size() is a representable value of type index_type + */ + #ifndef __CUDA_ARCH__ + size_t stride = 1; + for(rank_type r=__extents.rank(); r>0; r--) { + assert(stride == other.stride(r-1)); + //if(stride != other.stride(r-1)) + // throw std::runtime_error("Assigning layout_stride to layout_foo with invalid strides."); + stride *= __extents.extent(r-1); + } + #endif + } + + __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_INLINE_FUNCTION + constexpr index_type operator() () const noexcept { return index_type(0); } + + template + __MDSPAN_INLINE_FUNCTION + constexpr index_type operator()(Indx0 idx0) const noexcept { + return static_cast(idx0); + } + + template + __MDSPAN_INLINE_FUNCTION + constexpr index_type operator()(Indx0 idx0, Indx1 idx1) const noexcept { + return static_cast(idx0 * __extents.extent(0) + idx1); + } + + __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_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 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 const& rhs) noexcept { + return lhs.extents() != rhs.extents(); + } +#endif + + // Not really public, but currently needed to implement fully constexpr useable submdspan: + template + constexpr index_type __get_stride(cuda::std::extents, cuda::std::integer_sequence) const { + return __MDSPAN_FOLD_TIMES_RIGHT((Idx>N? __extents.template __extent():1),1); + } + template + constexpr index_type __stride() const noexcept { + return __get_stride(__extents, std::make_index_sequence()); + } + +private: + __MDSPAN_NO_UNIQUE_ADDRESS extents_type __extents{}; + +}; + +} +#endif + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/access.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/access.pass.cpp new file mode 100644 index 0000000000..4909f42c98 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/access.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +int main(int, char**) +{ + { + using element_t = int; + cuda::std::array d{42,43}; + cuda::std::default_accessor a; + + assert( a.access( d.data(), 0 ) == 42 ); + assert( a.access( d.data(), 1 ) == 43 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/copy.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/copy.pass.cpp new file mode 100644 index 0000000000..94eef2dad4 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/copy.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +int main(int, char**) +{ + { + using element_t = int; + cuda::std::array d{42,43}; + cuda::std::default_accessor a0; + cuda::std::default_accessor a(a0); + + assert( a.access( d.data(), 0 ) == 42 ); + assert( a.access( d.data(), 1 ) == 43 ); + assert( a.offset( d.data(), 0 ) == d.data() ); + assert( a.offset( d.data(), 1 ) == d.data() + 1 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/offset.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/offset.pass.cpp new file mode 100644 index 0000000000..f2262efd40 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.accessor.default.members/offset.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +int main(int, char**) +{ + { + using element_t = int; + cuda::std::array d{42,43}; + cuda::std::default_accessor a; + + assert( a.offset( d.data(), 0 ) == d.data() ); + assert( a.offset( d.data(), 1 ) == d.data() + 1 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cmp/compare.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cmp/compare.pass.cpp new file mode 100644 index 0000000000..28048eb81a --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cmp/compare.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + using index_t = size_t; + + cuda::std::extents< index_t, 10 > e0; + cuda::std::extents< index_t, 10 > e1; + + assert( e0 == e1 ); + } + + { + using index_t = size_t; + + cuda::std::extents< index_t, 10 > e0; + cuda::std::extents< index_t, dyn > e1{ 10 }; + + assert( e0 == e1 ); + } + + { + using index_t = size_t; + + cuda::std::extents< index_t, 10 > e0; + cuda::std::extents< index_t, 10, 10 > e1; + + assert( e0 != e1 ); + } + + { + using index0_t = size_t; + using index1_t = uint8_t; + + cuda::std::extents< index0_t, 10 > e0; + cuda::std::extents< index1_t, 10 > e1; + + assert( e0 == e1 ); + } + + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/array.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/array.pass.cpp new file mode 100644 index 0000000000..fcfefbc757 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/array.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" +#include "../my_int.hpp" + +// TYPED_TEST(TestExtents, array_ctor) +template +__host__ __device__ void test_array_con() +{ + using TestFixture = TestExtents; + TestFixture t; + + auto e = typename TestFixture::extents_type(t.dyn_sizes); + assert(e == t.exts); +} + +template< class T, class IndexType, size_t N, class = void > +struct is_array_cons_avail : cuda::std::false_type {}; + +template< class T, class IndexType, size_t N > +struct is_array_cons_avail< T + , IndexType + , N + , cuda::std::enable_if_t< cuda::std::is_same< decltype( T{ cuda::std::declval>() } ) + , T + >::value + > + > : cuda::std::true_type {}; + +template< class T, class IndexType, size_t N > +constexpr bool is_array_cons_avail_v = is_array_cons_avail< T, IndexType, N >::value; + +int main(int, char**) +{ + test_array_con< cuda::std::tuple_element_t< 0, extents_test_types > >(); + test_array_con< cuda::std::tuple_element_t< 1, extents_test_types > >(); + test_array_con< cuda::std::tuple_element_t< 2, extents_test_types > >(); + test_array_con< cuda::std::tuple_element_t< 3, extents_test_types > >(); + test_array_con< cuda::std::tuple_element_t< 4, extents_test_types > >(); + test_array_con< cuda::std::tuple_element_t< 5, extents_test_types > >(); + + static_assert( is_array_cons_avail_v< cuda::std::dextents< int,2>, int , 2 > == true , "" ); + + static_assert( is_array_cons_avail_v< cuda::std::dextents< int,2>, my_int, 2 > == true , "" ); + + // Constraint: rank consistency + static_assert( is_array_cons_avail_v< cuda::std::dextents< int,1>, int , 2 > == false, "" ); + + // Constraint: convertibility + static_assert( is_array_cons_avail_v< cuda::std::dextents, my_int_non_convertible , 1 > == false, "" ); + + // Constraint: nonthrow-constructibility + static_assert( is_array_cons_avail_v< cuda::std::dextents< int,1>, my_int_non_nothrow_constructible, 1 > == false, "" ); + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/convertible_to_size_t.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/convertible_to_size_t.pass.cpp new file mode 100644 index 0000000000..547883ef98 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/convertible_to_size_t.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include + +__host__ __device__ void check( cuda::std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +int main(int, char**) +{ + // TEST(TestExtentsCtorStdArrayConvertibleToSizeT, test_extents_ctor_std_array_convertible_to_size_t) + { + cuda::std::array i{2, 2}; + cuda::std::dextents e{i}; + + check( e ); + } + + // TEST(TestExtentsCtorStdArrayConvertibleToSizeT, test_extents_ctor_std_span_convertible_to_size_t) + { + cuda::std::array i{2, 2}; + cuda::std::span s(i.data(),2); + cuda::std::dextents e{s}; + + check( e ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/copy.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/copy.pass.cpp new file mode 100644 index 0000000000..9f36c6d3a0 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/copy.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +// TYPED_TEST(TestExtents, copy_ctor) +template +__host__ __device__ void test_copy_con() +{ + using TestFixture = TestExtents; + TestFixture t; + + typename TestFixture::extents_type e { t.exts }; + assert(e == t.exts); +} + +template< class T1, class T2, class = void > +struct is_copy_cons_avail : cuda::std::false_type {}; + +template< class T1, class T2 > +struct is_copy_cons_avail< T1 + , T2 + , cuda::std::enable_if_t< cuda::std::is_same< decltype( T1{ cuda::std::declval() } ) + , T1 + >::value + > + > : cuda::std::true_type {}; + +template< class T1, class T2 > +constexpr bool is_copy_cons_avail_v = is_copy_cons_avail< T1, T2 >::value; + +int main(int, char**) +{ + test_copy_con< cuda::std::tuple_element_t< 0, extents_test_types > >(); + test_copy_con< cuda::std::tuple_element_t< 1, extents_test_types > >(); + test_copy_con< cuda::std::tuple_element_t< 2, extents_test_types > >(); + test_copy_con< cuda::std::tuple_element_t< 3, extents_test_types > >(); + test_copy_con< cuda::std::tuple_element_t< 4, extents_test_types > >(); + test_copy_con< cuda::std::tuple_element_t< 5, extents_test_types > >(); + + static_assert( is_copy_cons_avail_v< cuda::std::extents, cuda::std::extents > == true , "" ); + + // Constraint: rank consistency + static_assert( is_copy_cons_avail_v< cuda::std::extents, cuda::std::extents > == false, "" ); + + // Constraint: extents consistency + static_assert( is_copy_cons_avail_v< cuda::std::extents, cuda::std::extents > == false, "" ); + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/default.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/default.pass.cpp new file mode 100644 index 0000000000..5680b0dd90 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/default.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +// TYPED_TEST(TestExtents, default_ctor) +template +__host__ __device__ +void test_default_con() +{ + using TestFixture = TestExtents; + + auto e = typename TestFixture::extents_type(); + auto e2 = typename TestFixture::extents_type{}; + assert( e == e2 ); + + for (size_t r = 0; r < e.rank(); ++r) + { + bool is_dynamic = (e.static_extent(r) == cuda::std::dynamic_extent); + assert( e.extent(r) == ( is_dynamic ? 0 : e.static_extent(r) ) ); + } +} + +int main(int, char**) +{ + test_default_con< cuda::std::tuple_element_t< 0, extents_test_types > >(); + test_default_con< cuda::std::tuple_element_t< 1, extents_test_types > >(); + test_default_con< cuda::std::tuple_element_t< 2, extents_test_types > >(); + test_default_con< cuda::std::tuple_element_t< 3, extents_test_types > >(); + test_default_con< cuda::std::tuple_element_t< 4, extents_test_types > >(); + test_default_con< cuda::std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/param_pack.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/param_pack.pass.cpp new file mode 100644 index 0000000000..91496b01cc --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/param_pack.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../my_int.hpp" + +__host__ __device__ void check( cuda::std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +template< class, class T, class... IndexTypes > +struct is_param_pack_cons_avail : cuda::std::false_type {}; + +template< class T, class... IndexTypes > +struct is_param_pack_cons_avail< cuda::std::enable_if_t< cuda::std::is_same< decltype( T{ cuda::std::declval()... } ) + , T + >::value + > + , T + , IndexTypes... + > : cuda::std::true_type {}; + +template< class T, class... IndexTypes > +constexpr bool is_param_pack_cons_avail_v = is_param_pack_cons_avail< void, T, IndexTypes... >::value; + +int main(int, char**) +{ + { + cuda::std::dextents e{2, 2}; + + check( e ); + } + + { + cuda::std::dextents e(2, 2); + + check( e ); + } + +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + { + cuda::std::extents e{2, 2}; + + check( e ); + } + + { + cuda::std::extents e(2, 2); + + check( e ); + } +#endif + + { + cuda::std::dextents e{2, 2}; + + check( e ); + } + + static_assert( is_param_pack_cons_avail_v< cuda::std::dextents, int , int > == true , "" ); + + static_assert( is_param_pack_cons_avail_v< cuda::std::dextents, my_int, my_int > == true , "" ); + + // Constraint: rank consistency + static_assert( is_param_pack_cons_avail_v< cuda::std::dextents, int , int > == false, "" ); + + // Constraint: convertibility + static_assert( is_param_pack_cons_avail_v< cuda::std::dextents, my_int_non_convertible > == false, "" ); + + // Constraint: nonthrow-constructibility + static_assert( is_param_pack_cons_avail_v< cuda::std::dextents, my_int_non_nothrow_constructible > == false, "" ); + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/span.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/span.pass.cpp new file mode 100644 index 0000000000..ecc264f1e0 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.cons/span.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" +#include "../my_int.hpp" + +// TYPED_TEST(TestExtents, array_ctor) +template +__host__ __device__ void test_span_con() +{ + using TestFixture = TestExtents; + TestFixture t; + + auto s = cuda::std::span( t.dyn_sizes ); + auto e = typename TestFixture::extents_type(s); + assert(e == t.exts); +} + +template< class T, class IndexType, size_t N, class = void > +struct is_span_cons_avail : cuda::std::false_type {}; + +template< class T, class IndexType, size_t N > +struct is_span_cons_avail< T + , IndexType + , N + , cuda::std::enable_if_t< cuda::std::is_same< decltype( T{ cuda::std::declval>() } ) + , T + >::value + > + > : cuda::std::true_type {}; + +template< class T, class IndexType, size_t N > +constexpr bool is_span_cons_avail_v = is_span_cons_avail< T, IndexType, N >::value; + +int main(int, char**) +{ + test_span_con< cuda::std::tuple_element_t< 0, extents_test_types > >(); + test_span_con< cuda::std::tuple_element_t< 1, extents_test_types > >(); + test_span_con< cuda::std::tuple_element_t< 2, extents_test_types > >(); + test_span_con< cuda::std::tuple_element_t< 3, extents_test_types > >(); + test_span_con< cuda::std::tuple_element_t< 4, extents_test_types > >(); + test_span_con< cuda::std::tuple_element_t< 5, extents_test_types > >(); + + static_assert( is_span_cons_avail_v< cuda::std::dextents, int , 2 > == true , "" ); + + static_assert( is_span_cons_avail_v< cuda::std::dextents, my_int, 2 > == true , "" ); + + // Constraint: rank consistency + static_assert( is_span_cons_avail_v< cuda::std::dextents, int , 2 > == false, "" ); + + // Constraint: convertibility + static_assert( is_span_cons_avail_v< cuda::std::dextents, my_int_non_convertible , 1 > == false, "" ); + + // Constraint: nonthrow-constructibility + static_assert( is_span_cons_avail_v< cuda::std::dextents, my_int_non_nothrow_constructible, 1 > == false, "" ); + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/extent.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/extent.pass.cpp new file mode 100644 index 0000000000..4b184bf857 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/extent.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +template struct TestExtentsExtent; +template +struct TestExtentsExtent< TEST_TYPE > +: public TestExtents< TEST_TYPE > +{ + using base = TestExtents; + using extents_type = typename TestExtents::extents_type; + + __host__ __device__ + void test_extent() + { + size_t result[extents_type::rank()]; + + extents_type _exts(DynamicSizes...); + for(size_t r=0; r<_exts.rank(); r++ ) + { + result[r] = _exts.extent(r); + } + + int dyn_count = 0; + for(size_t r=0; r +__host__ __device__ +void test_extent() +{ + TestExtentsExtent test; + + test.test_extent(); +} + +int main(int, char**) +{ + test_extent< cuda::std::tuple_element_t< 0, extents_test_types > >(); + test_extent< cuda::std::tuple_element_t< 1, extents_test_types > >(); + test_extent< cuda::std::tuple_element_t< 2, extents_test_types > >(); + test_extent< cuda::std::tuple_element_t< 3, extents_test_types > >(); + test_extent< cuda::std::tuple_element_t< 4, extents_test_types > >(); + test_extent< cuda::std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/rank.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/rank.pass.cpp new file mode 100644 index 0000000000..92957f380e --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/rank.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +template struct TestExtentsRank; +template +struct TestExtentsRank< TEST_TYPE > +: public TestExtents< TEST_TYPE > +{ + using base = TestExtents; + using extents_type = typename TestExtents::extents_type; + + __host__ __device__ void test_rank() + { + size_t result[2]; + + extents_type _exts(DynamicSizes...); + // Silencing an unused warning in nvc++ the condition will never be true + size_t dyn_val = _exts.rank()>0?static_cast(_exts.extent(0)):1; + result[0] = dyn_val > 1e9 ? dyn_val : _exts.rank(); + result[1] = _exts.rank_dynamic(); + + assert( result[0] == base::static_sizes.size() ); + assert( result[1] == base:: dyn_sizes.size() ); + + // Makes sure that `rank()` returns a constexpr + cuda::std::array a; + } +}; + +// TYPED_TEST(TestExtents, rank) +template +__host__ __device__ void test_rank() +{ + TestExtentsRank test; + + test.test_rank(); +} + +int main(int, char**) +{ + test_rank< cuda::std::tuple_element_t< 0, extents_test_types > >(); + test_rank< cuda::std::tuple_element_t< 1, extents_test_types > >(); + test_rank< cuda::std::tuple_element_t< 2, extents_test_types > >(); + test_rank< cuda::std::tuple_element_t< 3, extents_test_types > >(); + test_rank< cuda::std::tuple_element_t< 4, extents_test_types > >(); + test_rank< cuda::std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/static_extent.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/static_extent.pass.cpp new file mode 100644 index 0000000000..38cf5cb72a --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.obs/static_extent.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +template struct TestExtentsStaticExtent; +template +struct TestExtentsStaticExtent< TEST_TYPE > +: public TestExtents< TEST_TYPE > +{ + using base = TestExtents; + using extents_type = typename TestExtents::extents_type; + + __host__ __device__ + void test_static_extent() + { + size_t result[extents_type::rank()]; + + extents_type _exts(DynamicSizes...); + for(size_t r=0; r<_exts.rank(); r++) + { + // Silencing an unused warning in nvc++ the condition will never be true + size_t dyn_val = static_cast(_exts.extent(r)); + result[r] = dyn_val > 1e9 ? dyn_val : _exts.static_extent(r); + } + + for(size_t r=0; r +__host__ __device__ +void test_static_extent() +{ + TestExtentsStaticExtent test; + + test.test_static_extent(); +} + +int main(int, char**) +{ + test_static_extent< cuda::std::tuple_element_t< 0, extents_test_types > >(); + test_static_extent< cuda::std::tuple_element_t< 1, extents_test_types > >(); + test_static_extent< cuda::std::tuple_element_t< 2, extents_test_types > >(); + test_static_extent< cuda::std::tuple_element_t< 3, extents_test_types > >(); + test_static_extent< cuda::std::tuple_element_t< 4, extents_test_types > >(); + test_static_extent< cuda::std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.overview/extents_element.fail.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.overview/extents_element.fail.cpp new file mode 100644 index 0000000000..83e364b474 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.overview/extents_element.fail.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +__host__ __device__ void check( cuda::std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +struct dummy {}; + +int main(int, char**) +{ + { + cuda::std::dextents e{2 , 2}; + + check( e ); + } + + // Mandate: each element of Extents is either equal to dynamic_extent, or is representable as a value of type IndexType + { + + cuda::std::dextents e{dummy{}, 2}; + + check( e ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.overview/index_type.fail.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.overview/index_type.fail.cpp new file mode 100644 index 0000000000..438ba5f1ed --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.overview/index_type.fail.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +__host__ __device__ void check( cuda::std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +struct dummy {}; + +int main(int, char**) +{ + { + cuda::std::dextents e{2, 2}; + + check( e ); + } + + // Mandate: IndexType is a signed or unsigned integer type + { + + cuda::std::dextents e{2, 2}; + + check( e ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.util/extents_util.hpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.util/extents_util.hpp new file mode 100644 index 0000000000..ee05e3d019 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.extents.util/extents_util.hpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#include +#include + +#define TEST_TYPE \ + cuda::std::tuple < \ + cuda::std::extents, \ + cuda::std::integer_sequence \ + > + + +template struct TestExtents; +template +struct TestExtents< + cuda::std::tuple< + cuda::std::extents, + cuda::std::integer_sequence + > +> +{ + using extents_type = cuda::std::extents; + // Double Braces here to make it work with GCC 5 + // Otherwise: "error: array must be initialized with a brace-enclosed initializer" + const cuda::std::array static_sizes {{ Extents... }}; + const cuda::std::array dyn_sizes {{ DynamicSizes... }}; + extents_type exts { DynamicSizes... }; +}; + +template +using _sizes = cuda::std::integer_sequence; +template +using _exts = cuda::std::extents; + +constexpr auto dyn = cuda::std::dynamic_extent; + +using extents_test_types = cuda::std::tuple< + cuda::std::tuple< _exts< 10 >, _sizes< > > + , cuda::std::tuple< _exts, _sizes<10 > > + , cuda::std::tuple< _exts< 10, 3>, _sizes< > > + , cuda::std::tuple< _exts, _sizes<10 > > + , cuda::std::tuple< _exts< 10, dyn>, _sizes< 3 > > + , cuda::std::tuple< _exts, _sizes<10, 3> > +>; diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/copy.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/copy.pass.cpp new file mode 100644 index 0000000000..e0d1bef2b9 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/copy.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + + cuda::std::layout_left::mapping> m0{cuda::std::dextents{16,32}}; + cuda::std::layout_left::mapping> m {m0}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = cuda::std::layout_left::mapping>; + using mapping1_t = cuda::std::layout_left::mapping>; + using mappingd_t = cuda::std::layout_left::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_right_init.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_right_init.pass.cpp new file mode 100644 index 0000000000..ab0c674ec2 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_right_init.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + cuda::std::layout_right::mapping> m_right{cuda::std::dextents{16}}; + cuda::std::layout_left ::mapping> m( m_right ); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 1 ); + assert( m.extents().rank_dynamic() == 1 ); + assert( m.extents().extent(0) == 16 ); + assert( m.stride(0) == 1 ); + } + + // Constraint: extents_type::rank() <= 1 is true + { + using mapping0_t = cuda::std::layout_right::mapping>; + using mapping1_t = cuda::std::layout_left ::mapping>; + + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = cuda::std::layout_right::mapping>; + using mapping1_t = cuda::std::layout_left ::mapping>; + using mappingd_t = cuda::std::layout_left ::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_stride_init.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_stride_init.pass.cpp new file mode 100644 index 0000000000..7a3884edc0 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_stride_init.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + cuda::std::array a{1,16}; + cuda::std::layout_stride::mapping> m_stride{cuda::std::dextents{16, 32}, a}; + cuda::std::layout_left ::mapping> m( m_stride ); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = cuda::std::layout_stride::mapping>; + using mapping1_t = cuda::std::layout_left ::mapping>; + using mappingd_t = cuda::std::layout_left::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/list_init.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/list_init.pass.cpp new file mode 100644 index 0000000000..5fc9415306 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.cons/list_init.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +template +using test_left_type = cuda::std::tuple< + typename cuda::std::layout_left::template mapping, + cuda::std::integer_sequence +>; + +__host__ __device__ void typed_test_default_ctor_left() +{ + typed_test_default_ctor< test_left_type< cuda::std::extents > >(); + typed_test_default_ctor< test_left_type< cuda::std::extents, 10 > >(); + typed_test_default_ctor< test_left_type< cuda::std::extents, 5 > >(); + typed_test_default_ctor< test_left_type< cuda::std::extents, 10 > >(); + typed_test_default_ctor< test_left_type< cuda::std::extents > >(); +} + +__host__ __device__ void typed_test_compatible_left() +{ + typed_test_compatible< test_left_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_default_ctor_left(); + + typed_test_compatible_left(); + + // TEST(TestLayoutLeftListInitialization, test_layout_left_extent_initialization) + { + typedef int data_t ; + typedef size_t index_t; + + cuda::std::layout_left::mapping> m{cuda::std::dextents{16, 32}}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.fail.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.fail.cpp new file mode 100644 index 0000000000..73939274c0 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.fail.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = cuda::std::extents< index_t, 64, 128 >; + using ext3d_t = cuda::std::extents< index_t, 64, 128, 2 >; + + // Constraint: rank consistency + // This constraint is implemented in a different way in the reference implementation. There will be an overload function + // match but it will return false if the ranks are not consistent + { + constexpr ext2d_t e0; + constexpr ext3d_t e1; + constexpr cuda::std::layout_left::mapping m0{ e0 }; + constexpr cuda::std::layout_left::mapping m1{ e1 }; + + static_assert( m0 == m1, "" ); // expected-error + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.pass.cpp new file mode 100644 index 0000000000..df476245c1 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +__host__ __device__ void typed_test_compare_left() +{ + typed_test_compare< test_left_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_compare_left(); + + using index_t = size_t; + using ext1d_t = cuda::std::extents; + using ext2d_t = cuda::std::extents; + + { + ext2d_t e{64, 128}; + cuda::std::layout_left::mapping m0{ e }; + cuda::std::layout_left::mapping m { m0 }; + + assert( m == m0 ); + } + + { + ext2d_t e0{64, 128}; + ext2d_t e1{16, 32}; + cuda::std::layout_left::mapping m0{ e0 }; + cuda::std::layout_left::mapping m1{ e1 }; + + assert( m0 != m1 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/extents.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/extents.pass.cpp new file mode 100644 index 0000000000..404542e34e --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/extents.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext1d_t = cuda::std::extents; + using ext2d_t = cuda::std::extents; + + { + ext2d_t e{16, 32}; + cuda::std::layout_left::mapping m{e}; + + assert( m.extents() == e ); + } + + { + ext1d_t e{16}; + cuda::std::layout_right::mapping m_right{e}; + cuda::std::layout_left ::mapping m{m_right}; + + assert( m.extents() == e ); + } + + { + ext2d_t e{16, 32}; + cuda::std::array a{1,16}; + cuda::std::layout_stride::mapping m_stride{e, a}; + cuda::std::layout_left ::mapping m{m_stride}; + + assert( m.extents() == e ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_exhaustive.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..d6b924f924 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_exhaustive.pass.cpp @@ -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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + cuda::std::layout_left::mapping> m; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + + { + cuda::std::extents e{16, 32}; + cuda::std::layout_left::mapping> m{ e }; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_strided.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_strided.pass.cpp new file mode 100644 index 0000000000..a7b168cb16 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_strided.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + cuda::std::extents e{64, 128}; + cuda::std::layout_left::mapping> m{ e }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_unique.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_unique.pass.cpp new file mode 100644 index 0000000000..657147fae5 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_unique.pass.cpp @@ -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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + cuda::std::layout_left::mapping> m; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + + { + cuda::std::extents e{16, 32}; + cuda::std::layout_left::mapping> m{ e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/paren_op.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/paren_op.pass.cpp new file mode 100644 index 0000000000..4a684c28a6 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/paren_op.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../my_int.hpp" +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + cuda::std::extents e; + cuda::std::layout_left::mapping> m{e}; + + assert( m(5) == 5 ); + } + + { + cuda::std::extents e{16, 32}; + cuda::std::layout_left::mapping> m{e}; + + assert( m(2,1) == 2*1 + 1*16 ); + } + + { + cuda::std::extents e{16, 32, 8}; + cuda::std::layout_left::mapping> m{e}; + + assert( m(2,1,3) == 2*1 + 1*16 + 3*16*32 ); + } + + // Indices are of a type implicitly convertible to index_type + { + cuda::std::extents e{16, 32}; + cuda::std::layout_left::mapping> m{e}; + + assert( m(my_int(2),my_int(1)) == 2*1 + 1*16 ); + } + + // Constraints + { + cuda::std::extents e; + cuda::std::layout_left::mapping> m{e}; + + unused( m ); + + static_assert( is_paren_op_avail_v< decltype(m), index_t > == true, "" ); + + // rank consistency + static_assert( is_paren_op_avail_v< decltype(m), index_t, index_t > == false, "" ); + + // convertibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_convertible > == false, "" ); + + // nothrow-constructibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_nothrow_constructible > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/required_span_size.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/required_span_size.pass.cpp new file mode 100644 index 0000000000..34be1ee8e9 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/required_span_size.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = cuda::std::extents; + + { + cuda::std::extents e; + cuda::std::layout_left::mapping> m{e}; + + assert( m.required_span_size() == 16 ); + } + + { + ext2d_t e{16, 32}; + cuda::std::layout_left::mapping m{e}; + + assert( m.required_span_size() == 16*32 ); + } + + { + ext2d_t e{16, 0}; + cuda::std::layout_left::mapping m{e}; + + assert( m.required_span_size() == 0 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/stride.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/stride.pass.cpp new file mode 100644 index 0000000000..c6257af943 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.left.obs/stride.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext0d_t = cuda::std::extents; + using ext2d_t = cuda::std::extents; + + { + ext2d_t e{64, 128}; + cuda::std::layout_left::mapping m{ e }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 64 ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == true , "" ); + } + + { + ext2d_t e{1, 128}; + cuda::std::layout_left::mapping m{ e }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 1 ); + } + + // constraint: extents_­type?::?rank() > 0 + { + ext0d_t e{}; + cuda::std::layout_left::mapping m{ e }; + + unused( m ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/copy.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/copy.pass.cpp new file mode 100644 index 0000000000..53c686e865 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/copy.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + + cuda::std::layout_right::mapping> m0{cuda::std::dextents{16,32}}; + cuda::std::layout_right::mapping> m {m0}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = cuda::std::layout_right::mapping>; + using mapping1_t = cuda::std::layout_right::mapping>; + using mappingd_t = cuda::std::layout_right::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_left_init.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_left_init.pass.cpp new file mode 100644 index 0000000000..c9b5cab27b --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_left_init.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + cuda::std::layout_left ::mapping> m_right{cuda::std::dextents{16}}; + cuda::std::layout_right::mapping> m( m_right); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 1 ); + assert( m.extents().rank_dynamic() == 1 ); + assert( m.extents().extent(0) == 16 ); + assert( m.stride(0) == 1 ); + } + + // Constraint: extents_type::rank() <= 1 is true + { + using mapping0_t = cuda::std::layout_left::mapping>; + using mapping1_t = cuda::std::layout_right::mapping>; + + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = cuda::std::layout_left::mapping>; + using mapping1_t = cuda::std::layout_right::mapping>; + using mappingd_t = cuda::std::layout_right::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_stride_init.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_stride_init.pass.cpp new file mode 100644 index 0000000000..1f762332c7 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_stride_init.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + cuda::std::array a{32,1}; + cuda::std::layout_stride::mapping> m_stride{cuda::std::dextents{16, 32}, a}; + cuda::std::layout_right ::mapping> m( m_stride ); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = cuda::std::layout_stride::mapping>; + using mapping1_t = cuda::std::layout_right ::mapping>; + using mappingd_t = cuda::std::layout_right ::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/list_init.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/list_init.pass.cpp new file mode 100644 index 0000000000..1396d3c81b --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.cons/list_init.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +template +using test_right_type = cuda::std::tuple< + typename cuda::std::layout_right::template mapping, + cuda::std::integer_sequence +>; + +__host__ __device__ void typed_test_default_ctor_right() +{ + typed_test_default_ctor< test_right_type< cuda::std::extents > >(); + typed_test_default_ctor< test_right_type< cuda::std::extents, 10 > >(); + typed_test_default_ctor< test_right_type< cuda::std::extents, 5 > >(); + typed_test_default_ctor< test_right_type< cuda::std::extents, 10 > >(); + typed_test_default_ctor< test_right_type< cuda::std::extents > >(); +} + +__host__ __device__ void typed_test_compatible_right() +{ + typed_test_compatible< test_right_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_default_ctor_right(); + + typed_test_compatible_right(); + + // TEST(TestLayoutRightListInitialization, test_layout_right_extent_initialization) + { + cuda::std::layout_right::mapping> m{cuda::std::dextents{16, 32}}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.fail.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.fail.cpp new file mode 100644 index 0000000000..e2f337f2a4 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.fail.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = cuda::std::extents< index_t, 64, 128 >; + using ext3d_t = cuda::std::extents< index_t, 64, 128, 2 >; + + // Constraint: rank consistency + // This constraint is implemented in a different way in the reference implementation. There will be an overload function + // match but it will return false if the ranks are not consistent + { + constexpr ext2d_t e0; + constexpr ext3d_t e1; + constexpr cuda::std::layout_right::mapping m0{ e0 }; + constexpr cuda::std::layout_right::mapping m1{ e1 }; + + static_assert( m0 == m1, "" ); // expected-error + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.pass.cpp new file mode 100644 index 0000000000..59108739a0 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +__host__ __device__ void typed_test_compare_right() +{ + typed_test_compare< test_right_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_compare_right(); + + using index_t = size_t; + using ext1d_t = cuda::std::extents; + using ext2d_t = cuda::std::extents; + + { + ext2d_t e{64, 128}; + cuda::std::layout_right::mapping m0{ e }; + cuda::std::layout_right::mapping m { m0 }; + + assert( m == m0 ); + } + + { + ext2d_t e0{64, 128}; + ext2d_t e1{16, 32}; + cuda::std::layout_right::mapping m0{ e0 }; + cuda::std::layout_right::mapping m1{ e1 }; + + assert( m0 != m1 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/extents.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/extents.pass.cpp new file mode 100644 index 0000000000..483b9521ca --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/extents.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext1d_t = cuda::std::extents; + using ext2d_t = cuda::std::extents; + + { + ext2d_t e{16, 32}; + cuda::std::layout_right::mapping m{e}; + + assert( m.extents() == e ); + } + + { + ext1d_t e{16}; + cuda::std::layout_left ::mapping m_left{e}; + cuda::std::layout_right::mapping m( m_left ); + + assert( m.extents() == e ); + } + + { + ext2d_t e{16, 32}; + cuda::std::array a{32,1}; + cuda::std::layout_stride::mapping m_stride{e, a}; + cuda::std::layout_right ::mapping m( m_stride ); + + assert( m.extents() == e ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_exhaustive.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..2fc4bc2f2e --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_exhaustive.pass.cpp @@ -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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + cuda::std::layout_right::mapping> m; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + + { + cuda::std::extents e{16, 32}; + cuda::std::layout_right::mapping> m{ e }; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_strided.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_strided.pass.cpp new file mode 100644 index 0000000000..831b2008cf --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_strided.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + cuda::std::extents e{64, 128}; + cuda::std::layout_right::mapping> m{ e }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_unique.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_unique.pass.cpp new file mode 100644 index 0000000000..026d9c3f50 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_unique.pass.cpp @@ -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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + cuda::std::layout_right::mapping> m; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + + { + cuda::std::extents e{16, 32}; + cuda::std::layout_right::mapping> m{ e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/paren_op.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/paren_op.pass.cpp new file mode 100644 index 0000000000..6283281293 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/paren_op.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../my_int.hpp" +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + cuda::std::extents e; + cuda::std::layout_right::mapping> m{e}; + + assert( m(5) == 5 ); + } + + { + cuda::std::extents e{16, 32}; + cuda::std::layout_right::mapping> m{e}; + + assert( m(2,1) == 2*32 + 1*1 ); + } + + { + cuda::std::extents e{16, 32, 8}; + cuda::std::layout_right::mapping> m{e}; + + assert( m(2,1,3) == 2*32*8 + 1*8 + 3*1 ); + } + + // Indices are of a type implicitly convertible to index_type + { + cuda::std::extents e{16, 32}; + cuda::std::layout_right::mapping> m{e}; + + assert( m(my_int(2),my_int(1)) == 2*32 + 1*1 ); + } + + // Constraints + { + cuda::std::extents e; + cuda::std::layout_right::mapping> m{e}; + + unused( m ); + + static_assert( is_paren_op_avail_v< decltype(m), index_t > == true, "" ); + + // rank consistency + static_assert( is_paren_op_avail_v< decltype(m), index_t, index_t > == false, "" ); + + // convertibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_convertible > == false, "" ); + + // nothrow-constructibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_nothrow_constructible > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/required_span_size.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/required_span_size.pass.cpp new file mode 100644 index 0000000000..a24b5dc7a7 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/required_span_size.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = cuda::std::extents; + + { + cuda::std::extents e; + cuda::std::layout_right::mapping> m{e}; + + assert( m.required_span_size() == 16 ); + } + + { + ext2d_t e{16, 32}; + cuda::std::layout_right::mapping m{e}; + + assert( m.required_span_size() == 16*32 ); + } + + { + ext2d_t e{16, 0}; + cuda::std::layout_right::mapping m{e}; + + assert( m.required_span_size() == 0 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/stride.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/stride.pass.cpp new file mode 100644 index 0000000000..df611e6df0 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.right.obs/stride.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext0d_t = cuda::std::extents; + using ext2d_t = cuda::std::extents; + + { + ext2d_t e{64, 128}; + cuda::std::layout_right::mapping m{ e }; + + assert( m.stride(0) == 128 ); + assert( m.stride(1) == 1 ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == true , "" ); + } + + { + ext2d_t e{64, 1}; + cuda::std::layout_right::mapping m{ e }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 1 ); + } + + // constraint: extents_type::rank() > 0 + { + ext0d_t e{}; + cuda::std::layout_right::mapping m{ e }; + + unused( m ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.cons/list_init.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.cons/list_init.pass.cpp new file mode 100644 index 0000000000..7696561590 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.cons/list_init.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include + +#define CHECK_MAPPING(m) \ + assert( m.is_exhaustive() == false); \ + assert( m.extents().rank() == 2 ); \ + assert( m.extents().rank_dynamic() == 2 ); \ + assert( m.extents().extent(0) == 16 ); \ + assert( m.extents().extent(1) == 32 ); \ + assert( m.stride(0) == 1 ); \ + assert( m.stride(1) == 128 ); \ + assert( m.strides()[0] == 1 ); \ + assert( m.strides()[1] == 128 ) + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + // From a span + { + typedef int data_t ; + typedef size_t index_t; + + using my_ext = typename cuda::std::extents; + + cuda::std::array a{1, 128}; + cuda::std::span s(a.data(), 2); + cuda::std::layout_stride::mapping> m{cuda::std::dextents{16, 32}, s}; + + CHECK_MAPPING(m); + } + + // TEST(TestLayoutStrideListInitialization, test_list_initialization) + { + typedef int data_t ; + typedef size_t index_t; + + cuda::std::layout_stride::mapping> m{cuda::std::dextents{16, 32}, cuda::std::array{1, 128}}; + + CHECK_MAPPING(m); + } + + // From another mapping + { + typedef int data_t ; + typedef size_t index_t; + + cuda::std::layout_stride::mapping> m0{cuda::std::dextents{16, 32}, cuda::std::array{1, 128}}; + cuda::std::layout_stride::mapping> m{m0}; + + CHECK_MAPPING(m); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.fail.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.fail.cpp new file mode 100644 index 0000000000..e5e6916ae3 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.fail.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = cuda::std::extents< index_t, 64, 128 >; + using ext3d_t = cuda::std::extents< index_t, 64, 128, 2 >; + + // Constraint: rank consistency + { + constexpr ext2d_t e0; + constexpr ext3d_t e1; + constexpr cuda::std::array a0{1,64}; + constexpr cuda::std::array a1{1,64,64*128}; + constexpr cuda::std::layout_stride::mapping m0{ e0, a0 }; + constexpr cuda::std::layout_stride::mapping m1{ e1, a1 }; + + static_assert( m0 == m1, "" ); // expected-error + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.pass.cpp new file mode 100644 index 0000000000..b1c964c984 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext1d_t = cuda::std::extents; + using ext2d_t = cuda::std::extents; + + { + cuda::std::extents e; + cuda::std::array a{1,16}; + cuda::std::layout_stride::mapping m0{e, a}; + cuda::std::layout_stride::mapping m {m0}; + + assert( m0 == m ); + } + + { + using index2_t = int32_t; + + cuda::std::extents e; + cuda::std::array a{1,16}; + cuda::std::extents e2; + cuda::std::array a2{1,16}; + cuda::std::layout_stride::mapping m1{e , a }; + cuda::std::layout_stride::mapping m2{e2, a2}; + + assert( m1 == m2 ); + } + + { + cuda::std::extents e; + cuda::std::array a0{1,16}; + cuda::std::array a1{1,32}; + cuda::std::layout_stride::mapping m0{e, a0}; + cuda::std::layout_stride::mapping m1{e, a1}; + + assert( m0 != m1 ); + } + + { + cuda::std::extents e; + cuda::std::array a{1,16}; + cuda::std::layout_stride::mapping m{e, a}; + cuda::std::layout_left ::mapping m_left{e}; + + assert( m == m_left ); + } + + { + cuda::std::extents e; + cuda::std::array a{32,1}; + cuda::std::layout_stride::mapping m{e, a}; + cuda::std::layout_right ::mapping m_right{e}; + + assert( m == m_right ); + } + + { + cuda::std::extents e0; + cuda::std::extents e1; + cuda::std::array a{1,16}; + cuda::std::layout_stride::mapping m0{e0, a}; + cuda::std::layout_stride::mapping m1{e1, a}; + + assert( m0 != m1 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/extents.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/extents.pass.cpp new file mode 100644 index 0000000000..6f2791aac2 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/extents.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = cuda::std::extents; + + { + ext2d_t e{16, 32}; + cuda::std::array a{1,16}; + cuda::std::layout_stride::mapping m{e, a}; + + assert( m.extents() == e ); + } + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_exhaustive.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..c0671cff3a --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_exhaustive.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + cuda::std::extents e; + cuda::std::array a{1}; + cuda::std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + cuda::std::extents e; + cuda::std::array a{2}; + cuda::std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + { + cuda::std::extents e; + cuda::std::array a{1,16}; + cuda::std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + cuda::std::extents e{16, 32}; + cuda::std::array a{1,128}; + cuda::std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + { + cuda::std::extents e{16, 32, 4}; + cuda::std::array a{1,16*4,16}; + cuda::std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + cuda::std::extents e{16, 32, 4}; + cuda::std::array a{1,16*4+1,16}; + cuda::std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_strided.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_strided.pass.cpp new file mode 100644 index 0000000000..c11e189a3d --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_strided.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +int main(int, char**) +{ + { + using dexts = cuda::std::dextents; + cuda::std::array a{1, 128}; + + cuda::std::layout_stride::mapping m{dexts{16, 32}, a}; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_unique.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_unique.pass.cpp new file mode 100644 index 0000000000..90bdc2b648 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_unique.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + cuda::std::extents e; + cuda::std::array a{1}; + cuda::std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + { + cuda::std::extents e{16, 32}; + cuda::std::array a{1,16}; + cuda::std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/paren_op.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/paren_op.pass.cpp new file mode 100644 index 0000000000..5e9b64072d --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/paren_op.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../my_int.hpp" +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + cuda::std::extents e; + cuda::std::array a{1}; + cuda::std::layout_stride::mapping> m{e, a}; + + assert( m(8) == 8 ); + } + + { + cuda::std::extents e{16, 32}; + cuda::std::array a{1,16}; + cuda::std::layout_stride::mapping> m{e, a}; + + assert( m(8,16) == 8*1 + 16*16 ); + } + + { + cuda::std::extents e{32}; + cuda::std::array a{1,24}; + cuda::std::layout_stride::mapping> m{e, a}; + + assert( m(8,16) == 8*1 + 16*24 ); + } + + { + cuda::std::extents e{32}; + cuda::std::array a{48,1}; + cuda::std::layout_stride::mapping> m{e, a}; + + assert( m(8,16) == 8*48 + 16*1 ); + } + + // Indices are of a type implicitly convertible to index_type + { + cuda::std::extents e{16, 32}; + cuda::std::array a{1,16}; + cuda::std::layout_stride::mapping> m{e, a}; + + assert( m(my_int(8),my_int(16)) == 8*1 + 16*16 ); + } + + // Constraints + { + cuda::std::extents e; + cuda::std::array a{1}; + cuda::std::layout_stride::mapping> m{e, a}; + + static_assert( is_paren_op_avail_v< decltype(m), index_t > == true, "" ); + + // rank consistency + static_assert( is_paren_op_avail_v< decltype(m), index_t, index_t > == false, "" ); + + // convertibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_convertible > == false, "" ); + + // nothrow-constructibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_nothrow_constructible > == false, "" ); + } + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/required_span_size.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/required_span_size.pass.cpp new file mode 100644 index 0000000000..77e0fab380 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/required_span_size.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = cuda::std::extents; + + { + cuda::std::extents e; + cuda::std::array a{1}; + cuda::std::layout_stride::mapping> m{e, a}; + + assert( m.required_span_size() == 16 ); + } + + { + ext2d_t e{16, 32}; + cuda::std::array a{1,16}; + cuda::std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 16*32 ); + } + + { + ext2d_t e{16, 0}; + cuda::std::array a{1,1}; + cuda::std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 0 ); + } + + { + cuda::std::extents e{32}; + cuda::std::array a{1,24}; + cuda::std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 32*24 - (24-16) ); + } + + { + cuda::std::extents e{32}; + cuda::std::array a{48,1}; + cuda::std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 16*48 - (48-32) ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/stride.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/stride.pass.cpp new file mode 100644 index 0000000000..ac637cc73d --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/stride.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext0d_t = cuda::std::extents; + using ext2d_t = cuda::std::extents; + + auto e = cuda::std::dextents{16, 32}; + auto s_arr = cuda::std::array {1, 128}; + + // From a span + { + cuda::std::span s(s_arr.data(), 2); + cuda::std::layout_stride::mapping m{e, s}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == true , "" ); + } + + // From an array + { + cuda::std::layout_stride::mapping m{e, s_arr}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + } + + // From another mapping + { + cuda::std::layout_stride::mapping m0{e, s_arr}; + cuda::std::layout_stride::mapping m{m0}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + } + + // constraint: extents_­type?::?rank() > 0 + { + ext0d_t e{}; + cuda::std::layout_stride::mapping m{ e, cuda::std::array{} }; + + unused( m ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/strides.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/strides.pass.cpp new file mode 100644 index 0000000000..ba3323b2f1 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.stride.obs/strides.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = cuda::std::extents; + + auto e = cuda::std::dextents{16, 32}; + auto s_arr = cuda::std::array {1, 128}; + + // From a span + { + cuda::std::span s(s_arr.data(), 2); + cuda::std::layout_stride::mapping m{e, s}; + + assert( m.strides()[0] == 1 ); + assert( m.strides()[1] == 128 ); + } + + // From an array + { + cuda::std::layout_stride::mapping m{e, s_arr}; + + assert( m.strides()[0] == 1 ); + assert( m.strides()[1] == 128 ); + } + + // From another mapping + { + cuda::std::layout_stride::mapping m0{e, s_arr}; + cuda::std::layout_stride::mapping m{m0}; + + assert( m.strides()[0] == 1 ); + assert( m.strides()[1] == 128 ); + } + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.util/layout_util.hpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.util/layout_util.hpp new file mode 100644 index 0000000000..dbe0637722 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.layout.util/layout_util.hpp @@ -0,0 +1,169 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#include + +template struct TestLayoutCtors; +template +struct TestLayoutCtors +>> +{ + using mapping_type = Mapping; + using extents_type = typename mapping_type::extents_type; + Mapping map = { extents_type{ DynamicSizes... } }; +}; + +template __host__ __device__ void typed_test_default_ctor() +// TYPED_TEST( TestLayoutCtors, default_ctor ) +{ + // Default constructor ensures extents() == Extents() is true. + using TestFixture = TestLayoutCtors; + auto m = typename TestFixture::mapping_type(); + assert( m .extents() == typename TestFixture::extents_type() ); + auto m2 = typename TestFixture::mapping_type{}; + assert( m2.extents() == typename TestFixture::extents_type{} ); + assert( m == m2 ); +} + +template struct TestLayoutCompatCtors; +template +struct TestLayoutCompatCtors, + Mapping2, + cuda::std::integer_sequence +>> { + using mapping_type1 = Mapping; + using mapping_type2 = Mapping2; + using extents_type1 = cuda::std::remove_reference_t().extents())>; + using extents_type2 = cuda::std::remove_reference_t().extents())>; + Mapping map1 = { extents_type1{ DynamicSizes... } }; + Mapping2 map2 = { extents_type2{ DynamicSizes2... } }; +}; + +template __host__ __device__ void typed_test_compatible() +//TYPED_TEST(TestLayout{Left|Right}CompatCtors, compatible_construct_{1|2}) { +//TYPED_TEST(TestLayout{Left|Right}CompatCtors, compatible_assign_{1|2}) { +{ + using TestFixture = TestLayoutCompatCtors; + + // Construct + { + TestFixture t; + + auto m1 = typename TestFixture::mapping_type1(t.map2); + assert( m1.extents() == t.map2.extents() ); + + auto m2 = typename TestFixture::mapping_type2(t.map1); + assert( m2.extents() == t.map1.extents() ); + } + + // Assign + { + TestFixture t; + +#if __MDSPAN_HAS_CXX_17 + if constexpr ( cuda::std::is_convertible::value ) + { + t.map1 = t.map2; + } + else + { + t.map1 = typename TestFixture::mapping_type1( t.map2 ); + } +#else + t.map1 = typename TestFixture::mapping_type1( t.map2 ); +#endif + + assert( t.map1.extents() == t.map2.extents() ); + } +} + +template __host__ __device__ void typed_test_compare() +{ + using TestFixture = TestLayoutCompatCtors; + + { + TestFixture t; + + auto m1 = typename TestFixture::mapping_type1(t.map2); + assert( m1 == t.map2 ); + + auto m2 = typename TestFixture::mapping_type2(t.map1); + assert( m2 == t.map1 ); + } +} + +template +using _sizes = cuda::std::integer_sequence; +template +using _exts = cuda::std::extents; + +template +using test_left_type_pair = cuda::std::tuple< + typename cuda::std::layout_left::template mapping, S1, + typename cuda::std::layout_left::template mapping, S2 +>; + +template +using test_right_type_pair = cuda::std::tuple< + typename cuda::std::layout_right::template mapping, S1, + typename cuda::std::layout_right::template mapping, S2 +>; + +template< class T1, class T2, class = void > +struct is_cons_avail : cuda::std::false_type {}; + +template< class T1, class T2 > +struct is_cons_avail< T1 + , T2 + , cuda::std::enable_if_t< cuda::std::is_same< decltype( T1{ cuda::std::declval() } ) + , T1 + >::value + > + > : cuda::std::true_type {}; + +template< class T1, class T2 > +constexpr bool is_cons_avail_v = is_cons_avail< T1, T2 >::value; + +template< class, class T, class... Indicies > +struct is_paren_op_avail : cuda::std::false_type {}; + +template< class T, class... Indicies > +struct is_paren_op_avail< cuda::std::enable_if_t< cuda::std::is_same< decltype(cuda::std::declval()(cuda::std::declval()...)) + , typename T::index_type + >::value + > + , T + , Indicies... + > : cuda::std::true_type {}; + +template< class T, class... Indicies > +constexpr bool is_paren_op_avail_v = is_paren_op_avail< void, T, Indicies... >::value; + +template< class T, class RankType, class = void > +struct is_stride_avail : cuda::std::false_type {}; + +template< class T, class RankType > +struct is_stride_avail< T + , RankType + , cuda::std::enable_if_t< cuda::std::is_same< decltype( cuda::std::declval().stride( cuda::std::declval() ) ) + , typename T::index_type + >::value + > + > : cuda::std::true_type {}; + +template< class T, class RankType > +constexpr bool is_stride_avail_v = is_stride_avail< T, RankType >::value; + +// Workaround for variables that are only used in static_assert's +template< typename T > +__host__ __device__ constexpr bool unused( T && ) { return true; } diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/array_init_extents.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/array_init_extents.pass.cpp new file mode 100644 index 0000000000..180b1acba7 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/array_init_extents.pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +template< class T, class DataHandleT, class SizeType, size_t N, class = void > +struct is_array_cons_avail : cuda::std::false_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +struct is_array_cons_avail< T + , DataHandleT + , SizeType + , N + , cuda::std::enable_if_t< cuda::std::is_same< decltype( T{ cuda::std::declval() + , cuda::std::declval>() + } + ) + , T + >::value + > + > : cuda::std::true_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +constexpr bool is_array_cons_avail_v = is_array_cons_avail< T, DataHandleT, SizeType, N >::value; + +int main(int, char**) +{ + // extents from cuda::std::array + { + cuda::std::array d{42}; + cuda::std::mdspan> m{ d.data(), cuda::std::array{64, 128} }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // data from cptr, extents from cuda::std::array + { + using mdspan_t = cuda::std::mdspan>; + + cuda::std::array d{42}; + const int* const ptr = d.data(); + + static_assert( is_array_cons_avail_v< mdspan_t, decltype(ptr), int, 2 > == true, "" ); + + mdspan_t m{ptr, cuda::std::array{64, 128}}; + + static_assert( cuda::std::is_same::value, "" ); + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_convertible; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: (is_nothrow_constructible && ...) is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_nothrow_constructible; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: N == rank() || N == rank_dynamic() is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, dyn, dyn > >; + using other_index_t = int; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, int, 1 > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, 16 >, cuda::std::layout_stride >; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, 16 >, cuda::std::layout_right, Foo::my_accessor >; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/copy.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/copy.pass.cpp new file mode 100644 index 0000000000..b5de7deb0d --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/copy.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +template< class T1, class T0, class = void > +struct is_copy_cons_avail : cuda::std::false_type {}; + +template< class T1, class T0 > +struct is_copy_cons_avail< T1 + , T0 + , cuda::std::enable_if_t< cuda::std::is_same< decltype( T1{ cuda::std::declval() } ), T1 >::value > + > : cuda::std::true_type {}; + +template< class T1, class T0 > +constexpr bool is_copy_cons_avail_v = is_copy_cons_avail< T1, T0 >::value; + +int main(int, char**) +{ + // copy constructor + { + using ext_t = cuda::std::extents; + using mdspan_t = cuda::std::mdspan; + + static_assert( is_copy_cons_avail_v< mdspan_t, mdspan_t > == true, "" ); + + cuda::std::array d{42}; + mdspan_t m0{ d.data(), ext_t{64, 128} }; + mdspan_t m { m0 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // copy constructor with conversion + { + cuda::std::array d{42}; + cuda::std::mdspan> m0{ d.data(), cuda::std::extents{} }; + cuda::std::mdspan> m { m0 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: is_constructible_v&> is true + { + using mdspan1_t = cuda::std::mdspan, cuda::std::layout_left >; + using mdspan0_t = cuda::std::mdspan, cuda::std::layout_right>; + + static_assert( is_copy_cons_avail_v< mdspan1_t, mdspan0_t > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan1_t = cuda::std::mdspan, cuda::std::layout_right, Foo::my_accessor>; + using mdspan0_t = cuda::std::mdspan, cuda::std::layout_right>; + + static_assert( is_copy_cons_avail_v< mdspan1_t, mdspan0_t > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_c_array.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_c_array.pass.cpp new file mode 100644 index 0000000000..8e612b1c11 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_c_array.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, ctad_carray) + { + int data[5] = {1,2,3,4,5}; + cuda::std::mdspan m(data); + + static_assert(cuda::std::is_same::value == true, ""); + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == &data[0]); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 0 ); + assert(m.static_extent(0) == 5 ); + assert(m.extent(0) == 5 ); + assert(__MDSPAN_OP(m, 2) == 3 ); + + cuda::std::mdspan m2(data, 3); + + static_assert(cuda::std::is_same::value == true, ""); + static_assert(m2.is_exhaustive() == true, ""); + + assert(m2.data_handle() == &data[0]); + assert(m2.rank() == 1 ); + assert(m2.rank_dynamic() == 1 ); + assert(m2.extent(0) == 3 ); + assert(__MDSPAN_OP(m2, 2) == 3 ); + } +#endif + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_const_c_array.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_const_c_array.pass.cpp new file mode 100644 index 0000000000..0f19f086f6 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_const_c_array.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, ctad_const_carray) + { + const int data[5] = {1,2,3,4,5}; + cuda::std::mdspan m(data); + + static_assert(cuda::std::is_same::value == true, ""); + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == &data[0]); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 0 ); + assert(m.static_extent(0) == 5 ); + assert(m.extent(0) == 5 ); + assert(__MDSPAN_OP(m, 2) == 3 ); + } +#endif + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_copy.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_copy.pass.cpp new file mode 100644 index 0000000000..04c7cbaa10 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_copy.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + constexpr auto dyn = cuda::std::dynamic_extent; + + // copy constructor + { + cuda::std::array d{42}; + cuda::std::mdspan> m0{ d.data(), cuda::std::extents{64, 128} }; + cuda::std::mdspan m{ m0 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } +#endif + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents.pass.cpp new file mode 100644 index 0000000000..69a22b54f9 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +#define CHECK_MDSPAN(m,d) \ + static_assert(m.is_exhaustive(), ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.rank() == 2 ); \ + assert(m.rank_dynamic() == 2 ); \ + assert(m.extent(0) == 64 ); \ + assert(m.extent(1) == 128 ) + + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, extents_object) + { + cuda::std::array d{42}; + cuda::std::mdspan m{d.data(), cuda::std::extents{64, 128}}; + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, extents_object_move) + { + cuda::std::array d{42}; + cuda::std::mdspan m{d.data(), std::move(cuda::std::extents{64, 128})}; + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, extents_std_array) + { + cuda::std::array d{42}; + cuda::std::mdspan m{d.data(), cuda::std::array{64, 128}}; + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, cptr_extents_std_array) + { + cuda::std::array d{42}; + const int* const ptr= d.data(); + cuda::std::mdspan m{ptr, cuda::std::array{64, 128}}; + + static_assert(cuda::std::is_same::value, ""); + + CHECK_MDSPAN(m,d); + } + + // extents from std::span + { + cuda::std::array d{42}; + cuda::std::array sarr{64, 128}; + cuda::std::mdspan m{d.data(), cuda::std::span{sarr}}; + + CHECK_MDSPAN(m,d); + } +#endif + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents_pack.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents_pack.pass.cpp new file mode 100644 index 0000000000..a149a54c44 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents_pack.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, extents_pack) + { + cuda::std::array d{42}; + cuda::std::mdspan m(d.data(), 64, 128); + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 64 ); + assert(m.extent(1) == 128 ); + } +#endif + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_layouts.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_layouts.pass.cpp new file mode 100644 index 0000000000..5b60616c39 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_layouts.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +#define CHECK_MDSPAN(m,d,exhaust,s0,s1) \ + static_assert(m.rank() == 2 , ""); \ + static_assert(m.rank_dynamic() == 2 , ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.extent(0) == 16 ); \ + assert(m.extent(1) == 32 ); \ + assert(m.stride(0) == s0 ); \ + assert(m.stride(1) == s1 ); \ + assert(m.is_exhaustive() == exhaust ) + + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, layout_left) + { + cuda::std::array d{42}; + cuda::std::mdspan m0{d.data(), cuda::std::layout_left::mapping{cuda::std::extents{16, 32}}}; + + CHECK_MDSPAN( m0, d, true, 1, 16 ); + } + + // TEST(TestMdspanCTAD, layout_right) + { + cuda::std::array d{42}; + cuda::std::mdspan m0{d.data(), cuda::std::layout_right::mapping{cuda::std::extents{16, 32}}}; + + CHECK_MDSPAN( m0, d, true, 32, 1 ); + } + + // TEST(TestMdspanCTAD, layout_stride) + { + cuda::std::array d{42}; + cuda::std::mdspan m0{d.data(), cuda::std::layout_stride::mapping{cuda::std::extents{16, 32}, cuda::std::array{1, 128}}}; + + CHECK_MDSPAN( m0, d, false, 1, 128 ); + } +#endif + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_mapping.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_mapping.pass.cpp new file mode 100644 index 0000000000..ab9a89baeb --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_mapping.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + constexpr auto dyn = cuda::std::dynamic_extent; + + // mapping + { + using data_t = int; + using index_t = size_t; + cuda::std::array d{42}; + cuda::std::layout_left::mapping> map{cuda::std::dextents{64, 128}}; + cuda::std::mdspan m{ d.data(), map }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // mapping and accessor + { + using data_t = int; + using index_t = size_t; + cuda::std::array d{42}; + cuda::std::layout_left::mapping> map{cuda::std::dextents{64, 128}}; + cuda::std::default_accessor a; + cuda::std::mdspan m{ d.data(), map, a }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } +#endif + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_pointer.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_pointer.pass.cpp new file mode 100644 index 0000000000..b6e5288e40 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_pointer.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +#define CHECK_MDSPAN(m,d) \ + static_assert(cuda::std::is_same::value, ""); \ + static_assert(m.is_exhaustive(), ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.rank() == 0 ); \ + assert(m.rank_dynamic() == 0 ) + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, ctad_pointer) + { + cuda::std::array d = {1,2,3,4,5}; + int* ptr = d.data(); + cuda::std::mdspan m(ptr); + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, ctad_pointer_tmp) + { + cuda::std::array d = {1,2,3,4,5}; + cuda::std::mdspan m(d.data()); + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, ctad_pointer_move) + { + cuda::std::array d = {1,2,3,4,5}; + int* ptr = d.data(); + cuda::std::mdspan m(std::move(ptr)); + + CHECK_MDSPAN(m,d); + } +#endif + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_accessor.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_accessor.pass.cpp new file mode 100644 index 0000000000..b2d139a771 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_accessor.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../foo_customizations.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + using data_t = int; + using acc_t = Foo::foo_accessor; + using index_t = size_t; + + cuda::std::array d{42}; + cuda::std::layout_left::mapping> map{cuda::std::dextents{64, 128}}; + acc_t a; + cuda::std::mdspan, cuda::std::layout_left, acc_t> m{ d.data(), map, a }; + + static_assert(m.is_exhaustive(), ""); + //assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 64 ); + assert(m.extent(1) == 128 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_layout.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_layout.pass.cpp new file mode 100644 index 0000000000..eaf2c77466 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_layout.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../foo_customizations.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + using map_t = Foo::layout_foo::template mapping>; + + { + using data_t = int; + using lay_t = Foo::layout_foo; + using index_t = size_t; + + cuda::std::array d{42}; + lay_t::mapping> map{cuda::std::dextents{64, 128}}; + cuda::std::mdspan, lay_t> m{ d.data(), map }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/data_c_array.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/data_c_array.pass.cpp new file mode 100644 index 0000000000..6c0f457940 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/data_c_array.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + data_t data[1] = {42}; + cuda::std::mdspan> m(data); + auto val = m(0); + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == data ); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 0 ); + assert(m.extent(0) == 1 ); + assert(m.static_extent(0) == 1 ); + assert(m.stride(0) == 1 ); + assert(val == 42 ); + assert(m.size() == 1 ); + assert(m.empty() == false); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/default.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/default.pass.cpp new file mode 100644 index 0000000000..2aa353f354 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/default.pass.cpp @@ -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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + cuda::std::mdspan> m; + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == nullptr); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 1 ); + assert(m.extent(0) == 0 ); + assert(m.static_extent(0) == dyn ); + assert(m.stride(0) == 1 ); + assert(m.size() == 0 ); + assert(m.empty() == true ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents.pass.cpp new file mode 100644 index 0000000000..e2f8c35323 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +template< class T, class DataHandleType, class ExtentsType, class = void > +struct is_extents_cons_avail : cuda::std::false_type {}; + +template< class T, class DataHandleType, class ExtentsType > +struct is_extents_cons_avail< T + , DataHandleType + , ExtentsType + , cuda::std::enable_if_t< cuda::std::is_same< decltype( T{ cuda::std::declval() + , cuda::std::declval() + } + ) + , T + >::value + > + > : cuda::std::true_type {}; + +template< class T, class DataHandleType, class ExtentsType > +constexpr bool is_extents_cons_avail_v = is_extents_cons_avail< T, DataHandleType, ExtentsType >::value; + +int main(int, char**) +{ + // extents from extents object + { + using ext_t = cuda::std::extents; + cuda::std::array d{42}; + cuda::std::mdspan m{ d.data(), ext_t{64, 128} }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // extents from extents object move + { + using ext_t = cuda::std::extents< int, dyn, dyn >; + using mdspan_t = cuda::std::mdspan< int, ext_t >; + + static_assert( is_extents_cons_avail_v< mdspan_t, int *, ext_t > == true, "" ); + + cuda::std::array d{42}; + mdspan_t m{ d.data(), cuda::std::move(ext_t{64, 128}) }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: is_constructible_v is true + { + using ext_t = cuda::std::extents< int, 16, 16 >; + using mdspan_t = cuda::std::mdspan< int, ext_t, cuda::std::layout_stride >; + + static_assert( is_extents_cons_avail_v< mdspan_t, int *, ext_t > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using ext_t = cuda::std::extents< int, 16, 16 >; + using mdspan_t = cuda::std::mdspan< int, ext_t, cuda::std::layout_right, Foo::my_accessor >; + + static_assert( is_extents_cons_avail_v< mdspan_t, int *, ext_t > == false, "" ); + } + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents_pack.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents_pack.pass.cpp new file mode 100644 index 0000000000..8379871f25 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents_pack.pass.cpp @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +template< class, class T, class DataHandleT, class... SizeTypes > +struct is_param_pack_cons_avail : cuda::std::false_type {}; + +template< class T, class DataHandleT, class... SizeTypes > +struct is_param_pack_cons_avail< cuda::std::enable_if_t< cuda::std::is_same< decltype( T{ cuda::std::declval() + , cuda::std::declval()... + } + ) + , T + >::value + > + , T + , DataHandleT + , SizeTypes... + > : cuda::std::true_type {}; + +template< class T, class DataHandleT, class... SizeTypes > +constexpr bool is_param_pack_cons_avail_v = is_param_pack_cons_avail< void, T, DataHandleT, SizeTypes... >::value; + +int main(int, char**) +{ + { + using index_t = int; + cuda::std::array d{42}; + cuda::std::mdspan> m{ d.data(), 64, 128 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + { + using index_t = int; + cuda::std::array d{42}; + cuda::std::mdspan< int + , cuda::std::extents + , cuda::std::layout_right + , cuda::std::default_accessor + > m{ d.data(), 64, 128 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, dyn, dyn > >; + using other_index_t = my_int; + + cuda::std::array d{42}; + mdspan_t m{ d.data(), other_index_t(64), other_index_t(128) }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + + static_assert( is_param_pack_cons_avail_v< mdspan_t, decltype(d.data()), other_index_t, other_index_t > == true, "" ); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_convertible; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, other_index_t, other_index_t > == false, "" ); + } + + // Constraint: (is_nothrow_constructible && ...) is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_nothrow_constructible; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, other_index_t, other_index_t > == false, "" ); + } + + // Constraint: N == rank() || N == rank_dynamic() is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, dyn, dyn > >; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, int > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, 16 >, cuda::std::layout_stride >; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, int > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, 16 >, cuda::std::layout_right, Foo::my_accessor >; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, int > == false, "" ); + } + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_left.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_left.pass.cpp new file mode 100644 index 0000000000..c59f779018 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_left.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + cuda::std::array d{42}; + cuda::std::mdspan, cuda::std::layout_left> m{d.data(), 16, 32}; + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 16 ); + assert(m.extent(1) == 32 ); + assert(m.stride(0) == 1 ); + assert(m.stride(1) == 16 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_right.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_right.pass.cpp new file mode 100644 index 0000000000..ff740a3bfd --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_right.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + cuda::std::array d{42}; + cuda::std::mdspan, cuda::std::layout_right> m{d.data(), 16, 32}; + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 16 ); + assert(m.extent(1) == 32 ); + assert(m.stride(0) == 32 ); + assert(m.stride(1) == 1 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_stride.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_stride.pass.cpp new file mode 100644 index 0000000000..d2bb0ae9fb --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_stride.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + cuda::std::array d{42}; + + cuda::std::mdspan< int + , cuda::std::extents + , cuda::std::layout_stride + > + m { d.data() + , cuda::std::layout_stride::template mapping>{cuda::std::dextents{16, 32}, cuda::std::array{1, 128}} + }; + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 16 ); + assert(m.extent(1) == 32 ); + assert(m.stride(0) == 1 ); + assert(m.stride(1) == 128 ); + assert(m.is_exhaustive() == false ); + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/mapping.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/mapping.pass.cpp new file mode 100644 index 0000000000..625b309dab --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/mapping.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +template< class T, class DataHandleType, class MappingType, class = void > +struct is_mapping_cons_avail : cuda::std::false_type {}; + +template< class T, class DataHandleType, class MappingType > +struct is_mapping_cons_avail< T + , DataHandleType + , MappingType + , cuda::std::enable_if_t< cuda::std::is_same< decltype( T{ cuda::std::declval() + , cuda::std::declval() + } + ) + , T + >::value + > + > : cuda::std::true_type {}; + +template< class T, class DataHandleType, class MappingType > +constexpr bool is_mapping_cons_avail_v = is_mapping_cons_avail< T, DataHandleType, MappingType >::value; + +int main(int, char**) +{ + using data_t = int; + using index_t = size_t; + using ext_t = cuda::std::extents; + using mapping_t = cuda::std::layout_left::mapping; + + // mapping + { + using mdspan_t = cuda::std::mdspan; + + static_assert( is_mapping_cons_avail_v< mdspan_t, int *, mapping_t > == true, "" ); + + cuda::std::array d{42}; + mapping_t map{cuda::std::dextents{64, 128}}; + mdspan_t m{ d.data(), map }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = cuda::std::mdspan>; + + static_assert( is_mapping_cons_avail_v< mdspan_t, int *, mapping_t > == false, "" ); + } + + // mapping and accessor + { + + cuda::std::array d{42}; + mapping_t map{cuda::std::dextents{64, 128}}; + cuda::std::default_accessor a; + cuda::std::mdspan m{ d.data(), map, a }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/span_init_extents.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/span_init_extents.pass.cpp new file mode 100644 index 0000000000..9615587439 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.cons/span_init_extents.pass.cpp @@ -0,0 +1,96 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = cuda::std::dynamic_extent; + +template< class T, class DataHandleT, class SizeType, size_t N, class = void > +struct is_span_cons_avail : cuda::std::false_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +struct is_span_cons_avail< T + , DataHandleT + , SizeType + , N + , cuda::std::enable_if_t< cuda::std::is_same< decltype( T{ cuda::std::declval() + , cuda::std::declval>() + } + ) + , T + >::value + > + > : cuda::std::true_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +constexpr bool is_span_cons_avail_v = is_span_cons_avail< T, DataHandleT, SizeType, N >::value; + +int main(int, char**) +{ + // extents from cuda::std::span + { + using mdspan_t = cuda::std::mdspan>; + using other_index_t = int; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == true, "" ); + + cuda::std::array d{42}; + cuda::std::array sarr{64, 128}; + + mdspan_t m{d.data(), cuda::std::span{sarr}}; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = cuda::std::mdspan>; + using other_index_t = my_int_non_convertible; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = cuda::std::mdspan>; + using other_index_t = my_int_non_convertible; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: N == rank() || N == rank_dynamic() is true + { + using mdspan_t = cuda::std::mdspan>; + using other_index_t = int; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 1 > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, 16 >, cuda::std::layout_stride >; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = cuda::std::mdspan< int, cuda::std::extents< int, 16 >, cuda::std::layout_right, Foo::my_accessor >; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/accessor.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/accessor.pass.cpp new file mode 100644 index 0000000000..414f40bf7b --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/accessor.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + using data_t = int; + using index_t = size_t; + cuda::std::array d{42}; + cuda::std::layout_left::mapping> map{cuda::std::dextents{64, 128}}; + cuda::std::default_accessor const a; + cuda::std::mdspan, cuda::std::layout_left> m{ d.data(), map, a }; + + assert( m.accessor().access( d.data(), 0 ) == a.access( d.data(), 0 ) ); + assert( m.accessor().offset( d.data(), 0 ) == a.offset( d.data(), 0 ) ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/brackets_op.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/brackets_op.pass.cpp new file mode 100644 index 0000000000..9b31e6de2c --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/brackets_op.pass.cpp @@ -0,0 +1,162 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include +#include "../my_int.hpp" + +// Will be testing `m[0,0]` when it becomes available +// Alternatively, could use macro `__MDSPAN_OP(m,0,0)` which is turned to either `m[0,0]` or `m(0,0)`, +// depending on if `__cpp_multidimensional_subscript` is defined or not + +constexpr auto dyn = cuda::std::dynamic_extent; + +template< class, class T, class... OtherIndexTypes > +struct is_bracket_op_avail : cuda::std::false_type {}; + +template< class T, class... OtherIndexTypes > +struct is_bracket_op_avail< cuda::std::enable_if_t< cuda::std::is_same< decltype( cuda::std::declval()(cuda::std::declval()...) ) + , typename T::accessor_type::reference + >::value + > + , T + , OtherIndexTypes... + > : cuda::std::true_type {}; + +template< class T, class... OtherIndexTypes > +constexpr bool is_bracket_op_avail_v = is_bracket_op_avail< void, T, OtherIndexTypes... >::value; + +template< class T, class OtherIndexType, size_t N, class = void > +struct is_bracket_op_array_avail : cuda::std::false_type {}; + +template< class T, class OtherIndexType, size_t N > +struct is_bracket_op_array_avail< T + , OtherIndexType + , N + , cuda::std::enable_if_t< cuda::std::is_same< decltype( cuda::std::declval()(cuda::std::declval>()) ) + , typename T::accessor_type::reference + >::value + > + > : cuda::std::true_type {}; + +template< class T, class OtherIndexType, size_t N > +constexpr bool is_bracket_op_array_avail_v = is_bracket_op_array_avail< T, OtherIndexType, N >::value; + +template< class T, class OtherIndexType, size_t N, class = void > +struct is_bracket_op_span_avail : cuda::std::false_type {}; + +template< class T, class OtherIndexType, size_t N > +struct is_bracket_op_span_avail< T + , OtherIndexType + , N + , cuda::std::enable_if_t< cuda::std::is_same< decltype( cuda::std::declval()(cuda::std::declval>()) ) + , typename T::accessor_type::reference + >::value + > + > : cuda::std::true_type {}; + +template< class T, class OtherIndexType, size_t N > +constexpr bool is_bracket_op_span_avail_v = is_bracket_op_span_avail< T, OtherIndexType, N >::value; + + +int main(int, char**) +{ + { + using element_t = int; + using index_t = int; + using ext_t = cuda::std::extents; + using mdspan_t = cuda::std::mdspan; + + cuda::std::array d{42,43,44,45}; + mdspan_t m{d.data(), ext_t{2, 2}}; + + static_assert( is_bracket_op_avail_v< decltype(m), int, int > == true, "" ); + + // param pack + assert( m(0,0) == 42 ); + assert( m(0,1) == 43 ); + assert( m(1,0) == 44 ); + assert( m(1,1) == 45 ); + + // array of indices + assert( m(cuda::std::array{0,0}) == 42 ); + assert( m(cuda::std::array{0,1}) == 43 ); + assert( m(cuda::std::array{1,0}) == 44 ); + assert( m(cuda::std::array{1,1}) == 45 ); + + static_assert( is_bracket_op_array_avail_v< decltype(m), int, 2 > == true, "" ); + + // span of indices + assert( m(cuda::std::span{cuda::std::array{0,0}}) == 42 ); + assert( m(cuda::std::span{cuda::std::array{0,1}}) == 43 ); + assert( m(cuda::std::span{cuda::std::array{1,0}}) == 44 ); + assert( m(cuda::std::span{cuda::std::array{1,1}}) == 45 ); + + static_assert( is_bracket_op_span_avail_v< decltype(m), int, 2 > == true, "" ); + } + + // Param pack of indices in a type implicitly convertible to index_type + { + using element_t = int; + using index_t = int; + using ext_t = cuda::std::extents; + using mdspan_t = cuda::std::mdspan; + + cuda::std::array d{42,43,44,45}; + mdspan_t m{d.data(), ext_t{2, 2}}; + + assert( m(my_int(0),my_int(0)) == 42 ); + assert( m(my_int(0),my_int(1)) == 43 ); + assert( m(my_int(1),my_int(0)) == 44 ); + assert( m(my_int(1),my_int(1)) == 45 ); + } + + // Constraint: rank consistency + { + using element_t = int; + using index_t = int; + using mdspan_t = cuda::std::mdspan>; + + static_assert( is_bracket_op_avail_v< mdspan_t, index_t, index_t > == false, "" ); + + static_assert( is_bracket_op_array_avail_v< mdspan_t, index_t, 2 > == false, "" ); + + static_assert( is_bracket_op_span_avail_v < mdspan_t, index_t, 2 > == false, "" ); + } + + // Constraint: convertibility + { + using element_t = int; + using index_t = int; + using mdspan_t = cuda::std::mdspan>; + + static_assert( is_bracket_op_avail_v< mdspan_t, my_int_non_convertible > == false, "" ); + + static_assert( is_bracket_op_array_avail_v< mdspan_t, my_int_non_convertible, 1 > == false, "" ); + + static_assert( is_bracket_op_span_avail_v < mdspan_t, my_int_non_convertible, 1 > == false, "" ); + } + + // Constraint: nonthrow-constructibility + { + using element_t = int; + using index_t = int; + using mdspan_t = cuda::std::mdspan>; + + static_assert( is_bracket_op_avail_v< mdspan_t, my_int_non_nothrow_constructible > == false, "" ); + + static_assert( is_bracket_op_array_avail_v< mdspan_t, my_int_non_nothrow_constructible, 1 > == false, "" ); + + static_assert( is_bracket_op_span_avail_v < mdspan_t, my_int_non_nothrow_constructible, 1 > == false, "" ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/data_handle.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/data_handle.pass.cpp new file mode 100644 index 0000000000..dde9b895a6 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/data_handle.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +int main(int, char**) +{ + // C array + { + const int d[5] = {1,2,3,4,5}; +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + cuda::std::mdspan m(d); +#else + cuda::std::mdspan> m(d); +#endif + + assert( m.data_handle() == d ); + } + + // std array + { + cuda::std::array d = {1,2,3,4,5}; +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + cuda::std::mdspan m(d.data()); +#else + cuda::std::mdspan> m(d.data()); +#endif + + assert( m.data_handle() == d.data() ); + } + + // C pointer + { + cuda::std::array d = {1,2,3,4,5}; + int* ptr = d.data(); +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + cuda::std::mdspan m(ptr); +#else + cuda::std::mdspan> m(ptr); +#endif + + assert( m.data_handle() == ptr ); + } + + // Copy constructor + { + cuda::std::array d = {1,2,3,4,5}; +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + cuda::std::mdspan m0(d.data()); + cuda::std::mdspan m (m0); +#else + cuda::std::mdspan> m0(d.data()); + cuda::std::mdspan> m (m0); +#endif + + assert( m.data_handle() == m0.data_handle() ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/empty.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/empty.pass.cpp new file mode 100644 index 0000000000..f998222f4d --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/empty.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +int main(int, char**) +{ + cuda::std::array storage{1}; + + { + cuda::std::mdspan> m; + + assert( m.empty() == true ); + } + + { + cuda::std::mdspan> m{ storage.data(), 0 }; + + assert( m.empty() == true ); + } + + { + cuda::std::mdspan> m{ storage.data(), 2 }; + + assert( m.empty() == false ); + } + + { + cuda::std::mdspan> m{ storage.data(), 2, 0 }; + + assert( m.empty() == true ); + } + + { + cuda::std::mdspan> m{ storage.data(), 2, 2 }; + + assert( m.empty() == false ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/extent.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/extent.pass.cpp new file mode 100644 index 0000000000..d2a6d3ca81 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/extent.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + typedef int data_t ; + typedef size_t index_t; + + cuda::std::array d{42}; + + { + cuda::std::mdspan> m; + + assert( m.extent(0) == 0 ); + assert( m.extent(1) == 0 ); + } + + { + cuda::std::mdspan> m{d.data()}; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + { + cuda::std::mdspan> m{d.data(), 16, 32}; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + { + cuda::std::array d{42}; + cuda::std::mdspan, cuda::std::layout_left> m{d.data(), 16, 32}; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + { + using dexts = cuda::std::dextents; + + cuda::std::mdspan< int, cuda::std::extents, cuda::std::layout_stride > + m { d.data() + , cuda::std::layout_stride::template mapping{dexts{16, 32}, cuda::std::array{1, 128}} + }; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/extents.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/extents.pass.cpp new file mode 100644 index 0000000000..9fde30ee84 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/extents.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + cuda::std::array d{42}; + cuda::std::extents e{64, 128}; + cuda::std::mdspan> m{ d.data(), e }; + + assert( &m.extents() == &m.mapping().extents() ); + } + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_exhaustive.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..a10d8533f5 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_exhaustive.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + cuda::std::mdspan> m; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + cuda::std::array d{42}; + cuda::std::extents e{64, 128}; + + { + cuda::std::mdspan, cuda::std::layout_left> m{ d.data(), e }; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + using dexts = cuda::std::dextents; + + cuda::std::mdspan< int, cuda::std::extents, cuda::std::layout_stride > + m { d.data() + , cuda::std::layout_stride::template mapping{dexts{16, 32}, cuda::std::array{1, 128}} + }; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_strided.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_strided.pass.cpp new file mode 100644 index 0000000000..1a32e3f0cb --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_strided.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + cuda::std::mdspan> m; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + cuda::std::array d{42}; + cuda::std::extents e{64, 128}; + + { + cuda::std::mdspan, cuda::std::layout_left> m{ d.data(), e }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + { + using dexts = cuda::std::dextents; + + cuda::std::mdspan< int, cuda::std::extents, cuda::std::layout_stride > + m { d.data() + , cuda::std::layout_stride::template mapping{dexts{16, 32}, cuda::std::array{1, 128}} + }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_unique.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_unique.pass.cpp new file mode 100644 index 0000000000..27558a89f5 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/is_unique.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + { + cuda::std::mdspan> m; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + cuda::std::array d{42}; + cuda::std::extents e{64, 128}; + + { + cuda::std::mdspan> m{ d.data(), e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + { + cuda::std::mdspan, cuda::std::layout_left> m{ d.data(), e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/mapping.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/mapping.pass.cpp new file mode 100644 index 0000000000..ca92bd5ac0 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/mapping.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + // mapping + { + using data_t = int; + using index_t = size_t; + cuda::std::array d{42}; + cuda::std::layout_left::mapping> map{cuda::std::dextents{64, 128}}; + cuda::std::mdspan, cuda::std::layout_left> m{ d.data(), map }; + + assert( m.mapping() == map ); + } + + // mapping and accessor + { + using data_t = int; + using index_t = size_t; + cuda::std::array d{42}; + cuda::std::layout_left::mapping> map{cuda::std::dextents{64, 128}}; + cuda::std::default_accessor a; + cuda::std::mdspan, cuda::std::layout_left> m{ d.data(), map, a }; + + assert( m.mapping() == map ); + } + + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/rank.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/rank.pass.cpp new file mode 100644 index 0000000000..315f6f8f41 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/rank.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + typedef int data_t ; + typedef size_t index_t; + + cuda::std::array d{42}; + + { + cuda::std::mdspan> m; + + static_assert( m.rank () == 1, "" ); + assert ( m.rank_dynamic() == 1 ); + } + + { + cuda::std::mdspan> m{d.data()}; + + static_assert( m.rank () == 1, "" ); + assert ( m.rank_dynamic() == 0 ); + } + + { + cuda::std::mdspan> m{d.data(), 16, 32}; + + static_assert( m.rank () == 2, "" ); + assert ( m.rank_dynamic() == 2 ); + } + + { + cuda::std::mdspan> m{d.data(), 16, 32}; + + static_assert( m.rank () == 3, "" ); + assert ( m.rank_dynamic() == 2 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/size.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/size.pass.cpp new file mode 100644 index 0000000000..d6a40e04ac --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/size.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +template +__host__ __device__ void test_mdspan_size(cuda::std::array& storage, Extents&& e) +{ + using extents_type = cuda::std::remove_cv_t>; + cuda::std::mdspan m(storage.data(), cuda::std::forward(e)); + + static_assert(cuda::std::is_same::value, + "The return type of mdspan::size() must be size_t."); + + // m.size() must not overflow, as long as the product of extents + // is representable as a value of type size_t. + assert( m.size() == N ); +} + + +int main(int, char**) +{ + // TEST(TestMdspan, MdspanSizeReturnTypeAndPrecondition) + { + cuda::std::array storage; + + static_assert(cuda::std::numeric_limits::max() == 127, "max int8_t != 127"); + test_mdspan_size(storage, cuda::std::extents{}); // 12 * 11 == 132 + } + + { + cuda::std::array storage; + + static_assert(cuda::std::numeric_limits::max() == 255, "max uint8_t != 255"); + test_mdspan_size(storage, cuda::std::extents{}); // 16 * 17 == 272 + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/stride.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/stride.pass.cpp new file mode 100644 index 0000000000..184cef2a58 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/stride.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +int main(int, char**) +{ + typedef int data_t ; + typedef size_t index_t; + + cuda::std::array d{42}; + + { + cuda::std::mdspan> m; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 1 ); + } + + { + cuda::std::mdspan> m{d.data(), 16, 32}; + + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + { + cuda::std::array d{42}; + cuda::std::mdspan, cuda::std::layout_left> m{d.data(), 16, 32}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + { + using dexts = cuda::std::dextents; + + cuda::std::mdspan< int, cuda::std::extents, cuda::std::layout_stride > + m { d.data() + , cuda::std::layout_stride::template mapping{dexts{16, 32}, cuda::std::array{1, 128}} + }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + } + + return 0; +} + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/swap.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/swap.pass.cpp new file mode 100644 index 0000000000..8cc9956a73 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.members/swap.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +__host__ __device__ void test_std_swap_static_extents() +{ + int data1[12] = {1,2,3,4,5,6,7,8,9,10,11,12}; + int data2[12] = {21,22,23,24,25,26,27,28,29,30,31,32}; + + cuda::std::mdspan> m1(data1); + cuda::std::mdspan> m2(data2); + cuda::std::extents exts1; + cuda::std::layout_right::mapping> map1(exts1); + cuda::std::extents exts2; + cuda::std::layout_right::mapping> map2(exts2); + + assert(m1.data_handle() == data1); + assert(m1.mapping() == map1); + auto val1 = m1(0,0); + assert(val1 == 1); + assert(m2.data_handle() == data2); + assert(m2.mapping() == map2); + auto val2 = m2(0,0); + assert(val2 == 21); + + cuda::std::swap(m1,m2); + assert(m1.data_handle() == data2); + assert(m1.mapping() == map2); + val1 = m1(0,0); + assert(val1 == 21); + assert(m2.data_handle() == data1); + assert(m2.mapping() == map1); + val2 = m2(0,0); + assert(val2 == 1); +} + +__host__ __device__ void test_std_swap_dynamic_extents() +{ + int data1[12] = {1,2,3,4,5,6,7,8,9,10,11,12}; + int data2[12] = {21,22,23,24,25,26,27,28,29,30,31,32}; + + cuda::std::mdspan> m1(data1,3,4); + cuda::std::mdspan> m2(data2,4,3); + cuda::std::dextents exts1(3,4); + cuda::std::layout_right::mapping> map1(exts1); + cuda::std::dextents exts2(4,3); + cuda::std::layout_right::mapping> map2(exts2); + + assert(m1.data_handle() == data1); + assert(m1.mapping() == map1); + auto val1 = m1(0,0); + assert(val1 == 1); + assert(m2.data_handle() == data2); + assert(m2.mapping() == map2); + auto val2 = m2(0,0); + assert(val2 == 21); + + cuda::std::swap(m1,m2); + assert(m1.data_handle() == data2); + assert(m1.mapping() == map2); + val1 = m1(0,0); + assert(val1 == 21); + assert(m2.data_handle() == data1); + assert(m2.mapping() == map1); + val2 = m2(0,0); + assert(val2 == 1); +} + +int main(int, char**) +{ + test_std_swap_static_extents(); + + test_std_swap_dynamic_extents(); + + //TODO port tests for customized layout and accessor + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.util/mdspan_util.hpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.util/mdspan_util.hpp new file mode 100644 index 0000000000..c9b4d10c9f --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.mdspan.util/mdspan_util.hpp @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#define CHECK_MDSPAN_EXTENT(m,d,e0,e1) \ + static_assert(m.is_exhaustive(), ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.rank() == 2 ); \ + assert(m.rank_dynamic() == 2 ); \ + assert(m.extent(0) == e0 ); \ + assert(m.extent(1) == e1 ) diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/dim_reduction.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/dim_reduction.pass.cpp new file mode 100644 index 0000000000..b5036d6c40 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/dim_reduction.pass.cpp @@ -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) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +int main(int, char**) +{ + // TEST(TestSubmdspanLayoutRightStaticSizedRankReducing3Dto1D, test_submdspan_layout_right_static_sized_rank_reducing_3d_to_1d) + { + cuda::std::array d; + cuda::std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = cuda::std::submdspan(m, 1, 1, cuda::std::full_extent); + + static_assert(decltype(sub0)::rank()==1,"unexpected submdspan rank"); + static_assert(sub0.rank() == 1, ""); + static_assert(sub0.rank_dynamic() == 0, ""); + assert(sub0.extent(0) == 4); + assert(sub0(1) == 42); + } + + // TEST(TestSubmdspanLayoutLeftStaticSizedRankReducing3Dto1D, test_submdspan_layout_left_static_sized_rank_reducing_3d_to_1d) + { + cuda::std::array d; + cuda::std::mdspan, cuda::std::layout_left> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = cuda::std::submdspan(m, 1, 1, cuda::std::full_extent); + + static_assert(sub0.rank() == 1, ""); + static_assert(sub0.rank_dynamic() == 0, ""); + assert(sub0.extent(0) == 4); + assert(sub0(1) == 42); + } + + // TEST(TestSubmdspanLayoutRightStaticSizedRankReducingNested3Dto0D, test_submdspan_layout_right_static_sized_rank_reducing_nested_3d_to_0d) + { + cuda::std::array d; + cuda::std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = cuda::std::submdspan(m, 1, cuda::std::full_extent, cuda::std::full_extent); + + static_assert(sub0.rank() == 2, ""); + static_assert(sub0.rank_dynamic() == 0, ""); + assert(sub0.extent(0) == 3); + assert(sub0.extent(1) == 4); + assert(sub0(1, 1) == 42); + + auto sub1 = cuda::std::submdspan(sub0, 1, cuda::std::full_extent); + static_assert(sub1.rank() == 1, ""); + static_assert(sub1.rank_dynamic() == 0, ""); + assert(sub1.extent(0) == 4); + assert(sub1(1) == 42); + + auto sub2 = cuda::std::submdspan(sub1, 1); + static_assert(sub2.rank() == 0, ""); + static_assert(sub2.rank_dynamic() == 0, ""); + assert(sub2() == 42); + } + + return 0; +} + + + + diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/pair_init.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/pair_init.pass.cpp new file mode 100644 index 0000000000..2277480327 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/pair_init.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +int main(int, char**) +{ + // TEST(TestSubmdspanLayoutRightStaticSizedPairs, test_submdspan_layout_right_static_sized_pairs) + { + cuda::std::array d; + cuda::std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = cuda::std::submdspan(m, cuda::std::pair{1, 2}, cuda::std::pair{1, 3}, cuda::std::pair{1, 4}); + + static_assert( sub0.rank() == 3, "" ); + static_assert( sub0.rank_dynamic() == 3, "" ); + assert( sub0.extent(0) == 1 ); + assert( sub0.extent(1) == 2 ); + assert( sub0.extent(2) == 3 ); + assert( sub0(0, 0, 0) == 42 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/return_type.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/return_type.pass.cpp new file mode 100644 index 0000000000..4f8f082267 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/return_type.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +constexpr auto dyn = cuda::std::dynamic_extent; + +//template + +using submdspan_test_types = cuda::std::tuple< + // LayoutLeft to LayoutLeft + cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::dextents, cuda::std::pair> + , cuda::std::tuple,cuda::std::dextents, int> + , cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t, cuda::std::pair> + , cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t, int> + , cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t, cuda::std::full_extent_t, cuda::std::pair> + , cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t, cuda::std::pair, int> + , cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t, int, int> + , cuda::std::tuple,cuda::std::dextents, cuda::std::pair, int, int> + , cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t, cuda::std::full_extent_t, cuda::std::pair, int, int, int> + , cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t, cuda::std::pair, int, int, int, int> + , cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t, int, int, int ,int, int> + , cuda::std::tuple,cuda::std::dextents, cuda::std::pair, int, int, int, int, int> + // LayoutRight to LayoutRight + , cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::dextents, cuda::std::pair> + , cuda::std::tuple,cuda::std::dextents, int> + , cuda::std::tuple,cuda::std::dextents, cuda::std::full_extent_t, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::dextents, cuda::std::pair, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::dextents, int, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::dextents, cuda::std::pair, cuda::std::full_extent_t, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::dextents, int, cuda::std::pair, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::dextents, int, int, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::dextents, int, int, int, cuda::std::pair, cuda::std::full_extent_t, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::dextents, int, int, int, int, cuda::std::pair, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::dextents, int, int, int, int, int, cuda::std::full_extent_t> + // LayoutRight to LayoutRight Check Extents Preservation + , cuda::std::tuple,cuda::std::extents, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::extents, cuda::std::pair> + , cuda::std::tuple,cuda::std::extents, int> + , cuda::std::tuple,cuda::std::extents, cuda::std::full_extent_t, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::extents, cuda::std::pair, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::extents, int, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::extents, cuda::std::pair, cuda::std::full_extent_t, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::extents, int, cuda::std::pair, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::extents, int, int, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::extents, int, int, int, cuda::std::pair, cuda::std::full_extent_t, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::extents, int, int, int, int, cuda::std::pair, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::extents, int, int, int, int, int, cuda::std::full_extent_t> + + , cuda::std::tuple,cuda::std::extents, cuda::std::full_extent_t, int, cuda::std::pair, int, int, cuda::std::full_extent_t> + , cuda::std::tuple,cuda::std::extents, int, cuda::std::full_extent_t, cuda::std::pair, int, cuda::std::full_extent_t, int> + >; + +template struct TestSubMDSpan; + +template +struct TestSubMDSpan< + cuda::std::tuple> +{ + using mds_org_t = cuda::std::mdspan; + using mds_sub_t = cuda::std::mdspan; + using map_t = typename mds_org_t::mapping_type; + + using mds_sub_deduced_t = decltype(cuda::std::submdspan(mds_org_t(nullptr, map_t()), SubArgs()...)); + using sub_args_t = cuda::std::tuple; +}; + +// TYPED_TEST(TestSubMDSpan, submdspan_return_type) +template +__host__ __device__ void test_submdspan() +{ + using TestFixture = TestSubMDSpan; + + static_assert(cuda::std::is_same::value, + "SubMDSpan: wrong return type"); +} + +int main(int, char**) +{ + static_assert( cuda::std::tuple_size< submdspan_test_types >{} == 40, "" ); + + test_submdspan< cuda::std::tuple_element_t< 0, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 1, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 2, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 3, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 4, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 5, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 6, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 7, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 8, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 9, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 10, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 11, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 12, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 13, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 14, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 15, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 16, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 17, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 18, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 19, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 20, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 21, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 22, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 23, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 24, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 25, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 26, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 27, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 28, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 29, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 30, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 31, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 32, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 33, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 34, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 35, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 36, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 37, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 38, submdspan_test_types > >(); + test_submdspan< cuda::std::tuple_element_t< 39, submdspan_test_types > >(); + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/tuple_init.pass.cpp b/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/tuple_init.pass.cpp new file mode 100644 index 0000000000..79ca1f6753 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/tuple_init.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with 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. All rights reserved. +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11, nvrtc && nvcc-12.0, nvrtc && nvcc-12.1 + +#include +#include + +int main(int, char**) +{ + // TEST(TestSubmdspanLayoutRightStaticSizedTuples, test_submdspan_layout_right_static_sized_tuples) + { + cuda::std::array d; + cuda::std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = cuda::std::submdspan(m, cuda::std::tuple{1, 2}, cuda::std::tuple{1, 3}, cuda::std::tuple{1, 4}); + + static_assert( sub0.rank() == 3, "" ); + static_assert( sub0.rank_dynamic() == 3, "" ); + assert( sub0.extent(0) == 1 ); + assert( sub0.extent(1) == 2 ); + assert( sub0.extent(2) == 3 ); + assert( sub0(0, 0, 0) == 42 ); + } + + return 0; +} diff --git a/.upstream-tests/test/std/containers/views/mdspan/my_accessor.hpp b/.upstream-tests/test/std/containers/views/mdspan/my_accessor.hpp new file mode 100644 index 0000000000..09e9fe4703 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/my_accessor.hpp @@ -0,0 +1,37 @@ +#ifndef _MY_ACCESSOR_HPP +#define _MY_ACCESSOR_HPP + +#include "foo_customizations.hpp" + +namespace Foo +{ + // Same as Foo::foo_accessor but + // 1. Doesn't have a default constructor + // 2. Isn't contructible from the default accessor + template + struct my_accessor { + using offset_policy = my_accessor; + using element_type = T; + using reference = T&; + using data_handle_type = foo_ptr; + + __MDSPAN_INLINE_FUNCTION + constexpr my_accessor(int* ptr) noexcept { flag = ptr; } + + template + __MDSPAN_INLINE_FUNCTION + constexpr my_accessor(my_accessor other) noexcept { flag = other.flag; } + + + constexpr reference access(data_handle_type p, size_t i) const noexcept { + return p.data[i]; + } + + constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept { + return data_handle_type(p.data+i); + } + int* flag; + }; +} + +#endif diff --git a/.upstream-tests/test/std/containers/views/mdspan/my_int.hpp b/.upstream-tests/test/std/containers/views/mdspan/my_int.hpp new file mode 100644 index 0000000000..2f8b1ce3b6 --- /dev/null +++ b/.upstream-tests/test/std/containers/views/mdspan/my_int.hpp @@ -0,0 +1,45 @@ +#ifndef _MY_INT_HPP +#define _MY_INT_HPP + +struct my_int_non_convertible; + +struct my_int +{ + int _val; + + __host__ __device__ my_int( my_int_non_convertible ) noexcept; + __host__ __device__ constexpr my_int( int val ) : _val( val ){}; + __host__ __device__ constexpr operator int() const noexcept { return _val; } +}; + +template <> struct cuda::std::is_integral : cuda::std::true_type {}; + +// Wrapper type that's not implicitly convertible + +struct my_int_non_convertible +{ + my_int _val; + + my_int_non_convertible(); + __host__ __device__ my_int_non_convertible( my_int val ) : _val( val ){}; + __host__ __device__ operator my_int() const noexcept { return _val; } +}; + +__host__ __device__ my_int::my_int( my_int_non_convertible ) noexcept {} + +template <> struct cuda::std::is_integral : cuda::std::true_type {}; + +// Wrapper type that's not nothrow-constructible + +struct my_int_non_nothrow_constructible +{ + int _val; + + my_int_non_nothrow_constructible(); + __host__ __device__ my_int_non_nothrow_constructible( int val ) : _val( val ){}; + __host__ __device__ operator int() const { return _val; } +}; + +template <> struct cuda::std::is_integral : cuda::std::true_type {}; + +#endif diff --git a/include/cuda/std/detail/__config b/include/cuda/std/detail/__config index 12abc63543..ce66fe3e61 100644 --- a/include/cuda/std/detail/__config +++ b/include/cuda/std/detail/__config @@ -68,6 +68,10 @@ # define _LIBCUDACXX_HAS_NO_INT128 #endif +#if defined(_LIBCUDACXX_COMPILER_MSVC) || (defined(_LIBCUDACXX_CUDACC_VER) && (_LIBCUDACXX_CUDACC_VER < 1100000)) +# define _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS +#endif + #ifndef _LIBCUDACXX_ASSERT # define _LIBCUDACXX_ASSERT(x, m) ((void)0) #endif diff --git a/include/cuda/std/detail/libcxx/include/CMakeLists.txt b/include/cuda/std/detail/libcxx/include/CMakeLists.txt index 1e575e1f03..c63c2b243b 100644 --- a/include/cuda/std/detail/libcxx/include/CMakeLists.txt +++ b/include/cuda/std/detail/libcxx/include/CMakeLists.txt @@ -39,6 +39,23 @@ set(files __iterator/wrap_iter.h __libcpp_version __locale + __mdspan/compressed_pair.hpp + __mdspan/config.hpp + __mdspan/default_accessor.hpp + __mdspan/dynamic_extent.hpp + __mdspan/extents.hpp + __mdspan/full_extent_t.hpp + __mdspan/layout_left.hpp + __mdspan/layout_right.hpp + __mdspan/layout_stride.hpp + __mdspan/macros.hpp + __mdspan/maybe_static_value.hpp + __mdspan/mdspan.hpp + __mdspan/no_unique_address.hpp + __mdspan/standard_layout_static_array.hpp + __mdspan/static_array.hpp + __mdspan/submdspan.hpp + __mdspan/type_list.hpp __memory/addressof.h __memory/pointer_traits.h __mutex_base @@ -275,6 +292,7 @@ set(files locale.h map math.h + mdspan memory module.modulemap mutex diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h b/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h new file mode 100644 index 0000000000..4b1c5514c8 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h @@ -0,0 +1,225 @@ +/* +//@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 + +#include "macros.h" + +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) +# include "no_unique_address.h" +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD +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 { + __MDSPAN_NO_UNIQUE_ADDRESS _Tp __t_val; + __MDSPAN_NO_UNIQUE_ADDRESS _Up __u_val; + __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _Tp &__first() noexcept { return __t_val; } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__first() const noexcept { + return __t_val; + } + __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _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) {} +}; + +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + +// First empty. +template +struct __compressed_pair< + _Tp, _Up, + _CUDA_VSTD::enable_if_t<__MDSPAN_TRAIT(_CUDA_VSTD::is_empty, _Tp) && !__MDSPAN_TRAIT(_CUDA_VSTD::is_empty, _Up)>> + : private _Tp { + _Up __u_val; + __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _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 __MDSPAN_CONSTEXPR_14 _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 __MDSPAN_CONSTEXPR_14 _Tp &__first() noexcept { return __t_val; } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__first() const noexcept { + return __t_val; + } + __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _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<__MDSPAN_TRAIT(_CUDA_VSTD::is_empty, _Tp) && __MDSPAN_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 __MDSPAN_CONSTEXPR_14 _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 __MDSPAN_CONSTEXPR_14 _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 // !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + +} // end namespace detail +_LIBCUDACXX_END_NAMESPACE_STD + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/config.h b/include/cuda/std/detail/libcxx/include/__mdspan/config.h new file mode 100644 index 0000000000..9351f6e8ff --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/config.h @@ -0,0 +1,296 @@ +/* +//@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 __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 + +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) +# if ((__has_cpp_attribute(no_unique_address) >= 201803L) && \ + (!defined(_LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS) || __MDSPAN_HAS_CXX_20)) +# define __MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS 1 +# define __MDSPAN_NO_UNIQUE_ADDRESS [[no_unique_address]] +# else +# define __MDSPAN_NO_UNIQUE_ADDRESS +# endif +#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_USE_INLINE_VARIABLES +# if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L \ + || (!defined(__cpp_inline_variables) && __MDSPAN_HAS_CXX_17) +# define __MDSPAN_USE_INLINE_VARIABLES 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(__GNUC__) || __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(__GNUC__) || __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 diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h b/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h new file mode 100644 index 0000000000..4f6f4b1fc6 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h @@ -0,0 +1,90 @@ +/* +//@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 + +#include "macros.h" + +#ifndef __cuda_std__ +#include // size_t +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::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]; + } + +}; + +_LIBCUDACXX_END_NAMESPACE_STD + + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h b/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h new file mode 100644 index 0000000000..91d9730cfd --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h @@ -0,0 +1,75 @@ +/* +//@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 + +#include "macros.h" + +#ifndef __cuda_std__ +#include // size_t +#include // numeric_limits +#include // dynamic_extent +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +namespace detail { + +template +__MDSPAN_HOST_DEVICE constexpr auto __make_dynamic_extent() { + return dynamic_extent; +} + +template +__MDSPAN_HOST_DEVICE constexpr auto __make_dynamic_extent_integral() { + return dynamic_extent; +} + +} // end namespace detail + +_LIBCUDACXX_END_NAMESPACE_STD + +//============================================================================================================== + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/extents.h b/include/cuda/std/detail/libcxx/include/__mdspan/extents.h new file mode 100644 index 0000000000..7e2d38f511 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/extents.h @@ -0,0 +1,548 @@ +/* +//@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 + +#include "macros.h" +#include "static_array.h" +#include "standard_layout_static_array.h" + +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) +# include "no_unique_address.h" +#endif + +#ifndef __cuda_std__ +#include +#include +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +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 +__MDSPAN_HOST_DEVICE +static constexpr false_type _check_compatible_extents( + false_type, _CUDA_VSTD::integer_sequence, _CUDA_VSTD::integer_sequence +) noexcept { return { }; } + +template +static integral_constant< + bool, + __MDSPAN_FOLD_AND( + ( + _Extents == dynamic_extent + || _OtherExtents == dynamic_extent + || _Extents == _OtherExtents + ) /* && ... */ + ) +> +__MDSPAN_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 +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : private detail::__no_unique_address_emulation< + detail::__partially_static_sizes_tagged> +#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; + +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + __MDSPAN_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 __MDSPAN_CONSTEXPR_14 + __storage_t& __storage() noexcept { +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + return __storage_; +#else + return this->__base_t::__ref(); +#endif + } + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr __storage_t const& __storage() const noexcept { +#if defined(__MDSPAN_USE_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>()) /* || ... */ + ); + } + +#if !defined(__MDSPAN_USE_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __storage_{ +#else + : __base_t(__base_t{__storage_t{ +#endif + __other.__storage().__enable_psa_conversion() +#if defined(__MDSPAN_USE_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(__MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _Integral, index_type) /* && ... */) && + __MDSPAN_FOLD_AND(__MDSPAN_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(__MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _Integral, index_type) /* && ... */) && + __MDSPAN_FOLD_AND(__MDSPAN_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __storage_{ +#else + : __base_t(__base_t{typename __base_t::__stored_type{ +#endif + _CUDA_VSTD::conditional_t(), + static_cast(__exts)... +#if defined(__MDSPAN_USE_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _IndexType, index_type) && + __MDSPAN_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _IndexType, index_type) && + __MDSPAN_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 +#if defined(__MDSPAN_USE_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} +#if defined(__MDSPAN_USE_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _IndexType, index_type) && + __MDSPAN_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _IndexType, index_type) && + __MDSPAN_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 +#if defined(__MDSPAN_USE_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 +#if defined(__MDSPAN_USE_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __storage_{ +#else + : __base_t(__base_t{ +#endif + __sto +#if defined(__MDSPAN_USE_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( +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + __base_t{ +#endif + _CUDA_VSTD::move(__bs.template __with_tag()) +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + } +#endif + ); + } + + template + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr + index_type __extent() const noexcept { + return __storage().template __get_n<_Np>(); + } + + template + __MDSPAN_INLINE_FUNCTION + static constexpr + index_type __static_extent() noexcept { + return __storage_t::template __get_static_n<_Np, _Default>(); + } + +}; + +namespace detail { + +template > +struct __make_dextents; + +template +struct __make_dextents<_IndexType, _Rank, _CUDA_VSTD::extents<_IndexType, _ExtentsPack...>> { + using type = typename __make_dextents<_IndexType, _Rank - 1, + _CUDA_VSTD::extents<_IndexType, _CUDA_VSTD::dynamic_extent, _ExtentsPack...>>::type; +}; + +template +struct __make_dextents<_IndexType, 0, _CUDA_VSTD::extents<_IndexType, _ExtentsPack...>> { + using type = _CUDA_VSTD::extents<_IndexType, _ExtentsPack...>; +}; + +} // end namespace detail + +template +using dextents = typename detail::__make_dextents<_IndexType, _Rank>::type; + +#if defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) +template +extents(_IndexTypes...) + // Workaround for nvcc + //-> extents()...>; + // Adding "(void)" so that clang doesn't complain this is unused + -> extents; +#endif + +namespace detail { + +template +struct __is_extents : false_type {}; + +template +struct __is_extents<_CUDA_VSTD::extents<_IndexType, _ExtentsPack...>> : true_type {}; + +template +static constexpr bool __is_extents_v = __is_extents<_Tp>::value; + + +template +struct __extents_to_partially_static_sizes; + +template +struct __extents_to_partially_static_sizes<_CUDA_VSTD::extents<_IndexType, _ExtentsPack...>> { + using type = detail::__partially_static_sizes< + typename _CUDA_VSTD::extents<_IndexType, _ExtentsPack...>::index_type, size_t, + _ExtentsPack...>; +}; + +template +using __extents_to_partially_static_sizes_t = typename __extents_to_partially_static_sizes<_Extents>::type; + +} // end namespace detail +_LIBCUDACXX_END_NAMESPACE_STD + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h b/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h new file mode 100644 index 0000000000..ea07c7c8cd --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h @@ -0,0 +1,57 @@ +/* +//@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 + +#include "macros.h" + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +struct full_extent_t { explicit full_extent_t() = default; }; + +__MDSPAN_INLINE_VARIABLE constexpr auto full_extent = full_extent_t{ }; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h new file mode 100644 index 0000000000..4afe275b5c --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h @@ -0,0 +1,255 @@ +/* +//@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 + +#include "macros.h" +#include "extents.h" + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +//============================================================================== + +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 + __MDSPAN_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 + __MDSPAN_HOST_DEVICE + constexpr index_type __compute_offset( + __rank_count, const _Ip& __i) const { + return __i; + } + + __MDSPAN_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; + + __MDSPAN_HOST_DEVICE + constexpr mapping(extents_type const& __exts) noexcept + :__extents(__exts) + { } + + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherExtents, + /* requires */ ( + __MDSPAN_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 __MDSPAN_CONSTEXPR_14 + 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 */ ( + __MDSPAN_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 __MDSPAN_CONSTEXPR_14 + 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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_constructible, extents_type, _OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((extents_type::rank() > 0)) + __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + 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 + */ + #ifndef __CUDA_ARCH__ + size_t __stride = 1; + for(rank_type __r=0; __r<__extents.rank(); __r++) { + #ifndef _LIBCUDACXX_NO_EXCEPTIONS + if(__stride != static_cast(__other.stride(__r))) + __throw_runtime_error("Assigning layout_stride to layout_left with invalid strides."); + #else + assert(__stride == static_cast(__other.stride(__r))); + #endif + __stride *= __extents.extent(__r); + } + #endif + } + + __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(), __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 + __MDSPAN_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 + __MDSPAN_HOST_DEVICE + constexpr index_type stride() const noexcept { + return __get_stride<_Np>(__extents, _CUDA_VSTD::make_index_sequence()); + } + +private: + __MDSPAN_NO_UNIQUE_ADDRESS extents_type __extents{}; + +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h new file mode 100644 index 0000000000..6944232fd4 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h @@ -0,0 +1,256 @@ +/* +//@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 + +#include "macros.h" +#include "extents.h" +#include "layout_stride.h" + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +//============================================================================== +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 + __MDSPAN_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 + __MDSPAN_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...); + } + + __MDSPAN_HOST_DEVICE + constexpr index_type __compute_offset(size_t __offset, __rank_count) const { + return static_cast(__offset); + } + + __MDSPAN_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; + + __MDSPAN_HOST_DEVICE + constexpr mapping(extents_type const& __exts) noexcept + :__extents(__exts) + { } + + __MDSPAN_TEMPLATE_REQUIRES( + class _OtherExtents, + /* requires */ ( + __MDSPAN_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 __MDSPAN_CONSTEXPR_14 + 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 */ ( + __MDSPAN_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 __MDSPAN_CONSTEXPR_14 + 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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_constructible, extents_type, _OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((extents_type::rank() > 0)) + __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + 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 + */ + #ifndef __CUDA_ARCH__ + size_t __stride = 1; + for(rank_type __r=__extents.rank(); __r>0; __r--) { + #ifndef _LIBCUDACXX_NO_EXCEPTIONS + if(__stride != static_cast(__other.stride(__r-1))) + __throw_runtime_error("Assigning layout_stride to layout_right with invalid strides."); + #else + assert(__stride == static_cast(__other.stride(__r-1))); + #endif + __stride *= __extents.extent(__r-1); + } + #endif + } + + __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( + (__MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _Indices, index_type) && + __MDSPAN_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _Indices)) + ) + ) + ) + __MDSPAN_HOST_DEVICE + constexpr index_type operator()(_Indices... __idxs) const noexcept { + return __compute_offset(__rank_count<0, extents_type::rank()>(), __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 + __MDSPAN_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 + __MDSPAN_HOST_DEVICE + constexpr index_type __stride() const noexcept { + return __get_stride<_Np>(__extents, _CUDA_VSTD::make_index_sequence()); + } + +private: + __MDSPAN_NO_UNIQUE_ADDRESS extents_type __extents{}; + +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h new file mode 100644 index 0000000000..e4ef1f52a1 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h @@ -0,0 +1,537 @@ +/* +//@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 + +#include "macros.h" +#include "static_array.h" +#include "extents.h" +#include "compressed_pair.h" + +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) +# include "no_unique_address.h" +#endif + +#ifndef __cuda_std__ +#include +#include +#include +#endif +#if __MDSPAN_USE_CONCEPTS && __MDSPAN_HAS_CXX_20 +#include +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +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 +#if !defined(__MDSPAN_USE_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; + +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + __MDSPAN_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 { +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + return __members.__second(); +#else + return this->__base_t::__ref().__second(); +#endif + } + __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 __strides_storage_t& + __strides_storage() noexcept { +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + return __members.__second(); +#else + return this->__base_t::__ref().__second(); +#endif + } + + template + __MDSPAN_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()>>; + + + //---------------------------------------------------------------------------- + +#if defined(__MDSPAN_USE_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( +#if !defined(__MDSPAN_USE_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))} + ) +#if !defined(__MDSPAN_USE_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' + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, const remove_const_t<_IntegralTypes>&, typename _Extents::index_type) && + __MDSPAN_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __members{ +#else + : __base_t(__base_t{__member_pair_t( +#endif + __e, __strides_storage_t(__impl::fill_strides(__s)) +#if defined(__MDSPAN_USE_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' + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, const remove_const_t<_IntegralTypes>&, typename _Extents::index_type) && + __MDSPAN_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __members{ +#else + : __base_t(__base_t{__member_pair_t( +#endif + __e, __strides_storage_t(__impl::fill_strides(__s)) +#if defined(__MDSPAN_USE_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 */ ( + __MDSPAN_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> && + __MDSPAN_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 __MDSPAN_CONSTEXPR_14 + mapping(_StridedLayoutMapping const& __other) noexcept // NOLINT(google-explicit-constructor) +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __members{ +#else + : __base_t(__base_t{__member_pair_t( +#endif + __other.extents(), __strides_storage_t(__impl::fill_strides(__other)) +#if defined(__MDSPAN_USE_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 { +#if defined(__MDSPAN_USE_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(__MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _Indices, index_type) /*&& ...*/ ) && + __MDSPAN_FOLD_AND(__MDSPAN_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _Indices) /*&& ...*/) + ) + ) + __MDSPAN_FORCE_INLINE_FUNCTION + constexpr index_type operator()(_Indices... __idxs) const noexcept { + return __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 __MDSPAN_CONSTEXPR_14 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 + + }; +}; + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/macros.h b/include/cuda/std/detail/libcxx/include/__mdspan/macros.h new file mode 100644 index 0000000000..4316cef0db --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/macros.h @@ -0,0 +1,653 @@ +/* +//@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 + +#include "config.h" + +#ifndef __cuda_std__ +#include // is_void +#endif + +#ifndef __MDSPAN_HOST_DEVICE +# if defined(__MDSPAN_HAS_CUDA) || defined(__MDSPAN_HAS_HIP) +# define __MDSPAN_HOST_DEVICE __host__ __device__ +# else +# define __MDSPAN_HOST_DEVICE +# endif +#endif + +#ifndef __MDSPAN_FORCE_INLINE_FUNCTION +# ifdef __MDSPAN_COMPILER_MSVC // Microsoft compilers +# define __MDSPAN_FORCE_INLINE_FUNCTION __forceinline __MDSPAN_HOST_DEVICE +# else +# define __MDSPAN_FORCE_INLINE_FUNCTION __attribute__((always_inline)) __MDSPAN_HOST_DEVICE +# endif +#endif + +#ifndef __MDSPAN_INLINE_FUNCTION +# define __MDSPAN_INLINE_FUNCTION inline __MDSPAN_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 + +#ifdef __MDSPAN_USE_INLINE_VARIABLES +# define __MDSPAN_INLINE_VARIABLE inline +#else +# define __MDSPAN_INLINE_VARIABLE +#endif + +// end inline variables }}}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 +__MDSPAN_HOST_DEVICE +constexpr __mdspan_enable_fold_comma __fold_comma_impl(_Args&&... __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(...) \ + __MDSPAN_TRAIT(_CUDA_VSTD::is_same, __fold_compatibility_impl::__bools<(__VA_ARGS__)..., true>, __fold_compatibility_impl::__bools) + +#endif + +// end fold expressions }}}1 +//============================================================================== + +//============================================================================== +// {{{1 + +#if __MDSPAN_USE_VARIABLE_TEMPLATES +# define __MDSPAN_TRAIT(__TRAIT, ...) __TRAIT##_v<__VA_ARGS__> +#else +# define __MDSPAN_TRAIT(__TRAIT, ...) __TRAIT<__VA_ARGS__>::value +#endif + +// end Variable template compatibility }}}1 +//============================================================================== + +//============================================================================== +// {{{1 + +#if __MDSPAN_USE_CONSTEXPR_14 +# define __MDSPAN_CONSTEXPR_14 constexpr +// 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 +# define __MDSPAN_CONSTEXPR_14_DEFAULTED +#endif + +// end Pre-C++14 constexpr }}}1 +//============================================================================== + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h b/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h new file mode 100644 index 0000000000..e2ae006888 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h @@ -0,0 +1,155 @@ +/* +//@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 + +#include "macros.h" + +#include "dynamic_extent.h" + +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) +# include "no_unique_address.h" +#endif + +// This is only needed for the non-standard-layout version of partially +// static array. +// Needs to be after the includes above to work with the single header generator +#if !__MDSPAN_PRESERVE_STANDARD_LAYOUT +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +//============================================================================== + +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 __MDSPAN_CONSTEXPR_14 + __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> +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __no_unique_address_emulation<_Tp> +#endif +{ + static constexpr _static_t __static_value = __is_dynamic_sentinal; +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + __MDSPAN_NO_UNIQUE_ADDRESS _dynamic_t __v = {}; + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t __value() const noexcept { + return __v; + } + __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _dynamic_t &__ref() noexcept { + return __v; + } + template + __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __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 __MDSPAN_CONSTEXPR_14 _dynamic_t &__ref() noexcept { + return this->__no_unique_address_emulation<_dynamic_t>::__ref(); + } + template + __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __mdspan_enable_fold_comma + __set_value(_Up&& __rhs) noexcept { + this->__no_unique_address_emulation<_dynamic_t>::__ref() = (_Up &&)__rhs; + return {}; + } +#endif +}; + +} // namespace detail + +//============================================================================== + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // !__MDSPAN_PRESERVE_STANDARD_LAYOUT + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h b/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h new file mode 100644 index 0000000000..b2b6a69491 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h @@ -0,0 +1,439 @@ +/* +//@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 + +#include "default_accessor.h" +#include "layout_right.h" +#include "extents.h" +#include "compressed_pair.h" + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +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) && + __MDSPAN_TRAIT(_CUDA_VSTD::is_default_constructible, data_handle_type) && + __MDSPAN_TRAIT(_CUDA_VSTD::is_default_constructible, mapping_type) && + __MDSPAN_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(__MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SizeTypes, index_type) /* && ... */) && + __MDSPAN_FOLD_AND(__MDSPAN_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeTypes) /* && ... */) && + ((sizeof...(_SizeTypes) == rank()) || (sizeof...(_SizeTypes) == rank_dynamic())) && + __MDSPAN_TRAIT(_CUDA_VSTD::is_constructible, mapping_type, extents_type) && + __MDSPAN_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + __MDSPAN_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeType) && + ((_Np == rank()) || (_Np == rank_dynamic())) && + __MDSPAN_TRAIT(_CUDA_VSTD::is_constructible, mapping_type, extents_type) && + __MDSPAN_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + __MDSPAN_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _SizeType) && + ((_Np == rank()) || (_Np == rank_dynamic())) && + __MDSPAN_TRAIT(_CUDA_VSTD::is_constructible, mapping_type, extents_type) && + __MDSPAN_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 */ (__MDSPAN_TRAIT(_CUDA_VSTD::is_default_constructible, accessor_type) && + __MDSPAN_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 */ (__MDSPAN_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_constructible, mapping_type, typename _OtherLayoutPolicy::template mapping<_OtherExtents>) && + __MDSPAN_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(__MDSPAN_TRAIT(_CUDA_VSTD::is_constructible, data_handle_type, typename _OtherAccessor::data_handle_type),"Incompatible data_handle_type for mdspan construction"); + static_assert(__MDSPAN_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(__MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SizeTypes, index_type) /* && ... */) && + __MDSPAN_FOLD_AND(__MDSPAN_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + __MDSPAN_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + __MDSPAN_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _Index, index_type) && + __MDSPAN_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(__MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SizeTypes, index_type) /* && ... */) && + __MDSPAN_FOLD_AND(__MDSPAN_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + __MDSPAN_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 */ ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SizeType, index_type) && + __MDSPAN_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 __MDSPAN_CONSTEXPR_14 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 __MDSPAN_CONSTEXPR_14 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 __MDSPAN_CONSTEXPR_14 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(__MDSPAN_TRAIT(is_integral, _SizeTypes) /* && ... */) && + (sizeof...(_SizeTypes) > 0) +) +explicit mdspan(_ElementType*, _SizeTypes...) + -> mdspan<_ElementType, dextents>; + +__MDSPAN_TEMPLATE_REQUIRES( + class _Pointer, + (__MDSPAN_TRAIT(is_pointer, _CUDA_VSTD::remove_reference_t<_Pointer>)) +) +mdspan(_Pointer&&) -> mdspan<_CUDA_VSTD::remove_pointer_t<_CUDA_VSTD::remove_reference_t<_Pointer>>, extents>; +__MDSPAN_TEMPLATE_REQUIRES( + class _CArray, + (__MDSPAN_TRAIT(is_array, _CArray) && (rank_v<_CArray> == 1)) +) +mdspan(_CArray&) -> mdspan<_CUDA_VSTD::remove_all_extents_t<_CArray>, extents>>; + +template +mdspan(_ElementType*, const _CUDA_VSTD::array<_SizeType, _Np>&) + -> mdspan<_ElementType, dextents>; + +template +mdspan(_ElementType*, _CUDA_VSTD::span<_SizeType, _Np>) + -> mdspan<_ElementType, dextents>; + +// This one is necessary because all the constructors take `data_handle_type`s, not +// `_ElementType*`s, and `data_handle_type` is taken from `accessor_type::data_handle_type`, which +// seems to throw off automatic deduction guides. +template +mdspan(_ElementType*, const extents<_SizeType, _ExtentsPack...>&) + -> mdspan<_ElementType, extents<_SizeType, _ExtentsPack...>>; + +template +mdspan(_ElementType*, const _MappingType&) + -> mdspan<_ElementType, typename _MappingType::extents_type, typename _MappingType::layout_type>; + +template +mdspan(const typename _AccessorType::data_handle_type, const _MappingType&, const _AccessorType&) + -> mdspan; +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h b/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h new file mode 100644 index 0000000000..43359d884b --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h @@ -0,0 +1,127 @@ +/* +//@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_NO_UNIQUE_ADDRESS_HPP +#define _LIBCUDACXX___MDSPAN_NO_UNIQUE_ADDRESS_HPP + +#include "macros.h" + +_LIBCUDACXX_BEGIN_NAMESPACE_STD +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 __MDSPAN_CONSTEXPR_14 _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<__MDSPAN_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 + __MDSPAN_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 __MDSPAN_CONSTEXPR_14 _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 +_LIBCUDACXX_END_NAMESPACE_STD + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h b/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h new file mode 100644 index 0000000000..6375cb2939 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h @@ -0,0 +1,671 @@ +/* +//@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 + +#include "macros.h" +#include "dynamic_extent.h" +#include "compressed_pair.h" + +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) +# include "no_unique_address.h" +#endif + +#ifndef __cuda_std__ +#include +#include +#include // integer_sequence +#include +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD +namespace detail { + +//============================================================================== + +__MDSPAN_INLINE_VARIABLE constexpr struct + __construct_psa_from_dynamic_exts_values_tag_t { +} __construct_psa_from_dynamic_exts_values_tag = {}; + +__MDSPAN_INLINE_VARIABLE constexpr struct + __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> +#if !defined(__MDSPAN_USE_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>; + +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + __MDSPAN_NO_UNIQUE_ADDRESS __next_t __next_; +#else + using __base_t = __no_unique_address_emulation<__next_t>; +#endif + + __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 __next_t &__next() noexcept { +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + return __next_; +#else + return this->__base_t::__ref(); +#endif + } + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t const &__next() const noexcept { +#if defined(__MDSPAN_USE_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __construct_psa_from_all_exts_values_tag, __vals... +#if defined(__MDSPAN_USE_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __construct_psa_from_dynamic_exts_values_tag, __vals... +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + } +#else + )}) +#endif + { } + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + array<_Up, _Np> const &__vals) noexcept +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __vals +#if defined(__MDSPAN_USE_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __tag, __vals +#if defined(__MDSPAN_USE_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __tag, __vals +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + } +#else + )}) +#endif + { } + + template + __MDSPAN_INLINE_FUNCTION constexpr explicit __standard_layout_psa( + _CUDA_VSTD::span<_Up, _Np> const &__vals) noexcept +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __vals +#if defined(__MDSPAN_USE_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __tag, __vals +#if defined(__MDSPAN_USE_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __tag, __vals +#if defined(__MDSPAN_USE_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 +#if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) + : __next_{ +#else + : __base_t(__base_t{__next_t( +#endif + __rhs.__next() +#if defined(__MDSPAN_USE_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 __MDSPAN_CONSTEXPR_14 void + __set_n(_Tp const &__rhs) noexcept { + __next().__set_value(__rhs); + } + template = 1> + __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 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 __MDSPAN_CONSTEXPR_14 __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 __MDSPAN_CONSTEXPR_14 void + __set_n(_Tp const &__rhs) noexcept { + __next().__set_value(__rhs); + } + template = 1> + __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 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...>>; + using __psa_impl_t::__psa_impl_t; +#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: + using __base_t::__base_t; + +#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 +_LIBCUDACXX_END_NAMESPACE_STD + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h b/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h new file mode 100644 index 0000000000..7eee043156 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h @@ -0,0 +1,288 @@ +/* +//@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 + +#include "macros.h" + +#include "dynamic_extent.h" +#include "maybe_static_value.h" +#include "standard_layout_static_array.h" +#include "type_list.h" + +// Needs to be after the includes above to work with the single header generator +#if !__MDSPAN_PRESERVE_STANDARD_LAYOUT +#ifndef __cuda_std__ +#include // size_t +#include // integer_sequence +#include +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD +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 __MDSPAN_CONSTEXPR_14 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: + using __base_t::__base_t; +}; + +//============================================================================== + +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: + using __base_t::__base_t; + 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 +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // !__MDSPAN_PRESERVE_STANDARD_LAYOUT + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h b/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h new file mode 100644 index 0000000000..caec7ab2ba --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h @@ -0,0 +1,588 @@ +/* +//@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 + +#include "mdspan.h" +#include "full_extent_t.h" +#include "dynamic_extent.h" +#include "layout_left.h" +#include "layout_right.h" +#include "layout_stride.h" +#include "macros.h" + +#ifndef __cuda_std__ +#include // apply +#include // pair +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +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) + __MDSPAN_CONSTEXPR_14 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) + __MDSPAN_CONSTEXPR_14 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) + __MDSPAN_CONSTEXPR_14 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) + __MDSPAN_CONSTEXPR_14 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) + __MDSPAN_CONSTEXPR_14 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 = typename conditional< + _PreserveLayoutAnalysis::value, + typename _PreserveLayoutAnalysis::layout_type_if_preserved, + layout_stride + >::type; + + // TODO noexcept specification + template + __MDSPAN_INLINE_FUNCTION + __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( + ( + __MDSPAN_CONSTEXPR_14 /* 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( + ( + __MDSPAN_CONSTEXPR_14 /* 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( + ( + __MDSPAN_CONSTEXPR_14 /* 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 */ ( + ( + __MDSPAN_TRAIT(_CUDA_VSTD::is_same, _LP, layout_left) + || __MDSPAN_TRAIT(_CUDA_VSTD::is_same, _LP, layout_right) + || detail::_is_layout_stride<_LP>::value + ) && + __MDSPAN_FOLD_AND(( + __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SliceSpecs, size_t) + || __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SliceSpecs, tuple) + || __MDSPAN_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 */ + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h b/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h new file mode 100644 index 0000000000..498dc9af31 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h @@ -0,0 +1,121 @@ +/* +//@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 + +#include "macros.h" + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +//============================================================================== + +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 + __MDSPAN_HOST_DEVICE + __type_at_assign_op_ignore_rest<_Result> operator=(_Tp&&); + using type = _Result; +}; + +struct __type_at_assign_op_impl { + template + __MDSPAN_HOST_DEVICE + __type_at_assign_op_impl operator=(__type_at_entry<_Ip, _Idx, _Tp>&&); + template + __MDSPAN_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 + +//============================================================================== + +_LIBCUDACXX_END_NAMESPACE_STD + + +#endif diff --git a/include/cuda/std/detail/libcxx/include/mdspan b/include/cuda/std/detail/libcxx/include/mdspan new file mode 100644 index 0000000000..8068a38429 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/mdspan @@ -0,0 +1,79 @@ +/* +//@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 +#define _LIBCUDACXX_MDSPAN + +#ifndef __cuda_std__ +#include "array" +#include "span" +#include "cstddef" +#include "limits" +#include "tuple" +#include "type_traits" +#include "utility" +#include "version" +#include <__pragma_push> +#endif // __cuda_std__ + +#if _LIBCUDACXX_STD_VER > 11 + +#include "__mdspan/default_accessor.h" +#include "__mdspan/full_extent_t.h" +#include "__mdspan/mdspan.h" +#include "__mdspan/dynamic_extent.h" +#include "__mdspan/extents.h" +#include "__mdspan/layout_stride.h" +#include "__mdspan/layout_left.h" +#include "__mdspan/layout_right.h" +#include "__mdspan/macros.h" +#include "__mdspan/static_array.h" +#include "__mdspan/submdspan.h" + +#endif // _LIBCUDACXX_STD_VER > 11 + +#ifndef __cuda_std__ +#include <__pragma_pop> +#endif // __cuda_std__ + +#endif diff --git a/include/cuda/std/detail/libcxx/include/numeric b/include/cuda/std/detail/libcxx/include/numeric index 5503544864..388dfa1671 100644 --- a/include/cuda/std/detail/libcxx/include/numeric +++ b/include/cuda/std/detail/libcxx/include/numeric @@ -16,6 +16,7 @@ namespace std { +#ifndef __cuda_std__ template T accumulate(InputIterator first, InputIterator last, T init); @@ -123,15 +124,18 @@ template template OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); +#endif // __cuda_std__ template void iota(ForwardIterator first, ForwardIterator last, T value); +#ifndef __cuda_std__ template constexpr common_type_t gcd(M m, N n); // C++17 template constexpr common_type_t lcm(M m, N n); // C++17 +#endif // __cuda_std__ integer midpoint(integer a, integer b); // C++20 pointer midpoint(pointer a, pointer b); // C++20 @@ -141,22 +145,25 @@ floating_point midpoint(floating_point a, floating_point b); // C++20 */ +#ifndef __cuda_std__ #include <__config> #include #include // for numeric_limits #include #include // for isnormal #include +#include <__pragma_push> #if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) #pragma GCC system_header #endif -_LIBCUDACXX_PUSH_MACROS #include <__undef_macros> +#endif // __cuda_std__ _LIBCUDACXX_BEGIN_NAMESPACE_STD +#ifndef __cuda_std__ template inline _LIBCUDACXX_INLINE_VISIBILITY _Tp @@ -448,6 +455,7 @@ adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterat } return __result; } +#endif // __cuda_std__ template inline _LIBCUDACXX_INLINE_VISIBILITY @@ -459,6 +467,7 @@ iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_) } +#ifndef __cuda_std__ #if _LIBCUDACXX_STD_VER > 14 template ::value> struct __ct_abs; @@ -581,13 +590,16 @@ midpoint(_Fp __a, _Fp __b) noexcept } #endif // _LIBCUDACXX_STD_VER > 17 +#endif // __cuda_std__ _LIBCUDACXX_END_NAMESPACE_STD -_LIBCUDACXX_POP_MACROS - #if defined(_LIBCUDACXX_HAS_PARALLEL_ALGORITHMS) && _LIBCUDACXX_STD_VER >= 17 # include <__pstl_numeric> #endif +#ifndef __cuda_std__ +#include <__pragma_pop> +#endif //__cuda_std__ + #endif // _LIBCUDACXX_NUMERIC diff --git a/include/cuda/std/mdspan b/include/cuda/std/mdspan new file mode 100644 index 0000000000..799396b3ff --- /dev/null +++ b/include/cuda/std/mdspan @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_MDSPAN +#define _CUDA_MDSPAN + +#include "array" +#include "span" +#include "cstddef" +#include "limits" +#include "tuple" +#include "type_traits" +#include "utility" +#include "version" + +#include "detail/__config" + +#include "detail/__pragma_push" + +#include "detail/libcxx/include/algorithm" +#include "detail/libcxx/include/numeric" +#include "detail/libcxx/include/mdspan" + +#include "detail/__pragma_pop" + +#endif //_CUDA_MDSPAN From c834cf74bbfb5b91798fa705fde4e4fc1bc42f42 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Thu, 9 Feb 2023 14:09:32 +0100 Subject: [PATCH 3/7] Make the header conform to our internal architecture --- .../libcxx/include/__mdspan/compressed_pair.h | 21 ++++++++-- .../detail/libcxx/include/__mdspan/config.h | 10 ++++- .../include/__mdspan/default_accessor.h | 16 +++++-- .../libcxx/include/__mdspan/dynamic_extent.h | 15 +++++-- .../detail/libcxx/include/__mdspan/extents.h | 39 +++++++++++++---- .../libcxx/include/__mdspan/full_extent_t.h | 16 ++++++- .../libcxx/include/__mdspan/layout_left.h | 22 ++++++++-- .../libcxx/include/__mdspan/layout_right.h | 24 +++++++++-- .../libcxx/include/__mdspan/layout_stride.h | 42 +++++++++++++------ .../detail/libcxx/include/__mdspan/macros.h | 20 +++++++-- .../include/__mdspan/maybe_static_value.h | 22 +++++++--- .../detail/libcxx/include/__mdspan/mdspan.h | 33 ++++++++++++--- .../include/__mdspan/no_unique_address.h | 22 +++++++++- .../__mdspan/standard_layout_static_array.h | 31 +++++++++----- .../libcxx/include/__mdspan/static_array.h | 35 ++++++++++------ .../libcxx/include/__mdspan/submdspan.h | 39 ++++++++++++----- .../libcxx/include/__mdspan/type_list.h | 17 ++++++-- include/cuda/std/detail/libcxx/include/mdspan | 23 ++-------- include/cuda/std/mdspan | 4 +- 19 files changed, 338 insertions(+), 113 deletions(-) diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h b/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h index 4b1c5514c8..7591172641 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h @@ -44,13 +44,25 @@ #ifndef _LIBCUDACXX___MDSPAN_COMPRESSED_PAIR_HPP #define _LIBCUDACXX___MDSPAN_COMPRESSED_PAIR_HPP -#include "macros.h" +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ +#include "../__mdspan/macros.h" #if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) -# include "no_unique_address.h" +#include "../__mdspan/no_unique_address.h" +#endif +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_empty.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header #endif _LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + namespace detail { // For no unique address emulation, this is the case taken when neither are empty. @@ -220,6 +232,9 @@ struct __compressed_pair< #endif // !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) } // end namespace detail + +#endif // _LIBCUDACXX_STD_VER > 11 + _LIBCUDACXX_END_NAMESPACE_STD -#endif +#endif // _LIBCUDACXX___MDSPAN_COMPRESSED_PAIR_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/config.h b/include/cuda/std/detail/libcxx/include/__mdspan/config.h index 9351f6e8ff..15c5b2d3ea 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/config.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/config.h @@ -44,6 +44,12 @@ #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 @@ -293,4 +299,6 @@ static_assert(__MDSPAN_CPLUSPLUS >= __MDSPAN_CXX_STD_14, "mdspan requires C++14 # define __MDSPAN_OP6(mds, a, b, c, d, e, f) mds(a,b,c,d,e,f) #endif -#endif +#endif // _LIBCUDACXX_STD_VER > 11 + +#endif // _LIBCUDACXX___MDSPAN_CONFIG_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h b/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h index 4f6f4b1fc6..6ba418723b 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/default_accessor.h @@ -44,14 +44,21 @@ #ifndef _LIBCUDACXX___MDSPAN_DEFAULT_ACCESSOR_HPP #define _LIBCUDACXX___MDSPAN_DEFAULT_ACCESSOR_HPP -#include "macros.h" - #ifndef __cuda_std__ +#include <__config> #include // size_t +#endif // __cuda_std__ + +#include "../__mdspan/macros.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header #endif _LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 11 + template struct default_accessor { @@ -84,7 +91,8 @@ struct default_accessor { }; -_LIBCUDACXX_END_NAMESPACE_STD +#endif // _LIBCUDACXX_STD_VER > 11 +_LIBCUDACXX_END_NAMESPACE_STD -#endif +#endif // _LIBCUDACXX___MDSPAN_DEFAULT_ACCESSOR_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h b/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h index 91d9730cfd..2cf1f0e211 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h @@ -44,16 +44,23 @@ #ifndef _LIBCUDACXX___MDSPAN_DYNAMIC_EXTENT_HPP #define _LIBCUDACXX___MDSPAN_DYNAMIC_EXTENT_HPP -#include "macros.h" - #ifndef __cuda_std__ +#include <__config> #include // size_t #include // numeric_limits #include // dynamic_extent +#endif // __cuda_std__ + +#include "../__mdspan/macros.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header #endif _LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 11 + namespace detail { template @@ -68,8 +75,10 @@ __MDSPAN_HOST_DEVICE constexpr auto __make_dynamic_extent_integral() { } // end namespace detail +#endif // _LIBCUDACXX_STD_VER > 11 + _LIBCUDACXX_END_NAMESPACE_STD //============================================================================================================== -#endif +#endif // _LIBCUDACXX___MDSPAN_DYNAMIC_EXTENT_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/extents.h b/include/cuda/std/detail/libcxx/include/__mdspan/extents.h index 7e2d38f511..e8d4d7cb44 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/extents.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/extents.h @@ -44,21 +44,39 @@ #ifndef _LIBCUDACXX___MDSPAN_EXTENTS_HPP #define _LIBCUDACXX___MDSPAN_EXTENTS_HPP -#include "macros.h" -#include "static_array.h" -#include "standard_layout_static_array.h" +#ifndef __cuda_std__ +#include <__config> +#include +#include +#include +#include +#endif // __cuda_std__ +#include "../__mdspan/macros.h" #if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) -# include "no_unique_address.h" +#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" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header #endif -#ifndef __cuda_std__ -#include -#include +#if defined(_LIBCUDACXX_PUSH_MACROS) + _LIBCUDACXX_PUSH_MACROS #endif +#include "../__undef_macros" _LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 11 + namespace detail { template @@ -543,6 +561,13 @@ 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/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h b/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h index ea07c7c8cd..3b0be0d911 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h @@ -44,14 +44,26 @@ #ifndef _LIBCUDACXX___MDSPAN_FULL_EXTENT_T_HPP #define _LIBCUDACXX___MDSPAN_FULL_EXTENT_T_HPP -#include "macros.h" +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/macros.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif _LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 11 + struct full_extent_t { explicit full_extent_t() = default; }; __MDSPAN_INLINE_VARIABLE constexpr auto full_extent = full_extent_t{ }; +#endif // _LIBCUDACXX_STD_VER > 11 + _LIBCUDACXX_END_NAMESPACE_STD -#endif +#endif // _LIBCUDACXX___MDSPAN_FULL_EXTENT_T_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h index 4afe275b5c..ec1b8d1d2f 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h @@ -44,11 +44,25 @@ #ifndef _LIBCUDACXX___MDSPAN_LAYOUT_LEFT_HPP #define _LIBCUDACXX___MDSPAN_LAYOUT_LEFT_HPP -#include "macros.h" -#include "extents.h" +#ifndef __cuda_std__ +#include <__config> +#include +#endif // __cuda_std__ + +#include "../__mdspan/extents.h" +#include "../__mdspan/macros.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_nothrow_constructible.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif _LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 11 + //============================================================================== template @@ -250,6 +264,8 @@ class layout_left::mapping { }; +#endif // _LIBCUDACXX_STD_VER > 11 + _LIBCUDACXX_END_NAMESPACE_STD -#endif +#endif // _LIBCUDACXX___MDSPAN_LAYOUT_LEFT_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h index 6944232fd4..8452f2104d 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h @@ -44,12 +44,26 @@ #ifndef _LIBCUDACXX___MDSPAN_LAYOUT_RIGHT_HPP #define _LIBCUDACXX___MDSPAN_LAYOUT_RIGHT_HPP -#include "macros.h" -#include "extents.h" -#include "layout_stride.h" +#ifndef __cuda_std__ +#include <__config> +#include +#endif // __cuda_std__ + +#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" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif _LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 11 + //============================================================================== template class layout_right::mapping { @@ -251,6 +265,8 @@ class layout_right::mapping { }; +#endif // _LIBCUDACXX_STD_VER > 11 + _LIBCUDACXX_END_NAMESPACE_STD -#endif +#endif // _LIBCUDACXX___MDSPAN_LAYOUT_RIGHT_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h index e4ef1f52a1..117080475d 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h @@ -44,26 +44,40 @@ #ifndef _LIBCUDACXX___MDSPAN_LAYOUT_STRIDE_HPP #define _LIBCUDACXX___MDSPAN_LAYOUT_STRIDE_HPP -#include "macros.h" -#include "static_array.h" -#include "extents.h" -#include "compressed_pair.h" - -#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) -# include "no_unique_address.h" -#endif - #ifndef __cuda_std__ +#include <__config> #include -#include #include -#endif -#if __MDSPAN_USE_CONCEPTS && __MDSPAN_HAS_CXX_20 +#if __MDSPAN_USE_CONCEPTS && __MDSPAN_HAS_CXX_20 #include #endif +#include +#include +#include +#endif // __cuda_std__ + +#include "../__mdspan/compressed_pair.h" +#include "../__mdspan/extents.h" +#include "../__mdspan/macros.h" +#if !defined(__MDSPAN_USE_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/move.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif _LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 11 + struct layout_left { template class mapping; @@ -532,6 +546,8 @@ struct layout_stride { }; }; +#endif // _LIBCUDACXX_STD_VER > 11 + _LIBCUDACXX_END_NAMESPACE_STD -#endif +#endif // _LIBCUDACXX___MDSPAN_LAYOUT_STRIDE_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/macros.h b/include/cuda/std/detail/libcxx/include/__mdspan/macros.h index 4316cef0db..beb23ad62a 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/macros.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/macros.h @@ -45,12 +45,22 @@ #ifndef _LIBCUDACXX___MDSPAN_MACROS_HPP #define _LIBCUDACXX___MDSPAN_MACROS_HPP -#include "config.h" - #ifndef __cuda_std__ -#include // is_void +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/config.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_void.h" +#include "../__type_traits/remove_reference.h" +#include "../__utility/declval.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header #endif +#if _LIBCUDACXX_STD_VER > 11 + #ifndef __MDSPAN_HOST_DEVICE # if defined(__MDSPAN_HAS_CUDA) || defined(__MDSPAN_HAS_HIP) # define __MDSPAN_HOST_DEVICE __host__ __device__ @@ -650,4 +660,6 @@ _LIBCUDACXX_END_NAMESPACE_STD // end Pre-C++14 constexpr }}}1 //============================================================================== -#endif +#endif // _LIBCUDACXX_STD_VER > 11 + +#endif // _LIBCUDACXX___MDSPAN_MACROS_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h b/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h index e2ae006888..83e97e891d 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h @@ -44,20 +44,29 @@ #ifndef _LIBCUDACXX___MDSPAN_MAYBE_STATIC_VALUE_HPP #define _LIBCUDACXX___MDSPAN_MAYBE_STATIC_VALUE_HPP -#include "macros.h" - -#include "dynamic_extent.h" +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ +#include "../__mdspan/dynamic_extent.h" +#include "../__mdspan/macros.h" #if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) -# include "no_unique_address.h" +#include "../__mdspan/no_unique_address.h" +#endif + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header #endif // This is only needed for the non-standard-layout version of partially // static array. // Needs to be after the includes above to work with the single header generator #if !__MDSPAN_PRESERVE_STANDARD_LAYOUT + _LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 11 + //============================================================================== namespace detail { @@ -148,8 +157,11 @@ struct __maybe_static_value<_dynamic_t, _static_t, __is_dynamic_sentinal, __is_d //============================================================================== + +#endif // _LIBCUDACXX_STD_VER > 11 + _LIBCUDACXX_END_NAMESPACE_STD #endif // !__MDSPAN_PRESERVE_STANDARD_LAYOUT -#endif +#endif // _LIBCUDACXX___MDSPAN_MAYBE_STATIC_VALUE_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h b/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h index b2b6a69491..928b4c2a6b 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h @@ -45,13 +45,34 @@ #ifndef _LIBCUDACXX___MDSPAN_MDSPAN_HPP #define _LIBCUDACXX___MDSPAN_MDSPAN_HPP -#include "default_accessor.h" -#include "layout_right.h" -#include "extents.h" -#include "compressed_pair.h" +#ifndef __cuda_std__ +#include <__config> +#include +#include +#include +#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/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/remove_cv.h" +#include "../__type_traits/remove_pointer.h" +#include "../__type_traits/remove_reference.h" +#include "../__type_traits/remove_all_extents.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif _LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 11 + template < class _ElementType, class _Extents, @@ -434,6 +455,8 @@ mdspan(const typename _AccessorType::data_handle_type, const _MappingType&, cons -> mdspan; #endif +#endif // _LIBCUDACXX_STD_VER > 11 + _LIBCUDACXX_END_NAMESPACE_STD -#endif +#endif // _LIBCUDACXX___MDSPAN_MDSPAN_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h b/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h index 43359d884b..813861e25c 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h @@ -44,9 +44,24 @@ #ifndef _LIBCUDACXX___MDSPAN_NO_UNIQUE_ADDRESS_HPP #define _LIBCUDACXX___MDSPAN_NO_UNIQUE_ADDRESS_HPP -#include "macros.h" +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/macros.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_empty.h" +#include "../__type_traits/is_trivially_destructible.h" +#include "../__utility/move.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif _LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + namespace detail { //============================================================================== @@ -122,6 +137,9 @@ struct __no_unique_address_emulation< //============================================================================== } // end namespace detail + +#endif // _LIBCUDACXX_STD_VER > 11 + _LIBCUDACXX_END_NAMESPACE_STD -#endif +#endif // _LIBCUDACXX___MDSPAN_NO_UNIQUE_ADDRESS_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h b/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h index 6375cb2939..168bca41e8 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h @@ -44,22 +44,30 @@ #ifndef _LIBCUDACXX___MDSPAN_STANDARD_LAYOUT_STATIC_ARRAY_HPP #define _LIBCUDACXX___MDSPAN_STANDARD_LAYOUT_STATIC_ARRAY_HPP -#include "macros.h" -#include "dynamic_extent.h" -#include "compressed_pair.h" - -#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) -# include "no_unique_address.h" -#endif - #ifndef __cuda_std__ +#include <__config> #include +#include #include #include // integer_sequence -#include +#endif // __cuda_std__ + +#include "../__mdspan/compressed_pair.h" +#include "../__mdspan/dynamic_extent.h" +#include "../__mdspan/macros.h" +#if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) +#include "../__mdspan/no_unique_address.h" +#endif +#include "../__type_traits/enable_if.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header #endif _LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + namespace detail { //============================================================================== @@ -666,6 +674,9 @@ struct __partially_static_sizes #endif // __MDSPAN_PRESERVE_STATIC_LAYOUT } // end namespace detail + +#endif // _LIBCUDACXX_STD_VER > 11 + _LIBCUDACXX_END_NAMESPACE_STD -#endif +#endif // _LIBCUDACXX___MDSPAN_STANDARD_LAYOUT_STATIC_ARRAY_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h b/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h index 7eee043156..eed12e6b16 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h @@ -44,22 +44,30 @@ #ifndef _LIBCUDACXX___MDSPAN_STATIC_ARRAY_HPP #define _LIBCUDACXX___MDSPAN_STATIC_ARRAY_HPP -#include "macros.h" - -#include "dynamic_extent.h" -#include "maybe_static_value.h" -#include "standard_layout_static_array.h" -#include "type_list.h" - -// Needs to be after the includes above to work with the single header generator -#if !__MDSPAN_PRESERVE_STANDARD_LAYOUT #ifndef __cuda_std__ -#include // size_t -#include // integer_sequence +#include <__config> #include +#include +#include +#include // integer_sequence +#endif // __cuda_std__ + +#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" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header #endif +#if !__MDSPAN_PRESERVE_STANDARD_LAYOUT + _LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + namespace detail { //============================================================================== @@ -281,8 +289,11 @@ 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 +#endif // _LIBCUDACXX___MDSPAN_STATIC_ARRAY_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h b/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h index caec7ab2ba..7910b5f226 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h @@ -45,21 +45,36 @@ #ifndef _LIBCUDACXX___MDSPAN_SUBMDSPAN_HPP #define _LIBCUDACXX___MDSPAN_SUBMDSPAN_HPP -#include "mdspan.h" -#include "full_extent_t.h" -#include "dynamic_extent.h" -#include "layout_left.h" -#include "layout_right.h" -#include "layout_stride.h" -#include "macros.h" - #ifndef __cuda_std__ +#include <__config> #include // apply #include // pair +#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" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header #endif _LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 11 + namespace detail { template @@ -397,11 +412,11 @@ struct __assign_op_slice_handler< } // TODO defer instantiation of this? - using layout_type = typename conditional< + using layout_type = conditional_t< _PreserveLayoutAnalysis::value, typename _PreserveLayoutAnalysis::layout_type_if_preserved, layout_stride - >::type; + >; // TODO noexcept specification template @@ -583,6 +598,8 @@ __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( ) /* clang-format: on */ +#endif // _LIBCUDACXX_STD_VER > 11 + _LIBCUDACXX_END_NAMESPACE_STD -#endif +#endif // _LIBCUDACXX___MDSPAN_SUBMDSPAN_HPP diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h b/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h index 498dc9af31..87d8fae5ad 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h @@ -44,10 +44,20 @@ #ifndef _LIBCUDACXX___MDSPAN_TYPE_LIST_HPP #define _LIBCUDACXX___MDSPAN_TYPE_LIST_HPP -#include "macros.h" +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__mdspan/macros.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif _LIBCUDACXX_BEGIN_NAMESPACE_STD +#if _LIBCUDACXX_STD_VER > 11 + //============================================================================== namespace detail { @@ -115,7 +125,8 @@ struct __type_at<3, __type_list<_T0, _T1, _T2, _T3, _Ts...>> { //============================================================================== -_LIBCUDACXX_END_NAMESPACE_STD +#endif // _LIBCUDACXX_STD_VER > 11 +_LIBCUDACXX_END_NAMESPACE_STD -#endif +#endif // _LIBCUDACXX___MDSPAN_TYPE_LIST_HPP diff --git a/include/cuda/std/detail/libcxx/include/mdspan b/include/cuda/std/detail/libcxx/include/mdspan index 8068a38429..6d60c498c6 100644 --- a/include/cuda/std/detail/libcxx/include/mdspan +++ b/include/cuda/std/detail/libcxx/include/mdspan @@ -45,18 +45,9 @@ #define _LIBCUDACXX_MDSPAN #ifndef __cuda_std__ -#include "array" -#include "span" -#include "cstddef" -#include "limits" -#include "tuple" -#include "type_traits" -#include "utility" -#include "version" -#include <__pragma_push> -#endif // __cuda_std__ - -#if _LIBCUDACXX_STD_VER > 11 +#include <__config> +#include +#endif //__cuda_std__ #include "__mdspan/default_accessor.h" #include "__mdspan/full_extent_t.h" @@ -70,10 +61,4 @@ #include "__mdspan/static_array.h" #include "__mdspan/submdspan.h" -#endif // _LIBCUDACXX_STD_VER > 11 - -#ifndef __cuda_std__ -#include <__pragma_pop> -#endif // __cuda_std__ - -#endif +#endif // _LIBCUDACXX_MDSPAN diff --git a/include/cuda/std/mdspan b/include/cuda/std/mdspan index 799396b3ff..4a7c841ef7 100644 --- a/include/cuda/std/mdspan +++ b/include/cuda/std/mdspan @@ -4,6 +4,7 @@ // under the Apache License v2.0 with 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. All rights reserved. // //===----------------------------------------------------------------------===// @@ -15,7 +16,6 @@ #include "cstddef" #include "limits" #include "tuple" -#include "type_traits" #include "utility" #include "version" @@ -29,4 +29,4 @@ #include "detail/__pragma_pop" -#endif //_CUDA_MDSPAN +#endif // _CUDA_MDSPAN From 5cb6a2a78a2f1ee428716f82b2aa1ad69f7a0749 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Thu, 9 Feb 2023 14:16:51 +0100 Subject: [PATCH 4/7] Replace usages of `__MDSPAN_INLINE_VARIABLE` with `_LIBCUDACXX_INLINE_VAR` --- .../cuda/std/detail/libcxx/include/__mdspan/config.h | 7 ------- .../detail/libcxx/include/__mdspan/full_extent_t.h | 2 +- .../cuda/std/detail/libcxx/include/__mdspan/macros.h | 12 ------------ .../include/__mdspan/standard_layout_static_array.h | 4 ++-- 4 files changed, 3 insertions(+), 22 deletions(-) diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/config.h b/include/cuda/std/detail/libcxx/include/__mdspan/config.h index 15c5b2d3ea..cb6d5a4c3f 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/config.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/config.h @@ -154,13 +154,6 @@ static_assert(__MDSPAN_CPLUSPLUS >= __MDSPAN_CXX_STD_14, "mdspan requires C++14 # endif #endif -#ifndef __MDSPAN_USE_INLINE_VARIABLES -# if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L \ - || (!defined(__cpp_inline_variables) && __MDSPAN_HAS_CXX_17) -# define __MDSPAN_USE_INLINE_VARIABLES 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) diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h b/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h index 3b0be0d911..294ba6c6af 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/full_extent_t.h @@ -60,7 +60,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD struct full_extent_t { explicit full_extent_t() = default; }; -__MDSPAN_INLINE_VARIABLE constexpr auto full_extent = full_extent_t{ }; +_LIBCUDACXX_INLINE_VAR constexpr auto full_extent = full_extent_t{ }; #endif // _LIBCUDACXX_STD_VER > 11 diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/macros.h b/include/cuda/std/detail/libcxx/include/__mdspan/macros.h index beb23ad62a..a70f38432a 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/macros.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/macros.h @@ -256,18 +256,6 @@ // end Concept emulation }}}1 //============================================================================== -//============================================================================== -// {{{1 - -#ifdef __MDSPAN_USE_INLINE_VARIABLES -# define __MDSPAN_INLINE_VARIABLE inline -#else -# define __MDSPAN_INLINE_VARIABLE -#endif - -// end inline variables }}}1 -//============================================================================== - //============================================================================== // {{{1 diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h b/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h index 168bca41e8..9da8ccc1dd 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h @@ -72,11 +72,11 @@ namespace detail { //============================================================================== -__MDSPAN_INLINE_VARIABLE constexpr struct +_LIBCUDACXX_INLINE_VAR constexpr struct __construct_psa_from_dynamic_exts_values_tag_t { } __construct_psa_from_dynamic_exts_values_tag = {}; -__MDSPAN_INLINE_VARIABLE constexpr struct +_LIBCUDACXX_INLINE_VAR constexpr struct __construct_psa_from_all_exts_values_tag_t { } __construct_psa_from_all_exts_values_tag = {}; From 4f45d79b50730bd38b0b24b44fb08ede1eb972fa Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Thu, 9 Feb 2023 14:17:58 +0100 Subject: [PATCH 5/7] We are always at least C++14 so replace `__MDSPAN_CONSTEXPR_14` with `constexpr` --- .../views/mdspan/foo_customizations.hpp | 8 ++++---- .../libcxx/include/__mdspan/compressed_pair.h | 16 ++++++++-------- .../std/detail/libcxx/include/__mdspan/extents.h | 2 +- .../detail/libcxx/include/__mdspan/layout_left.h | 6 +++--- .../libcxx/include/__mdspan/layout_right.h | 6 +++--- .../libcxx/include/__mdspan/layout_stride.h | 6 +++--- .../std/detail/libcxx/include/__mdspan/macros.h | 2 -- .../libcxx/include/__mdspan/maybe_static_value.h | 10 +++++----- .../std/detail/libcxx/include/__mdspan/mdspan.h | 6 +++--- .../libcxx/include/__mdspan/no_unique_address.h | 4 ++-- .../__mdspan/standard_layout_static_array.h | 12 ++++++------ .../libcxx/include/__mdspan/static_array.h | 2 +- .../detail/libcxx/include/__mdspan/submdspan.h | 16 ++++++++-------- 13 files changed, 47 insertions(+), 49 deletions(-) diff --git a/.upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp b/.upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp index 626fa3e378..4a5ec27b02 100644 --- a/.upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp +++ b/.upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp @@ -87,7 +87,7 @@ class layout_foo::mapping { ) ) __MDSPAN_CONDITIONAL_EXPLICIT((!cuda::std::is_convertible::value)) // needs two () due to comma - __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_INLINE_FUNCTION constexpr mapping(mapping const& other) noexcept // NOLINT(google-explicit-constructor) :__extents(other.extents()) { @@ -104,7 +104,7 @@ class layout_foo::mapping { ) ) __MDSPAN_CONDITIONAL_EXPLICIT((!cuda::std::is_convertible::value)) // needs two () due to comma - __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_INLINE_FUNCTION constexpr mapping(cuda::std::layout_right::mapping const& other) noexcept // NOLINT(google-explicit-constructor) :__extents(other.extents()) {} @@ -117,7 +117,7 @@ class layout_foo::mapping { ) ) __MDSPAN_CONDITIONAL_EXPLICIT((!cuda::std::is_convertible::value)) // needs two () due to comma - __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_INLINE_FUNCTION constexpr mapping(cuda::std::layout_left::mapping const& other) noexcept // NOLINT(google-explicit-constructor) :__extents(other.extents()) {} @@ -129,7 +129,7 @@ class layout_foo::mapping { ) ) __MDSPAN_CONDITIONAL_EXPLICIT((extents_type::rank() > 0)) - __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_INLINE_FUNCTION constexpr mapping(cuda::std::layout_stride::mapping const& other) // NOLINT(google-explicit-constructor) :__extents(other.extents()) { diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h b/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h index 7591172641..21d40e37cf 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h @@ -70,11 +70,11 @@ namespace detail { template struct __compressed_pair { __MDSPAN_NO_UNIQUE_ADDRESS _Tp __t_val; __MDSPAN_NO_UNIQUE_ADDRESS _Up __u_val; - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _Tp &__first() noexcept { return __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 __MDSPAN_CONSTEXPR_14 _Up &__second() noexcept { return __u_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; } @@ -107,13 +107,13 @@ struct __compressed_pair< _CUDA_VSTD::enable_if_t<__MDSPAN_TRAIT(_CUDA_VSTD::is_empty, _Tp) && !__MDSPAN_TRAIT(_CUDA_VSTD::is_empty, _Up)>> : private _Tp { _Up __u_val; - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _Tp &__first() noexcept { + __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 __MDSPAN_CONSTEXPR_14 _Up &__second() noexcept { return __u_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; } @@ -144,11 +144,11 @@ struct __compressed_pair< _CUDA_VSTD::enable_if_t> : private _Up { _Tp __t_val; - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _Tp &__first() noexcept { return __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 __MDSPAN_CONSTEXPR_14 _Up &__second() noexcept { + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up &__second() noexcept { return *static_cast<_Up *>(this); } __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up const &__second() const noexcept { @@ -195,13 +195,13 @@ struct __compressed_pair< using __first_base_t = __no_unique_address_emulation<_Tp, 0>; using __second_base_t = __no_unique_address_emulation<_Up, 1>; - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _Tp &__first() noexcept { + __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 __MDSPAN_CONSTEXPR_14 _Up &__second() noexcept { + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up &__second() noexcept { return this->__second_base_t::__ref(); } __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Up const &__second() const noexcept { diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/extents.h b/include/cuda/std/detail/libcxx/include/__mdspan/extents.h index e8d4d7cb44..6fbeb1f736 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/extents.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/extents.h @@ -143,7 +143,7 @@ class extents // private members dealing with the way we internally store dynamic extents private: - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __storage_t& __storage() noexcept { #if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) return __storage_; diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h index ec1b8d1d2f..4c6e29490c 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h @@ -121,7 +121,7 @@ class layout_left::mapping { ) ) __MDSPAN_CONDITIONAL_EXPLICIT((!_CUDA_VSTD::is_convertible<_OtherExtents, extents_type>::value)) // needs two () due to comma - __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_INLINE_FUNCTION constexpr mapping(mapping<_OtherExtents> const& __other) noexcept // NOLINT(google-explicit-constructor) :__extents(__other.extents()) { @@ -139,7 +139,7 @@ class layout_left::mapping { ) ) __MDSPAN_CONDITIONAL_EXPLICIT((!_CUDA_VSTD::is_convertible<_OtherExtents, extents_type>::value)) // needs two () due to comma - __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_INLINE_FUNCTION constexpr mapping(layout_right::mapping<_OtherExtents> const& __other) noexcept // NOLINT(google-explicit-constructor) :__extents(__other.extents()) { @@ -156,7 +156,7 @@ class layout_left::mapping { ) ) __MDSPAN_CONDITIONAL_EXPLICIT((extents_type::rank() > 0)) - __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_INLINE_FUNCTION constexpr mapping(layout_stride::mapping<_OtherExtents> const& __other) // NOLINT(google-explicit-constructor) :__extents(__other.extents()) { diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h index 8452f2104d..fb9a5c89e0 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h @@ -125,7 +125,7 @@ class layout_right::mapping { ) ) __MDSPAN_CONDITIONAL_EXPLICIT((!_CUDA_VSTD::is_convertible<_OtherExtents, extents_type>::value)) // needs two () due to comma - __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_INLINE_FUNCTION constexpr mapping(mapping<_OtherExtents> const& __other) noexcept // NOLINT(google-explicit-constructor) :__extents(__other.extents()) { @@ -143,7 +143,7 @@ class layout_right::mapping { ) ) __MDSPAN_CONDITIONAL_EXPLICIT((!_CUDA_VSTD::is_convertible<_OtherExtents, extents_type>::value)) // needs two () due to comma - __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_INLINE_FUNCTION constexpr mapping(layout_left::mapping<_OtherExtents> const& __other) noexcept // NOLINT(google-explicit-constructor) :__extents(__other.extents()) { @@ -160,7 +160,7 @@ class layout_right::mapping { ) ) __MDSPAN_CONDITIONAL_EXPLICIT((extents_type::rank() > 0)) - __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_INLINE_FUNCTION constexpr mapping(layout_stride::mapping<_OtherExtents> const& __other) // NOLINT(google-explicit-constructor) :__extents(__other.extents()) { diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h index 117080475d..a2baff5041 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h @@ -150,7 +150,7 @@ struct layout_stride { return this->__base_t::__ref().__second(); #endif } - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 __strides_storage_t& + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __strides_storage_t& __strides_storage() noexcept { #if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) return __members.__second(); @@ -389,7 +389,7 @@ struct layout_stride { detail::__is_mapping_of || detail::__is_mapping_of) ) // needs two () due to comma - __MDSPAN_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_INLINE_FUNCTION constexpr mapping(_StridedLayoutMapping const& __other) noexcept // NOLINT(google-explicit-constructor) #if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) : __members{ @@ -461,7 +461,7 @@ struct layout_stride { __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 __MDSPAN_CONSTEXPR_14 bool is_exhaustive() const noexcept { + __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; } diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/macros.h b/include/cuda/std/detail/libcxx/include/__mdspan/macros.h index a70f38432a..1e0c708f9b 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/macros.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/macros.h @@ -633,7 +633,6 @@ _LIBCUDACXX_END_NAMESPACE_STD // {{{1 #if __MDSPAN_USE_CONSTEXPR_14 -# define __MDSPAN_CONSTEXPR_14 constexpr // Workaround for a bug (I think?) in EDG frontends # ifdef __EDG__ # define __MDSPAN_CONSTEXPR_14_DEFAULTED @@ -641,7 +640,6 @@ _LIBCUDACXX_END_NAMESPACE_STD # define __MDSPAN_CONSTEXPR_14_DEFAULTED constexpr # endif #else -# define __MDSPAN_CONSTEXPR_14 # define __MDSPAN_CONSTEXPR_14_DEFAULTED #endif diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h b/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h index 83e97e891d..65fbc20b62 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h @@ -81,7 +81,7 @@ struct __maybe_static_value { return static_cast<_dynamic_t>(__v); } template - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __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? @@ -126,11 +126,11 @@ struct __maybe_static_value<_dynamic_t, _static_t, __is_dynamic_sentinal, __is_d __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t __value() const noexcept { return __v; } - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _dynamic_t &__ref() noexcept { + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t &__ref() noexcept { return __v; } template - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __mdspan_enable_fold_comma __set_value(_Up&& __rhs) noexcept { __v = (_Up &&)rhs; @@ -140,11 +140,11 @@ struct __maybe_static_value<_dynamic_t, _static_t, __is_dynamic_sentinal, __is_d __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t __value() const noexcept { return this->__no_unique_address_emulation<_dynamic_t>::__ref(); } - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _dynamic_t &__ref() noexcept { + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t &__ref() noexcept { return this->__no_unique_address_emulation<_dynamic_t>::__ref(); } template - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __mdspan_enable_fold_comma __set_value(_Up&& __rhs) noexcept { this->__no_unique_address_emulation<_dynamic_t>::__ref() = (_Up &&)__rhs; diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h b/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h index 928b4c2a6b..ab7d89c4e9 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h @@ -399,11 +399,11 @@ class mdspan detail::__compressed_pair __members{}; - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 data_handle_type& __ptr_ref() noexcept { return __members.__first(); } + __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 __MDSPAN_CONSTEXPR_14 mapping_type& __mapping_ref() noexcept { return __members.__second().__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 __MDSPAN_CONSTEXPR_14 accessor_type& __accessor_ref() noexcept { return __members.__second().__second(); } + __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 diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h b/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h index 813861e25c..f7e74ec03a 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h @@ -73,7 +73,7 @@ struct __no_unique_address_emulation { __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__ref() const noexcept { return __v; } - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _Tp &__ref() noexcept { + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp &__ref() noexcept { return __v; } }; @@ -105,7 +105,7 @@ struct __no_unique_address_emulation< __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__ref() const noexcept { return *static_cast<_Tp const *>(this); } - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 _Tp &__ref() noexcept { + __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp &__ref() noexcept { return *static_cast<_Tp *>(this); } diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h b/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h index 9da8ccc1dd..071553f34b 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h @@ -129,7 +129,7 @@ struct __standard_layout_psa< using __base_t = __no_unique_address_emulation<__next_t>; #endif - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 __next_t &__next() noexcept { + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t &__next() noexcept { #if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) return __next_; #else @@ -340,12 +340,12 @@ struct __standard_layout_psa< return __value; } template = 0> - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 void + __MDSPAN_FORCE_INLINE_FUNCTION constexpr void __set_n(_Tp const &__rhs) noexcept { __next().__set_value(__rhs); } template = 1> - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 void + __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 @@ -382,7 +382,7 @@ struct __standard_layout_psa< using __value_pair_t = __compressed_pair<_Tp, __next_t>; __value_pair_t __value_pair; - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 __next_t &__next() noexcept { + __MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t &__next() noexcept { return __value_pair.__second(); } __MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t const &__next() const noexcept { @@ -500,12 +500,12 @@ struct __standard_layout_psa< return __value_pair.__first(); } template = 0> - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 void + __MDSPAN_FORCE_INLINE_FUNCTION constexpr void __set_n(_Tp const &__rhs) noexcept { __next().__set_value(__rhs); } template = 1> - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 void + __MDSPAN_FORCE_INLINE_FUNCTION constexpr void __set_n(_Tp const &__rhs) noexcept { __value_pair.__first() = __rhs; } diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h b/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h index eed12e6b16..c738d7fc56 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h @@ -210,7 +210,7 @@ class __partially_static_array_impl< } template - __MDSPAN_FORCE_INLINE_FUNCTION __MDSPAN_CONSTEXPR_14 void __set_n(_Up&& __rhs) noexcept { + __MDSPAN_FORCE_INLINE_FUNCTION constexpr void __set_n(_Up&& __rhs) noexcept { static_cast<__base_n<_Ip>*>(this)->__set_value((_Up&&)__rhs); } diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h b/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h index 7910b5f226..03ae723ab9 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h @@ -288,7 +288,7 @@ struct __assign_op_slice_handler< // 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) - __MDSPAN_CONSTEXPR_14 auto + constexpr auto operator=(__slice_wrap<_OldStaticExtent, _OldStaticStride, size_t>&& __slice) noexcept -> __assign_op_slice_handler< _IndexT, @@ -310,7 +310,7 @@ struct __assign_op_slice_handler< // but it might help for specialized layouts. template __MDSPAN_FORCE_INLINE_FUNCTION // NOLINT (misc-unconventional-assign-operator) - __MDSPAN_CONSTEXPR_14 auto + constexpr auto operator=(__slice_wrap<_OldStaticExtent, _OldStaticStride, integral_constant<_IntegerType, _Value0>>&&) noexcept -> __assign_op_slice_handler< _IndexT, @@ -335,7 +335,7 @@ struct __assign_op_slice_handler< // For a _CUDA_VSTD::full_extent, offset 0 and old extent template __MDSPAN_FORCE_INLINE_FUNCTION // NOLINT (misc-unconventional-assign-operator) - __MDSPAN_CONSTEXPR_14 auto + constexpr auto operator=(__slice_wrap<_OldStaticExtent, _OldStaticStride, full_extent_t>&& __slice) noexcept -> __assign_op_slice_handler< _IndexT, @@ -359,7 +359,7 @@ struct __assign_op_slice_handler< // 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) - __MDSPAN_CONSTEXPR_14 auto + constexpr auto operator=(__slice_wrap<_OldStaticExtent, _OldStaticStride, tuple>&& __slice) noexcept -> __assign_op_slice_handler< _IndexT, @@ -387,7 +387,7 @@ struct __assign_op_slice_handler< class _IntegerType0, _IntegerType0 _Value0, class _IntegerType1, _IntegerType1 _Value1> __MDSPAN_FORCE_INLINE_FUNCTION // NOLINT (misc-unconventional-assign-operator) - __MDSPAN_CONSTEXPR_14 auto + constexpr auto operator=(__slice_wrap<_OldStaticExtent, _OldStaticStride, tuple, integral_constant<_IntegerType1, _Value1>>>&& __slice) noexcept -> __assign_op_slice_handler< _IndexT, @@ -423,7 +423,7 @@ struct __assign_op_slice_handler< __MDSPAN_INLINE_FUNCTION __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( ( - __MDSPAN_CONSTEXPR_14 /* auto */ + constexpr /* auto */ _make_layout_mapping_impl(NewLayout) noexcept ), ( @@ -437,7 +437,7 @@ struct __assign_op_slice_handler< __MDSPAN_INLINE_FUNCTION __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( ( - __MDSPAN_CONSTEXPR_14 /* auto */ + constexpr /* auto */ _make_layout_mapping_impl(layout_stride) noexcept ), ( @@ -450,7 +450,7 @@ struct __assign_op_slice_handler< __MDSPAN_INLINE_FUNCTION __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( ( - __MDSPAN_CONSTEXPR_14 /* auto */ + constexpr /* auto */ make_layout_mapping(_OldLayoutMapping const&) noexcept ), ( From 1e25eb1709a6284b6ee292f37cda5b74b0061f6b Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Thu, 9 Feb 2023 14:20:13 +0100 Subject: [PATCH 6/7] Add some necessary __uglification --- .../views/mdspan/foo_customizations.hpp | 2 +- .../libcxx/include/__mdspan/compressed_pair.h | 4 +- .../libcxx/include/__mdspan/dynamic_extent.h | 4 +- .../detail/libcxx/include/__mdspan/extents.h | 62 +++++++++---------- .../libcxx/include/__mdspan/layout_left.h | 2 +- .../libcxx/include/__mdspan/layout_right.h | 2 +- .../libcxx/include/__mdspan/layout_stride.h | 36 +++++------ .../include/__mdspan/maybe_static_value.h | 4 +- .../detail/libcxx/include/__mdspan/mdspan.h | 6 +- .../include/__mdspan/no_unique_address.h | 4 +- .../__mdspan/standard_layout_static_array.h | 4 +- .../libcxx/include/__mdspan/static_array.h | 4 +- .../libcxx/include/__mdspan/submdspan.h | 20 +++--- .../libcxx/include/__mdspan/type_list.h | 4 +- 14 files changed, 79 insertions(+), 79 deletions(-) diff --git a/.upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp b/.upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp index 4a5ec27b02..3b9f3224cc 100644 --- a/.upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp +++ b/.upstream-tests/test/std/containers/views/mdspan/foo_customizations.hpp @@ -61,7 +61,7 @@ class layout_foo::mapping { using layout_type = layout_foo; private: - static_assert(cuda::std::detail::__is_extents_v, + static_assert(cuda::std::__detail::__is_extents_v, "layout_foo::mapping must be instantiated with a specialization of cuda::std::extents."); static_assert(extents_type::rank() < 3, "layout_foo only supports 0D, 1D and 2D"); diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h b/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h index 21d40e37cf..4f1bc9c99d 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/compressed_pair.h @@ -63,7 +63,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD #if _LIBCUDACXX_STD_VER > 11 -namespace detail { +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. @@ -231,7 +231,7 @@ struct __compressed_pair< #endif // !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) -} // end namespace detail +} // end namespace __detail #endif // _LIBCUDACXX_STD_VER > 11 diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h b/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h index 2cf1f0e211..699ec15a50 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/dynamic_extent.h @@ -61,7 +61,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD #if _LIBCUDACXX_STD_VER > 11 -namespace detail { +namespace __detail { template __MDSPAN_HOST_DEVICE constexpr auto __make_dynamic_extent() { @@ -73,7 +73,7 @@ __MDSPAN_HOST_DEVICE constexpr auto __make_dynamic_extent_integral() { return dynamic_extent; } -} // end namespace detail +} // end namespace __detail #endif // _LIBCUDACXX_STD_VER > 11 diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/extents.h b/include/cuda/std/detail/libcxx/include/__mdspan/extents.h index 6fbeb1f736..781770f1e5 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/extents.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/extents.h @@ -77,24 +77,24 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD #if _LIBCUDACXX_STD_VER > 11 -namespace detail { +namespace __detail { template -struct _count_dynamic_extents; +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; +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<> { +struct __count_dynamic_extents<> { static constexpr size_t val = 0; }; template __MDSPAN_HOST_DEVICE -static constexpr false_type _check_compatible_extents( +static constexpr false_type __check_compatible_extents( false_type, _CUDA_VSTD::integer_sequence, _CUDA_VSTD::integer_sequence ) noexcept { return { }; } @@ -110,19 +110,19 @@ static integral_constant< ) > __MDSPAN_HOST_DEVICE -_check_compatible_extents( +__check_compatible_extents( true_type, _CUDA_VSTD::integer_sequence, _CUDA_VSTD::integer_sequence ) noexcept { return { }; } struct __extents_tag { }; -} // end namespace detail +} // end namespace __detail template class extents #if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) - : private detail::__no_unique_address_emulation< - detail::__partially_static_sizes_tagged> + : private __detail::__no_unique_address_emulation< + __detail::__partially_static_sizes_tagged<__detail::__extents_tag, _ThisIndexType , size_t, _Extents...>> #endif { public: @@ -132,12 +132,12 @@ class extents using size_type = make_unsigned_t; // internal typedefs which for technical reasons are public - using __storage_t = detail::__partially_static_sizes_tagged; + using __storage_t = __detail::__partially_static_sizes_tagged<__detail::__extents_tag, index_type, size_t, _Extents...>; #if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) __MDSPAN_NO_UNIQUE_ADDRESS __storage_t __storage_; #else - using __base_t = detail::__no_unique_address_emulation<__storage_t>; + using __base_t = __detail::__no_unique_address_emulation<__storage_t>; #endif // private members dealing with the way we internally store dynamic extents @@ -229,7 +229,7 @@ class extents 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( + decltype(__detail::__check_compatible_extents( integral_constant{}, _CUDA_VSTD::integer_sequence{}, _CUDA_VSTD::integer_sequence{} @@ -271,7 +271,7 @@ class extents __MDSPAN_FOLD_AND(__MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _Integral, index_type) /* && ... */) && __MDSPAN_FOLD_AND(__MDSPAN_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) == __detail::__count_dynamic_extents<_Extents...>::val) || (sizeof...(_Integral) == sizeof...(_Extents))) ) ) @@ -293,8 +293,8 @@ class extents : __base_t(__base_t{typename __base_t::__stored_type{ #endif _CUDA_VSTD::conditional_t(), + __detail::__construct_psa_from_dynamic_exts_values_tag_t, + __detail::__construct_psa_from_all_exts_values_tag_t>(), static_cast(__exts)... #if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) } @@ -319,7 +319,7 @@ class extents /* requires */ ( __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _IndexType, index_type) && __MDSPAN_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _IndexType) && - ((_Np == detail::_count_dynamic_extents<_Extents...>::val) || + ((_Np == __detail::__count_dynamic_extents<_Extents...>::val) || (_Np == sizeof...(_Extents))) ) ) @@ -343,8 +343,8 @@ class extents : __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>(), + __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} #if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) } @@ -369,7 +369,7 @@ class extents /* requires */ ( __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _IndexType, index_type) && __MDSPAN_TRAIT(_CUDA_VSTD::is_nothrow_constructible, index_type, _IndexType) && - ((_Np == detail::_count_dynamic_extents<_Extents...>::val) || + ((_Np == __detail::__count_dynamic_extents<_Extents...>::val) || (_Np == sizeof...(_Extents))) ) ) @@ -393,8 +393,8 @@ class extents : __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>(), + __detail::__construct_psa_from_dynamic_exts_array_tag_t<0>, + __detail::__construct_psa_from_all_exts_array_tag_t>(), __exts #if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) } @@ -473,7 +473,7 @@ class extents public: // (but not really) __MDSPAN_INLINE_FUNCTION static constexpr - extents __make_extents_impl(detail::__partially_static_sizes&& __bs) noexcept { + 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 @@ -482,7 +482,7 @@ class extents #if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) __base_t{ #endif - _CUDA_VSTD::move(__bs.template __with_tag()) + _CUDA_VSTD::move(__bs.template __with_tag<__detail::__extents_tag>()) #if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) } #endif @@ -505,7 +505,7 @@ class extents }; -namespace detail { +namespace __detail { template > struct __make_dextents; @@ -521,21 +521,21 @@ struct __make_dextents<_IndexType, 0, _CUDA_VSTD::extents<_IndexType, _ExtentsPa using type = _CUDA_VSTD::extents<_IndexType, _ExtentsPack...>; }; -} // end namespace detail +} // end namespace __detail template -using dextents = typename detail::__make_dextents<_IndexType, _Rank>::type; +using dextents = typename __detail::__make_dextents<_IndexType, _Rank>::type; #if defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) template extents(_IndexTypes...) // Workaround for nvcc - //-> extents()...>; + //-> extents()...>; // Adding "(void)" so that clang doesn't complain this is unused -> extents; #endif -namespace detail { +namespace __detail { template struct __is_extents : false_type {}; @@ -552,7 +552,7 @@ struct __extents_to_partially_static_sizes; template struct __extents_to_partially_static_sizes<_CUDA_VSTD::extents<_IndexType, _ExtentsPack...>> { - using type = detail::__partially_static_sizes< + using type = __detail::__partially_static_sizes< typename _CUDA_VSTD::extents<_IndexType, _ExtentsPack...>::index_type, size_t, _ExtentsPack...>; }; @@ -560,7 +560,7 @@ struct __extents_to_partially_static_sizes<_CUDA_VSTD::extents<_IndexType, _Exte template using __extents_to_partially_static_sizes_t = typename __extents_to_partially_static_sizes<_Extents>::type; -} // end namespace detail +} // end namespace __detail #endif // _LIBCUDACXX_STD_VER > 11 diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h index 4c6e29490c..ddd8315b28 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h @@ -75,7 +75,7 @@ class layout_left::mapping { 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."); + static_assert(__detail::__is_extents_v, "layout_left::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); template friend class mapping; diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h index fb9a5c89e0..9e472ba53c 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h @@ -75,7 +75,7 @@ class layout_right::mapping { 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."); + static_assert(__detail::__is_extents_v, "layout_right::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); template friend class mapping; diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h index a2baff5041..495fa4e805 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h @@ -87,7 +87,7 @@ struct layout_right { class mapping; }; -namespace detail { +namespace __detail { template constexpr bool __is_mapping_of = _CUDA_VSTD::is_same, _Mapping>::value; @@ -104,14 +104,14 @@ namespace detail { bool_constant<_Mp::is_always_unique()>::value; }; #endif -} // namespace detail +} // namespace __detail struct layout_stride { template class mapping #if !defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) - : private detail::__no_unique_address_emulation< - detail::__compressed_pair< + : private __detail::__no_unique_address_emulation< + __detail::__compressed_pair< _Extents, _CUDA_VSTD::array > @@ -126,7 +126,7 @@ struct layout_stride { 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."); + static_assert(__detail::__is_extents_v<_Extents>, "layout_stride::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); private: @@ -134,12 +134,12 @@ struct layout_stride { //---------------------------------------------------------------------------- using __strides_storage_t = _CUDA_VSTD::array;//_CUDA_VSTD::dextents; - using __member_pair_t = detail::__compressed_pair; + using __member_pair_t = __detail::__compressed_pair; #if defined(__MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) __MDSPAN_NO_UNIQUE_ADDRESS __member_pair_t __members; #else - using __base_t = detail::__no_unique_address_emulation<__member_pair_t>; + using __base_t = __detail::__no_unique_address_emulation<__member_pair_t>; #endif __MDSPAN_FORCE_INLINE_FUNCTION constexpr __strides_storage_t const& @@ -229,7 +229,7 @@ struct layout_stride { __MDSPAN_INLINE_FUNCTION static constexpr const __strides_storage_t fill_strides( - detail::__extents_to_partially_static_sizes_t< + __detail::__extents_to_partially_static_sizes_t< _CUDA_VSTD::dextents>&& __s) { return __strides_storage_t{static_cast(__s.template __get_n<_Idxs>())...}; } @@ -262,8 +262,8 @@ struct layout_stride { __MDSPAN_INLINE_FUNCTION static constexpr mapping __make_mapping( - detail::__extents_to_partially_static_sizes_t<_Extents>&& __exts, - detail::__extents_to_partially_static_sizes_t< + __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 @@ -369,7 +369,7 @@ struct layout_stride { class _StridedLayoutMapping, /* requires */ ( __MDSPAN_TRAIT(_CUDA_VSTD::is_constructible, extents_type, typename _StridedLayoutMapping::extents_type) && - detail::__is_mapping_of && + __detail::__is_mapping_of && _StridedLayoutMapping::is_always_unique() && _StridedLayoutMapping::is_always_strided() ) @@ -377,7 +377,7 @@ struct layout_stride { #else template requires( - detail::__layout_mapping_alike<_StridedLayoutMapping> && + __detail::__layout_mapping_alike<_StridedLayoutMapping> && __MDSPAN_TRAIT(_CUDA_VSTD::is_constructible, extents_type, typename _StridedLayoutMapping::extents_type) && _StridedLayoutMapping::is_always_unique() && _StridedLayoutMapping::is_always_strided() @@ -385,9 +385,9 @@ struct layout_stride { #endif __MDSPAN_CONDITIONAL_EXPLICIT( (!_CUDA_VSTD::is_convertible::value) && - (detail::__is_mapping_of || - detail::__is_mapping_of || - detail::__is_mapping_of) + (__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) @@ -482,7 +482,7 @@ struct layout_stride { __MDSPAN_TEMPLATE_REQUIRES( class _StridedLayoutMapping, /* requires */ ( - detail::__is_mapping_of && + __detail::__is_mapping_of && (extents_type::rank() == _StridedLayoutMapping::extents_type::rank()) && _StridedLayoutMapping::is_always_strided() ) @@ -490,7 +490,7 @@ struct layout_stride { #else template requires( - detail::__layout_mapping_alike<_StridedLayoutMapping> && + __detail::__layout_mapping_alike<_StridedLayoutMapping> && (extents_type::rank() == _StridedLayoutMapping::extents_type::rank()) && _StridedLayoutMapping::is_always_strided() ) @@ -521,7 +521,7 @@ struct layout_stride { __MDSPAN_TEMPLATE_REQUIRES( class _StridedLayoutMapping, /* requires */ ( - detail::__is_mapping_of && + __detail::__is_mapping_of && (extents_type::rank() == _StridedLayoutMapping::extents_type::rank()) && _StridedLayoutMapping::is_always_strided() ) diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h b/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h index 65fbc20b62..46582bd008 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/maybe_static_value.h @@ -69,7 +69,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD //============================================================================== -namespace detail { +namespace __detail { // static case template , "mdspan's Extents template parameter must be a specialization of _CUDA_VSTD::extents."); + 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 @@ -138,7 +138,7 @@ class mdspan // 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; + using __map_acc_pair_t = __detail::__compressed_pair; public: @@ -397,7 +397,7 @@ class mdspan private: - detail::__compressed_pair __members{}; + __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(); } diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h b/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h index f7e74ec03a..f09126395a 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/no_unique_address.h @@ -62,7 +62,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD #if _LIBCUDACXX_STD_VER > 11 -namespace detail { +namespace __detail { //============================================================================== @@ -136,7 +136,7 @@ struct __no_unique_address_emulation< //============================================================================== -} // end namespace detail +} // end namespace __detail #endif // _LIBCUDACXX_STD_VER > 11 diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h b/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h index 071553f34b..6c9caf1c1e 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/standard_layout_static_array.h @@ -68,7 +68,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD #if _LIBCUDACXX_STD_VER > 11 -namespace detail { +namespace __detail { //============================================================================== @@ -673,7 +673,7 @@ struct __partially_static_sizes #endif // __MDSPAN_PRESERVE_STATIC_LAYOUT -} // end namespace detail +} // end namespace __detail #endif // _LIBCUDACXX_STD_VER > 11 diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h b/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h index c738d7fc56..53656cb5cb 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/static_array.h @@ -68,7 +68,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD #if _LIBCUDACXX_STD_VER > 11 -namespace detail { +namespace __detail { //============================================================================== @@ -288,7 +288,7 @@ struct __partially_static_sizes : template using __partially_static_sizes_tagged = __partially_static_sizes; -} // end namespace detail +} // end namespace __detail #endif // _LIBCUDACXX_STD_VER > 11 diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h b/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h index 03ae723ab9..c741889f46 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/submdspan.h @@ -75,7 +75,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD #if _LIBCUDACXX_STD_VER > 11 -namespace detail { +namespace __detail { template struct __slice_wrap { @@ -475,9 +475,9 @@ constexpr auto _submdspan_impl( auto __handled = __MDSPAN_FOLD_ASSIGN_LEFT( ( - detail::__assign_op_slice_handler< + __detail::__assign_op_slice_handler< __index_t, - detail::preserve_layout_analysis<_LP> + __detail::preserve_layout_analysis<_LP> >{ __partially_static_sizes<__index_t, size_t>{}, __partially_static_sizes<__index_t, size_t>{}, @@ -485,7 +485,7 @@ constexpr auto _submdspan_impl( } ), /* = ... = */ - detail::__wrap_slice< + __detail::__wrap_slice< _Exts, dynamic_extent >( __slices, __src.extents().template __extent<_Idxs>(), @@ -534,9 +534,9 @@ __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( __src, __MDSPAN_FOLD_ASSIGN_LEFT( ( - detail::__assign_op_slice_handler< + __detail::__assign_op_slice_handler< size_t, - detail::preserve_layout_analysis<_LP> + __detail::preserve_layout_analysis<_LP> >{ __partially_static_sizes<_ST, size_t>{}, __partially_static_sizes<_ST, size_t>{}, @@ -544,7 +544,7 @@ __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( } ), /* = ... = */ - detail::__wrap_slice< + __detail::__wrap_slice< _Exts, dynamic_extent >( __slices, __src.extents().template __extent<_Idxs>(), __src.mapping().stride(_Idxs) @@ -564,7 +564,7 @@ struct _is_layout_stride< > : true_type { }; -} // namespace detail +} // namespace __detail //============================================================================== @@ -574,7 +574,7 @@ __MDSPAN_TEMPLATE_REQUIRES( ( __MDSPAN_TRAIT(_CUDA_VSTD::is_same, _LP, layout_left) || __MDSPAN_TRAIT(_CUDA_VSTD::is_same, _LP, layout_right) - || detail::_is_layout_stride<_LP>::value + || __detail::_is_layout_stride<_LP>::value ) && __MDSPAN_FOLD_AND(( __MDSPAN_TRAIT(_CUDA_VSTD::is_convertible, _SliceSpecs, size_t) @@ -593,7 +593,7 @@ __MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( ), ( /* return */ - detail::_submdspan_impl(_CUDA_VSTD::make_index_sequence{}, __src, __slices...) /*;*/ + __detail::_submdspan_impl(_CUDA_VSTD::make_index_sequence{}, __src, __slices...) /*;*/ ) ) /* clang-format: on */ diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h b/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h index 87d8fae5ad..481eceb3d7 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/type_list.h @@ -60,7 +60,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD //============================================================================== -namespace detail { +namespace __detail { template struct __type_list { static constexpr auto __size = sizeof...(_Ts); }; @@ -121,7 +121,7 @@ struct __type_at<3, __type_list<_T0, _T1, _T2, _T3, _Ts...>> { }; -} // namespace detail +} // namespace __detail //============================================================================== From 24702f02a2736bf42b21a552fed1eb6018f29ba4 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Mon, 13 Feb 2023 20:25:05 +0100 Subject: [PATCH 7/7] Bring back all the tests --- .../views/mdspan/foo_customizations.hpp | 228 ++++++++++++++++++ .../access.pass.cpp | 26 ++ .../copy.pass.cpp | 29 +++ .../offset.pass.cpp | 26 ++ .../mdspan.extents.cmp/compare.pass.cpp | 57 +++++ .../mdspan/mdspan.extents.cons/array.pass.cpp | 66 +++++ .../convertible_to_size_t.pass.cpp | 44 ++++ .../mdspan/mdspan.extents.cons/copy.pass.cpp | 59 +++++ .../mdspan.extents.cons/default.pass.cpp | 42 ++++ .../mdspan.extents.cons/param_pack.pass.cpp | 88 +++++++ .../mdspan/mdspan.extents.cons/span.pass.cpp | 67 +++++ .../mdspan/mdspan.extents.obs/extent.pass.cpp | 64 +++++ .../mdspan/mdspan.extents.obs/rank.pass.cpp | 60 +++++ .../mdspan.extents.obs/static_extent.pass.cpp | 63 +++++ .../extents_element.fail.cpp | 42 ++++ .../index_type.fail.cpp | 42 ++++ .../mdspan.extents.util/extents_util.hpp | 50 ++++ .../mdspan.layout.left.cons/copy.pass.cpp | 47 ++++ .../mdspan.layout.left.cons/ctad.pass.cpp | 38 +++ .../layout_right_init.pass.cpp | 52 ++++ .../layout_stride_init.pass.cpp | 47 ++++ .../list_init.pass.cpp | 72 ++++++ .../mdspan.layout.left.obs/compare.fail.cpp | 32 +++ .../mdspan.layout.left.obs/compare.pass.cpp | 57 +++++ .../mdspan.layout.left.obs/extents.pass.cpp | 47 ++++ .../is_exhaustive.pass.cpp | 37 +++ .../is_strided.pass.cpp | 27 +++ .../mdspan.layout.left.obs/is_unique.pass.cpp | 37 +++ .../mdspan.layout.left.obs/paren_op.pass.cpp | 71 ++++++ .../required_span_size.pass.cpp | 43 ++++ .../mdspan.layout.left.obs/stride.pass.cpp | 52 ++++ .../mdspan.layout.right.cons/copy.pass.cpp | 47 ++++ .../mdspan.layout.right.cons/ctad.pass.cpp | 39 +++ .../layout_left_init.pass.cpp | 52 ++++ .../layout_stride_init.pass.cpp | 47 ++++ .../list_init.pass.cpp | 69 ++++++ .../mdspan.layout.right.obs/compare.fail.cpp | 32 +++ .../mdspan.layout.right.obs/compare.pass.cpp | 57 +++++ .../mdspan.layout.right.obs/extents.pass.cpp | 47 ++++ .../is_exhaustive.pass.cpp | 37 +++ .../is_strided.pass.cpp | 27 +++ .../is_unique.pass.cpp | 37 +++ .../mdspan.layout.right.obs/paren_op.pass.cpp | 71 ++++++ .../required_span_size.pass.cpp | 43 ++++ .../mdspan.layout.right.obs/stride.pass.cpp | 52 ++++ .../mdspan.layout.stride.cons/ctad.pass.cpp | 40 +++ .../list_init.pass.cpp | 66 +++++ .../mdspan.layout.stride.obs/compare.fail.cpp | 35 +++ .../mdspan.layout.stride.obs/compare.pass.cpp | 83 +++++++ .../mdspan.layout.stride.obs/extents.pass.cpp | 31 +++ .../is_exhaustive.pass.cpp | 75 ++++++ .../is_strided.pass.cpp | 27 +++ .../is_unique.pass.cpp | 39 +++ .../paren_op.pass.cpp | 83 +++++++ .../required_span_size.pass.cpp | 62 +++++ .../mdspan.layout.stride.obs/stride.pass.cpp | 65 +++++ .../mdspan.layout.stride.obs/strides.pass.cpp | 52 ++++ .../mdspan/mdspan.layout.util/layout_util.hpp | 168 +++++++++++++ .../array_init_extents.pass.cpp | 104 ++++++++ .../mdspan/mdspan.mdspan.cons/copy.pass.cpp | 72 ++++++ .../mdspan.mdspan.cons/ctad_c_array.pass.cpp | 49 ++++ .../ctad_const_c_array.pass.cpp | 39 +++ .../mdspan.mdspan.cons/ctad_copy.pass.cpp | 34 +++ .../mdspan.mdspan.cons/ctad_extents.pass.cpp | 75 ++++++ .../ctad_extents_pack.pass.cpp | 36 +++ .../mdspan.mdspan.cons/ctad_layouts.pass.cpp | 57 +++++ .../mdspan.mdspan.cons/ctad_mapping.pass.cpp | 48 ++++ .../mdspan.mdspan.cons/ctad_pointer.pass.cpp | 55 +++++ .../custom_accessor.pass.cpp | 39 +++ .../mdspan.mdspan.cons/custom_layout.pass.cpp | 35 +++ .../mdspan.mdspan.cons/data_c_array.pass.cpp | 39 +++ .../mdspan.mdspan.cons/default.pass.cpp | 37 +++ .../mdspan.mdspan.cons/extents.pass.cpp | 80 ++++++ .../mdspan.mdspan.cons/extents_pack.pass.cpp | 111 +++++++++ .../list_init_layout_left.pass.cpp | 38 +++ .../list_init_layout_right.pass.cpp | 38 +++ .../list_init_layout_stride.pass.cpp | 39 +++ .../mdspan.mdspan.cons/mapping.pass.cpp | 76 ++++++ .../span_init_extents.pass.cpp | 96 ++++++++ .../mdspan.mdspan.members/accessor.pass.cpp | 31 +++ .../brackets_op.pass.cpp | 161 +++++++++++++ .../data_handle.pass.cpp | 68 ++++++ .../mdspan.mdspan.members/empty.pass.cpp | 49 ++++ .../mdspan.mdspan.members/extent.pass.cpp | 66 +++++ .../mdspan.mdspan.members/extents.pass.cpp | 28 +++ .../is_exhaustive.pass.cpp | 49 ++++ .../mdspan.mdspan.members/is_strided.pass.cpp | 48 ++++ .../mdspan.mdspan.members/is_unique.pass.cpp | 44 ++++ .../mdspan.mdspan.members/mapping.pass.cpp | 44 ++++ .../mdspan.mdspan.members/rank.pass.cpp | 52 ++++ .../mdspan.mdspan.members/size.pass.cpp | 47 ++++ .../mdspan.mdspan.members/stride.pass.cpp | 59 +++++ .../mdspan.mdspan.members/swap.pass.cpp | 87 +++++++ .../mdspan/mdspan.mdspan.util/mdspan_util.hpp | 15 ++ .../dim_reduction.pass.cpp | 73 ++++++ .../pair_init.pass.cpp | 32 +++ .../return_type.pass.cpp | 140 +++++++++++ .../tuple_init.pass.cpp | 32 +++ .../containers/views/mdspan/my_accessor.hpp | 37 +++ .../std/containers/views/mdspan/my_int.hpp | 45 ++++ 100 files changed, 5599 insertions(+) create mode 100644 libcxx/test/std/containers/views/mdspan/foo_customizations.hpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/access.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/copy.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/offset.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.cmp/compare.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/array.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/convertible_to_size_t.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/default.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/param_pack.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/span.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/extent.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/rank.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/static_extent.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/extents_element.fail.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/index_type.fail.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.extents.util/extents_util.hpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/ctad.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_right_init.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_stride_init.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/list_init.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.fail.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/extents.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_exhaustive.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_strided.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_unique.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/paren_op.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/required_span_size.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/stride.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/ctad.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_left_init.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_stride_init.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/list_init.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.fail.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/extents.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_exhaustive.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_strided.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_unique.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/paren_op.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/required_span_size.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/stride.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/ctad.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/list_init.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.fail.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/extents.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_exhaustive.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_strided.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_unique.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/paren_op.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/required_span_size.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/stride.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/strides.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.layout.util/layout_util.hpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/array_init_extents.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_c_array.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_const_c_array.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_copy.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents_pack.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_layouts.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_mapping.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_pointer.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_accessor.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_layout.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/data_c_array.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/default.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents_pack.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_left.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_right.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_stride.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/mapping.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/span_init_extents.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/accessor.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/brackets_op.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/data_handle.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/empty.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extent.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extents.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_exhaustive.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_strided.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_unique.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/mapping.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/rank.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/size.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/stride.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/swap.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.mdspan.util/mdspan_util.hpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/dim_reduction.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/pair_init.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/return_type.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/tuple_init.pass.cpp create mode 100644 libcxx/test/std/containers/views/mdspan/my_accessor.hpp create mode 100644 libcxx/test/std/containers/views/mdspan/my_int.hpp diff --git a/libcxx/test/std/containers/views/mdspan/foo_customizations.hpp b/libcxx/test/std/containers/views/mdspan/foo_customizations.hpp new file mode 100644 index 0000000000..f359b46d2a --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/foo_customizations.hpp @@ -0,0 +1,228 @@ +#ifndef _FOO_CUSTOMIZATIONS_HPP +#define _FOO_CUSTOMIZATIONS_HPP + +// Taken from the reference implementation repo + +namespace Foo { + template + struct foo_ptr { + T* data; + __MDSPAN_HOST_DEVICE + constexpr foo_ptr(T* ptr):data(ptr) {} + }; + + template + struct foo_accessor { + using offset_policy = foo_accessor; + using element_type = T; + using reference = T&; + using data_handle_type = foo_ptr; + + __MDSPAN_INLINE_FUNCTION + constexpr foo_accessor(int* ptr = nullptr) noexcept { flag = ptr; } + + template + __MDSPAN_INLINE_FUNCTION + constexpr foo_accessor(std::default_accessor) noexcept { flag = nullptr; } + + template + __MDSPAN_INLINE_FUNCTION + constexpr foo_accessor(foo_accessor other) noexcept { flag = other.flag; } + + + constexpr reference access(data_handle_type p, size_t i) const noexcept { + return p.data[i]; + } + + constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept { + return data_handle_type(p.data+i); + } + int* flag; + + friend constexpr void swap(foo_accessor& x, foo_accessor& y) { + x.flag[0] = 99; + y.flag[0] = 77; + std::swap(x.flag, y.flag); + } + }; + +struct layout_foo { + template + class mapping; +}; + +template +class layout_foo::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_foo; + private: + + static_assert(std::detail::__is_extents_v, + "layout_foo::mapping must be instantiated with a specialization of std::extents."); + static_assert(extents_type::rank() < 3, "layout_foo only supports 0D, 1D and 2D"); + + template + friend class mapping; + + public: + + //-------------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping(mapping const&) noexcept = default; + + __MDSPAN_HOST_DEVICE + constexpr mapping(extents_type const& __exts) noexcept + :__extents(__exts) + { } + + __MDSPAN_TEMPLATE_REQUIRES( + class OtherExtents, + /* requires */ ( + __MDSPAN_TRAIT(std::is_constructible, extents_type, OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!std::is_convertible::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION constexpr + mapping(mapping 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 */ ( + __MDSPAN_TRAIT(std::is_constructible, extents_type, OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!std::is_convertible::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION constexpr + mapping(std::layout_right::mapping const& other) noexcept // NOLINT(google-explicit-constructor) + :__extents(other.extents()) + {} + + __MDSPAN_TEMPLATE_REQUIRES( + class OtherExtents, + /* requires */ ( + __MDSPAN_TRAIT(std::is_constructible, extents_type, OtherExtents) && + (extents_type::rank() <= 1) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!std::is_convertible::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION constexpr + mapping(std::layout_left::mapping const& other) noexcept // NOLINT(google-explicit-constructor) + :__extents(other.extents()) + {} + + __MDSPAN_TEMPLATE_REQUIRES( + class OtherExtents, + /* requires */ ( + __MDSPAN_TRAIT(std::is_constructible, extents_type, OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((extents_type::rank() > 0)) + __MDSPAN_INLINE_FUNCTION constexpr + mapping(std::layout_stride::mapping const& other) // NOLINT(google-explicit-constructor) + :__extents(other.extents()) + { + /* + * TODO: check precondition + * other.required_span_size() is a representable value of type index_type + */ + #ifndef __CUDA_ARCH__ + size_t stride = 1; + for(rank_type r=__extents.rank(); r>0; r--) { + assert(stride == other.stride(r-1)); + //if(stride != other.stride(r-1)) + // throw std::runtime_error("Assigning layout_stride to layout_foo with invalid strides."); + stride *= __extents.extent(r-1); + } + #endif + } + + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr_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_INLINE_FUNCTION + constexpr index_type operator() () const noexcept { return index_type(0); } + + template + __MDSPAN_INLINE_FUNCTION + constexpr index_type operator()(Indx0 idx0) const noexcept { + return static_cast(idx0); + } + + template + __MDSPAN_INLINE_FUNCTION + constexpr index_type operator()(Indx0 idx0, Indx1 idx1) const noexcept { + return static_cast(idx0 * __extents.extent(0) + idx1); + } + + __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_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 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 const& rhs) noexcept { + return lhs.extents() != rhs.extents(); + } +#endif + + // Not really public, but currently needed to implement fully constexpr useable submdspan: + template + constexpr index_type __get_stride(std::extents, std::integer_sequence) const { + return __MDSPAN_FOLD_TIMES_RIGHT((Idx>N? __extents.template __extent():1),1); + } + template + constexpr index_type __stride() const noexcept { + return __get_stride(__extents, std::make_index_sequence()); + } + +private: + __MDSPAN_NO_UNIQUE_ADDRESS extents_type __extents{}; + +}; + +} +#endif + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/access.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/access.pass.cpp new file mode 100644 index 0000000000..aa8afc285c --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/access.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + { + using element_t = int; + std::array d{42,43}; + std::default_accessor a; + + assert( a.access( d.data(), 0 ) == 42 ); + assert( a.access( d.data(), 1 ) == 43 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/copy.pass.cpp new file mode 100644 index 0000000000..240f66c920 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/copy.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + { + using element_t = int; + std::array d{42,43}; + std::default_accessor a0; + std::default_accessor a(a0); + + assert( a.access( d.data(), 0 ) == 42 ); + assert( a.access( d.data(), 1 ) == 43 ); + assert( a.offset( d.data(), 0 ) == d.data() ); + assert( a.offset( d.data(), 1 ) == d.data() + 1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/offset.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/offset.pass.cpp new file mode 100644 index 0000000000..5a1679b8e7 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/offset.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + { + using element_t = int; + std::array d{42,43}; + std::default_accessor a; + + assert( a.offset( d.data(), 0 ) == d.data() ); + assert( a.offset( d.data(), 1 ) == d.data() + 1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cmp/compare.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cmp/compare.pass.cpp new file mode 100644 index 0000000000..4341f78690 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cmp/compare.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + using index_t = size_t; + + std::extents< index_t, 10 > e0; + std::extents< index_t, 10 > e1; + + assert( e0 == e1 ); + } + + { + using index_t = size_t; + + std::extents< index_t, 10 > e0; + std::extents< index_t, dyn > e1{ 10 }; + + assert( e0 == e1 ); + } + + { + using index_t = size_t; + + std::extents< index_t, 10 > e0; + std::extents< index_t, 10, 10 > e1; + + assert( e0 != e1 ); + } + + { + using index0_t = size_t; + using index1_t = uint8_t; + + std::extents< index0_t, 10 > e0; + std::extents< index1_t, 10 > e1; + + assert( e0 == e1 ); + } + + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/array.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/array.pass.cpp new file mode 100644 index 0000000000..6f3805aed3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/array.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" +#include "../my_int.hpp" + +// TYPED_TEST(TestExtents, array_ctor) +template +void test_array_con() +{ + using TestFixture = TestExtents; + TestFixture t; + + auto e = typename TestFixture::extents_type(t.dyn_sizes); + assert(e == t.exts); +} + +template< class T, class IndexType, size_t N, class = void > +struct is_array_cons_avail : std::false_type {}; + +template< class T, class IndexType, size_t N > +struct is_array_cons_avail< T + , IndexType + , N + , std::enable_if_t< std::is_same< decltype( T{ std::declval>() } ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class IndexType, size_t N > +constexpr bool is_array_cons_avail_v = is_array_cons_avail< T, IndexType, N >::value; + +int main(int, char**) +{ + test_array_con< std::tuple_element_t< 0, extents_test_types > >(); + test_array_con< std::tuple_element_t< 1, extents_test_types > >(); + test_array_con< std::tuple_element_t< 2, extents_test_types > >(); + test_array_con< std::tuple_element_t< 3, extents_test_types > >(); + test_array_con< std::tuple_element_t< 4, extents_test_types > >(); + test_array_con< std::tuple_element_t< 5, extents_test_types > >(); + + static_assert( is_array_cons_avail_v< std::dextents< int,2>, int , 2 > == true , "" ); + + static_assert( is_array_cons_avail_v< std::dextents< int,2>, my_int, 2 > == true , "" ); + + // Constraint: rank consistency + static_assert( is_array_cons_avail_v< std::dextents< int,1>, int , 2 > == false, "" ); + + // Constraint: convertibility + static_assert( is_array_cons_avail_v< std::dextents, my_int_non_convertible , 1 > == false, "" ); + + // Constraint: nonthrow-constructibility + static_assert( is_array_cons_avail_v< std::dextents< int,1>, my_int_non_nothrow_constructible, 1 > == false, "" ); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/convertible_to_size_t.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/convertible_to_size_t.pass.cpp new file mode 100644 index 0000000000..9ec1e4d443 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/convertible_to_size_t.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +void check( std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +int main(int, char**) +{ + // TEST(TestExtentsCtorStdArrayConvertibleToSizeT, test_extents_ctor_std_array_convertible_to_size_t) + { + std::array i{2, 2}; + std::dextents e{i}; + + check( e ); + } + + // TEST(TestExtentsCtorStdArrayConvertibleToSizeT, test_extents_ctor_std_span_convertible_to_size_t) + { + std::array i{2, 2}; + std::span s(i.data(),2); + std::dextents e{s}; + + check( e ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/copy.pass.cpp new file mode 100644 index 0000000000..526b2d219a --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/copy.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +// TYPED_TEST(TestExtents, copy_ctor) +template +void test_copy_con() +{ + using TestFixture = TestExtents; + TestFixture t; + + typename TestFixture::extents_type e { t.exts }; + assert(e == t.exts); +} + +template< class T1, class T2, class = void > +struct is_copy_cons_avail : std::false_type {}; + +template< class T1, class T2 > +struct is_copy_cons_avail< T1 + , T2 + , std::enable_if_t< std::is_same< decltype( T1{ std::declval() } ) + , T1 + >::value + > + > : std::true_type {}; + +template< class T1, class T2 > +constexpr bool is_copy_cons_avail_v = is_copy_cons_avail< T1, T2 >::value; + +int main(int, char**) +{ + test_copy_con< std::tuple_element_t< 0, extents_test_types > >(); + test_copy_con< std::tuple_element_t< 1, extents_test_types > >(); + test_copy_con< std::tuple_element_t< 2, extents_test_types > >(); + test_copy_con< std::tuple_element_t< 3, extents_test_types > >(); + test_copy_con< std::tuple_element_t< 4, extents_test_types > >(); + test_copy_con< std::tuple_element_t< 5, extents_test_types > >(); + + static_assert( is_copy_cons_avail_v< std::extents, std::extents > == true , "" ); + + // Constraint: rank consistency + static_assert( is_copy_cons_avail_v< std::extents, std::extents > == false, "" ); + + // Constraint: extents consistency + static_assert( is_copy_cons_avail_v< std::extents, std::extents > == false, "" ); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/default.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/default.pass.cpp new file mode 100644 index 0000000000..13fc88c141 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/default.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +// TYPED_TEST(TestExtents, default_ctor) +template +void test_default_con() +{ + using TestFixture = TestExtents; + + auto e = typename TestFixture::extents_type(); + auto e2 = typename TestFixture::extents_type{}; + assert( e == e2 ); + + for (size_t r = 0; r < e.rank(); ++r) + { + bool is_dynamic = (e.static_extent(r) == std::dynamic_extent); + assert( e.extent(r) == ( is_dynamic ? 0 : e.static_extent(r) ) ); + } +} + +int main(int, char**) +{ + test_default_con< std::tuple_element_t< 0, extents_test_types > >(); + test_default_con< std::tuple_element_t< 1, extents_test_types > >(); + test_default_con< std::tuple_element_t< 2, extents_test_types > >(); + test_default_con< std::tuple_element_t< 3, extents_test_types > >(); + test_default_con< std::tuple_element_t< 4, extents_test_types > >(); + test_default_con< std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/param_pack.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/param_pack.pass.cpp new file mode 100644 index 0000000000..9d900619e3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/param_pack.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../my_int.hpp" + +void check( std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +template< class, class T, class... IndexTypes > +struct is_param_pack_cons_avail : std::false_type {}; + +template< class T, class... IndexTypes > +struct is_param_pack_cons_avail< std::enable_if_t< std::is_same< decltype( T{ std::declval()... } ) + , T + >::value + > + , T + , IndexTypes... + > : std::true_type {}; + +template< class T, class... IndexTypes > +constexpr bool is_param_pack_cons_avail_v = is_param_pack_cons_avail< void, T, IndexTypes... >::value; + +int main(int, char**) +{ + { + std::dextents e{2, 2}; + + check( e ); + } + + { + std::dextents e(2, 2); + + check( e ); + } + +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + { + std::extents e{2, 2}; + + check( e ); + } + + { + std::extents e(2, 2); + + check( e ); + } +#endif + + { + std::dextents e{2, 2}; + + check( e ); + } + + static_assert( is_param_pack_cons_avail_v< std::dextents, int , int > == true , "" ); + + static_assert( is_param_pack_cons_avail_v< std::dextents, my_int, my_int > == true , "" ); + + // Constraint: rank consistency + static_assert( is_param_pack_cons_avail_v< std::dextents, int , int > == false, "" ); + + // Constraint: convertibility + static_assert( is_param_pack_cons_avail_v< std::dextents, my_int_non_convertible > == false, "" ); + + // Constraint: nonthrow-constructibility + static_assert( is_param_pack_cons_avail_v< std::dextents, my_int_non_nothrow_constructible > == false, "" ); + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/span.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/span.pass.cpp new file mode 100644 index 0000000000..cbe0b4f0b0 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/span.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" +#include "../my_int.hpp" + +// TYPED_TEST(TestExtents, array_ctor) +template +void test_span_con() +{ + using TestFixture = TestExtents; + TestFixture t; + + auto s = std::span( t.dyn_sizes ); + auto e = typename TestFixture::extents_type(s); + assert(e == t.exts); +} + +template< class T, class IndexType, size_t N, class = void > +struct is_span_cons_avail : std::false_type {}; + +template< class T, class IndexType, size_t N > +struct is_span_cons_avail< T + , IndexType + , N + , std::enable_if_t< std::is_same< decltype( T{ std::declval>() } ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class IndexType, size_t N > +constexpr bool is_span_cons_avail_v = is_span_cons_avail< T, IndexType, N >::value; + +int main(int, char**) +{ + test_span_con< std::tuple_element_t< 0, extents_test_types > >(); + test_span_con< std::tuple_element_t< 1, extents_test_types > >(); + test_span_con< std::tuple_element_t< 2, extents_test_types > >(); + test_span_con< std::tuple_element_t< 3, extents_test_types > >(); + test_span_con< std::tuple_element_t< 4, extents_test_types > >(); + test_span_con< std::tuple_element_t< 5, extents_test_types > >(); + + static_assert( is_span_cons_avail_v< std::dextents, int , 2 > == true , "" ); + + static_assert( is_span_cons_avail_v< std::dextents, my_int, 2 > == true , "" ); + + // Constraint: rank consistency + static_assert( is_span_cons_avail_v< std::dextents, int , 2 > == false, "" ); + + // Constraint: convertibility + static_assert( is_span_cons_avail_v< std::dextents, my_int_non_convertible , 1 > == false, "" ); + + // Constraint: nonthrow-constructibility + static_assert( is_span_cons_avail_v< std::dextents, my_int_non_nothrow_constructible, 1 > == false, "" ); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/extent.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/extent.pass.cpp new file mode 100644 index 0000000000..e0d7bba343 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/extent.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +template struct TestExtentsExtent; +template +struct TestExtentsExtent< TEST_TYPE > +: public TestExtents< TEST_TYPE > +{ + using base = TestExtents; + using extents_type = typename TestExtents::extents_type; + + void test_extent() + { + size_t result[extents_type::rank()]; + + extents_type _exts(DynamicSizes...); + for(size_t r=0; r<_exts.rank(); r++ ) + { + result[r] = _exts.extent(r); + } + + int dyn_count = 0; + for(size_t r=0; r +void test_extent() +{ + TestExtentsExtent test; + + test.test_extent(); +} + +int main(int, char**) +{ + test_extent< std::tuple_element_t< 0, extents_test_types > >(); + test_extent< std::tuple_element_t< 1, extents_test_types > >(); + test_extent< std::tuple_element_t< 2, extents_test_types > >(); + test_extent< std::tuple_element_t< 3, extents_test_types > >(); + test_extent< std::tuple_element_t< 4, extents_test_types > >(); + test_extent< std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/rank.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/rank.pass.cpp new file mode 100644 index 0000000000..de02ff117d --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/rank.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +template struct TestExtentsRank; +template +struct TestExtentsRank< TEST_TYPE > +: public TestExtents< TEST_TYPE > +{ + using base = TestExtents; + using extents_type = typename TestExtents::extents_type; + + void test_rank() + { + size_t result[2]; + + extents_type _exts(DynamicSizes...); + // Silencing an unused warning in nvc++ the condition will never be true + size_t dyn_val = _exts.rank()>0?static_cast(_exts.extent(0)):1; + result[0] = dyn_val > 1e9 ? dyn_val : _exts.rank(); + result[1] = _exts.rank_dynamic(); + + assert( result[0] == base::static_sizes.size() ); + assert( result[1] == base:: dyn_sizes.size() ); + + // Makes sure that `rank()` returns a constexpr + std::array a; + } +}; + +// TYPED_TEST(TestExtents, rank) +template +void test_rank() +{ + TestExtentsRank test; + + test.test_rank(); +} + +int main(int, char**) +{ + test_rank< std::tuple_element_t< 0, extents_test_types > >(); + test_rank< std::tuple_element_t< 1, extents_test_types > >(); + test_rank< std::tuple_element_t< 2, extents_test_types > >(); + test_rank< std::tuple_element_t< 3, extents_test_types > >(); + test_rank< std::tuple_element_t< 4, extents_test_types > >(); + test_rank< std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/static_extent.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/static_extent.pass.cpp new file mode 100644 index 0000000000..ed942b540e --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/static_extent.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +template struct TestExtentsStaticExtent; +template +struct TestExtentsStaticExtent< TEST_TYPE > +: public TestExtents< TEST_TYPE > +{ + using base = TestExtents; + using extents_type = typename TestExtents::extents_type; + + void test_static_extent() + { + size_t result[extents_type::rank()]; + + extents_type _exts(DynamicSizes...); + for(size_t r=0; r<_exts.rank(); r++) + { + // Silencing an unused warning in nvc++ the condition will never be true + size_t dyn_val = static_cast(_exts.extent(r)); + result[r] = dyn_val > 1e9 ? dyn_val : _exts.static_extent(r); + } + + for(size_t r=0; r +void test_static_extent() +{ + TestExtentsStaticExtent test; + + test.test_static_extent(); +} + +int main(int, char**) +{ + test_static_extent< std::tuple_element_t< 0, extents_test_types > >(); + test_static_extent< std::tuple_element_t< 1, extents_test_types > >(); + test_static_extent< std::tuple_element_t< 2, extents_test_types > >(); + test_static_extent< std::tuple_element_t< 3, extents_test_types > >(); + test_static_extent< std::tuple_element_t< 4, extents_test_types > >(); + test_static_extent< std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/extents_element.fail.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/extents_element.fail.cpp new file mode 100644 index 0000000000..990ff6f136 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/extents_element.fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +void check( std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +struct dummy {}; + +int main(int, char**) +{ + { + std::dextents e{2 , 2}; + + check( e ); + } + + // Mandate: each element of Extents is either equal to dynamic_extent, or is representable as a value of type IndexType + { + + std::dextents e{dummy{}, 2}; + + check( e ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/index_type.fail.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/index_type.fail.cpp new file mode 100644 index 0000000000..019081d9eb --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/index_type.fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +void check( std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +struct dummy {}; + +int main(int, char**) +{ + { + std::dextents e{2, 2}; + + check( e ); + } + + // Mandate: IndexType is a signed or unsigned integer type + { + + std::dextents e{2, 2}; + + check( e ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.util/extents_util.hpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.util/extents_util.hpp new file mode 100644 index 0000000000..b076ddb620 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.util/extents_util.hpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include + +#define TEST_TYPE \ + std::tuple < \ + std::extents, \ + std::integer_sequence \ + > + + +template struct TestExtents; +template +struct TestExtents< + std::tuple< + std::extents, + std::integer_sequence + > +> +{ + using extents_type = std::extents; + // Double Braces here to make it work with GCC 5 + // Otherwise: "error: array must be initialized with a brace-enclosed initializer" + const std::array static_sizes {{ Extents... }}; + const std::array dyn_sizes {{ DynamicSizes... }}; + extents_type exts { DynamicSizes... }; +}; + +template +using _sizes = std::integer_sequence; +template +using _exts = std::extents; + +constexpr auto dyn = std::dynamic_extent; + +using extents_test_types = std::tuple< + std::tuple< _exts< 10 >, _sizes< > > + , std::tuple< _exts, _sizes<10 > > + , std::tuple< _exts< 10, 3>, _sizes< > > + , std::tuple< _exts, _sizes<10 > > + , std::tuple< _exts< 10, dyn>, _sizes< 3 > > + , std::tuple< _exts, _sizes<10, 3> > +>; diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/copy.pass.cpp new file mode 100644 index 0000000000..7f9a6425f5 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/copy.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + + std::layout_left::mapping> m0{std::dextents{16,32}}; + std::layout_left::mapping> m {m0}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_left::mapping>; + using mapping1_t = std::layout_left::mapping>; + using mappingd_t = std::layout_left::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/ctad.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/ctad.pass.cpp new file mode 100644 index 0000000000..cd862d2fb9 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/ctad.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_left::mapping m{std::extents{16, 32}}; + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_right_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_right_init.pass.cpp new file mode 100644 index 0000000000..68abb6dba0 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_right_init.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_right::mapping> m_right{std::dextents{16}}; + std::layout_left ::mapping> m( m_right ); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 1 ); + assert( m.extents().rank_dynamic() == 1 ); + assert( m.extents().extent(0) == 16 ); + assert( m.stride(0) == 1 ); + } + + // Constraint: extents_type::rank() <= 1 is true + { + using mapping0_t = std::layout_right::mapping>; + using mapping1_t = std::layout_left ::mapping>; + + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_right::mapping>; + using mapping1_t = std::layout_left ::mapping>; + using mappingd_t = std::layout_left ::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_stride_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_stride_init.pass.cpp new file mode 100644 index 0000000000..7b73b354fd --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_stride_init.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::array a{1,16}; + std::layout_stride::mapping> m_stride{std::dextents{16, 32}, a}; + std::layout_left ::mapping> m( m_stride ); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_stride::mapping>; + using mapping1_t = std::layout_left ::mapping>; + using mappingd_t = std::layout_left::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/list_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/list_init.pass.cpp new file mode 100644 index 0000000000..4b5be506f5 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/list_init.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template +using test_left_type = std::tuple< + typename std::layout_left::template mapping, + std::integer_sequence +>; + +void typed_test_default_ctor_left() +{ + typed_test_default_ctor< test_left_type< std::extents > >(); + typed_test_default_ctor< test_left_type< std::extents, 10 > >(); + typed_test_default_ctor< test_left_type< std::extents, 5 > >(); + typed_test_default_ctor< test_left_type< std::extents, 10 > >(); + typed_test_default_ctor< test_left_type< std::extents > >(); +} + +void typed_test_compatible_left() +{ + typed_test_compatible< test_left_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_default_ctor_left(); + + typed_test_compatible_left(); + + // TEST(TestLayoutLeftListInitialization, test_layout_left_extent_initialization) + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_left::mapping> m{std::dextents{16, 32}}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.fail.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.fail.cpp new file mode 100644 index 0000000000..b4ecdce7e8 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.fail.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = std::extents< index_t, 64, 128 >; + using ext3d_t = std::extents< index_t, 64, 128, 2 >; + + // Constraint: rank consistency + // This constraint is implemented in a different way in the reference implementation. There will be an overload function + // match but it will return false if the ranks are not consistent + { + constexpr ext2d_t e0; + constexpr ext3d_t e1; + constexpr std::layout_left::mapping m0{ e0 }; + constexpr std::layout_left::mapping m1{ e1 }; + + static_assert( m0 == m1, "" ); // expected-error + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.pass.cpp new file mode 100644 index 0000000000..6c996f4aef --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +void typed_test_compare_left() +{ + typed_test_compare< test_left_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_compare_left(); + + using index_t = size_t; + using ext1d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{64, 128}; + std::layout_left::mapping m0{ e }; + std::layout_left::mapping m { m0 }; + + assert( m == m0 ); + } + + { + ext2d_t e0{64, 128}; + ext2d_t e1{16, 32}; + std::layout_left::mapping m0{ e0 }; + std::layout_left::mapping m1{ e1 }; + + assert( m0 != m1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/extents.pass.cpp new file mode 100644 index 0000000000..9eb8ebe9f0 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/extents.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext1d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{16, 32}; + std::layout_left::mapping m{e}; + + assert( m.extents() == e ); + } + + { + ext1d_t e{16}; + std::layout_right::mapping m_right{e}; + std::layout_left ::mapping m{m_right}; + + assert( m.extents() == e ); + } + + { + ext2d_t e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping m_stride{e, a}; + std::layout_left ::mapping m{m_stride}; + + assert( m.extents() == e ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_exhaustive.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..951ed1c3c5 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_exhaustive.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_left::mapping> m; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + + { + std::extents e{16, 32}; + std::layout_left::mapping> m{ e }; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_strided.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_strided.pass.cpp new file mode 100644 index 0000000000..4bb5564c3b --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_strided.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::extents e{64, 128}; + std::layout_left::mapping> m{ e }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_unique.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_unique.pass.cpp new file mode 100644 index 0000000000..6af01adda0 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_unique.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_left::mapping> m; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + + { + std::extents e{16, 32}; + std::layout_left::mapping> m{ e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/paren_op.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/paren_op.pass.cpp new file mode 100644 index 0000000000..1166a3a224 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/paren_op.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../my_int.hpp" +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + std::extents e; + std::layout_left::mapping> m{e}; + + assert( m(5) == 5 ); + } + + { + std::extents e{16, 32}; + std::layout_left::mapping> m{e}; + + assert( m(2,1) == 2*1 + 1*16 ); + } + + { + std::extents e{16, 32, 8}; + std::layout_left::mapping> m{e}; + + assert( m(2,1,3) == 2*1 + 1*16 + 3*16*32 ); + } + + // Indices are of a type implicitly convertible to index_type + { + std::extents e{16, 32}; + std::layout_left::mapping> m{e}; + + assert( m(my_int(2),my_int(1)) == 2*1 + 1*16 ); + } + + // Constraints + { + std::extents e; + std::layout_left::mapping> m{e}; + + unused( m ); + + static_assert( is_paren_op_avail_v< decltype(m), index_t > == true, "" ); + + // rank consistency + static_assert( is_paren_op_avail_v< decltype(m), index_t, index_t > == false, "" ); + + // convertibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_convertible > == false, "" ); + + // nothrow-constructibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_nothrow_constructible > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/required_span_size.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/required_span_size.pass.cpp new file mode 100644 index 0000000000..6d29525aa7 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/required_span_size.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = std::extents; + + { + std::extents e; + std::layout_left::mapping> m{e}; + + assert( m.required_span_size() == 16 ); + } + + { + ext2d_t e{16, 32}; + std::layout_left::mapping m{e}; + + assert( m.required_span_size() == 16*32 ); + } + + { + ext2d_t e{16, 0}; + std::layout_left::mapping m{e}; + + assert( m.required_span_size() == 0 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/stride.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/stride.pass.cpp new file mode 100644 index 0000000000..6c3e19a5e7 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/stride.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext0d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{64, 128}; + std::layout_left::mapping m{ e }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 64 ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == true , "" ); + } + + { + ext2d_t e{1, 128}; + std::layout_left::mapping m{ e }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 1 ); + } + + // constraint: extents_­type?::?rank() > 0 + { + ext0d_t e{}; + std::layout_left::mapping m{ e }; + + unused( m ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/copy.pass.cpp new file mode 100644 index 0000000000..adb4252475 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/copy.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + + std::layout_right::mapping> m0{std::dextents{16,32}}; + std::layout_right::mapping> m {m0}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_right::mapping>; + using mapping1_t = std::layout_right::mapping>; + using mappingd_t = std::layout_right::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/ctad.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/ctad.pass.cpp new file mode 100644 index 0000000000..169f1ac71f --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/ctad.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_right::mapping m{std::extents{16, 32}}; + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_left_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_left_init.pass.cpp new file mode 100644 index 0000000000..e71b4de4bc --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_left_init.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_left ::mapping> m_right{std::dextents{16}}; + std::layout_right::mapping> m( m_right); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 1 ); + assert( m.extents().rank_dynamic() == 1 ); + assert( m.extents().extent(0) == 16 ); + assert( m.stride(0) == 1 ); + } + + // Constraint: extents_type::rank() <= 1 is true + { + using mapping0_t = std::layout_left::mapping>; + using mapping1_t = std::layout_right::mapping>; + + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_left::mapping>; + using mapping1_t = std::layout_right::mapping>; + using mappingd_t = std::layout_right::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_stride_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_stride_init.pass.cpp new file mode 100644 index 0000000000..c41a169b1f --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_stride_init.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::array a{32,1}; + std::layout_stride::mapping> m_stride{std::dextents{16, 32}, a}; + std::layout_right ::mapping> m( m_stride ); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_stride::mapping>; + using mapping1_t = std::layout_right ::mapping>; + using mappingd_t = std::layout_right ::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/list_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/list_init.pass.cpp new file mode 100644 index 0000000000..718147daf9 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/list_init.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template +using test_right_type = std::tuple< + typename std::layout_right::template mapping, + std::integer_sequence +>; + +void typed_test_default_ctor_right() +{ + typed_test_default_ctor< test_right_type< std::extents > >(); + typed_test_default_ctor< test_right_type< std::extents, 10 > >(); + typed_test_default_ctor< test_right_type< std::extents, 5 > >(); + typed_test_default_ctor< test_right_type< std::extents, 10 > >(); + typed_test_default_ctor< test_right_type< std::extents > >(); +} + +void typed_test_compatible_right() +{ + typed_test_compatible< test_right_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_default_ctor_right(); + + typed_test_compatible_right(); + + // TEST(TestLayoutRightListInitialization, test_layout_right_extent_initialization) + { + std::layout_right::mapping> m{std::dextents{16, 32}}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.fail.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.fail.cpp new file mode 100644 index 0000000000..6dbbd4ce7d --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.fail.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = std::extents< index_t, 64, 128 >; + using ext3d_t = std::extents< index_t, 64, 128, 2 >; + + // Constraint: rank consistency + // This constraint is implemented in a different way in the reference implementation. There will be an overload function + // match but it will return false if the ranks are not consistent + { + constexpr ext2d_t e0; + constexpr ext3d_t e1; + constexpr std::layout_right::mapping m0{ e0 }; + constexpr std::layout_right::mapping m1{ e1 }; + + static_assert( m0 == m1, "" ); // expected-error + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.pass.cpp new file mode 100644 index 0000000000..a4514dd652 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +void typed_test_compare_right() +{ + typed_test_compare< test_right_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_compare_right(); + + using index_t = size_t; + using ext1d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{64, 128}; + std::layout_right::mapping m0{ e }; + std::layout_right::mapping m { m0 }; + + assert( m == m0 ); + } + + { + ext2d_t e0{64, 128}; + ext2d_t e1{16, 32}; + std::layout_right::mapping m0{ e0 }; + std::layout_right::mapping m1{ e1 }; + + assert( m0 != m1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/extents.pass.cpp new file mode 100644 index 0000000000..05ea13ef35 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/extents.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext1d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{16, 32}; + std::layout_right::mapping m{e}; + + assert( m.extents() == e ); + } + + { + ext1d_t e{16}; + std::layout_left ::mapping m_left{e}; + std::layout_right::mapping m( m_left ); + + assert( m.extents() == e ); + } + + { + ext2d_t e{16, 32}; + std::array a{32,1}; + std::layout_stride::mapping m_stride{e, a}; + std::layout_right ::mapping m( m_stride ); + + assert( m.extents() == e ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_exhaustive.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..072860754c --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_exhaustive.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_right::mapping> m; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + + { + std::extents e{16, 32}; + std::layout_right::mapping> m{ e }; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_strided.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_strided.pass.cpp new file mode 100644 index 0000000000..8c2e2d79fb --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_strided.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::extents e{64, 128}; + std::layout_right::mapping> m{ e }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_unique.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_unique.pass.cpp new file mode 100644 index 0000000000..f7483cfdbc --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_unique.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_right::mapping> m; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + + { + std::extents e{16, 32}; + std::layout_right::mapping> m{ e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/paren_op.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/paren_op.pass.cpp new file mode 100644 index 0000000000..67ba37ff11 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/paren_op.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../my_int.hpp" +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + std::extents e; + std::layout_right::mapping> m{e}; + + assert( m(5) == 5 ); + } + + { + std::extents e{16, 32}; + std::layout_right::mapping> m{e}; + + assert( m(2,1) == 2*32 + 1*1 ); + } + + { + std::extents e{16, 32, 8}; + std::layout_right::mapping> m{e}; + + assert( m(2,1,3) == 2*32*8 + 1*8 + 3*1 ); + } + + // Indices are of a type implicitly convertible to index_type + { + std::extents e{16, 32}; + std::layout_right::mapping> m{e}; + + assert( m(my_int(2),my_int(1)) == 2*32 + 1*1 ); + } + + // Constraints + { + std::extents e; + std::layout_right::mapping> m{e}; + + unused( m ); + + static_assert( is_paren_op_avail_v< decltype(m), index_t > == true, "" ); + + // rank consistency + static_assert( is_paren_op_avail_v< decltype(m), index_t, index_t > == false, "" ); + + // convertibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_convertible > == false, "" ); + + // nothrow-constructibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_nothrow_constructible > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/required_span_size.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/required_span_size.pass.cpp new file mode 100644 index 0000000000..ff49b9ddde --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/required_span_size.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = std::extents; + + { + std::extents e; + std::layout_right::mapping> m{e}; + + assert( m.required_span_size() == 16 ); + } + + { + ext2d_t e{16, 32}; + std::layout_right::mapping m{e}; + + assert( m.required_span_size() == 16*32 ); + } + + { + ext2d_t e{16, 0}; + std::layout_right::mapping m{e}; + + assert( m.required_span_size() == 0 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/stride.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/stride.pass.cpp new file mode 100644 index 0000000000..fa37757e0e --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/stride.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext0d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{64, 128}; + std::layout_right::mapping m{ e }; + + assert( m.stride(0) == 128 ); + assert( m.stride(1) == 1 ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == true , "" ); + } + + { + ext2d_t e{64, 1}; + std::layout_right::mapping m{ e }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 1 ); + } + + // constraint: extents_type::rank() > 0 + { + ext0d_t e{}; + std::layout_right::mapping m{ e }; + + unused( m ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/ctad.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/ctad.pass.cpp new file mode 100644 index 0000000000..5836dbecef --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/ctad.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_stride::mapping m{std::dextents{16, 32}, std::array{1, 128}}; + + assert( m.is_exhaustive() == false); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + assert( m.strides()[0] == 1 ); + assert( m.strides()[1] == 128 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/list_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/list_init.pass.cpp new file mode 100644 index 0000000000..6a5cdf80bd --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/list_init.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +#define CHECK_MAPPING(m) \ + assert( m.is_exhaustive() == false); \ + assert( m.extents().rank() == 2 ); \ + assert( m.extents().rank_dynamic() == 2 ); \ + assert( m.extents().extent(0) == 16 ); \ + assert( m.extents().extent(1) == 32 ); \ + assert( m.stride(0) == 1 ); \ + assert( m.stride(1) == 128 ); \ + assert( m.strides()[0] == 1 ); \ + assert( m.strides()[1] == 128 ) + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + // From a span + { + typedef int data_t ; + typedef size_t index_t; + + using my_ext = typename std::extents; + + std::array a{1, 128}; + std::span s(a.data(), 2); + std::layout_stride::mapping> m{std::dextents{16, 32}, s}; + + CHECK_MAPPING(m); + } + + // TEST(TestLayoutStrideListInitialization, test_list_initialization) + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_stride::mapping> m{std::dextents{16, 32}, std::array{1, 128}}; + + CHECK_MAPPING(m); + } + + // From another mapping + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_stride::mapping> m0{std::dextents{16, 32}, std::array{1, 128}}; + std::layout_stride::mapping> m{m0}; + + CHECK_MAPPING(m); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.fail.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.fail.cpp new file mode 100644 index 0000000000..d7b456ad64 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.fail.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = std::extents< index_t, 64, 128 >; + using ext3d_t = std::extents< index_t, 64, 128, 2 >; + + // Constraint: rank consistency + { + constexpr ext2d_t e0; + constexpr ext3d_t e1; + constexpr std::array a0{1,64}; + constexpr std::array a1{1,64,64*128}; + constexpr std::layout_stride::mapping m0{ e0, a0 }; + constexpr std::layout_stride::mapping m1{ e1, a1 }; + + static_assert( m0 == m1, "" ); // expected-error + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.pass.cpp new file mode 100644 index 0000000000..8f0f42e164 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext1d_t = std::extents; + using ext2d_t = std::extents; + + { + std::extents e; + std::array a{1,16}; + std::layout_stride::mapping m0{e, a}; + std::layout_stride::mapping m {m0}; + + assert( m0 == m ); + } + + { + using index2_t = int32_t; + + std::extents e; + std::array a{1,16}; + std::extents e2; + std::array a2{1,16}; + std::layout_stride::mapping m1{e , a }; + std::layout_stride::mapping m2{e2, a2}; + + assert( m1 == m2 ); + } + + { + std::extents e; + std::array a0{1,16}; + std::array a1{1,32}; + std::layout_stride::mapping m0{e, a0}; + std::layout_stride::mapping m1{e, a1}; + + assert( m0 != m1 ); + } + + { + std::extents e; + std::array a{1,16}; + std::layout_stride::mapping m{e, a}; + std::layout_left ::mapping m_left{e}; + + assert( m == m_left ); + } + + { + std::extents e; + std::array a{32,1}; + std::layout_stride::mapping m{e, a}; + std::layout_right ::mapping m_right{e}; + + assert( m == m_right ); + } + + { + std::extents e0; + std::extents e1; + std::array a{1,16}; + std::layout_stride::mapping m0{e0, a}; + std::layout_stride::mapping m1{e1, a}; + + assert( m0 != m1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/extents.pass.cpp new file mode 100644 index 0000000000..597d21bc58 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/extents.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = std::extents; + + { + ext2d_t e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping m{e, a}; + + assert( m.extents() == e ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_exhaustive.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..2ccdc28f51 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_exhaustive.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + std::extents e; + std::array a{1}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + std::extents e; + std::array a{2}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + { + std::extents e; + std::array a{1,16}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + std::extents e{16, 32}; + std::array a{1,128}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + { + std::extents e{16, 32, 4}; + std::array a{1,16*4,16}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + std::extents e{16, 32, 4}; + std::array a{1,16*4+1,16}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_strided.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_strided.pass.cpp new file mode 100644 index 0000000000..06c0043388 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_strided.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + { + using dexts = std::dextents; + std::array a{1, 128}; + + std::layout_stride::mapping m{dexts{16, 32}, a}; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_unique.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_unique.pass.cpp new file mode 100644 index 0000000000..a1c19b5b1a --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_unique.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + std::extents e; + std::array a{1}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + { + std::extents e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/paren_op.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/paren_op.pass.cpp new file mode 100644 index 0000000000..7f440dc4c3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/paren_op.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../my_int.hpp" +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + std::extents e; + std::array a{1}; + std::layout_stride::mapping> m{e, a}; + + assert( m(8) == 8 ); + } + + { + std::extents e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping> m{e, a}; + + assert( m(8,16) == 8*1 + 16*16 ); + } + + { + std::extents e{32}; + std::array a{1,24}; + std::layout_stride::mapping> m{e, a}; + + assert( m(8,16) == 8*1 + 16*24 ); + } + + { + std::extents e{32}; + std::array a{48,1}; + std::layout_stride::mapping> m{e, a}; + + assert( m(8,16) == 8*48 + 16*1 ); + } + + // Indices are of a type implicitly convertible to index_type + { + std::extents e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping> m{e, a}; + + assert( m(my_int(8),my_int(16)) == 8*1 + 16*16 ); + } + + // Constraints + { + std::extents e; + std::array a{1}; + std::layout_stride::mapping> m{e, a}; + + static_assert( is_paren_op_avail_v< decltype(m), index_t > == true, "" ); + + // rank consistency + static_assert( is_paren_op_avail_v< decltype(m), index_t, index_t > == false, "" ); + + // convertibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_convertible > == false, "" ); + + // nothrow-constructibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_nothrow_constructible > == false, "" ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/required_span_size.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/required_span_size.pass.cpp new file mode 100644 index 0000000000..9972901a0e --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/required_span_size.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = std::extents; + + { + std::extents e; + std::array a{1}; + std::layout_stride::mapping> m{e, a}; + + assert( m.required_span_size() == 16 ); + } + + { + ext2d_t e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 16*32 ); + } + + { + ext2d_t e{16, 0}; + std::array a{1,1}; + std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 0 ); + } + + { + std::extents e{32}; + std::array a{1,24}; + std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 32*24 - (24-16) ); + } + + { + std::extents e{32}; + std::array a{48,1}; + std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 16*48 - (48-32) ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/stride.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/stride.pass.cpp new file mode 100644 index 0000000000..508a1a8d5b --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/stride.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext0d_t = std::extents; + using ext2d_t = std::extents; + + auto e = std::dextents{16, 32}; + auto s_arr = std::array {1, 128}; + + // From a span + { + std::span s(s_arr.data(), 2); + std::layout_stride::mapping m{e, s}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == true , "" ); + } + + // From an array + { + std::layout_stride::mapping m{e, s_arr}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + } + + // From another mapping + { + std::layout_stride::mapping m0{e, s_arr}; + std::layout_stride::mapping m{m0}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + } + + // constraint: extents_­type?::?rank() > 0 + { + ext0d_t e{}; + std::layout_stride::mapping m{ e, std::array{} }; + + unused( m ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/strides.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/strides.pass.cpp new file mode 100644 index 0000000000..260a3e5aa9 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/strides.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = std::extents; + + auto e = std::dextents{16, 32}; + auto s_arr = std::array {1, 128}; + + // From a span + { + std::span s(s_arr.data(), 2); + std::layout_stride::mapping m{e, s}; + + assert( m.strides()[0] == 1 ); + assert( m.strides()[1] == 128 ); + } + + // From an array + { + std::layout_stride::mapping m{e, s_arr}; + + assert( m.strides()[0] == 1 ); + assert( m.strides()[1] == 128 ); + } + + // From another mapping + { + std::layout_stride::mapping m0{e, s_arr}; + std::layout_stride::mapping m{m0}; + + assert( m.strides()[0] == 1 ); + assert( m.strides()[1] == 128 ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.util/layout_util.hpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.util/layout_util.hpp new file mode 100644 index 0000000000..93f6310b14 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.util/layout_util.hpp @@ -0,0 +1,168 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +template struct TestLayoutCtors; +template +struct TestLayoutCtors +>> +{ + using mapping_type = Mapping; + using extents_type = typename mapping_type::extents_type; + Mapping map = { extents_type{ DynamicSizes... } }; +}; + +template void typed_test_default_ctor() +// TYPED_TEST( TestLayoutCtors, default_ctor ) +{ + // Default constructor ensures extents() == Extents() is true. + using TestFixture = TestLayoutCtors; + auto m = typename TestFixture::mapping_type(); + assert( m .extents() == typename TestFixture::extents_type() ); + auto m2 = typename TestFixture::mapping_type{}; + assert( m2.extents() == typename TestFixture::extents_type{} ); + assert( m == m2 ); +} + +template struct TestLayoutCompatCtors; +template +struct TestLayoutCompatCtors, + Mapping2, + std::integer_sequence +>> { + using mapping_type1 = Mapping; + using mapping_type2 = Mapping2; + using extents_type1 = std::remove_reference_t().extents())>; + using extents_type2 = std::remove_reference_t().extents())>; + Mapping map1 = { extents_type1{ DynamicSizes... } }; + Mapping2 map2 = { extents_type2{ DynamicSizes2... } }; +}; + +template void typed_test_compatible() +//TYPED_TEST(TestLayout{Left|Right}CompatCtors, compatible_construct_{1|2}) { +//TYPED_TEST(TestLayout{Left|Right}CompatCtors, compatible_assign_{1|2}) { +{ + using TestFixture = TestLayoutCompatCtors; + + // Construct + { + TestFixture t; + + auto m1 = typename TestFixture::mapping_type1(t.map2); + assert( m1.extents() == t.map2.extents() ); + + auto m2 = typename TestFixture::mapping_type2(t.map1); + assert( m2.extents() == t.map1.extents() ); + } + + // Assign + { + TestFixture t; + +#if __MDSPAN_HAS_CXX_17 + if constexpr ( std::is_convertible::value ) + { + t.map1 = t.map2; + } + else + { + t.map1 = typename TestFixture::mapping_type1( t.map2 ); + } +#else + t.map1 = typename TestFixture::mapping_type1( t.map2 ); +#endif + + assert( t.map1.extents() == t.map2.extents() ); + } +} + +template void typed_test_compare() +{ + using TestFixture = TestLayoutCompatCtors; + + { + TestFixture t; + + auto m1 = typename TestFixture::mapping_type1(t.map2); + assert( m1 == t.map2 ); + + auto m2 = typename TestFixture::mapping_type2(t.map1); + assert( m2 == t.map1 ); + } +} + +template +using _sizes = std::integer_sequence; +template +using _exts = std::extents; + +template +using test_left_type_pair = std::tuple< + typename std::layout_left::template mapping, S1, + typename std::layout_left::template mapping, S2 +>; + +template +using test_right_type_pair = std::tuple< + typename std::layout_right::template mapping, S1, + typename std::layout_right::template mapping, S2 +>; + +template< class T1, class T2, class = void > +struct is_cons_avail : std::false_type {}; + +template< class T1, class T2 > +struct is_cons_avail< T1 + , T2 + , std::enable_if_t< std::is_same< decltype( T1{ std::declval() } ) + , T1 + >::value + > + > : std::true_type {}; + +template< class T1, class T2 > +constexpr bool is_cons_avail_v = is_cons_avail< T1, T2 >::value; + +template< class, class T, class... Indicies > +struct is_paren_op_avail : std::false_type {}; + +template< class T, class... Indicies > +struct is_paren_op_avail< std::enable_if_t< std::is_same< decltype(std::declval()(std::declval()...)) + , typename T::index_type + >::value + > + , T + , Indicies... + > : std::true_type {}; + +template< class T, class... Indicies > +constexpr bool is_paren_op_avail_v = is_paren_op_avail< void, T, Indicies... >::value; + +template< class T, class RankType, class = void > +struct is_stride_avail : std::false_type {}; + +template< class T, class RankType > +struct is_stride_avail< T + , RankType + , std::enable_if_t< std::is_same< decltype( std::declval().stride( std::declval() ) ) + , typename T::index_type + >::value + > + > : std::true_type {}; + +template< class T, class RankType > +constexpr bool is_stride_avail_v = is_stride_avail< T, RankType >::value; + +// Workaround for variables that are only used in static_assert's +template< typename T > +constexpr bool unused( T && ) { return true; } diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/array_init_extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/array_init_extents.pass.cpp new file mode 100644 index 0000000000..e572c5422f --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/array_init_extents.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class T, class DataHandleT, class SizeType, size_t N, class = void > +struct is_array_cons_avail : std::false_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +struct is_array_cons_avail< T + , DataHandleT + , SizeType + , N + , std::enable_if_t< std::is_same< decltype( T{ std::declval() + , std::declval>() + } + ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +constexpr bool is_array_cons_avail_v = is_array_cons_avail< T, DataHandleT, SizeType, N >::value; + +int main(int, char**) +{ + // extents from std::array + { + std::array d{42}; + std::mdspan> m{ d.data(), std::array{64, 128} }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // data from cptr, extents from std::array + { + using mdspan_t = std::mdspan>; + + std::array d{42}; + const int* const ptr = d.data(); + + static_assert( is_array_cons_avail_v< mdspan_t, decltype(ptr), int, 2 > == true, "" ); + + mdspan_t m{ptr, std::array{64, 128}}; + + static_assert( std::is_same::value, "" ); + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_convertible; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: (is_nothrow_constructible && ...) is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_nothrow_constructible; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: N == rank() || N == rank_dynamic() is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = int; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, int, 1 > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_stride >; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_right, Foo::my_accessor >; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/copy.pass.cpp new file mode 100644 index 0000000000..c3a403d0fd --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/copy.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class T1, class T0, class = void > +struct is_copy_cons_avail : std::false_type {}; + +template< class T1, class T0 > +struct is_copy_cons_avail< T1 + , T0 + , std::enable_if_t< std::is_same< decltype( T1{ std::declval() } ), T1 >::value > + > : std::true_type {}; + +template< class T1, class T0 > +constexpr bool is_copy_cons_avail_v = is_copy_cons_avail< T1, T0 >::value; + +int main(int, char**) +{ + // copy constructor + { + using ext_t = std::extents; + using mdspan_t = std::mdspan; + + static_assert( is_copy_cons_avail_v< mdspan_t, mdspan_t > == true, "" ); + + std::array d{42}; + mdspan_t m0{ d.data(), ext_t{64, 128} }; + mdspan_t m { m0 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // copy constructor with conversion + { + std::array d{42}; + std::mdspan> m0{ d.data(), std::extents{} }; + std::mdspan> m { m0 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: is_constructible_v&> is true + { + using mdspan1_t = std::mdspan, std::layout_left >; + using mdspan0_t = std::mdspan, std::layout_right>; + + static_assert( is_copy_cons_avail_v< mdspan1_t, mdspan0_t > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan1_t = std::mdspan, std::layout_right, Foo::my_accessor>; + using mdspan0_t = std::mdspan, std::layout_right>; + + static_assert( is_copy_cons_avail_v< mdspan1_t, mdspan0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_c_array.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_c_array.pass.cpp new file mode 100644 index 0000000000..bfad7aedbd --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_c_array.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, ctad_carray) + { + int data[5] = {1,2,3,4,5}; + std::mdspan m(data); + + static_assert(std::is_same::value == true, ""); + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == &data[0]); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 0 ); + assert(m.static_extent(0) == 5 ); + assert(m.extent(0) == 5 ); + assert(__MDSPAN_OP(m, 2) == 3 ); + + std::mdspan m2(data, 3); + + static_assert(std::is_same::value == true, ""); + static_assert(m2.is_exhaustive() == true, ""); + + assert(m2.data_handle() == &data[0]); + assert(m2.rank() == 1 ); + assert(m2.rank_dynamic() == 1 ); + assert(m2.extent(0) == 3 ); + assert(__MDSPAN_OP(m2, 2) == 3 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_const_c_array.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_const_c_array.pass.cpp new file mode 100644 index 0000000000..2309e21b04 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_const_c_array.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, ctad_const_carray) + { + const int data[5] = {1,2,3,4,5}; + std::mdspan m(data); + + static_assert(std::is_same::value == true, ""); + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == &data[0]); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 0 ); + assert(m.static_extent(0) == 5 ); + assert(m.extent(0) == 5 ); + assert(__MDSPAN_OP(m, 2) == 3 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_copy.pass.cpp new file mode 100644 index 0000000000..2da5193352 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_copy.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + constexpr auto dyn = std::dynamic_extent; + + // copy constructor + { + std::array d{42}; + std::mdspan> m0{ d.data(), std::extents{64, 128} }; + std::mdspan m{ m0 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents.pass.cpp new file mode 100644 index 0000000000..93b787d35b --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +#define CHECK_MDSPAN(m,d) \ + static_assert(m.is_exhaustive(), ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.rank() == 2 ); \ + assert(m.rank_dynamic() == 2 ); \ + assert(m.extent(0) == 64 ); \ + assert(m.extent(1) == 128 ) + + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, extents_object) + { + std::array d{42}; + std::mdspan m{d.data(), std::extents{64, 128}}; + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, extents_object_move) + { + std::array d{42}; + std::mdspan m{d.data(), std::move(std::extents{64, 128})}; + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, extents_std_array) + { + std::array d{42}; + std::mdspan m{d.data(), std::array{64, 128}}; + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, cptr_extents_std_array) + { + std::array d{42}; + const int* const ptr= d.data(); + std::mdspan m{ptr, std::array{64, 128}}; + + static_assert(std::is_same::value, ""); + + CHECK_MDSPAN(m,d); + } + + // extents from std::span + { + std::array d{42}; + std::array sarr{64, 128}; + std::mdspan m{d.data(), std::span{sarr}}; + + CHECK_MDSPAN(m,d); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents_pack.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents_pack.pass.cpp new file mode 100644 index 0000000000..70066ac2ab --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents_pack.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, extents_pack) + { + std::array d{42}; + std::mdspan m(d.data(), 64, 128); + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 64 ); + assert(m.extent(1) == 128 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_layouts.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_layouts.pass.cpp new file mode 100644 index 0000000000..02c8525bc3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_layouts.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +#define CHECK_MDSPAN(m,d,exhaust,s0,s1) \ + static_assert(m.rank() == 2 , ""); \ + static_assert(m.rank_dynamic() == 2 , ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.extent(0) == 16 ); \ + assert(m.extent(1) == 32 ); \ + assert(m.stride(0) == s0 ); \ + assert(m.stride(1) == s1 ); \ + assert(m.is_exhaustive() == exhaust ) + + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, layout_left) + { + std::array d{42}; + std::mdspan m0{d.data(), std::layout_left::mapping{std::extents{16, 32}}}; + + CHECK_MDSPAN( m0, d, true, 1, 16 ); + } + + // TEST(TestMdspanCTAD, layout_right) + { + std::array d{42}; + std::mdspan m0{d.data(), std::layout_right::mapping{std::extents{16, 32}}}; + + CHECK_MDSPAN( m0, d, true, 32, 1 ); + } + + // TEST(TestMdspanCTAD, layout_stride) + { + std::array d{42}; + std::mdspan m0{d.data(), std::layout_stride::mapping{std::extents{16, 32}, std::array{1, 128}}}; + + CHECK_MDSPAN( m0, d, false, 1, 128 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_mapping.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_mapping.pass.cpp new file mode 100644 index 0000000000..0b3c2bace1 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_mapping.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + constexpr auto dyn = std::dynamic_extent; + + // mapping + { + using data_t = int; + using index_t = size_t; + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + std::mdspan m{ d.data(), map }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // mapping and accessor + { + using data_t = int; + using index_t = size_t; + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + std::default_accessor a; + std::mdspan m{ d.data(), map, a }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_pointer.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_pointer.pass.cpp new file mode 100644 index 0000000000..4de93f64b9 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_pointer.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +#define CHECK_MDSPAN(m,d) \ + static_assert(std::is_same::value, ""); \ + static_assert(m.is_exhaustive(), ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.rank() == 0 ); \ + assert(m.rank_dynamic() == 0 ) + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, ctad_pointer) + { + std::array d = {1,2,3,4,5}; + int* ptr = d.data(); + std::mdspan m(ptr); + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, ctad_pointer_tmp) + { + std::array d = {1,2,3,4,5}; + std::mdspan m(d.data()); + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, ctad_pointer_move) + { + std::array d = {1,2,3,4,5}; + int* ptr = d.data(); + std::mdspan m(std::move(ptr)); + + CHECK_MDSPAN(m,d); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_accessor.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_accessor.pass.cpp new file mode 100644 index 0000000000..1ecf269e72 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_accessor.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../foo_customizations.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + using data_t = int; + using acc_t = Foo::foo_accessor; + using index_t = size_t; + + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + acc_t a; + std::mdspan, std::layout_left, acc_t> m{ d.data(), map, a }; + + static_assert(m.is_exhaustive(), ""); + //assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 64 ); + assert(m.extent(1) == 128 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_layout.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_layout.pass.cpp new file mode 100644 index 0000000000..c07d554ead --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_layout.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../foo_customizations.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using map_t = Foo::layout_foo::template mapping>; + + { + using data_t = int; + using lay_t = Foo::layout_foo; + using index_t = size_t; + + std::array d{42}; + lay_t::mapping> map{std::dextents{64, 128}}; + std::mdspan, lay_t> m{ d.data(), map }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/data_c_array.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/data_c_array.pass.cpp new file mode 100644 index 0000000000..1eba3cc1f4 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/data_c_array.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + data_t data[1] = {42}; + std::mdspan> m(data); + auto val = m(0); + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == data ); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 0 ); + assert(m.extent(0) == 1 ); + assert(m.static_extent(0) == 1 ); + assert(m.stride(0) == 1 ); + assert(val == 42 ); + assert(m.size() == 1 ); + assert(m.empty() == false); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/default.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/default.pass.cpp new file mode 100644 index 0000000000..1ebc1778f5 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/default.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + std::mdspan> m; + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == nullptr); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 1 ); + assert(m.extent(0) == 0 ); + assert(m.static_extent(0) == dyn ); + assert(m.stride(0) == 1 ); + assert(m.size() == 0 ); + assert(m.empty() == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents.pass.cpp new file mode 100644 index 0000000000..dc38f72369 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class T, class DataHandleType, class ExtentsType, class = void > +struct is_extents_cons_avail : std::false_type {}; + +template< class T, class DataHandleType, class ExtentsType > +struct is_extents_cons_avail< T + , DataHandleType + , ExtentsType + , std::enable_if_t< std::is_same< decltype( T{ std::declval() + , std::declval() + } + ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class DataHandleType, class ExtentsType > +constexpr bool is_extents_cons_avail_v = is_extents_cons_avail< T, DataHandleType, ExtentsType >::value; + +int main(int, char**) +{ + // extents from extents object + { + using ext_t = std::extents; + std::array d{42}; + std::mdspan m{ d.data(), ext_t{64, 128} }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // extents from extents object move + { + using ext_t = std::extents< int, dyn, dyn >; + using mdspan_t = std::mdspan< int, ext_t >; + + static_assert( is_extents_cons_avail_v< mdspan_t, int *, ext_t > == true, "" ); + + std::array d{42}; + mdspan_t m{ d.data(), std::move(ext_t{64, 128}) }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: is_constructible_v is true + { + using ext_t = std::extents< int, 16, 16 >; + using mdspan_t = std::mdspan< int, ext_t, std::layout_stride >; + + static_assert( is_extents_cons_avail_v< mdspan_t, int *, ext_t > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using ext_t = std::extents< int, 16, 16 >; + using mdspan_t = std::mdspan< int, ext_t, std::layout_right, Foo::my_accessor >; + + static_assert( is_extents_cons_avail_v< mdspan_t, int *, ext_t > == false, "" ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents_pack.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents_pack.pass.cpp new file mode 100644 index 0000000000..8b885d471d --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents_pack.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class, class T, class DataHandleT, class... SizeTypes > +struct is_param_pack_cons_avail : std::false_type {}; + +template< class T, class DataHandleT, class... SizeTypes > +struct is_param_pack_cons_avail< std::enable_if_t< std::is_same< decltype( T{ std::declval() + , std::declval()... + } + ) + , T + >::value + > + , T + , DataHandleT + , SizeTypes... + > : std::true_type {}; + +template< class T, class DataHandleT, class... SizeTypes > +constexpr bool is_param_pack_cons_avail_v = is_param_pack_cons_avail< void, T, DataHandleT, SizeTypes... >::value; + +int main(int, char**) +{ + { + using index_t = int; + std::array d{42}; + std::mdspan> m{ d.data(), 64, 128 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + { + using index_t = int; + std::array d{42}; + std::mdspan< int + , std::extents + , std::layout_right + , std::default_accessor + > m{ d.data(), 64, 128 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = my_int; + + std::array d{42}; + mdspan_t m{ d.data(), other_index_t(64), other_index_t(128) }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + + static_assert( is_param_pack_cons_avail_v< mdspan_t, decltype(d.data()), other_index_t, other_index_t > == true, "" ); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_convertible; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, other_index_t, other_index_t > == false, "" ); + } + + // Constraint: (is_nothrow_constructible && ...) is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_nothrow_constructible; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, other_index_t, other_index_t > == false, "" ); + } + + // Constraint: N == rank() || N == rank_dynamic() is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, int > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_stride >; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, int > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_right, Foo::my_accessor >; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, int > == false, "" ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_left.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_left.pass.cpp new file mode 100644 index 0000000000..cad112e4e2 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_left.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + std::array d{42}; + std::mdspan, std::layout_left> m{d.data(), 16, 32}; + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 16 ); + assert(m.extent(1) == 32 ); + assert(m.stride(0) == 1 ); + assert(m.stride(1) == 16 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_right.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_right.pass.cpp new file mode 100644 index 0000000000..41fce63541 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_right.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + std::array d{42}; + std::mdspan, std::layout_right> m{d.data(), 16, 32}; + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 16 ); + assert(m.extent(1) == 32 ); + assert(m.stride(0) == 32 ); + assert(m.stride(1) == 1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_stride.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_stride.pass.cpp new file mode 100644 index 0000000000..144a47e404 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_stride.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + std::array d{42}; + + std::mdspan< int + , std::extents + , std::layout_stride + > + m { d.data() + , std::layout_stride::template mapping>{std::dextents{16, 32}, std::array{1, 128}} + }; + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 16 ); + assert(m.extent(1) == 32 ); + assert(m.stride(0) == 1 ); + assert(m.stride(1) == 128 ); + assert(m.is_exhaustive() == false ); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/mapping.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/mapping.pass.cpp new file mode 100644 index 0000000000..eff2ae0e7c --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/mapping.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class T, class DataHandleType, class MappingType, class = void > +struct is_mapping_cons_avail : std::false_type {}; + +template< class T, class DataHandleType, class MappingType > +struct is_mapping_cons_avail< T + , DataHandleType + , MappingType + , std::enable_if_t< std::is_same< decltype( T{ std::declval() + , std::declval() + } + ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class DataHandleType, class MappingType > +constexpr bool is_mapping_cons_avail_v = is_mapping_cons_avail< T, DataHandleType, MappingType >::value; + +int main(int, char**) +{ + using data_t = int; + using index_t = size_t; + using ext_t = std::extents; + using mapping_t = std::layout_left::mapping; + + // mapping + { + using mdspan_t = std::mdspan; + + static_assert( is_mapping_cons_avail_v< mdspan_t, int *, mapping_t > == true, "" ); + + std::array d{42}; + mapping_t map{std::dextents{64, 128}}; + mdspan_t m{ d.data(), map }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = std::mdspan>; + + static_assert( is_mapping_cons_avail_v< mdspan_t, int *, mapping_t > == false, "" ); + } + + // mapping and accessor + { + + std::array d{42}; + mapping_t map{std::dextents{64, 128}}; + std::default_accessor a; + std::mdspan m{ d.data(), map, a }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/span_init_extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/span_init_extents.pass.cpp new file mode 100644 index 0000000000..228cabf87a --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/span_init_extents.pass.cpp @@ -0,0 +1,96 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class T, class DataHandleT, class SizeType, size_t N, class = void > +struct is_span_cons_avail : std::false_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +struct is_span_cons_avail< T + , DataHandleT + , SizeType + , N + , std::enable_if_t< std::is_same< decltype( T{ std::declval() + , std::declval>() + } + ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +constexpr bool is_span_cons_avail_v = is_span_cons_avail< T, DataHandleT, SizeType, N >::value; + + +int main(int, char**) +{ + // extents from std::span + { + using mdspan_t = std::mdspan>; + using other_index_t = int; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == true, "" ); + + std::array d{42}; + std::array sarr{64, 128}; + + mdspan_t m{d.data(), std::span{sarr}}; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = std::mdspan>; + using other_index_t = my_int_non_convertible; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = std::mdspan>; + using other_index_t = my_int_non_convertible; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: N == rank() || N == rank_dynamic() is true + { + using mdspan_t = std::mdspan>; + using other_index_t = int; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 1 > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_stride >; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_right, Foo::my_accessor >; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/accessor.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/accessor.pass.cpp new file mode 100644 index 0000000000..983dacc152 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/accessor.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + using data_t = int; + using index_t = size_t; + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + std::default_accessor const a; + std::mdspan, std::layout_left> m{ d.data(), map, a }; + + assert( m.accessor().access( d.data(), 0 ) == a.access( d.data(), 0 ) ); + assert( m.accessor().offset( d.data(), 0 ) == a.offset( d.data(), 0 ) ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/brackets_op.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/brackets_op.pass.cpp new file mode 100644 index 0000000000..6f7debd231 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/brackets_op.pass.cpp @@ -0,0 +1,161 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../my_int.hpp" + +// Will be testing `m[0,0]` when it becomes available +// Alternatively, could use macro `__MDSPAN_OP(m,0,0)` which is turned to either `m[0,0]` or `m(0,0)`, +// depending on if `__cpp_multidimensional_subscript` is defined or not + +constexpr auto dyn = std::dynamic_extent; + +template< class, class T, class... OtherIndexTypes > +struct is_bracket_op_avail : std::false_type {}; + +template< class T, class... OtherIndexTypes > +struct is_bracket_op_avail< std::enable_if_t< std::is_same< decltype( std::declval()(std::declval()...) ) + , typename T::accessor_type::reference + >::value + > + , T + , OtherIndexTypes... + > : std::true_type {}; + +template< class T, class... OtherIndexTypes > +constexpr bool is_bracket_op_avail_v = is_bracket_op_avail< void, T, OtherIndexTypes... >::value; + +template< class T, class OtherIndexType, size_t N, class = void > +struct is_bracket_op_array_avail : std::false_type {}; + +template< class T, class OtherIndexType, size_t N > +struct is_bracket_op_array_avail< T + , OtherIndexType + , N + , std::enable_if_t< std::is_same< decltype( std::declval()(std::declval>()) ) + , typename T::accessor_type::reference + >::value + > + > : std::true_type {}; + +template< class T, class OtherIndexType, size_t N > +constexpr bool is_bracket_op_array_avail_v = is_bracket_op_array_avail< T, OtherIndexType, N >::value; + +template< class T, class OtherIndexType, size_t N, class = void > +struct is_bracket_op_span_avail : std::false_type {}; + +template< class T, class OtherIndexType, size_t N > +struct is_bracket_op_span_avail< T + , OtherIndexType + , N + , std::enable_if_t< std::is_same< decltype( std::declval()(std::declval>()) ) + , typename T::accessor_type::reference + >::value + > + > : std::true_type {}; + +template< class T, class OtherIndexType, size_t N > +constexpr bool is_bracket_op_span_avail_v = is_bracket_op_span_avail< T, OtherIndexType, N >::value; + + +int main(int, char**) +{ + { + using element_t = int; + using index_t = int; + using ext_t = std::extents; + using mdspan_t = std::mdspan; + + std::array d{42,43,44,45}; + mdspan_t m{d.data(), ext_t{2, 2}}; + + static_assert( is_bracket_op_avail_v< decltype(m), int, int > == true, "" ); + + // param pack + assert( m(0,0) == 42 ); + assert( m(0,1) == 43 ); + assert( m(1,0) == 44 ); + assert( m(1,1) == 45 ); + + // array of indices + assert( m(std::array{0,0}) == 42 ); + assert( m(std::array{0,1}) == 43 ); + assert( m(std::array{1,0}) == 44 ); + assert( m(std::array{1,1}) == 45 ); + + static_assert( is_bracket_op_array_avail_v< decltype(m), int, 2 > == true, "" ); + + // span of indices + assert( m(std::span{std::array{0,0}}) == 42 ); + assert( m(std::span{std::array{0,1}}) == 43 ); + assert( m(std::span{std::array{1,0}}) == 44 ); + assert( m(std::span{std::array{1,1}}) == 45 ); + + static_assert( is_bracket_op_span_avail_v< decltype(m), int, 2 > == true, "" ); + } + + // Param pack of indices in a type implicitly convertible to index_type + { + using element_t = int; + using index_t = int; + using ext_t = std::extents; + using mdspan_t = std::mdspan; + + std::array d{42,43,44,45}; + mdspan_t m{d.data(), ext_t{2, 2}}; + + assert( m(my_int(0),my_int(0)) == 42 ); + assert( m(my_int(0),my_int(1)) == 43 ); + assert( m(my_int(1),my_int(0)) == 44 ); + assert( m(my_int(1),my_int(1)) == 45 ); + } + + // Constraint: rank consistency + { + using element_t = int; + using index_t = int; + using mdspan_t = std::mdspan>; + + static_assert( is_bracket_op_avail_v< mdspan_t, index_t, index_t > == false, "" ); + + static_assert( is_bracket_op_array_avail_v< mdspan_t, index_t, 2 > == false, "" ); + + static_assert( is_bracket_op_span_avail_v < mdspan_t, index_t, 2 > == false, "" ); + } + + // Constraint: convertibility + { + using element_t = int; + using index_t = int; + using mdspan_t = std::mdspan>; + + static_assert( is_bracket_op_avail_v< mdspan_t, my_int_non_convertible > == false, "" ); + + static_assert( is_bracket_op_array_avail_v< mdspan_t, my_int_non_convertible, 1 > == false, "" ); + + static_assert( is_bracket_op_span_avail_v < mdspan_t, my_int_non_convertible, 1 > == false, "" ); + } + + // Constraint: nonthrow-constructibility + { + using element_t = int; + using index_t = int; + using mdspan_t = std::mdspan>; + + static_assert( is_bracket_op_avail_v< mdspan_t, my_int_non_nothrow_constructible > == false, "" ); + + static_assert( is_bracket_op_array_avail_v< mdspan_t, my_int_non_nothrow_constructible, 1 > == false, "" ); + + static_assert( is_bracket_op_span_avail_v < mdspan_t, my_int_non_nothrow_constructible, 1 > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/data_handle.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/data_handle.pass.cpp new file mode 100644 index 0000000000..cdce9fc189 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/data_handle.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + // C array + { + const int d[5] = {1,2,3,4,5}; +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + std::mdspan m(d); +#else + std::mdspan> m(d); +#endif + + assert( m.data_handle() == d ); + } + + // std array + { + std::array d = {1,2,3,4,5}; +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + std::mdspan m(d.data()); +#else + std::mdspan> m(d.data()); +#endif + + assert( m.data_handle() == d.data() ); + } + + // C pointer + { + std::array d = {1,2,3,4,5}; + int* ptr = d.data(); +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + std::mdspan m(ptr); +#else + std::mdspan> m(ptr); +#endif + + assert( m.data_handle() == ptr ); + } + + // Copy constructor + { + std::array d = {1,2,3,4,5}; +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + std::mdspan m0(d.data()); + std::mdspan m (m0); +#else + std::mdspan> m0(d.data()); + std::mdspan> m (m0); +#endif + + assert( m.data_handle() == m0.data_handle() ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/empty.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/empty.pass.cpp new file mode 100644 index 0000000000..a689a53cfe --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/empty.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + std::array storage{1}; + + { + std::mdspan> m; + + assert( m.empty() == true ); + } + + { + std::mdspan> m{ storage.data(), 0 }; + + assert( m.empty() == true ); + } + + { + std::mdspan> m{ storage.data(), 2 }; + + assert( m.empty() == false ); + } + + { + std::mdspan> m{ storage.data(), 2, 0 }; + + assert( m.empty() == true ); + } + + { + std::mdspan> m{ storage.data(), 2, 2 }; + + assert( m.empty() == false ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extent.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extent.pass.cpp new file mode 100644 index 0000000000..d5bb06e207 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extent.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + typedef int data_t ; + typedef size_t index_t; + + std::array d{42}; + + { + std::mdspan> m; + + assert( m.extent(0) == 0 ); + assert( m.extent(1) == 0 ); + } + + { + std::mdspan> m{d.data()}; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + { + std::mdspan> m{d.data(), 16, 32}; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + { + std::array d{42}; + std::mdspan, std::layout_left> m{d.data(), 16, 32}; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + { + using dexts = std::dextents; + + std::mdspan< int, std::extents, std::layout_stride > + m { d.data() + , std::layout_stride::template mapping{dexts{16, 32}, std::array{1, 128}} + }; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extents.pass.cpp new file mode 100644 index 0000000000..0e84e1d3b3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extents.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::array d{42}; + std::extents e{64, 128}; + std::mdspan> m{ d.data(), e }; + + assert( &m.extents() == &m.mapping().extents() ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_exhaustive.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..d85a8f449c --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_exhaustive.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::mdspan> m; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + std::array d{42}; + std::extents e{64, 128}; + + { + std::mdspan, std::layout_left> m{ d.data(), e }; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + using dexts = std::dextents; + + std::mdspan< int, std::extents, std::layout_stride > + m { d.data() + , std::layout_stride::template mapping{dexts{16, 32}, std::array{1, 128}} + }; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_strided.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_strided.pass.cpp new file mode 100644 index 0000000000..29478a8d31 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_strided.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::mdspan> m; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + std::array d{42}; + std::extents e{64, 128}; + + { + std::mdspan, std::layout_left> m{ d.data(), e }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + { + using dexts = std::dextents; + + std::mdspan< int, std::extents, std::layout_stride > + m { d.data() + , std::layout_stride::template mapping{dexts{16, 32}, std::array{1, 128}} + }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_unique.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_unique.pass.cpp new file mode 100644 index 0000000000..a3918e420b --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_unique.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::mdspan> m; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + std::array d{42}; + std::extents e{64, 128}; + + { + std::mdspan> m{ d.data(), e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + { + std::mdspan, std::layout_left> m{ d.data(), e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/mapping.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/mapping.pass.cpp new file mode 100644 index 0000000000..1861fb42dc --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/mapping.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + // mapping + { + using data_t = int; + using index_t = size_t; + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + std::mdspan, std::layout_left> m{ d.data(), map }; + + assert( m.mapping() == map ); + } + + // mapping and accessor + { + using data_t = int; + using index_t = size_t; + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + std::default_accessor a; + std::mdspan, std::layout_left> m{ d.data(), map, a }; + + assert( m.mapping() == map ); + } + + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/rank.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/rank.pass.cpp new file mode 100644 index 0000000000..4dd3337814 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/rank.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + typedef int data_t ; + typedef size_t index_t; + + std::array d{42}; + + { + std::mdspan> m; + + static_assert( m.rank () == 1, "" ); + assert ( m.rank_dynamic() == 1 ); + } + + { + std::mdspan> m{d.data()}; + + static_assert( m.rank () == 1, "" ); + assert ( m.rank_dynamic() == 0 ); + } + + { + std::mdspan> m{d.data(), 16, 32}; + + static_assert( m.rank () == 2, "" ); + assert ( m.rank_dynamic() == 2 ); + } + + { + std::mdspan> m{d.data(), 16, 32}; + + static_assert( m.rank () == 3, "" ); + assert ( m.rank_dynamic() == 2 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/size.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/size.pass.cpp new file mode 100644 index 0000000000..300b77ee97 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/size.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +template +void test_mdspan_size(std::array& storage, Extents&& e) +{ + using extents_type = std::remove_cv_t>; + std::mdspan m(storage.data(), std::forward(e)); + + static_assert(std::is_same::value, + "The return type of mdspan::size() must be size_t."); + + // m.size() must not overflow, as long as the product of extents + // is representable as a value of type size_t. + assert( m.size() == N ); +} + + +int main(int, char**) +{ + // TEST(TestMdspan, MdspanSizeReturnTypeAndPrecondition) + { + std::array storage; + + static_assert(std::numeric_limits::max() == 127, "max int8_t != 127"); + test_mdspan_size(storage, std::extents{}); // 12 * 11 == 132 + } + + { + std::array storage; + + static_assert(std::numeric_limits::max() == 255, "max uint8_t != 255"); + test_mdspan_size(storage, std::extents{}); // 16 * 17 == 272 + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/stride.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/stride.pass.cpp new file mode 100644 index 0000000000..6017cfa7b6 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/stride.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + typedef int data_t ; + typedef size_t index_t; + + std::array d{42}; + + { + std::mdspan> m; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 1 ); + } + + { + std::mdspan> m{d.data(), 16, 32}; + + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + { + std::array d{42}; + std::mdspan, std::layout_left> m{d.data(), 16, 32}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + { + using dexts = std::dextents; + + std::mdspan< int, std::extents, std::layout_stride > + m { d.data() + , std::layout_stride::template mapping{dexts{16, 32}, std::array{1, 128}} + }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/swap.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/swap.pass.cpp new file mode 100644 index 0000000000..dcf5ef1d28 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/swap.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +void test_std_swap_static_extents() +{ + int data1[12] = {1,2,3,4,5,6,7,8,9,10,11,12}; + int data2[12] = {21,22,23,24,25,26,27,28,29,30,31,32}; + + std::mdspan> m1(data1); + std::mdspan> m2(data2); + std::extents exts1; + std::layout_right::mapping> map1(exts1); + std::extents exts2; + std::layout_right::mapping> map2(exts2); + + assert(m1.data_handle() == data1); + assert(m1.mapping() == map1); + auto val1 = m1(0,0); + assert(val1 == 1); + assert(m2.data_handle() == data2); + assert(m2.mapping() == map2); + auto val2 = m2(0,0); + assert(val2 == 21); + + std::swap(m1,m2); + assert(m1.data_handle() == data2); + assert(m1.mapping() == map2); + val1 = m1(0,0); + assert(val1 == 21); + assert(m2.data_handle() == data1); + assert(m2.mapping() == map1); + val2 = m2(0,0); + assert(val2 == 1); +} + +void test_std_swap_dynamic_extents() +{ + int data1[12] = {1,2,3,4,5,6,7,8,9,10,11,12}; + int data2[12] = {21,22,23,24,25,26,27,28,29,30,31,32}; + + std::mdspan> m1(data1,3,4); + std::mdspan> m2(data2,4,3); + std::dextents exts1(3,4); + std::layout_right::mapping> map1(exts1); + std::dextents exts2(4,3); + std::layout_right::mapping> map2(exts2); + + assert(m1.data_handle() == data1); + assert(m1.mapping() == map1); + auto val1 = m1(0,0); + assert(val1 == 1); + assert(m2.data_handle() == data2); + assert(m2.mapping() == map2); + auto val2 = m2(0,0); + assert(val2 == 21); + + std::swap(m1,m2); + assert(m1.data_handle() == data2); + assert(m1.mapping() == map2); + val1 = m1(0,0); + assert(val1 == 21); + assert(m2.data_handle() == data1); + assert(m2.mapping() == map1); + val2 = m2(0,0); + assert(val2 == 1); +} + +int main(int, char**) +{ + test_std_swap_static_extents(); + + test_std_swap_dynamic_extents(); + + //TODO port tests for customized layout and accessor + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.util/mdspan_util.hpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.util/mdspan_util.hpp new file mode 100644 index 0000000000..96dc6bab24 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.util/mdspan_util.hpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#define CHECK_MDSPAN_EXTENT(m,d,e0,e1) \ + static_assert(m.is_exhaustive(), ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.rank() == 2 ); \ + assert(m.rank_dynamic() == 2 ); \ + assert(m.extent(0) == e0 ); \ + assert(m.extent(1) == e1 ) diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/dim_reduction.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/dim_reduction.pass.cpp new file mode 100644 index 0000000000..39fb787c4b --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/dim_reduction.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + // TEST(TestSubmdspanLayoutRightStaticSizedRankReducing3Dto1D, test_submdspan_layout_right_static_sized_rank_reducing_3d_to_1d) + { + std::array d; + std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = std::submdspan(m, 1, 1, std::full_extent); + + static_assert(decltype(sub0)::rank()==1,"unexpected submdspan rank"); + static_assert(sub0.rank() == 1, ""); + static_assert(sub0.rank_dynamic() == 0, ""); + assert(sub0.extent(0) == 4); + assert(sub0(1) == 42); + } + + // TEST(TestSubmdspanLayoutLeftStaticSizedRankReducing3Dto1D, test_submdspan_layout_left_static_sized_rank_reducing_3d_to_1d) + { + std::array d; + std::mdspan, std::layout_left> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = std::submdspan(m, 1, 1, std::full_extent); + + static_assert(sub0.rank() == 1, ""); + static_assert(sub0.rank_dynamic() == 0, ""); + assert(sub0.extent(0) == 4); + assert(sub0(1) == 42); + } + + // TEST(TestSubmdspanLayoutRightStaticSizedRankReducingNested3Dto0D, test_submdspan_layout_right_static_sized_rank_reducing_nested_3d_to_0d) + { + std::array d; + std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = std::submdspan(m, 1, std::full_extent, std::full_extent); + + static_assert(sub0.rank() == 2, ""); + static_assert(sub0.rank_dynamic() == 0, ""); + assert(sub0.extent(0) == 3); + assert(sub0.extent(1) == 4); + assert(sub0(1, 1) == 42); + + auto sub1 = std::submdspan(sub0, 1, std::full_extent); + static_assert(sub1.rank() == 1, ""); + static_assert(sub1.rank_dynamic() == 0, ""); + assert(sub1.extent(0) == 4); + assert(sub1(1) == 42); + + auto sub2 = std::submdspan(sub1, 1); + static_assert(sub2.rank() == 0, ""); + static_assert(sub2.rank_dynamic() == 0, ""); + assert(sub2() == 42); + } + + return 0; +} + + + + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/pair_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/pair_init.pass.cpp new file mode 100644 index 0000000000..08f5b3f155 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/pair_init.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + // TEST(TestSubmdspanLayoutRightStaticSizedPairs, test_submdspan_layout_right_static_sized_pairs) + { + std::array d; + std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = std::submdspan(m, std::pair{1, 2}, std::pair{1, 3}, std::pair{1, 4}); + + static_assert( sub0.rank() == 3, "" ); + static_assert( sub0.rank_dynamic() == 3, "" ); + assert( sub0.extent(0) == 1 ); + assert( sub0.extent(1) == 2 ); + assert( sub0.extent(2) == 3 ); + assert( sub0(0, 0, 0) == 42 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/return_type.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/return_type.pass.cpp new file mode 100644 index 0000000000..fcf91cb6c3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/return_type.pass.cpp @@ -0,0 +1,140 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +//template + +using submdspan_test_types = std::tuple< + // LayoutLeft to LayoutLeft + std::tuple,std::dextents, std::full_extent_t> + , std::tuple,std::dextents, std::pair> + , std::tuple,std::dextents, int> + , std::tuple,std::dextents, std::full_extent_t, std::full_extent_t> + , std::tuple,std::dextents, std::full_extent_t, std::pair> + , std::tuple,std::dextents, std::full_extent_t, int> + , std::tuple,std::dextents, std::full_extent_t, std::full_extent_t, std::pair> + , std::tuple,std::dextents, std::full_extent_t, std::pair, int> + , std::tuple,std::dextents, std::full_extent_t, int, int> + , std::tuple,std::dextents, std::pair, int, int> + , std::tuple,std::dextents, std::full_extent_t, std::full_extent_t, std::pair, int, int, int> + , std::tuple,std::dextents, std::full_extent_t, std::pair, int, int, int, int> + , std::tuple,std::dextents, std::full_extent_t, int, int, int ,int, int> + , std::tuple,std::dextents, std::pair, int, int, int, int, int> + // LayoutRight to LayoutRight + , std::tuple,std::dextents, std::full_extent_t> + , std::tuple,std::dextents, std::pair> + , std::tuple,std::dextents, int> + , std::tuple,std::dextents, std::full_extent_t, std::full_extent_t> + , std::tuple,std::dextents, std::pair, std::full_extent_t> + , std::tuple,std::dextents, int, std::full_extent_t> + , std::tuple,std::dextents, std::pair, std::full_extent_t, std::full_extent_t> + , std::tuple,std::dextents, int, std::pair, std::full_extent_t> + , std::tuple,std::dextents, int, int, std::full_extent_t> + , std::tuple,std::dextents, int, int, int, std::pair, std::full_extent_t, std::full_extent_t> + , std::tuple,std::dextents, int, int, int, int, std::pair, std::full_extent_t> + , std::tuple,std::dextents, int, int, int, int, int, std::full_extent_t> + // LayoutRight to LayoutRight Check Extents Preservation + , std::tuple,std::extents, std::full_extent_t> + , std::tuple,std::extents, std::pair> + , std::tuple,std::extents, int> + , std::tuple,std::extents, std::full_extent_t, std::full_extent_t> + , std::tuple,std::extents, std::pair, std::full_extent_t> + , std::tuple,std::extents, int, std::full_extent_t> + , std::tuple,std::extents, std::pair, std::full_extent_t, std::full_extent_t> + , std::tuple,std::extents, int, std::pair, std::full_extent_t> + , std::tuple,std::extents, int, int, std::full_extent_t> + , std::tuple,std::extents, int, int, int, std::pair, std::full_extent_t, std::full_extent_t> + , std::tuple,std::extents, int, int, int, int, std::pair, std::full_extent_t> + , std::tuple,std::extents, int, int, int, int, int, std::full_extent_t> + + , std::tuple,std::extents, std::full_extent_t, int, std::pair, int, int, std::full_extent_t> + , std::tuple,std::extents, int, std::full_extent_t, std::pair, int, std::full_extent_t, int> + >; + +template struct TestSubMDSpan; + +template +struct TestSubMDSpan< + std::tuple> +{ + using mds_org_t = std::mdspan; + using mds_sub_t = std::mdspan; + using map_t = typename mds_org_t::mapping_type; + + using mds_sub_deduced_t = decltype(std::submdspan(mds_org_t(nullptr, map_t()), SubArgs()...)); + using sub_args_t = std::tuple; +}; + +// TYPED_TEST(TestSubMDSpan, submdspan_return_type) +template +void test_submdspan() +{ + using TestFixture = TestSubMDSpan; + + static_assert(std::is_same::value, + "SubMDSpan: wrong return type"); +} + +int main(int, char**) +{ + static_assert( std::tuple_size< submdspan_test_types >{} == 40, "" ); + + test_submdspan< std::tuple_element_t< 0, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 1, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 2, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 3, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 4, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 5, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 6, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 7, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 8, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 9, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 10, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 11, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 12, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 13, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 14, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 15, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 16, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 17, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 18, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 19, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 20, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 21, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 22, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 23, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 24, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 25, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 26, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 27, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 28, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 29, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 30, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 31, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 32, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 33, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 34, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 35, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 36, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 37, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 38, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 39, submdspan_test_types > >(); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/tuple_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/tuple_init.pass.cpp new file mode 100644 index 0000000000..73fa839394 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/tuple_init.pass.cpp @@ -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 +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + // TEST(TestSubmdspanLayoutRightStaticSizedTuples, test_submdspan_layout_right_static_sized_tuples) + { + std::array d; + std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = std::submdspan(m, std::tuple{1, 2}, std::tuple{1, 3}, std::tuple{1, 4}); + + static_assert( sub0.rank() == 3, "" ); + static_assert( sub0.rank_dynamic() == 3, "" ); + assert( sub0.extent(0) == 1 ); + assert( sub0.extent(1) == 2 ); + assert( sub0.extent(2) == 3 ); + assert( sub0(0, 0, 0) == 42 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/my_accessor.hpp b/libcxx/test/std/containers/views/mdspan/my_accessor.hpp new file mode 100644 index 0000000000..09e9fe4703 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/my_accessor.hpp @@ -0,0 +1,37 @@ +#ifndef _MY_ACCESSOR_HPP +#define _MY_ACCESSOR_HPP + +#include "foo_customizations.hpp" + +namespace Foo +{ + // Same as Foo::foo_accessor but + // 1. Doesn't have a default constructor + // 2. Isn't contructible from the default accessor + template + struct my_accessor { + using offset_policy = my_accessor; + using element_type = T; + using reference = T&; + using data_handle_type = foo_ptr; + + __MDSPAN_INLINE_FUNCTION + constexpr my_accessor(int* ptr) noexcept { flag = ptr; } + + template + __MDSPAN_INLINE_FUNCTION + constexpr my_accessor(my_accessor other) noexcept { flag = other.flag; } + + + constexpr reference access(data_handle_type p, size_t i) const noexcept { + return p.data[i]; + } + + constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept { + return data_handle_type(p.data+i); + } + int* flag; + }; +} + +#endif diff --git a/libcxx/test/std/containers/views/mdspan/my_int.hpp b/libcxx/test/std/containers/views/mdspan/my_int.hpp new file mode 100644 index 0000000000..e2d04966f4 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/my_int.hpp @@ -0,0 +1,45 @@ +#ifndef _MY_INT_HPP +#define _MY_INT_HPP + +struct my_int_non_convertible; + +struct my_int +{ + int _val; + + my_int( my_int_non_convertible ) noexcept; + constexpr my_int( int val ) : _val( val ){}; + constexpr operator int() const noexcept { return _val; } +}; + +template <> struct std::is_integral : std::true_type {}; + +// Wrapper type that's not implicitly convertible + +struct my_int_non_convertible +{ + my_int _val; + + my_int_non_convertible(); + my_int_non_convertible( my_int val ) : _val( val ){}; + operator my_int() const noexcept { return _val; } +}; + +my_int::my_int( my_int_non_convertible ) noexcept {} + +template <> struct std::is_integral : std::true_type {}; + +// Wrapper type that's not nothrow-constructible + +struct my_int_non_nothrow_constructible +{ + int _val; + + my_int_non_nothrow_constructible(); + my_int_non_nothrow_constructible( int val ) : _val( val ){}; + operator int() const { return _val; } +}; + +template <> struct std::is_integral : std::true_type {}; + +#endif