Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move strings filter benchmarks to nvbench #17269

Merged
merged 7 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cpp/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ ConfigureNVBench(
# ##################################################################################################
# * strings benchmark -------------------------------------------------------------------
ConfigureBench(
STRINGS_BENCH string/factory.cu string/filter.cpp string/repeat_strings.cpp string/replace.cpp
string/translate.cpp string/url_decode.cu
STRINGS_BENCH string/factory.cu string/repeat_strings.cpp string/replace.cpp string/translate.cpp
string/url_decode.cu
)

ConfigureNVBench(
Expand All @@ -374,6 +374,7 @@ ConfigureNVBench(
string/copy_range.cpp
string/count.cpp
string/extract.cpp
string/filter.cpp
string/find.cpp
string/join_strings.cpp
string/lengths.cpp
Expand Down
95 changes: 45 additions & 50 deletions cpp/benchmarks/string/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@
* limitations under the License.
*/

#include "string_bench_args.hpp"

#include <benchmarks/common/generate_input.hpp>
#include <benchmarks/fixture/benchmark_fixture.hpp>
#include <benchmarks/synchronization/synchronization.hpp>

#include <cudf_test/column_wrapper.hpp>

#include <cudf/scalar/scalar.hpp>
#include <cudf/strings/char_types/char_types.hpp>
Expand All @@ -29,57 +23,58 @@
#include <cudf/strings/translate.hpp>
#include <cudf/utilities/default_stream.hpp>

#include <vector>

enum FilterAPI { filter, filter_chars, strip };
#include <nvbench/nvbench.cuh>

class StringFilterChars : public cudf::benchmark {};
#include <vector>

static void BM_filter_chars(benchmark::State& state, FilterAPI api)
static void bench_filter(nvbench::state& state)
{
cudf::size_type const n_rows{static_cast<cudf::size_type>(state.range(0))};
cudf::size_type const max_str_length{static_cast<cudf::size_type>(state.range(1))};
auto const num_rows = static_cast<cudf::size_type>(state.get_int64("num_rows"));
auto const min_width = static_cast<cudf::size_type>(state.get_int64("min_width"));
auto const max_width = static_cast<cudf::size_type>(state.get_int64("max_width"));
auto const api = state.get_string("api");

data_profile const profile = data_profile_builder().distribution(
cudf::type_id::STRING, distribution_id::NORMAL, 0, max_str_length);
auto const column = create_random_column(cudf::type_id::STRING, row_count{n_rows}, profile);
cudf::strings_column_view input(column->view());
cudf::type_id::STRING, distribution_id::NORMAL, min_width, max_width);
auto const column = create_random_column(cudf::type_id::STRING, row_count{num_rows}, profile);
auto const input = cudf::strings_column_view(column->view());

auto const types = cudf::strings::string_character_types::SPACE;
std::vector<std::pair<cudf::char_utf8, cudf::char_utf8>> filter_table{
{cudf::char_utf8{'a'}, cudf::char_utf8{'c'}}};
auto stream = cudf::get_default_stream();
state.set_cuda_stream(nvbench::make_cuda_stream_view(stream.value()));
auto chars_size = input.chars_size(stream);
state.add_global_memory_reads<nvbench::int8_t>(chars_size);

for (auto _ : state) {
cuda_event_timer raii(state, true, cudf::get_default_stream());
switch (api) {
case filter: cudf::strings::filter_characters_of_type(input, types); break;
case filter_chars: cudf::strings::filter_characters(input, filter_table); break;
case strip: cudf::strings::strip(input); break;
if (api == "filter") {
auto const types = cudf::strings::string_character_types::SPACE;
{
auto result = cudf::strings::filter_characters_of_type(input, types);
auto sv = cudf::strings_column_view(result->view());
state.add_global_memory_writes<nvbench::int8_t>(sv.chars_size(stream));
}
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
cudf::strings::filter_characters_of_type(input, types);
});
} else if (api == "chars") {
state.add_global_memory_writes<nvbench::int8_t>(chars_size);
std::vector<std::pair<cudf::char_utf8, cudf::char_utf8>> filter_table{
{cudf::char_utf8{'a'}, cudf::char_utf8{'c'}}};
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
cudf::strings::filter_characters(input, filter_table);
});
} else if (api == "strip") {
{
auto result = cudf::strings::strip(input);
auto sv = cudf::strings_column_view(result->view());
state.add_global_memory_writes<nvbench::int8_t>(sv.chars_size(stream));
}
state.exec(nvbench::exec_tag::sync,
[&](nvbench::launch& launch) { cudf::strings::strip(input); });
}

state.SetBytesProcessed(state.iterations() * input.chars_size(cudf::get_default_stream()));
}

static void generate_bench_args(benchmark::internal::Benchmark* b)
{
int const min_rows = 1 << 12;
int const max_rows = 1 << 24;
int const row_multiplier = 8;
int const min_length = 1 << 5;
int const max_length = 1 << 13;
int const length_multiplier = 2;
generate_string_bench_args(
b, min_rows, max_rows, row_multiplier, min_length, max_length, length_multiplier);
}

#define STRINGS_BENCHMARK_DEFINE(name) \
BENCHMARK_DEFINE_F(StringFilterChars, name) \
(::benchmark::State & st) { BM_filter_chars(st, FilterAPI::name); } \
BENCHMARK_REGISTER_F(StringFilterChars, name) \
->Apply(generate_bench_args) \
->UseManualTime() \
->Unit(benchmark::kMillisecond);

STRINGS_BENCHMARK_DEFINE(filter)
STRINGS_BENCHMARK_DEFINE(filter_chars)
STRINGS_BENCHMARK_DEFINE(strip)
NVBENCH_BENCH(bench_filter)
.set_name("filter")
.add_int64_axis("min_width", {0})
.add_int64_axis("max_width", {32, 64, 128, 256})
.add_int64_axis("num_rows", {32768, 262144, 2097152})
.add_string_axis("api", {"filter", "chars", "strip"});
Loading