Skip to content

Commit

Permalink
Update Serial
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalobg committed Jun 5, 2024
1 parent 2929a6c commit 9ff46ec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/StreamModels.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ std::unique_ptr<Stream<T>> make_stream(Args... args) {

#elif defined(SERIAL)
// Use the Serial implementation
return std::make_unique<SerialStream<T>>(array_size, deviceIndex);
return std::make_unique<SerialStream<T>>(args...);

#elif defined(FUTHARK)
// Use the Futhark implementation
Expand Down
15 changes: 8 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>::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<T>::epsilon() * T(100.0);
T max_rel_dot = std::numeric_limits<T>::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);
Expand All @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions src/serial/SerialStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
#endif

template <class T>
SerialStream<T>::SerialStream(const intptr_t ARRAY_SIZE, int device)
SerialStream<T>::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 <class T>
Expand All @@ -44,15 +46,11 @@ void SerialStream<T>::init_arrays(T initA, T initB, T initC)
}

template <class T>
void SerialStream<T>::read_arrays(std::vector<T>& h_a, std::vector<T>& h_b, std::vector<T>& h_c)
void SerialStream<T>::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 <class T>
Expand Down
23 changes: 11 additions & 12 deletions src/serial/SerialStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ class SerialStream : public Stream<T>
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<T>& a, std::vector<T>& b, std::vector<T>& c) override;
void get_arrays(T const*& a, T const*& b, T const*& c) override;
void init_arrays(T initA, T initB, T initC);
};

0 comments on commit 9ff46ec

Please sign in to comment.