sc_hypervisor.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. /* synchronise the hypervisor when several workers try to update its information */
  26. starpu_pthread_mutex_t act_hypervisor_mutex;
  27. /* Forward declaration of an internal data structure
  28. * FIXME: Remove when no longer exposed. */
  29. /* the resizing is not done instantly, a request is kept and executed
  30. when available */
  31. struct resize_request_entry;
  32. /* platform of resizing contexts */
  33. struct sc_hypervisor_policy
  34. {
  35. /* name of the strategy */
  36. const char* name;
  37. /* indicate if it is a policiy create by the user or not */
  38. unsigned custom;
  39. /* Distribute workers to contexts even at the begining of the program */
  40. void (*size_ctxs)(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
  41. /* Require explicit resizing */
  42. void (*resize_ctxs)(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
  43. /* the hypervisor takes a decision when the worker was idle for another cyle in this ctx */
  44. void (*handle_idle_cycle)(unsigned sched_ctx, int worker);
  45. /* the hypervisor takes a decision when another task was pushed on this worker in this ctx */
  46. void (*handle_pushed_task)(unsigned sched_ctx, int worker);
  47. /* the hypervisor takes a decision when another task was poped from this worker in this ctx */
  48. void (*handle_poped_task)(unsigned sched_ctx, int worker,struct starpu_task *task, uint32_t footprint);
  49. /* the hypervisor takes a decision when the worker stoped being idle in this ctx */
  50. void (*handle_idle_end)(unsigned sched_ctx, int worker);
  51. /* the hypervisor takes a decision when a certain task finished executing in this ctx */
  52. void (*handle_post_exec_hook)(unsigned sched_ctx, int task_tag);
  53. /* the hypervisor takes a decision when a job was submitted in this ctx */
  54. void (*handle_submitted_job)(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, size_t data_size);
  55. /* the hypervisor takes a decision when a certain ctx was deleted */
  56. void (*end_ctx)(unsigned sched_ctx);
  57. };
  58. /* start the hypervisor indicating the resizing policy to user */
  59. struct starpu_sched_ctx_performance_counters *sc_hypervisor_init(struct sc_hypervisor_policy *policy);
  60. /* shutdown the hypervisor */
  61. void sc_hypervisor_shutdown(void);
  62. /* only registered contexts are resized by the hypervisor */
  63. void sc_hypervisor_register_ctx(unsigned sched_ctx, double total_flops);
  64. /* remove a worker from the hypervisor's list */
  65. void sc_hypervisor_unregister_ctx(unsigned sched_ctx);
  66. /* submit a requirement of resizing when a task taged with task_tag is executed */
  67. void sc_hypervisor_post_resize_request(unsigned sched_ctx, int task_tag);
  68. /* reevaluate the distribution of the resources and eventually resize if needed */
  69. void sc_hypervisor_resize_ctxs(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
  70. /* don't allow the hypervisor to resize a context */
  71. void sc_hypervisor_stop_resize(unsigned sched_ctx);
  72. /* allow the hypervisor to resize a context */
  73. void sc_hypervisor_start_resize(unsigned sched_ctx);
  74. /* check out the current policy of the hypervisor */
  75. const char *sc_hypervisor_get_policy();
  76. /* ask the hypervisor to add workers to a sched_ctx */
  77. void sc_hypervisor_add_workers_to_sched_ctx(int* workers_to_add, unsigned nworkers_to_add, unsigned sched_ctx);
  78. /* ask the hypervisor to remove workers from a sched_ctx */
  79. void sc_hypervisor_remove_workers_from_sched_ctx(int* workers_to_remove, unsigned nworkers_to_remove, unsigned sched_ctx, unsigned now);
  80. /* ask the hypervisor to move workers from one context to another */
  81. void sc_hypervisor_move_workers(unsigned sender_sched_ctx, unsigned receiver_sched_ctx, int *workers_to_move, unsigned nworkers_to_move, unsigned now);
  82. /* ask the hypervisor to chose a distribution of workers in the required contexts */
  83. void sc_hypervisor_size_ctxs(int *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
  84. /* check if there are pending demands of resizing */
  85. unsigned sc_hypervisor_get_size_req(int **sched_ctxs, int* nsched_ctxs, int **workers, int *nworkers);
  86. /* save a demand of resizing */
  87. void sc_hypervisor_save_size_req(int *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
  88. /* clear the list of pending demands of resizing */
  89. void sc_hypervisor_free_size_req(void);
  90. /* check out if a context can be resized */
  91. unsigned sc_hypervisor_can_resize(unsigned sched_ctx);
  92. /* indicate the types of tasks a context will execute in order to better decide the sizing of ctxs */
  93. void sc_hypervisor_set_type_of_task(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, size_t data_size);
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif