-
Notifications
You must be signed in to change notification settings - Fork 2
/
idq-bench-float32-schoenauer.c
139 lines (120 loc) · 3.64 KB
/
idq-bench-float32-schoenauer.c
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
/*
* Benchmark designed to stress the instruction decoders. Designed for Intel Haswell microarchitecture. Compiled with GCC 4.4.
*
* Usage: ./idq-bench-float32-schoenauer [ -b ] [ -m ] [ -n <running time multiplier> ] [ -r <number of times to repeat> ]
*
* Author: Mikael Hirki <mikael.hirki@gmail.com>
*
* Copyright (c) 2015 Helsinki Institute of Physics
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <pthread.h>
#include "measure-util.h"
/*
* Number of inner loop iterations.
*/
#define ARRAY_SIZE 2048
/*
* Loop enough times to make the power consumption measurable.
*/
#define NTIMES 606000
/*
* Data type used in the benchmark kernels.
*/
typedef float kernel_data_t;
/* Exponential macro expansion */
#define ADD_1 sum += a + b * c; j++;
#define ADD_2 ADD_1 ADD_1
#define ADD_4 ADD_2 ADD_2
#define ADD_8 ADD_4 ADD_4
#define ADD_16 ADD_8 ADD_8
#define ADD_32 ADD_16 ADD_16
#define ADD_64 ADD_32 ADD_32
#define ADD_128 ADD_64 ADD_64
#define ADD_256 ADD_128 ADD_128
#define ADD_512 ADD_256 ADD_256
#define ADD_1024 ADD_512 ADD_512
#define ADD_2048 ADD_1024 ADD_1024
/*
* Benchmark kernels
*/
kernel_data_t kernel_normal(long ntimes, kernel_data_t a, kernel_data_t b, kernel_data_t c) {
long i = 0, j = 0;
kernel_data_t sum = 0;
for (i = 0; i < ntimes; i++) {
for (j = 0; j < ARRAY_SIZE;) {
ADD_512
}
}
return sum;
}
kernel_data_t kernel_extreme(long ntimes, kernel_data_t a, kernel_data_t b, kernel_data_t c) {
long i = 0, j = 0;
kernel_data_t sum = 0;
for (i = 0; i < ntimes; i++) {
for (j = 0; j < ARRAY_SIZE;) {
ADD_1024
}
}
return sum;
}
typedef struct {
kernel_data_t a;
kernel_data_t b;
kernel_data_t c;
} benchdata_t;
static int bench_init(void **benchdata) {
benchdata_t *data = calloc(1, sizeof(benchdata_t));
*benchdata = data;
data->a = 1;
data->b = 2;
data->c = 3;
/* Success */
return 1;
}
static int bench_normal(void *benchdata, long ntimes) {
benchdata_t *data = benchdata;
return kernel_normal(ntimes, data->a, data->b, data->c);
}
static int bench_extreme(void *benchdata, long ntimes) {
benchdata_t *data = benchdata;
return kernel_extreme(ntimes, data->a, data->b, data->c);
}
static int bench_cleanup(void *benchdata) {
benchdata_t *data = benchdata;
free(data);
/* Success */
return 1;
}
int main(int argc, char **argv) {
measure_benchmark_t bench;
memset(&bench, 0, sizeof(bench));
/* Set up benchmark parameters */
bench.ntimes = NTIMES;
bench.init = bench_init;
bench.normal = bench_normal;
bench.extreme = bench_extreme;
bench.cleanup = bench_cleanup;
return measure_main(argc, argv, &bench);
}