-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxtensor-test.cc
More file actions
450 lines (389 loc) · 24.4 KB
/
xtensor-test.cc
File metadata and controls
450 lines (389 loc) · 24.4 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
#include <iostream>
#include "xtensor/xarray.hpp"
#include "xtensor/xio.hpp"
#include "xtensor/xview.hpp"
#include "xtensor/xrandom.hpp"
#include <time.h>
constexpr size_t NN = 16*600000;//10000000;
constexpr size_t nrep = 10;
#include "MatriplXT.h"
// /usr/local/Cellar/gcc/7.1.0/bin/c++-7 -O2 -mavx -DXTENSOR_USE_XSIMD -I /Users/cerati/miniconda3/include/ xtensor-test.cc -o xtensor-test.exe
void test_v0(const std::array<xt::xarray<float>, 36>& input, const int type) {
MatriplXT66 A;
for (size_t i=0;i<36;++i) A[i] = input[i];
MatriplXT66 B;
for (size_t i=0;i<36;++i) B[i] = input[i]+0.5;
MatriplXT66 C;
for (size_t i=0;i<36;++i) C[i] = xt::zeros<float>({NN});
//dry run, not timed
if (type==1) MultiplyXT66Loop(A, B, C);
else if (type==2) MultiplyXT66LoopTile(A, B, C);
else MultiplyXT66(A, B, C);
//timed run, repeated nrep times
const clock_t begin = clock();
for (size_t nit=0; nit<nrep; ++nit) {
if (type==1) MultiplyXT66Loop(A, B, C);
else if (type==2) MultiplyXT66LoopTile(A, B, C);
else MultiplyXT66(A, B, C);
}
const clock_t end = clock();
for (size_t nn=0; nn<1/*NN*/; nn++) {
// std::cout << "nn=" << nn << std::endl;
// // std::cout << std::scientific;
// std::cout << "A" << std::endl;
// A.print(std::cout,nn);
// std::cout << "B" << std::endl;
// B.print(std::cout,nn);
std::cout << "C" << std::endl;
C.print(std::cout,nn);
// std::cout << std::fixed;
}
float time = float(end-begin)/CLOCKS_PER_SEC;
if (type==1) std::cout << "v0 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s (loop version), i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
else if (type==2) std::cout << "v0 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s (loop-tile version), i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
else std::cout << "v0 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s, i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
}
void test_v1(const std::array<xt::xarray<float>, 36>& input, const int type) {
MatriplXT66_v1 A(NN);
for (size_t i=0;i<36;++i) A[i] = input[i];
MatriplXT66_v1 B(NN);
for (size_t i=0;i<36;++i) B[i] = input[i]+0.5;
MatriplXT66_v1 C(NN);
for (size_t i=0;i<36;++i) C[i] = xt::zeros<float>({NN});
//dry run, not timed
if (type==1) MultiplyXT66Loop(A, B, C);
else if (type==2) MultiplyXT66Stack(A, B, C);
else MultiplyXT66(A, B, C);
//timed run, repeated nrep times
const clock_t begin = clock();
for (size_t nit=0; nit<nrep; ++nit) {
if (type==1) MultiplyXT66Loop(A, B, C);
else if (type==2) MultiplyXT66Stack(A, B, C);
else MultiplyXT66(A, B, C);
}
const clock_t end = clock();
for (size_t nn=0; nn<1/*NN*/; nn++) {
// std::cout << "nn=" << nn << std::endl;
// std::cout << "A" << std::endl;
// A.print(std::cout,nn);
// std::cout << "B" << std::endl;
// B.print(std::cout,nn);
std::cout << "C" << std::endl;
C.print(std::cout,nn);
}
float time = float(end-begin)/CLOCKS_PER_SEC;
if (type==1) std::cout << "v1 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s (loop version), i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
else if (type==2) std::cout << "v1 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s (stack version), i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
else std::cout << "v1 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s, i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
}
void test_v2(const std::array<xt::xarray<float>, 36>& input, const int type) {
MatriplXT66_v2 A(NN);
for (size_t i=0;i<36;++i) A[i] = input[i];
MatriplXT66_v2 B(NN);
for (size_t i=0;i<36;++i) B[i] = input[i]+0.5;
MatriplXT66_v2 C(NN);
for (size_t i=0;i<36;++i) C[i] = xt::zeros<float>({NN});
//dry run, not timed
if (type==1) MultiplyXT66Loop(A, B, C);
else if (type==2) MultiplyXT66Stack(A, B, C);
else MultiplyXT66(A, B, C);
//timed run, repeated nrep times
const clock_t begin = clock();
for (size_t nit=0; nit<nrep; ++nit) {
if (type==1) MultiplyXT66Loop(A, B, C);
else if (type==2) MultiplyXT66Stack(A, B, C);
else MultiplyXT66(A, B, C);
}
const clock_t end = clock();
for (size_t nn=0; nn<1/*NN*/; nn++) {
// std::cout << "nn=" << nn << std::endl;
// std::cout << "A" << std::endl;
// A.print(std::cout,nn);
// std::cout << "B" << std::endl;
// B.print(std::cout,nn);
std::cout << "C" << std::endl;
C.print(std::cout,nn);
}
float time = float(end-begin)/CLOCKS_PER_SEC;
if (type==1) std::cout << "v2 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s (loop version), i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
else if (type==2) std::cout << "v2 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s (stack version), i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
else std::cout << "v2 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s, i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
}
void test_v3(const std::array<xt::xarray<float>, 36>& input, const int type) {
MatriplXT66_v3 A;
for (size_t i=0;i<36;++i) A[i] = input[i];
MatriplXT66_v3 B;
for (size_t i=0;i<36;++i) B[i] = input[i]+0.5;
MatriplXT66_v3 C;
for (size_t i=0;i<36;++i) C[i] = xt::zeros<float>({NN});
//dry run, not timed
MultiplyXT66(A, B, C);
//timed run, repeated nrep times
const clock_t begin = clock();
for (size_t nit=0; nit<nrep; ++nit) {
MultiplyXT66(A, B, C);
}
const clock_t end = clock();
for (size_t nn=0; nn<1/*NN*/; nn++) {
// std::cout << "nn=" << nn << std::endl;
// std::cout << "A" << std::endl;
// A.print(std::cout,nn);
// std::cout << "B" << std::endl;
// B.print(std::cout,nn);
std::cout << "C" << std::endl;
C.print(std::cout,nn);
}
float time = float(end-begin)/CLOCKS_PER_SEC;
// if (type==1) std::cout << "v3 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s (loop version), i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
// else if (type==2) std::cout << "v3 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s (stack version), i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
// else
std::cout << "v3 -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s, i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
}
void test_plainArray_matrix(const std::array<xt::xarray<float>, 36>& input, const int type) {
//
float* Ax = new float[NN*36];
float* Bx = new float[NN*36];
float* Cx = new float[NN*36];
for (size_t j=0;j<NN*36;++j) Cx[j]=0.;
//
// store in matrix order (i.e. all elements of a given matrix are contiguous)
for (size_t x=0;x<NN;++x) {
for (size_t i=0;i<36;++i) {
Ax[i + 36*x] = input[i](x);
Bx[i + 36*x] = input[i](x)+0.5;
}
}
//dry run, not timed
plainArray_matrix_mult66(Ax,Bx,Cx);
//timed run, repeated nrep times
const clock_t begin = clock();
for (size_t nit=0; nit<nrep; ++nit) {
plainArray_matrix_mult66(Ax,Bx,Cx);
}
const clock_t end = clock();
// std::cout << "Ax=" << std::endl
// << Ax[(0*6+0)] << "\t" << Ax[(0*6+1)] << "\t" << Ax[(0*6+2)] << "\t" << Ax[(0*6+3)] << "\t" << Ax[(0*6+4)] << "\t" << Ax[(0*6+5)] << std::endl
// << Ax[(1*6+0)] << "\t" << Ax[(1*6+1)] << "\t" << Ax[(1*6+2)] << "\t" << Ax[(1*6+3)] << "\t" << Ax[(1*6+4)] << "\t" << Ax[(1*6+5)] << std::endl
// << Ax[(2*6+0)] << "\t" << Ax[(2*6+1)] << "\t" << Ax[(2*6+2)] << "\t" << Ax[(2*6+3)] << "\t" << Ax[(2*6+4)] << "\t" << Ax[(2*6+5)] << std::endl
// << Ax[(3*6+0)] << "\t" << Ax[(3*6+1)] << "\t" << Ax[(3*6+2)] << "\t" << Ax[(3*6+3)] << "\t" << Ax[(3*6+4)] << "\t" << Ax[(3*6+5)] << std::endl
// << Ax[(4*6+0)] << "\t" << Ax[(4*6+1)] << "\t" << Ax[(4*6+2)] << "\t" << Ax[(4*6+3)] << "\t" << Ax[(4*6+4)] << "\t" << Ax[(4*6+5)] << std::endl
// << Ax[(5*6+0)] << "\t" << Ax[(5*6+1)] << "\t" << Ax[(5*6+2)] << "\t" << Ax[(5*6+3)] << "\t" << Ax[(5*6+4)] << "\t" << Ax[(5*6+5)] << std::endl;
// std::cout << "Bx=" << std::endl
// << Bx[(0*6+0)] << "\t" << Bx[(0*6+1)] << "\t" << Bx[(0*6+2)] << "\t" << Bx[(0*6+3)] << "\t" << Bx[(0*6+4)] << "\t" << Bx[(0*6+5)] << std::endl
// << Bx[(1*6+0)] << "\t" << Bx[(1*6+1)] << "\t" << Bx[(1*6+2)] << "\t" << Bx[(1*6+3)] << "\t" << Bx[(1*6+4)] << "\t" << Bx[(1*6+5)] << std::endl
// << Bx[(2*6+0)] << "\t" << Bx[(2*6+1)] << "\t" << Bx[(2*6+2)] << "\t" << Bx[(2*6+3)] << "\t" << Bx[(2*6+4)] << "\t" << Bx[(2*6+5)] << std::endl
// << Bx[(3*6+0)] << "\t" << Bx[(3*6+1)] << "\t" << Bx[(3*6+2)] << "\t" << Bx[(3*6+3)] << "\t" << Bx[(3*6+4)] << "\t" << Bx[(3*6+5)] << std::endl
// << Bx[(4*6+0)] << "\t" << Bx[(4*6+1)] << "\t" << Bx[(4*6+2)] << "\t" << Bx[(4*6+3)] << "\t" << Bx[(4*6+4)] << "\t" << Bx[(4*6+5)] << std::endl
// << Bx[(5*6+0)] << "\t" << Bx[(5*6+1)] << "\t" << Bx[(5*6+2)] << "\t" << Bx[(5*6+3)] << "\t" << Bx[(5*6+4)] << "\t" << Bx[(5*6+5)] << std::endl;
std::cout << "Cx=" << std::endl
<< Cx[(0*6+0)] << "\t" << Cx[(0*6+1)] << "\t" << Cx[(0*6+2)] << "\t" << Cx[(0*6+3)] << "\t" << Cx[(0*6+4)] << "\t" << Cx[(0*6+5)] << std::endl
<< Cx[(1*6+0)] << "\t" << Cx[(1*6+1)] << "\t" << Cx[(1*6+2)] << "\t" << Cx[(1*6+3)] << "\t" << Cx[(1*6+4)] << "\t" << Cx[(1*6+5)] << std::endl
<< Cx[(2*6+0)] << "\t" << Cx[(2*6+1)] << "\t" << Cx[(2*6+2)] << "\t" << Cx[(2*6+3)] << "\t" << Cx[(2*6+4)] << "\t" << Cx[(2*6+5)] << std::endl
<< Cx[(3*6+0)] << "\t" << Cx[(3*6+1)] << "\t" << Cx[(3*6+2)] << "\t" << Cx[(3*6+3)] << "\t" << Cx[(3*6+4)] << "\t" << Cx[(3*6+5)] << std::endl
<< Cx[(4*6+0)] << "\t" << Cx[(4*6+1)] << "\t" << Cx[(4*6+2)] << "\t" << Cx[(4*6+3)] << "\t" << Cx[(4*6+4)] << "\t" << Cx[(4*6+5)] << std::endl
<< Cx[(5*6+0)] << "\t" << Cx[(5*6+1)] << "\t" << Cx[(5*6+2)] << "\t" << Cx[(5*6+3)] << "\t" << Cx[(5*6+4)] << "\t" << Cx[(5*6+5)] << std::endl;
float time = float(end-begin)/CLOCKS_PER_SEC;
std::cout << "plainArray_matrix -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s, i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
delete Ax, Bx, Cx;
}
void test_plainArray_element(const std::array<xt::xarray<float>, 36>& input, const int type) {
//
float* Ax = new float[NN*36];
float* Bx = new float[NN*36];
float* Cx = new float[NN*36];
for (size_t j=0;j<NN*36;++j) Cx[j]=0.;
//
// store in element order (i.e. all matrices for a given element are contiguous)
for (size_t x=0;x<NN;++x) {
for (size_t i=0;i<36;++i) {
Ax[i*NN + x] = input[i](x);
Bx[i*NN + x] = input[i](x)+0.5;
}
}
//dry run, not timed
plainArray_element_mult66(Ax,Bx,Cx);
//timed run, repeated nrep times
const clock_t begin = clock();
for (size_t nit=0; nit<nrep; ++nit) {
plainArray_element_mult66(Ax,Bx,Cx);
}
const clock_t end = clock();
// std::cout << "Ax=" << std::endl
// << Ax[NN*(0*6+0)] << "\t" << Ax[NN*(0*6+1)] << "\t" << Ax[NN*(0*6+2)] << "\t" << Ax[NN*(0*6+3)] << "\t" << Ax[NN*(0*6+4)] << "\t" << Ax[NN*(0*6+5)] << std::endl
// << Ax[NN*(1*6+0)] << "\t" << Ax[NN*(1*6+1)] << "\t" << Ax[NN*(1*6+2)] << "\t" << Ax[NN*(1*6+3)] << "\t" << Ax[NN*(1*6+4)] << "\t" << Ax[NN*(1*6+5)] << std::endl
// << Ax[NN*(2*6+0)] << "\t" << Ax[NN*(2*6+1)] << "\t" << Ax[NN*(2*6+2)] << "\t" << Ax[NN*(2*6+3)] << "\t" << Ax[NN*(2*6+4)] << "\t" << Ax[NN*(2*6+5)] << std::endl
// << Ax[NN*(3*6+0)] << "\t" << Ax[NN*(3*6+1)] << "\t" << Ax[NN*(3*6+2)] << "\t" << Ax[NN*(3*6+3)] << "\t" << Ax[NN*(3*6+4)] << "\t" << Ax[NN*(3*6+5)] << std::endl
// << Ax[NN*(4*6+0)] << "\t" << Ax[NN*(4*6+1)] << "\t" << Ax[NN*(4*6+2)] << "\t" << Ax[NN*(4*6+3)] << "\t" << Ax[NN*(4*6+4)] << "\t" << Ax[NN*(4*6+5)] << std::endl
// << Ax[NN*(5*6+0)] << "\t" << Ax[NN*(5*6+1)] << "\t" << Ax[NN*(5*6+2)] << "\t" << Ax[NN*(5*6+3)] << "\t" << Ax[NN*(5*6+4)] << "\t" << Ax[NN*(5*6+5)] << std::endl;
// std::cout << "Bx=" << std::endl
// << Bx[NN*(0*6+0)] << "\t" << Bx[NN*(0*6+1)] << "\t" << Bx[NN*(0*6+2)] << "\t" << Bx[NN*(0*6+3)] << "\t" << Bx[NN*(0*6+4)] << "\t" << Bx[NN*(0*6+5)] << std::endl
// << Bx[NN*(1*6+0)] << "\t" << Bx[NN*(1*6+1)] << "\t" << Bx[NN*(1*6+2)] << "\t" << Bx[NN*(1*6+3)] << "\t" << Bx[NN*(1*6+4)] << "\t" << Bx[NN*(1*6+5)] << std::endl
// << Bx[NN*(2*6+0)] << "\t" << Bx[NN*(2*6+1)] << "\t" << Bx[NN*(2*6+2)] << "\t" << Bx[NN*(2*6+3)] << "\t" << Bx[NN*(2*6+4)] << "\t" << Bx[NN*(2*6+5)] << std::endl
// << Bx[NN*(3*6+0)] << "\t" << Bx[NN*(3*6+1)] << "\t" << Bx[NN*(3*6+2)] << "\t" << Bx[NN*(3*6+3)] << "\t" << Bx[NN*(3*6+4)] << "\t" << Bx[NN*(3*6+5)] << std::endl
// << Bx[NN*(4*6+0)] << "\t" << Bx[NN*(4*6+1)] << "\t" << Bx[NN*(4*6+2)] << "\t" << Bx[NN*(4*6+3)] << "\t" << Bx[NN*(4*6+4)] << "\t" << Bx[NN*(4*6+5)] << std::endl
// << Bx[NN*(5*6+0)] << "\t" << Bx[NN*(5*6+1)] << "\t" << Bx[NN*(5*6+2)] << "\t" << Bx[NN*(5*6+3)] << "\t" << Bx[NN*(5*6+4)] << "\t" << Bx[NN*(5*6+5)] << std::endl;
std::cout << "Cx=" << std::endl
<< Cx[NN*(0*6+0)] << "\t" << Cx[NN*(0*6+1)] << "\t" << Cx[NN*(0*6+2)] << "\t" << Cx[NN*(0*6+3)] << "\t" << Cx[NN*(0*6+4)] << "\t" << Cx[NN*(0*6+5)] << std::endl
<< Cx[NN*(1*6+0)] << "\t" << Cx[NN*(1*6+1)] << "\t" << Cx[NN*(1*6+2)] << "\t" << Cx[NN*(1*6+3)] << "\t" << Cx[NN*(1*6+4)] << "\t" << Cx[NN*(1*6+5)] << std::endl
<< Cx[NN*(2*6+0)] << "\t" << Cx[NN*(2*6+1)] << "\t" << Cx[NN*(2*6+2)] << "\t" << Cx[NN*(2*6+3)] << "\t" << Cx[NN*(2*6+4)] << "\t" << Cx[NN*(2*6+5)] << std::endl
<< Cx[NN*(3*6+0)] << "\t" << Cx[NN*(3*6+1)] << "\t" << Cx[NN*(3*6+2)] << "\t" << Cx[NN*(3*6+3)] << "\t" << Cx[NN*(3*6+4)] << "\t" << Cx[NN*(3*6+5)] << std::endl
<< Cx[NN*(4*6+0)] << "\t" << Cx[NN*(4*6+1)] << "\t" << Cx[NN*(4*6+2)] << "\t" << Cx[NN*(4*6+3)] << "\t" << Cx[NN*(4*6+4)] << "\t" << Cx[NN*(4*6+5)] << std::endl
<< Cx[NN*(5*6+0)] << "\t" << Cx[NN*(5*6+1)] << "\t" << Cx[NN*(5*6+2)] << "\t" << Cx[NN*(5*6+3)] << "\t" << Cx[NN*(5*6+4)] << "\t" << Cx[NN*(5*6+5)] << std::endl;
float time = float(end-begin)/CLOCKS_PER_SEC;
std::cout << "plainArray_element -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s, i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
delete Ax, Bx, Cx;
}
void test_plainArray_el16mx(const std::array<xt::xarray<float>, 36>& input, const int type, bool align) {
//
float* Ax = (align ? (float*) _mm_malloc(36*NN*sizeof(float), 64) : new float[NN*36]);
float* Bx = (align ? (float*) _mm_malloc(36*NN*sizeof(float), 64) : new float[NN*36]);
float* Cx = (align ? (float*) _mm_malloc(36*NN*sizeof(float), 64) : new float[NN*36]);
for (size_t j=0;j<NN*36;++j) Cx[j]=0.;
//
// store in element order for bunches of 16 matrices (a la matriplex)
for (size_t x=0;x<NN/16;++x) {
for (size_t i=0;i<36;++i) {
for (size_t n=0;n<16;++n) {
Ax[n + i*16 + 16*36*x] = input[i](n+16*x);
Bx[n + i*16 + 16*36*x] = input[i](n+16*x)+0.5;
}
}
}
//dry run, not timed
if (type==1) {
plainArray_el16mx_mult66_v1(Ax,Bx,Cx);
} else {
plainArray_el16mx_mult66(Ax,Bx,Cx);
}
//timed run, repeated nrep times
const clock_t begin = clock();
for (size_t nit=0; nit<nrep; ++nit) {
if (type==1) {
plainArray_el16mx_mult66_v1(Ax,Bx,Cx);
} else {
plainArray_el16mx_mult66(Ax,Bx,Cx);
}
}
const clock_t end = clock();
// std::cout << "Ax=" << std::endl
// << Ax[16*(0*6+0)] << "\t" << Ax[16*(0*6+1)] << "\t" << Ax[16*(0*6+2)] << "\t" << Ax[16*(0*6+3)] << "\t" << Ax[16*(0*6+4)] << "\t" << Ax[16*(0*6+5)] << std::endl
// << Ax[16*(1*6+0)] << "\t" << Ax[16*(1*6+1)] << "\t" << Ax[16*(1*6+2)] << "\t" << Ax[16*(1*6+3)] << "\t" << Ax[16*(1*6+4)] << "\t" << Ax[16*(1*6+5)] << std::endl
// << Ax[16*(2*6+0)] << "\t" << Ax[16*(2*6+1)] << "\t" << Ax[16*(2*6+2)] << "\t" << Ax[16*(2*6+3)] << "\t" << Ax[16*(2*6+4)] << "\t" << Ax[16*(2*6+5)] << std::endl
// << Ax[16*(3*6+0)] << "\t" << Ax[16*(3*6+1)] << "\t" << Ax[16*(3*6+2)] << "\t" << Ax[16*(3*6+3)] << "\t" << Ax[16*(3*6+4)] << "\t" << Ax[16*(3*6+5)] << std::endl
// << Ax[16*(4*6+0)] << "\t" << Ax[16*(4*6+1)] << "\t" << Ax[16*(4*6+2)] << "\t" << Ax[16*(4*6+3)] << "\t" << Ax[16*(4*6+4)] << "\t" << Ax[16*(4*6+5)] << std::endl
// << Ax[16*(5*6+0)] << "\t" << Ax[16*(5*6+1)] << "\t" << Ax[16*(5*6+2)] << "\t" << Ax[16*(5*6+3)] << "\t" << Ax[16*(5*6+4)] << "\t" << Ax[16*(5*6+5)] << std::endl;
// std::cout << "Bx=" << std::endl
// << Bx[16*(0*6+0)] << "\t" << Bx[16*(0*6+1)] << "\t" << Bx[16*(0*6+2)] << "\t" << Bx[16*(0*6+3)] << "\t" << Bx[16*(0*6+4)] << "\t" << Bx[16*(0*6+5)] << std::endl
// << Bx[16*(1*6+0)] << "\t" << Bx[16*(1*6+1)] << "\t" << Bx[16*(1*6+2)] << "\t" << Bx[16*(1*6+3)] << "\t" << Bx[16*(1*6+4)] << "\t" << Bx[16*(1*6+5)] << std::endl
// << Bx[16*(2*6+0)] << "\t" << Bx[16*(2*6+1)] << "\t" << Bx[16*(2*6+2)] << "\t" << Bx[16*(2*6+3)] << "\t" << Bx[16*(2*6+4)] << "\t" << Bx[16*(2*6+5)] << std::endl
// << Bx[16*(3*6+0)] << "\t" << Bx[16*(3*6+1)] << "\t" << Bx[16*(3*6+2)] << "\t" << Bx[16*(3*6+3)] << "\t" << Bx[16*(3*6+4)] << "\t" << Bx[16*(3*6+5)] << std::endl
// << Bx[16*(4*6+0)] << "\t" << Bx[16*(4*6+1)] << "\t" << Bx[16*(4*6+2)] << "\t" << Bx[16*(4*6+3)] << "\t" << Bx[16*(4*6+4)] << "\t" << Bx[16*(4*6+5)] << std::endl
// << Bx[16*(5*6+0)] << "\t" << Bx[16*(5*6+1)] << "\t" << Bx[16*(5*6+2)] << "\t" << Bx[16*(5*6+3)] << "\t" << Bx[16*(5*6+4)] << "\t" << Bx[16*(5*6+5)] << std::endl;
std::cout << "Cx=" << std::endl
<< Cx[16*(0*6+0)] << "\t" << Cx[16*(0*6+1)] << "\t" << Cx[16*(0*6+2)] << "\t" << Cx[16*(0*6+3)] << "\t" << Cx[16*(0*6+4)] << "\t" << Cx[16*(0*6+5)] << std::endl
<< Cx[16*(1*6+0)] << "\t" << Cx[16*(1*6+1)] << "\t" << Cx[16*(1*6+2)] << "\t" << Cx[16*(1*6+3)] << "\t" << Cx[16*(1*6+4)] << "\t" << Cx[16*(1*6+5)] << std::endl
<< Cx[16*(2*6+0)] << "\t" << Cx[16*(2*6+1)] << "\t" << Cx[16*(2*6+2)] << "\t" << Cx[16*(2*6+3)] << "\t" << Cx[16*(2*6+4)] << "\t" << Cx[16*(2*6+5)] << std::endl
<< Cx[16*(3*6+0)] << "\t" << Cx[16*(3*6+1)] << "\t" << Cx[16*(3*6+2)] << "\t" << Cx[16*(3*6+3)] << "\t" << Cx[16*(3*6+4)] << "\t" << Cx[16*(3*6+5)] << std::endl
<< Cx[16*(4*6+0)] << "\t" << Cx[16*(4*6+1)] << "\t" << Cx[16*(4*6+2)] << "\t" << Cx[16*(4*6+3)] << "\t" << Cx[16*(4*6+4)] << "\t" << Cx[16*(4*6+5)] << std::endl
<< Cx[16*(5*6+0)] << "\t" << Cx[16*(5*6+1)] << "\t" << Cx[16*(5*6+2)] << "\t" << Cx[16*(5*6+3)] << "\t" << Cx[16*(5*6+4)] << "\t" << Cx[16*(5*6+5)] << std::endl;
float time = float(end-begin)/CLOCKS_PER_SEC;
if (type==1) std::cout << "plainArray_el16mx (mplex loop) with align=" << align << " -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s, i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
else std::cout << "plainArray_el16mx (plain loop) with align=" << align << " -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s, i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
if (align) {
_mm_free(Ax);
_mm_free(Bx);
_mm_free(Cx);
} else {
delete Ax, Bx, Cx;
}
}
void test_plainArray_xsimd(const std::array<xt::xarray<float>, 36>& input) {
//
using vector_type = std::vector<float, XSIMD_DEFAULT_ALLOCATOR(float)>;
using b_type = xsimd::simd_type<float>;
//
vector_type A[36];
vector_type B[36];
vector_type C[36];
//
for (size_t i=0;i<36;++i) {
A[i] = vector_type(NN,0.);
B[i] = vector_type(NN,0.);
C[i] = vector_type(NN,0.);
for (size_t x=0;x<NN;++x) {
A[i][x] = input[i](x);
B[i][x] = input[i](x)+0.5;
}
}
//
const std::size_t inc = b_type::size;
const std::size_t size = NN;
//
// size for which the vectorization is possible (we assume there is nothing left out, i.e. size-vec_size==0)
const std::size_t vec_size = size - size % inc;
//dry run, not timed
plainArray_xsimd_mult66(A, B, C, vec_size, inc);
//timed run, repeated nrep times
const clock_t begin = clock();
for (size_t nit=0; nit<nrep; ++nit) {
plainArray_xsimd_mult66(A, B, C, vec_size, inc);
}
const clock_t end = clock();
//
// std::cout << "A=" << std::endl
// << A[(0*6+0)][0] << "\t" << A[(0*6+1)][0] << "\t" << A[(0*6+2)][0] << "\t" << A[(0*6+3)][0] << "\t" << A[(0*6+4)][0] << "\t" << A[(0*6+5)][0] << std::endl
// << A[(1*6+0)][0] << "\t" << A[(1*6+1)][0] << "\t" << A[(1*6+2)][0] << "\t" << A[(1*6+3)][0] << "\t" << A[(1*6+4)][0] << "\t" << A[(1*6+5)][0] << std::endl
// << A[(2*6+0)][0] << "\t" << A[(2*6+1)][0] << "\t" << A[(2*6+2)][0] << "\t" << A[(2*6+3)][0] << "\t" << A[(2*6+4)][0] << "\t" << A[(2*6+5)][0] << std::endl
// << A[(3*6+0)][0] << "\t" << A[(3*6+1)][0] << "\t" << A[(3*6+2)][0] << "\t" << A[(3*6+3)][0] << "\t" << A[(3*6+4)][0] << "\t" << A[(3*6+5)][0] << std::endl
// << A[(4*6+0)][0] << "\t" << A[(4*6+1)][0] << "\t" << A[(4*6+2)][0] << "\t" << A[(4*6+3)][0] << "\t" << A[(4*6+4)][0] << "\t" << A[(4*6+5)][0] << std::endl
// << A[(5*6+0)][0] << "\t" << A[(5*6+1)][0] << "\t" << A[(5*6+2)][0] << "\t" << A[(5*6+3)][0] << "\t" << A[(5*6+4)][0] << "\t" << A[(5*6+5)][0] << std::endl;
// std::cout << "B=" << std::endl
// << B[(0*6+0)][0] << "\t" << B[(0*6+1)][0] << "\t" << B[(0*6+2)][0] << "\t" << B[(0*6+3)][0] << "\t" << B[(0*6+4)][0] << "\t" << B[(0*6+5)][0] << std::endl
// << B[(1*6+0)][0] << "\t" << B[(1*6+1)][0] << "\t" << B[(1*6+2)][0] << "\t" << B[(1*6+3)][0] << "\t" << B[(1*6+4)][0] << "\t" << B[(1*6+5)][0] << std::endl
// << B[(2*6+0)][0] << "\t" << B[(2*6+1)][0] << "\t" << B[(2*6+2)][0] << "\t" << B[(2*6+3)][0] << "\t" << B[(2*6+4)][0] << "\t" << B[(2*6+5)][0] << std::endl
// << B[(3*6+0)][0] << "\t" << B[(3*6+1)][0] << "\t" << B[(3*6+2)][0] << "\t" << B[(3*6+3)][0] << "\t" << B[(3*6+4)][0] << "\t" << B[(3*6+5)][0] << std::endl
// << B[(4*6+0)][0] << "\t" << B[(4*6+1)][0] << "\t" << B[(4*6+2)][0] << "\t" << B[(4*6+3)][0] << "\t" << B[(4*6+4)][0] << "\t" << B[(4*6+5)][0] << std::endl
// << B[(5*6+0)][0] << "\t" << B[(5*6+1)][0] << "\t" << B[(5*6+2)][0] << "\t" << B[(5*6+3)][0] << "\t" << B[(5*6+4)][0] << "\t" << B[(5*6+5)][0] << std::endl;
std::cout << "C=" << std::endl
<< C[(0*6+0)][0] << "\t" << C[(0*6+1)][0] << "\t" << C[(0*6+2)][0] << "\t" << C[(0*6+3)][0] << "\t" << C[(0*6+4)][0] << "\t" << C[(0*6+5)][0] << std::endl
<< C[(1*6+0)][0] << "\t" << C[(1*6+1)][0] << "\t" << C[(1*6+2)][0] << "\t" << C[(1*6+3)][0] << "\t" << C[(1*6+4)][0] << "\t" << C[(1*6+5)][0] << std::endl
<< C[(2*6+0)][0] << "\t" << C[(2*6+1)][0] << "\t" << C[(2*6+2)][0] << "\t" << C[(2*6+3)][0] << "\t" << C[(2*6+4)][0] << "\t" << C[(2*6+5)][0] << std::endl
<< C[(3*6+0)][0] << "\t" << C[(3*6+1)][0] << "\t" << C[(3*6+2)][0] << "\t" << C[(3*6+3)][0] << "\t" << C[(3*6+4)][0] << "\t" << C[(3*6+5)][0] << std::endl
<< C[(4*6+0)][0] << "\t" << C[(4*6+1)][0] << "\t" << C[(4*6+2)][0] << "\t" << C[(4*6+3)][0] << "\t" << C[(4*6+4)][0] << "\t" << C[(4*6+5)][0] << std::endl
<< C[(5*6+0)][0] << "\t" << C[(5*6+1)][0] << "\t" << C[(5*6+2)][0] << "\t" << C[(5*6+3)][0] << "\t" << C[(5*6+4)][0] << "\t" << C[(5*6+5)][0] << std::endl;
float time = float(end-begin)/CLOCKS_PER_SEC;
std::cout << "plainArray_xsimd -- time for NN*nrep=" << NN*nrep << " multiplications is " << time << " s, i.e. per mult. [s]=" << time/float(NN*nrep) << std::endl;
}
int main(int argc, char* argv[])
{
std::cout << "running with NN=" << NN << " nrep=" << nrep << std::endl;
std::array<xt::xarray<float>, 36> input;
for (size_t i=0;i<36;++i) input[i] = xt::linspace<float>(i,i+100,NN);
std::cout << "done preparing input" << std::endl;
test_v0(input,0);
// test_v0(input,1);
// test_v0(input,2);
std::cout << std::endl;
test_v1(input,0);
// test_v1(input,1);
// // test_v1(input,2);
std::cout << std::endl;
test_v2(input,0);
// test_v2(input,1);
// // test_v2(input,2);
std::cout << std::endl;
test_v3(input,0);
std::cout << std::endl;
test_plainArray_matrix(input,0);
std::cout << std::endl;
test_plainArray_element(input,0);
std::cout << std::endl;
test_plainArray_el16mx(input,0,0);
std::cout << std::endl;
test_plainArray_el16mx(input,1,0);
std::cout << std::endl;
test_plainArray_el16mx(input,1,1);
std::cout << std::endl;
test_plainArray_xsimd(input);
return 0;
}