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

Fix static extents assignment for LayoutLeft/LayoutRight assignment #5535

Merged
merged 2 commits into from
Oct 10, 2022

Conversation

crtrott
Copy link
Member

@crtrott crtrott commented Oct 7, 2022

We always supported the following:

Kokkos::View<int[5]> a("A");
Kokkos::View<int[5]> b("A");
Kokkos::View<int*> c("C",5);
a = b;
b = a;
b = c;

We also supported for always:

Kokkos::View<int*,Kokkos::LayoutLeft> a("A",5);
Kokkos::View<int*,Kokkos::LayoutRight> b("B",5);
a = b;
b = a;

What apparently doesn't work is:

Kokkos::View<int[5],Kokkos::LayoutLeft> a("A");
Kokkos::View<int[5],Kokkos::LayoutRight> b("B");
a = b;
b = a;

Turns out we do some extra checks for dynamic rank match, when accounting for LayoutLeft/LayoutRight convertibility of Rank 0 and Rank 1 Views.
That check is unnecessary, since it will get checked via the dimension assignability check already.
I.e. we hadn't properly orthogonalized the extents assignability from the Layout assignability for mixing LayoutLeft/LayoutRight.

This fixes this by getting rid of the erroneous condition.

@crtrott
Copy link
Member Author

crtrott commented Oct 7, 2022

Note the proper dimension check happens around line 281 or so.

@crtrott
Copy link
Member Author

crtrott commented Oct 7, 2022

Fixes #5534 @lucbv

@@ -1128,9 +1128,8 @@ struct ViewOffset<
KOKKOS_INLINE_FUNCTION constexpr ViewOffset(
const ViewOffset<DimRHS, Kokkos::LayoutRight, void>& rhs)
: m_dim(rhs.m_dim.N0, 0, 0, 0, 0, 0, 0, 0) {
static_assert((DimRHS::rank == 0 && dimension_type::rank == 0) ||
(DimRHS::rank == 1 && dimension_type::rank == 1 &&
dimension_type::rank_dynamic == 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.

That line 1133 is the offending check.

@crtrott crtrott added Blocks Promotion Overview issue for release-blocking bugs Patch Release labels Oct 7, 2022
@crtrott
Copy link
Member Author

crtrott commented Oct 7, 2022

Note this behavior was always intended (as the fact that it works for matching layouts attest too) and this is also how mdspan works.

Copy link
Contributor

@lucbv lucbv left a comment

Choose a reason for hiding this comment

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

I talked this through with @crtrott and agree with the logic

Copy link
Member

@dalg24 dalg24 left a comment

Choose a reason for hiding this comment

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

The view assignable unit test could use some refactor (not requesting changes just saying)
Your changes should enable rank-0 view assignments as well isn't it? If I am not mistake please add tests for it.

Impl::TestAssignability<View<int[10], left, d_exec>,
View<int*, right, d_exec>>::test(false, true, 10);
Impl::TestAssignability<View<int*, left, d_exec>,
View<int[5], right, d_exec>>::test(true, true, 5);
Copy link
Member

Choose a reason for hiding this comment

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

Wait why do you pass 5? Isn't it something we only relaxed not so long ago? kokkos/kokkos-core-wiki#108
Please drop it here and below.

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 unnescessary here, gonna change that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also added the rank-0 mixed layout case.

Comment on lines +95 to +96
Impl::TestAssignability<View<int, left, d_exec>,
View<int, right, d_exec>>::test(true, true);
Copy link
Member

Choose a reason for hiding this comment

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

No right -> left?

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 guess we could add them everywhere, but mostly this is about mismatch, not any specific layouts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocks Promotion Overview issue for release-blocking bugs Patch Release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants