xlu_implicit.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010 Mehdi Juhoor <mjuhoor@gmail.com>
  5. * Copyright (C) 2010 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. static void create_task_11(starpu_data_handle dataA, unsigned k, struct starpu_sched_ctx *sched_ctx)
  22. {
  23. struct starpu_task *task = starpu_task_create();
  24. task->cl = &cl11;
  25. /* which sub-data is manipulated ? */
  26. task->buffers[0].handle = starpu_data_get_sub_data(dataA, 2, k, k);
  27. task->buffers[0].mode = STARPU_RW;
  28. /* this is an important task */
  29. if (!no_prio)
  30. task->priority = STARPU_MAX_PRIO;
  31. if(sched_ctx == NULL)
  32. starpu_task_submit(task);
  33. else
  34. starpu_task_submit_to_ctx(task, sched_ctx);
  35. }
  36. static void create_task_12(starpu_data_handle dataA, unsigned k, unsigned j, struct starpu_sched_ctx *sched_ctx)
  37. {
  38. struct starpu_task *task = starpu_task_create();
  39. task->cl = &cl12;
  40. /* which sub-data is manipulated ? */
  41. task->buffers[0].handle = starpu_data_get_sub_data(dataA, 2, k, k);
  42. task->buffers[0].mode = STARPU_R;
  43. task->buffers[1].handle = starpu_data_get_sub_data(dataA, 2, j, k);
  44. task->buffers[1].mode = STARPU_RW;
  45. if (!no_prio && (j == k+1))
  46. task->priority = STARPU_MAX_PRIO;
  47. if(sched_ctx == NULL)
  48. starpu_task_submit(task);
  49. else
  50. starpu_task_submit_to_ctx(task, sched_ctx);
  51. }
  52. static void create_task_21(starpu_data_handle dataA, unsigned k, unsigned i, struct starpu_sched_ctx *sched_ctx)
  53. {
  54. struct starpu_task *task = starpu_task_create();
  55. task->cl = &cl21;
  56. /* which sub-data is manipulated ? */
  57. task->buffers[0].handle = starpu_data_get_sub_data(dataA, 2, k, k);
  58. task->buffers[0].mode = STARPU_R;
  59. task->buffers[1].handle = starpu_data_get_sub_data(dataA, 2, k, i);
  60. task->buffers[1].mode = STARPU_RW;
  61. if (!no_prio && (i == k+1))
  62. task->priority = STARPU_MAX_PRIO;
  63. if(sched_ctx == NULL)
  64. starpu_task_submit(task);
  65. else
  66. starpu_task_submit_to_ctx(task, sched_ctx);
  67. }
  68. static void create_task_22(starpu_data_handle dataA, unsigned k, unsigned i, unsigned j, struct starpu_sched_ctx *sched_ctx)
  69. {
  70. struct starpu_task *task = starpu_task_create();
  71. task->cl = &cl22;
  72. /* which sub-data is manipulated ? */
  73. task->buffers[0].handle = starpu_data_get_sub_data(dataA, 2, k, i);
  74. task->buffers[0].mode = STARPU_R;
  75. task->buffers[1].handle = starpu_data_get_sub_data(dataA, 2, j, k);
  76. task->buffers[1].mode = STARPU_R;
  77. task->buffers[2].handle = starpu_data_get_sub_data(dataA, 2, j, i);
  78. task->buffers[2].mode = STARPU_RW;
  79. if (!no_prio && (i == k + 1) && (j == k +1) )
  80. task->priority = STARPU_MAX_PRIO;
  81. if(sched_ctx == NULL)
  82. starpu_task_submit(task);
  83. else
  84. starpu_task_submit_to_ctx(task, sched_ctx);
  85. }
  86. /*
  87. * code to bootstrap the factorization
  88. */
  89. static double dw_codelet_facto_v3(starpu_data_handle dataA, unsigned lu_nblocks, struct starpu_sched_ctx *sched_ctx)
  90. {
  91. struct timeval start;
  92. struct timeval end;
  93. /* create all the DAG nodes */
  94. unsigned i,j,k;
  95. gettimeofday(&start, NULL);
  96. for (k = 0; k < lu_nblocks; k++)
  97. {
  98. create_task_11(dataA, k, sched_ctx);
  99. for (i = k+1; i<lu_nblocks; i++)
  100. {
  101. create_task_12(dataA, k, i, sched_ctx);
  102. create_task_21(dataA, k, i, sched_ctx);
  103. }
  104. for (i = k+1; i<lu_nblocks; i++)
  105. for (j = k+1; j<lu_nblocks; j++)
  106. create_task_22(dataA, k, i, j, sched_ctx);
  107. }
  108. /* stall the application until the end of computations */
  109. if(sched_ctx == NULL)
  110. starpu_task_wait_for_all();
  111. else
  112. starpu_wait_for_all_tasks_of_sched_ctx(sched_ctx);
  113. gettimeofday(&end, NULL);
  114. double timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  115. unsigned n = starpu_matrix_get_nx(dataA);
  116. double flop = (2.0f*n*n*n)/3.0f;
  117. return (flop/timing/1000.0f);
  118. }
  119. double STARPU_LU(lu_decomposition)(TYPE *matA, unsigned size, unsigned ld, unsigned lu_nblocks, struct starpu_sched_ctx *sched_ctx)
  120. {
  121. starpu_data_handle dataA;
  122. /* monitor and partition the A matrix into blocks :
  123. * one block is now determined by 2 unsigned (i,j) */
  124. starpu_matrix_data_register(&dataA, 0, (uintptr_t)matA, ld, size, size, sizeof(TYPE));
  125. struct starpu_data_filter f;
  126. f.filter_func = starpu_vertical_block_filter_func;
  127. f.nchildren = lu_nblocks;
  128. f.get_nchildren = NULL;
  129. f.get_child_ops = NULL;
  130. struct starpu_data_filter f2;
  131. f2.filter_func = starpu_block_filter_func;
  132. f2.nchildren = lu_nblocks;
  133. f2.get_nchildren = NULL;
  134. f2.get_child_ops = NULL;
  135. starpu_data_map_filters(dataA, 2, &f, &f2);
  136. double gflops = dw_codelet_facto_v3(dataA, lu_nblocks, sched_ctx);
  137. /* gather all the data */
  138. starpu_data_unpartition(dataA, 0);
  139. starpu_data_unregister(dataA);
  140. return gflops;
  141. }