From da1ffe0008fa6029eac37a68757ce74d2412cc47 Mon Sep 17 00:00:00 2001 From: fbusato Date: Mon, 25 Nov 2024 22:09:14 +0000 Subject: [PATCH 1/3] add std::dims --- docs/libcudacxx/standard_api.rst | 6 ++++-- docs/libcudacxx/standard_api/container_library/mdspan.rst | 1 + libcudacxx/include/cuda/std/__mdspan/extents.h | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/libcudacxx/standard_api.rst b/docs/libcudacxx/standard_api.rst index 0729df55406..cb01d478702 100644 --- a/docs/libcudacxx/standard_api.rst +++ b/docs/libcudacxx/standard_api.rst @@ -101,5 +101,7 @@ Feature availability: - C++23 ```` is available in C++17. - - mdspan is feature complete in C++17 onwards. - - mdspan on msvc is only supported in C++20 and onwards. + - ``mdspan`` is feature complete in C++17 onwards. + - ``mdspan`` on msvc is only supported in C++20 and onwards. + +- C++26 ``std::dims`` is available in C++17. diff --git a/docs/libcudacxx/standard_api/container_library/mdspan.rst b/docs/libcudacxx/standard_api/container_library/mdspan.rst index 664a60eb48e..72174d13624 100644 --- a/docs/libcudacxx/standard_api/container_library/mdspan.rst +++ b/docs/libcudacxx/standard_api/container_library/mdspan.rst @@ -7,6 +7,7 @@ Extensions ---------- - All features of ```` are made available in C++17 onwards +- C++26 ``std::dims`` is made available in C++17 onwards Restrictions ------------ diff --git a/libcudacxx/include/cuda/std/__mdspan/extents.h b/libcudacxx/include/cuda/std/__mdspan/extents.h index 302cc26894a..99e127b3532 100644 --- a/libcudacxx/include/cuda/std/__mdspan/extents.h +++ b/libcudacxx/include/cuda/std/__mdspan/extents.h @@ -525,6 +525,9 @@ struct __make_dextents<_IndexType, 0, _CUDA_VSTD::extents<_IndexType, _ExtentsPa template using dextents = typename __detail::__make_dextents<_IndexType, _Rank>::type; +template +using dims = dextents<_IndexType, _Rank>; + # if defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) template _CCCL_HOST_DEVICE extents(_IndexTypes...) From 6f023abd9f9f2d8751f7e56618aa110aa6925a49 Mon Sep 17 00:00:00 2001 From: fbusato Date: Mon, 25 Nov 2024 23:54:54 +0000 Subject: [PATCH 2/3] add std::dims test --- .../mdspan.extents.dims/compare.pass.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 libcudacxx/test/libcudacxx/std/containers/views/mdspan/mdspan.extents.dims/compare.pass.cpp diff --git a/libcudacxx/test/libcudacxx/std/containers/views/mdspan/mdspan.extents.dims/compare.pass.cpp b/libcudacxx/test/libcudacxx/std/containers/views/mdspan/mdspan.extents.dims/compare.pass.cpp new file mode 100644 index 00000000000..3548cd28745 --- /dev/null +++ b/libcudacxx/test/libcudacxx/std/containers/views/mdspan/mdspan.extents.dims/compare.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) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++11 +// UNSUPPORTED: msvc && c++14, msvc && c++17 + +#include +#include + +int main(int, char**) +{ + { + using index_t = size_t; + + cuda::std::dextents e0{1, 2, 3}; + cuda::std::dims<3> e1{1, 2, 3}; + + assert(e0 == e1); + } + + return 0; +} From 13898265d3e21860a371daf41c0791bdb6975d36 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Tue, 26 Nov 2024 09:03:05 +0100 Subject: [PATCH 3/3] Add tests --- .../views/mdspan/mdspan.extents.dims/compare.pass.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libcudacxx/test/libcudacxx/std/containers/views/mdspan/mdspan.extents.dims/compare.pass.cpp b/libcudacxx/test/libcudacxx/std/containers/views/mdspan/mdspan.extents.dims/compare.pass.cpp index 3548cd28745..ec2e8c6d725 100644 --- a/libcudacxx/test/libcudacxx/std/containers/views/mdspan/mdspan.extents.dims/compare.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/containers/views/mdspan/mdspan.extents.dims/compare.pass.cpp @@ -3,7 +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) 2023 NVIDIA CORPORATION & AFFILIATES. +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. // //===----------------------------------------------------------------------===// @@ -21,6 +21,7 @@ int main(int, char**) cuda::std::dextents e0{1, 2, 3}; cuda::std::dims<3> e1{1, 2, 3}; + static_assert(cuda::std::is_same::value, ""); assert(e0 == e1); }