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

Add chars-tokenizer to nvtext tokenize_benchmark.cpp #8125

Merged
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
17 changes: 14 additions & 3 deletions cpp/benchmarks/text/tokenize_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class TextTokenize : public cudf::benchmark {
};

enum class tokenize_type { single, multi, count, count_multi, ngrams };
enum class tokenize_type { single, multi, count, count_multi, ngrams, characters };

static void BM_tokenize(benchmark::State& state, tokenize_type tt)
{
Expand All @@ -48,18 +48,28 @@ static void BM_tokenize(benchmark::State& state, tokenize_type tt)
for (auto _ : state) {
cuda_event_timer raii(state, true, rmm::cuda_stream_default);
switch (tt) {
case tokenize_type::single: nvtext::tokenize(input); break;
case tokenize_type::single:
// single whitespace delimiter
nvtext::tokenize(input);
break;
case tokenize_type::multi:
nvtext::tokenize(input, cudf::strings_column_view(delimiters));
break;
case tokenize_type::count: nvtext::count_tokens(input); break;
case tokenize_type::count:
// single whitespace delimiter
nvtext::count_tokens(input);
break;
case tokenize_type::count_multi:
nvtext::count_tokens(input, cudf::strings_column_view(delimiters));
break;
case tokenize_type::ngrams:
// default is bigrams
nvtext::ngrams_tokenize(input);
break;
case tokenize_type::characters:
// every character becomes a string
nvtext::character_tokenize(input);
break;
}
}

Expand Down Expand Up @@ -90,3 +100,4 @@ NVTEXT_BENCHMARK_DEFINE(multi)
NVTEXT_BENCHMARK_DEFINE(count)
NVTEXT_BENCHMARK_DEFINE(count_multi)
NVTEXT_BENCHMARK_DEFINE(ngrams)
NVTEXT_BENCHMARK_DEFINE(characters)
1 change: 0 additions & 1 deletion cpp/src/text/tokenize.cu
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ std::unique_ptr<cudf::column> character_tokenize(cudf::strings_column_view const
// To minimize memory, count the number of characters so we can
// build the output offsets without an intermediate buffer.
// In the worst case each byte is a character so the output is 4x the input.
auto strings_view = cudf::column_device_view::create(strings_column.parent(), stream);
cudf::size_type num_characters = thrust::count_if(
rmm::exec_policy(stream), d_chars, d_chars + chars_bytes, [] __device__(uint8_t byte) {
return cudf::strings::detail::is_begin_utf8_char(byte);
Expand Down