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

Remove use_annotated_operator #736

Merged
merged 1 commit into from
Jan 2, 2025
Merged

Conversation

tpadioleau
Copy link
Member

Reasons:

  • not used
  • std algorithms of Kokkos always annotate KOKKOS_FUNCTION the functors

@tpadioleau tpadioleau self-assigned this Jan 2, 2025
Copy link

@science-enthusiast science-enthusiast left a comment

Choose a reason for hiding this comment

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

I am not yet able to follow why use_annotated_operator was needed in the first place. But I have verified that these are the places in the code base where use_annotated_operator was appearing and I also follow how the modified code will look like when use_annotated_operator is removed.

@tpadioleau
Copy link
Member Author

tpadioleau commented Jan 2, 2025

I am not yet able to follow why use_annotated_operator was needed in the first place. But I have verified that these are the places in the code base where use_annotated_operator was appearing and I also follow how the modified code will look like when use_annotated_operator is removed.

If we take the following example in the context of Kokkos being compiled with the CUDA backend enabled:

ddc::parallell_for_each(Kokkos::DefaultHostExecutionSpace(), ddom, [&](DElem delem)
{
    // ...
});

There is a priori no need to use KOKKOS_LAMBDA because there will not be any CUDA kernel here. Internally we wrap the user lambda into an other functor that converts Kokkos integers into a ddc::DiscreteElement. Because of this wrapper, annotated with KOKKOS_FUNCTION, the compiler notices that the host-only lambda will be compiled in the context of a host and device function and emits a warning.

The use_annotated_operator was introduced to workaround this based on the value of the execution space passed of the first parameter.

We get rid of it because this is quite a corner case and most of the time we can always capture by copy. This also forces the user to get closer to a device compatible kernel.

@science-enthusiast
Copy link

science-enthusiast commented Jan 2, 2025

ddc::parallell_for_each(Kokkos::DefaultHostExecutionSpace(), ddom, [&](DElem delem)
{
    // ...
});

There is a priori no need to use KOKKOS_LAMBDA because there will not be any CUDA kernel here. Internally we wrap the user lambda into an other functor that converts Kokkos integers into a ddc::DiscreteElement. Because of this wrapper, annotated with KOKKOS_FUNCTION, the compiler notices that the host-only lambda will be compiled in the context of a host and device function and emits a warning.

Does this mean that use_annotated_operator was needed only for a capture by reference lambda executing in the host?

I don't understand why it is difficult to avoid compiling the lambda in the context of a host and device function, when Kokkos::DefaultHostExecutionSpace() is passed? Why can't it be compiled in the context of the host alone and the warning be avoided?

@tpadioleau
Copy link
Member Author

Does this mean that use_annotated_operator was needed only for a capture by reference lambda executing in the host?

Not exactly, it was needed if the user did not annotate the lambda __host__ __device__ to make it an extended lambda (it is CUDA vocabulary). Among all restrictions, extended lambdas cannot capture by reference, see point 12 in https://docs.nvidia.com/cuda/cuda-c-programming-guide/#extended-lambda-restrictions

I don't understand why it is difficult to avoid compiling the lambda in the context of a host and device function, when Kokkos::DefaultHostExecutionSpace() is passed? Why can't it be compiled in the context of the host alone and the warning be avoided?

DDC cannot know if the given functor/lambda is annotated or not, so we used to take the information from the Kokkos execution space.

@tpadioleau tpadioleau merged commit 9a715db into main Jan 2, 2025
55 checks passed
@tpadioleau tpadioleau deleted the remove-use_annotated_operator branch January 2, 2025 15:30
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.

2 participants