modular_prio_prefetching.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 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. #include <starpu_sched_component.h>
  17. #include <starpu_scheduler.h>
  18. #define _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT 4
  19. #define _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT 1000000000.0
  20. static void initialize_prio_prefetching_center_policy(unsigned sched_ctx_id)
  21. {
  22. unsigned ntasks_threshold = _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT;
  23. double exp_len_threshold = _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT;
  24. const char *strval_ntasks_threshold = getenv("STARPU_NTASKS_THRESHOLD");
  25. if (strval_ntasks_threshold)
  26. ntasks_threshold = atof(strval_ntasks_threshold);
  27. const char *strval_exp_len_threshold = getenv("STARPU_EXP_LEN_THRESHOLD");
  28. if (strval_exp_len_threshold)
  29. exp_len_threshold = atof(strval_exp_len_threshold);
  30. starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
  31. struct starpu_sched_tree *t = starpu_sched_tree_create(sched_ctx_id);
  32. t->root = starpu_sched_component_prio_create(t, NULL);
  33. struct starpu_sched_component * eager_component = starpu_sched_component_eager_create(t, NULL);
  34. t->root->add_child(t->root, eager_component);
  35. eager_component->add_parent(eager_component, t->root);
  36. struct starpu_prio_data prio_data =
  37. {
  38. .ntasks_threshold = ntasks_threshold,
  39. .exp_len_threshold = exp_len_threshold,
  40. };
  41. unsigned i;
  42. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  43. {
  44. struct starpu_sched_component * worker_component = starpu_sched_component_worker_get(sched_ctx_id, i);
  45. STARPU_ASSERT(worker_component);
  46. struct starpu_sched_component * prio_component = starpu_sched_component_prio_create(t, &prio_data);
  47. prio_component->add_child(prio_component, worker_component);
  48. worker_component->add_parent(worker_component, prio_component);
  49. eager_component->add_child(eager_component, prio_component);
  50. prio_component->add_parent(prio_component, eager_component);
  51. }
  52. starpu_sched_tree_update_workers(t);
  53. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  54. }
  55. static void deinitialize_prio_prefetching_center_policy(unsigned sched_ctx_id)
  56. {
  57. struct starpu_sched_tree *tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  58. starpu_sched_tree_destroy(tree);
  59. starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
  60. }
  61. struct starpu_sched_policy _starpu_sched_modular_prio_prefetching_policy =
  62. {
  63. .init_sched = initialize_prio_prefetching_center_policy,
  64. .deinit_sched = deinitialize_prio_prefetching_center_policy,
  65. .add_workers = starpu_sched_tree_add_workers,
  66. .remove_workers = starpu_sched_tree_remove_workers,
  67. .push_task = starpu_sched_tree_push_task,
  68. .pop_task = starpu_sched_tree_pop_task,
  69. .pre_exec_hook = starpu_sched_component_worker_pre_exec_hook,
  70. .post_exec_hook = starpu_sched_component_worker_post_exec_hook,
  71. .pop_every_task = NULL,
  72. .policy_name = "modular-prio-prefetching",
  73. .policy_description = "prio prefetching modular policy"
  74. };