perf_knobs_03.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2019-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include <assert.h>
  18. #include <string.h>
  19. #define NTASKS 100
  20. volatile int task_count[2];
  21. void cpu_func(void *buffer[], void *cl_arg)
  22. {
  23. (void)buffer;
  24. (void)cl_arg;
  25. int workerid = starpu_worker_get_id();
  26. STARPU_ASSERT(workerid == 0 || workerid == 1);
  27. task_count[workerid]++;
  28. }
  29. int main(int argc, char **argv)
  30. {
  31. int ret;
  32. struct starpu_conf conf;
  33. starpu_conf_init(&conf);
  34. starpu_conf_noworker(&conf);
  35. conf.ncpus = 2;
  36. {
  37. const char *sched_pol_name = starpu_getenv("STARPU_SCHED");
  38. if (sched_pol_name != NULL && strcmp(sched_pol_name, "prio") != 0)
  39. {
  40. fprintf(stderr, "example uses 'prio' scheduling policy.\n");
  41. return 77;
  42. }
  43. }
  44. conf.sched_policy_name = "prio";
  45. ret = starpu_initialize(&conf, &argc, &argv);
  46. if (ret == -ENODEV)
  47. return 77;
  48. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  49. if (starpu_cpu_worker_get_count() != 2
  50. || starpu_cuda_worker_get_count() != 0
  51. || starpu_opencl_worker_get_count() != 0
  52. || starpu_mic_worker_get_count() != 0
  53. || starpu_mpi_ms_worker_get_count() != 0)
  54. {
  55. starpu_shutdown();
  56. fprintf(stderr, "example needs exactly two cpu cores.\n");
  57. return 77;
  58. }
  59. {
  60. const char * const max_prio_knob_name = "starpu.task.s_max_priority_cap_knob";
  61. const char * const min_prio_knob_name = "starpu.task.s_min_priority_cap_knob";
  62. const char * const knob_scope_name = "per_scheduler";
  63. const char * const knob_type_name = "int32";
  64. int32_t max_prio_val;
  65. int32_t min_prio_val;
  66. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  67. const int max_prio_id = starpu_perf_knob_name_to_id(scope_id, max_prio_knob_name);
  68. STARPU_ASSERT(starpu_perf_knob_get_type_id(max_prio_id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  69. const int min_prio_id = starpu_perf_knob_name_to_id(scope_id, min_prio_knob_name);
  70. STARPU_ASSERT(starpu_perf_knob_get_type_id(min_prio_id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  71. printf("%s:\n", max_prio_knob_name);
  72. max_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(max_prio_id, "prio");
  73. printf("- %d\n", max_prio_val);
  74. printf("%s:\n", min_prio_knob_name);
  75. min_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(min_prio_id, "prio");
  76. printf("- %d\n", min_prio_val);
  77. STARPU_ASSERT (max_prio_val >= min_prio_val);
  78. if (min_prio_val > 0)
  79. {
  80. starpu_perf_knob_set_per_scheduler_int32_value(min_prio_id, "prio", 0);
  81. starpu_perf_knob_set_per_scheduler_int32_value(max_prio_id, "prio", 0);
  82. }
  83. else
  84. {
  85. starpu_perf_knob_set_per_scheduler_int32_value(max_prio_id, "prio", 0);
  86. starpu_perf_knob_set_per_scheduler_int32_value(min_prio_id, "prio", 0);
  87. }
  88. printf("%s:\n", max_prio_knob_name);
  89. max_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(max_prio_id, "prio");
  90. printf("- %d\n", max_prio_val);
  91. printf("%s:\n", min_prio_knob_name);
  92. min_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(min_prio_id, "prio");
  93. printf("- %d\n", min_prio_val);
  94. STARPU_ASSERT (max_prio_val == 0);
  95. STARPU_ASSERT (min_prio_val == 0);
  96. }
  97. {
  98. const char * const knob_name = "starpu.worker.w_enable_worker_knob";
  99. const char * const knob_scope_name = "per_worker";
  100. const char * const knob_type_name = "int32";
  101. int32_t val;
  102. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  103. const int id = starpu_perf_knob_name_to_id(scope_id, knob_name);
  104. STARPU_ASSERT(starpu_perf_knob_get_type_id(id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  105. struct starpu_codelet cl =
  106. {
  107. .cpu_funcs = {cpu_func}
  108. };
  109. task_count[0] = 0;
  110. task_count[1] = 0;
  111. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  112. STARPU_ASSERT(val == 1);
  113. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  114. STARPU_ASSERT(val == 1);
  115. starpu_perf_knob_set_per_worker_int32_value(id, 1, 0);
  116. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  117. STARPU_ASSERT(val == 0);
  118. int i;
  119. for (i=0; i<NTASKS; i++)
  120. {
  121. starpu_task_insert(&cl, 0);
  122. }
  123. starpu_task_wait_for_all();
  124. STARPU_ASSERT(task_count[0] == NTASKS);
  125. STARPU_ASSERT(task_count[1] == 0);
  126. task_count[0] = 0;
  127. starpu_perf_knob_set_per_worker_int32_value(id, 1, 1);
  128. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  129. STARPU_ASSERT(val == 1);
  130. starpu_perf_knob_set_per_worker_int32_value(id, 0, 0);
  131. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  132. STARPU_ASSERT(val == 0);
  133. for (i=0; i<NTASKS; i++)
  134. {
  135. starpu_task_insert(&cl, 0);
  136. }
  137. starpu_task_wait_for_all();
  138. STARPU_ASSERT(task_count[0] == 0);
  139. STARPU_ASSERT(task_count[1] == NTASKS);
  140. starpu_perf_knob_set_per_worker_int32_value(id, 0, 1);
  141. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  142. STARPU_ASSERT(val == 1);
  143. }
  144. starpu_shutdown();
  145. return 0;
  146. }