sc_hypervisor.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 - 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. #ifndef SC_HYPERVISOR_H
  17. #define SC_HYPERVISOR_H
  18. #include <starpu.h>
  19. #include <starpu_sched_ctx_hypervisor.h>
  20. #include <sc_hypervisor_config.h>
  21. #include <sc_hypervisor_monitoring.h>
  22. #include <math.h>
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. /* synchronise the hypervisor when several workers try to update its information */
  28. starpu_pthread_mutex_t act_hypervisor_mutex;
  29. /* platform of resizing contexts */
  30. struct sc_hypervisor_policy
  31. {
  32. /* name of the strategy */
  33. const char* name;
  34. /* indicate if it is a policiy create by the user or not */
  35. unsigned custom;
  36. /* Distribute workers to contexts even at the begining of the program */
  37. void (*size_ctxs)(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
  38. /* Require explicit resizing */
  39. void (*resize_ctxs)(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
  40. /* the hypervisor takes a decision when the worker was idle for another cyle in this ctx */
  41. void (*handle_idle_cycle)(unsigned sched_ctx, int worker);
  42. /* the hypervisor takes a decision when another task was pushed on this worker in this ctx */
  43. void (*handle_pushed_task)(unsigned sched_ctx, int worker);
  44. /* the hypervisor takes a decision when another task was poped from this worker in this ctx */
  45. void (*handle_poped_task)(unsigned sched_ctx, int worker,struct starpu_task *task, uint32_t footprint);
  46. /* the hypervisor takes a decision when the worker stoped being idle in this ctx */
  47. void (*handle_idle_end)(unsigned sched_ctx, int worker);
  48. /* the hypervisor takes a decision when a certain task finished executing in this ctx */
  49. void (*handle_post_exec_hook)(unsigned sched_ctx, int task_tag);
  50. /* the hypervisor takes a decision when a job was submitted in this ctx */
  51. void (*handle_submitted_job)(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, size_t data_size);
  52. /* the hypervisor takes a decision when a certain ctx was deleted */
  53. void (*end_ctx)(unsigned sched_ctx);
  54. /* the hypervisor takes a decision when a certain ctx was registerd */
  55. void (*start_ctx)(unsigned sched_ctx);
  56. /* the hypervisor initializes values for the workers */
  57. void (*init_worker)(int workerid, unsigned sched_ctx);
  58. };
  59. /* start the hypervisor indicating the resizing policy to user */
  60. void* sc_hypervisor_init(struct sc_hypervisor_policy *policy);
  61. /* shutdown the hypervisor */
  62. void sc_hypervisor_shutdown(void);
  63. /* only registered contexts are resized by the hypervisor */
  64. void sc_hypervisor_register_ctx(unsigned sched_ctx, double total_flops);
  65. /* remove a worker from the hypervisor's list */
  66. void sc_hypervisor_unregister_ctx(unsigned sched_ctx);
  67. /* submit a requirement of resizing when a task taged with task_tag is executed */
  68. void sc_hypervisor_post_resize_request(unsigned sched_ctx, int task_tag);
  69. /* reevaluate the distribution of the resources and eventually resize if needed */
  70. void sc_hypervisor_resize_ctxs(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
  71. /* don't allow the hypervisor to resize a context */
  72. void sc_hypervisor_stop_resize(unsigned sched_ctx);
  73. /* allow the hypervisor to resize a context */
  74. void sc_hypervisor_start_resize(unsigned sched_ctx);
  75. /* check out the current policy of the hypervisor */
  76. const char *sc_hypervisor_get_policy();
  77. /* ask the hypervisor to add workers to a sched_ctx */
  78. void sc_hypervisor_add_workers_to_sched_ctx(int* workers_to_add, unsigned nworkers_to_add, unsigned sched_ctx);
  79. /* ask the hypervisor to remove workers from a sched_ctx */
  80. void sc_hypervisor_remove_workers_from_sched_ctx(int* workers_to_remove, unsigned nworkers_to_remove, unsigned sched_ctx, unsigned now);
  81. /* ask the hypervisor to move workers from one context to another */
  82. void sc_hypervisor_move_workers(unsigned sender_sched_ctx, unsigned receiver_sched_ctx, int *workers_to_move, unsigned nworkers_to_move, unsigned now);
  83. /* ask the hypervisor to chose a distribution of workers in the required contexts */
  84. void sc_hypervisor_size_ctxs(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
  85. /* check if there are pending demands of resizing */
  86. unsigned sc_hypervisor_get_size_req(unsigned **sched_ctxs, int* nsched_ctxs, int **workers, int *nworkers);
  87. /* save a demand of resizing */
  88. void sc_hypervisor_save_size_req(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
  89. /* clear the list of pending demands of resizing */
  90. void sc_hypervisor_free_size_req(void);
  91. /* check out if a context can be resized */
  92. unsigned sc_hypervisor_can_resize(unsigned sched_ctx);
  93. /* indicate the types of tasks a context will execute in order to better decide the sizing of ctxs */
  94. void sc_hypervisor_set_type_of_task(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, size_t data_size);
  95. /* change dynamically the total number of flops of a context, move the deadline of the finishing time of the context */
  96. void sc_hypervisor_update_diff_total_flops(unsigned sched_ctx, double diff_total_flops);
  97. /* change dynamically the number of the elapsed flops in a context, modify the past in order to better compute the speed */
  98. void sc_hypervisor_update_diff_elapsed_flops(unsigned sched_ctx, double diff_task_flops);
  99. /* updates the min and max workers needed by each context */
  100. void sc_hypervisor_update_resize_interval(unsigned *sched_ctxs, int nsched_ctxs, int max_nworkers);
  101. /* returns a list of contexts that are on the same level in the hierarchy of contexts */
  102. void sc_hypervisor_get_ctxs_on_level(unsigned **sched_ctxs, int *nsched_ctxs, unsigned hierarchy_level, unsigned father_sched_ctx_id);
  103. /* returns the number of levels of ctxs registered to the hyp */
  104. unsigned sc_hypervisor_get_nhierarchy_levels(void);
  105. /* return the leaves ctxs from the list of ctxs */
  106. void sc_hypervisor_get_leaves(unsigned *sched_ctxs, int nsched_ctxs, unsigned *leaves, int *nleaves);
  107. /* returns the nready flops of all ctxs below in hierachy of sched_ctx */
  108. double sc_hypervisor_get_nready_flops_of_all_sons_of_sched_ctx(unsigned sched_ctx);
  109. void sc_hypervisor_print_overhead();
  110. void sc_hypervisor_init_worker(int workerid, unsigned sched_ctx);
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #endif