Skip to content

Add mdspan-style template parameter support for Kokkos::View#26

Draft
Copilot wants to merge 11 commits intodevelopfrom
copilot/overhaul-kokkos-view-template-params
Draft

Add mdspan-style template parameter support for Kokkos::View#26
Copilot wants to merge 11 commits intodevelopfrom
copilot/overhaul-kokkos-view-template-params

Conversation

Copy link

Copilot AI commented Jan 28, 2026

Enable Kokkos::View to accept mdspan-style template parameters (extents, layout_left/right, SpaceAwareAccessor) as an alternative to classical syntax (double**, LayoutLeft, CudaSpace), maintaining full backward compatibility.

Changes

  • Trait detection (Kokkos_Concepts.hpp): Added is_mdspan_extents_v, is_mdspan_layout_v, and is_mdspan_accessor_v to identify mdspan types

  • Type converters (Kokkos_ViewTraits.hpp):

    • ArrayLayoutFromMDSpanLayout: Maps layout_left/right/stride to LayoutLeft/Right/Stride
    • MemorySpaceFromAccessor: Extracts memory space from SpaceAwareAccessor
    • SafeDataTypeFromExtents: Converts element type + extents to data type specification
  • ViewTraits specializations: Added SFINAE specializations to process mdspan parameters alongside existing ArrayLayout/Space/MemoryTraits specializations

  • Primary template enhancement: Modified to detect mdspan parameters and convert them to canonical Kokkos types

Example

// Classical syntax (unchanged)
Kokkos::View<double**, Kokkos::LayoutLeft, Kokkos::CudaSpace> v1;

// New mdspan-style syntax (intended)
Kokkos::View<double, 
             Kokkos::dextents<size_t, 2>, 
             Kokkos::layout_left,
             Kokkos::Impl::SpaceAwareAccessor<Kokkos::CudaSpace, 
                                               Kokkos::default_accessor<double>>> v2;

Known Issue

SFINAE specialization conflict occurs when processing multiple mdspan types in sequence (e.g., ViewTraits<void, layout_left, SpaceAwareAccessor>). The recursive template instantiation doesn't match existing specializations correctly. Requires refactoring the specialization pattern to handle combined mdspan parameter cases.

Original prompt

I want to work on overhauling Kokkos::View to enable users to specify template parameters in the style of of mdspan or BasicView, while maintaining backward compatibility. E.g. I want both Kokkos::View<double, Kokkos::dextents<int, 2>, Kokkos::layout_left, Kokkos::SpaceAwareAccessor<Kokkos::CudaSpace, Kokkos::default_accessor<double>>> and the classical Kokkos::View<double**, Kokkos::LayoutLeft, Kokkos::CudaSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>> be valid ways to specify a Kokkos Views.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Overhaul Kokkos::View for template parameter specification Add mdspan-style template parameter support for Kokkos::View Jan 28, 2026
Copilot AI requested a review from crtrott January 28, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants