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.

zgemv.c 7.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* All rights reserved. */
  4. /* */
  5. /* Redistribution and use in source and binary forms, with or */
  6. /* without modification, are permitted provided that the following */
  7. /* conditions are met: */
  8. /* */
  9. /* 1. Redistributions of source code must retain the above */
  10. /* copyright notice, this list of conditions and the following */
  11. /* disclaimer. */
  12. /* */
  13. /* 2. Redistributions in binary form must reproduce the above */
  14. /* copyright notice, this list of conditions and the following */
  15. /* disclaimer in the documentation and/or other materials */
  16. /* provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  19. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  20. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  21. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  22. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  23. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  24. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  25. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  26. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  27. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  28. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  29. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  30. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  31. /* POSSIBILITY OF SUCH DAMAGE. */
  32. /* */
  33. /* The views and conclusions contained in the software and */
  34. /* documentation are those of the authors and should not be */
  35. /* interpreted as representing official policies, either expressed */
  36. /* or implied, of The University of Texas at Austin. */
  37. /*********************************************************************/
  38. #include <stdio.h>
  39. #include "common.h"
  40. #ifdef FUNCTION_PROFILE
  41. #include "functable.h"
  42. #endif
  43. #ifdef XDOUBLE
  44. #define ERROR_NAME "XGEMV "
  45. #elif defined(DOUBLE)
  46. #define ERROR_NAME "ZGEMV "
  47. #else
  48. #define ERROR_NAME "CGEMV "
  49. #endif
  50. #ifdef SMP
  51. static int (*gemv_thread[])(BLASLONG, BLASLONG, FLOAT *, FLOAT *, BLASLONG, FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *, int) = {
  52. #ifdef XDOUBLE
  53. xgemv_thread_n, xgemv_thread_t, xgemv_thread_r, xgemv_thread_c, xgemv_thread_o, xgemv_thread_u, xgemv_thread_s, xgemv_thread_d,
  54. #elif defined DOUBLE
  55. zgemv_thread_n, zgemv_thread_t, zgemv_thread_r, zgemv_thread_c, zgemv_thread_o, zgemv_thread_u, zgemv_thread_s, zgemv_thread_d,
  56. #else
  57. cgemv_thread_n, cgemv_thread_t, cgemv_thread_r, cgemv_thread_c, cgemv_thread_o, cgemv_thread_u, cgemv_thread_s, cgemv_thread_d,
  58. #endif
  59. };
  60. #endif
  61. #ifndef CBLAS
  62. void NAME(char *TRANS, blasint *M, blasint *N,
  63. FLOAT *ALPHA, FLOAT *a, blasint *LDA,
  64. FLOAT *x, blasint *INCX,
  65. FLOAT *BETA, FLOAT *y, blasint *INCY){
  66. char trans = *TRANS;
  67. blasint m = *M;
  68. blasint n = *N;
  69. blasint lda = *LDA;
  70. blasint incx = *INCX;
  71. blasint incy = *INCY;
  72. FLOAT *buffer;
  73. #ifdef SMP
  74. int nthreads;
  75. int nthreads_max;
  76. int nthreads_avail;
  77. double MNK;
  78. #endif
  79. int (*gemv[])(BLASLONG, BLASLONG, BLASLONG, FLOAT, FLOAT, FLOAT *, BLASLONG,
  80. FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
  81. GEMV_N, GEMV_T, GEMV_R, GEMV_C,
  82. GEMV_O, GEMV_U, GEMV_S, GEMV_D,
  83. };
  84. blasint info;
  85. blasint lenx, leny;
  86. blasint i;
  87. FLOAT alpha_r = *(ALPHA + 0);
  88. FLOAT alpha_i = *(ALPHA + 1);
  89. FLOAT beta_r = *(BETA + 0);
  90. FLOAT beta_i = *(BETA + 1);
  91. PRINT_DEBUG_NAME;
  92. TOUPPER(trans);
  93. info = 0;
  94. i = -1;
  95. if (trans == 'N') i = 0;
  96. if (trans == 'T') i = 1;
  97. if (trans == 'R') i = 2;
  98. if (trans == 'C') i = 3;
  99. if (trans == 'O') i = 4;
  100. if (trans == 'U') i = 5;
  101. if (trans == 'S') i = 6;
  102. if (trans == 'D') i = 7;
  103. if (incy == 0) info = 11;
  104. if (incx == 0) info = 8;
  105. if (lda < MAX(1,m)) info = 6;
  106. if (n < 0) info = 3;
  107. if (m < 0) info = 2;
  108. if (i < 0) info = 1;
  109. trans = i;
  110. if (info != 0) {
  111. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  112. return;
  113. }
  114. #else
  115. void CNAME(enum CBLAS_ORDER order,
  116. enum CBLAS_TRANSPOSE TransA,
  117. blasint m, blasint n,
  118. FLOAT *ALPHA,
  119. FLOAT *a, blasint lda,
  120. FLOAT *x, blasint incx,
  121. FLOAT *BETA,
  122. FLOAT *y, blasint incy){
  123. FLOAT *buffer;
  124. blasint lenx, leny;
  125. int trans;
  126. blasint info, t;
  127. #ifdef SMP
  128. int nthreads;
  129. int nthreads_max;
  130. int nthreads_avail;
  131. double MNK;
  132. #endif
  133. int (*gemv[])(BLASLONG, BLASLONG, BLASLONG, FLOAT, FLOAT, FLOAT *, BLASLONG,
  134. FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
  135. GEMV_N, GEMV_T, GEMV_R, GEMV_C,
  136. GEMV_O, GEMV_U, GEMV_S, GEMV_D,
  137. };
  138. FLOAT alpha_r = *(ALPHA + 0);
  139. FLOAT alpha_i = *(ALPHA + 1);
  140. FLOAT beta_r = *(BETA + 0);
  141. FLOAT beta_i = *(BETA + 1);
  142. PRINT_DEBUG_CNAME;
  143. trans = -1;
  144. info = 0;
  145. if (order == CblasColMajor) {
  146. if (TransA == CblasNoTrans) trans = 0;
  147. if (TransA == CblasTrans) trans = 1;
  148. if (TransA == CblasConjNoTrans) trans = 2;
  149. if (TransA == CblasConjTrans) trans = 3;
  150. info = -1;
  151. if (incy == 0) info = 11;
  152. if (incx == 0) info = 8;
  153. if (lda < MAX(1, m)) info = 6;
  154. if (n < 0) info = 3;
  155. if (m < 0) info = 2;
  156. if (trans < 0) info = 1;
  157. }
  158. if (order == CblasRowMajor) {
  159. if (TransA == CblasNoTrans) trans = 1;
  160. if (TransA == CblasTrans) trans = 0;
  161. if (TransA == CblasConjNoTrans) trans = 3;
  162. if (TransA == CblasConjTrans) trans = 2;
  163. info = -1;
  164. t = n;
  165. n = m;
  166. m = t;
  167. if (incy == 0) info = 11;
  168. if (incx == 0) info = 8;
  169. if (lda < MAX(1, m)) info = 6;
  170. if (n < 0) info = 3;
  171. if (m < 0) info = 2;
  172. if (trans < 0) info = 1;
  173. }
  174. if (info >= 0) {
  175. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  176. return;
  177. }
  178. #endif
  179. /* Quick return if possible. */
  180. if (m == 0 || n == 0) return;
  181. lenx = n;
  182. leny = m;
  183. if (trans & 1) lenx = m;
  184. if (trans & 1) leny = n;
  185. if (beta_r != ONE || beta_i != ZERO) SCAL_K(leny, 0, 0, beta_r, beta_i, y, abs(incy), NULL, 0, NULL, 0);
  186. if (alpha_r == ZERO && alpha_i == ZERO) return;
  187. IDEBUG_START;
  188. FUNCTION_PROFILE_START();
  189. if (incx < 0) x -= (lenx - 1) * incx * 2;
  190. if (incy < 0) y -= (leny - 1) * incy * 2;
  191. buffer = (FLOAT *)blas_memory_alloc(1);
  192. #ifdef SMP
  193. nthreads_max = num_cpu_avail(2);
  194. nthreads_avail = nthreads_max;
  195. MNK = (double) m * (double) n;
  196. if ( MNK <= ( 256.0 * (double) (GEMM_MULTITHREAD_THRESHOLD * GEMM_MULTITHREAD_THRESHOLD) ))
  197. nthreads_max = 1;
  198. if ( nthreads_max > nthreads_avail )
  199. nthreads = nthreads_avail;
  200. else
  201. nthreads = nthreads_max;
  202. if (nthreads == 1) {
  203. #endif
  204. (gemv[(int)trans])(m, n, 0, alpha_r, alpha_i, a, lda, x, incx, y, incy, buffer);
  205. #ifdef SMP
  206. } else {
  207. (gemv_thread[(int)trans])(m, n, ALPHA, a, lda, x, incx, y, incy, buffer, nthreads);
  208. }
  209. #endif
  210. blas_memory_free(buffer);
  211. FUNCTION_PROFILE_END(4, m * n + m + n, 2 * m * n);
  212. IDEBUG_END;
  213. return;
  214. }