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_L.c 8.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 <ctype.h>
  40. #include "common.h"
  41. const static FLOAT dm1 = -1.;
  42. #ifdef CONJ
  43. #define GEMM_KERNEL GEMM_KERNEL_L
  44. #if (!defined(TRANSA) && defined(UPPER)) || (defined(TRANSA) && !defined(UPPER))
  45. #define TRSM_KERNEL TRSM_KERNEL_LR
  46. #else
  47. #define TRSM_KERNEL TRSM_KERNEL_LC
  48. #endif
  49. #else
  50. #define GEMM_KERNEL GEMM_KERNEL_N
  51. #if (!defined(TRANSA) && defined(UPPER)) || (defined(TRANSA) && !defined(UPPER))
  52. #define TRSM_KERNEL TRSM_KERNEL_LN
  53. #else
  54. #define TRSM_KERNEL TRSM_KERNEL_LT
  55. #endif
  56. #endif
  57. #if 0
  58. #undef GEMM_P
  59. #undef GEMM_Q
  60. #undef GEMM_R
  61. #define GEMM_P 8
  62. #define GEMM_Q 12
  63. #define GEMM_R 1600
  64. #endif
  65. int CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa, FLOAT *sb, BLASLONG dummy) {
  66. BLASLONG m, n, lda, ldb;
  67. FLOAT *beta, *a, *b;
  68. BLASLONG ls, is, js;
  69. BLASLONG min_l, min_i, min_j;
  70. BLASLONG jjs, min_jj;
  71. #if !((!defined(UPPER) && !defined(TRANSA)) || (defined(UPPER) && defined(TRANSA)))
  72. BLASLONG start_is;
  73. #endif
  74. m = args -> m;
  75. n = args -> n;
  76. a = (FLOAT *)args -> a;
  77. b = (FLOAT *)args -> b;
  78. lda = args -> lda;
  79. ldb = args -> ldb;
  80. beta = (FLOAT *)args -> beta;
  81. if (range_n) {
  82. BLASLONG n_from = *(((BLASLONG *)range_n) + 0);
  83. BLASLONG n_to = *(((BLASLONG *)range_n) + 1);
  84. n = n_to - n_from;
  85. b += n_from * ldb * COMPSIZE;
  86. }
  87. if (beta) {
  88. #ifndef COMPLEX
  89. if (beta[0] != ONE)
  90. GEMM_BETA(m, n, 0, beta[0], NULL, 0, NULL, 0, b, ldb);
  91. if (beta[0] == ZERO) return 0;
  92. #else
  93. if ((beta[0] != ONE) || (beta[1] != ZERO))
  94. GEMM_BETA(m, n, 0, beta[0], beta[1], NULL, 0, NULL, 0, b, ldb);
  95. if ((beta[0] == ZERO) && (beta[1] == ZERO)) return 0;
  96. #endif
  97. }
  98. for(js = 0; js < n; js += GEMM_R){
  99. min_j = n - js;
  100. if (min_j > GEMM_R) min_j = GEMM_R;
  101. #if (!defined(UPPER) && !defined(TRANSA)) || (defined(UPPER) && defined(TRANSA))
  102. for(ls = 0; ls < m; ls += GEMM_Q){
  103. min_l = m - ls;
  104. if (min_l > GEMM_Q) min_l = GEMM_Q;
  105. min_i = min_l;
  106. if (min_i > GEMM_P) min_i = GEMM_P;
  107. #ifndef TRANSA
  108. TRSM_ILTCOPY(min_l, min_i, a + (ls + ls * lda) * COMPSIZE, lda, 0, sa);
  109. #else
  110. TRSM_IUNCOPY(min_l, min_i, a + (ls + ls * lda) * COMPSIZE, lda, 0, sa);
  111. #endif
  112. for(jjs = js; jjs < js + min_j; jjs += min_jj){
  113. min_jj = min_j + js - jjs;
  114. if (min_jj >= GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  115. else
  116. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  117. GEMM_ONCOPY(min_l, min_jj, b + (ls + jjs * ldb) * COMPSIZE, ldb, sb + min_l * (jjs - js) * COMPSIZE);
  118. TRSM_KERNEL(min_i, min_jj, min_l, dm1,
  119. #ifdef COMPLEX
  120. ZERO,
  121. #endif
  122. sa, sb + min_l * (jjs - js) * COMPSIZE,
  123. b + (ls + jjs * ldb) * COMPSIZE, ldb, 0);
  124. }
  125. for(is = ls + min_i; is < ls + min_l; is += GEMM_P){
  126. min_i = ls + min_l - is;
  127. if (min_i > GEMM_P) min_i = GEMM_P;
  128. #ifndef TRANSA
  129. TRSM_ILTCOPY(min_l, min_i, a + (is + ls * lda) * COMPSIZE, lda, is - ls, sa);
  130. #else
  131. TRSM_IUNCOPY(min_l, min_i, a + (ls + is * lda) * COMPSIZE, lda, is - ls, sa);
  132. #endif
  133. TRSM_KERNEL(min_i, min_j, min_l, dm1,
  134. #ifdef COMPLEX
  135. ZERO,
  136. #endif
  137. sa, sb, b + (is + js * ldb) * COMPSIZE, ldb, is - ls);
  138. }
  139. for(is = ls + min_l; is < m; is += GEMM_P){
  140. min_i = m - is;
  141. if (min_i > GEMM_P) min_i = GEMM_P;
  142. #ifndef TRANSA
  143. GEMM_ITCOPY(min_l, min_i, a + (is + ls * lda) * COMPSIZE, lda, sa);
  144. #else
  145. GEMM_INCOPY(min_l, min_i, a + (ls + is * lda) * COMPSIZE, lda, sa);
  146. #endif
  147. GEMM_KERNEL(min_i, min_j, min_l, dm1,
  148. #ifdef COMPLEX
  149. ZERO,
  150. #endif
  151. sa, sb, b + (is + js * ldb) * COMPSIZE, ldb);
  152. }
  153. }
  154. #else
  155. for(ls = m; ls > 0; ls -= GEMM_Q){
  156. min_l = ls;
  157. if (min_l > GEMM_Q) min_l = GEMM_Q;
  158. start_is = ls - min_l;
  159. while (start_is + GEMM_P < ls) start_is += GEMM_P;
  160. min_i = ls - start_is;
  161. if (min_i > GEMM_P) min_i = GEMM_P;
  162. #ifndef TRANSA
  163. TRSM_IUTCOPY(min_l, min_i, a + (start_is + (ls - min_l) * lda) * COMPSIZE, lda, start_is - (ls - min_l), sa);
  164. #else
  165. TRSM_ILNCOPY(min_l, min_i, a + ((ls - min_l) + start_is * lda) * COMPSIZE, lda, start_is - (ls - min_l), sa);
  166. #endif
  167. for(jjs = js; jjs < js + min_j; jjs += min_jj){
  168. min_jj = min_j + js - jjs;
  169. if (min_jj >= GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  170. else
  171. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  172. GEMM_ONCOPY(min_l, min_jj, b + (ls - min_l + jjs * ldb) * COMPSIZE, ldb, sb + min_l * (jjs - js) * COMPSIZE);
  173. TRSM_KERNEL(min_i, min_jj, min_l, dm1,
  174. #ifdef COMPLEX
  175. ZERO,
  176. #endif
  177. sa, sb + min_l * (jjs - js) * COMPSIZE,
  178. b + (start_is + jjs * ldb) * COMPSIZE, ldb, start_is - ls + min_l);
  179. }
  180. for(is = start_is - GEMM_P; is >= ls - min_l; is -= GEMM_P){
  181. min_i = ls - is;
  182. if (min_i > GEMM_P) min_i = GEMM_P;
  183. #ifndef TRANSA
  184. TRSM_IUTCOPY(min_l, min_i, a + (is + (ls - min_l) * lda) * COMPSIZE, lda, is - (ls - min_l), sa);
  185. #else
  186. TRSM_ILNCOPY(min_l, min_i, a + ((ls - min_l) + is * lda) * COMPSIZE, lda, is - (ls - min_l), sa);
  187. #endif
  188. TRSM_KERNEL(min_i, min_j, min_l, dm1,
  189. #ifdef COMPLEX
  190. ZERO,
  191. #endif
  192. sa, sb,
  193. b + (is + js * ldb) * COMPSIZE, ldb, + is - (ls - min_l) );
  194. }
  195. for(is = 0; is < ls - min_l; is += GEMM_P){
  196. min_i = ls - min_l - is;
  197. if (min_i > GEMM_P) min_i = GEMM_P;
  198. #ifndef TRANSA
  199. GEMM_ITCOPY(min_l, min_i, a + (is + (ls - min_l) * lda) * COMPSIZE, lda, sa);
  200. #else
  201. GEMM_INCOPY(min_l, min_i, a + ((ls - min_l) + is * lda) * COMPSIZE, lda, sa);
  202. #endif
  203. GEMM_KERNEL(min_i, min_j, min_l, dm1,
  204. #ifdef COMPLEX
  205. ZERO,
  206. #endif
  207. sa, sb, b + (is + js * ldb) * COMPSIZE, ldb);
  208. }
  209. }
  210. #endif
  211. }
  212. return 0;
  213. }