perf_knobs_03.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. conf.ncpus = 2;
  35. conf.ncuda = 0;
  36. conf.nopencl = 0;
  37. conf.nmic = 0;
  38. conf.nmpi_ms = 0;
  39. {
  40. const char *sched_pol_name = starpu_getenv("STARPU_SCHED");
  41. if (sched_pol_name != NULL && strcmp(sched_pol_name, "prio") != 0)
  42. {
  43. fprintf(stderr, "example uses 'prio' scheduling policy.\n");
  44. return 77;
  45. }
  46. }
  47. conf.sched_policy_name = "prio";
  48. ret = starpu_initialize(&conf, &argc, &argv);
  49. if (ret == -ENODEV)
  50. return 77;
  51. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  52. if (starpu_cpu_worker_get_count() != 2
  53. || starpu_cuda_worker_get_count() != 0
  54. || starpu_opencl_worker_get_count() != 0
  55. || starpu_mic_worker_get_count() != 0
  56. || starpu_mpi_ms_worker_get_count() != 0)
  57. {
  58. fprintf(stderr, "example needs exactly two cpu cores.\n");
  59. return 77;
  60. }
  61. {
  62. const char * const max_prio_knob_name = "starpu.task.s_max_priority_cap_knob";
  63. const char * const min_prio_knob_name = "starpu.task.s_min_priority_cap_knob";
  64. const char * const knob_scope_name = "per_scheduler";
  65. const char * const knob_type_name = "int32";
  66. int32_t max_prio_val;
  67. int32_t min_prio_val;
  68. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  69. const int max_prio_id = starpu_perf_knob_name_to_id(scope_id, max_prio_knob_name);
  70. STARPU_ASSERT(starpu_perf_knob_get_type_id(max_prio_id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  71. const int min_prio_id = starpu_perf_knob_name_to_id(scope_id, min_prio_knob_name);
  72. STARPU_ASSERT(starpu_perf_knob_get_type_id(min_prio_id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  73. printf("%s:\n", max_prio_knob_name);
  74. max_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(max_prio_id, "prio");
  75. printf("- %d\n", max_prio_val);
  76. printf("%s:\n", min_prio_knob_name);
  77. min_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(min_prio_id, "prio");
  78. printf("- %d\n", min_prio_val);
  79. STARPU_ASSERT (max_prio_val >= min_prio_val);
  80. if (min_prio_val > 0)
  81. {
  82. starpu_perf_knob_set_per_scheduler_int32_value(min_prio_id, "prio", 0);
  83. starpu_perf_knob_set_per_scheduler_int32_value(max_prio_id, "prio", 0);
  84. }
  85. else
  86. {
  87. starpu_perf_knob_set_per_scheduler_int32_value(max_prio_id, "prio", 0);
  88. starpu_perf_knob_set_per_scheduler_int32_value(min_prio_id, "prio", 0);
  89. }
  90. printf("%s:\n", max_prio_knob_name);
  91. max_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(max_prio_id, "prio");
  92. printf("- %d\n", max_prio_val);
  93. printf("%s:\n", min_prio_knob_name);
  94. min_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(min_prio_id, "prio");
  95. printf("- %d\n", min_prio_val);
  96. STARPU_ASSERT (max_prio_val == 0);
  97. STARPU_ASSERT (min_prio_val == 0);
  98. }
  99. {
  100. const char * const knob_name = "starpu.worker.w_enable_worker_knob";
  101. const char * const knob_scope_name = "per_worker";
  102. const char * const knob_type_name = "int32";
  103. int32_t val;
  104. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  105. const int id = starpu_perf_knob_name_to_id(scope_id, knob_name);
  106. STARPU_ASSERT(starpu_perf_knob_get_type_id(id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  107. struct starpu_codelet cl =
  108. {
  109. .cpu_funcs = {cpu_func}
  110. };
  111. task_count[0] = 0;
  112. task_count[1] = 0;
  113. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  114. STARPU_ASSERT(val == 1);
  115. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  116. STARPU_ASSERT(val == 1);
  117. starpu_perf_knob_set_per_worker_int32_value(id, 1, 0);
  118. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  119. STARPU_ASSERT(val == 0);
  120. int i;
  121. for (i=0; i<NTASKS; i++)
  122. {
  123. starpu_task_insert(&cl, 0);
  124. }
  125. starpu_task_wait_for_all();
  126. STARPU_ASSERT(task_count[0] == NTASKS);
  127. STARPU_ASSERT(task_count[1] == 0);
  128. task_count[0] = 0;
  129. starpu_perf_knob_set_per_worker_int32_value(id, 1, 1);
  130. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  131. STARPU_ASSERT(val == 1);
  132. starpu_perf_knob_set_per_worker_int32_value(id, 0, 0);
  133. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  134. STARPU_ASSERT(val == 0);
  135. for (i=0; i<NTASKS; i++)
  136. {
  137. starpu_task_insert(&cl, 0);
  138. }
  139. starpu_task_wait_for_all();
  140. STARPU_ASSERT(task_count[0] == 0);
  141. STARPU_ASSERT(task_count[1] == NTASKS);
  142. starpu_perf_knob_set_per_worker_int32_value(id, 0, 1);
  143. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  144. STARPU_ASSERT(val == 1);
  145. }
  146. starpu_shutdown();
  147. return 0;
  148. }