component_perfmodel_select.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-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_sched_component.h>
  17. #include <starpu_scheduler.h>
  18. /* The decision component takes care of the scheduling of tasks which are not
  19. * calibrated, or tasks which don't have a performance model, because the scheduling
  20. * architecture of this scheduler for tasks with no performance model is exactly
  21. * the same as the tree-prio scheduler.
  22. * Tasks with a perfmodel are pushed to the perfmodel_component, which takes care of the
  23. * scheduling of those tasks on the correct worker_component.
  24. */
  25. struct _starpu_perfmodel_select_data
  26. {
  27. struct starpu_sched_component * calibrator_component;
  28. struct starpu_sched_component * no_perfmodel_component;
  29. struct starpu_sched_component * perfmodel_component;
  30. };
  31. static int perfmodel_select_push_task(struct starpu_sched_component * component, struct starpu_task * task)
  32. {
  33. STARPU_ASSERT(component && component->data && task && starpu_sched_component_is_perfmodel_select(component));
  34. STARPU_ASSERT(starpu_sched_component_can_execute_task(component,task));
  35. struct _starpu_perfmodel_select_data * data = component->data;
  36. double length;
  37. int can_execute = starpu_sched_component_execute_preds(component,task,&length);
  38. if(can_execute)
  39. {
  40. if(isnan(length))
  41. {
  42. static int warned;
  43. STARPU_HG_DISABLE_CHECKING(warned);
  44. if (!warned)
  45. {
  46. warned = 1;
  47. _STARPU_DISP("Warning: performance model for %s not finished calibrating, using a dumb scheduling heuristic for now\n",starpu_task_get_name(task));
  48. }
  49. return starpu_sched_component_push_task(component,data->calibrator_component,task);
  50. }
  51. if(_STARPU_IS_ZERO(length))
  52. return starpu_sched_component_push_task(component,data->no_perfmodel_component,task);
  53. return starpu_sched_component_push_task(component,data->perfmodel_component,task);
  54. }
  55. else
  56. return 1;
  57. }
  58. static struct starpu_task * perfmodel_select_pull_task(struct starpu_sched_component * component STARPU_ATTRIBUTE_UNUSED, struct starpu_sched_component * to STARPU_ATTRIBUTE_UNUSED)
  59. {
  60. /* We don't want to pull tasks blindly, only let them go through push, so we push to the right component. */
  61. return NULL;
  62. }
  63. static void perfmodel_select_component_deinit_data(struct starpu_sched_component * component)
  64. {
  65. STARPU_ASSERT(component && component->data);
  66. struct _starpu_perfmodel_select_data * d = component->data;
  67. free(d);
  68. }
  69. int starpu_sched_component_is_perfmodel_select(struct starpu_sched_component * component)
  70. {
  71. return component->push_task == perfmodel_select_push_task;
  72. }
  73. struct starpu_sched_component * starpu_sched_component_perfmodel_select_create(struct starpu_sched_tree *tree, struct starpu_sched_component_perfmodel_select_data * params)
  74. {
  75. STARPU_ASSERT(params);
  76. STARPU_ASSERT(params->calibrator_component && params->no_perfmodel_component && params->perfmodel_component);
  77. struct starpu_sched_component * component = starpu_sched_component_create(tree, "perfmodel_selector");
  78. struct _starpu_perfmodel_select_data *data;
  79. _STARPU_MALLOC(data, sizeof(*data));
  80. data->calibrator_component = params->calibrator_component;
  81. data->no_perfmodel_component = params->no_perfmodel_component;
  82. data->perfmodel_component = params->perfmodel_component;
  83. component->data = data;
  84. component->can_pull = starpu_sched_component_send_can_push_to_parents;
  85. component->push_task = perfmodel_select_push_task;
  86. component->pull_task = perfmodel_select_pull_task;
  87. component->deinit_data = perfmodel_select_component_deinit_data;
  88. component->estimated_end = starpu_sched_component_estimated_end_min;
  89. return component;
  90. }