-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
524 lines (456 loc) · 21.8 KB
/
main.cpp
File metadata and controls
524 lines (456 loc) · 21.8 KB
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
#include <iostream>
#include <vector>
#include <chrono>
#include <iomanip>
#include <Windows.h>
#include "Simd.h"
using namespace std;
using namespace chrono;
void AddMultipliedScalar(float* dst, const float* src, int n, float coeff);
void AddMultipliedScalarUnrolled(float* dst, const float* src, int n, float coeff);
void AddMultipliedScalarUnrolledRestrict(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedScalarUnrolled2(float* dst, const float* src, int n, float coeff);
void AddMultipliedScalarUnrolled2Restrict(float* __restrict dst, const float* __restrict src, int n, float coeff);
void ExponentiateAddScalar(float* __restrict dst, const float* __restrict src, int n, float dummy);
void Exponentiate2AddScalar(float* __restrict dst, const float* __restrict src, int n, float dummy);
void ExponentiateAddSSE(float* __restrict dst, const float* __restrict src, int n, float dummy);
void ExponentiateAddAVX(float* __restrict dst, const float* __restrict src, int n, float dummy);
void AddMultipliedSimpleSSE(float* dst, const float* src, int n, float coeff);
void AddMultipliedSSE(float* dst, const float* src, int n, float coeff);
void AddMultipliedRestrictSSE(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedSSE2(float* dst, const float* src, int n, float coeff);
void AddMultipliedRestrictSSE2(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedSSE3(float* dst, const float* src, int n, float coeff);
void AddMultipliedRestrictSSE3(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedSSE4(float* dst, const float* src, int n, float coeff);
void AddMultipliedRestrictSSE4(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedSSE5(float* dst, const float* src, int n, float coeff);
void AddMultipliedRestrictSSE5(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddExponentialRestrictSSE(float* __restrict dst, const float* __restrict src, int n, float coeff, float ek = 0.999f);
void AddExponentialRestrictAVX(float* __restrict dst, const float* __restrict src, int n, float coeff, float ek = 0.999f);
void LinearMultiplyAddRestrictSSE(float* __restrict dst, const float* __restrict src, int n, float u, float du = 0.001f);
void LinearMultiplyAddRestrictAVX(float* __restrict dst, const float* __restrict src, int n, float u, float du = 0.001f);
void AddMultipliedAutoSSE(float* dst, const float* src, int n, float coeff);
void AddMultipliedUnrolledAutoSSE(float* dst, const float* src, int n, float coeff);
void AddMultipliedUnrolledRestrictAutoSSE(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedUnrolled2AutoSSE(float* dst, const float* src, int n, float coeff);
void AddMultipliedUnrolled2RestrictAutoSSE(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedSimpleAVX(float* dst, const float* src, int n, float coeff);
void AddMultipliedAVX(float* dst, const float* src, int n, float coeff);
void AddMultipliedRestrictAVX(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedAVX2(float* dst, const float* src, int n, float coeff);
void AddMultipliedRestrictAVX2(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedAVX3(float* dst, const float* src, int n, float coeff);
void AddMultipliedRestrictAVX3(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedRestrictPrefetch1AVX3(float* __restrict dst, const float* __restrict src, int n, float coeff, const float* prefetchSrc);
void AddMultipliedRestrictPrefetch2AVX3(float* __restrict dst, const float* __restrict src, int n, float coeff, const float* prefetchSrc);
void AddMultipliedAVX4(float* dst, const float* src, int n, float coeff);
void AddMultipliedRestrictAVX4(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedAVX5(float* dst, const float* src, int n, float coeff);
void AddMultipliedRestrictAVX5(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedAutoAVX(float* dst, const float* src, int n, float coeff);
void AddMultipliedUnrolledAutoAVX(float* dst, const float* src, int n, float coeff);
void AddMultipliedUnrolledRestrictAutoAVX(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedUnrolled2AutoAVX(float* dst, const float* src, int n, float coeff);
void AddMultipliedUnrolled2RestrictAutoAVX(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedFMA(float* dst, const float* src, int n, float coeff);
void AddMultipliedRestrictFMA(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedRestrictFMA5(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedRestrictFMA6(float* __restrict dst, const float* __restrict src, int n, float coeff);
void AddMultipliedX2RestrictSSE(float* __restrict dst, const float* __restrict srcs[2], int n, const float coeffs[2]);
void AddMultipliedX2RestrictSSE2(float* __restrict dst, const float* __restrict srcs[2], int n, const float coeffs[2]);
void AddMultipliedX2RestrictSSE3(float* __restrict dst, const float* __restrict srcs[2], int n, const float coeffs[2]);
void AddMultipliedX2RestrictSSE4(float* __restrict dst, const float* __restrict srcs[2], int n, const float coeffs[2]);
void AddMultipliedX3RestrictSSE(float* __restrict dst, const float* __restrict srcs[3], int n, const float coeffs[3]);
void AddMultipliedX3RestrictSSE2(float* __restrict dst, const float* __restrict srcs[3], int n, const float coeffs[3]);
void AddMultipliedX2RestrictAVX(float* __restrict dst, const float* __restrict srcs[2], int n, const float coeffs[2]);
void AddMultipliedX3RestrictAVX(float* __restrict dst, const float* __restrict srcs[3], int n, const float coeffs[3]);
void AddMultipliedX3RestrictAVXClass(float* __restrict dst, const float* __restrict srcs[3], int n, const float coeffs[3]);
void AddMultipliedX4RestrictAVX(float* __restrict dst, const float* __restrict srcs[4], int n, const float coeffs[4]);
void AddMultipliedX8RestrictAVX(float* __restrict dst, const float* __restrict srcs[8], int n, const float coeffs[8]);
void AddMultipliedX2RestrictFMA(float* __restrict dst, const float* __restrict srcs[2], int n, const float coeffs[2]);
void AddExponentialX2RestrictSSE(float* __restrict dst, const float* __restrict src[2], int n, const float coeff[2], float ek0 = 0.999f, float ek1 = 0.999f);
void AddExponentialX2RestrictAVX(float* __restrict dst, const float* __restrict src[2], int n, const float coeff[2], float ek0 = 0.999f, float ek1 = 0.999f);
void LinearMultiplyAddX2RestrictSSE(float* __restrict dst, const float* __restrict src[2], int n, const float u[2], float du0 = 0.001f, float du1 = 0.001f);
void LinearMultiplyAddX2RestrictClassSSE(float* __restrict dst, const float* __restrict src[2], int n, const float u[2], float du0 = 0.001f, float du1 = 0.001f);
void LinearMultiplyAddX2RestrictAVX(float* __restrict dst, const float* __restrict src[2], int n, const float u[2], float du0 = 0.001f, float du1 = 0.001f);
void AddInterpolatedScalar(float* __restrict dst, const float* __restrict src, int n, float rate = 1.213f);
void AddInterpolatedSSE(float* __restrict dst, const float* __restrict src, int n, float rate = 1.213f);
float SumAVX(const float* arr, int n);
float SumAVX2(const float* arr, int n);
float SumAVX3(const float* arr, int n);
float SumAVX4(const float* arr, int n);
float SumSSE(const float* arr, int n);
float SumSSE2(const float* arr, int n);
float SumSSE3(const float* arr, int n);
float Sum(const std::vector<float>& v)
{
double sum = 0;
for(float x: v) sum += x;
return float(sum);
}
template<size_t N> float Sum(float(&v)[N])
{
double sum = 0;
for(float x: v) sum += x;
return float(sum);
}
#define TEST(f) {\
alignas(64) float dst[1024]{};\
if(size_t(dst) & 31) cout << "dst is not aligned!" << endl;\
auto t0 = high_resolution_clock::now();\
if(numThreads == 0) for(int k = 0; k < nChunks; k++)\
{\
f(dst, srcs[k], chunkSize, coeffs[k]);\
}\
else for(int thread = 0; thread < numThreads; thread++)\
for(int k = 0; k < nChunks; k++)\
{\
f(dst + thread * chunkSize / numThreads, srcs[k] + thread * chunkSize / numThreads, chunkSize / numThreads, coeffs[k]);\
}\
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;\
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);\
auto fps = 2*srcLen/(time/1000.0f)/1000000000;\
cout << left << setw(40) << #f << right << setw(6) << time << " ms\t"\
<< gbs << " GB/s\tsum = " << Sum(dst) <<\
"\t" << fps << " GFlops/s" << endl;\
}
#define TEST_PREFETCH(f) {\
alignas(64) float dst[1024]{};\
if(size_t(dst) & 31) cout << "dst is not aligned!" << endl;\
auto t0 = high_resolution_clock::now();\
for(int thread = 0; thread < numThreads; thread++)\
for(int k = 0; k < nChunks; k++)\
{\
f(dst + thread * chunkSize / numThreads, srcs[k] + thread * chunkSize / numThreads, chunkSize / numThreads, coeffs[k], k + 2 < nChunks? srcs[k+2]: nullptr);\
}\
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;\
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);\
auto fps = 2*srcLen/(time/1000.0f)/1000000000;\
cout << left << setw(40) << #f << right << setw(6) << time << " ms\t"\
<< gbs << " GB/s\tsum = " << Sum(dst) <<\
"\t" << fps << " GFlops/s" << endl;\
}
#define TEST_X(f, inc) {\
alignas(64) float dst[1024]{};\
if(size_t(dst) & 31) cout << "dst is not aligned!" << endl;\
auto t0 = high_resolution_clock::now();\
for(int k = 0; k < nChunks; k += inc)\
{\
f(dst, srcs + k, chunkSize, coeffs + k);\
}\
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;\
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);\
auto fps = 2*srcLen/(time/1000.0f)/1000000000;\
cout << left << setw(40) << #f << right << setw(6) << time << " ms\t"\
<< gbs << " GB/s\tsum = " << Sum(dst) <<\
"\t" << fps << " GFlops/s" << endl;\
}
#define TEST_REDUCE(f) {\
auto t0 = high_resolution_clock::now();\
auto result = f(srcData, srcLen);\
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;\
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);\
auto fps = srcLen/(time/1000.0f)/1000000000;\
cout << left << setw(40) << #f << right << setw(6) << time << " ms\t"\
<< gbs << " GB/s\tresult = " << result <<\
"\t" << fps << " GFlops/s" << endl;\
}
void RunTests(const float* srcs[], const float* coeffs, int chunkSize, int nChunks, int numThreads)
{
const size_t srcLen = chunkSize * nChunks;
cout << endl << "Scalar" << endl;
TEST(AddMultipliedScalar);
TEST(AddMultipliedScalarUnrolled);
TEST(AddMultipliedScalarUnrolledRestrict);
TEST(AddMultipliedScalarUnrolled2);
TEST(AddMultipliedScalarUnrolled2Restrict);
TEST(AddInterpolatedScalar);
TEST(ExponentiateAddScalar);
TEST(Exponentiate2AddScalar);
cout << endl << "SSE" << endl;
TEST(AddMultipliedSimpleSSE);
TEST(AddMultipliedSSE);
TEST(AddMultipliedRestrictSSE);
TEST(AddMultipliedSSE2);
TEST(AddMultipliedRestrictSSE2);
TEST(AddMultipliedSSE3);
TEST(AddMultipliedRestrictSSE3);
TEST(AddMultipliedSSE4);
TEST(AddMultipliedRestrictSSE4);
TEST(AddMultipliedSSE5);
TEST(AddMultipliedRestrictSSE5);
TEST(AddExponentialRestrictSSE);
TEST(LinearMultiplyAddRestrictSSE);
TEST(AddInterpolatedSSE);
TEST(AddMultipliedAutoSSE);
TEST(AddMultipliedUnrolledAutoSSE);
TEST(AddMultipliedUnrolledRestrictAutoSSE);
TEST(AddMultipliedUnrolled2AutoSSE);
TEST(AddMultipliedUnrolled2RestrictAutoSSE);
TEST(ExponentiateAddSSE);
cout << endl << "AVX" << endl;
if(Simd::IsAvxSupported())
{
TEST(AddMultipliedSimpleAVX);
TEST(AddMultipliedAVX);
TEST(AddMultipliedRestrictAVX);
TEST(AddMultipliedAVX2);
TEST(AddMultipliedRestrictAVX2);
TEST(AddMultipliedAVX3);
TEST(AddMultipliedRestrictAVX3);
TEST(AddMultipliedAVX4);
TEST(AddMultipliedRestrictAVX4);
TEST(AddMultipliedAVX5);
TEST(AddMultipliedRestrictAVX5);
TEST_PREFETCH(AddMultipliedRestrictPrefetch1AVX3);
TEST_PREFETCH(AddMultipliedRestrictPrefetch2AVX3);
TEST(AddExponentialRestrictAVX);
TEST(LinearMultiplyAddRestrictAVX);
TEST(AddMultipliedAutoAVX);
TEST(AddMultipliedUnrolledAutoAVX);
TEST(AddMultipliedUnrolledRestrictAutoAVX);
TEST(AddMultipliedUnrolled2AutoAVX);
TEST(AddMultipliedUnrolled2RestrictAutoAVX);
TEST(ExponentiateAddAVX);
}
else cout << "Not supported" << endl;
cout << endl << "FMA" << endl;
if(Simd::IsAvxSupported())
{
TEST(AddMultipliedFMA);
TEST(AddMultipliedRestrictFMA);
TEST(AddMultipliedRestrictFMA5);
TEST(AddMultipliedRestrictFMA6);
}
else cout << "Not supported" << endl;
cout << endl << "Multiple sum" << endl;
TEST_X(AddMultipliedX2RestrictSSE, 2);
TEST_X(AddMultipliedX2RestrictSSE2, 2);
TEST_X(AddMultipliedX2RestrictSSE3, 2);
TEST_X(AddMultipliedX2RestrictSSE4, 2);
TEST_X(AddMultipliedX3RestrictSSE, 3);
TEST_X(AddMultipliedX3RestrictSSE2, 3);
TEST_X(AddExponentialX2RestrictSSE, 2);
TEST_X(AddExponentialX2RestrictAVX, 2);
TEST_X(LinearMultiplyAddX2RestrictSSE, 2);
TEST_X(LinearMultiplyAddX2RestrictClassSSE, 2);
TEST_X(LinearMultiplyAddX2RestrictAVX, 2);
if(Simd::IsAvxSupported())
{
TEST_X(AddMultipliedX2RestrictAVX, 2);
TEST_X(AddMultipliedX3RestrictAVX, 3);
TEST_X(AddMultipliedX3RestrictAVXClass, 3);
TEST_X(AddMultipliedX4RestrictAVX, 4);
TEST_X(AddMultipliedX8RestrictAVX, 8);
TEST_X(AddMultipliedX2RestrictFMA, 2);
}
}
void RunTestGroup(int nChunks, int chunkSize, const float* srcData, int srcLen, int numThreads)
{
vector<float> coeffs(nChunks);
for(float& c: coeffs) c = float(rand()) / float(RAND_MAX);
vector<const float*> srcs(nChunks);
cout << "--- RANDOM BLOCK READING" << endl;
for(int i = 0; i < nChunks; i++)
srcs[i] = srcData + unsigned(((rand() << 15) | rand()) * chunkSize) % srcLen;
RunTests(srcs.data(), coeffs.data(), chunkSize, nChunks, numThreads);
cout << endl << endl << "--- 128 STREAMS" << endl;
for(int i = 128; i < nChunks; i++)
srcs[i] = srcData + ((srcs[i & 127] - srcData) + i/128*chunkSize) % srcLen;
RunTests(srcs.data(), coeffs.data(), chunkSize, nChunks, numThreads);
cout << endl << endl << "--- 128 REV STREAMS" << endl;
for(int i = 128; i < nChunks; i++)
srcs[i] = srcData + ((srcs[(i & 128)? 127 - (i & 127): (i & 127)] - srcData) + i/128*chunkSize) % srcLen;
RunTests(srcs.data(), coeffs.data(), chunkSize, nChunks, numThreads);
cout << endl << endl << "--- 32 STREAMS" << endl;
for(int i = 32; i < nChunks; i++)
srcs[i] = srcData + ((srcs[i & 31] - srcData) + i/32*chunkSize) % srcLen;
RunTests(srcs.data(), coeffs.data(), chunkSize, nChunks, numThreads);
cout << endl << endl << "--- 32 REV STREAMS" << endl;
for(int i = 32; i < nChunks; i++)
srcs[i] = srcData + ((srcs[(i & 32)? 31 - (i & 31): (i & 31)] - srcData) + i/32*chunkSize) % srcLen;
RunTests(srcs.data(), coeffs.data(), chunkSize, nChunks, numThreads);
cout << endl << endl << "--- 16 STREAMS" << endl;
for(int i = 16; i < nChunks; i++)
srcs[i] = srcData + ((srcs[i & 15] - srcData) + i/16*chunkSize) % srcLen;
RunTests(srcs.data(), coeffs.data(), chunkSize, nChunks, numThreads);
cout << endl << endl << "--- SEQUENTIAL BLOCK READING" << endl;
for(int i = 0; i < nChunks; i++)
srcs[i] = srcData + i*chunkSize;
RunTests(srcs.data(), coeffs.data(), chunkSize, nChunks, numThreads);
cout << endl << endl << "--- SAME BLOCK READING" << endl;
for(int i = 0; i < nChunks; i++)
srcs[i] = srcData;
RunTests(srcs.data(), coeffs.data(), chunkSize, nChunks, numThreads);
}
struct RandGen
{
RandGen(unsigned seed = 157898685): Seed(seed) {}
float operator()()
{
Seed *= 16807;
return float(int(Seed)) * 4.6566129e-10f;
}
unsigned Seed;
} frand;
void PerfTests()
{
const size_t nChunks = 300000;
const size_t chunkSize = 1024;
const size_t srcLen = chunkSize*nChunks;
vector<float> src(srcLen + 16);
float* srcData = src.data() + 16;
for(size_t i = 0; i < srcLen; i++)
srcData[i] = frand();
cout << "------- 1 THREAD" << endl << endl;
RunTestGroup(nChunks, chunkSize, srcData, srcLen, 1);
cout << endl << "------- 4 THREADS" << endl << endl;
//RunTestGroup(nChunks, chunkSize, srcData, srcLen, 2);
vector<const float*> srcs(nChunks);
cout << endl << endl << "--- 128 STREAMS" << endl;
for(int i = 0; i < nChunks; i++)
srcs[i] = srcData + unsigned(((rand() << 15) | rand()) * chunkSize) % srcLen;
for(int i = 128; i < nChunks; i++)
srcs[i] = srcData + ((srcs[i & 127] - srcData) + i/128*chunkSize) % srcLen;
vector<float> coeffs(nChunks);
for(float& c: coeffs) c = float(rand()) / float(RAND_MAX);
alignas(64) float dst[1024]{};
if(size_t(dst) & 31) cout << "dst is not aligned!" << endl;
auto t0 = high_resolution_clock::now();
#pragma omp parallel for
for(int thread = 0; thread < 4; thread++)
{
for(int k = 0; k < nChunks; k+=3)
{
const float* srcs1[] = {srcs[k] + thread * chunkSize / 4, srcs[k+1] + thread * chunkSize / 4, srcs[k+2] + thread * chunkSize / 4};
AddMultipliedX3RestrictAVX(dst + thread * chunkSize / 4, srcs1, chunkSize / 4, coeffs.data() + k);
}
}
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);
auto fps = 2*srcLen/(time/1000.0f)/1000000000;
cout << left << setw(40) << "AddMultipliedX3RestrictAVX" << right << setw(6) << time << " ms\t"
<< gbs << " GB/s\tsum = " << Sum(dst) <<
"\t" << fps << " GFlops/s" << endl;
cout << endl << endl << "--- REDUCTION OPERATIONS" << endl;
TEST_REDUCE(SumSSE);
TEST_REDUCE(SumSSE2);
TEST_REDUCE(SumSSE3);
if(Simd::IsAvxSupported())
{
TEST_REDUCE(SumAVX);
TEST_REDUCE(SumAVX2);
TEST_REDUCE(SumAVX3);
TEST_REDUCE(SumAVX4);
{
auto t0 = high_resolution_clock::now();
float results[4];
for(int i = 0; i<4; i++) results[i] = SumAVX3(srcData + srcLen/4*i, srcLen/4);
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);
auto fps = srcLen/(time/1000.0f)/1000000000;
cout << left << setw(40) << "SumAVX3 4 parts" << right << setw(6) << time << " ms\t"
<< gbs << " GB/s\tresult = " << Sum(results) <<
"\t" << fps << " GFlops/s" << endl;
}
{
auto t0 = high_resolution_clock::now();
float results[4];
#pragma omp parallel for
for(int i = 0; i<4; i++)
results[i] = SumAVX3(srcData + srcLen/4*i, srcLen/4);
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);
auto fps = srcLen/(time/1000.0f)/1000000000;
cout << left << setw(40) << "SumAVX3 4 parts MT" << right << setw(6) << time << " ms\t"
<< gbs << " GB/s\tresult = " << Sum(results) <<
"\t" << fps << " GFlops/s" << endl;
}
{
auto t0 = high_resolution_clock::now();
float results[2];
#pragma omp parallel for
for(int i = 0; i<2; i++)
results[i] = SumAVX3(srcData + srcLen/2*i, srcLen/2);
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);
auto fps = srcLen/(time/1000.0f)/1000000000;
cout << left << setw(40) << "SumAVX3 2 parts MT" << right << setw(6) << time << " ms\t"
<< gbs << " GB/s\tresult = " << Sum(results) <<
"\t" << fps << " GFlops/s" << endl;
}
{
auto t0 = high_resolution_clock::now();
float results[2];
#pragma omp parallel for
for(int i = 0; i<2; i++)
results[i] = SumAVX4(srcData + srcLen/2*i, srcLen/2);
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);
auto fps = srcLen/(time/1000.0f)/1000000000;
cout << left << setw(40) << "SumAVX4 2 parts MT" << right << setw(6) << time << " ms\t"
<< gbs << " GB/s\tresult = " << Sum(results) <<
"\t" << fps << " GFlops/s" << endl;
}
}
{
auto t0 = high_resolution_clock::now();
float results[2];
#pragma omp parallel for
for(int i = 0; i<2; i++)
results[i] = SumSSE(srcData + srcLen/2*i, srcLen/2);
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);
auto fps = srcLen/(time/1000.0f)/1000000000;
cout << left << setw(40) << "SumSSE 2 parts MT" << right << setw(6) << time << " ms\t"
<< gbs << " GB/s\tresult = " << Sum(results) <<
"\t" << fps << " GFlops/s" << endl;
}
{
auto t0 = high_resolution_clock::now();
float results[2];
#pragma omp parallel for
for(int i = 0; i<2; i++)
results[i] = SumSSE2(srcData + srcLen/2*i, srcLen/2);
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);
auto fps = srcLen/(time/1000.0f)/1000000000;
cout << left << setw(40) << "SumSSE2 2 parts MT" << right << setw(6) << time << " ms\t"
<< gbs << " GB/s\tresult = " << Sum(results) <<
"\t" << fps << " GFlops/s" << endl;
}
{
auto t0 = high_resolution_clock::now();
float results[4];
#pragma omp parallel for
for(int i = 0; i<4; i++)
results[i] = SumSSE(srcData + srcLen/4*i, srcLen/4);
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);
auto fps = srcLen/(time/1000.0f)/1000000000;
cout << left << setw(40) << "SumSSE 4 parts MT" << right << setw(6) << time << " ms\t"
<< gbs << " GB/s\tresult = " << Sum(results) <<
"\t" << fps << " GFlops/s" << endl;
}
{
auto t0 = high_resolution_clock::now();
float results[4];
#pragma omp parallel for
for(int i = 0; i<4; i++)
results[i] = SumSSE2(srcData + srcLen/4*i, srcLen/4);
auto time = (high_resolution_clock::now() - t0).count()/100000/10.0f;
auto gbs = srcLen/(time/1000.0f)*sizeof(float)/(1 << 30);
auto fps = srcLen/(time/1000.0f)/1000000000;
cout << left << setw(40) << "SumSSE2 4 parts MT" << right << setw(6) << time << " ms\t"
<< gbs << " GB/s\tresult = " << Sum(results) <<
"\t" << fps << " GFlops/s" << endl;
}
}
void SimdTest();
int main()
{
SimdTest();
cout << endl;
PerfTests();
}