perf_knobs_02.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. int main(int argc, char **argv)
  20. {
  21. int ret;
  22. ret = starpu_init(NULL);
  23. if (ret == -ENODEV)
  24. return 77;
  25. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  26. {
  27. const char * const knob_name = "starpu.global.g_calibrate_knob";
  28. const char * const knob_scope_name = "global";
  29. const char * const knob_type_name = "int32";
  30. int32_t val, val_save;
  31. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  32. const int id = starpu_perf_knob_name_to_id(scope_id, knob_name);
  33. STARPU_ASSERT(starpu_perf_knob_get_type_id(id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  34. printf("%s:\n", knob_name);
  35. val_save = val = starpu_perf_knob_get_global_int32_value(id);
  36. printf("- %d\n", val);
  37. starpu_perf_knob_set_global_int32_value(id, 1);
  38. val = starpu_perf_knob_get_global_int32_value(id);
  39. printf("- %d\n", val);
  40. STARPU_ASSERT(val == 1);
  41. starpu_perf_knob_set_global_int32_value(id, 0);
  42. val = starpu_perf_knob_get_global_int32_value(id);
  43. printf("- %d\n", val);
  44. STARPU_ASSERT(val == 0);
  45. starpu_perf_knob_set_global_int32_value(id, val_save);
  46. val = starpu_perf_knob_get_global_int32_value(id);
  47. printf("- %d\n", val);
  48. STARPU_ASSERT(val == val_save);
  49. }
  50. {
  51. const char * const knob_name = "starpu.global.g_enable_catch_signal_knob";
  52. const char * const knob_scope_name = "global";
  53. const char * const knob_type_name = "int32";
  54. int32_t val, val_save;
  55. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  56. const int id = starpu_perf_knob_name_to_id(scope_id, knob_name);
  57. STARPU_ASSERT(starpu_perf_knob_get_type_id(id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  58. printf("%s:\n", knob_name);
  59. val_save = val = starpu_perf_knob_get_global_int32_value(id);
  60. printf("- %d\n", val);
  61. starpu_perf_knob_set_global_int32_value(id, 1);
  62. val = starpu_perf_knob_get_global_int32_value(id);
  63. printf("- %d\n", val);
  64. STARPU_ASSERT(val == 1);
  65. starpu_perf_knob_set_global_int32_value(id, 0);
  66. val = starpu_perf_knob_get_global_int32_value(id);
  67. printf("- %d\n", val);
  68. STARPU_ASSERT(val == 0);
  69. starpu_perf_knob_set_global_int32_value(id, val_save);
  70. val = starpu_perf_knob_get_global_int32_value(id);
  71. printf("- %d\n", val);
  72. STARPU_ASSERT(val == val_save);
  73. }
  74. {
  75. const char * const knob_name = "starpu.worker.w_bind_to_pu_knob";
  76. const char * const knob_scope_name = "per_worker";
  77. const char * const knob_type_name = "int32";
  78. int32_t val;
  79. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  80. const int id = starpu_perf_knob_name_to_id(scope_id, knob_name);
  81. STARPU_ASSERT(starpu_perf_knob_get_type_id(id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  82. printf("%s:\n", knob_name);
  83. unsigned int ncpu = starpu_cpu_worker_get_count();
  84. unsigned int i;
  85. for (i=0; i<ncpu; i++)
  86. {
  87. val = starpu_perf_knob_get_per_worker_int32_value(id, i);
  88. STARPU_ASSERT(val >= 0);
  89. printf("- %u: %d\n", i, val);
  90. }
  91. }
  92. {
  93. const char * const knob_name = "starpu.task.s_max_priority_cap_knob";
  94. const char * const knob_scope_name = "per_scheduler";
  95. const char * const knob_type_name = "int32";
  96. int32_t val;
  97. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  98. const int id = starpu_perf_knob_name_to_id(scope_id, knob_name);
  99. STARPU_ASSERT(starpu_perf_knob_get_type_id(id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  100. printf("%s:\n", knob_name);
  101. val = starpu_perf_knob_get_per_scheduler_int32_value(id, "prio");
  102. printf("- %d\n", val);
  103. }
  104. {
  105. const char * const knob_name = "starpu.task.s_min_priority_cap_knob";
  106. const char * const knob_scope_name = "per_scheduler";
  107. const char * const knob_type_name = "int32";
  108. int32_t val;
  109. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  110. const int id = starpu_perf_knob_name_to_id(scope_id, knob_name);
  111. STARPU_ASSERT(starpu_perf_knob_get_type_id(id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  112. printf("%s:\n", knob_name);
  113. val = starpu_perf_knob_get_per_scheduler_int32_value(id, "prio");
  114. printf("- %d\n", val);
  115. }
  116. starpu_shutdown();
  117. return 0;
  118. }