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.

syrk_thread.c 5.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 <stdlib.h>
  40. #include <math.h>
  41. #include "common.h"
  42. int CNAME(int mode, blas_arg_t *arg, BLASLONG *range_m, BLASLONG *range_n, int (*function)(), void *sa, void *sb, BLASLONG nthreads) {
  43. blas_queue_t queue[MAX_CPU_NUMBER];
  44. BLASLONG range[MAX_CPU_NUMBER + 1];
  45. BLASLONG width, i;
  46. BLASLONG n_from, n_to;
  47. double dnum, nf, nt, di;
  48. int num_cpu;
  49. int mask = 0;
  50. if (!(mode & BLAS_COMPLEX)) {
  51. switch (mode & BLAS_PREC) {
  52. case BLAS_SINGLE:
  53. mask = SGEMM_UNROLL_MN - 1;
  54. break;
  55. case BLAS_DOUBLE:
  56. mask = DGEMM_UNROLL_MN - 1;
  57. break;
  58. #ifdef EXPRECISION
  59. case BLAS_XDOUBLE:
  60. mask = MAX(QGEMM_UNROLL_M, QGEMM_UNROLL_N) - 1;
  61. break;
  62. #endif
  63. }
  64. } else {
  65. switch (mode & BLAS_PREC) {
  66. case BLAS_SINGLE:
  67. mask = CGEMM_UNROLL_MN - 1;
  68. break;
  69. case BLAS_DOUBLE:
  70. mask = ZGEMM_UNROLL_MN - 1;
  71. break;
  72. #ifdef EXPRECISION
  73. case BLAS_XDOUBLE:
  74. mask = MAX(XGEMM_UNROLL_M, XGEMM_UNROLL_N) - 1;
  75. break;
  76. #endif
  77. }
  78. }
  79. n_from = 0;
  80. n_to = arg -> n;
  81. if (range_n) {
  82. n_from = *(range_n + 0);
  83. n_to = *(range_n + 1);
  84. }
  85. if (!(mode & BLAS_UPLO)) {
  86. nf = (double)(n_from);
  87. nt = (double)(n_to);
  88. dnum = (nt * nt - nf * nf) / (double)nthreads;
  89. num_cpu = 0;
  90. range[0] = n_from;
  91. i = n_from;
  92. while (i < n_to){
  93. if (nthreads - num_cpu > 1) {
  94. di = (double)i;
  95. width = (BLASLONG)(( sqrt(di * di + dnum) - di + mask)/(mask+1)) * (mask+1);
  96. if ((width <= 0) || (width > n_to - i)) width = n_to - i;
  97. } else {
  98. width = n_to - i;
  99. }
  100. range[num_cpu + 1] = range[num_cpu] + width;
  101. queue[num_cpu].mode = mode;
  102. queue[num_cpu].routine = function;
  103. queue[num_cpu].args = arg;
  104. queue[num_cpu].range_m = range_m;
  105. queue[num_cpu].range_n = &range[num_cpu];
  106. queue[num_cpu].sa = NULL;
  107. queue[num_cpu].sb = NULL;
  108. queue[num_cpu].next = &queue[num_cpu + 1];
  109. num_cpu ++;
  110. i += width;
  111. }
  112. } else {
  113. nf = (double)(arg -> n - n_from);
  114. nt = (double)(arg -> n - n_to);
  115. dnum = (nt * nt - nf * nf) / (double)nthreads;
  116. num_cpu = 0;
  117. range[0] = n_from;
  118. i = n_from;
  119. while (i < n_to){
  120. if (nthreads - num_cpu > 1) {
  121. di = (double)(arg -> n - i);
  122. width = ((BLASLONG)((-sqrt(di * di + dnum) + di) + mask)/(mask+1)) * (mask+1);
  123. if ((width <= 0) || (width > n_to - i)) width = n_to - i;
  124. } else {
  125. width = n_to - i;
  126. }
  127. range[num_cpu + 1] = range[num_cpu] + width;
  128. queue[num_cpu].mode = mode;
  129. queue[num_cpu].routine = function;
  130. queue[num_cpu].args = arg;
  131. queue[num_cpu].range_m = range_m;
  132. queue[num_cpu].range_n = &range[num_cpu];
  133. queue[num_cpu].sa = NULL;
  134. queue[num_cpu].sb = NULL;
  135. queue[num_cpu].next = &queue[num_cpu + 1];
  136. num_cpu ++;
  137. i += width;
  138. }
  139. }
  140. if (num_cpu) {
  141. queue[0].sa = sa;
  142. queue[0].sb = sb;
  143. queue[num_cpu - 1].next = NULL;
  144. exec_blas(num_cpu, queue);
  145. }
  146. return 0;
  147. }