starpu_sched_ctx.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 - 2012 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 __STARPU_SCHED_CTX_H__
  17. #define __STARPU_SCHED_CTX_H__
  18. #include <starpu.h>
  19. #ifdef __cplusplus
  20. extern "C"
  21. {
  22. #endif
  23. /*
  24. * MANAGEMENT OF SCHEDULING CONTEXTS
  25. */
  26. /* create a context indicating the scheduling policy, the workers it should have and a potential name */
  27. unsigned starpu_sched_ctx_create(const char *policy_name, int *workerids_ctx, int nworkers_ctx, const char *sched_ctx_name);
  28. /* create a context indicating an approximate interval of resources */
  29. unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const char *sched_name,
  30. int min_ncpus, int max_ncpus, int min_ngpus, int max_ngpus,
  31. unsigned allow_overlap);
  32. /* add workers to a context */
  33. void starpu_sched_ctx_add_workers(int *workerids_ctx, int nworkers_ctx, unsigned sched_ctx_id);
  34. /* remove workers from a context */
  35. void starpu_sched_ctx_remove_workers(int *workerids_ctx, int nworkers_ctx, unsigned sched_ctx_id);
  36. /* delete a certain context */
  37. void starpu_sched_ctx_delete(unsigned sched_ctx_id);
  38. /* indicate which context whill inherit the resources of this context when he will be deleted */
  39. void starpu_sched_ctx_set_inheritor(unsigned sched_ctx_id, unsigned inheritor);
  40. /* mutex synchronising several simultaneous modifications of a context */
  41. starpu_pthread_mutex_t* starpu_sched_ctx_get_changing_ctx_mutex(unsigned sched_ctx_id);
  42. /* indicate that the current thread is submitting only to the current context */
  43. void starpu_sched_ctx_set_context(unsigned *sched_ctx_id);
  44. /* find out to which context is submitting the current thread */
  45. unsigned starpu_sched_ctx_get_context(void);
  46. /* stop submitting tasks from the empty context list until the next time the context has
  47. time to check the empty context list*/
  48. void starpu_sched_ctx_stop_task_submission(void);
  49. /* indicate starpu that hte application finished submitting to this context in order to
  50. move the workers to the inheritor as soon as possible */
  51. void starpu_sched_ctx_finished_submit(unsigned sched_ctx_id);
  52. /*
  53. * CONNECTION WITH THE HYPERVISOR
  54. */
  55. /* performance counters used by the starpu to indicate the hypervisor
  56. how the application and the resources are executing */
  57. struct starpu_sched_ctx_performance_counters
  58. {
  59. /* tell the hypervisor for how long a worker was idle in a certain context */
  60. void (*notify_idle_cycle)(unsigned sched_ctx_id, int worker, double idle_time);
  61. /* tell the hypervisor when a worker stoped being idle in a certain context */
  62. void (*notify_idle_end)(unsigned sched_ctx_id, int worker);
  63. /* tell the hypervisor when a task was pushed on a worker in a certain context */
  64. void (*notify_pushed_task)(unsigned sched_ctx_id, int worker);
  65. /* tell the hypervisor when a task was poped from a worker in a certain context */
  66. void (*notify_poped_task)(unsigned sched_ctx_id, int worker, struct starpu_task *task, size_t data_size, uint32_t footprint);
  67. /* tell the hypervisor when a task finished executing in a certain context */
  68. void (*notify_post_exec_hook)(unsigned sched_ctx_id, int taskid);
  69. /* tell the hypervisor when a task was submitted to a certain context */
  70. void (*notify_submitted_job)(struct starpu_task *task, uint32_t footprint);
  71. /* tell the hypervisor when a context was deleted */
  72. void (*notify_delete_context)(unsigned sched_ctx);
  73. };
  74. #ifdef STARPU_USE_SC_HYPERVISOR
  75. /* indicates to starpu the pointer to the performance counte */
  76. void starpu_sched_ctx_set_perf_counters(unsigned sched_ctx_id, struct starpu_sched_ctx_performance_counters *perf_counters);
  77. /* callback that lets the scheduling policy tell the hypervisor that a task was pushed on a worker */
  78. void starpu_sched_ctx_call_pushed_task_cb(int workerid, unsigned sched_ctx_id);
  79. #endif //STARPU_USE_SC_HYPERVISOR
  80. /* allow the hypervisor to let starpu know he's initialised */
  81. void starpu_sched_ctx_notify_hypervisor_exists(void);
  82. /* ask starpu if he is informed if the hypervisor is initialised */
  83. unsigned starpu_sched_ctx_check_if_hypervisor_exists(void);
  84. /*
  85. * POLICY DATA
  86. */
  87. /* allow the scheduling policy to have its own data in a context, like a private list of tasks, mutexes, conds, etc. */
  88. void starpu_sched_ctx_set_policy_data(unsigned sched_ctx_id, void *policy_data);
  89. /* return the scheduling policy private data */
  90. void* starpu_sched_ctx_get_policy_data(unsigned sched_ctx_id);
  91. /*
  92. * WORKERS IN CONTEXT
  93. */
  94. /* create a worker collection for a context, the type can be only STARPU_WORKER_LIST for now, which corresponds to a simple list */
  95. struct starpu_worker_collection* starpu_sched_ctx_create_worker_collection(unsigned sched_ctx_id, int type);
  96. /* free the worker collection when removing the context */
  97. void starpu_sched_ctx_delete_worker_collection(unsigned sched_ctx_id);
  98. /*return the worker collection */
  99. struct starpu_worker_collection* starpu_sched_ctx_get_worker_collection(unsigned sched_ctx_id);
  100. /* return the number of workers in the sched_ctx's collection */
  101. unsigned starpu_sched_ctx_get_nworkers(unsigned sched_ctx_id);
  102. /* return the number of shared workers in the sched_ctx's collection */
  103. unsigned starpu_sched_ctx_get_nshared_workers(unsigned sched_ctx_id, unsigned sched_ctx_id2);
  104. /* return 1 if the worker belongs to the context and 0 otherwise */
  105. unsigned starpu_sched_ctx_contains_worker(int workerid, unsigned sched_ctx_id);
  106. /* check if a worker is shared between several contexts */
  107. unsigned starpu_sched_ctx_overlapping_ctxs_on_worker(int workerid);
  108. /* manage sharing of resources between contexts: checkOB which ctx has its turn to pop */
  109. unsigned starpu_sched_ctx_is_ctxs_turn(int workerid, unsigned sched_ctx_id);
  110. /* manage sharing of resources between contexts: by default a round_robin strategy
  111. is executed but the user can interfere to tell which ctx has its turn to pop */
  112. void starpu_sched_ctx_set_turn_to_other_ctx(int workerid, unsigned sched_ctx_id);
  113. /* time sharing a resources, indicate how long a worker has been active in
  114. the current sched_ctx */
  115. double starpu_sched_ctx_get_max_time_worker_on_ctx(void);
  116. /*
  117. * Priorities
  118. */
  119. /* get min priority for the scheduler of the global context */
  120. int starpu_sched_get_min_priority(void);
  121. /* get max priority for the scheduler of the global context */
  122. int starpu_sched_get_max_priority(void);
  123. /* set min priority for the scheduler of the global context */
  124. int starpu_sched_set_min_priority(int min_prio);
  125. /* set max priority for the scheduler of the global context */
  126. int starpu_sched_set_max_priority(int max_prio);
  127. /* get min priority for the scheduler of the scheduling context indicated */
  128. int starpu_sched_ctx_get_min_priority(unsigned sched_ctx_id);
  129. /* get max priority for the scheduler of the scheduling context indicated */
  130. int starpu_sched_ctx_get_max_priority(unsigned sched_ctx_id);
  131. /* set min priority for the scheduler of the scheduling context indicated */
  132. int starpu_sched_ctx_set_min_priority(unsigned sched_ctx_id, int min_prio);
  133. /* set max priority for the scheduler of the scheduling context indicated */
  134. int starpu_sched_ctx_set_max_priority(unsigned sched_ctx_id, int max_prio);
  135. /* Provided for legacy reasons */
  136. #define STARPU_MIN_PRIO (starpu_sched_get_min_priority())
  137. #define STARPU_MAX_PRIO (starpu_sched_get_max_priority())
  138. /* By convention, the default priority level should be 0 so that we can
  139. * statically allocate tasks with a default priority. */
  140. #define STARPU_DEFAULT_PRIO 0
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif /* __STARPU_SCHED_CTX_H__ */