Skip to content

Commit dd6ebdf

Browse files
committed
Refactor the performance measurement system
1 parent 2824209 commit dd6ebdf

File tree

12 files changed

+302
-947
lines changed

12 files changed

+302
-947
lines changed

benchmark/amax.c

+56-114
Original file line numberDiff line numberDiff line change
@@ -25,125 +25,73 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
2525
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*****************************************************************************/
2727

28-
#include <stdio.h>
29-
#include <stdlib.h>
30-
#ifdef __CYGWIN32__
31-
#include <sys/time.h>
32-
#endif
33-
#include "common.h"
34-
28+
#include "bench.h"
3529

3630
#undef AMAX
3731

3832
#ifdef COMPLEX
3933
#ifdef DOUBLE
40-
#define AMAX BLASFUNC(dzamax)
34+
#define AMAX BLASFUNC(dzamax)
4135
#else
42-
#define AMAX BLASFUNC(scamax)
36+
#define AMAX BLASFUNC(scamax)
4337
#endif
4438
#else
4539
#ifdef DOUBLE
46-
#define AMAX BLASFUNC(damax)
40+
#define AMAX BLASFUNC(damax)
4741
#else
48-
#define AMAX BLASFUNC(samax)
42+
#define AMAX BLASFUNC(samax)
4943
#endif
5044
#endif
5145

52-
#if defined(__WIN32__) || defined(__WIN64__)
53-
54-
#ifndef DELTA_EPOCH_IN_MICROSECS
55-
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
56-
#endif
57-
58-
int gettimeofday(struct timeval *tv, void *tz){
59-
60-
FILETIME ft;
61-
unsigned __int64 tmpres = 0;
62-
static int tzflag;
63-
64-
if (NULL != tv)
65-
{
66-
GetSystemTimeAsFileTime(&ft);
67-
68-
tmpres |= ft.dwHighDateTime;
69-
tmpres <<= 32;
70-
tmpres |= ft.dwLowDateTime;
71-
72-
/*converting file time to unix epoch*/
73-
tmpres /= 10; /*convert into microseconds*/
74-
tmpres -= DELTA_EPOCH_IN_MICROSECS;
75-
tv->tv_sec = (long)(tmpres / 1000000UL);
76-
tv->tv_usec = (long)(tmpres % 1000000UL);
77-
}
78-
79-
return 0;
80-
}
81-
82-
#endif
83-
84-
#if !defined(__WIN32__) && !defined(__WIN64__) && !defined(__CYGWIN32__) && 0
85-
86-
static void *huge_malloc(BLASLONG size){
87-
int shmid;
88-
void *address;
89-
90-
#ifndef SHM_HUGETLB
91-
#define SHM_HUGETLB 04000
92-
#endif
93-
94-
if ((shmid =shmget(IPC_PRIVATE,
95-
(size + HUGE_PAGESIZE) & ~(HUGE_PAGESIZE - 1),
96-
SHM_HUGETLB | IPC_CREAT |0600)) < 0) {
97-
printf( "Memory allocation failed(shmget).\n");
98-
exit(1);
99-
}
100-
101-
address = shmat(shmid, NULL, SHM_RND);
102-
103-
if ((BLASLONG)address == -1){
104-
printf( "Memory allocation failed(shmat).\n");
105-
exit(1);
106-
}
107-
108-
shmctl(shmid, IPC_RMID, 0);
109-
110-
return address;
111-
}
112-
113-
#define malloc huge_malloc
114-
115-
#endif
116-
117-
int main(int argc, char *argv[]){
46+
int main(int argc, char *argv[])
47+
{
11848

11949
FLOAT *x;
12050
blasint m, i;
121-
blasint inc_x=1;
51+
blasint inc_x = 1;
12252
int loops = 1;
12353
int l;
12454
char *p;
12555

56+
int from = 1;
57+
int to = 200;
58+
int step = 1;
12659

127-
int from = 1;
128-
int to = 200;
129-
int step = 1;
130-
131-
struct timeval start, stop;
132-
double time1,timeg;
60+
double time1, timeg;
13361

134-
argc--;argv++;
62+
argc--;
63+
argv++;
13564

136-
if (argc > 0) { from = atol(*argv); argc--; argv++;}
137-
if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
138-
if (argc > 0) { step = atol(*argv); argc--; argv++;}
65+
if (argc > 0)
66+
{
67+
from = atol(*argv);
68+
argc--;
69+
argv++;
70+
}
71+
if (argc > 0)
72+
{
73+
to = MAX(atol(*argv), from);
74+
argc--;
75+
argv++;
76+
}
77+
if (argc > 0)
78+
{
79+
step = atol(*argv);
80+
argc--;
81+
argv++;
82+
}
13983

140-
if ((p = getenv("OPENBLAS_LOOPS"))) loops = atoi(p);
141-
if ((p = getenv("OPENBLAS_INCX"))) inc_x = atoi(p);
84+
if ((p = getenv("OPENBLAS_LOOPS")))
85+
loops = atoi(p);
86+
if ((p = getenv("OPENBLAS_INCX")))
87+
inc_x = atoi(p);
14288

143-
fprintf(stderr, "From : %3d To : %3d Step = %3d Inc_x = %d Loops = %d\n", from, to, step,inc_x,loops);
89+
fprintf(stderr, "From : %3d To : %3d Step = %3d Inc_x = %d Loops = %d\n", from, to, step, inc_x, loops);
14490

145-
if (( x = (FLOAT *)malloc(sizeof(FLOAT) * to * abs(inc_x) * COMPSIZE)) == NULL){
146-
fprintf(stderr,"Out of Memory!!\n");exit(1);
91+
if ((x = (FLOAT *)malloc(sizeof(FLOAT) * to * abs(inc_x) * COMPSIZE)) == NULL)
92+
{
93+
fprintf(stderr, "Out of Memory!!\n");
94+
exit(1);
14795
}
14896

14997
#ifdef __linux
@@ -152,37 +100,31 @@ int main(int argc, char *argv[]){
152100

153101
fprintf(stderr, " SIZE Flops\n");
154102

155-
for(m = from; m <= to; m += step)
103+
for (m = from; m <= to; m += step)
156104
{
157105

158-
timeg=0;
159-
160-
fprintf(stderr, " %6d : ", (int)m);
106+
timeg = 0;
107+
fprintf(stderr, " %6d : ", (int)m);
161108

109+
for (l = 0; l < loops; l++)
110+
{
162111

163-
for (l=0; l<loops; l++)
164-
{
165-
166-
for(i = 0; i < m * COMPSIZE * abs(inc_x); i++){
167-
x[i] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
168-
}
169-
170-
gettimeofday( &start, (struct timezone *)0);
171-
AMAX (&m, x, &inc_x);
172-
gettimeofday( &stop, (struct timezone *)0);
173-
174-
time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
175-
176-
timeg += time1;
112+
for (i = 0; i < m * COMPSIZE * abs(inc_x); i++)
113+
{
114+
x[i] = ((FLOAT)rand() / (FLOAT)RAND_MAX) - 0.5;
115+
}
177116

117+
begin();
118+
AMAX(&m, x, &inc_x);
119+
end();
120+
timeg += getsec();
178121
}
179122

180123
timeg /= loops;
181124

182125
fprintf(stderr,
183-
" %10.2f MFlops %10.6f sec\n",
184-
COMPSIZE * sizeof(FLOAT) * 1. * (double)m / timeg * 1.e-6, timeg);
185-
126+
" %10.2f MFlops %10.6f sec\n",
127+
COMPSIZE * sizeof(FLOAT) * 1. * (double)m / timeg * 1.e-6, timeg);
186128
}
187129

188130
return 0;

0 commit comments

Comments
 (0)