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.

gemm_thread_mn.c 5.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 "common.h"
  41. static const int divide_rule[][2] =
  42. {{ 0, 0},
  43. { 1, 1}, { 1, 2}, { 1, 3}, { 2, 2},
  44. { 1, 5}, { 2, 3}, { 1, 7}, { 2, 4},
  45. { 3, 3}, { 2, 5}, { 1, 11}, { 2, 6},
  46. { 1, 13}, { 2, 7}, { 3, 5}, { 4, 4},
  47. { 1, 17}, { 3, 6}, { 1, 19}, { 4, 5},
  48. { 3, 7}, { 2, 11}, { 1, 23}, { 4, 6},
  49. { 5, 5}, { 2, 13}, { 3, 9}, { 4, 7},
  50. { 1, 29}, { 5, 6}, { 1, 31}, { 4, 8},
  51. { 3, 11}, { 2, 17}, { 5, 7}, { 6, 6},
  52. { 1, 37}, { 2, 19}, { 3, 13}, { 5, 8},
  53. { 1, 41}, { 6, 7}, { 1, 43}, { 4, 11},
  54. { 5, 9}, { 2, 23}, { 1, 47}, { 6, 8},
  55. { 7, 7}, { 5, 10}, { 3, 17}, { 4, 13},
  56. { 1, 53}, { 6, 9}, { 5, 11}, { 7, 8},
  57. { 3, 19}, { 2, 29}, { 1, 59}, { 6, 10},
  58. { 1, 61}, { 2, 31}, { 7, 9}, { 8, 8},
  59. };
  60. int CNAME(int mode, blas_arg_t *arg, BLASLONG *range_m, BLASLONG *range_n, int (*function)(blas_arg_t*, BLASLONG*, BLASLONG*,FLOAT *, FLOAT *, BLASLONG ), void *sa, void *sb, BLASLONG nthreads) {
  61. blas_queue_t queue[MAX_CPU_NUMBER];
  62. BLASLONG range_M[MAX_CPU_NUMBER + 1], range_N[MAX_CPU_NUMBER + 1];
  63. BLASLONG procs, num_cpu_m, num_cpu_n;
  64. BLASLONG width, i, j;
  65. BLASLONG divM, divN;
  66. divM = divide_rule[nthreads][0];
  67. divN = divide_rule[nthreads][1];
  68. if (!range_m) {
  69. range_M[0] = 0;
  70. i = arg -> m;
  71. } else {
  72. range_M[0] = range_m[0];
  73. i = range_m[1] - range_m[0];
  74. }
  75. num_cpu_m = 0;
  76. while (i > 0){
  77. width = blas_quickdivide(i + divM - num_cpu_m - 1, divM - num_cpu_m);
  78. i -= width;
  79. if (i < 0) width = width + i;
  80. range_M[num_cpu_m + 1] = range_M[num_cpu_m] + width;
  81. num_cpu_m ++;
  82. }
  83. if (!range_n) {
  84. range_N[0] = 0;
  85. i = arg -> n;
  86. } else {
  87. range_N[0] = range_n[0];
  88. i = range_n[1] - range_n[0];
  89. }
  90. num_cpu_n = 0;
  91. while (i > 0){
  92. width = blas_quickdivide(i + divN - num_cpu_n - 1, divN - num_cpu_n);
  93. i -= width;
  94. if (i < 0) width = width + i;
  95. range_N[num_cpu_n + 1] = range_N[num_cpu_n] + width;
  96. num_cpu_n ++;
  97. }
  98. procs = 0;
  99. for (j = 0; j < num_cpu_n; j++) {
  100. for (i = 0; i < num_cpu_m; i++) {
  101. queue[procs].mode = mode;
  102. queue[procs].routine = function;
  103. queue[procs].args = arg;
  104. queue[procs].range_m = &range_M[i];
  105. queue[procs].range_n = &range_N[j];
  106. queue[procs].sa = NULL;
  107. queue[procs].sb = NULL;
  108. queue[procs].next = &queue[procs + 1];
  109. procs ++;
  110. }
  111. }
  112. if (procs) {
  113. queue[0].sa = sa;
  114. queue[0].sb = sb;
  115. queue[procs - 1].next = NULL;
  116. exec_blas(procs, queue);
  117. }
  118. return 0;
  119. }