tree_heft.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 INRIA
  4. * Copyright (C) 2013 Simon Archipoff
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu_sched_node.h>
  18. #include <starpu_scheduler.h>
  19. #include <float.h>
  20. /* The two thresolds concerns the prio nodes, which contains queues
  21. * who can handle the priority of StarPU tasks. You can tune your
  22. * scheduling by benching those values and choose which one is the
  23. * best for your current application.
  24. * The current value of the ntasks_threshold is the best we found
  25. * so far across several types of applications (cholesky, LU, stencil).
  26. */
  27. #define _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT 30
  28. #define _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT 1000000000.0
  29. static void initialize_heft_center_policy(unsigned sched_ctx_id)
  30. {
  31. starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
  32. unsigned ntasks_threshold = _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT;
  33. double exp_len_threshold = _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT;
  34. const char *strval_ntasks_threshold = getenv("STARPU_NTASKS_THRESHOLD");
  35. if (strval_ntasks_threshold)
  36. ntasks_threshold = atof(strval_ntasks_threshold);
  37. const char *strval_exp_len_threshold = getenv("STARPU_EXP_LEN_THRESHOLD");
  38. if (strval_exp_len_threshold)
  39. exp_len_threshold = atof(strval_exp_len_threshold);
  40. /* The scheduling strategy look like this :
  41. *
  42. * |
  43. * window_node
  44. * |
  45. * perfmodel_node <--push-- perfmodel_select_node --push--> eager_node
  46. * | |
  47. * | |
  48. * >----------------------------------------------------<
  49. * | |
  50. * best_impl_node best_impl_node
  51. * | |
  52. * prio_node prio_node
  53. * | |
  54. * worker_node worker_node
  55. *
  56. * A window contain the tasks that failed to be pushed, so as when the prio_nodes reclaim
  57. * tasks by calling room to their father (classically, just after a successful pop have
  58. * been made by its associated worker_node), this call goes up to the window_node which
  59. * pops a task from its local queue and try to schedule it by pushing it to the
  60. * decision_node.
  61. * The decision node takes care of the scheduling of tasks which are not
  62. * calibrated, or tasks which don't have a performance model, because the scheduling
  63. * architecture of this scheduler for tasks with no performance model is exactly
  64. * the same as the tree-prio scheduler.
  65. * Tasks with a perfmodel are pushed to the perfmodel_node, which takes care of the
  66. * scheduling of those tasks on the correct worker_node.
  67. * Finally, the task will be pushed to the prio_node which is the direct
  68. * father in the tree of the worker_node the task has been scheduled on. This
  69. * node will push the task on its local queue if no one of the two thresholds
  70. * have been reached for it, or send a push_error signal to its father.
  71. */
  72. struct starpu_sched_tree * t = starpu_sched_tree_create(sched_ctx_id);
  73. struct starpu_sched_node * window_node = starpu_sched_node_prio_create(NULL);
  74. t->root = window_node;
  75. struct starpu_sched_node * perfmodel_node = starpu_sched_node_mct_create(NULL);
  76. struct starpu_sched_node * no_perfmodel_node = starpu_sched_node_eager_create(NULL);
  77. struct starpu_sched_node * calibrator_node = starpu_sched_node_eager_create(NULL);
  78. struct starpu_perfmodel_select_data perfmodel_select_data =
  79. {
  80. .calibrator_node = calibrator_node,
  81. .no_perfmodel_node = no_perfmodel_node,
  82. .perfmodel_node = perfmodel_node,
  83. };
  84. struct starpu_sched_node * perfmodel_select_node = starpu_sched_node_perfmodel_select_create(&perfmodel_select_data);
  85. window_node->add_child(window_node, perfmodel_select_node);
  86. starpu_sched_node_set_father(perfmodel_select_node, window_node, sched_ctx_id);
  87. struct starpu_prio_data prio_data =
  88. {
  89. .ntasks_threshold = ntasks_threshold,
  90. .exp_len_threshold = exp_len_threshold,
  91. };
  92. unsigned i;
  93. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  94. {
  95. struct starpu_sched_node * worker_node = starpu_sched_node_worker_get(i);
  96. STARPU_ASSERT(worker_node);
  97. struct starpu_sched_node * prio = starpu_sched_node_prio_create(&prio_data);
  98. prio->add_child(prio, worker_node);
  99. starpu_sched_node_set_father(worker_node, prio, sched_ctx_id);
  100. struct starpu_sched_node * impl_node = starpu_sched_node_best_implementation_create(NULL);
  101. impl_node->add_child(impl_node, prio);
  102. starpu_sched_node_set_father(prio, impl_node, sched_ctx_id);
  103. perfmodel_select_node->add_child(perfmodel_select_node, impl_node);
  104. starpu_sched_node_set_father(impl_node, perfmodel_select_node, sched_ctx_id);
  105. }
  106. starpu_sched_tree_update_workers(t);
  107. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  108. }
  109. static void deinitialize_heft_center_policy(unsigned sched_ctx_id)
  110. {
  111. struct starpu_sched_tree *t = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  112. starpu_sched_tree_destroy(t);
  113. starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
  114. }
  115. struct starpu_sched_policy _starpu_sched_tree_heft_policy =
  116. {
  117. .init_sched = initialize_heft_center_policy,
  118. .deinit_sched = deinitialize_heft_center_policy,
  119. .add_workers = starpu_sched_tree_add_workers,
  120. .remove_workers = starpu_sched_tree_remove_workers,
  121. .push_task = starpu_sched_tree_push_task,
  122. .pop_task = starpu_sched_tree_pop_task,
  123. .pre_exec_hook = starpu_sched_node_worker_pre_exec_hook,
  124. .post_exec_hook = starpu_sched_node_worker_post_exec_hook,
  125. .pop_every_task = NULL,
  126. .policy_name = "tree-heft",
  127. .policy_description = "heft tree policy"
  128. };