This is the Kokkos Project's implementation of the ISO C++ mdspan feature with extensions for High Performance Computing (HPC) use cases.
The implementation underpins the primary data structures of the Kokkos Project and is used in production environments.
Kokkos MDSpan is part of the Kokkos C++ Performance Portability Programming Ecosystem.
Kokkos is a Linux Foundation project and a Core stage member of the LF's High Performance Software Foundation.
- Backport to C++14/17/20/23
- Not all features are supported in C++14
- Macros to enable, e.g.,
__device__marking of all functions for CUDA compatibility - Non-standard extensions for device code compatibility
The latest release of Kokkos's mdspan can be obtained from the GitHub releases page.
For questions find us on Slack: https://kokkos.org/community/chat/#slack or open a GitHub issue.
This implementation is fully conforming with the version of mdspan voted into the C++26 draft standard.
When not at least in C++23 mode the implementation deviates from the C++26 draft standard as follows:
- implements
operator()notoperator[]- you can control which operator is available by defining
MDSPAN_USE_BRACKET_OPERATOR=[0,1]andMDSPAN_USE_PAREN_OPERATOR=[0,1]irrespective of whether language support for multidimensionaloperator[]is detected.
- you can control which operator is available by defining
- mdspan has a default constructor even in cases where it shouldn't (i.e., all static extents, and default constructible mapping/accessor)
- the conditional explicit markup is missing, making certain constructors implicit
- most notably you can implicitly convert from dynamic extent to static extent, which you can't in C++20 mode
- there is a constraint on
layout_left::mapping::stride(),layout_right::mapping::stride()andlayout_stride::mapping::stride()thatextents_type::rank() > 0istrue, which is not implemented in C++17 or C++14.
- deduction guides don't exist
- submdspan (P2630) is not available - an earlier variant of submdspan is available up to release 0.5 in C++14 mode
layout_left_paddedandlayout_right_paddedare not available.- benchmarks are not available (they need submdspan)
This project is a CMake project.
cmake -B builddir [<options...>]
cmake --build builddir
cmake --install builddir [--prefix <prefix>]
mdspan specific options:
MDSPAN_ENABLE_TESTS: Enable tests. Default: OffMDSPAN_ENABLE_EXAMPLES: Build examples. Default: OffMDSPAN_ENABLE_BENCHMARKS: Enable benchmarks. Default: OffMDSPAN_ENABLE_COMP_BENCH: Enable compilation benchmarks. Default: OffMDSPAN_ENABLE_CUDA: Enable Cuda tests/benchmarks/examples if tests/benchmarks/examples are enabled. Default: OffMDSPAN_ENABLE_SYCL: Enable SYCL tests/benchmarks/examples if tests/benchmarks/examples are enabled. Default: OffMDSPAN_ENABLE_HIP: Enable HIP tests/benchmarks/examples if tests/benchmarks/examples are enabled. Default: OffMDSPAN_ENABLE_OPENMP: Enable OpenMP benchmarks if benchmarks are enabled. Default: On if and only if OpenMP is detectedMDSPAN_CXX_STANDARD: Set the C++ standard for compiling tests/benchmarks/examples. Default: Auto-DetectMDSPAN_USE_SYSTEM_GTEST: Use system-installed GoogleTest library for tests. Default: OffMDSPAN_USE_SYSTEM_BENCHMARK: Use system-installed Google Benchmark library for benchmarks. Default: On
Note: if you only install mdspan, the CUDA/SYCL/HIP/OPENMP options have no real effect. MDSpan is installed in a headers only fashion, and discovers use of CUDA, HIP, SYCL and OpenMP from compiler macros. Thus a single install of MDSpan can be used for all such downstream use cases.
Please see this page for details on how to contribute.
The full license statement used in all headers is available here.