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.

trtri_U_single.c 6.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 "common.h"
  40. static FLOAT dp1 = 1.;
  41. static FLOAT dm1 = -1.;
  42. #ifdef UNIT
  43. #define TRTI2 TRTI2_UU
  44. #else
  45. #define TRTI2 TRTI2_UN
  46. #endif
  47. #if 0
  48. #undef GEMM_P
  49. #undef GEMM_Q
  50. #undef GEMM_R
  51. #define GEMM_P 8
  52. #define GEMM_Q 20
  53. #define GEMM_R 64
  54. #endif
  55. #define GEMM_PQ MAX(GEMM_P, GEMM_Q)
  56. #define REAL_GEMM_R (GEMM_R - 2 * GEMM_PQ)
  57. blasint CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa, FLOAT *sb, BLASLONG myid) {
  58. BLASLONG n, lda;
  59. FLOAT *a;
  60. BLASLONG i, is, min_i, start_is;
  61. BLASLONG ls, min_l;
  62. BLASLONG bk;
  63. BLASLONG blocking;
  64. BLASLONG range_N[2];
  65. FLOAT *sa_trsm = (FLOAT *)((BLASLONG)sb);
  66. FLOAT *sa_trmm = (FLOAT *)((((BLASLONG)sb
  67. + GEMM_PQ * GEMM_Q * COMPSIZE * SIZE + GEMM_ALIGN) & ~GEMM_ALIGN)
  68. + GEMM_OFFSET_A);
  69. FLOAT *sb_gemm = (FLOAT *)((((BLASLONG)sa_trmm
  70. + GEMM_PQ * GEMM_Q * COMPSIZE * SIZE + GEMM_ALIGN) & ~GEMM_ALIGN)
  71. + GEMM_OFFSET_B);
  72. n = args -> n;
  73. a = (FLOAT *)args -> a;
  74. lda = args -> lda;
  75. if (range_n) {
  76. n = range_n[1] - range_n[0];
  77. a += range_n[0] * (lda + 1) * COMPSIZE;
  78. }
  79. if (n <= DTB_ENTRIES) {
  80. TRTI2(args, NULL, range_n, sa, sb, 0);
  81. return 0;
  82. }
  83. blocking = GEMM_Q;
  84. if (n <= 4 * GEMM_Q) blocking = (n + 3) / 4;
  85. for (i = 0; i < n; i += blocking) {
  86. bk = MIN(blocking, n - i);
  87. if (i > 0) TRSM_OUNCOPY(bk, bk, a + (i + i * lda) * COMPSIZE, lda, 0, sa_trsm);
  88. if (!range_n) {
  89. range_N[0] = i;
  90. range_N[1] = i + bk;
  91. } else {
  92. range_N[0] = range_n[0] + i;
  93. range_N[1] = range_n[0] + i + bk;
  94. }
  95. CNAME(args, NULL, range_N, sa, sa_trmm, 0);
  96. if (n -bk - i > 0) {
  97. TRMM_IUTCOPY(bk, bk, a + (i + i * lda) * COMPSIZE, lda, 0, 0, sa_trmm);
  98. for (ls = i + bk; ls < n; ls += REAL_GEMM_R) {
  99. min_l = n - ls;
  100. if (min_l > REAL_GEMM_R) min_l = REAL_GEMM_R;
  101. GEMM_ONCOPY (bk, min_l, a + (i + ls * lda) * COMPSIZE, lda, sb_gemm);
  102. if (i > 0) {
  103. for (is = 0; is < i; is += GEMM_P) {
  104. min_i = i - is;
  105. if (min_i > GEMM_P) min_i = GEMM_P;
  106. if (ls == i + bk) {
  107. NEG_TCOPY (bk, min_i, a + (is + i * lda) * COMPSIZE, lda, sa);
  108. TRSM_KERNEL_RN(min_i, bk, bk, dm1,
  109. #ifdef COMPLEX
  110. ZERO,
  111. #endif
  112. sa, sa_trsm,
  113. a + (is + i * lda) * COMPSIZE, lda, 0);
  114. } else {
  115. GEMM_ITCOPY (bk, min_i, a + (is + i * lda) * COMPSIZE, lda, sa);
  116. }
  117. GEMM_KERNEL_N(min_i, min_l, bk, dp1,
  118. #ifdef COMPLEX
  119. ZERO,
  120. #endif
  121. sa, sb_gemm,
  122. a + (is + ls * lda) * COMPSIZE, lda);
  123. }
  124. }
  125. start_is = 0;
  126. while (start_is < bk) start_is += GEMM_P;
  127. start_is -= GEMM_P;
  128. for (is = 0; is < bk; is += GEMM_P) {
  129. min_i = bk - is;
  130. if (min_i > GEMM_P) min_i = GEMM_P;
  131. TRMM_KERNEL_LN(min_i, min_l, bk, dp1,
  132. #ifdef COMPLEX
  133. ZERO,
  134. #endif
  135. sa_trmm + is * bk * COMPSIZE, sb_gemm,
  136. a + (i + is + ls * lda) * COMPSIZE, lda, is);
  137. }
  138. }
  139. } else {
  140. if (i > 0) {
  141. for (is = 0; is < i; is += GEMM_P) {
  142. min_i = i - is;
  143. if (min_i > GEMM_P) min_i = GEMM_P;
  144. NEG_TCOPY (bk, min_i, a + (is + i * lda) * COMPSIZE, lda, sa);
  145. TRSM_KERNEL_RN(min_i, bk, bk, dm1,
  146. #ifdef COMPLEX
  147. ZERO,
  148. #endif
  149. sa, sa_trsm,
  150. a + (is + i * lda) * COMPSIZE, lda, 0);
  151. }
  152. }
  153. }
  154. }
  155. return 0;
  156. }