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_kernel.c 6.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. #ifndef CONJA
  41. #ifndef CONJB
  42. #define GEMM_KERNEL GEMM_KERNEL_N
  43. #else
  44. #define GEMM_KERNEL GEMM_KERNEL_R
  45. #endif
  46. #else
  47. #ifndef CONJB
  48. #define GEMM_KERNEL GEMM_KERNEL_L
  49. #else
  50. #define GEMM_KERNEL GEMM_KERNEL_B
  51. #endif
  52. #endif
  53. int CNAME(BLASLONG m, BLASLONG n, BLASLONG k, FLOAT alpha_r,
  54. #ifdef COMPLEX
  55. FLOAT alpha_i,
  56. #endif
  57. FLOAT *a, FLOAT *b, FLOAT *c, BLASLONG ldc, BLASLONG offset){
  58. BLASLONG i, j;
  59. BLASLONG loop;
  60. FLOAT *cc, *ss;
  61. FLOAT subbuffer[GEMM_UNROLL_MN * (GEMM_UNROLL_MN + 1) * COMPSIZE];
  62. if (m + offset < 0) {
  63. #ifndef LOWER
  64. GEMM_KERNEL(m, n, k,
  65. alpha_r,
  66. #ifdef COMPLEX
  67. alpha_i,
  68. #endif
  69. a, b, c, ldc);
  70. #endif
  71. return 0;
  72. }
  73. if (n < offset) {
  74. #ifdef LOWER
  75. GEMM_KERNEL(m, n, k,
  76. alpha_r,
  77. #ifdef COMPLEX
  78. alpha_i,
  79. #endif
  80. a, b, c, ldc);
  81. #endif
  82. return 0;
  83. }
  84. if (offset > 0) {
  85. #ifdef LOWER
  86. GEMM_KERNEL(m, offset, k,
  87. alpha_r,
  88. #ifdef COMPLEX
  89. alpha_i,
  90. #endif
  91. a, b, c, ldc);
  92. #endif
  93. b += offset * k * COMPSIZE;
  94. c += offset * ldc * COMPSIZE;
  95. n -= offset;
  96. offset = 0;
  97. if (n <= 0) return 0;
  98. }
  99. if (n > m + offset) {
  100. #ifndef LOWER
  101. GEMM_KERNEL(m, n - m - offset, k,
  102. alpha_r,
  103. #ifdef COMPLEX
  104. alpha_i,
  105. #endif
  106. a,
  107. b + (m + offset) * k * COMPSIZE,
  108. c + (m + offset) * ldc * COMPSIZE, ldc);
  109. #endif
  110. n = m + offset;
  111. if (n <= 0) return 0;
  112. }
  113. if (offset < 0) {
  114. #ifndef LOWER
  115. GEMM_KERNEL(-offset, n, k,
  116. alpha_r,
  117. #ifdef COMPLEX
  118. alpha_i,
  119. #endif
  120. a, b, c, ldc);
  121. #endif
  122. a -= offset * k * COMPSIZE;
  123. c -= offset * COMPSIZE;
  124. m += offset;
  125. offset = 0;
  126. if (m <= 0) return 0;
  127. }
  128. if (m > n - offset) {
  129. #ifdef LOWER
  130. GEMM_KERNEL(m - n + offset, n, k,
  131. alpha_r,
  132. #ifdef COMPLEX
  133. alpha_i,
  134. #endif
  135. a + (n - offset) * k * COMPSIZE,
  136. b,
  137. c + (n - offset) * COMPSIZE, ldc);
  138. #endif
  139. m = n + offset;
  140. if (m <= 0) return 0;
  141. }
  142. for (loop = 0; loop < n; loop += GEMM_UNROLL_MN) {
  143. int mm, nn;
  144. mm = (loop & ~(GEMM_UNROLL_MN - 1));
  145. nn = MIN(GEMM_UNROLL_MN, n - loop);
  146. #ifndef LOWER
  147. GEMM_KERNEL(mm, nn, k,
  148. alpha_r,
  149. #ifdef COMPLEX
  150. alpha_i,
  151. #endif
  152. a, b + loop * k * COMPSIZE, c + loop * ldc * COMPSIZE, ldc);
  153. #endif
  154. GEMM_BETA(nn, nn, 0, ZERO,
  155. #ifdef COMPLEX
  156. ZERO,
  157. #endif
  158. NULL, 0, NULL, 0, subbuffer, nn);
  159. GEMM_KERNEL(nn, nn, k,
  160. alpha_r,
  161. #ifdef COMPLEX
  162. alpha_i,
  163. #endif
  164. a + loop * k * COMPSIZE, b + loop * k * COMPSIZE, subbuffer, nn);
  165. cc = c + (loop + loop * ldc) * COMPSIZE;
  166. ss = subbuffer;
  167. #ifndef LOWER
  168. for (j = 0; j < nn; j ++) {
  169. for (i = 0; i <= j; i ++) {
  170. #ifndef COMPLEX
  171. cc[i] += ss[i];
  172. #else
  173. cc[i * 2 + 0] += ss[i * 2 + 0];
  174. cc[i * 2 + 1] += ss[i * 2 + 1];
  175. #endif
  176. }
  177. ss += nn * COMPSIZE;
  178. cc += ldc * COMPSIZE;
  179. }
  180. #else
  181. for (j = 0; j < nn; j ++) {
  182. for (i = j; i < nn; i ++) {
  183. #ifndef COMPLEX
  184. cc[i] += ss[i];
  185. #else
  186. cc[i * 2 + 0] += ss[i * 2 + 0];
  187. cc[i * 2 + 1] += ss[i * 2 + 1];
  188. #endif
  189. }
  190. ss += nn * COMPSIZE;
  191. cc += ldc * COMPSIZE;
  192. }
  193. #endif
  194. #ifdef LOWER
  195. GEMM_KERNEL(m - mm - nn, nn, k,
  196. alpha_r,
  197. #ifdef COMPLEX
  198. alpha_i,
  199. #endif
  200. a + (mm + nn) * k * COMPSIZE, b + loop * k * COMPSIZE,
  201. c + (mm + nn + loop * ldc) * COMPSIZE, ldc);
  202. #endif
  203. }
  204. return 0;
  205. }