Skip to content

Commit e6399e9

Browse files
tom91136gonzalobg
authored andcommitted
Add serial model
1 parent e1fffc0 commit e6399e9

File tree

7 files changed

+193
-0
lines changed

7 files changed

+193
-0
lines changed

Diff for: CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ endif ()
146146
include(cmake/register_models.cmake)
147147

148148
# register out models <model_name> <preprocessor_def_name> <source files...>
149+
register_model(serial SERIAL SerialStream.cpp)
149150
register_model(omp OMP OMPStream.cpp)
150151
register_model(ocl OCL OCLStream.cpp)
151152
register_model(std-data STD_DATA STDDataStream.cpp)

Diff for: src/StreamModels.h

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "SYCLStream2020.h"
3232
#elif defined(OMP)
3333
#include "OMPStream.h"
34+
#elif defined(SERIAL)
35+
#include "SerialStream.h"
3436
#elif defined(FUTHARK)
3537
#include "FutharkStream.h"
3638
#endif
@@ -93,6 +95,10 @@ std::unique_ptr<Stream<T>> make_stream(intptr_t array_size, int deviceIndex) {
9395
// Use the OpenMP implementation
9496
return std::make_unique<OMPStream<T>>(array_size, deviceIndex);
9597

98+
#elif defined(SERIAL)
99+
// Use the Serial implementation
100+
return std::make_unique<SerialStream<T>>(array_size, deviceIndex);
101+
96102
#elif defined(FUTHARK)
97103
// Use the Futhark implementation
98104
return std::make_unique<FutharkStream<T>>(array_size, deviceIndex);

Diff for: src/ci-test-compile.sh

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ build_gcc() {
138138
local name="gcc_build"
139139
local cxx="-DCMAKE_CXX_COMPILER=${GCC_CXX:?}"
140140

141+
run_build $name "${GCC_CXX:?}" serial "$cxx"
141142
run_build $name "${GCC_CXX:?}" omp "$cxx"
142143
if [ "$MODEL" = "all" ] || [ "$MODEL" = "OMP" ]; then
143144
# sanity check that it at least runs
@@ -219,6 +220,7 @@ build_gcc() {
219220
build_clang() {
220221
local name="clang_build"
221222
local cxx="-DCMAKE_CXX_COMPILER=${CLANG_CXX:?}"
223+
run_build $name "${CLANG_CXX:?}" serial "$cxx"
222224
run_build $name "${CLANG_CXX:?}" omp "$cxx"
223225

224226
if [ "${CLANG_OMP_OFFLOAD_AMD:-false}" != "false" ]; then
@@ -276,6 +278,7 @@ build_nvhpc() {
276278
}
277279

278280
build_aocc() {
281+
run_build aocc_build "${AOCC_CXX:?}" serial "-DCMAKE_CXX_COMPILER=${AOCC_CXX:?}"
279282
run_build aocc_build "${AOCC_CXX:?}" omp "-DCMAKE_CXX_COMPILER=${AOCC_CXX:?}"
280283
}
281284

@@ -309,6 +312,7 @@ build_icpc() {
309312
set -u
310313
local name="intel_build"
311314
local cxx="-DCMAKE_CXX_COMPILER=${ICPC_CXX:?}"
315+
run_build $name "${ICPC_CXX:?}" serial "$cxx"
312316
run_build $name "${ICPC_CXX:?}" omp "$cxx"
313317
run_build $name "${ICPC_CXX:?}" ocl "$cxx -DOpenCL_LIBRARY=${OCL_LIB:?}"
314318
if check_cmake_ver "3.20.0"; then

Diff for: src/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define VERSION_STRING "5.0"
2020

2121
#include "Stream.h"
22+
2223
#include "StreamModels.h"
2324
#include "Unit.h"
2425

Diff for: src/serial/SerialStream.cpp

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
2+
// Copyright (c) 2015-16 Tom Deakin, Simon McIntosh-Smith, Tom Lin
3+
// University of Bristol HPC
4+
//
5+
// For full license terms please see the LICENSE file distributed with this
6+
// source code
7+
8+
#include <cstdlib> // For aligned_alloc
9+
#include "SerialStream.h"
10+
11+
#ifndef ALIGNMENT
12+
#define ALIGNMENT (2*1024*1024) // 2MB
13+
#endif
14+
15+
template <class T>
16+
SerialStream<T>::SerialStream(const intptr_t ARRAY_SIZE, int device)
17+
{
18+
array_size = ARRAY_SIZE;
19+
20+
// Allocate on the host
21+
this->a = (T*)aligned_alloc(ALIGNMENT, sizeof(T)*array_size);
22+
this->b = (T*)aligned_alloc(ALIGNMENT, sizeof(T)*array_size);
23+
this->c = (T*)aligned_alloc(ALIGNMENT, sizeof(T)*array_size);
24+
}
25+
26+
template <class T>
27+
SerialStream<T>::~SerialStream()
28+
{
29+
free(a);
30+
free(b);
31+
free(c);
32+
}
33+
34+
template <class T>
35+
void SerialStream<T>::init_arrays(T initA, T initB, T initC)
36+
{
37+
intptr_t array_size = this->array_size;
38+
for (intptr_t i = 0; i < array_size; i++)
39+
{
40+
a[i] = initA;
41+
b[i] = initB;
42+
c[i] = initC;
43+
}
44+
}
45+
46+
template <class T>
47+
void SerialStream<T>::read_arrays(std::vector<T>& h_a, std::vector<T>& h_b, std::vector<T>& h_c)
48+
{
49+
for (intptr_t i = 0; i < array_size; i++)
50+
{
51+
h_a[i] = a[i];
52+
h_b[i] = b[i];
53+
h_c[i] = c[i];
54+
}
55+
56+
}
57+
58+
template <class T>
59+
void SerialStream<T>::copy()
60+
{
61+
for (intptr_t i = 0; i < array_size; i++)
62+
{
63+
c[i] = a[i];
64+
}
65+
}
66+
67+
template <class T>
68+
void SerialStream<T>::mul()
69+
{
70+
const T scalar = startScalar;
71+
for (intptr_t i = 0; i < array_size; i++)
72+
{
73+
b[i] = scalar * c[i];
74+
}
75+
}
76+
77+
template <class T>
78+
void SerialStream<T>::add()
79+
{
80+
for (intptr_t i = 0; i < array_size; i++)
81+
{
82+
c[i] = a[i] + b[i];
83+
}
84+
}
85+
86+
template <class T>
87+
void SerialStream<T>::triad()
88+
{
89+
const T scalar = startScalar;
90+
for (intptr_t i = 0; i < array_size; i++)
91+
{
92+
a[i] = b[i] + scalar * c[i];
93+
}
94+
}
95+
96+
template <class T>
97+
void SerialStream<T>::nstream()
98+
{
99+
const T scalar = startScalar;
100+
for (intptr_t i = 0; i < array_size; i++)
101+
{
102+
a[i] += b[i] + scalar * c[i];
103+
}
104+
}
105+
106+
template <class T>
107+
T SerialStream<T>::dot()
108+
{
109+
T sum{};
110+
for (intptr_t i = 0; i < array_size; i++)
111+
{
112+
sum += a[i] * b[i];
113+
}
114+
return sum;
115+
}
116+
117+
118+
119+
void listDevices(void)
120+
{
121+
std::cout << "0: CPU" << std::endl;
122+
}
123+
124+
std::string getDeviceName(const int)
125+
{
126+
return std::string("Device name unavailable");
127+
}
128+
129+
std::string getDeviceDriver(const int)
130+
{
131+
return std::string("Device driver unavailable");
132+
}
133+
template class SerialStream<float>;
134+
template class SerialStream<double>;

Diff for: src/serial/SerialStream.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
// Copyright (c) 2015-16 Tom Deakin, Simon McIntosh-Smith, Tom Lin
3+
// University of Bristol HPC
4+
//
5+
// For full license terms please see the LICENSE file distributed with this
6+
// source code
7+
8+
#pragma once
9+
10+
#include <iostream>
11+
#include <stdexcept>
12+
13+
#include "Stream.h"
14+
15+
16+
#define IMPLEMENTATION_STRING "Serial"
17+
18+
template <class T>
19+
class SerialStream : public Stream<T>
20+
{
21+
protected:
22+
// Size of arrays
23+
intptr_t array_size;
24+
25+
// Device side pointers
26+
T *a;
27+
T *b;
28+
T *c;
29+
30+
public:
31+
SerialStream(const intptr_t, int);
32+
~SerialStream();
33+
34+
virtual void copy() override;
35+
virtual void add() override;
36+
virtual void mul() override;
37+
virtual void triad() override;
38+
virtual void nstream() override;
39+
virtual T dot() override;
40+
41+
virtual void init_arrays(T initA, T initB, T initC) override;
42+
virtual void read_arrays(std::vector<T>& a, std::vector<T>& b, std::vector<T>& c) override;
43+
};

Diff for: src/serial/model.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
macro(setup)
2+
# Nothing to do
3+
endmacro()
4+

0 commit comments

Comments
 (0)