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_LT_sve.c 7.5 kB

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