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.

zger.c 6.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 "common.h"
  40. #ifdef FUNCTION_PROFILE
  41. #include "functable.h"
  42. #endif
  43. #ifdef SMP
  44. #ifdef __64BIT__
  45. #define SMPTEST 1
  46. #endif
  47. #endif
  48. #ifdef XDOUBLE
  49. #ifndef CONJ
  50. #define ERROR_NAME "XGERU "
  51. #else
  52. #define ERROR_NAME "XGERC "
  53. #endif
  54. #elif defined DOUBLE
  55. #ifndef CONJ
  56. #define ERROR_NAME "ZGERU "
  57. #else
  58. #define ERROR_NAME "ZGERC "
  59. #endif
  60. #else
  61. #ifndef CONJ
  62. #define ERROR_NAME "CGERU "
  63. #else
  64. #define ERROR_NAME "CGERC "
  65. #endif
  66. #endif
  67. #if defined XDOUBLE
  68. #ifndef CONJ
  69. #define GER GERU_K
  70. #define GER_THREAD xger_thread_U
  71. #else
  72. #define GER GERC_K
  73. #define GER_THREAD xger_thread_C
  74. #define GERV GERV_K
  75. #define GERV_THREAD xger_thread_V
  76. #endif
  77. #elif defined DOUBLE
  78. #ifndef CONJ
  79. #define GER GERU_K
  80. #define GER_THREAD zger_thread_U
  81. #else
  82. #define GER GERC_K
  83. #define GER_THREAD zger_thread_C
  84. #define GERV GERV_K
  85. #define GERV_THREAD zger_thread_V
  86. #endif
  87. #else
  88. #ifndef CONJ
  89. #define GER GERU_K
  90. #define GER_THREAD cger_thread_U
  91. #else
  92. #define GER GERC_K
  93. #define GER_THREAD cger_thread_C
  94. #define GERV GERV_K
  95. #define GERV_THREAD cger_thread_V
  96. #endif
  97. #endif
  98. #ifndef CBLAS
  99. void NAME(blasint *M, blasint *N, FLOAT *Alpha,
  100. FLOAT *x, blasint *INCX,
  101. FLOAT *y, blasint *INCY,
  102. FLOAT *a, blasint *LDA){
  103. blasint m = *M;
  104. blasint n = *N;
  105. FLOAT alpha_r = Alpha[0];
  106. FLOAT alpha_i = Alpha[1];
  107. blasint incx = *INCX;
  108. blasint incy = *INCY;
  109. blasint lda = *LDA;
  110. FLOAT *buffer;
  111. #ifdef SMPTEST
  112. int nthreads;
  113. #endif
  114. blasint info;
  115. PRINT_DEBUG_NAME;
  116. info = 0;
  117. if (lda < MAX(1,m)) info = 9;
  118. if (incy == 0) info = 7;
  119. if (incx == 0) info = 5;
  120. if (n < 0) info = 2;
  121. if (m < 0) info = 1;
  122. if (info){
  123. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  124. return;
  125. }
  126. #else
  127. void CNAME(enum CBLAS_ORDER order,
  128. blasint m, blasint n,
  129. FLOAT *Alpha,
  130. FLOAT *x, blasint incx,
  131. FLOAT *y, blasint incy,
  132. FLOAT *a, blasint lda) {
  133. FLOAT alpha_r = Alpha[0];
  134. FLOAT alpha_i = Alpha[1];
  135. FLOAT *buffer;
  136. blasint info, t;
  137. #ifdef SMPTEST
  138. int nthreads;
  139. #endif
  140. PRINT_DEBUG_CNAME;
  141. info = 0;
  142. if (order == CblasColMajor) {
  143. info = -1;
  144. if (lda < MAX(1,m)) info = 9;
  145. if (incy == 0) info = 7;
  146. if (incx == 0) info = 5;
  147. if (n < 0) info = 2;
  148. if (m < 0) info = 1;
  149. }
  150. if (order == CblasRowMajor) {
  151. info = -1;
  152. t = n;
  153. n = m;
  154. m = t;
  155. t = incx;
  156. incx = incy;
  157. incy = t;
  158. buffer = x;
  159. x = y;
  160. y = buffer;
  161. if (lda < MAX(1,m)) info = 9;
  162. if (incy == 0) info = 7;
  163. if (incx == 0) info = 5;
  164. if (n < 0) info = 2;
  165. if (m < 0) info = 1;
  166. }
  167. if (info >= 0) {
  168. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  169. return;
  170. }
  171. #endif
  172. /* Quick return if possible. */
  173. if (m == 0 || n == 0) return;
  174. if ((alpha_r == 0.) && (alpha_i == 0.)) return;
  175. IDEBUG_START;
  176. FUNCTION_PROFILE_START();
  177. if (incy < 0) y -= (n - 1) * incy * 2;
  178. if (incx < 0) x -= (m - 1) * incx * 2;
  179. STACK_ALLOC(2 * m, FLOAT, buffer);
  180. #ifdef SMPTEST
  181. // Threshold chosen so that speed-up is > 1 on a Xeon E5-2630
  182. if(1L * m * n > 36L * sizeof(FLOAT) * sizeof(FLOAT) * GEMM_MULTITHREAD_THRESHOLD)
  183. nthreads = num_cpu_avail(2);
  184. else
  185. nthreads = 1;
  186. if (nthreads == 1) {
  187. #endif
  188. #if !defined(CBLAS) || !defined(CONJ)
  189. GER(m, n, 0, alpha_r, alpha_i, x, incx, y, incy, a, lda, buffer);
  190. #else
  191. if (order == CblasColMajor) {
  192. GER(m, n, 0, alpha_r, alpha_i, x, incx, y, incy, a, lda, buffer);
  193. } else {
  194. GERV(m, n, 0, alpha_r, alpha_i, x, incx, y, incy, a, lda, buffer);
  195. }
  196. #endif
  197. #ifdef SMPTEST
  198. } else {
  199. #if !defined(CBLAS) || !defined(CONJ)
  200. GER_THREAD(m, n, Alpha, x, incx, y, incy, a, lda, buffer, nthreads);
  201. #else
  202. if (order == CblasColMajor) {
  203. GER_THREAD(m, n, Alpha, x, incx, y, incy, a, lda, buffer, nthreads);
  204. } else {
  205. GERV_THREAD(m, n, Alpha, x, incx, y, incy, a, lda, buffer, nthreads);
  206. }
  207. #endif
  208. }
  209. #endif
  210. STACK_FREE(buffer);
  211. FUNCTION_PROFILE_END(4, m * n + m + n, 2 * m * n);
  212. IDEBUG_END;
  213. return;
  214. }