scheduling_contexts.doxy 15 KB

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