From c3bbe1a8770010718ce4f99a6721a2f04281cace Mon Sep 17 00:00:00 2001 From: Yunsong Wang Date: Wed, 2 Oct 2024 10:30:35 -0700 Subject: [PATCH] Add std::byte compute_hash overloads for backward compatibility --- .../detail/hash_functions/murmurhash3.cuh | 60 +++++++++++++++++++ include/cuco/detail/hash_functions/xxhash.cuh | 40 +++++++++++++ 2 files changed, 100 insertions(+) diff --git a/include/cuco/detail/hash_functions/murmurhash3.cuh b/include/cuco/detail/hash_functions/murmurhash3.cuh index f99c04c75..ea91322d7 100644 --- a/include/cuco/detail/hash_functions/murmurhash3.cuh +++ b/include/cuco/detail/hash_functions/murmurhash3.cuh @@ -203,6 +203,26 @@ struct MurmurHash3_32 { return h1; } + /** + * @brief Returns a hash value for its argument, as a value of type `result_type`. + * + * @note This API is to ensure backward compatibility with existing use cases using `std::byte`. + * Users are encouraged to use the appropriate `cuda::std::byte` overload whenever possible for + * better support and performance on the device. + * + * @tparam Extent The extent type + * + * @param bytes The input argument to hash + * @param size The extent of the data in bytes + * @return The resulting hash value + */ + template + constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes, + Extent size) const noexcept + { + this->compute_hash(reinterpret_cast(bytes), size); + } + private: constexpr __host__ __device__ std::uint32_t rotl32(std::uint32_t x, std::int8_t r) const noexcept { @@ -351,6 +371,26 @@ struct MurmurHash3_x64_128 { return {h1, h2}; } + /** + * @brief Returns a hash value for its argument, as a value of type `result_type`. + * + * @note This API is to ensure backward compatibility with existing use cases using `std::byte`. + * Users are encouraged to use the appropriate `cuda::std::byte` overload whenever possible for + * better support and performance on the device. + * + * @tparam Extent The extent type + * + * @param bytes The input argument to hash + * @param size The extent of the data in bytes + * @return The resulting hash value + */ + template + constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes, + Extent size) const noexcept + { + this->compute_hash(reinterpret_cast(bytes), size); + } + private: MurmurHash3_fmix64 fmix64_; std::uint64_t seed_; @@ -548,6 +588,26 @@ struct MurmurHash3_x86_128 { return {h1, h2, h3, h4}; } + /** + * @brief Returns a hash value for its argument, as a value of type `result_type`. + * + * @note This API is to ensure backward compatibility with existing use cases using `std::byte`. + * Users are encouraged to use the appropriate `cuda::std::byte` overload whenever possible for + * better support and performance on the device. + * + * @tparam Extent The extent type + * + * @param bytes The input argument to hash + * @param size The extent of the data in bytes + * @return The resulting hash value + */ + template + constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes, + Extent size) const noexcept + { + this->compute_hash(reinterpret_cast(bytes), size); + } + private: MurmurHash3_fmix32 fmix32_; std::uint32_t seed_; diff --git a/include/cuco/detail/hash_functions/xxhash.cuh b/include/cuco/detail/hash_functions/xxhash.cuh index 4ef75c782..6f1f30dd8 100644 --- a/include/cuco/detail/hash_functions/xxhash.cuh +++ b/include/cuco/detail/hash_functions/xxhash.cuh @@ -169,6 +169,26 @@ struct XXHash_32 { return finalize(h32); } + /** + * @brief Returns a hash value for its argument, as a value of type `result_type`. + * + * @note This API is to ensure backward compatibility with existing use cases using `std::byte`. + * Users are encouraged to use the appropriate `cuda::std::byte` overload whenever possible for + * better support and performance on the device. + * + * @tparam Extent The extent type + * + * @param bytes The input argument to hash + * @param size The extent of the data in bytes + * @return The resulting hash value + */ + template + constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes, + Extent size) const noexcept + { + this->compute_hash(reinterpret_cast(bytes), size); + } + private: // avalanche helper constexpr __host__ __device__ std::uint32_t finalize(std::uint32_t h) const noexcept @@ -366,6 +386,26 @@ struct XXHash_64 { return finalize(h64); } + /** + * @brief Returns a hash value for its argument, as a value of type `result_type`. + * + * @note This API is to ensure backward compatibility with existing use cases using `std::byte`. + * Users are encouraged to use the appropriate `cuda::std::byte` overload whenever possible for + * better support and performance on the device. + * + * @tparam Extent The extent type + * + * @param bytes The input argument to hash + * @param size The extent of the data in bytes + * @return The resulting hash value + */ + template + constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes, + Extent size) const noexcept + { + this->compute_hash(reinterpret_cast(bytes), size); + } + private: // avalanche helper constexpr __host__ __device__ std::uint64_t finalize(std::uint64_t h) const noexcept