Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new submdspan implementation #223

Closed
wants to merge 14 commits into from

Conversation

crtrott
Copy link
Member

@crtrott crtrott commented Dec 29, 2022

This uses ADL customization point design.

It doesn't use the backward compatibility stuff yet to improve readability for an initial review, i.e. it will only work on host with C++20 and C++23.

It also doesn't implement yet correct stride calculation when using strided_index_range

Comment on lines 6 to 11
template <class ElementType, class Extents, class LayoutPolicy,
class AccessorPolicy, class... SliceSpecifiers>
constexpr auto
submdspan(const mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy> &src,
SliceSpecifiers... slices) {
const auto sub_map_offset = submdspan_mapping(src.mapping(), slices...);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider forwarding the slice specifiers, as in the code below? It shouldn't make a performance difference for the current slice specifiers (that are all structs of small value types anyway); it's more a specification question.

Suggested change
template <class ElementType, class Extents, class LayoutPolicy,
class AccessorPolicy, class... SliceSpecifiers>
constexpr auto
submdspan(const mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy> &src,
SliceSpecifiers... slices) {
const auto sub_map_offset = submdspan_mapping(src.mapping(), slices...);
template <class ElementType, class Extents, class LayoutPolicy,
class AccessorPolicy, class... SliceSpecifiers>
constexpr auto
submdspan(const mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy> &src,
SliceSpecifiers&&... slices) {
const auto sub_map_offset = submdspan_mapping(src.mapping(), forward<SliceSpecifiers>(slices)...);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could try

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried this I ran into some trouble with failing tests, i.e. some deduction went haywire, my guess is that all the internal logic also needs to account for && including all the helper functions for matching and counting etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for trying! I think it's OK to leave this alone for now. If LWG wants it we can investigate it then.

SliceSpecifiers...>::type;
};

// final specialziation containing the final index_sequence
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor spelling issue:

Suggested change
// final specialziation containing the final index_sequence
// final specialization containing the final index_sequence

Does "final specialization" mean "this is the end of the 'recursion' on inv_map_rank specializations"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the comment to express this better

Comment on lines 19 to 20
// InvMapRank is gonna be a index_sequence, which we build recursively
// to contain the mapped indicies.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// InvMapRank is gonna be a index_sequence, which we build recursively
// to contain the mapped indicies.
// InvMapRank is an index_sequence, which we build recursively
// to contain the mapped indices.

template <size_t Counter, class InvMapRank, class... SliceSpecifiers>
struct inv_map_rank;

// specialization reducing rank by one (i.e. integral slice specifier)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// specialization reducing rank by one (i.e. integral slice specifier)
// specialization reducing rank by one (i.e., integral slice specifier)

return r.offset;
}

// last_of(slice): getting end of slice sepcifier range
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// last_of(slice): getting end of slice sepcifier range
// last_of(slice): getting end of slice specifier range

requires(
!is_convertible_v<Slice, size_t> &&
!is_strided_index_range<Slice>::
value) constexpr static auto next_extent(const Extents &ext,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider reformatting to make this more consistent with the other overloads?

// Return type of submdspan_mapping overloads
//******************************************
template <class Mapping> struct mapping_offset {
Mapping map;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider calling this mapping instead of map, to avoid collision with std::map?

Suggested change
Mapping map;
Mapping mapping;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah should do this.

Comment on lines 33 to 44
struct preserve_layout_left_mapping<index_sequence<Idx...>, SubRank,
SliceSpecifiers...> {
constexpr static bool value =
(SubRank == 0) ||
((Idx < SubRank - 1
? is_same_v<SliceSpecifiers, full_extent_t>
: (Idx == SubRank - 1 ? is_same_v<SliceSpecifiers, full_extent_t> ||
is_convertible_v<SliceSpecifiers,
tuple<size_t, size_t>>
: true)) &&
...);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression for value is a bit hard to read, but it's also hard to simplify it, given that all the repeated bools in it (like is_same_v<SliceSpecifiers, full_extent_t>) depend on a pack. Rewriting them into tuples or arrays somehow makes it worse.

Would you consider changing the term

Idx == SubRank - 1 ? is_same_v<SliceSpecifiers, full_extent_t> ||
                                        is_convertible_v<SliceSpecifiers,
                                                         tuple<size_t, size_t>>
                                  : true)

into the following?

Idx != SubRank - 1 or
  is_same_v<SliceSpecifiers, full_extent_t> or
  is_convertible_v<SliceSpecifiers, tuple<size_t, size_t>>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah that is better :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually that expression is wrong ...
this thing will return true for integers and what not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I inserted a correct one which is more structured like this instead of nested ?: statements.

@crtrott crtrott closed this Jan 8, 2023
@crtrott crtrott deleted the new-submdspan branch February 1, 2023 03:47
mhoemmen pushed a commit to mhoemmen/mdspan that referenced this pull request Jul 26, 2023
mhoemmen added a commit to mhoemmen/mdspan that referenced this pull request Jul 26, 2023
…output-file

fix kokkos#223: cmake ambigous output file name
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