-
-
Notifications
You must be signed in to change notification settings - Fork 427
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
Make internal algorithms functions const #4808
Make internal algorithms functions const #4808
Conversation
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.
I would like to try and not make the members mutable (if you haven't tried that) to see what actually breaks. I think the main reason for not making those const in the first place was that the user supplied function objects might be mutable themselves.
Yep, I'll have a closer look at what exactly needs to be non-const. The user-supplied functions will be a problem in the end though. I'd imagine we don't actually want to require them to be const? |
Those are specifically allowed to be non-const, think of a function object that counts odd numbers using a for_each for instance... |
Yep, that's that I thought. |
Kokkos expects functions in parallel regions to be const. This satisfies Kokkos' requirements when calling HPX's algorithm functions in Kokkos parallel regions.
eb54e1b
to
21ee2dd
Compare
@hkaiser here's a log of building hpx/libs/algorithms/tests/unit/algorithms/transform_tests.hpp Lines 21 to 37 in a98d61f
@G-071 this branch is what you need right now as a workaround to have the Kokkos executors work with parallel algorithms. |
@msimberg let's specialize the algorithms for Kokkos, I think this will result in the cleanest solution. |
HPX parallel algorithms wrap element-wise functions into bigger functions that operate on chunks. These functions are non-const. In the Kokkos executors I invoke those wrapping functions inside a Kokkos parallel region, and Kokkos expects element-wise functions to be const. This is a workaround that marks HPX functions like
operator()
forfor_loop_iteration
as const, and its members as mutable. As far as I can tell we can't make them properly const because of requirements in HPX itself, but I may be wrong here. Also as far as I can tell we don't really violate anything fundamental in Kokkos by doing this. Kokkos mostly requires functions to be const to discourage modifying e.g. members in a parallel region since that can be difficult to get right. Of course, this does feel very wrong, so I'm opening this up to see if someone would have suggestions on how to avoid this.Note: I've only done this for
for_loop
,for_each
, andtransform
as those are the only parallel algorithms that currently work with the Kokkos executors. Others will need specialization instead of going through our parallel algorithm machinery.