Skip to content

Commit a336fb0

Browse files
committed
CHECKPOINT
submdspan builds now when submdspan_mapping is called with canonical slices, but the submdspan test fails. Investigate whether this is a bug in the implementation.
1 parent de58bc0 commit a336fb0

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

include/experimental/__p2630_bits/submdspan.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,16 @@ submdspan(const mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy> &src,
2828
SliceSpecifiers... slices) {
2929

3030
#if defined(MDSPAN_ENABLE_P3663)
31-
[[maybe_unused]] auto [...canonical_slices] = submdspan_canonicalize_slices(src.extents(), slices...);
31+
auto [...canonical_slices] = submdspan_canonicalize_slices(src.extents(), slices...);
3232
static_assert(sizeof...(canonical_slices) == sizeof...(slices));
33-
[[maybe_unused]] auto sub_map_result = submdspan_mapping(src.mapping(), canonical_slices...);
34-
35-
#if 0
3633
// TODO FIX IN PROPOSAL: [canonical_]slices (incorrect formatting).
3734
auto sub_map_result = submdspan_mapping(src.mapping(), canonical_slices...);
3835
// TODO FIX IN PROPOSAL: It's src.data_handle(), not src.data().
3936
// Missing "typename" before AccessorPolicy::offset_policy.
4037
return mdspan(src.accessor().offset(src.data_handle(), sub_map_result.offset),
4138
sub_map_result.mapping,
4239
typename AccessorPolicy::offset_policy(src.accessor()));
43-
#endif // 0
44-
#endif
45-
46-
//#else
40+
#else
4741
const auto sub_submdspan_mapping_result = submdspan_mapping(src.mapping(), slices...);
4842
// NVCC has a problem with the deduction so lets figure out the type
4943
using sub_mapping_t = std::remove_cv_t<decltype(sub_submdspan_mapping_result.mapping)>;
@@ -54,6 +48,6 @@ submdspan(const mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy> &src,
5448
src.accessor().offset(src.data_handle(), sub_submdspan_mapping_result.offset),
5549
sub_submdspan_mapping_result.mapping,
5650
sub_accessor_t(src.accessor()));
57-
//#endif
51+
#endif
5852
}
5953
} // namespace MDSPAN_IMPL_STANDARD_NAMESPACE

include/experimental/__p2630_bits/submdspan_mapping.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,35 @@ MDSPAN_INLINE_FUNCTION constexpr auto construct_sub_strides(
132132
static_cast<index_type>(get<InvMapIdxs>(slices_stride_factor)))...}};
133133
}
134134

135+
// NOTE Make the submdspan_mapping_impl functions recognize
136+
// strided_slice with compile-time stride 1 as a range slice.
137+
// Otherwise, they fall back to layout_stride::mapping.
138+
// This might be a bug in the pre-P3663 implementation.
139+
140+
#if defined(MDSPAN_ENABLE_P3663)
141+
142+
template<class SliceSpecifier, class IndexType>
143+
struct is_range_slice : std::false_type {};
144+
145+
template<class IndexType>
146+
struct is_range_slice<full_extent_t, IndexType> : std::true_type {};
147+
148+
template<class OffsetType, class ExtentType, auto Stride, class IndexType>
149+
struct is_range_slice<strided_slice<OffsetType, ExtentType, std::constant_wrapper<Stride>>, IndexType> {
150+
static constexpr bool value = (std::constant_wrapper<Stride>{}() == IndexType(1));
151+
};
152+
153+
#else
154+
135155
template<class SliceSpecifier, class IndexType>
136156
struct is_range_slice {
137157
constexpr static bool value =
138158
std::is_same_v<SliceSpecifier, full_extent_t> ||
139159
index_pair_like<SliceSpecifier, IndexType>::value;
140160
};
141161

162+
#endif // MDSPAN_ENABLE_P3663
163+
142164
template<class SliceSpecifier, class IndexType>
143165
constexpr bool is_range_slice_v = is_range_slice<SliceSpecifier, IndexType>::value;
144166

0 commit comments

Comments
 (0)