-
Notifications
You must be signed in to change notification settings - Fork 100
Trie #350
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
Draft
amukkara
wants to merge
41
commits into
NVIDIA:dev
Choose a base branch
from
amukkara:trie
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Trie #350
Changes from 33 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
85de9c2
Trie checkin
amukkara c724f61
Coding style
amukkara ac5af70
Change template parameter name
amukkara ffdde23
Includes
amukkara 18e9501
Misc coding style changes
amukkara c5c1ec5
Remove bitvector template parameter
amukkara 152f716
Remove some host-side structures
amukkara 643ba31
bit_vector -> dynamic_bitset
amukkara 53b2ba4
dynamic_bitset API change
amukkara fdca1c2
Template variable naming style
amukkara 10f1b05
Minor
amukkara 748c1ea
Add allocator template parameter
amukkara d2e339b
Misc coding style
amukkara 74effe6
Comments
amukkara c6d300f
Run a dummy test() on bitsets
amukkara c57e491
Use allocator for member classes
amukkara 4e4a08f
Buffer bitset updates on host
amukkara 6a8af91
Minor changes in lookup test
amukkara 248d71f
Use iterators as parameters to insert()
amukkara 25eaa9d
Move key generation utilities into different file
amukkara 2753a38
Limit grid size to 128
amukkara 01c35df
Add performance test
amukkara 7151733
Store labels in host vector during insertions
amukkara 9f7d6d3
Parallelize input preprocessing
amukkara 342bcee
Move dynamic_bitset tests into tests/trie
amukkara 81f9d46
Consolidate trie utils in a single file
amukkara 03821ef
find_next host-bulk API in dynamic_bitset
amukkara f70d528
Dynamic bitset benchmarks
amukkara bd4549e
Consistent use of LabelType
amukkara 5f67117
Trie benchmarks
amukkara 660bdc0
Reorganize trie utils
amukkara 6f2b0b8
Use cuco key generators
amukkara 799d968
Add key length and key count nvbench axes
amukkara 025c59a
Add namespaces
amukkara 6184e50
Remove custom key comparator
amukkara 7f1d083
Include multiple label types
amukkara 5ed0498
Change key distribution to uniform
amukkara 6842144
Move file
amukkara 4dcb7ce
Delete file read utilities
amukkara 9892378
Change nvbench axes order
amukkara fc3fa7a
Trie examples
amukkara 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 hidden or 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 hidden or 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,62 @@ | ||
| /* | ||
| * Copyright (c) 2023, 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 <defaults.hpp> | ||
| #include <utils.hpp> | ||
|
|
||
| #include <cuco/detail/trie/dynamic_bitset/dynamic_bitset.cuh> | ||
| #include <cuco/utility/key_generator.hpp> | ||
|
|
||
| #include <nvbench/nvbench.cuh> | ||
|
|
||
| #include <thrust/host_vector.h> | ||
|
|
||
| using namespace cuco::benchmark; | ||
| using namespace cuco::utility; | ||
|
|
||
| /** | ||
| * @brief A benchmark evaluating `cuco::experimental::detail::dynamic_bitset::find_next` performance | ||
| */ | ||
| template <typename Dist> | ||
| void dynamic_bitset_find_next(nvbench::state& state, nvbench::type_list<Dist>) | ||
| { | ||
| auto const num_bits = state.get_int64_or_default("NumInputs", defaults::N); | ||
| using word_type = typename cuco::experimental::detail::dynamic_bitset<>::word_type; | ||
| auto const bits_per_word = cuco::experimental::detail::dynamic_bitset<>::bits_per_word; | ||
| thrust::host_vector<word_type> keys((num_bits - 1) / bits_per_word + 1); | ||
|
|
||
| key_generator gen; | ||
| gen.generate(dist_from_state<Dist>(state), keys.begin(), keys.end()); | ||
|
|
||
| cuco::experimental::detail::dynamic_bitset bitset; | ||
| bitset.insert(keys.begin(), keys.end(), num_bits); | ||
|
|
||
| const size_t query_size = min(1000 * 1000lu, num_bits / 10); | ||
| thrust::device_vector<size_t> inputs(query_size); | ||
| thrust::sequence(inputs.begin(), inputs.end(), 0); | ||
| thrust::device_vector<size_t> outputs(query_size); | ||
|
|
||
| state.add_element_count(query_size); | ||
| state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) { | ||
| bitset.find_next(inputs.begin(), inputs.end(), outputs.begin()); | ||
| }); | ||
| } | ||
|
|
||
| NVBENCH_BENCH_TYPES(dynamic_bitset_find_next, | ||
| NVBENCH_TYPE_AXES(nvbench::type_list<distribution::gaussian>)) | ||
| .set_name("dynamic_bitset_find_next") | ||
| .set_type_axes_names({"Distribution"}) | ||
| .set_max_noise(defaults::MAX_NOISE); | ||
This file contains hidden or 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,62 @@ | ||
| /* | ||
| * Copyright (c) 2023, 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 <defaults.hpp> | ||
| #include <utils.hpp> | ||
|
|
||
| #include <cuco/detail/trie/dynamic_bitset/dynamic_bitset.cuh> | ||
| #include <cuco/utility/key_generator.hpp> | ||
|
|
||
| #include <nvbench/nvbench.cuh> | ||
|
|
||
| #include <thrust/host_vector.h> | ||
|
|
||
| using namespace cuco::benchmark; | ||
| using namespace cuco::utility; | ||
|
|
||
| /** | ||
| * @brief A benchmark evaluating `cuco::experimental::detail::dynamic_bitset::rank` performance | ||
| */ | ||
| template <typename Dist> | ||
| void dynamic_bitset_rank(nvbench::state& state, nvbench::type_list<Dist>) | ||
| { | ||
| auto const num_bits = state.get_int64_or_default("NumInputs", defaults::N); | ||
| using word_type = typename cuco::experimental::detail::dynamic_bitset<>::word_type; | ||
| auto const bits_per_word = cuco::experimental::detail::dynamic_bitset<>::bits_per_word; | ||
| thrust::host_vector<word_type> keys((num_bits - 1) / bits_per_word + 1); | ||
|
|
||
| key_generator gen; | ||
| gen.generate(dist_from_state<Dist>(state), keys.begin(), keys.end()); | ||
|
|
||
| cuco::experimental::detail::dynamic_bitset bitset; | ||
| bitset.insert(keys.begin(), keys.end(), num_bits); | ||
|
|
||
| const size_t query_size = min(1000 * 1000lu, num_bits / 10); | ||
| thrust::device_vector<size_t> inputs(query_size); | ||
| thrust::sequence(inputs.begin(), inputs.end(), 0); | ||
| thrust::device_vector<size_t> outputs(query_size); | ||
|
|
||
| state.add_element_count(query_size); | ||
| state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) { | ||
| bitset.rank(inputs.begin(), inputs.end(), outputs.begin()); | ||
| }); | ||
| } | ||
|
|
||
| NVBENCH_BENCH_TYPES(dynamic_bitset_rank, | ||
| NVBENCH_TYPE_AXES(nvbench::type_list<distribution::gaussian>)) | ||
| .set_name("dynamic_bitset_rank") | ||
| .set_type_axes_names({"Distribution"}) | ||
| .set_max_noise(defaults::MAX_NOISE); |
This file contains hidden or 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,62 @@ | ||
| /* | ||
| * Copyright (c) 2023, 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 <defaults.hpp> | ||
| #include <utils.hpp> | ||
|
|
||
| #include <cuco/detail/trie/dynamic_bitset/dynamic_bitset.cuh> | ||
| #include <cuco/utility/key_generator.hpp> | ||
|
|
||
| #include <nvbench/nvbench.cuh> | ||
|
|
||
| #include <thrust/host_vector.h> | ||
|
|
||
| using namespace cuco::benchmark; | ||
| using namespace cuco::utility; | ||
|
|
||
| /** | ||
| * @brief A benchmark evaluating `cuco::experimental::detail::dynamic_bitset::select` performance | ||
| */ | ||
| template <typename Dist> | ||
| void dynamic_bitset_select(nvbench::state& state, nvbench::type_list<Dist>) | ||
| { | ||
| auto const num_bits = state.get_int64_or_default("NumInputs", defaults::N); | ||
| using word_type = typename cuco::experimental::detail::dynamic_bitset<>::word_type; | ||
| auto const bits_per_word = cuco::experimental::detail::dynamic_bitset<>::bits_per_word; | ||
| thrust::host_vector<word_type> keys((num_bits - 1) / bits_per_word + 1); | ||
|
|
||
| key_generator gen; | ||
| gen.generate(dist_from_state<Dist>(state), keys.begin(), keys.end()); | ||
|
|
||
| cuco::experimental::detail::dynamic_bitset bitset; | ||
| bitset.insert(keys.begin(), keys.end(), num_bits); | ||
|
|
||
| const size_t query_size = min(1000 * 1000lu, num_bits / 10); | ||
| thrust::device_vector<size_t> inputs(query_size); | ||
| thrust::sequence(inputs.begin(), inputs.end(), 0); | ||
| thrust::device_vector<size_t> outputs(query_size); | ||
|
|
||
| state.add_element_count(query_size); | ||
| state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) { | ||
| bitset.select(inputs.begin(), inputs.end(), outputs.begin()); | ||
| }); | ||
| } | ||
|
|
||
| NVBENCH_BENCH_TYPES(dynamic_bitset_select, | ||
| NVBENCH_TYPE_AXES(nvbench::type_list<distribution::gaussian>)) | ||
| .set_name("dynamic_bitset_select") | ||
| .set_type_axes_names({"Distribution"}) | ||
| .set_max_noise(defaults::MAX_NOISE); |
This file contains hidden or 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,56 @@ | ||
| /* | ||
| * Copyright (c) 2023, 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 <defaults.hpp> | ||
| #include <utils.hpp> | ||
|
|
||
| #include <cuco/detail/trie/dynamic_bitset/dynamic_bitset.cuh> | ||
| #include <cuco/utility/key_generator.hpp> | ||
|
|
||
| #include <nvbench/nvbench.cuh> | ||
|
|
||
| #include <thrust/host_vector.h> | ||
|
|
||
| using namespace cuco::benchmark; | ||
| using namespace cuco::utility; | ||
|
|
||
| /** | ||
| * @brief A benchmark evaluating `cuco::experimental::detail::dynamic_bitset::size` performance | ||
| */ | ||
| template <typename Dist> | ||
| void dynamic_bitset_size(nvbench::state& state, nvbench::type_list<Dist>) | ||
| { | ||
| auto const num_bits = state.get_int64_or_default("NumInputs", defaults::N); | ||
| using word_type = typename cuco::experimental::detail::dynamic_bitset<>::word_type; | ||
| auto const bits_per_word = cuco::experimental::detail::dynamic_bitset<>::bits_per_word; | ||
| thrust::host_vector<word_type> keys((num_bits - 1) / bits_per_word + 1); | ||
|
|
||
| key_generator gen; | ||
| gen.generate(dist_from_state<Dist>(state), keys.begin(), keys.end()); | ||
|
|
||
| cuco::experimental::detail::dynamic_bitset bitset; | ||
| bitset.insert(keys.begin(), keys.end(), num_bits); | ||
|
|
||
| state.add_element_count(1); | ||
| state.exec(nvbench::exec_tag::sync, | ||
| [&](nvbench::launch& launch) { auto const size = bitset.size(); }); | ||
| } | ||
|
|
||
| NVBENCH_BENCH_TYPES(dynamic_bitset_size, | ||
| NVBENCH_TYPE_AXES(nvbench::type_list<distribution::gaussian>)) | ||
| .set_name("dynamic_bitset_size") | ||
| .set_type_axes_names({"Distribution"}) | ||
| .set_max_noise(defaults::MAX_NOISE); |
This file contains hidden or 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,62 @@ | ||
| /* | ||
| * Copyright (c) 2023, 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 <defaults.hpp> | ||
| #include <utils.hpp> | ||
|
|
||
| #include <cuco/detail/trie/dynamic_bitset/dynamic_bitset.cuh> | ||
| #include <cuco/utility/key_generator.hpp> | ||
|
|
||
| #include <nvbench/nvbench.cuh> | ||
|
|
||
| #include <thrust/host_vector.h> | ||
|
|
||
| using namespace cuco::benchmark; | ||
| using namespace cuco::utility; | ||
|
|
||
| /** | ||
| * @brief A benchmark evaluating `cuco::experimental::detail::dynamic_bitset::test` performance | ||
| */ | ||
| template <typename Dist> | ||
| void dynamic_bitset_test(nvbench::state& state, nvbench::type_list<Dist>) | ||
| { | ||
| auto const num_bits = state.get_int64_or_default("NumInputs", defaults::N); | ||
| using word_type = typename cuco::experimental::detail::dynamic_bitset<>::word_type; | ||
| auto const bits_per_word = cuco::experimental::detail::dynamic_bitset<>::bits_per_word; | ||
| thrust::host_vector<word_type> keys((num_bits - 1) / bits_per_word + 1); | ||
|
|
||
| key_generator gen; | ||
| gen.generate(dist_from_state<Dist>(state), keys.begin(), keys.end()); | ||
|
|
||
| cuco::experimental::detail::dynamic_bitset bitset; | ||
| bitset.insert(keys.begin(), keys.end(), num_bits); | ||
|
|
||
| const size_t query_size = min(1000 * 1000lu, num_bits / 10); | ||
| thrust::device_vector<size_t> inputs(query_size); | ||
| thrust::sequence(inputs.begin(), inputs.end(), 0); | ||
| thrust::device_vector<size_t> outputs(query_size); | ||
|
|
||
| state.add_element_count(query_size); | ||
| state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) { | ||
| bitset.test(inputs.begin(), inputs.end(), outputs.begin()); | ||
| }); | ||
| } | ||
|
|
||
| NVBENCH_BENCH_TYPES(dynamic_bitset_test, | ||
| NVBENCH_TYPE_AXES(nvbench::type_list<distribution::gaussian>)) | ||
| .set_name("dynamic_bitset_test") | ||
| .set_type_axes_names({"Distribution"}) | ||
| .set_max_noise(defaults::MAX_NOISE); |
This file contains hidden or 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,60 @@ | ||
| /* | ||
| * Copyright (c) 2023, 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 <defaults.hpp> | ||
| #include <utils.hpp> | ||
|
|
||
| #include "../../tests/trie/trie_utils.hpp" | ||
amukkara marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <cuco/trie.cuh> | ||
| #include <cuco/utility/key_generator.hpp> | ||
|
|
||
| #include <nvbench/nvbench.cuh> | ||
|
|
||
| using namespace cuco::benchmark; | ||
| using namespace cuco::utility; | ||
|
|
||
| /** | ||
| * @brief A benchmark evaluating `cuco::experimental::trie::insert` performance | ||
| */ | ||
| void trie_insert(nvbench::state& state) | ||
| { | ||
| auto const num_keys = state.get_int64_or_default("NumKeys", 100 * 1000); | ||
| auto const max_key_length = state.get_int64_or_default("MaxKeyLength", 10); | ||
|
|
||
| using LabelType = int; | ||
|
||
| cuco::experimental::trie<LabelType> trie; | ||
|
|
||
| thrust::host_vector<LabelType> labels; | ||
| thrust::host_vector<size_t> offsets; | ||
|
|
||
| distribution::unique lengths_dist; | ||
| distribution::gaussian labels_dist{0.5}; | ||
| generate_labels(labels, offsets, num_keys, max_key_length, lengths_dist, labels_dist); | ||
| auto keys = sorted_keys(labels, offsets); | ||
|
|
||
| state.add_element_count(num_keys); | ||
| state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) { | ||
| for (auto& key : keys) { | ||
| trie.insert(key.begin(), key.end()); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| NVBENCH_BENCH(trie_insert) | ||
| .set_name("trie_insert") | ||
| .set_max_noise(defaults::MAX_NOISE) | ||
| .add_int64_axis("NumKeys", std::vector<nvbench::int64_t>{100 * 1000, 1000 * 1000}) | ||
| .add_int64_axis("MaxKeyLength", std::vector<nvbench::int64_t>{4, 8, 16}); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.