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

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