Skip to content

Commit

Permalink
Merge pull request ROCm#196 from ROCmSoftwarePlatform/release-staging…
Browse files Browse the repository at this point in the history
…/rocm-rel-6.0

Use consistent test data
  • Loading branch information
tfalders authored Oct 2, 2023
2 parents 00ae3cb + e27faa8 commit 344f525
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions clients/include/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,32 +390,32 @@ class hipsolver_nan_rng
template <typename T>
T random_generator()
{
// return rand()/( (T)RAND_MAX + 1);
return T(rand() % 10 + 1);
return std::uniform_int_distribution<int>(1, 10)(hipsolver_rng);
};

// for hipsolverComplex, generate 2 floats
/*! \brief generate two random numbers in range [1,2,3,4,5,6,7,8,9,10] */
template <>
inline hipsolverComplex random_generator<hipsolverComplex>()
{
return hipsolverComplex(rand() % 10 + 1, rand() % 10 + 1);
return hipsolverComplex(float(std::uniform_int_distribution<int>(1, 10)(hipsolver_rng)),
float(std::uniform_int_distribution<int>(1, 10)(hipsolver_rng)));
}

// for hipsolverDoubleComplex, generate 2 doubles
/*! \brief generate two random numbers in range [1,2,3,4,5,6,7,8,9,10] */
template <>
inline hipsolverDoubleComplex random_generator<hipsolverDoubleComplex>()
{
return hipsolverDoubleComplex(rand() % 10 + 1, rand() % 10 + 1);
return hipsolverDoubleComplex(double(std::uniform_int_distribution<int>(1, 10)(hipsolver_rng)),
double(std::uniform_int_distribution<int>(1, 10)(hipsolver_rng)));
}

/*! \brief generate a random number in range [-1,-2,-3,-4,-5,-6,-7,-8,-9,-10] */
template <typename T>
inline T random_generator_negative()
{
// return rand()/( (T)RAND_MAX + 1);
return -T(rand() % 10 + 1);
return std::uniform_int_distribution<int>(-10, -1)(hipsolver_rng);
};

// for complex, generate two values, convert both to negative
Expand All @@ -425,13 +425,16 @@ inline T random_generator_negative()
template <>
inline hipsolverComplex random_generator_negative<hipsolverComplex>()
{
return {float(-(rand() % 10 + 1)), float(-(rand() % 10 + 1))};
return hipsolverComplex(float(std::uniform_int_distribution<int>(-10, -1)(hipsolver_rng)),
float(std::uniform_int_distribution<int>(-10, -1)(hipsolver_rng)));
}

template <>
inline hipsolverDoubleComplex random_generator_negative<hipsolverDoubleComplex>()
{
return {double(-(rand() % 10 + 1)), double(-(rand() % 10 + 1))};
return hipsolverDoubleComplex(
double(std::uniform_int_distribution<int>(-10, -1)(hipsolver_rng)),
double(std::uniform_int_distribution<int>(-10, -1)(hipsolver_rng)));
}

/* ============================================================================================ */
Expand Down Expand Up @@ -467,6 +470,27 @@ int type2int(T val);

/* ============================================================================================ */
/*! \brief Debugging purpose, print out CPU and GPU result matrix, not valid in complex number */
template <typename T, std::enable_if_t<!is_complex<T>, int> = 0>
void print_matrix(T* result, int m, int n, int lda)
{
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
printf("matrix col %d, row %d, result=%.8g\n", j, i, double(result[i + j * lda]));
}

/*! \brief Debugging purpose, print out CPU and GPU result matrix, valid for complex number */
template <typename T, std::enable_if_t<+is_complex<T>, int> = 0>
void print_matrix(T* result, int m, int n, int lda)
{
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
printf("matrix col %d, row %d, result=(%.8g,%.8g)\n",
j,
i,
double(result[i + j * lda].real()),
double(result[i + j * lda].imag()));
}

template <typename T, std::enable_if_t<!is_complex<T>, int> = 0>
void print_matrix(T* CPU_result, T* GPU_result, int m, int n, int lda)
{
Expand Down

0 comments on commit 344f525

Please sign in to comment.