test_papi.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*****************************************************************************
  2. * This example shows how to use PAPI_add_event, PAPI_start, PAPI_read, *
  3. * PAPI_stop and PAPI_remove_event. *
  4. ******************************************************************************/
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <starpu.h>
  9. #include <starpu_perfmodel.h>
  10. #include <starpu_scheduler.h>
  11. #include "../helper.h"
  12. /*
  13. * A multi-implementation benchmark with dmda scheduler
  14. * we aim to test the energy model with the different size of gamma
  15. * for large size of gamma, dmda choose the second implementation which consumes less energy
  16. * otherwise, it choose the first implementtaion which minimizes the execution time
  17. */
  18. #define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
  19. #define STARTlin 131072
  20. #define START 1024
  21. #ifdef STARPU_QUICK_CHECK
  22. #define END 1048576
  23. #else
  24. #define END 16777216
  25. #endif
  26. int ntasks;
  27. /* First implementation */
  28. void memset0_cpu(void *descr[], void *arg)
  29. {
  30. (void)arg;
  31. STARPU_SKIP_IF_VALGRIND;
  32. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  33. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  34. unsigned i;
  35. starpu_usleep(100);
  36. for (i=0; i<n ; i++)
  37. {
  38. ptr[0] += i;
  39. }
  40. }
  41. /*Second implementation */
  42. void memset_cpu(void *descr[], void *arg)
  43. {
  44. (void)arg;
  45. STARPU_SKIP_IF_VALGRIND;
  46. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  47. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  48. int i;
  49. for (i=0; i<6.5*n ; i++)
  50. {
  51. ptr[0] += i;
  52. }
  53. }
  54. static struct starpu_perfmodel my_perfmodel=
  55. {
  56. .type = STARPU_HISTORY_BASED,
  57. .symbol = "my_perfmodel",
  58. };
  59. static struct starpu_codelet memset_cl=
  60. {
  61. .cpu_funcs = {memset0_cpu, memset_cpu},
  62. .cpu_funcs_name = {"memset0_cpu", "memset_cpu"},
  63. .model = &my_perfmodel,
  64. .energy_model = &my_perfmodel,
  65. .nbuffers = 1,
  66. .modes = {STARPU_W}
  67. };
  68. static void test_memset(int nelems, struct starpu_codelet *codelet)
  69. {
  70. ntasks = starpu_cpu_worker_get_count() * 30;
  71. int loop;
  72. struct starpu_task *task;
  73. // TODO: faire plutôt un tableau[nloops] de handles, et on fait unregister dans une boucle séparée, pour laisser les tâches tourner en parallèle
  74. starpu_data_handle_t tab_handle[ntasks];
  75. for (loop = 0; loop < ntasks; loop++)
  76. {
  77. task = starpu_task_create();
  78. starpu_vector_data_register(&tab_handle[loop], -1, (uintptr_t)NULL, nelems, sizeof(int));
  79. task->cl = codelet;
  80. task->where = STARPU_CPU;
  81. task->handles[0] = tab_handle[loop];
  82. int ret = starpu_task_submit(task);
  83. if (ret == -ENODEV)
  84. exit(STARPU_TEST_SKIPPED);
  85. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  86. }
  87. for (loop = 0; loop < ntasks; loop++)
  88. {
  89. starpu_data_unregister(tab_handle[loop]);
  90. }
  91. }
  92. int main(int argc, char **argv)
  93. {
  94. starpu_profiling_status_set(STARPU_PROFILING_ENABLE);
  95. struct starpu_conf conf;
  96. starpu_data_handle_t handle;
  97. int ret;
  98. int retval;
  99. int size;
  100. starpu_conf_init(&conf);
  101. conf.sched_policy_name = "eager";
  102. ret = starpu_initialize(&conf, &argc, &argv);
  103. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  104. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  105. for (size = STARTlin; size < END; size *= 2)
  106. {
  107. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, size, sizeof(int));
  108. struct starpu_task *task = starpu_task_create();
  109. task->cl = &memset_cl;
  110. task->handles[0] = handle;
  111. task->synchronous = 1;
  112. task->destroy = 0;
  113. /* Start counting */
  114. if ( (retval = starpu_energy_start()) != 0)
  115. ERROR_RETURN(retval);
  116. test_memset(size, &memset_cl);
  117. /* Stop counting and store the values into the array */
  118. if ( (retval = starpu_energy_stop(&my_perfmodel, task, ntasks)) != 0)
  119. ERROR_RETURN(retval);
  120. starpu_task_destroy(task);
  121. starpu_data_unregister(handle);
  122. }
  123. starpu_shutdown();
  124. return EXIT_SUCCESS;
  125. }