CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
217 lines
5.4 KiB
C++
217 lines
5.4 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <stddef.h>
|
|
#include <tuple>
|
|
#include <type_traits>
|
|
|
|
#include <rocRoller/Utilities/Concepts.hpp>
|
|
|
|
namespace rocRoller
|
|
{
|
|
/**
|
|
* \ingroup Utilities
|
|
* \defgroup Comparison Comparison
|
|
*/
|
|
|
|
/**
|
|
* \addtogroup Comparison
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* Lexicographically compares two lists of values, one pair of values at a
|
|
* time.
|
|
*
|
|
* \return -1: The first list is lesser.
|
|
* 1: The second list is lesser.
|
|
* 0: The lists are equal.
|
|
*/
|
|
inline int LexicographicCompare()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
template <typename A>
|
|
inline int LexicographicCompare(A const& lhs, A const& rhs)
|
|
{
|
|
if(lhs < rhs)
|
|
return -1;
|
|
if(lhs > rhs)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
template <typename A,
|
|
typename... Args,
|
|
typename = typename std::enable_if<sizeof...(Args) % 2 == 0>>
|
|
inline int LexicographicCompare(A const& lhs, A const& rhs, Args const&... rest)
|
|
{
|
|
if(lhs < rhs)
|
|
return -1;
|
|
if(lhs > rhs)
|
|
return 1;
|
|
return LexicographicCompare(rest...);
|
|
}
|
|
|
|
/**
|
|
* @brief Traits class which enables comparison operators to be implemented
|
|
* based on a `compare()` function.
|
|
*
|
|
* Specializations must implement a `compare(lhs, rhs)` function which returns:
|
|
* - -1: lhs is lesser
|
|
* - 0: values are equal
|
|
* - 1: rhs is lesser
|
|
*/
|
|
template <typename T, typename U = T>
|
|
struct Comparison
|
|
{
|
|
enum
|
|
{
|
|
implemented = false
|
|
};
|
|
};
|
|
|
|
template <typename T,
|
|
typename U,
|
|
typename = typename std::enable_if<Comparison<T, U>::implemented>::type>
|
|
inline bool operator==(T const& lhs, U const& rhs)
|
|
{
|
|
return Comparison<T, U>::compare(lhs, rhs) == 0;
|
|
}
|
|
|
|
template <typename T,
|
|
typename U,
|
|
typename = typename std::enable_if<Comparison<T, U>::implemented>::type>
|
|
inline bool operator!=(T const& lhs, U const& rhs)
|
|
{
|
|
return Comparison<T, U>::compare(lhs, rhs) != 0;
|
|
}
|
|
|
|
template <typename T,
|
|
typename U,
|
|
typename = typename std::enable_if<Comparison<T, U>::implemented>::type>
|
|
inline bool operator<(T const& lhs, U const& rhs)
|
|
{
|
|
return Comparison<T, U>::compare(lhs, rhs) < 0;
|
|
}
|
|
|
|
template <typename T,
|
|
typename U,
|
|
typename = typename std::enable_if<Comparison<T, U>::implemented>::type>
|
|
inline bool operator<=(T const& lhs, U const& rhs)
|
|
{
|
|
return Comparison<T, U>::compare(lhs, rhs) <= 0;
|
|
}
|
|
|
|
template <typename T,
|
|
typename U,
|
|
typename = typename std::enable_if<Comparison<T, U>::implemented>::type>
|
|
inline bool operator>(T const& lhs, U const& rhs)
|
|
{
|
|
return Comparison<T, U>::compare(lhs, rhs) > 0;
|
|
}
|
|
|
|
template <typename T,
|
|
typename U,
|
|
typename = typename std::enable_if<Comparison<T, U>::implemented>::type>
|
|
inline bool operator>=(T const& lhs, U const& rhs)
|
|
{
|
|
return Comparison<T, U>::compare(lhs, rhs) >= 0;
|
|
}
|
|
|
|
/**
|
|
* Combines a number of already-hashed values.
|
|
*/
|
|
template <typename... Ts>
|
|
inline size_t combine_hashes(size_t a, Ts... rest)
|
|
{
|
|
return combine_hashes(a, combine_hashes(rest...));
|
|
}
|
|
|
|
template <>
|
|
inline size_t combine_hashes(size_t a, size_t b)
|
|
{
|
|
return b ^ (a + 0x9b9773e99e3779b9 + (b << 6) + (b >> 2));
|
|
}
|
|
|
|
template <CHashable T>
|
|
inline size_t hash_combine(T const& val)
|
|
{
|
|
return std::hash<T>()(val);
|
|
}
|
|
|
|
template <CHashable T, CHashable... Ts>
|
|
inline size_t hash_combine(T const& val, Ts const&... more)
|
|
{
|
|
//size_t mine = sizeof(val);
|
|
size_t mine = std::hash<T>()(val);
|
|
size_t rest = hash_combine(more...);
|
|
|
|
//return mine + rest;
|
|
return combine_hashes(mine, rest);
|
|
}
|
|
|
|
template <typename Iter>
|
|
inline size_t hash_combine_iter(Iter begin, Iter end)
|
|
{
|
|
size_t rv = 0;
|
|
while(begin != end)
|
|
{
|
|
rv = combine_hashes(hash_combine(*begin), rv);
|
|
begin++;
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
template <size_t N, class... Types>
|
|
struct tuple_hash
|
|
{
|
|
using MyTuple = std::tuple<Types...>;
|
|
using TypeN = typename std::tuple_element<N, MyTuple>::type;
|
|
static size_t apply(std::tuple<Types...> const& tup)
|
|
{
|
|
size_t mine = std::hash<TypeN>()(std::get<N>(tup));
|
|
size_t rest = tuple_hash<N - 1, Types...>::apply(tup);
|
|
|
|
return combine_hashes(mine, rest);
|
|
}
|
|
};
|
|
|
|
template <class... Types>
|
|
struct tuple_hash<0, Types...>
|
|
{
|
|
using MyTuple = std::tuple<Types...>;
|
|
using Type0 = typename std::tuple_element<0, MyTuple>::type;
|
|
static size_t apply(std::tuple<Types...> const& tup)
|
|
{
|
|
return std::hash<Type0>()(std::get<0>(tup));
|
|
}
|
|
};
|
|
|
|
template <class... Types>
|
|
size_t hash_tuple(std::tuple<Types...> const& tup)
|
|
{
|
|
return tuple_hash<sizeof...(Types) - 1, Types...>::apply(tup);
|
|
}
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
} // namespace rocRoller
|
|
|
|
namespace std
|
|
{
|
|
template <class... Types>
|
|
struct hash<tuple<Types...>>
|
|
{
|
|
inline size_t operator()(tuple<Types...> const& tup) const
|
|
{
|
|
return rocRoller::hash_tuple(tup);
|
|
}
|
|
};
|
|
} // namespace std
|