Skip to content

Commit 3dd094f

Browse files
committed
Merge pull request #413 from wernsaar/develop
additional benchmarks
2 parents 339ab34 + 7424e2b commit 3dd094f

File tree

10 files changed

+2414
-91
lines changed

10 files changed

+2414
-91
lines changed

benchmark/Makefile

Lines changed: 623 additions & 91 deletions
Large diffs are not rendered by default.

benchmark/gemm.c

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
/***************************************************************************
2+
Copyright (c) 2014, The OpenBLAS Project
3+
All rights reserved.
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are
6+
met:
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in
11+
the documentation and/or other materials provided with the
12+
distribution.
13+
3. Neither the name of the OpenBLAS project nor the names of
14+
its contributors may be used to endorse or promote products
15+
derived from this software without specific prior written permission.
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
20+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*****************************************************************************/
27+
28+
#include <stdio.h>
29+
#include <stdlib.h>
30+
#ifdef __CYGWIN32__
31+
#include <sys/time.h>
32+
#endif
33+
#include "common.h"
34+
35+
36+
#undef GEMM
37+
38+
#ifndef COMPLEX
39+
40+
#ifdef DOUBLE
41+
#define GEMM BLASFUNC(dgemm)
42+
#else
43+
#define GEMM BLASFUNC(sgemm)
44+
#endif
45+
46+
#else
47+
48+
#ifdef DOUBLE
49+
#define GEMM BLASFUNC(zgemm)
50+
#else
51+
#define GEMM BLASFUNC(cgemm)
52+
#endif
53+
54+
#endif
55+
56+
#if defined(__WIN32__) || defined(__WIN64__)
57+
58+
#ifndef DELTA_EPOCH_IN_MICROSECS
59+
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
60+
#endif
61+
62+
int gettimeofday(struct timeval *tv, void *tz){
63+
64+
FILETIME ft;
65+
unsigned __int64 tmpres = 0;
66+
static int tzflag;
67+
68+
if (NULL != tv)
69+
{
70+
GetSystemTimeAsFileTime(&ft);
71+
72+
tmpres |= ft.dwHighDateTime;
73+
tmpres <<= 32;
74+
tmpres |= ft.dwLowDateTime;
75+
76+
/*converting file time to unix epoch*/
77+
tmpres /= 10; /*convert into microseconds*/
78+
tmpres -= DELTA_EPOCH_IN_MICROSECS;
79+
tv->tv_sec = (long)(tmpres / 1000000UL);
80+
tv->tv_usec = (long)(tmpres % 1000000UL);
81+
}
82+
83+
return 0;
84+
}
85+
86+
#endif
87+
88+
#if !defined(__WIN32__) && !defined(__WIN64__) && !defined(__CYGWIN32__) && 0
89+
90+
static void *huge_malloc(BLASLONG size){
91+
int shmid;
92+
void *address;
93+
94+
#ifndef SHM_HUGETLB
95+
#define SHM_HUGETLB 04000
96+
#endif
97+
98+
if ((shmid =shmget(IPC_PRIVATE,
99+
(size + HUGE_PAGESIZE) & ~(HUGE_PAGESIZE - 1),
100+
SHM_HUGETLB | IPC_CREAT |0600)) < 0) {
101+
printf( "Memory allocation failed(shmget).\n");
102+
exit(1);
103+
}
104+
105+
address = shmat(shmid, NULL, SHM_RND);
106+
107+
if ((BLASLONG)address == -1){
108+
printf( "Memory allocation failed(shmat).\n");
109+
exit(1);
110+
}
111+
112+
shmctl(shmid, IPC_RMID, 0);
113+
114+
return address;
115+
}
116+
117+
#define malloc huge_malloc
118+
119+
#endif
120+
121+
int MAIN__(int argc, char *argv[]){
122+
123+
FLOAT *a, *b, *c;
124+
FLOAT alpha[] = {1.0, 1.0};
125+
FLOAT beta [] = {1.0, 1.0};
126+
char trans='N';
127+
blasint m, i, j;
128+
int loops = 1;
129+
int l;
130+
char *p;
131+
132+
int from = 1;
133+
int to = 200;
134+
int step = 1;
135+
136+
struct timeval start, stop;
137+
double time1,timeg;
138+
139+
argc--;argv++;
140+
141+
if (argc > 0) { from = atol(*argv); argc--; argv++;}
142+
if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
143+
if (argc > 0) { step = atol(*argv); argc--; argv++;}
144+
145+
fprintf(stderr, "From : %3d To : %3d Step = %3d\n", from, to, step);
146+
147+
if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
148+
fprintf(stderr,"Out of Memory!!\n");exit(1);
149+
}
150+
151+
if (( b = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
152+
fprintf(stderr,"Out of Memory!!\n");exit(1);
153+
}
154+
155+
if (( c = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
156+
fprintf(stderr,"Out of Memory!!\n");exit(1);
157+
}
158+
159+
p = getenv("OPENBLAS_LOOPS");
160+
if ( p != NULL )
161+
loops = atoi(p);
162+
163+
164+
#ifdef linux
165+
srandom(getpid());
166+
#endif
167+
168+
fprintf(stderr, " SIZE Flops\n");
169+
170+
for(m = from; m <= to; m += step)
171+
{
172+
173+
timeg=0;
174+
175+
fprintf(stderr, " %6d : ", (int)m);
176+
177+
for (l=0; l<loops; l++)
178+
{
179+
180+
for(j = 0; j < m; j++){
181+
for(i = 0; i < m * COMPSIZE; i++){
182+
a[i + j * m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
183+
b[i + j * m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
184+
c[i + j * m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
185+
}
186+
}
187+
188+
gettimeofday( &start, (struct timezone *)0);
189+
190+
GEMM (&trans, &trans, &m, &m, &m, alpha, a, &m, b, &m, beta, c, &m );
191+
192+
gettimeofday( &stop, (struct timezone *)0);
193+
194+
time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
195+
196+
timeg += time1;
197+
198+
}
199+
200+
timeg /= loops;
201+
fprintf(stderr,
202+
" %10.2f MFlops\n",
203+
COMPSIZE * COMPSIZE * 2. * (double)m * (double)m * (double)m / timeg * 1.e-6);
204+
205+
}
206+
207+
return 0;
208+
}
209+
210+
void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));

0 commit comments

Comments
 (0)