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 assertion in adjacent_difference #10

Draft
wants to merge 135 commits into
base: develop
Choose a base branch
from

Conversation

yasahi-hpc
Copy link
Member

Fixes kokkos#6890

This PR aims at adding assertions if adjacent_difference works on the identical source and destination views.
For this purpose, I added

  1. New KOKKOS_EXPECT to make sure that source and destination views are not the same (expect_not_identical)
  2. Add these assertions in adjacent_difference with Execution space
  3. Added death tests in debug mode

When it comes to the team level, it is more complicated. Equality for different views may be satisfied on subviews having the extent of size 0 in some direction. This is happening in the test. I am not quite sure what is the correct way to avoid this situation.

Co-authored-by: Damien L-G <dalg24@gmail.com>
@yasahi-hpc yasahi-hpc self-assigned this Mar 27, 2024
@yasahi-hpc yasahi-hpc marked this pull request as draft March 27, 2024 15:23
@yasahi-hpc
Copy link
Member Author

I have updated based on the comments from core.

In the new version,

  1. New KOKKOS_EXPECT to make sure that source and destination views do not overlap
  2. Calling find_first_of to check if there is an overlap
  3. Death tests in debug mode excluded since it throws not aborts

Comment on lines 85 to 92
#if !defined(NDEBUG) || defined(KOKKOS_ENFORCE_CONTRACTS) || \
defined(KOKKOS_ENABLE_DEBUG)
auto last_dest = first_dest + num_elements;
auto found_first = Kokkos::Experimental::find_first_of(ex, first_from, last_from, first_dest, last_dest);
KOKKOS_EXPECTS(found_first == last_from);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you could extract this to a Impl::expect_no_overlap similar to Impl::expect_valid_range, I guess it will be useful 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.

That makes sense. In the end, I will implement Impl::expect_no_overlap and find_first_overlap_of with tests.

#if !defined(NDEBUG) || defined(KOKKOS_ENFORCE_CONTRACTS) || \
defined(KOKKOS_ENABLE_DEBUG)
auto last_dest = first_dest + num_elements;
auto found_first = Kokkos::Experimental::find_first_of(ex, first_from, last_from, first_dest, last_dest);
Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid find_first_of compares the content, not the adresses, I would check that if the iterators are compatble (i.e. is_valid_range(first_from, first_dest)), then either first_dest>last_from or first_dest+last_from-first_from<first_from

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 is true. I may need find_first_overlap_of to compare iterators.

@jbigot
Copy link
Member

jbigot commented Apr 3, 2024

From my point of view, this is first a documentation issue, is the doc clear about the precondition? If so, the check in code is a nice thing to have, but not a requirement.

@yasahi-hpc
Copy link
Member Author

From my point of view, this is first a documentation issue, is the doc clear about the precondition? If so, the check in code is a nice thing to have, but not a requirement.

I will implement as requested. At least, it would be a good practice

@yasahi-hpc
Copy link
Member Author

yasahi-hpc commented Apr 5, 2024

I have updated based on the comments from core.

In the new version,

  1. New KOKKOS_EXPECT to make sure that source and destination views do not overlap
  2. Tests are performed only if iterators are construbile from other iterator.

Still the issue with death tests, if we add that I got the following failure.
Here is the DEATH tests.

  #if !defined(NDEBUG) || defined(KOKKOS_ENFORCE_CONTRACTS) || \
    defined(KOKKOS_ENABLE_DEBUG)
  {
    auto view_dest = view_from;
    EXPECT_DEATH(
      {KE::adjacent_difference(exespace(), view_from,
                               view_dest, args...);
       Kokkos::fence();
      },
      "Kokkos contract violation:.*");
  }
  {
    auto view_dest = view_from;
    EXPECT_DEATH(
      {KE::adjacent_difference("label", exespace(), view_from,
                               view_dest, args...);
       Kokkos::fence();
      },
      "Kokkos contract violation:.*");
  }
  Kokkos::fence();
  #endif

Errors

[WARNING] /gpfs/users/asahiy/work/Kokkos/kokkos/tpls/gtest/gtest/gtest-all.cc:9326:: Death tests use fork(), which is unsafe particularly in a threaded context. For this test, Google Test detected 3 threads. See https://github.com/google/googletest/blob/master/docs/advanced.md#death-tests-and-threads for more explanation and suggested solutions, especially if this is the last message you see before your test times out.
/gpfs/users/asahiy/work/Kokkos/kokkos/algorithms/unit_tests/TestStdAlgorithmsAdjacentDifference.cpp:252: Failure
Death test: {KE::adjacent_difference("label", exespace(), view_from, view_dest, args...); Kokkos::fence(); }
    Result: threw an exception.
 Error msg:
[  DEATH   ] 
[  DEATH   ] /gpfs/users/asahiy/work/Kokkos/kokkos/algorithms/unit_tests/TestStdAlgorithmsAdjacentDifference.cpp:252:: Caught std::exception-derived exception escaping the death test statement. Exception message: cudaSetDevice(m_cudaDev) error( cudaErrorInitializationError): initialization error /gpfs/users/asahiy/work/Kokkos/kokkos/core/src/Cuda/Kokkos_Cuda_Instance.hpp:187
[  DEATH   ] 

IteratorType1 last,
IteratorType2 s_first,
IteratorType2 s_last) {
if constexpr( std::is_constructible_v<IteratorType2, IteratorType1> ) {
Copy link
Member

Choose a reason for hiding this comment

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

you can maybe add a else if constexpr that checks the opposite case that

Copy link
Member Author

@yasahi-hpc yasahi-hpc Apr 5, 2024

Choose a reason for hiding this comment

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

Do you mean that
there is a case that
std::is_constructible_v<IteratorType2, IteratorType1> is false but std::is_constructible_v<IteratorType1, IteratorType2> is true?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, while you can get a const iterator from a non const one, the opposite is not possible

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. I will add that.

Copy link
Member

@jbigot jbigot left a comment

Choose a reason for hiding this comment

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

looks great to me

@yasahi-hpc
Copy link
Member Author

Thanks!

@yasahi-hpc yasahi-hpc closed this Apr 5, 2024
@yasahi-hpc yasahi-hpc reopened this Apr 5, 2024
dalg24 and others added 16 commits April 11, 2024 17:41
…xy_template_param

Deprecate trailing `Proxy` template argument in `Kokkos::Array`
Reported in kokkos#6934 (review)

Co-authored-by: Nevin Liber <nliber@anl.gov>
…de_in_kokkos_array

Remove unnecessary `<limits>` header include in `<Kokkos_Array.hpp>`
…#6929)

* Adding converting constructor in Kokkos::RandomAccessIterator

* fix constructible tests for Kokkos::RandomAccessIterator

* fix converting constructor in Kokkos::RandomAccessIterator

* Add comments to explain friend class of RandomAccessIterator is needed for converting constructor

* Introduce KOKKOS_IMPL_CONDITIONAL_EXPLICIT macro from kokkos#6830

* Adding a conditional explicit in converting constructor of RandomAccessIterator

* Rename ViewType to OtherViewType in converting constructor for readability

* Replace tests with static_assert if they rely on compile time behaviour only

* fix a condition for conditional explicit

* Revert "Introduce KOKKOS_IMPL_CONDITIONAL_EXPLICIT macro from kokkos#6830"

This reverts commit ee42c6d.

* On second thought `KOKKOS_IMPL_CONDITIONAL_EXPLICIT` is not such a good idea

because it let user write code that would compile with C++17 but not
with later standards.

---------

Co-authored-by: Yuuichi Asahi <yuuichi.asahi@cea.fr>
…ssion

Temporary fix for our nightly builds so we can make decision on minimum
CXX20 compiler requirements when we see fit.
Specializing the swap algorithm for Kokkos arrays was initially proposed
in kokkos#6697 but we dropped it to focus on the Kokkos swap ADL ordeal.
Somehow we overlooked a stray <Kokkos_Swap.hpp> header include in the
Kokkos::Array header file.  This PR reintroduce a
`Kokkos::kokkos_swap(Kokkos::Array)` specialization, following closely
what the standard library does for `std::swap(std::array)`.
This specialization is not documented, does not follow the standard
library, it is not tested and has no known usage in Trilinos.
`Kokkos::pair`, as we generally describe it, was intended as a drop-in
replacement for `std::pair`.  Hence, obscure departure from the standard
implementation do not look like a good idea.
This PR suggest to deprecate that `T2=void` specialization for
degenerate pair that only hold one element.
…es_expression

Prefer standard C++ feature testing to guard the C++20 requires expression
* Fix deprecated warning from Kokkos::Array specialization

The warnings come from the template arguments in deprecated specialization
`Kokkos::Array<>::{contiguous,strided}` which refer to `Kokkos::Array<>`
that is marked as deprecated.

Minimal reproducer [here](https://godbolt.org/z/s18Txa5P6).  GCC9 eats
it but GCC10 onwards raise a warning.

I propose the easy way out, that is we drop the `[[deprecated]]`
attribute on `Kokkos::Array<>`.  Let me know if you have a better idea.

Sample warning from ArborX nightlies for completeness:
```
In file included from /var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/KokkosExp_MDRangePolicy.hpp:29,
                 from /var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/Kokkos_Tuners.hpp:28,
                 from /var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/impl/Kokkos_Tools_Generic.hpp:26,
                 from /var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/Kokkos_Parallel.hpp:34,
                 from /var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/Kokkos_MemoryPool.hpp:26,
                 from /var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/Kokkos_TaskScheduler.hpp:34,
                 from /var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/Serial/Kokkos_Serial.hpp:37,
                 from /var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/decl/Kokkos_Declare_SERIAL.hpp:21,
                 from /var/jenkins/workspace/ArborX_nightly/build-kokkos/KokkosCore_Config_DeclareBackend.hpp:22,
                 from /var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/Kokkos_Core.hpp:45,
                 from /var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/impl/Kokkos_Core.cpp:21:
/var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/Kokkos_Array.hpp:197:66: warning: 'Array' is deprecated [-Wdeprecated-declarations]
  197 | struct KOKKOS_DEPRECATED Array<T, KOKKOS_INVALID_INDEX, Array<>::contiguous> {
      |                                                                  ^~~~~~~~~~
/var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/Kokkos_Array.hpp:191:26: note: declared here
  191 | struct KOKKOS_DEPRECATED Array<void, KOKKOS_INVALID_INDEX, void> {
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/Kokkos_Array.hpp:265:66: warning: 'Array' is deprecated [-Wdeprecated-declarations]
  265 | struct KOKKOS_DEPRECATED Array<T, KOKKOS_INVALID_INDEX, Array<>::strided> {
      |                                                                  ^~~~~~~
/var/jenkins/workspace/ArborX_nightly/source-kokkos/core/src/Kokkos_Array.hpp:191:26: note: declared here
  191 | struct KOKKOS_DEPRECATED Array<void, KOKKOS_INVALID_INDEX, void> {
      |
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

* Revert "Fix deprecated warning from Kokkos::Array specialization"

This reverts commit 38db1ca.

* Let Array<>::{contiguous,strided} be aliases to Impl:: tag classes

Better approach to suppress the GCC deprecation warning suggested by
Thomas on Slack.

Co-Authored-By: Thomas Padioleau <thomas.padioleau@cea.fr>

---------

Co-authored-by: Thomas Padioleau <thomas.padioleau@cea.fr>
…_specialization

Deprecate specialization of `Kokkos::pair` for a single element
Fixed the CHANGELOG link for PR6601 (Threads backend change)
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.

adjacent_difference should not allow running with source being the same as destination