test_prio.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2015 Université de Bordeaux
  4. * Copyright (C) 2010 Mehdi Juhoor <mjuhoor@gmail.com>
  5. * Copyright (C) 2010, 2011, 2012, 2013 CNRS
  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 "cholesky.h"
  19. /* to test with dmda* schedulers */
  20. static int _test_prio(starpu_data_handle_t dataA, unsigned nblocks)
  21. {
  22. int ret;
  23. double start;
  24. double end;
  25. unsigned i,j,k;
  26. unsigned long n = starpu_matrix_get_nx(dataA);
  27. unsigned long nn = n/nblocks;
  28. int prio_level = noprio?STARPU_DEFAULT_PRIO:STARPU_MAX_PRIO;
  29. starpu_fxt_start_profiling();
  30. start = starpu_timing_now();
  31. /* create all the DAG nodes */
  32. for (k = 0; k < nblocks; k++)
  33. {
  34. starpu_data_handle_t sdatakk = starpu_data_get_sub_data(dataA, 2, k, k);
  35. ret = starpu_task_insert(&cl11,
  36. STARPU_PRIORITY, k,
  37. STARPU_RW, sdatakk,
  38. STARPU_FLOPS, (double) FLOPS_SPOTRF(nn),
  39. STARPU_TAG_ONLY, TAG11(k),
  40. 0);
  41. if (ret == -ENODEV) return 77;
  42. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  43. for (j = 0; j<nblocks; j++)
  44. {
  45. starpu_data_handle_t sdatakj = starpu_data_get_sub_data(dataA, 2, k, j);
  46. ret = starpu_task_insert(&cl21,
  47. STARPU_PRIORITY, k+j,
  48. STARPU_R, sdatakj,
  49. STARPU_RW, sdatakj,
  50. STARPU_FLOPS, (double) FLOPS_STRSM(nn, nn),
  51. STARPU_TAG_ONLY, TAG21(k,j),
  52. 0);
  53. if (ret == -ENODEV) return 77;
  54. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  55. }
  56. }
  57. starpu_task_wait_for_all();
  58. end = starpu_timing_now();
  59. starpu_fxt_stop_profiling();
  60. double timing = end - start;
  61. double flop = FLOPS_SPOTRF(n);
  62. PRINTF("# size\tms\tGFlops");
  63. PRINTF("\n");
  64. PRINTF("%lu\t%.0f\t%.1f", n, timing/1000, (flop/timing/1000.0f));
  65. PRINTF("\n");
  66. return 0;
  67. }
  68. static int test_prio(float *matA, unsigned size, unsigned ld, unsigned nblocks)
  69. {
  70. starpu_data_handle_t dataA;
  71. /* monitor and partition the A matrix into blocks :
  72. * one block is now determined by 2 unsigned (i,j) */
  73. starpu_matrix_data_register(&dataA, STARPU_MAIN_RAM, (uintptr_t)matA, ld, size, size, sizeof(float));
  74. struct starpu_data_filter f =
  75. {
  76. .filter_func = starpu_matrix_filter_vertical_block,
  77. .nchildren = nblocks
  78. };
  79. struct starpu_data_filter f2 =
  80. {
  81. .filter_func = starpu_matrix_filter_block,
  82. .nchildren = nblocks
  83. };
  84. starpu_data_map_filters(dataA, 2, &f, &f2);
  85. int ret = _test_prio(dataA, nblocks);
  86. starpu_data_unpartition(dataA, STARPU_MAIN_RAM);
  87. starpu_data_unregister(dataA);
  88. return ret;
  89. }
  90. static void execute_test_prio(unsigned size, unsigned nblocks)
  91. {
  92. int ret;
  93. float *mat = NULL;
  94. unsigned i,j;
  95. #ifndef STARPU_SIMGRID
  96. starpu_malloc((void **)&mat, (size_t)size*size*sizeof(float));
  97. for (i = 0; i < size; i++)
  98. {
  99. for (j = 0; j < size; j++)
  100. {
  101. mat[j +i*size] = (1.0f/(1.0f+i+j)) + ((i == j)?1.0f*size:0.0f);
  102. /* mat[j +i*size] = ((i == j)?1.0f*size:0.0f); */
  103. }
  104. }
  105. #endif
  106. ret = test_prio(mat, size, size, nblocks);
  107. starpu_free(mat);
  108. }
  109. int main(int argc, char **argv)
  110. {
  111. /* create a simple definite positive symetric matrix example
  112. *
  113. * Hilbert matrix : h(i,j) = 1/(i+j+1)
  114. * */
  115. parse_args(argc, argv);
  116. int ret;
  117. ret = starpu_init(NULL);
  118. starpu_fxt_stop_profiling();
  119. if (ret == -ENODEV)
  120. return 77;
  121. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  122. #ifdef STARPU_USE_CUDA
  123. initialize_chol_model(&chol_model_11,"chol_model_11",cpu_chol_task_11_cost,cuda_chol_task_11_cost);
  124. initialize_chol_model(&chol_model_21,"chol_model_21",cpu_chol_task_21_cost,cuda_chol_task_21_cost);
  125. initialize_chol_model(&chol_model_22,"chol_model_22",cpu_chol_task_22_cost,cuda_chol_task_22_cost);
  126. #else
  127. initialize_chol_model(&chol_model_11,"chol_model_11",cpu_chol_task_11_cost,NULL);
  128. initialize_chol_model(&chol_model_21,"chol_model_21",cpu_chol_task_21_cost,NULL);
  129. initialize_chol_model(&chol_model_22,"chol_model_22",cpu_chol_task_22_cost,NULL);
  130. #endif
  131. starpu_cublas_init();
  132. execute_test_prio(size, nblocks);
  133. starpu_cublas_shutdown();
  134. starpu_shutdown();
  135. return ret;
  136. }