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

Fixes for Kokkos::Array #6372

Merged
merged 11 commits into from
Sep 13, 2023
Merged

Fixes for Kokkos::Array #6372

merged 11 commits into from
Sep 13, 2023

Conversation

nliber
Copy link
Contributor

@nliber nliber commented Aug 23, 2023

(Part of issue #6355)

This P/R contains fixes for

Kokkos::Array<T, KOKKOS_INVALID_INDEX, Kokkos::Array<>::contiguous>::empty()
Kokkos::Array<T, KOKKOS_INVALID_INDEX, Kokkos::Array<>::strided>::empty()
Kokkos::Array<T, KOKKOS_INVALID_INDEX, Kokkos::Array<>::strided>::operator=(...)

As well as unit tests for the above and the rest of Kokkos::Array.

Added 2023-Aug-23:

Changed the return value for Kokkos::Array<T, 0>::data() from pointer(0) to nullptr. Technically this wasn't a bug, but it did trigger warnings under some builds.

@PhilMiller
Copy link
Contributor

Code looks fine, compilers are being silly about char subscripting and need to be addressed, though

@nliber
Copy link
Contributor Author

nliber commented Aug 23, 2023

Code looks fine, compilers are being silly about char subscripting and need to be addressed, though

@PhilMiller sigh. I had addressed that for clang, but not gcc. Anyway, fixed.

@PhilMiller
Copy link
Contributor

You've still got some CUDA and HIP build failures in Jenkins.

@nliber
Copy link
Contributor Author

nliber commented Aug 25, 2023

You've still got some CUDA and HIP build failures in Jenkins.

Testing fix now...

@PhilMiller
Copy link
Contributor

The OpenMPTarget failure is noise.

The CUDA-Clang failure seems to be from the compiler thinking that is_integral_v<__int128> == false! I think that's probably in line with the standard, but maybe requires changing the test.

Comment on lines 137 to 147
#if defined(__clang__)
if constexpr (std::is_integral_v<__int128>) {
auto i128 = static_cast<__int128>(index);
ASSERT_EQ(a[i128], a[index]);
ASSERT_EQ(ca[i128], a[index]);

auto u128 = static_cast<unsigned __int128>(index);
ASSERT_EQ(a[u128], a[index]);
ASSERT_EQ(ca[u128], a[index]);
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use or test __int128 anywhere else in Kokkos. Why do you care about it here?

Copy link
Contributor Author

@nliber nliber Aug 25, 2023

Choose a reason for hiding this comment

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

I was trying to have a complete set of is_integral tests, as that is what the functions are currently templated on. This is a publicly available class, so it should work with compilers that consider __int128 to be an integral type.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would just drop it. __int128 isn't portable anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@@ -199,7 +199,7 @@ struct Array<T, KOKKOS_INVALID_INDEX, Array<>::contiguous> {
using const_pointer = std::add_const_t<T>*;

KOKKOS_INLINE_FUNCTION constexpr size_type size() const { return m_size; }
KOKKOS_INLINE_FUNCTION constexpr bool empty() const { return 0 != m_size; }
KOKKOS_INLINE_FUNCTION constexpr bool empty() const { return 0 == m_size; }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that this didn't cause any problem elsewhere. Was it just never used or never tested before?

Copy link
Contributor Author

@nliber nliber Aug 25, 2023

Choose a reason for hiding this comment

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

Definitely never tested before. Calling empty() only makes sense in either generic code or with data structures whose size is determined at run time. The latter is only true for the Proxy partial specialisations of Kokkos::Array.

I suspect no one uses Kokkos::Array<T, KOKKOS_INVALID_INDEX, Proxy> directly. As I state in Issue #6355, it has very unusual semantics (unlike Kokkos::Array<T, N>) as it is non-owning with weird (and untested until now) semantics for assignment.

@nliber
Copy link
Contributor Author

nliber commented Aug 25, 2023

The OpenMPTarget failure is noise.

The CUDA-Clang failure seems to be from the compiler thinking that is_integral_v<__int128> == false! I think that's probably in line with the standard, but maybe requires changing the test.

Until now, I thought clang considered __int128 to be an integral type, while gcc does not. (I believe gcc is correct with regards to the standard.). It looks like that isn't true for the CUDA part of the build.

@nliber nliber force-pushed the arrayfixes branch 2 times, most recently from 0a13e4a to f957041 Compare August 30, 2023 22:40
Comment on lines 17 to 25
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wchar-subscripts"
#endif

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wchar-subscripts"
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Why do we bother with accesses with all integral types known to men?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to eventually change it to is_convertible_v<T, size_t> (which is closer to how std::array works). Because it has been around a long time, I don't feel comfortable making that change w/o a full set of tests to make sure nothing is missing or generates other warnings.

std::array just uses size_t. I'm assuming the is_integral was used in Array to eliminate compiler warnings that the implicit conversion sometimes generates.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could array_element_access test be wrapped into a type-parametrized test?
https://github.com/google/googletest/blob/main/docs/advanced.md#type-parameterized-tests

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I couldn't resist and tried to rewrite it on my own. Consider cz4rs@be291da, which would produce following test output:

Note: Google Test filter = *ArrayOpsTest*
[==========] Running 24 tests from 12 test suites.
[----------] Global test environment set-up.
[----------] 2 tests from serial/ArrayOpsTest/0, where TypeParam = signed char
[ RUN      ] serial/ArrayOpsTest/0.array_element_access
[       OK ] serial/ArrayOpsTest/0.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/0.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/0.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/0 (0 ms total)

[----------] 2 tests from serial/ArrayOpsTest/1, where TypeParam = unsigned char
[ RUN      ] serial/ArrayOpsTest/1.array_element_access
[       OK ] serial/ArrayOpsTest/1.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/1.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/1.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/1 (0 ms total)

[----------] 2 tests from serial/ArrayOpsTest/2, where TypeParam = short
[ RUN      ] serial/ArrayOpsTest/2.array_element_access
[       OK ] serial/ArrayOpsTest/2.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/2.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/2.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/2 (0 ms total)

[----------] 2 tests from serial/ArrayOpsTest/3, where TypeParam = unsigned short
[ RUN      ] serial/ArrayOpsTest/3.array_element_access
[       OK ] serial/ArrayOpsTest/3.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/3.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/3.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/3 (0 ms total)

[----------] 2 tests from serial/ArrayOpsTest/4, where TypeParam = int
[ RUN      ] serial/ArrayOpsTest/4.array_element_access
[       OK ] serial/ArrayOpsTest/4.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/4.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/4.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/4 (0 ms total)

[----------] 2 tests from serial/ArrayOpsTest/5, where TypeParam = unsigned int
[ RUN      ] serial/ArrayOpsTest/5.array_element_access
[       OK ] serial/ArrayOpsTest/5.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/5.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/5.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/5 (0 ms total)

[----------] 2 tests from serial/ArrayOpsTest/6, where TypeParam = long
[ RUN      ] serial/ArrayOpsTest/6.array_element_access
[       OK ] serial/ArrayOpsTest/6.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/6.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/6.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/6 (0 ms total)

[----------] 2 tests from serial/ArrayOpsTest/7, where TypeParam = unsigned long
[ RUN      ] serial/ArrayOpsTest/7.array_element_access
[       OK ] serial/ArrayOpsTest/7.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/7.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/7.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/7 (0 ms total)

[----------] 2 tests from serial/ArrayOpsTest/8, where TypeParam = long long
[ RUN      ] serial/ArrayOpsTest/8.array_element_access
[       OK ] serial/ArrayOpsTest/8.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/8.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/8.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/8 (0 ms total)

[----------] 2 tests from serial/ArrayOpsTest/9, where TypeParam = unsigned long long
[ RUN      ] serial/ArrayOpsTest/9.array_element_access
[       OK ] serial/ArrayOpsTest/9.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/9.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/9.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/9 (0 ms total)

[----------] 2 tests from serial/ArrayOpsTest/10, where TypeParam = (anonymous namespace)::Enum
[ RUN      ] serial/ArrayOpsTest/10.array_element_access
[       OK ] serial/ArrayOpsTest/10.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/10.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/10.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/10 (0 ms total)

[----------] 2 tests from serial/ArrayOpsTest/11, where TypeParam = (anonymous namespace)::EnumShort
[ RUN      ] serial/ArrayOpsTest/11.array_element_access
[       OK ] serial/ArrayOpsTest/11.array_element_access (0 ms)
[ RUN      ] serial/ArrayOpsTest/11.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/11.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/11 (0 ms total)

[----------] Global test environment tear-down
[==========] 24 tests from 12 test suites ran. (0 ms total)
[  PASSED  ] 24 tests.

Copy link
Contributor Author

@nliber nliber Sep 12, 2023

Choose a reason for hiding this comment

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

Interesting...

The error messages look fine as well (as they show what TypeParam is on the FAILED line:

[----------] 2 tests from serial/ArrayOpsTest/0, where TypeParam = signed char
[ RUN      ] serial/ArrayOpsTest/0.array_element_access
/Users/nliber/git/github.com/kokkos/kokkos-array/core/unit_test/TestArrayOps.hpp:48: Failure
Expected: (a[cast_index]) != (a[index]), actual: 5 vs 5
[  FAILED  ] serial/ArrayOpsTest/0.array_element_access, where TypeParam = signed char (0 ms)
[ RUN      ] serial/ArrayOpsTest/0.array_contiguous_element_access
[       OK ] serial/ArrayOpsTest/0.array_contiguous_element_access (0 ms)
[----------] 2 tests from serial/ArrayOpsTest/0 (0 ms total)

That was my concern with using C++ templates for these tests (if you don't get the template parameter name when the test fails, it is hard to track down what actually broke), but this looks fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, some of the GoogleTest macros involved with the type parameterized tests don't work across our compiler suite. Reverting...

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I've never tried to do full CI run :| In that case I think this test is good as it is.

Copy link
Contributor

@cz4rs cz4rs left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@dalg24
Copy link
Member

dalg24 commented Sep 13, 2023

Timeouts HIP builds and SYCL build

@dalg24
Copy link
Member

dalg24 commented Sep 13, 2023

Make sure you update the 4.2 changelog

@dalg24 dalg24 merged commit 615fc1a into kokkos:develop Sep 13, 2023
28 of 29 checks passed
@masterleinad masterleinad mentioned this pull request Sep 14, 2023
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.

None yet

6 participants