Skip to content

Commit c0649aa

Browse files
authored
Merge pull request #2506 from xiaofengF/develop
Add benchmark for SPMV and fix segmentation fault when data size >= 50000
2 parents 0fe0914 + ae3f2c2 commit c0649aa

2 files changed

Lines changed: 243 additions & 1 deletion

File tree

benchmark/Makefile

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ goto :: slinpack.goto dlinpack.goto clinpack.goto zlinpack.goto \
7979
cherk.goto zherk.goto \
8080
cher2k.goto zher2k.goto \
8181
sgemv.goto dgemv.goto cgemv.goto zgemv.goto \
82+
sspmv.goto dspmv.goto \
8283
strmv.goto dtrmv.goto ctrmv.goto ztrmv.goto \
8384
stpmv.goto dtpmv.goto ctpmv.goto ztpmv.goto \
8485
strsv.goto dtrsv.goto ctrsv.goto ztrsv.goto \
@@ -156,6 +157,7 @@ atlas :: slinpack.atlas dlinpack.atlas clinpack.atlas zlinpack.atlas \
156157
cherk.atlas zherk.atlas \
157158
cher2k.atlas zher2k.atlas \
158159
sgemv.atlas dgemv.atlas cgemv.atlas zgemv.atlas \
160+
sspmv.atlas dspmv.atlas \
159161
strmv.atlas dtrmv.atlas ctrmv.atlas ztrmv.atlas \
160162
stpmv.atlas dtpmv.atlas ctpmv.atlas ztpmv.atlas \
161163
strsv.atlas dtrsv.atlas ctrsv.atlas ztrsv.atlas \
@@ -232,6 +234,7 @@ goto :: sgemm.goto dgemm.goto cgemm.goto zgemm.goto \
232234
cherk.goto zherk.goto \
233235
cher2k.goto zher2k.goto \
234236
sgemv.goto dgemv.goto cgemv.goto zgemv.goto \
237+
sspmv.goto dspmv.goto \
235238
strmv.goto dtrmv.goto ctrmv.goto ztrmv.goto \
236239
stpmv.goto dtpmv.goto ctpmv.goto ztpmv.goto \
237240
strsv.goto dtrsv.goto ctrsv.goto ztrsv.goto \
@@ -315,6 +318,7 @@ atlas :: slinpack.atlas dlinpack.atlas clinpack.atlas zlinpack.atlas \
315318
cherk.atlas zherk.atlas \
316319
cher2k.atlas zher2k.atlas \
317320
sgemv.atlas dgemv.atlas cgemv.atlas zgemv.atlas \
321+
sspmv.atlas dspmv.atlas \
318322
strmv.atlas dtrmv.atlas ctrmv.atlas ztrmv.atlas \
319323
stpmv.atlas dtpmv.atlas ctpmv.atlas ztpmv.atlas \
320324
strsv.atlas dtrsv.atlas ctrsv.atlas ztrsv.atlas \
@@ -1306,6 +1310,20 @@ zgemv.mkl : zgemv.$(SUFFIX)
13061310
zgemv.veclib : zgemv.$(SUFFIX)
13071311
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBVECLIB) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
13081312

1313+
##################################### Sspmv ####################################################
1314+
sspmv.goto : sspmv.$(SUFFIX) ../$(LIBNAME)
1315+
$(CC) $(CFLAGS) -o $(@F) $^ $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB) -lm
1316+
1317+
sspmv.atlas : sspmv.$(SUFFIX)
1318+
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBATLAS) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
1319+
1320+
##################################### Dspmv ####################################################
1321+
dspmv.goto : dspmv.$(SUFFIX) ../$(LIBNAME)
1322+
$(CC) $(CFLAGS) -o $(@F) $^ $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB) -lm
1323+
1324+
dspmv.atlas : dspmv.$(SUFFIX)
1325+
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBATLAS) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
1326+
13091327
##################################### Strmv ####################################################
13101328
strmv.goto : strmv.$(SUFFIX) ../$(LIBNAME)
13111329
$(CC) $(CFLAGS) -o $(@F) $^ $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB) -lm
@@ -2862,6 +2880,12 @@ cgemv.$(SUFFIX) : gemv.c
28622880
zgemv.$(SUFFIX) : gemv.c
28632881
$(CC) $(CFLAGS) -c -DCOMPLEX -DDOUBLE -o $(@F) $^
28642882

2883+
sspmv.$(SUFFIX) : spmv.c
2884+
$(CC) $(CFLAGS) -c -UCOMPLEX -UDOUBLE -o $(@F) $^
2885+
2886+
dspmv.$(SUFFIX) : spmv.c
2887+
$(CC) $(CFLAGS) -c -UCOMPLEX -DDOUBLE -o $(@F) $^
2888+
28652889
strmv.$(SUFFIX) : trmv.c
28662890
$(CC) $(CFLAGS) -c -UCOMPLEX -UDOUBLE -o $(@F) $^
28672891

@@ -3211,4 +3235,3 @@ clean ::
32113235
@rm -f *.goto *.mkl *.acml *.atlas *.veclib *.essl smallscaling
32123236

32133237
include $(TOPDIR)/Makefile.tail
3214-

benchmark/spmv.c

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
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 SPMV
37+
38+
39+
#ifndef COMPLEX
40+
41+
#ifdef DOUBLE
42+
#define SPMV BLASFUNC(dspmv)
43+
#else
44+
#define SPMV BLASFUNC(sspmv)
45+
#endif
46+
47+
#else
48+
49+
#ifdef DOUBLE
50+
#define SPMV BLASFUNC(zspmv)
51+
#else
52+
#define SPMV BLASFUNC(cspmv)
53+
#endif
54+
55+
#endif
56+
57+
#if defined(__WIN32__) || defined(__WIN64__)
58+
59+
#ifndef DELTA_EPOCH_IN_MICROSECS
60+
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
61+
#endif
62+
63+
int gettimeofday(struct timeval *tv, void *tz){
64+
65+
FILETIME ft;
66+
unsigned __int64 tmpres = 0;
67+
static int tzflag;
68+
69+
if (NULL != tv)
70+
{
71+
GetSystemTimeAsFileTime(&ft);
72+
73+
tmpres |= ft.dwHighDateTime;
74+
tmpres <<= 32;
75+
tmpres |= ft.dwLowDateTime;
76+
77+
/*converting file time to unix epoch*/
78+
tmpres /= 10; /*convert into microseconds*/
79+
tmpres -= DELTA_EPOCH_IN_MICROSECS;
80+
tv->tv_sec = (long)(tmpres / 1000000UL);
81+
tv->tv_usec = (long)(tmpres % 1000000UL);
82+
}
83+
84+
return 0;
85+
}
86+
87+
#endif
88+
89+
#if !defined(__WIN32__) && !defined(__WIN64__) && !defined(__CYGWIN32__) && 0
90+
91+
static void *huge_malloc(BLASLONG size){
92+
int shmid;
93+
void *address;
94+
95+
#ifndef SHM_HUGETLB
96+
#define SHM_HUGETLB 04000
97+
#endif
98+
99+
if ((shmid =shmget(IPC_PRIVATE,
100+
(size + HUGE_PAGESIZE) & ~(HUGE_PAGESIZE - 1),
101+
SHM_HUGETLB | IPC_CREAT |0600)) < 0) {
102+
printf( "Memory allocation failed(shmget).\n");
103+
exit(1);
104+
}
105+
106+
address = shmat(shmid, NULL, SHM_RND);
107+
108+
if ((BLASLONG)address == -1){
109+
printf( "Memory allocation failed(shmat).\n");
110+
exit(1);
111+
}
112+
113+
shmctl(shmid, IPC_RMID, 0);
114+
115+
return address;
116+
}
117+
118+
#define malloc huge_malloc
119+
120+
#endif
121+
122+
int main(int argc, char *argv[]){
123+
124+
FLOAT *a, *x, *y;
125+
FLOAT alpha[] = {1.0, 1.0};
126+
FLOAT beta [] = {1.0, 1.0};
127+
char uplo='L';
128+
blasint m, i, j;
129+
blasint inc_x=1,inc_y=1;
130+
int loops = 1;
131+
int l;
132+
char *p;
133+
134+
int from = 1;
135+
int to = 200;
136+
int step = 1;
137+
138+
struct timeval start, stop;
139+
double time1,timeg;
140+
141+
argc--;argv++;
142+
143+
if (argc > 0) { from = atol(*argv); argc--; argv++;}
144+
if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
145+
if (argc > 0) { step = atol(*argv); argc--; argv++;}
146+
147+
if ((p = getenv("OPENBLAS_LOOPS"))) loops = atoi(p);
148+
if ((p = getenv("OPENBLAS_INCX"))) inc_x = atoi(p);
149+
if ((p = getenv("OPENBLAS_INCY"))) inc_y = atoi(p);
150+
if ((p = getenv("OPENBLAS_UPLO"))) uplo=*p;
151+
152+
fprintf(stderr, "From : %3d To : %3d Step = %3d Uplo = '%c' Inc_x = %d Inc_y = %d Loops = %d\n", from, to, step,uplo,inc_x,inc_y,loops);
153+
154+
if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
155+
fprintf(stderr,"Out of Memory!!\n");exit(1);
156+
}
157+
158+
if (( x = (FLOAT *)malloc(sizeof(FLOAT) * to * abs(inc_x) * COMPSIZE)) == NULL){
159+
fprintf(stderr,"Out of Memory!!\n");exit(1);
160+
}
161+
162+
if (( y = (FLOAT *)malloc(sizeof(FLOAT) * to * abs(inc_y) * COMPSIZE)) == NULL){
163+
fprintf(stderr,"Out of Memory!!\n");exit(1);
164+
}
165+
166+
#ifdef linux
167+
srandom(getpid());
168+
#endif
169+
170+
fprintf(stderr, " SIZE Flops\n");
171+
172+
for(m = from; m <= to; m += step)
173+
{
174+
175+
timeg=0;
176+
177+
fprintf(stderr, " %6dx%d : ", (int)m,(int)m);
178+
179+
for(j = 0; j < m; j++){
180+
for(i = 0; i < m * COMPSIZE; i++){
181+
a[(long)i + (long)j * (long)m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
182+
}
183+
}
184+
185+
186+
for (l=0; l<loops; l++)
187+
{
188+
189+
for(i = 0; i < m * COMPSIZE * abs(inc_x); i++){
190+
x[i] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
191+
}
192+
193+
for(i = 0; i < m * COMPSIZE * abs(inc_y); i++){
194+
y[i] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
195+
}
196+
gettimeofday( &start, (struct timezone *)0);
197+
198+
SPMV (&uplo, &m, alpha, a, x, &inc_x, beta, y, &inc_y );
199+
200+
gettimeofday( &stop, (struct timezone *)0);
201+
202+
time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
203+
204+
timeg += time1;
205+
206+
}
207+
208+
timeg /= loops;
209+
210+
fprintf(stderr,
211+
" %10.2f MFlops\n",
212+
COMPSIZE * COMPSIZE * 2. * (double)m * (double)m / timeg * 1.e-6);
213+
214+
}
215+
216+
return 0;
217+
}
218+
219+
// void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));

0 commit comments

Comments
 (0)