modular_random.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013, 2017 INRIA
  4. * Copyright (C) 2013 Simon Archipoff
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu_sched_component.h>
  18. #include <starpu_scheduler.h>
  19. /* Random scheduler with a fifo queue for its scheduling window */
  20. static void initialize_random_fifo_center_policy(unsigned sched_ctx_id)
  21. {
  22. struct starpu_sched_tree *t;
  23. struct starpu_sched_component * random_component;
  24. t = starpu_sched_tree_create(sched_ctx_id);
  25. t->root = starpu_sched_component_fifo_create(t, NULL);
  26. random_component = starpu_sched_component_random_create(t, NULL);
  27. starpu_sched_component_connect(t->root, random_component);
  28. unsigned i;
  29. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  30. starpu_sched_component_connect(random_component, starpu_sched_component_worker_new(sched_ctx_id, i));
  31. starpu_sched_tree_update_workers(t);
  32. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  33. }
  34. static void deinitialize_random_fifo_center_policy(unsigned sched_ctx_id)
  35. {
  36. struct starpu_sched_tree *tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  37. starpu_sched_tree_destroy(tree);
  38. }
  39. struct starpu_sched_policy _starpu_sched_modular_random_policy =
  40. {
  41. .init_sched = initialize_random_fifo_center_policy,
  42. .deinit_sched = deinitialize_random_fifo_center_policy,
  43. .add_workers = starpu_sched_tree_add_workers,
  44. .remove_workers = starpu_sched_tree_remove_workers,
  45. .push_task = starpu_sched_tree_push_task,
  46. .pop_task = starpu_sched_tree_pop_task,
  47. .pre_exec_hook = NULL,
  48. .post_exec_hook = NULL,
  49. .pop_every_task = NULL,
  50. .policy_name = "modular-random",
  51. .policy_description = "random modular policy",
  52. .worker_type = STARPU_WORKER_LIST,
  53. };
  54. /* Random scheduler with a priority queue for its scheduling window */
  55. static void initialize_random_prio_center_policy(unsigned sched_ctx_id)
  56. {
  57. struct starpu_sched_tree *t;
  58. struct starpu_sched_component * random_component;
  59. t = starpu_sched_tree_create(sched_ctx_id);
  60. t->root = starpu_sched_component_prio_create(t, NULL);
  61. random_component = starpu_sched_component_random_create(t, NULL);
  62. starpu_sched_component_connect(t->root, random_component);
  63. unsigned i;
  64. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  65. starpu_sched_component_connect(random_component, starpu_sched_component_worker_new(sched_ctx_id, i));
  66. starpu_sched_tree_update_workers(t);
  67. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  68. }
  69. static void deinitialize_random_prio_center_policy(unsigned sched_ctx_id)
  70. {
  71. struct starpu_sched_tree *tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  72. starpu_sched_tree_destroy(tree);
  73. }
  74. struct starpu_sched_policy _starpu_sched_modular_random_prio_policy =
  75. {
  76. .init_sched = initialize_random_prio_center_policy,
  77. .deinit_sched = deinitialize_random_prio_center_policy,
  78. .add_workers = starpu_sched_tree_add_workers,
  79. .remove_workers = starpu_sched_tree_remove_workers,
  80. .push_task = starpu_sched_tree_push_task,
  81. .pop_task = starpu_sched_tree_pop_task,
  82. .pre_exec_hook = NULL,
  83. .post_exec_hook = NULL,
  84. .pop_every_task = NULL,
  85. .policy_name = "modular-random-prio",
  86. .policy_description = "random-prio modular policy",
  87. .worker_type = STARPU_WORKER_LIST,
  88. };