diff --git a/src/StreamModels.h b/src/StreamModels.h index b803b0f1..b13d5b34 100644 --- a/src/StreamModels.h +++ b/src/StreamModels.h @@ -97,7 +97,7 @@ std::unique_ptr> make_stream(Args... args) { #elif defined(SERIAL) // Use the Serial implementation - return std::make_unique>(array_size, deviceIndex); + return std::make_unique>(args...); #elif defined(FUTHARK) // Use the Futhark implementation diff --git a/src/main.cpp b/src/main.cpp index 55fd6f43..604e14a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -328,10 +328,11 @@ void check_solution(const size_t num_times, T const* a, T const* b, T const* c, abort(); } - // Error relative tolerance check + // Error relative tolerance check - a higher tolerance is used for reductions. size_t failed = 0; - T max_rel = std::numeric_limits::epsilon() * T(1000000.0); - auto check = [&](const char* name, T is, T should, size_t i = size_t(-1)) { + T max_rel = std::numeric_limits::epsilon() * T(100.0); + T max_rel_dot = std::numeric_limits::epsilon() * T(10000000.0); + auto check = [&](const char* name, T is, T should, T max_rel, size_t i = size_t(-1)) { // Relative difference: T diff = std::abs(is - should); T abs_is = std::abs(is); @@ -353,15 +354,15 @@ void check_solution(const size_t num_times, T const* a, T const* b, T const* c, for (size_t i = 0; i < num_benchmarks; ++i) { if (bench[i].id != BenchId::Dot) continue; if (run_benchmark(bench[i])) - check("sum", sum, goldS); + check("sum", sum, goldS, max_rel_dot); break; } // Calculate the L^infty-norm relative error for (size_t i = 0; i < array_size; ++i) { - check("a", a[i], goldA, i); - check("b", b[i], goldB, i); - check("c", c[i], goldC, i); + check("a", a[i], goldA, i, max_rel); + check("b", b[i], goldB, i, max_rel); + check("c", c[i], goldC, i, max_rel); } if (failed > 0 && !silence_errors) diff --git a/src/serial/SerialStream.cpp b/src/serial/SerialStream.cpp index 0fc0fdb1..394a657c 100644 --- a/src/serial/SerialStream.cpp +++ b/src/serial/SerialStream.cpp @@ -13,14 +13,16 @@ #endif template -SerialStream::SerialStream(const intptr_t ARRAY_SIZE, int device) +SerialStream::SerialStream(BenchId bs, const intptr_t array_size, const int device_id, + T initA, T initB, T initC) + : array_size{array_size} { - array_size = ARRAY_SIZE; - // Allocate on the host this->a = (T*)aligned_alloc(ALIGNMENT, sizeof(T)*array_size); this->b = (T*)aligned_alloc(ALIGNMENT, sizeof(T)*array_size); this->c = (T*)aligned_alloc(ALIGNMENT, sizeof(T)*array_size); + + init_arrays(initA, initB, initC); } template @@ -44,15 +46,11 @@ void SerialStream::init_arrays(T initA, T initB, T initC) } template -void SerialStream::read_arrays(std::vector& h_a, std::vector& h_b, std::vector& h_c) +void SerialStream::get_arrays(T const*& h_a, T const*& h_b, T const*& h_c) { - for (intptr_t i = 0; i < array_size; i++) - { - h_a[i] = a[i]; - h_b[i] = b[i]; - h_c[i] = c[i]; - } - + h_a = a; + h_b = b; + h_c = c; } template diff --git a/src/serial/SerialStream.h b/src/serial/SerialStream.h index 3c62d296..9f5653d4 100644 --- a/src/serial/SerialStream.h +++ b/src/serial/SerialStream.h @@ -23,21 +23,20 @@ class SerialStream : public Stream intptr_t array_size; // Device side pointers - T *a; - T *b; - T *c; + T *a, *b, *c; public: - SerialStream(const intptr_t, int); + SerialStream(BenchId bs, const intptr_t array_size, const int device_id, + T initA, T initB, T initC); ~SerialStream(); - virtual void copy() override; - virtual void add() override; - virtual void mul() override; - virtual void triad() override; - virtual void nstream() override; - virtual T dot() override; + void copy() override; + void add() override; + void mul() override; + void triad() override; + void nstream() override; + T dot() override; - virtual void init_arrays(T initA, T initB, T initC) override; - virtual void read_arrays(std::vector& a, std::vector& b, std::vector& c) override; + void get_arrays(T const*& a, T const*& b, T const*& c) override; + void init_arrays(T initA, T initB, T initC); };