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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. m = args -> m;
  72. n = args -> n;
  73. a = (FLOAT *)args -> a;
  74. b = (FLOAT *)args -> b;
  75. lda = args -> lda;
  76. ldb = args -> ldb;
  77. beta = (FLOAT *)args -> beta;
  78. if (range_n) {
  79. BLASLONG n_from = *(((BLASLONG *)range_n) + 0);
  80. BLASLONG n_to = *(((BLASLONG *)range_n) + 1);
  81. n = n_to - n_from;
  82. b += n_from * ldb * COMPSIZE;
  83. }
  84. if (beta) {
  85. #ifndef COMPLEX
  86. if (beta[0] != ONE)
  87. GEMM_BETA(m, n, 0, beta[0], NULL, 0, NULL, 0, b, ldb);
  88. if (beta[0] == ZERO) return 0;
  89. #else
  90. if ((beta[0] != ONE) || (beta[1] != ZERO))
  91. GEMM_BETA(m, n, 0, beta[0], beta[1], NULL, 0, NULL, 0, b, ldb);
  92. if ((beta[0] == ZERO) && (beta[1] == ZERO)) return 0;
  93. #endif
  94. }
  95. for(js = 0; js < n; js += GEMM_R){
  96. min_j = n - js;
  97. if (min_j > GEMM_R) min_j = GEMM_R;
  98. #if (!defined(UPPER) && !defined(TRANSA)) || (defined(UPPER) && defined(TRANSA))
  99. for(ls = 0; ls < m; ls += GEMM_Q){
  100. min_l = m - ls;
  101. if (min_l > GEMM_Q) min_l = GEMM_Q;
  102. min_i = min_l;
  103. if (min_i > GEMM_P) min_i = GEMM_P;
  104. #ifndef TRANSA
  105. TRSM_ILTCOPY(min_l, min_i, a + (ls + ls * lda) * COMPSIZE, lda, 0, sa);
  106. #else
  107. TRSM_IUNCOPY(min_l, min_i, a + (ls + ls * lda) * COMPSIZE, lda, 0, sa);
  108. #endif
  109. for(jjs = js; jjs < js + min_j; jjs += min_jj){
  110. min_jj = min_j + js - jjs;
  111. if (min_jj > GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  112. else
  113. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  114. GEMM_ONCOPY(min_l, min_jj, b + (ls + jjs * ldb) * COMPSIZE, ldb, sb + min_l * (jjs - js) * COMPSIZE);
  115. TRSM_KERNEL(min_i, min_jj, min_l, dm1,
  116. #ifdef COMPLEX
  117. ZERO,
  118. #endif
  119. sa, sb + min_l * (jjs - js) * COMPSIZE,
  120. b + (ls + jjs * ldb) * COMPSIZE, ldb, 0);
  121. }
  122. for(is = ls + min_i; is < ls + min_l; is += GEMM_P){
  123. min_i = ls + min_l - is;
  124. if (min_i > GEMM_P) min_i = GEMM_P;
  125. #ifndef TRANSA
  126. TRSM_ILTCOPY(min_l, min_i, a + (is + ls * lda) * COMPSIZE, lda, is - ls, sa);
  127. #else
  128. TRSM_IUNCOPY(min_l, min_i, a + (ls + is * lda) * COMPSIZE, lda, is - ls, sa);
  129. #endif
  130. TRSM_KERNEL(min_i, min_j, min_l, dm1,
  131. #ifdef COMPLEX
  132. ZERO,
  133. #endif
  134. sa, sb, b + (is + js * ldb) * COMPSIZE, ldb, is - ls);
  135. }
  136. for(is = ls + min_l; is < m; is += GEMM_P){
  137. min_i = m - is;
  138. if (min_i > GEMM_P) min_i = GEMM_P;
  139. #ifndef TRANSA
  140. GEMM_ITCOPY(min_l, min_i, a + (is + ls * lda) * COMPSIZE, lda, sa);
  141. #else
  142. GEMM_INCOPY(min_l, min_i, a + (ls + is * lda) * COMPSIZE, lda, sa);
  143. #endif
  144. GEMM_KERNEL(min_i, min_j, min_l, dm1,
  145. #ifdef COMPLEX
  146. ZERO,
  147. #endif
  148. sa, sb, b + (is + js * ldb) * COMPSIZE, ldb);
  149. }
  150. }
  151. #else
  152. BLASLONG start_is;
  153. for(ls = m; ls > 0; ls -= GEMM_Q){
  154. min_l = ls;
  155. if (min_l > GEMM_Q) min_l = GEMM_Q;
  156. start_is = ls - min_l;
  157. while (start_is + GEMM_P < ls) start_is += GEMM_P;
  158. min_i = ls - start_is;
  159. if (min_i > GEMM_P) min_i = GEMM_P;
  160. #ifndef TRANSA
  161. TRSM_IUTCOPY(min_l, min_i, a + (start_is + (ls - min_l) * lda) * COMPSIZE, lda, start_is - (ls - min_l), sa);
  162. #else
  163. TRSM_ILNCOPY(min_l, min_i, a + ((ls - min_l) + start_is * lda) * COMPSIZE, lda, start_is - (ls - min_l), sa);
  164. #endif
  165. for(jjs = js; jjs < js + min_j; jjs += min_jj){
  166. min_jj = min_j + js - jjs;
  167. if (min_jj > GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  168. else
  169. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  170. GEMM_ONCOPY(min_l, min_jj, b + (ls - min_l + jjs * ldb) * COMPSIZE, ldb, sb + min_l * (jjs - js) * COMPSIZE);
  171. TRSM_KERNEL(min_i, min_jj, min_l, dm1,
  172. #ifdef COMPLEX
  173. ZERO,
  174. #endif
  175. sa, sb + min_l * (jjs - js) * COMPSIZE,
  176. b + (start_is + jjs * ldb) * COMPSIZE, ldb, start_is - ls + min_l);
  177. }
  178. for(is = start_is - GEMM_P; is >= ls - min_l; is -= GEMM_P){
  179. min_i = ls - is;
  180. if (min_i > GEMM_P) min_i = GEMM_P;
  181. #ifndef TRANSA
  182. TRSM_IUTCOPY(min_l, min_i, a + (is + (ls - min_l) * lda) * COMPSIZE, lda, is - (ls - min_l), sa);
  183. #else
  184. TRSM_ILNCOPY(min_l, min_i, a + ((ls - min_l) + is * lda) * COMPSIZE, lda, is - (ls - min_l), sa);
  185. #endif
  186. TRSM_KERNEL(min_i, min_j, min_l, dm1,
  187. #ifdef COMPLEX
  188. ZERO,
  189. #endif
  190. sa, sb,
  191. b + (is + js * ldb) * COMPSIZE, ldb, + is - (ls - min_l) );
  192. }
  193. for(is = 0; is < ls - min_l; is += GEMM_P){
  194. min_i = ls - min_l - is;
  195. if (min_i > GEMM_P) min_i = GEMM_P;
  196. #ifndef TRANSA
  197. GEMM_ITCOPY(min_l, min_i, a + (is + (ls - min_l) * lda) * COMPSIZE, lda, sa);
  198. #else
  199. GEMM_INCOPY(min_l, min_i, a + ((ls - min_l) + is * lda) * COMPSIZE, lda, sa);
  200. #endif
  201. GEMM_KERNEL(min_i, min_j, min_l, dm1,
  202. #ifdef COMPLEX
  203. ZERO,
  204. #endif
  205. sa, sb, b + (is + js * ldb) * COMPSIZE, ldb);
  206. }
  207. }
  208. #endif
  209. }
  210. return 0;
  211. }