Check result of the final reduction
This commit is contained in:
parent
04ca357159
commit
275bfb2066
20
main.cpp
20
main.cpp
@ -44,7 +44,7 @@ bool use_float = false;
|
|||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void check_solution(const unsigned int ntimes, std::vector<T>& a, std::vector<T>& b, std::vector<T>& c);
|
void check_solution(const unsigned int ntimes, std::vector<T>& a, std::vector<T>& b, std::vector<T>& c, T& sum);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void run();
|
void run();
|
||||||
@ -94,6 +94,9 @@ void run()
|
|||||||
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-9 << " GB)" << std::endl;
|
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-9 << " GB)" << std::endl;
|
||||||
std::cout.precision(ss);
|
std::cout.precision(ss);
|
||||||
|
|
||||||
|
// Result of the Dot kernel
|
||||||
|
T sum;
|
||||||
|
|
||||||
Stream<T> *stream;
|
Stream<T> *stream;
|
||||||
|
|
||||||
#if defined(CUDA)
|
#if defined(CUDA)
|
||||||
@ -167,7 +170,7 @@ void run()
|
|||||||
|
|
||||||
// Execute Dot
|
// Execute Dot
|
||||||
t1 = std::chrono::high_resolution_clock::now();
|
t1 = std::chrono::high_resolution_clock::now();
|
||||||
stream->dot();
|
sum = stream->dot();
|
||||||
t2 = std::chrono::high_resolution_clock::now();
|
t2 = std::chrono::high_resolution_clock::now();
|
||||||
timings[4].push_back(std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count());
|
timings[4].push_back(std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count());
|
||||||
|
|
||||||
@ -175,7 +178,7 @@ void run()
|
|||||||
|
|
||||||
// Check solutions
|
// Check solutions
|
||||||
stream->read_arrays(a, b, c);
|
stream->read_arrays(a, b, c);
|
||||||
check_solution<T>(num_times, a, b, c);
|
check_solution<T>(num_times, a, b, c, sum);
|
||||||
|
|
||||||
// Display timing results
|
// Display timing results
|
||||||
std::cout
|
std::cout
|
||||||
@ -220,12 +223,13 @@ void run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void check_solution(const unsigned int ntimes, std::vector<T>& a, std::vector<T>& b, std::vector<T>& c)
|
void check_solution(const unsigned int ntimes, std::vector<T>& a, std::vector<T>& b, std::vector<T>& c, T& sum)
|
||||||
{
|
{
|
||||||
// Generate correct solution
|
// Generate correct solution
|
||||||
T goldA = 0.1;
|
T goldA = 0.1;
|
||||||
T goldB = 0.2;
|
T goldB = 0.2;
|
||||||
T goldC = 0.0;
|
T goldC = 0.0;
|
||||||
|
T golSum = 0.0;
|
||||||
|
|
||||||
const T scalar = 0.3;
|
const T scalar = 0.3;
|
||||||
|
|
||||||
@ -238,6 +242,9 @@ void check_solution(const unsigned int ntimes, std::vector<T>& a, std::vector<T>
|
|||||||
goldA = goldB + scalar * goldC;
|
goldA = goldB + scalar * goldC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do the reduction
|
||||||
|
goldSum = goldA * goldB * ntimes;
|
||||||
|
|
||||||
// Calculate the average error
|
// Calculate the average error
|
||||||
double errA = std::accumulate(a.begin(), a.end(), 0.0, [&](double sum, const T val){ return sum + fabs(val - goldA); });
|
double errA = std::accumulate(a.begin(), a.end(), 0.0, [&](double sum, const T val){ return sum + fabs(val - goldA); });
|
||||||
errA /= a.size();
|
errA /= a.size();
|
||||||
@ -245,6 +252,7 @@ void check_solution(const unsigned int ntimes, std::vector<T>& a, std::vector<T>
|
|||||||
errB /= b.size();
|
errB /= b.size();
|
||||||
double errC = std::accumulate(c.begin(), c.end(), 0.0, [&](double sum, const T val){ return sum + fabs(val - goldC); });
|
double errC = std::accumulate(c.begin(), c.end(), 0.0, [&](double sum, const T val){ return sum + fabs(val - goldC); });
|
||||||
errC /= c.size();
|
errC /= c.size();
|
||||||
|
double errSum = fabs(sum - goldSum);
|
||||||
|
|
||||||
double epsi = std::numeric_limits<T>::epsilon() * 100.0;
|
double epsi = std::numeric_limits<T>::epsilon() * 100.0;
|
||||||
|
|
||||||
@ -260,6 +268,10 @@ void check_solution(const unsigned int ntimes, std::vector<T>& a, std::vector<T>
|
|||||||
std::cerr
|
std::cerr
|
||||||
<< "Validation failed on c[]. Average error " << errC
|
<< "Validation failed on c[]. Average error " << errC
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
if (errSum > epsi)
|
||||||
|
std::cerr
|
||||||
|
<< "Validation failed on sum. Error " << errSum
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user