scheduling_policy.doxy 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013 Inria
  4. * Copyright (C) 2010-2019 CNRS
  5. * Copyright (C) 2009-2011,2014-2019 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. /*! \defgroup API_Scheduling_Policy Scheduling Policy
  19. \brief TODO. While StarPU comes with a variety of scheduling policies
  20. (see \ref TaskSchedulingPolicy), it may sometimes be desirable to
  21. implement custom policies to address specific problems. The API
  22. described below allows users to write their own scheduling policy.
  23. \def STARPU_MAXIMPLEMENTATIONS
  24. \ingroup API_Scheduling_Policy
  25. Define the maximum number of implementations per architecture. The default value can be modified at
  26. configure by using the option \ref enable-maximplementations "--enable-maximplementations".
  27. \struct starpu_sched_policy
  28. \ingroup API_Scheduling_Policy
  29. Contain all the methods that implement a
  30. scheduling policy. An application may specify which scheduling
  31. strategy in the field starpu_conf::sched_policy passed to the function
  32. starpu_init().
  33. For each task going through the scheduler, the following methods get called in the given order:
  34. <ul>
  35. <li>starpu_sched_policy::submit_hook when the task is submitted</li>
  36. <li>starpu_sched_policy::push_task when the task becomes ready. The scheduler is here <b>given</b> the task</li>
  37. <li>starpu_sched_policy::pop_task when the worker is idle. The scheduler here <b>gives</b> back the task to the core. It must not access this task any more</li>
  38. <li>starpu_sched_policy::pre_exec_hook right before the worker actually starts the task computation (after transferring any missing data).</li>
  39. <li>starpu_sched_policy::post_exec_hook right after the worker actually completes the task computation.</li>
  40. </ul>
  41. For each task not going through the scheduler (because starpu_task::execute_on_a_specific_worker was set), these get called:
  42. <ul>
  43. <li>starpu_sched_policy::submit_hook when the task is submitted</li>
  44. <li>starpu_sched_policy::push_task_notify when the task becomes ready. This is just a notification, the scheduler does not have to do anything about the task.</li>
  45. <li>starpu_sched_policy::pre_exec_hook right before the worker actually starts the task computation (after transferring any missing data).</li>
  46. <li>starpu_sched_policy::post_exec_hook right after the worker actually completes the task computation.</li>
  47. </ul>
  48. \var void (*starpu_sched_policy::init_sched)(unsigned sched_ctx_id)
  49. Initialize the scheduling policy, called before any other method.
  50. \var void (*starpu_sched_policy::deinit_sched)(unsigned sched_ctx_id)
  51. Cleanup the scheduling policy, called before any other method.
  52. \var int (*starpu_sched_policy::push_task)(struct starpu_task *)
  53. Insert a task into the scheduler, called when the task becomes ready for
  54. execution. This must call starpu_push_task_end() once it has effectively
  55. pushed the task to a queue (to note the time when this was done in the
  56. task), but before releasing mutexes (so that the task hasn't been
  57. already taken by a worker).
  58. \var void (*starpu_sched_policy::push_task_notify)(struct starpu_task *, int workerid, int perf_workerid, unsigned sched_ctx_id)
  59. Notify the scheduler that a task was pushed on a given worker.
  60. This method is called when a task that was explicitly
  61. assigned to a worker becomes ready and is about to be executed
  62. by the worker. This method therefore permits to keep the state
  63. of the scheduler coherent even when StarPU bypasses the
  64. scheduling strategy.
  65. \var struct starpu_task *(*starpu_sched_policy::pop_task)(unsigned sched_ctx_id)
  66. Get a task from the scheduler.
  67. If this method returns NULL, the worker will start sleeping. If later on
  68. some task are pushed for this worker, starpu_wake_worker() must be
  69. called to wake the worker so it can call the pop_task() method again.
  70. The mutex associated to the worker is already taken when this method
  71. is called. This method may release it (e.g. for scalability reasons
  72. when doing work stealing), but it must acquire it again before taking
  73. the decision whether to return a task or NULL, so the atomicity of
  74. deciding to return NULL and making the worker actually sleep is
  75. preserved. Otherwise in simgrid or blocking driver mode the worker might start
  76. sleeping while a task has just been pushed for it.
  77. If this method is defined as <c>NULL</c>, the worker will only execute
  78. tasks from its local queue. In this case, the push_task method should
  79. use the starpu_push_local_task method to assign tasks to the different
  80. workers.
  81. \var struct starpu_task *(*starpu_sched_policy::pop_every_task)(unsigned sched_ctx_id)
  82. Remove all available tasks from the scheduler (tasks are
  83. chained by the means of the field starpu_task::prev and
  84. starpu_task::next). The mutex associated to the worker is
  85. already taken when this method is called. This is currently
  86. not used and can be discarded.
  87. \var void (*starpu_sched_policy::submit_hook)(struct starpu_task *)
  88. Optional field. This method is called when a task is submitted.
  89. \var void (*starpu_sched_policy::pre_exec_hook)(struct starpu_task *)
  90. Optional field. This method is called every time a task is starting.
  91. \var void (*starpu_sched_policy::post_exec_hook)(struct starpu_task *)
  92. Optional field. This method is called every time a task has been executed.
  93. \var void (*starpu_sched_policy::do_schedule)(unsigned sched_ctx_id)
  94. Optional field. This method is called when it is a good time to start
  95. scheduling tasks. This is notably called when the application calls
  96. starpu_task_wait_for_all() or starpu_do_schedule() explicitly.
  97. \var void (*starpu_sched_policy::add_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers)
  98. Initialize scheduling structures corresponding to each worker used by the policy.
  99. \var void (*starpu_sched_policy::remove_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers)
  100. Deinitialize scheduling structures corresponding to each worker used by the policy.
  101. \var const char *starpu_sched_policy::policy_name
  102. Optional field. Name of the policy.
  103. \var const char *starpu_sched_policy::policy_description
  104. Optional field. Human readable description of the policy.
  105. \fn struct starpu_sched_policy **starpu_sched_get_predefined_policies()
  106. \ingroup API_Scheduling_Policy
  107. Return an <c>NULL</c>-terminated array of all the predefined scheduling
  108. policies.
  109. \fn void starpu_worker_get_sched_condition(int workerid, starpu_pthread_mutex_t **sched_mutex, starpu_pthread_cond_t **sched_cond)
  110. \ingroup API_Scheduling_Policy
  111. When there is no available task for a worker, StarPU blocks this
  112. worker on a condition variable. This function specifies which
  113. condition variable (and the associated mutex) should be used to block
  114. (and to wake up) a worker. Note that multiple workers may use the same
  115. condition variable. For instance, in the case of a scheduling strategy
  116. with a single task queue, the same condition variable would be used to
  117. block and wake up all workers.
  118. \fn int starpu_wake_worker_no_relax(int workerid)
  119. \ingroup API_Scheduling_Policy
  120. Must be called to wake up a worker that is sleeping on the cond.
  121. Return 0 whenever the worker is not in a sleeping state or has the
  122. state_keep_awake flag on.
  123. \fn int starpu_wake_worker_locked(int workerid)
  124. \ingroup API_Scheduling_Policy
  125. Version of starpu_wake_worker_no_relax() which assumes that the sched
  126. mutex is locked
  127. \fn int starpu_sched_set_min_priority(int min_prio)
  128. \ingroup API_Scheduling_Policy
  129. TODO: check if this is correct
  130. Define the minimum task priority level supported by the scheduling
  131. policy. The default minimum priority level is the same as the default
  132. priority level which is 0 by convention. The application may access
  133. that value by calling the function starpu_sched_get_min_priority().
  134. This function should only be called from the initialization method of
  135. the scheduling policy, and should not be used directly from the
  136. application.
  137. \fn int starpu_sched_set_max_priority(int max_prio)
  138. \ingroup API_Scheduling_Policy
  139. TODO: check if this is correct
  140. Define the maximum priority level supported by the scheduling policy.
  141. The default maximum priority level is 1. The application may access
  142. that value by calling the function starpu_sched_get_max_priority().
  143. This function should only be called from the initialization method of
  144. the scheduling policy, and should not be used directly from the
  145. application.
  146. \fn int starpu_sched_get_min_priority(void)
  147. \ingroup API_Scheduling_Policy
  148. TODO: check if this is correct
  149. Return the current minimum priority level supported by the scheduling
  150. policy
  151. \fn int starpu_sched_get_max_priority(void)
  152. \ingroup API_Scheduling_Policy
  153. TODO: check if this is correct
  154. Return the current maximum priority level supported by the scheduling
  155. policy
  156. \fn int starpu_push_local_task(int workerid, struct starpu_task *task, int back)
  157. \ingroup API_Scheduling_Policy
  158. The scheduling policy may put tasks directly into a worker’s local
  159. queue so that it is not always necessary to create its own queue when
  160. the local queue is sufficient. If \p back is not 0, \p task is put
  161. at the back of the queue where the worker will pop tasks first.
  162. Setting \p back to 0 therefore ensures a FIFO ordering.
  163. \fn int starpu_push_task_end(struct starpu_task *task)
  164. \ingroup API_Scheduling_Policy
  165. Must be called by a scheduler to notify that the given
  166. task has just been pushed.
  167. \fn int starpu_worker_can_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl)
  168. \ingroup API_Scheduling_Policy
  169. Check if the worker specified by workerid can execute the codelet.
  170. Schedulers need to call it before assigning a task to a worker,
  171. otherwise the task may fail to execute.
  172. \fn int starpu_worker_can_execute_task_impl(unsigned workerid, struct starpu_task *task, unsigned *impl_mask)
  173. \ingroup API_Scheduling_Policy
  174. Check if the worker specified by workerid can execute the codelet and returns
  175. which implementation numbers can be used.
  176. Schedulers need to call it before assigning a task to a worker,
  177. otherwise the task may fail to execute.
  178. This should be preferred rather than calling starpu_worker_can_execute_task for
  179. each and every implementation. It can also be used with <c>impl_mask == NULL</c> to
  180. check for at least one implementation without determining which.
  181. \fn int starpu_worker_can_execute_task_first_impl(unsigned workerid, struct starpu_task *task, unsigned *nimpl)
  182. \ingroup API_Scheduling_Policy
  183. Check if the worker specified by workerid can execute the codelet and returns
  184. the first implementation which can be used.
  185. Schedulers need to call it before assigning a task to a worker,
  186. otherwise the task may fail to execute.
  187. This should be preferred rather than calling starpu_worker_can_execute_task for
  188. each and every implementation. It can also be used with <c>impl_mask == NULL</c> to
  189. check for at least one implementation without determining which.
  190. \fn uint32_t starpu_task_footprint(struct starpu_perfmodel *model, struct starpu_task *task, struct starpu_perfmodel_arch *arch, unsigned nimpl)
  191. \ingroup API_Scheduling_Policy
  192. Return the footprint for a given task, taking into account user-provided
  193. perfmodel footprint or size_base functions.
  194. \fn uint32_t starpu_task_data_footprint(struct starpu_task *task)
  195. \ingroup API_Scheduling_Policy
  196. Return the raw footprint for the data of a given task (without taking into account user-provided functions).
  197. \fn double starpu_task_expected_length(struct starpu_task *task, struct starpu_perfmodel_arch *arch, unsigned nimpl)
  198. \ingroup API_Scheduling_Policy
  199. Return expected task duration in micro-seconds.
  200. \fn double starpu_worker_get_relative_speedup(struct starpu_perfmodel_arch *perf_arch)
  201. \ingroup API_Scheduling_Policy
  202. Return an estimated speedup factor relative to CPU speed
  203. \fn double starpu_task_expected_data_transfer_time(unsigned memory_node, struct starpu_task *task)
  204. \ingroup API_Scheduling_Policy
  205. Return expected data transfer time in micro-seconds for the given \p
  206. memory_node. Prefer using starpu_task_expected_data_transfer_time_for() which is
  207. more precise.
  208. \fn double starpu_task_expected_data_transfer_time_for(struct starpu_task *task, unsigned worker)
  209. \ingroup API_Scheduling_Policy
  210. Return expected data transfer time in micro-seconds for the given \p worker.
  211. \fn double starpu_data_expected_transfer_time(starpu_data_handle_t handle, unsigned memory_node, enum starpu_data_access_mode mode)
  212. \ingroup API_Scheduling_Policy
  213. Predict the transfer time (in micro-seconds) to move \p handle to a memory node
  214. \fn double starpu_task_expected_energy(struct starpu_task *task, struct starpu_perfmodel_arch *arch, unsigned nimpl)
  215. \ingroup API_Scheduling_Policy
  216. Return expected energy consumption in J
  217. \fn double starpu_task_expected_conversion_time(struct starpu_task *task, struct starpu_perfmodel_arch *arch, unsigned nimpl)
  218. \ingroup API_Scheduling_Policy
  219. Return expected conversion time in ms (multiformat interface only)
  220. \fn int starpu_get_prefetch_flag(void)
  221. \ingroup API_Scheduling_Policy
  222. Whether \ref STARPU_PREFETCH was set
  223. \fn int starpu_prefetch_task_input_on_node(struct starpu_task *task, unsigned node)
  224. \ingroup API_Scheduling_Policy
  225. Prefetch data for a given p task on a given p node
  226. \fn int starpu_prefetch_task_input_on_node_prio(struct starpu_task *task, unsigned node, int prio)
  227. \ingroup API_Scheduling_Policy
  228. Prefetch data for a given p task on a given p node with a given priority
  229. \fn int starpu_idle_prefetch_task_input_on_node(struct starpu_task *task, unsigned node)
  230. \ingroup API_Scheduling_Policy
  231. Prefetch data for a given p task on a given p node when the bus is idle
  232. \fn int starpu_idle_prefetch_task_input_on_node_prio(struct starpu_task *task, unsigned node, int prio)
  233. \ingroup API_Scheduling_Policy
  234. Prefetch data for a given p task on a given p node when the bus is idle with a given priority
  235. \fn int starpu_prefetch_task_input_for(struct starpu_task *task, unsigned worker)
  236. \ingroup API_Scheduling_Policy
  237. Prefetch data for a given p task on a given p worker
  238. \fn int starpu_prefetch_task_input_for_prio(struct starpu_task *task, unsigned worker, int prio)
  239. \ingroup API_Scheduling_Policy
  240. Prefetch data for a given p task on a given p worker with a given priority
  241. \fn int starpu_idle_prefetch_task_input_for(struct starpu_task *task, unsigned worker)
  242. \ingroup API_Scheduling_Policy
  243. Prefetch data for a given p task on a given p worker when the bus is idle
  244. \fn int starpu_idle_prefetch_task_input_for_prio(struct starpu_task *task, unsigned worker, int prio)
  245. \ingroup API_Scheduling_Policy
  246. Prefetch data for a given p task on a given p worker when the bus is idle with a given priority
  247. \fn void starpu_task_notify_ready_soon_register(starpu_notify_ready_soon_func f, void *data);
  248. \ingroup API_Scheduling_Policy
  249. Register a callback to be called when it is determined when a task will be ready
  250. an estimated amount of time from now, because its last dependency has just
  251. started and we know how long it will take.
  252. \fn void starpu_sched_ctx_worker_shares_tasks_lists(int workerid, int sched_ctx_id)
  253. \ingroup API_Scheduling_Policy
  254. The scheduling policies indicates if the worker may pop tasks from the list of other workers
  255. or if there is a central list with task for all the workers
  256. */