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 constraint for layout_left|right|stride::stride(), and add test #238

Merged
merged 6 commits into from
Feb 24, 2023

Conversation

youyu3
Copy link
Contributor

@youyu3 youyu3 commented Feb 3, 2023

Addresses #201.
Had to update a few existing tests to get them to pass.

Copy link
Member

@crtrott crtrott left a comment

Choose a reason for hiding this comment

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

I don't really like introducing template parameters there. How about we just implement the constraint for C++20 and above, and then have the if constexpr condition and the specific test for availability protected also for C++20. Then note in the README that this constraint is not implemented in C++17/14.

for(size_t r=0; r != this->exts1.rank(); ++r) {
ASSERT_EQ(map1.extents().extent(r), map2.extents().extent(r));
ASSERT_EQ(map1.stride(r), map2.stride(r));
if constexpr (TestFixture::exts_1_t::rank() > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

We still test this with C++14

Copy link
Member

Choose a reason for hiding this comment

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

Given my other comment, I would just protect the condition with whether C++20 is on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works for me. Will update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. May not be the best-looking #ifs...

Copy link
Contributor

Choose a reason for hiding this comment

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

This code should be fine even if MDSPAN_HAS_CXX_20 defined, because the constraint on stride(r) won't come into play, no? I'd rather have fewer macros if we can avoid it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check is for the case when exts_1_t::rank() == 0 in the C++20 mode, in which case we have the constraint and it'll result in a compilation error without the if constexpr.
Well, that being said, I think we should only protect the line that calls stride(). I'll fix that.

@@ -176,6 +176,12 @@ class layout_left::mapping {
MDSPAN_INLINE_FUNCTION constexpr bool is_exhaustive() const noexcept { return true; }
MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { return true; }

MDSPAN_TEMPLATE_REQUIRES(
Copy link
Member

Choose a reason for hiding this comment

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

I don't like introducing a template parameter here for C++17/14. I would say we just do this only for C++20 using a requires clause on a non-templated function, and note down in the readme that this constraint is not implemented pre-c++20,

@@ -143,15 +143,21 @@ void check_correctness(MDA& m, size_t rank, size_t rank_dynamic,
ASSERT_EQ(m.rank_dynamic(), rank_dynamic);
if(rank>0) {
ASSERT_EQ(m.extent(0), extent_0);
ASSERT_EQ(m.stride(0), stride_0);
if constexpr (MDA::extents_type::rank()>0) {
Copy link
Member

Choose a reason for hiding this comment

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

same as above.

Copy link
Contributor

@mhoemmen mhoemmen left a comment

Choose a reason for hiding this comment

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

I made a note in one place where I think an #if ... #endif could be removed. Thanks!

for(size_t r=0; r != this->exts1.rank(); ++r) {
ASSERT_EQ(map1.extents().extent(r), map2.extents().extent(r));
ASSERT_EQ(map1.stride(r), map2.stride(r));
if constexpr (TestFixture::exts_1_t::rank() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This code should be fine even if MDSPAN_HAS_CXX_20 defined, because the constraint on stride(r) won't come into play, no? I'd rather have fewer macros if we can avoid it.

Copy link
Member

@crtrott crtrott left a comment

Choose a reason for hiding this comment

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

Just one small cleanup in the mdarray test, after that this is good.

@@ -143,15 +143,33 @@ void check_correctness(MDA& m, size_t rank, size_t rank_dynamic,
ASSERT_EQ(m.rank_dynamic(), rank_dynamic);
if(rank>0) {
ASSERT_EQ(m.extent(0), extent_0);
ASSERT_EQ(m.stride(0), stride_0);
#if MDSPAN_HAS_CXX_20
Copy link
Member

Choose a reason for hiding this comment

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

can't we just move that above 144. After all runtime wise these checks anyway only execute if rank>0 and we don't need to check that it compiles, there are other tests which do taht.

Copy link
Member

Choose a reason for hiding this comment

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

And I mean with that we only need one big constexpr if protection for all runtime check rank clauses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. Updated.

@crtrott crtrott merged commit cf374bc into kokkos:stable Feb 24, 2023
mhoemmen added a commit to mhoemmen/mdspan that referenced this pull request Jul 26, 2023
Adopt post-mdspan-0.3.0 and implement P1673R9 fully
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.

3 participants