scheduling_contexts.doxy 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * This file is part of the StarPU Handbook.
  3. * Copyright (C) 2009--2011 Universit@'e de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2016 CNRS
  5. * Copyright (C) 2011, 2012 INRIA
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \defgroup API_Scheduling_Contexts Scheduling Contexts
  9. \brief StarPU permits on one hand grouping workers in combined workers
  10. in order to execute a parallel task and on the other hand grouping
  11. tasks in bundles that will be executed by a single specified worker.
  12. In contrast when we group workers in scheduling contexts we submit
  13. starpu tasks to them and we schedule them with the policy assigned to
  14. the context. Scheduling contexts can be created, deleted and modified
  15. dynamically.
  16. \struct starpu_sched_ctx_performance_counters
  17. Performance counters used by the starpu to indicate the
  18. hypervisor how the application and the resources are executing.
  19. \ingroup API_Scheduling_Contexts
  20. \var void (*starpu_sched_ctx_performance_counters::notify_idle_cycle)(unsigned sched_ctx_id, int worker, double idle_time)
  21. Informs the hypervisor for how long a worker has been idle in the specified context
  22. \var void (*starpu_sched_ctx_performance_counters::notify_pushed_task)(unsigned sched_ctx_id, int worker)
  23. Notifies the hypervisor that a task has been scheduled on the queue of the worker corresponding to the specified context
  24. \var void (*starpu_sched_ctx_performance_counters::notify_poped_task)(unsigned sched_ctx_id, int worker)
  25. Informs the hypervisor that a task executing a specified number of instructions has been poped from the worker
  26. \var void (*starpu_sched_ctx_performance_counters::notify_post_exec_task)(struct starpu_task *task, size_t data_size, uint32_t footprint, int hypervisor_tag, double flops)
  27. Notifies the hypervisor that a task has just been executed
  28. \var void (*starpu_sched_ctx_performance_counters::notify_submitted_job)(struct starpu_task *task, uint32_t footprint, size_t data_size)
  29. Notifies the hypervisor that a task has just been submitted
  30. \var void (*starpu_sched_ctx_performance_counters::notify_delete_context)(unsigned sched_ctx)
  31. Notifies the hypervisor that the context was deleted
  32. @name Scheduling Contexts Basic API
  33. \ingroup API_Scheduling_Contexts
  34. \def STARPU_NMAX_SCHED_CTXS
  35. \ingroup API_Scheduling_Policy
  36. Define the maximum number of scheduling contexts managed by StarPU. The default value can be
  37. modified at configure by using the option \ref enable-max-sched-ctxs "--enable-max-sched-ctxs".
  38. \fn unsigned starpu_sched_ctx_create(int *workerids_ctx, int nworkers_ctx, const char *sched_ctx_name, ...)
  39. \ingroup API_Scheduling_Contexts
  40. This function creates a scheduling context with the given parameters
  41. (see below) and assigns the workers in \p workerids_ctx to execute the
  42. tasks submitted to it. The return value represents the identifier of
  43. the context that has just been created. It will be further used to
  44. indicate the context the tasks will be submitted to. The return value
  45. should be at most \ref STARPU_NMAX_SCHED_CTXS.
  46. The arguments following the name of the scheduling context can be of
  47. the following types:
  48. <ul>
  49. <li> ::STARPU_SCHED_CTX_POLICY_NAME, followed by the name of a
  50. predefined scheduling policy
  51. </li>
  52. <li> ::STARPU_SCHED_CTX_POLICY_STRUCT, followed by a pointer to a
  53. custom scheduling policy (struct starpu_sched_policy *)
  54. </li>
  55. <li> ::STARPU_SCHED_CTX_POLICY_MIN_PRIO, followed by a integer
  56. representing the minimum priority value to be defined for the
  57. scheduling policy.
  58. </li>
  59. <li> ::STARPU_SCHED_CTX_POLICY_MAX_PRIO, followed by a integer
  60. representing the maximum priority value to be defined for the
  61. scheduling policy.
  62. </li>
  63. <li> ::STARPU_SCHED_CTX_POLICY_INIT, followed by a function pointer
  64. (ie. void init_sched(void)) allowing to initialize the scheduling policy.
  65. </li>
  66. <li> ::STARPU_SCHED_CTX_USER_DATA, followed by a pointer
  67. to a custom user data structure, to be retrieved by \ref starpu_sched_ctx_get_user_data().
  68. </li>
  69. </ul>
  70. \def STARPU_SCHED_CTX_POLICY_NAME
  71. \ingroup API_Scheduling_Contexts
  72. This macro is used when calling starpu_sched_ctx_create() to specify a
  73. name for a scheduling policy
  74. \def STARPU_SCHED_CTX_POLICY_STRUCT
  75. \ingroup API_Scheduling_Contexts
  76. This macro is used when calling starpu_sched_ctx_create() to specify a
  77. pointer to a scheduling policy
  78. \def STARPU_SCHED_CTX_POLICY_MIN_PRIO
  79. \ingroup API_Scheduling_Contexts
  80. This macro is used when calling starpu_sched_ctx_create() to specify a
  81. minimum scheduler priority value.
  82. \def STARPU_SCHED_CTX_POLICY_MAX_PRIO
  83. \ingroup API_Scheduling_Contexts
  84. This macro is used when calling starpu_sched_ctx_create() to specify a
  85. maximum scheduler priority value.
  86. \def STARPU_SCHED_CTX_POLICY_INIT
  87. \ingroup API_Scheduling_Contexts
  88. This macro is used when calling starpu_sched_ctx_create() to specify a
  89. function pointer allowing to initialize the scheduling policy.
  90. \def STARPU_SCHED_CTX_USER_DATA
  91. \ingroup API_Scheduling_Contexts
  92. This macro is used when calling starpu_sched_ctx_create() to specify a
  93. pointer to some user data related to the context being created.
  94. \fn unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const char *sched_ctx_name, int min_ncpus, int max_ncpus, int min_ngpus, int max_ngpus, unsigned allow_overlap)
  95. \ingroup API_Scheduling_Contexts
  96. Create a context indicating an approximate interval of resources
  97. \fn void starpu_sched_ctx_register_close_callback(unsigned sched_ctx_id, void (*close_callback)(unsigned sched_ctx_id, void* args), void *args)
  98. \ingroup API_Scheduling_Contexts
  99. Execute the callback whenever the last task of the context finished executing, it is called with the pramaters: sched_ctx and any other paramter needed
  100. by the application (packed in a void*)
  101. \fn void starpu_sched_ctx_add_workers(int *workerids_ctx, int nworkers_ctx, unsigned sched_ctx_id)
  102. \ingroup API_Scheduling_Contexts
  103. This function adds dynamically the workers in \p workerids_ctx to the
  104. context \p sched_ctx_id. The last argument cannot be greater than
  105. \ref STARPU_NMAX_SCHED_CTXS.
  106. \fn void starpu_sched_ctx_remove_workers(int *workerids_ctx, int nworkers_ctx, unsigned sched_ctx_id)
  107. \ingroup API_Scheduling_Contexts
  108. This function removes the workers in \p workerids_ctx from the context
  109. \p sched_ctx_id. The last argument cannot be greater than
  110. STARPU_NMAX_SCHED_CTXS.
  111. \fn void starpu_sched_ctx_display_workers(unsigned sched_ctx_id, FILE *f)
  112. \ingroup API_Scheduling_Contexts
  113. This function prints on the file \p f the worker names belonging to the context \p sched_ctx_id
  114. \fn void starpu_sched_ctx_delete(unsigned sched_ctx_id)
  115. \ingroup API_Scheduling_Contexts
  116. Delete scheduling context \p sched_ctx_id and transfer remaining
  117. workers to the inheritor scheduling context.
  118. \fn void starpu_sched_ctx_set_inheritor(unsigned sched_ctx_id, unsigned inheritor)
  119. \ingroup API_Scheduling_Contexts
  120. Indicate which context whill inherit the resources of this context
  121. when he will be deleted.
  122. \fn void starpu_sched_ctx_set_context(unsigned *sched_ctx_id)
  123. \ingroup API_Scheduling_Contexts
  124. Set the scheduling context the subsequent tasks will be submitted to
  125. \fn unsigned starpu_sched_ctx_get_context(void)
  126. \ingroup API_Scheduling_Contexts
  127. Return the scheduling context the tasks are currently submitted to,
  128. or ::STARPU_NMAX_SCHED_CTXS if no default context has been defined
  129. by calling the function starpu_sched_ctx_set_context().
  130. \fn void starpu_sched_ctx_stop_task_submission(void)
  131. \ingroup API_Scheduling_Contexts
  132. Stop submitting tasks from the empty context list until the next time
  133. the context has time to check the empty context list
  134. \fn void starpu_sched_ctx_finished_submit(unsigned sched_ctx_id)
  135. \ingroup API_Scheduling_Contexts
  136. Indicate starpu that the application finished submitting to this
  137. context in order to move the workers to the inheritor as soon as
  138. possible.
  139. \fn unsigned starpu_sched_ctx_get_workers_list(unsigned sched_ctx_id, int **workerids)
  140. \ingroup API_Scheduling_Contexts
  141. Returns the list of workers in the array \p workerids, the returned value is the
  142. number of workers. The user should free the \p workerids table after finishing
  143. using it (it is allocated inside the function with the proper size)
  144. \fn unsigned starpu_sched_ctx_get_workers_list_raw(unsigned sched_ctx_id, int **workerids)
  145. \ingroup API_Scheduling_Contexts
  146. Returns the list of workers in the array \p workerids, the returned value is the
  147. number of workers. This list is provided in raw order, i.e. not sorted by tree or list order,
  148. and the user should not free the \p workerids table.
  149. This function is thus much less costly than starpu_sched_ctx_get_workers_list.
  150. \fn unsigned starpu_sched_ctx_get_nworkers(unsigned sched_ctx_id)
  151. \ingroup API_Scheduling_Contexts
  152. Return the number of workers managed by the specified contexts
  153. (Usually needed to verify if it manages any workers or if it should be
  154. blocked)
  155. \fn unsigned starpu_sched_ctx_get_nshared_workers(unsigned sched_ctx_id, unsigned sched_ctx_id2)
  156. \ingroup API_Scheduling_Contexts
  157. Return the number of workers shared by two contexts.
  158. \fn unsigned starpu_sched_ctx_contains_worker(int workerid, unsigned sched_ctx_id)
  159. \ingroup API_Scheduling_Contexts
  160. Return 1 if the worker belongs to the context and 0 otherwise
  161. \fn unsigned starpu_sched_ctx_worker_get_id(unsigned sched_ctx_id)
  162. \ingroup API_Scheduling_Contexts
  163. Return the workerid if the worker belongs to the context and -1 otherwise.
  164. If the thread calling this function is not a worker the function returns -1
  165. as it calls the function starpu_worker_get_id().
  166. \fn unsigned starpu_sched_ctx_overlapping_ctxs_on_worker(int workerid)
  167. \ingroup API_Scheduling_Contexts
  168. Check if a worker is shared between several contexts
  169. @name Scheduling Context Priorities
  170. \ingroup API_Scheduling_Contexts
  171. \def STARPU_MIN_PRIO
  172. \ingroup API_Scheduling_Contexts
  173. Provided for legacy reasons.
  174. \def STARPU_MAX_PRIO
  175. \ingroup API_Scheduling_Contexts
  176. Provided for legacy reasons.
  177. \def STARPU_DEFAULT_PRIO
  178. \ingroup API_Scheduling_Contexts
  179. By convention, the default priority level should be 0 so that we can
  180. statically allocate tasks with a default priority.
  181. \fn int starpu_sched_ctx_set_min_priority(unsigned sched_ctx_id, int min_prio)
  182. \ingroup API_Scheduling_Contexts
  183. Defines the minimum task priority level supported by the scheduling
  184. policy of the given scheduler context. The default minimum priority
  185. level is the same as the default priority level which is 0 by
  186. convention. The application may access that value by calling the function
  187. starpu_sched_ctx_get_min_priority(). This function should only
  188. be called from the initialization method of the scheduling policy, and
  189. should not be used directly from the application.
  190. \fn int starpu_sched_ctx_set_max_priority(unsigned sched_ctx_id, int max_prio)
  191. \ingroup API_Scheduling_Contexts
  192. Defines the maximum priority level supported by the scheduling policy
  193. of the given scheduler context. The default maximum priority level is
  194. 1. The application may access that value by calling the
  195. starpu_sched_ctx_get_max_priority function. This function should only
  196. be called from the initialization method of the scheduling policy, and
  197. should not be used directly from the application.
  198. \fn int starpu_sched_ctx_get_min_priority(unsigned sched_ctx_id)
  199. \ingroup API_Scheduling_Contexts
  200. Returns the current minimum priority level supported by the scheduling
  201. policy of the given scheduler context.
  202. \fn int starpu_sched_ctx_get_max_priority(unsigned sched_ctx_id)
  203. \ingroup API_Scheduling_Contexts
  204. Returns the current maximum priority level supported by the scheduling
  205. policy of the given scheduler context.
  206. \fn int starpu_sched_ctx_min_priority_is_set(unsigned sched_ctx_id)
  207. \ingroup API_Scheduling_Contexts
  208. todo
  209. \fn int starpu_sched_ctx_max_priority_is_set(unsigned sched_ctx_id)
  210. \ingroup API_Scheduling_Contexts
  211. todo
  212. \fn void *starpu_sched_ctx_get_user_data(unsigned sched_ctx_id)
  213. \ingroup API_Scheduling_Contexts
  214. Return the user data pointer associated to the scheduling context.
  215. @name Scheduling Context Worker Collection
  216. \ingroup API_Scheduling_Contexts
  217. \fn struct starpu_worker_collection *starpu_sched_ctx_create_worker_collection(unsigned sched_ctx_id, enum starpu_worker_collection_type type)
  218. \ingroup API_Scheduling_Contexts
  219. Create a worker collection of the type indicated by the last parameter
  220. for the context specified through the first parameter.
  221. \fn void starpu_sched_ctx_delete_worker_collection(unsigned sched_ctx_id)
  222. \ingroup API_Scheduling_Contexts
  223. Delete the worker collection of the specified scheduling context
  224. \fn struct starpu_worker_collection *starpu_sched_ctx_get_worker_collection(unsigned sched_ctx_id)
  225. \ingroup API_Scheduling_Contexts
  226. Return the worker collection managed by the indicated context
  227. @name Scheduling Context Link with Hypervisor
  228. \ingroup API_Scheduling_Contexts
  229. \fn void starpu_sched_ctx_set_perf_counters(unsigned sched_ctx_id, void *perf_counters)
  230. \ingroup API_Scheduling_Contexts
  231. Indicates to starpu the pointer to the performance counter
  232. \fn void starpu_sched_ctx_call_pushed_task_cb(int workerid, unsigned sched_ctx_id)
  233. \ingroup API_Scheduling_Contexts
  234. Callback that lets the scheduling policy tell the hypervisor that a
  235. task was pushed on a worker
  236. \fn void starpu_sched_ctx_notify_hypervisor_exists(void)
  237. \ingroup API_Scheduling_Contexts
  238. Allow the hypervisor to let starpu know he's initialised
  239. \fn unsigned starpu_sched_ctx_check_if_hypervisor_exists(void)
  240. \ingroup API_Scheduling_Contexts
  241. Ask starpu if he is informed if the hypervisor is initialised
  242. \fn void starpu_sched_ctx_set_policy_data(unsigned sched_ctx_id, void *policy_data)
  243. \ingroup API_Scheduling_Contexts
  244. Allocate the scheduling policy data (private information of the scheduler like queues, variables,
  245. additional condition variables) the context
  246. \fn void *starpu_sched_ctx_get_policy_data(unsigned sched_ctx_id)
  247. \ingroup API_Scheduling_Contexts
  248. Return the scheduling policy data (private information of the scheduler) of the contexts previously
  249. assigned to.
  250. \fn void *starpu_sched_ctx_exec_parallel_code(void* (*func)(void*), void *param, unsigned sched_ctx_id)
  251. \ingroup API_Scheduling_Contexts
  252. execute any parallel code on the workers of the sched_ctx (workers are blocked)
  253. \fn int starpu_sched_ctx_get_nready_tasks(unsigned sched_ctx_id)
  254. \ingroup API_Scheduling_Contexts
  255. todo
  256. \fn double starpu_sched_ctx_get_nready_flops(unsigned sched_ctx_id)
  257. \ingroup API_Scheduling_Contexts
  258. todo
  259. */