Change-Id: I452cd5d1b258ccbc354a2f424d062f0fa91100ea

[ROCm/clr commit: 0f46bd5131]
Этот коммит содержится в:
Belton-Schure, Aidan
2025-05-28 09:08:38 +01:00
коммит произвёл GitHub
родитель b936e55e81
Коммит 8074e10ce6
+35 -14
Просмотреть файл
@@ -51,31 +51,45 @@ THE SOFTWARE.
#include <type_traits>
#endif // defined(__HIPCC_RTC__)
namespace hip_impl {
inline
constexpr
unsigned int next_pot(unsigned int x) {
// Precondition: x > 1.
return 1u << (32u - __builtin_clz(x - 1u));
}
} // Namespace hip_impl.
template <typename T, unsigned int n> struct HIP_vector_base;
template <typename T, unsigned int rank> struct HIP_vector_type;
template<typename T, unsigned int n> struct HIP_vector_base;
template <typename T, unsigned int rank> struct HIP_vector_type;
namespace hip_impl {
inline constexpr unsigned int next_pot(unsigned int x) {
// Precondition: x > 1.
return 1u << (32u - __builtin_clz(x - 1u));
}
template <typename T, unsigned int n>
__attribute__((always_inline)) __HOST_DEVICE__ typename HIP_vector_base<T, n>::Native_vec_*
get_native_pointer(HIP_vector_base<T, n>& base_vec) {
static_assert(sizeof(base_vec) == sizeof(typename HIP_vector_base<T, n>::Native_vec_));
static_assert(std::alignment_of<HIP_vector_base<T, n>>::value ==
std::alignment_of<typename HIP_vector_base<T, n>::Native_vec_>::value);
return reinterpret_cast<typename HIP_vector_base<T, n>::Native_vec_*>(&base_vec.x);
};
template <typename T, unsigned int n>
__attribute__((always_inline)) __HOST_DEVICE__ const typename HIP_vector_base<T, n>::Native_vec_*
get_native_pointer(const HIP_vector_base<T, n>& base_vec) {
static_assert(sizeof(base_vec) == sizeof(typename HIP_vector_base<T, n>::Native_vec_));
static_assert(std::alignment_of<HIP_vector_base<T, n>>::value ==
std::alignment_of<typename HIP_vector_base<T, n>::Native_vec_>::value);
return reinterpret_cast<const typename HIP_vector_base<T, n>::Native_vec_*>(&base_vec.x);
};
} // Namespace hip_impl.
template <typename T, unsigned int n>
__attribute__((always_inline)) __HOST_DEVICE__ typename HIP_vector_base<T, n>::Native_vec_&
get_native_vector(HIP_vector_base<T, n>& base_vec) {
static_assert(sizeof(base_vec) == sizeof(typename HIP_vector_base<T, n>::Native_vec_));
return *reinterpret_cast<typename HIP_vector_base<T, n>::Native_vec_*>(&base_vec.x);
return *hip_impl::get_native_pointer(base_vec);
};
template <typename T, unsigned int n>
__attribute__((
always_inline)) __HOST_DEVICE__ const typename HIP_vector_base<T, n>::Native_vec_&
get_native_vector(const HIP_vector_base<T, n>& base_vec) {
static_assert(sizeof(base_vec) == sizeof(typename HIP_vector_base<T, n>::Native_vec_));
return *reinterpret_cast<const typename HIP_vector_base<T, n>::Native_vec_*>(&base_vec.x);
return *hip_impl::get_native_pointer(base_vec);
};
template<typename T>
@@ -349,6 +363,13 @@ THE SOFTWARE.
HIP_vector_type& operator=(HIP_vector_type&&) = default;
// Operators
__HOST_DEVICE__
T& operator[](size_t idx) noexcept { return (*hip_impl::get_native_pointer(*this))[idx]; }
__HOST_DEVICE__
const T& operator[](size_t idx) const noexcept {
return (*hip_impl::get_native_pointer(*this))[idx];
}
__HOST_DEVICE__
HIP_vector_type& operator++() noexcept {
HIP_vector_type unity = make_vector_type<T, rank>(1);