component_perfmodel_select.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. return starpu_sched_component_push_task(component,data->calibrator_component,task);
  42. if(_STARPU_IS_ZERO(length))
  43. return starpu_sched_component_push_task(component,data->no_perfmodel_component,task);
  44. return starpu_sched_component_push_task(component,data->perfmodel_component,task);
  45. }
  46. else
  47. return 1;
  48. }
  49. static void perfmodel_select_component_deinit_data(struct starpu_sched_component * component)
  50. {
  51. STARPU_ASSERT(component && component->data);
  52. struct _starpu_perfmodel_select_data * d = component->data;
  53. free(d);
  54. }
  55. int starpu_sched_component_is_perfmodel_select(struct starpu_sched_component * component)
  56. {
  57. return component->push_task == perfmodel_select_push_task;
  58. }
  59. struct starpu_sched_component * starpu_sched_component_perfmodel_select_create(struct starpu_sched_tree *tree, struct starpu_sched_component_perfmodel_select_data * params)
  60. {
  61. STARPU_ASSERT(params);
  62. STARPU_ASSERT(params->calibrator_component && params->no_perfmodel_component && params->perfmodel_component);
  63. struct starpu_sched_component * component = starpu_sched_component_create(tree, "perfmodel_selector");
  64. struct _starpu_perfmodel_select_data * data = malloc(sizeof(*data));
  65. data->calibrator_component = params->calibrator_component;
  66. data->no_perfmodel_component = params->no_perfmodel_component;
  67. data->perfmodel_component = params->perfmodel_component;
  68. component->data = data;
  69. component->push_task = perfmodel_select_push_task;
  70. component->deinit_data = perfmodel_select_component_deinit_data;
  71. return component;
  72. }