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.

zher2k_kernel.c 6.2 kB

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