[libcu++] Implement P3104R6 Bit permutations - #10063
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughChangesAdds Bit operation utilities
Suggested reviewers: Comment |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 71b3dca6-5e9a-45ad-8e43-fd768a1f3e9a
📒 Files selected for processing (9)
libcudacxx/include/cuda/std/__bit/bit_compress.hlibcudacxx/include/cuda/std/__bit/bit_expand.hlibcudacxx/include/cuda/std/__bit/bit_repeat.hlibcudacxx/include/cuda/std/__bit/bit_reverse.hlibcudacxx/include/cuda/std/bitlibcudacxx/test/libcudacxx/std/numerics/bit/bit.count/bit_compress.pass.cpplibcudacxx/test/libcudacxx/std/numerics/bit/bit.count/bit_expand.pass.cpplibcudacxx/test/libcudacxx/std/numerics/bit/bit.count/bit_repeat.pass.cpplibcudacxx/test/libcudacxx/std/numerics/bit/bit.count/bit_reverse.pass.cpp
🚧 Files skipped from review as they are similar to previous changes (5)
- libcudacxx/include/cuda/std/__bit/bit_reverse.h
- libcudacxx/include/cuda/std/bit
- libcudacxx/include/cuda/std/__bit/bit_repeat.h
- libcudacxx/include/cuda/std/__bit/bit_expand.h
- libcudacxx/include/cuda/std/__bit/bit_compress.h
fbusato
left a comment
There was a problem hiding this comment.
looks good. Left a couple of minor issues
| #if _CCCL_HAS_INT128() | ||
| test<__uint128_t>(); | ||
| #endif // _CCCL_HAS_INT128() | ||
| return true; |
There was a problem hiding this comment.
note. Other bit operations also test for aliases. I think it makes more sense to only test for builtin types. Just a consistency note.
There was a problem hiding this comment.
Yeah, I know, but I don't see the motivation behind testing the same types, just as aliases, this should cover all cases
This comment has been minimized.
This comment has been minimized.
| const auto __n = ::cuda::std::countl_one(__mask_rev); | ||
|
|
||
| // Write __n consecutive bits. | ||
| const auto __segment = static_cast<_Tp>(__v & ::cuda::bitmask<_Tp>(0, __n)); |
There was a problem hiding this comment.
Do we really need a bitmask here, or can we do the simple shift?
There was a problem hiding this comment.
bitmask is more efficient on device, it produces a single BMSK instruction
| const auto __pattern = static_cast<_Tp>(__v & ::cuda::bitmask<_Tp>(0, __n)); | ||
| _Tp __ret = __pattern; | ||
| for (int __i = __n; __i < __width; __i += __n) | ||
| { | ||
| __ret <<= __n; | ||
| __ret |= __pattern; | ||
| } | ||
| return __ret; | ||
| } |
There was a problem hiding this comment.
Question: I am slightly worried about smaller than int sized integers. Wouldnt it be more efficient to promote to 32 bit and then cast back?
The masked bit operations are probably not efficient
There was a problem hiding this comment.
Probably? I wanted to implement the simpler cases first and then we can optimize every algorithm separately
| const auto __n = ::cuda::std::countl_one(__mask_rev); | ||
|
|
||
| // Write __n consecutive bits. | ||
| const auto __segment = static_cast<_Tp>(__v & ::cuda::bitmask<_Tp>(0, __n)); |
There was a problem hiding this comment.
Question: Should we use the shl instruction on device?
At least clang knows some compiler builtins (__builtin_ia32_pext_di and __builtin_ia32_pext_si) for that https://www.mail-archive.com/cfe-commits@lists.llvm.org/msg706509.html
GCC knows _pext_u32 and _pext_u64 but only with -mbmi2 We might want to investigate if it is worth to optimize for clang-cuda here or at least add this as a followup
We will probably need the fallback for constexpr evaluation anyhow
| return __v; | ||
| } | ||
|
|
||
| const auto __pattern = static_cast<_Tp>(__v & ::cuda::bitmask<_Tp>(0, __n)); |
There was a problem hiding this comment.
Ditto we should be able to use compiler builtins for that
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🥳 CI Workflow Results🟩 Finished in 2h 39m: Pass: 100%/120 | Total: 1d 22h | Max: 1h 48m | Hits: 100%/358474See results here. |
No description provided.