component_userchoice.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2019-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. /* This component uses (uintptr_t) tasks->sched_data as the child number it
  17. * should push its tasks to. It can thus be used to let the user choose which
  18. * scheduler a task should go to. */
  19. #include <starpu_sched_component.h>
  20. #include <starpu_scheduler.h>
  21. static int userchoice_push_task(struct starpu_sched_component * component, struct starpu_task * task)
  22. {
  23. unsigned target = (uintptr_t) task->sched_data;
  24. STARPU_ASSERT(target < component->nchildren);
  25. return starpu_sched_component_push_task(component, component->children[target], task);
  26. }
  27. static struct starpu_task * userchoice_pull_task(struct starpu_sched_component * component, struct starpu_sched_component * to STARPU_ATTRIBUTE_UNUSED)
  28. {
  29. _STARPU_DISP("stage component is not supposed to be pull from...\n");
  30. return starpu_sched_component_parents_pull_task(component, to);
  31. }
  32. int userchoice_can_pull(struct starpu_sched_component * component)
  33. {
  34. _STARPU_DISP("stage component is not supposed to be pull from...\n");
  35. return starpu_sched_component_can_pull(component);
  36. }
  37. int starpu_sched_component_is_userchoice(struct starpu_sched_component * component)
  38. {
  39. return component->push_task == userchoice_push_task;
  40. }
  41. struct starpu_sched_component * starpu_sched_component_userchoice_create(struct starpu_sched_tree *tree, void *args STARPU_ATTRIBUTE_UNUSED)
  42. {
  43. struct starpu_sched_component *component = starpu_sched_component_create(tree, "userchoice");
  44. component->push_task = userchoice_push_task;
  45. component->pull_task = userchoice_pull_task;
  46. component->can_pull = userchoice_can_pull;
  47. return component;
  48. }