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

Add support for View::rank[_dynamic]() #5870

Merged
merged 10 commits into from
Feb 22, 2023

Conversation

dalg24
Copy link
Member

@dalg24 dalg24 commented Feb 9, 2023

Related to #5717

Not sure it is worth the trouble. Opening so we can discuss. We agreed to move forward at the dev meeting.

View member Before this PR After this PR
View::Rank implementation-defined integral type deprecated
View::rank implementation-defined integral type unspecified type that is convertible to size_t
View::rank() not provided returns size_t
View::rank_dynamic implementation-defined integral type unspecified type that is convertible to size_t
View::rank_dynamic() not provided returns size_t

Two things worth noting:

  • One advantage of the View::rank() member over the rank(View) free function is that it can be used in constant expressions.
  • The actual type of View::rank as it was defined before was left up to the implementation (up to the compiler not to Kokkos) but in practice it was often int which means this change may yield warnings about comparing signed and unsigned integral types. It may also break code that was using the type of View::rank. The rational for choosing size_t was to align with std::mdspan.

@ldh4
Copy link
Contributor

ldh4 commented Feb 9, 2023

I agree with this change, keeping it consistent with ViewTraits, even though there seem to be handful of comparison of different integer signedness warnings to be handled.

We also happened to have called the struct that contains the iteration pattern Kokkos::Rank. So, renaming View::Rank to View::rank could help reducing potential source of that confusion, especially when used without fully qualified names.

@PhilMiller
Copy link
Contributor

Down the line, whatever we do with these interfaces ought to support code that's generic over both View and DynRankView (and maybe indicate DynamicView as rank 1, because that's how it would be accessed and copied)

@nmm0
Copy link
Contributor

nmm0 commented Feb 15, 2023

I added to the MDspan project since it's related (i.e. rank returning size_t)

using value_type = T;
using type = integral_constant<T, v>;
static constexpr T value = v;
KOKKOS_FUNCTION constexpr operator value_type() const noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're re-implementing it anyway because of the need for __host__ __device__ we could eventually deprecate this conversion if we wanted to make the view API more similar to mdspan.

That's assuming this utility class is not used elsewhere...

Copy link
Member Author

Choose a reason for hiding this comment

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

You read my mind

Copy link
Member Author

Choose a reason for hiding this comment

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

But not doing that for a while. We need to get users off of View::Rank first and we want to make it reasonably easy for them to support a range of Kokkos versions.

@dalg24 dalg24 changed the title Add support for View::rank[_dynamic]() and deprecate View::Rank Add support for View::rank[_dynamic]() Feb 16, 2023
Comment on lines +1639 to +1640
message += std::to_string(dst.extent(0));
for (size_t r = 1; r < dst_type::rank; r++) {
Copy link
Member Author

Choose a reason for hiding this comment

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

These changes are to avoid warning pointless comparison of unsigned integer with zero when the loop is from 0 to rank-1

@@ -814,14 +814,14 @@ class View : public ViewTraits<DataType, Properties...> {

template <typename... Is>
static KOKKOS_FUNCTION void check_access_member_function_valid_args(Is...) {
static_assert(traits::rank <= sizeof...(Is), "");
static_assert(rank <= sizeof...(Is), "");
Copy link
Member Author

Choose a reason for hiding this comment

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

traits::rank[_dynamic_rank] are still valid but it is cleaner without qualifying.

@@ -29,7 +29,7 @@ struct is_admissible_to_kokkos_std_algorithms : std::false_type {};

template <typename T>
struct is_admissible_to_kokkos_std_algorithms<
T, std::enable_if_t< ::Kokkos::is_view<T>::value && T::rank == 1 &&
T, std::enable_if_t< ::Kokkos::is_view<T>::value && T::rank() == 1 &&
Copy link
Member Author

Choose a reason for hiding this comment

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

MSVC was choking on that guy. Was giving failed static assertions all over the place in algorithms

@@ -1716,7 +1705,7 @@ struct RankDataType<ValueType, 0> {

template <unsigned N, typename... Args>
KOKKOS_FUNCTION std::enable_if_t<
N == View<Args...>::rank &&
N == View<Args...>::rank() &&
Copy link
Member Author

Choose a reason for hiding this comment

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

This change and the one below was for MSVC :(

dalg24 and others added 2 commits February 17, 2023 12:10
Co-Authored-By: Christian Trott <crtrott@sandia.gov>
@dalg24
Copy link
Member Author

dalg24 commented Feb 17, 2023

Retest this please

@dalg24 dalg24 marked this pull request as ready for review February 17, 2023 17:47
@dalg24
Copy link
Member Author

dalg24 commented Feb 19, 2023

Retest this please

@crtrott crtrott mentioned this pull request Feb 22, 2023
Copy link
Contributor

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

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

Looks OK to me.

@dalg24
Copy link
Member Author

dalg24 commented Feb 22, 2023

Ignoring HIP failure

@dalg24 dalg24 merged commit e146fc9 into kokkos:develop Feb 22, 2023
@dalg24 dalg24 deleted the view_rank_member_function branch February 22, 2023 17:15
@nmm0 nmm0 moved this from In progress to Done in Feature: MDSpan Mar 8, 2023
@dalg24 dalg24 mentioned this pull request Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants