sched_ctx_hypervisor.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include <starpu.h>
  2. #include <pthread.h>
  3. /* ioctl properties*/
  4. #define HYPERVISOR_MAX_IDLE -1
  5. #define HYPERVISOR_MIN_WORKING -2
  6. #define HYPERVISOR_PRIORITY -3
  7. #define HYPERVISOR_MIN_WORKERS -4
  8. #define HYPERVISOR_MAX_WORKERS -5
  9. #define HYPERVISOR_GRANULARITY -6
  10. #define HYPERVISOR_FIXED_WORKERS -7
  11. #define HYPERVISOR_MIN_TASKS -8
  12. #define HYPERVISOR_NEW_WORKERS_MAX_IDLE -9
  13. #define HYPERVISOR_TIME_TO_APPLY -10
  14. #define HYPERVISOR_EMPTY_CTX_MAX_IDLE -11
  15. pthread_mutex_t act_hypervisor_mutex;
  16. #define MAX_IDLE_TIME 5000000000
  17. #define MIN_WORKING_TIME 500
  18. struct policy_config {
  19. /* underneath this limit we cannot resize */
  20. int min_nworkers;
  21. /* above this limit we cannot resize */
  22. int max_nworkers;
  23. /*resize granularity */
  24. int granularity;
  25. /* priority for a worker to stay in this context */
  26. /* the smaller the priority the faster it will be moved */
  27. /* to another context */
  28. int priority[STARPU_NMAXWORKERS];
  29. /* above this limit the priority of the worker is reduced */
  30. double max_idle[STARPU_NMAXWORKERS];
  31. /* underneath this limit the priority of the worker is reduced */
  32. double min_working[STARPU_NMAXWORKERS];
  33. /* workers that will not move */
  34. int fixed_workers[STARPU_NMAXWORKERS];
  35. /* max idle for the workers that will be added during the resizing process*/
  36. double new_workers_max_idle;
  37. /* above this context we allow removing all workers */
  38. double empty_ctx_max_idle[STARPU_NMAXWORKERS];
  39. };
  40. struct resize_ack{
  41. int receiver_sched_ctx;
  42. int *moved_workers;
  43. int nmoved_workers;
  44. };
  45. struct sched_ctx_wrapper {
  46. unsigned sched_ctx;
  47. struct policy_config *config;
  48. double current_idle_time[STARPU_NMAXWORKERS];
  49. int pushed_tasks[STARPU_NMAXWORKERS];
  50. int poped_tasks[STARPU_NMAXWORKERS];
  51. double total_flops;
  52. double total_elapsed_flops[STARPU_NMAXWORKERS];
  53. double elapsed_flops[STARPU_NMAXWORKERS];
  54. double remaining_flops;
  55. double start_time;
  56. struct resize_ack resize_ack;
  57. };
  58. struct hypervisor_policy {
  59. const char* name;
  60. unsigned custom;
  61. void (*handle_idle_cycle)(unsigned sched_ctx, int worker);
  62. void (*handle_pushed_task)(unsigned sched_ctx, int worker);
  63. void (*handle_poped_task)(unsigned sched_ctx, int worker);
  64. void (*handle_idle_end)(unsigned sched_ctx, int worker);
  65. void (*handle_post_exec_hook)(unsigned sched_ctx, struct starpu_htbl32_node_s* resize_requests, int task_tag);
  66. };
  67. struct starpu_performance_counters* sched_ctx_hypervisor_init(struct hypervisor_policy* policy);
  68. void sched_ctx_hypervisor_shutdown(void);
  69. void sched_ctx_hypervisor_register_ctx(unsigned sched_ctx, double total_flops);
  70. void sched_ctx_hypervisor_unregister_ctx(unsigned sched_ctx);
  71. void sched_ctx_hypervisor_resize(unsigned sched_ctx, int task_tag);
  72. void sched_ctx_hypervisor_move_workers(unsigned sender_sched_ctx, unsigned receier_sched_ctx, int *workers_to_move, unsigned nworkers_to_move);
  73. void sched_ctx_hypervisor_stop_resize(unsigned sched_ctx);
  74. void sched_ctx_hypervisor_start_resize(unsigned sched_ctx);
  75. void sched_ctx_hypervisor_ioctl(unsigned sched_ctx, ...);
  76. void sched_ctx_hypervisor_set_config(unsigned sched_ctx, void *config);
  77. struct policy_config* sched_ctx_hypervisor_get_config(unsigned sched_ctx);
  78. void sched_ctx_hypervisor_steal_workers(unsigned sched_ctx, int *workers, int nworkers, int task_tag);
  79. int* sched_ctx_hypervisor_get_sched_ctxs();
  80. int sched_ctx_hypervisor_get_nsched_ctxs();
  81. struct sched_ctx_wrapper* sched_ctx_hypervisor_get_wrapper(unsigned sched_ctx);
  82. double sched_ctx_hypervisor_get_elapsed_flops_per_sched_ctx(struct sched_ctx_wrapper* sc_w);