-
Notifications
You must be signed in to change notification settings - Fork 915
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 gbenchmark for nvtext replace-tokens function #7708
Merged
rapids-bot
merged 1 commit into
rapidsai:branch-0.19
from
davidwendt:benchmark-nvtext-replace
Mar 26, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,85 @@ | ||
/* | ||
* Copyright (c) 2021, 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 <benchmark/benchmark.h> | ||
#include <benchmarks/fixture/benchmark_fixture.hpp> | ||
#include <benchmarks/string/string_bench_args.hpp> | ||
#include <benchmarks/synchronization/synchronization.hpp> | ||
|
||
#include <cudf/strings/strings_column_view.hpp> | ||
#include <cudf_test/base_fixture.hpp> | ||
#include <cudf_test/column_wrapper.hpp> | ||
|
||
#include <nvtext/replace.hpp> | ||
|
||
class TextReplace : public cudf::benchmark { | ||
}; | ||
|
||
static void BM_replace(benchmark::State& state) | ||
{ | ||
auto const n_rows = static_cast<cudf::size_type>(state.range(0)); | ||
auto const n_length = static_cast<cudf::size_type>(state.range(1)); | ||
|
||
std::vector<std::string> words{" ", "one ", "two ", "three ", "four ", | ||
"five ", "six ", "sevén ", "eight ", "nine ", | ||
"ten ", "eleven ", "twelve ", "thirteen ", "fourteen ", | ||
"fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen "}; | ||
|
||
std::default_random_engine generator; | ||
std::uniform_int_distribution<int> tokens_dist(0, words.size() - 1); | ||
std::string row; // build a row of random tokens | ||
while (static_cast<int>(row.size()) < n_length) row += words[tokens_dist(generator)]; | ||
|
||
std::uniform_int_distribution<int> position_dist(0, 16); | ||
|
||
auto elements = cudf::detail::make_counting_transform_iterator( | ||
0, [&](auto idx) { return row.c_str() + position_dist(generator); }); | ||
cudf::test::strings_column_wrapper input(elements, elements + n_rows); | ||
cudf::strings_column_view view(input); | ||
|
||
cudf::test::strings_column_wrapper targets({"one", "two", "sevén", "zero"}); | ||
cudf::test::strings_column_wrapper replacements({"1", "2", "7", "0"}); | ||
|
||
for (auto _ : state) { | ||
cuda_event_timer raii(state, true, 0); | ||
nvtext::replace_tokens( | ||
view, cudf::strings_column_view(targets), cudf::strings_column_view(replacements)); | ||
} | ||
|
||
state.SetBytesProcessed(state.iterations() * view.chars_size()); | ||
} | ||
|
||
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_row_length = 1 << 5; | ||
int const max_row_length = 1 << 13; | ||
int const length_multiplier = 4; | ||
generate_string_bench_args( | ||
b, min_rows, max_rows, row_multiplier, min_row_length, max_row_length, length_multiplier); | ||
} | ||
|
||
#define NVTEXT_BENCHMARK_DEFINE(name) \ | ||
BENCHMARK_DEFINE_F(TextReplace, name) \ | ||
(::benchmark::State & st) { BM_replace(st); } \ | ||
BENCHMARK_REGISTER_F(TextReplace, name) \ | ||
->Apply(generate_bench_args) \ | ||
->UseManualTime() \ | ||
->Unit(benchmark::kMillisecond); | ||
|
||
NVTEXT_BENCHMARK_DEFINE(replace) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious, why
16
? Is this a good size test? Do we need to benchmark if each string is of size around1000
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an arbitrary power of two number less than 32 to force some amount of warp divergence.
This benchmark tests with string lengths ranging from 32 to 8K and also some row sizes between 4K to 16M (within limits of column size boundaries).