scheduling_policy.doxy 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \defgroup API_Scheduling_Policy Scheduling Policy
  9. \brief TODO. While StarPU comes with a variety of scheduling policies
  10. (see \ref TaskSchedulingPolicy), it may sometimes be desirable to
  11. implement custom policies to address specific problems. The API
  12. described below allows users to write their own scheduling policy.
  13. \def STARPU_MAXIMPLEMENTATIONS
  14. \ingroup API_Scheduling_Policy
  15. Define the maximum number of implementations per architecture. The default value can be modified at
  16. configure by using the option \ref enable-maximplementations "--enable-maximplementations".
  17. \struct starpu_sched_policy
  18. \ingroup API_Scheduling_Policy
  19. Contain all the methods that implement a
  20. scheduling policy. An application may specify which scheduling
  21. strategy in the field starpu_conf::sched_policy passed to the function
  22. starpu_init().
  23. For each task going through the scheduler, the following methods get called in the given order:
  24. <ul>
  25. <li>starpu_sched_policy::submit_hook when the task is submitted</li>
  26. <li>starpu_sched_policy::push_task when the task becomes ready. The scheduler is here <b>given</b> the task</li>
  27. <li>starpu_sched_policy::pop_task when the worker is idle. The scheduler here <b>gives</b> back the task to the core</li>
  28. <li>starpu_sched_policy::pre_exec_hook right before the worker actually starts the task computation (after transferring any missing data).</li>
  29. <li>starpu_sched_policy::post_exec_hook right after the worker actually completes the task computation.</li>
  30. </ul>
  31. For each task not going through the scheduler (because starpu_task::execute_on_a_specific_worker was set), these get called:
  32. <ul>
  33. <li>starpu_sched_policy::submit_hook when the task is submitted</li>
  34. <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>
  35. <li>starpu_sched_policy::pre_exec_hook right before the worker actually starts the task computation (after transferring any missing data).</li>
  36. <li>starpu_sched_policy::post_exec_hook right after the worker actually completes the task computation.</li>
  37. </ul>
  38. \var void (*starpu_sched_policy::init_sched)(unsigned sched_ctx_id)
  39. Initialize the scheduling policy, called before any other method.
  40. \var void (*starpu_sched_policy::deinit_sched)(unsigned sched_ctx_id)
  41. Cleanup the scheduling policy, called before any other method.
  42. \var int (*starpu_sched_policy::push_task)(struct starpu_task *)
  43. Insert a task into the scheduler, called when the task becomes ready for
  44. execution.
  45. \var void (*starpu_sched_policy::push_task_notify)(struct starpu_task *, int workerid, int perf_workerid, unsigned sched_ctx_id)
  46. Notify the scheduler that a task was pushed on a given worker.
  47. This method is called when a task that was explicitly
  48. assigned to a worker becomes ready and is about to be executed
  49. by the worker. This method therefore permits to keep the state
  50. of the scheduler coherent even when StarPU bypasses the
  51. scheduling strategy.
  52. \var struct starpu_task *(*starpu_sched_policy::pop_task)(unsigned sched_ctx_id)
  53. Get a task from the scheduler. The mutex associated to the
  54. worker is already taken when this method is called. If this
  55. method is defined as <c>NULL</c>, the worker will only execute tasks
  56. from its local queue. In this case, the push_task method
  57. should use the starpu_push_local_task method to assign tasks
  58. to the different workers.
  59. \var struct starpu_task *(*starpu_sched_policy::pop_every_task)(unsigned sched_ctx_id)
  60. Remove all available tasks from the scheduler (tasks are
  61. chained by the means of the field starpu_task::prev and
  62. starpu_task::next). The mutex associated to the worker is
  63. already taken when this method is called. This is currently
  64. not used and can be discarded.
  65. \var void (*starpu_sched_policy::submit_hook)(struct starpu_task *)
  66. Optional field. This method is called when a task is submitted.
  67. \var void (*starpu_sched_policy::pre_exec_hook)(struct starpu_task *)
  68. Optional field. This method is called every time a task is starting.
  69. \var void (*starpu_sched_policy::post_exec_hook)(struct starpu_task *)
  70. Optional field. This method is called every time a task has been executed.
  71. \var void (*starpu_sched_policy::do_schedule)(unsigned sched_ctx_id)
  72. Optional field. This method is called when it is a good time to start
  73. scheduling tasks. This is notably called when the application calls
  74. starpu_task_wait_for_all or starpu_do_schedule explicitly.
  75. \var void (*starpu_sched_policy::add_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers)
  76. Initialize scheduling structures corresponding to each worker used by the policy.
  77. \var void (*starpu_sched_policy::remove_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers)
  78. Deinitialize scheduling structures corresponding to each worker used by the policy.
  79. \var const char *starpu_sched_policy::policy_name
  80. Optional field. Name of the policy.
  81. \var const char *starpu_sched_policy::policy_description
  82. Optional field. Human readable description of the policy.
  83. \fn struct starpu_sched_policy **starpu_sched_get_predefined_policies()
  84. \ingroup API_Scheduling_Policy
  85. Return an <c>NULL</c>-terminated array of all the predefined scheduling
  86. policies.
  87. \fn void starpu_worker_get_sched_condition(int workerid, starpu_pthread_mutex_t **sched_mutex, starpu_pthread_cond_t **sched_cond)
  88. \ingroup API_Scheduling_Policy
  89. When there is no available task for a worker, StarPU blocks this
  90. worker on a condition variable. This function specifies which
  91. condition variable (and the associated mutex) should be used to block
  92. (and to wake up) a worker. Note that multiple workers may use the same
  93. condition variable. For instance, in the case of a scheduling strategy
  94. with a single task queue, the same condition variable would be used to
  95. block and wake up all workers.
  96. \fn void starpu_worker_get_job_id(struct starpu_task *task)
  97. \ingroup API_Scheduling_Policy
  98. Return the job id of the given task, i.e. a number that uniquely identifies this
  99. task for the local MPI node, and can be found in the various offline execution
  100. traces reports.
  101. \fn int starpu_sched_set_min_priority(int min_prio)
  102. \ingroup API_Scheduling_Policy
  103. TODO: check if this is correct
  104. Define the minimum task priority level supported by the scheduling
  105. policy. The default minimum priority level is the same as the default
  106. priority level which is 0 by convention. The application may access
  107. that value by calling the function starpu_sched_get_min_priority().
  108. This function should only be called from the initialization method of
  109. the scheduling policy, and should not be used directly from the
  110. application.
  111. \fn int starpu_sched_set_max_priority(int max_prio)
  112. \ingroup API_Scheduling_Policy
  113. TODO: check if this is correct
  114. Define the maximum priority level supported by the scheduling policy.
  115. The default maximum priority level is 1. The application may access
  116. that value by calling the function starpu_sched_get_max_priority().
  117. This function should only be called from the initialization method of
  118. the scheduling policy, and should not be used directly from the
  119. application.
  120. \fn int starpu_sched_get_min_priority(void)
  121. \ingroup API_Scheduling_Policy
  122. TODO: check if this is correct
  123. Return the current minimum priority level supported by the scheduling
  124. policy
  125. \fn int starpu_sched_get_max_priority(void)
  126. \ingroup API_Scheduling_Policy
  127. TODO: check if this is correct
  128. Return the current maximum priority level supported by the scheduling
  129. policy
  130. \fn int starpu_push_local_task(int workerid, struct starpu_task *task, int back)
  131. \ingroup API_Scheduling_Policy
  132. The scheduling policy may put tasks directly into a worker’s local
  133. queue so that it is not always necessary to create its own queue when
  134. the local queue is sufficient. If \p back is not 0, \p task is put
  135. at the back of the queue where the worker will pop tasks first.
  136. Setting \p back to 0 therefore ensures a FIFO ordering.
  137. \fn int starpu_push_task_end(struct starpu_task *task)
  138. \ingroup API_Scheduling_Policy
  139. Must be called by a scheduler to notify that the given
  140. task has just been pushed.
  141. \fn int starpu_worker_can_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl)
  142. \ingroup API_Scheduling_Policy
  143. Check if the worker specified by workerid can execute the codelet.
  144. Schedulers need to call it before assigning a task to a worker,
  145. otherwise the task may fail to execute.
  146. \fn int starpu_worker_can_execute_task_impl(unsigned workerid, struct starpu_task *task, unsigned *impl_mask)
  147. \ingroup API_Scheduling_Policy
  148. Check if the worker specified by workerid can execute the codelet and returns
  149. which implementation numbers can be used.
  150. Schedulers need to call it before assigning a task to a worker,
  151. otherwise the task may fail to execute.
  152. This should be preferred rather than calling starpu_worker_can_execute_task for
  153. each and every implementation. It can also be used with <c>impl_mask == NULL</c> to
  154. check for at least one implementation without determining which.
  155. \fn int starpu_worker_can_execute_task_first_impl(unsigned workerid, struct starpu_task *task, unsigned *nimpl)
  156. \ingroup API_Scheduling_Policy
  157. Check if the worker specified by workerid can execute the codelet and returns
  158. the first implementation which can be used.
  159. Schedulers need to call it before assigning a task to a worker,
  160. otherwise the task may fail to execute.
  161. This should be preferred rather than calling starpu_worker_can_execute_task for
  162. each and every implementation. It can also be used with <c>impl_mask == NULL</c> to
  163. check for at least one implementation without determining which.
  164. \fn uint32_t starpu_task_footprint(struct starpu_perfmodel *model, struct starpu_task *task, struct starpu_perfmodel_arch *arch, unsigned nimpl)
  165. \ingroup API_Scheduling_Policy
  166. Return the footprint for a given task, taking into account user-provided
  167. perfmodel footprint or size_base functions.
  168. \fn uint32_t starpu_task_data_footprint(struct starpu_task *task)
  169. \ingroup API_Scheduling_Policy
  170. Return the raw footprint for the data of a given task (without taking into account user-provided functions).
  171. \fn double starpu_task_expected_length(struct starpu_task *task, struct starpu_perfmodel_arch *arch, unsigned nimpl)
  172. \ingroup API_Scheduling_Policy
  173. Return expected task duration in micro-seconds.
  174. \fn double starpu_worker_get_relative_speedup(struct starpu_perfmodel_arch *perf_arch)
  175. \ingroup API_Scheduling_Policy
  176. Return an estimated speedup factor relative to CPU speed
  177. \fn double starpu_task_expected_data_transfer_time(unsigned memory_node, struct starpu_task *task)
  178. \ingroup API_Scheduling_Policy
  179. Return expected data transfer time in micro-seconds.
  180. \fn double starpu_data_expected_transfer_time(starpu_data_handle_t handle, unsigned memory_node, enum starpu_data_access_mode mode)
  181. \ingroup API_Scheduling_Policy
  182. Predict the transfer time (in micro-seconds) to move \p handle to a memory node
  183. \fn double starpu_task_expected_energy(struct starpu_task *task, struct starpu_perfmodel_arch *arch, unsigned nimpl)
  184. \ingroup API_Scheduling_Policy
  185. Return expected energy consumption in J
  186. \fn double starpu_task_expected_conversion_time(struct starpu_task *task, struct starpu_perfmodel_arch *arch, unsigned nimpl)
  187. \ingroup API_Scheduling_Policy
  188. Return expected conversion time in ms (multiformat interface only)
  189. \fn int starpu_get_prefetch_flag(void)
  190. \ingroup API_Scheduling_Policy
  191. Whether \ref STARPU_PREFETCH was set
  192. \fn int starpu_prefetch_task_input_on_node(struct starpu_task *task, unsigned node)
  193. \ingroup API_Scheduling_Policy
  194. Prefetch data for a given task on a given node
  195. \fn int starpu_idle_prefetch_task_input_on_node(struct starpu_task *task, unsigned node)
  196. \ingroup API_Scheduling_Policy
  197. Prefetch data for a given task on a given node when the bus is idle
  198. \fn void starpu_sched_ctx_worker_shares_tasks_lists(int workerid, int sched_ctx_id)
  199. \ingroup API_Scheduling_Policy
  200. The scheduling policies indicates if the worker may pop tasks from the list of other workers
  201. or if there is a central list with task for all the workers
  202. */