perf_knobs_03.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2019-2020 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. fprintf(stderr, "example needs exactly two cpu cores.\n");
  56. return 77;
  57. }
  58. {
  59. const char * const max_prio_knob_name = "starpu.task.s_max_priority_cap_knob";
  60. const char * const min_prio_knob_name = "starpu.task.s_min_priority_cap_knob";
  61. const char * const knob_scope_name = "per_scheduler";
  62. const char * const knob_type_name = "int32";
  63. int32_t max_prio_val;
  64. int32_t min_prio_val;
  65. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  66. const int max_prio_id = starpu_perf_knob_name_to_id(scope_id, max_prio_knob_name);
  67. STARPU_ASSERT(starpu_perf_knob_get_type_id(max_prio_id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  68. const int min_prio_id = starpu_perf_knob_name_to_id(scope_id, min_prio_knob_name);
  69. STARPU_ASSERT(starpu_perf_knob_get_type_id(min_prio_id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  70. printf("%s:\n", max_prio_knob_name);
  71. max_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(max_prio_id, "prio");
  72. printf("- %d\n", max_prio_val);
  73. printf("%s:\n", min_prio_knob_name);
  74. min_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(min_prio_id, "prio");
  75. printf("- %d\n", min_prio_val);
  76. STARPU_ASSERT (max_prio_val >= min_prio_val);
  77. if (min_prio_val > 0)
  78. {
  79. starpu_perf_knob_set_per_scheduler_int32_value(min_prio_id, "prio", 0);
  80. starpu_perf_knob_set_per_scheduler_int32_value(max_prio_id, "prio", 0);
  81. }
  82. else
  83. {
  84. starpu_perf_knob_set_per_scheduler_int32_value(max_prio_id, "prio", 0);
  85. starpu_perf_knob_set_per_scheduler_int32_value(min_prio_id, "prio", 0);
  86. }
  87. printf("%s:\n", max_prio_knob_name);
  88. max_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(max_prio_id, "prio");
  89. printf("- %d\n", max_prio_val);
  90. printf("%s:\n", min_prio_knob_name);
  91. min_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(min_prio_id, "prio");
  92. printf("- %d\n", min_prio_val);
  93. STARPU_ASSERT (max_prio_val == 0);
  94. STARPU_ASSERT (min_prio_val == 0);
  95. }
  96. {
  97. const char * const knob_name = "starpu.worker.w_enable_worker_knob";
  98. const char * const knob_scope_name = "per_worker";
  99. const char * const knob_type_name = "int32";
  100. int32_t val;
  101. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  102. const int id = starpu_perf_knob_name_to_id(scope_id, knob_name);
  103. STARPU_ASSERT(starpu_perf_knob_get_type_id(id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  104. struct starpu_codelet cl =
  105. {
  106. .cpu_funcs = {cpu_func}
  107. };
  108. task_count[0] = 0;
  109. task_count[1] = 0;
  110. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  111. STARPU_ASSERT(val == 1);
  112. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  113. STARPU_ASSERT(val == 1);
  114. starpu_perf_knob_set_per_worker_int32_value(id, 1, 0);
  115. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  116. STARPU_ASSERT(val == 0);
  117. int i;
  118. for (i=0; i<NTASKS; i++)
  119. {
  120. starpu_task_insert(&cl, 0);
  121. }
  122. starpu_task_wait_for_all();
  123. STARPU_ASSERT(task_count[0] == NTASKS);
  124. STARPU_ASSERT(task_count[1] == 0);
  125. task_count[0] = 0;
  126. starpu_perf_knob_set_per_worker_int32_value(id, 1, 1);
  127. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  128. STARPU_ASSERT(val == 1);
  129. starpu_perf_knob_set_per_worker_int32_value(id, 0, 0);
  130. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  131. STARPU_ASSERT(val == 0);
  132. for (i=0; i<NTASKS; i++)
  133. {
  134. starpu_task_insert(&cl, 0);
  135. }
  136. starpu_task_wait_for_all();
  137. STARPU_ASSERT(task_count[0] == 0);
  138. STARPU_ASSERT(task_count[1] == NTASKS);
  139. starpu_perf_knob_set_per_worker_int32_value(id, 0, 1);
  140. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  141. STARPU_ASSERT(val == 1);
  142. }
  143. starpu_shutdown();
  144. return 0;
  145. }