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

unordered_map,unordered_set: Fix excess list size for very low capacities #414

Merged
merged 1 commit into from
Apr 8, 2024
Merged
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
7 changes: 4 additions & 3 deletions src/stdgpu/impl/unordered_base_detail.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -1203,9 +1203,10 @@ unordered_base<Key, Value, KeyFromValue, Hash, KeyEqual, Allocator>::createDevic
index_t bucket_count = static_cast<index_t>(
bit_ceil(static_cast<std::size_t>(std::ceil(static_cast<float>(capacity) / default_max_load_factor()))));

// excess count is estimated by the expected collision count and conservatively lowered since entries falling into
// regular buckets are already included here
index_t excess_count = std::max<index_t>(1, expected_collisions(bucket_count, capacity) * 2 / 3);
// excess count is estimated by the expected collision count:
// - Conservatively lower the amount since entries falling into regular buckets are already included here
// - Increase amount by 1 since insertion expects a non-empty excess list also in case of no collision
index_t excess_count = std::max<index_t>(1, expected_collisions(bucket_count, capacity) * 2 / 3 + 1);
stotko marked this conversation as resolved.
Show resolved Hide resolved

index_t total_count = bucket_count + excess_count;

Expand Down