Skip to content

Commit 5625009

Browse files
authored
Update strings benchmarks to use alloc_size column/table function (#18822)
Fixes the strings benchmarks to use `alloc_size()` member function instead of `chars_size()` which did not account for reading the offsets or the bitmask. Reference #13735 Authors: - David Wendt (https://github.com/davidwendt) Approvers: - Vukasin Milovanovic (https://github.com/vuule) - Nghia Truong (https://github.com/ttnghia) URL: #18822
1 parent 92b1013 commit 5625009

29 files changed

+112
-127
lines changed

cpp/benchmarks/string/case.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2021-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@ void bench_case(nvbench::state& state)
3434
auto const column = create_random_column(cudf::type_id::STRING, row_count{num_rows}, profile);
3535

3636
auto col_view = column->view();
37+
auto col_size = column->alloc_size();
3738

3839
cudf::column::contents ascii_contents;
3940
if (encoding == "ascii") {
@@ -46,23 +47,22 @@ void bench_case(nvbench::state& state)
4647
ascii_profile);
4748
auto ascii_data = ascii_column->view();
4849

49-
col_view = cudf::column_view(col_view.type(),
50+
col_view = cudf::column_view(col_view.type(),
5051
col_view.size(),
5152
ascii_data.data<char>(),
5253
col_view.null_mask(),
5354
col_view.null_count(),
5455
0,
55-
{input.offsets()});
56-
56+
{input.offsets()});
57+
col_size = ascii_column->alloc_size();
5758
ascii_contents = ascii_column->release();
5859
}
5960
auto input = cudf::strings_column_view(col_view);
6061

6162
state.set_cuda_stream(nvbench::make_cuda_stream_view(cudf::get_default_stream().value()));
6263

63-
state.add_element_count(input.chars_size(cudf::get_default_stream()), "chars_size");
64-
state.add_global_memory_reads<nvbench::int8_t>(input.chars_size(cudf::get_default_stream()));
65-
state.add_global_memory_writes<nvbench::int8_t>(input.chars_size(cudf::get_default_stream()));
64+
state.add_global_memory_reads<nvbench::int8_t>(col_size);
65+
state.add_global_memory_writes<nvbench::int8_t>(col_size);
6666

6767
state.exec(nvbench::exec_tag::sync,
6868
[&](nvbench::launch& launch) { auto result = cudf::strings::to_lower(input); });

cpp/benchmarks/string/char_types.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,12 +38,12 @@ static void bench_char_types(nvbench::state& state)
3838

3939
state.set_cuda_stream(nvbench::make_cuda_stream_view(cudf::get_default_stream().value()));
4040
// gather some throughput statistics as well
41-
auto chars_size = input.chars_size(cudf::get_default_stream());
42-
state.add_global_memory_reads<nvbench::int8_t>(chars_size); // all bytes are read;
41+
auto data_size = table->alloc_size();
42+
state.add_global_memory_reads<nvbench::int8_t>(data_size); // all bytes are read;
4343
if (api_type == "all") {
4444
state.add_global_memory_writes<nvbench::int8_t>(num_rows); // output is a bool8 per row
4545
} else {
46-
state.add_global_memory_writes<nvbench::int8_t>(chars_size);
46+
state.add_global_memory_writes<nvbench::int8_t>(data_size);
4747
}
4848

4949
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {

cpp/benchmarks/string/combine.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2021-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,10 +38,9 @@ static void bench_combine(nvbench::state& state)
3838

3939
auto stream = cudf::get_default_stream();
4040
state.set_cuda_stream(nvbench::make_cuda_stream_view(stream.value()));
41-
auto chars_size =
42-
input1.chars_size(stream) + input2.chars_size(stream) + (num_rows * separator.size());
43-
state.add_global_memory_reads<nvbench::int8_t>(chars_size); // all bytes are read;
44-
state.add_global_memory_writes<nvbench::int8_t>(chars_size);
41+
auto const data_size = table->alloc_size();
42+
state.add_global_memory_reads<nvbench::int8_t>(data_size); // all bytes are read;
43+
state.add_global_memory_writes<nvbench::int8_t>(data_size + (num_rows * separator.size()));
4544

4645
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
4746
auto result = cudf::strings::concatenate(table->view(), separator);

cpp/benchmarks/string/contains.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2021-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,9 +40,7 @@ static void bench_contains(nvbench::state& state)
4040
auto pattern = patterns[pattern_index];
4141
auto program = cudf::strings::regex_program::create(pattern);
4242

43-
auto chars_size = input.chars_size(cudf::get_default_stream());
44-
state.add_element_count(chars_size, "chars_size");
45-
state.add_global_memory_reads<nvbench::int8_t>(chars_size);
43+
state.add_global_memory_reads<nvbench::int8_t>(col->alloc_size());
4644
state.add_global_memory_writes<nvbench::int32_t>(input.size());
4745

4846
state.exec(nvbench::exec_tag::sync,

cpp/benchmarks/string/convert_datetime.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2021-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,12 +54,12 @@ void bench_convert_datetime(nvbench::state& state, nvbench::type_list<DataType>)
5454

5555
if (from_ts) {
5656
state.add_global_memory_reads<DataType>(num_rows);
57-
state.add_global_memory_writes<int8_t>(sv.chars_size(stream));
57+
state.add_global_memory_writes<int8_t>(s_col->alloc_size());
5858
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
5959
cudf::strings::from_timestamps(ts_col->view(), format);
6060
});
6161
} else {
62-
state.add_global_memory_reads<int8_t>(sv.chars_size(stream));
62+
state.add_global_memory_reads<int8_t>(s_col->alloc_size());
6363
state.add_global_memory_writes<DataType>(num_rows);
6464
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
6565
cudf::strings::to_timestamps(sv, data_type, format);

cpp/benchmarks/string/convert_durations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,7 +58,7 @@ void bench_convert_duration(nvbench::state& state, nvbench::type_list<DataType>)
5858
} else {
5959
auto source = cudf::strings::from_durations(input, format);
6060
auto view = cudf::strings_column_view(source->view());
61-
state.add_global_memory_reads<int8_t>(view.chars_size(stream));
61+
state.add_global_memory_reads<int8_t>(source->alloc_size());
6262
state.add_global_memory_writes<DataType>(num_rows);
6363
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
6464
cudf::strings::to_durations(view, data_type, format);

cpp/benchmarks/string/convert_fixed_point.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2021-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,11 +45,11 @@ void bench_convert_fixed_point(nvbench::state& state, nvbench::type_list<DataTyp
4545

4646
if (from_num) {
4747
state.add_global_memory_reads<int8_t>(num_rows * cudf::size_of(data_type));
48-
state.add_global_memory_writes<int8_t>(sv.chars_size(stream));
48+
state.add_global_memory_writes<int8_t>(strings_col->alloc_size());
4949
state.exec(nvbench::exec_tag::sync,
5050
[&](nvbench::launch& launch) { cudf::strings::to_fixed_point(sv, data_type); });
5151
} else {
52-
state.add_global_memory_reads<int8_t>(sv.chars_size(stream));
52+
state.add_global_memory_reads<int8_t>(strings_col->alloc_size());
5353
state.add_global_memory_writes<int8_t>(num_rows * cudf::size_of(data_type));
5454
state.exec(nvbench::exec_tag::sync,
5555
[&](nvbench::launch& launch) { cudf::strings::from_fixed_point(fp_col->view()); });

cpp/benchmarks/string/convert_numerics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2021-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ void bench_convert_number(nvbench::state& state, nvbench::type_list<NumericType>
5555

5656
if (from_num) {
5757
state.add_global_memory_reads<NumericType>(num_rows);
58-
state.add_global_memory_writes<int8_t>(sv.chars_size(stream));
58+
state.add_global_memory_writes<int8_t>(strings_col->alloc_size());
5959
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
6060
if constexpr (std::is_floating_point_v<NumericType>) {
6161
cudf::strings::to_floats(sv, data_type);
@@ -64,7 +64,7 @@ void bench_convert_number(nvbench::state& state, nvbench::type_list<NumericType>
6464
}
6565
});
6666
} else {
67-
state.add_global_memory_reads<int8_t>(sv.chars_size(stream));
67+
state.add_global_memory_reads<int8_t>(strings_col->alloc_size());
6868
state.add_global_memory_writes<NumericType>(num_rows);
6969
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
7070
if constexpr (std::is_floating_point_v<NumericType>)

cpp/benchmarks/string/copy.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,21 +46,21 @@ static void bench_copy(nvbench::state& state)
4646
if (api == "gather") {
4747
auto result =
4848
cudf::gather(source->view(), map_view, cudf::out_of_bounds_policy::NULLIFY, stream);
49-
auto chars_size = cudf::strings_column_view(result->view().column(0)).chars_size(stream);
50-
state.add_global_memory_reads<nvbench::int8_t>(chars_size +
49+
auto data_size = result->alloc_size();
50+
state.add_global_memory_reads<nvbench::int8_t>(data_size +
5151
(map_view.size() * sizeof(cudf::size_type)));
52-
state.add_global_memory_writes<nvbench::int8_t>(chars_size);
52+
state.add_global_memory_writes<nvbench::int8_t>(data_size);
5353
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
5454
cudf::gather(source->view(), map_view, cudf::out_of_bounds_policy::NULLIFY, stream);
5555
});
5656
} else if (api == "scatter") {
5757
auto const target =
5858
create_random_table({cudf::type_id::STRING}, row_count{num_rows}, table_profile);
59-
auto result = cudf::scatter(source->view(), map_view, target->view(), stream);
60-
auto chars_size = cudf::strings_column_view(result->view().column(0)).chars_size(stream);
61-
state.add_global_memory_reads<nvbench::int8_t>(chars_size +
59+
auto result = cudf::scatter(source->view(), map_view, target->view(), stream);
60+
auto data_size = result->alloc_size();
61+
state.add_global_memory_reads<nvbench::int8_t>(data_size +
6262
(map_view.size() * sizeof(cudf::size_type)));
63-
state.add_global_memory_writes<nvbench::int8_t>(chars_size);
63+
state.add_global_memory_writes<nvbench::int8_t>(data_size);
6464
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
6565
cudf::scatter(source->view(), map_view, target->view(), stream);
6666
});

cpp/benchmarks/string/copy_if_else.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,9 +43,9 @@ static void bench_copy(nvbench::state& state)
4343
auto const left_right = booleans->view().column(0);
4444

4545
state.set_cuda_stream(nvbench::make_cuda_stream_view(cudf::get_default_stream().value()));
46-
auto chars_size = cudf::strings_column_view(target).chars_size(cudf::get_default_stream());
47-
state.add_global_memory_reads<nvbench::int8_t>(chars_size); // all bytes are read;
48-
state.add_global_memory_writes<nvbench::int8_t>(chars_size); // both columns are similar size
46+
auto data_size = target_table->alloc_size();
47+
state.add_global_memory_reads<nvbench::int8_t>(data_size); // all bytes are read;
48+
state.add_global_memory_writes<nvbench::int8_t>(data_size); // both columns are similar size
4949

5050
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
5151
[[maybe_unused]] auto result = cudf::copy_if_else(source, target, left_right);

0 commit comments

Comments
 (0)