Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compute_hash overloads for std::byte* to maintain backward compatibility #608

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading