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_R.c 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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_R
  44. #if (!defined(TRANSA) && defined(UPPER)) || (defined(TRANSA) && !defined(UPPER))
  45. #define TRSM_KERNEL TRSM_KERNEL_RR
  46. #else
  47. #define TRSM_KERNEL TRSM_KERNEL_RC
  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_RN
  53. #else
  54. #define TRSM_KERNEL TRSM_KERNEL_RT
  55. #endif
  56. #endif
  57. #if 0
  58. #undef GEMM_P
  59. #undef GEMM_Q
  60. #undef GEMM_R
  61. #define GEMM_P 16
  62. #define GEMM_Q 20
  63. #define GEMM_R 24
  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_ls;
  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_m) {
  82. BLASLONG m_from = *(((BLASLONG *)range_m) + 0);
  83. BLASLONG m_to = *(((BLASLONG *)range_m) + 1);
  84. m = m_to - m_from;
  85. b += m_from * 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. #if (defined(UPPER) && !defined(TRANSA)) || (!defined(UPPER) && defined(TRANSA))
  99. for(js = 0; js < n; js += GEMM_R){
  100. min_j = n - js;
  101. if (min_j > GEMM_R) min_j = GEMM_R;
  102. for(ls = 0; ls < js; ls += GEMM_Q){
  103. min_l = js - ls;
  104. if (min_l > GEMM_Q) min_l = GEMM_Q;
  105. min_i = m;
  106. if (min_i > GEMM_P) min_i = GEMM_P;
  107. GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
  108. for(jjs = js; jjs < js + min_j; jjs += min_jj){
  109. min_jj = min_j + js - jjs;
  110. if (min_jj > GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  111. else
  112. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  113. #ifndef TRANSA
  114. GEMM_ONCOPY(min_l, min_jj, a + (ls + jjs * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
  115. #else
  116. GEMM_OTCOPY(min_l, min_jj, a + (jjs + ls * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
  117. #endif
  118. GEMM_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 + (jjs * ldb) * COMPSIZE, ldb);
  124. }
  125. for(is = min_i; is < m; is += GEMM_P){
  126. min_i = m - is;
  127. if (min_i > GEMM_P) min_i = GEMM_P;
  128. GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
  129. GEMM_KERNEL(min_i, min_j, min_l, dm1,
  130. #ifdef COMPLEX
  131. ZERO,
  132. #endif
  133. sa, sb, b + (is + js * ldb) * COMPSIZE, ldb);
  134. }
  135. }
  136. for(ls = js; ls < js + min_j; ls += GEMM_Q){
  137. min_l = js + min_j - ls;
  138. if (min_l > GEMM_Q) min_l = GEMM_Q;
  139. min_i = m;
  140. if (min_i > GEMM_P) min_i = GEMM_P;
  141. GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
  142. #ifndef TRANSA
  143. TRSM_OUNCOPY(min_l, min_l, a + (ls + ls * lda) * COMPSIZE, lda, 0, sb);
  144. #else
  145. TRSM_OLTCOPY(min_l, min_l, a + (ls + ls * lda) * COMPSIZE, lda, 0, sb);
  146. #endif
  147. TRSM_KERNEL(min_i, min_l, min_l, dm1,
  148. #ifdef COMPLEX
  149. ZERO,
  150. #endif
  151. sa,
  152. sb,
  153. b + (ls * ldb) * COMPSIZE, ldb, 0);
  154. for(jjs = 0; jjs < min_j - min_l - ls + js; jjs += min_jj){
  155. min_jj = min_j - min_l - ls + js - jjs;
  156. if (min_jj > GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  157. else
  158. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  159. #ifndef TRANSA
  160. GEMM_ONCOPY (min_l, min_jj, a + (ls + (ls + min_l + jjs) * lda) * COMPSIZE, lda,
  161. sb + min_l * (min_l + jjs) * COMPSIZE);
  162. #else
  163. GEMM_OTCOPY (min_l, min_jj, a + ((ls + min_l + jjs) + ls * lda) * COMPSIZE, lda,
  164. sb + min_l * (min_l + jjs) * COMPSIZE);
  165. #endif
  166. GEMM_KERNEL(min_i, min_jj, min_l, dm1,
  167. #ifdef COMPLEX
  168. ZERO,
  169. #endif
  170. sa,
  171. sb + min_l * (min_l + jjs) * COMPSIZE,
  172. b + (min_l + ls + jjs) * ldb * COMPSIZE, ldb);
  173. }
  174. for(is = min_i; is < m; is += GEMM_P){
  175. min_i = m - is;
  176. if (min_i > GEMM_P) min_i = GEMM_P;
  177. GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
  178. TRSM_KERNEL(min_i, min_l, min_l, dm1,
  179. #ifdef COMPLEX
  180. ZERO,
  181. #endif
  182. sa,
  183. sb,
  184. b + (is + ls * ldb) * COMPSIZE, ldb, 0);
  185. GEMM_KERNEL(min_i, min_j - min_l + js - ls, min_l, dm1,
  186. #ifdef COMPLEX
  187. ZERO,
  188. #endif
  189. sa,
  190. sb + min_l * min_l * COMPSIZE,
  191. b + (is + ( min_l + ls) * ldb) * COMPSIZE, ldb);
  192. }
  193. }
  194. }
  195. #else
  196. for(js = n; js > 0; js -= GEMM_R){
  197. min_j = js;
  198. if (min_j > GEMM_R) min_j = GEMM_R;
  199. for (ls = js; ls < n; ls += GEMM_Q) {
  200. min_l = n - ls;
  201. if (min_l > GEMM_Q) min_l = GEMM_Q;
  202. min_i = m;
  203. if (min_i > GEMM_P) min_i = GEMM_P;
  204. GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
  205. for(jjs = js; jjs < js + min_j; jjs += min_jj){
  206. min_jj = min_j + js - jjs;
  207. if (min_jj > GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  208. else
  209. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  210. #ifndef TRANSA
  211. GEMM_ONCOPY(min_l, min_jj, a + (ls + (jjs - min_j) * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
  212. #else
  213. GEMM_OTCOPY(min_l, min_jj, a + ((jjs - min_j) + ls * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
  214. #endif
  215. GEMM_KERNEL(min_i, min_jj, min_l, dm1,
  216. #ifdef COMPLEX
  217. ZERO,
  218. #endif
  219. sa, sb + min_l * (jjs - js) * COMPSIZE,
  220. b + (jjs - min_j) * ldb * COMPSIZE, ldb);
  221. }
  222. for(is = min_i; is < m; is += GEMM_P){
  223. min_i = m - is;
  224. if (min_i > GEMM_P) min_i = GEMM_P;
  225. GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
  226. GEMM_KERNEL(min_i, min_j, min_l, dm1,
  227. #ifdef COMPLEX
  228. ZERO,
  229. #endif
  230. sa, sb, b + (is + (js - min_j) * ldb) * COMPSIZE, ldb);
  231. }
  232. }
  233. start_ls = js - min_j;
  234. while (start_ls + GEMM_Q < js) start_ls += GEMM_Q;
  235. for(ls = start_ls; ls >= js - min_j; ls -= GEMM_Q){
  236. min_l = js - ls;
  237. if (min_l > GEMM_Q) min_l = GEMM_Q;
  238. min_i = m;
  239. if (min_i > GEMM_P) min_i = GEMM_P;
  240. GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
  241. #ifndef TRANSA
  242. TRSM_OLNCOPY(min_l, min_l, a + (ls + ls * lda) * COMPSIZE, lda,
  243. 0, sb + min_l * (min_j - js + ls) * COMPSIZE);
  244. #else
  245. TRSM_OUTCOPY(min_l, min_l, a + (ls + ls * lda) * COMPSIZE, lda,
  246. 0, sb + min_l * (min_j - js + ls) * COMPSIZE);
  247. #endif
  248. TRSM_KERNEL(min_i, min_l, min_l, dm1,
  249. #ifdef COMPLEX
  250. ZERO,
  251. #endif
  252. sa,
  253. sb + min_l * (min_j - js + ls) * COMPSIZE,
  254. b + (ls * ldb) * COMPSIZE, ldb, 0);
  255. for(jjs = 0; jjs < min_j - js + ls; jjs += min_jj){
  256. min_jj = min_j - js + ls - jjs;
  257. if (min_jj > GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  258. else
  259. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  260. #ifndef TRANSA
  261. GEMM_ONCOPY (min_l, min_jj, a + (ls + (js - min_j + jjs) * lda) * COMPSIZE, lda,
  262. sb + min_l * jjs * COMPSIZE);
  263. #else
  264. GEMM_OTCOPY (min_l, min_jj, a + ((js - min_j + jjs) + ls * lda) * COMPSIZE, lda,
  265. sb + min_l * jjs * COMPSIZE);
  266. #endif
  267. GEMM_KERNEL(min_i, min_jj, min_l, dm1,
  268. #ifdef COMPLEX
  269. ZERO,
  270. #endif
  271. sa,
  272. sb + min_l * jjs * COMPSIZE,
  273. b + (js - min_j + jjs) * ldb * COMPSIZE, ldb);
  274. }
  275. for(is = min_i; is < m; is += GEMM_P){
  276. min_i = m - is;
  277. if (min_i > GEMM_P) min_i = GEMM_P;
  278. GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
  279. TRSM_KERNEL(min_i, min_l, min_l, dm1,
  280. #ifdef COMPLEX
  281. ZERO,
  282. #endif
  283. sa,
  284. sb + min_l * (min_j - js + ls) * COMPSIZE,
  285. b + (is + ls * ldb) * COMPSIZE, ldb, 0);
  286. GEMM_KERNEL(min_i, min_j - js + ls, min_l, dm1,
  287. #ifdef COMPLEX
  288. ZERO,
  289. #endif
  290. sa,
  291. sb,
  292. b + (is + (js - min_j) * ldb) * COMPSIZE, ldb);
  293. }
  294. }
  295. }
  296. #endif
  297. return 0;
  298. }