Skip to content

Commit

Permalink
Add compute_hash overloads for std::byte* to maintain backward co…
Browse files Browse the repository at this point in the history
…mpatibility (#608)

Unblock rapidsai/cugraph#4686

The `compute_hash` function is a host-device function, so the
appropriate argument type is `cuda::std::byte`. However, to ensure
backward compatibility and avoid breaking existing use cases, this PR
adds overloads that accept `std::byte`.

---------

Co-authored-by: Daniel Jünger <[email protected]>
  • Loading branch information
PointKernel and sleeepyjack authored Oct 3, 2024
1 parent de9d8c8 commit f768729
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
{
return 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
{
return 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
{
return 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
{
return 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
{
return 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 f768729

Please sign in to comment.