test_papi.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. starpu_data_handle_t tab_handle[ntasks];
  74. for (loop = 0; loop < ntasks; loop++)
  75. {
  76. task = starpu_task_create();
  77. starpu_vector_data_register(&tab_handle[loop], -1, (uintptr_t)NULL, nelems, sizeof(int));
  78. task->cl = codelet;
  79. task->where = STARPU_CPU;
  80. task->handles[0] = tab_handle[loop];
  81. int ret = starpu_task_submit(task);
  82. if (ret == -ENODEV)
  83. exit(STARPU_TEST_SKIPPED);
  84. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  85. }
  86. for (loop = 0; loop < ntasks; loop++)
  87. {
  88. starpu_data_unregister(tab_handle[loop]);
  89. }
  90. }
  91. int main(int argc, char **argv)
  92. {
  93. starpu_profiling_status_set(STARPU_PROFILING_ENABLE);
  94. struct starpu_conf conf;
  95. starpu_data_handle_t handle;
  96. int ret;
  97. int retval;
  98. int size;
  99. starpu_conf_init(&conf);
  100. conf.sched_policy_name = "eager";
  101. ret = starpu_initialize(&conf, &argc, &argv);
  102. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  103. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  104. for (size = STARTlin; size < END; size *= 2)
  105. {
  106. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, size, sizeof(int));
  107. struct starpu_task *task = starpu_task_create();
  108. task->cl = &memset_cl;
  109. task->handles[0] = handle;
  110. task->synchronous = 1;
  111. task->destroy = 0;
  112. /* Start counting */
  113. if ( (retval = starpu_energy_start()) != 0)
  114. ERROR_RETURN(retval);
  115. test_memset(size, &memset_cl);
  116. /* Stop counting and store the values into the array */
  117. if ( (retval = starpu_energy_stop(&my_perfmodel, task, ntasks)) != 0)
  118. ERROR_RETURN(retval);
  119. starpu_task_destroy(task);
  120. starpu_data_unregister(handle);
  121. }
  122. starpu_shutdown();
  123. return EXIT_SUCCESS;
  124. }