modular_random_prefetching.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-2015,2017 Inria
  4. * Copyright (C) 2014,2017 CNRS
  5. * Copyright (C) 2014,2017 Université de Bordeaux
  6. * Copyright (C) 2013 Simon Archipoff
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. #include <starpu_sched_component.h>
  20. #include <starpu_scheduler.h>
  21. #include <limits.h>
  22. #define _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT 2
  23. #define _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT 1000000000.0
  24. /* Random scheduler with fifo queues for its scheduling window and its workers. */
  25. static void initialize_random_fifo_prefetching_center_policy(unsigned sched_ctx_id)
  26. {
  27. struct starpu_sched_tree *t;
  28. struct starpu_sched_component * random_component;
  29. t = starpu_sched_tree_create(sched_ctx_id);
  30. t->root = starpu_sched_component_fifo_create(t, NULL);
  31. random_component = starpu_sched_component_random_create(t, NULL);
  32. starpu_sched_component_connect(t->root, random_component);
  33. struct starpu_sched_component_fifo_data fifo_data =
  34. {
  35. .ntasks_threshold = starpu_get_env_number_default("STARPU_NTASKS_THRESHOLD", _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT),
  36. .exp_len_threshold = starpu_get_env_float_default("STARPU_EXP_LEN_THRESHOLD", _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT),
  37. };
  38. unsigned i;
  39. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  40. {
  41. struct starpu_sched_component * worker_component = starpu_sched_component_worker_new(sched_ctx_id, i);
  42. struct starpu_sched_component * fifo_component = starpu_sched_component_fifo_create(t, &fifo_data);
  43. starpu_sched_component_connect(fifo_component, worker_component);
  44. starpu_sched_component_connect(random_component, fifo_component);
  45. }
  46. starpu_sched_tree_update_workers(t);
  47. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  48. }
  49. static void deinitialize_random_fifo_prefetching_center_policy(unsigned sched_ctx_id)
  50. {
  51. struct starpu_sched_tree *tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  52. starpu_sched_tree_destroy(tree);
  53. }
  54. struct starpu_sched_policy _starpu_sched_modular_random_prefetching_policy =
  55. {
  56. .init_sched = initialize_random_fifo_prefetching_center_policy,
  57. .deinit_sched = deinitialize_random_fifo_prefetching_center_policy,
  58. .add_workers = starpu_sched_tree_add_workers,
  59. .remove_workers = starpu_sched_tree_remove_workers,
  60. .push_task = starpu_sched_tree_push_task,
  61. .pop_task = starpu_sched_tree_pop_task,
  62. .pre_exec_hook = NULL,
  63. .post_exec_hook = NULL,
  64. .pop_every_task = NULL,
  65. .policy_name = "modular-random-prefetching",
  66. .policy_description = "random prefetching modular policy",
  67. .worker_type = STARPU_WORKER_LIST,
  68. };
  69. /* Random scheduler with priority queues for its scheduling window and its workers. */
  70. static void initialize_random_prio_prefetching_center_policy(unsigned sched_ctx_id)
  71. {
  72. struct starpu_sched_tree *t;
  73. struct starpu_sched_component *random_component;
  74. t = starpu_sched_tree_create(sched_ctx_id);
  75. t->root = starpu_sched_component_prio_create(t, NULL);
  76. random_component = starpu_sched_component_random_create(t, NULL);
  77. starpu_sched_component_connect(t->root, random_component);
  78. struct starpu_sched_component_prio_data prio_data =
  79. {
  80. .ntasks_threshold = starpu_get_env_number_default("STARPU_NTASKS_THRESHOLD", _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT),
  81. .exp_len_threshold = starpu_get_env_float_default("STARPU_EXP_LEN_THRESHOLD", _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT),
  82. };
  83. unsigned i;
  84. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  85. {
  86. struct starpu_sched_component * worker_component = starpu_sched_component_worker_new(sched_ctx_id, i);
  87. struct starpu_sched_component * prio_component = starpu_sched_component_prio_create(t, &prio_data);
  88. starpu_sched_component_connect(prio_component, worker_component);
  89. starpu_sched_component_connect(random_component, prio_component);
  90. }
  91. starpu_sched_tree_update_workers(t);
  92. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  93. /* The application may use any integer */
  94. if (starpu_sched_ctx_min_priority_is_set(sched_ctx_id) == 0)
  95. starpu_sched_ctx_set_min_priority(sched_ctx_id, INT_MIN);
  96. if (starpu_sched_ctx_max_priority_is_set(sched_ctx_id) == 0)
  97. starpu_sched_ctx_set_max_priority(sched_ctx_id, INT_MAX);
  98. }
  99. static void deinitialize_random_prio_prefetching_center_policy(unsigned sched_ctx_id)
  100. {
  101. struct starpu_sched_tree *tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  102. starpu_sched_tree_destroy(tree);
  103. }
  104. struct starpu_sched_policy _starpu_sched_modular_random_prio_prefetching_policy =
  105. {
  106. .init_sched = initialize_random_prio_prefetching_center_policy,
  107. .deinit_sched = deinitialize_random_prio_prefetching_center_policy,
  108. .add_workers = starpu_sched_tree_add_workers,
  109. .remove_workers = starpu_sched_tree_remove_workers,
  110. .push_task = starpu_sched_tree_push_task,
  111. .pop_task = starpu_sched_tree_pop_task,
  112. .pre_exec_hook = NULL,
  113. .post_exec_hook = NULL,
  114. .pop_every_task = NULL,
  115. .policy_name = "modular-random-prio-prefetching",
  116. .policy_description = "random-prio prefetching modular policy",
  117. .worker_type = STARPU_WORKER_LIST,
  118. };