SWDEV-366138 - Add surface tests (#309)

Add surface tests
Optimize some codes
Change-Id: I1691b81d597bfd722d561778f919ebf8ca530e89
This commit is contained in:
ROCm CI Service Account
2023-06-21 05:03:37 +05:30
committed by GitHub
parent f4feab33bc
commit 2337705b55
8 changed files with 1249 additions and 68 deletions
+2 -67
View File
@@ -18,6 +18,7 @@ THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip_array_common.hh>
#include <vector>
#include <iostream>
@@ -31,47 +32,6 @@ __global__ void tex1dKernelFetch(T *val, hipTextureObject_t obj, int N) {
#endif
}
template <typename T>
static inline __host__ __device__ constexpr int rank() {
return sizeof(T) / sizeof(decltype(T::x));
}
template<typename T>
static inline T getRandom() {
double r = 0;
if (std::is_signed < T > ::value) {
r = (std::rand() - RAND_MAX / 2.0) / (RAND_MAX / 2.0 + 1.);
} else {
r = std::rand() / (RAND_MAX + 1.);
}
return static_cast<T>(std::numeric_limits < T > ::max() * r);
}
template<
typename T,
typename std::enable_if<rank<T>() == 1>::type* = nullptr>
static inline void initVal(T &val) {
val.x = getRandom<decltype(T::x)>();
}
template<
typename T,
typename std::enable_if<rank<T>() == 2>::type* = nullptr>
static inline void initVal(T &val) {
val.x = getRandom<decltype(T::x)>();
val.y = getRandom<decltype(T::x)>();
}
template<
typename T,
typename std::enable_if<rank<T>() == 4>::type* = nullptr>
static inline void initVal(T &val) {
val.x = getRandom<decltype(T::x)>();
val.y = getRandom<decltype(T::x)>();
val.z = getRandom<decltype(T::x)>();
val.w = getRandom<decltype(T::x)>();
}
template<
typename T,
typename std::enable_if<rank<T>() == 1>::type* = nullptr>
@@ -112,31 +72,6 @@ static inline void printVector(T &val) {
std::cout << ")";
}
template<
typename T,
typename std::enable_if<rank<T>() == 1>::type* = nullptr>
static inline bool isEqual(const T &val0, const T &val1) {
return val0.x == val1.x;
}
template<
typename T,
typename std::enable_if<rank<T>() == 2>::type* = nullptr>
static inline bool isEqual(const T &val0, const T &val1) {
return val0.x == val1.x &&
val0.y == val1.y;
}
template<
typename T,
typename std::enable_if<rank<T>() == 4>::type* = nullptr>
static inline bool isEqual(const T &val0, const T &val1) {
return val0.x == val1.x &&
val0.y == val1.y &&
val0.z == val1.z &&
val0.w == val1.w;
}
template<typename T>
bool runTest() {
const int N = 1024;
@@ -144,7 +79,7 @@ bool runTest() {
// Allocating the required buffer on gpu device
T *texBuf, *texBufOut;
T val[N], output[N];
hipGetLastError(); // Clear err due to negative tests
memset(output, 0, sizeof(output));
std::srand(std::time(nullptr)); // use current time as seed for random generator