|
| 1 | +/* |
| 2 | + * Copyright (c) 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 <benchmark_defaults.hpp> |
| 18 | +#include <benchmark_utils.hpp> |
| 19 | + |
| 20 | +#include <cuco/static_multiset.cuh> |
| 21 | +#include <cuco/utility/key_generator.cuh> |
| 22 | + |
| 23 | +#include <nvbench/nvbench.cuh> |
| 24 | + |
| 25 | +#include <thrust/device_vector.h> |
| 26 | +#include <thrust/transform.h> |
| 27 | + |
| 28 | +using namespace cuco::benchmark; |
| 29 | +using namespace cuco::utility; |
| 30 | + |
| 31 | +/** |
| 32 | + * @brief A benchmark evaluating `cuco::static_multiset::retrieve` performance |
| 33 | + */ |
| 34 | +template <typename Key, typename Dist> |
| 35 | +void static_multiset_retrieve(nvbench::state& state, nvbench::type_list<Key, Dist>) |
| 36 | +{ |
| 37 | + auto const num_keys = state.get_int64_or_default("NumInputs", defaults::N); |
| 38 | + auto const occupancy = state.get_float64_or_default("Occupancy", defaults::OCCUPANCY); |
| 39 | + auto const matching_rate = state.get_float64_or_default("MatchingRate", defaults::MATCHING_RATE); |
| 40 | + |
| 41 | + std::size_t const size = num_keys / occupancy; |
| 42 | + |
| 43 | + thrust::device_vector<Key> keys(num_keys); |
| 44 | + |
| 45 | + key_generator gen; |
| 46 | + gen.generate(dist_from_state<Dist>(state), keys.begin(), keys.end()); |
| 47 | + |
| 48 | + gen.dropout(keys.begin(), keys.end(), matching_rate); |
| 49 | + |
| 50 | + state.add_element_count(num_keys); |
| 51 | + |
| 52 | + cuco::static_multiset<Key> set{size, cuco::empty_key<Key>{-1}}; |
| 53 | + set.insert(keys.begin(), keys.end()); |
| 54 | + |
| 55 | + auto const output_size = set.count(keys.begin(), keys.end()); |
| 56 | + thrust::device_vector<Key> output_match(output_size); |
| 57 | + auto output_probe_begin = thrust::discard_iterator{}; |
| 58 | + |
| 59 | + state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) { |
| 60 | + set.retrieve( |
| 61 | + keys.begin(), keys.end(), output_probe_begin, output_match.begin(), {launch.get_stream()}); |
| 62 | + }); |
| 63 | +} |
| 64 | + |
| 65 | +NVBENCH_BENCH_TYPES(static_multiset_retrieve, |
| 66 | + NVBENCH_TYPE_AXES(defaults::KEY_TYPE_RANGE, |
| 67 | + nvbench::type_list<distribution::uniform>)) |
| 68 | + .set_name("static_multiset_retrieve_uniform_occupancy") |
| 69 | + .set_type_axes_names({"Key", "Distribution"}) |
| 70 | + .set_max_noise(defaults::MAX_NOISE) |
| 71 | + .add_float64_axis("Occupancy", defaults::OCCUPANCY_RANGE); |
| 72 | + |
| 73 | +NVBENCH_BENCH_TYPES(static_multiset_retrieve, |
| 74 | + NVBENCH_TYPE_AXES(defaults::KEY_TYPE_RANGE, |
| 75 | + nvbench::type_list<distribution::uniform>)) |
| 76 | + .set_name("static_multiset_retrieve_uniform_matching_rate") |
| 77 | + .set_type_axes_names({"Key", "Distribution"}) |
| 78 | + .set_max_noise(defaults::MAX_NOISE) |
| 79 | + .add_float64_axis("MatchingRate", defaults::MATCHING_RATE_RANGE); |
| 80 | + |
| 81 | +NVBENCH_BENCH_TYPES(static_multiset_retrieve, |
| 82 | + NVBENCH_TYPE_AXES(defaults::KEY_TYPE_RANGE, |
| 83 | + nvbench::type_list<distribution::uniform>)) |
| 84 | + .set_name("static_multiset_retrieve_uniform_multiplicity") |
| 85 | + .set_type_axes_names({"Key", "Distribution"}) |
| 86 | + .set_max_noise(defaults::MAX_NOISE) |
| 87 | + .add_int64_axis("Multiplicity", defaults::MULTIPLICITY_RANGE); |
0 commit comments