Skip to content

Commit 6fea1f9

Browse files
Convert headers' scratch rmm::device_uvector<T> to cuda::device_buffer<T>
Use CCCL buffers instead of RMM vectors where possible in inline implementations in the headers. Issue: rapidsai/build-planning#321
1 parent f5cb11b commit 6fea1f9

12 files changed

Lines changed: 58 additions & 46 deletions

File tree

‎cpp/include/cudf/detail/device_scalar.hpp‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include <cudf/detail/utilities/host_vector.hpp>
1010
#include <cudf/detail/utilities/vector_factories.hpp>
1111

12-
#include <rmm/device_uvector.hpp>
1312
#include <rmm/resource_ref.hpp>
1413

14+
#include <cuda/buffer>
1515
#include <cuda/stream>
1616

1717
#include <type_traits>
@@ -43,23 +43,25 @@ class device_scalar {
4343
explicit device_scalar(
4444
cuda::stream_ref stream,
4545
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())
46-
: _storage{1, stream, std::move(mr)}, bounce_buffer{make_pinned_vector<T>(1, stream)}
46+
: _storage{stream, std::move(mr), 1, cuda::no_init},
47+
bounce_buffer{make_pinned_vector<T>(1, stream)}
4748
{
4849
}
4950

5051
explicit device_scalar(
5152
T const& initial_value,
5253
cuda::stream_ref stream,
5354
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())
54-
: _storage{1, stream, std::move(mr)}, bounce_buffer{make_pinned_vector<T>(1, stream)}
55+
: _storage{stream, std::move(mr), 1, cuda::no_init},
56+
bounce_buffer{make_pinned_vector<T>(1, stream)}
5557
{
5658
set_value_async(initial_value, stream);
5759
}
5860

5961
device_scalar(device_scalar const& other,
6062
cuda::stream_ref stream,
6163
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())
62-
: _storage{other._storage, stream, mr}, bounce_buffer{make_pinned_vector<T>(1, stream)}
64+
: _storage{stream, mr, other._storage}, bounce_buffer{make_pinned_vector<T>(1, stream)}
6365
{
6466
}
6567

@@ -88,7 +90,7 @@ class device_scalar {
8890
[[nodiscard]] T const* data() const noexcept { return _storage.data(); }
8991

9092
private:
91-
rmm::device_uvector<T> _storage;
93+
cuda::device_buffer<T> _storage;
9294
mutable cudf::detail::host_vector<T> bounce_buffer;
9395
};
9496

‎cpp/include/cudf/detail/gather.cuh‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <cudf/detail/indexalator.cuh>
99
#include <cudf/detail/null_mask.hpp>
1010
#include <cudf/detail/utilities/assert.cuh>
11+
#include <cudf/detail/utilities/buffer_factories.hpp>
1112
#include <cudf/detail/utilities/cuda.cuh>
1213
#include <cudf/detail/utilities/grid_1d.cuh>
1314
#include <cudf/detail/utilities/vector_factories.hpp>
@@ -583,10 +584,10 @@ void gather_bitmask(table_view const& source,
583584
std::transform(target.begin(), target.end(), target_masks.begin(), [](auto const& col) {
584585
return col->mutable_view().null_mask();
585586
});
586-
auto d_target_masks = make_device_uvector_async(target_masks, stream, temp_mr);
587+
auto d_target_masks = make_device_buffer_async(target_masks, stream, temp_mr);
587588

588589
auto const device_source = table_device_view::create(source, stream, temp_mr);
589-
auto d_valid_counts = make_zeroed_device_uvector_async<size_type>(target.size(), stream, temp_mr);
590+
auto d_valid_counts = make_zeroed_device_buffer_async<size_type>(target.size(), stream, temp_mr);
590591

591592
// Dispatch operation enum to get implementation
592593
auto const impl = [op]() {

‎cpp/include/cudf/detail/labeling/label_segments.cuh‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include <cudf/types.hpp>
1010
#include <cudf/utilities/memory_resource.hpp>
1111

12-
#include <rmm/device_uvector.hpp>
1312
#include <rmm/exec_policy.hpp>
1413

14+
#include <cuda/buffer>
1515
#include <cuda/iterator>
1616
#include <cuda/stream>
1717
#include <thrust/for_each.h>
@@ -166,11 +166,13 @@ void labels_to_offsets(InputIterator labels_begin,
166166

167167
// This stores the unique label values.
168168
// Given the example above, we will have this array containing [0, 1, 4].
169-
auto list_indices = rmm::device_uvector<OutputType>(num_segments, stream);
169+
auto list_indices = cuda::device_buffer<OutputType>(
170+
stream, cudf::get_current_device_resource_ref(), num_segments, cuda::no_init);
170171

171172
// Stores the non-zero segment sizes.
172173
// Given the example above, we will have this array containing [4, 2, 4].
173-
auto list_sizes = rmm::device_uvector<OutputType>(num_segments, stream);
174+
auto list_sizes = cuda::device_buffer<OutputType>(
175+
stream, cudf::get_current_device_resource_ref(), num_segments, cuda::no_init);
174176

175177
// Count the numbers of labels in the each segment.
176178
auto const end = cudf::detail::reduce_by_key(labels_begin, // keys

‎cpp/include/cudf/detail/null_mask.cuh‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include <cudf/detail/device_scalar.hpp>
8+
#include <cudf/detail/utilities/buffer_factories.hpp>
89
#include <cudf/detail/utilities/cuda.cuh>
910
#include <cudf/detail/utilities/cuda.hpp>
1011
#include <cudf/detail/utilities/grid_1d.cuh>
@@ -313,7 +314,7 @@ segmented_bitmask_binop(Binop op,
313314
h_destination_masks_ptrs.push_back(h_destination_masks.back()->data());
314315
}
315316
auto destination_masks =
316-
cudf::detail::make_device_uvector_async(h_destination_masks_ptrs, stream, temp_mr);
317+
cudf::detail::make_device_buffer_async(h_destination_masks_ptrs, stream, temp_mr);
317318

318319
// for destination size, pass number of words in each destination buffer instead of number of bits
319320
auto null_counts = inplace_segmented_bitmask_binop(op,
@@ -363,8 +364,8 @@ size_type inplace_bitmask_binop(Binop op,
363364
auto const temp_mr = mr.get_temporary_mr();
364365
cudf::detail::device_scalar<size_type> d_counter{0, stream, temp_mr};
365366

366-
auto d_masks = cudf::detail::make_device_uvector_async(masks, stream, temp_mr);
367-
auto d_begin_bits = cudf::detail::make_device_uvector_async(masks_begin_bits, stream, temp_mr);
367+
auto d_masks = cudf::detail::make_device_buffer_async(masks, stream, temp_mr);
368+
auto d_begin_bits = cudf::detail::make_device_buffer_async(masks_begin_bits, stream, temp_mr);
368369

369370
auto constexpr block_size = 256;
370371
cudf::detail::grid_1d config(dest_mask.size(), block_size);
@@ -427,10 +428,9 @@ rmm::device_uvector<size_type> inplace_segmented_bitmask_binop(
427428
auto d_null_counts = cudf::detail::make_zeroed_device_uvector_async<size_type>(
428429
num_segments, stream, mr.get_output_mr());
429430
auto const temp_mr = mr.get_temporary_mr();
430-
auto d_masks = cudf::detail::make_device_uvector_async(masks, stream, temp_mr);
431-
auto d_begin_bits = cudf::detail::make_device_uvector_async(masks_begin_bits, stream, temp_mr);
432-
auto d_segment_offsets =
433-
cudf::detail::make_device_uvector_async(segment_offsets, stream, temp_mr);
431+
auto d_masks = cudf::detail::make_device_buffer_async(masks, stream, temp_mr);
432+
auto d_begin_bits = cudf::detail::make_device_buffer_async(masks_begin_bits, stream, temp_mr);
433+
auto d_segment_offsets = cudf::detail::make_device_buffer_async(segment_offsets, stream, temp_mr);
434434

435435
auto constexpr block_size = 256;
436436

@@ -701,7 +701,7 @@ std::vector<size_type> segmented_count_bits(bitmask_type const* bitmask,
701701
std::distance(indices_begin, indices_end), stream);
702702
std::copy(indices_begin, indices_end, std::back_inserter(h_indices));
703703
auto const temp_mr = cudf::get_current_device_resource_ref();
704-
auto const d_indices = make_device_uvector_async(h_indices, stream, temp_mr);
704+
auto const d_indices = make_device_buffer_async(h_indices, stream, temp_mr);
705705

706706
// Compute the bit counts over each segment.
707707
auto first_bit_indices_begin = cuda::transform_iterator(

‎cpp/include/cudf/detail/row_operator/primitive_lexicographic.cuh‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <cudf/detail/row_operator/lexicographic_common.cuh>
1212
#include <cudf/detail/row_operator/primitive_common.cuh>
1313
#include <cudf/detail/utilities/assert.cuh>
14+
#include <cudf/detail/utilities/buffer_factories.hpp>
1415
#include <cudf/detail/utilities/cuda.hpp>
15-
#include <cudf/detail/utilities/vector_factories.hpp>
1616
#include <cudf/table/table_device_view.cuh>
1717
#include <cudf/table/table_view.hpp>
1818
#include <cudf/types.hpp>
@@ -22,9 +22,9 @@
2222
#include <cudf/utilities/traits.hpp>
2323
#include <cudf/utilities/type_dispatcher.hpp>
2424

25-
#include <rmm/device_uvector.hpp>
2625
#include <rmm/resource_ref.hpp>
2726

27+
#include <cuda/buffer>
2828
#include <cuda/stream>
2929

3030
#include <type_traits>
@@ -150,9 +150,9 @@ class lexicographic_comparator {
150150
host_span<null_order const> null_precedence = {},
151151
cuda::stream_ref stream = cudf::get_default_stream())
152152
: _table{table_device_view::create(table, stream)},
153-
_column_order{cudf::detail::make_device_uvector_async(
153+
_column_order{cudf::detail::make_device_buffer_async(
154154
column_order, stream, cudf::get_current_device_resource_ref())},
155-
_null_precedence{cudf::detail::make_device_uvector_async(
155+
_null_precedence{cudf::detail::make_device_buffer_async(
156156
null_precedence, stream, cudf::get_current_device_resource_ref())}
157157
{
158158
if (not column_order.empty() or not null_precedence.empty()) {
@@ -180,8 +180,8 @@ class lexicographic_comparator {
180180
rmm::device_async_resource_ref>;
181181

182182
table_device_view_owner const _table;
183-
rmm::device_uvector<order> const _column_order;
184-
rmm::device_uvector<null_order> const _null_precedence;
183+
cuda::device_buffer<order> const _column_order;
184+
cuda::device_buffer<null_order> const _null_precedence;
185185
};
186186

187187
} // namespace cudf::detail::row::primitive

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <cudf/detail/iterator.cuh>
99
#include <cudf/detail/nvtx/ranges.hpp>
10-
#include <cudf/detail/utilities/vector_factories.hpp>
10+
#include <cudf/detail/utilities/buffer_factories.hpp>
1111
#include <cudf/utilities/error.hpp>
1212
#include <cudf/utilities/memory_resource.hpp>
1313

@@ -39,7 +39,7 @@ void batched_memset(cudf::host_span<cudf::device_span<T> const> host_buffers,
3939
CUDF_FUNC_RANGE();
4040

4141
// Copy buffer spans into device memory and then get sizes
42-
auto buffers = cudf::detail::make_device_uvector_async(
42+
auto buffers = cudf::detail::make_device_buffer_async(
4343
host_buffers, stream, cudf::get_current_device_resource_ref());
4444

4545
// Vector of sizes of all buffer spans

‎cpp/include/cudf/reduction/detail/approx_distinct_count.cuh‎

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

14-
#include <rmm/device_uvector.hpp>
15-
1614
#include <cuco/hyperloglog_ref.cuh>
15+
#include <cuda/buffer>
1716
#include <cuda/functional>
1817
#include <cuda/std/span>
1918
#include <cuda/stream>
@@ -34,7 +33,7 @@ namespace detail {
3433
* non-owning sketch storage modes:
3534
*
3635
* - **Owning mode**: Allocates and manages its own sketch storage as an
37-
* `rmm::device_uvector<int32_t>`. Used when constructing from a table or when copying
36+
* `cuda::device_buffer<int32_t>`. Used when constructing from a table or when copying
3837
* from a span.
3938
*
4039
* - **Non-owning mode**: Operates on user-provided `cuda::std::span<int32_t>` sketch
@@ -260,18 +259,17 @@ class approx_distinct_count {
260259
/**
261260
* @brief Storage type supporting both owning and non-owning modes
262261
*
263-
* - Owning: `device_uvector<register_type>` - allocates and manages storage
262+
* - Owning: `device_buffer<register_type>` - allocates and manages storage
264263
* - Non-owning: `span<byte>` - operates on user-provided storage
265264
*
266265
* The public API always exposes storage as `span<byte>` via `sketch()`.
267266
*/
268267
using storage_type =
269-
std::variant<rmm::device_uvector<register_type>, ///< Owning storage (allocated internally)
268+
std::variant<cuda::device_buffer<register_type>, ///< Owning storage (allocated internally)
270269
cuda::std::span<cuda::std::byte> ///< Non-owning storage (user-provided)
271270
>;
272271

273-
// Declared before `_storage` so it outlives the owning `device_uvector`, which only holds a
274-
// reference to this resource. Unused in non-owning (span) mode.
272+
// Declared before `_storage` so it outlives the owning buffer. Unused in non-owning (span) mode.
275273
cuda::mr::any_resource<cuda::mr::device_accessible> _mr; ///< Owns the sketch storage resource
276274
storage_type _storage; ///< Sketch register storage (owning or non-owning)
277275
std::int32_t _precision; ///< HLL precision parameter (determines 2^p registers)

‎cpp/include/cudf/reduction/detail/segmented_reduction.cuh‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <rmm/exec_policy.hpp>
1717

1818
#include <cub/device/device_segmented_reduce.cuh>
19+
#include <cuda/buffer>
1920
#include <cuda/execution>
2021
#include <cuda/iterator>
2122
#include <cuda/std/execution>
@@ -130,8 +131,10 @@ void segmented_reduce(InputIterator d_in,
130131
auto const initial_value = op.template get_identity<IntermediateType>();
131132
auto const binary_op = cudf::detail::cast_functor<IntermediateType>(op.get_binary_op());
132133

133-
rmm::device_uvector<IntermediateType> intermediate_result{static_cast<std::size_t>(num_segments),
134-
stream};
134+
cuda::device_buffer<IntermediateType> intermediate_result{stream,
135+
cudf::get_current_device_resource_ref(),
136+
static_cast<std::size_t>(num_segments),
137+
cuda::no_init};
135138

136139
auto const env = [&] {
137140
if constexpr (std::is_same_v<Op, op::variance> || std::is_same_v<Op, op::standard_deviation>) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include <cudf/strings/detail/strings_column_factories.cuh>
1010
#include <cudf/utilities/memory_resource.hpp>
1111

12-
#include <rmm/device_uvector.hpp>
1312
#include <rmm/exec_policy.hpp>
1413

14+
#include <cuda/buffer>
1515
#include <cuda/functional>
1616
#include <cuda/iterator>
1717
#include <cuda/std/optional>
@@ -66,7 +66,8 @@ std::unique_ptr<cudf::column> copy_if_else(StringIterLeft lhs_begin,
6666
if (null_count == 0) { null_mask = cudf::create_null_mask(0, cudf::mask_state::UNALLOCATED); }
6767

6868
// build vector of strings
69-
rmm::device_uvector<string_index_pair> indices(strings_count, stream);
69+
cuda::device_buffer<string_index_pair> indices(
70+
stream, cudf::get_current_device_resource_ref(), strings_count, cuda::no_init);
7071
thrust::transform(rmm::exec_policy_nosync(stream, cudf::get_current_device_resource_ref()),
7172
cuda::counting_iterator<size_type>{0},
7273
cuda::counting_iterator{static_cast<size_type>(strings_count)},

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <rmm/exec_policy.hpp>
2323

2424
#include <cub/device/device_memcpy.cuh>
25+
#include <cuda/buffer>
2526
#include <cuda/functional>
2627
#include <cuda/iterator>
2728
#include <cuda/std/execution>
@@ -248,7 +249,8 @@ auto make_strings_children(SizeAndExecuteFunction size_and_exec_fn,
248249
};
249250

250251
// Compute the output sizes
251-
auto output_sizes = rmm::device_uvector<size_type>(strings_count, stream);
252+
auto output_sizes = cuda::device_buffer<size_type>(
253+
stream, cudf::get_current_device_resource_ref(), strings_count, cuda::no_init);
252254
size_and_exec_fn.d_sizes = output_sizes.data();
253255
size_and_exec_fn.d_chars = nullptr;
254256
for_each_fn(size_and_exec_fn);

0 commit comments

Comments
 (0)