regression_based_check.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2011 Télécom-SudParis
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <assert.h>
  19. #include <starpu_scheduler.h>
  20. #include <unistd.h>
  21. #include "../helper.h"
  22. /*
  23. * - Calibrate the linear model only for large sizes: STARTline 1048576
  24. * - Separate the test_memset loop in two loops:
  25. * - linear: start from 1048576
  26. * - non-linear: keep start at 1024
  27. */
  28. #define STARTlin 131072
  29. #define START 1024
  30. #ifdef STARPU_QUICK_CHECK
  31. #define END 1048576
  32. #else
  33. #define END 16777216
  34. #endif
  35. void memset_cpu(void *descr[], void *arg)
  36. {
  37. (void)arg;
  38. STARPU_SKIP_IF_VALGRIND;
  39. unsigned *ptr = (unsigned *)STARPU_VECTOR_GET_PTR(descr[0]);
  40. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  41. unsigned i;
  42. starpu_usleep(1000);
  43. for (i=0; i<n ; i++)
  44. {
  45. ptr[0] += i;
  46. }
  47. }
  48. static struct starpu_perfmodel model =
  49. {
  50. .type = STARPU_REGRESSION_BASED,
  51. .symbol = "memset_regression_based"
  52. };
  53. static struct starpu_perfmodel nl_model =
  54. {
  55. .type = STARPU_NL_REGRESSION_BASED,
  56. .symbol = "non_linear_memset_regression_based"
  57. };
  58. static struct starpu_codelet memset_cl =
  59. {
  60. .cpu_funcs = {memset_cpu},
  61. .cpu_funcs_name = {"memset_cpu"},
  62. .model = &model,
  63. .nbuffers = 1,
  64. .modes = {STARPU_SCRATCH}
  65. };
  66. static struct starpu_codelet nl_memset_cl =
  67. {
  68. .cpu_funcs = {memset_cpu},
  69. .cpu_funcs_name = {"memset_cpu"},
  70. .model = &nl_model,
  71. .nbuffers = 1,
  72. .modes = {STARPU_SCRATCH}
  73. };
  74. static void test_memset(int nelems, struct starpu_codelet *codelet)
  75. {
  76. int nloops = 100;
  77. int loop;
  78. starpu_data_handle_t handle;
  79. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, nelems, sizeof(int));
  80. for (loop = 0; loop < nloops; loop++)
  81. {
  82. struct starpu_task *task = starpu_task_create();
  83. task->cl = codelet;
  84. task->handles[0] = handle;
  85. int ret = starpu_task_submit(task);
  86. if (ret == -ENODEV)
  87. exit(STARPU_TEST_SKIPPED);
  88. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  89. }
  90. starpu_do_schedule();
  91. starpu_data_unregister(handle);
  92. }
  93. static void compare_performance(int size, struct starpu_codelet *codelet, struct starpu_task *compar_task)
  94. {
  95. unsigned i;
  96. unsigned niter = 100;
  97. starpu_data_handle_t handle;
  98. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, size, sizeof(int));
  99. struct starpu_task *tasks[niter];
  100. for (i = 0; i < niter; i++)
  101. {
  102. struct starpu_task *task = starpu_task_create();
  103. task->cl = codelet;
  104. task->handles[0] = handle;
  105. task->synchronous = 1;
  106. /* We will destroy the task structure by hand so that we can
  107. * query the profiling info before the task is destroyed. */
  108. task->destroy = 0;
  109. tasks[i] = task;
  110. int ret = starpu_task_submit(task);
  111. if (STARPU_UNLIKELY(ret == -ENODEV))
  112. {
  113. FPRINTF(stderr, "No worker may execute this task\n");
  114. exit(0);
  115. }
  116. }
  117. starpu_data_unregister(handle);
  118. starpu_task_wait_for_all();
  119. double length_sum = 0.0;
  120. for (i = 0; i < niter; i++)
  121. {
  122. struct starpu_task *task = tasks[i];
  123. struct starpu_profiling_task_info *info = task->profiling_info;
  124. /* How long was the task execution ? */
  125. length_sum += starpu_timing_timespec_delay_us(&info->start_time, &info->end_time);
  126. /* We don't need the task structure anymore */
  127. starpu_task_destroy(task);
  128. }
  129. /* Display the occupancy of all workers during the test */
  130. unsigned worker;
  131. for (worker = 0; worker < starpu_worker_get_count(); worker++)
  132. {
  133. struct starpu_profiling_worker_info worker_info;
  134. int ret = starpu_profiling_worker_get_info(worker, &worker_info);
  135. STARPU_ASSERT(!ret);
  136. char workername[128];
  137. starpu_worker_get_name(worker, workername, sizeof(workername));
  138. unsigned nimpl;
  139. if (starpu_worker_get_type(worker)==STARPU_CPU_WORKER)
  140. {
  141. FPRINTF(stdout, "\n Worker :%s ::::::::::\n\n", workername);
  142. for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  143. {
  144. FPRINTF(stdout, "Expected time for %d on %s (impl %u): %f, Measured time: %f\n",
  145. size, workername, nimpl,starpu_task_expected_length(compar_task, starpu_worker_get_perf_archtype(worker, compar_task->sched_ctx), nimpl), ((length_sum)/niter));
  146. }
  147. }
  148. }
  149. }
  150. int main(int argc, char **argv)
  151. {
  152. /* Enable profiling */
  153. starpu_profiling_status_set(STARPU_PROFILING_ENABLE);
  154. struct starpu_conf conf;
  155. starpu_data_handle_t handle;
  156. int ret;
  157. starpu_conf_init(&conf);
  158. conf.sched_policy_name = "eager";
  159. conf.calibrate = 2;
  160. ret = starpu_initialize(&conf, &argc, &argv);
  161. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  162. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  163. int size;
  164. for (size = STARTlin; size < END; size *= 2)
  165. {
  166. /* Use a linear regression */
  167. test_memset(size, &memset_cl);
  168. }
  169. for (size = START; size < END; size *= 2)
  170. {
  171. /* Use a non-linear regression */
  172. test_memset(size, &nl_memset_cl);
  173. }
  174. ret = starpu_task_wait_for_all();
  175. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  176. starpu_shutdown();
  177. /* Test Phase */
  178. starpu_conf_init(&conf);
  179. conf.sched_policy_name = "eager";
  180. conf.calibrate = 0;
  181. ret = starpu_initialize(&conf, &argc, &argv);
  182. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  183. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  184. /* Now create a dummy task just to estimate its duration according to the regression */
  185. size = 1234567;
  186. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, size, sizeof(int));
  187. struct starpu_task *task = starpu_task_create();
  188. task->cl = &memset_cl;
  189. task->handles[0] = handle;
  190. task->destroy = 0;
  191. FPRINTF(stdout, "\n ////linear regression results////\n");
  192. compare_performance(size, &memset_cl, task);
  193. task->cl = &nl_memset_cl;
  194. FPRINTF(stdout, "\n ////non linear regression results////\n");
  195. compare_performance(size, &nl_memset_cl, task);
  196. starpu_task_destroy(task);
  197. starpu_data_unregister(handle);
  198. starpu_shutdown();
  199. return EXIT_SUCCESS;
  200. }