|
| 1 | +/* |
| 2 | + * Copyright (c) 2021-2024, NVIDIA CORPORATION. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <benchmarks/common/generate_input.hpp> |
| 18 | + |
| 19 | +#include <cudf/column/column_factories.hpp> |
| 20 | +#include <cudf/strings/detail/utilities.hpp> |
| 21 | +#include <cudf/strings/string_view.cuh> |
| 22 | +#include <cudf/strings/strings_column_view.hpp> |
| 23 | +#include <cudf/utilities/default_stream.hpp> |
| 24 | + |
| 25 | +#include <rmm/device_uvector.hpp> |
| 26 | + |
| 27 | +#include <nvbench/nvbench.cuh> |
| 28 | + |
| 29 | +#include <limits> |
| 30 | + |
| 31 | +static void bench_factory(nvbench::state& state) |
| 32 | +{ |
| 33 | + auto const num_rows = static_cast<cudf::size_type>(state.get_int64("num_rows")); |
| 34 | + auto const min_width = static_cast<cudf::size_type>(state.get_int64("min_width")); |
| 35 | + auto const max_width = static_cast<cudf::size_type>(state.get_int64("max_width")); |
| 36 | + |
| 37 | + data_profile const profile = data_profile_builder().distribution( |
| 38 | + cudf::type_id::STRING, distribution_id::NORMAL, min_width, max_width); |
| 39 | + auto const column = create_random_column(cudf::type_id::STRING, row_count{num_rows}, profile); |
| 40 | + auto const sv = cudf::strings_column_view(column->view()); |
| 41 | + |
| 42 | + auto stream = cudf::get_default_stream(); |
| 43 | + auto mr = cudf::get_current_device_resource_ref(); |
| 44 | + auto d_strings = cudf::strings::detail::create_string_vector_from_column(sv, stream, mr); |
| 45 | + |
| 46 | + state.set_cuda_stream(nvbench::make_cuda_stream_view(stream.value())); |
| 47 | + auto chars_size = sv.chars_size(stream); |
| 48 | + state.add_global_memory_reads<nvbench::int8_t>(chars_size); |
| 49 | + state.add_global_memory_writes<nvbench::int8_t>(chars_size); |
| 50 | + |
| 51 | + state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) { |
| 52 | + cudf::make_strings_column(d_strings, cudf::string_view{nullptr, 0}); |
| 53 | + }); |
| 54 | +} |
| 55 | + |
| 56 | +NVBENCH_BENCH(bench_factory) |
| 57 | + .set_name("factory") |
| 58 | + .add_int64_axis("min_width", {0}) |
| 59 | + .add_int64_axis("max_width", {32, 64, 128, 256}) |
| 60 | + .add_int64_axis("num_rows", {32768, 262144, 2097152}); |
0 commit comments