xlu_implicit_pivot.c 8.1 KB

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