Skip to content

Commit fb0b455

Browse files
committed
added hemv benchmark
1 parent 6f73ffc commit fb0b455

File tree

2 files changed

+246
-0
lines changed

2 files changed

+246
-0
lines changed

benchmark/Makefile

+38
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ goto :: slinpack.goto dlinpack.goto clinpack.goto zlinpack.goto \
3636
ssyr2k.goto dsyr2k.goto csyr2k.goto zsyr2k.goto \
3737
sger.goto dger.goto \
3838
ssymv.goto dsymv.goto csymv.goto zsymv.goto \
39+
chemv.goto zhemv.goto \
3940
chemm.goto zhemm.goto \
4041
cherk.goto zherk.goto \
4142
cher2k.goto zher2k.goto \
@@ -54,6 +55,7 @@ acml :: slinpack.acml dlinpack.acml clinpack.acml zlinpack.acml \
5455
ssyr2k.acml dsyr2k.acml csyr2k.acml zsyr2k.acml \
5556
sger.acml dger.acml \
5657
ssymv.acml dsymv.acml csymv.acml zsymv.acml \
58+
chemv.acml zhemv.acml \
5759
chemm.acml zhemm.acml \
5860
cherk.acml zherk.acml \
5961
cher2k.acml zher2k.acml \
@@ -72,6 +74,7 @@ atlas :: slinpack.atlas dlinpack.atlas clinpack.atlas zlinpack.atlas \
7274
ssyr2k.atlas dsyr2k.atlas csyr2k.atlas zsyr2k.atlas \
7375
sger.atlas dger.atlas \
7476
ssymv.atlas dsymv.atlas csymv.atlas zsymv.atlas \
77+
chemv.atlas zhemv.atlas \
7578
chemm.acml zhemm.acml \
7679
chemm.atlas zhemm.atlas \
7780
cherk.atlas zherk.atlas \
@@ -91,6 +94,7 @@ mkl :: slinpack.mkl dlinpack.mkl clinpack.mkl zlinpack.mkl \
9194
ssyr2k.mkl dsyr2k.mkl csyr2k.mkl zsyr2k.mkl \
9295
sger.mkl dger.mkl \
9396
ssymv.mkl dsymv.mkl csymv.mkl zsymv.mkl \
97+
chemv.mkl zhemv.mkl \
9498
chemm.mkl zhemm.mkl \
9599
cherk.mkl zherk.mkl \
96100
cher2k.mkl zher2k.mkl \
@@ -922,6 +926,33 @@ zpotrf.atlas : zpotrf.$(SUFFIX)
922926
zpotrf.mkl : zpotrf.$(SUFFIX)
923927
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBMKL) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
924928

929+
##################################### Chemv ####################################################
930+
931+
chemv.goto : chemv.$(SUFFIX) ../$(LIBNAME)
932+
$(CC) $(CFLAGS) -o $(@F) $^ $(CEXTRALIB) $(EXTRALIB) -lm
933+
934+
chemv.acml : chemv.$(SUFFIX)
935+
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBACML) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
936+
937+
chemv.atlas : chemv.$(SUFFIX)
938+
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBATLAS) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
939+
940+
chemv.mkl : chemv.$(SUFFIX)
941+
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBMKL) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
942+
943+
##################################### Zhemv ####################################################
944+
945+
zhemv.goto : zhemv.$(SUFFIX) ../$(LIBNAME)
946+
$(CC) $(CFLAGS) -o $(@F) $^ $(CEXTRALIB) $(EXTRALIB) -lm
947+
948+
zhemv.acml : zhemv.$(SUFFIX)
949+
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBACML) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
950+
951+
zhemv.atlas : zhemv.$(SUFFIX)
952+
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBATLAS) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
953+
954+
zhemv.mkl : zhemv.$(SUFFIX)
955+
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBMKL) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
925956

926957
###################################################################################################
927958

@@ -1105,6 +1136,13 @@ cpotrf.$(SUFFIX) : potrf.c
11051136
zpotrf.$(SUFFIX) : potrf.c
11061137
$(CC) $(CFLAGS) -c -DCOMPLEX -DDOUBLE -o $(@F) $^
11071138

1139+
chemv.$(SUFFIX) : hemv.c
1140+
$(CC) $(CFLAGS) -c -DCOMPLEX -UDOUBLE -o $(@F) $^
1141+
1142+
zhemv.$(SUFFIX) : hemv.c
1143+
$(CC) $(CFLAGS) -c -DCOMPLEX -DDOUBLE -o $(@F) $^
1144+
1145+
11081146

11091147

11101148

benchmark/hemv.c

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

0 commit comments

Comments
 (0)