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.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. #endif
  76. int (*gemv[])(BLASLONG, BLASLONG, BLASLONG, FLOAT, FLOAT, FLOAT *, BLASLONG,
  77. FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
  78. GEMV_N, GEMV_T, GEMV_R, GEMV_C,
  79. GEMV_O, GEMV_U, GEMV_S, GEMV_D,
  80. };
  81. blasint info;
  82. blasint lenx, leny;
  83. blasint i;
  84. PRINT_DEBUG_NAME;
  85. FLOAT alpha_r = *(ALPHA + 0);
  86. FLOAT alpha_i = *(ALPHA + 1);
  87. FLOAT beta_r = *(BETA + 0);
  88. FLOAT beta_i = *(BETA + 1);
  89. TOUPPER(trans);
  90. info = 0;
  91. i = -1;
  92. if (trans == 'N') i = 0;
  93. if (trans == 'T') i = 1;
  94. if (trans == 'R') i = 2;
  95. if (trans == 'C') i = 3;
  96. if (trans == 'O') i = 4;
  97. if (trans == 'U') i = 5;
  98. if (trans == 'S') i = 6;
  99. if (trans == 'D') i = 7;
  100. if (incy == 0) info = 11;
  101. if (incx == 0) info = 8;
  102. if (lda < MAX(1,m)) info = 6;
  103. if (n < 0) info = 3;
  104. if (m < 0) info = 2;
  105. if (i < 0) info = 1;
  106. trans = i;
  107. if (info != 0) {
  108. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  109. return;
  110. }
  111. #else
  112. void CNAME(enum CBLAS_ORDER order,
  113. enum CBLAS_TRANSPOSE TransA,
  114. blasint m, blasint n,
  115. FLOAT *ALPHA,
  116. FLOAT *a, blasint lda,
  117. FLOAT *x, blasint incx,
  118. FLOAT *BETA,
  119. FLOAT *y, blasint incy){
  120. FLOAT *buffer;
  121. blasint lenx, leny;
  122. int trans;
  123. blasint info, t;
  124. #ifdef SMP
  125. int nthreads;
  126. #endif
  127. int (*gemv[])(BLASLONG, BLASLONG, BLASLONG, FLOAT, FLOAT, FLOAT *, BLASLONG,
  128. FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
  129. GEMV_N, GEMV_T, GEMV_R, GEMV_C,
  130. GEMV_O, GEMV_U, GEMV_S, GEMV_D,
  131. };
  132. PRINT_DEBUG_CNAME;
  133. FLOAT alpha_r = *(ALPHA + 0);
  134. FLOAT alpha_i = *(ALPHA + 1);
  135. FLOAT beta_r = *(BETA + 0);
  136. FLOAT beta_i = *(BETA + 1);
  137. trans = -1;
  138. info = 0;
  139. if (order == CblasColMajor) {
  140. if (TransA == CblasNoTrans) trans = 0;
  141. if (TransA == CblasTrans) trans = 1;
  142. if (TransA == CblasConjNoTrans) trans = 2;
  143. if (TransA == CblasConjTrans) trans = 3;
  144. info = -1;
  145. if (incy == 0) info = 11;
  146. if (incx == 0) info = 8;
  147. if (lda < MAX(1, m)) info = 6;
  148. if (n < 0) info = 3;
  149. if (m < 0) info = 2;
  150. if (trans < 0) info = 1;
  151. }
  152. if (order == CblasRowMajor) {
  153. if (TransA == CblasNoTrans) trans = 1;
  154. if (TransA == CblasTrans) trans = 0;
  155. if (TransA == CblasConjNoTrans) trans = 3;
  156. if (TransA == CblasConjTrans) trans = 2;
  157. info = -1;
  158. t = n;
  159. n = m;
  160. m = t;
  161. if (incy == 0) info = 11;
  162. if (incx == 0) info = 8;
  163. if (lda < MAX(1, m)) info = 6;
  164. if (n < 0) info = 3;
  165. if (m < 0) info = 2;
  166. if (trans < 0) info = 1;
  167. }
  168. if (info >= 0) {
  169. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  170. return;
  171. }
  172. #endif
  173. /* Quick return if possible. */
  174. if (m == 0 || n == 0) return;
  175. lenx = n;
  176. leny = m;
  177. if (trans & 1) lenx = m;
  178. if (trans & 1) leny = n;
  179. if (beta_r != ONE || beta_i != ZERO) SCAL_K(leny, 0, 0, beta_r, beta_i, y, abs(incy), NULL, 0, NULL, 0);
  180. if (alpha_r == ZERO && alpha_i == ZERO) return;
  181. IDEBUG_START;
  182. FUNCTION_PROFILE_START();
  183. if (incx < 0) x -= (lenx - 1) * incx * 2;
  184. if (incy < 0) y -= (leny - 1) * incy * 2;
  185. buffer = (FLOAT *)blas_memory_alloc(1);
  186. #ifdef SMP
  187. nthreads = num_cpu_avail(2);
  188. if (nthreads == 1) {
  189. #endif
  190. (gemv[(int)trans])(m, n, 0, alpha_r, alpha_i, a, lda, x, incx, y, incy, buffer);
  191. #ifdef SMP
  192. } else {
  193. (gemv_thread[(int)trans])(m, n, ALPHA, a, lda, x, incx, y, incy, buffer, nthreads);
  194. }
  195. #endif
  196. blas_memory_free(buffer);
  197. FUNCTION_PROFILE_END(4, m * n + m + n, 2 * m * n);
  198. IDEBUG_END;
  199. return;
  200. }