Skip to content

Commit c87e83d

Browse files
Convert IO tests' scratch rmm::device_uvector<T> to cuda::device_buffer<T> (#24963)
Use CCCL buffers instead of RMM vectors in IO tests. Issue: rapidsai/build-planning#321 Authors: - Kyle Edwards (https://github.com/KyleFromNVIDIA) Approvers: - Muhammad Haseeb (https://github.com/mhaseeb123) - Bradley Dice (https://github.com/bdice) URL: #24963
1 parent 001cdc5 commit c87e83d

5 files changed

Lines changed: 66 additions & 66 deletions

File tree

‎cpp/tests/io/comp/comp_test.cpp‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
#include <cudf_test/memory_resource_utilities.hpp>
1414
#include <cudf_test/testing_main.hpp>
1515

16+
#include <cudf/detail/utilities/buffer_factories.hpp>
17+
#include <cudf/detail/utilities/vector_factories.hpp>
1618
#include <cudf/io/detail/codec.hpp>
1719
#include <cudf/io/types.hpp>
1820
#include <cudf/utilities/default_stream.hpp>
1921

20-
#include <rmm/device_buffer.hpp>
21-
#include <rmm/device_uvector.hpp>
22-
2322
#include <cuda/buffer>
2423
#include <cuda/iterator>
2524

@@ -85,7 +84,8 @@ struct DecompressTest
8584
compressed.data(),
8685
compressed.data() + compressed.size()};
8786
}
88-
rmm::device_uvector<uint8_t> dst{decompressed.size(), stream};
87+
cuda::device_buffer<uint8_t> dst{
88+
stream, cudf::get_current_device_resource_ref(), decompressed.size(), cuda::no_init};
8989

9090
cudf::detail::hostdevice_vector<device_span<uint8_t const>> inf_in(
9191
1, stream, cudf::get_current_device_resource_ref());
@@ -480,10 +480,16 @@ void roundtrip_test(cudf::io::compression_type compression,
480480

481481
auto const test_input = cudf::host_span<uint8_t const>{expected.data(), test_size};
482482

483-
auto d_comp = rmm::device_uvector<uint8_t>(
484-
cudf::io::detail::max_compressed_size(compression, test_input.size()), stream, mr);
483+
auto d_comp = cuda::device_buffer<uint8_t>(
484+
stream,
485+
mr,
486+
cudf::io::detail::max_compressed_size(compression, test_input.size()),
487+
cuda::no_init);
488+
// Tracks the valid compressed bytes since device_buffer cannot be shrunk yet
489+
// TODO: Remove this when https://github.com/NVIDIA/cccl/issues/12051 is resolved
490+
device_span<uint8_t const> compressed = d_comp;
485491
{
486-
auto const d_orig = cudf::detail::make_device_uvector_async(test_input, stream, mr);
492+
auto const d_orig = cudf::detail::make_device_buffer_async(test_input, stream, mr);
487493
auto hd_srcs = cudf::detail::hostdevice_vector<device_span<uint8_t const>>(
488494
1, stream, cudf::get_current_device_resource_ref());
489495
hd_srcs[0] = d_orig;
@@ -504,14 +510,15 @@ void roundtrip_test(cudf::io::compression_type compression,
504510
});
505511
hd_stats.device_to_host(stream);
506512
ASSERT_EQ(hd_stats[0].status, codec_status::SUCCESS);
507-
d_comp.resize(hd_stats[0].bytes_written, stream);
513+
// TODO: Resize the buffer once https://github.com/NVIDIA/cccl/issues/12051 is resolved.
514+
compressed = compressed.first(hd_stats[0].bytes_written);
508515
}
509516

510-
auto d_got = rmm::device_uvector<uint8_t>(test_input.size(), stream, mr);
517+
auto d_got = cuda::device_buffer<uint8_t>(stream, mr, test_input.size(), cuda::no_init);
511518
{
512519
auto hd_srcs = cudf::detail::hostdevice_vector<device_span<uint8_t const>>(
513520
1, stream, cudf::get_current_device_resource_ref());
514-
hd_srcs[0] = d_comp;
521+
hd_srcs[0] = compressed;
515522
hd_srcs.host_to_device_async(stream);
516523

517524
auto hd_dsts = cudf::detail::hostdevice_vector<device_span<uint8_t>>(

‎cpp/tests/io/fst/logical_stack_test.cu‎

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
#include <cudf_test/base_fixture.hpp>
99
#include <cudf_test/testing_main.hpp>
1010

11+
#include <cudf/detail/utilities/buffer_factories.hpp>
1112
#include <cudf/types.hpp>
1213
#include <cudf/utilities/error.hpp>
1314

14-
#include <rmm/device_uvector.hpp>
15-
1615
#include <cuda/stream>
1716
#include <cuda_runtime_api.h>
1817

@@ -199,34 +198,24 @@ TEST_F(LogicalStackTest, GroundTruth)
199198
std::back_inserter(stack_symbols),
200199
std::back_inserter(stack_op_indexes));
201200

202-
rmm::device_uvector<SymbolT> d_stack_ops{stack_symbols.size(), stream_view};
203-
rmm::device_uvector<SymbolOffsetT> d_stack_op_indexes{stack_op_indexes.size(), stream_view};
201+
auto d_stack_ops = cudf::detail::make_device_buffer_async(
202+
stack_symbols, stream_view, cudf::get_current_device_resource_ref());
203+
auto d_stack_op_indexes = cudf::detail::make_device_buffer_async(
204+
stack_op_indexes, stream_view, cudf::get_current_device_resource_ref());
204205
cudf::detail::hostdevice_vector<SymbolT> top_of_stack_gpu{
205206
string_size, stream_view, cudf::get_current_device_resource_ref()};
206-
cudf::device_span<SymbolOffsetT> d_stack_op_idx_span{d_stack_op_indexes};
207-
208-
CUDF_CUDA_TRY(cudaMemcpyAsync(d_stack_ops.data(),
209-
stack_symbols.data(),
210-
stack_symbols.size() * sizeof(SymbolT),
211-
cudaMemcpyDefault,
212-
stream.get()));
213-
214-
CUDF_CUDA_TRY(cudaMemcpyAsync(d_stack_op_indexes.data(),
215-
stack_op_indexes.data(),
216-
stack_op_indexes.size() * sizeof(SymbolOffsetT),
217-
cudaMemcpyDefault,
218-
stream.get()));
219-
220207
// Run algorithm
221-
fst::sparse_stack_op_to_top_of_stack<fst::stack_op_support::NO_RESET_SUPPORT, StackLevelT>(
222-
d_stack_ops.data(),
223-
d_stack_op_idx_span,
224-
JSONToStackOp{},
225-
top_of_stack_gpu.device_ptr(),
226-
empty_stack_symbol,
227-
read_symbol,
228-
string_size,
229-
stream.get());
208+
fst::sparse_stack_op_to_top_of_stack<fst::stack_op_support::NO_RESET_SUPPORT,
209+
StackLevelT,
210+
SymbolT*,
211+
SymbolOffsetT>(d_stack_ops.data(),
212+
d_stack_op_indexes,
213+
JSONToStackOp{},
214+
top_of_stack_gpu.device_ptr(),
215+
empty_stack_symbol,
216+
read_symbol,
217+
string_size,
218+
stream.get());
230219

231220
// Async copy results from device to host
232221
top_of_stack_gpu.device_to_host_async(stream_view);

‎cpp/tests/io/json/json_tree_csr.cu‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <rmm/cuda_stream.hpp>
1818
#include <rmm/exec_policy.hpp>
1919

20+
#include <cuda/buffer>
2021
#include <cuda/stream>
2122
#include <thrust/sequence.h>
2223
#include <thrust/sort.h>
@@ -166,12 +167,12 @@ void run_test(std::string const& input, bool enable_lines = true)
166167
auto& gpu_row_offsets = std::get<1>(tup);
167168

168169
auto const num_nodes = gpu_col_id.size();
169-
rmm::device_uvector<cudf::size_type> sorted_col_ids(gpu_col_id.size(), stream); // make a copy
170-
thrust::copy(
171-
rmm::exec_policy_nosync(stream), gpu_col_id.begin(), gpu_col_id.end(), sorted_col_ids.begin());
170+
cuda::device_buffer<cudf::size_type> sorted_col_ids(
171+
stream, cudf::get_current_device_resource_ref(), gpu_col_id); // make a copy
172172

173173
// sort by {col_id} on {node_ids} stable
174-
rmm::device_uvector<cudf::size_type> node_ids(gpu_col_id.size(), stream);
174+
cuda::device_buffer<cudf::size_type> node_ids(
175+
stream, cudf::get_current_device_resource_ref(), gpu_col_id.size(), cuda::no_init);
175176
thrust::sequence(rmm::exec_policy_nosync(stream), node_ids.begin(), node_ids.end());
176177
thrust::stable_sort_by_key(rmm::exec_policy_nosync(stream),
177178
sorted_col_ids.begin(),

‎cpp/tests/io/json/nested_json_test.cpp‎

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <cudf_test/random.hpp>
1414
#include <cudf_test/testing_main.hpp>
1515

16+
#include <cudf/detail/utilities/buffer_factories.hpp>
17+
#include <cudf/detail/utilities/vector_factories.hpp>
1618
#include <cudf/io/json.hpp>
1719
#include <cudf/scalar/scalar.hpp>
1820
#include <cudf/utilities/default_stream.hpp>
@@ -635,10 +637,10 @@ TEST_F(JsonParserTest, ExtractColumn)
635637
cudf::io::json_reader_options default_options{};
636638

637639
std::string const input = R"( [{"a":0.0, "b":1.0}, {"a":0.1, "b":1.1}, {"a":0.2, "b":1.2}] )";
638-
auto const d_input = cudf::detail::make_device_uvector_async(
639-
cudf::host_span<char const>{input.c_str(), input.size()},
640-
stream,
641-
cudf::get_current_device_resource_ref());
640+
auto const d_input =
641+
cudf::detail::make_device_buffer_async(cudf::host_span<char const>{input.c_str(), input.size()},
642+
stream,
643+
cudf::get_current_device_resource_ref());
642644
// Get the JSON's tree representation
643645
auto const cudf_table = json_parser(d_input, default_options, stream, mr);
644646

@@ -843,12 +845,12 @@ TEST_F(JsonTest, PostProcessTokenStream)
843845
thrust::copy(input.cbegin(), input.cend(), token_tuples);
844846

845847
// Initialize device-side test data
846-
auto const d_offsets = cudf::detail::make_device_uvector_async(
848+
auto const d_offsets = cudf::detail::make_device_buffer_async(
847849
cudf::host_span<token_index_t const>{offsets.data(), offsets.size()},
848850
stream,
849851
cudf::get_current_device_resource_ref());
850-
auto const d_tokens = cudf::detail::make_device_uvector_async(
851-
tokens, stream, cudf::get_current_device_resource_ref());
852+
auto const d_tokens =
853+
cudf::detail::make_device_buffer_async(tokens, stream, cudf::get_current_device_resource_ref());
852854

853855
// Run system-under-test
854856
auto [d_filtered_tokens, d_filtered_indices] =
@@ -892,7 +894,7 @@ TEST_P(JsonDelimiterParamTest, UTF_JSON)
892894
{"a":1,"b":Infinity,"c":[null], "d": {"year":-600,"author": "Kaniyan"}}])";
893895
std::replace(ascii_pass.begin(), ascii_pass.end(), '\n', delimiter);
894896

895-
auto const d_ascii_pass = cudf::detail::make_device_uvector(
897+
auto const d_ascii_pass = cudf::detail::make_device_buffer(
896898
cudf::host_span<char const>{ascii_pass.c_str(), ascii_pass.size()},
897899
stream,
898900
cudf::get_current_device_resource_ref());
@@ -909,7 +911,7 @@ TEST_P(JsonDelimiterParamTest, UTF_JSON)
909911
{"a":1,"b":Infinity,"c":[null], "d": {"year":-600,"author": "filip ʒakotɛ"}}])";
910912
std::replace(utf_failed.begin(), utf_failed.end(), '\n', delimiter);
911913

912-
auto const d_utf_failed = cudf::detail::make_device_uvector(
914+
auto const d_utf_failed = cudf::detail::make_device_buffer(
913915
cudf::host_span<char const>{utf_failed.c_str(), utf_failed.size()},
914916
stream,
915917
cudf::get_current_device_resource_ref());
@@ -926,10 +928,10 @@ TEST_P(JsonDelimiterParamTest, UTF_JSON)
926928
{"a":1,"b":NaN,"c":[null, null], "d": {"year": 2, "author": "filip ʒakotɛ"}}])";
927929
std::replace(utf_pass.begin(), utf_pass.end(), '\n', delimiter);
928930

929-
auto const d_utf_pass = cudf::detail::make_device_uvector(
930-
cudf::host_span<char const>{utf_pass.c_str(), utf_pass.size()},
931-
stream,
932-
cudf::get_current_device_resource_ref());
931+
auto const d_utf_pass =
932+
cudf::detail::make_device_buffer(cudf::host_span<char const>{utf_pass.c_str(), utf_pass.size()},
933+
stream,
934+
cudf::get_current_device_resource_ref());
933935
CUDF_EXPECT_NO_THROW(json_parser(d_utf_pass, default_options, stream, mr));
934936
}
935937

@@ -947,10 +949,10 @@ TEST_F(JsonParserTest, ExtractColumnWithQuotes)
947949
options.enable_keep_quotes(true);
948950

949951
std::string const input = R"( [{"a":"0.0", "b":1.0}, {"b":1.1}, {"b":2.1, "a":"2.0"}] )";
950-
auto const d_input = cudf::detail::make_device_uvector_async(
951-
cudf::host_span<char const>{input.c_str(), input.size()},
952-
stream,
953-
cudf::get_current_device_resource_ref());
952+
auto const d_input =
953+
cudf::detail::make_device_buffer_async(cudf::host_span<char const>{input.c_str(), input.size()},
954+
stream,
955+
cudf::get_current_device_resource_ref());
954956
// Get the JSON's tree representation
955957
auto const cudf_table = json_parser(d_input, options, stream, mr);
956958

@@ -990,7 +992,7 @@ TEST_F(JsonParserTest, ExpectFailMixStructAndList)
990992

991993
// libcudf does not currently support a mix of lists and structs.
992994
for (auto const& input : inputs_fail) {
993-
auto const d_input = cudf::detail::make_device_uvector_async(
995+
auto const d_input = cudf::detail::make_device_buffer_async(
994996
cudf::host_span<char const>{input.c_str(), input.size()},
995997
stream,
996998
cudf::get_current_device_resource_ref());
@@ -999,7 +1001,7 @@ TEST_F(JsonParserTest, ExpectFailMixStructAndList)
9991001
}
10001002

10011003
for (auto const& input : inputs_succeed) {
1002-
auto const d_input = cudf::detail::make_device_uvector_async(
1004+
auto const d_input = cudf::detail::make_device_buffer_async(
10031005
cudf::host_span<char const>{input.c_str(), input.size()},
10041006
stream,
10051007
cudf::get_current_device_resource_ref());
@@ -1021,9 +1023,9 @@ TEST_F(JsonParserTest, EmptyString)
10211023

10221024
std::string const input = R"([])";
10231025
auto const d_input =
1024-
cudf::detail::make_device_uvector(cudf::host_span<char const>{input.c_str(), input.size()},
1025-
stream,
1026-
cudf::get_current_device_resource_ref());
1026+
cudf::detail::make_device_buffer(cudf::host_span<char const>{input.c_str(), input.size()},
1027+
stream,
1028+
cudf::get_current_device_resource_ref());
10271029
// Get the JSON's tree representation
10281030
auto const cudf_table = json_parser(d_input, default_options, stream, mr);
10291031

@@ -1410,9 +1412,9 @@ TEST_F(JsonTest, RejectsUnquotedValuesWithInvalidLeadingChar)
14101412
token_t::StructEnd,
14111413
token_t::LineEnd};
14121414
std::vector<cuio_json::SymbolOffsetT> token_indices{0, 0, 1, 3, 5, 6, 6, 6, 7};
1413-
auto d_tokens = cudf::detail::make_device_uvector_async(
1415+
auto d_tokens = cudf::detail::make_device_buffer_async(
14141416
tokens, stream, cudf::get_current_device_resource_ref());
1415-
auto d_token_indices = cudf::detail::make_device_uvector_async(
1417+
auto d_token_indices = cudf::detail::make_device_buffer_async(
14161418
token_indices, stream, cudf::get_current_device_resource_ref());
14171419

14181420
cuio_json::detail::validate_token_stream(d_input, d_tokens, d_token_indices, opts, stream);

‎cpp/tests/io/parquet_writer_test.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <cudf/column/column_factories.hpp>
1717
#include <cudf/copying.hpp>
18+
#include <cudf/detail/utilities/buffer_factories.hpp>
1819
#include <cudf/filling.hpp>
1920
#include <cudf/io/data_sink.hpp>
2021
#include <cudf/io/detail/codec.hpp>
@@ -242,7 +243,7 @@ TEST_F(ParquetWriterTest, BufferSource)
242243

243244
// device buffer
244245
{
245-
auto const d_input = cudf::detail::make_device_uvector(
246+
auto const d_input = cudf::detail::make_device_buffer(
246247
cudf::host_span<uint8_t const>{reinterpret_cast<uint8_t const*>(out_buffer.data()),
247248
out_buffer.size()},
248249
cudf::get_default_stream(),

0 commit comments

Comments
 (0)