From c3bbe1a8770010718ce4f99a6721a2f04281cace Mon Sep 17 00:00:00 2001 From: Yunsong Wang Date: Wed, 2 Oct 2024 10:30:35 -0700 Subject: [PATCH 1/2] 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 From bb4f5f62a278290989eb3786e30fbb9ab6a88422 Mon Sep 17 00:00:00 2001 From: Yunsong Wang Date: Wed, 2 Oct 2024 10:45:22 -0700 Subject: [PATCH 2/2] Return! --- include/cuco/detail/hash_functions/murmurhash3.cuh | 6 +++--- include/cuco/detail/hash_functions/xxhash.cuh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/cuco/detail/hash_functions/murmurhash3.cuh b/include/cuco/detail/hash_functions/murmurhash3.cuh index ea91322d7..7aaa14d20 100644 --- a/include/cuco/detail/hash_functions/murmurhash3.cuh +++ b/include/cuco/detail/hash_functions/murmurhash3.cuh @@ -220,7 +220,7 @@ struct MurmurHash3_32 { constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes, Extent size) const noexcept { - this->compute_hash(reinterpret_cast(bytes), size); + return this->compute_hash(reinterpret_cast(bytes), size); } private: @@ -388,7 +388,7 @@ struct MurmurHash3_x64_128 { constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes, Extent size) const noexcept { - this->compute_hash(reinterpret_cast(bytes), size); + return this->compute_hash(reinterpret_cast(bytes), size); } private: @@ -605,7 +605,7 @@ struct MurmurHash3_x86_128 { constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes, Extent size) const noexcept { - this->compute_hash(reinterpret_cast(bytes), size); + return this->compute_hash(reinterpret_cast(bytes), size); } private: diff --git a/include/cuco/detail/hash_functions/xxhash.cuh b/include/cuco/detail/hash_functions/xxhash.cuh index 6f1f30dd8..cc5ab06f6 100644 --- a/include/cuco/detail/hash_functions/xxhash.cuh +++ b/include/cuco/detail/hash_functions/xxhash.cuh @@ -186,7 +186,7 @@ struct XXHash_32 { constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes, Extent size) const noexcept { - this->compute_hash(reinterpret_cast(bytes), size); + return this->compute_hash(reinterpret_cast(bytes), size); } private: @@ -403,7 +403,7 @@ struct XXHash_64 { constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes, Extent size) const noexcept { - this->compute_hash(reinterpret_cast(bytes), size); + return this->compute_hash(reinterpret_cast(bytes), size); } private: