Repository navigation
Conversation
miscco
left a comment
There was a problem hiding this comment.
Thanks a lot, this is already looking really great 🎉
I have two minor comments, but this is missing tests. Please have a look what we do for e.g countr_zero in libcudacxx/test/libcudacxx/std/numerics/bit/bitops.count/countr_zero.pass.cpp
If you have any questions, feel free to ask
02c7d56 to
731da14
Compare
|
Addressed all feedback:
|
79ef976 to
69d084e
Compare
|
fbusato
left a comment
There was a problem hiding this comment.
thanks a lot for your contribution. When you get a chance, please also add the documentation
cuda::ffs
69d084e to
73a7a6a
Compare
Skipped:
|
|
@fbusato @miscco @davebayer Is there any changes I could make to make this PR merge ready? |
|
@Aminsed sorry about the delay, this is just a matter of prioritization |
|
/ok to test 73a7a6a |
|
@Aminsed please ping us when you make progress. It is very easy to miss updates on the PR from our side. |
This comment has been minimized.
This comment has been minimized.
|
For verification, I pulled nvidia/cuda:13.0.2-devel-ubuntu22.04 (NVCC 13.0.88) and built/ran libcudacxx/test/libcudacxx/cuda/bit/ffs.pass.cpp; it passes, so the new cuda::ffs path behaves as expected with the latest toolchain. What I've learned from the CI run: If we re-run the full libcudacxx presets, CMake still aborts with “cuda_std_20 is not known to CUDA compiler” (NVCC 12.5 and even 13.0 don’t expose that compile feature yet). |
|
pre-commit.ci autofix |
|
/ok to test fd5edab |
This comment has been minimized.
This comment has been minimized.
|
Quick update: I re-ran the full libcudacxx, Thrust, CUB, and cudax presets in the rapidsai/devcontainers:25.12-cpp-llvm20-cuda13.0 image and they’re all green now. I also kicked off the c-parallel preset, but it still fails on existing issues (Thrust warnings treated as errors for unused parameters, plus lambda/index_sequence bugs in c/parallel/src/jit_templates). Those failures happen on current main as well, so I didn’t try to patch them here. Could you please rerun CI when you get a chance? |
|
/ok to test 9b5ddd2 |
This comment has been minimized.
This comment has been minimized.
4c609e6 to
28703eb
Compare
|
/ok to test a03dfe1 |
This comment has been minimized.
This comment has been minimized.
|
/ok to test 554a348 |
fbusato
left a comment
There was a problem hiding this comment.
I see there are multiple changes not related to ffs. Let me update the branch to align the code with the latest version
| } | ||
|
|
||
| #if _CCCL_COMPILER(NVRTC) | ||
| [[nodiscard]] _CCCL_DEVICE inline int __ffs_host32(::cuda::std::uint32_t __v) noexcept |
There was a problem hiding this comment.
I think that merging all __ffs_host* functions with if constexpr (sizeof(T) == X) would result in a shorted/cleaner code, or at least the constant evaluation part
| #else | ||
| [[nodiscard]] _CCCL_HOST_API inline int __ffs_host32(::cuda::std::uint32_t __v) noexcept | ||
| { | ||
| if (::cuda::std::__cccl_default_is_constant_evaluated()) |
There was a problem hiding this comment.
please use the new macro based on consteval
| #endif // _CCCL_HAS_INT128() | ||
|
|
||
| #if _CCCL_CUDA_COMPILATION() | ||
| [[nodiscard]] _CCCL_DEVICE_API inline int __ffs_device32(::cuda::std::uint32_t __v) noexcept |
There was a problem hiding this comment.
same here. We could merge the function bodies
| { | ||
| using _Unsigned = ::cuda::std::remove_cv_t<_Tp>; | ||
|
|
||
| #if !defined(_CCCL_BUILTIN_IS_CONSTANT_EVALUATED) |
There was a problem hiding this comment.
we should not check the built-in here. We can use consteval @davebayer
| # if _CCCL_HAS_INT128() | ||
| if constexpr (sizeof(_Unsigned) == sizeof(__uint128_t)) | ||
| { | ||
| NV_IF_ELSE_TARGET(NV_IS_HOST, | ||
| (return __detail::__ffs_host128(static_cast<__uint128_t>(__v));), | ||
| (return __detail::__ffs_device128(static_cast<__uint128_t>(__v));)) | ||
| } | ||
| # endif // _CCCL_HAS_INT128() | ||
|
|
||
| if constexpr (sizeof(_Unsigned) <= sizeof(::cuda::std::uint32_t)) | ||
| { | ||
| NV_IF_ELSE_TARGET(NV_IS_HOST, | ||
| (return __detail::__ffs_host32(static_cast<::cuda::std::uint32_t>(__v));), | ||
| (return __detail::__ffs_device32(static_cast<::cuda::std::uint32_t>(__v));)) | ||
| } | ||
| else | ||
| { | ||
| NV_IF_ELSE_TARGET(NV_IS_HOST, | ||
| (return __detail::__ffs_host64(static_cast<::cuda::std::uint64_t>(__v));), | ||
| (return __detail::__ffs_device64(static_cast<::cuda::std::uint64_t>(__v));)) |
There was a problem hiding this comment.
all these functions could be merged after the previous suggestions
|
/ok to test f896eac |
This comment has been minimized.
This comment has been minimized.
miscco
left a comment
There was a problem hiding this comment.
I am deeply concerned that this PR touches files that are not even remotely related to the topic at hand.
I would strongly encourage you to only touch files that are related to the topic at hand
|
@fbusato Addressed your feedback:
The PR now only contains changes directly related to
All tests verified locally:
Regarding the function merging suggestion on line 132 - the current pattern follows the existing structure in the codebase. Happy to refactor if you prefer the Ready for CI when you have a chance! |
|
/ok to test 816159c |
fbusato
left a comment
There was a problem hiding this comment.
looks good! I think the refactoring is not mandatory. The code in ffs.h is well-organized at the end.
😬 CI Workflow Results🟥 Finished in 5h 48m: Pass: 91%/91 | Total: 1d 18h | Max: 3h 09m | Hits: 98%/197722See results here. |
Implements cuda::ffs for unsigned integer types with optimized device implementations using CUDA intrinsics and host implementations using compiler builtins where available. - Uses __ffs intrinsic on device for 32-bit, __ffsll for 64-bit - Uses _CCCL_BUILTIN_FFS/FFSLL on host when available - Falls back to constexpr implementation for compile-time evaluation - Inlines host logic in NV_IF_ELSE_TARGET to avoid NVRTC issues - Includes comprehensive tests and documentation
816159c to
8e26465
Compare
|
closing as it is a duplicate of #9609 |
Implement type-safe
cuda::std::ffsfunction as replacement for__ffsintrinsic.x == 0correctly (returns 0)Fixes #6108