Skip to content

Commit ae6b7ca

Browse files
committed
Merge pull request #453 from wernsaar/develop
Enabled GEMM3M functions
2 parents 466bfb8 + f446d23 commit ae6b7ca

25 files changed

Lines changed: 13757 additions & 39 deletions

benchmark/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ mkl :: slinpack.mkl dlinpack.mkl clinpack.mkl zlinpack.mkl \
112112
spotrf.mkl dpotrf.mkl cpotrf.mkl zpotrf.mkl \
113113
ssymm.mkl dsymm.mkl csymm.mkl zsymm.mkl
114114

115+
116+
goto_3m :: cgemm3m.goto zgemm3m.goto
117+
118+
mkl_3m :: cgemm3m.mkl zgemm3m.mkl
119+
115120
all :: goto mkl atlas acml
116121

117122
##################################### Slinpack ####################################################
@@ -1043,6 +1048,22 @@ zaxpy.mkl : zaxpy.$(SUFFIX)
10431048
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBMKL) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
10441049

10451050

1051+
##################################### Cgemm3m ####################################################
1052+
1053+
cgemm3m.goto : cgemm3m.$(SUFFIX) ../$(LIBNAME)
1054+
$(CC) $(CFLAGS) -o $(@F) $^ $(CEXTRALIB) $(EXTRALIB) -lm
1055+
1056+
cgemm3m.mkl : cgemm3m.$(SUFFIX)
1057+
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBMKL) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
1058+
1059+
##################################### Zgemm3m ####################################################
1060+
1061+
zgemm3m.goto : zgemm3m.$(SUFFIX) ../$(LIBNAME)
1062+
$(CC) $(CFLAGS) -o $(@F) $^ $(CEXTRALIB) $(EXTRALIB) -lm
1063+
1064+
zgemm3m.mkl : zgemm3m.$(SUFFIX)
1065+
-$(CC) $(CFLAGS) -o $(@F) $^ $(LIBMKL) $(CEXTRALIB) $(EXTRALIB) $(FEXTRALIB)
1066+
10461067

10471068
###################################################################################################
10481069

@@ -1250,6 +1271,11 @@ caxpy.$(SUFFIX) : axpy.c
12501271
zaxpy.$(SUFFIX) : axpy.c
12511272
$(CC) $(CFLAGS) -c -DCOMPLEX -DDOUBLE -o $(@F) $^
12521273

1274+
cgemm3m.$(SUFFIX) : gemm3m.c
1275+
$(CC) $(CFLAGS) -c -DCOMPLEX -UDOUBLE -o $(@F) $^
1276+
1277+
zgemm3m.$(SUFFIX) : gemm3m.c
1278+
$(CC) $(CFLAGS) -c -DCOMPLEX -DDOUBLE -o $(@F) $^
12531279

12541280

12551281
clean ::

benchmark/gemm3m.c

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
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(zgemm3m)
50+
#else
51+
#define GEMM BLASFUNC(cgemm3m)
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+
if ((p = getenv("OPENBLAS_TRANS"))) trans=*p;
146+
147+
fprintf(stderr, "From : %3d To : %3d Step=%d : Trans=%c\n", from, to, step, trans);
148+
149+
if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
150+
fprintf(stderr,"Out of Memory!!\n");exit(1);
151+
}
152+
153+
if (( b = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
154+
fprintf(stderr,"Out of Memory!!\n");exit(1);
155+
}
156+
157+
if (( c = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
158+
fprintf(stderr,"Out of Memory!!\n");exit(1);
159+
}
160+
161+
p = getenv("OPENBLAS_LOOPS");
162+
if ( p != NULL )
163+
loops = atoi(p);
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, " %6d : ", (int)m);
178+
179+
for (l=0; l<loops; l++)
180+
{
181+
182+
for(j = 0; j < m; j++){
183+
for(i = 0; i < m * COMPSIZE; i++){
184+
a[i + j * m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
185+
b[i + j * m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
186+
c[i + j * m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
187+
}
188+
}
189+
190+
gettimeofday( &start, (struct timezone *)0);
191+
192+
GEMM (&trans, &trans, &m, &m, &m, alpha, a, &m, b, &m, beta, c, &m );
193+
194+
gettimeofday( &stop, (struct timezone *)0);
195+
196+
time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
197+
198+
timeg += time1;
199+
200+
}
201+
202+
timeg /= loops;
203+
fprintf(stderr,
204+
" %10.2f MFlops\n",
205+
COMPSIZE * COMPSIZE * 2. * (double)m * (double)m * (double)m / timeg * 1.e-6);
206+
207+
}
208+
209+
return 0;
210+
}
211+
212+
void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));

cblas.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,13 @@ void cblas_dgemm(OPENBLAS_CONST enum CBLAS_ORDER Order, OPENBLAS_CONST enum CBLA
243243
OPENBLAS_CONST double alpha, OPENBLAS_CONST double *A, OPENBLAS_CONST blasint lda, OPENBLAS_CONST double *B, OPENBLAS_CONST blasint ldb, OPENBLAS_CONST double beta, double *C, OPENBLAS_CONST blasint ldc);
244244
void cblas_cgemm(OPENBLAS_CONST enum CBLAS_ORDER Order, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransA, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransB, OPENBLAS_CONST blasint M, OPENBLAS_CONST blasint N, OPENBLAS_CONST blasint K,
245245
OPENBLAS_CONST float *alpha, OPENBLAS_CONST float *A, OPENBLAS_CONST blasint lda, OPENBLAS_CONST float *B, OPENBLAS_CONST blasint ldb, OPENBLAS_CONST float *beta, float *C, OPENBLAS_CONST blasint ldc);
246+
void cblas_cgemm3m(OPENBLAS_CONST enum CBLAS_ORDER Order, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransA, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransB, OPENBLAS_CONST blasint M, OPENBLAS_CONST blasint N, OPENBLAS_CONST blasint K,
247+
OPENBLAS_CONST float *alpha, OPENBLAS_CONST float *A, OPENBLAS_CONST blasint lda, OPENBLAS_CONST float *B, OPENBLAS_CONST blasint ldb, OPENBLAS_CONST float *beta, float *C, OPENBLAS_CONST blasint ldc);
246248
void cblas_zgemm(OPENBLAS_CONST enum CBLAS_ORDER Order, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransA, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransB, OPENBLAS_CONST blasint M, OPENBLAS_CONST blasint N, OPENBLAS_CONST blasint K,
247249
OPENBLAS_CONST double *alpha, OPENBLAS_CONST double *A, OPENBLAS_CONST blasint lda, OPENBLAS_CONST double *B, OPENBLAS_CONST blasint ldb, OPENBLAS_CONST double *beta, double *C, OPENBLAS_CONST blasint ldc);
250+
void cblas_zgemm3m(OPENBLAS_CONST enum CBLAS_ORDER Order, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransA, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransB, OPENBLAS_CONST blasint M, OPENBLAS_CONST blasint N, OPENBLAS_CONST blasint K,
251+
OPENBLAS_CONST double *alpha, OPENBLAS_CONST double *A, OPENBLAS_CONST blasint lda, OPENBLAS_CONST double *B, OPENBLAS_CONST blasint ldb, OPENBLAS_CONST double *beta, double *C, OPENBLAS_CONST blasint ldc);
252+
248253

249254
void cblas_ssymm(OPENBLAS_CONST enum CBLAS_ORDER Order, OPENBLAS_CONST enum CBLAS_SIDE Side, OPENBLAS_CONST enum CBLAS_UPLO Uplo, OPENBLAS_CONST blasint M, OPENBLAS_CONST blasint N,
250255
OPENBLAS_CONST float alpha, OPENBLAS_CONST float *A, OPENBLAS_CONST blasint lda, OPENBLAS_CONST float *B, OPENBLAS_CONST blasint ldb, OPENBLAS_CONST float beta, float *C, OPENBLAS_CONST blasint ldc);

cblas_noconst.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,12 @@ void cblas_dgemm(enum CBLAS_ORDER Order, enum CBLAS_TRANSPOSE TransA, enum CBLAS
231231
double alpha, double *A, blasint lda, double *B, blasint ldb, double beta, double *C, blasint ldc);
232232
void cblas_cgemm(enum CBLAS_ORDER Order, enum CBLAS_TRANSPOSE TransA, enum CBLAS_TRANSPOSE TransB, blasint M, blasint N, blasint K,
233233
float *alpha, float *A, blasint lda, float *B, blasint ldb, float *beta, float *C, blasint ldc);
234+
void cblas_cgemm3m(enum CBLAS_ORDER Order, enum CBLAS_TRANSPOSE TransA, enum CBLAS_TRANSPOSE TransB, blasint M, blasint N, blasint K,
235+
float *alpha, float *A, blasint lda, float *B, blasint ldb, float *beta, float *C, blasint ldc);
234236
void cblas_zgemm(enum CBLAS_ORDER Order, enum CBLAS_TRANSPOSE TransA, enum CBLAS_TRANSPOSE TransB, blasint M, blasint N, blasint K,
235237
double *alpha, double *A, blasint lda, double *B, blasint ldb, double *beta, double *C, blasint ldc);
238+
void cblas_zgemm3m(enum CBLAS_ORDER Order, enum CBLAS_TRANSPOSE TransA, enum CBLAS_TRANSPOSE TransB, blasint M, blasint N, blasint K,
239+
double *alpha, double *A, blasint lda, double *B, blasint ldb, double *beta, double *C, blasint ldc);
236240

237241
void cblas_ssymm(enum CBLAS_ORDER Order, enum CBLAS_SIDE Side, enum CBLAS_UPLO Uplo, blasint M, blasint N,
238242
float alpha, float *A, blasint lda, float *B, blasint ldb, float beta, float *C, blasint ldc);

0 commit comments

Comments
 (0)