-
Notifications
You must be signed in to change notification settings - Fork 407
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
Enable {transform_}exclusive_scan
in place
#6667
Conversation
Please include a code snippet that shows what usage this enables. |
The standard explicitly says that they may be equal. https://eel.is/c++draft/numeric.ops#exclusive.scan-8 Meaning if we don't currently support it, this can be considered as a defect report. |
From ArborX perspective, a simple example when we want to preallocate storage for queries for k-nearest neighbor kernels, where each predicate can be asking for a different number of neighbors: auto const n = queries.size();
Kokkos::View<int*, MemorySpace> offsets(Kokkos::view_alloc(
space, "offsets", Kokkos::WithoutInitializing), n + 1);
Kokkos::parallel_for("scan_queries",
Kokkos::RangePolicy<ExecutionSpace>(space, 0, n),
KOKKOS_LAMBDA(int i) { offsets(i) = queries(i).k; });
Kokkos::exclusive_scan(space, offsets, offsets); |
@fnrizzi What testing would you want to see here? |
The same page says the same holds true for the |
we can modify the existing test to ensure the source and dest are the same , and also fix the inclusive_scan accordingly. It is interesting that while the std draft explicitly has a remark about this, the std doc does not say anything. |
@fnrizzi please go ahead |
In the parameters description
|
Ah good eye, I totally missed it |
10c136c
to
2f079a7
Compare
exclusive_scan
in place
exclusive_scan
in place{transform_}exclusive_scan
in place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK to me.
@aprokop did you only do exclusive scan because that's all you needed or because inclusive scan does not have the defect? |
@dalg24 there is a PR I opened for it where I am adding the test. Inclusive scan works |
Cool. I was just checking https://godbolt.org/z/e4M4xnncY |
yes, seems to work, i still have to finalize PR will do that soon |
currently Kokkos
exclusive_scan
does not work for in-place operation.The c++ std says that exclusive_scan can support inplace, so this PR fixes the defect.
This PR fixes that and adds new tests.
While adding new tests, we also improve things to reduce duplication, use proper gtest << operator if needed, removing useless comments and adding new explanations.
use case
In ArborX, it is typical to do some some counting into a View, and then do a scan on that view to convert it to offsets. Creating a temporary extra view comes at the cost of additional memory and performance.
I don't think C++ standard says anything about whether it's allowable for
src
anddst
to be the same.