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
Add likely
and unlikely
attribute from C++20 to ref counting in views
#6730
base: develop
Are you sure you want to change the base?
Conversation
…NCH_UNLIKELY macro.
Thank you for adding this draft PR. Is there a reason for the specific KOKKOS_COMPILER_CLANG macro around the attribute? The likelihood attributes are legal C++20 and should be available in any compliant compiler, so the C++ version check should suffice. |
That's right. Fixed it. |
#if defined(KOKKOS_IMPL_REF_COUNT_BRANCH_LIKELY) | ||
#define KOKKOS_BRANCH_PROB [[likely]] | ||
#elif defined(KOKKOS_IMPL_REF_COUNT_BRANCH_UNLIKELY) | ||
#define KOKKOS_BRANCH_PROB [[unlikely]] |
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 also noticed that you need another else branch. This was not needed in the original code because it did not have a KOKKOS_ENABLE_CXX20
branch.
#else
#define KOKKOS_BRANCH_PROB
#define KOKKOS_BRANCH_PROB [[unlikely]] | ||
#endif | ||
#else | ||
#define KOKKOS_BRANCH_PROB |
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 do have an else
here. Do you mean something else @cdaley ?
core/src/impl/Kokkos_SharedAlloc.hpp
Outdated
#if defined(KOKKOS_ENABLE_CXX20) | ||
#if defined(KOKKOS_IMPL_REF_COUNT_BRANCH_LIKELY) | ||
#define KOKKOS_BRANCH_PROB [[likely]] | ||
#elif defined(KOKKOS_IMPL_REF_COUNT_BRANCH_UNLIKELY) | ||
#define KOKKOS_BRANCH_PROB [[unlikely]] | ||
#endif | ||
#endif |
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.
Is there any reason why not just do this:
#if defined(KOKKOS_ENABLE_CXX20) | |
#if defined(KOKKOS_IMPL_REF_COUNT_BRANCH_LIKELY) | |
#define KOKKOS_BRANCH_PROB [[likely]] | |
#elif defined(KOKKOS_IMPL_REF_COUNT_BRANCH_UNLIKELY) | |
#define KOKKOS_BRANCH_PROB [[unlikely]] | |
#endif | |
#endif | |
#if defined(KOKKOS_ENABLE_CXX20) | |
#define KOKKOS_BRANCH_PROB [[unlikely]] | |
#endif |
Basically either we do it or we don't. We could have an IMPL option to turn it off in case we get complaints, but there is no reason for us to switch back and forth. This will just cause issues down the road. Right now by default this is not on ever. |
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 don't think we should do this this way. When we merge this by default the unlikely argument should be used. And MAYBE we have an impl option to turn it off. But if so there needs to be a cmake option.
Followed @crtrott suggestion. Using |
core/src/impl/Kokkos_SharedAlloc.hpp
Outdated
#if defined(KOKKOS_ENABLE_IMPL_REF_COUNT_BRANCH_LIKELY) && \ | ||
defined(KOKKOS_ENABLE_CXX20) | ||
#define KOKKOS_BRANCH_PROB [[likely]] | ||
#else | ||
#define KOKKOS_BRANCH_PROB [[unlikely]] | ||
#endif |
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.
This won't work. It should be
#if defined(KOKKOS_ENABLE_IMPL_REF_COUNT_BRANCH_LIKELY) && \ | |
defined(KOKKOS_ENABLE_CXX20) | |
#define KOKKOS_BRANCH_PROB [[likely]] | |
#else | |
#define KOKKOS_BRANCH_PROB [[unlikely]] | |
#endif | |
#if defined(KOKKOS_ENABLE_CXX20) | |
#define KOKKOS_BRANCH_PROB [[unlikely]] | |
#else | |
#define KOKKOS_BRANCH_PROB | |
#endif |
to conform to @crtrott's suggestion.
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.
So we don't need a user provided option where they can opt for [likely]
attribute?
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.
Right. We are only considering adding [[unlikely]]
.
CXX = clang++ | ||
EXE = copy_view_performance.exe | ||
|
||
CXXFLAGS ?= -Ofast -DKOKKOS_IMPL_REF_COUNT_BRANCH_UNLIKELY |
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.
This macro should now be "KOKKOS_ENABLE_IMPL_REF_COUNT_BRANCH_UNLIKELY" to be the same as the macro in core/src/impl/Kokkos_SharedAlloc.hpp
cmake/kokkos_enable_options.cmake
Outdated
@@ -48,6 +48,7 @@ KOKKOS_ENABLE_OPTION(CUDA_LAMBDA ${CUDA_LAMBDA_DEFAULT} "Whether to allow lambda | |||
# resolved but we keep the option around a bit longer to be safe. | |||
KOKKOS_ENABLE_OPTION(IMPL_CUDA_MALLOC_ASYNC ON "Whether to enable CudaMallocAsync (requires CUDA Toolkit 11.2)") | |||
KOKKOS_ENABLE_OPTION(IMPL_NVHPC_AS_DEVICE_COMPILER OFF "Whether to allow nvc++ as Cuda device compiler") | |||
KOKKOS_ENABLE_OPTION(IMPL_REF_COUNT_BRANCH_UNLIKELY ON "Turn on `likely` attribute from C++20 when reference counting view copies") |
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.
KOKKOS_ENABLE_OPTION(IMPL_REF_COUNT_BRANCH_UNLIKELY ON "Turn on `likely` attribute from C++20 when reference counting view copies") | |
KOKKOS_ENABLE_OPTION(IMPL_REF_COUNT_BRANCH_UNLIKELY ON "Turn on `unlikely` attribute from C++20 when reference counting view copies") |
core/src/impl/Kokkos_SharedAlloc.hpp
Outdated
@@ -24,6 +24,15 @@ | |||
#include <cstdint> | |||
#include <string> | |||
|
|||
// Use likely, unlikely attributes from C++20 to improve performance of |
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.
// Use likely, unlikely attributes from C++20 to improve performance of | |
// Use unlikely attribute from C++20 to improve performance of |
The PR is to address issue #6508.
The PR adds the following:
likely
andunlikely
attribute from C++20 for reference counting of views.