component_perfmodel_select.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-2020 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. if (!warned)
  44. {
  45. warned = 1;
  46. _STARPU_DISP("Warning: performance model for %s not finished calibrating, using a dumb scheduling heuristic for now\n",starpu_task_get_name(task));
  47. }
  48. return starpu_sched_component_push_task(component,data->calibrator_component,task);
  49. }
  50. if(_STARPU_IS_ZERO(length))
  51. return starpu_sched_component_push_task(component,data->no_perfmodel_component,task);
  52. return starpu_sched_component_push_task(component,data->perfmodel_component,task);
  53. }
  54. else
  55. return 1;
  56. }
  57. static struct starpu_task * perfmodel_select_pull_task(struct starpu_sched_component * component STARPU_ATTRIBUTE_UNUSED, struct starpu_sched_component * to STARPU_ATTRIBUTE_UNUSED)
  58. {
  59. /* We don't want to pull tasks blindly, only let them go through push, so we push to the right component. */
  60. return NULL;
  61. }
  62. static void perfmodel_select_component_deinit_data(struct starpu_sched_component * component)
  63. {
  64. STARPU_ASSERT(component && component->data);
  65. struct _starpu_perfmodel_select_data * d = component->data;
  66. free(d);
  67. }
  68. int starpu_sched_component_is_perfmodel_select(struct starpu_sched_component * component)
  69. {
  70. return component->push_task == perfmodel_select_push_task;
  71. }
  72. struct starpu_sched_component * starpu_sched_component_perfmodel_select_create(struct starpu_sched_tree *tree, struct starpu_sched_component_perfmodel_select_data * params)
  73. {
  74. STARPU_ASSERT(params);
  75. STARPU_ASSERT(params->calibrator_component && params->no_perfmodel_component && params->perfmodel_component);
  76. struct starpu_sched_component * component = starpu_sched_component_create(tree, "perfmodel_selector");
  77. struct _starpu_perfmodel_select_data *data;
  78. _STARPU_MALLOC(data, sizeof(*data));
  79. data->calibrator_component = params->calibrator_component;
  80. data->no_perfmodel_component = params->no_perfmodel_component;
  81. data->perfmodel_component = params->perfmodel_component;
  82. component->data = data;
  83. component->can_pull = starpu_sched_component_send_can_push_to_parents;
  84. component->push_task = perfmodel_select_push_task;
  85. component->pull_task = perfmodel_select_pull_task;
  86. component->deinit_data = perfmodel_select_component_deinit_data;
  87. component->estimated_end = starpu_sched_component_estimated_end_min;
  88. return component;
  89. }