From 31d298c0d743805f92766c9cff861955ca56149a Mon Sep 17 00:00:00 2001 From: Jake Hemstad Date: Wed, 2 Jun 2021 11:38:34 -0500 Subject: [PATCH 1/4] Add trait for is_bitwise_comparable. --- include/cuco/static_map.cuh | 52 +++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/include/cuco/static_map.cuh b/include/cuco/static_map.cuh index 900197e5a..bb6140788 100644 --- a/include/cuco/static_map.cuh +++ b/include/cuco/static_map.cuh @@ -43,6 +43,40 @@ namespace cuco { template class dynamic_map; +/** + * @brief Customization point that can be specialized to indicate that it is safe to perform bitwise + * equality comparisons on objects of type `T`. + * + * By default, only types where `std::has_unique_object_representations_v` is true are safe for + * bitwise equality. However, this can be too restrictive for some types, e.g., floating point + * types. + * + * User-defined specializations of `is_bitwise_comparable` are allowed, but it is the users + * responsibility to ensure values do not occur that would lead to unexpected behavior. For example, + * if a `NaN` bit pattern were used as the empty sentinel value, it may not compare bitwise equal to + * other `NaN` bit patterns. + * + */ +template +struct is_bitwise_comparable : std::false_type { +}; + +template + struct is_bitwise_comparable < T, + std::enable_if_t> : std::true_type { +}; + +/** + * @brief Declares that a type `Type` is bitwise comparable. + * + */ +#define CUCO_DECLARE_BITWISE_COMPARABLE(Type) \ + namespace cuco { \ + template <> \ + struct is_bitwise_comparable : std::true_type { \ + }; \ + } + /** * @brief A GPU-accelerated, unordered, associative container of key-value * pairs with unique keys. @@ -117,14 +151,16 @@ template > class static_map { - template - static constexpr bool is_CAS_safe = - std::is_trivially_copyable_vand std::has_unique_object_representations_v; - - static_assert(is_CAS_safe, - "Key type must be trivially copyable and have unique object representation."); - static_assert(is_CAS_safe, - "Value type must be trivially copyable and have unique object representation."); + + static_assert( + is_bitwise_comparable::value, + "Key type must have unique object representations or have been explicitly declared as safe for " + "bitwise comparison via specialization of cuco::is_bitwise_comparable."); + + static_assert( + is_bitwise_comparable::value, + "Key type must have unique object representations or have been explicitly declared as safe for " + "bitwise comparison via specialization of cuco::is_bitwise_comparable."); friend class dynamic_map; From 616983b57a245d724441d6e00ecf060a66b96de1 Mon Sep 17 00:00:00 2001 From: Jake Hemstad Date: Wed, 2 Jun 2021 11:46:53 -0500 Subject: [PATCH 2/4] Update docs. --- include/cuco/static_map.cuh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/cuco/static_map.cuh b/include/cuco/static_map.cuh index bb6140788..0d459e786 100644 --- a/include/cuco/static_map.cuh +++ b/include/cuco/static_map.cuh @@ -61,6 +61,7 @@ template struct is_bitwise_comparable : std::false_type { }; +/// By default, only types with unique object representations are allowed template struct is_bitwise_comparable < T, std::enable_if_t> : std::true_type { @@ -85,14 +86,12 @@ template * concurrent insert and find) from threads in device code. * * Current limitations: - * - Requires keys and values that are trivially copyable and have unique object representations + * - Requires keys and values that where `cuco::is_bitwise_comparable::value` is true * - Comparisons against the "sentinel" values will always be done with bitwise comparisons. - * Therefore, the objects must have unique, bitwise object representations (e.g., no padding - * bits). * - Does not support erasing keys * - Capacity is fixed and will not grow automatically - * - Requires the user to specify sentinel values for both key and mapped value - * to indicate empty slots + * - Requires the user to specify sentinel values for both key and mapped value to indicate empty + * slots * - Does not support concurrent insert and find operations * * The `static_map` supports two types of operations: From b7dcaf5c4486f3ddc8640cc24e55f601036a8a48 Mon Sep 17 00:00:00 2001 From: Jake Hemstad Date: Wed, 2 Jun 2021 11:51:41 -0500 Subject: [PATCH 3/4] fix typo. --- include/cuco/static_map.cuh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cuco/static_map.cuh b/include/cuco/static_map.cuh index 0d459e786..2e75f1069 100644 --- a/include/cuco/static_map.cuh +++ b/include/cuco/static_map.cuh @@ -158,7 +158,7 @@ class static_map { static_assert( is_bitwise_comparable::value, - "Key type must have unique object representations or have been explicitly declared as safe for " + "Value type must have unique object representations or have been explicitly declared as safe for " "bitwise comparison via specialization of cuco::is_bitwise_comparable."); friend class dynamic_map; From b715c310f9677ee8c7fe68fcf57779946ca7646c Mon Sep 17 00:00:00 2001 From: Jake Hemstad Date: Wed, 2 Jun 2021 11:59:41 -0500 Subject: [PATCH 4/4] Missing angle bracket. --- include/cuco/static_map.cuh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cuco/static_map.cuh b/include/cuco/static_map.cuh index 2e75f1069..0fb74bed8 100644 --- a/include/cuco/static_map.cuh +++ b/include/cuco/static_map.cuh @@ -63,8 +63,8 @@ struct is_bitwise_comparable : std::false_type { /// By default, only types with unique object representations are allowed template - struct is_bitwise_comparable < T, - std::enable_if_t> : std::true_type { +struct is_bitwise_comparable>> + : std::true_type { }; /**