-
Notifications
You must be signed in to change notification settings - Fork 282
[Backport 3.1]: [CUB] Replace several direct uses of __clz
(#6099)
#6202
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,8 +48,15 @@ | |
#include <cub/util_ptx.cuh> | ||
#include <cub/util_type.cuh> | ||
|
||
#include <cuda/ptx> | ||
#include <cuda/std/__algorithm_> | ||
#include <cuda/__ptx/instructions/get_sreg.h> | ||
#include <cuda/std/__algorithm/clamp.h> | ||
#include <cuda/std/__bit/has_single_bit.h> | ||
Comment on lines
+52
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these two headers are never used if I'm not wrong |
||
#include <cuda/std/__bit/integral.h> | ||
#include <cuda/std/__functional/operations.h> | ||
#include <cuda/std/__type_traits/integral_constant.h> | ||
#include <cuda/std/__type_traits/is_integral.h> | ||
#include <cuda/std/__type_traits/is_unsigned.h> | ||
#include <cuda/warp> | ||
|
||
CUB_NAMESPACE_BEGIN | ||
namespace detail | ||
|
@@ -552,7 +559,7 @@ struct WarpScanShfl | |
ballot = ballot & ::cuda::ptx::get_sreg_lanemask_le(); | ||
|
||
// Find index of first set bit | ||
int segment_first_lane = _CUDA_VSTD::max(0, 31 - __clz(ballot)); | ||
int segment_first_lane = ::cuda::std::__bit_log2(ballot); | ||
|
||
// Iterate scan steps | ||
_CCCL_PRAGMA_UNROLL_FULL() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
#endif // no system header | ||
#include <thrust/detail/type_deduction.h> | ||
|
||
#include <cuda/std/__bit/countl.h> | ||
#include <cuda/std/__type_traits/make_unsigned.h> | ||
#include <cuda/std/limits> | ||
#include <cuda/std/type_traits> | ||
|
||
|
@@ -36,25 +38,6 @@ THRUST_NAMESPACE_BEGIN | |
namespace detail | ||
{ | ||
|
||
template <typename Integer> | ||
_CCCL_HOST_DEVICE _CCCL_FORCEINLINE Integer clz(Integer x) | ||
{ | ||
Integer result; | ||
|
||
NV_IF_TARGET(NV_IS_DEVICE, | ||
(result = ::__clz(x);), | ||
(int num_bits = 8 * sizeof(Integer); int num_bits_minus_one = num_bits - 1; result = num_bits; | ||
for (int i = num_bits_minus_one; i >= 0; --i) { | ||
if ((Integer(1) << i) & x) | ||
{ | ||
result = num_bits_minus_one - i; | ||
break; | ||
} | ||
})); | ||
|
||
return result; | ||
} | ||
|
||
template <typename Integer> | ||
_CCCL_HOST_DEVICE _CCCL_FORCEINLINE bool is_power_of_2(Integer x) | ||
{ | ||
|
@@ -85,7 +68,7 @@ _CCCL_HOST_DEVICE _CCCL_FORCEINLINE Integer log2(Integer x) | |
Integer num_bits = 8 * sizeof(Integer); | ||
Integer num_bits_minus_one = num_bits - 1; | ||
|
||
return num_bits_minus_one - clz(x); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return num_bits_minus_one - ::cuda::std::countl_zero(::cuda::std::__to_unsigned_like(x)); | ||
} | ||
|
||
template <typename Integer> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 unused
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 use
cuda::std::_If
AFAIK