xlu_implicit.c 4.2 KB

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