xlu_implicit_pivot.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010 Mehdi Juhoor <mjuhoor@gmail.com>
  5. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include "xlu.h"
  19. #include "xlu_kernels.h"
  20. static unsigned no_prio = 0;
  21. /*
  22. * Construct the DAG
  23. */
  24. static void create_task_pivot(starpu_data_handle_t *dataAp, unsigned nblocks,
  25. struct piv_s *piv_description,
  26. unsigned k, unsigned i,
  27. starpu_data_handle_t (* get_block)(starpu_data_handle_t *, unsigned, unsigned, unsigned))
  28. {
  29. struct starpu_task *task = starpu_task_create();
  30. task->cl = &cl_pivot;
  31. /* which sub-data is manipulated ? */
  32. task->handles[0] = get_block(dataAp, nblocks, k, i);
  33. task->cl_arg = &piv_description[k];
  34. /* this is an important task */
  35. if (!no_prio && (i == k+1))
  36. task->priority = STARPU_MAX_PRIO;
  37. starpu_task_submit(task);
  38. }
  39. static void create_task_11_pivot(starpu_data_handle_t *dataAp, unsigned nblocks,
  40. unsigned k, struct piv_s *piv_description,
  41. starpu_data_handle_t (* get_block)(starpu_data_handle_t *, unsigned, unsigned, unsigned))
  42. {
  43. struct starpu_task *task = starpu_task_create();
  44. task->cl = &cl11_pivot;
  45. task->cl_arg = &piv_description[k];
  46. /* which sub-data is manipulated ? */
  47. task->handles[0] = get_block(dataAp, nblocks, k, k);
  48. /* this is an important task */
  49. if (!no_prio)
  50. task->priority = STARPU_MAX_PRIO;
  51. starpu_task_submit(task);
  52. }
  53. static void create_task_12(starpu_data_handle_t *dataAp, unsigned nblocks, unsigned k, unsigned j,
  54. starpu_data_handle_t (* get_block)(starpu_data_handle_t *, unsigned, unsigned, unsigned))
  55. {
  56. struct starpu_task *task = starpu_task_create();
  57. task->cl = &cl12;
  58. /* which sub-data is manipulated ? */
  59. task->handles[0] = get_block(dataAp, nblocks, k, k);
  60. task->handles[1] = get_block(dataAp, nblocks, j, k);
  61. if (!no_prio && (j == k+1))
  62. task->priority = STARPU_MAX_PRIO;
  63. starpu_task_submit(task);
  64. }
  65. static void create_task_21(starpu_data_handle_t *dataAp, unsigned nblocks, unsigned k, unsigned i,
  66. starpu_data_handle_t (* get_block)(starpu_data_handle_t *, unsigned, unsigned, unsigned))
  67. {
  68. struct starpu_task *task = starpu_task_create();
  69. task->cl = &cl21;
  70. /* which sub-data is manipulated ? */
  71. task->handles[0] = get_block(dataAp, nblocks, k, k);
  72. task->handles[1] = get_block(dataAp, nblocks, k, i);
  73. if (!no_prio && (i == k+1))
  74. task->priority = STARPU_MAX_PRIO;
  75. starpu_task_submit(task);
  76. }
  77. static void create_task_22(starpu_data_handle_t *dataAp, unsigned nblocks, unsigned k, unsigned i, unsigned j,
  78. starpu_data_handle_t (* get_block)(starpu_data_handle_t *, unsigned, unsigned, unsigned))
  79. {
  80. struct starpu_task *task = starpu_task_create();
  81. task->cl = &cl22;
  82. /* which sub-data is manipulated ? */
  83. task->handles[0] = get_block(dataAp, nblocks, k, i);
  84. task->handles[1] = get_block(dataAp, nblocks, j, k);
  85. task->handles[2] = get_block(dataAp, nblocks, j, i);
  86. if (!no_prio && (i == k + 1) && (j == k +1) )
  87. task->priority = STARPU_MAX_PRIO;
  88. starpu_task_submit(task);
  89. }
  90. /*
  91. * code to bootstrap the factorization
  92. */
  93. static double dw_codelet_facto_pivot(starpu_data_handle_t *dataAp,
  94. struct piv_s *piv_description,
  95. unsigned nblocks,
  96. starpu_data_handle_t (* get_block)(starpu_data_handle_t *, unsigned, unsigned, unsigned))
  97. {
  98. struct timeval start;
  99. struct timeval end;
  100. gettimeofday(&start, NULL);
  101. /* create all the DAG nodes */
  102. unsigned i,j,k;
  103. for (k = 0; k < nblocks; k++)
  104. {
  105. create_task_11_pivot(dataAp, nblocks, k, piv_description, get_block);
  106. for (i = 0; i < nblocks; i++)
  107. {
  108. if (i != k)
  109. create_task_pivot(dataAp, nblocks, piv_description, k, i, get_block);
  110. }
  111. for (i = k+1; i<nblocks; i++)
  112. {
  113. create_task_12(dataAp, nblocks, k, i, get_block);
  114. create_task_21(dataAp, nblocks, k, i, get_block);
  115. }
  116. for (i = k+1; i<nblocks; i++)
  117. for (j = k+1; j<nblocks; j++)
  118. create_task_22(dataAp, nblocks, k, i, j, get_block);
  119. }
  120. /* stall the application until the end of computations */
  121. starpu_task_wait_for_all();
  122. gettimeofday(&end, NULL);
  123. double timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  124. return timing;
  125. }
  126. starpu_data_handle_t get_block_with_striding(starpu_data_handle_t *dataAp,
  127. unsigned nblocks __attribute__((unused)), unsigned j, unsigned i)
  128. {
  129. /* we use filters */
  130. return starpu_data_get_sub_data(*dataAp, 2, j, i);
  131. }
  132. void STARPU_LU(lu_decomposition_pivot)(TYPE *matA, unsigned *ipiv, unsigned size, unsigned ld, unsigned nblocks)
  133. {
  134. starpu_data_handle_t dataA;
  135. /* monitor and partition the A matrix into blocks :
  136. * one block is now determined by 2 unsigned (i,j) */
  137. starpu_matrix_data_register(&dataA, 0, (uintptr_t)matA, ld, size, size, sizeof(TYPE));
  138. struct starpu_data_filter f =
  139. {
  140. .filter_func = starpu_vertical_block_filter_func,
  141. .nchildren = nblocks
  142. };
  143. struct starpu_data_filter f2 =
  144. {
  145. .filter_func = starpu_block_filter_func,
  146. .nchildren = nblocks
  147. };
  148. starpu_data_map_filters(dataA, 2, &f, &f2);
  149. unsigned i;
  150. for (i = 0; i < size; i++)
  151. ipiv[i] = i;
  152. struct piv_s *piv_description = malloc(nblocks*sizeof(struct piv_s));
  153. unsigned block;
  154. for (block = 0; block < nblocks; block++)
  155. {
  156. piv_description[block].piv = ipiv;
  157. piv_description[block].first = block * (size / nblocks);
  158. piv_description[block].last = (block + 1) * (size / nblocks);
  159. }
  160. double timing;
  161. timing = dw_codelet_facto_pivot(&dataA, piv_description, nblocks, get_block_with_striding);
  162. FPRINTF(stderr, "Computation took (in ms)\n");
  163. FPRINTF(stderr, "%2.2f\n", timing/1000);
  164. unsigned n = starpu_matrix_get_nx(dataA);
  165. double flop = (2.0f*n*n*n)/3.0f;
  166. FPRINTF(stderr, "Synthetic GFlops : %2.2f\n", (flop/timing/1000.0f));
  167. /* gather all the data */
  168. starpu_data_unpartition(dataA, 0);
  169. starpu_data_unregister(dataA);
  170. }
  171. starpu_data_handle_t get_block_with_no_striding(starpu_data_handle_t *dataAp, unsigned nblocks, unsigned j, unsigned i)
  172. {
  173. /* dataAp is an array of data handle */
  174. return dataAp[i+j*nblocks];
  175. }
  176. void STARPU_LU(lu_decomposition_pivot_no_stride)(TYPE **matA, unsigned *ipiv, unsigned size, unsigned ld, unsigned nblocks)
  177. {
  178. starpu_data_handle_t *dataAp = malloc(nblocks*nblocks*sizeof(starpu_data_handle_t));
  179. /* monitor and partition the A matrix into blocks :
  180. * one block is now determined by 2 unsigned (i,j) */
  181. unsigned bi, bj;
  182. for (bj = 0; bj < nblocks; bj++)
  183. for (bi = 0; bi < nblocks; bi++)
  184. {
  185. starpu_matrix_data_register(&dataAp[bi+nblocks*bj], 0,
  186. (uintptr_t)matA[bi+nblocks*bj], size/nblocks,
  187. size/nblocks, size/nblocks, sizeof(TYPE));
  188. }
  189. unsigned i;
  190. for (i = 0; i < size; i++)
  191. ipiv[i] = i;
  192. struct piv_s *piv_description = malloc(nblocks*sizeof(struct piv_s));
  193. unsigned block;
  194. for (block = 0; block < nblocks; block++)
  195. {
  196. piv_description[block].piv = ipiv;
  197. piv_description[block].first = block * (size / nblocks);
  198. piv_description[block].last = (block + 1) * (size / nblocks);
  199. }
  200. double timing;
  201. timing = dw_codelet_facto_pivot(dataAp, piv_description, nblocks, get_block_with_no_striding);
  202. FPRINTF(stderr, "Computation took (in ms)\n");
  203. FPRINTF(stderr, "%2.2f\n", timing/1000);
  204. unsigned n = starpu_matrix_get_nx(dataAp[0])*nblocks;
  205. double flop = (2.0f*n*n*n)/3.0f;
  206. FPRINTF(stderr, "Synthetic GFlops : %2.2f\n", (flop/timing/1000.0f));
  207. for (bj = 0; bj < nblocks; bj++)
  208. for (bi = 0; bi < nblocks; bi++)
  209. {
  210. starpu_data_unregister(dataAp[bi+nblocks*bj]);
  211. }
  212. }