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_RN_sve.c 7.1 kB

3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. for (i = 0; i < n; i++) {
  66. bb = *(b + i);
  67. for (j = 0; j < m; j ++) {
  68. aa = *(c + j + i * ldc);
  69. aa *= bb;
  70. *a = aa;
  71. *(c + j + i * ldc) = aa;
  72. a ++;
  73. for (k = i + 1; k < n; k ++){
  74. *(c + j + k * ldc) -= aa * *(b + k);
  75. }
  76. }
  77. b += n;
  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 < n; i++) {
  88. bb1 = *(b + i * 2 + 0);
  89. bb2 = *(b + i * 2 + 1);
  90. for (j = 0; j < m; j ++) {
  91. aa1 = *(c + j * 2 + 0 + i * ldc);
  92. aa2 = *(c + j * 2 + 1 + i * 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. *(a + 0) = cc1;
  101. *(a + 1) = cc2;
  102. *(c + j * 2 + 0 + i * ldc) = cc1;
  103. *(c + j * 2 + 1 + i * ldc) = cc2;
  104. a += 2;
  105. for (k = i + 1; k < n; k ++){
  106. #ifndef CONJ
  107. *(c + j * 2 + 0 + k * ldc) -= cc1 * *(b + k * 2 + 0) - cc2 * *(b + k * 2 + 1);
  108. *(c + j * 2 + 1 + k * ldc) -= cc1 * *(b + k * 2 + 1) + cc2 * *(b + k * 2 + 0);
  109. #else
  110. *(c + j * 2 + 0 + k * ldc) -= cc1 * *(b + k * 2 + 0) + cc2 * *(b + k * 2 + 1);
  111. *(c + j * 2 + 1 + k * ldc) -= - cc1 * *(b + k * 2 + 1) + cc2 * *(b + k * 2 + 0);
  112. #endif
  113. }
  114. }
  115. b += n * 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 RN KERNEL 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. kk = -offset;
  139. while (j > 0) {
  140. aa = a;
  141. cc = c;
  142. i = sve_size;
  143. if (i <= m) {
  144. do {
  145. if (kk > 0) {
  146. GEMM_KERNEL(sve_size, GEMM_UNROLL_N, kk, dm1,
  147. #ifdef COMPLEX
  148. ZERO,
  149. #endif
  150. aa, b, cc, ldc);
  151. }
  152. solve(sve_size, GEMM_UNROLL_N,
  153. aa + kk * sve_size * COMPSIZE,
  154. b + kk * GEMM_UNROLL_N * COMPSIZE,
  155. cc, ldc);
  156. aa += sve_size * k * COMPSIZE;
  157. cc += sve_size * COMPSIZE;
  158. i += sve_size;
  159. } while (i <= m);
  160. }
  161. i = m % sve_size;
  162. if (i) {
  163. if (kk > 0) {
  164. GEMM_KERNEL(i, GEMM_UNROLL_N, kk, dm1,
  165. #ifdef COMPLEX
  166. ZERO,
  167. #endif
  168. aa, b, cc, ldc);
  169. }
  170. solve(i, GEMM_UNROLL_N,
  171. aa + kk * i * COMPSIZE,
  172. b + kk * GEMM_UNROLL_N * COMPSIZE,
  173. cc, ldc);
  174. aa += i * k * COMPSIZE;
  175. cc += i * COMPSIZE;
  176. }
  177. kk += GEMM_UNROLL_N;
  178. b += GEMM_UNROLL_N * k * COMPSIZE;
  179. c += GEMM_UNROLL_N * ldc * COMPSIZE;
  180. j --;
  181. jj += sve_size;
  182. }
  183. if (n & (GEMM_UNROLL_N - 1)) {
  184. j = (GEMM_UNROLL_N >> 1);
  185. while (j > 0) {
  186. if (n & j) {
  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. i += sve_size;
  207. }
  208. i = m % sve_size;
  209. if (i) {
  210. if (kk > 0) {
  211. GEMM_KERNEL(i, j, kk, dm1,
  212. #ifdef COMPLEX
  213. ZERO,
  214. #endif
  215. aa,
  216. b,
  217. cc,
  218. ldc);
  219. }
  220. solve(i, j,
  221. aa + kk * i * COMPSIZE,
  222. b + kk * j * COMPSIZE, cc, ldc);
  223. aa += i * k * COMPSIZE;
  224. cc += i * COMPSIZE;
  225. }
  226. b += j * k * COMPSIZE;
  227. c += j * ldc * COMPSIZE;
  228. kk += j;
  229. }
  230. j >>= 1;
  231. }
  232. }
  233. return 0;
  234. }