diff options
-rw-r--r-- | src/tuning/tuning.hpp | 13 | ||||
-rw-r--r-- | src/utilities.cpp | 20 | ||||
-rw-r--r-- | src/utilities.hpp | 2 | ||||
-rw-r--r-- | test/correctness/testblas.cpp | 14 | ||||
-rw-r--r-- | test/correctness/testblas.hpp | 1 | ||||
-rw-r--r-- | test/performance/client.cpp | 14 | ||||
-rw-r--r-- | test/performance/client.hpp | 1 |
7 files changed, 34 insertions, 31 deletions
diff --git a/src/tuning/tuning.hpp b/src/tuning/tuning.hpp index 19df5f9a..13bae5a6 100644 --- a/src/tuning/tuning.hpp +++ b/src/tuning/tuning.hpp @@ -30,6 +30,7 @@ namespace clblast { // that it is automatically compiled for the various kernels (given as the 'C' template argument). template <typename C, typename T> void Tuner(int argc, char* argv[]) { + constexpr auto kSeed = 42; // fixed seed for reproducibility // Sets the parameters and platform/device for which to tune (command-line options) auto help = std::string{"* Options given/available:\n"}; @@ -73,12 +74,12 @@ 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); - PopulateVector(y_vec); - PopulateVector(a_mat); - PopulateVector(b_mat); - PopulateVector(c_mat); - PopulateVector(temp); + PopulateVector(x_vec, kSeed); + PopulateVector(y_vec, kSeed); + PopulateVector(a_mat, kSeed); + PopulateVector(b_mat, kSeed); + PopulateVector(c_mat, kSeed); + PopulateVector(temp, kSeed); // Initializes the tuner for the chosen device cltune::Tuner tuner(args.platform_id, args.device_id); diff --git a/src/utilities.cpp b/src/utilities.cpp index 77bc72d7..86cc2d13 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -270,40 +270,40 @@ 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) { +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(GetRandomSeed()); + std::mt19937 mt(seed); std::uniform_real_distribution<T> dist(lower_limit, upper_limit); for (auto &element: vector) { element = dist(mt); } } -template void PopulateVector<float>(std::vector<float>&); -template void PopulateVector<double>(std::vector<double>&); +template void PopulateVector<float>(std::vector<float>&, const unsigned int); +template void PopulateVector<double>(std::vector<double>&, const unsigned int); // Specialized versions of the above for complex data-types template <> -void PopulateVector(std::vector<float2> &vector) { +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(GetRandomSeed()); + 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)); } } template <> -void PopulateVector(std::vector<double2> &vector) { +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(GetRandomSeed()); + std::mt19937 mt(seed); std::uniform_real_distribution<double> dist(lower_limit, upper_limit); 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) { +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(GetRandomSeed()); + std::mt19937 mt(seed); std::uniform_real_distribution<float> dist(lower_limit, upper_limit); for (auto &element: vector) { element = FloatToHalf(dist(mt)); } } diff --git a/src/utilities.hpp b/src/utilities.hpp index 75bd5a69..71bfc1af 100644 --- a/src/utilities.hpp +++ b/src/utilities.hpp @@ -219,7 +219,7 @@ constexpr auto kTestDataUpperLimit = 2.0; // Populates a vector with random data template <typename T> -void PopulateVector(std::vector<T> &vector); +void PopulateVector(std::vector<T> &vector, const unsigned int seed); // ================================================================================================= diff --git a/test/correctness/testblas.cpp b/test/correctness/testblas.cpp index 2e751255..fc908b9e 100644 --- a/test/correctness/testblas.cpp +++ b/test/correctness/testblas.cpp @@ -66,13 +66,13 @@ TestBlas<T,U>::TestBlas(int argc, char *argv[], const bool silent, 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_); - PopulateVector(y_source_); - PopulateVector(a_source_); - PopulateVector(b_source_); - PopulateVector(c_source_); - PopulateVector(ap_source_); - PopulateVector(scalar_source_); + 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); } // =============================================================================================== diff --git a/test/correctness/testblas.hpp b/test/correctness/testblas.hpp index d01cd06c..4b773801 100644 --- a/test/correctness/testblas.hpp +++ b/test/correctness/testblas.hpp @@ -30,6 +30,7 @@ namespace clblast { template <typename T, typename U> class TestBlas: public Tester<T,U> { public: + static constexpr auto kSeed = 42; // fixed seed for reproducibility // Uses several variables from the Tester class using Tester<T,U>::context_; diff --git a/test/performance/client.cpp b/test/performance/client.cpp index aaaab22e..cbb10d10 100644 --- a/test/performance/client.cpp +++ b/test/performance/client.cpp @@ -178,13 +178,13 @@ 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); - PopulateVector(y_source); - PopulateVector(a_source); - PopulateVector(b_source); - PopulateVector(c_source); - PopulateVector(ap_source); - PopulateVector(scalar_source); + 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); // Creates the matrices on the device auto x_vec = Buffer<T>(context, args.x_size); diff --git a/test/performance/client.hpp b/test/performance/client.hpp index 6d35fced..381ba158 100644 --- a/test/performance/client.hpp +++ b/test/performance/client.hpp @@ -40,6 +40,7 @@ namespace clblast { template <typename T, typename U> class Client { public: + static constexpr auto kSeed = 42; // fixed seed for reproducibility // Shorthand for the routine-specific functions passed to the tester using Routine = std::function<StatusCode(const Arguments<U>&, Buffers<T>&, Queue&)>; |