Skip to content

Add compile-time tests for mdspan-style View template arguments with helper abstraction#27

Draft
Copilot wants to merge 4 commits intoview-with-mdspan-argumentsfrom
copilot/add-mdspan-style-template-tests
Draft

Add compile-time tests for mdspan-style View template arguments with helper abstraction#27
Copilot wants to merge 4 commits intoview-with-mdspan-argumentsfrom
copilot/add-mdspan-style-template-tests

Conversation

Copy link

Copilot AI commented Jan 31, 2026

Adds tests validating that Kokkos::View constructed with mdspan-style template arguments (scalar, extents, layout, accessor) produces identical mdspan_type as traditional Kokkos style (datatype, layout, space, memorytraits).

Changes

  • New test file: core/unit_test/view/TestViewMDSpanStyleTemplateArgs.cpp

    • 15 compile-time assertions covering 1D-6D arrays, LayoutLeft/Right, memory traits (Unmanaged, Atomic, RandomAccess, Restrict, combinations), const types, and different execution spaces
    • Uses Kokkos::Experimental::Accessor<ElementType, Space, MemoryTraits> to construct accessors
  • Helper abstraction (added in separate commit):

    • test_mdspan_view_equivalence<ElementType, Rank, Layout, Space, MemTraits>: constructs both View styles and compares their mdspan_type
    • rank_to_asterisks<Rank>: maps rank integer to pointer syntax (T*, T**, etc.)
    • layout_to_mdspan<Layout>: maps LayoutLeft/Right to layout_left/right_padded<dynamic_extent>

Example

Traditional verbose assertion (10 lines):

static_assert(
    std::is_same_v<
        Kokkos::View<double*, Kokkos::DefaultExecutionSpace>::mdspan_type,
        Kokkos::View<double, Kokkos::dextents<size_t, 1>,
                     Kokkos::Experimental::layout_right_padded<Kokkos::dynamic_extent>,
                     Kokkos::Experimental::Accessor<double, Kokkos::DefaultExecutionSpace,
                                                    Kokkos::MemoryTraits<>>>::mdspan_type>);

Refactored with helper (3 lines):

static_assert(
    test_mdspan_view_equivalence<double, 1, Kokkos::LayoutRight,
                                 Kokkos::DefaultExecutionSpace>::value);

File reduced from 197→174 lines (12% reduction) while maintaining identical test coverage.

Original prompt

We need to add tests for the use of mdspan style template arguments in Kokkos::View. I.e. using scalartype, extents, layout and accessor as template arguments instead of datatype, layout, space, and memorytraits. The initial test should be a compile only tests asserting that the mdspan_type of equivalent Views defined in the two styles is the same.

For this test leverage accessors defined via Kokkos::Experimental::Accessor<scalar_type, space, MemoryTraits<SomeTraits>> only. For quick compilation tests while you work on this, add the test initially to the core/unit_test/default/TestDefaultDeviceDevelop.cpp which can be build by building the target Kokkos_CoreUnitTest_Develop. Only move it to a new file in the core/unit_test/view directory when you are happy with it.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add tests for mdspan style template arguments in Kokkos::View Add compile-time tests for mdspan-style View template arguments Jan 31, 2026
Copilot AI requested a review from crtrott January 31, 2026 17:47
Copilot AI changed the title Add compile-time tests for mdspan-style View template arguments Add compile-time tests for mdspan-style View template arguments with helper abstraction Jan 31, 2026
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

Comments