-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathConfiguration.hh
243 lines (201 loc) · 8.16 KB
/
Configuration.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*!
\file Configuration.hh
*/
#ifndef SPATTER_CONFIGURATION_HH
#define SPATTER_CONFIGURATION_HH
#include <algorithm>
#include <cctype>
#include <experimental/iterator>
#include <iomanip>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
#include <vector>
#ifdef USE_MPI
#include "mpi.h"
#endif
#ifdef USE_OPENMP
#include <omp.h>
#endif
#ifdef USE_CUDA
#include "CudaBackend.hh"
#include <cuda.h>
#include <cuda_runtime_api.h>
// stackoverflow.com/questions/14038589/what-is-the-canonical-way-to-check-for-errors-using-the-cuda-runtime-api
#define checkCudaErrors(ans) \
{ gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(
cudaError_t code, const char *file, int line, bool abort = true) {
if (code != cudaSuccess) {
std::cerr << "checkCudaErrors: " << cudaGetErrorString(code) << " " << file
<< " " << line << std::endl;
if (abort)
exit(code);
}
}
#endif
#include "AlignedAllocator.hh"
#include "SpatterTypes.hh"
#include "Timer.hh"
#define ALIGN 64
template <typename T>
using aligned_vector = std::vector<T, aligned_allocator<T, ALIGN>>;
namespace Spatter {
class ConfigurationBase {
public:
ConfigurationBase(const size_t id, const std::string name, std::string k,
const aligned_vector<size_t> &pattern,
const aligned_vector<size_t> &pattern_gather,
const aligned_vector<size_t> &pattern_scatter,
aligned_vector<double> &sparse, double *&dev_sparse, size_t &sparse_size,
aligned_vector<double> &sparse_gather, double *&dev_sparse_gather,
size_t &sparse_gather_size, aligned_vector<double> &sparse_scatter,
double *&dev_sparse_scatter, size_t &sparse_scatter_size,
aligned_vector<double> &dense,
aligned_vector<aligned_vector<double>> &dense_perthread,
double *&dev_dense, size_t &dense_size, const size_t delta,
const size_t delta_gather, const size_t delta_scatter,
const long int seed, const size_t wrap, const size_t count,
const size_t shared_mem, const size_t local_work_size, const int nthreads,
const unsigned long nruns, const bool aggregate, const bool atomic,
const unsigned long verbosity);
virtual ~ConfigurationBase();
virtual int run(bool timed, unsigned long run_id);
virtual void gather(bool timed, unsigned long run_id) = 0;
virtual void scatter(bool timed, unsigned long run_id) = 0;
virtual void scatter_gather(bool timed, unsigned long run_id) = 0;
virtual void multi_gather(bool timed, unsigned long run_id) = 0;
virtual void multi_scatter(bool timed, unsigned long run_id) = 0;
virtual void report();
virtual void setup();
private:
void print_no_mpi(
size_t bytes_per_run, double minimum_time, double maximum_bandwidth);
#ifdef USE_MPI
void print_mpi(std::vector<unsigned long long> &vector_bytes_per_run,
std::vector<double> &vector_minimum_time,
std::vector<double> &vector_maximum_bandwidth);
#endif
public:
const size_t id;
const std::string name;
std::string kernel;
const aligned_vector<size_t> pattern;
const aligned_vector<size_t> pattern_gather;
const aligned_vector<size_t> pattern_scatter;
aligned_vector<double> &sparse;
double *&dev_sparse;
size_t &sparse_size;
aligned_vector<double> &sparse_gather;
double *&dev_sparse_gather;
size_t &sparse_gather_size;
aligned_vector<double> &sparse_scatter;
double *&dev_sparse_scatter;
size_t &sparse_scatter_size;
aligned_vector<double> &dense;
aligned_vector<aligned_vector<double>> &dense_perthread;
double *&dev_dense;
size_t &dense_size;
const size_t delta;
const size_t delta_gather;
const size_t delta_scatter;
long int seed;
const size_t wrap;
const size_t count;
size_t shmem;
size_t local_work_size;
const int omp_threads;
const unsigned long nruns;
const bool aggregate;
const bool atomic;
const unsigned long verbosity;
Spatter::Timer timer;
std::vector<double> time_seconds;
};
std::ostream &operator<<(std::ostream &out, const ConfigurationBase &config);
template <typename Backend> class Configuration : public ConfigurationBase {};
template <> class Configuration<Spatter::Serial> : public ConfigurationBase {
public:
Configuration(const size_t id, const std::string name,
const std::string kernel, const aligned_vector<size_t> &pattern,
const aligned_vector<size_t> &pattern_gather,
const aligned_vector<size_t> &pattern_scatter,
aligned_vector<double> &sparse, double *&dev_sparse, size_t &sparse_size,
aligned_vector<double> &sparse_gather, double *&dev_sparse_gather,
size_t &sparse_gather_size, aligned_vector<double> &sparse_scatter,
double *&dev_sparse_scatter, size_t &sparse_scatter_size,
aligned_vector<double> &dense,
aligned_vector<aligned_vector<double>> &dense_perthread,
double *&dev_dense, size_t &dense_size, const size_t delta,
const size_t delta_gather, const size_t delta_scatter,
const long int seed, const size_t wrap, const size_t count,
const unsigned long nruns, const bool aggregate,
const unsigned long verbosity);
void gather(bool timed, unsigned long run_id);
void scatter(bool timed, unsigned long run_id);
void scatter_gather(bool timed, unsigned long run_id);
void multi_gather(bool timed, unsigned long run_id);
void multi_scatter(bool timed, unsigned long run_id);
};
#ifdef USE_OPENMP
template <> class Configuration<Spatter::OpenMP> : public ConfigurationBase {
public:
Configuration(const size_t id, const std::string name,
const std::string kernel, const aligned_vector<size_t> &pattern,
const aligned_vector<size_t> &pattern_gather,
aligned_vector<size_t> &pattern_scatter,
aligned_vector<double> &sparse, double *&dev_sparse, size_t &sparse_size,
aligned_vector<double> &sparse_gather, double *&dev_sparse_gather,
size_t &sparse_gather_size, aligned_vector<double> &sparse_scatter,
double *&dev_sparse_scatter, size_t &sparse_scatter_size,
aligned_vector<double> &dense,
aligned_vector<aligned_vector<double>> &dense_perthread,
double *&dev_dense, size_t &dense_size, const size_t delta,
const size_t delta_gather, const size_t delta_scatter,
const long int seed, const size_t wrap, const size_t count,
const int nthreads, const unsigned long nruns, const bool aggregate,
const bool atomic, const unsigned long verbosity);
int run(bool timed, unsigned long run_id);
void gather(bool timed, unsigned long run_id);
void scatter(bool timed, unsigned long run_id);
void scatter_gather(bool timed, unsigned long run_id);
void multi_gather(bool timed, unsigned long run_id);
void multi_scatter(bool timed, unsigned long run_id);
};
#endif
#ifdef USE_CUDA
template <> class Configuration<Spatter::CUDA> : public ConfigurationBase {
public:
Configuration(const size_t id, const std::string name,
const std::string kernel, const aligned_vector<size_t> &pattern,
const aligned_vector<size_t> &pattern_gather,
const aligned_vector<size_t> &pattern_scatter,
aligned_vector<double> &sparse, double *&dev_sparse, size_t &sparse_size,
aligned_vector<double> &sparse_gather, double *&dev_sparse_gather,
size_t &sparse_gather_size, aligned_vector<double> &sparse_scatter,
double *&dev_sparse_scatter, size_t &sparse_scatter_size,
aligned_vector<double> &dense,
aligned_vector<aligned_vector<double>> &dense_perthread,
double *&dev_dense, size_t &dense_size, const size_t delta,
const size_t delta_gather, const size_t delta_scatter,
const long int seed, const size_t wrap, const size_t count,
const size_t shared_mem, const size_t local_work_size,
const unsigned long nruns, const bool aggregate, const bool atomic,
const unsigned long verbosity);
~Configuration();
int run(bool timed, unsigned long run_id);
void gather(bool timed, unsigned long run_id);
void scatter(bool timed, unsigned long run_id);
void scatter_gather(bool timed, unsigned long run_id);
void multi_gather(bool timed, unsigned long run_id);
void multi_scatter(bool timed, unsigned long run_id);
void setup();
public:
size_t *dev_pattern;
size_t *dev_pattern_gather;
size_t *dev_pattern_scatter;
};
#endif
} // namespace Spatter
#endif