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.

gemv.c 6.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /***************************************************************************
  2. Copyright (c) 2014, 2025 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 "bench.h"
  28. #undef GEMV
  29. #ifndef COMPLEX
  30. #ifdef DOUBLE
  31. #define GEMV BLASFUNC(dgemv)
  32. #elif defined(BFLOAT16) && defined(BGEMM)
  33. #define GEMV BLASFUNC(bgemv)
  34. #elif defined(BFLOAT16)
  35. #define GEMV BLASFUNC(sbgemv)
  36. #undef IFLOAT
  37. #define IFLOAT bfloat16
  38. #else
  39. #define GEMV BLASFUNC(sgemv)
  40. #endif
  41. #else
  42. #ifdef DOUBLE
  43. #define GEMV BLASFUNC(zgemv)
  44. #else
  45. #define GEMV BLASFUNC(cgemv)
  46. #endif
  47. #endif
  48. int main(int argc, char *argv[]){
  49. IFLOAT *a, *x;
  50. FLOAT *y;
  51. #ifdef BGEMM
  52. blasint one=1;
  53. blasint two=2;
  54. float alpha_in[] = {1.0, 0.0};
  55. float beta_in[] = {0.0, 0.0};
  56. FLOAT alpha[2], beta[2];
  57. sbstobf16_(&two, alpha_in, &one, alpha, &one);
  58. sbstobf16_(&two, beta_in, &one, beta, &one);
  59. #else
  60. FLOAT alpha[] = {1.0, 0.0};
  61. FLOAT beta [] = {0.0, 0.0};
  62. #endif
  63. char trans='N';
  64. blasint m, i, j;
  65. blasint inc_x=1,inc_y=1;
  66. blasint n=0;
  67. int has_param_n = 0;
  68. int has_param_m = 0;
  69. int loops = 1;
  70. int l;
  71. char *p;
  72. int from = 1;
  73. int to = 200;
  74. int step = 1;
  75. double time1,timeg;
  76. argc--;argv++;
  77. if (argc > 0) { from = atol(*argv); argc--; argv++;}
  78. if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
  79. if (argc > 0) { step = atol(*argv); argc--; argv++;}
  80. int tomax = to;
  81. if ((p = getenv("OPENBLAS_LOOPS"))) loops = atoi(p);
  82. if ((p = getenv("OPENBLAS_INCX"))) inc_x = atoi(p);
  83. if ((p = getenv("OPENBLAS_INCY"))) inc_y = atoi(p);
  84. if ((p = getenv("OPENBLAS_TRANS"))) trans=*p;
  85. if ((p = getenv("OPENBLAS_PARAM_N"))) {
  86. n = atoi(p);
  87. if ((n>0)) has_param_n = 1;
  88. if ( n > tomax ) tomax = n;
  89. }
  90. if ( has_param_n == 0 )
  91. if ((p = getenv("OPENBLAS_PARAM_M"))) {
  92. m = atoi(p);
  93. if ((m>0)) has_param_m = 1;
  94. if ( m > tomax ) tomax = m;
  95. }
  96. fprintf(stderr, "From : %3d To : %3d Step = %3d Trans = '%c' Inc_x = %d Inc_y = %d Loops = %d\n", from, to, step,trans,inc_x,inc_y,loops);
  97. if (( a = (IFLOAT *)malloc(sizeof(IFLOAT) * tomax * tomax * COMPSIZE)) == NULL){
  98. fprintf(stderr,"Out of Memory!!\n");exit(1);
  99. }
  100. if (( x = (IFLOAT *)malloc(sizeof(IFLOAT) * tomax * abs(inc_x) * COMPSIZE)) == NULL){
  101. fprintf(stderr,"Out of Memory!!\n");exit(1);
  102. }
  103. if (( y = (FLOAT *)malloc(sizeof(FLOAT) * tomax * abs(inc_y) * COMPSIZE)) == NULL){
  104. fprintf(stderr,"Out of Memory!!\n");exit(1);
  105. }
  106. #ifdef __linux
  107. srandom(getpid());
  108. #endif
  109. fprintf(stderr, " SIZE Flops\n");
  110. if (has_param_m == 0)
  111. {
  112. for(m = from; m <= to; m += step)
  113. {
  114. timeg=0;
  115. if ( has_param_n == 0 ) n = m;
  116. fprintf(stderr, " %6dx%d : ", (int)m,(int)n);
  117. for(j = 0; j < m; j++){
  118. for(i = 0; i < n * COMPSIZE; i++){
  119. a[(long)i + (long)j * (long)m * COMPSIZE] = ((IFLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  120. }
  121. }
  122. for (l=0; l<loops; l++)
  123. {
  124. for(i = 0; i < n * COMPSIZE * abs(inc_x); i++){
  125. x[i] = ((IFLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  126. }
  127. for(i = 0; i < m * COMPSIZE * abs(inc_y); i++){
  128. y[i] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  129. }
  130. begin();
  131. GEMV (&trans, &m, &n, alpha, a, &m, x, &inc_x, beta, y, &inc_y );
  132. end();
  133. time1 = getsec();
  134. timeg += time1;
  135. }
  136. timeg /= loops;
  137. fprintf(stderr, " %10.2f MFlops %10.6f sec\n", COMPSIZE * COMPSIZE * 2. * (double)m * (double)n / timeg * 1.e-6, timeg);
  138. }
  139. }
  140. else
  141. {
  142. for(n = from; n <= to; n += step)
  143. {
  144. timeg=0;
  145. fprintf(stderr, " %6dx%d : ", (int)m,(int)n);
  146. for(j = 0; j < m; j++){
  147. for(i = 0; i < n * COMPSIZE; i++){
  148. a[(long)i + (long)j * (long)m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  149. }
  150. }
  151. for (l=0; l<loops; l++)
  152. {
  153. for(i = 0; i < n * COMPSIZE * abs(inc_x); i++){
  154. x[i] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  155. }
  156. for(i = 0; i < m * COMPSIZE * abs(inc_y); i++){
  157. y[i] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  158. }
  159. begin();
  160. GEMV (&trans, &m, &n, alpha, a, &m, x, &inc_x, beta, y, &inc_y );
  161. end();
  162. time1 = getsec();
  163. timeg += time1;
  164. }
  165. timeg /= loops;
  166. fprintf(stderr, " %10.2f MFlops %10.6f sec\n", COMPSIZE * COMPSIZE * 2. * (double)m * (double)n / timeg * 1.e-6, timeg);
  167. }
  168. }
  169. return 0;
  170. }
  171. // void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));