sc_hypervisor.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <sc_hypervisor_config.h>
  20. #include <sc_hypervisor_monitoring.h>
  21. #include <math.h>
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif
  26. /* synchronise the hypervisor when several workers try to update its information */
  27. starpu_pthread_mutex_t act_hypervisor_mutex;
  28. /* Forward declaration of an internal data structure
  29. * FIXME: Remove when no longer exposed. */
  30. /* the resizing is not done instantly, a request is kept and executed
  31. when available */
  32. struct resize_request_entry;
  33. /* platform of resizing contexts */
  34. struct sc_hypervisor_policy
  35. {
  36. /* name of the strategy */
  37. const char* name;
  38. /* indicate if it is a policiy create by the user or not */
  39. unsigned custom;
  40. /* Distribute workers to contexts even at the begining of the program */
  41. void (*size_ctxs)(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
  42. /* Require explicit resizing */
  43. void (*resize_ctxs)(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
  44. /* the hypervisor takes a decision when the worker was idle for another cyle in this ctx */
  45. void (*handle_idle_cycle)(unsigned sched_ctx, int worker);
  46. /* the hypervisor takes a decision when another task was pushed on this worker in this ctx */
  47. void (*handle_pushed_task)(unsigned sched_ctx, int worker);
  48. /* the hypervisor takes a decision when another task was poped from this worker in this ctx */
  49. void (*handle_poped_task)(unsigned sched_ctx, int worker,struct starpu_task *task, uint32_t footprint);
  50. /* the hypervisor takes a decision when the worker stoped being idle in this ctx */
  51. void (*handle_idle_end)(unsigned sched_ctx, int worker);
  52. /* the hypervisor takes a decision when a certain task finished executing in this ctx */
  53. void (*handle_post_exec_hook)(unsigned sched_ctx, int task_tag);
  54. /* the hypervisor takes a decision when a job was submitted in this ctx */
  55. void (*handle_submitted_job)(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, size_t data_size);
  56. /* the hypervisor takes a decision when a certain ctx was deleted */
  57. void (*end_ctx)(unsigned sched_ctx);
  58. };
  59. /* start the hypervisor indicating the resizing policy to user */
  60. struct starpu_sched_ctx_performance_counters *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(int *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(int *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(int **sched_ctxs, int* nsched_ctxs, int **workers, int *nworkers);
  87. /* save a demand of resizing */
  88. void sc_hypervisor_save_size_req(int *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. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif