-
Notifications
You must be signed in to change notification settings - Fork 6
/
genflops.cc
144 lines (123 loc) · 3.51 KB
/
genflops.cc
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
// x86 AVX FLOPs counter
// Based on:
// http://stackoverflow.com/questions/8389648/how-to-achieve-4-flops-per-cycle
#include <stdint.h>
#include <stdlib.h>
#include <iostream>
#include "openmp.h"
using namespace std;
#define SIMD 8
typedef float float_t;
typedef float_t simd_t[SIMD];
#define LOOP for(size_t s = 0; s < SIMD; s++)
float_t test_dp_mac_gen(float_t x,float_t y,size_t iterations){
register simd_t r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,rA,rB,rC,rD,rE,rF;
// Generate starting data.
LOOP r0[s] = x;
LOOP r1[s] = y;
LOOP r2[s] = y;
LOOP r3[s] = (float_t) 1.0;
LOOP r4[s] = (float_t)-1.0;
LOOP r5[s] = (float_t) 1.0;
LOOP r6[s] = (float_t)-1.0;
LOOP r7[s] = (float_t) 1.0;
LOOP r8[s] = (float_t)-1.0;
LOOP r9[s] = (float_t) 1.0;
LOOP rA[s] = (float_t)-1.0;
LOOP rB[s] = (float_t) 1.0;
LOOP rC[s] = (float_t)-1.0;
LOOP rD[s] = (float_t) 1.0;
LOOP rE[s] = (float_t)-1.0;
LOOP rF[s] = (float_t) 1.0;
for (size_t c = 0; c < iterations * 1000; c++) {
LOOP r0[s] = r0[s] * rC[s];
LOOP r1[s] = r1[s] + rD[s];
LOOP r2[s] = r2[s] * rE[s];
LOOP r3[s] = r3[s] - rF[s];
LOOP r4[s] = r4[s] * rC[s];
LOOP r5[s] = r5[s] + rD[s];
LOOP r6[s] = r6[s] * rE[s];
LOOP r7[s] = r7[s] - rF[s];
LOOP r8[s] = r8[s] * rC[s];
LOOP r9[s] = r9[s] + rD[s];
LOOP rA[s] = rA[s] * rE[s];
LOOP rB[s] = rB[s] - rF[s];
LOOP r0[s] = r0[s] + rF[s];
LOOP r1[s] = r1[s] * rE[s];
LOOP r2[s] = r2[s] - rD[s];
LOOP r3[s] = r3[s] * rC[s];
LOOP r4[s] = r4[s] + rF[s];
LOOP r5[s] = r5[s] * rE[s];
LOOP r6[s] = r6[s] - rD[s];
LOOP r7[s] = r7[s] * rC[s];
LOOP r8[s] = r8[s] + rF[s];
LOOP r9[s] = r9[s] * rE[s];
LOOP rA[s] = rA[s] - rD[s];
LOOP rB[s] = rB[s] * rC[s];
LOOP r0[s] = r0[s] * rC[s];
LOOP r1[s] = r1[s] + rD[s];
LOOP r2[s] = r2[s] * rE[s];
LOOP r3[s] = r3[s] - rF[s];
LOOP r4[s] = r4[s] * rC[s];
LOOP r5[s] = r5[s] + rD[s];
LOOP r6[s] = r6[s] * rE[s];
LOOP r7[s] = r7[s] - rF[s];
LOOP r8[s] = r8[s] * rC[s];
LOOP r9[s] = r9[s] + rD[s];
LOOP rA[s] = rA[s] * rE[s];
LOOP rB[s] = rB[s] - rF[s];
LOOP r0[s] = r0[s] + rF[s];
LOOP r1[s] = r1[s] * rE[s];
LOOP r2[s] = r2[s] - rD[s];
LOOP r3[s] = r3[s] * rC[s];
LOOP r4[s] = r4[s] + rF[s];
LOOP r5[s] = r5[s] * rE[s];
LOOP r6[s] = r6[s] - rD[s];
LOOP r7[s] = r7[s] * rC[s];
LOOP r8[s] = r8[s] + rF[s];
LOOP r9[s] = r9[s] * rE[s];
LOOP rA[s] = rA[s] - rD[s];
LOOP rB[s] = rB[s] * rC[s];
}
LOOP r0[s] = r0[s] + r1[s];
LOOP r2[s] = r2[s] + r3[s];
LOOP r4[s] = r4[s] + r5[s];
LOOP r6[s] = r6[s] + r7[s];
LOOP r8[s] = r8[s] + r9[s];
LOOP rA[s] = rA[s] + rB[s];
LOOP r0[s] = r0[s] + r2[s];
LOOP r4[s] = r4[s] + r6[s];
LOOP r8[s] = r8[s] + rA[s];
LOOP r0[s] = r0[s] + r4[s];
LOOP r0[s] = r0[s] + r8[s];
float_t out = (float_t)0;
LOOP out += r0[s];
return out;
}
void test_dp_mac_gen(int tds,size_t iterations){
float_t *sum = (float_t*)malloc(tds * sizeof(float_t));
float_t start = omp_get_wtime();
#pragma omp parallel num_threads(tds)
{
float_t ret = test_dp_mac_gen((float_t)1.1,(float_t)2.1,iterations);
sum[omp_get_thread_num()] = ret;
}
float_t secs = omp_get_wtime() - start;
uint64_t ops = 48 * 1000 * iterations * tds * 4;
cout << "Seconds = " << secs << endl;
cout << "FP Ops = " << ops << endl;
cout << "GFLOPs = " << ops / 1e9 / secs << endl;
float_t out = 0;
int c = 0;
while (c < tds){
out += sum[c++];
}
cout << "sum = " << out << endl;
cout << endl;
free(sum);
}
int main(int argc, char const *argv[])
{
test_dp_mac_gen(omp_get_max_threads(), argc >= 2 ? atol(argv[1]) : 1000000);
return 0;
}