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 fallback implementation for sort_by_key #6856

Merged
merged 5 commits into from
Mar 5, 2024

Conversation

masterleinad
Copy link
Contributor

Alternative to #6849. For the fallback implementation of sort_by_key using Kokkos::sort, we need to know in advance if the sort executes on the same device or the host so we can copy the keys used in the comparator accordingly.
This pull request makes this decision explicitly and we only call sort on the device in cases where we are sure that it doesn't execute in the host. Note that this disregards runtime decisions like when using SYCL with LayoutStride and we just play it safe by executing on the host in this case. Making it a compile-time decision might improve compile-time and avoids dealing with SYCL device-copyable issues in both branches.

Comment on lines 93 to 94
template <class ExecutionSpace, class Layout>
struct sort_on_device : std::false_type {};
Copy link
Member

Choose a reason for hiding this comment

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

Why bother with the trait? It doesn't seem like you use it. You can directly specialize the variable template.

Comment on lines 90 to 91
// For the fallback sort_by_key implementation we might need to execute
// Kokkos::sort on the host. This type trait determines at compile-time where we
Copy link
Member

Choose a reason for hiding this comment

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

we might need to execute Kokkos::sort on the host

"We need to consider if Kokkos::sort defers to the fallback implementation that copies the array to the host and uses std::sort. The value is determined by the implementation choices in the impl/Kokkos_SortImpl.hpp which mean they need to be kept in sync (sigh...)"

algorithms/src/sorting/impl/Kokkos_SortByKeyImpl.hpp Outdated Show resolved Hide resolved
// For the fallback implementation for sort_by_key using Kokkos::sort, we need
// to consider if Kokkos::sort defers to the fallback implementation that copies
// the array to the host and uses std::sort. This decision is made in
// impl/Kokkos_SortImpl.hpp and this type trait decides at runtime when it is
Copy link
Member

Choose a reason for hiding this comment

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

this type trait decides at runtime when it is safe to assume that Kokkos::sort doesn't manually copy to the host

I don't understand this sentence. There is no more trait and the variable template does not "decide" anything. Do you mean it is used somewhere to determine what to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We manually copy all data to the host and provide sort with a host execution space if that variable is false. Otherwise, we assume that sort doesn't copy to the host and we don't need to copy anything manually.

Copy link
Member

Choose a reason for hiding this comment

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

Please improve/update the comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dalg24
Copy link
Member

dalg24 commented Mar 4, 2024

Retest this please

@masterleinad
Copy link
Contributor Author

masterleinad commented Mar 4, 2024

Only the CUDA-12.2-NVHPC build on fetnat05 and the OpenMPTarget build on fetnat04 failed due to disk space issues.

@dalg24
Copy link
Member

dalg24 commented Mar 5, 2024

Ignoring Disk quota exceeded errors in the OpenMPTarget and one of the CUDA builds.

@dalg24 dalg24 merged commit 9feb104 into kokkos:develop Mar 5, 2024
32 of 33 checks passed
pzehner pushed a commit to CExA-project/kokkos that referenced this pull request Mar 8, 2024
* Fix fallback implementation for sort_by_key

* Guard with KOKKOS_ENABLE_ONEDPL

* Drop sort_on_device

* Improve wording

* Improve comment
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

3 participants