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.

trmm_R.c 12 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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 dp1 = 1.;
  42. #ifdef CONJ
  43. #define GEMM_KERNEL GEMM_KERNEL_R
  44. #define TRMM_KERNEL_N TRMM_KERNEL_RR
  45. #define TRMM_KERNEL_T TRMM_KERNEL_RC
  46. #else
  47. #define GEMM_KERNEL GEMM_KERNEL_N
  48. #define TRMM_KERNEL_N TRMM_KERNEL_RN
  49. #define TRMM_KERNEL_T TRMM_KERNEL_RT
  50. #endif
  51. #if 0
  52. #undef GEMM_P
  53. #undef GEMM_Q
  54. #undef GEMM_R
  55. #define GEMM_P 8
  56. #define GEMM_Q 12
  57. #define GEMM_R 16
  58. #endif
  59. int CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa, FLOAT *sb, BLASLONG dummy) {
  60. BLASLONG m, n, lda, ldb;
  61. FLOAT *beta, *a, *b;
  62. BLASLONG ls, is, js;
  63. BLASLONG min_l, min_i, min_j;
  64. BLASLONG jjs, min_jj;
  65. #if !((!defined(UPPER) && !defined(TRANSA)) || (defined(UPPER) && defined(TRANSA)))
  66. BLASLONG start_ls;
  67. #endif
  68. m = args -> m;
  69. n = args -> n;
  70. a = (FLOAT *)args -> a;
  71. b = (FLOAT *)args -> b;
  72. lda = args -> lda;
  73. ldb = args -> ldb;
  74. beta = (FLOAT *)args -> beta;
  75. if (range_m) {
  76. BLASLONG m_from = *(((BLASLONG *)range_m) + 0);
  77. BLASLONG m_to = *(((BLASLONG *)range_m) + 1);
  78. m = m_to - m_from;
  79. b += m_from * COMPSIZE;
  80. }
  81. if (beta) {
  82. #ifndef COMPLEX
  83. if (beta[0] != ONE)
  84. GEMM_BETA(m, n, 0, beta[0], NULL, 0, NULL, 0, b, ldb);
  85. if (beta[0] == ZERO) return 0;
  86. #else
  87. if ((beta[0] != ONE) || (beta[1] != ZERO))
  88. GEMM_BETA(m, n, 0, beta[0], beta[1], NULL, 0, NULL, 0, b, ldb);
  89. if ((beta[0] == ZERO) && (beta[1] == ZERO)) return 0;
  90. #endif
  91. }
  92. #if (!defined(UPPER) && !defined(TRANSA)) || (defined(UPPER) && defined(TRANSA))
  93. for(js = 0; js < n; js += GEMM_R){
  94. min_j = n - js;
  95. if (min_j > GEMM_R) min_j = GEMM_R;
  96. for(ls = js; ls < js + min_j; ls += GEMM_Q){
  97. min_l = js + min_j - ls;
  98. if (min_l > GEMM_Q) min_l = GEMM_Q;
  99. min_i = m;
  100. if (min_i > GEMM_P) min_i = GEMM_P;
  101. GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
  102. for(jjs = 0; jjs < ls - js; jjs += min_jj){
  103. min_jj = ls - js - jjs;
  104. #if defined(SKYLAKEX) || defined(COOPERLAKE) || defined(SAPPHIRERAPIDS)
  105. /* the current AVX512 s/d/c/z GEMM kernel requires n>=6*GEMM_UNROLL_N to achieve the best performance */
  106. if (min_jj >= 6*GEMM_UNROLL_N) min_jj = 6*GEMM_UNROLL_N;
  107. #else
  108. if (min_jj >= GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  109. else
  110. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  111. #endif
  112. #ifndef TRANSA
  113. GEMM_ONCOPY(min_l, min_jj, a + (ls + (js + jjs) * lda) * COMPSIZE, lda, sb + min_l * jjs * COMPSIZE);
  114. #else
  115. GEMM_OTCOPY(min_l, min_jj, a + ((js + jjs) + ls * lda) * COMPSIZE, lda, sb + min_l * jjs * COMPSIZE);
  116. #endif
  117. GEMM_KERNEL(min_i, min_jj, min_l, dp1,
  118. #ifdef COMPLEX
  119. ZERO,
  120. #endif
  121. sa, sb + min_l * jjs * COMPSIZE,
  122. b + ((js + jjs) * ldb) * COMPSIZE, ldb);
  123. }
  124. for(jjs = 0; jjs < min_l; jjs += min_jj){
  125. min_jj = min_l - jjs;
  126. #if defined(SKYLAKEX) || defined(COOPERLAKE) || defined(SAPPHIRERAPIDS)
  127. /* the current AVX512 s/d/c/z GEMM kernel requires n>=6*GEMM_UNROLL_N to achieve the best performance */
  128. if (min_jj >= 6*GEMM_UNROLL_N) min_jj = 6*GEMM_UNROLL_N;
  129. #else
  130. if (min_jj >= GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  131. else
  132. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  133. #endif
  134. #ifndef TRANSA
  135. TRMM_OLNCOPY(min_l, min_jj, a, lda, ls, ls + jjs, sb + min_l * (ls - js + jjs) * COMPSIZE);
  136. #else
  137. TRMM_OUTCOPY(min_l, min_jj, a, lda, ls, ls + jjs, sb + min_l * (ls - js + jjs) * COMPSIZE);
  138. #endif
  139. TRMM_KERNEL_T(min_i, min_jj, min_l, dp1,
  140. #ifdef COMPLEX
  141. ZERO,
  142. #endif
  143. sa,
  144. sb + (ls - js + jjs) * min_l * COMPSIZE,
  145. b + ((ls + jjs) * ldb) * COMPSIZE, ldb, -jjs);
  146. }
  147. for(is = min_i; is < m; is += GEMM_P){
  148. min_i = m - is;
  149. if (min_i > GEMM_P) min_i = GEMM_P;
  150. GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
  151. GEMM_KERNEL(min_i, ls - js, min_l, dp1,
  152. #ifdef COMPLEX
  153. ZERO,
  154. #endif
  155. sa, sb,
  156. b + (is + js * ldb) * COMPSIZE, ldb);
  157. TRMM_KERNEL_T(min_i, min_l, min_l, dp1,
  158. #ifdef COMPLEX
  159. ZERO,
  160. #endif
  161. sa,
  162. sb + (ls - js) * min_l * COMPSIZE,
  163. b + (is + ls * ldb) * COMPSIZE, ldb, 0);
  164. }
  165. }
  166. for(ls = js + min_j; ls < n; ls += GEMM_Q){
  167. min_l = n - ls;
  168. if (min_l > GEMM_Q) min_l = GEMM_Q;
  169. min_i = m;
  170. if (min_i > GEMM_P) min_i = GEMM_P;
  171. GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
  172. for(jjs = js; jjs < js + min_j; jjs += min_jj){
  173. min_jj = min_j + js - jjs;
  174. #if defined(SKYLAKEX) || defined(COOPERLAKE) || defined(SAPPHIRERAPIDS)
  175. /* the current AVX512 s/d/c/z GEMM kernel requires n>=6*GEMM_UNROLL_N to achieve the best performance */
  176. if (min_jj >= 6*GEMM_UNROLL_N) min_jj = 6*GEMM_UNROLL_N;
  177. #else
  178. if (min_jj >= GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  179. else
  180. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  181. #endif
  182. #ifndef TRANSA
  183. GEMM_ONCOPY(min_l, min_jj, a + (ls + jjs * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
  184. #else
  185. GEMM_OTCOPY(min_l, min_jj, a + (jjs + ls * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
  186. #endif
  187. GEMM_KERNEL(min_i, min_jj, min_l, dp1,
  188. #ifdef COMPLEX
  189. ZERO,
  190. #endif
  191. sa, sb + min_l * (jjs - js) * COMPSIZE,
  192. b + (jjs * ldb) * COMPSIZE, ldb);
  193. }
  194. for(is = min_i; is < m; is += GEMM_P){
  195. min_i = m - is;
  196. if (min_i > GEMM_P) min_i = GEMM_P;
  197. GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
  198. GEMM_KERNEL(min_i, min_j, min_l, dp1,
  199. #ifdef COMPLEX
  200. ZERO,
  201. #endif
  202. sa, sb, b + (is + js * ldb) * COMPSIZE, ldb);
  203. }
  204. }
  205. }
  206. #else
  207. for(js = n; js > 0; js -= GEMM_R){
  208. min_j = js;
  209. if (min_j > GEMM_R) min_j = GEMM_R;
  210. start_ls = js - min_j;
  211. while (start_ls + GEMM_Q < js) start_ls += GEMM_Q;
  212. for(ls = start_ls; ls >= js - min_j; ls -= GEMM_Q){
  213. min_l = js - ls;
  214. if (min_l > GEMM_Q) min_l = GEMM_Q;
  215. min_i = m;
  216. if (min_i > GEMM_P) min_i = GEMM_P;
  217. GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
  218. for(jjs = 0; jjs < min_l; jjs += min_jj){
  219. min_jj = min_l - jjs;
  220. #if defined(SKYLAKEX) || defined(COOPERLAKE) || defined(SAPPHIRERAPIDS)
  221. /* the current AVX512 s/d/c/z GEMM kernel requires n>=6*GEMM_UNROLL_N to achieve the best performance */
  222. if (min_jj >= 6*GEMM_UNROLL_N) min_jj = 6*GEMM_UNROLL_N;
  223. #else
  224. if (min_jj >= GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  225. else
  226. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  227. #endif
  228. #ifndef TRANSA
  229. TRMM_OUNCOPY(min_l, min_jj, a, lda, ls, ls + jjs, sb + min_l * jjs * COMPSIZE);
  230. #else
  231. TRMM_OLTCOPY(min_l, min_jj, a, lda, ls, ls + jjs, sb + min_l * jjs * COMPSIZE);
  232. #endif
  233. TRMM_KERNEL_N(min_i, min_jj, min_l, dp1,
  234. #ifdef COMPLEX
  235. ZERO,
  236. #endif
  237. sa,
  238. sb + min_l * jjs * COMPSIZE,
  239. b + ((ls + jjs) * ldb) * COMPSIZE, ldb, -jjs);
  240. }
  241. for(jjs = 0; jjs < js - ls - min_l; jjs += min_jj){
  242. min_jj = js - ls - min_l - jjs;
  243. #if defined(SKYLAKEX) || defined(COOPERLAKE) || defined(SAPPHIRERAPIDS)
  244. /* the current AVX512 s/d/c/z GEMM kernel requires n>=6*GEMM_UNROLL_N to achieve the best performance */
  245. if (min_jj >= 6*GEMM_UNROLL_N) min_jj = 6*GEMM_UNROLL_N;
  246. #else
  247. if (min_jj >= GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  248. else
  249. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  250. #endif
  251. #ifndef TRANSA
  252. GEMM_ONCOPY(min_l, min_jj, a + (ls + (ls + min_l + jjs) * lda) * COMPSIZE, lda,
  253. sb + min_l * (min_l + jjs) * COMPSIZE);
  254. #else
  255. GEMM_OTCOPY(min_l, min_jj, a + ((ls + min_l + jjs) + ls * lda) * COMPSIZE, lda,
  256. sb + min_l * (min_l + jjs) * COMPSIZE);
  257. #endif
  258. GEMM_KERNEL(min_i, min_jj, min_l, dp1,
  259. #ifdef COMPLEX
  260. ZERO,
  261. #endif
  262. sa,
  263. sb + min_l * (min_l + jjs) * COMPSIZE,
  264. b + ((ls + min_l + jjs) * ldb) * COMPSIZE, ldb);
  265. }
  266. for(is = min_i; is < m; is += GEMM_P){
  267. min_i = m - is;
  268. if (min_i > GEMM_P) min_i = GEMM_P;
  269. GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
  270. TRMM_KERNEL_N(min_i, min_l, min_l, dp1,
  271. #ifdef COMPLEX
  272. ZERO,
  273. #endif
  274. sa,
  275. sb,
  276. b + (is + ls * ldb) * COMPSIZE, ldb, 0);
  277. if (js - ls - min_l > 0) {
  278. GEMM_KERNEL(min_i, js - ls - min_l, min_l, dp1,
  279. #ifdef COMPLEX
  280. ZERO,
  281. #endif
  282. sa,
  283. sb + min_l * min_l * COMPSIZE,
  284. b + (is + (ls + min_l) * ldb) * COMPSIZE, ldb);
  285. }
  286. }
  287. }
  288. for(ls = 0; ls < js - min_j; ls += GEMM_Q){
  289. min_l = js - min_j - ls;
  290. if (min_l > GEMM_Q) min_l = GEMM_Q;
  291. min_i = m;
  292. if (min_i > GEMM_P) min_i = GEMM_P;
  293. GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
  294. for(jjs = js; jjs < js + min_j; jjs += min_jj){
  295. min_jj = min_j + js - jjs;
  296. #if defined(SKYLAKEX) || defined(COOPERLAKE) || defined(SAPPHIRERAPIDS)
  297. /* the current AVX512 s/d/c/z GEMM kernel requires n>=6*GEMM_UNROLL_N to achieve the best performance */
  298. if (min_jj >= 6*GEMM_UNROLL_N) min_jj = 6*GEMM_UNROLL_N;
  299. #else
  300. if (min_jj >= GEMM_UNROLL_N*3) min_jj = GEMM_UNROLL_N*3;
  301. else
  302. if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
  303. #endif
  304. #ifndef TRANSA
  305. GEMM_ONCOPY(min_l, min_jj, a + (ls + (jjs - min_j) * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
  306. #else
  307. GEMM_OTCOPY(min_l, min_jj, a + ((jjs - min_j) + ls * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
  308. #endif
  309. GEMM_KERNEL(min_i, min_jj, min_l, dp1,
  310. #ifdef COMPLEX
  311. ZERO,
  312. #endif
  313. sa, sb + min_l * (jjs - js) * COMPSIZE,
  314. b + ((jjs - min_j) * ldb) * COMPSIZE, ldb);
  315. }
  316. for(is = min_i; is < m; is += GEMM_P){
  317. min_i = m - is;
  318. if (min_i > GEMM_P) min_i = GEMM_P;
  319. GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
  320. GEMM_KERNEL(min_i, min_j, min_l, dp1,
  321. #ifdef COMPLEX
  322. ZERO,
  323. #endif
  324. sa, sb, b + (is + (js - min_j) * ldb) * COMPSIZE, ldb);
  325. }
  326. }
  327. }
  328. #endif
  329. return 0;
  330. }