modular_heft2.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-2014 Université de Bordeaux 1
  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. /* The two thresolds concerns the prio components, which contains queues
  22. * who can handle the priority of StarPU tasks. You can tune your
  23. * scheduling by benching those values and choose which one is the
  24. * best for your current application.
  25. * The current value of the ntasks_threshold is the best we found
  26. * so far across several types of applications (cholesky, LU, stencil).
  27. */
  28. #define _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT 30
  29. #define _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT 1000000000.0
  30. static void initialize_heft2_center_policy(unsigned sched_ctx_id)
  31. {
  32. starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
  33. unsigned ntasks_threshold = _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT;
  34. double exp_len_threshold = _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT;
  35. const char *strval_ntasks_threshold = getenv("STARPU_NTASKS_THRESHOLD");
  36. if (strval_ntasks_threshold)
  37. ntasks_threshold = atof(strval_ntasks_threshold);
  38. const char *strval_exp_len_threshold = getenv("STARPU_EXP_LEN_THRESHOLD");
  39. if (strval_exp_len_threshold)
  40. exp_len_threshold = atof(strval_exp_len_threshold);
  41. struct starpu_sched_tree * t = starpu_sched_tree_create(sched_ctx_id);
  42. struct starpu_sched_component * perfmodel_component = starpu_sched_component_heft_create(t, NULL);
  43. struct starpu_sched_component * no_perfmodel_component = starpu_sched_component_eager_create(t, NULL);
  44. struct starpu_sched_component * calibrator_component = starpu_sched_component_eager_create(t, NULL);
  45. struct starpu_perfmodel_select_data perfmodel_select_data =
  46. {
  47. .calibrator_component = calibrator_component,
  48. .no_perfmodel_component = no_perfmodel_component,
  49. .perfmodel_component = perfmodel_component,
  50. };
  51. struct starpu_sched_component * window_component = starpu_sched_component_prio_create(t, NULL);
  52. t->root = window_component;
  53. struct starpu_sched_component * perfmodel_select_component = starpu_sched_component_perfmodel_select_create(t, &perfmodel_select_data);
  54. window_component->add_child(window_component, perfmodel_select_component);
  55. perfmodel_select_component->add_parent(perfmodel_select_component, window_component);
  56. perfmodel_select_component->add_child(perfmodel_select_component, calibrator_component);
  57. calibrator_component->add_parent(calibrator_component, perfmodel_select_component);
  58. perfmodel_select_component->add_child(perfmodel_select_component, perfmodel_component);
  59. perfmodel_component->add_parent(perfmodel_component, perfmodel_select_component);
  60. perfmodel_select_component->add_child(perfmodel_select_component, no_perfmodel_component);
  61. no_perfmodel_component->add_parent(no_perfmodel_component, perfmodel_select_component);
  62. struct starpu_prio_data prio_data =
  63. {
  64. .ntasks_threshold = ntasks_threshold,
  65. .exp_len_threshold = exp_len_threshold,
  66. };
  67. unsigned i;
  68. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  69. {
  70. struct starpu_sched_component * worker_component = starpu_sched_component_worker_get(sched_ctx_id, i);
  71. STARPU_ASSERT(worker_component);
  72. struct starpu_sched_component * prio_component = starpu_sched_component_prio_create(t, &prio_data);
  73. prio_component->add_child(prio_component, worker_component);
  74. worker_component->add_parent(worker_component, prio_component);
  75. struct starpu_sched_component * impl_component = starpu_sched_component_best_implementation_create(t, NULL);
  76. impl_component->add_child(impl_component, prio_component);
  77. prio_component->add_parent(prio_component, impl_component);
  78. perfmodel_component->add_child(perfmodel_component, impl_component);
  79. impl_component->add_parent(impl_component, perfmodel_component);
  80. no_perfmodel_component->add_child(no_perfmodel_component, impl_component);
  81. impl_component->add_parent(impl_component, no_perfmodel_component);
  82. calibrator_component->add_child(calibrator_component, impl_component);
  83. impl_component->add_parent(impl_component, calibrator_component);
  84. }
  85. starpu_sched_tree_update_workers(t);
  86. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  87. }
  88. static void deinitialize_heft2_center_policy(unsigned sched_ctx_id)
  89. {
  90. struct starpu_sched_tree *t = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  91. starpu_sched_tree_destroy(t);
  92. starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
  93. }
  94. struct starpu_sched_policy _starpu_sched_modular_heft2_policy =
  95. {
  96. .init_sched = initialize_heft2_center_policy,
  97. .deinit_sched = deinitialize_heft2_center_policy,
  98. .add_workers = starpu_sched_tree_add_workers,
  99. .remove_workers = starpu_sched_tree_remove_workers,
  100. .push_task = starpu_sched_tree_push_task,
  101. .pop_task = starpu_sched_tree_pop_task,
  102. .pre_exec_hook = starpu_sched_component_worker_pre_exec_hook,
  103. .post_exec_hook = starpu_sched_component_worker_post_exec_hook,
  104. .pop_every_task = NULL,
  105. .policy_name = "modular-heft2",
  106. .policy_description = "heft modular2 policy"
  107. };