xlu_implicit.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. static void create_task_11(starpu_data_handle_t dataA, unsigned k)
  22. {
  23. int ret;
  24. struct starpu_task *task = starpu_task_create();
  25. task->cl = &cl11;
  26. /* which sub-data is manipulated ? */
  27. task->handles[0] = starpu_data_get_sub_data(dataA, 2, k, k);
  28. /* this is an important task */
  29. if (!no_prio)
  30. task->priority = STARPU_MAX_PRIO;
  31. ret = starpu_task_submit(task);
  32. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  33. }
  34. static void create_task_12(starpu_data_handle_t dataA, unsigned k, unsigned j)
  35. {
  36. int ret;
  37. struct starpu_task *task = starpu_task_create();
  38. task->cl = &cl12;
  39. /* which sub-data is manipulated ? */
  40. task->handles[0] = starpu_data_get_sub_data(dataA, 2, k, k);
  41. task->handles[1] = starpu_data_get_sub_data(dataA, 2, j, k);
  42. if (!no_prio && (j == k+1))
  43. task->priority = STARPU_MAX_PRIO;
  44. ret = starpu_task_submit(task);
  45. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  46. }
  47. static void create_task_21(starpu_data_handle_t dataA, unsigned k, unsigned i)
  48. {
  49. int ret;
  50. struct starpu_task *task = starpu_task_create();
  51. task->cl = &cl21;
  52. /* which sub-data is manipulated ? */
  53. task->handles[0] = starpu_data_get_sub_data(dataA, 2, k, k);
  54. task->handles[1] = starpu_data_get_sub_data(dataA, 2, k, i);
  55. if (!no_prio && (i == k+1))
  56. task->priority = STARPU_MAX_PRIO;
  57. ret = starpu_task_submit(task);
  58. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  59. }
  60. static void create_task_22(starpu_data_handle_t dataA, unsigned k, unsigned i, unsigned j)
  61. {
  62. int ret;
  63. struct starpu_task *task = starpu_task_create();
  64. task->cl = &cl22;
  65. /* which sub-data is manipulated ? */
  66. task->handles[0] = starpu_data_get_sub_data(dataA, 2, k, i);
  67. task->handles[1] = starpu_data_get_sub_data(dataA, 2, j, k);
  68. task->handles[2] = starpu_data_get_sub_data(dataA, 2, j, i);
  69. if (!no_prio && (i == k + 1) && (j == k +1) )
  70. task->priority = STARPU_MAX_PRIO;
  71. ret = starpu_task_submit(task);
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  73. }
  74. /*
  75. * code to bootstrap the factorization
  76. */
  77. static void dw_codelet_facto_v3(starpu_data_handle_t dataA, unsigned nblocks)
  78. {
  79. struct timeval start;
  80. struct timeval end;
  81. /* create all the DAG nodes */
  82. unsigned i,j,k;
  83. gettimeofday(&start, NULL);
  84. for (k = 0; k < nblocks; k++)
  85. {
  86. create_task_11(dataA, k);
  87. for (i = k+1; i<nblocks; i++)
  88. {
  89. create_task_12(dataA, k, i);
  90. create_task_21(dataA, k, i);
  91. }
  92. for (i = k+1; i<nblocks; i++)
  93. for (j = k+1; j<nblocks; j++)
  94. create_task_22(dataA, k, i, j);
  95. }
  96. /* stall the application until the end of computations */
  97. starpu_task_wait_for_all();
  98. gettimeofday(&end, NULL);
  99. double timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  100. FPRINTF(stderr, "Computation took (in ms)\n");
  101. FPRINTF(stdout, "%2.2f\n", timing/1000);
  102. unsigned n = starpu_matrix_get_nx(dataA);
  103. double flop = (2.0f*n*n*n)/3.0f;
  104. FPRINTF(stderr, "Synthetic GFlops : %2.2f\n", (flop/timing/1000.0f));
  105. }
  106. void STARPU_LU(lu_decomposition)(TYPE *matA, unsigned size, unsigned ld, unsigned nblocks)
  107. {
  108. starpu_data_handle_t dataA;
  109. /* monitor and partition the A matrix into blocks :
  110. * one block is now determined by 2 unsigned (i,j) */
  111. starpu_matrix_data_register(&dataA, 0, (uintptr_t)matA, ld, size, size, sizeof(TYPE));
  112. struct starpu_data_filter f =
  113. {
  114. .filter_func = starpu_vertical_block_filter_func,
  115. .nchildren = nblocks
  116. };
  117. struct starpu_data_filter f2 =
  118. {
  119. .filter_func = starpu_block_filter_func,
  120. .nchildren = nblocks
  121. };
  122. starpu_data_map_filters(dataA, 2, &f, &f2);
  123. dw_codelet_facto_v3(dataA, nblocks);
  124. /* gather all the data */
  125. starpu_data_unpartition(dataA, 0);
  126. starpu_data_unregister(dataA);
  127. }