summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2017-03-05 11:13:47 +0100
committerCedric Nugteren <web@cedricnugteren.nl>2017-03-05 11:13:47 +0100
commit7f14b11f1e240f12f5f6bf93cbbeab26001e9a5c (patch)
tree1ef26380cac190c11a8eea68b90d05f0593c2738
parentf9a520b3aff7b4eec99d9e11a03f9467e7ab351c (diff)
Changed the way the test-data is generated: now using a single MT generator and distribution for all data
-rw-r--r--src/tuning/tuning.hpp15
-rw-r--r--src/utilities/utilities.cpp37
-rw-r--r--src/utilities/utilities.hpp3
-rw-r--r--test/correctness/misc/override_parameters.cpp15
-rw-r--r--test/correctness/testblas.cpp18
-rw-r--r--test/performance/client.cpp22
-rw-r--r--test/routines/levelx/xinvert.hpp2
7 files changed, 58 insertions, 54 deletions
diff --git a/src/tuning/tuning.hpp b/src/tuning/tuning.hpp
index 1dd76894..7060fc9f 100644
--- a/src/tuning/tuning.hpp
+++ b/src/tuning/tuning.hpp
@@ -17,6 +17,7 @@
#include <vector>
#include <string>
+#include <random>
#include <cltune.h>
@@ -77,12 +78,14 @@ void Tuner(int argc, char* argv[]) {
auto b_mat = std::vector<T>(C::GetSizeB(args));
auto c_mat = std::vector<T>(C::GetSizeC(args));
auto temp = std::vector<T>(C::GetSizeTemp(args));
- PopulateVector(x_vec, kSeed);
- PopulateVector(y_vec, kSeed);
- PopulateVector(a_mat, kSeed);
- PopulateVector(b_mat, kSeed);
- PopulateVector(c_mat, kSeed);
- PopulateVector(temp, kSeed);
+ std::mt19937 mt(kSeed);
+ std::uniform_real_distribution<double> dist(kTestDataLowerLimit, kTestDataUpperLimit);
+ PopulateVector(x_vec, mt, dist);
+ PopulateVector(y_vec, mt, dist);
+ PopulateVector(a_mat, mt, dist);
+ PopulateVector(b_mat, mt, dist);
+ PopulateVector(c_mat, mt, dist);
+ PopulateVector(temp, mt, dist);
// Initializes the tuner for the chosen device
cltune::Tuner tuner(args.platform_id, args.device_id);
diff --git a/src/utilities/utilities.cpp b/src/utilities/utilities.cpp
index d68cc1a6..89265bd6 100644
--- a/src/utilities/utilities.cpp
+++ b/src/utilities/utilities.cpp
@@ -326,42 +326,29 @@ unsigned int GetRandomSeed() {
// Create a random number generator and populates a vector with samples from a random distribution
template <typename T>
-void PopulateVector(std::vector<T> &vector, const unsigned int seed) {
- auto lower_limit = static_cast<T>(kTestDataLowerLimit);
- auto upper_limit = static_cast<T>(kTestDataUpperLimit);
- std::mt19937 mt(seed);
- std::uniform_real_distribution<T> dist(lower_limit, upper_limit);
- for (auto &element: vector) { element = dist(mt); }
+void PopulateVector(std::vector<T> &vector, std::mt19937 &mt, std::uniform_real_distribution<double> &dist) {
+ for (auto &element: vector) { element = static_cast<T>(dist(mt)); }
}
-template void PopulateVector<float>(std::vector<float>&, const unsigned int);
-template void PopulateVector<double>(std::vector<double>&, const unsigned int);
+template void PopulateVector<float>(std::vector<float>&, std::mt19937&, std::uniform_real_distribution<double>&);
+template void PopulateVector<double>(std::vector<double>&, std::mt19937&, std::uniform_real_distribution<double>&);
// Specialized versions of the above for complex data-types
template <>
-void PopulateVector(std::vector<float2> &vector, const unsigned int seed) {
- auto lower_limit = static_cast<float>(kTestDataLowerLimit);
- auto upper_limit = static_cast<float>(kTestDataUpperLimit);
- std::mt19937 mt(seed);
- std::uniform_real_distribution<float> dist(lower_limit, upper_limit);
- for (auto &element: vector) { element.real(dist(mt)); element.imag(dist(mt)); }
+void PopulateVector(std::vector<float2> &vector, std::mt19937 &mt, std::uniform_real_distribution<double> &dist) {
+ for (auto &element: vector) {
+ element.real(static_cast<float>(dist(mt)));
+ element.imag(static_cast<float>(dist(mt)));
+ }
}
template <>
-void PopulateVector(std::vector<double2> &vector, const unsigned int seed) {
- auto lower_limit = static_cast<double>(kTestDataLowerLimit);
- auto upper_limit = static_cast<double>(kTestDataUpperLimit);
- std::mt19937 mt(seed);
- std::uniform_real_distribution<double> dist(lower_limit, upper_limit);
+void PopulateVector(std::vector<double2> &vector, std::mt19937 &mt, std::uniform_real_distribution<double> &dist) {
for (auto &element: vector) { element.real(dist(mt)); element.imag(dist(mt)); }
}
// Specialized versions of the above for half-precision
template <>
-void PopulateVector(std::vector<half> &vector, const unsigned int seed) {
- const auto lower_limit = static_cast<float>(kTestDataLowerLimit);
- const auto upper_limit = static_cast<float>(kTestDataUpperLimit);
- std::mt19937 mt(seed);
- std::uniform_real_distribution<float> dist(lower_limit, upper_limit);
- for (auto &element: vector) { element = FloatToHalf(dist(mt)); }
+void PopulateVector(std::vector<half> &vector, std::mt19937 &mt, std::uniform_real_distribution<double> &dist) {
+ for (auto &element: vector) { element = FloatToHalf(static_cast<float>(dist(mt))); }
}
// =================================================================================================
diff --git a/src/utilities/utilities.hpp b/src/utilities/utilities.hpp
index 3c9be6a2..330db597 100644
--- a/src/utilities/utilities.hpp
+++ b/src/utilities/utilities.hpp
@@ -20,6 +20,7 @@
#include <string>
#include <functional>
#include <complex>
+#include <random>
#include "clpp11.hpp"
#include "clblast.h"
@@ -234,7 +235,7 @@ constexpr auto kTestDataUpperLimit = 2.0;
// Populates a vector with random data
template <typename T>
-void PopulateVector(std::vector<T> &vector, const unsigned int seed);
+void PopulateVector(std::vector<T> &vector, std::mt19937 &mt, std::uniform_real_distribution<double> &dist);
// =================================================================================================
diff --git a/test/correctness/misc/override_parameters.cpp b/test/correctness/misc/override_parameters.cpp
index a4cecf0d..e6eebef7 100644
--- a/test/correctness/misc/override_parameters.cpp
+++ b/test/correctness/misc/override_parameters.cpp
@@ -11,11 +11,14 @@
//
// =================================================================================================
+#include <string>
+#include <vector>
+#include <unordered_map>
+#include <random>
+
#include "utilities/utilities.hpp"
#include "test/routines/level3/xgemm.hpp"
-#include <unordered_map>
-
namespace clblast {
// =================================================================================================
@@ -71,9 +74,11 @@ size_t RunOverrideTests(int argc, char *argv[], const bool silent, const std::st
auto host_a = std::vector<T>(args.m * args.k);
auto host_b = std::vector<T>(args.n * args.k);
auto host_c = std::vector<T>(args.m * args.n);
- PopulateVector(host_a, kSeed);
- PopulateVector(host_b, kSeed);
- PopulateVector(host_c, kSeed);
+ std::mt19937 mt(kSeed);
+ std::uniform_real_distribution<double> dist(kTestDataLowerLimit, kTestDataUpperLimit);
+ PopulateVector(host_a, mt, dist);
+ PopulateVector(host_b, mt, dist);
+ PopulateVector(host_c, mt, dist);
// Copy the matrices to the device
auto device_a = Buffer<T>(context, host_a.size());
diff --git a/test/correctness/testblas.cpp b/test/correctness/testblas.cpp
index d959ce18..505b3b36 100644
--- a/test/correctness/testblas.cpp
+++ b/test/correctness/testblas.cpp
@@ -13,7 +13,9 @@
#include <algorithm>
#include <iostream>
+#include <random>
+#include "utilities/utilities.hpp"
#include "test/correctness/testblas.hpp"
namespace clblast {
@@ -88,13 +90,15 @@ TestBlas<T,U>::TestBlas(const std::vector<std::string> &arguments, const bool si
c_source_.resize(std::max(max_mat, max_matvec)*std::max(max_ld, max_matvec) + max_offset);
ap_source_.resize(std::max(max_mat, max_matvec)*std::max(max_mat, max_matvec) + max_offset);
scalar_source_.resize(std::max(max_mat, max_matvec) + max_offset);
- PopulateVector(x_source_, kSeed);
- PopulateVector(y_source_, kSeed);
- PopulateVector(a_source_, kSeed);
- PopulateVector(b_source_, kSeed);
- PopulateVector(c_source_, kSeed);
- PopulateVector(ap_source_, kSeed);
- PopulateVector(scalar_source_, kSeed);
+ std::mt19937 mt(kSeed);
+ std::uniform_real_distribution<double> dist(kTestDataLowerLimit, kTestDataUpperLimit);
+ PopulateVector(x_source_, mt, dist);
+ PopulateVector(y_source_, mt, dist);
+ PopulateVector(a_source_, mt, dist);
+ PopulateVector(b_source_, mt, dist);
+ PopulateVector(c_source_, mt, dist);
+ PopulateVector(ap_source_, mt, dist);
+ PopulateVector(scalar_source_, mt, dist);
}
// ===============================================================================================
diff --git a/test/performance/client.cpp b/test/performance/client.cpp
index 2c45b35e..16b44b5a 100644
--- a/test/performance/client.cpp
+++ b/test/performance/client.cpp
@@ -11,13 +11,15 @@
//
// =================================================================================================
-#include "test/performance/client.hpp"
-
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <chrono>
+#include <random>
+
+#include "utilities/utilities.hpp"
+#include "test/performance/client.hpp"
namespace clblast {
// =================================================================================================
@@ -179,13 +181,15 @@ void Client<T,U>::PerformanceTest(Arguments<U> &args, const SetMetric set_sizes)
std::vector<T> c_source(args.c_size);
std::vector<T> ap_source(args.ap_size);
std::vector<T> scalar_source(args.scalar_size);
- PopulateVector(x_source, kSeed);
- PopulateVector(y_source, kSeed);
- PopulateVector(a_source, kSeed);
- PopulateVector(b_source, kSeed);
- PopulateVector(c_source, kSeed);
- PopulateVector(ap_source, kSeed);
- PopulateVector(scalar_source, kSeed);
+ std::mt19937 mt(kSeed);
+ std::uniform_real_distribution<double> dist(kTestDataLowerLimit, kTestDataUpperLimit);
+ PopulateVector(x_source, mt, dist);
+ PopulateVector(y_source, mt, dist);
+ PopulateVector(a_source, mt, dist);
+ PopulateVector(b_source, mt, dist);
+ PopulateVector(c_source, mt, dist);
+ PopulateVector(ap_source, mt, dist);
+ PopulateVector(scalar_source, mt, dist);
// Creates the matrices on the device
auto x_vec = Buffer<T>(context, args.x_size);
diff --git a/test/routines/levelx/xinvert.hpp b/test/routines/levelx/xinvert.hpp
index 05bea9aa..b470dbf3 100644
--- a/test/routines/levelx/xinvert.hpp
+++ b/test/routines/levelx/xinvert.hpp
@@ -19,7 +19,7 @@
#include <vector>
#include <string>
-#include "routines/levelx/xinvert.hpp"
+#include "utilities/utilities.hpp"
namespace clblast {
// =================================================================================================