Enable CUDA compatibility and non-standard extensions
stable__device__ marking on functions. Additionally, you can invoke non-standard extension methods by passing Kokkos::mdspan_non_standard as the first argument to the relevant calls.repository·stable·Indexed 19 days ago
https://github.com/kokkos/mdspanA header-only implementation of the C++ mdspan proposal (P0009) for non-owning multi-dimensional array references. It provides backports for C++14 and C++17, conforms to the C++23 draft standard (July 2022), and includes extensions for device-side compatibility such as CUDA.
__device__ marking on functions. Additionally, you can invoke non-standard extension methods by passing Kokkos::mdspan_non_standard as the first argument to the relevant calls.The implementation is fully conforming to the C++23 draft standard (July 2022). When using older standards, there are specific behavioral differences:
operator() instead of operator[] (unless configured otherwise via macros).mdspan has a default constructor even when it should not (e.g., all static extents and default constructible mapping/accessor).explicit markup: certain constructors are implicit, such as implicit conversion from dynamic extent to static extent.stride() for layout_left, layout_right, and layout_stride mappings requiring extents_type::rank() > 0 are not implemented.submdspan (P2630) is not available (an earlier variant is available up to release 0.5).submdspan.While the library is header-only for usage, you must use CMake to build and run the included test suites or benchmarks. Below are the recommended CMake configurations for different environments.
### clang-15 / cmake 3.23
cmake -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_BENCHMARKS=ON -DCMAKE_CXX_FLAGS="-Werror -Wall -Wextra -pedantic" -DCMAKE_CXX_STANDARD=23 -DMDSPAN_CXX_STANDARD=23 -DCMAKE_CXX_COMPILER=clang++
### gcc-11 / cmake 3.23
cmake -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_BENCHMARKS=ON -DCMAKE_CXX_FLAGS="-Werror -Wall -Wextra -pedantic" -DCMAKE_CXX_STANDARD=17 -DMDSPAN_CXX_STANDARD=17 -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_EXTENSIONS=OFF
### CUDA 11.x / gcc 9.1 / cmake 3.23
cmake -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_CUDA=ON -DMDSPAN_ENABLE_BENCHMARKS=ON -DCMAKE_CXX_STANDARD=17 -DCMAKE_CUDA_ARCHITECTURES=70 -DMDSPAN_CXX_STANDARD=17 -DCMAKE_CUDA_FLAGS="--expt-relaxed-constexpr --extended-lambda"mdspan implementation is header-only. You do not need to build or install it to use it in your own code; simply include the headers in your project. The library uses feature test macros to detect available compiler features automatically.In C++20 mode, the implementation defaults to providing operator() instead of operator[]. You can manually control which operators are available by defining the following macros, regardless of whether the compiler detects multi-dimensional subscript support:
MDSPAN_USE_BRACKET_OPERATOR=[0,1]MDSPAN_USE_PAREN_OPERATOR=[0,1]