Skip to content

Commit

Permalink
Add std::byte compute_hash overloads for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
PointKernel committed Oct 2, 2024
1 parent 8c8590c commit c3bbe1a
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
60 changes: 60 additions & 0 deletions include/cuco/detail/hash_functions/murmurhash3.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Extent>
constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes,
Extent size) const noexcept
{
this->compute_hash(reinterpret_cast<cuda::std::byte const*>(bytes), size);
}

private:
constexpr __host__ __device__ std::uint32_t rotl32(std::uint32_t x, std::int8_t r) const noexcept
{
Expand Down Expand Up @@ -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 <typename Extent>
constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes,
Extent size) const noexcept
{
this->compute_hash(reinterpret_cast<cuda::std::byte const*>(bytes), size);
}

private:
MurmurHash3_fmix64<std::uint64_t> fmix64_;
std::uint64_t seed_;
Expand Down Expand Up @@ -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 <typename Extent>
constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes,
Extent size) const noexcept
{
this->compute_hash(reinterpret_cast<cuda::std::byte const*>(bytes), size);
}

private:
MurmurHash3_fmix32<std::uint32_t> fmix32_;
std::uint32_t seed_;
Expand Down
40 changes: 40 additions & 0 deletions include/cuco/detail/hash_functions/xxhash.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Extent>
constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes,
Extent size) const noexcept
{
this->compute_hash(reinterpret_cast<cuda::std::byte const*>(bytes), size);
}

private:
// avalanche helper
constexpr __host__ __device__ std::uint32_t finalize(std::uint32_t h) const noexcept
Expand Down Expand Up @@ -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 <typename Extent>
constexpr result_type __host__ __device__ compute_hash(std::byte const* bytes,
Extent size) const noexcept
{
this->compute_hash(reinterpret_cast<cuda::std::byte const*>(bytes), size);
}

private:
// avalanche helper
constexpr __host__ __device__ std::uint64_t finalize(std::uint64_t h) const noexcept
Expand Down

0 comments on commit c3bbe1a

Please sign in to comment.