Skip to content

Commit

Permalink
Fix the default erase sentinel bug in the base open addressing ctor (#…
Browse files Browse the repository at this point in the history
…428)

This PR fixes a bug in the OA base class where the erased key sentinel
value should have been initialized by the empty key sentinel if not
specified.

Tests are updated to exercise this issue.

Needed by rapidsai/cudf#14813
  • Loading branch information
PointKernel committed Jan 23, 2024
1 parent c48225f commit fabd885
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/cuco/detail/open_addressing/open_addressing_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,15 @@ class open_addressing_impl {
cuda_stream_ref stream)
: empty_key_sentinel_{empty_key_sentinel},
empty_slot_sentinel_{empty_slot_sentinel},
erased_key_sentinel_{empty_key_sentinel},
predicate_{pred},
probing_scheme_{probing_scheme},
storage_{make_window_extent<open_addressing_impl>(
static_cast<size_type>(std::ceil(static_cast<double>(n) / desired_load_factor))),
alloc}
{
CUCO_EXPECTS(desired_load_factor > 0., "Desired occupancy must be larger than zero");
CUCO_EXPECTS(desired_load_factor < 1., "Desired occupancy must be smaller than one");
CUCO_EXPECTS(desired_load_factor <= 1., "Desired occupancy must be no larger than one");

this->clear_async(stream);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/static_set/insert_and_find_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ TEMPLATE_TEST_CASE_SIG(
cuco::linear_probing<CGSize, cuco::default_hash_function<Key>>,
cuco::double_hashing<CGSize, cuco::default_hash_function<Key>>>;

auto set = cuco::static_set{num_keys, cuco::empty_key<Key>{-1}, {}, {}, {}, cuco::storage<2>{}};
auto set =
cuco::static_set{num_keys, cuco::empty_key<Key>{-1}, {}, probe{}, {}, cuco::storage<2>{}};

test_insert_and_find(set, num_keys);
}
7 changes: 4 additions & 3 deletions tests/static_set/retrieve_all_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ TEMPLATE_TEST_CASE_SIG(
(int64_t, cuco::test::probe_sequence::linear_probing, 2))
{
constexpr std::size_t num_keys{400};
auto constexpr gold_capacity = CGSize == 1 ? 409 // 409 x 1 x 1
: 422 // 211 x 2 x 1
constexpr double desired_load_factor = 1.;
auto constexpr gold_capacity = CGSize == 1 ? 409 // 409 x 1 x 1
: 422 // 211 x 2 x 1
;

using probe = std::conditional_t<Probe == cuco::test::probe_sequence::linear_probing,
cuco::linear_probing<CGSize, cuco::default_hash_function<Key>>,
cuco::double_hashing<CGSize, cuco::default_hash_function<Key>>>;

auto set = cuco::static_set{num_keys, cuco::empty_key<Key>{-1}, {}, probe{}};
auto set = cuco::static_set{num_keys, desired_load_factor, cuco::empty_key<Key>{-1}, {}, probe{}};

REQUIRE(set.capacity() == gold_capacity);

Expand Down

0 comments on commit fabd885

Please sign in to comment.