Skip to content

Commit 39b014d

Browse files
committed
Merge remote-tracking branch 'origin/main' into improve-jaccard
2 parents 64e4446 + f224cf0 commit 39b014d

51 files changed

Lines changed: 715 additions & 518 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎cpp/include/cudf/fixed_point/detail/floating_conversion.hpp‎

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
2+
* SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -17,46 +17,6 @@
1717
namespace numeric {
1818
namespace detail {
1919

20-
/**
21-
* @brief Determine the number of significant bits in an integer
22-
*
23-
* @tparam T Type of input integer value. Must be either uint32_t, uint64_t, or __uint128_t
24-
* @param value The integer whose bits are being counted
25-
* @return The number of significant bits: the # of bits - # of leading zeroes
26-
*/
27-
template <typename T,
28-
CUDF_ENABLE_IF(cuda::std::is_same_v<T, uint32_t> || cuda::std::is_same_v<T, uint64_t> ||
29-
cuda::std::is_same_v<T, __uint128_t>)>
30-
CUDF_HOST_DEVICE inline constexpr int count_significant_bits(T value)
31-
{
32-
#ifdef __CUDA_ARCH__
33-
if constexpr (cuda::std::is_same_v<T, uint64_t>) {
34-
return 64 - __clzll(static_cast<int64_t>(value));
35-
} else if constexpr (cuda::std::is_same_v<T, uint32_t>) {
36-
return 32 - __clz(static_cast<int32_t>(value));
37-
} else if constexpr (cuda::std::is_same_v<T, __uint128_t>) {
38-
// 128 bit type, must break up into high and low components
39-
auto const high_bits = static_cast<int64_t>(value >> 64);
40-
auto const low_bits = static_cast<int64_t>(value);
41-
return 128 - (__clzll(high_bits) + static_cast<int>(high_bits == 0) * __clzll(low_bits));
42-
}
43-
#else
44-
if constexpr (cuda::std::is_same_v<T, uint64_t>) {
45-
return 64 - cuda::std::countl_zero(value);
46-
} else if constexpr (cuda::std::is_same_v<T, uint32_t>) {
47-
return 32 - cuda::std::countl_zero(value);
48-
} else if constexpr (cuda::std::is_same_v<T, __uint128_t>) {
49-
// 128 bit type, must break up into high and low components
50-
auto const high_bits = static_cast<uint64_t>(value >> 64);
51-
if (high_bits == 0) {
52-
return 64 - cuda::std::countl_zero(static_cast<uint64_t>(value));
53-
} else {
54-
return 128 - cuda::std::countl_zero(high_bits);
55-
}
56-
}
57-
#endif
58-
}
59-
6020
/**
6121
* @brief Helper struct for getting and setting the components of a floating-point value
6222
*
@@ -189,7 +149,7 @@ struct floating_converter {
189149

190150
// Line-up denormal to same (understood) bit as normal numbers
191151
// This is so bit-shifting starts at the same bit index
192-
auto const lineup_shift = num_significand_bits - count_significant_bits(significand);
152+
auto const lineup_shift = num_significand_bits - cuda::std::bit_width(significand);
193153
significand <<= lineup_shift;
194154
floating_pow2 -= lineup_shift;
195155
} else {
@@ -954,7 +914,7 @@ CUDF_HOST_DEVICE inline auto shift_to_binary_pospow(DecimalRep decimal_rep, int
954914
// except our first operation is a multiply, so not quite that far
955915
// We are bit-shifting down, so we need extra bits on the low-side, which this has.
956916
static constexpr int shift_up_to = sizeof(ShiftingRep) * 8 - Constants::max_bits_shift;
957-
int const shift_from = count_significant_bits(decimal_rep);
917+
int const shift_from = cuda::std::bit_width(decimal_rep);
958918
int const num_init_bit_shift = shift_up_to - shift_from;
959919
int pow2 = -num_init_bit_shift;
960920

@@ -1017,7 +977,7 @@ CUDF_HOST_DEVICE inline auto shift_to_binary_negpow(DecimalRep decimal_rep, int
1017977
// so that we lose minimal information we need on intermediary right-shifts.
1018978
// Note that since we're shifting 2s up, we need num_2s_shift_buffer_bits space on the high side
1019979
static constexpr int shift_up_to = sizeof(ShiftingRep) * 8 - Constants::num_2s_shift_buffer_bits;
1020-
int const shift_from = count_significant_bits(decimal_rep);
980+
int const shift_from = cuda::std::bit_width(decimal_rep);
1021981
int const num_init_bit_shift = shift_up_to - shift_from;
1022982
int pow2 = -num_init_bit_shift;
1023983

‎cpp/include/cudf/strings/detail/scatter.cuh‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
#include <cudf/strings/strings_column_view.hpp>
1010
#include <cudf/utilities/default_stream.hpp>
1111
#include <cudf/utilities/memory_resource.hpp>
12-
#include <cudf/utilities/span.hpp>
1312

14-
#include <rmm/device_uvector.hpp>
1513
#include <rmm/exec_policy.hpp>
1614

15+
#include <cuda/buffer>
1716
#include <cuda/functional>
1817
#include <cuda/iterator>
1918
#include <cuda/std/iterator>
@@ -59,7 +58,7 @@ std::unique_ptr<column> scatter(SourceIterator begin,
5958
if (target.is_empty()) return make_empty_column(type_id::STRING);
6059

6160
// create vector of string_view's to scatter into
62-
rmm::device_uvector<string_view> target_vector =
61+
auto target_vector =
6362
create_string_vector_from_column(target, stream, cudf::get_current_device_resource_ref());
6463

6564
// this ensures empty strings are not mapped to nulls in the make_strings_column function
@@ -77,8 +76,7 @@ std::unique_ptr<column> scatter(SourceIterator begin,
7776
target_vector.begin());
7877

7978
// build the output column
80-
auto sv_span = cudf::device_span<string_view const>(target_vector);
81-
return make_strings_column(sv_span, string_view{nullptr, 0}, stream, mr);
79+
return make_strings_column(target_vector, string_view{nullptr, 0}, stream, mr);
8280
}
8381

8482
} // namespace detail

‎cpp/include/cudf/strings/detail/utilities.hpp‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
#include <cudf/utilities/memory_resource.hpp>
1212
#include <cudf/utilities/span.hpp>
1313

14-
#include <rmm/device_uvector.hpp>
15-
14+
#include <cuda/buffer>
1615
#include <cuda/stream>
1716

1817
namespace CUDF_EXPORT cudf {
@@ -37,14 +36,14 @@ std::unique_ptr<column> create_offsets_child_column(int64_t chars_bytes,
3736
rmm::device_async_resource_ref mr);
3837

3938
/**
40-
* @brief Creates a string_view vector from a strings column.
39+
* @brief Creates a string_view buffer from a strings column.
4140
*
4241
* @param strings Strings column instance.
4342
* @param stream CUDA stream used for device memory operations and kernel launches.
44-
* @param mr Device memory resource used to allocate the returned vector's device memory.
45-
* @return Device vector of string_views
43+
* @param mr Device memory resource used to allocate the returned buffer's device memory.
44+
* @return Device buffer of string_views
4645
*/
47-
rmm::device_uvector<string_view> create_string_vector_from_column(
46+
cuda::device_buffer<string_view> create_string_vector_from_column(
4847
cudf::strings_column_view const strings,
4948
cuda::stream_ref stream,
5049
rmm::device_async_resource_ref mr);

‎cpp/src/binaryop/compiled/binary_ops.cuh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ struct ops_wrapper {
100100
column_device_view const& rhs;
101101
bool const& is_lhs_scalar;
102102
bool const& is_rhs_scalar;
103+
// With bit_width, nvcc 13.3 can outline decimal128 conversions and add local memory setup
104+
// before type dispatch, slowing float ADD. Keep this wrapper inline to avoid that setup.
103105
template <typename TypeCommon>
104-
__device__ void operator()(size_type i)
106+
__forceinline__ __device__ void operator()(size_type i)
105107
{
106108
if constexpr (cuda::std::is_invocable_v<BinaryOperator, TypeCommon, TypeCommon>) {
107109
TypeCommon x =

‎cpp/src/bitmask/null_mask.cu‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ void set_null_masks(cudf::host_span<bitmask_type*> bitmasks,
238238
average_nullmask_words +=
239239
cudf::util::div_rounding_up_safe<size_t>(cumulative_null_mask_words, num_bitmasks);
240240

241-
// Create device vectors from host spans
241+
// Create device buffers from host spans
242242
auto const mr = cudf::get_current_device_resource_ref();
243-
auto destinations = cudf::detail::make_device_uvector_async(bitmasks, stream, mr);
244-
auto const d_begin_bits = cudf::detail::make_device_uvector_async(begin_bits, stream, mr);
245-
auto const d_end_bits = cudf::detail::make_device_uvector_async(end_bits, stream, mr);
246-
auto const d_valids = cudf::detail::make_device_uvector_async(valids, stream, mr);
243+
auto destinations = cudf::detail::make_device_buffer_async(bitmasks, stream, mr);
244+
auto const d_begin_bits = cudf::detail::make_device_buffer_async(begin_bits, stream, mr);
245+
auto const d_end_bits = cudf::detail::make_device_buffer_async(end_bits, stream, mr);
246+
auto const d_valids = cudf::detail::make_device_buffer_async(valids, stream, mr);
247247
auto const number_of_mask_words =
248-
cudf::detail::make_device_uvector_async(h_number_of_mask_words, stream, mr);
248+
cudf::detail::make_device_buffer_async(h_number_of_mask_words, stream, mr);
249249

250250
// Compute block size using heuristic and launch kernel
251251
constexpr size_t max_words_per_thread = 64;
@@ -499,7 +499,7 @@ std::vector<size_type> batch_count_set_bits(host_span<bitmask_type const* const>
499499
if (!has_bitmask) { return output; }
500500

501501
auto const tmp_mr = cudf::get_current_device_resource_ref();
502-
auto const d_bitmasks = cudf::detail::make_device_uvector_async(bitmasks, stream, tmp_mr);
502+
auto const d_bitmasks = cudf::detail::make_device_buffer_async(bitmasks, stream, tmp_mr);
503503
auto const num_words = num_bitmask_words(num_bits_to_count);
504504
auto d_non_zero_count =
505505
cudf::detail::make_zeroed_device_buffer_async<size_type>(num_bitmasks, stream, tmp_mr);

‎cpp/src/column/column_factories.cu‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ std::unique_ptr<cudf::column> column_from_scalar_dispatch::operator()<cudf::stru
106106
cuda::stream_ref stream,
107107
rmm::device_async_resource_ref mr) const
108108
{
109-
CUDF_EXPECTS(size != 0, "0-length struct column is unsupported.");
110109
auto& ss = static_cast<scalar_type_t<cudf::struct_view> const&>(value);
111110
auto iter = cuda::make_constant_iterator(0);
112111

‎cpp/src/copying/concatenate.cu‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <cudf/detail/get_value.cuh>
1313
#include <cudf/detail/null_mask.hpp>
1414
#include <cudf/detail/nvtx/ranges.hpp>
15+
#include <cudf/detail/utilities/buffer_factories.hpp>
1516
#include <cudf/detail/utilities/cuda.cuh>
1617
#include <cudf/detail/utilities/cuda.hpp>
1718
#include <cudf/detail/utilities/cuda_memcpy.hpp>
@@ -74,7 +75,7 @@ auto create_device_views(host_span<column_view const> views, cuda::stream_ref st
7475
[](auto const& col) { return *col; });
7576

7677
auto d_views =
77-
make_device_uvector_async(device_views, stream, cudf::get_current_device_resource_ref());
78+
make_device_buffer_async(device_views, stream, cudf::get_current_device_resource_ref());
7879

7980
// Compute the partition offsets
8081
auto offsets = cudf::detail::make_pinned_vector_async<size_t>(views.size() + 1, stream);
@@ -86,7 +87,7 @@ auto create_device_views(host_span<column_view const> views, cuda::stream_ref st
8687
[](auto const& col) { return col.size(); },
8788
cuda::std::plus{});
8889
auto d_offsets =
89-
make_device_uvector_async(offsets, stream, cudf::get_current_device_resource_ref());
90+
make_device_buffer_async(offsets, stream, cudf::get_current_device_resource_ref());
9091
auto const output_size = offsets.back();
9192
cudf::detail::sync_stream(stream);
9293

‎cpp/src/groupby/hash/hash_csr_kernels.cuh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <cooperative_groups.h>
1818
#include <cuda/atomic>
19+
#include <cuda/cmath>
20+
#include <cuda/std/bit>
1921
#include <cuda/std/cstdint>
2022
#include <cuda/std/limits>
2123
#include <cuda/std/utility>
@@ -71,7 +73,7 @@ struct hash_set_ref {
7173
{
7274
representative = cudf::detail::CUDF_SIZE_TYPE_SENTINEL;
7375
// Multiply-high reduces the hash to any capacity without division or modulo.
74-
auto slot = __umulhi(__brev(hash_value), capacity);
76+
auto slot = cuda::mul_hi(cuda::std::bit_reverse(hash_value), capacity);
7577
for (cuda::std::uint32_t step = 0; step < max_probes; ++step) {
7678
auto slot_ref = cuda::atomic_ref<slot_type, cuda::thread_scope_device>{slots[slot]};
7779
auto current = slot_ref.load(cuda::memory_order_relaxed);

‎cpp/src/groupby/sort/group_quantiles.cu‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
#include <cudf/column/column_view.hpp>
1212
#include <cudf/detail/aggregation/aggregation.hpp>
1313
#include <cudf/detail/device_scalar.hpp>
14-
#include <cudf/detail/utilities/vector_factories.hpp>
14+
#include <cudf/detail/utilities/buffer_factories.hpp>
1515
#include <cudf/dictionary/detail/iterator.cuh>
1616
#include <cudf/dictionary/dictionary_column_view.hpp>
1717
#include <cudf/utilities/memory_resource.hpp>
1818
#include <cudf/utilities/span.hpp>
1919

20-
#include <rmm/device_uvector.hpp>
2120
#include <rmm/exec_policy.hpp>
2221

2322
#include <cuda/iterator>
@@ -156,7 +155,7 @@ std::unique_ptr<column> group_quantiles(column_view const& values,
156155
cuda::stream_ref stream,
157156
rmm::device_async_resource_ref mr)
158157
{
159-
auto dv_quantiles = cudf::detail::make_device_uvector_async(
158+
auto dv_quantiles = cudf::detail::make_device_buffer_async(
160159
quantiles, stream, cudf::get_current_device_resource_ref());
161160

162161
auto values_type = cudf::is_dictionary(values.type())

‎cpp/src/io/comp/debrotli.cu‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ THE SOFTWARE.
5555
#include <cudf/utilities/memory_resource.hpp>
5656

5757
#include <cuda/buffer>
58+
#include <cuda/std/bit>
5859
#include <cuda/stream>
5960

6061
namespace cudf::io::detail {
@@ -78,11 +79,6 @@ inline __device__ uint32_t brotli_distance_alphabet_size(uint8_t npostfix,
7879
return brotli_num_distance_short_codes + ndirect + (maxnbits << (npostfix + 1));
7980
}
8081

81-
inline __device__ uint32_t brev8(uint32_t x)
82-
{
83-
return (__brev(x) >> 24u); // kReverseBits[x]
84-
}
85-
8682
#define CONSTANT static const __device__ __constant__
8783
#include "brotli_tables.hpp"
8884

@@ -190,8 +186,6 @@ struct debrotli_state_s {
190186
__align__(8) char heap[local_heap_size];
191187
};
192188

193-
inline __device__ uint32_t Log2Floor(uint32_t value) { return 32 - __clz(value); }
194-
195189
/// @brief Safely read up to 4 bytes with bounds checking, handling end-of-buffer cases
196190
inline __device__ uint32_t safe_load_u32(uint8_t const* p, uint8_t const* end)
197191
{
@@ -615,7 +609,7 @@ static __device__ void BuildCodeLengthsHuffmanTable(huff_scratch_s* hs)
615609
for (int bits_count = hs->code_length_histo[bits]; bits_count != 0; --bits_count) {
616610
int end = table_size;
617611
code = huffcode(bits, hs->sorted[symbol++]);
618-
uint16_t* p = &hs->lenvlctab[brev8(key)];
612+
uint16_t* p = &hs->lenvlctab[cuda::std::bit_reverse(static_cast<uint8_t>(key))];
619613
do {
620614
end -= step;
621615
p[end] = code;
@@ -687,7 +681,7 @@ static __device__ uint32_t BuildHuffmanTable(uint16_t* root_lut,
687681
for (int bits_count = count[bits]; bits_count != 0; --bits_count) {
688682
symbol = symbol_lists[symbol];
689683
code = huffcode(bits, symbol);
690-
uint16_t* p = &lut[brev8(key)];
684+
uint16_t* p = &lut[cuda::std::bit_reverse(static_cast<uint8_t>(key))];
691685
int end = table_size;
692686
do {
693687
end -= step;
@@ -717,15 +711,15 @@ static __device__ uint32_t BuildHuffmanTable(uint16_t* root_lut,
717711
table_bits = NextTableBitSize(count, len, root_bits);
718712
table_size = 1 << table_bits;
719713
total_size += table_size;
720-
sub_key = brev8(key);
714+
sub_key = cuda::std::bit_reverse(static_cast<uint8_t>(key));
721715
key += key_step;
722716
root_lut[sub_key] =
723717
huffcode(table_bits + root_bits, (((size_t)(lut - root_lut)) - sub_key));
724718
sub_key = 0;
725719
}
726720
symbol = symbol_lists[symbol];
727721
code = huffcode(len - root_bits, symbol);
728-
uint16_t* p = &lut[brev8(sub_key)];
722+
uint16_t* p = &lut[cuda::std::bit_reverse(static_cast<uint8_t>(sub_key))];
729723
int end = table_size;
730724
do {
731725
end -= step;
@@ -904,7 +898,7 @@ static __device__ uint32_t DecodeHuffmanTree(debrotli_state_s* s,
904898
if (prefix_code_type == 1) {
905899
// Simple prefix Code
906900
uint32_t nsym = getbits(s, 2);
907-
uint32_t alphabet_bits = Log2Floor(alphabet_size - 1);
901+
uint32_t alphabet_bits = cuda::std::bit_width(alphabet_size - 1);
908902
for (uint32_t n = 0; n <= nsym; n++) {
909903
uint32_t v = getbits(s, alphabet_bits);
910904
if (v >= max_symbol) {

0 commit comments

Comments
 (0)