modular_prio_prefetching.c 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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,2018 Université de Bordeaux
  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 <starpu_scheduler.h>
  20. #include <limits.h>
  21. /* Just as documentation example, here is the detailed equivalent of the
  22. * starpu_sched_component_initialize_simple_scheduler call below */
  23. #if 0
  24. static void initialize_prio_prefetching_center_policy(unsigned sched_ctx_id)
  25. {
  26. struct starpu_sched_tree *t;
  27. struct starpu_sched_component * eager_component;
  28. t = starpu_sched_tree_create(sched_ctx_id);
  29. t->root = starpu_sched_component_prio_create(t, NULL);
  30. eager_component = starpu_sched_component_eager_create(t, NULL);
  31. starpu_sched_component_connect(t->root, eager_component);
  32. struct starpu_sched_component_prio_data prio_data =
  33. {
  34. .ntasks_threshold = starpu_get_env_number_default("STARPU_NTASKS_THRESHOLD", _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT),
  35. .exp_len_threshold = starpu_get_env_float_default("STARPU_EXP_LEN_THRESHOLD", _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT),
  36. };
  37. unsigned i;
  38. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  39. {
  40. struct starpu_sched_component * worker_component = starpu_sched_component_worker_new(sched_ctx_id, i);
  41. struct starpu_sched_component * prio_component = starpu_sched_component_prio_create(t, &prio_data);
  42. starpu_sched_component_connect(prio_component, worker_component);
  43. starpu_sched_component_connect(eager_component, prio_component);
  44. }
  45. starpu_sched_tree_update_workers(t);
  46. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  47. /* The application may use any integer */
  48. if (starpu_sched_ctx_min_priority_is_set(sched_ctx_id) == 0)
  49. starpu_sched_ctx_set_min_priority(sched_ctx_id, INT_MIN);
  50. if (starpu_sched_ctx_max_priority_is_set(sched_ctx_id) == 0)
  51. starpu_sched_ctx_set_max_priority(sched_ctx_id, INT_MAX);
  52. }
  53. #endif
  54. static void initialize_prio_prefetching_center_policy(unsigned sched_ctx_id)
  55. {
  56. starpu_sched_component_initialize_simple_scheduler((starpu_sched_component_create_t) starpu_sched_component_eager_create, NULL,
  57. STARPU_SCHED_SIMPLE_DECIDE_WORKERS |
  58. STARPU_SCHED_SIMPLE_FIFO_ABOVE |
  59. STARPU_SCHED_SIMPLE_FIFO_ABOVE_PRIO |
  60. STARPU_SCHED_SIMPLE_FIFOS_BELOW |
  61. STARPU_SCHED_SIMPLE_IMPL, sched_ctx_id);
  62. }
  63. static void deinitialize_prio_prefetching_center_policy(unsigned sched_ctx_id)
  64. {
  65. struct starpu_sched_tree *tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  66. starpu_sched_tree_destroy(tree);
  67. }
  68. struct starpu_sched_policy _starpu_sched_modular_prio_prefetching_policy =
  69. {
  70. .init_sched = initialize_prio_prefetching_center_policy,
  71. .deinit_sched = deinitialize_prio_prefetching_center_policy,
  72. .add_workers = starpu_sched_tree_add_workers,
  73. .remove_workers = starpu_sched_tree_remove_workers,
  74. .push_task = starpu_sched_tree_push_task,
  75. .pop_task = starpu_sched_tree_pop_task,
  76. .pre_exec_hook = starpu_sched_component_worker_pre_exec_hook,
  77. .post_exec_hook = starpu_sched_component_worker_post_exec_hook,
  78. .pop_every_task = NULL,
  79. .policy_name = "modular-prio-prefetching",
  80. .policy_description = "prio prefetching modular policy",
  81. .worker_type = STARPU_WORKER_LIST,
  82. };