modular_heft.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-2015 Université de Bordeaux
  4. * Copyright (C) 2013 INRIA
  5. * Copyright (C) 2013 Simon Archipoff
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu_sched_component.h>
  19. #include <starpu_scheduler.h>
  20. #include <float.h>
  21. #include <limits.h>
  22. /* The two thresolds concerns the prio components, which contains queues
  23. * who can handle the priority of StarPU tasks. You can tune your
  24. * scheduling by benching those values and choose which one is the
  25. * best for your current application.
  26. * The current value of the ntasks_threshold is the best we found
  27. * so far across several types of applications (cholesky, LU, stencil).
  28. */
  29. #define _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT 30
  30. #define _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT 1000000000.0
  31. static void initialize_heft_center_policy(unsigned sched_ctx_id)
  32. {
  33. starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
  34. /* The application may use any integer */
  35. if (starpu_sched_ctx_min_priority_is_set(sched_ctx_id) == 0)
  36. starpu_sched_ctx_set_min_priority(sched_ctx_id, INT_MIN);
  37. if (starpu_sched_ctx_max_priority_is_set(sched_ctx_id) == 0)
  38. starpu_sched_ctx_set_max_priority(sched_ctx_id, INT_MAX);
  39. /* The scheduling strategy look like this :
  40. *
  41. * |
  42. * window_component
  43. * |
  44. * perfmodel_component <--push-- perfmodel_select_component --push--> eager_component
  45. * | |
  46. * | |
  47. * >----------------------------------------------------<
  48. * | |
  49. * best_impl_component best_impl_component
  50. * | |
  51. * prio_component prio_component
  52. * | |
  53. * worker_component worker_component
  54. *
  55. * A window contain the tasks that failed to be pushed, so as when the prio_components reclaim
  56. * tasks by calling can_push to their parent (classically, just after a successful pop have
  57. * been made by its associated worker_component), this call goes up to the window_component which
  58. * pops a task from its local queue and try to schedule it by pushing it to the
  59. * decision_component.
  60. * Finally, the task will be pushed to the prio_component which is the direct
  61. * parent in the tree of the worker_component the task has been scheduled on. This
  62. * component will push the task on its local queue if no one of the two thresholds
  63. * have been reached for it, or send a push_error signal to its parent.
  64. */
  65. struct starpu_sched_tree * t = starpu_sched_tree_create(sched_ctx_id);
  66. struct starpu_sched_component * window_component = starpu_sched_component_prio_create(t, NULL);
  67. struct starpu_sched_component * perfmodel_component = starpu_sched_component_mct_create(t, NULL);
  68. struct starpu_sched_component * no_perfmodel_component = starpu_sched_component_eager_create(t, NULL);
  69. struct starpu_sched_component * calibrator_component = starpu_sched_component_eager_calibration_create(t, NULL);
  70. struct starpu_sched_component_perfmodel_select_data perfmodel_select_data =
  71. {
  72. .calibrator_component = calibrator_component,
  73. .no_perfmodel_component = no_perfmodel_component,
  74. .perfmodel_component = perfmodel_component,
  75. };
  76. struct starpu_sched_component * perfmodel_select_component = starpu_sched_component_perfmodel_select_create(t, &perfmodel_select_data);
  77. t->root = window_component;
  78. starpu_sched_component_connect(window_component, perfmodel_select_component);
  79. starpu_sched_component_connect(perfmodel_select_component, perfmodel_component);
  80. starpu_sched_component_connect(perfmodel_select_component, calibrator_component);
  81. starpu_sched_component_connect(perfmodel_select_component, no_perfmodel_component);
  82. struct starpu_sched_component_prio_data prio_data =
  83. {
  84. .ntasks_threshold = starpu_get_env_number_default("STARPU_NTASKS_THRESHOLD", _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT),
  85. .exp_len_threshold = starpu_get_env_float_default("STARPU_EXP_LEN_THRESHOLD", _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT),
  86. };
  87. unsigned i;
  88. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  89. {
  90. struct starpu_sched_component * worker_component = starpu_sched_component_worker_get(sched_ctx_id, i);
  91. struct starpu_sched_component * prio_component = starpu_sched_component_prio_create(t, &prio_data);
  92. struct starpu_sched_component * impl_component = starpu_sched_component_best_implementation_create(t, NULL);
  93. starpu_sched_component_connect(prio_component, worker_component);
  94. starpu_sched_component_connect(impl_component, prio_component);
  95. starpu_sched_component_connect(perfmodel_component, impl_component);
  96. starpu_sched_component_connect(no_perfmodel_component, impl_component);
  97. starpu_sched_component_connect(calibrator_component, impl_component);
  98. }
  99. starpu_sched_tree_update_workers(t);
  100. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  101. }
  102. static void deinitialize_heft_center_policy(unsigned sched_ctx_id)
  103. {
  104. struct starpu_sched_tree *t = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  105. starpu_sched_tree_destroy(t);
  106. starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
  107. }
  108. struct starpu_sched_policy _starpu_sched_modular_heft_policy =
  109. {
  110. .init_sched = initialize_heft_center_policy,
  111. .deinit_sched = deinitialize_heft_center_policy,
  112. .add_workers = starpu_sched_tree_add_workers,
  113. .remove_workers = starpu_sched_tree_remove_workers,
  114. .push_task = starpu_sched_tree_push_task,
  115. .pop_task = starpu_sched_tree_pop_task,
  116. .pre_exec_hook = starpu_sched_component_worker_pre_exec_hook,
  117. .post_exec_hook = starpu_sched_component_worker_post_exec_hook,
  118. .pop_every_task = NULL,
  119. .policy_name = "modular-heft",
  120. .policy_description = "heft modular policy"
  121. };