Extend vector type capabilities and add tests to reflect it. (#1656)

Этот коммит содержится в:
Alex Voicu
2019-11-20 16:02:32 +00:00
коммит произвёл Maneesh Gupta
родитель 153a959280
Коммит b5b3d1bbaa
3 изменённых файлов: 70 добавлений и 0 удалений
+37
Просмотреть файл
@@ -40,6 +40,7 @@ THE SOFTWARE.
#endif
#if defined(__cplusplus) && defined(__clang__)
#include <iosfwd>
#include <type_traits>
namespace hip_impl {
@@ -68,6 +69,23 @@ THE SOFTWARE.
}
};
friend
inline
std::ostream& operator<<(std::ostream& os,
const Scalar_accessor& x) noexcept {
return os << x.data[idx];
}
friend
inline
std::istream& operator>>(std::istream& is,
Scalar_accessor& x) noexcept {
T tmp;
is >> tmp;
x.data[idx] = tmp;
return is;
}
// Idea from https://t0rakka.silvrback.com/simd-scalar-accessor
Vector data;
@@ -76,6 +94,17 @@ THE SOFTWARE.
__host__ __device__
operator T() const volatile noexcept { return data[idx]; }
__host__ __device__
operator T&() noexcept {
return reinterpret_cast<
T (&)[sizeof(Vector) / sizeof(T)]>(data)[idx];
}
__host__ __device__
operator volatile T&() volatile noexcept {
return reinterpret_cast<
volatile T (&)[sizeof(Vector) / sizeof(T)]>(data)[idx];
}
__host__ __device__
Address operator&() const noexcept { return Address{this}; }
@@ -198,6 +227,8 @@ THE SOFTWARE.
Native_vec_ data;
hip_impl::Scalar_accessor<T, Native_vec_, 0> x;
};
using value_type = T;
};
template<typename T>
@@ -209,6 +240,8 @@ THE SOFTWARE.
hip_impl::Scalar_accessor<T, Native_vec_, 0> x;
hip_impl::Scalar_accessor<T, Native_vec_, 1> y;
};
using value_type = T;
};
template<typename T>
@@ -367,6 +400,8 @@ THE SOFTWARE.
T z;
};
};
using value_type = T;
};
template<typename T>
@@ -380,6 +415,8 @@ THE SOFTWARE.
hip_impl::Scalar_accessor<T, Native_vec_, 2> z;
hip_impl::Scalar_accessor<T, Native_vec_, 3> w;
};
using value_type = T;
};
template<typename T, unsigned int rank>