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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. #ifndef COMPLEX
  133. if (trans_arg == 'N') trans = 0;
  134. if (trans_arg == 'T') trans = 1;
  135. if (trans_arg == 'C') trans = 1;
  136. #else
  137. #ifdef HEMM
  138. if (trans_arg == 'N') trans = 0;
  139. if (trans_arg == 'C') trans = 1;
  140. #else
  141. if (trans_arg == 'N') trans = 0;
  142. if (trans_arg == 'T') trans = 1;
  143. #endif
  144. #endif
  145. nrowa = args.n;
  146. if (trans & 1) nrowa = args.k;
  147. info = 0;
  148. if (args.ldc < MAX(1,args.n)) info = 10;
  149. if (args.lda < MAX(1,nrowa)) info = 7;
  150. if (args.k < 0) info = 4;
  151. if (args.n < 0) info = 3;
  152. if (trans < 0) info = 2;
  153. if (uplo < 0) info = 1;
  154. if (info != 0) {
  155. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  156. return;
  157. }
  158. #else
  159. void CNAME(enum CBLAS_ORDER order, enum CBLAS_UPLO Uplo, enum CBLAS_TRANSPOSE Trans,
  160. blasint n, blasint k,
  161. #if !defined(COMPLEX) || defined(HEMM)
  162. FLOAT alpha,
  163. #else
  164. FLOAT *alpha,
  165. #endif
  166. FLOAT *a, blasint lda,
  167. #if !defined(COMPLEX) || defined(HEMM)
  168. FLOAT beta,
  169. #else
  170. FLOAT *beta,
  171. #endif
  172. FLOAT *c, blasint ldc) {
  173. blas_arg_t args;
  174. int uplo, trans;
  175. blasint info, nrowa;
  176. FLOAT *buffer;
  177. FLOAT *sa, *sb;
  178. #ifdef SMP
  179. #ifndef COMPLEX
  180. #ifdef XDOUBLE
  181. int mode = BLAS_XDOUBLE | BLAS_REAL;
  182. #elif defined(DOUBLE)
  183. int mode = BLAS_DOUBLE | BLAS_REAL;
  184. #else
  185. int mode = BLAS_SINGLE | BLAS_REAL;
  186. #endif
  187. #else
  188. #ifdef XDOUBLE
  189. int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  190. #elif defined(DOUBLE)
  191. int mode = BLAS_DOUBLE | BLAS_COMPLEX;
  192. #else
  193. int mode = BLAS_SINGLE | BLAS_COMPLEX;
  194. #endif
  195. #endif
  196. #endif
  197. PRINT_DEBUG_CNAME;
  198. args.n = n;
  199. args.k = k;
  200. args.a = (void *)a;
  201. args.c = (void *)c;
  202. args.lda = lda;
  203. args.ldc = ldc;
  204. #if !defined(COMPLEX) || defined(HEMM)
  205. args.alpha = (void *)&alpha;
  206. args.beta = (void *)&beta;
  207. #else
  208. args.alpha = (void *)alpha;
  209. args.beta = (void *)beta;
  210. #endif
  211. trans = -1;
  212. uplo = -1;
  213. info = 0;
  214. if (order == CblasColMajor) {
  215. if (Uplo == CblasUpper) uplo = 0;
  216. if (Uplo == CblasLower) uplo = 1;
  217. if (Trans == CblasNoTrans) trans = 0;
  218. #ifndef COMPLEX
  219. if (Trans == CblasTrans) trans = 1;
  220. if (Trans == CblasConjNoTrans) trans = 0;
  221. if (Trans == CblasConjTrans) trans = 1;
  222. #elif !defined(HEMM)
  223. if (Trans == CblasTrans) trans = 1;
  224. #else
  225. if (Trans == CblasConjTrans) trans = 1;
  226. #endif
  227. info = -1;
  228. nrowa = args.n;
  229. if (trans & 1) nrowa = args.k;
  230. if (args.ldc < MAX(1,args.n)) info = 10;
  231. if (args.lda < MAX(1,nrowa)) info = 7;
  232. if (args.k < 0) info = 4;
  233. if (args.n < 0) info = 3;
  234. if (trans < 0) info = 2;
  235. if (uplo < 0) info = 1;
  236. }
  237. if (order == CblasRowMajor) {
  238. if (Uplo == CblasUpper) uplo = 1;
  239. if (Uplo == CblasLower) uplo = 0;
  240. if (Trans == CblasNoTrans) trans = 1;
  241. #ifndef COMPLEX
  242. if (Trans == CblasTrans) trans = 0;
  243. if (Trans == CblasConjNoTrans) trans = 1;
  244. if (Trans == CblasConjTrans) trans = 0;
  245. #elif !defined(HEMM)
  246. if (Trans == CblasTrans) trans = 0;
  247. #else
  248. if (Trans == CblasConjTrans) trans = 0;
  249. #endif
  250. info = -1;
  251. nrowa = args.n;
  252. if (trans & 1) nrowa = args.k;
  253. if (args.ldc < MAX(1,args.n)) info = 10;
  254. if (args.lda < MAX(1,nrowa)) info = 7;
  255. if (args.k < 0) info = 4;
  256. if (args.n < 0) info = 3;
  257. if (trans < 0) info = 2;
  258. if (uplo < 0) info = 1;
  259. }
  260. if (info >= 0) {
  261. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  262. return;
  263. }
  264. #endif
  265. if (args.n == 0) return;
  266. IDEBUG_START;
  267. FUNCTION_PROFILE_START();
  268. buffer = (FLOAT *)blas_memory_alloc(0);
  269. sa = (FLOAT *)((BLASLONG)buffer + GEMM_OFFSET_A);
  270. sb = (FLOAT *)(((BLASLONG)sa + ((GEMM_P * GEMM_Q * COMPSIZE * SIZE + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  271. #ifdef SMP
  272. if (!trans){
  273. mode |= (BLAS_TRANSA_N | BLAS_TRANSB_T);
  274. } else {
  275. mode |= (BLAS_TRANSA_T | BLAS_TRANSB_N);
  276. }
  277. mode |= (uplo << BLAS_UPLO_SHIFT);
  278. args.common = NULL;
  279. args.nthreads = num_cpu_avail(3);
  280. if (args.nthreads == 1) {
  281. #endif
  282. (syrk[(uplo << 1) | trans ])(&args, NULL, NULL, sa, sb, 0);
  283. #ifdef SMP
  284. } else {
  285. #ifndef USE_SIMPLE_THREADED_LEVEL3
  286. (syrk[4 | (uplo << 1) | trans ])(&args, NULL, NULL, sa, sb, 0);
  287. #else
  288. syrk_thread(mode, &args, NULL, NULL, syrk[(uplo << 1) | trans ], sa, sb, args.nthreads);
  289. #endif
  290. }
  291. #endif
  292. blas_memory_free(buffer);
  293. FUNCTION_PROFILE_END(COMPSIZE * COMPSIZE, args.n * args.k + args.n * args.n / 2, args.n * args.n * args.k);
  294. IDEBUG_END;
  295. return;
  296. }