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.

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