Skip to content

[BUG]: UB in cuda::shuffle_iterator due to incorrect use of bit_ceil #7073

@leofang

Description

@leofang

Is this a duplicate?

Type of Bug

Runtime Error

Component

libcu++

Describe the bug

bit_ceil causes overflow in the bit shifts below. The original PR (#4564) calls a custom get_cipher_bits which is an optimized version of bit_width.

Originally posted by @leofang in #5530 (comment)

How to Reproduce

Pass 100,000,000 as __num_elements to the constructor to see this.

_CCCL_API __feistel_bijection(uint64_t __num_elements, _RNG&& __gen)
{
const uint64_t __total_bits = (::cuda::std::max) (uint64_t{4}, ::cuda::std::bit_ceil(__num_elements));
// Half bits rounded down
__left_side_bits = __total_bits / 2;
__left_side_mask = (1ull << __left_side_bits) - 1;

Expected behavior

The original PR before porting (#4564) was correct.

Reproduction link

No response

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working right.

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions