You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

syrk.c 5.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. #include <stdio.h>
  28. #include <stdlib.h>
  29. #ifdef __CYGWIN32__
  30. #include <sys/time.h>
  31. #endif
  32. #include "common.h"
  33. #undef SYRK
  34. #ifndef COMPLEX
  35. #ifdef DOUBLE
  36. #define SYRK BLASFUNC(dsyrk)
  37. #else
  38. #define SYRK BLASFUNC(ssyrk)
  39. #endif
  40. #else
  41. #ifdef DOUBLE
  42. #define SYRK BLASFUNC(zsyrk)
  43. #else
  44. #define SYRK BLASFUNC(csyrk)
  45. #endif
  46. #endif
  47. #if defined(__WIN32__) || defined(__WIN64__)
  48. #ifndef DELTA_EPOCH_IN_MICROSECS
  49. #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
  50. #endif
  51. int gettimeofday(struct timeval *tv, void *tz){
  52. FILETIME ft;
  53. unsigned __int64 tmpres = 0;
  54. static int tzflag;
  55. if (NULL != tv)
  56. {
  57. GetSystemTimeAsFileTime(&ft);
  58. tmpres |= ft.dwHighDateTime;
  59. tmpres <<= 32;
  60. tmpres |= ft.dwLowDateTime;
  61. /*converting file time to unix epoch*/
  62. tmpres /= 10; /*convert into microseconds*/
  63. tmpres -= DELTA_EPOCH_IN_MICROSECS;
  64. tv->tv_sec = (long)(tmpres / 1000000UL);
  65. tv->tv_usec = (long)(tmpres % 1000000UL);
  66. }
  67. return 0;
  68. }
  69. #endif
  70. #if !defined(__WIN32__) && !defined(__WIN64__) && !defined(__CYGWIN32__) && 0
  71. static void *huge_malloc(BLASLONG size){
  72. int shmid;
  73. void *address;
  74. #ifndef SHM_HUGETLB
  75. #define SHM_HUGETLB 04000
  76. #endif
  77. if ((shmid =shmget(IPC_PRIVATE,
  78. (size + HUGE_PAGESIZE) & ~(HUGE_PAGESIZE - 1),
  79. SHM_HUGETLB | IPC_CREAT |0600)) < 0) {
  80. printf( "Memory allocation failed(shmget).\n");
  81. exit(1);
  82. }
  83. address = shmat(shmid, NULL, SHM_RND);
  84. if ((BLASLONG)address == -1){
  85. printf( "Memory allocation failed(shmat).\n");
  86. exit(1);
  87. }
  88. shmctl(shmid, IPC_RMID, 0);
  89. return address;
  90. }
  91. #define malloc huge_malloc
  92. #endif
  93. int main(int argc, char *argv[]){
  94. FLOAT *a, *c;
  95. FLOAT alpha[] = {1.0, 1.0};
  96. FLOAT beta [] = {1.0, 1.0};
  97. char *p;
  98. char uplo='U';
  99. char trans='N';
  100. if ((p = getenv("OPENBLAS_UPLO"))) uplo=*p;
  101. if ((p = getenv("OPENBLAS_TRANS"))) trans=*p;
  102. blasint m, i, j;
  103. int from = 1;
  104. int to = 200;
  105. int step = 1;
  106. struct timeval start, stop;
  107. double time1;
  108. argc--;argv++;
  109. if (argc > 0) { from = atol(*argv); argc--; argv++;}
  110. if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
  111. if (argc > 0) { step = atol(*argv); argc--; argv++;}
  112. fprintf(stderr, "From : %3d To : %3d Step = %3d Uplo = %c Trans = %c\n", from, to, step,uplo,trans);
  113. if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  114. fprintf(stderr,"Out of Memory!!\n");exit(1);
  115. }
  116. if (( c = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  117. fprintf(stderr,"Out of Memory!!\n");exit(1);
  118. }
  119. #ifdef linux
  120. srandom(getpid());
  121. #endif
  122. fprintf(stderr, " SIZE Flops\n");
  123. for(m = from; m <= to; m += step)
  124. {
  125. fprintf(stderr, " %6d : ", (int)m);
  126. for(j = 0; j < m; j++){
  127. for(i = 0; i < m * COMPSIZE; i++){
  128. a[i + j * m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  129. c[i + j * m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  130. }
  131. }
  132. gettimeofday( &start, (struct timezone *)0);
  133. SYRK (&uplo, &trans, &m, &m, alpha, a, &m, beta, c, &m );
  134. gettimeofday( &stop, (struct timezone *)0);
  135. time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
  136. gettimeofday( &start, (struct timezone *)0);
  137. fprintf(stderr,
  138. " %10.2f MFlops\n",
  139. COMPSIZE * COMPSIZE * 1. * (double)m * (double)m * (double)m / time1 * 1.e-6);
  140. }
  141. return 0;
  142. }
  143. // void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));