-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance of copy_if_else for long strings (#15017)
Reworks the `cudf::strings::detail::copy_if_else()` to improve performance for long strings. The rework builds a vector of rows to pass to the `make_strings_column` factory that uses the optimized `gather_chars` function. Also includes a benchmark for copy_if_else specifically for strings columns. Closes #15014 Authors: - David Wendt (https://github.com/davidwendt) Approvers: - Bradley Dice (https://github.com/bdice) - Vukasin Milovanovic (https://github.com/vuule) URL: #15017
- Loading branch information
1 parent
825d30c
commit f43f7c5
Showing
3 changed files
with
84 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2024, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <benchmarks/common/generate_input.hpp> | ||
|
||
#include <cudf/copying.hpp> | ||
#include <cudf/strings/strings_column_view.hpp> | ||
#include <cudf/utilities/default_stream.hpp> | ||
|
||
#include <nvbench/nvbench.cuh> | ||
|
||
static void bench_copy(nvbench::state& state) | ||
{ | ||
auto const num_rows = static_cast<cudf::size_type>(state.get_int64("num_rows")); | ||
auto const row_width = static_cast<cudf::size_type>(state.get_int64("row_width")); | ||
|
||
if (static_cast<std::size_t>(num_rows) * static_cast<std::size_t>(row_width) >= | ||
static_cast<std::size_t>(std::numeric_limits<cudf::size_type>::max())) { | ||
state.skip("Skip benchmarks greater than size_type limit"); | ||
} | ||
|
||
data_profile const str_profile = data_profile_builder().distribution( | ||
cudf::type_id::STRING, distribution_id::NORMAL, 0, row_width); | ||
auto const source_table = | ||
create_random_table({cudf::type_id::STRING}, row_count{num_rows}, str_profile); | ||
auto const target_table = | ||
create_random_table({cudf::type_id::STRING}, row_count{num_rows}, str_profile); | ||
data_profile const bool_profile = data_profile_builder().no_validity(); | ||
auto const booleans = | ||
create_random_table({cudf::type_id::BOOL8}, row_count{num_rows}, bool_profile); | ||
|
||
auto const source = source_table->view().column(0); | ||
auto const target = target_table->view().column(0); | ||
auto const left_right = booleans->view().column(0); | ||
|
||
state.set_cuda_stream(nvbench::make_cuda_stream_view(cudf::get_default_stream().value())); | ||
auto chars_size = cudf::strings_column_view(target).chars_size(cudf::get_default_stream()); | ||
state.add_global_memory_reads<nvbench::int8_t>(chars_size); // all bytes are read; | ||
state.add_global_memory_writes<nvbench::int8_t>(chars_size); // both columns are similar size | ||
|
||
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) { | ||
[[maybe_unused]] auto result = cudf::copy_if_else(source, target, left_right); | ||
}); | ||
} | ||
|
||
NVBENCH_BENCH(bench_copy) | ||
.set_name("copy_if_else") | ||
.add_int64_axis("row_width", {32, 64, 128, 256, 512, 1024, 2048, 4096}) | ||
.add_int64_axis("num_rows", {4096, 32768, 262144, 2097152, 16777216}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters