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 9.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. #ifndef COMPLEX
  45. #ifdef XDOUBLE
  46. #define ERROR_NAME "QSYRK "
  47. #elif defined(DOUBLE)
  48. #define ERROR_NAME "DSYRK "
  49. #else
  50. #define ERROR_NAME "SSYRK "
  51. #endif
  52. #else
  53. #ifndef HEMM
  54. #ifdef XDOUBLE
  55. #define ERROR_NAME "XSYRK "
  56. #elif defined(DOUBLE)
  57. #define ERROR_NAME "ZSYRK "
  58. #else
  59. #define ERROR_NAME "CSYRK "
  60. #endif
  61. #else
  62. #ifdef XDOUBLE
  63. #define ERROR_NAME "XHERK "
  64. #elif defined(DOUBLE)
  65. #define ERROR_NAME "ZHERK "
  66. #else
  67. #define ERROR_NAME "CHERK "
  68. #endif
  69. #endif
  70. #endif
  71. static int (*syrk[])(blas_arg_t *, BLASLONG *, BLASLONG *, FLOAT *, FLOAT *, BLASLONG) = {
  72. #ifndef HEMM
  73. SYRK_UN, SYRK_UC, SYRK_LN, SYRK_LC,
  74. #if defined(SMP) && !defined(USE_SIMPLE_THREADED_LEVEL3)
  75. SYRK_THREAD_UN, SYRK_THREAD_UC, SYRK_THREAD_LN, SYRK_THREAD_LC,
  76. #endif
  77. #else
  78. HERK_UN, HERK_UC, HERK_LN, HERK_LC,
  79. #if defined(SMP) && !defined(USE_SIMPLE_THREADED_LEVEL3)
  80. HERK_THREAD_UN, HERK_THREAD_UC, HERK_THREAD_LN, HERK_THREAD_LC,
  81. #endif
  82. #endif
  83. };
  84. #ifndef CBLAS
  85. void NAME(char *UPLO, char *TRANS,
  86. blasint *N, blasint *K,
  87. FLOAT *alpha, FLOAT *a, blasint *ldA,
  88. FLOAT *beta, FLOAT *c, blasint *ldC){
  89. char uplo_arg = *UPLO;
  90. char trans_arg = *TRANS;
  91. blas_arg_t args;
  92. FLOAT *buffer;
  93. FLOAT *sa, *sb;
  94. #ifdef SMP
  95. #ifndef COMPLEX
  96. #ifdef XDOUBLE
  97. int mode = BLAS_XDOUBLE | BLAS_REAL;
  98. #elif defined(DOUBLE)
  99. int mode = BLAS_DOUBLE | BLAS_REAL;
  100. #else
  101. int mode = BLAS_SINGLE | BLAS_REAL;
  102. #endif
  103. #else
  104. #ifdef XDOUBLE
  105. int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  106. #elif defined(DOUBLE)
  107. int mode = BLAS_DOUBLE | BLAS_COMPLEX;
  108. #else
  109. int mode = BLAS_SINGLE | BLAS_COMPLEX;
  110. #endif
  111. #endif
  112. #endif
  113. blasint info;
  114. int uplo;
  115. int trans;
  116. int nrowa;
  117. PRINT_DEBUG_NAME;
  118. args.n = *N;
  119. args.k = *K;
  120. args.a = (void *)a;
  121. args.c = (void *)c;
  122. args.lda = *ldA;
  123. args.ldc = *ldC;
  124. args.alpha = (void *)alpha;
  125. args.beta = (void *)beta;
  126. TOUPPER(uplo_arg);
  127. TOUPPER(trans_arg);
  128. uplo = -1;
  129. trans = -1;
  130. if (uplo_arg == 'U') uplo = 0;
  131. if (uplo_arg == 'L') uplo = 1;
  132. if (trans_arg == 'N') trans = 0;
  133. if (trans_arg == 'T') trans = 1;
  134. if (trans_arg == 'R') trans = 0;
  135. if (trans_arg == 'C') trans = 1;
  136. nrowa = args.n;
  137. if (trans & 1) nrowa = args.k;
  138. info = 0;
  139. if (args.ldc < MAX(1,args.n)) info = 10;
  140. if (args.lda < MAX(1,nrowa)) info = 7;
  141. if (args.k < 0) info = 4;
  142. if (args.n < 0) info = 3;
  143. if (trans < 0) info = 2;
  144. if (uplo < 0) info = 1;
  145. if (info != 0) {
  146. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  147. return;
  148. }
  149. #else
  150. void CNAME(enum CBLAS_ORDER order, enum CBLAS_UPLO Uplo, enum CBLAS_TRANSPOSE Trans,
  151. blasint n, blasint k,
  152. #if !defined(COMPLEX) || defined(HEMM)
  153. FLOAT alpha,
  154. #else
  155. FLOAT *alpha,
  156. #endif
  157. FLOAT *a, blasint lda,
  158. #if !defined(COMPLEX) || defined(HEMM)
  159. FLOAT beta,
  160. #else
  161. FLOAT *beta,
  162. #endif
  163. FLOAT *c, blasint ldc) {
  164. blas_arg_t args;
  165. int uplo, trans;
  166. blasint info, nrowa;
  167. FLOAT *buffer;
  168. FLOAT *sa, *sb;
  169. #ifdef SMP
  170. #ifndef COMPLEX
  171. #ifdef XDOUBLE
  172. int mode = BLAS_XDOUBLE | BLAS_REAL;
  173. #elif defined(DOUBLE)
  174. int mode = BLAS_DOUBLE | BLAS_REAL;
  175. #else
  176. int mode = BLAS_SINGLE | BLAS_REAL;
  177. #endif
  178. #else
  179. #ifdef XDOUBLE
  180. int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  181. #elif defined(DOUBLE)
  182. int mode = BLAS_DOUBLE | BLAS_COMPLEX;
  183. #else
  184. int mode = BLAS_SINGLE | BLAS_COMPLEX;
  185. #endif
  186. #endif
  187. #endif
  188. PRINT_DEBUG_CNAME;
  189. args.n = n;
  190. args.k = k;
  191. args.a = (void *)a;
  192. args.c = (void *)c;
  193. args.lda = lda;
  194. args.ldc = ldc;
  195. #if !defined(COMPLEX) || defined(HEMM)
  196. args.alpha = (void *)&alpha;
  197. args.beta = (void *)&beta;
  198. #else
  199. args.alpha = (void *)alpha;
  200. args.beta = (void *)beta;
  201. #endif
  202. trans = -1;
  203. uplo = -1;
  204. info = 0;
  205. if (order == CblasColMajor) {
  206. if (Uplo == CblasUpper) uplo = 0;
  207. if (Uplo == CblasLower) uplo = 1;
  208. if (Trans == CblasNoTrans) trans = 0;
  209. #ifndef COMPLEX
  210. if (Trans == CblasTrans) trans = 1;
  211. if (Trans == CblasConjNoTrans) trans = 0;
  212. if (Trans == CblasConjTrans) trans = 1;
  213. #elif !defined(HEMM)
  214. if (Trans == CblasTrans) trans = 1;
  215. #else
  216. if (Trans == CblasConjTrans) trans = 1;
  217. #endif
  218. info = -1;
  219. nrowa = args.n;
  220. if (trans & 1) nrowa = args.k;
  221. if (args.ldc < MAX(1,args.n)) info = 10;
  222. if (args.lda < MAX(1,nrowa)) info = 7;
  223. if (args.k < 0) info = 4;
  224. if (args.n < 0) info = 3;
  225. if (trans < 0) info = 2;
  226. if (uplo < 0) info = 1;
  227. }
  228. if (order == CblasRowMajor) {
  229. if (Uplo == CblasUpper) uplo = 1;
  230. if (Uplo == CblasLower) uplo = 0;
  231. if (Trans == CblasNoTrans) trans = 1;
  232. #ifndef COMPLEX
  233. if (Trans == CblasTrans) trans = 0;
  234. if (Trans == CblasConjNoTrans) trans = 1;
  235. if (Trans == CblasConjTrans) trans = 0;
  236. #elif !defined(HEMM)
  237. if (Trans == CblasTrans) trans = 0;
  238. #else
  239. if (Trans == CblasConjTrans) trans = 0;
  240. #endif
  241. info = -1;
  242. nrowa = args.n;
  243. if (trans & 1) nrowa = args.k;
  244. if (args.ldc < MAX(1,args.n)) info = 10;
  245. if (args.lda < MAX(1,nrowa)) info = 7;
  246. if (args.k < 0) info = 4;
  247. if (args.n < 0) info = 3;
  248. if (trans < 0) info = 2;
  249. if (uplo < 0) info = 1;
  250. }
  251. if (info >= 0) {
  252. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  253. return;
  254. }
  255. #endif
  256. if (args.n == 0) return;
  257. IDEBUG_START;
  258. FUNCTION_PROFILE_START();
  259. buffer = (FLOAT *)blas_memory_alloc(0);
  260. sa = (FLOAT *)((BLASLONG)buffer + GEMM_OFFSET_A);
  261. sb = (FLOAT *)(((BLASLONG)sa + ((GEMM_P * GEMM_Q * COMPSIZE * SIZE + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  262. #ifdef SMP
  263. if (!trans){
  264. mode |= (BLAS_TRANSA_N | BLAS_TRANSB_T);
  265. } else {
  266. mode |= (BLAS_TRANSA_T | BLAS_TRANSB_N);
  267. }
  268. mode |= (uplo << BLAS_UPLO_SHIFT);
  269. args.common = NULL;
  270. args.nthreads = num_cpu_avail(3);
  271. if (args.nthreads == 1) {
  272. #endif
  273. (syrk[(uplo << 1) | trans ])(&args, NULL, NULL, sa, sb, 0);
  274. #ifdef SMP
  275. } else {
  276. #ifndef USE_SIMPLE_THREADED_LEVEL3
  277. (syrk[4 | (uplo << 1) | trans ])(&args, NULL, NULL, sa, sb, 0);
  278. #else
  279. syrk_thread(mode, &args, NULL, NULL, syrk[(uplo << 1) | trans ], sa, sb, args.nthreads);
  280. #endif
  281. }
  282. #endif
  283. blas_memory_free(buffer);
  284. FUNCTION_PROFILE_END(COMPSIZE * COMPSIZE, args.n * args.k + args.n * args.n / 2, args.n * args.n * args.k);
  285. IDEBUG_END;
  286. return;
  287. }