From 74a6944eeeb455330e70280dcd8e6353c55db497 Mon Sep 17 00:00:00 2001 From: Christian Trott Date: Tue, 24 Jan 2023 15:21:06 -0700 Subject: [PATCH 1/4] Rename strided_index_range.hpp to strided_slice.hpp --- .../__p2630_bits/{strided_index_range.hpp => strided_slice.hpp} | 0 include/experimental/__p2630_bits/submdspan_extents.hpp | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename include/experimental/__p2630_bits/{strided_index_range.hpp => strided_slice.hpp} (100%) diff --git a/include/experimental/__p2630_bits/strided_index_range.hpp b/include/experimental/__p2630_bits/strided_slice.hpp similarity index 100% rename from include/experimental/__p2630_bits/strided_index_range.hpp rename to include/experimental/__p2630_bits/strided_slice.hpp diff --git a/include/experimental/__p2630_bits/submdspan_extents.hpp b/include/experimental/__p2630_bits/submdspan_extents.hpp index c293b3fd..abc97f99 100644 --- a/include/experimental/__p2630_bits/submdspan_extents.hpp +++ b/include/experimental/__p2630_bits/submdspan_extents.hpp @@ -14,7 +14,7 @@ // //@HEADER -#include "strided_index_range.hpp" +#include "strided_slice.hpp" namespace std { namespace experimental { namespace detail { From b666a4cfce0682bc63ba9885b4cf055a1b5ebd25 Mon Sep 17 00:00:00 2001 From: Christian Trott Date: Tue, 24 Jan 2023 15:30:27 -0700 Subject: [PATCH 2/4] Rename strided_index_range to strided_slice --- .../__p2630_bits/strided_slice.hpp | 2 +- .../__p2630_bits/submdspan_extents.hpp | 22 +++++------ tests/test_submdspan.cpp | 38 +++++++++---------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/experimental/__p2630_bits/strided_slice.hpp b/include/experimental/__p2630_bits/strided_slice.hpp index 01af0b83..7933642d 100644 --- a/include/experimental/__p2630_bits/strided_slice.hpp +++ b/include/experimental/__p2630_bits/strided_slice.hpp @@ -20,7 +20,7 @@ namespace experimental { // Slice Specifier allowing for strides and compile time extent template -struct strided_index_range { +struct strided_slice { using offset_type = OffsetType; using extent_type = ExtentType; using stride_type = StrideType; diff --git a/include/experimental/__p2630_bits/submdspan_extents.hpp b/include/experimental/__p2630_bits/submdspan_extents.hpp index abc97f99..6f2c6a2e 100644 --- a/include/experimental/__p2630_bits/submdspan_extents.hpp +++ b/include/experimental/__p2630_bits/submdspan_extents.hpp @@ -42,12 +42,12 @@ constexpr auto inv_map_rank(integral_constant, index_sequence struct is_strided_index_range : false_type {}; +// Helper for identifying strided_slice +template struct is_strided_slice : false_type {}; template -struct is_strided_index_range< - strided_index_range> : true_type {}; +struct is_strided_slice< + strided_slice> : true_type {}; // first_of(slice): getting begin of slice specifier range MDSPAN_TEMPLATE_REQUIRES( @@ -77,7 +77,7 @@ constexpr auto first_of(const Slice &i) { template MDSPAN_INLINE_FUNCTION constexpr OffsetType -first_of(const strided_index_range &r) { +first_of(const strided_slice &r) { return r.offset; } @@ -155,7 +155,7 @@ template , const Extents &, - const strided_index_range &r) { + const strided_slice &r) { return r.extent; } @@ -169,7 +169,7 @@ constexpr auto stride_of(const T &) { template MDSPAN_INLINE_FUNCTION constexpr auto -stride_of(const strided_index_range &r) { +stride_of(const strided_slice &r) { return r.stride; } @@ -185,7 +185,7 @@ MDSPAN_INLINE_FUNCTION constexpr auto divide(const integral_constant &, const integral_constant &) { // cutting short division by zero - // this is used for strided_index_range with zero extent/stride + // this is used for strided_slice with zero extent/stride return integral_constant(); } @@ -214,7 +214,7 @@ struct StaticExtentFromRange, constexpr static size_t value = val1 - val0; }; -// compute new static extent from strided_index_range, preserving static +// compute new static extent from strided_slice, preserving static // knowledge template struct StaticExtentFromStridedRange { constexpr static size_t value = dynamic_extent; @@ -233,7 +233,7 @@ struct extents_constructor { MDSPAN_TEMPLATE_REQUIRES( class Slice, class... SlicesAndExtents, /* requires */(!is_convertible_v && - !is_strided_index_range::value) + !is_strided_slice::value) ) MDSPAN_INLINE_FUNCTION constexpr static auto next_extent(const Extents &ext, const Slice &sl, @@ -270,7 +270,7 @@ struct extents_constructor { MDSPAN_INLINE_FUNCTION constexpr static auto next_extent(const Extents &ext, - const strided_index_range &r, + const strided_slice &r, SlicesAndExtents... slices_and_extents) { using index_t = typename Extents::index_type; using new_static_extent_t = diff --git a/tests/test_submdspan.cpp b/tests/test_submdspan.cpp index 251b9219..b774449a 100644 --- a/tests/test_submdspan.cpp +++ b/tests/test_submdspan.cpp @@ -147,22 +147,22 @@ using submdspan_test_types = , std::tuple, args_t<6,4,5,6,7,8>, stdex::extents, int, int, int, int, std::pair, stdex::full_extent_t> , std::tuple, args_t<6,4,5,6,7,8>, stdex::extents, int, int, int, int, int, stdex::full_extent_t> // LayoutLeft to LayoutStride - , std::tuple, args_t<10>, stdex::dextents, stdex::strided_index_range> - , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_index_range, int> + , std::tuple, args_t<10>, stdex::dextents, stdex::strided_slice> + , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_slice, int> , std::tuple, args_t<10,20>, stdex::dextents, std::pair, stdex::full_extent_t> - , std::tuple, args_t<10,20>, stdex::dextents, std::pair, stdex::strided_index_range> - , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_index_range, std::pair> - , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_index_range, stdex::strided_index_range> + , std::tuple, args_t<10,20>, stdex::dextents, std::pair, stdex::strided_slice> + , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_slice, std::pair> + , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_slice, stdex::strided_slice> , std::tuple, args_t<6,4,5,6,7,8>, stdex::extents, stdex::full_extent_t, int, std::pair, int, int, stdex::full_extent_t> , std::tuple, args_t<6,4,5,6,7,8>, stdex::extents, int, stdex::full_extent_t, std::pair, int, stdex::full_extent_t, int> // layout_right to layout_stride - , std::tuple, args_t<10>, stdex::dextents, stdex::strided_index_range> - , std::tuple, args_t<10>, stdex::extents, stdex::strided_index_range,std::integral_constant>> - , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_index_range, int> + , std::tuple, args_t<10>, stdex::dextents, stdex::strided_slice> + , std::tuple, args_t<10>, stdex::extents, stdex::strided_slice,std::integral_constant>> + , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_slice, int> , std::tuple, args_t<10,20>, stdex::dextents, stdex::full_extent_t, std::pair> - , std::tuple, args_t<10,20>, stdex::dextents, std::pair, stdex::strided_index_range> - , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_index_range, std::pair> - , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_index_range, stdex::strided_index_range> + , std::tuple, args_t<10,20>, stdex::dextents, std::pair, stdex::strided_slice> + , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_slice, std::pair> + , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_slice, stdex::strided_slice> , std::tuple, args_t<6,4,5,6,7,8>, stdex::extents, stdex::full_extent_t, int, std::pair, int, int, stdex::full_extent_t> , std::tuple, args_t<6,4,5,6,7,8>, stdex::extents, int, stdex::full_extent_t, std::pair, int, stdex::full_extent_t, int> // Testing of customization point design @@ -172,8 +172,8 @@ using submdspan_test_types = , std::tuple, args_t<10,20>, stdex::dextents, stdex::full_extent_t, stdex::full_extent_t> , std::tuple, args_t<10,20>, stdex::dextents, std::pair, stdex::full_extent_t> , std::tuple, args_t<10,20>, stdex::dextents, int, stdex::full_extent_t> - , std::tuple, args_t<10>, stdex::dextents, stdex::strided_index_range> - , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_index_range, int> + , std::tuple, args_t<10>, stdex::dextents, stdex::strided_slice> + , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_slice, int> >; template struct TestSubMDSpan; @@ -204,13 +204,13 @@ struct TestSubMDSpan< return std::pair(1,3); } MDSPAN_INLINE_FUNCTION - static auto create_slice_arg(stdex::strided_index_range) { - return stdex::strided_index_range{1,3,2}; + static auto create_slice_arg(stdex::strided_slice) { + return stdex::strided_slice{1,3,2}; } template MDSPAN_INLINE_FUNCTION - static auto create_slice_arg(stdex::strided_index_range, std::integral_constant>) { - return stdex::strided_index_range, std::integral_constant>{1,std::integral_constant(), std::integral_constant()}; + static auto create_slice_arg(stdex::strided_slice, std::integral_constant>) { + return stdex::strided_slice, std::integral_constant>{1,std::integral_constant(), std::integral_constant()}; } MDSPAN_INLINE_FUNCTION static auto create_slice_arg(stdex::full_extent_t) { @@ -231,14 +231,14 @@ struct TestSubMDSpan< template MDSPAN_INLINE_FUNCTION static bool match_expected_extents(int src_idx, int sub_idx, SrcExtents src_ext, SubExtents sub_ext, - stdex::strided_index_range p, SliceArgs ... slices) { + stdex::strided_slice p, SliceArgs ... slices) { using idx_t = typename SubExtents::index_type; return (sub_ext.extent(sub_idx)==static_cast((p.extent+p.stride-1)/p.stride)) && match_expected_extents(++src_idx, ++sub_idx, src_ext, sub_ext, slices...); } template MDSPAN_INLINE_FUNCTION static bool match_expected_extents(int src_idx, int sub_idx, SrcExtents src_ext, SubExtents sub_ext, - stdex::strided_index_range,std::integral_constant>, SliceArgs ... slices) { + stdex::strided_slice,std::integral_constant>, SliceArgs ... slices) { return (sub_ext.extent(sub_idx)==0) && match_expected_extents(++src_idx, ++sub_idx, src_ext, sub_ext, slices...); } template From d89cb19efc1df33c22290daf992d673ff2884913 Mon Sep 17 00:00:00 2001 From: Christian Trott Date: Tue, 24 Jan 2023 15:42:19 -0700 Subject: [PATCH 3/4] Fix a nvhpc 22.3 build issue Its confusing extents<> with the function exetents() --- include/experimental/__p0009_bits/layout_stride.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/experimental/__p0009_bits/layout_stride.hpp b/include/experimental/__p0009_bits/layout_stride.hpp index 2dd7ec52..af3380c8 100644 --- a/include/experimental/__p0009_bits/layout_stride.hpp +++ b/include/experimental/__p0009_bits/layout_stride.hpp @@ -121,7 +121,7 @@ struct layout_stride { template _MDSPAN_HOST_DEVICE - constexpr index_type __get_size(extents,integer_sequence<::std::size_t, Idx...>) const { + constexpr index_type __get_size(::std::experimental::extents,integer_sequence<::std::size_t, Idx...>) const { return _MDSPAN_FOLD_TIMES_RIGHT( static_cast(extents().extent(Idx)), 1 ); } From 5702ddc1370e010bf0d4d1fb656586998ca9af31 Mon Sep 17 00:00:00 2001 From: Christian Trott Date: Tue, 24 Jan 2023 16:03:43 -0700 Subject: [PATCH 4/4] Add mandate check for strided_slice --- include/experimental/__p2630_bits/strided_slice.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/experimental/__p2630_bits/strided_slice.hpp b/include/experimental/__p2630_bits/strided_slice.hpp index 7933642d..f2f51bbc 100644 --- a/include/experimental/__p2630_bits/strided_slice.hpp +++ b/include/experimental/__p2630_bits/strided_slice.hpp @@ -15,9 +15,18 @@ // //@HEADER +#include + namespace std { namespace experimental { +namespace { + template + struct __mdspan_is_integral_constant: std::false_type {}; + + template + struct __mdspan_is_integral_constant>: std::true_type {}; +} // Slice Specifier allowing for strides and compile time extent template struct strided_slice { @@ -28,6 +37,10 @@ struct strided_slice { OffsetType offset; ExtentType extent; StrideType stride; + + static_assert(is_integral_v || __mdspan_is_integral_constant::value); + static_assert(is_integral_v || __mdspan_is_integral_constant::value); + static_assert(is_integral_v || __mdspan_is_integral_constant::value); }; } // experimental