test_papi.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_perfmodel energy_model=
  60. {
  61. .type = STARPU_HISTORY_BASED,
  62. .symbol = "energy_model",
  63. };
  64. static struct starpu_codelet memset_cl=
  65. {
  66. .cpu_funcs = {memset0_cpu, memset_cpu},
  67. .cpu_funcs_name = {"memset0_cpu", "memset_cpu"},
  68. .model = &my_perfmodel,
  69. .energy_model = &energy_model,
  70. .nbuffers = 1,
  71. .modes = {STARPU_W}
  72. };
  73. static void test_memset(int nelems, struct starpu_codelet *codelet)
  74. {
  75. ntasks = starpu_cpu_worker_get_count() * 30;
  76. int loop;
  77. struct starpu_task *task;
  78. starpu_data_handle_t tab_handle[ntasks];
  79. for (loop = 0; loop < ntasks; loop++)
  80. {
  81. task = starpu_task_create();
  82. starpu_vector_data_register(&tab_handle[loop], -1, (uintptr_t)NULL, nelems, sizeof(int));
  83. task->cl = codelet;
  84. task->where = STARPU_CPU;
  85. task->handles[0] = tab_handle[loop];
  86. int ret = starpu_task_submit(task);
  87. if (ret == -ENODEV)
  88. exit(STARPU_TEST_SKIPPED);
  89. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  90. }
  91. for (loop = 0; loop < ntasks; loop++)
  92. {
  93. starpu_data_unregister(tab_handle[loop]);
  94. }
  95. }
  96. int main(int argc, char **argv)
  97. {
  98. starpu_profiling_status_set(STARPU_PROFILING_ENABLE);
  99. struct starpu_conf conf;
  100. starpu_data_handle_t handle;
  101. int ret;
  102. int retval;
  103. int size;
  104. starpu_conf_init(&conf);
  105. conf.sched_policy_name = "eager";
  106. ret = starpu_initialize(&conf, &argc, &argv);
  107. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  108. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  109. for (size = STARTlin; size < END; size *= 2)
  110. {
  111. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, size, sizeof(int));
  112. struct starpu_task *task = starpu_task_create();
  113. task->cl = &memset_cl;
  114. task->handles[0] = handle;
  115. task->synchronous = 1;
  116. task->destroy = 0;
  117. /* Start counting */
  118. if ( (retval = starpu_energy_start()) != 0)
  119. ERROR_RETURN(retval);
  120. test_memset(size, &memset_cl);
  121. /* Stop counting and store the values into the array */
  122. if ( (retval = starpu_energy_stop(&energy_model, task, ntasks)) != 0)
  123. ERROR_RETURN(retval);
  124. starpu_task_destroy(task);
  125. starpu_data_unregister(handle);
  126. }
  127. starpu_shutdown();
  128. return EXIT_SUCCESS;
  129. }