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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. #ifdef USE_SIMPLE_THREADED_LEVEL3
  96. #ifndef COMPLEX
  97. #ifdef XDOUBLE
  98. int mode = BLAS_XDOUBLE | BLAS_REAL;
  99. #elif defined(DOUBLE)
  100. int mode = BLAS_DOUBLE | BLAS_REAL;
  101. #else
  102. int mode = BLAS_SINGLE | BLAS_REAL;
  103. #endif
  104. #else
  105. #ifdef XDOUBLE
  106. int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  107. #elif defined(DOUBLE)
  108. int mode = BLAS_DOUBLE | BLAS_COMPLEX;
  109. #else
  110. int mode = BLAS_SINGLE | BLAS_COMPLEX;
  111. #endif
  112. #endif
  113. #endif
  114. #endif
  115. blasint info;
  116. int uplo;
  117. int trans;
  118. int nrowa;
  119. PRINT_DEBUG_NAME;
  120. args.n = *N;
  121. args.k = *K;
  122. args.a = (void *)a;
  123. args.c = (void *)c;
  124. args.lda = *ldA;
  125. args.ldc = *ldC;
  126. args.alpha = (void *)alpha;
  127. args.beta = (void *)beta;
  128. TOUPPER(uplo_arg);
  129. TOUPPER(trans_arg);
  130. uplo = -1;
  131. trans = -1;
  132. if (uplo_arg == 'U') uplo = 0;
  133. if (uplo_arg == 'L') uplo = 1;
  134. #ifndef COMPLEX
  135. if (trans_arg == 'N') trans = 0;
  136. if (trans_arg == 'T') trans = 1;
  137. if (trans_arg == 'C') trans = 1;
  138. #else
  139. #ifdef HEMM
  140. if (trans_arg == 'N') trans = 0;
  141. if (trans_arg == 'C') trans = 1;
  142. #else
  143. if (trans_arg == 'N') trans = 0;
  144. if (trans_arg == 'T') trans = 1;
  145. #endif
  146. #endif
  147. nrowa = args.n;
  148. if (trans & 1) nrowa = args.k;
  149. info = 0;
  150. if (args.ldc < MAX(1,args.n)) info = 10;
  151. if (args.lda < MAX(1,nrowa)) info = 7;
  152. if (args.k < 0) info = 4;
  153. if (args.n < 0) info = 3;
  154. if (trans < 0) info = 2;
  155. if (uplo < 0) info = 1;
  156. if (info != 0) {
  157. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  158. return;
  159. }
  160. #else
  161. void CNAME(enum CBLAS_ORDER order, enum CBLAS_UPLO Uplo, enum CBLAS_TRANSPOSE Trans,
  162. blasint n, blasint k,
  163. #if !defined(COMPLEX) || defined(HEMM)
  164. FLOAT alpha,
  165. #else
  166. void *valpha,
  167. #endif
  168. #if !defined(COMPLEX)
  169. FLOAT *a, blasint lda,
  170. #else
  171. void *va, blasint lda,
  172. #endif
  173. #if !defined(COMPLEX) || defined(HEMM)
  174. FLOAT beta,
  175. #else
  176. void *vbeta,
  177. #endif
  178. #if !defined(COMPLEX)
  179. FLOAT *c, blasint ldc) {
  180. #else
  181. void *vc, blasint ldc) {
  182. #endif
  183. #ifdef COMPLEX
  184. #if !defined(HEMM)
  185. FLOAT* alpha = (FLOAT*) valpha;
  186. FLOAT* beta = (FLOAT*) vbeta;
  187. #endif
  188. FLOAT* a = (FLOAT*) va;
  189. FLOAT* c = (FLOAT*) vc;
  190. #endif
  191. blas_arg_t args;
  192. int uplo, trans;
  193. blasint info, nrowa;
  194. FLOAT *buffer;
  195. FLOAT *sa, *sb;
  196. #ifdef SMP
  197. #ifdef USE_SIMPLE_THREADED_LEVEL3
  198. #ifndef COMPLEX
  199. #ifdef XDOUBLE
  200. int mode = BLAS_XDOUBLE | BLAS_REAL;
  201. #elif defined(DOUBLE)
  202. int mode = BLAS_DOUBLE | BLAS_REAL;
  203. #else
  204. int mode = BLAS_SINGLE | BLAS_REAL;
  205. #endif
  206. #else
  207. #ifdef XDOUBLE
  208. int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  209. #elif defined(DOUBLE)
  210. int mode = BLAS_DOUBLE | BLAS_COMPLEX;
  211. #else
  212. int mode = BLAS_SINGLE | BLAS_COMPLEX;
  213. #endif
  214. #endif
  215. #endif
  216. #endif
  217. PRINT_DEBUG_CNAME;
  218. args.n = n;
  219. args.k = k;
  220. args.a = (void *)a;
  221. args.c = (void *)c;
  222. args.lda = lda;
  223. args.ldc = ldc;
  224. #if !defined(COMPLEX) || defined(HEMM)
  225. args.alpha = (void *)&alpha;
  226. args.beta = (void *)&beta;
  227. #else
  228. args.alpha = (void *)alpha;
  229. args.beta = (void *)beta;
  230. #endif
  231. trans = -1;
  232. uplo = -1;
  233. info = 0;
  234. if (order == CblasColMajor) {
  235. if (Uplo == CblasUpper) uplo = 0;
  236. if (Uplo == CblasLower) uplo = 1;
  237. if (Trans == CblasNoTrans) trans = 0;
  238. #ifndef COMPLEX
  239. if (Trans == CblasTrans) trans = 1;
  240. if (Trans == CblasConjNoTrans) trans = 0;
  241. if (Trans == CblasConjTrans) trans = 1;
  242. #elif !defined(HEMM)
  243. if (Trans == CblasTrans) trans = 1;
  244. #else
  245. if (Trans == CblasConjTrans) trans = 1;
  246. #endif
  247. info = -1;
  248. nrowa = args.n;
  249. if (trans & 1) nrowa = args.k;
  250. if (args.ldc < MAX(1,args.n)) info = 10;
  251. if (args.lda < MAX(1,nrowa)) info = 7;
  252. if (args.k < 0) info = 4;
  253. if (args.n < 0) info = 3;
  254. if (trans < 0) info = 2;
  255. if (uplo < 0) info = 1;
  256. }
  257. if (order == CblasRowMajor) {
  258. if (Uplo == CblasUpper) uplo = 1;
  259. if (Uplo == CblasLower) uplo = 0;
  260. if (Trans == CblasNoTrans) trans = 1;
  261. #ifndef COMPLEX
  262. if (Trans == CblasTrans) trans = 0;
  263. if (Trans == CblasConjNoTrans) trans = 1;
  264. if (Trans == CblasConjTrans) trans = 0;
  265. #elif !defined(HEMM)
  266. if (Trans == CblasTrans) trans = 0;
  267. #else
  268. if (Trans == CblasConjTrans) trans = 0;
  269. #endif
  270. info = -1;
  271. nrowa = args.n;
  272. if (trans & 1) nrowa = args.k;
  273. if (args.ldc < MAX(1,args.n)) info = 10;
  274. if (args.lda < MAX(1,nrowa)) info = 7;
  275. if (args.k < 0) info = 4;
  276. if (args.n < 0) info = 3;
  277. if (trans < 0) info = 2;
  278. if (uplo < 0) info = 1;
  279. }
  280. if (info >= 0) {
  281. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  282. return;
  283. }
  284. #endif
  285. if (args.n == 0) return;
  286. IDEBUG_START;
  287. FUNCTION_PROFILE_START();
  288. buffer = (FLOAT *)blas_memory_alloc(0);
  289. sa = (FLOAT *)((BLASLONG)buffer + GEMM_OFFSET_A);
  290. sb = (FLOAT *)(((BLASLONG)sa + ((GEMM_P * GEMM_Q * COMPSIZE * SIZE + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  291. #ifdef SMP
  292. #ifdef USE_SIMPLE_THREADED_LEVEL3
  293. if (!trans){
  294. mode |= (BLAS_TRANSA_N | BLAS_TRANSB_T);
  295. } else {
  296. mode |= (BLAS_TRANSA_T | BLAS_TRANSB_N);
  297. }
  298. mode |= (uplo << BLAS_UPLO_SHIFT);
  299. #endif
  300. args.common = NULL;
  301. args.nthreads = num_cpu_avail(3);
  302. if (args.nthreads == 1) {
  303. #endif
  304. (syrk[(uplo << 1) | trans ])(&args, NULL, NULL, sa, sb, 0);
  305. #ifdef SMP
  306. } else {
  307. #ifndef USE_SIMPLE_THREADED_LEVEL3
  308. (syrk[4 | (uplo << 1) | trans ])(&args, NULL, NULL, sa, sb, 0);
  309. #else
  310. syrk_thread(mode, &args, NULL, NULL, syrk[(uplo << 1) | trans ], sa, sb, args.nthreads);
  311. #endif
  312. }
  313. #endif
  314. blas_memory_free(buffer);
  315. FUNCTION_PROFILE_END(COMPSIZE * COMPSIZE, args.n * args.k + args.n * args.n / 2, args.n * args.n * args.k);
  316. IDEBUG_END;
  317. return;
  318. }