Skip to content

Commit

Permalink
Merge branch 'branch-24.04' into b2404-cleanup-mg-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nv-rliu authored Mar 1, 2024
2 parents ed9273b + c9d75bf commit bc69030
Show file tree
Hide file tree
Showing 6 changed files with 487 additions and 48 deletions.
44 changes: 44 additions & 0 deletions cpp/include/cugraph/utilities/mask_utils.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,50 @@ __device__ size_t count_set_bits(MaskIterator mask_first, size_t start_offset, s
thrust::plus<size_t>{});
}

// @p n starts from 1
template <typename MaskIterator> // should be packed bool
__device__ size_t
find_nth_set_bits(MaskIterator mask_first, size_t start_offset, size_t num_bits, size_t n)
{
static_assert(
std::is_same_v<typename thrust::iterator_traits<MaskIterator>::value_type, uint32_t>);
assert(n >= 1);
assert(n <= num_bits);

size_t pos{0};

mask_first = mask_first + packed_bool_offset(start_offset);
start_offset = start_offset % packed_bools_per_word();
if (start_offset != 0) {
auto mask = ~packed_bool_partial_mask(start_offset);
if (start_offset + num_bits < packed_bools_per_word()) {
mask &= packed_bool_partial_mask(start_offset + num_bits);
}
auto word = *mask_first & mask;
auto num_set_bits = __popc(word);
if (n <= num_set_bits) {
return static_cast<size_t>(__fns(word, start_offset, n)) - start_offset;
}
pos += __popc(mask);
n -= num_set_bits;
++mask_first;
}

while (pos < num_bits) {
auto mask = ((num_bits - pos) >= packed_bools_per_word())
? packed_bool_full_mask()
: packed_bool_partial_mask(num_bits - pos);
auto word = *mask_first & mask;
auto num_set_bits = __popc(word);
if (n <= num_set_bits) { return pos + static_cast<size_t>(__fns(word, 0, n)); }
pos += __popc(mask);
n -= num_set_bits;
++mask_first;
}

return std::numeric_limits<size_t>::max();
}

template <typename InputIterator,
typename MaskIterator, // should be packed bool
typename OutputIterator,
Expand Down
Loading

0 comments on commit bc69030

Please sign in to comment.