perf_knobs_03.c 5.0 KB

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