|
| 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