Skip to content

Commit 51019fe

Browse files
authored
Merge pull request #2498 from njutcz/develop
Add benchmark for ?amax, ?max, ?amin, ?min, i?max, i?amin and i?min.
2 parents b6a6ccb + bec7923 commit 51019fe

9 files changed

Lines changed: 4446 additions & 2975 deletions

File tree

benchmark/Makefile

Lines changed: 3127 additions & 2973 deletions
Large diffs are not rendered by default.

benchmark/amax.c

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/***************************************************************************
2+
Copyright (c) 2016, 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 AMAX
37+
38+
#ifdef COMPLEX
39+
#ifdef DOUBLE
40+
#define AMAX BLASFUNC(dzamax)
41+
#else
42+
#define AMAX BLASFUNC(scamax)
43+
#endif
44+
#else
45+
#ifdef DOUBLE
46+
#define AMAX BLASFUNC(damax)
47+
#else
48+
#define AMAX BLASFUNC(samax)
49+
#endif
50+
#endif
51+
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[]){
118+
119+
FLOAT *x;
120+
blasint m, i;
121+
blasint inc_x=1;
122+
int loops = 1;
123+
int l;
124+
char *p;
125+
126+
127+
int from = 1;
128+
int to = 200;
129+
int step = 1;
130+
131+
struct timeval start, stop;
132+
double time1,timeg;
133+
134+
argc--;argv++;
135+
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++;}
139+
140+
if ((p = getenv("OPENBLAS_LOOPS"))) loops = atoi(p);
141+
if ((p = getenv("OPENBLAS_INCX"))) inc_x = atoi(p);
142+
143+
fprintf(stderr, "From : %3d To : %3d Step = %3d Inc_x = %d Loops = %d\n", from, to, step,inc_x,loops);
144+
145+
if (( x = (FLOAT *)malloc(sizeof(FLOAT) * to * abs(inc_x) * COMPSIZE)) == NULL){
146+
fprintf(stderr,"Out of Memory!!\n");exit(1);
147+
}
148+
149+
#ifdef linux
150+
srandom(getpid());
151+
#endif
152+
153+
fprintf(stderr, " SIZE Flops\n");
154+
155+
for(m = from; m <= to; m += step)
156+
{
157+
158+
timeg=0;
159+
160+
fprintf(stderr, " %6d : ", (int)m);
161+
162+
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;
177+
178+
}
179+
180+
timeg /= loops;
181+
182+
fprintf(stderr,
183+
" %10.2f MFlops %10.6f sec\n",
184+
COMPSIZE * sizeof(FLOAT) * 1. * (double)m / timeg * 1.e-6, timeg);
185+
186+
}
187+
188+
return 0;
189+
}
190+
191+
// void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));

benchmark/amin.c

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/***************************************************************************
2+
Copyright (c) 2016, 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 AMIN
37+
38+
#ifdef COMPLEX
39+
#ifdef DOUBLE
40+
#define AMIN BLASFUNC(dzamin)
41+
#else
42+
#define AMIN BLASFUNC(scamin)
43+
#endif
44+
#else
45+
#ifdef DOUBLE
46+
#define AMIN BLASFUNC(damin)
47+
#else
48+
#define AMIN BLASFUNC(samin)
49+
#endif
50+
#endif
51+
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[]){
118+
119+
FLOAT *x;
120+
blasint m, i;
121+
blasint inc_x=1;
122+
int loops = 1;
123+
int l;
124+
char *p;
125+
126+
int from = 1;
127+
int to = 200;
128+
int step = 1;
129+
130+
struct timeval start, stop;
131+
double time1,timeg;
132+
133+
argc--;argv++;
134+
135+
if (argc > 0) { from = atol(*argv); argc--; argv++;}
136+
if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
137+
if (argc > 0) { step = atol(*argv); argc--; argv++;}
138+
139+
if ((p = getenv("OPENBLAS_LOOPS"))) loops = atoi(p);
140+
if ((p = getenv("OPENBLAS_INCX"))) inc_x = atoi(p);
141+
142+
fprintf(stderr, "From : %3d To : %3d Step = %3d Inc_x = %d Loops = %d\n", from, to, step,inc_x,loops);
143+
144+
if (( x = (FLOAT *)malloc(sizeof(FLOAT) * to * abs(inc_x) * COMPSIZE)) == NULL){
145+
fprintf(stderr,"Out of Memory!!\n");exit(1);
146+
}
147+
148+
#ifdef linux
149+
srandom(getpid());
150+
#endif
151+
152+
fprintf(stderr, " SIZE Flops\n");
153+
154+
for(m = from; m <= to; m += step)
155+
{
156+
157+
timeg=0;
158+
159+
fprintf(stderr, " %6d : ", (int)m);
160+
161+
162+
for (l=0; l<loops; l++)
163+
{
164+
165+
for(i = 0; i < m * COMPSIZE * abs(inc_x); i++){
166+
x[i] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
167+
}
168+
169+
gettimeofday( &start, (struct timezone *)0);
170+
171+
AMIN (&m, x, &inc_x);
172+
173+
gettimeofday( &stop, (struct timezone *)0);
174+
175+
time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
176+
177+
timeg += time1;
178+
179+
}
180+
181+
timeg /= loops;
182+
183+
fprintf(stderr,
184+
" %10.2f MFlops %10.6f sec\n",
185+
COMPSIZE * sizeof(FLOAT) * 1. * (double)m / timeg * 1.e-6, timeg);
186+
187+
}
188+
189+
return 0;
190+
}
191+
192+
// void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));

0 commit comments

Comments
 (0)