component_mct.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 "sched_component.h"
  20. #include <starpu_perfmodel.h>
  21. #include "helper_mct.h"
  22. #include <float.h>
  23. static int mct_push_task(struct starpu_sched_component * component, struct starpu_task * task)
  24. {
  25. STARPU_ASSERT(component && task && starpu_sched_component_is_mct(component));
  26. struct _starpu_mct_data * d = component->data;
  27. struct starpu_sched_component * best_component = NULL;
  28. /* Estimated task duration for each child */
  29. double estimated_lengths[component->nchildren];
  30. /* Estimated transfer duration for each child */
  31. double estimated_transfer_length[component->nchildren];
  32. /* Estimated transfer+task termination for each child */
  33. double estimated_ends_with_task[component->nchildren];
  34. int i;
  35. for(i=0; i < component->nchildren; i++)
  36. {
  37. estimated_lengths[i] = 0.0;
  38. estimated_transfer_length[i] = 0.0;
  39. estimated_ends_with_task[i] = 0.0;
  40. }
  41. /* Minimum transfer+task termination on all children */
  42. double min_exp_end_with_task = DBL_MAX;
  43. /* Maximum transfer+task termination on all children */
  44. double max_exp_end_with_task = 0.0;
  45. int suitable_components[component->nchildren];
  46. int nsuitable_components = 0;
  47. nsuitable_components = starpu_mct_compute_expected_times(component, task,
  48. estimated_lengths, estimated_transfer_length, estimated_ends_with_task,
  49. &min_exp_end_with_task, &max_exp_end_with_task, suitable_components);
  50. /* If no suitable components were found, it means that the perfmodel of
  51. * the task had been purged since it has been pushed on the mct component.
  52. * We should send a push_fail message to its parent so that it will
  53. * be able to reschedule the task properly. */
  54. if(nsuitable_components == 0)
  55. return 1;
  56. double best_fitness = DBL_MAX;
  57. int best_icomponent = -1;
  58. for(i = 0; i < nsuitable_components; i++)
  59. {
  60. int icomponent = suitable_components[i];
  61. #ifdef STARPU_DEVEL
  62. #warning FIXME: take power consumption into account
  63. #endif
  64. double tmp = starpu_mct_compute_fitness(d,
  65. estimated_ends_with_task[icomponent],
  66. min_exp_end_with_task,
  67. max_exp_end_with_task,
  68. estimated_transfer_length[icomponent],
  69. 0.0);
  70. if(tmp < best_fitness)
  71. {
  72. best_fitness = tmp;
  73. best_icomponent = icomponent;
  74. }
  75. }
  76. /* If no best component is found, it means that the perfmodel of
  77. * the task had been purged since it has been pushed on the mct component.
  78. * We should send a push_fail message to its parent so that it will
  79. * be able to reschedule the task properly. */
  80. if(best_icomponent == -1)
  81. return 1;
  82. best_component = component->children[best_icomponent];
  83. if(starpu_sched_component_is_worker(best_component))
  84. {
  85. best_component->can_pull(best_component);
  86. return 1;
  87. }
  88. int ret = best_component->push_task(best_component, task);
  89. return ret;
  90. }
  91. static void mct_component_deinit_data(struct starpu_sched_component * component)
  92. {
  93. STARPU_ASSERT(starpu_sched_component_is_mct(component));
  94. struct _starpu_mct_data * d = component->data;
  95. free(d);
  96. }
  97. int starpu_sched_component_is_mct(struct starpu_sched_component * component)
  98. {
  99. return component->push_task == mct_push_task;
  100. }
  101. struct starpu_sched_component * starpu_sched_component_mct_create(struct starpu_sched_tree *tree, struct starpu_mct_data * params)
  102. {
  103. struct starpu_sched_component * component = starpu_sched_component_create(tree);
  104. struct _starpu_mct_data *data = starpu_mct_init_parameters(params);
  105. component->data = data;
  106. component->push_task = mct_push_task;
  107. component->deinit_data = mct_component_deinit_data;
  108. return component;
  109. }