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_L_single.c 6.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_LU
  44. #else
  45. #define TRTI2 TRTI2_LN
  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_i;
  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. start_i = 0;
  86. while (start_i < n) start_i += blocking;
  87. start_i -= blocking;
  88. for (i = start_i; i >= 0; i -= blocking) {
  89. bk = MIN(blocking, n - i);
  90. if (n - bk - i > 0) TRSM_OLNCOPY(bk, bk, a + (i + i * lda) * COMPSIZE, lda, 0, sa_trsm);
  91. if (!range_n) {
  92. range_N[0] = i;
  93. range_N[1] = i + bk;
  94. } else {
  95. range_N[0] = range_n[0] + i;
  96. range_N[1] = range_n[0] + i + bk;
  97. }
  98. CNAME(args, NULL, range_N, sa, sa_trmm, 0);
  99. if (i > 0) {
  100. TRMM_ILTCOPY(bk, bk, a + (i + i * lda) * COMPSIZE, lda, 0, 0, sa_trmm);
  101. for (ls = 0; ls < i; ls += REAL_GEMM_R) {
  102. min_l = i - ls;
  103. if (min_l > REAL_GEMM_R) min_l = REAL_GEMM_R;
  104. GEMM_ONCOPY (bk, min_l, a + (i + ls * lda) * COMPSIZE, lda, sb_gemm);
  105. if (n - bk - i > 0) {
  106. for (is = i + bk; is < n; is += GEMM_P) {
  107. min_i = n - is;
  108. if (min_i > GEMM_P) min_i = GEMM_P;
  109. if (ls == 0) {
  110. NEG_TCOPY (bk, min_i, a + (is + i * lda) * COMPSIZE, lda, sa);
  111. TRSM_KERNEL_RT(min_i, bk, bk, dm1,
  112. #ifdef COMPLEX
  113. ZERO,
  114. #endif
  115. sa, sa_trsm,
  116. a + (is + i * lda) * COMPSIZE, lda, 0);
  117. } else {
  118. GEMM_ITCOPY (bk, min_i, a + (is + i * lda) * COMPSIZE, lda, sa);
  119. }
  120. GEMM_KERNEL_N(min_i, min_l, bk, dp1,
  121. #ifdef COMPLEX
  122. ZERO,
  123. #endif
  124. sa, sb_gemm,
  125. a + (is + ls * lda) * COMPSIZE, lda);
  126. }
  127. }
  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_LT(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 (n - bk - i > 0) {
  141. for (is = 0; is < n - bk - i; is += GEMM_P) {
  142. min_i = n - bk - i - is;
  143. if (min_i > GEMM_P) min_i = GEMM_P;
  144. NEG_TCOPY (bk, min_i, a + (i + bk + is + i * lda) * COMPSIZE, lda, sa);
  145. TRSM_KERNEL_RT(min_i, bk, bk, dm1,
  146. #ifdef COMPLEX
  147. ZERO,
  148. #endif
  149. sa, sa_trsm,
  150. a + (i + bk + is + i * lda) * COMPSIZE, lda, 0);
  151. }
  152. }
  153. }
  154. }
  155. return 0;
  156. }