├── examples ├── dot_product │ ├── CMakeLists.txt │ └── dot_product.cpp ├── aligned_accessor │ └── CMakeLists.txt ├── godbolt_starter │ ├── CMakeLists.txt │ └── godbolt_starter.cpp ├── restrict_accessor │ └── CMakeLists.txt ├── tiled_layout │ └── CMakeLists.txt └── CMakeLists.txt ├── benchmarks ├── copy │ └── CMakeLists.txt ├── tiny_matrix_add │ ├── CMakeLists.txt │ └── openmp │ │ └── CMakeLists.txt ├── matvec │ ├── CMakeLists.txt │ ├── cuda │ │ └── CMakeLists.txt │ └── openmp │ │ └── CMakeLists.txt ├── sum │ ├── cuda │ │ └── CMakeLists.txt │ ├── openmp │ │ └── CMakeLists.txt │ ├── CMakeLists.txt │ ├── sum_3d_left.cpp │ └── sum_3d_right.cpp ├── stencil │ ├── CMakeLists.txt │ ├── openmp │ │ └── CMakeLists.txt │ └── cuda │ │ └── CMakeLists.txt └── CMakeLists.txt ├── .clang-tidy ├── .gitignore ├── .github ├── dependabot.yml └── workflows │ ├── single-header.yml │ └── cmake-windows.yml ├── tests ├── libcxx-backports │ ├── CMakeLists.txt │ ├── default_accessor │ │ ├── CMakeLists.txt │ │ ├── default_accessor.element_type.verify.cpp │ │ ├── default_accessor.ctor.default.pass.cpp │ │ ├── default_accessor.access.pass.cpp │ │ ├── default_accessor.offset.pass.cpp │ │ ├── default_accessor.types.pass.cpp │ │ └── default_accessor.ctor.conversion.pass.cpp │ ├── extents │ │ ├── CMakeLists.txt │ │ ├── dextents.pass.cpp │ │ ├── ctad.pass.cpp │ │ ├── ctor_default.pass.cpp │ │ ├── types.pass.cpp │ │ ├── ctor_from_integral.pass.cpp │ │ ├── obs_static.pass.cpp │ │ ├── comparison.pass.cpp │ │ ├── ctor_from_array.pass.cpp │ │ └── ctor_from_span.pass.cpp │ ├── layout_left │ │ ├── CMakeLists.txt │ │ ├── layout_left.extents.verify.cpp │ │ ├── layout_left.ctor.default.pass.cpp │ │ ├── layout_left.stride.pass.cpp │ │ ├── layout_left.required_span_size.pass.cpp │ │ ├── layout_left.ctor.extents.pass.cpp │ │ ├── layout_left.properties.pass.cpp │ │ └── layout_left.index_operator.pass.cpp │ ├── llvm_test_macros.h │ ├── layout_right │ │ ├── CMakeLists.txt │ │ ├── layout_right.extents.verify.cpp │ │ ├── layout_right.ctor.default.pass.cpp │ │ ├── layout_right.stride.pass.cpp │ │ ├── layout_right.required_span_size.pass.cpp │ │ ├── layout_right.ctor.extents.pass.cpp │ │ ├── layout_right.properties.pass.cpp │ │ └── layout_right.index_operator.pass.cpp │ ├── layout_stride │ │ ├── CMakeLists.txt │ │ ├── layout_stride.extents.verify.cpp │ │ ├── layout_stride.stride.pass.cpp │ │ ├── layout_stride.is_exhaustive_corner_case.pass.cpp │ │ ├── layout_stride.required_span_size.pass.cpp │ │ ├── layout_stride.ctor.default.pass.cpp │ │ ├── layout_stride.deduction.pass.cpp │ │ └── layout_stride.properties.pass.cpp │ ├── mdspan │ │ ├── mdspan.extents.verify.cpp │ │ ├── CMakeLists.txt │ │ ├── mdspan.mapping.verify.cpp │ │ ├── mdspan.element_type.verify.cpp │ │ ├── mdspan.swap.pass.cpp │ │ ├── mdspan.conversion.verify.cpp │ │ ├── mdspan.ctor.copy.pass.cpp │ │ ├── mdspan.ctor.move.pass.cpp │ │ └── mdspan.move.pass.cpp │ ├── MinimalElementType.h │ └── ConvertibleToIntegral.h ├── test_macros.cpp ├── test_alternate_precondition_violation_handler.cpp ├── test_element_access.cpp ├── test_mdspan_conversion.cpp ├── test_mdspan_at.cpp ├── test_layout_preconditions.cpp ├── test_mdspan_size.cpp ├── test_mdarray_to_mdspan.cpp ├── test_dims.cpp └── CMakeLists.txt ├── cmake └── mdspanConfig.cmake.in ├── scripts └── snl │ ├── config-one-cuda │ ├── config-one │ ├── gtest-nvhpc-patch │ ├── gtest-clang-patch │ ├── build-all │ ├── config-all │ └── gtest-hip-patch ├── LICENSE_FILE_HEADER ├── comp_bench ├── cbench_submdspan.cpp.erb └── CMakeLists.txt ├── include ├── experimental │ ├── mdarray │ ├── __p0009_bits │ │ ├── full_extent_t.hpp │ │ ├── dynamic_extent.hpp │ │ ├── default_accessor.hpp │ │ ├── type_list.hpp │ │ └── no_unique_address.hpp │ ├── __p2389_bits │ │ └── dims.hpp │ ├── mdspan │ └── __p2630_bits │ │ ├── strided_slice.hpp │ │ └── submdspan.hpp └── mdspan │ ├── mdarray.hpp │ └── mdspan.hpp ├── compilation_tests ├── ctest_namespace_std.cpp ├── CMakeLists.txt ├── ctest_constexpr_layouts.cpp ├── ctest_mdspan_convertible.cpp ├── ctest_no_unique_address.cpp ├── ctest_layout_convertible.cpp └── ctest_extents_type_check.cpp └── make_single_header.py /examples/dot_product/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mdspan_add_example(dot_product) 2 | -------------------------------------------------------------------------------- /benchmarks/copy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | mdspan_add_benchmark(copy_layout_stride) 3 | -------------------------------------------------------------------------------- /examples/aligned_accessor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mdspan_add_example(aligned_accessor) 2 | -------------------------------------------------------------------------------- /examples/godbolt_starter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mdspan_add_example(godbolt_starter) 2 | -------------------------------------------------------------------------------- /examples/restrict_accessor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mdspan_add_example(restrict_accessor) 2 | -------------------------------------------------------------------------------- /examples/tiled_layout/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mdspan_add_example(simple_tiled_layout) 2 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | Checks: > 2 | -*, 3 | bugprone-reserved-identifier 4 | HeaderFilterRegex: 'include/*' -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | CMakeSettings.json 3 | CMakeUserPresets.json 4 | out 5 | build* 6 | Makefile 7 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: / 5 | schedule: 6 | interval: "weekly" 7 | -------------------------------------------------------------------------------- /benchmarks/tiny_matrix_add/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | mdspan_add_benchmark(tiny_matrix_add) 3 | 4 | if(MDSPAN_ENABLE_OPENMP) 5 | add_subdirectory(openmp) 6 | endif() 7 | -------------------------------------------------------------------------------- /benchmarks/matvec/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if(MDSPAN_ENABLE_CUDA) 3 | add_subdirectory(cuda) 4 | endif() 5 | 6 | if(MDSPAN_ENABLE_OPENMP) 7 | add_subdirectory(openmp) 8 | endif() 9 | -------------------------------------------------------------------------------- /benchmarks/sum/cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | mdspan_add_cuda_benchmark(sum_3d_cuda) 3 | target_include_directories(sum_3d_cuda PUBLIC 4 | $ 5 | ) -------------------------------------------------------------------------------- /benchmarks/matvec/cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | mdspan_add_cuda_benchmark(matvec_cuda) 3 | target_include_directories(matvec_cuda PUBLIC 4 | $ 5 | ) 6 | -------------------------------------------------------------------------------- /benchmarks/stencil/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | mdspan_add_benchmark(stencil_3d) 3 | 4 | if(MDSPAN_ENABLE_CUDA) 5 | add_subdirectory(cuda) 6 | endif() 7 | 8 | if(MDSPAN_ENABLE_OPENMP) 9 | add_subdirectory(openmp) 10 | endif() 11 | -------------------------------------------------------------------------------- /tests/libcxx-backports/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(extents) 2 | add_subdirectory(default_accessor) 3 | add_subdirectory(layout_left) 4 | add_subdirectory(layout_right) 5 | add_subdirectory(layout_stride) 6 | add_subdirectory(mdspan) 7 | -------------------------------------------------------------------------------- /benchmarks/sum/openmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | mdspan_add_openmp_benchmark(sum_3d_openmp) 3 | if(OpenMP_CXX_FOUND) 4 | target_include_directories(sum_3d_openmp PUBLIC 5 | $ 6 | ) 7 | endif() -------------------------------------------------------------------------------- /cmake/mdspanConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/mdspanTargets.cmake") 4 | 5 | if (@MDSPAN_GENERATE_STD_NAMESPACE_TARGETS@) 6 | include("${CMAKE_CURRENT_LIST_DIR}/mdspanStdTargets.cmake") 7 | endif() 8 | -------------------------------------------------------------------------------- /benchmarks/matvec/openmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | mdspan_add_openmp_benchmark(matvec_openmp) 3 | if(OpenMP_CXX_FOUND) 4 | target_include_directories(matvec_openmp PUBLIC 5 | $ 6 | ) 7 | endif() 8 | -------------------------------------------------------------------------------- /benchmarks/stencil/openmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | mdspan_add_openmp_benchmark(stencil_3d_openmp) 3 | if(OpenMP_CXX_FOUND) 4 | target_include_directories(stencil_3d_openmp PUBLIC 5 | $ 6 | ) 7 | endif() 8 | -------------------------------------------------------------------------------- /benchmarks/tiny_matrix_add/openmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | mdspan_add_openmp_benchmark(tiny_matrix_add_openmp) 3 | if(OpenMP_CXX_FOUND) 4 | target_include_directories(stencil_3d_openmp PUBLIC 5 | $ 6 | ) 7 | endif() 8 | -------------------------------------------------------------------------------- /benchmarks/sum/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | mdspan_add_benchmark(sum_3d_right) 3 | mdspan_add_benchmark(sum_3d_left) 4 | mdspan_add_benchmark(sum_submdspan_right) 5 | 6 | if(MDSPAN_ENABLE_CUDA) 7 | add_subdirectory(cuda) 8 | endif() 9 | 10 | if(MDSPAN_ENABLE_OPENMP) 11 | add_subdirectory(openmp) 12 | endif() 13 | -------------------------------------------------------------------------------- /benchmarks/stencil/cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") 3 | set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --extended-lambda") 4 | endif() 5 | 6 | mdspan_add_cuda_benchmark(stencil_3d_cuda) 7 | target_include_directories(stencil_3d_cuda PUBLIC 8 | $ 9 | ) 10 | -------------------------------------------------------------------------------- /tests/libcxx-backports/default_accessor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mdspan_add_test(default_accessor.access.pass) 2 | mdspan_add_test(default_accessor.ctor.conversion.pass) 3 | mdspan_add_test(default_accessor.ctor.default.pass) 4 | #mdspan_add_test(default_accessor.element_type.verify) 5 | mdspan_add_test(default_accessor.offset.pass) 6 | mdspan_add_test(default_accessor.types.pass) 7 | -------------------------------------------------------------------------------- /tests/libcxx-backports/extents/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mdspan_add_test(comparison.pass) 2 | mdspan_add_test(conversion.pass) 3 | mdspan_add_test(ctad.pass) 4 | mdspan_add_test(ctor_default.pass) 5 | mdspan_add_test(ctor_from_array.pass) 6 | mdspan_add_test(ctor_from_integral.pass) 7 | mdspan_add_test(ctor_from_span.pass) 8 | mdspan_add_test(dextents.pass) 9 | mdspan_add_test(obs_static.pass) 10 | mdspan_add_test(types.pass) 11 | -------------------------------------------------------------------------------- /scripts/snl/config-one-cuda: -------------------------------------------------------------------------------- 1 | COMP_DIR=$1 2 | COMPILER=$2 3 | STANDARD=$3 4 | CXXFLAGS=$4 5 | cd ${COMP_DIR}/cpp${STANDARD} 6 | cmake -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_BENCHMARKS=ON -DCMAKE_CUDA_FLAGS="'${CXXFLAGS}' --extended-lambda --expt-relaxed-constexpr" -DCMAKE_CXX_STANDARD=${STANDARD} -DMDSPAN_CXX_STANDARD=${STANDARD} -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_CXX_EXTENSIONS=OFF -DMDSPAN_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=70 ${MDSPAN_SOURCE} 7 | 8 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12...3.19) 2 | 3 | project(example LANGUAGES CXX) 4 | 5 | if(NOT TARGET mdspan::mdspan) 6 | find_package(mdspan REQUIRED) 7 | endif() 8 | 9 | function(mdspan_add_example EXENAME) 10 | add_executable(${EXENAME} ${EXENAME}.cpp) 11 | target_link_libraries(${EXENAME} mdspan::mdspan) 12 | endfunction() 13 | 14 | add_subdirectory(godbolt_starter) 15 | add_subdirectory(dot_product) 16 | add_subdirectory(tiled_layout) 17 | add_subdirectory(restrict_accessor) 18 | add_subdirectory(aligned_accessor) 19 | -------------------------------------------------------------------------------- /scripts/snl/config-one: -------------------------------------------------------------------------------- 1 | COMP_DIR=$1 2 | COMPILER=$2 3 | STANDARD=$3 4 | CXXFLAGS=$4 5 | cd ${COMP_DIR}/cpp${STANDARD} 6 | echo cmake -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_BENCHMARKS=ON -DCMAKE_CXX_FLAGS="'${CXXFLAGS}'" -DCMAKE_CXX_STANDARD=${STANDARD} -DMDSPAN_CXX_STANDARD=${STANDARD} -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_CXX_EXTENSIONS=OFF ${MDSPAN_SOURCE} 7 | cmake -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_BENCHMARKS=ON -DCMAKE_CXX_FLAGS="'${CXXFLAGS}'" -DCMAKE_CXX_STANDARD=${STANDARD} -DMDSPAN_CXX_STANDARD=${STANDARD} -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_CXX_EXTENSIONS=OFF ${MDSPAN_SOURCE} 8 | 9 | -------------------------------------------------------------------------------- /LICENSE_FILE_HEADER: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | -------------------------------------------------------------------------------- /scripts/snl/gtest-nvhpc-patch: -------------------------------------------------------------------------------- 1 | diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h 2 | index c9e1f324..4cce2ddc 100644 3 | --- a/googletest/include/gtest/internal/gtest-port.h 4 | +++ b/googletest/include/gtest/internal/gtest-port.h 5 | @@ -783,7 +783,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; 6 | // the marked function. 7 | #define GTEST_NO_TAIL_CALL_ __attribute__((disable_tail_calls)) 8 | #endif 9 | -#elif __GNUC__ 10 | +#elif __GNUC__ && !defined(__NVCOMPILER) 11 | #define GTEST_NO_TAIL_CALL_ \ 12 | __attribute__((optimize("no-optimize-sibling-calls"))) 13 | #else 14 | 15 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_left/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mdspan_add_test(layout_left.comparison.pass) 2 | mdspan_add_test(layout_left.ctor.default.pass) 3 | mdspan_add_test(layout_left.ctor.extents.pass) 4 | mdspan_add_test(layout_left.ctor.layout_right.pass) 5 | mdspan_add_test(layout_left.ctor.layout_stride.pass) 6 | mdspan_add_test(layout_left.ctor.mapping.pass) 7 | #mdspan_add_test(layout_left.extents.verify) 8 | mdspan_add_test(layout_left.index_operator.pass) 9 | mdspan_add_test(layout_left.properties.pass) 10 | mdspan_add_test(layout_left.required_span_size.pass) 11 | mdspan_add_test(layout_left.static_requirements.pass) 12 | mdspan_add_test(layout_left.stride.pass) 13 | -------------------------------------------------------------------------------- /tests/libcxx-backports/llvm_test_macros.h: -------------------------------------------------------------------------------- 1 | 2 | #define ASSERT_SAME_TYPE(...) static_assert((std::is_same_v<__VA_ARGS__>), "Types must be the same") 3 | #define LIBCPP_STATIC_ASSERT(A) static_assert(A); 4 | //#define ASSERT_NOEXCEPT(A) if consteval { static_assert(noexcept(A)); } else { assert(noexcept(A)); } 5 | #define ASSERT_NOEXCEPT(...) static_assert(noexcept(__VA_ARGS__), "Operation must be noexcept"); 6 | 7 | namespace std { 8 | using Kokkos::mdspan; 9 | using Kokkos::extents; 10 | using Kokkos::dextents; 11 | using Kokkos::default_accessor; 12 | using Kokkos::layout_left; 13 | using Kokkos::layout_right; 14 | using Kokkos::layout_stride; 15 | } 16 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_right/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mdspan_add_test(layout_right.comparison.pass) 2 | mdspan_add_test(layout_right.ctor.default.pass) 3 | mdspan_add_test(layout_right.ctor.extents.pass) 4 | mdspan_add_test(layout_right.ctor.layout_left.pass) 5 | mdspan_add_test(layout_right.ctor.layout_stride.pass) 6 | mdspan_add_test(layout_right.ctor.mapping.pass) 7 | #mdspan_add_test(layout_right.extents.verify) 8 | mdspan_add_test(layout_right.index_operator.pass) 9 | mdspan_add_test(layout_right.properties.pass) 10 | mdspan_add_test(layout_right.required_span_size.pass) 11 | mdspan_add_test(layout_right.static_requirements.pass) 12 | mdspan_add_test(layout_right.stride.pass) 13 | -------------------------------------------------------------------------------- /.github/workflows/single-header.yml: -------------------------------------------------------------------------------- 1 | name: Build Single Header 2 | 3 | on: 4 | push: 5 | branches: 6 | - stable 7 | 8 | jobs: 9 | deploy: 10 | runs-on: ubuntu-22.04 11 | steps: 12 | - uses: actions/checkout@v6 13 | - run: sudo apt-get install python3 14 | - run: ./make_single_header.py ./include/experimental/mdarray > /tmp/mdspan.hpp 15 | - uses: actions/checkout@v6 16 | with: 17 | ref: single-header 18 | - run: mv /tmp/mdspan.hpp mdspan.hpp 19 | - uses: stefanzweifel/git-auto-commit-action@v7 20 | with: 21 | branch: single-header 22 | commit_message: Update single header build. 23 | -------------------------------------------------------------------------------- /tests/test_macros.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | TEST(mdspan_macros, precondition_violation) 5 | { 6 | #if defined(MDSPAN_IMPL_HAS_CUDA) || defined(MDSPAN_IMPL_HAS_HIP) || defined(MDSPAN_IMPL_HAS_SYCL) 7 | constexpr auto msg = ""; 8 | #else 9 | constexpr auto msg = "hello, world!"; 10 | #endif 11 | 12 | ASSERT_DEATH(MDSPAN_IMPL_PRECONDITION((false && "hello, world!")), msg); 13 | } 14 | 15 | TEST(mdspan_macros, precondition_check_constexpr_invocable) 16 | { 17 | struct fn 18 | { 19 | constexpr auto operator()() const 20 | { 21 | MDSPAN_IMPL_PRECONDITION(1 + 1 == 2); 22 | return 42; 23 | } 24 | }; 25 | 26 | static constexpr auto x = fn{}(); 27 | (void)x; 28 | } 29 | -------------------------------------------------------------------------------- /comp_bench/cbench_submdspan.cpp.erb: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int test(int* data) { 5 | #if defined(METABENCH) 6 | <% (32/n).times do |k| %> 7 | auto <%= "sub0_#{k}" %> = Kokkos::mdspan 10 | > 11 | >(data); 12 | <% n.times do |i| %> 13 | auto <%= "sub#{i+1}_#{k}" %> = Kokkos::submdspan( 14 | <%= "sub#{i}_#{k}" %>, 15 | 1 16 | <%= ", Kokkos::full_extent" * (n - i - 1) %> 17 | ); 18 | <% end %> 19 | <% end %> 20 | return 42 21 | <% (32/n).times do |k| %> 22 | <%= " + sub#{n}_#{k}" %>() 23 | <% end %> 24 | ; 25 | #else 26 | (void) data; 27 | return 1; 28 | #endif 29 | } 30 | 31 | int main() {} 32 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_stride/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mdspan_add_test(layout_stride.comparison.pass) 2 | mdspan_add_test(layout_stride.ctor.default.pass) 3 | mdspan_add_test(layout_stride.ctor.extents_array.pass) 4 | mdspan_add_test(layout_stride.ctor.extents_span.pass) 5 | mdspan_add_test(layout_stride.ctor.strided_mapping.pass) 6 | mdspan_add_test(layout_stride.deduction.pass) 7 | #mdspan_add_test(layout_stride.extents.verify) //FIXME 8 | mdspan_add_test(layout_stride.index_operator.pass) 9 | mdspan_add_test(layout_stride.is_exhaustive_corner_case.pass) 10 | mdspan_add_test(layout_stride.properties.pass) 11 | mdspan_add_test(layout_stride.required_span_size.pass) 12 | mdspan_add_test(layout_stride.static_requirements.pass) 13 | mdspan_add_test(layout_stride.stride.pass) 14 | -------------------------------------------------------------------------------- /tests/test_alternate_precondition_violation_handler.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MDSPAN_IMPL_PRECONDITION_VIOLATION_HANDLER(cond, file, line) \ 4 | do { \ 5 | throw std::logic_error{"precondition failure"}; \ 6 | } while (0); 7 | 8 | #include 9 | #include 10 | 11 | TEST(mdspan_macros, alternate_precondition_violation_handler) 12 | { 13 | ASSERT_THROW(MDSPAN_IMPL_PRECONDITION(false), std::logic_error); 14 | } 15 | 16 | TEST(mdspan_macros, alternate_precondition_check_constexpr_invocable) 17 | { 18 | struct fn 19 | { 20 | constexpr auto operator()() const 21 | { 22 | MDSPAN_IMPL_PRECONDITION(1 + 1 == 2); 23 | return 42; 24 | } 25 | }; 26 | 27 | static constexpr auto x = fn{}(); 28 | (void)x; 29 | } 30 | -------------------------------------------------------------------------------- /tests/libcxx-backports/mdspan/mdspan.extents.verify.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 3 | // See https://llvm.org/LICENSE.txt for license information. 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 | // 6 | //===----------------------------------------------------------------------===// 7 | 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // template 13 | // class mdspan; 14 | // 15 | // Mandates: 16 | // - Extents is a specialization of extents 17 | 18 | #include 19 | 20 | void not_extents() { 21 | // expected-error-re@*:* {{static assertion failed {{.*}}mdspan: Extents template parameter must be a specialization of extents.}} 22 | [[maybe_unused]] std::mdspan m; 23 | } 24 | -------------------------------------------------------------------------------- /include/experimental/mdarray: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | #pragma once 18 | 19 | #ifndef MDSPAN_IMPL_STANDARD_NAMESPACE 20 | #define MDSPAN_IMPL_STANDARD_NAMESPACE std 21 | #endif 22 | 23 | #ifndef MDSPAN_IMPL_PROPOSED_NAMESPACE 24 | #define MDSPAN_IMPL_PROPOSED_NAMESPACE experimental 25 | #endif 26 | 27 | #include "mdspan" 28 | #include "../mdspan/mdarray.hpp" 29 | -------------------------------------------------------------------------------- /tests/libcxx-backports/mdspan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mdspan_add_test(mdspan.assign.pass) 2 | mdspan_add_test(mdspan.conversion.pass) 3 | #mdspan_add_test(mdspan.conversion.verify) 4 | mdspan_add_test(mdspan.ctor.copy.pass) 5 | mdspan_add_test(mdspan.ctor.default.pass) 6 | mdspan_add_test(mdspan.ctor.dh_array.pass) 7 | mdspan_add_test(mdspan.ctor.dh_extents.pass) 8 | mdspan_add_test(mdspan.ctor.dh_integers.pass) 9 | mdspan_add_test(mdspan.ctor.dh_map.pass) 10 | mdspan_add_test(mdspan.ctor.dh_map_acc.pass) 11 | mdspan_add_test(mdspan.ctor.dh_span.pass) 12 | mdspan_add_test(mdspan.ctor.move.pass) 13 | mdspan_add_test(mdspan.deduction.pass) 14 | #mdspan_add_test(mdspan.element_type.verify) 15 | #mdspan_add_test(mdspan.extents.verify) 16 | mdspan_add_test(mdspan.index_operator.pass) 17 | #mdspan_add_test(mdspan.mapping.verify) 18 | mdspan_add_test(mdspan.move.pass) 19 | mdspan_add_test(mdspan.properties.pass) 20 | mdspan_add_test(mdspan.swap.pass) 21 | mdspan_add_test(mdspan.types.pass) 22 | -------------------------------------------------------------------------------- /include/experimental/__p0009_bits/full_extent_t.hpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #pragma once 17 | 18 | #include "macros.hpp" 19 | 20 | namespace MDSPAN_IMPL_STANDARD_NAMESPACE { 21 | 22 | struct full_extent_t { explicit full_extent_t() = default; }; 23 | 24 | MDSPAN_IMPL_INLINE_VARIABLE constexpr auto full_extent = full_extent_t{ }; 25 | 26 | } // namespace MDSPAN_IMPL_STANDARD_NAMESPACE 27 | -------------------------------------------------------------------------------- /include/mdspan/mdarray.hpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | #ifndef MDARRAY_HPP_ 18 | #define MDARRAY_HPP_ 19 | 20 | #ifndef MDSPAN_IMPL_STANDARD_NAMESPACE 21 | #define MDSPAN_IMPL_STANDARD_NAMESPACE Kokkos 22 | #endif 23 | 24 | #ifndef MDSPAN_IMPL_PROPOSED_NAMESPACE 25 | #define MDSPAN_IMPL_PROPOSED_NAMESPACE Experimental 26 | #endif 27 | 28 | #include "mdspan.hpp" 29 | #include "../experimental/__p1684_bits/mdarray.hpp" 30 | 31 | #endif // MDARRAY_HPP_ 32 | -------------------------------------------------------------------------------- /compilation_tests/ctest_namespace_std.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | // These need to be ordered first or the test, well, fails 18 | #include 19 | #include 20 | 21 | #include "ctest_common.hpp" 22 | 23 | using test_extents_type = std::extents; 24 | using test_mdspan_type = std::mdspan; 25 | using test_mdarray_type = std::experimental::mdarray; 26 | -------------------------------------------------------------------------------- /include/experimental/__p2389_bits/dims.hpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | #pragma once 18 | 19 | // backward compatibility import into experimental 20 | namespace MDSPAN_IMPL_STANDARD_NAMESPACE { 21 | namespace MDSPAN_IMPL_PROPOSED_NAMESPACE { 22 | 23 | template< ::std::size_t Rank, class IndexType = std::size_t> 24 | using dims = 25 | :: MDSPAN_IMPL_STANDARD_NAMESPACE :: dextents; 26 | 27 | } // namespace MDSPAN_IMPL_PROPOSED_NAMESPACE 28 | } // namespace MDSPAN_IMPL_STANDARD_NAMESPACE 29 | -------------------------------------------------------------------------------- /scripts/snl/gtest-clang-patch: -------------------------------------------------------------------------------- 1 | diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h 2 | index eeaef04e..5d6d678d 100644 3 | --- a/googletest/include/gtest/gtest-printers.h 4 | +++ b/googletest/include/gtest/gtest-printers.h 5 | @@ -528,7 +528,7 @@ int AppropriateResolution(FloatType val) { 6 | } else if (val >= 0.0001) { 7 | mulfor6 = 1e9; 8 | } 9 | - if (static_cast(val * mulfor6 + 0.5) / mulfor6 == val) return 6; 10 | + if (static_cast(static_cast(val * mulfor6 + 0.5)) / mulfor6 == val) return 6; 11 | } else if (val < 1e10) { 12 | FloatType divfor6 = 1.0; 13 | if (val >= 1e9) { // 1,000,000,000 to 9,999,999,999 14 | @@ -540,7 +540,7 @@ int AppropriateResolution(FloatType val) { 15 | } else if (val >= 1e6) { // 1,000,000 to 9,999,999 16 | divfor6 = 10; 17 | } 18 | - if (static_cast(val / divfor6 + 0.5) * divfor6 == val) return 6; 19 | + if (static_cast(static_cast(val / divfor6 + 0.5)) * divfor6 == val) return 6; 20 | } 21 | return full; 22 | } 23 | -------------------------------------------------------------------------------- /tests/test_element_access.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | #include 18 | 19 | #include 20 | 21 | 22 | TEST(TestElementAccess, element_access_with_std_array) { 23 | std::array a{}; 24 | Kokkos::mdspan> s(a.data()); 25 | ASSERT_EQ(MDSPAN_IMPL_OP(s, (std::array{1, 2})), 0); 26 | MDSPAN_IMPL_OP(s, (std::array{0, 1})) = 3.14; 27 | ASSERT_EQ(MDSPAN_IMPL_OP(s, (std::array{0, 1})), 3.14); 28 | } 29 | -------------------------------------------------------------------------------- /tests/libcxx-backports/mdspan/mdspan.mapping.verify.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 3 | // See https://llvm.org/LICENSE.txt for license information. 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 | // 6 | //===----------------------------------------------------------------------===// 7 | 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // template 13 | // class mdspan; 14 | // 15 | // Mandates: 16 | // - LayoutPolicy shall meet the layout mapping policy requirements ([mdspan.layout.policy.reqmts]) 17 | 18 | #include 19 | 20 | void not_layout_policy() { 21 | // expected-error-re@*:* {{static assertion failed {{.*}}mdspan: LayoutPolicy template parameter is invalid. A common mistake is to pass a layout mapping instead of a layout policy}} 22 | [[maybe_unused]] std::mdspan, std::layout_left::template mapping>> m; 23 | } 24 | -------------------------------------------------------------------------------- /tests/test_mdspan_conversion.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | 18 | #include 19 | 20 | #include 21 | 22 | 23 | TEST(TestMdspanConversionConst, test_mdspan_conversion_const) { 24 | std::array a{}; 25 | Kokkos::mdspan> s(a.data()); 26 | ASSERT_EQ(s.data_handle(), a.data()); 27 | MDSPAN_IMPL_OP(s, 0, 1) = 3.14; 28 | Kokkos::mdspan> c_s(s); 29 | ASSERT_EQ((MDSPAN_IMPL_OP(c_s, 0, 1)), 3.14); 30 | } 31 | -------------------------------------------------------------------------------- /compilation_tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | macro(add_compilation_test name) 3 | if(MDSPAN_TEST_LANGUAGE) 4 | set_source_files_properties(${name} PROPERTIES LANGUAGE ${MDSPAN_TEST_LANGUAGE}) 5 | endif() 6 | add_executable(${name} ${name}.cpp) 7 | target_link_libraries(${name} mdspan) 8 | endmacro() 9 | 10 | add_compilation_test(ctest_constructor_sfinae) 11 | add_compilation_test(ctest_extents_ctors) 12 | add_compilation_test(ctest_extents_type_check) 13 | add_compilation_test(ctest_mdarray_type_check) 14 | add_compilation_test(ctest_layout_type_check) 15 | add_compilation_test(ctest_layout_convertible) 16 | add_compilation_test(ctest_mdspan_convertible) 17 | add_compilation_test(ctest_standard_layout) 18 | add_compilation_test(ctest_trivially_copyable) 19 | if(NOT MDSPAN_ENABLE_CUDA) 20 | add_compilation_test(ctest_no_unique_address) 21 | add_compilation_test(ctest_compressed_pair_layout) 22 | endif() 23 | add_compilation_test(ctest_constexpr_dereference) 24 | if(NOT CMAKE_CXX_STANDARD STREQUAL "14") 25 | add_compilation_test(ctest_constexpr_submdspan) 26 | endif() 27 | add_compilation_test(ctest_constexpr_layouts) 28 | add_compilation_test(ctest_namespace_std) 29 | -------------------------------------------------------------------------------- /tests/test_mdspan_at.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | 23 | TEST(TestMdspanAt, test_mdspan_at) { 24 | std::array a{}; 25 | Kokkos::mdspan> s(a.data()); 26 | 27 | s.at(0, 0) = 3.14; 28 | s.at(std::array{1, 2}) = 2.72; 29 | ASSERT_EQ(s.at(0, 0), 3.14); 30 | ASSERT_EQ(s.at(std::array{1, 2}), 2.72); 31 | 32 | EXPECT_THROW(s.at(2, 3), std::out_of_range); 33 | EXPECT_THROW(s.at(std::array{3, 1}), std::out_of_range); 34 | } 35 | -------------------------------------------------------------------------------- /examples/godbolt_starter/godbolt_starter.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | #if defined(MDSPAN_IMPL_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) 18 | // https://godbolt.org/z/ehErvsTce 19 | #include 20 | #include 21 | 22 | 23 | int main() { 24 | std::array d{ 25 | 0, 5, 1, 26 | 3, 8, 4, 27 | 2, 7, 6, 28 | }; 29 | 30 | Kokkos::mdspan m{d.data(), Kokkos::extents{3, 3}}; 31 | 32 | for (std::size_t i = 0; i < m.extent(0); ++i) 33 | for (std::size_t j = 0; j < m.extent(1); ++j) 34 | std::cout << "m(" << i << ", " << j << ") == " << m(i, j) << "\n"; 35 | } 36 | #else 37 | int main() {} 38 | #endif 39 | -------------------------------------------------------------------------------- /include/experimental/__p0009_bits/dynamic_extent.hpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #pragma once 17 | 18 | #include "macros.hpp" 19 | 20 | #if defined(__cpp_lib_span) 21 | #include 22 | #endif 23 | 24 | #include // size_t 25 | #include // numeric_limits 26 | 27 | namespace MDSPAN_IMPL_STANDARD_NAMESPACE { 28 | #if defined(__cpp_lib_span) 29 | using std::dynamic_extent; 30 | #else 31 | MDSPAN_IMPL_INLINE_VARIABLE constexpr auto dynamic_extent = std::numeric_limits::max(); 32 | #endif 33 | } // namespace MDSPAN_IMPL_STANDARD_NAMESPACE 34 | 35 | //============================================================================================================== 36 | -------------------------------------------------------------------------------- /tests/libcxx-backports/default_accessor/default_accessor.element_type.verify.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 3 | // See https://llvm.org/LICENSE.txt for license information. 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 | // 6 | //===----------------------------------------------------------------------===// 7 | 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // template 13 | // class default_accessor; 14 | 15 | // ElementType is required to be a complete object type that is neither an abstract class type nor an array type. 16 | 17 | #include 18 | #include "../llvm_test_macros.h" 19 | 20 | class AbstractClass { 21 | public: 22 | virtual void method() = 0; 23 | }; 24 | 25 | void not_abstract_class() { 26 | // expected-error-re@*:* {{static assertion failed {{.*}}default_accessor: template argument may not be an abstract class}} 27 | [[maybe_unused]] std::default_accessor acc; 28 | } 29 | 30 | void not_array_type() { 31 | // expected-error-re@*:* {{static assertion failed {{.*}}default_accessor: template argument may not be an array type}} 32 | [[maybe_unused]] std::default_accessor acc; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /compilation_tests/ctest_constexpr_layouts.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include "ctest_common.hpp" 17 | 18 | #include 19 | 20 | 21 | // Only works with newer constexpr 22 | #if defined(MDSPAN_IMPL_USE_CONSTEXPR_14) && MDSPAN_IMPL_USE_CONSTEXPR_14 23 | 24 | constexpr std::ptrdiff_t 25 | layout_stride_simple(int i) { 26 | using map_t = Kokkos::layout_stride::template mapping< 27 | Kokkos::extents 28 | >; 29 | return map_t(Kokkos::extents{}, std::array{1})(i); 30 | } 31 | 32 | MDSPAN_STATIC_TEST( 33 | layout_stride_simple(0) == 0 34 | ); 35 | MDSPAN_STATIC_TEST( 36 | layout_stride_simple(1) == 1 37 | ); 38 | 39 | #endif // MDSPAN_IMPL_USE_CONSTEXPR_14 40 | -------------------------------------------------------------------------------- /tests/test_layout_preconditions.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2024) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include 17 | 18 | #include 19 | 20 | TEST(TestConvertingConstructionFromLayoutStride, precondition_failure) { 21 | using E = Kokkos::extents; 22 | 23 | const auto stride = Kokkos::layout_stride::mapping{E{}, std::array{2, 8}}; 24 | 25 | #if defined(MDSPAN_IMPL_HAS_CUDA) || defined(MDSPAN_IMPL_HAS_HIP) || defined(MDSPAN_IMPL_HAS_SYCL) 26 | ASSERT_DEATH(Kokkos::layout_left::mapping{stride}, ""); 27 | ASSERT_DEATH(Kokkos::layout_right::mapping{stride}, ""); 28 | #else 29 | ASSERT_DEATH(Kokkos::layout_left::mapping{stride}, "invalid strides"); 30 | ASSERT_DEATH(Kokkos::layout_right::mapping{stride}, "invalid strides"); 31 | #endif 32 | } 33 | -------------------------------------------------------------------------------- /comp_bench/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include(metabench) 3 | 4 | # C++ standards that our benchmark will actually support 5 | set(_cbench_supported_standards 17 20 23) 6 | 7 | # Obtain the subset that are actually supported by the compiler 8 | set(_cbench_standards "") 9 | foreach(_std IN LISTS _cbench_supported_standards) 10 | if ("cxx_std_${_std}" IN_LIST CMAKE_CXX_COMPILE_FEATURES) 11 | list(APPEND _cbench_standards "${_std}") 12 | endif() 13 | endforeach() 14 | 15 | message(STATUS "Using the following C++ standards for compiler benchmarking: ${_cbench_standards}") 16 | 17 | function(add_cxx_comparison name template range) 18 | 19 | set(all_datasets) 20 | foreach(std IN LISTS _cbench_standards) 21 | metabench_add_dataset( 22 | ${name}_${std} 23 | ${template} 24 | ${range} 25 | MEDIAN_OF 3 26 | ) 27 | target_link_libraries(${name}_${std} mdspan) 28 | # Set parenthesis operator regardless of which standard we are using 29 | # so we don't have to ifdef 30 | target_compile_definitions(${name}_${std} PRIVATE MDSPAN_USE_PAREN_OPERATOR=1) 31 | set_property(TARGET ${name}_${std} PROPERTY CXX_STANDARD ${std}) 32 | set(all_datasets ${all_datasets} ${name}_${std}) 33 | endforeach() 34 | 35 | metabench_add_chart(${name} DATASETS ${all_datasets}) 36 | endfunction() 37 | 38 | add_cxx_comparison(submdspan_chart "cbench_submdspan.cpp.erb" "[2, 4, 8, 16, 32]") 39 | -------------------------------------------------------------------------------- /compilation_tests/ctest_mdspan_convertible.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include "ctest_common.hpp" 17 | 18 | #include 19 | 20 | #include 21 | 22 | 23 | //============================================================================== 24 | // {{{1 25 | 26 | MDSPAN_STATIC_TEST( 27 | std::is_convertible< 28 | Kokkos::mdspan>, 29 | Kokkos::mdspan> 30 | >::value 31 | ); 32 | 33 | MDSPAN_STATIC_TEST( 34 | !std::is_convertible< 35 | Kokkos::mdspan>, 36 | Kokkos::mdspan> 37 | >::value 38 | ); 39 | 40 | // end mdspan }}}1 41 | //============================================================================== 42 | 43 | -------------------------------------------------------------------------------- /tests/libcxx-backports/default_accessor/default_accessor.ctor.default.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // Test default construction: 14 | // 15 | // constexpr default_accessor() noexcept = default; 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../llvm_test_macros.h" 23 | 24 | #include "../MinimalElementType.h" 25 | 26 | template 27 | constexpr void test_construction() { 28 | ASSERT_NOEXCEPT(std::default_accessor{}); 29 | [[maybe_unused]] std::default_accessor acc; 30 | static_assert(std::is_trivially_default_constructible_v>); 31 | } 32 | 33 | constexpr bool test() { 34 | test_construction(); 35 | test_construction(); 36 | test_construction(); 37 | test_construction(); 38 | return true; 39 | } 40 | 41 | int main(int, char**) { 42 | test(); 43 | static_assert(test()); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_left/layout_left.extents.verify.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // template 14 | // class layout_left::mapping; 15 | 16 | // If Extents is not a specialization of extents, then the program is 17 | // ill-formed. 18 | 19 | // Mandates: If Extents::rank_dynamic() == 0 is true, then the size of the 20 | // multidimensional index space Extents() is representable as a value of type 21 | // typename Extents::index_type. 22 | 23 | #include 24 | 25 | void not_extents() { 26 | // expected-error-re@*:* {{static assertion failed {{.*}}layout_left::mapping template argument must be a specialization of extents}} 27 | [[maybe_unused]] std::layout_left::mapping mapping; 28 | } 29 | 30 | void representable() { 31 | // expected-error-re@*:* {{static assertion failed {{.*}}layout_left::mapping product of static extents must be representable as index_type.}} 32 | [[maybe_unused]] std::layout_left::mapping> mapping; 33 | } 34 | -------------------------------------------------------------------------------- /include/experimental/mdspan: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | #pragma once 18 | 19 | #ifndef MDSPAN_IMPL_STANDARD_NAMESPACE 20 | #define MDSPAN_IMPL_STANDARD_NAMESPACE std 21 | #endif 22 | 23 | #ifndef MDSPAN_IMPL_PROPOSED_NAMESPACE 24 | #define MDSPAN_IMPL_PROPOSED_NAMESPACE experimental 25 | #endif 26 | 27 | #include "../mdspan/mdspan.hpp" 28 | 29 | // backward compatibility import into experimental 30 | namespace MDSPAN_IMPL_STANDARD_NAMESPACE { 31 | namespace MDSPAN_IMPL_PROPOSED_NAMESPACE { 32 | using ::MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan; 33 | using ::MDSPAN_IMPL_STANDARD_NAMESPACE::extents; 34 | using ::MDSPAN_IMPL_STANDARD_NAMESPACE::layout_left; 35 | using ::MDSPAN_IMPL_STANDARD_NAMESPACE::layout_right; 36 | using ::MDSPAN_IMPL_STANDARD_NAMESPACE::layout_stride; 37 | using ::MDSPAN_IMPL_STANDARD_NAMESPACE::default_accessor; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_right/layout_right.extents.verify.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // template 14 | // class layout_left::mapping; 15 | 16 | // If Extents is not a specialization of extents, then the program is 17 | // ill-formed. 18 | 19 | // Mandates: If Extents::rank_dynamic() == 0 is true, then the size of the 20 | // multidimensional index space Extents() is representable as a value of type 21 | // typename Extents::index_type. 22 | 23 | #include 24 | 25 | void not_extents() { 26 | // expected-error-re@*:* {{static assertion failed {{.*}}layout_right::mapping template argument must be a specialization of extents}} 27 | [[maybe_unused]] std::layout_right::mapping mapping; 28 | } 29 | 30 | void representable() { 31 | // expected-error-re@*:* {{static assertion failed {{.*}}layout_right::mapping product of static extents must be representable as index_type.}} 32 | [[maybe_unused]] std::layout_right::mapping> mapping; 33 | } 34 | -------------------------------------------------------------------------------- /.github/workflows/cmake-windows.yml: -------------------------------------------------------------------------------- 1 | name: CMake Windows 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | concurrency: 8 | group: ${ {github.event_name }}-${{ github.workflow }}-${{ github.ref }} 9 | cancel-in-progress: ${{github.event_name == 'pull_request'}} 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | test_cmake-windows: 15 | name: MSVC C++-17 16 | runs-on: windows-2022 17 | 18 | steps: 19 | - uses: ilammy/msvc-dev-cmd@v1 20 | 21 | - name: Create Build Environment 22 | run: cmake -E make_directory ${{github.workspace}}/mdspan-build 23 | 24 | - name: Check Out 25 | uses: actions/checkout@v6 26 | with: 27 | path: ${{github.workspace}}/mdspan-src 28 | 29 | - name: Configure CMake 30 | shell: bash 31 | working-directory: ${{github.workspace}}/mdspan-build 32 | run: cmake -DCMAKE_CXX_FLAGS=-EHsc $GITHUB_WORKSPACE/mdspan-src -DMDSPAN_CXX_STANDARD=17 -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/mdspan-install -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_EXAMPLES=ON 33 | 34 | - name: Build 35 | shell: bash 36 | working-directory: ${{github.workspace}}/mdspan-build 37 | run: cmake --build . --parallel 4 --config Debug 38 | 39 | - name: Test 40 | working-directory: ${{github.workspace}}/mdspan-build 41 | shell: bash 42 | run: ctest --output-on-failure 43 | 44 | - name: Install 45 | shell: bash 46 | working-directory: ${{github.workspace}}/mdspan-build 47 | run: cmake --build . --target install 48 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_stride/layout_stride.extents.verify.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // template 14 | // class layout_stride::mapping; 15 | 16 | // If Extents is not a specialization of extents, then the program is 17 | // ill-formed. 18 | 19 | // Mandates: If Extents::rank_dynamic() == 0 is true, then the size of the 20 | // multidimensional index space Extents() is representable as a value of type 21 | // typename Extents::index_type. 22 | 23 | #include 24 | #include "../llvm_test_macros.h" 25 | 26 | void not_extents() { 27 | // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed {{.*}}layout_stride::mapping template argument must be a specialization of extents}} 28 | [[maybe_unused]] std::layout_stride::mapping mapping; 29 | } 30 | 31 | void representable() { 32 | // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed {{.*}}layout_stride::mapping product of static extents must be representable as index_type.}} 33 | [[maybe_unused]] std::layout_stride::mapping> mapping; 34 | } 35 | -------------------------------------------------------------------------------- /tests/libcxx-backports/default_accessor/default_accessor.access.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // constexpr reference access(data_handle_type p, size_t i) const noexcept; 14 | // 15 | // Effects: Equivalent to: return p[i]; 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "../llvm_test_macros.h" 22 | 23 | #include "../MinimalElementType.h" 24 | 25 | template 26 | constexpr void test_access() { 27 | ElementPool, 10> data; 28 | T* ptr = data.get_ptr(); 29 | std::default_accessor acc; 30 | for(int i = 0; i < 10; i++) { 31 | static_assert(std::is_same_v::reference>); 32 | ASSERT_NOEXCEPT(acc.access(ptr, i)); 33 | assert(&acc.access(ptr, i) == ptr + i); 34 | } 35 | } 36 | 37 | constexpr bool test() { 38 | test_access(); 39 | test_access(); 40 | test_access(); 41 | test_access(); 42 | return true; 43 | } 44 | 45 | int main(int, char**) { 46 | test(); 47 | static_assert(test()); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /tests/libcxx-backports/default_accessor/default_accessor.offset.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept; 14 | // 15 | // Effects: Equivalent to: return p+i; 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "../llvm_test_macros.h" 22 | 23 | #include "../MinimalElementType.h" 24 | 25 | template 26 | constexpr void test_offset() { 27 | ElementPool, 10> data; 28 | T* ptr = data.get_ptr(); 29 | std::default_accessor acc; 30 | for(int i = 0; i < 10; i++) { 31 | static_assert(std::is_same_v::data_handle_type>); 32 | ASSERT_NOEXCEPT(acc.offset(ptr, i)); 33 | assert(acc.offset(ptr, i) == ptr + i); 34 | } 35 | } 36 | 37 | constexpr bool test() { 38 | test_offset(); 39 | test_offset(); 40 | test_offset(); 41 | test_offset(); 42 | return true; 43 | } 44 | 45 | int main(int, char**) { 46 | test(); 47 | static_assert(test()); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /tests/libcxx-backports/extents/dextents.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // template 13 | // using dextents = see below; 14 | // 15 | // Result: A type E that is a specialization of extents such that 16 | // E::rank() == Rank && E::rank() == E::rank_dynamic() is true, 17 | // and E::index_type denotes IndexType. 18 | 19 | #include 20 | #include 21 | 22 | #include "../llvm_test_macros.h" 23 | 24 | template 25 | void test_alias_template_dextents() { 26 | constexpr size_t D = std::dynamic_extent; 27 | ASSERT_SAME_TYPE(std::dextents, std::extents); 28 | ASSERT_SAME_TYPE(std::dextents, std::extents); 29 | ASSERT_SAME_TYPE(std::dextents, std::extents); 30 | ASSERT_SAME_TYPE(std::dextents, std::extents); 31 | ASSERT_SAME_TYPE(std::dextents, std::extents); 32 | } 33 | 34 | int main(int, char**) { 35 | test_alias_template_dextents(); 36 | test_alias_template_dextents(); 37 | test_alias_template_dextents(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /include/mdspan/mdspan.hpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | #ifndef MDSPAN_HPP_ 18 | #define MDSPAN_HPP_ 19 | 20 | #ifndef MDSPAN_IMPL_STANDARD_NAMESPACE 21 | #define MDSPAN_IMPL_STANDARD_NAMESPACE Kokkos 22 | #endif 23 | 24 | #ifndef MDSPAN_IMPL_PROPOSED_NAMESPACE 25 | #define MDSPAN_IMPL_PROPOSED_NAMESPACE Experimental 26 | #endif 27 | 28 | #include "../experimental/__p0009_bits/default_accessor.hpp" 29 | #include "../experimental/__p0009_bits/full_extent_t.hpp" 30 | #include "../experimental/__p0009_bits/mdspan.hpp" 31 | #include "../experimental/__p0009_bits/dynamic_extent.hpp" 32 | #include "../experimental/__p0009_bits/extents.hpp" 33 | #include "../experimental/__p0009_bits/layout_stride.hpp" 34 | #include "../experimental/__p0009_bits/layout_left.hpp" 35 | #include "../experimental/__p0009_bits/layout_right.hpp" 36 | #include "../experimental/__p0009_bits/macros.hpp" 37 | #if MDSPAN_HAS_CXX_17 38 | #include "../experimental/__p2642_bits/layout_padded.hpp" 39 | #include "../experimental/__p2630_bits/submdspan.hpp" 40 | #endif 41 | #include "../experimental/__p2389_bits/dims.hpp" 42 | 43 | #endif // MDSPAN_HPP_ 44 | -------------------------------------------------------------------------------- /tests/libcxx-backports/mdspan/mdspan.element_type.verify.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 3 | // See https://llvm.org/LICENSE.txt for license information. 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 | // 6 | //===----------------------------------------------------------------------===// 7 | 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // template 13 | // class mdspan; 14 | // 15 | // Mandates: 16 | // - ElementType is a complete object type that is neither an abstract class type nor an array type. 17 | // - is_same_v is true. 18 | 19 | #include 20 | 21 | class AbstractClass { 22 | public: 23 | virtual void method() = 0; 24 | }; 25 | 26 | void not_abstract_class() { 27 | // expected-error-re@*:* {{static assertion failed {{.*}}mdspan: ElementType template parameter may not be an abstract class}} 28 | [[maybe_unused]] std::mdspan> m; 29 | } 30 | 31 | void not_array_type() { 32 | // expected-error-re@*:* {{static assertion failed {{.*}}mdspan: ElementType template parameter may not be an array type}} 33 | [[maybe_unused]] std::mdspan> m; 34 | } 35 | 36 | void element_type_mismatch() { 37 | // expected-error-re@*:* {{static assertion failed {{.*}}mdspan: ElementType template parameter must match AccessorPolicy::element_type}} 38 | [[maybe_unused]] std::mdspan, std::layout_right, std::default_accessor> m; 39 | } 40 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_left/layout_left.ctor.default.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // Test default construction: 14 | // 15 | // constexpr mapping() noexcept = default; 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "../llvm_test_macros.h" 22 | 23 | template 24 | constexpr void test_construction() { 25 | using M = std::layout_left::mapping; 26 | ASSERT_NOEXCEPT(M{}); 27 | M m; 28 | E e; 29 | 30 | // check correct extents are returned 31 | ASSERT_NOEXCEPT(m.extents()); 32 | assert(m.extents() == e); 33 | 34 | // check required_span_size() 35 | typename E::index_type expected_size = 1; 36 | for (typename E::rank_type r = 0; r < E::rank(); r++) 37 | expected_size *= e.extent(r); 38 | assert(m.required_span_size() == expected_size); 39 | } 40 | 41 | constexpr bool test() { 42 | constexpr size_t D = std::dynamic_extent; 43 | test_construction>(); 44 | test_construction>(); 45 | test_construction>(); 46 | test_construction>(); 47 | test_construction>(); 48 | return true; 49 | } 50 | 51 | int main(int, char**) { 52 | test(); 53 | static_assert(test()); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_right/layout_right.ctor.default.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // Test default construction: 14 | // 15 | // constexpr mapping() noexcept = default; 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "../llvm_test_macros.h" 22 | 23 | template 24 | constexpr void test_construction() { 25 | using M = std::layout_right::mapping; 26 | ASSERT_NOEXCEPT(M{}); 27 | M m; 28 | E e; 29 | 30 | // check correct extents are returned 31 | ASSERT_NOEXCEPT(m.extents()); 32 | assert(m.extents() == e); 33 | 34 | // check required_span_size() 35 | typename E::index_type expected_size = 1; 36 | for (typename E::rank_type r = 0; r < E::rank(); r++) 37 | expected_size *= e.extent(r); 38 | assert(m.required_span_size() == expected_size); 39 | } 40 | 41 | constexpr bool test() { 42 | constexpr size_t D = std::dynamic_extent; 43 | test_construction>(); 44 | test_construction>(); 45 | test_construction>(); 46 | test_construction>(); 47 | test_construction>(); 48 | return true; 49 | } 50 | 51 | int main(int, char**) { 52 | test(); 53 | static_assert(test()); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /tests/libcxx-backports/default_accessor/default_accessor.types.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // template 14 | // struct default_accessor { 15 | // using offset_policy = default_accessor; 16 | // using element_type = ElementType; 17 | // using reference = ElementType&; 18 | // using data_handle_type = ElementType*; 19 | // ... 20 | // }; 21 | // 22 | // Each specialization of default_accessor is a trivially copyable type that models semiregular. 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "../llvm_test_macros.h" 31 | 32 | #include "../MinimalElementType.h" 33 | 34 | template 35 | void test() { 36 | using A = std::default_accessor; 37 | ASSERT_SAME_TYPE(typename A::offset_policy, A); 38 | ASSERT_SAME_TYPE(typename A::element_type, T); 39 | ASSERT_SAME_TYPE(typename A::reference, T&); 40 | ASSERT_SAME_TYPE(typename A::data_handle_type, T*); 41 | 42 | static_assert(std::semiregular); 43 | static_assert(std::is_trivially_copyable_v); 44 | 45 | LIBCPP_STATIC_ASSERT(std::is_empty_v); 46 | } 47 | 48 | int main(int, char**) { 49 | test(); 50 | test(); 51 | test(); 52 | test(); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /tests/libcxx-backports/MinimalElementType.h: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef TEST_STD_CONTAINERS_VIEWS_MDSPAN_MINIMAL_ELEMENT_TYPE_H 10 | #define TEST_STD_CONTAINERS_VIEWS_MDSPAN_MINIMAL_ELEMENT_TYPE_H 11 | 12 | #include 13 | 14 | // Idiosyncratic element type for mdspan 15 | // Make sure we don't assume copyable, default constructible, movable etc. 16 | struct MinimalElementType { 17 | int val; 18 | constexpr MinimalElementType() = delete; 19 | constexpr MinimalElementType(const MinimalElementType&) = delete; 20 | constexpr explicit MinimalElementType(int v) noexcept : val(v){} 21 | constexpr MinimalElementType& operator=(const MinimalElementType&) = delete; 22 | }; 23 | 24 | // Helper class to create pointer to MinimalElementType 25 | template 26 | struct ElementPool { 27 | constexpr ElementPool() { 28 | nc_ptr_ = std::allocator>().allocate(N); 29 | ptr_ = nc_ptr_; 30 | for (int i = 0; i != N; ++i) 31 | std::construct_at(nc_ptr_ + i, 42); 32 | } 33 | 34 | constexpr T* get_ptr() { return ptr_; } 35 | 36 | constexpr ~ElementPool() { 37 | for (int i = 0; i != N; ++i) 38 | std::destroy_at(nc_ptr_ + i); 39 | std::allocator>().deallocate(nc_ptr_, N); 40 | } 41 | 42 | private: 43 | std::remove_const_t* nc_ptr_; 44 | T* ptr_; 45 | }; 46 | 47 | #endif // TEST_STD_CONTAINERS_VIEWS_MDSPAN_MINIMAL_ELEMENT_TYPE_H 48 | -------------------------------------------------------------------------------- /include/experimental/__p0009_bits/default_accessor.hpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #pragma once 17 | 18 | #include "macros.hpp" 19 | 20 | #include // size_t 21 | 22 | namespace MDSPAN_IMPL_STANDARD_NAMESPACE { 23 | 24 | template 25 | struct default_accessor { 26 | 27 | using offset_policy = default_accessor; 28 | using element_type = ElementType; 29 | using reference = ElementType&; 30 | using data_handle_type = ElementType*; 31 | 32 | MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr default_accessor() noexcept = default; 33 | 34 | MDSPAN_TEMPLATE_REQUIRES( 35 | class OtherElementType, 36 | /* requires */ ( 37 | MDSPAN_IMPL_TRAIT(std::is_convertible, OtherElementType(*)[], element_type(*)[]) 38 | ) 39 | ) 40 | MDSPAN_INLINE_FUNCTION 41 | constexpr default_accessor(default_accessor) noexcept {} 42 | 43 | MDSPAN_INLINE_FUNCTION 44 | constexpr data_handle_type 45 | offset(data_handle_type p, size_t i) const noexcept { 46 | return p + i; 47 | } 48 | 49 | MDSPAN_FORCE_INLINE_FUNCTION 50 | constexpr reference access(data_handle_type p, size_t i) const noexcept { 51 | return p[i]; 52 | } 53 | 54 | }; 55 | 56 | } // end namespace MDSPAN_IMPL_STANDARD_NAMESPACE 57 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_left/layout_left.stride.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // constexpr index_type stride(rank_type i) const noexcept; 14 | // 15 | // Constraints: extents_type::rank() > 0 is true. 16 | // 17 | // Preconditions: i < extents_type::rank() is true. 18 | // 19 | // Returns: extents().rev-prod-of-extents(i). 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "../llvm_test_macros.h" 27 | 28 | template 29 | constexpr void test_stride(std::array strides, Args... args) { 30 | using M = std::layout_left::mapping; 31 | M m(E(args...)); 32 | 33 | ASSERT_NOEXCEPT(m.stride(0)); 34 | for (size_t r = 0; r < E::rank(); r++) 35 | assert(strides[r] == m.stride(r)); 36 | } 37 | 38 | constexpr bool test() { 39 | constexpr size_t D = std::dynamic_extent; 40 | test_stride>(std::array{1}, 7); 41 | test_stride>(std::array{1}); 42 | test_stride>(std::array{1, 7}); 43 | test_stride>(std::array{1, 7, 56, 504}, 7, 9, 10); 44 | return true; 45 | } 46 | 47 | int main(int, char**) { 48 | test(); 49 | static_assert(test()); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_right/layout_right.stride.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // constexpr index_type stride(rank_type i) const noexcept; 14 | // 15 | // Constraints: extents_type::rank() > 0 is true. 16 | // 17 | // Preconditions: i < extents_type::rank() is true. 18 | // 19 | // Returns: extents().rev-prod-of-extents(i). 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "../llvm_test_macros.h" 27 | 28 | template 29 | constexpr void test_stride(std::array strides, Args... args) { 30 | using M = std::layout_right::mapping; 31 | M m(E(args...)); 32 | 33 | ASSERT_NOEXCEPT(m.stride(0)); 34 | for (size_t r = 0; r < E::rank(); r++) 35 | assert(strides[r] == m.stride(r)); 36 | } 37 | 38 | constexpr bool test() { 39 | constexpr size_t D = std::dynamic_extent; 40 | test_stride>(std::array{1}, 7); 41 | test_stride>(std::array{1}); 42 | test_stride>(std::array{8, 1}); 43 | test_stride>(std::array{720, 90, 10, 1}, 7, 9, 10); 44 | return true; 45 | } 46 | 47 | int main(int, char**) { 48 | test(); 49 | static_assert(test()); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /include/experimental/__p2630_bits/strided_slice.hpp: -------------------------------------------------------------------------------- 1 | 2 | //@HEADER 3 | // ************************************************************************ 4 | // 5 | // Kokkos v. 4.0 6 | // Copyright (2022) National Technology & Engineering 7 | // Solutions of Sandia, LLC (NTESS). 8 | // 9 | // Under the terms of Contract DE-NA0003525 with NTESS, 10 | // the U.S. Government retains certain rights in this software. 11 | // 12 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 13 | // See https://kokkos.org/LICENSE for license information. 14 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 15 | // 16 | //@HEADER 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | namespace MDSPAN_IMPL_STANDARD_NAMESPACE { 23 | 24 | namespace detail { 25 | template 26 | struct mdspan_is_integral_constant: std::false_type {}; 27 | 28 | template 29 | struct mdspan_is_integral_constant>: std::true_type {}; 30 | } 31 | 32 | // Slice Specifier allowing for strides and compile time extent 33 | template 34 | struct strided_slice { 35 | using offset_type = OffsetType; 36 | using extent_type = ExtentType; 37 | using stride_type = StrideType; 38 | 39 | MDSPAN_IMPL_NO_UNIQUE_ADDRESS OffsetType offset{}; 40 | MDSPAN_IMPL_NO_UNIQUE_ADDRESS ExtentType extent{}; 41 | MDSPAN_IMPL_NO_UNIQUE_ADDRESS StrideType stride{}; 42 | 43 | static_assert(std::is_integral_v || detail::mdspan_is_integral_constant::value); 44 | static_assert(std::is_integral_v || detail::mdspan_is_integral_constant::value); 45 | static_assert(std::is_integral_v || detail::mdspan_is_integral_constant::value); 46 | }; 47 | 48 | } // MDSPAN_IMPL_STANDARD_NAMESPACE 49 | -------------------------------------------------------------------------------- /include/experimental/__p2630_bits/submdspan.hpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | #pragma once 18 | 19 | #include "submdspan_extents.hpp" 20 | #include "submdspan_mapping.hpp" 21 | 22 | namespace MDSPAN_IMPL_STANDARD_NAMESPACE { 23 | template 25 | MDSPAN_INLINE_FUNCTION 26 | constexpr auto 27 | submdspan(const mdspan &src, 28 | SliceSpecifiers... slices) { 29 | const auto sub_submdspan_mapping_result = submdspan_mapping(src.mapping(), slices...); 30 | // NVCC has a problem with the deduction so lets figure out the type 31 | using sub_mapping_t = std::remove_cv_t; 32 | using sub_extents_t = typename sub_mapping_t::extents_type; 33 | using sub_layout_t = typename sub_mapping_t::layout_type; 34 | using sub_accessor_t = typename AccessorPolicy::offset_policy; 35 | return mdspan( 36 | src.accessor().offset(src.data_handle(), sub_submdspan_mapping_result.offset), 37 | sub_submdspan_mapping_result.mapping, 38 | sub_accessor_t(src.accessor())); 39 | } 40 | } // namespace MDSPAN_IMPL_STANDARD_NAMESPACE 41 | -------------------------------------------------------------------------------- /tests/libcxx-backports/ConvertibleToIntegral.h: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef TEST_STD_CONTAINERS_VIEWS_MDSPAN_CONVERTIBLE_TO_INTEGRAL_H 10 | #define TEST_STD_CONTAINERS_VIEWS_MDSPAN_CONVERTIBLE_TO_INTEGRAL_H 11 | 12 | struct IntType { 13 | int val; 14 | constexpr IntType() = default; 15 | constexpr IntType(int v) noexcept : val(v){} 16 | 17 | constexpr bool operator==(const IntType& rhs) const { return val == rhs.val; } 18 | constexpr operator int() const noexcept { return val; } 19 | constexpr operator unsigned char() const { return val; } 20 | constexpr operator char() const noexcept { return val; } 21 | }; 22 | 23 | // only non-const convertible 24 | struct IntTypeNC { 25 | int val; 26 | constexpr IntTypeNC() = default; 27 | constexpr IntTypeNC(int v) noexcept : val(v){} 28 | 29 | constexpr bool operator==(const IntType& rhs) const { return val == rhs.val; } 30 | constexpr operator int() noexcept { return val; } 31 | constexpr operator unsigned() { return val; } 32 | constexpr operator char() noexcept { return val; } 33 | }; 34 | 35 | // weird configurability of convertibility to int 36 | template 37 | struct IntConfig { 38 | int val; 39 | constexpr explicit IntConfig(int val_):val(val_){} 40 | constexpr operator int() noexcept(ctor_nt_nc) requires(conv_nc) { return val; } 41 | constexpr operator int() const noexcept(ctor_nt_c) requires(conv_c) { return val; } 42 | }; 43 | 44 | #endif // TEST_STD_CONTAINERS_VIEWS_MDSPAN_CONVERTIBLE_TO_INTEGRAL_H 45 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_left/layout_left.required_span_size.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // constexpr index_type required_span_size() const noexcept; 14 | // 15 | // Returns: extents().fwd-prod-of-extents(extents_type::rank()). 16 | 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../llvm_test_macros.h" 23 | 24 | template 25 | constexpr void test_required_span_size(E e, typename E::index_type expected_size) { 26 | using M = std::layout_left::mapping; 27 | const M m(e); 28 | 29 | ASSERT_NOEXCEPT(m.required_span_size()); 30 | assert(m.required_span_size() == expected_size); 31 | } 32 | 33 | constexpr bool test() { 34 | constexpr size_t D = std::dynamic_extent; 35 | test_required_span_size(std::extents(), 1); 36 | test_required_span_size(std::extents(0), 0); 37 | test_required_span_size(std::extents(1), 1); 38 | test_required_span_size(std::extents(7), 7); 39 | test_required_span_size(std::extents(), 7); 40 | test_required_span_size(std::extents(), 56); 41 | test_required_span_size(std::extents(7, 9, 10), 5040); 42 | test_required_span_size(std::extents(9, 10), 720); 43 | test_required_span_size(std::extents(9, 10), 0); 44 | return true; 45 | } 46 | 47 | int main(int, char**) { 48 | test(); 49 | static_assert(test()); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_right/layout_right.required_span_size.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // constexpr index_type required_span_size() const noexcept; 14 | // 15 | // Returns: extents().fwd-prod-of-extents(extents_type::rank()). 16 | 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../llvm_test_macros.h" 23 | 24 | template 25 | constexpr void test_required_span_size(E e, typename E::index_type expected_size) { 26 | using M = std::layout_right::mapping; 27 | const M m(e); 28 | 29 | ASSERT_NOEXCEPT(m.required_span_size()); 30 | assert(m.required_span_size() == expected_size); 31 | } 32 | 33 | constexpr bool test() { 34 | constexpr size_t D = std::dynamic_extent; 35 | test_required_span_size(std::extents(), 1); 36 | test_required_span_size(std::extents(0), 0); 37 | test_required_span_size(std::extents(1), 1); 38 | test_required_span_size(std::extents(7), 7); 39 | test_required_span_size(std::extents(), 7); 40 | test_required_span_size(std::extents(), 56); 41 | test_required_span_size(std::extents(7, 9, 10), 5040); 42 | test_required_span_size(std::extents(9, 10), 720); 43 | test_required_span_size(std::extents(9, 10), 0); 44 | return true; 45 | } 46 | 47 | int main(int, char**) { 48 | test(); 49 | static_assert(test()); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /tests/libcxx-backports/extents/ctad.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // template 13 | // explicit extents(Integrals...) -> see below; 14 | // Constraints: (is_convertible_v && ...) is true. 15 | // 16 | // Remarks: The deduced type is dextents. 17 | 18 | #include 19 | #include 20 | 21 | #include "../ConvertibleToIntegral.h" 22 | #include "../llvm_test_macros.h" 23 | 24 | struct NoDefaultCtorIndex { 25 | size_t value; 26 | constexpr NoDefaultCtorIndex() = delete; 27 | constexpr NoDefaultCtorIndex(size_t val) : value(val){} 28 | constexpr operator size_t() const noexcept { return value; } 29 | }; 30 | 31 | template 32 | constexpr void test(E e, Expected expected) { 33 | ASSERT_SAME_TYPE(E, Expected); 34 | assert(e == expected); 35 | } 36 | 37 | constexpr bool test() { 38 | constexpr std::size_t D = std::dynamic_extent; 39 | 40 | test(std::extents(), std::extents()); 41 | test(std::extents(1), std::extents(1)); 42 | test(std::extents(1, 2u), std::extents(1, 2u)); 43 | test(std::extents(1, 2u, 3, 4, 5, 6, 7, 8, 9), 44 | std::extents(1, 2u, 3, 4, 5, 6, 7, 8, 9)); 45 | test(std::extents(NoDefaultCtorIndex{1}, NoDefaultCtorIndex{2}), std::extents(1, 2)); 46 | return true; 47 | } 48 | 49 | int main(int, char**) { 50 | test(); 51 | static_assert(test()); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_left/layout_left.ctor.extents.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // constexpr mapping(const extents_type&) noexcept; 14 | // 15 | // Preconditions: The size of the multidimensional index space e is representable 16 | // as a value of type index_type ([basic.fundamental]). 17 | // 18 | // Effects: Direct-non-list-initializes extents_ with e. 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../llvm_test_macros.h" 25 | 26 | template 27 | constexpr void test_construction(E e) { 28 | using M = std::layout_left::mapping; 29 | ASSERT_NOEXCEPT(M{e}); 30 | M m(e); 31 | 32 | // check correct extents are returned 33 | ASSERT_NOEXCEPT(m.extents()); 34 | assert(m.extents() == e); 35 | 36 | // check required_span_size() 37 | typename E::index_type expected_size = 1; 38 | for (typename E::rank_type r = 0; r < E::rank(); r++) 39 | expected_size *= e.extent(r); 40 | assert(m.required_span_size() == expected_size); 41 | } 42 | 43 | constexpr bool test() { 44 | constexpr size_t D = std::dynamic_extent; 45 | test_construction(std::extents()); 46 | test_construction(std::extents(7)); 47 | test_construction(std::extents()); 48 | test_construction(std::extents()); 49 | test_construction(std::extents(7, 9, 10)); 50 | return true; 51 | } 52 | 53 | int main(int, char**) { 54 | test(); 55 | static_assert(test()); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_right/layout_right.ctor.extents.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // constexpr mapping(const extents_type&) noexcept; 14 | // 15 | // Preconditions: The size of the multidimensional index space e is representable 16 | // as a value of type index_type ([basic.fundamental]). 17 | // 18 | // Effects: Direct-non-list-initializes extents_ with e. 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../llvm_test_macros.h" 25 | 26 | template 27 | constexpr void test_construction(E e) { 28 | using M = std::layout_right::mapping; 29 | ASSERT_NOEXCEPT(M{e}); 30 | M m(e); 31 | 32 | // check correct extents are returned 33 | ASSERT_NOEXCEPT(m.extents()); 34 | assert(m.extents() == e); 35 | 36 | // check required_span_size() 37 | typename E::index_type expected_size = 1; 38 | for (typename E::rank_type r = 0; r < E::rank(); r++) 39 | expected_size *= e.extent(r); 40 | assert(m.required_span_size() == expected_size); 41 | } 42 | 43 | constexpr bool test() { 44 | constexpr size_t D = std::dynamic_extent; 45 | test_construction(std::extents()); 46 | test_construction(std::extents(7)); 47 | test_construction(std::extents()); 48 | test_construction(std::extents()); 49 | test_construction(std::extents(7, 9, 10)); 50 | return true; 51 | } 52 | 53 | int main(int, char**) { 54 | test(); 55 | static_assert(test()); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_stride/layout_stride.stride.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // constexpr index_type stride(rank_type i) const noexcept; 14 | // 15 | // Constraints: extents_type::rank() > 0 is true. 16 | // 17 | // Preconditions: i < extents_type::rank() is true. 18 | // 19 | // Returns: extents().rev-prod-of-extents(i). 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "../llvm_test_macros.h" 27 | 28 | template 29 | constexpr void test_stride(std::array strides, Args... args) { 30 | using M = std::layout_stride::mapping; 31 | M m(E(args...), strides); 32 | 33 | ASSERT_NOEXCEPT(m.stride(0)); 34 | for (size_t r = 0; r < E::rank(); r++) 35 | assert(strides[r] == m.stride(r)); 36 | 37 | ASSERT_NOEXCEPT(m.strides()); 38 | auto strides_out = m.strides(); 39 | static_assert(std::is_same_v>); 40 | for (size_t r = 0; r < E::rank(); r++) 41 | assert(strides[r] == strides_out[r]); 42 | } 43 | 44 | constexpr bool test() { 45 | constexpr size_t D = std::dynamic_extent; 46 | test_stride>(std::array{1}, 7); 47 | test_stride>(std::array{1}); 48 | test_stride>(std::array{8, 1}); 49 | test_stride>(std::array{720, 90, 10, 1}, 7, 9, 10); 50 | return true; 51 | } 52 | 53 | int main(int, char**) { 54 | test(); 55 | static_assert(test()); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /tests/libcxx-backports/extents/ctor_default.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // Test default construction: 13 | // 14 | // constexpr extents() noexcept = default; 15 | // 16 | // Remarks: since the standard uses an exposition only array member, dynamic extents 17 | // need to be zero intialized! 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "../ConvertibleToIntegral.h" 24 | #include "CtorTestCombinations.h" 25 | #include "../llvm_test_macros.h" 26 | 27 | struct DefaultCtorTest { 28 | template 29 | static constexpr void test_construction(AllExtents all_ext, Extents, std::index_sequence) { 30 | // This function gets called twice: once with Extents being just the dynamic ones, and once with all the extents specified. 31 | // We only test during the all extent case, since then Indices is the correct number. This allows us to reuse the same 32 | // testing machinery used in other constructor tests. 33 | if constexpr (sizeof...(Indices) == E::rank()) { 34 | ASSERT_NOEXCEPT(E{}); 35 | // Need to construct new expected values, replacing dynamic values with 0 36 | std::array expected_exts{ 37 | ((E::static_extent(Indices) == std::dynamic_extent) 38 | ? typename AllExtents::value_type(0) 39 | : all_ext[Indices])...}; 40 | test_runtime_observers(E{}, expected_exts); 41 | } 42 | } 43 | }; 44 | 45 | int main(int, char**) { 46 | test_index_type_combo(); 47 | static_assert(test_index_type_combo()); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /tests/test_mdspan_size.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace { 25 | 26 | 27 | template 28 | std::size_t product_of_extents(const Extents& e) 29 | { 30 | size_t prod = 1; 31 | for(std::size_t r = 0; r < e.rank(); ++r) { 32 | prod *= static_cast(e.extent(r)); 33 | } 34 | return prod; 35 | } 36 | 37 | template 38 | void test_mdspan_size(std::vector& storage, Extents&& e) 39 | { 40 | using extents_type = std::remove_cv_t>; 41 | using mdspan_t = Kokkos::mdspan; 42 | using size_type = typename mdspan_t::size_type; 43 | const size_type min_storage_size = static_cast(product_of_extents(e)); 44 | if(storage.size() < min_storage_size) { 45 | storage.resize(min_storage_size); 46 | } 47 | mdspan_t m(storage.data(), std::forward(e)); 48 | 49 | static_assert(std::is_same::value, 50 | "The return type of mdspan::size() must be size_type."); 51 | 52 | // m.size() must not overflow, as long as the product of extents 53 | // is representable as a value of type size_type. 54 | ASSERT_EQ( min_storage_size, m.size()); 55 | } 56 | 57 | TEST(TestMdspan, MdspanSizeReturnTypeAndPrecondition) 58 | { 59 | (void) test_info_; 60 | std::vector storage; 61 | 62 | static_assert(std::numeric_limits::max() == 127, "max int8_t != 127"); 63 | test_mdspan_size(storage, Kokkos::extents{}); // 12 * 11 == 132 64 | } 65 | 66 | } // namespace (anonymous) 67 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_stride/layout_stride.is_exhaustive_corner_case.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // constexpr bool is_exhaustive() const noexcept; 14 | // 15 | // Returns: 16 | // - true if rank_ is 0. 17 | // - Otherwise, true if there is a permutation P of the integers in the range [0, rank_) such that 18 | // stride(p0) equals 1, and stride(pi) equals stride(pi_1) * extents().extent(pi_1) for i in the 19 | // range [1, rank_), where pi is the ith element of P. 20 | // - Otherwise, false. 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "../llvm_test_macros.h" 28 | 29 | template 30 | constexpr void 31 | test_layout_mapping_stride(E ext, std::array strides, bool exhaustive) { 32 | using M = std::layout_stride::template mapping; 33 | M m(ext, strides); 34 | assert(m.is_exhaustive() == exhaustive); 35 | } 36 | 37 | constexpr bool test() { 38 | constexpr size_t D = std::dynamic_extent; 39 | test_layout_mapping_stride(std::extents(), std::array{1}, true); 40 | test_layout_mapping_stride(std::extents(0), std::array{3}, false); 41 | test_layout_mapping_stride(std::extents(), std::array{6, 2}, true); 42 | test_layout_mapping_stride(std::extents(3, 0), std::array{6, 2}, false); 43 | test_layout_mapping_stride(std::extents(0, 0), std::array{6, 2}, false); 44 | test_layout_mapping_stride( 45 | std::extents(3, 3, 0, 3), std::array{3, 1, 27, 9}, true); 46 | test_layout_mapping_stride(std::extents(0, 3, 3, 3), std::array{3, 1, 27, 9}, false); 47 | return true; 48 | } 49 | 50 | int main(int, char**) { 51 | test(); 52 | static_assert(test()); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_left/layout_left.properties.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // namespace std { 14 | // template 15 | // class layout_left::mapping { 16 | // 17 | // ... 18 | // static constexpr bool is_always_unique() noexcept { return true; } 19 | // static constexpr bool is_always_exhaustive() noexcept { return true; } 20 | // static constexpr bool is_always_strided() noexcept { return true; } 21 | // 22 | // static constexpr bool is_unique() noexcept { return true; } 23 | // static constexpr bool is_exhaustive() noexcept { return true; } 24 | // static constexpr bool is_strided() noexcept { return true; } 25 | // ... 26 | // }; 27 | // } 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "../llvm_test_macros.h" 35 | 36 | template 37 | constexpr void test_layout_mapping_left() { 38 | using M = std::layout_left::template mapping; 39 | assert(M::is_unique() == true); 40 | assert(M::is_exhaustive() == true); 41 | assert(M::is_strided() == true); 42 | assert(M::is_always_unique() == true); 43 | assert(M::is_always_exhaustive() == true); 44 | assert(M::is_always_strided() == true); 45 | ASSERT_NOEXCEPT(std::declval().is_unique()); 46 | ASSERT_NOEXCEPT(std::declval().is_exhaustive()); 47 | ASSERT_NOEXCEPT(std::declval().is_strided()); 48 | ASSERT_NOEXCEPT(M::is_always_unique()); 49 | ASSERT_NOEXCEPT(M::is_always_exhaustive()); 50 | ASSERT_NOEXCEPT(M::is_always_strided()); 51 | } 52 | 53 | constexpr bool test() { 54 | constexpr size_t D = std::dynamic_extent; 55 | test_layout_mapping_left>(); 56 | test_layout_mapping_left>(); 57 | test_layout_mapping_left>(); 58 | test_layout_mapping_left>(); 59 | return true; 60 | } 61 | 62 | int main(int, char**) { 63 | test(); 64 | static_assert(test()); 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_right/layout_right.properties.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // namespace std { 14 | // template 15 | // class layout_right::mapping { 16 | // 17 | // ... 18 | // static constexpr bool is_always_unique() noexcept { return true; } 19 | // static constexpr bool is_always_exhaustive() noexcept { return true; } 20 | // static constexpr bool is_always_strided() noexcept { return true; } 21 | // 22 | // static constexpr bool is_unique() noexcept { return true; } 23 | // static constexpr bool is_exhaustive() noexcept { return true; } 24 | // static constexpr bool is_strided() noexcept { return true; } 25 | // ... 26 | // }; 27 | // } 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "../llvm_test_macros.h" 35 | 36 | template 37 | constexpr void test_layout_mapping_right() { 38 | using M = std::layout_right::template mapping; 39 | assert(M::is_unique() == true); 40 | assert(M::is_exhaustive() == true); 41 | assert(M::is_strided() == true); 42 | assert(M::is_always_unique() == true); 43 | assert(M::is_always_exhaustive() == true); 44 | assert(M::is_always_strided() == true); 45 | ASSERT_NOEXCEPT(std::declval().is_unique()); 46 | ASSERT_NOEXCEPT(std::declval().is_exhaustive()); 47 | ASSERT_NOEXCEPT(std::declval().is_strided()); 48 | ASSERT_NOEXCEPT(M::is_always_unique()); 49 | ASSERT_NOEXCEPT(M::is_always_exhaustive()); 50 | ASSERT_NOEXCEPT(M::is_always_strided()); 51 | } 52 | 53 | constexpr bool test() { 54 | constexpr size_t D = std::dynamic_extent; 55 | test_layout_mapping_right>(); 56 | test_layout_mapping_right>(); 57 | test_layout_mapping_right>(); 58 | test_layout_mapping_right>(); 59 | return true; 60 | } 61 | 62 | int main(int, char**) { 63 | test(); 64 | static_assert(test()); 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_stride/layout_stride.required_span_size.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // Let REQUIRED-SPAN-SIZE(e, strides) be: 14 | // - 1, if e.rank() == 0 is true, 15 | // - otherwise 0, if the size of the multidimensional index space e is 0, 16 | // - otherwise 1 plus the sum of products of (e.extent(r) - 1) and strides[r] for all r in the range [0, e.rank()). 17 | 18 | // constexpr index_type required_span_size() const noexcept; 19 | // 20 | // Returns: REQUIRED-SPAN-SIZE(extents(), strides_). 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "../llvm_test_macros.h" 27 | 28 | template 29 | constexpr void test_required_span_size(E e, std::array strides, typename E::index_type expected_size) { 30 | using M = std::layout_stride::mapping; 31 | const M m(e, strides); 32 | 33 | ASSERT_NOEXCEPT(m.required_span_size()); 34 | assert(m.required_span_size() == expected_size); 35 | } 36 | 37 | constexpr bool test() { 38 | constexpr size_t D = std::dynamic_extent; 39 | test_required_span_size(std::extents(), std::array{}, 1); 40 | test_required_span_size(std::extents(0), std::array{5}, 0); 41 | test_required_span_size(std::extents(1), std::array{5}, 1); 42 | test_required_span_size(std::extents(7), std::array{5}, 31); 43 | test_required_span_size(std::extents(), std::array{5}, 31); 44 | test_required_span_size(std::extents(), std::array{20, 2}, 135); 45 | test_required_span_size( 46 | std::extents(7, 9, 10), std::array{1, 7, 7 * 8, 7 * 8 * 9}, 5040); 47 | test_required_span_size(std::extents(9, 10), std::array{1, 7, 7 * 8, 7 * 8 * 9}, 5034); 48 | test_required_span_size(std::extents(9, 10), std::array{1, 7, 7 * 8, 7 * 8 * 9}, 0); 49 | return true; 50 | } 51 | 52 | int main(int, char**) { 53 | test(); 54 | static_assert(test()); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /tests/test_mdarray_to_mdspan.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | 22 | namespace KokkosEx = MDSPAN_IMPL_STANDARD_NAMESPACE::MDSPAN_IMPL_PROPOSED_NAMESPACE; 23 | 24 | MDSPAN_IMPL_INLINE_VARIABLE constexpr auto dyn = Kokkos::dynamic_extent; 25 | 26 | template 27 | struct MDArrayToMDSpanOperatorTest { 28 | using mdspan_t = MDSpan; 29 | using c_mdspan_t = Kokkos::mdspan; 32 | static void test_check(mdspan_t mds, MDArray& mda) { 33 | ASSERT_EQ(mds.data_handle(), mda.data()); 34 | ASSERT_EQ(mds.extents(), mda.extents()); 35 | ASSERT_EQ(mds.mapping(), mda.mapping()); 36 | } 37 | static void test_check_const(c_mdspan_t mds, const MDArray& mda) { 38 | ASSERT_EQ(mds.data_handle(), mda.data()); 39 | ASSERT_EQ(mds.extents(), mda.extents()); 40 | ASSERT_EQ(mds.mapping(), mda.mapping()); 41 | } 42 | template 43 | static void test(ConstrArgs ... args) { 44 | MDArray a(args...); 45 | test_check(a, a); 46 | test_check(a.to_mdspan(), a); 47 | const MDArray& c_a = a; 48 | test_check_const(c_a, a); 49 | test_check_const(c_a.to_mdspan(), a); 50 | } 51 | }; 52 | 53 | TEST(TestMDArray,mdarray_to_mdspan) { 54 | MDArrayToMDSpanOperatorTest>, 55 | KokkosEx::mdarray>>::test( 56 | 100 57 | ); 58 | MDArrayToMDSpanOperatorTest>, 59 | KokkosEx::mdarray>>::test( 60 | 100 61 | ); 62 | } 63 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_stride/layout_stride.ctor.default.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // Test default construction: 14 | // 15 | // constexpr mapping() noexcept; 16 | // 17 | // 18 | // Preconditions: layout_right::mapping().required_span_size() is representable as a value of type index_type ([basic.fundamental]). 19 | // 20 | // Effects: Direct-non-list-initializes extents_ with extents_type(), and for all d in the range [0, rank_), 21 | // direct-non-list-initializes strides_[d] with layout_right::mapping().stride(d). 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "../llvm_test_macros.h" 28 | 29 | template 30 | constexpr void test_construction() { 31 | using M = std::layout_stride::mapping; 32 | ASSERT_NOEXCEPT(M{}); 33 | M m; 34 | E e; 35 | 36 | // check correct extents are returned 37 | ASSERT_NOEXCEPT(m.extents()); 38 | assert(m.extents() == e); 39 | 40 | // check required_span_size() 41 | typename E::index_type expected_size = 1; 42 | for (typename E::rank_type r = 0; r < E::rank(); r++) 43 | expected_size *= e.extent(r); 44 | assert(m.required_span_size() == expected_size); 45 | 46 | // check strides: node stride function is constrained on rank>0, e.extent(r) is not 47 | auto strides = m.strides(); 48 | ASSERT_NOEXCEPT(m.strides()); 49 | if constexpr (E::rank() > 0) { 50 | std::layout_right::mapping m_right; 51 | for (typename E::rank_type r = 0; r < E::rank(); r++) { 52 | assert(m.stride(r) == m_right.stride(r)); 53 | assert(strides[r] == m.stride(r)); 54 | } 55 | } 56 | } 57 | 58 | constexpr bool test() { 59 | constexpr size_t D = std::dynamic_extent; 60 | test_construction>(); 61 | test_construction>(); 62 | test_construction>(); 63 | test_construction>(); 64 | test_construction>(); 65 | test_construction>(); 66 | return true; 67 | } 68 | 69 | int main(int, char**) { 70 | test(); 71 | static_assert(test()); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /tests/libcxx-backports/mdspan/mdspan.swap.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | // 12 | // friend constexpr void swap(mdspan& x, mdspan& y) noexcept; 13 | // 14 | // Effects: Equivalent to: 15 | // swap(x.ptr_, y.ptr_); 16 | // swap(x.map_, y.map_); 17 | // swap(x.acc_, y.acc_); 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../llvm_test_macros.h" 25 | 26 | #include "../MinimalElementType.h" 27 | #include "../CustomTestLayouts.h" 28 | 29 | template 30 | constexpr void test_swap(MDS a, MDS b) { 31 | auto org_a = a; 32 | auto org_b = b; 33 | swap(a, b); 34 | assert(a.extents() == org_b.extents()); 35 | assert(b.extents() == org_a.extents()); 36 | if constexpr (std::equality_comparable) { 37 | assert(a.mapping() == org_b.mapping()); 38 | assert(b.mapping() == org_a.mapping()); 39 | } 40 | if constexpr (std::equality_comparable) { 41 | assert(a.data_handle() == org_b.data_handle()); 42 | assert(b.data_handle() == org_a.data_handle()); 43 | } 44 | // This check uses a side effect of layout_wrapping_integral::swap to make sure 45 | // mdspan calls the underlying components' swap via ADL 46 | #if MDSPAN_HAS_CXX23 47 | if !consteval { 48 | if constexpr (std::is_same_v>) { 49 | assert(MDS::mapping_type::swap_counter() > 0); 50 | } 51 | } 52 | #endif 53 | } 54 | 55 | constexpr bool test() { 56 | using extents_t = std::extents; 57 | float data_a[1024]; 58 | float data_b[1024]; 59 | { 60 | std::mdspan a(data_a, extents_t(12)); 61 | std::mdspan b(data_b, extents_t(5)); 62 | test_swap(a, b); 63 | } 64 | { 65 | layout_wrapping_integral<4>::template mapping map_a(extents_t(12), not_extents_constructible_tag()), 66 | map_b(extents_t(5), not_extents_constructible_tag()); 67 | std::mdspan a(data_a, map_a); 68 | std::mdspan b(data_b, map_b); 69 | test_swap(a, b); 70 | } 71 | return true; 72 | } 73 | 74 | int main(int, char**) { 75 | test(); 76 | static_assert(test()); 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_stride/layout_stride.deduction.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | // ADDITIONAL_COMPILE_FLAGS: -Wno-ctad-maybe-unsupported 10 | 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "../llvm_test_macros.h" 19 | 20 | // mdspan 21 | 22 | // layout_stride::mapping does not have explicit deduction guides, 23 | // but implicit deduction guides for constructor taking extents and strides 24 | // should work 25 | 26 | constexpr bool test() { 27 | constexpr size_t D = std::dynamic_extent; 28 | 29 | ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents(), std::array())), 30 | std::layout_stride::template mapping>); 31 | ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents(), std::array{1})), 32 | std::layout_stride::template mapping>); 33 | ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents(), std::array{1})), 34 | std::layout_stride::template mapping>); 35 | ASSERT_SAME_TYPE( 36 | decltype(std::layout_stride::mapping(std::extents(), std::array{3, 100})), 37 | std::layout_stride::template mapping>); 38 | 39 | ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents(), std::span())), 40 | std::layout_stride::template mapping>); 41 | ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents(), std::declval>())), 42 | std::layout_stride::template mapping>); 43 | ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents(), std::declval>())), 44 | std::layout_stride::template mapping>); 45 | ASSERT_SAME_TYPE( 46 | decltype(std::layout_stride::mapping(std::extents(), std::declval>())), 47 | std::layout_stride::template mapping>); 48 | return true; 49 | } 50 | 51 | int main(int, char**) { 52 | test(); 53 | static_assert(test()); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /scripts/snl/build-all: -------------------------------------------------------------------------------- 1 | 2 | 3 | echo "======================" 4 | echo "======================" 5 | echo "=====GCC 11.1=========" 6 | echo "======================" 7 | echo "======================" 8 | module swap gcc gcc/11.1 9 | cd gcc-11 10 | cd cpp14; make -j 48; make test; cd .. 11 | cd cpp17; make -j 48; make test; cd .. 12 | cd cpp20; make -j 48; make test; cd .. 13 | cd cpp23; make -j 48; make test; cd .. 14 | cd .. 15 | 16 | 17 | echo "======================" 18 | echo "======================" 19 | echo "=====GCC 9.1==========" 20 | echo "======================" 21 | echo "======================" 22 | module swap gcc gcc/9.1 23 | cd gcc-9 24 | cd cpp14; make -j 48; make test; cd .. 25 | cd cpp17; make -j 48; make test; cd .. 26 | cd cpp20; make -j 48; make test; cd .. 27 | cd .. 28 | 29 | echo "======================" 30 | echo "======================" 31 | echo "=====CLANG 15=========" 32 | echo "======================" 33 | echo "======================" 34 | module swap clang clang/15-head 35 | module swap gcc gcc/11.1 36 | cd clang-15 37 | cd cpp14; make -j 48; make test; cd .. 38 | cd cpp17; make -j 48; make test; cd .. 39 | cd cpp20; make -j 48; make test; cd .. 40 | cd cpp23; make -j 48; make test; cd .. 41 | cd .. 42 | 43 | echo "======================" 44 | echo "======================" 45 | echo "=====CLANG 8.0========" 46 | echo "======================" 47 | echo "======================" 48 | module swap clang clang/8.0 49 | module swap gcc gcc/9.1 50 | cd clang-8 51 | cd cpp14; make -j 48; make test; cd .. 52 | cd cpp17; make -j 48; make test; cd .. 53 | cd cpp20; make -j 48; make test; cd .. 54 | cd .. 55 | 56 | echo "======================" 57 | echo "======================" 58 | echo "=====NVCC 11.2========" 59 | echo "======================" 60 | echo "======================" 61 | module swap cuda cuda/11.2 62 | module swap gcc gcc/9.1 63 | cd nvcc-112 64 | cd cpp14; make -j 48; make test; cd .. 65 | cd cpp17; make -j 48; make test; cd .. 66 | cd .. 67 | 68 | echo "======================" 69 | echo "======================" 70 | echo "=====NVHPC 22.3=======" 71 | echo "======================" 72 | echo "======================" 73 | module unload cuda 74 | module unload nvhpc 75 | module load nvhpc/22.3 76 | cd nvhpc-223 77 | cd cpp14; make -j 48; make test; cd .. 78 | cd cpp17; make -j 48; make test; cd .. 79 | cd cpp20; make -j 48; make test; cd .. 80 | cd .. 81 | 82 | echo "======================" 83 | echo "======================" 84 | echo "=====NVHPC 22.3=======" 85 | echo "======================" 86 | echo "======================" 87 | module unload nvhpc 88 | module load nvhpc/22.7 89 | cd nvhpc-227 90 | cd cpp14; make -j 48; make test; cd .. 91 | cd cpp17; make -j 48; make test; cd .. 92 | cd cpp20; make -j 48; make test; cd .. 93 | cd .. 94 | module load cuda/11.2 95 | -------------------------------------------------------------------------------- /compilation_tests/ctest_no_unique_address.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include "ctest_common.hpp" 17 | 18 | #include 19 | 20 | #include 21 | 22 | 23 | //============================================================================== 24 | // {{{1 25 | 26 | MDSPAN_STATIC_TEST( 27 | sizeof(Kokkos::extents) == sizeof(ptrdiff_t) 28 | ); 29 | 30 | MDSPAN_STATIC_TEST( 31 | sizeof(Kokkos::extents) == sizeof(ptrdiff_t) 32 | ); 33 | 34 | MDSPAN_STATIC_TEST( 35 | sizeof(Kokkos::extents) == 2 * sizeof(ptrdiff_t) 36 | ); 37 | 38 | MDSPAN_STATIC_TEST( 39 | sizeof(Kokkos::extents) == sizeof(ptrdiff_t) 40 | ); 41 | 42 | MDSPAN_STATIC_TEST( 43 | sizeof(Kokkos::extents) == sizeof(ptrdiff_t) 44 | ); 45 | 46 | #ifdef MDSPAN_IMPL_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS 47 | MDSPAN_STATIC_TEST( 48 | std::is_empty>::value 49 | ); 50 | 51 | MDSPAN_STATIC_TEST( 52 | std::is_empty>::value 53 | ); 54 | #endif 55 | 56 | // end extents }}}1 57 | //============================================================================== 58 | 59 | //============================================================================== 60 | // {{{1 61 | 62 | MDSPAN_STATIC_TEST( 63 | sizeof(Kokkos::layout_left::template mapping< 64 | Kokkos::extents 65 | >) == sizeof(size_t) 66 | ); 67 | 68 | #if defined(MDSPAN_IMPL_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) && !defined(MDSPAN_IMPL_USE_FAKE_ATTRIBUTE_NO_UNIQUE_ADDRESS) 69 | MDSPAN_STATIC_TEST( 70 | std::is_empty 72 | >>::value 73 | ); 74 | #endif 75 | 76 | MDSPAN_STATIC_TEST( 77 | sizeof(Kokkos::layout_stride::template mapping< 78 | Kokkos::extents 79 | >) == 4 * sizeof(size_t) 80 | ); 81 | 82 | 83 | // end layouts }}}1 84 | //============================================================================== 85 | -------------------------------------------------------------------------------- /tests/libcxx-backports/extents/types.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // template 13 | // class extents { 14 | // public: 15 | // // types 16 | // using index_type = IndexType; 17 | // using size_type = make_unsigned_t; 18 | // using rank_type = size_t; 19 | // 20 | // static constexpr rank_type rank() noexcept { return sizeof...(Extents); } 21 | // static constexpr rank_type rank_dynamic() noexcept { return dynamic-index(rank()); } 22 | // ... 23 | // } 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "../llvm_test_macros.h" 31 | 32 | template 33 | void testExtents() { 34 | ASSERT_SAME_TYPE(typename E::index_type, IndexType); 35 | ASSERT_SAME_TYPE(typename E::size_type, std::make_unsigned_t); 36 | ASSERT_SAME_TYPE(typename E::rank_type, size_t); 37 | 38 | static_assert(sizeof...(Extents) == E::rank()); 39 | static_assert((static_cast(Extents == std::dynamic_extent) + ...) == E::rank_dynamic()); 40 | 41 | static_assert(std::regular); 42 | static_assert(std::is_trivially_copyable_v); 43 | 44 | // Did never find a way to make this true on windows 45 | #ifndef _WIN32 46 | LIBCPP_STATIC_ASSERT(std::is_empty_v == (E::rank_dynamic() == 0)); 47 | #endif 48 | } 49 | 50 | template 51 | void testExtents() { 52 | testExtents, IndexType, Extents...>(); 53 | } 54 | 55 | template 56 | void test() { 57 | constexpr size_t D = std::dynamic_extent; 58 | testExtents(); 59 | testExtents(); 60 | testExtents(); 61 | testExtents(); 62 | testExtents(); 63 | testExtents(); 64 | testExtents(); 65 | testExtents(); 66 | testExtents(); 67 | testExtents(); 68 | testExtents(); 69 | testExtents(); 70 | testExtents(); 71 | testExtents(); 72 | 73 | testExtents(); 74 | testExtents(); 75 | testExtents(); 76 | } 77 | 78 | int main(int, char**) { 79 | test(); 80 | test(); 81 | test(); 82 | test(); 83 | test(); 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /include/experimental/__p0009_bits/type_list.hpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include "macros.hpp" 17 | 18 | #include "trait_backports.hpp" // make_index_sequence 19 | 20 | namespace MDSPAN_IMPL_STANDARD_NAMESPACE { 21 | 22 | //============================================================================== 23 | 24 | namespace detail { 25 | 26 | template struct type_list { static constexpr auto size = sizeof...(Ts); }; 27 | 28 | // Implementation of type_list at() that's heavily optimized for small typelists 29 | template struct type_at; 30 | template > struct type_at_large_impl; 31 | 32 | template 33 | struct type_at_entry { }; 34 | 35 | template 36 | struct type_at_assign_op_ignore_rest { 37 | template 38 | type_at_assign_op_ignore_rest operator=(T&&); 39 | using type = Result; 40 | }; 41 | 42 | struct type_at_assign_op_impl { 43 | template 44 | type_at_assign_op_impl operator=(type_at_entry&&); 45 | template 46 | type_at_assign_op_ignore_rest operator=(type_at_entry&&); 47 | }; 48 | 49 | template 50 | struct type_at_large_impl, std::integer_sequence> 51 | : decltype( 52 | MDSPAN_IMPL_FOLD_ASSIGN_LEFT(type_at_assign_op_impl{}, /* = ... = */ type_at_entry{}) 53 | ) 54 | { }; 55 | 56 | template 57 | struct type_at> 58 | : type_at_large_impl> 59 | { }; 60 | 61 | template 62 | struct type_at<0, type_list> { 63 | using type = T0; 64 | }; 65 | 66 | template 67 | struct type_at<1, type_list> { 68 | using type = T1; 69 | }; 70 | 71 | template 72 | struct type_at<2, type_list> { 73 | using type = T2; 74 | }; 75 | 76 | template 77 | struct type_at<3, type_list> { 78 | using type = T3; 79 | }; 80 | 81 | 82 | } // namespace detail 83 | 84 | //============================================================================== 85 | 86 | } // end namespace MDSPAN_IMPL_STANDARD_NAMESPACE 87 | -------------------------------------------------------------------------------- /tests/libcxx-backports/default_accessor/default_accessor.ctor.conversion.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | // 13 | // Test converting constructor: 14 | // 15 | // template 16 | // constexpr default_accessor(default_accessor) noexcept {} 17 | // 18 | // Constraints: is_convertible_v is true. 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "../llvm_test_macros.h" 26 | 27 | #include "../MinimalElementType.h" 28 | 29 | struct Base {}; 30 | struct Derived: public Base {}; 31 | 32 | template 33 | constexpr void test_conversion() { 34 | std::default_accessor acc_from; 35 | ASSERT_NOEXCEPT(std::default_accessor(acc_from)); 36 | [[maybe_unused]] std::default_accessor acc_to(acc_from); 37 | } 38 | 39 | constexpr bool test() { 40 | // default accessor conversion largely behaves like pointer conversion 41 | test_conversion(); 42 | test_conversion(); 43 | test_conversion(); 44 | test_conversion(); 45 | test_conversion(); 46 | test_conversion(); 47 | 48 | // char is convertible to int, but accessors are not 49 | static_assert(!std::is_constructible_v, std::default_accessor>); 50 | // don't allow conversion from const elements to non-const 51 | static_assert(!std::is_constructible_v, std::default_accessor>); 52 | // MinimalElementType is constructible from int, but accessors should not be convertible 53 | static_assert(!std::is_constructible_v, std::default_accessor>); 54 | // don't allow conversion from const elements to non-const 55 | static_assert(!std::is_constructible_v, std::default_accessor>); 56 | // don't allow conversion from Base to Derived 57 | static_assert(!std::is_constructible_v, std::default_accessor>); 58 | // don't allow conversion from Derived to Base 59 | static_assert(!std::is_constructible_v, std::default_accessor>); 60 | 61 | return true; 62 | } 63 | 64 | int main(int, char**) { 65 | test(); 66 | static_assert(test()); 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /make_single_header.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | import sys 5 | import os 6 | from os.path import dirname, join as path_join, abspath, exists 7 | 8 | from pathlib import Path 9 | 10 | extra_paths = [path_join(dirname(abspath(__file__)), "include")] 11 | 12 | 13 | def find_file(included_name, current_file): 14 | current_dir = dirname(abspath(current_file)) 15 | for idir in [current_dir] + extra_paths: 16 | try_path = path_join(idir, included_name) 17 | if exists(try_path): 18 | return try_path 19 | return None 20 | 21 | 22 | def process_file( 23 | file_path, 24 | out_lines=[], 25 | front_matter_lines=[], 26 | back_matter_lines=[], 27 | processed_files=[], 28 | ): 29 | out_lines += "//BEGIN_FILE_INCLUDE: " + file_path + "\n" 30 | with open(file_path, "r") as f: 31 | for line in f: 32 | m_inc = re.match(r'# *include\s*[<"](.+)[>"]\s*', line) 33 | if m_inc: 34 | inc_name = m_inc.group(1) 35 | inc_path = find_file(inc_name, file_path) 36 | if inc_path is not None: 37 | inc_path_res = str(Path(inc_path).resolve()) 38 | if inc_path_res not in processed_files: 39 | processed_files += [inc_path_res] 40 | process_file( 41 | inc_path_res, 42 | out_lines, 43 | front_matter_lines, 44 | back_matter_lines, 45 | processed_files, 46 | ) 47 | else: 48 | # assume it's a system header 49 | out_lines += [line] 50 | continue 51 | m_once = re.match(r"#pragma once\s*", line) 52 | # ignore pragma once; we're handling it here 53 | if m_once: 54 | continue 55 | # otherwise, just add the line to the output 56 | if line[-1] != "\n": 57 | line = line + "\n" 58 | out_lines += [line] 59 | out_lines += "//END_FILE_INCLUDE: " + file_path + "\n" 60 | return ( 61 | "".join(front_matter_lines) 62 | + "\n" 63 | + "".join(out_lines) 64 | + "".join(back_matter_lines) 65 | ) 66 | 67 | 68 | if __name__ == "__main__": 69 | print( 70 | process_file( 71 | str(Path(sys.argv[1]).resolve()), 72 | [], 73 | # We use an include guard instead of `#pragma once` because Godbolt will 74 | # cause complaints about `#pragma once` when they are used in URL includes. 75 | [ 76 | "#ifndef MDSPAN_SINGLE_HEADER_INCLUDE_GUARD_\n", 77 | "#define MDSPAN_SINGLE_HEADER_INCLUDE_GUARD_\n", 78 | ], 79 | ["#endif // MDSPAN_SINGLE_HEADER_INCLUDE_GUARD_\n"], 80 | [str(Path(sys.argv[1]).resolve())], 81 | ) 82 | ) 83 | -------------------------------------------------------------------------------- /tests/libcxx-backports/mdspan/mdspan.conversion.verify.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 3 | // See https://llvm.org/LICENSE.txt for license information. 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 | // 6 | //===----------------------------------------------------------------------===// 7 | 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // template 14 | // constexpr explicit(see below) 15 | // mdspan(const mdspan& other); 17 | // 18 | // Constraints: 19 | // - is_constructible_v&> is true, and 20 | // - is_constructible_v is true. 21 | // Mandates: 22 | // - is_constructible_v is 23 | // - is_constructible_v is true. 24 | // 25 | // Preconditions: 26 | // - For each rank index r of extents_type, static_extent(r) == dynamic_extent || static_extent(r) == other.extent(r) is true. 27 | // - [0, map_.required_span_size()) is an accessible range of ptr_ and acc_ for values of ptr_, map_, and acc_ after the invocation of this constructor. 28 | // 29 | // Effects: 30 | // - Direct-non-list-initializes ptr_ with other.ptr_, 31 | // - direct-non-list-initializes map_ with other.map_, and 32 | // - direct-non-list-initializes acc_ with other.acc_. 33 | // 34 | // Remarks: The expression inside explicit is equivalent to: 35 | // !is_convertible_v&, mapping_type> 36 | // || !is_convertible_v 37 | 38 | #include 39 | #include "CustomTestAccessors.h" 40 | #include "../CustomTestLayouts.h" 41 | 42 | void cant_construct_data_handle_type() { 43 | int data; 44 | std::mdspan, std::layout_right, convertible_accessor_but_not_handle> m_nc(&data); 45 | // expected-error-re@*:* {{{{.*}}no matching constructor for initialization of {{.*}} (aka 'not_const_convertible_handle')}} 46 | // expected-error-re@*:* {{static assertion failed {{.*}}mdspan: incompatible data_handle_type for mdspan construction}} 47 | [[maybe_unused]] std:: 48 | mdspan, std::layout_right, convertible_accessor_but_not_handle> 49 | m_c(m_nc); 50 | } 51 | 52 | void mapping_constructible_despite_extents_compatibility() { 53 | int data; 54 | std::mdspan, always_convertible_layout> m(&data); 55 | // expected-error-re@*:* {{static assertion failed {{.*}}mdspan: incompatible extents for mdspan construction}} 56 | [[maybe_unused]] std::mdspan, always_convertible_layout> m2(m); 57 | } 58 | -------------------------------------------------------------------------------- /scripts/snl/config-all: -------------------------------------------------------------------------------- 1 | module swap gcc gcc/9.1 2 | ./config-one gcc-9 g++ 20 "-Wall -Wextra -Werror -pedantic" 3 | ./config-one gcc-9 g++ 17 "-Wall -Wextra -Werror" 4 | ./config-one gcc-9 g++ 14 "-Wall -Wextra -Werror" 5 | 6 | module swap gcc gcc/11.1 7 | ./config-one gcc-11 g++ 23 "-Wall -Wextra -Werror -pedantic" 8 | ./config-one gcc-11 g++ 20 "-Wall -Wextra -Werror -pedantic" 9 | ./config-one gcc-11 g++ 17 "-Wall -Wextra -Werror" 10 | ./config-one gcc-11 g++ 14 "-Wall -Wextra -Werror" 11 | 12 | module swap clang clang/15-head 13 | module swap gcc gcc/11.1 14 | ./config-one clang-15 clang++ 23 "-Wall -Wextra -Werror -pedantic" 15 | cd clang-15/cpp23/tests/googletest-src 16 | git apply ${MDSPAN_SOURCE}/scripts/snl/gtest-clang-patch 17 | cd ../../../../ 18 | ./config-one clang-15 clang++ 20 "-Wall -Wextra -Werror -pedantic" 19 | cd clang-15/cpp20/tests/googletest-src 20 | git apply ${MDSPAN_SOURCE}/scripts/snl/gtest-clang-patch 21 | cd ../../../../ 22 | ./config-one clang-15 clang++ 17 "-Wall -Wextra -Werror" 23 | cd clang-15/cpp17/tests/googletest-src 24 | git apply ${MDSPAN_SOURCE}/scripts/snl/gtest-clang-patch 25 | cd ../../../../ 26 | ./config-one clang-15 clang++ 14 "-Wall -Werror" 27 | cd clang-15/cpp14/tests/googletest-src 28 | git apply ${MDSPAN_SOURCE}/scripts/snl/gtest-clang-patch 29 | cd ../../../../ 30 | 31 | module swap clang clang/8.0 32 | module swap gcc gcc/9.1 33 | ./config-one clang-8 clang++ 20 "-Wall -Wextra -Werror --gcc-toolchain=/home/projects/x86-64/gcc/9.1" 34 | ./config-one clang-8 clang++ 17 "-Wall -Wextra -Werror --gcc-toolchain=/home/projects/x86-64/gcc/9.1" 35 | ./config-one clang-8 clang++ 14 "-Wall -Werror --gcc-toolchain=/home/projects/x86-64/gcc/9.1" 36 | 37 | module swap cuda cuda/11.2 38 | module swap gcc gcc/9.1 39 | ./config-one-cuda nvcc-112 g++ 17 "-Wall -Werror" 40 | ./config-one-cuda nvcc-112 g++ 14 "-Wall -Werror" 41 | 42 | module unload cuda 43 | module load nvhpc/22.3 44 | ./config-one nvhpc-223 nvc++ 20 "-Wall -Wextra" 45 | cd nvhpc-223/cpp20/tests/googletest-src 46 | git apply ${MDSPAN_SOURCE}/scripts/snl/gtest-nvhpc-patch 47 | cd ../../../../ 48 | ./config-one nvhpc-223 nvc++ 17 "-Wall -Wextra" 49 | cd nvhpc-223/cpp17/tests/googletest-src 50 | git apply ${MDSPAN_SOURCE}/scripts/snl/gtest-nvhpc-patch 51 | cd ../../../../ 52 | ./config-one nvhpc-223 nvc++ 14 "-Wall -Wextra" 53 | cd nvhpc-223/cpp14/tests/googletest-src 54 | git apply ${MDSPAN_SOURCE}/scripts/snl/gtest-nvhpc-patch 55 | cd ../../../../ 56 | module load cuda/11.2 57 | 58 | 59 | module unload cuda 60 | module load nvhpc/22.7 61 | ./config-one nvhpc-227 nvc++ 20 "-Wall -Wextra" 62 | cd nvhpc-227/cpp20/tests/googletest-src 63 | git apply ${MDSPAN_SOURCE}/scripts/snl/gtest-nvhpc-patch 64 | cd ../../../../ 65 | ./config-one nvhpc-227 nvc++ 17 "-Wall -Wextra" 66 | cd nvhpc-227/cpp17/tests/googletest-src 67 | git apply ${MDSPAN_SOURCE}/scripts/snl/gtest-nvhpc-patch 68 | cd ../../../../ 69 | ./config-one nvhpc-227 nvc++ 14 "-Wall -Wextra" 70 | cd nvhpc-227/cpp14/tests/googletest-src 71 | git apply ${MDSPAN_SOURCE}/scripts/snl/gtest-nvhpc-patch 72 | cd ../../../../ 73 | module load cuda/11.2 74 | -------------------------------------------------------------------------------- /tests/test_dims.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | namespace test { 22 | 23 | template 24 | static constexpr bool is_extents_v = false; 25 | 26 | template 27 | static constexpr bool is_extents_v< 28 | MDSPAN_IMPL_STANDARD_NAMESPACE :: extents 29 | > = true; 30 | 31 | template 32 | void test_dims_with_one_template_argument() 33 | { 34 | using d = MDSPAN_IMPL_STANDARD_NAMESPACE :: MDSPAN_IMPL_PROPOSED_NAMESPACE :: dims; 35 | static_assert(test::is_extents_v, "dims is not an extents specialization"); 36 | static_assert(std::is_same::value, "dims::index_type is wrong"); 37 | static_assert(d::rank() == Rank, "dims::rank() is wrong"); 38 | } 39 | 40 | template 41 | void test_dims_with_two_template_arguments() 42 | { 43 | using d = MDSPAN_IMPL_STANDARD_NAMESPACE :: MDSPAN_IMPL_PROPOSED_NAMESPACE :: dims; 44 | static_assert(test::is_extents_v, "dims is not an extents specialization"); 45 | static_assert(std::is_same::value, "dims::index_type is wrong"); 46 | static_assert(d::rank() == Rank, "dims::rank() is wrong"); 47 | } 48 | 49 | } // namespace test 50 | 51 | TEST(TestDims, Test0) 52 | { 53 | using test::test_dims_with_one_template_argument; 54 | using test::test_dims_with_two_template_arguments; 55 | 56 | test_dims_with_one_template_argument<0>(); 57 | test_dims_with_one_template_argument<1>(); 58 | test_dims_with_one_template_argument<2>(); 59 | test_dims_with_one_template_argument<3>(); 60 | test_dims_with_one_template_argument<4>(); 61 | test_dims_with_one_template_argument<5>(); 62 | test_dims_with_one_template_argument<6>(); 63 | test_dims_with_one_template_argument<7>(); 64 | test_dims_with_one_template_argument<8>(); 65 | 66 | test_dims_with_two_template_arguments<0, std::size_t>(); 67 | test_dims_with_two_template_arguments<1, std::size_t>(); 68 | test_dims_with_two_template_arguments<2, std::size_t>(); 69 | test_dims_with_two_template_arguments<3, std::size_t>(); 70 | test_dims_with_two_template_arguments<4, std::size_t>(); 71 | test_dims_with_two_template_arguments<5, std::size_t>(); 72 | test_dims_with_two_template_arguments<6, std::size_t>(); 73 | test_dims_with_two_template_arguments<7, std::size_t>(); 74 | test_dims_with_two_template_arguments<8, std::size_t>(); 75 | } 76 | -------------------------------------------------------------------------------- /tests/libcxx-backports/extents/ctor_from_integral.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // Test construction from integral: 13 | // 14 | // template 15 | // constexpr explicit extents(OtherIndexTypes ... exts) noexcept; 16 | // 17 | // Let N be sizeof...(OtherIndexTypes), and let 18 | // exts_arr be array{static_cast(std::move(exts))...}. 19 | // 20 | // Constraints: 21 | // * (is_convertible_v && ...) is true, 22 | // * (is_nothrow_constructible_v && ...) is true, and 23 | // * N == rank_dynamic() || N == rank() is true. 24 | // 25 | // Preconditions: 26 | // * If N != rank_dynamic() is true, exts_arr[r] equals Er for each r for which 27 | // Er is a static extent, and 28 | // * either 29 | // - sizeof...(exts) == 0 is true, or 30 | // - each element of exts is nonnegative and is representable as a value of type index_type. 31 | // 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include "../ConvertibleToIntegral.h" 38 | #include "CtorTestCombinations.h" 39 | #include "../llvm_test_macros.h" 40 | 41 | struct IntegralCtorTest { 42 | template 43 | static constexpr void test_construction(AllExtents all_ext, Extents ext, std::index_sequence) { 44 | // construction from indices 45 | ASSERT_NOEXCEPT(E(ext[Indices]...)); 46 | test_runtime_observers(E(ext[Indices]...), all_ext); 47 | } 48 | }; 49 | 50 | int main(int, char**) { 51 | test_index_type_combo(); 52 | static_assert(test_index_type_combo()); 53 | 54 | constexpr size_t D = std::dynamic_extent; 55 | using E = std::extents; 56 | 57 | // check can't construct from too few arguments 58 | static_assert(!std::is_constructible_v, "extents constructible from illegal arguments"); 59 | // check can't construct from rank_dynamic < #args < rank 60 | static_assert(!std::is_constructible_v, "extents constructible from illegal arguments"); 61 | // check can't construct from too many arguments 62 | static_assert(!std::is_constructible_v, "extents constructible from illegal arguments"); 63 | 64 | // test construction fails from types not convertible to index_type but convertible to other integer types 65 | static_assert(std::is_convertible_v, "Test helper IntType unexpectedly not convertible to int"); 66 | static_assert(!std::is_constructible_v< std::extents, IntType>, 67 | "extents constructible from illegal arguments"); 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /compilation_tests/ctest_layout_convertible.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include "ctest_common.hpp" 17 | 18 | #include 19 | 20 | 21 | struct NotARealLayout { 22 | template 23 | struct mapping { 24 | using extents_type = Extents; 25 | using rank_type = typename extents_type::rank_type; 26 | using index_type = typename extents_type::index_type; 27 | using layout_type = NotARealLayout; 28 | 29 | constexpr extents_type& extents() const { return ext; } 30 | 31 | template 32 | index_type operator()(Idx ...) const { return 0; } 33 | 34 | index_type required_span_size() const { return 0; } 35 | 36 | index_type stride(rank_type) const { return 1; } 37 | 38 | private: 39 | extents_type ext; 40 | }; 41 | }; 42 | 43 | template 44 | struct AStridedLayout { 45 | template 46 | struct mapping { 47 | using extents_type = Extents; 48 | using rank_type = typename extents_type::rank_type; 49 | using index_type = typename extents_type::index_type; 50 | using layout_type = AStridedLayout; 51 | 52 | constexpr extents_type& extents() const { return ext; } 53 | 54 | template 55 | index_type operator()(Idx ...) const { return 0; } 56 | 57 | index_type required_span_size() const { return 0; } 58 | 59 | index_type stride(rank_type) const { return 1; } 60 | 61 | constexpr static bool is_always_strided() { return true; } 62 | constexpr static bool is_always_unique() { return unique; } 63 | constexpr static bool is_always_exhaustive() { return true; } 64 | constexpr bool is_strided() { return true; } 65 | constexpr bool is_unique() { return unique; } 66 | constexpr bool is_exhaustive() { return true; } 67 | 68 | private: 69 | extents_type ext; 70 | }; 71 | }; 72 | 73 | using E1 = Kokkos::extents; 74 | using E2 = Kokkos::extents; 75 | using LS1 = Kokkos::layout_stride::mapping; 76 | using LS2 = Kokkos::layout_stride::mapping; 77 | 78 | MDSPAN_STATIC_TEST( 79 | !std::is_constructible::mapping>::value && 80 | !std::is_convertible::mapping, LS1>::value 81 | ); 82 | 83 | #if !MDSPAN_HAS_CXX_14 && !MDSPAN_HAS_CXX_20 84 | MDSPAN_STATIC_TEST( 85 | std::is_constructible::mapping>::value && 86 | !std::is_convertible::mapping, LS2>::value 87 | ); 88 | #endif 89 | 90 | MDSPAN_STATIC_TEST( 91 | !std::is_constructible>::value 92 | ); 93 | 94 | 95 | -------------------------------------------------------------------------------- /tests/libcxx-backports/extents/obs_static.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // static constexpr rank_type rank() noexcept; 13 | // static constexpr rank_type rank_dynamic() noexcept; 14 | // 15 | // static constexpr size_t static_extent(rank_type i) noexcept; 16 | // 17 | // Preconditions: i < rank() is true. 18 | // 19 | // Returns: Ei. 20 | // 21 | // 22 | // constexpr index_type extent(rank_type i) const noexcept; 23 | // 24 | // Preconditions: i < rank() is true. 25 | // 26 | // Returns: Di. 27 | // 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "../llvm_test_macros.h" 34 | 35 | template 36 | void test_static_observers(std::index_sequence, std::index_sequence) { 37 | ASSERT_NOEXCEPT(E::rank()); 38 | static_assert(E::rank() == rank); 39 | ASSERT_NOEXCEPT(E::rank_dynamic()); 40 | static_assert(E::rank_dynamic() == rank_dynamic); 41 | 42 | // Let's only test this if the call isn't a precondition violation 43 | if constexpr (rank > 0) { 44 | ASSERT_NOEXCEPT(E::static_extent(0)); 45 | ASSERT_SAME_TYPE(decltype(E::static_extent(0)), size_t); 46 | static_assert(((E::static_extent(Indices) == StaticExts) && ...)); 47 | } 48 | } 49 | 50 | template 51 | void test_static_observers() { 52 | test_static_observers( 53 | std::index_sequence(), std::make_index_sequence()); 54 | } 55 | 56 | template 57 | void test() { 58 | constexpr size_t D = std::dynamic_extent; 59 | constexpr size_t S = 5; 60 | 61 | test_static_observers, 0, 0>(); 62 | 63 | test_static_observers, 1, 0, S>(); 64 | test_static_observers, 1, 1, D>(); 65 | 66 | test_static_observers, 2, 0, S, S>(); 67 | test_static_observers, 2, 1, S, D>(); 68 | test_static_observers, 2, 1, D, S>(); 69 | test_static_observers, 2, 2, D, D>(); 70 | 71 | test_static_observers, 3, 0, S, S, S>(); 72 | test_static_observers, 3, 1, S, S, D>(); 73 | test_static_observers, 3, 1, S, D, S>(); 74 | test_static_observers, 3, 1, D, S, S>(); 75 | test_static_observers, 3, 2, S, D, D>(); 76 | test_static_observers, 3, 2, D, S, D>(); 77 | test_static_observers, 3, 2, D, D, S>(); 78 | test_static_observers, 3, 3, D, D, D>(); 79 | } 80 | 81 | int main(int, char**) { 82 | test(); 83 | test(); 84 | test(); 85 | test(); 86 | test(); 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /benchmarks/sum/sum_3d_left.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | #include "sum_3d_common.hpp" 22 | #include "../fill.hpp" 23 | 24 | using index_type = int; 25 | //================================================================================ 26 | 27 | template 28 | using lmdspan = Kokkos::mdspan, Kokkos::layout_left>; 29 | template 30 | using rmdspan = Kokkos::mdspan, Kokkos::layout_right>; 31 | 32 | //================================================================================ 33 | 34 | template 35 | void BM_MDSpan_Sum_3D_left(benchmark::State& state, MDSpan, DynSizes... dyn) { 36 | using value_type = typename MDSpan::value_type; 37 | auto buffer = std::make_unique( 38 | MDSpan{nullptr, dyn...}.mapping().required_span_size() 39 | ); 40 | auto s = MDSpan{buffer.get(), dyn...}; 41 | mdspan_benchmark::fill_random(s); 42 | for (auto _ : state) { 43 | value_type sum = 0; 44 | for (index_type k = 0; k < s.extent(2); ++k) { 45 | for (index_type j = 0; j < s.extent(1); ++j) { 46 | for(index_type i = 0; i < s.extent(0); ++i) { 47 | sum += s(i, j, k); 48 | } 49 | } 50 | } 51 | benchmark::DoNotOptimize(sum); 52 | auto sdata = s.data_handle(); 53 | benchmark::DoNotOptimize(sdata); 54 | } 55 | state.SetBytesProcessed(s.size() * sizeof(value_type) * state.iterations()); 56 | } 57 | MDSPAN_BENCHMARK_ALL_3D(BM_MDSpan_Sum_3D_left, left_, lmdspan, 20, 20, 20); 58 | MDSPAN_BENCHMARK_ALL_3D(BM_MDSpan_Sum_3D_left, right_, rmdspan, 20, 20, 20); 59 | MDSPAN_BENCHMARK_ALL_3D(BM_MDSpan_Sum_3D_left, left_, lmdspan, 200, 200, 200); 60 | MDSPAN_BENCHMARK_ALL_3D(BM_MDSpan_Sum_3D_left, right_, rmdspan, 200, 200, 200); 61 | 62 | //================================================================================ 63 | 64 | BENCHMARK_CAPTURE( 65 | BM_Raw_Sum_1D, size_8000, int(), 8000 66 | ); 67 | BENCHMARK_CAPTURE( 68 | BM_Raw_Sum_1D, size_8000000, int(), 8000000 69 | ); 70 | 71 | BENCHMARK_CAPTURE( 72 | BM_Raw_Sum_3D_left, size_20_20_20, int(), 20, 20, 20 73 | ); 74 | BENCHMARK_CAPTURE( 75 | BM_Raw_Sum_3D_left, size_200_200_200, int(), 200, 200, 200 76 | ); 77 | 78 | //================================================================================ 79 | 80 | BENCHMARK_CAPTURE( 81 | BM_Raw_Static_Sum_3D_left, size_20_20_20, int(), 82 | std::integral_constant{}, 83 | std::integral_constant{}, 84 | std::integral_constant{} 85 | ); 86 | BENCHMARK_CAPTURE( 87 | BM_Raw_Static_Sum_3D_left, size_200_200_200, int(), 88 | std::integral_constant{}, 89 | std::integral_constant{}, 90 | std::integral_constant{} 91 | ); 92 | 93 | 94 | //================================================================================ 95 | 96 | BENCHMARK_MAIN(); 97 | -------------------------------------------------------------------------------- /benchmarks/sum/sum_3d_right.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | #include "sum_3d_common.hpp" 22 | #include "../fill.hpp" 23 | 24 | //================================================================================ 25 | 26 | using index_type = int; 27 | 28 | template 29 | using lmdspan = Kokkos::mdspan, Kokkos::layout_left>; 30 | template 31 | using rmdspan = Kokkos::mdspan, Kokkos::layout_right>; 32 | 33 | //================================================================================ 34 | 35 | template 36 | void BM_MDSpan_Sum_3D_right(benchmark::State& state, MDSpan, DynSizes... dyn) { 37 | 38 | using value_type = typename MDSpan::value_type; 39 | auto buffer = std::make_unique( 40 | MDSpan{nullptr, dyn...}.mapping().required_span_size() 41 | ); 42 | 43 | auto s = MDSpan{buffer.get(), dyn...}; 44 | mdspan_benchmark::fill_random(s); 45 | 46 | for (auto _ : state) { 47 | benchmark::DoNotOptimize(s); 48 | auto sdata = s.data_handle(); 49 | benchmark::DoNotOptimize(sdata); 50 | value_type sum = 0; 51 | for(index_type i = 0; i < s.extent(0); ++i) { 52 | for (index_type j = 0; j < s.extent(1); ++j) { 53 | for (index_type k = 0; k < s.extent(2); ++k) { 54 | sum += s(i, j, k); 55 | } 56 | } 57 | } 58 | benchmark::DoNotOptimize(sum); 59 | benchmark::ClobberMemory(); 60 | } 61 | state.SetBytesProcessed(s.size() * sizeof(value_type) * state.iterations()); 62 | } 63 | MDSPAN_BENCHMARK_ALL_3D(BM_MDSpan_Sum_3D_right, right_, rmdspan, 20, 20, 20); 64 | MDSPAN_BENCHMARK_ALL_3D(BM_MDSpan_Sum_3D_right, left_, lmdspan, 20, 20, 20); 65 | MDSPAN_BENCHMARK_ALL_3D(BM_MDSpan_Sum_3D_right, right_, rmdspan, 200, 200, 200); 66 | MDSPAN_BENCHMARK_ALL_3D(BM_MDSpan_Sum_3D_right, left_, lmdspan, 200, 200, 200); 67 | 68 | //================================================================================ 69 | 70 | BENCHMARK_CAPTURE( 71 | BM_Raw_Sum_3D_right, size_20_20_20, int(), size_t(20), size_t(20), size_t(20) 72 | ); 73 | BENCHMARK_CAPTURE( 74 | BM_Raw_Sum_3D_right, size_200_200_200, int(), size_t(200), size_t(200), size_t(200) 75 | ); 76 | 77 | //================================================================================ 78 | 79 | BENCHMARK_CAPTURE( 80 | BM_Raw_Static_Sum_3D_right, size_20_20_20, int(), 81 | std::integral_constant{}, 82 | std::integral_constant{}, 83 | std::integral_constant{} 84 | ); 85 | BENCHMARK_CAPTURE( 86 | BM_Raw_Static_Sum_3D_right, size_200_200_200, int(), 87 | std::integral_constant{}, 88 | std::integral_constant{}, 89 | std::integral_constant{} 90 | ); 91 | 92 | 93 | //================================================================================ 94 | 95 | BENCHMARK_CAPTURE( 96 | BM_Raw_Sum_1D, size_8000, int(), 8000 97 | ); 98 | 99 | //================================================================================ 100 | 101 | BENCHMARK_MAIN(); 102 | -------------------------------------------------------------------------------- /compilation_tests/ctest_extents_type_check.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include "ctest_common.hpp" 17 | 18 | #include 19 | 20 | 21 | using E1 = Kokkos::extents; 22 | 23 | MDSPAN_STATIC_TEST( 24 | std::is_same::value && 25 | std::is_same::value && 26 | std::is_same::value && 27 | std::is_same::value && 28 | std::is_same::value && 29 | std::is_same::value && 30 | std::is_same::value && 31 | std::is_same().extent(0)), typename E1::index_type>::value && 32 | std::is_same().extent(1)), typename E1::index_type>::value && 33 | (E1::rank()==2) && 34 | (E1::rank_dynamic()==1) && 35 | (E1::static_extent(0) == Kokkos::dynamic_extent) && 36 | (E1::static_extent(1) == 3) 37 | ); 38 | 39 | using E2 = Kokkos::extents; 40 | 41 | MDSPAN_STATIC_TEST( 42 | std::is_same::value && 43 | std::is_same::value && 44 | std::is_same::value && 45 | std::is_same::value && 46 | std::is_same::value && 47 | std::is_same::value && 48 | std::is_same::value && 49 | std::is_same::value && 50 | std::is_same().extent(0)), typename E2::index_type>::value && 51 | std::is_same().extent(1)), typename E2::index_type>::value && 52 | std::is_same().extent(2)), typename E2::index_type>::value && 53 | (E2::rank()==3) && 54 | (E2::rank_dynamic()==2) && 55 | (E2::static_extent(0) == Kokkos::dynamic_extent) && 56 | (E2::static_extent(1) == 3) && 57 | (E2::static_extent(2) == Kokkos::dynamic_extent) 58 | ); 59 | 60 | using E3 = Kokkos::extents; 61 | 62 | MDSPAN_STATIC_TEST( 63 | std::is_same::value && 64 | std::is_same::value && 65 | std::is_same::value && 66 | std::is_same::value && 67 | std::is_same::value && 68 | std::is_same::value && 69 | std::is_same::value && 70 | std::is_same::value && 71 | std::is_same().extent(0)), typename E3::index_type>::value && 72 | std::is_same().extent(1)), typename E3::index_type>::value && 73 | std::is_same().extent(2)), typename E3::index_type>::value && 74 | (E3::rank()==3) && 75 | (E3::rank_dynamic()==2) && 76 | (E3::static_extent(0) == Kokkos::dynamic_extent) && 77 | (E3::static_extent(1) == 3) && 78 | (E3::static_extent(2) == Kokkos::dynamic_extent) 79 | ); 80 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #The tests in CUDA use lambdas 3 | if(MDSPAN_ENABLE_CUDA) 4 | if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") 5 | set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --extended-lambda") 6 | endif() 7 | endif() 8 | 9 | function(mdspan_add_test name) 10 | set(options ENABLE_PRECONDITIONS) 11 | set(one_value SOURCE) 12 | set(multi_value) 13 | cmake_parse_arguments(ARGUMENT "${options}" "${one_value}" "${multi_value}" ${ARGN}) 14 | 15 | if(NOT DEFINED ARGUMENT_SOURCE) 16 | set(ARGUMENT_SOURCE ${name}.cpp) 17 | endif() 18 | 19 | if(MDSPAN_TEST_LANGUAGE) 20 | set_source_files_properties(${name} PROPERTIES LANGUAGE ${MDSPAN_TEST_LANGUAGE}) 21 | endif() 22 | add_executable(${name} ${ARGUMENT_SOURCE}) 23 | target_link_libraries(${name} mdspan GTest::gtest_main) 24 | add_test(${name} ${name}) 25 | set_property(TARGET ${name} PROPERTY COMPILE_WARNING_AS_ERROR ON) 26 | target_compile_definitions(${name} 27 | PUBLIC 28 | MDSPAN_IMPL_CHECK_PRECONDITION=$ 29 | ) 30 | endfunction() 31 | 32 | if(MDSPAN_USE_SYSTEM_GTEST) 33 | find_package(GTest CONFIG REQUIRED) 34 | else() 35 | include(FetchContent) 36 | 37 | if (MSVC) 38 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 39 | endif() 40 | fetchcontent_declare( 41 | googletest 42 | GIT_REPOSITORY https://github.com/google/googletest.git 43 | GIT_TAG v1.17.0 44 | ) 45 | 46 | # TODO CMake 3.28, we can pass EXCLUDE_FROM_ALL directly to fetchcontent_makeavailable 47 | fetchcontent_getproperties(googletest) 48 | if (NOT googletest_POPULATED) 49 | fetchcontent_populate(googletest) 50 | add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) 51 | endif() 52 | 53 | add_library(GTest::gtest_main ALIAS gtest_main) 54 | endif() 55 | 56 | # FIXME_MSVC 57 | if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") 58 | mdspan_add_test( 59 | test_precondition_checks_can_be_disabled 60 | SOURCE test_alternate_precondition_violation_handler.cpp 61 | ) 62 | target_compile_definitions( 63 | test_precondition_checks_can_be_disabled 64 | PUBLIC 65 | MDSPAN_IMPL_CHECK_PRECONDITION=0 66 | ) 67 | set_tests_properties( 68 | test_precondition_checks_can_be_disabled 69 | PROPERTIES 70 | PASS_REGULAR_EXPRESSION "Failure.*Expected.*throws an exception of type std::logic_error.*Actual.*it throws nothing" 71 | ) 72 | endif() 73 | 74 | if(NOT MDSPAN_ENABLE_CUDA AND NOT MDSPAN_ENABLE_HIP AND NOT MDSPAN_ENABLE_SYCL) 75 | mdspan_add_test(test_alternate_precondition_violation_handler ENABLE_PRECONDITIONS) 76 | endif() 77 | mdspan_add_test(test_macros ENABLE_PRECONDITIONS) 78 | mdspan_add_test(test_layout_preconditions ENABLE_PRECONDITIONS) 79 | 80 | mdspan_add_test(test_dims) 81 | mdspan_add_test(test_extents) 82 | mdspan_add_test(test_mdspan_at) 83 | mdspan_add_test(test_mdspan_ctors) 84 | mdspan_add_test(test_mdspan_swap) 85 | mdspan_add_test(test_mdspan_conversion) 86 | mdspan_add_test(test_mdspan_size) 87 | mdspan_add_test(test_element_access) 88 | mdspan_add_test(test_exhaustive_layouts) 89 | mdspan_add_test(test_layout_ctors) 90 | mdspan_add_test(test_layout_stride) 91 | if(NOT CMAKE_CXX_STANDARD STREQUAL "14") 92 | mdspan_add_test(test_submdspan) 93 | mdspan_add_test(test_submdspan_static_slice) 94 | mdspan_add_test(test_layout_padded_left ENABLE_PRECONDITIONS) 95 | mdspan_add_test(test_layout_padded_right ENABLE_PRECONDITIONS) 96 | endif() 97 | # both of those don't work yet since its using vector 98 | if(NOT MDSPAN_ENABLE_CUDA AND NOT MDSPAN_ENABLE_HIP) 99 | mdspan_add_test(test_mdarray_ctors) 100 | mdspan_add_test(test_mdarray_to_mdspan) 101 | endif() 102 | 103 | if(CMAKE_CXX_STANDARD GREATER_EQUAL 20) 104 | if((CMAKE_CXX_COMPILER_ID STREQUAL Clang) OR ((CMAKE_CXX_COMPILER_ID STREQUAL GNU) AND (CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 12.0.0))) 105 | add_subdirectory(libcxx-backports) 106 | endif() 107 | endif() 108 | -------------------------------------------------------------------------------- /include/experimental/__p0009_bits/no_unique_address.hpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #pragma once 17 | 18 | #include "macros.hpp" 19 | #include "trait_backports.hpp" 20 | 21 | namespace MDSPAN_IMPL_STANDARD_NAMESPACE { 22 | namespace detail { 23 | 24 | //============================================================================== 25 | 26 | template 27 | struct no_unique_address_emulation { 28 | using stored_type = T; 29 | T m_v; 30 | MDSPAN_FORCE_INLINE_FUNCTION constexpr T const &ref() const noexcept { 31 | return m_v; 32 | } 33 | MDSPAN_FORCE_INLINE_FUNCTION MDSPAN_IMPL_CONSTEXPR_14 T &ref() noexcept { 34 | return m_v; 35 | } 36 | }; 37 | 38 | // Empty case 39 | // This doesn't work if T is final, of course, but we're not using anything 40 | // like that currently. That kind of thing could be added pretty easily though 41 | template 42 | struct no_unique_address_emulation< 43 | T, Disambiguator, 44 | std::enable_if_t> : 49 | #ifdef MDSPAN_IMPL_COMPILER_MSVC 50 | // MSVC doesn't allow you to access public static member functions of a type 51 | // when you *happen* to privately inherit from that type. 52 | protected 53 | #else 54 | // But we still want this to be private if possible so that we don't accidentally 55 | // access members of T directly rather than calling ref() first, which wouldn't 56 | // work if T happens to be stateful and thus we're using the unspecialized definition 57 | // of no_unique_address_emulation above. 58 | private 59 | #endif 60 | T { 61 | using stored_type = T; 62 | MDSPAN_FORCE_INLINE_FUNCTION constexpr T const &ref() const noexcept { 63 | return *static_cast(this); 64 | } 65 | MDSPAN_FORCE_INLINE_FUNCTION MDSPAN_IMPL_CONSTEXPR_14 T &ref() noexcept { 66 | return *static_cast(this); 67 | } 68 | 69 | MDSPAN_INLINE_FUNCTION_DEFAULTED 70 | constexpr no_unique_address_emulation() noexcept = default; 71 | MDSPAN_INLINE_FUNCTION_DEFAULTED 72 | constexpr no_unique_address_emulation( 73 | no_unique_address_emulation const &) noexcept = default; 74 | MDSPAN_INLINE_FUNCTION_DEFAULTED 75 | constexpr no_unique_address_emulation( 76 | no_unique_address_emulation &&) noexcept = default; 77 | MDSPAN_INLINE_FUNCTION_DEFAULTED 78 | MDSPAN_IMPL_CONSTEXPR_14_DEFAULTED no_unique_address_emulation & 79 | operator=(no_unique_address_emulation const &) noexcept = default; 80 | MDSPAN_INLINE_FUNCTION_DEFAULTED 81 | MDSPAN_IMPL_CONSTEXPR_14_DEFAULTED no_unique_address_emulation & 82 | operator=(no_unique_address_emulation &&) noexcept = default; 83 | MDSPAN_INLINE_FUNCTION_DEFAULTED 84 | ~no_unique_address_emulation() noexcept = default; 85 | 86 | // Explicitly make this not a reference so that the copy or move 87 | // constructor still gets called. 88 | MDSPAN_INLINE_FUNCTION 89 | explicit constexpr no_unique_address_emulation(T const& v) noexcept : T(v) {} 90 | MDSPAN_INLINE_FUNCTION 91 | explicit constexpr no_unique_address_emulation(T&& v) noexcept : T(::std::move(v)) {} 92 | }; 93 | 94 | //============================================================================== 95 | 96 | } // end namespace detail 97 | } // end namespace MDSPAN_IMPL_STANDARD_NAMESPACE 98 | -------------------------------------------------------------------------------- /tests/libcxx-backports/extents/comparison.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | // 12 | // template 13 | // friend constexpr bool operator==(const extents& lhs, 14 | // const extents& rhs) noexcept; 15 | // 16 | // Returns: true if lhs.rank() equals rhs.rank() and 17 | // if lhs.extent(r) equals rhs.extent(r) for every rank index r of rhs, otherwise false. 18 | // 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "../llvm_test_macros.h" 26 | 27 | template 28 | constexpr void test_comparison(bool equal, To dest, From src) { 29 | ASSERT_NOEXCEPT(dest == src); 30 | assert((dest == src) == equal); 31 | assert((dest != src) == !equal); 32 | } 33 | 34 | template 35 | constexpr void test_comparison_different_rank() { 36 | constexpr size_t D = std::dynamic_extent; 37 | 38 | test_comparison(false, std::extents(), std::extents(1)); 39 | test_comparison(false, std::extents(), std::extents()); 40 | 41 | test_comparison(false, std::extents(1), std::extents()); 42 | test_comparison(false, std::extents(), std::extents()); 43 | 44 | test_comparison(false, std::extents(5), std::extents(5, 5)); 45 | test_comparison(false, std::extents(), std::extents(5)); 46 | test_comparison(false, std::extents(), std::extents()); 47 | 48 | test_comparison(false, std::extents(5, 5), std::extents(5)); 49 | test_comparison(false, std::extents(5), std::extents(5)); 50 | test_comparison(false, std::extents(), std::extents()); 51 | } 52 | 53 | template 54 | constexpr void test_comparison_same_rank() { 55 | constexpr size_t D = std::dynamic_extent; 56 | 57 | test_comparison(true, std::extents(), std::extents()); 58 | 59 | test_comparison(true, std::extents(5), std::extents(5)); 60 | test_comparison(true, std::extents(), std::extents(5)); 61 | test_comparison(true, std::extents(5), std::extents()); 62 | test_comparison(true, std::extents(), std::extents< T2, 5>()); 63 | test_comparison(false, std::extents(5), std::extents(7)); 64 | test_comparison(false, std::extents(), std::extents(7)); 65 | test_comparison(false, std::extents(5), std::extents()); 66 | test_comparison(false, std::extents(), std::extents()); 67 | 68 | test_comparison(true, std::extents(5, 6, 7, 8, 9), std::extents(5, 6, 7, 8, 9)); 69 | test_comparison(true, std::extents(5, 7, 9), std::extents(6, 7)); 70 | test_comparison(true, std::extents(5, 6, 7, 8, 9), std::extents()); 71 | test_comparison( 72 | false, std::extents(5, 6, 7, 8, 9), std::extents(5, 6, 3, 8, 9)); 73 | test_comparison(false, std::extents(5, 7, 9), std::extents(6, 7)); 74 | test_comparison(false, std::extents(5, 6, 7, 8, 9), std::extents()); 75 | } 76 | 77 | template 78 | constexpr void test_comparison() { 79 | test_comparison_same_rank(); 80 | test_comparison_different_rank(); 81 | } 82 | 83 | constexpr bool test() { 84 | test_comparison(); 85 | test_comparison(); 86 | test_comparison(); 87 | test_comparison(); 88 | return true; 89 | } 90 | 91 | int main(int, char**) { 92 | test(); 93 | static_assert(test()); 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /benchmarks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | function(mdspan_add_benchmark EXENAME) 3 | add_executable(${EXENAME} ${EXENAME}.cpp) 4 | target_link_libraries(${EXENAME} mdspan benchmark::benchmark) 5 | target_include_directories(${EXENAME} PUBLIC 6 | $ 7 | ) 8 | # Set flag to build with parenthesis enabled 9 | target_compile_definitions(${EXENAME} PRIVATE MDSPAN_USE_PAREN_OPERATOR=1) 10 | endfunction() 11 | 12 | if(MDSPAN_USE_SYSTEM_BENCHMARK) 13 | find_package(benchmark REQUIRED) 14 | else() 15 | set(BENCHMARK_ENABLE_TESTING OFF) 16 | include(FetchContent) 17 | 18 | fetchcontent_declare( 19 | benchmark 20 | GIT_REPOSITORY https://github.com/google/benchmark.git 21 | GIT_TAG v1.9.1 22 | ) 23 | 24 | # TODO CMake 3.28, we can pass EXCLUDE_FROM_ALL directly to fetchcontent_makeavailable(benchmark) 25 | fetchcontent_getproperties(benchmarkgoogletest) 26 | if (NOT benchmark_POPULATED) 27 | fetchcontent_populate(benchmark) 28 | add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} EXCLUDE_FROM_ALL) 29 | endif() 30 | endif() 31 | 32 | function(mdspan_add_cuda_benchmark EXENAME) 33 | add_executable(${EXENAME} ${EXENAME}.cu) 34 | target_link_libraries(${EXENAME} PUBLIC mdspan) 35 | target_include_directories(${EXENAME} PUBLIC 36 | $ 37 | ) 38 | # This is gross, but it's the best I can do in this version of CMake 39 | get_target_property(_benchmark_include benchmark::benchmark INTERFACE_INCLUDE_DIRECTORIES) 40 | get_target_property(_benchmark_libs_old benchmark::benchmark INTERFACE_LINK_LIBRARIES) 41 | get_target_property(_benchmark_libs_imported benchmark::benchmark IMPORTED_LOCATION_RELEASE) 42 | if(NOT _benchmark_libs_imported) 43 | get_target_property(_benchmark_libs_imported benchmark::benchmark IMPORTED_LOCATION_DEBUG) 44 | if(NOT _benchmark_libs_imported) 45 | get_target_property(_benchmark_libs_imported benchmark::benchmark IMPORTED_LOCATION_RELWITHDEBINFO) 46 | if(NOT _benchmark_libs_imported) 47 | get_target_property(_benchmark_libs_imported benchmark::benchmark IMPORTED_LOCATION_MINSIZEREL) 48 | if(NOT _benchmark_libs_imported) 49 | message(FATAL_ERROR 50 | "Could not figure out how to import google benchmark to hack around a cmake Cuda compatibility issue. Later versions of CMake will make this unnecessary" 51 | ) 52 | else() 53 | message(WARNING "Importing a Google Benchmark installation that was compiled in MinSizeRel mode. Times might not be reliable") 54 | endif() 55 | else() 56 | message(WARNING "Importing a Google Benchmark installation that was compiled in RelWithDebInfo mode. Times might not be reliable") 57 | endif() 58 | else() 59 | message(WARNING "Importing a Google Benchmark installation that was compiled in Debug mode. Times might not be reliable") 60 | endif() 61 | endif() 62 | string(REPLACE "-pthread" "" _benchmark_libs "${_benchmark_libs_old}") 63 | target_include_directories(${EXENAME} PUBLIC "${_benchmark_include}") 64 | target_link_libraries(${EXENAME} PUBLIC "${_benchmark_libs};${_benchmark_libs_imported}") 65 | target_compile_definitions(${EXENAME} PRIVATE MDSPAN_USE_PAREN_OPERATOR=1) 66 | if(_benchmark_libs_old MATCHES "-pthread") 67 | target_compile_options(${EXENAME} PUBLIC "-Xcompiler=-pthread") 68 | endif() 69 | endfunction() 70 | 71 | if(MDSPAN_ENABLE_OPENMP) 72 | find_package(OpenMP) 73 | endif() 74 | 75 | function(mdspan_add_openmp_benchmark EXENAME) 76 | if(MDSPAN_ENABLE_OPENMP) 77 | if(OpenMP_CXX_FOUND) 78 | add_executable(${EXENAME} ${EXENAME}.cpp) 79 | target_link_libraries(${EXENAME} mdspan benchmark::benchmark OpenMP::OpenMP_CXX) 80 | target_include_directories(${EXENAME} PUBLIC 81 | $ 82 | ) 83 | target_compile_definitions(${EXENAME} PRIVATE MDSPAN_USE_PAREN_OPERATOR=1) 84 | else() 85 | message(WARNING "Not adding target ${EXENAME} because OpenMP was not found") 86 | endif() 87 | endif() 88 | endfunction() 89 | 90 | add_subdirectory(sum) 91 | add_subdirectory(matvec) 92 | add_subdirectory(copy) 93 | add_subdirectory(stencil) 94 | add_subdirectory(tiny_matrix_add) 95 | -------------------------------------------------------------------------------- /scripts/snl/gtest-hip-patch: -------------------------------------------------------------------------------- 1 | diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h 2 | index 7d7e77c1..025ed642 100644 3 | --- a/googletest/include/gtest/gtest-printers.h 4 | +++ b/googletest/include/gtest/gtest-printers.h 5 | @@ -473,7 +473,7 @@ GTEST_API_ void PrintTo(char32_t c, ::std::ostream* os); 6 | inline void PrintTo(char16_t c, ::std::ostream* os) { 7 | PrintTo(ImplicitCast_(c), os); 8 | } 9 | -#ifdef __cpp_char8_t 10 | +#ifdef __cpp_lib_char8_t 11 | inline void PrintTo(char8_t c, ::std::ostream* os) { 12 | PrintTo(ImplicitCast_(c), os); 13 | } 14 | @@ -586,7 +586,7 @@ inline void PrintTo(const unsigned char* s, ::std::ostream* os) { 15 | inline void PrintTo(unsigned char* s, ::std::ostream* os) { 16 | PrintTo(ImplicitCast_(s), os); 17 | } 18 | -#ifdef __cpp_char8_t 19 | +#ifdef __cpp_lib_char8_t 20 | // Overloads for u8 strings. 21 | GTEST_API_ void PrintTo(const char8_t* s, ::std::ostream* os); 22 | inline void PrintTo(char8_t* s, ::std::ostream* os) { 23 | @@ -906,7 +906,7 @@ void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) { 24 | GTEST_API_ void UniversalPrintArray(const char* begin, size_t len, 25 | ::std::ostream* os); 26 | 27 | -#ifdef __cpp_char8_t 28 | +#ifdef __cpp_lib_char8_t 29 | // This overload prints a (const) char8_t array compactly. 30 | GTEST_API_ void UniversalPrintArray(const char8_t* begin, size_t len, 31 | ::std::ostream* os); 32 | @@ -1002,7 +1002,7 @@ template <> 33 | class UniversalTersePrinter : public UniversalTersePrinter { 34 | }; 35 | 36 | -#ifdef __cpp_char8_t 37 | +#ifdef __cpp_lib_char8_t 38 | template <> 39 | class UniversalTersePrinter { 40 | public: 41 | diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h 42 | index b4fa3f07..594a038c 100644 43 | --- a/googletest/include/gtest/internal/gtest-port.h 44 | +++ b/googletest/include/gtest/internal/gtest-port.h 45 | @@ -1939,7 +1939,7 @@ inline bool IsUpper(char ch) { 46 | inline bool IsXDigit(char ch) { 47 | return isxdigit(static_cast(ch)) != 0; 48 | } 49 | -#ifdef __cpp_char8_t 50 | +#ifdef __cpp_lib_char8_t 51 | inline bool IsXDigit(char8_t ch) { 52 | return isxdigit(static_cast(ch)) != 0; 53 | } 54 | diff --git a/googletest/src/gtest-printers.cc b/googletest/src/gtest-printers.cc 55 | index d475ad36..7ccd181d 100644 56 | --- a/googletest/src/gtest-printers.cc 57 | +++ b/googletest/src/gtest-printers.cc 58 | @@ -214,7 +214,7 @@ static const char* GetCharWidthPrefix(signed char) { return ""; } 59 | 60 | static const char* GetCharWidthPrefix(unsigned char) { return ""; } 61 | 62 | -#ifdef __cpp_char8_t 63 | +#ifdef __cpp_lib_char8_t 64 | static const char* GetCharWidthPrefix(char8_t) { return "u8"; } 65 | #endif 66 | 67 | @@ -230,7 +230,7 @@ static CharFormat PrintAsStringLiteralTo(char c, ostream* os) { 68 | return PrintAsStringLiteralTo(ToChar32(c), os); 69 | } 70 | 71 | -#ifdef __cpp_char8_t 72 | +#ifdef __cpp_lib_char8_t 73 | static CharFormat PrintAsStringLiteralTo(char8_t c, ostream* os) { 74 | return PrintAsStringLiteralTo(ToChar32(c), os); 75 | } 76 | @@ -393,7 +393,7 @@ void UniversalPrintArray(const char* begin, size_t len, ostream* os) { 77 | UniversalPrintCharArray(begin, len, os); 78 | } 79 | 80 | -#ifdef __cpp_char8_t 81 | +#ifdef __cpp_lib_char8_t 82 | // Prints a (const) char8_t array of 'len' elements, starting at address 83 | // 'begin'. 84 | void UniversalPrintArray(const char8_t* begin, size_t len, ostream* os) { 85 | @@ -436,7 +436,7 @@ void PrintCStringTo(const Char* s, ostream* os) { 86 | 87 | void PrintTo(const char* s, ostream* os) { PrintCStringTo(s, os); } 88 | 89 | -#ifdef __cpp_char8_t 90 | +#ifdef __cpp_lib_char8_t 91 | void PrintTo(const char8_t* s, ostream* os) { PrintCStringTo(s, os); } 92 | #endif 93 | 94 | @@ -528,7 +528,7 @@ void PrintStringTo(const ::std::string& s, ostream* os) { 95 | } 96 | } 97 | 98 | -#ifdef __cpp_char8_t 99 | +#ifdef __cpp_lib_char8_t 100 | void PrintU8StringTo(const ::std::u8string& s, ostream* os) { 101 | PrintCharsAsStringTo(s.data(), s.size(), os); 102 | } 103 | -------------------------------------------------------------------------------- /examples/dot_product/dot_product.cpp: -------------------------------------------------------------------------------- 1 | //@HEADER 2 | // ************************************************************************ 3 | // 4 | // Kokkos v. 4.0 5 | // Copyright (2022) National Technology & Engineering 6 | // Solutions of Sandia, LLC (NTESS). 7 | // 8 | // Under the terms of Contract DE-NA0003525 with NTESS, 9 | // the U.S. Government retains certain rights in this software. 10 | // 11 | // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. 12 | // See https://kokkos.org/LICENSE for license information. 13 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 14 | // 15 | //@HEADER 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | #if !(defined(__cpp_lib_make_unique) && __cpp_lib_make_unique >= 201304) && !MDSPAN_HAS_CXX_14 24 | // Not actually conforming, but it works for the purposes of this file 25 | namespace std { 26 | template 27 | struct __unique_ptr_new_impl { 28 | template 29 | static T* __impl(Args&&... args) { 30 | return new T((Args&&)args...); 31 | } 32 | }; 33 | template 34 | struct __unique_ptr_new_impl { 35 | static T* __impl(size_t size) { 36 | return new T[size]; 37 | } 38 | }; 39 | template 40 | std::unique_ptr make_unique(Args&&... args) { 41 | return std::unique_ptr(__unique_ptr_new_impl::__impl((Args&&)args...)); 42 | } 43 | } // end namespace std 44 | #endif 45 | 46 | //================================================================================ 47 | 48 | template < 49 | class T, 50 | class ExtsA, class LayA, class AccA, 51 | class ExtsB, class LayB, class AccB 52 | > 53 | T dot_product( 54 | Kokkos::mdspan a, 55 | Kokkos::mdspan b 56 | ) //requires ExtsA::rank() == ExtsB::rank() && ExtsA::rank() == 2 57 | { 58 | using int_t = typename ExtsA::index_type; 59 | T result = 0; 60 | for(int_t i = 0; i < a.extent(0); ++i) { 61 | for(int_t j = 0; j < a.extent(1); ++j) { 62 | #if MDSPAN_USE_BRACKET_OPERATOR 63 | result += a[i, j] * b[i, j]; 64 | #else 65 | result += a(i, j) * b(i, j); 66 | #endif 67 | } 68 | } 69 | return result; 70 | } 71 | 72 | //================================================================================ 73 | 74 | template < 75 | class T, 76 | class ExtsA, class LayA, class AccA 77 | > 78 | void fill_in_order( 79 | Kokkos::mdspan a 80 | ) // requires ExtsA::rank() == 2 81 | { 82 | using int_t = typename ExtsA::index_type; 83 | T count = 0; 84 | for(int_t i = 0; i < a.extent(0); ++i) { 85 | for(int_t j = 0; j < a.extent(1); ++j) { 86 | #if MDSPAN_USE_BRACKET_OPERATOR 87 | a[i, j] = count++; 88 | #else 89 | a(i, j) = count++; 90 | #endif 91 | } 92 | } 93 | } 94 | 95 | //================================================================================ 96 | 97 | constexpr int rows = 3; 98 | constexpr int cols = 3; 99 | 100 | //================================================================================ 101 | 102 | int main() { 103 | { 104 | using span_2d_dynamic = Kokkos::mdspan, Kokkos::layout_right>; 105 | using span_2d_dynamic_left = Kokkos::mdspan, Kokkos::layout_left>; 106 | 107 | auto data_a = std::make_unique(rows * cols); 108 | auto data_b = std::make_unique(rows * cols); 109 | 110 | auto a = span_2d_dynamic(data_a.get(), rows, cols); 111 | auto b = span_2d_dynamic_left(data_b.get(), rows, cols); 112 | fill_in_order(a); 113 | fill_in_order(b); 114 | 115 | std::cout << dot_product(a, b) << std::endl; 116 | } 117 | 118 | { 119 | using span_2d_10_10 = Kokkos::mdspan, Kokkos::layout_right>; 120 | using span_2d_10_10_left = Kokkos::mdspan, Kokkos::layout_right>; 121 | 122 | auto data_a = std::make_unique(100); 123 | auto data_b = std::make_unique(100); 124 | 125 | auto a = span_2d_10_10(data_a.get()); 126 | auto b = span_2d_10_10_left(data_b.get()); 127 | fill_in_order(a); 128 | fill_in_order(b); 129 | 130 | std::cout << dot_product(a, b) << std::endl; 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /tests/libcxx-backports/mdspan/mdspan.ctor.copy.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // constexpr mdspan(const mdspan&) = default; 13 | // 14 | // A specialization of mdspan is a trivially copyable type if its accessor_type, mapping_type, and data_handle_type are trivially copyable types. 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "../llvm_test_macros.h" 22 | 23 | #include "../MinimalElementType.h" 24 | #include "../CustomTestLayouts.h" 25 | #include "CustomTestAccessors.h" 26 | 27 | template 28 | constexpr void test_mdspan_types(const H& handle, const M& map, const A& acc) { 29 | using MDS = std::mdspan; 30 | 31 | MDS m_org(handle, map, acc); 32 | MDS m(m_org); 33 | static_assert(noexcept(MDS(m_org)) == (noexcept(H(handle))&& noexcept(M(map))&& noexcept(A(acc)))); 34 | static_assert( 35 | std::is_trivially_copyable_v == 36 | (std::is_trivially_copyable_v && std::is_trivially_copyable_v && std::is_trivially_copyable_v)); 37 | assert(m.extents() == map.extents()); 38 | if constexpr (std::equality_comparable) 39 | assert(m.data_handle() == handle); 40 | if constexpr (std::equality_comparable) 41 | assert(m.mapping() == map); 42 | if constexpr (std::equality_comparable) 43 | assert(m.accessor() == acc); 44 | } 45 | 46 | template 47 | constexpr void mixin_extents(const H& handle, const L& layout, const A& acc) { 48 | constexpr size_t D = std::dynamic_extent; 49 | test_mdspan_types(handle, construct_mapping(layout, std::extents()), acc); 50 | test_mdspan_types(handle, construct_mapping(layout, std::extents(7)), acc); 51 | test_mdspan_types(handle, construct_mapping(layout, std::extents()), acc); 52 | test_mdspan_types(handle, construct_mapping(layout, std::extents(2, 3)), acc); 53 | test_mdspan_types(handle, construct_mapping(layout, std::extents(0, 3)), acc); 54 | test_mdspan_types(handle, construct_mapping(layout, std::extents(1, 2, 3, 2)), acc); 55 | } 56 | 57 | template 58 | constexpr void mixin_layout(const H& handle, const A& acc) { 59 | // make sure we test a trivially copyable mapping 60 | static_assert(std::is_trivially_copyable_v>>); 61 | mixin_extents(handle, std::layout_left(), acc); 62 | mixin_extents(handle, std::layout_right(), acc); 63 | // make sure we test a not trivially copyable mapping 64 | static_assert( 65 | !std::is_trivially_copyable_v::template mapping>>); 66 | mixin_extents(handle, layout_wrapping_integral<4>(), acc); 67 | } 68 | 69 | template 70 | constexpr void mixin_accessor() { 71 | ElementPool elements; 72 | // make sure we test trivially constructible accessor and data_handle 73 | static_assert(std::is_trivially_copyable_v>); 74 | static_assert(std::is_trivially_copyable_v::data_handle_type>); 75 | mixin_layout(elements.get_ptr(), std::default_accessor()); 76 | 77 | // Using weird accessor/data_handle 78 | // Make sure they actually got the properties we want to test 79 | // checked_accessor is noexcept copy constructible except for const double 80 | checked_accessor acc(1024); 81 | static_assert(noexcept(checked_accessor(acc)) != std::is_same_v); 82 | mixin_layout(typename checked_accessor::data_handle_type(elements.get_ptr()), acc); 83 | } 84 | 85 | constexpr bool test() { 86 | mixin_accessor(); 87 | mixin_accessor(); 88 | mixin_accessor(); 89 | mixin_accessor(); 90 | mixin_accessor(); 91 | mixin_accessor(); 92 | return true; 93 | } 94 | int main(int, char**) { 95 | test(); 96 | static_assert(test()); 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /tests/libcxx-backports/extents/ctor_from_array.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // Test construction from array: 13 | // 14 | // template 15 | // constexpr explicit(N != rank_dynamic()) extents(const array& exts) noexcept; 16 | // 17 | // Constraints: 18 | // * is_convertible_v is true, 19 | // * is_nothrow_constructible_v is true, and 20 | // * N == rank_dynamic() || N == rank() is true. 21 | // 22 | // Preconditions: 23 | // * If N != rank_dynamic() is true, exts[r] equals Er for each r for which 24 | // Er is a static extent, and 25 | // * either 26 | // - N is zero, or 27 | // - exts[r] is nonnegative and is representable as a value of type index_type 28 | // for every rank index r. 29 | // 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "../ConvertibleToIntegral.h" 37 | #include "CtorTestCombinations.h" 38 | #include "../llvm_test_macros.h" 39 | 40 | struct ArrayCtorTest { 41 | template 42 | static constexpr void test_construction(std::array all_ext, Extents ext, std::index_sequence) { 43 | ASSERT_NOEXCEPT(E(ext)); 44 | if constexpr (N == E::rank_dynamic()) { 45 | test_implicit_construction_call(ext, all_ext); 46 | } 47 | test_runtime_observers(E(ext), all_ext); 48 | } 49 | }; 50 | 51 | template 52 | struct implicit_construction { 53 | bool value; 54 | implicit_construction(E) : value(true) {} 55 | template 56 | implicit_construction(T) : value(false) {} 57 | }; 58 | 59 | int main(int, char**) { 60 | test_index_type_combo(); 61 | static_assert(test_index_type_combo()); 62 | 63 | constexpr size_t D = std::dynamic_extent; 64 | using E = std::extents; 65 | 66 | // check can't construct from too few arguments 67 | static_assert(!std::is_constructible_v>, "extents constructible from illegal arguments"); 68 | // check can't construct from rank_dynamic < #args < rank 69 | static_assert(!std::is_constructible_v>, "extents constructible from illegal arguments"); 70 | // check can't construct from too many arguments 71 | static_assert(!std::is_constructible_v>, "extents constructible from illegal arguments"); 72 | 73 | // test implicit construction fails from span and array if all extents are given 74 | std::array a5{3, 4, 5, 6, 7}; 75 | // check that explicit construction works, i.e. no error 76 | static_assert(std::is_constructible_v< std::extents, decltype(a5)>, 77 | "extents unexpectectly not constructible"); 78 | // check that implicit construction doesn't work 79 | assert((implicit_construction>(a5).value == false)); 80 | 81 | // test construction fails from types not convertible to index_type but convertible to other integer types 82 | static_assert(std::is_convertible_v, "Test helper IntType unexpectedly not convertible to int"); 83 | static_assert(!std::is_constructible_v< std::extents, std::array>, 84 | "extents constructible from illegal arguments"); 85 | 86 | // index_type is not nothrow constructible 87 | static_assert(std::is_convertible_v); 88 | static_assert(std::is_convertible_v); 89 | static_assert(!std::is_nothrow_constructible_v); 90 | static_assert(!std::is_constructible_v, std::array>); 91 | 92 | // convertible from non-const to index_type but not from const 93 | static_assert(std::is_convertible_v); 94 | static_assert(!std::is_convertible_v); 95 | static_assert(std::is_nothrow_constructible_v); 96 | static_assert(!std::is_constructible_v, std::array>); 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /tests/libcxx-backports/mdspan/mdspan.ctor.move.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // constexpr mdspan(mdspan&&) = default; 13 | // 14 | // A specialization of mdspan is a trivially copyable type if its accessor_type, mapping_type, and data_handle_type are trivially copyable types. 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "../llvm_test_macros.h" 22 | 23 | #include "../MinimalElementType.h" 24 | #include "../CustomTestLayouts.h" 25 | #include "CustomTestAccessors.h" 26 | 27 | template 28 | constexpr void test_mdspan_types(const H& handle, const M& map, const A& acc) { 29 | using MDS = std::mdspan; 30 | 31 | MDS m_org(handle, map, acc); 32 | MDS m(std::move(m_org)); 33 | static_assert(std::is_trivially_move_constructible_v == 34 | (std::is_trivially_move_constructible_v && std::is_trivially_move_constructible_v && 35 | std::is_trivially_move_constructible_v)); 36 | assert(m.extents() == map.extents()); 37 | if constexpr (std::equality_comparable) 38 | assert(m.data_handle() == handle); 39 | if constexpr (std::equality_comparable) 40 | assert(m.mapping() == map); 41 | if constexpr (std::equality_comparable) 42 | assert(m.accessor() == acc); 43 | } 44 | 45 | template 46 | constexpr void mixin_extents(const H& handle, const L& layout, const A& acc) { 47 | constexpr size_t D = std::dynamic_extent; 48 | test_mdspan_types(handle, construct_mapping(layout, std::extents()), acc); 49 | test_mdspan_types(handle, construct_mapping(layout, std::extents(7)), acc); 50 | test_mdspan_types(handle, construct_mapping(layout, std::extents()), acc); 51 | test_mdspan_types(handle, construct_mapping(layout, std::extents(2, 3)), acc); 52 | test_mdspan_types(handle, construct_mapping(layout, std::extents(0, 3)), acc); 53 | test_mdspan_types(handle, construct_mapping(layout, std::extents(1, 2, 3, 2)), acc); 54 | } 55 | 56 | template 57 | constexpr void mixin_layout(const H& handle, const A& acc) { 58 | // make sure we test a trivially copyable mapping 59 | static_assert(std::is_trivially_move_constructible_v>>); 60 | mixin_extents(handle, std::layout_left(), acc); 61 | mixin_extents(handle, std::layout_right(), acc); 62 | // make sure we test a not trivially copyable mapping 63 | static_assert(!std::is_trivially_move_constructible_v< 64 | typename layout_wrapping_integral<4>::template mapping>>); 65 | mixin_extents(handle, layout_wrapping_integral<4>(), acc); 66 | } 67 | 68 | template 69 | constexpr void mixin_accessor() { 70 | ElementPool elements; 71 | // make sure we test trivially constructible accessor and data_handle 72 | static_assert(std::is_trivially_move_constructible_v>); 73 | static_assert(std::is_trivially_move_constructible_v::data_handle_type>); 74 | mixin_layout(elements.get_ptr(), std::default_accessor()); 75 | 76 | // Using weird accessor/data_handle 77 | // Make sure they actually got the properties we want to test 78 | // checked_accessor is noexcept copy constructible except for const double 79 | checked_accessor acc(1024); 80 | static_assert(std::is_trivially_move_constructible_v::data_handle_type> == 81 | std::is_same_v); 82 | mixin_layout(typename checked_accessor::data_handle_type(elements.get_ptr()), acc); 83 | } 84 | 85 | constexpr bool test() { 86 | mixin_accessor(); 87 | mixin_accessor(); 88 | mixin_accessor(); 89 | mixin_accessor(); 90 | mixin_accessor(); 91 | mixin_accessor(); 92 | return true; 93 | } 94 | int main(int, char**) { 95 | test(); 96 | static_assert(test()); 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /tests/libcxx-backports/mdspan/mdspan.move.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // constexpr mdspan& operator=(mdspan&&) = default; 13 | // 14 | // A specialization of mdspan is a trivially copyable type if its accessor_type, mapping_type, and data_handle_type are trivially copyable types. 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "../llvm_test_macros.h" 22 | 23 | #include "../MinimalElementType.h" 24 | #include "../CustomTestLayouts.h" 25 | #include "CustomTestAccessors.h" 26 | 27 | template 28 | constexpr void test_mdspan_types(const H& handle, const M& map, const A& acc) { 29 | using MDS = std::mdspan; 30 | 31 | MDS m_org(handle, map, acc); 32 | MDS m_copy(m_org); 33 | MDS m(std::move(m_copy)); 34 | 35 | assert(m.extents() == map.extents()); 36 | if constexpr (std::equality_comparable) 37 | assert(m.data_handle() == handle); 38 | if constexpr (std::equality_comparable) 39 | assert(m.mapping() == map); 40 | if constexpr (std::equality_comparable) 41 | assert(m.accessor() == acc); 42 | 43 | static_assert(std::is_trivially_move_assignable_v == 44 | (std::is_trivially_move_assignable_v && std::is_trivially_move_assignable_v && 45 | std::is_trivially_move_assignable_v)); 46 | } 47 | 48 | template 49 | constexpr void mixin_extents(const H& handle, const L& layout, const A& acc) { 50 | constexpr size_t D = std::dynamic_extent; 51 | test_mdspan_types(handle, construct_mapping(layout, std::extents()), acc); 52 | test_mdspan_types(handle, construct_mapping(layout, std::extents(7)), acc); 53 | test_mdspan_types(handle, construct_mapping(layout, std::extents()), acc); 54 | test_mdspan_types(handle, construct_mapping(layout, std::extents(2, 3)), acc); 55 | test_mdspan_types(handle, construct_mapping(layout, std::extents(0, 3)), acc); 56 | test_mdspan_types(handle, construct_mapping(layout, std::extents(1, 2, 3, 2)), acc); 57 | } 58 | 59 | template 60 | constexpr void mixin_layout(const H& handle, const A& acc) { 61 | // make sure we test a trivially copyable mapping 62 | static_assert(std::is_trivially_move_assignable_v>>); 63 | mixin_extents(handle, std::layout_left(), acc); 64 | mixin_extents(handle, std::layout_right(), acc); 65 | // make sure we test a not trivially copyable mapping 66 | static_assert( 67 | !std::is_trivially_move_assignable_v::template mapping>>); 68 | mixin_extents(handle, layout_wrapping_integral<4>(), acc); 69 | } 70 | 71 | template 72 | constexpr void mixin_accessor() { 73 | ElementPool elements; 74 | // make sure we test trivially constructible accessor and data_handle 75 | static_assert(std::is_trivially_copyable_v>); 76 | static_assert(std::is_trivially_copyable_v::data_handle_type>); 77 | mixin_layout(elements.get_ptr(), std::default_accessor()); 78 | 79 | // Using weird accessor/data_handle 80 | // Make sure they actually got the properties we want to test 81 | // checked_accessor is noexcept copy constructible except for const double 82 | checked_accessor acc(1024); 83 | static_assert(noexcept(checked_accessor(acc)) != std::is_same_v); 84 | mixin_layout(typename checked_accessor::data_handle_type(elements.get_ptr()), acc); 85 | } 86 | 87 | constexpr bool test() { 88 | mixin_accessor(); 89 | mixin_accessor(); 90 | mixin_accessor(); 91 | mixin_accessor(); 92 | mixin_accessor(); 93 | mixin_accessor(); 94 | return true; 95 | } 96 | int main(int, char**) { 97 | test(); 98 | static_assert(test()); 99 | return 0; 100 | } 101 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_right/layout_right.index_operator.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // Test default iteration: 14 | // 15 | // template 16 | // constexpr index_type operator()(Indices...) const noexcept; 17 | // 18 | // Constraints: 19 | // * sizeof...(Indices) == extents_type::rank() is true, 20 | // * (is_convertible_v && ...) is true, and 21 | // * (is_nothrow_constructible_v && ...) is true. 22 | // 23 | // Preconditions: 24 | // * extents_type::index-cast(i) is a multidimensional index in extents_. 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "../llvm_test_macros.h" 31 | 32 | #include "../ConvertibleToIntegral.h" 33 | 34 | template 35 | concept operator_constraints = requires(Mapping m, Indices ... idxs) { 36 | {std::is_same_v}; 37 | }; 38 | 39 | template 40 | requires( 41 | operator_constraints 42 | ) 43 | constexpr bool check_operator_constraints(Mapping m, Indices ... idxs) { 44 | (void) m(idxs...); 45 | return true; 46 | } 47 | 48 | template 49 | constexpr bool check_operator_constraints(Mapping, Indices ...) { 50 | return false; 51 | } 52 | 53 | template 54 | constexpr void iterate_right(M m, T& count, Args... args) { 55 | constexpr size_t r = sizeof...(Args); 56 | if constexpr (M::extents_type::rank() == r) { 57 | ASSERT_NOEXCEPT(m(args...)); 58 | assert(count == m(args...)); 59 | count++; 60 | } else { 61 | for (typename M::index_type i = 0; i < m.extents().extent(r); i++) { 62 | iterate_right(m, count, args..., i); 63 | } 64 | } 65 | } 66 | 67 | template 68 | constexpr void test_iteration(Args... args) { 69 | using M = std::layout_right::mapping; 70 | M m(E(args...)); 71 | 72 | typename E::index_type count = 0; 73 | iterate_right(m, count); 74 | } 75 | 76 | constexpr bool test() { 77 | constexpr size_t D = std::dynamic_extent; 78 | test_iteration>(); 79 | test_iteration>(1); 80 | test_iteration>(7); 81 | test_iteration>(); 82 | test_iteration>(); 83 | test_iteration>(1, 1, 1, 1); 84 | 85 | // Check operator constraint for number of arguments 86 | static_assert(check_operator_constraints(std::layout_right::mapping>(std::extents(1)), 0)); 87 | static_assert(!check_operator_constraints(std::layout_right::mapping>(std::extents(1)), 0, 0)); 88 | 89 | // Check operator constraint for convertibility of arguments to index_type 90 | static_assert(check_operator_constraints(std::layout_right::mapping>(std::extents(1)), IntType(0))); 91 | static_assert(!check_operator_constraints(std::layout_right::mapping>(std::extents(1)), IntType(0))); 92 | 93 | // Check operator constraint for no-throw-constructibility of index_type from arguments 94 | static_assert(!check_operator_constraints(std::layout_right::mapping>(std::extents(1)), IntType(0))); 95 | 96 | return true; 97 | } 98 | 99 | constexpr bool test_large() { 100 | constexpr size_t D = std::dynamic_extent; 101 | test_iteration>(7, 9, 10); 102 | test_iteration>(7, 10); 103 | return true; 104 | } 105 | 106 | int main(int, char**) { 107 | test(); 108 | static_assert(test()); 109 | 110 | // The large test iterates over ~10k loop indices. 111 | // With assertions enabled this triggered the maximum default limit 112 | // for steps in consteval expressions. Assertions roughly double the 113 | // total number of instructions, so this was already close to the maximum. 114 | test_large(); 115 | return 0; 116 | } 117 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_stride/layout_stride.properties.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // namespace std { 14 | // template 15 | // class layout_stride::mapping { 16 | // 17 | // ... 18 | // static constexpr bool is_always_unique() noexcept { return true; } 19 | // static constexpr bool is_always_exhaustive() noexcept { return false; } 20 | // static constexpr bool is_always_strided() noexcept { return true; } 21 | // 22 | // static constexpr bool is_unique() noexcept { return true; } 23 | // static constexpr bool is_exhaustive() noexcept; 24 | // static constexpr bool is_strided() noexcept { return true; } 25 | // ... 26 | // }; 27 | // } 28 | // 29 | // 30 | // layout_stride::mapping is a trivially copyable type that models regular for each E. 31 | // 32 | // constexpr bool is_exhaustive() const noexcept; 33 | // 34 | // Returns: 35 | // - true if rank_ is 0. 36 | // - Otherwise, true if there is a permutation P of the integers in the range [0, rank_) such that 37 | // stride(p0) equals 1, and stride(pi) equals stride(pi_1) * extents().extent(pi_1) for i in the 38 | // range [1, rank_), where pi is the ith element of P. 39 | // - Otherwise, false. 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "../llvm_test_macros.h" 47 | 48 | template 49 | constexpr void 50 | test_layout_mapping_stride(E ext, std::array strides, bool exhaustive) { 51 | using M = std::layout_stride::template mapping; 52 | M m(ext, strides); 53 | const M c_m = m; 54 | assert(m.strides() == strides); 55 | assert(c_m.strides() == strides); 56 | assert(m.extents() == ext); 57 | assert(c_m.extents() == ext); 58 | assert(M::is_unique() == true); 59 | assert(m.is_exhaustive() == exhaustive); 60 | assert(c_m.is_exhaustive() == exhaustive); 61 | assert(M::is_strided() == true); 62 | assert(M::is_always_unique() == true); 63 | assert(M::is_always_exhaustive() == false); 64 | assert(M::is_always_strided() == true); 65 | 66 | ASSERT_NOEXCEPT(m.strides()); 67 | ASSERT_NOEXCEPT(c_m.strides()); 68 | ASSERT_NOEXCEPT(m.extents()); 69 | ASSERT_NOEXCEPT(c_m.extents()); 70 | ASSERT_NOEXCEPT(M::is_unique()); 71 | ASSERT_NOEXCEPT(m.is_exhaustive()); 72 | ASSERT_NOEXCEPT(c_m.is_exhaustive()); 73 | ASSERT_NOEXCEPT(M::is_strided()); 74 | ASSERT_NOEXCEPT(M::is_always_unique()); 75 | ASSERT_NOEXCEPT(M::is_always_exhaustive()); 76 | ASSERT_NOEXCEPT(M::is_always_strided()); 77 | 78 | for (typename E::rank_type r = 0; r < E::rank(); r++) { 79 | assert(m.stride(r) == strides[r]); 80 | assert(c_m.stride(r) == strides[r]); 81 | ASSERT_NOEXCEPT(m.stride(r)); 82 | ASSERT_NOEXCEPT(c_m.stride(r)); 83 | } 84 | 85 | typename E::index_type expected_size = 1; 86 | for (typename E::rank_type r = 0; r < E::rank(); r++) { 87 | if (ext.extent(r) == 0) { 88 | expected_size = 0; 89 | break; 90 | } 91 | expected_size += (ext.extent(r) - 1) * static_cast(strides[r]); 92 | } 93 | assert(m.required_span_size() == expected_size); 94 | assert(c_m.required_span_size() == expected_size); 95 | ASSERT_NOEXCEPT(m.required_span_size()); 96 | ASSERT_NOEXCEPT(c_m.required_span_size()); 97 | 98 | static_assert(std::is_trivially_copyable_v); 99 | static_assert(std::regular); 100 | } 101 | 102 | constexpr bool test() { 103 | constexpr size_t D = std::dynamic_extent; 104 | test_layout_mapping_stride(std::extents(), std::array{}, true); 105 | test_layout_mapping_stride(std::extents(), std::array{1, 4}, true); 106 | test_layout_mapping_stride(std::extents(), std::array{1, 5}, false); 107 | test_layout_mapping_stride(std::extents(7), std::array{20, 2}, false); 108 | test_layout_mapping_stride(std::extents(3, 3, 3, 3), std::array{3, 1, 9, 27}, true); 109 | return true; 110 | } 111 | 112 | int main(int, char**) { 113 | test(); 114 | static_assert(test()); 115 | return 0; 116 | } 117 | -------------------------------------------------------------------------------- /tests/libcxx-backports/layout_left/layout_left.index_operator.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 10 | 11 | // 12 | 13 | // Test default iteration: 14 | // 15 | // template 16 | // constexpr index_type operator()(Indices...) const noexcept; 17 | // 18 | // Constraints: 19 | // * sizeof...(Indices) == extents_type::rank() is true, 20 | // * (is_convertible_v && ...) is true, and 21 | // * (is_nothrow_constructible_v && ...) is true. 22 | // 23 | // Preconditions: 24 | // * extents_type::index-cast(i) is a multidimensional index in extents_. 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "../llvm_test_macros.h" 31 | 32 | #include "../ConvertibleToIntegral.h" 33 | 34 | template 35 | concept operator_constraints = requires(Mapping m, Indices ... idxs) { 36 | {std::is_same_v}; 37 | }; 38 | 39 | template 40 | requires( 41 | operator_constraints 42 | ) 43 | constexpr bool check_operator_constraints(Mapping m, Indices ... idxs) { 44 | (void) m(idxs...); 45 | return true; 46 | } 47 | 48 | template 49 | constexpr bool check_operator_constraints(Mapping, Indices ...) { 50 | return false; 51 | } 52 | 53 | template 54 | constexpr void iterate_left(M m, T& count, Args... args) { 55 | constexpr int r = static_cast(M::extents_type::rank()) - 1 - static_cast(sizeof...(Args)); 56 | if constexpr (-1 == r) { 57 | ASSERT_NOEXCEPT(m(args...)); 58 | assert(count == m(args...)); 59 | count++; 60 | } else { 61 | for (typename M::index_type i = 0; i < m.extents().extent(r); i++) { 62 | iterate_left(m, count, i, args...); 63 | } 64 | } 65 | } 66 | 67 | template 68 | constexpr void test_iteration(Args... args) { 69 | using M = std::layout_left::mapping; 70 | M m(E(args...)); 71 | 72 | typename E::index_type count = 0; 73 | iterate_left(m, count); 74 | } 75 | 76 | constexpr bool test() { 77 | constexpr size_t D = std::dynamic_extent; 78 | test_iteration>(); 79 | test_iteration>(1); 80 | test_iteration>(7); 81 | test_iteration>(); 82 | test_iteration>(); 83 | test_iteration>(1, 1, 1, 1); 84 | 85 | // Check operator constraint for number of arguments 86 | static_assert(check_operator_constraints(std::layout_left::mapping>(std::extents(1)), 0)); 87 | static_assert(!check_operator_constraints(std::layout_left::mapping>(std::extents(1)), 0, 0)); 88 | 89 | // Check operator constraint for convertibility of arguments to index_type 90 | static_assert(check_operator_constraints(std::layout_left::mapping>(std::extents(1)), IntType(0))); 91 | static_assert(!check_operator_constraints(std::layout_left::mapping>(std::extents(1)), IntType(0))); 92 | 93 | // Check operator constraint for no-throw-constructibility of index_type from arguments 94 | static_assert(!check_operator_constraints(std::layout_left::mapping>(std::extents(1)), IntType(0))); 95 | 96 | return true; 97 | } 98 | 99 | constexpr bool test_large() { 100 | constexpr size_t D = std::dynamic_extent; 101 | test_iteration>(7, 9, 10); 102 | test_iteration>(7, 10); 103 | return true; 104 | } 105 | 106 | int main(int, char**) { 107 | test(); 108 | static_assert(test()); 109 | 110 | // The large test iterates over ~10k loop indices. 111 | // With assertions enabled this triggered the maximum default limit 112 | // for steps in consteval expressions. Assertions roughly double the 113 | // total number of instructions, so this was already close to the maximum. 114 | test_large(); 115 | return 0; 116 | } 117 | -------------------------------------------------------------------------------- /tests/libcxx-backports/extents/ctor_from_span.pass.cpp: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 | 10 | // 11 | 12 | // Test construction from span: 13 | // 14 | // template 15 | // constexpr explicit(N != rank_dynamic()) extents(span exts) noexcept; 16 | // 17 | // Constraints: 18 | // * is_convertible_v is true, 19 | // * is_nothrow_constructible_v is true, and 20 | // * N == rank_dynamic() || N == rank() is true. 21 | // 22 | // Preconditions: 23 | // * If N != rank_dynamic() is true, exts[r] equals Er for each r for which 24 | // Er is a static extent, and 25 | // * either 26 | // - N is zero, or 27 | // - exts[r] is nonnegative and is representable as a value of type index_type 28 | // for every rank index r. 29 | // 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "../ConvertibleToIntegral.h" 38 | #include "CtorTestCombinations.h" 39 | #include "../llvm_test_macros.h" 40 | 41 | struct SpanCtorTest { 42 | template 43 | static constexpr void test_construction(std::array all_ext, Extents ext, std::index_sequence) { 44 | ASSERT_NOEXCEPT(E(ext)); 45 | if constexpr (N == E::rank_dynamic()) { 46 | test_implicit_construction_call(std::span(ext), all_ext); 47 | } 48 | test_runtime_observers(E(std::span(ext)), all_ext); 49 | } 50 | }; 51 | 52 | template 53 | struct implicit_construction { 54 | bool value; 55 | implicit_construction(E) : value(true) {} 56 | template 57 | implicit_construction(T) : value(false) {} 58 | }; 59 | 60 | int main(int, char**) { 61 | test_index_type_combo(); 62 | static_assert(test_index_type_combo()); 63 | 64 | constexpr size_t D = std::dynamic_extent; 65 | using E = std::extents; 66 | 67 | // check can't construct from too few arguments 68 | static_assert(!std::is_constructible_v>, "extents constructible from illegal arguments"); 69 | // check can't construct from rank_dynamic < #args < rank 70 | static_assert(!std::is_constructible_v>, "extents constructible from illegal arguments"); 71 | // check can't construct from too many arguments 72 | static_assert(!std::is_constructible_v>, "extents constructible from illegal arguments"); 73 | 74 | // test implicit construction fails from span and array if all extents are given 75 | std::array a5{3, 4, 5, 6, 7}; 76 | std::span s5(a5.data(), 5); 77 | // check that explicit construction works, i.e. no error 78 | static_assert(std::is_constructible_v< std::extents, decltype(s5)>, 79 | "extents unexpectectly not constructible"); 80 | // check that implicit construction doesn't work 81 | assert((implicit_construction>(s5).value == false)); 82 | 83 | // test construction fails from types not convertible to index_type but convertible to other integer types 84 | static_assert(std::is_convertible_v, "Test helper IntType unexpectedly not convertible to int"); 85 | static_assert(!std::is_constructible_v< std::extents, std::span>, 86 | "extents constructible from illegal arguments"); 87 | 88 | // index_type is not nothrow constructible 89 | static_assert(std::is_convertible_v); 90 | static_assert(std::is_convertible_v); 91 | static_assert(!std::is_nothrow_constructible_v); 92 | static_assert(!std::is_constructible_v, std::span>); 93 | 94 | // convertible from non-const to index_type but not from const 95 | static_assert(std::is_convertible_v); 96 | static_assert(!std::is_convertible_v); 97 | static_assert(std::is_nothrow_constructible_v); 98 | static_assert(!std::is_constructible_v, std::span>); 99 | return 0; 100 | } 101 | --------------------------------------------------------------------------------