-
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
Backport bit manipulation facility from C++20 standard library header <bit>
#4577
Conversation
7cf153a
to
747071f
Compare
4d4be48
to
e914ebf
Compare
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.
The PR generally looks good, and there's no reason to think it shouldn't be merged. But I do have a basic question (perhaps I should know the answer, but I don't), why does Kokkos need to manipulate at the bit level? To deal with various proclivities and folkways of different compilers and backends?
This is part of a broader theme of Kokkos broadly mimicking C++ standard library functionality with |
|
||
namespace Kokkos::Impl { | ||
|
||
#if defined(KOKKOS_COMPILER_CLANG) || defined(KOKKOS_COMPILER_GCC) |
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.
IntelLLVM
would probably also define it.
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'd prefer fiddling with more compiler and other intrinsics later.
countl_zero(T x) noexcept { | ||
using ::Kokkos::Experimental::digits_v; | ||
if (x == 0) return digits_v<T>; | ||
// TODO use compiler intrinsics when available |
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.
// TODO use compiler intrinsics when available | |
// TODO use constexpr compiler intrinsics when available |
We already have a much of places where we would use these functions in the library. |
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.
(I figured out the failure with NVCC. It was a few stray constexpr qualifiers on builtin device side function templates.) |
Retest this please |
1 similar comment
Retest this please |
320378a
to
9823ec8
Compare
} | ||
|
||
TEST(TEST_CATEGORY, bit_manip_countr_zero) { | ||
test_bit_manip_countr_zero<unsigned char>(); |
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.
There is an issue with SYCL
4: value at 1 which is 248 was expected to be 0
4: value at 2 which is 249 was expected to be 1
4: value at 3 which is 248 was expected to be 0
4: value at 4 which is 250 was expected to be 2
4: value at 5 which is 248 was expected to be 0
4: value at 6 which is 249 was expected to be 1
4: value at 7 which is 248 was expected to be 0
4: value at 8 which is 251 was expected to be 3
4: value at 9 which is 248 was expected to be 0
4: value at 7e which is 249 was expected to be 1
4: value at 7f which is 248 was expected to be 0
4: value at 80 which is 255 was expected to be 7
4: value at 81 which is 248 was expected to be 0
4: value at 82 which is 249 was expected to be 1
4: value at 7f which is 248 was expected to be 0
4: /var/jenkins/workspace/Kokkos/core/unit_test/TestBitManipulationBuiltins.hpp:67: Failure
4: Expected equality of these values:
4: errors
4: Which is: 15
4: 0
4: Failed check no error for countr_zero(unsigned char)
4: [ FAILED ] sycl.bit_manip_countr_zero (9 ms)
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.
Daniel reported it works on Intel GPUs. I disabled on NVIDIA.
} | ||
|
||
TEST(TEST_CATEGORY, bit_manip_countr_one) { | ||
test_bit_manip_countr_one<unsigned char>(); |
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.
4: [ RUN ] sycl.bit_manip_countr_one
4: value at 0 which is 248 was expected to be 0
4: value at 1 which is 249 was expected to be 1
4: value at 2 which is 248 was expected to be 0
4: value at 3 which is 250 was expected to be 2
4: value at 4 which is 248 was expected to be 0
4: value at 5 which is 249 was expected to be 1
4: value at 6 which is 248 was expected to be 0
4: value at 7 which is 251 was expected to be 3
4: value at 8 which is 248 was expected to be 0
4: value at 9 which is 249 was expected to be 1
4: value at 7e which is 248 was expected to be 0
4: value at 7f which is 255 was expected to be 7
4: value at 80 which is 248 was expected to be 0
4: value at 7e which is 248 was expected to be 0
4: value at 7f which is 255 was expected to be 7
4: /var/jenkins/workspace/Kokkos/core/unit_test/TestBitManipulationBuiltins.hpp:67: Failure
4: Expected equality of these values:
4: errors
4: Which is: 15
4: 0
4: Failed check no error for countr_one(unsigned char)
SYCL build passed with the last commit. HIP failure is unrelated. |
static_assert(std::is_same_v<decltype(countl_zero_builtin(UInt())), int>); | ||
constexpr auto max = | ||
Kokkos::Experimental::finite_max_v<std::make_signed_t<UInt>>; | ||
// ^^^^^^^^^^^^^^^^^^ |
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.
Didn't mean to keep that change...
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 good to me, we just need to file an issue for the eventual merging of these paths
countl_zero(T x) noexcept { | ||
using ::Kokkos::Experimental::digits_v; | ||
if (x == 0) return digits_v<T>; | ||
// TODO use compiler intrinsics when available |
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.
We should file a new issue to avoid TODOs otherwise these will be forgotten, especially since we can't do this properly until C++20 support
countr_zero(T x) noexcept { | ||
using ::Kokkos::Experimental::digits_v; | ||
if (x == 0) return digits_v<T>; | ||
// TODO use compiler intrinsics when available |
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.
Same as above
Impl::is_standard_unsigned_integer_type_v<T>, int> | ||
popcount(T x) noexcept { | ||
if (x == 0) return 0; | ||
// TODO use compiler intrinsics when available |
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.
Same as above
I promised to myself that when I would review I would ask for docs/changelog entry. You already have the docs, so I guess we should add to the changelog of whatever this is targeting. |
Ignoring HIP failure |
Fix #3828See documentation in kokkos/kokkos-core-wiki#300
Deprecatedone in DeprecateKokkos::log2(unsigned) -> int
log2(unsigned) -> int
#4595Provide alternativewithdrawn (might come back with it in a follow up PR)Impl::bit_log2(UnsignedInteger) -> UnsignedInteger
for internal use onlyRemovewithdrawn (will propose in a follow up PR)Impl::bit_count(unsigned int)
in favor ofExperimental::popcount(UnsignedInteger) -> UnsignedInteger
NOTES
[bit.rot]
and I intend to removeImpl::rotate_right(unsigned, int) -> unsigned
in theBitset
implementation but I was planing to do that in a follow-up PR<impl/Kokkos_BitOps.hpp>
until we can get rid of the headerintegral_power_of_two*
facility inimpl/Kokkos_Traits.hpp
but I would rather deal with it laterExperimental::*_builtin
function templates. We can specialize further and add Intel intrinsics and such later.