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.

ztrmv.c 8.8 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 <ctype.h>
  40. #include "common.h"
  41. #ifdef FUNCTION_PROFILE
  42. #include "functable.h"
  43. #endif
  44. #ifdef XDOUBLE
  45. #define ERROR_NAME "XTRMV "
  46. #elif defined(DOUBLE)
  47. #define ERROR_NAME "ZTRMV "
  48. #else
  49. #define ERROR_NAME "CTRMV "
  50. #endif
  51. static int (*trmv[])(BLASLONG, FLOAT *, BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
  52. #ifdef XDOUBLE
  53. xtrmv_NUU, xtrmv_NUN, xtrmv_NLU, xtrmv_NLN,
  54. xtrmv_TUU, xtrmv_TUN, xtrmv_TLU, xtrmv_TLN,
  55. xtrmv_RUU, xtrmv_RUN, xtrmv_RLU, xtrmv_RLN,
  56. xtrmv_CUU, xtrmv_CUN, xtrmv_CLU, xtrmv_CLN,
  57. #elif defined(DOUBLE)
  58. ztrmv_NUU, ztrmv_NUN, ztrmv_NLU, ztrmv_NLN,
  59. ztrmv_TUU, ztrmv_TUN, ztrmv_TLU, ztrmv_TLN,
  60. ztrmv_RUU, ztrmv_RUN, ztrmv_RLU, ztrmv_RLN,
  61. ztrmv_CUU, ztrmv_CUN, ztrmv_CLU, ztrmv_CLN,
  62. #else
  63. ctrmv_NUU, ctrmv_NUN, ctrmv_NLU, ctrmv_NLN,
  64. ctrmv_TUU, ctrmv_TUN, ctrmv_TLU, ctrmv_TLN,
  65. ctrmv_RUU, ctrmv_RUN, ctrmv_RLU, ctrmv_RLN,
  66. ctrmv_CUU, ctrmv_CUN, ctrmv_CLU, ctrmv_CLN,
  67. #endif
  68. };
  69. #ifdef SMP
  70. static int (*trmv_thread[])(BLASLONG, FLOAT *, BLASLONG, FLOAT *, BLASLONG, FLOAT *, int) = {
  71. #ifdef XDOUBLE
  72. xtrmv_thread_NUU, xtrmv_thread_NUN, xtrmv_thread_NLU, xtrmv_thread_NLN,
  73. xtrmv_thread_TUU, xtrmv_thread_TUN, xtrmv_thread_TLU, xtrmv_thread_TLN,
  74. xtrmv_thread_RUU, xtrmv_thread_RUN, xtrmv_thread_RLU, xtrmv_thread_RLN,
  75. xtrmv_thread_CUU, xtrmv_thread_CUN, xtrmv_thread_CLU, xtrmv_thread_CLN,
  76. #elif defined(DOUBLE)
  77. ztrmv_thread_NUU, ztrmv_thread_NUN, ztrmv_thread_NLU, ztrmv_thread_NLN,
  78. ztrmv_thread_TUU, ztrmv_thread_TUN, ztrmv_thread_TLU, ztrmv_thread_TLN,
  79. ztrmv_thread_RUU, ztrmv_thread_RUN, ztrmv_thread_RLU, ztrmv_thread_RLN,
  80. ztrmv_thread_CUU, ztrmv_thread_CUN, ztrmv_thread_CLU, ztrmv_thread_CLN,
  81. #else
  82. ctrmv_thread_NUU, ctrmv_thread_NUN, ctrmv_thread_NLU, ctrmv_thread_NLN,
  83. ctrmv_thread_TUU, ctrmv_thread_TUN, ctrmv_thread_TLU, ctrmv_thread_TLN,
  84. ctrmv_thread_RUU, ctrmv_thread_RUN, ctrmv_thread_RLU, ctrmv_thread_RLN,
  85. ctrmv_thread_CUU, ctrmv_thread_CUN, ctrmv_thread_CLU, ctrmv_thread_CLN,
  86. #endif
  87. };
  88. #endif
  89. #ifndef CBLAS
  90. void NAME(char *UPLO, char *TRANS, char *DIAG,
  91. blasint *N, FLOAT *a, blasint *LDA, FLOAT *x, blasint *INCX){
  92. char uplo_arg = *UPLO;
  93. char trans_arg = *TRANS;
  94. char diag_arg = *DIAG;
  95. blasint n = *N;
  96. blasint lda = *LDA;
  97. blasint incx = *INCX;
  98. blasint info;
  99. int uplo;
  100. int unit;
  101. int trans, buffer_size;
  102. FLOAT *buffer;
  103. #ifdef SMP
  104. int nthreads;
  105. #endif
  106. PRINT_DEBUG_NAME;
  107. TOUPPER(uplo_arg);
  108. TOUPPER(trans_arg);
  109. TOUPPER(diag_arg);
  110. trans = -1;
  111. unit = -1;
  112. uplo = -1;
  113. if (trans_arg == 'N') trans = 0;
  114. if (trans_arg == 'T') trans = 1;
  115. if (trans_arg == 'R') trans = 2;
  116. if (trans_arg == 'C') trans = 3;
  117. if (diag_arg == 'U') unit = 0;
  118. if (diag_arg == 'N') unit = 1;
  119. if (uplo_arg == 'U') uplo = 0;
  120. if (uplo_arg == 'L') uplo = 1;
  121. info = 0;
  122. if (incx == 0) info = 8;
  123. if (lda < MAX(1, n)) info = 6;
  124. if (n < 0) info = 4;
  125. if (unit < 0) info = 3;
  126. if (trans < 0) info = 2;
  127. if (uplo < 0) info = 1;
  128. if (info != 0) {
  129. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  130. return;
  131. }
  132. #else
  133. void CNAME(enum CBLAS_ORDER order, enum CBLAS_UPLO Uplo,
  134. enum CBLAS_TRANSPOSE TransA, enum CBLAS_DIAG Diag,
  135. blasint n, void *va, blasint lda, void *vx, blasint incx) {
  136. FLOAT *a = (FLOAT*) va;
  137. FLOAT *x = (FLOAT*) vx;
  138. int trans, uplo, unit, buffer_size;
  139. blasint info;
  140. FLOAT *buffer;
  141. #ifdef SMP
  142. int nthreads;
  143. #endif
  144. PRINT_DEBUG_CNAME;
  145. unit = -1;
  146. uplo = -1;
  147. trans = -1;
  148. info = 0;
  149. if (order == CblasColMajor) {
  150. if (Uplo == CblasUpper) uplo = 0;
  151. if (Uplo == CblasLower) uplo = 1;
  152. if (TransA == CblasNoTrans) trans = 0;
  153. if (TransA == CblasTrans) trans = 1;
  154. if (TransA == CblasConjNoTrans) trans = 2;
  155. if (TransA == CblasConjTrans) trans = 3;
  156. if (Diag == CblasUnit) unit = 0;
  157. if (Diag == CblasNonUnit) unit = 1;
  158. info = -1;
  159. if (incx == 0) info = 8;
  160. if (lda < MAX(1, n)) info = 6;
  161. if (n < 0) info = 4;
  162. if (unit < 0) info = 3;
  163. if (trans < 0) info = 2;
  164. if (uplo < 0) info = 1;
  165. }
  166. if (order == CblasRowMajor) {
  167. if (Uplo == CblasUpper) uplo = 1;
  168. if (Uplo == CblasLower) uplo = 0;
  169. if (TransA == CblasNoTrans) trans = 1;
  170. if (TransA == CblasTrans) trans = 0;
  171. if (TransA == CblasConjNoTrans) trans = 3;
  172. if (TransA == CblasConjTrans) trans = 2;
  173. if (Diag == CblasUnit) unit = 0;
  174. if (Diag == CblasNonUnit) unit = 1;
  175. info = -1;
  176. if (incx == 0) info = 8;
  177. if (lda < MAX(1, n)) info = 6;
  178. if (n < 0) info = 4;
  179. if (unit < 0) info = 3;
  180. if (trans < 0) info = 2;
  181. if (uplo < 0) info = 1;
  182. }
  183. if (info >= 0) {
  184. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  185. return;
  186. }
  187. #endif
  188. if (n == 0) return;
  189. IDEBUG_START;
  190. FUNCTION_PROFILE_START();
  191. if (incx < 0 ) x -= (n - 1) * incx * 2;
  192. #ifdef SMP
  193. // Calibrated on a Xeon E5-2630
  194. if(1L * n * n > 36L * sizeof(FLOAT) * sizeof(FLOAT) * GEMM_MULTITHREAD_THRESHOLD) {
  195. nthreads = num_cpu_avail(2);
  196. if(nthreads > 2 && 1L * n * n < 64L * sizeof(FLOAT) * sizeof(FLOAT) * GEMM_MULTITHREAD_THRESHOLD)
  197. nthreads = 2;
  198. } else
  199. nthreads = 1;
  200. if(nthreads > 1) {
  201. buffer_size = n > 16 ? 0 : n * 4 + 40;
  202. }
  203. else
  204. #endif
  205. {
  206. buffer_size = ((n - 1) / DTB_ENTRIES) * 2 * DTB_ENTRIES + 32 / sizeof(FLOAT);
  207. // It seems to be required for some K8 or Barcelona CPU
  208. buffer_size += 8;
  209. if(incx != 1)
  210. buffer_size += n * 2;
  211. }
  212. STACK_ALLOC(buffer_size, FLOAT, buffer);
  213. #ifdef SMP
  214. if (nthreads == 1) {
  215. #endif
  216. (trmv[(trans<<2) | (uplo<<1) | unit])(n, a, lda, x, incx, buffer);
  217. #ifdef SMP
  218. } else {
  219. (trmv_thread[(trans<<2) | (uplo<<1) | unit])(n, a, lda, x, incx, buffer, nthreads);
  220. }
  221. #endif
  222. STACK_FREE(buffer);
  223. FUNCTION_PROFILE_END(4, n * n / 2 + n, n * n);
  224. IDEBUG_END;
  225. return;
  226. }