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.

trsm_kernel_LN_sve.c 8.5 kB

3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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 "common.h"
  39. #include "arm_sve.h"
  40. static FLOAT dm1 = -1.;
  41. #ifdef CONJ
  42. #define GEMM_KERNEL GEMM_KERNEL_L
  43. #else
  44. #define GEMM_KERNEL GEMM_KERNEL_N
  45. #endif
  46. #if GEMM_DEFAULT_UNROLL_N == 1
  47. #define GEMM_UNROLL_N_SHIFT 0
  48. #endif
  49. #if GEMM_DEFAULT_UNROLL_N == 2
  50. #define GEMM_UNROLL_N_SHIFT 1
  51. #endif
  52. #if GEMM_DEFAULT_UNROLL_N == 4
  53. #define GEMM_UNROLL_N_SHIFT 2
  54. #endif
  55. #if GEMM_DEFAULT_UNROLL_N == 8
  56. #define GEMM_UNROLL_N_SHIFT 3
  57. #endif
  58. #if GEMM_DEFAULT_UNROLL_N == 16
  59. #define GEMM_UNROLL_N_SHIFT 4
  60. #endif
  61. #ifndef COMPLEX
  62. static inline void solve(BLASLONG m, BLASLONG n, FLOAT *a, FLOAT *b, FLOAT *c, BLASLONG ldc) {
  63. FLOAT aa, bb;
  64. int i, j, k;
  65. a += (m - 1) * m;
  66. b += (m - 1) * n;
  67. for (i = m - 1; i >= 0; i--) {
  68. aa = *(a + i);
  69. for (j = 0; j < n; j ++) {
  70. bb = *(c + i + j * ldc);
  71. bb *= aa;
  72. *b = bb;
  73. *(c + i + j * ldc) = bb;
  74. b ++;
  75. for (k = 0; k < i; k ++){
  76. *(c + k + j * ldc) -= bb * *(a + k);
  77. }
  78. }
  79. a -= m;
  80. b -= 2 * n;
  81. }
  82. }
  83. #else
  84. static inline void solve(BLASLONG m, BLASLONG n, FLOAT *a, FLOAT *b, FLOAT *c, BLASLONG ldc) {
  85. FLOAT aa1, aa2;
  86. FLOAT bb1, bb2;
  87. FLOAT cc1, cc2;
  88. int i, j, k;
  89. ldc *= 2;
  90. a += (m - 1) * m * 2;
  91. b += (m - 1) * n * 2;
  92. for (i = m - 1; i >= 0; i--) {
  93. aa1 = *(a + i * 2 + 0);
  94. aa2 = *(a + i * 2 + 1);
  95. for (j = 0; j < n; j ++) {
  96. bb1 = *(c + i * 2 + 0 + j * ldc);
  97. bb2 = *(c + i * 2 + 1 + j * ldc);
  98. #ifndef CONJ
  99. cc1 = aa1 * bb1 - aa2 * bb2;
  100. cc2 = aa1 * bb2 + aa2 * bb1;
  101. #else
  102. cc1 = aa1 * bb1 + aa2 * bb2;
  103. cc2 = aa1 * bb2 - aa2 * bb1;
  104. #endif
  105. *(b + 0) = cc1;
  106. *(b + 1) = cc2;
  107. *(c + i * 2 + 0 + j * ldc) = cc1;
  108. *(c + i * 2 + 1 + j * ldc) = cc2;
  109. b += 2;
  110. for (k = 0; k < i; k ++){
  111. #ifndef CONJ
  112. *(c + k * 2 + 0 + j * ldc) -= cc1 * *(a + k * 2 + 0) - cc2 * *(a + k * 2 + 1);
  113. *(c + k * 2 + 1 + j * ldc) -= cc1 * *(a + k * 2 + 1) + cc2 * *(a + k * 2 + 0);
  114. #else
  115. *(c + k * 2 + 0 + j * ldc) -= cc1 * *(a + k * 2 + 0) + cc2 * *(a + k * 2 + 1);
  116. *(c + k * 2 + 1 + j * ldc) -= - cc1 * *(a + k * 2 + 1) + cc2 * *(a + k * 2 + 0);
  117. #endif
  118. }
  119. }
  120. a -= m * 2;
  121. b -= 4 * n;
  122. }
  123. }
  124. #endif
  125. int CNAME(BLASLONG m, BLASLONG n, BLASLONG k, FLOAT dummy1,
  126. #ifdef COMPLEX
  127. FLOAT dummy2,
  128. #endif
  129. FLOAT *a, FLOAT *b, FLOAT *c, BLASLONG ldc, BLASLONG offset){
  130. BLASLONG i, j;
  131. FLOAT *aa, *cc;
  132. BLASLONG kk;
  133. #ifdef DOUBLE
  134. int sve_size = svcntd();
  135. #else
  136. int sve_size = svcntw();
  137. #endif
  138. #if 0
  139. fprintf(stderr, "TRSM KERNEL LN : m = %3ld n = %3ld k = %3ld offset = %3ld\n",
  140. m, n, k, offset);
  141. #endif
  142. j = (n >> GEMM_UNROLL_N_SHIFT);
  143. while (j > 0) {
  144. kk = m + offset;
  145. i = m % sve_size;
  146. if (i) {
  147. aa = a + (m - i) * k * COMPSIZE;
  148. cc = c + (m - i) * COMPSIZE;
  149. if (k - kk > 0) {
  150. GEMM_KERNEL(i, GEMM_UNROLL_N, k - kk, dm1,
  151. #ifdef COMPLEX
  152. ZERO,
  153. #endif
  154. aa + i * kk * COMPSIZE,
  155. b + GEMM_UNROLL_N * kk * COMPSIZE,
  156. cc,
  157. ldc);
  158. }
  159. solve(i, GEMM_UNROLL_N,
  160. aa + (kk - i) * i * COMPSIZE,
  161. b + (kk - i) * GEMM_UNROLL_N * COMPSIZE,
  162. cc, ldc);
  163. kk -= i;
  164. }
  165. int mod = i;
  166. i = sve_size;
  167. if (i <= m) {
  168. aa = a + (m - mod - sve_size) * k * COMPSIZE;
  169. cc = c + (m - mod - sve_size) * COMPSIZE;
  170. do {
  171. if (k - kk > 0) {
  172. GEMM_KERNEL(sve_size, GEMM_UNROLL_N, k - kk, dm1,
  173. #ifdef COMPLEX
  174. ZERO,
  175. #endif
  176. aa + sve_size * kk * COMPSIZE,
  177. b + GEMM_UNROLL_N * kk * COMPSIZE,
  178. cc,
  179. ldc);
  180. }
  181. solve(sve_size, GEMM_UNROLL_N,
  182. aa + (kk - sve_size) * sve_size * COMPSIZE,
  183. b + (kk - sve_size) * GEMM_UNROLL_N * COMPSIZE,
  184. cc, ldc);
  185. aa -= sve_size * k * COMPSIZE;
  186. cc -= sve_size * COMPSIZE;
  187. kk -= sve_size;
  188. i += sve_size;
  189. } while (i <= m);
  190. }
  191. b += GEMM_UNROLL_N * k * COMPSIZE;
  192. c += GEMM_UNROLL_N * ldc * COMPSIZE;
  193. j --;
  194. }
  195. if (n & (GEMM_UNROLL_N - 1)) {
  196. j = (GEMM_UNROLL_N >> 1);
  197. while (j > 0) {
  198. if (n & j) {
  199. kk = m + offset;
  200. i = m % sve_size;
  201. if (i) {
  202. aa = a + (m - i) * k * COMPSIZE;
  203. cc = c + (m - i) * COMPSIZE;
  204. if (k - kk > 0) {
  205. GEMM_KERNEL(i, j, k - kk, dm1,
  206. #ifdef COMPLEX
  207. ZERO,
  208. #endif
  209. aa + i * kk * COMPSIZE,
  210. b + j * kk * COMPSIZE,
  211. cc, ldc);
  212. }
  213. solve(i, j,
  214. aa + (kk - i) * i * COMPSIZE,
  215. b + (kk - i) * j * COMPSIZE,
  216. cc, ldc);
  217. kk -= i;
  218. }
  219. int mod = i;
  220. i = sve_size;
  221. if (i <= m) {
  222. aa = a + (m - mod - sve_size) * k * COMPSIZE;
  223. cc = c + (m - mod - sve_size) * COMPSIZE;
  224. do {
  225. if (k - kk > 0) {
  226. GEMM_KERNEL(sve_size, j, k - kk, dm1,
  227. #ifdef COMPLEX
  228. ZERO,
  229. #endif
  230. aa + sve_size * kk * COMPSIZE,
  231. b + j * kk * COMPSIZE,
  232. cc,
  233. ldc);
  234. }
  235. solve(sve_size, j,
  236. aa + (kk - sve_size) * sve_size * COMPSIZE,
  237. b + (kk - sve_size) * j * COMPSIZE,
  238. cc, ldc);
  239. aa -= sve_size * k * COMPSIZE;
  240. cc -= sve_size * COMPSIZE;
  241. kk -= sve_size;
  242. i += sve_size;
  243. } while (i <= m);
  244. }
  245. b += j * k * COMPSIZE;
  246. c += j * ldc * COMPSIZE;
  247. }
  248. j >>= 1;
  249. }
  250. }
  251. return 0;
  252. }