component_perfmodel_select.c 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 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 void perfmodel_select_component_deinit_data(struct starpu_sched_component * component)
  58. {
  59. STARPU_ASSERT(component && component->data);
  60. struct _starpu_perfmodel_select_data * d = component->data;
  61. free(d);
  62. }
  63. int starpu_sched_component_is_perfmodel_select(struct starpu_sched_component * component)
  64. {
  65. return component->push_task == perfmodel_select_push_task;
  66. }
  67. struct starpu_sched_component * starpu_sched_component_perfmodel_select_create(struct starpu_sched_tree *tree, struct starpu_sched_component_perfmodel_select_data * params)
  68. {
  69. STARPU_ASSERT(params);
  70. STARPU_ASSERT(params->calibrator_component && params->no_perfmodel_component && params->perfmodel_component);
  71. struct starpu_sched_component * component = starpu_sched_component_create(tree, "perfmodel_selector");
  72. struct _starpu_perfmodel_select_data *data;
  73. _STARPU_MALLOC(data, sizeof(*data));
  74. data->calibrator_component = params->calibrator_component;
  75. data->no_perfmodel_component = params->no_perfmodel_component;
  76. data->perfmodel_component = params->perfmodel_component;
  77. component->data = data;
  78. component->can_pull = starpu_sched_component_send_can_push_to_parents;
  79. component->push_task = perfmodel_select_push_task;
  80. component->deinit_data = perfmodel_select_component_deinit_data;
  81. component->estimated_end = starpu_sched_component_estimated_end_min;
  82. return component;
  83. }