08scheduling.doxy 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \page Scheduling Scheduling
  9. \section TaskSchedulingPolicy Task Scheduling Policy
  10. The basics of the scheduling policy are that
  11. <ul>
  12. <li>The scheduler gets to schedule tasks (<c>push</c> operation) when they become
  13. ready to be executed, i.e. they are not waiting for some tags, data dependencies
  14. or task dependencies.</li>
  15. <li>Workers pull tasks (<c>pop</c> operation) one by one from the scheduler.
  16. </ul>
  17. This means scheduling policies usually contain at least one queue of tasks to
  18. store them between the time when they become available, and the time when a
  19. worker gets to grab them.
  20. By default, StarPU uses the simple greedy scheduler <c>eager</c>. This is
  21. because it provides correct load balance even if the application codelets do not
  22. have performance models. If your application codelets have performance models
  23. (\ref PerformanceModelExample), you should change the scheduler thanks
  24. to the environment variable \ref STARPU_SCHED. For instance <c>export
  25. STARPU_SCHED=dmda</c> . Use <c>help</c> to get the list of available schedulers.
  26. The <b>eager</b> scheduler uses a central task queue, from which all workers draw tasks
  27. to work on concurrently. This however does not permit to prefetch data since the scheduling
  28. decision is taken late. If a task has a non-0 priority, it is put at the front of the queue.
  29. The <b>prio</b> scheduler also uses a central task queue, but sorts tasks by
  30. priority (between -5 and 5).
  31. The <b>random</b> scheduler uses a queue per worker, and distributes tasks randomly according to assumed worker
  32. overall performance.
  33. The <b>ws</b> (work stealing) scheduler uses a queue per worker, and schedules
  34. a task on the worker which released it by
  35. default. When a worker becomes idle, it steals a task from the most loaded
  36. worker.
  37. The <b>lws</b> (locality work stealing) scheduler uses a queue per worker, and schedules
  38. a task on the worker which released it by
  39. default. When a worker becomes idle, it steals a task from neighbour workers. It
  40. also takes into account priorities.
  41. The <b>dm</b> (deque model) scheduler uses task execution performance models into account to
  42. perform a HEFT-similar scheduling strategy: it schedules tasks where their
  43. termination time will be minimal. The difference with HEFT is that <b>dm</b>
  44. schedules tasks as soon as they become available, and thus in the order they
  45. become available, without taking priorities into account.
  46. The <b>dmda</b> (deque model data aware) scheduler is similar to dm, but it also takes
  47. into account data transfer time.
  48. The <b>dmdar</b> (deque model data aware ready) scheduler is similar to dmda,
  49. but it also sorts tasks on per-worker queues by number of already-available data
  50. buffers on the target device.
  51. The <b>dmdas</b> (deque model data aware sorted) scheduler is similar to dmdar,
  52. except that it sorts tasks by priority order, which allows to become even closer
  53. to HEFT by respecting priorities after having made the scheduling decision (but
  54. it still schedules tasks in the order they become available).
  55. The <b>heft</b> (heterogeneous earliest finish time) scheduler is a deprecated
  56. alias for <b>dmda</b>.
  57. The <b>pheft</b> (parallel HEFT) scheduler is similar to dmda, it also supports
  58. parallel tasks (still experimental). Should not be used when several contexts using
  59. it are being executed simultaneously.
  60. The <b>peager</b> (parallel eager) scheduler is similar to eager, it also
  61. supports parallel tasks (still experimental). Should not be used when several
  62. contexts using it are being executed simultaneously.
  63. \section TaskDistributionVsDataTransfer Task Distribution Vs Data Transfer
  64. Distributing tasks to balance the load induces data transfer penalty. StarPU
  65. thus needs to find a balance between both. The target function that the
  66. scheduler <c>dmda</c> of StarPU
  67. tries to minimize is <c>alpha * T_execution + beta * T_data_transfer</c>, where
  68. <c>T_execution</c> is the estimated execution time of the codelet (usually
  69. accurate), and <c>T_data_transfer</c> is the estimated data transfer time. The
  70. latter is estimated based on bus calibration before execution start,
  71. i.e. with an idle machine, thus without contention. You can force bus
  72. re-calibration by running the tool <c>starpu_calibrate_bus</c>. The
  73. beta parameter defaults to <c>1</c>, but it can be worth trying to tweak it
  74. by using <c>export STARPU_SCHED_BETA=2</c> for instance, since during
  75. real application execution, contention makes transfer times bigger.
  76. This is of course imprecise, but in practice, a rough estimation
  77. already gives the good results that a precise estimation would give.
  78. \section Power-basedScheduling Power-based Scheduling
  79. If the application can provide some power performance model (through
  80. the field starpu_codelet::power_model), StarPU will
  81. take it into account when distributing tasks. The target function that
  82. the scheduler <c>dmda</c> minimizes becomes <c>alpha * T_execution +
  83. beta * T_data_transfer + gamma * Consumption</c> , where <c>Consumption</c>
  84. is the estimated task consumption in Joules. To tune this parameter, use
  85. <c>export STARPU_SCHED_GAMMA=3000</c> for instance, to express that each Joule
  86. (i.e kW during 1000us) is worth 3000us execution time penalty. Setting
  87. <c>alpha</c> and <c>beta</c> to zero permits to only take into account power consumption.
  88. This is however not sufficient to correctly optimize power: the scheduler would
  89. simply tend to run all computations on the most energy-conservative processing
  90. unit. To account for the consumption of the whole machine (including idle
  91. processing units), the idle power of the machine should be given by setting
  92. <c>export STARPU_IDLE_POWER=200</c> for 200W, for instance. This value can often
  93. be obtained from the machine power supplier.
  94. The power actually consumed by the total execution can be displayed by setting
  95. <c>export STARPU_PROFILING=1 STARPU_WORKER_STATS=1</c> .
  96. On-line task consumption measurement is currently only supported through the
  97. <c>CL_PROFILING_POWER_CONSUMED</c> OpenCL extension, implemented in the MoviSim
  98. simulator. Applications can however provide explicit measurements by
  99. using the function starpu_perfmodel_update_history() (examplified in \ref PerformanceModelExample
  100. with the <c>power_model</c> performance model). Fine-grain
  101. measurement is often not feasible with the feedback provided by the hardware, so
  102. the user can for instance run a given task a thousand times, measure the global
  103. consumption for that series of tasks, divide it by a thousand, repeat for
  104. varying kinds of tasks and task sizes, and eventually feed StarPU
  105. with these manual measurements through starpu_perfmodel_update_history().
  106. For instance, for CUDA devices, <c>nvidia-smi -q -d POWER</c> can be used to get
  107. the current consumption in Watt. Multiplying that value by the average duration
  108. of a single task gives the consumption of the task in Joules, which can be given
  109. to starpu_perfmodel_update_history().
  110. \section StaticScheduling Static Scheduling
  111. In some cases, one may want to force some scheduling, for instance force a given
  112. set of tasks to GPU0, another set to GPU1, etc. while letting some other tasks
  113. be scheduled on any other device. This can indeed be useful to guide StarPU into
  114. some work distribution, while still letting some degree of dynamism. For
  115. instance, to force execution of a task on CUDA0:
  116. \code{.c}
  117. task->execute_on_a_specific_worker = 1;
  118. task->worker = starpu_worker_get_by_type(STARPU_CUDA_WORKER, 0);
  119. \endcode
  120. One can also specify the order in which tasks must be executed by setting the
  121. starpu_task::workerder field. If this field is set to a non-zero value, it
  122. provides the per-worker consecutive order in which tasks will be executed,
  123. starting from 1. For a given of such task, the worker will thus not execute
  124. it before all the tasks with smaller order value have been executed, notably
  125. in case those tasks are not available yet due to some dependencies. This
  126. eventually gives total control of task scheduling, and StarPU will only serve as
  127. a "self-timed" task runtime. Of course, the provided order has to be runnable,
  128. i.e. a task should should not depend on another task bound to the same worker
  129. with a bigger order.
  130. Note however that using scheduling contexts while statically scheduling tasks on workers
  131. could be tricky. Be careful to schedule the tasks exactly on the workers of the corresponding
  132. contexts, otherwise the workers' corresponding scheduling structures may not be allocated or
  133. the execution of the application may deadlock. Moreover, the hypervisor should not be used when
  134. statically scheduling tasks.
  135. \section DefiningANewSchedulingPolicy Defining A New Scheduling Policy
  136. A full example showing how to define a new scheduling policy is available in
  137. the StarPU sources in the directory <c>examples/scheduler/</c>.
  138. See \ref API_Scheduling_Policy
  139. \code{.c}
  140. static struct starpu_sched_policy dummy_sched_policy = {
  141. .init_sched = init_dummy_sched,
  142. .deinit_sched = deinit_dummy_sched,
  143. .add_workers = dummy_sched_add_workers,
  144. .remove_workers = dummy_sched_remove_workers,
  145. .push_task = push_task_dummy,
  146. .push_prio_task = NULL,
  147. .pop_task = pop_task_dummy,
  148. .post_exec_hook = NULL,
  149. .pop_every_task = NULL,
  150. .policy_name = "dummy",
  151. .policy_description = "dummy scheduling strategy"
  152. };
  153. \endcode
  154. */