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_RT_sve.c 8.0 kB

3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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_R
  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 += (n - 1) * m;
  66. b += (n - 1) * n;
  67. for (i = n - 1; i >= 0; i--) {
  68. bb = *(b + i);
  69. for (j = 0; j < m; j ++) {
  70. aa = *(c + j + i * ldc);
  71. aa *= bb;
  72. *a = aa;
  73. *(c + j + i * ldc) = aa;
  74. a ++;
  75. for (k = 0; k < i; k ++){
  76. *(c + j + k * ldc) -= aa * *(b + k);
  77. }
  78. }
  79. b -= n;
  80. a -= 2 * m;
  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 += (n - 1) * m * 2;
  91. b += (n - 1) * n * 2;
  92. for (i = n - 1; i >= 0; i--) {
  93. bb1 = *(b + i * 2 + 0);
  94. bb2 = *(b + i * 2 + 1);
  95. for (j = 0; j < m; j ++) {
  96. aa1 = *(c + j * 2 + 0 + i * ldc);
  97. aa2 = *(c + j * 2 + 1 + i * 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. *(a + 0) = cc1;
  106. *(a + 1) = cc2;
  107. *(c + j * 2 + 0 + i * ldc) = cc1;
  108. *(c + j * 2 + 1 + i * ldc) = cc2;
  109. a += 2;
  110. for (k = 0; k < i; k ++){
  111. #ifndef CONJ
  112. *(c + j * 2 + 0 + k * ldc) -= cc1 * *(b + k * 2 + 0) - cc2 * *(b + k * 2 + 1);
  113. *(c + j * 2 + 1 + k * ldc) -= cc1 * *(b + k * 2 + 1) + cc2 * *(b + k * 2 + 0);
  114. #else
  115. *(c + j * 2 + 0 + k * ldc) -= cc1 * *(b + k * 2 + 0) + cc2 * *(b + k * 2 + 1);
  116. *(c + j * 2 + 1 + k * ldc) -= -cc1 * *(b + k * 2 + 1) + cc2 * *(b + k * 2 + 0);
  117. #endif
  118. }
  119. }
  120. b -= n * 2;
  121. a -= 4 * m;
  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 RT KERNEL m = %3ld n = %3ld k = %3ld offset = %3ld\n",
  140. m, n, k, offset);
  141. #endif
  142. kk = n - offset;
  143. c += n * ldc * COMPSIZE;
  144. b += n * k * COMPSIZE;
  145. if (n & (GEMM_UNROLL_N - 1)) {
  146. j = 1;
  147. while (j < GEMM_UNROLL_N) {
  148. if (n & j) {
  149. aa = a;
  150. b -= j * k * COMPSIZE;
  151. c -= j * ldc* COMPSIZE;
  152. cc = c;
  153. i = sve_size;
  154. if (i <= m) {
  155. do {
  156. if (k - kk > 0) {
  157. GEMM_KERNEL(sve_size, j, k - kk, dm1,
  158. #ifdef COMPLEX
  159. ZERO,
  160. #endif
  161. aa + sve_size * kk * COMPSIZE,
  162. b + j * kk * COMPSIZE,
  163. cc,
  164. ldc);
  165. }
  166. solve(sve_size, j,
  167. aa + (kk - j) * sve_size * COMPSIZE,
  168. b + (kk - j) * j * COMPSIZE,
  169. cc, ldc);
  170. aa += sve_size * k * COMPSIZE;
  171. cc += sve_size * COMPSIZE;
  172. i += sve_size;
  173. } while (i <= m);
  174. }
  175. i = m % sve_size;
  176. if (i) {
  177. if (k - kk > 0) {
  178. GEMM_KERNEL(i, j, k - kk, dm1,
  179. #ifdef COMPLEX
  180. ZERO,
  181. #endif
  182. aa + i * kk * COMPSIZE,
  183. b + j * kk * COMPSIZE,
  184. cc, ldc);
  185. }
  186. solve(i, j,
  187. aa + (kk - j) * i * COMPSIZE,
  188. b + (kk - j) * j * COMPSIZE,
  189. cc, ldc);
  190. aa += i * k * COMPSIZE;
  191. cc += i * COMPSIZE;
  192. }
  193. kk -= j;
  194. }
  195. j <<= 1;
  196. }
  197. }
  198. j = (n >> GEMM_UNROLL_N_SHIFT);
  199. if (j > 0) {
  200. do {
  201. aa = a;
  202. b -= GEMM_UNROLL_N * k * COMPSIZE;
  203. c -= GEMM_UNROLL_N * ldc * COMPSIZE;
  204. cc = c;
  205. i = sve_size;
  206. if (i <= m) {
  207. do {
  208. if (k - kk > 0) {
  209. GEMM_KERNEL(sve_size, GEMM_UNROLL_N, k - kk, dm1,
  210. #ifdef COMPLEX
  211. ZERO,
  212. #endif
  213. aa + sve_size * kk * COMPSIZE,
  214. b + GEMM_UNROLL_N * kk * COMPSIZE,
  215. cc,
  216. ldc);
  217. }
  218. solve(sve_size, GEMM_UNROLL_N,
  219. aa + (kk - GEMM_UNROLL_N) * sve_size * COMPSIZE,
  220. b + (kk - GEMM_UNROLL_N) * GEMM_UNROLL_N * COMPSIZE,
  221. cc, ldc);
  222. aa += sve_size * k * COMPSIZE;
  223. cc += sve_size * COMPSIZE;
  224. i += sve_size;
  225. } while (i <= m);
  226. }
  227. i = m % sve_size;
  228. if (i) {
  229. if (k - kk > 0) {
  230. GEMM_KERNEL(i, GEMM_UNROLL_N, k - kk, dm1,
  231. #ifdef COMPLEX
  232. ZERO,
  233. #endif
  234. aa + i * kk * COMPSIZE,
  235. b + GEMM_UNROLL_N * kk * COMPSIZE,
  236. cc,
  237. ldc);
  238. }
  239. solve(i, GEMM_UNROLL_N,
  240. aa + (kk - GEMM_UNROLL_N) * i * COMPSIZE,
  241. b + (kk - GEMM_UNROLL_N) * GEMM_UNROLL_N * COMPSIZE,
  242. cc, ldc);
  243. aa += i * k * COMPSIZE;
  244. cc += i * COMPSIZE;
  245. }
  246. kk -= GEMM_UNROLL_N;
  247. j --;
  248. } while (j > 0);
  249. }
  250. return 0;
  251. }