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.

ger.c 5.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. #define ERROR_NAME "QGER "
  50. #elif defined DOUBLE
  51. #define ERROR_NAME "DGER "
  52. #else
  53. #define ERROR_NAME "SGER "
  54. #endif
  55. #define GER GERU_K
  56. #if defined XDOUBLE
  57. #define GER_THREAD qger_thread
  58. #elif defined DOUBLE
  59. #define GER_THREAD dger_thread
  60. #else
  61. #define GER_THREAD sger_thread
  62. #endif
  63. #ifndef CBLAS
  64. void NAME(blasint *M, blasint *N, FLOAT *Alpha,
  65. FLOAT *x, blasint *INCX,
  66. FLOAT *y, blasint *INCY,
  67. FLOAT *a, blasint *LDA){
  68. blasint m = *M;
  69. blasint n = *N;
  70. FLOAT alpha = *Alpha;
  71. blasint incx = *INCX;
  72. blasint incy = *INCY;
  73. blasint lda = *LDA;
  74. FLOAT *buffer;
  75. #ifdef SMPTEST
  76. int nthreads;
  77. #endif
  78. blasint info;
  79. PRINT_DEBUG_NAME;
  80. info = 0;
  81. if (lda < MAX(1,m)) info = 9;
  82. if (incy == 0) info = 7;
  83. if (incx == 0) info = 5;
  84. if (n < 0) info = 2;
  85. if (m < 0) info = 1;
  86. if (info){
  87. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  88. return;
  89. }
  90. #else
  91. void CNAME(enum CBLAS_ORDER order,
  92. blasint m, blasint n,
  93. FLOAT alpha,
  94. FLOAT *x, blasint incx,
  95. FLOAT *y, blasint incy,
  96. FLOAT *a, blasint lda) {
  97. FLOAT *buffer;
  98. blasint info, t;
  99. #ifdef SMPTEST
  100. int nthreads;
  101. #endif
  102. PRINT_DEBUG_CNAME;
  103. info = 0;
  104. if (order == CblasColMajor) {
  105. info = -1;
  106. if (lda < MAX(1,m)) info = 9;
  107. if (incy == 0) info = 7;
  108. if (incx == 0) info = 5;
  109. if (n < 0) info = 2;
  110. if (m < 0) info = 1;
  111. }
  112. if (order == CblasRowMajor) {
  113. info = -1;
  114. t = n;
  115. n = m;
  116. m = t;
  117. t = incx;
  118. incx = incy;
  119. incy = t;
  120. buffer = x;
  121. x = y;
  122. y = buffer;
  123. if (lda < MAX(1,m)) info = 9;
  124. if (incy == 0) info = 7;
  125. if (incx == 0) info = 5;
  126. if (n < 0) info = 2;
  127. if (m < 0) info = 1;
  128. }
  129. if (info >= 0) {
  130. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  131. return;
  132. }
  133. #endif
  134. /* Quick return if possible. */
  135. if (m == 0 || n == 0) return;
  136. if (alpha == 0.) return;
  137. if (incx == 1 && incy == 1 && 1L*m*n <= 2048 *GEMM_MULTITHREAD_THRESHOLD) {
  138. GER(m, n, 0, alpha, x, incx, y, incy, a, lda, NULL);
  139. return;
  140. }
  141. IDEBUG_START;
  142. FUNCTION_PROFILE_START();
  143. if (incy < 0) y -= (n - 1) * incy;
  144. if (incx < 0) x -= (m - 1) * incx;
  145. STACK_ALLOC(m, FLOAT, buffer);
  146. #ifdef SMPTEST
  147. // Threshold chosen so that speed-up is > 1 on a Xeon E5-2630
  148. if(1L * m * n > 2048L * GEMM_MULTITHREAD_THRESHOLD)
  149. nthreads = num_cpu_avail(2);
  150. else
  151. nthreads = 1;
  152. if (nthreads == 1) {
  153. #endif
  154. GER(m, n, 0, alpha, x, incx, y, incy, a, lda, buffer);
  155. #ifdef SMPTEST
  156. } else {
  157. GER_THREAD(m, n, alpha, x, incx, y, incy, a, lda, buffer, nthreads);
  158. }
  159. #endif
  160. STACK_FREE(buffer);
  161. FUNCTION_PROFILE_END(1, m * n + m + n, 2 * m * n);
  162. IDEBUG_END;
  163. return;
  164. }