regression_based_check.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2020 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_W}
  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_W}
  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_data_unregister(handle);
  91. }
  92. static void compare_performance(int size, struct starpu_codelet *codelet, struct starpu_task *compar_task)
  93. {
  94. unsigned i;
  95. unsigned niter = 100;
  96. starpu_data_handle_t handle;
  97. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, size, sizeof(int));
  98. struct starpu_task *tasks[niter];
  99. for (i = 0; i < niter; i++)
  100. {
  101. struct starpu_task *task = starpu_task_create();
  102. task->cl = codelet;
  103. task->handles[0] = handle;
  104. task->synchronous = 1;
  105. /* We will destroy the task structure by hand so that we can
  106. * query the profiling info before the task is destroyed. */
  107. task->destroy = 0;
  108. tasks[i] = task;
  109. int ret = starpu_task_submit(task);
  110. if (STARPU_UNLIKELY(ret == -ENODEV))
  111. {
  112. FPRINTF(stderr, "No worker may execute this task\n");
  113. exit(0);
  114. }
  115. }
  116. starpu_data_unregister(handle);
  117. starpu_task_wait_for_all();
  118. double length_sum = 0.0;
  119. for (i = 0; i < niter; i++)
  120. {
  121. struct starpu_task *task = tasks[i];
  122. struct starpu_profiling_task_info *info = task->profiling_info;
  123. /* How long was the task execution ? */
  124. length_sum += starpu_timing_timespec_delay_us(&info->start_time, &info->end_time);
  125. /* We don't need the task structure anymore */
  126. starpu_task_destroy(task);
  127. }
  128. /* Display the occupancy of all workers during the test */
  129. unsigned worker;
  130. for (worker = 0; worker < starpu_worker_get_count(); worker++)
  131. {
  132. struct starpu_profiling_worker_info worker_info;
  133. int ret = starpu_profiling_worker_get_info(worker, &worker_info);
  134. STARPU_ASSERT(!ret);
  135. char workername[128];
  136. starpu_worker_get_name(worker, workername, sizeof(workername));
  137. unsigned nimpl;
  138. if (starpu_worker_get_type(worker)==STARPU_CPU_WORKER)
  139. {
  140. FPRINTF(stdout, "\n Worker :%s ::::::::::\n\n", workername);
  141. for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  142. {
  143. FPRINTF(stdout, "Expected time for %d on %s (impl %u): %f, Measured time: %f\n",
  144. size, workername, nimpl,starpu_task_expected_length(compar_task, starpu_worker_get_perf_archtype(worker, compar_task->sched_ctx), nimpl), ((length_sum)/niter));
  145. }
  146. }
  147. }
  148. }
  149. int main(int argc, char **argv)
  150. {
  151. /* Enable profiling */
  152. starpu_profiling_status_set(STARPU_PROFILING_ENABLE);
  153. struct starpu_conf conf;
  154. starpu_data_handle_t handle;
  155. int ret;
  156. starpu_conf_init(&conf);
  157. conf.sched_policy_name = "eager";
  158. conf.calibrate = 2;
  159. ret = starpu_initialize(&conf, &argc, &argv);
  160. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  161. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  162. int size;
  163. for (size = STARTlin; size < END; size *= 2)
  164. {
  165. /* Use a linear regression */
  166. test_memset(size, &memset_cl);
  167. }
  168. for (size = START; size < END; size *= 2)
  169. {
  170. /* Use a non-linear regression */
  171. test_memset(size, &nl_memset_cl);
  172. }
  173. ret = starpu_task_wait_for_all();
  174. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  175. starpu_shutdown();
  176. /* Test Phase */
  177. starpu_conf_init(&conf);
  178. conf.sched_policy_name = "eager";
  179. conf.calibrate = 0;
  180. ret = starpu_initialize(&conf, &argc, &argv);
  181. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  182. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  183. /* Now create a dummy task just to estimate its duration according to the regression */
  184. size = 1234567;
  185. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, size, sizeof(int));
  186. struct starpu_task *task = starpu_task_create();
  187. task->cl = &memset_cl;
  188. task->handles[0] = handle;
  189. task->destroy = 0;
  190. FPRINTF(stdout, "\n ////linear regression results////\n");
  191. compare_performance(size, &memset_cl, task);
  192. task->cl = &nl_memset_cl;
  193. FPRINTF(stdout, "\n ////non linear regression results////\n");
  194. compare_performance(size, &nl_memset_cl, task);
  195. starpu_task_destroy(task);
  196. starpu_data_unregister(handle);
  197. starpu_shutdown();
  198. return EXIT_SUCCESS;
  199. }